2 * Copyright 2021 Google LLC
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "src/sksl/ir/SkSLPostfixExpression.h"
10 #include "include/sksl/SkSLErrorReporter.h"
11 #include "src/sksl/SkSLAnalysis.h"
12 #include "src/sksl/SkSLContext.h"
13 #include "src/sksl/ir/SkSLVariableReference.h"
17 std::unique_ptr<Expression> PostfixExpression::Convert(const Context& context, Position pos,
18 std::unique_ptr<Expression> base, Operator op) {
19 const Type& baseType = base->type();
20 if (!baseType.isNumber()) {
21 context.fErrors->error(pos, "'" + std::string(op.tightOperatorName()) +
22 "' cannot operate on '" + baseType.displayName() + "'");
25 if (!Analysis::UpdateVariableRefKind(base.get(), VariableRefKind::kReadWrite,
29 return PostfixExpression::Make(context, pos, std::move(base), op);
32 std::unique_ptr<Expression> PostfixExpression::Make(const Context& context, Position pos,
33 std::unique_ptr<Expression> base, Operator op) {
34 SkASSERT(base->type().isNumber());
35 SkASSERT(Analysis::IsAssignable(*base));
36 return std::make_unique<PostfixExpression>(pos, std::move(base), op);