8 #include <catch2/catch_test_macros.hpp>
9 #include <catch2/matchers/catch_matchers_string.hpp>
18 using namespace nmodl;
19 using namespace visitor;
20 using namespace test_utils;
35 SCENARIO(
"TABLE stmt",
"[visitor][semantic_analysis]") {
36 GIVEN(
"Procedure with more than one argument") {
38 PROCEDURE rates_1(a, b) {
39 TABLE ainf FROM 0 TO 1 WITH 1
47 GIVEN(
"Procedure with exactly one argument") {
49 PROCEDURE rates_1(a) {
50 TABLE ainf FROM 0 TO 1 WITH 1
58 GIVEN(
"Procedure with less than one argument") {
61 TABLE ainf FROM 0 TO 1 WITH 1
69 GIVEN(
"Two procedures which use a table and have the same variable") {
72 TABLE var FROM 0 TO 1 WITH 10
76 TABLE var FROM 0 TO 1 WITH 10
88 SCENARIO(
"Destructor block",
"[visitor][semantic_analysis]") {
89 GIVEN(
"A point-process mod file, with a destructor") {
91 DESTRUCTOR { : Destructor is before
102 GIVEN(
"A artifial-cell mod file, with a destructor") {
115 GIVEN(
"A non point-process mod file, with a destructor") {
129 SCENARIO(
"Ion variable in CONSTANT block",
"[visitor][semantic_analysis]") {
130 GIVEN(
"A mod file with ion variable redeclared in a CONSTANT block") {
134 USEION ca READ cao, cai, ica WRITE cai
136 CONSTANT { cao = 2 (mM) }
138 THEN("Semantic analysis fails") {
144 SCENARIO(
"INDEPENDENT block",
"[visitor][semantic_analysis]") {
145 GIVEN(
"A mod file with Independent block with only t") {
148 t FROM 0 TO 1 WITH 100
151 THEN("Semantic analysis succeed") {
155 GIVEN(
"A mod file with Independent block with something else than t") {
158 t FROM 0 TO 1 WITH 100
159 u FROM 0 TO 1 WITH 100
162 THEN("Semantic analysis fails") {
168 SCENARIO(
"FUNCTION_TABLE block",
"[visitor][semantic_analysis]") {
169 GIVEN(
"A mod file with FUNCTION_TABLE without argument") {
173 THEN("Semantic analysis should fail") {
177 GIVEN(
"A mod file with FUNCTION_TABLE with at least one argument") {
179 FUNCTION_TABLE ttt(w (mV))
181 THEN("Semantic analysis should success") {
188 SCENARIO(
"At most one DERIVATIVE block",
"[visitor][semantic_analysis]") {
189 GIVEN(
"Only one DERIVATIVE block") {
195 THEN("Semantic analysis should success") {
199 GIVEN(
"2 DERIVATIVE blocks") {
208 THEN("Semantic analysis should failed") {
214 SCENARIO(
"RANDOM Construct",
"[visitor][semantic_analysis]") {
215 GIVEN(
"A mod file with correct RANDOM variable usage") {
223 x = 1 + random_negexp(r)
224 x = x + exp(random_negexp(r))
227 erand = random_negexp(r)
230 THEN("Semantic analysis should pass") {
235 GIVEN(
"A mod file with incorrect usage of RANDOM variable as function arguments") {
244 THEN("Semantic analysis should faial") {
249 GIVEN(
"A mod file with incorrect usage of RANDOM variable in an expression") {
259 THEN("Semantic analysis should fail") {
264 GIVEN(
"A mod file with incorrect usage of RANDOM variable in non-random function") {
274 THEN("Semantic analysis should fail") {
280 SCENARIO(
"RANGE and FUNCTION/PROCEDURE block",
"[visitor][semantic_analysis]") {
281 GIVEN(
"A mod file with same RANGE var name and a FUNCTION name") {
290 THEN("Semantic analysis should fail") {
294 GIVEN(
"A mod file with same RANGE var name and a PROCEDURE name") {
302 THEN("Semantic analysis should fail") {
308 SCENARIO(
"FUNCTION block that does not return anything must raise a warning",
309 "[visitor][semantic_analysis]") {
310 GIVEN(
"A mod file with a FUNCTION that does not return anything") {
315 THEN("Semantic analysis should raise a warning") {
318 REQUIRE_THAT(capture.output(),
319 Catch::Matchers::ContainsSubstring(
"does not have a return statement"));
322 GIVEN(
"A mod file with a FUNCTION that does not return anything and VERBATIM block") {
330 THEN("Semantic analysis should raise a warning") {
333 REQUIRE_THAT(capture.output(),
334 Catch::Matchers::ContainsSubstring(
335 "possible return statement in VERBATIM block"));
Class that binds all pieces together for parsing nmodl file.
Visitor to check some semantic rules on the AST
bool check(const ast::Program &node)
Concrete visitor for constructing symbol table from AST.
void visit_program(ast::Program &node) override
visit node of type ast::Program
bool parse_string(const std::string &input)
parser Units provided as string (used for testing)
encapsulates code generation backend implementations
Auto generated AST classes declaration.
bool run_semantic_analysis_visitor(const std::string &text)
SCENARIO("TABLE stmt", "[visitor][semantic_analysis]")
Visitor to check some semantic rules on the AST
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::parser::UnitDriver driver