absyntax_utils/search_base_type.hh
changeset 181 38d6eb056260
child 194 e18690830555
equal deleted inserted replaced
180:64334c5a00b1 181:38d6eb056260
       
     1 /*
       
     2  * (c) 2003 Mario de Sousa
       
     3  *
       
     4  * Offered to the public under the terms of the GNU General Public License
       
     5  * as published by the Free Software Foundation; either version 2 of the
       
     6  * License, or (at your option) any later version.
       
     7  *
       
     8  * This program is distributed in the hope that it will be useful, but
       
     9  * WITHOUT ANY WARRANTY; without even the implied warranty of
       
    10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
       
    11  * Public License for more details.
       
    12  *
       
    13  * This code is made available on the understanding that it will not be
       
    14  * used in safety-critical situations without a full and competent review.
       
    15  */
       
    16 
       
    17 /*
       
    18  * An IEC 61131-3 IL and ST compiler.
       
    19  *
       
    20  * Based on the
       
    21  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
       
    22  *
       
    23  */
       
    24 
       
    25 
       
    26 /* Determine the data type on which another data type is based on.
       
    27  * If a new default initial value is given, we DO NOT consider it a
       
    28  * new base class, and continue looking further!
       
    29  *
       
    30  * E.g. TYPE new_int_t : INT; END_TYPE;
       
    31  *      TYPE new_int2_t : INT = 2; END_TYPE;
       
    32  *      TYPE new_subr_t : INT (4..5); END_TYPE;
       
    33  *
       
    34  *    new_int_t is really an INT!!
       
    35  *    new_int2_t is also really an INT!!
       
    36  *    new_subr_t is also really an INT!!
       
    37  */
       
    38 
       
    39 
       
    40 class search_base_type_c: public null_visitor_c {
       
    41 
       
    42   private:
       
    43     symbol_c *current_type_name;
       
    44     bool is_subrange;
       
    45     bool is_enumerated;
       
    46 
       
    47   public:
       
    48     search_base_type_c(void);
       
    49 
       
    50   public:
       
    51     void *visit(identifier_c *type_name);
       
    52     bool type_is_subrange(symbol_c* type_decl);
       
    53     bool type_is_enumerated(symbol_c* type_decl);
       
    54 
       
    55   public:
       
    56   /***********************************/
       
    57   /* B 1.3.1 - Elementary Data Types */
       
    58   /***********************************/
       
    59     void *visit(time_type_name_c *symbol);
       
    60     void *visit(bool_type_name_c *symbol);
       
    61     void *visit(sint_type_name_c *symbol);
       
    62     void *visit(int_type_name_c *symbol);
       
    63     void *visit(dint_type_name_c *symbol);
       
    64     void *visit(lint_type_name_c *symbol);
       
    65     void *visit(usint_type_name_c *symbol);
       
    66     void *visit(uint_type_name_c *symbol);
       
    67     void *visit(udint_type_name_c *symbol);
       
    68     void *visit(ulint_type_name_c *symbol);
       
    69     void *visit(real_type_name_c *symbol);
       
    70     void *visit(lreal_type_name_c *symbol);
       
    71     void *visit(date_type_name_c *symbol);
       
    72     void *visit(tod_type_name_c *symbol);
       
    73     void *visit(dt_type_name_c *symbol)	;
       
    74     void *visit(byte_type_name_c *symbol);
       
    75     void *visit(word_type_name_c *symbol);
       
    76     void *visit(dword_type_name_c *symbol);
       
    77     void *visit(lword_type_name_c *symbol);
       
    78     void *visit(string_type_name_c *symbol);
       
    79     void *visit(wstring_type_name_c *symbol);
       
    80     void *visit(constant_int_type_name_c *symbol);
       
    81     void *visit(constant_real_type_name_c *symbol);
       
    82     void *visit(direct_variable_type_name_c *symbol);
       
    83 
       
    84     /******************************************************/
       
    85     /* Extensions to the base standard as defined in      */
       
    86     /* "Safety Software Technical Specification,          */
       
    87     /*  Part 1: Concepts and Function Blocks,             */
       
    88     /*  Version 1.0 – Official Release"                   */
       
    89     /* by PLCopen - Technical Committee 5 - 2006-01-31    */
       
    90     /******************************************************/
       
    91     void *visit(safebool_type_name_c *symbol);
       
    92 
       
    93   /********************************/
       
    94   /* B 1.3.3 - Derived data types */
       
    95   /********************************/
       
    96   /*  simple_type_name ':' simple_spec_init */
       
    97     void *visit(simple_type_declaration_c *symbol);
       
    98   /* simple_specification ASSIGN constant */
       
    99     void *visit(simple_spec_init_c *symbol);
       
   100   /*  subrange_type_name ':' subrange_spec_init */
       
   101     void *visit(subrange_type_declaration_c *symbol);
       
   102   /* subrange_specification ASSIGN signed_integer */
       
   103     void *visit(subrange_spec_init_c *symbol);
       
   104   /*  integer_type_name '(' subrange')' */
       
   105     void *visit(subrange_specification_c *symbol);
       
   106   /*  signed_integer DOTDOT signed_integer */
       
   107     void *visit(subrange_c *symbol);
       
   108 
       
   109   /*  enumerated_type_name ':' enumerated_spec_init */
       
   110     void *visit(enumerated_type_declaration_c *symbol);
       
   111   /* enumerated_specification ASSIGN enumerated_value */
       
   112     void *visit(enumerated_spec_init_c *symbol);
       
   113   /* helper symbol for enumerated_specification->enumerated_spec_init */
       
   114   /* enumerated_value_list ',' enumerated_value */
       
   115     void *visit(enumerated_value_list_c *symbol);
       
   116   /* enumerated_type_name '#' identifier */
       
   117   // SYM_REF2(enumerated_value_c, type, value)
       
   118     void *visit(enumerated_value_c *symbol);
       
   119   /*  identifier ':' array_spec_init */
       
   120     void *visit(array_type_declaration_c *symbol);
       
   121   /* array_specification [ASSIGN array_initialization} */
       
   122   /* array_initialization may be NULL ! */
       
   123     void *visit(array_spec_init_c *symbol);
       
   124   /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
       
   125     void *visit(array_specification_c *symbol);
       
   126   /* helper symbol for array_specification */
       
   127   /* array_subrange_list ',' subrange */
       
   128     void *visit(array_subrange_list_c *symbol);
       
   129   /* array_initialization:  '[' array_initial_elements_list ']' */
       
   130   /* helper symbol for array_initialization */
       
   131   /* array_initial_elements_list ',' array_initial_elements */
       
   132     void *visit(array_initial_elements_list_c *symbol);
       
   133   /* integer '(' [array_initial_element] ')' */
       
   134   /* array_initial_element may be NULL ! */
       
   135     void *visit(array_initial_elements_c *symbol);
       
   136   /*  structure_type_name ':' structure_specification */
       
   137       /* NOTE: structure_specification will point to either a
       
   138        *       initialized_structure_c
       
   139        *       OR A
       
   140        *       structure_element_declaration_list_c
       
   141        */
       
   142     void *visit(structure_type_declaration_c *symbol);
       
   143   /* structure_type_name ASSIGN structure_initialization */
       
   144   /* structure_initialization may be NULL ! */
       
   145     void *visit(initialized_structure_c *symbol);
       
   146   /* helper symbol for structure_declaration */
       
   147   /* structure_declaration:  STRUCT structure_element_declaration_list END_STRUCT */
       
   148   /* structure_element_declaration_list structure_element_declaration ';' */
       
   149     void *visit(structure_element_declaration_list_c *symbol);
       
   150   /*  structure_element_name ':' *_spec_init */
       
   151     void *visit(structure_element_declaration_c *symbol);
       
   152   /* helper symbol for structure_initialization */
       
   153   /* structure_initialization: '(' structure_element_initialization_list ')' */
       
   154   /* structure_element_initialization_list ',' structure_element_initialization */
       
   155     void *visit(structure_element_initialization_list_c *symbol);
       
   156   /*  structure_element_name ASSIGN value */
       
   157     void *visit(structure_element_initialization_c *symbol);
       
   158   /*  string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */
       
   159   /*
       
   160   SYM_REF4(string_type_declaration_c,	string_type_name,
       
   161   					elementary_string_type_name,
       
   162   					string_type_declaration_size,
       
   163   					string_type_declaration_init) // may be == NULL!
       
   164   */
       
   165     void *visit(string_type_declaration_c *symbol);
       
   166 }; // search_base_type_c
       
   167 
       
   168 
       
   169 
       
   170