Add better comments, and change name of functions to clarify what they do.
authorMario de Sousa <msousa@fe.up.pt>
Tue, 14 Jun 2011 14:53:37 +0100
changeset 321 a96399ab57c2
parent 320 4df13059b982
child 322 293967b9277d
child 324 f763383992c9
Add better comments, and change name of functions to clarify what they do.
absyntax_utils/search_expression_type.cc
absyntax_utils/search_varfb_instance_type.cc
absyntax_utils/search_varfb_instance_type.hh
stage3/visit_expression_type.cc
stage4/generate_c/generate_c_il.cc
stage4/generate_c/generate_c_inlinefcall.cc
stage4/generate_c/generate_c_st.cc
--- a/absyntax_utils/search_expression_type.cc	Fri Jun 10 08:47:38 2011 +0100
+++ b/absyntax_utils/search_expression_type.cc	Tue Jun 14 14:53:37 2011 +0100
@@ -231,7 +231,7 @@
   symbol_c *res;
   
   /* Nope, now we assume it is a variable, and determine its type... */
-  res = search_varfb_instance_type->get_type(symbol);
+  res = search_varfb_instance_type->get_basetype_decl(symbol);
   if (NULL != res) return res;
   
   return NULL;
@@ -244,7 +244,7 @@
   symbol_c *res;
   
   /* Nope, now we assume it is a variable, and determine its type... */
-  res = search_varfb_instance_type->get_type(symbol);
+  res = search_varfb_instance_type->get_basetype_decl(symbol);
   if (NULL != res) return res;
   
   return NULL;
@@ -258,7 +258,7 @@
   symbol_c *res;
   
   /* Nope, now we assume it is a variable, and determine its type... */
-  res = search_varfb_instance_type->get_type(symbol);
+  res = search_varfb_instance_type->get_basetype_decl(symbol);
   if (NULL != res) return res;
   
   return NULL;
@@ -268,7 +268,7 @@
   symbol_c *res;
   
   /* Nope, now we assume it is a variable, and determine its type... */
-  res = search_varfb_instance_type->get_type(symbol);
+  res = search_varfb_instance_type->get_basetype_decl(symbol);
   if (NULL != res) return res;
   
   return NULL;
--- a/absyntax_utils/search_varfb_instance_type.cc	Fri Jun 10 08:47:38 2011 +0100
+++ b/absyntax_utils/search_varfb_instance_type.cc	Tue Jun 14 14:53:37 2011 +0100
@@ -37,13 +37,6 @@
  * A mixture of array element of a structure element of a structure element
  * of a .... is also suported!
  *
- * A reference to the relevant base type __definition__ is returned.
- * This means that if we find that the variable is of type MY_INT,
- * which was previously declared to be
- * TYPE MY_INT: INT := 9;
- * this class wil return INT, and __not__ MY_INT !!
- *
- *
  *  example:
  *    window.points[1].coordinate.x
  *    window.points[1].colour
@@ -51,7 +44,44 @@
  *
  * This class must be passed the scope within which the
  * variable was declared, and the variable name...
