blob: 88feba66a76c6783a0950aab6ae9135f53289410 [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
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"
12#include "../SkSLToken.h"
Greg Daniel792d0f12016-11-20 14:53:35 +000013#include <sstream>
ethannicholasb3058bd2016-07-01 08:22:01 -070014
15namespace SkSL {
16
17/**
18 * Represents a binary operation, with the operator represented by the token's type.
19 */
20struct ASTBinaryExpression : public ASTExpression {
21 ASTBinaryExpression(std::unique_ptr<ASTExpression> left, Token op,
22 std::unique_ptr<ASTExpression> right)
23 : INHERITED(op.fPosition, kBinary_Kind)
24 , fLeft(std::move(left))
25 , fOperator(op.fKind)
26 , fRight(std::move(right)) {}
27
Greg Daniel792d0f12016-11-20 14:53:35 +000028 std::string description() const override {
ethannicholasb3058bd2016-07-01 08:22:01 -070029 return "(" + fLeft->description() + " " + Token::OperatorName(fOperator) + " " +
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