many little changes: removed some lint complaints; max_int and max_unsigned

are now constants if NOCROSS is defined; added lexstrict and expr_strict,
and changed calls where needed
This commit is contained in:
ceriel 1989-11-08 16:52:34 +00:00
parent 636c151d51
commit 67f9f2a74f
26 changed files with 164 additions and 141 deletions

View file

@ -54,6 +54,7 @@ interface.h
ival.g ival.g
l_brace.str l_brace.str
l_class.h l_class.h
l_comment.h
l_comment.c l_comment.c
l_dummy.c l_dummy.c
l_ev_ord.c l_ev_ord.c
@ -78,8 +79,12 @@ mcomm.c
mes.h mes.h
options options
options.c options.c
pragma.c
program.g program.g
proto.c
proto.str
replace.c replace.c
replace.str
scan.c scan.c
sizes.h sizes.h
skip.c skip.c

View file

@ -8,8 +8,9 @@
!File: errout.h !File: errout.h
#define ERROUT STDERR /* file pointer for writing messages */ #define ERROUT STDERR /* file pointer for writing messages */
#define MAXERR_LINE 5 /* maximum number of error messages given #define ERR_SHADOW 5 /* a syntax error overshadows error messages
on the same input line. */ until ERR_SHADOW symbols have been
accepted without syntax error */
!File: idfsize.h !File: idfsize.h

View file

@ -25,6 +25,9 @@
/* Data about the token yielded */ /* Data about the token yielded */
struct token dot, ahead, aside; struct token dot, ahead, aside;
int token_nmb = 0; /* number of the ahead token */
int tk_nmb_at_last_syn_err = -5/*ERR_SHADOW*/;
/* token number at last syntax error */
#ifndef NOPP #ifndef NOPP
int ReplaceMacros = 1; /* replacing macros */ int ReplaceMacros = 1; /* replacing macros */
@ -42,7 +45,6 @@ int LexSave = 0; /* last character read by GetChar */
#define FLG_ESEEN 0x01 /* possibly a floating point number */ #define FLG_ESEEN 0x01 /* possibly a floating point number */
#define FLG_DOTSEEN 0x02 /* certainly a floating point number */ #define FLG_DOTSEEN 0x02 /* certainly a floating point number */
extern arith full_mask[]; extern arith full_mask[];
extern arith max_int;
#ifndef NOPP #ifndef NOPP
static struct token LexStack[MAX_LL_DEPTH]; static struct token LexStack[MAX_LL_DEPTH];
@ -114,6 +116,8 @@ GetToken(ptok)
char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1]; char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1];
register int ch, nch; register int ch, nch;
token_nmb++;
if (File_Inserted) { if (File_Inserted) {
File_Inserted = 0; File_Inserted = 0;
goto firstline; goto firstline;
@ -178,38 +182,35 @@ garbage:
case '!': case '!':
if (nch == '=') if (nch == '=')
return ptok->tk_symb = NOTEQUAL; return ptok->tk_symb = NOTEQUAL;
UnGetChar(); break;
return ptok->tk_symb = ch;
case '&': case '&':
if (nch == '&') if (nch == '&')
return ptok->tk_symb = AND; return ptok->tk_symb = AND;
else if (nch == '=') if (nch == '=')
return ptok->tk_symb = ANDAB; return ptok->tk_symb = ANDAB;
UnGetChar(); break;
return ptok->tk_symb = ch;
case '+': case '+':
if (nch == '+') if (nch == '+')
return ptok->tk_symb = PLUSPLUS; return ptok->tk_symb = PLUSPLUS;
else if (nch == '=') if (nch == '=')
return ptok->tk_symb = PLUSAB; return ptok->tk_symb = PLUSAB;
UnGetChar(); break;
return ptok->tk_symb = ch;
case '-': case '-':
if (nch == '-') if (nch == '-')
return ptok->tk_symb = MINMIN; return ptok->tk_symb = MINMIN;
else if (nch == '>') if (nch == '>')
return ptok->tk_symb = ARROW; return ptok->tk_symb = ARROW;
else if (nch == '=') if (nch == '=')
return ptok->tk_symb = MINAB; return ptok->tk_symb = MINAB;
UnGetChar(); break;
return ptok->tk_symb = ch;
case '<': case '<':
if (AccFileSpecifier) { if (AccFileSpecifier) {
UnGetChar(); /* pushback nch */ UnGetChar(); /* pushback nch */
ptok->tk_bts = string_token("file specifier", ptok->tk_bts = string_token("file specifier",
'>', &(ptok->tk_len)); '>', &(ptok->tk_len));
return ptok->tk_symb = FILESPECIFIER; return ptok->tk_symb = FILESPECIFIER;
} else if (nch == '<') { }
if (nch == '<') {
if ((nch = GetChar()) == '=') if ((nch = GetChar()) == '=')
return ptok->tk_symb = LEFTAB; return ptok->tk_symb = LEFTAB;
UnGetChar(); UnGetChar();
@ -217,13 +218,11 @@ garbage:
} }
if (nch == '=') if (nch == '=')
return ptok->tk_symb = LESSEQ; return ptok->tk_symb = LESSEQ;
UnGetChar(); break;
return ptok->tk_symb = ch;
case '=': case '=':
if (nch == '=') if (nch == '=')
return ptok->tk_symb = EQUAL; return ptok->tk_symb = EQUAL;
UnGetChar(); break;
return ptok->tk_symb = ch;
case '>': case '>':
if (nch == '=') if (nch == '=')
return ptok->tk_symb = GREATEREQ; return ptok->tk_symb = GREATEREQ;
@ -233,30 +232,25 @@ garbage:
UnGetChar(); UnGetChar();
return ptok->tk_symb = RIGHT; return ptok->tk_symb = RIGHT;
} }
UnGetChar(); break;
return ptok->tk_symb = ch;
case '|': case '|':
if (nch == '|') if (nch == '|')
return ptok->tk_symb = OR; return ptok->tk_symb = OR;
else if (nch == '=') if (nch == '=')
return ptok->tk_symb = ORAB; return ptok->tk_symb = ORAB;
UnGetChar(); break;
return ptok->tk_symb = ch;
case '%': case '%':
if (nch == '=') if (nch == '=')
return ptok->tk_symb = MODAB; return ptok->tk_symb = MODAB;
UnGetChar(); break;
return ptok->tk_symb = ch;
case '*': case '*':
if (nch == '=') if (nch == '=')
return ptok->tk_symb = TIMESAB; return ptok->tk_symb = TIMESAB;
UnGetChar(); break;
return ptok->tk_symb = ch;
case '^': case '^':
if (nch == '=') if (nch == '=')
return ptok->tk_symb = XORAB; return ptok->tk_symb = XORAB;
UnGetChar(); break;
return ptok->tk_symb = ch;
case '/': case '/':
if (nch == '*' if (nch == '*'
#ifndef NOPP #ifndef NOPP
@ -266,14 +260,15 @@ garbage:
skipcomment(); skipcomment();
goto again; goto again;
} }
else if (nch == '=') if (nch == '=')
return ptok->tk_symb = DIVAB; return ptok->tk_symb = DIVAB;
UnGetChar(); break;
return ptok->tk_symb = ch;
default: default:
crash("bad class for char 0%o", ch); crash("bad class for char 0%o", ch);
/* NOTREACHED */ /* NOTREACHED */
} }
UnGetChar();
return ptok->tk_symb = ch;
case STCHAR: /* character constant */ case STCHAR: /* character constant */
ptok->tk_ival = char_constant("character"); ptok->tk_ival = char_constant("character");
ptok->tk_fund = INT; ptok->tk_fund = INT;
@ -508,7 +503,7 @@ char_constant(nm)
ch = GetChar(); ch = GetChar();
} }
if (size > 1) if (size > 1)
strict("%s constant includes more than one character", nm); lexstrict("%s constant includes more than one character", nm);
if (size > (int)int_size) if (size > (int)int_size)
lexerror("%s constant too long", nm); lexerror("%s constant too long", nm);
return val; return val;

