more lint code

This commit is contained in:
dick 1989-03-06 15:17:39 +00:00
parent bb7b8d6490
commit 1d0b3910b2
10 changed files with 578 additions and 412 deletions

View file

@ -929,7 +929,6 @@ declar.o: field.h
declar.o: file_info.h declar.o: file_info.h
declar.o: idf.h declar.o: idf.h
declar.o: l_lint.h declar.o: l_lint.h
declar.o: l_state.h
declar.o: label.h declar.o: label.h
declar.o: level.h declar.o: level.h
declar.o: lint.h declar.o: lint.h
@ -953,7 +952,6 @@ statement.o: expr.h
statement.o: file_info.h statement.o: file_info.h
statement.o: idf.h statement.o: idf.h
statement.o: l_lint.h statement.o: l_lint.h
statement.o: l_state.h
statement.o: label.h statement.o: label.h
statement.o: lint.h statement.o: lint.h
statement.o: nobitfield.h statement.o: nobitfield.h
@ -986,7 +984,7 @@ program.o: def.h
program.o: expr.h program.o: expr.h
program.o: file_info.h program.o: file_info.h
program.o: idf.h program.o: idf.h
program.o: l_state.h program.o: l_lint.h
program.o: label.h program.o: label.h
program.o: lint.h program.o: lint.h
program.o: nobitfield.h program.o: nobitfield.h

View file

@ -280,10 +280,15 @@ ch7bin(expp, oper, expr)
break; break;
case ',': case ',':
if (is_cp_cst(*expp)) if (is_cp_cst(*expp)) {
#ifdef LINT
hwarning("constant expression ignored");
#endif LINT
*expp = expr; *expp = expr;
else }
else {
*expp = new_oper(expr->ex_type, *expp, oper, expr); *expp = new_oper(expr->ex_type, *expp, oper, expr);
}
(*expp)->ex_flags |= EX_COMMA; (*expp)->ex_flags |= EX_COMMA;
break; break;
} }

View file

@ -27,7 +27,6 @@
#include "level.h" #include "level.h"
#ifdef LINT #ifdef LINT
#include "l_lint.h" #include "l_lint.h"
#include "l_state.h"
#endif LINT #endif LINT
extern char options[]; extern char options[];

View file

@ -353,7 +353,7 @@ declare_idf(ds, dc, lvl)
newdef->df_file = idf->id_file; newdef->df_file = idf->id_file;
newdef->df_line = idf->id_line; newdef->df_line = idf->id_line;
#ifdef LINT #ifdef LINT
newdef->df_set = (type->tp_fund == ARRAY); newdef->df_set = 0;
newdef->df_firstbrace = 0; newdef->df_firstbrace = 0;
#endif LINT #endif LINT
@ -490,11 +490,17 @@ global_redecl(idf, new_sc, tp)
error("cannot redeclare %s to static", error("cannot redeclare %s to static",
idf->id_text); idf->id_text);
else { else {
#ifdef LINT /* warn unconditionally */
warning("%s redeclared to static",
idf->id_text);
#else LINT
#ifndef NOROPTION #ifndef NOROPTION
/* warn conditionally */
if (options['R']) if (options['R'])
warning("%s redeclared to static", warning("%s redeclared to static",
idf->id_text); idf->id_text);
#endif #endif NOROPTION
#endif LINT
def->df_sc = STATIC; def->df_sc = STATIC;
} }
break; break;

View file

@ -255,14 +255,6 @@ oper2state(expr, val, used)
case GREATEREQ: case GREATEREQ:
case EQUAL: case EQUAL:
case NOTEQUAL: case NOTEQUAL:
lint_relop(left, right, oper);
lint_relop(right, left,
oper == '<' ? '>' :
oper == '>' ? '<' :
oper == LESSEQ ? GREATEREQ :
oper == GREATEREQ ? LESSEQ :
oper
);
goto dyadic; goto dyadic;
/* dyadic operators */ /* dyadic operators */
@ -338,11 +330,16 @@ expr_ignored(expr)
break; break;
case Value: case Value:
hwarning("value as statement"); if (expr->VL_CLASS == Const) {
hwarning("constant expression ignored");
}
else {
hwarning("value ignored");
}
break; break;
default: /* String Float */ default: /* String Float */
hwarning("constant as statement"); hwarning("constant ignored");
break; break;
} }
} }

View file

