shithub: scc

Download patch

ref: 7ee42919b3387df47b563fe9fe792ef0f7724365
parent: 117a0d066fb288fc4cbe597c8839e18765330271
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Jan 9 05:03:22 EST 2016

Add empty() function

This function allows to factorize common code in several functions
of decl.c

--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -535,6 +535,23 @@
 	return sym;
 }
 
+static int
+empty(Symbol *sym, Type *tp)
+{
+	if (!sym->name) {
+		sym->type = tp;
+		switch (tp->op) {
+		default:
+			warn("empty declaration");
+		case STRUCT:
+		case UNION:
+		case ENUM:
+			return 1;
+		}
+	}
+	return 0;
+}
+
 static Symbol *
 field(struct decl *dcl)
 {
@@ -543,11 +560,8 @@
 	Type *structp = dcl->parent, *tp = dcl->type;
 	TINT n = structp->n.elem;
 
-	if (!name) {
-		sym->type = tp;
-		warn("empty declaration");
+	if (empty(sym, tp))
 		return sym;
-	}
 	if (dcl->sclass)
 		error("storage class in struct/union field");
 	if (tp->op == FTN)
@@ -587,17 +601,8 @@
 	short flags;
 	int sclass = dcl->sclass;
 
-	if (!name) {
-		sym->type = tp;
-		switch (tp->op) {
-		default:
-			warn("empty declaration");
-		case STRUCT:
-		case UNION:
-		case ENUM:
-			return sym;
-		}
-	}
+	if (empty(sym, tp))
+		return sym;
 
 	/* TODO: Add warning about ANSI limits */
 	if (!tp->defined && sclass != EXTERN && sclass != TYPEDEF)