conti@564: /* conti@564: * matiec - a compiler for the programming languages defined in IEC 61131-3 conti@564: * conti@564: * Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt) conti@564: * Copyright (C) 2012 Manuele Conti (conti.ma@alice.it) conti@564: * conti@564: * This program is free software: you can redistribute it and/or modify conti@564: * it under the terms of the GNU General Public License as published by conti@564: * the Free Software Foundation, either version 3 of the License, or conti@564: * (at your option) any later version. conti@564: * conti@564: * This program is distributed in the hope that it will be useful, conti@564: * but WITHOUT ANY WARRANTY; without even the implied warranty of conti@564: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the conti@564: * GNU General Public License for more details. conti@564: * conti@564: * You should have received a copy of the GNU General Public License conti@564: * along with this program. If not, see . conti@564: * conti@564: * conti@564: * This code is made available on the understanding that it will not be conti@564: * used in safety-critical situations without a full and competent review. conti@564: */ conti@564: conti@564: /* conti@564: * An IEC 61131-3 compiler. conti@564: * conti@564: * Based on the conti@564: * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) conti@564: * conti@564: */ conti@564: conti@564: /* Determine the data type of an constant expression. conti@564: * A reference to the relevant type definition is returned. conti@564: * conti@564: * For example: conti@564: * 2 + 3 -> returns reference conti@564: * 22.2 - 5 -> returns reference conti@564: * etc... conti@564: */ conti@564: conti@564: #include conti@564: #include "../absyntax_utils/absyntax_utils.hh" conti@564: conti@564: conti@564: conti@564: class constant_folding_c : public iterator_visitor_c { conti@564: search_varfb_instance_type_c *search_varfb_instance_type; conti@564: search_base_type_c search_base_type; conti@564: int error_count; msousa@568: bool warning_found; conti@564: int current_display_error_level; conti@564: conti@564: public: conti@564: constant_folding_c(symbol_c *symbol = NULL); conti@564: virtual ~constant_folding_c(void); conti@564: int get_error_count(); conti@564: conti@564: private: conti@564: /*********************/ conti@564: /* B 1.2 - Constants */ conti@564: /*********************/ conti@564: /******************************/ conti@564: /* B 1.2.1 - Numeric Literals */ conti@564: /******************************/ conti@564: void *visit(real_c *symbol); conti@564: void *visit(integer_c *symbol); conti@564: void *visit(neg_real_c *symbol); conti@564: void *visit(neg_integer_c *symbol); conti@564: void *visit(binary_integer_c *symbol); conti@564: void *visit(octal_integer_c *symbol); conti@564: void *visit(hex_integer_c *symbol); conti@564: void *visit(integer_literal_c *symbol); conti@564: void *visit(real_literal_c *symbol); conti@564: void *visit(bit_string_literal_c *symbol); conti@564: void *visit(boolean_literal_c *symbol); conti@564: void *visit(boolean_true_c *symbol); conti@564: void *visit(boolean_false_c *symbol); conti@564: conti@564: /***************************************/ conti@564: /* B.3 - Language ST (Structured Text) */ conti@564: /***************************************/ conti@564: /***********************/ conti@564: /* B 3.1 - Expressions */ conti@564: /***********************/ conti@564: void *visit(or_expression_c *symbol); conti@564: void *visit(xor_expression_c *symbol); conti@564: void *visit(and_expression_c *symbol); conti@564: void *visit(equ_expression_c *symbol); conti@564: void *visit(notequ_expression_c *symbol); conti@564: void *visit(lt_expression_c *symbol); conti@564: void *visit(gt_expression_c *symbol); conti@564: void *visit(le_expression_c *symbol); conti@564: void *visit(ge_expression_c *symbol); conti@564: void *visit(add_expression_c *symbol); conti@564: void *visit(sub_expression_c *symbol); conti@564: void *visit(mul_expression_c *symbol); conti@564: void *visit(div_expression_c *symbol); conti@564: void *visit(mod_expression_c *symbol); conti@564: void *visit(power_expression_c *symbol); conti@564: void *visit(neg_expression_c *symbol); conti@564: void *visit(not_expression_c *symbol); conti@564: }; conti@564: