[hackers] [scc] Move initializer() to expr.c || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 10 Sep 2015 18:19:11 +0200 (CEST)

commit 1f34f795dd1fab4c3246623af6c8a095a5ffe634
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Sep 10 14:20:56 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
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
_AT_@ -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
_AT_@ -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
_AT_@ -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;
_AT_@ -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;
+ }
+}
Received on Thu Sep 10 2015 - 18:19:11 CEST

This archive was generated by hypermail 2.3.0 : Thu Sep 10 2015 - 18:24:10 CEST