MCPcopy Create free account
hub / github.com/KhronosGroup/glslang / wrapupSwitchSubsequence

Method wrapupSwitchSubsequence

glslang/MachineIndependent/ParseHelper.cpp:11641–11671  ·  view source on GitHub ↗

Take the sequence of statements that has been built up since the last case/default, put it on the list of top-level nodes for the current (inner-most) switch statement, and follow that by the case/default we are on now. (See switch topology comment on TIntermSwitch.)

Source from the content-addressed store, hash-verified

11639// TIntermSwitch.)
11640//
11641void TParseContext::wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode)
11642{
11643 TIntermSequence* switchSequence = switchSequenceStack.back();
11644
11645 if (statements) {
11646 if (switchSequence->size() == 0)
11647 error(statements->getLoc(), "cannot have statements before first case/default label", "switch", "");
11648 statements->setOperator(EOpSequence);
11649 switchSequence->push_back(statements);
11650 }
11651 if (branchNode) {
11652 // check all previous cases for the same label (or both are 'default')
11653 for (unsigned int s = 0; s < switchSequence->size(); ++s) {
11654 TIntermBranch* prevBranch = (*switchSequence)[s]->getAsBranchNode();
11655 if (prevBranch) {
11656 TIntermTyped* prevExpression = prevBranch->getExpression();
11657 TIntermTyped* newExpression = branchNode->getAsBranchNode()->getExpression();
11658 if (prevExpression == nullptr && newExpression == nullptr)
11659 error(branchNode->getLoc(), "duplicate label", "default", "");
11660 else if (prevExpression != nullptr &&
11661 newExpression != nullptr &&
11662 prevExpression->getAsConstantUnion() &&
11663 newExpression->getAsConstantUnion() &&
11664 prevExpression->getAsConstantUnion()->getConstArray()[0].getIConst() ==
11665 newExpression->getAsConstantUnion()->getConstArray()[0].getIConst())
11666 error(branchNode->getLoc(), "duplicated value", "case", "");
11667 }
11668 }
11669 switchSequence->push_back(branchNode);
11670 }
11671}
11672
11673//
11674// Turn the top-level node sequence built up of wrapupSwitchSubsequence9)

Callers 1

yyparseFunction · 0.45

Calls 8

errorFunction · 0.85
setOperatorMethod · 0.80
getExpressionMethod · 0.80
getIConstMethod · 0.80
sizeMethod · 0.45
push_backMethod · 0.45
getAsBranchNodeMethod · 0.45
getAsConstantUnionMethod · 0.45

Tested by

no test coverage detected