scc

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

commit e1ea759cef4ef3331b24d5fb90f28438a1df3070
parent 610912d2b4ceea59e7b760d8362f30460ff2b53a
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 29 Jun 2012 22:03:19 +0200

Reorder functions in type.c

This new order avoid some calls to non declared functions

Diffstat:
symbol.h | 1-
types.c | 104++++++++++++++++++++++++++++++++++++++++---------------------------------------
2 files changed, 53 insertions(+), 52 deletions(-)

diff --git a/symbol.h b/symbol.h @@ -88,7 +88,6 @@ extern struct type tchar, tshort, tint, tulong, tllong, tvoid, tkeyword; extern struct type tfloat, tdouble, tldouble, tlong; -extern struct type *mktype(register struct type *base, unsigned char op); extern struct type *decl_type(struct type *t); extern void pushtype(unsigned char mod); extern struct type *btype(struct type *tp, unsigned char tok); diff --git a/types.c b/types.c @@ -21,6 +21,58 @@ struct type tbool = {.btype = BOOL}; static unsigned char stack[NR_DECLARATORS]; static unsigned char *stackp = stack; + +static struct type * +mktype(register struct type *base, unsigned char op) +{ + register struct type **ptr, *nt; + assert(op == PTR || op == ARY || op == FTN || + op == VOLATILE || op == RESTRICT || op == CONST); + + switch (op) { + case PTR: + ptr = &base->ptr; + break; + case ARY: + ptr = &base->ary; + break; + case FTN: + ptr = &base->ftn; + break; + case VOLATILE: + ptr = &base->vltl; + break; + case RESTRICT: + ptr = &base->rstr; + break; + case CONST: + ptr = &base->cnst; + break; + } + if (*ptr) return *ptr; + + nt = xcalloc(sizeof(*base), 1); + *ptr = nt; + nt->op = op; + nt->base = base; + return nt; +} + +void pushtype(unsigned char mod) +{ + if (stackp == stack + NR_DECLARATORS) + error("Too much type declarators"); + *stackp++ = mod; +} + +struct type *decl_type(struct type *t) +{ + while (stackp != stack) + t = mktype(t, *--stackp); + ptype(t); + return t; +} + struct type *btype(struct type *tp, unsigned char tok) { switch (tok) { @@ -76,56 +128,6 @@ struct type *btype(struct type *tp, unsigned char tok) error("two or more basic types"); } -void pushtype(unsigned char mod) -{ - if (stackp == stack + NR_DECLARATORS) - error("Too much type declarators"); - *stackp++ = mod; -} - -struct type *decl_type(struct type *t) -{ - while (stackp != stack) - t = mktype(t, *--stackp); - ptype(t); - return t; -} - -struct type *mktype(register struct type *base, unsigned char op) -{ - register struct type **ptr, *nt; - assert(op == PTR || op == ARY || op == FTN || - op == VOLATILE || op == RESTRICT || op == CONST); - - switch (op) { - case PTR: - ptr = &base->ptr; - break; - case ARY: - ptr = &base->ary; - break; - case FTN: - ptr = &base->ftn; - break; - case VOLATILE: - ptr = &base->vltl; - break; - case RESTRICT: - ptr = &base->rstr; - break; - case CONST: - ptr = &base->cnst; - break; - } - if (*ptr) return *ptr; - - nt = xcalloc(sizeof(*base), 1); - *ptr = nt; - nt->op = op; - nt->base = base; - return nt; -} - void ctype(struct ctype *cp, unsigned char mod) { extern unsigned char nested_level; @@ -234,7 +236,7 @@ void ptype(register struct type *t) default: abort(); } - /* printf("%s %s", sign, type); */ + printf("%s", type); } } }