NEURON
function_callpath_visitor.cpp
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2024 Blue Brain Project, EPFL.
4  * See the top-level LICENSE file for details.
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
10 
11 namespace nmodl {
12 namespace visitor {
13 
14 using symtab::Symbol;
16 
18  if (visited_functions_or_procedures.empty()) {
19  return;
20  }
21  /// If node is either a RANGE var, a POINTER or a BBCOREPOINTER then
22  /// the FUNCTION or PROCEDURE it's used in should have the `use_range_ptr_var`
23  /// property
24  auto sym = psymtab->lookup(node.get_node_name());
25  const auto properties = NmodlType::range_var | NmodlType::pointer_var |
26  NmodlType::bbcore_pointer_var;
27  if (sym && sym->has_any_property(properties)) {
28  const auto top = visited_functions_or_procedures.back();
29  const auto caller_func_name =
30  top->is_function_block()
31  ? dynamic_cast<const ast::FunctionBlock*>(top)->get_node_name()
32  : dynamic_cast<const ast::ProcedureBlock*>(top)->get_node_name();
33  auto caller_func_proc_sym = psymtab->lookup(caller_func_name);
34  caller_func_proc_sym->add_properties(NmodlType::use_range_ptr_var);
35  }
36 }
37 
39  if (visited_functions_or_procedures.empty()) {
40  return;
41  }
42  const auto name = node.get_node_name();
43  const auto func_symbol = psymtab->lookup(name);
44  if (!func_symbol ||
45  !func_symbol->has_any_property(NmodlType::function_block | NmodlType::procedure_block) ||
46  func_symbol->get_nodes().empty()) {
47  return;
48  }
49  /// Visit the called FUNCTION/PROCEDURE AST node to check whether
50  /// it has `use_range_ptr_var` property. If it does the currently called
51  /// function needs to have it too.
52  const auto func_block = func_symbol->get_nodes()[0];
53  func_block->accept(*this);
54  if (func_symbol->has_any_property(NmodlType::use_range_ptr_var)) {
55  const auto top = visited_functions_or_procedures.back();
56  auto caller_func_name =
57  top->is_function_block()
58  ? dynamic_cast<const ast::FunctionBlock*>(top)->get_node_name()
59  : dynamic_cast<const ast::ProcedureBlock*>(top)->get_node_name();
60  auto caller_func_proc_sym = psymtab->lookup(caller_func_name);
61  caller_func_proc_sym->add_properties(NmodlType::use_range_ptr_var);
62  }
63 }
64 
66  /// Avoid recursive calls
70  return;
71  }
73  node.visit_children(*this);
75 }
76 
78  // Avoid recursive calls
82  return;
83  }
85  node.visit_children(*this);
87 }
88 
90  psymtab = node.get_symbol_table();
91  node.visit_children(*this);
92 }
93 
94 } // namespace visitor
95 } // namespace nmodl
Represents top level AST node for whole NMODL input.
Definition: program.hpp:39
Represents a variable.
Definition: var_name.hpp:43
std::shared_ptr< Symbol > lookup(const std::string &name) const
check if symbol with given name exist in the current table (but not in parents)
void visit_function_call(const ast::FunctionCall &node) override
visit node of type ast::FunctionCall
void visit_procedure_block(const ast::ProcedureBlock &node) override
visit node of type ast::ProcedureBlock
std::vector< const ast::Block * > visited_functions_or_procedures
Vector of currently visited functions or procedures (used as a searchable stack)
void visit_var_name(const ast::VarName &node) override
visit node of type ast::VarName
void visit_program(const ast::Program &node) override
visit node of type ast::Program
symtab::SymbolTable * psymtab
symbol table for the program
void visit_function_block(const ast::FunctionBlock &node) override
visit node of type ast::FunctionBlock
Visitor for traversing FunctionBlock s and ProcedureBlocks through their FunctionCall s
const char * name
Definition: init.cpp:16
char Symbol
Definition: nrnconf.h:25
NmodlType
NMODL variable properties.
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
static Node * node(Object *)
Definition: netcvode.cpp:291
int find(const int, const int, const int, const int, const int)