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