John Stiles | 52d3b01 | 2021-02-26 15:56:48 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 Google LLC |
| 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/SkSLAnalysis.h" |
| 9 | #include "src/sksl/SkSLContext.h" |
| 10 | #include "src/sksl/ir/SkSLPostfixExpression.h" |
| 11 | #include "src/sksl/ir/SkSLVariableReference.h" |
| 12 | |
| 13 | namespace SkSL { |
| 14 | |
| 15 | std::unique_ptr<Expression> PostfixExpression::Make(const Context& context, |
| 16 | std::unique_ptr<Expression> base, |
| 17 | Operator op) { |
| 18 | const Type& baseType = base->type(); |
| 19 | if (!baseType.isNumber()) { |
| 20 | context.fErrors.error(base->fOffset, |
| 21 | "'" + String(op.operatorName()) + "' cannot operate on '" + |
| 22 | baseType.displayName() + "'"); |
| 23 | return nullptr; |
| 24 | } |
| 25 | if (!Analysis::MakeAssignmentExpr(base.get(), VariableRefKind::kReadWrite, &context.fErrors)) { |
| 26 | return nullptr; |
| 27 | } |
| 28 | return std::make_unique<PostfixExpression>(std::move(base), op); |
| 29 | } |
| 30 | |
| 31 | } // namespace SkSL |