Skip to content

Commit

Permalink
SemanticAnalysisVisitor: detect if several solve blocks are given
Browse files Browse the repository at this point in the history
  • Loading branch information
alkino committed Nov 9, 2023
1 parent 36199d0 commit 7e91888
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/visitors/semantic_analysis_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "visitors/semantic_analysis_visitor.hpp"
#include "ast/breakpoint_block.hpp"
#include "ast/function_block.hpp"
#include "ast/function_table_block.hpp"
#include "ast/independent_block.hpp"
Expand Down Expand Up @@ -170,5 +171,24 @@ void SemanticAnalysisVisitor::visit_mutex_unlock(const ast::MutexUnlock& /* node
/// -->
}

void SemanticAnalysisVisitor::visit_breakpoint_block(const ast::BreakpointBlock& node) {
/// <-- This code is for check 8
solve_block_found_in_this_breakpoint_block = false;
node.visit_children(*this);
solve_block_found_in_this_breakpoint_block = false;
/// -->
}

void SemanticAnalysisVisitor::visit_solve_block(const ast::SolveBlock& /* node */) {
/// <-- This code is for check 8
if (solve_block_found_in_this_breakpoint_block) {
logger->critical("It is not allowed to have several solve blocks in the same breakpoint block");
check_fail = true;
} else {
solve_block_found_in_this_breakpoint_block = true;
}
/// -->
}

} // namespace visitor
} // namespace nmodl
8 changes: 8 additions & 0 deletions src/visitors/semantic_analysis_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* 5. Check if an independent variable is not 't'.
* 6. Check that mutex are not badly use
* 7. Check than function table got at least one argument.
* 8. Check that at most one solve block is present per breakpoint block.
*/
#include "ast/ast.hpp"
#include "visitors/ast_visitor.hpp"
Expand All @@ -54,6 +55,8 @@ class SemanticAnalysisVisitor: public ConstAstVisitor {
bool is_point_process = false;
/// true if we are inside a mutex locked part
bool in_mutex = false;
/// true if we already found a solve block
bool solve_block_found_in_this_breakpoint_block = false;

/// Store if we are in a procedure and if the arity of this is 1
void visit_procedure_block(const ast::ProcedureBlock& node) override;
Expand Down Expand Up @@ -82,6 +85,11 @@ class SemanticAnalysisVisitor: public ConstAstVisitor {
/// Look if MUTEXUNLOCK is outside a locked block
void visit_mutex_unlock(const ast::MutexUnlock& node) override;

void visit_breakpoint_block(const ast::BreakpointBlock& node) override;

/// Check how many solve block we got
void visit_solve_block(const ast::SolveBlock& node) override;

public:
SemanticAnalysisVisitor(bool accel_backend = false)
: accel_backend(accel_backend) {}
Expand Down

0 comments on commit 7e91888

Please sign in to comment.