# HG changeset patch # User laurent # Date 1259766661 -3600 # Node ID c6aed7e5f070a9dc4209c9038b0804bce90c1ce7 # Parent f332b62cd2c1c0549988d303cc51bfac4152d05e Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced diff -r f332b62cd2c1 -r c6aed7e5f070 absyntax_utils/search_var_instance_decl.cc --- a/absyntax_utils/search_var_instance_decl.cc Tue Dec 01 09:03:33 2009 +0100 +++ b/absyntax_utils/search_var_instance_decl.cc Wed Dec 02 16:11:01 2009 +0100 @@ -58,7 +58,6 @@ search_var_instance_decl_c::search_var_instance_decl_c(symbol_c *search_scope) { this->current_vartype = none_vt; - this->current_varqualifier = none_vq; this->search_scope = search_scope; this->search_name = NULL; this->current_type_decl = NULL; @@ -66,7 +65,6 @@ symbol_c *search_var_instance_decl_c::get_decl(symbol_c *variable_instance_name) { this->current_vartype = none_vt; - this->current_varqualifier = none_vq; this->search_name = variable_instance_name; return (symbol_c *)search_scope->accept(*this); } @@ -75,10 +73,6 @@ return current_vartype; } -unsigned int search_var_instance_decl_c::get_varqualifier() { - return current_varqualifier; -} - /***************************/ /* B 0 - Programming Model */ /***************************/ @@ -95,33 +89,15 @@ /* B 1.4.3 - Declaration & Initialization */ /******************************************/ -void *search_var_instance_decl_c::visit(constant_option_c *symbol) { - current_varqualifier = constant_vq; - return NULL; -} - -void *search_var_instance_decl_c::visit(retain_option_c *symbol) { - current_varqualifier = retain_vq; - return NULL; -} - -void *search_var_instance_decl_c::visit(non_retain_option_c *symbol) { - current_varqualifier = non_retain_vq; - return NULL; -} - /* edge -> The F_EDGE or R_EDGE directive */ // SYM_REF2(edge_declaration_c, edge, var1_list) // TODO void *search_var_instance_decl_c::visit(input_declarations_c *symbol) { current_vartype = input_vt; - if (symbol->option != NULL) - symbol->option->accept(*this); void *res = symbol->input_declaration_list->accept(*this); if (res == NULL) { current_vartype = none_vt; - current_varqualifier = none_vq; } return res; } @@ -130,12 +106,9 @@ /* option -> may be NULL ! */ void *search_var_instance_decl_c::visit(output_declarations_c *symbol) { current_vartype = output_vt; - if (symbol->option != NULL) - symbol->option->accept(*this); void *res = symbol->var_init_decl_list->accept(*this); if (res == NULL) { current_vartype = none_vt; - current_varqualifier = none_vq; } return res; } @@ -163,12 +136,9 @@ /* helper symbol for input_declarations */ void *search_var_instance_decl_c::visit(var_declarations_c *symbol) { current_vartype = private_vt; - if (symbol->option != NULL) - symbol->option->accept(*this); void *res = symbol->var_init_decl_list->accept(*this); if (res == NULL) { current_vartype = none_vt; - current_varqualifier = none_vq; } return res; } @@ -176,11 +146,9 @@ /* VAR RETAIN var_init_decl_list END_VAR */ void *search_var_instance_decl_c::visit(retentive_var_declarations_c *symbol) { current_vartype = private_vt; - current_varqualifier = retain_vq; void *res = symbol->var_init_decl_list->accept(*this); if (res == NULL) { current_vartype = none_vt; - current_varqualifier = none_vq; } return res; } @@ -190,12 +158,9 @@ //SYM_REF2(located_var_declarations_c, option, located_var_decl_list) void *search_var_instance_decl_c::visit(located_var_declarations_c *symbol) { current_vartype = located_vt; - if (symbol->option != NULL) - symbol->option->accept(*this); void *res = symbol->located_var_decl_list->accept(*this); if (res == NULL) { current_vartype = none_vt; - current_varqualifier = none_vq; } return res; } @@ -205,12 +170,9 @@ //SYM_REF2(external_var_declarations_c, option, external_declaration_list) void *search_var_instance_decl_c::visit(external_var_declarations_c *symbol) { current_vartype = external_vt; - if (symbol->option != NULL) - symbol->option->accept(*this); void *res = symbol->external_declaration_list->accept(*this); if (res == NULL) { current_vartype = none_vt; - current_varqualifier = none_vq; } return res; } @@ -220,12 +182,9 @@ //SYM_REF2(global_var_declarations_c, option, global_var_decl_list) void *search_var_instance_decl_c::visit(global_var_declarations_c *symbol) { current_vartype = global_vt; - if (symbol->option != NULL) - symbol->option->accept(*this); void *res = symbol->global_var_decl_list->accept(*this); if (res == NULL) { current_vartype = none_vt; - current_varqualifier = none_vq; } return res; } diff -r f332b62cd2c1 -r c6aed7e5f070 absyntax_utils/search_var_instance_decl.hh --- a/absyntax_utils/search_var_instance_decl.hh Tue Dec 01 09:03:33 2009 +0100 +++ b/absyntax_utils/search_var_instance_decl.hh Wed Dec 02 16:11:01 2009 +0100 @@ -66,15 +66,10 @@ /* Will contain a single value of generate_c_vardecl_c::XXXX_vt */ unsigned int current_vartype; - /* variable used to store the qualifier of variable currently being processed... */ - /* Will contain a single value of generate_c_vardecl_c::XXXX_vq */ - unsigned int current_varqualifier; - public: search_var_instance_decl_c(symbol_c *search_scope); symbol_c *get_decl(symbol_c *variable_instance_name); unsigned int get_vartype(); - unsigned int get_varqualifier(); public: @@ -89,12 +84,6 @@ static const unsigned int global_vt = 0x0040; // VAR_GLOBAL static const unsigned int located_vt = 0x0080; // VAR AT - /* the qualifier of variables that need to be processed... */ - static const unsigned int none_vq = 0x0000; - static const unsigned int constant_vq = 0x0001; // CONSTANT - static const unsigned int retain_vq = 0x0002; // RETAIN - static const unsigned int non_retain_vq = 0x0002; // NON_RETAIN - private: /***************************/ /* B 0 - Programming Model */ @@ -105,9 +94,6 @@ /* B 1.4.3 - Declaration & Initialisation */ /******************************************/ - void *visit(constant_option_c *symbol); - void *visit(retain_option_c *symbol); - void *visit(non_retain_option_c *symbol); /* edge -> The F_EDGE or R_EDGE directive */ // SYM_REF2(edge_declaration_c, edge, var1_list) // TODO diff -r f332b62cd2c1 -r c6aed7e5f070 lib/accessor.h --- a/lib/accessor.h Tue Dec 01 09:03:33 2009 +0100 +++ b/lib/accessor.h Wed Dec 02 16:11:01 2009 +0100 @@ -1,65 +1,64 @@ #ifndef __ACCESSOR_H #define __ACCESSOR_H + // variable declaration macros #define __DECLARE_VAR(type, name)\ - type name; + __IEC_##type##_t name; #define __DECLARE_GLOBAL(type, resource, name)\ - type resource##__##name;\ - static type *GLOBAL__##name = &resource##__##name;\ - type __GET_GLOBAL_##name(void) {return *GLOBAL__##name;}\ - void __SET_GLOBAL_##name(type value) {*GLOBAL__##name = value;} + __IEC_##type##_t resource##__##name;\ + static __IEC_##type##_t *GLOBAL__##name = &resource##__##name; #define __DECLARE_GLOBAL_LOCATION(type, location)\ extern type *location; #define __DECLARE_GLOBAL_LOCATED(type, resource, name)\ - type *resource##__##name;\ - static type *GLOBAL__##name;\ - type __GET_GLOBAL_##name(void) {return *GLOBAL__##name;}\ - void __SET_GLOBAL_##name(type value) {*GLOBAL__##name = value;} + __IEC_##type##_p resource##__##name;\ + static __IEC_##type##_p *GLOBAL__##name; #define __DECLARE_EXTERNAL(type, name)\ - type *name; + __IEC_##type##_p name; #define __DECLARE_LOCATED(type, name)\ - type *name; + __IEC_##type##_p name; // variable initialization macros -#define __INIT_VAR(name, initial)\ - name = initial; -#define __INIT_GLOBAL(name, initial)\ - *GLOBAL__##name = initial; -#define __INIT_GLOBAL_LOCATED(resource, name, location)\ - resource##__##name = location;\ - GLOBAL__##name = location; -#define __INIT_EXTERNAL(type, global, name)\ - {extern type *GLOBAL__##global;\ - name = GLOBAL__##global;} -#define __INIT_LOCATED(type, location, name)\ +#define __INIT_STRUCT(name, initial, retained)\ + name.value = initial;\ + name.flags |= retained?4:0; +#define __INIT_VAR(name, initial, retained)\ + __INIT_STRUCT(name, initial, retained) +#define __INIT_GLOBAL(name, initial, retained)\ + __INIT_STRUCT((*GLOBAL__##name), initial, retained) +#define __INIT_GLOBAL_LOCATED(resource, name, location, retained)\ + __INIT_STRUCT(resource##__##name, location, retained) +#define __INIT_EXTERNAL(type, global, name, retained)\ + {extern __IEC_##type##_t *GLOBAL__##global;\ + __INIT_STRUCT(name, &((*GLOBAL__##global).value), retained)} +#define __INIT_LOCATED(type, location, name, retained)\ {extern type *location;\ - name = location;} + __INIT_STRUCT(name, location, retained)} #define __INIT_LOCATED_VALUE(name, initial)\ - *name = initial; + *(name.value) = initial; // variable getting macros -#define __GET_VAR(name)\ - name +#define __GET_VAR(name, ...)\ + name.value __VA_ARGS__ #define __GET_EXTERNAL(name)\ - __GET_GLOBAL_##name() + name.flags & 2 ? name.fvalue : *(name.value) #define __GET_LOCATED(name)\ - *(name) + name.flags & 2 ? name.fvalue : *(name.value) #define __GET_VAR_BY_REF(name)\ &(name) #define __GET_EXTERNAL_BY_REF(name)\ - GLOBAL__##name + name.value #define __GET_LOCATED_BY_REF(name)\ - name + name.value // variable setting macros -#define __SET_VAR(name, new_value)\ - name = new_value +#define __SET_VAR(name, new_value, ...)\ + if (!(name.flags & 2)) name.value __VA_ARGS__ = new_value #define __SET_EXTERNAL(name, new_value)\ - __SET_GLOBAL_##name(value) + if (!(name.flags & 2)) *(name.value) = new_value #define __SET_LOCATED(name, new_value)\ - *(name) = value + if (!(name.flags & 2)) *(name.value) = new_value #endif //__ACCESSOR_H diff -r f332b62cd2c1 -r c6aed7e5f070 lib/iec_types_all.h --- a/lib/iec_types_all.h Tue Dec 01 09:03:33 2009 +0100 +++ b/lib/iec_types_all.h Wed Dec 02 16:11:01 2009 +0100 @@ -10,13 +10,54 @@ /* Include non windows.h clashing typedefs */ #include "iec_types.h" +#define TRUE 1 +#define FALSE 0 + +#define __DECLARE_IEC_TYPE(type)\ +typedef IEC_##type type;\ +\ +typedef struct {\ + IEC_##type value;\ + IEC_BYTE flags;\ +} __IEC_##type##_t;\ +\ +typedef struct {\ + IEC_##type *value;\ + IEC_BYTE flags;\ + IEC_##type fvalue;\ +} __IEC_##type##_p; + +#define __DECLARE_DERIVED_TYPE(base, type)\ +typedef base type;\ +typedef __IEC_##base##_t __IEC_##type##_t; + +#define __DECLARE_COMPLEX_STRUCT(type)\ +typedef struct {\ + type value;\ + IEC_BYTE flags;\ +} __IEC_##type##_t;\ +\ +typedef struct {\ + type *value;\ + IEC_BYTE flags;\ +} __IEC_##type##_p; + +#define __DECLARE_ARRAY_TYPE(base, type, size)\ +typedef base type size;\ +__DECLARE_COMPLEX_STRUCT(type); + +#define __DECLARE_STRUCT_TYPE(elements, type)\ +typedef elements type;\ +__DECLARE_COMPLEX_STRUCT(type); + /* Those typdefs clash with windows.h */ /* i.e. this file cannot be included aside windows.h */ +ANY(__DECLARE_IEC_TYPE) + + +/* typedef IEC_BOOL BOOL; -#define TRUE 1 -#define FALSE 0 - typedef IEC_SINT SINT; typedef IEC_INT INT; typedef IEC_DINT DINT; @@ -41,9 +82,10 @@ typedef IEC_TOD TOD; typedef IEC_STRING STRING; +*/ typedef struct { - BOOL state; // current step state. 0 : inative, 1: active + __IEC_BOOL_t state; // current step state. 0 : inative, 1: active BOOL prev_state; // previous step state. 0 : inative, 1: active TIME elapsed_time; // time since step is active } STEP; diff -r f332b62cd2c1 -r c6aed7e5f070 stage4/generate_c/generate_c.cc --- a/stage4/generate_c/generate_c.cc Tue Dec 01 09:03:33 2009 +0100 +++ b/stage4/generate_c/generate_c.cc Wed Dec 02 16:11:01 2009 +0100 @@ -699,7 +699,7 @@ symbol->fblock_name->accept(*this); s4o.print(" *"); s4o.print(FB_FUNCTION_PARAM); - s4o.print(") {\n"); + s4o.print(", BOOL retain) {\n"); s4o.indent_right(); /* (B.2) Member initializations... */ @@ -887,7 +887,7 @@ symbol->program_type_name->accept(*this); s4o.print(" *"); s4o.print(FB_FUNCTION_PARAM); - s4o.print(") {\n"); + s4o.print(", BOOL retain) {\n"); s4o.indent_right(); /* (B.2) Member initializations... */ @@ -1202,6 +1202,50 @@ assigntype_t wanted_assigntype; + /* the qualifier of variables that need to be processed... */ + static const unsigned int none_vq = 0x0000; + static const unsigned int constant_vq = 0x0001; // CONSTANT + static const unsigned int retain_vq = 0x0002; // RETAIN + static const unsigned int non_retain_vq = 0x0004; // NON_RETAIN + + /* variable used to store the qualifier of program currently being processed... */ + unsigned int current_varqualifier; + + void *print_retain(void) { + s4o.print(","); + switch (current_varqualifier) { + case retain_vq: + s4o.print("1"); + break; + case non_retain_vq: + s4o.print("0"); + break; + default: + s4o.print("retain"); + break; + } + return NULL; + } + + /******************************************/ + /* B 1.4.3 - Declaration & Initialisation */ + /******************************************/ + + void *visit(constant_option_c *symbol) { + current_varqualifier = constant_vq; + return NULL; + } + + void *visit(retain_option_c *symbol) { + current_varqualifier = retain_vq; + return NULL; + } + + void *visit(non_retain_option_c *symbol) { + current_varqualifier = non_retain_vq; + return NULL; + } + /********************************/ /* B 1.7 Configuration elements */ /********************************/ @@ -1281,6 +1325,8 @@ s4o.print(FB_INIT_SUFFIX); s4o.print("(void) {\n"); s4o.indent_right(); + s4o.print(s4o.indent_spaces); + s4o.print("BOOL retain = 0;\n"); /* (B.2) Global variables initialisations... */ if (current_global_vars != NULL) { @@ -1350,11 +1396,14 @@ s4o.print("\n"); break; case init_dt: + if (symbol->retain_option != NULL) + symbol->retain_option->accept(*this); s4o.print(s4o.indent_spaces); symbol->program_type_name->accept(*this); s4o.print(FB_INIT_SUFFIX); s4o.print("(&"); symbol->program_name->accept(*this); + print_retain(); s4o.print(");\n"); break; case run_dt: diff -r f332b62cd2c1 -r c6aed7e5f070 stage4/generate_c/generate_c_il.cc --- a/stage4/generate_c/generate_c_il.cc Tue Dec 01 09:03:33 2009 +0100 +++ b/stage4/generate_c/generate_c_il.cc Wed Dec 02 16:11:01 2009 +0100 @@ -469,28 +469,24 @@ /*********************/ /* B 1.4 - Variables */ /*********************/ -/* B 1.4 - Variables */ -/*********************/ + void *visit(symbolic_variable_c *symbol) { unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); if (this->is_variable_prefix_null()) { if (wanted_variablegeneration == fparam_output_vg) { - if (vartype == search_var_instance_decl_c::external_vt) { + if (vartype == search_var_instance_decl_c::external_vt) s4o.print(GET_EXTERNAL); - s4o.print("("); - symbol->var_name->accept(*this); - } - else { - s4o.print("&("); - generate_c_base_c::visit(symbol); - } + else + s4o.print("&"); + s4o.print("("); + generate_c_base_c::visit(symbol); s4o.print(")"); } else { if (vartype == search_var_instance_decl_c::external_vt) { s4o.print(GET_EXTERNAL); s4o.print("("); - symbol->var_name->accept(*this); + generate_c_base_c::visit(symbol); s4o.print(")"); } else @@ -500,42 +496,29 @@ else { switch (wanted_variablegeneration) { case expression_vg: - if (vartype == search_var_instance_decl_c::external_vt) { + if (vartype == search_var_instance_decl_c::external_vt) s4o.print(GET_EXTERNAL); - s4o.print("("); - symbol->var_name->accept(*this); - } - else { - if (vartype == search_var_instance_decl_c::located_vt) - s4o.print(GET_LOCATED); - else - s4o.print(GET_VAR); - s4o.print("("); - generate_c_base_c::visit(symbol); - } + else if (vartype == search_var_instance_decl_c::located_vt) + s4o.print(GET_LOCATED); + else + s4o.print(GET_VAR); + s4o.print("("); + generate_c_base_c::visit(symbol); s4o.print(")"); break; case fparam_output_vg: - if (vartype == search_var_instance_decl_c::external_vt) { + if (vartype == search_var_instance_decl_c::external_vt) s4o.print(GET_EXTERNAL_BY_REF); - s4o.print("("); - symbol->var_name->accept(*this); - } - else { - if (vartype == search_var_instance_decl_c::located_vt) - s4o.print(GET_LOCATED_BY_REF); - else - s4o.print(GET_VAR_BY_REF); - s4o.print("("); - generate_c_base_c::visit(symbol); - } + else if (vartype == search_var_instance_decl_c::located_vt) + s4o.print(GET_LOCATED_BY_REF); + else + s4o.print(GET_VAR_BY_REF); + s4o.print("("); + generate_c_base_c::visit(symbol); s4o.print(")"); break; default: - if (vartype == search_var_instance_decl_c::external_vt) - symbol->var_name->accept(*this); - else - generate_c_base_c::visit(symbol); + generate_c_base_c::visit(symbol); break; } } diff -r f332b62cd2c1 -r c6aed7e5f070 stage4/generate_c/generate_c_inlinefcall.cc --- a/stage4/generate_c/generate_c_inlinefcall.cc Tue Dec 01 09:03:33 2009 +0100 +++ b/stage4/generate_c/generate_c_inlinefcall.cc Wed Dec 02 16:11:01 2009 +0100 @@ -34,6 +34,12 @@ class generate_c_inline_c: public generate_c_typedecl_c { + public: + typedef enum { + expression_vg, + assignment_vg + } variablegeneration_t; + private: /* The name of the IL default variable... */ @@ -53,6 +59,8 @@ search_base_type_c search_base_type; + variablegeneration_t wanted_variablegeneration; + public: generate_c_inline_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) : generate_c_typedecl_c(s4o_ptr), @@ -63,6 +71,7 @@ this->set_variable_prefix(variable_prefix); fcall_number = 0; fbname = name; + wanted_variablegeneration = expression_vg; } virtual ~generate_c_inline_c(void) { @@ -162,8 +171,9 @@ else s4o.print(SET_VAR); s4o.print("("); - + wanted_variablegeneration = assignment_vg; PARAM_VALUE->accept(*this); + wanted_variablegeneration = expression_vg; s4o.print(", "); print_check_function(PARAM_TYPE, PARAM_NAME, NULL, true); s4o.print(");\n"); @@ -185,21 +195,25 @@ /* B 1.4 - Variables */ /*********************/ void *visit(symbolic_variable_c *symbol) { - unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); - if (vartype == search_var_instance_decl_c::external_vt) { - s4o.print(GET_EXTERNAL); - s4o.print("("); - symbol->var_name->accept(*this); + if (wanted_variablegeneration == expression_vg) { + unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); + if (vartype == search_var_instance_decl_c::external_vt) { + s4o.print(GET_EXTERNAL); + s4o.print("("); + symbol->var_name->accept(*this); + } + else { + if (vartype == search_var_instance_decl_c::located_vt) + s4o.print(GET_LOCATED); + else + s4o.print(GET_VAR); + s4o.print("("); + generate_c_base_c::visit(symbol); + } + s4o.print(")"); } - else { - if (vartype == search_var_instance_decl_c::located_vt) - s4o.print(GET_LOCATED); - else - s4o.print(GET_VAR); - s4o.print("("); + else generate_c_base_c::visit(symbol); - } - s4o.print(")"); return NULL; } diff -r f332b62cd2c1 -r c6aed7e5f070 stage4/generate_c/generate_c_sfc.cc --- a/stage4/generate_c/generate_c_sfc.cc Tue Dec 01 09:03:33 2009 +0100 +++ b/stage4/generate_c/generate_c_sfc.cc Wed Dec 02 16:11:01 2009 +0100 @@ -398,10 +398,12 @@ s4o.print("__debug_transition_list["); print_transition_number(); s4o.print("],"); + s4o.print(GET_VAR); + s4o.print("("); print_variable_prefix(); s4o.print("__transition_list["); print_transition_number(); - s4o.print("]);\n"); + s4o.print("]));\n"); s4o.indent_left(); s4o.print(s4o.indent_spaces + "}\n"); } diff -r f332b62cd2c1 -r c6aed7e5f070 stage4/generate_c/generate_c_sfcdecl.cc --- a/stage4/generate_c/generate_c_sfcdecl.cc Tue Dec 01 09:03:33 2009 +0100 +++ b/stage4/generate_c/generate_c_sfcdecl.cc Wed Dec 02 16:11:01 2009 +0100 @@ -99,12 +99,12 @@ s4o.print(s4o.indent_spaces + "UINT __nb_actions;\n"); /* transitions table declaration */ - s4o.print(s4o.indent_spaces + "BOOL __transition_list["); + s4o.print(s4o.indent_spaces + "__IEC_BOOL_t __transition_list["); s4o.print_integer(transition_number); s4o.print("];\n"); /* transitions debug table declaration */ - s4o.print(s4o.indent_spaces + "BOOL __debug_transition_list["); + s4o.print(s4o.indent_spaces + "__IEC_BOOL_t __debug_transition_list["); s4o.print_integer(transition_number); s4o.print("];\n"); @@ -128,7 +128,7 @@ wanted_sfcdeclaration = sfcinit_sd; /* steps table initialisation */ - s4o.print(s4o.indent_spaces + "STEP temp_step = {0, 0, 0};\n"); + s4o.print(s4o.indent_spaces + "static const STEP temp_step = {{0, 0}, 0, 0};\n"); s4o.print(s4o.indent_spaces + "for(i = 0; i < "); print_variable_prefix(); s4o.print("__nb_steps; i++) {\n"); @@ -154,7 +154,7 @@ wanted_sfcdeclaration = sfcinit_sd; /* actions table initialisation */ - s4o.print(s4o.indent_spaces + "ACTION temp_action = {0, 0, 0, 0, 0, 0};\n"); + s4o.print(s4o.indent_spaces + "static const ACTION temp_action = {0, 0, 0, 0, 0, 0};\n"); s4o.print(s4o.indent_spaces + "for(i = 0; i < "); print_variable_prefix(); s4o.print("__nb_actions; i++) {\n"); @@ -208,10 +208,12 @@ break; case sfcinit_sd: s4o.print(s4o.indent_spaces); + s4o.print(SET_VAR); + s4o.print("("); print_variable_prefix(); s4o.print("__step_list["); s4o.print_integer(step_number); - s4o.print("].state = 1;\n"); + s4o.print("].state,1);\n"); step_number++; break; case stepdef_sd: diff -r f332b62cd2c1 -r c6aed7e5f070 stage4/generate_c/generate_c_st.cc --- a/stage4/generate_c/generate_c_st.cc Tue Dec 01 09:03:33 2009 +0100 +++ b/stage4/generate_c/generate_c_st.cc Wed Dec 02 16:11:01 2009 +0100 @@ -119,22 +119,19 @@ unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); if (this->is_variable_prefix_null()) { if (wanted_variablegeneration == fparam_output_vg) { - if (vartype == search_var_instance_decl_c::external_vt) { + if (vartype == search_var_instance_decl_c::external_vt) s4o.print(GET_EXTERNAL); - s4o.print("("); - symbol->var_name->accept(*this); - } - else { - s4o.print("&("); - generate_c_base_c::visit(symbol); - } + else + s4o.print("&"); + s4o.print("("); + generate_c_base_c::visit(symbol); s4o.print(")"); } else { if (vartype == search_var_instance_decl_c::external_vt) { s4o.print(GET_EXTERNAL); s4o.print("("); - symbol->var_name->accept(*this); + generate_c_base_c::visit(symbol); s4o.print(")"); } else @@ -144,42 +141,29 @@ else { switch (wanted_variablegeneration) { case expression_vg: - if (vartype == search_var_instance_decl_c::external_vt) { + if (vartype == search_var_instance_decl_c::external_vt) s4o.print(GET_EXTERNAL); - s4o.print("("); - symbol->var_name->accept(*this); - } - else { - if (vartype == search_var_instance_decl_c::located_vt) - s4o.print(GET_LOCATED); - else - s4o.print(GET_VAR); - s4o.print("("); - generate_c_base_c::visit(symbol); - } + else if (vartype == search_var_instance_decl_c::located_vt) + s4o.print(GET_LOCATED); + else + s4o.print(GET_VAR); + s4o.print("("); + generate_c_base_c::visit(symbol); s4o.print(")"); break; case fparam_output_vg: - if (vartype == search_var_instance_decl_c::external_vt) { + if (vartype == search_var_instance_decl_c::external_vt) s4o.print(GET_EXTERNAL_BY_REF); - s4o.print("("); - symbol->var_name->accept(*this); - } - else { - if (vartype == search_var_instance_decl_c::located_vt) - s4o.print(GET_LOCATED_BY_REF); - else - s4o.print(GET_VAR_BY_REF); - s4o.print("("); - generate_c_base_c::visit(symbol); - } + else if (vartype == search_var_instance_decl_c::located_vt) + s4o.print(GET_LOCATED_BY_REF); + else + s4o.print(GET_VAR_BY_REF); + s4o.print("("); + generate_c_base_c::visit(symbol); s4o.print(")"); break; default: - if (vartype == search_var_instance_decl_c::external_vt) - symbol->var_name->accept(*this); - else - generate_c_base_c::visit(symbol); + generate_c_base_c::visit(symbol); break; } } @@ -224,6 +208,67 @@ /* B.1.4.2 Multi-element Variables */ /*************************************/ +// SYM_REF2(structured_variable_c, record_variable, field_selector) +void *visit(structured_variable_c *symbol) { + TRACE("structured_variable_c"); + + unsigned int vartype = search_varfb_instance_type->get_vartype(symbol->record_variable); + if (this->is_variable_prefix_null()) { + symbol->record_variable->accept(*this); + s4o.print("."); + symbol->field_selector->accept(*this); + } + else { + variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration; + switch (wanted_variablegeneration) { + case expression_vg: + wanted_variablegeneration = assignment_vg; + if (vartype == search_var_instance_decl_c::external_vt) { + s4o.print(GET_EXTERNAL); + s4o.print("("); + symbol->record_variable->accept(*this); + s4o.print(")."); + symbol->field_selector->accept(*this); + } + else { + if (vartype == search_var_instance_decl_c::located_vt) + s4o.print(GET_LOCATED); + else + s4o.print(GET_VAR); + s4o.print("("); + symbol->record_variable->accept(*this); + s4o.print("."); + symbol->field_selector->accept(*this); + s4o.print(")"); + } + wanted_variablegeneration = old_wanted_variablegeneration; + break; + case fparam_output_vg: + wanted_variablegeneration = assignment_vg; + s4o.print("&("); + if (vartype == search_var_instance_decl_c::external_vt) + s4o.print(GET_EXTERNAL); + else if (vartype == search_var_instance_decl_c::located_vt) + s4o.print(GET_LOCATED); + else + s4o.print(GET_VAR); + s4o.print("("); + symbol->record_variable->accept(*this); + s4o.print(")."); + symbol->field_selector->accept(*this); + s4o.print("))"); + wanted_variablegeneration = old_wanted_variablegeneration; + break; + default: + symbol->record_variable->accept(*this); + s4o.print("."); + symbol->field_selector->accept(*this); + break; + } + } + return NULL; +} + /* subscripted_variable '[' subscript_list ']' */ //SYM_REF2(array_variable_c, subscripted_variable, subscript_list) void *visit(array_variable_c *symbol) { diff -r f332b62cd2c1 -r c6aed7e5f070 stage4/generate_c/generate_c_typedecl.cc --- a/stage4/generate_c/generate_c_typedecl.cc Tue Dec 01 09:03:33 2009 +0100 +++ b/stage4/generate_c/generate_c_typedecl.cc Wed Dec 02 16:11:01 2009 +0100 @@ -195,13 +195,13 @@ void *visit(subrange_type_declaration_c *symbol) { TRACE("subrange_type_declaration_c"); - s4o_incl.print("typedef "); + s4o_incl.print("__DECLARE_DERIVED_TYPE("); current_basetypedeclaration = subrangebasetype_bd; symbol->subrange_spec_init->accept(*this); current_basetypedeclaration = none_bd; - s4o_incl.print(" "); + s4o_incl.print(", "); symbol->subrange_type_name->accept(*basedecl); - s4o_incl.print(";\n"); + s4o_incl.print(")\n"); current_type_name = symbol->subrange_type_name; @@ -340,16 +340,17 @@ void *visit(array_type_declaration_c *symbol) { TRACE("array_type_declaration_c"); - s4o_incl.print("typedef "); + s4o_incl.print("__DECLARE_ARRAY_TYPE("); current_basetypedeclaration = arraybasetypeincl_bd; symbol->array_spec_init->accept(*this); current_basetypedeclaration = none_bd; - s4o_incl.print(" "); + s4o_incl.print(","); symbol->identifier->accept(*basedecl); + s4o_incl.print(","); current_basetypedeclaration = arraysubrange_bd; symbol->array_spec_init->accept(*this); current_basetypedeclaration = none_bd; - s4o_incl.print(";\n"); + s4o_incl.print(")\n"); if (search_base_type.type_is_subrange(symbol->identifier)) { s4o.print("#define __CHECK_"); @@ -443,11 +444,11 @@ void *visit(simple_type_declaration_c *symbol) { TRACE("simple_type_declaration_c"); - s4o_incl.print("typedef "); + s4o_incl.print("__DECLARE_DERIVED_TYPE"); symbol->simple_spec_init->accept(*this); - s4o_incl.print(" "); + s4o_incl.print(","); symbol->simple_type_name->accept(*basedecl); - s4o_incl.print(";\n"); + s4o_incl.print(");\n"); return NULL; } @@ -515,11 +516,11 @@ void *visit(structure_type_declaration_c *symbol) { TRACE("structure_type_declaration_c"); - s4o_incl.print("typedef "); + s4o_incl.print("__DECLARE_STRUCT_TYPE("); symbol->structure_specification->accept(*this); - s4o_incl.print(" "); + s4o_incl.print(","); symbol->structure_type_name->accept(*basedecl); - s4o_incl.print(";\n"); + s4o_incl.print(");\n"); return NULL; } diff -r f332b62cd2c1 -r c6aed7e5f070 stage4/generate_c/generate_c_vardecl.cc --- a/stage4/generate_c/generate_c_vardecl.cc Tue Dec 01 09:03:33 2009 +0100 +++ b/stage4/generate_c/generate_c_vardecl.cc Wed Dec 02 16:11:01 2009 +0100 @@ -40,8 +40,39 @@ //#include "../../util/symtable.hh" - - +class initialization_analyzer_c: public null_visitor_c { + public: + typedef enum { + simple_it, + array_it, + struct_it + } initialization_type_t; + + private: + + initialization_type_t current_type; + + public: + initialization_analyzer_c(symbol_c* symbol) { + current_type = simple_it; + symbol->accept(*this); + } + ~initialization_analyzer_c(void) {} + + initialization_type_t get_initialization_type(void) { + return current_type; + } + + void *visit(array_initial_elements_list_c *symbol) { + current_type = array_it; + return NULL; + } + + void *visit(structure_element_initialization_list_c *symbol) { + current_type = struct_it; + return NULL; + } +}; class generate_c_array_initialization_c: public generate_c_typedecl_c { @@ -96,6 +127,7 @@ print_integer(dimension_number); s4o.print("];\n"); s4o.print(s4o.indent_spaces); + s4o.print("static const "); array_specification->accept(*this); s4o.print(" temp = "); init_array_values(array_initialization); @@ -124,7 +156,7 @@ if (defined_values_count < array_size) { for (int i = defined_values_count; i < array_size; i++) { if (defined_values_count > 0) - s4o.print(", "); + s4o.print(","); array_default_value->accept(*this); defined_values_count++; } @@ -156,20 +188,23 @@ for (i = 0; i < symbol->n; i++) { s4o.print(s4o.indent_spaces); + s4o.print(SET_VAR); + s4o.print("("); print_variable_prefix(); symbol->elements[i]->accept(*this); + s4o.print(",temp"); for (j = 0; j < dimension_number; j++) { s4o.print("[index["); print_integer(j); s4o.print("]]"); } - s4o.print(" = temp"); + s4o.print(","); for (j = 0; j < dimension_number; j++) { s4o.print("[index["); print_integer(j); s4o.print("]]"); } - s4o.print(";\n"); + s4o.print(");\n"); } return NULL; } @@ -245,15 +280,16 @@ if (defined_values_count >= array_size) ERROR; if (defined_values_count > 0) - s4o.print(", "); + s4o.print(","); symbol->elements[i]->accept(*this); defined_values_count++; } else { array_initial_elements_c *array_initial_element = dynamic_cast(symbol->elements[i]); - if (array_initial_element != NULL) - symbol->elements[i]->accept(*this); + if (array_initial_element != NULL) { + symbol->elements[i]->accept(*this); + } } current_initialization_count++; } @@ -281,7 +317,7 @@ initial_element_number = temp_element_number; if (initial_element_number > 0) { defined_values_count++; - s4o.print(", "); + s4o.print(","); } } else @@ -290,11 +326,13 @@ ERROR; for (int i = 0; i < initial_element_number; i++) { if (i > 0) - s4o.print(", "); - if (symbol->array_initial_element != NULL) + s4o.print(","); + if (symbol->array_initial_element != NULL) { symbol->array_initial_element->accept(*this); - else + } + else { array_default_value->accept(*this); + } } if (initial_element_number > 1) defined_values_count += initial_element_number - 1; @@ -514,6 +552,7 @@ s4o.print(s4o.indent_spaces + "{\n"); s4o.indent_right(); s4o.print(s4o.indent_spaces); + s4o.print("static const "); structure_type_name->accept(*this); s4o.print(" temp = "); structure_initialization->accept(*this); @@ -550,8 +589,10 @@ for (i = 0; i < symbol->n; i++) { s4o.print(s4o.indent_spaces); print_variable_prefix(); + s4o.print(SET_VAR); + s4o.print("("); symbol->elements[i]->accept(*this); - s4o.print(" = temp;\n"); + s4o.print(",temp);\n"); } return NULL; } @@ -583,7 +624,7 @@ structure_init_element_iterator_c structure_init_element_iterator(symbol); for(int i = 1; (element_name = structure_iterator.next()) != NULL; i++) { if (i > 1) - s4o.print(", "); + s4o.print(","); /* Get the value from an initialization */ symbol_c *element_value = structure_init_element_iterator.search(element_name); @@ -604,9 +645,9 @@ if (element_value == NULL) ERROR; - structure_element_initialization_list_c *structure_element_initialization_list = dynamic_cast(element_value); + initialization_analyzer_c initialization_analyzer(element_value); - if (structure_element_initialization_list != NULL) { + if (initialization_analyzer.get_initialization_type() == initialization_analyzer_c::struct_it) { generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); structure_initialization->set_variable_prefix(get_variable_prefix()); structure_initialization->init_structure_default(current_element_type); @@ -614,8 +655,9 @@ element_value->accept(*structure_initialization); delete structure_initialization; } - else + else { element_value->accept(*this); + } } s4o.print("}"); return NULL; @@ -747,6 +789,13 @@ // This, just of itself, will not print out any declarations!! // It must be acompanied by either program_vt and/or global_vt + /* the qualifier of variables that need to be processed... */ + static const unsigned int none_vq = 0x0000; + static const unsigned int constant_vq = 0x0001; // CONSTANT + static const unsigned int retain_vq = 0x0002; // RETAIN + static const unsigned int non_retain_vq = 0x0004; // NON_RETAIN + + /* How variables should be declared: as local variables or * variables within a function call interface. * @@ -813,10 +862,15 @@ /* Only set in the constructor...! */ /* Will contain a set of values of generate_c_vardecl_c::XXXX_vt */ unsigned int wanted_vartype; + /* variable used to store the type of variable currently being processed... */ /* Will contain a single value of generate_c_vardecl_c::XXXX_vt */ unsigned int current_vartype; + /* variable used to store the qualifier of variable currently being processed... */ + /* Will contain a single value of generate_c_vardecl_c::XXXX_vq */ + unsigned int current_varqualifier; + /* How variables should be declared: as local variables or * variables within a function interface... */ @@ -872,6 +926,22 @@ */ symbol_c *globalnamespace; + void *print_retain(void) { + s4o.print(","); + switch (current_varqualifier) { + case retain_vq: + s4o.print("1"); + break; + case non_retain_vq: + s4o.print("0"); + break; + default: + s4o.print("retain"); + break; + } + return NULL; + } + /* Actually produce the output where variables are declared... */ /* Note that located variables and EN/ENO are the exception, they * being declared in the located_var_decl_c, @@ -889,10 +959,15 @@ for(int i = 0; i < list->n; i++) { s4o.print(s4o.indent_spaces); if (wanted_varformat == local_vf) { - s4o.print(DECLARE_VAR); - s4o.print("("); + if (!is_fb) { + s4o.print(DECLARE_VAR); + s4o.print("("); + } this->current_var_type_symbol->accept(*this); - s4o.print(","); + if (is_fb) + s4o.print(" "); + else + s4o.print(","); } else if (wanted_varformat == localinit_vf) { this->current_var_type_symbol->accept(*this); @@ -907,8 +982,10 @@ } s4o.print(";\n"); } + else if (is_fb) + s4o.print(";\n"); else - s4o.print(")\n"); + s4o.print(")\n"); } } @@ -960,6 +1037,7 @@ s4o.print("(&"); this->print_variable_prefix(); list->elements[i]->accept(*this); + print_retain(); s4o.print(");"); } else if (this->current_var_init_symbol != NULL) { @@ -970,6 +1048,7 @@ list->elements[i]->accept(*this); s4o.print(","); this->current_var_init_symbol->accept(*this); + print_retain(); s4o.print(")"); } } @@ -987,6 +1066,7 @@ wanted_varformat = varformat; wanted_vartype = vartype; current_vartype = none_vt; + current_varqualifier = none_vq; current_var_type_symbol = NULL; current_var_init_symbol = NULL; globalnamespace = NULL; @@ -1096,9 +1176,21 @@ /******************************************/ /* B 1.4.3 - Declaration & Initialisation */ /******************************************/ -void *visit(constant_option_c *symbol) {s4o.print("CONSTANT"); return NULL;} -void *visit(retain_option_c *symbol) {s4o.print("RETAIN"); return NULL;} -void *visit(non_retain_option_c *symbol) {s4o.print("NON_RETAIN"); return NULL;} + +void *visit(constant_option_c *symbol) { + current_varqualifier = constant_vq; + return NULL; +} + +void *visit(retain_option_c *symbol) { + current_varqualifier = retain_vq; + return NULL; +} + +void *visit(non_retain_option_c *symbol) { + current_varqualifier = non_retain_vq; + return NULL; +} void *visit(input_declarations_c *symbol) { TRACE("input_declarations_c"); @@ -1110,8 +1202,11 @@ */ //s4o.indent_right(); current_vartype = input_vt; + if (symbol->option != NULL) + symbol->option->accept(*this); symbol->input_declaration_list->accept(*this); current_vartype = none_vt; + current_varqualifier = none_vt; //s4o.indent_left(); } return NULL; @@ -1182,6 +1277,7 @@ symbol->name->accept(*this); s4o.print(","); symbol->value->accept(*this); + print_retain(); s4o.print(")"); } } @@ -1248,7 +1344,9 @@ this->print_variable_prefix(); // s4o.print("ENO = __BOOL_LITERAL(TRUE);"); symbol->name->accept(*this); - s4o.print(",__BOOL_LITERAL(TRUE))"); + s4o.print(",__BOOL_LITERAL(TRUE)"); + print_retain(); + s4o.print(")"); } } return NULL; @@ -1370,8 +1468,11 @@ */ //s4o.indent_right(); current_vartype = output_vt; + if (symbol->option != NULL) + symbol->option->accept(*this); symbol->var_init_decl_list->accept(*this); current_vartype = none_vt; + current_varqualifier = none_vq; //s4o.indent_left(); } return NULL; @@ -1454,8 +1555,11 @@ symbol->option->accept(*this); */ current_vartype = private_vt; + if (symbol->option != NULL) + symbol->option->accept(*this); symbol->var_init_decl_list->accept(*this); current_vartype = none_vt; + current_varqualifier = none_vq; } return NULL; } @@ -1465,8 +1569,10 @@ TRACE("retentive_var_declarations_c"); if ((wanted_vartype & private_vt) != 0) { current_vartype = private_vt; + current_varqualifier = retain_vq; symbol->var_init_decl_list->accept(*this); current_vartype = none_vt; + current_varqualifier = none_vq; } return NULL; } @@ -1483,8 +1589,11 @@ symbol->option->accept(*this); */ current_vartype = located_vt; + if (symbol->option != NULL) + symbol->option->accept(*this); symbol->located_var_decl_list->accept(*this); current_vartype = none_vt; + current_varqualifier = none_vq; } return NULL; } @@ -1542,6 +1651,7 @@ symbol->location->accept(*this); s4o.print(","); print_variable_prefix(); + print_retain(); s4o.print(")\n"); if (this->current_var_init_symbol != NULL) { s4o.print(INIT_LOCATED_VALUE); @@ -1616,8 +1726,11 @@ */ //s4o.indent_right(); current_vartype = external_vt; + if (symbol->option != NULL) + symbol->option->accept(*this); symbol->external_declaration_list->accept(*this); current_vartype = none_vt; + current_varqualifier = none_vq; //s4o.indent_left(); } return NULL; @@ -1671,6 +1784,7 @@ s4o.print(","); print_variable_prefix(); symbol->global_var_name->accept(*this); + print_retain(); s4o.print(")"); break; @@ -1712,8 +1826,11 @@ unsigned int previous_vartype = current_vartype; // previous_vartype will be either none_vt, or resource_vt current_vartype = global_vt; + if (symbol->option != NULL) + symbol->option->accept(*this); symbol->global_var_decl_list->accept(*this); current_vartype = previous_vartype; + current_varqualifier = none_vq; //s4o.indent_left(); } return NULL; @@ -1799,6 +1916,7 @@ symbol->global_var_name->accept(*this); s4o.print(","); symbol->location->accept(*this); + print_retain(); s4o.print(")"); } if (this->current_var_init_symbol != NULL) { @@ -1812,6 +1930,7 @@ symbol->location->accept(*this); s4o.print(","); this->current_var_init_symbol->accept(*this); + print_retain(); s4o.print(")"); } break; @@ -1869,6 +1988,7 @@ list->elements[i]->accept(*this); s4o.print(","); this->current_var_init_symbol->accept(*this); + print_retain(); s4o.print(")"); #if 0 /* The following code would be for globalinit_vf !! diff -r f332b62cd2c1 -r c6aed7e5f070 stage4/generate_c/generate_var_list.cc --- a/stage4/generate_c/generate_var_list.cc Tue Dec 01 09:03:33 2009 +0100 +++ b/stage4/generate_c/generate_var_list.cc Wed Dec 02 16:11:01 2009 +0100 @@ -280,7 +280,7 @@ update_var_type_symbol(symbol->array_spec_init); this->current_var_type_category = array_vtc; - declare_variables(symbol->var1_list); + //declare_variables(symbol->var1_list); /* Values no longer in scope, and therefore no longer used. * Make an effort to keep them set to NULL when not in use @@ -305,7 +305,7 @@ update_var_type_symbol(symbol->initialized_structure); /* now to produce the c equivalent... */ - declare_variables(symbol->var1_list); + //declare_variables(symbol->var1_list); /* Values no longer in scope, and therefore no longer used. * Make an effort to keep them set to NULL when not in use