equal
deleted
inserted
replaced
343 static const unsigned int located_vt = 0x0080; // VAR <var_name> AT <location> |
343 static const unsigned int located_vt = 0x0080; // VAR <var_name> AT <location> |
344 static const unsigned int program_vt = 0x0100; // PROGRAM (inside a configuration!) |
344 static const unsigned int program_vt = 0x0100; // PROGRAM (inside a configuration!) |
345 // Programs declared inside a resource will not be declared |
345 // Programs declared inside a resource will not be declared |
346 // unless program_vt is acompanied by resource_vt |
346 // unless program_vt is acompanied by resource_vt |
347 |
347 |
|
348 static const unsigned int eneno_vt = 0x0200; // EN/ENO declaration |
|
349 |
348 static const unsigned int resource_vt = 0x8000; // RESOURCE (inside a configuration!) |
350 static const unsigned int resource_vt = 0x8000; // RESOURCE (inside a configuration!) |
349 // This, just of itself, will not print out any declarations!! |
351 // This, just of itself, will not print out any declarations!! |
350 // It must be acompanied by either program_vt and/or global_vt |
352 // It must be acompanied by either program_vt and/or global_vt |
351 |
353 |
352 /* How variables should be declared: as local variables or |
354 /* How variables should be declared: as local variables or |
399 * |
401 * |
400 * e.g. |
402 * e.g. |
401 * __plc_pt_c<INT, 8*sizeof(INT)> START_P::loc = __plc_pt_c<INT, 8*sizeof(INT)>("I2"); |
403 * __plc_pt_c<INT, 8*sizeof(INT)> START_P::loc = __plc_pt_c<INT, 8*sizeof(INT)>("I2"); |
402 */ |
404 */ |
403 typedef enum {finterface_vf, |
405 typedef enum {finterface_vf, |
404 foutputdecl_vf, |
|
405 foutputassign_vf, |
406 foutputassign_vf, |
406 local_vf, |
407 local_vf, |
407 localinit_vf, |
408 localinit_vf, |
408 init_vf, |
409 init_vf, |
409 constructorinit_vf, |
410 constructorinit_vf, |
433 int finterface_var_count; |
434 int finterface_var_count; |
434 |
435 |
435 /* Current parsed resource name, for resource |
436 /* Current parsed resource name, for resource |
436 * specific global variable declaration (with #define...)*/ |
437 * specific global variable declaration (with #define...)*/ |
437 symbol_c *resource_name; |
438 symbol_c *resource_name; |
|
439 |
|
440 /* Store if En and ENO parameters have been defined by user */ |
|
441 bool en_declared; |
|
442 bool eno_declared; |
438 |
443 |
439 /* Holds the references to the type and initial value |
444 /* Holds the references to the type and initial value |
440 * of the variables currently being declared. |
445 * of the variables currently being declared. |
441 * Please read the comment under var1_init_decl_c for further |
446 * Please read the comment under var1_init_decl_c for further |
442 * details... |
447 * details... |
527 s4o.print(" = "); this->current_var_init_symbol->accept(*this);} |
532 s4o.print(" = "); this->current_var_init_symbol->accept(*this);} |
528 */ |
533 */ |
529 } |
534 } |
530 } |
535 } |
531 |
536 |
532 if (wanted_varformat == foutputdecl_vf) { |
|
533 for(int i = 0; i < list->n; i++) { |
|
534 if ((current_vartype & (output_vt | inoutput_vt)) != 0) { |
|
535 s4o.print(s4o.indent_spaces); |
|
536 this->current_var_type_symbol->accept(*this); |
|
537 s4o.print(" "); |
|
538 list->elements[i]->accept(*this); |
|
539 s4o.print(";\n"); |
|
540 } |
|
541 } |
|
542 } |
|
543 |
|
544 if (wanted_varformat == foutputassign_vf) { |
537 if (wanted_varformat == foutputassign_vf) { |
545 for(int i = 0; i < list->n; i++) { |
538 for(int i = 0; i < list->n; i++) { |
546 if ((current_vartype & (output_vt | inoutput_vt)) != 0) { |
539 if ((current_vartype & (output_vt | inoutput_vt)) != 0) { |
547 s4o.print(s4o.indent_spaces + "if (__"); |
540 s4o.print(s4o.indent_spaces + "if (__"); |
548 list->elements[i]->accept(*this); |
541 list->elements[i]->accept(*this); |
597 current_var_type_symbol = NULL; |
590 current_var_type_symbol = NULL; |
598 current_var_init_symbol = NULL; |
591 current_var_init_symbol = NULL; |
599 globalnamespace = NULL; |
592 globalnamespace = NULL; |
600 nv = NULL; |
593 nv = NULL; |
601 resource_name = res_name; |
594 resource_name = res_name; |
|
595 en_declared = false; |
|
596 eno_declared = false; |
602 } |
597 } |
603 |
598 |
604 ~generate_c_vardecl_c(void) { |
599 ~generate_c_vardecl_c(void) { |
605 delete generate_c_array_initialization; |
600 delete generate_c_array_initialization; |
606 } |
601 } |
607 |
602 |
|
603 bool is_en_declared(void) { |
|
604 return en_declared; |
|
605 } |
|
606 |
|
607 bool is_eno_declared(void) { |
|
608 return eno_declared; |
|
609 } |
608 |
610 |
609 void print(symbol_c *symbol, symbol_c *scope = NULL, const char *variable_prefix = NULL) { |
611 void print(symbol_c *symbol, symbol_c *scope = NULL, const char *variable_prefix = NULL) { |
610 this->set_variable_prefix(variable_prefix); |
612 this->set_variable_prefix(variable_prefix); |
611 this->generate_c_array_initialization->set_variable_prefix(variable_prefix); |
613 this->generate_c_array_initialization->set_variable_prefix(variable_prefix); |
612 if (globalinit_vf == wanted_varformat) |
614 if (globalinit_vf == wanted_varformat) |
745 TRACE("edge_declaration_c"); |
747 TRACE("edge_declaration_c"); |
746 // TO DO ... |
748 // TO DO ... |
747 symbol->var1_list->accept(*this); |
749 symbol->var1_list->accept(*this); |
748 s4o.print(" : BOOL "); |
750 s4o.print(" : BOOL "); |
749 symbol->edge->accept(*this); |
751 symbol->edge->accept(*this); |
|
752 return NULL; |
|
753 } |
|
754 |
|
755 void *visit(en_param_declaration_c *symbol) { |
|
756 TRACE("en_declaration_c"); |
|
757 if (en_declared) ERROR; |
|
758 if (wanted_varformat == finterface_vf) { |
|
759 finterface_var_count++; |
|
760 } |
|
761 if ((current_vartype & eneno_vt) != 0) { |
|
762 if (wanted_varformat == finterface_vf) { |
|
763 s4o.print(nv->get()); |
|
764 s4o.print("\n" + s4o.indent_spaces + "BOOL EN"); |
|
765 } |
|
766 if (wanted_varformat == constructorinit_vf) { |
|
767 s4o.print(nv->get()); |
|
768 this->print_variable_prefix(); |
|
769 s4o.print("ENO = __BOOL_LITERAL(TRUE);"); |
|
770 } |
|
771 } |
|
772 en_declared = true; |
750 return NULL; |
773 return NULL; |
751 } |
774 } |
752 |
775 |
753 void *visit(raising_edge_option_c *symbol) { |
776 void *visit(raising_edge_option_c *symbol) { |
754 // TO DO ... |
777 // TO DO ... |
856 current_vartype = output_vt; |
879 current_vartype = output_vt; |
857 symbol->var_init_decl_list->accept(*this); |
880 symbol->var_init_decl_list->accept(*this); |
858 current_vartype = none_vt; |
881 current_vartype = none_vt; |
859 //s4o.indent_left(); |
882 //s4o.indent_left(); |
860 } |
883 } |
|
884 return NULL; |
|
885 } |
|
886 |
|
887 void *visit(eno_param_declaration_c *symbol) { |
|
888 TRACE("eno_declaration_c"); |
|
889 if (eno_declared) ERROR; |
|
890 if (wanted_varformat == finterface_vf) { |
|
891 finterface_var_count++; |
|
892 } |
|
893 if ((current_vartype & eneno_vt) != 0) { |
|
894 if (wanted_varformat == finterface_vf) { |
|
895 s4o.print(nv->get()); |
|
896 s4o.print("\n" + s4o.indent_spaces + "BOOL *EN0"); |
|
897 } |
|
898 if (wanted_varformat == constructorinit_vf) { |
|
899 s4o.print(nv->get()); |
|
900 this->print_variable_prefix(); |
|
901 s4o.print("ENO = __BOOL_LITERAL(TRUE);"); |
|
902 } |
|
903 } |
|
904 eno_declared = true; |
861 return NULL; |
905 return NULL; |
862 } |
906 } |
863 |
907 |
864 /* VAR_IN_OUT var_declaration_list END_VAR */ |
908 /* VAR_IN_OUT var_declaration_list END_VAR */ |
865 void *visit(input_output_declarations_c *symbol) { |
909 void *visit(input_output_declarations_c *symbol) { |