shithub: scc

Download patch

ref: 7d77cd4c9f3bd9c9a4ad49890b08a4181552ff3d
parent: e011fdb4c004eeba9f35fc42a289bde407baa8ad
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Oct 3 17:57:56 EDT 2013

Remove node3 call

node3 can be simulated using node and binary nodes, so remove it.

--- a/expr.c
+++ b/expr.c
@@ -291,7 +291,8 @@
 	while (yytoken == '?') {
 		aux = expr();
 		expect(':');
-		np = node3(OTERN, np, aux, or());
+		np = node(OTERN, np,
+		          node(O2EXP, aux, or()));
 	}
 	return np;
 }
--- a/flow.c
+++ b/flow.c
@@ -114,7 +114,9 @@
 	expect(')');
 
 	push(OFOR);
-	np = node(OFOR, node3(OFEXP, exp1, exp2, exp3), stmt());
+	np = node(OFOR, exp1,
+	          node(O2EXP, exp2,
+	               node(O2EXP, exp3, stmt())));
 	pop();
 	return np;
 }
@@ -130,7 +132,8 @@
 	expect(')');
 	body = stmt();
 
-	return node3(OIF, cond, body, (accept(ELSE)) ? stmt() : NULL);
+	return node(OIF, cond,
+	            node(O2EXP, body, (accept(ELSE)) ? stmt() : NULL));
 }
 
 static struct node *
--- a/syntax.h
+++ b/syntax.h
@@ -12,7 +12,7 @@
 	OA_MOD, OA_ADD, OA_SUB, OA_SHL, OA_SHR, OA_AND,
 	OA_XOR, OA_OR, OSYM, OCOMP, OSWITCH, OIF, OFOR,
 	OFEXP, ODO, OWHILE, OLABEL, OGOTO, OBREAK, OCONT,
-	ORETURN, OCASE, ODEFAULT, OFTN, ODEF
+	ORETURN, OCASE, ODEFAULT, OFTN, ODEF, O2EXP
 };
 
 struct node;
@@ -23,8 +23,6 @@
 extern void type_name(void);
 extern struct node *function(struct symbol *sym);
 
-extern struct node *node3(unsigned char op,
-			  struct node *l, struct node *i, struct node *r);
 extern struct node *node(unsigned char op, struct node *l, struct node *r);
 extern struct node *node1(unsigned char op, struct node *i);
 
--- a/tree.c
+++ b/tree.c
@@ -23,13 +23,6 @@
 	struct node *rigth;
 };
 
-struct node_op3 {
-	struct node base;
-	struct node *left;
-	struct node *infix;
-	struct node *rigth;
-};
-
 struct node_sym {
 	struct node base;
 	struct symbol *sym;
@@ -56,19 +49,6 @@
 }
 
 struct node *
-node3(unsigned char op, struct node *l, struct node *i, struct node *r)
-{
-	register struct node_op3 *np = xmalloc(sizeof(*np));
-
-	np->base.op = op;
-	np->left = l;
-	np->infix = i;
-	np->rigth = r;
-
-	return (struct node *) np;
-}
-
-struct node *
 node(unsigned char op, struct node *l, struct node *r)
 {
 	register struct node_op2 *np = xmalloc(sizeof(*np));
@@ -163,7 +143,7 @@
 		[OBOR] = {2, "|"},
 		[OAND] = {2, "&&"},
 		[OOR] = {2, "||"},
-		[OTERN] = {3, "?"},
+		[OTERN] = {2, "?"},
 		[OASSIGN] = {2, "="},
 		[OA_MUL] = {2, "*="},
 		[OA_DIV] = {2, "/="},
@@ -178,9 +158,9 @@
 		[OSYM] = {0, "sym"},
 		[OCOMP] = {255, "comp"},
 		[OSWITCH] = {2, "switch"},
-		[OIF] = {3, "if"},
+		[OIF] = {2, "if"},
 		[OFOR] = {2, "for"},
-		[OFEXP] = {3, "efor"},
+		[OFEXP] = {2, "efor"},
 		[ODO] = {2, "do"},
 		[OWHILE] = {2, "while"},
 		[OLABEL] = {2, "label"},
@@ -191,7 +171,8 @@
 		[OCASE] = {1, "case"},
 		[ODEFAULT] = {1, "default"},
 		[OFTN] = {1, "function"},
-		[ODEF] = {2, "def"}
+		[ODEF] = {2, "def"},
+		[O2EXP] = { 2, ":"}
 	};
 	if (!np) {
 		fputs(" nil", stdout);
@@ -220,11 +201,6 @@
 	case 2:
 		prtree_helper(((struct node_op2 *) np)->left);
 		prtree_helper(((struct node_op2 *) np)->rigth);
-		break;
-	case 3:
-		prtree_helper(((struct node_op3 *) np)->left);
-		prtree_helper(((struct node_op3 *) np)->infix);
-		prtree_helper(((struct node_op3 *) np)->rigth);
 		break;
 	case 255: {
 		register struct node **bp, **lim;