shithub: scc

Download patch

ref: 53524f0343fd7d547953ab39b09f336d661d4d88
parent: 78fb2955d0a19020b98dcaf65306217a47d720ea
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Jan 8 07:33:02 EST 2016

Convert fielddesig() and field() to use new type fields

--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -441,18 +441,22 @@
 		unexpected();
 	next();
 
-	switch (BTYPE(np)) {
-	case STRUCT:
-	case UNION:
-		if ((sym->flags & ISDECLARED) == 0)
-			error("incorrect field in struct/union");
-		np = node(OFIELD, sym->type, np, varnode(sym));
-		np->lvalue = 1;
-		return np;
-	default:
-		error("request for member '%s' in something not a structure or union",
+	if (!np->type->aggreg) {
+		errorp("request for member '%s' in something not a structure or union",
 		      yylval.sym->name);
+		goto free_np;
 	}
+	if ((sym->flags & ISDECLARED) == 0) {
+		errorp("incorrect field in struct/union");
+		goto free_np;
+	}
+	np = node(OFIELD, sym->type, np, varnode(sym));
+	np->lvalue = 1;
+	return np;
+
+free_np:
+	freetree(np);
+	return constnode(zero);
 }
 
 static Node *
@@ -1105,7 +1109,7 @@
 	int ons;
 	Symbol *sym, **p;
 
-	if (tp->op != STRUCT || tp->op != UNION)
+	if (!tp->aggreg)
 		errorp("field name not in record or union initializer");
 	ons = namespace;
 	namespace = tp->ns;