NEURON
var_usage_visitor.hpp
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 #pragma once
9 
10 /**
11  * \file
12  * \brief \copybrief nmodl::visitor::VarUsageVisitor
13  */
14 
15 #include <string>
16 
17 #include "visitors/ast_visitor.hpp"
18 
19 
20 namespace nmodl {
21 namespace visitor {
22 
23 /**
24  * \addtogroup visitor_classes
25  * \{
26  */
27 
28 /**
29  * \class VarUsageVisitor
30  * \brief Check if variable is used in given block
31  *
32  * \todo Check if macro is considered as variable
33  */
34 
35 class VarUsageVisitor: protected ConstAstVisitor {
36  private:
37  /// variable to check usage
38  std::string var_name;
39  bool used = false;
40 
41  void visit_name(const ast::Name& node) override;
42 
43  public:
44  VarUsageVisitor() = default;
45 
46  bool variable_used(const ast::Node& node, std::string name);
47 };
48 
49 /** \} */ // end of visitor_classes
50 
51 } // namespace visitor
52 } // namespace nmodl
Concrete visitor for all AST classes.
Represents a name.
Definition: name.hpp:44
Base class for all AST node.
Definition: node.hpp:40
Concrete constant visitor for all AST classes.
Check if variable is used in given block.
bool variable_used(const ast::Node &node, std::string name)
std::string var_name
variable to check usage
void visit_name(const ast::Name &node) override
rename matching variable
const char * name
Definition: init.cpp:16
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
static Node * node(Object *)
Definition: netcvode.cpp:291