Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
authormjsousa
Sat, 08 Feb 2014 18:33:32 +0000
changeset 858 c5f145364a4f
parent 857 70c4c259bc3e
child 859 41d11bacfc9b
Fix get_datatype_info_c::is_subrange(), which did not work when using base type! (we now use get_equivtype() instead of get_base_type() )
absyntax_utils/get_datatype_info.cc
absyntax_utils/search_base_type.cc
absyntax_utils/search_base_type.hh
--- a/absyntax_utils/get_datatype_info.cc	Sat Feb 08 10:48:20 2014 +0000
+++ b/absyntax_utils/get_datatype_info.cc	Sat Feb 08 18:33:32 2014 +0000
@@ -292,7 +292,7 @@
 
 
 bool get_datatype_info_c::is_subrange(symbol_c *type_symbol) {
-  symbol_c *type_decl = search_base_type_c::get_basetype_decl(type_symbol); /* NOTE: will work correctly once we update the way search_base_type_c works, by adding a new search_effective_type:c */
+  symbol_c *type_decl = search_base_type_c::get_equivtype_decl(type_symbol); /* NOTE: do NOT call search_base_type_c !! */
   if (NULL == type_decl)                                             {return false;}
   
   if (typeid(*type_decl) == typeid(subrange_type_declaration_c))     {return true;}   /*  subrange_type_name ':' subrange_spec_init */
--- a/absyntax_utils/search_base_type.cc	Sat Feb 08 10:48:20 2014 +0000
+++ b/absyntax_utils/search_base_type.cc	Sat Feb 08 18:33:32 2014 +0000
@@ -54,7 +54,7 @@
 
 
 
-search_base_type_c::search_base_type_c(void) {current_type_name = NULL; current_basetype = NULL;}
+search_base_type_c::search_base_type_c(void) {current_basetype_name = NULL; current_basetype = NULL; current_equivtype = NULL;}
 
 /* static method! */
 void search_base_type_c::create_singleton(void) {
@@ -63,11 +63,25 @@
 }
 
 /* static method! */
+symbol_c *search_base_type_c::get_equivtype_decl(symbol_c *symbol) {
+  create_singleton();
+  if (NULL == symbol)    return NULL; 
+  search_base_type_singleton->current_basetype_name = NULL;
+  search_base_type_singleton->current_basetype  = NULL; 
+  search_base_type_singleton->current_equivtype = NULL; 
+  symbol_c *basetype = (symbol_c *)symbol->accept(*search_base_type_singleton);
+  if (NULL != search_base_type_singleton->current_equivtype)
+    return search_base_type_singleton->current_equivtype;
+  return basetype;
+}
+
+/* static method! */
 symbol_c *search_base_type_c::get_basetype_decl(symbol_c *symbol) {
   create_singleton();
   if (NULL == symbol)    return NULL; 
-  search_base_type_singleton->current_type_name = NULL;
+  search_base_type_singleton->current_basetype_name = NULL;
   search_base_type_singleton->current_basetype  = NULL; 
+  search_base_type_singleton->current_equivtype = NULL; 
   return (symbol_c *)symbol->accept(*search_base_type_singleton);
 }
 
@@ -75,10 +89,11 @@
 symbol_c *search_base_type_c::get_basetype_id  (symbol_c *symbol) {
   create_singleton();
   if (NULL == symbol)    return NULL; 
-  search_base_type_singleton->current_type_name = NULL;
+  search_base_type_singleton->current_basetype_name = NULL;
   search_base_type_singleton->current_basetype  = NULL; 
+  search_base_type_singleton->current_equivtype = NULL; 
   symbol->accept(*search_base_type_singleton);
-  return (symbol_c *)search_base_type_singleton->current_type_name;
+  return (symbol_c *)search_base_type_singleton->current_basetype_name;
 }
 
 
@@ -93,7 +108,7 @@
 void *search_base_type_c::visit(identifier_c *type_name) {
   symbol_c *type_decl;
 
-  this->current_type_name = type_name;
+  this->current_basetype_name = type_name;
   /* if we have reached this point, it is because the current_basetype is not yet pointing to the base datatype we are looking for,
    * so we will be searching for the delcaration of the type named in type_name, which might be the base datatype (we search recursively!)
    */
@@ -210,16 +225,21 @@
 
 /*  subrange_type_name ':' subrange_spec_init */
 void *search_base_type_c::visit(subrange_type_declaration_c *symbol) {
+  this->current_equivtype = symbol;
   return symbol->subrange_spec_init->accept(*this);
 }
 
 /* subrange_specification ASSIGN signed_integer */
 void *search_base_type_c::visit(subrange_spec_init_c *symbol) {
+  if (NULL == this->current_equivtype)
+    this->current_equivtype = symbol;
   return symbol->subrange_specification->accept(*this);
 }
 
 /*  integer_type_name '(' subrange')' */
 void *search_base_type_c::visit(subrange_specification_c *symbol) {
+  if (NULL == this->current_equivtype)
+    this->current_equivtype = symbol;
   return symbol->integer_type_name->accept(*this);
 }
 
@@ -228,7 +248,7 @@
 
 /*  enumerated_type_name ':' enumerated_spec_init */
 void *search_base_type_c::visit(enumerated_type_declaration_c *symbol) {
-  this->current_type_name = symbol->enumerated_type_name;
+  this->current_basetype_name = symbol->enumerated_type_name;
   /* NOTE: We want search_base_type_c to return a enumerated_type_declaration_c as the base datatpe if possible
    *       (i.e. if it is a named datatype declared inside a TYPE ... END_TYPE declarations, as opposed to an
    *        anonymous datatype declared in a VAR ... AND_VAR declaration).
@@ -266,7 +286,7 @@
 
 /*  identifier ':' array_spec_init */
 void *search_base_type_c::visit(array_type_declaration_c *symbol) {
-  this->current_type_name = symbol->identifier;
+  this->current_basetype_name = symbol->identifier;
   return symbol->array_spec_init->accept(*this);
 }
 
@@ -303,7 +323,7 @@
  *       structure_element_declaration_list_c
  */
 void *search_base_type_c::visit(structure_type_declaration_c *symbol)  {
-  this->current_type_name = symbol->structure_type_name;
+  this->current_basetype_name = symbol->structure_type_name;
   return symbol->structure_specification->accept(*this);
 }
 
@@ -370,14 +390,14 @@
 /* INITIAL_STEP step_name ':' action_association_list END_STEP */
 // SYM_REF2(initial_step_c, step_name, action_association_list)
 void *search_base_type_c::visit(initial_step_c *symbol) {
-  this->current_type_name = NULL; /* this pseudo data type does not have a type name! */
+  this->current_basetype_name = NULL; /* this pseudo data type does not have a type name! */
   return (void *)symbol;
 }
 
 /* STEP step_name ':' action_association_list END_STEP */
 // SYM_REF2(step_c, step_name, action_association_list)
 void *search_base_type_c::visit(step_c *symbol) {
-  this->current_type_name = NULL; /* this pseudo data type does not have a type name! */
+  this->current_basetype_name = NULL; /* this pseudo data type does not have a type name! */
   return (void *)symbol;
 }
 
--- a/absyntax_utils/search_base_type.hh	Sat Feb 08 10:48:20 2014 +0000
+++ b/absyntax_utils/search_base_type.hh	Sat Feb 08 18:33:32 2014 +0000
@@ -31,19 +31,35 @@
  */
 
 
-/* Determine the data type on which another data type is based on.
- * If a new default initial value is given, we DO NOT consider it a
- * new base class, and continue looking further!
- *
- * E.g. TYPE new_int_t : INT; END_TYPE;
- *      TYPE new_int2_t : INT = 2; END_TYPE;
- *      TYPE new_subr_t : INT (4..5); END_TYPE;
- *
- *    new_int_t is really an INT!!
- *    new_int2_t is also really an INT!!
- *    new_subr_t is also really an INT!!
- *
- * Note that a FB declaration is also considered a base type, as
+/* Determine the data type on which another data type is based on. */
+
+/*
+ * What is a Base Type?
+ *    A base type is the fundamental data type from which the type is derived.
+ *    The main idea is that if two datatyes (A and B) share a common base type, 
+ *    then these two datatypes may be used interchangeably in an expression.
+ * 
+ * What is an Equivalent Type? 
+ *    An equivalent type is the data type from which the type is derived.
+ *    The Base type and the Equivalent type will always be the same, with the
+ *    exception of subranges!
+ *
+ * E.g. TYPE new_int_t  : INT; END_TYPE;
+ *      TYPE new_int2_t : INT := 2; END_TYPE;
+ *      TYPE new_int3_t : new_int2_t := 3; END_TYPE;
+ *      TYPE new_sub_t  : INT (4..10); END_TYPE;
+ *      TYPE new_sub2_t : new_sub_t  := 5 ; END_TYPE;
+ *      TYPE new_sub3_t : new_sub2_t := 6 ; END_TYPE;
+ *      TYPE new_sub4_t : new_int3_t (4..10); END_TYPE;    <-----  This is NOT legal syntax!
+ *
+ *    new_int_t   : base type->INT          equivalent type->INT
+ *    new_int2_t  : base type->INT          equivalent type->INT
+ *    new_int3_t  : base type->INT          equivalent type->INT
+ *    new_sub_t   : base type->INT          equivalent type->new_sub_t
+ *    new_sub2_t  : base type->INT          equivalent type->new_sub_t
+ *    new_sub3_t  : base type->INT          equivalent type->new_sub_t
+ *
+ * Note too that a FB declaration is also considered a base type, as
  * we may have FB instances declared of a specific FB type.
  */
 
@@ -51,8 +67,9 @@
 class search_base_type_c: public null_visitor_c {
 
   private:
-    symbol_c *current_type_name;
+    symbol_c *current_basetype_name;
     symbol_c *current_basetype;
+    symbol_c *current_equivtype;
     static search_base_type_c *search_base_type_singleton; // Make this a singleton class!
     
   private:  
@@ -60,8 +77,9 @@
 
   public:
     search_base_type_c(void);
-    static symbol_c *get_basetype_decl (symbol_c *symbol);
-    static symbol_c *get_basetype_id   (symbol_c *symbol);
+    static symbol_c *get_equivtype_decl(symbol_c *symbol);  /* get the Equivalent Type declaration */
+    static symbol_c *get_basetype_decl (symbol_c *symbol);  /* get the Base       Type declaration */
+    static symbol_c *get_basetype_id   (symbol_c *symbol);  /* get the Base       Type identifier  */
 
   public:
   /*************************/