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.
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"); } } }
void SgDefaultOptionStmt::fixupCopy_symbols(SgNode* copy, SgCopyHelp & help) const { #if DEBUG_FIXUP_COPY printf ("Inside of SgDefaultOptionStmt::fixupCopy_symbols() this = %p = %s copy = %p \n",this,this->class_name().c_str(),copy); #endif SgStatement::fixupCopy_symbols(copy,help); SgDefaultOptionStmt* defaultOptionStatement_copy = isSgDefaultOptionStmt(copy); ROSE_ASSERT(defaultOptionStatement_copy != NULL); ROSE_ASSERT(this->get_body() != NULL); this->get_body()->fixupCopy_symbols(defaultOptionStatement_copy->get_body(),help); }
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 }