changeset 160 | 59d58f5e6caa |
parent 152 | efc510145ab2 |
child 164 | a0679c78143a |
159:1e4eb0d48385 | 160:59d58f5e6caa |
---|---|
54 varlistparse_am |
54 varlistparse_am |
55 } arrayinitialization_mode_t; |
55 } arrayinitialization_mode_t; |
56 |
56 |
57 arrayinitialization_mode_t current_mode; |
57 arrayinitialization_mode_t current_mode; |
58 |
58 |
59 symbol_c* array_base_type; |
|
59 symbol_c* array_default_value; |
60 symbol_c* array_default_value; |
61 symbol_c* array_default_initialization; |
|
60 |
62 |
61 private: |
63 private: |
62 int dimension_number, current_dimension, array_size; |
64 int dimension_number; |
65 int current_dimension; |
|
66 int array_size; |
|
67 int defined_values_count; |
|
68 int current_initialization_count; |
|
63 |
69 |
64 public: |
70 public: |
65 generate_c_array_initialization_c(stage4out_c *s4o_ptr): generate_c_typedecl_c(s4o_ptr) {} |
71 generate_c_array_initialization_c(stage4out_c *s4o_ptr): generate_c_typedecl_c(s4o_ptr) {} |
66 ~generate_c_array_initialization_c(void) {} |
72 ~generate_c_array_initialization_c(void) {} |
67 |
73 |
74 void init_array_dimensions(symbol_c *array_specification) { |
|
75 dimension_number = 0; |
|
76 current_dimension = 0; |
|
77 array_size = 1; |
|
78 defined_values_count = 0; |
|
79 current_initialization_count = 0; |
|
80 array_base_type = array_default_value = array_default_initialization = NULL; |
|
81 |
|
82 current_mode = dimensioncount_am; |
|
83 array_specification->accept(*this); |
|
84 } |
|
85 |
|
68 void init_array(symbol_c *var1_list, symbol_c *array_specification, symbol_c *array_initialization) { |
86 void init_array(symbol_c *var1_list, symbol_c *array_specification, symbol_c *array_initialization) { |
69 int i; |
87 int i; |
70 |
88 |
71 dimension_number = 0; |
89 init_array_dimensions(array_specification); |
72 current_dimension = 0; |
|
73 array_size = 1; |
|
74 array_default_value = NULL; |
|
75 |
|
76 current_mode = dimensioncount_am; |
|
77 array_specification->accept(*this); |
|
78 |
90 |
79 current_mode = initializationvalue_am; |
91 current_mode = initializationvalue_am; |
80 s4o.print("\n"); |
92 s4o.print("\n"); |
81 s4o.print(s4o.indent_spaces + "{\n"); |
93 s4o.print(s4o.indent_spaces + "{\n"); |
82 s4o.indent_right(); |
94 s4o.indent_right(); |
84 print_integer(dimension_number); |
96 print_integer(dimension_number); |
85 s4o.print("];\n"); |
97 s4o.print("];\n"); |
86 s4o.print(s4o.indent_spaces); |
98 s4o.print(s4o.indent_spaces); |
87 array_specification->accept(*this); |
99 array_specification->accept(*this); |
88 s4o.print(" temp = "); |
100 s4o.print(" temp = "); |
89 array_initialization->accept(*this); |
101 init_array_values(array_initialization); |
90 s4o.print(";\n"); |
102 s4o.print(";\n"); |
91 |
103 |
92 current_mode = arrayassignment_am; |
104 current_mode = arrayassignment_am; |
93 array_specification->accept(*this); |
105 array_specification->accept(*this); |
94 |
106 |
101 s4o.print(s4o.indent_spaces + "}\n"); |
113 s4o.print(s4o.indent_spaces + "}\n"); |
102 } |
114 } |
103 s4o.indent_left(); |
115 s4o.indent_left(); |
104 s4o.print(s4o.indent_spaces + "}"); |
116 s4o.print(s4o.indent_spaces + "}"); |
105 } |
117 } |
106 |
118 |
119 void init_array_values(symbol_c *array_initialization) { |
|
120 s4o.print("{"); |
|
121 array_initialization->accept(*this); |
|
122 if (array_default_initialization != NULL && defined_values_count < array_size) |
|
123 array_default_initialization->accept(*this); |
|
124 if (defined_values_count < array_size) { |
|
125 for (int i = defined_values_count; i < array_size; i++) { |
|
126 if (defined_values_count > 0) |
|
127 s4o.print(", "); |
|
128 array_default_value->accept(*this); |
|
129 defined_values_count++; |
|
130 } |
|
131 } |
|
132 s4o.print("}"); |
|
133 } |
|
134 |
|
107 void *visit(identifier_c *type_name) { |
135 void *visit(identifier_c *type_name) { |
108 symbol_c *type_decl; |
136 symbol_c *type_decl; |
109 switch (current_mode) { |
137 switch (current_mode) { |
110 case dimensioncount_am: |
138 case dimensioncount_am: |
111 case arrayassignment_am: |
139 case arrayassignment_am: |
148 |
176 |
149 /********************************/ |
177 /********************************/ |
150 /* B 1.3.3 - Derived data types */ |
178 /* B 1.3.3 - Derived data types */ |
151 /********************************/ |
179 /********************************/ |
152 |
180 |
181 /* array_specification [ASSIGN array_initialization] */ |
|
182 /* array_initialization may be NULL ! */ |
|
183 void *visit(array_spec_init_c *symbol) { |
|
184 switch (current_mode) { |
|
185 case dimensioncount_am: |
|
186 array_default_initialization = symbol->array_initialization; |
|
187 break; |
|
188 default: |
|
189 break; |
|
190 } |
|
191 symbol->array_specification->accept(*this); |
|
192 return NULL; |
|
193 } |
|
194 |
|
153 /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
195 /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
154 void *visit(array_specification_c *symbol) { |
196 void *visit(array_specification_c *symbol) { |
197 symbol->array_subrange_list->accept(*this); |
|
155 switch (current_mode) { |
198 switch (current_mode) { |
156 case dimensioncount_am: |
199 case dimensioncount_am: |
157 symbol->array_subrange_list->accept(*this); |
200 array_base_type = symbol->non_generic_type_name; |
158 array_default_value = (symbol_c *)symbol->non_generic_type_name->accept(*type_initial_value_c::instance());; |
201 array_default_value = (symbol_c *)symbol->non_generic_type_name->accept(*type_initial_value_c::instance());; |
202 if (array_default_value == NULL) ERROR; |
|
159 break; |
203 break; |
160 default: |
204 default: |
161 symbol->array_subrange_list->accept(*this); |
|
162 break; |
205 break; |
163 } |
206 } |
164 return NULL; |
207 return NULL; |
165 } |
208 } |
166 |
209 |
194 /* helper symbol for array_initialization */ |
237 /* helper symbol for array_initialization */ |
195 /* array_initial_elements_list ',' array_initial_elements */ |
238 /* array_initial_elements_list ',' array_initial_elements */ |
196 void *visit(array_initial_elements_list_c *symbol) { |
239 void *visit(array_initial_elements_list_c *symbol) { |
197 switch (current_mode) { |
240 switch (current_mode) { |
198 case initializationvalue_am: |
241 case initializationvalue_am: |
199 int i; |
242 current_initialization_count = 0; |
200 |
243 for (int i = 0; i < symbol->n; i++) { |
201 s4o.print("{"); |
244 if (current_initialization_count >= defined_values_count) { |
202 for (i = 0; i < symbol->n; i++) { |
245 if (defined_values_count >= array_size) |
203 if (i > 0) |
246 ERROR; |
204 s4o.print(", "); |
247 if (defined_values_count > 0) |
205 symbol->elements[i]->accept(*this); |
248 s4o.print(", "); |
206 array_size--; |
249 symbol->elements[i]->accept(*this); |
250 defined_values_count++; |
|
251 } |
|
252 else { |
|
253 array_initial_elements_c *array_initial_element = dynamic_cast<array_initial_elements_c *>(symbol->elements[i]); |
|
254 |
|
255 if (array_initial_element != NULL) |
|
256 symbol->elements[i]->accept(*this); |
|
257 } |
|
258 current_initialization_count++; |
|
207 } |
259 } |
208 if (array_size > 0) { |
|
209 if (symbol->n > 0) |
|
210 s4o.print(", "); |
|
211 for (i = 0; i < array_size; i++) { |
|
212 if (i > 0) |
|
213 s4o.print(", "); |
|
214 array_default_value->accept(*this); |
|
215 } |
|
216 } |
|
217 s4o.print("}"); |
|
218 break; |
260 break; |
219 default: |
261 default: |
220 break; |
262 break; |
221 } |
263 } |
222 return NULL; |
264 return NULL; |
228 int initial_element_number; |
270 int initial_element_number; |
229 |
271 |
230 switch (current_mode) { |
272 switch (current_mode) { |
231 case initializationvalue_am: |
273 case initializationvalue_am: |
232 initial_element_number = extract_integer(symbol->integer); |
274 initial_element_number = extract_integer(symbol->integer); |
233 |
275 if (current_initialization_count < defined_values_count) { |
276 int temp_element_number = 0; |
|
277 int diff = defined_values_count - current_initialization_count; |
|
278 if (diff <= initial_element_number) |
|
279 temp_element_number = initial_element_number - diff; |
|
280 current_initialization_count += initial_element_number - 1; |
|
281 initial_element_number = temp_element_number; |
|
282 if (initial_element_number > 0) { |
|
283 defined_values_count++; |
|
284 s4o.print(", "); |
|
285 } |
|
286 } |
|
287 else |
|
288 current_initialization_count += initial_element_number - 1; |
|
289 if (defined_values_count + initial_element_number > array_size) |
|
290 ERROR; |
|
234 for (int i = 0; i < initial_element_number; i++) { |
291 for (int i = 0; i < initial_element_number; i++) { |
235 if (i > 0) |
292 if (i > 0) |
236 s4o.print(", "); |
293 s4o.print(", "); |
237 if (symbol->array_initial_element != NULL) |
294 if (symbol->array_initial_element != NULL) |
238 symbol->array_initial_element->accept(*this); |
295 symbol->array_initial_element->accept(*this); |
239 else if (array_default_value != NULL) |
296 else |
240 array_default_value->accept(*this); |
297 array_default_value->accept(*this); |
241 } |
298 } |
242 if (initial_element_number > 1) |
299 if (initial_element_number > 1) |
243 array_size -= initial_element_number - 1; |
300 defined_values_count += initial_element_number - 1; |
244 break; |
301 break; |
245 default: |
302 default: |
246 break; |
303 break; |
247 } |
304 } |
248 return NULL; |
305 return NULL; |
249 } |
306 } |
250 |
307 |
308 void *visit(structure_element_initialization_list_c *symbol); |
|
251 }; |
309 }; |
252 |
310 |
253 /***********************************************************************/ |
311 /***********************************************************************/ |
254 /***********************************************************************/ |
312 /***********************************************************************/ |
255 /***********************************************************************/ |
313 /***********************************************************************/ |
257 /***********************************************************************/ |
315 /***********************************************************************/ |
258 /***********************************************************************/ |
316 /***********************************************************************/ |
259 /***********************************************************************/ |
317 /***********************************************************************/ |
260 /***********************************************************************/ |
318 /***********************************************************************/ |
261 |
319 |
320 /* given a structure_element_declaration_list_c, iterate |
|
321 * through each element, returning the name |
|
322 * of each element...structure_element_iterator_c |
|
323 */ |
|
324 class structure_element_iterator_c : public null_visitor_c { |
|
325 |
|
326 private: |
|
327 /* a pointer to the structure_element_declaration_list_c |
|
328 * currently being analysed. |
|
329 */ |
|
330 symbol_c *type_decl; |
|
331 int next_element, element_count; |
|
332 identifier_c *current_element_name; |
|
333 symbol_c *current_element_type; |
|
334 symbol_c *current_element_default_value; |
|
335 |
|
336 |
|
337 public: |
|
338 /* start off at the first parameter once again... */ |
|
339 void reset(void) { |
|
340 next_element = element_count = 0; |
|
341 current_element_name = NULL; |
|
342 current_element_type = current_element_default_value = NULL; |
|
343 } |
|
344 |
|
345 /* initialise the iterator object. |
|
346 * We must be given a reference to the function declaration |
|
347 * that will be analysed... |
|
348 */ |
|
349 structure_element_iterator_c(symbol_c *type_decl) { |
|
350 this->type_decl = type_decl; |
|
351 reset(); |
|
352 } |
|
353 |
|
354 /* Skip to the next element. After object creation, |
|
355 * the object references on |
|
356 * element _before_ the first, so |
|
357 * this function must be called once to get the object to |
|
358 * reference the first element... |
|
359 * |
|
360 * Returns the element's name! |
|
361 */ |
|
362 identifier_c *next(void) { |
|
363 void *res; |
|
364 identifier_c *identifier; |
|
365 element_count = 0; |
|
366 next_element++; |
|
367 res = type_decl->accept(*this); |
|
368 if (res != NULL) { |
|
369 symbol_c *sym = (symbol_c *)res; |
|
370 identifier = dynamic_cast<identifier_c *>(sym); |
|
371 if (identifier == NULL) |
|
372 ERROR; |
|
373 } |
|
374 else |
|
375 return NULL; |
|
376 |
|
377 current_element_name = identifier; |
|
378 return current_element_name; |
|
379 } |
|
380 |
|
381 /* Returns the currently referenced element's default value, |
|
382 * or NULL if none is specified in the structure declaration itself. |
|
383 */ |
|
384 symbol_c *default_value(void) { |
|
385 return current_element_default_value; |
|
386 } |
|
387 |
|
388 /* Returns the currently referenced element's type name. */ |
|
389 symbol_c *element_type(void) { |
|
390 return current_element_type; |
|
391 } |
|
392 |
|
393 /********************************/ |
|
394 /* B 1.3.3 - Derived data types */ |
|
395 /********************************/ |
|
396 |
|
397 /* helper symbol for structure_declaration */ |
|
398 /* structure_element_declaration_list structure_element_declaration ';' */ |
|
399 void *visit(structure_element_declaration_list_c *symbol) { |
|
400 void *res; |
|
401 for (int i = 0; i < symbol->n; i++) { |
|
402 res = symbol->elements[i]->accept(*this); |
|
403 if (res != NULL) |
|
404 return res; |
|
405 } |
|
406 return NULL; |
|
407 } |
|
408 |
|
409 /* structure_element_name ':' *_spec_init */ |
|
410 void *visit(structure_element_declaration_c *symbol) { |
|
411 element_count++; |
|
412 if (next_element == element_count) { |
|
413 current_element_default_value = spec_init_sperator_c::get_init(symbol->spec_init); |
|
414 current_element_type = spec_init_sperator_c::get_spec(symbol->spec_init); |
|
415 return symbol->structure_element_name; |
|
416 } |
|
417 /* not yet the desired element... */ |
|
418 return NULL; |
|
419 } |
|
420 |
|
421 }; |
|
422 |
|
423 /* |
|
424 * Structure init element iterator. |
|
425 * It will search through the elements of a structure initialization |
|
426 */ |
|
427 class structure_init_element_iterator_c : public null_visitor_c { |
|
428 private: |
|
429 /* a pointer to the structure initialization |
|
430 * currently being analysed. |
|
431 */ |
|
432 symbol_c *structure_initialization; |
|
433 identifier_c *search_element_name; |
|
434 |
|
435 public: |
|
436 /* initialise the iterator object. |
|
437 * We must be given a reference to the structure initialization |
|
438 * that will be analysed... |
|
439 */ |
|
440 structure_init_element_iterator_c(symbol_c *structure_initialization) { |
|
441 this->structure_initialization = structure_initialization; |
|
442 search_element_name = NULL; |
|
443 } |
|
444 |
|
445 /* Search for the value passed to the element named <element_name>... */ |
|
446 symbol_c *search(symbol_c *element_name) { |
|
447 if (NULL == element_name) ERROR; |
|
448 search_element_name = dynamic_cast<identifier_c *>(element_name); |
|
449 if (NULL == search_element_name) ERROR; |
|
450 void *res = structure_initialization->accept(*this); |
|
451 return (symbol_c *)res; |
|
452 } |
|
453 |
|
454 /* helper symbol for structure_initialization */ |
|
455 /* structure_element_initialization_list ',' structure_element_initialization */ |
|
456 void *visit(structure_element_initialization_list_c *symbol) { |
|
457 void *res; |
|
458 for (int i = 0; i < symbol->n; i++) { |
|
459 res = symbol->elements[i]->accept(*this); |
|
460 if (res != NULL) |
|
461 return res; |
|
462 } |
|
463 return NULL; |
|
464 } |
|
465 |
|
466 /* structure_element_name ASSIGN value */ |
|
467 void *visit(structure_element_initialization_c *symbol) { |
|
468 identifier_c *element_name = dynamic_cast<identifier_c *>(symbol->structure_element_name); |
|
469 |
|
470 if (element_name == NULL) ERROR; |
|
471 |
|
472 if (strcasecmp(search_element_name->value, element_name->value) == 0) |
|
473 /* FOUND! This is the same element!! */ |
|
474 return (void *)symbol->value; |
|
475 return NULL; |
|
476 } |
|
477 }; |
|
478 |
|
479 class generate_c_structure_initialization_c: public generate_c_typedecl_c { |
|
480 |
|
481 public: |
|
482 typedef enum { |
|
483 none_sm, |
|
484 typedecl_sm, |
|
485 initializationvalue_sm, |
|
486 varlistparse_sm |
|
487 } structureinitialization_mode_t; |
|
488 |
|
489 structureinitialization_mode_t current_mode; |
|
490 |
|
491 private: |
|
492 symbol_c* structure_type_decl; |
|
493 symbol_c* current_element_type; |
|
494 |
|
495 public: |
|
496 generate_c_structure_initialization_c(stage4out_c *s4o_ptr): generate_c_typedecl_c(s4o_ptr) {} |
|
497 ~generate_c_structure_initialization_c(void) {} |
|
498 |
|
499 void init_structure_default(symbol_c *structure_type_name) { |
|
500 structure_type_decl = NULL; |
|
501 current_element_type = NULL; |
|
502 |
|
503 current_mode = typedecl_sm; |
|
504 structure_type_name->accept(*this); |
|
505 } |
|
506 |
|
507 void init_structure(symbol_c *var1_list, symbol_c *structure_type_name, symbol_c *structure_initialization) { |
|
508 int i; |
|
509 |
|
510 init_structure_default(structure_type_name); |
|
511 |
|
512 current_mode = initializationvalue_sm; |
|
513 s4o.print("\n"); |
|
514 s4o.print(s4o.indent_spaces + "{\n"); |
|
515 s4o.indent_right(); |
|
516 s4o.print(s4o.indent_spaces); |
|
517 structure_type_name->accept(*this); |
|
518 s4o.print(" temp = "); |
|
519 structure_initialization->accept(*this); |
|
520 s4o.print(";\n"); |
|
521 |
|
522 current_mode = varlistparse_sm; |
|
523 var1_list->accept(*this); |
|
524 |
|
525 s4o.indent_left(); |
|
526 s4o.print(s4o.indent_spaces + "}"); |
|
527 } |
|
528 |
|
529 void *visit(identifier_c *type_name) { |
|
530 symbol_c *type_decl; |
|
531 switch (current_mode) { |
|
532 case typedecl_sm: |
|
533 /* look up the type declaration... */ |
|
534 type_decl = type_symtable.find_value(type_name); |
|
535 if (type_decl == type_symtable.end_value()) |
|
536 /* Type declaration not found!! */ |
|
537 ERROR; |
|
538 type_decl->accept(*this); |
|
539 break; |
|
540 default: |
|
541 print_token(type_name); |
|
542 break; |
|
543 } |
|
544 return NULL; |
|
545 } |
|
546 |
|
547 void *visit(var1_list_c *symbol) { |
|
548 int i, j; |
|
549 |
|
550 for (i = 0; i < symbol->n; i++) { |
|
551 s4o.print(s4o.indent_spaces); |
|
552 print_variable_prefix(); |
|
553 symbol->elements[i]->accept(*this); |
|
554 s4o.print(" = temp;\n"); |
|
555 } |
|
556 return NULL; |
|
557 } |
|
558 |
|
559 /********************************/ |
|
560 /* B 1.3.3 - Derived data types */ |
|
561 /********************************/ |
|
562 |
|
563 /* helper symbol for structure_declaration */ |
|
564 /* structure_element_declaration_list structure_element_declaration ';' */ |
|
565 void *visit(structure_element_declaration_list_c *symbol) { |
|
566 switch (current_mode) { |
|
567 case typedecl_sm: |
|
568 structure_type_decl = (symbol_c *)symbol; |
|
569 break; |
|
570 default: |
|
571 break; |
|
572 } |
|
573 return NULL; |
|
574 } |
|
575 |
|
576 /* helper symbol for structure_initialization */ |
|
577 /* structure_element_initialization_list ',' structure_element_initialization */ |
|
578 void *visit(structure_element_initialization_list_c *symbol) { |
|
579 s4o.print("{"); |
|
580 structure_element_iterator_c structure_iterator(structure_type_decl); |
|
581 |
|
582 identifier_c *element_name; |
|
583 structure_init_element_iterator_c structure_init_element_iterator(symbol); |
|
584 for(int i = 1; (element_name = structure_iterator.next()) != NULL; i++) { |
|
585 if (i > 1) |
|
586 s4o.print(", "); |
|
587 |
|
588 /* Get the value from an initialization */ |
|
589 symbol_c *element_value = structure_init_element_iterator.search(element_name); |
|
590 |
|
591 if (element_value == NULL) { |
|
592 /* No value given for parameter, so we must use the default... */ |
|
593 /* First check whether default value specified in function declaration...*/ |
|
594 element_value = structure_iterator.default_value(); |
|
595 current_element_type = structure_iterator.element_type(); |
|
596 } |
|
597 |
|
598 if (element_value == NULL) { |
|
599 if (current_element_type == NULL) ERROR; |
|
600 |
|
601 /* If not, get the default value of this variable's type */ |
|
602 element_value = (symbol_c *)current_element_type->accept(*type_initial_value_c::instance()); |
|
603 } |
|
604 |
|
605 if (element_value == NULL) ERROR; |
|
606 |
|
607 element_value->accept(*this); |
|
608 } |
|
609 s4o.print("}"); |
|
610 return NULL; |
|
611 } |
|
612 |
|
613 /* helper symbol for array_initialization */ |
|
614 /* array_initial_elements_list ',' array_initial_elements */ |
|
615 void *visit(array_initial_elements_list_c *symbol) { |
|
616 generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o); |
|
617 array_initialization->set_variable_prefix(get_variable_prefix()); |
|
618 array_initialization->init_array_dimensions(current_element_type); |
|
619 array_initialization->current_mode = generate_c_array_initialization_c::initializationvalue_am; |
|
620 array_initialization->init_array_values(symbol); |
|
621 delete array_initialization; |
|
622 return NULL; |
|
623 } |
|
624 |
|
625 }; |
|
626 |
|
627 |
|
628 /* helper symbol for array_initialization */ |
|
629 /* structure_element_initialization_list ',' structure_element_initialization */ |
|
630 void *generate_c_array_initialization_c::visit(structure_element_initialization_list_c *symbol) { |
|
631 generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); |
|
632 structure_initialization->set_variable_prefix(get_variable_prefix()); |
|
633 structure_initialization->init_structure_default(array_base_type); |
|
634 structure_initialization->current_mode = generate_c_structure_initialization_c::initializationvalue_sm; |
|
635 symbol->accept(*structure_initialization); |
|
636 delete structure_initialization; |
|
637 return NULL; |
|
638 } |
|
639 |
|
640 /***********************************************************************/ |
|
641 /***********************************************************************/ |
|
642 /***********************************************************************/ |
|
643 /***********************************************************************/ |
|
644 /***********************************************************************/ |
|
645 /***********************************************************************/ |
|
646 /***********************************************************************/ |
|
647 /***********************************************************************/ |
|
262 |
648 |
263 |
649 |
264 |
650 |
265 class generate_c_vardecl_c: protected generate_c_typedecl_c { |
651 class generate_c_vardecl_c: protected generate_c_typedecl_c { |
266 |
652 |
411 globalinit_vf |
797 globalinit_vf |
412 } varformat_t; |
798 } varformat_t; |
413 |
799 |
414 |
800 |
415 private: |
801 private: |
416 generate_c_array_initialization_c *generate_c_array_initialization; |
|
417 |
|
418 /* variable used to store the types of variables that need to be processed... */ |
802 /* variable used to store the types of variables that need to be processed... */ |
419 /* Only set in the constructor...! */ |
803 /* Only set in the constructor...! */ |
420 /* Will contain a set of values of generate_c_vardecl_c::XXXX_vt */ |
804 /* Will contain a set of values of generate_c_vardecl_c::XXXX_vt */ |
421 unsigned int wanted_vartype; |
805 unsigned int wanted_vartype; |
422 /* variable used to store the type of variable currently being processed... */ |
806 /* variable used to store the type of variable currently being processed... */ |
581 |
965 |
582 |
966 |
583 public: |
967 public: |
584 generate_c_vardecl_c(stage4out_c *s4o_ptr, varformat_t varformat, unsigned int vartype, symbol_c* res_name = NULL) |
968 generate_c_vardecl_c(stage4out_c *s4o_ptr, varformat_t varformat, unsigned int vartype, symbol_c* res_name = NULL) |
585 : generate_c_typedecl_c(s4o_ptr) { |
969 : generate_c_typedecl_c(s4o_ptr) { |
586 generate_c_array_initialization = new generate_c_array_initialization_c(s4o_ptr); |
|
587 wanted_varformat = varformat; |
970 wanted_varformat = varformat; |
588 wanted_vartype = vartype; |
971 wanted_vartype = vartype; |
589 current_vartype = none_vt; |
972 current_vartype = none_vt; |
590 current_var_type_symbol = NULL; |
973 current_var_type_symbol = NULL; |
591 current_var_init_symbol = NULL; |
974 current_var_init_symbol = NULL; |
594 resource_name = res_name; |
977 resource_name = res_name; |
595 en_declared = false; |
978 en_declared = false; |
596 eno_declared = false; |
979 eno_declared = false; |
597 } |
980 } |
598 |
981 |
599 ~generate_c_vardecl_c(void) { |
982 ~generate_c_vardecl_c(void) {} |
600 delete generate_c_array_initialization; |
|
601 } |
|
602 |
983 |
603 bool is_en_declared(void) { |
984 bool is_en_declared(void) { |
604 return en_declared; |
985 return en_declared; |
605 } |
986 } |
606 |
987 |
608 return eno_declared; |
989 return eno_declared; |
609 } |
990 } |
610 |
991 |
611 void print(symbol_c *symbol, symbol_c *scope = NULL, const char *variable_prefix = NULL) { |
992 void print(symbol_c *symbol, symbol_c *scope = NULL, const char *variable_prefix = NULL) { |
612 this->set_variable_prefix(variable_prefix); |
993 this->set_variable_prefix(variable_prefix); |
613 this->generate_c_array_initialization->set_variable_prefix(variable_prefix); |
|
614 if (globalinit_vf == wanted_varformat) |
994 if (globalinit_vf == wanted_varformat) |
615 globalnamespace = scope; |
995 globalnamespace = scope; |
616 |
996 |
617 finterface_var_count = 0; |
997 finterface_var_count = 0; |
618 |
998 |
791 * current_var_init_symbol private variables... |
1171 * current_var_init_symbol private variables... |
792 */ |
1172 */ |
793 update_type_init(symbol->array_spec_init); |
1173 update_type_init(symbol->array_spec_init); |
794 |
1174 |
795 /* now to produce the c equivalent... */ |
1175 /* now to produce the c equivalent... */ |
796 if (wanted_varformat == constructorinit_vf) |
1176 if (wanted_varformat == constructorinit_vf) { |
797 generate_c_array_initialization->init_array(symbol->var1_list, this->current_var_type_symbol, this->current_var_init_symbol); |
1177 generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o); |
1178 array_initialization->set_variable_prefix(get_variable_prefix()); |
|
1179 array_initialization->init_array(symbol->var1_list, this->current_var_type_symbol, this->current_var_init_symbol); |
|
1180 delete array_initialization; |
|
1181 } |
|
798 else |
1182 else |
799 symbol->var1_list->accept(*this); |
1183 symbol->var1_list->accept(*this); |
800 |
1184 |
801 /* Values no longer in scope, and therefore no longer used. |
1185 /* Values no longer in scope, and therefore no longer used. |
802 * Make an effort to keep them set to NULL when not in use |
1186 * Make an effort to keep them set to NULL when not in use |
819 * current_var_init_symbol private variables... |
1203 * current_var_init_symbol private variables... |
820 */ |
1204 */ |
821 update_type_init(symbol->initialized_structure); |
1205 update_type_init(symbol->initialized_structure); |
822 |
1206 |
823 /* now to produce the c equivalent... */ |
1207 /* now to produce the c equivalent... */ |
824 symbol->var1_list->accept(*this); |
1208 if (wanted_varformat == constructorinit_vf) { |
1209 generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); |
|
1210 structure_initialization->set_variable_prefix(get_variable_prefix()); |
|
1211 structure_initialization->init_structure(symbol->var1_list, this->current_var_type_symbol, this->current_var_init_symbol); |
|
1212 delete structure_initialization; |
|
1213 } |
|
1214 else |
|
1215 symbol->var1_list->accept(*this); |
|
825 |
1216 |
826 /* Values no longer in scope, and therefore no longer used. |
1217 /* Values no longer in scope, and therefore no longer used. |
827 * Make an effort to keep them set to NULL when not in use |
1218 * Make an effort to keep them set to NULL when not in use |
828 * in order to catch bugs as soon as possible... |
1219 * in order to catch bugs as soon as possible... |
829 */ |
1220 */ |
947 /* Start off by setting the current_var_type_symbol and |
1338 /* Start off by setting the current_var_type_symbol and |
948 * current_var_init_symbol private variables... |
1339 * current_var_init_symbol private variables... |
949 */ |
1340 */ |
950 update_type_init(symbol->structure_type_name); |
1341 update_type_init(symbol->structure_type_name); |
951 |
1342 |
952 /* now to produce the c equivalent... */ |
1343 if (wanted_varformat == constructorinit_vf) { |
953 symbol->var1_list->accept(*this); |
1344 generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); |
1345 structure_initialization->set_variable_prefix(get_variable_prefix()); |
|
1346 structure_initialization->init_structure(symbol->var1_list, this->current_var_type_symbol, this->current_var_init_symbol); |
|
1347 delete structure_initialization; |
|
1348 } |
|
1349 else |
|
1350 /* now to produce the c equivalent... */ |
|
1351 symbol->var1_list->accept(*this); |
|
954 |
1352 |
955 /* Values no longer in scope, and therefore no longer used. |
1353 /* Values no longer in scope, and therefore no longer used. |
956 * Make an effort to keep them set to NULL when not in use |
1354 * Make an effort to keep them set to NULL when not in use |
957 * in order to catch bugs as soon as possible... |
1355 * in order to catch bugs as soon as possible... |
958 */ |
1356 */ |