absyntax_utils/search_base_type.hh
changeset 858 c5f145364a4f
parent 854 13d0b67de111
child 909 8b2a31dea131
equal deleted inserted replaced
857:70c4c259bc3e 858:c5f145364a4f
    29  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
    29  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
    30  *
    30  *
    31  */
    31  */
    32 
    32 
    33 
    33 
    34 /* Determine the data type on which another data type is based on.
    34 /* Determine the data type on which another data type is based on. */
    35  * If a new default initial value is given, we DO NOT consider it a
    35 
    36  * new base class, and continue looking further!
    36 /*
    37  *
    37  * What is a Base Type?
    38  * E.g. TYPE new_int_t : INT; END_TYPE;
    38  *    A base type is the fundamental data type from which the type is derived.
    39  *      TYPE new_int2_t : INT = 2; END_TYPE;
    39  *    The main idea is that if two datatyes (A and B) share a common base type, 
    40  *      TYPE new_subr_t : INT (4..5); END_TYPE;
    40  *    then these two datatypes may be used interchangeably in an expression.
    41  *
    41  * 
    42  *    new_int_t is really an INT!!
    42  * What is an Equivalent Type? 
    43  *    new_int2_t is also really an INT!!
    43  *    An equivalent type is the data type from which the type is derived.
    44  *    new_subr_t is also really an INT!!
    44  *    The Base type and the Equivalent type will always be the same, with the
    45  *
    45  *    exception of subranges!
    46  * Note that a FB declaration is also considered a base type, as
    46  *
       
    47  * E.g. TYPE new_int_t  : INT; END_TYPE;
       
    48  *      TYPE new_int2_t : INT := 2; END_TYPE;
       
    49  *      TYPE new_int3_t : new_int2_t := 3; END_TYPE;
       
    50  *      TYPE new_sub_t  : INT (4..10); END_TYPE;
       
    51  *      TYPE new_sub2_t : new_sub_t  := 5 ; END_TYPE;
       
    52  *      TYPE new_sub3_t : new_sub2_t := 6 ; END_TYPE;
       
    53  *      TYPE new_sub4_t : new_int3_t (4..10); END_TYPE;    <-----  This is NOT legal syntax!
       
    54  *
       
    55  *    new_int_t   : base type->INT          equivalent type->INT
       
    56  *    new_int2_t  : base type->INT          equivalent type->INT
       
    57  *    new_int3_t  : base type->INT          equivalent type->INT
       
    58  *    new_sub_t   : base type->INT          equivalent type->new_sub_t
       
    59  *    new_sub2_t  : base type->INT          equivalent type->new_sub_t
       
    60  *    new_sub3_t  : base type->INT          equivalent type->new_sub_t
       
    61  *
       
    62  * Note too that a FB declaration is also considered a base type, as
    47  * we may have FB instances declared of a specific FB type.
    63  * we may have FB instances declared of a specific FB type.
    48  */
    64  */
    49 
    65 
    50 
    66 
    51 class search_base_type_c: public null_visitor_c {
    67 class search_base_type_c: public null_visitor_c {
    52 
    68 
    53   private:
    69   private:
    54     symbol_c *current_type_name;
    70     symbol_c *current_basetype_name;
    55     symbol_c *current_basetype;
    71     symbol_c *current_basetype;
       
    72     symbol_c *current_equivtype;
    56     static search_base_type_c *search_base_type_singleton; // Make this a singleton class!
    73     static search_base_type_c *search_base_type_singleton; // Make this a singleton class!
    57     
    74     
    58   private:  
    75   private:  
    59     static void create_singleton(void);
    76     static void create_singleton(void);
    60 
    77 
    61   public:
    78   public:
    62     search_base_type_c(void);
    79     search_base_type_c(void);
    63     static symbol_c *get_basetype_decl (symbol_c *symbol);
    80     static symbol_c *get_equivtype_decl(symbol_c *symbol);  /* get the Equivalent Type declaration */
    64     static symbol_c *get_basetype_id   (symbol_c *symbol);
    81     static symbol_c *get_basetype_decl (symbol_c *symbol);  /* get the Base       Type declaration */
       
    82     static symbol_c *get_basetype_id   (symbol_c *symbol);  /* get the Base       Type identifier  */
    65 
    83 
    66   public:
    84   public:
    67   /*************************/
    85   /*************************/
    68   /* B.1 - Common elements */
    86   /* B.1 - Common elements */
    69   /*************************/
    87   /*************************/