mario@181: /* mario@181: * (c) 2003 Mario de Sousa mario@181: * mario@181: * Offered to the public under the terms of the GNU General Public License mario@181: * as published by the Free Software Foundation; either version 2 of the mario@181: * License, or (at your option) any later version. mario@181: * mario@181: * This program is distributed in the hope that it will be useful, but mario@181: * WITHOUT ANY WARRANTY; without even the implied warranty of mario@181: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General mario@181: * Public License for more details. mario@181: * mario@181: * This code is made available on the understanding that it will not be mario@181: * used in safety-critical situations without a full and competent review. mario@181: */ mario@181: mario@181: /* mario@181: * An IEC 61131-3 IL and ST compiler. mario@181: * mario@181: * Based on the mario@181: * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) mario@181: * mario@181: */ mario@181: mario@181: mario@181: mario@181: /* Determine the data type of a variable. mario@181: * The variable may be a simple variable, a function block instance, a mario@181: * struture element within a data structured type (a struct or a fb), or mario@181: * an array element. mario@181: * A mixture of array element of a structure element of a structure element mario@181: * of a .... is also suported! mario@181: * mario@181: * A reference to the relevant base type __definition__ is returned. mario@181: * This means that if we find that the variable is of type MY_INT, mario@181: * which was previously declared to be mario@181: * TYPE MY_INT: INT := 9; mario@181: * this class wil return INT, and __not__ MY_INT !! mario@181: * mario@181: * mario@181: * example: mario@181: * window.points[1].coordinate.x mario@181: * window.points[1].colour mario@181: * etc... ARE ALLOWED! mario@181: * mario@181: * This class must be passed the scope within which the mario@181: * variable was declared, and the variable name... mario@181: */ mario@181: mario@181: class search_varfb_instance_type_c: public search_base_type_c { mario@181: mario@181: private: mario@181: search_var_instance_decl_c search_var_instance_decl; mario@181: decompose_var_instance_name_c *decompose_var_instance_name; mario@181: symbol_c *current_structelement_name; mario@181: bool search_base_type; mario@181: mario@181: public: mario@181: search_varfb_instance_type_c(symbol_c *search_scope); mario@181: symbol_c *get_type(symbol_c *variable_name, bool base_type = true); mario@181: mario@181: unsigned int get_vartype(symbol_c *variable_name); mario@181: mario@181: private: mario@181: /* a helper function... */ mario@181: void *visit_list(list_c *list); mario@181: mario@181: /* a helper function... */ mario@181: void *base_type(symbol_c *symbol); mario@181: mario@181: mario@181: private: mario@181: /* We override the base class' visitor to identifier_c. mario@181: * This is so because the base class does not consider a function block mario@181: * to be a type, unlike this class that allows a variable instance mario@181: * of a function block type... mario@181: */ mario@181: void *visit(identifier_c *type_name); mario@181: mario@181: /********************************/ mario@181: /* B 1.3.3 - Derived data types */ mario@181: /********************************/ mario@181: mario@181: /* identifier ':' array_spec_init */ mario@181: void *visit(array_type_declaration_c *symbol); mario@181: mario@181: /* array_specification [ASSIGN array_initialization} */ mario@181: /* array_initialization may be NULL ! */ mario@181: void *visit(array_spec_init_c *symbol); mario@181: mario@181: /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ mario@181: void *visit(array_specification_c *symbol); mario@181: mario@181: /* structure_type_name ':' structure_specification */ mario@181: void *visit(structure_type_declaration_c *symbol); mario@181: mario@181: /* structure_type_name ASSIGN structure_initialization */ mario@181: /* structure_initialization may be NULL ! */ mario@181: // SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization) mario@181: void *visit(initialized_structure_c *symbol); mario@181: mario@181: /* helper symbol for structure_declaration */ mario@181: /* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ mario@181: /* structure_element_declaration_list structure_element_declaration ';' */ mario@181: void *visit(structure_element_declaration_list_c *symbol); mario@181: mario@181: /* structure_element_name ':' spec_init */ mario@181: void *visit(structure_element_declaration_c *symbol); mario@181: mario@181: /* helper symbol for structure_initialization */ mario@181: /* structure_initialization: '(' structure_element_initialization_list ')' */ mario@181: /* structure_element_initialization_list ',' structure_element_initialization */ mario@181: void *visit(structure_element_initialization_list_c *symbol); /* should never get called... */ mario@181: /* structure_element_name ASSIGN value */ mario@181: void *visit(structure_element_initialization_c *symbol); /* should never get called... */ mario@181: mario@181: mario@181: mario@181: /**************************************/ mario@181: /* B.1.5 - Program organization units */ mario@181: /**************************************/ mario@181: /*****************************/ mario@181: /* B 1.5.2 - Function Blocks */ mario@181: /*****************************/ mario@181: /* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ mario@181: // SYM_REF4(function_block_declaration_c, fblock_name, var_declarations, fblock_body, unused) mario@181: void *visit(function_block_declaration_c *symbol); mario@181: mario@181: }; // search_varfb_instance_type_c mario@181: mario@181: mario@181: mario@181: mario@181: mario@181: