ref: 1f34f795dd1fab4c3246623af6c8a095a5ffe634
parent: 3939d91c2494e9de10f4f7e8a692544416c5f021
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Sep 10 10:20:56 EDT 2015
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
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -374,7 +374,7 @@
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);
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -358,30 +358,6 @@
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)
{
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -421,7 +421,7 @@
return content(OPTR, np);
}
-Node *
+static Node *
assignop(char op, Node *lp, Node *rp)
{
int force = 0;
@@ -976,4 +976,28 @@
if (np->constant)
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;
+ }
}