shithub: scc

Download patch

ref: 64d1cd7568a6322903cc892973c2b4bf70d2d082
parent: 764d78a529e375df675e520cd628b3368e4949f2
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Oct 7 15:31:05 EDT 2013

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.

--- a/decl.c
+++ b/decl.c
@@ -291,7 +291,7 @@
 	if (accept('{')) {
 		struct compound c;
 
-		nodecomp(&c);
+		c.tree = NULL;
 		addstmt(&c, initializer(tp));
 		while (accept(',')) {
 			if (accept('}'))
@@ -310,7 +310,7 @@
 {
 	struct compound c;
 
-	nodecomp(&c);
+	c.tree = NULL;
 
 	do {
 		struct node *sp, *np;
--- a/flow.c
+++ b/flow.c
@@ -239,7 +239,7 @@
 	register struct node *np;
 	struct compound c;
 
-	nodecomp(&c);
+	c.tree = NULL;
 	expect('{');
 	new_ctx();
 	while (np = decl())
--- a/syntax.h
+++ b/syntax.h
@@ -35,7 +35,6 @@
 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);
 
--- a/tree.c
+++ b/tree.c
@@ -44,21 +44,16 @@
 	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;