コード例 #1
0
ファイル: defaultCase.C プロジェクト: 8l/rose
void
CompassAnalyses::DefaultCase::Traversal::
visit(SgNode* node)
   {
     
        SgSwitchStatement* theSwitch = isSgSwitchStatement(node);
        if (!theSwitch) return;
        bool has_default = false;
        if (isSgBasicBlock(theSwitch->get_body())) {
          SgBasicBlock* BBlock = isSgBasicBlock(theSwitch->get_body());
          //I should maybe do more sanity checking for nulls here
          SgStatementPtrList BBlockStmts = BBlock->get_statements();
          for (Rose_STL_Container<SgStatement*>::iterator j = BBlockStmts.begin(); j != BBlockStmts.end(); j++)
            {
              if (isSgDefaultOptionStmt(*j)){
                has_default = true;
                break;
              }
            }
        } else {
          if (isSgDefaultOptionStmt(theSwitch->get_body())) {
            has_default = true;
          }
        }
        if (!has_default){
          output->addOutput(new CheckerOutput(node));
        }
  // Implement your traversal here.  

   } //End of the visit function.
コード例 #2
0
void visitorTraversal::visit(SgNode* n)
   {
     SgSwitchStatement* switchStatement = isSgSwitchStatement(n);
     if (switchStatement != NULL)
        {
          SgStatementPtrList & cases = SageInterface::ensureBasicBlockAsBodyOfSwitch(switchStatement)->get_statements();
          bool switchHasDefault = false;

       // The default statement could be at any position in the list of cases.
          SgStatementPtrList::iterator i = cases.begin();
          while (i != cases.end())
             {
               SgDefaultOptionStmt* defaultCase = isSgDefaultOptionStmt(*i);
               if (defaultCase != NULL)
                  switchHasDefault = true;
               i++;
             }

          if (switchHasDefault == false)
             {
               printf ("Error (source code locations of switch without default case): \n");
               switchStatement->get_startOfConstruct()->display("Error: switch without default case");
             }
        }
   }
コード例 #3
0
ファイル: discardAssignment.C プロジェクト: 8l/rose
void
CompassAnalyses::DiscardAssignment::Traversal::
visit(SgNode* node)
   { 
     if (isSgAssignOp(node))
     {
       // simple case: the parent of a "real" assignment op must be an
       // expression statement
       if (!isSgExprStatement(node->get_parent()))
       {
         output->addOutput(new CheckerOutput(node));
       }
       else
       {
         // not so simple case: the parent is an expression statement, but if
         // that statement is an if/loop condition, we still want to complain
         SgNode *assignment = node->get_parent();
         SgNode *p = assignment->get_parent();
         SgDoWhileStmt *dws;
         SgForStatement *fs;
         SgIfStmt *is;
         SgSwitchStatement *ss;
         SgWhileStmt *ws;

         if ((dws = isSgDoWhileStmt(p)) && dws->get_condition() == assignment)
         {
           output->addOutput(new CheckerOutput(node));
         }
         else if ((fs = isSgForStatement(p)) && fs->get_test() == assignment)
         {
           output->addOutput(new CheckerOutput(node));
         }
         else if ((is = isSgIfStmt(p)) && is->get_conditional() == assignment)
         {
           output->addOutput(new CheckerOutput(node));
         }
         else if ((ss = isSgSwitchStatement(p)) && ss->get_item_selector() == assignment)
         {
           output->addOutput(new CheckerOutput(node));
         }
         else if ((ws = isSgWhileStmt(p)) && ws->get_condition() == assignment)
         {
           output->addOutput(new CheckerOutput(node));
         }
       }
     }
     else if (SgMemberFunctionRefExp *mf = isSgMemberFunctionRefExp(node))
     {
       // not so simple case: call to operator= member function that is not an
       // expression statement by itself
       SgFunctionCallExp *call = isSgFunctionCallExp(mf->get_parent()->get_parent());
       if (call && !isSgExprStatement(call->get_parent())
        && mf->get_parent() == call->get_function()
        && std::strcmp(mf->get_symbol()->get_name().str(), "operator=") == 0)
       {
         output->addOutput(new CheckerOutput(call));
       }
     }
   } //End of the visit function.
