37class ConstantExpressionVisitor :
public ProgramVisitor {
40 : fLoopIndices(loopIndices) {}
42 bool visitExpression(
const Expression&
e)
override {
50 case Expression::Kind::kSetting:
55 case Expression::Kind::kVariableReference: {
56 const Variable* v =
e.as<VariableReference>().variable();
61 return !fLoopIndices || !fLoopIndices->contains(v);
65 case Expression::Kind::kBinary:
72 case Expression::Kind::kConstructorArray:
73 case Expression::Kind::kConstructorArrayCast:
74 case Expression::Kind::kConstructorCompound:
75 case Expression::Kind::kConstructorCompoundCast:
76 case Expression::Kind::kConstructorDiagonalMatrix:
77 case Expression::Kind::kConstructorMatrixResize:
78 case Expression::Kind::kConstructorScalarCast:
79 case Expression::Kind::kConstructorSplat:
80 case Expression::Kind::kConstructorStruct:
81 case Expression::Kind::kFieldAccess:
83 case Expression::Kind::kPrefix:
84 case Expression::Kind::kPostfix:
85 case Expression::Kind::kSwizzle:
86 case Expression::Kind::kTernary:
87 return INHERITED::visitExpression(
e);
93 case Expression::Kind::kFunctionCall:
94 case Expression::Kind::kChildCall:
98 case Expression::Kind::kPoison:
99 case Expression::Kind::kFunctionReference:
100 case Expression::Kind::kMethodReference:
101 case Expression::Kind::kTypeReference:
118class ES2IndexingVisitor :
public ProgramVisitor {
120 ES2IndexingVisitor(ErrorReporter&
errors) : fErrors(
errors) {}
122 bool visitStatement(
const Statement&
s)
override {
123 if (
s.is<ForStatement>()) {
124 const ForStatement&
f =
s.as<ForStatement>();
125 SkASSERT(
f.initializer() &&
f.initializer()->is<VarDeclaration>());
126 const Variable* var =
f.initializer()->as<VarDeclaration>().var();
127 SkASSERT(!fLoopIndices.contains(var));
128 fLoopIndices.add(var);
129 bool result = this->visitStatement(*
f.statement());
130 fLoopIndices.remove(var);
133 return INHERITED::visitStatement(
s);
136 bool visitExpression(
const Expression&
e)
override {
137 if (
e.is<IndexExpression>()) {
138 const IndexExpression&
i =
e.as<IndexExpression>();
139 if (ConstantExpressionVisitor{&fLoopIndices}.visitExpression(*
i.index())) {
140 fErrors.error(
i.fPosition,
"index expression must be constant");
144 return INHERITED::visitExpression(
e);
150 ErrorReporter& fErrors;
158 return !ConstantExpressionVisitor{
nullptr}.visitExpression(expr);
162 ES2IndexingVisitor visitor(
errors);
163 visitor.visitProgramElement(pe);
#define SkDEBUGFAIL(message)
#define INHERITED(method,...)
virtual bool visitProgramElement(typename T::ProgramElement &programElement)
bool IsConstantExpression(const Expression &expr)
void ValidateIndexingForES2(const ProgramElement &pe, ErrorReporter &errors)