MicroModelicaCCompiler  4.5.3
statement.hpp
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  This file is part of QSS Solver.
4 
5  QSS Solver is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  QSS Solver is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QSS Solver. If not, see <http://www.gnu.org/licenses/>.
17 
18  ******************************************************************************/
19 
20 #ifndef AST_STATEMENT_H_
21 #define AST_STATEMENT_H_
22 
23 #include <string>
24 
25 #include "../util/macros.hpp"
26 #include "../util/util_types.hpp"
27 #include "ast_node.hpp"
28 #include "ast_types.hpp"
29 
30 class AST_Statement_ : public AST_Node_ {
31  public:
32  DEFINE_CLASS_PRINTER(AST_Statement);
33 
34  virtual string print() const = 0;
35  virtual StatementType statementType() = 0;
36  void accept(AST_Visitor *visitor);
37  GET_AS(Statement, While);
38  GET_AS(Statement, If);
39  GET_AS(Statement, For);
40  GET_AS(Statement, When);
41  GET_AS(Statement, Assign);
42  GET_AS(Statement, OutputAssigment);
43 };
44 
46  public:
47  string print() const;
48  virtual StatementType statementType();
49 };
50 
52  public:
53  string print() const;
54  virtual StatementType statementType();
55 };
56 
58  public:
59  AST_Statement_When_(AST_Expression cond, AST_StatementList, AST_Statement_ElseList, AST_Comment);
60  string print() const;
61  AST_Expression condition() const;
62  AST_StatementList statements() const;
63  AST_Statement_ElseList else_when() const;
64  AST_Comment comment() const;
65  bool hasComment();
66  bool hasElsewhen();
67  virtual StatementType statementType();
68 
69  private:
70  AST_Expression _cond;
71  AST_StatementList _sts;
72  AST_Statement_ElseList _else_list;
73  AST_Comment _comm;
74 };
75 
77  public:
78  AST_Statement_Assign_(AST_Expression_ComponentReference cr, AST_Expression exp);
79  string print() const;
80  AST_Expression exp() const;
81  void setExp(AST_Expression exp);
82  void setLHS(AST_Expression_ComponentReference comp_ref);
83  AST_Expression_ComponentReference lhs() const;
84  virtual StatementType statementType();
85 
86  private:
87  AST_Expression_ComponentReference _lhs;
88  AST_Expression _exp;
89 };
90 
92  public:
93  AST_Statement_If_(AST_Expression cond, AST_StatementList true_st, AST_Statement_ElseList, AST_StatementList false_st);
94  string print() const;
95  AST_Expression condition() const;
96  AST_StatementList statements() const;
97  AST_StatementList else_statements() const;
98  AST_Statement_ElseList else_if() const;
99  virtual StatementType statementType();
100 
101  private:
102  AST_Expression _cond;
103  AST_StatementList _true_st, _false_st;
104  AST_Statement_ElseList _else_list;
105 };
106 
108  public:
109  AST_Statement_While_(AST_Expression cond, AST_StatementList);
110  string print() const;
111  AST_Expression condition() const;
112  AST_StatementList statements() const;
113  virtual StatementType statementType();
114 
115  private:
116  AST_Expression _cond;
117  AST_StatementList _sts;
118 };
119 
121  public:
122  AST_Statement_For_(AST_ForIndexList index, AST_StatementList);
123  string print() const;
124  AST_StatementList statements() const;
125  AST_ForIndexList forIndexList() const;
126  virtual StatementType statementType();
127 
128  private:
129  AST_StatementList _sts;
130  AST_ForIndexList _ind;
131 };
132 
134  public:
135  AST_Statement_OutputAssigment_(AST_ExpressionList, AST_Expression_ComponentReference, AST_ExpressionList);
136  string print() const;
137  AST_ExpressionList out_expressions() const;
138  AST_Expression_ComponentReference function() const;
139  AST_ExpressionList arguments() const;
140  virtual StatementType statementType();
141  std::string functionName();
142 
143  private:
144  AST_ExpressionList _out_exps;
145  AST_Expression_ComponentReference _func;
146  AST_ExpressionList _args;
147  std::string _function_name;
148 };
149 
151  public:
152  AST_Statement_Else_(AST_Expression cond, AST_StatementList sts);
153  AST_Expression condition() const;
154  AST_StatementList statements() const;
155  void accept(AST_Visitor *visitor);
156 
157  private:
158  AST_Expression _cond;
159  AST_StatementList _sts;
160 };
161 
162 #endif /* AST_STATEMENT_H_ */
AST_Statement_Else_::accept
void accept(AST_Visitor *visitor)
Definition: statement.cpp:317
AST_Statement_If_::condition
AST_Expression condition() const
Definition: statement.cpp:222
AST_Statement_
Definition: statement.hpp:30
AST_Statement_Assign_::print
string print() const
Definition: statement.cpp:80
AST_Statement_For_
Definition: statement.hpp:120
AST_Statement_OutputAssigment_::AST_Statement_OutputAssigment_
AST_Statement_OutputAssigment_(AST_ExpressionList, AST_Expression_ComponentReference, AST_ExpressionList)
Definition: statement.cpp:267
AST_Statement_::accept
void accept(AST_Visitor *visitor)
Definition: statement.cpp:40
AST_Statement_Assign_::setExp
void setExp(AST_Expression exp)
Definition: statement.cpp:99
AST_Statement_OutputAssigment_::arguments
AST_ExpressionList arguments() const
Definition: statement.cpp:303
AST_Statement_OutputAssigment_::functionName
std::string functionName()
Definition: statement.cpp:307
AST_Statement_If_::statementType
virtual StatementType statementType()
Definition: statement.cpp:230
AST_Statement_When_::_else_list
AST_Statement_ElseList _else_list
Definition: statement.hpp:72
AST_Statement_If_::statements
AST_StatementList statements() const
Definition: statement.cpp:224
AST_Statement_When_::comment
AST_Comment comment() const
Definition: statement.cpp:156
AST_Statement_If_::_true_st
AST_StatementList _true_st
Definition: statement.hpp:103
AST_Statement_If_::else_if
AST_Statement_ElseList else_if() const
Definition: statement.cpp:228
AST_Statement_For_::statementType
virtual StatementType statementType()
Definition: statement.cpp:139
AST_Statement_When_::hasElsewhen
bool hasElsewhen()
Definition: statement.cpp:160
AST_Statement_OutputAssigment_::_out_exps
AST_ExpressionList _out_exps
Definition: statement.hpp:144
AST_Statement_For_::statements
AST_StatementList statements() const
Definition: statement.cpp:135
AST_Statement_Else_::AST_Statement_Else_
AST_Statement_Else_(AST_Expression cond, AST_StatementList sts)
Definition: statement.cpp:311
AST_Statement_While_::_cond
AST_Expression _cond
Definition: statement.hpp:116
AST_Statement_While_::AST_Statement_While_
AST_Statement_While_(AST_Expression cond, AST_StatementList)
Definition: statement.cpp:191
AST_Statement_When_::_sts
AST_StatementList _sts
Definition: statement.hpp:71
AST_Statement_If_::_else_list
AST_Statement_ElseList _else_list
Definition: statement.hpp:104
AST_Statement_When_::AST_Statement_When_
AST_Statement_When_(AST_Expression cond, AST_StatementList, AST_Statement_ElseList, AST_Comment)
Definition: statement.cpp:143
AST_Statement_Assign_::statementType
virtual StatementType statementType()
Definition: statement.cpp:78
AST_Statement_While_::statements
AST_StatementList statements() const
Definition: statement.cpp:197
AST_Statement_While_::_sts
AST_StatementList _sts
Definition: statement.hpp:117
AST_Statement_OutputAssigment_::_func
AST_Expression_ComponentReference _func
Definition: statement.hpp:145
AST_Statement_When_::condition
AST_Expression condition() const
Definition: statement.cpp:150
AST_Statement_OutputAssigment_::_function_name
std::string _function_name
Definition: statement.hpp:147
AST_Statement_OutputAssigment_::out_expressions
AST_ExpressionList out_expressions() const
Definition: statement.cpp:299
AST_Statement_Break_
Definition: statement.hpp:51
AST_Statement_Assign_::_lhs
AST_Expression_ComponentReference _lhs
Definition: statement.hpp:87
AST_Statement_Return_::statementType
virtual StatementType statementType()
Definition: statement.cpp:48
AST_Statement_Assign_::exp
AST_Expression exp() const
Definition: statement.cpp:74
AST_Statement_::DEFINE_CLASS_PRINTER
DEFINE_CLASS_PRINTER(AST_Statement)
AST_Statement_When_::_comm
AST_Comment _comm
Definition: statement.hpp:73
AST_Statement_While_
Definition: statement.hpp:107
AST_Statement_Assign_::lhs
AST_Expression_ComponentReference lhs() const
Definition: statement.cpp:76
AST_Node_
Definition: ast_node.hpp:29
AST_Statement_OutputAssigment_::_args
AST_ExpressionList _args
Definition: statement.hpp:146
AST_Statement_When_::_cond
AST_Expression _cond
Definition: statement.hpp:70
AST_Statement_If_::_false_st
AST_StatementList _false_st
Definition: statement.hpp:103
AST_Statement_Assign_::setLHS
void setLHS(AST_Expression_ComponentReference comp_ref)
Definition: statement.cpp:108
AST_Statement_Assign_
Definition: statement.hpp:76
AST_Statement_::statementType
virtual StatementType statementType()=0
AST_Statement_If_::print
string print() const
Definition: statement.cpp:232
AST_Statement_::print
virtual string print() const =0
AST_Statement_Assign_::_exp
AST_Expression _exp
Definition: statement.hpp:88
AST_Statement_While_::print
string print() const
Definition: statement.cpp:199
AST_Statement_Break_::statementType
virtual StatementType statementType()
Definition: statement.cpp:60
AST_Statement_For_::_ind
AST_ForIndexList _ind
Definition: statement.hpp:130
ast_node.hpp
AST_Statement_When_::hasComment
bool hasComment()
Definition: statement.cpp:158
MicroModelica::IR::RANGE::For
@ For
Definition: index.hpp:102
AST_Statement_OutputAssigment_::print
string print() const
Definition: statement.cpp:273
StatementType
StatementType
Definition: ast_types.hpp:191
AST_Statement_OutputAssigment_::statementType
virtual StatementType statementType()
Definition: statement.cpp:305
AST_Statement_When_
Definition: statement.hpp:57
AST_Statement_If_::_cond
AST_Expression _cond
Definition: statement.hpp:102
AST_Statement_While_::condition
AST_Expression condition() const
Definition: statement.cpp:193
AST_Statement_For_::print
string print() const
Definition: statement.cpp:120
AST_Statement_Else_::statements
AST_StatementList statements() const
Definition: statement.cpp:315
AST_Statement_When_::print
string print() const
Definition: statement.cpp:162
AST_Statement_::GET_AS
GET_AS(Statement, While)
ast_types.hpp
AST_Statement_Else_::condition
AST_Expression condition() const
Definition: statement.cpp:313
AST_Statement_If_::else_statements
AST_StatementList else_statements() const
Definition: statement.cpp:226
AST_Statement_Return_::print
string print() const
Definition: statement.cpp:50
AST_Visitor
Definition: ast_util.hpp:224
AST_Statement_If_
Definition: statement.hpp:91
AST_Statement_Assign_::AST_Statement_Assign_
AST_Statement_Assign_(AST_Expression_ComponentReference cr, AST_Expression exp)
Definition: statement.cpp:72
AST_Statement_For_::_sts
AST_StatementList _sts
Definition: statement.hpp:129
MicroModelica::IR::RANGE::If
@ If
Definition: index.hpp:102
AST_Statement_For_::forIndexList
AST_ForIndexList forIndexList() const
Definition: statement.cpp:137
AST_Statement_When_::else_when
AST_Statement_ElseList else_when() const
Definition: statement.cpp:154
AST_Statement_When_::statements
AST_StatementList statements() const
Definition: statement.cpp:152
AST_Statement_If_::AST_Statement_If_
AST_Statement_If_(AST_Expression cond, AST_StatementList true_st, AST_Statement_ElseList, AST_StatementList false_st)
Definition: statement.cpp:216
AST_Statement_For_::AST_Statement_For_
AST_Statement_For_(AST_ForIndexList index, AST_StatementList)
Definition: statement.cpp:118
AST_Statement_Else_::_cond
AST_Expression _cond
Definition: statement.hpp:158
AST_Statement_Break_::print
string print() const
Definition: statement.cpp:62
AST_Statement_OutputAssigment_
Definition: statement.hpp:133
AST_Statement_Else_::_sts
AST_StatementList _sts
Definition: statement.hpp:159
AST_Statement_Else_
Definition: statement.hpp:150
AST_Statement_While_::statementType
virtual StatementType statementType()
Definition: statement.cpp:195
AST_Statement_Return_
Definition: statement.hpp:45
AST_Statement_When_::statementType
virtual StatementType statementType()
Definition: statement.cpp:148