View file

@ -41,6 +41,8 @@ struct token {
#define tk_fval tok_data.tok_fval #define tk_fval tok_data.tok_fval
extern struct token dot, ahead, aside; extern struct token dot, ahead, aside;
extern int token_nmb; /* number of the ahead token */
extern int tk_nmb_at_last_syn_err; /* token number at last syntax error */
#ifndef NOPP #ifndef NOPP
extern int ReplaceMacros; /* "LLlex.c" */ extern int ReplaceMacros; /* "LLlex.c" */

View file

@ -22,8 +22,10 @@ LLmessage(tk) {
error("%s missing", symbol2str(tk)); error("%s missing", symbol2str(tk));
insert_token(tk); insert_token(tk);
} }
else else {
error("%s deleted", symbol2str(DOT)); error("%s deleted", symbol2str(DOT));
}
tk_nmb_at_last_syn_err = token_nmb;
} }
insert_token(tk) insert_token(tk)

View file

@ -8,8 +8,9 @@
!File: errout.h !File: errout.h
#define ERROUT STDERR /* file pointer for writing messages */ #define ERROUT STDERR /* file pointer for writing messages */
#define MAXERR_LINE 5 /* maximum number of error messages given #define ERR_SHADOW 0 /* a syntax error overshadows error messages
on the same input line. */ until ERR_SHADOW symbols have been
accepted without syntax error */
!File: idfsize.h !File: idfsize.h

View file

