Added RETAIN qualifier to VARIABLES.CSV
authorEdouard Tisserant
Tue, 14 Dec 2021 09:02:38 +0100
changeset 1097 520a4b937f13
parent 1096 fad6e7a818e2
child 1098 84bbafb4fb26
Added RETAIN qualifier to VARIABLES.CSV
stage4/generate_c/generate_var_list.cc
--- a/stage4/generate_c/generate_var_list.cc	Tue Dec 14 08:48:05 2021 +0100
+++ b/stage4/generate_c/generate_var_list.cc	Tue Dec 14 09:02:38 2021 +0100
@@ -238,7 +238,8 @@
     bool configuration_defined;
     std::list<SYMBOL> current_symbol_list;
     search_type_symbol_c *search_type_symbol;
-    
+    unsigned int is_retain;
+
   public:
     generate_var_list_c(stage4out_c *s4o_ptr, symbol_c *scope)
     : generate_c_base_and_typeid_c(s4o_ptr) {
@@ -248,6 +249,7 @@
       current_var_type_name = NULL;
       current_declarationtype = none_dt;
       current_var_class_category = none_vcc;
+      is_retain = 0;
     }
     
     ~generate_var_list_c(void) {
@@ -345,7 +347,9 @@
         case search_type_symbol_c::structure_vtc:
         case search_type_symbol_c::function_block_vtc:
           this->current_var_type_name->accept(*this);
-          s4o.print(";;\n");
+          s4o.print(";;");
+          print_retain();
+          s4o.print(";\n");
           if (this->current_var_class_category != external_vcc) {
               SYMBOL *current_name;
               symbol_c *tmp_var_type;
@@ -360,7 +364,9 @@
           break;
         case search_type_symbol_c::array_vtc:
           this->current_var_type_name->accept(*this);
-          s4o.print(";;\n");
+          s4o.print(";;");
+          print_retain();
+          s4o.print(";\n");
           break;
         default:
           // base type name
@@ -368,10 +374,18 @@
           s4o.print(";");
           // type name (eventualy derived)
           this->current_var_type_name->accept(*this);
+          s4o.print(";");
+          print_retain();
           s4o.print(";\n");
           break;
       }
     }
+    void print_retain() {
+      if(is_retain)
+          s4o.print("1");
+      else
+          s4o.print("0");
+    }
 
     void print_var_number(void) {
       char str[10];
@@ -444,6 +458,54 @@
 /* B.1.4.3 - Declaration and initialization */
 /********************************************/
     
+    void *visit(retain_option_c *symbol) {
+      is_retain = 1;
+      return NULL;
+    }
+
+    void *visit(non_retain_option_c *symbol) {
+      is_retain = 0;
+      return NULL;
+    }
+
+    /* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */
+    void *visit(output_declarations_c *symbol) {
+      unsigned int was_retain = is_retain;
+      if (symbol->option != NULL)
+        symbol->option->accept(*this);
+      symbol->var_init_decl_list->accept(*this);
+      is_retain = was_retain;
+      return NULL;
+    }
+
+    /*  VAR RETAIN var_init_decl_list END_VAR */
+    void *visit(retentive_var_declarations_c *symbol) {
+      unsigned int was_retain = is_retain;
+      symbol->var_init_decl_list->accept(*this);
+      is_retain = was_retain;
+      return NULL;
+    }
+
+    /*  VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */
+    void *visit(located_var_declarations_c *symbol) {
+      unsigned int was_retain = is_retain;
+      if (symbol->option != NULL)
+        symbol->option->accept(*this);
+      symbol->located_var_decl_list->accept(*this);
+      is_retain = was_retain;
+      return NULL;
+    }
+
+    /* VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */
+    void *visit(global_var_declarations_c *symbol) {
+      unsigned int was_retain = is_retain;
+      if (symbol->option != NULL)
+        symbol->option->accept(*this);
+      symbol->global_var_decl_list->accept(*this);
+      is_retain = was_retain;
+      return NULL;
+    }
+
     /*  [variable_name] location ':' located_var_spec_init */
     /* variable_name -> may be NULL ! */
     //SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused)