NEURON
global_to_range.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Blue Brain Project, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include <catch2/catch_test_macros.hpp>
9 
10 #include "ast/program.hpp"
11 #include "parser/nmodl_driver.hpp"
17 
18 using namespace nmodl;
19 using namespace visitor;
20 using namespace test_utils;
21 
24 
25 //=============================================================================
26 // GlobalToRange visitor tests
27 //=============================================================================
28 
29 std::shared_ptr<ast::Program> run_global_to_var_visitor(const std::string& text) {
31  auto ast = driver.parse_string(text);
32 
34  PerfVisitor().visit_program(*ast);
37  return ast;
38 }
39 
40 SCENARIO("GLOBAL to RANGE variable transformer", "[visitor][globaltorange]") {
41  GIVEN("mod file with GLOBAL variables that are written") {
42  std::string input_nmodl = R"(
43  NEURON {
44  SUFFIX test
45  RANGE a, b
46  GLOBAL x, y
47  }
48  ASSIGNED {
49  x
50  }
51  BREAKPOINT {
52  x = y
53  }
54  )";
55  auto ast = run_global_to_var_visitor(input_nmodl);
56  auto symtab = ast->get_symbol_table();
57  THEN("GLOBAL variables that are written are turned to RANGE") {
58  /// check for all RANGE variables : old ones + newly converted ones
59  auto vars = symtab->get_variables_with_properties(NmodlType::range_var);
60  REQUIRE(vars.size() == 3);
61 
62  /// x should be converted from GLOBAL to RANGE
63  auto x = symtab->lookup("x");
64  REQUIRE(x != nullptr);
65  REQUIRE(x->has_any_property(NmodlType::range_var) == true);
66  REQUIRE(x->has_any_property(NmodlType::global_var) == false);
67  }
68  THEN("GLOBAL variables that are read only remain GLOBAL") {
69  auto vars = symtab->get_variables_with_properties(NmodlType::global_var);
70  REQUIRE(vars.size() == 1);
71  REQUIRE(vars[0]->get_name() == "y");
72  }
73  }
74 }
Class that binds all pieces together for parsing nmodl file.
void visit_program(ast::Program &node) override
visit node of type ast::Program
Visitor to convert GLOBAL variables to RANGE variables.
Visitor for measuring performance related information
void visit_program(const ast::Program &node) override
visit node of type ast::Program
Concrete visitor for constructing symbol table from AST.
void visit_program(ast::Program &node) override
visit node of type ast::Program
SCENARIO("GLOBAL to RANGE variable transformer", "[visitor][globaltorange]")
std::shared_ptr< ast::Program > run_global_to_var_visitor(const std::string &text)
Visitor to convert GLOBAL variables to RANGE variables.
bool parse_string(const std::string &input)
parser Units provided as string (used for testing)
Definition: unit_driver.cpp:40
auto get_name(Tag const &tag, int field_index)
Get the nicest available name for the field_index-th instance of Tag.
NmodlType
NMODL variable properties.
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
Visitor for measuring performance related information
#define text
Definition: plot.cpp:60
Auto generated AST classes declaration.
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::parser::UnitDriver driver
Definition: parser.cpp:28