1 /* |
|
2 * matiec - a compiler for the programming languages defined in IEC 61131-3 |
|
3 * |
|
4 * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) |
|
5 * Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant |
|
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 ST expression. |
|
34 * A reference to the relevant type definition is returned. |
|
35 * |
|
36 * For example: |
|
37 * 2 + 3 -> returns reference to a int_type_name_c object. |
|
38 * 22.2 - 5 -> returns reference to a real_type_name_c object. |
|
39 * etc... |
|
40 */ |
|
41 |
|
42 /* WARNING WARNING WARNING |
|
43 * |
|
44 * When taking into consideration calls to functions, this search_expression_type_c |
|
45 * class will use internal atributes (i.e. anotation) in the function_invocation_c symbol |
|
46 * in the abstract syntax tree. |
|
47 * |
|
48 * Since this anotation/atribute is only set/populated with the correct value |
|
49 * during stage3 (semantic verification), this class will only work correctly |
|
50 * after the semantic verification in stage 3 has been executed |
|
51 * (to be more exact, the data type checking of stage 3). |
|
52 */ |
|
53 |
|
54 class search_expression_type_c: public search_constant_type_c { |
|
55 |
|
56 private: |
|
57 search_varfb_instance_type_c *search_varfb_instance_type; |
|
58 search_base_type_c search_base_type; |
|
59 |
|
60 |
|
61 public: |
|
62 search_expression_type_c(symbol_c *search_scope); |
|
63 virtual ~search_expression_type_c(void); |
|
64 |
|
65 /* A helper function... */ |
|
66 bool is_bool_type(symbol_c *type_symbol); |
|
67 bool is_time_type(symbol_c *type_symbol); |
|
68 bool is_string_type(symbol_c *type_symbol); |
|
69 bool is_literal_integer_type(symbol_c *type_symbol); |
|
70 bool is_integer_type(symbol_c *type_symbol); |
|
71 bool is_literal_real_type(symbol_c *type_symbol); |
|
72 bool is_real_type(symbol_c *type_symbol); |
|
73 bool is_num_type(symbol_c *type_symbol); |
|
74 bool is_nbinary_type(symbol_c *type_symbol); |
|
75 bool is_binary_type(symbol_c *type_symbol); |
|
76 |
|
77 bool is_same_type(symbol_c *first_type, symbol_c *second_type); |
|
78 symbol_c* common_type(symbol_c *first_type, symbol_c *second_type); |
|
79 symbol_c* default_literal_type(symbol_c *symbol); |
|
80 |
|
81 /*static bool_type_name_c bool_type_name;*/ |
|
82 |
|
83 /* A helper function... */ |
|
84 void *compute_boolean_expression(symbol_c *left_type, symbol_c *right_type); |
|
85 |
|
86 /* A helper function... */ |
|
87 void *compute_numeric_expression(symbol_c *left_type, symbol_c *right_type); |
|
88 |
|
89 /* a helper function... */ |
|
90 symbol_c *base_type(symbol_c *symbol); |
|
91 |
|
92 /*********************/ |
|
93 /* B 1.4 - Variables */ |
|
94 /*********************/ |
|
95 |
|
96 void *visit(symbolic_variable_c *symbol); |
|
97 |
|
98 /********************************************/ |
|
99 /* B 1.4.1 - Directly Represented Variables */ |
|
100 /********************************************/ |
|
101 void *visit(direct_variable_c *symbol); |
|
102 |
|
103 /*************************************/ |
|
104 /* B 1.4.2 - Multi-element variables */ |
|
105 /*************************************/ |
|
106 |
|
107 void *visit(array_variable_c *symbol); |
|
108 void *visit(structured_variable_c *symbol); |
|
109 |
|
110 /***************************************/ |
|
111 /* B.3 - Language ST (Structured Text) */ |
|
112 /***************************************/ |
|
113 /***********************/ |
|
114 /* B 3.1 - Expressions */ |
|
115 /***********************/ |
|
116 void *visit(or_expression_c *symbol); |
|
117 void *visit(xor_expression_c *symbol); |
|
118 void *visit(and_expression_c *symbol); |
|
119 void *visit(equ_expression_c *symbol); |
|
120 void *visit(notequ_expression_c *symbol); |
|
121 void *visit(lt_expression_c *symbol); |
|
122 void *visit(gt_expression_c *symbol); |
|
123 void *visit(le_expression_c *symbol); |
|
124 void *visit(ge_expression_c *symbol); |
|
125 |
|
126 void *visit(add_expression_c *symbol); |
|
127 void *visit(sub_expression_c *symbol); |
|
128 void *visit(mul_expression_c *symbol); |
|
129 void *visit(div_expression_c *symbol); |
|
130 void *visit(mod_expression_c *symbol); |
|
131 void *visit(power_expression_c *symbol); |
|
132 void *visit(neg_expression_c *symbol); |
|
133 void *visit(not_expression_c *symbol); |
|
134 void *visit(function_invocation_c *symbol); |
|
135 |
|
136 |
|
137 static integer_c integer; |
|
138 |
|
139 }; // search_expression_type_c |
|
140 |
|
141 |
|
142 |
|