10 #include <unordered_set>
25 std::unordered_set<ast::GlobalVar*> global_variables_to_remove;
26 std::unordered_set<ast::Statement*> global_statements_to_remove;
28 auto const& statement_block =
node.get_statement_block();
29 auto& statements = (*statement_block).get_statements();
32 for (
auto& statement: statements) {
34 if (statement->is_global()) {
35 const auto& global_variables =
36 std::static_pointer_cast<ast::Global>(statement)->
get_variables();
37 global_variables_to_remove.clear();
38 for (
auto& global_variable: global_variables) {
39 auto variable_name = global_variable->get_node_name();
41 if (symbol_table->lookup(variable_name)->get_write_count() > 0) {
42 range_variables.emplace_back(
new ast::RangeVar(global_variable->get_name()));
43 global_variables_to_remove.emplace(global_variable.get());
48 std::static_pointer_cast<ast::Global>(statement)->erase_global_var(
49 global_variables_to_remove);
52 if (global_variables.empty()) {
53 global_statements_to_remove.emplace(statement.get());
59 statement_block->erase_statement(global_statements_to_remove);
62 if (!range_variables.empty()) {
63 auto range_statement =
new ast::Range(range_variables);
64 statement_block->emplace_back_statement(range_statement);
Represent NEURON block in the mod file.
symtab::SymbolTable * get_symbol_table() const override
Return associated symbol table for the current ast node.
Represents RANGE variables statement in NMODL.
std::vector< std::shared_ptr< Symbol > > get_variables(syminfo::NmodlType with=syminfo::NmodlType::empty, syminfo::NmodlType without=syminfo::NmodlType::empty) const
get variables
const ast::Program & ast
ast::Ast* node
void visit_neuron_block(ast::NeuronBlock &node) override
Visit ast::NeuronBlock nodes to check if there is any GLOBAL variables defined in them that are writt...
Auto generated AST classes declaration.
Visitor to convert GLOBAL variables to RANGE variables.
std::vector< std::shared_ptr< RangeVar > > RangeVarVector
encapsulates code generation backend implementations
Auto generated AST classes declaration.
static Node * node(Object *)
Auto generated AST classes declaration.
Auto generated AST classes declaration.
Auto generated AST classes declaration.
Utility functions for visitors implementation.