コード例 #1
0
// DQ (5/22/2005): Added function with better name, since none of the fixes are really
// temporary any more.
void AstPostProcessing (SgNode* node)
{
    // DQ (7/7/2005): Introduce tracking of performance of ROSE.
    TimingPerformance timer ("AST post-processing:");

    // printf ("Inside of AstPostProcessing(node = %p) \n",node);

    // DQ (3/17/2007): This should be empty
    if (SgNode::get_globalMangledNameMap().size() != 0)
    {
        if (SgProject::get_verbose() > 0)
        {
            printf("AstPostProcessing(): found a node with globalMangledNameMap size not equal to 0: SgNode = %s =%s ", node->sage_class_name(),SageInterface::get_name(node).c_str());
            printf ("SgNode::get_globalMangledNameMap().size() != 0 size = %zu (clearing mangled name cache) \n",SgNode::get_globalMangledNameMap().size());
        }

        SgNode::clearGlobalMangledNameMap();
    }
    ROSE_ASSERT(SgNode::get_globalMangledNameMap().size() == 0);

    switch (node->variantT())
    {
    case V_SgProject:
    {
        SgProject* project = isSgProject(node);
        ROSE_ASSERT(project != NULL);

        // GB (8/19/2009): Added this call to perform post-processing on
        // the entire project at once. Conversely, commented out the
        // loop iterating over all files because repeated calls to
        // AstPostProcessing are slow due to repeated memory pool
        // traversals of the same nodes over and over again.
        // Only postprocess the AST if it was generated, and not were we just did the parsing.
        // postProcessingSupport(node);

        // printf ("In AstPostProcessing(): project->get_exit_after_parser() = %s \n",project->get_exit_after_parser() ? "true" : "false");
        if (project->get_exit_after_parser() == false)
        {
            postProcessingSupport (node);
        }
#if 0
        SgFilePtrList::iterator fileListIterator;
        for (fileListIterator = project->get_fileList().begin(); fileListIterator != project->get_fileList().end(); fileListIterator++)
        {
            // iterate through the list of current files
            AstPostProcessing(*fileListIterator);
        }
#endif

        // printf ("SgProject support not implemented in AstPostProcessing \n");
        // ROSE_ASSERT(false);
        break;
    }

    case V_SgDirectory:
    {
        SgDirectory* directory = isSgDirectory(node);
        ROSE_ASSERT(directory != NULL);

        printf ("SgDirectory support not implemented in AstPostProcessing \n");
        ROSE_ASSERT(false);
        break;
    }

    case V_SgFile:
    case V_SgSourceFile:
    {
        SgFile* file = isSgFile(node);
        ROSE_ASSERT(file != NULL);

        // Only postprocess the AST if it was generated, and not were we just did the parsing.
        if (file->get_exit_after_parser() == false)
        {
            postProcessingSupport (node);
        }

        break;
    }

    // Test for a binary executable, object file, etc.
    case V_SgBinaryComposite:
    {
        SgBinaryComposite* file = isSgBinaryComposite(node);
        ROSE_ASSERT(file != NULL);

        printf ("AstPostProcessing of SgBinaryFile \n");
        ROSE_ASSERT(false);

        break;
    }

    default:
    {
        // list general post-processing fixup here ...
        postProcessingSupport (node);
    }
    }

    // DQ (3/17/2007): Clear the static globalMangledNameMap, likely this is not enough and the mangled name map
    // should not be used while the names of scopes are being reset (done in the AST post-processing).
    SgNode::clearGlobalMangledNameMap();
}
コード例 #2
0
// DQ (5/22/2005): Added function with better name, since none of the fixes are really
// temporary any more.
void AstPostProcessing (SgNode* node)
   {
  // DQ (7/7/2005): Introduce tracking of performance of ROSE.
     TimingPerformance timer ("AST post-processing:");

     ROSE_ASSERT(node != NULL);

  // printf ("Inside of AstPostProcessing(node = %p) \n",node);

  // DQ (1/31/2014): We want to enforce this, but for now issue a warning if it is not followed.
  // Later I want to change the function's API to onoy take a SgProject.  Note that this is 
  // related to a performance bug that was fixed by Gergo a few years ago.  The fix could be
  // improved by enforcing that this could not be called at the SgFile level of the hierarchy.
     if (isSgProject(node) == NULL)
        {
          printf ("Error: AstPostProcessing should only be called on SgProject (due to repeated memory pool traversals when multiple files are specified on the command line). node = %s \n",node->class_name().c_str());
        }
  // DQ (1/31/2014): This is a problem to enforce this for at least (this test program): 
  //      tests/roseTests/astRewriteTests/testIncludeDirectiveInsertion.C
  // ROSE_ASSERT(isSgProject(node) != NULL);

  // DQ (3/17/2007): This should be empty
     if (SgNode::get_globalMangledNameMap().size() != 0)
        {
          if (SgProject::get_verbose() > 0)
             {
                printf("AstPostProcessing(): found a node with globalMangledNameMap size not equal to 0: SgNode = %s =%s ", node->class_name().c_str(),SageInterface::get_name(node).c_str());
               printf ("SgNode::get_globalMangledNameMap().size() != 0 size = %" PRIuPTR " (clearing mangled name cache) \n",SgNode::get_globalMangledNameMap().size());
             }

          SgNode::clearGlobalMangledNameMap();
        }
     ROSE_ASSERT(SgNode::get_globalMangledNameMap().size() == 0);

     switch (node->variantT())
        {
          case V_SgProject:
             {
               SgProject* project = isSgProject(node);
               ROSE_ASSERT(project != NULL);

            // GB (8/19/2009): Added this call to perform post-processing on
            // the entire project at once. Conversely, commented out the
            // loop iterating over all files because repeated calls to
            // AstPostProcessing are slow due to repeated memory pool
            // traversals of the same nodes over and over again.
            // Only postprocess the AST if it was generated, and not were we just did the parsing.
            // postProcessingSupport(node);

            // printf ("In AstPostProcessing(): project->get_exit_after_parser() = %s \n",project->get_exit_after_parser() ? "true" : "false");
               if (project->get_exit_after_parser() == false)
                  {
                    postProcessingSupport (node);
                  }
#if 0
               SgFilePtrList::iterator fileListIterator;
               for (fileListIterator = project->get_fileList().begin(); fileListIterator != project->get_fileList().end(); fileListIterator++)
                  {
                 // iterate through the list of current files
                    AstPostProcessing(*fileListIterator);
                  }
#endif

            // printf ("SgProject support not implemented in AstPostProcessing \n");
            // ROSE_ASSERT(false);
               break;
             }

          case V_SgDirectory:
             {
               SgDirectory* directory = isSgDirectory(node);
               ROSE_ASSERT(directory != NULL);

               printf ("SgDirectory support not implemented in AstPostProcessing \n");
               ROSE_ASSERT(false);
               break;
             }

          case V_SgFile:
          case V_SgSourceFile:
             {
               SgFile* file = isSgFile(node);
               ROSE_ASSERT(file != NULL);

            // Only postprocess the AST if it was generated, and not were we just did the parsing.
               if (file->get_exit_after_parser() == false)
                  {
                    postProcessingSupport (node);
                  }
               
               break;
             }

       // Test for a binary executable, object file, etc.
          case V_SgBinaryComposite:
             {
               SgBinaryComposite* file = isSgBinaryComposite(node);
               ROSE_ASSERT(file != NULL);

               printf ("Error: AstPostProcessing of SgBinaryFile is not defined \n");
               ROSE_ASSERT(false);

               break;
             }

          default:
             {
            // list general post-processing fixup here ...
               postProcessingSupport (node);
             }
        }

#if 0
  // DQ (1/12/2015): Save this so that we can check it for where it might be reset to be compiler generated (a bug).
     extern SgFunctionDeclaration* saved_functionDeclaration;
     ROSE_ASSERT(saved_functionDeclaration != NULL);

     printf ("saved_functionDeclaration = %p = %s \n",saved_functionDeclaration,saved_functionDeclaration->class_name().c_str());
     SgFunctionDeclaration* nondefiningDeclaration = isSgFunctionDeclaration(saved_functionDeclaration->get_firstNondefiningDeclaration());
     SgFunctionDeclaration* definingDeclaration    = isSgFunctionDeclaration(saved_functionDeclaration->get_definingDeclaration());
     printf ("saved_functionDeclaration nondefiningDeclaration = %p \n",nondefiningDeclaration);
     printf ("saved_functionDeclaration definingDeclaration    = %p \n",definingDeclaration);

     saved_functionDeclaration->get_startOfConstruct()->display("AstPostProcessing: saved_functionDeclaration source position of the first non-defining declaration that was modified by EDG: START: debug");
     saved_functionDeclaration->get_endOfConstruct()  ->display("AstPostProcessing: saved_functionDeclaration source position of the first non-defining declaration that was modified by EDG: END: debug");
#endif

  // DQ (3/17/2007): Clear the static globalMangledNameMap, likely this is not enough and the mangled name map 
  // should not be used while the names of scopes are being reset (done in the AST post-processing).
     SgNode::clearGlobalMangledNameMap();
   }