@ -140,9 +140,6 @@ SRC = $(CSRC) $(LCSRC) $(GCSRC)
LINT = /usr/bin/lint LINT = /usr/bin/lint
LINTFLAGS = LINTFLAGS =
MYLINT = ../lpass2/lint
MYLINTFLAGS = -xh
#EXCLEXCLEXCLEXCL #EXCLEXCLEXCLEXCL
.SUFFIXES: .str .h .SUFFIXES: .str .h
@ -198,11 +195,7 @@ cflow: Cfiles
$(CFLOW) $(CDEFS) $(SRC) $(CFLOW) $(CDEFS) $(SRC)
lint: Cfiles lint: Cfiles
sh -c 'if $(CC) nmclash.c > /dev/null 2>&1 ; then make "EMHOME="$(EMHOME) Xlint ; else sh Resolve Xlint ; fi' sh -c 'if $(CC) nmclash.c > /dev/null 2>&1 ; then make "EMHOME="$(EMHOME) LINT=$(LINT) LINTFLAGS=$(LINTFLAGS) Xlint ; else sh Resolve Xlint ; fi'
@rm -f nmclash.o a.out
mylint: Cfiles
sh -c 'if $(CC) nmclash.c > /dev/null 2>&1 ; then make "EMHOME="$(EMHOME) Xmylint ; else sh Resolve Xmylint ; fi'
@rm -f nmclash.o a.out @rm -f nmclash.o a.out
longnames: $(SRC) $(HFILES) longnames: $(SRC) $(HFILES)
@ -284,9 +277,6 @@ $(CURRDIR)lnt: $(OBJ) $(CURRDIR)Makefile
Xlint: $(SRC) Xlint: $(SRC)
$(LINT) $(CDEFS) $(LINTFLAGS) $(SRC) $(LINT) $(CDEFS) $(LINTFLAGS) $(SRC)
Xmylint: $(SRC)
$(MYLINT) $(CDEFS) $(MYLINTFLAGS) $(SRC)
#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO
main.o: LLlex.h main.o: LLlex.h
main.o: Lpars.h main.o: Lpars.h
@ -414,6 +404,7 @@ expr.o: sizes.h
expr.o: spec_arith.h expr.o: spec_arith.h
expr.o: target_sizes.h expr.o: target_sizes.h
expr.o: type.h expr.o: type.h
expr.o: use_tmp.h
ch3.o: Lpars.h ch3.o: Lpars.h
ch3.o: arith.h ch3.o: arith.h
ch3.o: assert.h ch3.o: assert.h

View file

@ -8,8 +8,9 @@
!File: errout.h !File: errout.h
#define ERROUT STDERR /* file pointer for writing messages */ #define ERROUT STDERR /* file pointer for writing messages */
#define MAXERR_LINE 5 /* maximum number of error messages given #define ERR_SHADOW 5 /* a syntax error overshadows error messages
on the same input line. */ until ERR_SHADOW symbols have been
accepted without syntax error */
!File: idfsize.h !File: idfsize.h

View file

@ -334,9 +334,9 @@ int2float(expp, tp)
exp->ex_type = tp; exp->ex_type = tp;
exp->ex_class = Float; exp->ex_class = Float;
/* exp->FL_VALUE = 0 /* Salloc(buf, (unsigned)strlen(buf)+1) */ ; exp->FL_VALUE = 0;
flt_arith2flt(exp->VL_VALUE, &(exp->FL_ARITH)); flt_arith2flt(exp->VL_VALUE, &(exp->FL_ARITH));
/* exp->FL_DATLAB = 0; */ exp->FL_DATLAB = 0;
} }
else *expp = arith2arith(tp, INT2FLOAT, *expp); else *expp = arith2arith(tp, INT2FLOAT, *expp);
} }

View file

