From aa48ffdd04cfa3ba2154afa3e76acadad579547a Mon Sep 17 00:00:00 2001 From: "joaquin.f.fernandez" Date: Mon, 5 Aug 2024 10:49:53 -0300 Subject: [PATCH] [iss-78] Squashed commit of the following: commit 1de50dea79814f149d9aa0348a670eb63fd0e33c Author: joaquin.f.fernandez Date: Fri Aug 2 14:56:28 2024 -0300 Updated test files. commit 8e273f8bb6c5ee3237124f3c02408077d3028d65 Author: joaquin.f.fernandez Date: Fri Aug 2 14:55:04 2024 -0300 Updated utils folder. commit 99ec8df8c7624b05c2573a620fc5b70a6d04b89c Author: joaquin.f.fernandez Date: Fri Aug 2 14:54:38 2024 -0300 Updated test folder. commit 47a54ae5377dc121e8818ef5864b232ba9adf56f Author: joaquin.f.fernandez Date: Fri Aug 2 14:54:05 2024 -0300 Updated parser folder. commit a18c598ae95f198383d1a1541bb46d498435f726 Author: joaquin.f.fernandez Date: Fri Aug 2 14:53:46 2024 -0300 Updated mmo folder. commit 24e3972d39a249c95da9fc6042db88e0093c258e Author: joaquin.f.fernandez Date: Fri Aug 2 14:53:27 2024 -0300 Updated flatter folder. commit 0c2e2e21d281ff0285b2ba15d48760ad8b586ef3 Author: joaquin.f.fernandez Date: Fri Aug 2 14:53:05 2024 -0300 Updated causalize folder. commit 194cb1ab5d86eab4d965c1d24d90c16725897a13 Author: joaquin.f.fernandez Date: Fri Aug 2 14:52:39 2024 -0300 Updated ast folder. commit 8f8bfec176c3a5671c0fced6db8c7ed86436830c Author: joaquin.f.fernandez Date: Fri Aug 2 14:51:48 2024 -0300 Update antialias folder. commit 9229adbf10a37cb8b55c288159002f16eb138878 Author: joaquin.f.fernandez Date: Fri Aug 2 13:46:15 2024 -0300 Updated util folder. commit cdc8383b61dfb882b2ad98c95f5f3e5f618b8419 Author: joaquin.f.fernandez Date: Fri Aug 2 13:45:15 2024 -0300 Updated parser folder. commit e56597270553e4bb45ce5fd22547907ff0e0053a Author: joaquin.f.fernandez Date: Fri Aug 2 13:44:47 2024 -0300 Updated mmo folder. commit 04544a56d9399e2bfc98a03f5d14827423c2bb13 Author: joaquin.f.fernandez Date: Fri Aug 2 13:44:15 2024 -0300 Updated flatter folder. commit 65d96f96b7c0984ab6f1c189221b28bcf7ffa0ea Author: joaquin.f.fernandez Date: Fri Aug 2 13:43:21 2024 -0300 Updated causalization folder. commit c6fc7e086450ddc4fadc638e9d42a89a2f3475f7 Author: joaquin.f.fernandez Date: Fri Aug 2 13:40:56 2024 -0300 Updated AST folder. --- antialias/main.cpp | 13 +- antialias/remove_alias.cpp | 14 +- .../{remove_alias.h => remove_alias.hpp} | 2 +- ast/{ast_types.h => ast_types.hpp} | 0 ast/class.cpp | 8 +- ast/{class.h => class.hpp} | 8 +- ast/element.cpp | 4 +- ast/{element.h => element.hpp} | 2 +- ast/equation.cpp | 2 +- ast/{equation.h => equation.hpp} | 2 +- ast/expression.cpp | 31 +- ast/{expression.h => expression.hpp} | 2 +- ast/modification.cpp | 16 +- ast/{modification.h => modification.hpp} | 2 +- ast/{queries.h => queries.hpp} | 6 +- ast/statement.cpp | 2 +- ast/{statement.h => statement.hpp} | 2 +- .../for_unrolling/for_index_iterator.cpp | 10 +- ...ndex_iterator.h => for_index_iterator.hpp} | 6 +- .../for_unrolling/process_for_equations.cpp | 10 +- ..._equations.h => process_for_equations.hpp} | 2 +- .../sbg_implementation/generate_sbg_input.cpp | 14 +- ...ate_sbg_input.h => generate_sbg_input.hpp} | 2 +- causalize/sbg_implementation/main.cpp | 14 +- flatter/class_finder.cpp | 12 +- flatter/{class_finder.h => class_finder.hpp} | 14 +- flatter/connectors.cpp | 485 +++++++++--------- flatter/{connectors.h => connectors.hpp} | 24 +- flatter/flatter.cpp | 8 +- flatter/{flatter.h => flatter.hpp} | 22 +- flatter/main.cpp | 39 +- flatter/{mmo_graph.h => mmo_graph.hpp} | 4 +- flatter/remove_composition.cpp | 2 +- ...e_composition.h => remove_composition.hpp} | 16 +- flatter/test/models_test.cpp | 2 +- mmo/main.cpp | 10 +- mmo/mmo_class.cpp | 21 +- mmo/{mmo_class.h => mmo_class.hpp} | 6 +- mmo/mmo_tree.cpp | 2 +- mmo/{mmo_tree.h => mmo_tree.hpp} | 8 +- parser/class.cpp | 4 +- parser/{class.h => class.hpp} | 8 +- parser/{class_def.h => class_def.hpp} | 2 +- parser/equation.cpp | 4 +- parser/{equation.h => equation.hpp} | 6 +- parser/{equation_def.h => equation_def.hpp} | 0 parser/expression.cpp | 4 +- parser/{expression.h => expression.hpp} | 6 +- .../{expression_def.h => expression_def.hpp} | 0 parser/ident.cpp | 4 +- parser/{ident.h => ident.hpp} | 2 +- parser/{ident_def.h => ident_def.hpp} | 0 parser/main.cpp | 38 +- parser/modification.cpp | 4 +- parser/{modification.h => modification.hpp} | 8 +- ...odification_def.h => modification_def.hpp} | 0 parser/parser.cpp | 8 +- parser/{parser.h => parser.hpp} | 2 +- parser/{skipper.h => skipper.hpp} | 0 parser/statement.cpp | 4 +- parser/{statement.h => statement.hpp} | 6 +- parser/{statement_def.h => statement_def.hpp} | 0 test/causalize/apply_tarjan_test.cpp | 4 +- .../causalize/causalization_strategy_test.cpp | 350 ++++++------- .../process_for_equations_test.cpp | 12 +- test/causalize/performance_test.cpp | 22 +- test/parse/print_parse.cpp | 13 +- test/util/EvalExpTest.cpp | 6 +- util/ast_visitors/all_expressions.cpp | 6 +- ...{all_expressions.h => all_expressions.hpp} | 4 +- util/ast_visitors/constant_expression.cpp | 10 +- ...t_expression.h => constant_expression.hpp} | 4 +- util/ast_visitors/contains_expression.cpp | 4 +- ...s_expression.h => contains_expression.hpp} | 4 +- .../contains_expression_flatter.cpp | 10 +- ...tter.h => contains_expression_flatter.hpp} | 2 +- util/ast_visitors/contains_unknown.cpp | 110 ++-- ...ontains_unknown.h => contains_unknown.hpp} | 6 +- util/ast_visitors/contains_vector.cpp | 452 ++++++++-------- ...{contains_vector.h => contains_vector.hpp} | 8 +- util/ast_visitors/dot_expression.cpp | 16 +- .../{dot_expression.h => dot_expression.hpp} | 9 +- ...quation_visitor.h => equation_visitor.hpp} | 4 +- util/ast_visitors/eval_expression.cpp | 132 ++--- ...{eval_expression.h => eval_expression.hpp} | 5 +- util/ast_visitors/eval_expression_flatter.cpp | 255 +++++---- ..._flatter.h => eval_expression_flatter.hpp} | 6 +- util/ast_visitors/ginac_interface.cpp | 10 +- ...{ginac_interface.h => ginac_interface.hpp} | 15 +- util/ast_visitors/mark_connector.cpp | 4 +- .../{mark_connector.h => mark_connector.hpp} | 6 +- util/ast_visitors/matching_exps.cpp | 23 +- .../{matching_exps.h => matching_exps.hpp} | 2 +- util/ast_visitors/partial_eval_expression.cpp | 12 +- ...pression.h => partial_eval_expression.hpp} | 6 +- util/ast_visitors/pwl_map_values.cpp | 8 +- .../{pwl_map_values.h => pwl_map_values.hpp} | 2 +- util/ast_visitors/replace_equation.cpp | 4 +- ...eplace_equation.h => replace_equation.hpp} | 4 +- util/ast_visitors/replace_expression.cpp | 4 +- ...ce_expression.h => replace_expression.hpp} | 2 +- util/ast_visitors/replace_index.cpp | 336 ++++++------ .../{replace_index.h => replace_index.hpp} | 10 +- util/ast_visitors/replace_statement.cpp | 4 +- ...lace_statement.h => replace_statement.hpp} | 6 +- util/ast_visitors/splitfor_visitor.cpp | 4 +- ...plitfor_visitor.h => splitfor_visitor.hpp} | 3 +- util/ast_visitors/state_variables_finder.cpp | 8 +- ...es_finder.h => state_variables_finder.hpp} | 7 +- ...tement_visitor.h => statement_visitor.hpp} | 4 +- .../to_micro/convert_to_micro.cpp | 8 +- ...onvert_to_micro.h => convert_to_micro.hpp} | 8 +- .../to_micro/convert_to_micro_expression.cpp | 15 +- ...sion.h => convert_to_micro_expression.hpp} | 6 +- .../to_micro/convert_to_micro_statement.cpp | 7 +- ...ement.h => convert_to_micro_statement.hpp} | 6 +- util/debug.cpp | 8 +- util/{debug.h => debug.hpp} | 0 util/derivate.cpp | 4 +- util/{derivate.h => derivate.hpp} | 4 +- util/derivate_equality.cpp | 10 +- ...ivate_equality.h => derivate_equality.hpp} | 6 +- util/logger.cpp | 8 +- util/{logger.h => logger.hpp} | 0 util/solve/solve.cpp | 22 +- util/solve/{solve.h => solve.hpp} | 6 +- util/table.cpp | 25 +- util/{table.h => table.hpp} | 6 +- util/type.cpp | 4 +- util/{type.h => type.hpp} | 4 +- 130 files changed, 1547 insertions(+), 1507 deletions(-) rename antialias/{remove_alias.h => remove_alias.hpp} (97%) rename ast/{ast_types.h => ast_types.hpp} (100%) rename ast/{class.h => class.hpp} (97%) rename ast/{element.h => element.hpp} (98%) rename ast/{equation.h => equation.hpp} (99%) rename ast/{expression.h => expression.hpp} (99%) rename ast/{modification.h => modification.hpp} (99%) rename ast/{queries.h => queries.hpp} (98%) rename ast/{statement.h => statement.hpp} (99%) rename causalize/common/for_unrolling/{for_index_iterator.h => for_index_iterator.hpp} (95%) rename causalize/common/for_unrolling/{process_for_equations.h => process_for_equations.hpp} (97%) rename causalize/sbg_implementation/{generate_sbg_input.h => generate_sbg_input.hpp} (98%) rename flatter/{class_finder.h => class_finder.hpp} (90%) rename flatter/{connectors.h => connectors.hpp} (93%) rename flatter/{flatter.h => flatter.hpp} (74%) rename flatter/{mmo_graph.h => mmo_graph.hpp} (97%) rename flatter/{remove_composition.h => remove_composition.hpp} (83%) rename mmo/{mmo_class.h => mmo_class.hpp} (96%) rename mmo/{mmo_tree.h => mmo_tree.hpp} (92%) rename parser/{class.h => class.hpp} (96%) rename parser/{class_def.h => class_def.hpp} (99%) rename parser/{equation.h => equation.hpp} (95%) rename parser/{equation_def.h => equation_def.hpp} (100%) rename parser/{expression.h => expression.hpp} (97%) rename parser/{expression_def.h => expression_def.hpp} (100%) rename parser/{ident.h => ident.hpp} (97%) rename parser/{ident_def.h => ident_def.hpp} (100%) rename parser/{modification.h => modification.hpp} (96%) rename parser/{modification_def.h => modification_def.hpp} (100%) rename parser/{parser.h => parser.hpp} (97%) rename parser/{skipper.h => skipper.hpp} (100%) rename parser/{statement.h => statement.hpp} (95%) rename parser/{statement_def.h => statement_def.hpp} (100%) rename util/ast_visitors/{all_expressions.h => all_expressions.hpp} (97%) rename util/ast_visitors/{constant_expression.h => constant_expression.hpp} (97%) rename util/ast_visitors/{contains_expression.h => contains_expression.hpp} (98%) rename util/ast_visitors/{contains_expression_flatter.h => contains_expression_flatter.hpp} (98%) rename util/ast_visitors/{contains_unknown.h => contains_unknown.hpp} (95%) rename util/ast_visitors/{contains_vector.h => contains_vector.hpp} (96%) rename util/ast_visitors/{dot_expression.h => dot_expression.hpp} (94%) rename util/ast_visitors/{equation_visitor.h => equation_visitor.hpp} (99%) rename util/ast_visitors/{eval_expression.h => eval_expression.hpp} (97%) rename util/ast_visitors/{eval_expression_flatter.h => eval_expression_flatter.hpp} (97%) rename util/ast_visitors/{ginac_interface.h => ginac_interface.hpp} (98%) rename util/ast_visitors/{mark_connector.h => mark_connector.hpp} (95%) rename util/ast_visitors/{matching_exps.h => matching_exps.hpp} (98%) rename util/ast_visitors/{partial_eval_expression.h => partial_eval_expression.hpp} (97%) rename util/ast_visitors/{pwl_map_values.h => pwl_map_values.hpp} (98%) rename util/ast_visitors/{replace_equation.h => replace_equation.hpp} (94%) rename util/ast_visitors/{replace_expression.h => replace_expression.hpp} (98%) rename util/ast_visitors/{replace_index.h => replace_index.hpp} (97%) rename util/ast_visitors/{replace_statement.h => replace_statement.hpp} (94%) rename util/ast_visitors/{splitfor_visitor.h => splitfor_visitor.hpp} (97%) rename util/ast_visitors/{state_variables_finder.h => state_variables_finder.hpp} (95%) rename util/ast_visitors/{statement_visitor.h => statement_visitor.hpp} (99%) rename util/ast_visitors/to_micro/{convert_to_micro.h => convert_to_micro.hpp} (95%) rename util/ast_visitors/to_micro/{convert_to_micro_expression.h => convert_to_micro_expression.hpp} (97%) rename util/ast_visitors/to_micro/{convert_to_micro_statement.h => convert_to_micro_statement.hpp} (96%) rename util/{debug.h => debug.hpp} (100%) rename util/{derivate.h => derivate.hpp} (94%) rename util/{derivate_equality.h => derivate_equality.hpp} (92%) rename util/{logger.h => logger.hpp} (100%) rename util/solve/{solve.h => solve.hpp} (94%) rename util/{table.h => table.hpp} (97%) rename util/{type.h => type.hpp} (98%) diff --git a/antialias/main.cpp b/antialias/main.cpp index 80efb23..76eaeaf 100644 --- a/antialias/main.cpp +++ b/antialias/main.cpp @@ -17,13 +17,14 @@ ******************************************************************************/ -#include -#include -#include -#include -#include #include -#include +#include +#include + +#include +#include +#include +#include int main(int argc, char** argv) { diff --git a/antialias/remove_alias.cpp b/antialias/remove_alias.cpp index 5db6949..e1f035f 100644 --- a/antialias/remove_alias.cpp +++ b/antialias/remove_alias.cpp @@ -17,14 +17,14 @@ ******************************************************************************/ -#include -#include -#include +#include +#include +#include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/antialias/remove_alias.h b/antialias/remove_alias.hpp similarity index 97% rename from antialias/remove_alias.h rename to antialias/remove_alias.hpp index 6968293..debffe9 100644 --- a/antialias/remove_alias.h +++ b/antialias/remove_alias.hpp @@ -19,7 +19,7 @@ #ifndef REMOVE_ALIAS_H #define REMOVE_ALIAS_H -#include +#include namespace Modelica { class RemoveAlias { diff --git a/ast/ast_types.h b/ast/ast_types.hpp similarity index 100% rename from ast/ast_types.h rename to ast/ast_types.hpp diff --git a/ast/class.cpp b/ast/class.cpp index d9779e7..42dda76 100644 --- a/ast/class.cpp +++ b/ast/class.cpp @@ -17,15 +17,15 @@ ******************************************************************************/ -#include -#include +#include +#include #include #include #if defined BOOST_VERSION && BOOST_VERSION > 105600 #include #endif #include -#include +#include namespace Modelica { namespace AST { @@ -161,7 +161,7 @@ std::ostream& operator<<(std::ostream& out, const EnumClass& c) out << c.name() << " = enumeration ("; out << c.enum_spec(); out << ")"; - + return out; } member_imp(DerClass, bool, final); diff --git a/ast/class.h b/ast/class.hpp similarity index 97% rename from ast/class.h rename to ast/class.hpp index 0d07868..fe75a4c 100644 --- a/ast/class.h +++ b/ast/class.hpp @@ -19,10 +19,10 @@ #ifndef AST_CLASS #define AST_CLASS -#include -#include -#include -#include +#include +#include +#include +#include namespace Modelica { namespace AST { diff --git a/ast/element.cpp b/ast/element.cpp index ed2ac8c..59c41c4 100644 --- a/ast/element.cpp +++ b/ast/element.cpp @@ -17,8 +17,8 @@ ******************************************************************************/ -#include -#include +#include +#include #include #include diff --git a/ast/element.h b/ast/element.hpp similarity index 98% rename from ast/element.h rename to ast/element.hpp index 826d4c2..84fa04a 100644 --- a/ast/element.h +++ b/ast/element.hpp @@ -19,7 +19,7 @@ #ifndef AST_ELEMENT #define AST_ELEMENT -#include +#include namespace Modelica { namespace AST { diff --git a/ast/equation.cpp b/ast/equation.cpp index ba04562..a7d3e3e 100644 --- a/ast/equation.cpp +++ b/ast/equation.cpp @@ -17,7 +17,7 @@ ******************************************************************************/ -#include +#include namespace Modelica { namespace AST { diff --git a/ast/equation.h b/ast/equation.hpp similarity index 99% rename from ast/equation.h rename to ast/equation.hpp index 4eeea25..365e5af 100644 --- a/ast/equation.h +++ b/ast/equation.hpp @@ -19,7 +19,7 @@ #ifndef AST_EQUATION #define AST_EQUATION -#include +#include namespace Modelica { namespace AST { diff --git a/ast/expression.cpp b/ast/expression.cpp index 50e795f..0ee2d84 100644 --- a/ast/expression.cpp +++ b/ast/expression.cpp @@ -22,8 +22,8 @@ #include #include -#include -#include +#include +#include long depth; namespace Modelica { @@ -51,20 +51,20 @@ std::ostream& operator<<(std::ostream& out, const SubAll& s) order_by_imp(SubAll); // AddAll -AddAll::AddAll(RefTuple a) : arr_(a){} +AddAll::AddAll(RefTuple a) : arr_(a) {} member_imp(AddAll, RefTuple, arr); -bool AddAll::operator==(const AddAll &other) const {return (other.arr() == arr());} -std::ostream& operator<<(std::ostream& out, const AddAll &aa){ +bool AddAll::operator==(const AddAll& other) const { return (other.arr() == arr()); } +std::ostream& operator<<(std::ostream& out, const AddAll& aa) +{ RefTuple rt = aa.arr(); ExpList inds = get<1>(rt); out << "sum(" << get<0>(rt) << "["; ExpList::iterator iti = inds.begin(); - for(; std::next(iti) != inds.end(); ++iti) - out << *iti << ", "; + for (; std::next(iti) != inds.end(); ++iti) out << *iti << ", "; out << *iti << "])"; return out; @@ -198,8 +198,7 @@ bool Indexes::operator==(const Indexes& other) const { return other.indexes() == order_by_imp(Indexes); // ForExp -ForExp::ForExp(Expression e, Indexes ind) - : indices_(ind), exp_(e){}; +ForExp::ForExp(Expression e, Indexes ind) : indices_(ind), exp_(e){}; std::ostream& operator<<(std::ostream& out, const ForExp& n) // output { out << n.exp() << " for " << n.indices(); @@ -223,8 +222,7 @@ member_imp(Named, Name, name); order_by_imp(Named); // UnaryOp -UnaryOp::UnaryOp(Expression e, UnaryOpType op) - : exp_(e), op_(op){}; +UnaryOp::UnaryOp(Expression e, UnaryOpType op) : exp_(e), op_(op){}; std::ostream& operator<<(std::ostream& out, const UnaryOp& n) // output { if (n.op() == Minus) @@ -236,7 +234,7 @@ std::ostream& operator<<(std::ostream& out, const UnaryOp& n) // output return out; } bool UnaryOp::operator==(const UnaryOp& other) const { return other.exp() == exp() && other.op() == op(); } -member_imp(UnaryOp, Expression, exp); +member_imp(UnaryOp, Expression, exp); member_imp(UnaryOp, UnaryOpType, op); order_by_imp(UnaryOp); @@ -375,12 +373,10 @@ std::ostream& operator<<(std::ostream& out, const Brace& c) // output return out; } bool Brace::operator==(const Brace& other) const { return other.args() == args(); } -member_imp(Brace, ExpList, args) -order_by_imp(Brace); +member_imp(Brace, ExpList, args) order_by_imp(Brace); // Bracket -Bracket::Bracket(ExpListList args) - : args_(args){}; +Bracket::Bracket(ExpListList args) : args_(args){}; std::ostream& operator<<(std::ostream& out, const Bracket& c) // output { out << "["; @@ -399,8 +395,7 @@ std::ostream& operator<<(std::ostream& out, const Bracket& c) // output return out; } bool Bracket::operator==(const Bracket& other) const { return other.args() == args(); } -member_imp(Bracket, ExpListList, args) -order_by_imp(Bracket); +member_imp(Bracket, ExpListList, args) order_by_imp(Bracket); Boolean True(TRUE); Boolean False(FALSE); diff --git a/ast/expression.h b/ast/expression.hpp similarity index 99% rename from ast/expression.h rename to ast/expression.hpp index 68b2fad..6bfa878 100644 --- a/ast/expression.h +++ b/ast/expression.hpp @@ -19,7 +19,7 @@ #ifndef AST_EXPRESSION #define AST_EXPRESSION -#include +#include #include #include #include diff --git a/ast/modification.cpp b/ast/modification.cpp index 9498827..eab551b 100644 --- a/ast/modification.cpp +++ b/ast/modification.cpp @@ -17,7 +17,7 @@ ******************************************************************************/ -#include +#include #include namespace Modelica { @@ -125,7 +125,7 @@ std::ostream& operator<<(std::ostream& out, const ShortClass& c) // output } } - if(c.enum_spec()) out << c.enum_spec().get(); + if (c.enum_spec()) out << c.enum_spec().get(); return out; } @@ -222,8 +222,7 @@ ShortClass::ShortClass(ClassPrefixes cp, Name n, TypePrefixes tp, Name der, Opti } enum_spec_ = Option(); }; -ShortClass::ShortClass(ClassPrefixes cp, Name n, EnumSpec es, Comment comm) : - prefixes_(cp), name_(n), enum_spec_(es), comment_(comm){} +ShortClass::ShortClass(ClassPrefixes cp, Name n, EnumSpec es, Comment comm) : prefixes_(cp), name_(n), enum_spec_(es), comment_(comm) {} bool ShortClass::operator==(const ShortClass& other) const { // TODO @@ -272,17 +271,20 @@ std::ostream& operator<<(std::ostream& out, const Comment& c) member_imp(Enum, Name, name); member_imp(Enum, Comment, comment); -std::ostream& operator<<(std::ostream &out, const Enum &e){ +std::ostream& operator<<(std::ostream& out, const Enum& e) +{ out << e.name() << " " << e.comment(); return out; } EnumSpec::EnumSpec(EnumList el) : list_(el){}; member_imp(EnumSpec, EnumList, list); -std::ostream& operator<<(std::ostream &out, const EnumSpec &es){ +std::ostream& operator<<(std::ostream& out, const EnumSpec& es) +{ int i = 0, l = es.list().size(); - foreach_(Enum e, es.list()){ + foreach_(Enum e, es.list()) + { out << e; if (++i < l) out << ", "; } diff --git a/ast/modification.h b/ast/modification.hpp similarity index 99% rename from ast/modification.h rename to ast/modification.hpp index 531e19d..3407ea0 100644 --- a/ast/modification.h +++ b/ast/modification.hpp @@ -19,7 +19,7 @@ #ifndef AST_MODIFICATION #define AST_MODIFICATION -#include +#include namespace Modelica { namespace AST { diff --git a/ast/queries.h b/ast/queries.hpp similarity index 98% rename from ast/queries.h rename to ast/queries.hpp index 01b02bb..5aba051 100644 --- a/ast/queries.h +++ b/ast/queries.hpp @@ -20,9 +20,9 @@ #ifndef QUERIES_H #define QUERIES_H -#include -#include -#include +#include +#include +#include #include namespace Modelica { diff --git a/ast/statement.cpp b/ast/statement.cpp index f7f52f1..ad3bb70 100644 --- a/ast/statement.cpp +++ b/ast/statement.cpp @@ -17,7 +17,7 @@ ******************************************************************************/ -#include +#include namespace Modelica { namespace AST { diff --git a/ast/statement.h b/ast/statement.hpp similarity index 99% rename from ast/statement.h rename to ast/statement.hpp index 8eabd48..604c8ba 100644 --- a/ast/statement.h +++ b/ast/statement.hpp @@ -19,7 +19,7 @@ #ifndef AST_STATEMENT #define AST_STATEMENT -#include +#include namespace Modelica { namespace AST { diff --git a/causalize/common/for_unrolling/for_index_iterator.cpp b/causalize/common/for_unrolling/for_index_iterator.cpp index 1fd9ea7..a7a68d5 100644 --- a/causalize/common/for_unrolling/for_index_iterator.cpp +++ b/causalize/common/for_unrolling/for_index_iterator.cpp @@ -17,11 +17,11 @@ ******************************************************************************/ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace Causalize { diff --git a/causalize/common/for_unrolling/for_index_iterator.h b/causalize/common/for_unrolling/for_index_iterator.hpp similarity index 95% rename from causalize/common/for_unrolling/for_index_iterator.h rename to causalize/common/for_unrolling/for_index_iterator.hpp index d6abdd7..4409e1c 100644 --- a/causalize/common/for_unrolling/for_index_iterator.h +++ b/causalize/common/for_unrolling/for_index_iterator.hpp @@ -17,9 +17,9 @@ ******************************************************************************/ -#include -#include -#include +#include +#include +#include namespace Causalize { class ForIndexIterator { diff --git a/causalize/common/for_unrolling/process_for_equations.cpp b/causalize/common/for_unrolling/process_for_equations.cpp index 21d80c7..013776a 100644 --- a/causalize/common/for_unrolling/process_for_equations.cpp +++ b/causalize/common/for_unrolling/process_for_equations.cpp @@ -21,12 +21,12 @@ #include #include -#include -#include -#include +#include +#include +#include -#include "process_for_equations.h" -#include "for_index_iterator.h" +#include "process_for_equations.hpp" +#include "for_index_iterator.hpp" namespace Causalize { diff --git a/causalize/common/for_unrolling/process_for_equations.h b/causalize/common/for_unrolling/process_for_equations.hpp similarity index 97% rename from causalize/common/for_unrolling/process_for_equations.h rename to causalize/common/for_unrolling/process_for_equations.hpp index ad7d950..ba28104 100644 --- a/causalize/common/for_unrolling/process_for_equations.h +++ b/causalize/common/for_unrolling/process_for_equations.hpp @@ -17,7 +17,7 @@ ******************************************************************************/ -#include +#include /** * Performs a loop unrolling over the for-equations diff --git a/causalize/sbg_implementation/generate_sbg_input.cpp b/causalize/sbg_implementation/generate_sbg_input.cpp index caeb7c4..6ad5ea2 100644 --- a/causalize/sbg_implementation/generate_sbg_input.cpp +++ b/causalize/sbg_implementation/generate_sbg_input.cpp @@ -20,13 +20,13 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include using namespace Modelica; diff --git a/causalize/sbg_implementation/generate_sbg_input.h b/causalize/sbg_implementation/generate_sbg_input.hpp similarity index 98% rename from causalize/sbg_implementation/generate_sbg_input.h rename to causalize/sbg_implementation/generate_sbg_input.hpp index 44a3c92..e8cc29c 100644 --- a/causalize/sbg_implementation/generate_sbg_input.h +++ b/causalize/sbg_implementation/generate_sbg_input.hpp @@ -20,7 +20,7 @@ #include #include -#include +#include namespace Causalize { diff --git a/causalize/sbg_implementation/main.cpp b/causalize/sbg_implementation/main.cpp index fc120f2..2c714da 100644 --- a/causalize/sbg_implementation/main.cpp +++ b/causalize/sbg_implementation/main.cpp @@ -20,12 +20,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include using namespace std; using namespace Modelica; @@ -46,7 +46,7 @@ void usage() void version() { cout << "Modelica C Compiler 2.0" << endl; - cout << "License GPLv3+: GNU GPL version 3 or later " << endl; + cout << "License GPLv3+: GNU GPL version 3 or later " << endl; cout << "This is free software: you are free to change and redistribute it." << endl; cout << "There is NO WARRANTY, to the extent permitted by law." << endl; } diff --git a/flatter/class_finder.cpp b/flatter/class_finder.cpp index 18c7754..3c2031f 100644 --- a/flatter/class_finder.cpp +++ b/flatter/class_finder.cpp @@ -18,11 +18,11 @@ ******************************************************************************/ -#include +#include #include #include -#include -#include +#include +#include using namespace std; using namespace Modelica; @@ -64,7 +64,7 @@ void ClassFinder::expand(MMO_Class &up, MMO_Class &down) if (v.indices()) indexes += v.indices().get(); if (indexes.size() > 0) v.set_indices(indexes); v.set_prefixes(v.prefixes() + get<0>(td)); - //LOG << "v2: " << v << "\n"; + // LOG << "v2: " << v << "\n"; if (is(t_final)) v.set_type("String"); if (is(t_final)) v.set_type("Integer"); @@ -110,7 +110,7 @@ void ClassFinder::ExpandAll(MMO_Class &up) } } -#define newMMO(NEW, OLD) \ +#define newMMO(NEW, OLD) \ MMO_Class *NEW = new MMO_Class(); \ *(NEW) = (OLD); @@ -366,7 +366,7 @@ void ClassFinder::applyArgument(MMO_Class &contex, MMO_Class &target, Argument m v.set_indices(OptIndices); v.set_prefixes(preType); v.set_type(comp.type()); - //LOG << "v1: " << v << "\n"; + // LOG << "v1: " << v << "\n"; target.syms_ref().insert(comp.declaration().name(), v); } else diff --git a/flatter/class_finder.h b/flatter/class_finder.hpp similarity index 90% rename from flatter/class_finder.h rename to flatter/class_finder.hpp index 809a8cf..1151ddc 100644 --- a/flatter/class_finder.h +++ b/flatter/class_finder.hpp @@ -22,13 +22,13 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include using namespace Modelica; using namespace Modelica::AST; diff --git a/flatter/connectors.cpp b/flatter/connectors.cpp index 9cd8ffe..857ca0c 100644 --- a/flatter/connectors.cpp +++ b/flatter/connectors.cpp @@ -15,12 +15,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include using namespace std; using namespace Modelica; @@ -31,9 +31,7 @@ using namespace SBG; member_imp(Connectors, MMO_Class, mmoclass); -member_imp(Connectors, SBGraph, G) -member_imp(Connectors, int, maxdim) -member_imp(Connectors, vector, vCount); +member_imp(Connectors, SBGraph, G) member_imp(Connectors, int, maxdim) member_imp(Connectors, vector, vCount); member_imp(Connectors, vector, eCount); member_imp(Connectors, int, ECount); member_imp(Connectors, PWLMap, ccG); @@ -52,19 +50,18 @@ member_imp(Connectors, VarsDimsTable, varsDims); Connectors::Connectors(MMO_Class &c) : mmoclass_(c), ECount_(0), maxdim_(1) {} // Determine if variable is a flow variable -bool Connectors::isFlowVar(Name v) +bool Connectors::isFlowVar(Name v) { - if (v[0] == '-') - v = v.substr(1, v.length() - 1); + if (v[0] == '-') v = v.substr(1, v.length() - 1); Option vi = mmoclass_.syms()[v]; if (vi) { TypePrefixes tps = (*vi).prefixes_; - foreach_ (Option tp, tps) { + foreach_(Option tp, tps) + { if (tp) { - if (*tp == flow) - return true; + if (*tp == flow) return true; } } } @@ -73,7 +70,8 @@ bool Connectors::isFlowVar(Name v) } // Add var to different containers of Connectors -void Connectors::addVar(Name n, VarInfo vi) { +void Connectors::addVar(Name n, VarInfo vi) +{ mmoclass_.addVar(n, vi); // Fill variables, effort and flow names @@ -88,26 +86,25 @@ void Connectors::addVar(Name n, VarInfo vi) { // Fill varsDims int dims = 0; Option vinds = vi.indices_; - if (vinds) - dims = (*vinds).size(); + if (vinds) dims = (*vinds).size(); Option odims(dims); - varsDims_.insert(n, dims); + varsDims_.insert(n, dims); } - // Initialization -bool Connectors::init() +bool Connectors::init() { // Get "largest" number of dimensions from variables - foreach_ (Name n, mmoclass_.variables()) { + foreach_(Name n, mmoclass_.variables()) + { Option ovi = mmoclass_.getVar(n); if (ovi) { VarInfo vi = *ovi; Option oinds = vi.indices(); if (oinds) { ExpList inds = *oinds; - set_maxdim(max((INT) maxdim_, (INT) inds.size())); + set_maxdim(max((INT)maxdim_, (INT)inds.size())); } } @@ -115,14 +112,15 @@ bool Connectors::init() LOG << "Variable " << n << " without information" << endl; return false; } - } + } vector maxdimVector(maxdim_, 1); set_vCount(maxdimVector); set_eCount(maxdimVector); // Fill all variable related info - foreach_ (Name n, mmoclass_.variables()) { + foreach_(Name n, mmoclass_.variables()) + { Option vinfo = mmoclass_.syms()[n]; if (vinfo) @@ -137,7 +135,7 @@ bool Connectors::init() // Fill countersCG ExpList newCG; ExpList::iterator itNewCG = newCG.begin(); - for(unsigned int i = 0; (int) i < maxdim_; ++i){ + for (unsigned int i = 0; (int)i < maxdim_; ++i) { string nm(1, 105 + i); itNewCG = newCG.insert(itNewCG, Expression(nm)); ++itNewCG; @@ -155,14 +153,16 @@ void Connectors::debug(std::string filename) LOG << "Connect Graph vertices & edges:" << endl << endl; // Print vertices - foreach_ (SetVertexDesc vi, vertices(G_)) { + foreach_(SetVertexDesc vi, vertices(G_)) + { Name n = G_[vi].id(); Set vs = G_[vi].range(); LOG << n << ": " << vs << endl; } // Print edges - foreach_ (SetEdgeDesc ei, edges(G_)) { + foreach_(SetEdgeDesc ei, edges(G_)) + { Name n = G_[ei].id(); PWLMap es1 = G_[ei].map_f(); PWLMap es2 = G_[ei].map_u(); @@ -179,7 +179,7 @@ void Connectors::debug(std::string filename) gp.printGraph(filename); LOG << "Generated Connect Graph written to " << filename << endl << endl; - LOG << "Connected components of SBG: " << filename << endl; + LOG << "Connected components of SBG: " << filename << endl; LOG << ccG_ << endl; } @@ -199,7 +199,8 @@ void Connectors::solve() notConnectEqs_ = get<1>(gr); - foreach_(Equation e, notConnectEqs_) { + foreach_(Equation e, notConnectEqs_) + { itAll = allEqs.insert(itAll, e); ++itAll; } @@ -207,7 +208,8 @@ void Connectors::solve() PWLMap res = connectedComponents(G_); set_ccG(res); - foreach_ (Name nm, mmoclass_.variables()) { + foreach_(Name nm, mmoclass_.variables()) + { Option ovi = mmoclass_.getVar(nm); if (ovi) { VarInfo vi = *ovi; @@ -219,7 +221,8 @@ void Connectors::solve() } EquationList connEqs = generateCode(); - foreach_(Equation e, connEqs) { + foreach_(Equation e, connEqs) + { itAll = allEqs.insert(itAll, e); ++itAll; } @@ -244,21 +247,20 @@ void Connectors::solve() // Given a connector name, get variables of the connector // Is used in the case in which the operator '-' is applied // to a connector, to add new negative variables of the connector -set Connectors::getByPrefix(Name n) +set Connectors::getByPrefix(Name n) { set res; - if (n[0] == '-') - n = n.substr(1, n.length() - 1); + if (n[0] == '-') n = n.substr(1, n.length() - 1); - foreach_ (Name nm, varsNms_) { + foreach_(Name nm, varsNms_) + { if (nm.length() > n.length()) { Name auxnm = nm.substr(0, n.length()); Name end = nm.substr(n.length(), 1); if (n == auxnm && end[0] == '_') { - if (n[0] == '-') - nm = '-' + nm; + if (n[0] == '-') nm = '-' + nm; res.insert(nm); } @@ -271,7 +273,7 @@ set Connectors::getByPrefix(Name n) // Add "negative" connectors vars to different containers of Connectors // The name n should be the name of a connector // This function should be only called by buildVertex -Option Connectors::addConnectorVars(Name n) +Option Connectors::addConnectorVars(Name n) { Option ovi = mmoclass_.getVar(n); @@ -279,8 +281,7 @@ Option Connectors::addConnectorVars(Name n) ovi = mmoclass_.getVar(n.substr(1, n.length() - 1)); if (ovi) { - foreach_ (Name nm, getByPrefix(n)) - addVar('-' + nm, *ovi); + foreach_(Name nm, getByPrefix(n)) addVar('-' + nm, *ovi); } else { @@ -300,7 +301,7 @@ Real Connectors::getValue(Expression exp) return Apply(eval_exp, exp); } -// Build a Set from a variable. All variables are updated to +// Build a Set from a variable. All variables are updated to // have the maximum number of dimensions according to the model. // To be used in buildVertex Set Connectors::buildSet(VarInfo v) @@ -310,7 +311,7 @@ Set Connectors::buildSet(VarInfo v) Option dims = v.indices(); MultiInterval v_intervals; - ExpList inds; + ExpList inds; ExpList::iterator itinds = inds.begin(); // Multi-dimensional variable @@ -323,7 +324,8 @@ Set Connectors::buildSet(VarInfo v) EvalExpFlatter evexp(auxsyms); // Fill dimensions if necessary - foreach_ (INT offset, vCount_) { + foreach_(INT offset, vCount_) + { Interval i; // Use declared dimensions for the variable @@ -357,17 +359,17 @@ Option Connectors::buildVertex(Name n) Option ovi = addConnectorVars(n); // Vertex already created - foreach_ (SetVertexDesc Vdesc, vertices(G_)) { - if (G_[Vdesc].id() == n) - return Option(Vdesc); + foreach_(SetVertexDesc Vdesc, vertices(G_)) + { + if (G_[Vdesc].id() == n) return Option(Vdesc); } - - // Vertex doesn't exist + + // Vertex doesn't exist if (ovi) { VarInfo vi = *ovi; Set s = buildSet(vi); - SetVertex V(n, s); + SetVertex V(n, s); SetVertexDesc Vdesc = boost::add_vertex(G_); G_[Vdesc] = V; @@ -390,7 +392,7 @@ MultiInterval Connectors::buildEdgeMultiInterval(VarInfo v, int offset) Option dims = v.indices(); MultiInterval v_intervals; - ExpList inds; + ExpList inds; ExpList::iterator itinds = inds.begin(); // Previous dimensions remain the same @@ -411,7 +413,8 @@ MultiInterval Connectors::buildEdgeMultiInterval(VarInfo v, int offset) EvalExpFlatter evexp(auxsyms); // Values of dimensions of interest - foreach_ (Expression e, inds) { + foreach_(Expression e, inds) + { Interval i; Interval auxi = Apply(evexp, *itinds); i = Interval(*itEC + auxi.lo() - 1, auxi.step(), *itEC + auxi.hi() - 1); @@ -420,8 +423,7 @@ MultiInterval Connectors::buildEdgeMultiInterval(VarInfo v, int offset) itNewEC = newECount.insert(itNewEC, i.hi() + 1); ++itNewEC; - if (itEC != eCount_.end()) - ++itEC; + if (itEC != eCount_.end()) ++itEC; } // Convert it to maximum dimension @@ -438,18 +440,18 @@ MultiInterval Connectors::buildEdgeMultiInterval(VarInfo v, int offset) // Given a subscript list r, traverse it to find in which // dimension nm is used. -int Connectors::locateCounterDimension(ExpOptList r, Name nm) +int Connectors::locateCounterDimension(ExpOptList r, Name nm) { int dim = 0; if (r) { - foreach_ (Expression ri, *r) { + foreach_(Expression ri, *r) + { Reference r(nm); Expression e(r); ContainsExpression co(e); - if (Apply(co, ri)) - return dim; + if (Apply(co, ri)) return dim; ++dim; } @@ -460,16 +462,17 @@ int Connectors::locateCounterDimension(ExpOptList r, Name nm) // Given a multi-interval whose dimension isn't the maxdim_, // complete it to have the maximum dimension in the model -MultiInterval Connectors::fillDims(MultiInterval mi, int olddim, int dim) +MultiInterval Connectors::fillDims(MultiInterval mi, int olddim, int dim) { vector newECount; vector::iterator itNewEC = newECount.begin(); int i = 0; - foreach_ (INT ei, eCount_) { + foreach_(INT ei, eCount_) + { if (i < olddim || i > dim) { Interval idim(ei, 1, ei); MultiInterval midim; - midim.addInter(idim); + midim.addInter(idim); if (i < olddim) mi = midim.crossProd(mi); @@ -497,7 +500,7 @@ MultiInterval Connectors::fillDims(MultiInterval mi, int olddim, int dim) // It creates a new Set which values are the ones // of the current counters // ENHANCEMENT: simplify this code, lulz -Set Connectors::buildEdgeDom(ExpOptList r) +Set Connectors::buildEdgeDom(ExpOptList r) { MultiInterval miCounters; @@ -506,7 +509,8 @@ Set Connectors::buildEdgeDom(ExpOptList r) vector newECount; vector::iterator itNewEC = newECount.begin(); - foreach_ (INT eci, eCount_) { + foreach_(INT eci, eCount_) + { miCounters.addInter(Interval(eci, 1, eci)); itNewEC = newECount.insert(itNewEC, eci + 1); @@ -519,7 +523,8 @@ Set Connectors::buildEdgeDom(ExpOptList r) // Connect is inside some loop else if (r) { int olddim = locateCounterDimension(r, *(counters_.begin())); - foreach_ (Name count, counters_) { + foreach_(Name count, counters_) + { int dim = locateCounterDimension(r, count); // Variable is declared in the loop, but it isn't used in the connect // This is considered an error in this compiler @@ -546,8 +551,7 @@ Set Connectors::buildEdgeDom(ExpOptList r) } // Complete remaining dimensions - if ((int) counters_.size() != maxdim_) - miCounters = fillDims(miCounters, olddim, dim); + if ((int)counters_.size() != maxdim_) miCounters = fillDims(miCounters, olddim, dim); olddim = dim; } @@ -575,7 +579,7 @@ LMap Connectors::buildLM(MultiInterval mi1, MultiInterval mi2) while (itmi1 != miinters1.end()) { if ((*itmi2).card() == 1) { REAL newg = 0; - REAL newo = (*itmi2).lo(); + REAL newo = (*itmi2).lo(); itresg = resg.insert(itresg, newg); itreso = reso.insert(itreso, newo); @@ -586,7 +590,7 @@ LMap Connectors::buildLM(MultiInterval mi1, MultiInterval mi2) else if ((*itmi1).card() == (*itmi2).card()) { REAL newg = (*itmi2).step() / (*itmi1).step(); - REAL newo = (*itmi2).lo() - newg * (*itmi1).lo(); + REAL newo = (*itmi2).lo() - newg * (*itmi1).lo(); itresg = resg.insert(itresg, newg); itreso = reso.insert(itreso, newo); @@ -610,7 +614,7 @@ LMap Connectors::buildLM(MultiInterval mi1, MultiInterval mi2) // Returns a multi-interval with the corresponding subscripts // applied -MultiInterval Connectors::subscriptMI(MultiInterval mi, ExpOptList r) +MultiInterval Connectors::subscriptMI(MultiInterval mi, ExpOptList r) { OrdCT mires; OrdCT::iterator itmires = mires.begin(); @@ -621,7 +625,8 @@ MultiInterval Connectors::subscriptMI(MultiInterval mi, ExpOptList r) EvalExpFlatter evexp(auxsyms); if (r) { - foreach_ (Expression ri, *r) { + foreach_(Expression ri, *r) + { Interval ndim = Apply(evexp, ri); INT offset = (*itmi).lo(); Interval res(ndim.lo() + offset - 1, ndim.step(), ndim.hi() + offset - 1); @@ -639,7 +644,7 @@ MultiInterval Connectors::subscriptMI(MultiInterval mi, ExpOptList r) } // Create left and right maps -PWLMap Connectors::buildEdgeMap(Set dom, Set im, ExpOptList r) +PWLMap Connectors::buildEdgeMap(Set dom, Set im, ExpOptList r) { PWLMap res; @@ -664,11 +669,11 @@ PWLMap Connectors::buildEdgeMap(Set dom, Set im, ExpOptList r) // Check if edge is already created bool Connectors::existsEdge(string nm) { - foreach_ (SetEdgeDesc ei, edges(G_)) { + foreach_(SetEdgeDesc ei, edges(G_)) + { string nmi = G_[ei].id(); - if (nmi == nm) - return true; + if (nmi == nm) return true; } return false; @@ -677,7 +682,7 @@ bool Connectors::existsEdge(string nm) // Create a set-edges. Current implementation might create several edges to connect // the same vertices. This doesn't impact on the cost of the algorithm // ENHANCEMENT: update edges insted of creeating, if set-edge exists -void Connectors::buildEdge(ExpOptList r1, ExpOptList r2, SetVertexDesc Vdesc1, SetVertexDesc Vdesc2) +void Connectors::buildEdge(ExpOptList r1, ExpOptList r2, SetVertexDesc Vdesc1, SetVertexDesc Vdesc2) { SetVertex V1 = G_[Vdesc1]; SetVertex V2 = G_[Vdesc2]; @@ -698,8 +703,7 @@ void Connectors::buildEdge(ExpOptList r1, ExpOptList r2, SetVertexDesc Vdesc1, S return; } Set dom = dom1; - if (dom2.card() > dom1.card()) - dom = dom2; + if (dom2.card() > dom1.card()) dom = dom2; PWLMap pw1 = buildEdgeMap(dom, V1.range(), r1); PWLMap pw2 = buildEdgeMap(dom, V2.range(), r2); SetEdge E(nm, pw1, pw2); @@ -714,7 +718,7 @@ void Connectors::buildEdge(ExpOptList r1, ExpOptList r2, SetVertexDesc Vdesc1, S bool Connectors::checkLinearBase(Expression e) { - if (is(e)) + if (is(e)) return true; else if (is(e)) @@ -727,7 +731,7 @@ bool Connectors::checkLinearBase(Expression e) // For the time being only a * x + b is allowed // e.g. a * x + b - c is rejected // ENHANCEMENT: generalize to arbitrary linear expressions -bool Connectors::checkLinear(Expression e) +bool Connectors::checkLinear(Expression e) { if (is(e)) { UnaryOp u = boost::get(e); @@ -739,11 +743,11 @@ bool Connectors::checkLinear(Expression e) Expression l = b.left(); Expression r = b.right(); - if (b.op() == Add || b.op() == Sub) + if (b.op() == Add || b.op() == Sub) return checkLinear(l) && checkLinear(r); - else if (b.op() == Mult) - return (is(l) && checkLinearBase(r)) || (is(r) && checkLinearBase(l)); + else if (b.op() == Mult) + return (is(l) && checkLinearBase(r)) || (is(r) && checkLinearBase(l)); else if (b.op() == Div) return is(r) && checkLinearBase(l); @@ -758,9 +762,10 @@ bool Connectors::checkLinear(Expression e) } // Check that all expressions in an expression list are linear -bool Connectors::checkLinearList(ExpList expl) +bool Connectors::checkLinearList(ExpList expl) { - foreach_ (Expression e, expl) { + foreach_(Expression e, expl) + { if (!checkLinear(e)) { LOG << "ERROR: Subscript " << e << " should be linear" << endl; return false; @@ -779,7 +784,8 @@ bool Connectors::checkCounters(ExpList l1, ExpList l2) ExpList::iterator itl2 = l2.begin(); while (itl1 != l1.end() && itl2 != l2.end()) { - foreach_ (Name nm1, varsNms_) { + foreach_(Name nm1, varsNms_) + { Reference r1(nm1); Expression e1(r1); ContainsExpression co1(e1); @@ -787,7 +793,8 @@ bool Connectors::checkCounters(ExpList l1, ExpList l2) bool coNm11 = Apply(co1, *itl1); bool coNm12 = Apply(co1, *itl2); - foreach_ (Name nm2, varsNms_) { + foreach_(Name nm2, varsNms_) + { Reference r2(nm2); Expression e2(r2); ContainsExpression co2(e2); @@ -796,7 +803,7 @@ bool Connectors::checkCounters(ExpList l1, ExpList l2) bool coNm21 = Apply(co2, *itl1); bool coNm22 = Apply(co2, *itl2); - // l1 is non linear in some dimension + // l1 is non linear in some dimension if (coNm11 && coNm21) { LOG << "ERROR: Subscript " << *itl1 << " should be linear" << endl; return false; @@ -817,7 +824,7 @@ bool Connectors::checkCounters(ExpList l1, ExpList l2) } } - ++itl1; + ++itl1; ++itl2; } @@ -831,7 +838,7 @@ bool Connectors::checkSubscripts(ExpOptList range1, ExpOptList range2) if (range1 && range2) { ExpList r1 = range1.get(); ExpList r2 = range2.get(); - + if (r1.size() == 0 || r2.size() == 0) return true; @@ -847,7 +854,7 @@ bool Connectors::checkSubscripts(ExpOptList range1, ExpOptList range2) else if (!checkLinearList(r2)) return false; - else if (!checkCounters(r1, r2)) + else if (!checkCounters(r1, r2)) return false; } } @@ -869,18 +876,16 @@ Pair Connectors::separate(Expression e) reference = boost::get(u.exp()); else LOG << "ERROR: It should be a Reference" << std::endl; - } - + } + else if (is(e)) reference = boost::get(e); Ref refs = reference.ref(); - if (refs.size() > 1) - LOG << "ERROR: There shouldn't be calls to members in connectores" << std::endl; + if (refs.size() > 1) LOG << "ERROR: There shouldn't be calls to members in connectores" << std::endl; RefTuple rf = refs.front(); ExpOptList opti; - if (get<1>(rf).size() > 0) - opti = Option(get<1>(rf)); + if (get<1>(rf).size() > 0) opti = Option(get<1>(rf)); Name r = get<0>(rf); return Pair(r, opti); @@ -890,7 +895,7 @@ Pair Connectors::separate(Expression e) bool Connectors::connect(Connect co) { Expression eleft = co.left(), eright = co.right(); - + Pair left = separate(eleft); Pair right = separate(eright); ExpOptList range1 = get<1>(left); @@ -902,14 +907,12 @@ bool Connectors::connect(Connect co) if (is(eleft)) { UnaryOp uop = boost::get(eleft); - if (uop.op_ == Minus) - v1 = "-" + v1; + if (uop.op_ == Minus) v1 = "-" + v1; } if (is(eright)) { UnaryOp uop = boost::get(eright); - if (uop.op_ == Minus) - v2 = "-" + v2; + if (uop.op_ == Minus) v2 = "-" + v2; } Option V1 = buildVertex(v1); @@ -921,7 +924,7 @@ bool Connectors::connect(Connect co) } else - return false; + return false; } return false; @@ -933,16 +936,18 @@ bool Connectors::connect(Connect co) // (If a counter does so in its declaration, they aren't independent) bool Connectors::checkIndependentCounters(ForEq feq) { - foreach_ (Index ind, feq.range().indexes()) { + foreach_(Index ind, feq.range().indexes()) + { Name n = ind.name(); OptExp e = ind.exp(); if (e) { - foreach_ (Name nm, counters_) { + foreach_(Name nm, counters_) + { Reference rnm(nm); Expression enm(rnm); ContainsExpression co(enm); - + if (Apply(co, *e) && nm != n) { LOG << "ERROR: Counters aren't independent in " << e << endl; return false; @@ -960,17 +965,17 @@ bool Connectors::checkIndependentCounters(ForEq feq) // Create vertices for non connected connectors (for flow equations) void Connectors::buildDisconnected() { - foreach_ (Name n, flowVars_) { + foreach_(Name n, flowVars_) + { int i = n.length(); - while (n[i] != '_') - i--; + while (n[i] != '_') i--; buildVertex(n.substr(0, i)); } } // Construct Connect Graph, treating connects. -// If the model doesn't satisfy the restrictions described in +// If the model doesn't satisfy the restrictions described in // the paper, an empty model will be returned. Pair Connectors::buildConnects(EquationList &eqs) { @@ -983,7 +988,8 @@ Pair Connectors::buildConnects(EquationList &eqs) const VarSymbolTable auxsyms = mmoclass_.syms(); EvalExpFlatter evexp(auxsyms); - foreach_(Equation eq, eqs) { + foreach_(Equation eq, eqs) + { // Connect equation if (is(eq)) { ok = connect(get(eq)); @@ -995,38 +1001,38 @@ Pair Connectors::buildConnects(EquationList &eqs) } // Traverse ForEqs to find connects - else if(is(eq)) { + else if (is(eq)) { // Save information of counters set prevVarsNms = varsNms_; set auxVarsNms = varsNms_; vector prevCounters = counters_; vector auxCounters = counters_; vector::iterator itaux = auxCounters.begin(); - + vector auxvars; vector::iterator itvars = auxvars.begin(); ForEq feq = boost::get(eq); - foreach_ (Index ind, feq.range().indexes()) { + foreach_(Index ind, feq.range().indexes()) + { Name n = ind.name(); OptExp e = ind.exp(); if (e) { Interval i = Apply(evexp, *e); if (!i.empty()) { - VarInfo vi(TypePrefixes(), n, Option(), - Option(Modification(ModAssign(*e))), - ExpOptList(ExpList(1, *e)), false); + VarInfo vi(TypePrefixes(), n, Option(), Option(Modification(ModAssign(*e))), ExpOptList(ExpList(1, *e)), + false); mmoclass_.addVar(n, vi); auxVarsNms.insert(n); - itaux = auxCounters.insert(itaux, n); - ++itaux; + itaux = auxCounters.insert(itaux, n); + ++itaux; itvars = auxvars.insert(itvars, n); ++itvars; } } - else { + else { ok = false; LOG << "ERROR: Counter " << n << " should have bounds" << endl; break; @@ -1042,15 +1048,12 @@ Pair Connectors::buildConnects(EquationList &eqs) ok = get<0>(rec); EquationList recNotConnEql = get<1>(rec); - if (!ok) - break; + if (!ok) break; // Check that for with connect equations have independent counters - if (eql.size() > 0 && eql.size() != recNotConnEql.size()) - ok = checkIndependentCounters(feq); + if (eql.size() > 0 && eql.size() != recNotConnEql.size()) ok = checkIndependentCounters(feq); - if (!ok) - break; + if (!ok) break; // If there are "non-connect" equations, put them in a new for if (!recNotConnEql.empty()) { @@ -1060,8 +1063,7 @@ Pair Connectors::buildConnects(EquationList &eqs) } // Remove information of counters - foreach_ (Name auxnm, auxvars) - mmoclass_.rmVar(auxnm); + foreach_(Name auxnm, auxvars) mmoclass_.rmVar(auxnm); set_varsNms(prevVarsNms); set_counters(prevCounters); @@ -1081,7 +1083,7 @@ Pair Connectors::buildConnects(EquationList &eqs) Pair Connectors::buildGraph(EquationList &eqs) { buildDisconnected(); - return buildConnects(eqs); + return buildConnects(eqs); } // Code generation helpers ----------------------------------------------------------------------- @@ -1093,11 +1095,11 @@ Name Connectors::getName(MultiInterval as) Set auxas = createSet(as); - foreach_ (SetVertexDesc vi, vertices(G_)) { + foreach_(SetVertexDesc vi, vertices(G_)) + { Set vs = G_[vi].range(); - if (!auxas.cap(vs).empty()) - nm = G_[vi].id(); + if (!auxas.cap(vs).empty()) nm = G_[vi].id(); } return nm; @@ -1105,18 +1107,18 @@ Name Connectors::getName(MultiInterval as) // Given a subset of a set-vertex, returns the set which contains // all the vertices in the set-vertex -MultiInterval Connectors::getAtomSet(MultiInterval as) +MultiInterval Connectors::getAtomSet(MultiInterval as) { MultiInterval res; Set auxas = createSet(as); - foreach_ (SetVertexDesc vi, vertices(G_)) { + foreach_(SetVertexDesc vi, vertices(G_)) + { Set vs = G_[vi].range(); if (!auxas.cap(vs).empty()) { - foreach_ (MultiInterval asvs, vs.asets()) - if (!asvs.cap(as).empty()) res = asvs; + foreach_(MultiInterval asvs, vs.asets()) if (!asvs.cap(as).empty()) res = asvs; } } @@ -1124,17 +1126,13 @@ MultiInterval Connectors::getAtomSet(MultiInterval as) } // Determine if a map is the identity -bool Connectors::isIdMap(LMap lm) +bool Connectors::isIdMap(LMap lm) { bool cond = true; - foreach_ (REAL g, lm.gain()) - if (g != 1) - cond = false; + foreach_(REAL g, lm.gain()) if (g != 1) cond = false; - foreach_ (REAL o, lm.offset()) - if (o != 0) - cond = false; + foreach_(REAL o, lm.offset()) if (o != 0) cond = false; return cond; } @@ -1147,14 +1145,16 @@ vector Connectors::getEffVars(Set connector) vector::iterator itres = res.begin(); // Get connector name - foreach_ (SetVertexDesc vi, vertices(G_)) { + foreach_(SetVertexDesc vi, vertices(G_)) + { Set vs = G_[vi].range(); Name vinm = G_[vi].id(); if (!connector.cap(vs).empty()) { // Search effort vars in the connector - foreach_ (Name e, effVars_) { - Name aux = e.substr(0, vinm.length()); + foreach_(Name e, effVars_) + { + Name aux = e.substr(0, vinm.length()); if (e.size() > vinm.size()) { Name end = e.substr(vinm.length(), 1); @@ -1181,14 +1181,16 @@ vector Connectors::getFlowVars(Set connector) vector::iterator itres = res.begin(); // Get connector name - foreach_ (SetVertexDesc vi, vertices(G_)) { + foreach_(SetVertexDesc vi, vertices(G_)) + { Set vs = G_[vi].range(); Name vinm = G_[vi].id(); if (!connector.cap(vs).empty()) { // Search flow vars in the connector - foreach_ (Name e, flowVars_) { - Name aux = e.substr(0, vinm.length()); + foreach_(Name e, flowVars_) + { + Name aux = e.substr(0, vinm.length()); if (e.size() > vinm.size()) { Name end = e.substr(vinm.length(), 1); if (aux == vinm && end == "_") { @@ -1205,7 +1207,7 @@ vector Connectors::getFlowVars(Set connector) return res; } -// Given an atomic set of a connected component, build the loop indexes +// Given an atomic set of a connected component, build the loop indexes // that will be used to write the flattened equations. // In each dimension the counter will set its bounds according to // the maximum number of elements in that dimension in all subsets of set-vertices. @@ -1216,16 +1218,17 @@ Indexes Connectors::buildIndex(Set connected) ExpList::iterator itCG = countersCG_.begin(); - OrdCT nElems; // Maximum number of elements in each dimension - foreach_ (MultiInterval c, connected.asets()) { + OrdCT nElems; // Maximum number of elements in each dimension + foreach_(MultiInterval c, connected.asets()) + { // Traverse dimensions OrdCT::iterator itElems = nElems.begin(); OrdCT nElemsAux; OrdCT::iterator itAux = nElemsAux.begin(); - foreach_ (Interval i, c.inters()) { + foreach_(Interval i, c.inters()) + { int elems = i.card(); - if (*itElems) - elems = max(*itElems, (INT) elems); + if (*itElems) elems = max(*itElems, (INT)elems); itAux = nElemsAux.insert(itAux, elems); ++itAux; @@ -1236,8 +1239,9 @@ Indexes Connectors::buildIndex(Set connected) } // Traverse dimensions - foreach_ (INT n, nElems) { - Range r(Expression(1), Expression(1), Expression((int) n)); + foreach_(INT n, nElems) + { + Range r(Expression(1), Expression(1), Expression((int)n)); Expression er(r); Option oer(er); @@ -1253,10 +1257,10 @@ Indexes Connectors::buildIndex(Set connected) return res; } -// Get atom sets that are in the dom of ccG_, +// Get atom sets that are in the dom of ccG_, // that don't have an intersection with atomRept // and whose image is contained by atomRept (represented vertices) -Set Connectors::getRepd(MultiInterval atomRept) +Set Connectors::getRepd(MultiInterval atomRept) { UnordCT atomRes; @@ -1264,8 +1268,7 @@ Set Connectors::getRepd(MultiInterval atomRept) Set pre = ccG_.preImage(rept); Set diff = pre.diff(rept); - if (diff.empty()) - return rept; + if (diff.empty()) return rept; return diff; } @@ -1296,12 +1299,12 @@ ExpList Connectors::buildSubscripts(Indexes indexes, MultiInterval original, Mul ExpList::iterator itCG = countersCG_.begin(); // Not an array, doesn't need subscripts - if (dims == 0) - return res; + if (dims == 0) return res; // Traverse counters, creating subscripts int dim = 0; - foreach_ (Index ind, indexes.indexes_) { + foreach_(Index ind, indexes.indexes_) + { // Complete subscripts up to variable dimension if (dim < dims) { OptExp oe = ind.exp_; @@ -1310,7 +1313,7 @@ ExpList Connectors::buildSubscripts(Indexes indexes, MultiInterval original, Mul // Constant value in dimension, don't use counter if ((*itmias).card() == 1) { - int off = (*itmias).lo() - (*itmiori).lo() + 1; + int off = (*itmias).lo() - (*itmiori).lo() + 1; Expression eoff(off); itres = res.insert(itres, eoff); @@ -1318,14 +1321,14 @@ ExpList Connectors::buildSubscripts(Indexes indexes, MultiInterval original, Mul // Use counter else { - Real step = (*itmias).step(); - Real off = (((*itmias).lo() - (*itmiori).lo() + 1)) - (step * loInd); + Real step = (*itmias).step(); + Real off = (((*itmias).lo() - (*itmiori).lo() + 1)) - (step * loInd); if (step == 0) itres = res.insert(itres, Expression(off)); else if (step == 1) { - if (off == 0) + if (off == 0) itres = res.insert(itres, *itCG); else if (off > 0) { @@ -1345,7 +1348,7 @@ ExpList Connectors::buildSubscripts(Indexes indexes, MultiInterval original, Mul Expression estep(step); BinOp bop(estep, Mult, *itCG); - if (off == 0) + if (off == 0) itres = res.insert(itres, bop); else if (off > 0) { @@ -1378,7 +1381,7 @@ ExpList Connectors::buildSubscripts(Indexes indexes, MultiInterval original, Mul // Build expressions for variables used in equations in a loop // The third argument is to restrict use to either effort or flow variables -ExpList Connectors::buildLoopExpr(Indexes indexes, MultiInterval as, vector vars) +ExpList Connectors::buildLoopExpr(Indexes indexes, MultiInterval as, vector vars) { ExpList res; ExpList::iterator itres = res.begin(); @@ -1386,7 +1389,8 @@ ExpList Connectors::buildLoopExpr(Indexes indexes, MultiInterval as, vector dims = varsDims_[nmas]; ExpList subs = buildSubscripts(indexes, getAtomSet(as), as, *dims); Reference rrept(nmas, subs); @@ -1395,10 +1399,10 @@ ExpList Connectors::buildLoopExpr(Indexes indexes, MultiInterval as, vector indexesNms; - foreach_ (Index i, indexes.indexes_) - indexesNms.insert(i.name()); + foreach_(Index i, indexes.indexes_) indexesNms.insert(i.name()); // Traverse equations - foreach_ (Equation eq, eqs) { + foreach_(Equation eq, eqs) + { if (is(eq)) { Equality eqty = boost::get(eq); Expression left = eqty.left_, right = eqty.right_; @@ -1527,14 +1535,14 @@ EquationList Connectors::buildLoop(Indexes indexes, EquationList eqs) bool usesCounters = false; // Traverse dimensions - foreach_ (Name i, indexesNms) { + foreach_(Name i, indexesNms) + { Reference refi(i); Expression ei(refi); ContainsExpressionFlatter co(ei); // Equation uses counter, it should go in a loop - if (Apply(co, left) || Apply(co, right)) - usesCounters = true; + if (Apply(co, left) || Apply(co, right)) usesCounters = true; } if (usesCounters) { @@ -1550,7 +1558,7 @@ EquationList Connectors::buildLoop(Indexes indexes, EquationList eqs) } // Create loops, and add the to result - if (loopeqs.size() != 0) { + if (loopeqs.size() != 0) { ForEq feq(indexes, loopeqs); res.insert(itres, feq); } @@ -1561,7 +1569,7 @@ EquationList Connectors::buildLoop(Indexes indexes, EquationList eqs) // Effort ---------------------------------------------------------------------------------------- // Create effort equations for a given representant -EquationList Connectors::buildEffEquations(Indexes indexes, MultiInterval atomRept, Set repd) +EquationList Connectors::buildEffEquations(Indexes indexes, MultiInterval atomRept, Set repd) { EquationList effEqs; EquationList::iterator itEffEqs = effEqs.begin(); @@ -1570,15 +1578,15 @@ EquationList Connectors::buildEffEquations(Indexes indexes, MultiInterval atomRe Set diff1 = rept.diff(repd); Set diff2 = repd.diff(rept); - if (diff1.empty() && diff2.empty()) - return effEqs; - - // Representant subscripts + if (diff1.empty() && diff2.empty()) return effEqs; + + // Representant subscripts ExpList effRept = buildLoopExpr(indexes, atomRept, getEffVars(Set(atomRept))); Expression left = *(effRept.begin()); // Other effort variables in the representant - foreach_ (Expression expRept, effRept) { + foreach_(Expression expRept, effRept) + { if (left != expRept) { Equality eq(left, expRept); itEffEqs = effEqs.insert(itEffEqs, eq); @@ -1587,18 +1595,19 @@ EquationList Connectors::buildEffEquations(Indexes indexes, MultiInterval atomRe } // Traverse represented connectors - foreach_ (MultiInterval atomRepd, repd.asets()) { + foreach_(MultiInterval atomRepd, repd.asets()) + { ExpList effRepd = buildLoopExpr(indexes, atomRepd, getEffVars(Set(atomRepd))); // Represented variables in connector - foreach_ (Expression eRepd, effRepd) { + foreach_(Expression eRepd, effRepd) + { Equality eq(left, eRepd); itEffEqs = effEqs.insert(itEffEqs, eq); ++itEffEqs; } } - if (!effEqs.size() == 0) - effEqs = buildLoop(indexes, effEqs); + if (!effEqs.size() == 0) effEqs = buildLoop(indexes, effEqs); return effEqs; } @@ -1606,7 +1615,7 @@ EquationList Connectors::buildEffEquations(Indexes indexes, MultiInterval atomRe // Flow ------------------------------------------------------------------------------------------ // Create effort equations for a given representant -EquationList Connectors::buildFlowEquations(Indexes indexes, MultiInterval atomRept, Set repd) +EquationList Connectors::buildFlowEquations(Indexes indexes, MultiInterval atomRept, Set repd) { EquationList res; @@ -1615,8 +1624,7 @@ EquationList Connectors::buildFlowEquations(Indexes indexes, MultiInterval atomR Set rept(atomRept); Set diff = repd.diff(rept); - if(repd.empty()) - return res; + if (repd.empty()) return res; if (diff.empty()) { Set emptySet; @@ -1627,29 +1635,27 @@ EquationList Connectors::buildFlowEquations(Indexes indexes, MultiInterval atomR if (atomRept.card() > 1) { EquationList eqsLoop; - // Representant subscripts + // Representant subscripts ExpList flowRept = buildLoopExpr(indexes, atomRept, getFlowVars(Set(atomRept))); Expression left = *(flowRept.begin()); // Other flow variables in the representant - foreach_ (Expression expRept, flowRept) { - if (left != expRept) - left = BinOp(left, Add, expRept); + foreach_(Expression expRept, flowRept) + { + if (left != expRept) left = BinOp(left, Add, expRept); } // Traverse represented connectors - foreach_ (MultiInterval atomRepd, repd.asets()) { + foreach_(MultiInterval atomRepd, repd.asets()) + { ExpList flowRepd = buildLoopExpr(indexes, atomRepd, getFlowVars(Set(atomRepd))); // Represented variables in connector - foreach_ (Expression expRepd, flowRepd) { - left = BinOp(left, Add, expRepd); - } + foreach_(Expression expRepd, flowRepd) { left = BinOp(left, Add, expRepd); } } Equality eq(left, right); eqsLoop.insert(eqsLoop.begin(), eq); - if (!eqsLoop.size() == 0) - res = buildLoop(indexes, eqsLoop); + if (!eqsLoop.size() == 0) res = buildLoop(indexes, eqsLoop); } // No need for a loop, sums will be used if needed @@ -1657,17 +1663,17 @@ EquationList Connectors::buildFlowEquations(Indexes indexes, MultiInterval atomR ExpList rept = buildAddExpr(atomRept, atomRept); Expression left = *(rept.begin()); - foreach_ (Expression e, rept) { - if (e != *(rept.begin())) - left = BinOp(left, Add, e); + foreach_(Expression e, rept) + { + if (e != *(rept.begin())) left = BinOp(left, Add, e); } // Traverse represented connectors - foreach_ (MultiInterval atomRepd, repd.asets()) { + foreach_(MultiInterval atomRepd, repd.asets()) + { ExpList add = buildAddExpr(atomRept, atomRepd); - foreach_ (Expression e, add) - left = BinOp(left, Add, e); + foreach_(Expression e, add) left = BinOp(left, Add, e); } Equality eq(left, right); @@ -1680,7 +1686,7 @@ EquationList Connectors::buildFlowEquations(Indexes indexes, MultiInterval atomR // Code generation ------------------------------------------------------------------------------- // Update mmoclass_ with connect's equations -EquationList Connectors::generateCode() +EquationList Connectors::generateCode() { EquationList res; EquationList::iterator itres = res.begin(); @@ -1691,18 +1697,20 @@ EquationList Connectors::generateCode() Set repts = ccG_.image(); - Set flowVertices; // Flow variables already in an equation + Set flowVertices; // Flow variables already in an equation Set effReps; // Traverse connected components - foreach_ (MultiInterval rept, repts.asets()) { + foreach_(MultiInterval rept, repts.asets()) + { Set repd = getRepd(rept); Indexes indexes = buildIndex(repd); // Effort equations EquationList effEqs = buildEffEquations(indexes, rept, repd); - foreach_ (Equation e, effEqs) { + foreach_(Equation e, effEqs) + { itres = res.insert(itres, e); ++itres; } @@ -1710,7 +1718,8 @@ EquationList Connectors::generateCode() // Flow equations EquationList flowEqs = buildFlowEquations(indexes, rept, repd); - foreach_ (Equation e, flowEqs) { + foreach_(Equation e, flowEqs) + { itres = res.insert(itres, e); ++itres; } @@ -1721,12 +1730,13 @@ EquationList Connectors::generateCode() } // Update flow variables and remove the prefix before generating code. - foreach_(Name nm, mmoclass_.variables()){ + foreach_(Name nm, mmoclass_.variables()) + { Option ovi = mmoclass_.getVar(nm); - if(ovi){ + if (ovi) { VarInfo vi = *ovi; Name ty = vi.type(); - if(ty == "Real"){ + if (ty == "Real") { vi.removePrefix(flow); mmoclass_.addVar(nm, vi); } @@ -1744,16 +1754,18 @@ EquationList Connectors::simplifyCode(EquationList eql) EquationList res; EquationList::iterator itres = res.begin(); - foreach_ (Equation eq1, eql) { + foreach_(Equation eq1, eql) + { bool trivial = false; bool found = false; - + if (is(eq1)) { EquationList newl; EquationList::iterator itnewl = newl.begin(); ForEq feq = boost::get(eq1); - foreach_ (Equation eq, feq.elements()) { + foreach_(Equation eq, feq.elements()) + { if (is(eq)) { Equality eqty = boost::get(eq); if (eqty.left() != eqty.right()) { @@ -1772,15 +1784,14 @@ EquationList Connectors::simplifyCode(EquationList eql) eq1 = newFeq; } - else if (is(eq1)) { + else if (is(eq1)) { Equality eqty = boost::get(eq1); - if (eqty.left() == eqty.right()) - trivial = true; + if (eqty.left() == eqty.right()) trivial = true; } - foreach_ (Equation eq2, res) { - if (eq1 == eq2) - found = true; + foreach_(Equation eq2, res) + { + if (eq1 == eq2) found = true; } if (!found && !trivial) { diff --git a/flatter/connectors.h b/flatter/connectors.hpp similarity index 93% rename from flatter/connectors.h rename to flatter/connectors.hpp index 357d876..d3037e8 100644 --- a/flatter/connectors.h +++ b/flatter/connectors.hpp @@ -20,21 +20,21 @@ #include #include -#include -#include -#include -#include -#include -#include -#include - -#include -#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include #include #include #include -#include -#include +#include +#include using namespace Modelica; using namespace Modelica::AST; diff --git a/flatter/flatter.cpp b/flatter/flatter.cpp index 13c42ec..e71b2f8 100644 --- a/flatter/flatter.cpp +++ b/flatter/flatter.cpp @@ -18,11 +18,11 @@ ******************************************************************************/ -#include -#include +#include +#include #include -#include -#include +#include +#include #include using namespace std; diff --git a/flatter/flatter.h b/flatter/flatter.hpp similarity index 74% rename from flatter/flatter.h rename to flatter/flatter.hpp index fadca74..4f63e74 100644 --- a/flatter/flatter.h +++ b/flatter/flatter.hpp @@ -20,17 +20,17 @@ #ifndef FLATTER_H #define FLATTER_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include class Flatter { diff --git a/flatter/main.cpp b/flatter/main.cpp index 75c691d..2781dbc 100644 --- a/flatter/main.cpp +++ b/flatter/main.cpp @@ -19,7 +19,6 @@ #include #include - #include #include #include @@ -27,14 +26,14 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include void usage() { @@ -43,12 +42,12 @@ void usage() cout << endl; cout << "-c , --class Flatter class defined in a Modelica model." << endl; cout << "-d, --debug Generate a detailed log file with debug information about the " << endl; - cout << " the generated graph, including a dot file for it and the" << endl; + cout << " the generated graph, including a dot file for it and the" << endl; cout << " differents stages of the flatter algorithm." << endl; cout << "-g , --graph Sets the output path for the generated graph dot file," << endl; cout << " this flag only has effect if the debug flag is enabled." << endl; cout << "-h, --help Display this information and exit" << endl; - + cout << "-v, --version Display version information and exit" << endl; cout << endl; cout << "Modelica C Compiler home page: https://github.com/CIFASIS/modelicacc " << endl; @@ -57,12 +56,11 @@ void usage() void version() { cout << "Modelica C Compiler 2.0" << endl; - cout << "License GPLv3+: GNU GPL version 3 or later " << endl; + cout << "License GPLv3+: GNU GPL version 3 or later " << endl; cout << "This is free software: you are free to change and redistribute it." << endl; cout << "There is NO WARRANTY, to the extent permitted by law." << endl; } - int main(int argc, char** argv) { using namespace std; @@ -80,12 +78,9 @@ int main(int argc, char** argv) string output_path = ""; while (true) { - static struct option long_options[] = {{"version", no_argument, 0, 'v'}, - {"help", no_argument, 0, 'h'}, - {"class", required_argument, 0, 'c'}, - {"graph", required_argument, 0, 'g'}, - {"debug", no_argument, 0, 'd'}, - {0, 0, 0, 0}}; + static struct option long_options[] = {{"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, + {"class", required_argument, 0, 'c'}, {"graph", required_argument, 0, 'g'}, + {"debug", no_argument, 0, 'd'}, {0, 0, 0, 0}}; int option_index = 0; opt = getopt_long(argc, argv, "vhdc:g:", long_options, &option_index); if (opt == EOF) { @@ -173,11 +168,11 @@ int main(int argc, char** argv) LOG << " - - - - - - - - - - - - - - - - - - - - - - - - " << std::endl; if (filename.empty()) { if (className != NULL) { - std::string str_class_name = className; - co.debug(str_class_name+".dot"); + std::string str_class_name = className; + co.debug(str_class_name + ".dot"); } else { co.debug("flatter.dot"); - } + } } else { co.debug(filename); } diff --git a/flatter/mmo_graph.h b/flatter/mmo_graph.hpp similarity index 97% rename from flatter/mmo_graph.h rename to flatter/mmo_graph.hpp index b5e7316..1553099 100644 --- a/flatter/mmo_graph.h +++ b/flatter/mmo_graph.hpp @@ -21,8 +21,8 @@ #include #include #include -#include -#include +#include +#include #ifndef MMOGRAPH_DEFINITION_ #define MMOGRAPH_DEFINITION_ diff --git a/flatter/remove_composition.cpp b/flatter/remove_composition.cpp index c01691e..be6ad35 100644 --- a/flatter/remove_composition.cpp +++ b/flatter/remove_composition.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ -#include +#include #include static int label; diff --git a/flatter/remove_composition.h b/flatter/remove_composition.hpp similarity index 83% rename from flatter/remove_composition.h rename to flatter/remove_composition.hpp index 0b5d035..7768268 100644 --- a/flatter/remove_composition.h +++ b/flatter/remove_composition.hpp @@ -18,14 +18,14 @@ ******************************************************************************/ -//#include -#include -#include -#include -#include -#include -#include -#include +//#include +#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/flatter/test/models_test.cpp b/flatter/test/models_test.cpp index ca43760..2b4a515 100644 --- a/flatter/test/models_test.cpp +++ b/flatter/test/models_test.cpp @@ -36,7 +36,7 @@ TEST_P(ITests, GenerateCode) const std::string NAME = GetParam(); std::cout << "Testing model: " << NAME << std::endl; const std::string FLATTER = "../../bin/flatter "; - const std::string ARGS = "../../test/mccprograms/" + NAME + ".mo -d -g ./test_data/" + NAME + ".dot" ; + const std::string ARGS = "../../test/mccprograms/" + NAME + ".mo -d -g ./test_data/" + NAME + ".dot"; const std::string RESULT_FILE = "./test_data/" + NAME + ".passed"; const std::string TEST_CMD = "./test_results.sh " + NAME; const std::string FLATTER_CMD = FLATTER + ARGS + " > ./test_data/" + NAME + ".mo"; diff --git a/mmo/main.cpp b/mmo/main.cpp index c167327..50716bc 100644 --- a/mmo/main.cpp +++ b/mmo/main.cpp @@ -18,12 +18,12 @@ ******************************************************************************/ #include -#include +#include #include -#include -#include -#include -#include +#include +#include +#include +#include #include int main(int argc, char** argv) diff --git a/mmo/mmo_class.cpp b/mmo/mmo_class.cpp index 5a12d94..1151098 100644 --- a/mmo/mmo_class.cpp +++ b/mmo/mmo_class.cpp @@ -17,10 +17,10 @@ ******************************************************************************/ -#include +#include #include -#include -#include +#include +#include #include @@ -230,23 +230,24 @@ void MMO_Class::insertElement(Element e) } } -void MMO_Class::addVar(Name n, VarInfo var){ - syms_.insert(n, var); - //cout << n << ": " << var << "\n"; +void MMO_Class::addVar(Name n, VarInfo var) +{ + syms_.insert(n, var); + // cout << n << ": " << var << "\n"; } -void MMO_Class::rmVar(Name n){ +void MMO_Class::rmVar(Name n) +{ syms_.remove(n); std::vector::iterator itvars = variables_.begin(); std::vector newvars; std::vector::iterator itnew = newvars.begin(); - for(; itvars != variables_.end(); ++itvars){ - if(*itvars != n){ + for (; itvars != variables_.end(); ++itvars) { + if (*itvars != n) { itnew = newvars.insert(itnew, *itvars); ++itnew; } - } set_variables(newvars); } diff --git a/mmo/mmo_class.h b/mmo/mmo_class.hpp similarity index 96% rename from mmo/mmo_class.h rename to mmo/mmo_class.hpp index 23ea861..2601b1a 100644 --- a/mmo/mmo_class.h +++ b/mmo/mmo_class.hpp @@ -20,9 +20,9 @@ #ifndef MMO_CLASS #define MMO_CLASS -#include -#include -#include +#include +#include +#include namespace Modelica { using namespace Modelica::AST; diff --git a/mmo/mmo_tree.cpp b/mmo/mmo_tree.cpp index 3e102fd..1423fff 100644 --- a/mmo/mmo_tree.cpp +++ b/mmo/mmo_tree.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include using namespace std; diff --git a/mmo/mmo_tree.h b/mmo/mmo_tree.hpp similarity index 92% rename from mmo/mmo_tree.h rename to mmo/mmo_tree.hpp index 747e16a..e0184e9 100644 --- a/mmo/mmo_tree.h +++ b/mmo/mmo_tree.hpp @@ -20,10 +20,10 @@ #ifndef CREATEMMOTREE_H #define CREATEMMOTREE_H -#include -#include -#include -#include +#include +#include +#include +#include using namespace Modelica; using namespace Modelica::AST; diff --git a/parser/class.cpp b/parser/class.cpp index 6d1edc0..40d65df 100644 --- a/parser/class.cpp +++ b/parser/class.cpp @@ -17,8 +17,8 @@ ******************************************************************************/ -#include -#include +#include +#include namespace Modelica { namespace Parser { diff --git a/parser/class.h b/parser/class.hpp similarity index 96% rename from parser/class.h rename to parser/class.hpp index 39234a0..6f7e8ad 100644 --- a/parser/class.h +++ b/parser/class.hpp @@ -21,10 +21,10 @@ #define CLASS_PARSER #include -#include -#include -#include -#include +#include +#include +#include +#include namespace qi = boost::spirit::qi; using namespace Modelica::AST; diff --git a/parser/class_def.h b/parser/class_def.hpp similarity index 99% rename from parser/class_def.h rename to parser/class_def.hpp index 1c1dd64..fa46a72 100644 --- a/parser/class_def.h +++ b/parser/class_def.hpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include BOOST_FUSION_ADAPT_STRUCT(Modelica::AST::Class, (Modelica::AST::Name, name_)(Modelica::AST::StringComment, st_comment_)(Modelica::AST::Composition, composition_)) diff --git a/parser/equation.cpp b/parser/equation.cpp index 0009e95..e3a8d14 100644 --- a/parser/equation.cpp +++ b/parser/equation.cpp @@ -17,8 +17,8 @@ ******************************************************************************/ -#include -#include +#include +#include namespace Modelica { namespace Parser { diff --git a/parser/equation.h b/parser/equation.hpp similarity index 95% rename from parser/equation.h rename to parser/equation.hpp index 3bb1892..3b23640 100644 --- a/parser/equation.h +++ b/parser/equation.hpp @@ -21,9 +21,9 @@ #define EQUATION_PARSER #include -#include -#include -#include +#include +#include +#include namespace qi = boost::spirit::qi; using namespace Modelica::AST; diff --git a/parser/equation_def.h b/parser/equation_def.hpp similarity index 100% rename from parser/equation_def.h rename to parser/equation_def.hpp diff --git a/parser/expression.cpp b/parser/expression.cpp index 229856b..ebe5bf2 100644 --- a/parser/expression.cpp +++ b/parser/expression.cpp @@ -17,8 +17,8 @@ ******************************************************************************/ -#include -#include +#include +#include namespace Modelica { namespace Parser { diff --git a/parser/expression.h b/parser/expression.hpp similarity index 97% rename from parser/expression.h rename to parser/expression.hpp index 73e6c84..dc67cbc 100644 --- a/parser/expression.h +++ b/parser/expression.hpp @@ -21,9 +21,9 @@ #define EXPRESSION_PARSER #include -#include -#include -#include +#include +#include +#include namespace qi = boost::spirit::qi; using namespace Modelica::AST; diff --git a/parser/expression_def.h b/parser/expression_def.hpp similarity index 100% rename from parser/expression_def.h rename to parser/expression_def.hpp diff --git a/parser/ident.cpp b/parser/ident.cpp index 218c83d..acab1fb 100644 --- a/parser/ident.cpp +++ b/parser/ident.cpp @@ -17,8 +17,8 @@ ******************************************************************************/ -#include -#include +#include +#include namespace Modelica { namespace Parser { diff --git a/parser/ident.h b/parser/ident.hpp similarity index 97% rename from parser/ident.h rename to parser/ident.hpp index f1fb97b..7ac92bf 100644 --- a/parser/ident.h +++ b/parser/ident.hpp @@ -20,7 +20,7 @@ #ifndef IDENT_PARSER #define IDENT_PARSER #include -#include +#include namespace qi = boost::spirit::qi; using namespace Modelica::AST; namespace Modelica { diff --git a/parser/ident_def.h b/parser/ident_def.hpp similarity index 100% rename from parser/ident_def.h rename to parser/ident_def.hpp diff --git a/parser/main.cpp b/parser/main.cpp index 72e3f90..4c69ba4 100644 --- a/parser/main.cpp +++ b/parser/main.cpp @@ -19,28 +19,29 @@ #include #include -#include +#include -#include -#include -#include +#include +#include +#include -int main(int argc, char** argv){ +int main(int argc, char** argv) +{ using namespace std; using namespace Modelica::AST; using namespace Modelica; using namespace boost; bool ret; - char *out = NULL; + char* out = NULL; char opt; std::ofstream outputFile; - while ((opt = getopt(argc, argv, "o:")) != -1){ - switch (opt){ - case 'o': - out = optarg; - break; + while ((opt = getopt(argc, argv, "o:")) != -1) { + switch (opt) { + case 'o': + out = optarg; + break; } } @@ -50,15 +51,18 @@ int main(int argc, char** argv){ else sd = Parser::ParseFile("", ret); - if(ret){ - if(out) std::cout << sd << std::endl; + if (ret) { + if (out) + std::cout << sd << std::endl; - else std::cout << sd << std::endl; + else + std::cout << sd << std::endl; } - else std::cout << "Error parser" << std::endl; - - if(out) return 0; + else + std::cout << "Error parser" << std::endl; + + if (out) return 0; return 0; } diff --git a/parser/modification.cpp b/parser/modification.cpp index 78bf1aa..52ec13c 100644 --- a/parser/modification.cpp +++ b/parser/modification.cpp @@ -17,8 +17,8 @@ ******************************************************************************/ -#include -#include +#include +#include namespace Modelica { namespace Parser { diff --git a/parser/modification.h b/parser/modification.hpp similarity index 96% rename from parser/modification.h rename to parser/modification.hpp index 5da0d63..5d0775b 100644 --- a/parser/modification.h +++ b/parser/modification.hpp @@ -21,10 +21,10 @@ #define MODIFICATION_PARSER #include -#include -#include -#include -#include +#include +#include +#include +#include namespace qi = boost::spirit::qi; using namespace Modelica::AST; diff --git a/parser/modification_def.h b/parser/modification_def.hpp similarity index 100% rename from parser/modification_def.h rename to parser/modification_def.hpp diff --git a/parser/parser.cpp b/parser/parser.cpp index 8076e1f..8b53501 100644 --- a/parser/parser.cpp +++ b/parser/parser.cpp @@ -23,10 +23,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include using namespace std; namespace Modelica { diff --git a/parser/parser.h b/parser/parser.hpp similarity index 97% rename from parser/parser.h rename to parser/parser.hpp index 4897e22..daf2efd 100644 --- a/parser/parser.h +++ b/parser/parser.hpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include -#include +#include namespace Modelica { namespace Parser { diff --git a/parser/skipper.h b/parser/skipper.hpp similarity index 100% rename from parser/skipper.h rename to parser/skipper.hpp diff --git a/parser/statement.cpp b/parser/statement.cpp index 6fdfdaa..ed6f46a 100644 --- a/parser/statement.cpp +++ b/parser/statement.cpp @@ -17,8 +17,8 @@ ******************************************************************************/ -#include -#include +#include +#include namespace Modelica { namespace Parser { diff --git a/parser/statement.h b/parser/statement.hpp similarity index 95% rename from parser/statement.h rename to parser/statement.hpp index ea95f5f..c9068aa 100644 --- a/parser/statement.h +++ b/parser/statement.hpp @@ -21,9 +21,9 @@ #define STATEMENT_PARSER #include -#include -#include -#include +#include +#include +#include namespace qi = boost::spirit::qi; using namespace Modelica::AST; diff --git a/parser/statement_def.h b/parser/statement_def.hpp similarity index 100% rename from parser/statement_def.h rename to parser/statement_def.hpp diff --git a/test/causalize/apply_tarjan_test.cpp b/test/causalize/apply_tarjan_test.cpp index c2ff17a..6854727 100644 --- a/test/causalize/apply_tarjan_test.cpp +++ b/test/causalize/apply_tarjan_test.cpp @@ -1,9 +1,9 @@ #include #include -#include +#include -#include +#include using namespace boost::unit_test; diff --git a/test/causalize/causalization_strategy_test.cpp b/test/causalize/causalization_strategy_test.cpp index 4eb812d..19cf12b 100644 --- a/test/causalize/causalization_strategy_test.cpp +++ b/test/causalize/causalization_strategy_test.cpp @@ -2,21 +2,21 @@ #include <<<<<<< HEAD -#include -#include +#include +#include ======= -#include -#include -#include +#include +#include +#include >>>>>>> origin/experimental_multidim_intentional_causalization -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include @@ -29,256 +29,256 @@ void check_causality(MMO_Class& mmoClass, ExpList unknowns) { const EquationList& causalEqs = mmoClass.equations_ref().equations_ref(); ======= -void check_causality(MMO_Class &mmo_class, ExpList unknowns) { - +void check_causality(MMO_Class &mmo_class, ExpList unknowns) +{ const EquationList &causalEqs = mmo_class.equations_ref().equations_ref(); >>>>>>> origin/experimental_multidim_intentional_causalization - foreach_(Equation equation, causalEqs) { - -<<<<<<< HEAD foreach_(Equation equation, causalEqs) { - Equality eqEq = boost::get(equation); - Expression leftExpression = eqEq.left_ref(); - - if (is(leftExpression)) { - knowns.push_back(leftExpression); - } else if (is(leftExpression)) { - Call call = boost::get(leftExpression); - if (call.name() == "der") knowns.push_back(leftExpression); - } else if (is(leftExpression)) { - Output output = boost::get(leftExpression); - foreach_(OptExp oe, output.args()) - { - if (oe) knowns.push_back(oe.get()); -======= - ContainsUnknown occurrs(unknowns, mmo_class.syms()); - ERROR_UNLESS(is(equation),"Must be only equality equations here"); - Equality eqEq = boost::get(equation); - Apply(occurrs, eqEq.right_ref()); - if (occurrs.getUsages().size()!=0) { - ERROR("Using no causalized unknown"); ->>>>>>> origin/experimental_multidim_intentional_causalization - } <<<<<<< HEAD - foreach_(Expression unknown, unknowns) + foreach_(Equation equation, causalEqs) { - Modelica::contains occurrs(unknown); - if (Apply(occurrs, eqEq.right_ref())) { - bool isKnown = false; - foreach_(Expression known, knowns) + Equality eqEq = boost::get(equation); + Expression leftExpression = eqEq.left_ref(); + + if (is(leftExpression)) { + knowns.push_back(leftExpression); + } else if (is(leftExpression)) { + Call call = boost::get(leftExpression); + if (call.name() == "der") knowns.push_back(leftExpression); + } else if (is(leftExpression)) { + Output output = boost::get(leftExpression); + foreach_(OptExp oe, output.args()) { - if (known == unknown) { - isKnown = true; - } - } - BOOST_CHECK(isKnown); + if (oe) knowns.push_back(oe.get()); ======= - ExpList::iterator known = std::find(unknowns.begin(), unknowns.end(), eqEq.left_ref()); - if (known!=unknowns.end()) { - unknowns.erase(known); - } else { - ERROR("Causalizing unknown already causalized"); + ContainsUnknown occurrs(unknowns, mmo_class.syms()); + ERROR_UNLESS(is(equation), "Must be only equality equations here"); + Equality eqEq = boost::get(equation); + Apply(occurrs, eqEq.right_ref()); + if (occurrs.getUsages().size() != 0) { + ERROR("Using no causalized unknown"); >>>>>>> origin/experimental_multidim_intentional_causalization - } + } - } <<<<<<< HEAD - } + foreach_(Expression unknown, unknowns) + { + Modelica::contains occurrs(unknown); + if (Apply(occurrs, eqEq.right_ref())) { + bool isKnown = false; + foreach_(Expression known, knowns) + { + if (known == unknown) { + isKnown = true; + } + } + BOOST_CHECK(isKnown); ======= - - if (unknowns.size()!=0) { - ERROR("Uncausalized unknowns"); + ExpList::iterator known = std::find(unknowns.begin(), unknowns.end(), eqEq.left_ref()); + if (known != unknowns.end()) { + unknowns.erase(known); } else { - std::cout << "Model causalized correctly\n"; - } + ERROR("Causalizing unknown already causalized"); +>>>>>>> origin/experimental_multidim_intentional_causalization + } + } +<<<<<<< HEAD + } +======= + + if (unknowns.size() != 0) { + ERROR("Uncausalized unknowns"); + } else { + std::cout << "Model causalized correctly\n"; + } >>>>>>> origin/experimental_multidim_intentional_causalization -} + } -void rlc_test() -{ - bool r; + void rlc_test() + { + bool r; <<<<<<< HEAD - StoredDef sd = parseFile("rlc.mo", r); + StoredDef sd = parseFile("rlc.mo", r); ======= - StoredDef sd = Parser::ParseFile("rlc.mo",r); + StoredDef sd = Parser::ParseFile("rlc.mo", r); >>>>>>> origin/experimental_multidim_intentional_causalization - if (!r) ERROR("Can't parse file\n"); + if (!r) ERROR("Can't parse file\n"); - Class ast_c = boost::get(sd.classes().front()); - MMO_Class mmo(ast_c); + Class ast_c = boost::get(sd.classes().front()); + MMO_Class mmo(ast_c); - UnknownsCollector collector(mmo); - ExpList unknowns = collector.collectUnknowns(); + UnknownsCollector collector(mmo); + ExpList unknowns = collector.collectUnknowns(); - Causalize::CausalizationStrategy cStrategy(mmo); - cStrategy.Causalize(); + Causalize::CausalizationStrategy cStrategy(mmo); + cStrategy.Causalize(); - check_causality(mmo, unknowns); -} + check_causality(mmo, unknowns); + } -void rlc_simple_test() -{ - bool r; + void rlc_simple_test() + { + bool r; <<<<<<< HEAD - StoredDef sd = parseFile("rlc.mo", r); + StoredDef sd = parseFile("rlc.mo", r); ======= - StoredDef sd = Parser::ParseFile("rlc.mo",r); + StoredDef sd = Parser::ParseFile("rlc.mo", r); >>>>>>> origin/experimental_multidim_intentional_causalization - if (!r) ERROR("Can't parse file\n"); + if (!r) ERROR("Can't parse file\n"); - Class ast_c = boost::get(sd.classes().front()); - MMO_Class mmo(ast_c); + Class ast_c = boost::get(sd.classes().front()); + MMO_Class mmo(ast_c); - UnknownsCollector collector(mmo); - ExpList unknowns = collector.collectUnknowns(); + UnknownsCollector collector(mmo); + ExpList unknowns = collector.collectUnknowns(); - Causalize::CausalizationStrategy cStrategy(mmo); - cStrategy.CausalizeSimple(); + Causalize::CausalizationStrategy cStrategy(mmo); + cStrategy.CausalizeSimple(); - check_causality(mmo, unknowns); -} + check_causality(mmo, unknowns); + } -void rlc_loop_test() -{ - bool r; + void rlc_loop_test() + { + bool r; <<<<<<< HEAD - StoredDef sd = parseFile("rlc_loop.mo", r); + StoredDef sd = parseFile("rlc_loop.mo", r); ======= - StoredDef sd = Parser::ParseFile("rlc_loop.mo",r); + StoredDef sd = Parser::ParseFile("rlc_loop.mo", r); >>>>>>> origin/experimental_multidim_intentional_causalization - if (!r) ERROR("Can't parse file\n"); + if (!r) ERROR("Can't parse file\n"); - Class ast_c = boost::get(sd.classes().front()); - MMO_Class mmo(ast_c); + Class ast_c = boost::get(sd.classes().front()); + MMO_Class mmo(ast_c); - UnknownsCollector collector(mmo); - ExpList unknowns = collector.collectUnknowns(); + UnknownsCollector collector(mmo); + ExpList unknowns = collector.collectUnknowns(); - Causalize::CausalizationStrategy cStrategy(mmo); - cStrategy.Causalize(); + Causalize::CausalizationStrategy cStrategy(mmo); + cStrategy.Causalize(); - check_causality(mmo, unknowns); -} + check_causality(mmo, unknowns); + } -void rlc_loop_tarjan_test() -{ - bool r; + void rlc_loop_tarjan_test() + { + bool r; <<<<<<< HEAD - StoredDef sd = parseFile("rlc_loop.mo", r); + StoredDef sd = parseFile("rlc_loop.mo", r); ======= - StoredDef sd = Parser::ParseFile("rlc_loop.mo",r); + StoredDef sd = Parser::ParseFile("rlc_loop.mo", r); >>>>>>> origin/experimental_multidim_intentional_causalization - if (!r) ERROR("Can't parse file\n"); + if (!r) ERROR("Can't parse file\n"); - Class ast_c = boost::get(sd.classes().front()); - MMO_Class mmo(ast_c); + Class ast_c = boost::get(sd.classes().front()); + MMO_Class mmo(ast_c); - UnknownsCollector collector(mmo); - ExpList unknowns = collector.collectUnknowns(); + UnknownsCollector collector(mmo); + ExpList unknowns = collector.collectUnknowns(); - Causalize::CausalizationStrategy cStrategy(mmo); - cStrategy.CausalizeTarjan(); + Causalize::CausalizationStrategy cStrategy(mmo); + cStrategy.CausalizeTarjan(); - check_causality(mmo, unknowns); -} + check_causality(mmo, unknowns); + } -void OneDHeatTransferTI_FD_test() -{ - bool r; + void OneDHeatTransferTI_FD_test() + { + bool r; <<<<<<< HEAD - StoredDef sd = parseFile("OneDHeatTransferTI_FD_100.mo", r); + StoredDef sd = parseFile("OneDHeatTransferTI_FD_100.mo", r); ======= - StoredDef sd = Parser::ParseFile("OneDHeatTransferTI_FD_100.mo",r); + StoredDef sd = Parser::ParseFile("OneDHeatTransferTI_FD_100.mo", r); >>>>>>> origin/experimental_multidim_intentional_causalization - if (!r) ERROR("Can't parse file\n"); + if (!r) ERROR("Can't parse file\n"); - Class ast_c = boost::get(sd.classes().front()); - MMO_Class mmo(ast_c); + Class ast_c = boost::get(sd.classes().front()); + MMO_Class mmo(ast_c); - UnknownsCollector collector(mmo); - ExpList unknowns = collector.collectUnknowns(); + UnknownsCollector collector(mmo); + ExpList unknowns = collector.collectUnknowns(); - Causalize::CausalizationStrategy cStrategy(mmo); - cStrategy.Causalize(); + Causalize::CausalizationStrategy cStrategy(mmo); + cStrategy.Causalize(); - check_causality(mmo, unknowns); -} + check_causality(mmo, unknowns); + } -void OneDHeatTransferTI_FD_simple_test() -{ - bool r; + void OneDHeatTransferTI_FD_simple_test() + { + bool r; <<<<<<< HEAD - StoredDef sd = parseFile("OneDHeatTransferTI_FD.mo", r); + StoredDef sd = parseFile("OneDHeatTransferTI_FD.mo", r); ======= - StoredDef sd = Parser::ParseFile("OneDHeatTransferTI_FD.mo",r); + StoredDef sd = Parser::ParseFile("OneDHeatTransferTI_FD.mo", r); >>>>>>> origin/experimental_multidim_intentional_causalization - if (!r) ERROR("Can't parse file\n"); + if (!r) ERROR("Can't parse file\n"); - Class ast_c = boost::get(sd.classes().front()); - MMO_Class mmo(ast_c); + Class ast_c = boost::get(sd.classes().front()); + MMO_Class mmo(ast_c); - UnknownsCollector collector(mmo); - ExpList unknowns = collector.collectUnknowns(); + UnknownsCollector collector(mmo); + ExpList unknowns = collector.collectUnknowns(); - Causalize::CausalizationStrategy cStrategy(mmo); - cStrategy.CausalizeSimple(); + Causalize::CausalizationStrategy cStrategy(mmo); + cStrategy.CausalizeSimple(); - check_causality(mmo, unknowns); -} + check_causality(mmo, unknowns); + } -// TODO fix the check_causality method -// void OneDHeatTransferTI_FD_loop_test() { + // TODO fix the check_causality method + // void OneDHeatTransferTI_FD_loop_test() { -// bool r; + // bool r; -// StoredDef sd = parseFile("OneDHeatTransferTI_FD_loop_100.mo",r); + // StoredDef sd = parseFile("OneDHeatTransferTI_FD_loop_100.mo",r); -// if (!r) -// ERROR("Can't parse file\n"); + // if (!r) + // ERROR("Can't parse file\n"); -// Class ast_c = boost::get(sd.classes().front()); -// MMO_Class mmo(ast_c); + // Class ast_c = boost::get(sd.classes().front()); + // MMO_Class mmo(ast_c); -// UnknownsCollector collector(mmo); -// ExpList unknowns = collector.collectUnknowns(); + // UnknownsCollector collector(mmo); + // ExpList unknowns = collector.collectUnknowns(); -// CausalizationStrategy cStrategy(mmo); -// cStrategy.causalize("Anything"); + // CausalizationStrategy cStrategy(mmo); + // cStrategy.causalize("Anything"); -// check_causality(mmo, unknowns); + // check_causality(mmo, unknowns); -// } + // } -test_suite* init_unit_test_suite(int, char*[]) -{ - debugInit("p"); + test_suite* init_unit_test_suite(int, char*[]) + { + debugInit("p"); - framework::master_test_suite().p_name.value = "Causalization Strategy Test"; + framework::master_test_suite().p_name.value = "Causalization Strategy Test"; - framework::master_test_suite().add(BOOST_TEST_CASE(&rlc_test)); - framework::master_test_suite().add(BOOST_TEST_CASE(&rlc_simple_test)); - framework::master_test_suite().add(BOOST_TEST_CASE(&rlc_loop_test)); - framework::master_test_suite().add(BOOST_TEST_CASE(&rlc_loop_tarjan_test)); - framework::master_test_suite().add(BOOST_TEST_CASE(&OneDHeatTransferTI_FD_test)); - framework::master_test_suite().add(BOOST_TEST_CASE(&OneDHeatTransferTI_FD_simple_test)); - // TODO fix the check_causality method - // framework::master_test_suite().add( BOOST_TEST_CASE( &OneDHeatTransferTI_FD_loop_test) ); + framework::master_test_suite().add(BOOST_TEST_CASE(&rlc_test)); + framework::master_test_suite().add(BOOST_TEST_CASE(&rlc_simple_test)); + framework::master_test_suite().add(BOOST_TEST_CASE(&rlc_loop_test)); + framework::master_test_suite().add(BOOST_TEST_CASE(&rlc_loop_tarjan_test)); + framework::master_test_suite().add(BOOST_TEST_CASE(&OneDHeatTransferTI_FD_test)); + framework::master_test_suite().add(BOOST_TEST_CASE(&OneDHeatTransferTI_FD_simple_test)); + // TODO fix the check_causality method + // framework::master_test_suite().add( BOOST_TEST_CASE( &OneDHeatTransferTI_FD_loop_test) ); - return 0; -} + return 0; + } diff --git a/test/causalize/for_unrolling/process_for_equations_test.cpp b/test/causalize/for_unrolling/process_for_equations_test.cpp index e04fd28..9599181 100644 --- a/test/causalize/for_unrolling/process_for_equations_test.cpp +++ b/test/causalize/for_unrolling/process_for_equations_test.cpp @@ -3,12 +3,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/test/causalize/performance_test.cpp b/test/causalize/performance_test.cpp index b6d7b34..4d3e452 100644 --- a/test/causalize/performance_test.cpp +++ b/test/causalize/performance_test.cpp @@ -1,18 +1,18 @@ -#include -#include +#include +#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include +#include +#include using namespace Modelica::AST; diff --git a/test/parse/print_parse.cpp b/test/parse/print_parse.cpp index baa8781..f785544 100644 --- a/test/parse/print_parse.cpp +++ b/test/parse/print_parse.cpp @@ -13,22 +13,23 @@ ******************************************************************************/ /*! \file test_parse.cpp -* Current support is for Linux filesystem. -*/ + * Current support is for Linux filesystem. + */ #include #include -#include +#include using namespace boost::filesystem; using namespace std; -int main(){ - path test_path("../mccprograms"); +int main() +{ + path test_path("../mccprograms"); - for(directory_entry &x : directory_iterator(test_path)){ + for (directory_entry &x : directory_iterator(test_path)) { bool ret = false; bool &ref = ret; diff --git a/test/util/EvalExpTest.cpp b/test/util/EvalExpTest.cpp index a7dd41b..7facbb3 100644 --- a/test/util/EvalExpTest.cpp +++ b/test/util/EvalExpTest.cpp @@ -3,9 +3,9 @@ #include #include -#include -#include -#include +#include +#include +#include using namespace boost::unit_test; diff --git a/util/ast_visitors/all_expressions.cpp b/util/ast_visitors/all_expressions.cpp index a777053..7310972 100644 --- a/util/ast_visitors/all_expressions.cpp +++ b/util/ast_visitors/all_expressions.cpp @@ -17,9 +17,9 @@ ******************************************************************************/ -#include -#include -#include +#include +#include +#include #include namespace Modelica { diff --git a/util/ast_visitors/all_expressions.h b/util/ast_visitors/all_expressions.hpp similarity index 97% rename from util/ast_visitors/all_expressions.h rename to util/ast_visitors/all_expressions.hpp index c756bc5..cba5c58 100644 --- a/util/ast_visitors/all_expressions.h +++ b/util/ast_visitors/all_expressions.hpp @@ -20,8 +20,8 @@ #ifndef AST_VISITOR_ALL #define AST_VISITOR_ALL #include -#include -#include +#include +#include namespace Modelica { typedef std::list Lexp; diff --git a/util/ast_visitors/constant_expression.cpp b/util/ast_visitors/constant_expression.cpp index ab55f64..a5ce45d 100644 --- a/util/ast_visitors/constant_expression.cpp +++ b/util/ast_visitors/constant_expression.cpp @@ -17,19 +17,19 @@ ******************************************************************************/ -#include +#include -#include +#include namespace Modelica { -ConstantExpression::ConstantExpression(VarSymbolTable& symbols) : _symbols(symbols) {}; +ConstantExpression::ConstantExpression(VarSymbolTable& symbols) : _symbols(symbols){}; bool ConstantExpression::operator()(Integer v) const { return true; } bool ConstantExpression::operator()(Boolean v) const { return true; } -bool ConstantExpression::operator()(AddAll v) const {return false;} +bool ConstantExpression::operator()(AddAll v) const { return false; } bool ConstantExpression::operator()(String v) const { return true; } @@ -126,7 +126,7 @@ bool ConstantExpression::operator()(Output v) const } bool ConstantExpression::operator()(Reference v) const -{ +{ std::string var_name = get<0>(v.ref().front()); return isConstantNoCheck(var_name, _symbols); } diff --git a/util/ast_visitors/constant_expression.h b/util/ast_visitors/constant_expression.hpp similarity index 97% rename from util/ast_visitors/constant_expression.h rename to util/ast_visitors/constant_expression.hpp index 0433f2c..8a96c58 100644 --- a/util/ast_visitors/constant_expression.h +++ b/util/ast_visitors/constant_expression.hpp @@ -22,8 +22,8 @@ #include -#include -#include +#include +#include namespace Modelica { diff --git a/util/ast_visitors/contains_expression.cpp b/util/ast_visitors/contains_expression.cpp index 0ce04e7..6a9dfb3 100644 --- a/util/ast_visitors/contains_expression.cpp +++ b/util/ast_visitors/contains_expression.cpp @@ -17,8 +17,8 @@ ******************************************************************************/ -#include -#include +#include +#include #include namespace Modelica { diff --git a/util/ast_visitors/contains_expression.h b/util/ast_visitors/contains_expression.hpp similarity index 98% rename from util/ast_visitors/contains_expression.h rename to util/ast_visitors/contains_expression.hpp index fea4c02..5a9aadb 100644 --- a/util/ast_visitors/contains_expression.h +++ b/util/ast_visitors/contains_expression.hpp @@ -19,8 +19,10 @@ #ifndef AST_VISITOR_CONTAINS #define AST_VISITOR_CONTAINS + #include -#include + +#include namespace Modelica { diff --git a/util/ast_visitors/contains_expression_flatter.cpp b/util/ast_visitors/contains_expression_flatter.cpp index d33f237..1b2904b 100644 --- a/util/ast_visitors/contains_expression_flatter.cpp +++ b/util/ast_visitors/contains_expression_flatter.cpp @@ -17,8 +17,8 @@ ******************************************************************************/ -#include -#include +#include +#include #include namespace Modelica { @@ -132,8 +132,10 @@ bool ContainsExpressionFlatter::operator()(Reference v) const if (get<0>(v.ref().front()) == get<0>(ref.ref().front()) && get<1>(v.ref().front()).size() == 0) return true; // Check variable subscripts - foreach_ (RefTuple r, v.ref()) { - foreach_ (Expression e, get<1>(r)) { + foreach_(RefTuple r, v.ref()) + { + foreach_(Expression e, get<1>(r)) + { if (ApplyThis(e)) { return true; } diff --git a/util/ast_visitors/contains_expression_flatter.h b/util/ast_visitors/contains_expression_flatter.hpp similarity index 98% rename from util/ast_visitors/contains_expression_flatter.h rename to util/ast_visitors/contains_expression_flatter.hpp index 45cf53b..590d689 100644 --- a/util/ast_visitors/contains_expression_flatter.h +++ b/util/ast_visitors/contains_expression_flatter.hpp @@ -20,7 +20,7 @@ #pragma once #include -#include +#include namespace Modelica { diff --git a/util/ast_visitors/contains_unknown.cpp b/util/ast_visitors/contains_unknown.cpp index dea7b3e..92d61e1 100644 --- a/util/ast_visitors/contains_unknown.cpp +++ b/util/ast_visitors/contains_unknown.cpp @@ -17,29 +17,27 @@ ******************************************************************************/ -#include -#include +#include +#include #include -#include -#include -#include +#include +#include +#include using namespace boost; using namespace Modelica; -using namespace Modelica::AST ; +using namespace Modelica::AST; -ContainsUnknown::ContainsUnknown(std::vector unks, const VarSymbolTable &s): syms(s){ - int i=0; - for (Expression e: unks) { +ContainsUnknown::ContainsUnknown(std::vector unks, const VarSymbolTable &s) : syms(s) +{ + int i = 0; + for (Expression e : unks) { std::stringstream ss; ss << e; - definedUnks.insert(make_pair(ss.str(),i++)); + definedUnks.insert(make_pair(ss.str(), i++)); } - -} -void ContainsUnknown::clear() { - usedUnks.clear(); } +void ContainsUnknown::clear() { usedUnks.clear(); } bool ContainsUnknown::operator()(Modelica::AST::Integer v) const { return false; } @@ -57,58 +55,64 @@ bool ContainsUnknown::operator()(SubEnd v) const { return false; } bool ContainsUnknown::operator()(SubAll v) const { return false; } -bool ContainsUnknown::operator()(BinOp v) const { - Expression l=v.left(), r=v.right(); +bool ContainsUnknown::operator()(BinOp v) const +{ + Expression l = v.left(), r = v.right(); bool rl = ApplyThis(l); bool rr = ApplyThis(r); return rr || rl; } -bool ContainsUnknown::operator()(UnaryOp v) const { - Expression e=v.exp(); +bool ContainsUnknown::operator()(UnaryOp v) const +{ + Expression e = v.exp(); return ApplyThis(e); } -bool ContainsUnknown::operator()(IfExp v) const { - Expression cond=v.cond(), then=v.then(), elseexp=v.elseexp(); +bool ContainsUnknown::operator()(IfExp v) const +{ + Expression cond = v.cond(), then = v.then(), elseexp = v.elseexp(); const bool rc = ApplyThis(cond); const bool rt = ApplyThis(then); const bool re = ApplyThis(elseexp); return rc || rt || re; } -bool ContainsUnknown::operator()(Range v) const { - Expression start=v.start(), end=v.end(); +bool ContainsUnknown::operator()(Range v) const +{ + Expression start = v.start(), end = v.end(); bool rs = ApplyThis(start); bool re = ApplyThis(end); return rs || re; } -bool ContainsUnknown::operator()(Brace v) const { +bool ContainsUnknown::operator()(Brace v) const +{ bool ret = false; - for (Expression exp: v.args()) { + for (Expression exp : v.args()) { bool b = ApplyThis(exp); ret |= b; } return ret; } -bool ContainsUnknown::operator()(Bracket v) const { +bool ContainsUnknown::operator()(Bracket v) const +{ bool ret = false; - for (auto &list: v.args()) { - for (Expression exp: list) { - bool b = ApplyThis(exp); - ret |= b; - } + for (auto &list : v.args()) { + for (Expression exp : list) { + bool b = ApplyThis(exp); + ret |= b; + } } return ret; -} // TODO: Warning! Modificado para que compile. +} // TODO: Warning! Modificado para que compile. -bool ContainsUnknown::operator()(Call call) const { - if ("der"!=call.name()) - return false; +bool ContainsUnknown::operator()(Call call) const +{ + if ("der" != call.name()) return false; int usage = IsUsed(call); - if (usage!=-1) { + if (usage != -1) { usedUnks.insert(usage); return true; } else { @@ -116,30 +120,34 @@ bool ContainsUnknown::operator()(Call call) const { } } -bool ContainsUnknown::operator()(FunctionExp v) const { +bool ContainsUnknown::operator()(FunctionExp v) const +{ bool ret = false; - for (Expression exp: v.args()) { + for (Expression exp : v.args()) { bool b = ApplyThis(exp); ret |= b; } return ret; } -bool ContainsUnknown::operator()(ForExp v) const { +bool ContainsUnknown::operator()(ForExp v) const +{ Expression exp = v.exp(); bool ret = ApplyThis(exp); return ret; } -bool ContainsUnknown::operator()(Named v) const { +bool ContainsUnknown::operator()(Named v) const +{ Expression exp = v.exp(); bool ret = ApplyThis(exp); return ret; } -bool ContainsUnknown::operator()(Output v) const { +bool ContainsUnknown::operator()(Output v) const +{ bool ret = false; - for (Option exp: v.args()) { + for (Option exp : v.args()) { if (exp) { bool b = ApplyThis(exp.get()); ret |= b; @@ -148,10 +156,10 @@ bool ContainsUnknown::operator()(Output v) const { return ret; } - -bool ContainsUnknown::operator()(Reference ref) const { +bool ContainsUnknown::operator()(Reference ref) const +{ int usage = IsUsed(ref); - if (usage!=-1) { + if (usage != -1) { usedUnks.insert(usage); return true; } else { @@ -159,21 +167,15 @@ bool ContainsUnknown::operator()(Reference ref) const { } } -std::set ContainsUnknown::getUsages() const { - return usedUnks; -} +std::set ContainsUnknown::getUsages() const { return usedUnks; } -int ContainsUnknown::IsUsed(Expression e) const { +int ContainsUnknown::IsUsed(Expression e) const +{ std::stringstream ss; ss << e; try { return definedUnks.at(ss.str()); - } catch (const std::out_of_range& oor) { + } catch (const std::out_of_range &oor) { return -1; } } - - - - - diff --git a/util/ast_visitors/contains_unknown.h b/util/ast_visitors/contains_unknown.hpp similarity index 95% rename from util/ast_visitors/contains_unknown.h rename to util/ast_visitors/contains_unknown.hpp index 40b3b4d..babb0f7 100644 --- a/util/ast_visitors/contains_unknown.h +++ b/util/ast_visitors/contains_unknown.hpp @@ -21,9 +21,9 @@ #define AST_VISITOR_CONTAINS_UNKNOWN #include -#include -#include -#include +#include +#include +#include #include using namespace Modelica; diff --git a/util/ast_visitors/contains_vector.cpp b/util/ast_visitors/contains_vector.cpp index b211e7c..532b006 100644 --- a/util/ast_visitors/contains_vector.cpp +++ b/util/ast_visitors/contains_vector.cpp @@ -17,269 +17,269 @@ ******************************************************************************/ -#include -#include +#include +#include #include -#include -#include +#include +#include #include -#include -#include +#include +#include using namespace Modelica; -using namespace Modelica::AST ; +using namespace Modelica::AST; namespace Causalize { - ContainsVector::ContainsVector(Expression e, VectorVertexProperty v, const VarSymbolTable &s): - exp(e), - unk2find(v), - syms(s), - foreq(false), - indexes() {}; - - /** - * Builds a ContainsVector class to find occurrences of the Expression 'e' - * using the table of symbols 's' and index list 'indexes' in 'for-equations'. - */ - ContainsVector::ContainsVector(VectorVertexProperty unk, VarSymbolTable &s, IndexList indexes): - exp(unk.unknown()), - unk2find(unk), - syms(s), - foreq(true), - indexes(indexes) { - EvalExpression ev(syms); - foreach_(Index i, indexes) { - if (!i.exp()) - ERROR("No index in for equation"); - ERROR_UNLESS(is(i.exp().get()), "Only range expressions supported"); - Range range = get(i.exp().get()); - forIndexIntervalList.push_back(Interval::closed(Apply(ev,range.start_ref()), Apply(ev,range.end_ref()))); - } - }; +ContainsVector::ContainsVector(Expression e, VectorVertexProperty v, const VarSymbolTable &s) + : exp(e), unk2find(v), syms(s), foreq(false), indexes(){}; + +/** + * Builds a ContainsVector class to find occurrences of the Expression 'e' + * using the table of symbols 's' and index list 'indexes' in 'for-equations'. + */ +ContainsVector::ContainsVector(VectorVertexProperty unk, VarSymbolTable &s, IndexList indexes) + : exp(unk.unknown()), unk2find(unk), syms(s), foreq(true), indexes(indexes) +{ + EvalExpression ev(syms); + foreach_(Index i, indexes) + { + if (!i.exp()) ERROR("No index in for equation"); + ERROR_UNLESS(is(i.exp().get()), "Only range expressions supported"); + Range range = get(i.exp().get()); + forIndexIntervalList.push_back(Interval::closed(Apply(ev, range.start_ref()), Apply(ev, range.end_ref()))); + } +}; - bool ContainsVector::operator()(Modelica::AST::Integer v) const { return exp==Expression(v); } +bool ContainsVector::operator()(Modelica::AST::Integer v) const { return exp == Expression(v); } - bool ContainsVector::operator()(AddAll v) const { return false; } +bool ContainsVector::operator()(AddAll v) const { return false; } - bool ContainsVector::operator()(Boolean v) const { return exp==Expression(v); } +bool ContainsVector::operator()(Boolean v) const { return exp == Expression(v); } - bool ContainsVector::operator()(String v) const { return exp==Expression(v); } +bool ContainsVector::operator()(String v) const { return exp == Expression(v); } - bool ContainsVector::operator()(Name v) const { return exp==Expression(v); } +bool ContainsVector::operator()(Name v) const { return exp == Expression(v); } - bool ContainsVector::operator()(Real v) const { return exp==Expression(v); } +bool ContainsVector::operator()(Real v) const { return exp == Expression(v); } - bool ContainsVector::operator()(SubEnd v) const { return exp==Expression(v); } +bool ContainsVector::operator()(SubEnd v) const { return exp == Expression(v); } - bool ContainsVector::operator()(SubAll v) const { return exp==Expression(v); } +bool ContainsVector::operator()(SubAll v) const { return exp == Expression(v); } - bool ContainsVector::operator()(BinOp v) const { - if (exp==Expression(v)) return true; - Expression l=v.left(), r=v.right(); - bool rl = ApplyThis(l); - bool rr = ApplyThis(r); - return rr || rl; - } +bool ContainsVector::operator()(BinOp v) const +{ + if (exp == Expression(v)) return true; + Expression l = v.left(), r = v.right(); + bool rl = ApplyThis(l); + bool rr = ApplyThis(r); + return rr || rl; +} - bool ContainsVector::operator()(UnaryOp v) const { - if (exp==Expression(v)) return true; - Expression e=v.exp(); - return ApplyThis(e); - } +bool ContainsVector::operator()(UnaryOp v) const +{ + if (exp == Expression(v)) return true; + Expression e = v.exp(); + return ApplyThis(e); +} - bool ContainsVector::operator()(IfExp v) const { - if (exp==Expression(v)) return true; - Expression cond=v.cond(), then=v.then(), elseexp=v.elseexp(); - const bool rc = ApplyThis(cond); - const bool rt = ApplyThis(then); - const bool re = ApplyThis(elseexp); - return rc || rt || re; - } +bool ContainsVector::operator()(IfExp v) const +{ + if (exp == Expression(v)) return true; + Expression cond = v.cond(), then = v.then(), elseexp = v.elseexp(); + const bool rc = ApplyThis(cond); + const bool rt = ApplyThis(then); + const bool re = ApplyThis(elseexp); + return rc || rt || re; +} - bool ContainsVector::operator()(Range v) const { - if (exp==Expression(v)) return true; - Expression start=v.start(), end=v.end(); - bool rs = ApplyThis(start); - bool re = ApplyThis(end); - return rs || re; - } +bool ContainsVector::operator()(Range v) const +{ + if (exp == Expression(v)) return true; + Expression start = v.start(), end = v.end(); + bool rs = ApplyThis(start); + bool re = ApplyThis(end); + return rs || re; +} - bool ContainsVector::operator()(Brace v) const { - if (exp==Expression(v)) return true; - return false; - } +bool ContainsVector::operator()(Brace v) const +{ + if (exp == Expression(v)) return true; + return false; +} - bool ContainsVector::operator()(Bracket v) const { - if (exp==Expression(v)) return true; - return false; - } +bool ContainsVector::operator()(Bracket v) const +{ + if (exp == Expression(v)) return true; + return false; +} - bool ContainsVector::operator()(Call call) const { - if (is(exp)) { //exp is a derivative expression - Call callExpr=get(exp); - if (call.name()=="der" && callExpr.name()=="der") { //call and exp are derivative expressions - ERROR_UNLESS(is(call.args().front()) && is(callExpr.args().front()), "Arguments to call must be a reference"); - Reference callRef=get(call.args().front()); - Reference callExprRef=get(callExpr.args().front()); - if (get<0>(callRef.ref().front())==get<0>(callExprRef.ref().front())) { //The references are the same - BuildPairs(callRef); - return true; - } - //The references are not the same - return false; - } - } else { //exp is not a derivative expression, find the occurrence of exp inside the call arguments - if (exp==Expression(call)) return true; - bool findOccur = false; - foreach_ (Expression e, call.args()) { - findOccur|=(ApplyThis(e)); +bool ContainsVector::operator()(Call call) const +{ + if (is(exp)) { // exp is a derivative expression + Call callExpr = get(exp); + if (call.name() == "der" && callExpr.name() == "der") { // call and exp are derivative expressions + ERROR_UNLESS(is(call.args().front()) && is(callExpr.args().front()), "Arguments to call must be a reference"); + Reference callRef = get(call.args().front()); + Reference callExprRef = get(callExpr.args().front()); + if (get<0>(callRef.ref().front()) == get<0>(callExprRef.ref().front())) { // The references are the same + BuildPairs(callRef); + return true; } - return findOccur; + // The references are not the same + return false; } - - return false; + } else { // exp is not a derivative expression, find the occurrence of exp inside the call arguments + if (exp == Expression(call)) return true; + bool findOccur = false; + foreach_(Expression e, call.args()) { findOccur |= (ApplyThis(e)); } + return findOccur; } - bool ContainsVector::operator()(FunctionExp v) const { - if (exp==Expression(v)) return true; - return false; - } + return false; +} - bool ContainsVector::operator()(ForExp v) const { - if (exp==Expression(v)) return true; - return false; - } +bool ContainsVector::operator()(FunctionExp v) const +{ + if (exp == Expression(v)) return true; + return false; +} - bool ContainsVector::operator()(Named v) const { - if (exp==Expression(v)) return true; - return false; - } +bool ContainsVector::operator()(ForExp v) const +{ + if (exp == Expression(v)) return true; + return false; +} - bool ContainsVector::operator()(Output v) const { - if (exp==Expression(v)) return true; - foreach_(OptExp oe, v.args()) - if (oe && ApplyThis(oe.get())) return true; - return false; - } +bool ContainsVector::operator()(Named v) const +{ + if (exp == Expression(v)) return true; + return false; +} +bool ContainsVector::operator()(Output v) const +{ + if (exp == Expression(v)) return true; + foreach_(OptExp oe, v.args()) if (oe && ApplyThis(oe.get())) return true; + return false; +} - bool ContainsVector::operator()(Reference ref) const { - if (is(exp)) { - if (get<0>(ref.ref().front())==get<0>(get(exp).ref().front())) { //The references are the same - BuildPairs(ref); - return true; - } +bool ContainsVector::operator()(Reference ref) const +{ + if (is(exp)) { + if (get<0>(ref.ref().front()) == get<0>(get(exp).ref().front())) { // The references are the same + BuildPairs(ref); + return true; } - return false; } + return false; +} - void ContainsVector::BuildPairs(Reference unkRef) const { - if (foreq) { //The equation is a for-equation - if (unk2find.unknown.dimension==0) { //the unknown is a scalar - Usage usage; - Offset offset; - labels.insert(IndexPair(MDI(forIndexIntervalList), MDI(0), offset, usage)); - } else { //the unknown is a vector - ERROR_UNLESS(unk2find.unknown.dimension==(int)get<1>(unkRef.ref().front()).size(), "Only complete usage of vectors are allowed"); - VarSymbolTable vst=syms; - std::vector iterator_names; - Usage usage_indexes; - foreach_(Index i, indexes) { - iterator_names.push_back(i.name()); - VarInfo vinfo = VarInfo(TypePrefixes(), "Integer", Option(), Modification()); - vst.insert(i.name(),vinfo); - } - IntervalList unk_indexes; - Expression unkRef_exp = unkRef; - Expression evaluated_expr=Apply(Modelica::PartialEvalExpression(vst),unkRef_exp); - ERROR_UNLESS(is(evaluated_expr), "Evaluated expression is not a reference"); - Reference r = get(evaluated_expr); - ExpList indexes_list = get<1>(r.ref().front()); - unsigned int total_index_uses = 0; - unsigned int index_count = 0; - std::vector offset_vector; - foreach_(Expression val,indexes_list) { - if (is(val)) { - int v = get(val); - unk_indexes.push_back(Interval::closed(v,v)); - usage_indexes.push_back(-1); - offset_vector.push_back(0); - } else if (is(val)) { - Reference ind_ref = get(val); - std::vector::iterator index_name = std::find(iterator_names.begin(), iterator_names.end(), get<0>(ind_ref.ref().front())); - ERROR_UNLESS(index_name!=iterator_names.end(), "Usage of variable in index expression not found"); - Index i = indexes.at(index_name-iterator_names.begin()); - if (!i.exp()) - ERROR("Implicit range not supported in for equations"); - ERROR_UNLESS(is(i.exp().get()), "Only range supported in for equations"); - Range range = get(i.exp().get()); - EvalExpression ev(syms); - int pos = index_name - iterator_names.begin(); - usage_indexes.push_back(pos); - unk_indexes.push_back(Interval::closed(Apply(ev,range.start_ref()), Apply(ev,range.end_ref()))); - total_index_uses++; - offset_vector.push_back(0); - } else if (is(val)) { - BinOp binop = get(Apply(Modelica::PartialEvalExpression(vst), val)); - ERROR_UNLESS(binop.op()==Add || - binop.op()==Sub , "Only addition and substraction are supported in indexes"); - ERROR_UNLESS(is(binop.left()),"Index must be of the form i+/-K where K is a constant"); - ERROR_UNLESS(is(binop.right()),"Index must be of the form i+/-K where K is a constant"); - int offset = get(binop.right()); - if (binop.op()==Sub) // Transform everything to an addition - offset *= -1; - Reference ind_ref = get(binop.left()); - std::vector::iterator index_name = std::find(iterator_names.begin(), iterator_names.end(), get<0>(ind_ref.ref().front())); - ERROR_UNLESS(index_name!=iterator_names.end(), "Usage of variable in index expression not found"); - Index i = indexes.at(index_name-iterator_names.begin()); - if (!i.exp()) - ERROR("Implicit range not supported in for equations"); - ERROR_UNLESS(is(i.exp().get()), "Only range supported in for equations"); - Range range = get(i.exp().get()); - EvalExpression ev(syms); - int pos = index_name - iterator_names.begin(); - offset_vector.push_back(offset); - usage_indexes.push_back(pos); - unk_indexes.push_back(Interval::closed(Apply(ev,range.start_ref())+offset, Apply(ev,range.end_ref())+offset)); - total_index_uses++; - } else { - ERROR("Index expression not supported"); - } - index_count++; - } - ERROR_UNLESS(total_index_uses == 0 || total_index_uses==forIndexIntervalList.size(), "The number of indexes does not match the number of uses"); - MDI mdi_eq(forIndexIntervalList), mdi_unk(unk_indexes); - ERROR_UNLESS( mdi_eq.Size() == mdi_unk.Size() - || mdi_eq.Size() == 1 - || mdi_unk.Size() == 1 - , "Edge of different size"); - labels.insert(IndexPair(mdi_eq, mdi_unk, Offset(offset_vector), usage_indexes)); +void ContainsVector::BuildPairs(Reference unkRef) const +{ + if (foreq) { // The equation is a for-equation + if (unk2find.unknown.dimension == 0) { // the unknown is a scalar + Usage usage; + Offset offset; + labels.insert(IndexPair(MDI(forIndexIntervalList), MDI(0), offset, usage)); + } else { // the unknown is a vector + ERROR_UNLESS(unk2find.unknown.dimension == (int)get<1>(unkRef.ref().front()).size(), "Only complete usage of vectors are allowed"); + VarSymbolTable vst = syms; + std::vector iterator_names; + Usage usage_indexes; + foreach_(Index i, indexes) + { + iterator_names.push_back(i.name()); + VarInfo vinfo = VarInfo(TypePrefixes(), "Integer", Option(), Modification()); + vst.insert(i.name(), vinfo); } - } else { //The equation is not a for-equation - if (unk2find.unknown.dimension==0) { //the unknown is a scalar - labels.insert(IndexPair(MDI(0), MDI(0), Offset(), Usage())); - } else { //the unknown is a vector - ERROR_UNLESS(unk2find.unknown.dimension==(int)get<1>(unkRef.ref().front()).size() || (int)get<1>(unkRef.ref().front()).size() ==0 , "Only complete usage of vectors are allowed"); - VarSymbolTable vst=syms; - Expression unkRef_exp = unkRef; - Expression evaluated_expr=Apply(Modelica::PartialEvalExpression(vst),unkRef_exp); - IntervalList unk_indexes; - ERROR_UNLESS(is(evaluated_expr), "Evaluated expression is not a reference"); - Reference r = get(evaluated_expr); - ExpList indexes = get<1>(r.ref().front()); - std::vector offset_vector(indexes.size(),0); - Usage usage_indexes(indexes.size(),-1); - foreach_(Expression val, indexes) { - ERROR_UNLESS(is(val), "Expression index could not be evaluated"); //TODO: See this error message + IntervalList unk_indexes; + Expression unkRef_exp = unkRef; + Expression evaluated_expr = Apply(Modelica::PartialEvalExpression(vst), unkRef_exp); + ERROR_UNLESS(is(evaluated_expr), "Evaluated expression is not a reference"); + Reference r = get(evaluated_expr); + ExpList indexes_list = get<1>(r.ref().front()); + unsigned int total_index_uses = 0; + unsigned int index_count = 0; + std::vector offset_vector; + foreach_(Expression val, indexes_list) + { + if (is(val)) { int v = get(val); - unk_indexes.push_back(Interval::closed(v,v)); + unk_indexes.push_back(Interval::closed(v, v)); + usage_indexes.push_back(-1); + offset_vector.push_back(0); + } else if (is(val)) { + Reference ind_ref = get(val); + std::vector::iterator index_name = std::find(iterator_names.begin(), iterator_names.end(), get<0>(ind_ref.ref().front())); + ERROR_UNLESS(index_name != iterator_names.end(), "Usage of variable in index expression not found"); + Index i = indexes.at(index_name - iterator_names.begin()); + if (!i.exp()) ERROR("Implicit range not supported in for equations"); + ERROR_UNLESS(is(i.exp().get()), "Only range supported in for equations"); + Range range = get(i.exp().get()); + EvalExpression ev(syms); + int pos = index_name - iterator_names.begin(); + usage_indexes.push_back(pos); + unk_indexes.push_back(Interval::closed(Apply(ev, range.start_ref()), Apply(ev, range.end_ref()))); + total_index_uses++; + offset_vector.push_back(0); + } else if (is(val)) { + BinOp binop = get(Apply(Modelica::PartialEvalExpression(vst), val)); + ERROR_UNLESS(binop.op() == Add || binop.op() == Sub, "Only addition and substraction are supported in indexes"); + ERROR_UNLESS(is(binop.left()), "Index must be of the form i+/-K where K is a constant"); + ERROR_UNLESS(is(binop.right()), "Index must be of the form i+/-K where K is a constant"); + int offset = get(binop.right()); + if (binop.op() == Sub) // Transform everything to an addition + offset *= -1; + Reference ind_ref = get(binop.left()); + std::vector::iterator index_name = std::find(iterator_names.begin(), iterator_names.end(), get<0>(ind_ref.ref().front())); + ERROR_UNLESS(index_name != iterator_names.end(), "Usage of variable in index expression not found"); + Index i = indexes.at(index_name - iterator_names.begin()); + if (!i.exp()) ERROR("Implicit range not supported in for equations"); + ERROR_UNLESS(is(i.exp().get()), "Only range supported in for equations"); + Range range = get(i.exp().get()); + EvalExpression ev(syms); + int pos = index_name - iterator_names.begin(); + offset_vector.push_back(offset); + usage_indexes.push_back(pos); + unk_indexes.push_back(Interval::closed(Apply(ev, range.start_ref()) + offset, Apply(ev, range.end_ref()) + offset)); + total_index_uses++; + } else { + ERROR("Index expression not supported"); } - if (indexes.size()==0) // If no usage, use the whole array - for(int i : unk2find.unknown.dimensionList) - unk_indexes.push_back(Interval::closed(1,i)); - labels.insert(IndexPair(MDI(0), MDI(unk_indexes), Offset(offset_vector), usage_indexes)); + index_count++; } + ERROR_UNLESS(total_index_uses == 0 || total_index_uses == forIndexIntervalList.size(), + "The number of indexes does not match the number of uses"); + MDI mdi_eq(forIndexIntervalList), mdi_unk(unk_indexes); + ERROR_UNLESS(mdi_eq.Size() == mdi_unk.Size() || mdi_eq.Size() == 1 || mdi_unk.Size() == 1, "Edge of different size"); + labels.insert(IndexPair(mdi_eq, mdi_unk, Offset(offset_vector), usage_indexes)); + } + } else { // The equation is not a for-equation + if (unk2find.unknown.dimension == 0) { // the unknown is a scalar + labels.insert(IndexPair(MDI(0), MDI(0), Offset(), Usage())); + } else { // the unknown is a vector + ERROR_UNLESS(unk2find.unknown.dimension == (int)get<1>(unkRef.ref().front()).size() || (int)get<1>(unkRef.ref().front()).size() == 0, + "Only complete usage of vectors are allowed"); + VarSymbolTable vst = syms; + Expression unkRef_exp = unkRef; + Expression evaluated_expr = Apply(Modelica::PartialEvalExpression(vst), unkRef_exp); + IntervalList unk_indexes; + ERROR_UNLESS(is(evaluated_expr), "Evaluated expression is not a reference"); + Reference r = get(evaluated_expr); + ExpList indexes = get<1>(r.ref().front()); + std::vector offset_vector(indexes.size(), 0); + Usage usage_indexes(indexes.size(), -1); + foreach_(Expression val, indexes) + { + ERROR_UNLESS(is(val), "Expression index could not be evaluated"); // TODO: See this error message + int v = get(val); + unk_indexes.push_back(Interval::closed(v, v)); + } + if (indexes.size() == 0) // If no usage, use the whole array + for (int i : unk2find.unknown.dimensionList) unk_indexes.push_back(Interval::closed(1, i)); + labels.insert(IndexPair(MDI(0), MDI(unk_indexes), Offset(offset_vector), usage_indexes)); } } - } + +} // namespace Causalize diff --git a/util/ast_visitors/contains_vector.h b/util/ast_visitors/contains_vector.hpp similarity index 96% rename from util/ast_visitors/contains_vector.h rename to util/ast_visitors/contains_vector.hpp index f6f7a7f..623e7d3 100644 --- a/util/ast_visitors/contains_vector.h +++ b/util/ast_visitors/contains_vector.hpp @@ -19,10 +19,12 @@ #ifndef AST_VISITOR_CONTAINS_VECTOR #define AST_VISITOR_CONTAINS_VECTOR + #include -#include -#include -#include + +#include +#include +#include #include #include diff --git a/util/ast_visitors/dot_expression.cpp b/util/ast_visitors/dot_expression.cpp index 4e6b55c..d972b9f 100644 --- a/util/ast_visitors/dot_expression.cpp +++ b/util/ast_visitors/dot_expression.cpp @@ -17,9 +17,9 @@ ******************************************************************************/ -#include -#include -#include +#include +#include +#include namespace Modelica { @@ -29,14 +29,14 @@ DotExpression::DotExpression(Option m, Name n, ExpList xs) : _class }; Expression DotExpression::operator()(Integer v) const { return v; } Expression DotExpression::operator()(Boolean v) const { return v; } -Expression DotExpression::operator()(AddAll v) const{ - RefTuple rt = v.arr(); +Expression DotExpression::operator()(AddAll v) const +{ + RefTuple rt = v.arr(); Name name; ExpList indices; - if(syms) - if(syms.get()[get<0>(rt)]) - name = prefix + "_"; + if (syms) + if (syms.get()[get<0>(rt)]) name = prefix + "_"; name += get<0>(rt); indices += get<1>(rt); diff --git a/util/ast_visitors/dot_expression.h b/util/ast_visitors/dot_expression.hpp similarity index 94% rename from util/ast_visitors/dot_expression.h rename to util/ast_visitors/dot_expression.hpp index cb96276..27daba2 100644 --- a/util/ast_visitors/dot_expression.h +++ b/util/ast_visitors/dot_expression.hpp @@ -18,10 +18,11 @@ ******************************************************************************/ #include -#include -#include -#include -#include + +#include +#include +#include +#include #ifndef AST_VISITOR_DOTEXPRESSION #define AST_VISITOR_DOTEXPRESSION diff --git a/util/ast_visitors/equation_visitor.h b/util/ast_visitors/equation_visitor.hpp similarity index 99% rename from util/ast_visitors/equation_visitor.h rename to util/ast_visitors/equation_visitor.hpp index bfe49f9..fd11291 100644 --- a/util/ast_visitors/equation_visitor.h +++ b/util/ast_visitors/equation_visitor.hpp @@ -19,8 +19,10 @@ #ifndef AST_VISITOR_EQ #define AST_VISITOR_EQ + #include -#include + +#include #define applyExp(X) boost::apply_visitor(v, X) namespace Modelica { diff --git a/util/ast_visitors/eval_expression.cpp b/util/ast_visitors/eval_expression.cpp index 407a932..341532b 100644 --- a/util/ast_visitors/eval_expression.cpp +++ b/util/ast_visitors/eval_expression.cpp @@ -21,14 +21,15 @@ #include #include -#include +#include -#include -#include +#include +#include -namespace Modelica{ +namespace Modelica { -EvalExpression::EvalExpression(const VarSymbolTable &v) : vtable(v){ +EvalExpression::EvalExpression(const VarSymbolTable &v) : vtable(v) +{ Option nm; name = nm; Option r; @@ -37,67 +38,74 @@ EvalExpression::EvalExpression(const VarSymbolTable &v) : vtable(v){ EvalExpression::EvalExpression(const VarSymbolTable &v, Name n, Real r) : vtable(v), name(n), val(r){}; -Real EvalExpression::operator()(Integer v) const {return v;} +Real EvalExpression::operator()(Integer v) const { return v; } -Real EvalExpression::operator()(Boolean v) const{ - if (v.val()) - return 1.0; +Real EvalExpression::operator()(Boolean v) const +{ + if (v.val()) return 1.0; return 0.0; } -Real EvalExpression::operator()(AddAll v) const{ +Real EvalExpression::operator()(AddAll v) const +{ ERROR("EvalExpression: trying to evaluate a AddAll"); return 0; } -Real EvalExpression::operator()(String v) const{ +Real EvalExpression::operator()(String v) const +{ ERROR("EvalExpression: trying to evaluate a String"); return 0; } -Real EvalExpression::operator()(Name v) const{ +Real EvalExpression::operator()(Name v) const +{ ERROR("EvalExpression: trying to evaluate a Name"); return 0; } -Real EvalExpression::operator()(Real v) const {return v;} +Real EvalExpression::operator()(Real v) const { return v; } -Real EvalExpression::operator()(SubAll v) const{ +Real EvalExpression::operator()(SubAll v) const +{ ERROR("EvalExpression: trying to evaluate a SubAll"); return 0; } -Real EvalExpression::operator()(SubEnd v) const{ +Real EvalExpression::operator()(SubEnd v) const +{ ERROR("EvalExpression: trying to evaluate a SubEnd"); return 0; } -Real EvalExpression::operator()(BinOp v) const{ +Real EvalExpression::operator()(BinOp v) const +{ Expression l = v.left(), r = v.right(); - switch (v.op()){ - case Add: - return ApplyThis(l) + ApplyThis(r); - case Sub: - return ApplyThis(l) - ApplyThis(r); - case Div: - return ApplyThis(l) / ApplyThis(r); - case Mult: - return ApplyThis(l) * ApplyThis(r); - case Exp: - return pow(ApplyThis(l), ApplyThis(r)); - default: - ERROR("EvalExpression: BinOp %s not supported.", BinOpTypeName[v.op()]); - return 0; + switch (v.op()) { + case Add: + return ApplyThis(l) + ApplyThis(r); + case Sub: + return ApplyThis(l) - ApplyThis(r); + case Div: + return ApplyThis(l) / ApplyThis(r); + case Mult: + return ApplyThis(l) * ApplyThis(r); + case Exp: + return pow(ApplyThis(l), ApplyThis(r)); + default: + ERROR("EvalExpression: BinOp %s not supported.", BinOpTypeName[v.op()]); + return 0; } } -Real EvalExpression::operator()(UnaryOp v) const{ - if (v.op() == Minus){ +Real EvalExpression::operator()(UnaryOp v) const +{ + if (v.op() == Minus) { Expression e = v.exp(); return -ApplyThis(e); - } + } - else if (v.op() == Plus){ + else if (v.op() == Plus) { Expression e = v.exp(); return ApplyThis(e); } @@ -106,55 +114,62 @@ Real EvalExpression::operator()(UnaryOp v) const{ return 0; } -Real EvalExpression::operator()(IfExp v) const{ +Real EvalExpression::operator()(IfExp v) const +{ ERROR("EvalExpression: trying to evaluate a IfExp"); return 0; } -Real EvalExpression::operator()(Range v) const{ +Real EvalExpression::operator()(Range v) const +{ ERROR("EvalExpression: trying to evaluate a Range"); return 0; } -Real EvalExpression::operator()(Brace v) const{ +Real EvalExpression::operator()(Brace v) const +{ WARNING("EvalExpression: trying to evaluate a Brace"); return 0; } -Real EvalExpression::operator()(Bracket v) const{ +Real EvalExpression::operator()(Bracket v) const +{ ERROR("EvalExpression: trying to evaluate a Bracket"); return 0; } -Real EvalExpression::operator()(Call v) const{ - if ("integer" == v.name()) - return ApplyThis(v.args().front()); +Real EvalExpression::operator()(Call v) const +{ + if ("integer" == v.name()) return ApplyThis(v.args().front()); + + if ("exp" == v.name()) return exp(ApplyThis(v.args().front())); - if ("exp" == v.name()) - return exp(ApplyThis(v.args().front())); - ERROR("EvalExpression: trying to evaluate a Call"); return 0; } -Real EvalExpression::operator()(FunctionExp v) const{ +Real EvalExpression::operator()(FunctionExp v) const +{ ERROR("EvalExpression: trying to evaluate a FunctionExp"); return 0; } -Real EvalExpression::operator()(ForExp v) const{ +Real EvalExpression::operator()(ForExp v) const +{ ERROR("EvalExpression: trying to evaluate a ForExp"); return 0; } -Real EvalExpression::operator()(Named v) const{ +Real EvalExpression::operator()(Named v) const +{ ERROR("EvalExpression: trying to evaluate a Named"); return 0; } -Real EvalExpression::operator()(Output v) const{ +Real EvalExpression::operator()(Output v) const +{ ERROR_UNLESS(v.args().size() == 1, "EvalExpression: Output expression with more than one element are not supported"); - if (v.args().front()){ + if (v.args().front()) { Expression e = v.args().front().get(); return ApplyThis(e); } @@ -163,7 +178,8 @@ Real EvalExpression::operator()(Output v) const{ return 0; } -Real EvalExpression::operator()(Reference v) const{ +Real EvalExpression::operator()(Reference v) const +{ Ref r = v.ref(); ERROR_UNLESS(r.size() == 1, "EvalExpression: conversion of dotted references not implemented"); Option oel = boost::get<1>(r[0]); @@ -180,25 +196,25 @@ Real EvalExpression::operator()(Reference v) const{ Modification m = vinfo.get().modification().get(); - if (is(m)){ + if (is(m)) { Expression meq = boost::get(m).exp(); return ApplyThis(meq); } - if (is(m)){ + if (is(m)) { Expression meq = boost::get(m).exp(); return ApplyThis(meq); } - if (is(m)){ + if (is(m)) { OptExp oe = get(m).exp(); - if (oe) - return ApplyThis(oe.get()); + if (oe) return ApplyThis(oe.get()); - foreach_(Argument a, get(m).modification_ref()){ - if (is(a)){ + foreach_(Argument a, get(m).modification_ref()) + { + if (is(a)) { ElMod em = boost::get(a); - if (em.name() == "start" && (em.modification()) && is(em.modification_ref().get())){ + if (em.name() == "start" && (em.modification()) && is(em.modification_ref().get())) { Expression e = get(em.modification_ref().get()).exp(); return ApplyThis(e); } diff --git a/util/ast_visitors/eval_expression.h b/util/ast_visitors/eval_expression.hpp similarity index 97% rename from util/ast_visitors/eval_expression.h rename to util/ast_visitors/eval_expression.hpp index 54d5ebe..04b95b5 100644 --- a/util/ast_visitors/eval_expression.h +++ b/util/ast_visitors/eval_expression.hpp @@ -21,8 +21,9 @@ #define AST_VISITOR_EVALEXP #include -#include -#include + +#include +#include namespace Modelica { diff --git a/util/ast_visitors/eval_expression_flatter.cpp b/util/ast_visitors/eval_expression_flatter.cpp index ed037db..af8aaec 100644 --- a/util/ast_visitors/eval_expression_flatter.cpp +++ b/util/ast_visitors/eval_expression_flatter.cpp @@ -21,12 +21,12 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -namespace Modelica{ +namespace Modelica { using namespace SBG; @@ -38,90 +38,98 @@ using namespace SBG; // This visitor is intended to be used for array subscripts -EvalExpFlatter::EvalExpFlatter(const VarSymbolTable &v) : vtable(v){ +EvalExpFlatter::EvalExpFlatter(const VarSymbolTable &v) : vtable(v) +{ Option nm; name = nm; Option r; } -EvalExpFlatter::EvalExpFlatter(const VarSymbolTable &v, Name n, Real r) - : vtable(v), name(n), val(r){}; +EvalExpFlatter::EvalExpFlatter(const VarSymbolTable &v, Name n, Real r) : vtable(v), name(n), val(r){}; -Interval EvalExpFlatter::operator()(Integer v) const{ - Interval i((INT) v, 1, (INT) v); +Interval EvalExpFlatter::operator()(Integer v) const +{ + Interval i((INT)v, 1, (INT)v); return i; } -Interval EvalExpFlatter::operator()(Boolean v) const{ +Interval EvalExpFlatter::operator()(Boolean v) const +{ INT res = 0; - if (v.val()) - res = 1; + if (v.val()) res = 1; Interval i(res, 1, res); return i; } -Interval EvalExpFlatter::operator()(AddAll v) const{ +Interval EvalExpFlatter::operator()(AddAll v) const +{ ERROR("EvalExpFlatter: trying to evaluate an AddAll"); Interval i; return i; } -Interval EvalExpFlatter::operator()(String v) const{ +Interval EvalExpFlatter::operator()(String v) const +{ ERROR("EvalExpFlatter: trying to evaluate a String"); Interval i; return i; } -Interval EvalExpFlatter::operator()(Name v) const{ +Interval EvalExpFlatter::operator()(Name v) const +{ ERROR("EvalExpFlatter: trying to evaluate a Name"); Interval i; return i; } -Interval EvalExpFlatter::operator()(Real v) const { +Interval EvalExpFlatter::operator()(Real v) const +{ INT res = v; Interval i(res, 1, res); return i; } -Interval EvalExpFlatter::operator()(SubAll v) const{ -/* - Option ovi = vtable[v]; - if(ovi){ - VarInfo vi = *ovi; - Option oinds = vi.indices(); - if(oinds){ - ExpList inds = *oinds; - ExpList::iterator itinds = inds.begin(); - - for(int i = 0; i < ???; i++) - ++itinds; - - Expression aux = *itinds; - INT to = ApplyThis(itinds); - Interval i(1, 1, to); - return i; +Interval EvalExpFlatter::operator()(SubAll v) const +{ + /* + Option ovi = vtable[v]; + if(ovi){ + VarInfo vi = *ovi; + Option oinds = vi.indices(); + if(oinds){ + ExpList inds = *oinds; + ExpList::iterator itinds = inds.begin(); + + for(int i = 0; i < ???; i++) + ++itinds; + + Expression aux = *itinds; + INT to = ApplyThis(itinds); + Interval i(1, 1, to); + return i; + } } - } -*/ + */ ERROR("EvalExpFlatter: trying to evaluate a SubAll"); Interval i; return i; } -Interval EvalExpFlatter::operator()(SubEnd v) const{ +Interval EvalExpFlatter::operator()(SubEnd v) const +{ ERROR("EvalExpFlatter: trying to evaluate a SubEnd"); Interval i; return i; } -Interval EvalExpFlatter::operator()(BinOp v) const{ +Interval EvalExpFlatter::operator()(BinOp v) const +{ Expression l = v.left(), r = v.right(); - Interval ll = ApplyThis(l), rr = ApplyThis(r); + Interval ll = ApplyThis(l), rr = ApplyThis(r); // Operations using constants - if(ll.card() == 1 && rr.card() == 1){ + if (ll.card() == 1 && rr.card() == 1) { Real nl = ll.lo(); Real nr = rr.lo(); BinOp bop(nl, v.op(), nr); @@ -129,71 +137,51 @@ Interval EvalExpFlatter::operator()(BinOp v) const{ EvalExpression evexp(vtable); Real res = Apply(evexp, e); - Interval i(res, 1, res); + Interval i(res, 1, res); return i; } - else if(ll.card() == 1){ - switch(v.op()){ - case Add: - { - Interval i(ll.lo() + rr.lo(), - rr.step(), - ll.hi() + rr.hi()); - return i; - } - case Sub: - { - Interval i(ll.lo() - rr.lo(), - rr.step(), - ll.hi() - rr.hi()); - return i; - } - case Mult: - { - Interval i(ll.lo() * rr.lo(), - ll.lo() * rr.step(), - ll.hi() * rr.hi()); - return i; - } - default: - { - ERROR("EvalExpFlatter: BinOp is not allowed"); - Interval i; - return i; - } + else if (ll.card() == 1) { + switch (v.op()) { + case Add: { + Interval i(ll.lo() + rr.lo(), rr.step(), ll.hi() + rr.hi()); + return i; + } + case Sub: { + Interval i(ll.lo() - rr.lo(), rr.step(), ll.hi() - rr.hi()); + return i; + } + case Mult: { + Interval i(ll.lo() * rr.lo(), ll.lo() * rr.step(), ll.hi() * rr.hi()); + return i; + } + default: { + ERROR("EvalExpFlatter: BinOp is not allowed"); + Interval i; + return i; + } } } - else if(rr.card() == 1){ - switch(v.op()){ - case Add: - { - Interval i(ll.lo() + rr.lo(), - ll.step(), - ll.hi() + rr.hi()); - return i; - } - case Sub: - { - Interval i(ll.lo() - rr.lo(), - ll.step(), - ll.hi() - rr.hi()); - return i; - } - case Mult: - { - Interval i(ll.lo() * rr.lo(), - ll.lo() * rr.step(), - ll.hi() * rr.hi()); - return i; - } - default: - { - ERROR("EvalExpFlatter: BinOp is not allowed"); - Interval i; - return i; - } + else if (rr.card() == 1) { + switch (v.op()) { + case Add: { + Interval i(ll.lo() + rr.lo(), ll.step(), ll.hi() + rr.hi()); + return i; + } + case Sub: { + Interval i(ll.lo() - rr.lo(), ll.step(), ll.hi() - rr.hi()); + return i; + } + case Mult: { + Interval i(ll.lo() * rr.lo(), ll.lo() * rr.step(), ll.hi() * rr.hi()); + return i; + } + default: { + ERROR("EvalExpFlatter: BinOp is not allowed"); + Interval i; + return i; + } } } @@ -202,7 +190,8 @@ Interval EvalExpFlatter::operator()(BinOp v) const{ return i; } -Interval EvalExpFlatter::operator()(UnaryOp v) const{ +Interval EvalExpFlatter::operator()(UnaryOp v) const +{ EvalExpression evexp(vtable); Expression e(v); Real aux = Apply(evexp, e); @@ -212,13 +201,15 @@ Interval EvalExpFlatter::operator()(UnaryOp v) const{ return i; } -Interval EvalExpFlatter::operator()(IfExp v) const{ +Interval EvalExpFlatter::operator()(IfExp v) const +{ ERROR("EvalExpFlatter: trying to evaluate a IfExp"); Interval i; return i; } -Interval EvalExpFlatter::operator()(Range v) const{ +Interval EvalExpFlatter::operator()(Range v) const +{ EvalExpression evexp(vtable); Expression st = v.start(); Real auxLo = Apply(evexp, st); @@ -226,7 +217,7 @@ Interval EvalExpFlatter::operator()(Range v) const{ Expression en = v.end(); Real auxHi = Apply(evexp, en); - if(v.step()){ + if (v.step()) { st = *(v.step()); auxStep = Apply(evexp, st); } @@ -235,26 +226,28 @@ Interval EvalExpFlatter::operator()(Range v) const{ INT newStep = auxStep; INT newHi = auxHi; - if (newLo <= newHi) - return Interval(newLo, newStep, newHi); + if (newLo <= newHi) return Interval(newLo, newStep, newHi); return Interval(true); } -Interval EvalExpFlatter::operator()(Brace v) const{ +Interval EvalExpFlatter::operator()(Brace v) const +{ WARNING("EvalExpFlatter: trying to evaluate a Brace"); Interval i; return i; } -Interval EvalExpFlatter::operator()(Bracket v) const{ +Interval EvalExpFlatter::operator()(Bracket v) const +{ ERROR("EvalExpFlatter: trying to evaluate a Bracket"); Interval i; return i; } -Interval EvalExpFlatter::operator()(Call v) const{ - if ("integer" == v.name()){ +Interval EvalExpFlatter::operator()(Call v) const +{ + if ("integer" == v.name()) { EvalExpression evexp(vtable); Real aux = Apply(evexp, v.args().front()); int res = aux; @@ -262,39 +255,43 @@ Interval EvalExpFlatter::operator()(Call v) const{ return i; } - if ("exp" == v.name()){ + if ("exp" == v.name()) { EvalExpression evexp(vtable); Real aux = exp(Apply(evexp, v.args().front())); int res = aux; Interval i(res, 1, res); return i; } - + ERROR("EvalExpFlatter: trying to evaluate a Call"); return 0; } -Interval EvalExpFlatter::operator()(FunctionExp v) const{ +Interval EvalExpFlatter::operator()(FunctionExp v) const +{ ERROR("EvalExpFlatter: trying to evaluate a FunctionExp"); Interval i; return i; } -Interval EvalExpFlatter::operator()(ForExp v) const{ +Interval EvalExpFlatter::operator()(ForExp v) const +{ ERROR("EvalExpFlatter: trying to evaluate a ForExp"); Interval i; return i; } -Interval EvalExpFlatter::operator()(Named v) const{ +Interval EvalExpFlatter::operator()(Named v) const +{ ERROR("EvalExpFlatter: trying to evaluate a Named"); Interval i; return i; } -Interval EvalExpFlatter::operator()(Output v) const{ +Interval EvalExpFlatter::operator()(Output v) const +{ ERROR_UNLESS(v.args().size() == 1, "EvalExpFlatter: Output expression with more than one element are not supported"); - if (v.args().front()){ + if (v.args().front()) { Expression e = v.args().front().get(); EvalExpression evexp(vtable); Real aux = Apply(evexp, e); @@ -308,21 +305,21 @@ Interval EvalExpFlatter::operator()(Output v) const{ return i; } -Interval EvalExpFlatter::operator()(Reference v) const{ +Interval EvalExpFlatter::operator()(Reference v) const +{ Ref r = v.ref(); ERROR_UNLESS(r.size() == 1, "EvalExpFlatter: conversion of dotted references not implemented"); Option oel = boost::get<1>(r[0]); ERROR_UNLESS((bool)oel, "EvalExpFlatter: conversion of subscripted references not implemented"); Name s = boost::get<0>(r[0]); - if (name && name.get() == s){ + if (name && name.get() == s) { Real aux = val.get(); INT res = aux; Interval i(res, 1, res); return i; } - Option vinfo = vtable[s]; if (!vinfo) ERROR("EvalExpFlatter: Variable %s not found !", s.c_str()); if (!vinfo.get().modification()) { @@ -330,30 +327,30 @@ Interval EvalExpFlatter::operator()(Reference v) const{ } Modification m = vinfo.get().modification().get(); - + VarSymbolTable auxtable = vtable; - auxtable.remove(s); // To check that is linear, preventing i * i, for example + auxtable.remove(s); // To check that is linear, preventing i * i, for example EvalExpFlatter evexp(auxtable); - if (is(m)){ + if (is(m)) { Expression meq = boost::get(m).exp(); return Apply(evexp, meq); } - if (is(m)){ + if (is(m)) { Expression meq = boost::get(m).exp(); return Apply(evexp, meq); } - if (is(m)){ + if (is(m)) { OptExp oe = get(m).exp(); - if (oe) - return Apply(evexp, oe.get()); + if (oe) return Apply(evexp, oe.get()); - foreach_(Argument a, get(m).modification_ref()){ - if (is(a)){ + foreach_(Argument a, get(m).modification_ref()) + { + if (is(a)) { ElMod em = boost::get(a); - if (em.name() == "start" && (em.modification()) && is(em.modification_ref().get())){ + if (em.name() == "start" && (em.modification()) && is(em.modification_ref().get())) { Expression e = get(em.modification_ref().get()).exp(); return Apply(evexp, e); } diff --git a/util/ast_visitors/eval_expression_flatter.h b/util/ast_visitors/eval_expression_flatter.hpp similarity index 97% rename from util/ast_visitors/eval_expression_flatter.h rename to util/ast_visitors/eval_expression_flatter.hpp index 44fd071..1c3ed44 100644 --- a/util/ast_visitors/eval_expression_flatter.h +++ b/util/ast_visitors/eval_expression_flatter.hpp @@ -19,9 +19,11 @@ #ifndef AST_VISITOR_EVALEXP_FLATTER #define AST_VISITOR_EVALEXP_FLATTER + #include -#include -#include + +#include +#include #include namespace Modelica { diff --git a/util/ast_visitors/ginac_interface.cpp b/util/ast_visitors/ginac_interface.cpp index 3c34447..55407d1 100644 --- a/util/ast_visitors/ginac_interface.cpp +++ b/util/ast_visitors/ginac_interface.cpp @@ -24,16 +24,16 @@ #include #include #include -#include -#include +#include +#include #include #include #include #include #include -#include -#include -#include +#include +#include +#include using namespace GiNaC; using namespace std; diff --git a/util/ast_visitors/ginac_interface.h b/util/ast_visitors/ginac_interface.hpp similarity index 98% rename from util/ast_visitors/ginac_interface.h rename to util/ast_visitors/ginac_interface.hpp index 6b12a2a..9e3888f 100644 --- a/util/ast_visitors/ginac_interface.h +++ b/util/ast_visitors/ginac_interface.hpp @@ -20,14 +20,17 @@ #ifndef GINAC_INTERFACE #define GINAC_INTERFACE -#include -#include -#include + +#include #include #include -#include -#include -#include +#include +#include +#include + + +#include +#include DECLARE_FUNCTION_2P(var) DECLARE_FUNCTION_1P(der) diff --git a/util/ast_visitors/mark_connector.cpp b/util/ast_visitors/mark_connector.cpp index 0b00261..3062c18 100644 --- a/util/ast_visitors/mark_connector.cpp +++ b/util/ast_visitors/mark_connector.cpp @@ -16,10 +16,10 @@ along with Modelica C Compiler. If not, see . ******************************************************************************/ - -#include #include +#include + using namespace Modelica; using namespace Modelica::AST; diff --git a/util/ast_visitors/mark_connector.h b/util/ast_visitors/mark_connector.hpp similarity index 95% rename from util/ast_visitors/mark_connector.h rename to util/ast_visitors/mark_connector.hpp index a80ab32..7d91e6b 100644 --- a/util/ast_visitors/mark_connector.h +++ b/util/ast_visitors/mark_connector.hpp @@ -19,9 +19,11 @@ #ifndef AST_VISITOR_MARKC #define AST_VISITOR_MARKC + #include -#include -#include + +#include +#include namespace Modelica { using namespace Modelica::AST; diff --git a/util/ast_visitors/matching_exps.cpp b/util/ast_visitors/matching_exps.cpp index 019b27b..8b1f3eb 100644 --- a/util/ast_visitors/matching_exps.cpp +++ b/util/ast_visitors/matching_exps.cpp @@ -17,15 +17,16 @@ ******************************************************************************/ -#include #include -#include +#include +#include using namespace std; namespace Modelica { -MatchingExps::MatchingExps(string variable_name, bool state_var) : _matched_exps(), _variable_name(variable_name), _state_var(state_var), _der_call(false), _has_der(false) {}; +MatchingExps::MatchingExps(string variable_name, bool state_var) + : _matched_exps(), _variable_name(variable_name), _state_var(state_var), _der_call(false), _has_der(false){}; bool MatchingExps::operator()(Integer v) const { return false; } @@ -75,7 +76,7 @@ bool MatchingExps::operator()(Range v) const } bool MatchingExps::operator()(Brace v) const -{ +{ bool matched = false; foreach_(Expression e, v.args()) { matched = matched || ApplyThis(e); } return matched; @@ -106,12 +107,13 @@ bool MatchingExps::operator()(Named v) const { return false; } bool MatchingExps::operator()(Output v) const { bool matched = false; - foreach_(OptExp out_exp, v.args()) { + foreach_(OptExp out_exp, v.args()) + { if (out_exp) { matched = matched || ApplyThis(out_exp.get()); } } - return matched; + return matched; } bool MatchingExps::operator()(Reference v) const @@ -119,15 +121,12 @@ bool MatchingExps::operator()(Reference v) const if (get<0>(v.ref().front()) == _variable_name) { if ((_state_var && _der_call) || !_state_var) { _matched_exps.insert(v); - return true; + return true; } - } + } return false; } -set MatchingExps::matchedExps() const -{ - return _matched_exps; -} +set MatchingExps::matchedExps() const { return _matched_exps; } } // namespace Modelica diff --git a/util/ast_visitors/matching_exps.h b/util/ast_visitors/matching_exps.hpp similarity index 98% rename from util/ast_visitors/matching_exps.h rename to util/ast_visitors/matching_exps.hpp index c08a36d..e6b2c91 100644 --- a/util/ast_visitors/matching_exps.h +++ b/util/ast_visitors/matching_exps.hpp @@ -23,7 +23,7 @@ #include #include -#include +#include namespace Modelica { diff --git a/util/ast_visitors/partial_eval_expression.cpp b/util/ast_visitors/partial_eval_expression.cpp index 584c891..18a2481 100644 --- a/util/ast_visitors/partial_eval_expression.cpp +++ b/util/ast_visitors/partial_eval_expression.cpp @@ -18,10 +18,11 @@ ******************************************************************************/ #include -#include -#include -#include -#include + +#include +#include +#include +#include namespace Modelica { @@ -37,7 +38,8 @@ Expression PartialEvalExpression::operator()(Real v) const return v; } Expression PartialEvalExpression::operator()(Boolean v) const { return v; } -Expression PartialEvalExpression::operator()(AddAll v) const { +Expression PartialEvalExpression::operator()(AddAll v) const +{ WARNING("Not evaluating AddAll exp"); return v; } diff --git a/util/ast_visitors/partial_eval_expression.h b/util/ast_visitors/partial_eval_expression.hpp similarity index 97% rename from util/ast_visitors/partial_eval_expression.h rename to util/ast_visitors/partial_eval_expression.hpp index 95b1e2f..0749d2e 100644 --- a/util/ast_visitors/partial_eval_expression.h +++ b/util/ast_visitors/partial_eval_expression.hpp @@ -19,9 +19,11 @@ #ifndef AST_VISITOR_PARTEVALEXP #define AST_VISITOR_PARTEVALEXP + #include -#include -#include + +#include +#include namespace Modelica { diff --git a/util/ast_visitors/pwl_map_values.cpp b/util/ast_visitors/pwl_map_values.cpp index 770b016..cc03984 100644 --- a/util/ast_visitors/pwl_map_values.cpp +++ b/util/ast_visitors/pwl_map_values.cpp @@ -17,10 +17,10 @@ ******************************************************************************/ -#include -#include -#include -#include +#include +#include +#include +#include namespace Modelica { diff --git a/util/ast_visitors/pwl_map_values.h b/util/ast_visitors/pwl_map_values.hpp similarity index 98% rename from util/ast_visitors/pwl_map_values.h rename to util/ast_visitors/pwl_map_values.hpp index 82084a6..390beee 100644 --- a/util/ast_visitors/pwl_map_values.h +++ b/util/ast_visitors/pwl_map_values.hpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include -#include +#include #ifndef AST_VISITOR_PWL_MAP_VALUES #define AST_VISITOR_PWL_MAP_VALUES diff --git a/util/ast_visitors/replace_equation.cpp b/util/ast_visitors/replace_equation.cpp index 509a044..fbab46e 100644 --- a/util/ast_visitors/replace_equation.cpp +++ b/util/ast_visitors/replace_equation.cpp @@ -17,8 +17,8 @@ ******************************************************************************/ -#include -#include +#include +#include namespace Modelica { diff --git a/util/ast_visitors/replace_equation.h b/util/ast_visitors/replace_equation.hpp similarity index 94% rename from util/ast_visitors/replace_equation.h rename to util/ast_visitors/replace_equation.hpp index 26f89a3..2b1f57a 100644 --- a/util/ast_visitors/replace_equation.h +++ b/util/ast_visitors/replace_equation.hpp @@ -20,8 +20,8 @@ #ifndef AST_VISITOR_REPLACE_EQ #define AST_VISITOR_REPLACE_EQ #include -#include -#include +#include +#include namespace Modelica { diff --git a/util/ast_visitors/replace_expression.cpp b/util/ast_visitors/replace_expression.cpp index b042e59..7ae3187 100644 --- a/util/ast_visitors/replace_expression.cpp +++ b/util/ast_visitors/replace_expression.cpp @@ -17,8 +17,8 @@ ******************************************************************************/ -#include -#include +#include +#include namespace Modelica { diff --git a/util/ast_visitors/replace_expression.h b/util/ast_visitors/replace_expression.hpp similarity index 98% rename from util/ast_visitors/replace_expression.h rename to util/ast_visitors/replace_expression.hpp index 38d2c39..5ac9312 100644 --- a/util/ast_visitors/replace_expression.h +++ b/util/ast_visitors/replace_expression.hpp @@ -20,7 +20,7 @@ #ifndef AST_VISITOR_REPLACE #define AST_VISITOR_REPLACE #include -#include +#include namespace Modelica { diff --git a/util/ast_visitors/replace_index.cpp b/util/ast_visitors/replace_index.cpp index 7b533d5..33e9497 100644 --- a/util/ast_visitors/replace_index.cpp +++ b/util/ast_visitors/replace_index.cpp @@ -17,186 +17,166 @@ ******************************************************************************/ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace Modelica { - ReplaceIndex::ReplaceIndex(const VarSymbolTable &v, bool eval):vtable(v),eval_parameters(eval) {counter=0;}; - Expression ReplaceIndex::operator()(Integer v) const { - if (v<0) return Output(v); - return v; - } - Expression ReplaceIndex::operator()(Real v) const { - if (v<0) return Output(v); - return v; - } - Expression ReplaceIndex::operator()(Boolean v) const { - return v; - } - Expression ReplaceIndex::operator()(String v) const { - return v; - } - Expression ReplaceIndex::operator()(Name v) const { - return v; - } - Expression ReplaceIndex::operator()(Expression v) const { - return v; - } - Expression ReplaceIndex::operator()(SubAll v) const { - return v; - } - Expression ReplaceIndex::operator()(SubEnd v) const { - return v; - } - Expression ReplaceIndex::operator()(BinOp v) const { - Expression l=v.left(), r=v.right(); - l=ApplyThis(l);r=ApplyThis(r); - if (eval_parameters && (is(l) || is(l)) && (is(r) || is(r))) { - Expression binop = BinOp(l,v.op(),r); - Expression e = Apply(EvalExpression(vtable),binop); - if (!is(l) && !is(r) && is(e)) { - return Integer(get(e)); - } - return Apply(EvalExpression(vtable),binop); - } - if (is(l) && is(r)) { // Only evaluate integer operations - Expression binop = BinOp(l,v.op(),r); - Expression e = Apply(EvalExpression(vtable),binop); - if (!is(l) && !is(r) && is(e)) { - return Integer(get(e)); - } - return Apply(EvalExpression(vtable),binop); - } - - if (v.op()==Add && isZero(l)) - return r; - if (v.op()==Add && isZero(r)) - return l; - if (v.op()==Sub && isZero(r)) - return l; - if (v.op()==Sub && isZero(l)) - return UnaryOp(r,Minus); - if (v.op()==Mult && isOne(l)) - return r; - if (v.op()==Mult && isOne(r)) - return l; - if (v.op()==Mult && (isZero(r) || isZero(l))) - return 0; - return BinOp(l,v.op(),r); - } - Expression ReplaceIndex::operator()(UnaryOp v) const { - Expression e=v.exp(); - Expression res= ApplyThis(e); - if (v.op()==Not && is(res)) { - if (get(res)==TRUE) - return Boolean(FALSE); - return Boolean(TRUE); - } - if (v.op()==Minus && is(res)) { - return Real(-get(res)); - } - if (v.op()==Minus && is(res)) - return Integer(-get(res)); - if (v.op()==Minus && is(res) && get(res).op()==Minus)// (-(-a)) == a - return get(res).exp(); - return UnaryOp(res, v.op()); - } - Expression ReplaceIndex::operator()(IfExp v) const { - WARNING("Not evaluating If exp"); - return v; - } - Expression ReplaceIndex::operator()(Range v) const { - Expression s=v.start(); - Expression e=v.end(); - if (!v.step()) - return Range(ApplyThis(s),ApplyThis(e)); - Expression st=v.step().get(); - return Range(ApplyThis(s),ApplyThis(st),ApplyThis(e)); - } - Expression ReplaceIndex::operator()(Brace v) const { - WARNING("Not evaluating brace exp"); - return v; - } - Expression ReplaceIndex::operator()(Bracket v) const { - return v; - } - Expression ReplaceIndex::operator()(Call v) const { - ExpList &args = v.args_ref(); - foreach_ (Expression &e, args) - e = ApplyThis(e); - return v; - } - Expression ReplaceIndex::operator()(FunctionExp v) const { - return v; - } - Expression ReplaceIndex::operator()(ForExp v) const { - Expression e = v.exp_; - Indexes i = v.indices_; - //~ table[e] = 1; - //~ if (!table.count(e)){; - //~ table[e] = counter++; - //~ } - return e; - //~ return e++reference_names2[e]; - } - Expression ReplaceIndex::operator()(Named v) const { - return v; - } - Expression ReplaceIndex::operator()(Output v) const { - if (v.args().size()==1 && v.args().front()) { - Expression e=v.args().front().get(); - if (is(e)) return e; - if (is(e)) return e; - if (is(e)) return ApplyThis(e); - return Output(ApplyThis(e)); - } - return v; - } - Expression ReplaceIndex::operator()(Reference v) const { - Ref r=v.ref(); - ERROR_UNLESS(r.size()==1,"ReplaceIndex conversion of dotted references not implemented"); - Option oel = boost::get<1>(r[0]); - Name s=boost::get<0>(r[0]); - if ((isConstant(s,vtable) || isParameter(s,vtable)) && (!oel || (oel && oel.get().size()==0))) { - Option vinfo = vtable[s]; - if (!vinfo) - ERROR("Variable %s not found",s.c_str()); - if (vinfo.get().type()=="Integer" && vinfo.get().modification()) { // evaluate integer parameters - Expression vv=v; - Real ret=Apply(EvalExpression(vtable),vv); - const int i=ret; - if (i==ret) { - if (i<0) return Output(i); - return i; - } - if (ret<0) return Output(Real(ret)); - return Real(ret); - } else if (vinfo.get().type()=="Boolean" && vinfo.get().modification()) { // evaluate boolean parameters - Expression vv=v; - Real ret=Apply(EvalExpression(vtable),vv); - if (ret==1.0) - return Boolean(TRUE); - return Boolean(FALSE); - } else if (eval_parameters && vinfo.get().type()=="Real" && !vinfo.get().indices() && vinfo.get().modification()) { // evaluate scalar parameters - Expression vv=v; - Real ret=Apply(EvalExpression(vtable),vv); - if (ret<0) return Output(Real(ret)); - return Real(ret); - } else { - return v; - } - } - if (oel) { - ExpList nl; - foreach_(Expression e, oel.get()) { - nl.push_back(ApplyThis(e)); - } - return Reference(Ref(1,RefTuple(s,nl))); +ReplaceIndex::ReplaceIndex(const VarSymbolTable &v, bool eval) : vtable(v), eval_parameters(eval) { counter = 0; }; +Expression ReplaceIndex::operator()(Integer v) const +{ + if (v < 0) return Output(v); + return v; +} +Expression ReplaceIndex::operator()(Real v) const +{ + if (v < 0) return Output(v); + return v; +} +Expression ReplaceIndex::operator()(Boolean v) const { return v; } +Expression ReplaceIndex::operator()(String v) const { return v; } +Expression ReplaceIndex::operator()(Name v) const { return v; } +Expression ReplaceIndex::operator()(Expression v) const { return v; } +Expression ReplaceIndex::operator()(SubAll v) const { return v; } +Expression ReplaceIndex::operator()(SubEnd v) const { return v; } +Expression ReplaceIndex::operator()(BinOp v) const +{ + Expression l = v.left(), r = v.right(); + l = ApplyThis(l); + r = ApplyThis(r); + if (eval_parameters && (is(l) || is(l)) && (is(r) || is(r))) { + Expression binop = BinOp(l, v.op(), r); + Expression e = Apply(EvalExpression(vtable), binop); + if (!is(l) && !is(r) && is(e)) { + return Integer(get(e)); + } + return Apply(EvalExpression(vtable), binop); + } + if (is(l) && is(r)) { // Only evaluate integer operations + Expression binop = BinOp(l, v.op(), r); + Expression e = Apply(EvalExpression(vtable), binop); + if (!is(l) && !is(r) && is(e)) { + return Integer(get(e)); + } + return Apply(EvalExpression(vtable), binop); + } + + if (v.op() == Add && isZero(l)) return r; + if (v.op() == Add && isZero(r)) return l; + if (v.op() == Sub && isZero(r)) return l; + if (v.op() == Sub && isZero(l)) return UnaryOp(r, Minus); + if (v.op() == Mult && isOne(l)) return r; + if (v.op() == Mult && isOne(r)) return l; + if (v.op() == Mult && (isZero(r) || isZero(l))) return 0; + return BinOp(l, v.op(), r); +} +Expression ReplaceIndex::operator()(UnaryOp v) const +{ + Expression e = v.exp(); + Expression res = ApplyThis(e); + if (v.op() == Not && is(res)) { + if (get(res) == TRUE) return Boolean(FALSE); + return Boolean(TRUE); + } + if (v.op() == Minus && is(res)) { + return Real(-get(res)); + } + if (v.op() == Minus && is(res)) return Integer(-get(res)); + if (v.op() == Minus && is(res) && get(res).op() == Minus) // (-(-a)) == a + return get(res).exp(); + return UnaryOp(res, v.op()); +} +Expression ReplaceIndex::operator()(IfExp v) const +{ + WARNING("Not evaluating If exp"); + return v; +} +Expression ReplaceIndex::operator()(Range v) const +{ + Expression s = v.start(); + Expression e = v.end(); + if (!v.step()) return Range(ApplyThis(s), ApplyThis(e)); + Expression st = v.step().get(); + return Range(ApplyThis(s), ApplyThis(st), ApplyThis(e)); +} +Expression ReplaceIndex::operator()(Brace v) const +{ + WARNING("Not evaluating brace exp"); + return v; +} +Expression ReplaceIndex::operator()(Bracket v) const { return v; } +Expression ReplaceIndex::operator()(Call v) const +{ + ExpList &args = v.args_ref(); + foreach_(Expression & e, args) e = ApplyThis(e); + return v; +} +Expression ReplaceIndex::operator()(FunctionExp v) const { return v; } +Expression ReplaceIndex::operator()(ForExp v) const +{ + Expression e = v.exp_; + Indexes i = v.indices_; + //~ table[e] = 1; + //~ if (!table.count(e)){; + //~ table[e] = counter++; + //~ } + return e; + //~ return e++reference_names2[e]; +} +Expression ReplaceIndex::operator()(Named v) const { return v; } +Expression ReplaceIndex::operator()(Output v) const +{ + if (v.args().size() == 1 && v.args().front()) { + Expression e = v.args().front().get(); + if (is(e)) return e; + if (is(e)) return e; + if (is(e)) return ApplyThis(e); + return Output(ApplyThis(e)); + } + return v; +} +Expression ReplaceIndex::operator()(Reference v) const +{ + Ref r = v.ref(); + ERROR_UNLESS(r.size() == 1, "ReplaceIndex conversion of dotted references not implemented"); + Option oel = boost::get<1>(r[0]); + Name s = boost::get<0>(r[0]); + if ((isConstant(s, vtable) || isParameter(s, vtable)) && (!oel || (oel && oel.get().size() == 0))) { + Option vinfo = vtable[s]; + if (!vinfo) ERROR("Variable %s not found", s.c_str()); + if (vinfo.get().type() == "Integer" && vinfo.get().modification()) { // evaluate integer parameters + Expression vv = v; + Real ret = Apply(EvalExpression(vtable), vv); + const int i = ret; + if (i == ret) { + if (i < 0) return Output(i); + return i; } - return v; - } + if (ret < 0) return Output(Real(ret)); + return Real(ret); + } else if (vinfo.get().type() == "Boolean" && vinfo.get().modification()) { // evaluate boolean parameters + Expression vv = v; + Real ret = Apply(EvalExpression(vtable), vv); + if (ret == 1.0) return Boolean(TRUE); + return Boolean(FALSE); + } else if (eval_parameters && vinfo.get().type() == "Real" && !vinfo.get().indices() && + vinfo.get().modification()) { // evaluate scalar parameters + Expression vv = v; + Real ret = Apply(EvalExpression(vtable), vv); + if (ret < 0) return Output(Real(ret)); + return Real(ret); + } else { + return v; + } + } + if (oel) { + ExpList nl; + foreach_(Expression e, oel.get()) { nl.push_back(ApplyThis(e)); } + return Reference(Ref(1, RefTuple(s, nl))); + } + return v; } +} // namespace Modelica diff --git a/util/ast_visitors/replace_index.h b/util/ast_visitors/replace_index.hpp similarity index 97% rename from util/ast_visitors/replace_index.h rename to util/ast_visitors/replace_index.hpp index 3d76cbc..240c636 100644 --- a/util/ast_visitors/replace_index.h +++ b/util/ast_visitors/replace_index.hpp @@ -19,12 +19,14 @@ #ifndef AST_VISITOR_REPLACEINDEX #define AST_VISITOR_REPLACEINDEX -#include -#include -#include -#include + #include #include +#include +#include + +#include +#include namespace Modelica { diff --git a/util/ast_visitors/replace_statement.cpp b/util/ast_visitors/replace_statement.cpp index 395a14a..edaef2c 100644 --- a/util/ast_visitors/replace_statement.cpp +++ b/util/ast_visitors/replace_statement.cpp @@ -17,8 +17,8 @@ ******************************************************************************/ -#include -#include +#include +#include namespace Modelica { diff --git a/util/ast_visitors/replace_statement.h b/util/ast_visitors/replace_statement.hpp similarity index 94% rename from util/ast_visitors/replace_statement.h rename to util/ast_visitors/replace_statement.hpp index 168037d..34e7671 100644 --- a/util/ast_visitors/replace_statement.h +++ b/util/ast_visitors/replace_statement.hpp @@ -19,9 +19,11 @@ #ifndef AST_VISITOR_REPLACE_ST #define AST_VISITOR_REPLACE_ST + #include -#include -#include + +#include +#include namespace Modelica { diff --git a/util/ast_visitors/splitfor_visitor.cpp b/util/ast_visitors/splitfor_visitor.cpp index 93ea128..b96f046 100644 --- a/util/ast_visitors/splitfor_visitor.cpp +++ b/util/ast_visitors/splitfor_visitor.cpp @@ -17,8 +17,8 @@ ******************************************************************************/ -#include -#include +#include +#include namespace Modelica { diff --git a/util/ast_visitors/splitfor_visitor.h b/util/ast_visitors/splitfor_visitor.hpp similarity index 97% rename from util/ast_visitors/splitfor_visitor.h rename to util/ast_visitors/splitfor_visitor.hpp index 396ee25..a7a6756 100644 --- a/util/ast_visitors/splitfor_visitor.h +++ b/util/ast_visitors/splitfor_visitor.hpp @@ -21,7 +21,8 @@ #define AST_VISITOR_SPLITFOR #include -#include + +#include namespace Modelica { diff --git a/util/ast_visitors/state_variables_finder.cpp b/util/ast_visitors/state_variables_finder.cpp index 90c4075..2243f25 100644 --- a/util/ast_visitors/state_variables_finder.cpp +++ b/util/ast_visitors/state_variables_finder.cpp @@ -22,11 +22,11 @@ #include #include -#include +#include -#include -#include -#include +#include +#include +#include StateVariablesFinder::StateVariablesFinder(MMO_Class &c) : _c(c) {} diff --git a/util/ast_visitors/state_variables_finder.h b/util/ast_visitors/state_variables_finder.hpp similarity index 95% rename from util/ast_visitors/state_variables_finder.h rename to util/ast_visitors/state_variables_finder.hpp index b2368ac..8c9348e 100644 --- a/util/ast_visitors/state_variables_finder.h +++ b/util/ast_visitors/state_variables_finder.hpp @@ -17,11 +17,12 @@ ******************************************************************************/ -#include -#include -#include #include +#include +#include +#include + using namespace std; using namespace Modelica; using namespace Modelica::AST; diff --git a/util/ast_visitors/statement_visitor.h b/util/ast_visitors/statement_visitor.hpp similarity index 99% rename from util/ast_visitors/statement_visitor.h rename to util/ast_visitors/statement_visitor.hpp index c544a3b..d694687 100644 --- a/util/ast_visitors/statement_visitor.h +++ b/util/ast_visitors/statement_visitor.hpp @@ -19,8 +19,10 @@ #ifndef AST_VISITOR_ST #define AST_VISITOR_ST + #include -#include + +#include namespace Modelica { using namespace Modelica::AST; diff --git a/util/ast_visitors/to_micro/convert_to_micro.cpp b/util/ast_visitors/to_micro/convert_to_micro.cpp index c2b7c0c..a0667ba 100644 --- a/util/ast_visitors/to_micro/convert_to_micro.cpp +++ b/util/ast_visitors/to_micro/convert_to_micro.cpp @@ -17,10 +17,10 @@ ******************************************************************************/ -#include -#include -#include -#include +#include +#include +#include +#include namespace Modelica { ConvertToMicro::ConvertToMicro(MMO_Class &cl) : mmo_class(cl), tomicro_exp(cl, disc_count) { disc_count = 0; } diff --git a/util/ast_visitors/to_micro/convert_to_micro.h b/util/ast_visitors/to_micro/convert_to_micro.hpp similarity index 95% rename from util/ast_visitors/to_micro/convert_to_micro.h rename to util/ast_visitors/to_micro/convert_to_micro.hpp index 9fd5004..03b1373 100644 --- a/util/ast_visitors/to_micro/convert_to_micro.h +++ b/util/ast_visitors/to_micro/convert_to_micro.hpp @@ -19,10 +19,12 @@ #ifndef AST_VISITOR_TO_MICRO #define AST_VISITOR_TO_MICRO + #include -#include -#include -#include + +#include +#include +#include namespace Modelica { diff --git a/util/ast_visitors/to_micro/convert_to_micro_expression.cpp b/util/ast_visitors/to_micro/convert_to_micro_expression.cpp index 0614b5e..923590c 100644 --- a/util/ast_visitors/to_micro/convert_to_micro_expression.cpp +++ b/util/ast_visitors/to_micro/convert_to_micro_expression.cpp @@ -17,12 +17,13 @@ ******************************************************************************/ -#include -#include -#include #include +#include #include +#include +#include + namespace Modelica { ConvertToMicroExpression::ConvertToMicroExpression(MMO_Class &cl, unsigned int &discont, bool w, bool in_alg) @@ -33,9 +34,7 @@ Expression ConvertToMicroExpression::operator()(Boolean v) const if (v == TRUE) return 1.0; return 0.0; } -Expression ConvertToMicroExpression::operator()(AddAll v) const{ - return v; -} +Expression ConvertToMicroExpression::operator()(AddAll v) const { return v; } Expression ConvertToMicroExpression::operator()(String v) const { WARNING("uModelica does not supports strings\n"); @@ -59,8 +58,8 @@ Expression ConvertToMicroExpression::operator()(BinOp v) const IfSt::ElseList el; IfSt ifst(Expression(v), StatementList(1, Assign(d, Expression(1.0))), el, StatementList(1, Assign(d, Expression(0.0)))); mmo_class.addInitStatement(ifst); - mmo_class.statements_ref().statements_ref().push_back(st); - rels.push_back(Expression(v)); + mmo_class.statements_ref().statements_ref().emplace_back(st); + rels.emplace_back(v); disc.push_back(d); return Call("pre", d); } else { diff --git a/util/ast_visitors/to_micro/convert_to_micro_expression.h b/util/ast_visitors/to_micro/convert_to_micro_expression.hpp similarity index 97% rename from util/ast_visitors/to_micro/convert_to_micro_expression.h rename to util/ast_visitors/to_micro/convert_to_micro_expression.hpp index 868c70a..605ee28 100644 --- a/util/ast_visitors/to_micro/convert_to_micro_expression.h +++ b/util/ast_visitors/to_micro/convert_to_micro_expression.hpp @@ -19,9 +19,11 @@ #ifndef AST_VISITOR_TO_MICRO_EXP #define AST_VISITOR_TO_MICRO_EXP + #include -#include -#include + +#include +#include namespace Modelica { diff --git a/util/ast_visitors/to_micro/convert_to_micro_statement.cpp b/util/ast_visitors/to_micro/convert_to_micro_statement.cpp index 9b64faf..7f631c7 100644 --- a/util/ast_visitors/to_micro/convert_to_micro_statement.cpp +++ b/util/ast_visitors/to_micro/convert_to_micro_statement.cpp @@ -17,12 +17,13 @@ ******************************************************************************/ -#include -#include -#include #include #include +#include +#include +#include + namespace Modelica { ConvertToMicroStatement::ConvertToMicroStatement(MMO_Class &cl, unsigned int &discont) : mmo_class(cl), disc_count(discont){}; diff --git a/util/ast_visitors/to_micro/convert_to_micro_statement.h b/util/ast_visitors/to_micro/convert_to_micro_statement.hpp similarity index 96% rename from util/ast_visitors/to_micro/convert_to_micro_statement.h rename to util/ast_visitors/to_micro/convert_to_micro_statement.hpp index 61d2ed6..0849697 100644 --- a/util/ast_visitors/to_micro/convert_to_micro_statement.h +++ b/util/ast_visitors/to_micro/convert_to_micro_statement.hpp @@ -19,9 +19,11 @@ #ifndef AST_VISITOR_TO_MICRO_ST #define AST_VISITOR_TO_MICRO_ST + #include -#include -#include + +#include +#include namespace Modelica { diff --git a/util/debug.cpp b/util/debug.cpp index 110a788..8be3ef5 100644 --- a/util/debug.cpp +++ b/util/debug.cpp @@ -17,12 +17,12 @@ ******************************************************************************/ -#include - -#include +#include #include +#include #include -#include + +#include "debug.hpp" static const char *enableFlags = NULL; // controls which DEBUG messages are printed diff --git a/util/debug.h b/util/debug.hpp similarity index 100% rename from util/debug.h rename to util/debug.hpp diff --git a/util/derivate.cpp b/util/derivate.cpp index 96eb772..34b5d10 100644 --- a/util/derivate.cpp +++ b/util/derivate.cpp @@ -18,8 +18,8 @@ ******************************************************************************/ -#include -#include +#include +#include namespace Modelica { diff --git a/util/derivate.h b/util/derivate.hpp similarity index 94% rename from util/derivate.h rename to util/derivate.hpp index 021cdb6..36086bb 100644 --- a/util/derivate.h +++ b/util/derivate.hpp @@ -21,8 +21,8 @@ #ifndef DERIVATE_H #define DERIVATE_H -#include -#include +#include +#include namespace Modelica { using namespace Modelica::AST; diff --git a/util/derivate_equality.cpp b/util/derivate_equality.cpp index 019c2f6..5993028 100644 --- a/util/derivate_equality.cpp +++ b/util/derivate_equality.cpp @@ -22,12 +22,12 @@ * */ -#include -#include -#include -#include +#include +#include +#include +#include #include -#include +#include namespace Modelica { Equality derivate_equality(Equality eq, VarSymbolTable syms) diff --git a/util/derivate_equality.h b/util/derivate_equality.hpp similarity index 92% rename from util/derivate_equality.h rename to util/derivate_equality.hpp index 30b7bf6..b146d75 100644 --- a/util/derivate_equality.h +++ b/util/derivate_equality.hpp @@ -21,9 +21,9 @@ #ifndef DERIVATE_EQ_H #define DERIVATE_EQ_H -#include -#include -#include +#include +#include +#include namespace Modelica { using namespace Modelica::AST; diff --git a/util/logger.cpp b/util/logger.cpp index 9ff83bc..50156cb 100644 --- a/util/logger.cpp +++ b/util/logger.cpp @@ -17,7 +17,7 @@ ******************************************************************************/ -#include "logger.h" +#include "logger.hpp" using namespace std; @@ -25,8 +25,8 @@ Modelica::Logger::Logger() {} Modelica::Logger::~Logger() { log.close(); } -void Modelica::Logger::setFile(string file_name) +void Modelica::Logger::setFile(string file_name) { - string log_file = file_name + ".log"; - log.open(log_file, std::ofstream::out); + string log_file = file_name + ".log"; + log.open(log_file, std::ofstream::out); } diff --git a/util/logger.h b/util/logger.hpp similarity index 100% rename from util/logger.h rename to util/logger.hpp diff --git a/util/solve/solve.cpp b/util/solve/solve.cpp index e2021b6..8ac9b7d 100644 --- a/util/solve/solve.cpp +++ b/util/solve/solve.cpp @@ -26,17 +26,17 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include using namespace GiNaC; diff --git a/util/solve/solve.h b/util/solve/solve.hpp similarity index 94% rename from util/solve/solve.h rename to util/solve/solve.hpp index 357d735..d797c94 100644 --- a/util/solve/solve.h +++ b/util/solve/solve.hpp @@ -18,9 +18,9 @@ ******************************************************************************/ #pragma once -#include -#include -#include +#include +#include +#include using namespace Modelica::AST; class EquationSolver { diff --git a/util/table.cpp b/util/table.cpp index 7510c23..630534a 100644 --- a/util/table.cpp +++ b/util/table.cpp @@ -17,9 +17,9 @@ ******************************************************************************/ -#include -// Si se usa type.h si o si tiene que estar mmo_class.h. No se puede ṕoner dentro de type.h -#include +#include +// Si se usa type.hpp si o si tiene que estar mmo_class.hpp. No se puede ṕoner dentro de type.hpp +#include using namespace Modelica::AST; @@ -41,11 +41,11 @@ bool VarInfo::isPrefix(TypePrefix p) void VarInfo::removePrefix(TypePrefix p) { TypePrefixes::iterator it = std::find(prefixes_ref().begin(), prefixes_ref().end(), Option(p)); - if (it != prefixes_ref().end()){ - //Option otp = *it; - //if(otp){ - // TypePrefix tp = *otp; - //std::cout << tp << "\n"; + if (it != prefixes_ref().end()) { + // Option otp = *it; + // if(otp){ + // TypePrefix tp = *otp; + // std::cout << tp << "\n"; //} prefixes_ref().erase(it); } @@ -56,9 +56,9 @@ std::ostream& operator<<(std::ostream& out, const VarInfo& v) // output out << "type: " << v.type() << " state: " << v.state() << " builtin: " << v.builtin() << "\n"; VarInfo auxv = v; TypePrefixes::iterator itpre = auxv.prefixes_ref().begin(); - for(; itpre != auxv.prefixes_ref().end(); ++itpre){ + for (; itpre != auxv.prefixes_ref().end(); ++itpre) { Option otp = *itpre; - if(otp){ + if (otp) { TypePrefix tp = *otp; out << tp << "\n"; } @@ -66,10 +66,11 @@ std::ostream& operator<<(std::ostream& out, const VarInfo& v) // output return out; } -std::ostream &operator<<(std::ostream &out, const VarSymbolTable &vst){ +std::ostream& operator<<(std::ostream& out, const VarSymbolTable& vst) +{ typename std::map::const_iterator it; - for(it = vst.begin(); it != vst.end(); ++it){ + for (it = vst.begin(); it != vst.end(); ++it) { out << it->first << ": " << it->second << "\n"; } diff --git a/util/table.h b/util/table.hpp similarity index 97% rename from util/table.h rename to util/table.hpp index f0f301d..b436a05 100644 --- a/util/table.h +++ b/util/table.hpp @@ -22,9 +22,9 @@ #include #include -#include -#include -#include +#include +#include +#include template struct SymbolTable : public std::map { diff --git a/util/type.cpp b/util/type.cpp index 2875393..647809b 100644 --- a/util/type.cpp +++ b/util/type.cpp @@ -20,8 +20,8 @@ #include #include -#include -#include +#include +#include namespace Type { using namespace Modelica; diff --git a/util/type.h b/util/type.hpp similarity index 98% rename from util/type.h rename to util/type.hpp index 97701a5..e10d44d 100644 --- a/util/type.h +++ b/util/type.hpp @@ -23,8 +23,8 @@ #include #include #include -#include -//#include +#include +//#include namespace Modelica { struct MMO_Class;