[hackers] [scc] [cc2] Remove statements in apply() || Roberto E. Vargas Caballero
commit 950cfce031fb38e6337e087c398dc4e7c5efc467
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
AuthorDate: Mon Apr 25 21:53:57 2016 +0200
Commit: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
CommitDate: Tue Apr 26 20:02:08 2016 +0200
[cc2] Remove statements in apply()
A usage case of apply() may be optimization, and we need some way
of removing unwanted statments, and we can use the return value
of the parameter function to mark what statements must be deleted.
diff --git a/cc2/node.c b/cc2/node.c
index 8fe75c0..96c3e90 100644
--- a/cc2/node.c
+++ b/cc2/node.c
_AT_@ -9,6 +9,7 @@
#define NNODES 32
+Node *curstmt;
Symbol *curfun;
Type rtype;
_AT_@ -18,7 +19,7 @@ struct arena {
};
static struct arena *arena;
-static Node *freep, *stmtp;
+static Node *freep;
static int inhome;
Node *
_AT_@ -50,14 +51,38 @@ addstmt(Node *np)
if (!curfun->u.stmt)
curfun->u.stmt = np;
else
- stmtp->next = np;
+ curstmt->next = np;
np->next = NULL;
- np->prev = stmtp;
- stmtp = np;
+ np->prev = curstmt;
+ curstmt = np;
return np;
}
+Node *
+delstmt(void)
+{
+ Node *next, *prev;
+
+ next = curstmt->next;
+ prev = curstmt->prev;
+ if (next)
+ next->prev = prev;
+ if (prev)
+ prev->next = next;
+ else
+ curfun->u.stmt = next;
+ deltree(curstmt);
+
+ return curstmt = next;
+}
+
+Node *
+nextstmt(void)
+{
+ return curstmt = curstmt->next;
+}
+
void
delnode(Node *np)
{
_AT_@ -87,17 +112,15 @@ cleannodes(void)
}
arena = NULL;
freep = NULL;
- stmtp = NULL;
+ curstmt = NULL;
}
void
apply(Node *(*fun)(Node *))
{
- Node *np;
-
if (!curfun)
return;
-
- for (np = curfun->u.stmt; np; np = np->next)
- (*fun)(np);
+ curstmt = curfun->u.stmt;
+ while (curstmt)
+ (*fun)(curstmt) ? nextstmt() : delstmt();
}
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:23 CEST