commit 7d77cd4c9f3bd9c9a4ad49890b08a4181552ff3d
parent e011fdb4c004eeba9f35fc42a289bde407baa8ad
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 3 Oct 2013 21:57:56 +0200
Remove node3 call
node3 can be simulated using node and binary nodes, so remove it.
Diffstat:
4 files changed, 13 insertions(+), 35 deletions(-)
diff --git a/expr.c b/expr.c
@@ -291,7 +291,8 @@ cond(void)
while (yytoken == '?') {
aux = expr();
expect(':');
- np = node3(OTERN, np, aux, or());
+ np = node(OTERN, np,
+ node(O2EXP, aux, or()));
}
return np;
}
diff --git a/flow.c b/flow.c
@@ -114,7 +114,9 @@ _for(void)
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 @@ _if(void)
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 *
diff --git a/syntax.h b/syntax.h
@@ -12,7 +12,7 @@ enum opcode {
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 struct node *decl(void);
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);
diff --git a/tree.c b/tree.c
@@ -23,13 +23,6 @@ struct node_op2 {
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 @@ nodesym(struct symbol *sym)
}
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 @@ prtree_helper(register struct node *np)
[OBOR] = {2, "|"},
[OAND] = {2, "&&"},
[OOR] = {2, "||"},
- [OTERN] = {3, "?"},
+ [OTERN] = {2, "?"},
[OASSIGN] = {2, "="},
[OA_MUL] = {2, "*="},
[OA_DIV] = {2, "/="},
@@ -178,9 +158,9 @@ prtree_helper(register struct node *np)
[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 @@ prtree_helper(register struct node *np)
[OCASE] = {1, "case"},
[ODEFAULT] = {1, "default"},
[OFTN] = {1, "function"},
- [ODEF] = {2, "def"}
+ [ODEF] = {2, "def"},
+ [O2EXP] = { 2, ":"}
};
if (!np) {
fputs(" nil", stdout);
@@ -221,11 +202,6 @@ prtree_helper(register struct node *np)
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;