1 /* 2 * Copyright 2016 Google Inc. 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 #ifndef SKSL_POSTFIXEXPRESSION 9 #define SKSL_POSTFIXEXPRESSION 10 11 #ifdef SKSL_EXT 12 #include "src/sksl/SkSLLexerExt.h" 13 #else 14 #include "src/sksl/SkSLLexer.h" 15 #endif 16 #include "src/sksl/SkSLOperators.h" 17 #include "src/sksl/ir/SkSLExpression.h" 18 19 namespace SkSL { 20 21 /** 22 * An expression modified by a unary operator appearing after it, such as 'i++'. 23 */ 24 class PostfixExpression final : public Expression { 25 public: 26 inline static constexpr Kind kExpressionKind = Kind::kPostfix; 27 PostfixExpression(std::unique_ptr<Expression> operand,Operator op)28 PostfixExpression(std::unique_ptr<Expression> operand, Operator op) 29 : INHERITED(operand->fLine, kExpressionKind, &operand->type()) 30 , fOperand(std::move(operand)) 31 , fOperator(op) {} 32 33 // Creates an SkSL postfix expression; uses the ErrorReporter to report errors. 34 static std::unique_ptr<Expression> Convert(const Context& context, 35 std::unique_ptr<Expression> base, 36 Operator op); 37 38 // Creates an SkSL postfix expression; reports errors via ASSERT. 39 static std::unique_ptr<Expression> Make(const Context& context, 40 std::unique_ptr<Expression> base, 41 Operator op); 42 getOperator()43 Operator getOperator() const { 44 return fOperator; 45 } 46 operand()47 std::unique_ptr<Expression>& operand() { 48 return fOperand; 49 } 50 operand()51 const std::unique_ptr<Expression>& operand() const { 52 return fOperand; 53 } 54 hasProperty(Property property)55 bool hasProperty(Property property) const override { 56 return (property == Property::kSideEffects) || 57 this->operand()->hasProperty(property); 58 } 59 clone()60 std::unique_ptr<Expression> clone() const override { 61 return std::make_unique<PostfixExpression>(this->operand()->clone(), this->getOperator()); 62 } 63 description()64 String description() const override { 65 return this->operand()->description() + this->getOperator().operatorName(); 66 } 67 68 private: 69 std::unique_ptr<Expression> fOperand; 70 Operator fOperator; 71 72 using INHERITED = Expression; 73 }; 74 75 } // namespace SkSL 76 77 #endif 78