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 "../SkSLToken.h" 15 16namespace SkSL { 17 18/** 19 * A binary operation. 20 */ 21struct BinaryExpression : public Expression { 22 BinaryExpression(Position position, std::unique_ptr<Expression> left, Token::Kind op, 23 std::unique_ptr<Expression> right, const Type& type) 24 : INHERITED(position, kBinary_Kind, type) 25 , fLeft(std::move(left)) 26 , fOperator(op) 27 , fRight(std::move(right)) {} 28 29 std::unique_ptr<Expression> constantPropagate(const IRGenerator& irGenerator, 30 const DefinitionMap& definitions) override { 31 return irGenerator.constantFold(*fLeft, 32 fOperator, 33 *fRight); 34 } 35 36 bool hasSideEffects() const override { 37 return Token::IsAssignment(fOperator) || fLeft->hasSideEffects() || 38 fRight->hasSideEffects(); 39 } 40 41 String description() const override { 42 return "(" + fLeft->description() + " " + Token::OperatorName(fOperator) + " " + 43 fRight->description() + ")"; 44 } 45 46 std::unique_ptr<Expression> fLeft; 47 const Token::Kind fOperator; 48 std::unique_ptr<Expression> fRight; 49 50 typedef Expression INHERITED; 51}; 52 53} // namespace 54 55#endif 56