@ -172,7 +172,7 @@ ch3cast(expp, oper, tp)
register struct type *oldtp; register struct type *oldtp;
if (oper == RETURN && tp->tp_fund == VOID) { if (oper == RETURN && tp->tp_fund == VOID) {
strict("return <expression> in function returning void"); expr_strict(*expp, "return <expression> in function returning void");
(*expp)->ex_type = void_type; (*expp)->ex_type = void_type;
return; return;
} }
@ -554,7 +554,7 @@ ch3asgn(expp, oper, expr)
if (!exp->ex_lvalue) { if (!exp->ex_lvalue) {
expr_error(exp, "no lvalue in operand of %s", oper_string); expr_error(exp, "no lvalue in operand of %s", oper_string);
} else if (exp->ex_flags & EX_ILVALUE) { } else if (exp->ex_flags & EX_ILVALUE) {
strict("incorrect lvalue in operand of %s", oper_string); expr_strict(exp, "incorrect lvalue in operand of %s", oper_string);
} else if (exp->ex_flags & EX_READONLY) { } else if (exp->ex_flags & EX_READONLY) {
expr_error(exp, "operand of %s is read-only", oper_string); expr_error(exp, "operand of %s is read-only", oper_string);
} else if (fund == STRUCT || fund == UNION) { } else if (fund == STRUCT || fund == UNION) {

View file

@ -375,11 +375,6 @@ code_declaration(idf, expr, lvl, sc)
if (def_sc == TYPEDEF) /* no code for typedefs */ if (def_sc == TYPEDEF) /* no code for typedefs */
return; return;
#ifndef PREPEND_SCOPES
if (fund == FUNCTION) {
code_scope(idf->id_text, def);
}
#endif PREPEND_SCOPES
if (lvl == L_GLOBAL) { /* global variable */ if (lvl == L_GLOBAL) { /* global variable */
/* is this an allocating declaration? */ /* is this an allocating declaration? */
if ( (sc == 0 || sc == STATIC) if ( (sc == 0 || sc == STATIC)
@ -429,9 +424,6 @@ code_declaration(idf, expr, lvl, sc)
case GLOBAL: case GLOBAL:
case IMPLICIT: case IMPLICIT:
/* we are sure there is no expression */ /* we are sure there is no expression */
#ifndef PREPEND_SCOPES
code_scope(idf->id_text, def);
#endif PREPEND_SCOPES
break; break;
case AUTO: case AUTO:
case REGISTER: case REGISTER:

View file

@ -17,8 +17,10 @@
#include "assert.h" #include "assert.h"
arith full_mask[MAXSIZE];/* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */ arith full_mask[MAXSIZE];/* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */
#ifndef NOCROSS
arith max_int; /* maximum integer on target machine */ arith max_int; /* maximum integer on target machine */
arith max_unsigned; /* maximum unsigned on target machine */ arith max_unsigned; /* maximum unsigned on target machine */
#endif /* NOCROSS */
extern int ResultKnown; extern int ResultKnown;
cstbin(expp, oper, expr) cstbin(expp, oper, expr)
@ -251,6 +253,8 @@ init_cst()
} }
if ((int)long_size > arith_size) if ((int)long_size > arith_size)
fatal("sizeof (arith) insufficient on this machine"); fatal("sizeof (arith) insufficient on this machine");
#ifndef NOCROSS
max_int = full_mask[(int)int_size] & ~(1L << ((int)int_size * 8 - 1)); max_int = full_mask[(int)int_size] & ~(1L << ((int)int_size * 8 - 1));
max_unsigned = full_mask[(int)int_size]; max_unsigned = full_mask[(int)int_size];
#endif /* NOCROSS */
} }

View file

@ -16,8 +16,6 @@
extern char options[]; extern char options[];
extern int level; extern int level;
extern char *symbol2str(); extern char *symbol2str();
extern char *type2str();
extern char *qual2str();
extern struct type *qualifier_type(); extern struct type *qualifier_type();
struct decspecs null_decspecs; struct decspecs null_decspecs;

View file

@ -213,7 +213,7 @@ int to_endif;
if (!to_endif && nestlevel == skiplevel) { if (!to_endif && nestlevel == skiplevel) {
if (SkipToNewLine()) if (SkipToNewLine())
if (!options['o']) if (!options['o'])
strict("garbage following #else"); lexstrict("garbage following #else");
NoUnstack--; NoUnstack--;
return; return;
} }
@ -224,7 +224,7 @@ int to_endif;
if (nestlevel == skiplevel) { if (nestlevel == skiplevel) {
if (SkipToNewLine()) if (SkipToNewLine())
if (!options['o']) if (!options['o'])
strict("garbage following #endif"); lexstrict("garbage following #endif");
nestlevel--; nestlevel--;
NoUnstack--; NoUnstack--;
return; return;
@ -368,7 +368,7 @@ do_else()
{ {
if (SkipToNewLine()) if (SkipToNewLine())
if (!options['o']) if (!options['o'])
strict("garbage following #else"); lexstrict("garbage following #else");
if (nestlevel <= nestlow) if (nestlevel <= nestlow)
lexerror("#else without corresponding #if"); lexerror("#else without corresponding #if");
else { /* mark this level as else-d */ else { /* mark this level as else-d */
@ -384,7 +384,7 @@ do_endif()
{ {
if (SkipToNewLine()) if (SkipToNewLine())
if (!options['o']) if (!options['o'])
strict("garbage following #endif"); lexstrict("garbage following #endif");
if (nestlevel <= nestlow) { if (nestlevel <= nestlow) {
lexerror("#endif without corresponding #if"); lexerror("#endif without corresponding #if");
} }

View file

@ -87,6 +87,19 @@ expr_error(va_alist) /* expr, fmt, args */
va_end(ap); va_end(ap);
} }
/*VARARGS*/
lexstrict(va_alist)
va_dcl
{
va_list ap;
va_start(ap);
{
_error(STRICT, FileName, LineNumber, ap);
}
va_end(ap);
}
/*VARARGS*/ /*VARARGS*/
strict(va_alist) strict(va_alist)
va_dcl va_dcl
@ -100,6 +113,24 @@ strict(va_alist)
va_end(ap); va_end(ap);
} }
/*VARARGS*/
expr_strict(va_alist) /* expr, fmt, args */
va_dcl
{
va_list ap;
va_start(ap);
{
struct expr *expr = va_arg(ap, struct expr *);
if (!(expr->ex_flags & EX_ERROR)) {
/* to prevent proliferation */
_error(STRICT, expr->ex_file, expr->ex_line, ap);
}
}
va_end(ap);
}
#ifdef DEBUG #ifdef DEBUG
/*VARARGS*/ /*VARARGS*/
debug(va_alist) debug(va_alist)
@ -269,17 +300,20 @@ _error(class, fn, ln, ap)
unsigned int ln; unsigned int ln;
va_list ap; va_list ap;
{ {
/* _error attempts to limit the number of error messages
for a given line to MAXERR_LINE.
*/
#ifndef LINT
static char *last_fn = 0;
static unsigned int last_ln = 0;
static int e_seen = 0;
#endif LINT
char *remark; char *remark;
char *fmt = va_arg(ap, char *); char *fmt = va_arg(ap, char *);
/* check visibility of message */
switch (class) {
case WARNING:
case ERROR:
case STRICT:
if (token_nmb < tk_nmb_at_last_syn_err + ERR_SHADOW)
/* warning or error message overshadowed */
return;
break;
}
/* Since name and number are gathered from different places /* Since name and number are gathered from different places
depending on the class, we first collect the relevant depending on the class, we first collect the relevant
values and then decide what to print. values and then decide what to print.
@ -338,26 +372,6 @@ _error(class, fn, ln, ap)
/*NOTREACHED*/; /*NOTREACHED*/;
} }
#ifndef LINT
if (class != DO_DEBUG) /* ??? DEBUG */
if (ln == last_ln && fn && last_fn && strcmp(fn, last_fn) == 0) {
/* we've seen this place before */
e_seen++;
if (e_seen == MAXERR_LINE)
fmt = "etc ...";
else
if (e_seen > MAXERR_LINE)
/* and too often, I'd say ! */
return;
}
else {
/* brand new place */
last_fn = fn;
last_ln = ln;
e_seen = 0;
}
#endif LINT
#ifdef LINT #ifdef LINT
if ( /* there is a file name */ if ( /* there is a file name */
fn fn

View file

@ -387,7 +387,7 @@ EVAL(expr, val, code, true_label, false_label)
case PLUSPLUS: case PLUSPLUS:
case MINMIN: case MINMIN:
{ {
arith tmp; arith tmp = 0;
int compl; /* Complexity of left operand */ int compl; /* Complexity of left operand */
int newcode = left->ex_type->tp_size > 0; /* CJ */ int newcode = left->ex_type->tp_size > 0; /* CJ */
#ifndef NOBITFIELD #ifndef NOBITFIELD
@ -803,9 +803,8 @@ store_val(vl, tp)
register struct value *vl; register struct value *vl;
register struct type *tp; register struct type *tp;
{ {
int al_on_word; register int inword = 0;
register int inword; register int indword = 0;
register int indword;
arith val = vl->vl_value; arith val = vl->vl_value;
if (vl->vl_class == Const) { /* absolute addressing */ if (vl->vl_class == Const) { /* absolute addressing */
@ -813,9 +812,10 @@ store_val(vl, tp)
store_block(tp->tp_size, tp->tp_align); store_block(tp->tp_size, tp->tp_align);
return; return;
} }
al_on_word = (tp->tp_align % word_align == 0); if (tp->tp_align % word_align == 0) {
if (!(inword = (tp->tp_size == word_size && al_on_word))) if (tp->tp_size == word_size) inword = 1;
indword = (tp->tp_size == dword_size && al_on_word); else if (tp->tp_size == dword_size) indword = 1;
}
if (vl->vl_class == Name) { if (vl->vl_class == Name) {
register struct idf *id = vl->vl_data.vl_idf; register struct idf *id = vl->vl_data.vl_idf;
register struct def *df = id->id_def; register struct def *df = id->id_def;
@ -877,8 +877,7 @@ load_val(expr, rlval)
{ {
register struct type *tp = expr->ex_type; register struct type *tp = expr->ex_type;
int rvalue = (rlval == RVAL && expr->ex_lvalue != 0); int rvalue = (rlval == RVAL && expr->ex_lvalue != 0);
int al_on_word; register int inword = 0, indword = 0;
register int inword, indword;
register arith val = expr->VL_VALUE; register arith val = expr->VL_VALUE;
if (expr->VL_CLASS == Const) { if (expr->VL_CLASS == Const) {
@ -891,9 +890,10 @@ load_val(expr, rlval)
return; return;
} }
if (rvalue) { if (rvalue) {
al_on_word = (tp->tp_align % word_align == 0); if (tp->tp_align % word_align == 0) {
if (!(inword = (tp->tp_size == word_size && al_on_word))) if (tp->tp_size == word_size) inword = 1;
indword = (tp->tp_size == dword_size && al_on_word); else if (tp->tp_size == dword_size) indword = 1;
}
} }
if (expr->VL_CLASS == Label) { if (expr->VL_CLASS == Label) {
if (rvalue) { if (rvalue) {

View file

@ -22,6 +22,7 @@
#include "declar.h" #include "declar.h"
#include "sizes.h" #include "sizes.h"
#include "level.h" #include "level.h"
#include "use_tmp.h"
extern char *symbol2str(); extern char *symbol2str();
extern char options[]; extern char options[];
@ -157,8 +158,14 @@ idf2expr(expr)
} }
else { else {
#ifndef LINT #ifndef LINT
if (!InSizeof) if (!InSizeof) {
def->df_used = 1; if (! def->df_used) {
#ifndef PREPEND_SCOPES
code_scope(idf->id_text, def);
#endif /* PREPEND_SCOPES */
def->df_used = 1;
}
}
#endif LINT #endif LINT
expr->ex_type = def->df_type; expr->ex_type = def->df_type;
if (expr->ex_type == error_type) { if (expr->ex_type == error_type) {

View file

@ -51,7 +51,7 @@ eval_field(expr, code)
register struct expr *rightop = expr->OP_RIGHT; register struct expr *rightop = expr->OP_RIGHT;
register struct field *fd = leftop->ex_type->tp_field; register struct field *fd = leftop->ex_type->tp_field;
struct type *tp = leftop->ex_type->tp_up; struct type *tp = leftop->ex_type->tp_up;
arith tmpvar; arith tmpvar = 0;
struct type *atype = tp->tp_unsigned ? uword_type : word_type; struct type *atype = tp->tp_unsigned ? uword_type : word_type;
/* First some assertions to be sure that the rest is legal */ /* First some assertions to be sure that the rest is legal */

View file

@ -31,7 +31,7 @@ fltcstbin(expp, oper, expr)
*/ */
flt_arith o1, o2; flt_arith o1, o2;
int compar = 0; int compar = 0;
int cmpval; int cmpval = 0;
o1 = (*expp)->FL_ARITH; o1 = (*expp)->FL_ARITH;
o2 = expr->FL_ARITH; o2 = expr->FL_ARITH;

View file

@ -623,10 +623,10 @@ check_formals(idf, dc)
error("incorrect number of parameters"); error("incorrect number of parameters");
} }
} else { /* make a pseudo-prototype */ } else { /* make a pseudo-prototype */
register struct proto *lpl; register struct proto *lpl = new_proto();
while (fm) { while (fm) {
if (pl == 0) pl = lpl = new_proto(); if (pl == 0) pl = lpl;
else { else {
lpl->next = new_proto(); lpl->next = new_proto();
lpl = lpl->next; lpl = lpl->next;
@ -638,7 +638,7 @@ check_formals(idf, dc)
fm = fm->next; fm = fm->next;
} }
if (pl == 0) { /* make func(void) */ if (pl == 0) { /* make func(void) */
pl = new_proto(); pl = lpl;
pl->pl_type = void_type; pl->pl_type = void_type;
pl->pl_flag = PL_VOID; pl->pl_flag = PL_VOID;
} }

View file

@ -70,13 +70,13 @@ init_pp()
tp = localtime(&clock); tp = localtime(&clock);
/* __DATE__ */ /* __DATE__ */
sprintf(dbuf, "\"%.3s %.2d %d\"", months[tp->tm_mon], sprint(dbuf, "\"%s %02d %d\"", months[tp->tm_mon],
tp->tm_mday, tp->tm_year+1900); tp->tm_mday, tp->tm_year+1900);
if (tp->tm_mday < 10) dbuf[5] = ' '; /* hack */ if (tp->tm_mday < 10) dbuf[5] = ' '; /* hack */
macro_def(str2idf("__DATE__"), dbuf, -1, strlen(dbuf), NOUNDEF); macro_def(str2idf("__DATE__"), dbuf, -1, strlen(dbuf), NOUNDEF);
/* __TIME__ */ /* __TIME__ */
sprintf(tbuf, "\"%.2d:%.2d:%.2d\"", tp->tm_hour, tp->tm_min, tp->tm_sec); sprint(tbuf, "\"%02d:%02d:%02d\"", tp->tm_hour, tp->tm_min, tp->tm_sec);
macro_def(str2idf("__TIME__"), tbuf, -1, strlen(tbuf), NOUNDEF); macro_def(str2idf("__TIME__"), tbuf, -1, strlen(tbuf), NOUNDEF);
/* __LINE__ */ /* __LINE__ */

View file

@ -12,7 +12,6 @@
#define INP_TYPE struct file_info #define INP_TYPE struct file_info
#define INP_VAR finfo #define INP_VAR finfo
struct file_info finfo; struct file_info finfo;
extern int nestlevel;
#include "nopp.h" #include "nopp.h"
#include <inp_pkg.body> #include <inp_pkg.body>
@ -42,6 +41,7 @@ getwdir(fn)
} }
int InputLevel; int InputLevel;
extern int nestlevel;
#endif NOPP #endif NOPP
int NoUnstack; int NoUnstack;

View file

@ -39,6 +39,7 @@ char *long2str();
char *strncpy(); char *strncpy();
extern char options[]; extern char options[];
static int gen_error; static int gen_error;
static int pack_level;
struct type **gen_tphead(), **gen_tpmiddle(); struct type **gen_tphead(), **gen_tpmiddle();
struct sdef *gen_align_to_next(); struct sdef *gen_align_to_next();
struct e_stack *p_stack; struct e_stack *p_stack;
@ -47,7 +48,6 @@ struct e_stack *p_stack;
/* initial_value recursively guides the initialisation expression. /* initial_value recursively guides the initialisation expression.
*/ */
/* 3.5 */ /* 3.5 */
{ static int pack_level; }
initial_value(register struct type **tpp; register struct expr **expp;) : initial_value(register struct type **tpp; register struct expr **expp;) :
{ if (tpp) gen_tpcheck(tpp); } { if (tpp) gen_tpcheck(tpp); }
@ -85,6 +85,7 @@ initial_value_pack(struct type **tpp; struct expr **expp;)
p_stack = p; p_stack = p;
} }
} }
if (pack_level < gen_error) gen_error = 0;
} }
'}' '}'
; ;
@ -117,15 +118,15 @@ gen_tpcheck(tpp)
switch((tp = *tpp)->tp_fund) { switch((tp = *tpp)->tp_fund) {
case ARRAY: case ARRAY:
if (! valid_type(tp->tp_up, "array element")) if (! valid_type(tp->tp_up, "array element"))
gen_error = 1; gen_error = pack_level;
break; break;
case STRUCT: case STRUCT:
if (! valid_type(tp, "struct")) if (! valid_type(tp, "struct"))
gen_error = 1; gen_error = pack_level;
break; break;
case UNION: case UNION:
if (! valid_type(tp, "union")) if (! valid_type(tp, "union"))
gen_error = 1; gen_error = pack_level;
break; break;
} }
} }
@ -150,7 +151,7 @@ gen_simple_exp(tpp, expp)
check_and_pad(expp, tpp); check_and_pad(expp, tpp);
break; break;
case ERRONEOUS: case ERRONEOUS:
gen_error = 1; gen_error = pack_level;
break; break;
default: default:
check_ival(expp, tp); check_ival(expp, tp);
@ -198,7 +199,7 @@ gen_tphead(tpp, nest)
register struct sdef *sd; register struct sdef *sd;
if (tpp && *tpp == error_type) { if (tpp && *tpp == error_type) {
gen_error = 1; gen_error = pack_level;
return 0; return 0;
} }
if (gen_error) return tpp; if (gen_error) return tpp;
@ -227,7 +228,7 @@ gen_tphead(tpp, nest)
#endif #endif
if (! sd) { if (! sd) {
/* something wrong with this struct */ /* something wrong with this struct */
gen_error = 1; gen_error = pack_level;
p_stack = p->next; p_stack = p->next;
free_e_stack(p); free_e_stack(p);
return 0; return 0;
@ -356,7 +357,6 @@ gen_tpend()
free_e_stack(p_stack); free_e_stack(p_stack);
p_stack = p; p_stack = p;
} }
gen_error = 0;
} }
/* check_and_pad() is given a simple initialisation expression /* check_and_pad() is given a simple initialisation expression
@ -690,12 +690,12 @@ illegal_init_cst(ex)
struct expr *ex; struct expr *ex;
{ {
expr_error(ex, "illegal initialisation constant"); expr_error(ex, "illegal initialisation constant");
gen_error = 1; gen_error = pack_level;
} }
too_many_initialisers() too_many_initialisers()
{ {
error("too many initialisers"); error("too many initialisers");
gen_error = 1; gen_error = pack_level;
} }
} }

View file

@ -49,11 +49,11 @@ check_for_void(pl)
} }
} }
add_proto(pl, ds, dc, level) add_proto(pl, ds, dc, lvl)
struct proto *pl; struct proto *pl;
struct decspecs *ds; struct decspecs *ds;
struct declarator *dc; struct declarator *dc;
int level; int lvl;
{ {
/* The full typed identifier or abstract type, described /* The full typed identifier or abstract type, described
by the structures decspecs and declarator are turned by the structures decspecs and declarator are turned
@ -102,7 +102,7 @@ add_proto(pl, ds, dc, level)
sc = (ds->ds_sc_given && ds->ds_sc != REGISTER) ? sc = (ds->ds_sc_given && ds->ds_sc != REGISTER) ?
0 : sc == 0 ? FORMAL : REGISTER; 0 : sc == 0 ? FORMAL : REGISTER;
if (def && (def->df_level == level /* || def->df_level < L_PROTO */ )) { if (def && (def->df_level == lvl /* || def->df_level < L_PROTO */ )) {
/* redeclaration at the same level */ /* redeclaration at the same level */
error("parameter %s redeclared", idf->id_text); error("parameter %s redeclared", idf->id_text);
} else if (idf != (struct idf *)0) { } else if (idf != (struct idf *)0) {
@ -111,7 +111,7 @@ add_proto(pl, ds, dc, level)
register struct def *newdef = new_def(); register struct def *newdef = new_def();
newdef->next = def; newdef->next = def;
newdef->df_level = level; newdef->df_level = lvl;
newdef->df_sc = sc; newdef->df_sc = sc;
newdef->df_type = type; newdef->df_type = type;
newdef->df_formal_array = formal_array; newdef->df_formal_array = formal_array;
@ -412,9 +412,9 @@ call_proto(expp)
/* stack up the parameter expressions */ /* stack up the parameter expressions */
while (right->ex_class == Oper && right->OP_OPER == PARCOMMA) { while (right->ex_class == Oper && right->OP_OPER == PARCOMMA) {
if (ecnt == STDC_NPARAMS) if (ecnt == STDC_NPARAMS)
strict("number of parameters exceeds ANSI limit"); expr_strict(right, "number of parameters exceeds ANSI limit");
if (ecnt >= NPARAMS-1) { if (ecnt >= NPARAMS-1) {
error("too many parameters"); expr_error(right, "too many parameters");
return; return;
} }
estack[ecnt++] = &(right->OP_RIGHT); estack[ecnt++] = &(right->OP_RIGHT);
@ -427,7 +427,7 @@ call_proto(expp)
parameters. parameters.
*/ */
if (pl && pl->pl_flag & PL_VOID) { if (pl && pl->pl_flag & PL_VOID) {
strict("no parameters expected"); expr_strict(*expp, "no parameters expected");
pl = NO_PROTO; pl = NO_PROTO;
} }
@ -451,7 +451,7 @@ call_proto(expp)
checked nor converted ! checked nor converted !
*/ */
if (pcnt < 0) { if (pcnt < 0) {
error("more parameters than specified in prototype"); expr_error(*expp, "more parameters than specified in prototype");
break; break;
} }
else if (!(pstack[pcnt]->pl_flag & PL_ELLIPSIS)) { else if (!(pstack[pcnt]->pl_flag & PL_ELLIPSIS)) {
@ -461,10 +461,10 @@ call_proto(expp)
any2parameter(estack[ecnt]); any2parameter(estack[ecnt]);
} }
if (pcnt >= 0 && !(pstack[0]->pl_flag & PL_ELLIPSIS)) if (pcnt >= 0 && !(pstack[0]->pl_flag & PL_ELLIPSIS))
error("less parameters than specified in prototype"); expr_error(*expp, "less parameters than specified in prototype");
} else { } else {
if (pl && !(pl->pl_flag & PL_VOID)) if (pl && !(pl->pl_flag & PL_VOID))
error("less parameters than specified in prototype"); expr_error(*expp, "less parameters than specified in prototype");
} }
} }

View file

@ -30,6 +30,7 @@
extern struct idf *GetIdentifier(); extern struct idf *GetIdentifier();
extern int InputLevel; extern int InputLevel;
struct repl *ReplaceList; /* list of currently active macros */ struct repl *ReplaceList; /* list of currently active macros */
extern char *strcat(), *strcpy();
int int
replace(idf) replace(idf)
@ -221,7 +222,7 @@ getactuals(repl, idf)
args->a_expvec[argcnt] = args->a_expptr; args->a_expvec[argcnt] = args->a_expptr;
args->a_rawvec[argcnt] = args->a_rawptr; args->a_rawvec[argcnt] = args->a_rawptr;
if (argcnt == STDC_NPARAMS) if (argcnt == STDC_NPARAMS)
strict("number of parameters exceeds ANSI standard"); lexstrict("number of parameters exceeds ANSI standard");
if (argcnt >= NPARAMS) if (argcnt >= NPARAMS)
fatal("argument vector overflow"); fatal("argument vector overflow");
} }

View file

@ -13,6 +13,8 @@ extern arith
short_size, word_size, dword_size, int_size, long_size, short_size, word_size, dword_size, int_size, long_size,
float_size, double_size, lngdbl_size, float_size, double_size, lngdbl_size,
pointer_size; pointer_size;
extern arith max_int, max_unsigned; /* cstoper.c */
#else NOCROSS #else NOCROSS
#define short_size (SZ_SHORT) #define short_size (SZ_SHORT)
#define word_size (SZ_WORD) #define word_size (SZ_WORD)
@ -23,6 +25,13 @@ extern arith
#define double_size (SZ_DOUBLE) #define double_size (SZ_DOUBLE)
#define lngdbl_size (SZ_LNGDBL) #define lngdbl_size (SZ_LNGDBL)
#define pointer_size (SZ_POINTER) #define pointer_size (SZ_POINTER)
#if int_size == 2
#define max_int ((arith)32767)
#define max_unsigned ((arith)65535)
#else /* int_size == 4 */
#define max_int ((arith)2147483647)
#define max_unsigned ((arith)4294967295)
#endif
#endif NOCROSS #endif NOCROSS
extern arith max_int, max_unsigned; /* cstoper.c */