Adding support for internal variable call generating
authorlbessard
Fri, 11 May 2007 16:29:22 +0200
changeset 25 e6a841e365b7
parent 24 7e830409f72a
child 26 fd67f54e64e1
Adding support for internal variable call generating
stage4/generate_cc/generate_cc_st.cc
stage4/generate_cc/search_var_instance_decl.cc
stage4/generate_cc/search_varfb_instance_type.cc
--- a/stage4/generate_cc/generate_cc_st.cc	Fri May 11 11:55:24 2007 +0200
+++ b/stage4/generate_cc/generate_cc_st.cc	Fri May 11 16:29:22 2007 +0200
@@ -66,17 +66,21 @@
      */
     search_expression_type_c *search_expression_type;
 
+    search_varfb_instance_type_c *search_varfb_instance_type;
+
   public:
     generate_cc_st_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL)
     : generate_cc_typedecl_c(s4o_ptr) {
       search_fb_instance_decl = new search_fb_instance_decl_c(scope);
       search_expression_type = new search_expression_type_c(scope);
+      search_varfb_instance_type = new search_varfb_instance_type_c(scope);
       this->set_variable_prefix(variable_prefix);
     }
 
     virtual ~generate_cc_st_c(void) {
       delete search_fb_instance_decl;
       delete search_expression_type;
+      delete search_varfb_instance_type;
     }
 
 
@@ -121,7 +125,23 @@
     }
 
   private:
-  
+
+/*********************/
+/* 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("*(");
+    generate_cc_base_c::visit(symbol);
+    s4o.print(")");
+  }
+  else {
+    generate_cc_base_c::visit(symbol);
+  }
+  return NULL;
+}
+
 /***************************************/
 /* B.3 - Language ST (Structured Text) */
 /***************************************/
--- a/stage4/generate_cc/search_var_instance_decl.cc	Fri May 11 11:55:24 2007 +0200
+++ b/stage4/generate_cc/search_var_instance_decl.cc	Fri May 11 16:29:22 2007 +0200
@@ -58,9 +58,14 @@
     symbol_c *search_scope;
     symbol_c *search_name;
     symbol_c *current_type_decl;
+    
+    /* variable used to store the type of variable currently being processed... */
+    /* Will contain a single value of generate_cc_vardecl_c::XXXX_vt */
+    unsigned int current_vartype;
 
   public:
     search_var_instance_decl_c(symbol_c *search_scope) {
+      this->current_vartype = none_vt;
       this->search_scope = search_scope;
       this->search_name = NULL;
       this->current_type_decl = NULL;
@@ -71,7 +76,23 @@
       return (symbol_c *)search_scope->accept(*this);
     }
 
+    unsigned int get_vartype() {
+      return current_vartype;
+    }
+
   public:
+  
+    /* the types of variables that need to be processed... */
+    static const unsigned int none_vt   = 0x0000;
+    static const unsigned int input_vt    = 0x0001;  // VAR_INPUT
+    static const unsigned int output_vt   = 0x0002;  // VAR_OUTPUT
+    static const unsigned int inoutput_vt = 0x0004;  // VAR_IN_OUT
+    static const unsigned int private_vt  = 0x0008;  // VAR
+    static const unsigned int temp_vt   = 0x0010;  // VAR_TEMP
+    static const unsigned int external_vt = 0x0020;  // VAR_EXTERNAL
+    static const unsigned int located_vt  = 0x0080;  // VAR <var_name> AT <location>
+
+
 /***************************/
 /* B 0 - Programming Model */
 /***************************/
@@ -91,6 +112,82 @@
 // SYM_REF2(edge_declaration_c, edge, var1_list)
 // TODO
 
