|
1 /* |
|
2 * matiec - a compiler for the programming languages defined in IEC 61131-3 |
|
3 * |
|
4 * Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt) |
|
5 * Copyright (C) 2012 Manuele Conti (conti.ma@alice.it) |
|
6 * |
|
7 * This program is free software: you can redistribute it and/or modify |
|
8 * it under the terms of the GNU General Public License as published by |
|
9 * the Free Software Foundation, either version 3 of the License, or |
|
10 * (at your option) any later version. |
|
11 * |
|
12 * This program is distributed in the hope that it will be useful, |
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 * GNU General Public License for more details. |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License |
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19 * |
|
20 * |
|
21 * This code is made available on the understanding that it will not be |
|
22 * used in safety-critical situations without a full and competent review. |
|
23 */ |
|
24 |
|
25 /* |
|
26 * An IEC 61131-3 compiler. |
|
27 * |
|
28 * Based on the |
|
29 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
30 * |
|
31 */ |
|
32 |
|
33 /* Determine the data type of an constant expression. |
|
34 * A reference to the relevant type definition is returned. |
|
35 * |
|
36 * For example: |
|
37 * 2 + 3 -> returns reference |
|
38 * 22.2 - 5 -> returns reference |
|
39 * etc... |
|
40 */ |
|
41 |
|
42 #include <vector> |
|
43 #include "../absyntax_utils/absyntax_utils.hh" |
|
44 |
|
45 |
|
46 |
|
47 class constant_folding_c : public iterator_visitor_c { |
|
48 search_varfb_instance_type_c *search_varfb_instance_type; |
|
49 search_base_type_c search_base_type; |
|
50 int error_count; |
|
51 int current_display_error_level; |
|
52 |
|
53 public: |
|
54 constant_folding_c(symbol_c *symbol = NULL); |
|
55 virtual ~constant_folding_c(void); |
|
56 int get_error_count(); |
|
57 |
|
58 private: |
|
59 /*********************/ |
|
60 /* B 1.2 - Constants */ |
|
61 /*********************/ |
|
62 /******************************/ |
|
63 /* B 1.2.1 - Numeric Literals */ |
|
64 /******************************/ |
|
65 void *visit(real_c *symbol); |
|
66 void *visit(integer_c *symbol); |
|
67 void *visit(neg_real_c *symbol); |
|
68 void *visit(neg_integer_c *symbol); |
|
69 void *visit(binary_integer_c *symbol); |
|
70 void *visit(octal_integer_c *symbol); |
|
71 void *visit(hex_integer_c *symbol); |
|
72 void *visit(integer_literal_c *symbol); |
|
73 void *visit(real_literal_c *symbol); |
|
74 void *visit(bit_string_literal_c *symbol); |
|
75 void *visit(boolean_literal_c *symbol); |
|
76 void *visit(boolean_true_c *symbol); |
|
77 void *visit(boolean_false_c *symbol); |
|
78 |
|
79 /***************************************/ |
|
80 /* B.3 - Language ST (Structured Text) */ |
|
81 /***************************************/ |
|
82 /***********************/ |
|
83 /* B 3.1 - Expressions */ |
|
84 /***********************/ |
|
85 void *visit(or_expression_c *symbol); |
|
86 void *visit(xor_expression_c *symbol); |
|
87 void *visit(and_expression_c *symbol); |
|
88 void *visit(equ_expression_c *symbol); |
|
89 void *visit(notequ_expression_c *symbol); |
|
90 void *visit(lt_expression_c *symbol); |
|
91 void *visit(gt_expression_c *symbol); |
|
92 void *visit(le_expression_c *symbol); |
|
93 void *visit(ge_expression_c *symbol); |
|
94 void *visit(add_expression_c *symbol); |
|
95 void *visit(sub_expression_c *symbol); |
|
96 void *visit(mul_expression_c *symbol); |
|
97 void *visit(div_expression_c *symbol); |
|
98 void *visit(mod_expression_c *symbol); |
|
99 void *visit(power_expression_c *symbol); |
|
100 void *visit(neg_expression_c *symbol); |
|
101 void *visit(not_expression_c *symbol); |
|
102 }; |
|
103 |