[hackers] [scc] [cc2] Do not move curstmt in addstmt() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 9 May 2016 17:00:22 +0200 (CEST)

commit e839d44a1d0bf83eccfbac6e9c333569ec7be0d0
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon May 9 10:07:39 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Mon May 9 12:43:02 2016 +0200

    [cc2] Do not move curstmt in addstmt()
    
    Addstmt() was moving the pointer to the current statement because
    it was useful in parser.c, but in the majority of cases we don't want
    such behaviour, and to solve the problem we had to add prevstmt().

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 70ba9d6..43c5f85 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -230,8 +230,7 @@ cgen(Node *np)
                 if (np->next == NULL) {
                         Node *tmp = newnode();
                         tmp->op = ORET;
- addstmt(tmp);
- prevstmt();
+ addstmt(tmp, KEEPCUR);
                 }
         }
         l = cgen(np->left);
diff --git a/cc2/cc2.h b/cc2/cc2.h
index 5ca106e..5e7cdc1 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -204,13 +204,15 @@ extern void defvar(Symbol *), defpar(Symbol *), defglobal(Symbol *);
 extern void setlabel(Symbol *sym);
 
 /* node.c */
+#define SETCUR 1
+#define KEEPCUR 0
 extern void apply(Node *(*fun)(Node *));
 extern void cleannodes(void);
 extern void delnode(Node *np);
 extern void deltree(Node *np);
 extern Node *newnode(void);
-extern Node *addstmt(Node *np);
-extern Node *prevstmt(void), *nextstmt(void);
+extern Node *addstmt(Node *np, int flags);
+extern Node *nextstmt(void);
 
 
 /* symbol.c */
diff --git a/cc2/node.c b/cc2/node.c
index 56b64fd..7214c6b 100644
--- a/cc2/node.c
+++ b/cc2/node.c
_AT_@ -46,15 +46,19 @@ newnode(void)
 }
 
 Node *
-addstmt(Node *np)
+addstmt(Node *np, int flag)
 {
+ if (curstmt)
+ np->next = curstmt->next;
+ np->prev = curstmt;
+
         if (!curfun->u.stmt)
                 curfun->u.stmt = np;
         else
                 curstmt->next = np;
- np->next = NULL;
- np->prev = curstmt;
- curstmt = np;
+
+ if (flag == SETCUR)
+ curstmt = np;
 
         return np;
 }
_AT_@ -83,12 +87,6 @@ nextstmt(void)
         return curstmt = curstmt->next;
 }
 
-Node *
-prevstmt(void)
-{
- return curstmt = curstmt->prev;
-}
-
 void
 delnode(Node *np)
 {
diff --git a/cc2/parser.c b/cc2/parser.c
index 09b2353..8d4bd6c 100644
--- a/cc2/parser.c
+++ b/cc2/parser.c
_AT_@ -579,7 +579,7 @@ labeldcl(void)
         sym->kind = SLABEL;
         sym->u.stmt = np;
         np->label = sym;
- addstmt(np);
+ addstmt(np, SETCUR);
 }
 
 static void
_AT_@ -593,7 +593,7 @@ stmt(void)
                 deltree(np);
                 return;
         }
- addstmt(np);
+ addstmt(np, SETCUR);
 }
 
 static void
Received on Mon May 09 2016 - 17:00:22 CEST

This archive was generated by hypermail 2.3.0 : Mon May 09 2016 - 17:12:15 CEST