Skip to content

Commit

Permalink
Don't generate code for undefined or unused routines
Browse files Browse the repository at this point in the history
  • Loading branch information
ojwb committed Sep 10, 2024
1 parent 7ed19e7 commit da13df5
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 6 deletions.
9 changes: 6 additions & 3 deletions compiler/analyser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1546,10 +1546,10 @@ extern void read_program(struct analyser * a) {
fprintf(stderr, "declared but not defined\n");
} else {
fprintf(stderr, "defined but not used\n");
q = q->next;
*ptr = q;
continue;
}
q = q->next;
*ptr = q;
continue;
} else if (q->type == t_routine || q->type == t_grouping) {
/* It's OK to define a grouping but only use it to define other
* groupings.
Expand All @@ -1567,6 +1567,9 @@ extern void read_program(struct analyser * a) {
line_num,
name_of_name_type(q->type),
q->s);
q = q->next;
*ptr = q;
continue;
}
} else if (q->type == t_external) {
/* Unused is OK. */
Expand Down
1 change: 1 addition & 0 deletions compiler/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,7 @@ static void generate_literalstring(struct generator * g, struct node * p) {

static void generate_define(struct generator * g, struct node * p) {
struct name * q = p->name;
if (q->type == t_routine && !q->used) return;
g->next_label = 0;

g->S[0] = q->type == t_routine ? "static" : "extern";
Expand Down
7 changes: 5 additions & 2 deletions compiler/generator_ada.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,11 +1099,14 @@ static void generate_literalstring(struct generator * g, struct node * p) {
}

static void generate_define(struct generator * g, struct node * p) {
struct name * q = p->name;
if (q->type == t_routine && !q->used) return;

struct str *saved_output;
struct str *saved_declarations;

/* Generate function header. */
g->V[0] = p->name;
g->V[0] = q;
w(g, "~N~Mprocedure ~W0 (Z : in out Context_Type; Result : out Boolean) is~N");
if (need_c_var(p->left)) {
w(g, "~M~MC : Result_Index;~N");
Expand Down Expand Up @@ -1135,7 +1138,7 @@ static void generate_define(struct generator * g, struct node * p) {
generate(g, p->left->right);
}
}
g->V[0] = p->name;
g->V[0] = q;
w(g, "~-~Mend ~W0;~N");

if (g->var_number) {
Expand Down
1 change: 1 addition & 0 deletions compiler/generator_csharp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ static void generate_literalstring(struct generator * g, struct node * p) {

static void generate_define(struct generator * g, struct node * p) {
struct name * q = p->name;
if (q->type == t_routine && !q->used) return;

struct str * saved_output = g->outbuf;

Expand Down
1 change: 1 addition & 0 deletions compiler/generator_go.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ static void generate_setup_context(struct generator * g) {

static void generate_define(struct generator * g, struct node * p) {
struct name * q = p->name;
if (q->type == t_routine && !q->used) return;

struct str * saved_output = g->outbuf;

Expand Down
1 change: 1 addition & 0 deletions compiler/generator_java.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ static void generate_literalstring(struct generator * g, struct node * p) {

static void generate_define(struct generator * g, struct node * p) {
struct name * q = p->name;
if (q->type == t_routine && !q->used) return;

struct str * saved_output = g->outbuf;

Expand Down
1 change: 1 addition & 0 deletions compiler/generator_js.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ static void generate_literalstring(struct generator * g, struct node * p) {

static void generate_define(struct generator * g, struct node * p) {
struct name * q = p->name;
if (q->type == t_routine && !q->used) return;

struct str * saved_output = g->outbuf;
struct str * saved_declarations = g->declarations;
Expand Down
5 changes: 4 additions & 1 deletion compiler/generator_pascal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,11 +1030,14 @@ static void generate_literalstring(struct generator * g, struct node * p) {
}

static void generate_define(struct generator * g, struct node * p) {
struct name * q = p->name;
if (q->type == t_routine && !q->used) return;

struct str *saved_output;
struct str *saved_declarations;

/* Generate function header. */
g->V[0] = p->name;
g->V[0] = q;
w(g, "~N~MFunction T~n.~W0 : Boolean;~N");

/* Save output*/
Expand Down
2 changes: 2 additions & 0 deletions compiler/generator_python.c
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,8 @@ static void generate_literalstring(struct generator * g, struct node * p) {

static void generate_define(struct generator * g, struct node * p) {
struct name * q = p->name;
if (q->type == t_routine && !q->used) return;
g->next_label = 0;

struct str * saved_output = g->outbuf;

Expand Down
1 change: 1 addition & 0 deletions compiler/generator_rust.c
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@ static void generate_setup_context(struct generator * g) {

static void generate_define(struct generator * g, struct node * p) {
struct name * q = p->name;
if (q->type == t_routine && !q->used) return;

struct str * saved_output = g->outbuf;

Expand Down

0 comments on commit da13df5

Please sign in to comment.