ref: 2891a62c9bcfcd4c3e9b396490245249d8e64bcb
parent: a8acad8243a648e895baebf39b5672b8209a30c6
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Aug 28 16:46:22 EDT 2012
Added tree structure for return
--- a/flow.c
+++ b/flow.c
@@ -175,6 +175,19 @@
}
static struct node *
+_return(void)
+{
+ register struct node *np;
+ extern struct ctype *curfun;
+
+ expect(RETURN);
+ /* TODO: Check the type of the function, can be void */
+ np = expr();
+ expect(';');
+ return node1(ORETURN, np);
+}
+
+static struct node *
stmt(void)
{
register struct node *np;
@@ -188,7 +201,7 @@
case WHILE: return _while();
case CONTINUE: return _continue();
case BREAK: return _break();
- case RETURN:
+ case RETURN: return _return();
case GOTO: return _goto();
case CASE: /* TODO */
case DEFAULT: /* TODO */
--- a/syntax.h
+++ b/syntax.h
@@ -11,7 +11,8 @@
OBOR, OAND, OOR, OTERN, OASSIGN, OA_MUL, OA_DIV,
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
+ OFEXP, ODO, OWHILE, OLABEL, OGOTO, OBREAK, OCONT,
+ ORETURN
};
struct node;
--- a/tree.c
+++ b/tree.c
@@ -187,6 +187,7 @@
[OGOTO] = {1, "goto"},
[OBREAK] = {1, "break"},
[OCONT] = {1, "cont"},
+ [ORETURN] = {1, "return"}
};
if (!np) {
fputs(" nil", stdout);
--
⑨