commit 1f34f795dd1fab4c3246623af6c8a095a5ffe634
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Thu Sep 10 14:20:56 2015 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Thu Sep 10 14:20:56 2015 +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

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 7b14454..ed6c670 100644
--- 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
index 9e6a2de..a7bd932 100644
--- 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
index d4fd0f9..58534dc 100644
--- 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;
+       }
+}

Reply via email to