Track filename and line number where variables are defined.

This commit is contained in:
Dianne Skoll
2025-05-24 22:58:28 -04:00
parent 102748397f
commit 9624b1045c
3 changed files with 7 additions and 3 deletions

View File

@@ -107,6 +107,8 @@ typedef struct var {
char preserve;
char is_constant;
char used_since_set;
char const *filename;
int lineno;
Value v;
} Var;

View File

@@ -601,6 +601,8 @@ int SetVar(char const *str, Value const *val, int nonconst_expr)
v->v = *val;
v->is_constant = ! nonconst_expr;
v->used_since_set = 0;
v->filename = GetCurrentFilename();
v->lineno = LineNo;
return OK;
}
@@ -843,7 +845,7 @@ void DumpUnusedVars(void)
fprintf(ErrFp, "%s\n", tr("The following variables were set, but not subsequently used:"));
done_header = 1;
}
fprintf(ErrFp, "\t%s\n", v->name);
fprintf(ErrFp, "\t%s - defined at %s:%d\n", v->name, v->filename, v->lineno);
}
}

View File

@@ -38716,6 +38716,6 @@ utctolocal(2050-11-06@04:00) => 2050-11-06@00:00
utctolocal(2050-11-06@07:00) => 2050-11-06@02:00
No reminders.
The following variables were set, but not subsequently used:
b
d
b - defined at -stdin-:2
d - defined at -stdin-:5
No reminders.