scc

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

commit c4d94b222aa21eb5f956a37717627c0a55fd6404
parent ed20286ef867b32a21feddc766d676b79254e640
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 14 Sep 2015 18:37:03 +0200

Fix size of n.elem

After the commit 7ba972c the type for n.elem in
the type struct was TINT, but in all the other
places we were using short, which was generating
different errors due to the implicit convertions.

Diffstat:
Mcc1/cc1.h | 4++--
Mcc1/code.c | 4++--
Mcc1/decl.c | 14+++++++-------
Mcc1/expr.c | 6++++--
Mcc1/types.c | 13++++---------
5 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -52,7 +52,7 @@ struct type { } p; union { unsigned char rank; /* convertion rank */ - TINT elem; /* number of type parameters */ + TINT elem; /* number of type parameters */ } n; }; @@ -320,7 +320,7 @@ extern void cpperror(char *fmt, ...); /* types.c */ extern bool eqtype(Type *tp1, Type *tp2); extern Type *ctype(unsigned type, unsigned sign, unsigned size); -extern Type *mktype(Type *tp, unsigned op, short nelem, Type *data[]); +extern Type *mktype(Type *tp, int op, TINT nelem, Type *data[]); extern Type *duptype(Type *base); extern struct limits *getlimits(Type *tp); diff --git a/cc1/code.c b/cc1/code.c @@ -235,7 +235,7 @@ emitletter(Type *tp) static void emittype(Type *tp) { - int n; + TINT n; Type **vp; Symbol **sp; char *tag; @@ -350,7 +350,7 @@ static void emitfun(unsigned op, void *arg) { Symbol *sym = arg, **sp; - int n; + TINT n; emitdcl(op, arg); puts("\n{"); diff --git a/cc1/decl.c b/cc1/decl.c @@ -16,7 +16,7 @@ struct declarators { unsigned char nr; struct declarator { unsigned char op; - unsigned short nelem; + TINT nelem; Symbol *sym; Type **tpars; Symbol **pars; @@ -33,7 +33,7 @@ struct decl { }; static void -push(struct declarators *dp, unsigned op, ...) +push(struct declarators *dp, int op, ...) { va_list va; unsigned n; @@ -49,10 +49,10 @@ push(struct declarators *dp, unsigned op, ...) switch (op) { case ARY: - p->nelem = va_arg(va, unsigned); + p->nelem = va_arg(va, TINT); break; case FTN: - p->nelem = va_arg(va, unsigned); + p->nelem = va_arg(va, TINT); p->tpars = va_arg(va, Type **); p->pars = va_arg(va, Symbol **); break; @@ -125,7 +125,7 @@ parameter(struct decl *dcl) { Symbol *sym = dcl->sym; Type *funtp = dcl->parent, *tp = dcl->type; - size_t n = funtp->n.elem; + TINT n = funtp->n.elem; char *name = sym->name; sym->type = tp; @@ -188,7 +188,7 @@ fundcl(struct declarators *dp) { Type type = {.n = {.elem = -1}, .p = {.pars= NULL}}; Symbol *syms[NR_FUNPARAM], **sp; - size_t size; + TINT size; Symbol *pars = NULL; pushctx(); @@ -516,7 +516,7 @@ field(struct decl *dcl) Symbol *sym = dcl->sym; char *name = sym->name; Type *structp = dcl->parent, *tp = dcl->type; - size_t n = structp->n.elem; + TINT n = structp->n.elem; if (!name) { sym->type = tp; diff --git a/cc1/expr.c b/cc1/expr.c @@ -532,7 +532,8 @@ static Node *assign(void); static Node * arguments(Node *np) { - int n, toomany;; + int toomany;; + TINT n; Node *par = NULL, *arg; Type **targs, *tp = np->type; @@ -1057,7 +1058,8 @@ static void initlist(Symbol *sym, Type *tp) { struct designator *des; - int n, toomany = 0; + int toomany = 0; + TINT n; Type *newtp; for (n = 0; ; ++n) { diff --git a/cc1/types.c b/cc1/types.c @@ -350,13 +350,11 @@ invalid_type: error("invalid type specification"); } -/* TODO: define a type for sizes instead of using short */ -static short +static TINT typesize(Type *tp) { - short align, size; Symbol **sp; - int n; + TINT n, size, align; switch (tp->op) { case ARY: @@ -391,7 +389,7 @@ typesize(Type *tp) } Type * -mktype(Type *tp, unsigned op, short nelem, Type *pars[]) +mktype(Type *tp, int op, TINT nelem, Type *pars[]) { static Type *typetab[NR_TYPE_HASH]; Type **tbl, type; @@ -460,7 +458,7 @@ mktype(Type *tp, unsigned op, short nelem, Type *pars[]) bool eqtype(Type *tp1, Type *tp2) { - int n; + TINT n; Type **p1, **p2; if (!tp1 || !tp2) @@ -490,8 +488,5 @@ eqtype(Type *tp1, Type *tp2) case INT: case FLOAT: return tp1->letter == tp2->letter; - default: - fputs("internal type error, aborting\n", stderr); - abort(); } }