90 function_call->accept(*this); |
90 function_call->accept(*this); |
91 } |
91 } |
92 } |
92 } |
93 |
93 |
94 void generate_inline(symbol_c *function_name, |
94 void generate_inline(symbol_c *function_name, |
95 symbol_c *return_data_type, |
95 symbol_c *function_type_prefix, |
|
96 symbol_c *function_type_suffix, |
96 std::list<FUNCTION_PARAM*> param_list) { |
97 std::list<FUNCTION_PARAM*> param_list) { |
97 std::list<FUNCTION_PARAM*>::iterator pt; |
98 std::list<FUNCTION_PARAM*>::iterator pt; |
98 |
99 |
99 fcall_number++; |
100 fcall_number++; |
100 |
101 |
101 s4o.print(s4o.indent_spaces); |
102 s4o.print(s4o.indent_spaces); |
102 s4o.print("inline "); |
103 s4o.print("inline "); |
103 return_data_type->accept(*this); |
104 function_type_prefix->accept(*this); |
104 s4o.print(" __"); |
105 s4o.print(" __"); |
105 fbname->accept(*this); |
106 fbname->accept(*this); |
106 s4o.print("_"); |
107 s4o.print("_"); |
107 function_name->accept(*this); |
108 function_name->accept(*this); |
|
109 if (function_type_suffix) |
|
110 function_type_suffix->accept(*this); |
108 s4o.print_integer(fcall_number); |
111 s4o.print_integer(fcall_number); |
109 s4o.print("("); |
112 s4o.print("("); |
110 s4o.indent_right(); |
113 s4o.indent_right(); |
111 |
114 |
112 PARAM_LIST_ITERATOR() { |
115 PARAM_LIST_ITERATOR() { |
258 unsigned int vartype; |
263 unsigned int vartype; |
259 if (wanted_variablegeneration == complextype_base_vg) |
264 if (wanted_variablegeneration == complextype_base_vg) |
260 generate_c_base_c::visit(symbol); |
265 generate_c_base_c::visit(symbol); |
261 else if (wanted_variablegeneration == complextype_suffix_vg) |
266 else if (wanted_variablegeneration == complextype_suffix_vg) |
262 return NULL; |
267 return NULL; |
263 else if (wanted_variablegeneration == expression_vg) { |
|
264 vartype = search_varfb_instance_type->get_vartype(symbol); |
|
265 if (vartype == search_var_instance_decl_c::external_vt) { |
|
266 s4o.print(GET_EXTERNAL); |
|
267 s4o.print("("); |
|
268 symbol->var_name->accept(*this); |
|
269 } |
|
270 else { |
|
271 if (vartype == search_var_instance_decl_c::located_vt) |
|
272 s4o.print(GET_LOCATED); |
|
273 else |
|
274 s4o.print(GET_VAR); |
|
275 s4o.print("("); |
|
276 generate_c_base_c::visit(symbol); |
|
277 } |
|
278 s4o.print(")"); |
|
279 } |
|
280 else |
268 else |
281 generate_c_base_c::visit(symbol); |
269 print_getter(symbol); |
282 return NULL; |
270 return NULL; |
283 } |
271 } |
284 |
272 |
285 /********************************************/ |
273 /********************************************/ |
286 /* B.1.4.1 Directly Represented Variables */ |
274 /* B.1.4.1 Directly Represented Variables */ |
365 /***********************************/ |
353 /***********************************/ |
366 /* B 2.1 Instructions and Operands */ |
354 /* B 2.1 Instructions and Operands */ |
367 /***********************************/ |
355 /***********************************/ |
368 |
356 |
369 void *visit(il_function_call_c *symbol) { |
357 void *visit(il_function_call_c *symbol) { |
370 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
358 symbol_c* function_type_prefix = NULL; |
371 |
359 symbol_c* function_name = NULL; |
372 if (f_decl != function_symtable.end_value()) { |
360 symbol_c* function_type_suffix = NULL; |
373 DECLARE_PARAM_LIST() |
361 DECLARE_PARAM_LIST() |
374 bool has_output_params = false; |
362 |
|
363 symbol_c *param_data_type = default_variable_name.current_type; |
|
364 |
|
365 function_call_param_iterator_c function_call_param_iterator(symbol); |
|
366 |
|
367 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
368 if (f_decl == function_symtable.end_value()) { |
|
369 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
|
370 if (current_function_type == function_none) ERROR; |
|
371 |
|
372 function_type_prefix = (symbol_c *)search_expression_type->compute_standard_function_il(symbol, param_data_type); |
|
373 |
|
374 symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN")); |
|
375 /* Add the value from EN param */ |
|
376 ADD_PARAM_LIST(en_param_name, |
|
377 (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())), |
|
378 (symbol_c*)(new bool_type_name_c()), |
|
379 function_param_iterator_c::direction_in) |
|
380 |
|
381 symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO")); |
|
382 /* Add the value from ENO param */ |
|
383 ADD_PARAM_LIST(eno_param_name, NULL, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
|
384 |
|
385 int nb_param = 1; |
|
386 if (symbol->il_operand_list != NULL) |
|
387 nb_param += ((list_c *)symbol->il_operand_list)->n; |
|
388 |
|
389 #include "il_code_gen.c" |
|
390 |
|
391 } |
|
392 else { |
|
393 function_name = symbol->function_name; |
375 |
394 |
376 /* determine the base data type returned by the function being called... */ |
395 /* determine the base data type returned by the function being called... */ |
377 search_base_type_c search_base_type; |
396 search_base_type_c search_base_type; |
378 symbol_c *return_data_type = (symbol_c *)f_decl->type_name->accept(search_base_type); |
397 function_type_prefix = (symbol_c *)f_decl->type_name->accept(search_base_type); |
379 if (NULL == return_data_type) ERROR; |
|
380 |
398 |
381 /* loop through each function parameter, find the value we should pass |
399 /* loop through each function parameter, find the value we should pass |
382 * to it, and then output the c equivalent... |
400 * to it, and then output the c equivalent... |
383 */ |
401 */ |
384 |
402 |
385 function_param_iterator_c fp_iterator(f_decl); |
403 function_param_iterator_c fp_iterator(f_decl); |
386 identifier_c *param_name; |
404 identifier_c *param_name; |
387 function_call_param_iterator_c function_call_param_iterator(symbol); |
|
388 for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
405 for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
389 symbol_c *param_type = fp_iterator.param_type(); |
406 symbol_c *param_type = fp_iterator.param_type(); |
390 if (param_type == NULL) ERROR; |
407 if (param_type == NULL) ERROR; |
391 |
408 |
392 function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
409 function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
422 param_value = fp_iterator.default_value(); |
439 param_value = fp_iterator.default_value(); |
423 } |
440 } |
424 |
441 |
425 ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction()) |
442 ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction()) |
426 } /* for(...) */ |
443 } /* for(...) */ |
427 |
|
428 if (function_call_param_iterator.next_nf() != NULL) ERROR; |
|
429 |
|
430 PARAM_LIST_ITERATOR() { |
|
431 if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
432 PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
433 PARAM_VALUE != NULL) { |
|
434 has_output_params = true; |
|
435 } |
|
436 } |
|
437 |
|
438 if (has_output_params) |
|
439 generate_inline(symbol->function_name, return_data_type, param_list); |
|
440 |
|
441 CLEAR_PARAM_LIST() |
|
442 } |
444 } |
443 return NULL; |
445 |
444 } |
446 if (function_call_param_iterator.next_nf() != NULL) ERROR; |
445 |
447 if (NULL == function_type_prefix) ERROR; |
|
448 |
|
449 bool has_output_params = false; |
|
450 |
|
451 PARAM_LIST_ITERATOR() { |
|
452 if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
453 PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
454 PARAM_VALUE != NULL) { |
|
455 has_output_params = true; |
|
456 } |
|
457 } |
|
458 |
|
459 if (has_output_params) |
|
460 generate_inline(function_name, function_type_prefix, function_type_suffix, param_list); |
|
461 |
|
462 CLEAR_PARAM_LIST() |
|
463 |
|
464 return NULL; |
|
465 } |
|
466 |
|
467 /* | function_name '(' eol_list [il_param_list] ')' */ |
|
468 // SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) |
446 void *visit(il_formal_funct_call_c *symbol) { |
469 void *visit(il_formal_funct_call_c *symbol) { |
447 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
470 symbol_c* function_type_prefix = NULL; |
448 |
471 symbol_c* function_name = NULL; |
449 if (f_decl != function_symtable.end_value()) { |
472 symbol_c* function_type_suffix = NULL; |
450 DECLARE_PARAM_LIST() |
473 DECLARE_PARAM_LIST() |
451 bool has_output_params = false; |
474 |
|
475 function_call_param_iterator_c function_call_param_iterator(symbol); |
|
476 |
|
477 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
478 if (f_decl == function_symtable.end_value()) { |
|
479 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
|
480 if (current_function_type == function_none) ERROR; |
|
481 |
|
482 function_type_prefix = (symbol_c *)search_expression_type->compute_standard_function_default(NULL, symbol); |
|
483 |
|
484 int nb_param = 0; |
|
485 if (symbol->il_param_list != NULL) |
|
486 nb_param += ((list_c *)symbol->il_param_list)->n; |
|
487 |
|
488 symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN")); |
|
489 /* Get the value from EN param */ |
|
490 symbol_c *EN_param_value = function_call_param_iterator.search_f(en_param_name); |
|
491 if (EN_param_value == NULL) |
|
492 EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
|
493 else |
|
494 nb_param --; |
|
495 ADD_PARAM_LIST(en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
|
496 |
|
497 symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO")); |
|
498 /* Get the value from ENO param */ |
|
499 symbol_c *ENO_param_value = function_call_param_iterator.search_f(eno_param_name); |
|
500 if (ENO_param_value != NULL) |
|
501 nb_param --; |
|
502 ADD_PARAM_LIST(eno_param_name, ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
|
503 |
|
504 #include "st_code_gen.c" |
|
505 |
|
506 } |
|
507 else { |
|
508 function_name = symbol->function_name; |
452 |
509 |
453 /* determine the base data type returned by the function being called... */ |
510 /* determine the base data type returned by the function being called... */ |
454 search_base_type_c search_base_type; |
511 search_base_type_c search_base_type; |
455 symbol_c *return_data_type = (symbol_c *)f_decl->type_name->accept(search_base_type); |
512 function_type_prefix = (symbol_c *)f_decl->type_name->accept(search_base_type); |
456 if (NULL == return_data_type) ERROR; |
|
457 |
513 |
458 /* loop through each function parameter, find the value we should pass |
514 /* loop through each function parameter, find the value we should pass |
459 * to it, and then output the c equivalent... |
515 * to it, and then output the c equivalent... |
460 */ |
516 */ |
461 |
517 |
462 function_param_iterator_c fp_iterator(f_decl); |
518 function_param_iterator_c fp_iterator(f_decl); |
463 identifier_c *param_name; |
519 identifier_c *param_name; |
464 function_call_param_iterator_c function_call_param_iterator(symbol); |
|
465 for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
520 for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
466 symbol_c *param_type = fp_iterator.param_type(); |
521 symbol_c *param_type = fp_iterator.param_type(); |
467 if (param_type == NULL) ERROR; |
522 if (param_type == NULL) ERROR; |
468 |
523 |
469 function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
524 function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
494 param_value = fp_iterator.default_value(); |
549 param_value = fp_iterator.default_value(); |
495 } |
550 } |
496 |
551 |
497 ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction()) |
552 ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction()) |
498 } |
553 } |
499 |
554 } |
500 if (function_call_param_iterator.next_nf() != NULL) ERROR; |
555 |
501 |
556 if (function_call_param_iterator.next_nf() != NULL) ERROR; |
502 PARAM_LIST_ITERATOR() { |
557 if (NULL == function_type_prefix) ERROR; |
503 if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
558 |
504 PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
559 bool has_output_params = false; |
505 PARAM_VALUE != NULL) { |
560 |
506 has_output_params = true; |
561 PARAM_LIST_ITERATOR() { |
507 } |
562 if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
563 PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
564 PARAM_VALUE != NULL) { |
|
565 has_output_params = true; |
508 } |
566 } |
509 |
567 } |
510 if (has_output_params) |
568 |
511 generate_inline(symbol->function_name, return_data_type, param_list); |
569 if (has_output_params) |
512 |
570 generate_inline(function_name, function_type_prefix, function_type_suffix, param_list); |
513 CLEAR_PARAM_LIST() |
571 |
514 } |
572 CLEAR_PARAM_LIST() |
|
573 |
515 return NULL; |
574 return NULL; |
516 } |
575 } |
517 |
576 |
518 /***************************************/ |
577 /***************************************/ |
519 /* B.3 - Language ST (Structured Text) */ |
578 /* B.3 - Language ST (Structured Text) */ |
521 /***********************/ |
580 /***********************/ |
522 /* B 3.1 - Expressions */ |
581 /* B 3.1 - Expressions */ |
523 /***********************/ |
582 /***********************/ |
524 |
583 |
525 void *visit(function_invocation_c *symbol) { |
584 void *visit(function_invocation_c *symbol) { |
|
585 symbol_c* function_type_prefix = NULL; |
|
586 symbol_c* function_name = NULL; |
|
587 symbol_c* function_type_suffix = NULL; |
|
588 DECLARE_PARAM_LIST() |
|
589 |
|
590 symbol_c *parameter_assignment_list = NULL; |
|
591 if (NULL != symbol-> formal_param_list) parameter_assignment_list = symbol-> formal_param_list; |
|
592 if (NULL != symbol->nonformal_param_list) parameter_assignment_list = symbol->nonformal_param_list; |
|
593 if (NULL == parameter_assignment_list) ERROR; |
|
594 |
|
595 function_call_param_iterator_c function_call_param_iterator(symbol); |
|
596 |
526 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
597 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
527 |
598 if (f_decl == function_symtable.end_value()) { |
528 if (f_decl != function_symtable.end_value()) { |
599 /* The function called is not in the symtable, so we test if it is a |
529 DECLARE_PARAM_LIST() |
600 * standard function defined in standard */ |
530 bool has_output_params = false; |
601 |
531 |
602 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
532 symbol_c *parameter_assignment_list = NULL; |
603 if (current_function_type == function_none) ERROR; |
533 if (NULL != symbol-> formal_param_list) parameter_assignment_list = symbol-> formal_param_list; |
604 |
534 if (NULL != symbol->nonformal_param_list) parameter_assignment_list = symbol->nonformal_param_list; |
605 function_type_prefix = search_expression_type->get_type(symbol); |
535 if (NULL == parameter_assignment_list) ERROR; |
606 |
|
607 int nb_param = ((list_c *)parameter_assignment_list)->n; |
|
608 |
|
609 symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN")); |
|
610 /* Get the value from EN param */ |
|
611 symbol_c *EN_param_value = function_call_param_iterator.search_f(en_param_name); |
|
612 if (EN_param_value == NULL) |
|
613 EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
|
614 else |
|
615 nb_param --; |
|
616 ADD_PARAM_LIST(en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
|
617 |
|
618 symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO")); |
|
619 /* Get the value from ENO param */ |
|
620 symbol_c *ENO_param_value = function_call_param_iterator.search_f(eno_param_name); |
|
621 if (ENO_param_value != NULL) |
|
622 nb_param --; |
|
623 ADD_PARAM_LIST(eno_param_name, ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
|
624 |
|
625 #include "st_code_gen.c" |
|
626 |
|
627 } |
|
628 else { |
|
629 function_name = symbol->function_name; |
536 |
630 |
537 /* determine the base data type returned by the function being called... */ |
631 /* determine the base data type returned by the function being called... */ |
538 search_base_type_c search_base_type; |
632 search_base_type_c search_base_type; |
539 symbol_c *return_data_type = (symbol_c *)f_decl->type_name->accept(search_base_type); |
633 function_type_prefix = (symbol_c *)f_decl->type_name->accept(search_base_type); |
540 if (NULL == return_data_type) ERROR; |
|
541 |
634 |
542 /* loop through each function parameter, find the value we should pass |
635 /* loop through each function parameter, find the value we should pass |
543 * to it, and then output the c equivalent... |
636 * to it, and then output the c equivalent... |
544 */ |
637 */ |
545 function_param_iterator_c fp_iterator(f_decl); |
638 function_param_iterator_c fp_iterator(f_decl); |
546 identifier_c *param_name; |
639 identifier_c *param_name; |
547 function_call_param_iterator_c function_call_param_iterator(symbol); |
|
548 for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
640 for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
549 symbol_c *param_type = fp_iterator.param_type(); |
641 symbol_c *param_type = fp_iterator.param_type(); |
550 if (param_type == NULL) ERROR; |
642 if (param_type == NULL) ERROR; |
551 |
643 |
552 function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
644 function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
567 } |
659 } |
568 |
660 |
569 ADD_PARAM_LIST(param_name, param_value, param_type, param_direction) |
661 ADD_PARAM_LIST(param_name, param_value, param_type, param_direction) |
570 } /* for(...) */ |
662 } /* for(...) */ |
571 // symbol->parameter_assignment->accept(*this); |
663 // symbol->parameter_assignment->accept(*this); |
572 |
664 } |
573 if (function_call_param_iterator.next_nf() != NULL) ERROR; |
665 |
574 |
666 if (function_call_param_iterator.next_nf() != NULL) ERROR; |
575 PARAM_LIST_ITERATOR() { |
667 if (NULL == function_type_prefix) ERROR; |
576 if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
668 |
577 PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
669 bool has_output_params = false; |
578 PARAM_VALUE != NULL) { |
670 |
579 has_output_params = true; |
671 PARAM_LIST_ITERATOR() { |
580 } |
672 if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
673 PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
674 PARAM_VALUE != NULL) { |
|
675 has_output_params = true; |
581 } |
676 } |
582 |
677 } |
583 if (has_output_params) |
678 |
584 generate_inline(symbol->function_name, return_data_type, param_list); |
679 if (has_output_params) |
585 |
680 generate_inline(function_name, function_type_prefix, function_type_suffix, param_list); |
586 CLEAR_PARAM_LIST() |
681 |
587 } |
682 CLEAR_PARAM_LIST() |
|
683 |
588 return NULL; |
684 return NULL; |
589 } |
685 } |
590 |
686 |
591 }; /* generate_c_inlinefcall_c */ |
687 }; /* generate_c_inlinefcall_c */ |
592 |
688 |