SummaryGraph.hpp

Go to the documentation of this file.
00001 #ifndef wali_graph_SUMMARY_GRAPH_H_
00002 #define wali_graph_SUMMARY_GRAPH_H_
00003 
00004 #include "wali/HashMap.hpp"
00005 
00006 #include "wali/wfa/WFA.hpp"
00007 
00008 #include "wali/graph/IntraGraph.hpp"
00009 #include "wali/graph/InterGraph.hpp"
00010 
00011 #include "wali/wpds/ewpds/ERule.hpp"
00012 
00013 namespace wali {
00014 
00015     namespace graph {
00016 
00017         class SummaryGraphStats {
00018             public:
00019                 clock_t t1,t2,t3,t4,t5; // for debugging and profiling
00020                 SummaryGraphStats() {
00021                     t1 = t2 = t3 = t4 = t5 = 0;
00022                 }
00023         };
00024 
00025         class SummaryGraphNode {
00026             public:
00027                 Transition trans;
00028                 reg_exp_t regexp;
00029                 int uno; // 0 if not updatable
00030                 sem_elem_t weight;
00031 
00032                 SummaryGraphNode() : trans(0,0,0), regexp(NULL), uno(-1),
00033                                      weight(NULL) { }
00034 
00035                 SummaryGraphNode(const SummaryGraphNode &n) : trans(n.trans), regexp(n.regexp),
00036                                                               uno(n.uno), weight(n.weight) { }
00037 
00038                 SummaryGraphNode(Transition &_trans, reg_exp_t &_regexp, int _uno, sem_elem_t _weight) : trans(_trans),
00039                                                                                                          regexp(_regexp), uno(_uno), weight(_weight) { } 
00040 
00041                 SummaryGraphNode(Transition &_trans) : trans(_trans),
00042                                                        regexp(NULL), uno(-1), weight(NULL) { } 
00043         };
00044 
00045         class SummaryGraph {
00046             private:
00047                 typedef wali::HashMap<int, int> StackGraphMap;
00048                 typedef std::map<Transition, int, TransitionCmp> TransMap;
00049 
00050                 InterGraphPtr post_igr;
00051                 Key init_state;
00052 
00053                 // The set of procedure entry nodes
00054                 set<Key> procEntries;
00055 
00056                 // IntraGraph to Key for procedure entry of the procedure
00057                 // represented by the InraGraph
00058                 std::map<IntraGraph *, Key> procEntryMap;
00059       
00060                 // Map to cache [k -> MOP(k,\epsilon)]
00061                 std::map<Key, sem_elem_t> popWeightMap;
00062 
00063                 // Map [Transition -> ERule used to create it]
00064                 std::map<Transition, wpds::ewpds::erule_t, TransitionCmp> eruleMap;
00065 
00066                 // Nodes that belong to multiple procedures
00067                 std::set<Key> multiple_proc_nodes;
00068 
00069                 StackGraphMap stack_graph_map;
00070                 std::list<IntraGraph *> changed_graphs;
00071                 std::set<IntraGraph *> updated_graphs;
00072 
00073                 InterGraph::PRINT_OP pkey;
00074                 SummaryGraphStats stats;
00075 
00076                 std::vector<SummaryGraphNode> nodes;
00077                 TransMap trans_map;
00078 
00079             public:
00080                 SummaryGraph(InterGraphPtr gr, 
00081                              wali::Key ss, 
00082                              set<Key> &pe, 
00083                              wfa::WFA &Agrow, 
00084                              InterGraph::PRINT_OP pop = InterGraph::defaultPrintOp);
00085 
00086                 ~SummaryGraph();
00087                 void preAddUpdate(Transition &t, sem_elem_t se);
00088                 void getUpdatedTransitions(std::list<WTransition> &ls);
00089                 void preGetUpdatedTransitions(std::list<WTransition> &ls);
00090                 void getMiddleTransitions(std::list<WTransition> &ls);
00091                 void summaryPoststar(wali::wfa::WFA const & ca_in, wali::wfa::WFA& ca_out);
00092 
00093                 sem_elem_t pushWeight(Key k);
00094                 sem_elem_t popWeight(Key k);
00095                 Key getEntry(Key k);
00096                 bool reachable(Key stk);
00097                 bool multiple_proc(Key stk);
00098 
00099                 ostream &printStats(ostream &out);
00100 
00101             private:
00102                 int stk2nodeno(int stk);
00103                 int trans2nodeno(Transition &tr);
00104                 int getIntraNodeNumber(Transition &tr);
00105                 void calculatePopWeights();
00106 
00107                 void addIntraTrans(Transition &tr, sem_elem_t wt, wfa::WFA &ca_out);
00108                 void addMiddleTrans(Transition &tr, sem_elem_t wt, wfa::WFA &ca_out);
00109                 Key changeStateGeneration(Key st, int gen);
00110 
00111         };
00112 
00113     } // namespace graph
00114 
00115 } // namespace wali
00116 
00117 #endif // wali_graph_SUMMARY_GRAPH_H_