Fixed __SET_EXTERNAL_FB declaration in accessor.h, invoked when accessing EXTERNAL_BLOCK.VARIABLE. Macro was invoking __SET_VAR with wrong parameter count. Fixed corresponding code generator for ST. Seems similar codegen for IL is also broken, but fix would affect other (unknown) behviours -> didn't touch it.
--- a/lib/C/accessor.h Mon Oct 04 11:29:13 2021 +0200
+++ b/lib/C/accessor.h Wed Nov 24 08:58:58 2021 +0100
@@ -129,7 +129,7 @@
if (!(prefix name.flags & __IEC_FORCE_FLAG || __IS_GLOBAL_##name##_FORCED()))\
(*(prefix name.value)) suffix = new_value;}
#define __SET_EXTERNAL_FB(prefix, name, suffix, new_value)\
- __SET_VAR((*(prefix name)), suffix, new_value)
+ __SET_VAR(prefix, name, suffix, new_value)
#define __SET_LOCATED(prefix, name, suffix, new_value)\
if (!(prefix name.flags & __IEC_FORCE_FLAG)) *(prefix name.value) suffix = new_value
--- a/stage4/generate_c/generate_c_st.cc Mon Oct 04 11:29:13 2021 +0200
+++ b/stage4/generate_c/generate_c_st.cc Wed Nov 24 08:58:58 2021 +0100
@@ -169,8 +169,9 @@
symbol_c* fb_symbol = NULL,
symbol_c* fb_value = NULL) {
+ unsigned int vartype;
if (fb_symbol == NULL) {
- unsigned int vartype = analyse_variable_c::first_nonfb_vardecltype(symbol, scope_);
+ vartype = analyse_variable_c::first_nonfb_vardecltype(symbol, scope_);
symbol_c *first_nonfb = analyse_variable_c::find_first_nonfb(symbol);
if (first_nonfb == NULL) ERROR;
if (vartype == search_var_instance_decl_c::external_vt) {
@@ -186,7 +187,7 @@
s4o.print(SET_VAR);
}
else {
- unsigned int vartype = search_var_instance_decl->get_vartype(fb_symbol);
+ vartype = search_var_instance_decl->get_vartype(fb_symbol);
if (vartype == search_var_instance_decl_c::external_vt)
s4o.print(SET_EXTERNAL_FB);
else
@@ -195,12 +196,20 @@
s4o.print("(");
if (fb_symbol != NULL) {
- print_variable_prefix();
- // It is my (MJS) conviction that by this time the following will always be true...
- // wanted_variablegeneration == expression_vg;
- fb_symbol->accept(*this);
- s4o.print(".,");
- symbol->accept(*this);
+ if (vartype == search_var_instance_decl_c::external_vt){
+ print_variable_prefix();
+ s4o.print(",");
+ fb_symbol->accept(*this);
+ s4o.print("->");
+ symbol->accept(*this);
+ }else{
+ print_variable_prefix();
+ // It is my (MJS) conviction that by this time the following will always be true...
+ // wanted_variablegeneration == expression_vg;
+ fb_symbol->accept(*this);
+ s4o.print(".,");
+ symbol->accept(*this);
+ }
s4o.print(",");
s4o.print(",");
} else {