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

Commit b76ade7

Browse files
Nicolas CornuNicolas Cornu
authored andcommitted
Add a check for external definition that are not thread safe
1 parent af7c772 commit b76ade7

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

src/lexer/token_mapping.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,31 @@ const static std::vector<std::string> extern_definitions = {"acos",
244244
"tanh",
245245
"threshold"};
246246
const static std::vector<std::string> need_nt = {"at_time"};
247+
const static std::vector<std::string> not_thread_safe = {"force",
248+
"deflate",
249+
"expfit",
250+
"derivs",
251+
"spline",
252+
"exprand",
253+
"gauss",
254+
"normrand",
255+
"poisrand",
256+
"poisson",
257+
"setseed",
258+
"scop_random",
259+
"boundary",
260+
"romberg",
261+
"invert",
262+
"stepforce",
263+
"schedule",
264+
"set_seed",
265+
"nrn_random_play"};
266+
267+
bool is_external_definitions(const std::string& token) {
268+
return std::find(extern_definitions.cbegin(), extern_definitions.cend(), token) !=
269+
extern_definitions.cend();
270+
}
271+
247272

248273
/**
249274
* Checks if \c token is one of the functions coming from NEURON/CoreNEURON and needs
@@ -257,6 +282,12 @@ bool needs_neuron_thread_first_arg(const std::string& token) {
257282
}
258283

259284

285+
bool is_not_thread_safe(const std::string& token) {
286+
return std::find(not_thread_safe.cbegin(), not_thread_safe.cend(), token) !=
287+
not_thread_safe.cend();
288+
}
289+
290+
260291
/**
261292
* Variables from NEURON that are directly used in NMODL
262293
*

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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "ast/program.hpp"
55
#include "ast/suffix.hpp"
66
#include "ast/table_statement.hpp"
7+
#include "lexer/token_mapping.hpp"
78
#include "symtab/symbol_properties.hpp"
89
#include "utils/logger.hpp"
910
#include "visitors/visitor_utils.hpp"
@@ -101,5 +102,17 @@ void SemanticAnalysisVisitor::visit_destructor_block(const ast::DestructorBlock&
101102
/// -->
102103
}
103104

105+
void SemanticAnalysisVisitor::visit_function_call(const ast::FunctionCall& node) {
106+
/// <-- This code is for check 5
107+
const auto& name = node.get_node_name();
108+
if (details::is_external_definitions(name) && details::is_not_thread_safe(name)) {
109+
logger->critical(
110+
"SemanticAnalysisVisitor :: '{}' is not thread safe and incompatible with CoreNEURON",
111+
name);
112+
check_fail = true;
113+
}
114+
/// -->
115+
}
116+
104117
} // namespace visitor
105118
} // namespace nmodl

src/visitors/semantic_analysis_visitor.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
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.
3030
* 4. Check if ion variables from a `USEION` statement are not declared in `CONSTANT` block.
31+
* 5. Check that an external definition is allowed by CoreNeuron
3132
*/
3233
#include "ast/ast.hpp"
3334
#include "visitors/ast_visitor.hpp"
@@ -60,6 +61,10 @@ class SemanticAnalysisVisitor: public ConstAstVisitor {
6061
/// Visit destructor and check that the file is of type POINT_PROCESS or ARTIFICIAL_CELL
6162
void visit_destructor_block(const ast::DestructorBlock& node) override;
6263

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

0 commit comments

Comments
 (0)