当前位置: 首页>>代码示例>>C++>>正文


C++ SgStatement::unparseToString方法代码示例

本文整理汇总了C++中SgStatement::unparseToString方法的典型用法代码示例。如果您正苦于以下问题:C++ SgStatement::unparseToString方法的具体用法?C++ SgStatement::unparseToString怎么用?C++ SgStatement::unparseToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SgStatement的用法示例。


在下文中一共展示了SgStatement::unparseToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: printf

SgNode*
SourceLocationInheritedAttribute::
getCurrentStatementInScope( SgScopeStatement* targetScope ) const
   {
     ROSE_ASSERT (targetScope != NULL);

#if 1
     printf ("At top of SourceLocationInheritedAttribute::getCurrentStatementInScope(): targetScope = %p targetScope->sage_class_name() = %s \n",
          targetScope,targetScope->sage_class_name());
#endif

     int scopeDepth = -1;
     unsigned int i;

  // Search the scopeList for the target scope. We no longer use the index of the 
  // scope to compute the index into the statement list. This would be complicated 
  // since the lists are different sizes debending on the details of the traversal 
  // of the AST (what is a child vs. what is a new sort of Sage node).
     for (i = 0; i < scopeList.size(); i++)
        {
          ROSE_ASSERT (scopeList[i] != NULL);
          if (scopeList[i] == targetScope)
               scopeDepth = i;
        }

#if 1
  // error checking (redundent with assert below, but provides better user interface) 
  // printf ("scopeDepth = %d \n",scopeDepth);
     if (scopeDepth < 0)
        {
       // Report an error since no scope was found
          printf ("ERROR: target scope was not found targetScope = %p targetScope->unparseToString() = %s \n",
               targetScope,targetScope->unparseToString().c_str());
          ROSE_ABORT();
        }
#endif

     ROSE_ASSERT (scopeDepth >= 0);

  // Now get the depth of the associated target statement
  // int targetStatementDepth = scopeDepth+1;
  // increment depends upon number of functions (could be more than one with local class definitions).
  // int targetStatementDepth = scopeDepth+1;

#if 1
     printf ("In SourceLocationInheritedAttribute::getCurrentStatementInScope(): scopeDepth = %d  scopeList.size()     = %zu \n",scopeDepth,scopeList.size());
     printf ("In SourceLocationInheritedAttribute::getCurrentStatementInScope(): scopeDepth = %d  statementList.size() = %zu \n",scopeDepth,statementList.size());
     printf ("##### Find the associated current statement in the target scope: \n");
#endif

  // If this is not a query about the deepest scope then we can find the current statement 
  // in scopeList by looking at the next scope.  Else we have to look at the last statement in the 
  // statement list (to find the current statement in the deepest (currently local) scope).
     SgStatement* targetStatement = NULL;
     if (scopeDepth < (int)(scopeList.size()-1))
        {
          printf ("     use the NEXT statement in the scope list \n");
#if 0
          targetStatement = scopeList[scopeDepth+1];
#else
       // We need to find the target statement in the targe scope, this might not be in the
       // list of scopes since only some scopes are saved to avoid redundent accumulation of 
       // multiple nodes that can represent only a single scope (e.g. functions).  The scope
       // that we store are not always the ones that represent the first node representing 
       // that scope (e.g. functions). But the targetStaement must be initialized to the 
       // statement that appears in the target scope (because the insertion mechanism requires 
       // this).
          int indexOfTargetStatement = -1;
          for (i = 0; i < statementList.size(); i++)
             {
               ROSE_ASSERT (statementList[i] != NULL);
               if (statementList[i] == targetScope)
                    indexOfTargetStatement = i+1;
             }
          ROSE_ASSERT (indexOfTargetStatement >= 0);
          ROSE_ASSERT (indexOfTargetStatement < (int)statementList.size());
          targetStatement = statementList[indexOfTargetStatement];
#endif
        }
       else
        {
          printf ("     use the LAST statement in the statement list \n");
          targetStatement = *(statementList.rbegin());
        }

     ROSE_ASSERT (targetStatement != NULL);

#if 0
     if (isSgScopeStatement( *(statementList.rbegin()) ) != NULL)
          targetStatementDepth = scopeDepth;
       else
          targetStatementDepth = scopeDepth+1;
#endif

#if 1
     printf ("targetScope     = %p targetScope->sage_class_name()     = %s \n",
          targetScope,targetScope->sage_class_name());
     printf ("targetScope = %p targetScope->unparseToString() = %s \n",
          targetScope,targetScope->unparseToString().c_str());
     printf ("targetStatement = %p targetStatement->sage_class_name() = %s \n",
//.........这里部分代码省略.........
开发者ID:Federico2014,项目名称:edg4x-rose,代码行数:101,代码来源:sourceLocationInheritedAttribute.C

示例2: isSgStatement

void
FunctionCallNormalization::visit( SgNode *astNode )
   {
     SgStatement *stm = isSgStatement( astNode );

     // visiting all statements which may contain function calls;
     // Note 1: we do not look at the body of loops, or sequences of statements, but only
     // at statements which may contain directly function calls; all other statements will have their component parts visited in turn
     if ( isSgEnumDeclaration( astNode ) || isSgVariableDeclaration( astNode ) || isSgVariableDefinition( astNode ) ||
                               isSgExprStatement( astNode ) || isSgForStatement( astNode ) || isSgReturnStmt( astNode ) ||
                               isSgSwitchStatement( astNode ) )
        {
       // maintain the mappings from function calls to expressions (variables or dereferenced variables)
          map<SgFunctionCallExp *, SgExpression *> fct2Var;

       // list of Declaration structures, one structure per function call
          DeclarationPtrList declarations;
          bool variablesDefined = false;
             
       // list of function calls, in correnspondence with the inForTest list below
          list<SgNode*> functionCallExpList;
          list<bool> inForTest;

          SgForStatement *forStm = isSgForStatement( stm );
          SgSwitchStatement *swStm = isSgSwitchStatement( stm );
          list<SgNode*> temp1, temp2;

       // for-loops and Switch statements have conditions ( and increment ) expressed as expressions
       // and not as standalone statements; this will change in future Sage versions
       // TODO: when for-loops and switch statements have conditions expressed via SgStatements
       // these cases won't be treated separately; however, do-while will have condition expressed via expression
       // so that will be the only exceptional case to be treated separately
          if (forStm != NULL)
             {
            // create a list of function calls in the condition and increment expression
            // the order is important, the condition is evaluated after the increment expression
            // temp1 = FEOQueryForNodes( forStm->get_increment_expr_root(), V_SgFunctionCallExp );
            // temp2 = FEOQueryForNodes( forStm->get_test_expr_root(), V_SgFunctionCallExp );
               temp1 = FEOQueryForNodes( forStm->get_increment(), V_SgFunctionCallExp );
               temp2 = FEOQueryForNodes( forStm->get_test_expr(), V_SgFunctionCallExp );
               functionCallExpList = temp1;
               functionCallExpList.splice( functionCallExpList.end(), temp2 );
             }
            else
             {
               if (swStm != NULL)
                  {
                 // create a list of function calls in the condition in the order of function evaluation
                 // DQ (11/23/2005): Fixed SgSwitchStmt to have SgStatement for conditional.
                 // list<SgNode*> temp1 = FEOQueryForNodes( swStm->get_item_selector_root(), V_SgFunctionCallExp );
                    list<SgNode*> temp1 = FEOQueryForNodes( swStm->get_item_selector(), V_SgFunctionCallExp );
                    functionCallExpList = temp1;
                  }
                 else
                  {
                 // create a list of function calls in the statement in the order of function evaluation
                    functionCallExpList = FEOQueryForNodes( stm, V_SgFunctionCallExp );
                  }
             }

         // all function calls get replaced: this is because they can occur in expressions (e.g. for-loops)
         // which makes it difficult to build control flow graphs
         if ( functionCallExpList.size() > 0 )
           {
             cout << "--------------------------------------\nStatement ";
             cout << stm->unparseToString() << "\n";;
             
             // traverse the list of function calls in the current statement, generate a structure  Declaration for each call
             // put these structures in a list to be inserted in the code later
             for ( list<SgNode *>::iterator i = functionCallExpList.begin(); i != functionCallExpList.end(); i++ )
               {
                 variablesDefined = true;

                 // get function call exp
                 SgFunctionCallExp *exp = isSgFunctionCallExp( *i );
                 ROSE_ASSERT ( exp );
                 
                 // get type of expression, generate unique variable name
                 SgType *expType = exp->get_type();
                 ROSE_ASSERT ( expType );
                 Sg_File_Info *location = Sg_File_Info::generateDefaultFileInfoForTransformationNode();
                 ROSE_ASSERT ( location );
                 ostringstream os;
                 os << "__tempVar__" << location;
                 SgName name = os.str().c_str();

                 // replace previous variable bindings in the AST
                 SgExprListExp *paramsList = exp->get_args();
                 SgExpression *function = exp->get_function();
                 ROSE_ASSERT ( paramsList && function );
                 replaceFunctionCallsInExpression( paramsList, fct2Var );
                 replaceFunctionCallsInExpression( function, fct2Var );

                 // duplicate function call expression, for the initialization declaration and the assignment
                 SgTreeCopy treeCopy;
                 SgFunctionCallExp *newExpInit = isSgFunctionCallExp( exp->copy( treeCopy ) );
                 ROSE_ASSERT ( newExpInit );
                 SgFunctionCallExp *newExpAssign = isSgFunctionCallExp( exp->copy( treeCopy ) );
                 ROSE_ASSERT ( newExpAssign );

//.........这里部分代码省略.........
开发者ID:Federico2014,项目名称:edg4x-rose,代码行数:101,代码来源:FunctionNormalization.C

示例3: getForloopTest

/*
 * returns test condition of for loop
 */
string MigrationOutliner::getForloopTest(SgForStatement *forstmt){
        SgStatement* testcondition = forstmt->get_test();
        return testcondition->unparseToString();
}//end getFunctionName
开发者ID:ssrg-vt,项目名称:aira,代码行数:7,代码来源:migration_outliner.cpp


注:本文中的SgStatement::unparseToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。