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 | |
John Stiles | 23521a8 | 2021-03-02 17:02:51 -0500 | [diff] [blame^] | 15 | std::unique_ptr<Expression> PostfixExpression::Convert(const Context& context, |
| 16 | std::unique_ptr<Expression> base, |
| 17 | Operator op) { |
John Stiles | 52d3b01 | 2021-02-26 15:56:48 -0500 | [diff] [blame] | 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 | } |
John Stiles | 23521a8 | 2021-03-02 17:02:51 -0500 | [diff] [blame^] | 28 | return PostfixExpression::Make(context, std::move(base), op); |
| 29 | } |
| 30 | |
| 31 | std::unique_ptr<Expression> PostfixExpression::Make(const Context&, |
| 32 | std::unique_ptr<Expression> base, |
| 33 | Operator op) { |
| 34 | SkASSERT(base->type().isNumber()); |
| 35 | SkASSERT(Analysis::IsAssignable(*base)); |
John Stiles | 52d3b01 | 2021-02-26 15:56:48 -0500 | [diff] [blame] | 36 | return std::make_unique<PostfixExpression>(std::move(base), op); |
| 37 | } |
| 38 | |
| 39 | } // namespace SkSL |