MicroModelicaCCompiler  4.5.3
reduction_functions.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 MMO_REDUCTION_FUNCTIONS_H
21 #define MMO_REDUCTION_FUNCTIONS_H
22 
23 #include <string>
24 
25 #include <util/symbol_table.hpp>
26 #include <util/util.hpp>
27 #include <util/visitors/convert_cont_red.hpp>
28 #include <util/visitors/convert_disc_red.hpp>
29 #include "helpers.hpp"
30 
31 namespace MicroModelica {
32 namespace IR {
33 
34 template <class T, class C>
35 class ReductionFunctions {
36  public:
37  ReductionFunctions(AST_Expression expression, Util::Variable lhs)
38  : _has_reduction_function(false), _expression(expression), _lhs(lhs){};
39 
41 
42  list<T> code() { return _code; };
43 
44  list<Util::Variable> variables() { return _variables; };
45 
46  AST_Expression apply()
47  {
48  C convert_red;
49  convert_red.setLHS(_lhs);
50  AST_Expression converted_exp = _expression;
51  int operators = convert_red.operators();
52  for (int i = 0; i < operators; i++) {
53  convert_red.setReduction(i);
54  converted_exp = convert_red.apply(converted_exp);
55  _has_reduction_function |= convert_red.hasReduction();
56  insertCode(convert_red.code(), convert_red.variables());
57  }
58  return converted_exp;
59  };
60 
61  protected:
62  void insertCode(list<T> code, list<Util::Variable> variables)
63  {
64  _code.insert(_code.end(), code.begin(), code.end());
65  _variables.insert(_variables.end(), variables.begin(), variables.end());
66  }
67 
69  AST_Expression _expression;
70  list<T> _code;
71  list<Util::Variable> _variables;
73 };
74 
75 } // namespace IR
76 } // namespace MicroModelica
77 
78 #endif /* MMO_REDUCTION_FUNCTIONS_H */
MicroModelica::IR::ReductionFunctions::_variables
list< Util::Variable > _variables
Definition: reduction_functions.hpp:122
MicroModelica::IR::ReductionFunctions::variables
list< Util::Variable > variables()
Definition: reduction_functions.hpp:95
MicroModelica::Util::Variable
Definition: symbol_table.hpp:75
MicroModelica::IR::ReductionFunctions::ReductionFunctions
ReductionFunctions(AST_Expression expression, Util::Variable lhs)
Definition: reduction_functions.hpp:88
symbol_table.hpp
helpers.hpp
MicroModelica::IR::ReductionFunctions::_lhs
Util::Variable _lhs
Definition: reduction_functions.hpp:123
MicroModelica::IR::ReductionFunctions::_expression
AST_Expression _expression
Definition: reduction_functions.hpp:120
MicroModelica::IR::ReductionFunctions::apply
AST_Expression apply()
Definition: reduction_functions.hpp:97
MicroModelica::IR::ReductionFunctions::code
list< T > code()
Definition: reduction_functions.hpp:93
MicroModelica::IR::ReductionFunctions::_code
list< T > _code
Definition: reduction_functions.hpp:121
MicroModelica::IR::ReductionFunctions::insertCode
void insertCode(list< T > code, list< Util::Variable > variables)
Definition: reduction_functions.hpp:113
MicroModelica
Definition: files.cpp:45
MicroModelica::IR::ReductionFunctions::_has_reduction_function
bool _has_reduction_function
Definition: reduction_functions.hpp:119
util.hpp
MicroModelica::IR::ReductionFunctions::hasReductionFunctions
bool hasReductionFunctions()
Definition: reduction_functions.hpp:91