ref: af0a60913386396971fb0c4311370d68ae247c26
parent: 3d2cb9931a7aa956b7cd04a13de1711d7dd5dd48
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Jul 11 05:26:42 EDT 2014
Add unexpected() This function makes a common task, saying to the user that an unexpected token was read from the input.
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -15,6 +15,7 @@
extern struct user_opt options;
extern void error(const char *fmt, ...);
extern void warn(signed char flag, const char *fmt, ...);
+extern void unexpected(void);
/* definitions of types */
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -70,7 +70,7 @@
} else if (flags) { if (yytoken != IDEN) {if (flags & ID_EXPECTED)
- error("unexpected '%s'", yytext);+ unexpected();
sym = install("", NS_IDEN); } else {sym = newiden();
@@ -302,7 +302,7 @@
case ';':
break;
default:
- error("declaration expected");+ unexpected();
}
if (yytoken != ';') {@@ -374,7 +374,7 @@
tp->defined = 1;
while (yytoken != '}') {if (yytoken != IDEN)
- error("identifier expected");+ unexpected();
sym = newiden();
sym->type = inttype;
if (accept('='))@@ -512,7 +512,7 @@
expect(';');return;
default:
- error("declaration expected");+ unexpected();
}
}
--- a/cc1/error.c
+++ b/cc1/error.c
@@ -41,3 +41,10 @@
warn_helper(-1, fmt, va);
va_end(va);
}
+
+void
+unexpected(void)
+{+ error("unexpected '%s'", yytext);+}
+
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -302,7 +302,7 @@
Field *fp;
if (yytoken != IDEN)
- error("unexpected '%s'", yytext);+ unexpected();
switch (np->typeop) {case STRUCT: case UNION:
for (fp = np->utype->u.fields; fp; fp = fp->next) {@@ -477,7 +477,7 @@
Node *np;
if ((np = unary()) == NULL)
- error("unexpected '%s'", yytext);+ unexpected();
tp = np->type;
/* TODO: free np */
return tp;
@@ -530,7 +530,7 @@
tp = typename();
expect(')');if ((np1 = eval(cast())) == NULL)
- error("unexpected '%s'", yytext);+ unexpected();
if ((np2 = convert(np1, tp, 1)) == NULL)
error("bad type convertion requested");np2->b.lvalue = np1->b.lvalue;
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -412,7 +412,7 @@
expect(register uint8_t tok)
{if (yytoken != tok)
- error("unexpected %s", yytext);+ unexpected();
next();
}
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -193,7 +193,7 @@
expect(GOTO);
if (yytoken != IDEN)
- error("unexpected '%s'", yytext);+ unexpected();
emitjump(label(yytext, 0), NULL);
next();
expect(';');@@ -211,7 +211,7 @@
expect(SWITCH);
expect ('(');if ((cond = expr()) == NULL)
- error("expected expression before '%s'", yytext);+ unexpected();
if ((cond = convert(cond, inttype, 0)) == NULL)
error("incorrect type in switch statement"); expect (')');@@ -242,7 +242,7 @@
if (!lswitch)
error("case label not within a switch statement");if ((np = expr()) == NULL)
- error("expected expression before '%s'", yytext);+ unexpected();
if ((np = convert(np, inttype, 0)) == NULL)
error("incorrect type in case statement"); expect(':');--
⑨