scc

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

commit 1f34f795dd1fab4c3246623af6c8a095a5ffe634
parent 3939d91c2494e9de10f4f7e8a692544416c5f021
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 10 Sep 2015 14:20:56 +0200

Move initializer() to expr.c

This function will use (and it is using) several functions
of expr.c, so it is better move it to expr.c

Diffstat:
cc1/cc1.h | 2+-
cc1/decl.c | 24------------------------
cc1/expr.c | 26+++++++++++++++++++++++++-
3 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -374,7 +374,7 @@ extern bool isnodecmp(int op); extern int negop(int op); extern bool cmpnode(Node *np, TUINT val); extern Node *decay(Node *np); -extern Node *assignop(char op, Node *lp, Node *rp); +extern void initializer(Symbol *sym); /* cpp.c */ extern void icpp(void); diff --git a/cc1/decl.c b/cc1/decl.c @@ -358,30 +358,6 @@ return_type: return tp; } -/* TODO: check correctness of the initializator */ -/* TODO: emit initializer */ -static void -initializer(Symbol *sym) -{ - Node *np; - - if (accept('{')) { - do { - if (yytoken == '}') - break; - initializer(sym); - } while (accept(','); - - expect('}'); - return; - } - np = expr(); - if ((sym->flags & ISLOCAL) == 0) { - emit(OEXPR, assignop(OINIT, varnode(sym), np)); - return; - } -} - static Symbol * newtag(void) { diff --git a/cc1/expr.c b/cc1/expr.c @@ -421,7 +421,7 @@ array(Node *lp, Node *rp) return content(OPTR, np); } -Node * +static Node * assignop(char op, Node *lp, Node *rp) { int force = 0; @@ -977,3 +977,27 @@ condexpr(void) warn("conditional expression is constant"); return np; } + +/* TODO: check correctness of the initializator */ +/* TODO: emit initializer */ +void +initializer(Symbol *sym) +{ + Node *np; + + if (accept('{')) { + do { + if (yytoken == '}') + break; + initializer(sym); + } while (accept(',')); + + expect('}'); + return; + } + np = expr(); + if ((sym->flags & ISLOCAL) == 0) { + emit(OEXPR, assignop(OINIT, varnode(sym), np)); + return; + } +}