shithub: scc

Download patch

ref: 0304c0486f58225dca5ee08111a1493d3c58daa7
parent: 2891a62c9bcfcd4c3e9b396490245249d8e64bcb
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Aug 28 16:48:20 EDT 2012

Added tree structure for case

--- a/flow.c
+++ b/flow.c
@@ -188,6 +188,25 @@
 }
 
 static struct node *
+_case(void)
+{
+	register unsigned char *bp;
+	register struct node *np, *exp;
+
+	expect(CASE);
+	exp = expr();
+	/* TODO: check if exp is constant */
+	/* TODO: Check if the type is correct */
+	for (bp = blocks; bp < blockp && *bp != OSWITCH; ++bp)
+		; /* nothing */
+	if (bp == blockp)
+		error("case statement not within switch");
+	np = node1(OCASE, exp);
+	expect(':');
+	return np;
+}
+
+static struct node *
 stmt(void)
 {
 	register struct node *np;
@@ -203,7 +222,7 @@
 	case BREAK:    return _break();
 	case RETURN:   return _return();
 	case GOTO:     return _goto();
-	case CASE:     /* TODO */
+	case CASE:     return _case();
 	case DEFAULT:  /* TODO */
 	case IDEN:     return label();
 	}
--- 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
+	ORETURN, OCASE
 };
 
 struct node;
--- a/tree.c
+++ b/tree.c
@@ -187,7 +187,8 @@
 		[OGOTO] = {1, "goto"},
 		[OBREAK] = {1, "break"},
 		[OCONT] = {1, "cont"},
-		[ORETURN] = {1, "return"}
+		[ORETURN] = {1, "return"},
+		[OCASE] = {1, "case"}
 	};
 	if (!np) {
 		fputs(" nil", stdout);