graphProcessingSgIncGraph.h

Go to the documentation of this file.
00001 /*
00002 
00003 FINISH TEMPFLATPATH CODE
00004 
00005 */
00006 
00007 
00008 
00009 
00010 // Original Author (SgGraphTraversal mechanisms): Michael Hoffman
00011 //$id$
00012 #include<omp.h>
00013 #include <boost/regex.hpp> 
00014 #include <iostream>
00015 #include <fstream>
00016 #include <string>
00017 
00071 #include "staticCFG.h"
00072 #include <vector>
00073 #include <algorithm>
00074 #include <utility>
00075 #include <iostream>
00076 #include <sys/time.h>
00077 #include <sys/resource.h>
00078 //#include "graphBot.h"
00079 
00080 //This is necessary for technical reasons with regards to the graphnodeinheritedmap
00081 
00082 
00083 
00084 struct Bot {
00085     std::vector<std::vector<SgGraphNode*> > path;
00086     std::vector<std::set<SgGraphNode*> > pthloops;
00087     std::vector<SgGraphNode*> currpth;
00088     std::vector<std::pair<SgGraphNode*, int> > nodelst;
00089     bool on;
00090     bool remove;
00091 };
00092 
00093 double timeDifference(const struct timeval& end, const struct timeval& begin)
00094 {
00095     return (end.tv_sec + end.tv_usec / 1.0e6) - (begin.tv_sec + begin.tv_usec / 1.0e6);
00096 }
00097 
00098 static inline timeval getCPUTime() {
00099   rusage ru;
00100   getrusage(RUSAGE_SELF, &ru);
00101   return ru.ru_utime;
00102 }
00103 
00104 
00105 struct compareSgGraphNode {
00106     bool operator()(const SgGraphNode* a, const SgGraphNode* b) const
00107     {
00108         return a==b;
00109     }
00110 };
00111 
00112 
00113 /* The SgGraphTraversal class is utilized specifically for StaticCFG traversals,
00114 though the input must be in terms of a SgIncidenceDirectedGraph*/
00115 template <class InheritedAttributeType, class SynthesizedAttributeType>
00116 class SgGraphTraversal
00117 {
00118    public:
00119     std::set<std::map<int, std::set<int> > > subpathmap;
00120     int loopNum;
00121     int nullNum;
00122     std::set<SgDirectedGraphEdge*> nullEdgesOrdered;
00123     std::map<SgGraphNode*, int> loopNumMap;
00124     std::map<SgGraphNode*, int> pathValMap;
00125     int nullloops;
00126     std::vector<std::vector<SgGraphNode*> > looppaths;
00127     std::vector<std::vector<SgGraphNode*> > iLoops;
00128     std::vector<SgGraphNode*> ifstatements;
00129     virtual ~SgGraphTraversal(); 
00130     SgGraphTraversal(); 
00131     // Copy operations
00132     int nullEdgesPaths;
00133     int turns;
00134     SgGraphTraversal(const SgGraphTraversal &);
00135     const SgGraphTraversal &operator=(const SgGraphTraversal &);
00136     //This is not used, but will be important if SynthesizedAttributes become useful
00137     typedef StackFrameVector<SynthesizedAttributeType> SynthesizedAttributesList;
00138     //one of the most important structures in the algorithm, this attaches SgGraphNode*s to InheritedAttributeTypes so that
00139     //looking up the values is possible.
00140     //int numnodes;
00141     //std::map<SgGraphNode*, InheritedAttributeType> seen;
00142     int numnodes;
00143     //InheritedAttributeType pthgraphinherit;
00144     //StaticCFG::CFG* SgCFG;
00145     SgGraphNode* nullnode;
00146     std::map<SgGraphNode*, int> primenode;
00147     bool done;
00148     //std::set<SgGraphNode*> startnodes;
00149     std::set<SgGraphNode*> lstN;
00150     std::map<SgGraphNode*, std::vector<std::set<int> > > lstordmap;
00151     std::set<SgGraphNode*> solvedLoops;
00152     std::map<SgGraphNode*, std::vector<SgGraphNode*> > checkednodes; 
00153     std::map<SgGraphNode*, std::set<SgGraphNode*> > downed;
00154    
00155     //std::map<SgGraphNode*, int> nodeinedgordmap;
00156     //a value for nodes that have no value, set in the traverse function
00157     InheritedAttributeType nullInherit;
00158     //the user invoked function, runs the algorithm
00159     InheritedAttributeType traverse(SgGraphNode* basenode, SgIncidenceDirectedGraph* g,
00160             InheritedAttributeType inheritedValue, InheritedAttributeType nullInherit,
00161             SgGraphNode* endnode, bool insep = false, bool pcHk = false);
00162     std::set<SgGraphNode*> loopSet;
00163 
00164    protected:
00165     //User defined functions to do whatever is needed in evaluation
00166     //All the user gets access to is the node in question
00167     //and the values of the parent nodes (this should be all that is necessary)
00168     virtual InheritedAttributeType evaluateInheritedAttribute(SgGraphNode* n,
00169             std::vector<InheritedAttributeType> inheritedValues) = 0;
00170     //Not used, but may be useful if SynthesizedAttributes become workable in this context
00171     virtual SynthesizedAttributeType evaluateSynthesizedAttribute(SgGraphNode* n,
00172             InheritedAttributeType in,
00173             SynthesizedAttributesList l) = 0;
00174 
00175 #if !USE_ROSE
00176  // DQ (11/3/2011): EDG compilains about this (but GNU allowed it, I think that EDG might be correct,
00177  // namely that the value of a reference must be an lvalue (not NULL).  But since we are only trying 
00178  // to compile ROSE with ROSE (using the new EDG 4.3 front-end as a tests) we can just skip this case for now.
00179     virtual void pathAnalyze(std::vector<SgGraphNode*>& pth, bool loop=false, std::set<std::vector<SgGraphNode*> >& incloops=NULL) = 0;
00180 #else
00181     virtual void pathAnalyze(std::vector<SgGraphNode*>& pth, bool loop, std::set<std::vector<SgGraphNode*> >& incloops) = 0;
00182 #endif
00183 
00184     //also not used, but important for possible later use of SynthesizedAttributes
00185     SynthesizedAttributeType defaultSynthesizedAttribute(InheritedAttributeType);
00186    private:
00187     double distime;
00188     //std::set<std::pair<std::pair<SgGraphNode*, SgGraphNode*>, std::pair<SgGraphNode*, SgGraphNode*> > > flpset;
00189     //std::set<std::pair<std::pair<SgGraphNode*, SgGraphNode*>, std::pair<SgGraphNode*, SgGraphNode*> > > goodset;
00190     std::set<SgGraphNode*> ploops;
00191     std::map<SgGraphNode*, std::set<std::vector<SgGraphNode*> > > lpbegins;
00192     std::map<SgGraphNode*, int> frksLeft;
00193     int currm;
00194     int dpMax;
00195     int repEval;
00196     bool pathCheck;
00197     int pathsSize;
00198     //this constructs the graph tree for computation of inheritedValues
00199 
00200 
00201     std::map<SgGraphNode*, InheritedAttributeType> known;
00202     std::vector<InheritedAttributeType> connectNodes;
00203     std::map<SgGraphNode*, bool> solved;
00204     std::set<SgGraphNode*> solvedset;
00205     //these two are not used, but will be important if SynthesizedAttributes are made reasonable in this context
00206     SynthesizedAttributesList *synthesizedAttributes;
00207     SynthesizedAttributeType traversalResult();
00208     //finally we have two functions necessary for parallel processing if that is chosen to be used by the user
00209  
00210 
00211     
00212   
00213     std::map<SgGraphNode*, int> nodeInEdgesNum;
00214     int currprime;
00215     std::vector<SgGraphNode*> endnodefakes;
00216     std::map<SgGraphNode*, std::vector<std::vector<SgGraphNode*> > > pathsAtMk;
00217     std::set<SgGraphNode*> mkloops;
00218     std::map<SgGraphNode*, std::set<std::vector<SgGraphNode*> > > mkloopmap;
00219     std::map<SgGraphNode*, std::set<std::vector<SgGraphNode*> > > subPathsAtMk;
00220     std::vector<SgGraphNode*> mkglobal;
00221     std::vector<SgGraphNode*> clglobal;
00222     bool inseparable;
00223     void solvePaths(SgIncidenceDirectedGraph* g, SgGraphNode* n, SgGraphNode* endnode);
00224     std::vector<std::set<SgGraphNode*> > closuresVec;
00225     void evaluatePaths(SgIncidenceDirectedGraph* g, SgGraphNode* realstartnode, SgGraphNode* endnode);
00226     void evaluatePathsPar(SgIncidenceDirectedGraph* g, SgGraphNode* realstartnode, SgGraphNode* endnode);
00227     bool disjoint(std::vector<SgGraphNode*>& path, std::vector<SgGraphNode*>& vec2) const;
00228     std::set<std::vector<SgGraphNode*> > flatpaths;
00229 //    void evalNode(SgIncidenceDirectedGraph* g, SgGraphNode* n);
00230     bool canSolve(SgIncidenceDirectedGraph* g, SgGraphNode* n);
00231     std::map<SgGraphNode*, InheritedAttributeType> inhVals;
00232     std::set<SgDirectedGraphEdge*> seenEdges;
00233     std::set<SgDirectedGraphEdge*> nullEdges;
00234     std::set<SgGraphNode*> clsT;
00235     void computeOrder(SgIncidenceDirectedGraph* g, SgGraphNode* n, SgGraphNode* endnode);
00236     void computeInheritedOrdered(SgIncidenceDirectedGraph* g, SgGraphNode* n);
00237     std::pair<bool, SgGraphNode*> getNextPar(SgIncidenceDirectedGraph* g, SgGraphNode* n);
00238     std::pair<bool, SgGraphNode*> getNextChild(SgIncidenceDirectedGraph* g, SgGraphNode* n);
00239     bool computable(SgIncidenceDirectedGraph* g, SgGraphNode* n);
00240     void evalNodeOrdered(SgIncidenceDirectedGraph* g, SgGraphNode* n);
00241     std::map<SgGraphNode*, int> oVals;
00242     bool canEval(SgIncidenceDirectedGraph* g, SgGraphNode* n);
00243     void setPathVal(SgIncidenceDirectedGraph*g, SgGraphNode* n);
00244     void printNodePlusEdgesForAnalysis(SgIncidenceDirectedGraph* g, SgGraphNode* n, int loopNum, int pathVal, std::ofstream& ss);
00245     void printNodePlusEdgesForAnalysisPath(SgIncidenceDirectedGraph* g, std::vector<SgGraphNode*> n, int loopNum, int pathVal, std::ofstream& ss);
00246     void printNodeForAnalysis(SgGraphNode* n, int loopNum, int pathNum, std::ofstream& ss);
00247     std::set<SgGraphNode*> completedNodesPath;
00248     std::set<std::pair<SgGraphNode*, SgGraphNode*> > completedEdgesPath;
00249     void printEdgeForAnalysis(SgDirectedGraphEdge* e, bool isNullEdge, std::ofstream& ss);
00250     void printEdgeForAnalysisPath(SgGraphNode* g1, SgGraphNode* g2, std::ofstream& ss);
00251     std::map<int, SgGraphNode*> iVals;
00252     
00253     std::set<SgDirectedGraphEdge*> nullEdgesOrderedOut;
00254     std::set<SgDirectedGraphEdge*> completedEdgesOut;
00255     std::set<SgDirectedGraphEdge*> completedEdges;
00256     std::set<SgGraphNode*> compPar;
00257     std::set<SgGraphNode*> compChild;
00258     std::set<SgGraphNode*> computedNodes;
00259     SgGraphNode* st;
00260     SgGraphNode* en;
00261     double fllp;
00262     int loopnum;
00263     //std::set<SgGraphNode*> solved;
00264     //InheritedAttributeType findAndReverse(SgGraphNode* n, SgIncidenceDirectedGraph* g);
00265      //evaluateAllInheritedAttribute(std::vector<InheritedAttributeType> endNodeInhVec, SgGraphNode* endnode, std::vector<SgGraphNode*> nodes, std::vector<InheritedAttributeType> inh);
00266 //std::vector<InheritedAttributeType> getZeroInhs(std::vector<std::vector<std::vector<SgGraphNode*> > > qAnsSetSet, std::vector<InheritedAttributeType> endnodeInhVec, SgGraphNode* node);
00267 
00268 };
00269 
00270 
00271 
00272 /*
00273 template <class InheritedAttributeType, class SynthesizedAttributeType>
00274 void
00275 GraphBot<InheritedAttributeType, SynthesizedAttributeType>::
00276 travelDown(SgIncidenceDirectedGraph* g) {
00277     std::set<SgDirectedGraphEdge*> oedgs = g->computeEdgeSetOut(iAmHere);
00278     bool taken = false;
00279     if (oedgs.size() > 1) {
00280         std::set<SgDirectedGraphEdge*> edgeTrav = clEdgeTrav[iAmHere];
00281         ROSE_ASSERT(clEdgeTrav.find(iAmHere) != clEdgeTrav.end());
00282         for (std::set<SgDirectedGraphEdge*>::iterator i = oedgs.begin(); i != oedgs.end(); i++) {
00283             if (edgTrav.find(*i) == edgTrav.end() || !taken) {
00284                 taken = true;
00285                 iAmHere = (*i)->get_to();
00286                 lastEdge = *i;
00287             }
00288         }
00289     }
00290     else {
00291         iAmHere = (*(oedgs.begin())->get_to();
00292     }
00293 }
00294 */
00295 
00296 
00297 
00298 
00299 
00300 
00301 /*
00302 ***************************
00303 Various Admin Functions
00304 ***************************
00305 */
00306 template<class InheritedAttributeType, class SynthesizedAttributeType>
00307 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
00308 SgGraphTraversal()
00309   : synthesizedAttributes(new SynthesizedAttributesList())
00310 {
00311 }
00312 
00313 #ifndef SWIG
00314 
00315 template<class InheritedAttributeType, class SynthesizedAttributeType>
00316 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
00317 ~SgGraphTraversal()
00318 {
00319         ROSE_ASSERT(synthesizedAttributes != NULL);
00320         delete synthesizedAttributes;
00321         synthesizedAttributes = NULL;
00322 }
00323 
00324 #endif
00325 
00326 
00327 template<class InheritedAttributeType, class SynthesizedAttributeType>
00328 const SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType> &
00329 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
00330 operator=(const SgGraphTraversal &other)
00331 {
00332 
00333     ROSE_ASSERT(synthesizedAttributes != NULL);
00334     delete synthesizedAttributes;
00335     synthesizedAttributes = other.synthesizedAttributes->deepCopy();
00336 
00337     return *this;
00338 }
00339 
00357 template<class InheritedAttributeType, class SynthesizedAttributeType>
00358 InheritedAttributeType
00359 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
00360 traverse(SgGraphNode* n, SgIncidenceDirectedGraph* g, InheritedAttributeType inheritedValue, InheritedAttributeType nullI, SgGraphNode* endnode, bool insep, bool pCh) {
00361    //numnodes = 0;
00362    //primes.clear();
00363     looppaths.clear();
00364     iLoops.clear();
00365     completedEdgesPath.clear();
00366     pathValMap.clear();
00367     loopNumMap.clear();
00368     nullloops = 0;
00369     nullEdgesPaths = 0;
00370     fllp = 0.0;
00371     mkglobal.clear();
00372     clglobal.clear();
00373   
00374     lpbegins.clear();
00375     //currents.clear();
00376    inhVals.clear();
00377    iVals.clear();
00378    oVals.clear();
00379    //reservedEdges.clear();
00380    completedEdges.clear();
00381    completedEdgesOut.clear();
00382    //completedNodes.clear();
00383    computedNodes.clear();
00384    nullEdgesOrdered.clear();
00385    nullEdgesOrderedOut.clear();
00386    loopSet.clear();
00387    pathsAtMk.clear();
00388    
00389    st = n;
00390    en = endnode;
00391    distime = 0.0;
00392    int currm = 1;
00393    int turns = 0;
00394    pathsSize = 0;
00395    done = false;
00396    numnodes = 1;
00397    std::cout << "starting traversal" << std::endl;
00398    pathCheck = pCh;
00399    currprime = 1;
00400    inseparable = insep;
00401    synthesizedAttributes->resetStack();
00402    ROSE_ASSERT(synthesizedAttributes->debugSize() == 0);
00403    //SgCFG = cfg;
00404    inhVals[n] = inheritedValue;
00405    //GraphBot<InheritedAttributeType, SynthesizedAttributeType>::inhVals[n] = inheritedValue;
00406    //primes = generatePrimesSieve();
00407    
00408   
00409 //   graphnodeinheritedordmap[ncpy] = inheritedValue;
00410 //   nodenodeordmap[ncpy] = n;
00411 //   std::vector<SgGraphNode*> lst;
00412 //   lst.push_back(n);
00413 //   lstordmap[ncpy] = lst;
00414 
00415    nullInherit = nullI;
00416 InheritedAttributeType inh;
00417    struct timeval t1, t2, t3, t4, t5, t6, t7, t8;
00418    //else {
00419        loopnum = 0;
00420        //InheritedAttributeType inh;
00421        t1 = getCPUTime();
00422        
00423        //this function essentially sets up for the evaluate later, it makes putting together the paths much easier
00424        solvePaths(g, n, endnode);
00425 
00426        t2 = getCPUTime();
00427 
00428 //making sure that endnode hasn't already been evaluated before the traversal starts, unlikely but just in case
00429        ROSE_ASSERT(inhVals.find(endnode) == inhVals.end());
00430 
00431        std::cout << "solvePaths done" << std::endl;
00432        double diff = timeDifference(t2, t1);
00433        t5 = getCPUTime();
00434        //InheritedAttributeType pthgraphinherit = botTraverse(g, n, endnode);
00435        oVals[n] = 0;
00436        iVals[0] = n;
00437        pathValMap[n] = 1;
00438 //inserting n as a computed node
00439        computedNodes.insert(n);
00440 //computes the order in which the nodes must be evaluated, makes computeInheritedOrdered much faster
00441        computeOrder(g, n, endnode);
00442        std::cout << "order computed" << std::endl;
00443 //computes the nodal inheritance values
00444        computeInheritedOrdered(g, n);
00445        std::cout << "inheritance computed" << std::endl;
00446        ROSE_ASSERT(oVals.find(endnode) != oVals.end());
00447        ROSE_ASSERT(inhVals.find(endnode) != inhVals.end());
00448 //value at the endnode
00449        InheritedAttributeType pthgraphinherit = inhVals[endnode];
00450        //= evaluateGraph(g, n, endnode, inheritedValue);
00451        t6 = getCPUTime();
00452        std::cout << "evaluateGraph done" << std::endl;
00453        double diff3 = timeDifference(t6, t5);
00454        t3 = getCPUTime();
00455 //actually evaluates every path with a user defined pathAnalyze function
00456        //for (int i = 0; i < 10; i++) {
00457        evaluatePaths(g, n, endnode);
00458        //}
00459        t4 = getCPUTime();
00460        
00461        t7 = getCPUTime();
00462        //evaluatePathsPar(g, n, endnode);
00463        t8 = getCPUTime();
00464        
00465        std::cout << "evaluatePaths done " << std::endl;
00466        double diff2 = timeDifference(t4, t3);
00467        double diff2Par = timeDifference(t8, t7);
00468        std::cout << "pathsolve took: " << diff << std::endl;
00469        std::cout << "patheval took: " << diff2 << std::endl;
00470        std::cout << "parpatheval took: " << diff2Par << std::endl;
00471        std::cout << "grapheval took: " << diff3 << std::endl;
00472        std::cout << "entire pathsolve took: " << diff+diff2+diff3+diff2Par << std::endl;
00473        std::cout << "potential loops: " << nullEdgesOrdered.size() << std::endl;
00474        std::cout << "nullNum: " << nullNum << std::endl;
00475        //std::cout << "goodsets: " << goodset.size() << std::endl;
00476        //std::cout << "flpsets: " << flpset.size() << std::endl;
00477        std::cout << "mkloops: " << mkloops.size() << std::endl;
00478        std::cout << "distime: " << distime << std::endl;
00479        std::cout << "fllp: " << fllp << std::endl;
00480        return pthgraphinherit;
00481    //}
00482    //std::cout << "number of endnodefakes: " << endnodefakes.size() << std::endl;
00483    //std::cout << "should be number of nodes: " << currprime << std::endl;
00484    //if (pathanalysis == true) {
00485      // analyzepaths(endnode, g);
00486    //}
00487    //return inh;
00488    //Currently this is not very useful, but it does nothing if traversalResult is not set.
00489 }
00490 
00491 /* WARNING:
00492    This is not a general is_disjoint. It skips the 
00493 first element of the second set because in the way I assemble
00494 paths the last element of the path and the first element of addend
00495 must be the same. Hence I simply skip the first node
00496 */
00497 bool is_disjoint(std::set<SgGraphNode*> set1, std::set<SgGraphNode*> set2) {
00498  
00499    if (set1.empty() || set2.empty()) {
00500        return true;
00501    }
00502    std::set<SgGraphNode*>::iterator it1 = set1.begin();
00503    std::set<SgGraphNode*>::iterator it2 = set2.begin();
00504    std::set<SgGraphNode*>::iterator it1End = set1.end();
00505    std::set<SgGraphNode*>::iterator it2End = set2.end();
00506 
00507     if (*it1 > *set2.rbegin() || *it2 > *set1.rbegin()) {
00508         return true;
00509     }
00510     
00511     while (it1 != it1End && it2 != it2End) {
00512         if (*it1 == *it2) {
00513             return false;
00514         }
00515         if (*it1 < *it2) {
00516             it1++;
00517         }
00518         else {
00519             it2++;
00520         }
00521      }
00522      return true;
00523 }   
00524 
00525 
00526 
00527 //Checks for disjoint, necessary in computing the paths
00528 template<class InheritedAttributeType, class SynthesizedAttributeType>
00529 bool
00530 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
00531 disjoint(std::vector<SgGraphNode*>& pthloops, std::vector<SgGraphNode*>& vec2) const {
00532 /*
00533     time_t t1, t2;
00534     time(&t1);
00535     int a = 0;
00536     std::set<SgGraphNode*> s1;
00537     std::set<SgGraphNode*> s2;
00538     std::vector<SgGraphNode*> mkloopvec;
00539     bool goodsetbool;
00540     bool pbool = true;
00541     //std::cout << "calculating disjoint" << std::endl;
00542     ROSE_ASSERT((path.back()).back() == vec2.front());
00543 
00544     //copy(vec2.begin(), vec2.end(), inserter(s2, s2.end()));
00545 /*
00546     for (int i = 0; i < vec2.size(); i++) {
00547         if (ploops.find(vec2[i]) != ploops.end()) {
00548             pbool = false;
00549         }
00550     }
00551     if (pbool) {
00552         return true;
00553     }
00554     if (
00555 */  //for (int q = 0; q < pthloops->size(); q++) {
00556         for (int i = 0; i < pthloops.size(); i++) {
00557             if (find(vec2.begin(), vec2.end(), pthloops[i]) != vec2.end()) {
00558                 return false;
00559             }
00560         }
00561         return true;
00562 }
00563 /*
00564     if (pbool) {
00565         time(&t2);
00566         double diff = difftime(t2, t1);
00567         distime += diff;
00568         return true;
00569     }
00570     for (unsigned int k = 0; k < path.size(); k++) {
00571         s1.clear();
00572 */
00573 /*
00574         pbool = true;
00575         for (int p = 0; p < path[k].size(); p++) {
00576             if (ploops.find(path[k][p]) != ploops.end()) {
00577                 pbool = false;
00578             }
00579         }
00580 //        copy(path[k].begin(), path[k].end(), inserter(s1, s1.end()));
00581         if (!pbool) {
00582 */
00583 /*
00584         std::pair<std::pair<SgGraphNode*, SgGraphNode*>, std::pair<SgGraphNode*, SgGraphNode*> > flp;
00585         flp.second.first = vec2[0];
00586         flp.second.first = vec2[1];
00587 
00588         flp.first.first = path[k][0];
00589         flp.first.second = path[k][1];
00590         if (vec2.front() == vec2.back()) {
00591         time(&t2);
00592         double diff = difftime(t2, t1);
00593         distime += diff;
00594 
00595             return false;
00596         }
00597         if (flpset.find(flp) != flpset.end()) {
00598             //std::cout << "already seen" << std::endl;
00599         time(&t2);
00600         double diff = difftime(t2, t1);
00601         distime += diff;
00602 
00603             return false;
00604         }
00605 */
00606 /*
00607         else if (goodset.find(flp) != goodset.end()) {
00608             goodsetbool = true;
00609         }
00610 */
00611 /*
00612         if (is_disjoint(s1,s2)) {
00613             //goodset.insert(flp);
00614             continue;
00615         }
00616         else {
00617             return false;
00618         }
00619 */
00620 /*
00621        else {
00622         std::vector<SgGraphNode*> vec1 = path[k];
00623         
00624         //for (unsigned int i = 0; i < vec1.size(); i++) {
00625             for (unsigned int j = 0; j < mkloopvec.size(); j++) {
00626                 std::vector<SgGraphNode*>::iterator q = find(vec1.begin(), vec1.end(), mkloopvec[j]);
00627                 if (q != vec1.end()) {
00628                     if (*q != vec1[vec1.size() - 1] || j != 0) {
00629                         
00630                         flpset.insert(flp);
00631       //                  std::cout << "not disjoint" << std::endl;
00632         time(&t2);
00633         double diff = difftime(t2, t1);
00634         distime += diff;
00635 
00636                         return false;
00637                     }
00638                 }
00639             }
00640         //}
00641         //goodset.insert(flp);
00642     }
00643     }
00644     //}
00645 */
00646 
00647     
00648 /*
00649     for (unsigned int p = 0; p < vec2.size(); p++) {
00650         for (unsigned int q = 0; q < vec2.size(); q++) {
00651             if (p != q) {
00652                 if (vec2[p] == vec2[q]) {
00653                     return false;
00654                 }
00655             }
00656         }
00657     }
00658 */
00659 /*
00660         time(&t2);
00661         double diff = difftime(t2, t1);
00662         distime += diff;
00663 
00664     return true;
00665 }
00666 */
00667 //checks for solvability of a node in nodal analysis
00668 
00669 template<class InheritedAttributeType, class SynthesizedAttributeType>
00670 bool
00671 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
00672 canSolve(SgIncidenceDirectedGraph* g, SgGraphNode* n) {
00673     bool loop = false;
00674     if (inhVals.find(n) != inhVals.end()) {
00675         return true;
00676     }
00677     std::set<SgDirectedGraphEdge*> oed = g->computeEdgeSetIn(n);
00678     if (oed.size() == 0) {
00679         return false;
00680     }
00681         for (std::set<SgDirectedGraphEdge*>::iterator i = oed.begin(); i != oed.end(); i++) {
00682             if (inhVals.find((*i)->get_from()) == inhVals.end() && nullEdges.find(*i) == nullEdges.end()) {
00683                 return false;
00684             }
00685         }
00686    return true;
00687 } 
00688 
00689 //this function evaluates values of paths via the user-defined pathAnalyze function
00690 
00691 template<class InheritedAttributeType, class SynthesizedAttributeType>
00692 void
00693 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
00694 evaluatePathsPar(SgIncidenceDirectedGraph* g, SgGraphNode* realstartnode, SgGraphNode* endnode) {
00695 std::vector<std::vector<SgGraphNode*> > path;
00696 std::vector<SgGraphNode*> spath;
00697 SgGraphNode* n = realstartnode;
00698 int successes = 0;
00699 int failures = 0;
00700 int j = 0;
00701 std::vector<SgGraphNode*> currpthorg;
00702 int currint = 0;
00703 std::map<SgGraphNode*, int> intPath;
00704 intPath[n] = currint;
00705 currint++;
00706 std::map<SgGraphNode*, int> currents;
00707 SgGraphNode* currnode;
00708 bool step = false;
00709 bool midstep = false;
00710 
00711 //note: pathsAtMk is referring to subpaths connected to that marker, a marker is a split in the graph (usually an if statement)
00712 
00713 std::vector<std::vector<SgGraphNode*> > pth = pathsAtMk[realstartnode];
00714 std::vector<std::vector<SgGraphNode*> > cpth = pathsAtMk[realstartnode];
00715     path.clear();
00716     int disjoints = 0;
00717     int disjointtrues = 0;
00718     currpthorg = pth[0];
00719     intPath[pth[0].front()] = currint;
00720     std::set<SgGraphNode*> pthloopstmp;
00721     SgGraphNode* fakenode;
00722     pthloopstmp.insert(fakenode);
00723     std::vector<std::set<SgGraphNode*> > pthloops;
00724     pthloops.push_back(pthloopstmp);
00725     pthloopstmp.clear();
00726     currint++;
00727     
00728     int stepnum = 0;
00729     std::vector<SgGraphNode*> rs;
00730     rs.push_back(realstartnode);
00731     path.push_back(rs);
00732     currents.clear();
00733 
00734     step = false;
00735     std::vector<SgGraphNode*> sub;
00736 
00737 
00738     std::set<std::vector<SgGraphNode*> > nullIncLoops;
00739     std::vector<struct Bot*> todobotlst;
00740     std::vector<struct Bot*> botlst;
00741     struct Bot* rootBot = new Bot;
00742     rootBot->remove = false;
00743     
00744     rootBot->path = path;
00745     rootBot->currpth = currpthorg;
00746     rootBot->pthloops = pthloops;
00747     rootBot->on = true;
00748      botlst.push_back(rootBot);
00749     int tip = 1;
00750     int ti = 1;
00751     std::vector<std::pair<std::vector<SgGraphNode*>, std::vector<std::set<SgGraphNode*> > > > collectedPaths;
00752     int maxlst = 0;
00753     while (true) {
00754     if (todobotlst.size()+botlst.size() > maxlst) {
00755         maxlst = todobotlst.size()+botlst.size();
00756         std::cout << "maxlst: " << maxlst << std::endl;
00757         std::cout << "todobotlst.size(): " << todobotlst.size() << std::endl;
00758         std::cout << "botlst.size(): " << botlst.size() << std::endl;
00759     }
00760     int MAXBOTS = 10000;
00761     int MINPATHS = 1000;
00762     int LOCALMAXBOTS = 10;
00763     int LOCALMAXNODES = 0;
00764     std::vector<struct Bot*> lstnullbot;
00765     std::vector<std::vector<struct Bot*> > newbotlsts (MAXBOTS, lstnullbot);
00766     //std::vector<struct Bot*> newbotlsts (MAXBOTS, lstnullbot);
00767     //tip = ti;
00768     //ti = 0;
00769     ROSE_ASSERT(botlst.size() >= 0);
00770     if (botlst.size() == 0) {
00771         if (todobotlst.size() != 0) {
00772             while (todobotlst.size() > 0 && botlst.size() < MAXBOTS) {
00773                 todobotlst.back()->on = true;
00774                 botlst.push_back(todobotlst.back());
00775                 todobotlst.pop_back();
00776             }
00777         }
00778         else {
00779             if (collectedPaths.size() > 0) {
00780                   for (int i = 0; i < collectedPaths.size(); i++) {
00781                   std::set<std::vector<SgGraphNode*> > incloops;
00782                   std::vector<std::set<SgGraphNode*> > pthloops = collectedPaths[i].second;
00783                   for (int q = 0; q < pthloops.size(); q++) {
00784                   for (std::set<SgGraphNode*>::iterator p = pthloops[q].begin(); p != pthloops[q].end(); p++) {
00785                     for (std::set<std::vector<SgGraphNode*> >::iterator o = mkloopmap[*p].begin(); o != mkloopmap[*p].end(); o++) {
00786                         incloops.insert(*o);
00787                     }
00788                  }
00789                  }
00790 
00791 
00792         pathAnalyze(collectedPaths[i].first, false, incloops);
00793     }
00794     collectedPaths.clear();
00795             }
00796             break;
00797         }
00798     }
00799     if (botlst.size() > 0) {
00800     std::pair<std::vector<SgGraphNode*>, std::vector<std::set<SgGraphNode*> > > nullpr;
00801     std::vector<std::pair<std::vector<SgGraphNode*>, std::vector<std::set<SgGraphNode*> > > > newpathslst (MAXBOTS, nullpr);
00802     #pragma omp parallel for
00803     for (int i = 0; i < botlst.size(); i++) {
00804         //std::map<SgGraphNode*, std::set<std::vector<SgGraphNode*> > > mkloopmaptmp = mkloopmap;
00805         std::vector<struct Bot*> localbotlst;
00806         std::pair<std::vector<SgGraphNode*>, std::vector<std::set<SgGraphNode*> > > localnewpath;
00807         struct Bot* currBot = botlst[i];
00808         if (currBot->on) {
00809         std::vector<SgGraphNode*> currpth = currBot->currpth;
00810         std::vector<std::vector<SgGraphNode*> > path = currBot->path;
00811         std::vector<std::set<SgGraphNode*> > pthloops = currBot->pthloops;
00812         
00813             if (currpth.back() == endnode) {
00814             path.push_back(currpth);
00815             std::vector<SgGraphNode*> flatpath;
00816             std::set<std::vector<SgGraphNode*> > incloops;
00817             struct timeval q1, q2;
00818             ROSE_ASSERT(path.size() == pthloops.size() + 1);
00819             q1 = getCPUTime();
00820             for (unsigned int q = 0; q < pthloops.size(); q++) {
00821                 for (unsigned int r = 0; r < path[q].size(); r++) {
00822                     flatpath.push_back(path[q][r]);
00823                 }
00824 
00825 /*
00826 #pragma omp critical
00827 {
00828                 for (std::set<SgGraphNode*>::iterator p = pthloops[q].begin(); p != pthloops[q].end(); p++) {
00829                     for (std::set<std::vector<SgGraphNode*> >::iterator o = mkloopmap[*p].begin(); o != mkloopmap[*p].end(); o++) {
00830                         incloops.insert(*o);
00831                     }
00832                  }
00833 }
00834 */
00835 
00836              }
00837 
00838              for (unsigned int pt2 = 0; pt2 < path[path.size()-1].size(); pt2++) {
00839                      flatpath.push_back(path[path.size()-1][pt2]);
00840              }             
00841              q2 = getCPUTime();
00842              fllp += timeDifference(q2,q1);
00843              flatpath.push_back(endnode);
00844 //user defined function, run on the final path, gives the user loops that are included via "incloops" a set of vectors that contain the individual loops
00845 /*
00846              #pragma omp critical (analyze)
00847 {
00848              pathAnalyze(flatpath, false, incloops);
00849 }
00850 */
00851              std::pair<std::vector<SgGraphNode*> , std::vector<std::set<SgGraphNode*> > > newcol;
00852              newcol.first = flatpath;
00853              newcol.second = pthloops;
00854              localnewpath = newcol;
00855              incloops.clear();
00856 
00857              int pts = pathsSize++;
00858              pathsSize += 1;
00859             
00860              flatpath.clear();
00861              path.pop_back();
00862              int rounds = 0;
00863              bool starter = false;
00864 
00865 // This gets a bit complicated so here is an overview:
00866 // This is running down the graph and finding the endnode. Once it finds the endnode it goes back up to the last unevaluated subpath. It does this quickly with an integer that counts how many times that node has been used for a path. If this ends up being the number of outnodes, we don't need that node anymore, so we clear it to zero, then continue up the graph. We HAVE to reset because every time a new pathway is chosen above that node, it needs to have the ability to traverse that node.
00867 /*
00868               if (currBot->nodelst.size() != 0) {
00869                    while (path.back().back() != currBot->nodelst.back().first) {
00870                        ROSE_ASSERT(path.size() != 0);
00871                        path.pop_back();
00872                        pthloops.pop_back();
00873                        
00874                    }
00875                    currBot->path = path;
00876                    currBot->pthloops = pthloops;
00877                    currBot->currpth = pathsAtMk[(path.back()).back()][currBot->nodelst.back().second];
00878                    currBot->nodelst.pop_back();
00879                    localbotlst.push_back(currBot);
00880              }
00881              else {
00882 */
00883                  currBot->remove = true;
00884                  localbotlst.push_back(currBot);
00885              //}
00886          }
00887          else {
00888 
00889 //this checks first to see if we have any loops in our path. If not it continues down, if there is it goes back to the last nonloop node
00890         bool disj = true;
00891         struct timeval tdisb, tdise;
00892         //tdisb = getCPUTime();
00893         for (int x = 0; x < pthloops.size(); x++) {
00894             for (std::set<SgGraphNode*>::iterator j = pthloops[x].begin(); j != pthloops[x].end(); j++) {
00895                 if (find(currpth.begin(), currpth.end(), *j) != currpth.end()) {
00896                     disj = false;
00897                 }
00898              }
00899         }
00900         //tdise = getCPUTime();
00901         //distime += timeDifference(tdise, tdisb);
00902         if (disj) {
00903             
00904             disjointtrues++;
00905             //std::cout << "disjoints: " << disjointtrues << std::endl;
00906             midstep = false;
00907 std::set<SgGraphNode*> pthloopstmp;
00908             pthloopstmp.clear();
00909                 for (int i = 0; i < currpth.size(); i++) {
00910                     //currflat.push_back(currpth[i]);
00911                     if (mkloops.find(currpth[i]) != mkloops.end()) {
00912                        pthloopstmp.insert(currpth[i]);
00913                     }
00914                 }
00915                 pthloops.push_back(pthloopstmp);
00916                 path.push_back(currpth);
00917                 pthloopstmp.clear();
00918                 
00919                 //std::set<std::vector<SgGraphNode*> > lpth;
00920                 std::vector<SgGraphNode*> oldcurrpth = currpth;
00921                 currpth.clear();
00922                         SgGraphNode* frontnode = (path.back()).front();
00923                         SgGraphNode* backnode = (path.back()).back();
00924      
00925                         ROSE_ASSERT(pathsAtMk.find(backnode) != pathsAtMk.end() || backnode == endnode);
00926                         ROSE_ASSERT(pathsAtMk.find(frontnode) != pathsAtMk.end());
00927                         std::vector<std::vector<SgGraphNode*> > tmppths = pathsAtMk[backnode];
00928                         currBot->currpth = tmppths[0];
00929                         currBot->path = path;
00930                         currBot->pthloops = pthloops;
00931                         //newbotlst.push_back(currBot);
00932                         for (int tp = 1; tp < tmppths.size(); tp++) {
00933                             //if (localbotlst.size() < LOCALMAXBOTS) {
00934 /*
00935                             if (currBot->nodelst.size() < LOCALMAXNODES) {
00936                                 std::pair<SgGraphNode*, int> cur;
00937                                 cur.second = tp;
00938                                 cur.first = path.back().back();
00939                                 currBot->nodelst.push_back(cur);
00940                             }
00941                             else {
00942 */
00943                                 struct Bot* newBot = new Bot;
00944                                 newBot->remove = false;
00945                                 newBot->currpth = tmppths[tp];
00946                                 newBot->path = path;
00947                                 newBot->pthloops = pthloops;
00948                                 localbotlst.push_back(newBot);
00949                                 //ti++;
00950  //                           }
00951                         }
00952                         localbotlst.push_back(currBot);
00953                         //ti++;
00954          }          
00955          else {
00956 /*
00957                if (currBot->nodelst.size() != 0) {
00958                    while (path.back().back() != currBot->nodelst.back().first) {
00959                        ROSE_ASSERT(path.size() != 0);
00960                        path.pop_back();
00961                        pthloops.pop_back();
00962                        
00963                    }
00964                    currBot->path = path;
00965                    currBot->pthloops = pthloops;
00966                    currBot->currpth =  pathsAtMk[(path.back()).back()][currBot->nodelst.back().second];
00967                    currBot->nodelst.pop_back();
00968                    localbotlst.push_back(currBot);
00969                    //ti++;
00970              }
00971 
00972              else {
00973 */
00974                  currBot->remove = true;
00975                  localbotlst.push_back(currBot);
00976                  //delete currBot;
00977  //            }
00978 
00979         }
00980      }
00981  newpathslst[i] = localnewpath;
00982  newbotlsts[i] = localbotlst;
00983  }
00984 }
00985  botlst.clear();
00986  int num = 0;
00987 
00988  for (int i = 0; i < newbotlsts.size(); i++) {
00989     if (newpathslst[i].first.size() > 0) {
00990         collectedPaths.push_back(newpathslst[i]);
00991     }
00992     for (int j = 0; j < newbotlsts[i].size(); j++) {
00993         if (newbotlsts[i][j]->remove == true) {
00994             delete newbotlsts[i][j];
00995         }
00996         else if (num < MAXBOTS) {
00997             newbotlsts[i][j]->on = true;
00998             botlst.push_back(newbotlsts[i][j]);
00999             num++;
01000         }
01001         else {
01002             newbotlsts[i][j]->on = false;
01003             todobotlst.push_back(newbotlsts[i][j]);
01004         }
01005     }
01006 }
01007 
01008 if (collectedPaths.size() > MINPATHS) {
01009           
01010     for (int i = 0; i < collectedPaths.size(); i++) {
01011                  std::vector<std::set<SgGraphNode*> > pthloops;   
01012                 std::set<std::vector<SgGraphNode*> > incloops;
01013                 pthloops = collectedPaths[i].second;
01014                 for (int q = 0; q < pthloops.size(); q++) {
01015                 for (std::set<SgGraphNode*>::iterator p = pthloops[q].begin(); p != pthloops[q].end(); p++) {
01016                     for (std::set<std::vector<SgGraphNode*> >::iterator o = mkloopmap[*p].begin(); o != mkloopmap[*p].end(); o++) {
01017                         incloops.insert(*o);
01018                     }
01019                  }
01020                }
01021 
01022         pathAnalyze(collectedPaths[i].first, false, incloops);
01023     }
01024     collectedPaths.clear();
01025 }
01026 }
01027  else {
01028             if (collectedPaths.size() > 0) {
01029             for (int i = 0; i < collectedPaths.size(); i++) {
01030                 std::set<std::vector<SgGraphNode*> > incloops;
01031                 pthloops = collectedPaths[i].second;
01032                 for (int q = 0; q < pthloops.size(); q++) {
01033                 for (std::set<SgGraphNode*>::iterator p = pthloops[q].begin(); p != pthloops[q].end(); p++) {
01034                     for (std::set<std::vector<SgGraphNode*> >::iterator o = mkloopmap[*p].begin(); o != mkloopmap[*p].end(); o++) {
01035                         incloops.insert(*o);
01036                     }
01037                  }
01038                }
01039  
01040         pathAnalyze(collectedPaths[i].first, false, incloops);
01041     }
01042     }
01043     collectedPaths.clear();
01044  break;
01045  }
01046 }
01047 
01048 std::cout << "successes: " << successes << std::endl;
01049 std::cout << "failures: " << failures << std::endl;
01050 std::cout << "maxlst: " << maxlst << std::endl;
01051 return;
01052 }
01053 
01054 
01055 
01056 template<class InheritedAttributeType, class SynthesizedAttributeType>
01057 void
01058 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01059 evaluatePaths(SgIncidenceDirectedGraph* g, SgGraphNode* realstartnode, SgGraphNode* endnode) {
01060 //std::set<SgGraphNode*> seen;
01061 //for (std::map<SgGraphNode*, std::vector<std::vector<SgGraphNode*> > >::iterator i = pathsAtMk.begin(); i != pathsAtMk.end(); i++) {
01062 /*    
01063     std::vector<std::vector<SgGraphNode*> > tocheck = (*i).second;
01064     for (int j = 0; j < tocheck.size(); j++) {
01065         for (int k = 0; k < tocheck[j].size(); k++) {
01066             if (seen.find(tocheck[j][k]) != seen.end()) {
01067                 ploops.insert(tocheck[j][k]);
01068             }
01069             else {
01070                 seen.insert(tocheck[j][k]);
01071             }
01072         }
01073     }
01074 }
01075 */     
01076 std::vector<std::vector<SgGraphNode*> > path;
01077 std::vector<SgGraphNode*> spath;
01078 SgGraphNode* n = realstartnode;
01079 int successes = 0;
01080 int failures = 0;
01081 int j = 0;
01082 std::vector<SgGraphNode*> currpth;
01083 int currint = 0;
01084 std::map<SgGraphNode*, int> intPath;
01085 intPath[n] = currint;
01086 currint++;
01087 std::map<SgGraphNode*, int> currents;
01088 SgGraphNode* currnode;
01089 bool step = false;
01090 bool midstep = false;
01091 
01092 //note: pathsAtMk is referring to subpaths connected to that marker, a marker is a split in the graph (usually an if statement)
01093 
01094 std::vector<std::vector<SgGraphNode*> > pth = pathsAtMk[realstartnode];
01095 std::vector<std::vector<SgGraphNode*> > cpth = pathsAtMk[realstartnode];
01096     path.clear();
01097     int disjoints = 0;
01098     int disjointtrues = 0;
01099     currpth = pth[0];
01100     intPath[pth[0].front()] = currint;
01101     std::set<SgGraphNode*> pthloopstmp;
01102     SgGraphNode* fakenode;
01103     pthloopstmp.insert(fakenode);
01104     std::vector<std::set<SgGraphNode*> > pthloops;
01105     pthloops.push_back(pthloopstmp);
01106     pthloopstmp.clear();
01107     currint++;
01108     
01109     int stepnum = 0;
01110     std::vector<SgGraphNode*> rs;
01111     rs.push_back(realstartnode);
01112     path.push_back(rs);
01113     //currflat.push_back(realstartnode);
01114     currents.clear();
01115 
01116     step = false;
01117     //std::vector<SgGraphNode*> currflat;
01118     std::vector<SgGraphNode*> sub;
01119 
01120 /*
01121     std::ofstream mz;
01122     mz.open("pathanalysis.dot");
01123     mz << "digraph defaultName { \n";
01124 */
01125     std::set<std::vector<SgGraphNode*> > nullIncLoops;
01126 
01127 /*
01128     for (unsigned int p = 0; p < looppaths.size(); p++) {
01129         std::vector<SgGraphNode*> lp = looppaths[p];
01130 
01131         for (unsigned int i = 0; i < lp.size()-1; i++) {
01132             for (unsigned int l = i+1; l < lp.size(); l++) {
01133                 if (lp[i] == lp[l] && lp[i] != realstartnode && lp[i] != endnode) {
01134                 std::vector<SgGraphNode*> interiorloop;
01135                 interiorloop.clear();
01136                 for (unsigned int j = i; j < l+1; j++) {
01137                     interiorloop.push_back(lp[j]);
01138                 }
01139                 if (interiorloop.size() > 2) {
01140                 }
01141                 if (interiorloop.size() > 2 && interiorloop.back() != endnode) {
01142                 if (find(iLoops.begin(), iLoops.end(), interiorloop) == iLoops.end()) {
01143                     if (find(looppaths.begin(), looppaths.end(), interiorloop) == looppaths.end()) {
01144                         iLoops.push_back(interiorloop);
01145                         loopnum++;
01146                         for (unsigned int k = 0; k < interiorloop.size(); k++) {
01147                              loopNumMap[interiorloop[k]] = loopnum;
01148                         }
01149                         lpbegins[interiorloop.front()].insert(interiorloop);
01150                         pathAnalyze(interiorloop, true, nullIncLoops);
01151                         
01152                     }
01153                 }
01154                 }
01155                 }
01156             }
01157         }
01158         if (lp.size() > 2) {   
01159             lpbegins[lp.front()].insert(lp);      
01160             pathAnalyze(lp, true, nullIncLoops);
01161             //for (unsigned int i = 1; i < lp.size(); i++) {
01162             //    printNodePlusEdgesForAnalysisPath(g, lp, p, p, mz);
01163             //}
01164         }
01165     }
01166 */
01167     while (step == false) {
01168         stepnum++;
01169         
01170         if (currpth.back() == endnode) {
01171             path.push_back(currpth);
01172             //for (int i = 0; i < currpth.size(); i++) {
01173             //    currflat.push_back(currpth[i]);
01174             //}
01175             std::vector<SgGraphNode*> flatpath;
01176             //std::vector<SgGraphNode*> sub;
01177             std::set<std::vector<SgGraphNode*> > incloops;
01178             struct timeval q1, q2;
01179             //std::cout << "path.size(): " << path.size() << std::endl;
01180             //std::cout << "pthloops.size(): " << pthloops.size() << std::endl;
01181             ROSE_ASSERT(path.size() == pthloops.size() + 1);
01182             q1 = getCPUTime();
01183             for (unsigned int q = 0; q < pthloops.size(); q++) {
01184                 //sub = path[q];
01185                 //sub.pop_back();
01186                 for (unsigned int r = 0; r < path[q].size(); r++) {
01187                     flatpath.push_back(path[q][r]);
01188                 }
01189                 for (std::set<SgGraphNode*>::iterator p = pthloops[q].begin(); p != pthloops[q].end(); p++) {
01190                     for (std::set<std::vector<SgGraphNode*> >::iterator o = mkloopmap[*p].begin(); o != mkloopmap[*p].end(); o++) {
01191                         incloops.insert(*o);
01192                     }
01193                  }
01194              }
01195              for (unsigned int pt2 = 0; pt2 < path[path.size()-1].size(); pt2++) {
01196                      flatpath.push_back(path[path.size()-1][pt2]);
01197              }
01198              
01199              q2 = getCPUTime();
01200              fllp += timeDifference(q2,q1);
01201              flatpath.push_back(endnode);
01202 /* 
01203             for (unsigned int ps = 0; ps < flatpath.size(); ps++) {
01204                  if (lpbegins.find(flatpath[ps]) != lpbegins.end()) {
01205                      for (std::set<std::vector<SgGraphNode*> >::iterator sv = lpbegins[flatpath[ps]].begin(); sv != lpbegins[flatpath[ps]].end(); sv++) {
01206                          incloops.insert(*sv);
01207                      }
01208                  }
01209              }
01210 */
01211 //user defined function, run on the final path, gives the user loops that are included via "incloops" a set of vectors that contain the individual loops
01212              pathAnalyze(flatpath, false, incloops);
01213              incloops.clear();
01214                 //printNodePlusEdgesForAnalysisPath(g, flatpath, -1, -1, mz);
01215 
01216              int pts = pathsSize++;
01217              pathsSize += 1;
01218             
01219              flatpath.clear();
01220              path.pop_back();
01221              int rounds = 0;
01222              bool starter = false;
01223 
01224 // This gets a bit complicated so here is an overview:
01225 // This is running down the graph and finding the endnode. Once it finds the endnode it goes back up to the last unevaluated subpath. It does this quickly with an integer that counts how many times that node has been used for a path. If this ends up being the number of outnodes, we don't need that node anymore, so we clear it to zero, then continue up the graph. We HAVE to reset because every time a new pathway is chosen above that node, it needs to have the ability to traverse that node.
01226 
01227 
01228               while (true) {
01229                    rounds++;
01230                    ROSE_ASSERT(pathsAtMk.find((path.back()).back()) != pathsAtMk.end());
01231                    if ((path.back()).front() == realstartnode) {
01232                        starter = true;
01233                    }
01234                    if (currents[(path.back()).back()] < (pathsAtMk[(path.back()).back()].size()) /*|| (path.back()).front() == realstartnode*/) {
01235                               std::vector<std::vector<SgGraphNode*> > cpths = pathsAtMk[(path.back()).back()];
01236                               currpth = cpths[currents[(path.back()).back()]];
01237                               currents[(path.back()).back()]++;
01238                               break;
01239                    }
01240                    else {
01241                        currents[(path.back()).back()] = 0;
01242                        path.pop_back();
01243                        pthloops.pop_back();
01244                    }
01245                    if (starter == true) {
01246                        step = true;
01247                        break;
01248                    }
01249 
01250            }
01251         }
01252         else {
01253 
01254 //this checks first to see if we have any loops in our path. If not it continues down, if there is it goes back to the last nonloop node
01255         bool disj = true;
01256         struct timeval tdisb, tdise;
01257         tdisb = getCPUTime();
01258         for (int i = 0; i < pthloops.size(); i++) {
01259             for (std::set<SgGraphNode*>::iterator j = pthloops[i].begin(); j != pthloops[i].end(); j++) {
01260                 if (find(currpth.begin(), currpth.end(), *j) != currpth.end()) {
01261                     disj = false;
01262                 }
01263              }
01264         }
01265 /*
01266         #pragma omp parallel for num_threads(4) private(i,j)
01267         for (i = 0; i < pthloops.size(); i++) {
01268             if (disj) {
01269             for (std::set<SgGraphNode*>::iterator j = pthloops[i].begin(); j != pthloops[i].end(); j++) {
01270                 if (find(currpth.begin(), currpth.end(), *j) != currpth.end()) {
01271                     disj = false;
01272                     //j = pthloops[i].size();
01273                 }
01274             }
01275             }
01276             
01277         }
01278 */
01279         tdise = getCPUTime();
01280         distime += timeDifference(tdise, tdisb);
01281         if (disj) {
01282             
01283             disjointtrues++;
01284             //std::cout << "disjoints: " << disjointtrues << std::endl;
01285             midstep = false;
01286             std::set<SgGraphNode*> pthloopstmp;
01287             pthloopstmp.clear();
01288                 for (int i = 0; i < currpth.size(); i++) {
01289                     //currflat.push_back(currpth[i]);
01290                     if (mkloops.find(currpth[i]) != mkloops.end()) {
01291                        pthloopstmp.insert(currpth[i]);
01292                     }
01293                 }
01294                 pthloops.push_back(pthloopstmp);
01295                 path.push_back(currpth);
01296                 pthloopstmp.clear();
01297                 
01298                 //std::set<std::vector<SgGraphNode*> > lpth;
01299                 std::vector<SgGraphNode*> oldcurrpth = currpth;
01300                 currpth.clear();
01301                 if (currents.find((path.back()).back()) == currents.end()) {
01302                     currents[(path.back()).back()] = 0;
01303                 }
01304                         SgGraphNode* frontnode = (path.back()).front();
01305                         SgGraphNode* backnode = (path.back()).back();
01306      
01307                         ROSE_ASSERT(pathsAtMk.find(backnode) != pathsAtMk.end() || backnode == endnode);
01308                         ROSE_ASSERT(pathsAtMk.find(frontnode) != pathsAtMk.end());
01309                         if (currents.find(backnode) == currents.end()) {
01310                             currents[backnode] = 0;
01311                         }
01312                         else {
01313                             ROSE_ASSERT(currents[backnode] == 0);
01314                         }
01315                         std::vector<std::vector<SgGraphNode*> > tmppths = pathsAtMk[backnode];
01316                        
01317                         currpth = tmppths[currents[backnode]];
01318                         ROSE_ASSERT(currpth != oldcurrpth);
01319                         currents[backnode]++;
01320                     }        
01321      else {
01322         disjoints++;
01323         //std::cout << "disjoint false: " << s << std::endl;
01324         
01325         while (true) {
01326             if (currents[(path.back()).back()] < pathsAtMk[(path.back()).back()].size() || path.back().back() == realstartnode) {
01327                 break;
01328             }
01329             currents[(path.back()).back()] = 0;
01330             path.pop_back();
01331             pthloops.pop_back();
01332         }
01333         if ((path.back()).back() != realstartnode) {
01334         currpth = (pathsAtMk[(path.back()).back()])[currents[(path.back()).back()]];
01335         currents[(path.back()).back()]++;
01336         }
01337         else {
01338         step = true;
01339         }
01340     }
01341  }
01342  }
01343 std::cout << "successes: " << successes << std::endl;
01344 std::cout << "failures: " << failures << std::endl;
01345 
01346 return;
01347 }
01348     
01349         
01350 //these are debugging functions, used to visually ascertain where the paths are going to check to make sure everything is evaluated
01351 
01352 
01353 /* DEBUGGING */
01354 
01355 template<class InheritedAttributeType, class SynthesizedAttributeType>
01356 void
01357 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01358 printNodePlusEdgesForAnalysis(SgIncidenceDirectedGraph* g, SgGraphNode* n, int loopNum, int pathVal, std::ofstream& ss) {
01359   printNodeForAnalysis(n, loopNum, pathVal, ss);
01360   std::set<SgDirectedGraphEdge*> outEdges = g->computeEdgeSetOut(n);
01361   for (std::set<SgDirectedGraphEdge*>::iterator i = outEdges.begin(); i != outEdges.end(); i++) {
01362     if (nullEdgesOrdered.find(*i) == nullEdgesOrdered.end()) {
01363         printEdgeForAnalysis(*i, false, ss);
01364     }
01365     else {
01366         printEdgeForAnalysis(*i, true, ss);
01367     }   
01368   }
01369 }
01370 
01371 template<class InheritedAttributeType, class SynthesizedAttributeType>
01372 void
01373 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01374 printNodePlusEdgesForAnalysisPath(SgIncidenceDirectedGraph* g, std::vector<SgGraphNode*> n, int loopNum, int pathVal, std::ofstream& ss) {
01375   for (unsigned int i = 0; i < n.size()-1; i++) {
01376      if (completedNodesPath.find(n[i]) == completedNodesPath.end()) {
01377          printNodeForAnalysis(n[i], loopNum, pathVal, ss);
01378          completedNodesPath.insert(n[i]);
01379      }
01380      std::pair<SgGraphNode*, SgGraphNode*> prnod;
01381      prnod.first = n[i+1];
01382      prnod.second = n[i];
01383      if (completedEdgesPath.find(prnod) == completedEdgesPath.end()) {
01384          printEdgeForAnalysisPath(n[i+1], n[i], ss);
01385          completedEdgesPath.insert(prnod);
01386      }
01387   }
01388   if (completedNodesPath.find(n[n.size() - 1]) == completedNodesPath.end()) {
01389      printNodeForAnalysis(n[n.size()-1], loopNum, pathVal, ss);
01390      completedNodesPath.insert(n[n.size() - 1]);
01391   }
01392 
01393 }
01394 
01395 
01396 template<class InheritedAttributeType, class SynthesizedAttributeType>
01397 void
01398 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01399 printNodeForAnalysis(SgGraphNode* n, int loopNum, int pathNum, std::ofstream &ss) {
01400   int id = n->get_index();
01401   std::string nodeColor = "black";
01402   if (loopNum != 0) {
01403   ss << id << " [label=\"" << "LoopNumS" << loopNum << "\", color=\"" << "green" << "\", style=\"" << "solid" << "\"];\n";
01404   }
01405   else {
01406   ss << id << " [label=\"" << "pathNumS" << pathNum << "\", color=\"" << "black" << "\", style=\"" << "dotted" << "\"];\n";
01407   }
01408   
01409 }
01410 template<class InheritedAttributeType, class SynthesizedAttributeType>
01411 void
01412 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01413 printEdgeForAnalysis(SgDirectedGraphEdge* e, bool isNullEdge, std::ofstream &ss) {
01414   if (isNullEdge) {
01415       ss << e->get_from()->get_index() << " -> " << e->get_to()->get_index() << " [label=\"" << "NullEdge" << "\", style=\"" << "dotted" << "\"];\n";
01416   }
01417   else {
01418       ss << e->get_from()->get_index() << " -> " << e->get_to()->get_index() << " [label=\"" << "\", style=\"" << "solid" << "\"];\n";
01419   }
01420 }
01421 template<class InheritedAttributeType, class SynthesizedAttributeType>
01422 void
01423 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01424 printEdgeForAnalysisPath(SgGraphNode* g1, SgGraphNode* g2, std::ofstream &ss) {
01425       ss << g2->get_index() << " -> " << g1->get_index() << " [label=\"" << "Edge" << "\", style=\"" << "solid" << "\"];\n";
01426 }
01427 
01428 /* END DEBUGGING */
01429 
01430 //This function sets up the graph so that the evaluatePath function can easily traverse the paths
01431 
01432 template<class InheritedAttributeType, class SynthesizedAttributeType>
01433 void
01434 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01435 solvePaths(SgIncidenceDirectedGraph* g, SgGraphNode* n, SgGraphNode* endnode) {
01436     bool done = false;
01437     bool edges = true;
01438     bool tookone = false;
01439     std::vector<SgGraphNode*> mkpath;
01440     std::vector<SgGraphNode*> marks;
01441     marks.push_back(n);
01442     mkglobal.push_back(n);
01443     SgGraphNode* currn = n;
01444     SgGraphNode* took;
01445     std::set<SgDirectedGraphEdge*> taken;
01446     std::vector<SgGraphNode*> toTake;
01447     std::vector<SgGraphNode*> path;
01448     path.push_back(n);
01449     mkpath.push_back(n);
01450     int itr = 0;
01451     int bifurcations = 0;
01452     std::map<SgGraphNode*, bool> completed;
01453     while (done == false) {
01454              ROSE_ASSERT(currn != NULL);
01455 //check to see if we've hit the endnode or if we're done, if not continue, if so push the subpath into the "pathsAtMk" repository            
01456                if (currn == endnode || completed.find(currn) != completed.end()) {
01457                 if (pathsAtMk.find(marks.back()) == pathsAtMk.end()) {
01458                     std::vector<std::vector<SgGraphNode*> > emptypath;
01459                     pathsAtMk[marks.back()] = emptypath;
01460                 }
01461                 edges = false;
01462                 pathsAtMk[marks.back()].push_back(mkpath);
01463                 //for (int mk = 0; mk < mkpath.size(); mk++) {
01464                  //   std::set<SgDirectedGraphEdge*> iedg = g->computeEdgeSetIn(mkpath[mk]);
01465                     //if (iedg.size() > 1) {
01466                     //    ploops.insert(mkpath[mk]);
01467                    // }
01468                 //}
01469                 ROSE_ASSERT(mkpath.front() == marks.back());
01470                 if (marks.size() == 0) {
01471                     return;
01472                 }
01473                 mkpath.clear();
01474                 bool y = true;
01475                 bool haventtaken = false;
01476                 bool p = true;
01477                 int place;
01478                 bool found = false;
01479                 while (found == false) {
01480                     if (marks.size() == 0) {
01481                         return;
01482                     }
01483                     SgDirectedGraphEdge* tooked;
01484                     SgGraphNode* mark1 = marks.back();
01485                     std::set<SgDirectedGraphEdge*> oedg = g->computeEdgeSetOut(mark1);
01486                     ROSE_ASSERT(oedg.size() > 1 || mark1 == n);
01487                         for (std::set<SgDirectedGraphEdge*>::iterator j = oedg.begin(); j != oedg.end(); j++) {
01488                             if (taken.find(*j) == taken.end() && haventtaken == false) {
01489                                 tooked = *j;
01490                                 haventtaken = true;
01491                             }
01492                         }
01493                         if (haventtaken == true) {
01494                             if (marks.back() == n) {
01495                                 path.clear();
01496                             }
01497                             path.push_back(marks.back());
01498                             if ( mkpath.empty() || (mkpath.back() != marks.back()) ) {
01499                                 ROSE_ASSERT(!marks.empty());
01500                                 mkpath.push_back(marks.back());
01501                             }
01502                             taken.insert(tooked);
01503                             took = tooked->get_to();
01504                             found = true;
01505                         }
01506                         else {
01507                             completed[marks.back()] = true;
01508                             bifurcations++;
01509                             marks.pop_back();
01510                         }
01511                     }
01512                     if (marks.size() == 0) {
01513                         return;
01514                     } 
01515                     haventtaken = false;
01516                     found = false; 
01517                                 
01518              }
01519 //if we haven't reached the endnode or completed, continue down the graph
01520              else {
01521             std::set<SgDirectedGraphEdge*> oedg = g->computeEdgeSetOut(currn);
01522             std::set<SgDirectedGraphEdge*> iedg = g->computeEdgeSetIn(currn);
01523             if (oedg.size() > 1) {
01524                      if (mkpath.back() != currn) {
01525                      mkpath.push_back(currn);
01526                      }
01527                      pathsAtMk[marks.back()].push_back(mkpath);
01528                      mkpath.clear();
01529                      mkpath.push_back(currn);
01530                      marks.push_back(currn);
01531                      if (find(mkglobal.begin(), mkglobal.end(), currn) == mkglobal.end()) {
01532                          mkglobal.push_back(currn);
01533                      }
01534                      for (std::set<SgDirectedGraphEdge*>::iterator i = oedg.begin(); i != oedg.end(); i++) {
01535                           if (taken.find(*i) == taken.end() && tookone == false) {
01536                                taken.insert(*i);
01537                                tookone = true;
01538                                took = (*i)->get_to();
01539                           }
01540                           else if (taken.find(*i) == taken.end() && tookone == true) {
01541                                //toTake.push_back((*i)->get_to());
01542                           }
01543                    }
01544                    tookone = false;
01545            }
01546            else {
01547                 took = (*(oedg.begin()))->get_to();
01548            }
01549            }
01550            itr++;
01551            
01552            if (find(path.begin(), path.end(), took) == path.end()) {
01553                mkpath.push_back(took);
01554                path.push_back(took);
01555                currn = took;
01556            }
01557            else {
01558                mkloops.insert(took);
01559                std::vector<SgGraphNode*> lptemp;
01560                lptemp.clear();
01561                lptemp.push_back(took);
01562                while (path.back() != took) {
01563                    
01564                    path.pop_back();
01565                   
01566                    lptemp.push_back(path.back());
01567                    
01568                }
01569                (mkloopmap[took]).insert(lptemp);
01570 /*
01571                if (lptemp.size() > 1) {
01572                if (find(looppaths.begin(), looppaths.end(), lptemp) == looppaths.end() && find(lptemp.begin(), lptemp.end(), st) == lptemp.end() && find(lptemp.begin(), lptemp.end(), endnode) == lptemp.end()) {
01573                    looppaths.push_back(lptemp);
01574                    loopnum++;
01575                    for (unsigned int i = 0; i < lptemp.size(); i++) {
01576                        loopNumMap[lptemp[i]] = loopnum;
01577                    }
01578                }
01579                }
01580 */
01581                path.push_back(took);
01582                currn = path.back();
01583                mkpath.push_back(took);
01584            }
01585            
01586                
01587 }
01588            return;
01589 }
01590 
01591 //not currently useful
01592 template <class InheritedAttributeType, class SynthesizedAttributeType>
01593 SynthesizedAttributeType
01594 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01595 defaultSynthesizedAttribute(InheritedAttributeType inh)
01596 {
01597     SynthesizedAttributeType s = SynthesizedAttributeType();
01598     return s;
01599 }
01600 
01601 
01602 //computes the order in which to evaluate the nodes in nodal analysis so that you don't evaluate a node before you evaluate its parents
01603 
01604 template <class InheritedAttributeType, class SynthesizedAttributeType>
01605 void
01606 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01607 computeOrder(SgIncidenceDirectedGraph* g, SgGraphNode* n, SgGraphNode* endnode) {
01608     std::map<SgGraphNode*, int> incomputables;
01609     std::set<SgGraphNode*> lpposs;
01610     //std::set<SgGraphNode*> lps;
01611     SgGraphNode* currn;
01612     currn = n;
01613     int orders = 0; 
01614     while (true) {
01615         if (orders % 10000 == 0) {
01616             std::cout << "orders: " << orders << std::endl;
01617         }
01618         orders++;
01619         if (currn == endnode) {
01620         }
01621         if (computable(g, currn) || currn == n) {
01622             int mp;
01623             if (oVals.find(currn) == oVals.end()) {
01624                  oVals[currn] = currm++;
01625                  iVals[currm++] = currn;
01626                  currm += 1;
01627             }
01628             if (currn == endnode) {
01629                 
01630                 break;
01631             }
01632             std::pair<bool, SgGraphNode*> pbs = getNextChild(g, currn);
01633             computedNodes.insert(currn);
01634             ROSE_ASSERT(pbs.first == true);
01635             currn = pbs.second;
01636         }
01637         else {
01638             std::pair<bool, SgGraphNode*> pbp = getNextPar(g, currn);
01639             ROSE_ASSERT(pbp.first == true);
01640             currn = pbp.second;
01641             
01642         }
01643         
01644     }
01645     std::cout << "required orders" << orders << std::endl;
01646     std::cout << "incomputables.size() " << incomputables.size() << std::endl;
01647 }
01648 
01649 //simple fucntion to check the computability under nodal analysis
01650 template <class InheritedAttributeType, class SynthesizedAttributeType>
01651 bool
01652 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01653 computable(SgIncidenceDirectedGraph* g, SgGraphNode* n) {
01654     if (computedNodes.find(n) != computedNodes.end()) {
01655         return true;
01656     }
01657     std::set<SgDirectedGraphEdge*> ed = g->computeEdgeSetIn(n);
01658     bool comp = true;
01659     for (std::set<SgDirectedGraphEdge*>::iterator i = ed.begin(); i != ed.end(); i++) {
01660         if (oVals.find((*i)->get_from()) == oVals.end() && nullEdgesOrdered.find(*i) == nullEdgesOrdered.end()) {
01661             comp = false;
01662         }
01663     }
01664     return comp;
01665 }
01666 
01667 
01668 //computes the inherited attribute values in nodal analysis
01669 
01670 template <class InheritedAttributeType, class SynthesizedAttributeType>
01671 void
01672 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01673 computeInheritedOrdered(SgIncidenceDirectedGraph* g, SgGraphNode* n) {
01674     int runs = 0;
01675 //    std::ofstream mf;
01676 //    mf.open("analysis.dot");
01677 //    mf << "digraph defaultName { \n";
01678     for (std::map<int, SgGraphNode*>::iterator i = iVals.begin(); i != iVals.end(); i++) {
01679         runs++;
01680         ROSE_ASSERT(canEval(g, (*i).second));
01681         setPathVal(g, n);
01682         //printNodePlusEdgesForAnalysis(g, (*i).second, loopNumMap[(*i).second], pathValMap[(*i).second], mf);
01683         evalNodeOrdered(g, (*i).second);
01684     }
01685 }
01686 
01687 //checks to see if evaluation is possible under nodal analysis
01688 template <class InheritedAttributeType, class SynthesizedAttributeType>
01689 bool
01690 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01691 canEval(SgIncidenceDirectedGraph* g, SgGraphNode* n) {
01692     bool evaled = true;
01693     if (inhVals.find(n) == inhVals.end()) {
01694     std::set<SgDirectedGraphEdge*> ins = g->computeEdgeSetIn(n);
01695     for (std::set<SgDirectedGraphEdge*>::iterator i = ins.begin(); i != ins.end(); i++) {
01696         if (inhVals.find((*i)->get_from()) == inhVals.end() && nullEdgesOrdered.find(*i) == nullEdgesOrdered.end()) {
01697             evaled = false;
01698         }
01699     }
01700     }
01701     return evaled;
01702 }
01703 
01704 
01705 //actually does the evaluation
01706 template <class InheritedAttributeType, class SynthesizedAttributeType>
01707 void
01708 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01709 evalNodeOrdered(SgIncidenceDirectedGraph* g, SgGraphNode* n) {
01710     if (inhVals.find(n) != inhVals.end()) {
01711         return;
01712     }
01713     std::set<SgDirectedGraphEdge*> par = g->computeEdgeSetIn(n);
01714     std::vector<InheritedAttributeType> inh;
01715     for (std::set<SgDirectedGraphEdge*>::iterator i = par.begin(); i != par.end(); i++) {
01716         if (inhVals.find((*i)->get_from()) != inhVals.end()) {
01717             inh.push_back(inhVals[(*i)->get_from()]);
01718         }
01719     }
01720     
01721     if (n != st || inh.size() > 0) {
01722         InheritedAttributeType inhX;
01723         inhX = evaluateInheritedAttribute(n, inh);
01724         inhVals[n] = inhX;
01725     }
01726     //std::cout << "num of inhVals: " << inh.size() << std::endl;
01727     
01728 }
01729 
01730 
01731 //debugging function, currently not useful for the end user
01732 template <class InheritedAttributeType, class SynthesizedAttributeType>
01733 void
01734 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01735 setPathVal(SgIncidenceDirectedGraph* g, SgGraphNode* currn) {
01736        if (pathValMap.find(currn) != pathValMap.end()) {
01737            return;
01738        }
01739        std::set<SgDirectedGraphEdge*> ined = g->computeEdgeSetIn(currn);
01740        int tmppathcount = 0;
01741        for (std::set<SgDirectedGraphEdge*>::iterator i = ined.begin(); i != ined.end(); i++) {
01742             ROSE_ASSERT(pathValMap.find((*i)->get_from()) != pathValMap.end() /*|| nullEdgesOrdered.find(*i) != nullEdgesOrdered.end()*/);
01743             //if (nullEdgesOrdered.find(*i) != nullEdgesOrdered.end()) {
01744             //    pathValMap[(*i)->get_from()] = 0;
01745            // }
01746             int pv = pathValMap[(*i)->get_from()];
01747             if (pv != 0) {
01748             tmppathcount += pv;
01749             }
01750         }
01751         pathValMap[currn] = tmppathcount;
01752         return;
01753     }
01754 
01755 //computes the next child to be analyzed in nodal analysis
01756 template <class InheritedAttributeType, class SynthesizedAttributeType>
01757 std::pair<bool, SgGraphNode*>
01758 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01759 getNextChild(SgIncidenceDirectedGraph* g, SgGraphNode* n) {
01760     bool nullPoss = false;
01761     //std::cout << "nextChild" << std::endl;
01762     std::set<SgDirectedGraphEdge*> outs = g->computeEdgeSetOut(n);
01763     //std::cout << "outs.size(): " << outs.size() << std::endl;
01764     //std::cout << "outs: " << outs.size() << std::endl;
01765     SgGraphNode* nextNode;
01766     SgGraphNode* nullNode;
01767     bool completed = false;
01768     bool completeNull = false;
01769     
01770     for (std::set<SgDirectedGraphEdge*>::iterator i = outs.begin(); i != outs.end(); i++) {
01771 
01772         if (outs.size() == 1) {
01773             nextNode = (*i)->get_to();
01774             if (nullEdgesOrdered.find(*i) != nullEdgesOrdered.end()) {
01775                 nullNum++;
01776             }
01777             //completedEdges.insert(*i);
01778             completed = true;
01779         }
01780         else if (completed == false && computedNodes.find((*i)->get_to()) == computedNodes.end()) {
01781             completed = true;
01782             nextNode = (*i)->get_to();
01783             if (nullEdgesOrdered.find(*i) != nullEdgesOrdered.end()) {
01784                 nullNum++;
01785             }
01786             completedEdgesOut.insert(*i);
01787         }
01788         
01789             
01790     }
01791     std::pair<bool, SgGraphNode*> pr;
01792     ROSE_ASSERT (completed == true || completeNull == true);
01793     if (completed == true) {
01794         pr.first = completed;
01795         pr.second = nextNode;
01796         return pr;
01797     }
01798     else {
01799         pr.first = true;
01800         pr.second = nullNode;
01801         return pr;
01802     } 
01803     
01804 }
01805 
01806 //computes the next parent to be analyzed in nodal analysis
01807 template <class InheritedAttributeType, class SynthesizedAttributeType>
01808 std::pair<bool, SgGraphNode*>
01809 SgGraphTraversal<InheritedAttributeType, SynthesizedAttributeType>::
01810 getNextPar(SgIncidenceDirectedGraph* g, SgGraphNode* n) {
01811     std::set<SgDirectedGraphEdge*> ins = g->computeEdgeSetIn(n);
01812     SgGraphNode* nextPar;
01813     SgDirectedGraphEdge* nullEdgeO;
01814     bool completed = false;
01815     bool completeNull = false;
01816     for (std::set<SgDirectedGraphEdge*>::iterator i = ins.begin(); i != ins.end(); i++) {
01817 
01818         if (ins.size() == 1 /*&& completedEdges.find(*i) == completedEdges.end()*/) {
01819             completed = true;
01820             completedEdges.insert(*i);
01821             nextPar = (*i)->get_from();
01822         }
01823 
01824         else if (completedEdges.find(*i) == completedEdges.end() && completed == false) {
01825             completed = true;
01826             nextPar = (*i)->get_from();
01827             completedEdges.insert(*i);
01828         }
01829 
01830         else if (completedEdges.find(*i) != completedEdges.end() && computedNodes.find((*i)->get_from()) == computedNodes.end() && completed == false /*&& nullEdgesOrdered.find(*i) == nullEdgesOrdered.end()*/) {
01831             completeNull = true;
01832             std::pair<SgGraphNode*, SgGraphNode*> lpp;
01833             nextPar = n;
01834             nullEdgesOrdered.insert(*i);
01835             nullEdgesPaths++;
01836             
01837         }
01838     }
01839     ROSE_ASSERT(completed == true || completeNull == true);
01840     std::pair<bool, SgGraphNode*> pr;
01841     pr.first = completed;
01842     pr.second = nextPar;
01843 
01844     if (completeNull == true && completed == false) {
01845         pr.first = completeNull;
01846         pr.second = nextPar;
01847     }
01848    
01849     return pr;
01850 }
01851  
01852     
01853 
01854 
01855 
01856 
01857 
01858 
01859  
01860     
01861 
01862   
01863         
01864     
01865             

Generated on Sat May 19 00:53:06 2012 for ROSE by  doxygen 1.4.7