/** * @brief Performs the removal of code in the given function. */ void UnreachableCodeInCFGRemover::performRemovalInFunc(ShPtr<Function> func) { cfg = cfgBuilder->getCFG(func); ShPtr<Statement> body(func->getBody()); if (!skipEmptyStmts(body)) { // The body is empty. return; } visitStmt(body); }
/** * @brief Adds a statement to the current node, visits its successors, and adds * a forward or backward edge from the current node to the * successor/parent of @a stmt. * * Empty statements are skipped (i.e. not added to <tt>cfg->stmtNodeMapping</tt> * and <tt>currNode->stmts</tt>). */ void RecursiveCFGBuilder::addStatement(ShPtr<Statement> stmt) { if (!isa<EmptyStmt>(stmt)) { cfg->stmtNodeMapping[stmt] = currNode; currNode->stmts.push_back(stmt); } if (ShPtr<Statement> stmtSucc = stmt->getSuccessor()) { visitStmt(stmtSucc); return; } addForwardOrBackwardEdge(stmt); }
/** * @brief Adds a (either new or existing) node starting with @a stmt into the * CFG and returns it. * * @par Preconditions * - @a stmt is non-null */ ShPtr<CFG::Node> RecursiveCFGBuilder::addNode(ShPtr<Statement> stmt) { PRECONDITION_NON_NULL(stmt); // Does a node corresponding to stmt already exist? auto stmtNodeIter = firstStmtNodeMapping.find(stmt); if (stmtNodeIter != firstStmtNodeMapping.end()) { return stmtNodeIter->second; } // Add a new node. ShPtr<CFG::Node> nodeToAdd = currNode = ShPtr<CFG::Node>(new CFG::Node()); firstStmtNodeMapping[stmt] = currNode; visitStmt(stmt); cfg->addNode(nodeToAdd); return nodeToAdd; }
virtual void visit(AstUCStmt* nodep, AstNUser*) { needNonStaticFunc(nodep); visitStmt(nodep); }
virtual void visit(AstNodeStmt* nodep, AstNUser*) { visitStmt(nodep); }
void GotoTargetAnalysis::visit(ShPtr<GotoStmt> stmt) { // Do not visit the goto's target, just its successor (if any). visitStmt(stmt->getSuccessor()); }
virtual void visit(AstNodeStmt* nodep) { visitStmt(nodep); }