1 // Copyright 2017-2019 VMware, Inc.
2 // SPDX-License-Identifier: BSD-2-Clause
3 //
4 // The BSD-2 license (the License) set forth below applies to all parts of the
5 // Cascade project. You may not use this file except in compliance with the
6 // License.
7 //
8 // BSD-2 License
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright notice, this
14 // list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright notice,
17 // this list of conditions and the following disclaimer in the documentation
18 // and/or other materials provided with the distribution.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND
21 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 #ifndef CASCADE_SRC_VERILOG_AST_BINARY_EXPRESSION_H
32 #define CASCADE_SRC_VERILOG_AST_BINARY_EXPRESSION_H
33
34 #include "verilog/ast/types/expression.h"
35 #include "verilog/ast/types/macro.h"
36
37 namespace cascade {
38
39 class BinaryExpression : public Expression {
40 public:
41 // Supporting Concepts:
42 enum class Op : uint8_t {
43 PLUS = 0,
44 MINUS,
45 TIMES,
46 DIV,
47 MOD,
48 EEEQ,
49 EEQ,
50 BEEQ,
51 BEQ,
52 AAMP,
53 PPIPE,
54 TTIMES,
55 LT,
56 LEQ,
57 GT,
58 GEQ,
59 AMP,
60 PIPE,
61 CARAT,
62 TCARAT,
63 LLT,
64 LLLT,
65 GGT,
66 GGGT
67 };
68
69 // Constructors:
70 BinaryExpression(Expression* lhs__, Op op__, Expression* rhs__);
71 ~BinaryExpression() override;
72
73 // Node Interface:
74 NODE(BinaryExpression)
75 BinaryExpression* clone() const override;
76
77 // Get/Set
78 PTR_GET_SET(BinaryExpression, Expression, lhs)
79 VAL_GET_SET(BinaryExpression, Op, op)
80 PTR_GET_SET(BinaryExpression, Expression, rhs)
81
82 private:
83 PTR_ATTR(Expression, lhs);
84 VAL_ATTR(Op, op);
85 PTR_ATTR(Expression, rhs);
86 };
87
BinaryExpression(Expression * lhs__,Op op__,Expression * rhs__)88 inline BinaryExpression::BinaryExpression(Expression* lhs__, Op op__, Expression* rhs__) : Expression(Node::Tag::binary_expression) {
89 PTR_SETUP(lhs);
90 VAL_SETUP(op);
91 PTR_SETUP(rhs);
92 parent_ = nullptr;
93 }
94
~BinaryExpression()95 inline BinaryExpression::~BinaryExpression() {
96 PTR_TEARDOWN(lhs);
97 VAL_TEARDOWN(op);
98 PTR_TEARDOWN(rhs);
99 }
100
clone()101 inline BinaryExpression* BinaryExpression::clone() const {
102 return new BinaryExpression(lhs_->clone(), op_, rhs_->clone());
103 }
104
105 } // namespace cascade
106
107 #endif
108
109