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 /* NOTE: The use of this visitor class is now deprecated. |
|
34 * The new version of stage3 data type checking adds an entry to |
|
35 * every relevant object in the abstract syntax tree defining |
|
36 * the data type of that object. Please use that instead! |
|
37 */ |
|
38 |
|
39 |
|
40 |
|
41 /* Determine the data type of a specific constant or variable. |
|
42 * A reference to the relevant type definition is returned. |
|
43 * |
|
44 * For example: |
|
45 * 22 -> returns reference to a int_type_name_c object. |
|
46 * 22.2 -> returns reference to a real_type_name_c object. |
|
47 * LREAL#22.2 -> returns reference to a lreal_type_name_c object. |
|
48 * etc... |
|
49 */ |
|
50 |
|
51 |
|
52 #include "../absyntax/visitor.hh" |
|
53 |
|
54 #ifndef _SEARCH_CONSTANT_TYPE_HH |
|
55 #define _SEARCH_CONSTANT_TYPE_HH |
|
56 |
|
57 class search_constant_type_c: public search_visitor_c { |
|
58 |
|
59 public: |
|
60 /* object used to identify an entry in the abstract syntax tree with an invalid data type */ |
|
61 /* This is only used from stage3 onwards. Stages 1 and 2 will never create any instances of invalid_type_name_c */ |
|
62 static invalid_type_name_c invalid_type_name; |
|
63 |
|
64 /**********************/ |
|
65 /* B.1.3 - Data types */ |
|
66 /**********************/ |
|
67 /***********************************/ |
|
68 /* B 1.3.1 - Elementary Data Types */ |
|
69 /***********************************/ |
|
70 static real_type_name_c real_type_name; |
|
71 static sint_type_name_c sint_type_name; |
|
72 static lint_type_name_c lint_type_name; |
|
73 static dint_type_name_c dint_type_name; |
|
74 static date_type_name_c date_type_name; |
|
75 static dword_type_name_c dword_type_name; |
|
76 static dt_type_name_c dt_type_name; |
|
77 static tod_type_name_c tod_type_name; |
|
78 static udint_type_name_c udint_type_name; |
|
79 static word_type_name_c word_type_name; |
|
80 static wstring_type_name_c wstring_type_name; |
|
81 static string_type_name_c string_type_name; |
|
82 static lword_type_name_c lword_type_name; |
|
83 static uint_type_name_c uint_type_name; |
|
84 static lreal_type_name_c lreal_type_name; |
|
85 static byte_type_name_c byte_type_name; |
|
86 static usint_type_name_c usint_type_name; |
|
87 static ulint_type_name_c ulint_type_name; |
|
88 static bool_type_name_c bool_type_name; |
|
89 static time_type_name_c time_type_name; |
|
90 static int_type_name_c int_type_name; |
|
91 |
|
92 |
|
93 /******************************************************/ |
|
94 /* Extensions to the base standard as defined in */ |
|
95 /* "Safety Software Technical Specification, */ |
|
96 /* Part 1: Concepts and Function Blocks, */ |
|
97 /* Version 1.0 – Official Release" */ |
|
98 /* by PLCopen - Technical Committee 5 - 2006-01-31 */ |
|
99 /******************************************************/ |
|
100 |
|
101 // static safebool_type_name_c safebool_type_name; |
|
102 /* The following is required because the expression (TOD_var - TOD_var) will result in a data type |
|
103 * (in this case, TIME) that is neither of the expression elements... |
|
104 */ |
|
105 static safetime_type_name_c safetime_type_name; |
|
106 static safetod_type_name_c safetod_type_name; |
|
107 static safedt_type_name_c safedt_type_name; |
|
108 static safedate_type_name_c safedate_type_name; |
|
109 static safereal_type_name_c safereal_type_name; |
|
110 static safesint_type_name_c safesint_type_name; |
|
111 static safelint_type_name_c safelint_type_name; |
|
112 static safedint_type_name_c safedint_type_name; |
|
113 static safedword_type_name_c safedword_type_name; |
|
114 static safeudint_type_name_c safeudint_type_name; |
|
115 static safeword_type_name_c safeword_type_name; |
|
116 static safewstring_type_name_c safewstring_type_name; |
|
117 static safestring_type_name_c safestring_type_name; |
|
118 static safelword_type_name_c safelword_type_name; |
|
119 static safeuint_type_name_c safeuint_type_name; |
|
120 static safelreal_type_name_c safelreal_type_name; |
|
121 static safebyte_type_name_c safebyte_type_name; |
|
122 static safeusint_type_name_c safeusint_type_name; |
|
123 static safeulint_type_name_c safeulint_type_name; |
|
124 static safebool_type_name_c safebool_type_name; |
|
125 static safeint_type_name_c safeint_type_name; |
|
126 |
|
127 public: |
|
128 symbol_c *get_type(symbol_c *constant); |
|
129 |
|
130 |
|
131 private: |
|
132 /*********************/ |
|
133 /* B 1.2 - Constants */ |
|
134 /*********************/ |
|
135 |
|
136 /******************************/ |
|
137 /* B 1.2.1 - Numeric Literals */ |
|
138 /******************************/ |
|
139 void *visit(real_c *symbol); |
|
140 void *visit(neg_real_c *symbol); |
|
141 void *visit(integer_c *symbol); |
|
142 void *visit(neg_integer_c *symbol); |
|
143 void *visit(binary_integer_c *symbol); |
|
144 void *visit(octal_integer_c *symbol); |
|
145 void *visit(hex_integer_c *symbol); |
|
146 |
|
147 void *visit(integer_literal_c *symbol); |
|
148 void *visit(real_literal_c *symbol); |
|
149 void *visit(bit_string_literal_c *symbol); |
|
150 void *visit(boolean_literal_c *symbol); |
|
151 |
|
152 void *visit(boolean_true_c *symbol); |
|
153 void *visit(boolean_false_c *symbol); |
|
154 |
|
155 /*******************************/ |
|
156 /* B.1.2.2 Character Strings */ |
|
157 /*******************************/ |
|
158 void *visit(double_byte_character_string_c *symbol); |
|
159 void *visit(single_byte_character_string_c *symbol); |
|
160 |
|
161 /***************************/ |
|
162 /* B 1.2.3 - Time Literals */ |
|
163 /***************************/ |
|
164 /************************/ |
|
165 /* B 1.2.3.1 - Duration */ |
|
166 /************************/ |
|
167 void *visit(neg_time_c *symbol); |
|
168 void *visit(duration_c *symbol); |
|
169 void *visit(interval_c *symbol); |
|
170 void *visit(fixed_point_c *symbol); |
|
171 |
|
172 /************************************/ |
|
173 /* B 1.2.3.2 - Time of day and Date */ |
|
174 /************************************/ |
|
175 void *visit(time_of_day_c *symbol); |
|
176 void *visit(daytime_c *symbol); |
|
177 void *visit(date_c *symbol); |
|
178 void *visit(date_literal_c *symbol); |
|
179 void *visit(date_and_time_c *symbol); |
|
180 |
|
181 /********************************/ |
|
182 /* B 1.3.3 - Derived data types */ |
|
183 /********************************/ |
|
184 void *visit(enumerated_value_c *symbol); |
|
185 }; // search_constant_type_c |
|
186 |
|
187 |
|
188 #endif /* ifndef _SEARCH_CONSTANT_TYPE_HH */ |
|