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


C++ SgScopeStatement::prepend_statement方法代码示例

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


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

示例1: instr

  void instr(SgGlobal* global) {

    // Create the lock and key variables in global scope.
    // In main:
    // EnterScope();
    // lock = getTopLock();
    // key = getTopKey();
    // .... rest of main
    // ExitScope();
    // return;
    // FIXME: Add case where we handle arbitrary exits from main
    // This can be handled similar to the way returns are handled
    // for basic blocks.

    SgScopeStatement* scope = isSgScopeStatement(global);

    // Insert lock and key variables at the top of the global scope
    // lock variable
    std::cout << "VarCounter: " << Util::VarCounter << std::endl;
    SgName lock_name("lock_var" + boost::lexical_cast<std::string>(Util::VarCounter));
    SgVariableDeclaration* lock_var = Util::createLocalVariable(lock_name, getLockType(), NULL, scope);
    // Add declaration at the top of the scope
    scope->prepend_statement(lock_var);

    // key variable
    // **** IMPORTANT: Using same counter value for lock and key
    SgName key_name("key_var" + boost::lexical_cast<std::string>(Util::VarCounter));
    Util::VarCounter++;
    SgVariableDeclaration* key_var = Util::createLocalVariable(key_name, getKeyType(), NULL, scope);
    // Insert this key decl after the lock decl
    SI::insertStatementAfter(lock_var, key_var);


    // Now, find the main function and insert...
    // EnterScope();
    // lock = getTopLock();
    // key = getTopKey();
    // .... rest of main
    // ExitScope()
    // return; -- this already exists...
    // see FIXME above

    // find main function...
    SgFunctionDeclaration* MainFn = SI::findMain(global);
    if(!MainFn) {
#ifdef HANDLE_GLOBAL_SCOPE_DEBUG
      printf("Can't find Main function. Not inserting Global Enter and Exit Scopes\n");
#endif
      return;
    }

    SgBasicBlock *bb = Util::getBBForFn(MainFn);

    // insert EnterScope()
#if 0
    SgExpression* overload = buildOverloadFn("EnterScope", NULL, NULL, SgTypeVoid::createType(), scope,
        GEFD(bb));
#endif
    SgExpression* overload = buildMultArgOverloadFn("EnterScope", SB::buildExprListExp(), SgTypeVoid::createType(), scope,
        GEFD(bb));

    SgStatement* enter_scope = SB::buildExprStatement(overload);
    Util::insertAtTopOfBB(bb, enter_scope);

    // insert lock = getTopLock();
    //overload = buildOverloadFn("getTopLock", NULL, NULL, getLockType(), scope, GEFD(bb));
    overload = buildMultArgOverloadFn("getTopLock", SB::buildExprListExp(), getLockType(), scope, GEFD(bb));
    //SgStatement* lock_assign = SB::buildExprStatement(SB::buildAssignOp(SB::buildVarRefExp(lock_var), overload));
    //SI::insertStatementAfter(enter_scope, lock_assign); //RMM COMMENTED OUT

    // insert key = getTopKey();
    // overload = buildOverloadFn("getTopKey", NULL, NULL, getKeyType(), scope, GEFD(bb));
    overload = buildMultArgOverloadFn("getTopKey", SB::buildExprListExp(), getKeyType(), scope, GEFD(bb));
    //SgStatement* key_assign = SB::buildExprStatement(SB::buildAssignOp(SB::buildVarRefExp(key_var), overload));
    //SI::insertStatementAfter(lock_assign, key_assign); //RMM COMMENTED OUT

    // add to scope -> lock and key map... SLKM
    LockKeyPair lock_key = std::make_pair(lock_var, key_var);
    scopeLockMap[scope] = lock_key;

    ROSE_ASSERT(existsInSLKM(scope));

    // Insert ExitScope if last stmt is not return.
    SgStatementPtrList& stmts = bb->get_statements();
    SgStatementPtrList::iterator it = stmts.begin();
    it += (stmts.size() - 1);

    // A little iffy on the scope part here... lets check that.
    if(!isSgReturnStmt(*it)) {
      // Last statement is not return. So, add exit scope...
      // If its a break/continue statement, insert statement before,
      // otherwise, add exit_scope afterwards.
      //SgExpression* overload = buildOverloadFn("ExitScope", NULL, NULL, SgTypeVoid::createType(), scope, GEFD(bb));
      SgExpression* overload = buildMultArgOverloadFn("ExitScope", SB::buildExprListExp(), SgTypeVoid::createType(), scope, GEFD(bb));

      // check if its break/continue
      if(isSgBreakStmt(*it) || isSgContinueStmt(*it)) {
        SI::insertStatementBefore(*it, SB::buildExprStatement(overload));
      }
      else {
//.........这里部分代码省略.........
开发者ID:matzke1,项目名称:rose-develop,代码行数:101,代码来源:instrScopeStmts.C


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