blob: 15297d003ea691b29f0b68659d27af840fd8b450 [file] [log] [blame]
John Stiles52d3b012021-02-26 15:56:48 -05001/*
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
13namespace SkSL {
14
John Stiles23521a82021-03-02 17:02:51 -050015std::unique_ptr<Expression> PostfixExpression::Convert(const Context& context,
16 std::unique_ptr<Expression> base,
17 Operator op) {
John Stiles52d3b012021-02-26 15:56:48 -050018 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 Stiles23521a82021-03-02 17:02:51 -050028 return PostfixExpression::Make(context, std::move(base), op);
29}
30
31std::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 Stiles52d3b012021-02-26 15:56:48 -050036 return std::make_unique<PostfixExpression>(std::move(base), op);
37}
38
39} // namespace SkSL