• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
descriptionBinaryExpression41     String description() const override {
42         return "(" + fLeft->description() + " " + Compiler::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