2 * Copyright 2016 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SKSL_POSTFIXEXPRESSION
9 #define SKSL_POSTFIXEXPRESSION
11 #include "include/sksl/SkSLOperator.h"
12 #include "src/sksl/ir/SkSLExpression.h"
17 * An expression modified by a unary operator appearing after it, such as 'i++'.
19 class PostfixExpression final : public Expression {
21 inline static constexpr Kind kExpressionKind = Kind::kPostfix;
23 PostfixExpression(Position pos, std::unique_ptr<Expression> operand, Operator op)
24 : INHERITED(pos, kExpressionKind, &operand->type())
25 , fOperand(std::move(operand))
28 // Creates an SkSL postfix expression; uses the ErrorReporter to report errors.
29 static std::unique_ptr<Expression> Convert(const Context& context,
31 std::unique_ptr<Expression> base,
34 // Creates an SkSL postfix expression; reports errors via ASSERT.
35 static std::unique_ptr<Expression> Make(const Context& context,
37 std::unique_ptr<Expression> base,
40 Operator getOperator() const {
44 std::unique_ptr<Expression>& operand() {
48 const std::unique_ptr<Expression>& operand() const {
52 bool hasProperty(Property property) const override {
53 return (property == Property::kSideEffects) ||
54 this->operand()->hasProperty(property);
57 std::unique_ptr<Expression> clone(Position pos) const override {
58 return std::make_unique<PostfixExpression>(pos, this->operand()->clone(),
62 std::string description() const override {
63 return this->operand()->description() + this->getOperator().operatorName();
67 std::unique_ptr<Expression> fOperand;
70 using INHERITED = Expression;