aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLIRGenerator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sksl/SkSLIRGenerator.cpp')
-rw-r--r--src/sksl/SkSLIRGenerator.cpp78
1 files changed, 2 insertions, 76 deletions
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp
index ae2a90f899..247766f51e 100644
--- a/src/sksl/SkSLIRGenerator.cpp
+++ b/src/sksl/SkSLIRGenerator.cpp
@@ -8,7 +8,6 @@
#include "SkSLIRGenerator.h"
#include "limits.h"
-#include <unordered_set>
#include "SkSLCompiler.h"
#include "ast/SkSLASTBoolLiteral.h"
@@ -40,8 +39,6 @@
#include "ir/SkSLPostfixExpression.h"
#include "ir/SkSLPrefixExpression.h"
#include "ir/SkSLReturnStatement.h"
-#include "ir/SkSLSwitchCase.h"
-#include "ir/SkSLSwitchStatement.h"
#include "ir/SkSLSwizzle.h"
#include "ir/SkSLTernaryExpression.h"
#include "ir/SkSLUnresolvedFunction.h"
@@ -84,27 +81,12 @@ public:
IRGenerator* fIR;
};
-class AutoSwitchLevel {
-public:
- AutoSwitchLevel(IRGenerator* ir)
- : fIR(ir) {
- fIR->fSwitchLevel++;
- }
-
- ~AutoSwitchLevel() {
- fIR->fSwitchLevel--;
- }
-
- IRGenerator* fIR;
-};
-
IRGenerator::IRGenerator(const Context* context, std::shared_ptr<SymbolTable> symbolTable,
ErrorReporter& errorReporter)
: fContext(*context)
, fCurrentFunction(nullptr)
, fSymbolTable(std::move(symbolTable))
, fLoopLevel(0)
-, fSwitchLevel(0)
, fErrors(errorReporter) {}
void IRGenerator::pushSymbolTable() {
@@ -171,8 +153,6 @@ std::unique_ptr<Statement> IRGenerator::convertStatement(const ASTStatement& sta
return this->convertWhile((ASTWhileStatement&) statement);
case ASTStatement::kDo_Kind:
return this->convertDo((ASTDoStatement&) statement);
- case ASTStatement::kSwitch_Kind:
- return this->convertSwitch((ASTSwitchStatement&) statement);
case ASTStatement::kReturn_Kind:
return this->convertReturn((ASTReturnStatement&) statement);
case ASTStatement::kBreak_Kind:
@@ -377,60 +357,6 @@ std::unique_ptr<Statement> IRGenerator::convertDo(const ASTDoStatement& d) {
std::move(test)));
}
-std::unique_ptr<Statement> IRGenerator::convertSwitch(const ASTSwitchStatement& s) {
- AutoSwitchLevel level(this);
- std::unique_ptr<Expression> value = this->convertExpression(*s.fValue);
- if (!value) {
- return nullptr;
- }
- if (value->fType != *fContext.fUInt_Type) {
- value = this->coerce(std::move(value), *fContext.fInt_Type);
- if (!value) {
- return nullptr;
- }
- }
- AutoSymbolTable table(this);
- std::unordered_set<int> caseValues;
- std::vector<std::unique_ptr<SwitchCase>> cases;
- for (const auto& c : s.fCases) {
- std::unique_ptr<Expression> caseValue;
- if (c->fValue) {
- caseValue = this->convertExpression(*c->fValue);
- if (!caseValue) {
- return nullptr;
- }
- if (caseValue->fType != *fContext.fUInt_Type) {
- caseValue = this->coerce(std::move(caseValue), *fContext.fInt_Type);
- if (!caseValue) {
- return nullptr;
- }
- }
- if (!caseValue->isConstant()) {
- fErrors.error(caseValue->fPosition, "case value must be a constant");
- return nullptr;
- }
- ASSERT(caseValue->fKind == Expression::kIntLiteral_Kind);
- int64_t v = ((IntLiteral&) *caseValue).fValue;
- if (caseValues.find(v) != caseValues.end()) {
- fErrors.error(caseValue->fPosition, "duplicate case value");
- }
- caseValues.insert(v);
- }
- std::vector<std::unique_ptr<Statement>> statements;
- for (const auto& s : c->fStatements) {
- std::unique_ptr<Statement> converted = this->convertStatement(*s);
- if (!converted) {
- return nullptr;
- }
- statements.push_back(std::move(converted));
- }
- cases.emplace_back(new SwitchCase(c->fPosition, std::move(caseValue),
- std::move(statements)));
- }
- return std::unique_ptr<Statement>(new SwitchStatement(s.fPosition, std::move(value),
- std::move(cases)));
-}
-
std::unique_ptr<Statement> IRGenerator::convertExpressionStatement(
const ASTExpressionStatement& s) {
std::unique_ptr<Expression> e = this->convertExpression(*s.fExpression);
@@ -467,10 +393,10 @@ std::unique_ptr<Statement> IRGenerator::convertReturn(const ASTReturnStatement&
}
std::unique_ptr<Statement> IRGenerator::convertBreak(const ASTBreakStatement& b) {
- if (fLoopLevel > 0 || fSwitchLevel > 0) {
+ if (fLoopLevel > 0) {
return std::unique_ptr<Statement>(new BreakStatement(b.fPosition));
} else {
- fErrors.error(b.fPosition, "break statement must be inside a loop or switch");
+ fErrors.error(b.fPosition, "break statement must be inside a loop");
return nullptr;
}
}