| 2518 | | New_Node : Tree_Node_Access := new Tree_Node; |
|---|
| 2519 | | begin |
|---|
| 2520 | | New_Node.Unit := Unit; |
|---|
| 2521 | | |
|---|
| 2522 | | if This.Last_Node = null then |
|---|
| 2523 | | This.Next := Add_Node (This.Next, New_Node.Self); |
|---|
| 2524 | | else |
|---|
| 2525 | | This.Last_Node.Next := Add_Node |
|---|
| 2526 | | (This.Last_Node.Next, New_Node.Self); |
|---|
| 2527 | | |
|---|
| 2528 | | New_Node.Prevs := Add_Node |
|---|
| 2529 | | (New_Node.Prevs, This.Last_Node.Self); |
|---|
| 2530 | | end if; |
|---|
| 2531 | | |
|---|
| 2532 | | This.Last_Node := New_Node; |
|---|
| | 2535 | begin |
|---|
| | 2536 | if Find (This, Unit) /= null then |
|---|
| | 2537 | Asis.Implementation.Set_Status |
|---|
| | 2538 | (Asis.Errors.Internal_Error, |
|---|
| | 2539 | "Elaboration order dublicate unit: " & Unit_Full_Name (Unit)); |
|---|
| | 2540 | |
|---|
| | 2541 | raise Asis.Exceptions.ASIS_Failed; |
|---|
| | 2542 | end if; |
|---|
| | 2543 | |
|---|
| | 2544 | declare |
|---|
| | 2545 | New_Node : Tree_Node_Access := new Tree_Node; |
|---|
| | 2546 | begin |
|---|
| | 2547 | New_Node.Unit := Unit; |
|---|
| | 2548 | |
|---|
| | 2549 | if This.Last_Node = null then |
|---|
| | 2550 | This.Next := Add_Node (This.Next, New_Node.Self); |
|---|
| | 2551 | else |
|---|
| | 2552 | This.Last_Node.Next := Add_Node |
|---|
| | 2553 | (This.Last_Node.Next, New_Node.Self); |
|---|
| | 2554 | |
|---|
| | 2555 | New_Node.Prevs := Add_Node |
|---|
| | 2556 | (New_Node.Prevs, This.Last_Node.Self); |
|---|
| | 2557 | end if; |
|---|
| | 2558 | |
|---|
| | 2559 | This.Last_Node := New_Node; |
|---|
| | 2560 | This.Units := Add_Node_Ordered (This.Units, New_Node.Self); |
|---|
| | 2561 | end; |
|---|
| 3387 | | -- A_Pure_Pragma |
|---|
| | 3440 | begin |
|---|
| | 3441 | if not Node.Elaborated |
|---|
| | 3442 | and then Node.Consistent |
|---|
| | 3443 | and then not Is_Nil (Node.Unit) |
|---|
| | 3444 | and then Unit_Kind (Node.Unit) in |
|---|
| | 3445 | A_Procedure .. A_Generic_Package_Renaming |
|---|
| | 3446 | then |
|---|
| | 3447 | if Elaboration_Line /= null then |
|---|
| | 3448 | -- test circular -- |
|---|
| | 3449 | if In_List |
|---|
| | 3450 | (Elaboration_Line, Elaboration_Line.all'Last, Node.Unit) |
|---|
| | 3451 | then |
|---|
| | 3452 | Node.Circular := Append |
|---|
| | 3453 | (Node.Circular, Elaboration_Line.all); |
|---|
| | 3454 | return; |
|---|
| | 3455 | end if; |
|---|
| | 3456 | end if; |
|---|
| | 3457 | |
|---|
| | 3458 | Elaboration_Line := Append |
|---|
| | 3459 | (Elaboration_Line, Node.Unit); |
|---|
| | 3460 | |
|---|
| | 3461 | if Node.Next /= null then |
|---|
| | 3462 | for Index in Node.Next.all'Range loop |
|---|
| | 3463 | Elab_Spec (Node.Next (Index)); |
|---|
| | 3464 | end loop; |
|---|
| | 3465 | end if; |
|---|
| | 3466 | |
|---|
| | 3467 | Elab_Pragmed_Bodys (Node, Node.Unit); |
|---|
| | 3468 | |
|---|
| | 3469 | Append (Result, Node.Unit); |
|---|
| | 3470 | Node.Elaborated := True; |
|---|
| | 3471 | Remove_From_List (Elaboration_Line, Node.Unit); |
|---|
| | 3472 | end if; |
|---|
| | 3473 | |
|---|
| | 3474 | if Is_Elaborate_Body (Node) then |
|---|
| | 3475 | -- An_Elaborate_Body_Pragma -- 10.2.1(22) |
|---|
| | 3476 | Elab_Body (Node); |
|---|
| | 3477 | end if; |
|---|
| | 3478 | end Elab_Spec; |
|---|
| | 3479 | |
|---|
| | 3480 | -- Elab_Body -- |
|---|
| | 3481 | procedure Elab_Body |
|---|
| | 3482 | (Node : in Tree_Node_Access; |
|---|
| | 3483 | All_Bodys : in Boolean := False) |
|---|
| | 3484 | is |
|---|
| | 3485 | Unit : Compilation_Unit := Nil_Compilation_Unit; |
|---|
| | 3486 | begin |
|---|
| | 3487 | if not Node.Body_Elaborated |
|---|
| | 3488 | then |
|---|
| | 3489 | if not Is_Nil (Node.Unit_Body) |
|---|
| | 3490 | and then Node.Body_Consistent |
|---|
| | 3491 | then |
|---|
| | 3492 | Unit := Node.Unit_Body; |
|---|
| | 3493 | |
|---|
| | 3494 | elsif not Is_Nil (Node.Unit) |
|---|
| | 3495 | and then Node.Consistent |
|---|
| | 3496 | then |
|---|
| | 3497 | Unit := Node.Unit; |
|---|
| | 3498 | end if; |
|---|
| | 3499 | |
|---|
| | 3500 | if Unit_Kind (Unit) in |
|---|
| | 3501 | A_Procedure_Body .. A_Protected_Body_Subunit |
|---|
| | 3502 | then |
|---|
| | 3503 | if Elaboration_Line /= null then |
|---|
| | 3504 | -- test circular -- |
|---|
| | 3505 | if In_List |
|---|
| | 3506 | (Elaboration_Line, Elaboration_Line.all'Last, Unit) |
|---|
| | 3507 | then |
|---|
| | 3508 | Node.Circular := Append |
|---|
| | 3509 | (Node.Circular, Elaboration_Line.all); |
|---|
| | 3510 | return; |
|---|
| | 3511 | end if; |
|---|
| | 3512 | end if; |
|---|
| | 3513 | |
|---|
| | 3514 | Elaboration_Line := Append (Elaboration_Line, Unit); |
|---|
| | 3515 | |
|---|
| | 3516 | if Node.Body_Dependences /= null then |
|---|
| | 3517 | for Index in Node.Body_Dependences.all'Range loop |
|---|
| | 3518 | Elab_Spec (Node.Body_Dependences (Index)); |
|---|
| | 3519 | end loop; |
|---|
| | 3520 | end if; |
|---|
| | 3521 | |
|---|
| | 3522 | Elab_Pragmed_Bodys (Node, Unit); |
|---|
| | 3523 | |
|---|
| | 3524 | if All_Bodys then |
|---|
| | 3525 | if Node.Body_Dependences /= null then |
|---|
| | 3526 | for Index in Node.Body_Dependences.all'Range loop |
|---|
| | 3527 | Elab_Body (Node.Body_Dependences (Index), True); |
|---|
| | 3528 | end loop; |
|---|
| | 3529 | end if; |
|---|
| | 3530 | end if; |
|---|
| | 3531 | |
|---|
| | 3532 | Append (Result, Unit); |
|---|
| | 3533 | |
|---|
| | 3534 | if Is_Identical (Unit, Node.Unit_Body) then |
|---|
| | 3535 | Node.Body_Elaborated := True; |
|---|
| | 3536 | else |
|---|
| | 3537 | Node.Elaborated := True; |
|---|
| | 3538 | end if; |
|---|
| | 3539 | |
|---|
| | 3540 | Remove_From_List (Elaboration_Line, Unit); |
|---|
| | 3541 | end if; |
|---|
| | 3542 | end if; |
|---|
| | 3543 | |
|---|
| | 3544 | Elab_Subunits (Node); |
|---|
| | 3545 | end Elab_Body; |
|---|
| | 3546 | |
|---|
| | 3547 | -- Elab_Subunits -- |
|---|
| | 3548 | procedure Elab_Subunits |
|---|
| | 3549 | (Node : in Tree_Node_Access) |
|---|
| | 3550 | is |
|---|
| | 3551 | Next_Node : Tree_Node_Access; |
|---|
| | 3552 | begin |
|---|
| | 3553 | if not Node.Body_Elaborated then |
|---|
| | 3554 | return; |
|---|
| | 3555 | end if; |
|---|
| | 3556 | |
|---|
| | 3557 | if Node.Prevs /= null then |
|---|
| | 3558 | for Index in Node.Prevs.all'Range loop |
|---|
| | 3559 | Next_Node := Node.Prevs (Index); |
|---|
| | 3560 | |
|---|
| | 3561 | if Unit_Kind (Next_Node.Unit) in |
|---|
| | 3562 | A_Procedure_Body_Subunit .. A_Protected_Body_Subunit |
|---|
| | 3563 | then |
|---|
| | 3564 | Elab_Body (Next_Node); |
|---|
| | 3565 | end if; |
|---|
| | 3566 | end loop; |
|---|
| | 3567 | end if; |
|---|
| | 3568 | end Elab_Subunits; |
|---|
| | 3569 | |
|---|
| | 3570 | -- Elab_Pragmed_Bodys -- |
|---|
| | 3571 | procedure Elab_Pragmed_Bodys |
|---|
| | 3572 | (Node : in Tree_Node_Access; |
|---|
| | 3573 | Unit : in Compilation_Unit) |
|---|
| | 3574 | is |
|---|
| | 3575 | -- An_Elaborate_Pragma -- 10.2.1(20) |
|---|
| | 3576 | -- An_Elaborate_All_Pragma -- 10.2.1(21) |
|---|
| | 3577 | |
|---|
| | 3578 | use Asis.Elements; |
|---|
| | 3579 | With_List : constant Asis.Context_Clause_List := |
|---|
| | 3580 | Context_Clause_Elements (Unit, True); |
|---|
| | 3581 | |
|---|
| | 3582 | El : Element; |
|---|
| | 3583 | Internal_Unit : Compilation_Unit; |
|---|
| | 3584 | begin |
|---|
| | 3585 | for Index in With_List'Range loop |
|---|
| | 3586 | El := With_List (Index); |
|---|
| | 3587 | |
|---|
| | 3588 | if Element_Kind (El) = A_Pragma then |
|---|
| | 3589 | if Pragma_Kind (El) = An_Elaborate_Pragma then |
|---|
| | 3590 | Internal_Unit := Get_Compilation_Unit |
|---|
| | 3591 | (Unit, With_List (Index), Index, The_Context); |
|---|
| | 3592 | |
|---|
| | 3593 | Elab_Body (Find (Result, Internal_Unit)); |
|---|
| | 3594 | |
|---|
| | 3595 | elsif Pragma_Kind (El) = An_Elaborate_All_Pragma then |
|---|
| | 3596 | Internal_Unit := Get_Compilation_Unit |
|---|
| | 3597 | (Unit, With_List (Index), Index, The_Context); |
|---|
| | 3598 | |
|---|
| | 3599 | Elab_Body (Find (Result, Internal_Unit), True); |
|---|
| | 3600 | end if; |
|---|
| | 3601 | end if; |
|---|
| | 3602 | end loop; |
|---|
| | 3603 | end Elab_Pragmed_Bodys; |
|---|
| | 3604 | |
|---|
| | 3605 | -- Process_Pure_Spec -- |
|---|
| | 3606 | procedure Process_Pure_Spec |
|---|
| | 3607 | (Node : in Tree_Node_Access) |
|---|
| | 3608 | is |
|---|
| | 3609 | -- A_Pure_Pragma -- 10.2.1(14) |
|---|
| 3403 | | end Process_Pure; |
|---|
| | 3624 | end Process_Pure_Spec; |
|---|
| | 3625 | |
|---|
| | 3626 | -- Process_Pure_Body -- |
|---|
| | 3627 | procedure Process_Pure_Body |
|---|
| | 3628 | (Node : in Tree_Node_Access) |
|---|
| | 3629 | is |
|---|
| | 3630 | -- A_Pure_Pragma -- 10.2.1(14) |
|---|
| | 3631 | begin |
|---|
| | 3632 | if Is_Pure (Node) then |
|---|
| | 3633 | Elab_Body (Node); |
|---|
| | 3634 | end if; |
|---|
| | 3635 | |
|---|
| | 3636 | if Node.Prevs /= null then |
|---|
| | 3637 | for Index in Node.Prevs.all'Range loop |
|---|
| | 3638 | Process_Pure_Body (Node.Prevs (Index)); |
|---|
| | 3639 | end loop; |
|---|
| | 3640 | end if; |
|---|
| | 3641 | end Process_Pure_Body; |
|---|
| | 3642 | |
|---|
| | 3643 | -- Process_Preelaborate_Spec -- |
|---|
| | 3644 | procedure Process_Preelaborate_Spec |
|---|
| | 3645 | (Node : in Tree_Node_Access) |
|---|
| | 3646 | is |
|---|
| | 3647 | -- A_Preelaborate_Pragma -- 10.2.1(3) |
|---|
| | 3648 | begin |
|---|
| | 3649 | if not Node.Elaborated |
|---|
| | 3650 | and then not Is_Nil (Node.Unit) |
|---|
| | 3651 | then |
|---|
| | 3652 | if Is_Preelaborate (Node) then |
|---|
| | 3653 | Elab_Spec (Node); |
|---|
| | 3654 | end if; |
|---|
| | 3655 | end if; |
|---|
| | 3656 | |
|---|
| | 3657 | if Node.Prevs /= null then |
|---|
| | 3658 | for Index in Node.Prevs.all'Range loop |
|---|
| | 3659 | Process_Preelaborate_Spec (Node.Prevs (Index)); |
|---|
| | 3660 | end loop; |
|---|
| | 3661 | end if; |
|---|
| | 3662 | end Process_Preelaborate_Spec; |
|---|
| | 3663 | |
|---|
| | 3664 | -- Process_Preelaborate_Body -- |
|---|
| | 3665 | procedure Process_Preelaborate_Body |
|---|
| | 3666 | (Node : in Tree_Node_Access) |
|---|
| | 3667 | is |
|---|
| | 3668 | -- A_Preelaborate_Pragma -- 10.2.1(3) |
|---|
| | 3669 | begin |
|---|
| | 3670 | if Is_Preelaborate (Node) then |
|---|
| | 3671 | Elab_Body (Node); |
|---|
| | 3672 | end if; |
|---|
| | 3673 | |
|---|
| | 3674 | if Node.Prevs /= null then |
|---|
| | 3675 | for Index in Node.Prevs.all'Range loop |
|---|
| | 3676 | Process_Preelaborate_Body (Node.Prevs (Index)); |
|---|
| | 3677 | end loop; |
|---|
| | 3678 | end if; |
|---|
| | 3679 | end Process_Preelaborate_Body; |
|---|
| | 3680 | |
|---|
| | 3681 | -- Process_Spec -- |
|---|
| | 3682 | procedure Process_Spec |
|---|
| | 3683 | (Node : in Tree_Node_Access) |
|---|
| | 3684 | is |
|---|
| | 3685 | begin |
|---|
| | 3686 | if not Node.Elaborated |
|---|
| | 3687 | and then not Is_Nil (Node.Unit) |
|---|
| | 3688 | then |
|---|
| | 3689 | Elab_Spec (Node); |
|---|
| | 3690 | end if; |
|---|
| | 3691 | |
|---|
| | 3692 | if Node.Prevs /= null then |
|---|
| | 3693 | for Index in Node.Prevs.all'Range loop |
|---|
| | 3694 | Process_Spec (Node.Prevs (Index)); |
|---|
| | 3695 | end loop; |
|---|
| | 3696 | end if; |
|---|
| | 3697 | end Process_Spec; |
|---|
| | 3698 | |
|---|
| | 3699 | -- Process_Body -- |
|---|
| | 3700 | procedure Process_Body |
|---|
| | 3701 | (Node : in Tree_Node_Access) |
|---|
| | 3702 | is |
|---|
| | 3703 | begin |
|---|
| | 3704 | Elab_Body (Node); |
|---|
| | 3705 | |
|---|
| | 3706 | if Node.Prevs /= null then |
|---|
| | 3707 | for Index in Node.Prevs.all'Range loop |
|---|
| | 3708 | Process_Body (Node.Prevs (Index)); |
|---|
| | 3709 | end loop; |
|---|
| | 3710 | end if; |
|---|
| | 3711 | end Process_Body; |
|---|
| 3411 | | if Root_Node.Prevs /= null then |
|---|
| 3412 | | for Index in Root_Node.Prevs.all'Range loop |
|---|
| 3413 | | Process_Pure (Root_Node.Prevs (Index)); |
|---|
| 3414 | | end loop; |
|---|
| 3415 | | end if; |
|---|
| | 3719 | if Root_Node.Prevs = null then |
|---|
| | 3720 | return Result; |
|---|
| | 3721 | end if; |
|---|
| | 3722 | |
|---|
| | 3723 | for Index in Root_Node.Prevs.all'Range loop |
|---|
| | 3724 | Deallocate (Elaboration_Line); |
|---|
| | 3725 | Process_Pure_Spec (Root_Node.Prevs (Index)); |
|---|
| | 3726 | end loop; |
|---|
| | 3727 | |
|---|
| | 3728 | for Index in Root_Node.Prevs.all'Range loop |
|---|
| | 3729 | Deallocate (Elaboration_Line); |
|---|
| | 3730 | Process_Pure_Body (Root_Node.Prevs (Index)); |
|---|
| | 3731 | end loop; |
|---|
| | 3732 | |
|---|
| | 3733 | for Index in Root_Node.Prevs.all'Range loop |
|---|
| | 3734 | Deallocate (Elaboration_Line); |
|---|
| | 3735 | Process_Preelaborate_Spec (Root_Node.Prevs (Index)); |
|---|
| | 3736 | end loop; |
|---|
| | 3737 | |
|---|
| | 3738 | for Index in Root_Node.Prevs.all'Range loop |
|---|
| | 3739 | Deallocate (Elaboration_Line); |
|---|
| | 3740 | Process_Preelaborate_Body (Root_Node.Prevs (Index)); |
|---|
| | 3741 | end loop; |
|---|
| | 3742 | |
|---|
| | 3743 | for Index in Root_Node.Prevs.all'Range loop |
|---|
| | 3744 | Deallocate (Elaboration_Line); |
|---|
| | 3745 | Process_Spec (Root_Node.Prevs (Index)); |
|---|
| | 3746 | end loop; |
|---|
| | 3747 | |
|---|
| | 3748 | for Index in Root_Node.Prevs.all'Range loop |
|---|
| | 3749 | Deallocate (Elaboration_Line); |
|---|
| | 3750 | Process_Body (Root_Node.Prevs (Index)); |
|---|
| | 3751 | end loop; |
|---|
| | 3779 | |
|---|
| | 3780 | --------------------- |
|---|
| | 3781 | -- Is_Preelaborate -- |
|---|
| | 3782 | --------------------- |
|---|
| | 3783 | |
|---|
| | 3784 | function Is_Preelaborate |
|---|
| | 3785 | (This : in Tree_Node_Access) |
|---|
| | 3786 | return Boolean |
|---|
| | 3787 | is |
|---|
| | 3788 | begin |
|---|
| | 3789 | if This.Internal_Preelaborate = Unknown then |
|---|
| | 3790 | Retrive_Pragmas (This); |
|---|
| | 3791 | end if; |
|---|
| | 3792 | |
|---|
| | 3793 | if This.Internal_Preelaborate = Extended_True then |
|---|
| | 3794 | return True; |
|---|
| | 3795 | else |
|---|
| | 3796 | return False; |
|---|
| | 3797 | end if; |
|---|
| | 3798 | end Is_Preelaborate; |
|---|
| | 3799 | |
|---|
| | 3800 | ----------------------- |
|---|
| | 3801 | -- Is_Elaborate_Body -- |
|---|
| | 3802 | ----------------------- |
|---|
| | 3803 | |
|---|
| | 3804 | function Is_Elaborate_Body |
|---|
| | 3805 | (This : in Tree_Node_Access) |
|---|
| | 3806 | return Boolean |
|---|
| | 3807 | is |
|---|
| | 3808 | begin |
|---|
| | 3809 | if This.Internal_Spec_With_Body = Unknown then |
|---|
| | 3810 | Retrive_Pragmas (This); |
|---|
| | 3811 | end if; |
|---|
| | 3812 | |
|---|
| | 3813 | if This.Internal_Spec_With_Body = Extended_True then |
|---|
| | 3814 | return True; |
|---|
| | 3815 | else |
|---|
| | 3816 | return False; |
|---|
| | 3817 | end if; |
|---|
| | 3818 | end Is_Elaborate_Body; |
|---|
| | 3819 | |
|---|
| | 3820 | --------------------- |
|---|
| | 3821 | -- Retrive_Pragmas -- |
|---|
| | 3822 | --------------------- |
|---|
| | 3823 | |
|---|
| | 3824 | procedure Retrive_Pragmas |
|---|
| | 3825 | (This : in Tree_Node_Access) |
|---|
| | 3826 | is |
|---|
| | 3827 | begin |
|---|
| | 3828 | if Is_Nil (This.Unit) then |
|---|
| | 3829 | return; |
|---|
| | 3830 | end if; |
|---|
| | 3831 | |
|---|
| | 3832 | declare |
|---|
| | 3833 | Pragma_List : constant Asis.Pragma_Element_List := |
|---|
| | 3834 | Asis.Elements.Corresponding_Pragmas |
|---|
| | 3835 | (Asis.Elements.Unit_Declaration (This.Unit)); |
|---|
| | 3836 | begin |
|---|
| | 3837 | for Index in Pragma_List'Range loop |
|---|
| | 3838 | if Pragma_Kind (Pragma_List (Index).all) = A_Pure_Pragma then |
|---|
| | 3839 | This.Internal_Pure := Extended_True; |
|---|
| | 3840 | end if; |
|---|
| | 3841 | |
|---|
| | 3842 | if Pragma_Kind (Pragma_List (Index).all) = |
|---|
| | 3843 | A_Preelaborate_Pragma |
|---|
| | 3844 | then |
|---|
| | 3845 | This.Internal_Preelaborate := Extended_True; |
|---|
| | 3846 | end if; |
|---|
| | 3847 | |
|---|
| | 3848 | if Pragma_Kind (Pragma_List (Index).all) = |
|---|
| | 3849 | An_Elaborate_Body_Pragma |
|---|
| | 3850 | then |
|---|
| | 3851 | This.Internal_Spec_With_Body := Extended_True; |
|---|
| | 3852 | end if; |
|---|
| | 3853 | |
|---|
| | 3854 | end loop; |
|---|
| | 3855 | end; |
|---|
| | 3856 | |
|---|
| | 3857 | if This.Internal_Pure = Unknown then |
|---|
| | 3858 | This.Internal_Pure := Extended_False; |
|---|
| | 3859 | end if; |
|---|
| | 3860 | |
|---|
| | 3861 | if This.Internal_Preelaborate = Extended_True then |
|---|
| | 3862 | This.Internal_Preelaborate := Extended_False; |
|---|
| | 3863 | end if; |
|---|
| | 3864 | |
|---|
| | 3865 | if This.Internal_Spec_With_Body = Unknown then |
|---|
| | 3866 | This.Internal_Spec_With_Body := Extended_False; |
|---|
| | 3867 | end if; |
|---|
| | 3868 | end Retrive_Pragmas; |
|---|