| 1 |
/* |
| 2 |
* Copyright 2021 Google Inc. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "src/sksl/ir/SkSLExpression.h" |
| 9 |
|
| 10 |
#include "src/sksl/SkSLBuiltinTypes.h" |
| 11 |
#include "src/sksl/SkSLContext.h" |
| 12 |
#include "src/sksl/SkSLDefines.h" |
| 13 |
#include "src/sksl/SkSLErrorReporter.h" |
| 14 |
#include "src/sksl/SkSLOperator.h" |
| 15 |
|
| 16 |
namespace SkSL { |
| 17 |
|
| 18 |
std::string Expression::description() const { |
| 19 |
return this->description(OperatorPrecedence::kExpression); |
| 20 |
} |
| 21 |
|
| 22 |
bool Expression::isIncomplete(const Context& context) const { |
| 23 |
switch (this->kind()) { |
| 24 |
case Kind::kFunctionReference: |
| 25 |
context.fErrors->error(fPosition.after(), "expected '(' to begin function call"); |
| 26 |
return true; |
| 27 |
|
| 28 |
case Kind::kMethodReference: |
| 29 |
context.fErrors->error(fPosition.after(), "expected '(' to begin method call"); |
| 30 |
return true; |
| 31 |
|
| 32 |
case Kind::kTypeReference: |
| 33 |
context.fErrors->error(fPosition.after(), |
| 34 |
"expected '(' to begin constructor invocation"); |
| 35 |
return true; |
| 36 |
|
| 37 |
case Kind::kVariableReference: |
| 38 |
if (this->type().matches(*context.fTypes.fSkCaps)) { |
| 39 |
context.fErrors->error(fPosition, "invalid expression"); |
| 40 |
return true; |
| 41 |
} |
| 42 |
return false; |
| 43 |
|
| 44 |
default: |
| 45 |
return false; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
ExpressionArray ExpressionArray::clone() const { |
| 50 |
ExpressionArray cloned; |
| 51 |
cloned.reserve_exact(this->size()); |
| 52 |
for (const std::unique_ptr<Expression>& expr : *this) { |
| 53 |
cloned.push_back(expr ? expr->clone() : nullptr); |
| 54 |
} |
| 55 |
return cloned; |
| 56 |
} |
| 57 |
|
| 58 |
} // namespace SkSL |