-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca42abc
commit 5452b00
Showing
2 changed files
with
290 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/******************************************************************************* | ||
This file is part of Set--Based Graph Library. | ||
SBG Library is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
SBG Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with SBG Library. If not, see <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#include "sbg/info.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace LIB { | ||
|
||
DeclRanged::DeclRanged() : prefix_(), name_(), reps_() {} | ||
DeclRanged::DeclRanged(std::string prefix, std::string name, SetPiece reps) | ||
: prefix_(prefix), name_(name), reps_(reps) {} | ||
|
||
member_imp(DeclRanged, std::string, prefix); | ||
member_imp(DeclRanged, std::string, name); | ||
member_imp(DeclRanged, SetPiece, reps); | ||
|
||
std::ostream &operator<<(std::ostream &out, const DeclRanged &dr) | ||
{ | ||
out << dr.prefix() << " " << dr.name(); | ||
|
||
SetPiece mdi = dr.reps(); | ||
unsigned int sz = mdi.size(); | ||
if (sz > 0) { | ||
out << "["; | ||
unsigned int j = 0; | ||
for (; j < sz - 1; j++) { | ||
out << cardinal(mdi[j]) << ", "; | ||
} | ||
out << cardinal(mdi[j]); | ||
out << "]"; | ||
} | ||
out << ";"; | ||
|
||
return out; | ||
} | ||
|
||
std::ostream &operator<<(std::ostream &out, const DeclsRanged &ddr) | ||
{ | ||
BOOST_FOREACH (DeclRanged dr, ddr) out << dr << "\n"; | ||
|
||
return out; | ||
} | ||
|
||
VertexInfo::VertexInfo() : decl_() {} | ||
VertexInfo::VertexInfo(DeclRanged decl) : decl_(decl) {} | ||
|
||
member_imp(VertexInfo, DeclRanged, decl); | ||
|
||
std::ostream &operator<<(std::ostream &out, const VertexInfo &vi) | ||
{ | ||
out << vi.decl(); | ||
|
||
return out; | ||
} | ||
|
||
std::ostream &operator<<(std::ostream &out, const VerticesInfo &vvi) | ||
{ | ||
BOOST_FOREACH (VertexInfo vi, vvi) out << vi << "\n"; | ||
|
||
return out; | ||
} | ||
|
||
UseRanged::UseRanged() : prefix_(), name_(), subs_(), suffix_() {} | ||
UseRanged::UseRanged(std::string prefix, std::string name, MDLExp subs, std::string suffix) | ||
: prefix_(prefix), name_(name), subs_(subs), suffix_(suffix) {} | ||
|
||
member_imp(UseRanged, std::string, prefix); | ||
member_imp(UseRanged, std::string, name); | ||
member_imp(UseRanged, MDLExp, subs); | ||
member_imp(UseRanged, std::string, suffix); | ||
|
||
std::ostream &operator<<(std::ostream &out, const UseRanged &ur) | ||
{ | ||
out << ur.prefix() << ur.name(); | ||
|
||
MDLExp mdle = ur.subs(); | ||
unsigned int sz = mdle.size(); | ||
if (sz > 0) { | ||
out << "["; | ||
unsigned int j = 0; | ||
for (; j < sz - 1; j++) out << mdle[j] << ", "; | ||
out << mdle[j]; | ||
out << "]"; | ||
} | ||
|
||
out << ur.suffix(); | ||
|
||
return out; | ||
} | ||
|
||
std::ostream &operator<<(std::ostream &out, const UsesRanged &uur) | ||
{ | ||
BOOST_FOREACH (UseRanged ur, uur) out << ur; | ||
|
||
return out; | ||
} | ||
|
||
RangedExpr::RangedExpr() : range_(), expr_() {} | ||
RangedExpr::RangedExpr(SetPiece range, UsesRanged expr) : range_(range), expr_(expr) {} | ||
|
||
member_imp(RangedExpr, SetPiece, range); | ||
member_imp(RangedExpr, UsesRanged, expr); | ||
|
||
std::string iterators[7] = {"i", "j", "k", "l", "m", "n", "o"}; | ||
|
||
std::ostream &operator<<(std::ostream &out, const RangedExpr &re) | ||
{ | ||
SetPiece mdi = re.range(); | ||
unsigned int sz = mdi.size(); | ||
if (sz > 0) { | ||
out << "for "; | ||
|
||
unsigned int j = 0; | ||
for (; j < sz - 1; j++) out << iterators[j] << " in " << mdi[j] << ", "; | ||
out << iterators[j] << " in " << mdi[j]; | ||
|
||
out << " loop\n" << re.expr() << "\nend for;"; | ||
} | ||
|
||
else out << re.expr(); | ||
|
||
return out; | ||
} | ||
|
||
EdgeInfo::EdgeInfo() : expr_() {} | ||
EdgeInfo::EdgeInfo(RangedExpr expr) : expr_(expr) {} | ||
|
||
member_imp(EdgeInfo, RangedExpr, expr); | ||
|
||
std::ostream &operator<<(std::ostream &out, const EdgeInfo &ei) | ||
{ | ||
out << ei.expr(); | ||
|
||
return out; | ||
} | ||
|
||
std::ostream &operator<<(std::ostream &out, const EdgesInfo &eei) | ||
{ | ||
BOOST_FOREACH (EdgeInfo ei, eei) out << ei << "\n"; | ||
|
||
return out; | ||
} | ||
|
||
} // namespace LIB | ||
|
||
} // namespace SBG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/** @file info.hpp | ||
@brief <b>SBG information structures</b> | ||
These structures were designed to keep information about variable names and | ||
equations definitions in the ModelicaCC context. In sense, they are an | ||
interface between Modelica code and the SBG representation. They store | ||
information to print Modelica-like code after each flatter/causalization | ||
stage in which an SBG is used. | ||
<hr> | ||
This file is part of Set--Based Graph Library. | ||
SBG Library is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
SBG Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with SBG Library. If not, see <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#ifndef SBG_INFO_HPP | ||
#define SBG_INFO_HPP | ||
|
||
#include <sbg/multidim_inter.hpp> | ||
#include <sbg/multidim_lexp.hpp> | ||
|
||
namespace SBG { | ||
|
||
namespace LIB { | ||
|
||
/** @struct DeclRanged | ||
* | ||
* @brief DeclRanged is used to represent the declaration of an array of | ||
* objects. | ||
* | ||
* In the Modelica context, the declaration of Real a[100] will result in the | ||
* creation of interval [700:799], so there will be a VertexInfo vi with a | ||
* DeclRanged dr such that dr.prefix = "Real", dr.name = "a", | ||
* dr.reps = [700:799]. | ||
*/ | ||
|
||
struct DeclRanged { | ||
member_class(std::string, prefix); | ||
member_class(std::string, name); | ||
member_class(SetPiece, reps); | ||
|
||
DeclRanged(); | ||
DeclRanged(std::string prefix, std::string name, SetPiece reps); | ||
}; | ||
std::ostream &operator<<(std::ostream &out, const DeclRanged &rd); | ||
|
||
typedef std::vector<DeclRanged> DeclsRanged; | ||
std::ostream &operator<<(std::ostream &out, const DeclsRanged &rd); | ||
|
||
struct VertexInfo { | ||
member_class(DeclRanged, decl); | ||
|
||
VertexInfo(); | ||
VertexInfo(DeclRanged decl); | ||
}; | ||
std::ostream &operator<<(std::ostream &out, const VertexInfo &vi); | ||
|
||
typedef std::vector<VertexInfo> VerticesInfo; | ||
std::ostream &operator<<(std::ostream &out, const VerticesInfo &vvi); | ||
|
||
/** @struct UseRanged | ||
* | ||
* @brief UseRanged should keep info about the use of an array of variables. | ||
* The trail member is used to specify any possible code between two | ||
* consecutive arrays. | ||
* | ||
* For example, when the array "a" is used by a loop: | ||
* for i [5:5:50] loop | ||
* a[i] = b[i]; | ||
* end for; | ||
* the corresponding UseRanged ur will be such that ur.prefix = "", | ||
* ur.name = "a", ur.subs = 1*x+0, ur.suffix = " = " | ||
*/ | ||
|
||
struct UseRanged { | ||
member_class(std::string, prefix); | ||
member_class(std::string, name); | ||
member_class(MDLExp, subs); | ||
member_class(std::string, suffix); | ||
|
||
UseRanged(); | ||
UseRanged(std::string prefix, std::string name, MDLExp subs, std::string suffix); | ||
}; | ||
std::ostream &operator<<(std::ostream &out, const UseRanged &rd); | ||
|
||
typedef std::vector<UseRanged> UsesRanged; | ||
std::ostream &operator<<(std::ostream &out, const UsesRanged &uur); | ||
|
||
struct RangedExpr { | ||
member_class(SetPiece, range); | ||
member_class(UsesRanged, expr); | ||
|
||
RangedExpr(); | ||
RangedExpr(SetPiece range, UsesRanged expr); | ||
}; | ||
std::ostream &operator<<(std::ostream &out, const RangedExpr &re); | ||
|
||
struct EdgeInfo { | ||
member_class(RangedExpr, expr); | ||
|
||
EdgeInfo(); | ||
EdgeInfo(RangedExpr expr); | ||
}; | ||
std::ostream &operator<<(std::ostream &out, const EdgeInfo &ri); | ||
|
||
typedef std::vector<EdgeInfo> EdgesInfo; | ||
std::ostream &operator<<(std::ostream &out, const EdgesInfo &eei); | ||
|
||
} // namespace LIB | ||
|
||
} // namespace SBG | ||
|
||
#endif |