root / trunk / compiler / cppAst / ast / expressions / BinaryOperator.hpp
1 | 7 | krennw | /**
|
---|---|---|---|
2 | *
|
||
3 | * OOAS Compiler - C++ AST
|
||
4 | *
|
||
5 | * Copyright 2015, AIT Austrian Institute of Technology.
|
||
6 | * All rights reserved.
|
||
7 | *
|
||
8 | * SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
||
9 | *
|
||
10 | * If you modify the file please update the list of contributors below to in-
|
||
11 | * clude your name. Please also stick to the coding convention of using TABs
|
||
12 | * to do the basic (block-level) indentation and spaces for anything after
|
||
13 | * that. (Enable the display of special chars and it should be pretty obvious
|
||
14 | * what this means.) Also, remove all trailing whitespace.
|
||
15 | *
|
||
16 | * Contributors:
|
||
17 | * Willibald Krenn (AIT)
|
||
18 | * Stephan Zimmerer (AIT)
|
||
19 | * Christoph Czurda (AIT)
|
||
20 | *
|
||
21 | */
|
||
22 | 2 | krennw | |
23 | |||
24 | |||
25 | |||
26 | #pragma once
|
||
27 | |||
28 | #include <ast/expressions/Expression.hpp> |
||
29 | #include <ast/IAstVisitor.hpp> |
||
30 | |||
31 | namespace Ast {
|
||
32 | |||
33 | class BinaryOperator |
||
34 | : public Expression
|
||
35 | { |
||
36 | protected:
|
||
37 | Expression* m_left; |
||
38 | Expression* m_right; |
||
39 | |||
40 | BinaryOperator(ExpressionKind kind): |
||
41 | Expression(kind), |
||
42 | m_left (nullptr),
|
||
43 | m_right (nullptr)
|
||
44 | {}; |
||
45 | BinaryOperator(const BinaryOperator& toCopy):
|
||
46 | Expression(toCopy), |
||
47 | m_left (toCopy.m_left), |
||
48 | m_right (toCopy.m_right) |
||
49 | {}; |
||
50 | |||
51 | static BinaryOperator* create(ExpressionKind k) {return new BinaryOperator(k);} |
||
52 | static BinaryOperator* createCopy(const BinaryOperator& toCopy) {return new BinaryOperator(toCopy);} |
||
53 | public:
|
||
54 | friend class Ast; |
||
55 | friend class Expression; |
||
56 | |||
57 | void init(std::int32_t line, std::int32_t pos,
|
||
58 | Type* typeRef,IdentifierList* callTargetsIdentifierListRef, |
||
59 | SymbolTable* symbTabRef, Expression* left, Expression* right) |
||
60 | { |
||
61 | Expression::init(line,pos,typeRef,callTargetsIdentifierListRef, symbTabRef); |
||
62 | m_left = left; |
||
63 | m_right = right; |
||
64 | } |
||
65 | |||
66 | |||
67 | Expression* left() {return m_left;};
|
||
68 | Expression* right(){return m_right;};
|
||
69 | void setRightChild(Expression* child) {m_right = child;};
|
||
70 | void setLeftChild(Expression* child) {m_left = child;};
|
||
71 | |||
72 | void accept(IAstVisitor& visitor) override {visitor.visit(this);}; |
||
73 | }; |
||
74 | } |