1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2020, Free Software Foundation, Inc. --
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- --
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- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
32 with Aspects; use Aspects;
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Checks; use Checks;
36 with Contracts; use Contracts;
37 with Csets; use Csets;
38 with Debug; use Debug;
39 with Einfo; use Einfo;
40 with Elists; use Elists;
41 with Errout; use Errout;
42 with Exp_Dist; use Exp_Dist;
43 with Exp_Util; use Exp_Util;
44 with Expander; use Expander;
45 with Freeze; use Freeze;
46 with Ghost; use Ghost;
47 with Gnatvsn; use Gnatvsn;
49 with Lib.Writ; use Lib.Writ;
50 with Lib.Xref; use Lib.Xref;
51 with Namet.Sp; use Namet.Sp;
52 with Nlists; use Nlists;
53 with Nmake; use Nmake;
54 with Output; use Output;
55 with Par_SCO; use Par_SCO;
56 with Restrict; use Restrict;
57 with Rident; use Rident;
58 with Rtsfind; use Rtsfind;
60 with Sem_Aux; use Sem_Aux;
61 with Sem_Ch3; use Sem_Ch3;
62 with Sem_Ch6; use Sem_Ch6;
63 with Sem_Ch8; use Sem_Ch8;
64 with Sem_Ch12; use Sem_Ch12;
65 with Sem_Ch13; use Sem_Ch13;
66 with Sem_Disp; use Sem_Disp;
67 with Sem_Dist; use Sem_Dist;
68 with Sem_Elab; use Sem_Elab;
69 with Sem_Elim; use Sem_Elim;
70 with Sem_Eval; use Sem_Eval;
71 with Sem_Intr; use Sem_Intr;
72 with Sem_Mech; use Sem_Mech;
73 with Sem_Res; use Sem_Res;
74 with Sem_Type; use Sem_Type;
75 with Sem_Util; use Sem_Util;
76 with Sem_Warn; use Sem_Warn;
77 with Stand; use Stand;
78 with Sinfo; use Sinfo;
79 with Sinfo.CN; use Sinfo.CN;
80 with Sinput; use Sinput;
81 with Stringt; use Stringt;
82 with Stylesw; use Stylesw;
84 with Targparm; use Targparm;
85 with Tbuild; use Tbuild;
87 with Uintp; use Uintp;
88 with Uname; use Uname;
89 with Urealp; use Urealp;
90 with Validsw; use Validsw;
91 with Warnsw; use Warnsw;
93 with System.Case_Util;
95 package body Sem_Prag is
97 ----------------------------------------------
98 -- Common Handling of Import-Export Pragmas --
99 ----------------------------------------------
101 -- In the following section, a number of Import_xxx and Export_xxx pragmas
102 -- are defined by GNAT. These are compatible with the DEC pragmas of the
103 -- same name, and all have the following common form and processing:
106 -- [Internal =>] LOCAL_NAME
107 -- [, [External =>] EXTERNAL_SYMBOL]
108 -- [, other optional parameters ]);
111 -- [Internal =>] LOCAL_NAME
112 -- [, [External =>] EXTERNAL_SYMBOL]
113 -- [, other optional parameters ]);
115 -- EXTERNAL_SYMBOL ::=
117 -- | static_string_EXPRESSION
119 -- The internal LOCAL_NAME designates the entity that is imported or
120 -- exported, and must refer to an entity in the current declarative
121 -- part (as required by the rules for LOCAL_NAME).
123 -- The external linker name is designated by the External parameter if
124 -- given, or the Internal parameter if not (if there is no External
125 -- parameter, the External parameter is a copy of the Internal name).
127 -- If the External parameter is given as a string, then this string is
128 -- treated as an external name (exactly as though it had been given as an
129 -- External_Name parameter for a normal Import pragma).
131 -- If the External parameter is given as an identifier (or there is no
132 -- External parameter, so that the Internal identifier is used), then
133 -- the external name is the characters of the identifier, translated
134 -- to all lower case letters.
136 -- Note: the external name specified or implied by any of these special
137 -- Import_xxx or Export_xxx pragmas override an external or link name
138 -- specified in a previous Import or Export pragma.
140 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
141 -- named notation, following the standard rules for subprogram calls, i.e.
142 -- parameters can be given in any order if named notation is used, and
143 -- positional and named notation can be mixed, subject to the rule that all
144 -- positional parameters must appear first.
146 -- Note: All these pragmas are implemented exactly following the DEC design
147 -- and implementation and are intended to be fully compatible with the use
148 -- of these pragmas in the DEC Ada compiler.
150 --------------------------------------------
151 -- Checking for Duplicated External Names --
152 --------------------------------------------
154 -- It is suspicious if two separate Export pragmas use the same external
155 -- name. The following table is used to diagnose this situation so that
156 -- an appropriate warning can be issued.
158 -- The Node_Id stored is for the N_String_Literal node created to hold
159 -- the value of the external name. The Sloc of this node is used to
160 -- cross-reference the location of the duplication.
162 package Externals is new Table.Table (
163 Table_Component_Type => Node_Id,
164 Table_Index_Type => Int,
165 Table_Low_Bound => 0,
166 Table_Initial => 100,
167 Table_Increment => 100,
168 Table_Name => "Name_Externals");
170 -------------------------------------
171 -- Local Subprograms and Variables --
172 -------------------------------------
174 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
175 -- This routine is used for possible casing adjustment of an explicit
176 -- external name supplied as a string literal (the node N), according to
177 -- the casing requirement of Opt.External_Name_Casing. If this is set to
178 -- As_Is, then the string literal is returned unchanged, but if it is set
179 -- to Uppercase or Lowercase, then a new string literal with appropriate
180 -- casing is constructed.
182 procedure Analyze_Part_Of
186 Encap_Id : out Entity_Id;
187 Legal : out Boolean);
188 -- Subsidiary to Analyze_Part_Of_In_Decl_Part, Analyze_Part_Of_Option and
189 -- Analyze_Pragma. Perform full analysis of indicator Part_Of. Indic is the
190 -- Part_Of indicator. Item_Id is the entity of an abstract state, object or
191 -- package instantiation. Encap denotes the encapsulating state or single
192 -- concurrent type. Encap_Id is the entity of Encap. Flag Legal is set when
193 -- the indicator is legal.
195 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
196 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
197 -- Query whether a particular item appears in a mixed list of nodes and
198 -- entities. It is assumed that all nodes in the list have entities.
200 procedure Check_Postcondition_Use_In_Inlined_Subprogram
202 Spec_Id : Entity_Id);
203 -- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition,
204 -- Precondition, Refined_Post, and Test_Case. Emit a warning when pragma
205 -- Prag is associated with subprogram Spec_Id subject to Inline_Always,
206 -- and assertions are enabled.
208 procedure Check_State_And_Constituent_Use
212 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
213 -- Global and Initializes. Determine whether a state from list States and a
214 -- corresponding constituent from list Constits (if any) appear in the same
215 -- context denoted by Context. If this is the case, emit an error.
217 procedure Contract_Freeze_Error
218 (Contract_Id : Entity_Id;
219 Freeze_Id : Entity_Id);
220 -- Subsidiary to the analysis of pragmas Contract_Cases, Part_Of, Post, and
221 -- Pre. Emit a freezing-related error message where Freeze_Id is the entity
222 -- of a body which caused contract freezing and Contract_Id denotes the
223 -- entity of the affected contstruct.
225 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id);
226 -- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma
227 -- Prag that duplicates previous pragma Prev.
229 function Find_Encapsulating_State
231 Constit_Id : Entity_Id) return Entity_Id;
232 -- Given the entity of a constituent Constit_Id, find the corresponding
233 -- encapsulating state which appears in States. The routine returns Empty
234 -- if no such state is found.
236 function Find_Related_Context
238 Do_Checks : Boolean := False) return Node_Id;
239 -- Subsidiary to the analysis of pragmas
242 -- Constant_After_Elaboration
246 -- Find the first source declaration or statement found while traversing
247 -- the previous node chain starting from pragma Prag. If flag Do_Checks is
248 -- set, the routine reports duplicate pragmas. The routine returns Empty
249 -- when reaching the start of the node chain.
251 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
252 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
253 -- original one, following the renaming chain) is returned. Otherwise the
254 -- entity is returned unchanged. Should be in Einfo???
256 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
257 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
258 -- Get_SPARK_Mode_From_Annotation. Convert a name into a corresponding
259 -- value of type SPARK_Mode_Type.
261 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
262 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
263 -- Determine whether dependency clause Clause is surrounded by extra
264 -- parentheses. If this is the case, issue an error message.
266 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
267 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
268 -- pragma Depends. Determine whether the type of dependency item Item is
269 -- tagged, unconstrained array, unconstrained record or a record with at
270 -- least one unconstrained component.
272 procedure Record_Possible_Body_Reference
273 (State_Id : Entity_Id;
275 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
276 -- Global. Given an abstract state denoted by State_Id and a reference Ref
277 -- to it, determine whether the reference appears in a package body that
278 -- will eventually refine the state. If this is the case, record the
279 -- reference for future checks (see Analyze_Refined_State_In_Decls).
281 procedure Resolve_State (N : Node_Id);
282 -- Handle the overloading of state names by functions. When N denotes a
283 -- function, this routine finds the corresponding state and sets the entity
284 -- of N to that of the state.
286 procedure Rewrite_Assertion_Kind
288 From_Policy : Boolean := False);
289 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
290 -- then it is rewritten as an identifier with the corresponding special
291 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
292 -- and Check_Policy. If the names are Precondition or Postcondition, this
293 -- combination is deprecated in favor of Assertion_Policy and Ada2012
294 -- Aspect names. The parameter From_Policy indicates that the pragma
295 -- is the old non-standard Check_Policy and not a rewritten pragma.
297 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id);
298 -- Place semantic information on the argument of an Elaborate/Elaborate_All
299 -- pragma. Entity name for unit and its parents is taken from item in
300 -- previous with_clause that mentions the unit.
302 procedure Validate_Compile_Time_Warning_Or_Error
305 -- Common processing for Compile_Time_Error and Compile_Time_Warning of
306 -- pragma N. Called when the pragma is processed as part of its regular
307 -- analysis but also called after calling the back end to validate these
308 -- pragmas for size and alignment appropriateness.
310 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id);
311 -- N is a pragma Compile_Time_Error or Compile_Warning_Error whose boolean
312 -- expression is not known at compile time during the front end. This
313 -- procedure makes an entry in a table. The actual checking is performed by
314 -- Validate_Compile_Time_Warning_Errors, which is invoked after calling the
317 Dummy : Integer := 0;
318 pragma Volatile (Dummy);
319 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
322 pragma No_Inline (ip);
323 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
324 -- is just to help debugging the front end. If a pragma Inspection_Point
325 -- is added to a source program, then breaking on ip will get you to that
326 -- point in the program.
329 pragma No_Inline (rv);
330 -- This is a dummy function called by the processing for pragma Reviewable.
331 -- It is there for assisting front end debugging. By placing a Reviewable
332 -- pragma in the source program, a breakpoint on rv catches this place in
333 -- the source, allowing convenient stepping to the point of interest.
335 ------------------------------------------------------
336 -- Table for Defer_Compile_Time_Warning_Error_To_BE --
337 ------------------------------------------------------
339 -- The following table collects pragmas Compile_Time_Error and Compile_
340 -- Time_Warning for validation. Entries are made by calls to subprogram
341 -- Defer_Compile_Time_Warning_Error_To_BE, and the call to the procedure
342 -- Validate_Compile_Time_Warning_Errors does the actual error checking
343 -- and posting of warning and error messages. The reason for this delayed
344 -- processing is to take advantage of back-annotations of attributes size
345 -- and alignment values performed by the back end.
347 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
348 -- that by the time Validate_Compile_Time_Warning_Errors is called, Sprint
349 -- will already have modified all Sloc values if the -gnatD option is set.
351 type CTWE_Entry is record
353 -- Source location used in warnings and error messages
356 -- Pragma Compile_Time_Error or Compile_Time_Warning
359 -- The scope which encloses the pragma
362 package Compile_Time_Warnings_Errors is new Table.Table (
363 Table_Component_Type => CTWE_Entry,
364 Table_Index_Type => Int,
365 Table_Low_Bound => 1,
367 Table_Increment => 200,
368 Table_Name => "Compile_Time_Warnings_Errors");
370 -------------------------------
371 -- Adjust_External_Name_Case --
372 -------------------------------
374 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
378 -- Adjust case of literal if required
380 if Opt.External_Name_Exp_Casing = As_Is then
384 -- Copy existing string
390 for J in 1 .. String_Length (Strval (N)) loop
391 CC := Get_String_Char (Strval (N), J);
393 if Opt.External_Name_Exp_Casing = Uppercase
394 and then CC >= Get_Char_Code ('a')
395 and then CC <= Get_Char_Code ('z')
397 Store_String_Char (CC - 32);
399 elsif Opt.External_Name_Exp_Casing = Lowercase
400 and then CC >= Get_Char_Code ('A')
401 and then CC <= Get_Char_Code ('Z')
403 Store_String_Char (CC + 32);
406 Store_String_Char (CC);
411 Make_String_Literal (Sloc (N),
412 Strval => End_String);
414 end Adjust_External_Name_Case;
416 -----------------------------------------
417 -- Analyze_Contract_Cases_In_Decl_Part --
418 -----------------------------------------
420 -- WARNING: This routine manages Ghost regions. Return statements must be
421 -- replaced by gotos which jump to the end of the routine and restore the
424 procedure Analyze_Contract_Cases_In_Decl_Part
426 Freeze_Id : Entity_Id := Empty)
428 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
429 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
431 Others_Seen : Boolean := False;
432 -- This flag is set when an "others" choice is encountered. It is used
433 -- to detect multiple illegal occurrences of "others".
435 procedure Analyze_Contract_Case (CCase : Node_Id);
436 -- Verify the legality of a single contract case
438 ---------------------------
439 -- Analyze_Contract_Case --
440 ---------------------------
442 procedure Analyze_Contract_Case (CCase : Node_Id) is
443 Case_Guard : Node_Id;
446 Extra_Guard : Node_Id;
449 if Nkind (CCase) = N_Component_Association then
450 Case_Guard := First (Choices (CCase));
451 Conseq := Expression (CCase);
453 -- Each contract case must have exactly one case guard
455 Extra_Guard := Next (Case_Guard);
457 if Present (Extra_Guard) then
459 ("contract case must have exactly one case guard",
463 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
465 if Nkind (Case_Guard) = N_Others_Choice then
468 ("only one others choice allowed in contract cases",
474 elsif Others_Seen then
476 ("others must be the last choice in contract cases", N);
479 -- Preanalyze the case guard and consequence
481 if Nkind (Case_Guard) /= N_Others_Choice then
482 Errors := Serious_Errors_Detected;
483 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
485 -- Emit a clarification message when the case guard contains
486 -- at least one undefined reference, possibly due to contract
489 if Errors /= Serious_Errors_Detected
490 and then Present (Freeze_Id)
491 and then Has_Undefined_Reference (Case_Guard)
493 Contract_Freeze_Error (Spec_Id, Freeze_Id);
497 Errors := Serious_Errors_Detected;
498 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
500 -- Emit a clarification message when the consequence contains
501 -- at least one undefined reference, possibly due to contract
504 if Errors /= Serious_Errors_Detected
505 and then Present (Freeze_Id)
506 and then Has_Undefined_Reference (Conseq)
508 Contract_Freeze_Error (Spec_Id, Freeze_Id);
511 -- The contract case is malformed
514 Error_Msg_N ("wrong syntax in contract case", CCase);
516 end Analyze_Contract_Case;
520 CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
522 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
523 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
524 -- Save the Ghost-related attributes to restore on exit
527 Restore_Scope : Boolean := False;
529 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
532 -- Do not analyze the pragma multiple times
534 if Is_Analyzed_Pragma (N) then
538 -- Set the Ghost mode in effect from the pragma. Due to the delayed
539 -- analysis of the pragma, the Ghost mode at point of declaration and
540 -- point of analysis may not necessarily be the same. Use the mode in
541 -- effect at the point of declaration.
545 -- Single and multiple contract cases must appear in aggregate form. If
546 -- this is not the case, then either the parser of the analysis of the
547 -- pragma failed to produce an aggregate.
549 pragma Assert (Nkind (CCases) = N_Aggregate);
551 if Present (Component_Associations (CCases)) then
553 -- Ensure that the formal parameters are visible when analyzing all
554 -- clauses. This falls out of the general rule of aspects pertaining
555 -- to subprogram declarations.
557 if not In_Open_Scopes (Spec_Id) then
558 Restore_Scope := True;
559 Push_Scope (Spec_Id);
561 if Is_Generic_Subprogram (Spec_Id) then
562 Install_Generic_Formals (Spec_Id);
564 Install_Formals (Spec_Id);
568 CCase := First (Component_Associations (CCases));
569 while Present (CCase) loop
570 Analyze_Contract_Case (CCase);
574 if Restore_Scope then
578 -- Currently it is not possible to inline pre/postconditions on a
579 -- subprogram subject to pragma Inline_Always.
581 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
583 -- Otherwise the pragma is illegal
586 Error_Msg_N ("wrong syntax for constract cases", N);
589 Set_Is_Analyzed_Pragma (N);
591 Restore_Ghost_Region (Saved_GM, Saved_IGR);
592 end Analyze_Contract_Cases_In_Decl_Part;
594 ----------------------------------
595 -- Analyze_Depends_In_Decl_Part --
596 ----------------------------------
598 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
599 Loc : constant Source_Ptr := Sloc (N);
600 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
601 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
603 All_Inputs_Seen : Elist_Id := No_Elist;
604 -- A list containing the entities of all the inputs processed so far.
605 -- The list is populated with unique entities because the same input
606 -- may appear in multiple input lists.
608 All_Outputs_Seen : Elist_Id := No_Elist;
609 -- A list containing the entities of all the outputs processed so far.
610 -- The list is populated with unique entities because output items are
611 -- unique in a dependence relation.
613 Constits_Seen : Elist_Id := No_Elist;
614 -- A list containing the entities of all constituents processed so far.
615 -- It aids in detecting illegal usage of a state and a corresponding
616 -- constituent in pragma [Refinde_]Depends.
618 Global_Seen : Boolean := False;
619 -- A flag set when pragma Global has been processed
621 Null_Output_Seen : Boolean := False;
622 -- A flag used to track the legality of a null output
624 Result_Seen : Boolean := False;
625 -- A flag set when Spec_Id'Result is processed
627 States_Seen : Elist_Id := No_Elist;
628 -- A list containing the entities of all states processed so far. It
629 -- helps in detecting illegal usage of a state and a corresponding
630 -- constituent in pragma [Refined_]Depends.
632 Subp_Inputs : Elist_Id := No_Elist;
633 Subp_Outputs : Elist_Id := No_Elist;
634 -- Two lists containing the full set of inputs and output of the related
635 -- subprograms. Note that these lists contain both nodes and entities.
637 Task_Input_Seen : Boolean := False;
638 Task_Output_Seen : Boolean := False;
639 -- Flags used to track the implicit dependence of a task unit on itself
641 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
642 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
643 -- to the name buffer. The individual kinds are as follows:
644 -- E_Abstract_State - "state"
645 -- E_Constant - "constant"
646 -- E_Generic_In_Out_Parameter - "generic parameter"
647 -- E_Generic_In_Parameter - "generic parameter"
648 -- E_In_Parameter - "parameter"
649 -- E_In_Out_Parameter - "parameter"
650 -- E_Loop_Parameter - "loop parameter"
651 -- E_Out_Parameter - "parameter"
652 -- E_Protected_Type - "current instance of protected type"
653 -- E_Task_Type - "current instance of task type"
654 -- E_Variable - "global"
656 procedure Analyze_Dependency_Clause
659 -- Verify the legality of a single dependency clause. Flag Is_Last
660 -- denotes whether Clause is the last clause in the relation.
662 procedure Check_Function_Return;
663 -- Verify that Funtion'Result appears as one of the outputs
664 -- (SPARK RM 6.1.5(10)).
671 -- Ensure that an item fulfills its designated input and/or output role
672 -- as specified by pragma Global (if any) or the enclosing context. If
673 -- this is not the case, emit an error. Item and Item_Id denote the
674 -- attributes of an item. Flag Is_Input should be set when item comes
675 -- from an input list. Flag Self_Ref should be set when the item is an
676 -- output and the dependency clause has operator "+".
678 procedure Check_Usage
679 (Subp_Items : Elist_Id;
680 Used_Items : Elist_Id;
682 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
683 -- error if this is not the case.
685 procedure Normalize_Clause (Clause : Node_Id);
686 -- Remove a self-dependency "+" from the input list of a clause
688 -----------------------------
689 -- Add_Item_To_Name_Buffer --
690 -----------------------------
692 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
694 if Ekind (Item_Id) = E_Abstract_State then
695 Add_Str_To_Name_Buffer ("state");
697 elsif Ekind (Item_Id) = E_Constant then
698 Add_Str_To_Name_Buffer ("constant");
700 elsif Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
701 E_Generic_In_Parameter)
703 Add_Str_To_Name_Buffer ("generic parameter");
705 elsif Is_Formal (Item_Id) then
706 Add_Str_To_Name_Buffer ("parameter");
708 elsif Ekind (Item_Id) = E_Loop_Parameter then
709 Add_Str_To_Name_Buffer ("loop parameter");
711 elsif Ekind (Item_Id) = E_Protected_Type
712 or else Is_Single_Protected_Object (Item_Id)
714 Add_Str_To_Name_Buffer ("current instance of protected type");
716 elsif Ekind (Item_Id) = E_Task_Type
717 or else Is_Single_Task_Object (Item_Id)
719 Add_Str_To_Name_Buffer ("current instance of task type");
721 elsif Ekind (Item_Id) = E_Variable then
722 Add_Str_To_Name_Buffer ("global");
724 -- The routine should not be called with non-SPARK items
729 end Add_Item_To_Name_Buffer;
731 -------------------------------
732 -- Analyze_Dependency_Clause --
733 -------------------------------
735 procedure Analyze_Dependency_Clause
739 procedure Analyze_Input_List (Inputs : Node_Id);
740 -- Verify the legality of a single input list
742 procedure Analyze_Input_Output
747 Seen : in out Elist_Id;
748 Null_Seen : in out Boolean;
749 Non_Null_Seen : in out Boolean);
750 -- Verify the legality of a single input or output item. Flag
751 -- Is_Input should be set whenever Item is an input, False when it
752 -- denotes an output. Flag Self_Ref should be set when the item is an
753 -- output and the dependency clause has a "+". Flag Top_Level should
754 -- be set whenever Item appears immediately within an input or output
755 -- list. Seen is a collection of all abstract states, objects and
756 -- formals processed so far. Flag Null_Seen denotes whether a null
757 -- input or output has been encountered. Flag Non_Null_Seen denotes
758 -- whether a non-null input or output has been encountered.
760 ------------------------
761 -- Analyze_Input_List --
762 ------------------------
764 procedure Analyze_Input_List (Inputs : Node_Id) is
765 Inputs_Seen : Elist_Id := No_Elist;
766 -- A list containing the entities of all inputs that appear in the
767 -- current input list.
769 Non_Null_Input_Seen : Boolean := False;
770 Null_Input_Seen : Boolean := False;
771 -- Flags used to check the legality of an input list
776 -- Multiple inputs appear as an aggregate
778 if Nkind (Inputs) = N_Aggregate then
779 if Present (Component_Associations (Inputs)) then
781 ("nested dependency relations not allowed", Inputs);
783 elsif Present (Expressions (Inputs)) then
784 Input := First (Expressions (Inputs));
785 while Present (Input) loop
792 Null_Seen => Null_Input_Seen,
793 Non_Null_Seen => Non_Null_Input_Seen);
798 -- Syntax error, always report
801 Error_Msg_N ("malformed input dependency list", Inputs);
804 -- Process a solitary input
813 Null_Seen => Null_Input_Seen,
814 Non_Null_Seen => Non_Null_Input_Seen);
817 -- Detect an illegal dependency clause of the form
821 if Null_Output_Seen and then Null_Input_Seen then
823 ("null dependency clause cannot have a null input list",
826 end Analyze_Input_List;
828 --------------------------
829 -- Analyze_Input_Output --
830 --------------------------
832 procedure Analyze_Input_Output
837 Seen : in out Elist_Id;
838 Null_Seen : in out Boolean;
839 Non_Null_Seen : in out Boolean)
841 procedure Current_Task_Instance_Seen;
842 -- Set the appropriate global flag when the current instance of a
843 -- task unit is encountered.
845 --------------------------------
846 -- Current_Task_Instance_Seen --
847 --------------------------------
849 procedure Current_Task_Instance_Seen is
852 Task_Input_Seen := True;
854 Task_Output_Seen := True;
856 end Current_Task_Instance_Seen;
860 Is_Output : constant Boolean := not Is_Input;
864 -- Start of processing for Analyze_Input_Output
867 -- Multiple input or output items appear as an aggregate
869 if Nkind (Item) = N_Aggregate then
870 if not Top_Level then
871 SPARK_Msg_N ("nested grouping of items not allowed", Item);
873 elsif Present (Component_Associations (Item)) then
875 ("nested dependency relations not allowed", Item);
877 -- Recursively analyze the grouped items
879 elsif Present (Expressions (Item)) then
880 Grouped := First (Expressions (Item));
881 while Present (Grouped) loop
884 Is_Input => Is_Input,
885 Self_Ref => Self_Ref,
888 Null_Seen => Null_Seen,
889 Non_Null_Seen => Non_Null_Seen);
894 -- Syntax error, always report
897 Error_Msg_N ("malformed dependency list", Item);
900 -- Process attribute 'Result in the context of a dependency clause
902 elsif Is_Attribute_Result (Item) then
903 Non_Null_Seen := True;
907 -- Attribute 'Result is allowed to appear on the output side of
908 -- a dependency clause (SPARK RM 6.1.5(6)).
911 SPARK_Msg_N ("function result cannot act as input", Item);
915 ("cannot mix null and non-null dependency items", Item);
921 -- Detect multiple uses of null in a single dependency list or
922 -- throughout the whole relation. Verify the placement of a null
923 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
925 elsif Nkind (Item) = N_Null then
928 ("multiple null dependency relations not allowed", Item);
930 elsif Non_Null_Seen then
932 ("cannot mix null and non-null dependency items", Item);
940 ("null output list must be the last clause in a "
941 & "dependency relation", Item);
943 -- Catch a useless dependence of the form:
948 ("useless dependence, null depends on itself", Item);
956 Non_Null_Seen := True;
959 SPARK_Msg_N ("cannot mix null and non-null items", Item);
963 Resolve_State (Item);
965 -- Find the entity of the item. If this is a renaming, climb
966 -- the renaming chain to reach the root object. Renamings of
967 -- non-entire objects do not yield an entity (Empty).
969 Item_Id := Entity_Of (Item);
971 if Present (Item_Id) then
975 if Ekind_In (Item_Id, E_Constant, E_Loop_Parameter)
978 -- Current instances of concurrent types
980 Ekind_In (Item_Id, E_Protected_Type, E_Task_Type)
985 Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
986 E_Generic_In_Parameter,
994 Ekind_In (Item_Id, E_Abstract_State, E_Variable)
996 -- A [generic] function is not allowed to have Output
997 -- items in its dependency relations. Note that "null"
998 -- and attribute 'Result are still valid items.
1000 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
1001 and then not Is_Input
1004 ("output item is not applicable to function", Item);
1007 -- The item denotes a concurrent type. Note that single
1008 -- protected/task types are not considered here because
1009 -- they behave as objects in the context of pragma
1010 -- [Refined_]Depends.
1012 if Ekind_In (Item_Id, E_Protected_Type, E_Task_Type) then
1014 -- This use is legal as long as the concurrent type is
1015 -- the current instance of an enclosing type.
1017 if Is_CCT_Instance (Item_Id, Spec_Id) then
1019 -- The dependence of a task unit on itself is
1020 -- implicit and may or may not be explicitly
1021 -- specified (SPARK RM 6.1.4).
1023 if Ekind (Item_Id) = E_Task_Type then
1024 Current_Task_Instance_Seen;
1027 -- Otherwise this is not the current instance
1031 ("invalid use of subtype mark in dependency "
1032 & "relation", Item);
1035 -- The dependency of a task unit on itself is implicit
1036 -- and may or may not be explicitly specified
1037 -- (SPARK RM 6.1.4).
1039 elsif Is_Single_Task_Object (Item_Id)
1040 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
1042 Current_Task_Instance_Seen;
1045 -- Ensure that the item fulfills its role as input and/or
1046 -- output as specified by pragma Global or the enclosing
1049 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
1051 -- Detect multiple uses of the same state, variable or
1052 -- formal parameter. If this is not the case, add the
1053 -- item to the list of processed relations.
1055 if Contains (Seen, Item_Id) then
1057 ("duplicate use of item &", Item, Item_Id);
1059 Append_New_Elmt (Item_Id, Seen);
1062 -- Detect illegal use of an input related to a null
1063 -- output. Such input items cannot appear in other
1064 -- input lists (SPARK RM 6.1.5(13)).
1067 and then Null_Output_Seen
1068 and then Contains (All_Inputs_Seen, Item_Id)
1071 ("input of a null output list cannot appear in "
1072 & "multiple input lists", Item);
1075 -- Add an input or a self-referential output to the list
1076 -- of all processed inputs.
1078 if Is_Input or else Self_Ref then
1079 Append_New_Elmt (Item_Id, All_Inputs_Seen);
1082 -- State related checks (SPARK RM 6.1.5(3))
1084 if Ekind (Item_Id) = E_Abstract_State then
1086 -- Package and subprogram bodies are instantiated
1087 -- individually in a separate compiler pass. Due to
1088 -- this mode of instantiation, the refinement of a
1089 -- state may no longer be visible when a subprogram
1090 -- body contract is instantiated. Since the generic
1091 -- template is legal, do not perform this check in
1092 -- the instance to circumvent this oddity.
1097 -- An abstract state with visible refinement cannot
1098 -- appear in pragma [Refined_]Depends as its place
1099 -- must be taken by some of its constituents
1100 -- (SPARK RM 6.1.4(7)).
1102 elsif Has_Visible_Refinement (Item_Id) then
1104 ("cannot mention state & in dependence relation",
1106 SPARK_Msg_N ("\use its constituents instead", Item);
1109 -- If the reference to the abstract state appears in
1110 -- an enclosing package body that will eventually
1111 -- refine the state, record the reference for future
1115 Record_Possible_Body_Reference
1116 (State_Id => Item_Id,
1121 -- When the item renames an entire object, replace the
1122 -- item with a reference to the object.
1124 if Entity (Item) /= Item_Id then
1126 New_Occurrence_Of (Item_Id, Sloc (Item)));
1130 -- Add the entity of the current item to the list of
1133 if Ekind (Item_Id) = E_Abstract_State then
1134 Append_New_Elmt (Item_Id, States_Seen);
1136 -- The variable may eventually become a constituent of a
1137 -- single protected/task type. Record the reference now
1138 -- and verify its legality when analyzing the contract of
1139 -- the variable (SPARK RM 9.3).
1141 elsif Ekind (Item_Id) = E_Variable then
1142 Record_Possible_Part_Of_Reference
1147 if Ekind_In (Item_Id, E_Abstract_State,
1150 and then Present (Encapsulating_State (Item_Id))
1152 Append_New_Elmt (Item_Id, Constits_Seen);
1155 -- All other input/output items are illegal
1156 -- (SPARK RM 6.1.5(1)).
1160 ("item must denote parameter, variable, state or "
1161 & "current instance of concurrent type", Item);
1164 -- All other input/output items are illegal
1165 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1169 ("item must denote parameter, variable, state or current "
1170 & "instance of concurrent type", Item);
1173 end Analyze_Input_Output;
1181 Non_Null_Output_Seen : Boolean := False;
1182 -- Flag used to check the legality of an output list
1184 -- Start of processing for Analyze_Dependency_Clause
1187 Inputs := Expression (Clause);
1190 -- An input list with a self-dependency appears as operator "+" where
1191 -- the actuals inputs are the right operand.
1193 if Nkind (Inputs) = N_Op_Plus then
1194 Inputs := Right_Opnd (Inputs);
1198 -- Process the output_list of a dependency_clause
1200 Output := First (Choices (Clause));
1201 while Present (Output) loop
1202 Analyze_Input_Output
1205 Self_Ref => Self_Ref,
1207 Seen => All_Outputs_Seen,
1208 Null_Seen => Null_Output_Seen,
1209 Non_Null_Seen => Non_Null_Output_Seen);
1214 -- Process the input_list of a dependency_clause
1216 Analyze_Input_List (Inputs);
1217 end Analyze_Dependency_Clause;
1219 ---------------------------
1220 -- Check_Function_Return --
1221 ---------------------------
1223 procedure Check_Function_Return is
1225 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
1226 and then not Result_Seen
1229 ("result of & must appear in exactly one output list",
1232 end Check_Function_Return;
1238 procedure Check_Role
1240 Item_Id : Entity_Id;
1245 (Item_Is_Input : out Boolean;
1246 Item_Is_Output : out Boolean);
1247 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1248 -- Item_Is_Output are set depending on the role.
1250 procedure Role_Error
1251 (Item_Is_Input : Boolean;
1252 Item_Is_Output : Boolean);
1253 -- Emit an error message concerning the incorrect use of Item in
1254 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1255 -- denote whether the item is an input and/or an output.
1262 (Item_Is_Input : out Boolean;
1263 Item_Is_Output : out Boolean)
1265 -- A constant or IN parameter of access type should be handled
1266 -- like a variable, as the underlying memory pointed-to can be
1267 -- modified. Use Adjusted_Kind to do this adjustment.
1269 Adjusted_Kind : Entity_Kind := Ekind (Item_Id);
1272 if Ekind_In (Item_Id, E_Constant,
1273 E_Generic_In_Parameter,
1275 and then Is_Access_Type (Etype (Item_Id))
1277 Adjusted_Kind := E_Variable;
1280 case Adjusted_Kind is
1284 when E_Abstract_State =>
1286 -- When pragma Global is present it determines the mode of
1287 -- the abstract state.
1290 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1291 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1293 -- Otherwise the state has a default IN OUT mode, because it
1294 -- behaves as a variable.
1297 Item_Is_Input := True;
1298 Item_Is_Output := True;
1301 -- Constants and IN parameters
1304 | E_Generic_In_Parameter
1308 -- When pragma Global is present it determines the mode
1309 -- of constant objects as inputs (and such objects cannot
1310 -- appear as outputs in the Global contract).
1313 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1315 Item_Is_Input := True;
1318 Item_Is_Output := False;
1320 -- Variables and IN OUT parameters, as well as constants and
1321 -- IN parameters of access type which are handled like
1324 when E_Generic_In_Out_Parameter
1325 | E_In_Out_Parameter
1328 -- When pragma Global is present it determines the mode of
1333 -- A variable has mode IN when its type is unconstrained
1334 -- or tagged because array bounds, discriminants or tags
1338 Appears_In (Subp_Inputs, Item_Id)
1339 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1341 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1343 -- Otherwise the variable has a default IN OUT mode
1346 Item_Is_Input := True;
1347 Item_Is_Output := True;
1350 when E_Out_Parameter =>
1352 -- An OUT parameter of the related subprogram; it cannot
1353 -- appear in Global.
1355 if Scope (Item_Id) = Spec_Id then
1357 -- The parameter has mode IN if its type is unconstrained
1358 -- or tagged because array bounds, discriminants or tags
1362 Is_Unconstrained_Or_Tagged_Item (Item_Id);
1364 Item_Is_Output := True;
1366 -- An OUT parameter of an enclosing subprogram; it can
1367 -- appear in Global and behaves as a read-write variable.
1370 -- When pragma Global is present it determines the mode
1375 -- A variable has mode IN when its type is
1376 -- unconstrained or tagged because array
1377 -- bounds, discriminants or tags can be read.
1380 Appears_In (Subp_Inputs, Item_Id)
1381 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1383 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1385 -- Otherwise the variable has a default IN OUT mode
1388 Item_Is_Input := True;
1389 Item_Is_Output := True;
1395 when E_Protected_Type =>
1398 -- A variable has mode IN when its type is unconstrained
1399 -- or tagged because array bounds, discriminants or tags
1403 Appears_In (Subp_Inputs, Item_Id)
1404 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1406 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1409 -- A protected type acts as a formal parameter of mode IN
1410 -- when it applies to a protected function.
1412 if Ekind (Spec_Id) = E_Function then
1413 Item_Is_Input := True;
1414 Item_Is_Output := False;
1416 -- Otherwise the protected type acts as a formal of mode
1420 Item_Is_Input := True;
1421 Item_Is_Output := True;
1429 -- When pragma Global is present it determines the mode of
1434 Appears_In (Subp_Inputs, Item_Id)
1435 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1437 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1439 -- Otherwise task types act as IN OUT parameters
1442 Item_Is_Input := True;
1443 Item_Is_Output := True;
1447 raise Program_Error;
1455 procedure Role_Error
1456 (Item_Is_Input : Boolean;
1457 Item_Is_Output : Boolean)
1459 Error_Msg : Name_Id;
1464 -- When the item is not part of the input and the output set of
1465 -- the related subprogram, then it appears as extra in pragma
1466 -- [Refined_]Depends.
1468 if not Item_Is_Input and then not Item_Is_Output then
1469 Add_Item_To_Name_Buffer (Item_Id);
1470 Add_Str_To_Name_Buffer
1471 (" & cannot appear in dependence relation");
1473 Error_Msg := Name_Find;
1474 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1476 Error_Msg_Name_1 := Chars (Spec_Id);
1478 (Fix_Msg (Spec_Id, "\& is not part of the input or output "
1479 & "set of subprogram %"), Item, Item_Id);
1481 -- The mode of the item and its role in pragma [Refined_]Depends
1482 -- are in conflict. Construct a detailed message explaining the
1483 -- illegality (SPARK RM 6.1.5(5-6)).
1486 if Item_Is_Input then
1487 Add_Str_To_Name_Buffer ("read-only");
1489 Add_Str_To_Name_Buffer ("write-only");
1492 Add_Char_To_Name_Buffer (' ');
1493 Add_Item_To_Name_Buffer (Item_Id);
1494 Add_Str_To_Name_Buffer (" & cannot appear as ");
1496 if Item_Is_Input then
1497 Add_Str_To_Name_Buffer ("output");
1499 Add_Str_To_Name_Buffer ("input");
1502 Add_Str_To_Name_Buffer (" in dependence relation");
1503 Error_Msg := Name_Find;
1504 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1510 Item_Is_Input : Boolean;
1511 Item_Is_Output : Boolean;
1513 -- Start of processing for Check_Role
1516 Find_Role (Item_Is_Input, Item_Is_Output);
1521 if not Item_Is_Input then
1522 Role_Error (Item_Is_Input, Item_Is_Output);
1525 -- Self-referential item
1528 if not Item_Is_Input or else not Item_Is_Output then
1529 Role_Error (Item_Is_Input, Item_Is_Output);
1534 elsif not Item_Is_Output then
1535 Role_Error (Item_Is_Input, Item_Is_Output);
1543 procedure Check_Usage
1544 (Subp_Items : Elist_Id;
1545 Used_Items : Elist_Id;
1548 procedure Usage_Error (Item_Id : Entity_Id);
1549 -- Emit an error concerning the illegal usage of an item
1555 procedure Usage_Error (Item_Id : Entity_Id) is
1556 Error_Msg : Name_Id;
1563 -- Unconstrained and tagged items are not part of the explicit
1564 -- input set of the related subprogram, they do not have to be
1565 -- present in a dependence relation and should not be flagged
1566 -- (SPARK RM 6.1.5(5)).
1568 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1571 Add_Item_To_Name_Buffer (Item_Id);
1572 Add_Str_To_Name_Buffer
1573 (" & is missing from input dependence list");
1575 Error_Msg := Name_Find;
1576 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1578 ("\add `null ='> &` dependency to ignore this input",
1582 -- Output case (SPARK RM 6.1.5(10))
1587 Add_Item_To_Name_Buffer (Item_Id);
1588 Add_Str_To_Name_Buffer
1589 (" & is missing from output dependence list");
1591 Error_Msg := Name_Find;
1592 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1600 Item_Id : Entity_Id;
1602 -- Start of processing for Check_Usage
1605 if No (Subp_Items) then
1609 -- Each input or output of the subprogram must appear in a dependency
1612 Elmt := First_Elmt (Subp_Items);
1613 while Present (Elmt) loop
1614 Item := Node (Elmt);
1616 if Nkind (Item) = N_Defining_Identifier then
1619 Item_Id := Entity_Of (Item);
1622 -- The item does not appear in a dependency
1624 if Present (Item_Id)
1625 and then not Contains (Used_Items, Item_Id)
1627 if Is_Formal (Item_Id) then
1628 Usage_Error (Item_Id);
1630 -- The current instance of a protected type behaves as a formal
1631 -- parameter (SPARK RM 6.1.4).
1633 elsif Ekind (Item_Id) = E_Protected_Type
1634 or else Is_Single_Protected_Object (Item_Id)
1636 Usage_Error (Item_Id);
1638 -- The current instance of a task type behaves as a formal
1639 -- parameter (SPARK RM 6.1.4).
1641 elsif Ekind (Item_Id) = E_Task_Type
1642 or else Is_Single_Task_Object (Item_Id)
1644 -- The dependence of a task unit on itself is implicit and
1645 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1646 -- Emit an error if only one input/output is present.
1648 if Task_Input_Seen /= Task_Output_Seen then
1649 Usage_Error (Item_Id);
1652 -- States and global objects are not used properly only when
1653 -- the subprogram is subject to pragma Global.
1655 elsif Global_Seen then
1656 Usage_Error (Item_Id);
1664 ----------------------
1665 -- Normalize_Clause --
1666 ----------------------
1668 procedure Normalize_Clause (Clause : Node_Id) is
1669 procedure Create_Or_Modify_Clause
1675 Multiple : Boolean);
1676 -- Create a brand new clause to represent the self-reference or
1677 -- modify the input and/or output lists of an existing clause. Output
1678 -- denotes a self-referencial output. Outputs is the output list of a
1679 -- clause. Inputs is the input list of a clause. After denotes the
1680 -- clause after which the new clause is to be inserted. Flag In_Place
1681 -- should be set when normalizing the last output of an output list.
1682 -- Flag Multiple should be set when Output comes from a list with
1685 -----------------------------
1686 -- Create_Or_Modify_Clause --
1687 -----------------------------
1689 procedure Create_Or_Modify_Clause
1697 procedure Propagate_Output
1700 -- Handle the various cases of output propagation to the input
1701 -- list. Output denotes a self-referencial output item. Inputs
1702 -- is the input list of a clause.
1704 ----------------------
1705 -- Propagate_Output --
1706 ----------------------
1708 procedure Propagate_Output
1712 function In_Input_List
1714 Inputs : List_Id) return Boolean;
1715 -- Determine whether a particulat item appears in the input
1716 -- list of a clause.
1722 function In_Input_List
1724 Inputs : List_Id) return Boolean
1729 Elmt := First (Inputs);
1730 while Present (Elmt) loop
1731 if Entity_Of (Elmt) = Item then
1743 Output_Id : constant Entity_Id := Entity_Of (Output);
1746 -- Start of processing for Propagate_Output
1749 -- The clause is of the form:
1751 -- (Output =>+ null)
1753 -- Remove null input and replace it with a copy of the output:
1755 -- (Output => Output)
1757 if Nkind (Inputs) = N_Null then
1758 Rewrite (Inputs, New_Copy_Tree (Output));
1760 -- The clause is of the form:
1762 -- (Output =>+ (Input1, ..., InputN))
1764 -- Determine whether the output is not already mentioned in the
1765 -- input list and if not, add it to the list of inputs:
1767 -- (Output => (Output, Input1, ..., InputN))
1769 elsif Nkind (Inputs) = N_Aggregate then
1770 Grouped := Expressions (Inputs);
1772 if not In_Input_List
1776 Prepend_To (Grouped, New_Copy_Tree (Output));
1779 -- The clause is of the form:
1781 -- (Output =>+ Input)
1783 -- If the input does not mention the output, group the two
1786 -- (Output => (Output, Input))
1788 elsif Entity_Of (Inputs) /= Output_Id then
1790 Make_Aggregate (Loc,
1791 Expressions => New_List (
1792 New_Copy_Tree (Output),
1793 New_Copy_Tree (Inputs))));
1795 end Propagate_Output;
1799 Loc : constant Source_Ptr := Sloc (Clause);
1800 New_Clause : Node_Id;
1802 -- Start of processing for Create_Or_Modify_Clause
1805 -- A null output depending on itself does not require any
1808 if Nkind (Output) = N_Null then
1811 -- A function result cannot depend on itself because it cannot
1812 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1814 elsif Is_Attribute_Result (Output) then
1815 SPARK_Msg_N ("function result cannot depend on itself", Output);
1819 -- When performing the transformation in place, simply add the
1820 -- output to the list of inputs (if not already there). This
1821 -- case arises when dealing with the last output of an output
1822 -- list. Perform the normalization in place to avoid generating
1823 -- a malformed tree.
1826 Propagate_Output (Output, Inputs);
1828 -- A list with multiple outputs is slowly trimmed until only
1829 -- one element remains. When this happens, replace aggregate
1830 -- with the element itself.
1834 Rewrite (Outputs, Output);
1840 -- Unchain the output from its output list as it will appear in
1841 -- a new clause. Note that we cannot simply rewrite the output
1842 -- as null because this will violate the semantics of pragma
1847 -- Generate a new clause of the form:
1848 -- (Output => Inputs)
1851 Make_Component_Association (Loc,
1852 Choices => New_List (Output),
1853 Expression => New_Copy_Tree (Inputs));
1855 -- The new clause contains replicated content that has already
1856 -- been analyzed. There is not need to reanalyze or renormalize
1859 Set_Analyzed (New_Clause);
1862 (Output => First (Choices (New_Clause)),
1863 Inputs => Expression (New_Clause));
1865 Insert_After (After, New_Clause);
1867 end Create_Or_Modify_Clause;
1871 Outputs : constant Node_Id := First (Choices (Clause));
1873 Last_Output : Node_Id;
1874 Next_Output : Node_Id;
1877 -- Start of processing for Normalize_Clause
1880 -- A self-dependency appears as operator "+". Remove the "+" from the
1881 -- tree by moving the real inputs to their proper place.
1883 if Nkind (Expression (Clause)) = N_Op_Plus then
1884 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1885 Inputs := Expression (Clause);
1887 -- Multiple outputs appear as an aggregate
1889 if Nkind (Outputs) = N_Aggregate then
1890 Last_Output := Last (Expressions (Outputs));
1892 Output := First (Expressions (Outputs));
1893 while Present (Output) loop
1895 -- Normalization may remove an output from its list,
1896 -- preserve the subsequent output now.
1898 Next_Output := Next (Output);
1900 Create_Or_Modify_Clause
1905 In_Place => Output = Last_Output,
1908 Output := Next_Output;
1914 Create_Or_Modify_Clause
1923 end Normalize_Clause;
1927 Deps : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
1928 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
1932 Last_Clause : Node_Id;
1933 Restore_Scope : Boolean := False;
1935 -- Start of processing for Analyze_Depends_In_Decl_Part
1938 -- Do not analyze the pragma multiple times
1940 if Is_Analyzed_Pragma (N) then
1944 -- Empty dependency list
1946 if Nkind (Deps) = N_Null then
1948 -- Gather all states, objects and formal parameters that the
1949 -- subprogram may depend on. These items are obtained from the
1950 -- parameter profile or pragma [Refined_]Global (if available).
1952 Collect_Subprogram_Inputs_Outputs
1953 (Subp_Id => Subp_Id,
1954 Subp_Inputs => Subp_Inputs,
1955 Subp_Outputs => Subp_Outputs,
1956 Global_Seen => Global_Seen);
1958 -- Verify that every input or output of the subprogram appear in a
1961 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1962 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1963 Check_Function_Return;
1965 -- Dependency clauses appear as component associations of an aggregate
1967 elsif Nkind (Deps) = N_Aggregate then
1969 -- Do not attempt to perform analysis of a syntactically illegal
1970 -- clause as this will lead to misleading errors.
1972 if Has_Extra_Parentheses (Deps) then
1976 if Present (Component_Associations (Deps)) then
1977 Last_Clause := Last (Component_Associations (Deps));
1979 -- Gather all states, objects and formal parameters that the
1980 -- subprogram may depend on. These items are obtained from the
1981 -- parameter profile or pragma [Refined_]Global (if available).
1983 Collect_Subprogram_Inputs_Outputs
1984 (Subp_Id => Subp_Id,
1985 Subp_Inputs => Subp_Inputs,
1986 Subp_Outputs => Subp_Outputs,
1987 Global_Seen => Global_Seen);
1989 -- When pragma [Refined_]Depends appears on a single concurrent
1990 -- type, it is relocated to the anonymous object.
1992 if Is_Single_Concurrent_Object (Spec_Id) then
1995 -- Ensure that the formal parameters are visible when analyzing
1996 -- all clauses. This falls out of the general rule of aspects
1997 -- pertaining to subprogram declarations.
1999 elsif not In_Open_Scopes (Spec_Id) then
2000 Restore_Scope := True;
2001 Push_Scope (Spec_Id);
2003 if Ekind (Spec_Id) = E_Task_Type then
2004 if Has_Discriminants (Spec_Id) then
2005 Install_Discriminants (Spec_Id);
2008 elsif Is_Generic_Subprogram (Spec_Id) then
2009 Install_Generic_Formals (Spec_Id);
2012 Install_Formals (Spec_Id);
2016 Clause := First (Component_Associations (Deps));
2017 while Present (Clause) loop
2018 Errors := Serious_Errors_Detected;
2020 -- The normalization mechanism may create extra clauses that
2021 -- contain replicated input and output names. There is no need
2022 -- to reanalyze them.
2024 if not Analyzed (Clause) then
2025 Set_Analyzed (Clause);
2027 Analyze_Dependency_Clause
2029 Is_Last => Clause = Last_Clause);
2032 -- Do not normalize a clause if errors were detected (count
2033 -- of Serious_Errors has increased) because the inputs and/or
2034 -- outputs may denote illegal items.
2036 if Serious_Errors_Detected = Errors then
2037 Normalize_Clause (Clause);
2043 if Restore_Scope then
2047 -- Verify that every input or output of the subprogram appear in a
2050 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
2051 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
2052 Check_Function_Return;
2054 -- The dependency list is malformed. This is a syntax error, always
2058 Error_Msg_N ("malformed dependency relation", Deps);
2062 -- The top level dependency relation is malformed. This is a syntax
2063 -- error, always report.
2066 Error_Msg_N ("malformed dependency relation", Deps);
2070 -- Ensure that a state and a corresponding constituent do not appear
2071 -- together in pragma [Refined_]Depends.
2073 Check_State_And_Constituent_Use
2074 (States => States_Seen,
2075 Constits => Constits_Seen,
2079 Set_Is_Analyzed_Pragma (N);
2080 end Analyze_Depends_In_Decl_Part;
2082 --------------------------------------------
2083 -- Analyze_External_Property_In_Decl_Part --
2084 --------------------------------------------
2086 procedure Analyze_External_Property_In_Decl_Part
2088 Expr_Val : out Boolean)
2090 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pragma_Name (N));
2091 Arg1 : constant Node_Id :=
2092 First (Pragma_Argument_Associations (N));
2093 Obj_Decl : constant Node_Id := Find_Related_Context (N);
2094 Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl);
2100 -- Do not analyze the pragma multiple times
2102 if Is_Analyzed_Pragma (N) then
2106 Error_Msg_Name_1 := Pragma_Name (N);
2108 -- An external property pragma must apply to an effectively volatile
2109 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
2110 -- The check is performed at the end of the declarative region due to a
2111 -- possible out-of-order arrangement of pragmas:
2114 -- pragma Async_Readers (Obj);
2115 -- pragma Volatile (Obj);
2117 if Prag_Id /= Pragma_No_Caching
2118 and then not Is_Effectively_Volatile (Obj_Id)
2120 if No_Caching_Enabled (Obj_Id) then
2122 ("illegal combination of external property % and property "
2123 & """No_Caching"" (SPARK RM 7.1.2(6))", N);
2126 ("external property % must apply to a volatile object", N);
2129 -- Pragma No_Caching should only apply to volatile variables of
2130 -- a non-effectively volatile type (SPARK RM 7.1.2).
2132 elsif Prag_Id = Pragma_No_Caching then
2133 if Is_Effectively_Volatile (Etype (Obj_Id)) then
2134 SPARK_Msg_N ("property % must not apply to an object of "
2135 & "an effectively volatile type", N);
2136 elsif not Is_Volatile (Obj_Id) then
2137 SPARK_Msg_N ("property % must apply to a volatile object", N);
2141 -- Ensure that the Boolean expression (if present) is static. A missing
2142 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
2146 if Present (Arg1) then
2147 Expr := Get_Pragma_Arg (Arg1);
2149 if Is_OK_Static_Expression (Expr) then
2150 Expr_Val := Is_True (Expr_Value (Expr));
2154 Set_Is_Analyzed_Pragma (N);
2155 end Analyze_External_Property_In_Decl_Part;
2157 ---------------------------------
2158 -- Analyze_Global_In_Decl_Part --
2159 ---------------------------------
2161 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
2162 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
2163 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
2164 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
2166 Constits_Seen : Elist_Id := No_Elist;
2167 -- A list containing the entities of all constituents processed so far.
2168 -- It aids in detecting illegal usage of a state and a corresponding
2169 -- constituent in pragma [Refinde_]Global.
2171 Seen : Elist_Id := No_Elist;
2172 -- A list containing the entities of all the items processed so far. It
2173 -- plays a role in detecting distinct entities.
2175 States_Seen : Elist_Id := No_Elist;
2176 -- A list containing the entities of all states processed so far. It
2177 -- helps in detecting illegal usage of a state and a corresponding
2178 -- constituent in pragma [Refined_]Global.
2180 In_Out_Seen : Boolean := False;
2181 Input_Seen : Boolean := False;
2182 Output_Seen : Boolean := False;
2183 Proof_Seen : Boolean := False;
2184 -- Flags used to verify the consistency of modes
2186 procedure Analyze_Global_List
2188 Global_Mode : Name_Id := Name_Input);
2189 -- Verify the legality of a single global list declaration. Global_Mode
2190 -- denotes the current mode in effect.
2192 -------------------------
2193 -- Analyze_Global_List --
2194 -------------------------
2196 procedure Analyze_Global_List
2198 Global_Mode : Name_Id := Name_Input)
2200 procedure Analyze_Global_Item
2202 Global_Mode : Name_Id);
2203 -- Verify the legality of a single global item declaration denoted by
2204 -- Item. Global_Mode denotes the current mode in effect.
2206 procedure Check_Duplicate_Mode
2208 Status : in out Boolean);
2209 -- Flag Status denotes whether a particular mode has been seen while
2210 -- processing a global list. This routine verifies that Mode is not a
2211 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2213 procedure Check_Mode_Restriction_In_Enclosing_Context
2215 Item_Id : Entity_Id);
2216 -- Verify that an item of mode In_Out or Output does not appear as
2217 -- an input in the Global aspect of an enclosing subprogram or task
2218 -- unit. If this is the case, emit an error. Item and Item_Id are
2219 -- respectively the item and its entity.
2221 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
2222 -- Mode denotes either In_Out or Output. Depending on the kind of the
2223 -- related subprogram, emit an error if those two modes apply to a
2224 -- function (SPARK RM 6.1.4(10)).
2226 -------------------------
2227 -- Analyze_Global_Item --
2228 -------------------------
2230 procedure Analyze_Global_Item
2232 Global_Mode : Name_Id)
2234 Item_Id : Entity_Id;
2237 -- Detect one of the following cases
2239 -- with Global => (null, Name)
2240 -- with Global => (Name_1, null, Name_2)
2241 -- with Global => (Name, null)
2243 if Nkind (Item) = N_Null then
2244 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
2249 Resolve_State (Item);
2251 -- Find the entity of the item. If this is a renaming, climb the
2252 -- renaming chain to reach the root object. Renamings of non-
2253 -- entire objects do not yield an entity (Empty).
2255 Item_Id := Entity_Of (Item);
2257 if Present (Item_Id) then
2259 -- A global item may denote a formal parameter of an enclosing
2260 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2261 -- provide a better error diagnostic.
2263 if Is_Formal (Item_Id) then
2264 if Scope (Item_Id) = Spec_Id then
2266 (Fix_Msg (Spec_Id, "global item cannot reference "
2267 & "parameter of subprogram &"), Item, Spec_Id);
2271 -- A global item may denote a concurrent type as long as it is
2272 -- the current instance of an enclosing protected or task type
2273 -- (SPARK RM 6.1.4).
2275 elsif Ekind_In (Item_Id, E_Protected_Type, E_Task_Type) then
2276 if Is_CCT_Instance (Item_Id, Spec_Id) then
2278 -- Pragma [Refined_]Global associated with a protected
2279 -- subprogram cannot mention the current instance of a
2280 -- protected type because the instance behaves as a
2281 -- formal parameter.
2283 if Ekind (Item_Id) = E_Protected_Type then
2284 if Scope (Spec_Id) = Item_Id then
2285 Error_Msg_Name_1 := Chars (Item_Id);
2287 (Fix_Msg (Spec_Id, "global item of subprogram & "
2288 & "cannot reference current instance of "
2289 & "protected type %"), Item, Spec_Id);
2293 -- Pragma [Refined_]Global associated with a task type
2294 -- cannot mention the current instance of a task type
2295 -- because the instance behaves as a formal parameter.
2297 else pragma Assert (Ekind (Item_Id) = E_Task_Type);
2298 if Spec_Id = Item_Id then
2299 Error_Msg_Name_1 := Chars (Item_Id);
2301 (Fix_Msg (Spec_Id, "global item of subprogram & "
2302 & "cannot reference current instance of task "
2303 & "type %"), Item, Spec_Id);
2308 -- Otherwise the global item denotes a subtype mark that is
2309 -- not a current instance.
2313 ("invalid use of subtype mark in global list", Item);
2317 -- A global item may denote the anonymous object created for a
2318 -- single protected/task type as long as the current instance
2319 -- is the same single type (SPARK RM 6.1.4).
2321 elsif Is_Single_Concurrent_Object (Item_Id)
2322 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
2324 -- Pragma [Refined_]Global associated with a protected
2325 -- subprogram cannot mention the current instance of a
2326 -- protected type because the instance behaves as a formal
2329 if Is_Single_Protected_Object (Item_Id) then
2330 if Scope (Spec_Id) = Etype (Item_Id) then
2331 Error_Msg_Name_1 := Chars (Item_Id);
2333 (Fix_Msg (Spec_Id, "global item of subprogram & "
2334 & "cannot reference current instance of protected "
2335 & "type %"), Item, Spec_Id);
2339 -- Pragma [Refined_]Global associated with a task type
2340 -- cannot mention the current instance of a task type
2341 -- because the instance behaves as a formal parameter.
2343 else pragma Assert (Is_Single_Task_Object (Item_Id));
2344 if Spec_Id = Item_Id then
2345 Error_Msg_Name_1 := Chars (Item_Id);
2347 (Fix_Msg (Spec_Id, "global item of subprogram & "
2348 & "cannot reference current instance of task "
2349 & "type %"), Item, Spec_Id);
2354 -- A formal object may act as a global item inside a generic
2356 elsif Is_Formal_Object (Item_Id) then
2359 -- The only legal references are those to abstract states,
2360 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2362 elsif not Ekind_In (Item_Id, E_Abstract_State,
2368 ("global item must denote object, state or current "
2369 & "instance of concurrent type", Item);
2371 if Ekind (Item_Id) in Named_Kind then
2373 ("\named number & is not an object", Item, Item);
2379 -- State related checks
2381 if Ekind (Item_Id) = E_Abstract_State then
2383 -- Package and subprogram bodies are instantiated
2384 -- individually in a separate compiler pass. Due to this
2385 -- mode of instantiation, the refinement of a state may
2386 -- no longer be visible when a subprogram body contract
2387 -- is instantiated. Since the generic template is legal,
2388 -- do not perform this check in the instance to circumvent
2394 -- An abstract state with visible refinement cannot appear
2395 -- in pragma [Refined_]Global as its place must be taken by
2396 -- some of its constituents (SPARK RM 6.1.4(7)).
2398 elsif Has_Visible_Refinement (Item_Id) then
2400 ("cannot mention state & in global refinement",
2402 SPARK_Msg_N ("\use its constituents instead", Item);
2405 -- An external state cannot appear as a global item of a
2406 -- nonvolatile function (SPARK RM 7.1.3(8)).
2408 elsif Is_External_State (Item_Id)
2409 and then Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2410 and then not Is_Volatile_Function (Spec_Id)
2413 ("external state & cannot act as global item of "
2414 & "nonvolatile function", Item, Item_Id);
2417 -- If the reference to the abstract state appears in an
2418 -- enclosing package body that will eventually refine the
2419 -- state, record the reference for future checks.
2422 Record_Possible_Body_Reference
2423 (State_Id => Item_Id,
2427 -- Constant related checks
2429 elsif Ekind (Item_Id) = E_Constant
2430 and then not Is_Access_Type (Etype (Item_Id))
2433 -- Unless it is of an access type, a constant is a read-only
2434 -- item, therefore it cannot act as an output.
2436 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2438 ("constant & cannot act as output", Item, Item_Id);
2442 -- Loop parameter related checks
2444 elsif Ekind (Item_Id) = E_Loop_Parameter then
2446 -- A loop parameter is a read-only item, therefore it cannot
2447 -- act as an output.
2449 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2451 ("loop parameter & cannot act as output",
2456 -- Variable related checks. These are only relevant when
2457 -- SPARK_Mode is on as they are not standard Ada legality
2460 elsif SPARK_Mode = On
2461 and then Ekind (Item_Id) = E_Variable
2462 and then Is_Effectively_Volatile (Item_Id)
2464 -- An effectively volatile object cannot appear as a global
2465 -- item of a nonvolatile function (SPARK RM 7.1.3(8)).
2467 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2468 and then not Is_Volatile_Function (Spec_Id)
2471 ("volatile object & cannot act as global item of a "
2472 & "function", Item, Item_Id);
2475 -- An effectively volatile object with external property
2476 -- Effective_Reads set to True must have mode Output or
2477 -- In_Out (SPARK RM 7.1.3(10)).
2479 elsif Effective_Reads_Enabled (Item_Id)
2480 and then Global_Mode = Name_Input
2483 ("volatile object & with property Effective_Reads must "
2484 & "have mode In_Out or Output", Item, Item_Id);
2489 -- When the item renames an entire object, replace the item
2490 -- with a reference to the object.
2492 if Entity (Item) /= Item_Id then
2493 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2497 -- Some form of illegal construct masquerading as a name
2498 -- (SPARK RM 6.1.4(4)).
2502 ("global item must denote object, state or current instance "
2503 & "of concurrent type", Item);
2507 -- Verify that an output does not appear as an input in an
2508 -- enclosing subprogram.
2510 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2511 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
2514 -- The same entity might be referenced through various way.
2515 -- Check the entity of the item rather than the item itself
2516 -- (SPARK RM 6.1.4(10)).
2518 if Contains (Seen, Item_Id) then
2519 SPARK_Msg_N ("duplicate global item", Item);
2521 -- Add the entity of the current item to the list of processed
2525 Append_New_Elmt (Item_Id, Seen);
2527 if Ekind (Item_Id) = E_Abstract_State then
2528 Append_New_Elmt (Item_Id, States_Seen);
2530 -- The variable may eventually become a constituent of a single
2531 -- protected/task type. Record the reference now and verify its
2532 -- legality when analyzing the contract of the variable
2535 elsif Ekind (Item_Id) = E_Variable then
2536 Record_Possible_Part_Of_Reference
2541 if Ekind_In (Item_Id, E_Abstract_State, E_Constant, E_Variable)
2542 and then Present (Encapsulating_State (Item_Id))
2544 Append_New_Elmt (Item_Id, Constits_Seen);
2547 end Analyze_Global_Item;
2549 --------------------------
2550 -- Check_Duplicate_Mode --
2551 --------------------------
2553 procedure Check_Duplicate_Mode
2555 Status : in out Boolean)
2559 SPARK_Msg_N ("duplicate global mode", Mode);
2563 end Check_Duplicate_Mode;
2565 -------------------------------------------------
2566 -- Check_Mode_Restriction_In_Enclosing_Context --
2567 -------------------------------------------------
2569 procedure Check_Mode_Restriction_In_Enclosing_Context
2571 Item_Id : Entity_Id)
2573 Context : Entity_Id;
2575 Inputs : Elist_Id := No_Elist;
2576 Outputs : Elist_Id := No_Elist;
2579 -- Traverse the scope stack looking for enclosing subprograms or
2580 -- tasks subject to pragma [Refined_]Global.
2582 Context := Scope (Subp_Id);
2583 while Present (Context) and then Context /= Standard_Standard loop
2585 -- For a single task type, retrieve the corresponding object to
2586 -- which pragma [Refined_]Global is attached.
2588 if Ekind (Context) = E_Task_Type
2589 and then Is_Single_Concurrent_Type (Context)
2591 Context := Anonymous_Object (Context);
2594 if (Is_Subprogram (Context)
2595 or else Ekind (Context) = E_Task_Type
2596 or else Is_Single_Task_Object (Context))
2598 (Present (Get_Pragma (Context, Pragma_Global))
2600 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2602 Collect_Subprogram_Inputs_Outputs
2603 (Subp_Id => Context,
2604 Subp_Inputs => Inputs,
2605 Subp_Outputs => Outputs,
2606 Global_Seen => Dummy);
2608 -- The item is classified as In_Out or Output but appears as
2609 -- an Input in an enclosing subprogram or task unit (SPARK
2612 if Appears_In (Inputs, Item_Id)
2613 and then not Appears_In (Outputs, Item_Id)
2616 ("global item & cannot have mode In_Out or Output",
2619 if Is_Subprogram (Context) then
2621 (Fix_Msg (Subp_Id, "\item already appears as input "
2622 & "of subprogram &"), Item, Context);
2625 (Fix_Msg (Subp_Id, "\item already appears as input "
2626 & "of task &"), Item, Context);
2629 -- Stop the traversal once an error has been detected
2635 Context := Scope (Context);
2637 end Check_Mode_Restriction_In_Enclosing_Context;
2639 ----------------------------------------
2640 -- Check_Mode_Restriction_In_Function --
2641 ----------------------------------------
2643 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2645 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
2647 ("global mode & is not applicable to functions", Mode);
2649 end Check_Mode_Restriction_In_Function;
2657 -- Start of processing for Analyze_Global_List
2660 if Nkind (List) = N_Null then
2661 Set_Analyzed (List);
2663 -- Single global item declaration
2665 elsif Nkind_In (List, N_Expanded_Name,
2667 N_Selected_Component)
2669 Analyze_Global_Item (List, Global_Mode);
2671 -- Simple global list or moded global list declaration
2673 elsif Nkind (List) = N_Aggregate then
2674 Set_Analyzed (List);
2676 -- The declaration of a simple global list appear as a collection
2679 if Present (Expressions (List)) then
2680 if Present (Component_Associations (List)) then
2682 ("cannot mix moded and non-moded global lists", List);
2685 Item := First (Expressions (List));
2686 while Present (Item) loop
2687 Analyze_Global_Item (Item, Global_Mode);
2691 -- The declaration of a moded global list appears as a collection
2692 -- of component associations where individual choices denote
2695 elsif Present (Component_Associations (List)) then
2696 if Present (Expressions (List)) then
2698 ("cannot mix moded and non-moded global lists", List);
2701 Assoc := First (Component_Associations (List));
2702 while Present (Assoc) loop
2703 Mode := First (Choices (Assoc));
2705 if Nkind (Mode) = N_Identifier then
2706 if Chars (Mode) = Name_In_Out then
2707 Check_Duplicate_Mode (Mode, In_Out_Seen);
2708 Check_Mode_Restriction_In_Function (Mode);
2710 elsif Chars (Mode) = Name_Input then
2711 Check_Duplicate_Mode (Mode, Input_Seen);
2713 elsif Chars (Mode) = Name_Output then
2714 Check_Duplicate_Mode (Mode, Output_Seen);
2715 Check_Mode_Restriction_In_Function (Mode);
2717 elsif Chars (Mode) = Name_Proof_In then
2718 Check_Duplicate_Mode (Mode, Proof_Seen);
2721 SPARK_Msg_N ("invalid mode selector", Mode);
2725 SPARK_Msg_N ("invalid mode selector", Mode);
2728 -- Items in a moded list appear as a collection of
2729 -- expressions. Reuse the existing machinery to analyze
2733 (List => Expression (Assoc),
2734 Global_Mode => Chars (Mode));
2742 raise Program_Error;
2745 -- Any other attempt to declare a global item is illegal. This is a
2746 -- syntax error, always report.
2749 Error_Msg_N ("malformed global list", List);
2751 end Analyze_Global_List;
2755 Items : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
2757 Restore_Scope : Boolean := False;
2759 -- Start of processing for Analyze_Global_In_Decl_Part
2762 -- Do not analyze the pragma multiple times
2764 if Is_Analyzed_Pragma (N) then
2768 -- There is nothing to be done for a null global list
2770 if Nkind (Items) = N_Null then
2771 Set_Analyzed (Items);
2773 -- Analyze the various forms of global lists and items. Note that some
2774 -- of these may be malformed in which case the analysis emits error
2778 -- When pragma [Refined_]Global appears on a single concurrent type,
2779 -- it is relocated to the anonymous object.
2781 if Is_Single_Concurrent_Object (Spec_Id) then
2784 -- Ensure that the formal parameters are visible when processing an
2785 -- item. This falls out of the general rule of aspects pertaining to
2786 -- subprogram declarations.
2788 elsif not In_Open_Scopes (Spec_Id) then
2789 Restore_Scope := True;
2790 Push_Scope (Spec_Id);
2792 if Ekind (Spec_Id) = E_Task_Type then
2793 if Has_Discriminants (Spec_Id) then
2794 Install_Discriminants (Spec_Id);
2797 elsif Is_Generic_Subprogram (Spec_Id) then
2798 Install_Generic_Formals (Spec_Id);
2801 Install_Formals (Spec_Id);
2805 Analyze_Global_List (Items);
2807 if Restore_Scope then
2812 -- Ensure that a state and a corresponding constituent do not appear
2813 -- together in pragma [Refined_]Global.
2815 Check_State_And_Constituent_Use
2816 (States => States_Seen,
2817 Constits => Constits_Seen,
2820 Set_Is_Analyzed_Pragma (N);
2821 end Analyze_Global_In_Decl_Part;
2823 --------------------------------------------
2824 -- Analyze_Initial_Condition_In_Decl_Part --
2825 --------------------------------------------
2827 -- WARNING: This routine manages Ghost regions. Return statements must be
2828 -- replaced by gotos which jump to the end of the routine and restore the
2831 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2832 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2833 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2834 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
2836 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
2837 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
2838 -- Save the Ghost-related attributes to restore on exit
2841 -- Do not analyze the pragma multiple times
2843 if Is_Analyzed_Pragma (N) then
2847 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2848 -- analysis of the pragma, the Ghost mode at point of declaration and
2849 -- point of analysis may not necessarily be the same. Use the mode in
2850 -- effect at the point of declaration.
2854 -- The expression is preanalyzed because it has not been moved to its
2855 -- final place yet. A direct analysis may generate side effects and this
2856 -- is not desired at this point.
2858 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2859 Set_Is_Analyzed_Pragma (N);
2861 Restore_Ghost_Region (Saved_GM, Saved_IGR);
2862 end Analyze_Initial_Condition_In_Decl_Part;
2864 --------------------------------------
2865 -- Analyze_Initializes_In_Decl_Part --
2866 --------------------------------------
2868 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2869 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2870 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2872 Constits_Seen : Elist_Id := No_Elist;
2873 -- A list containing the entities of all constituents processed so far.
2874 -- It aids in detecting illegal usage of a state and a corresponding
2875 -- constituent in pragma Initializes.
2877 Items_Seen : Elist_Id := No_Elist;
2878 -- A list of all initialization items processed so far. This list is
2879 -- used to detect duplicate items.
2881 States_And_Objs : Elist_Id := No_Elist;
2882 -- A list of all abstract states and objects declared in the visible
2883 -- declarations of the related package. This list is used to detect the
2884 -- legality of initialization items.
2886 States_Seen : Elist_Id := No_Elist;
2887 -- A list containing the entities of all states processed so far. It
2888 -- helps in detecting illegal usage of a state and a corresponding
2889 -- constituent in pragma Initializes.
2891 procedure Analyze_Initialization_Item (Item : Node_Id);
2892 -- Verify the legality of a single initialization item
2894 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2895 -- Verify the legality of a single initialization item followed by a
2896 -- list of input items.
2898 procedure Collect_States_And_Objects (Pack_Decl : Node_Id);
2899 -- Inspect the visible declarations of the related package and gather
2900 -- the entities of all abstract states and objects in States_And_Objs.
2902 ---------------------------------
2903 -- Analyze_Initialization_Item --
2904 ---------------------------------
2906 procedure Analyze_Initialization_Item (Item : Node_Id) is
2907 Item_Id : Entity_Id;
2911 Resolve_State (Item);
2913 if Is_Entity_Name (Item) then
2914 Item_Id := Entity_Of (Item);
2916 if Present (Item_Id)
2917 and then Ekind_In (Item_Id, E_Abstract_State,
2921 -- When the initialization item is undefined, it appears as
2922 -- Any_Id. Do not continue with the analysis of the item.
2924 if Item_Id = Any_Id then
2927 -- The state or variable must be declared in the visible
2928 -- declarations of the package (SPARK RM 7.1.5(7)).
2930 elsif not Contains (States_And_Objs, Item_Id) then
2931 Error_Msg_Name_1 := Chars (Pack_Id);
2933 ("initialization item & must appear in the visible "
2934 & "declarations of package %", Item, Item_Id);
2936 -- Detect a duplicate use of the same initialization item
2937 -- (SPARK RM 7.1.5(5)).
2939 elsif Contains (Items_Seen, Item_Id) then
2940 SPARK_Msg_N ("duplicate initialization item", Item);
2942 -- The item is legal, add it to the list of processed states
2946 Append_New_Elmt (Item_Id, Items_Seen);
2948 if Ekind (Item_Id) = E_Abstract_State then
2949 Append_New_Elmt (Item_Id, States_Seen);
2952 if Present (Encapsulating_State (Item_Id)) then
2953 Append_New_Elmt (Item_Id, Constits_Seen);
2957 -- The item references something that is not a state or object
2958 -- (SPARK RM 7.1.5(3)).
2962 ("initialization item must denote object or state", Item);
2965 -- Some form of illegal construct masquerading as a name
2966 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2970 ("initialization item must denote object or state", Item);
2972 end Analyze_Initialization_Item;
2974 ---------------------------------------------
2975 -- Analyze_Initialization_Item_With_Inputs --
2976 ---------------------------------------------
2978 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2979 Inputs_Seen : Elist_Id := No_Elist;
2980 -- A list of all inputs processed so far. This list is used to detect
2981 -- duplicate uses of an input.
2983 Non_Null_Seen : Boolean := False;
2984 Null_Seen : Boolean := False;
2985 -- Flags used to check the legality of an input list
2987 procedure Analyze_Input_Item (Input : Node_Id);
2988 -- Verify the legality of a single input item
2990 ------------------------
2991 -- Analyze_Input_Item --
2992 ------------------------
2994 procedure Analyze_Input_Item (Input : Node_Id) is
2995 Input_Id : Entity_Id;
3000 if Nkind (Input) = N_Null then
3003 ("multiple null initializations not allowed", Item);
3005 elsif Non_Null_Seen then
3007 ("cannot mix null and non-null initialization item", Item);
3015 Non_Null_Seen := True;
3019 ("cannot mix null and non-null initialization item", Item);
3023 Resolve_State (Input);
3025 if Is_Entity_Name (Input) then
3026 Input_Id := Entity_Of (Input);
3028 if Present (Input_Id)
3029 and then Ekind_In (Input_Id, E_Abstract_State,
3031 E_Generic_In_Out_Parameter,
3032 E_Generic_In_Parameter,
3040 -- The input cannot denote states or objects declared
3041 -- within the related package (SPARK RM 7.1.5(4)).
3043 if Within_Scope (Input_Id, Current_Scope) then
3045 -- Do not consider generic formal parameters or their
3046 -- respective mappings to generic formals. Even though
3047 -- the formals appear within the scope of the package,
3048 -- it is allowed for an initialization item to depend
3049 -- on an input item.
3051 if Ekind_In (Input_Id, E_Generic_In_Out_Parameter,
3052 E_Generic_In_Parameter)
3056 elsif Ekind_In (Input_Id, E_Constant, E_Variable)
3057 and then Present (Corresponding_Generic_Association
3058 (Declaration_Node (Input_Id)))
3063 Error_Msg_Name_1 := Chars (Pack_Id);
3065 ("input item & cannot denote a visible object or "
3066 & "state of package %", Input, Input_Id);
3071 -- Detect a duplicate use of the same input item
3072 -- (SPARK RM 7.1.5(5)).
3074 if Contains (Inputs_Seen, Input_Id) then
3075 SPARK_Msg_N ("duplicate input item", Input);
3079 -- At this point it is known that the input is legal. Add
3080 -- it to the list of processed inputs.
3082 Append_New_Elmt (Input_Id, Inputs_Seen);
3084 if Ekind (Input_Id) = E_Abstract_State then
3085 Append_New_Elmt (Input_Id, States_Seen);
3088 if Ekind_In (Input_Id, E_Abstract_State,
3091 and then Present (Encapsulating_State (Input_Id))
3093 Append_New_Elmt (Input_Id, Constits_Seen);
3096 -- The input references something that is not a state or an
3097 -- object (SPARK RM 7.1.5(3)).
3101 ("input item must denote object or state", Input);
3104 -- Some form of illegal construct masquerading as a name
3105 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
3109 ("input item must denote object or state", Input);
3112 end Analyze_Input_Item;
3116 Inputs : constant Node_Id := Expression (Item);
3120 Name_Seen : Boolean := False;
3121 -- A flag used to detect multiple item names
3123 -- Start of processing for Analyze_Initialization_Item_With_Inputs
3126 -- Inspect the name of an item with inputs
3128 Elmt := First (Choices (Item));
3129 while Present (Elmt) loop
3131 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
3134 Analyze_Initialization_Item (Elmt);
3140 -- Multiple input items appear as an aggregate
3142 if Nkind (Inputs) = N_Aggregate then
3143 if Present (Expressions (Inputs)) then
3144 Input := First (Expressions (Inputs));
3145 while Present (Input) loop
3146 Analyze_Input_Item (Input);
3151 if Present (Component_Associations (Inputs)) then
3153 ("inputs must appear in named association form", Inputs);
3156 -- Single input item
3159 Analyze_Input_Item (Inputs);
3161 end Analyze_Initialization_Item_With_Inputs;
3163 --------------------------------
3164 -- Collect_States_And_Objects --
3165 --------------------------------
3167 procedure Collect_States_And_Objects (Pack_Decl : Node_Id) is
3168 Pack_Spec : constant Node_Id := Specification (Pack_Decl);
3169 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
3171 State_Elmt : Elmt_Id;
3174 -- Collect the abstract states defined in the package (if any)
3176 if Has_Non_Null_Abstract_State (Pack_Id) then
3177 State_Elmt := First_Elmt (Abstract_States (Pack_Id));
3178 while Present (State_Elmt) loop
3179 Append_New_Elmt (Node (State_Elmt), States_And_Objs);
3180 Next_Elmt (State_Elmt);
3184 -- Collect all objects that appear in the visible declarations of the
3187 if Present (Visible_Declarations (Pack_Spec)) then
3188 Decl := First (Visible_Declarations (Pack_Spec));
3189 while Present (Decl) loop
3190 if Comes_From_Source (Decl)
3191 and then Nkind_In (Decl, N_Object_Declaration,
3192 N_Object_Renaming_Declaration)
3194 Append_New_Elmt (Defining_Entity (Decl), States_And_Objs);
3196 elsif Nkind (Decl) = N_Package_Declaration then
3197 Collect_States_And_Objects (Decl);
3199 elsif Is_Single_Concurrent_Type_Declaration (Decl) then
3201 (Anonymous_Object (Defining_Entity (Decl)),
3208 end Collect_States_And_Objects;
3212 Inits : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
3215 -- Start of processing for Analyze_Initializes_In_Decl_Part
3218 -- Do not analyze the pragma multiple times
3220 if Is_Analyzed_Pragma (N) then
3224 -- Nothing to do when the initialization list is empty
3226 if Nkind (Inits) = N_Null then
3230 -- Single and multiple initialization clauses appear as an aggregate. If
3231 -- this is not the case, then either the parser or the analysis of the
3232 -- pragma failed to produce an aggregate.
3234 pragma Assert (Nkind (Inits) = N_Aggregate);
3236 -- Initialize the various lists used during analysis
3238 Collect_States_And_Objects (Pack_Decl);
3240 if Present (Expressions (Inits)) then
3241 Init := First (Expressions (Inits));
3242 while Present (Init) loop
3243 Analyze_Initialization_Item (Init);
3248 if Present (Component_Associations (Inits)) then
3249 Init := First (Component_Associations (Inits));
3250 while Present (Init) loop
3251 Analyze_Initialization_Item_With_Inputs (Init);
3256 -- Ensure that a state and a corresponding constituent do not appear
3257 -- together in pragma Initializes.
3259 Check_State_And_Constituent_Use
3260 (States => States_Seen,
3261 Constits => Constits_Seen,
3264 Set_Is_Analyzed_Pragma (N);
3265 end Analyze_Initializes_In_Decl_Part;
3267 ---------------------
3268 -- Analyze_Part_Of --
3269 ---------------------
3271 procedure Analyze_Part_Of
3273 Item_Id : Entity_Id;
3275 Encap_Id : out Entity_Id;
3276 Legal : out Boolean)
3278 procedure Check_Part_Of_Abstract_State;
3279 pragma Inline (Check_Part_Of_Abstract_State);
3280 -- Verify the legality of indicator Part_Of when the encapsulator is an
3283 procedure Check_Part_Of_Concurrent_Type;
3284 pragma Inline (Check_Part_Of_Concurrent_Type);
3285 -- Verify the legality of indicator Part_Of when the encapsulator is a
3286 -- single concurrent type.
3288 ----------------------------------
3289 -- Check_Part_Of_Abstract_State --
3290 ----------------------------------
3292 procedure Check_Part_Of_Abstract_State is
3293 Pack_Id : Entity_Id;
3294 Placement : State_Space_Kind;
3295 Parent_Unit : Entity_Id;
3298 -- Determine where the object, package instantiation or state lives
3299 -- with respect to the enclosing packages or package bodies.
3301 Find_Placement_In_State_Space
3302 (Item_Id => Item_Id,
3303 Placement => Placement,
3304 Pack_Id => Pack_Id);
3306 -- The item appears in a non-package construct with a declarative
3307 -- part (subprogram, block, etc). As such, the item is not allowed
3308 -- to be a part of an encapsulating state because the item is not
3311 if Placement = Not_In_Package then
3313 ("indicator Part_Of cannot appear in this context "
3314 & "(SPARK RM 7.2.6(5))", Indic);
3316 Error_Msg_Name_1 := Chars (Scope (Encap_Id));
3318 ("\& is not part of the hidden state of package %",
3322 -- The item appears in the visible state space of some package. In
3323 -- general this scenario does not warrant Part_Of except when the
3324 -- package is a nongeneric private child unit and the encapsulating
3325 -- state is declared in a parent unit or a public descendant of that
3328 elsif Placement = Visible_State_Space then
3329 if Is_Child_Unit (Pack_Id)
3330 and then not Is_Generic_Unit (Pack_Id)
3331 and then Is_Private_Descendant (Pack_Id)
3333 -- A variable or state abstraction which is part of the visible
3334 -- state of a nongeneric private child unit or its public
3335 -- descendants must have its Part_Of indicator specified. The
3336 -- Part_Of indicator must denote a state declared by either the
3337 -- parent unit of the private unit or by a public descendant of
3338 -- that parent unit.
3340 -- Find the nearest private ancestor (which can be the current
3343 Parent_Unit := Pack_Id;
3344 while Present (Parent_Unit) loop
3347 (Parent (Unit_Declaration_Node (Parent_Unit)));
3348 Parent_Unit := Scope (Parent_Unit);
3351 Parent_Unit := Scope (Parent_Unit);
3353 if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then
3355 ("indicator Part_Of must denote abstract state of & or of "
3356 & "its public descendant (SPARK RM 7.2.6(3))",
3357 Indic, Parent_Unit);
3360 elsif Scope (Encap_Id) = Parent_Unit
3362 (Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id))
3363 and then not Is_Private_Descendant (Scope (Encap_Id)))
3369 ("indicator Part_Of must denote abstract state of & or of "
3370 & "its public descendant (SPARK RM 7.2.6(3))",
3371 Indic, Parent_Unit);
3375 -- Indicator Part_Of is not needed when the related package is
3376 -- not a nongeneric private child unit or a public descendant
3381 ("indicator Part_Of cannot appear in this context "
3382 & "(SPARK RM 7.2.6(5))", Indic);
3384 Error_Msg_Name_1 := Chars (Pack_Id);
3386 ("\& is declared in the visible part of package %",
3391 -- When the item appears in the private state space of a package, the
3392 -- encapsulating state must be declared in the same package.
3394 elsif Placement = Private_State_Space then
3395 if Scope (Encap_Id) /= Pack_Id then
3397 ("indicator Part_Of must denote an abstract state of "
3398 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3400 Error_Msg_Name_1 := Chars (Pack_Id);
3402 ("\& is declared in the private part of package %",
3407 -- Items declared in the body state space of a package do not need
3408 -- Part_Of indicators as the refinement has already been seen.
3412 ("indicator Part_Of cannot appear in this context "
3413 & "(SPARK RM 7.2.6(5))", Indic);
3415 if Scope (Encap_Id) = Pack_Id then
3416 Error_Msg_Name_1 := Chars (Pack_Id);
3418 ("\& is declared in the body of package %", Indic, Item_Id);
3424 -- At this point it is known that the Part_Of indicator is legal
3427 end Check_Part_Of_Abstract_State;
3429 -----------------------------------
3430 -- Check_Part_Of_Concurrent_Type --
3431 -----------------------------------
3433 procedure Check_Part_Of_Concurrent_Type is
3434 function In_Proper_Order
3436 Second : Node_Id) return Boolean;
3437 pragma Inline (In_Proper_Order);
3438 -- Determine whether node First precedes node Second
3440 procedure Placement_Error;
3441 pragma Inline (Placement_Error);
3442 -- Emit an error concerning the illegal placement of the item with
3443 -- respect to the single concurrent type.
3445 ---------------------
3446 -- In_Proper_Order --
3447 ---------------------
3449 function In_Proper_Order
3451 Second : Node_Id) return Boolean
3456 if List_Containing (First) = List_Containing (Second) then
3458 while Present (N) loop
3468 end In_Proper_Order;
3470 ---------------------
3471 -- Placement_Error --
3472 ---------------------
3474 procedure Placement_Error is
3477 ("indicator Part_Of must denote a previously declared single "
3478 & "protected type or single task type", Encap);
3479 end Placement_Error;
3483 Conc_Typ : constant Entity_Id := Etype (Encap_Id);
3484 Encap_Decl : constant Node_Id := Declaration_Node (Encap_Id);
3485 Encap_Context : constant Node_Id := Parent (Encap_Decl);
3487 Item_Context : Node_Id;
3488 Item_Decl : Node_Id;
3489 Prv_Decls : List_Id;
3490 Vis_Decls : List_Id;
3492 -- Start of processing for Check_Part_Of_Concurrent_Type
3495 -- Only abstract states and variables can act as constituents of an
3496 -- encapsulating single concurrent type.
3498 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
3501 -- The constituent is a constant
3503 elsif Ekind (Item_Id) = E_Constant then
3504 Error_Msg_Name_1 := Chars (Encap_Id);
3506 (Fix_Msg (Conc_Typ, "constant & cannot act as constituent of "
3507 & "single protected type %"), Indic, Item_Id);
3510 -- The constituent is a package instantiation
3513 Error_Msg_Name_1 := Chars (Encap_Id);
3515 (Fix_Msg (Conc_Typ, "package instantiation & cannot act as "
3516 & "constituent of single protected type %"), Indic, Item_Id);
3520 -- When the item denotes an abstract state of a nested package, use
3521 -- the declaration of the package to detect proper placement.
3526 -- with Abstract_State => (State with Part_Of => T)
3528 if Ekind (Item_Id) = E_Abstract_State then
3529 Item_Decl := Unit_Declaration_Node (Scope (Item_Id));
3531 Item_Decl := Declaration_Node (Item_Id);
3534 Item_Context := Parent (Item_Decl);
3536 -- The item and the single concurrent type must appear in the same
3537 -- declarative region, with the item following the declaration of
3538 -- the single concurrent type (SPARK RM 9(3)).
3540 if Item_Context = Encap_Context then
3541 if Nkind_In (Item_Context, N_Package_Specification,
3542 N_Protected_Definition,
3545 Prv_Decls := Private_Declarations (Item_Context);
3546 Vis_Decls := Visible_Declarations (Item_Context);
3548 -- The placement is OK when the single concurrent type appears
3549 -- within the visible declarations and the item in the private
3555 -- Constit : ... with Part_Of => PO;
3558 if List_Containing (Encap_Decl) = Vis_Decls
3559 and then List_Containing (Item_Decl) = Prv_Decls
3563 -- The placement is illegal when the item appears within the
3564 -- visible declarations and the single concurrent type is in
3565 -- the private declarations.
3568 -- Constit : ... with Part_Of => PO;
3573 elsif List_Containing (Item_Decl) = Vis_Decls
3574 and then List_Containing (Encap_Decl) = Prv_Decls
3579 -- Otherwise both the item and the single concurrent type are
3580 -- in the same list. Ensure that the declaration of the single
3581 -- concurrent type precedes that of the item.
3583 elsif not In_Proper_Order
3584 (First => Encap_Decl,
3585 Second => Item_Decl)
3591 -- Otherwise both the item and the single concurrent type are
3592 -- in the same list. Ensure that the declaration of the single
3593 -- concurrent type precedes that of the item.
3595 elsif not In_Proper_Order
3596 (First => Encap_Decl,
3597 Second => Item_Decl)
3603 -- Otherwise the item and the single concurrent type reside within
3604 -- unrelated regions.
3607 Error_Msg_Name_1 := Chars (Encap_Id);
3609 (Fix_Msg (Conc_Typ, "constituent & must be declared "
3610 & "immediately within the same region as single protected "
3611 & "type %"), Indic, Item_Id);
3615 -- At this point it is known that the Part_Of indicator is legal
3618 end Check_Part_Of_Concurrent_Type;
3620 -- Start of processing for Analyze_Part_Of
3623 -- Assume that the indicator is illegal
3628 if Nkind_In (Encap, N_Expanded_Name,
3630 N_Selected_Component)
3633 Resolve_State (Encap);
3635 Encap_Id := Entity (Encap);
3637 -- The encapsulator is an abstract state
3639 if Ekind (Encap_Id) = E_Abstract_State then
3642 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3644 elsif Is_Single_Concurrent_Object (Encap_Id) then
3647 -- Otherwise the encapsulator is not a legal choice
3651 ("indicator Part_Of must denote abstract state, single "
3652 & "protected type or single task type", Encap);
3656 -- This is a syntax error, always report
3660 ("indicator Part_Of must denote abstract state, single protected "
3661 & "type or single task type", Encap);
3665 -- Catch a case where indicator Part_Of denotes the abstract view of a
3666 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3668 if From_Limited_With (Encap_Id)
3669 and then Present (Non_Limited_View (Encap_Id))
3670 and then Ekind (Non_Limited_View (Encap_Id)) = E_Variable
3672 SPARK_Msg_N ("indicator Part_Of must denote abstract state", Encap);
3673 SPARK_Msg_N ("\& denotes abstract view of object", Encap);
3677 -- The encapsulator is an abstract state
3679 if Ekind (Encap_Id) = E_Abstract_State then
3680 Check_Part_Of_Abstract_State;
3682 -- The encapsulator is a single concurrent type
3685 Check_Part_Of_Concurrent_Type;
3687 end Analyze_Part_Of;
3689 ----------------------------------
3690 -- Analyze_Part_Of_In_Decl_Part --
3691 ----------------------------------
3693 procedure Analyze_Part_Of_In_Decl_Part
3695 Freeze_Id : Entity_Id := Empty)
3697 Encap : constant Node_Id :=
3698 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
3699 Errors : constant Nat := Serious_Errors_Detected;
3700 Var_Decl : constant Node_Id := Find_Related_Context (N);
3701 Var_Id : constant Entity_Id := Defining_Entity (Var_Decl);
3702 Constits : Elist_Id;
3703 Encap_Id : Entity_Id;
3707 -- Detect any discrepancies between the placement of the variable with
3708 -- respect to general state space and the encapsulating state or single
3715 Encap_Id => Encap_Id,
3718 -- The Part_Of indicator turns the variable into a constituent of the
3719 -- encapsulating state or single concurrent type.
3722 pragma Assert (Present (Encap_Id));
3723 Constits := Part_Of_Constituents (Encap_Id);
3725 if No (Constits) then
3726 Constits := New_Elmt_List;
3727 Set_Part_Of_Constituents (Encap_Id, Constits);
3730 Append_Elmt (Var_Id, Constits);
3731 Set_Encapsulating_State (Var_Id, Encap_Id);
3733 -- A Part_Of constituent partially refines an abstract state. This
3734 -- property does not apply to protected or task units.
3736 if Ekind (Encap_Id) = E_Abstract_State then
3737 Set_Has_Partial_Visible_Refinement (Encap_Id);
3741 -- Emit a clarification message when the encapsulator is undefined,
3742 -- possibly due to contract freezing.
3744 if Errors /= Serious_Errors_Detected
3745 and then Present (Freeze_Id)
3746 and then Has_Undefined_Reference (Encap)
3748 Contract_Freeze_Error (Var_Id, Freeze_Id);
3750 end Analyze_Part_Of_In_Decl_Part;
3752 --------------------
3753 -- Analyze_Pragma --
3754 --------------------
3756 procedure Analyze_Pragma (N : Node_Id) is
3757 Loc : constant Source_Ptr := Sloc (N);
3759 Pname : Name_Id := Pragma_Name (N);
3760 -- Name of the source pragma, or name of the corresponding aspect for
3761 -- pragmas which originate in a source aspect. In the latter case, the
3762 -- name may be different from the pragma name.
3764 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
3766 Pragma_Exit : exception;
3767 -- This exception is used to exit pragma processing completely. It
3768 -- is used when an error is detected, and no further processing is
3769 -- required. It is also used if an earlier error has left the tree in
3770 -- a state where the pragma should not be processed.
3773 -- Number of pragma argument associations
3779 -- First four pragma arguments (pragma argument association nodes, or
3780 -- Empty if the corresponding argument does not exist).
3782 type Name_List is array (Natural range <>) of Name_Id;
3783 type Args_List is array (Natural range <>) of Node_Id;
3784 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3786 -----------------------
3787 -- Local Subprograms --
3788 -----------------------
3790 function Acc_First (N : Node_Id) return Node_Id;
3791 -- Helper function to iterate over arguments given to OpenAcc pragmas
3793 function Acc_Next (N : Node_Id) return Node_Id;
3794 -- Helper function to iterate over arguments given to OpenAcc pragmas
3796 procedure Ada_2005_Pragma;
3797 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3798 -- Ada 95 mode, these are implementation defined pragmas, so should be
3799 -- caught by the No_Implementation_Pragmas restriction.
3801 procedure Ada_2012_Pragma;
3802 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3803 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3804 -- should be caught by the No_Implementation_Pragmas restriction.
3806 procedure Analyze_Depends_Global
3807 (Spec_Id : out Entity_Id;
3808 Subp_Decl : out Node_Id;
3809 Legal : out Boolean);
3810 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3811 -- legality of the placement and related context of the pragma. Spec_Id
3812 -- is the entity of the related subprogram. Subp_Decl is the declaration
3813 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3815 procedure Analyze_If_Present (Id : Pragma_Id);
3816 -- Inspect the remainder of the list containing pragma N and look for
3817 -- a pragma that matches Id. If found, analyze the pragma.
3819 procedure Analyze_Pre_Post_Condition;
3820 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3822 procedure Analyze_Refined_Depends_Global_Post
3823 (Spec_Id : out Entity_Id;
3824 Body_Id : out Entity_Id;
3825 Legal : out Boolean);
3826 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3827 -- Refined_Global and Refined_Post. Verify the legality of the placement
3828 -- and related context of the pragma. Spec_Id is the entity of the
3829 -- related subprogram. Body_Id is the entity of the subprogram body.
3830 -- Flag Legal is set when the pragma is legal.
3832 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False);
3833 -- Perform full analysis of pragma Unmodified and the write aspect of
3834 -- pragma Unused. Flag Is_Unused should be set when verifying the
3835 -- semantics of pragma Unused.
3837 procedure Analyze_Unreferenced_Or_Unused (Is_Unused : Boolean := False);
3838 -- Perform full analysis of pragma Unreferenced and the read aspect of
3839 -- pragma Unused. Flag Is_Unused should be set when verifying the
3840 -- semantics of pragma Unused.
3842 procedure Check_Ada_83_Warning;
3843 -- Issues a warning message for the current pragma if operating in Ada
3844 -- 83 mode (used for language pragmas that are not a standard part of
3845 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3848 procedure Check_Arg_Count (Required : Nat);
3849 -- Check argument count for pragma is equal to given parameter. If not,
3850 -- then issue an error message and raise Pragma_Exit.
3852 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3853 -- Arg which can either be a pragma argument association, in which case
3854 -- the check is applied to the expression of the association or an
3855 -- expression directly.
3857 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
3858 -- Check that an argument has the right form for an EXTERNAL_NAME
3859 -- parameter of an extended import/export pragma. The rule is that the
3860 -- name must be an identifier or string literal (in Ada 83 mode) or a
3861 -- static string expression (in Ada 95 mode).
3863 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
3864 -- Check the specified argument Arg to make sure that it is an
3865 -- identifier. If not give error and raise Pragma_Exit.
3867 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
3868 -- Check the specified argument Arg to make sure that it is an integer
3869 -- literal. If not give error and raise Pragma_Exit.
3871 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
3872 -- Check the specified argument Arg to make sure that it has the proper
3873 -- syntactic form for a local name and meets the semantic requirements
3874 -- for a local name. The local name is analyzed as part of the
3875 -- processing for this call. In addition, the local name is required
3876 -- to represent an entity at the library level.
3878 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
3879 -- Check the specified argument Arg to make sure that it has the proper
3880 -- syntactic form for a local name and meets the semantic requirements
3881 -- for a local name. The local name is analyzed as part of the
3882 -- processing for this call.
3884 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
3885 -- Check the specified argument Arg to make sure that it is a valid
3886 -- locking policy name. If not give error and raise Pragma_Exit.
3888 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
3889 -- Check the specified argument Arg to make sure that it is a valid
3890 -- elaboration policy name. If not give error and raise Pragma_Exit.
3892 procedure Check_Arg_Is_One_Of
3895 procedure Check_Arg_Is_One_Of
3897 N1, N2, N3 : Name_Id);
3898 procedure Check_Arg_Is_One_Of
3900 N1, N2, N3, N4 : Name_Id);
3901 procedure Check_Arg_Is_One_Of
3903 N1, N2, N3, N4, N5 : Name_Id);
3904 -- Check the specified argument Arg to make sure that it is an
3905 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3906 -- present). If not then give error and raise Pragma_Exit.
3908 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
3909 -- Check the specified argument Arg to make sure that it is a valid
3910 -- queuing policy name. If not give error and raise Pragma_Exit.
3912 procedure Check_Arg_Is_OK_Static_Expression
3914 Typ : Entity_Id := Empty);
3915 -- Check the specified argument Arg to make sure that it is a static
3916 -- expression of the given type (i.e. it will be analyzed and resolved
3917 -- using this type, which can be any valid argument to Resolve, e.g.
3918 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3919 -- Typ is left Empty, then any static expression is allowed. Includes
3920 -- checking that the argument does not raise Constraint_Error.
3922 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
3923 -- Check the specified argument Arg to make sure that it is a valid task
3924 -- dispatching policy name. If not give error and raise Pragma_Exit.
3926 procedure Check_Arg_Order (Names : Name_List);
3927 -- Checks for an instance of two arguments with identifiers for the
3928 -- current pragma which are not in the sequence indicated by Names,
3929 -- and if so, generates a fatal message about bad order of arguments.
3931 procedure Check_At_Least_N_Arguments (N : Nat);
3932 -- Check there are at least N arguments present
3934 procedure Check_At_Most_N_Arguments (N : Nat);
3935 -- Check there are no more than N arguments present
3937 procedure Check_Atomic_VFA (E : Entity_Id; VFA : Boolean);
3938 -- Apply legality checks to type or object E subject to an Atomic aspect
3939 -- in Ada 2020 (RM C.6(13)) or to a Volatile_Full_Access aspect.
3941 procedure Check_Component
3944 In_Variant_Part : Boolean := False);
3945 -- Examine an Unchecked_Union component for correct use of per-object
3946 -- constrained subtypes, and for restrictions on finalizable components.
3947 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3948 -- should be set when Comp comes from a record variant.
3950 procedure Check_Duplicate_Pragma (E : Entity_Id);
3951 -- Check if a rep item of the same name as the current pragma is already
3952 -- chained as a rep pragma to the given entity. If so give a message
3953 -- about the duplicate, and then raise Pragma_Exit so does not return.
3954 -- Note that if E is a type, then this routine avoids flagging a pragma
3955 -- which applies to a parent type from which E is derived.
3957 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
3958 -- Nam is an N_String_Literal node containing the external name set by
3959 -- an Import or Export pragma (or extended Import or Export pragma).
3960 -- This procedure checks for possible duplications if this is the export
3961 -- case, and if found, issues an appropriate error message.
3963 procedure Check_Expr_Is_OK_Static_Expression
3965 Typ : Entity_Id := Empty);
3966 -- Check the specified expression Expr to make sure that it is a static
3967 -- expression of the given type (i.e. it will be analyzed and resolved
3968 -- using this type, which can be any valid argument to Resolve, e.g.
3969 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3970 -- Typ is left Empty, then any static expression is allowed. Includes
3971 -- checking that the expression does not raise Constraint_Error.
3973 procedure Check_First_Subtype (Arg : Node_Id);
3974 -- Checks that Arg, whose expression is an entity name, references a
3977 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
3978 -- Checks that the given argument has an identifier, and if so, requires
3979 -- it to match the given identifier name. If there is no identifier, or
3980 -- a non-matching identifier, then an error message is given and
3981 -- Pragma_Exit is raised.
3983 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
3984 -- Checks that the given argument has an identifier, and if so, requires
3985 -- it to match one of the given identifier names. If there is no
3986 -- identifier, or a non-matching identifier, then an error message is
3987 -- given and Pragma_Exit is raised.
3989 procedure Check_In_Main_Program;
3990 -- Common checks for pragmas that appear within a main program
3991 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
3993 procedure Check_Interrupt_Or_Attach_Handler;
3994 -- Common processing for first argument of pragma Interrupt_Handler or
3995 -- pragma Attach_Handler.
3997 procedure Check_Loop_Pragma_Placement;
3998 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
3999 -- appear immediately within a construct restricted to loops, and that
4000 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
4002 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
4003 -- Check that pragma appears in a declarative part, or in a package
4004 -- specification, i.e. that it does not occur in a statement sequence
4007 procedure Check_No_Identifier (Arg : Node_Id);
4008 -- Checks that the given argument does not have an identifier. If
4009 -- an identifier is present, then an error message is issued, and
4010 -- Pragma_Exit is raised.
4012 procedure Check_No_Identifiers;
4013 -- Checks that none of the arguments to the pragma has an identifier.
4014 -- If any argument has an identifier, then an error message is issued,
4015 -- and Pragma_Exit is raised.
4017 procedure Check_No_Link_Name;
4018 -- Checks that no link name is specified
4020 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
4021 -- Checks if the given argument has an identifier, and if so, requires
4022 -- it to match the given identifier name. If there is a non-matching
4023 -- identifier, then an error message is given and Pragma_Exit is raised.
4025 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
4026 -- Checks if the given argument has an identifier, and if so, requires
4027 -- it to match the given identifier name. If there is a non-matching
4028 -- identifier, then an error message is given and Pragma_Exit is raised.
4029 -- In this version of the procedure, the identifier name is given as
4030 -- a string with lower case letters.
4032 procedure Check_Static_Boolean_Expression (Expr : Node_Id);
4033 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
4034 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
4035 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
4036 -- is an OK static boolean expression. Emit an error if this is not the
4039 procedure Check_Static_Constraint (Constr : Node_Id);
4040 -- Constr is a constraint from an N_Subtype_Indication node from a
4041 -- component constraint in an Unchecked_Union type. This routine checks
4042 -- that the constraint is static as required by the restrictions for
4045 procedure Check_Valid_Configuration_Pragma;
4046 -- Legality checks for placement of a configuration pragma
4048 procedure Check_Valid_Library_Unit_Pragma;
4049 -- Legality checks for library unit pragmas. A special case arises for
4050 -- pragmas in generic instances that come from copies of the original
4051 -- library unit pragmas in the generic templates. In the case of other
4052 -- than library level instantiations these can appear in contexts which
4053 -- would normally be invalid (they only apply to the original template
4054 -- and to library level instantiations), and they are simply ignored,
4055 -- which is implemented by rewriting them as null statements.
4057 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
4058 -- Check an Unchecked_Union variant for lack of nested variants and
4059 -- presence of at least one component. UU_Typ is the related Unchecked_
4062 procedure Ensure_Aggregate_Form (Arg : Node_Id);
4063 -- Subsidiary routine to the processing of pragmas Abstract_State,
4064 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
4065 -- Refined_Global and Refined_State. Transform argument Arg into
4066 -- an aggregate if not one already. N_Null is never transformed.
4067 -- Arg may denote an aspect specification or a pragma argument
4070 procedure Error_Pragma (Msg : String);
4071 pragma No_Return (Error_Pragma);
4072 -- Outputs error message for current pragma. The message contains a %
4073 -- that will be replaced with the pragma name, and the flag is placed
4074 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
4075 -- calls Fix_Error (see spec of that procedure for details).
4077 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
4078 pragma No_Return (Error_Pragma_Arg);
4079 -- Outputs error message for current pragma. The message may contain
4080 -- a % that will be replaced with the pragma name. The parameter Arg
4081 -- may either be a pragma argument association, in which case the flag
4082 -- is placed on the expression of this association, or an expression,
4083 -- in which case the flag is placed directly on the expression. The
4084 -- message is placed using Error_Msg_N, so the message may also contain
4085 -- an & insertion character which will reference the given Arg value.
4086 -- After placing the message, Pragma_Exit is raised. Note: this routine
4087 -- calls Fix_Error (see spec of that procedure for details).
4089 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
4090 pragma No_Return (Error_Pragma_Arg);
4091 -- Similar to above form of Error_Pragma_Arg except that two messages
4092 -- are provided, the second is a continuation comment starting with \.
4094 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
4095 pragma No_Return (Error_Pragma_Arg_Ident);
4096 -- Outputs error message for current pragma. The message may contain a %
4097 -- that will be replaced with the pragma name. The parameter Arg must be
4098 -- a pragma argument association with a non-empty identifier (i.e. its
4099 -- Chars field must be set), and the error message is placed on the
4100 -- identifier. The message is placed using Error_Msg_N so the message
4101 -- may also contain an & insertion character which will reference
4102 -- the identifier. After placing the message, Pragma_Exit is raised.
4103 -- Note: this routine calls Fix_Error (see spec of that procedure for
4106 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
4107 pragma No_Return (Error_Pragma_Ref);
4108 -- Outputs error message for current pragma. The message may contain
4109 -- a % that will be replaced with the pragma name. The parameter Ref
4110 -- must be an entity whose name can be referenced by & and sloc by #.
4111 -- After placing the message, Pragma_Exit is raised. Note: this routine
4112 -- calls Fix_Error (see spec of that procedure for details).
4114 function Find_Lib_Unit_Name return Entity_Id;
4115 -- Used for a library unit pragma to find the entity to which the
4116 -- library unit pragma applies, returns the entity found.
4118 procedure Find_Program_Unit_Name (Id : Node_Id);
4119 -- If the pragma is a compilation unit pragma, the id must denote the
4120 -- compilation unit in the same compilation, and the pragma must appear
4121 -- in the list of preceding or trailing pragmas. If it is a program
4122 -- unit pragma that is not a compilation unit pragma, then the
4123 -- identifier must be visible.
4125 function Find_Unique_Parameterless_Procedure
4127 Arg : Node_Id) return Entity_Id;
4128 -- Used for a procedure pragma to find the unique parameterless
4129 -- procedure identified by Name, returns it if it exists, otherwise
4130 -- errors out and uses Arg as the pragma argument for the message.
4132 function Fix_Error (Msg : String) return String;
4133 -- This is called prior to issuing an error message. Msg is the normal
4134 -- error message issued in the pragma case. This routine checks for the
4135 -- case of a pragma coming from an aspect in the source, and returns a
4136 -- message suitable for the aspect case as follows:
4138 -- Each substring "pragma" is replaced by "aspect"
4140 -- If "argument of" is at the start of the error message text, it is
4141 -- replaced by "entity for".
4143 -- If "argument" is at the start of the error message text, it is
4144 -- replaced by "entity".
4146 -- So for example, "argument of pragma X must be discrete type"
4147 -- returns "entity for aspect X must be a discrete type".
4149 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
4150 -- be different from the pragma name). If the current pragma results
4151 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
4152 -- original pragma name.
4154 procedure Gather_Associations
4156 Args : out Args_List);
4157 -- This procedure is used to gather the arguments for a pragma that
4158 -- permits arbitrary ordering of parameters using the normal rules
4159 -- for named and positional parameters. The Names argument is a list
4160 -- of Name_Id values that corresponds to the allowed pragma argument
4161 -- association identifiers in order. The result returned in Args is
4162 -- a list of corresponding expressions that are the pragma arguments.
4163 -- Note that this is a list of expressions, not of pragma argument
4164 -- associations (Gather_Associations has completely checked all the
4165 -- optional identifiers when it returns). An entry in Args is Empty
4166 -- on return if the corresponding argument is not present.
4168 procedure GNAT_Pragma;
4169 -- Called for all GNAT defined pragmas to check the relevant restriction
4170 -- (No_Implementation_Pragmas).
4172 function Is_Before_First_Decl
4173 (Pragma_Node : Node_Id;
4174 Decls : List_Id) return Boolean;
4175 -- Return True if Pragma_Node is before the first declarative item in
4176 -- Decls where Decls is the list of declarative items.
4178 function Is_Configuration_Pragma return Boolean;
4179 -- Determines if the placement of the current pragma is appropriate
4180 -- for a configuration pragma.
4182 function Is_In_Context_Clause return Boolean;
4183 -- Returns True if pragma appears within the context clause of a unit,
4184 -- and False for any other placement (does not generate any messages).
4186 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
4187 -- Analyzes the argument, and determines if it is a static string
4188 -- expression, returns True if so, False if non-static or not String.
4189 -- A special case is that a string literal returns True in Ada 83 mode
4190 -- (which has no such thing as static string expressions). Note that
4191 -- the call analyzes its argument, so this cannot be used for the case
4192 -- where an identifier might not be declared.
4194 procedure Pragma_Misplaced;
4195 pragma No_Return (Pragma_Misplaced);
4196 -- Issue fatal error message for misplaced pragma
4198 procedure Process_Atomic_Independent_Shared_Volatile;
4199 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
4200 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
4201 -- and treated as being identical in effect to pragma Atomic.
4203 procedure Process_Compile_Time_Warning_Or_Error;
4204 -- Common processing for Compile_Time_Error and Compile_Time_Warning
4206 procedure Process_Convention
4207 (C : out Convention_Id;
4208 Ent : out Entity_Id);
4209 -- Common processing for Convention, Interface, Import and Export.
4210 -- Checks first two arguments of pragma, and sets the appropriate
4211 -- convention value in the specified entity or entities. On return
4212 -- C is the convention, Ent is the referenced entity.
4214 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
4215 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
4216 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
4218 procedure Process_Extended_Import_Export_Object_Pragma
4219 (Arg_Internal : Node_Id;
4220 Arg_External : Node_Id;
4221 Arg_Size : Node_Id);
4222 -- Common processing for the pragmas Import/Export_Object. The three
4223 -- arguments correspond to the three named parameters of the pragmas. An
4224 -- argument is empty if the corresponding parameter is not present in
4227 procedure Process_Extended_Import_Export_Internal_Arg
4228 (Arg_Internal : Node_Id := Empty);
4229 -- Common processing for all extended Import and Export pragmas. The
4230 -- argument is the pragma parameter for the Internal argument. If
4231 -- Arg_Internal is empty or inappropriate, an error message is posted.
4232 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
4233 -- set to identify the referenced entity.
4235 procedure Process_Extended_Import_Export_Subprogram_Pragma
4236 (Arg_Internal : Node_Id;
4237 Arg_External : Node_Id;
4238 Arg_Parameter_Types : Node_Id;
4239 Arg_Result_Type : Node_Id := Empty;
4240 Arg_Mechanism : Node_Id;
4241 Arg_Result_Mechanism : Node_Id := Empty);
4242 -- Common processing for all extended Import and Export pragmas applying
4243 -- to subprograms. The caller omits any arguments that do not apply to
4244 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
4245 -- only in the Import_Function and Export_Function cases). The argument
4246 -- names correspond to the allowed pragma association identifiers.
4248 procedure Process_Generic_List;
4249 -- Common processing for Share_Generic and Inline_Generic
4251 procedure Process_Import_Or_Interface;
4252 -- Common processing for Import or Interface
4254 procedure Process_Import_Predefined_Type;
4255 -- Processing for completing a type with pragma Import. This is used
4256 -- to declare types that match predefined C types, especially for cases
4257 -- without corresponding Ada predefined type.
4259 type Inline_Status is (Suppressed, Disabled, Enabled);
4260 -- Inline status of a subprogram, indicated as follows:
4261 -- Suppressed: inlining is suppressed for the subprogram
4262 -- Disabled: no inlining is requested for the subprogram
4263 -- Enabled: inlining is requested/required for the subprogram
4265 procedure Process_Inline (Status : Inline_Status);
4266 -- Common processing for No_Inline, Inline and Inline_Always. Parameter
4267 -- indicates the inline status specified by the pragma.
4269 procedure Process_Interface_Name
4270 (Subprogram_Def : Entity_Id;
4274 -- Given the last two arguments of pragma Import, pragma Export, or
4275 -- pragma Interface_Name, performs validity checks and sets the
4276 -- Interface_Name field of the given subprogram entity to the
4277 -- appropriate external or link name, depending on the arguments given.
4278 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
4279 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
4280 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
4281 -- nor Link_Arg is present, the interface name is set to the default
4282 -- from the subprogram name. In addition, the pragma itself is passed
4283 -- to analyze any expressions in the case the pragma came from an aspect
4286 procedure Process_Interrupt_Or_Attach_Handler;
4287 -- Common processing for Interrupt and Attach_Handler pragmas
4289 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
4290 -- Common processing for Restrictions and Restriction_Warnings pragmas.
4291 -- Warn is True for Restriction_Warnings, or for Restrictions if the
4292 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
4293 -- is not set in the Restrictions case.
4295 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
4296 -- Common processing for Suppress and Unsuppress. The boolean parameter
4297 -- Suppress_Case is True for the Suppress case, and False for the
4300 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id);
4301 -- Subsidiary to the analysis of pragmas Independent[_Components].
4302 -- Record such a pragma N applied to entity E for future checks.
4304 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
4305 -- This procedure sets the Is_Exported flag for the given entity,
4306 -- checking that the entity was not previously imported. Arg is
4307 -- the argument that specified the entity. A check is also made
4308 -- for exporting inappropriate entities.
4310 procedure Set_Extended_Import_Export_External_Name
4311 (Internal_Ent : Entity_Id;
4312 Arg_External : Node_Id);
4313 -- Common processing for all extended import export pragmas. The first
4314 -- argument, Internal_Ent, is the internal entity, which has already
4315 -- been checked for validity by the caller. Arg_External is from the
4316 -- Import or Export pragma, and may be null if no External parameter
4317 -- was present. If Arg_External is present and is a non-null string
4318 -- (a null string is treated as the default), then the Interface_Name
4319 -- field of Internal_Ent is set appropriately.
4321 procedure Set_Imported (E : Entity_Id);
4322 -- This procedure sets the Is_Imported flag for the given entity,
4323 -- checking that it is not previously exported or imported.
4325 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
4326 -- Mech is a parameter passing mechanism (see Import_Function syntax
4327 -- for MECHANISM_NAME). This routine checks that the mechanism argument
4328 -- has the right form, and if not issues an error message. If the
4329 -- argument has the right form then the Mechanism field of Ent is
4330 -- set appropriately.
4332 procedure Set_Rational_Profile;
4333 -- Activate the set of configuration pragmas and permissions that make
4334 -- up the Rational profile.
4336 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id);
4337 -- Activate the set of configuration pragmas and restrictions that make
4338 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar,
4339 -- GNAT_Ravenscar_EDF, or Ravenscar. N is the corresponding pragma node,
4340 -- which is used for error messages on any constructs violating the
4343 procedure Validate_Acc_Condition_Clause (Clause : Node_Id);
4344 -- Make sure the argument of a given Acc_If clause is a Boolean
4346 procedure Validate_Acc_Data_Clause (Clause : Node_Id);
4347 -- Make sure the argument of an OpenAcc data clause (e.g. Copy, Copyin,
4348 -- Copyout...) is an identifier or an aggregate of identifiers.
4350 procedure Validate_Acc_Int_Expr_Clause (Clause : Node_Id);
4351 -- Make sure the argument of an OpenAcc clause is an Integer expression
4353 procedure Validate_Acc_Int_Expr_List_Clause (Clause : Node_Id);
4354 -- Make sure the argument of an OpenAcc clause is an Integer expression
4355 -- or a list of Integer expressions.
4357 procedure Validate_Acc_Loop_Collapse (Clause : Node_Id);
4358 -- Make sure that the parent loop of the Acc_Loop(Collapse => N) pragma
4359 -- contains at least N-1 nested loops.
4361 procedure Validate_Acc_Loop_Gang (Clause : Node_Id);
4362 -- Make sure the argument of the Gang clause of a Loop directive is
4363 -- either an integer expression or a (Static => integer expressions)
4366 procedure Validate_Acc_Loop_Vector (Clause : Node_Id);
4367 -- When this procedure is called in a construct offloaded by an
4368 -- Acc_Kernels pragma, makes sure that a Vector_Length clause does
4369 -- not exist on said pragma. In all cases, make sure the argument
4370 -- is an Integer expression.
4372 procedure Validate_Acc_Loop_Worker (Clause : Node_Id);
4373 -- When this procedure is called in a construct offloaded by an
4374 -- Acc_Parallel pragma, makes sure that no argument has been given.
4375 -- When this procedure is called in a construct offloaded by an
4376 -- Acc_Kernels pragma and if Loop_Worker was given an argument,
4377 -- makes sure that the Num_Workers clause does not appear on the
4378 -- Acc_Kernels pragma and that the argument is an integer.
4380 procedure Validate_Acc_Name_Reduction (Clause : Node_Id);
4381 -- Make sure the reduction clause is an aggregate made of a string
4382 -- representing a supported reduction operation (i.e. "+", "*", "and",
4383 -- "or", "min" or "max") and either an identifier or aggregate of
4386 procedure Validate_Acc_Size_Expressions (Clause : Node_Id);
4387 -- Makes sure that Clause is either an integer expression or an
4388 -- association with a Static as name and a list of integer expressions
4389 -- or "*" strings on the right hand side.
4395 function Acc_First (N : Node_Id) return Node_Id is
4397 if Nkind (N) = N_Aggregate then
4398 if Present (Expressions (N)) then
4399 return First (Expressions (N));
4401 elsif Present (Component_Associations (N)) then
4402 return Expression (First (Component_Associations (N)));
4413 function Acc_Next (N : Node_Id) return Node_Id is
4415 if Nkind (Parent (N)) = N_Component_Association then
4416 return Expression (Next (Parent (N)));
4418 elsif Nkind (Parent (N)) = N_Aggregate then
4426 ---------------------
4427 -- Ada_2005_Pragma --
4428 ---------------------
4430 procedure Ada_2005_Pragma is
4432 if Ada_Version <= Ada_95 then
4433 Check_Restriction (No_Implementation_Pragmas, N);
4435 end Ada_2005_Pragma;
4437 ---------------------
4438 -- Ada_2012_Pragma --
4439 ---------------------
4441 procedure Ada_2012_Pragma is
4443 if Ada_Version <= Ada_2005 then
4444 Check_Restriction (No_Implementation_Pragmas, N);
4446 end Ada_2012_Pragma;
4448 ----------------------------
4449 -- Analyze_Depends_Global --
4450 ----------------------------
4452 procedure Analyze_Depends_Global
4453 (Spec_Id : out Entity_Id;
4454 Subp_Decl : out Node_Id;
4455 Legal : out Boolean)
4458 -- Assume that the pragma is illegal
4465 Check_Arg_Count (1);
4467 -- Ensure the proper placement of the pragma. Depends/Global must be
4468 -- associated with a subprogram declaration or a body that acts as a
4471 Subp_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4475 if Nkind (Subp_Decl) = N_Entry_Declaration then
4478 -- Generic subprogram
4480 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4483 -- Object declaration of a single concurrent type
4485 elsif Nkind (Subp_Decl) = N_Object_Declaration
4486 and then Is_Single_Concurrent_Object
4487 (Unique_Defining_Entity (Subp_Decl))
4493 elsif Nkind (Subp_Decl) = N_Single_Task_Declaration then
4496 -- Subprogram body acts as spec
4498 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4499 and then No (Corresponding_Spec (Subp_Decl))
4503 -- Subprogram body stub acts as spec
4505 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4506 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
4510 -- Subprogram declaration
4512 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4517 elsif Nkind (Subp_Decl) = N_Task_Type_Declaration then
4525 -- If we get here, then the pragma is legal
4528 Spec_Id := Unique_Defining_Entity (Subp_Decl);
4530 -- When the related context is an entry, the entry must belong to a
4531 -- protected unit (SPARK RM 6.1.4(6)).
4533 if Is_Entry_Declaration (Spec_Id)
4534 and then Ekind (Scope (Spec_Id)) /= E_Protected_Type
4539 -- When the related context is an anonymous object created for a
4540 -- simple concurrent type, the type must be a task
4541 -- (SPARK RM 6.1.4(6)).
4543 elsif Is_Single_Concurrent_Object (Spec_Id)
4544 and then Ekind (Etype (Spec_Id)) /= E_Task_Type
4550 -- A pragma that applies to a Ghost entity becomes Ghost for the
4551 -- purposes of legality checks and removal of ignored Ghost code.
4553 Mark_Ghost_Pragma (N, Spec_Id);
4554 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4555 end Analyze_Depends_Global;
4557 ------------------------
4558 -- Analyze_If_Present --
4559 ------------------------
4561 procedure Analyze_If_Present (Id : Pragma_Id) is
4565 pragma Assert (Is_List_Member (N));
4567 -- Inspect the declarations or statements following pragma N looking
4568 -- for another pragma whose Id matches the caller's request. If it is
4569 -- available, analyze it.
4572 while Present (Stmt) loop
4573 if Nkind (Stmt) = N_Pragma and then Get_Pragma_Id (Stmt) = Id then
4574 Analyze_Pragma (Stmt);
4577 -- The first source declaration or statement immediately following
4578 -- N ends the region where a pragma may appear.
4580 elsif Comes_From_Source (Stmt) then
4586 end Analyze_If_Present;
4588 --------------------------------
4589 -- Analyze_Pre_Post_Condition --
4590 --------------------------------
4592 procedure Analyze_Pre_Post_Condition is
4593 Prag_Iden : constant Node_Id := Pragma_Identifier (N);
4594 Subp_Decl : Node_Id;
4595 Subp_Id : Entity_Id;
4597 Duplicates_OK : Boolean := False;
4598 -- Flag set when a pre/postcondition allows multiple pragmas of the
4601 In_Body_OK : Boolean := False;
4602 -- Flag set when a pre/postcondition is allowed to appear on a body
4603 -- even though the subprogram may have a spec.
4605 Is_Pre_Post : Boolean := False;
4606 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4609 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean;
4610 -- Implement rules in AI12-0131: an overriding operation can have
4611 -- a class-wide precondition only if one of its ancestors has an
4612 -- explicit class-wide precondition.
4614 -----------------------------
4615 -- Inherits_Class_Wide_Pre --
4616 -----------------------------
4618 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean is
4619 Typ : constant Entity_Id := Find_Dispatching_Type (E);
4622 Prev : Entity_Id := Overridden_Operation (E);
4625 -- Check ancestors on the overriding operation to examine the
4626 -- preconditions that may apply to them.
4628 while Present (Prev) loop
4629 Cont := Contract (Prev);
4630 if Present (Cont) then
4631 Prag := Pre_Post_Conditions (Cont);
4632 while Present (Prag) loop
4633 if Pragma_Name (Prag) = Name_Precondition
4634 and then Class_Present (Prag)
4639 Prag := Next_Pragma (Prag);
4643 -- For a type derived from a generic formal type, the operation
4644 -- inheriting the condition is a renaming, not an overriding of
4645 -- the operation of the formal. Ditto for an inherited
4646 -- operation which has no explicit contracts.
4648 if Is_Generic_Type (Find_Dispatching_Type (Prev))
4649 or else not Comes_From_Source (Prev)
4651 Prev := Alias (Prev);
4653 Prev := Overridden_Operation (Prev);
4657 -- If the controlling type of the subprogram has progenitors, an
4658 -- interface operation implemented by the current operation may
4659 -- have a class-wide precondition.
4661 if Has_Interfaces (Typ) then
4666 Prim_Elmt : Elmt_Id;
4667 Prim_List : Elist_Id;
4670 Collect_Interfaces (Typ, Ints);
4671 Elmt := First_Elmt (Ints);
4673 -- Iterate over the primitive operations of each interface
4675 while Present (Elmt) loop
4676 Prim_List := Direct_Primitive_Operations (Node (Elmt));
4677 Prim_Elmt := First_Elmt (Prim_List);
4678 while Present (Prim_Elmt) loop
4679 Prim := Node (Prim_Elmt);
4680 if Chars (Prim) = Chars (E)
4681 and then Present (Contract (Prim))
4682 and then Class_Present
4683 (Pre_Post_Conditions (Contract (Prim)))
4688 Next_Elmt (Prim_Elmt);
4697 end Inherits_Class_Wide_Pre;
4699 -- Start of processing for Analyze_Pre_Post_Condition
4702 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4703 -- offer uniformity among the various kinds of pre/postconditions by
4704 -- rewriting the pragma identifier. This allows the retrieval of the
4705 -- original pragma name by routine Original_Aspect_Pragma_Name.
4707 if Comes_From_Source (N) then
4708 if Nam_In (Pname, Name_Pre, Name_Pre_Class) then
4709 Is_Pre_Post := True;
4710 Set_Class_Present (N, Pname = Name_Pre_Class);
4711 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition));
4713 elsif Nam_In (Pname, Name_Post, Name_Post_Class) then
4714 Is_Pre_Post := True;
4715 Set_Class_Present (N, Pname = Name_Post_Class);
4716 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition));
4720 -- Determine the semantics with respect to duplicates and placement
4721 -- in a body. Pragmas Precondition and Postcondition were introduced
4722 -- before aspects and are not subject to the same aspect-like rules.
4724 if Nam_In (Pname, Name_Precondition, Name_Postcondition) then
4725 Duplicates_OK := True;
4731 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4732 -- argument without an identifier.
4735 Check_Arg_Count (1);
4736 Check_No_Identifiers;
4738 -- Pragmas Precondition and Postcondition have complex argument
4742 Check_At_Least_N_Arguments (1);
4743 Check_At_Most_N_Arguments (2);
4744 Check_Optional_Identifier (Arg1, Name_Check);
4746 if Present (Arg2) then
4747 Check_Optional_Identifier (Arg2, Name_Message);
4748 Preanalyze_Spec_Expression
4749 (Get_Pragma_Arg (Arg2), Standard_String);
4753 -- For a pragma PPC in the extended main source unit, record enabled
4755 -- ??? nothing checks that the pragma is in the main source unit
4757 if Is_Checked (N) and then not Split_PPC (N) then
4758 Set_SCO_Pragma_Enabled (Loc);
4761 -- Ensure the proper placement of the pragma
4764 Find_Related_Declaration_Or_Body
4765 (N, Do_Checks => not Duplicates_OK);
4767 -- When a pre/postcondition pragma applies to an abstract subprogram,
4768 -- its original form must be an aspect with 'Class.
4770 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
4771 if not From_Aspect_Specification (N) then
4773 ("pragma % cannot be applied to abstract subprogram");
4775 elsif not Class_Present (N) then
4777 ("aspect % requires ''Class for abstract subprogram");
4780 -- Entry declaration
4782 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
4785 -- Generic subprogram declaration
4787 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4792 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4793 and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK)
4797 -- Subprogram body stub
4799 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4800 and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK)
4804 -- Subprogram declaration
4806 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4808 -- AI05-0230: When a pre/postcondition pragma applies to a null
4809 -- procedure, its original form must be an aspect with 'Class.
4811 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
4812 and then Null_Present (Specification (Subp_Decl))
4813 and then From_Aspect_Specification (N)
4814 and then not Class_Present (N)
4816 Error_Pragma ("aspect % requires ''Class for null procedure");
4819 -- Implement the legality checks mandated by AI12-0131:
4820 -- Pre'Class shall not be specified for an overriding primitive
4821 -- subprogram of a tagged type T unless the Pre'Class aspect is
4822 -- specified for the corresponding primitive subprogram of some
4826 E : constant Entity_Id := Defining_Entity (Subp_Decl);
4829 if Class_Present (N)
4830 and then Pragma_Name (N) = Name_Precondition
4831 and then Present (Overridden_Operation (E))
4832 and then not Inherits_Class_Wide_Pre (E)
4835 ("illegal class-wide precondition on overriding operation",
4836 Corresponding_Aspect (N));
4840 -- A renaming declaration may inherit a generated pragma, its
4841 -- placement comes from expansion, not from source.
4843 elsif Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration
4844 and then not Comes_From_Source (N)
4848 -- Otherwise the placement is illegal
4855 Subp_Id := Defining_Entity (Subp_Decl);
4857 -- A pragma that applies to a Ghost entity becomes Ghost for the
4858 -- purposes of legality checks and removal of ignored Ghost code.
4860 Mark_Ghost_Pragma (N, Subp_Id);
4862 -- Chain the pragma on the contract for further processing by
4863 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4865 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
4867 -- Fully analyze the pragma when it appears inside an entry or
4868 -- subprogram body because it cannot benefit from forward references.
4870 if Nkind_In (Subp_Decl, N_Entry_Body,
4872 N_Subprogram_Body_Stub)
4874 -- The legality checks of pragmas Precondition and Postcondition
4875 -- are affected by the SPARK mode in effect and the volatility of
4876 -- the context. Analyze all pragmas in a specific order.
4878 Analyze_If_Present (Pragma_SPARK_Mode);
4879 Analyze_If_Present (Pragma_Volatile_Function);
4880 Analyze_Pre_Post_Condition_In_Decl_Part (N);
4882 end Analyze_Pre_Post_Condition;
4884 -----------------------------------------
4885 -- Analyze_Refined_Depends_Global_Post --
4886 -----------------------------------------
4888 procedure Analyze_Refined_Depends_Global_Post
4889 (Spec_Id : out Entity_Id;
4890 Body_Id : out Entity_Id;
4891 Legal : out Boolean)
4893 Body_Decl : Node_Id;
4894 Spec_Decl : Node_Id;
4897 -- Assume that the pragma is illegal
4904 Check_Arg_Count (1);
4905 Check_No_Identifiers;
4907 -- Verify the placement of the pragma and check for duplicates. The
4908 -- pragma must apply to a subprogram body [stub].
4910 Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4912 if not Nkind_In (Body_Decl, N_Entry_Body,
4914 N_Subprogram_Body_Stub,
4922 Body_Id := Defining_Entity (Body_Decl);
4923 Spec_Id := Unique_Defining_Entity (Body_Decl);
4925 -- The pragma must apply to the second declaration of a subprogram.
4926 -- In other words, the body [stub] cannot acts as a spec.
4928 if No (Spec_Id) then
4929 Error_Pragma ("pragma % cannot apply to a stand alone body");
4932 -- Catch the case where the subprogram body is a subunit and acts as
4933 -- the third declaration of the subprogram.
4935 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
4936 Error_Pragma ("pragma % cannot apply to a subunit");
4940 -- A refined pragma can only apply to the body [stub] of a subprogram
4941 -- declared in the visible part of a package. Retrieve the context of
4942 -- the subprogram declaration.
4944 Spec_Decl := Unit_Declaration_Node (Spec_Id);
4946 -- When dealing with protected entries or protected subprograms, use
4947 -- the enclosing protected type as the proper context.
4949 if Ekind_In (Spec_Id, E_Entry,
4953 and then Ekind (Scope (Spec_Id)) = E_Protected_Type
4955 Spec_Decl := Declaration_Node (Scope (Spec_Id));
4958 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
4960 (Fix_Msg (Spec_Id, "pragma % must apply to the body of "
4961 & "subprogram declared in a package specification"));
4965 -- If we get here, then the pragma is legal
4969 -- A pragma that applies to a Ghost entity becomes Ghost for the
4970 -- purposes of legality checks and removal of ignored Ghost code.
4972 Mark_Ghost_Pragma (N, Spec_Id);
4974 if Nam_In (Pname, Name_Refined_Depends, Name_Refined_Global) then
4975 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4977 end Analyze_Refined_Depends_Global_Post;
4979 ----------------------------------
4980 -- Analyze_Unmodified_Or_Unused --
4981 ----------------------------------
4983 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False) is
4988 Ghost_Error_Posted : Boolean := False;
4989 -- Flag set when an error concerning the illegal mix of Ghost and
4990 -- non-Ghost variables is emitted.
4992 Ghost_Id : Entity_Id := Empty;
4993 -- The entity of the first Ghost variable encountered while
4994 -- processing the arguments of the pragma.
4998 Check_At_Least_N_Arguments (1);
5000 -- Loop through arguments
5003 while Present (Arg) loop
5004 Check_No_Identifier (Arg);
5006 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
5007 -- in fact generate reference, so that the entity will have a
5008 -- reference, which will inhibit any warnings about it not
5009 -- being referenced, and also properly show up in the ali file
5010 -- as a reference. But this reference is recorded before the
5011 -- Has_Pragma_Unreferenced flag is set, so that no warning is
5012 -- generated for this reference.
5014 Check_Arg_Is_Local_Name (Arg);
5015 Arg_Expr := Get_Pragma_Arg (Arg);
5017 if Is_Entity_Name (Arg_Expr) then
5018 Arg_Id := Entity (Arg_Expr);
5020 -- Skip processing the argument if already flagged
5022 if Is_Assignable (Arg_Id)
5023 and then not Has_Pragma_Unmodified (Arg_Id)
5024 and then not Has_Pragma_Unused (Arg_Id)
5026 Set_Has_Pragma_Unmodified (Arg_Id);
5029 Set_Has_Pragma_Unused (Arg_Id);
5032 -- A pragma that applies to a Ghost entity becomes Ghost for
5033 -- the purposes of legality checks and removal of ignored
5036 Mark_Ghost_Pragma (N, Arg_Id);
5038 -- Capture the entity of the first Ghost variable being
5039 -- processed for error detection purposes.
5041 if Is_Ghost_Entity (Arg_Id) then
5042 if No (Ghost_Id) then
5046 -- Otherwise the variable is non-Ghost. It is illegal to mix
5047 -- references to Ghost and non-Ghost entities
5050 elsif Present (Ghost_Id)
5051 and then not Ghost_Error_Posted
5053 Ghost_Error_Posted := True;
5055 Error_Msg_Name_1 := Pname;
5057 ("pragma % cannot mention ghost and non-ghost "
5060 Error_Msg_Sloc := Sloc (Ghost_Id);
5061 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
5063 Error_Msg_Sloc := Sloc (Arg_Id);
5064 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
5067 -- Warn if already flagged as Unused or Unmodified
5069 elsif Has_Pragma_Unmodified (Arg_Id) then
5070 if Has_Pragma_Unused (Arg_Id) then
5072 ("??pragma Unused already given for &!", Arg_Expr,
5076 ("??pragma Unmodified already given for &!", Arg_Expr,
5080 -- Otherwise the pragma referenced an illegal entity
5084 ("pragma% can only be applied to a variable", Arg_Expr);
5090 end Analyze_Unmodified_Or_Unused;
5092 ------------------------------------
5093 -- Analyze_Unreferenced_Or_Unused --
5094 ------------------------------------
5096 procedure Analyze_Unreferenced_Or_Unused
5097 (Is_Unused : Boolean := False)
5104 Ghost_Error_Posted : Boolean := False;
5105 -- Flag set when an error concerning the illegal mix of Ghost and
5106 -- non-Ghost names is emitted.
5108 Ghost_Id : Entity_Id := Empty;
5109 -- The entity of the first Ghost name encountered while processing
5110 -- the arguments of the pragma.
5114 Check_At_Least_N_Arguments (1);
5116 -- Check case of appearing within context clause
5118 if not Is_Unused and then Is_In_Context_Clause then
5120 -- The arguments must all be units mentioned in a with clause in
5121 -- the same context clause. Note that Par.Prag already checked
5122 -- that the arguments are either identifiers or selected
5126 while Present (Arg) loop
5127 Citem := First (List_Containing (N));
5128 while Citem /= N loop
5129 Arg_Expr := Get_Pragma_Arg (Arg);
5131 if Nkind (Citem) = N_With_Clause
5132 and then Same_Name (Name (Citem), Arg_Expr)
5134 Set_Has_Pragma_Unreferenced
5137 (Library_Unit (Citem))));
5138 Set_Elab_Unit_Name (Arg_Expr, Name (Citem));
5147 ("argument of pragma% is not withed unit", Arg);
5153 -- Case of not in list of context items
5157 while Present (Arg) loop
5158 Check_No_Identifier (Arg);
5160 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
5161 -- in fact generate reference, so that the entity will have a
5162 -- reference, which will inhibit any warnings about it not
5163 -- being referenced, and also properly show up in the ali file
5164 -- as a reference. But this reference is recorded before the
5165 -- Has_Pragma_Unreferenced flag is set, so that no warning is
5166 -- generated for this reference.
5168 Check_Arg_Is_Local_Name (Arg);
5169 Arg_Expr := Get_Pragma_Arg (Arg);
5171 if Is_Entity_Name (Arg_Expr) then
5172 Arg_Id := Entity (Arg_Expr);
5174 -- Warn if already flagged as Unused or Unreferenced and
5175 -- skip processing the argument.
5177 if Has_Pragma_Unreferenced (Arg_Id) then
5178 if Has_Pragma_Unused (Arg_Id) then
5180 ("??pragma Unused already given for &!", Arg_Expr,
5184 ("??pragma Unreferenced already given for &!",
5188 -- Apply Unreferenced to the entity
5191 -- If the entity is overloaded, the pragma applies to the
5192 -- most recent overloading, as documented. In this case,
5193 -- name resolution does not generate a reference, so it
5194 -- must be done here explicitly.
5196 if Is_Overloaded (Arg_Expr) then
5197 Generate_Reference (Arg_Id, N);
5200 Set_Has_Pragma_Unreferenced (Arg_Id);
5203 Set_Has_Pragma_Unused (Arg_Id);
5206 -- A pragma that applies to a Ghost entity becomes Ghost
5207 -- for the purposes of legality checks and removal of
5208 -- ignored Ghost code.
5210 Mark_Ghost_Pragma (N, Arg_Id);
5212 -- Capture the entity of the first Ghost name being
5213 -- processed for error detection purposes.
5215 if Is_Ghost_Entity (Arg_Id) then
5216 if No (Ghost_Id) then
5220 -- Otherwise the name is non-Ghost. It is illegal to mix
5221 -- references to Ghost and non-Ghost entities
5224 elsif Present (Ghost_Id)
5225 and then not Ghost_Error_Posted
5227 Ghost_Error_Posted := True;
5229 Error_Msg_Name_1 := Pname;
5231 ("pragma % cannot mention ghost and non-ghost "
5234 Error_Msg_Sloc := Sloc (Ghost_Id);
5236 ("\& # declared as ghost", N, Ghost_Id);
5238 Error_Msg_Sloc := Sloc (Arg_Id);
5240 ("\& # declared as non-ghost", N, Arg_Id);
5248 end Analyze_Unreferenced_Or_Unused;
5250 --------------------------
5251 -- Check_Ada_83_Warning --
5252 --------------------------
5254 procedure Check_Ada_83_Warning is
5256 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5257 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
5259 end Check_Ada_83_Warning;
5261 ---------------------
5262 -- Check_Arg_Count --
5263 ---------------------
5265 procedure Check_Arg_Count (Required : Nat) is
5267 if Arg_Count /= Required then
5268 Error_Pragma ("wrong number of arguments for pragma%");
5270 end Check_Arg_Count;
5272 --------------------------------
5273 -- Check_Arg_Is_External_Name --
5274 --------------------------------
5276 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
5277 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5280 if Nkind (Argx) = N_Identifier then
5284 Analyze_And_Resolve (Argx, Standard_String);
5286 if Is_OK_Static_Expression (Argx) then
5289 elsif Etype (Argx) = Any_Type then
5292 -- An interesting special case, if we have a string literal and
5293 -- we are in Ada 83 mode, then we allow it even though it will
5294 -- not be flagged as static. This allows expected Ada 83 mode
5295 -- use of external names which are string literals, even though
5296 -- technically these are not static in Ada 83.
5298 elsif Ada_Version = Ada_83
5299 and then Nkind (Argx) = N_String_Literal
5303 -- Here we have a real error (non-static expression)
5306 Error_Msg_Name_1 := Pname;
5307 Flag_Non_Static_Expr
5308 (Fix_Error ("argument for pragma% must be a identifier or "
5309 & "static string expression!"), Argx);
5314 end Check_Arg_Is_External_Name;
5316 -----------------------------
5317 -- Check_Arg_Is_Identifier --
5318 -----------------------------
5320 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
5321 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5323 if Nkind (Argx) /= N_Identifier then
5324 Error_Pragma_Arg ("argument for pragma% must be identifier", Argx);
5326 end Check_Arg_Is_Identifier;
5328 ----------------------------------
5329 -- Check_Arg_Is_Integer_Literal --
5330 ----------------------------------
5332 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
5333 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5335 if Nkind (Argx) /= N_Integer_Literal then
5337 ("argument for pragma% must be integer literal", Argx);
5339 end Check_Arg_Is_Integer_Literal;
5341 -------------------------------------------
5342 -- Check_Arg_Is_Library_Level_Local_Name --
5343 -------------------------------------------
5347 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5348 -- | library_unit_NAME
5350 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
5352 Check_Arg_Is_Local_Name (Arg);
5354 -- If it came from an aspect, we want to give the error just as if it
5355 -- came from source.
5357 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
5358 and then (Comes_From_Source (N)
5359 or else Present (Corresponding_Aspect (Parent (Arg))))
5362 ("argument for pragma% must be library level entity", Arg);
5364 end Check_Arg_Is_Library_Level_Local_Name;
5366 -----------------------------
5367 -- Check_Arg_Is_Local_Name --
5368 -----------------------------
5372 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5373 -- | library_unit_NAME
5375 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
5376 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5379 -- If this pragma came from an aspect specification, we don't want to
5380 -- check for this error, because that would cause spurious errors, in
5381 -- case a type is frozen in a scope more nested than the type. The
5382 -- aspect itself of course can't be anywhere but on the declaration
5385 if Nkind (Arg) = N_Pragma_Argument_Association then
5386 if From_Aspect_Specification (Parent (Arg)) then
5390 -- Arg is the Expression of an N_Pragma_Argument_Association
5393 if From_Aspect_Specification (Parent (Parent (Arg))) then
5400 if Nkind (Argx) not in N_Direct_Name
5401 and then (Nkind (Argx) /= N_Attribute_Reference
5402 or else Present (Expressions (Argx))
5403 or else Nkind (Prefix (Argx)) /= N_Identifier)
5404 and then (not Is_Entity_Name (Argx)
5405 or else not Is_Compilation_Unit (Entity (Argx)))
5407 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
5410 -- No further check required if not an entity name
5412 if not Is_Entity_Name (Argx) then
5418 Ent : constant Entity_Id := Entity (Argx);
5419 Scop : constant Entity_Id := Scope (Ent);
5422 -- Case of a pragma applied to a compilation unit: pragma must
5423 -- occur immediately after the program unit in the compilation.
5425 if Is_Compilation_Unit (Ent) then
5427 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
5430 -- Case of pragma placed immediately after spec
5432 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
5435 -- Case of pragma placed immediately after body
5437 elsif Nkind (Decl) = N_Subprogram_Declaration
5438 and then Present (Corresponding_Body (Decl))
5442 (Parent (Unit_Declaration_Node
5443 (Corresponding_Body (Decl))));
5445 -- All other cases are illegal
5452 -- Special restricted placement rule from 10.2.1(11.8/2)
5454 elsif Is_Generic_Formal (Ent)
5455 and then Prag_Id = Pragma_Preelaborable_Initialization
5457 OK := List_Containing (N) =
5458 Generic_Formal_Declarations
5459 (Unit_Declaration_Node (Scop));
5461 -- If this is an aspect applied to a subprogram body, the
5462 -- pragma is inserted in its declarative part.
5464 elsif From_Aspect_Specification (N)
5465 and then Ent = Current_Scope
5467 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
5471 -- If the aspect is a predicate (possibly others ???) and the
5472 -- context is a record type, this is a discriminant expression
5473 -- within a type declaration, that freezes the predicated
5476 elsif From_Aspect_Specification (N)
5477 and then Prag_Id = Pragma_Predicate
5478 and then Ekind (Current_Scope) = E_Record_Type
5479 and then Scop = Scope (Current_Scope)
5483 -- Default case, just check that the pragma occurs in the scope
5484 -- of the entity denoted by the name.
5487 OK := Current_Scope = Scop;
5492 ("pragma% argument must be in same declarative part", Arg);
5496 end Check_Arg_Is_Local_Name;
5498 ---------------------------------
5499 -- Check_Arg_Is_Locking_Policy --
5500 ---------------------------------
5502 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
5503 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5506 Check_Arg_Is_Identifier (Argx);
5508 if not Is_Locking_Policy_Name (Chars (Argx)) then
5509 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
5511 end Check_Arg_Is_Locking_Policy;
5513 -----------------------------------------------
5514 -- Check_Arg_Is_Partition_Elaboration_Policy --
5515 -----------------------------------------------
5517 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
5518 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5521 Check_Arg_Is_Identifier (Argx);
5523 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
5525 ("& is not a valid partition elaboration policy name", Argx);
5527 end Check_Arg_Is_Partition_Elaboration_Policy;
5529 -------------------------
5530 -- Check_Arg_Is_One_Of --
5531 -------------------------
5533 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5534 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5537 Check_Arg_Is_Identifier (Argx);
5539 if not Nam_In (Chars (Argx), N1, N2) then
5540 Error_Msg_Name_2 := N1;
5541 Error_Msg_Name_3 := N2;
5542 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
5544 end Check_Arg_Is_One_Of;
5546 procedure Check_Arg_Is_One_Of
5548 N1, N2, N3 : Name_Id)
5550 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5553 Check_Arg_Is_Identifier (Argx);
5555 if not Nam_In (Chars (Argx), N1, N2, N3) then
5556 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5558 end Check_Arg_Is_One_Of;
5560 procedure Check_Arg_Is_One_Of
5562 N1, N2, N3, N4 : Name_Id)
5564 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5567 Check_Arg_Is_Identifier (Argx);
5569 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
5570 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5572 end Check_Arg_Is_One_Of;
5574 procedure Check_Arg_Is_One_Of
5576 N1, N2, N3, N4, N5 : Name_Id)
5578 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5581 Check_Arg_Is_Identifier (Argx);
5583 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
5584 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5586 end Check_Arg_Is_One_Of;
5588 ---------------------------------
5589 -- Check_Arg_Is_Queuing_Policy --
5590 ---------------------------------
5592 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
5593 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5596 Check_Arg_Is_Identifier (Argx);
5598 if not Is_Queuing_Policy_Name (Chars (Argx)) then
5599 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
5601 end Check_Arg_Is_Queuing_Policy;
5603 ---------------------------------------
5604 -- Check_Arg_Is_OK_Static_Expression --
5605 ---------------------------------------
5607 procedure Check_Arg_Is_OK_Static_Expression
5609 Typ : Entity_Id := Empty)
5612 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
5613 end Check_Arg_Is_OK_Static_Expression;
5615 ------------------------------------------
5616 -- Check_Arg_Is_Task_Dispatching_Policy --
5617 ------------------------------------------
5619 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
5620 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5623 Check_Arg_Is_Identifier (Argx);
5625 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
5627 ("& is not an allowed task dispatching policy name", Argx);
5629 end Check_Arg_Is_Task_Dispatching_Policy;
5631 ---------------------
5632 -- Check_Arg_Order --
5633 ---------------------
5635 procedure Check_Arg_Order (Names : Name_List) is
5638 Highest_So_Far : Natural := 0;
5639 -- Highest index in Names seen do far
5643 for J in 1 .. Arg_Count loop
5644 if Chars (Arg) /= No_Name then
5645 for K in Names'Range loop
5646 if Chars (Arg) = Names (K) then
5647 if K < Highest_So_Far then
5648 Error_Msg_Name_1 := Pname;
5650 ("parameters out of order for pragma%", Arg);
5651 Error_Msg_Name_1 := Names (K);
5652 Error_Msg_Name_2 := Names (Highest_So_Far);
5653 Error_Msg_N ("\% must appear before %", Arg);
5657 Highest_So_Far := K;
5665 end Check_Arg_Order;
5667 --------------------------------
5668 -- Check_At_Least_N_Arguments --
5669 --------------------------------
5671 procedure Check_At_Least_N_Arguments (N : Nat) is
5673 if Arg_Count < N then
5674 Error_Pragma ("too few arguments for pragma%");
5676 end Check_At_Least_N_Arguments;
5678 -------------------------------
5679 -- Check_At_Most_N_Arguments --
5680 -------------------------------
5682 procedure Check_At_Most_N_Arguments (N : Nat) is
5685 if Arg_Count > N then
5687 for J in 1 .. N loop
5689 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
5692 end Check_At_Most_N_Arguments;
5694 ------------------------
5695 -- Check_Atomic_VFA --
5696 ------------------------
5698 procedure Check_Atomic_VFA (E : Entity_Id; VFA : Boolean) is
5700 Aliased_Subcomponent : exception;
5701 -- Exception raised if an aliased subcomponent is found in E
5703 Independent_Subcomponent : exception;
5704 -- Exception raised if an independent subcomponent is found in E
5706 procedure Check_Subcomponents (Typ : Entity_Id);
5707 -- Apply checks to subcomponents for Atomic and Volatile_Full_Access
5709 -------------------------
5710 -- Check_Subcomponents --
5711 -------------------------
5713 procedure Check_Subcomponents (Typ : Entity_Id) is
5717 if Is_Array_Type (Typ) then
5718 Comp := Component_Type (Typ);
5720 -- For Atomic we accept any atomic subcomponents
5723 and then (Has_Atomic_Components (Typ)
5724 or else Is_Atomic (Comp))
5728 -- Give an error if the components are aliased
5730 elsif Has_Aliased_Components (Typ)
5731 or else Is_Aliased (Comp)
5733 raise Aliased_Subcomponent;
5735 -- For VFA we accept non-aliased VFA subcomponents
5738 and then Is_Volatile_Full_Access (Comp)
5742 -- Give an error if the components are independent
5744 elsif Has_Independent_Components (Typ)
5745 or else Is_Independent (Comp)
5747 raise Independent_Subcomponent;
5750 -- Recurse on the component type
5752 Check_Subcomponents (Comp);
5754 -- Note: Has_Aliased_Components, like Has_Atomic_Components,
5755 -- and Has_Independent_Components, applies only to arrays.
5756 -- However, this flag does not have a corresponding pragma, so
5757 -- perhaps it should be possible to apply it to record types as
5758 -- well. Should this be done ???
5760 elsif Is_Record_Type (Typ) then
5761 -- It is possible to have an aliased discriminant, so they
5762 -- must be checked along with normal components.
5764 Comp := First_Component_Or_Discriminant (Typ);
5765 while Present (Comp) loop
5767 -- For Atomic we accept any atomic subcomponents
5770 and then (Is_Atomic (Comp)
5771 or else Is_Atomic (Etype (Comp)))
5775 -- Give an error if the component is aliased
5777 elsif Is_Aliased (Comp)
5778 or else Is_Aliased (Etype (Comp))
5780 raise Aliased_Subcomponent;
5782 -- For VFA we accept non-aliased VFA subcomponents
5785 and then (Is_Volatile_Full_Access (Comp)
5786 or else Is_Volatile_Full_Access (Etype (Comp)))
5790 -- Give an error if the component is independent
5792 elsif Is_Independent (Comp)
5793 or else Is_Independent (Etype (Comp))
5795 raise Independent_Subcomponent;
5798 -- Recurse on the component type
5800 Check_Subcomponents (Etype (Comp));
5802 Next_Component_Or_Discriminant (Comp);
5805 end Check_Subcomponents;
5810 -- Fetch the type in case we are dealing with an object or component
5815 pragma Assert (Is_Object (E)
5817 Nkind (Declaration_Node (E)) = N_Component_Declaration);
5822 -- Check all the subcomponents of the type recursively, if any
5824 Check_Subcomponents (Typ);
5827 when Aliased_Subcomponent =>
5830 ("cannot apply Volatile_Full_Access with aliased "
5834 ("cannot apply Atomic with aliased subcomponent "
5838 when Independent_Subcomponent =>
5841 ("cannot apply Volatile_Full_Access with independent "
5845 ("cannot apply Atomic with independent subcomponent "
5850 raise Program_Error;
5851 end Check_Atomic_VFA;
5853 ---------------------
5854 -- Check_Component --
5855 ---------------------
5857 procedure Check_Component
5860 In_Variant_Part : Boolean := False)
5862 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
5863 Sindic : constant Node_Id :=
5864 Subtype_Indication (Component_Definition (Comp));
5865 Typ : constant Entity_Id := Etype (Comp_Id);
5868 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
5869 -- object constraint, then the component type shall be an Unchecked_
5872 if Nkind (Sindic) = N_Subtype_Indication
5873 and then Has_Per_Object_Constraint (Comp_Id)
5874 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
5877 ("component subtype subject to per-object constraint "
5878 & "must be an Unchecked_Union", Comp);
5880 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
5881 -- the body of a generic unit, or within the body of any of its
5882 -- descendant library units, no part of the type of a component
5883 -- declared in a variant_part of the unchecked union type shall be of
5884 -- a formal private type or formal private extension declared within
5885 -- the formal part of the generic unit.
5887 elsif Ada_Version >= Ada_2012
5888 and then In_Generic_Body (UU_Typ)
5889 and then In_Variant_Part
5890 and then Is_Private_Type (Typ)
5891 and then Is_Generic_Type (Typ)
5894 ("component of unchecked union cannot be of generic type", Comp);
5896 elsif Needs_Finalization (Typ) then
5898 ("component of unchecked union cannot be controlled", Comp);
5900 elsif Has_Task (Typ) then
5902 ("component of unchecked union cannot have tasks", Comp);
5904 end Check_Component;
5906 ----------------------------
5907 -- Check_Duplicate_Pragma --
5908 ----------------------------
5910 procedure Check_Duplicate_Pragma (E : Entity_Id) is
5911 Id : Entity_Id := E;
5915 -- Nothing to do if this pragma comes from an aspect specification,
5916 -- since we could not be duplicating a pragma, and we dealt with the
5917 -- case of duplicated aspects in Analyze_Aspect_Specifications.
5919 if From_Aspect_Specification (N) then
5923 -- Otherwise current pragma may duplicate previous pragma or a
5924 -- previously given aspect specification or attribute definition
5925 -- clause for the same pragma.
5927 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
5931 -- If the entity is a type, then we have to make sure that the
5932 -- ostensible duplicate is not for a parent type from which this
5936 if Nkind (P) = N_Pragma then
5938 Args : constant List_Id :=
5939 Pragma_Argument_Associations (P);
5942 and then Is_Entity_Name (Expression (First (Args)))
5943 and then Is_Type (Entity (Expression (First (Args))))
5944 and then Entity (Expression (First (Args))) /= E
5950 elsif Nkind (P) = N_Aspect_Specification
5951 and then Is_Type (Entity (P))
5952 and then Entity (P) /= E
5958 -- Here we have a definite duplicate
5960 Error_Msg_Name_1 := Pragma_Name (N);
5961 Error_Msg_Sloc := Sloc (P);
5963 -- For a single protected or a single task object, the error is
5964 -- issued on the original entity.
5966 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
5967 Id := Defining_Identifier (Original_Node (Parent (Id)));
5970 if Nkind (P) = N_Aspect_Specification
5971 or else From_Aspect_Specification (P)
5973 Error_Msg_NE ("aspect% for & previously given#", N, Id);
5975 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
5980 end Check_Duplicate_Pragma;
5982 ----------------------------------
5983 -- Check_Duplicated_Export_Name --
5984 ----------------------------------
5986 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
5987 String_Val : constant String_Id := Strval (Nam);
5990 -- We are only interested in the export case, and in the case of
5991 -- generics, it is the instance, not the template, that is the
5992 -- problem (the template will generate a warning in any case).
5994 if not Inside_A_Generic
5995 and then (Prag_Id = Pragma_Export
5997 Prag_Id = Pragma_Export_Procedure
5999 Prag_Id = Pragma_Export_Valued_Procedure
6001 Prag_Id = Pragma_Export_Function)
6003 for J in Externals.First .. Externals.Last loop
6004 if String_Equal (String_Val, Strval (Externals.Table (J))) then
6005 Error_Msg_Sloc := Sloc (Externals.Table (J));
6006 Error_Msg_N ("external name duplicates name given#", Nam);
6011 Externals.Append (Nam);
6013 end Check_Duplicated_Export_Name;
6015 ----------------------------------------
6016 -- Check_Expr_Is_OK_Static_Expression --
6017 ----------------------------------------
6019 procedure Check_Expr_Is_OK_Static_Expression
6021 Typ : Entity_Id := Empty)
6024 if Present (Typ) then
6025 Analyze_And_Resolve (Expr, Typ);
6027 Analyze_And_Resolve (Expr);
6030 -- An expression cannot be considered static if its resolution failed
6031 -- or if it's erroneous. Stop the analysis of the related pragma.
6033 if Etype (Expr) = Any_Type or else Error_Posted (Expr) then
6036 elsif Is_OK_Static_Expression (Expr) then
6039 -- An interesting special case, if we have a string literal and we
6040 -- are in Ada 83 mode, then we allow it even though it will not be
6041 -- flagged as static. This allows the use of Ada 95 pragmas like
6042 -- Import in Ada 83 mode. They will of course be flagged with
6043 -- warnings as usual, but will not cause errors.
6045 elsif Ada_Version = Ada_83
6046 and then Nkind (Expr) = N_String_Literal
6050 -- Finally, we have a real error
6053 Error_Msg_Name_1 := Pname;
6054 Flag_Non_Static_Expr
6055 (Fix_Error ("argument for pragma% must be a static expression!"),
6059 end Check_Expr_Is_OK_Static_Expression;
6061 -------------------------
6062 -- Check_First_Subtype --
6063 -------------------------
6065 procedure Check_First_Subtype (Arg : Node_Id) is
6066 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6067 Ent : constant Entity_Id := Entity (Argx);
6070 if Is_First_Subtype (Ent) then
6073 elsif Is_Type (Ent) then
6075 ("pragma% cannot apply to subtype", Argx);
6077 elsif Is_Object (Ent) then
6079 ("pragma% cannot apply to object, requires a type", Argx);
6083 ("pragma% cannot apply to&, requires a type", Argx);
6085 end Check_First_Subtype;
6087 ----------------------
6088 -- Check_Identifier --
6089 ----------------------
6091 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
6094 and then Nkind (Arg) = N_Pragma_Argument_Association
6096 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
6097 Error_Msg_Name_1 := Pname;
6098 Error_Msg_Name_2 := Id;
6099 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6103 end Check_Identifier;
6105 --------------------------------
6106 -- Check_Identifier_Is_One_Of --
6107 --------------------------------
6109 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
6112 and then Nkind (Arg) = N_Pragma_Argument_Association
6114 if Chars (Arg) = No_Name then
6115 Error_Msg_Name_1 := Pname;
6116 Error_Msg_N ("pragma% argument expects an identifier", Arg);
6119 elsif Chars (Arg) /= N1
6120 and then Chars (Arg) /= N2
6122 Error_Msg_Name_1 := Pname;
6123 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
6127 end Check_Identifier_Is_One_Of;
6129 ---------------------------
6130 -- Check_In_Main_Program --
6131 ---------------------------
6133 procedure Check_In_Main_Program is
6134 P : constant Node_Id := Parent (N);
6137 -- Must be in subprogram body
6139 if Nkind (P) /= N_Subprogram_Body then
6140 Error_Pragma ("% pragma allowed only in subprogram");
6142 -- Otherwise warn if obviously not main program
6144 elsif Present (Parameter_Specifications (Specification (P)))
6145 or else not Is_Compilation_Unit (Defining_Entity (P))
6147 Error_Msg_Name_1 := Pname;
6149 ("??pragma% is only effective in main program", N);
6151 end Check_In_Main_Program;
6153 ---------------------------------------
6154 -- Check_Interrupt_Or_Attach_Handler --
6155 ---------------------------------------
6157 procedure Check_Interrupt_Or_Attach_Handler is
6158 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
6159 Handler_Proc, Proc_Scope : Entity_Id;
6164 if Prag_Id = Pragma_Interrupt_Handler then
6165 Check_Restriction (No_Dynamic_Attachment, N);
6168 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
6169 Proc_Scope := Scope (Handler_Proc);
6171 if Ekind (Proc_Scope) /= E_Protected_Type then
6173 ("argument of pragma% must be protected procedure", Arg1);
6176 -- For pragma case (as opposed to access case), check placement.
6177 -- We don't need to do that for aspects, because we have the
6178 -- check that they aspect applies an appropriate procedure.
6180 if not From_Aspect_Specification (N)
6181 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
6183 Error_Pragma ("pragma% must be in protected definition");
6186 if not Is_Library_Level_Entity (Proc_Scope) then
6188 ("argument for pragma% must be library level entity", Arg1);
6191 -- AI05-0033: A pragma cannot appear within a generic body, because
6192 -- instance can be in a nested scope. The check that protected type
6193 -- is itself a library-level declaration is done elsewhere.
6195 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
6196 -- handle code prior to AI-0033. Analysis tools typically are not
6197 -- interested in this pragma in any case, so no need to worry too
6198 -- much about its placement.
6200 if Inside_A_Generic then
6201 if Ekind (Scope (Current_Scope)) = E_Generic_Package
6202 and then In_Package_Body (Scope (Current_Scope))
6203 and then not Relaxed_RM_Semantics
6205 Error_Pragma ("pragma% cannot be used inside a generic");
6208 end Check_Interrupt_Or_Attach_Handler;
6210 ---------------------------------
6211 -- Check_Loop_Pragma_Placement --
6212 ---------------------------------
6214 procedure Check_Loop_Pragma_Placement is
6215 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
6216 -- Verify whether the current pragma is properly grouped with other
6217 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
6218 -- related loop where the pragma appears.
6220 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
6221 -- Determine whether an arbitrary statement Stmt denotes pragma
6222 -- Loop_Invariant or Loop_Variant.
6224 procedure Placement_Error (Constr : Node_Id);
6225 pragma No_Return (Placement_Error);
6226 -- Node Constr denotes the last loop restricted construct before we
6227 -- encountered an illegal relation between enclosing constructs. Emit
6228 -- an error depending on what Constr was.
6230 --------------------------------
6231 -- Check_Loop_Pragma_Grouping --
6232 --------------------------------
6234 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
6235 Stop_Search : exception;
6236 -- This exception is used to terminate the recursive descent of
6237 -- routine Check_Grouping.
6239 procedure Check_Grouping (L : List_Id);
6240 -- Find the first group of pragmas in list L and if successful,
6241 -- ensure that the current pragma is part of that group. The
6242 -- routine raises Stop_Search once such a check is performed to
6243 -- halt the recursive descent.
6245 procedure Grouping_Error (Prag : Node_Id);
6246 pragma No_Return (Grouping_Error);
6247 -- Emit an error concerning the current pragma indicating that it
6248 -- should be placed after pragma Prag.
6250 --------------------
6251 -- Check_Grouping --
6252 --------------------
6254 procedure Check_Grouping (L : List_Id) is
6257 Prag : Node_Id := Empty; -- init to avoid warning
6260 -- Inspect the list of declarations or statements looking for
6261 -- the first grouping of pragmas:
6264 -- pragma Loop_Invariant ...;
6265 -- pragma Loop_Variant ...;
6267 -- pragma Loop_Variant ...; -- current pragma
6269 -- If the current pragma is not in the grouping, then it must
6270 -- either appear in a different declarative or statement list
6271 -- or the construct at (1) is separating the pragma from the
6275 while Present (Stmt) loop
6277 -- First pragma of the first topmost grouping has been found
6279 if Is_Loop_Pragma (Stmt) then
6281 -- The group and the current pragma are not in the same
6282 -- declarative or statement list.
6284 if List_Containing (Stmt) /= List_Containing (N) then
6285 Grouping_Error (Stmt);
6287 -- Try to reach the current pragma from the first pragma
6288 -- of the grouping while skipping other members:
6290 -- pragma Loop_Invariant ...; -- first pragma
6291 -- pragma Loop_Variant ...; -- member
6293 -- pragma Loop_Variant ...; -- current pragma
6296 while Present (Stmt) loop
6297 -- The current pragma is either the first pragma
6298 -- of the group or is a member of the group.
6299 -- Stop the search as the placement is legal.
6304 -- Skip group members, but keep track of the
6305 -- last pragma in the group.
6307 elsif Is_Loop_Pragma (Stmt) then
6310 -- Skip declarations and statements generated by
6311 -- the compiler during expansion. Note that some
6312 -- source statements (e.g. pragma Assert) may have
6313 -- been transformed so that they do not appear as
6314 -- coming from source anymore, so we instead look
6315 -- at their Original_Node.
6317 elsif not Comes_From_Source (Original_Node (Stmt))
6321 -- A non-pragma is separating the group from the
6322 -- current pragma, the placement is illegal.
6325 Grouping_Error (Prag);
6331 -- If the traversal did not reach the current pragma,
6332 -- then the list must be malformed.
6334 raise Program_Error;
6337 -- Pragmas Loop_Invariant and Loop_Variant may only appear
6338 -- inside a loop or a block housed inside a loop. Inspect
6339 -- the declarations and statements of the block as they may
6340 -- contain the first grouping. This case follows the one for
6341 -- loop pragmas, as block statements which originate in a
6342 -- loop pragma (and so Is_Loop_Pragma will return True on
6343 -- that block statement) should be treated in the previous
6346 elsif Nkind (Stmt) = N_Block_Statement then
6347 HSS := Handled_Statement_Sequence (Stmt);
6349 Check_Grouping (Declarations (Stmt));
6351 if Present (HSS) then
6352 Check_Grouping (Statements (HSS));
6360 --------------------
6361 -- Grouping_Error --
6362 --------------------
6364 procedure Grouping_Error (Prag : Node_Id) is
6366 Error_Msg_Sloc := Sloc (Prag);
6367 Error_Pragma ("pragma% must appear next to pragma#");
6370 -- Start of processing for Check_Loop_Pragma_Grouping
6373 -- Inspect the statements of the loop or nested blocks housed
6374 -- within to determine whether the current pragma is part of the
6375 -- first topmost grouping of Loop_Invariant and Loop_Variant.
6377 Check_Grouping (Statements (Loop_Stmt));
6380 when Stop_Search => null;
6381 end Check_Loop_Pragma_Grouping;
6383 --------------------
6384 -- Is_Loop_Pragma --
6385 --------------------
6387 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
6389 -- Inspect the original node as Loop_Invariant and Loop_Variant
6390 -- pragmas are rewritten to null when assertions are disabled.
6392 if Nkind (Original_Node (Stmt)) = N_Pragma then
6394 Nam_In (Pragma_Name_Unmapped (Original_Node (Stmt)),
6395 Name_Loop_Invariant,
6402 ---------------------
6403 -- Placement_Error --
6404 ---------------------
6406 procedure Placement_Error (Constr : Node_Id) is
6407 LA : constant String := " with Loop_Entry";
6410 if Prag_Id = Pragma_Assert then
6411 Error_Msg_String (1 .. LA'Length) := LA;
6412 Error_Msg_Strlen := LA'Length;
6414 Error_Msg_Strlen := 0;
6417 if Nkind (Constr) = N_Pragma then
6419 ("pragma %~ must appear immediately within the statements "
6423 ("block containing pragma %~ must appear immediately within "
6424 & "the statements of a loop", Constr);
6426 end Placement_Error;
6428 -- Local declarations
6433 -- Start of processing for Check_Loop_Pragma_Placement
6436 -- Check that pragma appears immediately within a loop statement,
6437 -- ignoring intervening block statements.
6441 while Present (Stmt) loop
6443 -- The pragma or previous block must appear immediately within the
6444 -- current block's declarative or statement part.
6446 if Nkind (Stmt) = N_Block_Statement then
6447 if (No (Declarations (Stmt))
6448 or else List_Containing (Prev) /= Declarations (Stmt))
6450 List_Containing (Prev) /=
6451 Statements (Handled_Statement_Sequence (Stmt))
6453 Placement_Error (Prev);
6456 -- Keep inspecting the parents because we are now within a
6457 -- chain of nested blocks.
6461 Stmt := Parent (Stmt);
6464 -- The pragma or previous block must appear immediately within the
6465 -- statements of the loop.
6467 elsif Nkind (Stmt) = N_Loop_Statement then
6468 if List_Containing (Prev) /= Statements (Stmt) then
6469 Placement_Error (Prev);
6472 -- Stop the traversal because we reached the innermost loop
6473 -- regardless of whether we encountered an error or not.
6477 -- Ignore a handled statement sequence. Note that this node may
6478 -- be related to a subprogram body in which case we will emit an
6479 -- error on the next iteration of the search.
6481 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
6482 Stmt := Parent (Stmt);
6484 -- Any other statement breaks the chain from the pragma to the
6488 Placement_Error (Prev);
6493 -- Check that the current pragma Loop_Invariant or Loop_Variant is
6494 -- grouped together with other such pragmas.
6496 if Is_Loop_Pragma (N) then
6498 -- The previous check should have located the related loop
6500 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
6501 Check_Loop_Pragma_Grouping (Stmt);
6503 end Check_Loop_Pragma_Placement;
6505 -------------------------------------------
6506 -- Check_Is_In_Decl_Part_Or_Package_Spec --
6507 -------------------------------------------
6509 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
6518 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
6521 elsif Nkind_In (P, N_Package_Specification,
6526 -- Note: the following tests seem a little peculiar, because
6527 -- they test for bodies, but if we were in the statement part
6528 -- of the body, we would already have hit the handled statement
6529 -- sequence, so the only way we get here is by being in the
6530 -- declarative part of the body.
6532 elsif Nkind_In (P, N_Subprogram_Body,
6543 Error_Pragma ("pragma% is not in declarative part or package spec");
6544 end Check_Is_In_Decl_Part_Or_Package_Spec;
6546 -------------------------
6547 -- Check_No_Identifier --
6548 -------------------------
6550 procedure Check_No_Identifier (Arg : Node_Id) is
6552 if Nkind (Arg) = N_Pragma_Argument_Association
6553 and then Chars (Arg) /= No_Name
6555 Error_Pragma_Arg_Ident
6556 ("pragma% does not permit identifier& here", Arg);
6558 end Check_No_Identifier;
6560 --------------------------
6561 -- Check_No_Identifiers --
6562 --------------------------
6564 procedure Check_No_Identifiers is
6568 for J in 1 .. Arg_Count loop
6569 Check_No_Identifier (Arg_Node);
6572 end Check_No_Identifiers;
6574 ------------------------
6575 -- Check_No_Link_Name --
6576 ------------------------
6578 procedure Check_No_Link_Name is
6580 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
6584 if Present (Arg4) then
6586 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
6588 end Check_No_Link_Name;
6590 -------------------------------
6591 -- Check_Optional_Identifier --
6592 -------------------------------
6594 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
6597 and then Nkind (Arg) = N_Pragma_Argument_Association
6598 and then Chars (Arg) /= No_Name
6600 if Chars (Arg) /= Id then
6601 Error_Msg_Name_1 := Pname;
6602 Error_Msg_Name_2 := Id;
6603 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6607 end Check_Optional_Identifier;
6609 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
6611 Check_Optional_Identifier (Arg, Name_Find (Id));
6612 end Check_Optional_Identifier;
6614 -------------------------------------
6615 -- Check_Static_Boolean_Expression --
6616 -------------------------------------
6618 procedure Check_Static_Boolean_Expression (Expr : Node_Id) is
6620 if Present (Expr) then
6621 Analyze_And_Resolve (Expr, Standard_Boolean);
6623 if not Is_OK_Static_Expression (Expr) then
6625 ("expression of pragma % must be static", Expr);
6628 end Check_Static_Boolean_Expression;
6630 -----------------------------
6631 -- Check_Static_Constraint --
6632 -----------------------------
6634 -- Note: for convenience in writing this procedure, in addition to
6635 -- the officially (i.e. by spec) allowed argument which is always a
6636 -- constraint, it also allows ranges and discriminant associations.
6637 -- Above is not clear ???
6639 procedure Check_Static_Constraint (Constr : Node_Id) is
6641 procedure Require_Static (E : Node_Id);
6642 -- Require given expression to be static expression
6644 --------------------
6645 -- Require_Static --
6646 --------------------
6648 procedure Require_Static (E : Node_Id) is
6650 if not Is_OK_Static_Expression (E) then
6651 Flag_Non_Static_Expr
6652 ("non-static constraint not allowed in Unchecked_Union!", E);
6657 -- Start of processing for Check_Static_Constraint
6660 case Nkind (Constr) is
6661 when N_Discriminant_Association =>
6662 Require_Static (Expression (Constr));
6665 Require_Static (Low_Bound (Constr));
6666 Require_Static (High_Bound (Constr));
6668 when N_Attribute_Reference =>
6669 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
6670 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
6672 when N_Range_Constraint =>
6673 Check_Static_Constraint (Range_Expression (Constr));
6675 when N_Index_Or_Discriminant_Constraint =>
6679 IDC := First (Constraints (Constr));
6680 while Present (IDC) loop
6681 Check_Static_Constraint (IDC);
6689 end Check_Static_Constraint;
6691 --------------------------------------
6692 -- Check_Valid_Configuration_Pragma --
6693 --------------------------------------
6695 -- A configuration pragma must appear in the context clause of a
6696 -- compilation unit, and only other pragmas may precede it. Note that
6697 -- the test also allows use in a configuration pragma file.
6699 procedure Check_Valid_Configuration_Pragma is
6701 if not Is_Configuration_Pragma then
6702 Error_Pragma ("incorrect placement for configuration pragma%");
6704 end Check_Valid_Configuration_Pragma;
6706 -------------------------------------
6707 -- Check_Valid_Library_Unit_Pragma --
6708 -------------------------------------
6710 procedure Check_Valid_Library_Unit_Pragma is
6712 Parent_Node : Node_Id;
6713 Unit_Name : Entity_Id;
6714 Unit_Kind : Node_Kind;
6715 Unit_Node : Node_Id;
6716 Sindex : Source_File_Index;
6719 if not Is_List_Member (N) then
6723 Plist := List_Containing (N);
6724 Parent_Node := Parent (Plist);
6726 if Parent_Node = Empty then
6729 -- Case of pragma appearing after a compilation unit. In this case
6730 -- it must have an argument with the corresponding name and must
6731 -- be part of the following pragmas of its parent.
6733 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
6734 if Plist /= Pragmas_After (Parent_Node) then
6737 elsif Arg_Count = 0 then
6739 ("argument required if outside compilation unit");
6742 Check_No_Identifiers;
6743 Check_Arg_Count (1);
6744 Unit_Node := Unit (Parent (Parent_Node));
6745 Unit_Kind := Nkind (Unit_Node);
6747 Analyze (Get_Pragma_Arg (Arg1));
6749 if Unit_Kind = N_Generic_Subprogram_Declaration
6750 or else Unit_Kind = N_Subprogram_Declaration
6752 Unit_Name := Defining_Entity (Unit_Node);
6754 elsif Unit_Kind in N_Generic_Instantiation then
6755 Unit_Name := Defining_Entity (Unit_Node);
6758 Unit_Name := Cunit_Entity (Current_Sem_Unit);
6761 if Chars (Unit_Name) /=
6762 Chars (Entity (Get_Pragma_Arg (Arg1)))
6765 ("pragma% argument is not current unit name", Arg1);
6768 if Ekind (Unit_Name) = E_Package
6769 and then Present (Renamed_Entity (Unit_Name))
6771 Error_Pragma ("pragma% not allowed for renamed package");
6775 -- Pragma appears other than after a compilation unit
6778 -- Here we check for the generic instantiation case and also
6779 -- for the case of processing a generic formal package. We
6780 -- detect these cases by noting that the Sloc on the node
6781 -- does not belong to the current compilation unit.
6783 Sindex := Source_Index (Current_Sem_Unit);
6785 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
6786 Rewrite (N, Make_Null_Statement (Loc));
6789 -- If before first declaration, the pragma applies to the
6790 -- enclosing unit, and the name if present must be this name.
6792 elsif Is_Before_First_Decl (N, Plist) then
6793 Unit_Node := Unit_Declaration_Node (Current_Scope);
6794 Unit_Kind := Nkind (Unit_Node);
6796 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
6799 elsif Unit_Kind = N_Subprogram_Body
6800 and then not Acts_As_Spec (Unit_Node)
6804 elsif Nkind (Parent_Node) = N_Package_Body then
6807 elsif Nkind (Parent_Node) = N_Package_Specification
6808 and then Plist = Private_Declarations (Parent_Node)
6812 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
6813 or else Nkind (Parent_Node) =
6814 N_Generic_Subprogram_Declaration)
6815 and then Plist = Generic_Formal_Declarations (Parent_Node)
6819 elsif Arg_Count > 0 then
6820 Analyze (Get_Pragma_Arg (Arg1));
6822 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
6824 ("name in pragma% must be enclosing unit", Arg1);
6827 -- It is legal to have no argument in this context
6833 -- Error if not before first declaration. This is because a
6834 -- library unit pragma argument must be the name of a library
6835 -- unit (RM 10.1.5(7)), but the only names permitted in this
6836 -- context are (RM 10.1.5(6)) names of subprogram declarations,
6837 -- generic subprogram declarations or generic instantiations.
6841 ("pragma% misplaced, must be before first declaration");
6845 end Check_Valid_Library_Unit_Pragma;
6851 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
6852 Clist : constant Node_Id := Component_List (Variant);
6856 Comp := First_Non_Pragma (Component_Items (Clist));
6857 while Present (Comp) loop
6858 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
6859 Next_Non_Pragma (Comp);
6863 ---------------------------
6864 -- Ensure_Aggregate_Form --
6865 ---------------------------
6867 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
6868 CFSD : constant Boolean := Get_Comes_From_Source_Default;
6869 Expr : constant Node_Id := Expression (Arg);
6870 Loc : constant Source_Ptr := Sloc (Expr);
6871 Comps : List_Id := No_List;
6872 Exprs : List_Id := No_List;
6873 Nam : Name_Id := No_Name;
6874 Nam_Loc : Source_Ptr;
6877 -- The pragma argument is in positional form:
6879 -- pragma Depends (Nam => ...)
6883 -- Note that the Sloc of the Chars field is the Sloc of the pragma
6884 -- argument association.
6886 if Nkind (Arg) = N_Pragma_Argument_Association then
6888 Nam_Loc := Sloc (Arg);
6890 -- Remove the pragma argument name as this will be captured in the
6893 Set_Chars (Arg, No_Name);
6896 -- The argument is already in aggregate form, but the presence of a
6897 -- name causes this to be interpreted as named association which in
6898 -- turn must be converted into an aggregate.
6900 -- pragma Global (In_Out => (A, B, C))
6904 -- pragma Global ((In_Out => (A, B, C)))
6906 -- aggregate aggregate
6908 if Nkind (Expr) = N_Aggregate then
6909 if Nam = No_Name then
6913 -- Do not transform a null argument into an aggregate as N_Null has
6914 -- special meaning in formal verification pragmas.
6916 elsif Nkind (Expr) = N_Null then
6920 -- Everything comes from source if the original comes from source
6922 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
6924 -- Positional argument is transformed into an aggregate with an
6925 -- Expressions list.
6927 if Nam = No_Name then
6928 Exprs := New_List (Relocate_Node (Expr));
6930 -- An associative argument is transformed into an aggregate with
6931 -- Component_Associations.
6935 Make_Component_Association (Loc,
6936 Choices => New_List (Make_Identifier (Nam_Loc, Nam)),
6937 Expression => Relocate_Node (Expr)));
6940 Set_Expression (Arg,
6941 Make_Aggregate (Loc,
6942 Component_Associations => Comps,
6943 Expressions => Exprs));
6945 -- Restore Comes_From_Source default
6947 Set_Comes_From_Source_Default (CFSD);
6948 end Ensure_Aggregate_Form;
6954 procedure Error_Pragma (Msg : String) is
6956 Error_Msg_Name_1 := Pname;
6957 Error_Msg_N (Fix_Error (Msg), N);
6961 ----------------------
6962 -- Error_Pragma_Arg --
6963 ----------------------
6965 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
6967 Error_Msg_Name_1 := Pname;
6968 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
6970 end Error_Pragma_Arg;
6972 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
6974 Error_Msg_Name_1 := Pname;
6975 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
6976 Error_Pragma_Arg (Msg2, Arg);
6977 end Error_Pragma_Arg;
6979 ----------------------------
6980 -- Error_Pragma_Arg_Ident --
6981 ----------------------------
6983 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
6985 Error_Msg_Name_1 := Pname;
6986 Error_Msg_N (Fix_Error (Msg), Arg);
6988 end Error_Pragma_Arg_Ident;
6990 ----------------------
6991 -- Error_Pragma_Ref --
6992 ----------------------
6994 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
6996 Error_Msg_Name_1 := Pname;
6997 Error_Msg_Sloc := Sloc (Ref);
6998 Error_Msg_NE (Fix_Error (Msg), N, Ref);
7000 end Error_Pragma_Ref;
7002 ------------------------
7003 -- Find_Lib_Unit_Name --
7004 ------------------------
7006 function Find_Lib_Unit_Name return Entity_Id is
7008 -- Return inner compilation unit entity, for case of nested
7009 -- categorization pragmas. This happens in generic unit.
7011 if Nkind (Parent (N)) = N_Package_Specification
7012 and then Defining_Entity (Parent (N)) /= Current_Scope
7014 return Defining_Entity (Parent (N));
7016 return Current_Scope;
7018 end Find_Lib_Unit_Name;
7020 ----------------------------
7021 -- Find_Program_Unit_Name --
7022 ----------------------------
7024 procedure Find_Program_Unit_Name (Id : Node_Id) is
7025 Unit_Name : Entity_Id;
7026 Unit_Kind : Node_Kind;
7027 P : constant Node_Id := Parent (N);
7030 if Nkind (P) = N_Compilation_Unit then
7031 Unit_Kind := Nkind (Unit (P));
7033 if Nkind_In (Unit_Kind, N_Subprogram_Declaration,
7034 N_Package_Declaration)
7035 or else Unit_Kind in N_Generic_Declaration
7037 Unit_Name := Defining_Entity (Unit (P));
7039 if Chars (Id) = Chars (Unit_Name) then
7040 Set_Entity (Id, Unit_Name);
7041 Set_Etype (Id, Etype (Unit_Name));
7043 Set_Etype (Id, Any_Type);
7045 ("cannot find program unit referenced by pragma%");
7049 Set_Etype (Id, Any_Type);
7050 Error_Pragma ("pragma% inapplicable to this unit");
7056 end Find_Program_Unit_Name;
7058 -----------------------------------------
7059 -- Find_Unique_Parameterless_Procedure --
7060 -----------------------------------------
7062 function Find_Unique_Parameterless_Procedure
7064 Arg : Node_Id) return Entity_Id
7066 Proc : Entity_Id := Empty;
7069 -- The body of this procedure needs some comments ???
7071 if not Is_Entity_Name (Name) then
7073 ("argument of pragma% must be entity name", Arg);
7075 elsif not Is_Overloaded (Name) then
7076 Proc := Entity (Name);
7078 if Ekind (Proc) /= E_Procedure
7079 or else Present (First_Formal (Proc))
7082 ("argument of pragma% must be parameterless procedure", Arg);
7087 Found : Boolean := False;
7089 Index : Interp_Index;
7092 Get_First_Interp (Name, Index, It);
7093 while Present (It.Nam) loop
7096 if Ekind (Proc) = E_Procedure
7097 and then No (First_Formal (Proc))
7101 Set_Entity (Name, Proc);
7102 Set_Is_Overloaded (Name, False);
7105 ("ambiguous handler name for pragma% ", Arg);
7109 Get_Next_Interp (Index, It);
7114 ("argument of pragma% must be parameterless procedure",
7117 Proc := Entity (Name);
7123 end Find_Unique_Parameterless_Procedure;
7129 function Fix_Error (Msg : String) return String is
7130 Res : String (Msg'Range) := Msg;
7131 Res_Last : Natural := Msg'Last;
7135 -- If we have a rewriting of another pragma, go to that pragma
7137 if Is_Rewrite_Substitution (N)
7138 and then Nkind (Original_Node (N)) = N_Pragma
7140 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
7143 -- Case where pragma comes from an aspect specification
7145 if From_Aspect_Specification (N) then
7147 -- Change appearence of "pragma" in message to "aspect"
7150 while J <= Res_Last - 5 loop
7151 if Res (J .. J + 5) = "pragma" then
7152 Res (J .. J + 5) := "aspect";
7160 -- Change "argument of" at start of message to "entity for"
7163 and then Res (Res'First .. Res'First + 10) = "argument of"
7165 Res (Res'First .. Res'First + 9) := "entity for";
7166 Res (Res'First + 10 .. Res_Last - 1) :=
7167 Res (Res'First + 11 .. Res_Last);
7168 Res_Last := Res_Last - 1;
7171 -- Change "argument" at start of message to "entity"
7174 and then Res (Res'First .. Res'First + 7) = "argument"
7176 Res (Res'First .. Res'First + 5) := "entity";
7177 Res (Res'First + 6 .. Res_Last - 2) :=
7178 Res (Res'First + 8 .. Res_Last);
7179 Res_Last := Res_Last - 2;
7182 -- Get name from corresponding aspect
7184 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
7187 -- Return possibly modified message
7189 return Res (Res'First .. Res_Last);
7192 -------------------------
7193 -- Gather_Associations --
7194 -------------------------
7196 procedure Gather_Associations
7198 Args : out Args_List)
7203 -- Initialize all parameters to Empty
7205 for J in Args'Range loop
7209 -- That's all we have to do if there are no argument associations
7211 if No (Pragma_Argument_Associations (N)) then
7215 -- Otherwise first deal with any positional parameters present
7217 Arg := First (Pragma_Argument_Associations (N));
7218 for Index in Args'Range loop
7219 exit when No (Arg) or else Chars (Arg) /= No_Name;
7220 Args (Index) := Get_Pragma_Arg (Arg);
7224 -- Positional parameters all processed, if any left, then we
7225 -- have too many positional parameters.
7227 if Present (Arg) and then Chars (Arg) = No_Name then
7229 ("too many positional associations for pragma%", Arg);
7232 -- Process named parameters if any are present
7234 while Present (Arg) loop
7235 if Chars (Arg) = No_Name then
7237 ("positional association cannot follow named association",
7241 for Index in Names'Range loop
7242 if Names (Index) = Chars (Arg) then
7243 if Present (Args (Index)) then
7245 ("duplicate argument association for pragma%", Arg);
7247 Args (Index) := Get_Pragma_Arg (Arg);
7252 if Index = Names'Last then
7253 Error_Msg_Name_1 := Pname;
7254 Error_Msg_N ("pragma% does not allow & argument", Arg);
7256 -- Check for possible misspelling
7258 for Index1 in Names'Range loop
7259 if Is_Bad_Spelling_Of
7260 (Chars (Arg), Names (Index1))
7262 Error_Msg_Name_1 := Names (Index1);
7263 Error_Msg_N -- CODEFIX
7264 ("\possible misspelling of%", Arg);
7276 end Gather_Associations;
7282 procedure GNAT_Pragma is
7284 -- We need to check the No_Implementation_Pragmas restriction for
7285 -- the case of a pragma from source. Note that the case of aspects
7286 -- generating corresponding pragmas marks these pragmas as not being
7287 -- from source, so this test also catches that case.
7289 if Comes_From_Source (N) then
7290 Check_Restriction (No_Implementation_Pragmas, N);
7294 --------------------------
7295 -- Is_Before_First_Decl --
7296 --------------------------
7298 function Is_Before_First_Decl
7299 (Pragma_Node : Node_Id;
7300 Decls : List_Id) return Boolean
7302 Item : Node_Id := First (Decls);
7305 -- Only other pragmas can come before this pragma, but they might
7306 -- have been rewritten so check the original node.
7309 if No (Item) or else Nkind (Original_Node (Item)) /= N_Pragma then
7312 elsif Item = Pragma_Node then
7318 end Is_Before_First_Decl;
7320 -----------------------------
7321 -- Is_Configuration_Pragma --
7322 -----------------------------
7324 -- A configuration pragma must appear in the context clause of a
7325 -- compilation unit, and only other pragmas may precede it. Note that
7326 -- the test below also permits use in a configuration pragma file.
7328 function Is_Configuration_Pragma return Boolean is
7329 Lis : constant List_Id := List_Containing (N);
7330 Par : constant Node_Id := Parent (N);
7334 -- If no parent, then we are in the configuration pragma file,
7335 -- so the placement is definitely appropriate.
7340 -- Otherwise we must be in the context clause of a compilation unit
7341 -- and the only thing allowed before us in the context list is more
7342 -- configuration pragmas.
7344 elsif Nkind (Par) = N_Compilation_Unit
7345 and then Context_Items (Par) = Lis
7352 elsif Nkind (Prg) /= N_Pragma then
7362 end Is_Configuration_Pragma;
7364 --------------------------
7365 -- Is_In_Context_Clause --
7366 --------------------------
7368 function Is_In_Context_Clause return Boolean is
7370 Parent_Node : Node_Id;
7373 if not Is_List_Member (N) then
7377 Plist := List_Containing (N);
7378 Parent_Node := Parent (Plist);
7380 if Parent_Node = Empty
7381 or else Nkind (Parent_Node) /= N_Compilation_Unit
7382 or else Context_Items (Parent_Node) /= Plist
7389 end Is_In_Context_Clause;
7391 ---------------------------------
7392 -- Is_Static_String_Expression --
7393 ---------------------------------
7395 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
7396 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
7397 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
7400 Analyze_And_Resolve (Argx);
7402 -- Special case Ada 83, where the expression will never be static,
7403 -- but we will return true if we had a string literal to start with.
7405 if Ada_Version = Ada_83 then
7408 -- Normal case, true only if we end up with a string literal that
7409 -- is marked as being the result of evaluating a static expression.
7412 return Is_OK_Static_Expression (Argx)
7413 and then Nkind (Argx) = N_String_Literal;
7416 end Is_Static_String_Expression;
7418 ----------------------
7419 -- Pragma_Misplaced --
7420 ----------------------
7422 procedure Pragma_Misplaced is
7424 Error_Pragma ("incorrect placement of pragma%");
7425 end Pragma_Misplaced;
7427 ------------------------------------------------
7428 -- Process_Atomic_Independent_Shared_Volatile --
7429 ------------------------------------------------
7431 procedure Process_Atomic_Independent_Shared_Volatile is
7432 procedure Check_VFA_Conflicts (Ent : Entity_Id);
7433 -- Check that Volatile_Full_Access and VFA do not conflict
7435 procedure Mark_Component_Or_Object (Ent : Entity_Id);
7436 -- Appropriately set flags on the given entity, either an array or
7437 -- record component, or an object declaration) according to the
7440 procedure Mark_Type (Ent : Entity_Id);
7441 -- Appropriately set flags on the given entity, a type
7443 procedure Set_Atomic_VFA (Ent : Entity_Id);
7444 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
7445 -- no explicit alignment was given, set alignment to unknown, since
7446 -- back end knows what the alignment requirements are for atomic and
7447 -- full access arrays. Note: this is necessary for derived types.
7449 -------------------------
7450 -- Check_VFA_Conflicts --
7451 -------------------------
7453 procedure Check_VFA_Conflicts (Ent : Entity_Id) is
7457 VFA_And_Atomic : Boolean := False;
7458 -- Set True if both VFA and Atomic present
7461 -- Fetch the type in case we are dealing with an object or
7464 if Is_Type (Ent) then
7467 pragma Assert (Is_Object (Ent)
7469 Nkind (Declaration_Node (Ent)) = N_Component_Declaration);
7474 -- Check Atomic and VFA used together
7476 if Prag_Id = Pragma_Volatile_Full_Access
7477 or else Is_Volatile_Full_Access (Ent)
7479 if Prag_Id = Pragma_Atomic
7480 or else Prag_Id = Pragma_Shared
7481 or else Is_Atomic (Ent)
7483 VFA_And_Atomic := True;
7485 elsif Is_Array_Type (Typ) then
7486 VFA_And_Atomic := Has_Atomic_Components (Typ);
7488 -- Note: Has_Atomic_Components is not used below, as this flag
7489 -- represents the pragma of the same name, Atomic_Components,
7490 -- which only applies to arrays.
7492 elsif Is_Record_Type (Typ) then
7493 -- Attributes cannot be applied to discriminants, only
7494 -- regular record components.
7496 Comp := First_Component (Typ);
7497 while Present (Comp) loop
7499 or else Is_Atomic (Typ)
7501 VFA_And_Atomic := True;
7506 Next_Component (Comp);
7510 if VFA_And_Atomic then
7512 ("cannot have Volatile_Full_Access and Atomic for same "
7516 end Check_VFA_Conflicts;
7518 ------------------------------
7519 -- Mark_Component_Or_Object --
7520 ------------------------------
7522 procedure Mark_Component_Or_Object (Ent : Entity_Id) is
7524 if Prag_Id = Pragma_Atomic
7525 or else Prag_Id = Pragma_Shared
7526 or else Prag_Id = Pragma_Volatile_Full_Access
7528 if Prag_Id = Pragma_Volatile_Full_Access then
7529 Set_Is_Volatile_Full_Access (Ent);
7531 Set_Is_Atomic (Ent);
7534 -- If the object declaration has an explicit initialization, a
7535 -- temporary may have to be created to hold the expression, to
7536 -- ensure that access to the object remains atomic.
7538 if Nkind (Parent (Ent)) = N_Object_Declaration
7539 and then Present (Expression (Parent (Ent)))
7541 Set_Has_Delayed_Freeze (Ent);
7545 -- Atomic/Shared/Volatile_Full_Access imply Independent
7547 if Prag_Id /= Pragma_Volatile then
7548 Set_Is_Independent (Ent);
7550 if Prag_Id = Pragma_Independent then
7551 Record_Independence_Check (N, Ent);
7555 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7557 if Prag_Id /= Pragma_Independent then
7558 Set_Is_Volatile (Ent);
7559 Set_Treat_As_Volatile (Ent);
7561 end Mark_Component_Or_Object;
7567 procedure Mark_Type (Ent : Entity_Id) is
7569 -- Attribute belongs on the base type. If the view of the type is
7570 -- currently private, it also belongs on the underlying type.
7572 -- In Ada_2020, the pragma can apply to a formal type, for which
7573 -- there may be no underlying type.
7575 if Prag_Id = Pragma_Atomic
7576 or else Prag_Id = Pragma_Shared
7577 or else Prag_Id = Pragma_Volatile_Full_Access
7579 Set_Atomic_VFA (Ent);
7580 Set_Atomic_VFA (Base_Type (Ent));
7582 if not Is_Generic_Type (Ent) then
7583 Set_Atomic_VFA (Underlying_Type (Ent));
7587 -- Atomic/Shared/Volatile_Full_Access imply Independent
7589 if Prag_Id /= Pragma_Volatile then
7590 Set_Is_Independent (Ent);
7591 Set_Is_Independent (Base_Type (Ent));
7593 if not Is_Generic_Type (Ent) then
7594 Set_Is_Independent (Underlying_Type (Ent));
7596 if Prag_Id = Pragma_Independent then
7597 Record_Independence_Check (N, Base_Type (Ent));
7602 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7604 if Prag_Id /= Pragma_Independent then
7605 Set_Is_Volatile (Ent);
7606 Set_Is_Volatile (Base_Type (Ent));
7608 if not Is_Generic_Type (Ent) then
7609 Set_Is_Volatile (Underlying_Type (Ent));
7610 Set_Treat_As_Volatile (Underlying_Type (Ent));
7613 Set_Treat_As_Volatile (Ent);
7616 -- Apply Volatile to the composite type's individual components,
7619 if Prag_Id = Pragma_Volatile
7620 and then Is_Record_Type (Etype (Ent))
7625 Comp := First_Component (Ent);
7626 while Present (Comp) loop
7627 Mark_Component_Or_Object (Comp);
7629 Next_Component (Comp);
7635 --------------------
7636 -- Set_Atomic_VFA --
7637 --------------------
7639 procedure Set_Atomic_VFA (Ent : Entity_Id) is
7641 if Prag_Id = Pragma_Volatile_Full_Access then
7642 Set_Is_Volatile_Full_Access (Ent);
7644 Set_Is_Atomic (Ent);
7647 if not Has_Alignment_Clause (Ent) then
7648 Set_Alignment (Ent, Uint_0);
7658 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
7661 Check_Ada_83_Warning;
7662 Check_No_Identifiers;
7663 Check_Arg_Count (1);
7664 Check_Arg_Is_Local_Name (Arg1);
7665 E_Arg := Get_Pragma_Arg (Arg1);
7667 if Etype (E_Arg) = Any_Type then
7671 E := Entity (E_Arg);
7673 -- A pragma that applies to a Ghost entity becomes Ghost for the
7674 -- purposes of legality checks and removal of ignored Ghost code.
7676 Mark_Ghost_Pragma (N, E);
7678 -- Check duplicate before we chain ourselves
7680 Check_Duplicate_Pragma (E);
7682 -- Check appropriateness of the entity
7684 Decl := Declaration_Node (E);
7686 -- Deal with the case where the pragma/attribute is applied to a type
7689 if Rep_Item_Too_Early (E, N)
7690 or else Rep_Item_Too_Late (E, N)
7694 Check_First_Subtype (Arg1);
7699 -- Deal with the case where the pragma/attribute applies to a
7700 -- component or object declaration.
7702 elsif Nkind (Decl) = N_Object_Declaration
7703 or else (Nkind (Decl) = N_Component_Declaration
7704 and then Original_Record_Component (E) = E)
7706 if Rep_Item_Too_Late (E, N) then
7710 Mark_Component_Or_Object (E);
7712 -- In other cases give an error
7715 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7718 -- Check that Volatile_Full_Access and Atomic do not conflict
7720 Check_VFA_Conflicts (E);
7722 -- Check for the application of Atomic or Volatile_Full_Access to
7723 -- an entity that has [nonatomic] aliased, or else specified to be
7724 -- independently addressable, subcomponents.
7726 if (Prag_Id = Pragma_Atomic and then Ada_Version >= Ada_2020)
7727 or else Prag_Id = Pragma_Volatile_Full_Access
7729 Check_Atomic_VFA (E, VFA => Prag_Id = Pragma_Volatile_Full_Access);
7732 -- The following check is only relevant when SPARK_Mode is on as
7733 -- this is not a standard Ada legality rule. Pragma Volatile can
7734 -- only apply to a full type declaration or an object declaration
7735 -- (SPARK RM 7.1.3(2)). Original_Node is necessary to account for
7736 -- untagged derived types that are rewritten as subtypes of their
7737 -- respective root types.
7740 and then Prag_Id = Pragma_Volatile
7741 and then not Nkind_In (Original_Node (Decl),
7742 N_Full_Type_Declaration,
7743 N_Object_Declaration,
7744 N_Single_Protected_Declaration,
7745 N_Single_Task_Declaration)
7748 ("argument of pragma % must denote a full type or object "
7749 & "declaration", Arg1);
7751 end Process_Atomic_Independent_Shared_Volatile;
7753 -------------------------------------------
7754 -- Process_Compile_Time_Warning_Or_Error --
7755 -------------------------------------------
7757 procedure Process_Compile_Time_Warning_Or_Error is
7758 P : Node_Id := Parent (N);
7759 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
7762 Check_Arg_Count (2);
7763 Check_No_Identifiers;
7764 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
7765 Analyze_And_Resolve (Arg1x, Standard_Boolean);
7767 -- In GNATprove mode, pragma Compile_Time_Error is translated as
7768 -- a Check pragma in GNATprove mode, handled as an assumption in
7769 -- GNATprove. This is correct as the compiler will issue an error
7770 -- if the condition cannot be statically evaluated to False.
7771 -- Compile_Time_Warning are ignored, as the analyzer may not have the
7772 -- same information as the compiler (in particular regarding size of
7773 -- objects decided in gigi) so it makes no sense to issue a warning
7776 if GNATprove_Mode then
7777 if Prag_Id = Pragma_Compile_Time_Error then
7781 -- Implement Compile_Time_Error by generating
7782 -- a corresponding Check pragma:
7784 -- pragma Check (name, condition);
7786 -- where name is the identifier matching the pragma name. So
7787 -- rewrite pragma in this manner and analyze the result.
7789 New_Args := New_List
7790 (Make_Pragma_Argument_Association
7792 Expression => Make_Identifier (Loc, Pname)),
7793 Make_Pragma_Argument_Association
7795 Expression => Arg1x));
7797 -- Rewrite as Check pragma
7801 Chars => Name_Check,
7802 Pragma_Argument_Associations => New_Args));
7808 Rewrite (N, Make_Null_Statement (Loc));
7814 -- If the condition is known at compile time (now), validate it now.
7815 -- Otherwise, register the expression for validation after the back
7816 -- end has been called, because it might be known at compile time
7817 -- then. For example, if the expression is "Record_Type'Size /= 32"
7818 -- it might be known after the back end has determined the size of
7819 -- Record_Type. We do not defer validation if we're inside a generic
7820 -- unit, because we will have more information in the instances.
7822 if Compile_Time_Known_Value (Arg1x) then
7823 Validate_Compile_Time_Warning_Or_Error (N, Sloc (Arg1));
7825 while Present (P) and then Nkind (P) not in N_Generic_Declaration
7827 if Nkind_In (P, N_Package_Body, N_Subprogram_Body) then
7828 P := Corresponding_Spec (P);
7835 Defer_Compile_Time_Warning_Error_To_BE (N);
7838 end Process_Compile_Time_Warning_Or_Error;
7840 ------------------------
7841 -- Process_Convention --
7842 ------------------------
7844 procedure Process_Convention
7845 (C : out Convention_Id;
7846 Ent : out Entity_Id)
7850 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
7851 -- Called if we have more than one Export/Import/Convention pragma.
7852 -- This is generally illegal, but we have a special case of allowing
7853 -- Import and Interface to coexist if they specify the convention in
7854 -- a consistent manner. We are allowed to do this, since Interface is
7855 -- an implementation defined pragma, and we choose to do it since we
7856 -- know Rational allows this combination. S is the entity id of the
7857 -- subprogram in question. This procedure also sets the special flag
7858 -- Import_Interface_Present in both pragmas in the case where we do
7859 -- have matching Import and Interface pragmas.
7861 procedure Set_Convention_From_Pragma (E : Entity_Id);
7862 -- Set convention in entity E, and also flag that the entity has a
7863 -- convention pragma. If entity is for a private or incomplete type,
7864 -- also set convention and flag on underlying type. This procedure
7865 -- also deals with the special case of C_Pass_By_Copy convention,
7866 -- and error checks for inappropriate convention specification.
7868 -------------------------------
7869 -- Diagnose_Multiple_Pragmas --
7870 -------------------------------
7872 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
7873 Pdec : constant Node_Id := Declaration_Node (S);
7877 function Same_Convention (Decl : Node_Id) return Boolean;
7878 -- Decl is a pragma node. This function returns True if this
7879 -- pragma has a first argument that is an identifier with a
7880 -- Chars field corresponding to the Convention_Id C.
7882 function Same_Name (Decl : Node_Id) return Boolean;
7883 -- Decl is a pragma node. This function returns True if this
7884 -- pragma has a second argument that is an identifier with a
7885 -- Chars field that matches the Chars of the current subprogram.
7887 ---------------------
7888 -- Same_Convention --
7889 ---------------------
7891 function Same_Convention (Decl : Node_Id) return Boolean is
7892 Arg1 : constant Node_Id :=
7893 First (Pragma_Argument_Associations (Decl));
7896 if Present (Arg1) then
7898 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
7900 if Nkind (Arg) = N_Identifier
7901 and then Is_Convention_Name (Chars (Arg))
7902 and then Get_Convention_Id (Chars (Arg)) = C
7910 end Same_Convention;
7916 function Same_Name (Decl : Node_Id) return Boolean is
7917 Arg1 : constant Node_Id :=
7918 First (Pragma_Argument_Associations (Decl));
7926 Arg2 := Next (Arg1);
7933 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
7935 if Nkind (Arg) = N_Identifier
7936 and then Chars (Arg) = Chars (S)
7945 -- Start of processing for Diagnose_Multiple_Pragmas
7950 -- Definitely give message if we have Convention/Export here
7952 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
7955 -- If we have an Import or Export, scan back from pragma to
7956 -- find any previous pragma applying to the same procedure.
7957 -- The scan will be terminated by the start of the list, or
7958 -- hitting the subprogram declaration. This won't allow one
7959 -- pragma to appear in the public part and one in the private
7960 -- part, but that seems very unlikely in practice.
7964 while Present (Decl) and then Decl /= Pdec loop
7966 -- Look for pragma with same name as us
7968 if Nkind (Decl) = N_Pragma
7969 and then Same_Name (Decl)
7971 -- Give error if same as our pragma or Export/Convention
7973 if Nam_In (Pragma_Name_Unmapped (Decl),
7976 Pragma_Name_Unmapped (N))
7980 -- Case of Import/Interface or the other way round
7982 elsif Nam_In (Pragma_Name_Unmapped (Decl),
7983 Name_Interface, Name_Import)
7985 -- Here we know that we have Import and Interface. It
7986 -- doesn't matter which way round they are. See if
7987 -- they specify the same convention. If so, all OK,
7988 -- and set special flags to stop other messages
7990 if Same_Convention (Decl) then
7991 Set_Import_Interface_Present (N);
7992 Set_Import_Interface_Present (Decl);
7995 -- If different conventions, special message
7998 Error_Msg_Sloc := Sloc (Decl);
8000 ("convention differs from that given#", Arg1);
8010 -- Give message if needed if we fall through those tests
8011 -- except on Relaxed_RM_Semantics where we let go: either this
8012 -- is a case accepted/ignored by other Ada compilers (e.g.
8013 -- a mix of Convention and Import), or another error will be
8014 -- generated later (e.g. using both Import and Export).
8016 if Err and not Relaxed_RM_Semantics then
8018 ("at most one Convention/Export/Import pragma is allowed",
8021 end Diagnose_Multiple_Pragmas;
8023 --------------------------------
8024 -- Set_Convention_From_Pragma --
8025 --------------------------------
8027 procedure Set_Convention_From_Pragma (E : Entity_Id) is
8029 -- Ada 2005 (AI-430): Check invalid attempt to change convention
8030 -- for an overridden dispatching operation. Technically this is
8031 -- an amendment and should only be done in Ada 2005 mode. However,
8032 -- this is clearly a mistake, since the problem that is addressed
8033 -- by this AI is that there is a clear gap in the RM.
8035 if Is_Dispatching_Operation (E)
8036 and then Present (Overridden_Operation (E))
8037 and then C /= Convention (Overridden_Operation (E))
8040 ("cannot change convention for overridden dispatching "
8041 & "operation", Arg1);
8044 -- Special checks for Convention_Stdcall
8046 if C = Convention_Stdcall then
8048 -- A dispatching call is not allowed. A dispatching subprogram
8049 -- cannot be used to interface to the Win32 API, so in fact
8050 -- this check does not impose any effective restriction.
8052 if Is_Dispatching_Operation (E) then
8053 Error_Msg_Sloc := Sloc (E);
8055 -- Note: make this unconditional so that if there is more
8056 -- than one call to which the pragma applies, we get a
8057 -- message for each call. Also don't use Error_Pragma,
8058 -- so that we get multiple messages.
8061 ("dispatching subprogram# cannot use Stdcall convention!",
8064 -- Several allowed cases
8066 elsif Is_Subprogram_Or_Generic_Subprogram (E)
8070 or else Ekind (E) = E_Variable
8072 -- A component as well. The entity does not have its Ekind
8073 -- set until the enclosing record declaration is fully
8076 or else Nkind (Parent (E)) = N_Component_Declaration
8078 -- An access to subprogram is also allowed
8082 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
8084 -- Allow internal call to set convention of subprogram type
8086 or else Ekind (E) = E_Subprogram_Type
8092 ("second argument of pragma% must be subprogram (type)",
8097 -- Set the convention
8099 Set_Convention (E, C);
8100 Set_Has_Convention_Pragma (E);
8102 -- For the case of a record base type, also set the convention of
8103 -- any anonymous access types declared in the record which do not
8104 -- currently have a specified convention.
8106 if Is_Record_Type (E) and then Is_Base_Type (E) then
8111 Comp := First_Component (E);
8112 while Present (Comp) loop
8113 if Present (Etype (Comp))
8114 and then Ekind_In (Etype (Comp),
8115 E_Anonymous_Access_Type,
8116 E_Anonymous_Access_Subprogram_Type)
8117 and then not Has_Convention_Pragma (Comp)
8119 Set_Convention (Comp, C);
8122 Next_Component (Comp);
8127 -- Deal with incomplete/private type case, where underlying type
8128 -- is available, so set convention of that underlying type.
8130 if Is_Incomplete_Or_Private_Type (E)
8131 and then Present (Underlying_Type (E))
8133 Set_Convention (Underlying_Type (E), C);
8134 Set_Has_Convention_Pragma (Underlying_Type (E), True);
8137 -- A class-wide type should inherit the convention of the specific
8138 -- root type (although this isn't specified clearly by the RM).
8140 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
8141 Set_Convention (Class_Wide_Type (E), C);
8144 -- If the entity is a record type, then check for special case of
8145 -- C_Pass_By_Copy, which is treated the same as C except that the
8146 -- special record flag is set. This convention is only permitted
8147 -- on record types (see AI95-00131).
8149 if Cname = Name_C_Pass_By_Copy then
8150 if Is_Record_Type (E) then
8151 Set_C_Pass_By_Copy (Base_Type (E));
8152 elsif Is_Incomplete_Or_Private_Type (E)
8153 and then Is_Record_Type (Underlying_Type (E))
8155 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
8158 ("C_Pass_By_Copy convention allowed only for record type",
8163 -- If the entity is a derived boolean type, check for the special
8164 -- case of convention C, C++, or Fortran, where we consider any
8165 -- nonzero value to represent true.
8167 if Is_Discrete_Type (E)
8168 and then Root_Type (Etype (E)) = Standard_Boolean
8174 C = Convention_Fortran)
8176 Set_Nonzero_Is_True (Base_Type (E));
8178 end Set_Convention_From_Pragma;
8182 Comp_Unit : Unit_Number_Type;
8187 -- Start of processing for Process_Convention
8190 Check_At_Least_N_Arguments (2);
8191 Check_Optional_Identifier (Arg1, Name_Convention);
8192 Check_Arg_Is_Identifier (Arg1);
8193 Cname := Chars (Get_Pragma_Arg (Arg1));
8195 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
8196 -- tested again below to set the critical flag).
8198 if Cname = Name_C_Pass_By_Copy then
8201 -- Otherwise we must have something in the standard convention list
8203 elsif Is_Convention_Name (Cname) then
8204 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
8206 -- Otherwise warn on unrecognized convention
8209 if Warn_On_Export_Import then
8211 ("??unrecognized convention name, C assumed",
8212 Get_Pragma_Arg (Arg1));
8218 Check_Optional_Identifier (Arg2, Name_Entity);
8219 Check_Arg_Is_Local_Name (Arg2);
8221 Id := Get_Pragma_Arg (Arg2);
8224 if not Is_Entity_Name (Id) then
8225 Error_Pragma_Arg ("entity name required", Arg2);
8230 -- Set entity to return
8234 -- Ada_Pass_By_Copy special checking
8236 if C = Convention_Ada_Pass_By_Copy then
8237 if not Is_First_Subtype (E) then
8239 ("convention `Ada_Pass_By_Copy` only allowed for types",
8243 if Is_By_Reference_Type (E) then
8245 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
8249 -- Ada_Pass_By_Reference special checking
8251 elsif C = Convention_Ada_Pass_By_Reference then
8252 if not Is_First_Subtype (E) then
8254 ("convention `Ada_Pass_By_Reference` only allowed for types",
8258 if Is_By_Copy_Type (E) then
8260 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
8265 -- Go to renamed subprogram if present, since convention applies to
8266 -- the actual renamed entity, not to the renaming entity. If the
8267 -- subprogram is inherited, go to parent subprogram.
8269 if Is_Subprogram (E)
8270 and then Present (Alias (E))
8272 if Nkind (Parent (Declaration_Node (E))) =
8273 N_Subprogram_Renaming_Declaration
8275 if Scope (E) /= Scope (Alias (E)) then
8277 ("cannot apply pragma% to non-local entity&#", E);
8282 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
8283 N_Private_Extension_Declaration)
8284 and then Scope (E) = Scope (Alias (E))
8288 -- Return the parent subprogram the entity was inherited from
8294 -- Check that we are not applying this to a specless body. Relax this
8295 -- check if Relaxed_RM_Semantics to accommodate other Ada compilers.
8297 if Is_Subprogram (E)
8298 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
8299 and then not Relaxed_RM_Semantics
8302 ("pragma% requires separate spec and must come before body");
8305 -- Check that we are not applying this to a named constant
8307 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
8308 Error_Msg_Name_1 := Pname;
8310 ("cannot apply pragma% to named constant!",
8311 Get_Pragma_Arg (Arg2));
8313 ("\supply appropriate type for&!", Arg2);
8316 if Ekind (E) = E_Enumeration_Literal then
8317 Error_Pragma ("enumeration literal not allowed for pragma%");
8320 -- Check for rep item appearing too early or too late
8322 if Etype (E) = Any_Type
8323 or else Rep_Item_Too_Early (E, N)
8327 elsif Present (Underlying_Type (E)) then
8328 E := Underlying_Type (E);
8331 if Rep_Item_Too_Late (E, N) then
8335 if Has_Convention_Pragma (E) then
8336 Diagnose_Multiple_Pragmas (E);
8338 elsif Convention (E) = Convention_Protected
8339 or else Ekind (Scope (E)) = E_Protected_Type
8342 ("a protected operation cannot be given a different convention",
8346 -- For Intrinsic, a subprogram is required
8348 if C = Convention_Intrinsic
8349 and then not Is_Subprogram_Or_Generic_Subprogram (E)
8351 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
8353 if not (Is_Type (E) and then Relaxed_RM_Semantics) then
8355 ("second argument of pragma% must be a subprogram", Arg2);
8359 -- Deal with non-subprogram cases
8361 if not Is_Subprogram_Or_Generic_Subprogram (E) then
8362 Set_Convention_From_Pragma (E);
8366 -- The pragma must apply to a first subtype, but it can also
8367 -- apply to a generic type in a generic formal part, in which
8368 -- case it will also appear in the corresponding instance.
8370 if Is_Generic_Type (E) or else In_Instance then
8373 Check_First_Subtype (Arg2);
8376 Set_Convention_From_Pragma (Base_Type (E));
8378 -- For access subprograms, we must set the convention on the
8379 -- internally generated directly designated type as well.
8381 if Ekind (E) = E_Access_Subprogram_Type then
8382 Set_Convention_From_Pragma (Directly_Designated_Type (E));
8386 -- For the subprogram case, set proper convention for all homonyms
8387 -- in same scope and the same declarative part, i.e. the same
8388 -- compilation unit.
8391 Comp_Unit := Get_Source_Unit (E);
8392 Set_Convention_From_Pragma (E);
8394 -- Treat a pragma Import as an implicit body, and pragma import
8395 -- as implicit reference (for navigation in GNAT Studio).
8397 if Prag_Id = Pragma_Import then
8398 Generate_Reference (E, Id, 'b');
8400 -- For exported entities we restrict the generation of references
8401 -- to entities exported to foreign languages since entities
8402 -- exported to Ada do not provide further information to
8403 -- GNAT Studio and add undesired references to the output of the
8406 elsif Prag_Id = Pragma_Export
8407 and then Convention (E) /= Convention_Ada
8409 Generate_Reference (E, Id, 'i');
8412 -- If the pragma comes from an aspect, it only applies to the
8413 -- given entity, not its homonyms.
8415 if From_Aspect_Specification (N) then
8416 if C = Convention_Intrinsic
8417 and then Nkind (Ent) = N_Defining_Operator_Symbol
8419 if Is_Fixed_Point_Type (Etype (Ent))
8420 or else Is_Fixed_Point_Type (Etype (First_Entity (Ent)))
8421 or else Is_Fixed_Point_Type (Etype (Last_Entity (Ent)))
8424 ("no intrinsic operator available for this fixed-point "
8427 ("\use expression functions with the desired "
8428 & "conversions made explicit", N);
8435 -- Otherwise Loop through the homonyms of the pragma argument's
8436 -- entity, an apply convention to those in the current scope.
8442 exit when No (E1) or else Scope (E1) /= Current_Scope;
8444 -- Ignore entry for which convention is already set
8446 if Has_Convention_Pragma (E1) then
8450 if Is_Subprogram (E1)
8451 and then Nkind (Parent (Declaration_Node (E1))) =
8453 and then not Relaxed_RM_Semantics
8455 Set_Has_Completion (E); -- to prevent cascaded error
8457 ("pragma% requires separate spec and must come before "
8461 -- Do not set the pragma on inherited operations or on formal
8464 if Comes_From_Source (E1)
8465 and then Comp_Unit = Get_Source_Unit (E1)
8466 and then not Is_Formal_Subprogram (E1)
8467 and then Nkind (Original_Node (Parent (E1))) /=
8468 N_Full_Type_Declaration
8470 if Present (Alias (E1))
8471 and then Scope (E1) /= Scope (Alias (E1))
8474 ("cannot apply pragma% to non-local entity& declared#",
8478 Set_Convention_From_Pragma (E1);
8480 if Prag_Id = Pragma_Import then
8481 Generate_Reference (E1, Id, 'b');
8489 end Process_Convention;
8491 ----------------------------------------
8492 -- Process_Disable_Enable_Atomic_Sync --
8493 ----------------------------------------
8495 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
8497 Check_No_Identifiers;
8498 Check_At_Most_N_Arguments (1);
8500 -- Modeled internally as
8501 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
8506 Pragma_Argument_Associations => New_List (
8507 Make_Pragma_Argument_Association (Loc,
8509 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
8511 if Present (Arg1) then
8512 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
8516 end Process_Disable_Enable_Atomic_Sync;
8518 -------------------------------------------------
8519 -- Process_Extended_Import_Export_Internal_Arg --
8520 -------------------------------------------------
8522 procedure Process_Extended_Import_Export_Internal_Arg
8523 (Arg_Internal : Node_Id := Empty)
8526 if No (Arg_Internal) then
8527 Error_Pragma ("Internal parameter required for pragma%");
8530 if Nkind (Arg_Internal) = N_Identifier then
8533 elsif Nkind (Arg_Internal) = N_Operator_Symbol
8534 and then (Prag_Id = Pragma_Import_Function
8536 Prag_Id = Pragma_Export_Function)
8542 ("wrong form for Internal parameter for pragma%", Arg_Internal);
8545 Check_Arg_Is_Local_Name (Arg_Internal);
8546 end Process_Extended_Import_Export_Internal_Arg;
8548 --------------------------------------------------
8549 -- Process_Extended_Import_Export_Object_Pragma --
8550 --------------------------------------------------
8552 procedure Process_Extended_Import_Export_Object_Pragma
8553 (Arg_Internal : Node_Id;
8554 Arg_External : Node_Id;
8560 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8561 Def_Id := Entity (Arg_Internal);
8563 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
8565 ("pragma% must designate an object", Arg_Internal);
8568 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
8570 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
8573 ("previous Common/Psect_Object applies, pragma % not permitted",
8577 if Rep_Item_Too_Late (Def_Id, N) then
8581 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
8583 if Present (Arg_Size) then
8584 Check_Arg_Is_External_Name (Arg_Size);
8587 -- Export_Object case
8589 if Prag_Id = Pragma_Export_Object then
8590 if not Is_Library_Level_Entity (Def_Id) then
8592 ("argument for pragma% must be library level entity",
8596 if Ekind (Current_Scope) = E_Generic_Package then
8597 Error_Pragma ("pragma& cannot appear in a generic unit");
8600 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
8602 ("exported object must have compile time known size",
8606 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
8607 Error_Msg_N ("??duplicate Export_Object pragma", N);
8609 Set_Exported (Def_Id, Arg_Internal);
8612 -- Import_Object case
8615 if Is_Concurrent_Type (Etype (Def_Id)) then
8617 ("cannot use pragma% for task/protected object",
8621 if Ekind (Def_Id) = E_Constant then
8623 ("cannot import a constant", Arg_Internal);
8626 if Warn_On_Export_Import
8627 and then Has_Discriminants (Etype (Def_Id))
8630 ("imported value must be initialized??", Arg_Internal);
8633 if Warn_On_Export_Import
8634 and then Is_Access_Type (Etype (Def_Id))
8637 ("cannot import object of an access type??", Arg_Internal);
8640 if Warn_On_Export_Import
8641 and then Is_Imported (Def_Id)
8643 Error_Msg_N ("??duplicate Import_Object pragma", N);
8645 -- Check for explicit initialization present. Note that an
8646 -- initialization generated by the code generator, e.g. for an
8647 -- access type, does not count here.
8649 elsif Present (Expression (Parent (Def_Id)))
8652 (Original_Node (Expression (Parent (Def_Id))))
8654 Error_Msg_Sloc := Sloc (Def_Id);
8656 ("imported entities cannot be initialized (RM B.1(24))",
8657 "\no initialization allowed for & declared#", Arg1);
8659 Set_Imported (Def_Id);
8660 Note_Possible_Modification (Arg_Internal, Sure => False);
8663 end Process_Extended_Import_Export_Object_Pragma;
8665 ------------------------------------------------------
8666 -- Process_Extended_Import_Export_Subprogram_Pragma --
8667 ------------------------------------------------------
8669 procedure Process_Extended_Import_Export_Subprogram_Pragma
8670 (Arg_Internal : Node_Id;
8671 Arg_External : Node_Id;
8672 Arg_Parameter_Types : Node_Id;
8673 Arg_Result_Type : Node_Id := Empty;
8674 Arg_Mechanism : Node_Id;
8675 Arg_Result_Mechanism : Node_Id := Empty)
8681 Ambiguous : Boolean;
8684 function Same_Base_Type
8686 Formal : Entity_Id) return Boolean;
8687 -- Determines if Ptype references the type of Formal. Note that only
8688 -- the base types need to match according to the spec. Ptype here is
8689 -- the argument from the pragma, which is either a type name, or an
8690 -- access attribute.
8692 --------------------
8693 -- Same_Base_Type --
8694 --------------------
8696 function Same_Base_Type
8698 Formal : Entity_Id) return Boolean
8700 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
8704 -- Case where pragma argument is typ'Access
8706 if Nkind (Ptype) = N_Attribute_Reference
8707 and then Attribute_Name (Ptype) = Name_Access
8709 Pref := Prefix (Ptype);
8712 if not Is_Entity_Name (Pref)
8713 or else Entity (Pref) = Any_Type
8718 -- We have a match if the corresponding argument is of an
8719 -- anonymous access type, and its designated type matches the
8720 -- type of the prefix of the access attribute
8722 return Ekind (Ftyp) = E_Anonymous_Access_Type
8723 and then Base_Type (Entity (Pref)) =
8724 Base_Type (Etype (Designated_Type (Ftyp)));
8726 -- Case where pragma argument is a type name
8731 if not Is_Entity_Name (Ptype)
8732 or else Entity (Ptype) = Any_Type
8737 -- We have a match if the corresponding argument is of the type
8738 -- given in the pragma (comparing base types)
8740 return Base_Type (Entity (Ptype)) = Ftyp;
8744 -- Start of processing for
8745 -- Process_Extended_Import_Export_Subprogram_Pragma
8748 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8752 -- Loop through homonyms (overloadings) of the entity
8754 Hom_Id := Entity (Arg_Internal);
8755 while Present (Hom_Id) loop
8756 Def_Id := Get_Base_Subprogram (Hom_Id);
8758 -- We need a subprogram in the current scope
8760 if not Is_Subprogram (Def_Id)
8761 or else Scope (Def_Id) /= Current_Scope
8768 -- Pragma cannot apply to subprogram body
8770 if Is_Subprogram (Def_Id)
8771 and then Nkind (Parent (Declaration_Node (Def_Id))) =
8775 ("pragma% requires separate spec and must come before "
8779 -- Test result type if given, note that the result type
8780 -- parameter can only be present for the function cases.
8782 if Present (Arg_Result_Type)
8783 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
8787 elsif Etype (Def_Id) /= Standard_Void_Type
8788 and then Nam_In (Pname, Name_Export_Procedure,
8789 Name_Import_Procedure)
8793 -- Test parameter types if given. Note that this parameter has
8794 -- not been analyzed (and must not be, since it is semantic
8795 -- nonsense), so we get it as the parser left it.
8797 elsif Present (Arg_Parameter_Types) then
8798 Check_Matching_Types : declare
8803 Formal := First_Formal (Def_Id);
8805 if Nkind (Arg_Parameter_Types) = N_Null then
8806 if Present (Formal) then
8810 -- A list of one type, e.g. (List) is parsed as a
8811 -- parenthesized expression.
8813 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
8814 and then Paren_Count (Arg_Parameter_Types) = 1
8817 or else Present (Next_Formal (Formal))
8822 Same_Base_Type (Arg_Parameter_Types, Formal);
8825 -- A list of more than one type is parsed as a aggregate
8827 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
8828 and then Paren_Count (Arg_Parameter_Types) = 0
8830 Ptype := First (Expressions (Arg_Parameter_Types));
8831 while Present (Ptype) or else Present (Formal) loop
8834 or else not Same_Base_Type (Ptype, Formal)
8839 Next_Formal (Formal);
8844 -- Anything else is of the wrong form
8848 ("wrong form for Parameter_Types parameter",
8849 Arg_Parameter_Types);
8851 end Check_Matching_Types;
8854 -- Match is now False if the entry we found did not match
8855 -- either a supplied Parameter_Types or Result_Types argument
8861 -- Ambiguous case, the flag Ambiguous shows if we already
8862 -- detected this and output the initial messages.
8865 if not Ambiguous then
8867 Error_Msg_Name_1 := Pname;
8869 ("pragma% does not uniquely identify subprogram!",
8871 Error_Msg_Sloc := Sloc (Ent);
8872 Error_Msg_N ("matching subprogram #!", N);
8876 Error_Msg_Sloc := Sloc (Def_Id);
8877 Error_Msg_N ("matching subprogram #!", N);
8882 Hom_Id := Homonym (Hom_Id);
8885 -- See if we found an entry
8888 if not Ambiguous then
8889 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
8891 ("pragma% cannot be given for generic subprogram");
8894 ("pragma% does not identify local subprogram");
8901 -- Import pragmas must be for imported entities
8903 if Prag_Id = Pragma_Import_Function
8905 Prag_Id = Pragma_Import_Procedure
8907 Prag_Id = Pragma_Import_Valued_Procedure
8909 if not Is_Imported (Ent) then
8911 ("pragma Import or Interface must precede pragma%");
8914 -- Here we have the Export case which can set the entity as exported
8916 -- But does not do so if the specified external name is null, since
8917 -- that is taken as a signal in DEC Ada 83 (with which we want to be
8918 -- compatible) to request no external name.
8920 elsif Nkind (Arg_External) = N_String_Literal
8921 and then String_Length (Strval (Arg_External)) = 0
8925 -- In all other cases, set entity as exported
8928 Set_Exported (Ent, Arg_Internal);
8931 -- Special processing for Valued_Procedure cases
8933 if Prag_Id = Pragma_Import_Valued_Procedure
8935 Prag_Id = Pragma_Export_Valued_Procedure
8937 Formal := First_Formal (Ent);
8940 Error_Pragma ("at least one parameter required for pragma%");
8942 elsif Ekind (Formal) /= E_Out_Parameter then
8943 Error_Pragma ("first parameter must have mode out for pragma%");
8946 Set_Is_Valued_Procedure (Ent);
8950 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
8952 -- Process Result_Mechanism argument if present. We have already
8953 -- checked that this is only allowed for the function case.
8955 if Present (Arg_Result_Mechanism) then
8956 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
8959 -- Process Mechanism parameter if present. Note that this parameter
8960 -- is not analyzed, and must not be analyzed since it is semantic
8961 -- nonsense, so we get it in exactly as the parser left it.
8963 if Present (Arg_Mechanism) then
8971 -- A single mechanism association without a formal parameter
8972 -- name is parsed as a parenthesized expression. All other
8973 -- cases are parsed as aggregates, so we rewrite the single
8974 -- parameter case as an aggregate for consistency.
8976 if Nkind (Arg_Mechanism) /= N_Aggregate
8977 and then Paren_Count (Arg_Mechanism) = 1
8979 Rewrite (Arg_Mechanism,
8980 Make_Aggregate (Sloc (Arg_Mechanism),
8981 Expressions => New_List (
8982 Relocate_Node (Arg_Mechanism))));
8985 -- Case of only mechanism name given, applies to all formals
8987 if Nkind (Arg_Mechanism) /= N_Aggregate then
8988 Formal := First_Formal (Ent);
8989 while Present (Formal) loop
8990 Set_Mechanism_Value (Formal, Arg_Mechanism);
8991 Next_Formal (Formal);
8994 -- Case of list of mechanism associations given
8997 if Null_Record_Present (Arg_Mechanism) then
8999 ("inappropriate form for Mechanism parameter",
9003 -- Deal with positional ones first
9005 Formal := First_Formal (Ent);
9007 if Present (Expressions (Arg_Mechanism)) then
9008 Mname := First (Expressions (Arg_Mechanism));
9009 while Present (Mname) loop
9012 ("too many mechanism associations", Mname);
9015 Set_Mechanism_Value (Formal, Mname);
9016 Next_Formal (Formal);
9021 -- Deal with named entries
9023 if Present (Component_Associations (Arg_Mechanism)) then
9024 Massoc := First (Component_Associations (Arg_Mechanism));
9025 while Present (Massoc) loop
9026 Choice := First (Choices (Massoc));
9028 if Nkind (Choice) /= N_Identifier
9029 or else Present (Next (Choice))
9032 ("incorrect form for mechanism association",
9036 Formal := First_Formal (Ent);
9040 ("parameter name & not present", Choice);
9043 if Chars (Choice) = Chars (Formal) then
9045 (Formal, Expression (Massoc));
9047 -- Set entity on identifier for proper tree
9050 Set_Entity (Choice, Formal);
9055 Next_Formal (Formal);
9064 end Process_Extended_Import_Export_Subprogram_Pragma;
9066 --------------------------
9067 -- Process_Generic_List --
9068 --------------------------
9070 procedure Process_Generic_List is
9075 Check_No_Identifiers;
9076 Check_At_Least_N_Arguments (1);
9078 -- Check all arguments are names of generic units or instances
9081 while Present (Arg) loop
9082 Exp := Get_Pragma_Arg (Arg);
9085 if not Is_Entity_Name (Exp)
9087 (not Is_Generic_Instance (Entity (Exp))
9089 not Is_Generic_Unit (Entity (Exp)))
9092 ("pragma% argument must be name of generic unit/instance",
9098 end Process_Generic_List;
9100 ------------------------------------
9101 -- Process_Import_Predefined_Type --
9102 ------------------------------------
9104 procedure Process_Import_Predefined_Type is
9105 Loc : constant Source_Ptr := Sloc (N);
9107 Ftyp : Node_Id := Empty;
9113 Nam := String_To_Name (Strval (Expression (Arg3)));
9115 Elmt := First_Elmt (Predefined_Float_Types);
9116 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
9120 Ftyp := Node (Elmt);
9122 if Present (Ftyp) then
9124 -- Don't build a derived type declaration, because predefined C
9125 -- types have no declaration anywhere, so cannot really be named.
9126 -- Instead build a full type declaration, starting with an
9127 -- appropriate type definition is built
9129 if Is_Floating_Point_Type (Ftyp) then
9130 Def := Make_Floating_Point_Definition (Loc,
9131 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
9132 Make_Real_Range_Specification (Loc,
9133 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
9134 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
9136 -- Should never have a predefined type we cannot handle
9139 raise Program_Error;
9142 -- Build and insert a Full_Type_Declaration, which will be
9143 -- analyzed as soon as this list entry has been analyzed.
9145 Decl := Make_Full_Type_Declaration (Loc,
9146 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
9147 Type_Definition => Def);
9149 Insert_After (N, Decl);
9150 Mark_Rewrite_Insertion (Decl);
9153 Error_Pragma_Arg ("no matching type found for pragma%", Arg2);
9155 end Process_Import_Predefined_Type;
9157 ---------------------------------
9158 -- Process_Import_Or_Interface --
9159 ---------------------------------
9161 procedure Process_Import_Or_Interface is
9167 -- In Relaxed_RM_Semantics, support old Ada 83 style:
9168 -- pragma Import (Entity, "external name");
9170 if Relaxed_RM_Semantics
9171 and then Arg_Count = 2
9172 and then Prag_Id = Pragma_Import
9173 and then Nkind (Expression (Arg2)) = N_String_Literal
9176 Def_Id := Get_Pragma_Arg (Arg1);
9179 if not Is_Entity_Name (Def_Id) then
9180 Error_Pragma_Arg ("entity name required", Arg1);
9183 Def_Id := Entity (Def_Id);
9184 Kill_Size_Check_Code (Def_Id);
9185 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
9188 Process_Convention (C, Def_Id);
9190 -- A pragma that applies to a Ghost entity becomes Ghost for the
9191 -- purposes of legality checks and removal of ignored Ghost code.
9193 Mark_Ghost_Pragma (N, Def_Id);
9194 Kill_Size_Check_Code (Def_Id);
9195 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
9198 -- Various error checks
9200 if Ekind_In (Def_Id, E_Variable, E_Constant) then
9202 -- We do not permit Import to apply to a renaming declaration
9204 if Present (Renamed_Object (Def_Id)) then
9206 ("pragma% not allowed for object renaming", Arg2);
9208 -- User initialization is not allowed for imported object, but
9209 -- the object declaration may contain a default initialization,
9210 -- that will be discarded. Note that an explicit initialization
9211 -- only counts if it comes from source, otherwise it is simply
9212 -- the code generator making an implicit initialization explicit.
9214 elsif Present (Expression (Parent (Def_Id)))
9215 and then Comes_From_Source
9216 (Original_Node (Expression (Parent (Def_Id))))
9218 -- Set imported flag to prevent cascaded errors
9220 Set_Is_Imported (Def_Id);
9222 Error_Msg_Sloc := Sloc (Def_Id);
9224 ("no initialization allowed for declaration of& #",
9225 "\imported entities cannot be initialized (RM B.1(24))",
9229 -- If the pragma comes from an aspect specification the
9230 -- Is_Imported flag has already been set.
9232 if not From_Aspect_Specification (N) then
9233 Set_Imported (Def_Id);
9236 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9238 -- Note that we do not set Is_Public here. That's because we
9239 -- only want to set it if there is no address clause, and we
9240 -- don't know that yet, so we delay that processing till
9243 -- pragma Import completes deferred constants
9245 if Ekind (Def_Id) = E_Constant then
9246 Set_Has_Completion (Def_Id);
9249 -- It is not possible to import a constant of an unconstrained
9250 -- array type (e.g. string) because there is no simple way to
9251 -- write a meaningful subtype for it.
9253 if Is_Array_Type (Etype (Def_Id))
9254 and then not Is_Constrained (Etype (Def_Id))
9257 ("imported constant& must have a constrained subtype",
9262 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9264 -- If the name is overloaded, pragma applies to all of the denoted
9265 -- entities in the same declarative part, unless the pragma comes
9266 -- from an aspect specification or was generated by the compiler
9267 -- (such as for pragma Provide_Shift_Operators).
9270 while Present (Hom_Id) loop
9272 Def_Id := Get_Base_Subprogram (Hom_Id);
9274 -- Ignore inherited subprograms because the pragma will apply
9275 -- to the parent operation, which is the one called.
9277 if Is_Overloadable (Def_Id)
9278 and then Present (Alias (Def_Id))
9282 -- If it is not a subprogram, it must be in an outer scope and
9283 -- pragma does not apply.
9285 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9288 -- The pragma does not apply to primitives of interfaces
9290 elsif Is_Dispatching_Operation (Def_Id)
9291 and then Present (Find_Dispatching_Type (Def_Id))
9292 and then Is_Interface (Find_Dispatching_Type (Def_Id))
9296 -- Verify that the homonym is in the same declarative part (not
9297 -- just the same scope). If the pragma comes from an aspect
9298 -- specification we know that it is part of the declaration.
9300 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
9301 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9302 and then not From_Aspect_Specification (N)
9307 -- If the pragma comes from an aspect specification the
9308 -- Is_Imported flag has already been set.
9310 if not From_Aspect_Specification (N) then
9311 Set_Imported (Def_Id);
9314 -- Reject an Import applied to an abstract subprogram
9316 if Is_Subprogram (Def_Id)
9317 and then Is_Abstract_Subprogram (Def_Id)
9319 Error_Msg_Sloc := Sloc (Def_Id);
9321 ("cannot import abstract subprogram& declared#",
9325 -- Special processing for Convention_Intrinsic
9327 if C = Convention_Intrinsic then
9329 -- Link_Name argument not allowed for intrinsic
9333 Set_Is_Intrinsic_Subprogram (Def_Id);
9335 -- If no external name is present, then check that this
9336 -- is a valid intrinsic subprogram. If an external name
9337 -- is present, then this is handled by the back end.
9340 Check_Intrinsic_Subprogram
9341 (Def_Id, Get_Pragma_Arg (Arg2));
9345 -- Verify that the subprogram does not have a completion
9346 -- through a renaming declaration. For other completions the
9347 -- pragma appears as a too late representation.
9350 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
9354 and then Nkind (Decl) = N_Subprogram_Declaration
9355 and then Present (Corresponding_Body (Decl))
9356 and then Nkind (Unit_Declaration_Node
9357 (Corresponding_Body (Decl))) =
9358 N_Subprogram_Renaming_Declaration
9360 Error_Msg_Sloc := Sloc (Def_Id);
9362 ("cannot import&, renaming already provided for "
9363 & "declaration #", N, Def_Id);
9367 -- If the pragma comes from an aspect specification, there
9368 -- must be an Import aspect specified as well. In the rare
9369 -- case where Import is set to False, the suprogram needs to
9370 -- have a local completion.
9373 Imp_Aspect : constant Node_Id :=
9374 Find_Aspect (Def_Id, Aspect_Import);
9378 if Present (Imp_Aspect)
9379 and then Present (Expression (Imp_Aspect))
9381 Expr := Expression (Imp_Aspect);
9382 Analyze_And_Resolve (Expr, Standard_Boolean);
9384 if Is_Entity_Name (Expr)
9385 and then Entity (Expr) = Standard_True
9387 Set_Has_Completion (Def_Id);
9390 -- If there is no expression, the default is True, as for
9391 -- all boolean aspects. Same for the older pragma.
9394 Set_Has_Completion (Def_Id);
9398 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9401 if Is_Compilation_Unit (Hom_Id) then
9403 -- Its possible homonyms are not affected by the pragma.
9404 -- Such homonyms might be present in the context of other
9405 -- units being compiled.
9409 elsif From_Aspect_Specification (N) then
9412 -- If the pragma was created by the compiler, then we don't
9413 -- want it to apply to other homonyms. This kind of case can
9414 -- occur when using pragma Provide_Shift_Operators, which
9415 -- generates implicit shift and rotate operators with Import
9416 -- pragmas that might apply to earlier explicit or implicit
9417 -- declarations marked with Import (for example, coming from
9418 -- an earlier pragma Provide_Shift_Operators for another type),
9419 -- and we don't generally want other homonyms being treated
9420 -- as imported or the pragma flagged as an illegal duplicate.
9422 elsif not Comes_From_Source (N) then
9426 Hom_Id := Homonym (Hom_Id);
9430 -- Import a CPP class
9432 elsif C = Convention_CPP
9433 and then (Is_Record_Type (Def_Id)
9434 or else Ekind (Def_Id) = E_Incomplete_Type)
9436 if Ekind (Def_Id) = E_Incomplete_Type then
9437 if Present (Full_View (Def_Id)) then
9438 Def_Id := Full_View (Def_Id);
9442 ("cannot import 'C'P'P type before full declaration seen",
9443 Get_Pragma_Arg (Arg2));
9445 -- Although we have reported the error we decorate it as
9446 -- CPP_Class to avoid reporting spurious errors
9448 Set_Is_CPP_Class (Def_Id);
9453 -- Types treated as CPP classes must be declared limited (note:
9454 -- this used to be a warning but there is no real benefit to it
9455 -- since we did effectively intend to treat the type as limited
9458 if not Is_Limited_Type (Def_Id) then
9460 ("imported 'C'P'P type must be limited",
9461 Get_Pragma_Arg (Arg2));
9464 if Etype (Def_Id) /= Def_Id
9465 and then not Is_CPP_Class (Root_Type (Def_Id))
9467 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
9470 Set_Is_CPP_Class (Def_Id);
9472 -- Imported CPP types must not have discriminants (because C++
9473 -- classes do not have discriminants).
9475 if Has_Discriminants (Def_Id) then
9477 ("imported 'C'P'P type cannot have discriminants",
9478 First (Discriminant_Specifications
9479 (Declaration_Node (Def_Id))));
9482 -- Check that components of imported CPP types do not have default
9483 -- expressions. For private types this check is performed when the
9484 -- full view is analyzed (see Process_Full_View).
9486 if not Is_Private_Type (Def_Id) then
9487 Check_CPP_Type_Has_No_Defaults (Def_Id);
9490 -- Import a CPP exception
9492 elsif C = Convention_CPP
9493 and then Ekind (Def_Id) = E_Exception
9497 ("'External_'Name arguments is required for 'Cpp exception",
9500 -- As only a string is allowed, Check_Arg_Is_External_Name
9503 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9506 if Present (Arg4) then
9508 ("Link_Name argument not allowed for imported Cpp exception",
9512 -- Do not call Set_Interface_Name as the name of the exception
9513 -- shouldn't be modified (and in particular it shouldn't be
9514 -- the External_Name). For exceptions, the External_Name is the
9515 -- name of the RTTI structure.
9517 -- ??? Emit an error if pragma Import/Export_Exception is present
9519 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
9521 Check_Arg_Count (3);
9522 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9524 Process_Import_Predefined_Type;
9528 ("second argument of pragma% must be object, subprogram "
9529 & "or incomplete type",
9533 -- If this pragma applies to a compilation unit, then the unit, which
9534 -- is a subprogram, does not require (or allow) a body. We also do
9535 -- not need to elaborate imported procedures.
9537 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9539 Cunit : constant Node_Id := Parent (Parent (N));
9541 Set_Body_Required (Cunit, False);
9544 end Process_Import_Or_Interface;
9546 --------------------
9547 -- Process_Inline --
9548 --------------------
9550 procedure Process_Inline (Status : Inline_Status) is
9557 Ghost_Error_Posted : Boolean := False;
9558 -- Flag set when an error concerning the illegal mix of Ghost and
9559 -- non-Ghost subprograms is emitted.
9561 Ghost_Id : Entity_Id := Empty;
9562 -- The entity of the first Ghost subprogram encountered while
9563 -- processing the arguments of the pragma.
9565 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id);
9566 -- Verify the placement of pragma Inline_Always with respect to the
9567 -- initial declaration of subprogram Spec_Id.
9569 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
9570 -- Returns True if it can be determined at this stage that inlining
9571 -- is not possible, for example if the body is available and contains
9572 -- exception handlers, we prevent inlining, since otherwise we can
9573 -- get undefined symbols at link time. This function also emits a
9574 -- warning if the pragma appears too late.
9576 -- ??? is business with link symbols still valid, or does it relate
9577 -- to front end ZCX which is being phased out ???
9579 procedure Make_Inline (Subp : Entity_Id);
9580 -- Subp is the defining unit name of the subprogram declaration. If
9581 -- the pragma is valid, call Set_Inline_Flags on Subp, as well as on
9582 -- the corresponding body, if there is one present.
9584 procedure Set_Inline_Flags (Subp : Entity_Id);
9585 -- Set Has_Pragma_{No_Inline,Inline,Inline_Always} flag on Subp.
9586 -- Also set or clear Is_Inlined flag on Subp depending on Status.
9588 -----------------------------------
9589 -- Check_Inline_Always_Placement --
9590 -----------------------------------
9592 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id) is
9593 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id);
9595 function Compilation_Unit_OK return Boolean;
9596 pragma Inline (Compilation_Unit_OK);
9597 -- Determine whether pragma Inline_Always applies to a compatible
9598 -- compilation unit denoted by Spec_Id.
9600 function Declarative_List_OK return Boolean;
9601 pragma Inline (Declarative_List_OK);
9602 -- Determine whether the initial declaration of subprogram Spec_Id
9603 -- and the pragma appear in compatible declarative lists.
9605 function Subprogram_Body_OK return Boolean;
9606 pragma Inline (Subprogram_Body_OK);
9607 -- Determine whether pragma Inline_Always applies to a compatible
9608 -- subprogram body denoted by Spec_Id.
9610 -------------------------
9611 -- Compilation_Unit_OK --
9612 -------------------------
9614 function Compilation_Unit_OK return Boolean is
9615 Comp_Unit : constant Node_Id := Parent (Spec_Decl);
9618 -- The pragma appears after the initial declaration of a
9619 -- compilation unit.
9621 -- procedure Comp_Unit;
9622 -- pragma Inline_Always (Comp_Unit);
9624 -- Note that for compatibility reasons, the following case is
9627 -- procedure Stand_Alone_Body_Comp_Unit is
9629 -- end Stand_Alone_Body_Comp_Unit;
9630 -- pragma Inline_Always (Stand_Alone_Body_Comp_Unit);
9633 Nkind (Comp_Unit) = N_Compilation_Unit
9634 and then Present (Aux_Decls_Node (Comp_Unit))
9635 and then Is_List_Member (N)
9636 and then List_Containing (N) =
9637 Pragmas_After (Aux_Decls_Node (Comp_Unit));
9638 end Compilation_Unit_OK;
9640 -------------------------
9641 -- Declarative_List_OK --
9642 -------------------------
9644 function Declarative_List_OK return Boolean is
9645 Context : constant Node_Id := Parent (Spec_Decl);
9647 Init_Decl : Node_Id;
9648 Init_List : List_Id;
9649 Prag_List : List_Id;
9652 -- Determine the proper initial declaration. In general this is
9653 -- the declaration node of the subprogram except when the input
9654 -- denotes a generic instantiation.
9656 -- procedure Inst is new Gen;
9657 -- pragma Inline_Always (Inst);
9659 -- In this case the original subprogram is moved inside an
9660 -- anonymous package while pragma Inline_Always remains at the
9661 -- level of the anonymous package. Use the declaration of the
9662 -- package because it reflects the placement of the original
9665 -- package Anon_Pack is
9666 -- procedure Inst is ... end Inst; -- original
9669 -- procedure Inst renames Anon_Pack.Inst;
9670 -- pragma Inline_Always (Inst);
9672 if Is_Generic_Instance (Spec_Id) then
9673 Init_Decl := Parent (Parent (Spec_Decl));
9674 pragma Assert (Nkind (Init_Decl) = N_Package_Declaration);
9676 Init_Decl := Spec_Decl;
9679 if Is_List_Member (Init_Decl) and then Is_List_Member (N) then
9680 Init_List := List_Containing (Init_Decl);
9681 Prag_List := List_Containing (N);
9683 -- The pragma and then initial declaration appear within the
9684 -- same declarative list.
9686 if Init_List = Prag_List then
9689 -- A special case of the above is when both the pragma and
9690 -- the initial declaration appear in different lists of a
9691 -- package spec, protected definition, or a task definition.
9696 -- pragma Inline_Always (Proc);
9699 elsif Nkind_In (Context, N_Package_Specification,
9700 N_Protected_Definition,
9702 and then Init_List = Visible_Declarations (Context)
9703 and then Prag_List = Private_Declarations (Context)
9710 end Declarative_List_OK;
9712 ------------------------
9713 -- Subprogram_Body_OK --
9714 ------------------------
9716 function Subprogram_Body_OK return Boolean is
9717 Body_Decl : Node_Id;
9720 -- The pragma appears within the declarative list of a stand-
9721 -- alone subprogram body.
9723 -- procedure Stand_Alone_Body is
9724 -- pragma Inline_Always (Stand_Alone_Body);
9727 -- end Stand_Alone_Body;
9729 -- The compiler creates a dummy spec in this case, however the
9730 -- pragma remains within the declarative list of the body.
9732 if Nkind (Spec_Decl) = N_Subprogram_Declaration
9733 and then not Comes_From_Source (Spec_Decl)
9734 and then Present (Corresponding_Body (Spec_Decl))
9737 Unit_Declaration_Node (Corresponding_Body (Spec_Decl));
9739 if Present (Declarations (Body_Decl))
9740 and then Is_List_Member (N)
9741 and then List_Containing (N) = Declarations (Body_Decl)
9748 end Subprogram_Body_OK;
9750 -- Start of processing for Check_Inline_Always_Placement
9753 -- This check is relevant only for pragma Inline_Always
9755 if Pname /= Name_Inline_Always then
9758 -- Nothing to do when the pragma is internally generated on the
9759 -- assumption that it is properly placed.
9761 elsif not Comes_From_Source (N) then
9764 -- Nothing to do for internally generated subprograms that act
9765 -- as accidental homonyms of a source subprogram being inlined.
9767 elsif not Comes_From_Source (Spec_Id) then
9770 -- Nothing to do for generic formal subprograms that act as
9771 -- homonyms of another source subprogram being inlined.
9773 elsif Is_Formal_Subprogram (Spec_Id) then
9776 elsif Compilation_Unit_OK
9777 or else Declarative_List_OK
9778 or else Subprogram_Body_OK
9783 -- At this point it is known that the pragma applies to or appears
9784 -- within a completing body, a completing stub, or a subunit.
9786 Error_Msg_Name_1 := Pname;
9787 Error_Msg_Name_2 := Chars (Spec_Id);
9788 Error_Msg_Sloc := Sloc (Spec_Id);
9791 ("pragma % must appear on initial declaration of subprogram "
9792 & "% defined #", N);
9793 end Check_Inline_Always_Placement;
9795 ---------------------------
9796 -- Inlining_Not_Possible --
9797 ---------------------------
9799 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
9800 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
9804 if Nkind (Decl) = N_Subprogram_Body then
9805 Stats := Handled_Statement_Sequence (Decl);
9806 return Present (Exception_Handlers (Stats))
9807 or else Present (At_End_Proc (Stats));
9809 elsif Nkind (Decl) = N_Subprogram_Declaration
9810 and then Present (Corresponding_Body (Decl))
9812 if Analyzed (Corresponding_Body (Decl)) then
9813 Error_Msg_N ("pragma appears too late, ignored??", N);
9816 -- If the subprogram is a renaming as body, the body is just a
9817 -- call to the renamed subprogram, and inlining is trivially
9821 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
9822 N_Subprogram_Renaming_Declaration
9828 Handled_Statement_Sequence
9829 (Unit_Declaration_Node (Corresponding_Body (Decl)));
9832 Present (Exception_Handlers (Stats))
9833 or else Present (At_End_Proc (Stats));
9837 -- If body is not available, assume the best, the check is
9838 -- performed again when compiling enclosing package bodies.
9842 end Inlining_Not_Possible;
9848 procedure Make_Inline (Subp : Entity_Id) is
9849 Kind : constant Entity_Kind := Ekind (Subp);
9850 Inner_Subp : Entity_Id := Subp;
9853 -- Ignore if bad type, avoid cascaded error
9855 if Etype (Subp) = Any_Type then
9859 -- If inlining is not possible, for now do not treat as an error
9861 elsif Status /= Suppressed
9862 and then Front_End_Inlining
9863 and then Inlining_Not_Possible (Subp)
9868 -- Here we have a candidate for inlining, but we must exclude
9869 -- derived operations. Otherwise we would end up trying to inline
9870 -- a phantom declaration, and the result would be to drag in a
9871 -- body which has no direct inlining associated with it. That
9872 -- would not only be inefficient but would also result in the
9873 -- backend doing cross-unit inlining in cases where it was
9874 -- definitely inappropriate to do so.
9876 -- However, a simple Comes_From_Source test is insufficient, since
9877 -- we do want to allow inlining of generic instances which also do
9878 -- not come from source. We also need to recognize specs generated
9879 -- by the front-end for bodies that carry the pragma. Finally,
9880 -- predefined operators do not come from source but are not
9881 -- inlineable either.
9883 elsif Is_Generic_Instance (Subp)
9884 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
9888 elsif not Comes_From_Source (Subp)
9889 and then Scope (Subp) /= Standard_Standard
9895 -- The referenced entity must either be the enclosing entity, or
9896 -- an entity declared within the current open scope.
9898 if Present (Scope (Subp))
9899 and then Scope (Subp) /= Current_Scope
9900 and then Subp /= Current_Scope
9903 ("argument of% must be entity in current scope", Assoc);
9907 -- Processing for procedure, operator or function. If subprogram
9908 -- is aliased (as for an instance) indicate that the renamed
9909 -- entity (if declared in the same unit) is inlined.
9910 -- If this is the anonymous subprogram created for a subprogram
9911 -- instance, the inlining applies to it directly. Otherwise we
9912 -- retrieve it as the alias of the visible subprogram instance.
9914 if Is_Subprogram (Subp) then
9916 -- Ensure that pragma Inline_Always is associated with the
9917 -- initial declaration of the subprogram.
9919 Check_Inline_Always_Placement (Subp);
9921 if Is_Wrapper_Package (Scope (Subp)) then
9924 Inner_Subp := Ultimate_Alias (Inner_Subp);
9927 if In_Same_Source_Unit (Subp, Inner_Subp) then
9928 Set_Inline_Flags (Inner_Subp);
9930 Decl := Parent (Parent (Inner_Subp));
9932 if Nkind (Decl) = N_Subprogram_Declaration
9933 and then Present (Corresponding_Body (Decl))
9935 Set_Inline_Flags (Corresponding_Body (Decl));
9937 elsif Is_Generic_Instance (Subp)
9938 and then Comes_From_Source (Subp)
9940 -- Indicate that the body needs to be created for
9941 -- inlining subsequent calls. The instantiation node
9942 -- follows the declaration of the wrapper package
9943 -- created for it. The subprogram that requires the
9944 -- body is the anonymous one in the wrapper package.
9946 if Scope (Subp) /= Standard_Standard
9948 Need_Subprogram_Instance_Body
9949 (Next (Unit_Declaration_Node
9950 (Scope (Alias (Subp)))), Subp)
9955 -- Inline is a program unit pragma (RM 10.1.5) and cannot
9956 -- appear in a formal part to apply to a formal subprogram.
9957 -- Do not apply check within an instance or a formal package
9958 -- the test will have been applied to the original generic.
9960 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
9961 and then List_Containing (Decl) = List_Containing (N)
9962 and then not In_Instance
9965 ("Inline cannot apply to a formal subprogram", N);
9971 -- For a generic subprogram set flag as well, for use at the point
9972 -- of instantiation, to determine whether the body should be
9975 elsif Is_Generic_Subprogram (Subp) then
9976 Set_Inline_Flags (Subp);
9979 -- Literals are by definition inlined
9981 elsif Kind = E_Enumeration_Literal then
9984 -- Anything else is an error
9988 ("expect subprogram name for pragma%", Assoc);
9992 ----------------------
9993 -- Set_Inline_Flags --
9994 ----------------------
9996 procedure Set_Inline_Flags (Subp : Entity_Id) is
9998 -- First set the Has_Pragma_XXX flags and issue the appropriate
9999 -- errors and warnings for suspicious combinations.
10001 if Prag_Id = Pragma_No_Inline then
10002 if Has_Pragma_Inline_Always (Subp) then
10004 ("Inline_Always and No_Inline are mutually exclusive", N);
10005 elsif Has_Pragma_Inline (Subp) then
10007 ("Inline and No_Inline both specified for& ??",
10008 N, Entity (Subp_Id));
10011 Set_Has_Pragma_No_Inline (Subp);
10013 if Prag_Id = Pragma_Inline_Always then
10014 if Has_Pragma_No_Inline (Subp) then
10016 ("Inline_Always and No_Inline are mutually exclusive",
10020 Set_Has_Pragma_Inline_Always (Subp);
10022 if Has_Pragma_No_Inline (Subp) then
10024 ("Inline and No_Inline both specified for& ??",
10025 N, Entity (Subp_Id));
10029 Set_Has_Pragma_Inline (Subp);
10032 -- Then adjust the Is_Inlined flag. It can never be set if the
10033 -- subprogram is subject to pragma No_Inline.
10037 Set_Is_Inlined (Subp, False);
10043 if not Has_Pragma_No_Inline (Subp) then
10044 Set_Is_Inlined (Subp, True);
10048 -- A pragma that applies to a Ghost entity becomes Ghost for the
10049 -- purposes of legality checks and removal of ignored Ghost code.
10051 Mark_Ghost_Pragma (N, Subp);
10053 -- Capture the entity of the first Ghost subprogram being
10054 -- processed for error detection purposes.
10056 if Is_Ghost_Entity (Subp) then
10057 if No (Ghost_Id) then
10061 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
10062 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
10064 elsif Present (Ghost_Id) and then not Ghost_Error_Posted then
10065 Ghost_Error_Posted := True;
10067 Error_Msg_Name_1 := Pname;
10069 ("pragma % cannot mention ghost and non-ghost subprograms",
10072 Error_Msg_Sloc := Sloc (Ghost_Id);
10073 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
10075 Error_Msg_Sloc := Sloc (Subp);
10076 Error_Msg_NE ("\& # declared as non-ghost", N, Subp);
10078 end Set_Inline_Flags;
10080 -- Start of processing for Process_Inline
10083 -- An inlined subprogram may grant access to its private enclosing
10084 -- context depending on the placement of its body. From elaboration
10085 -- point of view, the flow of execution may enter this private
10086 -- context, and then reach an external unit, thus producing a
10087 -- dependency on that external unit. For such a path to be properly
10088 -- discovered and encoded in the ALI file of the main unit, let the
10089 -- ABE mechanism process the body of the main unit, and encode all
10090 -- relevant invocation constructs and the relations between them.
10092 Mark_Save_Invocation_Graph_Of_Body;
10094 Check_No_Identifiers;
10095 Check_At_Least_N_Arguments (1);
10097 if Status = Enabled then
10098 Inline_Processing_Required := True;
10102 while Present (Assoc) loop
10103 Subp_Id := Get_Pragma_Arg (Assoc);
10107 if Is_Entity_Name (Subp_Id) then
10108 Subp := Entity (Subp_Id);
10110 if Subp = Any_Id then
10112 -- If previous error, avoid cascaded errors
10114 Check_Error_Detected;
10118 Make_Inline (Subp);
10120 -- For the pragma case, climb homonym chain. This is
10121 -- what implements allowing the pragma in the renaming
10122 -- case, with the result applying to the ancestors, and
10123 -- also allows Inline to apply to all previous homonyms.
10125 if not From_Aspect_Specification (N) then
10126 while Present (Homonym (Subp))
10127 and then Scope (Homonym (Subp)) = Current_Scope
10129 Make_Inline (Homonym (Subp));
10130 Subp := Homonym (Subp);
10136 if not Applies then
10137 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
10143 -- If the context is a package declaration, the pragma indicates
10144 -- that inlining will require the presence of the corresponding
10145 -- body. (this may be further refined).
10148 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
10149 N_Package_Declaration
10151 Set_Body_Needed_For_Inlining (Cunit_Entity (Current_Sem_Unit));
10153 end Process_Inline;
10155 ----------------------------
10156 -- Process_Interface_Name --
10157 ----------------------------
10159 procedure Process_Interface_Name
10160 (Subprogram_Def : Entity_Id;
10162 Link_Arg : Node_Id;
10166 Link_Nam : Node_Id;
10167 String_Val : String_Id;
10169 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
10170 -- SN is a string literal node for an interface name. This routine
10171 -- performs some minimal checks that the name is reasonable. In
10172 -- particular that no spaces or other obviously incorrect characters
10173 -- appear. This is only a warning, since any characters are allowed.
10175 ----------------------------------
10176 -- Check_Form_Of_Interface_Name --
10177 ----------------------------------
10179 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
10180 S : constant String_Id := Strval (Expr_Value_S (SN));
10181 SL : constant Nat := String_Length (S);
10186 Error_Msg_N ("interface name cannot be null string", SN);
10189 for J in 1 .. SL loop
10190 C := Get_String_Char (S, J);
10192 -- Look for dubious character and issue unconditional warning.
10193 -- Definitely dubious if not in character range.
10195 if not In_Character_Range (C)
10197 -- Commas, spaces and (back)slashes are dubious
10199 or else Get_Character (C) = ','
10200 or else Get_Character (C) = '\'
10201 or else Get_Character (C) = ' '
10202 or else Get_Character (C) = '/'
10205 ("??interface name contains illegal character",
10206 Sloc (SN) + Source_Ptr (J));
10209 end Check_Form_Of_Interface_Name;
10211 -- Start of processing for Process_Interface_Name
10214 -- If we are looking at a pragma that comes from an aspect then it
10215 -- needs to have its corresponding aspect argument expressions
10216 -- analyzed in addition to the generated pragma so that aspects
10217 -- within generic units get properly resolved.
10219 if Present (Prag) and then From_Aspect_Specification (Prag) then
10221 Asp : constant Node_Id := Corresponding_Aspect (Prag);
10229 -- Obtain all interfacing aspects used to construct the pragma
10231 Get_Interfacing_Aspects
10232 (Asp, Dummy_1, EN, Dummy_2, Dummy_3, LN);
10234 -- Analyze the expression of aspect External_Name
10236 if Present (EN) then
10237 Analyze (Expression (EN));
10240 -- Analyze the expressio of aspect Link_Name
10242 if Present (LN) then
10243 Analyze (Expression (LN));
10248 if No (Link_Arg) then
10249 if No (Ext_Arg) then
10252 elsif Chars (Ext_Arg) = Name_Link_Name then
10254 Link_Nam := Expression (Ext_Arg);
10257 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10258 Ext_Nam := Expression (Ext_Arg);
10263 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10264 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
10265 Ext_Nam := Expression (Ext_Arg);
10266 Link_Nam := Expression (Link_Arg);
10269 -- Check expressions for external name and link name are static
10271 if Present (Ext_Nam) then
10272 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
10273 Check_Form_Of_Interface_Name (Ext_Nam);
10275 -- Verify that external name is not the name of a local entity,
10276 -- which would hide the imported one and could lead to run-time
10277 -- surprises. The problem can only arise for entities declared in
10278 -- a package body (otherwise the external name is fully qualified
10279 -- and will not conflict).
10287 if Prag_Id = Pragma_Import then
10288 Nam := String_To_Name (Strval (Expr_Value_S (Ext_Nam)));
10289 E := Entity_Id (Get_Name_Table_Int (Nam));
10291 if Nam /= Chars (Subprogram_Def)
10292 and then Present (E)
10293 and then not Is_Overloadable (E)
10294 and then Is_Immediately_Visible (E)
10295 and then not Is_Imported (E)
10296 and then Ekind (Scope (E)) = E_Package
10299 while Present (Par) loop
10300 if Nkind (Par) = N_Package_Body then
10301 Error_Msg_Sloc := Sloc (E);
10303 ("imported entity is hidden by & declared#",
10308 Par := Parent (Par);
10315 if Present (Link_Nam) then
10316 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
10317 Check_Form_Of_Interface_Name (Link_Nam);
10320 -- If there is no link name, just set the external name
10322 if No (Link_Nam) then
10323 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
10325 -- For the Link_Name case, the given literal is preceded by an
10326 -- asterisk, which indicates to GCC that the given name should be
10327 -- taken literally, and in particular that no prepending of
10328 -- underlines should occur, even in systems where this is the
10333 Store_String_Char (Get_Char_Code ('*'));
10334 String_Val := Strval (Expr_Value_S (Link_Nam));
10335 Store_String_Chars (String_Val);
10337 Make_String_Literal (Sloc (Link_Nam),
10338 Strval => End_String);
10341 -- Set the interface name. If the entity is a generic instance, use
10342 -- its alias, which is the callable entity.
10344 if Is_Generic_Instance (Subprogram_Def) then
10345 Set_Encoded_Interface_Name
10346 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
10348 Set_Encoded_Interface_Name
10349 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
10352 Check_Duplicated_Export_Name (Link_Nam);
10353 end Process_Interface_Name;
10355 -----------------------------------------
10356 -- Process_Interrupt_Or_Attach_Handler --
10357 -----------------------------------------
10359 procedure Process_Interrupt_Or_Attach_Handler is
10360 Handler : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
10361 Prot_Typ : constant Entity_Id := Scope (Handler);
10364 -- A pragma that applies to a Ghost entity becomes Ghost for the
10365 -- purposes of legality checks and removal of ignored Ghost code.
10367 Mark_Ghost_Pragma (N, Handler);
10368 Set_Is_Interrupt_Handler (Handler);
10370 pragma Assert (Ekind (Prot_Typ) = E_Protected_Type);
10372 Record_Rep_Item (Prot_Typ, N);
10374 -- Chain the pragma on the contract for completeness
10376 Add_Contract_Item (N, Handler);
10377 end Process_Interrupt_Or_Attach_Handler;
10379 --------------------------------------------------
10380 -- Process_Restrictions_Or_Restriction_Warnings --
10381 --------------------------------------------------
10383 -- Note: some of the simple identifier cases were handled in par-prag,
10384 -- but it is harmless (and more straightforward) to simply handle all
10385 -- cases here, even if it means we repeat a bit of work in some cases.
10387 procedure Process_Restrictions_Or_Restriction_Warnings
10391 R_Id : Restriction_Id;
10397 -- Ignore all Restrictions pragmas in CodePeer mode
10399 if CodePeer_Mode then
10403 Check_Ada_83_Warning;
10404 Check_At_Least_N_Arguments (1);
10405 Check_Valid_Configuration_Pragma;
10408 while Present (Arg) loop
10410 Expr := Get_Pragma_Arg (Arg);
10412 -- Case of no restriction identifier present
10414 if Id = No_Name then
10415 if Nkind (Expr) /= N_Identifier then
10417 ("invalid form for restriction", Arg);
10422 (Process_Restriction_Synonyms (Expr));
10424 if R_Id not in All_Boolean_Restrictions then
10425 Error_Msg_Name_1 := Pname;
10427 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
10429 -- Check for possible misspelling
10431 for J in Restriction_Id loop
10433 Rnm : constant String := Restriction_Id'Image (J);
10436 Name_Buffer (1 .. Rnm'Length) := Rnm;
10437 Name_Len := Rnm'Length;
10438 Set_Casing (All_Lower_Case);
10440 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
10443 (Source_Index (Current_Sem_Unit)));
10444 Error_Msg_String (1 .. Rnm'Length) :=
10445 Name_Buffer (1 .. Name_Len);
10446 Error_Msg_Strlen := Rnm'Length;
10447 Error_Msg_N -- CODEFIX
10448 ("\possible misspelling of ""~""",
10449 Get_Pragma_Arg (Arg));
10458 if Implementation_Restriction (R_Id) then
10459 Check_Restriction (No_Implementation_Restrictions, Arg);
10462 -- Special processing for No_Elaboration_Code restriction
10464 if R_Id = No_Elaboration_Code then
10466 -- Restriction is only recognized within a configuration
10467 -- pragma file, or within a unit of the main extended
10468 -- program. Note: the test for Main_Unit is needed to
10469 -- properly include the case of configuration pragma files.
10471 if not (Current_Sem_Unit = Main_Unit
10472 or else In_Extended_Main_Source_Unit (N))
10476 -- Don't allow in a subunit unless already specified in
10479 elsif Nkind (Parent (N)) = N_Compilation_Unit
10480 and then Nkind (Unit (Parent (N))) = N_Subunit
10481 and then not Restriction_Active (No_Elaboration_Code)
10484 ("invalid specification of ""No_Elaboration_Code""",
10487 ("\restriction cannot be specified in a subunit", N);
10489 ("\unless also specified in body or spec", N);
10492 -- If we accept a No_Elaboration_Code restriction, then it
10493 -- needs to be added to the configuration restriction set so
10494 -- that we get proper application to other units in the main
10495 -- extended source as required.
10498 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
10502 -- If this is a warning, then set the warning unless we already
10503 -- have a real restriction active (we never want a warning to
10504 -- override a real restriction).
10507 if not Restriction_Active (R_Id) then
10508 Set_Restriction (R_Id, N);
10509 Restriction_Warnings (R_Id) := True;
10512 -- If real restriction case, then set it and make sure that the
10513 -- restriction warning flag is off, since a real restriction
10514 -- always overrides a warning.
10517 Set_Restriction (R_Id, N);
10518 Restriction_Warnings (R_Id) := False;
10521 -- Check for obsolescent restrictions in Ada 2005 mode
10524 and then Ada_Version >= Ada_2005
10525 and then (R_Id = No_Asynchronous_Control
10527 R_Id = No_Unchecked_Deallocation
10529 R_Id = No_Unchecked_Conversion)
10531 Check_Restriction (No_Obsolescent_Features, N);
10534 -- A very special case that must be processed here: pragma
10535 -- Restrictions (No_Exceptions) turns off all run-time
10536 -- checking. This is a bit dubious in terms of the formal
10537 -- language definition, but it is what is intended by RM
10538 -- H.4(12). Restriction_Warnings never affects generated code
10539 -- so this is done only in the real restriction case.
10541 -- Atomic_Synchronization is not a real check, so it is not
10542 -- affected by this processing).
10544 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
10545 -- run-time checks in CodePeer and GNATprove modes: we want to
10546 -- generate checks for analysis purposes, as set respectively
10547 -- by -gnatC and -gnatd.F
10550 and then not (CodePeer_Mode or GNATprove_Mode)
10551 and then R_Id = No_Exceptions
10553 for J in Scope_Suppress.Suppress'Range loop
10554 if J /= Atomic_Synchronization then
10555 Scope_Suppress.Suppress (J) := True;
10560 -- Case of No_Dependence => unit-name. Note that the parser
10561 -- already made the necessary entry in the No_Dependence table.
10563 elsif Id = Name_No_Dependence then
10564 if not OK_No_Dependence_Unit_Name (Expr) then
10568 -- Case of No_Specification_Of_Aspect => aspect-identifier
10570 elsif Id = Name_No_Specification_Of_Aspect then
10575 if Nkind (Expr) /= N_Identifier then
10578 A_Id := Get_Aspect_Id (Chars (Expr));
10581 if A_Id = No_Aspect then
10582 Error_Pragma_Arg ("invalid restriction name", Arg);
10584 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
10588 -- Case of No_Use_Of_Attribute => attribute-identifier
10590 elsif Id = Name_No_Use_Of_Attribute then
10591 if Nkind (Expr) /= N_Identifier
10592 or else not Is_Attribute_Name (Chars (Expr))
10594 Error_Msg_N ("unknown attribute name??", Expr);
10597 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
10600 -- Case of No_Use_Of_Entity => fully-qualified-name
10602 elsif Id = Name_No_Use_Of_Entity then
10604 -- Restriction is only recognized within a configuration
10605 -- pragma file, or within a unit of the main extended
10606 -- program. Note: the test for Main_Unit is needed to
10607 -- properly include the case of configuration pragma files.
10609 if Current_Sem_Unit = Main_Unit
10610 or else In_Extended_Main_Source_Unit (N)
10612 if not OK_No_Dependence_Unit_Name (Expr) then
10613 Error_Msg_N ("wrong form for entity name", Expr);
10615 Set_Restriction_No_Use_Of_Entity
10616 (Expr, Warn, No_Profile);
10620 -- Case of No_Use_Of_Pragma => pragma-identifier
10622 elsif Id = Name_No_Use_Of_Pragma then
10623 if Nkind (Expr) /= N_Identifier
10624 or else not Is_Pragma_Name (Chars (Expr))
10626 Error_Msg_N ("unknown pragma name??", Expr);
10628 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
10631 -- All other cases of restriction identifier present
10634 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
10635 Analyze_And_Resolve (Expr, Any_Integer);
10637 if R_Id not in All_Parameter_Restrictions then
10639 ("invalid restriction parameter identifier", Arg);
10641 elsif not Is_OK_Static_Expression (Expr) then
10642 Flag_Non_Static_Expr
10643 ("value must be static expression!", Expr);
10646 elsif not Is_Integer_Type (Etype (Expr))
10647 or else Expr_Value (Expr) < 0
10650 ("value must be non-negative integer", Arg);
10653 -- Restriction pragma is active
10655 Val := Expr_Value (Expr);
10657 if not UI_Is_In_Int_Range (Val) then
10659 ("pragma ignored, value too large??", Arg);
10662 -- Warning case. If the real restriction is active, then we
10663 -- ignore the request, since warning never overrides a real
10664 -- restriction. Otherwise we set the proper warning. Note that
10665 -- this circuit sets the warning again if it is already set,
10666 -- which is what we want, since the constant may have changed.
10669 if not Restriction_Active (R_Id) then
10671 (R_Id, N, Integer (UI_To_Int (Val)));
10672 Restriction_Warnings (R_Id) := True;
10675 -- Real restriction case, set restriction and make sure warning
10676 -- flag is off since real restriction always overrides warning.
10679 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
10680 Restriction_Warnings (R_Id) := False;
10686 end Process_Restrictions_Or_Restriction_Warnings;
10688 ---------------------------------
10689 -- Process_Suppress_Unsuppress --
10690 ---------------------------------
10692 -- Note: this procedure makes entries in the check suppress data
10693 -- structures managed by Sem. See spec of package Sem for full
10694 -- details on how we handle recording of check suppression.
10696 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
10701 In_Package_Spec : constant Boolean :=
10702 Is_Package_Or_Generic_Package (Current_Scope)
10703 and then not In_Package_Body (Current_Scope);
10705 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
10706 -- Used to suppress a single check on the given entity
10708 --------------------------------
10709 -- Suppress_Unsuppress_Echeck --
10710 --------------------------------
10712 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
10714 -- Check for error of trying to set atomic synchronization for
10715 -- a non-atomic variable.
10717 if C = Atomic_Synchronization
10718 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
10721 ("pragma & requires atomic type or variable",
10722 Pragma_Identifier (Original_Node (N)));
10725 Set_Checks_May_Be_Suppressed (E);
10727 if In_Package_Spec then
10728 Push_Global_Suppress_Stack_Entry
10731 Suppress => Suppress_Case);
10733 Push_Local_Suppress_Stack_Entry
10736 Suppress => Suppress_Case);
10739 -- If this is a first subtype, and the base type is distinct,
10740 -- then also set the suppress flags on the base type.
10742 if Is_First_Subtype (E) and then Etype (E) /= E then
10743 Suppress_Unsuppress_Echeck (Etype (E), C);
10745 end Suppress_Unsuppress_Echeck;
10747 -- Start of processing for Process_Suppress_Unsuppress
10750 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
10751 -- on user code: we want to generate checks for analysis purposes, as
10752 -- set respectively by -gnatC and -gnatd.F
10754 if Comes_From_Source (N)
10755 and then (CodePeer_Mode or GNATprove_Mode)
10760 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
10761 -- declarative part or a package spec (RM 11.5(5)).
10763 if not Is_Configuration_Pragma then
10764 Check_Is_In_Decl_Part_Or_Package_Spec;
10767 Check_At_Least_N_Arguments (1);
10768 Check_At_Most_N_Arguments (2);
10769 Check_No_Identifier (Arg1);
10770 Check_Arg_Is_Identifier (Arg1);
10772 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
10774 if C = No_Check_Id then
10776 ("argument of pragma% is not valid check name", Arg1);
10779 -- Warn that suppress of Elaboration_Check has no effect in SPARK
10781 if C = Elaboration_Check and then SPARK_Mode = On then
10783 ("Suppress of Elaboration_Check ignored in SPARK??",
10784 "\elaboration checking rules are statically enforced "
10785 & "(SPARK RM 7.7)", Arg1);
10788 -- One-argument case
10790 if Arg_Count = 1 then
10792 -- Make an entry in the local scope suppress table. This is the
10793 -- table that directly shows the current value of the scope
10794 -- suppress check for any check id value.
10796 if C = All_Checks then
10798 -- For All_Checks, we set all specific predefined checks with
10799 -- the exception of Elaboration_Check, which is handled
10800 -- specially because of not wanting All_Checks to have the
10801 -- effect of deactivating static elaboration order processing.
10802 -- Atomic_Synchronization is also not affected, since this is
10803 -- not a real check.
10805 for J in Scope_Suppress.Suppress'Range loop
10806 if J /= Elaboration_Check
10808 J /= Atomic_Synchronization
10810 Scope_Suppress.Suppress (J) := Suppress_Case;
10814 -- If not All_Checks, and predefined check, then set appropriate
10815 -- scope entry. Note that we will set Elaboration_Check if this
10816 -- is explicitly specified. Atomic_Synchronization is allowed
10817 -- only if internally generated and entity is atomic.
10819 elsif C in Predefined_Check_Id
10820 and then (not Comes_From_Source (N)
10821 or else C /= Atomic_Synchronization)
10823 Scope_Suppress.Suppress (C) := Suppress_Case;
10826 -- Also make an entry in the Local_Entity_Suppress table
10828 Push_Local_Suppress_Stack_Entry
10831 Suppress => Suppress_Case);
10833 -- Case of two arguments present, where the check is suppressed for
10834 -- a specified entity (given as the second argument of the pragma)
10837 -- This is obsolescent in Ada 2005 mode
10839 if Ada_Version >= Ada_2005 then
10840 Check_Restriction (No_Obsolescent_Features, Arg2);
10843 Check_Optional_Identifier (Arg2, Name_On);
10844 E_Id := Get_Pragma_Arg (Arg2);
10847 if not Is_Entity_Name (E_Id) then
10849 ("second argument of pragma% must be entity name", Arg2);
10852 E := Entity (E_Id);
10858 -- A pragma that applies to a Ghost entity becomes Ghost for the
10859 -- purposes of legality checks and removal of ignored Ghost code.
10861 Mark_Ghost_Pragma (N, E);
10863 -- Enforce RM 11.5(7) which requires that for a pragma that
10864 -- appears within a package spec, the named entity must be
10865 -- within the package spec. We allow the package name itself
10866 -- to be mentioned since that makes sense, although it is not
10867 -- strictly allowed by 11.5(7).
10870 and then E /= Current_Scope
10871 and then Scope (E) /= Current_Scope
10874 ("entity in pragma% is not in package spec (RM 11.5(7))",
10878 -- Loop through homonyms. As noted below, in the case of a package
10879 -- spec, only homonyms within the package spec are considered.
10882 Suppress_Unsuppress_Echeck (E, C);
10884 if Is_Generic_Instance (E)
10885 and then Is_Subprogram (E)
10886 and then Present (Alias (E))
10888 Suppress_Unsuppress_Echeck (Alias (E), C);
10891 -- Move to next homonym if not aspect spec case
10893 exit when From_Aspect_Specification (N);
10897 -- If we are within a package specification, the pragma only
10898 -- applies to homonyms in the same scope.
10900 exit when In_Package_Spec
10901 and then Scope (E) /= Current_Scope;
10904 end Process_Suppress_Unsuppress;
10906 -------------------------------
10907 -- Record_Independence_Check --
10908 -------------------------------
10910 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is
10911 pragma Unreferenced (N, E);
10913 -- For GCC back ends the validation is done a priori
10914 -- ??? This code is dead, might be useful in the future
10916 -- if not AAMP_On_Target then
10920 -- Independence_Checks.Append ((N, E));
10923 end Record_Independence_Check;
10929 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
10931 if Is_Imported (E) then
10933 ("cannot export entity& that was previously imported", Arg);
10935 elsif Present (Address_Clause (E))
10936 and then not Relaxed_RM_Semantics
10939 ("cannot export entity& that has an address clause", Arg);
10942 Set_Is_Exported (E);
10944 -- Generate a reference for entity explicitly, because the
10945 -- identifier may be overloaded and name resolution will not
10948 Generate_Reference (E, Arg);
10950 -- Deal with exporting non-library level entity
10952 if not Is_Library_Level_Entity (E) then
10954 -- Not allowed at all for subprograms
10956 if Is_Subprogram (E) then
10957 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
10959 -- Otherwise set public and statically allocated
10963 Set_Is_Statically_Allocated (E);
10965 -- Warn if the corresponding W flag is set
10967 if Warn_On_Export_Import
10969 -- Only do this for something that was in the source. Not
10970 -- clear if this can be False now (there used for sure to be
10971 -- cases on some systems where it was False), but anyway the
10972 -- test is harmless if not needed, so it is retained.
10974 and then Comes_From_Source (Arg)
10977 ("?x?& has been made static as a result of Export",
10980 ("\?x?this usage is non-standard and non-portable",
10986 if Warn_On_Export_Import and then Is_Type (E) then
10987 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
10990 if Warn_On_Export_Import and Inside_A_Generic then
10992 ("all instances of& will have the same external name?x?",
10997 ----------------------------------------------
10998 -- Set_Extended_Import_Export_External_Name --
10999 ----------------------------------------------
11001 procedure Set_Extended_Import_Export_External_Name
11002 (Internal_Ent : Entity_Id;
11003 Arg_External : Node_Id)
11005 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
11006 New_Name : Node_Id;
11009 if No (Arg_External) then
11013 Check_Arg_Is_External_Name (Arg_External);
11015 if Nkind (Arg_External) = N_String_Literal then
11016 if String_Length (Strval (Arg_External)) = 0 then
11019 New_Name := Adjust_External_Name_Case (Arg_External);
11022 elsif Nkind (Arg_External) = N_Identifier then
11023 New_Name := Get_Default_External_Name (Arg_External);
11025 -- Check_Arg_Is_External_Name should let through only identifiers and
11026 -- string literals or static string expressions (which are folded to
11027 -- string literals).
11030 raise Program_Error;
11033 -- If we already have an external name set (by a prior normal Import
11034 -- or Export pragma), then the external names must match
11036 if Present (Interface_Name (Internal_Ent)) then
11038 -- Ignore mismatching names in CodePeer mode, to support some
11039 -- old compilers which would export the same procedure under
11040 -- different names, e.g:
11042 -- pragma Export_Procedure (P, "a");
11043 -- pragma Export_Procedure (P, "b");
11045 if CodePeer_Mode then
11049 Check_Matching_Internal_Names : declare
11050 S1 : constant String_Id := Strval (Old_Name);
11051 S2 : constant String_Id := Strval (New_Name);
11053 procedure Mismatch;
11054 pragma No_Return (Mismatch);
11055 -- Called if names do not match
11061 procedure Mismatch is
11063 Error_Msg_Sloc := Sloc (Old_Name);
11065 ("external name does not match that given #",
11069 -- Start of processing for Check_Matching_Internal_Names
11072 if String_Length (S1) /= String_Length (S2) then
11076 for J in 1 .. String_Length (S1) loop
11077 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
11082 end Check_Matching_Internal_Names;
11084 -- Otherwise set the given name
11087 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
11088 Check_Duplicated_Export_Name (New_Name);
11090 end Set_Extended_Import_Export_External_Name;
11096 procedure Set_Imported (E : Entity_Id) is
11098 -- Error message if already imported or exported
11100 if Is_Exported (E) or else Is_Imported (E) then
11102 -- Error if being set Exported twice
11104 if Is_Exported (E) then
11105 Error_Msg_NE ("entity& was previously exported", N, E);
11107 -- Ignore error in CodePeer mode where we treat all imported
11108 -- subprograms as unknown.
11110 elsif CodePeer_Mode then
11113 -- OK if Import/Interface case
11115 elsif Import_Interface_Present (N) then
11118 -- Error if being set Imported twice
11121 Error_Msg_NE ("entity& was previously imported", N, E);
11124 Error_Msg_Name_1 := Pname;
11126 ("\(pragma% applies to all previous entities)", N);
11128 Error_Msg_Sloc := Sloc (E);
11129 Error_Msg_NE ("\import not allowed for& declared#", N, E);
11131 -- Here if not previously imported or exported, OK to import
11134 Set_Is_Imported (E);
11136 -- For subprogram, set Import_Pragma field
11138 if Is_Subprogram (E) then
11139 Set_Import_Pragma (E, N);
11142 -- If the entity is an object that is not at the library level,
11143 -- then it is statically allocated. We do not worry about objects
11144 -- with address clauses in this context since they are not really
11145 -- imported in the linker sense.
11148 and then not Is_Library_Level_Entity (E)
11149 and then No (Address_Clause (E))
11151 Set_Is_Statically_Allocated (E);
11158 -------------------------
11159 -- Set_Mechanism_Value --
11160 -------------------------
11162 -- Note: the mechanism name has not been analyzed (and cannot indeed be
11163 -- analyzed, since it is semantic nonsense), so we get it in the exact
11164 -- form created by the parser.
11166 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
11167 procedure Bad_Mechanism;
11168 pragma No_Return (Bad_Mechanism);
11169 -- Signal bad mechanism name
11171 -------------------
11172 -- Bad_Mechanism --
11173 -------------------
11175 procedure Bad_Mechanism is
11177 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
11180 -- Start of processing for Set_Mechanism_Value
11183 if Mechanism (Ent) /= Default_Mechanism then
11185 ("mechanism for & has already been set", Mech_Name, Ent);
11188 -- MECHANISM_NAME ::= value | reference
11190 if Nkind (Mech_Name) = N_Identifier then
11191 if Chars (Mech_Name) = Name_Value then
11192 Set_Mechanism (Ent, By_Copy);
11195 elsif Chars (Mech_Name) = Name_Reference then
11196 Set_Mechanism (Ent, By_Reference);
11199 elsif Chars (Mech_Name) = Name_Copy then
11201 ("bad mechanism name, Value assumed", Mech_Name);
11210 end Set_Mechanism_Value;
11212 --------------------------
11213 -- Set_Rational_Profile --
11214 --------------------------
11216 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
11217 -- extension to the semantics of renaming declarations.
11219 procedure Set_Rational_Profile is
11221 Implicit_Packing := True;
11222 Overriding_Renamings := True;
11223 Use_VADS_Size := True;
11224 end Set_Rational_Profile;
11226 ---------------------------
11227 -- Set_Ravenscar_Profile --
11228 ---------------------------
11230 -- The tasks to be done here are
11232 -- Set required policies
11234 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11235 -- (For Ravenscar and GNAT_Extended_Ravenscar profiles)
11236 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11237 -- (For GNAT_Ravenscar_EDF profile)
11238 -- pragma Locking_Policy (Ceiling_Locking)
11240 -- Set Detect_Blocking mode
11242 -- Set required restrictions (see System.Rident for detailed list)
11244 -- Set the No_Dependence rules
11245 -- No_Dependence => Ada.Asynchronous_Task_Control
11246 -- No_Dependence => Ada.Calendar
11247 -- No_Dependence => Ada.Execution_Time.Group_Budget
11248 -- No_Dependence => Ada.Execution_Time.Timers
11249 -- No_Dependence => Ada.Task_Attributes
11250 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11252 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id) is
11253 procedure Set_Error_Msg_To_Profile_Name;
11254 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
11257 -----------------------------------
11258 -- Set_Error_Msg_To_Profile_Name --
11259 -----------------------------------
11261 procedure Set_Error_Msg_To_Profile_Name is
11262 Prof_Nam : constant Node_Id :=
11264 (First (Pragma_Argument_Associations (N)));
11267 Get_Name_String (Chars (Prof_Nam));
11268 Adjust_Name_Case (Global_Name_Buffer, Sloc (Prof_Nam));
11269 Error_Msg_Strlen := Name_Len;
11270 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
11271 end Set_Error_Msg_To_Profile_Name;
11280 Profile_Dispatching_Policy : Character;
11282 -- Start of processing for Set_Ravenscar_Profile
11285 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11287 if Profile = GNAT_Ravenscar_EDF then
11288 Profile_Dispatching_Policy := 'E';
11290 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11293 Profile_Dispatching_Policy := 'F';
11296 if Task_Dispatching_Policy /= ' '
11297 and then Task_Dispatching_Policy /= Profile_Dispatching_Policy
11299 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11300 Set_Error_Msg_To_Profile_Name;
11301 Error_Pragma ("Profile (~) incompatible with policy#");
11303 -- Set the FIFO_Within_Priorities policy, but always preserve
11304 -- System_Location since we like the error message with the run time
11308 Task_Dispatching_Policy := Profile_Dispatching_Policy;
11310 if Task_Dispatching_Policy_Sloc /= System_Location then
11311 Task_Dispatching_Policy_Sloc := Loc;
11315 -- pragma Locking_Policy (Ceiling_Locking)
11317 if Locking_Policy /= ' '
11318 and then Locking_Policy /= 'C'
11320 Error_Msg_Sloc := Locking_Policy_Sloc;
11321 Set_Error_Msg_To_Profile_Name;
11322 Error_Pragma ("Profile (~) incompatible with policy#");
11324 -- Set the Ceiling_Locking policy, but preserve System_Location since
11325 -- we like the error message with the run time name.
11328 Locking_Policy := 'C';
11330 if Locking_Policy_Sloc /= System_Location then
11331 Locking_Policy_Sloc := Loc;
11335 -- pragma Detect_Blocking
11337 Detect_Blocking := True;
11339 -- Set the corresponding restrictions
11341 Set_Profile_Restrictions
11342 (Profile, N, Warn => Treat_Restrictions_As_Warnings);
11344 -- Set the No_Dependence restrictions
11346 -- The following No_Dependence restrictions:
11347 -- No_Dependence => Ada.Asynchronous_Task_Control
11348 -- No_Dependence => Ada.Calendar
11349 -- No_Dependence => Ada.Task_Attributes
11350 -- are already set by previous call to Set_Profile_Restrictions.
11352 -- Set the following restrictions which were added to Ada 2005:
11353 -- No_Dependence => Ada.Execution_Time.Group_Budget
11354 -- No_Dependence => Ada.Execution_Time.Timers
11356 if Ada_Version >= Ada_2005 then
11357 Pref_Id := Make_Identifier (Loc, Name_Find ("ada"));
11358 Sel_Id := Make_Identifier (Loc, Name_Find ("execution_time"));
11361 Make_Selected_Component
11364 Selector_Name => Sel_Id);
11366 Sel_Id := Make_Identifier (Loc, Name_Find ("group_budgets"));
11369 Make_Selected_Component
11372 Selector_Name => Sel_Id);
11374 Set_Restriction_No_Dependence
11376 Warn => Treat_Restrictions_As_Warnings,
11377 Profile => Ravenscar);
11379 Sel_Id := Make_Identifier (Loc, Name_Find ("timers"));
11382 Make_Selected_Component
11385 Selector_Name => Sel_Id);
11387 Set_Restriction_No_Dependence
11389 Warn => Treat_Restrictions_As_Warnings,
11390 Profile => Ravenscar);
11393 -- Set the following restriction which was added to Ada 2012 (see
11395 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11397 if Ada_Version >= Ada_2012 then
11398 Pref_Id := Make_Identifier (Loc, Name_Find ("system"));
11399 Sel_Id := Make_Identifier (Loc, Name_Find ("multiprocessors"));
11402 Make_Selected_Component
11405 Selector_Name => Sel_Id);
11407 Sel_Id := Make_Identifier (Loc, Name_Find ("dispatching_domains"));
11410 Make_Selected_Component
11413 Selector_Name => Sel_Id);
11415 Set_Restriction_No_Dependence
11417 Warn => Treat_Restrictions_As_Warnings,
11418 Profile => Ravenscar);
11420 end Set_Ravenscar_Profile;
11422 -----------------------------------
11423 -- Validate_Acc_Condition_Clause --
11424 -----------------------------------
11426 procedure Validate_Acc_Condition_Clause (Clause : Node_Id) is
11428 Analyze_And_Resolve (Clause);
11430 if not Is_Boolean_Type (Etype (Clause)) then
11431 Error_Pragma ("expected a boolean");
11433 end Validate_Acc_Condition_Clause;
11435 ------------------------------
11436 -- Validate_Acc_Data_Clause --
11437 ------------------------------
11439 procedure Validate_Acc_Data_Clause (Clause : Node_Id) is
11443 Expr := Acc_First (Clause);
11444 while Present (Expr) loop
11445 if Nkind (Expr) /= N_Identifier then
11446 Error_Pragma ("expected an identifer");
11449 Analyze_And_Resolve (Expr);
11451 Expr := Acc_Next (Expr);
11453 end Validate_Acc_Data_Clause;
11455 ----------------------------------
11456 -- Validate_Acc_Int_Expr_Clause --
11457 ----------------------------------
11459 procedure Validate_Acc_Int_Expr_Clause (Clause : Node_Id) is
11461 Analyze_And_Resolve (Clause);
11463 if not Is_Integer_Type (Etype (Clause)) then
11464 Error_Pragma_Arg ("expected an integer", Clause);
11466 end Validate_Acc_Int_Expr_Clause;
11468 ---------------------------------------
11469 -- Validate_Acc_Int_Expr_List_Clause --
11470 ---------------------------------------
11472 procedure Validate_Acc_Int_Expr_List_Clause (Clause : Node_Id) is
11476 Expr := Acc_First (Clause);
11477 while Present (Expr) loop
11478 Analyze_And_Resolve (Expr);
11480 if not Is_Integer_Type (Etype (Expr)) then
11481 Error_Pragma ("expected an integer");
11484 Expr := Acc_Next (Expr);
11486 end Validate_Acc_Int_Expr_List_Clause;
11488 --------------------------------
11489 -- Validate_Acc_Loop_Collapse --
11490 --------------------------------
11492 procedure Validate_Acc_Loop_Collapse (Clause : Node_Id) is
11494 Par_Loop : Node_Id;
11498 -- Make sure the argument is a positive integer
11500 Analyze_And_Resolve (Clause);
11502 Count := Static_Integer (Clause);
11503 if Count = No_Uint or else Count < 1 then
11504 Error_Pragma_Arg ("expected a positive integer", Clause);
11507 -- Then, make sure we have at least Count-1 tightly-nested loops
11508 -- (i.e. loops with no statements in between).
11510 Par_Loop := Parent (Parent (Parent (Clause)));
11511 Stmt := First (Statements (Par_Loop));
11513 -- Skip first pragmas in the parent loop
11515 while Present (Stmt) and then Nkind (Stmt) = N_Pragma loop
11519 if not Present (Next (Stmt)) then
11520 while Nkind (Stmt) = N_Loop_Statement and Count > 1 loop
11521 Stmt := First (Statements (Stmt));
11522 exit when Present (Next (Stmt));
11524 Count := Count - 1;
11530 ("Collapse argument too high or loops not tightly nested",
11533 end Validate_Acc_Loop_Collapse;
11535 ----------------------------
11536 -- Validate_Acc_Loop_Gang --
11537 ----------------------------
11539 procedure Validate_Acc_Loop_Gang (Clause : Node_Id) is
11541 Error_Pragma_Arg ("Loop_Gang not implemented", Clause);
11542 end Validate_Acc_Loop_Gang;
11544 ------------------------------
11545 -- Validate_Acc_Loop_Vector --
11546 ------------------------------
11548 procedure Validate_Acc_Loop_Vector (Clause : Node_Id) is
11550 Error_Pragma_Arg ("Loop_Vector not implemented", Clause);
11551 end Validate_Acc_Loop_Vector;
11553 -------------------------------
11554 -- Validate_Acc_Loop_Worker --
11555 -------------------------------
11557 procedure Validate_Acc_Loop_Worker (Clause : Node_Id) is
11559 Error_Pragma_Arg ("Loop_Worker not implemented", Clause);
11560 end Validate_Acc_Loop_Worker;
11562 ---------------------------------
11563 -- Validate_Acc_Name_Reduction --
11564 ---------------------------------
11566 procedure Validate_Acc_Name_Reduction (Clause : Node_Id) is
11568 -- ??? On top of the following operations, the OpenAcc spec adds the
11569 -- "bitwise and", "bitwise or" and modulo for C and ".eqv" and
11570 -- ".neqv" for Fortran. Can we, should we and how do we support them
11573 type Reduction_Op is (Add_Op, Mul_Op, Max_Op, Min_Op, And_Op, Or_Op);
11575 function To_Reduction_Op (Op : String) return Reduction_Op;
11576 -- Convert operator Op described by a String into its corresponding
11577 -- enumeration value.
11579 ---------------------
11580 -- To_Reduction_Op --
11581 ---------------------
11583 function To_Reduction_Op (Op : String) return Reduction_Op is
11588 elsif Op = "*" then
11591 elsif Op = "max" then
11594 elsif Op = "min" then
11597 elsif Op = "and" then
11600 elsif Op = "or" then
11604 Error_Pragma ("unsuported reduction operation");
11606 end To_Reduction_Op;
11610 Seen : constant Elist_Id := New_Elmt_List;
11613 Reduc_Op : Node_Id;
11614 Reduc_Var : Node_Id;
11616 -- Start of processing for Validate_Acc_Name_Reduction
11619 -- Reduction operations appear in the following form:
11620 -- ("+" => (a, b), "*" => c)
11622 Expr := First (Component_Associations (Clause));
11623 while Present (Expr) loop
11624 Reduc_Op := First (Choices (Expr));
11625 String_To_Name_Buffer (Strval (Reduc_Op));
11627 case To_Reduction_Op (Name_Buffer (1 .. Name_Len)) is
11633 Reduc_Var := Acc_First (Expression (Expr));
11634 while Present (Reduc_Var) loop
11635 Analyze_And_Resolve (Reduc_Var);
11637 if Contains (Seen, Entity (Reduc_Var)) then
11638 Error_Pragma ("variable used in multiple reductions");
11641 if Nkind (Reduc_Var) /= N_Identifier
11642 or not Is_Numeric_Type (Etype (Reduc_Var))
11645 ("expected an identifier for a Numeric");
11648 Append_Elmt (Entity (Reduc_Var), Seen);
11651 Reduc_Var := Acc_Next (Reduc_Var);
11657 Reduc_Var := Acc_First (Expression (Expr));
11658 while Present (Reduc_Var) loop
11659 Analyze_And_Resolve (Reduc_Var);
11661 if Contains (Seen, Entity (Reduc_Var)) then
11662 Error_Pragma ("variable used in multiple reductions");
11665 if Nkind (Reduc_Var) /= N_Identifier
11666 or not Is_Boolean_Type (Etype (Reduc_Var))
11669 ("expected a variable of type boolean");
11672 Append_Elmt (Entity (Reduc_Var), Seen);
11675 Reduc_Var := Acc_Next (Reduc_Var);
11681 end Validate_Acc_Name_Reduction;
11683 -----------------------------------
11684 -- Validate_Acc_Size_Expressions --
11685 -----------------------------------
11687 procedure Validate_Acc_Size_Expressions (Clause : Node_Id) is
11688 function Validate_Size_Expr (Expr : Node_Id) return Boolean;
11689 -- A size expr is either an integer expression or "*"
11691 ------------------------
11692 -- Validate_Size_Expr --
11693 ------------------------
11695 function Validate_Size_Expr (Expr : Node_Id) return Boolean is
11697 if Nkind (Expr) = N_Operator_Symbol then
11698 return Get_String_Char (Strval (Expr), 1) = Get_Char_Code ('*');
11701 Analyze_And_Resolve (Expr);
11703 return Is_Integer_Type (Etype (Expr));
11704 end Validate_Size_Expr;
11710 -- Start of processing for Validate_Acc_Size_Expressions
11713 Expr := Acc_First (Clause);
11714 while Present (Expr) loop
11715 if not Validate_Size_Expr (Expr) then
11717 ("Size expressions should be either integers or '*'");
11720 Expr := Acc_Next (Expr);
11722 end Validate_Acc_Size_Expressions;
11724 -- Start of processing for Analyze_Pragma
11727 -- The following code is a defense against recursion. Not clear that
11728 -- this can happen legitimately, but perhaps some error situations can
11729 -- cause it, and we did see this recursion during testing.
11731 if Analyzed (N) then
11737 Check_Restriction_No_Use_Of_Pragma (N);
11739 -- Ignore pragma if Ignore_Pragma applies. Also ignore pragma
11740 -- Default_Scalar_Storage_Order if the -gnatI switch was given.
11742 if Should_Ignore_Pragma_Sem (N)
11743 or else (Prag_Id = Pragma_Default_Scalar_Storage_Order
11744 and then Ignore_Rep_Clauses)
11749 -- Deal with unrecognized pragma
11751 if not Is_Pragma_Name (Pname) then
11752 if Warn_On_Unrecognized_Pragma then
11753 Error_Msg_Name_1 := Pname;
11754 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
11756 for PN in First_Pragma_Name .. Last_Pragma_Name loop
11757 if Is_Bad_Spelling_Of (Pname, PN) then
11758 Error_Msg_Name_1 := PN;
11759 Error_Msg_N -- CODEFIX
11760 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
11769 -- Here to start processing for recognized pragma
11771 Pname := Original_Aspect_Pragma_Name (N);
11773 -- Capture setting of Opt.Uneval_Old
11775 case Opt.Uneval_Old is
11777 Set_Uneval_Old_Accept (N);
11783 Set_Uneval_Old_Warn (N);
11786 raise Program_Error;
11789 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
11790 -- is already set, indicating that we have already checked the policy
11791 -- at the right point. This happens for example in the case of a pragma
11792 -- that is derived from an Aspect.
11794 if Is_Ignored (N) or else Is_Checked (N) then
11797 -- For a pragma that is a rewriting of another pragma, copy the
11798 -- Is_Checked/Is_Ignored status from the rewritten pragma.
11800 elsif Is_Rewrite_Substitution (N)
11801 and then Nkind (Original_Node (N)) = N_Pragma
11803 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
11804 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
11806 -- Otherwise query the applicable policy at this point
11809 Check_Applicable_Policy (N);
11811 -- If pragma is disabled, rewrite as NULL and skip analysis
11813 if Is_Disabled (N) then
11814 Rewrite (N, Make_Null_Statement (Loc));
11820 -- Preset arguments
11828 if Present (Pragma_Argument_Associations (N)) then
11829 Arg_Count := List_Length (Pragma_Argument_Associations (N));
11830 Arg1 := First (Pragma_Argument_Associations (N));
11832 if Present (Arg1) then
11833 Arg2 := Next (Arg1);
11835 if Present (Arg2) then
11836 Arg3 := Next (Arg2);
11838 if Present (Arg3) then
11839 Arg4 := Next (Arg3);
11845 -- An enumeration type defines the pragmas that are supported by the
11846 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
11847 -- into the corresponding enumeration value for the following case.
11855 -- pragma Abort_Defer;
11857 when Pragma_Abort_Defer =>
11859 Check_Arg_Count (0);
11861 -- The only required semantic processing is to check the
11862 -- placement. This pragma must appear at the start of the
11863 -- statement sequence of a handled sequence of statements.
11865 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
11866 or else N /= First (Statements (Parent (N)))
11871 --------------------
11872 -- Abstract_State --
11873 --------------------
11875 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
11877 -- ABSTRACT_STATE_LIST ::=
11879 -- | STATE_NAME_WITH_OPTIONS
11880 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
11882 -- STATE_NAME_WITH_OPTIONS ::=
11884 -- | (STATE_NAME with OPTION_LIST)
11886 -- OPTION_LIST ::= OPTION {, OPTION}
11890 -- | NAME_VALUE_OPTION
11892 -- SIMPLE_OPTION ::= Ghost | Synchronous
11894 -- NAME_VALUE_OPTION ::=
11895 -- Part_Of => ABSTRACT_STATE
11896 -- | External [=> EXTERNAL_PROPERTY_LIST]
11898 -- EXTERNAL_PROPERTY_LIST ::=
11899 -- EXTERNAL_PROPERTY
11900 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
11902 -- EXTERNAL_PROPERTY ::=
11903 -- Async_Readers [=> boolean_EXPRESSION]
11904 -- | Async_Writers [=> boolean_EXPRESSION]
11905 -- | Effective_Reads [=> boolean_EXPRESSION]
11906 -- | Effective_Writes [=> boolean_EXPRESSION]
11907 -- others => boolean_EXPRESSION
11909 -- STATE_NAME ::= defining_identifier
11911 -- ABSTRACT_STATE ::= name
11913 -- Characteristics:
11915 -- * Analysis - The annotation is fully analyzed immediately upon
11916 -- elaboration as it cannot forward reference entities.
11918 -- * Expansion - None.
11920 -- * Template - The annotation utilizes the generic template of the
11921 -- related package declaration.
11923 -- * Globals - The annotation cannot reference global entities.
11925 -- * Instance - The annotation is instantiated automatically when
11926 -- the related generic package is instantiated.
11928 when Pragma_Abstract_State => Abstract_State : declare
11929 Missing_Parentheses : Boolean := False;
11930 -- Flag set when a state declaration with options is not properly
11933 -- Flags used to verify the consistency of states
11935 Non_Null_Seen : Boolean := False;
11936 Null_Seen : Boolean := False;
11938 procedure Analyze_Abstract_State
11940 Pack_Id : Entity_Id);
11941 -- Verify the legality of a single state declaration. Create and
11942 -- decorate a state abstraction entity and introduce it into the
11943 -- visibility chain. Pack_Id denotes the entity or the related
11944 -- package where pragma Abstract_State appears.
11946 procedure Malformed_State_Error (State : Node_Id);
11947 -- Emit an error concerning the illegal declaration of abstract
11948 -- state State. This routine diagnoses syntax errors that lead to
11949 -- a different parse tree. The error is issued regardless of the
11950 -- SPARK mode in effect.
11952 ----------------------------
11953 -- Analyze_Abstract_State --
11954 ----------------------------
11956 procedure Analyze_Abstract_State
11958 Pack_Id : Entity_Id)
11960 -- Flags used to verify the consistency of options
11962 AR_Seen : Boolean := False;
11963 AW_Seen : Boolean := False;
11964 ER_Seen : Boolean := False;
11965 EW_Seen : Boolean := False;
11966 External_Seen : Boolean := False;
11967 Ghost_Seen : Boolean := False;
11968 Others_Seen : Boolean := False;
11969 Part_Of_Seen : Boolean := False;
11970 Synchronous_Seen : Boolean := False;
11972 -- Flags used to store the static value of all external states'
11975 AR_Val : Boolean := False;
11976 AW_Val : Boolean := False;
11977 ER_Val : Boolean := False;
11978 EW_Val : Boolean := False;
11980 State_Id : Entity_Id := Empty;
11981 -- The entity to be generated for the current state declaration
11983 procedure Analyze_External_Option (Opt : Node_Id);
11984 -- Verify the legality of option External
11986 procedure Analyze_External_Property
11988 Expr : Node_Id := Empty);
11989 -- Verify the legailty of a single external property. Prop
11990 -- denotes the external property. Expr is the expression used
11991 -- to set the property.
11993 procedure Analyze_Part_Of_Option (Opt : Node_Id);
11994 -- Verify the legality of option Part_Of
11996 procedure Check_Duplicate_Option
11998 Status : in out Boolean);
11999 -- Flag Status denotes whether a particular option has been
12000 -- seen while processing a state. This routine verifies that
12001 -- Opt is not a duplicate option and sets the flag Status
12002 -- (SPARK RM 7.1.4(1)).
12004 procedure Check_Duplicate_Property
12006 Status : in out Boolean);
12007 -- Flag Status denotes whether a particular property has been
12008 -- seen while processing option External. This routine verifies
12009 -- that Prop is not a duplicate property and sets flag Status.
12010 -- Opt is not a duplicate property and sets the flag Status.
12011 -- (SPARK RM 7.1.4(2))
12013 procedure Check_Ghost_Synchronous;
12014 -- Ensure that the abstract state is not subject to both Ghost
12015 -- and Synchronous simple options. Emit an error if this is the
12018 procedure Create_Abstract_State
12022 Is_Null : Boolean);
12023 -- Generate an abstract state entity with name Nam and enter it
12024 -- into visibility. Decl is the "declaration" of the state as
12025 -- it appears in pragma Abstract_State. Loc is the location of
12026 -- the related state "declaration". Flag Is_Null should be set
12027 -- when the associated Abstract_State pragma defines a null
12030 -----------------------------
12031 -- Analyze_External_Option --
12032 -----------------------------
12034 procedure Analyze_External_Option (Opt : Node_Id) is
12035 Errors : constant Nat := Serious_Errors_Detected;
12037 Props : Node_Id := Empty;
12040 if Nkind (Opt) = N_Component_Association then
12041 Props := Expression (Opt);
12044 -- External state with properties
12046 if Present (Props) then
12048 -- Multiple properties appear as an aggregate
12050 if Nkind (Props) = N_Aggregate then
12052 -- Simple property form
12054 Prop := First (Expressions (Props));
12055 while Present (Prop) loop
12056 Analyze_External_Property (Prop);
12060 -- Property with expression form
12062 Prop := First (Component_Associations (Props));
12063 while Present (Prop) loop
12064 Analyze_External_Property
12065 (Prop => First (Choices (Prop)),
12066 Expr => Expression (Prop));
12074 Analyze_External_Property (Props);
12077 -- An external state defined without any properties defaults
12078 -- all properties to True.
12087 -- Once all external properties have been processed, verify
12088 -- their mutual interaction. Do not perform the check when
12089 -- at least one of the properties is illegal as this will
12090 -- produce a bogus error.
12092 if Errors = Serious_Errors_Detected then
12093 Check_External_Properties
12094 (State, AR_Val, AW_Val, ER_Val, EW_Val);
12096 end Analyze_External_Option;
12098 -------------------------------
12099 -- Analyze_External_Property --
12100 -------------------------------
12102 procedure Analyze_External_Property
12104 Expr : Node_Id := Empty)
12106 Expr_Val : Boolean;
12109 -- Check the placement of "others" (if available)
12111 if Nkind (Prop) = N_Others_Choice then
12112 if Others_Seen then
12114 ("only one others choice allowed in option External",
12117 Others_Seen := True;
12120 elsif Others_Seen then
12122 ("others must be the last property in option External",
12125 -- The only remaining legal options are the four predefined
12126 -- external properties.
12128 elsif Nkind (Prop) = N_Identifier
12129 and then Nam_In (Chars (Prop), Name_Async_Readers,
12130 Name_Async_Writers,
12131 Name_Effective_Reads,
12132 Name_Effective_Writes)
12136 -- Otherwise the construct is not a valid property
12139 SPARK_Msg_N ("invalid external state property", Prop);
12143 -- Ensure that the expression of the external state property
12144 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
12146 if Present (Expr) then
12147 Analyze_And_Resolve (Expr, Standard_Boolean);
12149 if Is_OK_Static_Expression (Expr) then
12150 Expr_Val := Is_True (Expr_Value (Expr));
12153 ("expression of external state property must be "
12158 -- The lack of expression defaults the property to True
12164 -- Named properties
12166 if Nkind (Prop) = N_Identifier then
12167 if Chars (Prop) = Name_Async_Readers then
12168 Check_Duplicate_Property (Prop, AR_Seen);
12169 AR_Val := Expr_Val;
12171 elsif Chars (Prop) = Name_Async_Writers then
12172 Check_Duplicate_Property (Prop, AW_Seen);
12173 AW_Val := Expr_Val;
12175 elsif Chars (Prop) = Name_Effective_Reads then
12176 Check_Duplicate_Property (Prop, ER_Seen);
12177 ER_Val := Expr_Val;
12180 Check_Duplicate_Property (Prop, EW_Seen);
12181 EW_Val := Expr_Val;
12184 -- The handling of property "others" must take into account
12185 -- all other named properties that have been encountered so
12186 -- far. Only those that have not been seen are affected by
12190 if not AR_Seen then
12191 AR_Val := Expr_Val;
12194 if not AW_Seen then
12195 AW_Val := Expr_Val;
12198 if not ER_Seen then
12199 ER_Val := Expr_Val;
12202 if not EW_Seen then
12203 EW_Val := Expr_Val;
12206 end Analyze_External_Property;
12208 ----------------------------
12209 -- Analyze_Part_Of_Option --
12210 ----------------------------
12212 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
12213 Encap : constant Node_Id := Expression (Opt);
12214 Constits : Elist_Id;
12215 Encap_Id : Entity_Id;
12219 Check_Duplicate_Option (Opt, Part_Of_Seen);
12222 (Indic => First (Choices (Opt)),
12223 Item_Id => State_Id,
12225 Encap_Id => Encap_Id,
12228 -- The Part_Of indicator transforms the abstract state into
12229 -- a constituent of the encapsulating state or single
12230 -- concurrent type.
12233 pragma Assert (Present (Encap_Id));
12234 Constits := Part_Of_Constituents (Encap_Id);
12236 if No (Constits) then
12237 Constits := New_Elmt_List;
12238 Set_Part_Of_Constituents (Encap_Id, Constits);
12241 Append_Elmt (State_Id, Constits);
12242 Set_Encapsulating_State (State_Id, Encap_Id);
12244 end Analyze_Part_Of_Option;
12246 ----------------------------
12247 -- Check_Duplicate_Option --
12248 ----------------------------
12250 procedure Check_Duplicate_Option
12252 Status : in out Boolean)
12256 SPARK_Msg_N ("duplicate state option", Opt);
12260 end Check_Duplicate_Option;
12262 ------------------------------
12263 -- Check_Duplicate_Property --
12264 ------------------------------
12266 procedure Check_Duplicate_Property
12268 Status : in out Boolean)
12272 SPARK_Msg_N ("duplicate external property", Prop);
12276 end Check_Duplicate_Property;
12278 -----------------------------
12279 -- Check_Ghost_Synchronous --
12280 -----------------------------
12282 procedure Check_Ghost_Synchronous is
12284 -- A synchronized abstract state cannot be Ghost and vice
12285 -- versa (SPARK RM 6.9(19)).
12287 if Ghost_Seen and Synchronous_Seen then
12288 SPARK_Msg_N ("synchronized state cannot be ghost", State);
12290 end Check_Ghost_Synchronous;
12292 ---------------------------
12293 -- Create_Abstract_State --
12294 ---------------------------
12296 procedure Create_Abstract_State
12303 -- The abstract state may be semi-declared when the related
12304 -- package was withed through a limited with clause. In that
12305 -- case reuse the entity to fully declare the state.
12307 if Present (Decl) and then Present (Entity (Decl)) then
12308 State_Id := Entity (Decl);
12310 -- Otherwise the elaboration of pragma Abstract_State
12311 -- declares the state.
12314 State_Id := Make_Defining_Identifier (Loc, Nam);
12316 if Present (Decl) then
12317 Set_Entity (Decl, State_Id);
12321 -- Null states never come from source
12323 Set_Comes_From_Source (State_Id, not Is_Null);
12324 Set_Parent (State_Id, State);
12325 Set_Ekind (State_Id, E_Abstract_State);
12326 Set_Etype (State_Id, Standard_Void_Type);
12327 Set_Encapsulating_State (State_Id, Empty);
12329 -- Set the SPARK mode from the current context
12331 Set_SPARK_Pragma (State_Id, SPARK_Mode_Pragma);
12332 Set_SPARK_Pragma_Inherited (State_Id);
12334 -- An abstract state declared within a Ghost region becomes
12335 -- Ghost (SPARK RM 6.9(2)).
12337 if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then
12338 Set_Is_Ghost_Entity (State_Id);
12341 -- Establish a link between the state declaration and the
12342 -- abstract state entity. Note that a null state remains as
12343 -- N_Null and does not carry any linkages.
12345 if not Is_Null then
12346 if Present (Decl) then
12347 Set_Entity (Decl, State_Id);
12348 Set_Etype (Decl, Standard_Void_Type);
12351 -- Every non-null state must be defined, nameable and
12354 Push_Scope (Pack_Id);
12355 Generate_Definition (State_Id);
12356 Enter_Name (State_Id);
12359 end Create_Abstract_State;
12366 -- Start of processing for Analyze_Abstract_State
12369 -- A package with a null abstract state is not allowed to
12370 -- declare additional states.
12374 ("package & has null abstract state", State, Pack_Id);
12376 -- Null states appear as internally generated entities
12378 elsif Nkind (State) = N_Null then
12379 Create_Abstract_State
12380 (Nam => New_Internal_Name ('S'),
12382 Loc => Sloc (State),
12386 -- Catch a case where a null state appears in a list of
12387 -- non-null states.
12389 if Non_Null_Seen then
12391 ("package & has non-null abstract state",
12395 -- Simple state declaration
12397 elsif Nkind (State) = N_Identifier then
12398 Create_Abstract_State
12399 (Nam => Chars (State),
12401 Loc => Sloc (State),
12403 Non_Null_Seen := True;
12405 -- State declaration with various options. This construct
12406 -- appears as an extension aggregate in the tree.
12408 elsif Nkind (State) = N_Extension_Aggregate then
12409 if Nkind (Ancestor_Part (State)) = N_Identifier then
12410 Create_Abstract_State
12411 (Nam => Chars (Ancestor_Part (State)),
12412 Decl => Ancestor_Part (State),
12413 Loc => Sloc (Ancestor_Part (State)),
12415 Non_Null_Seen := True;
12418 ("state name must be an identifier",
12419 Ancestor_Part (State));
12422 -- Options External, Ghost and Synchronous appear as
12425 Opt := First (Expressions (State));
12426 while Present (Opt) loop
12427 if Nkind (Opt) = N_Identifier then
12431 if Chars (Opt) = Name_External then
12432 Check_Duplicate_Option (Opt, External_Seen);
12433 Analyze_External_Option (Opt);
12437 elsif Chars (Opt) = Name_Ghost then
12438 Check_Duplicate_Option (Opt, Ghost_Seen);
12439 Check_Ghost_Synchronous;
12441 if Present (State_Id) then
12442 Set_Is_Ghost_Entity (State_Id);
12447 elsif Chars (Opt) = Name_Synchronous then
12448 Check_Duplicate_Option (Opt, Synchronous_Seen);
12449 Check_Ghost_Synchronous;
12451 -- Option Part_Of without an encapsulating state is
12452 -- illegal (SPARK RM 7.1.4(8)).
12454 elsif Chars (Opt) = Name_Part_Of then
12456 ("indicator Part_Of must denote abstract state, "
12457 & "single protected type or single task type",
12460 -- Do not emit an error message when a previous state
12461 -- declaration with options was not parenthesized as
12462 -- the option is actually another state declaration.
12464 -- with Abstract_State
12465 -- (State_1 with ..., -- missing parentheses
12466 -- (State_2 with ...),
12467 -- State_3) -- ok state declaration
12469 elsif Missing_Parentheses then
12472 -- Otherwise the option is not allowed. Note that it
12473 -- is not possible to distinguish between an option
12474 -- and a state declaration when a previous state with
12475 -- options not properly parentheses.
12477 -- with Abstract_State
12478 -- (State_1 with ..., -- missing parentheses
12479 -- State_2); -- could be an option
12483 ("simple option not allowed in state declaration",
12487 -- Catch a case where missing parentheses around a state
12488 -- declaration with options cause a subsequent state
12489 -- declaration with options to be treated as an option.
12491 -- with Abstract_State
12492 -- (State_1 with ..., -- missing parentheses
12493 -- (State_2 with ...))
12495 elsif Nkind (Opt) = N_Extension_Aggregate then
12496 Missing_Parentheses := True;
12498 ("state declaration must be parenthesized",
12499 Ancestor_Part (State));
12501 -- Otherwise the option is malformed
12504 SPARK_Msg_N ("malformed option", Opt);
12510 -- Options External and Part_Of appear as component
12513 Opt := First (Component_Associations (State));
12514 while Present (Opt) loop
12515 Opt_Nam := First (Choices (Opt));
12517 if Nkind (Opt_Nam) = N_Identifier then
12518 if Chars (Opt_Nam) = Name_External then
12519 Analyze_External_Option (Opt);
12521 elsif Chars (Opt_Nam) = Name_Part_Of then
12522 Analyze_Part_Of_Option (Opt);
12525 SPARK_Msg_N ("invalid state option", Opt);
12528 SPARK_Msg_N ("invalid state option", Opt);
12534 -- Any other attempt to declare a state is illegal
12537 Malformed_State_Error (State);
12541 -- Guard against a junk state. In such cases no entity is
12542 -- generated and the subsequent checks cannot be applied.
12544 if Present (State_Id) then
12546 -- Verify whether the state does not introduce an illegal
12547 -- hidden state within a package subject to a null abstract
12550 Check_No_Hidden_State (State_Id);
12552 -- Check whether the lack of option Part_Of agrees with the
12553 -- placement of the abstract state with respect to the state
12556 if not Part_Of_Seen then
12557 Check_Missing_Part_Of (State_Id);
12560 -- Associate the state with its related package
12562 if No (Abstract_States (Pack_Id)) then
12563 Set_Abstract_States (Pack_Id, New_Elmt_List);
12566 Append_Elmt (State_Id, Abstract_States (Pack_Id));
12568 end Analyze_Abstract_State;
12570 ---------------------------
12571 -- Malformed_State_Error --
12572 ---------------------------
12574 procedure Malformed_State_Error (State : Node_Id) is
12576 Error_Msg_N ("malformed abstract state declaration", State);
12578 -- An abstract state with a simple option is being declared
12579 -- with "=>" rather than the legal "with". The state appears
12580 -- as a component association.
12582 if Nkind (State) = N_Component_Association then
12583 Error_Msg_N ("\use WITH to specify simple option", State);
12585 end Malformed_State_Error;
12589 Pack_Decl : Node_Id;
12590 Pack_Id : Entity_Id;
12594 -- Start of processing for Abstract_State
12598 Check_No_Identifiers;
12599 Check_Arg_Count (1);
12601 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
12603 if not Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
12604 N_Package_Declaration)
12610 Pack_Id := Defining_Entity (Pack_Decl);
12612 -- A pragma that applies to a Ghost entity becomes Ghost for the
12613 -- purposes of legality checks and removal of ignored Ghost code.
12615 Mark_Ghost_Pragma (N, Pack_Id);
12616 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
12618 -- Chain the pragma on the contract for completeness
12620 Add_Contract_Item (N, Pack_Id);
12622 -- The legality checks of pragmas Abstract_State, Initializes, and
12623 -- Initial_Condition are affected by the SPARK mode in effect. In
12624 -- addition, these three pragmas are subject to an inherent order:
12626 -- 1) Abstract_State
12628 -- 3) Initial_Condition
12630 -- Analyze all these pragmas in the order outlined above
12632 Analyze_If_Present (Pragma_SPARK_Mode);
12633 States := Expression (Get_Argument (N, Pack_Id));
12635 -- Multiple non-null abstract states appear as an aggregate
12637 if Nkind (States) = N_Aggregate then
12638 State := First (Expressions (States));
12639 while Present (State) loop
12640 Analyze_Abstract_State (State, Pack_Id);
12644 -- An abstract state with a simple option is being illegaly
12645 -- declared with "=>" rather than "with". In this case the
12646 -- state declaration appears as a component association.
12648 if Present (Component_Associations (States)) then
12649 State := First (Component_Associations (States));
12650 while Present (State) loop
12651 Malformed_State_Error (State);
12656 -- Various forms of a single abstract state. Note that these may
12657 -- include malformed state declarations.
12660 Analyze_Abstract_State (States, Pack_Id);
12663 Analyze_If_Present (Pragma_Initializes);
12664 Analyze_If_Present (Pragma_Initial_Condition);
12665 end Abstract_State;
12671 when Pragma_Acc_Data => Acc_Data : declare
12672 Clause_Names : constant Name_List :=
12685 Clauses : Args_List (Clause_Names'Range);
12688 if not OpenAcc_Enabled then
12694 if Nkind (Parent (N)) /= N_Loop_Statement then
12696 ("Acc_Data pragma should be placed in loop or block "
12700 Gather_Associations (Clause_Names, Clauses);
12702 for Id in Clause_Names'First .. Clause_Names'Last loop
12703 Clause := Clauses (Id);
12705 if Present (Clause) then
12706 case Clause_Names (Id) is
12714 Validate_Acc_Data_Clause (Clause);
12721 Error_Pragma ("unsupported pragma clause");
12724 raise Program_Error;
12729 Set_Is_OpenAcc_Environment (Parent (N));
12736 when Pragma_Acc_Loop => Acc_Loop : declare
12737 Clause_Names : constant Name_List :=
12750 Clauses : Args_List (Clause_Names'Range);
12754 if not OpenAcc_Enabled then
12760 -- Make sure the pragma is in an openacc construct
12762 Check_Loop_Pragma_Placement;
12765 while Present (Par)
12766 and then (Nkind (Par) /= N_Loop_Statement
12767 or else not Is_OpenAcc_Environment (Par))
12769 Par := Parent (Par);
12772 if not Is_OpenAcc_Environment (Par) then
12774 ("Acc_Loop directive must be associated with an OpenAcc "
12775 & "construct region");
12778 Gather_Associations (Clause_Names, Clauses);
12780 for Id in Clause_Names'First .. Clause_Names'Last loop
12781 Clause := Clauses (Id);
12783 if Present (Clause) then
12784 case Clause_Names (Id) is
12791 when Name_Collapse =>
12792 Validate_Acc_Loop_Collapse (Clause);
12795 Validate_Acc_Loop_Gang (Clause);
12797 when Name_Acc_Private =>
12798 Validate_Acc_Data_Clause (Clause);
12800 when Name_Reduction =>
12801 Validate_Acc_Name_Reduction (Clause);
12804 Validate_Acc_Size_Expressions (Clause);
12806 when Name_Vector =>
12807 Validate_Acc_Loop_Vector (Clause);
12809 when Name_Worker =>
12810 Validate_Acc_Loop_Worker (Clause);
12813 raise Program_Error;
12818 Set_Is_OpenAcc_Loop (Parent (N));
12821 ----------------------------------
12822 -- Acc_Parallel and Acc_Kernels --
12823 ----------------------------------
12825 when Pragma_Acc_Parallel
12826 | Pragma_Acc_Kernels
12828 Acc_Kernels_Or_Parallel : declare
12829 Clause_Names : constant Name_List :=
12842 Name_Vector_Length,
12848 Name_First_Private,
12857 Clauses : Args_List (Clause_Names'Range);
12860 if not OpenAcc_Enabled then
12865 Check_Loop_Pragma_Placement;
12867 if Nkind (Parent (N)) /= N_Loop_Statement then
12869 ("pragma should be placed in loop or block statements");
12872 Gather_Associations (Clause_Names, Clauses);
12874 for Id in Clause_Names'First .. Clause_Names'Last loop
12875 Clause := Clauses (Id);
12877 if Present (Clause) then
12878 if Chars (Parent (Clause)) = No_Name then
12879 Error_Pragma ("all arguments should be associations");
12881 case Clause_Names (Id) is
12883 -- Note: According to the OpenAcc Standard v2.6,
12884 -- Async's argument should be optional. Because this
12885 -- complicates parsing the clause, the argument is
12886 -- made mandatory. The standard defines two negative
12887 -- values, acc_async_noval and acc_async_sync. When
12888 -- given acc_async_noval as value, the clause should
12889 -- behave as if no argument was given. According to
12890 -- the standard, acc_async_noval is defined in header
12891 -- files for C and Fortran, thus this value should
12892 -- probably be defined in the OpenAcc Ada library once
12893 -- it is implemented.
12898 | Name_Vector_Length
12900 Validate_Acc_Int_Expr_Clause (Clause);
12902 when Name_Acc_If =>
12903 Validate_Acc_Condition_Clause (Clause);
12905 -- Unsupported by GCC
12910 Error_Pragma ("unsupported clause");
12912 when Name_Acc_Private
12913 | Name_First_Private
12915 if Prag_Id /= Pragma_Acc_Parallel then
12917 ("argument is only available for 'Parallel' "
12920 Validate_Acc_Data_Clause (Clause);
12930 Validate_Acc_Data_Clause (Clause);
12932 when Name_Reduction =>
12933 if Prag_Id /= Pragma_Acc_Parallel then
12935 ("argument is only available for 'Parallel' "
12938 Validate_Acc_Name_Reduction (Clause);
12941 when Name_Default =>
12942 if Chars (Clause) /= Name_None then
12943 Error_Pragma ("expected none");
12946 when Name_Device_Type =>
12947 Error_Pragma ("unsupported pragma clause");
12949 -- Similar to Name_Async, Name_Wait's arguments should
12950 -- be optional. However, this can be simulated using
12951 -- acc_async_noval, hence, we do not bother making the
12952 -- argument optional for now.
12955 Validate_Acc_Int_Expr_List_Clause (Clause);
12958 raise Program_Error;
12964 Set_Is_OpenAcc_Environment (Parent (N));
12965 end Acc_Kernels_Or_Parallel;
12973 -- Note: this pragma also has some specific processing in Par.Prag
12974 -- because we want to set the Ada version mode during parsing.
12976 when Pragma_Ada_83 =>
12978 Check_Arg_Count (0);
12980 -- We really should check unconditionally for proper configuration
12981 -- pragma placement, since we really don't want mixed Ada modes
12982 -- within a single unit, and the GNAT reference manual has always
12983 -- said this was a configuration pragma, but we did not check and
12984 -- are hesitant to add the check now.
12986 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
12987 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
12988 -- or Ada 2012 mode.
12990 if Ada_Version >= Ada_2005 then
12991 Check_Valid_Configuration_Pragma;
12994 -- Now set Ada 83 mode
12996 if Latest_Ada_Only then
12997 Error_Pragma ("??pragma% ignored");
12999 Ada_Version := Ada_83;
13000 Ada_Version_Explicit := Ada_83;
13001 Ada_Version_Pragma := N;
13010 -- Note: this pragma also has some specific processing in Par.Prag
13011 -- because we want to set the Ada 83 version mode during parsing.
13013 when Pragma_Ada_95 =>
13015 Check_Arg_Count (0);
13017 -- We really should check unconditionally for proper configuration
13018 -- pragma placement, since we really don't want mixed Ada modes
13019 -- within a single unit, and the GNAT reference manual has always
13020 -- said this was a configuration pragma, but we did not check and
13021 -- are hesitant to add the check now.
13023 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
13024 -- or Ada 95, so we must check if we are in Ada 2005 mode.
13026 if Ada_Version >= Ada_2005 then
13027 Check_Valid_Configuration_Pragma;
13030 -- Now set Ada 95 mode
13032 if Latest_Ada_Only then
13033 Error_Pragma ("??pragma% ignored");
13035 Ada_Version := Ada_95;
13036 Ada_Version_Explicit := Ada_95;
13037 Ada_Version_Pragma := N;
13040 ---------------------
13041 -- Ada_05/Ada_2005 --
13042 ---------------------
13045 -- pragma Ada_05 (LOCAL_NAME);
13047 -- pragma Ada_2005;
13048 -- pragma Ada_2005 (LOCAL_NAME):
13050 -- Note: these pragmas also have some specific processing in Par.Prag
13051 -- because we want to set the Ada 2005 version mode during parsing.
13053 -- The one argument form is used for managing the transition from
13054 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
13055 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
13056 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
13057 -- mode, a preference rule is established which does not choose
13058 -- such an entity unless it is unambiguously specified. This avoids
13059 -- extra subprograms marked this way from generating ambiguities in
13060 -- otherwise legal pre-Ada_2005 programs. The one argument form is
13061 -- intended for exclusive use in the GNAT run-time library.
13072 if Arg_Count = 1 then
13073 Check_Arg_Is_Local_Name (Arg1);
13074 E_Id := Get_Pragma_Arg (Arg1);
13076 if Etype (E_Id) = Any_Type then
13080 Set_Is_Ada_2005_Only (Entity (E_Id));
13081 Record_Rep_Item (Entity (E_Id), N);
13084 Check_Arg_Count (0);
13086 -- For Ada_2005 we unconditionally enforce the documented
13087 -- configuration pragma placement, since we do not want to
13088 -- tolerate mixed modes in a unit involving Ada 2005. That
13089 -- would cause real difficulties for those cases where there
13090 -- are incompatibilities between Ada 95 and Ada 2005.
13092 Check_Valid_Configuration_Pragma;
13094 -- Now set appropriate Ada mode
13096 if Latest_Ada_Only then
13097 Error_Pragma ("??pragma% ignored");
13099 Ada_Version := Ada_2005;
13100 Ada_Version_Explicit := Ada_2005;
13101 Ada_Version_Pragma := N;
13106 ---------------------
13107 -- Ada_12/Ada_2012 --
13108 ---------------------
13111 -- pragma Ada_12 (LOCAL_NAME);
13113 -- pragma Ada_2012;
13114 -- pragma Ada_2012 (LOCAL_NAME):
13116 -- Note: these pragmas also have some specific processing in Par.Prag
13117 -- because we want to set the Ada 2012 version mode during parsing.
13119 -- The one argument form is used for managing the transition from Ada
13120 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
13121 -- as Ada_2012 only, then referencing the entity in any pre-Ada_2012
13122 -- mode will generate a warning. In addition, in any pre-Ada_2012
13123 -- mode, a preference rule is established which does not choose
13124 -- such an entity unless it is unambiguously specified. This avoids
13125 -- extra subprograms marked this way from generating ambiguities in
13126 -- otherwise legal pre-Ada_2012 programs. The one argument form is
13127 -- intended for exclusive use in the GNAT run-time library.
13138 if Arg_Count = 1 then
13139 Check_Arg_Is_Local_Name (Arg1);
13140 E_Id := Get_Pragma_Arg (Arg1);
13142 if Etype (E_Id) = Any_Type then
13146 Set_Is_Ada_2012_Only (Entity (E_Id));
13147 Record_Rep_Item (Entity (E_Id), N);
13150 Check_Arg_Count (0);
13152 -- For Ada_2012 we unconditionally enforce the documented
13153 -- configuration pragma placement, since we do not want to
13154 -- tolerate mixed modes in a unit involving Ada 2012. That
13155 -- would cause real difficulties for those cases where there
13156 -- are incompatibilities between Ada 95 and Ada 2012. We could
13157 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
13159 Check_Valid_Configuration_Pragma;
13161 -- Now set appropriate Ada mode
13163 Ada_Version := Ada_2012;
13164 Ada_Version_Explicit := Ada_2012;
13165 Ada_Version_Pragma := N;
13173 -- pragma Ada_2020;
13175 -- Note: this pragma also has some specific processing in Par.Prag
13176 -- because we want to set the Ada 2020 version mode during parsing.
13178 when Pragma_Ada_2020 =>
13181 Check_Arg_Count (0);
13183 Check_Valid_Configuration_Pragma;
13185 -- Now set appropriate Ada mode
13187 Ada_Version := Ada_2020;
13188 Ada_Version_Explicit := Ada_2020;
13189 Ada_Version_Pragma := N;
13191 -------------------------------------
13192 -- Aggregate_Individually_Assign --
13193 -------------------------------------
13195 -- pragma Aggregate_Individually_Assign;
13197 when Pragma_Aggregate_Individually_Assign =>
13199 Check_Arg_Count (0);
13200 Check_Valid_Configuration_Pragma;
13201 Aggregate_Individually_Assign := True;
13203 ----------------------
13204 -- All_Calls_Remote --
13205 ----------------------
13207 -- pragma All_Calls_Remote [(library_package_NAME)];
13209 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
13210 Lib_Entity : Entity_Id;
13213 Check_Ada_83_Warning;
13214 Check_Valid_Library_Unit_Pragma;
13216 if Nkind (N) = N_Null_Statement then
13220 Lib_Entity := Find_Lib_Unit_Name;
13222 -- A pragma that applies to a Ghost entity becomes Ghost for the
13223 -- purposes of legality checks and removal of ignored Ghost code.
13225 Mark_Ghost_Pragma (N, Lib_Entity);
13227 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
13229 if Present (Lib_Entity) and then not Debug_Flag_U then
13230 if not Is_Remote_Call_Interface (Lib_Entity) then
13231 Error_Pragma ("pragma% only apply to rci unit");
13233 -- Set flag for entity of the library unit
13236 Set_Has_All_Calls_Remote (Lib_Entity);
13239 end All_Calls_Remote;
13241 ---------------------------
13242 -- Allow_Integer_Address --
13243 ---------------------------
13245 -- pragma Allow_Integer_Address;
13247 when Pragma_Allow_Integer_Address =>
13249 Check_Valid_Configuration_Pragma;
13250 Check_Arg_Count (0);
13252 -- If Address is a private type, then set the flag to allow
13253 -- integer address values. If Address is not private, then this
13254 -- pragma has no purpose, so it is simply ignored. Not clear if
13255 -- there are any such targets now.
13257 if Opt.Address_Is_Private then
13258 Opt.Allow_Integer_Address := True;
13266 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
13267 -- ARG ::= NAME | EXPRESSION
13269 -- The first two arguments are by convention intended to refer to an
13270 -- external tool and a tool-specific function. These arguments are
13273 when Pragma_Annotate => Annotate : declare
13278 --------------------------
13279 -- Inferred_String_Type --
13280 --------------------------
13282 function Preferred_String_Type (Expr : Node_Id) return Entity_Id;
13283 -- Infer the type to use for a string literal or a concatentation
13284 -- of operands whose types can be inferred. For such expressions,
13285 -- returns the "narrowest" of the three predefined string types
13286 -- that can represent the characters occurring in the expression.
13287 -- For other expressions, returns Empty.
13289 function Preferred_String_Type (Expr : Node_Id) return Entity_Id is
13291 case Nkind (Expr) is
13292 when N_String_Literal =>
13293 if Has_Wide_Wide_Character (Expr) then
13294 return Standard_Wide_Wide_String;
13295 elsif Has_Wide_Character (Expr) then
13296 return Standard_Wide_String;
13298 return Standard_String;
13301 when N_Op_Concat =>
13303 L_Type : constant Entity_Id
13304 := Preferred_String_Type (Left_Opnd (Expr));
13305 R_Type : constant Entity_Id
13306 := Preferred_String_Type (Right_Opnd (Expr));
13308 Type_Table : constant array (1 .. 4) of Entity_Id
13310 Standard_Wide_Wide_String,
13311 Standard_Wide_String,
13314 for Idx in Type_Table'Range loop
13315 if (L_Type = Type_Table (Idx)) or
13316 (R_Type = Type_Table (Idx))
13318 return Type_Table (Idx);
13321 raise Program_Error;
13327 end Preferred_String_Type;
13330 Check_At_Least_N_Arguments (1);
13332 Nam_Arg := Last (Pragma_Argument_Associations (N));
13334 -- Determine whether the last argument is "Entity => local_NAME"
13335 -- and if it is, perform the required semantic checks. Remove the
13336 -- argument from further processing.
13338 if Nkind (Nam_Arg) = N_Pragma_Argument_Association
13339 and then Chars (Nam_Arg) = Name_Entity
13341 Check_Arg_Is_Local_Name (Nam_Arg);
13342 Arg_Count := Arg_Count - 1;
13344 -- A pragma that applies to a Ghost entity becomes Ghost for
13345 -- the purposes of legality checks and removal of ignored Ghost
13348 if Is_Entity_Name (Get_Pragma_Arg (Nam_Arg))
13349 and then Present (Entity (Get_Pragma_Arg (Nam_Arg)))
13351 Mark_Ghost_Pragma (N, Entity (Get_Pragma_Arg (Nam_Arg)));
13354 -- Not allowed in compiler units (bootstrap issues)
13356 Check_Compiler_Unit ("Entity for pragma Annotate", N);
13359 -- Continue the processing with last argument removed for now
13361 Check_Arg_Is_Identifier (Arg1);
13362 Check_No_Identifiers;
13365 -- The second parameter is optional, it is never analyzed
13370 -- Otherwise there is a second parameter
13373 -- The second parameter must be an identifier
13375 Check_Arg_Is_Identifier (Arg2);
13377 -- Process the remaining parameters (if any)
13379 Arg := Next (Arg2);
13380 while Present (Arg) loop
13381 Expr := Get_Pragma_Arg (Arg);
13384 if Is_Entity_Name (Expr) then
13387 -- For string literals and concatenations of string literals
13388 -- we assume Standard_String as the type, unless the string
13389 -- contains wide or wide_wide characters.
13391 elsif Present (Preferred_String_Type (Expr)) then
13392 Resolve (Expr, Preferred_String_Type (Expr));
13394 elsif Is_Overloaded (Expr) then
13395 Error_Pragma_Arg ("ambiguous argument for pragma%", Expr);
13406 -------------------------------------------------
13407 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
13408 -------------------------------------------------
13411 -- ( [Check => ] Boolean_EXPRESSION
13412 -- [, [Message =>] Static_String_EXPRESSION]);
13414 -- pragma Assert_And_Cut
13415 -- ( [Check => ] Boolean_EXPRESSION
13416 -- [, [Message =>] Static_String_EXPRESSION]);
13419 -- ( [Check => ] Boolean_EXPRESSION
13420 -- [, [Message =>] Static_String_EXPRESSION]);
13422 -- pragma Loop_Invariant
13423 -- ( [Check => ] Boolean_EXPRESSION
13424 -- [, [Message =>] Static_String_EXPRESSION]);
13427 | Pragma_Assert_And_Cut
13429 | Pragma_Loop_Invariant
13432 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
13433 -- Determine whether expression Expr contains a Loop_Entry
13434 -- attribute reference.
13436 -------------------------
13437 -- Contains_Loop_Entry --
13438 -------------------------
13440 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
13441 Has_Loop_Entry : Boolean := False;
13443 function Process (N : Node_Id) return Traverse_Result;
13444 -- Process function for traversal to look for Loop_Entry
13450 function Process (N : Node_Id) return Traverse_Result is
13452 if Nkind (N) = N_Attribute_Reference
13453 and then Attribute_Name (N) = Name_Loop_Entry
13455 Has_Loop_Entry := True;
13462 procedure Traverse is new Traverse_Proc (Process);
13464 -- Start of processing for Contains_Loop_Entry
13468 return Has_Loop_Entry;
13469 end Contains_Loop_Entry;
13474 New_Args : List_Id;
13476 -- Start of processing for Assert
13479 -- Assert is an Ada 2005 RM-defined pragma
13481 if Prag_Id = Pragma_Assert then
13484 -- The remaining ones are GNAT pragmas
13490 Check_At_Least_N_Arguments (1);
13491 Check_At_Most_N_Arguments (2);
13492 Check_Arg_Order ((Name_Check, Name_Message));
13493 Check_Optional_Identifier (Arg1, Name_Check);
13494 Expr := Get_Pragma_Arg (Arg1);
13496 -- Special processing for Loop_Invariant, Loop_Variant or for
13497 -- other cases where a Loop_Entry attribute is present. If the
13498 -- assertion pragma contains attribute Loop_Entry, ensure that
13499 -- the related pragma is within a loop.
13501 if Prag_Id = Pragma_Loop_Invariant
13502 or else Prag_Id = Pragma_Loop_Variant
13503 or else Contains_Loop_Entry (Expr)
13505 Check_Loop_Pragma_Placement;
13507 -- Perform preanalysis to deal with embedded Loop_Entry
13510 Preanalyze_Assert_Expression (Expr, Any_Boolean);
13513 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
13514 -- a corresponding Check pragma:
13516 -- pragma Check (name, condition [, msg]);
13518 -- Where name is the identifier matching the pragma name. So
13519 -- rewrite pragma in this manner, transfer the message argument
13520 -- if present, and analyze the result
13522 -- Note: When dealing with a semantically analyzed tree, the
13523 -- information that a Check node N corresponds to a source Assert,
13524 -- Assume, or Assert_And_Cut pragma can be retrieved from the
13525 -- pragma kind of Original_Node(N).
13527 New_Args := New_List (
13528 Make_Pragma_Argument_Association (Loc,
13529 Expression => Make_Identifier (Loc, Pname)),
13530 Make_Pragma_Argument_Association (Sloc (Expr),
13531 Expression => Expr));
13533 if Arg_Count > 1 then
13534 Check_Optional_Identifier (Arg2, Name_Message);
13536 -- Provide semantic annotations for optional argument, for
13537 -- ASIS use, before rewriting.
13538 -- Is this still needed???
13540 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
13541 Append_To (New_Args, New_Copy_Tree (Arg2));
13544 -- Rewrite as Check pragma
13548 Chars => Name_Check,
13549 Pragma_Argument_Associations => New_Args));
13554 ----------------------
13555 -- Assertion_Policy --
13556 ----------------------
13558 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
13560 -- The following form is Ada 2012 only, but we allow it in all modes
13562 -- Pragma Assertion_Policy (
13563 -- ASSERTION_KIND => POLICY_IDENTIFIER
13564 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
13566 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
13568 -- RM_ASSERTION_KIND ::= Assert |
13569 -- Static_Predicate |
13570 -- Dynamic_Predicate |
13575 -- Type_Invariant |
13576 -- Type_Invariant'Class
13578 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
13580 -- Contract_Cases |
13582 -- Default_Initial_Condition |
13584 -- Initial_Condition |
13585 -- Loop_Invariant |
13591 -- Statement_Assertions
13593 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
13594 -- ID_ASSERTION_KIND list contains implementation-defined additions
13595 -- recognized by GNAT. The effect is to control the behavior of
13596 -- identically named aspects and pragmas, depending on the specified
13597 -- policy identifier:
13599 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
13601 -- Note: Check and Ignore are language-defined. Disable is a GNAT
13602 -- implementation-defined addition that results in totally ignoring
13603 -- the corresponding assertion. If Disable is specified, then the
13604 -- argument of the assertion is not even analyzed. This is useful
13605 -- when the aspect/pragma argument references entities in a with'ed
13606 -- package that is replaced by a dummy package in the final build.
13608 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
13609 -- and Type_Invariant'Class were recognized by the parser and
13610 -- transformed into references to the special internal identifiers
13611 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
13612 -- processing is required here.
13614 when Pragma_Assertion_Policy => Assertion_Policy : declare
13615 procedure Resolve_Suppressible (Policy : Node_Id);
13616 -- Converts the assertion policy 'Suppressible' to either Check or
13617 -- Ignore based on whether checks are suppressed via -gnatp.
13619 --------------------------
13620 -- Resolve_Suppressible --
13621 --------------------------
13623 procedure Resolve_Suppressible (Policy : Node_Id) is
13624 Arg : constant Node_Id := Get_Pragma_Arg (Policy);
13628 -- Transform policy argument Suppressible into either Ignore or
13629 -- Check depending on whether checks are enabled or suppressed.
13631 if Chars (Arg) = Name_Suppressible then
13632 if Suppress_Checks then
13633 Nam := Name_Ignore;
13638 Rewrite (Arg, Make_Identifier (Sloc (Arg), Nam));
13640 end Resolve_Suppressible;
13652 -- This can always appear as a configuration pragma
13654 if Is_Configuration_Pragma then
13657 -- It can also appear in a declarative part or package spec in Ada
13658 -- 2012 mode. We allow this in other modes, but in that case we
13659 -- consider that we have an Ada 2012 pragma on our hands.
13662 Check_Is_In_Decl_Part_Or_Package_Spec;
13666 -- One argument case with no identifier (first form above)
13669 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
13670 or else Chars (Arg1) = No_Name)
13672 Check_Arg_Is_One_Of (Arg1,
13673 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
13675 Resolve_Suppressible (Arg1);
13677 -- Treat one argument Assertion_Policy as equivalent to:
13679 -- pragma Check_Policy (Assertion, policy)
13681 -- So rewrite pragma in that manner and link on to the chain
13682 -- of Check_Policy pragmas, marking the pragma as analyzed.
13684 Policy := Get_Pragma_Arg (Arg1);
13688 Chars => Name_Check_Policy,
13689 Pragma_Argument_Associations => New_List (
13690 Make_Pragma_Argument_Association (Loc,
13691 Expression => Make_Identifier (Loc, Name_Assertion)),
13693 Make_Pragma_Argument_Association (Loc,
13695 Make_Identifier (Sloc (Policy), Chars (Policy))))));
13698 -- Here if we have two or more arguments
13701 Check_At_Least_N_Arguments (1);
13704 -- Loop through arguments
13707 while Present (Arg) loop
13708 LocP := Sloc (Arg);
13710 -- Kind must be specified
13712 if Nkind (Arg) /= N_Pragma_Argument_Association
13713 or else Chars (Arg) = No_Name
13716 ("missing assertion kind for pragma%", Arg);
13719 -- Check Kind and Policy have allowed forms
13721 Kind := Chars (Arg);
13722 Policy := Get_Pragma_Arg (Arg);
13724 if not Is_Valid_Assertion_Kind (Kind) then
13726 ("invalid assertion kind for pragma%", Arg);
13729 Check_Arg_Is_One_Of (Arg,
13730 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
13732 Resolve_Suppressible (Arg);
13734 if Kind = Name_Ghost then
13736 -- The Ghost policy must be either Check or Ignore
13737 -- (SPARK RM 6.9(6)).
13739 if not Nam_In (Chars (Policy), Name_Check,
13743 ("argument of pragma % Ghost must be Check or "
13744 & "Ignore", Policy);
13747 -- Pragma Assertion_Policy specifying a Ghost policy
13748 -- cannot occur within a Ghost subprogram or package
13749 -- (SPARK RM 6.9(14)).
13751 if Ghost_Mode > None then
13753 ("pragma % cannot appear within ghost subprogram or "
13758 -- Rewrite the Assertion_Policy pragma as a series of
13759 -- Check_Policy pragmas of the form:
13761 -- Check_Policy (Kind, Policy);
13763 -- Note: the insertion of the pragmas cannot be done with
13764 -- Insert_Action because in the configuration case, there
13765 -- are no scopes on the scope stack and the mechanism will
13768 Insert_Before_And_Analyze (N,
13770 Chars => Name_Check_Policy,
13771 Pragma_Argument_Associations => New_List (
13772 Make_Pragma_Argument_Association (LocP,
13773 Expression => Make_Identifier (LocP, Kind)),
13774 Make_Pragma_Argument_Association (LocP,
13775 Expression => Policy))));
13780 -- Rewrite the Assertion_Policy pragma as null since we have
13781 -- now inserted all the equivalent Check pragmas.
13783 Rewrite (N, Make_Null_Statement (Loc));
13786 end Assertion_Policy;
13788 ------------------------------
13789 -- Assume_No_Invalid_Values --
13790 ------------------------------
13792 -- pragma Assume_No_Invalid_Values (On | Off);
13794 when Pragma_Assume_No_Invalid_Values =>
13796 Check_Valid_Configuration_Pragma;
13797 Check_Arg_Count (1);
13798 Check_No_Identifiers;
13799 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13801 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
13802 Assume_No_Invalid_Values := True;
13804 Assume_No_Invalid_Values := False;
13807 --------------------------
13808 -- Attribute_Definition --
13809 --------------------------
13811 -- pragma Attribute_Definition
13812 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
13813 -- [Entity =>] LOCAL_NAME,
13814 -- [Expression =>] EXPRESSION | NAME);
13816 when Pragma_Attribute_Definition => Attribute_Definition : declare
13817 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
13822 Check_Arg_Count (3);
13823 Check_Optional_Identifier (Arg1, "attribute");
13824 Check_Optional_Identifier (Arg2, "entity");
13825 Check_Optional_Identifier (Arg3, "expression");
13827 if Nkind (Attribute_Designator) /= N_Identifier then
13828 Error_Msg_N ("attribute name expected", Attribute_Designator);
13832 Check_Arg_Is_Local_Name (Arg2);
13834 -- If the attribute is not recognized, then issue a warning (not
13835 -- an error), and ignore the pragma.
13837 Aname := Chars (Attribute_Designator);
13839 if not Is_Attribute_Name (Aname) then
13840 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
13844 -- Otherwise, rewrite the pragma as an attribute definition clause
13847 Make_Attribute_Definition_Clause (Loc,
13848 Name => Get_Pragma_Arg (Arg2),
13850 Expression => Get_Pragma_Arg (Arg3)));
13852 end Attribute_Definition;
13854 ------------------------------------------------------------------
13855 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
13857 ------------------------------------------------------------------
13859 -- pragma Async_Readers [ (boolean_EXPRESSION) ];
13860 -- pragma Async_Writers [ (boolean_EXPRESSION) ];
13861 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
13862 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
13863 -- pragma No_Caching [ (boolean_EXPRESSION) ];
13865 when Pragma_Async_Readers
13866 | Pragma_Async_Writers
13867 | Pragma_Effective_Reads
13868 | Pragma_Effective_Writes
13869 | Pragma_No_Caching
13871 Async_Effective : declare
13872 Obj_Decl : Node_Id;
13873 Obj_Id : Entity_Id;
13877 Check_No_Identifiers;
13878 Check_At_Most_N_Arguments (1);
13880 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
13882 -- Object declaration
13884 if Nkind (Obj_Decl) /= N_Object_Declaration then
13889 Obj_Id := Defining_Entity (Obj_Decl);
13891 -- Perform minimal verification to ensure that the argument is at
13892 -- least a variable. Subsequent finer grained checks will be done
13893 -- at the end of the declarative region the contains the pragma.
13895 if Ekind (Obj_Id) = E_Variable then
13897 -- A pragma that applies to a Ghost entity becomes Ghost for
13898 -- the purposes of legality checks and removal of ignored Ghost
13901 Mark_Ghost_Pragma (N, Obj_Id);
13903 -- Chain the pragma on the contract for further processing by
13904 -- Analyze_External_Property_In_Decl_Part.
13906 Add_Contract_Item (N, Obj_Id);
13908 -- Analyze the Boolean expression (if any)
13910 if Present (Arg1) then
13911 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
13914 -- Otherwise the external property applies to a constant
13917 Error_Pragma ("pragma % must apply to a volatile object");
13919 end Async_Effective;
13925 -- pragma Asynchronous (LOCAL_NAME);
13927 when Pragma_Asynchronous => Asynchronous : declare
13930 Formal : Entity_Id;
13935 procedure Process_Async_Pragma;
13936 -- Common processing for procedure and access-to-procedure case
13938 --------------------------
13939 -- Process_Async_Pragma --
13940 --------------------------
13942 procedure Process_Async_Pragma is
13945 Set_Is_Asynchronous (Nm);
13949 -- The formals should be of mode IN (RM E.4.1(6))
13952 while Present (S) loop
13953 Formal := Defining_Identifier (S);
13955 if Nkind (Formal) = N_Defining_Identifier
13956 and then Ekind (Formal) /= E_In_Parameter
13959 ("pragma% procedure can only have IN parameter",
13966 Set_Is_Asynchronous (Nm);
13967 end Process_Async_Pragma;
13969 -- Start of processing for pragma Asynchronous
13972 Check_Ada_83_Warning;
13973 Check_No_Identifiers;
13974 Check_Arg_Count (1);
13975 Check_Arg_Is_Local_Name (Arg1);
13977 if Debug_Flag_U then
13981 C_Ent := Cunit_Entity (Current_Sem_Unit);
13982 Analyze (Get_Pragma_Arg (Arg1));
13983 Nm := Entity (Get_Pragma_Arg (Arg1));
13985 -- A pragma that applies to a Ghost entity becomes Ghost for the
13986 -- purposes of legality checks and removal of ignored Ghost code.
13988 Mark_Ghost_Pragma (N, Nm);
13990 if not Is_Remote_Call_Interface (C_Ent)
13991 and then not Is_Remote_Types (C_Ent)
13993 -- This pragma should only appear in an RCI or Remote Types
13994 -- unit (RM E.4.1(4)).
13997 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
14000 if Ekind (Nm) = E_Procedure
14001 and then Nkind (Parent (Nm)) = N_Procedure_Specification
14003 if not Is_Remote_Call_Interface (Nm) then
14005 ("pragma% cannot be applied on non-remote procedure",
14009 L := Parameter_Specifications (Parent (Nm));
14010 Process_Async_Pragma;
14013 elsif Ekind (Nm) = E_Function then
14015 ("pragma% cannot be applied to function", Arg1);
14017 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
14018 if Is_Record_Type (Nm) then
14020 -- A record type that is the Equivalent_Type for a remote
14021 -- access-to-subprogram type.
14023 Decl := Declaration_Node (Corresponding_Remote_Type (Nm));
14026 -- A non-expanded RAS type (distribution is not enabled)
14028 Decl := Declaration_Node (Nm);
14031 if Nkind (Decl) = N_Full_Type_Declaration
14032 and then Nkind (Type_Definition (Decl)) =
14033 N_Access_Procedure_Definition
14035 L := Parameter_Specifications (Type_Definition (Decl));
14036 Process_Async_Pragma;
14038 if Is_Asynchronous (Nm)
14039 and then Expander_Active
14040 and then Get_PCS_Name /= Name_No_DSA
14042 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
14047 ("pragma% cannot reference access-to-function type",
14051 -- Only other possibility is Access-to-class-wide type
14053 elsif Is_Access_Type (Nm)
14054 and then Is_Class_Wide_Type (Designated_Type (Nm))
14056 Check_First_Subtype (Arg1);
14057 Set_Is_Asynchronous (Nm);
14058 if Expander_Active then
14059 RACW_Type_Is_Asynchronous (Nm);
14063 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
14071 -- pragma Atomic (LOCAL_NAME);
14073 when Pragma_Atomic =>
14074 Process_Atomic_Independent_Shared_Volatile;
14076 -----------------------
14077 -- Atomic_Components --
14078 -----------------------
14080 -- pragma Atomic_Components (array_LOCAL_NAME);
14082 -- This processing is shared by Volatile_Components
14084 when Pragma_Atomic_Components
14085 | Pragma_Volatile_Components
14087 Atomic_Components : declare
14093 Check_Ada_83_Warning;
14094 Check_No_Identifiers;
14095 Check_Arg_Count (1);
14096 Check_Arg_Is_Local_Name (Arg1);
14097 E_Id := Get_Pragma_Arg (Arg1);
14099 if Etype (E_Id) = Any_Type then
14103 E := Entity (E_Id);
14105 -- A pragma that applies to a Ghost entity becomes Ghost for the
14106 -- purposes of legality checks and removal of ignored Ghost code.
14108 Mark_Ghost_Pragma (N, E);
14109 Check_Duplicate_Pragma (E);
14111 if Rep_Item_Too_Early (E, N)
14113 Rep_Item_Too_Late (E, N)
14118 D := Declaration_Node (E);
14120 if (Nkind (D) = N_Full_Type_Declaration and then Is_Array_Type (E))
14122 (Nkind (D) = N_Object_Declaration
14123 and then (Ekind (E) = E_Constant
14125 Ekind (E) = E_Variable)
14126 and then Nkind (Object_Definition (D)) =
14127 N_Constrained_Array_Definition)
14129 (Ada_Version >= Ada_2020
14130 and then Nkind (D) = N_Formal_Type_Declaration)
14132 -- The flag is set on the base type, or on the object
14134 if Nkind (D) = N_Full_Type_Declaration then
14135 E := Base_Type (E);
14138 -- Atomic implies both Independent and Volatile
14140 if Prag_Id = Pragma_Atomic_Components then
14141 if Ada_Version >= Ada_2020 then
14143 (Component_Type (Etype (E)), VFA => False);
14146 Set_Has_Atomic_Components (E);
14147 Set_Has_Independent_Components (E);
14150 Set_Has_Volatile_Components (E);
14153 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
14155 end Atomic_Components;
14157 --------------------
14158 -- Attach_Handler --
14159 --------------------
14161 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
14163 when Pragma_Attach_Handler =>
14164 Check_Ada_83_Warning;
14165 Check_No_Identifiers;
14166 Check_Arg_Count (2);
14168 if No_Run_Time_Mode then
14169 Error_Msg_CRT ("Attach_Handler pragma", N);
14171 Check_Interrupt_Or_Attach_Handler;
14173 -- The expression that designates the attribute may depend on a
14174 -- discriminant, and is therefore a per-object expression, to
14175 -- be expanded in the init proc. If expansion is enabled, then
14176 -- perform semantic checks on a copy only.
14181 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
14184 -- In Relaxed_RM_Semantics mode, we allow any static
14185 -- integer value, for compatibility with other compilers.
14187 if Relaxed_RM_Semantics
14188 and then Nkind (Parg2) = N_Integer_Literal
14190 Typ := Standard_Integer;
14192 Typ := RTE (RE_Interrupt_ID);
14195 if Expander_Active then
14196 Temp := New_Copy_Tree (Parg2);
14197 Set_Parent (Temp, N);
14198 Preanalyze_And_Resolve (Temp, Typ);
14201 Resolve (Parg2, Typ);
14205 Process_Interrupt_Or_Attach_Handler;
14208 --------------------
14209 -- C_Pass_By_Copy --
14210 --------------------
14212 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
14214 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
14220 Check_Valid_Configuration_Pragma;
14221 Check_Arg_Count (1);
14222 Check_Optional_Identifier (Arg1, "max_size");
14224 Arg := Get_Pragma_Arg (Arg1);
14225 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
14227 Val := Expr_Value (Arg);
14231 ("maximum size for pragma% must be positive", Arg1);
14233 elsif UI_Is_In_Int_Range (Val) then
14234 Default_C_Record_Mechanism := UI_To_Int (Val);
14236 -- If a giant value is given, Int'Last will do well enough.
14237 -- If sometime someone complains that a record larger than
14238 -- two gigabytes is not copied, we will worry about it then.
14241 Default_C_Record_Mechanism := Mechanism_Type'Last;
14243 end C_Pass_By_Copy;
14249 -- pragma Check ([Name =>] CHECK_KIND,
14250 -- [Check =>] Boolean_EXPRESSION
14251 -- [,[Message =>] String_EXPRESSION]);
14253 -- CHECK_KIND ::= IDENTIFIER |
14256 -- Invariant'Class |
14257 -- Type_Invariant'Class
14259 -- The identifiers Assertions and Statement_Assertions are not
14260 -- allowed, since they have special meaning for Check_Policy.
14262 -- WARNING: The code below manages Ghost regions. Return statements
14263 -- must be replaced by gotos which jump to the end of the code and
14264 -- restore the Ghost mode.
14266 when Pragma_Check => Check : declare
14267 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
14268 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
14269 -- Save the Ghost-related attributes to restore on exit
14275 pragma Warnings (Off, Str);
14278 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
14279 -- the mode now to ensure that any nodes generated during analysis
14280 -- and expansion are marked as Ghost.
14282 Set_Ghost_Mode (N);
14285 Check_At_Least_N_Arguments (2);
14286 Check_At_Most_N_Arguments (3);
14287 Check_Optional_Identifier (Arg1, Name_Name);
14288 Check_Optional_Identifier (Arg2, Name_Check);
14290 if Arg_Count = 3 then
14291 Check_Optional_Identifier (Arg3, Name_Message);
14292 Str := Get_Pragma_Arg (Arg3);
14295 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
14296 Check_Arg_Is_Identifier (Arg1);
14297 Cname := Chars (Get_Pragma_Arg (Arg1));
14299 -- Check forbidden name Assertions or Statement_Assertions
14302 when Name_Assertions =>
14304 ("""Assertions"" is not allowed as a check kind for "
14305 & "pragma%", Arg1);
14307 when Name_Statement_Assertions =>
14309 ("""Statement_Assertions"" is not allowed as a check kind "
14310 & "for pragma%", Arg1);
14316 -- Check applicable policy. We skip this if Checked/Ignored status
14317 -- is already set (e.g. in the case of a pragma from an aspect).
14319 if Is_Checked (N) or else Is_Ignored (N) then
14322 -- For a non-source pragma that is a rewriting of another pragma,
14323 -- copy the Is_Checked/Ignored status from the rewritten pragma.
14325 elsif Is_Rewrite_Substitution (N)
14326 and then Nkind (Original_Node (N)) = N_Pragma
14328 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
14329 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
14331 -- Otherwise query the applicable policy at this point
14334 case Check_Kind (Cname) is
14335 when Name_Ignore =>
14336 Set_Is_Ignored (N, True);
14337 Set_Is_Checked (N, False);
14340 Set_Is_Ignored (N, False);
14341 Set_Is_Checked (N, True);
14343 -- For disable, rewrite pragma as null statement and skip
14344 -- rest of the analysis of the pragma.
14346 when Name_Disable =>
14347 Rewrite (N, Make_Null_Statement (Loc));
14351 -- No other possibilities
14354 raise Program_Error;
14358 -- If check kind was not Disable, then continue pragma analysis
14360 Expr := Get_Pragma_Arg (Arg2);
14362 -- Mark the pragma (or, if rewritten from an aspect, the original
14363 -- aspect) as enabled. Nothing to do for an internally generated
14364 -- check for a dynamic predicate.
14367 and then not Split_PPC (N)
14368 and then Cname /= Name_Dynamic_Predicate
14370 Set_SCO_Pragma_Enabled (Loc);
14373 -- Deal with analyzing the string argument. If checks are not
14374 -- on we don't want any expansion (since such expansion would
14375 -- not get properly deleted) but we do want to analyze (to get
14376 -- proper references). The Preanalyze_And_Resolve routine does
14377 -- just what we want. Ditto if pragma is active, because it will
14378 -- be rewritten as an if-statement whose analysis will complete
14379 -- analysis and expansion of the string message. This makes a
14380 -- difference in the unusual case where the expression for the
14381 -- string may have a side effect, such as raising an exception.
14382 -- This is mandated by RM 11.4.2, which specifies that the string
14383 -- expression is only evaluated if the check fails and
14384 -- Assertion_Error is to be raised.
14386 if Arg_Count = 3 then
14387 Preanalyze_And_Resolve (Str, Standard_String);
14390 -- Now you might think we could just do the same with the Boolean
14391 -- expression if checks are off (and expansion is on) and then
14392 -- rewrite the check as a null statement. This would work but we
14393 -- would lose the useful warnings about an assertion being bound
14394 -- to fail even if assertions are turned off.
14396 -- So instead we wrap the boolean expression in an if statement
14397 -- that looks like:
14399 -- if False and then condition then
14403 -- The reason we do this rewriting during semantic analysis rather
14404 -- than as part of normal expansion is that we cannot analyze and
14405 -- expand the code for the boolean expression directly, or it may
14406 -- cause insertion of actions that would escape the attempt to
14407 -- suppress the check code.
14409 -- Note that the Sloc for the if statement corresponds to the
14410 -- argument condition, not the pragma itself. The reason for
14411 -- this is that we may generate a warning if the condition is
14412 -- False at compile time, and we do not want to delete this
14413 -- warning when we delete the if statement.
14415 if Expander_Active and Is_Ignored (N) then
14416 Eloc := Sloc (Expr);
14419 Make_If_Statement (Eloc,
14421 Make_And_Then (Eloc,
14422 Left_Opnd => Make_Identifier (Eloc, Name_False),
14423 Right_Opnd => Expr),
14424 Then_Statements => New_List (
14425 Make_Null_Statement (Eloc))));
14427 -- Now go ahead and analyze the if statement
14429 In_Assertion_Expr := In_Assertion_Expr + 1;
14431 -- One rather special treatment. If we are now in Eliminated
14432 -- overflow mode, then suppress overflow checking since we do
14433 -- not want to drag in the bignum stuff if we are in Ignore
14434 -- mode anyway. This is particularly important if we are using
14435 -- a configurable run time that does not support bignum ops.
14437 if Scope_Suppress.Overflow_Mode_Assertions = Eliminated then
14439 Svo : constant Boolean :=
14440 Scope_Suppress.Suppress (Overflow_Check);
14442 Scope_Suppress.Overflow_Mode_Assertions := Strict;
14443 Scope_Suppress.Suppress (Overflow_Check) := True;
14445 Scope_Suppress.Suppress (Overflow_Check) := Svo;
14446 Scope_Suppress.Overflow_Mode_Assertions := Eliminated;
14449 -- Not that special case
14455 -- All done with this check
14457 In_Assertion_Expr := In_Assertion_Expr - 1;
14459 -- Check is active or expansion not active. In these cases we can
14460 -- just go ahead and analyze the boolean with no worries.
14463 In_Assertion_Expr := In_Assertion_Expr + 1;
14464 Analyze_And_Resolve (Expr, Any_Boolean);
14465 In_Assertion_Expr := In_Assertion_Expr - 1;
14468 Restore_Ghost_Region (Saved_GM, Saved_IGR);
14471 --------------------------
14472 -- Check_Float_Overflow --
14473 --------------------------
14475 -- pragma Check_Float_Overflow;
14477 when Pragma_Check_Float_Overflow =>
14479 Check_Valid_Configuration_Pragma;
14480 Check_Arg_Count (0);
14481 Check_Float_Overflow := not Machine_Overflows_On_Target;
14487 -- pragma Check_Name (check_IDENTIFIER);
14489 when Pragma_Check_Name =>
14491 Check_No_Identifiers;
14492 Check_Valid_Configuration_Pragma;
14493 Check_Arg_Count (1);
14494 Check_Arg_Is_Identifier (Arg1);
14497 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
14500 for J in Check_Names.First .. Check_Names.Last loop
14501 if Check_Names.Table (J) = Nam then
14506 Check_Names.Append (Nam);
14513 -- This is the old style syntax, which is still allowed in all modes:
14515 -- pragma Check_Policy ([Name =>] CHECK_KIND
14516 -- [Policy =>] POLICY_IDENTIFIER);
14518 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
14520 -- CHECK_KIND ::= IDENTIFIER |
14523 -- Type_Invariant'Class |
14526 -- This is the new style syntax, compatible with Assertion_Policy
14527 -- and also allowed in all modes.
14529 -- Pragma Check_Policy (
14530 -- CHECK_KIND => POLICY_IDENTIFIER
14531 -- {, CHECK_KIND => POLICY_IDENTIFIER});
14533 -- Note: the identifiers Name and Policy are not allowed as
14534 -- Check_Kind values. This avoids ambiguities between the old and
14535 -- new form syntax.
14537 when Pragma_Check_Policy => Check_Policy : declare
14542 Check_At_Least_N_Arguments (1);
14544 -- A Check_Policy pragma can appear either as a configuration
14545 -- pragma, or in a declarative part or a package spec (see RM
14546 -- 11.5(5) for rules for Suppress/Unsuppress which are also
14547 -- followed for Check_Policy).
14549 if not Is_Configuration_Pragma then
14550 Check_Is_In_Decl_Part_Or_Package_Spec;
14553 -- Figure out if we have the old or new syntax. We have the
14554 -- old syntax if the first argument has no identifier, or the
14555 -- identifier is Name.
14557 if Nkind (Arg1) /= N_Pragma_Argument_Association
14558 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
14562 Check_Arg_Count (2);
14563 Check_Optional_Identifier (Arg1, Name_Name);
14564 Kind := Get_Pragma_Arg (Arg1);
14565 Rewrite_Assertion_Kind (Kind,
14566 From_Policy => Comes_From_Source (N));
14567 Check_Arg_Is_Identifier (Arg1);
14569 -- Check forbidden check kind
14571 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
14572 Error_Msg_Name_2 := Chars (Kind);
14574 ("pragma% does not allow% as check name", Arg1);
14579 Check_Optional_Identifier (Arg2, Name_Policy);
14580 Check_Arg_Is_One_Of
14582 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
14584 -- And chain pragma on the Check_Policy_List for search
14586 Set_Next_Pragma (N, Opt.Check_Policy_List);
14587 Opt.Check_Policy_List := N;
14589 -- For the new syntax, what we do is to convert each argument to
14590 -- an old syntax equivalent. We do that because we want to chain
14591 -- old style Check_Policy pragmas for the search (we don't want
14592 -- to have to deal with multiple arguments in the search).
14603 while Present (Arg) loop
14604 LocP := Sloc (Arg);
14605 Argx := Get_Pragma_Arg (Arg);
14607 -- Kind must be specified
14609 if Nkind (Arg) /= N_Pragma_Argument_Association
14610 or else Chars (Arg) = No_Name
14613 ("missing assertion kind for pragma%", Arg);
14616 -- Construct equivalent old form syntax Check_Policy
14617 -- pragma and insert it to get remaining checks.
14621 Chars => Name_Check_Policy,
14622 Pragma_Argument_Associations => New_List (
14623 Make_Pragma_Argument_Association (LocP,
14625 Make_Identifier (LocP, Chars (Arg))),
14626 Make_Pragma_Argument_Association (Sloc (Argx),
14627 Expression => Argx)));
14631 -- For a configuration pragma, insert old form in
14632 -- the corresponding file.
14634 if Is_Configuration_Pragma then
14635 Insert_After (N, New_P);
14639 Insert_Action (N, New_P);
14643 -- Rewrite original Check_Policy pragma to null, since we
14644 -- have converted it into a series of old syntax pragmas.
14646 Rewrite (N, Make_Null_Statement (Loc));
14656 -- pragma Comment (static_string_EXPRESSION)
14658 -- Processing for pragma Comment shares the circuitry for pragma
14659 -- Ident. The only differences are that Ident enforces a limit of 31
14660 -- characters on its argument, and also enforces limitations on
14661 -- placement for DEC compatibility. Pragma Comment shares neither of
14662 -- these restrictions.
14664 -------------------
14665 -- Common_Object --
14666 -------------------
14668 -- pragma Common_Object (
14669 -- [Internal =>] LOCAL_NAME
14670 -- [, [External =>] EXTERNAL_SYMBOL]
14671 -- [, [Size =>] EXTERNAL_SYMBOL]);
14673 -- Processing for this pragma is shared with Psect_Object
14675 ----------------------------------------------
14676 -- Compile_Time_Error, Compile_Time_Warning --
14677 ----------------------------------------------
14679 -- pragma Compile_Time_Error
14680 -- (boolean_EXPRESSION, static_string_EXPRESSION);
14682 -- pragma Compile_Time_Warning
14683 -- (boolean_EXPRESSION, static_string_EXPRESSION);
14685 when Pragma_Compile_Time_Error | Pragma_Compile_Time_Warning =>
14687 Process_Compile_Time_Warning_Or_Error;
14689 ---------------------------
14690 -- Compiler_Unit_Warning --
14691 ---------------------------
14693 -- pragma Compiler_Unit_Warning;
14697 -- Originally, we had only pragma Compiler_Unit, and it resulted in
14698 -- errors not warnings. This means that we had introduced a big extra
14699 -- inertia to compiler changes, since even if we implemented a new
14700 -- feature, and even if all versions to be used for bootstrapping
14701 -- implemented this new feature, we could not use it, since old
14702 -- compilers would give errors for using this feature in units
14703 -- having Compiler_Unit pragmas.
14705 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
14706 -- problem. We no longer have any units mentioning Compiler_Unit,
14707 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
14708 -- and thus generates a warning which can be ignored. So that deals
14709 -- with the problem of old compilers not implementing the newer form
14712 -- Newer compilers recognize the new pragma, but generate warning
14713 -- messages instead of errors, which again can be ignored in the
14714 -- case of an old compiler which implements a wanted new feature
14715 -- but at the time felt like warning about it for older compilers.
14717 -- We retain Compiler_Unit so that new compilers can be used to build
14718 -- older run-times that use this pragma. That's an unusual case, but
14719 -- it's easy enough to handle, so why not?
14721 when Pragma_Compiler_Unit
14722 | Pragma_Compiler_Unit_Warning
14725 Check_Arg_Count (0);
14727 -- Only recognized in main unit
14729 if Current_Sem_Unit = Main_Unit then
14730 Compiler_Unit := True;
14733 -----------------------------
14734 -- Complete_Representation --
14735 -----------------------------
14737 -- pragma Complete_Representation;
14739 when Pragma_Complete_Representation =>
14741 Check_Arg_Count (0);
14743 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
14745 ("pragma & must appear within record representation clause");
14748 ----------------------------
14749 -- Complex_Representation --
14750 ----------------------------
14752 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
14754 when Pragma_Complex_Representation => Complex_Representation : declare
14761 Check_Arg_Count (1);
14762 Check_Optional_Identifier (Arg1, Name_Entity);
14763 Check_Arg_Is_Local_Name (Arg1);
14764 E_Id := Get_Pragma_Arg (Arg1);
14766 if Etype (E_Id) = Any_Type then
14770 E := Entity (E_Id);
14772 if not Is_Record_Type (E) then
14774 ("argument for pragma% must be record type", Arg1);
14777 Ent := First_Entity (E);
14780 or else No (Next_Entity (Ent))
14781 or else Present (Next_Entity (Next_Entity (Ent)))
14782 or else not Is_Floating_Point_Type (Etype (Ent))
14783 or else Etype (Ent) /= Etype (Next_Entity (Ent))
14786 ("record for pragma% must have two fields of the same "
14787 & "floating-point type", Arg1);
14790 Set_Has_Complex_Representation (Base_Type (E));
14792 -- We need to treat the type has having a non-standard
14793 -- representation, for back-end purposes, even though in
14794 -- general a complex will have the default representation
14795 -- of a record with two real components.
14797 Set_Has_Non_Standard_Rep (Base_Type (E));
14799 end Complex_Representation;
14801 -------------------------
14802 -- Component_Alignment --
14803 -------------------------
14805 -- pragma Component_Alignment (
14806 -- [Form =>] ALIGNMENT_CHOICE
14807 -- [, [Name =>] type_LOCAL_NAME]);
14809 -- ALIGNMENT_CHOICE ::=
14811 -- | Component_Size_4
14815 when Pragma_Component_Alignment => Component_AlignmentP : declare
14816 Args : Args_List (1 .. 2);
14817 Names : constant Name_List (1 .. 2) := (
14821 Form : Node_Id renames Args (1);
14822 Name : Node_Id renames Args (2);
14824 Atype : Component_Alignment_Kind;
14829 Gather_Associations (Names, Args);
14832 Error_Pragma ("missing Form argument for pragma%");
14835 Check_Arg_Is_Identifier (Form);
14837 -- Get proper alignment, note that Default = Component_Size on all
14838 -- machines we have so far, and we want to set this value rather
14839 -- than the default value to indicate that it has been explicitly
14840 -- set (and thus will not get overridden by the default component
14841 -- alignment for the current scope)
14843 if Chars (Form) = Name_Component_Size then
14844 Atype := Calign_Component_Size;
14846 elsif Chars (Form) = Name_Component_Size_4 then
14847 Atype := Calign_Component_Size_4;
14849 elsif Chars (Form) = Name_Default then
14850 Atype := Calign_Component_Size;
14852 elsif Chars (Form) = Name_Storage_Unit then
14853 Atype := Calign_Storage_Unit;
14857 ("invalid Form parameter for pragma%", Form);
14860 -- The pragma appears in a configuration file
14862 if No (Parent (N)) then
14863 Check_Valid_Configuration_Pragma;
14865 -- Capture the component alignment in a global variable when
14866 -- the pragma appears in a configuration file. Note that the
14867 -- scope stack is empty at this point and cannot be used to
14868 -- store the alignment value.
14870 Configuration_Component_Alignment := Atype;
14872 -- Case with no name, supplied, affects scope table entry
14874 elsif No (Name) then
14876 (Scope_Stack.Last).Component_Alignment_Default := Atype;
14878 -- Case of name supplied
14881 Check_Arg_Is_Local_Name (Name);
14883 Typ := Entity (Name);
14886 or else Rep_Item_Too_Early (Typ, N)
14890 Typ := Underlying_Type (Typ);
14893 if not Is_Record_Type (Typ)
14894 and then not Is_Array_Type (Typ)
14897 ("Name parameter of pragma% must identify record or "
14898 & "array type", Name);
14901 -- An explicit Component_Alignment pragma overrides an
14902 -- implicit pragma Pack, but not an explicit one.
14904 if not Has_Pragma_Pack (Base_Type (Typ)) then
14905 Set_Is_Packed (Base_Type (Typ), False);
14906 Set_Component_Alignment (Base_Type (Typ), Atype);
14909 end Component_AlignmentP;
14911 --------------------------------
14912 -- Constant_After_Elaboration --
14913 --------------------------------
14915 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
14917 when Pragma_Constant_After_Elaboration => Constant_After_Elaboration :
14919 Obj_Decl : Node_Id;
14920 Obj_Id : Entity_Id;
14924 Check_No_Identifiers;
14925 Check_At_Most_N_Arguments (1);
14927 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
14929 if Nkind (Obj_Decl) /= N_Object_Declaration then
14934 Obj_Id := Defining_Entity (Obj_Decl);
14936 -- The object declaration must be a library-level variable which
14937 -- is either explicitly initialized or obtains a value during the
14938 -- elaboration of a package body (SPARK RM 3.3.1).
14940 if Ekind (Obj_Id) = E_Variable then
14941 if not Is_Library_Level_Entity (Obj_Id) then
14943 ("pragma % must apply to a library level variable");
14947 -- Otherwise the pragma applies to a constant, which is illegal
14950 Error_Pragma ("pragma % must apply to a variable declaration");
14954 -- A pragma that applies to a Ghost entity becomes Ghost for the
14955 -- purposes of legality checks and removal of ignored Ghost code.
14957 Mark_Ghost_Pragma (N, Obj_Id);
14959 -- Chain the pragma on the contract for completeness
14961 Add_Contract_Item (N, Obj_Id);
14963 -- Analyze the Boolean expression (if any)
14965 if Present (Arg1) then
14966 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
14968 end Constant_After_Elaboration;
14970 --------------------
14971 -- Contract_Cases --
14972 --------------------
14974 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
14976 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
14978 -- CASE_GUARD ::= boolean_EXPRESSION | others
14980 -- CONSEQUENCE ::= boolean_EXPRESSION
14982 -- Characteristics:
14984 -- * Analysis - The annotation undergoes initial checks to verify
14985 -- the legal placement and context. Secondary checks preanalyze the
14988 -- Analyze_Contract_Cases_In_Decl_Part
14990 -- * Expansion - The annotation is expanded during the expansion of
14991 -- the related subprogram [body] contract as performed in:
14993 -- Expand_Subprogram_Contract
14995 -- * Template - The annotation utilizes the generic template of the
14996 -- related subprogram [body] when it is:
14998 -- aspect on subprogram declaration
14999 -- aspect on stand-alone subprogram body
15000 -- pragma on stand-alone subprogram body
15002 -- The annotation must prepare its own template when it is:
15004 -- pragma on subprogram declaration
15006 -- * Globals - Capture of global references must occur after full
15009 -- * Instance - The annotation is instantiated automatically when
15010 -- the related generic subprogram [body] is instantiated except for
15011 -- the "pragma on subprogram declaration" case. In that scenario
15012 -- the annotation must instantiate itself.
15014 when Pragma_Contract_Cases => Contract_Cases : declare
15015 Spec_Id : Entity_Id;
15016 Subp_Decl : Node_Id;
15017 Subp_Spec : Node_Id;
15021 Check_No_Identifiers;
15022 Check_Arg_Count (1);
15024 -- Ensure the proper placement of the pragma. Contract_Cases must
15025 -- be associated with a subprogram declaration or a body that acts
15029 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
15033 if Nkind (Subp_Decl) = N_Entry_Declaration then
15036 -- Generic subprogram
15038 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
15041 -- Body acts as spec
15043 elsif Nkind (Subp_Decl) = N_Subprogram_Body
15044 and then No (Corresponding_Spec (Subp_Decl))
15048 -- Body stub acts as spec
15050 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
15051 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
15057 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
15058 Subp_Spec := Specification (Subp_Decl);
15060 -- Pragma Contract_Cases is forbidden on null procedures, as
15061 -- this may lead to potential ambiguities in behavior when
15062 -- interface null procedures are involved.
15064 if Nkind (Subp_Spec) = N_Procedure_Specification
15065 and then Null_Present (Subp_Spec)
15067 Error_Msg_N (Fix_Error
15068 ("pragma % cannot apply to null procedure"), N);
15077 Spec_Id := Unique_Defining_Entity (Subp_Decl);
15079 -- A pragma that applies to a Ghost entity becomes Ghost for the
15080 -- purposes of legality checks and removal of ignored Ghost code.
15082 Mark_Ghost_Pragma (N, Spec_Id);
15083 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
15085 -- Chain the pragma on the contract for further processing by
15086 -- Analyze_Contract_Cases_In_Decl_Part.
15088 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
15090 -- Fully analyze the pragma when it appears inside an entry
15091 -- or subprogram body because it cannot benefit from forward
15094 if Nkind_In (Subp_Decl, N_Entry_Body,
15096 N_Subprogram_Body_Stub)
15098 -- The legality checks of pragma Contract_Cases are affected by
15099 -- the SPARK mode in effect and the volatility of the context.
15100 -- Analyze all pragmas in a specific order.
15102 Analyze_If_Present (Pragma_SPARK_Mode);
15103 Analyze_If_Present (Pragma_Volatile_Function);
15104 Analyze_Contract_Cases_In_Decl_Part (N);
15106 end Contract_Cases;
15112 -- pragma Controlled (first_subtype_LOCAL_NAME);
15114 when Pragma_Controlled => Controlled : declare
15118 Check_No_Identifiers;
15119 Check_Arg_Count (1);
15120 Check_Arg_Is_Local_Name (Arg1);
15121 Arg := Get_Pragma_Arg (Arg1);
15123 if not Is_Entity_Name (Arg)
15124 or else not Is_Access_Type (Entity (Arg))
15126 Error_Pragma_Arg ("pragma% requires access type", Arg1);
15128 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
15136 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
15137 -- [Entity =>] LOCAL_NAME);
15139 when Pragma_Convention => Convention : declare
15142 pragma Warnings (Off, C);
15143 pragma Warnings (Off, E);
15146 Check_Arg_Order ((Name_Convention, Name_Entity));
15147 Check_Ada_83_Warning;
15148 Check_Arg_Count (2);
15149 Process_Convention (C, E);
15151 -- A pragma that applies to a Ghost entity becomes Ghost for the
15152 -- purposes of legality checks and removal of ignored Ghost code.
15154 Mark_Ghost_Pragma (N, E);
15157 ---------------------------
15158 -- Convention_Identifier --
15159 ---------------------------
15161 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
15162 -- [Convention =>] convention_IDENTIFIER);
15164 when Pragma_Convention_Identifier => Convention_Identifier : declare
15170 Check_Arg_Order ((Name_Name, Name_Convention));
15171 Check_Arg_Count (2);
15172 Check_Optional_Identifier (Arg1, Name_Name);
15173 Check_Optional_Identifier (Arg2, Name_Convention);
15174 Check_Arg_Is_Identifier (Arg1);
15175 Check_Arg_Is_Identifier (Arg2);
15176 Idnam := Chars (Get_Pragma_Arg (Arg1));
15177 Cname := Chars (Get_Pragma_Arg (Arg2));
15179 if Is_Convention_Name (Cname) then
15180 Record_Convention_Identifier
15181 (Idnam, Get_Convention_Id (Cname));
15184 ("second arg for % pragma must be convention", Arg2);
15186 end Convention_Identifier;
15192 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
15194 when Pragma_CPP_Class =>
15197 if Warn_On_Obsolescent_Feature then
15199 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
15200 & "effect; replace it by pragma import?j?", N);
15203 Check_Arg_Count (1);
15207 Chars => Name_Import,
15208 Pragma_Argument_Associations => New_List (
15209 Make_Pragma_Argument_Association (Loc,
15210 Expression => Make_Identifier (Loc, Name_CPP)),
15211 New_Copy (First (Pragma_Argument_Associations (N))))));
15214 ---------------------
15215 -- CPP_Constructor --
15216 ---------------------
15218 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
15219 -- [, [External_Name =>] static_string_EXPRESSION ]
15220 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15222 when Pragma_CPP_Constructor => CPP_Constructor : declare
15225 Def_Id : Entity_Id;
15226 Tag_Typ : Entity_Id;
15230 Check_At_Least_N_Arguments (1);
15231 Check_At_Most_N_Arguments (3);
15232 Check_Optional_Identifier (Arg1, Name_Entity);
15233 Check_Arg_Is_Local_Name (Arg1);
15235 Id := Get_Pragma_Arg (Arg1);
15236 Find_Program_Unit_Name (Id);
15238 -- If we did not find the name, we are done
15240 if Etype (Id) = Any_Type then
15244 Def_Id := Entity (Id);
15246 -- Check if already defined as constructor
15248 if Is_Constructor (Def_Id) then
15250 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
15254 if Ekind (Def_Id) = E_Function
15255 and then (Is_CPP_Class (Etype (Def_Id))
15256 or else (Is_Class_Wide_Type (Etype (Def_Id))
15258 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
15260 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
15262 ("'C'P'P constructor must be defined in the scope of "
15263 & "its returned type", Arg1);
15266 if Arg_Count >= 2 then
15267 Set_Imported (Def_Id);
15268 Set_Is_Public (Def_Id);
15269 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
15272 Set_Has_Completion (Def_Id);
15273 Set_Is_Constructor (Def_Id);
15274 Set_Convention (Def_Id, Convention_CPP);
15276 -- Imported C++ constructors are not dispatching primitives
15277 -- because in C++ they don't have a dispatch table slot.
15278 -- However, in Ada the constructor has the profile of a
15279 -- function that returns a tagged type and therefore it has
15280 -- been treated as a primitive operation during semantic
15281 -- analysis. We now remove it from the list of primitive
15282 -- operations of the type.
15284 if Is_Tagged_Type (Etype (Def_Id))
15285 and then not Is_Class_Wide_Type (Etype (Def_Id))
15286 and then Is_Dispatching_Operation (Def_Id)
15288 Tag_Typ := Etype (Def_Id);
15290 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
15291 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
15295 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
15296 Set_Is_Dispatching_Operation (Def_Id, False);
15299 -- For backward compatibility, if the constructor returns a
15300 -- class wide type, and we internally change the return type to
15301 -- the corresponding root type.
15303 if Is_Class_Wide_Type (Etype (Def_Id)) then
15304 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
15308 ("pragma% requires function returning a 'C'P'P_Class type",
15311 end CPP_Constructor;
15317 when Pragma_CPP_Virtual =>
15320 if Warn_On_Obsolescent_Feature then
15322 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
15330 when Pragma_CPP_Vtable =>
15333 if Warn_On_Obsolescent_Feature then
15335 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
15343 -- pragma CPU (EXPRESSION);
15345 when Pragma_CPU => CPU : declare
15346 P : constant Node_Id := Parent (N);
15352 Check_No_Identifiers;
15353 Check_Arg_Count (1);
15357 if Nkind (P) = N_Subprogram_Body then
15358 Check_In_Main_Program;
15360 Arg := Get_Pragma_Arg (Arg1);
15361 Analyze_And_Resolve (Arg, Any_Integer);
15363 Ent := Defining_Unit_Name (Specification (P));
15365 if Nkind (Ent) = N_Defining_Program_Unit_Name then
15366 Ent := Defining_Identifier (Ent);
15371 if not Is_OK_Static_Expression (Arg) then
15372 Flag_Non_Static_Expr
15373 ("main subprogram affinity is not static!", Arg);
15376 -- If constraint error, then we already signalled an error
15378 elsif Raises_Constraint_Error (Arg) then
15381 -- Otherwise check in range
15385 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
15386 -- This is the entity System.Multiprocessors.CPU_Range;
15388 Val : constant Uint := Expr_Value (Arg);
15391 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
15393 Val > Expr_Value (Type_High_Bound (CPU_Id))
15396 ("main subprogram CPU is out of range", Arg1);
15402 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
15406 elsif Nkind (P) = N_Task_Definition then
15407 Arg := Get_Pragma_Arg (Arg1);
15408 Ent := Defining_Identifier (Parent (P));
15410 -- The expression must be analyzed in the special manner
15411 -- described in "Handling of Default and Per-Object
15412 -- Expressions" in sem.ads.
15414 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
15416 -- Anything else is incorrect
15422 -- Check duplicate pragma before we chain the pragma in the Rep
15423 -- Item chain of Ent.
15425 Check_Duplicate_Pragma (Ent);
15426 Record_Rep_Item (Ent, N);
15429 --------------------
15430 -- Deadline_Floor --
15431 --------------------
15433 -- pragma Deadline_Floor (time_span_EXPRESSION);
15435 when Pragma_Deadline_Floor => Deadline_Floor : declare
15436 P : constant Node_Id := Parent (N);
15442 Check_No_Identifiers;
15443 Check_Arg_Count (1);
15445 Arg := Get_Pragma_Arg (Arg1);
15447 -- The expression must be analyzed in the special manner described
15448 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
15450 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
15452 -- Only protected types allowed
15454 if Nkind (P) /= N_Protected_Definition then
15458 Ent := Defining_Identifier (Parent (P));
15460 -- Check duplicate pragma before we chain the pragma in the Rep
15461 -- Item chain of Ent.
15463 Check_Duplicate_Pragma (Ent);
15464 Record_Rep_Item (Ent, N);
15466 end Deadline_Floor;
15472 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
15474 when Pragma_Debug => Debug : declare
15481 -- The condition for executing the call is that the expander
15482 -- is active and that we are not ignoring this debug pragma.
15487 (Expander_Active and then not Is_Ignored (N)),
15490 if not Is_Ignored (N) then
15491 Set_SCO_Pragma_Enabled (Loc);
15494 if Arg_Count = 2 then
15496 Make_And_Then (Loc,
15497 Left_Opnd => Relocate_Node (Cond),
15498 Right_Opnd => Get_Pragma_Arg (Arg1));
15499 Call := Get_Pragma_Arg (Arg2);
15501 Call := Get_Pragma_Arg (Arg1);
15504 if Nkind_In (Call, N_Expanded_Name,
15507 N_Indexed_Component,
15508 N_Selected_Component)
15510 -- If this pragma Debug comes from source, its argument was
15511 -- parsed as a name form (which is syntactically identical).
15512 -- In a generic context a parameterless call will be left as
15513 -- an expanded name (if global) or selected_component if local.
15514 -- Change it to a procedure call statement now.
15516 Change_Name_To_Procedure_Call_Statement (Call);
15518 elsif Nkind (Call) = N_Procedure_Call_Statement then
15520 -- Already in the form of a procedure call statement: nothing
15521 -- to do (could happen in case of an internally generated
15527 -- All other cases: diagnose error
15530 ("argument of pragma ""Debug"" is not procedure call",
15535 -- Rewrite into a conditional with an appropriate condition. We
15536 -- wrap the procedure call in a block so that overhead from e.g.
15537 -- use of the secondary stack does not generate execution overhead
15538 -- for suppressed conditions.
15540 -- Normally the analysis that follows will freeze the subprogram
15541 -- being called. However, if the call is to a null procedure,
15542 -- we want to freeze it before creating the block, because the
15543 -- analysis that follows may be done with expansion disabled, in
15544 -- which case the body will not be generated, leading to spurious
15547 if Nkind (Call) = N_Procedure_Call_Statement
15548 and then Is_Entity_Name (Name (Call))
15550 Analyze (Name (Call));
15551 Freeze_Before (N, Entity (Name (Call)));
15555 Make_Implicit_If_Statement (N,
15557 Then_Statements => New_List (
15558 Make_Block_Statement (Loc,
15559 Handled_Statement_Sequence =>
15560 Make_Handled_Sequence_Of_Statements (Loc,
15561 Statements => New_List (Relocate_Node (Call)))))));
15564 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
15565 -- after analysis of the normally rewritten node, to capture all
15566 -- references to entities, which avoids issuing wrong warnings
15567 -- about unused entities.
15569 if GNATprove_Mode then
15570 Rewrite (N, Make_Null_Statement (Loc));
15578 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
15580 when Pragma_Debug_Policy =>
15582 Check_Arg_Count (1);
15583 Check_No_Identifiers;
15584 Check_Arg_Is_Identifier (Arg1);
15586 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
15587 -- rewrite it that way, and let the rest of the checking come
15588 -- from analyzing the rewritten pragma.
15592 Chars => Name_Check_Policy,
15593 Pragma_Argument_Associations => New_List (
15594 Make_Pragma_Argument_Association (Loc,
15595 Expression => Make_Identifier (Loc, Name_Debug)),
15597 Make_Pragma_Argument_Association (Loc,
15598 Expression => Get_Pragma_Arg (Arg1)))));
15601 -------------------------------
15602 -- Default_Initial_Condition --
15603 -------------------------------
15605 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
15607 when Pragma_Default_Initial_Condition => DIC : declare
15614 Check_No_Identifiers;
15615 Check_At_Most_N_Arguments (1);
15619 while Present (Stmt) loop
15621 -- Skip prior pragmas, but check for duplicates
15623 if Nkind (Stmt) = N_Pragma then
15624 if Pragma_Name (Stmt) = Pname then
15631 -- Skip internally generated code. Note that derived type
15632 -- declarations of untagged types with discriminants are
15633 -- rewritten as private type declarations.
15635 elsif not Comes_From_Source (Stmt)
15636 and then Nkind (Stmt) /= N_Private_Type_Declaration
15640 -- The associated private type [extension] has been found, stop
15643 elsif Nkind_In (Stmt, N_Private_Extension_Declaration,
15644 N_Private_Type_Declaration)
15646 Typ := Defining_Entity (Stmt);
15649 -- The pragma does not apply to a legal construct, issue an
15650 -- error and stop the analysis.
15657 Stmt := Prev (Stmt);
15660 -- The pragma does not apply to a legal construct, issue an error
15661 -- and stop the analysis.
15668 -- A pragma that applies to a Ghost entity becomes Ghost for the
15669 -- purposes of legality checks and removal of ignored Ghost code.
15671 Mark_Ghost_Pragma (N, Typ);
15673 -- The pragma signals that the type defines its own DIC assertion
15676 Set_Has_Own_DIC (Typ);
15678 -- Chain the pragma on the rep item chain for further processing
15680 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
15682 -- Create the declaration of the procedure which verifies the
15683 -- assertion expression of pragma DIC at runtime.
15685 Build_DIC_Procedure_Declaration (Typ);
15688 ----------------------------------
15689 -- Default_Scalar_Storage_Order --
15690 ----------------------------------
15692 -- pragma Default_Scalar_Storage_Order
15693 -- (High_Order_First | Low_Order_First);
15695 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
15696 Default : Character;
15700 Check_Arg_Count (1);
15702 -- Default_Scalar_Storage_Order can appear as a configuration
15703 -- pragma, or in a declarative part of a package spec.
15705 if not Is_Configuration_Pragma then
15706 Check_Is_In_Decl_Part_Or_Package_Spec;
15709 Check_No_Identifiers;
15710 Check_Arg_Is_One_Of
15711 (Arg1, Name_High_Order_First, Name_Low_Order_First);
15712 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15713 Default := Fold_Upper (Name_Buffer (1));
15715 if not Support_Nondefault_SSO_On_Target
15716 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
15718 if Warn_On_Unrecognized_Pragma then
15720 ("non-default Scalar_Storage_Order not supported "
15721 & "on target?g?", N);
15723 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
15726 -- Here set the specified default
15729 Opt.Default_SSO := Default;
15733 --------------------------
15734 -- Default_Storage_Pool --
15735 --------------------------
15737 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
15739 when Pragma_Default_Storage_Pool => Default_Storage_Pool : declare
15744 Check_Arg_Count (1);
15746 -- Default_Storage_Pool can appear as a configuration pragma, or
15747 -- in a declarative part of a package spec.
15749 if not Is_Configuration_Pragma then
15750 Check_Is_In_Decl_Part_Or_Package_Spec;
15753 if From_Aspect_Specification (N) then
15755 E : constant Entity_Id := Entity (Corresponding_Aspect (N));
15757 if not In_Open_Scopes (E) then
15759 ("aspect must apply to package or subprogram", N);
15764 if Present (Arg1) then
15765 Pool := Get_Pragma_Arg (Arg1);
15767 -- Case of Default_Storage_Pool (null);
15769 if Nkind (Pool) = N_Null then
15772 -- This is an odd case, this is not really an expression,
15773 -- so we don't have a type for it. So just set the type to
15776 Set_Etype (Pool, Empty);
15778 -- Case of Default_Storage_Pool (storage_pool_NAME);
15781 -- If it's a configuration pragma, then the only allowed
15782 -- argument is "null".
15784 if Is_Configuration_Pragma then
15785 Error_Pragma_Arg ("NULL expected", Arg1);
15788 -- The expected type for a non-"null" argument is
15789 -- Root_Storage_Pool'Class, and the pool must be a variable.
15791 Analyze_And_Resolve
15792 (Pool, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
15794 if Is_Variable (Pool) then
15796 -- A pragma that applies to a Ghost entity becomes Ghost
15797 -- for the purposes of legality checks and removal of
15798 -- ignored Ghost code.
15800 Mark_Ghost_Pragma (N, Entity (Pool));
15804 ("default storage pool must be a variable", Arg1);
15808 -- Record the pool name (or null). Freeze.Freeze_Entity for an
15809 -- access type will use this information to set the appropriate
15810 -- attributes of the access type. If the pragma appears in a
15811 -- generic unit it is ignored, given that it may refer to a
15814 if not Inside_A_Generic then
15815 Default_Pool := Pool;
15818 end Default_Storage_Pool;
15824 -- pragma Depends (DEPENDENCY_RELATION);
15826 -- DEPENDENCY_RELATION ::=
15828 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
15830 -- DEPENDENCY_CLAUSE ::=
15831 -- OUTPUT_LIST =>[+] INPUT_LIST
15832 -- | NULL_DEPENDENCY_CLAUSE
15834 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
15836 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
15838 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
15840 -- OUTPUT ::= NAME | FUNCTION_RESULT
15843 -- where FUNCTION_RESULT is a function Result attribute_reference
15845 -- Characteristics:
15847 -- * Analysis - The annotation undergoes initial checks to verify
15848 -- the legal placement and context. Secondary checks fully analyze
15849 -- the dependency clauses in:
15851 -- Analyze_Depends_In_Decl_Part
15853 -- * Expansion - None.
15855 -- * Template - The annotation utilizes the generic template of the
15856 -- related subprogram [body] when it is:
15858 -- aspect on subprogram declaration
15859 -- aspect on stand-alone subprogram body
15860 -- pragma on stand-alone subprogram body
15862 -- The annotation must prepare its own template when it is:
15864 -- pragma on subprogram declaration
15866 -- * Globals - Capture of global references must occur after full
15869 -- * Instance - The annotation is instantiated automatically when
15870 -- the related generic subprogram [body] is instantiated except for
15871 -- the "pragma on subprogram declaration" case. In that scenario
15872 -- the annotation must instantiate itself.
15874 when Pragma_Depends => Depends : declare
15876 Spec_Id : Entity_Id;
15877 Subp_Decl : Node_Id;
15880 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
15884 -- Chain the pragma on the contract for further processing by
15885 -- Analyze_Depends_In_Decl_Part.
15887 Add_Contract_Item (N, Spec_Id);
15889 -- Fully analyze the pragma when it appears inside an entry
15890 -- or subprogram body because it cannot benefit from forward
15893 if Nkind_In (Subp_Decl, N_Entry_Body,
15895 N_Subprogram_Body_Stub)
15897 -- The legality checks of pragmas Depends and Global are
15898 -- affected by the SPARK mode in effect and the volatility
15899 -- of the context. In addition these two pragmas are subject
15900 -- to an inherent order:
15905 -- Analyze all these pragmas in the order outlined above
15907 Analyze_If_Present (Pragma_SPARK_Mode);
15908 Analyze_If_Present (Pragma_Volatile_Function);
15909 Analyze_If_Present (Pragma_Global);
15910 Analyze_Depends_In_Decl_Part (N);
15915 ---------------------
15916 -- Detect_Blocking --
15917 ---------------------
15919 -- pragma Detect_Blocking;
15921 when Pragma_Detect_Blocking =>
15923 Check_Arg_Count (0);
15924 Check_Valid_Configuration_Pragma;
15925 Detect_Blocking := True;
15927 ------------------------------------
15928 -- Disable_Atomic_Synchronization --
15929 ------------------------------------
15931 -- pragma Disable_Atomic_Synchronization [(Entity)];
15933 when Pragma_Disable_Atomic_Synchronization =>
15935 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
15937 -------------------
15938 -- Discard_Names --
15939 -------------------
15941 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
15943 when Pragma_Discard_Names => Discard_Names : declare
15948 Check_Ada_83_Warning;
15950 -- Deal with configuration pragma case
15952 if Arg_Count = 0 and then Is_Configuration_Pragma then
15953 Global_Discard_Names := True;
15956 -- Otherwise, check correct appropriate context
15959 Check_Is_In_Decl_Part_Or_Package_Spec;
15961 if Arg_Count = 0 then
15963 -- If there is no parameter, then from now on this pragma
15964 -- applies to any enumeration, exception or tagged type
15965 -- defined in the current declarative part, and recursively
15966 -- to any nested scope.
15968 Set_Discard_Names (Current_Scope);
15972 Check_Arg_Count (1);
15973 Check_Optional_Identifier (Arg1, Name_On);
15974 Check_Arg_Is_Local_Name (Arg1);
15976 E_Id := Get_Pragma_Arg (Arg1);
15978 if Etype (E_Id) = Any_Type then
15982 E := Entity (E_Id);
15984 -- A pragma that applies to a Ghost entity becomes Ghost for
15985 -- the purposes of legality checks and removal of ignored
15988 Mark_Ghost_Pragma (N, E);
15990 if (Is_First_Subtype (E)
15992 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
15993 or else Ekind (E) = E_Exception
15995 Set_Discard_Names (E);
15996 Record_Rep_Item (E, N);
16000 ("inappropriate entity for pragma%", Arg1);
16006 ------------------------
16007 -- Dispatching_Domain --
16008 ------------------------
16010 -- pragma Dispatching_Domain (EXPRESSION);
16012 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
16013 P : constant Node_Id := Parent (N);
16019 Check_No_Identifiers;
16020 Check_Arg_Count (1);
16022 -- This pragma is born obsolete, but not the aspect
16024 if not From_Aspect_Specification (N) then
16026 (No_Obsolescent_Features, Pragma_Identifier (N));
16029 if Nkind (P) = N_Task_Definition then
16030 Arg := Get_Pragma_Arg (Arg1);
16031 Ent := Defining_Identifier (Parent (P));
16033 -- A pragma that applies to a Ghost entity becomes Ghost for
16034 -- the purposes of legality checks and removal of ignored Ghost
16037 Mark_Ghost_Pragma (N, Ent);
16039 -- The expression must be analyzed in the special manner
16040 -- described in "Handling of Default and Per-Object
16041 -- Expressions" in sem.ads.
16043 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
16045 -- Check duplicate pragma before we chain the pragma in the Rep
16046 -- Item chain of Ent.
16048 Check_Duplicate_Pragma (Ent);
16049 Record_Rep_Item (Ent, N);
16051 -- Anything else is incorrect
16056 end Dispatching_Domain;
16062 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
16064 when Pragma_Elaborate => Elaborate : declare
16069 -- Pragma must be in context items list of a compilation unit
16071 if not Is_In_Context_Clause then
16075 -- Must be at least one argument
16077 if Arg_Count = 0 then
16078 Error_Pragma ("pragma% requires at least one argument");
16081 -- In Ada 83 mode, there can be no items following it in the
16082 -- context list except other pragmas and implicit with clauses
16083 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
16084 -- placement rule does not apply.
16086 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
16088 while Present (Citem) loop
16089 if Nkind (Citem) = N_Pragma
16090 or else (Nkind (Citem) = N_With_Clause
16091 and then Implicit_With (Citem))
16096 ("(Ada 83) pragma% must be at end of context clause");
16103 -- Finally, the arguments must all be units mentioned in a with
16104 -- clause in the same context clause. Note we already checked (in
16105 -- Par.Prag) that the arguments are all identifiers or selected
16109 Outer : while Present (Arg) loop
16110 Citem := First (List_Containing (N));
16111 Inner : while Citem /= N loop
16112 if Nkind (Citem) = N_With_Clause
16113 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
16115 Set_Elaborate_Present (Citem, True);
16116 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
16118 -- With the pragma present, elaboration calls on
16119 -- subprograms from the named unit need no further
16120 -- checks, as long as the pragma appears in the current
16121 -- compilation unit. If the pragma appears in some unit
16122 -- in the context, there might still be a need for an
16123 -- Elaborate_All_Desirable from the current compilation
16124 -- to the named unit, so we keep the check enabled. This
16125 -- does not apply in SPARK mode, where we allow pragma
16126 -- Elaborate, but we don't trust it to be right so we
16127 -- will still insist on the Elaborate_All.
16129 if Legacy_Elaboration_Checks
16130 and then In_Extended_Main_Source_Unit (N)
16131 and then SPARK_Mode /= On
16133 Set_Suppress_Elaboration_Warnings
16134 (Entity (Name (Citem)));
16145 ("argument of pragma% is not withed unit", Arg);
16152 -------------------
16153 -- Elaborate_All --
16154 -------------------
16156 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
16158 when Pragma_Elaborate_All => Elaborate_All : declare
16163 Check_Ada_83_Warning;
16165 -- Pragma must be in context items list of a compilation unit
16167 if not Is_In_Context_Clause then
16171 -- Must be at least one argument
16173 if Arg_Count = 0 then
16174 Error_Pragma ("pragma% requires at least one argument");
16177 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
16178 -- have to appear at the end of the context clause, but may
16179 -- appear mixed in with other items, even in Ada 83 mode.
16181 -- Final check: the arguments must all be units mentioned in
16182 -- a with clause in the same context clause. Note that we
16183 -- already checked (in Par.Prag) that all the arguments are
16184 -- either identifiers or selected components.
16187 Outr : while Present (Arg) loop
16188 Citem := First (List_Containing (N));
16189 Innr : while Citem /= N loop
16190 if Nkind (Citem) = N_With_Clause
16191 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
16193 Set_Elaborate_All_Present (Citem, True);
16194 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
16196 -- Suppress warnings and elaboration checks on the named
16197 -- unit if the pragma is in the current compilation, as
16198 -- for pragma Elaborate.
16200 if Legacy_Elaboration_Checks
16201 and then In_Extended_Main_Source_Unit (N)
16203 Set_Suppress_Elaboration_Warnings
16204 (Entity (Name (Citem)));
16214 Set_Error_Posted (N);
16216 ("argument of pragma% is not withed unit", Arg);
16223 --------------------
16224 -- Elaborate_Body --
16225 --------------------
16227 -- pragma Elaborate_Body [( library_unit_NAME )];
16229 when Pragma_Elaborate_Body => Elaborate_Body : declare
16230 Cunit_Node : Node_Id;
16231 Cunit_Ent : Entity_Id;
16234 Check_Ada_83_Warning;
16235 Check_Valid_Library_Unit_Pragma;
16237 if Nkind (N) = N_Null_Statement then
16241 Cunit_Node := Cunit (Current_Sem_Unit);
16242 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
16244 -- A pragma that applies to a Ghost entity becomes Ghost for the
16245 -- purposes of legality checks and removal of ignored Ghost code.
16247 Mark_Ghost_Pragma (N, Cunit_Ent);
16249 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
16252 Error_Pragma ("pragma% must refer to a spec, not a body");
16254 Set_Body_Required (Cunit_Node);
16255 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
16257 -- If we are in dynamic elaboration mode, then we suppress
16258 -- elaboration warnings for the unit, since it is definitely
16259 -- fine NOT to do dynamic checks at the first level (and such
16260 -- checks will be suppressed because no elaboration boolean
16261 -- is created for Elaborate_Body packages).
16263 -- But in the static model of elaboration, Elaborate_Body is
16264 -- definitely NOT good enough to ensure elaboration safety on
16265 -- its own, since the body may WITH other units that are not
16266 -- safe from an elaboration point of view, so a client must
16267 -- still do an Elaborate_All on such units.
16269 -- Debug flag -gnatdD restores the old behavior of 3.13, where
16270 -- Elaborate_Body always suppressed elab warnings.
16272 if Legacy_Elaboration_Checks
16273 and then (Dynamic_Elaboration_Checks or Debug_Flag_DD)
16275 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
16278 end Elaborate_Body;
16280 ------------------------
16281 -- Elaboration_Checks --
16282 ------------------------
16284 -- pragma Elaboration_Checks (Static | Dynamic);
16286 when Pragma_Elaboration_Checks => Elaboration_Checks : declare
16287 procedure Check_Duplicate_Elaboration_Checks_Pragma;
16288 -- Emit an error if the current context list already contains
16289 -- a previous Elaboration_Checks pragma. This routine raises
16290 -- Pragma_Exit if a duplicate is found.
16292 procedure Ignore_Elaboration_Checks_Pragma;
16293 -- Warn that the effects of the pragma are ignored. This routine
16294 -- raises Pragma_Exit.
16296 -----------------------------------------------
16297 -- Check_Duplicate_Elaboration_Checks_Pragma --
16298 -----------------------------------------------
16300 procedure Check_Duplicate_Elaboration_Checks_Pragma is
16305 while Present (Item) loop
16306 if Nkind (Item) = N_Pragma
16307 and then Pragma_Name (Item) = Name_Elaboration_Checks
16317 end Check_Duplicate_Elaboration_Checks_Pragma;
16319 --------------------------------------
16320 -- Ignore_Elaboration_Checks_Pragma --
16321 --------------------------------------
16323 procedure Ignore_Elaboration_Checks_Pragma is
16325 Error_Msg_Name_1 := Pname;
16326 Error_Msg_N ("??effects of pragma % are ignored", N);
16328 ("\place pragma on initial declaration of library unit", N);
16331 end Ignore_Elaboration_Checks_Pragma;
16335 Context : constant Node_Id := Parent (N);
16338 -- Start of processing for Elaboration_Checks
16342 Check_Arg_Count (1);
16343 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
16345 -- The pragma appears in a configuration file
16347 if No (Context) then
16348 Check_Valid_Configuration_Pragma;
16349 Check_Duplicate_Elaboration_Checks_Pragma;
16351 -- The pragma acts as a configuration pragma in a compilation unit
16353 -- pragma Elaboration_Checks (...);
16354 -- package Pack is ...;
16356 elsif Nkind (Context) = N_Compilation_Unit
16357 and then List_Containing (N) = Context_Items (Context)
16359 Check_Valid_Configuration_Pragma;
16360 Check_Duplicate_Elaboration_Checks_Pragma;
16362 Unt := Unit (Context);
16364 -- The pragma must appear on the initial declaration of a unit.
16365 -- If this is not the case, warn that the effects of the pragma
16368 if Nkind (Unt) = N_Package_Body then
16369 Ignore_Elaboration_Checks_Pragma;
16371 -- Check the Acts_As_Spec flag of the compilation units itself
16372 -- to determine whether the subprogram body completes since it
16373 -- has not been analyzed yet. This is safe because compilation
16374 -- units are not overloadable.
16376 elsif Nkind (Unt) = N_Subprogram_Body
16377 and then not Acts_As_Spec (Context)
16379 Ignore_Elaboration_Checks_Pragma;
16381 elsif Nkind (Unt) = N_Subunit then
16382 Ignore_Elaboration_Checks_Pragma;
16385 -- Otherwise the pragma does not appear at the configuration level
16392 -- At this point the pragma is not a duplicate, and appears in the
16393 -- proper context. Set the elaboration model in effect.
16395 Dynamic_Elaboration_Checks :=
16396 Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic;
16397 end Elaboration_Checks;
16403 -- pragma Eliminate (
16404 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
16405 -- [Entity =>] IDENTIFIER |
16406 -- SELECTED_COMPONENT |
16408 -- [, Source_Location => SOURCE_TRACE]);
16410 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
16411 -- SOURCE_TRACE ::= STRING_LITERAL
16413 when Pragma_Eliminate => Eliminate : declare
16414 Args : Args_List (1 .. 5);
16415 Names : constant Name_List (1 .. 5) := (
16418 Name_Parameter_Types,
16420 Name_Source_Location);
16422 -- Note : Parameter_Types and Result_Type are leftovers from
16423 -- prior implementations of the pragma. They are not generated
16424 -- by the gnatelim tool, and play no role in selecting which
16425 -- of a set of overloaded names is chosen for elimination.
16427 Unit_Name : Node_Id renames Args (1);
16428 Entity : Node_Id renames Args (2);
16429 Parameter_Types : Node_Id renames Args (3);
16430 Result_Type : Node_Id renames Args (4);
16431 Source_Location : Node_Id renames Args (5);
16435 Check_Valid_Configuration_Pragma;
16436 Gather_Associations (Names, Args);
16438 if No (Unit_Name) then
16439 Error_Pragma ("missing Unit_Name argument for pragma%");
16443 and then (Present (Parameter_Types)
16445 Present (Result_Type)
16447 Present (Source_Location))
16449 Error_Pragma ("missing Entity argument for pragma%");
16452 if (Present (Parameter_Types)
16454 Present (Result_Type))
16456 Present (Source_Location)
16459 ("parameter profile and source location cannot be used "
16460 & "together in pragma%");
16463 Process_Eliminate_Pragma
16472 -----------------------------------
16473 -- Enable_Atomic_Synchronization --
16474 -----------------------------------
16476 -- pragma Enable_Atomic_Synchronization [(Entity)];
16478 when Pragma_Enable_Atomic_Synchronization =>
16480 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
16487 -- [ Convention =>] convention_IDENTIFIER,
16488 -- [ Entity =>] LOCAL_NAME
16489 -- [, [External_Name =>] static_string_EXPRESSION ]
16490 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16492 when Pragma_Export => Export : declare
16494 Def_Id : Entity_Id;
16496 pragma Warnings (Off, C);
16499 Check_Ada_83_Warning;
16503 Name_External_Name,
16506 Check_At_Least_N_Arguments (2);
16507 Check_At_Most_N_Arguments (4);
16509 -- In Relaxed_RM_Semantics, support old Ada 83 style:
16510 -- pragma Export (Entity, "external name");
16512 if Relaxed_RM_Semantics
16513 and then Arg_Count = 2
16514 and then Nkind (Expression (Arg2)) = N_String_Literal
16517 Def_Id := Get_Pragma_Arg (Arg1);
16520 if not Is_Entity_Name (Def_Id) then
16521 Error_Pragma_Arg ("entity name required", Arg1);
16524 Def_Id := Entity (Def_Id);
16525 Set_Exported (Def_Id, Arg1);
16528 Process_Convention (C, Def_Id);
16530 -- A pragma that applies to a Ghost entity becomes Ghost for
16531 -- the purposes of legality checks and removal of ignored Ghost
16534 Mark_Ghost_Pragma (N, Def_Id);
16536 if Ekind (Def_Id) /= E_Constant then
16537 Note_Possible_Modification
16538 (Get_Pragma_Arg (Arg2), Sure => False);
16541 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
16542 Set_Exported (Def_Id, Arg2);
16545 -- If the entity is a deferred constant, propagate the information
16546 -- to the full view, because gigi elaborates the full view only.
16548 if Ekind (Def_Id) = E_Constant
16549 and then Present (Full_View (Def_Id))
16552 Id2 : constant Entity_Id := Full_View (Def_Id);
16554 Set_Is_Exported (Id2, Is_Exported (Def_Id));
16555 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
16556 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
16561 ---------------------
16562 -- Export_Function --
16563 ---------------------
16565 -- pragma Export_Function (
16566 -- [Internal =>] LOCAL_NAME
16567 -- [, [External =>] EXTERNAL_SYMBOL]
16568 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16569 -- [, [Result_Type =>] TYPE_DESIGNATOR]
16570 -- [, [Mechanism =>] MECHANISM]
16571 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
16573 -- EXTERNAL_SYMBOL ::=
16575 -- | static_string_EXPRESSION
16577 -- PARAMETER_TYPES ::=
16579 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16581 -- TYPE_DESIGNATOR ::=
16583 -- | subtype_Name ' Access
16587 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16589 -- MECHANISM_ASSOCIATION ::=
16590 -- [formal_parameter_NAME =>] MECHANISM_NAME
16592 -- MECHANISM_NAME ::=
16596 when Pragma_Export_Function => Export_Function : declare
16597 Args : Args_List (1 .. 6);
16598 Names : constant Name_List (1 .. 6) := (
16601 Name_Parameter_Types,
16604 Name_Result_Mechanism);
16606 Internal : Node_Id renames Args (1);
16607 External : Node_Id renames Args (2);
16608 Parameter_Types : Node_Id renames Args (3);
16609 Result_Type : Node_Id renames Args (4);
16610 Mechanism : Node_Id renames Args (5);
16611 Result_Mechanism : Node_Id renames Args (6);
16615 Gather_Associations (Names, Args);
16616 Process_Extended_Import_Export_Subprogram_Pragma (
16617 Arg_Internal => Internal,
16618 Arg_External => External,
16619 Arg_Parameter_Types => Parameter_Types,
16620 Arg_Result_Type => Result_Type,
16621 Arg_Mechanism => Mechanism,
16622 Arg_Result_Mechanism => Result_Mechanism);
16623 end Export_Function;
16625 -------------------
16626 -- Export_Object --
16627 -------------------
16629 -- pragma Export_Object (
16630 -- [Internal =>] LOCAL_NAME
16631 -- [, [External =>] EXTERNAL_SYMBOL]
16632 -- [, [Size =>] EXTERNAL_SYMBOL]);
16634 -- EXTERNAL_SYMBOL ::=
16636 -- | static_string_EXPRESSION
16638 -- PARAMETER_TYPES ::=
16640 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16642 -- TYPE_DESIGNATOR ::=
16644 -- | subtype_Name ' Access
16648 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16650 -- MECHANISM_ASSOCIATION ::=
16651 -- [formal_parameter_NAME =>] MECHANISM_NAME
16653 -- MECHANISM_NAME ::=
16657 when Pragma_Export_Object => Export_Object : declare
16658 Args : Args_List (1 .. 3);
16659 Names : constant Name_List (1 .. 3) := (
16664 Internal : Node_Id renames Args (1);
16665 External : Node_Id renames Args (2);
16666 Size : Node_Id renames Args (3);
16670 Gather_Associations (Names, Args);
16671 Process_Extended_Import_Export_Object_Pragma (
16672 Arg_Internal => Internal,
16673 Arg_External => External,
16677 ----------------------
16678 -- Export_Procedure --
16679 ----------------------
16681 -- pragma Export_Procedure (
16682 -- [Internal =>] LOCAL_NAME
16683 -- [, [External =>] EXTERNAL_SYMBOL]
16684 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16685 -- [, [Mechanism =>] MECHANISM]);
16687 -- EXTERNAL_SYMBOL ::=
16689 -- | static_string_EXPRESSION
16691 -- PARAMETER_TYPES ::=
16693 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16695 -- TYPE_DESIGNATOR ::=
16697 -- | subtype_Name ' Access
16701 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16703 -- MECHANISM_ASSOCIATION ::=
16704 -- [formal_parameter_NAME =>] MECHANISM_NAME
16706 -- MECHANISM_NAME ::=
16710 when Pragma_Export_Procedure => Export_Procedure : declare
16711 Args : Args_List (1 .. 4);
16712 Names : constant Name_List (1 .. 4) := (
16715 Name_Parameter_Types,
16718 Internal : Node_Id renames Args (1);
16719 External : Node_Id renames Args (2);
16720 Parameter_Types : Node_Id renames Args (3);
16721 Mechanism : Node_Id renames Args (4);
16725 Gather_Associations (Names, Args);
16726 Process_Extended_Import_Export_Subprogram_Pragma (
16727 Arg_Internal => Internal,
16728 Arg_External => External,
16729 Arg_Parameter_Types => Parameter_Types,
16730 Arg_Mechanism => Mechanism);
16731 end Export_Procedure;
16737 -- pragma Export_Value (
16738 -- [Value =>] static_integer_EXPRESSION,
16739 -- [Link_Name =>] static_string_EXPRESSION);
16741 when Pragma_Export_Value =>
16743 Check_Arg_Order ((Name_Value, Name_Link_Name));
16744 Check_Arg_Count (2);
16746 Check_Optional_Identifier (Arg1, Name_Value);
16747 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
16749 Check_Optional_Identifier (Arg2, Name_Link_Name);
16750 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16752 -----------------------------
16753 -- Export_Valued_Procedure --
16754 -----------------------------
16756 -- pragma Export_Valued_Procedure (
16757 -- [Internal =>] LOCAL_NAME
16758 -- [, [External =>] EXTERNAL_SYMBOL,]
16759 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16760 -- [, [Mechanism =>] MECHANISM]);
16762 -- EXTERNAL_SYMBOL ::=
16764 -- | static_string_EXPRESSION
16766 -- PARAMETER_TYPES ::=
16768 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16770 -- TYPE_DESIGNATOR ::=
16772 -- | subtype_Name ' Access
16776 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16778 -- MECHANISM_ASSOCIATION ::=
16779 -- [formal_parameter_NAME =>] MECHANISM_NAME
16781 -- MECHANISM_NAME ::=
16785 when Pragma_Export_Valued_Procedure =>
16786 Export_Valued_Procedure : declare
16787 Args : Args_List (1 .. 4);
16788 Names : constant Name_List (1 .. 4) := (
16791 Name_Parameter_Types,
16794 Internal : Node_Id renames Args (1);
16795 External : Node_Id renames Args (2);
16796 Parameter_Types : Node_Id renames Args (3);
16797 Mechanism : Node_Id renames Args (4);
16801 Gather_Associations (Names, Args);
16802 Process_Extended_Import_Export_Subprogram_Pragma (
16803 Arg_Internal => Internal,
16804 Arg_External => External,
16805 Arg_Parameter_Types => Parameter_Types,
16806 Arg_Mechanism => Mechanism);
16807 end Export_Valued_Procedure;
16809 -------------------
16810 -- Extend_System --
16811 -------------------
16813 -- pragma Extend_System ([Name =>] Identifier);
16815 when Pragma_Extend_System =>
16817 Check_Valid_Configuration_Pragma;
16818 Check_Arg_Count (1);
16819 Check_Optional_Identifier (Arg1, Name_Name);
16820 Check_Arg_Is_Identifier (Arg1);
16822 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16825 and then Name_Buffer (1 .. 4) = "aux_"
16827 if Present (System_Extend_Pragma_Arg) then
16828 if Chars (Get_Pragma_Arg (Arg1)) =
16829 Chars (Expression (System_Extend_Pragma_Arg))
16833 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
16834 Error_Pragma ("pragma% conflicts with that #");
16838 System_Extend_Pragma_Arg := Arg1;
16840 if not GNAT_Mode then
16841 System_Extend_Unit := Arg1;
16845 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
16848 ------------------------
16849 -- Extensions_Allowed --
16850 ------------------------
16852 -- pragma Extensions_Allowed (ON | OFF);
16854 when Pragma_Extensions_Allowed =>
16856 Check_Arg_Count (1);
16857 Check_No_Identifiers;
16858 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16860 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
16861 Extensions_Allowed := True;
16862 Ada_Version := Ada_Version_Type'Last;
16865 Extensions_Allowed := False;
16866 Ada_Version := Ada_Version_Explicit;
16867 Ada_Version_Pragma := Empty;
16870 ------------------------
16871 -- Extensions_Visible --
16872 ------------------------
16874 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
16876 -- Characteristics:
16878 -- * Analysis - The annotation is fully analyzed immediately upon
16879 -- elaboration as its expression must be static.
16881 -- * Expansion - None.
16883 -- * Template - The annotation utilizes the generic template of the
16884 -- related subprogram [body] when it is:
16886 -- aspect on subprogram declaration
16887 -- aspect on stand-alone subprogram body
16888 -- pragma on stand-alone subprogram body
16890 -- The annotation must prepare its own template when it is:
16892 -- pragma on subprogram declaration
16894 -- * Globals - Capture of global references must occur after full
16897 -- * Instance - The annotation is instantiated automatically when
16898 -- the related generic subprogram [body] is instantiated except for
16899 -- the "pragma on subprogram declaration" case. In that scenario
16900 -- the annotation must instantiate itself.
16902 when Pragma_Extensions_Visible => Extensions_Visible : declare
16903 Formal : Entity_Id;
16904 Has_OK_Formal : Boolean := False;
16905 Spec_Id : Entity_Id;
16906 Subp_Decl : Node_Id;
16910 Check_No_Identifiers;
16911 Check_At_Most_N_Arguments (1);
16914 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
16916 -- Abstract subprogram declaration
16918 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
16921 -- Generic subprogram declaration
16923 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
16926 -- Body acts as spec
16928 elsif Nkind (Subp_Decl) = N_Subprogram_Body
16929 and then No (Corresponding_Spec (Subp_Decl))
16933 -- Body stub acts as spec
16935 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
16936 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
16940 -- Subprogram declaration
16942 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
16945 -- Otherwise the pragma is associated with an illegal construct
16948 Error_Pragma ("pragma % must apply to a subprogram");
16952 -- Mark the pragma as Ghost if the related subprogram is also
16953 -- Ghost. This also ensures that any expansion performed further
16954 -- below will produce Ghost nodes.
16956 Spec_Id := Unique_Defining_Entity (Subp_Decl);
16957 Mark_Ghost_Pragma (N, Spec_Id);
16959 -- Chain the pragma on the contract for completeness
16961 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
16963 -- The legality checks of pragma Extension_Visible are affected
16964 -- by the SPARK mode in effect. Analyze all pragmas in specific
16967 Analyze_If_Present (Pragma_SPARK_Mode);
16969 -- Examine the formals of the related subprogram
16971 Formal := First_Formal (Spec_Id);
16972 while Present (Formal) loop
16974 -- At least one of the formals is of a specific tagged type,
16975 -- the pragma is legal.
16977 if Is_Specific_Tagged_Type (Etype (Formal)) then
16978 Has_OK_Formal := True;
16981 -- A generic subprogram with at least one formal of a private
16982 -- type ensures the legality of the pragma because the actual
16983 -- may be specifically tagged. Note that this is verified by
16984 -- the check above at instantiation time.
16986 elsif Is_Private_Type (Etype (Formal))
16987 and then Is_Generic_Type (Etype (Formal))
16989 Has_OK_Formal := True;
16993 Next_Formal (Formal);
16996 if not Has_OK_Formal then
16997 Error_Msg_Name_1 := Pname;
16998 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
17000 ("\subprogram & lacks parameter of specific tagged or "
17001 & "generic private type", N, Spec_Id);
17006 -- Analyze the Boolean expression (if any)
17008 if Present (Arg1) then
17009 Check_Static_Boolean_Expression
17010 (Expression (Get_Argument (N, Spec_Id)));
17012 end Extensions_Visible;
17018 -- pragma External (
17019 -- [ Convention =>] convention_IDENTIFIER,
17020 -- [ Entity =>] LOCAL_NAME
17021 -- [, [External_Name =>] static_string_EXPRESSION ]
17022 -- [, [Link_Name =>] static_string_EXPRESSION ]);
17024 when Pragma_External => External : declare
17027 pragma Warnings (Off, C);
17034 Name_External_Name,
17036 Check_At_Least_N_Arguments (2);
17037 Check_At_Most_N_Arguments (4);
17038 Process_Convention (C, E);
17040 -- A pragma that applies to a Ghost entity becomes Ghost for the
17041 -- purposes of legality checks and removal of ignored Ghost code.
17043 Mark_Ghost_Pragma (N, E);
17045 Note_Possible_Modification
17046 (Get_Pragma_Arg (Arg2), Sure => False);
17047 Process_Interface_Name (E, Arg3, Arg4, N);
17048 Set_Exported (E, Arg2);
17051 --------------------------
17052 -- External_Name_Casing --
17053 --------------------------
17055 -- pragma External_Name_Casing (
17056 -- UPPERCASE | LOWERCASE
17057 -- [, AS_IS | UPPERCASE | LOWERCASE]);
17059 when Pragma_External_Name_Casing =>
17061 Check_No_Identifiers;
17063 if Arg_Count = 2 then
17064 Check_Arg_Is_One_Of
17065 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
17067 case Chars (Get_Pragma_Arg (Arg2)) is
17069 Opt.External_Name_Exp_Casing := As_Is;
17071 when Name_Uppercase =>
17072 Opt.External_Name_Exp_Casing := Uppercase;
17074 when Name_Lowercase =>
17075 Opt.External_Name_Exp_Casing := Lowercase;
17082 Check_Arg_Count (1);
17085 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
17087 case Chars (Get_Pragma_Arg (Arg1)) is
17088 when Name_Uppercase =>
17089 Opt.External_Name_Imp_Casing := Uppercase;
17091 when Name_Lowercase =>
17092 Opt.External_Name_Imp_Casing := Lowercase;
17102 -- pragma Fast_Math;
17104 when Pragma_Fast_Math =>
17106 Check_No_Identifiers;
17107 Check_Valid_Configuration_Pragma;
17110 --------------------------
17111 -- Favor_Top_Level --
17112 --------------------------
17114 -- pragma Favor_Top_Level (type_NAME);
17116 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
17121 Check_No_Identifiers;
17122 Check_Arg_Count (1);
17123 Check_Arg_Is_Local_Name (Arg1);
17124 Typ := Entity (Get_Pragma_Arg (Arg1));
17126 -- A pragma that applies to a Ghost entity becomes Ghost for the
17127 -- purposes of legality checks and removal of ignored Ghost code.
17129 Mark_Ghost_Pragma (N, Typ);
17131 -- If it's an access-to-subprogram type (in particular, not a
17132 -- subtype), set the flag on that type.
17134 if Is_Access_Subprogram_Type (Typ) then
17135 Set_Can_Use_Internal_Rep (Typ, False);
17137 -- Otherwise it's an error (name denotes the wrong sort of entity)
17141 ("access-to-subprogram type expected",
17142 Get_Pragma_Arg (Arg1));
17144 end Favor_Top_Level;
17146 ---------------------------
17147 -- Finalize_Storage_Only --
17148 ---------------------------
17150 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
17152 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
17153 Assoc : constant Node_Id := Arg1;
17154 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
17159 Check_No_Identifiers;
17160 Check_Arg_Count (1);
17161 Check_Arg_Is_Local_Name (Arg1);
17163 Find_Type (Type_Id);
17164 Typ := Entity (Type_Id);
17167 or else Rep_Item_Too_Early (Typ, N)
17171 Typ := Underlying_Type (Typ);
17174 if not Is_Controlled (Typ) then
17175 Error_Pragma ("pragma% must specify controlled type");
17178 Check_First_Subtype (Arg1);
17180 if Finalize_Storage_Only (Typ) then
17181 Error_Pragma ("duplicate pragma%, only one allowed");
17183 elsif not Rep_Item_Too_Late (Typ, N) then
17184 Set_Finalize_Storage_Only (Base_Type (Typ), True);
17186 end Finalize_Storage;
17192 -- pragma Ghost [ (boolean_EXPRESSION) ];
17194 when Pragma_Ghost => Ghost : declare
17198 Orig_Stmt : Node_Id;
17199 Prev_Id : Entity_Id;
17204 Check_No_Identifiers;
17205 Check_At_Most_N_Arguments (1);
17209 while Present (Stmt) loop
17211 -- Skip prior pragmas, but check for duplicates
17213 if Nkind (Stmt) = N_Pragma then
17214 if Pragma_Name (Stmt) = Pname then
17221 -- Task unit declared without a definition cannot be subject to
17222 -- pragma Ghost (SPARK RM 6.9(19)).
17224 elsif Nkind_In (Stmt, N_Single_Task_Declaration,
17225 N_Task_Type_Declaration)
17227 Error_Pragma ("pragma % cannot apply to a task type");
17230 -- Skip internally generated code
17232 elsif not Comes_From_Source (Stmt) then
17233 Orig_Stmt := Original_Node (Stmt);
17235 -- When pragma Ghost applies to an untagged derivation, the
17236 -- derivation is transformed into a [sub]type declaration.
17238 if Nkind_In (Stmt, N_Full_Type_Declaration,
17239 N_Subtype_Declaration)
17240 and then Comes_From_Source (Orig_Stmt)
17241 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
17242 and then Nkind (Type_Definition (Orig_Stmt)) =
17243 N_Derived_Type_Definition
17245 Id := Defining_Entity (Stmt);
17248 -- When pragma Ghost applies to an object declaration which
17249 -- is initialized by means of a function call that returns
17250 -- on the secondary stack, the object declaration becomes a
17253 elsif Nkind (Stmt) = N_Object_Renaming_Declaration
17254 and then Comes_From_Source (Orig_Stmt)
17255 and then Nkind (Orig_Stmt) = N_Object_Declaration
17257 Id := Defining_Entity (Stmt);
17260 -- When pragma Ghost applies to an expression function, the
17261 -- expression function is transformed into a subprogram.
17263 elsif Nkind (Stmt) = N_Subprogram_Declaration
17264 and then Comes_From_Source (Orig_Stmt)
17265 and then Nkind (Orig_Stmt) = N_Expression_Function
17267 Id := Defining_Entity (Stmt);
17271 -- The pragma applies to a legal construct, stop the traversal
17273 elsif Nkind_In (Stmt, N_Abstract_Subprogram_Declaration,
17274 N_Full_Type_Declaration,
17275 N_Generic_Subprogram_Declaration,
17276 N_Object_Declaration,
17277 N_Private_Extension_Declaration,
17278 N_Private_Type_Declaration,
17279 N_Subprogram_Declaration,
17280 N_Subtype_Declaration)
17282 Id := Defining_Entity (Stmt);
17285 -- The pragma does not apply to a legal construct, issue an
17286 -- error and stop the analysis.
17290 ("pragma % must apply to an object, package, subprogram "
17295 Stmt := Prev (Stmt);
17298 Context := Parent (N);
17300 -- Handle compilation units
17302 if Nkind (Context) = N_Compilation_Unit_Aux then
17303 Context := Unit (Parent (Context));
17306 -- Protected and task types cannot be subject to pragma Ghost
17307 -- (SPARK RM 6.9(19)).
17309 if Nkind_In (Context, N_Protected_Body, N_Protected_Definition)
17311 Error_Pragma ("pragma % cannot apply to a protected type");
17314 elsif Nkind_In (Context, N_Task_Body, N_Task_Definition) then
17315 Error_Pragma ("pragma % cannot apply to a task type");
17321 -- When pragma Ghost is associated with a [generic] package, it
17322 -- appears in the visible declarations.
17324 if Nkind (Context) = N_Package_Specification
17325 and then Present (Visible_Declarations (Context))
17326 and then List_Containing (N) = Visible_Declarations (Context)
17328 Id := Defining_Entity (Context);
17330 -- Pragma Ghost applies to a stand-alone subprogram body
17332 elsif Nkind (Context) = N_Subprogram_Body
17333 and then No (Corresponding_Spec (Context))
17335 Id := Defining_Entity (Context);
17337 -- Pragma Ghost applies to a subprogram declaration that acts
17338 -- as a compilation unit.
17340 elsif Nkind (Context) = N_Subprogram_Declaration then
17341 Id := Defining_Entity (Context);
17343 -- Pragma Ghost applies to a generic subprogram
17345 elsif Nkind (Context) = N_Generic_Subprogram_Declaration then
17346 Id := Defining_Entity (Specification (Context));
17352 ("pragma % must apply to an object, package, subprogram or "
17357 -- Handle completions of types and constants that are subject to
17360 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
17361 Prev_Id := Incomplete_Or_Partial_View (Id);
17363 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
17364 Error_Msg_Name_1 := Pname;
17366 -- The full declaration of a deferred constant cannot be
17367 -- subject to pragma Ghost unless the deferred declaration
17368 -- is also Ghost (SPARK RM 6.9(9)).
17370 if Ekind (Prev_Id) = E_Constant then
17371 Error_Msg_Name_1 := Pname;
17372 Error_Msg_NE (Fix_Error
17373 ("pragma % must apply to declaration of deferred "
17374 & "constant &"), N, Id);
17377 -- Pragma Ghost may appear on the full view of an incomplete
17378 -- type because the incomplete declaration lacks aspects and
17379 -- cannot be subject to pragma Ghost.
17381 elsif Ekind (Prev_Id) = E_Incomplete_Type then
17384 -- The full declaration of a type cannot be subject to
17385 -- pragma Ghost unless the partial view is also Ghost
17386 -- (SPARK RM 6.9(9)).
17389 Error_Msg_NE (Fix_Error
17390 ("pragma % must apply to partial view of type &"),
17396 -- A synchronized object cannot be subject to pragma Ghost
17397 -- (SPARK RM 6.9(19)).
17399 elsif Ekind (Id) = E_Variable then
17400 if Is_Protected_Type (Etype (Id)) then
17401 Error_Pragma ("pragma % cannot apply to a protected object");
17404 elsif Is_Task_Type (Etype (Id)) then
17405 Error_Pragma ("pragma % cannot apply to a task object");
17410 -- Analyze the Boolean expression (if any)
17412 if Present (Arg1) then
17413 Expr := Get_Pragma_Arg (Arg1);
17415 Analyze_And_Resolve (Expr, Standard_Boolean);
17417 if Is_OK_Static_Expression (Expr) then
17419 -- "Ghostness" cannot be turned off once enabled within a
17420 -- region (SPARK RM 6.9(6)).
17422 if Is_False (Expr_Value (Expr))
17423 and then Ghost_Mode > None
17426 ("pragma % with value False cannot appear in enabled "
17431 -- Otherwie the expression is not static
17435 ("expression of pragma % must be static", Expr);
17440 Set_Is_Ghost_Entity (Id);
17447 -- pragma Global (GLOBAL_SPECIFICATION);
17449 -- GLOBAL_SPECIFICATION ::=
17452 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
17454 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
17456 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
17457 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
17458 -- GLOBAL_ITEM ::= NAME
17460 -- Characteristics:
17462 -- * Analysis - The annotation undergoes initial checks to verify
17463 -- the legal placement and context. Secondary checks fully analyze
17464 -- the dependency clauses in:
17466 -- Analyze_Global_In_Decl_Part
17468 -- * Expansion - None.
17470 -- * Template - The annotation utilizes the generic template of the
17471 -- related subprogram [body] when it is:
17473 -- aspect on subprogram declaration
17474 -- aspect on stand-alone subprogram body
17475 -- pragma on stand-alone subprogram body
17477 -- The annotation must prepare its own template when it is:
17479 -- pragma on subprogram declaration
17481 -- * Globals - Capture of global references must occur after full
17484 -- * Instance - The annotation is instantiated automatically when
17485 -- the related generic subprogram [body] is instantiated except for
17486 -- the "pragma on subprogram declaration" case. In that scenario
17487 -- the annotation must instantiate itself.
17489 when Pragma_Global => Global : declare
17491 Spec_Id : Entity_Id;
17492 Subp_Decl : Node_Id;
17495 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
17499 -- Chain the pragma on the contract for further processing by
17500 -- Analyze_Global_In_Decl_Part.
17502 Add_Contract_Item (N, Spec_Id);
17504 -- Fully analyze the pragma when it appears inside an entry
17505 -- or subprogram body because it cannot benefit from forward
17508 if Nkind_In (Subp_Decl, N_Entry_Body,
17510 N_Subprogram_Body_Stub)
17512 -- The legality checks of pragmas Depends and Global are
17513 -- affected by the SPARK mode in effect and the volatility
17514 -- of the context. In addition these two pragmas are subject
17515 -- to an inherent order:
17520 -- Analyze all these pragmas in the order outlined above
17522 Analyze_If_Present (Pragma_SPARK_Mode);
17523 Analyze_If_Present (Pragma_Volatile_Function);
17524 Analyze_Global_In_Decl_Part (N);
17525 Analyze_If_Present (Pragma_Depends);
17534 -- pragma Ident (static_string_EXPRESSION)
17536 -- Note: pragma Comment shares this processing. Pragma Ident is
17537 -- identical in effect to pragma Commment.
17539 when Pragma_Comment
17547 Check_Arg_Count (1);
17548 Check_No_Identifiers;
17549 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17552 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
17559 GP := Parent (Parent (N));
17561 if Nkind_In (GP, N_Package_Declaration,
17562 N_Generic_Package_Declaration)
17567 -- If we have a compilation unit, then record the ident value,
17568 -- checking for improper duplication.
17570 if Nkind (GP) = N_Compilation_Unit then
17571 CS := Ident_String (Current_Sem_Unit);
17573 if Present (CS) then
17575 -- If we have multiple instances, concatenate them.
17577 Start_String (Strval (CS));
17578 Store_String_Char (' ');
17579 Store_String_Chars (Strval (Str));
17580 Set_Strval (CS, End_String);
17583 Set_Ident_String (Current_Sem_Unit, Str);
17586 -- For subunits, we just ignore the Ident, since in GNAT these
17587 -- are not separate object files, and hence not separate units
17588 -- in the unit table.
17590 elsif Nkind (GP) = N_Subunit then
17596 -------------------
17597 -- Ignore_Pragma --
17598 -------------------
17600 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
17602 -- Entirely handled in the parser, nothing to do here
17604 when Pragma_Ignore_Pragma =>
17607 ----------------------------
17608 -- Implementation_Defined --
17609 ----------------------------
17611 -- pragma Implementation_Defined (LOCAL_NAME);
17613 -- Marks previously declared entity as implementation defined. For
17614 -- an overloaded entity, applies to the most recent homonym.
17616 -- pragma Implementation_Defined;
17618 -- The form with no arguments appears anywhere within a scope, most
17619 -- typically a package spec, and indicates that all entities that are
17620 -- defined within the package spec are Implementation_Defined.
17622 when Pragma_Implementation_Defined => Implementation_Defined : declare
17627 Check_No_Identifiers;
17629 -- Form with no arguments
17631 if Arg_Count = 0 then
17632 Set_Is_Implementation_Defined (Current_Scope);
17634 -- Form with one argument
17637 Check_Arg_Count (1);
17638 Check_Arg_Is_Local_Name (Arg1);
17639 Ent := Entity (Get_Pragma_Arg (Arg1));
17640 Set_Is_Implementation_Defined (Ent);
17642 end Implementation_Defined;
17648 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
17650 -- IMPLEMENTATION_KIND ::=
17651 -- By_Entry | By_Protected_Procedure | By_Any | Optional
17653 -- "By_Any" and "Optional" are treated as synonyms in order to
17654 -- support Ada 2012 aspect Synchronization.
17656 when Pragma_Implemented => Implemented : declare
17657 Proc_Id : Entity_Id;
17662 Check_Arg_Count (2);
17663 Check_No_Identifiers;
17664 Check_Arg_Is_Identifier (Arg1);
17665 Check_Arg_Is_Local_Name (Arg1);
17666 Check_Arg_Is_One_Of (Arg2,
17669 Name_By_Protected_Procedure,
17672 -- Extract the name of the local procedure
17674 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
17676 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
17677 -- primitive procedure of a synchronized tagged type.
17679 if Ekind (Proc_Id) = E_Procedure
17680 and then Is_Primitive (Proc_Id)
17681 and then Present (First_Formal (Proc_Id))
17683 Typ := Etype (First_Formal (Proc_Id));
17685 if Is_Tagged_Type (Typ)
17688 -- Check for a protected, a synchronized or a task interface
17690 ((Is_Interface (Typ)
17691 and then Is_Synchronized_Interface (Typ))
17693 -- Check for a protected type or a task type that implements
17697 (Is_Concurrent_Record_Type (Typ)
17698 and then Present (Interfaces (Typ)))
17700 -- In analysis-only mode, examine original protected type
17703 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
17704 and then Present (Interface_List (Parent (Typ))))
17706 -- Check for a private record extension with keyword
17710 (Ekind_In (Typ, E_Record_Type_With_Private,
17711 E_Record_Subtype_With_Private)
17712 and then Synchronized_Present (Parent (Typ))))
17717 ("controlling formal must be of synchronized tagged type",
17722 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
17723 -- By_Protected_Procedure to the primitive procedure of a task
17726 if Chars (Arg2) = Name_By_Protected_Procedure
17727 and then Is_Interface (Typ)
17728 and then Is_Task_Interface (Typ)
17731 ("implementation kind By_Protected_Procedure cannot be "
17732 & "applied to a task interface primitive", Arg2);
17736 -- Procedures declared inside a protected type must be accepted
17738 elsif Ekind (Proc_Id) = E_Procedure
17739 and then Is_Protected_Type (Scope (Proc_Id))
17743 -- The first argument is not a primitive procedure
17747 ("pragma % must be applied to a primitive procedure", Arg1);
17751 Record_Rep_Item (Proc_Id, N);
17754 ----------------------
17755 -- Implicit_Packing --
17756 ----------------------
17758 -- pragma Implicit_Packing;
17760 when Pragma_Implicit_Packing =>
17762 Check_Arg_Count (0);
17763 Implicit_Packing := True;
17770 -- [Convention =>] convention_IDENTIFIER,
17771 -- [Entity =>] LOCAL_NAME
17772 -- [, [External_Name =>] static_string_EXPRESSION ]
17773 -- [, [Link_Name =>] static_string_EXPRESSION ]);
17775 when Pragma_Import =>
17776 Check_Ada_83_Warning;
17780 Name_External_Name,
17783 Check_At_Least_N_Arguments (2);
17784 Check_At_Most_N_Arguments (4);
17785 Process_Import_Or_Interface;
17787 ---------------------
17788 -- Import_Function --
17789 ---------------------
17791 -- pragma Import_Function (
17792 -- [Internal =>] LOCAL_NAME,
17793 -- [, [External =>] EXTERNAL_SYMBOL]
17794 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17795 -- [, [Result_Type =>] SUBTYPE_MARK]
17796 -- [, [Mechanism =>] MECHANISM]
17797 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
17799 -- EXTERNAL_SYMBOL ::=
17801 -- | static_string_EXPRESSION
17803 -- PARAMETER_TYPES ::=
17805 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17807 -- TYPE_DESIGNATOR ::=
17809 -- | subtype_Name ' Access
17813 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17815 -- MECHANISM_ASSOCIATION ::=
17816 -- [formal_parameter_NAME =>] MECHANISM_NAME
17818 -- MECHANISM_NAME ::=
17822 when Pragma_Import_Function => Import_Function : declare
17823 Args : Args_List (1 .. 6);
17824 Names : constant Name_List (1 .. 6) := (
17827 Name_Parameter_Types,
17830 Name_Result_Mechanism);
17832 Internal : Node_Id renames Args (1);
17833 External : Node_Id renames Args (2);
17834 Parameter_Types : Node_Id renames Args (3);
17835 Result_Type : Node_Id renames Args (4);
17836 Mechanism : Node_Id renames Args (5);
17837 Result_Mechanism : Node_Id renames Args (6);
17841 Gather_Associations (Names, Args);
17842 Process_Extended_Import_Export_Subprogram_Pragma (
17843 Arg_Internal => Internal,
17844 Arg_External => External,
17845 Arg_Parameter_Types => Parameter_Types,
17846 Arg_Result_Type => Result_Type,
17847 Arg_Mechanism => Mechanism,
17848 Arg_Result_Mechanism => Result_Mechanism);
17849 end Import_Function;
17851 -------------------
17852 -- Import_Object --
17853 -------------------
17855 -- pragma Import_Object (
17856 -- [Internal =>] LOCAL_NAME
17857 -- [, [External =>] EXTERNAL_SYMBOL]
17858 -- [, [Size =>] EXTERNAL_SYMBOL]);
17860 -- EXTERNAL_SYMBOL ::=
17862 -- | static_string_EXPRESSION
17864 when Pragma_Import_Object => Import_Object : declare
17865 Args : Args_List (1 .. 3);
17866 Names : constant Name_List (1 .. 3) := (
17871 Internal : Node_Id renames Args (1);
17872 External : Node_Id renames Args (2);
17873 Size : Node_Id renames Args (3);
17877 Gather_Associations (Names, Args);
17878 Process_Extended_Import_Export_Object_Pragma (
17879 Arg_Internal => Internal,
17880 Arg_External => External,
17884 ----------------------
17885 -- Import_Procedure --
17886 ----------------------
17888 -- pragma Import_Procedure (
17889 -- [Internal =>] LOCAL_NAME
17890 -- [, [External =>] EXTERNAL_SYMBOL]
17891 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17892 -- [, [Mechanism =>] MECHANISM]);
17894 -- EXTERNAL_SYMBOL ::=
17896 -- | static_string_EXPRESSION
17898 -- PARAMETER_TYPES ::=
17900 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17902 -- TYPE_DESIGNATOR ::=
17904 -- | subtype_Name ' Access
17908 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17910 -- MECHANISM_ASSOCIATION ::=
17911 -- [formal_parameter_NAME =>] MECHANISM_NAME
17913 -- MECHANISM_NAME ::=
17917 when Pragma_Import_Procedure => Import_Procedure : declare
17918 Args : Args_List (1 .. 4);
17919 Names : constant Name_List (1 .. 4) := (
17922 Name_Parameter_Types,
17925 Internal : Node_Id renames Args (1);
17926 External : Node_Id renames Args (2);
17927 Parameter_Types : Node_Id renames Args (3);
17928 Mechanism : Node_Id renames Args (4);
17932 Gather_Associations (Names, Args);
17933 Process_Extended_Import_Export_Subprogram_Pragma (
17934 Arg_Internal => Internal,
17935 Arg_External => External,
17936 Arg_Parameter_Types => Parameter_Types,
17937 Arg_Mechanism => Mechanism);
17938 end Import_Procedure;
17940 -----------------------------
17941 -- Import_Valued_Procedure --
17942 -----------------------------
17944 -- pragma Import_Valued_Procedure (
17945 -- [Internal =>] LOCAL_NAME
17946 -- [, [External =>] EXTERNAL_SYMBOL]
17947 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17948 -- [, [Mechanism =>] MECHANISM]);
17950 -- EXTERNAL_SYMBOL ::=
17952 -- | static_string_EXPRESSION
17954 -- PARAMETER_TYPES ::=
17956 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17958 -- TYPE_DESIGNATOR ::=
17960 -- | subtype_Name ' Access
17964 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17966 -- MECHANISM_ASSOCIATION ::=
17967 -- [formal_parameter_NAME =>] MECHANISM_NAME
17969 -- MECHANISM_NAME ::=
17973 when Pragma_Import_Valued_Procedure =>
17974 Import_Valued_Procedure : declare
17975 Args : Args_List (1 .. 4);
17976 Names : constant Name_List (1 .. 4) := (
17979 Name_Parameter_Types,
17982 Internal : Node_Id renames Args (1);
17983 External : Node_Id renames Args (2);
17984 Parameter_Types : Node_Id renames Args (3);
17985 Mechanism : Node_Id renames Args (4);
17989 Gather_Associations (Names, Args);
17990 Process_Extended_Import_Export_Subprogram_Pragma (
17991 Arg_Internal => Internal,
17992 Arg_External => External,
17993 Arg_Parameter_Types => Parameter_Types,
17994 Arg_Mechanism => Mechanism);
17995 end Import_Valued_Procedure;
18001 -- pragma Independent (LOCAL_NAME);
18003 when Pragma_Independent =>
18004 Process_Atomic_Independent_Shared_Volatile;
18006 ----------------------------
18007 -- Independent_Components --
18008 ----------------------------
18010 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
18012 when Pragma_Independent_Components => Independent_Components : declare
18019 Check_Ada_83_Warning;
18021 Check_No_Identifiers;
18022 Check_Arg_Count (1);
18023 Check_Arg_Is_Local_Name (Arg1);
18024 E_Id := Get_Pragma_Arg (Arg1);
18026 if Etype (E_Id) = Any_Type then
18030 E := Entity (E_Id);
18032 -- A record type with a self-referential component of anonymous
18033 -- access type is given an incomplete view in order to handle the
18036 -- type Rec is record
18037 -- Self : access Rec;
18043 -- type Ptr is access Rec;
18044 -- type Rec is record
18048 -- Since the incomplete view is now the initial view of the type,
18049 -- the argument of the pragma will reference the incomplete view,
18050 -- but this view is illegal according to the semantics of the
18053 -- Obtain the full view of an internally-generated incomplete type
18054 -- only. This way an attempt to associate the pragma with a source
18055 -- incomplete type is still caught.
18057 if Ekind (E) = E_Incomplete_Type
18058 and then not Comes_From_Source (E)
18059 and then Present (Full_View (E))
18061 E := Full_View (E);
18064 -- A pragma that applies to a Ghost entity becomes Ghost for the
18065 -- purposes of legality checks and removal of ignored Ghost code.
18067 Mark_Ghost_Pragma (N, E);
18069 -- Check duplicate before we chain ourselves
18071 Check_Duplicate_Pragma (E);
18073 -- Check appropriate entity
18075 if Rep_Item_Too_Early (E, N)
18077 Rep_Item_Too_Late (E, N)
18082 D := Declaration_Node (E);
18084 -- The flag is set on the base type, or on the object
18086 if Nkind (D) = N_Full_Type_Declaration
18087 and then (Is_Array_Type (E) or else Is_Record_Type (E))
18089 Set_Has_Independent_Components (Base_Type (E));
18090 Record_Independence_Check (N, Base_Type (E));
18092 -- For record type, set all components independent
18094 if Is_Record_Type (E) then
18095 C := First_Component (E);
18096 while Present (C) loop
18097 Set_Is_Independent (C);
18098 Next_Component (C);
18102 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
18103 and then Nkind (D) = N_Object_Declaration
18104 and then Nkind (Object_Definition (D)) =
18105 N_Constrained_Array_Definition
18107 Set_Has_Independent_Components (E);
18108 Record_Independence_Check (N, E);
18111 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
18113 end Independent_Components;
18115 -----------------------
18116 -- Initial_Condition --
18117 -----------------------
18119 -- pragma Initial_Condition (boolean_EXPRESSION);
18121 -- Characteristics:
18123 -- * Analysis - The annotation undergoes initial checks to verify
18124 -- the legal placement and context. Secondary checks preanalyze the
18127 -- Analyze_Initial_Condition_In_Decl_Part
18129 -- * Expansion - The annotation is expanded during the expansion of
18130 -- the package body whose declaration is subject to the annotation
18133 -- Expand_Pragma_Initial_Condition
18135 -- * Template - The annotation utilizes the generic template of the
18136 -- related package declaration.
18138 -- * Globals - Capture of global references must occur after full
18141 -- * Instance - The annotation is instantiated automatically when
18142 -- the related generic package is instantiated.
18144 when Pragma_Initial_Condition => Initial_Condition : declare
18145 Pack_Decl : Node_Id;
18146 Pack_Id : Entity_Id;
18150 Check_No_Identifiers;
18151 Check_Arg_Count (1);
18153 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
18155 if not Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
18156 N_Package_Declaration)
18162 Pack_Id := Defining_Entity (Pack_Decl);
18164 -- A pragma that applies to a Ghost entity becomes Ghost for the
18165 -- purposes of legality checks and removal of ignored Ghost code.
18167 Mark_Ghost_Pragma (N, Pack_Id);
18169 -- Chain the pragma on the contract for further processing by
18170 -- Analyze_Initial_Condition_In_Decl_Part.
18172 Add_Contract_Item (N, Pack_Id);
18174 -- The legality checks of pragmas Abstract_State, Initializes, and
18175 -- Initial_Condition are affected by the SPARK mode in effect. In
18176 -- addition, these three pragmas are subject to an inherent order:
18178 -- 1) Abstract_State
18180 -- 3) Initial_Condition
18182 -- Analyze all these pragmas in the order outlined above
18184 Analyze_If_Present (Pragma_SPARK_Mode);
18185 Analyze_If_Present (Pragma_Abstract_State);
18186 Analyze_If_Present (Pragma_Initializes);
18187 end Initial_Condition;
18189 ------------------------
18190 -- Initialize_Scalars --
18191 ------------------------
18193 -- pragma Initialize_Scalars
18194 -- [ ( TYPE_VALUE_PAIR {, TYPE_VALUE_PAIR} ) ];
18196 -- TYPE_VALUE_PAIR ::=
18197 -- SCALAR_TYPE => static_EXPRESSION
18203 -- | Long_Long_Flat
18213 when Pragma_Initialize_Scalars => Do_Initialize_Scalars : declare
18214 Seen : array (Scalar_Id) of Node_Id := (others => Empty);
18215 -- This collection holds the individual pairs which specify the
18216 -- invalid values of their respective scalar types.
18218 procedure Analyze_Float_Value
18219 (Scal_Typ : Float_Scalar_Id;
18220 Val_Expr : Node_Id);
18221 -- Analyze a type value pair associated with float type Scal_Typ
18222 -- and expression Val_Expr.
18224 procedure Analyze_Integer_Value
18225 (Scal_Typ : Integer_Scalar_Id;
18226 Val_Expr : Node_Id);
18227 -- Analyze a type value pair associated with integer type Scal_Typ
18228 -- and expression Val_Expr.
18230 procedure Analyze_Type_Value_Pair (Pair : Node_Id);
18231 -- Analyze type value pair Pair
18233 -------------------------
18234 -- Analyze_Float_Value --
18235 -------------------------
18237 procedure Analyze_Float_Value
18238 (Scal_Typ : Float_Scalar_Id;
18239 Val_Expr : Node_Id)
18242 Analyze_And_Resolve (Val_Expr, Any_Real);
18244 if Is_OK_Static_Expression (Val_Expr) then
18245 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value_R (Val_Expr));
18248 Error_Msg_Name_1 := Scal_Typ;
18249 Error_Msg_N ("value for type % must be static", Val_Expr);
18251 end Analyze_Float_Value;
18253 ---------------------------
18254 -- Analyze_Integer_Value --
18255 ---------------------------
18257 procedure Analyze_Integer_Value
18258 (Scal_Typ : Integer_Scalar_Id;
18259 Val_Expr : Node_Id)
18262 Analyze_And_Resolve (Val_Expr, Any_Integer);
18264 if Is_OK_Static_Expression (Val_Expr) then
18265 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value (Val_Expr));
18268 Error_Msg_Name_1 := Scal_Typ;
18269 Error_Msg_N ("value for type % must be static", Val_Expr);
18271 end Analyze_Integer_Value;
18273 -----------------------------
18274 -- Analyze_Type_Value_Pair --
18275 -----------------------------
18277 procedure Analyze_Type_Value_Pair (Pair : Node_Id) is
18278 Scal_Typ : constant Name_Id := Chars (Pair);
18279 Val_Expr : constant Node_Id := Expression (Pair);
18280 Prev_Pair : Node_Id;
18283 if Scal_Typ in Scalar_Id then
18284 Prev_Pair := Seen (Scal_Typ);
18286 -- Prevent multiple attempts to set a value for a scalar
18289 if Present (Prev_Pair) then
18290 Error_Msg_Name_1 := Scal_Typ;
18292 ("cannot specify multiple invalid values for type %",
18295 Error_Msg_Sloc := Sloc (Prev_Pair);
18296 Error_Msg_N ("previous value set #", Pair);
18298 -- Ignore the effects of the pair, but do not halt the
18299 -- analysis of the pragma altogether.
18303 -- Otherwise capture the first pair for this scalar type
18306 Seen (Scal_Typ) := Pair;
18309 if Scal_Typ in Float_Scalar_Id then
18310 Analyze_Float_Value (Scal_Typ, Val_Expr);
18312 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
18313 Analyze_Integer_Value (Scal_Typ, Val_Expr);
18316 -- Otherwise the scalar family is illegal
18319 Error_Msg_Name_1 := Pname;
18321 ("argument of pragma % must denote valid scalar family",
18324 end Analyze_Type_Value_Pair;
18328 Pairs : constant List_Id := Pragma_Argument_Associations (N);
18331 -- Start of processing for Do_Initialize_Scalars
18335 Check_Valid_Configuration_Pragma;
18336 Check_Restriction (No_Initialize_Scalars, N);
18338 -- Ignore the effects of the pragma when No_Initialize_Scalars is
18341 if Restriction_Active (No_Initialize_Scalars) then
18344 -- Initialize_Scalars creates false positives in CodePeer, and
18345 -- incorrect negative results in GNATprove mode, so ignore this
18346 -- pragma in these modes.
18348 elsif CodePeer_Mode or GNATprove_Mode then
18351 -- Otherwise analyze the pragma
18354 if Present (Pairs) then
18356 -- Install Standard in order to provide access to primitive
18357 -- types in case the expressions contain attributes such as
18360 Push_Scope (Standard_Standard);
18362 Pair := First (Pairs);
18363 while Present (Pair) loop
18364 Analyze_Type_Value_Pair (Pair);
18373 Init_Or_Norm_Scalars := True;
18374 Initialize_Scalars := True;
18376 end Do_Initialize_Scalars;
18382 -- pragma Initializes (INITIALIZATION_LIST);
18384 -- INITIALIZATION_LIST ::=
18386 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
18388 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
18393 -- | (INPUT {, INPUT})
18397 -- Characteristics:
18399 -- * Analysis - The annotation undergoes initial checks to verify
18400 -- the legal placement and context. Secondary checks preanalyze the
18403 -- Analyze_Initializes_In_Decl_Part
18405 -- * Expansion - None.
18407 -- * Template - The annotation utilizes the generic template of the
18408 -- related package declaration.
18410 -- * Globals - Capture of global references must occur after full
18413 -- * Instance - The annotation is instantiated automatically when
18414 -- the related generic package is instantiated.
18416 when Pragma_Initializes => Initializes : declare
18417 Pack_Decl : Node_Id;
18418 Pack_Id : Entity_Id;
18422 Check_No_Identifiers;
18423 Check_Arg_Count (1);
18425 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
18427 if not Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
18428 N_Package_Declaration)
18434 Pack_Id := Defining_Entity (Pack_Decl);
18436 -- A pragma that applies to a Ghost entity becomes Ghost for the
18437 -- purposes of legality checks and removal of ignored Ghost code.
18439 Mark_Ghost_Pragma (N, Pack_Id);
18440 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
18442 -- Chain the pragma on the contract for further processing by
18443 -- Analyze_Initializes_In_Decl_Part.
18445 Add_Contract_Item (N, Pack_Id);
18447 -- The legality checks of pragmas Abstract_State, Initializes, and
18448 -- Initial_Condition are affected by the SPARK mode in effect. In
18449 -- addition, these three pragmas are subject to an inherent order:
18451 -- 1) Abstract_State
18453 -- 3) Initial_Condition
18455 -- Analyze all these pragmas in the order outlined above
18457 Analyze_If_Present (Pragma_SPARK_Mode);
18458 Analyze_If_Present (Pragma_Abstract_State);
18459 Analyze_If_Present (Pragma_Initial_Condition);
18466 -- pragma Inline ( NAME {, NAME} );
18468 when Pragma_Inline =>
18470 -- Pragma always active unless in GNATprove mode. It is disabled
18471 -- in GNATprove mode because frontend inlining is applied
18472 -- independently of pragmas Inline and Inline_Always for
18473 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
18476 if not GNATprove_Mode then
18478 -- Inline status is Enabled if option -gnatn is specified.
18479 -- However this status determines only the value of the
18480 -- Is_Inlined flag on the subprogram and does not prevent
18481 -- the pragma itself from being recorded for later use,
18482 -- in particular for a later modification of Is_Inlined
18483 -- independently of the -gnatn option.
18485 -- In other words, if -gnatn is specified for a unit, then
18486 -- all Inline pragmas processed for the compilation of this
18487 -- unit, including those in the spec of other units, are
18488 -- activated, so subprograms will be inlined across units.
18490 -- If -gnatn is not specified, no Inline pragma is activated
18491 -- here, which means that subprograms will not be inlined
18492 -- across units. The Is_Inlined flag will nevertheless be
18493 -- set later when bodies are analyzed, so subprograms will
18494 -- be inlined within the unit.
18496 if Inline_Active then
18497 Process_Inline (Enabled);
18499 Process_Inline (Disabled);
18503 -------------------
18504 -- Inline_Always --
18505 -------------------
18507 -- pragma Inline_Always ( NAME {, NAME} );
18509 when Pragma_Inline_Always =>
18512 -- Pragma always active unless in CodePeer mode or GNATprove
18513 -- mode. It is disabled in CodePeer mode because inlining is
18514 -- not helpful, and enabling it caused walk order issues. It
18515 -- is disabled in GNATprove mode because frontend inlining is
18516 -- applied independently of pragmas Inline and Inline_Always for
18517 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
18520 if not CodePeer_Mode and not GNATprove_Mode then
18521 Process_Inline (Enabled);
18524 --------------------
18525 -- Inline_Generic --
18526 --------------------
18528 -- pragma Inline_Generic (NAME {, NAME});
18530 when Pragma_Inline_Generic =>
18532 Process_Generic_List;
18534 ----------------------
18535 -- Inspection_Point --
18536 ----------------------
18538 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
18540 when Pragma_Inspection_Point => Inspection_Point : declare
18547 if Arg_Count > 0 then
18550 Exp := Get_Pragma_Arg (Arg);
18553 if not Is_Entity_Name (Exp)
18554 or else not Is_Object (Entity (Exp))
18556 Error_Pragma_Arg ("object name required", Arg);
18560 exit when No (Arg);
18563 end Inspection_Point;
18569 -- pragma Interface (
18570 -- [ Convention =>] convention_IDENTIFIER,
18571 -- [ Entity =>] LOCAL_NAME
18572 -- [, [External_Name =>] static_string_EXPRESSION ]
18573 -- [, [Link_Name =>] static_string_EXPRESSION ]);
18575 when Pragma_Interface =>
18580 Name_External_Name,
18582 Check_At_Least_N_Arguments (2);
18583 Check_At_Most_N_Arguments (4);
18584 Process_Import_Or_Interface;
18586 -- In Ada 2005, the permission to use Interface (a reserved word)
18587 -- as a pragma name is considered an obsolescent feature, and this
18588 -- pragma was already obsolescent in Ada 95.
18590 if Ada_Version >= Ada_95 then
18592 (No_Obsolescent_Features, Pragma_Identifier (N));
18594 if Warn_On_Obsolescent_Feature then
18596 ("pragma Interface is an obsolescent feature?j?", N);
18598 ("|use pragma Import instead?j?", N);
18602 --------------------
18603 -- Interface_Name --
18604 --------------------
18606 -- pragma Interface_Name (
18607 -- [ Entity =>] LOCAL_NAME
18608 -- [,[External_Name =>] static_string_EXPRESSION ]
18609 -- [,[Link_Name =>] static_string_EXPRESSION ]);
18611 when Pragma_Interface_Name => Interface_Name : declare
18613 Def_Id : Entity_Id;
18614 Hom_Id : Entity_Id;
18620 ((Name_Entity, Name_External_Name, Name_Link_Name));
18621 Check_At_Least_N_Arguments (2);
18622 Check_At_Most_N_Arguments (3);
18623 Id := Get_Pragma_Arg (Arg1);
18626 -- This is obsolete from Ada 95 on, but it is an implementation
18627 -- defined pragma, so we do not consider that it violates the
18628 -- restriction (No_Obsolescent_Features).
18630 if Ada_Version >= Ada_95 then
18631 if Warn_On_Obsolescent_Feature then
18633 ("pragma Interface_Name is an obsolescent feature?j?", N);
18635 ("|use pragma Import instead?j?", N);
18639 if not Is_Entity_Name (Id) then
18641 ("first argument for pragma% must be entity name", Arg1);
18642 elsif Etype (Id) = Any_Type then
18645 Def_Id := Entity (Id);
18648 -- Special DEC-compatible processing for the object case, forces
18649 -- object to be imported.
18651 if Ekind (Def_Id) = E_Variable then
18652 Kill_Size_Check_Code (Def_Id);
18653 Note_Possible_Modification (Id, Sure => False);
18655 -- Initialization is not allowed for imported variable
18657 if Present (Expression (Parent (Def_Id)))
18658 and then Comes_From_Source (Expression (Parent (Def_Id)))
18660 Error_Msg_Sloc := Sloc (Def_Id);
18662 ("no initialization allowed for declaration of& #",
18666 -- For compatibility, support VADS usage of providing both
18667 -- pragmas Interface and Interface_Name to obtain the effect
18668 -- of a single Import pragma.
18670 if Is_Imported (Def_Id)
18671 and then Present (First_Rep_Item (Def_Id))
18672 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
18673 and then Pragma_Name (First_Rep_Item (Def_Id)) =
18678 Set_Imported (Def_Id);
18681 Set_Is_Public (Def_Id);
18682 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
18685 -- Otherwise must be subprogram
18687 elsif not Is_Subprogram (Def_Id) then
18689 ("argument of pragma% is not subprogram", Arg1);
18692 Check_At_Most_N_Arguments (3);
18696 -- Loop through homonyms
18699 Def_Id := Get_Base_Subprogram (Hom_Id);
18701 if Is_Imported (Def_Id) then
18702 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
18706 exit when From_Aspect_Specification (N);
18707 Hom_Id := Homonym (Hom_Id);
18709 exit when No (Hom_Id)
18710 or else Scope (Hom_Id) /= Current_Scope;
18715 ("argument of pragma% is not imported subprogram",
18719 end Interface_Name;
18721 -----------------------
18722 -- Interrupt_Handler --
18723 -----------------------
18725 -- pragma Interrupt_Handler (handler_NAME);
18727 when Pragma_Interrupt_Handler =>
18728 Check_Ada_83_Warning;
18729 Check_Arg_Count (1);
18730 Check_No_Identifiers;
18732 if No_Run_Time_Mode then
18733 Error_Msg_CRT ("Interrupt_Handler pragma", N);
18735 Check_Interrupt_Or_Attach_Handler;
18736 Process_Interrupt_Or_Attach_Handler;
18739 ------------------------
18740 -- Interrupt_Priority --
18741 ------------------------
18743 -- pragma Interrupt_Priority [(EXPRESSION)];
18745 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
18746 P : constant Node_Id := Parent (N);
18751 Check_Ada_83_Warning;
18753 if Arg_Count /= 0 then
18754 Arg := Get_Pragma_Arg (Arg1);
18755 Check_Arg_Count (1);
18756 Check_No_Identifiers;
18758 -- The expression must be analyzed in the special manner
18759 -- described in "Handling of Default and Per-Object
18760 -- Expressions" in sem.ads.
18762 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
18765 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
18770 Ent := Defining_Identifier (Parent (P));
18772 -- Check duplicate pragma before we chain the pragma in the Rep
18773 -- Item chain of Ent.
18775 Check_Duplicate_Pragma (Ent);
18776 Record_Rep_Item (Ent, N);
18778 -- Check the No_Task_At_Interrupt_Priority restriction
18780 if Nkind (P) = N_Task_Definition then
18781 Check_Restriction (No_Task_At_Interrupt_Priority, N);
18784 end Interrupt_Priority;
18786 ---------------------
18787 -- Interrupt_State --
18788 ---------------------
18790 -- pragma Interrupt_State (
18791 -- [Name =>] INTERRUPT_ID,
18792 -- [State =>] INTERRUPT_STATE);
18794 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
18795 -- INTERRUPT_STATE => System | Runtime | User
18797 -- Note: if the interrupt id is given as an identifier, then it must
18798 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
18799 -- given as a static integer expression which must be in the range of
18800 -- Ada.Interrupts.Interrupt_ID.
18802 when Pragma_Interrupt_State => Interrupt_State : declare
18803 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
18804 -- This is the entity Ada.Interrupts.Interrupt_ID;
18806 State_Type : Character;
18807 -- Set to 's'/'r'/'u' for System/Runtime/User
18810 -- Index to entry in Interrupt_States table
18813 -- Value of interrupt
18815 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
18816 -- The first argument to the pragma
18818 Int_Ent : Entity_Id;
18819 -- Interrupt entity in Ada.Interrupts.Names
18823 Check_Arg_Order ((Name_Name, Name_State));
18824 Check_Arg_Count (2);
18826 Check_Optional_Identifier (Arg1, Name_Name);
18827 Check_Optional_Identifier (Arg2, Name_State);
18828 Check_Arg_Is_Identifier (Arg2);
18830 -- First argument is identifier
18832 if Nkind (Arg1X) = N_Identifier then
18834 -- Search list of names in Ada.Interrupts.Names
18836 Int_Ent := First_Entity (RTE (RE_Names));
18838 if No (Int_Ent) then
18839 Error_Pragma_Arg ("invalid interrupt name", Arg1);
18841 elsif Chars (Int_Ent) = Chars (Arg1X) then
18842 Int_Val := Expr_Value (Constant_Value (Int_Ent));
18846 Next_Entity (Int_Ent);
18849 -- First argument is not an identifier, so it must be a static
18850 -- expression of type Ada.Interrupts.Interrupt_ID.
18853 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
18854 Int_Val := Expr_Value (Arg1X);
18856 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
18858 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
18861 ("value not in range of type "
18862 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
18868 case Chars (Get_Pragma_Arg (Arg2)) is
18869 when Name_Runtime => State_Type := 'r';
18870 when Name_System => State_Type := 's';
18871 when Name_User => State_Type := 'u';
18874 Error_Pragma_Arg ("invalid interrupt state", Arg2);
18877 -- Check if entry is already stored
18879 IST_Num := Interrupt_States.First;
18881 -- If entry not found, add it
18883 if IST_Num > Interrupt_States.Last then
18884 Interrupt_States.Append
18885 ((Interrupt_Number => UI_To_Int (Int_Val),
18886 Interrupt_State => State_Type,
18887 Pragma_Loc => Loc));
18890 -- Case of entry for the same entry
18892 elsif Int_Val = Interrupt_States.Table (IST_Num).
18895 -- If state matches, done, no need to make redundant entry
18898 State_Type = Interrupt_States.Table (IST_Num).
18901 -- Otherwise if state does not match, error
18904 Interrupt_States.Table (IST_Num).Pragma_Loc;
18906 ("state conflicts with that given #", Arg2);
18910 IST_Num := IST_Num + 1;
18912 end Interrupt_State;
18918 -- pragma Invariant
18919 -- ([Entity =>] type_LOCAL_NAME,
18920 -- [Check =>] EXPRESSION
18921 -- [,[Message =>] String_Expression]);
18923 when Pragma_Invariant => Invariant : declare
18930 Check_At_Least_N_Arguments (2);
18931 Check_At_Most_N_Arguments (3);
18932 Check_Optional_Identifier (Arg1, Name_Entity);
18933 Check_Optional_Identifier (Arg2, Name_Check);
18935 if Arg_Count = 3 then
18936 Check_Optional_Identifier (Arg3, Name_Message);
18937 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
18940 Check_Arg_Is_Local_Name (Arg1);
18942 Typ_Arg := Get_Pragma_Arg (Arg1);
18943 Find_Type (Typ_Arg);
18944 Typ := Entity (Typ_Arg);
18946 -- Nothing to do of the related type is erroneous in some way
18948 if Typ = Any_Type then
18951 -- AI12-0041: Invariants are allowed in interface types
18953 elsif Is_Interface (Typ) then
18956 -- An invariant must apply to a private type, or appear in the
18957 -- private part of a package spec and apply to a completion.
18958 -- a class-wide invariant can only appear on a private declaration
18959 -- or private extension, not a completion.
18961 -- A [class-wide] invariant may be associated a [limited] private
18962 -- type or a private extension.
18964 elsif Ekind_In (Typ, E_Limited_Private_Type,
18966 E_Record_Type_With_Private)
18970 -- A non-class-wide invariant may be associated with the full view
18971 -- of a [limited] private type or a private extension.
18973 elsif Has_Private_Declaration (Typ)
18974 and then not Class_Present (N)
18978 -- A class-wide invariant may appear on the partial view only
18980 elsif Class_Present (N) then
18982 ("pragma % only allowed for private type", Arg1);
18985 -- A regular invariant may appear on both views
18989 ("pragma % only allowed for private type or corresponding "
18990 & "full view", Arg1);
18994 -- An invariant associated with an abstract type (this includes
18995 -- interfaces) must be class-wide.
18997 if Is_Abstract_Type (Typ) and then not Class_Present (N) then
18999 ("pragma % not allowed for abstract type", Arg1);
19003 -- A pragma that applies to a Ghost entity becomes Ghost for the
19004 -- purposes of legality checks and removal of ignored Ghost code.
19006 Mark_Ghost_Pragma (N, Typ);
19008 -- The pragma defines a type-specific invariant, the type is said
19009 -- to have invariants of its "own".
19011 Set_Has_Own_Invariants (Typ);
19013 -- Set the Invariants_Ignored flag if that policy is in effect
19015 Set_Invariants_Ignored (Typ,
19016 Present (Check_Policy_List)
19018 (Policy_In_Effect (Name_Invariant) = Name_Ignore
19020 Policy_In_Effect (Name_Type_Invariant) = Name_Ignore));
19022 -- If the invariant is class-wide, then it can be inherited by
19023 -- derived or interface implementing types. The type is said to
19024 -- have "inheritable" invariants.
19026 if Class_Present (N) then
19027 Set_Has_Inheritable_Invariants (Typ);
19030 -- Chain the pragma on to the rep item chain, for processing when
19031 -- the type is frozen.
19033 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
19035 -- Create the declaration of the invariant procedure that will
19036 -- verify the invariant at run time. Interfaces are treated as the
19037 -- partial view of a private type in order to achieve uniformity
19038 -- with the general case. As a result, an interface receives only
19039 -- a "partial" invariant procedure, which is never called.
19041 Build_Invariant_Procedure_Declaration
19043 Partial_Invariant => Is_Interface (Typ));
19050 -- pragma Keep_Names ([On => ] LOCAL_NAME);
19052 when Pragma_Keep_Names => Keep_Names : declare
19057 Check_Arg_Count (1);
19058 Check_Optional_Identifier (Arg1, Name_On);
19059 Check_Arg_Is_Local_Name (Arg1);
19061 Arg := Get_Pragma_Arg (Arg1);
19064 if Etype (Arg) = Any_Type then
19068 if not Is_Entity_Name (Arg)
19069 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
19072 ("pragma% requires a local enumeration type", Arg1);
19075 Set_Discard_Names (Entity (Arg), False);
19082 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
19084 when Pragma_License =>
19087 -- Do not analyze pragma any further in CodePeer mode, to avoid
19088 -- extraneous errors in this implementation-dependent pragma,
19089 -- which has a different profile on other compilers.
19091 if CodePeer_Mode then
19095 Check_Arg_Count (1);
19096 Check_No_Identifiers;
19097 Check_Valid_Configuration_Pragma;
19098 Check_Arg_Is_Identifier (Arg1);
19101 Sind : constant Source_File_Index :=
19102 Source_Index (Current_Sem_Unit);
19105 case Chars (Get_Pragma_Arg (Arg1)) is
19107 Set_License (Sind, GPL);
19109 when Name_Modified_GPL =>
19110 Set_License (Sind, Modified_GPL);
19112 when Name_Restricted =>
19113 Set_License (Sind, Restricted);
19115 when Name_Unrestricted =>
19116 Set_License (Sind, Unrestricted);
19119 Error_Pragma_Arg ("invalid license name", Arg1);
19127 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
19129 when Pragma_Link_With => Link_With : declare
19135 if Operating_Mode = Generate_Code
19136 and then In_Extended_Main_Source_Unit (N)
19138 Check_At_Least_N_Arguments (1);
19139 Check_No_Identifiers;
19140 Check_Is_In_Decl_Part_Or_Package_Spec;
19141 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
19145 while Present (Arg) loop
19146 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
19148 -- Store argument, converting sequences of spaces to a
19149 -- single null character (this is one of the differences
19150 -- in processing between Link_With and Linker_Options).
19152 Arg_Store : declare
19153 C : constant Char_Code := Get_Char_Code (' ');
19154 S : constant String_Id :=
19155 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
19156 L : constant Nat := String_Length (S);
19159 procedure Skip_Spaces;
19160 -- Advance F past any spaces
19166 procedure Skip_Spaces is
19168 while F <= L and then Get_String_Char (S, F) = C loop
19173 -- Start of processing for Arg_Store
19176 Skip_Spaces; -- skip leading spaces
19178 -- Loop through characters, changing any embedded
19179 -- sequence of spaces to a single null character (this
19180 -- is how Link_With/Linker_Options differ)
19183 if Get_String_Char (S, F) = C then
19186 Store_String_Char (ASCII.NUL);
19189 Store_String_Char (Get_String_Char (S, F));
19197 if Present (Arg) then
19198 Store_String_Char (ASCII.NUL);
19202 Store_Linker_Option_String (End_String);
19210 -- pragma Linker_Alias (
19211 -- [Entity =>] LOCAL_NAME
19212 -- [Target =>] static_string_EXPRESSION);
19214 when Pragma_Linker_Alias =>
19216 Check_Arg_Order ((Name_Entity, Name_Target));
19217 Check_Arg_Count (2);
19218 Check_Optional_Identifier (Arg1, Name_Entity);
19219 Check_Optional_Identifier (Arg2, Name_Target);
19220 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19221 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
19223 -- The only processing required is to link this item on to the
19224 -- list of rep items for the given entity. This is accomplished
19225 -- by the call to Rep_Item_Too_Late (when no error is detected
19226 -- and False is returned).
19228 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
19231 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
19234 ------------------------
19235 -- Linker_Constructor --
19236 ------------------------
19238 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
19240 -- Code is shared with Linker_Destructor
19242 -----------------------
19243 -- Linker_Destructor --
19244 -----------------------
19246 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
19248 when Pragma_Linker_Constructor
19249 | Pragma_Linker_Destructor
19251 Linker_Constructor : declare
19257 Check_Arg_Count (1);
19258 Check_No_Identifiers;
19259 Check_Arg_Is_Local_Name (Arg1);
19260 Arg1_X := Get_Pragma_Arg (Arg1);
19262 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
19264 if not Is_Library_Level_Entity (Proc) then
19266 ("argument for pragma% must be library level entity", Arg1);
19269 -- The only processing required is to link this item on to the
19270 -- list of rep items for the given entity. This is accomplished
19271 -- by the call to Rep_Item_Too_Late (when no error is detected
19272 -- and False is returned).
19274 if Rep_Item_Too_Late (Proc, N) then
19277 Set_Has_Gigi_Rep_Item (Proc);
19279 end Linker_Constructor;
19281 --------------------
19282 -- Linker_Options --
19283 --------------------
19285 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
19287 when Pragma_Linker_Options => Linker_Options : declare
19291 Check_Ada_83_Warning;
19292 Check_No_Identifiers;
19293 Check_Arg_Count (1);
19294 Check_Is_In_Decl_Part_Or_Package_Spec;
19295 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
19296 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
19299 while Present (Arg) loop
19300 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
19301 Store_String_Char (ASCII.NUL);
19303 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
19307 if Operating_Mode = Generate_Code
19308 and then In_Extended_Main_Source_Unit (N)
19310 Store_Linker_Option_String (End_String);
19312 end Linker_Options;
19314 --------------------
19315 -- Linker_Section --
19316 --------------------
19318 -- pragma Linker_Section (
19319 -- [Entity =>] LOCAL_NAME
19320 -- [Section =>] static_string_EXPRESSION);
19322 when Pragma_Linker_Section => Linker_Section : declare
19327 Ghost_Error_Posted : Boolean := False;
19328 -- Flag set when an error concerning the illegal mix of Ghost and
19329 -- non-Ghost subprograms is emitted.
19331 Ghost_Id : Entity_Id := Empty;
19332 -- The entity of the first Ghost subprogram encountered while
19333 -- processing the arguments of the pragma.
19337 Check_Arg_Order ((Name_Entity, Name_Section));
19338 Check_Arg_Count (2);
19339 Check_Optional_Identifier (Arg1, Name_Entity);
19340 Check_Optional_Identifier (Arg2, Name_Section);
19341 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19342 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
19344 -- Check kind of entity
19346 Arg := Get_Pragma_Arg (Arg1);
19347 Ent := Entity (Arg);
19349 case Ekind (Ent) is
19351 -- Objects (constants and variables) and types. For these cases
19352 -- all we need to do is to set the Linker_Section_pragma field,
19353 -- checking that we do not have a duplicate.
19359 LPE := Linker_Section_Pragma (Ent);
19361 if Present (LPE) then
19362 Error_Msg_Sloc := Sloc (LPE);
19364 ("Linker_Section already specified for &#", Arg1, Ent);
19367 Set_Linker_Section_Pragma (Ent, N);
19369 -- A pragma that applies to a Ghost entity becomes Ghost for
19370 -- the purposes of legality checks and removal of ignored
19373 Mark_Ghost_Pragma (N, Ent);
19377 when Subprogram_Kind =>
19379 -- Aspect case, entity already set
19381 if From_Aspect_Specification (N) then
19382 Set_Linker_Section_Pragma
19383 (Entity (Corresponding_Aspect (N)), N);
19385 -- Propagate it to its ultimate aliased entity to
19386 -- facilitate the backend processing this attribute
19387 -- in instantiations of generic subprograms.
19389 if Present (Alias (Entity (Corresponding_Aspect (N))))
19391 Set_Linker_Section_Pragma
19393 (Entity (Corresponding_Aspect (N))), N);
19396 -- Pragma case, we must climb the homonym chain, but skip
19397 -- any for which the linker section is already set.
19401 if No (Linker_Section_Pragma (Ent)) then
19402 Set_Linker_Section_Pragma (Ent, N);
19404 -- Propagate it to its ultimate aliased entity to
19405 -- facilitate the backend processing this attribute
19406 -- in instantiations of generic subprograms.
19408 if Present (Alias (Ent)) then
19409 Set_Linker_Section_Pragma
19410 (Ultimate_Alias (Ent), N);
19413 -- A pragma that applies to a Ghost entity becomes
19414 -- Ghost for the purposes of legality checks and
19415 -- removal of ignored Ghost code.
19417 Mark_Ghost_Pragma (N, Ent);
19419 -- Capture the entity of the first Ghost subprogram
19420 -- being processed for error detection purposes.
19422 if Is_Ghost_Entity (Ent) then
19423 if No (Ghost_Id) then
19427 -- Otherwise the subprogram is non-Ghost. It is
19428 -- illegal to mix references to Ghost and non-Ghost
19429 -- entities (SPARK RM 6.9).
19431 elsif Present (Ghost_Id)
19432 and then not Ghost_Error_Posted
19434 Ghost_Error_Posted := True;
19436 Error_Msg_Name_1 := Pname;
19438 ("pragma % cannot mention ghost and "
19439 & "non-ghost subprograms", N);
19441 Error_Msg_Sloc := Sloc (Ghost_Id);
19443 ("\& # declared as ghost", N, Ghost_Id);
19445 Error_Msg_Sloc := Sloc (Ent);
19447 ("\& # declared as non-ghost", N, Ent);
19451 Ent := Homonym (Ent);
19453 or else Scope (Ent) /= Current_Scope;
19457 -- All other cases are illegal
19461 ("pragma% applies only to objects, subprograms, and types",
19464 end Linker_Section;
19470 -- pragma List (On | Off)
19472 -- There is nothing to do here, since we did all the processing for
19473 -- this pragma in Par.Prag (so that it works properly even in syntax
19476 when Pragma_List =>
19483 -- pragma Lock_Free [(Boolean_EXPRESSION)];
19485 when Pragma_Lock_Free => Lock_Free : declare
19486 P : constant Node_Id := Parent (N);
19492 Check_No_Identifiers;
19493 Check_At_Most_N_Arguments (1);
19495 -- Protected definition case
19497 if Nkind (P) = N_Protected_Definition then
19498 Ent := Defining_Identifier (Parent (P));
19502 if Arg_Count = 1 then
19503 Arg := Get_Pragma_Arg (Arg1);
19504 Val := Is_True (Static_Boolean (Arg));
19506 -- No arguments (expression is considered to be True)
19512 -- Check duplicate pragma before we chain the pragma in the Rep
19513 -- Item chain of Ent.
19515 Check_Duplicate_Pragma (Ent);
19516 Record_Rep_Item (Ent, N);
19517 Set_Uses_Lock_Free (Ent, Val);
19519 -- Anything else is incorrect placement
19526 --------------------
19527 -- Locking_Policy --
19528 --------------------
19530 -- pragma Locking_Policy (policy_IDENTIFIER);
19532 when Pragma_Locking_Policy => declare
19533 subtype LP_Range is Name_Id
19534 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
19539 Check_Ada_83_Warning;
19540 Check_Arg_Count (1);
19541 Check_No_Identifiers;
19542 Check_Arg_Is_Locking_Policy (Arg1);
19543 Check_Valid_Configuration_Pragma;
19544 LP_Val := Chars (Get_Pragma_Arg (Arg1));
19547 when Name_Ceiling_Locking => LP := 'C';
19548 when Name_Concurrent_Readers_Locking => LP := 'R';
19549 when Name_Inheritance_Locking => LP := 'I';
19552 if Locking_Policy /= ' '
19553 and then Locking_Policy /= LP
19555 Error_Msg_Sloc := Locking_Policy_Sloc;
19556 Error_Pragma ("locking policy incompatible with policy#");
19558 -- Set new policy, but always preserve System_Location since we
19559 -- like the error message with the run time name.
19562 Locking_Policy := LP;
19564 if Locking_Policy_Sloc /= System_Location then
19565 Locking_Policy_Sloc := Loc;
19570 -------------------
19571 -- Loop_Optimize --
19572 -------------------
19574 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
19576 -- OPTIMIZATION_HINT ::=
19577 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
19579 when Pragma_Loop_Optimize => Loop_Optimize : declare
19584 Check_At_Least_N_Arguments (1);
19585 Check_No_Identifiers;
19587 Hint := First (Pragma_Argument_Associations (N));
19588 while Present (Hint) loop
19589 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
19597 Check_Loop_Pragma_Placement;
19604 -- pragma Loop_Variant
19605 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
19607 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
19609 -- CHANGE_DIRECTION ::= Increases | Decreases
19611 when Pragma_Loop_Variant => Loop_Variant : declare
19616 Check_At_Least_N_Arguments (1);
19617 Check_Loop_Pragma_Placement;
19619 -- Process all increasing / decreasing expressions
19621 Variant := First (Pragma_Argument_Associations (N));
19622 while Present (Variant) loop
19623 if Chars (Variant) = No_Name then
19624 Error_Pragma_Arg_Ident ("expect name `Increases`", Variant);
19626 elsif not Nam_In (Chars (Variant), Name_Decreases,
19630 Name : String := Get_Name_String (Chars (Variant));
19633 -- It is a common mistake to write "Increasing" for
19634 -- "Increases" or "Decreasing" for "Decreases". Recognize
19635 -- specially names starting with "incr" or "decr" to
19636 -- suggest the corresponding name.
19638 System.Case_Util.To_Lower (Name);
19640 if Name'Length >= 4
19641 and then Name (1 .. 4) = "incr"
19643 Error_Pragma_Arg_Ident
19644 ("expect name `Increases`", Variant);
19646 elsif Name'Length >= 4
19647 and then Name (1 .. 4) = "decr"
19649 Error_Pragma_Arg_Ident
19650 ("expect name `Decreases`", Variant);
19653 Error_Pragma_Arg_Ident
19654 ("expect name `Increases` or `Decreases`", Variant);
19659 Preanalyze_Assert_Expression
19660 (Expression (Variant), Any_Discrete);
19666 -----------------------
19667 -- Machine_Attribute --
19668 -----------------------
19670 -- pragma Machine_Attribute (
19671 -- [Entity =>] LOCAL_NAME,
19672 -- [Attribute_Name =>] static_string_EXPRESSION
19673 -- [, [Info =>] static_EXPRESSION {, static_EXPRESSION}] );
19675 when Pragma_Machine_Attribute => Machine_Attribute : declare
19677 Def_Id : Entity_Id;
19681 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
19683 if Arg_Count >= 3 then
19684 Check_Optional_Identifier (Arg3, Name_Info);
19686 while Present (Arg) loop
19687 Check_Arg_Is_OK_Static_Expression (Arg);
19691 Check_Arg_Count (2);
19694 Check_Optional_Identifier (Arg1, Name_Entity);
19695 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
19696 Check_Arg_Is_Local_Name (Arg1);
19697 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
19698 Def_Id := Entity (Get_Pragma_Arg (Arg1));
19700 if Is_Access_Type (Def_Id) then
19701 Def_Id := Designated_Type (Def_Id);
19704 if Rep_Item_Too_Early (Def_Id, N) then
19708 Def_Id := Underlying_Type (Def_Id);
19710 -- The only processing required is to link this item on to the
19711 -- list of rep items for the given entity. This is accomplished
19712 -- by the call to Rep_Item_Too_Late (when no error is detected
19713 -- and False is returned).
19715 if Rep_Item_Too_Late (Def_Id, N) then
19718 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
19720 end Machine_Attribute;
19727 -- (MAIN_OPTION [, MAIN_OPTION]);
19730 -- [STACK_SIZE =>] static_integer_EXPRESSION
19731 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
19732 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
19734 when Pragma_Main => Main : declare
19735 Args : Args_List (1 .. 3);
19736 Names : constant Name_List (1 .. 3) := (
19738 Name_Task_Stack_Size_Default,
19739 Name_Time_Slicing_Enabled);
19745 Gather_Associations (Names, Args);
19747 for J in 1 .. 2 loop
19748 if Present (Args (J)) then
19749 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
19753 if Present (Args (3)) then
19754 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
19758 while Present (Nod) loop
19759 if Nkind (Nod) = N_Pragma
19760 and then Pragma_Name (Nod) = Name_Main
19762 Error_Msg_Name_1 := Pname;
19763 Error_Msg_N ("duplicate pragma% not permitted", Nod);
19774 -- pragma Main_Storage
19775 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
19777 -- MAIN_STORAGE_OPTION ::=
19778 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
19779 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
19781 when Pragma_Main_Storage => Main_Storage : declare
19782 Args : Args_List (1 .. 2);
19783 Names : constant Name_List (1 .. 2) := (
19784 Name_Working_Storage,
19791 Gather_Associations (Names, Args);
19793 for J in 1 .. 2 loop
19794 if Present (Args (J)) then
19795 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
19799 Check_In_Main_Program;
19802 while Present (Nod) loop
19803 if Nkind (Nod) = N_Pragma
19804 and then Pragma_Name (Nod) = Name_Main_Storage
19806 Error_Msg_Name_1 := Pname;
19807 Error_Msg_N ("duplicate pragma% not permitted", Nod);
19814 ----------------------------
19815 -- Max_Entry_Queue_Length --
19816 ----------------------------
19818 -- pragma Max_Entry_Queue_Length (static_integer_EXPRESSION);
19820 -- This processing is shared by Pragma_Max_Entry_Queue_Depth and
19821 -- Pragma_Max_Queue_Length.
19823 when Pragma_Max_Entry_Queue_Length
19824 | Pragma_Max_Entry_Queue_Depth
19825 | Pragma_Max_Queue_Length
19827 Max_Entry_Queue_Length : declare
19829 Entry_Decl : Node_Id;
19830 Entry_Id : Entity_Id;
19834 if Prag_Id = Pragma_Max_Entry_Queue_Depth
19835 or else Prag_Id = Pragma_Max_Queue_Length
19840 Check_Arg_Count (1);
19843 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
19845 -- Entry declaration
19847 if Nkind (Entry_Decl) = N_Entry_Declaration then
19849 -- Entry illegally within a task
19851 if Nkind (Parent (N)) = N_Task_Definition then
19852 Error_Pragma ("pragma % cannot apply to task entries");
19856 Entry_Id := Defining_Entity (Entry_Decl);
19858 -- Otherwise the pragma is associated with an illegal construct
19861 Error_Pragma ("pragma % must apply to a protected entry");
19865 -- Mark the pragma as Ghost if the related subprogram is also
19866 -- Ghost. This also ensures that any expansion performed further
19867 -- below will produce Ghost nodes.
19869 Mark_Ghost_Pragma (N, Entry_Id);
19871 -- Analyze the Integer expression
19873 Arg := Get_Pragma_Arg (Arg1);
19874 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
19876 Val := Expr_Value (Arg);
19880 ("argument for pragma% cannot be less than -1", Arg1);
19882 elsif not UI_Is_In_Int_Range (Val) then
19884 ("argument for pragma% out of range of Integer", Arg1);
19888 Record_Rep_Item (Entry_Id, N);
19889 end Max_Entry_Queue_Length;
19895 -- pragma Memory_Size (NUMERIC_LITERAL)
19897 when Pragma_Memory_Size =>
19900 -- Memory size is simply ignored
19902 Check_No_Identifiers;
19903 Check_Arg_Count (1);
19904 Check_Arg_Is_Integer_Literal (Arg1);
19912 -- The only correct use of this pragma is on its own in a file, in
19913 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
19914 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
19915 -- check for a file containing nothing but a No_Body pragma). If we
19916 -- attempt to process it during normal semantics processing, it means
19917 -- it was misplaced.
19919 when Pragma_No_Body =>
19923 -----------------------------
19924 -- No_Elaboration_Code_All --
19925 -----------------------------
19927 -- pragma No_Elaboration_Code_All;
19929 when Pragma_No_Elaboration_Code_All =>
19931 Check_Valid_Library_Unit_Pragma;
19933 if Nkind (N) = N_Null_Statement then
19937 -- Must appear for a spec or generic spec
19939 if not Nkind_In (Unit (Cunit (Current_Sem_Unit)),
19940 N_Generic_Package_Declaration,
19941 N_Generic_Subprogram_Declaration,
19942 N_Package_Declaration,
19943 N_Subprogram_Declaration)
19947 ("pragma% can only occur for package "
19948 & "or subprogram spec"));
19951 -- Set flag in unit table
19953 Set_No_Elab_Code_All (Current_Sem_Unit);
19955 -- Set restriction No_Elaboration_Code if this is the main unit
19957 if Current_Sem_Unit = Main_Unit then
19958 Set_Restriction (No_Elaboration_Code, N);
19961 -- If we are in the main unit or in an extended main source unit,
19962 -- then we also add it to the configuration restrictions so that
19963 -- it will apply to all units in the extended main source.
19965 if Current_Sem_Unit = Main_Unit
19966 or else In_Extended_Main_Source_Unit (N)
19968 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
19971 -- If in main extended unit, activate transitive with test
19973 if In_Extended_Main_Source_Unit (N) then
19974 Opt.No_Elab_Code_All_Pragma := N;
19977 -----------------------------
19978 -- No_Component_Reordering --
19979 -----------------------------
19981 -- pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)];
19983 when Pragma_No_Component_Reordering => No_Comp_Reordering : declare
19989 Check_At_Most_N_Arguments (1);
19991 if Arg_Count = 0 then
19992 Check_Valid_Configuration_Pragma;
19993 Opt.No_Component_Reordering := True;
19996 Check_Optional_Identifier (Arg2, Name_Entity);
19997 Check_Arg_Is_Local_Name (Arg1);
19998 E_Id := Get_Pragma_Arg (Arg1);
20000 if Etype (E_Id) = Any_Type then
20004 E := Entity (E_Id);
20006 if not Is_Record_Type (E) then
20007 Error_Pragma_Arg ("pragma% requires record type", Arg1);
20010 Set_No_Reordering (Base_Type (E));
20012 end No_Comp_Reordering;
20014 --------------------------
20015 -- No_Heap_Finalization --
20016 --------------------------
20018 -- pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ];
20020 when Pragma_No_Heap_Finalization => No_Heap_Finalization : declare
20021 Context : constant Node_Id := Parent (N);
20022 Typ_Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
20028 Check_No_Identifiers;
20030 -- The pragma appears in a configuration file
20032 if No (Context) then
20033 Check_Arg_Count (0);
20034 Check_Valid_Configuration_Pragma;
20036 -- Detect a duplicate pragma
20038 if Present (No_Heap_Finalization_Pragma) then
20041 Prev => No_Heap_Finalization_Pragma);
20045 No_Heap_Finalization_Pragma := N;
20047 -- Otherwise the pragma should be associated with a library-level
20048 -- named access-to-object type.
20051 Check_Arg_Count (1);
20052 Check_Arg_Is_Local_Name (Arg1);
20054 Find_Type (Typ_Arg);
20055 Typ := Entity (Typ_Arg);
20057 -- The type being subjected to the pragma is erroneous
20059 if Typ = Any_Type then
20060 Error_Pragma ("cannot find type referenced by pragma %");
20062 -- The pragma is applied to an incomplete or generic formal
20063 -- type way too early.
20065 elsif Rep_Item_Too_Early (Typ, N) then
20069 Typ := Underlying_Type (Typ);
20072 -- The pragma must apply to an access-to-object type
20074 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type) then
20077 -- Give a detailed error message on all other access type kinds
20079 elsif Ekind (Typ) = E_Access_Protected_Subprogram_Type then
20081 ("pragma % cannot apply to access protected subprogram "
20084 elsif Ekind (Typ) = E_Access_Subprogram_Type then
20086 ("pragma % cannot apply to access subprogram type");
20088 elsif Is_Anonymous_Access_Type (Typ) then
20090 ("pragma % cannot apply to anonymous access type");
20092 -- Give a general error message in case the pragma applies to a
20093 -- non-access type.
20097 ("pragma % must apply to library level access type");
20100 -- At this point the argument denotes an access-to-object type.
20101 -- Ensure that the type is declared at the library level.
20103 if Is_Library_Level_Entity (Typ) then
20106 -- Quietly ignore an access-to-object type originally declared
20107 -- at the library level within a generic, but instantiated at
20108 -- a non-library level. As a result the access-to-object type
20109 -- "loses" its No_Heap_Finalization property.
20111 elsif In_Instance then
20116 ("pragma % must apply to library level access type");
20119 -- Detect a duplicate pragma
20121 if Present (No_Heap_Finalization_Pragma) then
20124 Prev => No_Heap_Finalization_Pragma);
20128 Prev := Get_Pragma (Typ, Pragma_No_Heap_Finalization);
20130 if Present (Prev) then
20138 Record_Rep_Item (Typ, N);
20140 end No_Heap_Finalization;
20146 -- pragma No_Inline ( NAME {, NAME} );
20148 when Pragma_No_Inline =>
20150 Process_Inline (Suppressed);
20156 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
20158 when Pragma_No_Return => No_Return : declare
20164 Ghost_Error_Posted : Boolean := False;
20165 -- Flag set when an error concerning the illegal mix of Ghost and
20166 -- non-Ghost subprograms is emitted.
20168 Ghost_Id : Entity_Id := Empty;
20169 -- The entity of the first Ghost procedure encountered while
20170 -- processing the arguments of the pragma.
20174 Check_At_Least_N_Arguments (1);
20176 -- Loop through arguments of pragma
20179 while Present (Arg) loop
20180 Check_Arg_Is_Local_Name (Arg);
20181 Id := Get_Pragma_Arg (Arg);
20184 if not Is_Entity_Name (Id) then
20185 Error_Pragma_Arg ("entity name required", Arg);
20188 if Etype (Id) = Any_Type then
20192 -- Loop to find matching procedures
20198 and then Scope (E) = Current_Scope
20200 if Ekind_In (E, E_Generic_Procedure, E_Procedure) then
20202 -- Check that the pragma is not applied to a body.
20203 -- First check the specless body case, to give a
20204 -- different error message. These checks do not apply
20205 -- if Relaxed_RM_Semantics, to accommodate other Ada
20206 -- compilers. Disable these checks under -gnatd.J.
20208 if not Debug_Flag_Dot_JJ then
20209 if Nkind (Parent (Declaration_Node (E))) =
20211 and then not Relaxed_RM_Semantics
20214 ("pragma% requires separate spec and must come "
20218 -- Now the "specful" body case
20220 if Rep_Item_Too_Late (E, N) then
20227 -- A pragma that applies to a Ghost entity becomes Ghost
20228 -- for the purposes of legality checks and removal of
20229 -- ignored Ghost code.
20231 Mark_Ghost_Pragma (N, E);
20233 -- Capture the entity of the first Ghost procedure being
20234 -- processed for error detection purposes.
20236 if Is_Ghost_Entity (E) then
20237 if No (Ghost_Id) then
20241 -- Otherwise the subprogram is non-Ghost. It is illegal
20242 -- to mix references to Ghost and non-Ghost entities
20245 elsif Present (Ghost_Id)
20246 and then not Ghost_Error_Posted
20248 Ghost_Error_Posted := True;
20250 Error_Msg_Name_1 := Pname;
20252 ("pragma % cannot mention ghost and non-ghost "
20253 & "procedures", N);
20255 Error_Msg_Sloc := Sloc (Ghost_Id);
20256 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
20258 Error_Msg_Sloc := Sloc (E);
20259 Error_Msg_NE ("\& # declared as non-ghost", N, E);
20262 -- Set flag on any alias as well
20264 if Is_Overloadable (E) and then Present (Alias (E)) then
20265 Set_No_Return (Alias (E));
20271 exit when From_Aspect_Specification (N);
20275 -- If entity in not in current scope it may be the enclosing
20276 -- suprogram body to which the aspect applies.
20279 if Entity (Id) = Current_Scope
20280 and then From_Aspect_Specification (N)
20282 Set_No_Return (Entity (Id));
20284 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
20296 -- pragma No_Run_Time;
20298 -- Note: this pragma is retained for backwards compatibility. See
20299 -- body of Rtsfind for full details on its handling.
20301 when Pragma_No_Run_Time =>
20303 Check_Valid_Configuration_Pragma;
20304 Check_Arg_Count (0);
20306 -- Remove backward compatibility if Build_Type is FSF or GPL and
20307 -- generate a warning.
20310 Ignore : constant Boolean := Build_Type in FSF .. GPL;
20313 Error_Pragma ("pragma% is ignored, has no effect??");
20315 No_Run_Time_Mode := True;
20316 Configurable_Run_Time_Mode := True;
20318 -- Set Duration to 32 bits if word size is 32
20320 if Ttypes.System_Word_Size = 32 then
20321 Duration_32_Bits_On_Target := True;
20324 -- Set appropriate restrictions
20326 Set_Restriction (No_Finalization, N);
20327 Set_Restriction (No_Exception_Handlers, N);
20328 Set_Restriction (Max_Tasks, N, 0);
20329 Set_Restriction (No_Tasking, N);
20333 -----------------------
20334 -- No_Tagged_Streams --
20335 -----------------------
20337 -- pragma No_Tagged_Streams [([Entity => ]tagged_type_local_NAME)];
20339 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
20345 Check_At_Most_N_Arguments (1);
20347 -- One argument case
20349 if Arg_Count = 1 then
20350 Check_Optional_Identifier (Arg1, Name_Entity);
20351 Check_Arg_Is_Local_Name (Arg1);
20352 E_Id := Get_Pragma_Arg (Arg1);
20354 if Etype (E_Id) = Any_Type then
20358 E := Entity (E_Id);
20360 Check_Duplicate_Pragma (E);
20362 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
20364 ("argument for pragma% must be root tagged type", Arg1);
20367 if Rep_Item_Too_Early (E, N)
20369 Rep_Item_Too_Late (E, N)
20373 Set_No_Tagged_Streams_Pragma (E, N);
20376 -- Zero argument case
20379 Check_Is_In_Decl_Part_Or_Package_Spec;
20380 No_Tagged_Streams := N;
20382 end No_Tagged_Strms;
20384 ------------------------
20385 -- No_Strict_Aliasing --
20386 ------------------------
20388 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
20390 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
20396 Check_At_Most_N_Arguments (1);
20398 if Arg_Count = 0 then
20399 Check_Valid_Configuration_Pragma;
20400 Opt.No_Strict_Aliasing := True;
20403 Check_Optional_Identifier (Arg2, Name_Entity);
20404 Check_Arg_Is_Local_Name (Arg1);
20405 E_Id := Get_Pragma_Arg (Arg1);
20407 if Etype (E_Id) = Any_Type then
20411 E := Entity (E_Id);
20413 if not Is_Access_Type (E) then
20414 Error_Pragma_Arg ("pragma% requires access type", Arg1);
20417 Set_No_Strict_Aliasing (Base_Type (E));
20419 end No_Strict_Aliasing;
20421 -----------------------
20422 -- Normalize_Scalars --
20423 -----------------------
20425 -- pragma Normalize_Scalars;
20427 when Pragma_Normalize_Scalars =>
20428 Check_Ada_83_Warning;
20429 Check_Arg_Count (0);
20430 Check_Valid_Configuration_Pragma;
20432 -- Normalize_Scalars creates false positives in CodePeer, and
20433 -- incorrect negative results in GNATprove mode, so ignore this
20434 -- pragma in these modes.
20436 if not (CodePeer_Mode or GNATprove_Mode) then
20437 Normalize_Scalars := True;
20438 Init_Or_Norm_Scalars := True;
20445 -- pragma Obsolescent;
20447 -- pragma Obsolescent (
20448 -- [Message =>] static_string_EXPRESSION
20449 -- [,[Version =>] Ada_05]]);
20451 -- pragma Obsolescent (
20452 -- [Entity =>] NAME
20453 -- [,[Message =>] static_string_EXPRESSION
20454 -- [,[Version =>] Ada_05]] );
20456 when Pragma_Obsolescent => Obsolescent : declare
20460 procedure Set_Obsolescent (E : Entity_Id);
20461 -- Given an entity Ent, mark it as obsolescent if appropriate
20463 ---------------------
20464 -- Set_Obsolescent --
20465 ---------------------
20467 procedure Set_Obsolescent (E : Entity_Id) is
20476 -- A pragma that applies to a Ghost entity becomes Ghost for
20477 -- the purposes of legality checks and removal of ignored Ghost
20480 Mark_Ghost_Pragma (N, E);
20482 -- Entity name was given
20484 if Present (Ename) then
20486 -- If entity name matches, we are fine.
20488 if Chars (Ename) = Chars (Ent) then
20489 Set_Entity (Ename, Ent);
20490 Generate_Reference (Ent, Ename);
20492 -- If entity name does not match, only possibility is an
20493 -- enumeration literal from an enumeration type declaration.
20495 elsif Ekind (Ent) /= E_Enumeration_Type then
20497 ("pragma % entity name does not match declaration");
20500 Ent := First_Literal (E);
20504 ("pragma % entity name does not match any "
20505 & "enumeration literal");
20507 elsif Chars (Ent) = Chars (Ename) then
20508 Set_Entity (Ename, Ent);
20509 Generate_Reference (Ent, Ename);
20513 Next_Literal (Ent);
20519 -- Ent points to entity to be marked
20521 if Arg_Count >= 1 then
20523 -- Deal with static string argument
20525 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
20526 S := Strval (Get_Pragma_Arg (Arg1));
20528 for J in 1 .. String_Length (S) loop
20529 if not In_Character_Range (Get_String_Char (S, J)) then
20531 ("pragma% argument does not allow wide characters",
20536 Obsolescent_Warnings.Append
20537 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
20539 -- Check for Ada_05 parameter
20541 if Arg_Count /= 1 then
20542 Check_Arg_Count (2);
20545 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
20548 Check_Arg_Is_Identifier (Argx);
20550 if Chars (Argx) /= Name_Ada_05 then
20551 Error_Msg_Name_2 := Name_Ada_05;
20553 ("only allowed argument for pragma% is %", Argx);
20556 if Ada_Version_Explicit < Ada_2005
20557 or else not Warn_On_Ada_2005_Compatibility
20565 -- Set flag if pragma active
20568 Set_Is_Obsolescent (Ent);
20572 end Set_Obsolescent;
20574 -- Start of processing for pragma Obsolescent
20579 Check_At_Most_N_Arguments (3);
20581 -- See if first argument specifies an entity name
20585 (Chars (Arg1) = Name_Entity
20587 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
20589 N_Operator_Symbol))
20591 Ename := Get_Pragma_Arg (Arg1);
20593 -- Eliminate first argument, so we can share processing
20597 Arg_Count := Arg_Count - 1;
20599 -- No Entity name argument given
20605 if Arg_Count >= 1 then
20606 Check_Optional_Identifier (Arg1, Name_Message);
20608 if Arg_Count = 2 then
20609 Check_Optional_Identifier (Arg2, Name_Version);
20613 -- Get immediately preceding declaration
20616 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
20620 -- Cases where we do not follow anything other than another pragma
20624 -- First case: library level compilation unit declaration with
20625 -- the pragma immediately following the declaration.
20627 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
20629 (Defining_Entity (Unit (Parent (Parent (N)))));
20632 -- Case 2: library unit placement for package
20636 Ent : constant Entity_Id := Find_Lib_Unit_Name;
20638 if Is_Package_Or_Generic_Package (Ent) then
20639 Set_Obsolescent (Ent);
20645 -- Cases where we must follow a declaration, including an
20646 -- abstract subprogram declaration, which is not in the
20647 -- other node subtypes.
20650 if Nkind (Decl) not in N_Declaration
20651 and then Nkind (Decl) not in N_Later_Decl_Item
20652 and then Nkind (Decl) not in N_Generic_Declaration
20653 and then Nkind (Decl) not in N_Renaming_Declaration
20654 and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration
20657 ("pragma% misplaced, "
20658 & "must immediately follow a declaration");
20661 Set_Obsolescent (Defining_Entity (Decl));
20671 -- pragma Optimize (Time | Space | Off);
20673 -- The actual check for optimize is done in Gigi. Note that this
20674 -- pragma does not actually change the optimization setting, it
20675 -- simply checks that it is consistent with the pragma.
20677 when Pragma_Optimize =>
20678 Check_No_Identifiers;
20679 Check_Arg_Count (1);
20680 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
20682 ------------------------
20683 -- Optimize_Alignment --
20684 ------------------------
20686 -- pragma Optimize_Alignment (Time | Space | Off);
20688 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
20690 Check_No_Identifiers;
20691 Check_Arg_Count (1);
20692 Check_Valid_Configuration_Pragma;
20695 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
20698 when Name_Off => Opt.Optimize_Alignment := 'O';
20699 when Name_Space => Opt.Optimize_Alignment := 'S';
20700 when Name_Time => Opt.Optimize_Alignment := 'T';
20703 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
20707 -- Set indication that mode is set locally. If we are in fact in a
20708 -- configuration pragma file, this setting is harmless since the
20709 -- switch will get reset anyway at the start of each unit.
20711 Optimize_Alignment_Local := True;
20712 end Optimize_Alignment;
20718 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
20720 when Pragma_Ordered => Ordered : declare
20721 Assoc : constant Node_Id := Arg1;
20727 Check_No_Identifiers;
20728 Check_Arg_Count (1);
20729 Check_Arg_Is_Local_Name (Arg1);
20731 Type_Id := Get_Pragma_Arg (Assoc);
20732 Find_Type (Type_Id);
20733 Typ := Entity (Type_Id);
20735 if Typ = Any_Type then
20738 Typ := Underlying_Type (Typ);
20741 if not Is_Enumeration_Type (Typ) then
20742 Error_Pragma ("pragma% must specify enumeration type");
20745 Check_First_Subtype (Arg1);
20746 Set_Has_Pragma_Ordered (Base_Type (Typ));
20749 -------------------
20750 -- Overflow_Mode --
20751 -------------------
20753 -- pragma Overflow_Mode
20754 -- ([General => ] MODE [, [Assertions => ] MODE]);
20756 -- MODE := STRICT | MINIMIZED | ELIMINATED
20758 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
20759 -- since System.Bignums makes this assumption. This is true of nearly
20760 -- all (all?) targets.
20762 when Pragma_Overflow_Mode => Overflow_Mode : declare
20763 function Get_Overflow_Mode
20765 Arg : Node_Id) return Overflow_Mode_Type;
20766 -- Function to process one pragma argument, Arg. If an identifier
20767 -- is present, it must be Name. Mode type is returned if a valid
20768 -- argument exists, otherwise an error is signalled.
20770 -----------------------
20771 -- Get_Overflow_Mode --
20772 -----------------------
20774 function Get_Overflow_Mode
20776 Arg : Node_Id) return Overflow_Mode_Type
20778 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
20781 Check_Optional_Identifier (Arg, Name);
20782 Check_Arg_Is_Identifier (Argx);
20784 if Chars (Argx) = Name_Strict then
20787 elsif Chars (Argx) = Name_Minimized then
20790 elsif Chars (Argx) = Name_Eliminated then
20791 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
20793 ("Eliminated not implemented on this target", Argx);
20799 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
20801 end Get_Overflow_Mode;
20803 -- Start of processing for Overflow_Mode
20807 Check_At_Least_N_Arguments (1);
20808 Check_At_Most_N_Arguments (2);
20810 -- Process first argument
20812 Scope_Suppress.Overflow_Mode_General :=
20813 Get_Overflow_Mode (Name_General, Arg1);
20815 -- Case of only one argument
20817 if Arg_Count = 1 then
20818 Scope_Suppress.Overflow_Mode_Assertions :=
20819 Scope_Suppress.Overflow_Mode_General;
20821 -- Case of two arguments present
20824 Scope_Suppress.Overflow_Mode_Assertions :=
20825 Get_Overflow_Mode (Name_Assertions, Arg2);
20829 --------------------------
20830 -- Overriding Renamings --
20831 --------------------------
20833 -- pragma Overriding_Renamings;
20835 when Pragma_Overriding_Renamings =>
20837 Check_Arg_Count (0);
20838 Check_Valid_Configuration_Pragma;
20839 Overriding_Renamings := True;
20845 -- pragma Pack (first_subtype_LOCAL_NAME);
20847 when Pragma_Pack => Pack : declare
20848 Assoc : constant Node_Id := Arg1;
20850 Ignore : Boolean := False;
20855 Check_No_Identifiers;
20856 Check_Arg_Count (1);
20857 Check_Arg_Is_Local_Name (Arg1);
20858 Type_Id := Get_Pragma_Arg (Assoc);
20860 if not Is_Entity_Name (Type_Id)
20861 or else not Is_Type (Entity (Type_Id))
20864 ("argument for pragma% must be type or subtype", Arg1);
20867 Find_Type (Type_Id);
20868 Typ := Entity (Type_Id);
20871 or else Rep_Item_Too_Early (Typ, N)
20875 Typ := Underlying_Type (Typ);
20878 -- A pragma that applies to a Ghost entity becomes Ghost for the
20879 -- purposes of legality checks and removal of ignored Ghost code.
20881 Mark_Ghost_Pragma (N, Typ);
20883 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
20884 Error_Pragma ("pragma% must specify array or record type");
20887 Check_First_Subtype (Arg1);
20888 Check_Duplicate_Pragma (Typ);
20892 if Is_Array_Type (Typ) then
20893 Ctyp := Component_Type (Typ);
20895 -- Ignore pack that does nothing
20897 if Known_Static_Esize (Ctyp)
20898 and then Known_Static_RM_Size (Ctyp)
20899 and then Esize (Ctyp) = RM_Size (Ctyp)
20900 and then Addressable (Esize (Ctyp))
20905 -- Process OK pragma Pack. Note that if there is a separate
20906 -- component clause present, the Pack will be cancelled. This
20907 -- processing is in Freeze.
20909 if not Rep_Item_Too_Late (Typ, N) then
20911 -- In CodePeer mode, we do not need complex front-end
20912 -- expansions related to pragma Pack, so disable handling
20915 if CodePeer_Mode then
20918 -- Normal case where we do the pack action
20922 Set_Is_Packed (Base_Type (Typ));
20923 Set_Has_Non_Standard_Rep (Base_Type (Typ));
20926 Set_Has_Pragma_Pack (Base_Type (Typ));
20930 -- For record types, the pack is always effective
20932 else pragma Assert (Is_Record_Type (Typ));
20933 if not Rep_Item_Too_Late (Typ, N) then
20934 Set_Is_Packed (Base_Type (Typ));
20935 Set_Has_Pragma_Pack (Base_Type (Typ));
20936 Set_Has_Non_Standard_Rep (Base_Type (Typ));
20947 -- There is nothing to do here, since we did all the processing for
20948 -- this pragma in Par.Prag (so that it works properly even in syntax
20951 when Pragma_Page =>
20958 -- pragma Part_Of (ABSTRACT_STATE);
20960 -- ABSTRACT_STATE ::= NAME
20962 when Pragma_Part_Of => Part_Of : declare
20963 procedure Propagate_Part_Of
20964 (Pack_Id : Entity_Id;
20965 State_Id : Entity_Id;
20966 Instance : Node_Id);
20967 -- Propagate the Part_Of indicator to all abstract states and
20968 -- objects declared in the visible state space of a package
20969 -- denoted by Pack_Id. State_Id is the encapsulating state.
20970 -- Instance is the package instantiation node.
20972 -----------------------
20973 -- Propagate_Part_Of --
20974 -----------------------
20976 procedure Propagate_Part_Of
20977 (Pack_Id : Entity_Id;
20978 State_Id : Entity_Id;
20979 Instance : Node_Id)
20981 Has_Item : Boolean := False;
20982 -- Flag set when the visible state space contains at least one
20983 -- abstract state or variable.
20985 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
20986 -- Propagate the Part_Of indicator to all abstract states and
20987 -- objects declared in the visible state space of a package
20988 -- denoted by Pack_Id.
20990 -----------------------
20991 -- Propagate_Part_Of --
20992 -----------------------
20994 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
20995 Constits : Elist_Id;
20996 Item_Id : Entity_Id;
20999 -- Traverse the entity chain of the package and set relevant
21000 -- attributes of abstract states and objects declared in the
21001 -- visible state space of the package.
21003 Item_Id := First_Entity (Pack_Id);
21004 while Present (Item_Id)
21005 and then not In_Private_Part (Item_Id)
21007 -- Do not consider internally generated items
21009 if not Comes_From_Source (Item_Id) then
21012 -- Do not consider generic formals or their corresponding
21013 -- actuals because they are not part of a visible state.
21014 -- Note that both entities are marked as hidden.
21016 elsif Is_Hidden (Item_Id) then
21019 -- The Part_Of indicator turns an abstract state or an
21020 -- object into a constituent of the encapsulating state.
21021 -- Note that constants are considered here even though
21022 -- they may not depend on variable input. This check is
21023 -- left to the SPARK prover.
21025 elsif Ekind_In (Item_Id, E_Abstract_State,
21030 Constits := Part_Of_Constituents (State_Id);
21032 if No (Constits) then
21033 Constits := New_Elmt_List;
21034 Set_Part_Of_Constituents (State_Id, Constits);
21037 Append_Elmt (Item_Id, Constits);
21038 Set_Encapsulating_State (Item_Id, State_Id);
21040 -- Recursively handle nested packages and instantiations
21042 elsif Ekind (Item_Id) = E_Package then
21043 Propagate_Part_Of (Item_Id);
21046 Next_Entity (Item_Id);
21048 end Propagate_Part_Of;
21050 -- Start of processing for Propagate_Part_Of
21053 Propagate_Part_Of (Pack_Id);
21055 -- Detect a package instantiation that is subject to a Part_Of
21056 -- indicator, but has no visible state.
21058 if not Has_Item then
21060 ("package instantiation & has Part_Of indicator but "
21061 & "lacks visible state", Instance, Pack_Id);
21063 end Propagate_Part_Of;
21067 Constits : Elist_Id;
21069 Encap_Id : Entity_Id;
21070 Item_Id : Entity_Id;
21074 -- Start of processing for Part_Of
21078 Check_No_Identifiers;
21079 Check_Arg_Count (1);
21081 Stmt := Find_Related_Context (N, Do_Checks => True);
21083 -- Object declaration
21085 if Nkind (Stmt) = N_Object_Declaration then
21088 -- Package instantiation
21090 elsif Nkind (Stmt) = N_Package_Instantiation then
21093 -- Single concurrent type declaration
21095 elsif Is_Single_Concurrent_Type_Declaration (Stmt) then
21098 -- Otherwise the pragma is associated with an illegal construct
21105 -- Extract the entity of the related object declaration or package
21106 -- instantiation. In the case of the instantiation, use the entity
21107 -- of the instance spec.
21109 if Nkind (Stmt) = N_Package_Instantiation then
21110 Stmt := Instance_Spec (Stmt);
21113 Item_Id := Defining_Entity (Stmt);
21115 -- A pragma that applies to a Ghost entity becomes Ghost for the
21116 -- purposes of legality checks and removal of ignored Ghost code.
21118 Mark_Ghost_Pragma (N, Item_Id);
21120 -- Chain the pragma on the contract for further processing by
21121 -- Analyze_Part_Of_In_Decl_Part or for completeness.
21123 Add_Contract_Item (N, Item_Id);
21125 -- A variable may act as constituent of a single concurrent type
21126 -- which in turn could be declared after the variable. Due to this
21127 -- discrepancy, the full analysis of indicator Part_Of is delayed
21128 -- until the end of the enclosing declarative region (see routine
21129 -- Analyze_Part_Of_In_Decl_Part).
21131 if Ekind (Item_Id) = E_Variable then
21134 -- Otherwise indicator Part_Of applies to a constant or a package
21138 Encap := Get_Pragma_Arg (Arg1);
21140 -- Detect any discrepancies between the placement of the
21141 -- constant or package instantiation with respect to state
21142 -- space and the encapsulating state.
21146 Item_Id => Item_Id,
21148 Encap_Id => Encap_Id,
21152 pragma Assert (Present (Encap_Id));
21154 if Ekind (Item_Id) = E_Constant then
21155 Constits := Part_Of_Constituents (Encap_Id);
21157 if No (Constits) then
21158 Constits := New_Elmt_List;
21159 Set_Part_Of_Constituents (Encap_Id, Constits);
21162 Append_Elmt (Item_Id, Constits);
21163 Set_Encapsulating_State (Item_Id, Encap_Id);
21165 -- Propagate the Part_Of indicator to the visible state
21166 -- space of the package instantiation.
21170 (Pack_Id => Item_Id,
21171 State_Id => Encap_Id,
21178 ----------------------------------
21179 -- Partition_Elaboration_Policy --
21180 ----------------------------------
21182 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
21184 when Pragma_Partition_Elaboration_Policy => PEP : declare
21185 subtype PEP_Range is Name_Id
21186 range First_Partition_Elaboration_Policy_Name
21187 .. Last_Partition_Elaboration_Policy_Name;
21188 PEP_Val : PEP_Range;
21193 Check_Arg_Count (1);
21194 Check_No_Identifiers;
21195 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
21196 Check_Valid_Configuration_Pragma;
21197 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
21200 when Name_Concurrent => PEP := 'C';
21201 when Name_Sequential => PEP := 'S';
21204 if Partition_Elaboration_Policy /= ' '
21205 and then Partition_Elaboration_Policy /= PEP
21207 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
21209 ("partition elaboration policy incompatible with policy#");
21211 -- Set new policy, but always preserve System_Location since we
21212 -- like the error message with the run time name.
21215 Partition_Elaboration_Policy := PEP;
21217 if Partition_Elaboration_Policy_Sloc /= System_Location then
21218 Partition_Elaboration_Policy_Sloc := Loc;
21227 -- pragma Passive [(PASSIVE_FORM)];
21229 -- PASSIVE_FORM ::= Semaphore | No
21231 when Pragma_Passive =>
21234 if Nkind (Parent (N)) /= N_Task_Definition then
21235 Error_Pragma ("pragma% must be within task definition");
21238 if Arg_Count /= 0 then
21239 Check_Arg_Count (1);
21240 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
21243 ----------------------------------
21244 -- Preelaborable_Initialization --
21245 ----------------------------------
21247 -- pragma Preelaborable_Initialization (DIRECT_NAME);
21249 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
21254 Check_Arg_Count (1);
21255 Check_No_Identifiers;
21256 Check_Arg_Is_Identifier (Arg1);
21257 Check_Arg_Is_Local_Name (Arg1);
21258 Check_First_Subtype (Arg1);
21259 Ent := Entity (Get_Pragma_Arg (Arg1));
21261 -- A pragma that applies to a Ghost entity becomes Ghost for the
21262 -- purposes of legality checks and removal of ignored Ghost code.
21264 Mark_Ghost_Pragma (N, Ent);
21266 -- The pragma may come from an aspect on a private declaration,
21267 -- even if the freeze point at which this is analyzed in the
21268 -- private part after the full view.
21270 if Has_Private_Declaration (Ent)
21271 and then From_Aspect_Specification (N)
21275 -- Check appropriate type argument
21277 elsif Is_Private_Type (Ent)
21278 or else Is_Protected_Type (Ent)
21279 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
21281 -- AI05-0028: The pragma applies to all composite types. Note
21282 -- that we apply this binding interpretation to earlier versions
21283 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
21284 -- choice since there are other compilers that do the same.
21286 or else Is_Composite_Type (Ent)
21292 ("pragma % can only be applied to private, formal derived, "
21293 & "protected, or composite type", Arg1);
21296 -- Give an error if the pragma is applied to a protected type that
21297 -- does not qualify (due to having entries, or due to components
21298 -- that do not qualify).
21300 if Is_Protected_Type (Ent)
21301 and then not Has_Preelaborable_Initialization (Ent)
21304 ("protected type & does not have preelaborable "
21305 & "initialization", Ent);
21307 -- Otherwise mark the type as definitely having preelaborable
21311 Set_Known_To_Have_Preelab_Init (Ent);
21314 if Has_Pragma_Preelab_Init (Ent)
21315 and then Warn_On_Redundant_Constructs
21317 Error_Pragma ("?r?duplicate pragma%!");
21319 Set_Has_Pragma_Preelab_Init (Ent);
21323 --------------------
21324 -- Persistent_BSS --
21325 --------------------
21327 -- pragma Persistent_BSS [(object_NAME)];
21329 when Pragma_Persistent_BSS => Persistent_BSS : declare
21336 Check_At_Most_N_Arguments (1);
21338 -- Case of application to specific object (one argument)
21340 if Arg_Count = 1 then
21341 Check_Arg_Is_Library_Level_Local_Name (Arg1);
21343 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
21345 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
21348 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
21351 Ent := Entity (Get_Pragma_Arg (Arg1));
21353 -- A pragma that applies to a Ghost entity becomes Ghost for
21354 -- the purposes of legality checks and removal of ignored Ghost
21357 Mark_Ghost_Pragma (N, Ent);
21359 -- Check for duplication before inserting in list of
21360 -- representation items.
21362 Check_Duplicate_Pragma (Ent);
21364 if Rep_Item_Too_Late (Ent, N) then
21368 Decl := Parent (Ent);
21370 if Present (Expression (Decl)) then
21371 -- Variables in Persistent_BSS cannot be initialized, so
21372 -- turn off any initialization that might be caused by
21373 -- pragmas Initialize_Scalars or Normalize_Scalars.
21375 if Kill_Range_Check (Expression (Decl)) then
21378 Name_Suppress_Initialization,
21379 Pragma_Argument_Associations => New_List (
21380 Make_Pragma_Argument_Association (Loc,
21381 Expression => New_Occurrence_Of (Ent, Loc))));
21382 Insert_Before (N, Prag);
21387 ("object for pragma% cannot have initialization", Arg1);
21391 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
21393 ("object type for pragma% is not potentially persistent",
21398 Make_Linker_Section_Pragma
21399 (Ent, Loc, ".persistent.bss");
21400 Insert_After (N, Prag);
21403 -- Case of use as configuration pragma with no arguments
21406 Check_Valid_Configuration_Pragma;
21407 Persistent_BSS_Mode := True;
21409 end Persistent_BSS;
21411 --------------------
21412 -- Rename_Pragma --
21413 --------------------
21415 -- pragma Rename_Pragma (
21416 -- [New_Name =>] IDENTIFIER,
21417 -- [Renamed =>] pragma_IDENTIFIER);
21419 when Pragma_Rename_Pragma => Rename_Pragma : declare
21420 New_Name : constant Node_Id := Get_Pragma_Arg (Arg1);
21421 Old_Name : constant Node_Id := Get_Pragma_Arg (Arg2);
21425 Check_Valid_Configuration_Pragma;
21426 Check_Arg_Count (2);
21427 Check_Optional_Identifier (Arg1, Name_New_Name);
21428 Check_Optional_Identifier (Arg2, Name_Renamed);
21430 if Nkind (New_Name) /= N_Identifier then
21431 Error_Pragma_Arg ("identifier expected", Arg1);
21434 if Nkind (Old_Name) /= N_Identifier then
21435 Error_Pragma_Arg ("identifier expected", Arg2);
21438 -- The New_Name arg should not be an existing pragma (but we allow
21439 -- it; it's just a warning). The Old_Name arg must be an existing
21442 if Is_Pragma_Name (Chars (New_Name)) then
21443 Error_Pragma_Arg ("??pragma is already defined", Arg1);
21446 if not Is_Pragma_Name (Chars (Old_Name)) then
21447 Error_Pragma_Arg ("existing pragma name expected", Arg1);
21450 Map_Pragma_Name (From => Chars (New_Name), To => Chars (Old_Name));
21457 -- pragma Polling (ON | OFF);
21459 when Pragma_Polling =>
21461 Check_Arg_Count (1);
21462 Check_No_Identifiers;
21463 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
21464 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
21466 -----------------------------------
21467 -- Post/Post_Class/Postcondition --
21468 -----------------------------------
21470 -- pragma Post (Boolean_EXPRESSION);
21471 -- pragma Post_Class (Boolean_EXPRESSION);
21472 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
21473 -- [,[Message =>] String_EXPRESSION]);
21475 -- Characteristics:
21477 -- * Analysis - The annotation undergoes initial checks to verify
21478 -- the legal placement and context. Secondary checks preanalyze the
21481 -- Analyze_Pre_Post_Condition_In_Decl_Part
21483 -- * Expansion - The annotation is expanded during the expansion of
21484 -- the related subprogram [body] contract as performed in:
21486 -- Expand_Subprogram_Contract
21488 -- * Template - The annotation utilizes the generic template of the
21489 -- related subprogram [body] when it is:
21491 -- aspect on subprogram declaration
21492 -- aspect on stand-alone subprogram body
21493 -- pragma on stand-alone subprogram body
21495 -- The annotation must prepare its own template when it is:
21497 -- pragma on subprogram declaration
21499 -- * Globals - Capture of global references must occur after full
21502 -- * Instance - The annotation is instantiated automatically when
21503 -- the related generic subprogram [body] is instantiated except for
21504 -- the "pragma on subprogram declaration" case. In that scenario
21505 -- the annotation must instantiate itself.
21508 | Pragma_Post_Class
21509 | Pragma_Postcondition
21511 Analyze_Pre_Post_Condition;
21513 --------------------------------
21514 -- Pre/Pre_Class/Precondition --
21515 --------------------------------
21517 -- pragma Pre (Boolean_EXPRESSION);
21518 -- pragma Pre_Class (Boolean_EXPRESSION);
21519 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
21520 -- [,[Message =>] String_EXPRESSION]);
21522 -- Characteristics:
21524 -- * Analysis - The annotation undergoes initial checks to verify
21525 -- the legal placement and context. Secondary checks preanalyze the
21528 -- Analyze_Pre_Post_Condition_In_Decl_Part
21530 -- * Expansion - The annotation is expanded during the expansion of
21531 -- the related subprogram [body] contract as performed in:
21533 -- Expand_Subprogram_Contract
21535 -- * Template - The annotation utilizes the generic template of the
21536 -- related subprogram [body] when it is:
21538 -- aspect on subprogram declaration
21539 -- aspect on stand-alone subprogram body
21540 -- pragma on stand-alone subprogram body
21542 -- The annotation must prepare its own template when it is:
21544 -- pragma on subprogram declaration
21546 -- * Globals - Capture of global references must occur after full
21549 -- * Instance - The annotation is instantiated automatically when
21550 -- the related generic subprogram [body] is instantiated except for
21551 -- the "pragma on subprogram declaration" case. In that scenario
21552 -- the annotation must instantiate itself.
21556 | Pragma_Precondition
21558 Analyze_Pre_Post_Condition;
21564 -- pragma Predicate
21565 -- ([Entity =>] type_LOCAL_NAME,
21566 -- [Check =>] boolean_EXPRESSION);
21568 when Pragma_Predicate => Predicate : declare
21575 Check_Arg_Count (2);
21576 Check_Optional_Identifier (Arg1, Name_Entity);
21577 Check_Optional_Identifier (Arg2, Name_Check);
21579 Check_Arg_Is_Local_Name (Arg1);
21581 Type_Id := Get_Pragma_Arg (Arg1);
21582 Find_Type (Type_Id);
21583 Typ := Entity (Type_Id);
21585 if Typ = Any_Type then
21589 -- A pragma that applies to a Ghost entity becomes Ghost for the
21590 -- purposes of legality checks and removal of ignored Ghost code.
21592 Mark_Ghost_Pragma (N, Typ);
21594 -- The remaining processing is simply to link the pragma on to
21595 -- the rep item chain, for processing when the type is frozen.
21596 -- This is accomplished by a call to Rep_Item_Too_Late. We also
21597 -- mark the type as having predicates.
21599 -- If the current policy for predicate checking is Ignore mark the
21600 -- subtype accordingly. In the case of predicates we consider them
21601 -- enabled unless Ignore is specified (either directly or with a
21602 -- general Assertion_Policy pragma) to preserve existing warnings.
21604 Set_Has_Predicates (Typ);
21606 -- Indicate that the pragma must be processed at the point the
21607 -- type is frozen, as is done for the corresponding aspect.
21609 Set_Has_Delayed_Aspects (Typ);
21610 Set_Has_Delayed_Freeze (Typ);
21612 Set_Predicates_Ignored (Typ,
21613 Present (Check_Policy_List)
21615 Policy_In_Effect (Name_Dynamic_Predicate) = Name_Ignore);
21616 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
21619 -----------------------
21620 -- Predicate_Failure --
21621 -----------------------
21623 -- pragma Predicate_Failure
21624 -- ([Entity =>] type_LOCAL_NAME,
21625 -- [Message =>] string_EXPRESSION);
21627 when Pragma_Predicate_Failure => Predicate_Failure : declare
21634 Check_Arg_Count (2);
21635 Check_Optional_Identifier (Arg1, Name_Entity);
21636 Check_Optional_Identifier (Arg2, Name_Message);
21638 Check_Arg_Is_Local_Name (Arg1);
21640 Type_Id := Get_Pragma_Arg (Arg1);
21641 Find_Type (Type_Id);
21642 Typ := Entity (Type_Id);
21644 if Typ = Any_Type then
21648 -- A pragma that applies to a Ghost entity becomes Ghost for the
21649 -- purposes of legality checks and removal of ignored Ghost code.
21651 Mark_Ghost_Pragma (N, Typ);
21653 -- The remaining processing is simply to link the pragma on to
21654 -- the rep item chain, for processing when the type is frozen.
21655 -- This is accomplished by a call to Rep_Item_Too_Late.
21657 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
21658 end Predicate_Failure;
21664 -- pragma Preelaborate [(library_unit_NAME)];
21666 -- Set the flag Is_Preelaborated of program unit name entity
21668 when Pragma_Preelaborate => Preelaborate : declare
21669 Pa : constant Node_Id := Parent (N);
21670 Pk : constant Node_Kind := Nkind (Pa);
21674 Check_Ada_83_Warning;
21675 Check_Valid_Library_Unit_Pragma;
21677 if Nkind (N) = N_Null_Statement then
21681 Ent := Find_Lib_Unit_Name;
21683 -- A pragma that applies to a Ghost entity becomes Ghost for the
21684 -- purposes of legality checks and removal of ignored Ghost code.
21686 Mark_Ghost_Pragma (N, Ent);
21687 Check_Duplicate_Pragma (Ent);
21689 -- This filters out pragmas inside generic parents that show up
21690 -- inside instantiations. Pragmas that come from aspects in the
21691 -- unit are not ignored.
21693 if Present (Ent) then
21694 if Pk = N_Package_Specification
21695 and then Present (Generic_Parent (Pa))
21696 and then not From_Aspect_Specification (N)
21701 if not Debug_Flag_U then
21702 Set_Is_Preelaborated (Ent);
21704 if Legacy_Elaboration_Checks then
21705 Set_Suppress_Elaboration_Warnings (Ent);
21712 -------------------------------
21713 -- Prefix_Exception_Messages --
21714 -------------------------------
21716 -- pragma Prefix_Exception_Messages;
21718 when Pragma_Prefix_Exception_Messages =>
21720 Check_Valid_Configuration_Pragma;
21721 Check_Arg_Count (0);
21722 Prefix_Exception_Messages := True;
21728 -- pragma Priority (EXPRESSION);
21730 when Pragma_Priority => Priority : declare
21731 P : constant Node_Id := Parent (N);
21736 Check_No_Identifiers;
21737 Check_Arg_Count (1);
21741 if Nkind (P) = N_Subprogram_Body then
21742 Check_In_Main_Program;
21744 Ent := Defining_Unit_Name (Specification (P));
21746 if Nkind (Ent) = N_Defining_Program_Unit_Name then
21747 Ent := Defining_Identifier (Ent);
21750 Arg := Get_Pragma_Arg (Arg1);
21751 Analyze_And_Resolve (Arg, Standard_Integer);
21755 if not Is_OK_Static_Expression (Arg) then
21756 Flag_Non_Static_Expr
21757 ("main subprogram priority is not static!", Arg);
21760 -- If constraint error, then we already signalled an error
21762 elsif Raises_Constraint_Error (Arg) then
21765 -- Otherwise check in range except if Relaxed_RM_Semantics
21766 -- where we ignore the value if out of range.
21769 if not Relaxed_RM_Semantics
21770 and then not Is_In_Range (Arg, RTE (RE_Priority))
21773 ("main subprogram priority is out of range", Arg1);
21776 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
21780 -- Load an arbitrary entity from System.Tasking.Stages or
21781 -- System.Tasking.Restricted.Stages (depending on the
21782 -- supported profile) to make sure that one of these packages
21783 -- is implicitly with'ed, since we need to have the tasking
21784 -- run time active for the pragma Priority to have any effect.
21785 -- Previously we with'ed the package System.Tasking, but this
21786 -- package does not trigger the required initialization of the
21787 -- run-time library.
21790 Discard : Entity_Id;
21791 pragma Warnings (Off, Discard);
21793 if Restricted_Profile then
21794 Discard := RTE (RE_Activate_Restricted_Tasks);
21796 Discard := RTE (RE_Activate_Tasks);
21800 -- Task or Protected, must be of type Integer
21802 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
21803 Arg := Get_Pragma_Arg (Arg1);
21804 Ent := Defining_Identifier (Parent (P));
21806 -- The expression must be analyzed in the special manner
21807 -- described in "Handling of Default and Per-Object
21808 -- Expressions" in sem.ads.
21810 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
21812 if not Is_OK_Static_Expression (Arg) then
21813 Check_Restriction (Static_Priorities, Arg);
21816 -- Anything else is incorrect
21822 -- Check duplicate pragma before we chain the pragma in the Rep
21823 -- Item chain of Ent.
21825 Check_Duplicate_Pragma (Ent);
21826 Record_Rep_Item (Ent, N);
21829 -----------------------------------
21830 -- Priority_Specific_Dispatching --
21831 -----------------------------------
21833 -- pragma Priority_Specific_Dispatching (
21834 -- policy_IDENTIFIER,
21835 -- first_priority_EXPRESSION,
21836 -- last_priority_EXPRESSION);
21838 when Pragma_Priority_Specific_Dispatching =>
21839 Priority_Specific_Dispatching : declare
21840 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
21841 -- This is the entity System.Any_Priority;
21844 Lower_Bound : Node_Id;
21845 Upper_Bound : Node_Id;
21851 Check_Arg_Count (3);
21852 Check_No_Identifiers;
21853 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
21854 Check_Valid_Configuration_Pragma;
21855 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21856 DP := Fold_Upper (Name_Buffer (1));
21858 Lower_Bound := Get_Pragma_Arg (Arg2);
21859 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
21860 Lower_Val := Expr_Value (Lower_Bound);
21862 Upper_Bound := Get_Pragma_Arg (Arg3);
21863 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
21864 Upper_Val := Expr_Value (Upper_Bound);
21866 -- It is not allowed to use Task_Dispatching_Policy and
21867 -- Priority_Specific_Dispatching in the same partition.
21869 if Task_Dispatching_Policy /= ' ' then
21870 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21872 ("pragma% incompatible with Task_Dispatching_Policy#");
21874 -- Check lower bound in range
21876 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
21878 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
21881 ("first_priority is out of range", Arg2);
21883 -- Check upper bound in range
21885 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
21887 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
21890 ("last_priority is out of range", Arg3);
21892 -- Check that the priority range is valid
21894 elsif Lower_Val > Upper_Val then
21896 ("last_priority_expression must be greater than or equal to "
21897 & "first_priority_expression");
21899 -- Store the new policy, but always preserve System_Location since
21900 -- we like the error message with the run-time name.
21903 -- Check overlapping in the priority ranges specified in other
21904 -- Priority_Specific_Dispatching pragmas within the same
21905 -- partition. We can only check those we know about.
21908 Specific_Dispatching.First .. Specific_Dispatching.Last
21910 if Specific_Dispatching.Table (J).First_Priority in
21911 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
21912 or else Specific_Dispatching.Table (J).Last_Priority in
21913 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
21916 Specific_Dispatching.Table (J).Pragma_Loc;
21918 ("priority range overlaps with "
21919 & "Priority_Specific_Dispatching#");
21923 -- The use of Priority_Specific_Dispatching is incompatible
21924 -- with Task_Dispatching_Policy.
21926 if Task_Dispatching_Policy /= ' ' then
21927 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21929 ("Priority_Specific_Dispatching incompatible "
21930 & "with Task_Dispatching_Policy#");
21933 -- The use of Priority_Specific_Dispatching forces ceiling
21936 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
21937 Error_Msg_Sloc := Locking_Policy_Sloc;
21939 ("Priority_Specific_Dispatching incompatible "
21940 & "with Locking_Policy#");
21942 -- Set the Ceiling_Locking policy, but preserve System_Location
21943 -- since we like the error message with the run time name.
21946 Locking_Policy := 'C';
21948 if Locking_Policy_Sloc /= System_Location then
21949 Locking_Policy_Sloc := Loc;
21953 -- Add entry in the table
21955 Specific_Dispatching.Append
21956 ((Dispatching_Policy => DP,
21957 First_Priority => UI_To_Int (Lower_Val),
21958 Last_Priority => UI_To_Int (Upper_Val),
21959 Pragma_Loc => Loc));
21961 end Priority_Specific_Dispatching;
21967 -- pragma Profile (profile_IDENTIFIER);
21969 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
21971 when Pragma_Profile =>
21973 Check_Arg_Count (1);
21974 Check_Valid_Configuration_Pragma;
21975 Check_No_Identifiers;
21978 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21981 if Chars (Argx) = Name_Ravenscar then
21982 Set_Ravenscar_Profile (Ravenscar, N);
21984 elsif Chars (Argx) = Name_Gnat_Extended_Ravenscar then
21985 Set_Ravenscar_Profile (GNAT_Extended_Ravenscar, N);
21987 elsif Chars (Argx) = Name_Gnat_Ravenscar_EDF then
21988 Set_Ravenscar_Profile (GNAT_Ravenscar_EDF, N);
21990 elsif Chars (Argx) = Name_Restricted then
21991 Set_Profile_Restrictions
21993 N, Warn => Treat_Restrictions_As_Warnings);
21995 elsif Chars (Argx) = Name_Rational then
21996 Set_Rational_Profile;
21998 elsif Chars (Argx) = Name_No_Implementation_Extensions then
21999 Set_Profile_Restrictions
22000 (No_Implementation_Extensions,
22001 N, Warn => Treat_Restrictions_As_Warnings);
22004 Error_Pragma_Arg ("& is not a valid profile", Argx);
22008 ----------------------
22009 -- Profile_Warnings --
22010 ----------------------
22012 -- pragma Profile_Warnings (profile_IDENTIFIER);
22014 -- profile_IDENTIFIER => Restricted | Ravenscar
22016 when Pragma_Profile_Warnings =>
22018 Check_Arg_Count (1);
22019 Check_Valid_Configuration_Pragma;
22020 Check_No_Identifiers;
22023 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
22026 if Chars (Argx) = Name_Ravenscar then
22027 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
22029 elsif Chars (Argx) = Name_Restricted then
22030 Set_Profile_Restrictions (Restricted, N, Warn => True);
22032 elsif Chars (Argx) = Name_No_Implementation_Extensions then
22033 Set_Profile_Restrictions
22034 (No_Implementation_Extensions, N, Warn => True);
22037 Error_Pragma_Arg ("& is not a valid profile", Argx);
22041 --------------------------
22042 -- Propagate_Exceptions --
22043 --------------------------
22045 -- pragma Propagate_Exceptions;
22047 -- Note: this pragma is obsolete and has no effect
22049 when Pragma_Propagate_Exceptions =>
22051 Check_Arg_Count (0);
22053 if Warn_On_Obsolescent_Feature then
22055 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
22056 "and has no effect?j?", N);
22059 -----------------------------
22060 -- Provide_Shift_Operators --
22061 -----------------------------
22063 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
22065 when Pragma_Provide_Shift_Operators =>
22066 Provide_Shift_Operators : declare
22069 procedure Declare_Shift_Operator (Nam : Name_Id);
22070 -- Insert declaration and pragma Instrinsic for named shift op
22072 ----------------------------
22073 -- Declare_Shift_Operator --
22074 ----------------------------
22076 procedure Declare_Shift_Operator (Nam : Name_Id) is
22082 Make_Subprogram_Declaration (Loc,
22083 Make_Function_Specification (Loc,
22084 Defining_Unit_Name =>
22085 Make_Defining_Identifier (Loc, Chars => Nam),
22087 Result_Definition =>
22088 Make_Identifier (Loc, Chars => Chars (Ent)),
22090 Parameter_Specifications => New_List (
22091 Make_Parameter_Specification (Loc,
22092 Defining_Identifier =>
22093 Make_Defining_Identifier (Loc, Name_Value),
22095 Make_Identifier (Loc, Chars => Chars (Ent))),
22097 Make_Parameter_Specification (Loc,
22098 Defining_Identifier =>
22099 Make_Defining_Identifier (Loc, Name_Amount),
22101 New_Occurrence_Of (Standard_Natural, Loc)))));
22105 Chars => Name_Import,
22106 Pragma_Argument_Associations => New_List (
22107 Make_Pragma_Argument_Association (Loc,
22108 Expression => Make_Identifier (Loc, Name_Intrinsic)),
22109 Make_Pragma_Argument_Association (Loc,
22110 Expression => Make_Identifier (Loc, Nam))));
22112 Insert_After (N, Import);
22113 Insert_After (N, Func);
22114 end Declare_Shift_Operator;
22116 -- Start of processing for Provide_Shift_Operators
22120 Check_Arg_Count (1);
22121 Check_Arg_Is_Local_Name (Arg1);
22123 Arg1 := Get_Pragma_Arg (Arg1);
22125 -- We must have an entity name
22127 if not Is_Entity_Name (Arg1) then
22129 ("pragma % must apply to integer first subtype", Arg1);
22132 -- If no Entity, means there was a prior error so ignore
22134 if Present (Entity (Arg1)) then
22135 Ent := Entity (Arg1);
22137 -- Apply error checks
22139 if not Is_First_Subtype (Ent) then
22141 ("cannot apply pragma %",
22142 "\& is not a first subtype",
22145 elsif not Is_Integer_Type (Ent) then
22147 ("cannot apply pragma %",
22148 "\& is not an integer type",
22151 elsif Has_Shift_Operator (Ent) then
22153 ("cannot apply pragma %",
22154 "\& already has declared shift operators",
22157 elsif Is_Frozen (Ent) then
22159 ("pragma % appears too late",
22160 "\& is already frozen",
22164 -- Now declare the operators. We do this during analysis rather
22165 -- than expansion, since we want the operators available if we
22166 -- are operating in -gnatc mode.
22168 Declare_Shift_Operator (Name_Rotate_Left);
22169 Declare_Shift_Operator (Name_Rotate_Right);
22170 Declare_Shift_Operator (Name_Shift_Left);
22171 Declare_Shift_Operator (Name_Shift_Right);
22172 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
22174 end Provide_Shift_Operators;
22180 -- pragma Psect_Object (
22181 -- [Internal =>] LOCAL_NAME,
22182 -- [, [External =>] EXTERNAL_SYMBOL]
22183 -- [, [Size =>] EXTERNAL_SYMBOL]);
22185 when Pragma_Common_Object
22186 | Pragma_Psect_Object
22188 Psect_Object : declare
22189 Args : Args_List (1 .. 3);
22190 Names : constant Name_List (1 .. 3) := (
22195 Internal : Node_Id renames Args (1);
22196 External : Node_Id renames Args (2);
22197 Size : Node_Id renames Args (3);
22199 Def_Id : Entity_Id;
22201 procedure Check_Arg (Arg : Node_Id);
22202 -- Checks that argument is either a string literal or an
22203 -- identifier, and posts error message if not.
22209 procedure Check_Arg (Arg : Node_Id) is
22211 if not Nkind_In (Original_Node (Arg),
22216 ("inappropriate argument for pragma %", Arg);
22220 -- Start of processing for Common_Object/Psect_Object
22224 Gather_Associations (Names, Args);
22225 Process_Extended_Import_Export_Internal_Arg (Internal);
22227 Def_Id := Entity (Internal);
22229 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
22231 ("pragma% must designate an object", Internal);
22234 Check_Arg (Internal);
22236 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
22238 ("cannot use pragma% for imported/exported object",
22242 if Is_Concurrent_Type (Etype (Internal)) then
22244 ("cannot specify pragma % for task/protected object",
22248 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
22250 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
22252 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
22255 if Ekind (Def_Id) = E_Constant then
22257 ("cannot specify pragma % for a constant", Internal);
22260 if Is_Record_Type (Etype (Internal)) then
22266 Ent := First_Entity (Etype (Internal));
22267 while Present (Ent) loop
22268 Decl := Declaration_Node (Ent);
22270 if Ekind (Ent) = E_Component
22271 and then Nkind (Decl) = N_Component_Declaration
22272 and then Present (Expression (Decl))
22273 and then Warn_On_Export_Import
22276 ("?x?object for pragma % has defaults", Internal);
22286 if Present (Size) then
22290 if Present (External) then
22291 Check_Arg_Is_External_Name (External);
22294 -- If all error tests pass, link pragma on to the rep item chain
22296 Record_Rep_Item (Def_Id, N);
22303 -- pragma Pure [(library_unit_NAME)];
22305 when Pragma_Pure => Pure : declare
22309 Check_Ada_83_Warning;
22311 -- If the pragma comes from a subprogram instantiation, nothing to
22312 -- check, this can happen at any level of nesting.
22314 if Is_Wrapper_Package (Current_Scope) then
22317 Check_Valid_Library_Unit_Pragma;
22320 if Nkind (N) = N_Null_Statement then
22324 Ent := Find_Lib_Unit_Name;
22326 -- A pragma that applies to a Ghost entity becomes Ghost for the
22327 -- purposes of legality checks and removal of ignored Ghost code.
22329 Mark_Ghost_Pragma (N, Ent);
22331 if not Debug_Flag_U then
22333 Set_Has_Pragma_Pure (Ent);
22335 if Legacy_Elaboration_Checks then
22336 Set_Suppress_Elaboration_Warnings (Ent);
22341 -------------------
22342 -- Pure_Function --
22343 -------------------
22345 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
22347 when Pragma_Pure_Function => Pure_Function : declare
22348 Def_Id : Entity_Id;
22351 Effective : Boolean := False;
22352 Orig_Def : Entity_Id;
22353 Same_Decl : Boolean := False;
22357 Check_Arg_Count (1);
22358 Check_Optional_Identifier (Arg1, Name_Entity);
22359 Check_Arg_Is_Local_Name (Arg1);
22360 E_Id := Get_Pragma_Arg (Arg1);
22362 if Etype (E_Id) = Any_Type then
22366 -- Loop through homonyms (overloadings) of referenced entity
22368 E := Entity (E_Id);
22370 -- A pragma that applies to a Ghost entity becomes Ghost for the
22371 -- purposes of legality checks and removal of ignored Ghost code.
22373 Mark_Ghost_Pragma (N, E);
22375 if Present (E) then
22377 Def_Id := Get_Base_Subprogram (E);
22379 if not Ekind_In (Def_Id, E_Function,
22380 E_Generic_Function,
22384 ("pragma% requires a function name", Arg1);
22387 -- When we have a generic function we must jump up a level
22388 -- to the declaration of the wrapper package itself.
22390 Orig_Def := Def_Id;
22392 if Is_Generic_Instance (Def_Id) then
22393 while Nkind (Orig_Def) /= N_Package_Declaration loop
22394 Orig_Def := Parent (Orig_Def);
22398 if In_Same_Declarative_Part (Parent (N), Orig_Def) then
22400 Set_Is_Pure (Def_Id);
22402 if not Has_Pragma_Pure_Function (Def_Id) then
22403 Set_Has_Pragma_Pure_Function (Def_Id);
22408 exit when From_Aspect_Specification (N);
22410 exit when No (E) or else Scope (E) /= Current_Scope;
22414 and then Warn_On_Redundant_Constructs
22417 ("pragma Pure_Function on& is redundant?r?",
22420 elsif not Same_Decl then
22422 ("pragma% argument must be in same declarative part",
22428 --------------------
22429 -- Queuing_Policy --
22430 --------------------
22432 -- pragma Queuing_Policy (policy_IDENTIFIER);
22434 when Pragma_Queuing_Policy => declare
22438 Check_Ada_83_Warning;
22439 Check_Arg_Count (1);
22440 Check_No_Identifiers;
22441 Check_Arg_Is_Queuing_Policy (Arg1);
22442 Check_Valid_Configuration_Pragma;
22443 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
22444 QP := Fold_Upper (Name_Buffer (1));
22446 if Queuing_Policy /= ' '
22447 and then Queuing_Policy /= QP
22449 Error_Msg_Sloc := Queuing_Policy_Sloc;
22450 Error_Pragma ("queuing policy incompatible with policy#");
22452 -- Set new policy, but always preserve System_Location since we
22453 -- like the error message with the run time name.
22456 Queuing_Policy := QP;
22458 if Queuing_Policy_Sloc /= System_Location then
22459 Queuing_Policy_Sloc := Loc;
22468 -- pragma Rational, for compatibility with foreign compiler
22470 when Pragma_Rational =>
22471 Set_Rational_Profile;
22473 ---------------------
22474 -- Refined_Depends --
22475 ---------------------
22477 -- pragma Refined_Depends (DEPENDENCY_RELATION);
22479 -- DEPENDENCY_RELATION ::=
22481 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
22483 -- DEPENDENCY_CLAUSE ::=
22484 -- OUTPUT_LIST =>[+] INPUT_LIST
22485 -- | NULL_DEPENDENCY_CLAUSE
22487 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
22489 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
22491 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
22493 -- OUTPUT ::= NAME | FUNCTION_RESULT
22496 -- where FUNCTION_RESULT is a function Result attribute_reference
22498 -- Characteristics:
22500 -- * Analysis - The annotation undergoes initial checks to verify
22501 -- the legal placement and context. Secondary checks fully analyze
22502 -- the dependency clauses/global list in:
22504 -- Analyze_Refined_Depends_In_Decl_Part
22506 -- * Expansion - None.
22508 -- * Template - The annotation utilizes the generic template of the
22509 -- related subprogram body.
22511 -- * Globals - Capture of global references must occur after full
22514 -- * Instance - The annotation is instantiated automatically when
22515 -- the related generic subprogram body is instantiated.
22517 when Pragma_Refined_Depends => Refined_Depends : declare
22518 Body_Id : Entity_Id;
22520 Spec_Id : Entity_Id;
22523 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22527 -- Chain the pragma on the contract for further processing by
22528 -- Analyze_Refined_Depends_In_Decl_Part.
22530 Add_Contract_Item (N, Body_Id);
22532 -- The legality checks of pragmas Refined_Depends and
22533 -- Refined_Global are affected by the SPARK mode in effect and
22534 -- the volatility of the context. In addition these two pragmas
22535 -- are subject to an inherent order:
22537 -- 1) Refined_Global
22538 -- 2) Refined_Depends
22540 -- Analyze all these pragmas in the order outlined above
22542 Analyze_If_Present (Pragma_SPARK_Mode);
22543 Analyze_If_Present (Pragma_Volatile_Function);
22544 Analyze_If_Present (Pragma_Refined_Global);
22545 Analyze_Refined_Depends_In_Decl_Part (N);
22547 end Refined_Depends;
22549 --------------------
22550 -- Refined_Global --
22551 --------------------
22553 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
22555 -- GLOBAL_SPECIFICATION ::=
22558 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
22560 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
22562 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
22563 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
22564 -- GLOBAL_ITEM ::= NAME
22566 -- Characteristics:
22568 -- * Analysis - The annotation undergoes initial checks to verify
22569 -- the legal placement and context. Secondary checks fully analyze
22570 -- the dependency clauses/global list in:
22572 -- Analyze_Refined_Global_In_Decl_Part
22574 -- * Expansion - None.
22576 -- * Template - The annotation utilizes the generic template of the
22577 -- related subprogram body.
22579 -- * Globals - Capture of global references must occur after full
22582 -- * Instance - The annotation is instantiated automatically when
22583 -- the related generic subprogram body is instantiated.
22585 when Pragma_Refined_Global => Refined_Global : declare
22586 Body_Id : Entity_Id;
22588 Spec_Id : Entity_Id;
22591 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22595 -- Chain the pragma on the contract for further processing by
22596 -- Analyze_Refined_Global_In_Decl_Part.
22598 Add_Contract_Item (N, Body_Id);
22600 -- The legality checks of pragmas Refined_Depends and
22601 -- Refined_Global are affected by the SPARK mode in effect and
22602 -- the volatility of the context. In addition these two pragmas
22603 -- are subject to an inherent order:
22605 -- 1) Refined_Global
22606 -- 2) Refined_Depends
22608 -- Analyze all these pragmas in the order outlined above
22610 Analyze_If_Present (Pragma_SPARK_Mode);
22611 Analyze_If_Present (Pragma_Volatile_Function);
22612 Analyze_Refined_Global_In_Decl_Part (N);
22613 Analyze_If_Present (Pragma_Refined_Depends);
22615 end Refined_Global;
22621 -- pragma Refined_Post (boolean_EXPRESSION);
22623 -- Characteristics:
22625 -- * Analysis - The annotation is fully analyzed immediately upon
22626 -- elaboration as it cannot forward reference entities.
22628 -- * Expansion - The annotation is expanded during the expansion of
22629 -- the related subprogram body contract as performed in:
22631 -- Expand_Subprogram_Contract
22633 -- * Template - The annotation utilizes the generic template of the
22634 -- related subprogram body.
22636 -- * Globals - Capture of global references must occur after full
22639 -- * Instance - The annotation is instantiated automatically when
22640 -- the related generic subprogram body is instantiated.
22642 when Pragma_Refined_Post => Refined_Post : declare
22643 Body_Id : Entity_Id;
22645 Spec_Id : Entity_Id;
22648 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22650 -- Fully analyze the pragma when it appears inside a subprogram
22651 -- body because it cannot benefit from forward references.
22655 -- Chain the pragma on the contract for completeness
22657 Add_Contract_Item (N, Body_Id);
22659 -- The legality checks of pragma Refined_Post are affected by
22660 -- the SPARK mode in effect and the volatility of the context.
22661 -- Analyze all pragmas in a specific order.
22663 Analyze_If_Present (Pragma_SPARK_Mode);
22664 Analyze_If_Present (Pragma_Volatile_Function);
22665 Analyze_Pre_Post_Condition_In_Decl_Part (N);
22667 -- Currently it is not possible to inline pre/postconditions on
22668 -- a subprogram subject to pragma Inline_Always.
22670 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
22674 -------------------
22675 -- Refined_State --
22676 -------------------
22678 -- pragma Refined_State (REFINEMENT_LIST);
22680 -- REFINEMENT_LIST ::=
22681 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
22683 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
22685 -- CONSTITUENT_LIST ::=
22688 -- | (CONSTITUENT {, CONSTITUENT})
22690 -- CONSTITUENT ::= object_NAME | state_NAME
22692 -- Characteristics:
22694 -- * Analysis - The annotation undergoes initial checks to verify
22695 -- the legal placement and context. Secondary checks preanalyze the
22696 -- refinement clauses in:
22698 -- Analyze_Refined_State_In_Decl_Part
22700 -- * Expansion - None.
22702 -- * Template - The annotation utilizes the template of the related
22705 -- * Globals - Capture of global references must occur after full
22708 -- * Instance - The annotation is instantiated automatically when
22709 -- the related generic package body is instantiated.
22711 when Pragma_Refined_State => Refined_State : declare
22712 Pack_Decl : Node_Id;
22713 Spec_Id : Entity_Id;
22717 Check_No_Identifiers;
22718 Check_Arg_Count (1);
22720 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
22722 if Nkind (Pack_Decl) /= N_Package_Body then
22727 Spec_Id := Corresponding_Spec (Pack_Decl);
22729 -- A pragma that applies to a Ghost entity becomes Ghost for the
22730 -- purposes of legality checks and removal of ignored Ghost code.
22732 Mark_Ghost_Pragma (N, Spec_Id);
22734 -- Chain the pragma on the contract for further processing by
22735 -- Analyze_Refined_State_In_Decl_Part.
22737 Add_Contract_Item (N, Defining_Entity (Pack_Decl));
22739 -- The legality checks of pragma Refined_State are affected by the
22740 -- SPARK mode in effect. Analyze all pragmas in a specific order.
22742 Analyze_If_Present (Pragma_SPARK_Mode);
22744 -- State refinement is allowed only when the corresponding package
22745 -- declaration has non-null pragma Abstract_State. Refinement not
22746 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
22748 if SPARK_Mode /= Off
22750 (No (Abstract_States (Spec_Id))
22751 or else Has_Null_Abstract_State (Spec_Id))
22754 ("useless refinement, package & does not define abstract "
22755 & "states", N, Spec_Id);
22760 -----------------------
22761 -- Relative_Deadline --
22762 -----------------------
22764 -- pragma Relative_Deadline (time_span_EXPRESSION);
22766 when Pragma_Relative_Deadline => Relative_Deadline : declare
22767 P : constant Node_Id := Parent (N);
22772 Check_No_Identifiers;
22773 Check_Arg_Count (1);
22775 Arg := Get_Pragma_Arg (Arg1);
22777 -- The expression must be analyzed in the special manner described
22778 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
22780 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
22784 if Nkind (P) = N_Subprogram_Body then
22785 Check_In_Main_Program;
22787 -- Only Task and subprogram cases allowed
22789 elsif Nkind (P) /= N_Task_Definition then
22793 -- Check duplicate pragma before we set the corresponding flag
22795 if Has_Relative_Deadline_Pragma (P) then
22796 Error_Pragma ("duplicate pragma% not allowed");
22799 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
22800 -- Relative_Deadline pragma node cannot be inserted in the Rep
22801 -- Item chain of Ent since it is rewritten by the expander as a
22802 -- procedure call statement that will break the chain.
22804 Set_Has_Relative_Deadline_Pragma (P);
22805 end Relative_Deadline;
22807 ------------------------
22808 -- Remote_Access_Type --
22809 ------------------------
22811 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
22813 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
22818 Check_Arg_Count (1);
22819 Check_Optional_Identifier (Arg1, Name_Entity);
22820 Check_Arg_Is_Local_Name (Arg1);
22822 E := Entity (Get_Pragma_Arg (Arg1));
22824 -- A pragma that applies to a Ghost entity becomes Ghost for the
22825 -- purposes of legality checks and removal of ignored Ghost code.
22827 Mark_Ghost_Pragma (N, E);
22829 if Nkind (Parent (E)) = N_Formal_Type_Declaration
22830 and then Ekind (E) = E_General_Access_Type
22831 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
22832 and then Scope (Root_Type (Directly_Designated_Type (E)))
22834 and then Is_Valid_Remote_Object_Type
22835 (Root_Type (Directly_Designated_Type (E)))
22837 Set_Is_Remote_Types (E);
22841 ("pragma% applies only to formal access-to-class-wide types",
22844 end Remote_Access_Type;
22846 ---------------------------
22847 -- Remote_Call_Interface --
22848 ---------------------------
22850 -- pragma Remote_Call_Interface [(library_unit_NAME)];
22852 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
22853 Cunit_Node : Node_Id;
22854 Cunit_Ent : Entity_Id;
22858 Check_Ada_83_Warning;
22859 Check_Valid_Library_Unit_Pragma;
22861 if Nkind (N) = N_Null_Statement then
22865 Cunit_Node := Cunit (Current_Sem_Unit);
22866 K := Nkind (Unit (Cunit_Node));
22867 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22869 -- A pragma that applies to a Ghost entity becomes Ghost for the
22870 -- purposes of legality checks and removal of ignored Ghost code.
22872 Mark_Ghost_Pragma (N, Cunit_Ent);
22874 if K = N_Package_Declaration
22875 or else K = N_Generic_Package_Declaration
22876 or else K = N_Subprogram_Declaration
22877 or else K = N_Generic_Subprogram_Declaration
22878 or else (K = N_Subprogram_Body
22879 and then Acts_As_Spec (Unit (Cunit_Node)))
22884 "pragma% must apply to package or subprogram declaration");
22887 Set_Is_Remote_Call_Interface (Cunit_Ent);
22888 end Remote_Call_Interface;
22894 -- pragma Remote_Types [(library_unit_NAME)];
22896 when Pragma_Remote_Types => Remote_Types : declare
22897 Cunit_Node : Node_Id;
22898 Cunit_Ent : Entity_Id;
22901 Check_Ada_83_Warning;
22902 Check_Valid_Library_Unit_Pragma;
22904 if Nkind (N) = N_Null_Statement then
22908 Cunit_Node := Cunit (Current_Sem_Unit);
22909 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22911 -- A pragma that applies to a Ghost entity becomes Ghost for the
22912 -- purposes of legality checks and removal of ignored Ghost code.
22914 Mark_Ghost_Pragma (N, Cunit_Ent);
22916 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
22917 N_Generic_Package_Declaration)
22920 ("pragma% can only apply to a package declaration");
22923 Set_Is_Remote_Types (Cunit_Ent);
22930 -- pragma Ravenscar;
22932 when Pragma_Ravenscar =>
22934 Check_Arg_Count (0);
22935 Check_Valid_Configuration_Pragma;
22936 Set_Ravenscar_Profile (Ravenscar, N);
22938 if Warn_On_Obsolescent_Feature then
22940 ("pragma Ravenscar is an obsolescent feature?j?", N);
22942 ("|use pragma Profile (Ravenscar) instead?j?", N);
22945 -------------------------
22946 -- Restricted_Run_Time --
22947 -------------------------
22949 -- pragma Restricted_Run_Time;
22951 when Pragma_Restricted_Run_Time =>
22953 Check_Arg_Count (0);
22954 Check_Valid_Configuration_Pragma;
22955 Set_Profile_Restrictions
22956 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
22958 if Warn_On_Obsolescent_Feature then
22960 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
22963 ("|use pragma Profile (Restricted) instead?j?", N);
22970 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
22973 -- restriction_IDENTIFIER
22974 -- | restriction_parameter_IDENTIFIER => EXPRESSION
22976 when Pragma_Restrictions =>
22977 Process_Restrictions_Or_Restriction_Warnings
22978 (Warn => Treat_Restrictions_As_Warnings);
22980 --------------------------
22981 -- Restriction_Warnings --
22982 --------------------------
22984 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
22987 -- restriction_IDENTIFIER
22988 -- | restriction_parameter_IDENTIFIER => EXPRESSION
22990 when Pragma_Restriction_Warnings =>
22992 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
22998 -- pragma Reviewable;
23000 when Pragma_Reviewable =>
23001 Check_Ada_83_Warning;
23002 Check_Arg_Count (0);
23004 -- Call dummy debugging function rv. This is done to assist front
23005 -- end debugging. By placing a Reviewable pragma in the source
23006 -- program, a breakpoint on rv catches this place in the source,
23007 -- allowing convenient stepping to the point of interest.
23011 --------------------------
23012 -- Secondary_Stack_Size --
23013 --------------------------
23015 -- pragma Secondary_Stack_Size (EXPRESSION);
23017 when Pragma_Secondary_Stack_Size => Secondary_Stack_Size : declare
23018 P : constant Node_Id := Parent (N);
23024 Check_No_Identifiers;
23025 Check_Arg_Count (1);
23027 if Nkind (P) = N_Task_Definition then
23028 Arg := Get_Pragma_Arg (Arg1);
23029 Ent := Defining_Identifier (Parent (P));
23031 -- The expression must be analyzed in the special manner
23032 -- described in "Handling of Default Expressions" in sem.ads.
23034 Preanalyze_Spec_Expression (Arg, Any_Integer);
23036 -- The pragma cannot appear if the No_Secondary_Stack
23037 -- restriction is in effect.
23039 Check_Restriction (No_Secondary_Stack, Arg);
23041 -- Anything else is incorrect
23047 -- Check duplicate pragma before we chain the pragma in the Rep
23048 -- Item chain of Ent.
23050 Check_Duplicate_Pragma (Ent);
23051 Record_Rep_Item (Ent, N);
23052 end Secondary_Stack_Size;
23054 --------------------------
23055 -- Short_Circuit_And_Or --
23056 --------------------------
23058 -- pragma Short_Circuit_And_Or;
23060 when Pragma_Short_Circuit_And_Or =>
23062 Check_Arg_Count (0);
23063 Check_Valid_Configuration_Pragma;
23064 Short_Circuit_And_Or := True;
23066 -------------------
23067 -- Share_Generic --
23068 -------------------
23070 -- pragma Share_Generic (GNAME {, GNAME});
23072 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
23074 when Pragma_Share_Generic =>
23076 Process_Generic_List;
23082 -- pragma Shared (LOCAL_NAME);
23084 when Pragma_Shared =>
23086 Process_Atomic_Independent_Shared_Volatile;
23088 --------------------
23089 -- Shared_Passive --
23090 --------------------
23092 -- pragma Shared_Passive [(library_unit_NAME)];
23094 -- Set the flag Is_Shared_Passive of program unit name entity
23096 when Pragma_Shared_Passive => Shared_Passive : declare
23097 Cunit_Node : Node_Id;
23098 Cunit_Ent : Entity_Id;
23101 Check_Ada_83_Warning;
23102 Check_Valid_Library_Unit_Pragma;
23104 if Nkind (N) = N_Null_Statement then
23108 Cunit_Node := Cunit (Current_Sem_Unit);
23109 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
23111 -- A pragma that applies to a Ghost entity becomes Ghost for the
23112 -- purposes of legality checks and removal of ignored Ghost code.
23114 Mark_Ghost_Pragma (N, Cunit_Ent);
23116 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
23117 N_Generic_Package_Declaration)
23120 ("pragma% can only apply to a package declaration");
23123 Set_Is_Shared_Passive (Cunit_Ent);
23124 end Shared_Passive;
23126 -----------------------
23127 -- Short_Descriptors --
23128 -----------------------
23130 -- pragma Short_Descriptors;
23132 -- Recognize and validate, but otherwise ignore
23134 when Pragma_Short_Descriptors =>
23136 Check_Arg_Count (0);
23137 Check_Valid_Configuration_Pragma;
23139 ------------------------------
23140 -- Simple_Storage_Pool_Type --
23141 ------------------------------
23143 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
23145 when Pragma_Simple_Storage_Pool_Type =>
23146 Simple_Storage_Pool_Type : declare
23152 Check_Arg_Count (1);
23153 Check_Arg_Is_Library_Level_Local_Name (Arg1);
23155 Type_Id := Get_Pragma_Arg (Arg1);
23156 Find_Type (Type_Id);
23157 Typ := Entity (Type_Id);
23159 if Typ = Any_Type then
23163 -- A pragma that applies to a Ghost entity becomes Ghost for the
23164 -- purposes of legality checks and removal of ignored Ghost code.
23166 Mark_Ghost_Pragma (N, Typ);
23168 -- We require the pragma to apply to a type declared in a package
23169 -- declaration, but not (immediately) within a package body.
23171 if Ekind (Current_Scope) /= E_Package
23172 or else In_Package_Body (Current_Scope)
23175 ("pragma% can only apply to type declared immediately "
23176 & "within a package declaration");
23179 -- A simple storage pool type must be an immutably limited record
23180 -- or private type. If the pragma is given for a private type,
23181 -- the full type is similarly restricted (which is checked later
23182 -- in Freeze_Entity).
23184 if Is_Record_Type (Typ)
23185 and then not Is_Limited_View (Typ)
23188 ("pragma% can only apply to explicitly limited record type");
23190 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
23192 ("pragma% can only apply to a private type that is limited");
23194 elsif not Is_Record_Type (Typ)
23195 and then not Is_Private_Type (Typ)
23198 ("pragma% can only apply to limited record or private type");
23201 Record_Rep_Item (Typ, N);
23202 end Simple_Storage_Pool_Type;
23204 ----------------------
23205 -- Source_File_Name --
23206 ----------------------
23208 -- There are five forms for this pragma:
23210 -- pragma Source_File_Name (
23211 -- [UNIT_NAME =>] unit_NAME,
23212 -- BODY_FILE_NAME => STRING_LITERAL
23213 -- [, [INDEX =>] INTEGER_LITERAL]);
23215 -- pragma Source_File_Name (
23216 -- [UNIT_NAME =>] unit_NAME,
23217 -- SPEC_FILE_NAME => STRING_LITERAL
23218 -- [, [INDEX =>] INTEGER_LITERAL]);
23220 -- pragma Source_File_Name (
23221 -- BODY_FILE_NAME => STRING_LITERAL
23222 -- [, DOT_REPLACEMENT => STRING_LITERAL]
23223 -- [, CASING => CASING_SPEC]);
23225 -- pragma Source_File_Name (
23226 -- SPEC_FILE_NAME => STRING_LITERAL
23227 -- [, DOT_REPLACEMENT => STRING_LITERAL]
23228 -- [, CASING => CASING_SPEC]);
23230 -- pragma Source_File_Name (
23231 -- SUBUNIT_FILE_NAME => STRING_LITERAL
23232 -- [, DOT_REPLACEMENT => STRING_LITERAL]
23233 -- [, CASING => CASING_SPEC]);
23235 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
23237 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
23238 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
23239 -- only be used when no project file is used, while SFNP can only be
23240 -- used when a project file is used.
23242 -- No processing here. Processing was completed during parsing, since
23243 -- we need to have file names set as early as possible. Units are
23244 -- loaded well before semantic processing starts.
23246 -- The only processing we defer to this point is the check for
23247 -- correct placement.
23249 when Pragma_Source_File_Name =>
23251 Check_Valid_Configuration_Pragma;
23253 ------------------------------
23254 -- Source_File_Name_Project --
23255 ------------------------------
23257 -- See Source_File_Name for syntax
23259 -- No processing here. Processing was completed during parsing, since
23260 -- we need to have file names set as early as possible. Units are
23261 -- loaded well before semantic processing starts.
23263 -- The only processing we defer to this point is the check for
23264 -- correct placement.
23266 when Pragma_Source_File_Name_Project =>
23268 Check_Valid_Configuration_Pragma;
23270 -- Check that a pragma Source_File_Name_Project is used only in a
23271 -- configuration pragmas file.
23273 -- Pragmas Source_File_Name_Project should only be generated by
23274 -- the Project Manager in configuration pragmas files.
23276 -- This is really an ugly test. It seems to depend on some
23277 -- accidental and undocumented property. At the very least it
23278 -- needs to be documented, but it would be better to have a
23279 -- clean way of testing if we are in a configuration file???
23281 if Present (Parent (N)) then
23283 ("pragma% can only appear in a configuration pragmas file");
23286 ----------------------
23287 -- Source_Reference --
23288 ----------------------
23290 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
23292 -- Nothing to do, all processing completed in Par.Prag, since we need
23293 -- the information for possible parser messages that are output.
23295 when Pragma_Source_Reference =>
23302 -- pragma SPARK_Mode [(On | Off)];
23304 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
23305 Mode_Id : SPARK_Mode_Type;
23307 procedure Check_Pragma_Conformance
23308 (Context_Pragma : Node_Id;
23309 Entity : Entity_Id;
23310 Entity_Pragma : Node_Id);
23311 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
23312 -- conformance of pragma N depending the following scenarios:
23314 -- If pragma Context_Pragma is not Empty, verify that pragma N is
23315 -- compatible with the pragma Context_Pragma that was inherited
23316 -- from the context:
23317 -- * If the mode of Context_Pragma is ON, then the new mode can
23319 -- * If the mode of Context_Pragma is OFF, then the only allowed
23320 -- new mode is also OFF. Emit error if this is not the case.
23322 -- If Entity is not Empty, verify that pragma N is compatible with
23323 -- pragma Entity_Pragma that belongs to Entity.
23324 -- * If Entity_Pragma is Empty, always issue an error as this
23325 -- corresponds to the case where a previous section of Entity
23326 -- has no SPARK_Mode set.
23327 -- * If the mode of Entity_Pragma is ON, then the new mode can
23329 -- * If the mode of Entity_Pragma is OFF, then the only allowed
23330 -- new mode is also OFF. Emit error if this is not the case.
23332 procedure Check_Library_Level_Entity (E : Entity_Id);
23333 -- Subsidiary to routines Process_xxx. Verify that the related
23334 -- entity E subject to pragma SPARK_Mode is library-level.
23336 procedure Process_Body (Decl : Node_Id);
23337 -- Verify the legality of pragma SPARK_Mode when it appears as the
23338 -- top of the body declarations of entry, package, protected unit,
23339 -- subprogram or task unit body denoted by Decl.
23341 procedure Process_Overloadable (Decl : Node_Id);
23342 -- Verify the legality of pragma SPARK_Mode when it applies to an
23343 -- entry or [generic] subprogram declaration denoted by Decl.
23345 procedure Process_Private_Part (Decl : Node_Id);
23346 -- Verify the legality of pragma SPARK_Mode when it appears at the
23347 -- top of the private declarations of a package spec, protected or
23348 -- task unit declaration denoted by Decl.
23350 procedure Process_Statement_Part (Decl : Node_Id);
23351 -- Verify the legality of pragma SPARK_Mode when it appears at the
23352 -- top of the statement sequence of a package body denoted by node
23355 procedure Process_Visible_Part (Decl : Node_Id);
23356 -- Verify the legality of pragma SPARK_Mode when it appears at the
23357 -- top of the visible declarations of a package spec, protected or
23358 -- task unit declaration denoted by Decl. The routine is also used
23359 -- on protected or task units declared without a definition.
23361 procedure Set_SPARK_Context;
23362 -- Subsidiary to routines Process_xxx. Set the global variables
23363 -- which represent the mode of the context from pragma N. Ensure
23364 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
23366 ------------------------------
23367 -- Check_Pragma_Conformance --
23368 ------------------------------
23370 procedure Check_Pragma_Conformance
23371 (Context_Pragma : Node_Id;
23372 Entity : Entity_Id;
23373 Entity_Pragma : Node_Id)
23375 Err_Id : Entity_Id;
23379 -- The current pragma may appear without an argument. If this
23380 -- is the case, associate all error messages with the pragma
23383 if Present (Arg1) then
23389 -- The mode of the current pragma is compared against that of
23390 -- an enclosing context.
23392 if Present (Context_Pragma) then
23393 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
23395 -- Issue an error if the new mode is less restrictive than
23396 -- that of the context.
23398 if Get_SPARK_Mode_From_Annotation (Context_Pragma) = Off
23399 and then Get_SPARK_Mode_From_Annotation (N) = On
23402 ("cannot change SPARK_Mode from Off to On", Err_N);
23403 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
23404 Error_Msg_N ("\SPARK_Mode was set to Off#", Err_N);
23409 -- The mode of the current pragma is compared against that of
23410 -- an initial package, protected type, subprogram or task type
23413 if Present (Entity) then
23415 -- A simple protected or task type is transformed into an
23416 -- anonymous type whose name cannot be used to issue error
23417 -- messages. Recover the original entity of the type.
23419 if Ekind_In (Entity, E_Protected_Type, E_Task_Type) then
23422 (Original_Node (Unit_Declaration_Node (Entity)));
23427 -- Both the initial declaration and the completion carry
23428 -- SPARK_Mode pragmas.
23430 if Present (Entity_Pragma) then
23431 pragma Assert (Nkind (Entity_Pragma) = N_Pragma);
23433 -- Issue an error if the new mode is less restrictive
23434 -- than that of the initial declaration.
23436 if Get_SPARK_Mode_From_Annotation (Entity_Pragma) = Off
23437 and then Get_SPARK_Mode_From_Annotation (N) = On
23439 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
23440 Error_Msg_Sloc := Sloc (Entity_Pragma);
23442 ("\value Off was set for SPARK_Mode on&#",
23447 -- Otherwise the initial declaration lacks a SPARK_Mode
23448 -- pragma in which case the current pragma is illegal as
23449 -- it cannot "complete".
23452 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
23453 Error_Msg_Sloc := Sloc (Err_Id);
23455 ("\no value was set for SPARK_Mode on&#",
23460 end Check_Pragma_Conformance;
23462 --------------------------------
23463 -- Check_Library_Level_Entity --
23464 --------------------------------
23466 procedure Check_Library_Level_Entity (E : Entity_Id) is
23467 procedure Add_Entity_To_Name_Buffer;
23468 -- Add the E_Kind of entity E to the name buffer
23470 -------------------------------
23471 -- Add_Entity_To_Name_Buffer --
23472 -------------------------------
23474 procedure Add_Entity_To_Name_Buffer is
23476 if Ekind_In (E, E_Entry, E_Entry_Family) then
23477 Add_Str_To_Name_Buffer ("entry");
23479 elsif Ekind_In (E, E_Generic_Package,
23483 Add_Str_To_Name_Buffer ("package");
23485 elsif Ekind_In (E, E_Protected_Body, E_Protected_Type) then
23486 Add_Str_To_Name_Buffer ("protected type");
23488 elsif Ekind_In (E, E_Function,
23489 E_Generic_Function,
23490 E_Generic_Procedure,
23494 Add_Str_To_Name_Buffer ("subprogram");
23497 pragma Assert (Ekind_In (E, E_Task_Body, E_Task_Type));
23498 Add_Str_To_Name_Buffer ("task type");
23500 end Add_Entity_To_Name_Buffer;
23504 Msg_1 : constant String := "incorrect placement of pragma%";
23507 -- Start of processing for Check_Library_Level_Entity
23510 -- A SPARK_Mode of On shall only apply to library-level
23511 -- entities, except for those in generic instances, which are
23512 -- ignored (even if the entity gets SPARK_Mode pragma attached
23513 -- in the AST, its effect is not taken into account unless the
23514 -- context already provides SPARK_Mode of On in GNATprove).
23516 if Get_SPARK_Mode_From_Annotation (N) = On
23517 and then not Is_Library_Level_Entity (E)
23518 and then Instantiation_Location (Sloc (N)) = No_Location
23520 Error_Msg_Name_1 := Pname;
23521 Error_Msg_N (Fix_Error (Msg_1), N);
23524 Add_Str_To_Name_Buffer ("\& is not a library-level ");
23525 Add_Entity_To_Name_Buffer;
23527 Msg_2 := Name_Find;
23528 Error_Msg_NE (Get_Name_String (Msg_2), N, E);
23532 end Check_Library_Level_Entity;
23538 procedure Process_Body (Decl : Node_Id) is
23539 Body_Id : constant Entity_Id := Defining_Entity (Decl);
23540 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
23543 -- Ignore pragma when applied to the special body created for
23544 -- inlining, recognized by its internal name _Parent.
23546 if Chars (Body_Id) = Name_uParent then
23550 Check_Library_Level_Entity (Body_Id);
23552 -- For entry bodies, verify the legality against:
23553 -- * The mode of the context
23554 -- * The mode of the spec (if any)
23556 if Nkind_In (Decl, N_Entry_Body, N_Subprogram_Body) then
23558 -- A stand-alone subprogram body
23560 if Body_Id = Spec_Id then
23561 Check_Pragma_Conformance
23562 (Context_Pragma => SPARK_Pragma (Body_Id),
23564 Entity_Pragma => Empty);
23566 -- An entry or subprogram body that completes a previous
23570 Check_Pragma_Conformance
23571 (Context_Pragma => SPARK_Pragma (Body_Id),
23573 Entity_Pragma => SPARK_Pragma (Spec_Id));
23577 Set_SPARK_Pragma (Body_Id, N);
23578 Set_SPARK_Pragma_Inherited (Body_Id, False);
23580 -- For package bodies, verify the legality against:
23581 -- * The mode of the context
23582 -- * The mode of the private part
23584 -- This case is separated from protected and task bodies
23585 -- because the statement part of the package body inherits
23586 -- the mode of the body declarations.
23588 elsif Nkind (Decl) = N_Package_Body then
23589 Check_Pragma_Conformance
23590 (Context_Pragma => SPARK_Pragma (Body_Id),
23592 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
23595 Set_SPARK_Pragma (Body_Id, N);
23596 Set_SPARK_Pragma_Inherited (Body_Id, False);
23597 Set_SPARK_Aux_Pragma (Body_Id, N);
23598 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
23600 -- For protected and task bodies, verify the legality against:
23601 -- * The mode of the context
23602 -- * The mode of the private part
23606 (Nkind_In (Decl, N_Protected_Body, N_Task_Body));
23608 Check_Pragma_Conformance
23609 (Context_Pragma => SPARK_Pragma (Body_Id),
23611 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
23614 Set_SPARK_Pragma (Body_Id, N);
23615 Set_SPARK_Pragma_Inherited (Body_Id, False);
23619 --------------------------
23620 -- Process_Overloadable --
23621 --------------------------
23623 procedure Process_Overloadable (Decl : Node_Id) is
23624 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23625 Spec_Typ : constant Entity_Id := Etype (Spec_Id);
23628 Check_Library_Level_Entity (Spec_Id);
23630 -- Verify the legality against:
23631 -- * The mode of the context
23633 Check_Pragma_Conformance
23634 (Context_Pragma => SPARK_Pragma (Spec_Id),
23636 Entity_Pragma => Empty);
23638 Set_SPARK_Pragma (Spec_Id, N);
23639 Set_SPARK_Pragma_Inherited (Spec_Id, False);
23641 -- When the pragma applies to the anonymous object created for
23642 -- a single task type, decorate the type as well. This scenario
23643 -- arises when the single task type lacks a task definition,
23644 -- therefore there is no issue with respect to a potential
23645 -- pragma SPARK_Mode in the private part.
23647 -- task type Anon_Task_Typ;
23648 -- Obj : Anon_Task_Typ;
23649 -- pragma SPARK_Mode ...;
23651 if Is_Single_Task_Object (Spec_Id) then
23652 Set_SPARK_Pragma (Spec_Typ, N);
23653 Set_SPARK_Pragma_Inherited (Spec_Typ, False);
23654 Set_SPARK_Aux_Pragma (Spec_Typ, N);
23655 Set_SPARK_Aux_Pragma_Inherited (Spec_Typ, True);
23657 end Process_Overloadable;
23659 --------------------------
23660 -- Process_Private_Part --
23661 --------------------------
23663 procedure Process_Private_Part (Decl : Node_Id) is
23664 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23667 Check_Library_Level_Entity (Spec_Id);
23669 -- Verify the legality against:
23670 -- * The mode of the visible declarations
23672 Check_Pragma_Conformance
23673 (Context_Pragma => Empty,
23675 Entity_Pragma => SPARK_Pragma (Spec_Id));
23678 Set_SPARK_Aux_Pragma (Spec_Id, N);
23679 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
23680 end Process_Private_Part;
23682 ----------------------------
23683 -- Process_Statement_Part --
23684 ----------------------------
23686 procedure Process_Statement_Part (Decl : Node_Id) is
23687 Body_Id : constant Entity_Id := Defining_Entity (Decl);
23690 Check_Library_Level_Entity (Body_Id);
23692 -- Verify the legality against:
23693 -- * The mode of the body declarations
23695 Check_Pragma_Conformance
23696 (Context_Pragma => Empty,
23698 Entity_Pragma => SPARK_Pragma (Body_Id));
23701 Set_SPARK_Aux_Pragma (Body_Id, N);
23702 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
23703 end Process_Statement_Part;
23705 --------------------------
23706 -- Process_Visible_Part --
23707 --------------------------
23709 procedure Process_Visible_Part (Decl : Node_Id) is
23710 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23711 Obj_Id : Entity_Id;
23714 Check_Library_Level_Entity (Spec_Id);
23716 -- Verify the legality against:
23717 -- * The mode of the context
23719 Check_Pragma_Conformance
23720 (Context_Pragma => SPARK_Pragma (Spec_Id),
23722 Entity_Pragma => Empty);
23724 -- A task unit declared without a definition does not set the
23725 -- SPARK_Mode of the context because the task does not have any
23726 -- entries that could inherit the mode.
23728 if not Nkind_In (Decl, N_Single_Task_Declaration,
23729 N_Task_Type_Declaration)
23734 Set_SPARK_Pragma (Spec_Id, N);
23735 Set_SPARK_Pragma_Inherited (Spec_Id, False);
23736 Set_SPARK_Aux_Pragma (Spec_Id, N);
23737 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
23739 -- When the pragma applies to a single protected or task type,
23740 -- decorate the corresponding anonymous object as well.
23742 -- protected Anon_Prot_Typ is
23743 -- pragma SPARK_Mode ...;
23745 -- end Anon_Prot_Typ;
23747 -- Obj : Anon_Prot_Typ;
23749 if Is_Single_Concurrent_Type (Spec_Id) then
23750 Obj_Id := Anonymous_Object (Spec_Id);
23752 Set_SPARK_Pragma (Obj_Id, N);
23753 Set_SPARK_Pragma_Inherited (Obj_Id, False);
23755 end Process_Visible_Part;
23757 -----------------------
23758 -- Set_SPARK_Context --
23759 -----------------------
23761 procedure Set_SPARK_Context is
23763 SPARK_Mode := Mode_Id;
23764 SPARK_Mode_Pragma := N;
23765 end Set_SPARK_Context;
23773 -- Start of processing for Do_SPARK_Mode
23776 -- When a SPARK_Mode pragma appears inside an instantiation whose
23777 -- enclosing context has SPARK_Mode set to "off", the pragma has
23778 -- no semantic effect.
23780 if Ignore_SPARK_Mode_Pragmas_In_Instance then
23781 Rewrite (N, Make_Null_Statement (Loc));
23787 Check_No_Identifiers;
23788 Check_At_Most_N_Arguments (1);
23790 -- Check the legality of the mode (no argument = ON)
23792 if Arg_Count = 1 then
23793 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23794 Mode := Chars (Get_Pragma_Arg (Arg1));
23799 Mode_Id := Get_SPARK_Mode_Type (Mode);
23800 Context := Parent (N);
23802 -- The pragma appears in a configuration file
23804 if No (Context) then
23805 Check_Valid_Configuration_Pragma;
23807 if Present (SPARK_Mode_Pragma) then
23810 Prev => SPARK_Mode_Pragma);
23816 -- The pragma acts as a configuration pragma in a compilation unit
23818 -- pragma SPARK_Mode ...;
23819 -- package Pack is ...;
23821 elsif Nkind (Context) = N_Compilation_Unit
23822 and then List_Containing (N) = Context_Items (Context)
23824 Check_Valid_Configuration_Pragma;
23827 -- Otherwise the placement of the pragma within the tree dictates
23828 -- its associated construct. Inspect the declarative list where
23829 -- the pragma resides to find a potential construct.
23833 while Present (Stmt) loop
23835 -- Skip prior pragmas, but check for duplicates. Note that
23836 -- this also takes care of pragmas generated for aspects.
23838 if Nkind (Stmt) = N_Pragma then
23839 if Pragma_Name (Stmt) = Pname then
23846 -- The pragma applies to an expression function that has
23847 -- already been rewritten into a subprogram declaration.
23849 -- function Expr_Func return ... is (...);
23850 -- pragma SPARK_Mode ...;
23852 elsif Nkind (Stmt) = N_Subprogram_Declaration
23853 and then Nkind (Original_Node (Stmt)) =
23854 N_Expression_Function
23856 Process_Overloadable (Stmt);
23859 -- The pragma applies to the anonymous object created for a
23860 -- single concurrent type.
23862 -- protected type Anon_Prot_Typ ...;
23863 -- Obj : Anon_Prot_Typ;
23864 -- pragma SPARK_Mode ...;
23866 elsif Nkind (Stmt) = N_Object_Declaration
23867 and then Is_Single_Concurrent_Object
23868 (Defining_Entity (Stmt))
23870 Process_Overloadable (Stmt);
23873 -- Skip internally generated code
23875 elsif not Comes_From_Source (Stmt) then
23878 -- The pragma applies to an entry or [generic] subprogram
23882 -- pragma SPARK_Mode ...;
23885 -- procedure Proc ...;
23886 -- pragma SPARK_Mode ...;
23888 elsif Nkind_In (Stmt, N_Generic_Subprogram_Declaration,
23889 N_Subprogram_Declaration)
23890 or else (Nkind (Stmt) = N_Entry_Declaration
23891 and then Is_Protected_Type
23892 (Scope (Defining_Entity (Stmt))))
23894 Process_Overloadable (Stmt);
23897 -- Otherwise the pragma does not apply to a legal construct
23898 -- or it does not appear at the top of a declarative or a
23899 -- statement list. Issue an error and stop the analysis.
23909 -- The pragma applies to a package or a subprogram that acts as
23910 -- a compilation unit.
23912 -- procedure Proc ...;
23913 -- pragma SPARK_Mode ...;
23915 if Nkind (Context) = N_Compilation_Unit_Aux then
23916 Context := Unit (Parent (Context));
23919 -- The pragma appears at the top of entry, package, protected
23920 -- unit, subprogram or task unit body declarations.
23922 -- entry Ent when ... is
23923 -- pragma SPARK_Mode ...;
23925 -- package body Pack is
23926 -- pragma SPARK_Mode ...;
23928 -- procedure Proc ... is
23929 -- pragma SPARK_Mode;
23931 -- protected body Prot is
23932 -- pragma SPARK_Mode ...;
23934 if Nkind_In (Context, N_Entry_Body,
23940 Process_Body (Context);
23942 -- The pragma appears at the top of the visible or private
23943 -- declaration of a package spec, protected or task unit.
23946 -- pragma SPARK_Mode ...;
23948 -- pragma SPARK_Mode ...;
23950 -- protected [type] Prot is
23951 -- pragma SPARK_Mode ...;
23953 -- pragma SPARK_Mode ...;
23955 elsif Nkind_In (Context, N_Package_Specification,
23956 N_Protected_Definition,
23959 if List_Containing (N) = Visible_Declarations (Context) then
23960 Process_Visible_Part (Parent (Context));
23962 Process_Private_Part (Parent (Context));
23965 -- The pragma appears at the top of package body statements
23967 -- package body Pack is
23969 -- pragma SPARK_Mode;
23971 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
23972 and then Nkind (Parent (Context)) = N_Package_Body
23974 Process_Statement_Part (Parent (Context));
23976 -- The pragma appeared as an aspect of a [generic] subprogram
23977 -- declaration that acts as a compilation unit.
23980 -- procedure Proc ...;
23981 -- pragma SPARK_Mode ...;
23983 elsif Nkind_In (Context, N_Generic_Subprogram_Declaration,
23984 N_Subprogram_Declaration)
23986 Process_Overloadable (Context);
23988 -- The pragma does not apply to a legal construct, issue error
23996 --------------------------------
23997 -- Static_Elaboration_Desired --
23998 --------------------------------
24000 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
24002 when Pragma_Static_Elaboration_Desired =>
24004 Check_At_Most_N_Arguments (1);
24006 if Is_Compilation_Unit (Current_Scope)
24007 and then Ekind (Current_Scope) = E_Package
24009 Set_Static_Elaboration_Desired (Current_Scope, True);
24011 Error_Pragma ("pragma% must apply to a library-level package");
24018 -- pragma Storage_Size (EXPRESSION);
24020 when Pragma_Storage_Size => Storage_Size : declare
24021 P : constant Node_Id := Parent (N);
24025 Check_No_Identifiers;
24026 Check_Arg_Count (1);
24028 -- The expression must be analyzed in the special manner described
24029 -- in "Handling of Default Expressions" in sem.ads.
24031 Arg := Get_Pragma_Arg (Arg1);
24032 Preanalyze_Spec_Expression (Arg, Any_Integer);
24034 if not Is_OK_Static_Expression (Arg) then
24035 Check_Restriction (Static_Storage_Size, Arg);
24038 if Nkind (P) /= N_Task_Definition then
24043 if Has_Storage_Size_Pragma (P) then
24044 Error_Pragma ("duplicate pragma% not allowed");
24046 Set_Has_Storage_Size_Pragma (P, True);
24049 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
24057 -- pragma Storage_Unit (NUMERIC_LITERAL);
24059 -- Only permitted argument is System'Storage_Unit value
24061 when Pragma_Storage_Unit =>
24062 Check_No_Identifiers;
24063 Check_Arg_Count (1);
24064 Check_Arg_Is_Integer_Literal (Arg1);
24066 if Intval (Get_Pragma_Arg (Arg1)) /=
24067 UI_From_Int (Ttypes.System_Storage_Unit)
24069 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
24071 ("the only allowed argument for pragma% is ^", Arg1);
24074 --------------------
24075 -- Stream_Convert --
24076 --------------------
24078 -- pragma Stream_Convert (
24079 -- [Entity =>] type_LOCAL_NAME,
24080 -- [Read =>] function_NAME,
24081 -- [Write =>] function NAME);
24083 when Pragma_Stream_Convert => Stream_Convert : declare
24084 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
24085 -- Check that the given argument is the name of a local function
24086 -- of one argument that is not overloaded earlier in the current
24087 -- local scope. A check is also made that the argument is a
24088 -- function with one parameter.
24090 --------------------------------------
24091 -- Check_OK_Stream_Convert_Function --
24092 --------------------------------------
24094 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
24098 Check_Arg_Is_Local_Name (Arg);
24099 Ent := Entity (Get_Pragma_Arg (Arg));
24101 if Has_Homonym (Ent) then
24103 ("argument for pragma% may not be overloaded", Arg);
24106 if Ekind (Ent) /= E_Function
24107 or else No (First_Formal (Ent))
24108 or else Present (Next_Formal (First_Formal (Ent)))
24111 ("argument for pragma% must be function of one argument",
24114 end Check_OK_Stream_Convert_Function;
24116 -- Start of processing for Stream_Convert
24120 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
24121 Check_Arg_Count (3);
24122 Check_Optional_Identifier (Arg1, Name_Entity);
24123 Check_Optional_Identifier (Arg2, Name_Read);
24124 Check_Optional_Identifier (Arg3, Name_Write);
24125 Check_Arg_Is_Local_Name (Arg1);
24126 Check_OK_Stream_Convert_Function (Arg2);
24127 Check_OK_Stream_Convert_Function (Arg3);
24130 Typ : constant Entity_Id :=
24131 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
24132 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
24133 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
24136 Check_First_Subtype (Arg1);
24138 -- Check for too early or too late. Note that we don't enforce
24139 -- the rule about primitive operations in this case, since, as
24140 -- is the case for explicit stream attributes themselves, these
24141 -- restrictions are not appropriate. Note that the chaining of
24142 -- the pragma by Rep_Item_Too_Late is actually the critical
24143 -- processing done for this pragma.
24145 if Rep_Item_Too_Early (Typ, N)
24147 Rep_Item_Too_Late (Typ, N, FOnly => True)
24152 -- Return if previous error
24154 if Etype (Typ) = Any_Type
24156 Etype (Read) = Any_Type
24158 Etype (Write) = Any_Type
24165 if Underlying_Type (Etype (Read)) /= Typ then
24167 ("incorrect return type for function&", Arg2);
24170 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
24172 ("incorrect parameter type for function&", Arg3);
24175 if Underlying_Type (Etype (First_Formal (Read))) /=
24176 Underlying_Type (Etype (Write))
24179 ("result type of & does not match Read parameter type",
24183 end Stream_Convert;
24189 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
24191 -- This is processed by the parser since some of the style checks
24192 -- take place during source scanning and parsing. This means that
24193 -- we don't need to issue error messages here.
24195 when Pragma_Style_Checks => Style_Checks : declare
24196 A : constant Node_Id := Get_Pragma_Arg (Arg1);
24202 Check_No_Identifiers;
24204 -- Two argument form
24206 if Arg_Count = 2 then
24207 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
24214 E_Id := Get_Pragma_Arg (Arg2);
24217 if not Is_Entity_Name (E_Id) then
24219 ("second argument of pragma% must be entity name",
24223 E := Entity (E_Id);
24225 if not Ignore_Style_Checks_Pragmas then
24230 Set_Suppress_Style_Checks
24231 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
24232 exit when No (Homonym (E));
24239 -- One argument form
24242 Check_Arg_Count (1);
24244 if Nkind (A) = N_String_Literal then
24248 Slen : constant Natural := Natural (String_Length (S));
24249 Options : String (1 .. Slen);
24255 C := Get_String_Char (S, Pos (J));
24256 exit when not In_Character_Range (C);
24257 Options (J) := Get_Character (C);
24259 -- If at end of string, set options. As per discussion
24260 -- above, no need to check for errors, since we issued
24261 -- them in the parser.
24264 if not Ignore_Style_Checks_Pragmas then
24265 Set_Style_Check_Options (Options);
24275 elsif Nkind (A) = N_Identifier then
24276 if Chars (A) = Name_All_Checks then
24277 if not Ignore_Style_Checks_Pragmas then
24279 Set_GNAT_Style_Check_Options;
24281 Set_Default_Style_Check_Options;
24285 elsif Chars (A) = Name_On then
24286 if not Ignore_Style_Checks_Pragmas then
24287 Style_Check := True;
24290 elsif Chars (A) = Name_Off then
24291 if not Ignore_Style_Checks_Pragmas then
24292 Style_Check := False;
24303 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
24305 when Pragma_Subtitle =>
24307 Check_Arg_Count (1);
24308 Check_Optional_Identifier (Arg1, Name_Subtitle);
24309 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
24316 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
24318 when Pragma_Suppress =>
24319 Process_Suppress_Unsuppress (Suppress_Case => True);
24325 -- pragma Suppress_All;
24327 -- The only check made here is that the pragma has no arguments.
24328 -- There are no placement rules, and the processing required (setting
24329 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
24330 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
24331 -- then creates and inserts a pragma Suppress (All_Checks).
24333 when Pragma_Suppress_All =>
24335 Check_Arg_Count (0);
24337 -------------------------
24338 -- Suppress_Debug_Info --
24339 -------------------------
24341 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
24343 when Pragma_Suppress_Debug_Info => Suppress_Debug_Info : declare
24344 Nam_Id : Entity_Id;
24348 Check_Arg_Count (1);
24349 Check_Optional_Identifier (Arg1, Name_Entity);
24350 Check_Arg_Is_Local_Name (Arg1);
24352 Nam_Id := Entity (Get_Pragma_Arg (Arg1));
24354 -- A pragma that applies to a Ghost entity becomes Ghost for the
24355 -- purposes of legality checks and removal of ignored Ghost code.
24357 Mark_Ghost_Pragma (N, Nam_Id);
24358 Set_Debug_Info_Off (Nam_Id);
24359 end Suppress_Debug_Info;
24361 ----------------------------------
24362 -- Suppress_Exception_Locations --
24363 ----------------------------------
24365 -- pragma Suppress_Exception_Locations;
24367 when Pragma_Suppress_Exception_Locations =>
24369 Check_Arg_Count (0);
24370 Check_Valid_Configuration_Pragma;
24371 Exception_Locations_Suppressed := True;
24373 -----------------------------
24374 -- Suppress_Initialization --
24375 -----------------------------
24377 -- pragma Suppress_Initialization ([Entity =>] type_Name);
24379 when Pragma_Suppress_Initialization => Suppress_Init : declare
24385 Check_Arg_Count (1);
24386 Check_Optional_Identifier (Arg1, Name_Entity);
24387 Check_Arg_Is_Local_Name (Arg1);
24389 E_Id := Get_Pragma_Arg (Arg1);
24391 if Etype (E_Id) = Any_Type then
24395 E := Entity (E_Id);
24397 -- A pragma that applies to a Ghost entity becomes Ghost for the
24398 -- purposes of legality checks and removal of ignored Ghost code.
24400 Mark_Ghost_Pragma (N, E);
24402 if not Is_Type (E) and then Ekind (E) /= E_Variable then
24404 ("pragma% requires variable, type or subtype", Arg1);
24407 if Rep_Item_Too_Early (E, N)
24409 Rep_Item_Too_Late (E, N, FOnly => True)
24414 -- For incomplete/private type, set flag on full view
24416 if Is_Incomplete_Or_Private_Type (E) then
24417 if No (Full_View (Base_Type (E))) then
24419 ("argument of pragma% cannot be an incomplete type", Arg1);
24421 Set_Suppress_Initialization (Full_View (E));
24424 -- For first subtype, set flag on base type
24426 elsif Is_First_Subtype (E) then
24427 Set_Suppress_Initialization (Base_Type (E));
24429 -- For other than first subtype, set flag on subtype or variable
24432 Set_Suppress_Initialization (E);
24440 -- pragma System_Name (DIRECT_NAME);
24442 -- Syntax check: one argument, which must be the identifier GNAT or
24443 -- the identifier GCC, no other identifiers are acceptable.
24445 when Pragma_System_Name =>
24447 Check_No_Identifiers;
24448 Check_Arg_Count (1);
24449 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
24451 -----------------------------
24452 -- Task_Dispatching_Policy --
24453 -----------------------------
24455 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
24457 when Pragma_Task_Dispatching_Policy => declare
24461 Check_Ada_83_Warning;
24462 Check_Arg_Count (1);
24463 Check_No_Identifiers;
24464 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
24465 Check_Valid_Configuration_Pragma;
24466 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
24467 DP := Fold_Upper (Name_Buffer (1));
24469 if Task_Dispatching_Policy /= ' '
24470 and then Task_Dispatching_Policy /= DP
24472 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
24474 ("task dispatching policy incompatible with policy#");
24476 -- Set new policy, but always preserve System_Location since we
24477 -- like the error message with the run time name.
24480 Task_Dispatching_Policy := DP;
24482 if Task_Dispatching_Policy_Sloc /= System_Location then
24483 Task_Dispatching_Policy_Sloc := Loc;
24492 -- pragma Task_Info (EXPRESSION);
24494 when Pragma_Task_Info => Task_Info : declare
24495 P : constant Node_Id := Parent (N);
24501 if Warn_On_Obsolescent_Feature then
24503 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
24504 & "instead?j?", N);
24507 if Nkind (P) /= N_Task_Definition then
24508 Error_Pragma ("pragma% must appear in task definition");
24511 Check_No_Identifiers;
24512 Check_Arg_Count (1);
24514 Analyze_And_Resolve
24515 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
24517 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
24521 Ent := Defining_Identifier (Parent (P));
24523 -- Check duplicate pragma before we chain the pragma in the Rep
24524 -- Item chain of Ent.
24527 (Ent, Name_Task_Info, Check_Parents => False)
24529 Error_Pragma ("duplicate pragma% not allowed");
24532 Record_Rep_Item (Ent, N);
24539 -- pragma Task_Name (string_EXPRESSION);
24541 when Pragma_Task_Name => Task_Name : declare
24542 P : constant Node_Id := Parent (N);
24547 Check_No_Identifiers;
24548 Check_Arg_Count (1);
24550 Arg := Get_Pragma_Arg (Arg1);
24552 -- The expression is used in the call to Create_Task, and must be
24553 -- expanded there, not in the context of the current spec. It must
24554 -- however be analyzed to capture global references, in case it
24555 -- appears in a generic context.
24557 Preanalyze_And_Resolve (Arg, Standard_String);
24559 if Nkind (P) /= N_Task_Definition then
24563 Ent := Defining_Identifier (Parent (P));
24565 -- Check duplicate pragma before we chain the pragma in the Rep
24566 -- Item chain of Ent.
24569 (Ent, Name_Task_Name, Check_Parents => False)
24571 Error_Pragma ("duplicate pragma% not allowed");
24574 Record_Rep_Item (Ent, N);
24581 -- pragma Task_Storage (
24582 -- [Task_Type =>] LOCAL_NAME,
24583 -- [Top_Guard =>] static_integer_EXPRESSION);
24585 when Pragma_Task_Storage => Task_Storage : declare
24586 Args : Args_List (1 .. 2);
24587 Names : constant Name_List (1 .. 2) := (
24591 Task_Type : Node_Id renames Args (1);
24592 Top_Guard : Node_Id renames Args (2);
24598 Gather_Associations (Names, Args);
24600 if No (Task_Type) then
24602 ("missing task_type argument for pragma%");
24605 Check_Arg_Is_Local_Name (Task_Type);
24607 Ent := Entity (Task_Type);
24609 if not Is_Task_Type (Ent) then
24611 ("argument for pragma% must be task type", Task_Type);
24614 if No (Top_Guard) then
24616 ("pragma% takes two arguments", Task_Type);
24618 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
24621 Check_First_Subtype (Task_Type);
24623 if Rep_Item_Too_Late (Ent, N) then
24632 -- pragma Test_Case
24633 -- ([Name =>] Static_String_EXPRESSION
24634 -- ,[Mode =>] MODE_TYPE
24635 -- [, Requires => Boolean_EXPRESSION]
24636 -- [, Ensures => Boolean_EXPRESSION]);
24638 -- MODE_TYPE ::= Nominal | Robustness
24640 -- Characteristics:
24642 -- * Analysis - The annotation undergoes initial checks to verify
24643 -- the legal placement and context. Secondary checks preanalyze the
24646 -- Analyze_Test_Case_In_Decl_Part
24648 -- * Expansion - None.
24650 -- * Template - The annotation utilizes the generic template of the
24651 -- related subprogram when it is:
24653 -- aspect on subprogram declaration
24655 -- The annotation must prepare its own template when it is:
24657 -- pragma on subprogram declaration
24659 -- * Globals - Capture of global references must occur after full
24662 -- * Instance - The annotation is instantiated automatically when
24663 -- the related generic subprogram is instantiated except for the
24664 -- "pragma on subprogram declaration" case. In that scenario the
24665 -- annotation must instantiate itself.
24667 when Pragma_Test_Case => Test_Case : declare
24668 procedure Check_Distinct_Name (Subp_Id : Entity_Id);
24669 -- Ensure that the contract of subprogram Subp_Id does not contain
24670 -- another Test_Case pragma with the same Name as the current one.
24672 -------------------------
24673 -- Check_Distinct_Name --
24674 -------------------------
24676 procedure Check_Distinct_Name (Subp_Id : Entity_Id) is
24677 Items : constant Node_Id := Contract (Subp_Id);
24678 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
24682 -- Inspect all Test_Case pragma of the related subprogram
24683 -- looking for one with a duplicate "Name" argument.
24685 if Present (Items) then
24686 Prag := Contract_Test_Cases (Items);
24687 while Present (Prag) loop
24688 if Pragma_Name (Prag) = Name_Test_Case
24690 and then String_Equal
24691 (Name, Get_Name_From_CTC_Pragma (Prag))
24693 Error_Msg_Sloc := Sloc (Prag);
24694 Error_Pragma ("name for pragma % is already used #");
24697 Prag := Next_Pragma (Prag);
24700 end Check_Distinct_Name;
24704 Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit));
24707 Subp_Decl : Node_Id;
24708 Subp_Id : Entity_Id;
24710 -- Start of processing for Test_Case
24714 Check_At_Least_N_Arguments (2);
24715 Check_At_Most_N_Arguments (4);
24717 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
24721 Check_Optional_Identifier (Arg1, Name_Name);
24722 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
24726 Check_Optional_Identifier (Arg2, Name_Mode);
24727 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
24729 -- Arguments "Requires" and "Ensures"
24731 if Present (Arg3) then
24732 if Present (Arg4) then
24733 Check_Identifier (Arg3, Name_Requires);
24734 Check_Identifier (Arg4, Name_Ensures);
24736 Check_Identifier_Is_One_Of
24737 (Arg3, Name_Requires, Name_Ensures);
24741 -- Pragma Test_Case must be associated with a subprogram declared
24742 -- in a library-level package. First determine whether the current
24743 -- compilation unit is a legal context.
24745 if Nkind_In (Pack_Decl, N_Package_Declaration,
24746 N_Generic_Package_Declaration)
24750 -- Otherwise the placement is illegal
24754 ("pragma % must be specified within a package declaration");
24758 Subp_Decl := Find_Related_Declaration_Or_Body (N);
24760 -- Find the enclosing context
24762 Context := Parent (Subp_Decl);
24764 if Present (Context) then
24765 Context := Parent (Context);
24768 -- Verify the placement of the pragma
24770 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
24772 ("pragma % cannot be applied to abstract subprogram");
24775 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
24776 Error_Pragma ("pragma % cannot be applied to entry");
24779 -- The context is a [generic] subprogram declared at the top level
24780 -- of the [generic] package unit.
24782 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
24783 N_Subprogram_Declaration)
24784 and then Present (Context)
24785 and then Nkind_In (Context, N_Generic_Package_Declaration,
24786 N_Package_Declaration)
24790 -- Otherwise the placement is illegal
24794 ("pragma % must be applied to a library-level subprogram "
24799 Subp_Id := Defining_Entity (Subp_Decl);
24801 -- A pragma that applies to a Ghost entity becomes Ghost for the
24802 -- purposes of legality checks and removal of ignored Ghost code.
24804 Mark_Ghost_Pragma (N, Subp_Id);
24806 -- Chain the pragma on the contract for further processing by
24807 -- Analyze_Test_Case_In_Decl_Part.
24809 Add_Contract_Item (N, Subp_Id);
24811 -- Preanalyze the original aspect argument "Name" for a generic
24812 -- subprogram to properly capture global references.
24814 if Is_Generic_Subprogram (Subp_Id) then
24815 Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True);
24817 if Present (Asp_Arg) then
24819 -- The argument appears with an identifier in association
24822 if Nkind (Asp_Arg) = N_Component_Association then
24823 Asp_Arg := Expression (Asp_Arg);
24826 Check_Expr_Is_OK_Static_Expression
24827 (Asp_Arg, Standard_String);
24831 -- Ensure that the all Test_Case pragmas of the related subprogram
24832 -- have distinct names.
24834 Check_Distinct_Name (Subp_Id);
24836 -- Fully analyze the pragma when it appears inside an entry
24837 -- or subprogram body because it cannot benefit from forward
24840 if Nkind_In (Subp_Decl, N_Entry_Body,
24842 N_Subprogram_Body_Stub)
24844 -- The legality checks of pragma Test_Case are affected by the
24845 -- SPARK mode in effect and the volatility of the context.
24846 -- Analyze all pragmas in a specific order.
24848 Analyze_If_Present (Pragma_SPARK_Mode);
24849 Analyze_If_Present (Pragma_Volatile_Function);
24850 Analyze_Test_Case_In_Decl_Part (N);
24854 --------------------------
24855 -- Thread_Local_Storage --
24856 --------------------------
24858 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
24860 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
24866 Check_Arg_Count (1);
24867 Check_Optional_Identifier (Arg1, Name_Entity);
24868 Check_Arg_Is_Library_Level_Local_Name (Arg1);
24870 Id := Get_Pragma_Arg (Arg1);
24873 if not Is_Entity_Name (Id)
24874 or else Ekind (Entity (Id)) /= E_Variable
24876 Error_Pragma_Arg ("local variable name required", Arg1);
24881 -- A pragma that applies to a Ghost entity becomes Ghost for the
24882 -- purposes of legality checks and removal of ignored Ghost code.
24884 Mark_Ghost_Pragma (N, E);
24886 if Rep_Item_Too_Early (E, N)
24888 Rep_Item_Too_Late (E, N)
24893 Set_Has_Pragma_Thread_Local_Storage (E);
24894 Set_Has_Gigi_Rep_Item (E);
24895 end Thread_Local_Storage;
24901 -- pragma Time_Slice (static_duration_EXPRESSION);
24903 when Pragma_Time_Slice => Time_Slice : declare
24909 Check_Arg_Count (1);
24910 Check_No_Identifiers;
24911 Check_In_Main_Program;
24912 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
24914 if not Error_Posted (Arg1) then
24916 while Present (Nod) loop
24917 if Nkind (Nod) = N_Pragma
24918 and then Pragma_Name (Nod) = Name_Time_Slice
24920 Error_Msg_Name_1 := Pname;
24921 Error_Msg_N ("duplicate pragma% not permitted", Nod);
24928 -- Process only if in main unit
24930 if Get_Source_Unit (Loc) = Main_Unit then
24931 Opt.Time_Slice_Set := True;
24932 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
24934 if Val <= Ureal_0 then
24935 Opt.Time_Slice_Value := 0;
24937 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
24938 Opt.Time_Slice_Value := 1_000_000_000;
24941 Opt.Time_Slice_Value :=
24942 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
24951 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
24953 -- TITLING_OPTION ::=
24954 -- [Title =>] STRING_LITERAL
24955 -- | [Subtitle =>] STRING_LITERAL
24957 when Pragma_Title => Title : declare
24958 Args : Args_List (1 .. 2);
24959 Names : constant Name_List (1 .. 2) := (
24965 Gather_Associations (Names, Args);
24968 for J in 1 .. 2 loop
24969 if Present (Args (J)) then
24970 Check_Arg_Is_OK_Static_Expression
24971 (Args (J), Standard_String);
24976 ----------------------------
24977 -- Type_Invariant[_Class] --
24978 ----------------------------
24980 -- pragma Type_Invariant[_Class]
24981 -- ([Entity =>] type_LOCAL_NAME,
24982 -- [Check =>] EXPRESSION);
24984 when Pragma_Type_Invariant
24985 | Pragma_Type_Invariant_Class
24987 Type_Invariant : declare
24988 I_Pragma : Node_Id;
24991 Check_Arg_Count (2);
24993 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
24994 -- setting Class_Present for the Type_Invariant_Class case.
24996 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
24997 I_Pragma := New_Copy (N);
24998 Set_Pragma_Identifier
24999 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
25000 Rewrite (N, I_Pragma);
25001 Set_Analyzed (N, False);
25003 end Type_Invariant;
25005 ---------------------
25006 -- Unchecked_Union --
25007 ---------------------
25009 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
25011 when Pragma_Unchecked_Union => Unchecked_Union : declare
25012 Assoc : constant Node_Id := Arg1;
25013 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
25023 Check_No_Identifiers;
25024 Check_Arg_Count (1);
25025 Check_Arg_Is_Local_Name (Arg1);
25027 Find_Type (Type_Id);
25029 Typ := Entity (Type_Id);
25031 -- A pragma that applies to a Ghost entity becomes Ghost for the
25032 -- purposes of legality checks and removal of ignored Ghost code.
25034 Mark_Ghost_Pragma (N, Typ);
25037 or else Rep_Item_Too_Early (Typ, N)
25041 Typ := Underlying_Type (Typ);
25044 if Rep_Item_Too_Late (Typ, N) then
25048 Check_First_Subtype (Arg1);
25050 -- Note remaining cases are references to a type in the current
25051 -- declarative part. If we find an error, we post the error on
25052 -- the relevant type declaration at an appropriate point.
25054 if not Is_Record_Type (Typ) then
25055 Error_Msg_N ("unchecked union must be record type", Typ);
25058 elsif Is_Tagged_Type (Typ) then
25059 Error_Msg_N ("unchecked union must not be tagged", Typ);
25062 elsif not Has_Discriminants (Typ) then
25064 ("unchecked union must have one discriminant", Typ);
25067 -- Note: in previous versions of GNAT we used to check for limited
25068 -- types and give an error, but in fact the standard does allow
25069 -- Unchecked_Union on limited types, so this check was removed.
25071 -- Similarly, GNAT used to require that all discriminants have
25072 -- default values, but this is not mandated by the RM.
25074 -- Proceed with basic error checks completed
25077 Tdef := Type_Definition (Declaration_Node (Typ));
25078 Clist := Component_List (Tdef);
25080 -- Check presence of component list and variant part
25082 if No (Clist) or else No (Variant_Part (Clist)) then
25084 ("unchecked union must have variant part", Tdef);
25088 -- Check components
25090 Comp := First_Non_Pragma (Component_Items (Clist));
25091 while Present (Comp) loop
25092 Check_Component (Comp, Typ);
25093 Next_Non_Pragma (Comp);
25096 -- Check variant part
25098 Vpart := Variant_Part (Clist);
25100 Variant := First_Non_Pragma (Variants (Vpart));
25101 while Present (Variant) loop
25102 Check_Variant (Variant, Typ);
25103 Next_Non_Pragma (Variant);
25107 Set_Is_Unchecked_Union (Typ);
25108 Set_Convention (Typ, Convention_C);
25109 Set_Has_Unchecked_Union (Base_Type (Typ));
25110 Set_Is_Unchecked_Union (Base_Type (Typ));
25111 end Unchecked_Union;
25113 ----------------------------
25114 -- Unevaluated_Use_Of_Old --
25115 ----------------------------
25117 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
25119 when Pragma_Unevaluated_Use_Of_Old =>
25121 Check_Arg_Count (1);
25122 Check_No_Identifiers;
25123 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
25125 -- Suppress/Unsuppress can appear as a configuration pragma, or in
25126 -- a declarative part or a package spec.
25128 if not Is_Configuration_Pragma then
25129 Check_Is_In_Decl_Part_Or_Package_Spec;
25132 -- Store proper setting of Uneval_Old
25134 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
25135 Uneval_Old := Fold_Upper (Name_Buffer (1));
25137 ------------------------
25138 -- Unimplemented_Unit --
25139 ------------------------
25141 -- pragma Unimplemented_Unit;
25143 -- Note: this only gives an error if we are generating code, or if
25144 -- we are in a generic library unit (where the pragma appears in the
25145 -- body, not in the spec).
25147 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
25148 Cunitent : constant Entity_Id :=
25149 Cunit_Entity (Get_Source_Unit (Loc));
25150 Ent_Kind : constant Entity_Kind := Ekind (Cunitent);
25154 Check_Arg_Count (0);
25156 if Operating_Mode = Generate_Code
25157 or else Ent_Kind = E_Generic_Function
25158 or else Ent_Kind = E_Generic_Procedure
25159 or else Ent_Kind = E_Generic_Package
25161 Get_Name_String (Chars (Cunitent));
25162 Set_Casing (Mixed_Case);
25163 Write_Str (Name_Buffer (1 .. Name_Len));
25164 Write_Str (" is not supported in this configuration");
25166 raise Unrecoverable_Error;
25168 end Unimplemented_Unit;
25170 ------------------------
25171 -- Universal_Aliasing --
25172 ------------------------
25174 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
25176 when Pragma_Universal_Aliasing => Universal_Alias : declare
25182 Check_Arg_Count (1);
25183 Check_Optional_Identifier (Arg2, Name_Entity);
25184 Check_Arg_Is_Local_Name (Arg1);
25185 E_Id := Get_Pragma_Arg (Arg1);
25187 if Etype (E_Id) = Any_Type then
25191 E := Entity (E_Id);
25193 if not Is_Type (E) then
25194 Error_Pragma_Arg ("pragma% requires type", Arg1);
25197 -- A pragma that applies to a Ghost entity becomes Ghost for the
25198 -- purposes of legality checks and removal of ignored Ghost code.
25200 Mark_Ghost_Pragma (N, E);
25201 Set_Universal_Aliasing (Base_Type (E));
25202 Record_Rep_Item (E, N);
25203 end Universal_Alias;
25205 --------------------
25206 -- Universal_Data --
25207 --------------------
25209 -- pragma Universal_Data [(library_unit_NAME)];
25211 when Pragma_Universal_Data =>
25213 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
25219 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
25221 when Pragma_Unmodified =>
25222 Analyze_Unmodified_Or_Unused;
25228 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
25230 -- or when used in a context clause:
25232 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
25234 when Pragma_Unreferenced =>
25235 Analyze_Unreferenced_Or_Unused;
25237 --------------------------
25238 -- Unreferenced_Objects --
25239 --------------------------
25241 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
25243 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
25245 Arg_Expr : Node_Id;
25246 Arg_Id : Entity_Id;
25248 Ghost_Error_Posted : Boolean := False;
25249 -- Flag set when an error concerning the illegal mix of Ghost and
25250 -- non-Ghost types is emitted.
25252 Ghost_Id : Entity_Id := Empty;
25253 -- The entity of the first Ghost type encountered while processing
25254 -- the arguments of the pragma.
25258 Check_At_Least_N_Arguments (1);
25261 while Present (Arg) loop
25262 Check_No_Identifier (Arg);
25263 Check_Arg_Is_Local_Name (Arg);
25264 Arg_Expr := Get_Pragma_Arg (Arg);
25266 if Is_Entity_Name (Arg_Expr) then
25267 Arg_Id := Entity (Arg_Expr);
25269 if Is_Type (Arg_Id) then
25270 Set_Has_Pragma_Unreferenced_Objects (Arg_Id);
25272 -- A pragma that applies to a Ghost entity becomes Ghost
25273 -- for the purposes of legality checks and removal of
25274 -- ignored Ghost code.
25276 Mark_Ghost_Pragma (N, Arg_Id);
25278 -- Capture the entity of the first Ghost type being
25279 -- processed for error detection purposes.
25281 if Is_Ghost_Entity (Arg_Id) then
25282 if No (Ghost_Id) then
25283 Ghost_Id := Arg_Id;
25286 -- Otherwise the type is non-Ghost. It is illegal to mix
25287 -- references to Ghost and non-Ghost entities
25290 elsif Present (Ghost_Id)
25291 and then not Ghost_Error_Posted
25293 Ghost_Error_Posted := True;
25295 Error_Msg_Name_1 := Pname;
25297 ("pragma % cannot mention ghost and non-ghost types",
25300 Error_Msg_Sloc := Sloc (Ghost_Id);
25301 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
25303 Error_Msg_Sloc := Sloc (Arg_Id);
25304 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
25308 ("argument for pragma% must be type or subtype", Arg);
25312 ("argument for pragma% must be type or subtype", Arg);
25317 end Unreferenced_Objects;
25319 ------------------------------
25320 -- Unreserve_All_Interrupts --
25321 ------------------------------
25323 -- pragma Unreserve_All_Interrupts;
25325 when Pragma_Unreserve_All_Interrupts =>
25327 Check_Arg_Count (0);
25329 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
25330 Unreserve_All_Interrupts := True;
25337 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
25339 when Pragma_Unsuppress =>
25341 Process_Suppress_Unsuppress (Suppress_Case => False);
25347 -- pragma Unused (LOCAL_NAME {, LOCAL_NAME});
25349 when Pragma_Unused =>
25350 Analyze_Unmodified_Or_Unused (Is_Unused => True);
25351 Analyze_Unreferenced_Or_Unused (Is_Unused => True);
25353 -------------------
25354 -- Use_VADS_Size --
25355 -------------------
25357 -- pragma Use_VADS_Size;
25359 when Pragma_Use_VADS_Size =>
25361 Check_Arg_Count (0);
25362 Check_Valid_Configuration_Pragma;
25363 Use_VADS_Size := True;
25365 ---------------------
25366 -- Validity_Checks --
25367 ---------------------
25369 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
25371 when Pragma_Validity_Checks => Validity_Checks : declare
25372 A : constant Node_Id := Get_Pragma_Arg (Arg1);
25378 Check_Arg_Count (1);
25379 Check_No_Identifiers;
25381 -- Pragma always active unless in CodePeer or GNATprove modes,
25382 -- which use a fixed configuration of validity checks.
25384 if not (CodePeer_Mode or GNATprove_Mode) then
25385 if Nkind (A) = N_String_Literal then
25389 Slen : constant Natural := Natural (String_Length (S));
25390 Options : String (1 .. Slen);
25394 -- Couldn't we use a for loop here over Options'Range???
25398 C := Get_String_Char (S, Pos (J));
25400 -- This is a weird test, it skips setting validity
25401 -- checks entirely if any element of S is out of
25402 -- range of Character, what is that about ???
25404 exit when not In_Character_Range (C);
25405 Options (J) := Get_Character (C);
25408 Set_Validity_Check_Options (Options);
25416 elsif Nkind (A) = N_Identifier then
25417 if Chars (A) = Name_All_Checks then
25418 Set_Validity_Check_Options ("a");
25419 elsif Chars (A) = Name_On then
25420 Validity_Checks_On := True;
25421 elsif Chars (A) = Name_Off then
25422 Validity_Checks_On := False;
25426 end Validity_Checks;
25432 -- pragma Volatile (LOCAL_NAME);
25434 when Pragma_Volatile =>
25435 Process_Atomic_Independent_Shared_Volatile;
25437 -------------------------
25438 -- Volatile_Components --
25439 -------------------------
25441 -- pragma Volatile_Components (array_LOCAL_NAME);
25443 -- Volatile is handled by the same circuit as Atomic_Components
25445 --------------------------
25446 -- Volatile_Full_Access --
25447 --------------------------
25449 -- pragma Volatile_Full_Access (LOCAL_NAME);
25451 when Pragma_Volatile_Full_Access =>
25453 Process_Atomic_Independent_Shared_Volatile;
25455 -----------------------
25456 -- Volatile_Function --
25457 -----------------------
25459 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
25461 when Pragma_Volatile_Function => Volatile_Function : declare
25462 Over_Id : Entity_Id;
25463 Spec_Id : Entity_Id;
25464 Subp_Decl : Node_Id;
25468 Check_No_Identifiers;
25469 Check_At_Most_N_Arguments (1);
25472 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
25474 -- Generic subprogram
25476 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
25479 -- Body acts as spec
25481 elsif Nkind (Subp_Decl) = N_Subprogram_Body
25482 and then No (Corresponding_Spec (Subp_Decl))
25486 -- Body stub acts as spec
25488 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
25489 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
25495 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
25503 Spec_Id := Unique_Defining_Entity (Subp_Decl);
25505 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
25510 -- A pragma that applies to a Ghost entity becomes Ghost for the
25511 -- purposes of legality checks and removal of ignored Ghost code.
25513 Mark_Ghost_Pragma (N, Spec_Id);
25515 -- Chain the pragma on the contract for completeness
25517 Add_Contract_Item (N, Spec_Id);
25519 -- The legality checks of pragma Volatile_Function are affected by
25520 -- the SPARK mode in effect. Analyze all pragmas in a specific
25523 Analyze_If_Present (Pragma_SPARK_Mode);
25525 -- A volatile function cannot override a non-volatile function
25526 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
25527 -- in New_Overloaded_Entity, however at that point the pragma has
25528 -- not been processed yet.
25530 Over_Id := Overridden_Operation (Spec_Id);
25532 if Present (Over_Id)
25533 and then not Is_Volatile_Function (Over_Id)
25536 ("incompatible volatile function values in effect", Spec_Id);
25538 Error_Msg_Sloc := Sloc (Over_Id);
25540 ("\& declared # with Volatile_Function value False",
25543 Error_Msg_Sloc := Sloc (Spec_Id);
25545 ("\overridden # with Volatile_Function value True",
25549 -- Analyze the Boolean expression (if any)
25551 if Present (Arg1) then
25552 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
25554 end Volatile_Function;
25556 ----------------------
25557 -- Warning_As_Error --
25558 ----------------------
25560 -- pragma Warning_As_Error (static_string_EXPRESSION);
25562 when Pragma_Warning_As_Error =>
25564 Check_Arg_Count (1);
25565 Check_No_Identifiers;
25566 Check_Valid_Configuration_Pragma;
25568 if not Is_Static_String_Expression (Arg1) then
25570 ("argument of pragma% must be static string expression",
25573 -- OK static string expression
25576 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
25577 Warnings_As_Errors (Warnings_As_Errors_Count) :=
25578 new String'(Acquire_Warning_Match_String
25579 (Expr_Value_S (Get_Pragma_Arg (Arg1))));
25586 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
25588 -- DETAILS ::= On | Off
25589 -- DETAILS ::= On | Off, local_NAME
25590 -- DETAILS ::= static_string_EXPRESSION
25591 -- DETAILS ::= On | Off, static_string_EXPRESSION
25593 -- TOOL_NAME ::= GNAT | GNATProve
25595 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
25597 -- Note: If the first argument matches an allowed tool name, it is
25598 -- always considered to be a tool name, even if there is a string
25599 -- variable of that name.
25601 -- Note if the second argument of DETAILS is a local_NAME then the
25602 -- second form is always understood. If the intention is to use
25603 -- the fourth form, then you can write NAME & "" to force the
25604 -- intepretation as a static_string_EXPRESSION.
25606 when Pragma_Warnings => Warnings : declare
25607 Reason : String_Id;
25611 Check_At_Least_N_Arguments (1);
25613 -- See if last argument is labeled Reason. If so, make sure we
25614 -- have a string literal or a concatenation of string literals,
25615 -- and acquire the REASON string. Then remove the REASON argument
25616 -- by decreasing Num_Args by one; Remaining processing looks only
25617 -- at first Num_Args arguments).
25620 Last_Arg : constant Node_Id :=
25621 Last (Pragma_Argument_Associations (N));
25624 if Nkind (Last_Arg) = N_Pragma_Argument_Association
25625 and then Chars (Last_Arg) = Name_Reason
25628 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
25629 Reason := End_String;
25630 Arg_Count := Arg_Count - 1;
25632 -- Not allowed in compiler units (bootstrap issues)
25634 Check_Compiler_Unit ("Reason for pragma Warnings", N);
25636 -- No REASON string, set null string as reason
25639 Reason := Null_String_Id;
25643 -- Now proceed with REASON taken care of and eliminated
25645 Check_No_Identifiers;
25647 -- If debug flag -gnatd.i is set, pragma is ignored
25649 if Debug_Flag_Dot_I then
25653 -- Process various forms of the pragma
25656 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
25657 Shifted_Args : List_Id;
25660 -- See if first argument is a tool name, currently either
25661 -- GNAT or GNATprove. If so, either ignore the pragma if the
25662 -- tool used does not match, or continue as if no tool name
25663 -- was given otherwise, by shifting the arguments.
25665 if Nkind (Argx) = N_Identifier
25666 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
25668 if Chars (Argx) = Name_Gnat then
25669 if CodePeer_Mode or GNATprove_Mode then
25670 Rewrite (N, Make_Null_Statement (Loc));
25675 elsif Chars (Argx) = Name_Gnatprove then
25676 if not GNATprove_Mode then
25677 Rewrite (N, Make_Null_Statement (Loc));
25683 raise Program_Error;
25686 -- At this point, the pragma Warnings applies to the tool,
25687 -- so continue with shifted arguments.
25689 Arg_Count := Arg_Count - 1;
25691 if Arg_Count = 1 then
25692 Shifted_Args := New_List (New_Copy (Arg2));
25693 elsif Arg_Count = 2 then
25694 Shifted_Args := New_List (New_Copy (Arg2),
25696 elsif Arg_Count = 3 then
25697 Shifted_Args := New_List (New_Copy (Arg2),
25701 raise Program_Error;
25706 Chars => Name_Warnings,
25707 Pragma_Argument_Associations => Shifted_Args));
25712 -- One argument case
25714 if Arg_Count = 1 then
25716 -- On/Off one argument case was processed by parser
25718 if Nkind (Argx) = N_Identifier
25719 and then Nam_In (Chars (Argx), Name_On, Name_Off)
25723 -- One argument case must be ON/OFF or static string expr
25725 elsif not Is_Static_String_Expression (Arg1) then
25727 ("argument of pragma% must be On/Off or static string "
25728 & "expression", Arg1);
25730 -- One argument string expression case
25734 Lit : constant Node_Id := Expr_Value_S (Argx);
25735 Str : constant String_Id := Strval (Lit);
25736 Len : constant Nat := String_Length (Str);
25744 while J <= Len loop
25745 C := Get_String_Char (Str, J);
25746 OK := In_Character_Range (C);
25749 Chr := Get_Character (C);
25751 -- Dash case: only -Wxxx is accepted
25758 C := Get_String_Char (Str, J);
25759 Chr := Get_Character (C);
25760 exit when Chr = 'W';
25765 elsif J < Len and then Chr = '.' then
25767 C := Get_String_Char (Str, J);
25768 Chr := Get_Character (C);
25770 if not Set_Dot_Warning_Switch (Chr) then
25772 ("invalid warning switch character "
25773 & '.' & Chr, Arg1);
25779 OK := Set_Warning_Switch (Chr);
25784 ("invalid warning switch character " & Chr,
25790 ("invalid wide character in warning switch ",
25799 -- Two or more arguments (must be two)
25802 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
25803 Check_Arg_Count (2);
25811 E_Id := Get_Pragma_Arg (Arg2);
25814 -- In the expansion of an inlined body, a reference to
25815 -- the formal may be wrapped in a conversion if the
25816 -- actual is a conversion. Retrieve the real entity name.
25818 if (In_Instance_Body or In_Inlined_Body)
25819 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
25821 E_Id := Expression (E_Id);
25824 -- Entity name case
25826 if Is_Entity_Name (E_Id) then
25827 E := Entity (E_Id);
25834 (E, (Chars (Get_Pragma_Arg (Arg1)) =
25837 -- Suppress elaboration warnings if the entity
25838 -- denotes an elaboration target.
25840 if Is_Elaboration_Target (E) then
25841 Set_Is_Elaboration_Warnings_OK_Id (E, False);
25844 -- For OFF case, make entry in warnings off
25845 -- pragma table for later processing. But we do
25846 -- not do that within an instance, since these
25847 -- warnings are about what is needed in the
25848 -- template, not an instance of it.
25850 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
25851 and then Warn_On_Warnings_Off
25852 and then not In_Instance
25854 Warnings_Off_Pragmas.Append ((N, E, Reason));
25857 if Is_Enumeration_Type (E) then
25861 Lit := First_Literal (E);
25862 while Present (Lit) loop
25863 Set_Warnings_Off (Lit);
25864 Next_Literal (Lit);
25869 exit when No (Homonym (E));
25874 -- Error if not entity or static string expression case
25876 elsif not Is_Static_String_Expression (Arg2) then
25878 ("second argument of pragma% must be entity name "
25879 & "or static string expression", Arg2);
25881 -- Static string expression case
25884 -- Note on configuration pragma case: If this is a
25885 -- configuration pragma, then for an OFF pragma, we
25886 -- just set Config True in the call, which is all
25887 -- that needs to be done. For the case of ON, this
25888 -- is normally an error, unless it is canceling the
25889 -- effect of a previous OFF pragma in the same file.
25890 -- In any other case, an error will be signalled (ON
25891 -- with no matching OFF).
25893 -- Note: We set Used if we are inside a generic to
25894 -- disable the test that the non-config case actually
25895 -- cancels a warning. That's because we can't be sure
25896 -- there isn't an instantiation in some other unit
25897 -- where a warning is suppressed.
25899 -- We could do a little better here by checking if the
25900 -- generic unit we are inside is public, but for now
25901 -- we don't bother with that refinement.
25904 Message : constant String :=
25905 Acquire_Warning_Match_String
25906 (Expr_Value_S (Get_Pragma_Arg (Arg2)));
25908 if Chars (Argx) = Name_Off then
25909 Set_Specific_Warning_Off
25910 (Loc, Message, Reason,
25911 Config => Is_Configuration_Pragma,
25912 Used => Inside_A_Generic or else In_Instance);
25914 elsif Chars (Argx) = Name_On then
25915 Set_Specific_Warning_On (Loc, Message, Err);
25919 ("??pragma Warnings On with no matching "
25920 & "Warnings Off", Loc);
25930 -------------------
25931 -- Weak_External --
25932 -------------------
25934 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
25936 when Pragma_Weak_External => Weak_External : declare
25941 Check_Arg_Count (1);
25942 Check_Optional_Identifier (Arg1, Name_Entity);
25943 Check_Arg_Is_Library_Level_Local_Name (Arg1);
25944 Ent := Entity (Get_Pragma_Arg (Arg1));
25946 if Rep_Item_Too_Early (Ent, N) then
25949 Ent := Underlying_Type (Ent);
25952 -- The pragma applies to entities with addresses
25954 if Is_Type (Ent) then
25955 Error_Pragma ("pragma applies to objects and subprograms");
25958 -- The only processing required is to link this item on to the
25959 -- list of rep items for the given entity. This is accomplished
25960 -- by the call to Rep_Item_Too_Late (when no error is detected
25961 -- and False is returned).
25963 if Rep_Item_Too_Late (Ent, N) then
25966 Set_Has_Gigi_Rep_Item (Ent);
25970 -----------------------------
25971 -- Wide_Character_Encoding --
25972 -----------------------------
25974 -- pragma Wide_Character_Encoding (IDENTIFIER);
25976 when Pragma_Wide_Character_Encoding =>
25979 -- Nothing to do, handled in parser. Note that we do not enforce
25980 -- configuration pragma placement, this pragma can appear at any
25981 -- place in the source, allowing mixed encodings within a single
25986 --------------------
25987 -- Unknown_Pragma --
25988 --------------------
25990 -- Should be impossible, since the case of an unknown pragma is
25991 -- separately processed before the case statement is entered.
25993 when Unknown_Pragma =>
25994 raise Program_Error;
25997 -- AI05-0144: detect dangerous order dependence. Disabled for now,
25998 -- until AI is formally approved.
26000 -- Check_Order_Dependence;
26003 when Pragma_Exit => null;
26004 end Analyze_Pragma;
26006 ---------------------------------------------
26007 -- Analyze_Pre_Post_Condition_In_Decl_Part --
26008 ---------------------------------------------
26010 -- WARNING: This routine manages Ghost regions. Return statements must be
26011 -- replaced by gotos which jump to the end of the routine and restore the
26014 procedure Analyze_Pre_Post_Condition_In_Decl_Part
26016 Freeze_Id : Entity_Id := Empty)
26018 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
26019 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
26021 Disp_Typ : Entity_Id;
26022 -- The dispatching type of the subprogram subject to the pre- or
26025 function Check_References (Nod : Node_Id) return Traverse_Result;
26026 -- Check that expression Nod does not mention non-primitives of the
26027 -- type, global objects of the type, or other illegalities described
26028 -- and implied by AI12-0113.
26030 ----------------------
26031 -- Check_References --
26032 ----------------------
26034 function Check_References (Nod : Node_Id) return Traverse_Result is
26036 if Nkind (Nod) = N_Function_Call
26037 and then Is_Entity_Name (Name (Nod))
26040 Func : constant Entity_Id := Entity (Name (Nod));
26044 -- An operation of the type must be a primitive
26046 if No (Find_Dispatching_Type (Func)) then
26047 Form := First_Formal (Func);
26048 while Present (Form) loop
26049 if Etype (Form) = Disp_Typ then
26051 ("operation in class-wide condition must be "
26052 & "primitive of &", Nod, Disp_Typ);
26055 Next_Formal (Form);
26058 -- A return object of the type is illegal as well
26060 if Etype (Func) = Disp_Typ
26061 or else Etype (Func) = Class_Wide_Type (Disp_Typ)
26064 ("operation in class-wide condition must be primitive "
26065 & "of &", Nod, Disp_Typ);
26068 -- Otherwise we have a call to an overridden primitive, and we
26069 -- will create a common class-wide clone for the body of
26070 -- original operation and its eventual inherited versions. If
26071 -- the original operation dispatches on result it is never
26072 -- inherited and there is no need for a clone. There is not
26073 -- need for a clone either in GNATprove mode, as cases that
26074 -- would require it are rejected (when an inherited primitive
26075 -- calls an overridden operation in a class-wide contract), and
26076 -- the clone would make proof impossible in some cases.
26078 elsif not Is_Abstract_Subprogram (Spec_Id)
26079 and then No (Class_Wide_Clone (Spec_Id))
26080 and then not Has_Controlling_Result (Spec_Id)
26081 and then not GNATprove_Mode
26083 Build_Class_Wide_Clone_Decl (Spec_Id);
26087 elsif Is_Entity_Name (Nod)
26089 (Etype (Nod) = Disp_Typ
26090 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
26091 and then Ekind_In (Entity (Nod), E_Constant, E_Variable)
26094 ("object in class-wide condition must be formal of type &",
26097 elsif Nkind (Nod) = N_Explicit_Dereference
26098 and then (Etype (Nod) = Disp_Typ
26099 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
26100 and then (not Is_Entity_Name (Prefix (Nod))
26101 or else not Is_Formal (Entity (Prefix (Nod))))
26104 ("operation in class-wide condition must be primitive of &",
26109 end Check_References;
26111 procedure Check_Class_Wide_Condition is
26112 new Traverse_Proc (Check_References);
26116 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
26118 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
26119 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
26120 -- Save the Ghost-related attributes to restore on exit
26123 Restore_Scope : Boolean := False;
26125 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
26128 -- Do not analyze the pragma multiple times
26130 if Is_Analyzed_Pragma (N) then
26134 -- Set the Ghost mode in effect from the pragma. Due to the delayed
26135 -- analysis of the pragma, the Ghost mode at point of declaration and
26136 -- point of analysis may not necessarily be the same. Use the mode in
26137 -- effect at the point of declaration.
26139 Set_Ghost_Mode (N);
26141 -- Ensure that the subprogram and its formals are visible when analyzing
26142 -- the expression of the pragma.
26144 if not In_Open_Scopes (Spec_Id) then
26145 Restore_Scope := True;
26146 Push_Scope (Spec_Id);
26148 if Is_Generic_Subprogram (Spec_Id) then
26149 Install_Generic_Formals (Spec_Id);
26151 Install_Formals (Spec_Id);
26155 Errors := Serious_Errors_Detected;
26156 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
26158 -- Emit a clarification message when the expression contains at least
26159 -- one undefined reference, possibly due to contract freezing.
26161 if Errors /= Serious_Errors_Detected
26162 and then Present (Freeze_Id)
26163 and then Has_Undefined_Reference (Expr)
26165 Contract_Freeze_Error (Spec_Id, Freeze_Id);
26168 if Class_Present (N) then
26170 -- Verify that a class-wide condition is legal, i.e. the operation is
26171 -- a primitive of a tagged type. Note that a generic subprogram is
26172 -- not a primitive operation.
26174 Disp_Typ := Find_Dispatching_Type (Spec_Id);
26176 if No (Disp_Typ) or else Is_Generic_Subprogram (Spec_Id) then
26177 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
26179 if From_Aspect_Specification (N) then
26181 ("aspect % can only be specified for a primitive operation "
26182 & "of a tagged type", Corresponding_Aspect (N));
26184 -- The pragma is a source construct
26188 ("pragma % can only be specified for a primitive operation "
26189 & "of a tagged type", N);
26192 -- Remaining semantic checks require a full tree traversal
26195 Check_Class_Wide_Condition (Expr);
26200 if Restore_Scope then
26204 -- If analysis of the condition indicates that a class-wide clone
26205 -- has been created, build and analyze its declaration.
26207 if Is_Subprogram (Spec_Id)
26208 and then Present (Class_Wide_Clone (Spec_Id))
26210 Analyze (Unit_Declaration_Node (Class_Wide_Clone (Spec_Id)));
26213 -- Currently it is not possible to inline pre/postconditions on a
26214 -- subprogram subject to pragma Inline_Always.
26216 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
26217 Set_Is_Analyzed_Pragma (N);
26219 Restore_Ghost_Region (Saved_GM, Saved_IGR);
26220 end Analyze_Pre_Post_Condition_In_Decl_Part;
26222 ------------------------------------------
26223 -- Analyze_Refined_Depends_In_Decl_Part --
26224 ------------------------------------------
26226 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
26227 procedure Check_Dependency_Clause
26228 (Spec_Id : Entity_Id;
26229 Dep_Clause : Node_Id;
26230 Dep_States : Elist_Id;
26231 Refinements : List_Id;
26232 Matched_Items : in out Elist_Id);
26233 -- Try to match a single dependency clause Dep_Clause against one or
26234 -- more refinement clauses found in list Refinements. Each successful
26235 -- match eliminates at least one refinement clause from Refinements.
26236 -- Spec_Id denotes the entity of the related subprogram. Dep_States
26237 -- denotes the entities of all abstract states which appear in pragma
26238 -- Depends. Matched_Items contains the entities of all successfully
26239 -- matched items found in pragma Depends.
26241 procedure Check_Output_States
26242 (Spec_Inputs : Elist_Id;
26243 Spec_Outputs : Elist_Id;
26244 Body_Inputs : Elist_Id;
26245 Body_Outputs : Elist_Id);
26246 -- Determine whether pragma Depends contains an output state with a
26247 -- visible refinement and if so, ensure that pragma Refined_Depends
26248 -- mentions all its constituents as outputs. Spec_Inputs and
26249 -- Spec_Outputs denote the inputs and outputs of the subprogram spec
26250 -- synthesized from pragma Depends. Body_Inputs and Body_Outputs denote
26251 -- the inputs and outputs of the subprogram body synthesized from pragma
26252 -- Refined_Depends.
26254 function Collect_States (Clauses : List_Id) return Elist_Id;
26255 -- Given a normalized list of dependencies obtained from calling
26256 -- Normalize_Clauses, return a list containing the entities of all
26257 -- states appearing in dependencies. It helps in checking refinements
26258 -- involving a state and a corresponding constituent which is not a
26259 -- direct constituent of the state.
26261 procedure Normalize_Clauses (Clauses : List_Id);
26262 -- Given a list of dependence or refinement clauses Clauses, normalize
26263 -- each clause by creating multiple dependencies with exactly one input
26266 procedure Remove_Extra_Clauses
26267 (Clauses : List_Id;
26268 Matched_Items : Elist_Id);
26269 -- Given a list of refinement clauses Clauses, remove all clauses whose
26270 -- inputs and/or outputs have been previously matched. See the body for
26271 -- all special cases. Matched_Items contains the entities of all matched
26272 -- items found in pragma Depends.
26274 procedure Report_Extra_Clauses (Clauses : List_Id);
26275 -- Emit an error for each extra clause found in list Clauses
26277 -----------------------------
26278 -- Check_Dependency_Clause --
26279 -----------------------------
26281 procedure Check_Dependency_Clause
26282 (Spec_Id : Entity_Id;
26283 Dep_Clause : Node_Id;
26284 Dep_States : Elist_Id;
26285 Refinements : List_Id;
26286 Matched_Items : in out Elist_Id)
26288 Dep_Input : constant Node_Id := Expression (Dep_Clause);
26289 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
26291 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean;
26292 -- Determine whether dependency item Dep_Item has been matched in a
26293 -- previous clause.
26295 function Is_In_Out_State_Clause return Boolean;
26296 -- Determine whether dependence clause Dep_Clause denotes an abstract
26297 -- state that depends on itself (State => State).
26299 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
26300 -- Determine whether item Item denotes an abstract state with visible
26301 -- null refinement.
26303 procedure Match_Items
26304 (Dep_Item : Node_Id;
26305 Ref_Item : Node_Id;
26306 Matched : out Boolean);
26307 -- Try to match dependence item Dep_Item against refinement item
26308 -- Ref_Item. To match against a possible null refinement (see 2, 9),
26309 -- set Ref_Item to Empty. Flag Matched is set to True when one of
26310 -- the following conformance scenarios is in effect:
26311 -- 1) Both items denote null
26312 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
26313 -- 3) Both items denote attribute 'Result
26314 -- 4) Both items denote the same object
26315 -- 5) Both items denote the same formal parameter
26316 -- 6) Both items denote the same current instance of a type
26317 -- 7) Both items denote the same discriminant
26318 -- 8) Dep_Item is an abstract state with visible null refinement
26319 -- and Ref_Item denotes null.
26320 -- 9) Dep_Item is an abstract state with visible null refinement
26321 -- and Ref_Item is Empty (special case).
26322 -- 10) Dep_Item is an abstract state with full or partial visible
26323 -- non-null refinement and Ref_Item denotes one of its
26325 -- 11) Dep_Item is an abstract state without a full visible
26326 -- refinement and Ref_Item denotes the same state.
26327 -- When scenario 10 is in effect, the entity of the abstract state
26328 -- denoted by Dep_Item is added to list Refined_States.
26330 procedure Record_Item (Item_Id : Entity_Id);
26331 -- Store the entity of an item denoted by Item_Id in Matched_Items
26333 ------------------------
26334 -- Is_Already_Matched --
26335 ------------------------
26337 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean is
26338 Item_Id : Entity_Id := Empty;
26341 -- When the dependency item denotes attribute 'Result, check for
26342 -- the entity of the related subprogram.
26344 if Is_Attribute_Result (Dep_Item) then
26345 Item_Id := Spec_Id;
26347 elsif Is_Entity_Name (Dep_Item) then
26348 Item_Id := Available_View (Entity_Of (Dep_Item));
26352 Present (Item_Id) and then Contains (Matched_Items, Item_Id);
26353 end Is_Already_Matched;
26355 ----------------------------
26356 -- Is_In_Out_State_Clause --
26357 ----------------------------
26359 function Is_In_Out_State_Clause return Boolean is
26360 Dep_Input_Id : Entity_Id;
26361 Dep_Output_Id : Entity_Id;
26364 -- Detect the following clause:
26367 if Is_Entity_Name (Dep_Input)
26368 and then Is_Entity_Name (Dep_Output)
26370 -- Handle abstract views generated for limited with clauses
26372 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
26373 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
26376 Ekind (Dep_Input_Id) = E_Abstract_State
26377 and then Dep_Input_Id = Dep_Output_Id;
26381 end Is_In_Out_State_Clause;
26383 ---------------------------
26384 -- Is_Null_Refined_State --
26385 ---------------------------
26387 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
26388 Item_Id : Entity_Id;
26391 if Is_Entity_Name (Item) then
26393 -- Handle abstract views generated for limited with clauses
26395 Item_Id := Available_View (Entity_Of (Item));
26398 Ekind (Item_Id) = E_Abstract_State
26399 and then Has_Null_Visible_Refinement (Item_Id);
26403 end Is_Null_Refined_State;
26409 procedure Match_Items
26410 (Dep_Item : Node_Id;
26411 Ref_Item : Node_Id;
26412 Matched : out Boolean)
26414 Dep_Item_Id : Entity_Id;
26415 Ref_Item_Id : Entity_Id;
26418 -- Assume that the two items do not match
26422 -- A null matches null or Empty (special case)
26424 if Nkind (Dep_Item) = N_Null
26425 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
26429 -- Attribute 'Result matches attribute 'Result
26431 elsif Is_Attribute_Result (Dep_Item)
26432 and then Is_Attribute_Result (Ref_Item)
26434 -- Put the entity of the related function on the list of
26435 -- matched items because attribute 'Result does not carry
26436 -- an entity similar to states and constituents.
26438 Record_Item (Spec_Id);
26441 -- Abstract states, current instances of concurrent types,
26442 -- discriminants, formal parameters and objects.
26444 elsif Is_Entity_Name (Dep_Item) then
26446 -- Handle abstract views generated for limited with clauses
26448 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
26450 if Ekind (Dep_Item_Id) = E_Abstract_State then
26452 -- An abstract state with visible null refinement matches
26453 -- null or Empty (special case).
26455 if Has_Null_Visible_Refinement (Dep_Item_Id)
26456 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
26458 Record_Item (Dep_Item_Id);
26461 -- An abstract state with visible non-null refinement
26462 -- matches one of its constituents, or itself for an
26463 -- abstract state with partial visible refinement.
26465 elsif Has_Non_Null_Visible_Refinement (Dep_Item_Id) then
26466 if Is_Entity_Name (Ref_Item) then
26467 Ref_Item_Id := Entity_Of (Ref_Item);
26469 if Ekind_In (Ref_Item_Id, E_Abstract_State,
26472 and then Present (Encapsulating_State (Ref_Item_Id))
26473 and then Find_Encapsulating_State
26474 (Dep_States, Ref_Item_Id) = Dep_Item_Id
26476 Record_Item (Dep_Item_Id);
26479 elsif not Has_Visible_Refinement (Dep_Item_Id)
26480 and then Ref_Item_Id = Dep_Item_Id
26482 Record_Item (Dep_Item_Id);
26487 -- An abstract state without a visible refinement matches
26490 elsif Is_Entity_Name (Ref_Item)
26491 and then Entity_Of (Ref_Item) = Dep_Item_Id
26493 Record_Item (Dep_Item_Id);
26497 -- A current instance of a concurrent type, discriminant,
26498 -- formal parameter or an object matches itself.
26500 elsif Is_Entity_Name (Ref_Item)
26501 and then Entity_Of (Ref_Item) = Dep_Item_Id
26503 Record_Item (Dep_Item_Id);
26513 procedure Record_Item (Item_Id : Entity_Id) is
26515 if No (Matched_Items) then
26516 Matched_Items := New_Elmt_List;
26519 Append_Unique_Elmt (Item_Id, Matched_Items);
26524 Clause_Matched : Boolean := False;
26525 Dummy : Boolean := False;
26526 Inputs_Match : Boolean;
26527 Next_Ref_Clause : Node_Id;
26528 Outputs_Match : Boolean;
26529 Ref_Clause : Node_Id;
26530 Ref_Input : Node_Id;
26531 Ref_Output : Node_Id;
26533 -- Start of processing for Check_Dependency_Clause
26536 -- Do not perform this check in an instance because it was already
26537 -- performed successfully in the generic template.
26539 if In_Instance then
26543 -- Examine all refinement clauses and compare them against the
26544 -- dependence clause.
26546 Ref_Clause := First (Refinements);
26547 while Present (Ref_Clause) loop
26548 Next_Ref_Clause := Next (Ref_Clause);
26550 -- Obtain the attributes of the current refinement clause
26552 Ref_Input := Expression (Ref_Clause);
26553 Ref_Output := First (Choices (Ref_Clause));
26555 -- The current refinement clause matches the dependence clause
26556 -- when both outputs match and both inputs match. See routine
26557 -- Match_Items for all possible conformance scenarios.
26559 -- Depends Dep_Output => Dep_Input
26563 -- Refined_Depends Ref_Output => Ref_Input
26566 (Dep_Item => Dep_Input,
26567 Ref_Item => Ref_Input,
26568 Matched => Inputs_Match);
26571 (Dep_Item => Dep_Output,
26572 Ref_Item => Ref_Output,
26573 Matched => Outputs_Match);
26575 -- An In_Out state clause may be matched against a refinement with
26576 -- a null input or null output as long as the non-null side of the
26577 -- relation contains a valid constituent of the In_Out_State.
26579 if Is_In_Out_State_Clause then
26581 -- Depends => (State => State)
26582 -- Refined_Depends => (null => Constit) -- OK
26585 and then not Outputs_Match
26586 and then Nkind (Ref_Output) = N_Null
26588 Outputs_Match := True;
26591 -- Depends => (State => State)
26592 -- Refined_Depends => (Constit => null) -- OK
26594 if not Inputs_Match
26595 and then Outputs_Match
26596 and then Nkind (Ref_Input) = N_Null
26598 Inputs_Match := True;
26602 -- The current refinement clause is legally constructed following
26603 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
26604 -- the pool of candidates. The seach continues because a single
26605 -- dependence clause may have multiple matching refinements.
26607 if Inputs_Match and Outputs_Match then
26608 Clause_Matched := True;
26609 Remove (Ref_Clause);
26612 Ref_Clause := Next_Ref_Clause;
26615 -- Depending on the order or composition of refinement clauses, an
26616 -- In_Out state clause may not be directly refinable.
26618 -- Refined_State => (State => (Constit_1, Constit_2))
26619 -- Depends => ((Output, State) => (Input, State))
26620 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
26622 -- Matching normalized clause (State => State) fails because there is
26623 -- no direct refinement capable of satisfying this relation. Another
26624 -- similar case arises when clauses (Constit_1 => Input) and (Output
26625 -- => Constit_2) are matched first, leaving no candidates for clause
26626 -- (State => State). Both scenarios are legal as long as one of the
26627 -- previous clauses mentioned a valid constituent of State.
26629 if not Clause_Matched
26630 and then Is_In_Out_State_Clause
26631 and then Is_Already_Matched (Dep_Input)
26633 Clause_Matched := True;
26636 -- A clause where the input is an abstract state with visible null
26637 -- refinement or a 'Result attribute is implicitly matched when the
26638 -- output has already been matched in a previous clause.
26640 -- Refined_State => (State => null)
26641 -- Depends => (Output => State) -- implicitly OK
26642 -- Refined_Depends => (Output => ...)
26643 -- Depends => (...'Result => State) -- implicitly OK
26644 -- Refined_Depends => (...'Result => ...)
26646 if not Clause_Matched
26647 and then Is_Null_Refined_State (Dep_Input)
26648 and then Is_Already_Matched (Dep_Output)
26650 Clause_Matched := True;
26653 -- A clause where the output is an abstract state with visible null
26654 -- refinement is implicitly matched when the input has already been
26655 -- matched in a previous clause.
26657 -- Refined_State => (State => null)
26658 -- Depends => (State => Input) -- implicitly OK
26659 -- Refined_Depends => (... => Input)
26661 if not Clause_Matched
26662 and then Is_Null_Refined_State (Dep_Output)
26663 and then Is_Already_Matched (Dep_Input)
26665 Clause_Matched := True;
26668 -- At this point either all refinement clauses have been examined or
26669 -- pragma Refined_Depends contains a solitary null. Only an abstract
26670 -- state with null refinement can possibly match these cases.
26672 -- Refined_State => (State => null)
26673 -- Depends => (State => null)
26674 -- Refined_Depends => null -- OK
26676 if not Clause_Matched then
26678 (Dep_Item => Dep_Input,
26680 Matched => Inputs_Match);
26683 (Dep_Item => Dep_Output,
26685 Matched => Outputs_Match);
26687 Clause_Matched := Inputs_Match and Outputs_Match;
26690 -- If the contents of Refined_Depends are legal, then the current
26691 -- dependence clause should be satisfied either by an explicit match
26692 -- or by one of the special cases.
26694 if not Clause_Matched then
26696 (Fix_Msg (Spec_Id, "dependence clause of subprogram & has no "
26697 & "matching refinement in body"), Dep_Clause, Spec_Id);
26699 end Check_Dependency_Clause;
26701 -------------------------
26702 -- Check_Output_States --
26703 -------------------------
26705 procedure Check_Output_States
26706 (Spec_Inputs : Elist_Id;
26707 Spec_Outputs : Elist_Id;
26708 Body_Inputs : Elist_Id;
26709 Body_Outputs : Elist_Id)
26711 procedure Check_Constituent_Usage (State_Id : Entity_Id);
26712 -- Determine whether all constituents of state State_Id with full
26713 -- visible refinement are used as outputs in pragma Refined_Depends.
26714 -- Emit an error if this is not the case (SPARK RM 7.2.4(5)).
26716 -----------------------------
26717 -- Check_Constituent_Usage --
26718 -----------------------------
26720 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
26721 Constits : constant Elist_Id :=
26722 Partial_Refinement_Constituents (State_Id);
26723 Constit_Elmt : Elmt_Id;
26724 Constit_Id : Entity_Id;
26725 Only_Partial : constant Boolean :=
26726 not Has_Visible_Refinement (State_Id);
26727 Posted : Boolean := False;
26730 if Present (Constits) then
26731 Constit_Elmt := First_Elmt (Constits);
26732 while Present (Constit_Elmt) loop
26733 Constit_Id := Node (Constit_Elmt);
26735 -- Issue an error when a constituent of State_Id is used,
26736 -- and State_Id has only partial visible refinement
26737 -- (SPARK RM 7.2.4(3d)).
26739 if Only_Partial then
26740 if (Present (Body_Inputs)
26741 and then Appears_In (Body_Inputs, Constit_Id))
26743 (Present (Body_Outputs)
26744 and then Appears_In (Body_Outputs, Constit_Id))
26746 Error_Msg_Name_1 := Chars (State_Id);
26748 ("constituent & of state % cannot be used in "
26749 & "dependence refinement", N, Constit_Id);
26750 Error_Msg_Name_1 := Chars (State_Id);
26751 SPARK_Msg_N ("\use state % instead", N);
26754 -- The constituent acts as an input (SPARK RM 7.2.5(3))
26756 elsif Present (Body_Inputs)
26757 and then Appears_In (Body_Inputs, Constit_Id)
26759 Error_Msg_Name_1 := Chars (State_Id);
26761 ("constituent & of state % must act as output in "
26762 & "dependence refinement", N, Constit_Id);
26764 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
26766 elsif No (Body_Outputs)
26767 or else not Appears_In (Body_Outputs, Constit_Id)
26772 ("output state & must be replaced by all its "
26773 & "constituents in dependence refinement",
26778 ("\constituent & is missing in output list",
26782 Next_Elmt (Constit_Elmt);
26785 end Check_Constituent_Usage;
26790 Item_Elmt : Elmt_Id;
26791 Item_Id : Entity_Id;
26793 -- Start of processing for Check_Output_States
26796 -- Do not perform this check in an instance because it was already
26797 -- performed successfully in the generic template.
26799 if In_Instance then
26802 -- Inspect the outputs of pragma Depends looking for a state with a
26803 -- visible refinement.
26805 elsif Present (Spec_Outputs) then
26806 Item_Elmt := First_Elmt (Spec_Outputs);
26807 while Present (Item_Elmt) loop
26808 Item := Node (Item_Elmt);
26810 -- Deal with the mixed nature of the input and output lists
26812 if Nkind (Item) = N_Defining_Identifier then
26815 Item_Id := Available_View (Entity_Of (Item));
26818 if Ekind (Item_Id) = E_Abstract_State then
26820 -- The state acts as an input-output, skip it
26822 if Present (Spec_Inputs)
26823 and then Appears_In (Spec_Inputs, Item_Id)
26827 -- Ensure that all of the constituents are utilized as
26828 -- outputs in pragma Refined_Depends.
26830 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
26831 Check_Constituent_Usage (Item_Id);
26835 Next_Elmt (Item_Elmt);
26838 end Check_Output_States;
26840 --------------------
26841 -- Collect_States --
26842 --------------------
26844 function Collect_States (Clauses : List_Id) return Elist_Id is
26845 procedure Collect_State
26847 States : in out Elist_Id);
26848 -- Add the entity of Item to list States when it denotes to a state
26850 -------------------
26851 -- Collect_State --
26852 -------------------
26854 procedure Collect_State
26856 States : in out Elist_Id)
26861 if Is_Entity_Name (Item) then
26862 Id := Entity_Of (Item);
26864 if Ekind (Id) = E_Abstract_State then
26865 if No (States) then
26866 States := New_Elmt_List;
26869 Append_Unique_Elmt (Id, States);
26879 States : Elist_Id := No_Elist;
26881 -- Start of processing for Collect_States
26884 Clause := First (Clauses);
26885 while Present (Clause) loop
26886 Input := Expression (Clause);
26887 Output := First (Choices (Clause));
26889 Collect_State (Input, States);
26890 Collect_State (Output, States);
26896 end Collect_States;
26898 -----------------------
26899 -- Normalize_Clauses --
26900 -----------------------
26902 procedure Normalize_Clauses (Clauses : List_Id) is
26903 procedure Normalize_Inputs (Clause : Node_Id);
26904 -- Normalize clause Clause by creating multiple clauses for each
26905 -- input item of Clause. It is assumed that Clause has exactly one
26906 -- output. The transformation is as follows:
26908 -- Output => (Input_1, Input_2) -- original
26910 -- Output => Input_1 -- normalizations
26911 -- Output => Input_2
26913 procedure Normalize_Outputs (Clause : Node_Id);
26914 -- Normalize clause Clause by creating multiple clause for each
26915 -- output item of Clause. The transformation is as follows:
26917 -- (Output_1, Output_2) => Input -- original
26919 -- Output_1 => Input -- normalization
26920 -- Output_2 => Input
26922 ----------------------
26923 -- Normalize_Inputs --
26924 ----------------------
26926 procedure Normalize_Inputs (Clause : Node_Id) is
26927 Inputs : constant Node_Id := Expression (Clause);
26928 Loc : constant Source_Ptr := Sloc (Clause);
26929 Output : constant List_Id := Choices (Clause);
26930 Last_Input : Node_Id;
26932 New_Clause : Node_Id;
26933 Next_Input : Node_Id;
26936 -- Normalization is performed only when the original clause has
26937 -- more than one input. Multiple inputs appear as an aggregate.
26939 if Nkind (Inputs) = N_Aggregate then
26940 Last_Input := Last (Expressions (Inputs));
26942 -- Create a new clause for each input
26944 Input := First (Expressions (Inputs));
26945 while Present (Input) loop
26946 Next_Input := Next (Input);
26948 -- Unhook the current input from the original input list
26949 -- because it will be relocated to a new clause.
26953 -- Special processing for the last input. At this point the
26954 -- original aggregate has been stripped down to one element.
26955 -- Replace the aggregate by the element itself.
26957 if Input = Last_Input then
26958 Rewrite (Inputs, Input);
26960 -- Generate a clause of the form:
26965 Make_Component_Association (Loc,
26966 Choices => New_Copy_List_Tree (Output),
26967 Expression => Input);
26969 -- The new clause contains replicated content that has
26970 -- already been analyzed, mark the clause as analyzed.
26972 Set_Analyzed (New_Clause);
26973 Insert_After (Clause, New_Clause);
26976 Input := Next_Input;
26979 end Normalize_Inputs;
26981 -----------------------
26982 -- Normalize_Outputs --
26983 -----------------------
26985 procedure Normalize_Outputs (Clause : Node_Id) is
26986 Inputs : constant Node_Id := Expression (Clause);
26987 Loc : constant Source_Ptr := Sloc (Clause);
26988 Outputs : constant Node_Id := First (Choices (Clause));
26989 Last_Output : Node_Id;
26990 New_Clause : Node_Id;
26991 Next_Output : Node_Id;
26995 -- Multiple outputs appear as an aggregate. Nothing to do when
26996 -- the clause has exactly one output.
26998 if Nkind (Outputs) = N_Aggregate then
26999 Last_Output := Last (Expressions (Outputs));
27001 -- Create a clause for each output. Note that each time a new
27002 -- clause is created, the original output list slowly shrinks
27003 -- until there is one item left.
27005 Output := First (Expressions (Outputs));
27006 while Present (Output) loop
27007 Next_Output := Next (Output);
27009 -- Unhook the output from the original output list as it
27010 -- will be relocated to a new clause.
27014 -- Special processing for the last output. At this point
27015 -- the original aggregate has been stripped down to one
27016 -- element. Replace the aggregate by the element itself.
27018 if Output = Last_Output then
27019 Rewrite (Outputs, Output);
27022 -- Generate a clause of the form:
27023 -- (Output => Inputs)
27026 Make_Component_Association (Loc,
27027 Choices => New_List (Output),
27028 Expression => New_Copy_Tree (Inputs));
27030 -- The new clause contains replicated content that has
27031 -- already been analyzed. There is not need to reanalyze
27034 Set_Analyzed (New_Clause);
27035 Insert_After (Clause, New_Clause);
27038 Output := Next_Output;
27041 end Normalize_Outputs;
27047 -- Start of processing for Normalize_Clauses
27050 Clause := First (Clauses);
27051 while Present (Clause) loop
27052 Normalize_Outputs (Clause);
27056 Clause := First (Clauses);
27057 while Present (Clause) loop
27058 Normalize_Inputs (Clause);
27061 end Normalize_Clauses;
27063 --------------------------
27064 -- Remove_Extra_Clauses --
27065 --------------------------
27067 procedure Remove_Extra_Clauses
27068 (Clauses : List_Id;
27069 Matched_Items : Elist_Id)
27073 Input_Id : Entity_Id;
27074 Next_Clause : Node_Id;
27076 State_Id : Entity_Id;
27079 Clause := First (Clauses);
27080 while Present (Clause) loop
27081 Next_Clause := Next (Clause);
27083 Input := Expression (Clause);
27084 Output := First (Choices (Clause));
27086 -- Recognize a clause of the form
27090 -- where Input is a constituent of a state which was already
27091 -- successfully matched. This clause must be removed because it
27092 -- simply indicates that some of the constituents of the state
27095 -- Refined_State => (State => (Constit_1, Constit_2))
27096 -- Depends => (Output => State)
27097 -- Refined_Depends => ((Output => Constit_1), -- State matched
27098 -- (null => Constit_2)) -- OK
27100 if Nkind (Output) = N_Null and then Is_Entity_Name (Input) then
27102 -- Handle abstract views generated for limited with clauses
27104 Input_Id := Available_View (Entity_Of (Input));
27106 -- The input must be a constituent of a state
27108 if Ekind_In (Input_Id, E_Abstract_State,
27111 and then Present (Encapsulating_State (Input_Id))
27113 State_Id := Encapsulating_State (Input_Id);
27115 -- The state must have a non-null visible refinement and be
27116 -- matched in a previous clause.
27118 if Has_Non_Null_Visible_Refinement (State_Id)
27119 and then Contains (Matched_Items, State_Id)
27125 -- Recognize a clause of the form
27129 -- where Output is an arbitrary item. This clause must be removed
27130 -- because a null input legitimately matches anything.
27132 elsif Nkind (Input) = N_Null then
27136 Clause := Next_Clause;
27138 end Remove_Extra_Clauses;
27140 --------------------------
27141 -- Report_Extra_Clauses --
27142 --------------------------
27144 procedure Report_Extra_Clauses (Clauses : List_Id) is
27148 -- Do not perform this check in an instance because it was already
27149 -- performed successfully in the generic template.
27151 if In_Instance then
27154 elsif Present (Clauses) then
27155 Clause := First (Clauses);
27156 while Present (Clause) loop
27158 ("unmatched or extra clause in dependence refinement",
27164 end Report_Extra_Clauses;
27168 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
27169 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
27170 Errors : constant Nat := Serious_Errors_Detected;
27177 Body_Inputs : Elist_Id := No_Elist;
27178 Body_Outputs : Elist_Id := No_Elist;
27179 -- The inputs and outputs of the subprogram body synthesized from pragma
27180 -- Refined_Depends.
27182 Dependencies : List_Id := No_List;
27184 -- The corresponding Depends pragma along with its clauses
27186 Matched_Items : Elist_Id := No_Elist;
27187 -- A list containing the entities of all successfully matched items
27188 -- found in pragma Depends.
27190 Refinements : List_Id := No_List;
27191 -- The clauses of pragma Refined_Depends
27193 Spec_Id : Entity_Id;
27194 -- The entity of the subprogram subject to pragma Refined_Depends
27196 Spec_Inputs : Elist_Id := No_Elist;
27197 Spec_Outputs : Elist_Id := No_Elist;
27198 -- The inputs and outputs of the subprogram spec synthesized from pragma
27201 States : Elist_Id := No_Elist;
27202 -- A list containing the entities of all states whose constituents
27203 -- appear in pragma Depends.
27205 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
27208 -- Do not analyze the pragma multiple times
27210 if Is_Analyzed_Pragma (N) then
27214 Spec_Id := Unique_Defining_Entity (Body_Decl);
27216 -- Use the anonymous object as the proper spec when Refined_Depends
27217 -- applies to the body of a single task type. The object carries the
27218 -- proper Chars as well as all non-refined versions of pragmas.
27220 if Is_Single_Concurrent_Type (Spec_Id) then
27221 Spec_Id := Anonymous_Object (Spec_Id);
27224 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
27226 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
27227 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
27229 if No (Depends) then
27231 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
27232 & "& lacks aspect or pragma Depends"), N, Spec_Id);
27236 Deps := Expression (Get_Argument (Depends, Spec_Id));
27238 -- A null dependency relation renders the refinement useless because it
27239 -- cannot possibly mention abstract states with visible refinement. Note
27240 -- that the inverse is not true as states may be refined to null
27241 -- (SPARK RM 7.2.5(2)).
27243 if Nkind (Deps) = N_Null then
27245 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
27246 & "depend on abstract state with visible refinement"), N, Spec_Id);
27250 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
27251 -- This ensures that the categorization of all refined dependency items
27252 -- is consistent with their role.
27254 Analyze_Depends_In_Decl_Part (N);
27256 -- Do not match dependencies against refinements if Refined_Depends is
27257 -- illegal to avoid emitting misleading error.
27259 if Serious_Errors_Detected = Errors then
27261 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
27262 -- the inputs and outputs of the subprogram spec and body to verify
27263 -- the use of states with visible refinement and their constituents.
27265 if No (Get_Pragma (Spec_Id, Pragma_Global))
27266 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
27268 Collect_Subprogram_Inputs_Outputs
27269 (Subp_Id => Spec_Id,
27270 Synthesize => True,
27271 Subp_Inputs => Spec_Inputs,
27272 Subp_Outputs => Spec_Outputs,
27273 Global_Seen => Dummy);
27275 Collect_Subprogram_Inputs_Outputs
27276 (Subp_Id => Body_Id,
27277 Synthesize => True,
27278 Subp_Inputs => Body_Inputs,
27279 Subp_Outputs => Body_Outputs,
27280 Global_Seen => Dummy);
27282 -- For an output state with a visible refinement, ensure that all
27283 -- constituents appear as outputs in the dependency refinement.
27285 Check_Output_States
27286 (Spec_Inputs => Spec_Inputs,
27287 Spec_Outputs => Spec_Outputs,
27288 Body_Inputs => Body_Inputs,
27289 Body_Outputs => Body_Outputs);
27292 -- Multiple dependency clauses appear as component associations of an
27293 -- aggregate. Note that the clauses are copied because the algorithm
27294 -- modifies them and this should not be visible in Depends.
27296 pragma Assert (Nkind (Deps) = N_Aggregate);
27297 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
27298 Normalize_Clauses (Dependencies);
27300 -- Gather all states which appear in Depends
27302 States := Collect_States (Dependencies);
27304 Refs := Expression (Get_Argument (N, Spec_Id));
27306 if Nkind (Refs) = N_Null then
27307 Refinements := No_List;
27309 -- Multiple dependency clauses appear as component associations of an
27310 -- aggregate. Note that the clauses are copied because the algorithm
27311 -- modifies them and this should not be visible in Refined_Depends.
27313 else pragma Assert (Nkind (Refs) = N_Aggregate);
27314 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
27315 Normalize_Clauses (Refinements);
27318 -- At this point the clauses of pragmas Depends and Refined_Depends
27319 -- have been normalized into simple dependencies between one output
27320 -- and one input. Examine all clauses of pragma Depends looking for
27321 -- matching clauses in pragma Refined_Depends.
27323 Clause := First (Dependencies);
27324 while Present (Clause) loop
27325 Check_Dependency_Clause
27326 (Spec_Id => Spec_Id,
27327 Dep_Clause => Clause,
27328 Dep_States => States,
27329 Refinements => Refinements,
27330 Matched_Items => Matched_Items);
27335 -- Pragma Refined_Depends may contain multiple clarification clauses
27336 -- which indicate that certain constituents do not influence the data
27337 -- flow in any way. Such clauses must be removed as long as the state
27338 -- has been matched, otherwise they will be incorrectly flagged as
27341 -- Refined_State => (State => (Constit_1, Constit_2))
27342 -- Depends => (Output => State)
27343 -- Refined_Depends => ((Output => Constit_1), -- State matched
27344 -- (null => Constit_2)) -- must be removed
27346 Remove_Extra_Clauses (Refinements, Matched_Items);
27348 if Serious_Errors_Detected = Errors then
27349 Report_Extra_Clauses (Refinements);
27354 Set_Is_Analyzed_Pragma (N);
27355 end Analyze_Refined_Depends_In_Decl_Part;
27357 -----------------------------------------
27358 -- Analyze_Refined_Global_In_Decl_Part --
27359 -----------------------------------------
27361 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
27363 -- The corresponding Global pragma
27365 Has_In_State : Boolean := False;
27366 Has_In_Out_State : Boolean := False;
27367 Has_Out_State : Boolean := False;
27368 Has_Proof_In_State : Boolean := False;
27369 -- These flags are set when the corresponding Global pragma has a state
27370 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
27373 Has_Null_State : Boolean := False;
27374 -- This flag is set when the corresponding Global pragma has at least
27375 -- one state with a null refinement.
27377 In_Constits : Elist_Id := No_Elist;
27378 In_Out_Constits : Elist_Id := No_Elist;
27379 Out_Constits : Elist_Id := No_Elist;
27380 Proof_In_Constits : Elist_Id := No_Elist;
27381 -- These lists contain the entities of all Input, In_Out, Output and
27382 -- Proof_In constituents that appear in Refined_Global and participate
27383 -- in state refinement.
27385 In_Items : Elist_Id := No_Elist;
27386 In_Out_Items : Elist_Id := No_Elist;
27387 Out_Items : Elist_Id := No_Elist;
27388 Proof_In_Items : Elist_Id := No_Elist;
27389 -- These lists contain the entities of all Input, In_Out, Output and
27390 -- Proof_In items defined in the corresponding Global pragma.
27392 Repeat_Items : Elist_Id := No_Elist;
27393 -- A list of all global items without full visible refinement found
27394 -- in pragma Global. These states should be repeated in the global
27395 -- refinement (SPARK RM 7.2.4(3c)) unless they have a partial visible
27396 -- refinement, in which case they may be repeated (SPARK RM 7.2.4(3d)).
27398 Spec_Id : Entity_Id;
27399 -- The entity of the subprogram subject to pragma Refined_Global
27401 States : Elist_Id := No_Elist;
27402 -- A list of all states with full or partial visible refinement found in
27405 procedure Check_In_Out_States;
27406 -- Determine whether the corresponding Global pragma mentions In_Out
27407 -- states with visible refinement and if so, ensure that one of the
27408 -- following completions apply to the constituents of the state:
27409 -- 1) there is at least one constituent of mode In_Out
27410 -- 2) there is at least one Input and one Output constituent
27411 -- 3) not all constituents are present and one of them is of mode
27413 -- This routine may remove elements from In_Constits, In_Out_Constits,
27414 -- Out_Constits and Proof_In_Constits.
27416 procedure Check_Input_States;
27417 -- Determine whether the corresponding Global pragma mentions Input
27418 -- states with visible refinement and if so, ensure that at least one of
27419 -- its constituents appears as an Input item in Refined_Global.
27420 -- This routine may remove elements from In_Constits, In_Out_Constits,
27421 -- Out_Constits and Proof_In_Constits.
27423 procedure Check_Output_States;
27424 -- Determine whether the corresponding Global pragma mentions Output
27425 -- states with visible refinement and if so, ensure that all of its
27426 -- constituents appear as Output items in Refined_Global.
27427 -- This routine may remove elements from In_Constits, In_Out_Constits,
27428 -- Out_Constits and Proof_In_Constits.
27430 procedure Check_Proof_In_States;
27431 -- Determine whether the corresponding Global pragma mentions Proof_In
27432 -- states with visible refinement and if so, ensure that at least one of
27433 -- its constituents appears as a Proof_In item in Refined_Global.
27434 -- This routine may remove elements from In_Constits, In_Out_Constits,
27435 -- Out_Constits and Proof_In_Constits.
27437 procedure Check_Refined_Global_List
27439 Global_Mode : Name_Id := Name_Input);
27440 -- Verify the legality of a single global list declaration. Global_Mode
27441 -- denotes the current mode in effect.
27443 procedure Collect_Global_Items
27445 Mode : Name_Id := Name_Input);
27446 -- Gather all Input, In_Out, Output and Proof_In items from node List
27447 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
27448 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
27449 -- and Has_Proof_In_State are set when there is at least one abstract
27450 -- state with full or partial visible refinement available in the
27451 -- corresponding mode. Flag Has_Null_State is set when at least state
27452 -- has a null refinement. Mode denotes the current global mode in
27455 function Present_Then_Remove
27457 Item : Entity_Id) return Boolean;
27458 -- Search List for a particular entity Item. If Item has been found,
27459 -- remove it from List. This routine is used to strip lists In_Constits,
27460 -- In_Out_Constits and Out_Constits of valid constituents.
27462 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id);
27463 -- Same as function Present_Then_Remove, but do not report the presence
27464 -- of Item in List.
27466 procedure Report_Extra_Constituents;
27467 -- Emit an error for each constituent found in lists In_Constits,
27468 -- In_Out_Constits and Out_Constits.
27470 procedure Report_Missing_Items;
27471 -- Emit an error for each global item not repeated found in list
27474 -------------------------
27475 -- Check_In_Out_States --
27476 -------------------------
27478 procedure Check_In_Out_States is
27479 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27480 -- Determine whether one of the following coverage scenarios is in
27482 -- 1) there is at least one constituent of mode In_Out or Output
27483 -- 2) there is at least one pair of constituents with modes Input
27484 -- and Output, or Proof_In and Output.
27485 -- 3) there is at least one constituent of mode Output and not all
27486 -- constituents are present.
27487 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
27489 -----------------------------
27490 -- Check_Constituent_Usage --
27491 -----------------------------
27493 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27494 Constits : constant Elist_Id :=
27495 Partial_Refinement_Constituents (State_Id);
27496 Constit_Elmt : Elmt_Id;
27497 Constit_Id : Entity_Id;
27498 Has_Missing : Boolean := False;
27499 In_Out_Seen : Boolean := False;
27500 Input_Seen : Boolean := False;
27501 Output_Seen : Boolean := False;
27502 Proof_In_Seen : Boolean := False;
27505 -- Process all the constituents of the state and note their modes
27506 -- within the global refinement.
27508 if Present (Constits) then
27509 Constit_Elmt := First_Elmt (Constits);
27510 while Present (Constit_Elmt) loop
27511 Constit_Id := Node (Constit_Elmt);
27513 if Present_Then_Remove (In_Constits, Constit_Id) then
27514 Input_Seen := True;
27516 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
27517 In_Out_Seen := True;
27519 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
27520 Output_Seen := True;
27522 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
27524 Proof_In_Seen := True;
27527 Has_Missing := True;
27530 Next_Elmt (Constit_Elmt);
27534 -- An In_Out constituent is a valid completion
27536 if In_Out_Seen then
27539 -- A pair of one Input/Proof_In and one Output constituent is a
27540 -- valid completion.
27542 elsif (Input_Seen or Proof_In_Seen) and Output_Seen then
27545 elsif Output_Seen then
27547 -- A single Output constituent is a valid completion only when
27548 -- some of the other constituents are missing.
27550 if Has_Missing then
27553 -- Otherwise all constituents are of mode Output
27557 ("global refinement of state & must include at least one "
27558 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
27562 -- The state lacks a completion. When full refinement is visible,
27563 -- always emit an error (SPARK RM 7.2.4(3a)). When only partial
27564 -- refinement is visible, emit an error if the abstract state
27565 -- itself is not utilized (SPARK RM 7.2.4(3d)). In the case where
27566 -- both are utilized, Check_State_And_Constituent_Use. will issue
27569 elsif not Input_Seen
27570 and then not In_Out_Seen
27571 and then not Output_Seen
27572 and then not Proof_In_Seen
27574 if Has_Visible_Refinement (State_Id)
27575 or else Contains (Repeat_Items, State_Id)
27578 ("missing global refinement of state &", N, State_Id);
27581 -- Otherwise the state has a malformed completion where at least
27582 -- one of the constituents has a different mode.
27586 ("global refinement of state & redefines the mode of its "
27587 & "constituents", N, State_Id);
27589 end Check_Constituent_Usage;
27593 Item_Elmt : Elmt_Id;
27594 Item_Id : Entity_Id;
27596 -- Start of processing for Check_In_Out_States
27599 -- Do not perform this check in an instance because it was already
27600 -- performed successfully in the generic template.
27602 if In_Instance then
27605 -- Inspect the In_Out items of the corresponding Global pragma
27606 -- looking for a state with a visible refinement.
27608 elsif Has_In_Out_State and then Present (In_Out_Items) then
27609 Item_Elmt := First_Elmt (In_Out_Items);
27610 while Present (Item_Elmt) loop
27611 Item_Id := Node (Item_Elmt);
27613 -- Ensure that one of the three coverage variants is satisfied
27615 if Ekind (Item_Id) = E_Abstract_State
27616 and then Has_Non_Null_Visible_Refinement (Item_Id)
27618 Check_Constituent_Usage (Item_Id);
27621 Next_Elmt (Item_Elmt);
27624 end Check_In_Out_States;
27626 ------------------------
27627 -- Check_Input_States --
27628 ------------------------
27630 procedure Check_Input_States is
27631 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27632 -- Determine whether at least one constituent of state State_Id with
27633 -- full or partial visible refinement is used and has mode Input.
27634 -- Ensure that the remaining constituents do not have In_Out or
27635 -- Output modes. Emit an error if this is not the case
27636 -- (SPARK RM 7.2.4(5)).
27638 -----------------------------
27639 -- Check_Constituent_Usage --
27640 -----------------------------
27642 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27643 Constits : constant Elist_Id :=
27644 Partial_Refinement_Constituents (State_Id);
27645 Constit_Elmt : Elmt_Id;
27646 Constit_Id : Entity_Id;
27647 In_Seen : Boolean := False;
27650 if Present (Constits) then
27651 Constit_Elmt := First_Elmt (Constits);
27652 while Present (Constit_Elmt) loop
27653 Constit_Id := Node (Constit_Elmt);
27655 -- At least one of the constituents appears as an Input
27657 if Present_Then_Remove (In_Constits, Constit_Id) then
27660 -- A Proof_In constituent can refine an Input state as long
27661 -- as there is at least one Input constituent present.
27663 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
27667 -- The constituent appears in the global refinement, but has
27668 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
27670 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
27671 or else Present_Then_Remove (Out_Constits, Constit_Id)
27673 Error_Msg_Name_1 := Chars (State_Id);
27675 ("constituent & of state % must have mode `Input` in "
27676 & "global refinement", N, Constit_Id);
27679 Next_Elmt (Constit_Elmt);
27683 -- Not one of the constituents appeared as Input. Always emit an
27684 -- error when the full refinement is visible (SPARK RM 7.2.4(3a)).
27685 -- When only partial refinement is visible, emit an error if the
27686 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
27687 -- the case where both are utilized, an error will be issued in
27688 -- Check_State_And_Constituent_Use.
27691 and then (Has_Visible_Refinement (State_Id)
27692 or else Contains (Repeat_Items, State_Id))
27695 ("global refinement of state & must include at least one "
27696 & "constituent of mode `Input`", N, State_Id);
27698 end Check_Constituent_Usage;
27702 Item_Elmt : Elmt_Id;
27703 Item_Id : Entity_Id;
27705 -- Start of processing for Check_Input_States
27708 -- Do not perform this check in an instance because it was already
27709 -- performed successfully in the generic template.
27711 if In_Instance then
27714 -- Inspect the Input items of the corresponding Global pragma looking
27715 -- for a state with a visible refinement.
27717 elsif Has_In_State and then Present (In_Items) then
27718 Item_Elmt := First_Elmt (In_Items);
27719 while Present (Item_Elmt) loop
27720 Item_Id := Node (Item_Elmt);
27722 -- When full refinement is visible, ensure that at least one of
27723 -- the constituents is utilized and is of mode Input. When only
27724 -- partial refinement is visible, ensure that either one of
27725 -- the constituents is utilized and is of mode Input, or the
27726 -- abstract state is repeated and no constituent is utilized.
27728 if Ekind (Item_Id) = E_Abstract_State
27729 and then Has_Non_Null_Visible_Refinement (Item_Id)
27731 Check_Constituent_Usage (Item_Id);
27734 Next_Elmt (Item_Elmt);
27737 end Check_Input_States;
27739 -------------------------
27740 -- Check_Output_States --
27741 -------------------------
27743 procedure Check_Output_States is
27744 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27745 -- Determine whether all constituents of state State_Id with full
27746 -- visible refinement are used and have mode Output. Emit an error
27747 -- if this is not the case (SPARK RM 7.2.4(5)).
27749 -----------------------------
27750 -- Check_Constituent_Usage --
27751 -----------------------------
27753 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27754 Constits : constant Elist_Id :=
27755 Partial_Refinement_Constituents (State_Id);
27756 Only_Partial : constant Boolean :=
27757 not Has_Visible_Refinement (State_Id);
27758 Constit_Elmt : Elmt_Id;
27759 Constit_Id : Entity_Id;
27760 Posted : Boolean := False;
27763 if Present (Constits) then
27764 Constit_Elmt := First_Elmt (Constits);
27765 while Present (Constit_Elmt) loop
27766 Constit_Id := Node (Constit_Elmt);
27768 -- Issue an error when a constituent of State_Id is utilized
27769 -- and State_Id has only partial visible refinement
27770 -- (SPARK RM 7.2.4(3d)).
27772 if Only_Partial then
27773 if Present_Then_Remove (Out_Constits, Constit_Id)
27774 or else Present_Then_Remove (In_Constits, Constit_Id)
27776 Present_Then_Remove (In_Out_Constits, Constit_Id)
27778 Present_Then_Remove (Proof_In_Constits, Constit_Id)
27780 Error_Msg_Name_1 := Chars (State_Id);
27782 ("constituent & of state % cannot be used in global "
27783 & "refinement", N, Constit_Id);
27784 Error_Msg_Name_1 := Chars (State_Id);
27785 SPARK_Msg_N ("\use state % instead", N);
27788 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
27791 -- The constituent appears in the global refinement, but has
27792 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
27794 elsif Present_Then_Remove (In_Constits, Constit_Id)
27795 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
27796 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
27798 Error_Msg_Name_1 := Chars (State_Id);
27800 ("constituent & of state % must have mode `Output` in "
27801 & "global refinement", N, Constit_Id);
27803 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
27809 ("`Output` state & must be replaced by all its "
27810 & "constituents in global refinement", N, State_Id);
27814 ("\constituent & is missing in output list",
27818 Next_Elmt (Constit_Elmt);
27821 end Check_Constituent_Usage;
27825 Item_Elmt : Elmt_Id;
27826 Item_Id : Entity_Id;
27828 -- Start of processing for Check_Output_States
27831 -- Do not perform this check in an instance because it was already
27832 -- performed successfully in the generic template.
27834 if In_Instance then
27837 -- Inspect the Output items of the corresponding Global pragma
27838 -- looking for a state with a visible refinement.
27840 elsif Has_Out_State and then Present (Out_Items) then
27841 Item_Elmt := First_Elmt (Out_Items);
27842 while Present (Item_Elmt) loop
27843 Item_Id := Node (Item_Elmt);
27845 -- When full refinement is visible, ensure that all of the
27846 -- constituents are utilized and they have mode Output. When
27847 -- only partial refinement is visible, ensure that no
27848 -- constituent is utilized.
27850 if Ekind (Item_Id) = E_Abstract_State
27851 and then Has_Non_Null_Visible_Refinement (Item_Id)
27853 Check_Constituent_Usage (Item_Id);
27856 Next_Elmt (Item_Elmt);
27859 end Check_Output_States;
27861 ---------------------------
27862 -- Check_Proof_In_States --
27863 ---------------------------
27865 procedure Check_Proof_In_States is
27866 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27867 -- Determine whether at least one constituent of state State_Id with
27868 -- full or partial visible refinement is used and has mode Proof_In.
27869 -- Ensure that the remaining constituents do not have Input, In_Out,
27870 -- or Output modes. Emit an error if this is not the case
27871 -- (SPARK RM 7.2.4(5)).
27873 -----------------------------
27874 -- Check_Constituent_Usage --
27875 -----------------------------
27877 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27878 Constits : constant Elist_Id :=
27879 Partial_Refinement_Constituents (State_Id);
27880 Constit_Elmt : Elmt_Id;
27881 Constit_Id : Entity_Id;
27882 Proof_In_Seen : Boolean := False;
27885 if Present (Constits) then
27886 Constit_Elmt := First_Elmt (Constits);
27887 while Present (Constit_Elmt) loop
27888 Constit_Id := Node (Constit_Elmt);
27890 -- At least one of the constituents appears as Proof_In
27892 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
27893 Proof_In_Seen := True;
27895 -- The constituent appears in the global refinement, but has
27896 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
27898 elsif Present_Then_Remove (In_Constits, Constit_Id)
27899 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
27900 or else Present_Then_Remove (Out_Constits, Constit_Id)
27902 Error_Msg_Name_1 := Chars (State_Id);
27904 ("constituent & of state % must have mode `Proof_In` "
27905 & "in global refinement", N, Constit_Id);
27908 Next_Elmt (Constit_Elmt);
27912 -- Not one of the constituents appeared as Proof_In. Always emit
27913 -- an error when full refinement is visible (SPARK RM 7.2.4(3a)).
27914 -- When only partial refinement is visible, emit an error if the
27915 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
27916 -- the case where both are utilized, an error will be issued by
27917 -- Check_State_And_Constituent_Use.
27919 if not Proof_In_Seen
27920 and then (Has_Visible_Refinement (State_Id)
27921 or else Contains (Repeat_Items, State_Id))
27924 ("global refinement of state & must include at least one "
27925 & "constituent of mode `Proof_In`", N, State_Id);
27927 end Check_Constituent_Usage;
27931 Item_Elmt : Elmt_Id;
27932 Item_Id : Entity_Id;
27934 -- Start of processing for Check_Proof_In_States
27937 -- Do not perform this check in an instance because it was already
27938 -- performed successfully in the generic template.
27940 if In_Instance then
27943 -- Inspect the Proof_In items of the corresponding Global pragma
27944 -- looking for a state with a visible refinement.
27946 elsif Has_Proof_In_State and then Present (Proof_In_Items) then
27947 Item_Elmt := First_Elmt (Proof_In_Items);
27948 while Present (Item_Elmt) loop
27949 Item_Id := Node (Item_Elmt);
27951 -- Ensure that at least one of the constituents is utilized
27952 -- and is of mode Proof_In. When only partial refinement is
27953 -- visible, ensure that either one of the constituents is
27954 -- utilized and is of mode Proof_In, or the abstract state
27955 -- is repeated and no constituent is utilized.
27957 if Ekind (Item_Id) = E_Abstract_State
27958 and then Has_Non_Null_Visible_Refinement (Item_Id)
27960 Check_Constituent_Usage (Item_Id);
27963 Next_Elmt (Item_Elmt);
27966 end Check_Proof_In_States;
27968 -------------------------------
27969 -- Check_Refined_Global_List --
27970 -------------------------------
27972 procedure Check_Refined_Global_List
27974 Global_Mode : Name_Id := Name_Input)
27976 procedure Check_Refined_Global_Item
27978 Global_Mode : Name_Id);
27979 -- Verify the legality of a single global item declaration. Parameter
27980 -- Global_Mode denotes the current mode in effect.
27982 -------------------------------
27983 -- Check_Refined_Global_Item --
27984 -------------------------------
27986 procedure Check_Refined_Global_Item
27988 Global_Mode : Name_Id)
27990 Item_Id : constant Entity_Id := Entity_Of (Item);
27992 procedure Inconsistent_Mode_Error (Expect : Name_Id);
27993 -- Issue a common error message for all mode mismatches. Expect
27994 -- denotes the expected mode.
27996 -----------------------------
27997 -- Inconsistent_Mode_Error --
27998 -----------------------------
28000 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
28003 ("global item & has inconsistent modes", Item, Item_Id);
28005 Error_Msg_Name_1 := Global_Mode;
28006 Error_Msg_Name_2 := Expect;
28007 SPARK_Msg_N ("\expected mode %, found mode %", Item);
28008 end Inconsistent_Mode_Error;
28012 Enc_State : Entity_Id := Empty;
28013 -- Encapsulating state for constituent, Empty otherwise
28015 -- Start of processing for Check_Refined_Global_Item
28018 if Ekind_In (Item_Id, E_Abstract_State,
28022 Enc_State := Find_Encapsulating_State (States, Item_Id);
28025 -- When the state or object acts as a constituent of another
28026 -- state with a visible refinement, collect it for the state
28027 -- completeness checks performed later on. Note that the item
28028 -- acts as a constituent only when the encapsulating state is
28029 -- present in pragma Global.
28031 if Present (Enc_State)
28032 and then (Has_Visible_Refinement (Enc_State)
28033 or else Has_Partial_Visible_Refinement (Enc_State))
28034 and then Contains (States, Enc_State)
28036 -- If the state has only partial visible refinement, remove it
28037 -- from the list of items that should be repeated from pragma
28040 if not Has_Visible_Refinement (Enc_State) then
28041 Present_Then_Remove (Repeat_Items, Enc_State);
28044 if Global_Mode = Name_Input then
28045 Append_New_Elmt (Item_Id, In_Constits);
28047 elsif Global_Mode = Name_In_Out then
28048 Append_New_Elmt (Item_Id, In_Out_Constits);
28050 elsif Global_Mode = Name_Output then
28051 Append_New_Elmt (Item_Id, Out_Constits);
28053 elsif Global_Mode = Name_Proof_In then
28054 Append_New_Elmt (Item_Id, Proof_In_Constits);
28057 -- When not a constituent, ensure that both occurrences of the
28058 -- item in pragmas Global and Refined_Global match. Also remove
28059 -- it when present from the list of items that should be repeated
28060 -- from pragma Global.
28063 Present_Then_Remove (Repeat_Items, Item_Id);
28065 if Contains (In_Items, Item_Id) then
28066 if Global_Mode /= Name_Input then
28067 Inconsistent_Mode_Error (Name_Input);
28070 elsif Contains (In_Out_Items, Item_Id) then
28071 if Global_Mode /= Name_In_Out then
28072 Inconsistent_Mode_Error (Name_In_Out);
28075 elsif Contains (Out_Items, Item_Id) then
28076 if Global_Mode /= Name_Output then
28077 Inconsistent_Mode_Error (Name_Output);
28080 elsif Contains (Proof_In_Items, Item_Id) then
28083 -- The item does not appear in the corresponding Global pragma,
28084 -- it must be an extra (SPARK RM 7.2.4(3)).
28087 pragma Assert (Present (Global));
28088 Error_Msg_Sloc := Sloc (Global);
28090 ("extra global item & does not refine or repeat any "
28091 & "global item #", Item, Item_Id);
28094 end Check_Refined_Global_Item;
28100 -- Start of processing for Check_Refined_Global_List
28103 -- Do not perform this check in an instance because it was already
28104 -- performed successfully in the generic template.
28106 if In_Instance then
28109 elsif Nkind (List) = N_Null then
28112 -- Single global item declaration
28114 elsif Nkind_In (List, N_Expanded_Name,
28116 N_Selected_Component)
28118 Check_Refined_Global_Item (List, Global_Mode);
28120 -- Simple global list or moded global list declaration
28122 elsif Nkind (List) = N_Aggregate then
28124 -- The declaration of a simple global list appear as a collection
28127 if Present (Expressions (List)) then
28128 Item := First (Expressions (List));
28129 while Present (Item) loop
28130 Check_Refined_Global_Item (Item, Global_Mode);
28134 -- The declaration of a moded global list appears as a collection
28135 -- of component associations where individual choices denote
28138 elsif Present (Component_Associations (List)) then
28139 Item := First (Component_Associations (List));
28140 while Present (Item) loop
28141 Check_Refined_Global_List
28142 (List => Expression (Item),
28143 Global_Mode => Chars (First (Choices (Item))));
28151 raise Program_Error;
28157 raise Program_Error;
28159 end Check_Refined_Global_List;
28161 --------------------------
28162 -- Collect_Global_Items --
28163 --------------------------
28165 procedure Collect_Global_Items
28167 Mode : Name_Id := Name_Input)
28169 procedure Collect_Global_Item
28171 Item_Mode : Name_Id);
28172 -- Add a single item to the appropriate list. Item_Mode denotes the
28173 -- current mode in effect.
28175 -------------------------
28176 -- Collect_Global_Item --
28177 -------------------------
28179 procedure Collect_Global_Item
28181 Item_Mode : Name_Id)
28183 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
28184 -- The above handles abstract views of variables and states built
28185 -- for limited with clauses.
28188 -- Signal that the global list contains at least one abstract
28189 -- state with a visible refinement. Note that the refinement may
28190 -- be null in which case there are no constituents.
28192 if Ekind (Item_Id) = E_Abstract_State then
28193 if Has_Null_Visible_Refinement (Item_Id) then
28194 Has_Null_State := True;
28196 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
28197 Append_New_Elmt (Item_Id, States);
28199 if Item_Mode = Name_Input then
28200 Has_In_State := True;
28201 elsif Item_Mode = Name_In_Out then
28202 Has_In_Out_State := True;
28203 elsif Item_Mode = Name_Output then
28204 Has_Out_State := True;
28205 elsif Item_Mode = Name_Proof_In then
28206 Has_Proof_In_State := True;
28211 -- Record global items without full visible refinement found in
28212 -- pragma Global which should be repeated in the global refinement
28213 -- (SPARK RM 7.2.4(3c), SPARK RM 7.2.4(3d)).
28215 if Ekind (Item_Id) /= E_Abstract_State
28216 or else not Has_Visible_Refinement (Item_Id)
28218 Append_New_Elmt (Item_Id, Repeat_Items);
28221 -- Add the item to the proper list
28223 if Item_Mode = Name_Input then
28224 Append_New_Elmt (Item_Id, In_Items);
28225 elsif Item_Mode = Name_In_Out then
28226 Append_New_Elmt (Item_Id, In_Out_Items);
28227 elsif Item_Mode = Name_Output then
28228 Append_New_Elmt (Item_Id, Out_Items);
28229 elsif Item_Mode = Name_Proof_In then
28230 Append_New_Elmt (Item_Id, Proof_In_Items);
28232 end Collect_Global_Item;
28238 -- Start of processing for Collect_Global_Items
28241 if Nkind (List) = N_Null then
28244 -- Single global item declaration
28246 elsif Nkind_In (List, N_Expanded_Name,
28248 N_Selected_Component)
28250 Collect_Global_Item (List, Mode);
28252 -- Single global list or moded global list declaration
28254 elsif Nkind (List) = N_Aggregate then
28256 -- The declaration of a simple global list appear as a collection
28259 if Present (Expressions (List)) then
28260 Item := First (Expressions (List));
28261 while Present (Item) loop
28262 Collect_Global_Item (Item, Mode);
28266 -- The declaration of a moded global list appears as a collection
28267 -- of component associations where individual choices denote mode.
28269 elsif Present (Component_Associations (List)) then
28270 Item := First (Component_Associations (List));
28271 while Present (Item) loop
28272 Collect_Global_Items
28273 (List => Expression (Item),
28274 Mode => Chars (First (Choices (Item))));
28282 raise Program_Error;
28285 -- To accommodate partial decoration of disabled SPARK features, this
28286 -- routine may be called with illegal input. If this is the case, do
28287 -- not raise Program_Error.
28292 end Collect_Global_Items;
28294 -------------------------
28295 -- Present_Then_Remove --
28296 -------------------------
28298 function Present_Then_Remove
28300 Item : Entity_Id) return Boolean
28305 if Present (List) then
28306 Elmt := First_Elmt (List);
28307 while Present (Elmt) loop
28308 if Node (Elmt) = Item then
28309 Remove_Elmt (List, Elmt);
28318 end Present_Then_Remove;
28320 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id) is
28323 Ignore := Present_Then_Remove (List, Item);
28324 end Present_Then_Remove;
28326 -------------------------------
28327 -- Report_Extra_Constituents --
28328 -------------------------------
28330 procedure Report_Extra_Constituents is
28331 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
28332 -- Emit an error for every element of List
28334 ---------------------------------------
28335 -- Report_Extra_Constituents_In_List --
28336 ---------------------------------------
28338 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
28339 Constit_Elmt : Elmt_Id;
28342 if Present (List) then
28343 Constit_Elmt := First_Elmt (List);
28344 while Present (Constit_Elmt) loop
28345 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
28346 Next_Elmt (Constit_Elmt);
28349 end Report_Extra_Constituents_In_List;
28351 -- Start of processing for Report_Extra_Constituents
28354 -- Do not perform this check in an instance because it was already
28355 -- performed successfully in the generic template.
28357 if In_Instance then
28361 Report_Extra_Constituents_In_List (In_Constits);
28362 Report_Extra_Constituents_In_List (In_Out_Constits);
28363 Report_Extra_Constituents_In_List (Out_Constits);
28364 Report_Extra_Constituents_In_List (Proof_In_Constits);
28366 end Report_Extra_Constituents;
28368 --------------------------
28369 -- Report_Missing_Items --
28370 --------------------------
28372 procedure Report_Missing_Items is
28373 Item_Elmt : Elmt_Id;
28374 Item_Id : Entity_Id;
28377 -- Do not perform this check in an instance because it was already
28378 -- performed successfully in the generic template.
28380 if In_Instance then
28384 if Present (Repeat_Items) then
28385 Item_Elmt := First_Elmt (Repeat_Items);
28386 while Present (Item_Elmt) loop
28387 Item_Id := Node (Item_Elmt);
28388 SPARK_Msg_NE ("missing global item &", N, Item_Id);
28389 Next_Elmt (Item_Elmt);
28393 end Report_Missing_Items;
28397 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
28398 Errors : constant Nat := Serious_Errors_Detected;
28400 No_Constit : Boolean;
28402 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
28405 -- Do not analyze the pragma multiple times
28407 if Is_Analyzed_Pragma (N) then
28411 Spec_Id := Unique_Defining_Entity (Body_Decl);
28413 -- Use the anonymous object as the proper spec when Refined_Global
28414 -- applies to the body of a single task type. The object carries the
28415 -- proper Chars as well as all non-refined versions of pragmas.
28417 if Is_Single_Concurrent_Type (Spec_Id) then
28418 Spec_Id := Anonymous_Object (Spec_Id);
28421 Global := Get_Pragma (Spec_Id, Pragma_Global);
28422 Items := Expression (Get_Argument (N, Spec_Id));
28424 -- The subprogram declaration lacks pragma Global. This renders
28425 -- Refined_Global useless as there is nothing to refine.
28427 if No (Global) then
28429 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
28430 & "& lacks aspect or pragma Global"), N, Spec_Id);
28434 -- Extract all relevant items from the corresponding Global pragma
28436 Collect_Global_Items (Expression (Get_Argument (Global, Spec_Id)));
28438 -- Package and subprogram bodies are instantiated individually in
28439 -- a separate compiler pass. Due to this mode of instantiation, the
28440 -- refinement of a state may no longer be visible when a subprogram
28441 -- body contract is instantiated. Since the generic template is legal,
28442 -- do not perform this check in the instance to circumvent this oddity.
28444 if In_Instance then
28447 -- Non-instance case
28450 -- The corresponding Global pragma must mention at least one
28451 -- state with a visible refinement at the point Refined_Global
28452 -- is processed. States with null refinements need Refined_Global
28453 -- pragma (SPARK RM 7.2.4(2)).
28455 if not Has_In_State
28456 and then not Has_In_Out_State
28457 and then not Has_Out_State
28458 and then not Has_Proof_In_State
28459 and then not Has_Null_State
28462 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
28463 & "depend on abstract state with visible refinement"),
28467 -- The global refinement of inputs and outputs cannot be null when
28468 -- the corresponding Global pragma contains at least one item except
28469 -- in the case where we have states with null refinements.
28471 elsif Nkind (Items) = N_Null
28473 (Present (In_Items)
28474 or else Present (In_Out_Items)
28475 or else Present (Out_Items)
28476 or else Present (Proof_In_Items))
28477 and then not Has_Null_State
28480 (Fix_Msg (Spec_Id, "refinement cannot be null, subprogram & has "
28481 & "global items"), N, Spec_Id);
28486 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
28487 -- This ensures that the categorization of all refined global items is
28488 -- consistent with their role.
28490 Analyze_Global_In_Decl_Part (N);
28492 -- Perform all refinement checks with respect to completeness and mode
28495 if Serious_Errors_Detected = Errors then
28496 Check_Refined_Global_List (Items);
28499 -- Store the information that no constituent is used in the global
28500 -- refinement, prior to calling checking procedures which remove items
28501 -- from the list of constituents.
28505 and then No (In_Out_Constits)
28506 and then No (Out_Constits)
28507 and then No (Proof_In_Constits);
28509 -- For Input states with visible refinement, at least one constituent
28510 -- must be used as an Input in the global refinement.
28512 if Serious_Errors_Detected = Errors then
28513 Check_Input_States;
28516 -- Verify all possible completion variants for In_Out states with
28517 -- visible refinement.
28519 if Serious_Errors_Detected = Errors then
28520 Check_In_Out_States;
28523 -- For Output states with visible refinement, all constituents must be
28524 -- used as Outputs in the global refinement.
28526 if Serious_Errors_Detected = Errors then
28527 Check_Output_States;
28530 -- For Proof_In states with visible refinement, at least one constituent
28531 -- must be used as Proof_In in the global refinement.
28533 if Serious_Errors_Detected = Errors then
28534 Check_Proof_In_States;
28537 -- Emit errors for all constituents that belong to other states with
28538 -- visible refinement that do not appear in Global.
28540 if Serious_Errors_Detected = Errors then
28541 Report_Extra_Constituents;
28544 -- Emit errors for all items in Global that are not repeated in the
28545 -- global refinement and for which there is no full visible refinement
28546 -- and, in the case of states with partial visible refinement, no
28547 -- constituent is mentioned in the global refinement.
28549 if Serious_Errors_Detected = Errors then
28550 Report_Missing_Items;
28553 -- Emit an error if no constituent is used in the global refinement
28554 -- (SPARK RM 7.2.4(3f)). Emit this error last, in case a more precise
28555 -- one may be issued by the checking procedures. Do not perform this
28556 -- check in an instance because it was already performed successfully
28557 -- in the generic template.
28559 if Serious_Errors_Detected = Errors
28560 and then not In_Instance
28561 and then not Has_Null_State
28562 and then No_Constit
28564 SPARK_Msg_N ("missing refinement", N);
28568 Set_Is_Analyzed_Pragma (N);
28569 end Analyze_Refined_Global_In_Decl_Part;
28571 ----------------------------------------
28572 -- Analyze_Refined_State_In_Decl_Part --
28573 ----------------------------------------
28575 procedure Analyze_Refined_State_In_Decl_Part
28577 Freeze_Id : Entity_Id := Empty)
28579 Body_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
28580 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
28581 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
28583 Available_States : Elist_Id := No_Elist;
28584 -- A list of all abstract states defined in the package declaration that
28585 -- are available for refinement. The list is used to report unrefined
28588 Body_States : Elist_Id := No_Elist;
28589 -- A list of all hidden states that appear in the body of the related
28590 -- package. The list is used to report unused hidden states.
28592 Constituents_Seen : Elist_Id := No_Elist;
28593 -- A list that contains all constituents processed so far. The list is
28594 -- used to detect multiple uses of the same constituent.
28596 Freeze_Posted : Boolean := False;
28597 -- A flag that controls the output of a freezing-related error (see use
28600 Refined_States_Seen : Elist_Id := No_Elist;
28601 -- A list that contains all refined states processed so far. The list is
28602 -- used to detect duplicate refinements.
28604 procedure Analyze_Refinement_Clause (Clause : Node_Id);
28605 -- Perform full analysis of a single refinement clause
28607 procedure Report_Unrefined_States (States : Elist_Id);
28608 -- Emit errors for all unrefined abstract states found in list States
28610 -------------------------------
28611 -- Analyze_Refinement_Clause --
28612 -------------------------------
28614 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
28615 AR_Constit : Entity_Id := Empty;
28616 AW_Constit : Entity_Id := Empty;
28617 ER_Constit : Entity_Id := Empty;
28618 EW_Constit : Entity_Id := Empty;
28619 -- The entities of external constituents that contain one of the
28620 -- following enabled properties: Async_Readers, Async_Writers,
28621 -- Effective_Reads and Effective_Writes.
28623 External_Constit_Seen : Boolean := False;
28624 -- Flag used to mark when at least one external constituent is part
28625 -- of the state refinement.
28627 Non_Null_Seen : Boolean := False;
28628 Null_Seen : Boolean := False;
28629 -- Flags used to detect multiple uses of null in a single clause or a
28630 -- mixture of null and non-null constituents.
28632 Part_Of_Constits : Elist_Id := No_Elist;
28633 -- A list of all candidate constituents subject to indicator Part_Of
28634 -- where the encapsulating state is the current state.
28637 State_Id : Entity_Id;
28638 -- The current state being refined
28640 procedure Analyze_Constituent (Constit : Node_Id);
28641 -- Perform full analysis of a single constituent
28643 procedure Check_External_Property
28644 (Prop_Nam : Name_Id;
28646 Constit : Entity_Id);
28647 -- Determine whether a property denoted by name Prop_Nam is present
28648 -- in the refined state. Emit an error if this is not the case. Flag
28649 -- Enabled should be set when the property applies to the refined
28650 -- state. Constit denotes the constituent (if any) which introduces
28651 -- the property in the refinement.
28653 procedure Match_State;
28654 -- Determine whether the state being refined appears in list
28655 -- Available_States. Emit an error when attempting to re-refine the
28656 -- state or when the state is not defined in the package declaration,
28657 -- otherwise remove the state from Available_States.
28659 procedure Report_Unused_Constituents (Constits : Elist_Id);
28660 -- Emit errors for all unused Part_Of constituents in list Constits
28662 -------------------------
28663 -- Analyze_Constituent --
28664 -------------------------
28666 procedure Analyze_Constituent (Constit : Node_Id) is
28667 procedure Match_Constituent (Constit_Id : Entity_Id);
28668 -- Determine whether constituent Constit denoted by its entity
28669 -- Constit_Id appears in Body_States. Emit an error when the
28670 -- constituent is not a valid hidden state of the related package
28671 -- or when it is used more than once. Otherwise remove the
28672 -- constituent from Body_States.
28674 -----------------------
28675 -- Match_Constituent --
28676 -----------------------
28678 procedure Match_Constituent (Constit_Id : Entity_Id) is
28679 procedure Collect_Constituent;
28680 -- Verify the legality of constituent Constit_Id and add it to
28681 -- the refinements of State_Id.
28683 -------------------------
28684 -- Collect_Constituent --
28685 -------------------------
28687 procedure Collect_Constituent is
28688 Constits : Elist_Id;
28691 -- The Ghost policy in effect at the point of abstract state
28692 -- declaration and constituent must match (SPARK RM 6.9(15))
28694 Check_Ghost_Refinement
28695 (State, State_Id, Constit, Constit_Id);
28697 -- A synchronized state must be refined by a synchronized
28698 -- object or another synchronized state (SPARK RM 9.6).
28700 if Is_Synchronized_State (State_Id)
28701 and then not Is_Synchronized_Object (Constit_Id)
28702 and then not Is_Synchronized_State (Constit_Id)
28705 ("constituent of synchronized state & must be "
28706 & "synchronized", Constit, State_Id);
28709 -- Add the constituent to the list of processed items to aid
28710 -- with the detection of duplicates.
28712 Append_New_Elmt (Constit_Id, Constituents_Seen);
28714 -- Collect the constituent in the list of refinement items
28715 -- and establish a relation between the refined state and
28718 Constits := Refinement_Constituents (State_Id);
28720 if No (Constits) then
28721 Constits := New_Elmt_List;
28722 Set_Refinement_Constituents (State_Id, Constits);
28725 Append_Elmt (Constit_Id, Constits);
28726 Set_Encapsulating_State (Constit_Id, State_Id);
28728 -- The state has at least one legal constituent, mark the
28729 -- start of the refinement region. The region ends when the
28730 -- body declarations end (see routine Analyze_Declarations).
28732 Set_Has_Visible_Refinement (State_Id);
28734 -- When the constituent is external, save its relevant
28735 -- property for further checks.
28737 if Async_Readers_Enabled (Constit_Id) then
28738 AR_Constit := Constit_Id;
28739 External_Constit_Seen := True;
28742 if Async_Writers_Enabled (Constit_Id) then
28743 AW_Constit := Constit_Id;
28744 External_Constit_Seen := True;
28747 if Effective_Reads_Enabled (Constit_Id) then
28748 ER_Constit := Constit_Id;
28749 External_Constit_Seen := True;
28752 if Effective_Writes_Enabled (Constit_Id) then
28753 EW_Constit := Constit_Id;
28754 External_Constit_Seen := True;
28756 end Collect_Constituent;
28760 State_Elmt : Elmt_Id;
28762 -- Start of processing for Match_Constituent
28765 -- Detect a duplicate use of a constituent
28767 if Contains (Constituents_Seen, Constit_Id) then
28769 ("duplicate use of constituent &", Constit, Constit_Id);
28773 -- The constituent is subject to a Part_Of indicator
28775 if Present (Encapsulating_State (Constit_Id)) then
28776 if Encapsulating_State (Constit_Id) = State_Id then
28777 Remove (Part_Of_Constits, Constit_Id);
28778 Collect_Constituent;
28780 -- The constituent is part of another state and is used
28781 -- incorrectly in the refinement of the current state.
28784 Error_Msg_Name_1 := Chars (State_Id);
28786 ("& cannot act as constituent of state %",
28787 Constit, Constit_Id);
28789 ("\Part_Of indicator specifies encapsulator &",
28790 Constit, Encapsulating_State (Constit_Id));
28793 -- The only other source of legal constituents is the body
28794 -- state space of the related package.
28797 if Present (Body_States) then
28798 State_Elmt := First_Elmt (Body_States);
28799 while Present (State_Elmt) loop
28801 -- Consume a valid constituent to signal that it has
28802 -- been encountered.
28804 if Node (State_Elmt) = Constit_Id then
28805 Remove_Elmt (Body_States, State_Elmt);
28806 Collect_Constituent;
28810 Next_Elmt (State_Elmt);
28814 -- At this point it is known that the constituent is not
28815 -- part of the package hidden state and cannot be used in
28816 -- a refinement (SPARK RM 7.2.2(9)).
28818 Error_Msg_Name_1 := Chars (Spec_Id);
28820 ("cannot use & in refinement, constituent is not a hidden "
28821 & "state of package %", Constit, Constit_Id);
28823 end Match_Constituent;
28827 Constit_Id : Entity_Id;
28828 Constits : Elist_Id;
28830 -- Start of processing for Analyze_Constituent
28833 -- Detect multiple uses of null in a single refinement clause or a
28834 -- mixture of null and non-null constituents.
28836 if Nkind (Constit) = N_Null then
28839 ("multiple null constituents not allowed", Constit);
28841 elsif Non_Null_Seen then
28843 ("cannot mix null and non-null constituents", Constit);
28848 -- Collect the constituent in the list of refinement items
28850 Constits := Refinement_Constituents (State_Id);
28852 if No (Constits) then
28853 Constits := New_Elmt_List;
28854 Set_Refinement_Constituents (State_Id, Constits);
28857 Append_Elmt (Constit, Constits);
28859 -- The state has at least one legal constituent, mark the
28860 -- start of the refinement region. The region ends when the
28861 -- body declarations end (see Analyze_Declarations).
28863 Set_Has_Visible_Refinement (State_Id);
28866 -- Non-null constituents
28869 Non_Null_Seen := True;
28873 ("cannot mix null and non-null constituents", Constit);
28877 Resolve_State (Constit);
28879 -- Ensure that the constituent denotes a valid state or a
28880 -- whole object (SPARK RM 7.2.2(5)).
28882 if Is_Entity_Name (Constit) then
28883 Constit_Id := Entity_Of (Constit);
28885 -- When a constituent is declared after a subprogram body
28886 -- that caused freezing of the related contract where
28887 -- pragma Refined_State resides, the constituent appears
28888 -- undefined and carries Any_Id as its entity.
28890 -- package body Pack
28891 -- with Refined_State => (State => Constit)
28894 -- with Refined_Global => (Input => Constit)
28902 if Constit_Id = Any_Id then
28903 SPARK_Msg_NE ("& is undefined", Constit, Constit_Id);
28905 -- Emit a specialized info message when the contract of
28906 -- the related package body was "frozen" by another body.
28907 -- Note that it is not possible to precisely identify why
28908 -- the constituent is undefined because it is not visible
28909 -- when pragma Refined_State is analyzed. This message is
28910 -- a reasonable approximation.
28912 if Present (Freeze_Id) and then not Freeze_Posted then
28913 Freeze_Posted := True;
28915 Error_Msg_Name_1 := Chars (Body_Id);
28916 Error_Msg_Sloc := Sloc (Freeze_Id);
28918 ("body & declared # freezes the contract of %",
28921 ("\all constituents must be declared before body #",
28924 -- A misplaced constituent is a critical error because
28925 -- pragma Refined_Depends or Refined_Global depends on
28926 -- the proper link between a state and a constituent.
28927 -- Stop the compilation, as this leads to a multitude
28928 -- of misleading cascaded errors.
28930 raise Unrecoverable_Error;
28933 -- The constituent is a valid state or object
28935 elsif Ekind_In (Constit_Id, E_Abstract_State,
28939 Match_Constituent (Constit_Id);
28941 -- The variable may eventually become a constituent of a
28942 -- single protected/task type. Record the reference now
28943 -- and verify its legality when analyzing the contract of
28944 -- the variable (SPARK RM 9.3).
28946 if Ekind (Constit_Id) = E_Variable then
28947 Record_Possible_Part_Of_Reference
28948 (Var_Id => Constit_Id,
28952 -- Otherwise the constituent is illegal
28956 ("constituent & must denote object or state",
28957 Constit, Constit_Id);
28960 -- The constituent is illegal
28963 SPARK_Msg_N ("malformed constituent", Constit);
28966 end Analyze_Constituent;
28968 -----------------------------
28969 -- Check_External_Property --
28970 -----------------------------
28972 procedure Check_External_Property
28973 (Prop_Nam : Name_Id;
28975 Constit : Entity_Id)
28978 -- The property is missing in the declaration of the state, but
28979 -- a constituent is introducing it in the state refinement
28980 -- (SPARK RM 7.2.8(2)).
28982 if not Enabled and then Present (Constit) then
28983 Error_Msg_Name_1 := Prop_Nam;
28984 Error_Msg_Name_2 := Chars (State_Id);
28986 ("constituent & introduces external property % in refinement "
28987 & "of state %", State, Constit);
28989 Error_Msg_Sloc := Sloc (State_Id);
28991 ("\property is missing in abstract state declaration #",
28994 end Check_External_Property;
29000 procedure Match_State is
29001 State_Elmt : Elmt_Id;
29004 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
29006 if Contains (Refined_States_Seen, State_Id) then
29008 ("duplicate refinement of state &", State, State_Id);
29012 -- Inspect the abstract states defined in the package declaration
29013 -- looking for a match.
29015 State_Elmt := First_Elmt (Available_States);
29016 while Present (State_Elmt) loop
29018 -- A valid abstract state is being refined in the body. Add
29019 -- the state to the list of processed refined states to aid
29020 -- with the detection of duplicate refinements. Remove the
29021 -- state from Available_States to signal that it has already
29024 if Node (State_Elmt) = State_Id then
29025 Append_New_Elmt (State_Id, Refined_States_Seen);
29026 Remove_Elmt (Available_States, State_Elmt);
29030 Next_Elmt (State_Elmt);
29033 -- If we get here, we are refining a state that is not defined in
29034 -- the package declaration.
29036 Error_Msg_Name_1 := Chars (Spec_Id);
29038 ("cannot refine state, & is not defined in package %",
29042 --------------------------------
29043 -- Report_Unused_Constituents --
29044 --------------------------------
29046 procedure Report_Unused_Constituents (Constits : Elist_Id) is
29047 Constit_Elmt : Elmt_Id;
29048 Constit_Id : Entity_Id;
29049 Posted : Boolean := False;
29052 if Present (Constits) then
29053 Constit_Elmt := First_Elmt (Constits);
29054 while Present (Constit_Elmt) loop
29055 Constit_Id := Node (Constit_Elmt);
29057 -- Generate an error message of the form:
29059 -- state ... has unused Part_Of constituents
29060 -- abstract state ... defined at ...
29061 -- constant ... defined at ...
29062 -- variable ... defined at ...
29067 ("state & has unused Part_Of constituents",
29071 Error_Msg_Sloc := Sloc (Constit_Id);
29073 if Ekind (Constit_Id) = E_Abstract_State then
29075 ("\abstract state & defined #", State, Constit_Id);
29077 elsif Ekind (Constit_Id) = E_Constant then
29079 ("\constant & defined #", State, Constit_Id);
29082 pragma Assert (Ekind (Constit_Id) = E_Variable);
29083 SPARK_Msg_NE ("\variable & defined #", State, Constit_Id);
29086 Next_Elmt (Constit_Elmt);
29089 end Report_Unused_Constituents;
29091 -- Local declarations
29093 Body_Ref : Node_Id;
29094 Body_Ref_Elmt : Elmt_Id;
29096 Extra_State : Node_Id;
29098 -- Start of processing for Analyze_Refinement_Clause
29101 -- A refinement clause appears as a component association where the
29102 -- sole choice is the state and the expressions are the constituents.
29103 -- This is a syntax error, always report.
29105 if Nkind (Clause) /= N_Component_Association then
29106 Error_Msg_N ("malformed state refinement clause", Clause);
29110 -- Analyze the state name of a refinement clause
29112 State := First (Choices (Clause));
29115 Resolve_State (State);
29117 -- Ensure that the state name denotes a valid abstract state that is
29118 -- defined in the spec of the related package.
29120 if Is_Entity_Name (State) then
29121 State_Id := Entity_Of (State);
29123 -- When the abstract state is undefined, it appears as Any_Id. Do
29124 -- not continue with the analysis of the clause.
29126 if State_Id = Any_Id then
29129 -- Catch any attempts to re-refine a state or refine a state that
29130 -- is not defined in the package declaration.
29132 elsif Ekind (State_Id) = E_Abstract_State then
29136 SPARK_Msg_NE ("& must denote abstract state", State, State_Id);
29140 -- References to a state with visible refinement are illegal.
29141 -- When nested packages are involved, detecting such references is
29142 -- tricky because pragma Refined_State is analyzed later than the
29143 -- offending pragma Depends or Global. References that occur in
29144 -- such nested context are stored in a list. Emit errors for all
29145 -- references found in Body_References (SPARK RM 6.1.4(8)).
29147 if Present (Body_References (State_Id)) then
29148 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
29149 while Present (Body_Ref_Elmt) loop
29150 Body_Ref := Node (Body_Ref_Elmt);
29152 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
29153 Error_Msg_Sloc := Sloc (State);
29154 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
29156 Next_Elmt (Body_Ref_Elmt);
29160 -- The state name is illegal. This is a syntax error, always report.
29163 Error_Msg_N ("malformed state name in refinement clause", State);
29167 -- A refinement clause may only refine one state at a time
29169 Extra_State := Next (State);
29171 if Present (Extra_State) then
29173 ("refinement clause cannot cover multiple states", Extra_State);
29176 -- Replicate the Part_Of constituents of the refined state because
29177 -- the algorithm will consume items.
29179 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
29181 -- Analyze all constituents of the refinement. Multiple constituents
29182 -- appear as an aggregate.
29184 Constit := Expression (Clause);
29186 if Nkind (Constit) = N_Aggregate then
29187 if Present (Component_Associations (Constit)) then
29189 ("constituents of refinement clause must appear in "
29190 & "positional form", Constit);
29192 else pragma Assert (Present (Expressions (Constit)));
29193 Constit := First (Expressions (Constit));
29194 while Present (Constit) loop
29195 Analyze_Constituent (Constit);
29200 -- Various forms of a single constituent. Note that these may include
29201 -- malformed constituents.
29204 Analyze_Constituent (Constit);
29207 -- Verify that external constituents do not introduce new external
29208 -- property in the state refinement (SPARK RM 7.2.8(2)).
29210 if Is_External_State (State_Id) then
29211 Check_External_Property
29212 (Prop_Nam => Name_Async_Readers,
29213 Enabled => Async_Readers_Enabled (State_Id),
29214 Constit => AR_Constit);
29216 Check_External_Property
29217 (Prop_Nam => Name_Async_Writers,
29218 Enabled => Async_Writers_Enabled (State_Id),
29219 Constit => AW_Constit);
29221 Check_External_Property
29222 (Prop_Nam => Name_Effective_Reads,
29223 Enabled => Effective_Reads_Enabled (State_Id),
29224 Constit => ER_Constit);
29226 Check_External_Property
29227 (Prop_Nam => Name_Effective_Writes,
29228 Enabled => Effective_Writes_Enabled (State_Id),
29229 Constit => EW_Constit);
29231 -- When a refined state is not external, it should not have external
29232 -- constituents (SPARK RM 7.2.8(1)).
29234 elsif External_Constit_Seen then
29236 ("non-external state & cannot contain external constituents in "
29237 & "refinement", State, State_Id);
29240 -- Ensure that all Part_Of candidate constituents have been mentioned
29241 -- in the refinement clause.
29243 Report_Unused_Constituents (Part_Of_Constits);
29244 end Analyze_Refinement_Clause;
29246 -----------------------------
29247 -- Report_Unrefined_States --
29248 -----------------------------
29250 procedure Report_Unrefined_States (States : Elist_Id) is
29251 State_Elmt : Elmt_Id;
29254 if Present (States) then
29255 State_Elmt := First_Elmt (States);
29256 while Present (State_Elmt) loop
29258 ("abstract state & must be refined", Node (State_Elmt));
29260 Next_Elmt (State_Elmt);
29263 end Report_Unrefined_States;
29265 -- Local declarations
29267 Clauses : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
29270 -- Start of processing for Analyze_Refined_State_In_Decl_Part
29273 -- Do not analyze the pragma multiple times
29275 if Is_Analyzed_Pragma (N) then
29279 -- Save the scenario for examination by the ABE Processing phase
29281 Record_Elaboration_Scenario (N);
29283 -- Replicate the abstract states declared by the package because the
29284 -- matching algorithm will consume states.
29286 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
29288 -- Gather all abstract states and objects declared in the visible
29289 -- state space of the package body. These items must be utilized as
29290 -- constituents in a state refinement.
29292 Body_States := Collect_Body_States (Body_Id);
29294 -- Multiple non-null state refinements appear as an aggregate
29296 if Nkind (Clauses) = N_Aggregate then
29297 if Present (Expressions (Clauses)) then
29299 ("state refinements must appear as component associations",
29302 else pragma Assert (Present (Component_Associations (Clauses)));
29303 Clause := First (Component_Associations (Clauses));
29304 while Present (Clause) loop
29305 Analyze_Refinement_Clause (Clause);
29310 -- Various forms of a single state refinement. Note that these may
29311 -- include malformed refinements.
29314 Analyze_Refinement_Clause (Clauses);
29317 -- List all abstract states that were left unrefined
29319 Report_Unrefined_States (Available_States);
29321 Set_Is_Analyzed_Pragma (N);
29322 end Analyze_Refined_State_In_Decl_Part;
29324 ------------------------------------
29325 -- Analyze_Test_Case_In_Decl_Part --
29326 ------------------------------------
29328 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is
29329 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
29330 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
29332 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id);
29333 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
29334 -- denoted by Arg_Nam.
29336 ------------------------------
29337 -- Preanalyze_Test_Case_Arg --
29338 ------------------------------
29340 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id) is
29344 -- Preanalyze the original aspect argument for a generic subprogram
29345 -- to properly capture global references.
29347 if Is_Generic_Subprogram (Spec_Id) then
29351 Arg_Nam => Arg_Nam,
29352 From_Aspect => True);
29354 if Present (Arg) then
29355 Preanalyze_Assert_Expression
29356 (Expression (Arg), Standard_Boolean);
29360 Arg := Test_Case_Arg (N, Arg_Nam);
29362 if Present (Arg) then
29363 Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean);
29365 end Preanalyze_Test_Case_Arg;
29369 Restore_Scope : Boolean := False;
29371 -- Start of processing for Analyze_Test_Case_In_Decl_Part
29374 -- Do not analyze the pragma multiple times
29376 if Is_Analyzed_Pragma (N) then
29380 -- Ensure that the formal parameters are visible when analyzing all
29381 -- clauses. This falls out of the general rule of aspects pertaining
29382 -- to subprogram declarations.
29384 if not In_Open_Scopes (Spec_Id) then
29385 Restore_Scope := True;
29386 Push_Scope (Spec_Id);
29388 if Is_Generic_Subprogram (Spec_Id) then
29389 Install_Generic_Formals (Spec_Id);
29391 Install_Formals (Spec_Id);
29395 Preanalyze_Test_Case_Arg (Name_Requires);
29396 Preanalyze_Test_Case_Arg (Name_Ensures);
29398 if Restore_Scope then
29402 -- Currently it is not possible to inline pre/postconditions on a
29403 -- subprogram subject to pragma Inline_Always.
29405 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
29407 Set_Is_Analyzed_Pragma (N);
29408 end Analyze_Test_Case_In_Decl_Part;
29414 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
29419 if Present (List) then
29420 Elmt := First_Elmt (List);
29421 while Present (Elmt) loop
29422 if Nkind (Node (Elmt)) = N_Defining_Identifier then
29425 Id := Entity_Of (Node (Elmt));
29428 if Id = Item_Id then
29439 -----------------------------------
29440 -- Build_Pragma_Check_Equivalent --
29441 -----------------------------------
29443 function Build_Pragma_Check_Equivalent
29445 Subp_Id : Entity_Id := Empty;
29446 Inher_Id : Entity_Id := Empty;
29447 Keep_Pragma_Id : Boolean := False) return Node_Id
29449 function Suppress_Reference (N : Node_Id) return Traverse_Result;
29450 -- Detect whether node N references a formal parameter subject to
29451 -- pragma Unreferenced. If this is the case, set Comes_From_Source
29452 -- to False to suppress the generation of a reference when analyzing
29455 ------------------------
29456 -- Suppress_Reference --
29457 ------------------------
29459 function Suppress_Reference (N : Node_Id) return Traverse_Result is
29460 Formal : Entity_Id;
29463 if Is_Entity_Name (N) and then Present (Entity (N)) then
29464 Formal := Entity (N);
29466 -- The formal parameter is subject to pragma Unreferenced. Prevent
29467 -- the generation of references by resetting the Comes_From_Source
29470 if Is_Formal (Formal)
29471 and then Has_Pragma_Unreferenced (Formal)
29473 Set_Comes_From_Source (N, False);
29478 end Suppress_Reference;
29480 procedure Suppress_References is
29481 new Traverse_Proc (Suppress_Reference);
29485 Loc : constant Source_Ptr := Sloc (Prag);
29486 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
29487 Check_Prag : Node_Id;
29491 Needs_Wrapper : Boolean;
29492 pragma Unreferenced (Needs_Wrapper);
29494 -- Start of processing for Build_Pragma_Check_Equivalent
29497 -- When the pre- or postcondition is inherited, map the formals of the
29498 -- inherited subprogram to those of the current subprogram. In addition,
29499 -- map primitive operations of the parent type into the corresponding
29500 -- primitive operations of the descendant.
29502 if Present (Inher_Id) then
29503 pragma Assert (Present (Subp_Id));
29505 Update_Primitives_Mapping (Inher_Id, Subp_Id);
29507 -- Use generic machinery to copy inherited pragma, as if it were an
29508 -- instantiation, resetting source locations appropriately, so that
29509 -- expressions inside the inherited pragma use chained locations.
29510 -- This is used in particular in GNATprove to locate precisely
29511 -- messages on a given inherited pragma.
29513 Set_Copied_Sloc_For_Inherited_Pragma
29514 (Unit_Declaration_Node (Subp_Id), Inher_Id);
29515 Check_Prag := New_Copy_Tree (Source => Prag);
29517 -- Build the inherited class-wide condition
29519 Build_Class_Wide_Expression
29520 (Prag => Check_Prag,
29522 Par_Subp => Inher_Id,
29523 Adjust_Sloc => True,
29524 Needs_Wrapper => Needs_Wrapper);
29526 -- If not an inherited condition simply copy the original pragma
29529 Check_Prag := New_Copy_Tree (Source => Prag);
29532 -- Mark the pragma as being internally generated and reset the Analyzed
29535 Set_Analyzed (Check_Prag, False);
29536 Set_Comes_From_Source (Check_Prag, False);
29538 -- The tree of the original pragma may contain references to the
29539 -- formal parameters of the related subprogram. At the same time
29540 -- the corresponding body may mark the formals as unreferenced:
29542 -- procedure Proc (Formal : ...)
29543 -- with Pre => Formal ...;
29545 -- procedure Proc (Formal : ...) is
29546 -- pragma Unreferenced (Formal);
29549 -- This creates problems because all pragma Check equivalents are
29550 -- analyzed at the end of the body declarations. Since all source
29551 -- references have already been accounted for, reset any references
29552 -- to such formals in the generated pragma Check equivalent.
29554 Suppress_References (Check_Prag);
29556 if Present (Corresponding_Aspect (Prag)) then
29557 Nam := Chars (Identifier (Corresponding_Aspect (Prag)));
29562 -- Unless Keep_Pragma_Id is True in order to keep the identifier of
29563 -- the copied pragma in the newly created pragma, convert the copy into
29564 -- pragma Check by correcting the name and adding a check_kind argument.
29566 if not Keep_Pragma_Id then
29567 Set_Class_Present (Check_Prag, False);
29569 Set_Pragma_Identifier
29570 (Check_Prag, Make_Identifier (Loc, Name_Check));
29572 Prepend_To (Pragma_Argument_Associations (Check_Prag),
29573 Make_Pragma_Argument_Association (Loc,
29574 Expression => Make_Identifier (Loc, Nam)));
29577 -- Update the error message when the pragma is inherited
29579 if Present (Inher_Id) then
29580 Msg_Arg := Last (Pragma_Argument_Associations (Check_Prag));
29582 if Chars (Msg_Arg) = Name_Message then
29583 String_To_Name_Buffer (Strval (Expression (Msg_Arg)));
29585 -- Insert "inherited" to improve the error message
29587 if Name_Buffer (1 .. 8) = "failed p" then
29588 Insert_Str_In_Name_Buffer ("inherited ", 8);
29589 Set_Strval (Expression (Msg_Arg), String_From_Name_Buffer);
29595 end Build_Pragma_Check_Equivalent;
29597 -----------------------------
29598 -- Check_Applicable_Policy --
29599 -----------------------------
29601 procedure Check_Applicable_Policy (N : Node_Id) is
29605 Ename : constant Name_Id := Original_Aspect_Pragma_Name (N);
29608 -- No effect if not valid assertion kind name
29610 if not Is_Valid_Assertion_Kind (Ename) then
29614 -- Loop through entries in check policy list
29616 PP := Opt.Check_Policy_List;
29617 while Present (PP) loop
29619 PPA : constant List_Id := Pragma_Argument_Associations (PP);
29620 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
29624 or else Pnm = Name_Assertion
29625 or else (Pnm = Name_Statement_Assertions
29626 and then Nam_In (Ename, Name_Assert,
29627 Name_Assert_And_Cut,
29629 Name_Loop_Invariant,
29630 Name_Loop_Variant))
29632 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
29638 -- In CodePeer mode and GNATprove mode, we need to
29639 -- consider all assertions, unless they are disabled.
29640 -- Force Is_Checked on ignored assertions, in particular
29641 -- because transformations of the AST may depend on
29642 -- assertions being checked (e.g. the translation of
29643 -- attribute 'Loop_Entry).
29645 if CodePeer_Mode or GNATprove_Mode then
29646 Set_Is_Checked (N, True);
29647 Set_Is_Ignored (N, False);
29649 Set_Is_Checked (N, False);
29650 Set_Is_Ignored (N, True);
29656 Set_Is_Checked (N, True);
29657 Set_Is_Ignored (N, False);
29659 when Name_Disable =>
29660 Set_Is_Ignored (N, True);
29661 Set_Is_Checked (N, False);
29662 Set_Is_Disabled (N, True);
29664 -- That should be exhaustive, the null here is a defence
29665 -- against a malformed tree from previous errors.
29674 PP := Next_Pragma (PP);
29678 -- If there are no specific entries that matched, then we let the
29679 -- setting of assertions govern. Note that this provides the needed
29680 -- compatibility with the RM for the cases of assertion, invariant,
29681 -- precondition, predicate, and postcondition. Note also that
29682 -- Assertions_Enabled is forced in CodePeer mode and GNATprove mode.
29684 if Assertions_Enabled then
29685 Set_Is_Checked (N, True);
29686 Set_Is_Ignored (N, False);
29688 Set_Is_Checked (N, False);
29689 Set_Is_Ignored (N, True);
29691 end Check_Applicable_Policy;
29693 -------------------------------
29694 -- Check_External_Properties --
29695 -------------------------------
29697 procedure Check_External_Properties
29705 -- All properties enabled
29707 if AR and AW and ER and EW then
29710 -- Async_Readers + Effective_Writes
29711 -- Async_Readers + Async_Writers + Effective_Writes
29713 elsif AR and EW and not ER then
29716 -- Async_Writers + Effective_Reads
29717 -- Async_Readers + Async_Writers + Effective_Reads
29719 elsif AW and ER and not EW then
29722 -- Async_Readers + Async_Writers
29724 elsif AR and AW and not ER and not EW then
29729 elsif AR and not AW and not ER and not EW then
29734 elsif AW and not AR and not ER and not EW then
29739 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
29742 end Check_External_Properties;
29748 function Check_Kind (Nam : Name_Id) return Name_Id is
29752 -- Loop through entries in check policy list
29754 PP := Opt.Check_Policy_List;
29755 while Present (PP) loop
29757 PPA : constant List_Id := Pragma_Argument_Associations (PP);
29758 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
29762 or else (Pnm = Name_Assertion
29763 and then Is_Valid_Assertion_Kind (Nam))
29764 or else (Pnm = Name_Statement_Assertions
29765 and then Nam_In (Nam, Name_Assert,
29766 Name_Assert_And_Cut,
29768 Name_Loop_Invariant,
29769 Name_Loop_Variant))
29771 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
29780 return Name_Ignore;
29782 when Name_Disable =>
29783 return Name_Disable;
29786 raise Program_Error;
29790 PP := Next_Pragma (PP);
29795 -- If there are no specific entries that matched, then we let the
29796 -- setting of assertions govern. Note that this provides the needed
29797 -- compatibility with the RM for the cases of assertion, invariant,
29798 -- precondition, predicate, and postcondition.
29800 if Assertions_Enabled then
29803 return Name_Ignore;
29807 ---------------------------
29808 -- Check_Missing_Part_Of --
29809 ---------------------------
29811 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
29812 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
29813 -- Determine whether a package denoted by Pack_Id declares at least one
29816 -----------------------
29817 -- Has_Visible_State --
29818 -----------------------
29820 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
29821 Item_Id : Entity_Id;
29824 -- Traverse the entity chain of the package trying to find at least
29825 -- one visible abstract state, variable or a package [instantiation]
29826 -- that declares a visible state.
29828 Item_Id := First_Entity (Pack_Id);
29829 while Present (Item_Id)
29830 and then not In_Private_Part (Item_Id)
29832 -- Do not consider internally generated items
29834 if not Comes_From_Source (Item_Id) then
29837 -- Do not consider generic formals or their corresponding actuals
29838 -- because they are not part of a visible state. Note that both
29839 -- entities are marked as hidden.
29841 elsif Is_Hidden (Item_Id) then
29844 -- A visible state has been found. Note that constants are not
29845 -- considered here because it is not possible to determine whether
29846 -- they depend on variable input. This check is left to the SPARK
29849 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
29852 -- Recursively peek into nested packages and instantiations
29854 elsif Ekind (Item_Id) = E_Package
29855 and then Has_Visible_State (Item_Id)
29860 Next_Entity (Item_Id);
29864 end Has_Visible_State;
29868 Pack_Id : Entity_Id;
29869 Placement : State_Space_Kind;
29871 -- Start of processing for Check_Missing_Part_Of
29874 -- Do not consider abstract states, variables or package instantiations
29875 -- coming from an instance as those always inherit the Part_Of indicator
29876 -- of the instance itself.
29878 if In_Instance then
29881 -- Do not consider internally generated entities as these can never
29882 -- have a Part_Of indicator.
29884 elsif not Comes_From_Source (Item_Id) then
29887 -- Perform these checks only when SPARK_Mode is enabled as they will
29888 -- interfere with standard Ada rules and produce false positives.
29890 elsif SPARK_Mode /= On then
29893 -- Do not consider constants, because the compiler cannot accurately
29894 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
29895 -- act as a hidden state of a package.
29897 elsif Ekind (Item_Id) = E_Constant then
29901 -- Find where the abstract state, variable or package instantiation
29902 -- lives with respect to the state space.
29904 Find_Placement_In_State_Space
29905 (Item_Id => Item_Id,
29906 Placement => Placement,
29907 Pack_Id => Pack_Id);
29909 -- Items that appear in a non-package construct (subprogram, block, etc)
29910 -- do not require a Part_Of indicator because they can never act as a
29913 if Placement = Not_In_Package then
29916 -- An item declared in the body state space of a package always act as a
29917 -- constituent and does not need explicit Part_Of indicator.
29919 elsif Placement = Body_State_Space then
29922 -- In general an item declared in the visible state space of a package
29923 -- does not require a Part_Of indicator. The only exception is when the
29924 -- related package is a nongeneric private child unit, in which case
29925 -- Part_Of must denote a state in the parent unit or in one of its
29928 elsif Placement = Visible_State_Space then
29929 if Is_Child_Unit (Pack_Id)
29930 and then not Is_Generic_Unit (Pack_Id)
29931 and then Is_Private_Descendant (Pack_Id)
29933 -- A package instantiation does not need a Part_Of indicator when
29934 -- the related generic template has no visible state.
29936 if Ekind (Item_Id) = E_Package
29937 and then Is_Generic_Instance (Item_Id)
29938 and then not Has_Visible_State (Item_Id)
29942 -- All other cases require Part_Of
29946 ("indicator Part_Of is required in this context "
29947 & "(SPARK RM 7.2.6(3))", Item_Id);
29948 Error_Msg_Name_1 := Chars (Pack_Id);
29950 ("\& is declared in the visible part of private child "
29951 & "unit %", Item_Id);
29955 -- When the item appears in the private state space of a package, it
29956 -- must be a part of some state declared by the said package.
29958 else pragma Assert (Placement = Private_State_Space);
29960 -- The related package does not declare a state, the item cannot act
29961 -- as a Part_Of constituent.
29963 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
29966 -- A package instantiation does not need a Part_Of indicator when the
29967 -- related generic template has no visible state.
29969 elsif Ekind (Item_Id) = E_Package
29970 and then Is_Generic_Instance (Item_Id)
29971 and then not Has_Visible_State (Item_Id)
29975 -- All other cases require Part_Of
29979 ("indicator Part_Of is required in this context "
29980 & "(SPARK RM 7.2.6(2))", Item_Id);
29981 Error_Msg_Name_1 := Chars (Pack_Id);
29983 ("\& is declared in the private part of package %", Item_Id);
29986 end Check_Missing_Part_Of;
29988 ---------------------------------------------------
29989 -- Check_Postcondition_Use_In_Inlined_Subprogram --
29990 ---------------------------------------------------
29992 procedure Check_Postcondition_Use_In_Inlined_Subprogram
29994 Spec_Id : Entity_Id)
29997 if Warn_On_Redundant_Constructs
29998 and then Has_Pragma_Inline_Always (Spec_Id)
29999 and then Assertions_Enabled
30001 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
30003 if From_Aspect_Specification (Prag) then
30005 ("aspect % not enforced on inlined subprogram &?r?",
30006 Corresponding_Aspect (Prag), Spec_Id);
30009 ("pragma % not enforced on inlined subprogram &?r?",
30013 end Check_Postcondition_Use_In_Inlined_Subprogram;
30015 -------------------------------------
30016 -- Check_State_And_Constituent_Use --
30017 -------------------------------------
30019 procedure Check_State_And_Constituent_Use
30020 (States : Elist_Id;
30021 Constits : Elist_Id;
30024 Constit_Elmt : Elmt_Id;
30025 Constit_Id : Entity_Id;
30026 State_Id : Entity_Id;
30029 -- Nothing to do if there are no states or constituents
30031 if No (States) or else No (Constits) then
30035 -- Inspect the list of constituents and try to determine whether its
30036 -- encapsulating state is in list States.
30038 Constit_Elmt := First_Elmt (Constits);
30039 while Present (Constit_Elmt) loop
30040 Constit_Id := Node (Constit_Elmt);
30042 -- Determine whether the constituent is part of an encapsulating
30043 -- state that appears in the same context and if this is the case,
30044 -- emit an error (SPARK RM 7.2.6(7)).
30046 State_Id := Find_Encapsulating_State (States, Constit_Id);
30048 if Present (State_Id) then
30049 Error_Msg_Name_1 := Chars (Constit_Id);
30051 ("cannot mention state & and its constituent % in the same "
30052 & "context", Context, State_Id);
30056 Next_Elmt (Constit_Elmt);
30058 end Check_State_And_Constituent_Use;
30060 ---------------------------------------------
30061 -- Collect_Inherited_Class_Wide_Conditions --
30062 ---------------------------------------------
30064 procedure Collect_Inherited_Class_Wide_Conditions (Subp : Entity_Id) is
30065 Parent_Subp : constant Entity_Id :=
30066 Ultimate_Alias (Overridden_Operation (Subp));
30067 -- The Overridden_Operation may itself be inherited and as such have no
30068 -- explicit contract.
30070 Prags : constant Node_Id := Contract (Parent_Subp);
30071 In_Spec_Expr : Boolean := In_Spec_Expression;
30072 Installed : Boolean;
30074 New_Prag : Node_Id;
30077 Installed := False;
30079 -- Iterate over the contract of the overridden subprogram to find all
30080 -- inherited class-wide pre- and postconditions.
30082 if Present (Prags) then
30083 Prag := Pre_Post_Conditions (Prags);
30085 while Present (Prag) loop
30086 if Nam_In (Pragma_Name_Unmapped (Prag),
30087 Name_Precondition, Name_Postcondition)
30088 and then Class_Present (Prag)
30090 -- The generated pragma must be analyzed in the context of
30091 -- the subprogram, to make its formals visible. In addition,
30092 -- we must inhibit freezing and full analysis because the
30093 -- controlling type of the subprogram is not frozen yet, and
30094 -- may have further primitives.
30096 if not Installed then
30099 Install_Formals (Subp);
30100 In_Spec_Expr := In_Spec_Expression;
30101 In_Spec_Expression := True;
30105 Build_Pragma_Check_Equivalent
30106 (Prag, Subp, Parent_Subp, Keep_Pragma_Id => True);
30108 Insert_After (Unit_Declaration_Node (Subp), New_Prag);
30109 Preanalyze (New_Prag);
30111 -- Prevent further analysis in subsequent processing of the
30112 -- current list of declarations
30114 Set_Analyzed (New_Prag);
30117 Prag := Next_Pragma (Prag);
30121 In_Spec_Expression := In_Spec_Expr;
30125 end Collect_Inherited_Class_Wide_Conditions;
30127 ---------------------------------------
30128 -- Collect_Subprogram_Inputs_Outputs --
30129 ---------------------------------------
30131 procedure Collect_Subprogram_Inputs_Outputs
30132 (Subp_Id : Entity_Id;
30133 Synthesize : Boolean := False;
30134 Subp_Inputs : in out Elist_Id;
30135 Subp_Outputs : in out Elist_Id;
30136 Global_Seen : out Boolean)
30138 procedure Collect_Dependency_Clause (Clause : Node_Id);
30139 -- Collect all relevant items from a dependency clause
30141 procedure Collect_Global_List
30143 Mode : Name_Id := Name_Input);
30144 -- Collect all relevant items from a global list
30146 -------------------------------
30147 -- Collect_Dependency_Clause --
30148 -------------------------------
30150 procedure Collect_Dependency_Clause (Clause : Node_Id) is
30151 procedure Collect_Dependency_Item
30153 Is_Input : Boolean);
30154 -- Add an item to the proper subprogram input or output collection
30156 -----------------------------
30157 -- Collect_Dependency_Item --
30158 -----------------------------
30160 procedure Collect_Dependency_Item
30162 Is_Input : Boolean)
30167 -- Nothing to collect when the item is null
30169 if Nkind (Item) = N_Null then
30172 -- Ditto for attribute 'Result
30174 elsif Is_Attribute_Result (Item) then
30177 -- Multiple items appear as an aggregate
30179 elsif Nkind (Item) = N_Aggregate then
30180 Extra := First (Expressions (Item));
30181 while Present (Extra) loop
30182 Collect_Dependency_Item (Extra, Is_Input);
30186 -- Otherwise this is a solitary item
30190 Append_New_Elmt (Item, Subp_Inputs);
30192 Append_New_Elmt (Item, Subp_Outputs);
30195 end Collect_Dependency_Item;
30197 -- Start of processing for Collect_Dependency_Clause
30200 if Nkind (Clause) = N_Null then
30203 -- A dependency clause appears as component association
30205 elsif Nkind (Clause) = N_Component_Association then
30206 Collect_Dependency_Item
30207 (Item => Expression (Clause),
30210 Collect_Dependency_Item
30211 (Item => First (Choices (Clause)),
30212 Is_Input => False);
30214 -- To accommodate partial decoration of disabled SPARK features, this
30215 -- routine may be called with illegal input. If this is the case, do
30216 -- not raise Program_Error.
30221 end Collect_Dependency_Clause;
30223 -------------------------
30224 -- Collect_Global_List --
30225 -------------------------
30227 procedure Collect_Global_List
30229 Mode : Name_Id := Name_Input)
30231 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
30232 -- Add an item to the proper subprogram input or output collection
30234 -------------------------
30235 -- Collect_Global_Item --
30236 -------------------------
30238 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
30240 if Nam_In (Mode, Name_In_Out, Name_Input) then
30241 Append_New_Elmt (Item, Subp_Inputs);
30244 if Nam_In (Mode, Name_In_Out, Name_Output) then
30245 Append_New_Elmt (Item, Subp_Outputs);
30247 end Collect_Global_Item;
30254 -- Start of processing for Collect_Global_List
30257 if Nkind (List) = N_Null then
30260 -- Single global item declaration
30262 elsif Nkind_In (List, N_Expanded_Name,
30264 N_Selected_Component)
30266 Collect_Global_Item (List, Mode);
30268 -- Simple global list or moded global list declaration
30270 elsif Nkind (List) = N_Aggregate then
30271 if Present (Expressions (List)) then
30272 Item := First (Expressions (List));
30273 while Present (Item) loop
30274 Collect_Global_Item (Item, Mode);
30279 Assoc := First (Component_Associations (List));
30280 while Present (Assoc) loop
30281 Collect_Global_List
30282 (List => Expression (Assoc),
30283 Mode => Chars (First (Choices (Assoc))));
30288 -- To accommodate partial decoration of disabled SPARK features, this
30289 -- routine may be called with illegal input. If this is the case, do
30290 -- not raise Program_Error.
30295 end Collect_Global_List;
30302 Formal : Entity_Id;
30304 Spec_Id : Entity_Id := Empty;
30305 Subp_Decl : Node_Id;
30308 -- Start of processing for Collect_Subprogram_Inputs_Outputs
30311 Global_Seen := False;
30313 -- Process all formal parameters of entries, [generic] subprograms, and
30316 if Ekind_In (Subp_Id, E_Entry,
30319 E_Generic_Function,
30320 E_Generic_Procedure,
30324 Subp_Decl := Unit_Declaration_Node (Subp_Id);
30325 Spec_Id := Unique_Defining_Entity (Subp_Decl);
30327 -- Process all formal parameters
30329 Formal := First_Entity (Spec_Id);
30330 while Present (Formal) loop
30331 if Ekind_In (Formal, E_In_Out_Parameter, E_In_Parameter) then
30332 Append_New_Elmt (Formal, Subp_Inputs);
30335 if Ekind_In (Formal, E_In_Out_Parameter, E_Out_Parameter) then
30336 Append_New_Elmt (Formal, Subp_Outputs);
30338 -- Out parameters can act as inputs when the related type is
30339 -- tagged, unconstrained array, unconstrained record, or record
30340 -- with unconstrained components.
30342 if Ekind (Formal) = E_Out_Parameter
30343 and then Is_Unconstrained_Or_Tagged_Item (Formal)
30345 Append_New_Elmt (Formal, Subp_Inputs);
30349 Next_Entity (Formal);
30352 -- Otherwise the input denotes a task type, a task body, or the
30353 -- anonymous object created for a single task type.
30355 elsif Ekind_In (Subp_Id, E_Task_Type, E_Task_Body)
30356 or else Is_Single_Task_Object (Subp_Id)
30358 Subp_Decl := Declaration_Node (Subp_Id);
30359 Spec_Id := Unique_Defining_Entity (Subp_Decl);
30362 -- When processing an entry, subprogram or task body, look for pragmas
30363 -- Refined_Depends and Refined_Global as they specify the inputs and
30366 if Is_Entry_Body (Subp_Id)
30367 or else Ekind_In (Subp_Id, E_Subprogram_Body, E_Task_Body)
30369 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
30370 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
30372 -- Subprogram declaration or stand-alone body case, look for pragmas
30373 -- Depends and Global
30376 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
30377 Global := Get_Pragma (Spec_Id, Pragma_Global);
30380 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
30381 -- because it provides finer granularity of inputs and outputs.
30383 if Present (Global) then
30384 Global_Seen := True;
30385 Collect_Global_List (Expression (Get_Argument (Global, Spec_Id)));
30387 -- When the related subprogram lacks pragma [Refined_]Global, fall back
30388 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
30389 -- the inputs and outputs from [Refined_]Depends.
30391 elsif Synthesize and then Present (Depends) then
30392 Clauses := Expression (Get_Argument (Depends, Spec_Id));
30394 -- Multiple dependency clauses appear as an aggregate
30396 if Nkind (Clauses) = N_Aggregate then
30397 Clause := First (Component_Associations (Clauses));
30398 while Present (Clause) loop
30399 Collect_Dependency_Clause (Clause);
30403 -- Otherwise this is a single dependency clause
30406 Collect_Dependency_Clause (Clauses);
30410 -- The current instance of a protected type acts as a formal parameter
30411 -- of mode IN for functions and IN OUT for entries and procedures
30412 -- (SPARK RM 6.1.4).
30414 if Ekind (Scope (Spec_Id)) = E_Protected_Type then
30415 Typ := Scope (Spec_Id);
30417 -- Use the anonymous object when the type is single protected
30419 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
30420 Typ := Anonymous_Object (Typ);
30423 Append_New_Elmt (Typ, Subp_Inputs);
30425 if Ekind_In (Spec_Id, E_Entry, E_Entry_Family, E_Procedure) then
30426 Append_New_Elmt (Typ, Subp_Outputs);
30429 -- The current instance of a task type acts as a formal parameter of
30430 -- mode IN OUT (SPARK RM 6.1.4).
30432 elsif Ekind (Spec_Id) = E_Task_Type then
30435 -- Use the anonymous object when the type is single task
30437 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
30438 Typ := Anonymous_Object (Typ);
30441 Append_New_Elmt (Typ, Subp_Inputs);
30442 Append_New_Elmt (Typ, Subp_Outputs);
30444 elsif Is_Single_Task_Object (Spec_Id) then
30445 Append_New_Elmt (Spec_Id, Subp_Inputs);
30446 Append_New_Elmt (Spec_Id, Subp_Outputs);
30448 end Collect_Subprogram_Inputs_Outputs;
30450 ---------------------------
30451 -- Contract_Freeze_Error --
30452 ---------------------------
30454 procedure Contract_Freeze_Error
30455 (Contract_Id : Entity_Id;
30456 Freeze_Id : Entity_Id)
30459 Error_Msg_Name_1 := Chars (Contract_Id);
30460 Error_Msg_Sloc := Sloc (Freeze_Id);
30463 ("body & declared # freezes the contract of%", Contract_Id, Freeze_Id);
30465 ("\all contractual items must be declared before body #", Contract_Id);
30466 end Contract_Freeze_Error;
30468 ---------------------------------
30469 -- Delay_Config_Pragma_Analyze --
30470 ---------------------------------
30472 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
30474 return Nam_In (Pragma_Name_Unmapped (N),
30475 Name_Interrupt_State, Name_Priority_Specific_Dispatching);
30476 end Delay_Config_Pragma_Analyze;
30478 -----------------------
30479 -- Duplication_Error --
30480 -----------------------
30482 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is
30483 Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag);
30484 Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev);
30487 Error_Msg_Sloc := Sloc (Prev);
30488 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
30490 -- Emit a precise message to distinguish between source pragmas and
30491 -- pragmas generated from aspects. The ordering of the two pragmas is
30495 -- Prag -- duplicate
30497 -- No error is emitted when both pragmas come from aspects because this
30498 -- is already detected by the general aspect analysis mechanism.
30500 if Prag_From_Asp and Prev_From_Asp then
30502 elsif Prag_From_Asp then
30503 Error_Msg_N ("aspect % duplicates pragma declared #", Prag);
30504 elsif Prev_From_Asp then
30505 Error_Msg_N ("pragma % duplicates aspect declared #", Prag);
30507 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
30509 end Duplication_Error;
30511 ------------------------------
30512 -- Find_Encapsulating_State --
30513 ------------------------------
30515 function Find_Encapsulating_State
30516 (States : Elist_Id;
30517 Constit_Id : Entity_Id) return Entity_Id
30519 State_Id : Entity_Id;
30522 -- Since a constituent may be part of a larger constituent set, climb
30523 -- the encapsulating state chain looking for a state that appears in
30526 State_Id := Encapsulating_State (Constit_Id);
30527 while Present (State_Id) loop
30528 if Contains (States, State_Id) then
30532 State_Id := Encapsulating_State (State_Id);
30536 end Find_Encapsulating_State;
30538 --------------------------
30539 -- Find_Related_Context --
30540 --------------------------
30542 function Find_Related_Context
30544 Do_Checks : Boolean := False) return Node_Id
30549 Stmt := Prev (Prag);
30550 while Present (Stmt) loop
30552 -- Skip prior pragmas, but check for duplicates
30554 if Nkind (Stmt) = N_Pragma then
30556 and then Pragma_Name (Stmt) = Pragma_Name (Prag)
30563 -- Skip internally generated code
30565 elsif not Comes_From_Source (Stmt) then
30567 -- The anonymous object created for a single concurrent type is a
30568 -- suitable context.
30570 if Nkind (Stmt) = N_Object_Declaration
30571 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
30576 -- Return the current source construct
30586 end Find_Related_Context;
30588 --------------------------------------
30589 -- Find_Related_Declaration_Or_Body --
30590 --------------------------------------
30592 function Find_Related_Declaration_Or_Body
30594 Do_Checks : Boolean := False) return Node_Id
30596 Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
30598 procedure Expression_Function_Error;
30599 -- Emit an error concerning pragma Prag that illegaly applies to an
30600 -- expression function.
30602 -------------------------------
30603 -- Expression_Function_Error --
30604 -------------------------------
30606 procedure Expression_Function_Error is
30608 Error_Msg_Name_1 := Prag_Nam;
30610 -- Emit a precise message to distinguish between source pragmas and
30611 -- pragmas generated from aspects.
30613 if From_Aspect_Specification (Prag) then
30615 ("aspect % cannot apply to a stand alone expression function",
30619 ("pragma % cannot apply to a stand alone expression function",
30622 end Expression_Function_Error;
30626 Context : constant Node_Id := Parent (Prag);
30629 Look_For_Body : constant Boolean :=
30630 Nam_In (Prag_Nam, Name_Refined_Depends,
30631 Name_Refined_Global,
30633 Name_Refined_State);
30634 -- Refinement pragmas must be associated with a subprogram body [stub]
30636 -- Start of processing for Find_Related_Declaration_Or_Body
30639 Stmt := Prev (Prag);
30640 while Present (Stmt) loop
30642 -- Skip prior pragmas, but check for duplicates. Pragmas produced
30643 -- by splitting a complex pre/postcondition are not considered to
30646 if Nkind (Stmt) = N_Pragma then
30648 and then not Split_PPC (Stmt)
30649 and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam
30656 -- Emit an error when a refinement pragma appears on an expression
30657 -- function without a completion.
30660 and then Look_For_Body
30661 and then Nkind (Stmt) = N_Subprogram_Declaration
30662 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
30663 and then not Has_Completion (Defining_Entity (Stmt))
30665 Expression_Function_Error;
30668 -- The refinement pragma applies to a subprogram body stub
30670 elsif Look_For_Body
30671 and then Nkind (Stmt) = N_Subprogram_Body_Stub
30675 -- Skip internally generated code
30677 elsif not Comes_From_Source (Stmt) then
30679 -- The anonymous object created for a single concurrent type is a
30680 -- suitable context.
30682 if Nkind (Stmt) = N_Object_Declaration
30683 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
30687 elsif Nkind (Stmt) = N_Subprogram_Declaration then
30689 -- The subprogram declaration is an internally generated spec
30690 -- for an expression function.
30692 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
30695 -- The subprogram declaration is an internally generated spec
30696 -- for a stand-alone subrogram body declared inside a protected
30699 elsif Present (Corresponding_Body (Stmt))
30700 and then Comes_From_Source (Corresponding_Body (Stmt))
30701 and then Is_Protected_Type (Current_Scope)
30705 -- The subprogram is actually an instance housed within an
30706 -- anonymous wrapper package.
30708 elsif Present (Generic_Parent (Specification (Stmt))) then
30713 -- Return the current construct which is either a subprogram body,
30714 -- a subprogram declaration or is illegal.
30723 -- If we fall through, then the pragma was either the first declaration
30724 -- or it was preceded by other pragmas and no source constructs.
30726 -- The pragma is associated with a library-level subprogram
30728 if Nkind (Context) = N_Compilation_Unit_Aux then
30729 return Unit (Parent (Context));
30731 -- The pragma appears inside the declarations of an entry body
30733 elsif Nkind (Context) = N_Entry_Body then
30736 -- The pragma appears inside the statements of a subprogram body. This
30737 -- placement is the result of subprogram contract expansion.
30739 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
30740 return Parent (Context);
30742 -- The pragma appears inside the declarative part of a package body
30744 elsif Nkind (Context) = N_Package_Body then
30747 -- The pragma appears inside the declarative part of a subprogram body
30749 elsif Nkind (Context) = N_Subprogram_Body then
30752 -- The pragma appears inside the declarative part of a task body
30754 elsif Nkind (Context) = N_Task_Body then
30757 -- The pragma appears inside the visible part of a package specification
30759 elsif Nkind (Context) = N_Package_Specification then
30760 return Parent (Context);
30762 -- The pragma is a byproduct of aspect expansion, return the related
30763 -- context of the original aspect. This case has a lower priority as
30764 -- the above circuitry pinpoints precisely the related context.
30766 elsif Present (Corresponding_Aspect (Prag)) then
30767 return Parent (Corresponding_Aspect (Prag));
30769 -- No candidate subprogram [body] found
30774 end Find_Related_Declaration_Or_Body;
30776 ----------------------------------
30777 -- Find_Related_Package_Or_Body --
30778 ----------------------------------
30780 function Find_Related_Package_Or_Body
30782 Do_Checks : Boolean := False) return Node_Id
30784 Context : constant Node_Id := Parent (Prag);
30785 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
30789 Stmt := Prev (Prag);
30790 while Present (Stmt) loop
30792 -- Skip prior pragmas, but check for duplicates
30794 if Nkind (Stmt) = N_Pragma then
30795 if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then
30801 -- Skip internally generated code
30803 elsif not Comes_From_Source (Stmt) then
30804 if Nkind (Stmt) = N_Subprogram_Declaration then
30806 -- The subprogram declaration is an internally generated spec
30807 -- for an expression function.
30809 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
30812 -- The subprogram is actually an instance housed within an
30813 -- anonymous wrapper package.
30815 elsif Present (Generic_Parent (Specification (Stmt))) then
30820 -- Return the current source construct which is illegal
30829 -- If we fall through, then the pragma was either the first declaration
30830 -- or it was preceded by other pragmas and no source constructs.
30832 -- The pragma is associated with a package. The immediate context in
30833 -- this case is the specification of the package.
30835 if Nkind (Context) = N_Package_Specification then
30836 return Parent (Context);
30838 -- The pragma appears in the declarations of a package body
30840 elsif Nkind (Context) = N_Package_Body then
30843 -- The pragma appears in the statements of a package body
30845 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
30846 and then Nkind (Parent (Context)) = N_Package_Body
30848 return Parent (Context);
30850 -- The pragma is a byproduct of aspect expansion, return the related
30851 -- context of the original aspect. This case has a lower priority as
30852 -- the above circuitry pinpoints precisely the related context.
30854 elsif Present (Corresponding_Aspect (Prag)) then
30855 return Parent (Corresponding_Aspect (Prag));
30857 -- No candidate package [body] found
30862 end Find_Related_Package_Or_Body;
30868 function Get_Argument
30870 Context_Id : Entity_Id := Empty) return Node_Id
30872 Args : constant List_Id := Pragma_Argument_Associations (Prag);
30875 -- Use the expression of the original aspect when analyzing the template
30876 -- of a generic unit. In both cases the aspect's tree must be decorated
30877 -- to allow for ASIS queries or to save the global references in the
30878 -- generic context.
30880 if From_Aspect_Specification (Prag)
30881 and then (Present (Context_Id) and then Is_Generic_Unit (Context_Id))
30883 return Corresponding_Aspect (Prag);
30885 -- Otherwise use the expression of the pragma
30887 elsif Present (Args) then
30888 return First (Args);
30895 -------------------------
30896 -- Get_Base_Subprogram --
30897 -------------------------
30899 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
30901 -- Follow subprogram renaming chain
30903 if Is_Subprogram (Def_Id)
30904 and then Nkind (Parent (Declaration_Node (Def_Id))) =
30905 N_Subprogram_Renaming_Declaration
30906 and then Present (Alias (Def_Id))
30908 return Alias (Def_Id);
30912 end Get_Base_Subprogram;
30914 -----------------------
30915 -- Get_SPARK_Mode_Type --
30916 -----------------------
30918 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
30920 if N = Name_On then
30922 elsif N = Name_Off then
30925 -- Any other argument is illegal. Assume that no SPARK mode applies to
30926 -- avoid potential cascaded errors.
30931 end Get_SPARK_Mode_Type;
30933 ------------------------------------
30934 -- Get_SPARK_Mode_From_Annotation --
30935 ------------------------------------
30937 function Get_SPARK_Mode_From_Annotation
30938 (N : Node_Id) return SPARK_Mode_Type
30943 if Nkind (N) = N_Aspect_Specification then
30944 Mode := Expression (N);
30946 else pragma Assert (Nkind (N) = N_Pragma);
30947 Mode := First (Pragma_Argument_Associations (N));
30949 if Present (Mode) then
30950 Mode := Get_Pragma_Arg (Mode);
30954 -- Aspect or pragma SPARK_Mode specifies an explicit mode
30956 if Present (Mode) then
30957 if Nkind (Mode) = N_Identifier then
30958 return Get_SPARK_Mode_Type (Chars (Mode));
30960 -- In case of a malformed aspect or pragma, return the default None
30966 -- Otherwise the lack of an expression defaults SPARK_Mode to On
30971 end Get_SPARK_Mode_From_Annotation;
30973 ---------------------------
30974 -- Has_Extra_Parentheses --
30975 ---------------------------
30977 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
30981 -- The aggregate should not have an expression list because a clause
30982 -- is always interpreted as a component association. The only way an
30983 -- expression list can sneak in is by adding extra parentheses around
30984 -- the individual clauses:
30986 -- Depends (Output => Input) -- proper form
30987 -- Depends ((Output => Input)) -- extra parentheses
30989 -- Since the extra parentheses are not allowed by the syntax of the
30990 -- pragma, flag them now to avoid emitting misleading errors down the
30993 if Nkind (Clause) = N_Aggregate
30994 and then Present (Expressions (Clause))
30996 Expr := First (Expressions (Clause));
30997 while Present (Expr) loop
30999 -- A dependency clause surrounded by extra parentheses appears
31000 -- as an aggregate of component associations with an optional
31001 -- Paren_Count set.
31003 if Nkind (Expr) = N_Aggregate
31004 and then Present (Component_Associations (Expr))
31007 ("dependency clause contains extra parentheses", Expr);
31009 -- Otherwise the expression is a malformed construct
31012 SPARK_Msg_N ("malformed dependency clause", Expr);
31022 end Has_Extra_Parentheses;
31028 procedure Initialize is
31031 Compile_Time_Warnings_Errors.Init;
31040 Dummy := Dummy + 1;
31043 -----------------------------
31044 -- Is_Config_Static_String --
31045 -----------------------------
31047 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
31049 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
31050 -- This is an internal recursive function that is just like the outer
31051 -- function except that it adds the string to the name buffer rather
31052 -- than placing the string in the name buffer.
31054 ------------------------------
31055 -- Add_Config_Static_String --
31056 ------------------------------
31058 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
31065 if Nkind (N) = N_Op_Concat then
31066 if Add_Config_Static_String (Left_Opnd (N)) then
31067 N := Right_Opnd (N);
31073 if Nkind (N) /= N_String_Literal then
31074 Error_Msg_N ("string literal expected for pragma argument", N);
31078 for J in 1 .. String_Length (Strval (N)) loop
31079 C := Get_String_Char (Strval (N), J);
31081 if not In_Character_Range (C) then
31083 ("string literal contains invalid wide character",
31084 Sloc (N) + 1 + Source_Ptr (J));
31088 Add_Char_To_Name_Buffer (Get_Character (C));
31093 end Add_Config_Static_String;
31095 -- Start of processing for Is_Config_Static_String
31100 return Add_Config_Static_String (Arg);
31101 end Is_Config_Static_String;
31103 -------------------------------
31104 -- Is_Elaboration_SPARK_Mode --
31105 -------------------------------
31107 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
31110 (Nkind (N) = N_Pragma
31111 and then Pragma_Name (N) = Name_SPARK_Mode
31112 and then Is_List_Member (N));
31114 -- Pragma SPARK_Mode affects the elaboration of a package body when it
31115 -- appears in the statement part of the body.
31118 Present (Parent (N))
31119 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
31120 and then List_Containing (N) = Statements (Parent (N))
31121 and then Present (Parent (Parent (N)))
31122 and then Nkind (Parent (Parent (N))) = N_Package_Body;
31123 end Is_Elaboration_SPARK_Mode;
31125 -----------------------
31126 -- Is_Enabled_Pragma --
31127 -----------------------
31129 function Is_Enabled_Pragma (Prag : Node_Id) return Boolean is
31133 if Present (Prag) then
31134 Arg := First (Pragma_Argument_Associations (Prag));
31136 if Present (Arg) then
31137 return Is_True (Expr_Value (Get_Pragma_Arg (Arg)));
31139 -- The lack of a Boolean argument automatically enables the pragma
31145 -- The pragma is missing, therefore it is not enabled
31150 end Is_Enabled_Pragma;
31152 -----------------------------------------
31153 -- Is_Non_Significant_Pragma_Reference --
31154 -----------------------------------------
31156 -- This function makes use of the following static table which indicates
31157 -- whether appearance of some name in a given pragma is to be considered
31158 -- as a reference for the purposes of warnings about unreferenced objects.
31160 -- -1 indicates that appearence in any argument is significant
31161 -- 0 indicates that appearance in any argument is not significant
31162 -- +n indicates that appearance as argument n is significant, but all
31163 -- other arguments are not significant
31164 -- 9n arguments from n on are significant, before n insignificant
31166 Sig_Flags : constant array (Pragma_Id) of Int :=
31167 (Pragma_Abort_Defer => -1,
31168 Pragma_Abstract_State => -1,
31169 Pragma_Acc_Data => 0,
31170 Pragma_Acc_Kernels => 0,
31171 Pragma_Acc_Loop => 0,
31172 Pragma_Acc_Parallel => 0,
31173 Pragma_Ada_83 => -1,
31174 Pragma_Ada_95 => -1,
31175 Pragma_Ada_05 => -1,
31176 Pragma_Ada_2005 => -1,
31177 Pragma_Ada_12 => -1,
31178 Pragma_Ada_2012 => -1,
31179 Pragma_Ada_2020 => -1,
31180 Pragma_Aggregate_Individually_Assign => 0,
31181 Pragma_All_Calls_Remote => -1,
31182 Pragma_Allow_Integer_Address => -1,
31183 Pragma_Annotate => 93,
31184 Pragma_Assert => -1,
31185 Pragma_Assert_And_Cut => -1,
31186 Pragma_Assertion_Policy => 0,
31187 Pragma_Assume => -1,
31188 Pragma_Assume_No_Invalid_Values => 0,
31189 Pragma_Async_Readers => 0,
31190 Pragma_Async_Writers => 0,
31191 Pragma_Asynchronous => 0,
31192 Pragma_Atomic => 0,
31193 Pragma_Atomic_Components => 0,
31194 Pragma_Attach_Handler => -1,
31195 Pragma_Attribute_Definition => 92,
31196 Pragma_Check => -1,
31197 Pragma_Check_Float_Overflow => 0,
31198 Pragma_Check_Name => 0,
31199 Pragma_Check_Policy => 0,
31200 Pragma_CPP_Class => 0,
31201 Pragma_CPP_Constructor => 0,
31202 Pragma_CPP_Virtual => 0,
31203 Pragma_CPP_Vtable => 0,
31205 Pragma_C_Pass_By_Copy => 0,
31206 Pragma_Comment => -1,
31207 Pragma_Common_Object => 0,
31208 Pragma_Compile_Time_Error => -1,
31209 Pragma_Compile_Time_Warning => -1,
31210 Pragma_Compiler_Unit => -1,
31211 Pragma_Compiler_Unit_Warning => -1,
31212 Pragma_Complete_Representation => 0,
31213 Pragma_Complex_Representation => 0,
31214 Pragma_Component_Alignment => 0,
31215 Pragma_Constant_After_Elaboration => 0,
31216 Pragma_Contract_Cases => -1,
31217 Pragma_Controlled => 0,
31218 Pragma_Convention => 0,
31219 Pragma_Convention_Identifier => 0,
31220 Pragma_Deadline_Floor => -1,
31221 Pragma_Debug => -1,
31222 Pragma_Debug_Policy => 0,
31223 Pragma_Detect_Blocking => 0,
31224 Pragma_Default_Initial_Condition => -1,
31225 Pragma_Default_Scalar_Storage_Order => 0,
31226 Pragma_Default_Storage_Pool => 0,
31227 Pragma_Depends => -1,
31228 Pragma_Disable_Atomic_Synchronization => 0,
31229 Pragma_Discard_Names => 0,
31230 Pragma_Dispatching_Domain => -1,
31231 Pragma_Effective_Reads => 0,
31232 Pragma_Effective_Writes => 0,
31233 Pragma_Elaborate => 0,
31234 Pragma_Elaborate_All => 0,
31235 Pragma_Elaborate_Body => 0,
31236 Pragma_Elaboration_Checks => 0,
31237 Pragma_Eliminate => 0,
31238 Pragma_Enable_Atomic_Synchronization => 0,
31239 Pragma_Export => -1,
31240 Pragma_Export_Function => -1,
31241 Pragma_Export_Object => -1,
31242 Pragma_Export_Procedure => -1,
31243 Pragma_Export_Value => -1,
31244 Pragma_Export_Valued_Procedure => -1,
31245 Pragma_Extend_System => -1,
31246 Pragma_Extensions_Allowed => 0,
31247 Pragma_Extensions_Visible => 0,
31248 Pragma_External => -1,
31249 Pragma_Favor_Top_Level => 0,
31250 Pragma_External_Name_Casing => 0,
31251 Pragma_Fast_Math => 0,
31252 Pragma_Finalize_Storage_Only => 0,
31254 Pragma_Global => -1,
31255 Pragma_Ident => -1,
31256 Pragma_Ignore_Pragma => 0,
31257 Pragma_Implementation_Defined => -1,
31258 Pragma_Implemented => -1,
31259 Pragma_Implicit_Packing => 0,
31260 Pragma_Import => 93,
31261 Pragma_Import_Function => 0,
31262 Pragma_Import_Object => 0,
31263 Pragma_Import_Procedure => 0,
31264 Pragma_Import_Valued_Procedure => 0,
31265 Pragma_Independent => 0,
31266 Pragma_Independent_Components => 0,
31267 Pragma_Initial_Condition => -1,
31268 Pragma_Initialize_Scalars => 0,
31269 Pragma_Initializes => -1,
31270 Pragma_Inline => 0,
31271 Pragma_Inline_Always => 0,
31272 Pragma_Inline_Generic => 0,
31273 Pragma_Inspection_Point => -1,
31274 Pragma_Interface => 92,
31275 Pragma_Interface_Name => 0,
31276 Pragma_Interrupt_Handler => -1,
31277 Pragma_Interrupt_Priority => -1,
31278 Pragma_Interrupt_State => -1,
31279 Pragma_Invariant => -1,
31280 Pragma_Keep_Names => 0,
31281 Pragma_License => 0,
31282 Pragma_Link_With => -1,
31283 Pragma_Linker_Alias => -1,
31284 Pragma_Linker_Constructor => -1,
31285 Pragma_Linker_Destructor => -1,
31286 Pragma_Linker_Options => -1,
31287 Pragma_Linker_Section => -1,
31289 Pragma_Lock_Free => 0,
31290 Pragma_Locking_Policy => 0,
31291 Pragma_Loop_Invariant => -1,
31292 Pragma_Loop_Optimize => 0,
31293 Pragma_Loop_Variant => -1,
31294 Pragma_Machine_Attribute => -1,
31296 Pragma_Main_Storage => -1,
31297 Pragma_Max_Entry_Queue_Depth => 0,
31298 Pragma_Max_Entry_Queue_Length => 0,
31299 Pragma_Max_Queue_Length => 0,
31300 Pragma_Memory_Size => 0,
31301 Pragma_No_Body => 0,
31302 Pragma_No_Caching => 0,
31303 Pragma_No_Component_Reordering => -1,
31304 Pragma_No_Elaboration_Code_All => 0,
31305 Pragma_No_Heap_Finalization => 0,
31306 Pragma_No_Inline => 0,
31307 Pragma_No_Return => 0,
31308 Pragma_No_Run_Time => -1,
31309 Pragma_No_Strict_Aliasing => -1,
31310 Pragma_No_Tagged_Streams => 0,
31311 Pragma_Normalize_Scalars => 0,
31312 Pragma_Obsolescent => 0,
31313 Pragma_Optimize => 0,
31314 Pragma_Optimize_Alignment => 0,
31315 Pragma_Overflow_Mode => 0,
31316 Pragma_Overriding_Renamings => 0,
31317 Pragma_Ordered => 0,
31320 Pragma_Part_Of => 0,
31321 Pragma_Partition_Elaboration_Policy => 0,
31322 Pragma_Passive => 0,
31323 Pragma_Persistent_BSS => 0,
31324 Pragma_Polling => 0,
31325 Pragma_Prefix_Exception_Messages => 0,
31327 Pragma_Postcondition => -1,
31328 Pragma_Post_Class => -1,
31330 Pragma_Precondition => -1,
31331 Pragma_Predicate => -1,
31332 Pragma_Predicate_Failure => -1,
31333 Pragma_Preelaborable_Initialization => -1,
31334 Pragma_Preelaborate => 0,
31335 Pragma_Pre_Class => -1,
31336 Pragma_Priority => -1,
31337 Pragma_Priority_Specific_Dispatching => 0,
31338 Pragma_Profile => 0,
31339 Pragma_Profile_Warnings => 0,
31340 Pragma_Propagate_Exceptions => 0,
31341 Pragma_Provide_Shift_Operators => 0,
31342 Pragma_Psect_Object => 0,
31344 Pragma_Pure_Function => 0,
31345 Pragma_Queuing_Policy => 0,
31346 Pragma_Rational => 0,
31347 Pragma_Ravenscar => 0,
31348 Pragma_Refined_Depends => -1,
31349 Pragma_Refined_Global => -1,
31350 Pragma_Refined_Post => -1,
31351 Pragma_Refined_State => -1,
31352 Pragma_Relative_Deadline => 0,
31353 Pragma_Rename_Pragma => 0,
31354 Pragma_Remote_Access_Type => -1,
31355 Pragma_Remote_Call_Interface => -1,
31356 Pragma_Remote_Types => -1,
31357 Pragma_Restricted_Run_Time => 0,
31358 Pragma_Restriction_Warnings => 0,
31359 Pragma_Restrictions => 0,
31360 Pragma_Reviewable => -1,
31361 Pragma_Secondary_Stack_Size => -1,
31362 Pragma_Short_Circuit_And_Or => 0,
31363 Pragma_Share_Generic => 0,
31364 Pragma_Shared => 0,
31365 Pragma_Shared_Passive => 0,
31366 Pragma_Short_Descriptors => 0,
31367 Pragma_Simple_Storage_Pool_Type => 0,
31368 Pragma_Source_File_Name => 0,
31369 Pragma_Source_File_Name_Project => 0,
31370 Pragma_Source_Reference => 0,
31371 Pragma_SPARK_Mode => 0,
31372 Pragma_Storage_Size => -1,
31373 Pragma_Storage_Unit => 0,
31374 Pragma_Static_Elaboration_Desired => 0,
31375 Pragma_Stream_Convert => 0,
31376 Pragma_Style_Checks => 0,
31377 Pragma_Subtitle => 0,
31378 Pragma_Suppress => 0,
31379 Pragma_Suppress_Exception_Locations => 0,
31380 Pragma_Suppress_All => 0,
31381 Pragma_Suppress_Debug_Info => 0,
31382 Pragma_Suppress_Initialization => 0,
31383 Pragma_System_Name => 0,
31384 Pragma_Task_Dispatching_Policy => 0,
31385 Pragma_Task_Info => -1,
31386 Pragma_Task_Name => -1,
31387 Pragma_Task_Storage => -1,
31388 Pragma_Test_Case => -1,
31389 Pragma_Thread_Local_Storage => -1,
31390 Pragma_Time_Slice => -1,
31392 Pragma_Type_Invariant => -1,
31393 Pragma_Type_Invariant_Class => -1,
31394 Pragma_Unchecked_Union => 0,
31395 Pragma_Unevaluated_Use_Of_Old => 0,
31396 Pragma_Unimplemented_Unit => 0,
31397 Pragma_Universal_Aliasing => 0,
31398 Pragma_Universal_Data => 0,
31399 Pragma_Unmodified => 0,
31400 Pragma_Unreferenced => 0,
31401 Pragma_Unreferenced_Objects => 0,
31402 Pragma_Unreserve_All_Interrupts => 0,
31403 Pragma_Unsuppress => 0,
31404 Pragma_Unused => 0,
31405 Pragma_Use_VADS_Size => 0,
31406 Pragma_Validity_Checks => 0,
31407 Pragma_Volatile => 0,
31408 Pragma_Volatile_Components => 0,
31409 Pragma_Volatile_Full_Access => 0,
31410 Pragma_Volatile_Function => 0,
31411 Pragma_Warning_As_Error => 0,
31412 Pragma_Warnings => 0,
31413 Pragma_Weak_External => 0,
31414 Pragma_Wide_Character_Encoding => 0,
31415 Unknown_Pragma => 0);
31417 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
31423 function Arg_No return Nat;
31424 -- Returns an integer showing what argument we are in. A value of
31425 -- zero means we are not in any of the arguments.
31431 function Arg_No return Nat is
31436 A := First (Pragma_Argument_Associations (Parent (P)));
31450 -- Start of processing for Non_Significant_Pragma_Reference
31455 if Nkind (P) /= N_Pragma_Argument_Association then
31459 Id := Get_Pragma_Id (Parent (P));
31460 C := Sig_Flags (Id);
31475 return AN < (C - 90);
31481 end Is_Non_Significant_Pragma_Reference;
31483 ------------------------------
31484 -- Is_Pragma_String_Literal --
31485 ------------------------------
31487 -- This function returns true if the corresponding pragma argument is a
31488 -- static string expression. These are the only cases in which string
31489 -- literals can appear as pragma arguments. We also allow a string literal
31490 -- as the first argument to pragma Assert (although it will of course
31491 -- always generate a type error).
31493 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
31494 Pragn : constant Node_Id := Parent (Par);
31495 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
31496 Pname : constant Name_Id := Pragma_Name (Pragn);
31502 N := First (Assoc);
31509 if Pname = Name_Assert then
31512 elsif Pname = Name_Export then
31515 elsif Pname = Name_Ident then
31518 elsif Pname = Name_Import then
31521 elsif Pname = Name_Interface_Name then
31524 elsif Pname = Name_Linker_Alias then
31527 elsif Pname = Name_Linker_Section then
31530 elsif Pname = Name_Machine_Attribute then
31533 elsif Pname = Name_Source_File_Name then
31536 elsif Pname = Name_Source_Reference then
31539 elsif Pname = Name_Title then
31542 elsif Pname = Name_Subtitle then
31548 end Is_Pragma_String_Literal;
31550 ---------------------------
31551 -- Is_Private_SPARK_Mode --
31552 ---------------------------
31554 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
31557 (Nkind (N) = N_Pragma
31558 and then Pragma_Name (N) = Name_SPARK_Mode
31559 and then Is_List_Member (N));
31561 -- For pragma SPARK_Mode to be private, it has to appear in the private
31562 -- declarations of a package.
31565 Present (Parent (N))
31566 and then Nkind (Parent (N)) = N_Package_Specification
31567 and then List_Containing (N) = Private_Declarations (Parent (N));
31568 end Is_Private_SPARK_Mode;
31570 -------------------------------------
31571 -- Is_Unconstrained_Or_Tagged_Item --
31572 -------------------------------------
31574 function Is_Unconstrained_Or_Tagged_Item
31575 (Item : Entity_Id) return Boolean
31577 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
31578 -- Determine whether record type Typ has at least one unconstrained
31581 ---------------------------------
31582 -- Has_Unconstrained_Component --
31583 ---------------------------------
31585 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
31589 Comp := First_Component (Typ);
31590 while Present (Comp) loop
31591 if Is_Unconstrained_Or_Tagged_Item (Comp) then
31595 Next_Component (Comp);
31599 end Has_Unconstrained_Component;
31603 Typ : constant Entity_Id := Etype (Item);
31605 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
31608 if Is_Tagged_Type (Typ) then
31611 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
31614 elsif Is_Record_Type (Typ) then
31615 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
31618 return Has_Unconstrained_Component (Typ);
31621 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
31627 end Is_Unconstrained_Or_Tagged_Item;
31629 -----------------------------
31630 -- Is_Valid_Assertion_Kind --
31631 -----------------------------
31633 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
31640 | Name_Assertion_Policy
31641 | Name_Static_Predicate
31642 | Name_Dynamic_Predicate
31647 | Name_Type_Invariant
31648 | Name_uType_Invariant
31652 | Name_Assert_And_Cut
31654 | Name_Contract_Cases
31656 | Name_Default_Initial_Condition
31658 | Name_Initial_Condition
31661 | Name_Loop_Invariant
31662 | Name_Loop_Variant
31663 | Name_Postcondition
31664 | Name_Precondition
31666 | Name_Refined_Post
31667 | Name_Statement_Assertions
31674 end Is_Valid_Assertion_Kind;
31676 --------------------------------------
31677 -- Process_Compilation_Unit_Pragmas --
31678 --------------------------------------
31680 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
31682 -- A special check for pragma Suppress_All, a very strange DEC pragma,
31683 -- strange because it comes at the end of the unit. Rational has the
31684 -- same name for a pragma, but treats it as a program unit pragma, In
31685 -- GNAT we just decide to allow it anywhere at all. If it appeared then
31686 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
31687 -- node, and we insert a pragma Suppress (All_Checks) at the start of
31688 -- the context clause to ensure the correct processing.
31690 if Has_Pragma_Suppress_All (N) then
31691 Prepend_To (Context_Items (N),
31692 Make_Pragma (Sloc (N),
31693 Chars => Name_Suppress,
31694 Pragma_Argument_Associations => New_List (
31695 Make_Pragma_Argument_Association (Sloc (N),
31696 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
31699 -- Nothing else to do at the current time
31701 end Process_Compilation_Unit_Pragmas;
31703 --------------------------------------------
31704 -- Validate_Compile_Time_Warning_Or_Error --
31705 --------------------------------------------
31707 procedure Validate_Compile_Time_Warning_Or_Error
31711 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
31712 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
31713 Arg2 : constant Node_Id := Next (Arg1);
31715 Pname : constant Name_Id := Pragma_Name_Unmapped (N);
31716 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
31719 Analyze_And_Resolve (Arg1x, Standard_Boolean);
31721 if Compile_Time_Known_Value (Arg1x) then
31722 if Is_True (Expr_Value (Arg1x)) then
31724 -- We have already verified that the second argument is a static
31725 -- string expression. Its string value must be retrieved
31726 -- explicitly if it is a declared constant, otherwise it has
31727 -- been constant-folded previously.
31730 Cent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
31731 Str : constant String_Id :=
31732 Strval (Expr_Value_S (Get_Pragma_Arg (Arg2)));
31733 Str_Len : constant Nat := String_Length (Str);
31735 Force : constant Boolean :=
31736 Prag_Id = Pragma_Compile_Time_Warning
31737 and then Is_Spec_Name (Unit_Name (Current_Sem_Unit))
31738 and then (Ekind (Cent) /= E_Package
31739 or else not In_Private_Part (Cent));
31740 -- Set True if this is the warning case, and we are in the
31741 -- visible part of a package spec, or in a subprogram spec,
31742 -- in which case we want to force the client to see the
31743 -- warning, even though it is not in the main unit.
31751 -- Loop through segments of message separated by line feeds.
31752 -- We output these segments as separate messages with
31753 -- continuation marks for all but the first.
31758 Error_Msg_Strlen := 0;
31760 -- Loop to copy characters from argument to error message
31764 exit when Ptr > Str_Len;
31765 CC := Get_String_Char (Str, Ptr);
31768 -- Ignore wide chars ??? else store character
31770 if In_Character_Range (CC) then
31771 C := Get_Character (CC);
31772 exit when C = ASCII.LF;
31773 Error_Msg_Strlen := Error_Msg_Strlen + 1;
31774 Error_Msg_String (Error_Msg_Strlen) := C;
31778 -- Here with one line ready to go
31780 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
31782 -- If this is a warning in a spec, then we want clients
31783 -- to see the warning, so mark the message with the
31784 -- special sequence !! to force the warning. In the case
31785 -- of a package spec, we do not force this if we are in
31786 -- the private part of the spec.
31789 if Cont = False then
31790 Error_Msg ("<<~!!", Eloc);
31793 Error_Msg ("\<<~!!", Eloc);
31796 -- Error, rather than warning, or in a body, so we do not
31797 -- need to force visibility for client (error will be
31798 -- output in any case, and this is the situation in which
31799 -- we do not want a client to get a warning, since the
31800 -- warning is in the body or the spec private part).
31803 if Cont = False then
31804 Error_Msg ("<<~", Eloc);
31807 Error_Msg ("\<<~", Eloc);
31811 exit when Ptr > Str_Len;
31816 -- Arg1x is not known at compile time, so possibly issue an error
31817 -- or warning. This can happen only if the pragma's processing
31818 -- was deferred until after the back end is run (see
31819 -- Process_Compile_Time_Warning_Or_Error). Note that the warning
31820 -- control switch applies to only the warning case.
31822 elsif Prag_Id = Pragma_Compile_Time_Error then
31823 Error_Msg_N ("condition is not known at compile time", Arg1x);
31825 elsif Warn_On_Unknown_Compile_Time_Warning then
31826 Error_Msg_N ("?condition is not known at compile time", Arg1x);
31828 end Validate_Compile_Time_Warning_Or_Error;
31830 ------------------------------------
31831 -- Record_Possible_Body_Reference --
31832 ------------------------------------
31834 procedure Record_Possible_Body_Reference
31835 (State_Id : Entity_Id;
31839 Spec_Id : Entity_Id;
31842 -- Ensure that we are dealing with a reference to a state
31844 pragma Assert (Ekind (State_Id) = E_Abstract_State);
31846 -- Climb the tree starting from the reference looking for a package body
31847 -- whose spec declares the referenced state. This criteria automatically
31848 -- excludes references in package specs which are legal. Note that it is
31849 -- not wise to emit an error now as the package body may lack pragma
31850 -- Refined_State or the referenced state may not be mentioned in the
31851 -- refinement. This approach avoids the generation of misleading errors.
31854 while Present (Context) loop
31855 if Nkind (Context) = N_Package_Body then
31856 Spec_Id := Corresponding_Spec (Context);
31858 if Present (Abstract_States (Spec_Id))
31859 and then Contains (Abstract_States (Spec_Id), State_Id)
31861 if No (Body_References (State_Id)) then
31862 Set_Body_References (State_Id, New_Elmt_List);
31865 Append_Elmt (Ref, To => Body_References (State_Id));
31870 Context := Parent (Context);
31872 end Record_Possible_Body_Reference;
31874 ------------------------------------------
31875 -- Relocate_Pragmas_To_Anonymous_Object --
31876 ------------------------------------------
31878 procedure Relocate_Pragmas_To_Anonymous_Object
31879 (Typ_Decl : Node_Id;
31880 Obj_Decl : Node_Id)
31884 Next_Decl : Node_Id;
31887 if Nkind (Typ_Decl) = N_Protected_Type_Declaration then
31888 Def := Protected_Definition (Typ_Decl);
31890 pragma Assert (Nkind (Typ_Decl) = N_Task_Type_Declaration);
31891 Def := Task_Definition (Typ_Decl);
31894 -- The concurrent definition has a visible declaration list. Inspect it
31895 -- and relocate all canidate pragmas.
31897 if Present (Def) and then Present (Visible_Declarations (Def)) then
31898 Decl := First (Visible_Declarations (Def));
31899 while Present (Decl) loop
31901 -- Preserve the following declaration for iteration purposes due
31902 -- to possible relocation of a pragma.
31904 Next_Decl := Next (Decl);
31906 if Nkind (Decl) = N_Pragma
31907 and then Pragma_On_Anonymous_Object_OK (Get_Pragma_Id (Decl))
31910 Insert_After (Obj_Decl, Decl);
31912 -- Skip internally generated code
31914 elsif not Comes_From_Source (Decl) then
31917 -- No candidate pragmas are available for relocation
31926 end Relocate_Pragmas_To_Anonymous_Object;
31928 ------------------------------
31929 -- Relocate_Pragmas_To_Body --
31930 ------------------------------
31932 procedure Relocate_Pragmas_To_Body
31933 (Subp_Body : Node_Id;
31934 Target_Body : Node_Id := Empty)
31936 procedure Relocate_Pragma (Prag : Node_Id);
31937 -- Remove a single pragma from its current list and add it to the
31938 -- declarations of the proper body (either Subp_Body or Target_Body).
31940 ---------------------
31941 -- Relocate_Pragma --
31942 ---------------------
31944 procedure Relocate_Pragma (Prag : Node_Id) is
31949 -- When subprogram stubs or expression functions are involves, the
31950 -- destination declaration list belongs to the proper body.
31952 if Present (Target_Body) then
31953 Target := Target_Body;
31955 Target := Subp_Body;
31958 Decls := Declarations (Target);
31962 Set_Declarations (Target, Decls);
31965 -- Unhook the pragma from its current list
31968 Prepend (Prag, Decls);
31969 end Relocate_Pragma;
31973 Body_Id : constant Entity_Id :=
31974 Defining_Unit_Name (Specification (Subp_Body));
31975 Next_Stmt : Node_Id;
31978 -- Start of processing for Relocate_Pragmas_To_Body
31981 -- Do not process a body that comes from a separate unit as no construct
31982 -- can possibly follow it.
31984 if not Is_List_Member (Subp_Body) then
31987 -- Do not relocate pragmas that follow a stub if the stub does not have
31990 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
31991 and then No (Target_Body)
31995 -- Do not process internally generated routine _Postconditions
31997 elsif Ekind (Body_Id) = E_Procedure
31998 and then Chars (Body_Id) = Name_uPostconditions
32003 -- Look at what is following the body. We are interested in certain kind
32004 -- of pragmas (either from source or byproducts of expansion) that can
32005 -- apply to a body [stub].
32007 Stmt := Next (Subp_Body);
32008 while Present (Stmt) loop
32010 -- Preserve the following statement for iteration purposes due to a
32011 -- possible relocation of a pragma.
32013 Next_Stmt := Next (Stmt);
32015 -- Move a candidate pragma following the body to the declarations of
32018 if Nkind (Stmt) = N_Pragma
32019 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
32022 -- If a source pragma Warnings follows the body, it applies to
32023 -- following statements and does not belong in the body.
32025 if Get_Pragma_Id (Stmt) = Pragma_Warnings
32026 and then Comes_From_Source (Stmt)
32030 Relocate_Pragma (Stmt);
32033 -- Skip internally generated code
32035 elsif not Comes_From_Source (Stmt) then
32038 -- No candidate pragmas are available for relocation
32046 end Relocate_Pragmas_To_Body;
32048 -------------------
32049 -- Resolve_State --
32050 -------------------
32052 procedure Resolve_State (N : Node_Id) is
32057 if Is_Entity_Name (N) and then Present (Entity (N)) then
32058 Func := Entity (N);
32060 -- Handle overloading of state names by functions. Traverse the
32061 -- homonym chain looking for an abstract state.
32063 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
32064 pragma Assert (Is_Overloaded (N));
32066 State := Homonym (Func);
32067 while Present (State) loop
32068 if Ekind (State) = E_Abstract_State then
32070 -- Resolve the overloading by setting the proper entity of
32071 -- the reference to that of the state.
32073 Set_Etype (N, Standard_Void_Type);
32074 Set_Entity (N, State);
32075 Set_Is_Overloaded (N, False);
32077 Generate_Reference (State, N);
32081 State := Homonym (State);
32084 -- A function can never act as a state. If the homonym chain does
32085 -- not contain a corresponding state, then something went wrong in
32086 -- the overloading mechanism.
32088 raise Program_Error;
32093 ----------------------------
32094 -- Rewrite_Assertion_Kind --
32095 ----------------------------
32097 procedure Rewrite_Assertion_Kind
32099 From_Policy : Boolean := False)
32105 if Nkind (N) = N_Attribute_Reference
32106 and then Attribute_Name (N) = Name_Class
32107 and then Nkind (Prefix (N)) = N_Identifier
32109 case Chars (Prefix (N)) is
32116 when Name_Type_Invariant =>
32117 Nam := Name_uType_Invariant;
32119 when Name_Invariant =>
32120 Nam := Name_uInvariant;
32126 -- Recommend standard use of aspect names Pre/Post
32128 elsif Nkind (N) = N_Identifier
32129 and then From_Policy
32130 and then Serious_Errors_Detected = 0
32132 if Chars (N) = Name_Precondition
32133 or else Chars (N) = Name_Postcondition
32135 Error_Msg_N ("Check_Policy is a non-standard pragma??", N);
32137 ("\use Assertion_Policy and aspect names Pre/Post for "
32138 & "Ada2012 conformance?", N);
32144 if Nam /= No_Name then
32145 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
32147 end Rewrite_Assertion_Kind;
32155 Dummy := Dummy + 1;
32158 --------------------------------
32159 -- Set_Encoded_Interface_Name --
32160 --------------------------------
32162 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
32163 Str : constant String_Id := Strval (S);
32164 Len : constant Nat := String_Length (Str);
32169 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
32172 -- Stores encoded value of character code CC. The encoding we use an
32173 -- underscore followed by four lower case hex digits.
32179 procedure Encode is
32181 Store_String_Char (Get_Char_Code ('_'));
32183 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
32185 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
32187 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
32189 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
32192 -- Start of processing for Set_Encoded_Interface_Name
32195 -- If first character is asterisk, this is a link name, and we leave it
32196 -- completely unmodified. We also ignore null strings (the latter case
32197 -- happens only in error cases).
32200 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
32202 Set_Interface_Name (E, S);
32207 CC := Get_String_Char (Str, J);
32209 exit when not In_Character_Range (CC);
32211 C := Get_Character (CC);
32213 exit when C /= '_' and then C /= '$'
32214 and then C not in '0' .. '9'
32215 and then C not in 'a' .. 'z'
32216 and then C not in 'A' .. 'Z';
32219 Set_Interface_Name (E, S);
32227 -- Here we need to encode. The encoding we use as follows:
32228 -- three underscores + four hex digits (lower case)
32232 for J in 1 .. String_Length (Str) loop
32233 CC := Get_String_Char (Str, J);
32235 if not In_Character_Range (CC) then
32238 C := Get_Character (CC);
32240 if C = '_' or else C = '$'
32241 or else C in '0' .. '9'
32242 or else C in 'a' .. 'z'
32243 or else C in 'A' .. 'Z'
32245 Store_String_Char (CC);
32252 Set_Interface_Name (E,
32253 Make_String_Literal (Sloc (S),
32254 Strval => End_String));
32256 end Set_Encoded_Interface_Name;
32258 ------------------------
32259 -- Set_Elab_Unit_Name --
32260 ------------------------
32262 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is
32267 if Nkind (N) = N_Identifier
32268 and then Nkind (With_Item) = N_Identifier
32270 Set_Entity (N, Entity (With_Item));
32272 elsif Nkind (N) = N_Selected_Component then
32273 Change_Selected_Component_To_Expanded_Name (N);
32274 Set_Entity (N, Entity (With_Item));
32275 Set_Entity (Selector_Name (N), Entity (N));
32277 Pref := Prefix (N);
32278 Scop := Scope (Entity (N));
32279 while Nkind (Pref) = N_Selected_Component loop
32280 Change_Selected_Component_To_Expanded_Name (Pref);
32281 Set_Entity (Selector_Name (Pref), Scop);
32282 Set_Entity (Pref, Scop);
32283 Pref := Prefix (Pref);
32284 Scop := Scope (Scop);
32287 Set_Entity (Pref, Scop);
32290 Generate_Reference (Entity (With_Item), N, Set_Ref => False);
32291 end Set_Elab_Unit_Name;
32293 -----------------------
32294 -- Set_Overflow_Mode --
32295 -----------------------
32297 procedure Set_Overflow_Mode (N : Node_Id) is
32299 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type;
32300 -- Function to process one pragma argument, Arg
32302 -----------------------
32303 -- Get_Overflow_Mode --
32304 -----------------------
32306 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type is
32307 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
32310 if Chars (Argx) = Name_Strict then
32313 elsif Chars (Argx) = Name_Minimized then
32316 elsif Chars (Argx) = Name_Eliminated then
32320 raise Program_Error;
32322 end Get_Overflow_Mode;
32326 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
32327 Arg2 : constant Node_Id := Next (Arg1);
32329 -- Start of processing for Set_Overflow_Mode
32332 -- Process first argument
32334 Scope_Suppress.Overflow_Mode_General :=
32335 Get_Overflow_Mode (Arg1);
32337 -- Case of only one argument
32340 Scope_Suppress.Overflow_Mode_Assertions :=
32341 Scope_Suppress.Overflow_Mode_General;
32343 -- Case of two arguments present
32346 Scope_Suppress.Overflow_Mode_Assertions :=
32347 Get_Overflow_Mode (Arg2);
32349 end Set_Overflow_Mode;
32351 -------------------
32352 -- Test_Case_Arg --
32353 -------------------
32355 function Test_Case_Arg
32358 From_Aspect : Boolean := False) return Node_Id
32360 Aspect : constant Node_Id := Corresponding_Aspect (Prag);
32365 pragma Assert (Nam_In (Arg_Nam, Name_Ensures,
32370 -- The caller requests the aspect argument
32372 if From_Aspect then
32373 if Present (Aspect)
32374 and then Nkind (Expression (Aspect)) = N_Aggregate
32376 Args := Expression (Aspect);
32378 -- "Name" and "Mode" may appear without an identifier as a
32379 -- positional association.
32381 if Present (Expressions (Args)) then
32382 Arg := First (Expressions (Args));
32384 if Present (Arg) and then Arg_Nam = Name_Name then
32392 if Present (Arg) and then Arg_Nam = Name_Mode then
32397 -- Some or all arguments may appear as component associatons
32399 if Present (Component_Associations (Args)) then
32400 Arg := First (Component_Associations (Args));
32401 while Present (Arg) loop
32402 if Chars (First (Choices (Arg))) = Arg_Nam then
32411 -- Otherwise retrieve the argument directly from the pragma
32414 Arg := First (Pragma_Argument_Associations (Prag));
32416 if Present (Arg) and then Arg_Nam = Name_Name then
32420 -- Skip argument "Name"
32424 if Present (Arg) and then Arg_Nam = Name_Mode then
32428 -- Skip argument "Mode"
32432 -- Arguments "Requires" and "Ensures" are optional and may not be
32435 while Present (Arg) loop
32436 if Chars (Arg) = Arg_Nam then
32447 --------------------------------------------
32448 -- Defer_Compile_Time_Warning_Error_To_BE --
32449 --------------------------------------------
32451 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id) is
32452 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
32454 Compile_Time_Warnings_Errors.Append
32455 (New_Val => CTWE_Entry'(Eloc => Sloc (Arg1),
32456 Scope => Current_Scope,
32459 -- If the Boolean expression contains T'Size, and we're not in the main
32460 -- unit being compiled, then we need to copy the pragma into the main
32461 -- unit, because otherwise T'Size might never be computed, leaving it
32464 if not In_Extended_Main_Code_Unit (N) then
32465 Insert_Library_Level_Action (New_Copy_Tree (N));
32467 end Defer_Compile_Time_Warning_Error_To_BE;
32469 ------------------------------------------
32470 -- Validate_Compile_Time_Warning_Errors --
32471 ------------------------------------------
32473 procedure Validate_Compile_Time_Warning_Errors is
32474 procedure Set_Scope (S : Entity_Id);
32475 -- Install all enclosing scopes of S along with S itself
32477 procedure Unset_Scope (S : Entity_Id);
32478 -- Uninstall all enclosing scopes of S along with S itself
32484 procedure Set_Scope (S : Entity_Id) is
32486 if S /= Standard_Standard then
32487 Set_Scope (Scope (S));
32497 procedure Unset_Scope (S : Entity_Id) is
32499 if S /= Standard_Standard then
32500 Unset_Scope (Scope (S));
32506 -- Start of processing for Validate_Compile_Time_Warning_Errors
32509 Expander_Mode_Save_And_Set (False);
32510 In_Compile_Time_Warning_Or_Error := True;
32512 for N in Compile_Time_Warnings_Errors.First ..
32513 Compile_Time_Warnings_Errors.Last
32516 T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N);
32519 Set_Scope (T.Scope);
32520 Reset_Analyzed_Flags (T.Prag);
32521 Validate_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc);
32522 Unset_Scope (T.Scope);
32526 In_Compile_Time_Warning_Or_Error := False;
32527 Expander_Mode_Restore;
32528 end Validate_Compile_Time_Warning_Errors;