shithub: scc

Download patch

ref: e1715607a4c65b30729c43c736eb67b957f35073
parent: a30b9999606a95dfdc73c4ae0264c2fecdb992c0
author: Roberto E. Vargas Caballero <[email protected]>
date: Sat Jul 1 14:27:31 EDT 2017

[cc1] Move defined() logic to a function

The code of defined was a bit confusing while it was in unary(),
but this new separation helps to have better separation of
responsabilities.

--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -827,6 +827,28 @@
 	}
 }
 
+static Node *
+defined(void)
+{
+	Symbol *sym;
+	int paren;
+
+	disexpand = 1;
+	next();
+	paren = accept('(');
+	if (yytoken != IDEN && yytoken != TYPEIDEN)
+		cpperror("operator 'defined' requires an identifier");
+	if (yytoken == TYPEIDEN || !(yylval.sym->flags & SDECLARED))
+		sym = zero;
+	else
+		sym = one;
+	disexpand = 0;
+	next();
+	if (paren)
+		expect(')');
+	return constnode(sym);
+}
+
 static Node *cast(int);
 
 static Node *
@@ -833,10 +855,8 @@
 unary(int needdecay)
 {
 	Node *(*fun)(int, Node *), *np;
-	Symbol *sym;
 	int op;
 	Type *tp;
-	int paren;
 
 	switch (yytoken) {
 	case '!': op = 0;     fun = negation;     break;
@@ -859,24 +879,9 @@
 		goto chk_decay;
 	case IDEN:
 	case TYPEIDEN:
-		if (lexmode != CPPMODE || strcmp(yylval.sym->name, "defined"))
-			goto call_postfix;
-		disexpand = 1;
-		next();
-		paren = accept('(');
-		if (yytoken != IDEN && yytoken != TYPEIDEN)
-			cpperror("operator 'defined' requires an identifier");
-		if (yytoken == TYPEIDEN || !(yylval.sym->flags & SDECLARED))
-			sym = zero;
-		else
-			sym = one;
-		disexpand = 0;
-		next();
-		if (paren)
-			expect(')');
-		return constnode(sym);
+		if (lexmode == CPPMODE && !strcmp(yylval.sym->name, "defined"))
+			return defined();
 	default:
-	call_postfix:
 		np = postfix(primary());
 		goto chk_decay;
 	}