ref: b09facc71149bd600d32d2c063c762e78340bda9
parent: 5be6d06570908e1574813c3f9b0f0f6d8a7cc34b
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Apr 24 12:57:24 EDT 2014
Add Caselist type This type is going to be used for the switch implementation, so we need keep a track of all the elements of the switch.
--- a/cc1.h
+++ b/cc1.h
@@ -125,11 +125,12 @@
*lookup(char *s, unsigned char ns),
*install(char *s, unsigned char ns);
-typedef void Ctxfun(Symbol *, Symbol *, Symbol *);
+typedef struct caselist Caselist;
+typedef void Ctxfun(Symbol *, Symbol *, Caselist *);
extern Ctxfun compound;
extern void context(Ctxfun *fun,
- Symbol *lbreak, Symbol *lcont, Symbol *lswitch);
+ Symbol *lbreak, Symbol *lcont, Caselist *lswitch);
extern Type *typename(void);
--- a/stmt.c
+++ b/stmt.c
@@ -5,11 +5,22 @@
#include "cc1.h"
+struct scase {
+ int val;
+ Symbol *label;
+ struct scase *next;
+};
+
+struct caselist {
+ short nr;
+ struct scase *head;
+};
+
Symbol *curfun;
extern Node *convert(Node *np, Type *tp1, char iscast);
extern Node *iszero(Node *np), *eval(Node *np);
-static void stmt(Symbol *lbreak, Symbol *lcont, Symbol *lswitch);
+static void stmt(Symbol *lbreak, Symbol *lcont, Caselist *lswitch);
static Symbol *
label(char *s, char define)
@@ -54,7 +65,7 @@
}
static void
-While(Symbol *lswitch)
+While(Caselist *lswitch)
{
Symbol *begin, *cond, *end;
Node *np;
@@ -76,7 +87,7 @@
}
static void
-For(Symbol *lswitch)
+For(Caselist *lswitch)
{
Symbol *begin, *cond, *end;
Node *econd = NULL, *einc = NULL;
@@ -109,7 +120,7 @@
}
static void
-Dowhile(Symbol *lswitch)
+Dowhile(Caselist *lswitch)
{
Symbol *begin= label(NULL, 1), *end = label(NULL, 1);
@@ -189,7 +200,7 @@
}
void
-compound(Symbol *lbreak, Symbol *lcont, Symbol *lswitch)
+compound(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
{
expect('{');
for (;;) {
@@ -207,7 +218,7 @@
}
static void
-stmt(Symbol *lbreak, Symbol *lcont, Symbol *lswitch)
+stmt(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
{
repeat:
--- a/symbol.c
+++ b/symbol.c
@@ -47,7 +47,7 @@
}
void
-context(Ctxfun *fun, Symbol *lbreak, Symbol *lcont, Symbol *lswitch)
+context(Ctxfun *fun, Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
{
uint8_t ns;