+    void *visit(input_declarations_c *symbol) {
+      current_vartype = input_vt;
+      void *res = symbol->input_declaration_list->accept(*this);
+      if (res == NULL) {
+        current_vartype = none_vt;
+      }
+      return res;
+    }
+
+/* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */
+/* option -> may be NULL ! */
+    void *visit(output_declarations_c *symbol) {
+      current_vartype = output_vt;
+      void *res = symbol->var_init_decl_list->accept(*this);
+      if (res == NULL) {
+        current_vartype = none_vt;
+      }
+      return res;
+    }
+
+/*  VAR_IN_OUT var_declaration_list END_VAR */
+    void *visit(input_output_declarations_c *symbol) {
+      current_vartype = inoutput_vt;
+      void *res = symbol->var_declaration_list->accept(*this);
+      if (res == NULL) {
+        current_vartype = none_vt;
+      }
+      return res;
+    }
+
+/* VAR [CONSTANT] var_init_decl_list END_VAR */
+/* option -> may be NULL ! */
+/* helper symbol for input_declarations */
+    void *visit(var_declarations_c *symbol) {
+      current_vartype = private_vt;
+      void *res = symbol->var_init_decl_list->accept(*this);
+      if (res == NULL) {
+        current_vartype = none_vt;
+      }
+      return NULL;
+    }
+
+/*  VAR RETAIN var_init_decl_list END_VAR */
+    void *visit(retentive_var_declarations_c *symbol) {
+      current_vartype = private_vt;
+      void *res = symbol->var_init_decl_list->accept(*this);
+      if (res == NULL) {
+        current_vartype = none_vt;
+      }
+      return NULL;
+    }
+
+/*  VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */
+/* option -> may be NULL ! */
+//SYM_REF2(located_var_declarations_c, option, located_var_decl_list)
+    void *visit(located_var_declarations_c *symbol) {
+      current_vartype = located_vt;
+      void *res = symbol->located_var_decl_list->accept(*this);
+      if (res == NULL) {
+        current_vartype = none_vt;
+      }
+      return NULL;
+    }
+
+/*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */
+/* option -> may be NULL ! */
+//SYM_REF2(external_var_declarations_c, option, external_declaration_list)
+    void *visit(external_var_declarations_c *symbol) {
+      current_vartype = external_vt;
+      void *res = symbol->external_declaration_list->accept(*this);
+      if (res == NULL) {
+        current_vartype = none_vt;
+      }
+      return NULL;
+    }
+
 /* var1_list is one of the following...
  *    simple_spec_init_c *
  *    subrange_spec_init_c *
--- a/stage4/generate_cc/search_varfb_instance_type.cc	Fri May 11 11:55:24 2007 +0200
+++ b/stage4/generate_cc/search_varfb_instance_type.cc	Fri May 11 16:29:22 2007 +0200
@@ -75,7 +75,7 @@
       symbol_c *var_decl = search_var_instance_decl.get_decl(var_name_part);
       if (NULL == var_decl) {
         /* variable instance declaration not found! */
- 	return NULL;
+ 	      return NULL;
       }
 
       /* if it is a struct or function block, we must search the type
@@ -94,6 +94,40 @@
       return res;
     }
 
+    unsigned int get_vartype(symbol_c *variable_name) {
+      this->current_structelement_name = NULL;
+      this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name);
+      if (NULL == decompose_var_instance_name) ERROR;
+
+      /* find the part of the variable name that will appear in the
+       * variable declaration, for e.g., in window.point.x, this would be
+       * window!
+       */
+      symbol_c *var_name_part = decompose_var_instance_name->next_part();
+      if (NULL == var_name_part) ERROR;
+
+      /* Now we try to find the variable instance declaration, to determine its type... */
+      symbol_c *var_decl = search_var_instance_decl.get_decl(var_name_part);
+      if (NULL == var_decl) {
+        /* variable instance declaration not found! */
+        return 0;
+      }
+
+      /* if it is a struct or function block, we must search the type
+       * of the struct or function block member.
+       * This is done by this class visiting the var_decl.
+       * This class, while visiting, will recursively call
+       * decompose_var_instance_name->get_next() when and if required...
+       */
+      unsigned int res = search_var_instance_decl.get_vartype();
+      
+      /* make sure that we have decomposed all strcuture elements of the variable name */
+      symbol_c *var_name = decompose_var_instance_name->next_part();
+      if (NULL != var_name) ERROR;
+
+      return res;
+    }
+
   private:
     /* a helper function... */
     void *visit_list(list_c *list)	{