aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/ir/SkSLVarDeclarations.h
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-06-01 11:29:45 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-06-02 13:23:36 +0000
commit88bd8edcff23dc9cf31b664cba7ba73b235318b0 (patch)
treebda38d25837904f6e5320e3f54b91465a9aab3d9 /src/sksl/ir/SkSLVarDeclarations.h
parentec4400bfe34bbb90eaceaae168b2c6edf9aca4d9 (diff)
Fixed an issue with sksl variable declarations
There was an issue where multiple variables defined in the same declaration were not being sequenced appropriately during analysis, so 'int x = 0, y = x + 1' would report that x was undefined. Bug: skia: Change-Id: I882f7e216467306f6a6013a0a34aac30a4c60744 Reviewed-on: https://skia-review.googlesource.com/18313 Reviewed-by: Chris Dalton <csmartdalton@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/ir/SkSLVarDeclarations.h')
-rw-r--r--src/sksl/ir/SkSLVarDeclarations.h21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/sksl/ir/SkSLVarDeclarations.h b/src/sksl/ir/SkSLVarDeclarations.h
index dbf2928d49..c07fee87db 100644
--- a/src/sksl/ir/SkSLVarDeclarations.h
+++ b/src/sksl/ir/SkSLVarDeclarations.h
@@ -20,11 +20,12 @@ namespace SkSL {
* 'int x = 2, y[3];' is a VarDeclarations statement containing two individual VarDeclaration
* instances.
*/
-struct VarDeclaration {
+struct VarDeclaration : public Statement {
VarDeclaration(const Variable* var,
std::vector<std::unique_ptr<Expression>> sizes,
std::unique_ptr<Expression> value)
- : fVar(var)
+ : INHERITED(var->fPosition, Statement::kVarDeclaration_Kind)
+ , fVar(var)
, fSizes(std::move(sizes))
, fValue(std::move(value)) {}
@@ -46,6 +47,8 @@ struct VarDeclaration {
const Variable* fVar;
std::vector<std::unique_ptr<Expression>> fSizes;
std::unique_ptr<Expression> fValue;
+
+ typedef Statement INHERITED;
};
/**
@@ -55,14 +58,18 @@ struct VarDeclarations : public ProgramElement {
VarDeclarations(Position position, const Type* baseType,
std::vector<std::unique_ptr<VarDeclaration>> vars)
: INHERITED(position, kVar_Kind)
- , fBaseType(*baseType)
- , fVars(std::move(vars)) {}
+ , fBaseType(*baseType) {
+ for (auto& var : vars) {
+ fVars.push_back(std::unique_ptr<Statement>(var.release()));
+ }
+ }
String description() const override {
if (!fVars.size()) {
return String();
}
- String result = fVars[0]->fVar->fModifiers.description() + fBaseType.description() + " ";
+ String result = ((VarDeclaration&) *fVars[0]).fVar->fModifiers.description() +
+ fBaseType.description() + " ";
String separator;
for (const auto& var : fVars) {
result += separator;
@@ -73,7 +80,9 @@ struct VarDeclarations : public ProgramElement {
}
const Type& fBaseType;
- std::vector<std::unique_ptr<VarDeclaration>> fVars;
+ // this *should* be a vector of unique_ptr<VarDeclaration>, but it significantly simplifies the
+ // CFG to only have to worry about unique_ptr<Statement>
+ std::vector<std::unique_ptr<Statement>> fVars;
typedef ProgramElement INHERITED;
};