247 if (current_initialization_count >= defined_values_count) { |
247 if (current_initialization_count >= defined_values_count) { |
248 if (defined_values_count >= array_size) |
248 if (defined_values_count >= array_size) |
249 ERROR; |
249 ERROR; |
250 if (defined_values_count > 0) |
250 if (defined_values_count > 0) |
251 s4o.print(","); |
251 s4o.print(","); |
252 symbol->elements[i]->accept(*this); |
252 symbol->get_element(i)->accept(*this); |
253 defined_values_count++; |
253 defined_values_count++; |
254 } |
254 } |
255 else { |
255 else { |
256 array_initial_elements_c *array_initial_element = dynamic_cast<array_initial_elements_c *>(symbol->elements[i]); |
256 array_initial_elements_c *array_initial_element = dynamic_cast<array_initial_elements_c *>(symbol->get_element(i)); |
257 |
257 |
258 if (array_initial_element != NULL) { |
258 if (array_initial_element != NULL) { |
259 symbol->elements[i]->accept(*this); |
259 symbol->get_element(i)->accept(*this); |
260 } |
260 } |
261 } |
261 } |
262 current_initialization_count++; |
262 current_initialization_count++; |
263 } |
263 } |
264 break; |
264 break; |
412 /* helper symbol for structure_declaration */ |
412 /* helper symbol for structure_declaration */ |
413 /* structure_element_declaration_list structure_element_declaration ';' */ |
413 /* structure_element_declaration_list structure_element_declaration ';' */ |
414 void *visit(structure_element_declaration_list_c *symbol) { |
414 void *visit(structure_element_declaration_list_c *symbol) { |
415 void *res; |
415 void *res; |
416 for (int i = 0; i < symbol->n; i++) { |
416 for (int i = 0; i < symbol->n; i++) { |
417 res = symbol->elements[i]->accept(*this); |
417 res = symbol->get_element(i)->accept(*this); |
418 if (res != NULL) |
418 if (res != NULL) |
419 return res; |
419 return res; |
420 } |
420 } |
421 return NULL; |
421 return NULL; |
422 } |
422 } |
470 /* helper symbol for structure_initialization */ |
470 /* helper symbol for structure_initialization */ |
471 /* structure_element_initialization_list ',' structure_element_initialization */ |
471 /* structure_element_initialization_list ',' structure_element_initialization */ |
472 void *visit(structure_element_initialization_list_c *symbol) { |
472 void *visit(structure_element_initialization_list_c *symbol) { |
473 void *res; |
473 void *res; |
474 for (int i = 0; i < symbol->n; i++) { |
474 for (int i = 0; i < symbol->n; i++) { |
475 res = symbol->elements[i]->accept(*this); |
475 res = symbol->get_element(i)->accept(*this); |
476 if (res != NULL) |
476 if (res != NULL) |
477 return res; |
477 return res; |
478 } |
478 } |
479 return NULL; |
479 return NULL; |
480 } |
480 } |
972 void print_fb_explicit_initial_values(symbol_c *fbvar_name, symbol_c *init_values_list) { |
972 void print_fb_explicit_initial_values(symbol_c *fbvar_name, symbol_c *init_values_list) { |
973 structure_element_initialization_list_c *init_list = dynamic_cast<structure_element_initialization_list_c *>(init_values_list); |
973 structure_element_initialization_list_c *init_list = dynamic_cast<structure_element_initialization_list_c *>(init_values_list); |
974 if (NULL == init_list) ERROR; |
974 if (NULL == init_list) ERROR; |
975 |
975 |
976 for (int i = 0; i < init_list->n; i++) { |
976 for (int i = 0; i < init_list->n; i++) { |
977 structure_element_initialization_c *init_list_elem = dynamic_cast<structure_element_initialization_c *>(init_list->elements[i]); |
977 structure_element_initialization_c *init_list_elem = dynamic_cast<structure_element_initialization_c *>(init_list->get_element(i)); |
978 if (NULL == init_list_elem) ERROR; |
978 if (NULL == init_list_elem) ERROR; |
979 s4o.print("\n"); |
979 s4o.print("\n"); |
980 s4o.print(s4o.indent_spaces); |
980 s4o.print(s4o.indent_spaces); |
981 s4o.print(INIT_VAR); |
981 s4o.print(INIT_VAR); |
982 s4o.print("("); |
982 s4o.print("("); |
1028 s4o.print(SET_VAR); |
1028 s4o.print(SET_VAR); |
1029 s4o.print("("); |
1029 s4o.print("("); |
1030 print_variable_prefix(); |
1030 print_variable_prefix(); |
1031 s4o.print(","); |
1031 s4o.print(","); |
1032 } |
1032 } |
1033 list->elements[i]->accept(*this); |
1033 list->get_element(i)->accept(*this); |
1034 if (wanted_varformat != local_vf) { |
1034 if (wanted_varformat != local_vf) { |
1035 if (wanted_varformat == localinit_vf && |
1035 if (wanted_varformat == localinit_vf && |
1036 (current_vartype & inoutput_vt) != 0) { |
1036 (current_vartype & inoutput_vt) != 0) { |
1037 s4o.print(";\n"); |
1037 s4o.print(";\n"); |
1038 s4o.print(s4o.indent_spaces); |
1038 s4o.print(s4o.indent_spaces); |
1039 s4o.print("if (__"); |
1039 s4o.print("if (__"); |
1040 list->elements[i]->accept(*this); |
1040 list->get_element(i)->accept(*this); |
1041 s4o.print(" != NULL) {\n"); |
1041 s4o.print(" != NULL) {\n"); |
1042 s4o.indent_right(); |
1042 s4o.indent_right(); |
1043 s4o.print(s4o.indent_spaces); |
1043 s4o.print(s4o.indent_spaces); |
1044 list->elements[i]->accept(*this); |
1044 list->get_element(i)->accept(*this); |
1045 s4o.print(" = *__"); |
1045 s4o.print(" = *__"); |
1046 list->elements[i]->accept(*this); |
1046 list->get_element(i)->accept(*this); |
1047 s4o.print(";\n"); |
1047 s4o.print(";\n"); |
1048 s4o.indent_left(); |
1048 s4o.indent_left(); |
1049 s4o.print(s4o.indent_spaces); |
1049 s4o.print(s4o.indent_spaces); |
1050 s4o.print("}\n"); |
1050 s4o.print("}\n"); |
1051 s4o.print(s4o.indent_spaces); |
1051 s4o.print(s4o.indent_spaces); |
1056 this->current_var_type_symbol->accept(*this); |
1056 this->current_var_type_symbol->accept(*this); |
1057 s4o.print(" temp = "); |
1057 s4o.print(" temp = "); |
1058 this->current_var_init_symbol->accept(*this); |
1058 this->current_var_init_symbol->accept(*this); |
1059 s4o.print(";\n"); |
1059 s4o.print(";\n"); |
1060 s4o.print(s4o.indent_spaces); |
1060 s4o.print(s4o.indent_spaces); |
1061 list->elements[i]->accept(*this); |
1061 list->get_element(i)->accept(*this); |
1062 s4o.print(" = temp;\n"); |
1062 s4o.print(" = temp;\n"); |
1063 s4o.indent_left(); |
1063 s4o.indent_left(); |
1064 s4o.print(s4o.indent_spaces); |
1064 s4o.print(s4o.indent_spaces); |
1065 s4o.print("}\n"); |
1065 s4o.print("}\n"); |
1066 } |
1066 } |
1092 this->current_var_type_symbol->accept(*this); |
1092 this->current_var_type_symbol->accept(*this); |
1093 if ((current_vartype & (output_vt | inoutput_vt)) != 0) |
1093 if ((current_vartype & (output_vt | inoutput_vt)) != 0) |
1094 s4o.print(" *__"); |
1094 s4o.print(" *__"); |
1095 else |
1095 else |
1096 s4o.print(" "); |
1096 s4o.print(" "); |
1097 list->elements[i]->accept(*this); |
1097 list->get_element(i)->accept(*this); |
1098 /* We do not print the initial value at function declaration! |
1098 /* We do not print the initial value at function declaration! |
1099 * It is up to the caller to pass the correct default value |
1099 * It is up to the caller to pass the correct default value |
1100 * if none is specified in the ST source code |
1100 * if none is specified in the ST source code |
1101 */ |
1101 */ |
1102 /* if (this->current_var_init_symbol != NULL) { |
1102 /* if (this->current_var_init_symbol != NULL) { |
1107 |
1107 |
1108 if (wanted_varformat == foutputassign_vf) { |
1108 if (wanted_varformat == foutputassign_vf) { |
1109 for(int i = 0; i < list->n; i++) { |
1109 for(int i = 0; i < list->n; i++) { |
1110 if ((current_vartype & (output_vt | inoutput_vt)) != 0) { |
1110 if ((current_vartype & (output_vt | inoutput_vt)) != 0) { |
1111 s4o.print(s4o.indent_spaces + "if (__"); |
1111 s4o.print(s4o.indent_spaces + "if (__"); |
1112 list->elements[i]->accept(*this); |
1112 list->get_element(i)->accept(*this); |
1113 s4o.print(" != NULL) {\n"); |
1113 s4o.print(" != NULL) {\n"); |
1114 s4o.indent_right(); |
1114 s4o.indent_right(); |
1115 s4o.print(s4o.indent_spaces + "*__"); |
1115 s4o.print(s4o.indent_spaces + "*__"); |
1116 list->elements[i]->accept(*this); |
1116 list->get_element(i)->accept(*this); |
1117 s4o.print(" = "); |
1117 s4o.print(" = "); |
1118 list->elements[i]->accept(*this); |
1118 list->get_element(i)->accept(*this); |
1119 s4o.print(";\n"); |
1119 s4o.print(";\n"); |
1120 s4o.indent_left(); |
1120 s4o.indent_left(); |
1121 s4o.print(s4o.indent_spaces + "}\n"); |
1121 s4o.print(s4o.indent_spaces + "}\n"); |
1122 } |
1122 } |
1123 } |
1123 } |
1137 s4o.print(nv->get()); |
1137 s4o.print(nv->get()); |
1138 this->current_var_type_symbol->accept(*this); |
1138 this->current_var_type_symbol->accept(*this); |
1139 s4o.print(FB_INIT_SUFFIX); |
1139 s4o.print(FB_INIT_SUFFIX); |
1140 s4o.print("(&"); |
1140 s4o.print("(&"); |
1141 this->print_variable_prefix(); |
1141 this->print_variable_prefix(); |
1142 list->elements[i]->accept(*this); |
1142 list->get_element(i)->accept(*this); |
1143 print_retain(); |
1143 print_retain(); |
1144 s4o.print(");"); |
1144 s4o.print(");"); |
1145 if (this->current_var_init_symbol != NULL) { |
1145 if (this->current_var_init_symbol != NULL) { |
1146 /* This FB instance declaration includes an explicit initialiser list |
1146 /* This FB instance declaration includes an explicit initialiser list |
1147 * e.g. VAR my_fb : FB_typ := (var1 := 42, var2 := 'hello'); END_VAR |
1147 * e.g. VAR my_fb : FB_typ := (var1 := 42, var2 := 'hello'); END_VAR |
1150 * FB variables one by one... |
1150 * FB variables one by one... |
1151 * The generated C code will lokk something like: |
1151 * The generated C code will lokk something like: |
1152 * __INIT_VAR(data__->my_fb.var1, __INT_LITERAL(42), retain); |
1152 * __INIT_VAR(data__->my_fb.var1, __INT_LITERAL(42), retain); |
1153 * __INIT_VAR(data__->my_fb.var1, __STRING_LITERAL("hello"), retain); |
1153 * __INIT_VAR(data__->my_fb.var1, __STRING_LITERAL("hello"), retain); |
1154 */ |
1154 */ |
1155 print_fb_explicit_initial_values(list->elements[i], this->current_var_init_symbol); |
1155 print_fb_explicit_initial_values(list->get_element(i), this->current_var_init_symbol); |
1156 } |
1156 } |
1157 } |
1157 } |
1158 else if (this->current_var_init_symbol != NULL) { |
1158 else if (this->current_var_init_symbol != NULL) { |
1159 s4o.print(nv->get()); |
1159 s4o.print(nv->get()); |
1160 s4o.print(INIT_VAR); |
1160 s4o.print(INIT_VAR); |
1161 s4o.print("("); |
1161 s4o.print("("); |
1162 this->print_variable_prefix(); |
1162 this->print_variable_prefix(); |
1163 list->elements[i]->accept(*this); |
1163 list->get_element(i)->accept(*this); |
1164 s4o.print(","); |
1164 s4o.print(","); |
1165 this->current_var_init_symbol->accept(*this); |
1165 this->current_var_init_symbol->accept(*this); |
1166 print_retain(); |
1166 print_retain(); |
1167 s4o.print(")"); |
1167 s4o.print(")"); |
1168 } |
1168 } |
2155 this->current_var_type_symbol->accept(*this); |
2155 this->current_var_type_symbol->accept(*this); |
2156 s4o.print(","); |
2156 s4o.print(","); |
2157 if(this->resource_name != NULL) |
2157 if(this->resource_name != NULL) |
2158 this->resource_name->accept(*this); |
2158 this->resource_name->accept(*this); |
2159 s4o.print(","); |
2159 s4o.print(","); |
2160 list->elements[i]->accept(*this); |
2160 list->get_element(i)->accept(*this); |
2161 s4o.print(")\n"); |
2161 s4o.print(")\n"); |
2162 } |
2162 } |
2163 break; |
2163 break; |
2164 |
2164 |
2165 case constructorinit_vf: |
2165 case constructorinit_vf: |
2172 else |
2172 else |
2173 s4o.print(INIT_GLOBAL); |
2173 s4o.print(INIT_GLOBAL); |
2174 s4o.print("("); |
2174 s4o.print("("); |
2175 this->current_var_type_symbol->accept(*this); |
2175 this->current_var_type_symbol->accept(*this); |
2176 s4o.print(","); |
2176 s4o.print(","); |
2177 list->elements[i]->accept(*this); |
2177 list->get_element(i)->accept(*this); |
2178 if (this->current_var_init_symbol != NULL) { |
2178 if (this->current_var_init_symbol != NULL) { |
2179 s4o.print(","); |
2179 s4o.print(","); |
2180 s4o.print(INITIAL_VALUE); |
2180 s4o.print(INITIAL_VALUE); |
2181 s4o.print("("); |
2181 s4o.print("("); |
2182 this->current_var_init_symbol->accept(*this); |
2182 this->current_var_init_symbol->accept(*this); |
2194 s4o.print("> "); |
2194 s4o.print("> "); |
2195 if (this->globalnamespace != NULL) { |
2195 if (this->globalnamespace != NULL) { |
2196 this->globalnamespace->accept(*this); |
2196 this->globalnamespace->accept(*this); |
2197 s4o.print("::"); |
2197 s4o.print("::"); |
2198 } |
2198 } |
2199 list->elements[i]->accept(*this); |
2199 list->get_element(i)->accept(*this); |
2200 |
2200 |
2201 if (this->current_var_init_symbol != NULL) { |
2201 if (this->current_var_init_symbol != NULL) { |
2202 s4o.print(" = "); |
2202 s4o.print(" = "); |
2203 s4o.print("__ext_element_c<"); |
2203 s4o.print("__ext_element_c<"); |
2204 this->current_var_type_symbol->accept(*this); |
2204 this->current_var_type_symbol->accept(*this); |