User Guide
symbol.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 "symtab/symbol.hpp"
9 #include "utils/logger.hpp"
10 #include <ast/ast.hpp>
11 
12 namespace nmodl {
13 namespace symtab {
14 
15 using syminfo::NmodlType;
16 using syminfo::Status;
17 
18 
19 bool Symbol::is_variable() const noexcept {
20  // if symbol has one of the following property then it
21  // is considered as variable in the NMODL
22  // clang-format off
23  NmodlType var_properties = NmodlType::local_var
24  | NmodlType::global_var
25  | NmodlType::range_var
26  | NmodlType::param_assign
27  | NmodlType::pointer_var
28  | NmodlType::bbcore_pointer_var
29  | NmodlType::extern_var
30  | NmodlType::assigned_definition
31  | NmodlType::read_ion_var
32  | NmodlType::write_ion_var
33  | NmodlType::nonspecific_cur_var
34  | NmodlType::electrode_cur_var
35  | NmodlType::argument
36  | NmodlType::extern_neuron_variable;
37  // clang-format on
38  return has_any_property(var_properties);
39 }
40 
41 std::string Symbol::to_string() const {
42  std::string s(name);
43  if (properties != NmodlType::empty) {
44  s += fmt::format(" [Properties : {}]", syminfo::to_string(properties));
45  }
46  if (status != Status::empty) {
47  s += fmt::format(" [Status : {}]", syminfo::to_string(status));
48  }
49  return s;
50 }
51 
52 std::vector<ast::Ast*> Symbol::get_nodes_by_type(
53  std::initializer_list<ast::AstNodeType> l) const noexcept {
54  std::vector<ast::Ast*> _nodes;
55  for (const auto& n: nodes) {
56  for (const auto& m: l) {
57  if (n->get_node_type() == m) {
58  _nodes.push_back(n);
59  break;
60  }
61  }
62  }
63  return _nodes;
64 }
65 
66 } // namespace symtab
67 } // namespace nmodl
symbol.hpp
Implement class to represent a symbol in Symbol Table.
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::symtab::syminfo::Status
Status
state during various compiler passes
Definition: symbol_properties.hpp:54
nmodl::symtab::Symbol::has_any_property
bool has_any_property(syminfo::NmodlType new_properties) const noexcept
check if symbol has any of the given property
Definition: symbol.hpp:289
nmodl::symtab::syminfo::to_string
std::string to_string(const T &obj)
Definition: symbol_properties.hpp:282
nmodl::symtab::Symbol::status
syminfo::Status status
status of symbol after processing through various passes
Definition: symbol.hpp:76
ast.hpp
Auto generated AST classes declaration.
nmodl::symtab::Symbol::name
std::string name
name of the symbol
Definition: symbol.hpp:57
nmodl::symtab::syminfo::NmodlType
NmodlType
NMODL variable properties.
Definition: symbol_properties.hpp:116
logger.hpp
Implement logger based on spdlog library.
nmodl::symtab::Symbol::get_nodes_by_type
std::vector< ast::Ast * > get_nodes_by_type(std::initializer_list< ast::AstNodeType > l) const noexcept
Definition: symbol.cpp:52
nmodl::symtab::Symbol::is_variable
bool is_variable() const noexcept
check if symbol is a variable in nmodl
Definition: symbol.cpp:19
nmodl::symtab::Symbol::properties
syminfo::NmodlType properties
properties of symbol as a result of usage across whole mod file
Definition: symbol.hpp:73
nmodl::symtab::Symbol::to_string
std::string to_string() const
Definition: symbol.cpp:41