blob: 98241bda6dbcfa74951dad3b42995e7b9acc1c23 [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
John Stiles2dda4b62021-09-16 13:18:10 -04008#include "src/sksl/ir/SkSLPostfixExpression.h"
9
10#include "include/sksl/SkSLErrorReporter.h"
John Stiles52d3b012021-02-26 15:56:48 -050011#include "src/sksl/SkSLAnalysis.h"
12#include "src/sksl/SkSLContext.h"
John Stiles52d3b012021-02-26 15:56:48 -050013#include "src/sksl/ir/SkSLVariableReference.h"
14
15namespace SkSL {
16
John Stiles23521a82021-03-02 17:02:51 -050017std::unique_ptr<Expression> PostfixExpression::Convert(const Context& context,
18 std::unique_ptr<Expression> base,
19 Operator op) {
John Stiles52d3b012021-02-26 15:56:48 -050020 const Type& baseType = base->type();
21 if (!baseType.isNumber()) {
Ethan Nicholas89cfde12021-09-27 11:20:34 -040022 context.fErrors->error(base->fLine,
Ethan Nicholas8d116542021-08-11 13:27:16 -040023 "'" + String(op.operatorName()) + "' cannot operate on '" +
24 baseType.displayName() + "'");
John Stiles52d3b012021-02-26 15:56:48 -050025 return nullptr;
26 }
John Stilesbb8cf582021-08-26 23:34:59 -040027 if (!Analysis::UpdateVariableRefKind(base.get(), VariableRefKind::kReadWrite,
28 context.fErrors)) {
John Stiles52d3b012021-02-26 15:56:48 -050029 return nullptr;
30 }
John Stiles23521a82021-03-02 17:02:51 -050031 return PostfixExpression::Make(context, std::move(base), op);
32}
33
34std::unique_ptr<Expression> PostfixExpression::Make(const Context&,
35 std::unique_ptr<Expression> base,
36 Operator op) {
37 SkASSERT(base->type().isNumber());
38 SkASSERT(Analysis::IsAssignable(*base));
John Stiles52d3b012021-02-26 15:56:48 -050039 return std::make_unique<PostfixExpression>(std::move(base), op);
40}
41
42} // namespace SkSL