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_BINARYEXPRESSION 9 #define SKSL_BINARYEXPRESSION 10 11 #include "SkSLExpression.h" 12 #include "SkSLExpression.h" 13 #include "../SkSLIRGenerator.h" 14 #include "../SkSLLexer.h" 15 16 namespace SkSL { 17 18 /** 19 * A binary operation. 20 */ 21 struct BinaryExpression : public Expression { BinaryExpressionBinaryExpression22 BinaryExpression(int offset, std::unique_ptr<Expression> left, Token::Kind op, 23 std::unique_ptr<Expression> right, const Type& type) 24 : INHERITED(offset, kBinary_Kind, type) 25 , fLeft(std::move(left)) 26 , fOperator(op) 27 , fRight(std::move(right)) {} 28 constantPropagateBinaryExpression29 std::unique_ptr<Expression> constantPropagate(const IRGenerator& irGenerator, 30 const DefinitionMap& definitions) override { 31 return irGenerator.constantFold(*fLeft, 32 fOperator, 33 *fRight); 34 } 35 hasSideEffectsBinaryExpression36 bool hasSideEffects() const override { 37 return Compiler::IsAssignment(fOperator) || fLeft->hasSideEffects() || 38 fRight->hasSideEffects(); 39 } 40 cloneBinaryExpression41 std::unique_ptr<Expression> clone() const override { 42 return std::unique_ptr<Expression>(new BinaryExpression(fOffset, fLeft->clone(), fOperator, 43 fRight->clone(), fType)); 44 } 45 descriptionBinaryExpression46 String description() const override { 47 return "(" + fLeft->description() + " " + Compiler::OperatorName(fOperator) + " " + 48 fRight->description() + ")"; 49 } 50 51 std::unique_ptr<Expression> fLeft; 52 const Token::Kind fOperator; 53 std::unique_ptr<Expression> fRight; 54 55 typedef Expression INHERITED; 56 }; 57 58 } // namespace 59 60 #endif 61