mario@181: /* msousa@265: * matiec - a compiler for the programming languages defined in IEC 61131-3 mario@181: * msousa@265: * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) Edouard@279: * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant mario@181: * 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: /* Determine the data type of an ST expression. mario@181: * A reference to the relevant type definition is returned. mario@181: * mario@181: * For example: mario@181: * 2 + 3 -> returns reference to a int_type_name_c object. mario@181: * 22.2 - 5 -> returns reference to a real_type_name_c object. mario@181: * etc... mario@181: */ mario@181: mario@181: class search_expression_type_c: public search_constant_type_c { mario@181: mario@181: private: mario@181: search_varfb_instance_type_c *search_varfb_instance_type; mario@181: search_base_type_c search_base_type; mario@181: mario@181: mario@181: public: mario@181: search_expression_type_c(symbol_c *search_scope); mario@181: virtual ~search_expression_type_c(void); mario@181: mario@181: /* A helper function... */ mario@181: bool is_bool_type(symbol_c *type_symbol); mario@181: bool is_time_type(symbol_c *type_symbol); mario@181: bool is_string_type(symbol_c *type_symbol); ccb@202: bool is_literal_integer_type(symbol_c *type_symbol); mario@181: bool is_integer_type(symbol_c *type_symbol); ccb@202: bool is_literal_real_type(symbol_c *type_symbol); mario@181: bool is_real_type(symbol_c *type_symbol); mario@181: bool is_num_type(symbol_c *type_symbol); mario@181: bool is_nbinary_type(symbol_c *type_symbol); mario@181: bool is_binary_type(symbol_c *type_symbol); mario@181: mario@181: bool is_same_type(symbol_c *first_type, symbol_c *second_type); mario@181: symbol_c* common_type(symbol_c *first_type, symbol_c *second_type); laurent@336: symbol_c* default_literal_type(symbol_c *symbol); mario@181: mario@181: /* mario@181: #include "search_type_code.c" mario@181: */ mario@181: void *compute_standard_function_default(function_invocation_c *st_symbol, il_formal_funct_call_c *il_symbol); mario@181: void *compute_standard_function_il(il_function_call_c *symbol, symbol_c *param_data_type); mario@181: mario@181: mario@181: mario@181: /*static bool_type_name_c bool_type_name;*/ mario@181: mario@181: /* A helper function... */ mario@181: void *compute_boolean_expression(symbol_c *left_type, symbol_c *right_type); mario@181: mario@181: /* A helper function... */ mario@181: void *compute_numeric_expression(symbol_c *left_type, symbol_c *right_type); mario@181: mario@181: /* a helper function... */ mario@181: symbol_c *base_type(symbol_c *symbol); mario@181: mario@181: /*********************/ mario@181: /* B 1.4 - Variables */ mario@181: /*********************/ mario@181: mario@181: void *visit(symbolic_variable_c *symbol); mario@181: mario@181: /********************************************/ mario@181: /* B 1.4.1 - Directly Represented Variables */ mario@181: /********************************************/ mario@181: void *visit(direct_variable_c *symbol); mario@181: mario@181: /*************************************/ mario@181: /* B 1.4.2 - Multi-element variables */ mario@181: /*************************************/ mario@181: mario@181: void *visit(array_variable_c *symbol); mario@181: void *visit(structured_variable_c *symbol); mario@181: mario@181: /***************************************/ mario@181: /* B.3 - Language ST (Structured Text) */ mario@181: /***************************************/ mario@181: /***********************/ mario@181: /* B 3.1 - Expressions */ mario@181: /***********************/ mario@181: void *visit(or_expression_c *symbol); mario@181: void *visit(xor_expression_c *symbol); mario@181: void *visit(and_expression_c *symbol); mario@181: void *visit(equ_expression_c *symbol); mario@181: void *visit(notequ_expression_c *symbol); mario@181: void *visit(lt_expression_c *symbol); mario@181: void *visit(gt_expression_c *symbol); mario@181: void *visit(le_expression_c *symbol); mario@181: void *visit(ge_expression_c *symbol); mario@181: mario@181: void *visit(add_expression_c *symbol); mario@181: void *visit(sub_expression_c *symbol); mario@181: void *visit(mul_expression_c *symbol); mario@181: void *visit(div_expression_c *symbol); mario@181: void *visit(mod_expression_c *symbol); mario@181: void *visit(power_expression_c *symbol); mario@181: void *visit(neg_expression_c *symbol); mario@181: void *visit(not_expression_c *symbol); mario@181: void *visit(function_invocation_c *symbol); ccb@202: ccb@202: ccb@202: static integer_c integer; ccb@202: mario@181: }; // search_expression_type_c mario@181: mario@181: ccb@202: