Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid use of ion variable in the CONSTANT block #1955

Merged
merged 6 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/nmodl/modl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ no longer adequate for saying we can not */
#endif
chk_thread_safe();
chk_global_state();
check_useion_variables();

parout(); /* print .var file.
* Also #defines which used to be in defs.h
* are printed into .c file at beginning.
Expand Down
1 change: 1 addition & 0 deletions src/nmodl/nmodlfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void net_init(Item* qinit, Item* qp2);
void fornetcon(Item* keyword, Item* par1, Item* args, Item* par2, Item* stmt, Item* qend);
void chk_thread_safe();
void chk_global_state();
void check_useion_variables();
void threadsafe_seen(Item* q1, Item* q2);
void explicit_decl(int level, Item* q);
void parm_array_install(Symbol* n, char* num, char* units, char* limits, int index);
Expand Down
34 changes: 34 additions & 0 deletions src/nmodl/nocpout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,40 @@ static void _destructor(Prop* _prop) {\n\
}
}


// Check if read/write variable from USEION is declared in a
// CONSTANT block. There are certain MOD files where this pattern
// is used and it doesn't produce a desired code. Hence, we check
// all ion variables and error if any variable is declared as CONSTANT.
void check_ion_vars_as_constant(char* ion_name, const List* ion_var_list) {
const Item* var;
ITERATE(var, ion_var_list) {
const Symbol* var_sym = SYM(var);
int type = iontype(var_sym->name, ion_name);
if (type == IONIN || type == IONOUT || type == IONCUR || type == IONCONC ||
type == IONEREV) {
if (var_sym->subtype & nmodlCONST) {
diag(var_sym->name,
" used in USEION statement can not be re-declared in a CONSTANT block");
}
}
}
}


// check semantics of read & write variables from USEION statements
void check_useion_variables() {
const Item* ion_var;
ITERATE(ion_var, useion) {
// read variables
check_ion_vars_as_constant(SYM(ion_var)->name, LST(ion_var->next));
// write variables
check_ion_vars_as_constant(SYM(ion_var)->name, LST(ion_var->next->next));
ion_var = ion_var->next->next->next;
}
}


void warn_ignore(Symbol* s) {
int b;
double d1, d2;
Expand Down