8 #include <catch2/catch_test_macros.hpp>
18 using namespace nmodl;
19 using namespace visitor;
21 using namespace test_utils;
36 std::stringstream stream;
45 SCENARIO(
"Perform constant folder on NMODL constructs") {
46 GIVEN(
"Simple integer expression") {
52 std::string expected_text = R"(
57 THEN("successfully folds") {
63 GIVEN(
"Simple double expression") {
69 std::string expected_text = R"(
74 THEN("successfully folds") {
80 GIVEN(
"Complex expression") {
83 a = 1 + (2) + (2 / 2) + (((1+((2)))))
86 std::string expected_text = R"(
91 THEN("successfully folds") {
97 GIVEN(
"Integer expression with define statement") {
102 a = N + (2*N) + (N / 2) + (((1+((N)))))
107 std::string expected_text = R"(
116 THEN("successfully folds") {
122 GIVEN(
"Only fold part of the statement") {
133 std::string expected_text = R"(
143 THEN("successfully folds and keep other statements untouched") {
149 GIVEN(
"Don't remove parentheses if not simplifying") {
154 a = ((N+1)+5)*(c+1+N)/(b - 2)
157 std::string expected_text = R"(
161 a = 16*(c+1+10)/(b-2)
164 THEN("successfully folds and keep other statements untouched") {
Visitor for checking parents of ast nodes
Class that binds all pieces together for parsing nmodl file.
void visit_program(ast::Program &node) override
visit node of type ast::Program
Perform constant folding of integer/float/double expressions.
Visitor for printing AST back to NMODL
void visit_program(const ast::Program &node) override
visit node of type ast::Program
Concrete visitor for constructing symbol table from AST.
void visit_program(ast::Program &node) override
visit node of type ast::Program
Visitor for checking parents of ast nodes
int check_ast(const ast::Ast &node)
A small wrapper to have a nicer call in parser.cpp.
std::string run_constant_folding_visitor(const std::string &text)
SCENARIO("Perform constant folder on NMODL constructs")
Perform constant folding of integer/float/double expressions.
bool parse_string(const std::string &input)
parser Units provided as string (used for testing)
std::string reindent_text(const std::string &text, int indent_level)
Reindent nmodl text for text-to-text comparison.
encapsulates code generation backend implementations
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
Auto generated AST classes declaration.
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::parser::UnitDriver driver