/** ** \file callgraph/call-graph-visitor.cc ** \brief Implementation of callgraph::CallGraphVisitor. **/ #include #include #include namespace callgraph { const CallGraph* CallGraphVisitor::create(const ast::Ast& tree) { // Create a new empty callgraph callgraph_ = new CallGraph(); // Launch visitor. tree.accept(*this); // Return created callgraph. return callgraph_; } CallGraph* CallGraphVisitor::create(ast::Ast& tree) { return const_cast(create(const_cast(tree))); } /*-----------. | Visiting. | `-----------*/ void CallGraphVisitor::operator()(const ast::CallExp& e) { // FIXME: Some code was deleted here (Link the Caller with the CallExp's declaration). } void CallGraphVisitor::operator()(const ast::FunctionChunk& e) { // First define the nodes for each defined function. for (ast::FunctionDec* f : e) callgraph_->fundec_add(f); // Now bind callers and callees. super_type::operator()(e); } void CallGraphVisitor::operator()(const ast::FunctionDec& e) { // Current function becomes temporarily the caller function. ast::FunctionDec* save = caller; caller = const_cast(&e); super_type::operator()(e); caller = save; } } // namespace callgraph