shithub: scc

Download patch

ref: ec632e06b5e6b66954cf811d2dd99b511273dc31
parent: cbb848825ea18d45601a09baafaf7000eef12526
author: Roberto E. Vargas Caballero <[email protected]>
date: Sat Feb 4 13:56:44 EST 2017

[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.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -426,7 +426,7 @@
 /* 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);
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -621,7 +621,7 @@
 			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;
 		}
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -106,7 +106,7 @@
 
 	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 @@
 			toomany = 1;
 		}
 		if (accept('=')) {
-			Node *np = iconstexpr();
+			Node *np = constexpr();
 
 			if (np == NULL)
 				errorp("invalid enumeration value");
@@ -626,7 +626,7 @@
 		Node *np;
 		TINT n;
 
-		if ((np = iconstexpr()) == NULL) {
+		if ((np = constexpr()) == NULL) {
 			unexpected();
 			n = 0;
 		} else {
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -1199,26 +1199,10 @@
 	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);
 }
 
--- a/cc1/init.c
+++ b/cc1/init.c
@@ -37,7 +37,7 @@
 	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");
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -265,7 +265,7 @@
 	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");