improved error messages

This commit is contained in:
dick 1990-11-19 14:14:12 +00:00
parent fb143bcdb5
commit d443d61b09
3 changed files with 53 additions and 27 deletions

View file

@ -171,7 +171,7 @@ idf2expr(expr)
add_def(idf, IMPLICIT, funint_type, level); /* RM 13 */ add_def(idf, IMPLICIT, funint_type, level); /* RM 13 */
else { else {
if (!is_anon_idf(idf)) if (!is_anon_idf(idf))
error("%s undefined", idf->id_text); error("identifier %s undefined", idf->id_text);
/* declare idf anyway */ /* declare idf anyway */
add_def(idf, 0, error_type, level); add_def(idf, 0, error_type, level);
} }

View file

@ -288,8 +288,10 @@ expr_ignored(expr)
struct expr *expr; struct expr *expr;
{ {
switch (expr->ex_class) { switch (expr->ex_class) {
int oper;
case Oper: case Oper:
switch (expr->OP_OPER) { oper = expr->OP_OPER;
switch (oper) {
case '=': case '=':
case TIMESAB: case TIMESAB:
case DIVAB: case DIVAB:
@ -304,6 +306,7 @@ expr_ignored(expr)
case '(': case '(':
case '?': case '?':
case ',': case ',':
oper = 0; /* ignore the ignoring */
break; break;
case PLUSAB: case PLUSAB:
@ -312,21 +315,32 @@ expr_ignored(expr)
case POSTDECR: case POSTDECR:
case PLUSPLUS: case PLUSPLUS:
case MINMIN: case MINMIN:
/* may hide the operator '*' */ oper = 0; /* ignore in priciple */
/* may, however, hide the operator '*' */
if ( /* operation on a pointer */ if ( /* operation on a pointer */
expr->OP_TYPE->tp_fund == POINTER expr->OP_TYPE->tp_fund == POINTER
&& /* the result is dereferenced, e.g. *p++; */ && /* the result is dereferenced, e.g. *p++; */
expr->ex_type == expr->OP_TYPE->tp_up expr->ex_type == expr->OP_TYPE->tp_up
) { ) {
hwarning("result of * ignored"); oper = '*';
} }
break; break;
default: case '/':
hwarning("result of %s ignored", /* this is a specially weird case: the '/' may
symbol2str(expr->OP_OPER)); result from pointer subtraction
*/
if ( expr->OP_TYPE->tp_fund == INT
&& expr->OP_LEFT->OP_OPER == '-'
&& expr->OP_LEFT->OP_TYPE->tp_fund == POINTER
) {
oper = '-';
}
break; break;
} }
if (oper) {
hwarning("result of %s ignored", symbol2str(oper));
}
break; break;
case Value: case Value:

View file

@ -151,7 +151,7 @@ lint_1_local(idf, def)
&& !def->df_used && !def->df_used
&& !is_anon_idf(idf) && !is_anon_idf(idf)
) { ) {
def_warning(def, "%s %s not used anywhere in function %s", def_warning(def, "%s %s not applied anywhere in function %s",
symbol2str(sc), idf->id_text, func_name); symbol2str(sc), idf->id_text, func_name);
} }
@ -309,7 +309,8 @@ change_state(idf, to_state)
case USED: case USED:
if (!a->ad_set) { if (!a->ad_set) {
if (!is_anon_idf(idf)) { if (!is_anon_idf(idf)) {
warning("%s%s uninitialized", idf->id_text, warning("variable %s%s uninitialized",
idf->id_text,
(a->ad_maybe_set ? " possibly" : "") (a->ad_maybe_set ? " possibly" : "")
); );
} }
@ -342,7 +343,7 @@ add_auto(idf) /* to current state on top of lint_stack */
a = new_auto_def(); a = new_auto_def();
a->ad_idf = idf; a->ad_idf = idf;
a->ad_def = idf->id_def; a->ad_def = def;
a->ad_used = def->df_used; a->ad_used = def->df_used;
a->ad_set = def->df_set; a->ad_set = def->df_set;
@ -361,16 +362,19 @@ check_autos()
ASSERT(!(a && a->ad_def->df_level > level)); ASSERT(!(a && a->ad_def->df_level > level));
while (a && a->ad_def->df_level == level) { while (a && a->ad_def->df_level == level) {
if (!a->ad_used && !is_anon_idf(a->ad_idf)) { struct idf *idf = a->ad_idf;
if (a->ad_set || a->ad_maybe_set) { struct def *def = idf->id_def;
def_warning(a->ad_def,
if (!def->df_used && !is_anon_idf(idf)) {
if (def->df_set || a->ad_maybe_set) {
def_warning(def,
"%s set but not used in function %s", "%s set but not used in function %s",
a->ad_idf->id_text, func_name); idf->id_text, func_name);
} }
else { else {
def_warning(a->ad_def, def_warning(def,
"%s not used anywhere in function %s", "%s not used anywhere in function %s",
a->ad_idf->id_text, func_name); idf->id_text, func_name);
} }
} }
@ -1216,6 +1220,24 @@ lint_pop()
#ifdef DEBUG #ifdef DEBUG
/* FOR DEBUGGING */ /* FOR DEBUGGING */
PRIVATE
print_autos(a)
struct auto_def *a;
{
while (a) {
struct idf *idf = a->ad_idf;
struct def *def = idf->id_def;
print("%s", idf->id_text);
print("(lvl=%d)", a->ad_def->df_level);
print("(u%ds%dm%d U%dS%d) ",
a->ad_used, a->ad_set, a->ad_maybe_set,
def->df_used, def->df_set
);
a = a->next;
}
}
PRIVATE PRIVATE
pr_lint_state(nm, st) pr_lint_state(nm, st)
char *nm; char *nm;
@ -1241,7 +1263,7 @@ print_lint_stack(msg)
while (lse) { while (lse) {
print(" |-------------- level %d ------------\n", print(" |-------------- level %d ------------\n",
lse->ls_level); lse->ls_level);
pr_lint_state(" |cur", lse->ls_current); pr_lint_state(" |current", lse->ls_current);
print(" |class == %s\n", print(" |class == %s\n",
lse->ls_class ? symbol2str(lse->ls_class) : "{"); lse->ls_class ? symbol2str(lse->ls_class) : "{");
@ -1277,16 +1299,6 @@ print_lint_stack(msg)
print(" |--------------\n\n"); print(" |--------------\n\n");
} }
print_autos(a)
register struct auto_def *a;
{
while (a) {
print("%s", a->ad_idf->id_text);
print("(lvl=%d)", a->ad_def->df_level);
print("(U%dS%dM%d) ", a->ad_used, a->ad_set, a->ad_maybe_set);
a = a->next;
}
}
#endif DEBUG #endif DEBUG
#endif LINT #endif LINT