- */
+ *
+ *
+ *
+ *
+ *
+ * This class has several members, depending on the exact data the caller
+ * is looking for...
+ *
+ *    - item i: we can get either the name of the data type(A),
+ *              or it's declaration (B)
+ *             (notice however that some variables belong to a data type that does
+ *              not have a name, only a declaration as in
+ *              VAR a: ARRAY [1..3] of INT; END_VAR
+ *             )
+ *    - item ii: we can get either the direct data type (1), 
+ *               or the base type (2)
+ * 
+ *   By direct type, I mean the data type of the variable. By base type, I 
+ * mean the data type on which the direct type is based on. For example, in 
+ * a subrange on INT, the direct type is the subrange itself, while the 
+ * base type is INT.
+ * e.g.
+ *   This means that if we find that the variable is of type MY_INT,
+ *   which was previously declared to be
+ *   TYPE MY_INT: INT := 9;
+ *   option (1) will return MY_INT
+ *   option (2) will return INT
+ * 
+ *
+ * Member functions:
+ * ================
+ *   get_basetype_decl()  ---> returns 2B 
+ *   get_type_id()        ---> returns 1A
+ * 
+ *   Since we haven't yet needed them, we don't yet implement
+ *   get_basetype_id()    ----> would return 2A
+ *   get_type_decl()      ----> would return 1B
+ */ 
 
 
 /*
@@ -67,7 +97,7 @@
   this->current_rawtype = NULL;
 }
 
-symbol_c *search_varfb_instance_type_c::get_type(symbol_c *variable_name) {
+symbol_c *search_varfb_instance_type_c::get_basetype_decl(symbol_c *variable_name) {
   this->current_structelement_name = NULL;
   this->current_rawtype = NULL;
   this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name);
@@ -140,8 +170,8 @@
   return res;
 }
 
-symbol_c *search_varfb_instance_type_c::get_rawtype(symbol_c *variable_name) {
-  symbol_c *rawtype = this->get_type(variable_name);
+symbol_c *search_varfb_instance_type_c::get_type_id(symbol_c *variable_name) {
+  symbol_c *rawtype = this->get_basetype_decl(variable_name);
   if (this->current_rawtype != NULL)
     return this->current_rawtype;
   else
--- a/absyntax_utils/search_varfb_instance_type.hh	Fri Jun 10 08:47:38 2011 +0100
+++ b/absyntax_utils/search_varfb_instance_type.hh	Tue Jun 14 14:53:37 2011 +0100
@@ -39,13 +39,6 @@
  * A mixture of array element of a structure element of a structure element
  * of a .... is also suported!
  *
- * A reference to the relevant base type __definition__ is returned.
- * This means that if we find that the variable is of type MY_INT,
- * which was previously declared to be
- * TYPE MY_INT: INT := 9;
- * this class wil return INT, and __not__ MY_INT !!
- *
- *
  *  example:
  *    window.points[1].coordinate.x
  *    window.points[1].colour
@@ -53,7 +46,44 @@
  *
  * This class must be passed the scope within which the
  * variable was declared, and the variable name...
- */
+ *
+ *
+ *
+ *
+ *
+ * This class has several members, depending on the exact data the caller
+ * is looking for...
+ *
+ *    - item i: we can get either the name of the data type(A),
+ *              or it's declaration (B)
+ *             (notice however that some variables belong to a data type that does
+ *              not have a name, only a declaration as in
+ *              VAR a: ARRAY [1..3] of INT; END_VAR
+ *             )
+ *    - item ii: we can get either the direct data type (1), 
+ *               or the base type (2)
+ * 
+ *   By direct type, I mean the data type of the variable. By base type, I 
+ * mean the data type on which the direct type is based on. For example, in 
+ * a subrange on INT, the direct type is the subrange itself, while the 
+ * base type is INT.
+ * e.g.
+ *   This means that if we find that the variable is of type MY_INT,
+ *   which was previously declared to be
+ *   TYPE MY_INT: INT := 9;
+ *   option (1) will return MY_INT
+ *   option (2) will return INT
+ * 
+ *
+ * Member functions:
+ * ================
+ *   get_basetype_decl()  ---> returns 2B 
+ *   get_type_id()        ---> returns 1A
+ * 
+ *   Since we haven't yet needed them, we don't yet implement
+ *   get_basetype_id()    ----> would return 2A
+ *   get_type_decl()      ----> would return 1B
+ */ 
 
 class search_varfb_instance_type_c: public search_base_type_c {
 
@@ -66,8 +96,8 @@
 
   public:
     search_varfb_instance_type_c(symbol_c *search_scope);
-    symbol_c *get_type(symbol_c *variable_name);
-    symbol_c *get_rawtype(symbol_c *variable_name);
+    symbol_c *get_basetype_decl(symbol_c *variable_name);
+    symbol_c *get_type_id(symbol_c *variable_name);
 
     unsigned int get_vartype(symbol_c *variable_name);
     bool type_is_complex(void);
--- a/stage3/visit_expression_type.cc	Fri Jun 10 08:47:38 2011 +0100
+++ b/stage3/visit_expression_type.cc	Tue Jun 14 14:53:37 2011 +0100
@@ -910,7 +910,7 @@
 /*********************/
 
 void *visit_expression_type_c::visit(symbolic_variable_c *symbol) {
-  return search_varfb_instance_type->get_type(symbol);
+  return search_varfb_instance_type->get_basetype_decl(symbol);
 }
 
 /********************************************/
@@ -937,11 +937,11 @@
 /* B 1.4.2 - Multi-element variables */
 /*************************************/
 void *visit_expression_type_c::visit(array_variable_c *symbol) {
-  return search_varfb_instance_type->get_type(symbol);
+  return search_varfb_instance_type->get_basetype_decl(symbol);
 }
 
 void *visit_expression_type_c::visit(structured_variable_c *symbol) {
-  return search_varfb_instance_type->get_type(symbol);
+  return search_varfb_instance_type->get_basetype_decl(symbol);
 }
 
 
@@ -1130,12 +1130,12 @@
    *         fb1(...)
    *       End_Program
    *
-   *    search_varfb_instance_type->get_type( identifier_c("fb1") )
+   *    search_varfb_instance_type->get_basetype_decl( identifier_c("fb1") )
    *    in the scope of Program 'test'
    *    will return the fb declaration of foo_fb_type !!
    */
 #if 0
-  symbol_c *fb_decl_symbol = search_varfb_instance_type->get_type(symbol->fb_name);
+  symbol_c *fb_decl_symbol = search_varfb_instance_type->get_basetype_decl(symbol->fb_name);
     /* The following should never occur. The function block must be defined, 
      * and the FB type being called MUST be in the symtable... 
      * This was all already checked at stage 2!
@@ -1146,7 +1146,7 @@
     /* should never occur. ... */
   if (NULL == fb_decl) ERROR;
 #endif
-  symbol_c *fb_decl = search_varfb_instance_type->get_type(symbol->fb_name);
+  symbol_c *fb_decl = search_varfb_instance_type->get_basetype_decl(symbol->fb_name);
     /* The following should never occur. The function block must be defined, 
      * and the FB type being called MUST be in the symtable... 
      * This was all already checked at stage 2!
@@ -2040,7 +2040,7 @@
 /* param_assignment_list -> may be NULL ! */
 // SYM_REF3(fb_invocation_c, fb_name, formal_param_list, nonformal_param_list)
 void *visit_expression_type_c::visit(fb_invocation_c *symbol) {
-  symbol_c *fb_decl = search_varfb_instance_type->get_type(symbol->fb_name);
+  symbol_c *fb_decl = search_varfb_instance_type->get_basetype_decl(symbol->fb_name);
     /* The following should never occur. The function block must be defined, 
      * and the FB type being called MUST be in the symtable... 
      * This was all already checked at stage 2!
--- a/stage4/generate_c/generate_c_il.cc	Fri Jun 10 08:47:38 2011 +0100
+++ b/stage4/generate_c/generate_c_il.cc	Tue Jun 14 14:53:37 2011 +0100
@@ -647,7 +647,7 @@
     case complextype_suffix_vg:
       symbol->subscripted_variable->accept(*this);
 
-      current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable);
+      current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable);
       if (current_array_type == NULL) ERROR;
 
       s4o.print(".table");
@@ -659,7 +659,7 @@
       if (this->is_variable_prefix_null()) {
         symbol->subscripted_variable->accept(*this);
 
-        current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable);
+        current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable);
         if (current_array_type == NULL) ERROR;
 
         s4o.print(".table");
@@ -1120,7 +1120,7 @@
     if (param_value != NULL)
       if ((param_direction == function_param_iterator_c::direction_out) ||
           (param_direction == function_param_iterator_c::direction_inout)) {
-        symbol_c *param_type = search_varfb_instance_type->get_rawtype(param_value);
+        symbol_c *param_type = search_varfb_instance_type->get_type_id(param_value);
         s4o.print(";\n" + s4o.indent_spaces);
         if (this->is_variable_prefix_null()) {
           param_value->accept(*this);
@@ -1479,7 +1479,7 @@
 }
 
 void *visit(ST_operator_c *symbol)	{
-  symbol_c *operand_type = search_varfb_instance_type->get_rawtype(this->current_operand);
+  symbol_c *operand_type = search_varfb_instance_type->get_type_id(this->current_operand);
   if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type) ||
   	  search_expression_type->is_literal_real_type(this->default_variable_name.current_type))
       this->default_variable_name.current_type = this->current_operand_type;
@@ -1496,7 +1496,7 @@
 }
 
 void *visit(STN_operator_c *symbol)	{
-  symbol_c *operand_type = search_varfb_instance_type->get_rawtype(this->current_operand);
+  symbol_c *operand_type = search_varfb_instance_type->get_type_id(this->current_operand);
   if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type))
 	this->default_variable_name.current_type = this->current_operand_type;
   
--- a/stage4/generate_c/generate_c_inlinefcall.cc	Fri Jun 10 08:47:38 2011 +0100
+++ b/stage4/generate_c/generate_c_inlinefcall.cc	Tue Jun 14 14:53:37 2011 +0100
@@ -312,7 +312,7 @@
         case complextype_suffix_vg:
           symbol->subscripted_variable->accept(*this);
 
-          current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable);
+          current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable);
           if (current_array_type == NULL) ERROR;
 
           s4o.print(".table");
--- a/stage4/generate_c/generate_c_st.cc	Fri Jun 10 08:47:38 2011 +0100
+++ b/stage4/generate_c/generate_c_st.cc	Tue Jun 14 14:53:37 2011 +0100
@@ -305,7 +305,7 @@
     case complextype_suffix_vg:
       symbol->subscripted_variable->accept(*this);
 
-      current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable);
+      current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable);
       if (current_array_type == NULL) ERROR;
 
       s4o.print(".table");
@@ -319,7 +319,7 @@
       if (this->is_variable_prefix_null()) {
     	symbol->subscripted_variable->accept(*this);
 
-    	current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable);
+    	current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable);
     	if (current_array_type == NULL) ERROR;
 
     	s4o.print(".table");
@@ -789,7 +789,7 @@
 /* B 3.2.1 Assignment Statements */
 /*********************************/
 void *visit(assignment_statement_c *symbol) {
-  symbol_c *left_type = search_varfb_instance_type->get_rawtype(symbol->l_exp);
+  symbol_c *left_type = search_varfb_instance_type->get_type_id(symbol->l_exp);
   
   if (this->is_variable_prefix_null()) {
     symbol->l_exp->accept(*this);
@@ -893,7 +893,7 @@
     if (param_value != NULL)
       if ((param_direction == function_param_iterator_c::direction_out) ||
           (param_direction == function_param_iterator_c::direction_inout)) {
-        symbol_c *param_type = search_varfb_instance_type->get_rawtype(param_value);
+        symbol_c *param_type = search_varfb_instance_type->get_type_id(param_value);
         s4o.print(";\n" + s4o.indent_spaces);
         if (this->is_variable_prefix_null()) {
           param_value->accept(*this);