コード例 #4
0
    /** Makes a CFG edge, adding appropriate labels. */
    void makeEdge(SgAsmInstruction* from, SgAsmInstruction* to, const AuxiliaryInformation* info, vector<CFGEdge>& result) {
#if 0
        SgAsmNode* fromNode = from.getNode();
        unsigned int fromIndex = from.getIndex();
        SgAsmNode* toNode = to.getNode();
        unsigned int toIndex = to.getIndex();
#if 0
        // Exit early if the edge should not exist because of a control flow discontinuity
        if (fromIndex == 1 && (isSgGotoStatement(fromNode) || isSgBreakStmt(fromNode) || isSgContinueStmt(fromNode))) {
            return;
        }
        if (isSgReturnStmt(fromNode) && toNode == fromNode->get_parent()) {
            SgReturnStmt* rs = isSgReturnStmt(fromNode);
            if (fromIndex == 1 || fromIndex == 0 && !rs->get_expression()) return;
        }
        if (fromIndex == 1 && isSgSwitchStatement(fromNode) &&
            isSgSwitchStatement(fromNode)->get_body() == toNode) return;
#endif
#endif
        // Create the edge
        result.push_back(CFGEdge(CFGNode(from, info), CFGNode(to, info), info));
    }
コード例 #5
0
ファイル: HtSageUtils.cpp プロジェクト: CarlEbeling/OpenHT
SgStatement *findSafeInsertPoint(SgNode *node) {
    SgStatement *insertPoint = SageInterface::getEnclosingStatement(node);
    SgStatement *es = isSgExprStatement(insertPoint);
    SgStatement *esParent = es ? isSgStatement(es->get_parent()) : 0;
    if (es && (isSgSwitchStatement(esParent) || isSgIfStmt(esParent))) {
      // Make sure insertion point is outside of the condition of an if-stmt
      // or the selector of a switch-stmt.
      insertPoint = esParent; 
    } else {
      if (esParent) {
        assert(isSgBasicBlock(esParent));
      }
    }
    return insertPoint;
}
コード例 #6
0
  foreach (SgBasicBlock *caseBody, newBlocks) {
    SgStatementPtrList &stmts = caseBody->get_statements();
    SgStatement *lastStmt = 0;
    if (!stmts.empty()) {
#if 0
      lastStmt = stmts.back();
#else
      // Skip NullStatements.
      for (int idx = stmts.size() - 1; idx >= 0; idx--) {
        if (!isSgNullStatement(stmts[idx])) {
          lastStmt = stmts[idx];
          break;
        }
      }
#endif
    }

    // Insert HtContinue for a fall-through.
    bool fallsThrough = (lastStmt == 0 || !isSgGotoStatement(lastStmt));
    if (fallsThrough) {
      if (!isSgSwitchStatement(lastStmt) && !isHtThreadControlStmt(lastStmt)) {
        int target = (casenum == newBlocks.size()) ? -1 : casenum + 1;
        callStmt = SageBuilder::buildFunctionCallStmt(
            "HtContinue", SageBuilder::buildVoidType(),
            SageBuilder::buildExprListExp(SageBuilder::buildEnumVal_nfi(target,
            enumDecl, stateToName[target])), funcBody);
        SageInterface::appendStatement(callStmt, caseBody);
      }
      SgStatement *brkStmt = SageBuilder::buildBreakStmt();
      SageInterface::appendStatement(brkStmt, caseBody);
    }

    // Insert HtContinue for each explicit goto.
    std::vector<SgGotoStatement *> gotos = 
        SageInterface::querySubTree<SgGotoStatement>(caseBody,
        V_SgGotoStatement); 
    foreach (SgGotoStatement *ngoto, gotos) {
      int target = labelToState[ngoto->get_label()];
      callStmt = SageBuilder::buildFunctionCallStmt(
          "HtContinue", SageBuilder::buildVoidType(),
          SageBuilder::buildExprListExp(SageBuilder::buildEnumVal_nfi(target,
          enumDecl, stateToName[target])), funcBody);
      SgStatement *brkStmt = SageBuilder::buildBreakStmt();
      SageInterface::insertStatementBefore(ngoto, callStmt);
      SageInterface::replaceStatement(ngoto, brkStmt, true);
    }
コード例 #7
0
void
SgSwitchStatement::fixupCopy_symbols(SgNode* copy, SgCopyHelp & help) const
   {
#if DEBUG_FIXUP_COPY
     printf ("Inside of SgSwitchStatement::fixupCopy_symbols() this = %p = %s  copy = %p \n",this,this->class_name().c_str(),copy);
#endif

     SgScopeStatement::fixupCopy_symbols(copy,help);

     SgSwitchStatement* switchStatement_copy = isSgSwitchStatement(copy);
     ROSE_ASSERT(switchStatement_copy != NULL);

     ROSE_ASSERT(this->get_item_selector() != NULL);
     this->get_item_selector()->fixupCopy_symbols(switchStatement_copy->get_item_selector(),help);

     ROSE_ASSERT(this->get_body() != NULL);
     this->get_body()->fixupCopy_symbols(switchStatement_copy->get_body(),help);
   }
コード例 #8
0
    EdgeConditionKind CFGEdge::condition() const {
#if 0
        SgAsmNode* srcNode = src.getNode();
        unsigned int srcIndex = src.getIndex();
        SgAsmNode* tgtNode = tgt.getNode();
        unsigned int tgtIndex = tgt.getIndex();
        if (isSgAsmMov(srcNode) ) {
            SgAsmMov* ifs = isSgAsmMov(srcNode);
#if 0
            if (ifs->get_true_body() == tgtNode) {
                return eckTrue;
            } else if (ifs->get_false_body() == tgtNode) {
                return eckFalse;
            } else ROSE_ASSERT (!"Bad successor in if statement");
#endif
        }
#if 0
        else if (isSgWhileStmt(srcNode) && srcIndex == 1) {
            if (srcNode == tgtNode) {
                // False case for while test
                return eckFalse;
            } else {
                return eckTrue;
            }
        } else if (isSgDoWhileStmt(srcNode) && srcIndex == 2) {
            // tgtIndex values are 0 for true branch and 3 for false branch
            if (tgtIndex == 0) {
                return eckTrue;
            } else {
                return eckFalse;
            }
        } else if (isSgForStatement(srcNode) && srcIndex == 2) {
            if (srcNode == tgtNode) {
                // False case for test
                return eckFalse;
            } else {
                return eckTrue;
            }
        } else if (isSgSwitchStatement(srcNode) && isSgCaseOptionStmt(tgtNode)) {
            return eckCaseLabel;
        } else if (isSgSwitchStatement(srcNode) && isSgDefaultOptionStmt(tgtNode)){
            return eckDefault;
        } else if (isSgConditionalExp(srcNode) && srcIndex == 1) {
            SgConditionalExp* ce = isSgConditionalExp(srcNode);
            if (ce->get_true_exp() == tgtNode) {
                return eckTrue;
            } else if (ce->get_false_exp() == tgtNode) {
                return eckFalse;
            } else ROSE_ASSERT (!"Bad successor in conditional expression");
        } else if (isSgAndOp(srcNode) && srcIndex == 1) {
            if (srcNode == tgtNode) {
                // Short-circuited false case
                return eckFalse;
            } else {
                return eckTrue;
            }
        } else if (isSgOrOp(srcNode) && srcIndex == 1) {
            if (srcNode == tgtNode) {
                // Short-circuited true case
                return eckTrue;
            } else {
                return eckFalse;
            }
        } 
#endif
        else {
            // No key
            return eckUnconditional;
        }
#else
    // DQ (11/28/2009): This function was already commented out, but must return a value for use in MSVC.
       return eckFalse;
#endif
    }