Mercurial > hg > CbC > CbC_gcc
comparison gcc/ada/sem_prag.adb @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
4 -- -- | 4 -- -- |
5 -- S E M _ P R A G -- | 5 -- S E M _ P R A G -- |
6 -- -- | 6 -- -- |
7 -- B o d y -- | 7 -- B o d y -- |
8 -- -- | 8 -- -- |
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. -- | 9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. -- |
10 -- -- | 10 -- -- |
11 -- GNAT is free software; you can redistribute it and/or modify it under -- | 11 -- GNAT is free software; you can redistribute it and/or modify it under -- |
12 -- terms of the GNU General Public License as published by the Free Soft- -- | 12 -- terms of the GNU General Public License as published by the Free Soft- -- |
13 -- ware Foundation; either version 3, or (at your option) any later ver- -- | 13 -- ware Foundation; either version 3, or (at your option) any later ver- -- |
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- | 14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
62 with Sem_Ch8; use Sem_Ch8; | 62 with Sem_Ch8; use Sem_Ch8; |
63 with Sem_Ch12; use Sem_Ch12; | 63 with Sem_Ch12; use Sem_Ch12; |
64 with Sem_Ch13; use Sem_Ch13; | 64 with Sem_Ch13; use Sem_Ch13; |
65 with Sem_Disp; use Sem_Disp; | 65 with Sem_Disp; use Sem_Disp; |
66 with Sem_Dist; use Sem_Dist; | 66 with Sem_Dist; use Sem_Dist; |
67 with Sem_Elab; use Sem_Elab; | |
67 with Sem_Elim; use Sem_Elim; | 68 with Sem_Elim; use Sem_Elim; |
68 with Sem_Eval; use Sem_Eval; | 69 with Sem_Eval; use Sem_Eval; |
69 with Sem_Intr; use Sem_Intr; | 70 with Sem_Intr; use Sem_Intr; |
70 with Sem_Mech; use Sem_Mech; | 71 with Sem_Mech; use Sem_Mech; |
71 with Sem_Res; use Sem_Res; | 72 with Sem_Res; use Sem_Res; |
215 procedure Contract_Freeze_Error | 216 procedure Contract_Freeze_Error |
216 (Contract_Id : Entity_Id; | 217 (Contract_Id : Entity_Id; |
217 Freeze_Id : Entity_Id); | 218 Freeze_Id : Entity_Id); |
218 -- Subsidiary to the analysis of pragmas Contract_Cases, Part_Of, Post, and | 219 -- Subsidiary to the analysis of pragmas Contract_Cases, Part_Of, Post, and |
219 -- Pre. Emit a freezing-related error message where Freeze_Id is the entity | 220 -- Pre. Emit a freezing-related error message where Freeze_Id is the entity |
220 -- of a body which caused contract "freezing" and Contract_Id denotes the | 221 -- of a body which caused contract freezing and Contract_Id denotes the |
221 -- entity of the affected contstruct. | 222 -- entity of the affected contstruct. |
222 | 223 |
223 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id); | 224 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id); |
224 -- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma | 225 -- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma |
225 -- Prag that duplicates previous pragma Prev. | 226 -- Prag that duplicates previous pragma Prev. |
430 Errors := Serious_Errors_Detected; | 431 Errors := Serious_Errors_Detected; |
431 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean); | 432 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean); |
432 | 433 |
433 -- Emit a clarification message when the case guard contains | 434 -- Emit a clarification message when the case guard contains |
434 -- at least one undefined reference, possibly due to contract | 435 -- at least one undefined reference, possibly due to contract |
435 -- "freezing". | 436 -- freezing. |
436 | 437 |
437 if Errors /= Serious_Errors_Detected | 438 if Errors /= Serious_Errors_Detected |
438 and then Present (Freeze_Id) | 439 and then Present (Freeze_Id) |
439 and then Has_Undefined_Reference (Case_Guard) | 440 and then Has_Undefined_Reference (Case_Guard) |
440 then | 441 then |
445 Errors := Serious_Errors_Detected; | 446 Errors := Serious_Errors_Detected; |
446 Preanalyze_Assert_Expression (Conseq, Standard_Boolean); | 447 Preanalyze_Assert_Expression (Conseq, Standard_Boolean); |
447 | 448 |
448 -- Emit a clarification message when the consequence contains | 449 -- Emit a clarification message when the consequence contains |
449 -- at least one undefined reference, possibly due to contract | 450 -- at least one undefined reference, possibly due to contract |
450 -- "freezing". | 451 -- freezing. |
451 | 452 |
452 if Errors /= Serious_Errors_Detected | 453 if Errors /= Serious_Errors_Detected |
453 and then Present (Freeze_Id) | 454 and then Present (Freeze_Id) |
454 and then Has_Undefined_Reference (Conseq) | 455 and then Has_Undefined_Reference (Conseq) |
455 then | 456 then |
465 | 466 |
466 -- Local variables | 467 -- Local variables |
467 | 468 |
468 CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id)); | 469 CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id)); |
469 | 470 |
470 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; | 471 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
471 -- Save the Ghost mode to restore on exit | 472 Saved_IGR : constant Node_Id := Ignored_Ghost_Region; |
473 -- Save the Ghost-related attributes to restore on exit | |
472 | 474 |
473 CCase : Node_Id; | 475 CCase : Node_Id; |
474 Restore_Scope : Boolean := False; | 476 Restore_Scope : Boolean := False; |
475 | 477 |
476 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part | 478 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part |
533 Error_Msg_N ("wrong syntax for constract cases", N); | 535 Error_Msg_N ("wrong syntax for constract cases", N); |
534 end if; | 536 end if; |
535 | 537 |
536 Set_Is_Analyzed_Pragma (N); | 538 Set_Is_Analyzed_Pragma (N); |
537 | 539 |
538 Restore_Ghost_Mode (Saved_GM); | 540 Restore_Ghost_Region (Saved_GM, Saved_IGR); |
539 end Analyze_Contract_Cases_In_Decl_Part; | 541 end Analyze_Contract_Cases_In_Decl_Part; |
540 | 542 |
541 ---------------------------------- | 543 ---------------------------------- |
542 -- Analyze_Depends_In_Decl_Part -- | 544 -- Analyze_Depends_In_Decl_Part -- |
543 ---------------------------------- | 545 ---------------------------------- |
938 | 940 |
939 -- States, variables | 941 -- States, variables |
940 | 942 |
941 Ekind_In (Item_Id, E_Abstract_State, E_Variable) | 943 Ekind_In (Item_Id, E_Abstract_State, E_Variable) |
942 then | 944 then |
945 -- A [generic] function is not allowed to have Output | |
946 -- items in its dependency relations. Note that "null" | |
947 -- and attribute 'Result are still valid items. | |
948 | |
949 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) | |
950 and then not Is_Input | |
951 then | |
952 SPARK_Msg_N | |
953 ("output item is not applicable to function", Item); | |
954 end if; | |
955 | |
943 -- The item denotes a concurrent type. Note that single | 956 -- The item denotes a concurrent type. Note that single |
944 -- protected/task types are not considered here because | 957 -- protected/task types are not considered here because |
945 -- they behave as objects in the context of pragma | 958 -- they behave as objects in the context of pragma |
946 -- [Refined_]Depends. | 959 -- [Refined_]Depends. |
947 | 960 |
2007 | 2020 |
2008 procedure Analyze_External_Property_In_Decl_Part | 2021 procedure Analyze_External_Property_In_Decl_Part |
2009 (N : Node_Id; | 2022 (N : Node_Id; |
2010 Expr_Val : out Boolean) | 2023 Expr_Val : out Boolean) |
2011 is | 2024 is |
2012 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N)); | 2025 Arg1 : constant Node_Id := |
2013 Obj_Decl : constant Node_Id := Find_Related_Context (N); | 2026 First (Pragma_Argument_Associations (N)); |
2027 Obj_Decl : constant Node_Id := Find_Related_Context (N); | |
2014 Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl); | 2028 Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl); |
2015 Expr : Node_Id; | 2029 Expr : Node_Id; |
2016 | 2030 |
2017 begin | 2031 begin |
2018 Expr_Val := False; | 2032 Expr_Val := False; |
2112 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)). | 2126 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)). |
2113 | 2127 |
2114 procedure Check_Mode_Restriction_In_Enclosing_Context | 2128 procedure Check_Mode_Restriction_In_Enclosing_Context |
2115 (Item : Node_Id; | 2129 (Item : Node_Id; |
2116 Item_Id : Entity_Id); | 2130 Item_Id : Entity_Id); |
2117 -- Verify that an item of mode In_Out or Output does not appear as an | 2131 -- Verify that an item of mode In_Out or Output does not appear as |
2118 -- input in the Global aspect of an enclosing subprogram. If this is | 2132 -- an input in the Global aspect of an enclosing subprogram or task |
2119 -- the case, emit an error. Item and Item_Id are respectively the | 2133 -- unit. If this is the case, emit an error. Item and Item_Id are |
2120 -- item and its entity. | 2134 -- respectively the item and its entity. |
2121 | 2135 |
2122 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id); | 2136 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id); |
2123 -- Mode denotes either In_Out or Output. Depending on the kind of the | 2137 -- Mode denotes either In_Out or Output. Depending on the kind of the |
2124 -- related subprogram, emit an error if those two modes apply to a | 2138 -- related subprogram, emit an error if those two modes apply to a |
2125 -- function (SPARK RM 6.1.4(10)). | 2139 -- function (SPARK RM 6.1.4(10)). |
2467 Dummy : Boolean; | 2481 Dummy : Boolean; |
2468 Inputs : Elist_Id := No_Elist; | 2482 Inputs : Elist_Id := No_Elist; |
2469 Outputs : Elist_Id := No_Elist; | 2483 Outputs : Elist_Id := No_Elist; |
2470 | 2484 |
2471 begin | 2485 begin |
2472 -- Traverse the scope stack looking for enclosing subprograms | 2486 -- Traverse the scope stack looking for enclosing subprograms or |
2473 -- subject to pragma [Refined_]Global. | 2487 -- tasks subject to pragma [Refined_]Global. |
2474 | 2488 |
2475 Context := Scope (Subp_Id); | 2489 Context := Scope (Subp_Id); |
2476 while Present (Context) and then Context /= Standard_Standard loop | 2490 while Present (Context) and then Context /= Standard_Standard loop |
2477 if Is_Subprogram (Context) | 2491 |
2492 -- For a single task type, retrieve the corresponding object to | |
2493 -- which pragma [Refined_]Global is attached. | |
2494 | |
2495 if Ekind (Context) = E_Task_Type | |
2496 and then Is_Single_Concurrent_Type (Context) | |
2497 then | |
2498 Context := Anonymous_Object (Context); | |
2499 end if; | |
2500 | |
2501 if (Is_Subprogram (Context) | |
2502 or else Ekind (Context) = E_Task_Type | |
2503 or else Is_Single_Task_Object (Context)) | |
2478 and then | 2504 and then |
2479 (Present (Get_Pragma (Context, Pragma_Global)) | 2505 (Present (Get_Pragma (Context, Pragma_Global)) |
2480 or else | 2506 or else |
2481 Present (Get_Pragma (Context, Pragma_Refined_Global))) | 2507 Present (Get_Pragma (Context, Pragma_Refined_Global))) |
2482 then | 2508 then |
2483 Collect_Subprogram_Inputs_Outputs | 2509 Collect_Subprogram_Inputs_Outputs |
2484 (Subp_Id => Context, | 2510 (Subp_Id => Context, |
2485 Subp_Inputs => Inputs, | 2511 Subp_Inputs => Inputs, |
2486 Subp_Outputs => Outputs, | 2512 Subp_Outputs => Outputs, |
2487 Global_Seen => Dummy); | 2513 Global_Seen => Dummy); |
2488 | 2514 |
2489 -- The item is classified as In_Out or Output but appears as | 2515 -- The item is classified as In_Out or Output but appears as |
2490 -- an Input in an enclosing subprogram (SPARK RM 6.1.4(12)). | 2516 -- an Input in an enclosing subprogram or task unit (SPARK |
2517 -- RM 6.1.4(12)). | |
2491 | 2518 |
2492 if Appears_In (Inputs, Item_Id) | 2519 if Appears_In (Inputs, Item_Id) |
2493 and then not Appears_In (Outputs, Item_Id) | 2520 and then not Appears_In (Outputs, Item_Id) |
2494 then | 2521 then |
2495 SPARK_Msg_NE | 2522 SPARK_Msg_NE |
2496 ("global item & cannot have mode In_Out or Output", | 2523 ("global item & cannot have mode In_Out or Output", |
2497 Item, Item_Id); | 2524 Item, Item_Id); |
2498 | 2525 |
2499 SPARK_Msg_NE | 2526 if Is_Subprogram (Context) then |
2500 (Fix_Msg (Subp_Id, "\item already appears as input of " | 2527 SPARK_Msg_NE |
2501 & "subprogram &"), Item, Context); | 2528 (Fix_Msg (Subp_Id, "\item already appears as input " |
2529 & "of subprogram &"), Item, Context); | |
2530 else | |
2531 SPARK_Msg_NE | |
2532 (Fix_Msg (Subp_Id, "\item already appears as input " | |
2533 & "of task &"), Item, Context); | |
2534 end if; | |
2502 | 2535 |
2503 -- Stop the traversal once an error has been detected | 2536 -- Stop the traversal once an error has been detected |
2504 | 2537 |
2505 exit; | 2538 exit; |
2506 end if; | 2539 end if; |
2705 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is | 2738 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is |
2706 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N); | 2739 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N); |
2707 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl); | 2740 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl); |
2708 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id)); | 2741 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id)); |
2709 | 2742 |
2710 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; | 2743 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
2711 -- Save the Ghost mode to restore on exit | 2744 Saved_IGR : constant Node_Id := Ignored_Ghost_Region; |
2745 -- Save the Ghost-related attributes to restore on exit | |
2712 | 2746 |
2713 begin | 2747 begin |
2714 -- Do not analyze the pragma multiple times | 2748 -- Do not analyze the pragma multiple times |
2715 | 2749 |
2716 if Is_Analyzed_Pragma (N) then | 2750 if Is_Analyzed_Pragma (N) then |
2729 -- is not desired at this point. | 2763 -- is not desired at this point. |
2730 | 2764 |
2731 Preanalyze_Assert_Expression (Expr, Standard_Boolean); | 2765 Preanalyze_Assert_Expression (Expr, Standard_Boolean); |
2732 Set_Is_Analyzed_Pragma (N); | 2766 Set_Is_Analyzed_Pragma (N); |
2733 | 2767 |
2734 Restore_Ghost_Mode (Saved_GM); | 2768 Restore_Ghost_Region (Saved_GM, Saved_IGR); |
2735 end Analyze_Initial_Condition_In_Decl_Part; | 2769 end Analyze_Initial_Condition_In_Decl_Part; |
2736 | 2770 |
2737 -------------------------------------- | 2771 -------------------------------------- |
2738 -- Analyze_Initializes_In_Decl_Part -- | 2772 -- Analyze_Initializes_In_Decl_Part -- |
2739 -------------------------------------- | 2773 -------------------------------------- |
2749 | 2783 |
2750 Items_Seen : Elist_Id := No_Elist; | 2784 Items_Seen : Elist_Id := No_Elist; |
2751 -- A list of all initialization items processed so far. This list is | 2785 -- A list of all initialization items processed so far. This list is |
2752 -- used to detect duplicate items. | 2786 -- used to detect duplicate items. |
2753 | 2787 |
2754 Non_Null_Seen : Boolean := False; | |
2755 Null_Seen : Boolean := False; | |
2756 -- Flags used to check the legality of a null initialization list | |
2757 | |
2758 States_And_Objs : Elist_Id := No_Elist; | 2788 States_And_Objs : Elist_Id := No_Elist; |
2759 -- A list of all abstract states and objects declared in the visible | 2789 -- A list of all abstract states and objects declared in the visible |
2760 -- declarations of the related package. This list is used to detect the | 2790 -- declarations of the related package. This list is used to detect the |
2761 -- legality of initialization items. | 2791 -- legality of initialization items. |
2762 | 2792 |
2782 | 2812 |
2783 procedure Analyze_Initialization_Item (Item : Node_Id) is | 2813 procedure Analyze_Initialization_Item (Item : Node_Id) is |
2784 Item_Id : Entity_Id; | 2814 Item_Id : Entity_Id; |
2785 | 2815 |
2786 begin | 2816 begin |
2787 -- Null initialization list | 2817 Analyze (Item); |
2788 | 2818 Resolve_State (Item); |
2789 if Nkind (Item) = N_Null then | 2819 |
2790 if Null_Seen then | 2820 if Is_Entity_Name (Item) then |
2791 SPARK_Msg_N ("multiple null initializations not allowed", Item); | 2821 Item_Id := Entity_Of (Item); |
2792 | 2822 |
2793 elsif Non_Null_Seen then | 2823 if Present (Item_Id) |
2824 and then Ekind_In (Item_Id, E_Abstract_State, | |
2825 E_Constant, | |
2826 E_Variable) | |
2827 then | |
2828 -- When the initialization item is undefined, it appears as | |
2829 -- Any_Id. Do not continue with the analysis of the item. | |
2830 | |
2831 if Item_Id = Any_Id then | |
2832 null; | |
2833 | |
2834 -- The state or variable must be declared in the visible | |
2835 -- declarations of the package (SPARK RM 7.1.5(7)). | |
2836 | |
2837 elsif not Contains (States_And_Objs, Item_Id) then | |
2838 Error_Msg_Name_1 := Chars (Pack_Id); | |
2839 SPARK_Msg_NE | |
2840 ("initialization item & must appear in the visible " | |
2841 & "declarations of package %", Item, Item_Id); | |
2842 | |
2843 -- Detect a duplicate use of the same initialization item | |
2844 -- (SPARK RM 7.1.5(5)). | |
2845 | |
2846 elsif Contains (Items_Seen, Item_Id) then | |
2847 SPARK_Msg_N ("duplicate initialization item", Item); | |
2848 | |
2849 -- The item is legal, add it to the list of processed states | |
2850 -- and variables. | |
2851 | |
2852 else | |
2853 Append_New_Elmt (Item_Id, Items_Seen); | |
2854 | |
2855 if Ekind (Item_Id) = E_Abstract_State then | |
2856 Append_New_Elmt (Item_Id, States_Seen); | |
2857 end if; | |
2858 | |
2859 if Present (Encapsulating_State (Item_Id)) then | |
2860 Append_New_Elmt (Item_Id, Constits_Seen); | |
2861 end if; | |
2862 end if; | |
2863 | |
2864 -- The item references something that is not a state or object | |
2865 -- (SPARK RM 7.1.5(3)). | |
2866 | |
2867 else | |
2794 SPARK_Msg_N | 2868 SPARK_Msg_N |
2795 ("cannot mix null and non-null initialization items", Item); | 2869 ("initialization item must denote object or state", Item); |
2796 else | 2870 end if; |
2797 Null_Seen := True; | 2871 |
2798 end if; | 2872 -- Some form of illegal construct masquerading as a name |
2799 | 2873 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report. |
2800 -- Initialization item | |
2801 | 2874 |
2802 else | 2875 else |
2803 Non_Null_Seen := True; | 2876 Error_Msg_N |
2804 | 2877 ("initialization item must denote object or state", Item); |
2805 if Null_Seen then | |
2806 SPARK_Msg_N | |
2807 ("cannot mix null and non-null initialization items", Item); | |
2808 end if; | |
2809 | |
2810 Analyze (Item); | |
2811 Resolve_State (Item); | |
2812 | |
2813 if Is_Entity_Name (Item) then | |
2814 Item_Id := Entity_Of (Item); | |
2815 | |
2816 if Present (Item_Id) | |
2817 and then Ekind_In (Item_Id, E_Abstract_State, | |
2818 E_Constant, | |
2819 E_Variable) | |
2820 then | |
2821 -- When the initialization item is undefined, it appears as | |
2822 -- Any_Id. Do not continue with the analysis of the item. | |
2823 | |
2824 if Item_Id = Any_Id then | |
2825 null; | |
2826 | |
2827 -- The state or variable must be declared in the visible | |
2828 -- declarations of the package (SPARK RM 7.1.5(7)). | |
2829 | |
2830 elsif not Contains (States_And_Objs, Item_Id) then | |
2831 Error_Msg_Name_1 := Chars (Pack_Id); | |
2832 SPARK_Msg_NE | |
2833 ("initialization item & must appear in the visible " | |
2834 & "declarations of package %", Item, Item_Id); | |
2835 | |
2836 -- Detect a duplicate use of the same initialization item | |
2837 -- (SPARK RM 7.1.5(5)). | |
2838 | |
2839 elsif Contains (Items_Seen, Item_Id) then | |
2840 SPARK_Msg_N ("duplicate initialization item", Item); | |
2841 | |
2842 -- The item is legal, add it to the list of processed states | |
2843 -- and variables. | |
2844 | |
2845 else | |
2846 Append_New_Elmt (Item_Id, Items_Seen); | |
2847 | |
2848 if Ekind (Item_Id) = E_Abstract_State then | |
2849 Append_New_Elmt (Item_Id, States_Seen); | |
2850 end if; | |
2851 | |
2852 if Present (Encapsulating_State (Item_Id)) then | |
2853 Append_New_Elmt (Item_Id, Constits_Seen); | |
2854 end if; | |
2855 end if; | |
2856 | |
2857 -- The item references something that is not a state or object | |
2858 -- (SPARK RM 7.1.5(3)). | |
2859 | |
2860 else | |
2861 SPARK_Msg_N | |
2862 ("initialization item must denote object or state", Item); | |
2863 end if; | |
2864 | |
2865 -- Some form of illegal construct masquerading as a name | |
2866 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report. | |
2867 | |
2868 else | |
2869 Error_Msg_N | |
2870 ("initialization item must denote object or state", Item); | |
2871 end if; | |
2872 end if; | 2878 end if; |
2873 end Analyze_Initialization_Item; | 2879 end Analyze_Initialization_Item; |
2874 | 2880 |
2875 --------------------------------------------- | 2881 --------------------------------------------- |
2876 -- Analyze_Initialization_Item_With_Inputs -- | 2882 -- Analyze_Initialization_Item_With_Inputs -- |
2892 -- Analyze_Input_Item -- | 2898 -- Analyze_Input_Item -- |
2893 ------------------------ | 2899 ------------------------ |
2894 | 2900 |
2895 procedure Analyze_Input_Item (Input : Node_Id) is | 2901 procedure Analyze_Input_Item (Input : Node_Id) is |
2896 Input_Id : Entity_Id; | 2902 Input_Id : Entity_Id; |
2897 Input_OK : Boolean := True; | |
2898 | 2903 |
2899 begin | 2904 begin |
2900 -- Null input list | 2905 -- Null input list |
2901 | 2906 |
2902 if Nkind (Input) = N_Null then | 2907 if Nkind (Input) = N_Null then |
2933 E_Generic_In_Out_Parameter, | 2938 E_Generic_In_Out_Parameter, |
2934 E_Generic_In_Parameter, | 2939 E_Generic_In_Parameter, |
2935 E_In_Parameter, | 2940 E_In_Parameter, |
2936 E_In_Out_Parameter, | 2941 E_In_Out_Parameter, |
2937 E_Out_Parameter, | 2942 E_Out_Parameter, |
2943 E_Protected_Type, | |
2944 E_Task_Type, | |
2938 E_Variable) | 2945 E_Variable) |
2939 then | 2946 then |
2940 -- The input cannot denote states or objects declared | 2947 -- The input cannot denote states or objects declared |
2941 -- within the related package (SPARK RM 7.1.5(4)). | 2948 -- within the related package (SPARK RM 7.1.5(4)). |
2942 | 2949 |
2958 (Declaration_Node (Input_Id))) | 2965 (Declaration_Node (Input_Id))) |
2959 then | 2966 then |
2960 null; | 2967 null; |
2961 | 2968 |
2962 else | 2969 else |
2963 Input_OK := False; | |
2964 Error_Msg_Name_1 := Chars (Pack_Id); | 2970 Error_Msg_Name_1 := Chars (Pack_Id); |
2965 SPARK_Msg_NE | 2971 SPARK_Msg_NE |
2966 ("input item & cannot denote a visible object or " | 2972 ("input item & cannot denote a visible object or " |
2967 & "state of package %", Input, Input_Id); | 2973 & "state of package %", Input, Input_Id); |
2974 return; | |
2968 end if; | 2975 end if; |
2969 end if; | 2976 end if; |
2970 | 2977 |
2971 -- Detect a duplicate use of the same input item | 2978 -- Detect a duplicate use of the same input item |
2972 -- (SPARK RM 7.1.5(5)). | 2979 -- (SPARK RM 7.1.5(5)). |
2973 | 2980 |
2974 if Contains (Inputs_Seen, Input_Id) then | 2981 if Contains (Inputs_Seen, Input_Id) then |
2975 Input_OK := False; | |
2976 SPARK_Msg_N ("duplicate input item", Input); | 2982 SPARK_Msg_N ("duplicate input item", Input); |
2983 return; | |
2977 end if; | 2984 end if; |
2978 | 2985 |
2979 -- Input is legal, add it to the list of processed inputs | 2986 -- At this point it is known that the input is legal. Add |
2980 | 2987 -- it to the list of processed inputs. |
2981 if Input_OK then | 2988 |
2982 Append_New_Elmt (Input_Id, Inputs_Seen); | 2989 Append_New_Elmt (Input_Id, Inputs_Seen); |
2983 | 2990 |
2984 if Ekind (Input_Id) = E_Abstract_State then | 2991 if Ekind (Input_Id) = E_Abstract_State then |
2985 Append_New_Elmt (Input_Id, States_Seen); | 2992 Append_New_Elmt (Input_Id, States_Seen); |
2986 end if; | 2993 end if; |
2987 | 2994 |
2988 if Ekind_In (Input_Id, E_Abstract_State, | 2995 if Ekind_In (Input_Id, E_Abstract_State, |
2989 E_Constant, | 2996 E_Constant, |
2990 E_Variable) | 2997 E_Variable) |
2991 and then Present (Encapsulating_State (Input_Id)) | 2998 and then Present (Encapsulating_State (Input_Id)) |
2992 then | 2999 then |
2993 Append_New_Elmt (Input_Id, Constits_Seen); | 3000 Append_New_Elmt (Input_Id, Constits_Seen); |
2994 end if; | |
2995 end if; | 3001 end if; |
2996 | 3002 |
2997 -- The input references something that is not a state or an | 3003 -- The input references something that is not a state or an |
2998 -- object (SPARK RM 7.1.5(3)). | 3004 -- object (SPARK RM 7.1.5(3)). |
2999 | 3005 |
3165 Item_Id : Entity_Id; | 3171 Item_Id : Entity_Id; |
3166 Encap : Node_Id; | 3172 Encap : Node_Id; |
3167 Encap_Id : out Entity_Id; | 3173 Encap_Id : out Entity_Id; |
3168 Legal : out Boolean) | 3174 Legal : out Boolean) |
3169 is | 3175 is |
3170 Encap_Typ : Entity_Id; | 3176 procedure Check_Part_Of_Abstract_State; |
3171 Item_Decl : Node_Id; | 3177 pragma Inline (Check_Part_Of_Abstract_State); |
3172 Pack_Id : Entity_Id; | 3178 -- Verify the legality of indicator Part_Of when the encapsulator is an |
3173 Placement : State_Space_Kind; | 3179 -- abstract state. |
3174 Parent_Unit : Entity_Id; | 3180 |
3181 procedure Check_Part_Of_Concurrent_Type; | |
3182 pragma Inline (Check_Part_Of_Concurrent_Type); | |
3183 -- Verify the legality of indicator Part_Of when the encapsulator is a | |
3184 -- single concurrent type. | |
3185 | |
3186 ---------------------------------- | |
3187 -- Check_Part_Of_Abstract_State -- | |
3188 ---------------------------------- | |
3189 | |
3190 procedure Check_Part_Of_Abstract_State is | |
3191 Pack_Id : Entity_Id; | |
3192 Placement : State_Space_Kind; | |
3193 Parent_Unit : Entity_Id; | |
3194 | |
3195 begin | |
3196 -- Determine where the object, package instantiation or state lives | |
3197 -- with respect to the enclosing packages or package bodies. | |
3198 | |
3199 Find_Placement_In_State_Space | |
3200 (Item_Id => Item_Id, | |
3201 Placement => Placement, | |
3202 Pack_Id => Pack_Id); | |
3203 | |
3204 -- The item appears in a non-package construct with a declarative | |
3205 -- part (subprogram, block, etc). As such, the item is not allowed | |
3206 -- to be a part of an encapsulating state because the item is not | |
3207 -- visible. | |
3208 | |
3209 if Placement = Not_In_Package then | |
3210 SPARK_Msg_N | |
3211 ("indicator Part_Of cannot appear in this context " | |
3212 & "(SPARK RM 7.2.6(5))", Indic); | |
3213 | |
3214 Error_Msg_Name_1 := Chars (Scope (Encap_Id)); | |
3215 SPARK_Msg_NE | |
3216 ("\& is not part of the hidden state of package %", | |
3217 Indic, Item_Id); | |
3218 return; | |
3219 | |
3220 -- The item appears in the visible state space of some package. In | |
3221 -- general this scenario does not warrant Part_Of except when the | |
3222 -- package is a nongeneric private child unit and the encapsulating | |
3223 -- state is declared in a parent unit or a public descendant of that | |
3224 -- parent unit. | |
3225 | |
3226 elsif Placement = Visible_State_Space then | |
3227 if Is_Child_Unit (Pack_Id) | |
3228 and then not Is_Generic_Unit (Pack_Id) | |
3229 and then Is_Private_Descendant (Pack_Id) | |
3230 then | |
3231 -- A variable or state abstraction which is part of the visible | |
3232 -- state of a nongeneric private child unit or its public | |
3233 -- descendants must have its Part_Of indicator specified. The | |
3234 -- Part_Of indicator must denote a state declared by either the | |
3235 -- parent unit of the private unit or by a public descendant of | |
3236 -- that parent unit. | |
3237 | |
3238 -- Find the nearest private ancestor (which can be the current | |
3239 -- unit itself). | |
3240 | |
3241 Parent_Unit := Pack_Id; | |
3242 while Present (Parent_Unit) loop | |
3243 exit when | |
3244 Private_Present | |
3245 (Parent (Unit_Declaration_Node (Parent_Unit))); | |
3246 Parent_Unit := Scope (Parent_Unit); | |
3247 end loop; | |
3248 | |
3249 Parent_Unit := Scope (Parent_Unit); | |
3250 | |
3251 if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then | |
3252 SPARK_Msg_NE | |
3253 ("indicator Part_Of must denote abstract state of & or of " | |
3254 & "its public descendant (SPARK RM 7.2.6(3))", | |
3255 Indic, Parent_Unit); | |
3256 return; | |
3257 | |
3258 elsif Scope (Encap_Id) = Parent_Unit | |
3259 or else | |
3260 (Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id)) | |
3261 and then not Is_Private_Descendant (Scope (Encap_Id))) | |
3262 then | |
3263 null; | |
3264 | |
3265 else | |
3266 SPARK_Msg_NE | |
3267 ("indicator Part_Of must denote abstract state of & or of " | |
3268 & "its public descendant (SPARK RM 7.2.6(3))", | |
3269 Indic, Parent_Unit); | |
3270 return; | |
3271 end if; | |
3272 | |
3273 -- Indicator Part_Of is not needed when the related package is | |
3274 -- not a nongeneric private child unit or a public descendant | |
3275 -- thereof. | |
3276 | |
3277 else | |
3278 SPARK_Msg_N | |
3279 ("indicator Part_Of cannot appear in this context " | |
3280 & "(SPARK RM 7.2.6(5))", Indic); | |
3281 | |
3282 Error_Msg_Name_1 := Chars (Pack_Id); | |
3283 SPARK_Msg_NE | |
3284 ("\& is declared in the visible part of package %", | |
3285 Indic, Item_Id); | |
3286 return; | |
3287 end if; | |
3288 | |
3289 -- When the item appears in the private state space of a package, the | |
3290 -- encapsulating state must be declared in the same package. | |
3291 | |
3292 elsif Placement = Private_State_Space then | |
3293 if Scope (Encap_Id) /= Pack_Id then | |
3294 SPARK_Msg_NE | |
3295 ("indicator Part_Of must denote an abstract state of " | |
3296 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id); | |
3297 | |
3298 Error_Msg_Name_1 := Chars (Pack_Id); | |
3299 SPARK_Msg_NE | |
3300 ("\& is declared in the private part of package %", | |
3301 Indic, Item_Id); | |
3302 return; | |
3303 end if; | |
3304 | |
3305 -- Items declared in the body state space of a package do not need | |
3306 -- Part_Of indicators as the refinement has already been seen. | |
3307 | |
3308 else | |
3309 SPARK_Msg_N | |
3310 ("indicator Part_Of cannot appear in this context " | |
3311 & "(SPARK RM 7.2.6(5))", Indic); | |
3312 | |
3313 if Scope (Encap_Id) = Pack_Id then | |
3314 Error_Msg_Name_1 := Chars (Pack_Id); | |
3315 SPARK_Msg_NE | |
3316 ("\& is declared in the body of package %", Indic, Item_Id); | |
3317 end if; | |
3318 | |
3319 return; | |
3320 end if; | |
3321 | |
3322 -- At this point it is known that the Part_Of indicator is legal | |
3323 | |
3324 Legal := True; | |
3325 end Check_Part_Of_Abstract_State; | |
3326 | |
3327 ----------------------------------- | |
3328 -- Check_Part_Of_Concurrent_Type -- | |
3329 ----------------------------------- | |
3330 | |
3331 procedure Check_Part_Of_Concurrent_Type is | |
3332 function In_Proper_Order | |
3333 (First : Node_Id; | |
3334 Second : Node_Id) return Boolean; | |
3335 pragma Inline (In_Proper_Order); | |
3336 -- Determine whether node First precedes node Second | |
3337 | |
3338 procedure Placement_Error; | |
3339 pragma Inline (Placement_Error); | |
3340 -- Emit an error concerning the illegal placement of the item with | |
3341 -- respect to the single concurrent type. | |
3342 | |
3343 --------------------- | |
3344 -- In_Proper_Order -- | |
3345 --------------------- | |
3346 | |
3347 function In_Proper_Order | |
3348 (First : Node_Id; | |
3349 Second : Node_Id) return Boolean | |
3350 is | |
3351 N : Node_Id; | |
3352 | |
3353 begin | |
3354 if List_Containing (First) = List_Containing (Second) then | |
3355 N := First; | |
3356 while Present (N) loop | |
3357 if N = Second then | |
3358 return True; | |
3359 end if; | |
3360 | |
3361 Next (N); | |
3362 end loop; | |
3363 end if; | |
3364 | |
3365 return False; | |
3366 end In_Proper_Order; | |
3367 | |
3368 --------------------- | |
3369 -- Placement_Error -- | |
3370 --------------------- | |
3371 | |
3372 procedure Placement_Error is | |
3373 begin | |
3374 SPARK_Msg_N | |
3375 ("indicator Part_Of must denote a previously declared single " | |
3376 & "protected type or single task type", Encap); | |
3377 end Placement_Error; | |
3378 | |
3379 -- Local variables | |
3380 | |
3381 Conc_Typ : constant Entity_Id := Etype (Encap_Id); | |
3382 Encap_Decl : constant Node_Id := Declaration_Node (Encap_Id); | |
3383 Encap_Context : constant Node_Id := Parent (Encap_Decl); | |
3384 | |
3385 Item_Context : Node_Id; | |
3386 Item_Decl : Node_Id; | |
3387 Prv_Decls : List_Id; | |
3388 Vis_Decls : List_Id; | |
3389 | |
3390 -- Start of processing for Check_Part_Of_Concurrent_Type | |
3391 | |
3392 begin | |
3393 -- Only abstract states and variables can act as constituents of an | |
3394 -- encapsulating single concurrent type. | |
3395 | |
3396 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then | |
3397 null; | |
3398 | |
3399 -- The constituent is a constant | |
3400 | |
3401 elsif Ekind (Item_Id) = E_Constant then | |
3402 Error_Msg_Name_1 := Chars (Encap_Id); | |
3403 SPARK_Msg_NE | |
3404 (Fix_Msg (Conc_Typ, "constant & cannot act as constituent of " | |
3405 & "single protected type %"), Indic, Item_Id); | |
3406 return; | |
3407 | |
3408 -- The constituent is a package instantiation | |
3409 | |
3410 else | |
3411 Error_Msg_Name_1 := Chars (Encap_Id); | |
3412 SPARK_Msg_NE | |
3413 (Fix_Msg (Conc_Typ, "package instantiation & cannot act as " | |
3414 & "constituent of single protected type %"), Indic, Item_Id); | |
3415 return; | |
3416 end if; | |
3417 | |
3418 -- When the item denotes an abstract state of a nested package, use | |
3419 -- the declaration of the package to detect proper placement. | |
3420 | |
3421 -- package Pack is | |
3422 -- task T; | |
3423 -- package Nested | |
3424 -- with Abstract_State => (State with Part_Of => T) | |
3425 | |
3426 if Ekind (Item_Id) = E_Abstract_State then | |
3427 Item_Decl := Unit_Declaration_Node (Scope (Item_Id)); | |
3428 else | |
3429 Item_Decl := Declaration_Node (Item_Id); | |
3430 end if; | |
3431 | |
3432 Item_Context := Parent (Item_Decl); | |
3433 | |
3434 -- The item and the single concurrent type must appear in the same | |
3435 -- declarative region, with the item following the declaration of | |
3436 -- the single concurrent type (SPARK RM 9(3)). | |
3437 | |
3438 if Item_Context = Encap_Context then | |
3439 if Nkind_In (Item_Context, N_Package_Specification, | |
3440 N_Protected_Definition, | |
3441 N_Task_Definition) | |
3442 then | |
3443 Prv_Decls := Private_Declarations (Item_Context); | |
3444 Vis_Decls := Visible_Declarations (Item_Context); | |
3445 | |
3446 -- The placement is OK when the single concurrent type appears | |
3447 -- within the visible declarations and the item in the private | |
3448 -- declarations. | |
3449 -- | |
3450 -- package Pack is | |
3451 -- protected PO ... | |
3452 -- private | |
3453 -- Constit : ... with Part_Of => PO; | |
3454 -- end Pack; | |
3455 | |
3456 if List_Containing (Encap_Decl) = Vis_Decls | |
3457 and then List_Containing (Item_Decl) = Prv_Decls | |
3458 then | |
3459 null; | |
3460 | |
3461 -- The placement is illegal when the item appears within the | |
3462 -- visible declarations and the single concurrent type is in | |
3463 -- the private declarations. | |
3464 -- | |
3465 -- package Pack is | |
3466 -- Constit : ... with Part_Of => PO; | |
3467 -- private | |
3468 -- protected PO ... | |
3469 -- end Pack; | |
3470 | |
3471 elsif List_Containing (Item_Decl) = Vis_Decls | |
3472 and then List_Containing (Encap_Decl) = Prv_Decls | |
3473 then | |
3474 Placement_Error; | |
3475 return; | |
3476 | |
3477 -- Otherwise both the item and the single concurrent type are | |
3478 -- in the same list. Ensure that the declaration of the single | |
3479 -- concurrent type precedes that of the item. | |
3480 | |
3481 elsif not In_Proper_Order | |
3482 (First => Encap_Decl, | |
3483 Second => Item_Decl) | |
3484 then | |
3485 Placement_Error; | |
3486 return; | |
3487 end if; | |
3488 | |
3489 -- Otherwise both the item and the single concurrent type are | |
3490 -- in the same list. Ensure that the declaration of the single | |
3491 -- concurrent type precedes that of the item. | |
3492 | |
3493 elsif not In_Proper_Order | |
3494 (First => Encap_Decl, | |
3495 Second => Item_Decl) | |
3496 then | |
3497 Placement_Error; | |
3498 return; | |
3499 end if; | |
3500 | |
3501 -- Otherwise the item and the single concurrent type reside within | |
3502 -- unrelated regions. | |
3503 | |
3504 else | |
3505 Error_Msg_Name_1 := Chars (Encap_Id); | |
3506 SPARK_Msg_NE | |
3507 (Fix_Msg (Conc_Typ, "constituent & must be declared " | |
3508 & "immediately within the same region as single protected " | |
3509 & "type %"), Indic, Item_Id); | |
3510 return; | |
3511 end if; | |
3512 | |
3513 -- At this point it is known that the Part_Of indicator is legal | |
3514 | |
3515 Legal := True; | |
3516 end Check_Part_Of_Concurrent_Type; | |
3517 | |
3518 -- Start of processing for Analyze_Part_Of | |
3175 | 3519 |
3176 begin | 3520 begin |
3177 -- Assume that the indicator is illegal | 3521 -- Assume that the indicator is illegal |
3178 | 3522 |
3179 Encap_Id := Empty; | 3523 Encap_Id := Empty; |
3229 end if; | 3573 end if; |
3230 | 3574 |
3231 -- The encapsulator is an abstract state | 3575 -- The encapsulator is an abstract state |
3232 | 3576 |
3233 if Ekind (Encap_Id) = E_Abstract_State then | 3577 if Ekind (Encap_Id) = E_Abstract_State then |
3234 | 3578 Check_Part_Of_Abstract_State; |
3235 -- Determine where the object, package instantiation or state lives | |
3236 -- with respect to the enclosing packages or package bodies. | |
3237 | |
3238 Find_Placement_In_State_Space | |
3239 (Item_Id => Item_Id, | |
3240 Placement => Placement, | |
3241 Pack_Id => Pack_Id); | |
3242 | |
3243 -- The item appears in a non-package construct with a declarative | |
3244 -- part (subprogram, block, etc). As such, the item is not allowed | |
3245 -- to be a part of an encapsulating state because the item is not | |
3246 -- visible. | |
3247 | |
3248 if Placement = Not_In_Package then | |
3249 SPARK_Msg_N | |
3250 ("indicator Part_Of cannot appear in this context " | |
3251 & "(SPARK RM 7.2.6(5))", Indic); | |
3252 Error_Msg_Name_1 := Chars (Scope (Encap_Id)); | |
3253 SPARK_Msg_NE | |
3254 ("\& is not part of the hidden state of package %", | |
3255 Indic, Item_Id); | |
3256 return; | |
3257 | |
3258 -- The item appears in the visible state space of some package. In | |
3259 -- general this scenario does not warrant Part_Of except when the | |
3260 -- package is a private child unit and the encapsulating state is | |
3261 -- declared in a parent unit or a public descendant of that parent | |
3262 -- unit. | |
3263 | |
3264 elsif Placement = Visible_State_Space then | |
3265 if Is_Child_Unit (Pack_Id) | |
3266 and then Is_Private_Descendant (Pack_Id) | |
3267 then | |
3268 -- A variable or state abstraction which is part of the visible | |
3269 -- state of a private child unit (or one of its public | |
3270 -- descendants) must have its Part_Of indicator specified. The | |
3271 -- Part_Of indicator must denote a state abstraction declared | |
3272 -- by either the parent unit of the private unit or by a public | |
3273 -- descendant of that parent unit. | |
3274 | |
3275 -- Find nearest private ancestor (which can be the current unit | |
3276 -- itself). | |
3277 | |
3278 Parent_Unit := Pack_Id; | |
3279 while Present (Parent_Unit) loop | |
3280 exit when | |
3281 Private_Present | |
3282 (Parent (Unit_Declaration_Node (Parent_Unit))); | |
3283 Parent_Unit := Scope (Parent_Unit); | |
3284 end loop; | |
3285 | |
3286 Parent_Unit := Scope (Parent_Unit); | |
3287 | |
3288 if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then | |
3289 SPARK_Msg_NE | |
3290 ("indicator Part_Of must denote abstract state or public " | |
3291 & "descendant of & (SPARK RM 7.2.6(3))", | |
3292 Indic, Parent_Unit); | |
3293 return; | |
3294 | |
3295 elsif Scope (Encap_Id) = Parent_Unit | |
3296 or else | |
3297 (Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id)) | |
3298 and then not Is_Private_Descendant (Scope (Encap_Id))) | |
3299 then | |
3300 null; | |
3301 | |
3302 else | |
3303 SPARK_Msg_NE | |
3304 ("indicator Part_Of must denote abstract state or public " | |
3305 & "descendant of & (SPARK RM 7.2.6(3))", | |
3306 Indic, Parent_Unit); | |
3307 return; | |
3308 end if; | |
3309 | |
3310 -- Indicator Part_Of is not needed when the related package is not | |
3311 -- a private child unit or a public descendant thereof. | |
3312 | |
3313 else | |
3314 SPARK_Msg_N | |
3315 ("indicator Part_Of cannot appear in this context " | |
3316 & "(SPARK RM 7.2.6(5))", Indic); | |
3317 Error_Msg_Name_1 := Chars (Pack_Id); | |
3318 SPARK_Msg_NE | |
3319 ("\& is declared in the visible part of package %", | |
3320 Indic, Item_Id); | |
3321 return; | |
3322 end if; | |
3323 | |
3324 -- When the item appears in the private state space of a package, the | |
3325 -- encapsulating state must be declared in the same package. | |
3326 | |
3327 elsif Placement = Private_State_Space then | |
3328 if Scope (Encap_Id) /= Pack_Id then | |
3329 SPARK_Msg_NE | |
3330 ("indicator Part_Of must designate an abstract state of " | |
3331 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id); | |
3332 Error_Msg_Name_1 := Chars (Pack_Id); | |
3333 SPARK_Msg_NE | |
3334 ("\& is declared in the private part of package %", | |
3335 Indic, Item_Id); | |
3336 return; | |
3337 end if; | |
3338 | |
3339 -- Items declared in the body state space of a package do not need | |
3340 -- Part_Of indicators as the refinement has already been seen. | |
3341 | |
3342 else | |
3343 SPARK_Msg_N | |
3344 ("indicator Part_Of cannot appear in this context " | |
3345 & "(SPARK RM 7.2.6(5))", Indic); | |
3346 | |
3347 if Scope (Encap_Id) = Pack_Id then | |
3348 Error_Msg_Name_1 := Chars (Pack_Id); | |
3349 SPARK_Msg_NE | |
3350 ("\& is declared in the body of package %", Indic, Item_Id); | |
3351 end if; | |
3352 | |
3353 return; | |
3354 end if; | |
3355 | 3579 |
3356 -- The encapsulator is a single concurrent type | 3580 -- The encapsulator is a single concurrent type |
3357 | 3581 |
3358 else | 3582 else |
3359 Encap_Typ := Etype (Encap_Id); | 3583 Check_Part_Of_Concurrent_Type; |
3360 | |
3361 -- Only abstract states and variables can act as constituents of an | |
3362 -- encapsulating single concurrent type. | |
3363 | |
3364 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then | |
3365 null; | |
3366 | |
3367 -- The constituent is a constant | |
3368 | |
3369 elsif Ekind (Item_Id) = E_Constant then | |
3370 Error_Msg_Name_1 := Chars (Encap_Id); | |
3371 SPARK_Msg_NE | |
3372 (Fix_Msg (Encap_Typ, "constant & cannot act as constituent of " | |
3373 & "single protected type %"), Indic, Item_Id); | |
3374 return; | |
3375 | |
3376 -- The constituent is a package instantiation | |
3377 | |
3378 else | |
3379 Error_Msg_Name_1 := Chars (Encap_Id); | |
3380 SPARK_Msg_NE | |
3381 (Fix_Msg (Encap_Typ, "package instantiation & cannot act as " | |
3382 & "constituent of single protected type %"), Indic, Item_Id); | |
3383 return; | |
3384 end if; | |
3385 | |
3386 -- When the item denotes an abstract state of a nested package, use | |
3387 -- the declaration of the package to detect proper placement. | |
3388 | |
3389 -- package Pack is | |
3390 -- task T; | |
3391 -- package Nested | |
3392 -- with Abstract_State => (State with Part_Of => T) | |
3393 | |
3394 if Ekind (Item_Id) = E_Abstract_State then | |
3395 Item_Decl := Unit_Declaration_Node (Scope (Item_Id)); | |
3396 else | |
3397 Item_Decl := Declaration_Node (Item_Id); | |
3398 end if; | |
3399 | |
3400 -- Both the item and its encapsulating single concurrent type must | |
3401 -- appear in the same declarative region (SPARK RM 9.3). Note that | |
3402 -- privacy is ignored. | |
3403 | |
3404 if Parent (Item_Decl) /= Parent (Declaration_Node (Encap_Id)) then | |
3405 Error_Msg_Name_1 := Chars (Encap_Id); | |
3406 SPARK_Msg_NE | |
3407 (Fix_Msg (Encap_Typ, "constituent & must be declared " | |
3408 & "immediately within the same region as single protected " | |
3409 & "type %"), Indic, Item_Id); | |
3410 return; | |
3411 end if; | |
3412 | |
3413 -- The declaration of the item should follow the declaration of its | |
3414 -- encapsulating single concurrent type and must appear in the same | |
3415 -- declarative region (SPARK RM 9.3). | |
3416 | |
3417 declare | |
3418 N : Node_Id; | |
3419 | |
3420 begin | |
3421 N := Next (Declaration_Node (Encap_Id)); | |
3422 while Present (N) loop | |
3423 exit when N = Item_Decl; | |
3424 Next (N); | |
3425 end loop; | |
3426 | |
3427 -- The single concurrent type might be in the visible part of a | |
3428 -- package, and the declaration of the item in the private part | |
3429 -- of the same package. | |
3430 | |
3431 if No (N) then | |
3432 declare | |
3433 Pack : constant Node_Id := | |
3434 Parent (Declaration_Node (Encap_Id)); | |
3435 begin | |
3436 if Nkind (Pack) = N_Package_Specification | |
3437 and then not In_Private_Part (Encap_Id) | |
3438 then | |
3439 N := First (Private_Declarations (Pack)); | |
3440 while Present (N) loop | |
3441 exit when N = Item_Decl; | |
3442 Next (N); | |
3443 end loop; | |
3444 end if; | |
3445 end; | |
3446 end if; | |
3447 | |
3448 if No (N) then | |
3449 SPARK_Msg_N | |
3450 ("indicator Part_Of must denote a previously declared " | |
3451 & "single protected type or single task type", Encap); | |
3452 return; | |
3453 end if; | |
3454 end; | |
3455 end if; | 3584 end if; |
3456 | |
3457 Legal := True; | |
3458 end Analyze_Part_Of; | 3585 end Analyze_Part_Of; |
3459 | 3586 |
3460 ---------------------------------- | 3587 ---------------------------------- |
3461 -- Analyze_Part_Of_In_Decl_Part -- | 3588 -- Analyze_Part_Of_In_Decl_Part -- |
3462 ---------------------------------- | 3589 ---------------------------------- |
3508 Set_Has_Partial_Visible_Refinement (Encap_Id); | 3635 Set_Has_Partial_Visible_Refinement (Encap_Id); |
3509 end if; | 3636 end if; |
3510 end if; | 3637 end if; |
3511 | 3638 |
3512 -- Emit a clarification message when the encapsulator is undefined, | 3639 -- Emit a clarification message when the encapsulator is undefined, |
3513 -- possibly due to contract "freezing". | 3640 -- possibly due to contract freezing. |
3514 | 3641 |
3515 if Errors /= Serious_Errors_Detected | 3642 if Errors /= Serious_Errors_Detected |
3516 and then Present (Freeze_Id) | 3643 and then Present (Freeze_Id) |
3517 and then Has_Undefined_Reference (Encap) | 3644 and then Has_Undefined_Reference (Encap) |
3518 then | 3645 then |
3555 -- Types used for arguments to Check_Arg_Order and Gather_Associations | 3682 -- Types used for arguments to Check_Arg_Order and Gather_Associations |
3556 | 3683 |
3557 ----------------------- | 3684 ----------------------- |
3558 -- Local Subprograms -- | 3685 -- Local Subprograms -- |
3559 ----------------------- | 3686 ----------------------- |
3687 | |
3688 function Acc_First (N : Node_Id) return Node_Id; | |
3689 -- Helper function to iterate over arguments given to OpenAcc pragmas | |
3690 | |
3691 function Acc_Next (N : Node_Id) return Node_Id; | |
3692 -- Helper function to iterate over arguments given to OpenAcc pragmas | |
3560 | 3693 |
3561 procedure Acquire_Warning_Match_String (Arg : Node_Id); | 3694 procedure Acquire_Warning_Match_String (Arg : Node_Id); |
3562 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to | 3695 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to |
3563 -- get the given string argument, and place it in Name_Buffer, adding | 3696 -- get the given string argument, and place it in Name_Buffer, adding |
3564 -- leading and trailing asterisks if they are not already present. The | 3697 -- leading and trailing asterisks if they are not already present. The |
4105 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar, | 4238 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar, |
4106 -- GNAT_Ravenscar_EDF, or Ravenscar. N is the corresponding pragma node, | 4239 -- GNAT_Ravenscar_EDF, or Ravenscar. N is the corresponding pragma node, |
4107 -- which is used for error messages on any constructs violating the | 4240 -- which is used for error messages on any constructs violating the |
4108 -- profile. | 4241 -- profile. |
4109 | 4242 |
4243 procedure Validate_Acc_Condition_Clause (Clause : Node_Id); | |
4244 -- Make sure the argument of a given Acc_If clause is a Boolean | |
4245 | |
4246 procedure Validate_Acc_Data_Clause (Clause : Node_Id); | |
4247 -- Make sure the argument of an OpenAcc data clause (e.g. Copy, Copyin, | |
4248 -- Copyout...) is an identifier or an aggregate of identifiers. | |
4249 | |
4250 procedure Validate_Acc_Int_Expr_Clause (Clause : Node_Id); | |
4251 -- Make sure the argument of an OpenAcc clause is an Integer expression | |
4252 | |
4253 procedure Validate_Acc_Int_Expr_List_Clause (Clause : Node_Id); | |
4254 -- Make sure the argument of an OpenAcc clause is an Integer expression | |
4255 -- or a list of Integer expressions. | |
4256 | |
4257 procedure Validate_Acc_Loop_Collapse (Clause : Node_Id); | |
4258 -- Make sure that the parent loop of the Acc_Loop(Collapse => N) pragma | |
4259 -- contains at least N-1 nested loops. | |
4260 | |
4261 procedure Validate_Acc_Loop_Gang (Clause : Node_Id); | |
4262 -- Make sure the argument of the Gang clause of a Loop directive is | |
4263 -- either an integer expression or a (Static => integer expressions) | |
4264 -- aggregate. | |
4265 | |
4266 procedure Validate_Acc_Loop_Vector (Clause : Node_Id); | |
4267 -- When this procedure is called in a construct offloaded by an | |
4268 -- Acc_Kernels pragma, makes sure that a Vector_Length clause does | |
4269 -- not exist on said pragma. In all cases, make sure the argument | |
4270 -- is an Integer expression. | |
4271 | |
4272 procedure Validate_Acc_Loop_Worker (Clause : Node_Id); | |
4273 -- When this procedure is called in a construct offloaded by an | |
4274 -- Acc_Parallel pragma, makes sure that no argument has been given. | |
4275 -- When this procedure is called in a construct offloaded by an | |
4276 -- Acc_Kernels pragma and if Loop_Worker was given an argument, | |
4277 -- makes sure that the Num_Workers clause does not appear on the | |
4278 -- Acc_Kernels pragma and that the argument is an integer. | |
4279 | |
4280 procedure Validate_Acc_Name_Reduction (Clause : Node_Id); | |
4281 -- Make sure the reduction clause is an aggregate made of a string | |
4282 -- representing a supported reduction operation (i.e. "+", "*", "and", | |
4283 -- "or", "min" or "max") and either an identifier or aggregate of | |
4284 -- identifiers. | |
4285 | |
4286 procedure Validate_Acc_Size_Expressions (Clause : Node_Id); | |
4287 -- Makes sure that Clause is either an integer expression or an | |
4288 -- association with a Static as name and a list of integer expressions | |
4289 -- or "*" strings on the right hand side. | |
4290 | |
4291 --------------- | |
4292 -- Acc_First -- | |
4293 --------------- | |
4294 | |
4295 function Acc_First (N : Node_Id) return Node_Id is | |
4296 begin | |
4297 if Nkind (N) = N_Aggregate then | |
4298 if Present (Expressions (N)) then | |
4299 return First (Expressions (N)); | |
4300 | |
4301 elsif Present (Component_Associations (N)) then | |
4302 return Expression (First (Component_Associations (N))); | |
4303 end if; | |
4304 end if; | |
4305 | |
4306 return N; | |
4307 end Acc_First; | |
4308 | |
4309 -------------- | |
4310 -- Acc_Next -- | |
4311 -------------- | |
4312 | |
4313 function Acc_Next (N : Node_Id) return Node_Id is | |
4314 begin | |
4315 if Nkind (Parent (N)) = N_Component_Association then | |
4316 return Expression (Next (Parent (N))); | |
4317 | |
4318 elsif Nkind (Parent (N)) = N_Aggregate then | |
4319 return Next (N); | |
4320 | |
4321 else | |
4322 return Empty; | |
4323 end if; | |
4324 end Acc_Next; | |
4325 | |
4110 ---------------------------------- | 4326 ---------------------------------- |
4111 -- Acquire_Warning_Match_String -- | 4327 -- Acquire_Warning_Match_String -- |
4112 ---------------------------------- | 4328 ---------------------------------- |
4113 | 4329 |
4114 procedure Acquire_Warning_Match_String (Arg : Node_Id) is | 4330 procedure Acquire_Warning_Match_String (Arg : Node_Id) is |
4338 while Present (Prev) loop | 4554 while Present (Prev) loop |
4339 Cont := Contract (Prev); | 4555 Cont := Contract (Prev); |
4340 if Present (Cont) then | 4556 if Present (Cont) then |
4341 Prag := Pre_Post_Conditions (Cont); | 4557 Prag := Pre_Post_Conditions (Cont); |
4342 while Present (Prag) loop | 4558 while Present (Prag) loop |
4343 if Class_Present (Prag) then | 4559 if Pragma_Name (Prag) = Name_Precondition |
4560 and then Class_Present (Prag) | |
4561 then | |
4344 return True; | 4562 return True; |
4345 end if; | 4563 end if; |
4346 | 4564 |
4347 Prag := Next_Pragma (Prag); | 4565 Prag := Next_Pragma (Prag); |
4348 end loop; | 4566 end loop; |
4615 -- Verify the placement of the pragma and check for duplicates. The | 4833 -- Verify the placement of the pragma and check for duplicates. The |
4616 -- pragma must apply to a subprogram body [stub]. | 4834 -- pragma must apply to a subprogram body [stub]. |
4617 | 4835 |
4618 Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True); | 4836 Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True); |
4619 | 4837 |
4620 -- Entry body | 4838 if not Nkind_In (Body_Decl, N_Entry_Body, |
4621 | 4839 N_Subprogram_Body, |
4622 if Nkind (Body_Decl) = N_Entry_Body then | 4840 N_Subprogram_Body_Stub, |
4623 null; | 4841 N_Task_Body, |
4624 | 4842 N_Task_Body_Stub) |
4625 -- Subprogram body | 4843 then |
4626 | |
4627 elsif Nkind (Body_Decl) = N_Subprogram_Body then | |
4628 null; | |
4629 | |
4630 -- Subprogram body stub | |
4631 | |
4632 elsif Nkind (Body_Decl) = N_Subprogram_Body_Stub then | |
4633 null; | |
4634 | |
4635 -- Task body | |
4636 | |
4637 elsif Nkind (Body_Decl) = N_Task_Body then | |
4638 null; | |
4639 | |
4640 else | |
4641 Pragma_Misplaced; | 4844 Pragma_Misplaced; |
4642 return; | 4845 return; |
4643 end if; | 4846 end if; |
4644 | 4847 |
4645 Body_Id := Defining_Entity (Body_Decl); | 4848 Body_Id := Defining_Entity (Body_Decl); |
4810 | 5013 |
4811 Next (Arg); | 5014 Next (Arg); |
4812 end loop; | 5015 end loop; |
4813 end Analyze_Unmodified_Or_Unused; | 5016 end Analyze_Unmodified_Or_Unused; |
4814 | 5017 |
4815 ----------------------------------- | 5018 ------------------------------------ |
4816 -- Analyze_Unreference_Or_Unused -- | 5019 -- Analyze_Unreferenced_Or_Unused -- |
4817 ----------------------------------- | 5020 ------------------------------------ |
4818 | 5021 |
4819 procedure Analyze_Unreferenced_Or_Unused | 5022 procedure Analyze_Unreferenced_Or_Unused |
4820 (Is_Unused : Boolean := False) | 5023 (Is_Unused : Boolean := False) |
4821 is | 5024 is |
4822 Arg : Node_Id; | 5025 Arg : Node_Id; |
5815 -- Check_Grouping -- | 6018 -- Check_Grouping -- |
5816 -------------------- | 6019 -------------------- |
5817 | 6020 |
5818 procedure Check_Grouping (L : List_Id) is | 6021 procedure Check_Grouping (L : List_Id) is |
5819 HSS : Node_Id; | 6022 HSS : Node_Id; |
5820 Prag : Node_Id; | |
5821 Stmt : Node_Id; | 6023 Stmt : Node_Id; |
6024 Prag : Node_Id := Empty; -- init to avoid warning | |
5822 | 6025 |
5823 begin | 6026 begin |
5824 -- Inspect the list of declarations or statements looking for | 6027 -- Inspect the list of declarations or statements looking for |
5825 -- the first grouping of pragmas: | 6028 -- the first grouping of pragmas: |
5826 | 6029 |
5836 -- grouping. | 6039 -- grouping. |
5837 | 6040 |
5838 Stmt := First (L); | 6041 Stmt := First (L); |
5839 while Present (Stmt) loop | 6042 while Present (Stmt) loop |
5840 | 6043 |
5841 -- Pragmas Loop_Invariant and Loop_Variant may only appear | |
5842 -- inside a loop or a block housed inside a loop. Inspect | |
5843 -- the declarations and statements of the block as they may | |
5844 -- contain the first grouping. | |
5845 | |
5846 if Nkind (Stmt) = N_Block_Statement then | |
5847 HSS := Handled_Statement_Sequence (Stmt); | |
5848 | |
5849 Check_Grouping (Declarations (Stmt)); | |
5850 | |
5851 if Present (HSS) then | |
5852 Check_Grouping (Statements (HSS)); | |
5853 end if; | |
5854 | |
5855 -- First pragma of the first topmost grouping has been found | 6044 -- First pragma of the first topmost grouping has been found |
5856 | 6045 |
5857 elsif Is_Loop_Pragma (Stmt) then | 6046 if Is_Loop_Pragma (Stmt) then |
5858 | 6047 |
5859 -- The group and the current pragma are not in the same | 6048 -- The group and the current pragma are not in the same |
5860 -- declarative or statement list. | 6049 -- declarative or statement list. |
5861 | 6050 |
5862 if List_Containing (Stmt) /= List_Containing (N) then | 6051 if List_Containing (Stmt) /= List_Containing (N) then |
5870 -- . . . | 6059 -- . . . |
5871 -- pragma Loop_Variant ...; -- current pragma | 6060 -- pragma Loop_Variant ...; -- current pragma |
5872 | 6061 |
5873 else | 6062 else |
5874 while Present (Stmt) loop | 6063 while Present (Stmt) loop |
5875 | |
5876 -- The current pragma is either the first pragma | 6064 -- The current pragma is either the first pragma |
5877 -- of the group or is a member of the group. Stop | 6065 -- of the group or is a member of the group. |
5878 -- the search as the placement is legal. | 6066 -- Stop the search as the placement is legal. |
5879 | 6067 |
5880 if Stmt = N then | 6068 if Stmt = N then |
5881 raise Stop_Search; | 6069 raise Stop_Search; |
5882 | 6070 |
5883 -- Skip group members, but keep track of the last | 6071 -- Skip group members, but keep track of the |
5884 -- pragma in the group. | 6072 -- last pragma in the group. |
5885 | 6073 |
5886 elsif Is_Loop_Pragma (Stmt) then | 6074 elsif Is_Loop_Pragma (Stmt) then |
5887 Prag := Stmt; | 6075 Prag := Stmt; |
5888 | 6076 |
5889 -- Skip declarations and statements generated by | 6077 -- Skip declarations and statements generated by |
5890 -- the compiler during expansion. | 6078 -- the compiler during expansion. Note that some |
5891 | 6079 -- source statements (e.g. pragma Assert) may have |
5892 elsif not Comes_From_Source (Stmt) then | 6080 -- been transformed so that they do not appear as |
6081 -- coming from source anymore, so we instead look | |
6082 -- at their Original_Node. | |
6083 | |
6084 elsif not Comes_From_Source (Original_Node (Stmt)) | |
6085 then | |
5893 null; | 6086 null; |
5894 | 6087 |
5895 -- A non-pragma is separating the group from the | 6088 -- A non-pragma is separating the group from the |
5896 -- current pragma, the placement is illegal. | 6089 -- current pragma, the placement is illegal. |
5897 | 6090 |
5904 | 6097 |
5905 -- If the traversal did not reach the current pragma, | 6098 -- If the traversal did not reach the current pragma, |
5906 -- then the list must be malformed. | 6099 -- then the list must be malformed. |
5907 | 6100 |
5908 raise Program_Error; | 6101 raise Program_Error; |
6102 end if; | |
6103 | |
6104 -- Pragmas Loop_Invariant and Loop_Variant may only appear | |
6105 -- inside a loop or a block housed inside a loop. Inspect | |
6106 -- the declarations and statements of the block as they may | |
6107 -- contain the first grouping. This case follows the one for | |
6108 -- loop pragmas, as block statements which originate in a | |
6109 -- loop pragma (and so Is_Loop_Pragma will return True on | |
6110 -- that block statement) should be treated in the previous | |
6111 -- case. | |
6112 | |
6113 elsif Nkind (Stmt) = N_Block_Statement then | |
6114 HSS := Handled_Statement_Sequence (Stmt); | |
6115 | |
6116 Check_Grouping (Declarations (Stmt)); | |
6117 | |
6118 if Present (HSS) then | |
6119 Check_Grouping (Statements (HSS)); | |
5909 end if; | 6120 end if; |
5910 end if; | 6121 end if; |
5911 | 6122 |
5912 Next (Stmt); | 6123 Next (Stmt); |
5913 end loop; | 6124 end loop; |
7300 -- untagged derived types that are rewritten as subtypes of their | 7511 -- untagged derived types that are rewritten as subtypes of their |
7301 -- respective root types. | 7512 -- respective root types. |
7302 | 7513 |
7303 if SPARK_Mode = On | 7514 if SPARK_Mode = On |
7304 and then Prag_Id = Pragma_Volatile | 7515 and then Prag_Id = Pragma_Volatile |
7305 and then | 7516 and then not Nkind_In (Original_Node (Decl), |
7306 not Nkind_In (Original_Node (Decl), N_Full_Type_Declaration, | 7517 N_Full_Type_Declaration, |
7307 N_Object_Declaration) | 7518 N_Object_Declaration, |
7519 N_Single_Protected_Declaration, | |
7520 N_Single_Task_Declaration) | |
7308 then | 7521 then |
7309 Error_Pragma_Arg | 7522 Error_Pragma_Arg |
7310 ("argument of pragma % must denote a full type or object " | 7523 ("argument of pragma % must denote a full type or object " |
7311 & "declaration", Arg1); | 7524 & "declaration", Arg1); |
7312 end if; | 7525 end if; |
7355 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1); | 7568 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1); |
7356 | 7569 |
7357 -- Start of processing for Process_Compile_Time_Warning_Or_Error | 7570 -- Start of processing for Process_Compile_Time_Warning_Or_Error |
7358 | 7571 |
7359 begin | 7572 begin |
7573 -- In GNATprove mode, pragmas Compile_Time_Error and | |
7574 -- Compile_Time_Warning are ignored, as the analyzer may not have the | |
7575 -- same information as the compiler (in particular regarding size of | |
7576 -- objects decided in gigi) so it makes no sense to issue an error or | |
7577 -- warning in GNATprove. | |
7578 | |
7579 if GNATprove_Mode then | |
7580 Rewrite (N, Make_Null_Statement (Loc)); | |
7581 return; | |
7582 end if; | |
7583 | |
7360 Check_Arg_Count (2); | 7584 Check_Arg_Count (2); |
7361 Check_No_Identifiers; | 7585 Check_No_Identifiers; |
7362 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String); | 7586 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String); |
7363 Analyze_And_Resolve (Arg1x, Standard_Boolean); | 7587 Analyze_And_Resolve (Arg1x, Standard_Boolean); |
7364 | 7588 |
10705 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is | 10929 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is |
10706 procedure Bad_Mechanism; | 10930 procedure Bad_Mechanism; |
10707 pragma No_Return (Bad_Mechanism); | 10931 pragma No_Return (Bad_Mechanism); |
10708 -- Signal bad mechanism name | 10932 -- Signal bad mechanism name |
10709 | 10933 |
10710 ------------------------- | 10934 ------------------- |
10711 -- Bad_Mechanism_Value -- | 10935 -- Bad_Mechanism -- |
10712 ------------------------- | 10936 ------------------- |
10713 | 10937 |
10714 procedure Bad_Mechanism is | 10938 procedure Bad_Mechanism is |
10715 begin | 10939 begin |
10716 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name); | 10940 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name); |
10717 end Bad_Mechanism; | 10941 end Bad_Mechanism; |
10955 (Unit => Nod, | 11179 (Unit => Nod, |
10956 Warn => Treat_Restrictions_As_Warnings, | 11180 Warn => Treat_Restrictions_As_Warnings, |
10957 Profile => Ravenscar); | 11181 Profile => Ravenscar); |
10958 end if; | 11182 end if; |
10959 end Set_Ravenscar_Profile; | 11183 end Set_Ravenscar_Profile; |
11184 | |
11185 ----------------------------------- | |
11186 -- Validate_Acc_Condition_Clause -- | |
11187 ----------------------------------- | |
11188 | |
11189 procedure Validate_Acc_Condition_Clause (Clause : Node_Id) is | |
11190 begin | |
11191 Analyze_And_Resolve (Clause); | |
11192 | |
11193 if not Is_Boolean_Type (Etype (Clause)) then | |
11194 Error_Pragma ("expected a boolean"); | |
11195 end if; | |
11196 end Validate_Acc_Condition_Clause; | |
11197 | |
11198 ------------------------------ | |
11199 -- Validate_Acc_Data_Clause -- | |
11200 ------------------------------ | |
11201 | |
11202 procedure Validate_Acc_Data_Clause (Clause : Node_Id) is | |
11203 Expr : Node_Id; | |
11204 | |
11205 begin | |
11206 Expr := Acc_First (Clause); | |
11207 while Present (Expr) loop | |
11208 if Nkind (Expr) /= N_Identifier then | |
11209 Error_Pragma ("expected an identifer"); | |
11210 end if; | |
11211 | |
11212 Analyze_And_Resolve (Expr); | |
11213 | |
11214 Expr := Acc_Next (Expr); | |
11215 end loop; | |
11216 end Validate_Acc_Data_Clause; | |
11217 | |
11218 ---------------------------------- | |
11219 -- Validate_Acc_Int_Expr_Clause -- | |
11220 ---------------------------------- | |
11221 | |
11222 procedure Validate_Acc_Int_Expr_Clause (Clause : Node_Id) is | |
11223 begin | |
11224 Analyze_And_Resolve (Clause); | |
11225 | |
11226 if not Is_Integer_Type (Etype (Clause)) then | |
11227 Error_Pragma_Arg ("expected an integer", Clause); | |
11228 end if; | |
11229 end Validate_Acc_Int_Expr_Clause; | |
11230 | |
11231 --------------------------------------- | |
11232 -- Validate_Acc_Int_Expr_List_Clause -- | |
11233 --------------------------------------- | |
11234 | |
11235 procedure Validate_Acc_Int_Expr_List_Clause (Clause : Node_Id) is | |
11236 Expr : Node_Id; | |
11237 | |
11238 begin | |
11239 Expr := Acc_First (Clause); | |
11240 while Present (Expr) loop | |
11241 Analyze_And_Resolve (Expr); | |
11242 | |
11243 if not Is_Integer_Type (Etype (Expr)) then | |
11244 Error_Pragma ("expected an integer"); | |
11245 end if; | |
11246 | |
11247 Expr := Acc_Next (Expr); | |
11248 end loop; | |
11249 end Validate_Acc_Int_Expr_List_Clause; | |
11250 | |
11251 -------------------------------- | |
11252 -- Validate_Acc_Loop_Collapse -- | |
11253 -------------------------------- | |
11254 | |
11255 procedure Validate_Acc_Loop_Collapse (Clause : Node_Id) is | |
11256 Count : Uint; | |
11257 Par_Loop : Node_Id; | |
11258 Stmt : Node_Id; | |
11259 | |
11260 begin | |
11261 -- Make sure the argument is a positive integer | |
11262 | |
11263 Analyze_And_Resolve (Clause); | |
11264 | |
11265 Count := Static_Integer (Clause); | |
11266 if Count = No_Uint or else Count < 1 then | |
11267 Error_Pragma_Arg ("expected a positive integer", Clause); | |
11268 end if; | |
11269 | |
11270 -- Then, make sure we have at least Count-1 tightly-nested loops | |
11271 -- (i.e. loops with no statements in between). | |
11272 | |
11273 Par_Loop := Parent (Parent (Parent (Clause))); | |
11274 Stmt := First (Statements (Par_Loop)); | |
11275 | |
11276 -- Skip first pragmas in the parent loop | |
11277 | |
11278 while Present (Stmt) and then Nkind (Stmt) = N_Pragma loop | |
11279 Next (Stmt); | |
11280 end loop; | |
11281 | |
11282 if not Present (Next (Stmt)) then | |
11283 while Nkind (Stmt) = N_Loop_Statement and Count > 1 loop | |
11284 Stmt := First (Statements (Stmt)); | |
11285 exit when Present (Next (Stmt)); | |
11286 | |
11287 Count := Count - 1; | |
11288 end loop; | |
11289 end if; | |
11290 | |
11291 if Count > 1 then | |
11292 Error_Pragma_Arg | |
11293 ("Collapse argument too high or loops not tightly nested", | |
11294 Clause); | |
11295 end if; | |
11296 end Validate_Acc_Loop_Collapse; | |
11297 | |
11298 ---------------------------- | |
11299 -- Validate_Acc_Loop_Gang -- | |
11300 ---------------------------- | |
11301 | |
11302 procedure Validate_Acc_Loop_Gang (Clause : Node_Id) is | |
11303 begin | |
11304 Error_Pragma_Arg ("Loop_Gang not implemented", Clause); | |
11305 end Validate_Acc_Loop_Gang; | |
11306 | |
11307 ------------------------------ | |
11308 -- Validate_Acc_Loop_Vector -- | |
11309 ------------------------------ | |
11310 | |
11311 procedure Validate_Acc_Loop_Vector (Clause : Node_Id) is | |
11312 begin | |
11313 Error_Pragma_Arg ("Loop_Vector not implemented", Clause); | |
11314 end Validate_Acc_Loop_Vector; | |
11315 | |
11316 ------------------------------- | |
11317 -- Validate_Acc_Loop_Worker -- | |
11318 ------------------------------- | |
11319 | |
11320 procedure Validate_Acc_Loop_Worker (Clause : Node_Id) is | |
11321 begin | |
11322 Error_Pragma_Arg ("Loop_Worker not implemented", Clause); | |
11323 end Validate_Acc_Loop_Worker; | |
11324 | |
11325 --------------------------------- | |
11326 -- Validate_Acc_Name_Reduction -- | |
11327 --------------------------------- | |
11328 | |
11329 procedure Validate_Acc_Name_Reduction (Clause : Node_Id) is | |
11330 | |
11331 -- ??? On top of the following operations, the OpenAcc spec adds the | |
11332 -- "bitwise and", "bitwise or" and modulo for C and ".eqv" and | |
11333 -- ".neqv" for Fortran. Can we, should we and how do we support them | |
11334 -- in Ada? | |
11335 | |
11336 type Reduction_Op is (Add_Op, Mul_Op, Max_Op, Min_Op, And_Op, Or_Op); | |
11337 | |
11338 function To_Reduction_Op (Op : String) return Reduction_Op; | |
11339 -- Convert operator Op described by a String into its corresponding | |
11340 -- enumeration value. | |
11341 | |
11342 --------------------- | |
11343 -- To_Reduction_Op -- | |
11344 --------------------- | |
11345 | |
11346 function To_Reduction_Op (Op : String) return Reduction_Op is | |
11347 begin | |
11348 if Op = "+" then | |
11349 return Add_Op; | |
11350 | |
11351 elsif Op = "*" then | |
11352 return Mul_Op; | |
11353 | |
11354 elsif Op = "max" then | |
11355 return Max_Op; | |
11356 | |
11357 elsif Op = "min" then | |
11358 return Min_Op; | |
11359 | |
11360 elsif Op = "and" then | |
11361 return And_Op; | |
11362 | |
11363 elsif Op = "or" then | |
11364 return Or_Op; | |
11365 | |
11366 else | |
11367 Error_Pragma ("unsuported reduction operation"); | |
11368 end if; | |
11369 end To_Reduction_Op; | |
11370 | |
11371 -- Local variables | |
11372 | |
11373 Seen : constant Elist_Id := New_Elmt_List; | |
11374 | |
11375 Expr : Node_Id; | |
11376 Reduc_Op : Node_Id; | |
11377 Reduc_Var : Node_Id; | |
11378 | |
11379 -- Start of processing for Validate_Acc_Name_Reduction | |
11380 | |
11381 begin | |
11382 -- Reduction operations appear in the following form: | |
11383 -- ("+" => (a, b), "*" => c) | |
11384 | |
11385 Expr := First (Component_Associations (Clause)); | |
11386 while Present (Expr) loop | |
11387 Reduc_Op := First (Choices (Expr)); | |
11388 String_To_Name_Buffer (Strval (Reduc_Op)); | |
11389 | |
11390 case To_Reduction_Op (Name_Buffer (1 .. Name_Len)) is | |
11391 when Add_Op | |
11392 | Mul_Op | |
11393 | Max_Op | |
11394 | Min_Op | |
11395 => | |
11396 Reduc_Var := Acc_First (Expression (Expr)); | |
11397 while Present (Reduc_Var) loop | |
11398 Analyze_And_Resolve (Reduc_Var); | |
11399 | |
11400 if Contains (Seen, Entity (Reduc_Var)) then | |
11401 Error_Pragma ("variable used in multiple reductions"); | |
11402 | |
11403 else | |
11404 if Nkind (Reduc_Var) /= N_Identifier | |
11405 or not Is_Numeric_Type (Etype (Reduc_Var)) | |
11406 then | |
11407 Error_Pragma | |
11408 ("expected an identifier for a Numeric"); | |
11409 end if; | |
11410 | |
11411 Append_Elmt (Entity (Reduc_Var), Seen); | |
11412 end if; | |
11413 | |
11414 Reduc_Var := Acc_Next (Reduc_Var); | |
11415 end loop; | |
11416 | |
11417 when And_Op | |
11418 | Or_Op | |
11419 => | |
11420 Reduc_Var := Acc_First (Expression (Expr)); | |
11421 while Present (Reduc_Var) loop | |
11422 Analyze_And_Resolve (Reduc_Var); | |
11423 | |
11424 if Contains (Seen, Entity (Reduc_Var)) then | |
11425 Error_Pragma ("variable used in multiple reductions"); | |
11426 | |
11427 else | |
11428 if Nkind (Reduc_Var) /= N_Identifier | |
11429 or not Is_Boolean_Type (Etype (Reduc_Var)) | |
11430 then | |
11431 Error_Pragma | |
11432 ("expected a variable of type boolean"); | |
11433 end if; | |
11434 | |
11435 Append_Elmt (Entity (Reduc_Var), Seen); | |
11436 end if; | |
11437 | |
11438 Reduc_Var := Acc_Next (Reduc_Var); | |
11439 end loop; | |
11440 end case; | |
11441 | |
11442 Next (Expr); | |
11443 end loop; | |
11444 end Validate_Acc_Name_Reduction; | |
11445 | |
11446 ----------------------------------- | |
11447 -- Validate_Acc_Size_Expressions -- | |
11448 ----------------------------------- | |
11449 | |
11450 procedure Validate_Acc_Size_Expressions (Clause : Node_Id) is | |
11451 function Validate_Size_Expr (Expr : Node_Id) return Boolean; | |
11452 -- A size expr is either an integer expression or "*" | |
11453 | |
11454 ------------------------ | |
11455 -- Validate_Size_Expr -- | |
11456 ------------------------ | |
11457 | |
11458 function Validate_Size_Expr (Expr : Node_Id) return Boolean is | |
11459 begin | |
11460 if Nkind (Expr) = N_Operator_Symbol then | |
11461 return Get_String_Char (Strval (Expr), 1) = Get_Char_Code ('*'); | |
11462 end if; | |
11463 | |
11464 Analyze_And_Resolve (Expr); | |
11465 | |
11466 return Is_Integer_Type (Etype (Expr)); | |
11467 end Validate_Size_Expr; | |
11468 | |
11469 -- Local variables | |
11470 | |
11471 Expr : Node_Id; | |
11472 | |
11473 -- Start of processing for Validate_Acc_Size_Expressions | |
11474 | |
11475 begin | |
11476 Expr := Acc_First (Clause); | |
11477 while Present (Expr) loop | |
11478 if not Validate_Size_Expr (Expr) then | |
11479 Error_Pragma | |
11480 ("Size expressions should be either integers or '*'"); | |
11481 end if; | |
11482 | |
11483 Expr := Acc_Next (Expr); | |
11484 end loop; | |
11485 end Validate_Acc_Size_Expressions; | |
10960 | 11486 |
10961 -- Start of processing for Analyze_Pragma | 11487 -- Start of processing for Analyze_Pragma |
10962 | 11488 |
10963 begin | 11489 begin |
10964 -- The following code is a defense against recursion. Not clear that | 11490 -- The following code is a defense against recursion. Not clear that |
11003 return; | 11529 return; |
11004 end if; | 11530 end if; |
11005 | 11531 |
11006 -- Here to start processing for recognized pragma | 11532 -- Here to start processing for recognized pragma |
11007 | 11533 |
11008 Pname := Original_Aspect_Pragma_Name (N); | 11534 Pname := Original_Aspect_Pragma_Name (N); |
11009 | 11535 |
11010 -- Capture setting of Opt.Uneval_Old | 11536 -- Capture setting of Opt.Uneval_Old |
11011 | 11537 |
11012 case Opt.Uneval_Old is | 11538 case Opt.Uneval_Old is |
11013 when 'A' => | 11539 when 'A' => |
11034 -- For a pragma that is a rewriting of another pragma, copy the | 11560 -- For a pragma that is a rewriting of another pragma, copy the |
11035 -- Is_Checked/Is_Ignored status from the rewritten pragma. | 11561 -- Is_Checked/Is_Ignored status from the rewritten pragma. |
11036 | 11562 |
11037 elsif Is_Rewrite_Substitution (N) | 11563 elsif Is_Rewrite_Substitution (N) |
11038 and then Nkind (Original_Node (N)) = N_Pragma | 11564 and then Nkind (Original_Node (N)) = N_Pragma |
11039 and then Original_Node (N) /= N | |
11040 then | 11565 then |
11041 Set_Is_Ignored (N, Is_Ignored (Original_Node (N))); | 11566 Set_Is_Ignored (N, Is_Ignored (Original_Node (N))); |
11042 Set_Is_Checked (N, Is_Checked (Original_Node (N))); | 11567 Set_Is_Checked (N, Is_Checked (Original_Node (N))); |
11043 | 11568 |
11044 -- Otherwise query the applicable policy at this point | 11569 -- Otherwise query the applicable policy at this point |
11388 Expr_Val := Is_True (Expr_Value (Expr)); | 11913 Expr_Val := Is_True (Expr_Value (Expr)); |
11389 else | 11914 else |
11390 SPARK_Msg_N | 11915 SPARK_Msg_N |
11391 ("expression of external state property must be " | 11916 ("expression of external state property must be " |
11392 & "static", Expr); | 11917 & "static", Expr); |
11918 return; | |
11393 end if; | 11919 end if; |
11394 | 11920 |
11395 -- The lack of expression defaults the property to True | 11921 -- The lack of expression defaults the property to True |
11396 | 11922 |
11397 else | 11923 else |
11560 Set_Comes_From_Source (State_Id, not Is_Null); | 12086 Set_Comes_From_Source (State_Id, not Is_Null); |
11561 Set_Parent (State_Id, State); | 12087 Set_Parent (State_Id, State); |
11562 Set_Ekind (State_Id, E_Abstract_State); | 12088 Set_Ekind (State_Id, E_Abstract_State); |
11563 Set_Etype (State_Id, Standard_Void_Type); | 12089 Set_Etype (State_Id, Standard_Void_Type); |
11564 Set_Encapsulating_State (State_Id, Empty); | 12090 Set_Encapsulating_State (State_Id, Empty); |
12091 | |
12092 -- Set the SPARK mode from the current context | |
12093 | |
12094 Set_SPARK_Pragma (State_Id, SPARK_Mode_Pragma); | |
12095 Set_SPARK_Pragma_Inherited (State_Id); | |
11565 | 12096 |
11566 -- An abstract state declared within a Ghost region becomes | 12097 -- An abstract state declared within a Ghost region becomes |
11567 -- Ghost (SPARK RM 6.9(2)). | 12098 -- Ghost (SPARK RM 6.9(2)). |
11568 | 12099 |
11569 if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then | 12100 if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then |
11830 Check_No_Identifiers; | 12361 Check_No_Identifiers; |
11831 Check_Arg_Count (1); | 12362 Check_Arg_Count (1); |
11832 | 12363 |
11833 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True); | 12364 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True); |
11834 | 12365 |
11835 -- Ensure the proper placement of the pragma. Abstract states must | 12366 if not Nkind_In (Pack_Decl, N_Generic_Package_Declaration, |
11836 -- be associated with a package declaration. | 12367 N_Package_Declaration) |
11837 | |
11838 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration, | |
11839 N_Package_Declaration) | |
11840 then | 12368 then |
11841 null; | |
11842 | |
11843 -- Otherwise the pragma is associated with an illegal construct | |
11844 | |
11845 else | |
11846 Pragma_Misplaced; | 12369 Pragma_Misplaced; |
11847 return; | 12370 return; |
11848 end if; | 12371 end if; |
11849 | 12372 |
11850 Pack_Id := Defining_Entity (Pack_Decl); | 12373 Pack_Id := Defining_Entity (Pack_Decl); |
11901 end if; | 12424 end if; |
11902 | 12425 |
11903 Analyze_If_Present (Pragma_Initializes); | 12426 Analyze_If_Present (Pragma_Initializes); |
11904 Analyze_If_Present (Pragma_Initial_Condition); | 12427 Analyze_If_Present (Pragma_Initial_Condition); |
11905 end Abstract_State; | 12428 end Abstract_State; |
12429 | |
12430 -------------- | |
12431 -- Acc_Data -- | |
12432 -------------- | |
12433 | |
12434 when Pragma_Acc_Data => Acc_Data : declare | |
12435 Clause_Names : constant Name_List := | |
12436 (Name_Attach, | |
12437 Name_Copy, | |
12438 Name_Copy_In, | |
12439 Name_Copy_Out, | |
12440 Name_Create, | |
12441 Name_Delete, | |
12442 Name_Detach, | |
12443 Name_Device_Ptr, | |
12444 Name_No_Create, | |
12445 Name_Present); | |
12446 | |
12447 Clause : Node_Id; | |
12448 Clauses : Args_List (Clause_Names'Range); | |
12449 | |
12450 begin | |
12451 if not OpenAcc_Enabled then | |
12452 return; | |
12453 end if; | |
12454 | |
12455 GNAT_Pragma; | |
12456 | |
12457 if Nkind (Parent (N)) /= N_Loop_Statement then | |
12458 Error_Pragma | |
12459 ("Acc_Data pragma should be placed in loop or block " | |
12460 & "statements"); | |
12461 end if; | |
12462 | |
12463 Gather_Associations (Clause_Names, Clauses); | |
12464 | |
12465 for Id in Clause_Names'First .. Clause_Names'Last loop | |
12466 Clause := Clauses (Id); | |
12467 | |
12468 if Present (Clause) then | |
12469 case Clause_Names (Id) is | |
12470 when Name_Copy | |
12471 | Name_Copy_In | |
12472 | Name_Copy_Out | |
12473 | Name_Create | |
12474 | Name_Device_Ptr | |
12475 | Name_Present | |
12476 => | |
12477 Validate_Acc_Data_Clause (Clause); | |
12478 | |
12479 when Name_Attach | |
12480 | Name_Detach | |
12481 | Name_Delete | |
12482 | Name_No_Create | |
12483 => | |
12484 Error_Pragma ("unsupported pragma clause"); | |
12485 | |
12486 when others => | |
12487 raise Program_Error; | |
12488 end case; | |
12489 end if; | |
12490 end loop; | |
12491 | |
12492 Set_Is_OpenAcc_Environment (Parent (N)); | |
12493 end Acc_Data; | |
12494 | |
12495 -------------- | |
12496 -- Acc_Loop -- | |
12497 -------------- | |
12498 | |
12499 when Pragma_Acc_Loop => Acc_Loop : declare | |
12500 Clause_Names : constant Name_List := | |
12501 (Name_Auto, | |
12502 Name_Collapse, | |
12503 Name_Gang, | |
12504 Name_Independent, | |
12505 Name_Acc_Private, | |
12506 Name_Reduction, | |
12507 Name_Seq, | |
12508 Name_Tile, | |
12509 Name_Vector, | |
12510 Name_Worker); | |
12511 | |
12512 Clause : Node_Id; | |
12513 Clauses : Args_List (Clause_Names'Range); | |
12514 Par : Node_Id; | |
12515 | |
12516 begin | |
12517 if not OpenAcc_Enabled then | |
12518 return; | |
12519 end if; | |
12520 | |
12521 GNAT_Pragma; | |
12522 | |
12523 -- Make sure the pragma is in an openacc construct | |
12524 | |
12525 Check_Loop_Pragma_Placement; | |
12526 | |
12527 Par := Parent (N); | |
12528 while Present (Par) | |
12529 and then (Nkind (Par) /= N_Loop_Statement | |
12530 or else not Is_OpenAcc_Environment (Par)) | |
12531 loop | |
12532 Par := Parent (Par); | |
12533 end loop; | |
12534 | |
12535 if not Is_OpenAcc_Environment (Par) then | |
12536 Error_Pragma | |
12537 ("Acc_Loop directive must be associated with an OpenAcc " | |
12538 & "construct region"); | |
12539 end if; | |
12540 | |
12541 Gather_Associations (Clause_Names, Clauses); | |
12542 | |
12543 for Id in Clause_Names'First .. Clause_Names'Last loop | |
12544 Clause := Clauses (Id); | |
12545 | |
12546 if Present (Clause) then | |
12547 case Clause_Names (Id) is | |
12548 when Name_Auto | |
12549 | Name_Independent | |
12550 | Name_Seq | |
12551 => | |
12552 null; | |
12553 | |
12554 when Name_Collapse => | |
12555 Validate_Acc_Loop_Collapse (Clause); | |
12556 | |
12557 when Name_Gang => | |
12558 Validate_Acc_Loop_Gang (Clause); | |
12559 | |
12560 when Name_Acc_Private => | |
12561 Validate_Acc_Data_Clause (Clause); | |
12562 | |
12563 when Name_Reduction => | |
12564 Validate_Acc_Name_Reduction (Clause); | |
12565 | |
12566 when Name_Tile => | |
12567 Validate_Acc_Size_Expressions (Clause); | |
12568 | |
12569 when Name_Vector => | |
12570 Validate_Acc_Loop_Vector (Clause); | |
12571 | |
12572 when Name_Worker => | |
12573 Validate_Acc_Loop_Worker (Clause); | |
12574 | |
12575 when others => | |
12576 raise Program_Error; | |
12577 end case; | |
12578 end if; | |
12579 end loop; | |
12580 | |
12581 Set_Is_OpenAcc_Loop (Parent (N)); | |
12582 end Acc_Loop; | |
12583 | |
12584 ---------------------------------- | |
12585 -- Acc_Parallel and Acc_Kernels -- | |
12586 ---------------------------------- | |
12587 | |
12588 when Pragma_Acc_Parallel | |
12589 | Pragma_Acc_Kernels | |
12590 => | |
12591 Acc_Kernels_Or_Parallel : declare | |
12592 Clause_Names : constant Name_List := | |
12593 (Name_Acc_If, | |
12594 Name_Async, | |
12595 Name_Copy, | |
12596 Name_Copy_In, | |
12597 Name_Copy_Out, | |
12598 Name_Create, | |
12599 Name_Default, | |
12600 Name_Device_Ptr, | |
12601 Name_Device_Type, | |
12602 Name_Num_Gangs, | |
12603 Name_Num_Workers, | |
12604 Name_Present, | |
12605 Name_Vector_Length, | |
12606 Name_Wait, | |
12607 | |
12608 -- Parallel only | |
12609 | |
12610 Name_Acc_Private, | |
12611 Name_First_Private, | |
12612 Name_Reduction, | |
12613 | |
12614 -- Kernels only | |
12615 | |
12616 Name_Attach, | |
12617 Name_No_Create); | |
12618 | |
12619 Clause : Node_Id; | |
12620 Clauses : Args_List (Clause_Names'Range); | |
12621 | |
12622 begin | |
12623 if not OpenAcc_Enabled then | |
12624 return; | |
12625 end if; | |
12626 | |
12627 GNAT_Pragma; | |
12628 Check_Loop_Pragma_Placement; | |
12629 | |
12630 if Nkind (Parent (N)) /= N_Loop_Statement then | |
12631 Error_Pragma | |
12632 ("pragma should be placed in loop or block statements"); | |
12633 end if; | |
12634 | |
12635 Gather_Associations (Clause_Names, Clauses); | |
12636 | |
12637 for Id in Clause_Names'First .. Clause_Names'Last loop | |
12638 Clause := Clauses (Id); | |
12639 | |
12640 if Present (Clause) then | |
12641 if Chars (Parent (Clause)) = No_Name then | |
12642 Error_Pragma ("all arguments should be associations"); | |
12643 else | |
12644 case Clause_Names (Id) is | |
12645 | |
12646 -- Note: According to the OpenAcc Standard v2.6, | |
12647 -- Async's argument should be optional. Because this | |
12648 -- complicates parsing the clause, the argument is | |
12649 -- made mandatory. The standard defines two negative | |
12650 -- values, acc_async_noval and acc_async_sync. When | |
12651 -- given acc_async_noval as value, the clause should | |
12652 -- behave as if no argument was given. According to | |
12653 -- the standard, acc_async_noval is defined in header | |
12654 -- files for C and Fortran, thus this value should | |
12655 -- probably be defined in the OpenAcc Ada library once | |
12656 -- it is implemented. | |
12657 | |
12658 when Name_Async | |
12659 | Name_Num_Gangs | |
12660 | Name_Num_Workers | |
12661 | Name_Vector_Length | |
12662 => | |
12663 Validate_Acc_Int_Expr_Clause (Clause); | |
12664 | |
12665 when Name_Acc_If => | |
12666 Validate_Acc_Condition_Clause (Clause); | |
12667 | |
12668 -- Unsupported by GCC | |
12669 | |
12670 when Name_Attach | |
12671 | Name_No_Create | |
12672 => | |
12673 Error_Pragma ("unsupported clause"); | |
12674 | |
12675 when Name_Acc_Private | |
12676 | Name_First_Private | |
12677 => | |
12678 if Prag_Id /= Pragma_Acc_Parallel then | |
12679 Error_Pragma | |
12680 ("argument is only available for 'Parallel' " | |
12681 & "construct"); | |
12682 else | |
12683 Validate_Acc_Data_Clause (Clause); | |
12684 end if; | |
12685 | |
12686 when Name_Copy | |
12687 | Name_Copy_In | |
12688 | Name_Copy_Out | |
12689 | Name_Create | |
12690 | Name_Device_Ptr | |
12691 | Name_Present | |
12692 => | |
12693 Validate_Acc_Data_Clause (Clause); | |
12694 | |
12695 when Name_Reduction => | |
12696 if Prag_Id /= Pragma_Acc_Parallel then | |
12697 Error_Pragma | |
12698 ("argument is only available for 'Parallel' " | |
12699 & "construct"); | |
12700 else | |
12701 Validate_Acc_Name_Reduction (Clause); | |
12702 end if; | |
12703 | |
12704 when Name_Default => | |
12705 if Chars (Clause) /= Name_None then | |
12706 Error_Pragma ("expected none"); | |
12707 end if; | |
12708 | |
12709 when Name_Device_Type => | |
12710 Error_Pragma ("unsupported pragma clause"); | |
12711 | |
12712 -- Similar to Name_Async, Name_Wait's arguments should | |
12713 -- be optional. However, this can be simulated using | |
12714 -- acc_async_noval, hence, we do not bother making the | |
12715 -- argument optional for now. | |
12716 | |
12717 when Name_Wait => | |
12718 Validate_Acc_Int_Expr_List_Clause (Clause); | |
12719 | |
12720 when others => | |
12721 raise Program_Error; | |
12722 end case; | |
12723 end if; | |
12724 end if; | |
12725 end loop; | |
12726 | |
12727 Set_Is_OpenAcc_Environment (Parent (N)); | |
12728 end Acc_Kernels_Or_Parallel; | |
11906 | 12729 |
11907 ------------ | 12730 ------------ |
11908 -- Ada_83 -- | 12731 -- Ada_83 -- |
11909 ------------ | 12732 ------------ |
11910 | 12733 |
12759 | 13582 |
12760 Obj_Decl := Find_Related_Context (N, Do_Checks => True); | 13583 Obj_Decl := Find_Related_Context (N, Do_Checks => True); |
12761 | 13584 |
12762 -- Object declaration | 13585 -- Object declaration |
12763 | 13586 |
12764 if Nkind (Obj_Decl) = N_Object_Declaration then | 13587 if Nkind (Obj_Decl) /= N_Object_Declaration then |
12765 null; | |
12766 | |
12767 -- Otherwise the pragma is associated with an illegal construact | |
12768 | |
12769 else | |
12770 Pragma_Misplaced; | 13588 Pragma_Misplaced; |
12771 return; | 13589 return; |
12772 end if; | 13590 end if; |
12773 | 13591 |
12774 Obj_Id := Defining_Entity (Obj_Decl); | 13592 Obj_Id := Defining_Entity (Obj_Decl); |
13139 -- WARNING: The code below manages Ghost regions. Return statements | 13957 -- WARNING: The code below manages Ghost regions. Return statements |
13140 -- must be replaced by gotos which jump to the end of the code and | 13958 -- must be replaced by gotos which jump to the end of the code and |
13141 -- restore the Ghost mode. | 13959 -- restore the Ghost mode. |
13142 | 13960 |
13143 when Pragma_Check => Check : declare | 13961 when Pragma_Check => Check : declare |
13144 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; | 13962 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
13145 -- Save the Ghost mode to restore on exit | 13963 Saved_IGR : constant Node_Id := Ignored_Ghost_Region; |
13964 -- Save the Ghost-related attributes to restore on exit | |
13146 | 13965 |
13147 Cname : Name_Id; | 13966 Cname : Name_Id; |
13148 Eloc : Source_Ptr; | 13967 Eloc : Source_Ptr; |
13149 Expr : Node_Id; | 13968 Expr : Node_Id; |
13150 Str : Node_Id; | 13969 Str : Node_Id; |
13198 -- For a non-source pragma that is a rewriting of another pragma, | 14017 -- For a non-source pragma that is a rewriting of another pragma, |
13199 -- copy the Is_Checked/Ignored status from the rewritten pragma. | 14018 -- copy the Is_Checked/Ignored status from the rewritten pragma. |
13200 | 14019 |
13201 elsif Is_Rewrite_Substitution (N) | 14020 elsif Is_Rewrite_Substitution (N) |
13202 and then Nkind (Original_Node (N)) = N_Pragma | 14021 and then Nkind (Original_Node (N)) = N_Pragma |
13203 and then Original_Node (N) /= N | |
13204 then | 14022 then |
13205 Set_Is_Ignored (N, Is_Ignored (Original_Node (N))); | 14023 Set_Is_Ignored (N, Is_Ignored (Original_Node (N))); |
13206 Set_Is_Checked (N, Is_Checked (Original_Node (N))); | 14024 Set_Is_Checked (N, Is_Checked (Original_Node (N))); |
13207 | 14025 |
13208 -- Otherwise query the applicable policy at this point | 14026 -- Otherwise query the applicable policy at this point |
13335 In_Assertion_Expr := In_Assertion_Expr + 1; | 14153 In_Assertion_Expr := In_Assertion_Expr + 1; |
13336 Analyze_And_Resolve (Expr, Any_Boolean); | 14154 Analyze_And_Resolve (Expr, Any_Boolean); |
13337 In_Assertion_Expr := In_Assertion_Expr - 1; | 14155 In_Assertion_Expr := In_Assertion_Expr - 1; |
13338 end if; | 14156 end if; |
13339 | 14157 |
13340 Restore_Ghost_Mode (Saved_GM); | 14158 Restore_Ghost_Region (Saved_GM, Saved_IGR); |
13341 end Check; | 14159 end Check; |
13342 | 14160 |
13343 -------------------------- | 14161 -------------------------- |
13344 -- Check_Float_Overflow -- | 14162 -- Check_Float_Overflow -- |
13345 -------------------------- | 14163 -------------------------- |
13804 Check_No_Identifiers; | 14622 Check_No_Identifiers; |
13805 Check_At_Most_N_Arguments (1); | 14623 Check_At_Most_N_Arguments (1); |
13806 | 14624 |
13807 Obj_Decl := Find_Related_Context (N, Do_Checks => True); | 14625 Obj_Decl := Find_Related_Context (N, Do_Checks => True); |
13808 | 14626 |
13809 -- Object declaration | 14627 if Nkind (Obj_Decl) /= N_Object_Declaration then |
13810 | |
13811 if Nkind (Obj_Decl) = N_Object_Declaration then | |
13812 null; | |
13813 | |
13814 -- Otherwise the pragma is associated with an illegal construct | |
13815 | |
13816 else | |
13817 Pragma_Misplaced; | 14628 Pragma_Misplaced; |
13818 return; | 14629 return; |
13819 end if; | 14630 end if; |
13820 | 14631 |
13821 Obj_Id := Defining_Entity (Obj_Decl); | 14632 Obj_Id := Defining_Entity (Obj_Decl); |
15000 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg)) | 15811 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg)) |
15001 then | 15812 then |
15002 Set_Elaborate_Present (Citem, True); | 15813 Set_Elaborate_Present (Citem, True); |
15003 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem)); | 15814 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem)); |
15004 | 15815 |
15816 -- With the pragma present, elaboration calls on | |
15817 -- subprograms from the named unit need no further | |
15818 -- checks, as long as the pragma appears in the current | |
15819 -- compilation unit. If the pragma appears in some unit | |
15820 -- in the context, there might still be a need for an | |
15821 -- Elaborate_All_Desirable from the current compilation | |
15822 -- to the named unit, so we keep the check enabled. This | |
15823 -- does not apply in SPARK mode, where we allow pragma | |
15824 -- Elaborate, but we don't trust it to be right so we | |
15825 -- will still insist on the Elaborate_All. | |
15826 | |
15827 if Legacy_Elaboration_Checks | |
15828 and then In_Extended_Main_Source_Unit (N) | |
15829 and then SPARK_Mode /= On | |
15830 then | |
15831 Set_Suppress_Elaboration_Warnings | |
15832 (Entity (Name (Citem))); | |
15833 end if; | |
15834 | |
15005 exit Inner; | 15835 exit Inner; |
15006 end if; | 15836 end if; |
15007 | 15837 |
15008 Next (Citem); | 15838 Next (Citem); |
15009 end loop Inner; | 15839 end loop Inner; |
15013 ("argument of pragma% is not withed unit", Arg); | 15843 ("argument of pragma% is not withed unit", Arg); |
15014 end if; | 15844 end if; |
15015 | 15845 |
15016 Next (Arg); | 15846 Next (Arg); |
15017 end loop Outer; | 15847 end loop Outer; |
15018 | |
15019 -- Give a warning if operating in static mode with one of the | |
15020 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set. | |
15021 | |
15022 if Elab_Warnings | |
15023 and not Dynamic_Elaboration_Checks | |
15024 | |
15025 -- pragma Elaborate not allowed in SPARK mode anyway. We | |
15026 -- already complained about it, no point in generating any | |
15027 -- further complaint. | |
15028 | |
15029 and SPARK_Mode /= On | |
15030 then | |
15031 Error_Msg_N | |
15032 ("?l?use of pragma Elaborate may not be safe", N); | |
15033 Error_Msg_N | |
15034 ("?l?use pragma Elaborate_All instead if possible", N); | |
15035 end if; | |
15036 end Elaborate; | 15848 end Elaborate; |
15037 | 15849 |
15038 ------------------- | 15850 ------------------- |
15039 -- Elaborate_All -- | 15851 -- Elaborate_All -- |
15040 ------------------- | 15852 ------------------- |
15077 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg)) | 15889 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg)) |
15078 then | 15890 then |
15079 Set_Elaborate_All_Present (Citem, True); | 15891 Set_Elaborate_All_Present (Citem, True); |
15080 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem)); | 15892 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem)); |
15081 | 15893 |
15894 -- Suppress warnings and elaboration checks on the named | |
15895 -- unit if the pragma is in the current compilation, as | |
15896 -- for pragma Elaborate. | |
15897 | |
15898 if Legacy_Elaboration_Checks | |
15899 and then In_Extended_Main_Source_Unit (N) | |
15900 then | |
15901 Set_Suppress_Elaboration_Warnings | |
15902 (Entity (Name (Citem))); | |
15903 end if; | |
15904 | |
15082 exit Innr; | 15905 exit Innr; |
15083 end if; | 15906 end if; |
15084 | 15907 |
15085 Next (Citem); | 15908 Next (Citem); |
15086 end loop Innr; | 15909 end loop Innr; |
15126 then | 15949 then |
15127 Error_Pragma ("pragma% must refer to a spec, not a body"); | 15950 Error_Pragma ("pragma% must refer to a spec, not a body"); |
15128 else | 15951 else |
15129 Set_Body_Required (Cunit_Node); | 15952 Set_Body_Required (Cunit_Node); |
15130 Set_Has_Pragma_Elaborate_Body (Cunit_Ent); | 15953 Set_Has_Pragma_Elaborate_Body (Cunit_Ent); |
15954 | |
15955 -- If we are in dynamic elaboration mode, then we suppress | |
15956 -- elaboration warnings for the unit, since it is definitely | |
15957 -- fine NOT to do dynamic checks at the first level (and such | |
15958 -- checks will be suppressed because no elaboration boolean | |
15959 -- is created for Elaborate_Body packages). | |
15960 -- | |
15961 -- But in the static model of elaboration, Elaborate_Body is | |
15962 -- definitely NOT good enough to ensure elaboration safety on | |
15963 -- its own, since the body may WITH other units that are not | |
15964 -- safe from an elaboration point of view, so a client must | |
15965 -- still do an Elaborate_All on such units. | |
15966 -- | |
15967 -- Debug flag -gnatdD restores the old behavior of 3.13, where | |
15968 -- Elaborate_Body always suppressed elab warnings. | |
15969 | |
15970 if Legacy_Elaboration_Checks | |
15971 and then (Dynamic_Elaboration_Checks or Debug_Flag_DD) | |
15972 then | |
15973 Set_Suppress_Elaboration_Warnings (Cunit_Ent); | |
15974 end if; | |
15131 end if; | 15975 end if; |
15132 end Elaborate_Body; | 15976 end Elaborate_Body; |
15133 | 15977 |
15134 ------------------------ | 15978 ------------------------ |
15135 -- Elaboration_Checks -- | 15979 -- Elaboration_Checks -- |
15136 ------------------------ | 15980 ------------------------ |
15137 | 15981 |
15138 -- pragma Elaboration_Checks (Static | Dynamic); | 15982 -- pragma Elaboration_Checks (Static | Dynamic); |
15139 | 15983 |
15140 when Pragma_Elaboration_Checks => | 15984 when Pragma_Elaboration_Checks => Elaboration_Checks : declare |
15985 procedure Check_Duplicate_Elaboration_Checks_Pragma; | |
15986 -- Emit an error if the current context list already contains | |
15987 -- a previous Elaboration_Checks pragma. This routine raises | |
15988 -- Pragma_Exit if a duplicate is found. | |
15989 | |
15990 procedure Ignore_Elaboration_Checks_Pragma; | |
15991 -- Warn that the effects of the pragma are ignored. This routine | |
15992 -- raises Pragma_Exit. | |
15993 | |
15994 ----------------------------------------------- | |
15995 -- Check_Duplicate_Elaboration_Checks_Pragma -- | |
15996 ----------------------------------------------- | |
15997 | |
15998 procedure Check_Duplicate_Elaboration_Checks_Pragma is | |
15999 Item : Node_Id; | |
16000 | |
16001 begin | |
16002 Item := Prev (N); | |
16003 while Present (Item) loop | |
16004 if Nkind (Item) = N_Pragma | |
16005 and then Pragma_Name (Item) = Name_Elaboration_Checks | |
16006 then | |
16007 Duplication_Error | |
16008 (Prag => N, | |
16009 Prev => Item); | |
16010 raise Pragma_Exit; | |
16011 end if; | |
16012 | |
16013 Prev (Item); | |
16014 end loop; | |
16015 end Check_Duplicate_Elaboration_Checks_Pragma; | |
16016 | |
16017 -------------------------------------- | |
16018 -- Ignore_Elaboration_Checks_Pragma -- | |
16019 -------------------------------------- | |
16020 | |
16021 procedure Ignore_Elaboration_Checks_Pragma is | |
16022 begin | |
16023 Error_Msg_Name_1 := Pname; | |
16024 Error_Msg_N ("??effects of pragma % are ignored", N); | |
16025 Error_Msg_N | |
16026 ("\place pragma on initial declaration of library unit", N); | |
16027 | |
16028 raise Pragma_Exit; | |
16029 end Ignore_Elaboration_Checks_Pragma; | |
16030 | |
16031 -- Local variables | |
16032 | |
16033 Context : constant Node_Id := Parent (N); | |
16034 Unt : Node_Id; | |
16035 | |
16036 -- Start of processing for Elaboration_Checks | |
16037 | |
16038 begin | |
15141 GNAT_Pragma; | 16039 GNAT_Pragma; |
15142 Check_Arg_Count (1); | 16040 Check_Arg_Count (1); |
15143 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic); | 16041 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic); |
15144 | 16042 |
15145 -- Set flag accordingly (ignore attempt at dynamic elaboration | 16043 -- The pragma appears in a configuration file |
15146 -- checks in SPARK mode). | 16044 |
16045 if No (Context) then | |
16046 Check_Valid_Configuration_Pragma; | |
16047 Check_Duplicate_Elaboration_Checks_Pragma; | |
16048 | |
16049 -- The pragma acts as a configuration pragma in a compilation unit | |
16050 | |
16051 -- pragma Elaboration_Checks (...); | |
16052 -- package Pack is ...; | |
16053 | |
16054 elsif Nkind (Context) = N_Compilation_Unit | |
16055 and then List_Containing (N) = Context_Items (Context) | |
16056 then | |
16057 Check_Valid_Configuration_Pragma; | |
16058 Check_Duplicate_Elaboration_Checks_Pragma; | |
16059 | |
16060 Unt := Unit (Context); | |
16061 | |
16062 -- The pragma must appear on the initial declaration of a unit. | |
16063 -- If this is not the case, warn that the effects of the pragma | |
16064 -- are ignored. | |
16065 | |
16066 if Nkind (Unt) = N_Package_Body then | |
16067 Ignore_Elaboration_Checks_Pragma; | |
16068 | |
16069 -- Check the Acts_As_Spec flag of the compilation units itself | |
16070 -- to determine whether the subprogram body completes since it | |
16071 -- has not been analyzed yet. This is safe because compilation | |
16072 -- units are not overloadable. | |
16073 | |
16074 elsif Nkind (Unt) = N_Subprogram_Body | |
16075 and then not Acts_As_Spec (Context) | |
16076 then | |
16077 Ignore_Elaboration_Checks_Pragma; | |
16078 | |
16079 elsif Nkind (Unt) = N_Subunit then | |
16080 Ignore_Elaboration_Checks_Pragma; | |
16081 end if; | |
16082 | |
16083 -- Otherwise the pragma does not appear at the configuration level | |
16084 -- and is illegal. | |
16085 | |
16086 else | |
16087 Pragma_Misplaced; | |
16088 end if; | |
16089 | |
16090 -- At this point the pragma is not a duplicate, and appears in the | |
16091 -- proper context. Set the elaboration model in effect. | |
15147 | 16092 |
15148 Dynamic_Elaboration_Checks := | 16093 Dynamic_Elaboration_Checks := |
15149 Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic; | 16094 Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic; |
16095 end Elaboration_Checks; | |
15150 | 16096 |
15151 --------------- | 16097 --------------- |
15152 -- Eliminate -- | 16098 -- Eliminate -- |
15153 --------------- | 16099 --------------- |
15154 | 16100 |
16472 ("controlling formal must be of synchronized tagged type", | 17418 ("controlling formal must be of synchronized tagged type", |
16473 Arg1); | 17419 Arg1); |
16474 return; | 17420 return; |
16475 end if; | 17421 end if; |
16476 | 17422 |
17423 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind | |
17424 -- By_Protected_Procedure to the primitive procedure of a task | |
17425 -- interface. | |
17426 | |
17427 if Chars (Arg2) = Name_By_Protected_Procedure | |
17428 and then Is_Interface (Typ) | |
17429 and then Is_Task_Interface (Typ) | |
17430 then | |
17431 Error_Pragma_Arg | |
17432 ("implementation kind By_Protected_Procedure cannot be " | |
17433 & "applied to a task interface primitive", Arg2); | |
17434 return; | |
17435 end if; | |
17436 | |
16477 -- Procedures declared inside a protected type must be accepted | 17437 -- Procedures declared inside a protected type must be accepted |
16478 | 17438 |
16479 elsif Ekind (Proc_Id) = E_Procedure | 17439 elsif Ekind (Proc_Id) = E_Procedure |
16480 and then Is_Protected_Type (Scope (Proc_Id)) | 17440 and then Is_Protected_Type (Scope (Proc_Id)) |
16481 then | 17441 then |
16484 -- The first argument is not a primitive procedure | 17444 -- The first argument is not a primitive procedure |
16485 | 17445 |
16486 else | 17446 else |
16487 Error_Pragma_Arg | 17447 Error_Pragma_Arg |
16488 ("pragma % must be applied to a primitive procedure", Arg1); | 17448 ("pragma % must be applied to a primitive procedure", Arg1); |
16489 return; | |
16490 end if; | |
16491 | |
16492 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind | |
16493 -- By_Protected_Procedure to the primitive procedure of a task | |
16494 -- interface. | |
16495 | |
16496 if Chars (Arg2) = Name_By_Protected_Procedure | |
16497 and then Is_Interface (Typ) | |
16498 and then Is_Task_Interface (Typ) | |
16499 then | |
16500 Error_Pragma_Arg | |
16501 ("implementation kind By_Protected_Procedure cannot be " | |
16502 & "applied to a task interface primitive", Arg2); | |
16503 return; | 17449 return; |
16504 end if; | 17450 end if; |
16505 | 17451 |
16506 Record_Rep_Item (Proc_Id, N); | 17452 Record_Rep_Item (Proc_Id, N); |
16507 end Implemented; | 17453 end Implemented; |
16783 return; | 17729 return; |
16784 end if; | 17730 end if; |
16785 | 17731 |
16786 E := Entity (E_Id); | 17732 E := Entity (E_Id); |
16787 | 17733 |
17734 -- A record type with a self-referential component of anonymous | |
17735 -- access type is given an incomplete view in order to handle the | |
17736 -- self reference: | |
17737 -- | |
17738 -- type Rec is record | |
17739 -- Self : access Rec; | |
17740 -- end record; | |
17741 -- | |
17742 -- becomes | |
17743 -- | |
17744 -- type Rec; | |
17745 -- type Ptr is access Rec; | |
17746 -- type Rec is record | |
17747 -- Self : Ptr; | |
17748 -- end record; | |
17749 -- | |
17750 -- Since the incomplete view is now the initial view of the type, | |
17751 -- the argument of the pragma will reference the incomplete view, | |
17752 -- but this view is illegal according to the semantics of the | |
17753 -- pragma. | |
17754 -- | |
17755 -- Obtain the full view of an internally-generated incomplete type | |
17756 -- only. This way an attempt to associate the pragma with a source | |
17757 -- incomplete type is still caught. | |
17758 | |
17759 if Ekind (E) = E_Incomplete_Type | |
17760 and then not Comes_From_Source (E) | |
17761 and then Present (Full_View (E)) | |
17762 then | |
17763 E := Full_View (E); | |
17764 end if; | |
17765 | |
16788 -- A pragma that applies to a Ghost entity becomes Ghost for the | 17766 -- A pragma that applies to a Ghost entity becomes Ghost for the |
16789 -- purposes of legality checks and removal of ignored Ghost code. | 17767 -- purposes of legality checks and removal of ignored Ghost code. |
16790 | 17768 |
16791 Mark_Ghost_Pragma (N, E); | 17769 Mark_Ghost_Pragma (N, E); |
16792 | 17770 |
16875 Check_No_Identifiers; | 17853 Check_No_Identifiers; |
16876 Check_Arg_Count (1); | 17854 Check_Arg_Count (1); |
16877 | 17855 |
16878 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True); | 17856 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True); |
16879 | 17857 |
16880 -- Ensure the proper placement of the pragma. Initial_Condition | 17858 if not Nkind_In (Pack_Decl, N_Generic_Package_Declaration, |
16881 -- must be associated with a package declaration. | 17859 N_Package_Declaration) |
16882 | |
16883 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration, | |
16884 N_Package_Declaration) | |
16885 then | 17860 then |
16886 null; | |
16887 | |
16888 -- Otherwise the pragma is associated with an illegal context | |
16889 | |
16890 else | |
16891 Pragma_Misplaced; | 17861 Pragma_Misplaced; |
16892 return; | 17862 return; |
16893 end if; | 17863 end if; |
16894 | 17864 |
16895 Pack_Id := Defining_Entity (Pack_Decl); | 17865 Pack_Id := Defining_Entity (Pack_Decl); |
16921 | 17891 |
16922 ------------------------ | 17892 ------------------------ |
16923 -- Initialize_Scalars -- | 17893 -- Initialize_Scalars -- |
16924 ------------------------ | 17894 ------------------------ |
16925 | 17895 |
16926 -- pragma Initialize_Scalars; | 17896 -- pragma Initialize_Scalars |
16927 | 17897 -- [ ( TYPE_VALUE_PAIR {, TYPE_VALUE_PAIR} ) ]; |
16928 when Pragma_Initialize_Scalars => | 17898 |
17899 -- TYPE_VALUE_PAIR ::= | |
17900 -- SCALAR_TYPE => static_EXPRESSION | |
17901 | |
17902 -- SCALAR_TYPE := | |
17903 -- Short_Float | |
17904 -- | Float | |
17905 -- | Long_Float | |
17906 -- | Long_Long_Flat | |
17907 -- | Signed_8 | |
17908 -- | Signed_16 | |
17909 -- | Signed_32 | |
17910 -- | Signed_64 | |
17911 -- | Unsigned_8 | |
17912 -- | Unsigned_16 | |
17913 -- | Unsigned_32 | |
17914 -- | Unsigned_64 | |
17915 | |
17916 when Pragma_Initialize_Scalars => Do_Initialize_Scalars : declare | |
17917 Seen : array (Scalar_Id) of Node_Id := (others => Empty); | |
17918 -- This collection holds the individual pairs which specify the | |
17919 -- invalid values of their respective scalar types. | |
17920 | |
17921 procedure Analyze_Float_Value | |
17922 (Scal_Typ : Float_Scalar_Id; | |
17923 Val_Expr : Node_Id); | |
17924 -- Analyze a type value pair associated with float type Scal_Typ | |
17925 -- and expression Val_Expr. | |
17926 | |
17927 procedure Analyze_Integer_Value | |
17928 (Scal_Typ : Integer_Scalar_Id; | |
17929 Val_Expr : Node_Id); | |
17930 -- Analyze a type value pair associated with integer type Scal_Typ | |
17931 -- and expression Val_Expr. | |
17932 | |
17933 procedure Analyze_Type_Value_Pair (Pair : Node_Id); | |
17934 -- Analyze type value pair Pair | |
17935 | |
17936 ------------------------- | |
17937 -- Analyze_Float_Value -- | |
17938 ------------------------- | |
17939 | |
17940 procedure Analyze_Float_Value | |
17941 (Scal_Typ : Float_Scalar_Id; | |
17942 Val_Expr : Node_Id) | |
17943 is | |
17944 begin | |
17945 Analyze_And_Resolve (Val_Expr, Any_Real); | |
17946 | |
17947 if Is_OK_Static_Expression (Val_Expr) then | |
17948 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value_R (Val_Expr)); | |
17949 | |
17950 else | |
17951 Error_Msg_Name_1 := Scal_Typ; | |
17952 Error_Msg_N ("value for type % must be static", Val_Expr); | |
17953 end if; | |
17954 end Analyze_Float_Value; | |
17955 | |
17956 --------------------------- | |
17957 -- Analyze_Integer_Value -- | |
17958 --------------------------- | |
17959 | |
17960 procedure Analyze_Integer_Value | |
17961 (Scal_Typ : Integer_Scalar_Id; | |
17962 Val_Expr : Node_Id) | |
17963 is | |
17964 begin | |
17965 Analyze_And_Resolve (Val_Expr, Any_Integer); | |
17966 | |
17967 if Is_OK_Static_Expression (Val_Expr) then | |
17968 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value (Val_Expr)); | |
17969 | |
17970 else | |
17971 Error_Msg_Name_1 := Scal_Typ; | |
17972 Error_Msg_N ("value for type % must be static", Val_Expr); | |
17973 end if; | |
17974 end Analyze_Integer_Value; | |
17975 | |
17976 ----------------------------- | |
17977 -- Analyze_Type_Value_Pair -- | |
17978 ----------------------------- | |
17979 | |
17980 procedure Analyze_Type_Value_Pair (Pair : Node_Id) is | |
17981 Scal_Typ : constant Name_Id := Chars (Pair); | |
17982 Val_Expr : constant Node_Id := Expression (Pair); | |
17983 Prev_Pair : Node_Id; | |
17984 | |
17985 begin | |
17986 if Scal_Typ in Scalar_Id then | |
17987 Prev_Pair := Seen (Scal_Typ); | |
17988 | |
17989 -- Prevent multiple attempts to set a value for a scalar | |
17990 -- type. | |
17991 | |
17992 if Present (Prev_Pair) then | |
17993 Error_Msg_Name_1 := Scal_Typ; | |
17994 Error_Msg_N | |
17995 ("cannot specify multiple invalid values for type %", | |
17996 Pair); | |
17997 | |
17998 Error_Msg_Sloc := Sloc (Prev_Pair); | |
17999 Error_Msg_N ("previous value set #", Pair); | |
18000 | |
18001 -- Ignore the effects of the pair, but do not halt the | |
18002 -- analysis of the pragma altogether. | |
18003 | |
18004 return; | |
18005 | |
18006 -- Otherwise capture the first pair for this scalar type | |
18007 | |
18008 else | |
18009 Seen (Scal_Typ) := Pair; | |
18010 end if; | |
18011 | |
18012 if Scal_Typ in Float_Scalar_Id then | |
18013 Analyze_Float_Value (Scal_Typ, Val_Expr); | |
18014 | |
18015 else pragma Assert (Scal_Typ in Integer_Scalar_Id); | |
18016 Analyze_Integer_Value (Scal_Typ, Val_Expr); | |
18017 end if; | |
18018 | |
18019 -- Otherwise the scalar family is illegal | |
18020 | |
18021 else | |
18022 Error_Msg_Name_1 := Pname; | |
18023 Error_Msg_N | |
18024 ("argument of pragma % must denote valid scalar family", | |
18025 Pair); | |
18026 end if; | |
18027 end Analyze_Type_Value_Pair; | |
18028 | |
18029 -- Local variables | |
18030 | |
18031 Pairs : constant List_Id := Pragma_Argument_Associations (N); | |
18032 Pair : Node_Id; | |
18033 | |
18034 -- Start of processing for Do_Initialize_Scalars | |
18035 | |
18036 begin | |
16929 GNAT_Pragma; | 18037 GNAT_Pragma; |
16930 Check_Arg_Count (0); | |
16931 Check_Valid_Configuration_Pragma; | 18038 Check_Valid_Configuration_Pragma; |
16932 Check_Restriction (No_Initialize_Scalars, N); | 18039 Check_Restriction (No_Initialize_Scalars, N); |
18040 | |
18041 -- Ignore the effects of the pragma when No_Initialize_Scalars is | |
18042 -- in effect. | |
18043 | |
18044 if Restriction_Active (No_Initialize_Scalars) then | |
18045 null; | |
16933 | 18046 |
16934 -- Initialize_Scalars creates false positives in CodePeer, and | 18047 -- Initialize_Scalars creates false positives in CodePeer, and |
16935 -- incorrect negative results in GNATprove mode, so ignore this | 18048 -- incorrect negative results in GNATprove mode, so ignore this |
16936 -- pragma in these modes. | 18049 -- pragma in these modes. |
16937 | 18050 |
16938 if not Restriction_Active (No_Initialize_Scalars) | 18051 elsif CodePeer_Mode or GNATprove_Mode then |
16939 and then not (CodePeer_Mode or GNATprove_Mode) | 18052 null; |
16940 then | 18053 |
18054 -- Otherwise analyze the pragma | |
18055 | |
18056 else | |
18057 if Present (Pairs) then | |
18058 | |
18059 -- Install Standard in order to provide access to primitive | |
18060 -- types in case the expressions contain attributes such as | |
18061 -- Integer'Last. | |
18062 | |
18063 Push_Scope (Standard_Standard); | |
18064 | |
18065 Pair := First (Pairs); | |
18066 while Present (Pair) loop | |
18067 Analyze_Type_Value_Pair (Pair); | |
18068 Next (Pair); | |
18069 end loop; | |
18070 | |
18071 -- Remove Standard | |
18072 | |
18073 Pop_Scope; | |
18074 end if; | |
18075 | |
16941 Init_Or_Norm_Scalars := True; | 18076 Init_Or_Norm_Scalars := True; |
16942 Initialize_Scalars := True; | 18077 Initialize_Scalars := True; |
16943 end if; | 18078 end if; |
18079 end Do_Initialize_Scalars; | |
16944 | 18080 |
16945 ----------------- | 18081 ----------------- |
16946 -- Initializes -- | 18082 -- Initializes -- |
16947 ----------------- | 18083 ----------------- |
16948 | 18084 |
16989 Check_No_Identifiers; | 18125 Check_No_Identifiers; |
16990 Check_Arg_Count (1); | 18126 Check_Arg_Count (1); |
16991 | 18127 |
16992 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True); | 18128 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True); |
16993 | 18129 |
16994 -- Ensure the proper placement of the pragma. Initializes must be | 18130 if not Nkind_In (Pack_Decl, N_Generic_Package_Declaration, |
16995 -- associated with a package declaration. | 18131 N_Package_Declaration) |
16996 | |
16997 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration, | |
16998 N_Package_Declaration) | |
16999 then | 18132 then |
17000 null; | |
17001 | |
17002 -- Otherwise the pragma is associated with an illegal construc | |
17003 | |
17004 else | |
17005 Pragma_Misplaced; | 18133 Pragma_Misplaced; |
17006 return; | 18134 return; |
17007 end if; | 18135 end if; |
17008 | 18136 |
17009 Pack_Id := Defining_Entity (Pack_Decl); | 18137 Pack_Id := Defining_Entity (Pack_Decl); |
18165 -- Process all increasing / decreasing expressions | 19293 -- Process all increasing / decreasing expressions |
18166 | 19294 |
18167 Variant := First (Pragma_Argument_Associations (N)); | 19295 Variant := First (Pragma_Argument_Associations (N)); |
18168 while Present (Variant) loop | 19296 while Present (Variant) loop |
18169 if Chars (Variant) = No_Name then | 19297 if Chars (Variant) = No_Name then |
18170 Error_Pragma_Arg ("expect name `Increases`", Variant); | 19298 Error_Pragma_Arg_Ident ("expect name `Increases`", Variant); |
18171 | 19299 |
18172 elsif not Nam_In (Chars (Variant), Name_Decreases, | 19300 elsif not Nam_In (Chars (Variant), Name_Decreases, |
18173 Name_Increases) | 19301 Name_Increases) |
18174 then | 19302 then |
18175 declare | 19303 declare |
18356 -- Max_Queue_Length -- | 19484 -- Max_Queue_Length -- |
18357 ---------------------- | 19485 ---------------------- |
18358 | 19486 |
18359 -- pragma Max_Queue_Length (static_integer_EXPRESSION); | 19487 -- pragma Max_Queue_Length (static_integer_EXPRESSION); |
18360 | 19488 |
18361 when Pragma_Max_Queue_Length => Max_Queue_Length : declare | 19489 -- This processing is shared by Pragma_Max_Entry_Queue_Depth |
19490 | |
19491 when Pragma_Max_Queue_Length | |
19492 | Pragma_Max_Entry_Queue_Depth | |
19493 => | |
19494 Max_Queue_Length : declare | |
18362 Arg : Node_Id; | 19495 Arg : Node_Id; |
18363 Entry_Decl : Node_Id; | 19496 Entry_Decl : Node_Id; |
18364 Entry_Id : Entity_Id; | 19497 Entry_Id : Entity_Id; |
18365 Val : Uint; | 19498 Val : Uint; |
18366 | 19499 |
18367 begin | 19500 begin |
18368 GNAT_Pragma; | 19501 if Prag_Id = Pragma_Max_Queue_Length then |
19502 GNAT_Pragma; | |
19503 end if; | |
19504 | |
18369 Check_Arg_Count (1); | 19505 Check_Arg_Count (1); |
18370 | 19506 |
18371 Entry_Decl := | 19507 Entry_Decl := |
18372 Find_Related_Declaration_Or_Body (N, Do_Checks => True); | 19508 Find_Related_Declaration_Or_Body (N, Do_Checks => True); |
18373 | 19509 |
18380 if Nkind (Parent (N)) = N_Task_Definition then | 19516 if Nkind (Parent (N)) = N_Task_Definition then |
18381 Error_Pragma ("pragma % cannot apply to task entries"); | 19517 Error_Pragma ("pragma % cannot apply to task entries"); |
18382 return; | 19518 return; |
18383 end if; | 19519 end if; |
18384 | 19520 |
18385 Entry_Id := Unique_Defining_Entity (Entry_Decl); | 19521 Entry_Id := Defining_Entity (Entry_Decl); |
18386 | 19522 |
18387 -- Otherwise the pragma is associated with an illegal construct | 19523 -- Otherwise the pragma is associated with an illegal construct |
18388 | 19524 |
18389 else | 19525 else |
18390 Error_Pragma ("pragma % must apply to a protected entry"); | 19526 Error_Pragma ("pragma % must apply to a protected entry"); |
18418 -- if it's not an integer literal because this is not taken care | 19554 -- if it's not an integer literal because this is not taken care |
18419 -- of automatically elsewhere. | 19555 -- of automatically elsewhere. |
18420 | 19556 |
18421 if Nkind (Arg) /= N_Integer_Literal then | 19557 if Nkind (Arg) /= N_Integer_Literal then |
18422 Rewrite (Arg, Make_Integer_Literal (Sloc (Arg), Val)); | 19558 Rewrite (Arg, Make_Integer_Literal (Sloc (Arg), Val)); |
19559 Set_Etype (Arg, Etype (Original_Node (Arg))); | |
18423 end if; | 19560 end if; |
18424 | 19561 |
18425 Record_Rep_Item (Entry_Id, N); | 19562 Record_Rep_Item (Entry_Id, N); |
18426 end Max_Queue_Length; | 19563 end Max_Queue_Length; |
18427 | 19564 |
19545 -- Do not consider internally generated items | 20682 -- Do not consider internally generated items |
19546 | 20683 |
19547 if not Comes_From_Source (Item_Id) then | 20684 if not Comes_From_Source (Item_Id) then |
19548 null; | 20685 null; |
19549 | 20686 |
20687 -- Do not consider generic formals or their corresponding | |
20688 -- actuals because they are not part of a visible state. | |
20689 -- Note that both entities are marked as hidden. | |
20690 | |
20691 elsif Is_Hidden (Item_Id) then | |
20692 null; | |
20693 | |
19550 -- The Part_Of indicator turns an abstract state or an | 20694 -- The Part_Of indicator turns an abstract state or an |
19551 -- object into a constituent of the encapsulating state. | 20695 -- object into a constituent of the encapsulating state. |
20696 -- Note that constants are considered here even though | |
20697 -- they may not depend on variable input. This check is | |
20698 -- left to the SPARK prover. | |
19552 | 20699 |
19553 elsif Ekind_In (Item_Id, E_Abstract_State, | 20700 elsif Ekind_In (Item_Id, E_Abstract_State, |
19554 E_Constant, | 20701 E_Constant, |
19555 E_Variable) | 20702 E_Variable) |
19556 then | 20703 then |
20112 -- subtype accordingly. In the case of predicates we consider them | 21259 -- subtype accordingly. In the case of predicates we consider them |
20113 -- enabled unless Ignore is specified (either directly or with a | 21260 -- enabled unless Ignore is specified (either directly or with a |
20114 -- general Assertion_Policy pragma) to preserve existing warnings. | 21261 -- general Assertion_Policy pragma) to preserve existing warnings. |
20115 | 21262 |
20116 Set_Has_Predicates (Typ); | 21263 Set_Has_Predicates (Typ); |
21264 | |
21265 -- Indicate that the pragma must be processed at the point the | |
21266 -- type is frozen, as is done for the corresponding aspect. | |
21267 | |
21268 Set_Has_Delayed_Aspects (Typ); | |
21269 Set_Has_Delayed_Freeze (Typ); | |
21270 | |
20117 Set_Predicates_Ignored (Typ, | 21271 Set_Predicates_Ignored (Typ, |
20118 Present (Check_Policy_List) | 21272 Present (Check_Policy_List) |
20119 and then | 21273 and then |
20120 Policy_In_Effect (Name_Dynamic_Predicate) = Name_Ignore); | 21274 Policy_In_Effect (Name_Dynamic_Predicate) = Name_Ignore); |
20121 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True); | 21275 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True); |
20203 null; | 21357 null; |
20204 | 21358 |
20205 else | 21359 else |
20206 if not Debug_Flag_U then | 21360 if not Debug_Flag_U then |
20207 Set_Is_Preelaborated (Ent); | 21361 Set_Is_Preelaborated (Ent); |
21362 | |
21363 if Legacy_Elaboration_Checks then | |
21364 Set_Suppress_Elaboration_Warnings (Ent); | |
21365 end if; | |
20208 end if; | 21366 end if; |
20209 end if; | 21367 end if; |
20210 end if; | 21368 end if; |
20211 end Preelaborate; | 21369 end Preelaborate; |
20212 | 21370 |
20830 Mark_Ghost_Pragma (N, Ent); | 21988 Mark_Ghost_Pragma (N, Ent); |
20831 | 21989 |
20832 if not Debug_Flag_U then | 21990 if not Debug_Flag_U then |
20833 Set_Is_Pure (Ent); | 21991 Set_Is_Pure (Ent); |
20834 Set_Has_Pragma_Pure (Ent); | 21992 Set_Has_Pragma_Pure (Ent); |
21993 | |
21994 if Legacy_Elaboration_Checks then | |
21995 Set_Suppress_Elaboration_Warnings (Ent); | |
21996 end if; | |
20835 end if; | 21997 end if; |
20836 end Pure; | 21998 end Pure; |
20837 | 21999 |
20838 ------------------- | 22000 ------------------- |
20839 -- Pure_Function -- | 22001 -- Pure_Function -- |
20844 when Pragma_Pure_Function => Pure_Function : declare | 22006 when Pragma_Pure_Function => Pure_Function : declare |
20845 Def_Id : Entity_Id; | 22007 Def_Id : Entity_Id; |
20846 E : Entity_Id; | 22008 E : Entity_Id; |
20847 E_Id : Node_Id; | 22009 E_Id : Node_Id; |
20848 Effective : Boolean := False; | 22010 Effective : Boolean := False; |
22011 Orig_Def : Entity_Id; | |
22012 Same_Decl : Boolean := False; | |
20849 | 22013 |
20850 begin | 22014 begin |
20851 GNAT_Pragma; | 22015 GNAT_Pragma; |
20852 Check_Arg_Count (1); | 22016 Check_Arg_Count (1); |
20853 Check_Optional_Identifier (Arg1, Name_Entity); | 22017 Check_Optional_Identifier (Arg1, Name_Entity); |
20877 then | 22041 then |
20878 Error_Pragma_Arg | 22042 Error_Pragma_Arg |
20879 ("pragma% requires a function name", Arg1); | 22043 ("pragma% requires a function name", Arg1); |
20880 end if; | 22044 end if; |
20881 | 22045 |
20882 Set_Is_Pure (Def_Id); | 22046 -- When we have a generic function we must jump up a level |
20883 | 22047 -- to the declaration of the wrapper package itself. |
20884 if not Has_Pragma_Pure_Function (Def_Id) then | 22048 |
20885 Set_Has_Pragma_Pure_Function (Def_Id); | 22049 Orig_Def := Def_Id; |
20886 Effective := True; | 22050 |
22051 if Is_Generic_Instance (Def_Id) then | |
22052 while Nkind (Orig_Def) /= N_Package_Declaration loop | |
22053 Orig_Def := Parent (Orig_Def); | |
22054 end loop; | |
22055 end if; | |
22056 | |
22057 if In_Same_Declarative_Part (Parent (N), Orig_Def) then | |
22058 Same_Decl := True; | |
22059 Set_Is_Pure (Def_Id); | |
22060 | |
22061 if not Has_Pragma_Pure_Function (Def_Id) then | |
22062 Set_Has_Pragma_Pure_Function (Def_Id); | |
22063 Effective := True; | |
22064 end if; | |
20887 end if; | 22065 end if; |
20888 | 22066 |
20889 exit when From_Aspect_Specification (N); | 22067 exit when From_Aspect_Specification (N); |
20890 E := Homonym (E); | 22068 E := Homonym (E); |
20891 exit when No (E) or else Scope (E) /= Current_Scope; | 22069 exit when No (E) or else Scope (E) /= Current_Scope; |
20895 and then Warn_On_Redundant_Constructs | 22073 and then Warn_On_Redundant_Constructs |
20896 then | 22074 then |
20897 Error_Msg_NE | 22075 Error_Msg_NE |
20898 ("pragma Pure_Function on& is redundant?r?", | 22076 ("pragma Pure_Function on& is redundant?r?", |
20899 N, Entity (E_Id)); | 22077 N, Entity (E_Id)); |
22078 | |
22079 elsif not Same_Decl then | |
22080 Error_Pragma_Arg | |
22081 ("pragma% argument must be in same declarative part", | |
22082 Arg1); | |
20900 end if; | 22083 end if; |
20901 end if; | 22084 end if; |
20902 end Pure_Function; | 22085 end Pure_Function; |
20903 | 22086 |
20904 -------------------- | 22087 -------------------- |
21193 Check_No_Identifiers; | 22376 Check_No_Identifiers; |
21194 Check_Arg_Count (1); | 22377 Check_Arg_Count (1); |
21195 | 22378 |
21196 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True); | 22379 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True); |
21197 | 22380 |
21198 -- Ensure the proper placement of the pragma. Refined states must | 22381 if Nkind (Pack_Decl) /= N_Package_Body then |
21199 -- be associated with a package body. | |
21200 | |
21201 if Nkind (Pack_Decl) = N_Package_Body then | |
21202 null; | |
21203 | |
21204 -- Otherwise the pragma is associated with an illegal construct | |
21205 | |
21206 else | |
21207 Pragma_Misplaced; | 22382 Pragma_Misplaced; |
21208 return; | 22383 return; |
21209 end if; | 22384 end if; |
21210 | 22385 |
21211 Spec_Id := Corresponding_Spec (Pack_Decl); | 22386 Spec_Id := Corresponding_Spec (Pack_Decl); |
24251 -- Non-Dot case | 25426 -- Non-Dot case |
24252 | 25427 |
24253 else | 25428 else |
24254 OK := Set_Warning_Switch (Chr); | 25429 OK := Set_Warning_Switch (Chr); |
24255 end if; | 25430 end if; |
24256 end if; | 25431 |
24257 | 25432 if not OK then |
24258 if not OK then | 25433 Error_Pragma_Arg |
25434 ("invalid warning switch character " & Chr, | |
25435 Arg1); | |
25436 end if; | |
25437 | |
25438 else | |
24259 Error_Pragma_Arg | 25439 Error_Pragma_Arg |
24260 ("invalid warning switch character " & Chr, | 25440 ("invalid wide character in warning switch ", |
24261 Arg1); | 25441 Arg1); |
24262 end if; | 25442 end if; |
24263 | 25443 |
24264 J := J + 1; | 25444 J := J + 1; |
24265 end loop; | 25445 end loop; |
24301 else | 25481 else |
24302 loop | 25482 loop |
24303 Set_Warnings_Off | 25483 Set_Warnings_Off |
24304 (E, (Chars (Get_Pragma_Arg (Arg1)) = | 25484 (E, (Chars (Get_Pragma_Arg (Arg1)) = |
24305 Name_Off)); | 25485 Name_Off)); |
25486 | |
25487 -- Suppress elaboration warnings if the entity | |
25488 -- denotes an elaboration target. | |
25489 | |
25490 if Is_Elaboration_Target (E) then | |
25491 Set_Is_Elaboration_Warnings_OK_Id (E, False); | |
25492 end if; | |
24306 | 25493 |
24307 -- For OFF case, make entry in warnings off | 25494 -- For OFF case, make entry in warnings off |
24308 -- pragma table for later processing. But we do | 25495 -- pragma table for later processing. But we do |
24309 -- not do that within an instance, since these | 25496 -- not do that within an instance, since these |
24310 -- warnings are about what is needed in the | 25497 -- warnings are about what is needed in the |
24565 procedure Check_Class_Wide_Condition is | 25752 procedure Check_Class_Wide_Condition is |
24566 new Traverse_Proc (Check_References); | 25753 new Traverse_Proc (Check_References); |
24567 | 25754 |
24568 -- Local variables | 25755 -- Local variables |
24569 | 25756 |
24570 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id)); | 25757 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id)); |
24571 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; | 25758 |
24572 -- Save the Ghost mode to restore on exit | 25759 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
25760 Saved_IGR : constant Node_Id := Ignored_Ghost_Region; | |
25761 -- Save the Ghost-related attributes to restore on exit | |
24573 | 25762 |
24574 Errors : Nat; | 25763 Errors : Nat; |
24575 Restore_Scope : Boolean := False; | 25764 Restore_Scope : Boolean := False; |
24576 | 25765 |
24577 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part | 25766 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part |
24606 | 25795 |
24607 Errors := Serious_Errors_Detected; | 25796 Errors := Serious_Errors_Detected; |
24608 Preanalyze_Assert_Expression (Expr, Standard_Boolean); | 25797 Preanalyze_Assert_Expression (Expr, Standard_Boolean); |
24609 | 25798 |
24610 -- Emit a clarification message when the expression contains at least | 25799 -- Emit a clarification message when the expression contains at least |
24611 -- one undefined reference, possibly due to contract "freezing". | 25800 -- one undefined reference, possibly due to contract freezing. |
24612 | 25801 |
24613 if Errors /= Serious_Errors_Detected | 25802 if Errors /= Serious_Errors_Detected |
24614 and then Present (Freeze_Id) | 25803 and then Present (Freeze_Id) |
24615 and then Has_Undefined_Reference (Expr) | 25804 and then Has_Undefined_Reference (Expr) |
24616 then | 25805 then |
24666 -- subprogram subject to pragma Inline_Always. | 25855 -- subprogram subject to pragma Inline_Always. |
24667 | 25856 |
24668 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id); | 25857 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id); |
24669 Set_Is_Analyzed_Pragma (N); | 25858 Set_Is_Analyzed_Pragma (N); |
24670 | 25859 |
24671 Restore_Ghost_Mode (Saved_GM); | 25860 Restore_Ghost_Region (Saved_GM, Saved_IGR); |
24672 end Analyze_Pre_Post_Condition_In_Decl_Part; | 25861 end Analyze_Pre_Post_Condition_In_Decl_Part; |
24673 | 25862 |
24674 ------------------------------------------ | 25863 ------------------------------------------ |
24675 -- Analyze_Refined_Depends_In_Decl_Part -- | 25864 -- Analyze_Refined_Depends_In_Decl_Part -- |
24676 ------------------------------------------ | 25865 ------------------------------------------ |
26550 | 27739 |
26551 -- The item does not appear in the corresponding Global pragma, | 27740 -- The item does not appear in the corresponding Global pragma, |
26552 -- it must be an extra (SPARK RM 7.2.4(3)). | 27741 -- it must be an extra (SPARK RM 7.2.4(3)). |
26553 | 27742 |
26554 else | 27743 else |
26555 SPARK_Msg_NE ("extra global item &", Item, Item_Id); | 27744 pragma Assert (Present (Global)); |
27745 Error_Msg_Sloc := Sloc (Global); | |
27746 SPARK_Msg_NE ("extra global item & does not refine or " & | |
27747 "repeat any global item #", Item, Item_Id); | |
26556 end if; | 27748 end if; |
26557 end if; | 27749 end if; |
26558 end Check_Refined_Global_Item; | 27750 end Check_Refined_Global_Item; |
26559 | 27751 |
26560 -- Local variables | 27752 -- Local variables |
27273 | 28465 |
27274 Next_Elmt (State_Elmt); | 28466 Next_Elmt (State_Elmt); |
27275 end loop; | 28467 end loop; |
27276 end if; | 28468 end if; |
27277 | 28469 |
27278 -- Constants are part of the hidden state of a package, but | 28470 -- At this point it is known that the constituent is not |
27279 -- the compiler cannot determine whether they have variable | 28471 -- part of the package hidden state and cannot be used in |
27280 -- input (SPARK RM 7.1.1(2)) and cannot classify them as a | 28472 -- a refinement (SPARK RM 7.2.2(9)). |
27281 -- hidden state. Accept the constant quietly even if it is | 28473 |
27282 -- a visible state or lacks a Part_Of indicator. | 28474 Error_Msg_Name_1 := Chars (Spec_Id); |
27283 | 28475 SPARK_Msg_NE |
27284 if Ekind (Constit_Id) = E_Constant then | 28476 ("cannot use & in refinement, constituent is not a hidden " |
27285 Collect_Constituent; | 28477 & "state of package %", Constit, Constit_Id); |
27286 | |
27287 -- If we get here, then the constituent is not a hidden | |
27288 -- state of the related package and may not be used in a | |
27289 -- refinement (SPARK RM 7.2.2(9)). | |
27290 | |
27291 else | |
27292 Error_Msg_Name_1 := Chars (Spec_Id); | |
27293 SPARK_Msg_NE | |
27294 ("cannot use & in refinement, constituent is not a " | |
27295 & "hidden state of package %", Constit, Constit_Id); | |
27296 end if; | |
27297 end if; | 28478 end if; |
27298 end Match_Constituent; | 28479 end Match_Constituent; |
27299 | 28480 |
27300 -- Local variables | 28481 -- Local variables |
27301 | 28482 |
27356 | 28537 |
27357 if Is_Entity_Name (Constit) then | 28538 if Is_Entity_Name (Constit) then |
27358 Constit_Id := Entity_Of (Constit); | 28539 Constit_Id := Entity_Of (Constit); |
27359 | 28540 |
27360 -- When a constituent is declared after a subprogram body | 28541 -- When a constituent is declared after a subprogram body |
27361 -- that caused "freezing" of the related contract where | 28542 -- that caused freezing of the related contract where |
27362 -- pragma Refined_State resides, the constituent appears | 28543 -- pragma Refined_State resides, the constituent appears |
27363 -- undefined and carries Any_Id as its entity. | 28544 -- undefined and carries Any_Id as its entity. |
27364 | 28545 |
27365 -- package body Pack | 28546 -- package body Pack |
27366 -- with Refined_State => (State => Constit) | 28547 -- with Refined_State => (State => Constit) |
27748 -- Do not analyze the pragma multiple times | 28929 -- Do not analyze the pragma multiple times |
27749 | 28930 |
27750 if Is_Analyzed_Pragma (N) then | 28931 if Is_Analyzed_Pragma (N) then |
27751 return; | 28932 return; |
27752 end if; | 28933 end if; |
28934 | |
28935 -- Save the scenario for examination by the ABE Processing phase | |
28936 | |
28937 Record_Elaboration_Scenario (N); | |
27753 | 28938 |
27754 -- Replicate the abstract states declared by the package because the | 28939 -- Replicate the abstract states declared by the package because the |
27755 -- matching algorithm will consume states. | 28940 -- matching algorithm will consume states. |
27756 | 28941 |
27757 Available_States := New_Copy_Elist (Abstract_States (Spec_Id)); | 28942 Available_States := New_Copy_Elist (Abstract_States (Spec_Id)); |
28104 | 29289 |
28105 case Policy is | 29290 case Policy is |
28106 when Name_Ignore | 29291 when Name_Ignore |
28107 | Name_Off | 29292 | Name_Off |
28108 => | 29293 => |
28109 Set_Is_Ignored (N, True); | 29294 -- In CodePeer mode and GNATprove mode, we need to |
28110 Set_Is_Checked (N, False); | 29295 -- consider all assertions, unless they are disabled. |
29296 -- Force Is_Checked on ignored assertions, in particular | |
29297 -- because transformations of the AST may depend on | |
29298 -- assertions being checked (e.g. the translation of | |
29299 -- attribute 'Loop_Entry). | |
29300 | |
29301 if CodePeer_Mode or GNATprove_Mode then | |
29302 Set_Is_Checked (N, True); | |
29303 Set_Is_Ignored (N, False); | |
29304 else | |
29305 Set_Is_Checked (N, False); | |
29306 Set_Is_Ignored (N, True); | |
29307 end if; | |
28111 | 29308 |
28112 when Name_Check | 29309 when Name_Check |
28113 | Name_On | 29310 | Name_On |
28114 => | 29311 => |
28115 Set_Is_Checked (N, True); | 29312 Set_Is_Checked (N, True); |
28135 end loop; | 29332 end loop; |
28136 | 29333 |
28137 -- If there are no specific entries that matched, then we let the | 29334 -- If there are no specific entries that matched, then we let the |
28138 -- setting of assertions govern. Note that this provides the needed | 29335 -- setting of assertions govern. Note that this provides the needed |
28139 -- compatibility with the RM for the cases of assertion, invariant, | 29336 -- compatibility with the RM for the cases of assertion, invariant, |
28140 -- precondition, predicate, and postcondition. | 29337 -- precondition, predicate, and postcondition. Note also that |
29338 -- Assertions_Enabled is forced in CodePeer mode and GNATprove mode. | |
28141 | 29339 |
28142 if Assertions_Enabled then | 29340 if Assertions_Enabled then |
28143 Set_Is_Checked (N, True); | 29341 Set_Is_Checked (N, True); |
28144 Set_Is_Ignored (N, False); | 29342 Set_Is_Ignored (N, False); |
28145 else | 29343 else |
28290 -- Do not consider internally generated items | 29488 -- Do not consider internally generated items |
28291 | 29489 |
28292 if not Comes_From_Source (Item_Id) then | 29490 if not Comes_From_Source (Item_Id) then |
28293 null; | 29491 null; |
28294 | 29492 |
28295 -- A visible state has been found | 29493 -- Do not consider generic formals or their corresponding actuals |
29494 -- because they are not part of a visible state. Note that both | |
29495 -- entities are marked as hidden. | |
29496 | |
29497 elsif Is_Hidden (Item_Id) then | |
29498 null; | |
29499 | |
29500 -- A visible state has been found. Note that constants are not | |
29501 -- considered here because it is not possible to determine whether | |
29502 -- they depend on variable input. This check is left to the SPARK | |
29503 -- prover. | |
28296 | 29504 |
28297 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then | 29505 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then |
28298 return True; | 29506 return True; |
28299 | 29507 |
28300 -- Recursively peek into nested packages and instantiations | 29508 -- Recursively peek into nested packages and instantiations |
28367 elsif Placement = Body_State_Space then | 29575 elsif Placement = Body_State_Space then |
28368 null; | 29576 null; |
28369 | 29577 |
28370 -- In general an item declared in the visible state space of a package | 29578 -- In general an item declared in the visible state space of a package |
28371 -- does not require a Part_Of indicator. The only exception is when the | 29579 -- does not require a Part_Of indicator. The only exception is when the |
28372 -- related package is a private child unit in which case Part_Of must | 29580 -- related package is a nongeneric private child unit, in which case |
28373 -- denote a state in the parent unit or in one of its descendants. | 29581 -- Part_Of must denote a state in the parent unit or in one of its |
29582 -- descendants. | |
28374 | 29583 |
28375 elsif Placement = Visible_State_Space then | 29584 elsif Placement = Visible_State_Space then |
28376 if Is_Child_Unit (Pack_Id) | 29585 if Is_Child_Unit (Pack_Id) |
29586 and then not Is_Generic_Unit (Pack_Id) | |
28377 and then Is_Private_Descendant (Pack_Id) | 29587 and then Is_Private_Descendant (Pack_Id) |
28378 then | 29588 then |
28379 -- A package instantiation does not need a Part_Of indicator when | 29589 -- A package instantiation does not need a Part_Of indicator when |
28380 -- the related generic template has no visible state. | 29590 -- the related generic template has no visible state. |
28381 | 29591 |
28396 ("\& is declared in the visible part of private child " | 29606 ("\& is declared in the visible part of private child " |
28397 & "unit %", Item_Id); | 29607 & "unit %", Item_Id); |
28398 end if; | 29608 end if; |
28399 end if; | 29609 end if; |
28400 | 29610 |
28401 -- When the item appears in the private state space of a packge, it must | 29611 -- When the item appears in the private state space of a package, it |
28402 -- be a part of some state declared by the said package. | 29612 -- must be a part of some state declared by the said package. |
28403 | 29613 |
28404 else pragma Assert (Placement = Private_State_Space); | 29614 else pragma Assert (Placement = Private_State_Space); |
28405 | 29615 |
28406 -- The related package does not declare a state, the item cannot act | 29616 -- The related package does not declare a state, the item cannot act |
28407 -- as a Part_Of constituent. | 29617 -- as a Part_Of constituent. |
28410 null; | 29620 null; |
28411 | 29621 |
28412 -- A package instantiation does not need a Part_Of indicator when the | 29622 -- A package instantiation does not need a Part_Of indicator when the |
28413 -- related generic template has no visible state. | 29623 -- related generic template has no visible state. |
28414 | 29624 |
28415 elsif Ekind (Pack_Id) = E_Package | 29625 elsif Ekind (Item_Id) = E_Package |
28416 and then Is_Generic_Instance (Pack_Id) | 29626 and then Is_Generic_Instance (Item_Id) |
28417 and then not Has_Visible_State (Pack_Id) | 29627 and then not Has_Visible_State (Item_Id) |
28418 then | 29628 then |
28419 null; | 29629 null; |
28420 | 29630 |
28421 -- All other cases require Part_Of | 29631 -- All other cases require Part_Of |
28422 | 29632 |
28745 Clause : Node_Id; | 29955 Clause : Node_Id; |
28746 Clauses : Node_Id; | 29956 Clauses : Node_Id; |
28747 Depends : Node_Id; | 29957 Depends : Node_Id; |
28748 Formal : Entity_Id; | 29958 Formal : Entity_Id; |
28749 Global : Node_Id; | 29959 Global : Node_Id; |
28750 Spec_Id : Entity_Id; | 29960 Spec_Id : Entity_Id := Empty; |
28751 Subp_Decl : Node_Id; | 29961 Subp_Decl : Node_Id; |
28752 Typ : Entity_Id; | 29962 Typ : Entity_Id; |
28753 | 29963 |
28754 -- Start of processing for Collect_Subprogram_Inputs_Outputs | 29964 -- Start of processing for Collect_Subprogram_Inputs_Outputs |
28755 | 29965 |
29136 -- for an expression function. | 30346 -- for an expression function. |
29137 | 30347 |
29138 if Nkind (Original_Node (Stmt)) = N_Expression_Function then | 30348 if Nkind (Original_Node (Stmt)) = N_Expression_Function then |
29139 return Stmt; | 30349 return Stmt; |
29140 | 30350 |
30351 -- The subprogram declaration is an internally generated spec | |
30352 -- for a stand-alone subrogram body declared inside a protected | |
30353 -- body. | |
30354 | |
30355 elsif Present (Corresponding_Body (Stmt)) | |
30356 and then Comes_From_Source (Corresponding_Body (Stmt)) | |
30357 and then Is_Protected_Type (Current_Scope) | |
30358 then | |
30359 return Stmt; | |
30360 | |
29141 -- The subprogram is actually an instance housed within an | 30361 -- The subprogram is actually an instance housed within an |
29142 -- anonymous wrapper package. | 30362 -- anonymous wrapper package. |
29143 | 30363 |
29144 elsif Present (Generic_Parent (Specification (Stmt))) then | 30364 elsif Present (Generic_Parent (Specification (Stmt))) then |
29145 return Stmt; | 30365 return Stmt; |
29288 -- the above circuitry pinpoints precisely the related context. | 30508 -- the above circuitry pinpoints precisely the related context. |
29289 | 30509 |
29290 elsif Present (Corresponding_Aspect (Prag)) then | 30510 elsif Present (Corresponding_Aspect (Prag)) then |
29291 return Parent (Corresponding_Aspect (Prag)); | 30511 return Parent (Corresponding_Aspect (Prag)); |
29292 | 30512 |
29293 -- No candidate packge [body] found | 30513 -- No candidate package [body] found |
29294 | 30514 |
29295 else | 30515 else |
29296 return Empty; | 30516 return Empty; |
29297 end if; | 30517 end if; |
29298 end Find_Related_Package_Or_Body; | 30518 end Find_Related_Package_Or_Body; |
29332 ------------------------- | 30552 ------------------------- |
29333 -- Get_Base_Subprogram -- | 30553 -- Get_Base_Subprogram -- |
29334 ------------------------- | 30554 ------------------------- |
29335 | 30555 |
29336 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is | 30556 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is |
29337 Result : Entity_Id; | |
29338 | |
29339 begin | 30557 begin |
29340 -- Follow subprogram renaming chain | 30558 -- Follow subprogram renaming chain |
29341 | 30559 |
29342 Result := Def_Id; | 30560 if Is_Subprogram (Def_Id) |
29343 | 30561 and then Nkind (Parent (Declaration_Node (Def_Id))) = |
29344 if Is_Subprogram (Result) | 30562 N_Subprogram_Renaming_Declaration |
29345 and then | 30563 and then Present (Alias (Def_Id)) |
29346 Nkind (Parent (Declaration_Node (Result))) = | |
29347 N_Subprogram_Renaming_Declaration | |
29348 and then Present (Alias (Result)) | |
29349 then | 30564 then |
29350 Result := Alias (Result); | 30565 return Alias (Def_Id); |
30566 else | |
30567 return Def_Id; | |
29351 end if; | 30568 end if; |
29352 | |
29353 return Result; | |
29354 end Get_Base_Subprogram; | 30569 end Get_Base_Subprogram; |
29355 | 30570 |
29356 ----------------------- | 30571 ----------------------- |
29357 -- Get_SPARK_Mode_Type -- | 30572 -- Get_SPARK_Mode_Type -- |
29358 ----------------------- | 30573 ----------------------- |
29362 if N = Name_On then | 30577 if N = Name_On then |
29363 return On; | 30578 return On; |
29364 elsif N = Name_Off then | 30579 elsif N = Name_Off then |
29365 return Off; | 30580 return Off; |
29366 | 30581 |
29367 -- Any other argument is illegal | 30582 -- Any other argument is illegal. Assume that no SPARK mode applies to |
30583 -- avoid potential cascaded errors. | |
29368 | 30584 |
29369 else | 30585 else |
29370 raise Program_Error; | 30586 return None; |
29371 end if; | 30587 end if; |
29372 end Get_SPARK_Mode_Type; | 30588 end Get_SPARK_Mode_Type; |
29373 | 30589 |
29374 ------------------------------------ | 30590 ------------------------------------ |
29375 -- Get_SPARK_Mode_From_Annotation -- | 30591 -- Get_SPARK_Mode_From_Annotation -- |
29604 -- 9n arguments from n on are significant, before n insignificant | 30820 -- 9n arguments from n on are significant, before n insignificant |
29605 | 30821 |
29606 Sig_Flags : constant array (Pragma_Id) of Int := | 30822 Sig_Flags : constant array (Pragma_Id) of Int := |
29607 (Pragma_Abort_Defer => -1, | 30823 (Pragma_Abort_Defer => -1, |
29608 Pragma_Abstract_State => -1, | 30824 Pragma_Abstract_State => -1, |
30825 Pragma_Acc_Data => 0, | |
30826 Pragma_Acc_Kernels => 0, | |
30827 Pragma_Acc_Loop => 0, | |
30828 Pragma_Acc_Parallel => 0, | |
29609 Pragma_Ada_83 => -1, | 30829 Pragma_Ada_83 => -1, |
29610 Pragma_Ada_95 => -1, | 30830 Pragma_Ada_95 => -1, |
29611 Pragma_Ada_05 => -1, | 30831 Pragma_Ada_05 => -1, |
29612 Pragma_Ada_2005 => -1, | 30832 Pragma_Ada_2005 => -1, |
29613 Pragma_Ada_12 => -1, | 30833 Pragma_Ada_12 => -1, |
29727 Pragma_Loop_Optimize => 0, | 30947 Pragma_Loop_Optimize => 0, |
29728 Pragma_Loop_Variant => -1, | 30948 Pragma_Loop_Variant => -1, |
29729 Pragma_Machine_Attribute => -1, | 30949 Pragma_Machine_Attribute => -1, |
29730 Pragma_Main => -1, | 30950 Pragma_Main => -1, |
29731 Pragma_Main_Storage => -1, | 30951 Pragma_Main_Storage => -1, |
30952 Pragma_Max_Entry_Queue_Depth => 0, | |
29732 Pragma_Max_Queue_Length => 0, | 30953 Pragma_Max_Queue_Length => 0, |
29733 Pragma_Memory_Size => 0, | 30954 Pragma_Memory_Size => 0, |
29734 Pragma_No_Return => 0, | 30955 Pragma_No_Return => 0, |
29735 Pragma_No_Body => 0, | 30956 Pragma_No_Body => 0, |
29736 Pragma_No_Component_Reordering => -1, | 30957 Pragma_No_Component_Reordering => -1, |
30147 begin | 31368 begin |
30148 Analyze_And_Resolve (Arg1x, Standard_Boolean); | 31369 Analyze_And_Resolve (Arg1x, Standard_Boolean); |
30149 | 31370 |
30150 if Compile_Time_Known_Value (Arg1x) then | 31371 if Compile_Time_Known_Value (Arg1x) then |
30151 if Is_True (Expr_Value (Arg1x)) then | 31372 if Is_True (Expr_Value (Arg1x)) then |
31373 | |
31374 -- We have already verified that the second argument is a static | |
31375 -- string expression. Its string value must be retrieved | |
31376 -- explicitly if it is a declared constant, otherwise it has | |
31377 -- been constant-folded previously. | |
31378 | |
30152 declare | 31379 declare |
30153 Cent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit); | 31380 Cent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit); |
30154 Pname : constant Name_Id := Pragma_Name_Unmapped (N); | 31381 Pname : constant Name_Id := Pragma_Name_Unmapped (N); |
30155 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname); | 31382 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname); |
30156 Str : constant String_Id := Strval (Get_Pragma_Arg (Arg2)); | 31383 Str : constant String_Id := |
31384 Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))); | |
30157 Str_Len : constant Nat := String_Length (Str); | 31385 Str_Len : constant Nat := String_Length (Str); |
30158 | 31386 |
30159 Force : constant Boolean := | 31387 Force : constant Boolean := |
30160 Prag_Id = Pragma_Compile_Time_Warning | 31388 Prag_Id = Pragma_Compile_Time_Warning |
30161 and then Is_Spec_Name (Unit_Name (Current_Sem_Unit)) | 31389 and then Is_Spec_Name (Unit_Name (Current_Sem_Unit)) |