428 |
428 |
429 /* The number of variables already declared. */ |
429 /* The number of variables already declared. */ |
430 /* Used to declare 'void' in case no variables are declared in a function interface... */ |
430 /* Used to declare 'void' in case no variables are declared in a function interface... */ |
431 int finterface_var_count; |
431 int finterface_var_count; |
432 |
432 |
433 |
433 /* Current parsed resource name, for resource |
|
434 * specific global variable declaration (with #define...)*/ |
|
435 symbol_c *resource_name; |
434 |
436 |
435 /* Holds the references to the type and initial value |
437 /* Holds the references to the type and initial value |
436 * of the variables currently being declared. |
438 * of the variables currently being declared. |
437 * Please read the comment under var1_init_decl_c for further |
439 * Please read the comment under var1_init_decl_c for further |
438 * details... |
440 * details... |
552 |
554 |
553 |
555 |
554 |
556 |
555 |
557 |
556 public: |
558 public: |
557 generate_c_vardecl_c(stage4out_c *s4o_ptr, varformat_t varformat, unsigned int vartype) |
559 generate_c_vardecl_c(stage4out_c *s4o_ptr, varformat_t varformat, unsigned int vartype, symbol_c* res_name = NULL) |
558 : generate_c_typedecl_c(s4o_ptr) { |
560 : generate_c_typedecl_c(s4o_ptr) { |
559 generate_c_array_initialization = new generate_c_array_initialization_c(s4o_ptr); |
561 generate_c_array_initialization = new generate_c_array_initialization_c(s4o_ptr); |
560 wanted_varformat = varformat; |
562 wanted_varformat = varformat; |
561 wanted_vartype = vartype; |
563 wanted_vartype = vartype; |
562 current_vartype = none_vt; |
564 current_vartype = none_vt; |
563 current_var_type_symbol = NULL; |
565 current_var_type_symbol = NULL; |
564 current_var_init_symbol = NULL; |
566 current_var_init_symbol = NULL; |
565 globalnamespace = NULL; |
567 globalnamespace = NULL; |
566 nv = NULL; |
568 nv = NULL; |
|
569 resource_name = res_name; |
567 } |
570 } |
568 |
571 |
569 ~generate_c_vardecl_c(void) { |
572 ~generate_c_vardecl_c(void) { |
570 delete generate_c_array_initialization; |
573 delete generate_c_array_initialization; |
571 } |
574 } |
1204 s4o.print("* "); |
1207 s4o.print("* "); |
1205 symbol->location->accept(*this); |
1208 symbol->location->accept(*this); |
1206 s4o.print(";\n"); |
1209 s4o.print(";\n"); |
1207 this->current_var_type_symbol->accept(*this); |
1210 this->current_var_type_symbol->accept(*this); |
1208 s4o.print(" *"); |
1211 s4o.print(" *"); |
|
1212 if (this->resource_name != NULL) { |
|
1213 this->resource_name->accept(*this); |
|
1214 s4o.print("__"); |
|
1215 } |
1209 symbol->global_var_name->accept(*this); |
1216 symbol->global_var_name->accept(*this); |
1210 s4o.print(";\n"); |
1217 s4o.print(";\n"); |
|
1218 if (this->resource_name != NULL) { |
|
1219 s4o.print("#define "); |
|
1220 symbol->global_var_name->accept(*this); |
|
1221 s4o.print(" "); |
|
1222 this->resource_name->accept(*this); |
|
1223 s4o.print("__"); |
|
1224 symbol->global_var_name->accept(*this); |
|
1225 s4o.print("\n"); |
|
1226 } |
1211 } |
1227 } |
1212 break; |
1228 break; |
1213 |
1229 |
1214 case constructorinit_vf: |
1230 case constructorinit_vf: |
1215 s4o.print(nv->get()); |
1231 s4o.print(nv->get()); |
1262 case local_vf: |
1278 case local_vf: |
1263 case localinit_vf: |
1279 case localinit_vf: |
1264 for(int i = 0; i < list->n; i++) { |
1280 for(int i = 0; i < list->n; i++) { |
1265 s4o.print(s4o.indent_spaces); |
1281 s4o.print(s4o.indent_spaces); |
1266 this->current_var_type_symbol->accept(*this); |
1282 this->current_var_type_symbol->accept(*this); |
1267 s4o.print(" __"); |
1283 s4o.print(" "); |
|
1284 if(this->resource_name != NULL) |
|
1285 this->resource_name->accept(*this); |
|
1286 s4o.print("__"); |
1268 list->elements[i]->accept(*this); |
1287 list->elements[i]->accept(*this); |
1269 s4o.print(";\n"); |
1288 s4o.print(";\n"); |
|
1289 if(this->resource_name != NULL) |
|
1290 s4o.print("static "); |
1270 this->current_var_type_symbol->accept(*this); |
1291 this->current_var_type_symbol->accept(*this); |
1271 s4o.print(" *"); |
1292 s4o.print(" *"); |
1272 list->elements[i]->accept(*this); |
1293 list->elements[i]->accept(*this); |
1273 s4o.print(" = &__"); |
1294 s4o.print(" = &"); |
|
1295 if(this->resource_name != NULL) |
|
1296 this->resource_name->accept(*this); |
|
1297 s4o.print("__"); |
1274 list->elements[i]->accept(*this); |
1298 list->elements[i]->accept(*this); |
1275 #if 0 |
1299 #if 0 |
1276 if (wanted_varformat == localinit_vf) { |
1300 if (wanted_varformat == localinit_vf) { |
1277 if (this->current_var_init_symbol != NULL) { |
1301 if (this->current_var_init_symbol != NULL) { |
1278 s4o.print(" = "); |
1302 s4o.print(" = "); |
1595 END_RESOURCE |
1619 END_RESOURCE |
1596 */ |
1620 */ |
1597 // SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
1621 // SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
1598 void *visit(resource_declaration_c *symbol) { |
1622 void *visit(resource_declaration_c *symbol) { |
1599 TRACE("resource_declaration_c"); |
1623 TRACE("resource_declaration_c"); |
1600 |
1624 //// Not used anymore. Even resource list are processed as single resource |
1601 if ((wanted_vartype & resource_vt) != 0) { |
1625 // if ((wanted_vartype & resource_vt) != 0) { |
1602 s4o.print(s4o.indent_spaces + "struct {\n"); |
1626 // s4o.print(s4o.indent_spaces + "struct {\n"); |
1603 s4o.indent_right(); |
1627 // s4o.indent_right(); |
1604 |
1628 // |
1605 current_vartype = resource_vt; |
1629 // current_vartype = resource_vt; |
1606 if (NULL != symbol->global_var_declarations) |
1630 // if (NULL != symbol->global_var_declarations) |
1607 symbol->global_var_declarations->accept(*this); // will contain VAR_GLOBAL declarations!! |
1631 // symbol->global_var_declarations->accept(*this); // will contain VAR_GLOBAL declarations!! |
1608 if (NULL != symbol->resource_declaration) |
1632 // if (NULL != symbol->resource_declaration) |
1609 symbol->resource_declaration->accept(*this); // will contain PROGRAM declarations!! |
1633 // symbol->resource_declaration->accept(*this); // will contain PROGRAM declarations!! |
1610 current_vartype = none_vt; |
1634 // current_vartype = none_vt; |
1611 |
1635 // |
1612 s4o.indent_left(); |
1636 // s4o.indent_left(); |
1613 s4o.print(s4o.indent_spaces + "} "); |
1637 // s4o.print(s4o.indent_spaces + "} "); |
1614 symbol->resource_name->accept(*this); |
1638 // symbol->resource_name->accept(*this); |
1615 s4o.print(";\n"); |
1639 // s4o.print(";\n"); |
1616 } |
1640 // } |
1617 return NULL; |
1641 return NULL; |
1618 } |
1642 } |
1619 |
1643 |
1620 /* task_configuration_list program_configuration_list */ |
1644 /* task_configuration_list program_configuration_list */ |
1621 // SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
1645 // SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |