scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 7ee42919b3387df47b563fe9fe792ef0f7724365
parent 117a0d066fb288fc4cbe597c8839e18765330271
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat,  9 Jan 2016 10:03:22 +0100

Add empty() function

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

Diffstat:
cc1/decl.c | 35++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/cc1/decl.c b/cc1/decl.c @@ -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) { @@ -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) @@ -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)