示例#1
0
void
CompassAnalyses::FunctionDocumentation::Traversal::
visit(SgNode* sgNode)
{ 
  // Implement your traversal here.  
  if (isSgFunctionDeclaration(sgNode)) 
    {
      SgFunctionDeclaration* funcDecl = isSgFunctionDeclaration(sgNode);
      if (funcDecl->get_file_info()->isCompilerGenerated() 
          || funcDecl->get_definingDeclaration() != sgNode
          )
        return;


      if (!( isDocumented( funcDecl) || 
          isDocumented(isSgFunctionDeclaration(funcDecl->get_firstNondefiningDeclaration()))
           ) 
         ) {
        std::string funcName = funcDecl->get_qualified_name();
        output->addOutput(new CheckerOutput(funcDecl, funcName));
      }

    }




} //End of the visit function.
 virtual void visit(SgNode *node) { /*override*/
     SgFunctionCallExp *fcall = isSgFunctionCallExp(node);
     SgFunctionDeclaration *fdecl = fcall ? fcall->getAssociatedFunctionDeclaration() : NULL;
     std::string fname = fdecl ? fdecl->get_qualified_name().getString() : "";
     if (SageInterface::is_Java_language()) {
         if (0==fname.compare("System.getenv")) {
             found.push_back(fcall);
             CodeProperties::message(std::cout, fcall, "environment variable is read");
         }
     } else if (0==fname.compare("::getenv")) {
         found.push_back(fcall);
         CodeProperties::message(std::cout, fcall, "environment variable is read");
     }
 }
 foreach(SgDirectedGraphEdge *edge, edges) {
     SgGraphNode *toNode = edge->get_to();
     SgFunctionDeclaration *toDecl = isSgFunctionDeclaration(toNode->get_SgNode());
     ROSE_ASSERT(toDecl != NULL);
     
     if(toDecl->get_specialFunctionModifier().isConstructor() || toDecl->get_specialFunctionModifier().isDestructor())
         continue;
     
     if(find(functions.begin(), functions.end(), toDecl) == functions.end()) {
          graph->removeDirectedEdge(edge);
          std::cout << "Edge removed from " << defDecl->get_qualified_name().getString() << " to " << 
                  toDecl->get_qualified_name().getString()<< std::endl;
     }
     
 }
示例#4
0
// DQ (6/25/2011): Put the function definition into the source file (avoid function definitions in header files).
// std::string operator()(SgNode* node)
std::string AstDOTGenerationExtended_Defaults::NamedExtraNodeInfo::operator()(SgNode* node)
   {
                        std::ostringstream ss;

                        // add namespace name
                        if (SgNamespaceDeclarationStatement* n = isSgNamespaceDeclarationStatement(node))
                        {
                                ss << n->get_qualified_name().str() << "\\n";
                        }
                        // add class name
                        if (SgClassDeclaration* n = isSgClassDeclaration(node))
                        {
                                ss << n->get_qualified_name().str() << "\\n";
                        }
                        // add function name
                        if (SgFunctionDeclaration* n = isSgFunctionDeclaration(node))
                        {
                                ss << n->get_qualified_name().str() << "\\n";
                        }
                        if (SgFunctionRefExp* n = isSgFunctionRefExp(node))
                        {
                                SgFunctionDeclaration* decl = n->getAssociatedFunctionDeclaration();
                                if (decl) // it's null if through a function pointer
                                {
                                        ss << decl->get_qualified_name().str() << "\\n";
                                }
                        }
                        // add variable name
                        if (SgInitializedName* n = isSgInitializedName(node))
                        {
                                ss << n->get_qualified_name().str() << "\\n";
                        }
                        if (SgVarRefExp* n = isSgVarRefExp(node))
                        {
                                SgVariableSymbol* sym = n->get_symbol();
                                ss << sym->get_name().getString() << "\\n";
                        }
                        // add variable name
                        if (SgVariableSymbol* n = isSgVariableSymbol(node))
                        {
                                ss << n->get_name().str() << "\\n";
                        }

                        return ss.str();
   }