mario@181: /* msousa@265: * matiec - a compiler for the programming languages defined in IEC 61131-3 msousa@265: * msousa@265: * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) msousa@265: * msousa@265: * This program is free software: you can redistribute it and/or modify msousa@265: * it under the terms of the GNU General Public License as published by msousa@265: * the Free Software Foundation, either version 3 of the License, or msousa@265: * (at your option) any later version. msousa@265: * msousa@265: * This program is distributed in the hope that it will be useful, msousa@265: * but WITHOUT ANY WARRANTY; without even the implied warranty of msousa@265: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the msousa@265: * GNU General Public License for more details. msousa@265: * msousa@265: * You should have received a copy of the GNU General Public License msousa@265: * along with this program. If not, see . msousa@265: * 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: /* msousa@265: * An IEC 61131-3 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: /* Determine the data type of a specific variable instance, including mario@181: * function block instances. mario@181: * A reference to the relevant variable declaration is returned. mario@181: * The variable instance may NOT be a member of a structure of a memeber mario@181: * of a structure of an element of an array of ... mario@181: * mario@181: * example: mario@181: * window.points[1].coordinate.x mario@181: * window.points[1].colour mario@181: * etc... ARE NOT ALLOWED! mario@181: * mario@181: * This class must only be passed the name of the variable that will appear mario@181: * in the variable declaration. In the above examples, this would be mario@181: * 'window' !! mario@181: * mario@181: * mario@181: * If you need to pass a complete name of a variable instance (such as mario@181: * 'window.points[1].coordinate.x') use the search_varfb_instance_type_c instead! mario@181: */ mario@181: /* Note that current_type_decl that this class returns may reference the mario@181: * name of a type, or the type declaration itself! mario@181: * For an example of the first, consider a variable declared as ... mario@181: * x : AAA; mario@181: * where the AAA type is previously declared as whatever. mario@181: * For an example of the second, consider a variable declared as ... mario@181: * x : array of int [10]; ----> is allowed mario@181: * mario@181: * If it is the first, we will return a reference to the name, if the second mario@181: * we return a reference to the declaration!! mario@181: */ mario@181: mario@181: mario@181: class search_var_instance_decl_c: public search_visitor_c { mario@181: mario@181: private: mario@181: symbol_c *search_scope; mario@181: symbol_c *search_name; mario@181: symbol_c *current_type_decl; mario@181: mario@181: /* variable used to store the type of variable currently being processed... */ mario@181: /* Will contain a single value of generate_c_vardecl_c::XXXX_vt */ mario@181: unsigned int current_vartype; mario@181: mario@181: public: mario@181: search_var_instance_decl_c(symbol_c *search_scope); mario@181: symbol_c *get_decl(symbol_c *variable_instance_name); laurent@226: unsigned int get_vartype(void); mario@181: mario@181: public: mario@181: mario@181: /* the types of variables that need to be processed... */ mario@181: static const unsigned int none_vt = 0x0000; mario@181: static const unsigned int input_vt = 0x0001; // VAR_INPUT mario@181: static const unsigned int output_vt = 0x0002; // VAR_OUTPUT mario@181: static const unsigned int inoutput_vt = 0x0004; // VAR_IN_OUT mario@181: static const unsigned int private_vt = 0x0008; // VAR mario@181: static const unsigned int temp_vt = 0x0010; // VAR_TEMP mario@181: static const unsigned int external_vt = 0x0020; // VAR_EXTERNAL mario@181: static const unsigned int global_vt = 0x0040; // VAR_GLOBAL mario@181: static const unsigned int located_vt = 0x0080; // VAR AT mario@181: mario@181: private: mario@181: /***************************/ mario@181: /* B 0 - Programming Model */ mario@181: /***************************/ mario@181: void *visit(library_c *symbol); mario@181: mario@181: /******************************************/ mario@181: /* B 1.4.3 - Declaration & Initialisation */ mario@181: /******************************************/ laurent@217: mario@181: /* edge -> The F_EDGE or R_EDGE directive */ mario@181: // SYM_REF2(edge_declaration_c, edge, var1_list) mario@181: // TODO mario@181: void *visit(input_declarations_c *symbol); mario@181: /* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */ mario@181: /* option -> may be NULL ! */ mario@181: void *visit(output_declarations_c *symbol); mario@181: /* VAR_IN_OUT var_declaration_list END_VAR */ mario@181: void *visit(input_output_declarations_c *symbol); ccb@202: /* ENO : BOOL */ ccb@202: void *visit(eno_param_declaration_c *symbol); mario@181: /* VAR [CONSTANT] var_init_decl_list END_VAR */ mario@181: /* option -> may be NULL ! */ mario@181: /* helper symbol for input_declarations */ mario@181: void *visit(var_declarations_c *symbol); mario@181: /* VAR RETAIN var_init_decl_list END_VAR */ mario@181: void *visit(retentive_var_declarations_c *symbol); mario@181: /* VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */ mario@181: /* option -> may be NULL ! */ mario@181: //SYM_REF2(located_var_declarations_c, option, located_var_decl_list) mario@181: void *visit(located_var_declarations_c *symbol); mario@181: /*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */ mario@181: /* option -> may be NULL ! */ mario@181: //SYM_REF2(external_var_declarations_c, option, external_declaration_list) mario@181: void *visit(external_var_declarations_c *symbol); mario@181: /*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */ mario@181: /* option -> may be NULL ! */ mario@181: //SYM_REF2(global_var_declarations_c, option, global_var_decl_list) mario@181: void *visit(global_var_declarations_c *symbol); mario@181: /* var1_list is one of the following... mario@181: * simple_spec_init_c * mario@181: * subrange_spec_init_c * mario@181: * enumerated_spec_init_c * mario@181: */ mario@181: // SYM_REF2(var1_init_decl_c, var1_list, spec_init) mario@181: void *visit(var1_init_decl_c *symbol); mario@181: /* var1_list ',' variable_name */ mario@181: // SYM_LIST(var1_list_c) mario@181: void *visit(var1_list_c *symbol); mario@181: /* name_list ':' function_block_type_name ASSIGN structure_initialization */ mario@181: /* structure_initialization -> may be NULL ! */ mario@181: void *visit(fb_name_decl_c *symbol); mario@181: /* name_list ',' fb_name */ mario@181: void *visit(fb_name_list_c *symbol); mario@181: /* var1_list ':' array_spec_init */ mario@181: // SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) mario@181: void *visit(array_var_init_decl_c *symbol); mario@181: /* var1_list ':' initialized_structure */ mario@181: // SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) mario@181: void *visit(structured_var_init_decl_c *symbol); mario@181: /* var1_list ':' array_specification */ mario@181: // SYM_REF2(array_var_declaration_c, var1_list, array_specification) mario@181: void *visit(array_var_declaration_c *symbol); mario@181: /* var1_list ':' structure_type_name */ mario@181: // SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name) mario@181: void *visit(structured_var_declaration_c *symbol); mario@181: /* [variable_name] location ':' located_var_spec_init */ mario@181: /* variable_name -> may be NULL ! */ mario@181: // SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) mario@181: // TODO!! mario@181: mario@181: /* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ mario@181: // SYM_REF2(external_declaration_c, global_var_name, specification) mario@181: void *visit(external_declaration_c *symbol); mario@181: /*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ mario@181: /* type_specification ->may be NULL ! */ mario@181: // SYM_REF2(global_var_decl_c, global_var_spec, type_specification) mario@181: void *visit(global_var_decl_c *symbol); mario@181: /*| global_var_name location */ mario@181: //SYM_REF2(global_var_spec_c, global_var_name, location) mario@181: void *visit(global_var_spec_c *symbol); mario@181: /*| global_var_list ',' global_var_name */ mario@181: //SYM_LIST(global_var_list_c) mario@181: void *visit(global_var_list_c *symbol); mario@181: /* [variable_name] location ':' located_var_spec_init */ mario@181: /* variable_name -> may be NULL ! */ mario@181: //SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) mario@181: void *visit(located_var_decl_c *symbol); mario@181: /*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ mario@181: /* type_specification ->may be NULL ! */ mario@181: // SYM_REF2(global_var_decl_c, global_var_spec, type_specification) mario@181: // TODO!! mario@181: /* AT direct_variable */ mario@181: // SYM_REF2(location_c, direct_variable, unused) mario@181: void *visit(location_c *symbol); mario@181: /*| global_var_list ',' global_var_name */ mario@181: // SYM_LIST(global_var_list_c) mario@181: // TODO!! mario@181: /* var1_list ':' single_byte_string_spec */ mario@181: // SYM_REF2(single_byte_string_var_declaration_c, var1_list, single_byte_string_spec) mario@181: void *visit(single_byte_string_var_declaration_c *symbol); mario@181: /* STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */ mario@181: /* integer ->may be NULL ! */ mario@181: /* single_byte_character_string ->may be NULL ! */ mario@181: // SYM_REF2(single_byte_string_spec_c, integer, single_byte_character_string) mario@181: // TODO!! mario@181: mario@181: /* var1_list ':' double_byte_string_spec */ mario@181: // SYM_REF2(double_byte_string_var_declaration_c, var1_list, double_byte_string_spec) mario@181: void *visit(double_byte_string_var_declaration_c *symbol); mario@181: /* WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */ mario@181: /* integer ->may be NULL ! */ mario@181: /* double_byte_character_string ->may be NULL ! */ mario@181: // SYM_REF2(double_byte_string_spec_c, integer, double_byte_character_string) mario@181: // TODO!! mario@181: mario@181: /* variable_name incompl_location ':' var_spec */ mario@181: // SYM_REF4(incompl_located_var_decl_c, variable_name, incompl_location, var_spec, unused) mario@181: // TODO!! mario@181: mario@181: /* AT incompl_location_token */ mario@181: // SYM_TOKEN(incompl_location_c) mario@181: // TODO!! mario@181: mario@181: mario@181: /**************************************/ mario@181: /* B.1.5 - Program organization units */ mario@181: /**************************************/ mario@181: /***********************/ mario@181: /* B 1.5.1 - Functions */ mario@181: /***********************/ mario@181: // SYM_REF4(function_declaration_c, derived_function_name, type_name, var_declarations_list, function_body) mario@181: void *visit(function_declaration_c *symbol); mario@181: mario@181: /*****************************/ mario@181: /* B 1.5.2 - Function Blocks */ mario@181: /*****************************/ mario@181: void *visit(function_block_declaration_c *symbol); mario@181: mario@181: /**********************/ mario@181: /* B 1.5.3 - Programs */ mario@181: /**********************/ mario@181: void *visit(program_declaration_c *symbol); mario@181: mario@181: /********************************/ mario@181: /* B 1.7 Configuration elements */ mario@181: /********************************/ mario@181: mario@181: /* mario@181: CONFIGURATION configuration_name mario@181: optional_global_var_declarations mario@181: (resource_declaration_list | single_resource_declaration) mario@181: optional_access_declarations mario@181: optional_instance_specific_initializations mario@181: END_CONFIGURATION mario@181: */ mario@181: /* mario@181: SYM_REF6(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations, unused) mario@181: */ mario@181: void *visit(configuration_declaration_c *symbol); mario@181: /* mario@181: RESOURCE resource_name ON resource_type_name mario@181: optional_global_var_declarations mario@181: single_resource_declaration mario@181: END_RESOURCE mario@181: */ mario@181: // SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) mario@181: void *visit(resource_declaration_c *symbol); mario@181: mario@181: /* task_configuration_list program_configuration_list */ mario@181: // SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) mario@181: void *visit(single_resource_declaration_c *symbol); mario@181: mario@181: #if 0 mario@181: /*********************/ mario@181: /* B 1.4 - Variables */ mario@181: /*********************/ mario@181: SYM_REF2(symbolic_variable_c, var_name, unused) mario@181: mario@181: /********************************************/ mario@181: /* B.1.4.1 Directly Represented Variables */ mario@181: /********************************************/ mario@181: SYM_TOKEN(direct_variable_c) mario@181: mario@181: /*************************************/ mario@181: /* B.1.4.2 Multi-element Variables */ mario@181: /*************************************/ mario@181: /* subscripted_variable '[' subscript_list ']' */ mario@181: SYM_REF2(array_variable_c, subscripted_variable, subscript_list) mario@181: mario@181: /* subscript_list ',' subscript */ mario@181: SYM_LIST(subscript_list_c) mario@181: mario@181: /* record_variable '.' field_selector */ mario@181: /* WARNING: input and/or output variables of function blocks mario@181: * may be accessed as fields of a tructured variable! mario@181: * Code handling a structured_variable_c must take mario@181: * this into account! mario@181: */ mario@181: SYM_REF2(structured_variable_c, record_variable, field_selector) mario@181: #endif mario@181: mario@181: }; // search_var_instance_decl_c mario@181: