ref: 674df8f71072a8ee390e55e2659e9559d6acf4b1
parent: a7ae86f6a9874e7fd38c36fe31cef8e7d52268db
author: Ori Bernstein <[email protected]>
date: Fri Jun 29 08:56:53 EDT 2012
Add constructors for match nodes
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -534,9 +534,9 @@
;
forstmt : Tfor optexprln optexprln optexprln block
- {$$ = mkloop($1->line, $2, $3, $4, $5);}
+ {$$ = mkloopstmt($1->line, $2, $3, $4, $5);}
| Tfor decl optexprln optexprln block
- {$$ = mkloop($1->line, $2, $3, $4, $5);}
+ {$$ = mkloopstmt($1->line, $2, $3, $4, $5);}
;
optexprln: exprln {$$ = $1;}
@@ -545,15 +545,15 @@
whilestmt
: Twhile exprln block
- {$$ = mkloop($1->line, NULL, $2, NULL, $3);}
+ {$$ = mkloopstmt($1->line, NULL, $2, NULL, $3);}
;
ifstmt : Tif exprln blockbody elifs
- {$$ = mkif($1->line, $2, $3, $4);}
+ {$$ = mkifstmt($1->line, $2, $3, $4);}
;
elifs : Telif exprln blockbody elifs
- {$$ = mkif($1->line, $2, $3, $4);}
+ {$$ = mkifstmt($1->line, $2, $3, $4);}
| Telse blockbody Tendblk
{$$ = $2;}
| Tendblk
--- a/parse/node.c
+++ b/parse/node.c
@@ -73,7 +73,7 @@
return n;
}
-Node *mkif(int line, Node *cond, Node *iftrue, Node *iffalse)
+Node *mkifstmt(int line, Node *cond, Node *iftrue, Node *iffalse)
{
Node *n;
@@ -85,7 +85,7 @@
return n;
}
-Node *mkloop(int line, Node *init, Node *cond, Node *incr, Node *body)
+Node *mkloopstmt(int line, Node *init, Node *cond, Node *incr, Node *body)
{
Node *n;
@@ -95,6 +95,27 @@
n->loopstmt.step = incr;
n->loopstmt.body = body;
+ return n;
+}
+
+Node *mkmatchstmt(int line, Node *val, Node **matches, size_t nmatches)
+{
+ Node *n;
+
+ n = mknode(line, Nmatchstmt);
+ n->matchstmt.val = val;
+ n->matchstmt.matches = matches;
+ n->matchstmt.nmatches = nmatches;
+ return n;
+}
+
+Node *mkmatch(int line, Node *pat, Node *body)
+{
+ Node *n;
+
+ n = mknode(line, Nmatch);
+ n->match.pat = pat;
+ n->match.block = body;
return n;
}
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -345,8 +345,10 @@
Node *mkuse(int line, char *use, int islocal);
Node *mkexpr(int line, Op op, ...); /* NULL terminated */
Node *mkcall(int line, Node *fn, Node **args, size_t nargs);
-Node *mkif(int line, Node *cond, Node *iftrue, Node *iffalse);
-Node *mkloop(int line, Node *init, Node *cond, Node *incr, Node *body);
+Node *mkifstmt(int line, Node *cond, Node *iftrue, Node *iffalse);
+Node *mkloopstmt(int line, Node *init, Node *cond, Node *incr, Node *body);
+Node *mkmatchstmt(int line, Node *val, Node **matches, size_t nmatches);
+Node *mkmatch(int line, Node *pat, Node *body);
Node *mkblock(int line, Stab *scope);
Node *mkintlit(int line, uvlong val);