scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 28af012e9746a4adacc4e2909d0cfb5e9d8e94e9
parent 46eaaf7b32ddb0e7ce17c03db45d6c6ef98bc0f0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 30 Oct 2013 08:13:18 +0100

Convert mktype to static function

ctype is a more general interface to the creation of types,
so it is better have only one interface than two.

Diffstat:
Mdecl.c | 3+--
Msymbol.h | 1-
Mtypes.c | 25++++++++++++++-----------
3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/decl.c b/decl.c @@ -83,8 +83,7 @@ fielddcl(unsigned char ns) register struct ctype *tp, *base; if (!(base = specifier())) { - base = newctype(); - base->type = INT; + base = ctype(NULL, INT); warn(options.implicit, "data definition has no type or storage class"); } diff --git a/symbol.h b/symbol.h @@ -73,7 +73,6 @@ extern void freesyms(void); extern struct symbol *lookup(const char *s, signed char ns); extern void insert(struct symbol *sym, unsigned char ctx); extern struct ctype *storage(struct ctype *tp, unsigned char mod); -extern struct ctype *newctype(void); extern void delctype(struct ctype *tp); extern unsigned char hash(register const char *s); diff --git a/types.c b/types.c @@ -1,6 +1,7 @@ #include <assert.h> #include <stdlib.h> +#include <string.h> #include "sizes.h" #include "cc.h" @@ -11,14 +12,11 @@ static unsigned char stack[NR_DECLARATORS]; static unsigned char *stackp = stack; - -struct ctype * -newctype(void) +void +initctype(register struct ctype *tp) { - register struct ctype *tp = xcalloc(sizeof(*tp), 1); - + memset(tp, 0, sizeof(*tp)); tp->forward = 1; - return tp; } void @@ -43,7 +41,8 @@ mktype(register struct ctype *tp, unsigned char op) case PTR: case FTN: { register struct ctype *aux = tp; - tp = newctype(); + tp = xmalloc(sizeof(*tp)); + initctype(tp); tp->type = op; tp->base = aux; tp->len = len; @@ -88,8 +87,10 @@ ctype(struct ctype *tp, unsigned char tok) { register unsigned char type; - if (!tp) - tp = newctype(); + if (!tp) { + tp = xmalloc(sizeof(*tp)); + initctype(tp); + } type = tp->type; switch (tok) { @@ -191,8 +192,10 @@ storage(register struct ctype *tp, unsigned char mod) { extern unsigned char curctx; - if (!tp) - tp = newctype(); + if (!tp) { + tp = xmalloc(sizeof(*tp)); + initctype(tp); + } switch (mod) { case TYPEDEF: if (tp->c_typedef)