absyntax_utils/search_varfb_instance_type.hh
changeset 181 38d6eb056260
child 226 29f8ffc203c1
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 
       
    27 /* Determine the data type of a variable.
       
    28  * The variable may be a simple variable, a function block instance, a
       
    29  * struture element within a data structured type (a struct or a fb), or
       
    30  * an array element.
       
    31  * A mixture of array element of a structure element of a structure element
       
    32  * of a .... is also suported!
       
    33  *
       
    34  * A reference to the relevant base type __definition__ is returned.
       
    35  * This means that if we find that the variable is of type MY_INT,
       
    36  * which was previously declared to be
       
    37  * TYPE MY_INT: INT := 9;
       
    38  * this class wil return INT, and __not__ MY_INT !!
       
    39  *
       
    40  *
       
    41  *  example:
       
    42  *    window.points[1].coordinate.x
       
    43  *    window.points[1].colour
       
    44  *    etc... ARE ALLOWED!
       
    45  *
       
    46  * This class must be passed the scope within which the
       
    47  * variable was declared, and the variable name...
       
    48  */
       
    49 
       
    50 class search_varfb_instance_type_c: public search_base_type_c {
       
    51 
       
    52   private:
       
    53     search_var_instance_decl_c search_var_instance_decl;
       
    54     decompose_var_instance_name_c *decompose_var_instance_name;
       
    55     symbol_c *current_structelement_name;
       
    56     bool search_base_type;
       
    57 
       
    58   public:
       
    59     search_varfb_instance_type_c(symbol_c *search_scope);
       
    60     symbol_c *get_type(symbol_c *variable_name, bool base_type = true);
       
    61 
       
    62     unsigned int get_vartype(symbol_c *variable_name);
       
    63 
       
    64   private:
       
    65     /* a helper function... */
       
    66     void *visit_list(list_c *list);
       
    67 
       
    68     /* a helper function... */
       
    69     void *base_type(symbol_c *symbol);
       
    70 
       
    71 
       
    72   private:
       
    73     /* We override the base class' visitor to identifier_c.
       
    74      * This is so because the base class does not consider a function block
       
    75      * to be a type, unlike this class that allows a variable instance
       
    76      * of a function block type...
       
    77      */
       
    78     void *visit(identifier_c *type_name);
       
    79 
       
    80     /********************************/
       
    81     /* B 1.3.3 - Derived data types */
       
    82     /********************************/
       
    83     
       
    84     /*  identifier ':' array_spec_init */
       
    85     void *visit(array_type_declaration_c *symbol);
       
    86     
       
    87     /* array_specification [ASSIGN array_initialization} */
       
    88     /* array_initialization may be NULL ! */
       
    89     void *visit(array_spec_init_c *symbol);
       
    90     
       
    91     /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
       
    92     void *visit(array_specification_c *symbol);
       
    93 
       
    94     /*  structure_type_name ':' structure_specification */
       
    95     void *visit(structure_type_declaration_c *symbol);
       
    96 
       
    97     /* structure_type_name ASSIGN structure_initialization */
       
    98     /* structure_initialization may be NULL ! */
       
    99     // SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization)
       
   100     void *visit(initialized_structure_c *symbol);
       
   101 
       
   102     /* helper symbol for structure_declaration */
       
   103     /* structure_declaration:  STRUCT structure_element_declaration_list END_STRUCT */
       
   104     /* structure_element_declaration_list structure_element_declaration ';' */
       
   105     void *visit(structure_element_declaration_list_c *symbol);
       
   106 
       
   107     /*  structure_element_name ':' spec_init */
       
   108     void *visit(structure_element_declaration_c *symbol);
       
   109 
       
   110     /* helper symbol for structure_initialization */
       
   111     /* structure_initialization: '(' structure_element_initialization_list ')' */
       
   112     /* structure_element_initialization_list ',' structure_element_initialization */
       
   113     void *visit(structure_element_initialization_list_c *symbol); /* should never get called... */
       
   114     /*  structure_element_name ASSIGN value */
       
   115     void *visit(structure_element_initialization_c *symbol); /* should never get called... */
       
   116 
       
   117 
       
   118 
       
   119     /**************************************/
       
   120     /* B.1.5 - Program organization units */
       
   121     /**************************************/
       
   122     /*****************************/
       
   123     /* B 1.5.2 - Function Blocks */
       
   124     /*****************************/
       
   125     /*  FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */
       
   126     // SYM_REF4(function_block_declaration_c, fblock_name, var_declarations, fblock_body, unused)
       
   127     void *visit(function_block_declaration_c *symbol);
       
   128 
       
   129 }; // search_varfb_instance_type_c
       
   130 
       
   131 
       
   132 
       
   133 
       
   134 
       
   135