NEURON
external.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2024 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"
12 #include "parser/nmodl_driver.hpp"
13 #include "utils/test_utils.hpp"
15 
16 using namespace nmodl;
17 using namespace visitor;
18 using namespace test_utils;
19 
20 using ast::AstNodeType;
24 
25 CodegenInfo compute_code_info(const std::string& text) {
27  const auto& ast = driver.parse_string(text);
28 
29  /// construct symbol table and run codegen helper visitor
32 
33  /// symbols/variables are collected in info object
34  return v.analyze(*ast);
35 }
36 
37 
38 TEST_CASE("EXTERNAL variables") {
39  std::string mod = R"(
40 NEURON {
41  EXTERNAL gbl_foo, param_bar
42 }
43 
44 ASSIGNED {
45  foo
46  gbl_foo
47  param_bar
48 }
49 )";
50 
51  auto info = compute_code_info(mod);
52 
53  std::vector<std::string> actual;
54  for (const auto& var: info.external_variables) {
55  actual.push_back(var->get_name());
56  }
57  std::sort(actual.begin(), actual.end());
58 
59  std::vector<std::string> expected{"gbl_foo", "param_bar"};
60 
61  REQUIRE(actual == expected);
62 }
Helper visitor to gather AST information to help code generation.
Class that binds all pieces together for parsing nmodl file.
Concrete visitor for constructing symbol table from AST.
void visit_program(ast::Program &node) override
visit node of type ast::Program
Helper visitor to gather AST information to help code generation.
#define v
Definition: md1redef.h:11
TEST_CASE("EXTERNAL variables")
Definition: external.cpp:38
CodegenInfo compute_code_info(const std::string &text)
Definition: external.cpp:25
AstNodeType
Enum type for every AST node type.
Definition: ast_decl.hpp:166
bool parse_string(const std::string &input)
parser Units provided as string (used for testing)
Definition: unit_driver.cpp:40
double var(InputIterator begin, InputIterator end)
Definition: ivocvect.h:108
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
static List * info
#define text
Definition: plot.cpp:60
Auto generated AST classes declaration.
Represent information collected from AST for code generation.
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::parser::UnitDriver driver
Definition: parser.cpp:28