LCOV - code coverage report
Current view: top level - home/yyan7/compiler/rexompiler/src/midend/astProcessing - AstProcessing.C (source / functions) Hit Total Coverage
Test: ROSE Lines: 15 19 78.9 %
Date: 2022-12-08 13:48:47 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // tps (01/14/2010) : Switching from rose.h to sage3.
       2             : #include "sage3basic.h"
       3             : 
       4             : // Original Author (AstProcessing classes): Markus Schordan
       5             : // Rewritten by: Gergo Barany
       6             : // $Id: AstProcessing.C,v 1.10 2008/01/25 02:25:48 dquinlan Exp $
       7             : 
       8             : // For information about the changes introduced during the rewrite, see
       9             : // the comment in AstProcessing.h
      10             : 
      11             : // GB (05/30/2007): This was completely rewritten from the old version to
      12             : // use much more efficient comparisons now available to us; it also never
      13             : // causes visits to included files, something that happened from time to
      14             : // time with the old version.
      15             : bool 
      16   277916000 : SgTreeTraversal_inFileToTraverse(SgNode* node, bool traversalConstraint, SgFile* fileToVisit)
      17             :    {
      18             : #if 0
      19             :   // DQ (8/20/2018): Added debugging for support unparsing of header files.
      20             :      printf ("In SgTreeTraversal_inFileToTraverse(): traversalConstraint = %s fileToVisit = %p filename = %s node = %p = %s \n",
      21             :              traversalConstraint ? "true" : "false",fileToVisit,(traversalConstraint == true) ? fileToVisit->getFileName().c_str() : "null",
      22             :              node,node != NULL ? node->class_name().c_str() : "null");
      23             : #endif
      24             : 
      25             :   // If traversing without constraint, just continue.
      26             :   // if (!traversalConstraint)
      27   277916000 :      if (traversalConstraint == false)
      28             :         {
      29             :           return true;
      30             :         }
      31             : 
      32             :   // DQ (1/21/2008): Recently added SgAsmNodes for binaries also do not 
      33             :   // have a SgFileInfo object.
      34             :   // Of all the nodes to be traversed, only SgProject is allowed to have
      35             :   // a NULL file info; go ahead and try to traverse it (even though this
      36             :   // does not make sense since it is not within any file).
      37     1336860 :      if (node->get_file_info() == NULL)
      38             :         {
      39             :        // DQ (1/20/2008): This fails for binary files, why is this!
      40             :        // if (isSgProject(node) == NULL)
      41             :        //      printf ("What node is this: node = %p = %s \n",node,node->class_name().c_str()); // SageInterface::get_name(node).c_str());
      42             :        // ROSE_ASSERT(isSgProject(node) != NULL);
      43             : 
      44             :        // DQ (11/20/2013): Added SgJavaImportStatementList and SgJavaClassDeclarationList to the exception list since they don't have a source position field.
      45             :        // if (isSgProject(node) == NULL && isSgAsmNode(node) == NULL)
      46           0 :           if (isSgProject(node) == NULL )
      47             :              {
      48           0 :                printf ("Error: SgTreeTraversal_inFileToTraverse() --- node->get_file_info() == NULL: node = %p = %s \n",node,node->class_name().c_str());
      49           0 :                SageInterface::dumpInfo(node);
      50             :              }
      51             : 
      52             : #if 0
      53             :        // DQ (11/19/2013): Allow this to pass while we are evaluating the AST traversal for Java.
      54             :        // ROSE_ASSERT(isSgProject(node) != NULL || isSgAsmNode(node) != NULL);
      55             :        // if (isSgProject(node) == NULL && isSgAsmNode(node) == NULL)
      56             :           if (isSgProject(node) == NULL && isSgAsmNode(node) == NULL && isSgJavaImportStatementList(node) == NULL && isSgJavaClassDeclarationList(node) == NULL)
      57             :              {
      58             :                printf ("WARNING: isSgProject(node) == NULL && isSgAsmNode(node) == NULL: this could be Java code using an incomplete AST: node = %p = %s \n",node,node->class_name().c_str());
      59             :              }
      60             : #endif
      61             : 
      62           0 :           return true;
      63             :         }
      64             : 
      65             :   // Traverse compiler generated code and code generated from
      66             :   // transformations, unless it is "frontend specific" like the stuff in
      67             :   // rose_edg_required_macros_and_functions.h.
      68     1336860 :      bool isFrontendSpecific = node->get_file_info()->isFrontendSpecific();
      69     1336860 :      bool isCompilerGeneratedOrPartOfTransformation;
      70     1336860 :      if (isFrontendSpecific)
      71             :         {
      72             :           isCompilerGeneratedOrPartOfTransformation = false;
      73             :         }
      74             :        else
      75             :         {
      76             :        // DQ (11/14/2008): Implicitly defined functions in Fortran are not marked as compiler generated 
      77             :        // (the function body is at least explicit in the source file), but the function declaration IR 
      78             :        // nodes is marked as coming from file == NULL_FILE and it is also marked as "outputInCodeGeneration"
      79             :        // So it should be traversed so that we can see the function body and so that it can be a proper 
      80             :        // part of the definition of the AST.
      81             :        // isCompilerGeneratedOrPartOfTransformation = node->get_file_info()->isCompilerGenerated() || node->get_file_info()->isTransformation();
      82      239300 :           bool isOutputInCodeGeneration = node->get_file_info()->isOutputInCodeGeneration();
      83      239300 :           isCompilerGeneratedOrPartOfTransformation = node->get_file_info()->isCompilerGenerated() || node->get_file_info()->isTransformation() || isOutputInCodeGeneration;
      84             :         }
      85             : 
      86             :   // Traverse this node if it is in the file we want to visit.
      87     1336860 :      bool isRightFile = node->get_file_info()->isSameFile(fileToVisit);
      88             : 
      89             : #if 0
      90             :      printf ("In SgTreeTraversal_inFileToTraverse(): node = %p = %s isRightFile = %s \n",node,node->class_name().c_str(),isRightFile ? "true" : "false");
      91             : #endif
      92             : 
      93             :   // This function is meant to traverse input files in the sense of not
      94             :   // visiting "header" files (a fuzzy concept). But not every #included file
      95             :   // is a header, "code" (another fuzzy concept) can also be #included; see
      96             :   // test2005_157.C for an example. We want to traverse such code, so we
      97             :   // cannot rely on just comparing files.
      98             :   // The following heuristic is therefore used: If a node is included from
      99             :   // global scope or from within a namespace definition, we guess that it is
     100             :   // a header and don't traverse it. Otherwise, we guess that it is "code"
     101             :   // and do traverse it.
     102     1336860 :      bool isCode = node->get_parent() != NULL
     103     1336860 :                    && !isSgGlobal(node->get_parent())
     104     1459610 :                    && !isSgNamespaceDefinitionStatement(node->get_parent());
     105             : 
     106     1336860 :      bool traverseNode;
     107     1336860 :      if (isCompilerGeneratedOrPartOfTransformation || isRightFile || isCode)
     108             :           traverseNode = true;
     109             :        else
     110     1208340 :           traverseNode = false;
     111             : 
     112             : 
     113             : #if 0
     114             :   // DQ (8/17/2018): Need to stop here and debug this function tomorrow.
     115             :      printf ("Exiting as a test! \n");
     116             :      ROSE_ABORT();
     117             : #endif
     118             : 
     119             : #if 0
     120             :   // DQ (8/20/2018): Added debugging for support unparsing of header files.
     121             :      printf ("Leaving SgTreeTraversal_inFileToTraverse(): traverseNode = %s \n",traverseNode ? "true" : "false");
     122             : #endif
     123             : 
     124             :      return traverseNode;
     125             :    }

Generated by: LCOV version 1.14