commit 64d1cd7568a6322903cc892973c2b4bf70d2d082
parent 764d78a529e375df675e520cd628b3368e4949f2
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Mon, 7 Oct 2013 19:31:05 +0200
Remove nodecomp and fix addstmt
A expansion node has always the right node pointing to the new
expression, while left is pointing to the next statement, so the
new node must be assigned to the left side, while np parameter
must be assigned to the right branch of the new expansion node.
Diffstat:
4 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/decl.c b/decl.c
@@ -291,7 +291,7 @@ initializer(register struct ctype *tp)
if (accept('{')) {
struct compound c;
- nodecomp(&c);
+ c.tree = NULL;
addstmt(&c, initializer(tp));
while (accept(',')) {
if (accept('}'))
@@ -310,7 +310,7 @@ listdcl(struct ctype *base)
{
struct compound c;
- nodecomp(&c);
+ c.tree = NULL;
do {
struct node *sp, *np;
diff --git a/flow.c b/flow.c
@@ -239,7 +239,7 @@ compound(void)
register struct node *np;
struct compound c;
- nodecomp(&c);
+ c.tree = NULL;
expect('{');
new_ctx();
while (np = decl())
diff --git a/syntax.h b/syntax.h
@@ -35,7 +35,6 @@ extern struct node *function(struct symbol *sym);
extern struct node *node(unsigned char op, struct node *l, struct node *r);
extern struct node *nodesym(struct symbol *sym);
extern struct node *addstmt(struct compound *p, struct node *np);
-extern struct node *addstmt(struct compound *p, struct node *np);
extern bool walk(register struct node *np, bool (*fun)(struct node *));
extern void prtree(register struct node *np);
diff --git a/tree.c b/tree.c
@@ -44,21 +44,16 @@ node(unsigned char op, struct node *l, struct node *r)
return (struct node *) np;
}
-void
-nodecomp(register struct compound *p)
-{
- p->tree = node(OCOMP, NULL, NULL);
- p->last = (struct node_op2 *) p->tree;
-}
-
struct node *
addstmt(struct compound *p, struct node *np)
{
- if (!p->last->left) {
- p->last->left = np;
+ if (!p->tree) {
+ p->tree = node(OCOMP, NULL, NULL);
+ p->last = (struct node_op2 *) p->tree;
+ p->last->right = np;
} else {
p->last = (struct node_op2 *)
- (p->last->right = node(O2EXP, NULL, np));
+ (p->last->left = node(O2EXP, NULL, np));
}
return p->tree;