# HG changeset patch # User Mario de Sousa # Date 1321817808 0 # Node ID b6a522b762c9b5d9d99e90cd9035249cadc4eaf7 # Parent a9d377c4987a1f5a83d2111c4a6de8cd911ae101# Parent 9b88b8b6bccd35d48ce454d0f647019532619212 Merging with Laurent's repository. diff -r a9d377c4987a -r b6a522b762c9 lib/accessor.h --- a/lib/accessor.h Fri Nov 04 19:16:29 2011 +0000 +++ b/lib/accessor.h Sun Nov 20 19:36:48 2011 +0000 @@ -6,15 +6,14 @@ // variable declaration macros #define __DECLARE_VAR(type, name)\ __IEC_##type##_t name; -#define __DECLARE_GLOBAL(type, resource, name)\ - __IEC_##type##_t resource##__##name;\ - static __IEC_##type##_t *GLOBAL__##name = &resource##__##name;\ +#define __DECLARE_GLOBAL(type, domain, name)\ + __IEC_##type##_t domain##__##name;\ + static __IEC_##type##_t *GLOBAL__##name = &(domain##__##name);\ void __INIT_GLOBAL_##name(type value) {\ (*GLOBAL__##name).value = value;\ }\ - void __SET_GLOBAL_##name(type value) {\ - if (!((*GLOBAL__##name).flags & __IEC_FORCE_FLAG))\ - (*GLOBAL__##name).value = value;\ + IEC_BYTE __IS_GLOBAL_##name##_FORCED(void) {\ + return (*GLOBAL__##name).flags & __IEC_FORCE_FLAG;\ }\ type* __GET_GLOBAL_##name(void) {\ return &((*GLOBAL__##name).value);\ @@ -23,13 +22,12 @@ extern type *location; #define __DECLARE_GLOBAL_LOCATED(type, resource, name)\ __IEC_##type##_p resource##__##name;\ - static __IEC_##type##_p *GLOBAL__##name = &resource##__##name;\ + static __IEC_##type##_p *GLOBAL__##name = &(resource##__##name);\ void __INIT_GLOBAL_##name(type value) {\ *((*GLOBAL__##name).value) = value;\ }\ - void __SET_GLOBAL_##name(type value) {\ - if (!((*GLOBAL__##name).flags & __IEC_FORCE_FLAG))\ - *((*GLOBAL__##name).value) = value;\ + IEC_BYTE __IS_GLOBAL_##name##_FORCED(void) {\ + return (*GLOBAL__##name).flags & __IEC_FORCE_FLAG;\ }\ type* __GET_GLOBAL_##name(void) {\ return (*GLOBAL__##name).value;\ @@ -52,16 +50,21 @@ __INIT_GLOBAL_##name(temp);\ __INIT_RETAIN((*GLOBAL__##name), retained)\ } -#define __INIT_GLOBAL_LOCATED(resource, name, location, retained)\ - resource##__##name.value = location;\ - __INIT_RETAIN(resource##__##name, retained) +#define __INIT_GLOBAL_LOCATED(domain, name, location, retained)\ + domain##__##name.value = location;\ + __INIT_RETAIN(domain##__##name, retained) #define __INIT_EXTERNAL(type, global, name, retained)\ - name.value = __GET_GLOBAL_##global();\ - __INIT_RETAIN(name, retained) + {\ + extern type* __GET_GLOBAL_##global();\ + name.value = __GET_GLOBAL_##global();\ + __INIT_RETAIN(name, retained)\ + } #define __INIT_LOCATED(type, location, name, retained)\ - {extern type *location;\ - name.value = location;\ - __INIT_RETAIN(name, retained)} + {\ + extern type *location;\ + name.value = location;\ + __INIT_RETAIN(name, retained)\ + } #define __INIT_LOCATED_VALUE(name, initial)\ *(name.value) = initial; @@ -81,14 +84,12 @@ ((name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(*(name.value) __VA_ARGS__)) // variable setting macros -#define __SET_VAR(name, new_value, ...)\ - if (!(name.flags & __IEC_FORCE_FLAG)) name.value __VA_ARGS__ = new_value -#define __SET_EXTERNAL(global, name, new_value)\ - if (!(name.flags & __IEC_FORCE_FLAG))\ - __SET_GLOBAL_##global(new_value) -#define __SET_COMPLEX_EXTERNAL(name, new_value, ...)\ - *(name.value) __VA_ARGS__ = new_value -#define __SET_LOCATED(name, new_value, ...)\ - if (!(name.flags & __IEC_FORCE_FLAG)) *(name.value) __VA_ARGS__ = new_value +#define __SET_VAR(prefix, name, new_value, ...)\ + if (!(prefix name.flags & __IEC_FORCE_FLAG)) prefix name.value __VA_ARGS__ = new_value +#define __SET_EXTERNAL(prefix, name, new_value, ...)\ + if (!(prefix name.flags & __IEC_FORCE_FLAG || __IS_GLOBAL_##name##_FORCED()))\ + (*(prefix name.value)) __VA_ARGS__ = new_value +#define __SET_LOCATED(prefix, name, new_value, ...)\ + if (!(prefix name.flags & __IEC_FORCE_FLAG)) *(prefix name.value) __VA_ARGS__ = new_value #endif //__ACCESSOR_H diff -r a9d377c4987a -r b6a522b762c9 lib/create_standard_function_txt.sh --- a/lib/create_standard_function_txt.sh Fri Nov 04 19:16:29 2011 +0000 +++ b/lib/create_standard_function_txt.sh Sun Nov 20 19:36:48 2011 +0000 @@ -427,7 +427,9 @@ /**************/ /* SUB */ /**************/ -#define __iec_(TYPENAME) __arith_static(SUB, TYPENAME) +#define __iec_(TYPENAME)\ +__function_2p(SUB_##TYPENAME, TYPENAME, IN1, TYPENAME, IN2, TYPENAME) /* explicitly typed function */\ +__function_2p(SUB, TYPENAME, IN1, TYPENAME, IN2, TYPENAME) /* overloaded function */ __ANY_NUM(__iec_) #undef __iec_ diff -r a9d377c4987a -r b6a522b762c9 lib/iec_std_lib.h --- a/lib/iec_std_lib.h Fri Nov 04 19:16:29 2011 +0000 +++ b/lib/iec_std_lib.h Sun Nov 20 19:36:48 2011 +0000 @@ -340,7 +340,7 @@ static inline STRING __bit_to_string(LWORD IN) { STRING res; res = __INIT_STRING; - res.len = snprintf((char*)res.body, STR_MAX_LEN, "16#%llx", IN); + res.len = snprintf((char*)res.body, STR_MAX_LEN, "16#%llx",(long long unsigned int)IN); if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; return res; } @@ -354,14 +354,14 @@ static inline STRING __sint_to_string(LINT IN) { STRING res; res = __INIT_STRING; - res.len = snprintf((char*)res.body, STR_MAX_LEN, "%lld", IN); + res.len = snprintf((char*)res.body, STR_MAX_LEN, "%lld", (long long int)IN); if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; return res; } static inline STRING __uint_to_string(ULINT IN) { STRING res; res = __INIT_STRING; - res.len = snprintf((char*)res.body, STR_MAX_LEN, "%llu", IN); + res.len = snprintf((char*)res.body, STR_MAX_LEN, "%llu", (long long unsigned int)IN); if(res.len > STR_MAX_LEN) res.len = STR_MAX_LEN; return res; } diff -r a9d377c4987a -r b6a522b762c9 lib/standard_functions.txt --- a/lib/standard_functions.txt Fri Nov 04 19:16:29 2011 +0000 +++ b/lib/standard_functions.txt Sun Nov 20 19:36:48 2011 +0000 @@ -607,32 +607,26 @@ FUNCTION MUL : UDINT VAR_INPUT IN 1 .. : UDINT; END_VAR RETURN; END_FUNCTION FUNCTION MUL_ULINT : ULINT VAR_INPUT IN 1 .. : ULINT; END_VAR RETURN; END_FUNCTION FUNCTION MUL : ULINT VAR_INPUT IN 1 .. : ULINT; END_VAR RETURN; END_FUNCTION - - - - - - -FUNCTION SUB_REAL : REAL VAR_INPUT IN : REAL; END_VAR RETURN; END_FUNCTION -FUNCTION SUB : REAL VAR_INPUT IN : REAL; END_VAR RETURN; END_FUNCTION -FUNCTION SUB_LREAL : LREAL VAR_INPUT IN : LREAL; END_VAR RETURN; END_FUNCTION -FUNCTION SUB : LREAL VAR_INPUT IN : LREAL; END_VAR RETURN; END_FUNCTION -FUNCTION SUB_SINT : SINT VAR_INPUT IN : SINT; END_VAR RETURN; END_FUNCTION -FUNCTION SUB : SINT VAR_INPUT IN : SINT; END_VAR RETURN; END_FUNCTION -FUNCTION SUB_INT : INT VAR_INPUT IN : INT; END_VAR RETURN; END_FUNCTION -FUNCTION SUB : INT VAR_INPUT IN : INT; END_VAR RETURN; END_FUNCTION -FUNCTION SUB_DINT : DINT VAR_INPUT IN : DINT; END_VAR RETURN; END_FUNCTION -FUNCTION SUB : DINT VAR_INPUT IN : DINT; END_VAR RETURN; END_FUNCTION -FUNCTION SUB_LINT : LINT VAR_INPUT IN : LINT; END_VAR RETURN; END_FUNCTION -FUNCTION SUB : LINT VAR_INPUT IN : LINT; END_VAR RETURN; END_FUNCTION -FUNCTION SUB_USINT : USINT VAR_INPUT IN : USINT; END_VAR RETURN; END_FUNCTION -FUNCTION SUB : USINT VAR_INPUT IN : USINT; END_VAR RETURN; END_FUNCTION -FUNCTION SUB_UINT : UINT VAR_INPUT IN : UINT; END_VAR RETURN; END_FUNCTION -FUNCTION SUB : UINT VAR_INPUT IN : UINT; END_VAR RETURN; END_FUNCTION -FUNCTION SUB_UDINT : UDINT VAR_INPUT IN : UDINT; END_VAR RETURN; END_FUNCTION -FUNCTION SUB : UDINT VAR_INPUT IN : UDINT; END_VAR RETURN; END_FUNCTION -FUNCTION SUB_ULINT : ULINT VAR_INPUT IN : ULINT; END_VAR RETURN; END_FUNCTION -FUNCTION SUB : ULINT VAR_INPUT IN : ULINT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB_REAL : REAL VAR_INPUT IN1 : REAL; IN2 : REAL; END_VAR RETURN; END_FUNCTION +FUNCTION SUB : REAL VAR_INPUT IN1 : REAL; IN2 : REAL; END_VAR RETURN; END_FUNCTION +FUNCTION SUB_LREAL : LREAL VAR_INPUT IN1 : LREAL; IN2 : LREAL; END_VAR RETURN; END_FUNCTION +FUNCTION SUB : LREAL VAR_INPUT IN1 : LREAL; IN2 : LREAL; END_VAR RETURN; END_FUNCTION +FUNCTION SUB_SINT : SINT VAR_INPUT IN1 : SINT; IN2 : SINT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB : SINT VAR_INPUT IN1 : SINT; IN2 : SINT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB_INT : INT VAR_INPUT IN1 : INT; IN2 : INT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB : INT VAR_INPUT IN1 : INT; IN2 : INT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB_DINT : DINT VAR_INPUT IN1 : DINT; IN2 : DINT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB : DINT VAR_INPUT IN1 : DINT; IN2 : DINT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB_LINT : LINT VAR_INPUT IN1 : LINT; IN2 : LINT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB : LINT VAR_INPUT IN1 : LINT; IN2 : LINT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB_USINT : USINT VAR_INPUT IN1 : USINT; IN2 : USINT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB : USINT VAR_INPUT IN1 : USINT; IN2 : USINT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB_UINT : UINT VAR_INPUT IN1 : UINT; IN2 : UINT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB : UINT VAR_INPUT IN1 : UINT; IN2 : UINT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB_UDINT : UDINT VAR_INPUT IN1 : UDINT; IN2 : UDINT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB : UDINT VAR_INPUT IN1 : UDINT; IN2 : UDINT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB_ULINT : ULINT VAR_INPUT IN1 : ULINT; IN2 : ULINT; END_VAR RETURN; END_FUNCTION +FUNCTION SUB : ULINT VAR_INPUT IN1 : ULINT; IN2 : ULINT; END_VAR RETURN; END_FUNCTION FUNCTION DIV_REAL : REAL VAR_INPUT IN1 : REAL; IN2 : REAL; END_VAR RETURN; END_FUNCTION FUNCTION DIV : REAL VAR_INPUT IN1 : REAL; IN2 : REAL; END_VAR RETURN; END_FUNCTION FUNCTION DIV_LREAL : LREAL VAR_INPUT IN1 : LREAL; IN2 : LREAL; END_VAR RETURN; END_FUNCTION diff -r a9d377c4987a -r b6a522b762c9 lib/timer.txt --- a/lib/timer.txt Fri Nov 04 19:16:29 2011 +0000 +++ b/lib/timer.txt Sun Nov 20 19:36:48 2011 +0000 @@ -90,7 +90,7 @@ CURRENT_TIME, START_TIME : TIME; END_VAR - {__SET_VAR(data__->CURRENT_TIME,__CURRENT_TIME)} + {__SET_VAR(data__->,CURRENT_TIME,__CURRENT_TIME)} IF ((STATE = 0) AND NOT(PREV_IN) AND IN) (* found rising edge on IN *) THEN @@ -171,7 +171,7 @@ CURRENT_TIME, START_TIME : TIME; END_VAR - {__SET_VAR(data__->CURRENT_TIME,__CURRENT_TIME)} + {__SET_VAR(data__->,CURRENT_TIME,__CURRENT_TIME)} IF ((STATE = 0) AND NOT(PREV_IN) AND IN) (* found rising edge on IN *) THEN @@ -255,7 +255,7 @@ CURRENT_TIME, START_TIME : TIME; END_VAR - {__SET_VAR(data__->CURRENT_TIME,__CURRENT_TIME)} + {__SET_VAR(data__->,CURRENT_TIME,__CURRENT_TIME)} IF ((STATE = 0) AND PREV_IN AND NOT(IN)) (* found falling edge on IN *) THEN diff -r a9d377c4987a -r b6a522b762c9 stage3/visit_expression_type.cc --- a/stage3/visit_expression_type.cc Fri Nov 04 19:16:29 2011 +0000 +++ b/stage3/visit_expression_type.cc Sun Nov 20 19:36:48 2011 +0000 @@ -440,6 +440,13 @@ return false; } +bool visit_expression_type_c::is_ANY_ELEMENTARY_OR_ENUMERATED_compatible(symbol_c *type_symbol) { + if (type_symbol == NULL) {return false;} + if (search_base_type.type_is_enumerated(type_symbol)) {return true;} + return is_ANY_ELEMENTARY_compatible(type_symbol); +} + + /* Determine the common data type between two data types. * If no common data type found, return NULL. * @@ -1785,7 +1792,7 @@ void *visit_expression_type_c::visit(equ_expression_c *symbol) { symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); - compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible, symbol->l_exp, symbol->r_exp); + compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_OR_ENUMERATED_compatible, symbol->l_exp, symbol->r_exp); return &search_expression_type_c::bool_type_name; } @@ -1793,7 +1800,7 @@ void *visit_expression_type_c::visit(notequ_expression_c *symbol) { symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); - compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible, symbol->l_exp, symbol->r_exp); + compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_OR_ENUMERATED_compatible, symbol->l_exp, symbol->r_exp); return &search_expression_type_c::bool_type_name; } diff -r a9d377c4987a -r b6a522b762c9 stage3/visit_expression_type.hh --- a/stage3/visit_expression_type.hh Fri Nov 04 19:16:29 2011 +0000 +++ b/stage3/visit_expression_type.hh Sun Nov 20 19:36:48 2011 +0000 @@ -137,6 +137,8 @@ bool is_literal_real_type (symbol_c *type_symbol); bool is_literal_bool_type (symbol_c *type_symbol); + bool is_ANY_ELEMENTARY_OR_ENUMERATED_compatible (symbol_c *type_symbol); + /* Determine the common data type between two data types. * If no common data type found, return NULL. * diff -r a9d377c4987a -r b6a522b762c9 stage4/generate_c/generate_c.cc --- a/stage4/generate_c/generate_c.cc Fri Nov 04 19:16:29 2011 +0000 +++ b/stage4/generate_c/generate_c.cc Sun Nov 20 19:36:48 2011 +0000 @@ -124,7 +124,6 @@ /* Variable setter symbol for accessor macros */ #define SET_VAR "__SET_VAR" #define SET_EXTERNAL "__SET_EXTERNAL" -#define SET_COMPLEX_EXTERNAL "__SET_COMPLEX_EXTERNAL" #define SET_LOCATED "__SET_LOCATED" @@ -1334,7 +1333,7 @@ s4o.print(SET_VAR); s4o.print("("); s4o.print(FB_FUNCTION_PARAM); - s4o.print("->ENO,__BOOL_LITERAL(FALSE));\n"); + s4o.print("->,ENO,__BOOL_LITERAL(FALSE));\n"); s4o.print(s4o.indent_spaces + "return;\n"); s4o.indent_left(); s4o.print(s4o.indent_spaces + "}\n"); @@ -1344,7 +1343,7 @@ s4o.print(SET_VAR); s4o.print("("); s4o.print(FB_FUNCTION_PARAM); - s4o.print("->ENO,__BOOL_LITERAL(TRUE));\n"); + s4o.print("->,ENO,__BOOL_LITERAL(TRUE));\n"); s4o.indent_left(); s4o.print(s4o.indent_spaces + "}\n"); @@ -1621,7 +1620,8 @@ /* (A.2) Global variables */ vardecl = new generate_c_vardecl_c(&s4o, generate_c_vardecl_c::local_vf, - generate_c_vardecl_c::global_vt); + generate_c_vardecl_c::global_vt, + symbol->configuration_name); vardecl->print(symbol); delete vardecl; s4o.print("\n"); @@ -1894,6 +1894,7 @@ s4o.print("extern unsigned long long common_ticktime__;\n\n"); s4o.print("#include \"accessor.h\"\n\n"); + s4o.print("#include \"POUS.h\"\n\n"); /* (A.2) Global variables... */ if (current_global_vars != NULL) { @@ -1907,7 +1908,6 @@ } /* (A.3) POUs inclusion */ - s4o.print("#include \"POUS.h\"\n\n"); s4o.print("#include \"POUS.c\"\n\n"); wanted_declaretype = declare_dt; @@ -2098,33 +2098,29 @@ if (symbol->single_data_source != NULL) { symbol_c *config_var_decl = NULL; symbol_c *res_var_decl = NULL; - unsigned int vartype; + s4o.print(s4o.indent_spaces + "{"); symbol_c *current_var_reference = ((global_var_reference_c *)(symbol->single_data_source))->global_var_name; res_var_decl = search_resource_instance->get_decl(current_var_reference); if (res_var_decl == NULL) { config_var_decl = search_config_instance->get_decl(current_var_reference); if (config_var_decl == NULL) ERROR; - vartype = search_config_instance->get_vartype(); - s4o.print(s4o.indent_spaces + "{extern "); config_var_decl->accept(*this); - s4o.print(" *"); - symbol->single_data_source->accept(*this); - s4o.print("; "); } else { - vartype = search_resource_instance->get_vartype(); - s4o.print(s4o.indent_spaces); + res_var_decl->accept(*this); } + s4o.print("* "); + symbol->single_data_source->accept(*this); + s4o.print(" = __GET_GLOBAL_"); + symbol->single_data_source->accept(*this); + s4o.print("();"); s4o.print(SET_VAR); s4o.print("("); current_task_name->accept(*this); - s4o.print("_R_TRIG.CLK, *__GET_GLOBAL_"); + s4o.print("_R_TRIG.,CLK, *"); symbol->single_data_source->accept(*this); - s4o.print("());"); - if (config_var_decl != NULL) - s4o.print("}"); - s4o.print("\n"); + s4o.print(");}\n"); s4o.print(s4o.indent_spaces + "R_TRIG"); s4o.print(FB_FUNCTION_SUFFIX); s4o.print("(&"); diff -r a9d377c4987a -r b6a522b762c9 stage4/generate_c/generate_c_il.cc --- a/stage4/generate_c/generate_c_il.cc Fri Nov 04 19:16:29 2011 +0000 +++ b/stage4/generate_c/generate_c_il.cc Sun Nov 20 19:36:48 2011 +0000 @@ -132,6 +132,7 @@ expression_vg, assignment_vg, complextype_base_vg, + complextype_base_assignment_vg, complextype_suffix_vg, fparam_output_vg } variablegeneration_t; @@ -287,6 +288,11 @@ this->default_variable_back_name.accept(*this); } + void reset_default_variable_name(void) { + this->default_variable_name.current_type = NULL; + this->default_variable_back_name.current_type = NULL; + } + private: /* A helper function... */ /* @@ -468,35 +474,21 @@ bool negative = false) { unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); bool type_is_complex = search_varfb_instance_type->type_is_complex(); - if (vartype == search_var_instance_decl_c::external_vt) { - symbolic_variable_c *variable = dynamic_cast(symbol); - /* TODO Find a solution for forcing global complex variables */ - if (variable != NULL) { - s4o.print(SET_EXTERNAL); - s4o.print("("); - variable->var_name->accept(*this); - s4o.print(","); - } - else { - s4o.print(SET_COMPLEX_EXTERNAL); - s4o.print("("); - } - } - else { - if (vartype == search_var_instance_decl_c::located_vt) - s4o.print(SET_LOCATED); - else - s4o.print(SET_VAR); - s4o.print("("); - } + if (vartype == search_var_instance_decl_c::external_vt) + s4o.print(SET_EXTERNAL); + else if (vartype == search_var_instance_decl_c::located_vt) + s4o.print(SET_LOCATED); + else + s4o.print(SET_VAR); + s4o.print("("); if (fb_symbol != NULL) { print_variable_prefix(); fb_symbol->accept(*this); - s4o.print("."); + s4o.print(".,"); } else if (type_is_complex) - wanted_variablegeneration = complextype_base_vg; + wanted_variablegeneration = complextype_base_assignment_vg; else wanted_variablegeneration = assignment_vg; @@ -580,8 +572,13 @@ void *visit(symbolic_variable_c *symbol) { unsigned int vartype; switch (wanted_variablegeneration) { + case complextype_base_assignment_vg: + case assignment_vg: + this->print_variable_prefix(); + s4o.print(","); + symbol->var_name->accept(*this); + break; case complextype_base_vg: - case assignment_vg: generate_c_base_c::visit(symbol); break; case complextype_suffix_vg: @@ -648,6 +645,7 @@ TRACE("structured_variable_c"); switch (wanted_variablegeneration) { case complextype_base_vg: + case complextype_base_assignment_vg: symbol->record_variable->accept(*this); break; case complextype_suffix_vg: @@ -674,6 +672,7 @@ void *visit(array_variable_c *symbol) { switch (wanted_variablegeneration) { case complextype_base_vg: + case complextype_base_assignment_vg: symbol->subscripted_variable->accept(*this); break; case complextype_suffix_vg: diff -r a9d377c4987a -r b6a522b762c9 stage4/generate_c/generate_c_inlinefcall.cc --- a/stage4/generate_c/generate_c_inlinefcall.cc Fri Nov 04 19:16:29 2011 +0000 +++ b/stage4/generate_c/generate_c_inlinefcall.cc Sun Nov 20 19:36:48 2011 +0000 @@ -120,6 +120,9 @@ search_expression_type = new search_expression_type_c(scope); search_varfb_instance_type = new search_varfb_instance_type_c(scope); this->set_variable_prefix(variable_prefix); + current_operand = NULL; + current_operand_type = NULL; + il_default_variable_init_value = NULL; fcall_number = 0; fbname = name; wanted_variablegeneration = expression_vg; @@ -330,27 +333,13 @@ symbol_c* type, symbol_c* value) { unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); - if (vartype == search_var_instance_decl_c::external_vt) { - symbolic_variable_c *variable = dynamic_cast(symbol); - /* TODO Find a solution for forcing global complex variables */ - if (variable != NULL) { - s4o.print(SET_EXTERNAL); - s4o.print("("); - variable->var_name->accept(*this); - s4o.print(","); - } - else { - s4o.print(SET_COMPLEX_EXTERNAL); - s4o.print("("); - } - } - else { - if (vartype == search_var_instance_decl_c::located_vt) - s4o.print(SET_LOCATED); - else - s4o.print(SET_VAR); - s4o.print("("); - } + if (vartype == search_var_instance_decl_c::external_vt) + s4o.print(SET_EXTERNAL); + else if (vartype == search_var_instance_decl_c::located_vt) + s4o.print(SET_LOCATED); + else + s4o.print(SET_VAR); + s4o.print("(,"); wanted_variablegeneration = complextype_base_vg; symbol->accept(*this); @@ -469,6 +458,7 @@ } return NULL; } + /* | il_simple_operator [il_operand] */ //SYM_REF2(il_simple_operation_c, il_simple_operator, il_operand) void *visit(il_simple_operation_c *symbol) { diff -r a9d377c4987a -r b6a522b762c9 stage4/generate_c/generate_c_sfc.cc --- a/stage4/generate_c/generate_c_sfc.cc Fri Nov 04 19:16:29 2011 +0000 +++ b/stage4/generate_c/generate_c_sfc.cc Sun Nov 20 19:36:48 2011 +0000 @@ -96,8 +96,9 @@ } } - void print_step_argument(symbol_c *step_name, const char* argument) { - print_variable_prefix(); + void print_step_argument(symbol_c *step_name, const char* argument, bool setter=false) { + print_variable_prefix(); + if (setter) s4o.print(","); s4o.print("__step_list["); s4o.print(SFC_STEP_ACTION_PREFIX); step_name->accept(*this); @@ -105,8 +106,9 @@ s4o.print(argument); } - void print_action_argument(symbol_c *action_name, const char* argument) { - print_variable_prefix(); + void print_action_argument(symbol_c *action_name, const char* argument, bool setter=false) { + print_variable_prefix(); + if (setter) s4o.print(","); s4o.print("__action_list["); s4o.print(SFC_STEP_ACTION_PREFIX); action_name->accept(*this); @@ -122,7 +124,7 @@ s4o.print(s4o.indent_spaces); s4o.print(SET_VAR); s4o.print("("); - print_step_argument(step_name, "state"); + print_step_argument(step_name, "state", true); s4o.print(",0);\n"); } @@ -130,7 +132,7 @@ s4o.print(s4o.indent_spaces); s4o.print(SET_VAR); s4o.print("("); - print_step_argument(step_name, "state"); + print_step_argument(step_name, "state", true); s4o.print(",1);\n" + s4o.indent_spaces); print_step_argument(step_name, "elapsed_time"); s4o.print(" = __time_to_timespec(1, 0, 0, 0, 0, 0);\n"); @@ -283,7 +285,7 @@ s4o.print(SET_VAR); s4o.print("("); print_variable_prefix(); - s4o.print("__transition_list["); + s4o.print(",__transition_list["); print_transition_number(); s4o.print("],0);\n"); s4o.indent_left(); @@ -337,6 +339,7 @@ s4o.print(SET_VAR); s4o.print("("); print_variable_prefix(); + s4o.print(","); if (wanted_sfcgeneration == transitiontestdebug_sg) s4o.print("__debug_"); else @@ -345,6 +348,7 @@ print_transition_number(); s4o.print("],"); generate_c_il->print_backup_variable(); + generate_c_il->reset_default_variable_name(); s4o.print(");\n"); } // Transition condition is in ST @@ -353,6 +357,7 @@ s4o.print(SET_VAR); s4o.print("("); print_variable_prefix(); + s4o.print(","); if (wanted_sfcgeneration == transitiontestdebug_sg) s4o.print("__debug_"); else @@ -370,7 +375,7 @@ s4o.print(SET_VAR); s4o.print("("); print_variable_prefix(); - s4o.print("__debug_transition_list["); + s4o.print(",__debug_transition_list["); print_transition_number(); s4o.print("],"); s4o.print(GET_VAR); @@ -842,21 +847,16 @@ unsigned int vartype = search_var_instance_decl->get_vartype(); s4o.print(s4o.indent_spaces); - if (vartype == search_var_instance_decl_c::external_vt) { + if (vartype == search_var_instance_decl_c::external_vt) s4o.print(SET_EXTERNAL); - s4o.print("("); - pt->symbol->accept(*this); - s4o.print(","); - } - else { - if (vartype == search_var_instance_decl_c::located_vt) - s4o.print(SET_LOCATED); - else - s4o.print(SET_VAR); - s4o.print("("); - } - print_variable_prefix(); - pt->symbol->accept(*this); + else if (vartype == search_var_instance_decl_c::located_vt) + s4o.print(SET_LOCATED); + else + s4o.print(SET_VAR); + s4o.print("("); + print_variable_prefix(); + s4o.print(","); + pt->symbol->accept(*this); s4o.print(","); print_variable_prefix(); s4o.print("__action_list["); diff -r a9d377c4987a -r b6a522b762c9 stage4/generate_c/generate_c_sfcdecl.cc --- a/stage4/generate_c/generate_c_sfcdecl.cc Fri Nov 04 19:16:29 2011 +0000 +++ b/stage4/generate_c/generate_c_sfcdecl.cc Sun Nov 20 19:36:48 2011 +0000 @@ -250,7 +250,7 @@ s4o.print(SET_VAR); s4o.print("("); print_variable_prefix(); - s4o.print("__step_list["); + s4o.print(",__step_list["); s4o.print_integer(step_number); s4o.print("].state,1);\n"); step_number++; diff -r a9d377c4987a -r b6a522b762c9 stage4/generate_c/generate_c_st.cc --- a/stage4/generate_c/generate_c_st.cc Fri Nov 04 19:16:29 2011 +0000 +++ b/stage4/generate_c/generate_c_st.cc Sun Nov 20 19:36:48 2011 +0000 @@ -51,6 +51,7 @@ expression_vg, assignment_vg, complextype_base_vg, + complextype_base_assignment_vg, complextype_suffix_vg, fparam_output_vg } variablegeneration_t; @@ -171,35 +172,21 @@ unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); bool type_is_complex = search_varfb_instance_type->type_is_complex(); - if (vartype == search_var_instance_decl_c::external_vt) { - symbolic_variable_c *variable = dynamic_cast(symbol); - /* TODO Find a solution for forcing global complex variables */ - if (variable != NULL) { - s4o.print(SET_EXTERNAL); - s4o.print("("); - variable->var_name->accept(*this); - s4o.print(","); - } - else { - s4o.print(SET_COMPLEX_EXTERNAL); - s4o.print("("); - } - } - else { - if (vartype == search_var_instance_decl_c::located_vt) - s4o.print(SET_LOCATED); - else - s4o.print(SET_VAR); - s4o.print("("); - } + if (vartype == search_var_instance_decl_c::external_vt) + s4o.print(SET_EXTERNAL); + else if (vartype == search_var_instance_decl_c::located_vt) + s4o.print(SET_LOCATED); + else + s4o.print(SET_VAR); + s4o.print("("); if (fb_symbol != NULL) { print_variable_prefix(); fb_symbol->accept(*this); - s4o.print("."); + s4o.print(".,"); } else if (type_is_complex) - wanted_variablegeneration = complextype_base_vg; + wanted_variablegeneration = complextype_base_assignment_vg; else wanted_variablegeneration = assignment_vg; @@ -249,8 +236,13 @@ void *visit(symbolic_variable_c *symbol) { unsigned int vartype; switch (wanted_variablegeneration) { + case complextype_base_assignment_vg: + case assignment_vg: + this->print_variable_prefix(); + s4o.print(","); + symbol->var_name->accept(*this); + break; case complextype_base_vg: - case assignment_vg: generate_c_base_c::visit(symbol); break; case complextype_suffix_vg: @@ -317,6 +309,7 @@ TRACE("structured_variable_c"); switch (wanted_variablegeneration) { case complextype_base_vg: + case complextype_base_assignment_vg: symbol->record_variable->accept(*this); break; case complextype_suffix_vg: @@ -343,6 +336,7 @@ void *visit(array_variable_c *symbol) { switch (wanted_variablegeneration) { case complextype_base_vg: + case complextype_base_assignment_vg: symbol->subscripted_variable->accept(*this); break; case complextype_suffix_vg: diff -r a9d377c4987a -r b6a522b762c9 stage4/generate_c/generate_c_vardecl.cc --- a/stage4/generate_c/generate_c_vardecl.cc Fri Nov 04 19:16:29 2011 +0000 +++ b/stage4/generate_c/generate_c_vardecl.cc Sun Nov 20 19:36:48 2011 +0000 @@ -161,6 +161,7 @@ s4o.print(SET_VAR); s4o.print("("); print_variable_prefix(); + s4o.print(","); symbol->elements[i]->accept(*this); s4o.print(",temp);\n"); } @@ -553,6 +554,7 @@ s4o.print(SET_VAR); s4o.print("("); print_variable_prefix(); + s4o.print(","); symbol->elements[i]->accept(*this); s4o.print(",temp);\n"); } @@ -924,16 +926,19 @@ s4o.print(" "); else s4o.print(","); + print_variable_prefix(); } else if (wanted_varformat == localinit_vf) { this->current_var_type_symbol->accept(*this); s4o.print(" "); + print_variable_prefix(); } else if (wanted_varformat == init_vf) { s4o.print(SET_VAR); s4o.print("("); + print_variable_prefix(); + s4o.print(","); } - print_variable_prefix(); list->elements[i]->accept(*this); if (wanted_varformat != local_vf) { if (wanted_varformat == localinit_vf &&