scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 28974f98e6d51b5413f0080787bf3f2d074b9589
parent 95b9b266a3ac7b75b955dedebde0df75640978ee
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat,  4 Feb 2017 18:56:44 +0100

[cc1] Remove iconstexpr()

there were a constexpr() and an iconstexpr() but only
iconstexpr() was used, so it is better to join them
and simplify the code.

Diffstat:
Mcc1/cc1.h | 2+-
Mcc1/cpp.c | 2+-
Mcc1/decl.c | 6+++---
Mcc1/expr.c | 18+-----------------
Mcc1/init.c | 2+-
Mcc1/stmt.c | 2+-
6 files changed, 8 insertions(+), 24 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -426,7 +426,7 @@ extern TUINT ones(int nbytes); /* expr.c */ extern Node *decay(Node *), *negate(Node *np), *assign(void); extern Node *convert(Node *np, Type *tp1, char iscast); -extern Node *iconstexpr(void), *condexpr(void), *expr(void); +extern Node *constexpr(void), *condexpr(void), *expr(void); extern int isnodecmp(int op); extern int negop(int op); extern int cmpnode(Node *np, TUINT val); diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -621,7 +621,7 @@ ifclause(int negate, int isifdef) killsym(sym); } else { /* TODO: catch recovery here */ - if ((expr = iconstexpr()) == NULL) { + if ((expr = constexpr()) == NULL) { cpperror("parameter of #if is not an integer constant expression"); return; } diff --git a/cc1/decl.c b/cc1/decl.c @@ -106,7 +106,7 @@ arydcl(struct declarators *dp) expect('['); if (yytoken != ']') { - if ((np = iconstexpr()) == NULL) { + if ((np = constexpr()) == NULL) { errorp("invalid storage size"); } else { if ((n = np->sym->u.i) <= 0) { @@ -572,7 +572,7 @@ enumdcl(void) toomany = 1; } if (accept('=')) { - Node *np = iconstexpr(); + Node *np = constexpr(); if (np == NULL) errorp("invalid enumeration value"); @@ -626,7 +626,7 @@ field(struct decl *dcl) Node *np; TINT n; - if ((np = iconstexpr()) == NULL) { + if ((np = constexpr()) == NULL) { unexpected(); n = 0; } else { diff --git a/cc1/expr.c b/cc1/expr.c @@ -1199,26 +1199,10 @@ constexpr(void) Node *np; np = ternary(); - if (!(np->flags & NCONST)) { + if (!np || !(np->flags & NCONST) || np->type->op != INT) { freetree(np); return NULL; } - return np; -} - -Node * -iconstexpr(void) -{ - Node *np; - - if ((np = constexpr()) == NULL) - return NULL; - - if (np->type->op != INT) { - freetree(np); - return NULL; - } - return convert(np, inttype, 0); } diff --git a/cc1/init.c b/cc1/init.c @@ -37,7 +37,7 @@ arydesig(Init *ip) if (ip->type->op != ARY) errorp("array index in non-array initializer"); next(); - np = iconstexpr(); + np = constexpr(); npos = np->sym->u.i; if (npos < 0 || (tp->prop & TDEFINED) && npos >= tp->n.elem) { errorp("array index in initializer exceeds array bounds"); diff --git a/cc1/stmt.c b/cc1/stmt.c @@ -265,7 +265,7 @@ Case(Symbol *lbreak, Symbol *lcont, Switch *sw) Symbol *label; expect(CASE); - if ((np = iconstexpr()) == NULL) + if ((np = constexpr()) == NULL) errorp("case label does not reduce to an integer constant"); if (!sw) { errorp("case label not within a switch statement");