00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024 #ifndef SHSECTION_HPP
00025 #define SHSECTION_HPP
00026
00027 #include <map>
00028 #include <list>
00029 #include <iosfwd>
00030 #include "ShDllExport.hpp"
00031 #include "ShInfo.hpp"
00032 #include "ShRefCount.hpp"
00033 #include "ShCtrlGraph.hpp"
00034 #include "ShStructural.hpp"
00035
00041
00042
00043
00044 namespace SH {
00045
00046
00047
00048
00049
00050 class ShSectionNode: public ShRefCountable {
00051 public:
00053 ShSectionNode();
00054
00055 typedef std::set<ShPointer<ShSectionNode> > SectionSet;
00056 typedef SectionSet::iterator iterator;
00057 typedef SectionSet::const_iterator const_iterator;
00058
00059 SectionSet children;
00060 ShSectionNode* parent;
00061
00062 iterator begin() { return children.begin(); }
00063 iterator end() { return children.end(); }
00064 const_iterator begin() const { return children.begin(); }
00065 const_iterator end() const { return children.end(); }
00066 void addChild(ShPointer<ShSectionNode> child);
00067
00068 typedef std::list<ShCtrlGraphNodePtr> CfgNodeList;
00069 typedef CfgNodeList::iterator cfg_iterator;
00070 typedef CfgNodeList::const_iterator const_cfg_iterator;
00071
00078 CfgNodeList cfgNodes;
00079
00080 cfg_iterator cfgBegin() { return cfgNodes.begin(); }
00081 cfg_iterator cfgEnd() { return cfgNodes.end(); }
00082 const_cfg_iterator cfgBegin() const { return cfgNodes.begin(); }
00083 const_cfg_iterator cfgEnd() const { return cfgNodes.end(); }
00084 void addCfg(ShCtrlGraphNodePtr cfgNode) { cfgNodes.push_back(cfgNode); }
00085
00086
00087 bool isRoot() const { return !parent; }
00088
00090 ShStatement* getStart();
00091 ShStatement* getEnd();
00092
00094 std::string name();
00095
00096
00097 int depth();
00098 };
00099 typedef ShPointer<ShSectionNode> ShSectionNodePtr;
00100
00101 class ShSectionTree {
00102 public:
00103 ShSectionNodePtr root;
00104
00105 ShSectionTree(ShStructural &structural);
00106
00107
00108
00109 template<class F>
00110 void dfs(F& functor);
00111
00112
00113 ShSectionNodePtr operator[](ShCtrlGraphNodePtr cfgNode);
00114
00115
00116
00117 bool contains(ShSectionNodePtr section, ShCtrlGraphNodePtr cfgNode);
00118
00119
00120 std::ostream& dump(std::ostream& out);
00121
00122
00123
00124
00125
00126
00127
00128
00129 template<class F>
00130 std::ostream& dump(std::ostream& out, F& functor);
00131
00132 private:
00133
00134 static void makeSection(ShStructuralNodePtr structNode, ShSectionNodePtr section);
00135
00136 typedef std::map<ShCtrlGraphNodePtr, ShSectionNodePtr> CfgSectionMap;
00137 CfgSectionMap cfgSection;
00138 void gatherCfgSection(ShSectionNodePtr section);
00139
00140
00141 template<class F>
00142 static void realDfs(ShSectionNodePtr node, F& functor);
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 template<class F>
00153 void realDump(std::ostream& out, std::ostream& cfgout, ShSectionNodePtr node, F& functor);
00154 };
00155
00156 }
00157
00158 #include "ShSectionImpl.hpp"
00159
00160 #endif