absyntax_utils/search_base_type.hh
changeset 870 9c6c588fd708
parent 858 c5f145364a4f
child 909 8b2a31dea131
equal deleted inserted replaced
822:a7d9e0b8636b 870:9c6c588fd708
    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;
    56     bool is_array;
    72     symbol_c *current_equivtype;
    57     bool is_subrange;
       
    58     bool is_enumerated;
       
    59     bool is_fb;
       
    60     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!
    61     
    74     
    62   private:  
    75   private:  
    63     static void create_singleton(void);
    76     static void create_singleton(void);
    64 
    77 
    65   public:
    78   public:
    66     search_base_type_c(void);
    79     search_base_type_c(void);
    67     static symbol_c *get_basetype_decl (symbol_c *symbol);
    80     static symbol_c *get_equivtype_decl(symbol_c *symbol);  /* get the Equivalent Type declaration */
    68     static symbol_c *get_basetype_id   (symbol_c *symbol);
    81     static symbol_c *get_basetype_decl (symbol_c *symbol);  /* get the Base       Type declaration */
    69     static bool      type_is_subrange  (symbol_c *type_decl);
    82     static symbol_c *get_basetype_id   (symbol_c *symbol);  /* get the Base       Type identifier  */
    70     static bool      type_is_enumerated(symbol_c *type_decl);
       
    71     static bool      type_is_fb        (symbol_c *type_decl);
       
    72 
    83 
    73   public:
    84   public:
    74   /*************************/
    85   /*************************/
    75   /* B.1 - Common elements */
    86   /* B.1 - Common elements */
    76   /*************************/
    87   /*************************/