Permalink
Browse files

emit a warning about unused variables.

  • Loading branch information...
1 parent ab0b519 commit e3056fd07fe1ebcd9a4a72aef6d7711a7ee0b190 @kjs kjs committed Jun 24, 2012
Showing with 9 additions and 1 deletion.
  1. +6 −0 src/gencode.c
  2. +2 −1 src/symtab.c
  3. +1 −0 src/symtab.h
View
@@ -168,6 +168,12 @@ unfreeze_registers(M1_compiler *comp, m1_symboltable *table) {
assert(comp->registers[type][regno] == REG_SYMBOL);
comp->registers[type][regno] = REG_UNUSED;
}
+ else { /* if no register is allocated, it's an unused variable. Emit a warning*/
+
+ fprintf(stderr, "%s:%d: warning: unused variable '%s'\n",
+ comp->current_filename, iter->line, iter->name);
+ ++comp->warnings;
+ }
iter = sym_iter_next(iter);
}
View
@@ -110,7 +110,8 @@ sym_new_symbol(M1_compiler *comp, m1_symboltable *table, char *varname, char *ty
sym->regno = NO_REG_ALLOCATED_YET; /* need to allocate a register later. */
sym->next = NULL; /* symbols are stored in a list */
sym->type_name = type; /* store the name of the type, as it may not have been defined yet. */
-
+ sym->line = yyget_lineno(comp->yyscanner);
+
link_sym(table, sym);
return sym;
View
@@ -67,6 +67,7 @@ typedef struct m1_symbol {
m1_valuetype valtype; /* selector of value union. */
unsigned num_elems; /* 1 for normal symbols; > 1 for arrays. */
+ unsigned line;
union {
unsigned offset; /* offset from base when this symbol is a struct member. */

0 comments on commit e3056fd

Please sign in to comment.