[hackers] [scc] [cc2] Conver statement list into a double link || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 27 Apr 2016 20:46:33 +0200 (CEST)

commit e2c5b2c6dacc3a0c42fe14b79d05abc0acb42d1f
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
AuthorDate: Mon Apr 25 20:10:45 2016 +0200
Commit: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
CommitDate: Mon Apr 25 20:10:45 2016 +0200

    [cc2] Conver statement list into a double link
    
    We need a double list because we are going to do some modifications
    to the elements of the list, mainly in optimizations. Since stmt
    operations are node operations is more logical if we move it to
    node.c, where all the node functions live.

diff --git a/cc2/cc2.h b/cc2/cc2.h
index 44ce9b1..40b805b 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -138,7 +138,7 @@ struct symbol {
         char kind;
         union {
                 TSIZE off;
- Node *nlabel;
+ Node *stmt;
                 Inst *ilabel;
         } u;
         Symbol *next;
_AT_@ -160,7 +160,7 @@ struct node {
         } u;
         Symbol *label;
         Node *left, *right;
- Node *stmt;
+ Node *next, *prev;
 };
 
 struct addr {
_AT_@ -208,6 +208,7 @@ extern void cleannodes(void);
 extern void delnode(Node *np);
 extern void deltree(Node *np);
 extern Node *newnode(void);
+extern Node *addstmt(Node *np);
 
 /* symbol.c */
 #define TMPSYM 0
diff --git a/cc2/node.c b/cc2/node.c
index 147a76a..8fe75c0 100644
--- a/cc2/node.c
+++ b/cc2/node.c
_AT_@ -18,7 +18,7 @@ struct arena {
 };
 
 static struct arena *arena;
-static Node *freep;
+static Node *freep, *stmtp;
 static int inhome;
 
 Node *
_AT_@ -44,6 +44,20 @@ newnode(void)
         return memset(np, 0, sizeof(*np));
 }
 
+Node *
+addstmt(Node *np)
+{
+ if (!curfun->u.stmt)
+ curfun->u.stmt = np;
+ else
+ stmtp->next = np;
+ np->next = NULL;
+ np->prev = stmtp;
+ stmtp = np;
+
+ return np;
+}
+
 void
 delnode(Node *np)
 {
_AT_@ -73,6 +87,7 @@ cleannodes(void)
         }
         arena = NULL;
         freep = NULL;
+ stmtp = NULL;
 }
 
 void
_AT_@ -83,6 +98,6 @@ apply(Node *(*fun)(Node *))
         if (!curfun)
                 return;
 
- for (np = curfun->u.nlabel; np; np = np->stmt)
+ for (np = curfun->u.stmt; np; np = np->next)
                 (*fun)(np);
 }
diff --git a/cc2/parser.c b/cc2/parser.c
index f8448bb..2cfb49e 100644
--- a/cc2/parser.c
+++ b/cc2/parser.c
_AT_@ -131,7 +131,6 @@ static struct decoc {
 };
 
 static int sclass, inpars, ininit, endf, lineno;
-static Node *stmtp;
 static void *stack[STACKSIZ], **sp = stack;
 
 static void
_AT_@ -569,16 +568,6 @@ flddecl(void)
 }
 
 static void
-addstmt(Node *np)
-{
- if (!curfun->u.nlabel)
- curfun->u.nlabel = np;
- else
- stmtp->stmt = np;
- stmtp = np;
-}
-
-static void
 labeldcl(void)
 {
         Node *np;
Received on Wed Apr 27 2016 - 20:46:33 CEST

This archive was generated by hypermail 2.3.0 : Wed Apr 27 2016 - 20:48:15 CEST