MicroModelicaCCompiler  4.5.3
type.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 #pragma once
21 
22 #include <iostream>
23 #include <list>
24 #include <string>
25 
26 #include <ast/ast_types.hpp>
27 #include <ast/expression.hpp>
28 #include <util/macros.hpp>
29 
31 
33 DEFINE_TYPE(Type_Real);
34 DEFINE_TYPE(Type_Integer);
35 DEFINE_TYPE(Type_Boolean);
36 DEFINE_TYPE(Type_String);
37 DEFINE_TYPE(Type_Array);
38 DEFINE_TYPE(Type_Tupla);
39 DEFINE_TYPE(Type_Function);
41 
42 class Type_ {
43  public:
44  virtual ~Type_() = default;
45  virtual SymbolType getType() = 0;
46  virtual string print() const = 0;
47  friend ostream &operator<<(ostream &os, const Type_ &e);
48  friend ostream &operator<<(ostream &os, const Type &e);
49  friend int operator==(Type_ &e1, Type_ &e2);
50  friend int operator==(Type_ &e1, Type e2);
51  friend int operator!=(Type_ &e1, Type_ &e2);
52  friend int operator!=(Type_ &e1, Type e2);
53  Type_Array getAsArray();
54  Type_Tupla getAsTupla();
55  Type_Function getAsFunction();
56 };
57 
58 class Type_Real_ : public Type_ {
59  public:
60  Type_Real_() = default;
61  ~Type_Real_() override = default;
62  SymbolType getType() override { return SymbolType::TYREAL; };
63  string print() const override;
64 };
65 
66 Type_Real newType_Real();
67 void deleteType_Real(Type_Real m);
68 
69 class Type_Integer_ : public Type_ {
70  public:
71  Type_Integer_() = default;
72  ~Type_Integer_() override = default;
73  SymbolType getType() override { return SymbolType::TYINTEGER; };
74  string print() const override;
75 };
76 
77 Type_Integer newType_Integer();
78 void deleteType_Integer(Type_Integer m);
79 
80 class Type_Boolean_ : public Type_ {
81  public:
82  ~Type_Boolean_() override = default;
83  ;
84  SymbolType getType() override { return SymbolType::TYBOOLEAN; };
85  string print() const override;
86 };
87 
88 class Type_String_ : public Type_ {
89  public:
90  ~Type_String_() override = default;
91  SymbolType getType() override { return SymbolType::TYSTRING; };
92  string print() const override;
93 };
94 
95 Type_String newType_String();
96 void deleteType_String(Type_String m);
97 
98 class Type_Array_ : public Type_ {
99  public:
100  Type_Array_(Type t, AST_Expression dim);
101  ~Type_Array_() override = default;
102  SymbolType getType() override { return SymbolType::TYARRAY; }
103  string print() const override;
104  Type arrayOf();
105  AST_Expression dimension() { return _dim; };
106 
107  private:
108  Type _t;
109  AST_Expression _dim;
110 };
111 
112 class Type_Tupla_ : public Type_ {
113  public:
114  explicit Type_Tupla_(TypeList tyl);
115  ~Type_Tupla_() override = default;
116  string print() const override;
117  TypeList tupla() { return _tyl; };
118  SymbolType getType() override { return SymbolType::TYTUPLA; }
119 
120  private:
121  TypeList _tyl;
122 };
123 
124 class Type_Function_ : public Type_ {
125  public:
126  Type_Function_(Type output, TypeList input);
127  ~Type_Function_() override = default;
128  string print() const override;
129  TypeList input() { return _input; };
130  Type output() { return _output; };
131  SymbolType getType() override { return SymbolType::TYFUNCTION; };
132 
133  private:
134  TypeList _input;
136 };
Type_Tupla_::tupla
TypeList tupla()
Definition: type.hpp:117
Type_Real_::~Type_Real_
~Type_Real_() override=default
SymbolType::TYTUPLA
@ TYTUPLA
SymbolType
SymbolType
Definition: type.hpp:30
Type_Array_::_dim
AST_Expression _dim
Definition: type.hpp:109
DEFINE_TYPE
DEFINE_TYPE(Type)
deleteType_Real
void deleteType_Real(Type_Real m)
Definition: type.cpp:47
SymbolType::TYFUNCTION
@ TYFUNCTION
Type_Array_::arrayOf
Type arrayOf()
Definition: type.cpp:100
macros.hpp
SymbolType::TYREAL
@ TYREAL
Type_Boolean_::print
string print() const override
Definition: type.cpp:60
SymbolType::TYSTRING
@ TYSTRING
Type_Real_::print
string print() const override
Definition: type.cpp:38
Type_Array_::Type_Array_
Type_Array_(Type t, AST_Expression dim)
Definition: type.cpp:98
Type_::print
virtual string print() const =0
newType_Real
Type_Real newType_Real()
Definition: type.cpp:45
Type_Function_::getType
SymbolType getType() override
Definition: type.hpp:131
Type_Tupla_::~Type_Tupla_
~Type_Tupla_() override=default
Type_::getAsFunction
Type_Function getAsFunction()
Definition: type.cpp:106
MicroModelica::IR::EQUATION::Type
Type
Definition: equation.hpp:50
Type_::operator==
friend int operator==(Type_ &e1, Type_ &e2)
Definition: type.cpp:108
Type_::getType
virtual SymbolType getType()=0
Type_Tupla_::print
string print() const override
Definition: type.cpp:143
Type_Function_::~Type_Function_
~Type_Function_() override=default
Type_::getAsArray
Type_Array getAsArray()
Definition: type.cpp:102
Type_Tupla_::getType
SymbolType getType() override
Definition: type.hpp:118
newType_Integer
Type_Integer newType_Integer()
Definition: type.cpp:56
Type_Array_::_t
Type _t
Definition: type.hpp:105
Type_Function_::_output
Type _output
Definition: type.hpp:135
Type_Tupla_
Definition: type.hpp:112
Type_Real_
Definition: type.hpp:58
Type_Array_::print
string print() const override
Definition: type.cpp:78
Type_Tupla_::_tyl
TypeList _tyl
Definition: type.hpp:121
Type_Array_::getType
SymbolType getType() override
Definition: type.hpp:102
Type_String_::print
string print() const override
Definition: type.cpp:67
SymbolType::TYINTEGER
@ TYINTEGER
Type_Function_::_input
TypeList _input
Definition: type.hpp:131
Type_Real_::getType
SymbolType getType() override
Definition: type.hpp:62
newType_String
Type_String newType_String()
Definition: type.cpp:74
DEFINE_LIST
DEFINE_LIST(Type)
Type_::operator!=
friend int operator!=(Type_ &e1, Type_ &e2)
Definition: type.cpp:137
Type_Real_::Type_Real_
Type_Real_()=default
Type_Array_
Definition: type.hpp:98
Type_Tupla_::Type_Tupla_
Type_Tupla_(TypeList tyl)
Definition: type.cpp:141
Type_::operator<<
friend ostream & operator<<(ostream &os, const Type_ &e)
Definition: type.cpp:26
Type_
Definition: type.hpp:42
Type_Function_::Type_Function_
Type_Function_(Type output, TypeList input)
Definition: type.cpp:159
SymbolType::TYBOOLEAN
@ TYBOOLEAN
Type_String_
Definition: type.hpp:88
Type_Integer_::getType
SymbolType getType() override
Definition: type.hpp:73
deleteType_Integer
void deleteType_Integer(Type_Integer m)
Definition: type.cpp:58
Type_Integer_::print
string print() const override
Definition: type.cpp:49
Type_::getAsTupla
Type_Tupla getAsTupla()
Definition: type.cpp:104
ast_types.hpp
Type_Integer_::Type_Integer_
Type_Integer_()=default
Type_String_::getType
SymbolType getType() override
Definition: type.hpp:91
Type_::~Type_
virtual ~Type_()=default
Type_Function_::output
Type output()
Definition: type.hpp:130
Type_Function_::input
TypeList input()
Definition: type.hpp:129
Type_String_::~Type_String_
~Type_String_() override=default
SymbolType::TYARRAY
@ TYARRAY
deleteType_String
void deleteType_String(Type_String m)
Definition: type.cpp:76
Type_Function_
Definition: type.hpp:124
Type_Array_::~Type_Array_
~Type_Array_() override=default
Type_Integer_::~Type_Integer_
~Type_Integer_() override=default
Type_Function_::print
string print() const override
Definition: type.cpp:161
Type_Integer_
Definition: type.hpp:69
Type_Array_::dimension
AST_Expression dimension()
Definition: type.hpp:105
Type_Boolean_::~Type_Boolean_
~Type_Boolean_() override=default
expression.hpp
Type_Boolean_
Definition: type.hpp:80
Type_Boolean_::getType
SymbolType getType() override
Definition: type.hpp:84