示例#1
0
void visitorTraversal::analyzePath(std::vector<VertexID>& pathR) {
    std::vector<string> path;
   for (unsigned int j = 0; j < pathR.size(); j++) {
       SgGraphNode* R = getGraphNode[pathR[j]];
      CFGNode cf = cfg->toCFGNode(R);
       string str = cf.toString();str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());
       path.push_back(str);
    }
    paths.push_back(path);
   // ROSE_ASSERT(sssv.find(path) != sssv.end());
}
示例#2
0
void visitorTraversal::analyzePath(std::vector<VertexID>& pathR) {
    std::vector<SgGraphNode*> exprPath;
    std::vector<string> path;
    //ss << "vector<string> sss;\n";
    for (unsigned int j = 0; j < pathR.size(); j++) {
       SgGraphNode* R = getGraphNode[pathR[j]];
      CFGNode cf = cfg->toCFGNode(R);
   //    path.push_back(R->get_name());
      string str = cf.toString();
      str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());
       //ss << "string str = \"" << str << "\";\n";
       ss << "sss.push_back(\"" << str << "\");\n";
    }
    ss << "sssv.insert(sss);\n";
    ss << "sss.clear();\n";
   // paths.insert(path);
    
}
示例#3
0
int main( int argc, char * argv[] )
   {
  // Build the AST used by ROSE
     SgProject* project = frontend(argc,argv);
     ROSE_ASSERT(project != NULL);

  // Build a list of functions within the AST and find all access functions 
  // (function name starts with "get_" or "set_")

  // Build list using a query of the whole AST
     Rose_STL_Container<SgNode*> functionDefinitionList = NodeQuery::querySubTree (project,V_SgFunctionDefinition);

  // Build list using nested Queries (operating on return result of previous query)
  //   Rose_STL_Container<SgNode*> accessFunctionsList;
  //   accessFunctionsList = NodeQuery::queryNodeList (functionDeclarationList,&querySolverAccessFunctions);
  //   printFunctionDeclarationList(accessFunctionsList);

  // Alternative form of same query building the list using a query of the whole AST
   //  accessFunctionsList = NodeQuery::querySubTree (project,&querySolverAccessFunctions);
   //  printFunctionDeclarationList(accessFunctionsList);
int counter = 0;
for (Rose_STL_Container<SgNode*>::iterator i = functionDefinitionList.begin(); i != functionDefinitionList.end(); i++) {
   SgFunctionDefinition* fnc = isSgFunctionDefinition(*i);
  stringstream ss; 
  SgFunctionDeclaration* functionDeclaration = fnc->get_declaration();
  string fileName= functionDeclaration->get_name().str();//StringUtility::stripPathFromFileName(mainDef->get_file_info()->get_filenameString());
    string dotFileName1;
ss << fileName << "." << counter << ".dot";
    counter++;
    dotFileName1 = ss.str();
    //SgFunctionDefinition* fnc = functionDeclaration->get_definition();
    if (fnc != NULL) {
    StaticCFG::CFG* cfg = new StaticCFG::CFG(fnc);
    SgIncidenceDirectedGraph* g = new SgIncidenceDirectedGraph();
     visitorTraversal* vis = new visitorTraversal();
    g = cfg->getGraph();
    myGraph* mg = new myGraph();
    mg = instantiateGraph(g, (*cfg));
    vis->tltnodes = 0;
    vis->paths = 0;
 std::cout << dotFileName1 << std::endl;
 cfgToDot(fnc,dotFileName1);
    //vis->firstPrepGraph(constcfg);
    //t1 = getCPUTime();
    vis->constructPathAnalyzer(mg, true, 0, 0, true);
    
    //t2 = getCPUTim
    std::cout << "function: " << fileName << std::endl;
    std::cout << "paths: " << vis->paths << std::endl;
    delete vis;
    delete cfg;
    delete g;
    delete mg;
    //std::cout << "took: " << timeDifference(t2, t1) << std::endl;
    }
    }
   SgProject* proj = project; 
   SgFunctionDeclaration* mainDefDecl = SageInterface::findMain(proj);
   if (mainDefDecl != NULL) {
  SgFunctionDefinition* mainDef = mainDefDecl->get_definition();
   visitorTraversal* vis = new visitorTraversal();
    StaticCFG::CFG cfg(mainDef);
   //cfg.buildFullCFG();
    stringstream ss;
    string fileName= StringUtility::stripPathFromFileName(mainDef->get_file_info()->get_filenameString());
    string dotFileName1=fileName+"."+ mainDef->get_declaration()->get_name() +".dot";

    cfgToDot(mainDef,dotFileName1);
    //cfg->buildFullCFG();
    SgIncidenceDirectedGraph* g = new SgIncidenceDirectedGraph();
    g = cfg.getGraph();
    myGraph* mg = new myGraph();
    mg = instantiateGraph(g, cfg);
    vis->tltnodes = 0;
    vis->paths = 0;
    //vis->firstPrepGraph(constcfg);
    vis->constructPathAnalyzer(mg, true, 0, 0, true);
    //std::cout << "took: " << timeDifference(t2, t1) << std::endl;
    //cfg.clearNodesAndEdges();
    std::cout << "finished" << std::endl;
    std::cout << "tltnodes: " << vis->tltnodes << " paths: " << vis->paths << std::endl;
    //std::cout << "ipaths: " << ipaths << std::endl;
    delete vis;

    }

// Another way to query for collections of IR nodes
     VariantVector vv1 = V_SgClassDefinition;
     std::cout << "Number of class definitions in the memory pool is: " << NodeQuery::queryMemoryPool(vv1).size() << std::endl;

  // Another way to query for collections of multiple IR nodes.
  // VariantVector(V_SgType) is internally expanded to all IR nodes derived from SgType.
     VariantVector vv2 = VariantVector(V_SgClassDefinition) + VariantVector(V_SgType);
     std::cout << "Number of class definitions AND types in the memory pool is: " << NodeQuery::queryMemoryPool(vv2).size() << std::endl;

  // Note: Show composition of AST queries

     return 0;
   }