73 #define IS_OVERFLOW(dtype, symbol) (symbol_c::cs_overflow == (symbol)->const_value._##dtype.status) |
73 #define IS_OVERFLOW(dtype, symbol) (symbol_c::cs_overflow == (symbol)->const_value._##dtype.status) |
74 |
74 |
75 |
75 |
76 |
76 |
77 |
77 |
78 #define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order) ? (symbol1) : (symbol2)) |
|
79 #define LAST_(symbol1, symbol2) (((symbol1)->last_order > (symbol2)->last_order) ? (symbol1) : (symbol2)) |
|
80 |
|
81 |
|
82 #define STAGE3_ERROR(error_level, symbol1, symbol2, ...) { \ |
|
83 fprintf(stderr, "%s:%d-%d..%d-%d: error: ", \ |
|
84 FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\ |
|
85 LAST_(symbol1,symbol2) ->last_line, LAST_(symbol1,symbol2) ->last_column);\ |
|
86 fprintf(stderr, __VA_ARGS__); \ |
|
87 fprintf(stderr, "\n"); \ |
|
88 } |
|
89 |
|
90 |
|
91 #define STAGE3_WARNING(symbol1, symbol2, ...) { \ |
|
92 fprintf(stderr, "%s:%d-%d..%d-%d: warning: ", \ |
|
93 FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\ |
|
94 LAST_(symbol1,symbol2) ->last_line, LAST_(symbol1,symbol2) ->last_column);\ |
|
95 fprintf(stderr, __VA_ARGS__); \ |
|
96 fprintf(stderr, "\n"); \ |
|
97 } |
|
98 |
|
99 |
|
100 |
|
101 /* set to 1 to see debug info during execution */ |
78 /* set to 1 to see debug info during execution */ |
102 static int debug = 0; |
79 static int debug = 0; |
103 |
80 |
104 |
81 |
105 |
82 |
159 enumerated_value_symtable_t::iterator lower = global_enumerated_value_symtable.lower_bound(symbol->value); |
136 enumerated_value_symtable_t::iterator lower = global_enumerated_value_symtable.lower_bound(symbol->value); |
160 enumerated_value_symtable_t::iterator upper = global_enumerated_value_symtable.upper_bound(symbol->value); |
137 enumerated_value_symtable_t::iterator upper = global_enumerated_value_symtable.upper_bound(symbol->value); |
161 for (; lower != upper; lower++) |
138 for (; lower != upper; lower++) |
162 if (lower->second == current_enumerated_type) { |
139 if (lower->second == current_enumerated_type) { |
163 /* The same identifier is used more than once as an enumerated value/constant inside the same enumerated datat type! */ |
140 /* The same identifier is used more than once as an enumerated value/constant inside the same enumerated datat type! */ |
164 STAGE3_ERROR(0, symbol, symbol, "Duplicate identifier in enumerated data type."); |
|
165 return NULL; /* No need to insert it! It is already in the table! */ |
141 return NULL; /* No need to insert it! It is already in the table! */ |
166 } |
142 } |
167 |
143 |
168 global_enumerated_value_symtable.insert(symbol->value, current_enumerated_type); |
144 global_enumerated_value_symtable.insert(symbol->value, current_enumerated_type); |
169 return NULL; |
145 return NULL; |
227 */ |
203 */ |
228 |
204 |
229 static enumerated_value_symtable_t local_enumerated_value_symtable; |
205 static enumerated_value_symtable_t local_enumerated_value_symtable; |
230 |
206 |
231 |
207 |
232 class populate_enumvalue_symtable_c: public iterator_visitor_c { |
208 class populate_localenumvalue_symtable_c: public iterator_visitor_c { |
233 private: |
209 private: |
234 symbol_c *current_enumerated_type; |
210 symbol_c *current_enumerated_type; |
235 |
211 |
236 public: |
212 public: |
237 populate_enumvalue_symtable_c(void) {current_enumerated_type = NULL;}; |
213 populate_localenumvalue_symtable_c(void) {current_enumerated_type = NULL;}; |
238 ~populate_enumvalue_symtable_c(void) {} |
214 ~populate_localenumvalue_symtable_c(void) {} |
239 |
215 |
240 public: |
216 public: |
241 /*************************/ |
217 /*************************/ |
242 /* B.1 - Common elements */ |
218 /* B.1 - Common elements */ |
243 /*************************/ |
219 /*************************/ |
269 enumerated_value_symtable_t::iterator lower = local_enumerated_value_symtable.lower_bound(symbol->value); |
245 enumerated_value_symtable_t::iterator lower = local_enumerated_value_symtable.lower_bound(symbol->value); |
270 enumerated_value_symtable_t::iterator upper = local_enumerated_value_symtable.upper_bound(symbol->value); |
246 enumerated_value_symtable_t::iterator upper = local_enumerated_value_symtable.upper_bound(symbol->value); |
271 for (; lower != upper; lower++) |
247 for (; lower != upper; lower++) |
272 if (lower->second == current_enumerated_type) { |
248 if (lower->second == current_enumerated_type) { |
273 /* The same identifier is used more than once as an enumerated value/constant inside the same enumerated datat type! */ |
249 /* The same identifier is used more than once as an enumerated value/constant inside the same enumerated datat type! */ |
274 STAGE3_ERROR(0, symbol, symbol, "Duplicate identifier in enumerated data type."); |
|
275 return NULL; /* No need to insert it! It is already in the table! */ |
250 return NULL; /* No need to insert it! It is already in the table! */ |
276 } |
251 } |
277 |
252 |
278 /* add it to the local symbol table. */ |
253 /* add it to the local symbol table. */ |
279 local_enumerated_value_symtable.insert(symbol->value, current_enumerated_type); |
254 local_enumerated_value_symtable.insert(symbol->value, current_enumerated_type); |
280 return NULL; |
255 return NULL; |
281 } |
256 } |
282 }; // class populate_enumvalue_symtable_c |
257 }; // class populate_enumvalue_symtable_c |
283 |
258 |
284 static populate_enumvalue_symtable_c populate_enumvalue_symtable; |
259 static populate_localenumvalue_symtable_c populate_enumvalue_symtable; |
285 |
260 |
286 |
261 |
287 |
262 |
288 |
263 |
289 /*****************************************************/ |
264 /*****************************************************/ |