Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 3699a27

Browse files
author
Nicolas Cornu
committed
Add a check for external definition that are not thread safe
1 parent 60249f1 commit 3699a27

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

src/lexer/token_mapping.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ const static std::vector<std::string> extern_definitions = {"acos",
246246
"tanh",
247247
"threshold"};
248248
const static std::vector<std::string> need_nt = {"at_time"};
249+
const static std::vector<std::string> not_thread_safe = {"force", "deflate", "expfit", "derivs", "spline", "exprand", "gauss", "normrand", "poisrand", "poisson", "setseed", "scop_random", "boundary", "romberg", "invert", "stepforce", "schedule", "set_seed", "nrn_random_play"};
250+
251+
bool is_external_definitions(const std::string& token) {
252+
return std::find(extern_definitions.cbegin(), extern_definitions.cend(), token) != extern_definitions.cend();
253+
}
254+
249255

250256
/**
251257
* Checks if \c token is one of the functions coming from NEURON/CoreNEURON and needs
@@ -259,6 +265,11 @@ bool needs_neuron_thread_first_arg(const std::string& token) {
259265
}
260266

261267

268+
bool is_not_thread_safe(const std::string& token) {
269+
return std::find(not_thread_safe.cbegin(), not_thread_safe.cend(), token) != not_thread_safe.cend();
270+
}
271+
272+
262273
/**
263274
* Variables from NEURON that are directly used in NMODL
264275
*

src/lexer/token_mapping.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ std::vector<std::string> get_external_functions();
2727

2828
namespace details {
2929

30+
bool is_external_definitions(const std::string& token);
3031
bool needs_neuron_thread_first_arg(const std::string& token);
32+
bool is_not_thread_safe(const std::string& token);
3133

3234
} // namespace details
3335

src/visitors/semantic_analysis_visitor.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "ast/table_statement.hpp"
77
#include "utils/logger.hpp"
88
#include "visitors/visitor_utils.hpp"
9+
#include "lexer/token_mapping.hpp"
910

1011
namespace nmodl {
1112
namespace visitor {
@@ -78,5 +79,15 @@ void SemanticAnalysisVisitor::visit_destructor_block(const ast::DestructorBlock&
7879
/// -->
7980
}
8081

82+
void SemanticAnalysisVisitor::visit_function_call(const ast::FunctionCall& node) {
83+
/// <-- This code is for check 4
84+
const auto& name = node.get_node_name();
85+
if (details::is_external_definitions(name) && details::is_not_thread_safe(name)) {
86+
logger->critical("SemanticAnalysisVisitor :: '{}' is not thread safe and incompatible with CoreNEURON", name);
87+
check_fail = true;
88+
}
89+
/// -->
90+
}
91+
8192
} // namespace visitor
8293
} // namespace nmodl

src/visitors/semantic_analysis_visitor.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* (mandatory in mod2c).
2828
* 2. Check that destructor blocks are only inside mod file that are point_process
2929
* 3. A TABLE statement in functions cannot have name list, and should have one in procedures
30+
* 4. Check that an external definition is allowed by CoreNeuron
3031
*/
3132
#include "ast/ast.hpp"
3233
#include "visitors/ast_visitor.hpp"
@@ -59,6 +60,10 @@ class SemanticAnalysisVisitor: public ConstAstVisitor {
5960
/// Visit destructor and check that the file is of type POINT_PROCESS or ARTIFICIAL_CELL
6061
void visit_destructor_block(const ast::DestructorBlock& node) override;
6162

63+
/// Visit function call and check if the function is not thread safe and so not
64+
/// compatible with CoreNeuron
65+
void visit_function_call(const ast::FunctionCall& node) override;
66+
6267
public:
6368
SemanticAnalysisVisitor() = default;
6469

0 commit comments

Comments
 (0)