MicroModelicaCCompiler  4.5.3
stored_definition.cpp
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 #include "stored_definition.hpp"
21 
22 #include <stddef.h>
23 #include <iostream>
24 #include <list>
25 
26 #include "class.hpp"
27 #include "imports.hpp"
28 
29 AST_StoredDefinition_::AST_StoredDefinition_(AST_ClassList ml, AST_String within) : _model_list(ml), _within(within)
30 {
31  _imports = new AST_Imports();
32 }
33 
34 CLASSP_PRINTER_IMP(AST_StoredDefinition);
35 
36 AST_ClassList AST_StoredDefinition_::models() const { return _model_list; }
37 
39 
40 ostream &operator<<(ostream &os, const AST_StoredDefinition_ &sd)
41 {
42  AST_ClassListIterator it;
43  AST_ClassList cl = sd.models();
44  if (sd.within() != nullptr) os << "within " << sd.within() << endl;
45  foreach (it, cl) {
46  os << current_element(it);
47  }
48  return os;
49 }
50 
52 {
53  visitor->visit(this);
54  AST_ClassListIterator it;
55  foreach (it, _model_list) {
56  AST_Class x = current_element(it);
57  AST_TypePrefix p = x->prefix();
58  if ((p == CP_FUNCTION) || (p == CP_IMPURE) || (p == CP_PURE)) {
59  x->accept(visitor);
60  }
61  }
62  foreach (it, _model_list) {
63  AST_Class x = current_element(it);
64  AST_TypePrefix p = x->prefix();
65  if (p == CP_MODEL || p == CP_PACKAGE) {
66  x->accept(visitor);
67  }
68  }
69  visitor->leave(this);
70 }
71 
72 bool AST_StoredDefinition_::hasWithin() { return _within != nullptr; }
73 
75 {
76  AST_Imports imp;
77  _imports->apply(this);
78  return _imports->imports();
79 }
operator<<
ostream & operator<<(ostream &os, const AST_StoredDefinition_ &sd)
Definition: stored_definition.cpp:40
AST_StoredDefinition_
Definition: stored_definition.hpp:29
AST_Imports::apply
int apply(AST_Node x)
Definition: imports.cpp:69
AST_StoredDefinition_::imports
AST_StringList imports()
Definition: stored_definition.cpp:74
AST_StoredDefinition_::_within
AST_String _within
Definition: stored_definition.hpp:42
AST_StoredDefinition_::_model_list
AST_ClassList _model_list
Definition: stored_definition.hpp:41
AST_StoredDefinition_::hasWithin
bool hasWithin()
Definition: stored_definition.cpp:72
imports.hpp
CP_IMPURE
@ CP_IMPURE
Definition: ast_types.hpp:223
AST_String
string * AST_String
Definition: ast_types.hpp:46
AST_StoredDefinition_::AST_StoredDefinition_
AST_StoredDefinition_(AST_ClassList ml, AST_String within)
Definition: stored_definition.cpp:29
AST_StoredDefinition_::accept
void accept(AST_Visitor *visitor)
Definition: stored_definition.cpp:51
AST_StoredDefinition_::within
AST_String within() const
Definition: stored_definition.cpp:38
AST_StoredDefinition_::_imports
AST_Imports * _imports
Definition: stored_definition.hpp:43
AST_TypePrefix
int AST_TypePrefix
Definition: ast_types.hpp:50
AST_Imports
Definition: imports.hpp:29
stored_definition.hpp
class.hpp
CP_PURE
@ CP_PURE
Definition: ast_types.hpp:222
CLASSP_PRINTER_IMP
CLASSP_PRINTER_IMP(AST_StoredDefinition)
AST_Visitor::visit
virtual void visit(AST_Class x)=0
CP_PACKAGE
@ CP_PACKAGE
Definition: ast_types.hpp:224
CP_FUNCTION
@ CP_FUNCTION
Definition: ast_types.hpp:225
AST_Visitor
Definition: ast_util.hpp:224
AST_Imports::imports
AST_StringList imports()
Definition: imports.cpp:75
AST_Visitor::leave
virtual void leave(AST_Class x)=0
CP_MODEL
@ CP_MODEL
Definition: ast_types.hpp:215
current_element
#define current_element(it)
Definition: ast_types.hpp:34
AST_StoredDefinition_::models
AST_ClassList models() const
Definition: stored_definition.cpp:36