ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 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_ASTBINARYEXPRESSION |
| 9 | #define SKSL_ASTBINARYEXPRESSION |
| 10 | |
| 11 | #include "SkSLASTExpression.h" |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 12 | #include "../SkSLCompiler.h" |
| 13 | #include "../SkSLLexer.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 14 | |
| 15 | namespace SkSL { |
| 16 | |
| 17 | /** |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 18 | * Represents a binary operation, with the operator represented by the token's type. |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 19 | */ |
| 20 | struct ASTBinaryExpression : public ASTExpression { |
| 21 | ASTBinaryExpression(std::unique_ptr<ASTExpression> left, Token op, |
| 22 | std::unique_ptr<ASTExpression> right) |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 23 | : INHERITED(op.fOffset, kBinary_Kind) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 24 | , fLeft(std::move(left)) |
| 25 | , fOperator(op.fKind) |
| 26 | , fRight(std::move(right)) {} |
| 27 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 28 | String description() const override { |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 29 | return "(" + fLeft->description() + " " + Compiler::OperatorName(fOperator) + " " + |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 30 | fRight->description() + ")"; |
| 31 | } |
| 32 | |
| 33 | const std::unique_ptr<ASTExpression> fLeft; |
| 34 | const Token::Kind fOperator; |
| 35 | const std::unique_ptr<ASTExpression> fRight; |
| 36 | |
| 37 | typedef ASTExpression INHERITED; |
| 38 | }; |
| 39 | |
| 40 | } // namespace |
| 41 | |
| 42 | #endif |