Line data Source code
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 0 : struct BinaryExpression : public Expression {
22 0 : BinaryExpression(Position position, std::unique_ptr<Expression> left, Token::Kind op,
23 : std::unique_ptr<Expression> right, const Type& type)
24 0 : : INHERITED(position, kBinary_Kind, type)
25 0 : , fLeft(std::move(left))
26 : , fOperator(op)
27 0 : , fRight(std::move(right)) {}
28 :
29 0 : virtual std::unique_ptr<Expression> constantPropagate(
30 : const IRGenerator& irGenerator,
31 : const DefinitionMap& definitions) override {
32 0 : return irGenerator.constantFold(*fLeft,
33 0 : fOperator,
34 0 : *fRight);
35 : }
36 :
37 0 : virtual String description() const override {
38 0 : return "(" + fLeft->description() + " " + Token::OperatorName(fOperator) + " " +
39 0 : 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
|