[hackers] [scc] Add empty() function || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Sat, 9 Jan 2016 21:33:36 +0100 (CET)

commit 7ee42919b3387df47b563fe9fe792ef0f7724365
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sat Jan 9 10:03:22 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Sat Jan 9 10:03:22 2016 +0100

    Add empty() function
    
    This function allows to factorize common code in several functions
    of decl.c

diff --git a/cc1/decl.c b/cc1/decl.c
index 4dcefb1..05a12da 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
_AT_@ -535,6 +535,23 @@ type(struct decl *dcl)
         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)
 {
_AT_@ -543,11 +560,8 @@ field(struct decl *dcl)
         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)
_AT_@ -587,17 +601,8 @@ identifier(struct decl *dcl)
         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)
Received on Sat Jan 09 2016 - 21:33:36 CET

This archive was generated by hypermail 2.3.0 : Sat Jan 09 2016 - 21:36:15 CET