42 #include <string> |
42 #include <string> |
43 #include <string.h> |
43 #include <string.h> |
44 #include <strings.h> |
44 #include <strings.h> |
45 |
45 |
46 |
46 |
|
47 |
|
48 /* A small helper class, to transform elementary data type to string. |
|
49 * this allows us to generate more relevant error messages... |
|
50 */ |
|
51 |
|
52 class elementary_type_c: public null_visitor_c { |
|
53 elementary_type_c(void) {}; |
|
54 ~elementary_type_c(void) {}; |
|
55 |
|
56 private: |
|
57 /* singleton class! */ |
|
58 static elementary_type_c *singleton; |
|
59 |
|
60 public: |
|
61 static const char * to_string(symbol_c *symbol) { |
|
62 if (NULL == singleton) singleton = new elementary_type_c; |
|
63 if (NULL == singleton) ERROR; |
|
64 const char *res = (const char *)symbol->accept(*singleton); |
|
65 if (NULL == res) ERROR; |
|
66 if (NULL == res) ERROR; |
|
67 return res; |
|
68 } |
|
69 |
|
70 /***********************************/ |
|
71 /* B 1.3.1 - Elementary Data Types */ |
|
72 /***********************************/ |
|
73 void *visit(time_type_name_c *symbol) {return (void *)"TIME"; }; |
|
74 void *visit(bool_type_name_c *symbol) {return (void *)"BOOL"; }; |
|
75 void *visit(sint_type_name_c *symbol) {return (void *)"SINT"; }; |
|
76 void *visit(int_type_name_c *symbol) {return (void *)"INT"; }; |
|
77 void *visit(dint_type_name_c *symbol) {return (void *)"DINT"; }; |
|
78 void *visit(lint_type_name_c *symbol) {return (void *)"LINT"; }; |
|
79 void *visit(usint_type_name_c *symbol) {return (void *)"USINT"; }; |
|
80 void *visit(uint_type_name_c *symbol) {return (void *)"UINT"; }; |
|
81 void *visit(udint_type_name_c *symbol) {return (void *)"UDINT"; }; |
|
82 void *visit(ulint_type_name_c *symbol) {return (void *)"ULINT"; }; |
|
83 void *visit(real_type_name_c *symbol) {return (void *)"REAL"; }; |
|
84 void *visit(lreal_type_name_c *symbol) {return (void *)"LREAL"; }; |
|
85 void *visit(date_type_name_c *symbol) {return (void *)"DATE"; }; |
|
86 void *visit(tod_type_name_c *symbol) {return (void *)"TOD"; }; |
|
87 void *visit(dt_type_name_c *symbol) {return (void *)"DT"; }; |
|
88 void *visit(byte_type_name_c *symbol) {return (void *)"BYTE"; }; |
|
89 void *visit(word_type_name_c *symbol) {return (void *)"WORD"; }; |
|
90 void *visit(lword_type_name_c *symbol) {return (void *)"LWORD"; }; |
|
91 void *visit(dword_type_name_c *symbol) {return (void *)"DWORD"; }; |
|
92 void *visit(string_type_name_c *symbol) {return (void *)"STRING"; }; |
|
93 void *visit(wstring_type_name_c *symbol) {return (void *)"WSTRING"; }; |
|
94 |
|
95 void *visit(safetime_type_name_c *symbol) {return (void *)"SAFETIME"; }; |
|
96 void *visit(safebool_type_name_c *symbol) {return (void *)"SAFEBOOL"; }; |
|
97 void *visit(safesint_type_name_c *symbol) {return (void *)"SAFESINT"; }; |
|
98 void *visit(safeint_type_name_c *symbol) {return (void *)"SAFEINT"; }; |
|
99 void *visit(safedint_type_name_c *symbol) {return (void *)"SAFEDINT"; }; |
|
100 void *visit(safelint_type_name_c *symbol) {return (void *)"SAFELINT"; }; |
|
101 void *visit(safeusint_type_name_c *symbol) {return (void *)"SAFEUSINT"; }; |
|
102 void *visit(safeuint_type_name_c *symbol) {return (void *)"SAFEUINT"; }; |
|
103 void *visit(safeudint_type_name_c *symbol) {return (void *)"SAFEUDINT"; }; |
|
104 void *visit(safeulint_type_name_c *symbol) {return (void *)"SAFEULINT"; }; |
|
105 void *visit(safereal_type_name_c *symbol) {return (void *)"SAFEREAL"; }; |
|
106 void *visit(safelreal_type_name_c *symbol) {return (void *)"SAFELREAL"; }; |
|
107 void *visit(safedate_type_name_c *symbol) {return (void *)"SAFEDATE"; }; |
|
108 void *visit(safetod_type_name_c *symbol) {return (void *)"SAFETOD"; }; |
|
109 void *visit(safedt_type_name_c *symbol) {return (void *)"SAFEDT"; }; |
|
110 void *visit(safebyte_type_name_c *symbol) {return (void *)"SAFEBYTE"; }; |
|
111 void *visit(safeword_type_name_c *symbol) {return (void *)"SAFEWORD"; }; |
|
112 void *visit(safelword_type_name_c *symbol) {return (void *)"SAFELWORD"; }; |
|
113 void *visit(safedword_type_name_c *symbol) {return (void *)"SAFEDWORD"; }; |
|
114 void *visit(safestring_type_name_c *symbol) {return (void *)"SAFESTRING"; }; |
|
115 void *visit(safewstring_type_name_c *symbol) {return (void *)"SAFEWSTRING"; }; |
|
116 }; |
|
117 |
|
118 |
|
119 elementary_type_c *elementary_type_c::singleton = NULL; |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
47 #define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order) ? (symbol1) : (symbol2)) |
125 #define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order) ? (symbol1) : (symbol2)) |
48 #define LAST_(symbol1, symbol2) (((symbol1)->last_order > (symbol2)->last_order) ? (symbol1) : (symbol2)) |
126 #define LAST_(symbol1, symbol2) (((symbol1)->last_order > (symbol2)->last_order) ? (symbol1) : (symbol2)) |
49 |
127 |
50 #define STAGE3_ERROR(symbol1, symbol2, ...) { \ |
128 #define STAGE3_ERROR(error_level, symbol1, symbol2, ...) { \ |
51 fprintf(stderr, "%s:%d-%d..%d-%d: error : ", \ |
129 if (current_display_error_level >= error_level) { \ |
52 FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column, \ |
130 fprintf(stderr, "%s:%d-%d..%d-%d: error : ", \ |
53 LAST_(symbol1,symbol2) ->last_line, LAST_(symbol1,symbol2) ->last_column); \ |
131 FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\ |
54 fprintf(stderr, __VA_ARGS__); \ |
132 LAST_(symbol1,symbol2) ->last_line, LAST_(symbol1,symbol2) ->last_column);\ |
55 fprintf(stderr, "\n"); \ |
133 fprintf(stderr, __VA_ARGS__); \ |
56 il_error = true; \ |
134 fprintf(stderr, "\n"); \ |
57 error_found = true;\ |
135 il_error = true; \ |
58 } |
136 error_found = true; \ |
|
137 } \ |
|
138 } |
59 |
139 |
60 |
140 |
61 /* set to 1 to see debug info during execution */ |
141 /* set to 1 to see debug info during execution */ |
62 static int debug = 0; |
142 static int debug = 0; |
63 |
143 |
64 print_datatypes_error_c::print_datatypes_error_c(symbol_c *ignore) { |
144 print_datatypes_error_c::print_datatypes_error_c(symbol_c *ignore) { |
65 error_found = false; |
145 error_found = false; |
|
146 current_display_error_level = error_level_default; |
66 } |
147 } |
67 |
148 |
68 print_datatypes_error_c::~print_datatypes_error_c(void) { |
149 print_datatypes_error_c::~print_datatypes_error_c(void) { |
69 error_found = false; |
|
70 } |
150 } |
71 |
151 |
72 int print_datatypes_error_c::get_error_found() { |
152 int print_datatypes_error_c::get_error_found() { |
73 return error_found; |
153 return error_found; |
74 } |
154 } |
88 /******************************/ |
168 /******************************/ |
89 /* B 1.2.1 - Numeric Literals */ |
169 /* B 1.2.1 - Numeric Literals */ |
90 /******************************/ |
170 /******************************/ |
91 void *print_datatypes_error_c::visit(real_c *symbol) { |
171 void *print_datatypes_error_c::visit(real_c *symbol) { |
92 if (symbol->candidate_datatypes.size() == 0) { |
172 if (symbol->candidate_datatypes.size() == 0) { |
93 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_REAL data type."); |
173 STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_REAL data type."); |
94 } else if (NULL == symbol->datatype) { |
174 } else if (NULL == symbol->datatype) { |
95 STAGE3_ERROR(symbol, symbol, "ANY_REAL data type not valid in this location."); |
175 STAGE3_ERROR(4, symbol, symbol, "ANY_REAL data type not valid in this location."); |
96 } |
176 } |
97 return NULL; |
177 return NULL; |
98 } |
178 } |
99 |
179 |
100 void *print_datatypes_error_c::visit(integer_c *symbol) { |
180 void *print_datatypes_error_c::visit(integer_c *symbol) { |
101 if (symbol->candidate_datatypes.size() == 0) { |
181 if (symbol->candidate_datatypes.size() == 0) { |
102 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_INT data type."); |
182 STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type."); |
103 } else if (NULL == symbol->datatype) { |
183 } else if (NULL == symbol->datatype) { |
104 STAGE3_ERROR(symbol, symbol, "ANY_INT data type not valid in this location."); |
184 STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location."); |
105 } |
185 } |
106 return NULL; |
186 return NULL; |
107 } |
187 } |
108 |
188 |
109 void *print_datatypes_error_c::visit(neg_real_c *symbol) { |
189 void *print_datatypes_error_c::visit(neg_real_c *symbol) { |
110 if (symbol->candidate_datatypes.size() == 0) { |
190 if (symbol->candidate_datatypes.size() == 0) { |
111 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_REAL data type."); |
191 STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_REAL data type."); |
112 } else if (NULL == symbol->datatype) { |
192 } else if (NULL == symbol->datatype) { |
113 STAGE3_ERROR(symbol, symbol, "ANY_REAL data type not valid in this location."); |
193 STAGE3_ERROR(4, symbol, symbol, "ANY_REAL data type not valid in this location."); |
114 } |
194 } |
115 return NULL; |
195 return NULL; |
116 } |
196 } |
117 |
197 |
118 void *print_datatypes_error_c::visit(neg_integer_c *symbol) { |
198 void *print_datatypes_error_c::visit(neg_integer_c *symbol) { |
119 if (symbol->candidate_datatypes.size() == 0) { |
199 if (symbol->candidate_datatypes.size() == 0) { |
120 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_INT data type."); |
200 STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type."); |
121 } else if (NULL == symbol->datatype) { |
201 } else if (NULL == symbol->datatype) { |
122 STAGE3_ERROR(symbol, symbol, "ANY_INT data type not valid in this location."); |
202 STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location."); |
123 } |
203 } |
124 return NULL; |
204 return NULL; |
125 } |
205 } |
126 |
206 |
127 void *print_datatypes_error_c::visit(binary_integer_c *symbol) { |
207 void *print_datatypes_error_c::visit(binary_integer_c *symbol) { |
128 if (symbol->candidate_datatypes.size() == 0) { |
208 if (symbol->candidate_datatypes.size() == 0) { |
129 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_INT data type."); |
209 STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type."); |
130 } else if (NULL == symbol->datatype) { |
210 } else if (NULL == symbol->datatype) { |
131 STAGE3_ERROR(symbol, symbol, "ANY_INT data type not valid in this location."); |
211 STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location."); |
132 } |
212 } |
133 return NULL; |
213 return NULL; |
134 } |
214 } |
135 |
215 |
136 void *print_datatypes_error_c::visit(octal_integer_c *symbol) { |
216 void *print_datatypes_error_c::visit(octal_integer_c *symbol) { |
137 if (symbol->candidate_datatypes.size() == 0) { |
217 if (symbol->candidate_datatypes.size() == 0) { |
138 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_INT data type."); |
218 STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type."); |
139 } else if (NULL == symbol->datatype) { |
219 } else if (NULL == symbol->datatype) { |
140 STAGE3_ERROR(symbol, symbol, "ANY_INT data type not valid in this location."); |
220 STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location."); |
141 } |
221 } |
142 return NULL; |
222 return NULL; |
143 } |
223 } |
144 |
224 |
145 void *print_datatypes_error_c::visit(hex_integer_c *symbol) { |
225 void *print_datatypes_error_c::visit(hex_integer_c *symbol) { |
146 if (symbol->candidate_datatypes.size() == 0) { |
226 if (symbol->candidate_datatypes.size() == 0) { |
147 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_INT data type."); |
227 STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type."); |
148 } else if (NULL == symbol->datatype) { |
228 } else if (NULL == symbol->datatype) { |
149 STAGE3_ERROR(symbol, symbol, "ANY_INT data type not valid in this location."); |
229 STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location."); |
150 } |
230 } |
151 return NULL; |
231 return NULL; |
152 } |
232 } |
153 |
233 |
154 void *print_datatypes_error_c::visit(integer_literal_c *symbol) { |
234 void *print_datatypes_error_c::visit(integer_literal_c *symbol) { |
155 if (symbol->candidate_datatypes.size() == 0) { |
235 if (symbol->candidate_datatypes.size() == 0) { |
156 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_INT data type."); |
236 STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", elementary_type_c::to_string(symbol->type)); |
157 } else if (NULL == symbol->datatype) { |
237 } else if (NULL == symbol->datatype) { |
158 STAGE3_ERROR(symbol, symbol, "ANY_INT data type not valid in this location."); |
238 STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location."); |
159 } |
239 } |
160 return NULL; |
240 return NULL; |
161 } |
241 } |
162 |
242 |
163 void *print_datatypes_error_c::visit(real_literal_c *symbol) { |
243 void *print_datatypes_error_c::visit(real_literal_c *symbol) { |
164 if (symbol->candidate_datatypes.size() == 0) { |
244 if (symbol->candidate_datatypes.size() == 0) { |
165 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_REAL data type."); |
245 STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", elementary_type_c::to_string(symbol->type)); |
166 } else if (NULL == symbol->datatype) { |
246 } else if (NULL == symbol->datatype) { |
167 STAGE3_ERROR(symbol, symbol, "ANY_REAL data type not valid in this location."); |
247 STAGE3_ERROR(4, symbol, symbol, "ANY_REAL data type not valid in this location."); |
168 } |
248 } |
169 return NULL; |
249 return NULL; |
170 } |
250 } |
171 |
251 |
172 void *print_datatypes_error_c::visit(bit_string_literal_c *symbol) { |
252 void *print_datatypes_error_c::visit(bit_string_literal_c *symbol) { |
173 if (symbol->candidate_datatypes.size() == 0) { |
253 if (symbol->candidate_datatypes.size() == 0) { |
174 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_BIT data type."); |
254 STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", elementary_type_c::to_string(symbol->type)); |
175 } else if (NULL == symbol->datatype) { |
255 } else if (NULL == symbol->datatype) { |
176 STAGE3_ERROR(symbol, symbol, "ANY_BIT data type not valid in this location."); |
256 STAGE3_ERROR(4, symbol, symbol, "ANY_BIT data type not valid in this location."); |
177 } |
257 } |
178 return NULL; |
258 return NULL; |
179 } |
259 } |
180 |
260 |
181 void *print_datatypes_error_c::visit(boolean_literal_c *symbol) { |
261 void *print_datatypes_error_c::visit(boolean_literal_c *symbol) { |
182 if (symbol->candidate_datatypes.size() == 0) { |
262 if (symbol->candidate_datatypes.size() == 0) { |
183 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_BOOL data type."); |
263 STAGE3_ERROR(0, symbol, symbol, "Value is not valid for %s data type.", elementary_type_c::to_string(symbol->type)); |
184 } else if (NULL == symbol->datatype) { |
264 } else if (NULL == symbol->datatype) { |
185 STAGE3_ERROR(symbol, symbol, "ANY_BOOL data type not valid in this location."); |
265 STAGE3_ERROR(4, symbol, symbol, "ANY_BOOL data type not valid in this location."); |
186 } |
266 } |
187 return NULL; |
267 return NULL; |
188 } |
268 } |
189 |
269 |
190 void *print_datatypes_error_c::visit(boolean_true_c *symbol) { |
270 void *print_datatypes_error_c::visit(boolean_true_c *symbol) { |
191 if (symbol->candidate_datatypes.size() == 0) { |
271 if (symbol->candidate_datatypes.size() == 0) { |
192 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_BOOL data type."); |
272 STAGE3_ERROR(0, symbol, symbol, "Value is not valid for ANY_BOOL data type."); |
193 } else if (NULL == symbol->datatype) { |
273 } else if (NULL == symbol->datatype) { |
194 STAGE3_ERROR(symbol, symbol, "ANY_BOOL data type not valid in this location."); |
274 STAGE3_ERROR(4, symbol, symbol, "ANY_BOOL data type not valid in this location."); |
195 } |
275 } |
196 return NULL; |
276 return NULL; |
197 } |
277 } |
198 |
278 |
199 void *print_datatypes_error_c::visit(boolean_false_c *symbol) { |
279 void *print_datatypes_error_c::visit(boolean_false_c *symbol) { |
200 if (symbol->candidate_datatypes.size() == 0) { |
280 if (symbol->candidate_datatypes.size() == 0) { |
201 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_BOOL data type."); |
281 STAGE3_ERROR(0, symbol, symbol, "Value is not valid for ANY_BOOL data type."); |
202 } else if (NULL == symbol->datatype) { |
282 } else if (NULL == symbol->datatype) { |
203 STAGE3_ERROR(symbol, symbol, "ANY_BOOL data type not valid in this location."); |
283 STAGE3_ERROR(4, symbol, symbol, "ANY_BOOL data type not valid in this location."); |
204 } |
284 } |
205 return NULL; |
285 return NULL; |
206 } |
286 } |
207 |
287 |
208 /*******************************/ |
288 /*******************************/ |
209 /* B.1.2.2 Character Strings */ |
289 /* B.1.2.2 Character Strings */ |
210 /*******************************/ |
290 /*******************************/ |
211 void *print_datatypes_error_c::visit(double_byte_character_string_c *symbol) { |
291 void *print_datatypes_error_c::visit(double_byte_character_string_c *symbol) { |
212 if (symbol->candidate_datatypes.size() == 0) { |
292 if (symbol->candidate_datatypes.size() == 0) { |
213 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for WSTRING data type."); |
293 STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for WSTRING data type."); |
214 } else if (NULL == symbol->datatype) { |
294 } else if (NULL == symbol->datatype) { |
215 STAGE3_ERROR(symbol, symbol, "WSTRING data type not valid in this location."); |
295 STAGE3_ERROR(4, symbol, symbol, "WSTRING data type not valid in this location."); |
216 } |
296 } |
217 return NULL; |
297 return NULL; |
218 } |
298 } |
219 |
299 |
220 void *print_datatypes_error_c::visit(single_byte_character_string_c *symbol) { |
300 void *print_datatypes_error_c::visit(single_byte_character_string_c *symbol) { |
221 if (symbol->candidate_datatypes.size() == 0) { |
301 if (symbol->candidate_datatypes.size() == 0) { |
222 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for STRING data type."); |
302 STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for STRING data type."); |
223 } else if (NULL == symbol->datatype) { |
303 } else if (NULL == symbol->datatype) { |
224 STAGE3_ERROR(symbol, symbol, "STRING data type not valid in this location."); |
304 STAGE3_ERROR(4, symbol, symbol, "STRING data type not valid in this location."); |
225 } |
305 } |
226 return NULL; |
306 return NULL; |
227 } |
307 } |
228 |
308 |
229 /***************************/ |
309 /***************************/ |
232 /************************/ |
312 /************************/ |
233 /* B 1.2.3.1 - Duration */ |
313 /* B 1.2.3.1 - Duration */ |
234 /************************/ |
314 /************************/ |
235 void *print_datatypes_error_c::visit(duration_c *symbol) { |
315 void *print_datatypes_error_c::visit(duration_c *symbol) { |
236 if (symbol->candidate_datatypes.size() == 0) { |
316 if (symbol->candidate_datatypes.size() == 0) { |
237 STAGE3_ERROR(symbol, symbol, "Invalid syntax for TIME data type."); |
317 STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for TIME data type."); |
238 } else if (NULL == symbol->datatype) { |
318 } else if (NULL == symbol->datatype) { |
239 STAGE3_ERROR(symbol, symbol, "TIME data type not valid in this location."); |
319 STAGE3_ERROR(4, symbol, symbol, "TIME data type not valid in this location."); |
240 } |
320 } |
241 return NULL; |
321 return NULL; |
242 } |
322 } |
243 |
323 |
244 /************************************/ |
324 /************************************/ |
245 /* B 1.2.3.2 - Time of day and Date */ |
325 /* B 1.2.3.2 - Time of day and Date */ |
246 /************************************/ |
326 /************************************/ |
247 void *print_datatypes_error_c::visit(time_of_day_c *symbol) { |
327 void *print_datatypes_error_c::visit(time_of_day_c *symbol) { |
248 if (symbol->candidate_datatypes.size() == 0) { |
328 if (symbol->candidate_datatypes.size() == 0) { |
249 STAGE3_ERROR(symbol, symbol, "Invalid syntax for TOD data type."); |
329 STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for TOD data type."); |
250 } else if (NULL == symbol->datatype) { |
330 } else if (NULL == symbol->datatype) { |
251 STAGE3_ERROR(symbol, symbol, "TOD data type not valid in this location."); |
331 STAGE3_ERROR(4, symbol, symbol, "TOD data type not valid in this location."); |
252 } |
332 } |
253 return NULL; |
333 return NULL; |
254 } |
334 } |
255 |
335 |
256 void *print_datatypes_error_c::visit(date_c *symbol) { |
336 void *print_datatypes_error_c::visit(date_c *symbol) { |
257 if (symbol->candidate_datatypes.size() == 0) { |
337 if (symbol->candidate_datatypes.size() == 0) { |
258 STAGE3_ERROR(symbol, symbol, "Invalid syntax for DATE data type."); |
338 STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for DATE data type."); |
259 } else if (NULL == symbol->datatype) { |
339 } else if (NULL == symbol->datatype) { |
260 STAGE3_ERROR(symbol, symbol, "DATE data type not valid in this location."); |
340 STAGE3_ERROR(4, symbol, symbol, "DATE data type not valid in this location."); |
261 } |
341 } |
262 return NULL; |
342 return NULL; |
263 } |
343 } |
264 |
344 |
265 void *print_datatypes_error_c::visit(date_and_time_c *symbol) { |
345 void *print_datatypes_error_c::visit(date_and_time_c *symbol) { |
266 if (symbol->candidate_datatypes.size() == 0) { |
346 if (symbol->candidate_datatypes.size() == 0) { |
267 STAGE3_ERROR(symbol, symbol, "Invalid syntax for DT data type."); |
347 STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for DT data type."); |
268 } else if (NULL == symbol->datatype) { |
348 } else if (NULL == symbol->datatype) { |
269 STAGE3_ERROR(symbol, symbol, "DT data type not valid in this location."); |
349 STAGE3_ERROR(4, symbol, symbol, "DT data type not valid in this location."); |
270 } |
350 } |
271 return NULL; |
351 return NULL; |
272 } |
352 } |
273 |
353 |
274 /**********************/ |
354 /**********************/ |
283 return NULL; |
363 return NULL; |
284 } |
364 } |
285 |
365 |
286 void *print_datatypes_error_c::visit(enumerated_value_c *symbol) { |
366 void *print_datatypes_error_c::visit(enumerated_value_c *symbol) { |
287 if (symbol->candidate_datatypes.size() == 0) |
367 if (symbol->candidate_datatypes.size() == 0) |
288 STAGE3_ERROR(symbol, symbol, "Ambiguous enumerate value or Variable not declared in this scope."); |
368 STAGE3_ERROR(0, symbol, symbol, "Ambiguous enumerate value or Variable not declared in this scope."); |
289 return NULL; |
369 return NULL; |
290 } |
370 } |
291 |
371 |
292 |
372 |
293 /*********************/ |
373 /*********************/ |
294 /* B 1.4 - Variables */ |
374 /* B 1.4 - Variables */ |
295 /*********************/ |
375 /*********************/ |
296 void *print_datatypes_error_c::visit(symbolic_variable_c *symbol) { |
376 void *print_datatypes_error_c::visit(symbolic_variable_c *symbol) { |
297 if (symbol->candidate_datatypes.size() == 0) |
377 if (symbol->candidate_datatypes.size() == 0) |
298 STAGE3_ERROR(symbol, symbol, "Variable not declared in this scope."); |
378 STAGE3_ERROR(0, symbol, symbol, "Variable not declared in this scope."); |
299 return NULL; |
379 return NULL; |
300 } |
380 } |
301 |
381 |
302 /********************************************/ |
382 /********************************************/ |
303 /* B 1.4.1 - Directly Represented Variables */ |
383 /* B 1.4.1 - Directly Represented Variables */ |
304 /********************************************/ |
384 /********************************************/ |
305 void *print_datatypes_error_c::visit(direct_variable_c *symbol) { |
385 void *print_datatypes_error_c::visit(direct_variable_c *symbol) { |
306 if (symbol->candidate_datatypes.size() == 0) |
386 if (symbol->candidate_datatypes.size() == 0) |
307 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for located variable data type."); |
387 STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for located variable data type."); |
308 return NULL; |
388 return NULL; |
309 } |
389 } |
310 |
390 |
311 /*************************************/ |
391 /*************************************/ |
312 /* B 1.4.2 - Multi-element variables */ |
392 /* B 1.4.2 - Multi-element variables */ |
313 /*************************************/ |
393 /*************************************/ |
314 /* subscripted_variable '[' subscript_list ']' */ |
394 /* subscripted_variable '[' subscript_list ']' */ |
315 // SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
395 // SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
316 void *print_datatypes_error_c::visit(array_variable_c *symbol) { |
396 void *print_datatypes_error_c::visit(array_variable_c *symbol) { |
317 if (symbol->candidate_datatypes.size() == 0) |
397 if (symbol->candidate_datatypes.size() == 0) |
318 STAGE3_ERROR(symbol, symbol, "Array variable not declared in this scope."); |
398 STAGE3_ERROR(0, symbol, symbol, "Array variable not declared in this scope."); |
319 |
399 |
320 /* recursively call the subscript list to print any errors in the expressions used in the subscript...*/ |
400 /* recursively call the subscript list to print any errors in the expressions used in the subscript...*/ |
321 symbol->subscript_list->accept(*this); |
401 symbol->subscript_list->accept(*this); |
322 return NULL; |
402 return NULL; |
323 } |
403 } |
513 |
593 |
514 void *print_datatypes_error_c::visit(S_operator_c *symbol) { |
594 void *print_datatypes_error_c::visit(S_operator_c *symbol) { |
515 il_operand->accept(*this); |
595 il_operand->accept(*this); |
516 if ((symbol->candidate_datatypes.size() == 0) && |
596 if ((symbol->candidate_datatypes.size() == 0) && |
517 (il_operand->candidate_datatypes.size() > 0)) |
597 (il_operand->candidate_datatypes.size() > 0)) |
518 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'S' operator."); |
598 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'S' operator."); |
519 prev_il_instruction = symbol; |
599 prev_il_instruction = symbol; |
520 return NULL; |
600 return NULL; |
521 } |
601 } |
522 |
602 |
523 void *print_datatypes_error_c::visit(R_operator_c *symbol) { |
603 void *print_datatypes_error_c::visit(R_operator_c *symbol) { |
524 il_operand->accept(*this); |
604 il_operand->accept(*this); |
525 if ((symbol->candidate_datatypes.size() == 0) && |
605 if ((symbol->candidate_datatypes.size() == 0) && |
526 (il_operand->candidate_datatypes.size() > 0)) |
606 (il_operand->candidate_datatypes.size() > 0)) |
527 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'R' operator."); |
607 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'R' operator."); |
528 prev_il_instruction = symbol; |
608 prev_il_instruction = symbol; |
529 return NULL; |
609 return NULL; |
530 } |
610 } |
531 |
611 |
532 void *print_datatypes_error_c::visit(S1_operator_c *symbol) { |
612 void *print_datatypes_error_c::visit(S1_operator_c *symbol) { |
533 il_operand->accept(*this); |
613 il_operand->accept(*this); |
534 if ((symbol->candidate_datatypes.size() == 0) && |
614 if ((symbol->candidate_datatypes.size() == 0) && |
535 (il_operand->candidate_datatypes.size() > 0)) |
615 (il_operand->candidate_datatypes.size() > 0)) |
536 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'S1' operator."); |
616 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'S1' operator."); |
537 prev_il_instruction = symbol; |
617 prev_il_instruction = symbol; |
538 return NULL; |
618 return NULL; |
539 } |
619 } |
540 |
620 |
541 void *print_datatypes_error_c::visit(R1_operator_c *symbol) { |
621 void *print_datatypes_error_c::visit(R1_operator_c *symbol) { |
542 il_operand->accept(*this); |
622 il_operand->accept(*this); |
543 if ((symbol->candidate_datatypes.size() == 0) && |
623 if ((symbol->candidate_datatypes.size() == 0) && |
544 (il_operand->candidate_datatypes.size() > 0)) |
624 (il_operand->candidate_datatypes.size() > 0)) |
545 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'R1' operator."); |
625 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'R1' operator."); |
546 prev_il_instruction = symbol; |
626 prev_il_instruction = symbol; |
547 return NULL; |
627 return NULL; |
548 } |
628 } |
549 |
629 |
550 void *print_datatypes_error_c::visit(CLK_operator_c *symbol) { |
630 void *print_datatypes_error_c::visit(CLK_operator_c *symbol) { |
579 |
659 |
580 void *print_datatypes_error_c::visit(AND_operator_c *symbol) { |
660 void *print_datatypes_error_c::visit(AND_operator_c *symbol) { |
581 il_operand->accept(*this); |
661 il_operand->accept(*this); |
582 if ((symbol->candidate_datatypes.size() == 0) && |
662 if ((symbol->candidate_datatypes.size() == 0) && |
583 (il_operand->candidate_datatypes.size() > 0)) |
663 (il_operand->candidate_datatypes.size() > 0)) |
584 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'AND' operator."); |
664 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'AND' operator."); |
585 prev_il_instruction = symbol; |
665 prev_il_instruction = symbol; |
586 return NULL; |
666 return NULL; |
587 } |
667 } |
588 |
668 |
589 void *print_datatypes_error_c::visit(OR_operator_c *symbol) { |
669 void *print_datatypes_error_c::visit(OR_operator_c *symbol) { |
590 il_operand->accept(*this); |
670 il_operand->accept(*this); |
591 if ((symbol->candidate_datatypes.size() == 0) && |
671 if ((symbol->candidate_datatypes.size() == 0) && |
592 (il_operand->candidate_datatypes.size() > 0)) |
672 (il_operand->candidate_datatypes.size() > 0)) |
593 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'OR' operator."); |
673 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'OR' operator."); |
594 prev_il_instruction = symbol; |
674 prev_il_instruction = symbol; |
595 return NULL; |
675 return NULL; |
596 } |
676 } |
597 |
677 |
598 void *print_datatypes_error_c::visit(XOR_operator_c *symbol) { |
678 void *print_datatypes_error_c::visit(XOR_operator_c *symbol) { |
599 il_operand->accept(*this); |
679 il_operand->accept(*this); |
600 if ((symbol->candidate_datatypes.size() == 0) && |
680 if ((symbol->candidate_datatypes.size() == 0) && |
601 (il_operand->candidate_datatypes.size() > 0)) |
681 (il_operand->candidate_datatypes.size() > 0)) |
602 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'XOR' operator."); |
682 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'XOR' operator."); |
603 prev_il_instruction = symbol; |
683 prev_il_instruction = symbol; |
604 return NULL; |
684 return NULL; |
605 } |
685 } |
606 |
686 |
607 void *print_datatypes_error_c::visit(ANDN_operator_c *symbol) { |
687 void *print_datatypes_error_c::visit(ANDN_operator_c *symbol) { |
608 il_operand->accept(*this); |
688 il_operand->accept(*this); |
609 if ((symbol->candidate_datatypes.size() == 0) && |
689 if ((symbol->candidate_datatypes.size() == 0) && |
610 (il_operand->candidate_datatypes.size() > 0)) |
690 (il_operand->candidate_datatypes.size() > 0)) |
611 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'ANDN' operator."); |
691 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ANDN' operator."); |
612 prev_il_instruction = symbol; |
692 prev_il_instruction = symbol; |
613 return NULL; |
693 return NULL; |
614 } |
694 } |
615 |
695 |
616 void *print_datatypes_error_c::visit(ORN_operator_c *symbol) { |
696 void *print_datatypes_error_c::visit(ORN_operator_c *symbol) { |
617 il_operand->accept(*this); |
697 il_operand->accept(*this); |
618 if ((symbol->candidate_datatypes.size() == 0) && |
698 if ((symbol->candidate_datatypes.size() == 0) && |
619 (il_operand->candidate_datatypes.size() > 0)) |
699 (il_operand->candidate_datatypes.size() > 0)) |
620 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'ORN' operator."); |
700 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ORN' operator."); |
621 prev_il_instruction = symbol; |
701 prev_il_instruction = symbol; |
622 return NULL; |
702 return NULL; |
623 } |
703 } |
624 |
704 |
625 void *print_datatypes_error_c::visit(XORN_operator_c *symbol) { |
705 void *print_datatypes_error_c::visit(XORN_operator_c *symbol) { |
626 il_operand->accept(*this); |
706 il_operand->accept(*this); |
627 if ((symbol->candidate_datatypes.size() == 0) && |
707 if ((symbol->candidate_datatypes.size() == 0) && |
628 (il_operand->candidate_datatypes.size() > 0)) |
708 (il_operand->candidate_datatypes.size() > 0)) |
629 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'ORN' operator."); |
709 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ORN' operator."); |
630 prev_il_instruction = symbol; |
710 prev_il_instruction = symbol; |
631 return NULL; |
711 return NULL; |
632 } |
712 } |
633 |
713 |
634 void *print_datatypes_error_c::visit(ADD_operator_c *symbol) { |
714 void *print_datatypes_error_c::visit(ADD_operator_c *symbol) { |
635 il_operand->accept(*this); |
715 il_operand->accept(*this); |
636 if ((symbol->candidate_datatypes.size() == 0) && |
716 if ((symbol->candidate_datatypes.size() == 0) && |
637 (il_operand->candidate_datatypes.size() > 0)) |
717 (il_operand->candidate_datatypes.size() > 0)) |
638 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'ADD' operator."); |
718 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ADD' operator."); |
639 prev_il_instruction = symbol; |
719 prev_il_instruction = symbol; |
640 return NULL; |
720 return NULL; |
641 } |
721 } |
642 |
722 |
643 void *print_datatypes_error_c::visit(SUB_operator_c *symbol) { |
723 void *print_datatypes_error_c::visit(SUB_operator_c *symbol) { |
644 il_operand->accept(*this); |
724 il_operand->accept(*this); |
645 if ((symbol->candidate_datatypes.size() == 0) && |
725 if ((symbol->candidate_datatypes.size() == 0) && |
646 (il_operand->candidate_datatypes.size() > 0)) |
726 (il_operand->candidate_datatypes.size() > 0)) |
647 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'SUB' operator."); |
727 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'SUB' operator."); |
648 prev_il_instruction = symbol; |
728 prev_il_instruction = symbol; |
649 return NULL; |
729 return NULL; |
650 } |
730 } |
651 |
731 |
652 void *print_datatypes_error_c::visit(MUL_operator_c *symbol) { |
732 void *print_datatypes_error_c::visit(MUL_operator_c *symbol) { |
653 il_operand->accept(*this); |
733 il_operand->accept(*this); |
654 if ((symbol->candidate_datatypes.size() == 0) && |
734 if ((symbol->candidate_datatypes.size() == 0) && |
655 (il_operand->candidate_datatypes.size() > 0)) |
735 (il_operand->candidate_datatypes.size() > 0)) |
656 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'MUL' operator."); |
736 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'MUL' operator."); |
657 prev_il_instruction = symbol; |
737 prev_il_instruction = symbol; |
658 return NULL; |
738 return NULL; |
659 } |
739 } |
660 |
740 |
661 void *print_datatypes_error_c::visit(DIV_operator_c *symbol) { |
741 void *print_datatypes_error_c::visit(DIV_operator_c *symbol) { |
662 il_operand->accept(*this); |
742 il_operand->accept(*this); |
663 if ((symbol->candidate_datatypes.size() == 0) && |
743 if ((symbol->candidate_datatypes.size() == 0) && |
664 (il_operand->candidate_datatypes.size() > 0)) |
744 (il_operand->candidate_datatypes.size() > 0)) |
665 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'DIV' operator."); |
745 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'DIV' operator."); |
666 prev_il_instruction = symbol; |
746 prev_il_instruction = symbol; |
667 return NULL; |
747 return NULL; |
668 } |
748 } |
669 |
749 |
670 void *print_datatypes_error_c::visit(MOD_operator_c *symbol) { |
750 void *print_datatypes_error_c::visit(MOD_operator_c *symbol) { |
671 il_operand->accept(*this); |
751 il_operand->accept(*this); |
672 if ((symbol->candidate_datatypes.size() == 0) && |
752 if ((symbol->candidate_datatypes.size() == 0) && |
673 (il_operand->candidate_datatypes.size() > 0)) |
753 (il_operand->candidate_datatypes.size() > 0)) |
674 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'MOD' operator."); |
754 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'MOD' operator."); |
675 prev_il_instruction = symbol; |
755 prev_il_instruction = symbol; |
676 return NULL; |
756 return NULL; |
677 } |
757 } |
678 |
758 |
679 void *print_datatypes_error_c::visit(GT_operator_c *symbol) { |
759 void *print_datatypes_error_c::visit(GT_operator_c *symbol) { |
767 symbol->l_exp->accept(*this); |
847 symbol->l_exp->accept(*this); |
768 symbol->r_exp->accept(*this); |
848 symbol->r_exp->accept(*this); |
769 if ((symbol->candidate_datatypes.size() == 0) && |
849 if ((symbol->candidate_datatypes.size() == 0) && |
770 (symbol->l_exp->candidate_datatypes.size() > 0) && |
850 (symbol->l_exp->candidate_datatypes.size() > 0) && |
771 (symbol->r_exp->candidate_datatypes.size() > 0)) |
851 (symbol->r_exp->candidate_datatypes.size() > 0)) |
772 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'OR' expression."); |
852 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'OR' expression."); |
773 return NULL; |
853 return NULL; |
774 } |
854 } |
775 |
855 |
776 |
856 |
777 void *print_datatypes_error_c::visit(xor_expression_c *symbol) { |
857 void *print_datatypes_error_c::visit(xor_expression_c *symbol) { |
778 symbol->l_exp->accept(*this); |
858 symbol->l_exp->accept(*this); |
779 symbol->r_exp->accept(*this); |
859 symbol->r_exp->accept(*this); |
780 if ((symbol->candidate_datatypes.size() == 0) && |
860 if ((symbol->candidate_datatypes.size() == 0) && |
781 (symbol->l_exp->candidate_datatypes.size() > 0) && |
861 (symbol->l_exp->candidate_datatypes.size() > 0) && |
782 (symbol->r_exp->candidate_datatypes.size() > 0)) |
862 (symbol->r_exp->candidate_datatypes.size() > 0)) |
783 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'XOR' expression."); |
863 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'XOR' expression."); |
784 return NULL; |
864 return NULL; |
785 } |
865 } |
786 |
866 |
787 |
867 |
788 void *print_datatypes_error_c::visit(and_expression_c *symbol) { |
868 void *print_datatypes_error_c::visit(and_expression_c *symbol) { |
789 symbol->l_exp->accept(*this); |
869 symbol->l_exp->accept(*this); |
790 symbol->r_exp->accept(*this); |
870 symbol->r_exp->accept(*this); |
791 if ((symbol->candidate_datatypes.size() == 0) && |
871 if ((symbol->candidate_datatypes.size() == 0) && |
792 (symbol->l_exp->candidate_datatypes.size() > 0) && |
872 (symbol->l_exp->candidate_datatypes.size() > 0) && |
793 (symbol->r_exp->candidate_datatypes.size() > 0)) |
873 (symbol->r_exp->candidate_datatypes.size() > 0)) |
794 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'AND' expression."); |
874 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'AND' expression."); |
795 return NULL; |
875 return NULL; |
796 } |
876 } |
797 |
877 |
798 |
878 |
799 void *print_datatypes_error_c::visit(equ_expression_c *symbol) { |
879 void *print_datatypes_error_c::visit(equ_expression_c *symbol) { |
800 symbol->l_exp->accept(*this); |
880 symbol->l_exp->accept(*this); |
801 symbol->r_exp->accept(*this); |
881 symbol->r_exp->accept(*this); |
802 if ((symbol->candidate_datatypes.size() == 0) && |
882 if ((symbol->candidate_datatypes.size() == 0) && |
803 (symbol->l_exp->candidate_datatypes.size() > 0) && |
883 (symbol->l_exp->candidate_datatypes.size() > 0) && |
804 (symbol->r_exp->candidate_datatypes.size() > 0)) |
884 (symbol->r_exp->candidate_datatypes.size() > 0)) |
805 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '=' expression."); |
885 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '=' expression."); |
806 return NULL; |
886 return NULL; |
807 } |
887 } |
808 |
888 |
809 |
889 |
810 void *print_datatypes_error_c::visit(notequ_expression_c *symbol) { |
890 void *print_datatypes_error_c::visit(notequ_expression_c *symbol) { |
811 symbol->l_exp->accept(*this); |
891 symbol->l_exp->accept(*this); |
812 symbol->r_exp->accept(*this); |
892 symbol->r_exp->accept(*this); |
813 if ((symbol->candidate_datatypes.size() == 0) && |
893 if ((symbol->candidate_datatypes.size() == 0) && |
814 (symbol->l_exp->candidate_datatypes.size() > 0) && |
894 (symbol->l_exp->candidate_datatypes.size() > 0) && |
815 (symbol->r_exp->candidate_datatypes.size() > 0)) |
895 (symbol->r_exp->candidate_datatypes.size() > 0)) |
816 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '<>' expression."); |
896 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '<>' expression."); |
817 return NULL; |
897 return NULL; |
818 } |
898 } |
819 |
899 |
820 |
900 |
821 void *print_datatypes_error_c::visit(lt_expression_c *symbol) { |
901 void *print_datatypes_error_c::visit(lt_expression_c *symbol) { |
822 symbol->l_exp->accept(*this); |
902 symbol->l_exp->accept(*this); |
823 symbol->r_exp->accept(*this); |
903 symbol->r_exp->accept(*this); |
824 if ((symbol->candidate_datatypes.size() == 0) && |
904 if ((symbol->candidate_datatypes.size() == 0) && |
825 (symbol->l_exp->candidate_datatypes.size() > 0) && |
905 (symbol->l_exp->candidate_datatypes.size() > 0) && |
826 (symbol->r_exp->candidate_datatypes.size() > 0)) |
906 (symbol->r_exp->candidate_datatypes.size() > 0)) |
827 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '<' expression."); |
907 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '<' expression."); |
828 return NULL; |
908 return NULL; |
829 } |
909 } |
830 |
910 |
831 |
911 |
832 void *print_datatypes_error_c::visit(gt_expression_c *symbol) { |
912 void *print_datatypes_error_c::visit(gt_expression_c *symbol) { |
833 symbol->l_exp->accept(*this); |
913 symbol->l_exp->accept(*this); |
834 symbol->r_exp->accept(*this); |
914 symbol->r_exp->accept(*this); |
835 if ((symbol->candidate_datatypes.size() == 0) && |
915 if ((symbol->candidate_datatypes.size() == 0) && |
836 (symbol->l_exp->candidate_datatypes.size() > 0) && |
916 (symbol->l_exp->candidate_datatypes.size() > 0) && |
837 (symbol->r_exp->candidate_datatypes.size() > 0)) |
917 (symbol->r_exp->candidate_datatypes.size() > 0)) |
838 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '>' expression."); |
918 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '>' expression."); |
839 return NULL; |
919 return NULL; |
840 } |
920 } |
841 |
921 |
842 |
922 |
843 void *print_datatypes_error_c::visit(le_expression_c *symbol) { |
923 void *print_datatypes_error_c::visit(le_expression_c *symbol) { |
844 symbol->l_exp->accept(*this); |
924 symbol->l_exp->accept(*this); |
845 symbol->r_exp->accept(*this); |
925 symbol->r_exp->accept(*this); |
846 if ((symbol->candidate_datatypes.size() == 0) && |
926 if ((symbol->candidate_datatypes.size() == 0) && |
847 (symbol->l_exp->candidate_datatypes.size() > 0) && |
927 (symbol->l_exp->candidate_datatypes.size() > 0) && |
848 (symbol->r_exp->candidate_datatypes.size() > 0)) |
928 (symbol->r_exp->candidate_datatypes.size() > 0)) |
849 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '<=' expression."); |
929 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '<=' expression."); |
850 return NULL; |
930 return NULL; |
851 } |
931 } |
852 |
932 |
853 |
933 |
854 void *print_datatypes_error_c::visit(ge_expression_c *symbol) { |
934 void *print_datatypes_error_c::visit(ge_expression_c *symbol) { |
855 symbol->l_exp->accept(*this); |
935 symbol->l_exp->accept(*this); |
856 symbol->r_exp->accept(*this); |
936 symbol->r_exp->accept(*this); |
857 if ((symbol->candidate_datatypes.size() == 0) && |
937 if ((symbol->candidate_datatypes.size() == 0) && |
858 (symbol->l_exp->candidate_datatypes.size() > 0) && |
938 (symbol->l_exp->candidate_datatypes.size() > 0) && |
859 (symbol->r_exp->candidate_datatypes.size() > 0)) |
939 (symbol->r_exp->candidate_datatypes.size() > 0)) |
860 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '>=' expression."); |
940 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '>=' expression."); |
861 return NULL; |
941 return NULL; |
862 } |
942 } |
863 |
943 |
864 |
944 |
865 void *print_datatypes_error_c::visit(add_expression_c *symbol) { |
945 void *print_datatypes_error_c::visit(add_expression_c *symbol) { |
866 symbol->l_exp->accept(*this); |
946 symbol->l_exp->accept(*this); |
867 symbol->r_exp->accept(*this); |
947 symbol->r_exp->accept(*this); |
868 if ((symbol->candidate_datatypes.size() == 0) && |
948 if ((symbol->candidate_datatypes.size() == 0) && |
869 (symbol->l_exp->candidate_datatypes.size() > 0) && |
949 (symbol->l_exp->candidate_datatypes.size() > 0) && |
870 (symbol->r_exp->candidate_datatypes.size() > 0)) |
950 (symbol->r_exp->candidate_datatypes.size() > 0)) |
871 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '+' expression."); |
951 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '+' expression."); |
872 |
952 |
873 return NULL; |
953 return NULL; |
874 } |
954 } |
875 |
955 |
876 |
956 |
879 symbol->l_exp->accept(*this); |
959 symbol->l_exp->accept(*this); |
880 symbol->r_exp->accept(*this); |
960 symbol->r_exp->accept(*this); |
881 if ((symbol->candidate_datatypes.size() == 0) && |
961 if ((symbol->candidate_datatypes.size() == 0) && |
882 (symbol->l_exp->candidate_datatypes.size() > 0) && |
962 (symbol->l_exp->candidate_datatypes.size() > 0) && |
883 (symbol->r_exp->candidate_datatypes.size() > 0)) |
963 (symbol->r_exp->candidate_datatypes.size() > 0)) |
884 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '-' expression."); |
964 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '-' expression."); |
885 return NULL; |
965 return NULL; |
886 } |
966 } |
887 |
967 |
888 void *print_datatypes_error_c::visit(mul_expression_c *symbol) { |
968 void *print_datatypes_error_c::visit(mul_expression_c *symbol) { |
889 symbol->l_exp->accept(*this); |
969 symbol->l_exp->accept(*this); |
890 symbol->r_exp->accept(*this); |
970 symbol->r_exp->accept(*this); |
891 if ((symbol->candidate_datatypes.size() == 0) && |
971 if ((symbol->candidate_datatypes.size() == 0) && |
892 (symbol->l_exp->candidate_datatypes.size() > 0) && |
972 (symbol->l_exp->candidate_datatypes.size() > 0) && |
893 (symbol->r_exp->candidate_datatypes.size() > 0)) |
973 (symbol->r_exp->candidate_datatypes.size() > 0)) |
894 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '*' expression."); |
974 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '*' expression."); |
895 return NULL; |
975 return NULL; |
896 } |
976 } |
897 |
977 |
898 void *print_datatypes_error_c::visit(div_expression_c *symbol) { |
978 void *print_datatypes_error_c::visit(div_expression_c *symbol) { |
899 symbol->l_exp->accept(*this); |
979 symbol->l_exp->accept(*this); |
900 symbol->r_exp->accept(*this); |
980 symbol->r_exp->accept(*this); |
901 if ((symbol->candidate_datatypes.size() == 0) && |
981 if ((symbol->candidate_datatypes.size() == 0) && |
902 (symbol->l_exp->candidate_datatypes.size() > 0) && |
982 (symbol->l_exp->candidate_datatypes.size() > 0) && |
903 (symbol->r_exp->candidate_datatypes.size() > 0)) |
983 (symbol->r_exp->candidate_datatypes.size() > 0)) |
904 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '/' expression."); |
984 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '/' expression."); |
905 return NULL; |
985 return NULL; |
906 } |
986 } |
907 |
987 |
908 |
988 |
909 void *print_datatypes_error_c::visit(mod_expression_c *symbol) { |
989 void *print_datatypes_error_c::visit(mod_expression_c *symbol) { |
910 symbol->l_exp->accept(*this); |
990 symbol->l_exp->accept(*this); |
911 symbol->r_exp->accept(*this); |
991 symbol->r_exp->accept(*this); |
912 if ((symbol->candidate_datatypes.size() == 0) && |
992 if ((symbol->candidate_datatypes.size() == 0) && |
913 (symbol->l_exp->candidate_datatypes.size() > 0) && |
993 (symbol->l_exp->candidate_datatypes.size() > 0) && |
914 (symbol->r_exp->candidate_datatypes.size() > 0)) |
994 (symbol->r_exp->candidate_datatypes.size() > 0)) |
915 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'MOD' expression."); |
995 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'MOD' expression."); |
916 return NULL; |
996 return NULL; |
917 } |
997 } |
918 |
998 |
919 |
999 |
920 void *print_datatypes_error_c::visit(power_expression_c *symbol) { |
1000 void *print_datatypes_error_c::visit(power_expression_c *symbol) { |
921 symbol->l_exp->accept(*this); |
1001 symbol->l_exp->accept(*this); |
922 symbol->r_exp->accept(*this); |
1002 symbol->r_exp->accept(*this); |
923 if ((symbol->candidate_datatypes.size() == 0) && |
1003 if ((symbol->candidate_datatypes.size() == 0) && |
924 (symbol->l_exp->candidate_datatypes.size() > 0) && |
1004 (symbol->l_exp->candidate_datatypes.size() > 0) && |
925 (symbol->r_exp->candidate_datatypes.size() > 0)) |
1005 (symbol->r_exp->candidate_datatypes.size() > 0)) |
926 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '**' expression."); |
1006 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '**' expression."); |
927 return NULL; |
1007 return NULL; |
928 } |
1008 } |
929 |
1009 |
930 |
1010 |
931 void *print_datatypes_error_c::visit(neg_expression_c *symbol) { |
1011 void *print_datatypes_error_c::visit(neg_expression_c *symbol) { |
932 symbol->exp->accept(*this); |
1012 symbol->exp->accept(*this); |
933 if ((symbol->candidate_datatypes.size() == 0) && |
1013 if ((symbol->candidate_datatypes.size() == 0) && |
934 (symbol->exp->candidate_datatypes.size() > 0)) |
1014 (symbol->exp->candidate_datatypes.size() > 0)) |
935 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'NEG' expression."); |
1015 STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'NEG' expression."); |
936 return NULL; |
1016 return NULL; |
937 } |
1017 } |
938 |
1018 |
939 |
1019 |
940 void *print_datatypes_error_c::visit(not_expression_c *symbol) { |
1020 void *print_datatypes_error_c::visit(not_expression_c *symbol) { |
941 symbol->exp->accept(*this); |
1021 symbol->exp->accept(*this); |
942 if ((symbol->candidate_datatypes.size() == 0) && |
1022 if ((symbol->candidate_datatypes.size() == 0) && |
943 (symbol->exp->candidate_datatypes.size() > 0)) |
1023 (symbol->exp->candidate_datatypes.size() > 0)) |
944 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'NOT' expression."); |
1024 STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'NOT' expression."); |
945 return NULL; |
1025 return NULL; |
946 } |
1026 } |
947 |
1027 |
948 |
1028 |
949 void *print_datatypes_error_c::visit(function_invocation_c *symbol) { |
1029 void *print_datatypes_error_c::visit(function_invocation_c *symbol) { |
1101 symbol->beg_expression->accept(*this); |
1185 symbol->beg_expression->accept(*this); |
1102 symbol->end_expression->accept(*this); |
1186 symbol->end_expression->accept(*this); |
1103 /* Control variable */ |
1187 /* Control variable */ |
1104 if ((NULL == symbol->control_variable->datatype) && |
1188 if ((NULL == symbol->control_variable->datatype) && |
1105 (symbol->control_variable->candidate_datatypes.size() > 0)) { |
1189 (symbol->control_variable->candidate_datatypes.size() > 0)) { |
1106 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'FOR' control variable."); |
1190 STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'FOR' control variable."); |
1107 } |
1191 } |
1108 /* BEG expression */ |
1192 /* BEG expression */ |
1109 if ((NULL == symbol->beg_expression->datatype) && |
1193 if ((NULL == symbol->beg_expression->datatype) && |
1110 (symbol->beg_expression->candidate_datatypes.size() > 0)) { |
1194 (symbol->beg_expression->candidate_datatypes.size() > 0)) { |
1111 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'FOR' begin expression."); |
1195 STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'FOR' begin expression."); |
1112 } |
1196 } |
1113 /* END expression */ |
1197 /* END expression */ |
1114 if ((NULL == symbol->end_expression->datatype) && |
1198 if ((NULL == symbol->end_expression->datatype) && |
1115 (symbol->end_expression->candidate_datatypes.size() > 0)) { |
1199 (symbol->end_expression->candidate_datatypes.size() > 0)) { |
1116 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'FOR' end expression."); |
1200 STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'FOR' end expression."); |
1117 } |
1201 } |
1118 /* BY expression */ |
1202 /* BY expression */ |
1119 if ((NULL != symbol->by_expression) && |
1203 if ((NULL != symbol->by_expression) && |
1120 (NULL == symbol->by_expression->datatype) && |
1204 (NULL == symbol->by_expression->datatype) && |
1121 (symbol->end_expression->candidate_datatypes.size() > 0)) { |
1205 (symbol->end_expression->candidate_datatypes.size() > 0)) { |
1122 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'FOR' by expression."); |
1206 STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'FOR' by expression."); |
1123 } |
1207 } |
1124 /* DO statement */ |
1208 /* DO statement */ |
1125 if (NULL != symbol->statement_list) |
1209 if (NULL != symbol->statement_list) |
1126 symbol->statement_list->accept(*this); |
1210 symbol->statement_list->accept(*this); |
1127 |
1211 |