shithub: scc

Download patch

ref: d247bc3fa770720335e31b8d3c735200b2484c30
parent: 620b4d63082783d846415b9e240f256f11b16e51
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Mar 11 12:31:31 EDT 2014

Make type_name void

We do not need anymore the return value of type_name(), because
we can detect when the next element is a type name calling to ahead().

--- a/decl.c
+++ b/decl.c
@@ -384,7 +384,7 @@
 	}
 }
 
-bool
+void
 type_name(struct ctype *tp)
 {
 	struct storage store;
@@ -395,9 +395,9 @@
 	initqlf(&qlf);
 
 	if (!specifier(tp, &store, &qlf))
-		return false;
+		return;
 
 	declarator(tp, NS_TYPE, 0);
-	return true;
+	return;
 }
 
--- a/expr.c
+++ b/expr.c
@@ -93,8 +93,14 @@
 		next();
 		if (accept('(')) {
 			struct ctype type;
-			if (!type_name(&type))
+			switch (yytoken) {
+			case STORAGE: case TQUALIFIER: case TYPE:
+				type_name(&type);
+				break;
+			default:
 				expr();
+				break;
+			}
 			expect(')');
 		} else {
 			unary();
@@ -123,10 +129,18 @@
 static struct node *
 cast(void)
 {
+	register struct node *np;
+	struct ctype type;
+
 	while (accept('(')) {
-		struct ctype type;
-		if (!type_name(&type))
-			error("expected a type name");
+		switch (yytoken) {
+		case STORAGE: case TQUALIFIER: case TYPE:
+			type_name(&type); /* TODO: type_name should return a np*/
+			break;
+		default:
+			np = expr();
+			break;
+		}
 		expect(')');
 	}
 	return unary();
--- a/syntax.h
+++ b/syntax.h
@@ -30,7 +30,7 @@
 
 extern struct node *expr(void);
 extern struct node *decl(unsigned char ns);
-extern bool type_name(struct ctype *tp);
+extern void type_name(struct ctype *tp);
 extern struct node *function(struct symbol *sym);
 
 extern struct node *node(unsigned char op, struct node *l, struct node *r);