User Guide
ast_common.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  * \dir
12  * \brief AST Implementation
13  *
14  * \file
15  * \brief Implementation of AST base class and it's properties
16  */
17 
18 #include <memory>
19 #include <string>
20 
21 #include "ast/ast_decl.hpp"
22 #include "lexer/modtoken.hpp"
23 #include "symtab/symbol_table.hpp"
24 #include "visitors/visitor.hpp"
25 
26 namespace nmodl {
27 
28 /// Abstract Syntax Tree (AST) related implementations
29 namespace ast {
30 
31 /**
32  * @defgroup ast AST Implementation
33  * @brief All AST related implementation details
34  *
35  * @defgroup ast_prop AST Properties
36  * @ingroup ast
37  * @brief Properties and types used with of AST classes
38  * @{
39  */
40 
41 /**
42  * \brief enum Type for binary operators in NMODL
43  *
44  * NMODL support different binary operators and this
45  * type is used to store their value in the AST.
46  */
47 typedef enum {
48  BOP_ADDITION, ///< \+
49  BOP_SUBTRACTION, ///< --
50  BOP_MULTIPLICATION, ///< \c *
51  BOP_DIVISION, ///< \/
52  BOP_POWER, ///< ^
53  BOP_AND, ///< &&
54  BOP_OR, ///< ||
55  BOP_GREATER, ///< >
56  BOP_LESS, ///< <
58  BOP_LESS_EQUAL, ///< <=
59  BOP_ASSIGN, ///< =
60  BOP_NOT_EQUAL, ///< !=
62 } BinaryOp;
63 
64 /**
65  * \brief string representation of ast::BinaryOp
66  *
67  * When AST is converted back to NMODL or C code, ast::BinaryOpNames
68  * is used to lookup the corresponding symbol for the operator.
69  */
70 static const std::string BinaryOpNames[] =
71  {"+", "-", "*", "/", "^", "&&", "||", ">", "<", ">=", "<=", "=", "!=", "=="};
72 
73 /// enum type for unary operators
74 typedef enum { UOP_NOT, UOP_NEGATION } UnaryOp;
75 
76 /// string representation of ast::UnaryOp
77 static const std::string UnaryOpNames[] = {"!", "-"};
78 
79 /// enum type to distinguish BEFORE or AFTER blocks
81 
82 /// string representation of ast::BAType
83 static const std::string BATypeNames[] = {"BREAKPOINT", "SOLVE", "INITIAL", "STEP"};
84 
85 /// enum type used for UNIT_ON or UNIT_OFF state
86 typedef enum { UNIT_ON, UNIT_OFF } UnitStateType;
87 
88 /// string representation of ast::UnitStateType
89 static const std::string UnitStateTypeNames[] = {"UNITSON", "UNITSOFF"};
90 
91 /// enum type used for Reaction statement
92 typedef enum { LTMINUSGT, LTLT, MINUSGT } ReactionOp;
93 
94 /// string representation of ast::ReactionOp
95 static const std::string ReactionOpNames[] = {"<->", "<<", "->"};
96 
97 /** @} */ // end of ast_prop
98 
99 } // namespace ast
100 } // namespace nmodl
nmodl::ast::BOP_GREATER_EQUAL
@ BOP_GREATER_EQUAL
>=
Definition: ast_common.hpp:57
nmodl::ast::BinaryOp
BinaryOp
enum Type for binary operators in NMODL
Definition: ast_common.hpp:47
nmodl::ast::UnaryOp
UnaryOp
enum type for unary operators
Definition: ast_common.hpp:74
nmodl::ast::BATYPE_STEP
@ BATYPE_STEP
Definition: ast_common.hpp:80
nmodl::ast::BOP_LESS
@ BOP_LESS
<
Definition: ast_common.hpp:56
nmodl::ast::BAType
BAType
enum type to distinguish BEFORE or AFTER blocks
Definition: ast_common.hpp:80
nmodl::ast::ReactionOpNames
static const std::string ReactionOpNames[]
string representation of ast::ReactionOp
Definition: ast_common.hpp:95
nmodl::ast::BATYPE_INITIAL
@ BATYPE_INITIAL
Definition: ast_common.hpp:80
nmodl::ast::BOP_POWER
@ BOP_POWER
^
Definition: ast_common.hpp:52
nmodl::ast::UNIT_OFF
@ UNIT_OFF
Definition: ast_common.hpp:86
ast_decl.hpp
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::ast::UOP_NEGATION
@ UOP_NEGATION
Definition: ast_common.hpp:74
nmodl::ast::ReactionOp
ReactionOp
enum type used for Reaction statement
Definition: ast_common.hpp:92
nmodl::ast::BATypeNames
static const std::string BATypeNames[]
string representation of ast::BAType
Definition: ast_common.hpp:83
symbol_table.hpp
Implement classes for representing symbol table at block and file scope.
nmodl::ast::BOP_ASSIGN
@ BOP_ASSIGN
=
Definition: ast_common.hpp:59
nmodl::ast::BOP_SUBTRACTION
@ BOP_SUBTRACTION
Definition: ast_common.hpp:49
nmodl::ast::UOP_NOT
@ UOP_NOT
Definition: ast_common.hpp:74
visitor.hpp
nmodl::ast::BOP_EXACT_EQUAL
@ BOP_EXACT_EQUAL
==
Definition: ast_common.hpp:61
nmodl::ast::BOP_OR
@ BOP_OR
||
Definition: ast_common.hpp:54
nmodl::ast::BOP_ADDITION
@ BOP_ADDITION
+
Definition: ast_common.hpp:48
nmodl::ast::BOP_DIVISION
@ BOP_DIVISION
\/
Definition: ast_common.hpp:51
nmodl::ast::BOP_MULTIPLICATION
@ BOP_MULTIPLICATION
*
Definition: ast_common.hpp:50
nmodl::ast::UnitStateTypeNames
static const std::string UnitStateTypeNames[]
string representation of ast::UnitStateType
Definition: ast_common.hpp:89
nmodl::ast::BATYPE_SOLVE
@ BATYPE_SOLVE
Definition: ast_common.hpp:80
nmodl::ast::BOP_LESS_EQUAL
@ BOP_LESS_EQUAL
<=
Definition: ast_common.hpp:58
nmodl::ast::BATYPE_BREAKPOINT
@ BATYPE_BREAKPOINT
Definition: ast_common.hpp:80
nmodl::ast::LTMINUSGT
@ LTMINUSGT
Definition: ast_common.hpp:92
nmodl::ast::BOP_AND
@ BOP_AND
&&
Definition: ast_common.hpp:53
nmodl::ast::BinaryOpNames
static const std::string BinaryOpNames[]
string representation of ast::BinaryOp
Definition: ast_common.hpp:70
modtoken.hpp
nmodl::ast::UNIT_ON
@ UNIT_ON
Definition: ast_common.hpp:86
nmodl::ast::BOP_NOT_EQUAL
@ BOP_NOT_EQUAL
!=
Definition: ast_common.hpp:60
nmodl::ast::UnitStateType
UnitStateType
enum type used for UNIT_ON or UNIT_OFF state
Definition: ast_common.hpp:86
nmodl::ast::UnaryOpNames
static const std::string UnaryOpNames[]
string representation of ast::UnaryOp
Definition: ast_common.hpp:77
nmodl::ast::MINUSGT
@ MINUSGT
Definition: ast_common.hpp:92
nmodl::ast::LTLT
@ LTLT
Definition: ast_common.hpp:92
nmodl::ast::BOP_GREATER
@ BOP_GREATER
Definition: ast_common.hpp:55