Add basic error checks for switch and case
Check that the case labels have constant scalar integers, and that switch
statements are initialized with scalar integers. Also check that case and
default labels do not exist outside switch statements. Allow break
statements inside switch statements.
Tested by manually disabling shading language version checks for switch
in a Chromium build and checking that the expected errors are generated.
BUG=angle:921
Change-Id: Ibe83d0db52958c493ded5640d4babf670dc02d55
Reviewed-on: https://chromium-review.googlesource.com/251523
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/ParseContext.h b/src/compiler/translator/ParseContext.h
index a4e28de..ff0ba37 100644
--- a/src/compiler/translator/ParseContext.h
+++ b/src/compiler/translator/ParseContext.h
@@ -34,6 +34,7 @@
treeRoot(0),
mLoopNestingLevel(0),
structNestingLevel(0),
+ mSwitchNestingLevel(0),
currentFunctionType(NULL),
mFunctionReturnsValue(false),
checksPrecisionErrors(checksPrecErrors),
@@ -53,6 +54,7 @@
TIntermNode* treeRoot; // root of parse tree being created
int mLoopNestingLevel; // 0 if outside all loops
int structNestingLevel; // incremented while parsing a struct declaration
+ int mSwitchNestingLevel; // 0 if outside all switch statements
const TType* currentFunctionType; // the return type of the function that's currently being parsed
bool mFunctionReturnsValue; // true if a non-void function has a return
bool checksPrecisionErrors; // true if an error will be generated when a variable is declared without precision, explicit or implicit.