Home | History | Annotate | Download | only in ir
      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 
     16 namespace SkSL {
     17 
     18 /**
     19  * A binary operation.
     20  */
     21 struct 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     virtual std::unique_ptr<Expression> constantPropagate(
     30                                                         const IRGenerator& irGenerator,
     31                                                         const DefinitionMap& definitions) override {
     32         return irGenerator.constantFold(*fLeft,
     33                                         fOperator,
     34                                         *fRight);
     35     }
     36 
     37     virtual SkString description() const override {
     38         return "(" + fLeft->description() + " " + Token::OperatorName(fOperator) + " " +
     39                fRight->description() + ")";
     40     }
     41 
     42     std::unique_ptr<Expression> fLeft;
     43     const Token::Kind fOperator;
     44     std::unique_ptr<Expression> fRight;
     45 
     46     typedef Expression INHERITED;
     47 };
     48 
     49 } // namespace
     50 
     51 #endif
     52