@ -12,35 +12,52 @@
* control of the program. * control of the program.
*/ */
#define TEST_VAR 0 /* not a constant */
#define TEST_TRUE 1 /* always true */
#define TEST_FALSE 2 /* always false */
struct switch_states { struct loop_state { /* used in lint_end_state only */
int lps_test; /* is the test a constant? */
struct state *lps_body;
struct state *lps_loop;
};
struct switch_state { /* used in lint_end_state only */
struct state *sws_case; struct state *sws_case;
struct state *sws_break; struct state *sws_break;
int sws_default_met; int sws_default_met;
}; };
/* This union describes the (possibly incomplete) state at the end of the
mentioned construct.
*/
union lint_end_state { /* used in lint_stack_entry only */
struct state *ule_if;
struct loop_state ule_loop;
struct switch_state ule_switch;
};
struct lint_stack_entry { struct lint_stack_entry {
struct lint_stack_entry *next; struct lint_stack_entry *next;
struct lint_stack_entry *ls_previous; struct lint_stack_entry *ls_previous;
short ls_class; /* IF, WHILE, DO, FOR, SWITCH, CASE */
int ls_level; int ls_level;
struct state *ls_current; /* used by all classes */ struct state *ls_current; /* used by all classes */
union { short ls_class; /* IF, WHILE, DO, FOR, SWITCH, CASE */
struct state *u_if_state; /* used for IF-class */ union lint_end_state ls_end;
struct state *u_end; /* used for loop-classes */
struct switch_states u_switch;
} ls_states; /* not used for CASE-class */
}; };
/* macros to access the union */
#define LS_IF_STATE ls_states.u_if_state
#define LS_END ls_states.u_end
#define LS_CASE ls_states.u_switch.sws_case
#define LS_BREAK ls_states.u_switch.sws_break
#define LS_DEFAULT_MET ls_states.u_switch.sws_default_met
/* ALLOCDEF "lint_stack_entry" 10 */ /* ALLOCDEF "lint_stack_entry" 10 */
/* macros to access the union */
#define LS_IF ls_end.ule_if
#define LS_TEST ls_end.ule_loop.lps_test
#define LS_BODY ls_end.ule_loop.lps_body
#define LS_LOOP ls_end.ule_loop.lps_loop
#define LS_CASE ls_end.ule_switch.sws_case
#define LS_BREAK ls_end.ule_switch.sws_break
#define LS_DEFAULT_MET ls_end.ule_switch.sws_default_met
/* describes a branch in the program, with its local idfs */
struct state { struct state {
struct state *next; /* only used by memory allocator */ struct state *next; /* only used by memory allocator */
struct auto_def *st_auto_list; struct auto_def *st_auto_list;
@ -50,6 +67,7 @@ struct state {
/* ALLOCDEF "state" 15 */ /* ALLOCDEF "state" 15 */
/* describes the state of a local idf in a given branch of the program */
struct auto_def { struct auto_def {
struct auto_def *next; struct auto_def *next;
struct idf *ad_idf; struct idf *ad_idf;
@ -61,13 +79,14 @@ struct auto_def {
/* ALLOCDEF "auto_def" 20 */ /* ALLOCDEF "auto_def" 20 */
struct expr_state { /* describes the state of an idf during expression evaluation */
struct expr_state { /*actually concerns idfs only */
struct expr_state *next; struct expr_state *next;
struct idf *es_idf; struct idf *es_idf; /* the idf with its offset */
arith es_offset; arith es_offset;
int es_used; int es_used; /* value has been used */
int es_referred; int es_referred; /* address has been taken */
int es_set; int es_set; /* has been assigned to */
}; };
/* ALLOCDEF "expr_state" 20 */ /* ALLOCDEF "expr_state" 20 */

File diff suppressed because it is too large Load diff

View file

@ -58,7 +58,7 @@
#include "expr.h" #include "expr.h"
#include "def.h" #include "def.h"
#ifdef LINT #ifdef LINT
#include "l_state.h" #include "l_lint.h"
#endif LINT #endif LINT
#ifndef NOPP #ifndef NOPP
@ -205,11 +205,11 @@ function(struct decspecs *ds; struct declarator *dc;)
{ {
end_proc(fbytes); end_proc(fbytes);
#ifdef LINT #ifdef LINT
lint_return_stmt(0); /* implicit return at end of function */ lint_implicit_return();
#endif LINT #endif LINT
unstack_level(); /* L_FORMAL2 declarations */ unstack_level(); /* L_FORMAL2 declarations */
#ifdef LINT #ifdef LINT
check_args_used(); lint_end_formals();
#endif LINT #endif LINT
unstack_level(); /* L_FORMAL1 declarations */ unstack_level(); /* L_FORMAL1 declarations */
#ifdef LINT #ifdef LINT

View file

@ -101,7 +101,7 @@ unstack_level()
#endif DEBUG #endif DEBUG
#ifdef LINT #ifdef LINT
lint_local_level(local_level); lint_end_local(local_level);
#endif LINT #endif LINT
/* The implementation below is more careful than strictly /* The implementation below is more careful than strictly
@ -177,7 +177,7 @@ unstack_world()
register struct stack_entry *se = local_level->sl_entry; register struct stack_entry *se = local_level->sl_entry;
#ifdef LINT #ifdef LINT
lint_global_level(local_level); lint_end_global(local_level);
#endif LINT #endif LINT
open_name_list(); open_name_list();

View file

@ -23,13 +23,12 @@
#include "def.h" #include "def.h"
#ifdef LINT #ifdef LINT
#include "l_lint.h" #include "l_lint.h"
#include "l_state.h"
#endif LINT #endif LINT
extern int level; extern int level;
} }
/* Each statement construction is stacked in order to trace a /* Each statement construction is stacked in order to trace a ???
statement to such a construction. Example: a case statement should statement to such a construction. Example: a case statement should
be recognized as a piece of the most enclosing switch statement. be recognized as a piece of the most enclosing switch statement.
*/ */
@ -209,18 +208,16 @@ while_statement
if (expr->VL_VALUE == (arith)0) { if (expr->VL_VALUE == (arith)0) {
C_bra(l_break); C_bra(l_break);
} }
#ifdef LINT
start_loop_stmt(WHILE, 1,
expr->VL_VALUE != (arith)0);
#endif LINT
} }
else { else {
code_expr(expr, RVAL, TRUE, l_body, l_break); code_expr(expr, RVAL, TRUE, l_body, l_break);
C_df_ilb(l_body); C_df_ilb(l_body);
#ifdef LINT
start_loop_stmt(WHILE, 0, 0);
#endif LINT
} }
#ifdef LINT
start_while_stmt(expr);
#endif LINT
} }
')' ')'
statement statement
@ -230,6 +227,7 @@ while_statement
unstack_stmt(); unstack_stmt();
free_expression(expr); free_expression(expr);
#ifdef LINT #ifdef LINT
end_loop_body();
end_loop_stmt(); end_loop_stmt();
#endif LINT #endif LINT
} }
@ -246,13 +244,17 @@ do_statement
{ C_df_ilb(l_body); { C_df_ilb(l_body);
stack_stmt(l_break, l_continue); stack_stmt(l_break, l_continue);
#ifdef LINT #ifdef LINT
start_loop_stmt(DO, 1, 1); start_do_stmt();
#endif LINT #endif LINT
} }
statement statement
WHILE WHILE
'(' '('
{ C_df_ilb(l_continue); {
#ifdef LINT
end_loop_body();
#endif LINT
C_df_ilb(l_continue);
} }
expression(&expr) expression(&expr)
{ {
@ -287,9 +289,6 @@ for_statement
label l_continue = text_label(); label l_continue = text_label();
label l_body = text_label(); label l_body = text_label();
label l_test = text_label(); label l_test = text_label();
#ifdef LINT
int const = 1, cond = 1; /* the default case */
#endif LINT
} }
: :
FOR FOR
@ -312,17 +311,10 @@ for_statement
if (e_test->VL_VALUE == (arith)0) { if (e_test->VL_VALUE == (arith)0) {
C_bra(l_break); C_bra(l_break);
} }
#ifdef LINT
const = 1,
cond = e_test->VL_VALUE != (arith)0;
#endif LINT
} }
else { else {
code_expr(e_test, RVAL, TRUE, l_body, l_break); code_expr(e_test, RVAL, TRUE, l_body, l_break);
C_df_ilb(l_body); C_df_ilb(l_body);
#ifdef LINT
const = 0, cond = 0;
#endif LINT
} }
} }
]? ]?
@ -331,13 +323,13 @@ for_statement
')' ')'
{ {
#ifdef LINT #ifdef LINT
start_loop_stmt(FOR, const, cond); start_for_stmt(e_test);
#endif LINT #endif LINT
} }
statement statement
{ {
#ifdef LINT #ifdef LINT
end_loop_stmt(); end_loop_body();
#endif LINT #endif LINT
C_df_ilb(l_continue); C_df_ilb(l_continue);
if (e_incr) if (e_incr)
@ -349,6 +341,9 @@ for_statement
free_expression(e_init); free_expression(e_init);
free_expression(e_test); free_expression(e_test);
free_expression(e_incr); free_expression(e_incr);
#ifdef LINT
end_loop_stmt();
#endif LINT
} }
; ;
@ -423,7 +418,7 @@ return_statement
do_return_expr(expr); do_return_expr(expr);
free_expression(expr); free_expression(expr);
#ifdef LINT #ifdef LINT
lint_return_stmt(1); lint_return_stmt(VALRETURNED);
#endif LINT #endif LINT
} }
| |
@ -431,7 +426,7 @@ return_statement
{ {
do_return(); do_return();
#ifdef LINT #ifdef LINT
lint_return_stmt(0); lint_return_stmt(NOVALRETURNED);
#endif LINT #endif LINT
} }
] ]