squeezing for MINIX

This commit is contained in:
eck 1989-10-18 13:12:31 +00:00
parent 84297d3460
commit 8ff400fd0f
10 changed files with 70 additions and 95 deletions

View file

@ -11,7 +11,6 @@ LintPars
align.h align.h
arith.c arith.c
arith.h arith.h
asm.c
assert.h assert.h
atw.h atw.h
blocks.c blocks.c

View file

@ -581,7 +581,7 @@ quoted(ch)
for (;;) { for (;;) {
ch = GetChar(); ch = GetChar();
if (vch = val_in_base(ch, 16), vch == -1) if (vch = hex_val(ch), vch == -1)
break; break;
hex = hex * 16 + vch; hex = hex * 16 + vch;
} }
@ -605,22 +605,12 @@ quoted(ch)
int int
val_in_base(ch, base) hex_val(ch)
register int ch; register int ch;
{ {
switch (base) { return is_dig(ch) ? ch - '0'
case 8:
return (is_dig(ch) && ch < '9') ? ch - '0' : -1;
case 10:
return is_dig(ch) ? ch - '0' : -1;
case 16:
return is_dig(ch) ? ch - '0'
: is_hex(ch) ? (ch - 'a' + 10) & 017 : is_hex(ch) ? (ch - 'a' + 10) & 017
: -1; : -1;
default:
fatal("(val_in_base) illegal base value %d", base);
/* NOTREACHED */
}
} }
@ -763,10 +753,7 @@ struct token *ptok;
ubound = max_arith / (base / 2); ubound = max_arith / (base / 2);
while (is_hex(*cp)) { while (is_hex(*cp)) {
dig = is_dig(*cp) ? *cp - '0' dig = hex_val(*cp);
: (( *cp >= 'A' && *cp <= 'F' ? *cp - 'A'
: *cp - 'a')
+ 10) ;
if (dig >= base) { if (dig >= base) {
malformed++; /* ignore */ malformed++; /* ignore */
} }

View file

@ -50,7 +50,6 @@ extern int UnknownIdIsZero; /* "LLlex.c" */
#endif NOPP #endif NOPP
extern int EoiForNewline; /* "LLlex.c" */ extern int EoiForNewline; /* "LLlex.c" */
extern int AccFileSpecifier; /* "LLlex.c" */ extern int AccFileSpecifier; /* "LLlex.c" */
extern int SkipEscNewline; /* "LLlex.c" */
extern int File_Inserted; /* "LLlex.c" */ extern int File_Inserted; /* "LLlex.c" */
extern int NoUnstack; /* buffer.c */ extern int NoUnstack; /* buffer.c */

View file

@ -342,14 +342,11 @@ equal_type(tp, otp, check_qual)
{ {
if (tp == otp) if (tp == otp)
return 1; return 1;
if (!tp || !otp) if (!tp
return 0; || !otp
|| (tp->tp_fund != otp->tp_fund)
if (tp->tp_fund != otp->tp_fund) || (tp->tp_unsigned != otp->tp_unsigned)
return 0; || (tp->tp_align != otp->tp_align))
if (tp->tp_unsigned != otp->tp_unsigned)
return 0;
if (tp->tp_align != otp->tp_align)
return 0; return 0;
if (tp->tp_fund != ARRAY /* && tp->tp_fund != STRUCT */ ) { /* UNION ??? */ if (tp->tp_fund != ARRAY /* && tp->tp_fund != STRUCT */ ) { /* UNION ??? */
if (tp->tp_size != otp->tp_size) if (tp->tp_size != otp->tp_size)

View file

@ -41,8 +41,7 @@
#define is_oct(ch) (isoct[ch]) #define is_oct(ch) (isoct[ch])
#define is_dig(ch) (isdig[ch]) #define is_dig(ch) (isdig[ch])
#define is_hex(ch) (ishex[ch]) #define is_hex(ch) (ishex[ch])
#define is_suf(ch) (issuf[ch])
#define is_wsp(ch) (iswsp[ch]) #define is_wsp(ch) (iswsp[ch])
extern char tkclass[]; extern char tkclass[];
extern char inidf[], isoct[], isdig[], ishex[], issuf[], iswsp[]; extern char inidf[], isoct[], isdig[], ishex[], iswsp[];

View file

@ -110,19 +110,22 @@ other_specifier(register struct decspecs *ds;)
} }
| |
/* This qualifier applies to the top type. /* This qualifier applies to the top type.
E.g. const float * is a pointer to const float. E.g. volatile float * is a pointer to volatile float.
*/ */
[ VOLATILE | CONST ] VOLATILE
{ if (DOT == VOLATILE) { { if (ds->ds_typequal & TQ_VOLATILE)
if (ds->ds_typequal & TQ_VOLATILE) error("repeated type qualifier");
error("repeated type qualifier"); ds->ds_typequal |= TQ_VOLATILE;
ds->ds_typequal |= TQ_VOLATILE; }
} |
if (DOT == CONST) { /* This qualifier applies to the top type.
if (ds->ds_typequal & TQ_CONST) E.g. volatile float * is a pointer to volatile float.
error("repeated type qualifier"); */
ds->ds_typequal |= TQ_CONST; CONST
} {
if (ds->ds_typequal & TQ_CONST)
error("repeated type qualifier");
ds->ds_typequal |= TQ_CONST;
} }
; ;
@ -692,28 +695,20 @@ pointer(int *qual;)
/* 3.5.4 */ /* 3.5.4 */
type_qualifier_list(int *qual;) type_qualifier_list(int *qual;)
: :
[
[ VOLATILE | CONST ]
{ *qual = (DOT == VOLATILE) ? TQ_VOLATILE : TQ_CONST; }
[
[ VOLATILE | CONST ]
{ if (DOT == VOLATILE) {
if (*qual & TQ_VOLATILE)
error("repeated type qualifier");
*qual |= TQ_VOLATILE;
}
if (DOT == CONST) {
if (*qual & TQ_CONST)
error("repeated type qualifier");
*qual |= TQ_CONST;
}
}
]*
|
empty
{ *qual = 0; } { *qual = 0; }
] [
VOLATILE
{ if (*qual & TQ_VOLATILE)
error("repeated type qualifier");
*qual |= TQ_VOLATILE;
}
|
CONST
{ if (*qual & TQ_CONST)
error("repeated type qualifier");
*qual |= TQ_CONST;
}
]*
; ;
empty: empty:

View file

@ -52,7 +52,7 @@ GetIdentifier(skiponerr)
ReplaceMacros = 1; ReplaceMacros = 1;
UnknownIdIsZero = tmp; UnknownIdIsZero = tmp;
if (tok != IDENTIFIER) { if (tok != IDENTIFIER) {
if (skiponerr && tok != EOI) SkipToNewLine(0); if (skiponerr && tok != EOI) SkipToNewLine();
return (struct idf *)0; return (struct idf *)0;
} }
return tk.tk_idf; return tk.tk_idf;
@ -108,7 +108,7 @@ domacro()
*/ */
if (GetToken(&tk) != INTEGER) { if (GetToken(&tk) != INTEGER) {
error("bad #line syntax"); error("bad #line syntax");
SkipToNewLine(0); SkipToNewLine();
} }
else else
do_line((unsigned int)tk.tk_ival); do_line((unsigned int)tk.tk_ival);
@ -125,7 +125,7 @@ domacro()
default: default:
/* invalid word seen after the '#' */ /* invalid word seen after the '#' */
lexerror("%s: unknown control", tk.tk_idf->id_text); lexerror("%s: unknown control", tk.tk_idf->id_text);
SkipToNewLine(0); SkipToNewLine();
} }
break; break;
case INTEGER: /* # <integer> [<filespecifier>]? */ case INTEGER: /* # <integer> [<filespecifier>]? */
@ -135,7 +135,7 @@ domacro()
break; break;
default: /* invalid token following '#' */ default: /* invalid token following '#' */
lexerror("illegal # line"); lexerror("illegal # line");
SkipToNewLine(0); SkipToNewLine();
} }
EoiForNewline = 0; EoiForNewline = 0;
} }
@ -167,14 +167,14 @@ int to_endif;
return; return;
} }
UnGetChar(); UnGetChar();
SkipToNewLine(0); SkipToNewLine();
continue; continue;
} }
ReplaceMacros = 0; ReplaceMacros = 0;
toknum = GetToken(&tk); toknum = GetToken(&tk);
ReplaceMacros = 1; ReplaceMacros = 1;
if (toknum != IDENTIFIER) { if (toknum != IDENTIFIER) {
SkipToNewLine(0); SkipToNewLine();
continue; continue;
} }
/* an IDENTIFIER: look for #if, #ifdef and #ifndef /* an IDENTIFIER: look for #if, #ifdef and #ifndef
@ -184,13 +184,13 @@ int to_endif;
*/ */
switch(tk.tk_idf->id_resmac) { switch(tk.tk_idf->id_resmac) {
default: default:
SkipToNewLine(0); SkipToNewLine();
break; break;
case K_IF: case K_IF:
case K_IFDEF: case K_IFDEF:
case K_IFNDEF: case K_IFNDEF:
push_if(); push_if();
SkipToNewLine(0); SkipToNewLine();
break; break;
case K_ELIF: case K_ELIF:
if (ifstack[nestlevel]) if (ifstack[nestlevel])
@ -203,30 +203,30 @@ int to_endif;
return; return;
} }
} }
else SkipToNewLine(0); /* otherwise done in ifexpr() */ else SkipToNewLine(); /* otherwise done in ifexpr() */
break; break;
case K_ELSE: case K_ELSE:
if (ifstack[nestlevel]) if (ifstack[nestlevel])
lexerror("#else after #else"); lexerror("#else after #else");
++(ifstack[nestlevel]); ++(ifstack[nestlevel]);
if (!to_endif && nestlevel == skiplevel) { if (!to_endif && nestlevel == skiplevel) {
if (SkipToNewLine(1)) if (SkipToNewLine())
strict("garbage following #else"); strict("garbage following #else");
NoUnstack--; NoUnstack--;
return; return;
} }
else SkipToNewLine(0); else SkipToNewLine();
break; break;
case K_ENDIF: case K_ENDIF:
ASSERT(nestlevel > nestlow); ASSERT(nestlevel > nestlow);
if (nestlevel == skiplevel) { if (nestlevel == skiplevel) {
if (SkipToNewLine(1)) if (SkipToNewLine())
strict("garbage following #endif"); strict("garbage following #endif");
nestlevel--; nestlevel--;
NoUnstack--; NoUnstack--;
return; return;
} }
else SkipToNewLine(0); else SkipToNewLine();
nestlevel--; nestlevel--;
break; break;
} }
@ -273,7 +273,7 @@ do_include()
filenm = (char *)0; filenm = (char *)0;
} }
AccFileSpecifier = 0; AccFileSpecifier = 0;
SkipToNewLine(0); SkipToNewLine();
inctable[0] = WorkingDir; inctable[0] = WorkingDir;
if (filenm) { if (filenm) {
if (!InsertFile(filenm, &inctable[tok==FILESPECIFIER],&result)){ if (!InsertFile(filenm, &inctable[tok==FILESPECIFIER],&result)){
@ -313,7 +313,7 @@ do_define()
ch = GetChar(); ch = GetChar();
if (ch == '(') { if (ch == '(') {
if ((nformals = getparams(formals, parbuf)) == -1) { if ((nformals = getparams(formals, parbuf)) == -1) {
SkipToNewLine(0); SkipToNewLine();
return; /* an error occurred */ return; /* an error occurred */
} }
ch = GetChar(); ch = GetChar();
@ -348,12 +348,12 @@ do_elif()
{ {
if (nestlevel <= nestlow) { if (nestlevel <= nestlow) {
lexerror("#elif without corresponding #if"); lexerror("#elif without corresponding #if");
SkipToNewLine(0); SkipToNewLine();
} }
else { /* restart at this level as if a #if is detected. */ else { /* restart at this level as if a #if is detected. */
if (ifstack[nestlevel]) { if (ifstack[nestlevel]) {
lexerror("#elif after #else"); lexerror("#elif after #else");
SkipToNewLine(0); SkipToNewLine();
} }
nestlevel--; nestlevel--;
push_if(); push_if();
@ -363,7 +363,7 @@ do_elif()
do_else() do_else()
{ {
if (SkipToNewLine(1)) if (SkipToNewLine())
strict("garbage following #else"); strict("garbage following #else");
if (nestlevel <= nestlow) if (nestlevel <= nestlow)
lexerror("#else without corresponding #if"); lexerror("#else without corresponding #if");
@ -378,7 +378,7 @@ do_else()
do_endif() do_endif()
{ {
if (SkipToNewLine(1)) if (SkipToNewLine())
strict("garbage following #endif"); strict("garbage following #endif");
if (nestlevel <= nestlow) { if (nestlevel <= nestlow) {
lexerror("#endif without corresponding #if"); lexerror("#endif without corresponding #if");
@ -409,7 +409,7 @@ do_ifdef(how)
if (how ^ (id && id->id_macro != 0)) if (how ^ (id && id->id_macro != 0))
skip_block(0); skip_block(0);
else if (id) else if (id)
SkipToNewLine(0); SkipToNewLine();
} }
do_undef() do_undef()
@ -427,7 +427,7 @@ do_undef()
id->id_macro = (struct macro *) 0; id->id_macro = (struct macro *) 0;
} }
} /* else: don't complain */ } /* else: don't complain */
SkipToNewLine(0); SkipToNewLine();
} }
else else
lexerror("illegal #undef construction"); lexerror("illegal #undef construction");
@ -707,7 +707,7 @@ GetIdentifier(skiponerr)
tok = GetToken(&tk); tok = GetToken(&tk);
if (tok != IDENTIFIER) { if (tok != IDENTIFIER) {
if (skiponerr && tok != EOI) SkipToNewLine(0); if (skiponerr && tok != EOI) SkipToNewLine();
return (struct idf *)0; return (struct idf *)0;
} }
return tk.tk_idf; return tk.tk_idf;
@ -723,7 +723,7 @@ domacro()
if (strcmp(tk.tk_idf->id_text, "line") if (strcmp(tk.tk_idf->id_text, "line")
&& strcmp(tk.tk_idf->id_text, "pragma")) { && strcmp(tk.tk_idf->id_text, "pragma")) {
error("illegal # line"); error("illegal # line");
SkipToNewLine(0); SkipToNewLine();
return; return;
} }
else if ( !strcmp(tk.tk_idf->id_text, "pragma")) { else if ( !strcmp(tk.tk_idf->id_text, "pragma")) {
@ -735,7 +735,7 @@ domacro()
} }
if (tok != INTEGER) { if (tok != INTEGER) {
error("illegal # line"); error("illegal # line");
SkipToNewLine(0); SkipToNewLine();
return; return;
} }
do_line((unsigned int) tk.tk_ival); do_line((unsigned int) tk.tk_ival);
@ -752,5 +752,5 @@ do_line(l)
LineNumber = l - 1; /* the number of the next input line */ LineNumber = l - 1; /* the number of the next input line */
if (GetToken(&tk) == STRING) /* is there a filespecifier? */ if (GetToken(&tk) == STRING) /* is there a filespecifier? */
FileName = tk.tk_bts; FileName = tk.tk_bts;
SkipToNewLine(0); SkipToNewLine();
} }

View file

@ -577,7 +577,7 @@ ch_array(tpp, ex)
} }
/* throw out the characters of the already prepared string */ /* throw out the characters of the already prepared string */
s = Malloc((unsigned) (length)); s = Malloc((unsigned) (length));
clear(s, length); clear(s, (unsigned)length);
i = length <= ex->SG_LEN ? length : ex->SG_LEN; i = length <= ex->SG_LEN ? length : ex->SG_LEN;
to = s; from = ex->SG_VALUE; to = s; from = ex->SG_VALUE;
while(--i >= 0) { while(--i >= 0) {

View file

@ -58,6 +58,6 @@ do_pragma()
default: default:
break; break;
} }
SkipToNewLine(0); SkipToNewLine();
} }
} }

View file

@ -59,11 +59,10 @@ skipspaces(ch, skipnl)
} }
#endif NOPP #endif NOPP
SkipToNewLine(garbage) SkipToNewLine()
int garbage;
{ {
register int ch; register int ch;
register int pstrict = 0; register int garbage = 0;
while ((ch = GetChar()) != '\n') { while ((ch = GetChar()) != '\n') {
if (ch == '/') { if (ch == '/') {
@ -76,9 +75,9 @@ SkipToNewLine(garbage)
continue; continue;
} }
} }
if (garbage && !is_wsp(ch)) if (!is_wsp(ch))
pstrict = 1; garbage = 1;
} }
++LineNumber; ++LineNumber;
return pstrict; return garbage;
} }