diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
| commit | 967be9e750221ab2ab783f95df79bb26d290a45e (patch) | |
| tree | 6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/src/callgraph/parent-graph-visitor.cc | |
Diffstat (limited to 'tiger-compiler/src/callgraph/parent-graph-visitor.cc')
| -rw-r--r-- | tiger-compiler/src/callgraph/parent-graph-visitor.cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tiger-compiler/src/callgraph/parent-graph-visitor.cc b/tiger-compiler/src/callgraph/parent-graph-visitor.cc new file mode 100644 index 0000000..f99121d --- /dev/null +++ b/tiger-compiler/src/callgraph/parent-graph-visitor.cc @@ -0,0 +1,42 @@ +/** + ** \file callgraph/parent-graph-visitor.cc + ** \brief Implementation for callgraph::ParentGraphVisitor. + **/ + +#include <ast/function-dec.hh> +#include <callgraph/parent-graph-visitor.hh> + +namespace callgraph +{ + ParentGraph* ParentGraphVisitor::create(ast::Ast& tree) + { + // Create a new empty parentgraph + parentgraph = new ParentGraph(); + + // Launch visitor. + tree.accept(*this); + + // Return created parentgraph. + return parentgraph; + } + + void ParentGraphVisitor::operator()(ast::FunctionChunk& e) + { + for (ast::FunctionDec* f : e) + { + parentgraph->fundec_add(f); + parentgraph->fundec_link(f, parent); + } + super_type::operator()(e); + } + + void ParentGraphVisitor::operator()(ast::FunctionDec& e) + { + // Current function becomes temporarily the parent function. + ast::FunctionDec* tmp = parent; + parent = &e; + super_type::operator()(e); + parent = tmp; + } + +} // namespace callgraph |
