User Guide
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"
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
30  SymtabVisitor().visit_program(*ast);
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 }
test_utils.hpp
nmodl::parser::NmodlDriver
Class that binds all pieces together for parsing nmodl file.
Definition: nmodl_driver.hpp:67
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::codegen::CodegenInfo
Represent information collected from AST for code generation.
Definition: codegen_info.hpp:335
codegen_helper_visitor.hpp
Helper visitor to gather AST information to help code generation.
nmodl::ast::AstNodeType
AstNodeType
Enum type for every AST node type.
Definition: ast_decl.hpp:166
TEST_CASE
TEST_CASE("EXTERNAL variables")
Definition: external.cpp:38
program.hpp
Auto generated AST classes declaration.
driver
nmodl::parser::UnitDriver driver
Definition: parser.cpp:28
nmodl::parser::UnitDriver::parse_string
bool parse_string(const std::string &input)
parser Units provided as string (used for testing)
Definition: unit_driver.cpp:40
nmodl::codegen::CodegenHelperVisitor::analyze
codegen::CodegenInfo analyze(const ast::Program &node)
run visitor and return information for code generation
Definition: codegen_helper_visitor.cpp:821
compute_code_info
CodegenInfo compute_code_info(const std::string &text)
Definition: external.cpp:25
nmodl::codegen::CodegenHelperVisitor
Helper visitor to gather AST information to help code generation.
Definition: codegen_helper_visitor.hpp:47
nmodl_driver.hpp
symtab_visitor.hpp
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.