13#include <boost/regex.hpp>  
   77#include <sys/resource.h> 
   85    std::vector<std::vector<SgGraphNode*> > path;
 
   86    std::vector<std::set<SgGraphNode*> > pthloops;
 
   87    std::vector<SgGraphNode*> currpth;
 
   88    std::vector<std::pair<SgGraphNode*, int> > nodelst;
 
 
   93double timeDifference(
const struct timeval& end, 
const struct timeval& begin)
 
   95    return (end.tv_sec + end.tv_usec / 1.0e6) - (begin.tv_sec + begin.tv_usec / 1.0e6);
 
   98static inline timeval getCPUTime() {
 
  100  getrusage(RUSAGE_SELF, &ru);
 
  115template <
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
  119    std::set<std::map<int, std::set<int> > > subpathmap;
 
  122    std::set<SgDirectedGraphEdge*> nullEdgesOrdered;
 
  123    std::map<SgGraphNode*, int> loopNumMap;
 
  124    std::map<SgGraphNode*, int> pathValMap;
 
  126    std::vector<std::vector<SgGraphNode*> > looppaths;
 
  127    std::vector<std::vector<SgGraphNode*> > iLoops;
 
  128    std::vector<SgGraphNode*> ifstatements;
 
  146    std::map<SgGraphNode*, int> primenode;
 
  149    std::set<SgGraphNode*> lstN;
 
  150    std::map<SgGraphNode*, std::vector<std::set<int> > > lstordmap;
 
  151    std::set<SgGraphNode*> solvedLoops;
 
  152    std::map<SgGraphNode*, std::vector<SgGraphNode*> > checkednodes; 
 
  153    std::map<SgGraphNode*, std::set<SgGraphNode*> > downed;
 
  157    InheritedAttributeType nullInherit;
 
  160            InheritedAttributeType inheritedValue, InheritedAttributeType nullInherit,
 
  161            SgGraphNode* endnode, 
bool insep = 
false, 
bool pcHk = 
false);
 
  162    std::set<SgGraphNode*> loopSet;
 
  168    virtual InheritedAttributeType evaluateInheritedAttribute(
SgGraphNode* n,
 
  169            std::vector<InheritedAttributeType> inheritedValues) = 0;
 
  171    virtual SynthesizedAttributeType evaluateSynthesizedAttribute(
SgGraphNode* n,
 
  172            InheritedAttributeType in,
 
  179    virtual void pathAnalyze(std::vector<SgGraphNode*>& pth, 
bool loop=
false, std::set<std::vector<SgGraphNode*> >& incloops=NULL) = 0;
 
  181    virtual void pathAnalyze(std::vector<SgGraphNode*>& pth, 
bool loop, std::set<std::vector<SgGraphNode*> >& incloops) = 0;
 
  185    SynthesizedAttributeType defaultSynthesizedAttribute(InheritedAttributeType);
 
  190    std::set<SgGraphNode*> ploops;
 
  191    std::map<SgGraphNode*, std::set<std::vector<SgGraphNode*> > > lpbegins;
 
  192    std::map<SgGraphNode*, int> frksLeft;
 
  201    std::map<SgGraphNode*, InheritedAttributeType> known;
 
  202    std::vector<InheritedAttributeType> connectNodes;
 
  203    std::map<SgGraphNode*, bool> solved;
 
  204    std::set<SgGraphNode*> solvedset;
 
  207    SynthesizedAttributeType traversalResult();
 
  213    std::map<SgGraphNode*, int> nodeInEdgesNum;
 
  215    std::vector<SgGraphNode*> endnodefakes;
 
  216    std::map<SgGraphNode*, std::vector<std::vector<SgGraphNode*> > > pathsAtMk;
 
  217    std::set<SgGraphNode*> mkloops;
 
  218    std::map<SgGraphNode*, std::set<std::vector<SgGraphNode*> > > mkloopmap;
 
  219    std::map<SgGraphNode*, std::set<std::vector<SgGraphNode*> > > subPathsAtMk;
 
  220    std::vector<SgGraphNode*> mkglobal;
 
  221    std::vector<SgGraphNode*> clglobal;
 
  224    std::vector<std::set<SgGraphNode*> > closuresVec;
 
  227    bool disjoint(std::vector<SgGraphNode*>& path, std::vector<SgGraphNode*>& vec2) 
const;
 
  228    std::set<std::vector<SgGraphNode*> > flatpaths;
 
  231    std::map<SgGraphNode*, InheritedAttributeType> inhVals;
 
  232    std::set<SgDirectedGraphEdge*> seenEdges;
 
  233    std::set<SgDirectedGraphEdge*> nullEdges;
 
  234    std::set<SgGraphNode*> clsT;
 
  241    std::map<SgGraphNode*, int> oVals;
 
  245    void printNodePlusEdgesForAnalysisPath(
SgIncidenceDirectedGraph* g, std::vector<SgGraphNode*> n, 
int loopNum, 
int pathVal, std::ofstream& ss);
 
  246    void printNodeForAnalysis(
SgGraphNode* n, 
int loopNum, 
int pathNum, std::ofstream& ss);
 
  247    std::set<SgGraphNode*> completedNodesPath;
 
  248    std::set<std::pair<SgGraphNode*, SgGraphNode*> > completedEdgesPath;
 
  251    std::map<int, SgGraphNode*> iVals;
 
  253    std::set<SgDirectedGraphEdge*> nullEdgesOrderedOut;
 
  254    std::set<SgDirectedGraphEdge*> completedEdgesOut;
 
  255    std::set<SgDirectedGraphEdge*> completedEdges;
 
  256    std::set<SgGraphNode*> compPar;
 
  257    std::set<SgGraphNode*> compChild;
 
  258    std::set<SgGraphNode*> computedNodes;
 
  306template<
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
  309  : synthesizedAttributes(new SynthesizedAttributesList())
 
  315template<
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
  319        ROSE_ASSERT(synthesizedAttributes != NULL);
 
  320        delete synthesizedAttributes;
 
  321        synthesizedAttributes = NULL;
 
  327template<
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
  333    ROSE_ASSERT(synthesizedAttributes != NULL);
 
  334    delete synthesizedAttributes;
 
  335    synthesizedAttributes = other.synthesizedAttributes->deepCopy();
 
  357template<
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
  358InheritedAttributeType
 
  365    completedEdgesPath.clear();
 
  380   completedEdges.clear();
 
  381   completedEdgesOut.clear();
 
  383   computedNodes.clear();
 
  384   nullEdgesOrdered.clear();
 
  385   nullEdgesOrderedOut.clear();
 
  397   std::cout << 
"starting traversal" << std::endl;
 
  401   synthesizedAttributes->resetStack();
 
  402   ROSE_ASSERT(synthesizedAttributes->debugSize() == 0);
 
  404   inhVals[n] = inheritedValue;
 
  416InheritedAttributeType inh;
 
  417   struct timeval t1, t2, t3, t4, t5, t6, t7, t8;
 
  424       solvePaths(g, n, endnode);
 
  429       ROSE_ASSERT(inhVals.find(endnode) == inhVals.end());
 
  431       std::cout << 
"solvePaths done" << std::endl;
 
  432       double diff = timeDifference(t2, t1);
 
  439       computedNodes.insert(n);
 
  441       computeOrder(g, n, endnode);
 
  442       std::cout << 
"order computed" << std::endl;
 
  444       computeInheritedOrdered(g, n);
 
  445       std::cout << 
"inheritance computed" << std::endl;
 
  446       ROSE_ASSERT(oVals.find(endnode) != oVals.end());
 
  447       ROSE_ASSERT(inhVals.find(endnode) != inhVals.end());
 
  449       InheritedAttributeType pthgraphinherit = inhVals[endnode];
 
  452       std::cout << 
"evaluateGraph done" << std::endl;
 
  453       double diff3 = timeDifference(t6, t5);
 
  457       evaluatePaths(g, n, endnode);
 
  465       std::cout << 
"evaluatePaths done " << std::endl;
 
  466       double diff2 = timeDifference(t4, t3);
 
  467       double diff2Par = timeDifference(t8, t7);
 
  468       std::cout << 
"pathsolve took: " << diff << std::endl;
 
  469       std::cout << 
"patheval took: " << diff2 << std::endl;
 
  470       std::cout << 
"parpatheval took: " << diff2Par << std::endl;
 
  471       std::cout << 
"grapheval took: " << diff3 << std::endl;
 
  472       std::cout << 
"entire pathsolve took: " << diff+diff2+diff3+diff2Par << std::endl;
 
  473       std::cout << 
"potential loops: " << nullEdgesOrdered.size() << std::endl;
 
  474       std::cout << 
"nullNum: " << nullNum << std::endl;
 
  477       std::cout << 
"mkloops: " << mkloops.size() << std::endl;
 
  478       std::cout << 
"distime: " << distime << std::endl;
 
  479       std::cout << 
"fllp: " << fllp << std::endl;
 
  480       return pthgraphinherit;
 
 
 
  497bool is_disjoint(std::set<SgGraphNode*> set1, std::set<SgGraphNode*> set2) {
 
  499   if (set1.empty() || set2.empty()) {
 
  502   std::set<SgGraphNode*>::iterator it1 = set1.begin();
 
  503   std::set<SgGraphNode*>::iterator it2 = set2.begin();
 
  504   std::set<SgGraphNode*>::iterator it1End = set1.end();
 
  505   std::set<SgGraphNode*>::iterator it2End = set2.end();
 
  507    if (*it1 > *set2.rbegin() || *it2 > *set1.rbegin()) {
 
  511    while (it1 != it1End && it2 != it2End) {
 
  528template<
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
  531disjoint(std::vector<SgGraphNode*>& pthloops, std::vector<SgGraphNode*>& vec2)
 const {
 
  556        for (
int i = 0; i < pthloops.size(); i++) {
 
  557            if (find(vec2.begin(), vec2.end(), pthloops[i]) != vec2.end()) {
 
  669template<
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
  674    if (inhVals.find(n) != inhVals.end()) {
 
  677    std::set<SgDirectedGraphEdge*> oed = g->computeEdgeSetIn(n);
 
  678    if (oed.size() == 0) {
 
  681        for (std::set<SgDirectedGraphEdge*>::iterator i = oed.begin(); i != oed.end(); i++) {
 
  682            if (inhVals.find((*i)->get_from()) == inhVals.end() && nullEdges.find(*i) == nullEdges.end()) {
 
  691template<
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
  695std::vector<std::vector<SgGraphNode*> > path;
 
  696std::vector<SgGraphNode*> spath;
 
  701std::vector<SgGraphNode*> currpthorg;
 
  703std::map<SgGraphNode*, int> intPath;
 
  706std::map<SgGraphNode*, int> currents;
 
  713std::vector<std::vector<SgGraphNode*> > pth = pathsAtMk[realstartnode];
 
  714std::vector<std::vector<SgGraphNode*> > cpth = pathsAtMk[realstartnode];
 
  717    int disjointtrues = 0;
 
  719    intPath[pth[0].front()] = currint;
 
  720    std::set<SgGraphNode*> pthloopstmp;
 
  722    pthloopstmp.insert(fakenode);
 
  723    std::vector<std::set<SgGraphNode*> > pthloops;
 
  724    pthloops.push_back(pthloopstmp);
 
  729    std::vector<SgGraphNode*> rs;
 
  730    rs.push_back(realstartnode);
 
  735    std::vector<SgGraphNode*> sub;
 
  738    std::set<std::vector<SgGraphNode*> > nullIncLoops;
 
  739    std::vector<struct Bot*> todobotlst;
 
  740    std::vector<struct Bot*> botlst;
 
  741    struct Bot* rootBot = 
new Bot;
 
  742    rootBot->remove = 
false;
 
  744    rootBot->path = path;
 
  745    rootBot->currpth = currpthorg;
 
  746    rootBot->pthloops = pthloops;
 
  748     botlst.push_back(rootBot);
 
  751    std::vector<std::pair<std::vector<SgGraphNode*>, std::vector<std::set<SgGraphNode*> > > > collectedPaths;
 
  754    if (todobotlst.size()+botlst.size() > maxlst) {
 
  755        maxlst = todobotlst.size()+botlst.size();
 
  756        std::cout << 
"maxlst: " << maxlst << std::endl;
 
  757        std::cout << 
"todobotlst.size(): " << todobotlst.size() << std::endl;
 
  758        std::cout << 
"botlst.size(): " << botlst.size() << std::endl;
 
  762    int LOCALMAXBOTS = 10;
 
  763    int LOCALMAXNODES = 0;
 
  764    std::vector<struct Bot*> lstnullbot;
 
  765    std::vector<std::vector<struct Bot*> > newbotlsts (MAXBOTS, lstnullbot);
 
  769    ROSE_ASSERT(botlst.size() >= 0);
 
  770    if (botlst.size() == 0) {
 
  771        if (todobotlst.size() != 0) {
 
  772            while (todobotlst.size() > 0 && botlst.size() < MAXBOTS) {
 
  773                todobotlst.back()->on = 
true;
 
  774                botlst.push_back(todobotlst.back());
 
  775                todobotlst.pop_back();
 
  779            if (collectedPaths.size() > 0) {
 
  780                  for (
int i = 0; i < collectedPaths.size(); i++) {
 
  781                  std::set<std::vector<SgGraphNode*> > incloops;
 
  782                  std::vector<std::set<SgGraphNode*> > pthloops = collectedPaths[i].second;
 
  783                  for (
int q = 0; q < pthloops.size(); q++) {
 
  784                  for (std::set<SgGraphNode*>::iterator p = pthloops[q].begin(); p != pthloops[q].end(); p++) {
 
  785                    for (std::set<std::vector<SgGraphNode*> >::iterator o = mkloopmap[*p].begin(); o != mkloopmap[*p].end(); o++) {
 
  792        pathAnalyze(collectedPaths[i].first, 
false, incloops);
 
  794    collectedPaths.clear();
 
  799    if (botlst.size() > 0) {
 
  800    std::pair<std::vector<SgGraphNode*>, std::vector<std::set<SgGraphNode*> > > nullpr;
 
  801    std::vector<std::pair<std::vector<SgGraphNode*>, std::vector<std::set<SgGraphNode*> > > > newpathslst (MAXBOTS, nullpr);
 
  802    #pragma omp parallel for 
  803    for (
int i = 0; i < botlst.size(); i++) {
 
  805        std::vector<struct Bot*> localbotlst;
 
  806        std::pair<std::vector<SgGraphNode*>, std::vector<std::set<SgGraphNode*> > > localnewpath;
 
  807        struct Bot* currBot = botlst[i];
 
  809        std::vector<SgGraphNode*> currpth = currBot->currpth;
 
  810        std::vector<std::vector<SgGraphNode*> > path = currBot->path;
 
  811        std::vector<std::set<SgGraphNode*> > pthloops = currBot->pthloops;
 
  813            if (currpth.back() == endnode) {
 
  814            path.push_back(currpth);
 
  815            std::vector<SgGraphNode*> flatpath;
 
  816            std::set<std::vector<SgGraphNode*> > incloops;
 
  817            struct timeval q1, q2;
 
  818            ROSE_ASSERT(path.size() == pthloops.size() + 1);
 
  820            for (
unsigned int q = 0; q < pthloops.size(); q++) {
 
  821                for (
unsigned int r = 0; r < path[q].size(); r++) {
 
  822                    flatpath.push_back(path[q][r]);
 
  838             for (
unsigned int pt2 = 0; pt2 < path[path.size()-1].size(); pt2++) {
 
  839                     flatpath.push_back(path[path.size()-1][pt2]);
 
  842             fllp += timeDifference(q2,q1);
 
  843             flatpath.push_back(endnode);
 
  851             std::pair<std::vector<SgGraphNode*> , std::vector<std::set<SgGraphNode*> > > newcol;
 
  852             newcol.first = flatpath;
 
  853             newcol.second = pthloops;
 
  854             localnewpath = newcol;
 
  857             int pts = pathsSize++;
 
  863             bool starter = 
false;
 
  883                 currBot->remove = 
true;
 
  884                 localbotlst.push_back(currBot);
 
  891        struct timeval tdisb, tdise;
 
  893        for (
int x = 0; x < pthloops.size(); x++) {
 
  894            for (std::set<SgGraphNode*>::iterator j = pthloops[x].begin(); j != pthloops[x].end(); j++) {
 
  895                if (find(currpth.begin(), currpth.end(), *j) != currpth.end()) {
 
  907std::set<SgGraphNode*> pthloopstmp;
 
  909                for (
int i = 0; i < currpth.size(); i++) {
 
  911                    if (mkloops.find(currpth[i]) != mkloops.end()) {
 
  912                       pthloopstmp.insert(currpth[i]);
 
  915                pthloops.push_back(pthloopstmp);
 
  916                path.push_back(currpth);
 
  920                std::vector<SgGraphNode*> oldcurrpth = currpth;
 
  925                        ROSE_ASSERT(pathsAtMk.find(backnode) != pathsAtMk.end() || backnode == endnode);
 
  926                        ROSE_ASSERT(pathsAtMk.find(frontnode) != pathsAtMk.end());
 
  927                        std::vector<std::vector<SgGraphNode*> > tmppths = pathsAtMk[backnode];
 
  928                        currBot->currpth = tmppths[0];
 
  929                        currBot->path = path;
 
  930                        currBot->pthloops = pthloops;
 
  932                        for (
int tp = 1; tp < tmppths.size(); tp++) {
 
  943                                struct Bot* newBot = 
new Bot;
 
  944                                newBot->remove = 
false;
 
  945                                newBot->currpth = tmppths[tp];
 
  947                                newBot->pthloops = pthloops;
 
  948                                localbotlst.push_back(newBot);
 
  952                        localbotlst.push_back(currBot);
 
  974                 currBot->remove = 
true;
 
  975                 localbotlst.push_back(currBot);
 
  981 newpathslst[i] = localnewpath;
 
  982 newbotlsts[i] = localbotlst;
 
  988 for (
int i = 0; i < newbotlsts.size(); i++) {
 
  989    if (newpathslst[i].first.size() > 0) {
 
  990        collectedPaths.push_back(newpathslst[i]);
 
  992    for (
int j = 0; j < newbotlsts[i].size(); j++) {
 
  993        if (newbotlsts[i][j]->remove == 
true) {
 
  994            delete newbotlsts[i][j];
 
  996        else if (num < MAXBOTS) {
 
  997            newbotlsts[i][j]->on = 
true;
 
  998            botlst.push_back(newbotlsts[i][j]);
 
 1002            newbotlsts[i][j]->on = 
false;
 
 1003            todobotlst.push_back(newbotlsts[i][j]);
 
 1008if (collectedPaths.size() > MINPATHS) {
 
 1010    for (
int i = 0; i < collectedPaths.size(); i++) {
 
 1011                 std::vector<std::set<SgGraphNode*> > pthloops;   
 
 1012                std::set<std::vector<SgGraphNode*> > incloops;
 
 1013                pthloops = collectedPaths[i].second;
 
 1014                for (
int q = 0; q < pthloops.size(); q++) {
 
 1015                for (std::set<SgGraphNode*>::iterator p = pthloops[q].begin(); p != pthloops[q].end(); p++) {
 
 1016                    for (std::set<std::vector<SgGraphNode*> >::iterator o = mkloopmap[*p].begin(); o != mkloopmap[*p].end(); o++) {
 
 1017                        incloops.insert(*o);
 
 1022        pathAnalyze(collectedPaths[i].first, 
false, incloops);
 
 1024    collectedPaths.clear();
 
 1028            if (collectedPaths.size() > 0) {
 
 1029            for (
int i = 0; i < collectedPaths.size(); i++) {
 
 1030                std::set<std::vector<SgGraphNode*> > incloops;
 
 1031                pthloops = collectedPaths[i].second;
 
 1032                for (
int q = 0; q < pthloops.size(); q++) {
 
 1033                for (std::set<SgGraphNode*>::iterator p = pthloops[q].begin(); p != pthloops[q].end(); p++) {
 
 1034                    for (std::set<std::vector<SgGraphNode*> >::iterator o = mkloopmap[*p].begin(); o != mkloopmap[*p].end(); o++) {
 
 1035                        incloops.insert(*o);
 
 1040        pathAnalyze(collectedPaths[i].first, 
false, incloops);
 
 1043    collectedPaths.clear();
 
 1048std::cout << 
"successes: " << successes << std::endl;
 
 1049std::cout << 
"failures: " << failures << std::endl;
 
 1050std::cout << 
"maxlst: " << maxlst << std::endl;
 
 1056template<
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1076std::vector<std::vector<SgGraphNode*> > path;
 
 1077std::vector<SgGraphNode*> spath;
 
 1082std::vector<SgGraphNode*> currpth;
 
 1084std::map<SgGraphNode*, int> intPath;
 
 1085intPath[n] = currint;
 
 1087std::map<SgGraphNode*, int> currents;
 
 1090bool midstep = 
false;
 
 1094std::vector<std::vector<SgGraphNode*> > pth = pathsAtMk[realstartnode];
 
 1095std::vector<std::vector<SgGraphNode*> > cpth = pathsAtMk[realstartnode];
 
 1098    int disjointtrues = 0;
 
 1100    intPath[pth[0].front()] = currint;
 
 1101    std::set<SgGraphNode*> pthloopstmp;
 
 1103    pthloopstmp.insert(fakenode);
 
 1104    std::vector<std::set<SgGraphNode*> > pthloops;
 
 1105    pthloops.push_back(pthloopstmp);
 
 1106    pthloopstmp.clear();
 
 1110    std::vector<SgGraphNode*> rs;
 
 1111    rs.push_back(realstartnode);
 
 1118    std::vector<SgGraphNode*> sub;
 
 1125    std::set<std::vector<SgGraphNode*> > nullIncLoops;
 
 1167    while (step == 
false) {
 
 1170        if (currpth.back() == endnode) {
 
 1171            path.push_back(currpth);
 
 1175            std::vector<SgGraphNode*> flatpath;
 
 1177            std::set<std::vector<SgGraphNode*> > incloops;
 
 1178            struct timeval q1, q2;
 
 1181            ROSE_ASSERT(path.size() == pthloops.size() + 1);
 
 1183            for (
unsigned int q = 0; q < pthloops.size(); q++) {
 
 1186                for (
unsigned int r = 0; r < path[q].size(); r++) {
 
 1187                    flatpath.push_back(path[q][r]);
 
 1189                for (std::set<SgGraphNode*>::iterator p = pthloops[q].begin(); p != pthloops[q].end(); p++) {
 
 1190                    for (std::set<std::vector<SgGraphNode*> >::iterator o = mkloopmap[*p].begin(); o != mkloopmap[*p].end(); o++) {
 
 1191                        incloops.insert(*o);
 
 1195             for (
unsigned int pt2 = 0; pt2 < path[path.size()-1].size(); pt2++) {
 
 1196                     flatpath.push_back(path[path.size()-1][pt2]);
 
 1200             fllp += timeDifference(q2,q1);
 
 1201             flatpath.push_back(endnode);
 
 1212             pathAnalyze(flatpath, 
false, incloops);
 
 1216             int pts = pathsSize++;
 
 1222             bool starter = 
false;
 
 1230                   ROSE_ASSERT(pathsAtMk.find((path.back()).back()) != pathsAtMk.end());
 
 1231                   if ((path.back()).front() == realstartnode) {
 
 1234                   if (currents[(path.back()).back()] < (pathsAtMk[(path.back()).back()].size()) ) {
 
 1235                              std::vector<std::vector<SgGraphNode*> > cpths = pathsAtMk[(path.back()).back()];
 
 1236                              currpth = cpths[currents[(path.back()).back()]];
 
 1237                              currents[(path.back()).back()]++;
 
 1241                       currents[(path.back()).back()] = 0;
 
 1243                       pthloops.pop_back();
 
 1245                   if (starter == 
true) {
 
 1256        struct timeval tdisb, tdise;
 
 1257        tdisb = getCPUTime();
 
 1258        for (
int i = 0; i < pthloops.size(); i++) {
 
 1259            for (std::set<SgGraphNode*>::iterator j = pthloops[i].begin(); j != pthloops[i].end(); j++) {
 
 1260                if (find(currpth.begin(), currpth.end(), *j) != currpth.end()) {
 
 1279        tdise = getCPUTime();
 
 1280        distime += timeDifference(tdise, tdisb);
 
 1286            std::set<SgGraphNode*> pthloopstmp;
 
 1287            pthloopstmp.clear();
 
 1288                for (
int i = 0; i < currpth.size(); i++) {
 
 1290                    if (mkloops.find(currpth[i]) != mkloops.end()) {
 
 1291                       pthloopstmp.insert(currpth[i]);
 
 1294                pthloops.push_back(pthloopstmp);
 
 1295                path.push_back(currpth);
 
 1296                pthloopstmp.clear();
 
 1299                std::vector<SgGraphNode*> oldcurrpth = currpth;
 
 1301                if (currents.find((path.back()).back()) == currents.end()) {
 
 1302                    currents[(path.back()).back()] = 0;
 
 1307                        ROSE_ASSERT(pathsAtMk.find(backnode) != pathsAtMk.end() || backnode == endnode);
 
 1308                        ROSE_ASSERT(pathsAtMk.find(frontnode) != pathsAtMk.end());
 
 1309                        if (currents.find(backnode) == currents.end()) {
 
 1310                            currents[backnode] = 0;
 
 1313                            ROSE_ASSERT(currents[backnode] == 0);
 
 1315                        std::vector<std::vector<SgGraphNode*> > tmppths = pathsAtMk[backnode];
 
 1317                        currpth = tmppths[currents[backnode]];
 
 1318                        ROSE_ASSERT(currpth != oldcurrpth);
 
 1319                        currents[backnode]++;
 
 1326            if (currents[(path.back()).back()] < pathsAtMk[(path.back()).back()].size() || path.back().back() == realstartnode) {
 
 1329            currents[(path.back()).back()] = 0;
 
 1331            pthloops.pop_back();
 
 1333        if ((path.back()).back() != realstartnode) {
 
 1334        currpth = (pathsAtMk[(path.back()).back()])[currents[(path.back()).back()]];
 
 1335        currents[(path.back()).back()]++;
 
 1343std::cout << 
"successes: " << successes << std::endl;
 
 1344std::cout << 
"failures: " << failures << std::endl;
 
 1355template<
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1359  printNodeForAnalysis(n, loopNum, pathVal, ss);
 
 1360  std::set<SgDirectedGraphEdge*> outEdges = g->computeEdgeSetOut(n);
 
 1361  for (std::set<SgDirectedGraphEdge*>::iterator i = outEdges.begin(); i != outEdges.end(); i++) {
 
 1362    if (nullEdgesOrdered.find(*i) == nullEdgesOrdered.end()) {
 
 1363        printEdgeForAnalysis(*i, 
false, ss);
 
 1366        printEdgeForAnalysis(*i, 
true, ss);
 
 1371template<
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1375  for (
unsigned int i = 0; i < n.size()-1; i++) {
 
 1376     if (completedNodesPath.find(n[i]) == completedNodesPath.end()) {
 
 1377         printNodeForAnalysis(n[i], loopNum, pathVal, ss);
 
 1378         completedNodesPath.insert(n[i]);
 
 1380     std::pair<SgGraphNode*, SgGraphNode*> prnod;
 
 1381     prnod.first = n[i+1];
 
 1382     prnod.second = n[i];
 
 1383     if (completedEdgesPath.find(prnod) == completedEdgesPath.end()) {
 
 1384         printEdgeForAnalysisPath(n[i+1], n[i], ss);
 
 1385         completedEdgesPath.insert(prnod);
 
 1388  if (completedNodesPath.find(n[n.size() - 1]) == completedNodesPath.end()) {
 
 1389     printNodeForAnalysis(n[n.size()-1], loopNum, pathVal, ss);
 
 1390     completedNodesPath.insert(n[n.size() - 1]);
 
 1396template<
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1400  int id = n->get_index();
 
 1401  std::string nodeColor = 
"black";
 
 1403  ss << 
id << 
" [label=\"" << 
"LoopNumS" << loopNum << 
"\", color=\"" << 
"green" << 
"\", style=\"" << 
"solid" << 
"\"];\n";
 
 1406  ss << 
id << 
" [label=\"" << 
"pathNumS" << pathNum << 
"\", color=\"" << 
"black" << 
"\", style=\"" << 
"dotted" << 
"\"];\n";
 
 1410template<
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1415      ss << e->get_from()->get_index() << 
" -> " << e->get_to()->get_index() << 
" [label=\"" << 
"NullEdge" << 
"\", style=\"" << 
"dotted" << 
"\"];\n";
 
 1418      ss << e->get_from()->get_index() << 
" -> " << e->get_to()->get_index() << 
" [label=\"" << 
"\", style=\"" << 
"solid" << 
"\"];\n";
 
 1421template<
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1425      ss << g2->get_index() << 
" -> " << g1->get_index() << 
" [label=\"" << 
"Edge" << 
"\", style=\"" << 
"solid" << 
"\"];\n";
 
 1432template<
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1438    bool tookone = 
false;
 
 1439    std::vector<SgGraphNode*> mkpath;
 
 1440    std::vector<SgGraphNode*> marks;
 
 1442    mkglobal.push_back(n);
 
 1445    std::set<SgDirectedGraphEdge*> taken;
 
 1446    std::vector<SgGraphNode*> toTake;
 
 1447    std::vector<SgGraphNode*> path;
 
 1449    mkpath.push_back(n);
 
 1451    int bifurcations = 0;
 
 1452    std::map<SgGraphNode*, bool> completed;
 
 1453    while (done == 
false) {
 
 1454             ROSE_ASSERT(currn != NULL);
 
 1456               if (currn == endnode || completed.find(currn) != completed.end()) {
 
 1457                if (pathsAtMk.find(marks.back()) == pathsAtMk.end()) {
 
 1458                    std::vector<std::vector<SgGraphNode*> > emptypath;
 
 1459                    pathsAtMk[marks.back()] = emptypath;
 
 1462                pathsAtMk[marks.back()].push_back(mkpath);
 
 1469                ROSE_ASSERT(mkpath.front() == marks.back());
 
 1470                if (marks.size() == 0) {
 
 1475                bool haventtaken = 
false;
 
 1479                while (found == 
false) {
 
 1480                    if (marks.size() == 0) {
 
 1485                    std::set<SgDirectedGraphEdge*> oedg = g->computeEdgeSetOut(mark1);
 
 1486                    ROSE_ASSERT(oedg.size() > 1 || mark1 == n);
 
 1487                        for (std::set<SgDirectedGraphEdge*>::iterator j = oedg.begin(); j != oedg.end(); j++) {
 
 1488                            if (taken.find(*j) == taken.end() && haventtaken == 
false) {
 
 1493                        if (haventtaken == 
true) {
 
 1494                            if (marks.back() == n) {
 
 1497                            path.push_back(marks.back());
 
 1498                            if ( mkpath.empty() || (mkpath.back() != marks.back()) ) {
 
 1499                                ROSE_ASSERT(!marks.empty());
 
 1500                                mkpath.push_back(marks.back());
 
 1502                            taken.insert(tooked);
 
 1503                            took = tooked->get_to();
 
 1507                            completed[marks.back()] = 
true;
 
 1512                    if (marks.size() == 0) {
 
 1515                    haventtaken = 
false;
 
 1521            std::set<SgDirectedGraphEdge*> oedg = g->computeEdgeSetOut(currn);
 
 1522            std::set<SgDirectedGraphEdge*> iedg = g->computeEdgeSetIn(currn);
 
 1523            if (oedg.size() > 1) {
 
 1524                     if (mkpath.back() != currn) {
 
 1525                     mkpath.push_back(currn);
 
 1527                     pathsAtMk[marks.back()].push_back(mkpath);
 
 1529                     mkpath.push_back(currn);
 
 1530                     marks.push_back(currn);
 
 1531                     if (find(mkglobal.begin(), mkglobal.end(), currn) == mkglobal.end()) {
 
 1532                         mkglobal.push_back(currn);
 
 1534                     for (std::set<SgDirectedGraphEdge*>::iterator i = oedg.begin(); i != oedg.end(); i++) {
 
 1535                          if (taken.find(*i) == taken.end() && tookone == 
false) {
 
 1538                               took = (*i)->get_to();
 
 1540                          else if (taken.find(*i) == taken.end() && tookone == 
true) {
 
 1547                took = (*(oedg.begin()))->get_to();
 
 1552           if (find(path.begin(), path.end(), took) == path.end()) {
 
 1553               mkpath.push_back(took);
 
 1554               path.push_back(took);
 
 1558               mkloops.insert(took);
 
 1559               std::vector<SgGraphNode*> lptemp;
 
 1561               lptemp.push_back(took);
 
 1562               while (path.back() != took) {
 
 1566                   lptemp.push_back(path.back());
 
 1569               (mkloopmap[took]).insert(lptemp);
 
 1581               path.push_back(took);
 
 1582               currn = path.back();
 
 1583               mkpath.push_back(took);
 
 1592template <
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1593SynthesizedAttributeType
 
 1597    SynthesizedAttributeType s = SynthesizedAttributeType();
 
 1604template <
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1608    std::map<SgGraphNode*, int> incomputables;
 
 1609    std::set<SgGraphNode*> lpposs;
 
 1615        if (orders % 10000 == 0) {
 
 1616            std::cout << 
"orders: " << orders << std::endl;
 
 1619        if (currn == endnode) {
 
 1621        if (computable(g, currn) || currn == n) {
 
 1623            if (oVals.find(currn) == oVals.end()) {
 
 1624                 oVals[currn] = currm++;
 
 1625                 iVals[currm++] = currn;
 
 1628            if (currn == endnode) {
 
 1632            std::pair<bool, SgGraphNode*> pbs = getNextChild(g, currn);
 
 1633            computedNodes.insert(currn);
 
 1634            ROSE_ASSERT(pbs.first == 
true);
 
 1638            std::pair<bool, SgGraphNode*> pbp = getNextPar(g, currn);
 
 1639            ROSE_ASSERT(pbp.first == 
true);
 
 1645    std::cout << 
"required orders" << orders << std::endl;
 
 1646    std::cout << 
"incomputables.size() " << incomputables.size() << std::endl;
 
 1650template <
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1654    if (computedNodes.find(n) != computedNodes.end()) {
 
 1657    std::set<SgDirectedGraphEdge*> ed = g->computeEdgeSetIn(n);
 
 1659    for (std::set<SgDirectedGraphEdge*>::iterator i = ed.begin(); i != ed.end(); i++) {
 
 1660        if (oVals.find((*i)->get_from()) == oVals.end() && nullEdgesOrdered.find(*i) == nullEdgesOrdered.end()) {
 
 1670template <
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1678    for (std::map<int, SgGraphNode*>::iterator i = iVals.begin(); i != iVals.end(); i++) {
 
 1680        ROSE_ASSERT(canEval(g, (*i).second));
 
 1683        evalNodeOrdered(g, (*i).second);
 
 1688template <
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1693    if (inhVals.find(n) == inhVals.end()) {
 
 1694    std::set<SgDirectedGraphEdge*> ins = g->computeEdgeSetIn(n);
 
 1695    for (std::set<SgDirectedGraphEdge*>::iterator i = ins.begin(); i != ins.end(); i++) {
 
 1696        if (inhVals.find((*i)->get_from()) == inhVals.end() && nullEdgesOrdered.find(*i) == nullEdgesOrdered.end()) {
 
 1706template <
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1710    if (inhVals.find(n) != inhVals.end()) {
 
 1713    std::set<SgDirectedGraphEdge*> par = g->computeEdgeSetIn(n);
 
 1714    std::vector<InheritedAttributeType> inh;
 
 1715    for (std::set<SgDirectedGraphEdge*>::iterator i = par.begin(); i != par.end(); i++) {
 
 1716        if (inhVals.find((*i)->get_from()) != inhVals.end()) {
 
 1717            inh.push_back(inhVals[(*i)->get_from()]);
 
 1721    if (n != st || inh.size() > 0) {
 
 1722        InheritedAttributeType inhX;
 
 1723        inhX = evaluateInheritedAttribute(n, inh);
 
 1732template <
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1736       if (pathValMap.find(currn) != pathValMap.end()) {
 
 1739       std::set<SgDirectedGraphEdge*> ined = g->computeEdgeSetIn(currn);
 
 1740       int tmppathcount = 0;
 
 1741       for (std::set<SgDirectedGraphEdge*>::iterator i = ined.begin(); i != ined.end(); i++) {
 
 1742            ROSE_ASSERT(pathValMap.find((*i)->get_from()) != pathValMap.end() );
 
 1746            int pv = pathValMap[(*i)->get_from()];
 
 1751        pathValMap[currn] = tmppathcount;
 
 1756template <
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1757std::pair<bool, SgGraphNode*>
 
 1760    bool nullPoss = 
false;
 
 1762    std::set<SgDirectedGraphEdge*> outs = g->computeEdgeSetOut(n);
 
 1767    bool completed = 
false;
 
 1768    bool completeNull = 
false;
 
 1770    for (std::set<SgDirectedGraphEdge*>::iterator i = outs.begin(); i != outs.end(); i++) {
 
 1772        if (outs.size() == 1) {
 
 1773            nextNode = (*i)->get_to();
 
 1774            if (nullEdgesOrdered.find(*i) != nullEdgesOrdered.end()) {
 
 1780        else if (completed == 
false && computedNodes.find((*i)->get_to()) == computedNodes.end()) {
 
 1782            nextNode = (*i)->get_to();
 
 1783            if (nullEdgesOrdered.find(*i) != nullEdgesOrdered.end()) {
 
 1786            completedEdgesOut.insert(*i);
 
 1791    std::pair<bool, SgGraphNode*> pr;
 
 1792    ROSE_ASSERT (completed == 
true || completeNull == 
true);
 
 1793    if (completed == 
true) {
 
 1794        pr.first = completed;
 
 1795        pr.second = nextNode;
 
 1800        pr.second = nullNode;
 
 1807template <
class InheritedAttributeType, 
class SynthesizedAttributeType>
 
 1808std::pair<bool, SgGraphNode*>
 
 1811    std::set<SgDirectedGraphEdge*> ins = g->computeEdgeSetIn(n);
 
 1814    bool completed = 
false;
 
 1815    bool completeNull = 
false;
 
 1816    for (std::set<SgDirectedGraphEdge*>::iterator i = ins.begin(); i != ins.end(); i++) {
 
 1818        if (ins.size() == 1 ) {
 
 1820            completedEdges.insert(*i);
 
 1821            nextPar = (*i)->get_from();
 
 1824        else if (completedEdges.find(*i) == completedEdges.end() && completed == 
false) {
 
 1826            nextPar = (*i)->get_from();
 
 1827            completedEdges.insert(*i);
 
 1830        else if (completedEdges.find(*i) != completedEdges.end() && computedNodes.find((*i)->get_from()) == computedNodes.end() && completed == 
false ) {
 
 1831            completeNull = 
true;
 
 1832            std::pair<SgGraphNode*, SgGraphNode*> lpp;
 
 1834            nullEdgesOrdered.insert(*i);
 
 1839    ROSE_ASSERT(completed == 
true || completeNull == 
true);
 
 1840    std::pair<bool, SgGraphNode*> pr;
 
 1841    pr.first = completed;
 
 1842    pr.second = nextPar;
 
 1844    if (completeNull == 
true && completed == 
false) {
 
 1845        pr.first = completeNull;
 
 1846        pr.second = nextPar;
 
InheritedAttributeType traverse(SgGraphNode *basenode, SgIncidenceDirectedGraph *g, InheritedAttributeType inheritedValue, InheritedAttributeType nullInherit, SgGraphNode *endnode, bool insep=false, bool pcHk=false)
This is the function that is used by the user directly to start the algorithm.