Front-end: Add error-recovery code for a switch statement that ends with a case/default that has no statements.

This commit is contained in:
John Kessenich 2015-07-18 11:13:14 -06:00
parent 51b31b5785
commit 2b4b9bd65b
3 changed files with 14 additions and 1 deletions

View File

@ -37,6 +37,8 @@ ERROR: node is still EOpNull!
0:23 case: with expression
0:23 Constant:
0:23 2 (const int)
0:21 Sequence
0:21 Branch: Break
0:26 switch
0:26 condition
0:26 'c' (uniform mediump int)
@ -300,6 +302,8 @@ ERROR: node is still EOpNull!
0:128 body
0:128 Sequence
0:129 default:
0:128 Sequence
0:128 Branch: Break
0:133 switch
0:133 condition
0:133 'c' (uniform mediump int)
@ -369,6 +373,8 @@ ERROR: node is still EOpNull!
0:23 case: with expression
0:23 Constant:
0:23 2 (const int)
0:21 Sequence
0:21 Branch: Break
0:26 switch
0:26 condition
0:26 'c' (uniform mediump int)
@ -632,6 +638,8 @@ ERROR: node is still EOpNull!
0:128 body
0:128 Sequence
0:129 default:
0:128 Sequence
0:128 Branch: Break
0:133 switch
0:133 condition
0:133 'c' (uniform mediump int)

View File

@ -641,7 +641,7 @@ public:
virtual TIntermAggregate* getAsAggregate() { return this; }
virtual const TIntermAggregate* getAsAggregate() const { return this; }
virtual void setOperator(TOperator o) { op = o; }
virtual TIntermSequence& getSequence() { return sequence; }
virtual TIntermSequence& getSequence() { return sequence; }
virtual const TIntermSequence& getSequence() const { return sequence; }
virtual void setName(const TString& n) { name = n; }
virtual const TString& getName() const { return name; }

View File

@ -5287,6 +5287,11 @@ TIntermNode* TParseContext::addSwitch(TSourceLoc loc, TIntermTyped* expression,
error(loc, "last case/default label not followed by statements", "switch", "");
else
warn(loc, "last case/default label not followed by statements", "switch", "");
// emulate a break for error recovery
lastStatements = intermediate.makeAggregate(intermediate.addBranch(EOpBreak, loc));
lastStatements->setOperator(EOpSequence);
switchSequence->push_back(lastStatements);
}
TIntermAggregate* body = new TIntermAggregate(EOpSequence);