[Ada] Implement initialization of CUDA runtime
[official-gcc.git] / gcc / ada / sem_prag.adb
blob33a3f7aecba612fbe41663e8f087e2018aeb27c8
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ P R A G --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2020, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
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 GNAT_CUDA; use GNAT_CUDA;
48 with Gnatvsn; use Gnatvsn;
49 with Lib; use Lib;
50 with Lib.Writ; use Lib.Writ;
51 with Lib.Xref; use Lib.Xref;
52 with Namet.Sp; use Namet.Sp;
53 with Nlists; use Nlists;
54 with Nmake; use Nmake;
55 with Output; use Output;
56 with Par_SCO; use Par_SCO;
57 with Restrict; use Restrict;
58 with Rident; use Rident;
59 with Rtsfind; use Rtsfind;
60 with Sem; use Sem;
61 with Sem_Aux; use Sem_Aux;
62 with Sem_Ch3; use Sem_Ch3;
63 with Sem_Ch6; use Sem_Ch6;
64 with Sem_Ch8; use Sem_Ch8;
65 with Sem_Ch12; use Sem_Ch12;
66 with Sem_Ch13; use Sem_Ch13;
67 with Sem_Disp; use Sem_Disp;
68 with Sem_Dist; use Sem_Dist;
69 with Sem_Elab; use Sem_Elab;
70 with Sem_Elim; use Sem_Elim;
71 with Sem_Eval; use Sem_Eval;
72 with Sem_Intr; use Sem_Intr;
73 with Sem_Mech; use Sem_Mech;
74 with Sem_Res; use Sem_Res;
75 with Sem_Type; use Sem_Type;
76 with Sem_Util; use Sem_Util;
77 with Sem_Warn; use Sem_Warn;
78 with Stand; use Stand;
79 with Sinfo; use Sinfo;
80 with Sinfo.CN; use Sinfo.CN;
81 with Sinput; use Sinput;
82 with Stringt; use Stringt;
83 with Stylesw; use Stylesw;
84 with Table;
85 with Targparm; use Targparm;
86 with Tbuild; use Tbuild;
87 with Ttypes;
88 with Uintp; use Uintp;
89 with Uname; use Uname;
90 with Urealp; use Urealp;
91 with Validsw; use Validsw;
92 with Warnsw; use Warnsw;
94 with System.Case_Util;
96 package body Sem_Prag is
98 ----------------------------------------------
99 -- Common Handling of Import-Export Pragmas --
100 ----------------------------------------------
102 -- In the following section, a number of Import_xxx and Export_xxx pragmas
103 -- are defined by GNAT. These are compatible with the DEC pragmas of the
104 -- same name, and all have the following common form and processing:
106 -- pragma Export_xxx
107 -- [Internal =>] LOCAL_NAME
108 -- [, [External =>] EXTERNAL_SYMBOL]
109 -- [, other optional parameters ]);
111 -- pragma Import_xxx
112 -- [Internal =>] LOCAL_NAME
113 -- [, [External =>] EXTERNAL_SYMBOL]
114 -- [, other optional parameters ]);
116 -- EXTERNAL_SYMBOL ::=
117 -- IDENTIFIER
118 -- | static_string_EXPRESSION
120 -- The internal LOCAL_NAME designates the entity that is imported or
121 -- exported, and must refer to an entity in the current declarative
122 -- part (as required by the rules for LOCAL_NAME).
124 -- The external linker name is designated by the External parameter if
125 -- given, or the Internal parameter if not (if there is no External
126 -- parameter, the External parameter is a copy of the Internal name).
128 -- If the External parameter is given as a string, then this string is
129 -- treated as an external name (exactly as though it had been given as an
130 -- External_Name parameter for a normal Import pragma).
132 -- If the External parameter is given as an identifier (or there is no
133 -- External parameter, so that the Internal identifier is used), then
134 -- the external name is the characters of the identifier, translated
135 -- to all lower case letters.
137 -- Note: the external name specified or implied by any of these special
138 -- Import_xxx or Export_xxx pragmas override an external or link name
139 -- specified in a previous Import or Export pragma.
141 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
142 -- named notation, following the standard rules for subprogram calls, i.e.
143 -- parameters can be given in any order if named notation is used, and
144 -- positional and named notation can be mixed, subject to the rule that all
145 -- positional parameters must appear first.
147 -- Note: All these pragmas are implemented exactly following the DEC design
148 -- and implementation and are intended to be fully compatible with the use
149 -- of these pragmas in the DEC Ada compiler.
151 --------------------------------------------
152 -- Checking for Duplicated External Names --
153 --------------------------------------------
155 -- It is suspicious if two separate Export pragmas use the same external
156 -- name. The following table is used to diagnose this situation so that
157 -- an appropriate warning can be issued.
159 -- The Node_Id stored is for the N_String_Literal node created to hold
160 -- the value of the external name. The Sloc of this node is used to
161 -- cross-reference the location of the duplication.
163 package Externals is new Table.Table (
164 Table_Component_Type => Node_Id,
165 Table_Index_Type => Int,
166 Table_Low_Bound => 0,
167 Table_Initial => 100,
168 Table_Increment => 100,
169 Table_Name => "Name_Externals");
171 -------------------------------------
172 -- Local Subprograms and Variables --
173 -------------------------------------
175 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
176 -- This routine is used for possible casing adjustment of an explicit
177 -- external name supplied as a string literal (the node N), according to
178 -- the casing requirement of Opt.External_Name_Casing. If this is set to
179 -- As_Is, then the string literal is returned unchanged, but if it is set
180 -- to Uppercase or Lowercase, then a new string literal with appropriate
181 -- casing is constructed.
183 procedure Analyze_Part_Of
184 (Indic : Node_Id;
185 Item_Id : Entity_Id;
186 Encap : Node_Id;
187 Encap_Id : out Entity_Id;
188 Legal : out Boolean);
189 -- Subsidiary to Analyze_Part_Of_In_Decl_Part, Analyze_Part_Of_Option and
190 -- Analyze_Pragma. Perform full analysis of indicator Part_Of. Indic is the
191 -- Part_Of indicator. Item_Id is the entity of an abstract state, object or
192 -- package instantiation. Encap denotes the encapsulating state or single
193 -- concurrent type. Encap_Id is the entity of Encap. Flag Legal is set when
194 -- the indicator is legal.
196 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
197 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
198 -- Query whether a particular item appears in a mixed list of nodes and
199 -- entities. It is assumed that all nodes in the list have entities.
201 procedure Check_Postcondition_Use_In_Inlined_Subprogram
202 (Prag : Node_Id;
203 Spec_Id : Entity_Id);
204 -- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition,
205 -- Precondition, Refined_Post, and Test_Case. Emit a warning when pragma
206 -- Prag is associated with subprogram Spec_Id subject to Inline_Always,
207 -- and assertions are enabled.
209 procedure Check_State_And_Constituent_Use
210 (States : Elist_Id;
211 Constits : Elist_Id;
212 Context : Node_Id);
213 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
214 -- Global and Initializes. Determine whether a state from list States and a
215 -- corresponding constituent from list Constits (if any) appear in the same
216 -- context denoted by Context. If this is the case, emit an error.
218 procedure Contract_Freeze_Error
219 (Contract_Id : Entity_Id;
220 Freeze_Id : Entity_Id);
221 -- Subsidiary to the analysis of pragmas Contract_Cases, Part_Of, Post, and
222 -- Pre. Emit a freezing-related error message where Freeze_Id is the entity
223 -- of a body which caused contract freezing and Contract_Id denotes the
224 -- entity of the affected contstruct.
226 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id);
227 -- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma
228 -- Prag that duplicates previous pragma Prev.
230 function Find_Encapsulating_State
231 (States : Elist_Id;
232 Constit_Id : Entity_Id) return Entity_Id;
233 -- Given the entity of a constituent Constit_Id, find the corresponding
234 -- encapsulating state which appears in States. The routine returns Empty
235 -- if no such state is found.
237 function Find_Related_Context
238 (Prag : Node_Id;
239 Do_Checks : Boolean := False) return Node_Id;
240 -- Subsidiary to the analysis of pragmas
241 -- Async_Readers
242 -- Async_Writers
243 -- Constant_After_Elaboration
244 -- Effective_Reads
245 -- Effective_Writers
246 -- Part_Of
247 -- Find the first source declaration or statement found while traversing
248 -- the previous node chain starting from pragma Prag. If flag Do_Checks is
249 -- set, the routine reports duplicate pragmas. The routine returns Empty
250 -- when reaching the start of the node chain.
252 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
253 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
254 -- original one, following the renaming chain) is returned. Otherwise the
255 -- entity is returned unchanged. Should be in Einfo???
257 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
258 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
259 -- Get_SPARK_Mode_From_Annotation. Convert a name into a corresponding
260 -- value of type SPARK_Mode_Type.
262 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
263 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
264 -- Determine whether dependency clause Clause is surrounded by extra
265 -- parentheses. If this is the case, issue an error message.
267 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
268 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
269 -- pragma Depends. Determine whether the type of dependency item Item is
270 -- tagged, unconstrained array, unconstrained record or a record with at
271 -- least one unconstrained component.
273 procedure Record_Possible_Body_Reference
274 (State_Id : Entity_Id;
275 Ref : Node_Id);
276 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
277 -- Global. Given an abstract state denoted by State_Id and a reference Ref
278 -- to it, determine whether the reference appears in a package body that
279 -- will eventually refine the state. If this is the case, record the
280 -- reference for future checks (see Analyze_Refined_State_In_Decls).
282 procedure Resolve_State (N : Node_Id);
283 -- Handle the overloading of state names by functions. When N denotes a
284 -- function, this routine finds the corresponding state and sets the entity
285 -- of N to that of the state.
287 procedure Rewrite_Assertion_Kind
288 (N : Node_Id;
289 From_Policy : Boolean := False);
290 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
291 -- then it is rewritten as an identifier with the corresponding special
292 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
293 -- and Check_Policy. If the names are Precondition or Postcondition, this
294 -- combination is deprecated in favor of Assertion_Policy and Ada2012
295 -- Aspect names. The parameter From_Policy indicates that the pragma
296 -- is the old non-standard Check_Policy and not a rewritten pragma.
298 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id);
299 -- Place semantic information on the argument of an Elaborate/Elaborate_All
300 -- pragma. Entity name for unit and its parents is taken from item in
301 -- previous with_clause that mentions the unit.
303 procedure Validate_Compile_Time_Warning_Or_Error
304 (N : Node_Id;
305 Eloc : Source_Ptr);
306 -- Common processing for Compile_Time_Error and Compile_Time_Warning of
307 -- pragma N. Called when the pragma is processed as part of its regular
308 -- analysis but also called after calling the back end to validate these
309 -- pragmas for size and alignment appropriateness.
311 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id);
312 -- N is a pragma Compile_Time_Error or Compile_Warning_Error whose boolean
313 -- expression is not known at compile time during the front end. This
314 -- procedure makes an entry in a table. The actual checking is performed by
315 -- Validate_Compile_Time_Warning_Errors, which is invoked after calling the
316 -- back end.
318 Dummy : Integer := 0;
319 pragma Volatile (Dummy);
320 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
322 procedure ip;
323 pragma No_Inline (ip);
324 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
325 -- is just to help debugging the front end. If a pragma Inspection_Point
326 -- is added to a source program, then breaking on ip will get you to that
327 -- point in the program.
329 procedure rv;
330 pragma No_Inline (rv);
331 -- This is a dummy function called by the processing for pragma Reviewable.
332 -- It is there for assisting front end debugging. By placing a Reviewable
333 -- pragma in the source program, a breakpoint on rv catches this place in
334 -- the source, allowing convenient stepping to the point of interest.
336 ------------------------------------------------------
337 -- Table for Defer_Compile_Time_Warning_Error_To_BE --
338 ------------------------------------------------------
340 -- The following table collects pragmas Compile_Time_Error and Compile_
341 -- Time_Warning for validation. Entries are made by calls to subprogram
342 -- Defer_Compile_Time_Warning_Error_To_BE, and the call to the procedure
343 -- Validate_Compile_Time_Warning_Errors does the actual error checking
344 -- and posting of warning and error messages. The reason for this delayed
345 -- processing is to take advantage of back-annotations of attributes size
346 -- and alignment values performed by the back end.
348 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
349 -- that by the time Validate_Compile_Time_Warning_Errors is called, Sprint
350 -- will already have modified all Sloc values if the -gnatD option is set.
352 type CTWE_Entry is record
353 Eloc : Source_Ptr;
354 -- Source location used in warnings and error messages
356 Prag : Node_Id;
357 -- Pragma Compile_Time_Error or Compile_Time_Warning
359 Scope : Node_Id;
360 -- The scope which encloses the pragma
361 end record;
363 package Compile_Time_Warnings_Errors is new Table.Table (
364 Table_Component_Type => CTWE_Entry,
365 Table_Index_Type => Int,
366 Table_Low_Bound => 1,
367 Table_Initial => 50,
368 Table_Increment => 200,
369 Table_Name => "Compile_Time_Warnings_Errors");
371 -------------------------------
372 -- Adjust_External_Name_Case --
373 -------------------------------
375 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
376 CC : Char_Code;
378 begin
379 -- Adjust case of literal if required
381 if Opt.External_Name_Exp_Casing = As_Is then
382 return N;
384 else
385 -- Copy existing string
387 Start_String;
389 -- Set proper casing
391 for J in 1 .. String_Length (Strval (N)) loop
392 CC := Get_String_Char (Strval (N), J);
394 if Opt.External_Name_Exp_Casing = Uppercase
395 and then CC >= Get_Char_Code ('a')
396 and then CC <= Get_Char_Code ('z')
397 then
398 Store_String_Char (CC - 32);
400 elsif Opt.External_Name_Exp_Casing = Lowercase
401 and then CC >= Get_Char_Code ('A')
402 and then CC <= Get_Char_Code ('Z')
403 then
404 Store_String_Char (CC + 32);
406 else
407 Store_String_Char (CC);
408 end if;
409 end loop;
411 return
412 Make_String_Literal (Sloc (N),
413 Strval => End_String);
414 end if;
415 end Adjust_External_Name_Case;
417 -----------------------------------------
418 -- Analyze_Contract_Cases_In_Decl_Part --
419 -----------------------------------------
421 -- WARNING: This routine manages Ghost regions. Return statements must be
422 -- replaced by gotos which jump to the end of the routine and restore the
423 -- Ghost mode.
425 procedure Analyze_Contract_Cases_In_Decl_Part
426 (N : Node_Id;
427 Freeze_Id : Entity_Id := Empty)
429 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
430 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
432 Others_Seen : Boolean := False;
433 -- This flag is set when an "others" choice is encountered. It is used
434 -- to detect multiple illegal occurrences of "others".
436 procedure Analyze_Contract_Case (CCase : Node_Id);
437 -- Verify the legality of a single contract case
439 ---------------------------
440 -- Analyze_Contract_Case --
441 ---------------------------
443 procedure Analyze_Contract_Case (CCase : Node_Id) is
444 Case_Guard : Node_Id;
445 Conseq : Node_Id;
446 Errors : Nat;
447 Extra_Guard : Node_Id;
449 begin
450 if Nkind (CCase) = N_Component_Association then
451 Case_Guard := First (Choices (CCase));
452 Conseq := Expression (CCase);
454 -- Each contract case must have exactly one case guard
456 Extra_Guard := Next (Case_Guard);
458 if Present (Extra_Guard) then
459 Error_Msg_N
460 ("contract case must have exactly one case guard",
461 Extra_Guard);
462 end if;
464 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
466 if Nkind (Case_Guard) = N_Others_Choice then
467 if Others_Seen then
468 Error_Msg_N
469 ("only one others choice allowed in contract cases",
470 Case_Guard);
471 else
472 Others_Seen := True;
473 end if;
475 elsif Others_Seen then
476 Error_Msg_N
477 ("others must be the last choice in contract cases", N);
478 end if;
480 -- Preanalyze the case guard and consequence
482 if Nkind (Case_Guard) /= N_Others_Choice then
483 Errors := Serious_Errors_Detected;
484 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
486 -- Emit a clarification message when the case guard contains
487 -- at least one undefined reference, possibly due to contract
488 -- freezing.
490 if Errors /= Serious_Errors_Detected
491 and then Present (Freeze_Id)
492 and then Has_Undefined_Reference (Case_Guard)
493 then
494 Contract_Freeze_Error (Spec_Id, Freeze_Id);
495 end if;
496 end if;
498 Errors := Serious_Errors_Detected;
499 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
501 -- Emit a clarification message when the consequence contains
502 -- at least one undefined reference, possibly due to contract
503 -- freezing.
505 if Errors /= Serious_Errors_Detected
506 and then Present (Freeze_Id)
507 and then Has_Undefined_Reference (Conseq)
508 then
509 Contract_Freeze_Error (Spec_Id, Freeze_Id);
510 end if;
512 -- The contract case is malformed
514 else
515 Error_Msg_N ("wrong syntax in contract case", CCase);
516 end if;
517 end Analyze_Contract_Case;
519 -- Local variables
521 CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
523 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
524 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
525 -- Save the Ghost-related attributes to restore on exit
527 CCase : Node_Id;
528 Restore_Scope : Boolean := False;
530 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
532 begin
533 -- Do not analyze the pragma multiple times
535 if Is_Analyzed_Pragma (N) then
536 return;
537 end if;
539 -- Set the Ghost mode in effect from the pragma. Due to the delayed
540 -- analysis of the pragma, the Ghost mode at point of declaration and
541 -- point of analysis may not necessarily be the same. Use the mode in
542 -- effect at the point of declaration.
544 Set_Ghost_Mode (N);
546 -- Single and multiple contract cases must appear in aggregate form. If
547 -- this is not the case, then either the parser of the analysis of the
548 -- pragma failed to produce an aggregate.
550 pragma Assert (Nkind (CCases) = N_Aggregate);
552 if Present (Component_Associations (CCases)) then
554 -- Ensure that the formal parameters are visible when analyzing all
555 -- clauses. This falls out of the general rule of aspects pertaining
556 -- to subprogram declarations.
558 if not In_Open_Scopes (Spec_Id) then
559 Restore_Scope := True;
560 Push_Scope (Spec_Id);
562 if Is_Generic_Subprogram (Spec_Id) then
563 Install_Generic_Formals (Spec_Id);
564 else
565 Install_Formals (Spec_Id);
566 end if;
567 end if;
569 CCase := First (Component_Associations (CCases));
570 while Present (CCase) loop
571 Analyze_Contract_Case (CCase);
572 Next (CCase);
573 end loop;
575 if Restore_Scope then
576 End_Scope;
577 end if;
579 -- Currently it is not possible to inline pre/postconditions on a
580 -- subprogram subject to pragma Inline_Always.
582 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
584 -- Otherwise the pragma is illegal
586 else
587 Error_Msg_N ("wrong syntax for contract cases", N);
588 end if;
590 Set_Is_Analyzed_Pragma (N);
592 Restore_Ghost_Region (Saved_GM, Saved_IGR);
593 end Analyze_Contract_Cases_In_Decl_Part;
595 ----------------------------------
596 -- Analyze_Depends_In_Decl_Part --
597 ----------------------------------
599 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
600 Loc : constant Source_Ptr := Sloc (N);
601 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
602 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
604 All_Inputs_Seen : Elist_Id := No_Elist;
605 -- A list containing the entities of all the inputs processed so far.
606 -- The list is populated with unique entities because the same input
607 -- may appear in multiple input lists.
609 All_Outputs_Seen : Elist_Id := No_Elist;
610 -- A list containing the entities of all the outputs processed so far.
611 -- The list is populated with unique entities because output items are
612 -- unique in a dependence relation.
614 Constits_Seen : Elist_Id := No_Elist;
615 -- A list containing the entities of all constituents processed so far.
616 -- It aids in detecting illegal usage of a state and a corresponding
617 -- constituent in pragma [Refinde_]Depends.
619 Global_Seen : Boolean := False;
620 -- A flag set when pragma Global has been processed
622 Null_Output_Seen : Boolean := False;
623 -- A flag used to track the legality of a null output
625 Result_Seen : Boolean := False;
626 -- A flag set when Spec_Id'Result is processed
628 States_Seen : Elist_Id := No_Elist;
629 -- A list containing the entities of all states processed so far. It
630 -- helps in detecting illegal usage of a state and a corresponding
631 -- constituent in pragma [Refined_]Depends.
633 Subp_Inputs : Elist_Id := No_Elist;
634 Subp_Outputs : Elist_Id := No_Elist;
635 -- Two lists containing the full set of inputs and output of the related
636 -- subprograms. Note that these lists contain both nodes and entities.
638 Task_Input_Seen : Boolean := False;
639 Task_Output_Seen : Boolean := False;
640 -- Flags used to track the implicit dependence of a task unit on itself
642 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
643 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
644 -- to the name buffer. The individual kinds are as follows:
645 -- E_Abstract_State - "state"
646 -- E_Constant - "constant"
647 -- E_Generic_In_Out_Parameter - "generic parameter"
648 -- E_Generic_In_Parameter - "generic parameter"
649 -- E_In_Parameter - "parameter"
650 -- E_In_Out_Parameter - "parameter"
651 -- E_Loop_Parameter - "loop parameter"
652 -- E_Out_Parameter - "parameter"
653 -- E_Protected_Type - "current instance of protected type"
654 -- E_Task_Type - "current instance of task type"
655 -- E_Variable - "global"
657 procedure Analyze_Dependency_Clause
658 (Clause : Node_Id;
659 Is_Last : Boolean);
660 -- Verify the legality of a single dependency clause. Flag Is_Last
661 -- denotes whether Clause is the last clause in the relation.
663 procedure Check_Function_Return;
664 -- Verify that Funtion'Result appears as one of the outputs
665 -- (SPARK RM 6.1.5(10)).
667 procedure Check_Role
668 (Item : Node_Id;
669 Item_Id : Entity_Id;
670 Is_Input : Boolean;
671 Self_Ref : Boolean);
672 -- Ensure that an item fulfills its designated input and/or output role
673 -- as specified by pragma Global (if any) or the enclosing context. If
674 -- this is not the case, emit an error. Item and Item_Id denote the
675 -- attributes of an item. Flag Is_Input should be set when item comes
676 -- from an input list. Flag Self_Ref should be set when the item is an
677 -- output and the dependency clause has operator "+".
679 procedure Check_Usage
680 (Subp_Items : Elist_Id;
681 Used_Items : Elist_Id;
682 Is_Input : Boolean);
683 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
684 -- error if this is not the case.
686 procedure Normalize_Clause (Clause : Node_Id);
687 -- Remove a self-dependency "+" from the input list of a clause
689 -----------------------------
690 -- Add_Item_To_Name_Buffer --
691 -----------------------------
693 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
694 begin
695 if Ekind (Item_Id) = E_Abstract_State then
696 Add_Str_To_Name_Buffer ("state");
698 elsif Ekind (Item_Id) = E_Constant then
699 Add_Str_To_Name_Buffer ("constant");
701 elsif Ekind (Item_Id) in
702 E_Generic_In_Out_Parameter | E_Generic_In_Parameter
703 then
704 Add_Str_To_Name_Buffer ("generic parameter");
706 elsif Is_Formal (Item_Id) then
707 Add_Str_To_Name_Buffer ("parameter");
709 elsif Ekind (Item_Id) = E_Loop_Parameter then
710 Add_Str_To_Name_Buffer ("loop parameter");
712 elsif Ekind (Item_Id) = E_Protected_Type
713 or else Is_Single_Protected_Object (Item_Id)
714 then
715 Add_Str_To_Name_Buffer ("current instance of protected type");
717 elsif Ekind (Item_Id) = E_Task_Type
718 or else Is_Single_Task_Object (Item_Id)
719 then
720 Add_Str_To_Name_Buffer ("current instance of task type");
722 elsif Ekind (Item_Id) = E_Variable then
723 Add_Str_To_Name_Buffer ("global");
725 -- The routine should not be called with non-SPARK items
727 else
728 raise Program_Error;
729 end if;
730 end Add_Item_To_Name_Buffer;
732 -------------------------------
733 -- Analyze_Dependency_Clause --
734 -------------------------------
736 procedure Analyze_Dependency_Clause
737 (Clause : Node_Id;
738 Is_Last : Boolean)
740 procedure Analyze_Input_List (Inputs : Node_Id);
741 -- Verify the legality of a single input list
743 procedure Analyze_Input_Output
744 (Item : Node_Id;
745 Is_Input : Boolean;
746 Self_Ref : Boolean;
747 Top_Level : Boolean;
748 Seen : in out Elist_Id;
749 Null_Seen : in out Boolean;
750 Non_Null_Seen : in out Boolean);
751 -- Verify the legality of a single input or output item. Flag
752 -- Is_Input should be set whenever Item is an input, False when it
753 -- denotes an output. Flag Self_Ref should be set when the item is an
754 -- output and the dependency clause has a "+". Flag Top_Level should
755 -- be set whenever Item appears immediately within an input or output
756 -- list. Seen is a collection of all abstract states, objects and
757 -- formals processed so far. Flag Null_Seen denotes whether a null
758 -- input or output has been encountered. Flag Non_Null_Seen denotes
759 -- whether a non-null input or output has been encountered.
761 ------------------------
762 -- Analyze_Input_List --
763 ------------------------
765 procedure Analyze_Input_List (Inputs : Node_Id) is
766 Inputs_Seen : Elist_Id := No_Elist;
767 -- A list containing the entities of all inputs that appear in the
768 -- current input list.
770 Non_Null_Input_Seen : Boolean := False;
771 Null_Input_Seen : Boolean := False;
772 -- Flags used to check the legality of an input list
774 Input : Node_Id;
776 begin
777 -- Multiple inputs appear as an aggregate
779 if Nkind (Inputs) = N_Aggregate then
780 if Present (Component_Associations (Inputs)) then
781 SPARK_Msg_N
782 ("nested dependency relations not allowed", Inputs);
784 elsif Present (Expressions (Inputs)) then
785 Input := First (Expressions (Inputs));
786 while Present (Input) loop
787 Analyze_Input_Output
788 (Item => Input,
789 Is_Input => True,
790 Self_Ref => False,
791 Top_Level => False,
792 Seen => Inputs_Seen,
793 Null_Seen => Null_Input_Seen,
794 Non_Null_Seen => Non_Null_Input_Seen);
796 Next (Input);
797 end loop;
799 -- Syntax error, always report
801 else
802 Error_Msg_N ("malformed input dependency list", Inputs);
803 end if;
805 -- Process a solitary input
807 else
808 Analyze_Input_Output
809 (Item => Inputs,
810 Is_Input => True,
811 Self_Ref => False,
812 Top_Level => False,
813 Seen => Inputs_Seen,
814 Null_Seen => Null_Input_Seen,
815 Non_Null_Seen => Non_Null_Input_Seen);
816 end if;
818 -- Detect an illegal dependency clause of the form
820 -- (null =>[+] null)
822 if Null_Output_Seen and then Null_Input_Seen then
823 SPARK_Msg_N
824 ("null dependency clause cannot have a null input list",
825 Inputs);
826 end if;
827 end Analyze_Input_List;
829 --------------------------
830 -- Analyze_Input_Output --
831 --------------------------
833 procedure Analyze_Input_Output
834 (Item : Node_Id;
835 Is_Input : Boolean;
836 Self_Ref : Boolean;
837 Top_Level : Boolean;
838 Seen : in out Elist_Id;
839 Null_Seen : in out Boolean;
840 Non_Null_Seen : in out Boolean)
842 procedure Current_Task_Instance_Seen;
843 -- Set the appropriate global flag when the current instance of a
844 -- task unit is encountered.
846 --------------------------------
847 -- Current_Task_Instance_Seen --
848 --------------------------------
850 procedure Current_Task_Instance_Seen is
851 begin
852 if Is_Input then
853 Task_Input_Seen := True;
854 else
855 Task_Output_Seen := True;
856 end if;
857 end Current_Task_Instance_Seen;
859 -- Local variables
861 Is_Output : constant Boolean := not Is_Input;
862 Grouped : Node_Id;
863 Item_Id : Entity_Id;
865 -- Start of processing for Analyze_Input_Output
867 begin
868 -- Multiple input or output items appear as an aggregate
870 if Nkind (Item) = N_Aggregate then
871 if not Top_Level then
872 SPARK_Msg_N ("nested grouping of items not allowed", Item);
874 elsif Present (Component_Associations (Item)) then
875 SPARK_Msg_N
876 ("nested dependency relations not allowed", Item);
878 -- Recursively analyze the grouped items
880 elsif Present (Expressions (Item)) then
881 Grouped := First (Expressions (Item));
882 while Present (Grouped) loop
883 Analyze_Input_Output
884 (Item => Grouped,
885 Is_Input => Is_Input,
886 Self_Ref => Self_Ref,
887 Top_Level => False,
888 Seen => Seen,
889 Null_Seen => Null_Seen,
890 Non_Null_Seen => Non_Null_Seen);
892 Next (Grouped);
893 end loop;
895 -- Syntax error, always report
897 else
898 Error_Msg_N ("malformed dependency list", Item);
899 end if;
901 -- Process attribute 'Result in the context of a dependency clause
903 elsif Is_Attribute_Result (Item) then
904 Non_Null_Seen := True;
906 Analyze (Item);
908 -- Attribute 'Result is allowed to appear on the output side of
909 -- a dependency clause (SPARK RM 6.1.5(6)).
911 if Is_Input then
912 SPARK_Msg_N ("function result cannot act as input", Item);
914 elsif Null_Seen then
915 SPARK_Msg_N
916 ("cannot mix null and non-null dependency items", Item);
918 else
919 Result_Seen := True;
920 end if;
922 -- Detect multiple uses of null in a single dependency list or
923 -- throughout the whole relation. Verify the placement of a null
924 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
926 elsif Nkind (Item) = N_Null then
927 if Null_Seen then
928 SPARK_Msg_N
929 ("multiple null dependency relations not allowed", Item);
931 elsif Non_Null_Seen then
932 SPARK_Msg_N
933 ("cannot mix null and non-null dependency items", Item);
935 else
936 Null_Seen := True;
938 if Is_Output then
939 if not Is_Last then
940 SPARK_Msg_N
941 ("null output list must be the last clause in a "
942 & "dependency relation", Item);
944 -- Catch a useless dependence of the form:
945 -- null =>+ ...
947 elsif Self_Ref then
948 SPARK_Msg_N
949 ("useless dependence, null depends on itself", Item);
950 end if;
951 end if;
952 end if;
954 -- Default case
956 else
957 Non_Null_Seen := True;
959 if Null_Seen then
960 SPARK_Msg_N ("cannot mix null and non-null items", Item);
961 end if;
963 Analyze (Item);
964 Resolve_State (Item);
966 -- Find the entity of the item. If this is a renaming, climb
967 -- the renaming chain to reach the root object. Renamings of
968 -- non-entire objects do not yield an entity (Empty).
970 Item_Id := Entity_Of (Item);
972 if Present (Item_Id) then
974 -- Constants
976 if Ekind (Item_Id) in E_Constant | E_Loop_Parameter
977 or else
979 -- Current instances of concurrent types
981 Ekind (Item_Id) in E_Protected_Type | E_Task_Type
982 or else
984 -- Formal parameters
986 Ekind (Item_Id) in E_Generic_In_Out_Parameter
987 | E_Generic_In_Parameter
988 | E_In_Parameter
989 | E_In_Out_Parameter
990 | E_Out_Parameter
991 or else
993 -- States, variables
995 Ekind (Item_Id) in E_Abstract_State | E_Variable
996 then
997 -- A [generic] function is not allowed to have Output
998 -- items in its dependency relations. Note that "null"
999 -- and attribute 'Result are still valid items.
1001 if Ekind (Spec_Id) in E_Function | E_Generic_Function
1002 and then not Is_Input
1003 then
1004 SPARK_Msg_N
1005 ("output item is not applicable to function", Item);
1006 end if;
1008 -- The item denotes a concurrent type. Note that single
1009 -- protected/task types are not considered here because
1010 -- they behave as objects in the context of pragma
1011 -- [Refined_]Depends.
1013 if Ekind (Item_Id) in E_Protected_Type | E_Task_Type then
1015 -- This use is legal as long as the concurrent type is
1016 -- the current instance of an enclosing type.
1018 if Is_CCT_Instance (Item_Id, Spec_Id) then
1020 -- The dependence of a task unit on itself is
1021 -- implicit and may or may not be explicitly
1022 -- specified (SPARK RM 6.1.4).
1024 if Ekind (Item_Id) = E_Task_Type then
1025 Current_Task_Instance_Seen;
1026 end if;
1028 -- Otherwise this is not the current instance
1030 else
1031 SPARK_Msg_N
1032 ("invalid use of subtype mark in dependency "
1033 & "relation", Item);
1034 end if;
1036 -- The dependency of a task unit on itself is implicit
1037 -- and may or may not be explicitly specified
1038 -- (SPARK RM 6.1.4).
1040 elsif Is_Single_Task_Object (Item_Id)
1041 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
1042 then
1043 Current_Task_Instance_Seen;
1044 end if;
1046 -- Ensure that the item fulfills its role as input and/or
1047 -- output as specified by pragma Global or the enclosing
1048 -- context.
1050 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
1052 -- Detect multiple uses of the same state, variable or
1053 -- formal parameter. If this is not the case, add the
1054 -- item to the list of processed relations.
1056 if Contains (Seen, Item_Id) then
1057 SPARK_Msg_NE
1058 ("duplicate use of item &", Item, Item_Id);
1059 else
1060 Append_New_Elmt (Item_Id, Seen);
1061 end if;
1063 -- Detect illegal use of an input related to a null
1064 -- output. Such input items cannot appear in other
1065 -- input lists (SPARK RM 6.1.5(13)).
1067 if Is_Input
1068 and then Null_Output_Seen
1069 and then Contains (All_Inputs_Seen, Item_Id)
1070 then
1071 SPARK_Msg_N
1072 ("input of a null output list cannot appear in "
1073 & "multiple input lists", Item);
1074 end if;
1076 -- Add an input or a self-referential output to the list
1077 -- of all processed inputs.
1079 if Is_Input or else Self_Ref then
1080 Append_New_Elmt (Item_Id, All_Inputs_Seen);
1081 end if;
1083 -- State related checks (SPARK RM 6.1.5(3))
1085 if Ekind (Item_Id) = E_Abstract_State then
1087 -- Package and subprogram bodies are instantiated
1088 -- individually in a separate compiler pass. Due to
1089 -- this mode of instantiation, the refinement of a
1090 -- state may no longer be visible when a subprogram
1091 -- body contract is instantiated. Since the generic
1092 -- template is legal, do not perform this check in
1093 -- the instance to circumvent this oddity.
1095 if In_Instance then
1096 null;
1098 -- An abstract state with visible refinement cannot
1099 -- appear in pragma [Refined_]Depends as its place
1100 -- must be taken by some of its constituents
1101 -- (SPARK RM 6.1.4(7)).
1103 elsif Has_Visible_Refinement (Item_Id) then
1104 SPARK_Msg_NE
1105 ("cannot mention state & in dependence relation",
1106 Item, Item_Id);
1107 SPARK_Msg_N ("\use its constituents instead", Item);
1108 return;
1110 -- If the reference to the abstract state appears in
1111 -- an enclosing package body that will eventually
1112 -- refine the state, record the reference for future
1113 -- checks.
1115 else
1116 Record_Possible_Body_Reference
1117 (State_Id => Item_Id,
1118 Ref => Item);
1119 end if;
1120 end if;
1122 -- When the item renames an entire object, replace the
1123 -- item with a reference to the object.
1125 if Entity (Item) /= Item_Id then
1126 Rewrite (Item,
1127 New_Occurrence_Of (Item_Id, Sloc (Item)));
1128 Analyze (Item);
1129 end if;
1131 -- Add the entity of the current item to the list of
1132 -- processed items.
1134 if Ekind (Item_Id) = E_Abstract_State then
1135 Append_New_Elmt (Item_Id, States_Seen);
1137 -- The variable may eventually become a constituent of a
1138 -- single protected/task type. Record the reference now
1139 -- and verify its legality when analyzing the contract of
1140 -- the variable (SPARK RM 9.3).
1142 elsif Ekind (Item_Id) = E_Variable then
1143 Record_Possible_Part_Of_Reference
1144 (Var_Id => Item_Id,
1145 Ref => Item);
1146 end if;
1148 if Ekind (Item_Id) in E_Abstract_State
1149 | E_Constant
1150 | E_Variable
1151 and then Present (Encapsulating_State (Item_Id))
1152 then
1153 Append_New_Elmt (Item_Id, Constits_Seen);
1154 end if;
1156 -- All other input/output items are illegal
1157 -- (SPARK RM 6.1.5(1)).
1159 else
1160 SPARK_Msg_N
1161 ("item must denote parameter, variable, state or "
1162 & "current instance of concurrent type", Item);
1163 end if;
1165 -- All other input/output items are illegal
1166 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1168 else
1169 Error_Msg_N
1170 ("item must denote parameter, variable, state or current "
1171 & "instance of concurrent type", Item);
1172 end if;
1173 end if;
1174 end Analyze_Input_Output;
1176 -- Local variables
1178 Inputs : Node_Id;
1179 Output : Node_Id;
1180 Self_Ref : Boolean;
1182 Non_Null_Output_Seen : Boolean := False;
1183 -- Flag used to check the legality of an output list
1185 -- Start of processing for Analyze_Dependency_Clause
1187 begin
1188 Inputs := Expression (Clause);
1189 Self_Ref := False;
1191 -- An input list with a self-dependency appears as operator "+" where
1192 -- the actuals inputs are the right operand.
1194 if Nkind (Inputs) = N_Op_Plus then
1195 Inputs := Right_Opnd (Inputs);
1196 Self_Ref := True;
1197 end if;
1199 -- Process the output_list of a dependency_clause
1201 Output := First (Choices (Clause));
1202 while Present (Output) loop
1203 Analyze_Input_Output
1204 (Item => Output,
1205 Is_Input => False,
1206 Self_Ref => Self_Ref,
1207 Top_Level => True,
1208 Seen => All_Outputs_Seen,
1209 Null_Seen => Null_Output_Seen,
1210 Non_Null_Seen => Non_Null_Output_Seen);
1212 Next (Output);
1213 end loop;
1215 -- Process the input_list of a dependency_clause
1217 Analyze_Input_List (Inputs);
1218 end Analyze_Dependency_Clause;
1220 ---------------------------
1221 -- Check_Function_Return --
1222 ---------------------------
1224 procedure Check_Function_Return is
1225 begin
1226 if Ekind (Spec_Id) in E_Function | E_Generic_Function
1227 and then not Result_Seen
1228 then
1229 SPARK_Msg_NE
1230 ("result of & must appear in exactly one output list",
1231 N, Spec_Id);
1232 end if;
1233 end Check_Function_Return;
1235 ----------------
1236 -- Check_Role --
1237 ----------------
1239 procedure Check_Role
1240 (Item : Node_Id;
1241 Item_Id : Entity_Id;
1242 Is_Input : Boolean;
1243 Self_Ref : Boolean)
1245 procedure Find_Role
1246 (Item_Is_Input : out Boolean;
1247 Item_Is_Output : out Boolean);
1248 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1249 -- Item_Is_Output are set depending on the role.
1251 procedure Role_Error
1252 (Item_Is_Input : Boolean;
1253 Item_Is_Output : Boolean);
1254 -- Emit an error message concerning the incorrect use of Item in
1255 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1256 -- denote whether the item is an input and/or an output.
1258 ---------------
1259 -- Find_Role --
1260 ---------------
1262 procedure Find_Role
1263 (Item_Is_Input : out Boolean;
1264 Item_Is_Output : out Boolean)
1266 -- A constant or IN parameter of access type should be handled
1267 -- like a variable, as the underlying memory pointed-to can be
1268 -- modified. Use Adjusted_Kind to do this adjustment.
1270 Adjusted_Kind : Entity_Kind := Ekind (Item_Id);
1272 begin
1273 if Ekind (Item_Id) in E_Constant
1274 | E_Generic_In_Parameter
1275 | E_In_Parameter
1276 and then Is_Access_Type (Etype (Item_Id))
1277 then
1278 Adjusted_Kind := E_Variable;
1279 end if;
1281 case Adjusted_Kind is
1283 -- Abstract states
1285 when E_Abstract_State =>
1287 -- When pragma Global is present it determines the mode of
1288 -- the abstract state.
1290 if Global_Seen then
1291 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1292 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1294 -- Otherwise the state has a default IN OUT mode, because it
1295 -- behaves as a variable.
1297 else
1298 Item_Is_Input := True;
1299 Item_Is_Output := True;
1300 end if;
1302 -- Constants and IN parameters
1304 when E_Constant
1305 | E_Generic_In_Parameter
1306 | E_In_Parameter
1307 | E_Loop_Parameter
1309 -- When pragma Global is present it determines the mode
1310 -- of constant objects as inputs (and such objects cannot
1311 -- appear as outputs in the Global contract).
1313 if Global_Seen then
1314 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1315 else
1316 Item_Is_Input := True;
1317 end if;
1319 Item_Is_Output := False;
1321 -- Variables and IN OUT parameters, as well as constants and
1322 -- IN parameters of access type which are handled like
1323 -- variables.
1325 when E_Generic_In_Out_Parameter
1326 | E_In_Out_Parameter
1327 | E_Variable
1329 -- When pragma Global is present it determines the mode of
1330 -- the object.
1332 if Global_Seen then
1334 -- A variable has mode IN when its type is unconstrained
1335 -- or tagged because array bounds, discriminants or tags
1336 -- can be read.
1338 Item_Is_Input :=
1339 Appears_In (Subp_Inputs, Item_Id)
1340 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1342 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1344 -- Otherwise the variable has a default IN OUT mode
1346 else
1347 Item_Is_Input := True;
1348 Item_Is_Output := True;
1349 end if;
1351 when E_Out_Parameter =>
1353 -- An OUT parameter of the related subprogram; it cannot
1354 -- appear in Global.
1356 if Scope (Item_Id) = Spec_Id then
1358 -- The parameter has mode IN if its type is unconstrained
1359 -- or tagged because array bounds, discriminants or tags
1360 -- can be read.
1362 Item_Is_Input :=
1363 Is_Unconstrained_Or_Tagged_Item (Item_Id);
1365 Item_Is_Output := True;
1367 -- An OUT parameter of an enclosing subprogram; it can
1368 -- appear in Global and behaves as a read-write variable.
1370 else
1371 -- When pragma Global is present it determines the mode
1372 -- of the object.
1374 if Global_Seen then
1376 -- A variable has mode IN when its type is
1377 -- unconstrained or tagged because array
1378 -- bounds, discriminants or tags can be read.
1380 Item_Is_Input :=
1381 Appears_In (Subp_Inputs, Item_Id)
1382 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1384 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1386 -- Otherwise the variable has a default IN OUT mode
1388 else
1389 Item_Is_Input := True;
1390 Item_Is_Output := True;
1391 end if;
1392 end if;
1394 -- Protected types
1396 when E_Protected_Type =>
1397 if Global_Seen then
1399 -- A variable has mode IN when its type is unconstrained
1400 -- or tagged because array bounds, discriminants or tags
1401 -- can be read.
1403 Item_Is_Input :=
1404 Appears_In (Subp_Inputs, Item_Id)
1405 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1407 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1409 else
1410 -- A protected type acts as a formal parameter of mode IN
1411 -- when it applies to a protected function.
1413 if Ekind (Spec_Id) = E_Function then
1414 Item_Is_Input := True;
1415 Item_Is_Output := False;
1417 -- Otherwise the protected type acts as a formal of mode
1418 -- IN OUT.
1420 else
1421 Item_Is_Input := True;
1422 Item_Is_Output := True;
1423 end if;
1424 end if;
1426 -- Task types
1428 when E_Task_Type =>
1430 -- When pragma Global is present it determines the mode of
1431 -- the object.
1433 if Global_Seen then
1434 Item_Is_Input :=
1435 Appears_In (Subp_Inputs, Item_Id)
1436 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1438 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1440 -- Otherwise task types act as IN OUT parameters
1442 else
1443 Item_Is_Input := True;
1444 Item_Is_Output := True;
1445 end if;
1447 when others =>
1448 raise Program_Error;
1449 end case;
1450 end Find_Role;
1452 ----------------
1453 -- Role_Error --
1454 ----------------
1456 procedure Role_Error
1457 (Item_Is_Input : Boolean;
1458 Item_Is_Output : Boolean)
1460 Error_Msg : Name_Id;
1462 begin
1463 Name_Len := 0;
1465 -- When the item is not part of the input and the output set of
1466 -- the related subprogram, then it appears as extra in pragma
1467 -- [Refined_]Depends.
1469 if not Item_Is_Input and then not Item_Is_Output then
1470 Add_Item_To_Name_Buffer (Item_Id);
1471 Add_Str_To_Name_Buffer
1472 (" & cannot appear in dependence relation");
1474 Error_Msg := Name_Find;
1475 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1477 Error_Msg_Name_1 := Chars (Spec_Id);
1478 SPARK_Msg_NE
1479 (Fix_Msg (Spec_Id, "\& is not part of the input or output "
1480 & "set of subprogram %"), Item, Item_Id);
1482 -- The mode of the item and its role in pragma [Refined_]Depends
1483 -- are in conflict. Construct a detailed message explaining the
1484 -- illegality (SPARK RM 6.1.5(5-6)).
1486 else
1487 if Item_Is_Input then
1488 Add_Str_To_Name_Buffer ("read-only");
1489 else
1490 Add_Str_To_Name_Buffer ("write-only");
1491 end if;
1493 Add_Char_To_Name_Buffer (' ');
1494 Add_Item_To_Name_Buffer (Item_Id);
1495 Add_Str_To_Name_Buffer (" & cannot appear as ");
1497 if Item_Is_Input then
1498 Add_Str_To_Name_Buffer ("output");
1499 else
1500 Add_Str_To_Name_Buffer ("input");
1501 end if;
1503 Add_Str_To_Name_Buffer (" in dependence relation");
1504 Error_Msg := Name_Find;
1505 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1506 end if;
1507 end Role_Error;
1509 -- Local variables
1511 Item_Is_Input : Boolean;
1512 Item_Is_Output : Boolean;
1514 -- Start of processing for Check_Role
1516 begin
1517 Find_Role (Item_Is_Input, Item_Is_Output);
1519 -- Input item
1521 if Is_Input then
1522 if not Item_Is_Input then
1523 Role_Error (Item_Is_Input, Item_Is_Output);
1524 end if;
1526 -- Self-referential item
1528 elsif Self_Ref then
1529 if not Item_Is_Input or else not Item_Is_Output then
1530 Role_Error (Item_Is_Input, Item_Is_Output);
1531 end if;
1533 -- Output item
1535 elsif not Item_Is_Output then
1536 Role_Error (Item_Is_Input, Item_Is_Output);
1537 end if;
1538 end Check_Role;
1540 -----------------
1541 -- Check_Usage --
1542 -----------------
1544 procedure Check_Usage
1545 (Subp_Items : Elist_Id;
1546 Used_Items : Elist_Id;
1547 Is_Input : Boolean)
1549 procedure Usage_Error (Item_Id : Entity_Id);
1550 -- Emit an error concerning the illegal usage of an item
1552 -----------------
1553 -- Usage_Error --
1554 -----------------
1556 procedure Usage_Error (Item_Id : Entity_Id) is
1557 Error_Msg : Name_Id;
1559 begin
1560 -- Input case
1562 if Is_Input then
1564 -- Unconstrained and tagged items are not part of the explicit
1565 -- input set of the related subprogram, they do not have to be
1566 -- present in a dependence relation and should not be flagged
1567 -- (SPARK RM 6.1.5(5)).
1569 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1570 Name_Len := 0;
1572 Add_Item_To_Name_Buffer (Item_Id);
1573 Add_Str_To_Name_Buffer
1574 (" & is missing from input dependence list");
1576 Error_Msg := Name_Find;
1577 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1578 SPARK_Msg_NE
1579 ("\add `null ='> &` dependency to ignore this input",
1580 N, Item_Id);
1581 end if;
1583 -- Output case (SPARK RM 6.1.5(10))
1585 else
1586 Name_Len := 0;
1588 Add_Item_To_Name_Buffer (Item_Id);
1589 Add_Str_To_Name_Buffer
1590 (" & is missing from output dependence list");
1592 Error_Msg := Name_Find;
1593 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1594 end if;
1595 end Usage_Error;
1597 -- Local variables
1599 Elmt : Elmt_Id;
1600 Item : Node_Id;
1601 Item_Id : Entity_Id;
1603 -- Start of processing for Check_Usage
1605 begin
1606 if No (Subp_Items) then
1607 return;
1608 end if;
1610 -- Each input or output of the subprogram must appear in a dependency
1611 -- relation.
1613 Elmt := First_Elmt (Subp_Items);
1614 while Present (Elmt) loop
1615 Item := Node (Elmt);
1617 if Nkind (Item) = N_Defining_Identifier then
1618 Item_Id := Item;
1619 else
1620 Item_Id := Entity_Of (Item);
1621 end if;
1623 -- The item does not appear in a dependency
1625 if Present (Item_Id)
1626 and then not Contains (Used_Items, Item_Id)
1627 then
1628 if Is_Formal (Item_Id) then
1629 Usage_Error (Item_Id);
1631 -- The current instance of a protected type behaves as a formal
1632 -- parameter (SPARK RM 6.1.4).
1634 elsif Ekind (Item_Id) = E_Protected_Type
1635 or else Is_Single_Protected_Object (Item_Id)
1636 then
1637 Usage_Error (Item_Id);
1639 -- The current instance of a task type behaves as a formal
1640 -- parameter (SPARK RM 6.1.4).
1642 elsif Ekind (Item_Id) = E_Task_Type
1643 or else Is_Single_Task_Object (Item_Id)
1644 then
1645 -- The dependence of a task unit on itself is implicit and
1646 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1647 -- Emit an error if only one input/output is present.
1649 if Task_Input_Seen /= Task_Output_Seen then
1650 Usage_Error (Item_Id);
1651 end if;
1653 -- States and global objects are not used properly only when
1654 -- the subprogram is subject to pragma Global.
1656 elsif Global_Seen then
1657 Usage_Error (Item_Id);
1658 end if;
1659 end if;
1661 Next_Elmt (Elmt);
1662 end loop;
1663 end Check_Usage;
1665 ----------------------
1666 -- Normalize_Clause --
1667 ----------------------
1669 procedure Normalize_Clause (Clause : Node_Id) is
1670 procedure Create_Or_Modify_Clause
1671 (Output : Node_Id;
1672 Outputs : Node_Id;
1673 Inputs : Node_Id;
1674 After : Node_Id;
1675 In_Place : Boolean;
1676 Multiple : Boolean);
1677 -- Create a brand new clause to represent the self-reference or
1678 -- modify the input and/or output lists of an existing clause. Output
1679 -- denotes a self-referencial output. Outputs is the output list of a
1680 -- clause. Inputs is the input list of a clause. After denotes the
1681 -- clause after which the new clause is to be inserted. Flag In_Place
1682 -- should be set when normalizing the last output of an output list.
1683 -- Flag Multiple should be set when Output comes from a list with
1684 -- multiple items.
1686 -----------------------------
1687 -- Create_Or_Modify_Clause --
1688 -----------------------------
1690 procedure Create_Or_Modify_Clause
1691 (Output : Node_Id;
1692 Outputs : Node_Id;
1693 Inputs : Node_Id;
1694 After : Node_Id;
1695 In_Place : Boolean;
1696 Multiple : Boolean)
1698 procedure Propagate_Output
1699 (Output : Node_Id;
1700 Inputs : Node_Id);
1701 -- Handle the various cases of output propagation to the input
1702 -- list. Output denotes a self-referencial output item. Inputs
1703 -- is the input list of a clause.
1705 ----------------------
1706 -- Propagate_Output --
1707 ----------------------
1709 procedure Propagate_Output
1710 (Output : Node_Id;
1711 Inputs : Node_Id)
1713 function In_Input_List
1714 (Item : Entity_Id;
1715 Inputs : List_Id) return Boolean;
1716 -- Determine whether a particulat item appears in the input
1717 -- list of a clause.
1719 -------------------
1720 -- In_Input_List --
1721 -------------------
1723 function In_Input_List
1724 (Item : Entity_Id;
1725 Inputs : List_Id) return Boolean
1727 Elmt : Node_Id;
1729 begin
1730 Elmt := First (Inputs);
1731 while Present (Elmt) loop
1732 if Entity_Of (Elmt) = Item then
1733 return True;
1734 end if;
1736 Next (Elmt);
1737 end loop;
1739 return False;
1740 end In_Input_List;
1742 -- Local variables
1744 Output_Id : constant Entity_Id := Entity_Of (Output);
1745 Grouped : List_Id;
1747 -- Start of processing for Propagate_Output
1749 begin
1750 -- The clause is of the form:
1752 -- (Output =>+ null)
1754 -- Remove null input and replace it with a copy of the output:
1756 -- (Output => Output)
1758 if Nkind (Inputs) = N_Null then
1759 Rewrite (Inputs, New_Copy_Tree (Output));
1761 -- The clause is of the form:
1763 -- (Output =>+ (Input1, ..., InputN))
1765 -- Determine whether the output is not already mentioned in the
1766 -- input list and if not, add it to the list of inputs:
1768 -- (Output => (Output, Input1, ..., InputN))
1770 elsif Nkind (Inputs) = N_Aggregate then
1771 Grouped := Expressions (Inputs);
1773 if not In_Input_List
1774 (Item => Output_Id,
1775 Inputs => Grouped)
1776 then
1777 Prepend_To (Grouped, New_Copy_Tree (Output));
1778 end if;
1780 -- The clause is of the form:
1782 -- (Output =>+ Input)
1784 -- If the input does not mention the output, group the two
1785 -- together:
1787 -- (Output => (Output, Input))
1789 elsif Entity_Of (Inputs) /= Output_Id then
1790 Rewrite (Inputs,
1791 Make_Aggregate (Loc,
1792 Expressions => New_List (
1793 New_Copy_Tree (Output),
1794 New_Copy_Tree (Inputs))));
1795 end if;
1796 end Propagate_Output;
1798 -- Local variables
1800 Loc : constant Source_Ptr := Sloc (Clause);
1801 New_Clause : Node_Id;
1803 -- Start of processing for Create_Or_Modify_Clause
1805 begin
1806 -- A null output depending on itself does not require any
1807 -- normalization.
1809 if Nkind (Output) = N_Null then
1810 return;
1812 -- A function result cannot depend on itself because it cannot
1813 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1815 elsif Is_Attribute_Result (Output) then
1816 SPARK_Msg_N ("function result cannot depend on itself", Output);
1817 return;
1818 end if;
1820 -- When performing the transformation in place, simply add the
1821 -- output to the list of inputs (if not already there). This
1822 -- case arises when dealing with the last output of an output
1823 -- list. Perform the normalization in place to avoid generating
1824 -- a malformed tree.
1826 if In_Place then
1827 Propagate_Output (Output, Inputs);
1829 -- A list with multiple outputs is slowly trimmed until only
1830 -- one element remains. When this happens, replace aggregate
1831 -- with the element itself.
1833 if Multiple then
1834 Remove (Output);
1835 Rewrite (Outputs, Output);
1836 end if;
1838 -- Default case
1840 else
1841 -- Unchain the output from its output list as it will appear in
1842 -- a new clause. Note that we cannot simply rewrite the output
1843 -- as null because this will violate the semantics of pragma
1844 -- Depends.
1846 Remove (Output);
1848 -- Generate a new clause of the form:
1849 -- (Output => Inputs)
1851 New_Clause :=
1852 Make_Component_Association (Loc,
1853 Choices => New_List (Output),
1854 Expression => New_Copy_Tree (Inputs));
1856 -- The new clause contains replicated content that has already
1857 -- been analyzed. There is not need to reanalyze or renormalize
1858 -- it again.
1860 Set_Analyzed (New_Clause);
1862 Propagate_Output
1863 (Output => First (Choices (New_Clause)),
1864 Inputs => Expression (New_Clause));
1866 Insert_After (After, New_Clause);
1867 end if;
1868 end Create_Or_Modify_Clause;
1870 -- Local variables
1872 Outputs : constant Node_Id := First (Choices (Clause));
1873 Inputs : Node_Id;
1874 Last_Output : Node_Id;
1875 Next_Output : Node_Id;
1876 Output : Node_Id;
1878 -- Start of processing for Normalize_Clause
1880 begin
1881 -- A self-dependency appears as operator "+". Remove the "+" from the
1882 -- tree by moving the real inputs to their proper place.
1884 if Nkind (Expression (Clause)) = N_Op_Plus then
1885 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1886 Inputs := Expression (Clause);
1888 -- Multiple outputs appear as an aggregate
1890 if Nkind (Outputs) = N_Aggregate then
1891 Last_Output := Last (Expressions (Outputs));
1893 Output := First (Expressions (Outputs));
1894 while Present (Output) loop
1896 -- Normalization may remove an output from its list,
1897 -- preserve the subsequent output now.
1899 Next_Output := Next (Output);
1901 Create_Or_Modify_Clause
1902 (Output => Output,
1903 Outputs => Outputs,
1904 Inputs => Inputs,
1905 After => Clause,
1906 In_Place => Output = Last_Output,
1907 Multiple => True);
1909 Output := Next_Output;
1910 end loop;
1912 -- Solitary output
1914 else
1915 Create_Or_Modify_Clause
1916 (Output => Outputs,
1917 Outputs => Empty,
1918 Inputs => Inputs,
1919 After => Empty,
1920 In_Place => True,
1921 Multiple => False);
1922 end if;
1923 end if;
1924 end Normalize_Clause;
1926 -- Local variables
1928 Deps : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
1929 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
1931 Clause : Node_Id;
1932 Errors : Nat;
1933 Last_Clause : Node_Id;
1934 Restore_Scope : Boolean := False;
1936 -- Start of processing for Analyze_Depends_In_Decl_Part
1938 begin
1939 -- Do not analyze the pragma multiple times
1941 if Is_Analyzed_Pragma (N) then
1942 return;
1943 end if;
1945 -- Empty dependency list
1947 if Nkind (Deps) = N_Null then
1949 -- Gather all states, objects and formal parameters that the
1950 -- subprogram may depend on. These items are obtained from the
1951 -- parameter profile or pragma [Refined_]Global (if available).
1953 Collect_Subprogram_Inputs_Outputs
1954 (Subp_Id => Subp_Id,
1955 Subp_Inputs => Subp_Inputs,
1956 Subp_Outputs => Subp_Outputs,
1957 Global_Seen => Global_Seen);
1959 -- Verify that every input or output of the subprogram appear in a
1960 -- dependency.
1962 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1963 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1964 Check_Function_Return;
1966 -- Dependency clauses appear as component associations of an aggregate
1968 elsif Nkind (Deps) = N_Aggregate then
1970 -- Do not attempt to perform analysis of a syntactically illegal
1971 -- clause as this will lead to misleading errors.
1973 if Has_Extra_Parentheses (Deps) then
1974 return;
1975 end if;
1977 if Present (Component_Associations (Deps)) then
1978 Last_Clause := Last (Component_Associations (Deps));
1980 -- Gather all states, objects and formal parameters that the
1981 -- subprogram may depend on. These items are obtained from the
1982 -- parameter profile or pragma [Refined_]Global (if available).
1984 Collect_Subprogram_Inputs_Outputs
1985 (Subp_Id => Subp_Id,
1986 Subp_Inputs => Subp_Inputs,
1987 Subp_Outputs => Subp_Outputs,
1988 Global_Seen => Global_Seen);
1990 -- When pragma [Refined_]Depends appears on a single concurrent
1991 -- type, it is relocated to the anonymous object.
1993 if Is_Single_Concurrent_Object (Spec_Id) then
1994 null;
1996 -- Ensure that the formal parameters are visible when analyzing
1997 -- all clauses. This falls out of the general rule of aspects
1998 -- pertaining to subprogram declarations.
2000 elsif not In_Open_Scopes (Spec_Id) then
2001 Restore_Scope := True;
2002 Push_Scope (Spec_Id);
2004 if Ekind (Spec_Id) = E_Task_Type then
2006 -- Task discriminants cannot appear in the [Refined_]Depends
2007 -- contract, but must be present for the analysis so that we
2008 -- can reject them with an informative error message.
2010 if Has_Discriminants (Spec_Id) then
2011 Install_Discriminants (Spec_Id);
2012 end if;
2014 elsif Is_Generic_Subprogram (Spec_Id) then
2015 Install_Generic_Formals (Spec_Id);
2017 else
2018 Install_Formals (Spec_Id);
2019 end if;
2020 end if;
2022 Clause := First (Component_Associations (Deps));
2023 while Present (Clause) loop
2024 Errors := Serious_Errors_Detected;
2026 -- The normalization mechanism may create extra clauses that
2027 -- contain replicated input and output names. There is no need
2028 -- to reanalyze them.
2030 if not Analyzed (Clause) then
2031 Set_Analyzed (Clause);
2033 Analyze_Dependency_Clause
2034 (Clause => Clause,
2035 Is_Last => Clause = Last_Clause);
2036 end if;
2038 -- Do not normalize a clause if errors were detected (count
2039 -- of Serious_Errors has increased) because the inputs and/or
2040 -- outputs may denote illegal items.
2042 if Serious_Errors_Detected = Errors then
2043 Normalize_Clause (Clause);
2044 end if;
2046 Next (Clause);
2047 end loop;
2049 if Restore_Scope then
2050 End_Scope;
2051 end if;
2053 -- Verify that every input or output of the subprogram appear in a
2054 -- dependency.
2056 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
2057 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
2058 Check_Function_Return;
2060 -- The dependency list is malformed. This is a syntax error, always
2061 -- report.
2063 else
2064 Error_Msg_N ("malformed dependency relation", Deps);
2065 return;
2066 end if;
2068 -- The top level dependency relation is malformed. This is a syntax
2069 -- error, always report.
2071 else
2072 Error_Msg_N ("malformed dependency relation", Deps);
2073 goto Leave;
2074 end if;
2076 -- Ensure that a state and a corresponding constituent do not appear
2077 -- together in pragma [Refined_]Depends.
2079 Check_State_And_Constituent_Use
2080 (States => States_Seen,
2081 Constits => Constits_Seen,
2082 Context => N);
2084 <<Leave>>
2085 Set_Is_Analyzed_Pragma (N);
2086 end Analyze_Depends_In_Decl_Part;
2088 --------------------------------------------
2089 -- Analyze_External_Property_In_Decl_Part --
2090 --------------------------------------------
2092 procedure Analyze_External_Property_In_Decl_Part
2093 (N : Node_Id;
2094 Expr_Val : out Boolean)
2096 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pragma_Name (N));
2097 Arg1 : constant Node_Id :=
2098 First (Pragma_Argument_Associations (N));
2099 Obj_Decl : constant Node_Id := Find_Related_Context (N);
2100 Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl);
2101 Expr : Node_Id;
2103 begin
2104 Expr_Val := False;
2106 -- Do not analyze the pragma multiple times
2108 if Is_Analyzed_Pragma (N) then
2109 return;
2110 end if;
2112 Error_Msg_Name_1 := Pragma_Name (N);
2114 -- An external property pragma must apply to an effectively volatile
2115 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
2116 -- The check is performed at the end of the declarative region due to a
2117 -- possible out-of-order arrangement of pragmas:
2119 -- Obj : ...;
2120 -- pragma Async_Readers (Obj);
2121 -- pragma Volatile (Obj);
2123 if Prag_Id /= Pragma_No_Caching
2124 and then not Is_Effectively_Volatile (Obj_Id)
2125 then
2126 if Ekind (Obj_Id) = E_Variable
2127 and then No_Caching_Enabled (Obj_Id)
2128 then
2129 SPARK_Msg_N
2130 ("illegal combination of external property % and property "
2131 & """No_Caching"" (SPARK RM 7.1.2(6))", N);
2132 else
2133 SPARK_Msg_N
2134 ("external property % must apply to a volatile type or object",
2136 end if;
2138 -- Pragma No_Caching should only apply to volatile variables of
2139 -- a non-effectively volatile type (SPARK RM 7.1.2).
2141 elsif Prag_Id = Pragma_No_Caching then
2142 if Is_Effectively_Volatile (Etype (Obj_Id)) then
2143 SPARK_Msg_N ("property % must not apply to an object of "
2144 & "an effectively volatile type", N);
2145 elsif not Is_Volatile (Obj_Id) then
2146 SPARK_Msg_N ("property % must apply to a volatile object", N);
2147 end if;
2148 end if;
2150 -- Ensure that the Boolean expression (if present) is static. A missing
2151 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
2153 Expr_Val := True;
2155 if Present (Arg1) then
2156 Expr := Get_Pragma_Arg (Arg1);
2158 if Is_OK_Static_Expression (Expr) then
2159 Expr_Val := Is_True (Expr_Value (Expr));
2160 end if;
2161 end if;
2163 Set_Is_Analyzed_Pragma (N);
2164 end Analyze_External_Property_In_Decl_Part;
2166 ---------------------------------
2167 -- Analyze_Global_In_Decl_Part --
2168 ---------------------------------
2170 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
2171 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
2172 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
2173 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
2175 Constits_Seen : Elist_Id := No_Elist;
2176 -- A list containing the entities of all constituents processed so far.
2177 -- It aids in detecting illegal usage of a state and a corresponding
2178 -- constituent in pragma [Refinde_]Global.
2180 Seen : Elist_Id := No_Elist;
2181 -- A list containing the entities of all the items processed so far. It
2182 -- plays a role in detecting distinct entities.
2184 States_Seen : Elist_Id := No_Elist;
2185 -- A list containing the entities of all states processed so far. It
2186 -- helps in detecting illegal usage of a state and a corresponding
2187 -- constituent in pragma [Refined_]Global.
2189 In_Out_Seen : Boolean := False;
2190 Input_Seen : Boolean := False;
2191 Output_Seen : Boolean := False;
2192 Proof_Seen : Boolean := False;
2193 -- Flags used to verify the consistency of modes
2195 procedure Analyze_Global_List
2196 (List : Node_Id;
2197 Global_Mode : Name_Id := Name_Input);
2198 -- Verify the legality of a single global list declaration. Global_Mode
2199 -- denotes the current mode in effect.
2201 -------------------------
2202 -- Analyze_Global_List --
2203 -------------------------
2205 procedure Analyze_Global_List
2206 (List : Node_Id;
2207 Global_Mode : Name_Id := Name_Input)
2209 procedure Analyze_Global_Item
2210 (Item : Node_Id;
2211 Global_Mode : Name_Id);
2212 -- Verify the legality of a single global item declaration denoted by
2213 -- Item. Global_Mode denotes the current mode in effect.
2215 procedure Check_Duplicate_Mode
2216 (Mode : Node_Id;
2217 Status : in out Boolean);
2218 -- Flag Status denotes whether a particular mode has been seen while
2219 -- processing a global list. This routine verifies that Mode is not a
2220 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2222 procedure Check_Mode_Restriction_In_Enclosing_Context
2223 (Item : Node_Id;
2224 Item_Id : Entity_Id);
2225 -- Verify that an item of mode In_Out or Output does not appear as
2226 -- an input in the Global aspect of an enclosing subprogram or task
2227 -- unit. If this is the case, emit an error. Item and Item_Id are
2228 -- respectively the item and its entity.
2230 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
2231 -- Mode denotes either In_Out or Output. Depending on the kind of the
2232 -- related subprogram, emit an error if those two modes apply to a
2233 -- function (SPARK RM 6.1.4(10)).
2235 -------------------------
2236 -- Analyze_Global_Item --
2237 -------------------------
2239 procedure Analyze_Global_Item
2240 (Item : Node_Id;
2241 Global_Mode : Name_Id)
2243 Item_Id : Entity_Id;
2245 begin
2246 -- Detect one of the following cases
2248 -- with Global => (null, Name)
2249 -- with Global => (Name_1, null, Name_2)
2250 -- with Global => (Name, null)
2252 if Nkind (Item) = N_Null then
2253 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
2254 return;
2255 end if;
2257 Analyze (Item);
2258 Resolve_State (Item);
2260 -- Find the entity of the item. If this is a renaming, climb the
2261 -- renaming chain to reach the root object. Renamings of non-
2262 -- entire objects do not yield an entity (Empty).
2264 Item_Id := Entity_Of (Item);
2266 if Present (Item_Id) then
2268 -- A global item may denote a formal parameter of an enclosing
2269 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2270 -- provide a better error diagnostic.
2272 if Is_Formal (Item_Id) then
2273 if Scope (Item_Id) = Spec_Id then
2274 SPARK_Msg_NE
2275 (Fix_Msg (Spec_Id, "global item cannot reference "
2276 & "parameter of subprogram &"), Item, Spec_Id);
2277 return;
2278 end if;
2280 -- A global item may denote a concurrent type as long as it is
2281 -- the current instance of an enclosing protected or task type
2282 -- (SPARK RM 6.1.4).
2284 elsif Ekind (Item_Id) in E_Protected_Type | E_Task_Type then
2285 if Is_CCT_Instance (Item_Id, Spec_Id) then
2287 -- Pragma [Refined_]Global associated with a protected
2288 -- subprogram cannot mention the current instance of a
2289 -- protected type because the instance behaves as a
2290 -- formal parameter.
2292 if Ekind (Item_Id) = E_Protected_Type then
2293 if Scope (Spec_Id) = Item_Id then
2294 Error_Msg_Name_1 := Chars (Item_Id);
2295 SPARK_Msg_NE
2296 (Fix_Msg (Spec_Id, "global item of subprogram & "
2297 & "cannot reference current instance of "
2298 & "protected type %"), Item, Spec_Id);
2299 return;
2300 end if;
2302 -- Pragma [Refined_]Global associated with a task type
2303 -- cannot mention the current instance of a task type
2304 -- because the instance behaves as a formal parameter.
2306 else pragma Assert (Ekind (Item_Id) = E_Task_Type);
2307 if Spec_Id = Item_Id then
2308 Error_Msg_Name_1 := Chars (Item_Id);
2309 SPARK_Msg_NE
2310 (Fix_Msg (Spec_Id, "global item of subprogram & "
2311 & "cannot reference current instance of task "
2312 & "type %"), Item, Spec_Id);
2313 return;
2314 end if;
2315 end if;
2317 -- Otherwise the global item denotes a subtype mark that is
2318 -- not a current instance.
2320 else
2321 SPARK_Msg_N
2322 ("invalid use of subtype mark in global list", Item);
2323 return;
2324 end if;
2326 -- A global item may denote the anonymous object created for a
2327 -- single protected/task type as long as the current instance
2328 -- is the same single type (SPARK RM 6.1.4).
2330 elsif Is_Single_Concurrent_Object (Item_Id)
2331 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
2332 then
2333 -- Pragma [Refined_]Global associated with a protected
2334 -- subprogram cannot mention the current instance of a
2335 -- protected type because the instance behaves as a formal
2336 -- parameter.
2338 if Is_Single_Protected_Object (Item_Id) then
2339 if Scope (Spec_Id) = Etype (Item_Id) then
2340 Error_Msg_Name_1 := Chars (Item_Id);
2341 SPARK_Msg_NE
2342 (Fix_Msg (Spec_Id, "global item of subprogram & "
2343 & "cannot reference current instance of protected "
2344 & "type %"), Item, Spec_Id);
2345 return;
2346 end if;
2348 -- Pragma [Refined_]Global associated with a task type
2349 -- cannot mention the current instance of a task type
2350 -- because the instance behaves as a formal parameter.
2352 else pragma Assert (Is_Single_Task_Object (Item_Id));
2353 if Spec_Id = Item_Id then
2354 Error_Msg_Name_1 := Chars (Item_Id);
2355 SPARK_Msg_NE
2356 (Fix_Msg (Spec_Id, "global item of subprogram & "
2357 & "cannot reference current instance of task "
2358 & "type %"), Item, Spec_Id);
2359 return;
2360 end if;
2361 end if;
2363 -- A formal object may act as a global item inside a generic
2365 elsif Is_Formal_Object (Item_Id) then
2366 null;
2368 -- The only legal references are those to abstract states,
2369 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2371 elsif Ekind (Item_Id) not in E_Abstract_State
2372 | E_Constant
2373 | E_Loop_Parameter
2374 | E_Variable
2375 then
2376 SPARK_Msg_N
2377 ("global item must denote object, state or current "
2378 & "instance of concurrent type", Item);
2380 if Ekind (Item_Id) in Named_Kind then
2381 SPARK_Msg_NE
2382 ("\named number & is not an object", Item, Item);
2383 end if;
2385 return;
2386 end if;
2388 -- State related checks
2390 if Ekind (Item_Id) = E_Abstract_State then
2392 -- Package and subprogram bodies are instantiated
2393 -- individually in a separate compiler pass. Due to this
2394 -- mode of instantiation, the refinement of a state may
2395 -- no longer be visible when a subprogram body contract
2396 -- is instantiated. Since the generic template is legal,
2397 -- do not perform this check in the instance to circumvent
2398 -- this oddity.
2400 if In_Instance then
2401 null;
2403 -- An abstract state with visible refinement cannot appear
2404 -- in pragma [Refined_]Global as its place must be taken by
2405 -- some of its constituents (SPARK RM 6.1.4(7)).
2407 elsif Has_Visible_Refinement (Item_Id) then
2408 SPARK_Msg_NE
2409 ("cannot mention state & in global refinement",
2410 Item, Item_Id);
2411 SPARK_Msg_N ("\use its constituents instead", Item);
2412 return;
2414 -- An external state cannot appear as a global item of a
2415 -- nonvolatile function (SPARK RM 7.1.3(8)).
2417 elsif Is_External_State (Item_Id)
2418 and then Ekind (Spec_Id) in E_Function | E_Generic_Function
2419 and then not Is_Volatile_Function (Spec_Id)
2420 then
2421 SPARK_Msg_NE
2422 ("external state & cannot act as global item of "
2423 & "nonvolatile function", Item, Item_Id);
2424 return;
2426 -- If the reference to the abstract state appears in an
2427 -- enclosing package body that will eventually refine the
2428 -- state, record the reference for future checks.
2430 else
2431 Record_Possible_Body_Reference
2432 (State_Id => Item_Id,
2433 Ref => Item);
2434 end if;
2436 -- Constant related checks
2438 elsif Ekind (Item_Id) = E_Constant
2439 and then not Is_Access_Type (Etype (Item_Id))
2440 then
2442 -- Unless it is of an access type, a constant is a read-only
2443 -- item, therefore it cannot act as an output.
2445 if Global_Mode in Name_In_Out | Name_Output then
2446 SPARK_Msg_NE
2447 ("constant & cannot act as output", Item, Item_Id);
2448 return;
2449 end if;
2451 -- Loop parameter related checks
2453 elsif Ekind (Item_Id) = E_Loop_Parameter then
2455 -- A loop parameter is a read-only item, therefore it cannot
2456 -- act as an output.
2458 if Global_Mode in Name_In_Out | Name_Output then
2459 SPARK_Msg_NE
2460 ("loop parameter & cannot act as output",
2461 Item, Item_Id);
2462 return;
2463 end if;
2465 -- Variable related checks. These are only relevant when
2466 -- SPARK_Mode is on as they are not standard Ada legality
2467 -- rules.
2469 elsif SPARK_Mode = On
2470 and then Ekind (Item_Id) = E_Variable
2471 and then Is_Effectively_Volatile_For_Reading (Item_Id)
2472 then
2473 -- An effectively volatile object for reading cannot appear
2474 -- as a global item of a nonvolatile function (SPARK RM
2475 -- 7.1.3(8)).
2477 if Ekind (Spec_Id) in E_Function | E_Generic_Function
2478 and then not Is_Volatile_Function (Spec_Id)
2479 then
2480 Error_Msg_NE
2481 ("volatile object & cannot act as global item of a "
2482 & "function", Item, Item_Id);
2483 return;
2485 -- An effectively volatile object with external property
2486 -- Effective_Reads set to True must have mode Output or
2487 -- In_Out (SPARK RM 7.1.3(10)).
2489 elsif Effective_Reads_Enabled (Item_Id)
2490 and then Global_Mode = Name_Input
2491 then
2492 Error_Msg_NE
2493 ("volatile object & with property Effective_Reads must "
2494 & "have mode In_Out or Output", Item, Item_Id);
2495 return;
2496 end if;
2497 end if;
2499 -- When the item renames an entire object, replace the item
2500 -- with a reference to the object.
2502 if Entity (Item) /= Item_Id then
2503 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2504 Analyze (Item);
2505 end if;
2507 -- Some form of illegal construct masquerading as a name
2508 -- (SPARK RM 6.1.4(4)).
2510 else
2511 Error_Msg_N
2512 ("global item must denote object, state or current instance "
2513 & "of concurrent type", Item);
2514 return;
2515 end if;
2517 -- Verify that an output does not appear as an input in an
2518 -- enclosing subprogram.
2520 if Global_Mode in Name_In_Out | Name_Output then
2521 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
2522 end if;
2524 -- The same entity might be referenced through various way.
2525 -- Check the entity of the item rather than the item itself
2526 -- (SPARK RM 6.1.4(10)).
2528 if Contains (Seen, Item_Id) then
2529 SPARK_Msg_N ("duplicate global item", Item);
2531 -- Add the entity of the current item to the list of processed
2532 -- items.
2534 else
2535 Append_New_Elmt (Item_Id, Seen);
2537 if Ekind (Item_Id) = E_Abstract_State then
2538 Append_New_Elmt (Item_Id, States_Seen);
2540 -- The variable may eventually become a constituent of a single
2541 -- protected/task type. Record the reference now and verify its
2542 -- legality when analyzing the contract of the variable
2543 -- (SPARK RM 9.3).
2545 elsif Ekind (Item_Id) = E_Variable then
2546 Record_Possible_Part_Of_Reference
2547 (Var_Id => Item_Id,
2548 Ref => Item);
2549 end if;
2551 if Ekind (Item_Id) in E_Abstract_State | E_Constant | E_Variable
2552 and then Present (Encapsulating_State (Item_Id))
2553 then
2554 Append_New_Elmt (Item_Id, Constits_Seen);
2555 end if;
2556 end if;
2557 end Analyze_Global_Item;
2559 --------------------------
2560 -- Check_Duplicate_Mode --
2561 --------------------------
2563 procedure Check_Duplicate_Mode
2564 (Mode : Node_Id;
2565 Status : in out Boolean)
2567 begin
2568 if Status then
2569 SPARK_Msg_N ("duplicate global mode", Mode);
2570 end if;
2572 Status := True;
2573 end Check_Duplicate_Mode;
2575 -------------------------------------------------
2576 -- Check_Mode_Restriction_In_Enclosing_Context --
2577 -------------------------------------------------
2579 procedure Check_Mode_Restriction_In_Enclosing_Context
2580 (Item : Node_Id;
2581 Item_Id : Entity_Id)
2583 Context : Entity_Id;
2584 Dummy : Boolean;
2585 Inputs : Elist_Id := No_Elist;
2586 Outputs : Elist_Id := No_Elist;
2588 begin
2589 -- Traverse the scope stack looking for enclosing subprograms or
2590 -- tasks subject to pragma [Refined_]Global.
2592 Context := Scope (Subp_Id);
2593 while Present (Context) and then Context /= Standard_Standard loop
2595 -- For a single task type, retrieve the corresponding object to
2596 -- which pragma [Refined_]Global is attached.
2598 if Ekind (Context) = E_Task_Type
2599 and then Is_Single_Concurrent_Type (Context)
2600 then
2601 Context := Anonymous_Object (Context);
2602 end if;
2604 if (Is_Subprogram (Context)
2605 or else Ekind (Context) = E_Task_Type
2606 or else Is_Single_Task_Object (Context))
2607 and then
2608 (Present (Get_Pragma (Context, Pragma_Global))
2609 or else
2610 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2611 then
2612 Collect_Subprogram_Inputs_Outputs
2613 (Subp_Id => Context,
2614 Subp_Inputs => Inputs,
2615 Subp_Outputs => Outputs,
2616 Global_Seen => Dummy);
2618 -- The item is classified as In_Out or Output but appears as
2619 -- an Input in an enclosing subprogram or task unit (SPARK
2620 -- RM 6.1.4(12)).
2622 if Appears_In (Inputs, Item_Id)
2623 and then not Appears_In (Outputs, Item_Id)
2624 then
2625 SPARK_Msg_NE
2626 ("global item & cannot have mode In_Out or Output",
2627 Item, Item_Id);
2629 if Is_Subprogram (Context) then
2630 SPARK_Msg_NE
2631 (Fix_Msg (Subp_Id, "\item already appears as input "
2632 & "of subprogram &"), Item, Context);
2633 else
2634 SPARK_Msg_NE
2635 (Fix_Msg (Subp_Id, "\item already appears as input "
2636 & "of task &"), Item, Context);
2637 end if;
2639 -- Stop the traversal once an error has been detected
2641 exit;
2642 end if;
2643 end if;
2645 Context := Scope (Context);
2646 end loop;
2647 end Check_Mode_Restriction_In_Enclosing_Context;
2649 ----------------------------------------
2650 -- Check_Mode_Restriction_In_Function --
2651 ----------------------------------------
2653 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2654 begin
2655 if Ekind (Spec_Id) in E_Function | E_Generic_Function then
2656 SPARK_Msg_N
2657 ("global mode & is not applicable to functions", Mode);
2658 end if;
2659 end Check_Mode_Restriction_In_Function;
2661 -- Local variables
2663 Assoc : Node_Id;
2664 Item : Node_Id;
2665 Mode : Node_Id;
2667 -- Start of processing for Analyze_Global_List
2669 begin
2670 if Nkind (List) = N_Null then
2671 Set_Analyzed (List);
2673 -- Single global item declaration
2675 elsif Nkind (List) in N_Expanded_Name
2676 | N_Identifier
2677 | N_Selected_Component
2678 then
2679 Analyze_Global_Item (List, Global_Mode);
2681 -- Simple global list or moded global list declaration
2683 elsif Nkind (List) = N_Aggregate then
2684 Set_Analyzed (List);
2686 -- The declaration of a simple global list appear as a collection
2687 -- of expressions.
2689 if Present (Expressions (List)) then
2690 if Present (Component_Associations (List)) then
2691 SPARK_Msg_N
2692 ("cannot mix moded and non-moded global lists", List);
2693 end if;
2695 Item := First (Expressions (List));
2696 while Present (Item) loop
2697 Analyze_Global_Item (Item, Global_Mode);
2698 Next (Item);
2699 end loop;
2701 -- The declaration of a moded global list appears as a collection
2702 -- of component associations where individual choices denote
2703 -- modes.
2705 elsif Present (Component_Associations (List)) then
2706 if Present (Expressions (List)) then
2707 SPARK_Msg_N
2708 ("cannot mix moded and non-moded global lists", List);
2709 end if;
2711 Assoc := First (Component_Associations (List));
2712 while Present (Assoc) loop
2713 Mode := First (Choices (Assoc));
2715 if Nkind (Mode) = N_Identifier then
2716 if Chars (Mode) = Name_In_Out then
2717 Check_Duplicate_Mode (Mode, In_Out_Seen);
2718 Check_Mode_Restriction_In_Function (Mode);
2720 elsif Chars (Mode) = Name_Input then
2721 Check_Duplicate_Mode (Mode, Input_Seen);
2723 elsif Chars (Mode) = Name_Output then
2724 Check_Duplicate_Mode (Mode, Output_Seen);
2725 Check_Mode_Restriction_In_Function (Mode);
2727 elsif Chars (Mode) = Name_Proof_In then
2728 Check_Duplicate_Mode (Mode, Proof_Seen);
2730 else
2731 SPARK_Msg_N ("invalid mode selector", Mode);
2732 end if;
2734 else
2735 SPARK_Msg_N ("invalid mode selector", Mode);
2736 end if;
2738 -- Items in a moded list appear as a collection of
2739 -- expressions. Reuse the existing machinery to analyze
2740 -- them.
2742 Analyze_Global_List
2743 (List => Expression (Assoc),
2744 Global_Mode => Chars (Mode));
2746 Next (Assoc);
2747 end loop;
2749 -- Invalid tree
2751 else
2752 raise Program_Error;
2753 end if;
2755 -- Any other attempt to declare a global item is illegal. This is a
2756 -- syntax error, always report.
2758 else
2759 Error_Msg_N ("malformed global list", List);
2760 end if;
2761 end Analyze_Global_List;
2763 -- Local variables
2765 Items : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
2767 Restore_Scope : Boolean := False;
2769 -- Start of processing for Analyze_Global_In_Decl_Part
2771 begin
2772 -- Do not analyze the pragma multiple times
2774 if Is_Analyzed_Pragma (N) then
2775 return;
2776 end if;
2778 -- There is nothing to be done for a null global list
2780 if Nkind (Items) = N_Null then
2781 Set_Analyzed (Items);
2783 -- Analyze the various forms of global lists and items. Note that some
2784 -- of these may be malformed in which case the analysis emits error
2785 -- messages.
2787 else
2788 -- When pragma [Refined_]Global appears on a single concurrent type,
2789 -- it is relocated to the anonymous object.
2791 if Is_Single_Concurrent_Object (Spec_Id) then
2792 null;
2794 -- Ensure that the formal parameters are visible when processing an
2795 -- item. This falls out of the general rule of aspects pertaining to
2796 -- subprogram declarations.
2798 elsif not In_Open_Scopes (Spec_Id) then
2799 Restore_Scope := True;
2800 Push_Scope (Spec_Id);
2802 if Ekind (Spec_Id) = E_Task_Type then
2804 -- Task discriminants cannot appear in the [Refined_]Global
2805 -- contract, but must be present for the analysis so that we
2806 -- can reject them with an informative error message.
2808 if Has_Discriminants (Spec_Id) then
2809 Install_Discriminants (Spec_Id);
2810 end if;
2812 elsif Is_Generic_Subprogram (Spec_Id) then
2813 Install_Generic_Formals (Spec_Id);
2815 else
2816 Install_Formals (Spec_Id);
2817 end if;
2818 end if;
2820 Analyze_Global_List (Items);
2822 if Restore_Scope then
2823 End_Scope;
2824 end if;
2825 end if;
2827 -- Ensure that a state and a corresponding constituent do not appear
2828 -- together in pragma [Refined_]Global.
2830 Check_State_And_Constituent_Use
2831 (States => States_Seen,
2832 Constits => Constits_Seen,
2833 Context => N);
2835 Set_Is_Analyzed_Pragma (N);
2836 end Analyze_Global_In_Decl_Part;
2838 --------------------------------------------
2839 -- Analyze_Initial_Condition_In_Decl_Part --
2840 --------------------------------------------
2842 -- WARNING: This routine manages Ghost regions. Return statements must be
2843 -- replaced by gotos which jump to the end of the routine and restore the
2844 -- Ghost mode.
2846 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2847 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2848 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2849 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
2851 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
2852 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
2853 -- Save the Ghost-related attributes to restore on exit
2855 begin
2856 -- Do not analyze the pragma multiple times
2858 if Is_Analyzed_Pragma (N) then
2859 return;
2860 end if;
2862 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2863 -- analysis of the pragma, the Ghost mode at point of declaration and
2864 -- point of analysis may not necessarily be the same. Use the mode in
2865 -- effect at the point of declaration.
2867 Set_Ghost_Mode (N);
2869 -- The expression is preanalyzed because it has not been moved to its
2870 -- final place yet. A direct analysis may generate side effects and this
2871 -- is not desired at this point.
2873 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2874 Set_Is_Analyzed_Pragma (N);
2876 Restore_Ghost_Region (Saved_GM, Saved_IGR);
2877 end Analyze_Initial_Condition_In_Decl_Part;
2879 --------------------------------------
2880 -- Analyze_Initializes_In_Decl_Part --
2881 --------------------------------------
2883 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2884 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2885 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2887 Constits_Seen : Elist_Id := No_Elist;
2888 -- A list containing the entities of all constituents processed so far.
2889 -- It aids in detecting illegal usage of a state and a corresponding
2890 -- constituent in pragma Initializes.
2892 Items_Seen : Elist_Id := No_Elist;
2893 -- A list of all initialization items processed so far. This list is
2894 -- used to detect duplicate items.
2896 States_And_Objs : Elist_Id := No_Elist;
2897 -- A list of all abstract states and objects declared in the visible
2898 -- declarations of the related package. This list is used to detect the
2899 -- legality of initialization items.
2901 States_Seen : Elist_Id := No_Elist;
2902 -- A list containing the entities of all states processed so far. It
2903 -- helps in detecting illegal usage of a state and a corresponding
2904 -- constituent in pragma Initializes.
2906 procedure Analyze_Initialization_Item (Item : Node_Id);
2907 -- Verify the legality of a single initialization item
2909 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2910 -- Verify the legality of a single initialization item followed by a
2911 -- list of input items.
2913 procedure Collect_States_And_Objects (Pack_Decl : Node_Id);
2914 -- Inspect the visible declarations of the related package and gather
2915 -- the entities of all abstract states and objects in States_And_Objs.
2917 ---------------------------------
2918 -- Analyze_Initialization_Item --
2919 ---------------------------------
2921 procedure Analyze_Initialization_Item (Item : Node_Id) is
2922 Item_Id : Entity_Id;
2924 begin
2925 Analyze (Item);
2926 Resolve_State (Item);
2928 if Is_Entity_Name (Item) then
2929 Item_Id := Entity_Of (Item);
2931 if Present (Item_Id)
2932 and then Ekind (Item_Id) in
2933 E_Abstract_State | E_Constant | E_Variable
2934 then
2935 -- When the initialization item is undefined, it appears as
2936 -- Any_Id. Do not continue with the analysis of the item.
2938 if Item_Id = Any_Id then
2939 null;
2941 -- The state or variable must be declared in the visible
2942 -- declarations of the package (SPARK RM 7.1.5(7)).
2944 elsif not Contains (States_And_Objs, Item_Id) then
2945 Error_Msg_Name_1 := Chars (Pack_Id);
2946 SPARK_Msg_NE
2947 ("initialization item & must appear in the visible "
2948 & "declarations of package %", Item, Item_Id);
2950 -- Detect a duplicate use of the same initialization item
2951 -- (SPARK RM 7.1.5(5)).
2953 elsif Contains (Items_Seen, Item_Id) then
2954 SPARK_Msg_N ("duplicate initialization item", Item);
2956 -- The item is legal, add it to the list of processed states
2957 -- and variables.
2959 else
2960 Append_New_Elmt (Item_Id, Items_Seen);
2962 if Ekind (Item_Id) = E_Abstract_State then
2963 Append_New_Elmt (Item_Id, States_Seen);
2964 end if;
2966 if Present (Encapsulating_State (Item_Id)) then
2967 Append_New_Elmt (Item_Id, Constits_Seen);
2968 end if;
2969 end if;
2971 -- The item references something that is not a state or object
2972 -- (SPARK RM 7.1.5(3)).
2974 else
2975 SPARK_Msg_N
2976 ("initialization item must denote object or state", Item);
2977 end if;
2979 -- Some form of illegal construct masquerading as a name
2980 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2982 else
2983 Error_Msg_N
2984 ("initialization item must denote object or state", Item);
2985 end if;
2986 end Analyze_Initialization_Item;
2988 ---------------------------------------------
2989 -- Analyze_Initialization_Item_With_Inputs --
2990 ---------------------------------------------
2992 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2993 Inputs_Seen : Elist_Id := No_Elist;
2994 -- A list of all inputs processed so far. This list is used to detect
2995 -- duplicate uses of an input.
2997 Non_Null_Seen : Boolean := False;
2998 Null_Seen : Boolean := False;
2999 -- Flags used to check the legality of an input list
3001 procedure Analyze_Input_Item (Input : Node_Id);
3002 -- Verify the legality of a single input item
3004 ------------------------
3005 -- Analyze_Input_Item --
3006 ------------------------
3008 procedure Analyze_Input_Item (Input : Node_Id) is
3009 Input_Id : Entity_Id;
3011 begin
3012 -- Null input list
3014 if Nkind (Input) = N_Null then
3015 if Null_Seen then
3016 SPARK_Msg_N
3017 ("multiple null initializations not allowed", Item);
3019 elsif Non_Null_Seen then
3020 SPARK_Msg_N
3021 ("cannot mix null and non-null initialization item", Item);
3022 else
3023 Null_Seen := True;
3024 end if;
3026 -- Input item
3028 else
3029 Non_Null_Seen := True;
3031 if Null_Seen then
3032 SPARK_Msg_N
3033 ("cannot mix null and non-null initialization item", Item);
3034 end if;
3036 Analyze (Input);
3037 Resolve_State (Input);
3039 if Is_Entity_Name (Input) then
3040 Input_Id := Entity_Of (Input);
3042 if Present (Input_Id)
3043 and then Ekind (Input_Id) in E_Abstract_State
3044 | E_Constant
3045 | E_Generic_In_Out_Parameter
3046 | E_Generic_In_Parameter
3047 | E_In_Parameter
3048 | E_In_Out_Parameter
3049 | E_Out_Parameter
3050 | E_Protected_Type
3051 | E_Task_Type
3052 | E_Variable
3053 then
3054 -- The input cannot denote states or objects declared
3055 -- within the related package (SPARK RM 7.1.5(4)).
3057 if Within_Scope (Input_Id, Current_Scope) then
3059 -- Do not consider generic formal parameters or their
3060 -- respective mappings to generic formals. Even though
3061 -- the formals appear within the scope of the package,
3062 -- it is allowed for an initialization item to depend
3063 -- on an input item.
3065 if Ekind (Input_Id) in E_Generic_In_Out_Parameter
3066 | E_Generic_In_Parameter
3067 then
3068 null;
3070 elsif Ekind (Input_Id) in E_Constant | E_Variable
3071 and then Present (Corresponding_Generic_Association
3072 (Declaration_Node (Input_Id)))
3073 then
3074 null;
3076 else
3077 Error_Msg_Name_1 := Chars (Pack_Id);
3078 SPARK_Msg_NE
3079 ("input item & cannot denote a visible object or "
3080 & "state of package %", Input, Input_Id);
3081 return;
3082 end if;
3083 end if;
3085 -- Detect a duplicate use of the same input item
3086 -- (SPARK RM 7.1.5(5)).
3088 if Contains (Inputs_Seen, Input_Id) then
3089 SPARK_Msg_N ("duplicate input item", Input);
3090 return;
3091 end if;
3093 -- At this point it is known that the input is legal. Add
3094 -- it to the list of processed inputs.
3096 Append_New_Elmt (Input_Id, Inputs_Seen);
3098 if Ekind (Input_Id) = E_Abstract_State then
3099 Append_New_Elmt (Input_Id, States_Seen);
3100 end if;
3102 if Ekind (Input_Id) in E_Abstract_State
3103 | E_Constant
3104 | E_Variable
3105 and then Present (Encapsulating_State (Input_Id))
3106 then
3107 Append_New_Elmt (Input_Id, Constits_Seen);
3108 end if;
3110 -- The input references something that is not a state or an
3111 -- object (SPARK RM 7.1.5(3)).
3113 else
3114 SPARK_Msg_N
3115 ("input item must denote object or state", Input);
3116 end if;
3118 -- Some form of illegal construct masquerading as a name
3119 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
3121 else
3122 Error_Msg_N
3123 ("input item must denote object or state", Input);
3124 end if;
3125 end if;
3126 end Analyze_Input_Item;
3128 -- Local variables
3130 Inputs : constant Node_Id := Expression (Item);
3131 Elmt : Node_Id;
3132 Input : Node_Id;
3134 Name_Seen : Boolean := False;
3135 -- A flag used to detect multiple item names
3137 -- Start of processing for Analyze_Initialization_Item_With_Inputs
3139 begin
3140 -- Inspect the name of an item with inputs
3142 Elmt := First (Choices (Item));
3143 while Present (Elmt) loop
3144 if Name_Seen then
3145 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
3146 else
3147 Name_Seen := True;
3148 Analyze_Initialization_Item (Elmt);
3149 end if;
3151 Next (Elmt);
3152 end loop;
3154 -- Multiple input items appear as an aggregate
3156 if Nkind (Inputs) = N_Aggregate then
3157 if Present (Expressions (Inputs)) then
3158 Input := First (Expressions (Inputs));
3159 while Present (Input) loop
3160 Analyze_Input_Item (Input);
3161 Next (Input);
3162 end loop;
3163 end if;
3165 if Present (Component_Associations (Inputs)) then
3166 SPARK_Msg_N
3167 ("inputs must appear in named association form", Inputs);
3168 end if;
3170 -- Single input item
3172 else
3173 Analyze_Input_Item (Inputs);
3174 end if;
3175 end Analyze_Initialization_Item_With_Inputs;
3177 --------------------------------
3178 -- Collect_States_And_Objects --
3179 --------------------------------
3181 procedure Collect_States_And_Objects (Pack_Decl : Node_Id) is
3182 Pack_Spec : constant Node_Id := Specification (Pack_Decl);
3183 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
3184 Decl : Node_Id;
3185 State_Elmt : Elmt_Id;
3187 begin
3188 -- Collect the abstract states defined in the package (if any)
3190 if Has_Non_Null_Abstract_State (Pack_Id) then
3191 State_Elmt := First_Elmt (Abstract_States (Pack_Id));
3192 while Present (State_Elmt) loop
3193 Append_New_Elmt (Node (State_Elmt), States_And_Objs);
3194 Next_Elmt (State_Elmt);
3195 end loop;
3196 end if;
3198 -- Collect all objects that appear in the visible declarations of the
3199 -- related package.
3201 if Present (Visible_Declarations (Pack_Spec)) then
3202 Decl := First (Visible_Declarations (Pack_Spec));
3203 while Present (Decl) loop
3204 if Comes_From_Source (Decl)
3205 and then Nkind (Decl) in N_Object_Declaration
3206 | N_Object_Renaming_Declaration
3207 then
3208 Append_New_Elmt (Defining_Entity (Decl), States_And_Objs);
3210 elsif Nkind (Decl) = N_Package_Declaration then
3211 Collect_States_And_Objects (Decl);
3213 elsif Is_Single_Concurrent_Type_Declaration (Decl) then
3214 Append_New_Elmt
3215 (Anonymous_Object (Defining_Entity (Decl)),
3216 States_And_Objs);
3217 end if;
3219 Next (Decl);
3220 end loop;
3221 end if;
3222 end Collect_States_And_Objects;
3224 -- Local variables
3226 Inits : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
3227 Init : Node_Id;
3229 -- Start of processing for Analyze_Initializes_In_Decl_Part
3231 begin
3232 -- Do not analyze the pragma multiple times
3234 if Is_Analyzed_Pragma (N) then
3235 return;
3236 end if;
3238 -- Nothing to do when the initialization list is empty
3240 if Nkind (Inits) = N_Null then
3241 return;
3242 end if;
3244 -- Single and multiple initialization clauses appear as an aggregate. If
3245 -- this is not the case, then either the parser or the analysis of the
3246 -- pragma failed to produce an aggregate.
3248 pragma Assert (Nkind (Inits) = N_Aggregate);
3250 -- Initialize the various lists used during analysis
3252 Collect_States_And_Objects (Pack_Decl);
3254 if Present (Expressions (Inits)) then
3255 Init := First (Expressions (Inits));
3256 while Present (Init) loop
3257 Analyze_Initialization_Item (Init);
3258 Next (Init);
3259 end loop;
3260 end if;
3262 if Present (Component_Associations (Inits)) then
3263 Init := First (Component_Associations (Inits));
3264 while Present (Init) loop
3265 Analyze_Initialization_Item_With_Inputs (Init);
3266 Next (Init);
3267 end loop;
3268 end if;
3270 -- Ensure that a state and a corresponding constituent do not appear
3271 -- together in pragma Initializes.
3273 Check_State_And_Constituent_Use
3274 (States => States_Seen,
3275 Constits => Constits_Seen,
3276 Context => N);
3278 Set_Is_Analyzed_Pragma (N);
3279 end Analyze_Initializes_In_Decl_Part;
3281 ---------------------
3282 -- Analyze_Part_Of --
3283 ---------------------
3285 procedure Analyze_Part_Of
3286 (Indic : Node_Id;
3287 Item_Id : Entity_Id;
3288 Encap : Node_Id;
3289 Encap_Id : out Entity_Id;
3290 Legal : out Boolean)
3292 procedure Check_Part_Of_Abstract_State;
3293 pragma Inline (Check_Part_Of_Abstract_State);
3294 -- Verify the legality of indicator Part_Of when the encapsulator is an
3295 -- abstract state.
3297 procedure Check_Part_Of_Concurrent_Type;
3298 pragma Inline (Check_Part_Of_Concurrent_Type);
3299 -- Verify the legality of indicator Part_Of when the encapsulator is a
3300 -- single concurrent type.
3302 ----------------------------------
3303 -- Check_Part_Of_Abstract_State --
3304 ----------------------------------
3306 procedure Check_Part_Of_Abstract_State is
3307 Pack_Id : Entity_Id;
3308 Placement : State_Space_Kind;
3309 Parent_Unit : Entity_Id;
3311 begin
3312 -- Determine where the object, package instantiation or state lives
3313 -- with respect to the enclosing packages or package bodies.
3315 Find_Placement_In_State_Space
3316 (Item_Id => Item_Id,
3317 Placement => Placement,
3318 Pack_Id => Pack_Id);
3320 -- The item appears in a non-package construct with a declarative
3321 -- part (subprogram, block, etc). As such, the item is not allowed
3322 -- to be a part of an encapsulating state because the item is not
3323 -- visible.
3325 if Placement = Not_In_Package then
3326 SPARK_Msg_N
3327 ("indicator Part_Of cannot appear in this context "
3328 & "(SPARK RM 7.2.6(5))", Indic);
3330 Error_Msg_Name_1 := Chars (Scope (Encap_Id));
3331 SPARK_Msg_NE
3332 ("\& is not part of the hidden state of package %",
3333 Indic, Item_Id);
3334 return;
3336 -- The item appears in the visible state space of some package. In
3337 -- general this scenario does not warrant Part_Of except when the
3338 -- package is a nongeneric private child unit and the encapsulating
3339 -- state is declared in a parent unit or a public descendant of that
3340 -- parent unit.
3342 elsif Placement = Visible_State_Space then
3343 if Is_Child_Unit (Pack_Id)
3344 and then not Is_Generic_Unit (Pack_Id)
3345 and then Is_Private_Descendant (Pack_Id)
3346 then
3347 -- A variable or state abstraction which is part of the visible
3348 -- state of a nongeneric private child unit or its public
3349 -- descendants must have its Part_Of indicator specified. The
3350 -- Part_Of indicator must denote a state declared by either the
3351 -- parent unit of the private unit or by a public descendant of
3352 -- that parent unit.
3354 -- Find the nearest private ancestor (which can be the current
3355 -- unit itself).
3357 Parent_Unit := Pack_Id;
3358 while Present (Parent_Unit) loop
3359 exit when
3360 Private_Present
3361 (Parent (Unit_Declaration_Node (Parent_Unit)));
3362 Parent_Unit := Scope (Parent_Unit);
3363 end loop;
3365 Parent_Unit := Scope (Parent_Unit);
3367 if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then
3368 SPARK_Msg_NE
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);
3372 return;
3374 elsif Scope (Encap_Id) = Parent_Unit
3375 or else
3376 (Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id))
3377 and then not Is_Private_Descendant (Scope (Encap_Id)))
3378 then
3379 null;
3381 else
3382 SPARK_Msg_NE
3383 ("indicator Part_Of must denote abstract state of & or of "
3384 & "its public descendant (SPARK RM 7.2.6(3))",
3385 Indic, Parent_Unit);
3386 return;
3387 end if;
3389 -- Indicator Part_Of is not needed when the related package is
3390 -- not a nongeneric private child unit or a public descendant
3391 -- thereof.
3393 else
3394 SPARK_Msg_N
3395 ("indicator Part_Of cannot appear in this context "
3396 & "(SPARK RM 7.2.6(5))", Indic);
3398 Error_Msg_Name_1 := Chars (Pack_Id);
3399 SPARK_Msg_NE
3400 ("\& is declared in the visible part of package %",
3401 Indic, Item_Id);
3402 return;
3403 end if;
3405 -- When the item appears in the private state space of a package, the
3406 -- encapsulating state must be declared in the same package.
3408 elsif Placement = Private_State_Space then
3409 if Scope (Encap_Id) /= Pack_Id then
3410 SPARK_Msg_NE
3411 ("indicator Part_Of must denote an abstract state of "
3412 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3414 Error_Msg_Name_1 := Chars (Pack_Id);
3415 SPARK_Msg_NE
3416 ("\& is declared in the private part of package %",
3417 Indic, Item_Id);
3418 return;
3419 end if;
3421 -- Items declared in the body state space of a package do not need
3422 -- Part_Of indicators as the refinement has already been seen.
3424 else
3425 SPARK_Msg_N
3426 ("indicator Part_Of cannot appear in this context "
3427 & "(SPARK RM 7.2.6(5))", Indic);
3429 if Scope (Encap_Id) = Pack_Id then
3430 Error_Msg_Name_1 := Chars (Pack_Id);
3431 SPARK_Msg_NE
3432 ("\& is declared in the body of package %", Indic, Item_Id);
3433 end if;
3435 return;
3436 end if;
3438 -- At this point it is known that the Part_Of indicator is legal
3440 Legal := True;
3441 end Check_Part_Of_Abstract_State;
3443 -----------------------------------
3444 -- Check_Part_Of_Concurrent_Type --
3445 -----------------------------------
3447 procedure Check_Part_Of_Concurrent_Type is
3448 function In_Proper_Order
3449 (First : Node_Id;
3450 Second : Node_Id) return Boolean;
3451 pragma Inline (In_Proper_Order);
3452 -- Determine whether node First precedes node Second
3454 procedure Placement_Error;
3455 pragma Inline (Placement_Error);
3456 -- Emit an error concerning the illegal placement of the item with
3457 -- respect to the single concurrent type.
3459 ---------------------
3460 -- In_Proper_Order --
3461 ---------------------
3463 function In_Proper_Order
3464 (First : Node_Id;
3465 Second : Node_Id) return Boolean
3467 N : Node_Id;
3469 begin
3470 if List_Containing (First) = List_Containing (Second) then
3471 N := First;
3472 while Present (N) loop
3473 if N = Second then
3474 return True;
3475 end if;
3477 Next (N);
3478 end loop;
3479 end if;
3481 return False;
3482 end In_Proper_Order;
3484 ---------------------
3485 -- Placement_Error --
3486 ---------------------
3488 procedure Placement_Error is
3489 begin
3490 SPARK_Msg_N
3491 ("indicator Part_Of must denote a previously declared single "
3492 & "protected type or single task type", Encap);
3493 end Placement_Error;
3495 -- Local variables
3497 Conc_Typ : constant Entity_Id := Etype (Encap_Id);
3498 Encap_Decl : constant Node_Id := Declaration_Node (Encap_Id);
3499 Encap_Context : constant Node_Id := Parent (Encap_Decl);
3501 Item_Context : Node_Id;
3502 Item_Decl : Node_Id;
3503 Prv_Decls : List_Id;
3504 Vis_Decls : List_Id;
3506 -- Start of processing for Check_Part_Of_Concurrent_Type
3508 begin
3509 -- Only abstract states and variables can act as constituents of an
3510 -- encapsulating single concurrent type.
3512 if Ekind (Item_Id) in E_Abstract_State | E_Variable then
3513 null;
3515 -- The constituent is a constant
3517 elsif Ekind (Item_Id) = E_Constant then
3518 Error_Msg_Name_1 := Chars (Encap_Id);
3519 SPARK_Msg_NE
3520 (Fix_Msg (Conc_Typ, "constant & cannot act as constituent of "
3521 & "single protected type %"), Indic, Item_Id);
3522 return;
3524 -- The constituent is a package instantiation
3526 else
3527 Error_Msg_Name_1 := Chars (Encap_Id);
3528 SPARK_Msg_NE
3529 (Fix_Msg (Conc_Typ, "package instantiation & cannot act as "
3530 & "constituent of single protected type %"), Indic, Item_Id);
3531 return;
3532 end if;
3534 -- When the item denotes an abstract state of a nested package, use
3535 -- the declaration of the package to detect proper placement.
3537 -- package Pack is
3538 -- task T;
3539 -- package Nested
3540 -- with Abstract_State => (State with Part_Of => T)
3542 if Ekind (Item_Id) = E_Abstract_State then
3543 Item_Decl := Unit_Declaration_Node (Scope (Item_Id));
3544 else
3545 Item_Decl := Declaration_Node (Item_Id);
3546 end if;
3548 Item_Context := Parent (Item_Decl);
3550 -- The item and the single concurrent type must appear in the same
3551 -- declarative region, with the item following the declaration of
3552 -- the single concurrent type (SPARK RM 9(3)).
3554 if Item_Context = Encap_Context then
3555 if Nkind (Item_Context) in N_Package_Specification
3556 | N_Protected_Definition
3557 | N_Task_Definition
3558 then
3559 Prv_Decls := Private_Declarations (Item_Context);
3560 Vis_Decls := Visible_Declarations (Item_Context);
3562 -- The placement is OK when the single concurrent type appears
3563 -- within the visible declarations and the item in the private
3564 -- declarations.
3566 -- package Pack is
3567 -- protected PO ...
3568 -- private
3569 -- Constit : ... with Part_Of => PO;
3570 -- end Pack;
3572 if List_Containing (Encap_Decl) = Vis_Decls
3573 and then List_Containing (Item_Decl) = Prv_Decls
3574 then
3575 null;
3577 -- The placement is illegal when the item appears within the
3578 -- visible declarations and the single concurrent type is in
3579 -- the private declarations.
3581 -- package Pack is
3582 -- Constit : ... with Part_Of => PO;
3583 -- private
3584 -- protected PO ...
3585 -- end Pack;
3587 elsif List_Containing (Item_Decl) = Vis_Decls
3588 and then List_Containing (Encap_Decl) = Prv_Decls
3589 then
3590 Placement_Error;
3591 return;
3593 -- Otherwise both the item and the single concurrent type are
3594 -- in the same list. Ensure that the declaration of the single
3595 -- concurrent type precedes that of the item.
3597 elsif not In_Proper_Order
3598 (First => Encap_Decl,
3599 Second => Item_Decl)
3600 then
3601 Placement_Error;
3602 return;
3603 end if;
3605 -- Otherwise both the item and the single concurrent type are
3606 -- in the same list. Ensure that the declaration of the single
3607 -- concurrent type precedes that of the item.
3609 elsif not In_Proper_Order
3610 (First => Encap_Decl,
3611 Second => Item_Decl)
3612 then
3613 Placement_Error;
3614 return;
3615 end if;
3617 -- Otherwise the item and the single concurrent type reside within
3618 -- unrelated regions.
3620 else
3621 Error_Msg_Name_1 := Chars (Encap_Id);
3622 SPARK_Msg_NE
3623 (Fix_Msg (Conc_Typ, "constituent & must be declared "
3624 & "immediately within the same region as single protected "
3625 & "type %"), Indic, Item_Id);
3626 return;
3627 end if;
3629 -- At this point it is known that the Part_Of indicator is legal
3631 Legal := True;
3632 end Check_Part_Of_Concurrent_Type;
3634 -- Start of processing for Analyze_Part_Of
3636 begin
3637 -- Assume that the indicator is illegal
3639 Encap_Id := Empty;
3640 Legal := False;
3642 if Nkind (Encap) in
3643 N_Expanded_Name | N_Identifier | N_Selected_Component
3644 then
3645 Analyze (Encap);
3646 Resolve_State (Encap);
3648 Encap_Id := Entity (Encap);
3650 -- The encapsulator is an abstract state
3652 if Ekind (Encap_Id) = E_Abstract_State then
3653 null;
3655 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3657 elsif Is_Single_Concurrent_Object (Encap_Id) then
3658 null;
3660 -- Otherwise the encapsulator is not a legal choice
3662 else
3663 SPARK_Msg_N
3664 ("indicator Part_Of must denote abstract state, single "
3665 & "protected type or single task type", Encap);
3666 return;
3667 end if;
3669 -- This is a syntax error, always report
3671 else
3672 Error_Msg_N
3673 ("indicator Part_Of must denote abstract state, single protected "
3674 & "type or single task type", Encap);
3675 return;
3676 end if;
3678 -- Catch a case where indicator Part_Of denotes the abstract view of a
3679 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3681 if From_Limited_With (Encap_Id)
3682 and then Present (Non_Limited_View (Encap_Id))
3683 and then Ekind (Non_Limited_View (Encap_Id)) = E_Variable
3684 then
3685 SPARK_Msg_N ("indicator Part_Of must denote abstract state", Encap);
3686 SPARK_Msg_N ("\& denotes abstract view of object", Encap);
3687 return;
3688 end if;
3690 -- The encapsulator is an abstract state
3692 if Ekind (Encap_Id) = E_Abstract_State then
3693 Check_Part_Of_Abstract_State;
3695 -- The encapsulator is a single concurrent type
3697 else
3698 Check_Part_Of_Concurrent_Type;
3699 end if;
3700 end Analyze_Part_Of;
3702 ----------------------------------
3703 -- Analyze_Part_Of_In_Decl_Part --
3704 ----------------------------------
3706 procedure Analyze_Part_Of_In_Decl_Part
3707 (N : Node_Id;
3708 Freeze_Id : Entity_Id := Empty)
3710 Encap : constant Node_Id :=
3711 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
3712 Errors : constant Nat := Serious_Errors_Detected;
3713 Var_Decl : constant Node_Id := Find_Related_Context (N);
3714 Var_Id : constant Entity_Id := Defining_Entity (Var_Decl);
3715 Constits : Elist_Id;
3716 Encap_Id : Entity_Id;
3717 Legal : Boolean;
3719 begin
3720 -- Detect any discrepancies between the placement of the variable with
3721 -- respect to general state space and the encapsulating state or single
3722 -- concurrent type.
3724 Analyze_Part_Of
3725 (Indic => N,
3726 Item_Id => Var_Id,
3727 Encap => Encap,
3728 Encap_Id => Encap_Id,
3729 Legal => Legal);
3731 -- The Part_Of indicator turns the variable into a constituent of the
3732 -- encapsulating state or single concurrent type.
3734 if Legal then
3735 pragma Assert (Present (Encap_Id));
3736 Constits := Part_Of_Constituents (Encap_Id);
3738 if No (Constits) then
3739 Constits := New_Elmt_List;
3740 Set_Part_Of_Constituents (Encap_Id, Constits);
3741 end if;
3743 Append_Elmt (Var_Id, Constits);
3744 Set_Encapsulating_State (Var_Id, Encap_Id);
3746 -- A Part_Of constituent partially refines an abstract state. This
3747 -- property does not apply to protected or task units.
3749 if Ekind (Encap_Id) = E_Abstract_State then
3750 Set_Has_Partial_Visible_Refinement (Encap_Id);
3751 end if;
3752 end if;
3754 -- Emit a clarification message when the encapsulator is undefined,
3755 -- possibly due to contract freezing.
3757 if Errors /= Serious_Errors_Detected
3758 and then Present (Freeze_Id)
3759 and then Has_Undefined_Reference (Encap)
3760 then
3761 Contract_Freeze_Error (Var_Id, Freeze_Id);
3762 end if;
3763 end Analyze_Part_Of_In_Decl_Part;
3765 --------------------
3766 -- Analyze_Pragma --
3767 --------------------
3769 procedure Analyze_Pragma (N : Node_Id) is
3770 Loc : constant Source_Ptr := Sloc (N);
3772 Pname : Name_Id := Pragma_Name (N);
3773 -- Name of the source pragma, or name of the corresponding aspect for
3774 -- pragmas which originate in a source aspect. In the latter case, the
3775 -- name may be different from the pragma name.
3777 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
3779 Pragma_Exit : exception;
3780 -- This exception is used to exit pragma processing completely. It
3781 -- is used when an error is detected, and no further processing is
3782 -- required. It is also used if an earlier error has left the tree in
3783 -- a state where the pragma should not be processed.
3785 Arg_Count : Nat;
3786 -- Number of pragma argument associations
3788 Arg1 : Node_Id;
3789 Arg2 : Node_Id;
3790 Arg3 : Node_Id;
3791 Arg4 : Node_Id;
3792 Arg5 : Node_Id;
3793 -- First five pragma arguments (pragma argument association nodes, or
3794 -- Empty if the corresponding argument does not exist).
3796 type Name_List is array (Natural range <>) of Name_Id;
3797 type Args_List is array (Natural range <>) of Node_Id;
3798 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3800 -----------------------
3801 -- Local Subprograms --
3802 -----------------------
3804 procedure Ada_2005_Pragma;
3805 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3806 -- Ada 95 mode, these are implementation defined pragmas, so should be
3807 -- caught by the No_Implementation_Pragmas restriction.
3809 procedure Ada_2012_Pragma;
3810 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3811 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3812 -- should be caught by the No_Implementation_Pragmas restriction.
3814 procedure Analyze_Depends_Global
3815 (Spec_Id : out Entity_Id;
3816 Subp_Decl : out Node_Id;
3817 Legal : out Boolean);
3818 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3819 -- legality of the placement and related context of the pragma. Spec_Id
3820 -- is the entity of the related subprogram. Subp_Decl is the declaration
3821 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3823 procedure Analyze_If_Present (Id : Pragma_Id);
3824 -- Inspect the remainder of the list containing pragma N and look for
3825 -- a pragma that matches Id. If found, analyze the pragma.
3827 procedure Analyze_Pre_Post_Condition;
3828 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3830 procedure Analyze_Refined_Depends_Global_Post
3831 (Spec_Id : out Entity_Id;
3832 Body_Id : out Entity_Id;
3833 Legal : out Boolean);
3834 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3835 -- Refined_Global and Refined_Post. Verify the legality of the placement
3836 -- and related context of the pragma. Spec_Id is the entity of the
3837 -- related subprogram. Body_Id is the entity of the subprogram body.
3838 -- Flag Legal is set when the pragma is legal.
3840 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False);
3841 -- Perform full analysis of pragma Unmodified and the write aspect of
3842 -- pragma Unused. Flag Is_Unused should be set when verifying the
3843 -- semantics of pragma Unused.
3845 procedure Analyze_Unreferenced_Or_Unused (Is_Unused : Boolean := False);
3846 -- Perform full analysis of pragma Unreferenced and the read aspect of
3847 -- pragma Unused. Flag Is_Unused should be set when verifying the
3848 -- semantics of pragma Unused.
3850 procedure Check_Ada_83_Warning;
3851 -- Issues a warning message for the current pragma if operating in Ada
3852 -- 83 mode (used for language pragmas that are not a standard part of
3853 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3854 -- of 95 pragma.
3856 procedure Check_Arg_Count (Required : Nat);
3857 -- Check argument count for pragma is equal to given parameter. If not,
3858 -- then issue an error message and raise Pragma_Exit.
3860 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3861 -- Arg which can either be a pragma argument association, in which case
3862 -- the check is applied to the expression of the association or an
3863 -- expression directly.
3865 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
3866 -- Check that an argument has the right form for an EXTERNAL_NAME
3867 -- parameter of an extended import/export pragma. The rule is that the
3868 -- name must be an identifier or string literal (in Ada 83 mode) or a
3869 -- static string expression (in Ada 95 mode).
3871 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
3872 -- Check the specified argument Arg to make sure that it is an
3873 -- identifier. If not give error and raise Pragma_Exit.
3875 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
3876 -- Check the specified argument Arg to make sure that it is an integer
3877 -- literal. If not give error and raise Pragma_Exit.
3879 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
3880 -- Check the specified argument Arg to make sure that it has the proper
3881 -- syntactic form for a local name and meets the semantic requirements
3882 -- for a local name. The local name is analyzed as part of the
3883 -- processing for this call. In addition, the local name is required
3884 -- to represent an entity at the library level.
3886 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
3887 -- Check the specified argument Arg to make sure that it has the proper
3888 -- syntactic form for a local name and meets the semantic requirements
3889 -- for a local name. The local name is analyzed as part of the
3890 -- processing for this call.
3892 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
3893 -- Check the specified argument Arg to make sure that it is a valid
3894 -- locking policy name. If not give error and raise Pragma_Exit.
3896 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
3897 -- Check the specified argument Arg to make sure that it is a valid
3898 -- elaboration policy name. If not give error and raise Pragma_Exit.
3900 procedure Check_Arg_Is_One_Of
3901 (Arg : Node_Id;
3902 N1, N2 : Name_Id);
3903 procedure Check_Arg_Is_One_Of
3904 (Arg : Node_Id;
3905 N1, N2, N3 : Name_Id);
3906 procedure Check_Arg_Is_One_Of
3907 (Arg : Node_Id;
3908 N1, N2, N3, N4 : Name_Id);
3909 procedure Check_Arg_Is_One_Of
3910 (Arg : Node_Id;
3911 N1, N2, N3, N4, N5 : Name_Id);
3912 -- Check the specified argument Arg to make sure that it is an
3913 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3914 -- present). If not then give error and raise Pragma_Exit.
3916 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
3917 -- Check the specified argument Arg to make sure that it is a valid
3918 -- queuing policy name. If not give error and raise Pragma_Exit.
3920 procedure Check_Arg_Is_OK_Static_Expression
3921 (Arg : Node_Id;
3922 Typ : Entity_Id := Empty);
3923 -- Check the specified argument Arg to make sure that it is a static
3924 -- expression of the given type (i.e. it will be analyzed and resolved
3925 -- using this type, which can be any valid argument to Resolve, e.g.
3926 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3927 -- Typ is left Empty, then any static expression is allowed. Includes
3928 -- checking that the argument does not raise Constraint_Error.
3930 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
3931 -- Check the specified argument Arg to make sure that it is a valid task
3932 -- dispatching policy name. If not give error and raise Pragma_Exit.
3934 procedure Check_Arg_Order (Names : Name_List);
3935 -- Checks for an instance of two arguments with identifiers for the
3936 -- current pragma which are not in the sequence indicated by Names,
3937 -- and if so, generates a fatal message about bad order of arguments.
3939 procedure Check_At_Least_N_Arguments (N : Nat);
3940 -- Check there are at least N arguments present
3942 procedure Check_At_Most_N_Arguments (N : Nat);
3943 -- Check there are no more than N arguments present
3945 procedure Check_Atomic_VFA (E : Entity_Id; VFA : Boolean);
3946 -- Apply legality checks to type or object E subject to an Atomic aspect
3947 -- in Ada 2020 (RM C.6(13)) or to a Volatile_Full_Access aspect.
3949 procedure Check_Component
3950 (Comp : Node_Id;
3951 UU_Typ : Entity_Id;
3952 In_Variant_Part : Boolean := False);
3953 -- Examine an Unchecked_Union component for correct use of per-object
3954 -- constrained subtypes, and for restrictions on finalizable components.
3955 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3956 -- should be set when Comp comes from a record variant.
3958 procedure Check_Duplicate_Pragma (E : Entity_Id);
3959 -- Check if a rep item of the same name as the current pragma is already
3960 -- chained as a rep pragma to the given entity. If so give a message
3961 -- about the duplicate, and then raise Pragma_Exit so does not return.
3962 -- Note that if E is a type, then this routine avoids flagging a pragma
3963 -- which applies to a parent type from which E is derived.
3965 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
3966 -- Nam is an N_String_Literal node containing the external name set by
3967 -- an Import or Export pragma (or extended Import or Export pragma).
3968 -- This procedure checks for possible duplications if this is the export
3969 -- case, and if found, issues an appropriate error message.
3971 procedure Check_Expr_Is_OK_Static_Expression
3972 (Expr : Node_Id;
3973 Typ : Entity_Id := Empty);
3974 -- Check the specified expression Expr to make sure that it is a static
3975 -- expression of the given type (i.e. it will be analyzed and resolved
3976 -- using this type, which can be any valid argument to Resolve, e.g.
3977 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3978 -- Typ is left Empty, then any static expression is allowed. Includes
3979 -- checking that the expression does not raise Constraint_Error.
3981 procedure Check_First_Subtype (Arg : Node_Id);
3982 -- Checks that Arg, whose expression is an entity name, references a
3983 -- first subtype.
3985 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
3986 -- Checks that the given argument has an identifier, and if so, requires
3987 -- it to match the given identifier name. If there is no identifier, or
3988 -- a non-matching identifier, then an error message is given and
3989 -- Pragma_Exit is raised.
3991 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
3992 -- Checks that the given argument has an identifier, and if so, requires
3993 -- it to match one of the given identifier names. If there is no
3994 -- identifier, or a non-matching identifier, then an error message is
3995 -- given and Pragma_Exit is raised.
3997 procedure Check_In_Main_Program;
3998 -- Common checks for pragmas that appear within a main program
3999 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
4001 procedure Check_Interrupt_Or_Attach_Handler;
4002 -- Common processing for first argument of pragma Interrupt_Handler or
4003 -- pragma Attach_Handler.
4005 procedure Check_Loop_Pragma_Placement;
4006 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
4007 -- appear immediately within a construct restricted to loops, and that
4008 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
4010 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
4011 -- Check that pragma appears in a declarative part, or in a package
4012 -- specification, i.e. that it does not occur in a statement sequence
4013 -- in a body.
4015 procedure Check_No_Identifier (Arg : Node_Id);
4016 -- Checks that the given argument does not have an identifier. If
4017 -- an identifier is present, then an error message is issued, and
4018 -- Pragma_Exit is raised.
4020 procedure Check_No_Identifiers;
4021 -- Checks that none of the arguments to the pragma has an identifier.
4022 -- If any argument has an identifier, then an error message is issued,
4023 -- and Pragma_Exit is raised.
4025 procedure Check_No_Link_Name;
4026 -- Checks that no link name is specified
4028 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
4029 -- Checks if the given argument has an identifier, and if so, requires
4030 -- it to match the given identifier name. If there is a non-matching
4031 -- identifier, then an error message is given and Pragma_Exit is raised.
4033 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
4034 -- Checks if the given argument has an identifier, and if so, requires
4035 -- it to match the given identifier name. If there is a non-matching
4036 -- identifier, then an error message is given and Pragma_Exit is raised.
4037 -- In this version of the procedure, the identifier name is given as
4038 -- a string with lower case letters.
4040 procedure Check_Static_Boolean_Expression (Expr : Node_Id);
4041 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
4042 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
4043 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
4044 -- is an OK static boolean expression. Emit an error if this is not the
4045 -- case.
4047 procedure Check_Static_Constraint (Constr : Node_Id);
4048 -- Constr is a constraint from an N_Subtype_Indication node from a
4049 -- component constraint in an Unchecked_Union type. This routine checks
4050 -- that the constraint is static as required by the restrictions for
4051 -- Unchecked_Union.
4053 procedure Check_Valid_Configuration_Pragma;
4054 -- Legality checks for placement of a configuration pragma
4056 procedure Check_Valid_Library_Unit_Pragma;
4057 -- Legality checks for library unit pragmas. A special case arises for
4058 -- pragmas in generic instances that come from copies of the original
4059 -- library unit pragmas in the generic templates. In the case of other
4060 -- than library level instantiations these can appear in contexts which
4061 -- would normally be invalid (they only apply to the original template
4062 -- and to library level instantiations), and they are simply ignored,
4063 -- which is implemented by rewriting them as null statements.
4065 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
4066 -- Check an Unchecked_Union variant for lack of nested variants and
4067 -- presence of at least one component. UU_Typ is the related Unchecked_
4068 -- Union type.
4070 procedure Ensure_Aggregate_Form (Arg : Node_Id);
4071 -- Subsidiary routine to the processing of pragmas Abstract_State,
4072 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
4073 -- Refined_Global and Refined_State. Transform argument Arg into
4074 -- an aggregate if not one already. N_Null is never transformed.
4075 -- Arg may denote an aspect specification or a pragma argument
4076 -- association.
4078 procedure Error_Pragma (Msg : String);
4079 pragma No_Return (Error_Pragma);
4080 -- Outputs error message for current pragma. The message contains a %
4081 -- that will be replaced with the pragma name, and the flag is placed
4082 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
4083 -- calls Fix_Error (see spec of that procedure for details).
4085 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
4086 pragma No_Return (Error_Pragma_Arg);
4087 -- Outputs error message for current pragma. The message may contain
4088 -- a % that will be replaced with the pragma name. The parameter Arg
4089 -- may either be a pragma argument association, in which case the flag
4090 -- is placed on the expression of this association, or an expression,
4091 -- in which case the flag is placed directly on the expression. The
4092 -- message is placed using Error_Msg_N, so the message may also contain
4093 -- an & insertion character which will reference the given Arg value.
4094 -- After placing the message, Pragma_Exit is raised. Note: this routine
4095 -- calls Fix_Error (see spec of that procedure for details).
4097 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
4098 pragma No_Return (Error_Pragma_Arg);
4099 -- Similar to above form of Error_Pragma_Arg except that two messages
4100 -- are provided, the second is a continuation comment starting with \.
4102 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
4103 pragma No_Return (Error_Pragma_Arg_Ident);
4104 -- Outputs error message for current pragma. The message may contain a %
4105 -- that will be replaced with the pragma name. The parameter Arg must be
4106 -- a pragma argument association with a non-empty identifier (i.e. its
4107 -- Chars field must be set), and the error message is placed on the
4108 -- identifier. The message is placed using Error_Msg_N so the message
4109 -- may also contain an & insertion character which will reference
4110 -- the identifier. After placing the message, Pragma_Exit is raised.
4111 -- Note: this routine calls Fix_Error (see spec of that procedure for
4112 -- details).
4114 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
4115 pragma No_Return (Error_Pragma_Ref);
4116 -- Outputs error message for current pragma. The message may contain
4117 -- a % that will be replaced with the pragma name. The parameter Ref
4118 -- must be an entity whose name can be referenced by & and sloc by #.
4119 -- After placing the message, Pragma_Exit is raised. Note: this routine
4120 -- calls Fix_Error (see spec of that procedure for details).
4122 function Find_Lib_Unit_Name return Entity_Id;
4123 -- Used for a library unit pragma to find the entity to which the
4124 -- library unit pragma applies, returns the entity found.
4126 procedure Find_Program_Unit_Name (Id : Node_Id);
4127 -- If the pragma is a compilation unit pragma, the id must denote the
4128 -- compilation unit in the same compilation, and the pragma must appear
4129 -- in the list of preceding or trailing pragmas. If it is a program
4130 -- unit pragma that is not a compilation unit pragma, then the
4131 -- identifier must be visible.
4133 function Find_Unique_Parameterless_Procedure
4134 (Name : Entity_Id;
4135 Arg : Node_Id) return Entity_Id;
4136 -- Used for a procedure pragma to find the unique parameterless
4137 -- procedure identified by Name, returns it if it exists, otherwise
4138 -- errors out and uses Arg as the pragma argument for the message.
4140 function Fix_Error (Msg : String) return String;
4141 -- This is called prior to issuing an error message. Msg is the normal
4142 -- error message issued in the pragma case. This routine checks for the
4143 -- case of a pragma coming from an aspect in the source, and returns a
4144 -- message suitable for the aspect case as follows:
4146 -- Each substring "pragma" is replaced by "aspect"
4148 -- If "argument of" is at the start of the error message text, it is
4149 -- replaced by "entity for".
4151 -- If "argument" is at the start of the error message text, it is
4152 -- replaced by "entity".
4154 -- So for example, "argument of pragma X must be discrete type"
4155 -- returns "entity for aspect X must be a discrete type".
4157 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
4158 -- be different from the pragma name). If the current pragma results
4159 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
4160 -- original pragma name.
4162 procedure Gather_Associations
4163 (Names : Name_List;
4164 Args : out Args_List);
4165 -- This procedure is used to gather the arguments for a pragma that
4166 -- permits arbitrary ordering of parameters using the normal rules
4167 -- for named and positional parameters. The Names argument is a list
4168 -- of Name_Id values that corresponds to the allowed pragma argument
4169 -- association identifiers in order. The result returned in Args is
4170 -- a list of corresponding expressions that are the pragma arguments.
4171 -- Note that this is a list of expressions, not of pragma argument
4172 -- associations (Gather_Associations has completely checked all the
4173 -- optional identifiers when it returns). An entry in Args is Empty
4174 -- on return if the corresponding argument is not present.
4176 procedure GNAT_Pragma;
4177 -- Called for all GNAT defined pragmas to check the relevant restriction
4178 -- (No_Implementation_Pragmas).
4180 function Is_Before_First_Decl
4181 (Pragma_Node : Node_Id;
4182 Decls : List_Id) return Boolean;
4183 -- Return True if Pragma_Node is before the first declarative item in
4184 -- Decls where Decls is the list of declarative items.
4186 function Is_Configuration_Pragma return Boolean;
4187 -- Determines if the placement of the current pragma is appropriate
4188 -- for a configuration pragma.
4190 function Is_In_Context_Clause return Boolean;
4191 -- Returns True if pragma appears within the context clause of a unit,
4192 -- and False for any other placement (does not generate any messages).
4194 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
4195 -- Analyzes the argument, and determines if it is a static string
4196 -- expression, returns True if so, False if non-static or not String.
4197 -- A special case is that a string literal returns True in Ada 83 mode
4198 -- (which has no such thing as static string expressions). Note that
4199 -- the call analyzes its argument, so this cannot be used for the case
4200 -- where an identifier might not be declared.
4202 procedure Pragma_Misplaced;
4203 pragma No_Return (Pragma_Misplaced);
4204 -- Issue fatal error message for misplaced pragma
4206 procedure Process_Atomic_Independent_Shared_Volatile;
4207 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
4208 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
4209 -- and treated as being identical in effect to pragma Atomic.
4211 procedure Process_Compile_Time_Warning_Or_Error;
4212 -- Common processing for Compile_Time_Error and Compile_Time_Warning
4214 procedure Process_Convention
4215 (C : out Convention_Id;
4216 Ent : out Entity_Id);
4217 -- Common processing for Convention, Interface, Import and Export.
4218 -- Checks first two arguments of pragma, and sets the appropriate
4219 -- convention value in the specified entity or entities. On return
4220 -- C is the convention, Ent is the referenced entity.
4222 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
4223 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
4224 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
4226 procedure Process_Extended_Import_Export_Object_Pragma
4227 (Arg_Internal : Node_Id;
4228 Arg_External : Node_Id;
4229 Arg_Size : Node_Id);
4230 -- Common processing for the pragmas Import/Export_Object. The three
4231 -- arguments correspond to the three named parameters of the pragmas. An
4232 -- argument is empty if the corresponding parameter is not present in
4233 -- the pragma.
4235 procedure Process_Extended_Import_Export_Internal_Arg
4236 (Arg_Internal : Node_Id := Empty);
4237 -- Common processing for all extended Import and Export pragmas. The
4238 -- argument is the pragma parameter for the Internal argument. If
4239 -- Arg_Internal is empty or inappropriate, an error message is posted.
4240 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
4241 -- set to identify the referenced entity.
4243 procedure Process_Extended_Import_Export_Subprogram_Pragma
4244 (Arg_Internal : Node_Id;
4245 Arg_External : Node_Id;
4246 Arg_Parameter_Types : Node_Id;
4247 Arg_Result_Type : Node_Id := Empty;
4248 Arg_Mechanism : Node_Id;
4249 Arg_Result_Mechanism : Node_Id := Empty);
4250 -- Common processing for all extended Import and Export pragmas applying
4251 -- to subprograms. The caller omits any arguments that do not apply to
4252 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
4253 -- only in the Import_Function and Export_Function cases). The argument
4254 -- names correspond to the allowed pragma association identifiers.
4256 procedure Process_Generic_List;
4257 -- Common processing for Share_Generic and Inline_Generic
4259 procedure Process_Import_Or_Interface;
4260 -- Common processing for Import or Interface
4262 procedure Process_Import_Predefined_Type;
4263 -- Processing for completing a type with pragma Import. This is used
4264 -- to declare types that match predefined C types, especially for cases
4265 -- without corresponding Ada predefined type.
4267 type Inline_Status is (Suppressed, Disabled, Enabled);
4268 -- Inline status of a subprogram, indicated as follows:
4269 -- Suppressed: inlining is suppressed for the subprogram
4270 -- Disabled: no inlining is requested for the subprogram
4271 -- Enabled: inlining is requested/required for the subprogram
4273 procedure Process_Inline (Status : Inline_Status);
4274 -- Common processing for No_Inline, Inline and Inline_Always. Parameter
4275 -- indicates the inline status specified by the pragma.
4277 procedure Process_Interface_Name
4278 (Subprogram_Def : Entity_Id;
4279 Ext_Arg : Node_Id;
4280 Link_Arg : Node_Id;
4281 Prag : Node_Id);
4282 -- Given the last two arguments of pragma Import, pragma Export, or
4283 -- pragma Interface_Name, performs validity checks and sets the
4284 -- Interface_Name field of the given subprogram entity to the
4285 -- appropriate external or link name, depending on the arguments given.
4286 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
4287 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
4288 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
4289 -- nor Link_Arg is present, the interface name is set to the default
4290 -- from the subprogram name. In addition, the pragma itself is passed
4291 -- to analyze any expressions in the case the pragma came from an aspect
4292 -- specification.
4294 procedure Process_Interrupt_Or_Attach_Handler;
4295 -- Common processing for Interrupt and Attach_Handler pragmas
4297 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
4298 -- Common processing for Restrictions and Restriction_Warnings pragmas.
4299 -- Warn is True for Restriction_Warnings, or for Restrictions if the
4300 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
4301 -- is not set in the Restrictions case.
4303 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
4304 -- Common processing for Suppress and Unsuppress. The boolean parameter
4305 -- Suppress_Case is True for the Suppress case, and False for the
4306 -- Unsuppress case.
4308 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id);
4309 -- Subsidiary to the analysis of pragmas Independent[_Components].
4310 -- Record such a pragma N applied to entity E for future checks.
4312 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
4313 -- This procedure sets the Is_Exported flag for the given entity,
4314 -- checking that the entity was not previously imported. Arg is
4315 -- the argument that specified the entity. A check is also made
4316 -- for exporting inappropriate entities.
4318 procedure Set_Extended_Import_Export_External_Name
4319 (Internal_Ent : Entity_Id;
4320 Arg_External : Node_Id);
4321 -- Common processing for all extended import export pragmas. The first
4322 -- argument, Internal_Ent, is the internal entity, which has already
4323 -- been checked for validity by the caller. Arg_External is from the
4324 -- Import or Export pragma, and may be null if no External parameter
4325 -- was present. If Arg_External is present and is a non-null string
4326 -- (a null string is treated as the default), then the Interface_Name
4327 -- field of Internal_Ent is set appropriately.
4329 procedure Set_Imported (E : Entity_Id);
4330 -- This procedure sets the Is_Imported flag for the given entity,
4331 -- checking that it is not previously exported or imported.
4333 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
4334 -- Mech is a parameter passing mechanism (see Import_Function syntax
4335 -- for MECHANISM_NAME). This routine checks that the mechanism argument
4336 -- has the right form, and if not issues an error message. If the
4337 -- argument has the right form then the Mechanism field of Ent is
4338 -- set appropriately.
4340 procedure Set_Rational_Profile;
4341 -- Activate the set of configuration pragmas and permissions that make
4342 -- up the Rational profile.
4344 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id);
4345 -- Activate the set of configuration pragmas and restrictions that make
4346 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar,
4347 -- GNAT_Ravenscar_EDF, Jorvik, or Ravenscar. N is the corresponding
4348 -- pragma node, which is used for error messages on any constructs
4349 -- violating the profile.
4351 ---------------------
4352 -- Ada_2005_Pragma --
4353 ---------------------
4355 procedure Ada_2005_Pragma is
4356 begin
4357 if Ada_Version <= Ada_95 then
4358 Check_Restriction (No_Implementation_Pragmas, N);
4359 end if;
4360 end Ada_2005_Pragma;
4362 ---------------------
4363 -- Ada_2012_Pragma --
4364 ---------------------
4366 procedure Ada_2012_Pragma is
4367 begin
4368 if Ada_Version <= Ada_2005 then
4369 Check_Restriction (No_Implementation_Pragmas, N);
4370 end if;
4371 end Ada_2012_Pragma;
4373 ----------------------------
4374 -- Analyze_Depends_Global --
4375 ----------------------------
4377 procedure Analyze_Depends_Global
4378 (Spec_Id : out Entity_Id;
4379 Subp_Decl : out Node_Id;
4380 Legal : out Boolean)
4382 begin
4383 -- Assume that the pragma is illegal
4385 Spec_Id := Empty;
4386 Subp_Decl := Empty;
4387 Legal := False;
4389 GNAT_Pragma;
4390 Check_Arg_Count (1);
4392 -- Ensure the proper placement of the pragma. Depends/Global must be
4393 -- associated with a subprogram declaration or a body that acts as a
4394 -- spec.
4396 Subp_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4398 -- Entry
4400 if Nkind (Subp_Decl) = N_Entry_Declaration then
4401 null;
4403 -- Generic subprogram
4405 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4406 null;
4408 -- Object declaration of a single concurrent type
4410 elsif Nkind (Subp_Decl) = N_Object_Declaration
4411 and then Is_Single_Concurrent_Object
4412 (Unique_Defining_Entity (Subp_Decl))
4413 then
4414 null;
4416 -- Single task type
4418 elsif Nkind (Subp_Decl) = N_Single_Task_Declaration then
4419 null;
4421 -- Subprogram body acts as spec
4423 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4424 and then No (Corresponding_Spec (Subp_Decl))
4425 then
4426 null;
4428 -- Subprogram body stub acts as spec
4430 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4431 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
4432 then
4433 null;
4435 -- Subprogram declaration
4437 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4438 null;
4440 -- Task type
4442 elsif Nkind (Subp_Decl) = N_Task_Type_Declaration then
4443 null;
4445 else
4446 Pragma_Misplaced;
4447 return;
4448 end if;
4450 -- If we get here, then the pragma is legal
4452 Legal := True;
4453 Spec_Id := Unique_Defining_Entity (Subp_Decl);
4455 -- When the related context is an entry, the entry must belong to a
4456 -- protected unit (SPARK RM 6.1.4(6)).
4458 if Is_Entry_Declaration (Spec_Id)
4459 and then Ekind (Scope (Spec_Id)) /= E_Protected_Type
4460 then
4461 Pragma_Misplaced;
4462 return;
4464 -- When the related context is an anonymous object created for a
4465 -- simple concurrent type, the type must be a task
4466 -- (SPARK RM 6.1.4(6)).
4468 elsif Is_Single_Concurrent_Object (Spec_Id)
4469 and then Ekind (Etype (Spec_Id)) /= E_Task_Type
4470 then
4471 Pragma_Misplaced;
4472 return;
4473 end if;
4475 -- A pragma that applies to a Ghost entity becomes Ghost for the
4476 -- purposes of legality checks and removal of ignored Ghost code.
4478 Mark_Ghost_Pragma (N, Spec_Id);
4479 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4480 end Analyze_Depends_Global;
4482 ------------------------
4483 -- Analyze_If_Present --
4484 ------------------------
4486 procedure Analyze_If_Present (Id : Pragma_Id) is
4487 Stmt : Node_Id;
4489 begin
4490 pragma Assert (Is_List_Member (N));
4492 -- Inspect the declarations or statements following pragma N looking
4493 -- for another pragma whose Id matches the caller's request. If it is
4494 -- available, analyze it.
4496 Stmt := Next (N);
4497 while Present (Stmt) loop
4498 if Nkind (Stmt) = N_Pragma and then Get_Pragma_Id (Stmt) = Id then
4499 Analyze_Pragma (Stmt);
4500 exit;
4502 -- The first source declaration or statement immediately following
4503 -- N ends the region where a pragma may appear.
4505 elsif Comes_From_Source (Stmt) then
4506 exit;
4507 end if;
4509 Next (Stmt);
4510 end loop;
4511 end Analyze_If_Present;
4513 --------------------------------
4514 -- Analyze_Pre_Post_Condition --
4515 --------------------------------
4517 procedure Analyze_Pre_Post_Condition is
4518 Prag_Iden : constant Node_Id := Pragma_Identifier (N);
4519 Subp_Decl : Node_Id;
4520 Subp_Id : Entity_Id;
4522 Duplicates_OK : Boolean := False;
4523 -- Flag set when a pre/postcondition allows multiple pragmas of the
4524 -- same kind.
4526 In_Body_OK : Boolean := False;
4527 -- Flag set when a pre/postcondition is allowed to appear on a body
4528 -- even though the subprogram may have a spec.
4530 Is_Pre_Post : Boolean := False;
4531 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4532 -- Post_Class.
4534 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean;
4535 -- Implement rules in AI12-0131: an overriding operation can have
4536 -- a class-wide precondition only if one of its ancestors has an
4537 -- explicit class-wide precondition.
4539 -----------------------------
4540 -- Inherits_Class_Wide_Pre --
4541 -----------------------------
4543 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean is
4544 Typ : constant Entity_Id := Find_Dispatching_Type (E);
4545 Cont : Node_Id;
4546 Prag : Node_Id;
4547 Prev : Entity_Id := Overridden_Operation (E);
4549 begin
4550 -- Check ancestors on the overriding operation to examine the
4551 -- preconditions that may apply to them.
4553 while Present (Prev) loop
4554 Cont := Contract (Prev);
4555 if Present (Cont) then
4556 Prag := Pre_Post_Conditions (Cont);
4557 while Present (Prag) loop
4558 if Pragma_Name (Prag) = Name_Precondition
4559 and then Class_Present (Prag)
4560 then
4561 return True;
4562 end if;
4564 Prag := Next_Pragma (Prag);
4565 end loop;
4566 end if;
4568 -- For a type derived from a generic formal type, the operation
4569 -- inheriting the condition is a renaming, not an overriding of
4570 -- the operation of the formal. Ditto for an inherited
4571 -- operation which has no explicit contracts.
4573 if Is_Generic_Type (Find_Dispatching_Type (Prev))
4574 or else not Comes_From_Source (Prev)
4575 then
4576 Prev := Alias (Prev);
4577 else
4578 Prev := Overridden_Operation (Prev);
4579 end if;
4580 end loop;
4582 -- If the controlling type of the subprogram has progenitors, an
4583 -- interface operation implemented by the current operation may
4584 -- have a class-wide precondition.
4586 if Has_Interfaces (Typ) then
4587 declare
4588 Elmt : Elmt_Id;
4589 Ints : Elist_Id;
4590 Prim : Entity_Id;
4591 Prim_Elmt : Elmt_Id;
4592 Prim_List : Elist_Id;
4594 begin
4595 Collect_Interfaces (Typ, Ints);
4596 Elmt := First_Elmt (Ints);
4598 -- Iterate over the primitive operations of each interface
4600 while Present (Elmt) loop
4601 Prim_List := Direct_Primitive_Operations (Node (Elmt));
4602 Prim_Elmt := First_Elmt (Prim_List);
4603 while Present (Prim_Elmt) loop
4604 Prim := Node (Prim_Elmt);
4605 if Chars (Prim) = Chars (E)
4606 and then Present (Contract (Prim))
4607 and then Class_Present
4608 (Pre_Post_Conditions (Contract (Prim)))
4609 then
4610 return True;
4611 end if;
4613 Next_Elmt (Prim_Elmt);
4614 end loop;
4616 Next_Elmt (Elmt);
4617 end loop;
4618 end;
4619 end if;
4621 return False;
4622 end Inherits_Class_Wide_Pre;
4624 -- Start of processing for Analyze_Pre_Post_Condition
4626 begin
4627 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4628 -- offer uniformity among the various kinds of pre/postconditions by
4629 -- rewriting the pragma identifier. This allows the retrieval of the
4630 -- original pragma name by routine Original_Aspect_Pragma_Name.
4632 if Comes_From_Source (N) then
4633 if Pname in Name_Pre | Name_Pre_Class then
4634 Is_Pre_Post := True;
4635 Set_Class_Present (N, Pname = Name_Pre_Class);
4636 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition));
4638 elsif Pname in Name_Post | Name_Post_Class then
4639 Is_Pre_Post := True;
4640 Set_Class_Present (N, Pname = Name_Post_Class);
4641 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition));
4642 end if;
4643 end if;
4645 -- Determine the semantics with respect to duplicates and placement
4646 -- in a body. Pragmas Precondition and Postcondition were introduced
4647 -- before aspects and are not subject to the same aspect-like rules.
4649 if Pname in Name_Precondition | Name_Postcondition then
4650 Duplicates_OK := True;
4651 In_Body_OK := True;
4652 end if;
4654 GNAT_Pragma;
4656 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4657 -- argument without an identifier.
4659 if Is_Pre_Post then
4660 Check_Arg_Count (1);
4661 Check_No_Identifiers;
4663 -- Pragmas Precondition and Postcondition have complex argument
4664 -- profile.
4666 else
4667 Check_At_Least_N_Arguments (1);
4668 Check_At_Most_N_Arguments (2);
4669 Check_Optional_Identifier (Arg1, Name_Check);
4671 if Present (Arg2) then
4672 Check_Optional_Identifier (Arg2, Name_Message);
4673 Preanalyze_Spec_Expression
4674 (Get_Pragma_Arg (Arg2), Standard_String);
4675 end if;
4676 end if;
4678 -- For a pragma PPC in the extended main source unit, record enabled
4679 -- status in SCO.
4680 -- ??? nothing checks that the pragma is in the main source unit
4682 if Is_Checked (N) and then not Split_PPC (N) then
4683 Set_SCO_Pragma_Enabled (Loc);
4684 end if;
4686 -- Ensure the proper placement of the pragma
4688 Subp_Decl :=
4689 Find_Related_Declaration_Or_Body
4690 (N, Do_Checks => not Duplicates_OK);
4692 -- When a pre/postcondition pragma applies to an abstract subprogram,
4693 -- its original form must be an aspect with 'Class.
4695 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
4696 if not From_Aspect_Specification (N) then
4697 Error_Pragma
4698 ("pragma % cannot be applied to abstract subprogram");
4700 elsif not Class_Present (N) then
4701 Error_Pragma
4702 ("aspect % requires ''Class for abstract subprogram");
4703 end if;
4705 -- Entry declaration
4707 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
4708 null;
4710 -- Generic subprogram declaration
4712 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4713 null;
4715 -- Subprogram body
4717 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4718 and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK)
4719 then
4720 null;
4722 -- Subprogram body stub
4724 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4725 and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK)
4726 then
4727 null;
4729 -- Subprogram declaration
4731 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4733 -- AI05-0230: When a pre/postcondition pragma applies to a null
4734 -- procedure, its original form must be an aspect with 'Class.
4736 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
4737 and then Null_Present (Specification (Subp_Decl))
4738 and then From_Aspect_Specification (N)
4739 and then not Class_Present (N)
4740 then
4741 Error_Pragma ("aspect % requires ''Class for null procedure");
4742 end if;
4744 -- Implement the legality checks mandated by AI12-0131:
4745 -- Pre'Class shall not be specified for an overriding primitive
4746 -- subprogram of a tagged type T unless the Pre'Class aspect is
4747 -- specified for the corresponding primitive subprogram of some
4748 -- ancestor of T.
4750 declare
4751 E : constant Entity_Id := Defining_Entity (Subp_Decl);
4753 begin
4754 if Class_Present (N)
4755 and then Pragma_Name (N) = Name_Precondition
4756 and then Present (Overridden_Operation (E))
4757 and then not Inherits_Class_Wide_Pre (E)
4758 then
4759 Error_Msg_N
4760 ("illegal class-wide precondition on overriding operation",
4761 Corresponding_Aspect (N));
4762 end if;
4763 end;
4765 -- A renaming declaration may inherit a generated pragma, its
4766 -- placement comes from expansion, not from source.
4768 elsif Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration
4769 and then not Comes_From_Source (N)
4770 then
4771 null;
4773 -- For Ada 2020, pre/postconditions can appear on formal subprograms
4775 elsif Nkind (Subp_Decl) = N_Formal_Concrete_Subprogram_Declaration
4776 and then Ada_Version >= Ada_2020
4777 then
4778 null;
4780 -- An access-to-subprogram type can have pre/postconditions, but
4781 -- these are transferred to the generated subprogram wrapper and
4782 -- analyzed there.
4784 -- Otherwise the placement of the pragma is illegal
4786 else
4787 Pragma_Misplaced;
4788 return;
4789 end if;
4791 Subp_Id := Defining_Entity (Subp_Decl);
4793 -- A pragma that applies to a Ghost entity becomes Ghost for the
4794 -- purposes of legality checks and removal of ignored Ghost code.
4796 Mark_Ghost_Pragma (N, Subp_Id);
4798 -- Chain the pragma on the contract for further processing by
4799 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4801 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
4803 -- Fully analyze the pragma when it appears inside an entry or
4804 -- subprogram body because it cannot benefit from forward references.
4806 if Nkind (Subp_Decl) in N_Entry_Body
4807 | N_Subprogram_Body
4808 | N_Subprogram_Body_Stub
4809 then
4810 -- The legality checks of pragmas Precondition and Postcondition
4811 -- are affected by the SPARK mode in effect and the volatility of
4812 -- the context. Analyze all pragmas in a specific order.
4814 Analyze_If_Present (Pragma_SPARK_Mode);
4815 Analyze_If_Present (Pragma_Volatile_Function);
4816 Analyze_Pre_Post_Condition_In_Decl_Part (N);
4817 end if;
4818 end Analyze_Pre_Post_Condition;
4820 -----------------------------------------
4821 -- Analyze_Refined_Depends_Global_Post --
4822 -----------------------------------------
4824 procedure Analyze_Refined_Depends_Global_Post
4825 (Spec_Id : out Entity_Id;
4826 Body_Id : out Entity_Id;
4827 Legal : out Boolean)
4829 Body_Decl : Node_Id;
4830 Spec_Decl : Node_Id;
4832 begin
4833 -- Assume that the pragma is illegal
4835 Spec_Id := Empty;
4836 Body_Id := Empty;
4837 Legal := False;
4839 GNAT_Pragma;
4840 Check_Arg_Count (1);
4841 Check_No_Identifiers;
4843 -- Verify the placement of the pragma and check for duplicates. The
4844 -- pragma must apply to a subprogram body [stub].
4846 Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4848 if Nkind (Body_Decl) not in
4849 N_Entry_Body | N_Subprogram_Body | N_Subprogram_Body_Stub |
4850 N_Task_Body | N_Task_Body_Stub
4851 then
4852 Pragma_Misplaced;
4853 return;
4854 end if;
4856 Body_Id := Defining_Entity (Body_Decl);
4857 Spec_Id := Unique_Defining_Entity (Body_Decl);
4859 -- The pragma must apply to the second declaration of a subprogram.
4860 -- In other words, the body [stub] cannot acts as a spec.
4862 if No (Spec_Id) then
4863 Error_Pragma ("pragma % cannot apply to a stand alone body");
4864 return;
4866 -- Catch the case where the subprogram body is a subunit and acts as
4867 -- the third declaration of the subprogram.
4869 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
4870 Error_Pragma ("pragma % cannot apply to a subunit");
4871 return;
4872 end if;
4874 -- A refined pragma can only apply to the body [stub] of a subprogram
4875 -- declared in the visible part of a package. Retrieve the context of
4876 -- the subprogram declaration.
4878 Spec_Decl := Unit_Declaration_Node (Spec_Id);
4880 -- When dealing with protected entries or protected subprograms, use
4881 -- the enclosing protected type as the proper context.
4883 if Ekind (Spec_Id) in E_Entry
4884 | E_Entry_Family
4885 | E_Function
4886 | E_Procedure
4887 and then Ekind (Scope (Spec_Id)) = E_Protected_Type
4888 then
4889 Spec_Decl := Declaration_Node (Scope (Spec_Id));
4890 end if;
4892 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
4893 Error_Pragma
4894 (Fix_Msg (Spec_Id, "pragma % must apply to the body of "
4895 & "subprogram declared in a package specification"));
4896 return;
4897 end if;
4899 -- If we get here, then the pragma is legal
4901 Legal := True;
4903 -- A pragma that applies to a Ghost entity becomes Ghost for the
4904 -- purposes of legality checks and removal of ignored Ghost code.
4906 Mark_Ghost_Pragma (N, Spec_Id);
4908 if Pname in Name_Refined_Depends | Name_Refined_Global then
4909 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4910 end if;
4911 end Analyze_Refined_Depends_Global_Post;
4913 ----------------------------------
4914 -- Analyze_Unmodified_Or_Unused --
4915 ----------------------------------
4917 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False) is
4918 Arg : Node_Id;
4919 Arg_Expr : Node_Id;
4920 Arg_Id : Entity_Id;
4922 Ghost_Error_Posted : Boolean := False;
4923 -- Flag set when an error concerning the illegal mix of Ghost and
4924 -- non-Ghost variables is emitted.
4926 Ghost_Id : Entity_Id := Empty;
4927 -- The entity of the first Ghost variable encountered while
4928 -- processing the arguments of the pragma.
4930 begin
4931 GNAT_Pragma;
4932 Check_At_Least_N_Arguments (1);
4934 -- Loop through arguments
4936 Arg := Arg1;
4937 while Present (Arg) loop
4938 Check_No_Identifier (Arg);
4940 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4941 -- in fact generate reference, so that the entity will have a
4942 -- reference, which will inhibit any warnings about it not
4943 -- being referenced, and also properly show up in the ali file
4944 -- as a reference. But this reference is recorded before the
4945 -- Has_Pragma_Unreferenced flag is set, so that no warning is
4946 -- generated for this reference.
4948 Check_Arg_Is_Local_Name (Arg);
4949 Arg_Expr := Get_Pragma_Arg (Arg);
4951 if Is_Entity_Name (Arg_Expr) then
4952 Arg_Id := Entity (Arg_Expr);
4954 -- Skip processing the argument if already flagged
4956 if Is_Assignable (Arg_Id)
4957 and then not Has_Pragma_Unmodified (Arg_Id)
4958 and then not Has_Pragma_Unused (Arg_Id)
4959 then
4960 Set_Has_Pragma_Unmodified (Arg_Id);
4962 if Is_Unused then
4963 Set_Has_Pragma_Unused (Arg_Id);
4964 end if;
4966 -- A pragma that applies to a Ghost entity becomes Ghost for
4967 -- the purposes of legality checks and removal of ignored
4968 -- Ghost code.
4970 Mark_Ghost_Pragma (N, Arg_Id);
4972 -- Capture the entity of the first Ghost variable being
4973 -- processed for error detection purposes.
4975 if Is_Ghost_Entity (Arg_Id) then
4976 if No (Ghost_Id) then
4977 Ghost_Id := Arg_Id;
4978 end if;
4980 -- Otherwise the variable is non-Ghost. It is illegal to mix
4981 -- references to Ghost and non-Ghost entities
4982 -- (SPARK RM 6.9).
4984 elsif Present (Ghost_Id)
4985 and then not Ghost_Error_Posted
4986 then
4987 Ghost_Error_Posted := True;
4989 Error_Msg_Name_1 := Pname;
4990 Error_Msg_N
4991 ("pragma % cannot mention ghost and non-ghost "
4992 & "variables", N);
4994 Error_Msg_Sloc := Sloc (Ghost_Id);
4995 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
4997 Error_Msg_Sloc := Sloc (Arg_Id);
4998 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
4999 end if;
5001 -- Warn if already flagged as Unused or Unmodified
5003 elsif Has_Pragma_Unmodified (Arg_Id) then
5004 if Has_Pragma_Unused (Arg_Id) then
5005 Error_Msg_NE
5006 ("??pragma Unused already given for &!", Arg_Expr,
5007 Arg_Id);
5008 else
5009 Error_Msg_NE
5010 ("??pragma Unmodified already given for &!", Arg_Expr,
5011 Arg_Id);
5012 end if;
5014 -- Otherwise the pragma referenced an illegal entity
5016 else
5017 Error_Pragma_Arg
5018 ("pragma% can only be applied to a variable", Arg_Expr);
5019 end if;
5020 end if;
5022 Next (Arg);
5023 end loop;
5024 end Analyze_Unmodified_Or_Unused;
5026 ------------------------------------
5027 -- Analyze_Unreferenced_Or_Unused --
5028 ------------------------------------
5030 procedure Analyze_Unreferenced_Or_Unused
5031 (Is_Unused : Boolean := False)
5033 Arg : Node_Id;
5034 Arg_Expr : Node_Id;
5035 Arg_Id : Entity_Id;
5036 Citem : Node_Id;
5038 Ghost_Error_Posted : Boolean := False;
5039 -- Flag set when an error concerning the illegal mix of Ghost and
5040 -- non-Ghost names is emitted.
5042 Ghost_Id : Entity_Id := Empty;
5043 -- The entity of the first Ghost name encountered while processing
5044 -- the arguments of the pragma.
5046 begin
5047 GNAT_Pragma;
5048 Check_At_Least_N_Arguments (1);
5050 -- Check case of appearing within context clause
5052 if not Is_Unused and then Is_In_Context_Clause then
5054 -- The arguments must all be units mentioned in a with clause in
5055 -- the same context clause. Note that Par.Prag already checked
5056 -- that the arguments are either identifiers or selected
5057 -- components.
5059 Arg := Arg1;
5060 while Present (Arg) loop
5061 Citem := First (List_Containing (N));
5062 while Citem /= N loop
5063 Arg_Expr := Get_Pragma_Arg (Arg);
5065 if Nkind (Citem) = N_With_Clause
5066 and then Same_Name (Name (Citem), Arg_Expr)
5067 then
5068 Set_Has_Pragma_Unreferenced
5069 (Cunit_Entity
5070 (Get_Source_Unit
5071 (Library_Unit (Citem))));
5072 Set_Elab_Unit_Name (Arg_Expr, Name (Citem));
5073 exit;
5074 end if;
5076 Next (Citem);
5077 end loop;
5079 if Citem = N then
5080 Error_Pragma_Arg
5081 ("argument of pragma% is not withed unit", Arg);
5082 end if;
5084 Next (Arg);
5085 end loop;
5087 -- Case of not in list of context items
5089 else
5090 Arg := Arg1;
5091 while Present (Arg) loop
5092 Check_No_Identifier (Arg);
5094 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
5095 -- in fact generate reference, so that the entity will have a
5096 -- reference, which will inhibit any warnings about it not
5097 -- being referenced, and also properly show up in the ali file
5098 -- as a reference. But this reference is recorded before the
5099 -- Has_Pragma_Unreferenced flag is set, so that no warning is
5100 -- generated for this reference.
5102 Check_Arg_Is_Local_Name (Arg);
5103 Arg_Expr := Get_Pragma_Arg (Arg);
5105 if Is_Entity_Name (Arg_Expr) then
5106 Arg_Id := Entity (Arg_Expr);
5108 -- Warn if already flagged as Unused or Unreferenced and
5109 -- skip processing the argument.
5111 if Has_Pragma_Unreferenced (Arg_Id) then
5112 if Has_Pragma_Unused (Arg_Id) then
5113 Error_Msg_NE
5114 ("??pragma Unused already given for &!", Arg_Expr,
5115 Arg_Id);
5116 else
5117 Error_Msg_NE
5118 ("??pragma Unreferenced already given for &!",
5119 Arg_Expr, Arg_Id);
5120 end if;
5122 -- Apply Unreferenced to the entity
5124 else
5125 -- If the entity is overloaded, the pragma applies to the
5126 -- most recent overloading, as documented. In this case,
5127 -- name resolution does not generate a reference, so it
5128 -- must be done here explicitly.
5130 if Is_Overloaded (Arg_Expr) then
5131 Generate_Reference (Arg_Id, N);
5132 end if;
5134 Set_Has_Pragma_Unreferenced (Arg_Id);
5136 if Is_Unused then
5137 Set_Has_Pragma_Unused (Arg_Id);
5138 end if;
5140 -- A pragma that applies to a Ghost entity becomes Ghost
5141 -- for the purposes of legality checks and removal of
5142 -- ignored Ghost code.
5144 Mark_Ghost_Pragma (N, Arg_Id);
5146 -- Capture the entity of the first Ghost name being
5147 -- processed for error detection purposes.
5149 if Is_Ghost_Entity (Arg_Id) then
5150 if No (Ghost_Id) then
5151 Ghost_Id := Arg_Id;
5152 end if;
5154 -- Otherwise the name is non-Ghost. It is illegal to mix
5155 -- references to Ghost and non-Ghost entities
5156 -- (SPARK RM 6.9).
5158 elsif Present (Ghost_Id)
5159 and then not Ghost_Error_Posted
5160 then
5161 Ghost_Error_Posted := True;
5163 Error_Msg_Name_1 := Pname;
5164 Error_Msg_N
5165 ("pragma % cannot mention ghost and non-ghost "
5166 & "names", N);
5168 Error_Msg_Sloc := Sloc (Ghost_Id);
5169 Error_Msg_NE
5170 ("\& # declared as ghost", N, Ghost_Id);
5172 Error_Msg_Sloc := Sloc (Arg_Id);
5173 Error_Msg_NE
5174 ("\& # declared as non-ghost", N, Arg_Id);
5175 end if;
5176 end if;
5177 end if;
5179 Next (Arg);
5180 end loop;
5181 end if;
5182 end Analyze_Unreferenced_Or_Unused;
5184 --------------------------
5185 -- Check_Ada_83_Warning --
5186 --------------------------
5188 procedure Check_Ada_83_Warning is
5189 begin
5190 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5191 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
5192 end if;
5193 end Check_Ada_83_Warning;
5195 ---------------------
5196 -- Check_Arg_Count --
5197 ---------------------
5199 procedure Check_Arg_Count (Required : Nat) is
5200 begin
5201 if Arg_Count /= Required then
5202 Error_Pragma ("wrong number of arguments for pragma%");
5203 end if;
5204 end Check_Arg_Count;
5206 --------------------------------
5207 -- Check_Arg_Is_External_Name --
5208 --------------------------------
5210 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
5211 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5213 begin
5214 if Nkind (Argx) = N_Identifier then
5215 return;
5217 else
5218 Analyze_And_Resolve (Argx, Standard_String);
5220 if Is_OK_Static_Expression (Argx) then
5221 return;
5223 elsif Etype (Argx) = Any_Type then
5224 raise Pragma_Exit;
5226 -- An interesting special case, if we have a string literal and
5227 -- we are in Ada 83 mode, then we allow it even though it will
5228 -- not be flagged as static. This allows expected Ada 83 mode
5229 -- use of external names which are string literals, even though
5230 -- technically these are not static in Ada 83.
5232 elsif Ada_Version = Ada_83
5233 and then Nkind (Argx) = N_String_Literal
5234 then
5235 return;
5237 -- Here we have a real error (non-static expression)
5239 else
5240 Error_Msg_Name_1 := Pname;
5241 Flag_Non_Static_Expr
5242 (Fix_Error ("argument for pragma% must be a identifier or "
5243 & "static string expression!"), Argx);
5245 raise Pragma_Exit;
5246 end if;
5247 end if;
5248 end Check_Arg_Is_External_Name;
5250 -----------------------------
5251 -- Check_Arg_Is_Identifier --
5252 -----------------------------
5254 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
5255 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5256 begin
5257 if Nkind (Argx) /= N_Identifier then
5258 Error_Pragma_Arg ("argument for pragma% must be identifier", Argx);
5259 end if;
5260 end Check_Arg_Is_Identifier;
5262 ----------------------------------
5263 -- Check_Arg_Is_Integer_Literal --
5264 ----------------------------------
5266 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
5267 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5268 begin
5269 if Nkind (Argx) /= N_Integer_Literal then
5270 Error_Pragma_Arg
5271 ("argument for pragma% must be integer literal", Argx);
5272 end if;
5273 end Check_Arg_Is_Integer_Literal;
5275 -------------------------------------------
5276 -- Check_Arg_Is_Library_Level_Local_Name --
5277 -------------------------------------------
5279 -- LOCAL_NAME ::=
5280 -- DIRECT_NAME
5281 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5282 -- | library_unit_NAME
5284 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
5285 begin
5286 Check_Arg_Is_Local_Name (Arg);
5288 -- If it came from an aspect, we want to give the error just as if it
5289 -- came from source.
5291 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
5292 and then (Comes_From_Source (N)
5293 or else Present (Corresponding_Aspect (Parent (Arg))))
5294 then
5295 Error_Pragma_Arg
5296 ("argument for pragma% must be library level entity", Arg);
5297 end if;
5298 end Check_Arg_Is_Library_Level_Local_Name;
5300 -----------------------------
5301 -- Check_Arg_Is_Local_Name --
5302 -----------------------------
5304 -- LOCAL_NAME ::=
5305 -- DIRECT_NAME
5306 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5307 -- | library_unit_NAME
5309 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
5310 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5312 begin
5313 -- If this pragma came from an aspect specification, we don't want to
5314 -- check for this error, because that would cause spurious errors, in
5315 -- case a type is frozen in a scope more nested than the type. The
5316 -- aspect itself of course can't be anywhere but on the declaration
5317 -- itself.
5319 if Nkind (Arg) = N_Pragma_Argument_Association then
5320 if From_Aspect_Specification (Parent (Arg)) then
5321 return;
5322 end if;
5324 -- Arg is the Expression of an N_Pragma_Argument_Association
5326 else
5327 if From_Aspect_Specification (Parent (Parent (Arg))) then
5328 return;
5329 end if;
5330 end if;
5332 Analyze (Argx);
5334 if Nkind (Argx) not in N_Direct_Name
5335 and then (Nkind (Argx) /= N_Attribute_Reference
5336 or else Present (Expressions (Argx))
5337 or else Nkind (Prefix (Argx)) /= N_Identifier)
5338 and then (not Is_Entity_Name (Argx)
5339 or else not Is_Compilation_Unit (Entity (Argx)))
5340 then
5341 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
5342 end if;
5344 -- No further check required if not an entity name
5346 if not Is_Entity_Name (Argx) then
5347 null;
5349 else
5350 declare
5351 OK : Boolean;
5352 Ent : constant Entity_Id := Entity (Argx);
5353 Scop : constant Entity_Id := Scope (Ent);
5355 begin
5356 -- Case of a pragma applied to a compilation unit: pragma must
5357 -- occur immediately after the program unit in the compilation.
5359 if Is_Compilation_Unit (Ent) then
5360 declare
5361 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
5363 begin
5364 -- Case of pragma placed immediately after spec
5366 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
5367 OK := True;
5369 -- Case of pragma placed immediately after body
5371 elsif Nkind (Decl) = N_Subprogram_Declaration
5372 and then Present (Corresponding_Body (Decl))
5373 then
5374 OK := Parent (N) =
5375 Aux_Decls_Node
5376 (Parent (Unit_Declaration_Node
5377 (Corresponding_Body (Decl))));
5379 -- All other cases are illegal
5381 else
5382 OK := False;
5383 end if;
5384 end;
5386 -- Special restricted placement rule from 10.2.1(11.8/2)
5388 elsif Is_Generic_Formal (Ent)
5389 and then Prag_Id = Pragma_Preelaborable_Initialization
5390 then
5391 OK := List_Containing (N) =
5392 Generic_Formal_Declarations
5393 (Unit_Declaration_Node (Scop));
5395 -- If this is an aspect applied to a subprogram body, the
5396 -- pragma is inserted in its declarative part.
5398 elsif From_Aspect_Specification (N)
5399 and then Ent = Current_Scope
5400 and then
5401 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
5402 then
5403 OK := True;
5405 -- If the aspect is a predicate (possibly others ???) and the
5406 -- context is a record type, this is a discriminant expression
5407 -- within a type declaration, that freezes the predicated
5408 -- subtype.
5410 elsif From_Aspect_Specification (N)
5411 and then Prag_Id = Pragma_Predicate
5412 and then Ekind (Current_Scope) = E_Record_Type
5413 and then Scop = Scope (Current_Scope)
5414 then
5415 OK := True;
5417 -- Default case, just check that the pragma occurs in the scope
5418 -- of the entity denoted by the name.
5420 else
5421 OK := Current_Scope = Scop;
5422 end if;
5424 if not OK then
5425 Error_Pragma_Arg
5426 ("pragma% argument must be in same declarative part", Arg);
5427 end if;
5428 end;
5429 end if;
5430 end Check_Arg_Is_Local_Name;
5432 ---------------------------------
5433 -- Check_Arg_Is_Locking_Policy --
5434 ---------------------------------
5436 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
5437 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5439 begin
5440 Check_Arg_Is_Identifier (Argx);
5442 if not Is_Locking_Policy_Name (Chars (Argx)) then
5443 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
5444 end if;
5445 end Check_Arg_Is_Locking_Policy;
5447 -----------------------------------------------
5448 -- Check_Arg_Is_Partition_Elaboration_Policy --
5449 -----------------------------------------------
5451 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
5452 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5454 begin
5455 Check_Arg_Is_Identifier (Argx);
5457 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
5458 Error_Pragma_Arg
5459 ("& is not a valid partition elaboration policy name", Argx);
5460 end if;
5461 end Check_Arg_Is_Partition_Elaboration_Policy;
5463 -------------------------
5464 -- Check_Arg_Is_One_Of --
5465 -------------------------
5467 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5468 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5470 begin
5471 Check_Arg_Is_Identifier (Argx);
5473 if Chars (Argx) not in N1 | N2 then
5474 Error_Msg_Name_2 := N1;
5475 Error_Msg_Name_3 := N2;
5476 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
5477 end if;
5478 end Check_Arg_Is_One_Of;
5480 procedure Check_Arg_Is_One_Of
5481 (Arg : Node_Id;
5482 N1, N2, N3 : Name_Id)
5484 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5486 begin
5487 Check_Arg_Is_Identifier (Argx);
5489 if Chars (Argx) not in N1 | N2 | N3 then
5490 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5491 end if;
5492 end Check_Arg_Is_One_Of;
5494 procedure Check_Arg_Is_One_Of
5495 (Arg : Node_Id;
5496 N1, N2, N3, N4 : Name_Id)
5498 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5500 begin
5501 Check_Arg_Is_Identifier (Argx);
5503 if Chars (Argx) not in N1 | N2 | N3 | N4 then
5504 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5505 end if;
5506 end Check_Arg_Is_One_Of;
5508 procedure Check_Arg_Is_One_Of
5509 (Arg : Node_Id;
5510 N1, N2, N3, N4, N5 : Name_Id)
5512 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5514 begin
5515 Check_Arg_Is_Identifier (Argx);
5517 if Chars (Argx) not in N1 | N2 | N3 | N4 | N5 then
5518 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5519 end if;
5520 end Check_Arg_Is_One_Of;
5522 ---------------------------------
5523 -- Check_Arg_Is_Queuing_Policy --
5524 ---------------------------------
5526 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
5527 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5529 begin
5530 Check_Arg_Is_Identifier (Argx);
5532 if not Is_Queuing_Policy_Name (Chars (Argx)) then
5533 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
5534 end if;
5535 end Check_Arg_Is_Queuing_Policy;
5537 ---------------------------------------
5538 -- Check_Arg_Is_OK_Static_Expression --
5539 ---------------------------------------
5541 procedure Check_Arg_Is_OK_Static_Expression
5542 (Arg : Node_Id;
5543 Typ : Entity_Id := Empty)
5545 begin
5546 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
5547 end Check_Arg_Is_OK_Static_Expression;
5549 ------------------------------------------
5550 -- Check_Arg_Is_Task_Dispatching_Policy --
5551 ------------------------------------------
5553 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
5554 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5556 begin
5557 Check_Arg_Is_Identifier (Argx);
5559 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
5560 Error_Pragma_Arg
5561 ("& is not an allowed task dispatching policy name", Argx);
5562 end if;
5563 end Check_Arg_Is_Task_Dispatching_Policy;
5565 ---------------------
5566 -- Check_Arg_Order --
5567 ---------------------
5569 procedure Check_Arg_Order (Names : Name_List) is
5570 Arg : Node_Id;
5572 Highest_So_Far : Natural := 0;
5573 -- Highest index in Names seen do far
5575 begin
5576 Arg := Arg1;
5577 for J in 1 .. Arg_Count loop
5578 if Chars (Arg) /= No_Name then
5579 for K in Names'Range loop
5580 if Chars (Arg) = Names (K) then
5581 if K < Highest_So_Far then
5582 Error_Msg_Name_1 := Pname;
5583 Error_Msg_N
5584 ("parameters out of order for pragma%", Arg);
5585 Error_Msg_Name_1 := Names (K);
5586 Error_Msg_Name_2 := Names (Highest_So_Far);
5587 Error_Msg_N ("\% must appear before %", Arg);
5588 raise Pragma_Exit;
5590 else
5591 Highest_So_Far := K;
5592 end if;
5593 end if;
5594 end loop;
5595 end if;
5597 Arg := Next (Arg);
5598 end loop;
5599 end Check_Arg_Order;
5601 --------------------------------
5602 -- Check_At_Least_N_Arguments --
5603 --------------------------------
5605 procedure Check_At_Least_N_Arguments (N : Nat) is
5606 begin
5607 if Arg_Count < N then
5608 Error_Pragma ("too few arguments for pragma%");
5609 end if;
5610 end Check_At_Least_N_Arguments;
5612 -------------------------------
5613 -- Check_At_Most_N_Arguments --
5614 -------------------------------
5616 procedure Check_At_Most_N_Arguments (N : Nat) is
5617 Arg : Node_Id;
5618 begin
5619 if Arg_Count > N then
5620 Arg := Arg1;
5621 for J in 1 .. N loop
5622 Next (Arg);
5623 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
5624 end loop;
5625 end if;
5626 end Check_At_Most_N_Arguments;
5628 ------------------------
5629 -- Check_Atomic_VFA --
5630 ------------------------
5632 procedure Check_Atomic_VFA (E : Entity_Id; VFA : Boolean) is
5634 Aliased_Subcomponent : exception;
5635 -- Exception raised if an aliased subcomponent is found in E
5637 Independent_Subcomponent : exception;
5638 -- Exception raised if an independent subcomponent is found in E
5640 procedure Check_Subcomponents (Typ : Entity_Id);
5641 -- Apply checks to subcomponents for Atomic and Volatile_Full_Access
5643 -------------------------
5644 -- Check_Subcomponents --
5645 -------------------------
5647 procedure Check_Subcomponents (Typ : Entity_Id) is
5648 Comp : Entity_Id;
5650 begin
5651 if Is_Array_Type (Typ) then
5652 Comp := Component_Type (Typ);
5654 -- For Atomic we accept any atomic subcomponents
5656 if not VFA
5657 and then (Has_Atomic_Components (Typ)
5658 or else Is_Atomic (Comp))
5659 then
5660 null;
5662 -- Give an error if the components are aliased
5664 elsif Has_Aliased_Components (Typ)
5665 or else Is_Aliased (Comp)
5666 then
5667 raise Aliased_Subcomponent;
5669 -- For VFA we accept non-aliased VFA subcomponents
5671 elsif VFA
5672 and then Is_Volatile_Full_Access (Comp)
5673 then
5674 null;
5676 -- Give an error if the components are independent
5678 elsif Has_Independent_Components (Typ)
5679 or else Is_Independent (Comp)
5680 then
5681 raise Independent_Subcomponent;
5682 end if;
5684 -- Recurse on the component type
5686 Check_Subcomponents (Comp);
5688 -- Note: Has_Aliased_Components, like Has_Atomic_Components,
5689 -- and Has_Independent_Components, applies only to arrays.
5690 -- However, this flag does not have a corresponding pragma, so
5691 -- perhaps it should be possible to apply it to record types as
5692 -- well. Should this be done ???
5694 elsif Is_Record_Type (Typ) then
5695 -- It is possible to have an aliased discriminant, so they
5696 -- must be checked along with normal components.
5698 Comp := First_Component_Or_Discriminant (Typ);
5699 while Present (Comp) loop
5701 -- For Atomic we accept any atomic subcomponents
5703 if not VFA
5704 and then (Is_Atomic (Comp)
5705 or else Is_Atomic (Etype (Comp)))
5706 then
5707 null;
5709 -- Give an error if the component is aliased
5711 elsif Is_Aliased (Comp)
5712 or else Is_Aliased (Etype (Comp))
5713 then
5714 raise Aliased_Subcomponent;
5716 -- For VFA we accept non-aliased VFA subcomponents
5718 elsif VFA
5719 and then (Is_Volatile_Full_Access (Comp)
5720 or else Is_Volatile_Full_Access (Etype (Comp)))
5721 then
5722 null;
5724 -- Give an error if the component is independent
5726 elsif Is_Independent (Comp)
5727 or else Is_Independent (Etype (Comp))
5728 then
5729 raise Independent_Subcomponent;
5730 end if;
5732 -- Recurse on the component type
5734 Check_Subcomponents (Etype (Comp));
5736 Next_Component_Or_Discriminant (Comp);
5737 end loop;
5738 end if;
5739 end Check_Subcomponents;
5741 Typ : Entity_Id;
5743 begin
5744 -- Fetch the type in case we are dealing with an object or component
5746 if Is_Type (E) then
5747 Typ := E;
5748 else
5749 pragma Assert (Is_Object (E)
5750 or else
5751 Nkind (Declaration_Node (E)) = N_Component_Declaration);
5753 Typ := Etype (E);
5754 end if;
5756 -- Check all the subcomponents of the type recursively, if any
5758 Check_Subcomponents (Typ);
5760 exception
5761 when Aliased_Subcomponent =>
5762 if VFA then
5763 Error_Pragma
5764 ("cannot apply Volatile_Full_Access with aliased "
5765 & "subcomponent ");
5766 else
5767 Error_Pragma
5768 ("cannot apply Atomic with aliased subcomponent "
5769 & "(RM C.6(13))");
5770 end if;
5772 when Independent_Subcomponent =>
5773 if VFA then
5774 Error_Pragma
5775 ("cannot apply Volatile_Full_Access with independent "
5776 & "subcomponent ");
5777 else
5778 Error_Pragma
5779 ("cannot apply Atomic with independent subcomponent "
5780 & "(RM C.6(13))");
5781 end if;
5783 when others =>
5784 raise Program_Error;
5785 end Check_Atomic_VFA;
5787 ---------------------
5788 -- Check_Component --
5789 ---------------------
5791 procedure Check_Component
5792 (Comp : Node_Id;
5793 UU_Typ : Entity_Id;
5794 In_Variant_Part : Boolean := False)
5796 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
5797 Sindic : constant Node_Id :=
5798 Subtype_Indication (Component_Definition (Comp));
5799 Typ : constant Entity_Id := Etype (Comp_Id);
5801 begin
5802 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
5803 -- object constraint, then the component type shall be an Unchecked_
5804 -- Union.
5806 if Nkind (Sindic) = N_Subtype_Indication
5807 and then Has_Per_Object_Constraint (Comp_Id)
5808 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
5809 then
5810 Error_Msg_N
5811 ("component subtype subject to per-object constraint "
5812 & "must be an Unchecked_Union", Comp);
5814 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
5815 -- the body of a generic unit, or within the body of any of its
5816 -- descendant library units, no part of the type of a component
5817 -- declared in a variant_part of the unchecked union type shall be of
5818 -- a formal private type or formal private extension declared within
5819 -- the formal part of the generic unit.
5821 elsif Ada_Version >= Ada_2012
5822 and then In_Generic_Body (UU_Typ)
5823 and then In_Variant_Part
5824 and then Is_Private_Type (Typ)
5825 and then Is_Generic_Type (Typ)
5826 then
5827 Error_Msg_N
5828 ("component of unchecked union cannot be of generic type", Comp);
5830 elsif Needs_Finalization (Typ) then
5831 Error_Msg_N
5832 ("component of unchecked union cannot be controlled", Comp);
5834 elsif Has_Task (Typ) then
5835 Error_Msg_N
5836 ("component of unchecked union cannot have tasks", Comp);
5837 end if;
5838 end Check_Component;
5840 ----------------------------
5841 -- Check_Duplicate_Pragma --
5842 ----------------------------
5844 procedure Check_Duplicate_Pragma (E : Entity_Id) is
5845 Id : Entity_Id := E;
5846 P : Node_Id;
5848 begin
5849 -- Nothing to do if this pragma comes from an aspect specification,
5850 -- since we could not be duplicating a pragma, and we dealt with the
5851 -- case of duplicated aspects in Analyze_Aspect_Specifications.
5853 if From_Aspect_Specification (N) then
5854 return;
5855 end if;
5857 -- Otherwise current pragma may duplicate previous pragma or a
5858 -- previously given aspect specification or attribute definition
5859 -- clause for the same pragma.
5861 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
5863 if Present (P) then
5865 -- If the entity is a type, then we have to make sure that the
5866 -- ostensible duplicate is not for a parent type from which this
5867 -- type is derived.
5869 if Is_Type (E) then
5870 if Nkind (P) = N_Pragma then
5871 declare
5872 Args : constant List_Id :=
5873 Pragma_Argument_Associations (P);
5874 begin
5875 if Present (Args)
5876 and then Is_Entity_Name (Expression (First (Args)))
5877 and then Is_Type (Entity (Expression (First (Args))))
5878 and then Entity (Expression (First (Args))) /= E
5879 then
5880 return;
5881 end if;
5882 end;
5884 elsif Nkind (P) = N_Aspect_Specification
5885 and then Is_Type (Entity (P))
5886 and then Entity (P) /= E
5887 then
5888 return;
5889 end if;
5890 end if;
5892 -- Here we have a definite duplicate
5894 Error_Msg_Name_1 := Pragma_Name (N);
5895 Error_Msg_Sloc := Sloc (P);
5897 -- For a single protected or a single task object, the error is
5898 -- issued on the original entity.
5900 if Ekind (Id) in E_Task_Type | E_Protected_Type then
5901 Id := Defining_Identifier (Original_Node (Parent (Id)));
5902 end if;
5904 if Nkind (P) = N_Aspect_Specification
5905 or else From_Aspect_Specification (P)
5906 then
5907 Error_Msg_NE ("aspect% for & previously given#", N, Id);
5908 else
5909 -- If -gnatwr is set, warn in case of a duplicate pragma
5910 -- [No_]Inline which is suspicious but not an error, generate
5911 -- an error for other pragmas.
5913 if Pragma_Name (N) in Name_Inline | Name_No_Inline then
5914 if Warn_On_Redundant_Constructs then
5915 Error_Msg_NE
5916 ("?r?pragma% for & duplicates pragma#", N, Id);
5917 end if;
5918 else
5919 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
5920 end if;
5921 end if;
5923 raise Pragma_Exit;
5924 end if;
5925 end Check_Duplicate_Pragma;
5927 ----------------------------------
5928 -- Check_Duplicated_Export_Name --
5929 ----------------------------------
5931 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
5932 String_Val : constant String_Id := Strval (Nam);
5934 begin
5935 -- We are only interested in the export case, and in the case of
5936 -- generics, it is the instance, not the template, that is the
5937 -- problem (the template will generate a warning in any case).
5939 if not Inside_A_Generic
5940 and then (Prag_Id = Pragma_Export
5941 or else
5942 Prag_Id = Pragma_Export_Procedure
5943 or else
5944 Prag_Id = Pragma_Export_Valued_Procedure
5945 or else
5946 Prag_Id = Pragma_Export_Function)
5947 then
5948 for J in Externals.First .. Externals.Last loop
5949 if String_Equal (String_Val, Strval (Externals.Table (J))) then
5950 Error_Msg_Sloc := Sloc (Externals.Table (J));
5951 Error_Msg_N ("external name duplicates name given#", Nam);
5952 exit;
5953 end if;
5954 end loop;
5956 Externals.Append (Nam);
5957 end if;
5958 end Check_Duplicated_Export_Name;
5960 ----------------------------------------
5961 -- Check_Expr_Is_OK_Static_Expression --
5962 ----------------------------------------
5964 procedure Check_Expr_Is_OK_Static_Expression
5965 (Expr : Node_Id;
5966 Typ : Entity_Id := Empty)
5968 begin
5969 if Present (Typ) then
5970 Analyze_And_Resolve (Expr, Typ);
5971 else
5972 Analyze_And_Resolve (Expr);
5973 end if;
5975 -- An expression cannot be considered static if its resolution failed
5976 -- or if it's erroneous. Stop the analysis of the related pragma.
5978 if Etype (Expr) = Any_Type or else Error_Posted (Expr) then
5979 raise Pragma_Exit;
5981 elsif Is_OK_Static_Expression (Expr) then
5982 return;
5984 -- An interesting special case, if we have a string literal and we
5985 -- are in Ada 83 mode, then we allow it even though it will not be
5986 -- flagged as static. This allows the use of Ada 95 pragmas like
5987 -- Import in Ada 83 mode. They will of course be flagged with
5988 -- warnings as usual, but will not cause errors.
5990 elsif Ada_Version = Ada_83
5991 and then Nkind (Expr) = N_String_Literal
5992 then
5993 return;
5995 -- Finally, we have a real error
5997 else
5998 Error_Msg_Name_1 := Pname;
5999 Flag_Non_Static_Expr
6000 (Fix_Error ("argument for pragma% must be a static expression!"),
6001 Expr);
6002 raise Pragma_Exit;
6003 end if;
6004 end Check_Expr_Is_OK_Static_Expression;
6006 -------------------------
6007 -- Check_First_Subtype --
6008 -------------------------
6010 procedure Check_First_Subtype (Arg : Node_Id) is
6011 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6012 Ent : constant Entity_Id := Entity (Argx);
6014 begin
6015 if Is_First_Subtype (Ent) then
6016 null;
6018 elsif Is_Type (Ent) then
6019 Error_Pragma_Arg
6020 ("pragma% cannot apply to subtype", Argx);
6022 elsif Is_Object (Ent) then
6023 Error_Pragma_Arg
6024 ("pragma% cannot apply to object, requires a type", Argx);
6026 else
6027 Error_Pragma_Arg
6028 ("pragma% cannot apply to&, requires a type", Argx);
6029 end if;
6030 end Check_First_Subtype;
6032 ----------------------
6033 -- Check_Identifier --
6034 ----------------------
6036 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
6037 begin
6038 if Present (Arg)
6039 and then Nkind (Arg) = N_Pragma_Argument_Association
6040 then
6041 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
6042 Error_Msg_Name_1 := Pname;
6043 Error_Msg_Name_2 := Id;
6044 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6045 raise Pragma_Exit;
6046 end if;
6047 end if;
6048 end Check_Identifier;
6050 --------------------------------
6051 -- Check_Identifier_Is_One_Of --
6052 --------------------------------
6054 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
6055 begin
6056 if Present (Arg)
6057 and then Nkind (Arg) = N_Pragma_Argument_Association
6058 then
6059 if Chars (Arg) = No_Name then
6060 Error_Msg_Name_1 := Pname;
6061 Error_Msg_N ("pragma% argument expects an identifier", Arg);
6062 raise Pragma_Exit;
6064 elsif Chars (Arg) /= N1
6065 and then Chars (Arg) /= N2
6066 then
6067 Error_Msg_Name_1 := Pname;
6068 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
6069 raise Pragma_Exit;
6070 end if;
6071 end if;
6072 end Check_Identifier_Is_One_Of;
6074 ---------------------------
6075 -- Check_In_Main_Program --
6076 ---------------------------
6078 procedure Check_In_Main_Program is
6079 P : constant Node_Id := Parent (N);
6081 begin
6082 -- Must be in subprogram body
6084 if Nkind (P) /= N_Subprogram_Body then
6085 Error_Pragma ("% pragma allowed only in subprogram");
6087 -- Otherwise warn if obviously not main program
6089 elsif Present (Parameter_Specifications (Specification (P)))
6090 or else not Is_Compilation_Unit (Defining_Entity (P))
6091 then
6092 Error_Msg_Name_1 := Pname;
6093 Error_Msg_N
6094 ("??pragma% is only effective in main program", N);
6095 end if;
6096 end Check_In_Main_Program;
6098 ---------------------------------------
6099 -- Check_Interrupt_Or_Attach_Handler --
6100 ---------------------------------------
6102 procedure Check_Interrupt_Or_Attach_Handler is
6103 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
6104 Handler_Proc, Proc_Scope : Entity_Id;
6106 begin
6107 Analyze (Arg1_X);
6109 if Prag_Id = Pragma_Interrupt_Handler then
6110 Check_Restriction (No_Dynamic_Attachment, N);
6111 end if;
6113 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
6114 Proc_Scope := Scope (Handler_Proc);
6116 if Ekind (Proc_Scope) /= E_Protected_Type then
6117 Error_Pragma_Arg
6118 ("argument of pragma% must be protected procedure", Arg1);
6119 end if;
6121 -- For pragma case (as opposed to access case), check placement.
6122 -- We don't need to do that for aspects, because we have the
6123 -- check that they aspect applies an appropriate procedure.
6125 if not From_Aspect_Specification (N)
6126 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
6127 then
6128 Error_Pragma ("pragma% must be in protected definition");
6129 end if;
6131 if not Is_Library_Level_Entity (Proc_Scope) then
6132 Error_Pragma_Arg
6133 ("argument for pragma% must be library level entity", Arg1);
6134 end if;
6136 -- AI05-0033: A pragma cannot appear within a generic body, because
6137 -- instance can be in a nested scope. The check that protected type
6138 -- is itself a library-level declaration is done elsewhere.
6140 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
6141 -- handle code prior to AI-0033. Analysis tools typically are not
6142 -- interested in this pragma in any case, so no need to worry too
6143 -- much about its placement.
6145 if Inside_A_Generic then
6146 if Ekind (Scope (Current_Scope)) = E_Generic_Package
6147 and then In_Package_Body (Scope (Current_Scope))
6148 and then not Relaxed_RM_Semantics
6149 then
6150 Error_Pragma ("pragma% cannot be used inside a generic");
6151 end if;
6152 end if;
6153 end Check_Interrupt_Or_Attach_Handler;
6155 ---------------------------------
6156 -- Check_Loop_Pragma_Placement --
6157 ---------------------------------
6159 procedure Check_Loop_Pragma_Placement is
6160 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
6161 -- Verify whether the current pragma is properly grouped with other
6162 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
6163 -- related loop where the pragma appears.
6165 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
6166 -- Determine whether an arbitrary statement Stmt denotes pragma
6167 -- Loop_Invariant or Loop_Variant.
6169 procedure Placement_Error (Constr : Node_Id);
6170 pragma No_Return (Placement_Error);
6171 -- Node Constr denotes the last loop restricted construct before we
6172 -- encountered an illegal relation between enclosing constructs. Emit
6173 -- an error depending on what Constr was.
6175 --------------------------------
6176 -- Check_Loop_Pragma_Grouping --
6177 --------------------------------
6179 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
6180 Stop_Search : exception;
6181 -- This exception is used to terminate the recursive descent of
6182 -- routine Check_Grouping.
6184 procedure Check_Grouping (L : List_Id);
6185 -- Find the first group of pragmas in list L and if successful,
6186 -- ensure that the current pragma is part of that group. The
6187 -- routine raises Stop_Search once such a check is performed to
6188 -- halt the recursive descent.
6190 procedure Grouping_Error (Prag : Node_Id);
6191 pragma No_Return (Grouping_Error);
6192 -- Emit an error concerning the current pragma indicating that it
6193 -- should be placed after pragma Prag.
6195 --------------------
6196 -- Check_Grouping --
6197 --------------------
6199 procedure Check_Grouping (L : List_Id) is
6200 HSS : Node_Id;
6201 Stmt : Node_Id;
6202 Prag : Node_Id := Empty; -- init to avoid warning
6204 begin
6205 -- Inspect the list of declarations or statements looking for
6206 -- the first grouping of pragmas:
6208 -- loop
6209 -- pragma Loop_Invariant ...;
6210 -- pragma Loop_Variant ...;
6211 -- . . . -- (1)
6212 -- pragma Loop_Variant ...; -- current pragma
6214 -- If the current pragma is not in the grouping, then it must
6215 -- either appear in a different declarative or statement list
6216 -- or the construct at (1) is separating the pragma from the
6217 -- grouping.
6219 Stmt := First (L);
6220 while Present (Stmt) loop
6222 -- First pragma of the first topmost grouping has been found
6224 if Is_Loop_Pragma (Stmt) then
6226 -- The group and the current pragma are not in the same
6227 -- declarative or statement list.
6229 if List_Containing (Stmt) /= List_Containing (N) then
6230 Grouping_Error (Stmt);
6232 -- Try to reach the current pragma from the first pragma
6233 -- of the grouping while skipping other members:
6235 -- pragma Loop_Invariant ...; -- first pragma
6236 -- pragma Loop_Variant ...; -- member
6237 -- . . .
6238 -- pragma Loop_Variant ...; -- current pragma
6240 else
6241 while Present (Stmt) loop
6242 -- The current pragma is either the first pragma
6243 -- of the group or is a member of the group.
6244 -- Stop the search as the placement is legal.
6246 if Stmt = N then
6247 raise Stop_Search;
6249 -- Skip group members, but keep track of the
6250 -- last pragma in the group.
6252 elsif Is_Loop_Pragma (Stmt) then
6253 Prag := Stmt;
6255 -- Skip declarations and statements generated by
6256 -- the compiler during expansion. Note that some
6257 -- source statements (e.g. pragma Assert) may have
6258 -- been transformed so that they do not appear as
6259 -- coming from source anymore, so we instead look
6260 -- at their Original_Node.
6262 elsif not Comes_From_Source (Original_Node (Stmt))
6263 then
6264 null;
6266 -- A non-pragma is separating the group from the
6267 -- current pragma, the placement is illegal.
6269 else
6270 Grouping_Error (Prag);
6271 end if;
6273 Next (Stmt);
6274 end loop;
6276 -- If the traversal did not reach the current pragma,
6277 -- then the list must be malformed.
6279 raise Program_Error;
6280 end if;
6282 -- Pragmas Loop_Invariant and Loop_Variant may only appear
6283 -- inside a loop or a block housed inside a loop. Inspect
6284 -- the declarations and statements of the block as they may
6285 -- contain the first grouping. This case follows the one for
6286 -- loop pragmas, as block statements which originate in a
6287 -- loop pragma (and so Is_Loop_Pragma will return True on
6288 -- that block statement) should be treated in the previous
6289 -- case.
6291 elsif Nkind (Stmt) = N_Block_Statement then
6292 HSS := Handled_Statement_Sequence (Stmt);
6294 Check_Grouping (Declarations (Stmt));
6296 if Present (HSS) then
6297 Check_Grouping (Statements (HSS));
6298 end if;
6299 end if;
6301 Next (Stmt);
6302 end loop;
6303 end Check_Grouping;
6305 --------------------
6306 -- Grouping_Error --
6307 --------------------
6309 procedure Grouping_Error (Prag : Node_Id) is
6310 begin
6311 Error_Msg_Sloc := Sloc (Prag);
6312 Error_Pragma ("pragma% must appear next to pragma#");
6313 end Grouping_Error;
6315 -- Start of processing for Check_Loop_Pragma_Grouping
6317 begin
6318 -- Inspect the statements of the loop or nested blocks housed
6319 -- within to determine whether the current pragma is part of the
6320 -- first topmost grouping of Loop_Invariant and Loop_Variant.
6322 Check_Grouping (Statements (Loop_Stmt));
6324 exception
6325 when Stop_Search => null;
6326 end Check_Loop_Pragma_Grouping;
6328 --------------------
6329 -- Is_Loop_Pragma --
6330 --------------------
6332 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
6333 begin
6334 -- Inspect the original node as Loop_Invariant and Loop_Variant
6335 -- pragmas are rewritten to null when assertions are disabled.
6337 if Nkind (Original_Node (Stmt)) = N_Pragma then
6338 return
6339 Pragma_Name_Unmapped (Original_Node (Stmt))
6340 in Name_Loop_Invariant | Name_Loop_Variant;
6341 else
6342 return False;
6343 end if;
6344 end Is_Loop_Pragma;
6346 ---------------------
6347 -- Placement_Error --
6348 ---------------------
6350 procedure Placement_Error (Constr : Node_Id) is
6351 LA : constant String := " with Loop_Entry";
6353 begin
6354 if Prag_Id = Pragma_Assert then
6355 Error_Msg_String (1 .. LA'Length) := LA;
6356 Error_Msg_Strlen := LA'Length;
6357 else
6358 Error_Msg_Strlen := 0;
6359 end if;
6361 if Nkind (Constr) = N_Pragma then
6362 Error_Pragma
6363 ("pragma %~ must appear immediately within the statements "
6364 & "of a loop");
6365 else
6366 Error_Pragma_Arg
6367 ("block containing pragma %~ must appear immediately within "
6368 & "the statements of a loop", Constr);
6369 end if;
6370 end Placement_Error;
6372 -- Local declarations
6374 Prev : Node_Id;
6375 Stmt : Node_Id;
6377 -- Start of processing for Check_Loop_Pragma_Placement
6379 begin
6380 -- Check that pragma appears immediately within a loop statement,
6381 -- ignoring intervening block statements.
6383 Prev := N;
6384 Stmt := Parent (N);
6385 while Present (Stmt) loop
6387 -- The pragma or previous block must appear immediately within the
6388 -- current block's declarative or statement part.
6390 if Nkind (Stmt) = N_Block_Statement then
6391 if (No (Declarations (Stmt))
6392 or else List_Containing (Prev) /= Declarations (Stmt))
6393 and then
6394 List_Containing (Prev) /=
6395 Statements (Handled_Statement_Sequence (Stmt))
6396 then
6397 Placement_Error (Prev);
6398 return;
6400 -- Keep inspecting the parents because we are now within a
6401 -- chain of nested blocks.
6403 else
6404 Prev := Stmt;
6405 Stmt := Parent (Stmt);
6406 end if;
6408 -- The pragma or previous block must appear immediately within the
6409 -- statements of the loop.
6411 elsif Nkind (Stmt) = N_Loop_Statement then
6412 if List_Containing (Prev) /= Statements (Stmt) then
6413 Placement_Error (Prev);
6414 end if;
6416 -- Stop the traversal because we reached the innermost loop
6417 -- regardless of whether we encountered an error or not.
6419 exit;
6421 -- Ignore a handled statement sequence. Note that this node may
6422 -- be related to a subprogram body in which case we will emit an
6423 -- error on the next iteration of the search.
6425 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
6426 Stmt := Parent (Stmt);
6428 -- Any other statement breaks the chain from the pragma to the
6429 -- loop.
6431 else
6432 Placement_Error (Prev);
6433 return;
6434 end if;
6435 end loop;
6437 -- Check that the current pragma Loop_Invariant or Loop_Variant is
6438 -- grouped together with other such pragmas.
6440 if Is_Loop_Pragma (N) then
6442 -- The previous check should have located the related loop
6444 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
6445 Check_Loop_Pragma_Grouping (Stmt);
6446 end if;
6447 end Check_Loop_Pragma_Placement;
6449 -------------------------------------------
6450 -- Check_Is_In_Decl_Part_Or_Package_Spec --
6451 -------------------------------------------
6453 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
6454 P : Node_Id;
6456 begin
6457 P := Parent (N);
6458 loop
6459 if No (P) then
6460 exit;
6462 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
6463 exit;
6465 elsif Nkind (P) in N_Package_Specification | N_Block_Statement then
6466 return;
6468 -- Note: the following tests seem a little peculiar, because
6469 -- they test for bodies, but if we were in the statement part
6470 -- of the body, we would already have hit the handled statement
6471 -- sequence, so the only way we get here is by being in the
6472 -- declarative part of the body.
6474 elsif Nkind (P) in
6475 N_Subprogram_Body | N_Package_Body | N_Task_Body | N_Entry_Body
6476 then
6477 return;
6478 end if;
6480 P := Parent (P);
6481 end loop;
6483 Error_Pragma ("pragma% is not in declarative part or package spec");
6484 end Check_Is_In_Decl_Part_Or_Package_Spec;
6486 -------------------------
6487 -- Check_No_Identifier --
6488 -------------------------
6490 procedure Check_No_Identifier (Arg : Node_Id) is
6491 begin
6492 if Nkind (Arg) = N_Pragma_Argument_Association
6493 and then Chars (Arg) /= No_Name
6494 then
6495 Error_Pragma_Arg_Ident
6496 ("pragma% does not permit identifier& here", Arg);
6497 end if;
6498 end Check_No_Identifier;
6500 --------------------------
6501 -- Check_No_Identifiers --
6502 --------------------------
6504 procedure Check_No_Identifiers is
6505 Arg_Node : Node_Id;
6506 begin
6507 Arg_Node := Arg1;
6508 for J in 1 .. Arg_Count loop
6509 Check_No_Identifier (Arg_Node);
6510 Next (Arg_Node);
6511 end loop;
6512 end Check_No_Identifiers;
6514 ------------------------
6515 -- Check_No_Link_Name --
6516 ------------------------
6518 procedure Check_No_Link_Name is
6519 begin
6520 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
6521 Arg4 := Arg3;
6522 end if;
6524 if Present (Arg4) then
6525 Error_Pragma_Arg
6526 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
6527 end if;
6528 end Check_No_Link_Name;
6530 -------------------------------
6531 -- Check_Optional_Identifier --
6532 -------------------------------
6534 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
6535 begin
6536 if Present (Arg)
6537 and then Nkind (Arg) = N_Pragma_Argument_Association
6538 and then Chars (Arg) /= No_Name
6539 then
6540 if Chars (Arg) /= Id then
6541 Error_Msg_Name_1 := Pname;
6542 Error_Msg_Name_2 := Id;
6543 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6544 raise Pragma_Exit;
6545 end if;
6546 end if;
6547 end Check_Optional_Identifier;
6549 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
6550 begin
6551 Check_Optional_Identifier (Arg, Name_Find (Id));
6552 end Check_Optional_Identifier;
6554 -------------------------------------
6555 -- Check_Static_Boolean_Expression --
6556 -------------------------------------
6558 procedure Check_Static_Boolean_Expression (Expr : Node_Id) is
6559 begin
6560 if Present (Expr) then
6561 Analyze_And_Resolve (Expr, Standard_Boolean);
6563 if not Is_OK_Static_Expression (Expr) then
6564 Error_Pragma_Arg
6565 ("expression of pragma % must be static", Expr);
6566 end if;
6567 end if;
6568 end Check_Static_Boolean_Expression;
6570 -----------------------------
6571 -- Check_Static_Constraint --
6572 -----------------------------
6574 -- Note: for convenience in writing this procedure, in addition to
6575 -- the officially (i.e. by spec) allowed argument which is always a
6576 -- constraint, it also allows ranges and discriminant associations.
6577 -- Above is not clear ???
6579 procedure Check_Static_Constraint (Constr : Node_Id) is
6581 procedure Require_Static (E : Node_Id);
6582 -- Require given expression to be static expression
6584 --------------------
6585 -- Require_Static --
6586 --------------------
6588 procedure Require_Static (E : Node_Id) is
6589 begin
6590 if not Is_OK_Static_Expression (E) then
6591 Flag_Non_Static_Expr
6592 ("non-static constraint not allowed in Unchecked_Union!", E);
6593 raise Pragma_Exit;
6594 end if;
6595 end Require_Static;
6597 -- Start of processing for Check_Static_Constraint
6599 begin
6600 case Nkind (Constr) is
6601 when N_Discriminant_Association =>
6602 Require_Static (Expression (Constr));
6604 when N_Range =>
6605 Require_Static (Low_Bound (Constr));
6606 Require_Static (High_Bound (Constr));
6608 when N_Attribute_Reference =>
6609 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
6610 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
6612 when N_Range_Constraint =>
6613 Check_Static_Constraint (Range_Expression (Constr));
6615 when N_Index_Or_Discriminant_Constraint =>
6616 declare
6617 IDC : Entity_Id;
6618 begin
6619 IDC := First (Constraints (Constr));
6620 while Present (IDC) loop
6621 Check_Static_Constraint (IDC);
6622 Next (IDC);
6623 end loop;
6624 end;
6626 when others =>
6627 null;
6628 end case;
6629 end Check_Static_Constraint;
6631 --------------------------------------
6632 -- Check_Valid_Configuration_Pragma --
6633 --------------------------------------
6635 -- A configuration pragma must appear in the context clause of a
6636 -- compilation unit, and only other pragmas may precede it. Note that
6637 -- the test also allows use in a configuration pragma file.
6639 procedure Check_Valid_Configuration_Pragma is
6640 begin
6641 if not Is_Configuration_Pragma then
6642 Error_Pragma ("incorrect placement for configuration pragma%");
6643 end if;
6644 end Check_Valid_Configuration_Pragma;
6646 -------------------------------------
6647 -- Check_Valid_Library_Unit_Pragma --
6648 -------------------------------------
6650 procedure Check_Valid_Library_Unit_Pragma is
6651 Plist : List_Id;
6652 Parent_Node : Node_Id;
6653 Unit_Name : Entity_Id;
6654 Unit_Kind : Node_Kind;
6655 Unit_Node : Node_Id;
6656 Sindex : Source_File_Index;
6658 begin
6659 if not Is_List_Member (N) then
6660 Pragma_Misplaced;
6662 else
6663 Plist := List_Containing (N);
6664 Parent_Node := Parent (Plist);
6666 if Parent_Node = Empty then
6667 Pragma_Misplaced;
6669 -- Case of pragma appearing after a compilation unit. In this case
6670 -- it must have an argument with the corresponding name and must
6671 -- be part of the following pragmas of its parent.
6673 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
6674 if Plist /= Pragmas_After (Parent_Node) then
6675 Pragma_Misplaced;
6677 elsif Arg_Count = 0 then
6678 Error_Pragma
6679 ("argument required if outside compilation unit");
6681 else
6682 Check_No_Identifiers;
6683 Check_Arg_Count (1);
6684 Unit_Node := Unit (Parent (Parent_Node));
6685 Unit_Kind := Nkind (Unit_Node);
6687 Analyze (Get_Pragma_Arg (Arg1));
6689 if Unit_Kind = N_Generic_Subprogram_Declaration
6690 or else Unit_Kind = N_Subprogram_Declaration
6691 then
6692 Unit_Name := Defining_Entity (Unit_Node);
6694 elsif Unit_Kind in N_Generic_Instantiation then
6695 Unit_Name := Defining_Entity (Unit_Node);
6697 else
6698 Unit_Name := Cunit_Entity (Current_Sem_Unit);
6699 end if;
6701 if Chars (Unit_Name) /=
6702 Chars (Entity (Get_Pragma_Arg (Arg1)))
6703 then
6704 Error_Pragma_Arg
6705 ("pragma% argument is not current unit name", Arg1);
6706 end if;
6708 if Ekind (Unit_Name) = E_Package
6709 and then Present (Renamed_Entity (Unit_Name))
6710 then
6711 Error_Pragma ("pragma% not allowed for renamed package");
6712 end if;
6713 end if;
6715 -- Pragma appears other than after a compilation unit
6717 else
6718 -- Here we check for the generic instantiation case and also
6719 -- for the case of processing a generic formal package. We
6720 -- detect these cases by noting that the Sloc on the node
6721 -- does not belong to the current compilation unit.
6723 Sindex := Source_Index (Current_Sem_Unit);
6725 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
6726 Rewrite (N, Make_Null_Statement (Loc));
6727 return;
6729 -- If before first declaration, the pragma applies to the
6730 -- enclosing unit, and the name if present must be this name.
6732 elsif Is_Before_First_Decl (N, Plist) then
6733 Unit_Node := Unit_Declaration_Node (Current_Scope);
6734 Unit_Kind := Nkind (Unit_Node);
6736 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
6737 Pragma_Misplaced;
6739 elsif Unit_Kind = N_Subprogram_Body
6740 and then not Acts_As_Spec (Unit_Node)
6741 then
6742 Pragma_Misplaced;
6744 elsif Nkind (Parent_Node) = N_Package_Body then
6745 Pragma_Misplaced;
6747 elsif Nkind (Parent_Node) = N_Package_Specification
6748 and then Plist = Private_Declarations (Parent_Node)
6749 then
6750 Pragma_Misplaced;
6752 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
6753 or else Nkind (Parent_Node) =
6754 N_Generic_Subprogram_Declaration)
6755 and then Plist = Generic_Formal_Declarations (Parent_Node)
6756 then
6757 Pragma_Misplaced;
6759 elsif Arg_Count > 0 then
6760 Analyze (Get_Pragma_Arg (Arg1));
6762 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
6763 Error_Pragma_Arg
6764 ("name in pragma% must be enclosing unit", Arg1);
6765 end if;
6767 -- It is legal to have no argument in this context
6769 else
6770 return;
6771 end if;
6773 -- Error if not before first declaration. This is because a
6774 -- library unit pragma argument must be the name of a library
6775 -- unit (RM 10.1.5(7)), but the only names permitted in this
6776 -- context are (RM 10.1.5(6)) names of subprogram declarations,
6777 -- generic subprogram declarations or generic instantiations.
6779 else
6780 Error_Pragma
6781 ("pragma% misplaced, must be before first declaration");
6782 end if;
6783 end if;
6784 end if;
6785 end Check_Valid_Library_Unit_Pragma;
6787 -------------------
6788 -- Check_Variant --
6789 -------------------
6791 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
6792 Clist : constant Node_Id := Component_List (Variant);
6793 Comp : Node_Id;
6795 begin
6796 Comp := First_Non_Pragma (Component_Items (Clist));
6797 while Present (Comp) loop
6798 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
6799 Next_Non_Pragma (Comp);
6800 end loop;
6801 end Check_Variant;
6803 ---------------------------
6804 -- Ensure_Aggregate_Form --
6805 ---------------------------
6807 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
6808 CFSD : constant Boolean := Get_Comes_From_Source_Default;
6809 Expr : constant Node_Id := Expression (Arg);
6810 Loc : constant Source_Ptr := Sloc (Expr);
6811 Comps : List_Id := No_List;
6812 Exprs : List_Id := No_List;
6813 Nam : Name_Id := No_Name;
6814 Nam_Loc : Source_Ptr;
6816 begin
6817 -- The pragma argument is in positional form:
6819 -- pragma Depends (Nam => ...)
6820 -- ^
6821 -- Chars field
6823 -- Note that the Sloc of the Chars field is the Sloc of the pragma
6824 -- argument association.
6826 if Nkind (Arg) = N_Pragma_Argument_Association then
6827 Nam := Chars (Arg);
6828 Nam_Loc := Sloc (Arg);
6830 -- Remove the pragma argument name as this will be captured in the
6831 -- aggregate.
6833 Set_Chars (Arg, No_Name);
6834 end if;
6836 -- The argument is already in aggregate form, but the presence of a
6837 -- name causes this to be interpreted as named association which in
6838 -- turn must be converted into an aggregate.
6840 -- pragma Global (In_Out => (A, B, C))
6841 -- ^ ^
6842 -- name aggregate
6844 -- pragma Global ((In_Out => (A, B, C)))
6845 -- ^ ^
6846 -- aggregate aggregate
6848 if Nkind (Expr) = N_Aggregate then
6849 if Nam = No_Name then
6850 return;
6851 end if;
6853 -- Do not transform a null argument into an aggregate as N_Null has
6854 -- special meaning in formal verification pragmas.
6856 elsif Nkind (Expr) = N_Null then
6857 return;
6858 end if;
6860 -- Everything comes from source if the original comes from source
6862 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
6864 -- Positional argument is transformed into an aggregate with an
6865 -- Expressions list.
6867 if Nam = No_Name then
6868 Exprs := New_List (Relocate_Node (Expr));
6870 -- An associative argument is transformed into an aggregate with
6871 -- Component_Associations.
6873 else
6874 Comps := New_List (
6875 Make_Component_Association (Loc,
6876 Choices => New_List (Make_Identifier (Nam_Loc, Nam)),
6877 Expression => Relocate_Node (Expr)));
6878 end if;
6880 Set_Expression (Arg,
6881 Make_Aggregate (Loc,
6882 Component_Associations => Comps,
6883 Expressions => Exprs));
6885 -- Restore Comes_From_Source default
6887 Set_Comes_From_Source_Default (CFSD);
6888 end Ensure_Aggregate_Form;
6890 ------------------
6891 -- Error_Pragma --
6892 ------------------
6894 procedure Error_Pragma (Msg : String) is
6895 begin
6896 Error_Msg_Name_1 := Pname;
6897 Error_Msg_N (Fix_Error (Msg), N);
6898 raise Pragma_Exit;
6899 end Error_Pragma;
6901 ----------------------
6902 -- Error_Pragma_Arg --
6903 ----------------------
6905 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
6906 begin
6907 Error_Msg_Name_1 := Pname;
6908 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
6909 raise Pragma_Exit;
6910 end Error_Pragma_Arg;
6912 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
6913 begin
6914 Error_Msg_Name_1 := Pname;
6915 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
6916 Error_Pragma_Arg (Msg2, Arg);
6917 end Error_Pragma_Arg;
6919 ----------------------------
6920 -- Error_Pragma_Arg_Ident --
6921 ----------------------------
6923 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
6924 begin
6925 Error_Msg_Name_1 := Pname;
6926 Error_Msg_N (Fix_Error (Msg), Arg);
6927 raise Pragma_Exit;
6928 end Error_Pragma_Arg_Ident;
6930 ----------------------
6931 -- Error_Pragma_Ref --
6932 ----------------------
6934 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
6935 begin
6936 Error_Msg_Name_1 := Pname;
6937 Error_Msg_Sloc := Sloc (Ref);
6938 Error_Msg_NE (Fix_Error (Msg), N, Ref);
6939 raise Pragma_Exit;
6940 end Error_Pragma_Ref;
6942 ------------------------
6943 -- Find_Lib_Unit_Name --
6944 ------------------------
6946 function Find_Lib_Unit_Name return Entity_Id is
6947 begin
6948 -- Return inner compilation unit entity, for case of nested
6949 -- categorization pragmas. This happens in generic unit.
6951 if Nkind (Parent (N)) = N_Package_Specification
6952 and then Defining_Entity (Parent (N)) /= Current_Scope
6953 then
6954 return Defining_Entity (Parent (N));
6955 else
6956 return Current_Scope;
6957 end if;
6958 end Find_Lib_Unit_Name;
6960 ----------------------------
6961 -- Find_Program_Unit_Name --
6962 ----------------------------
6964 procedure Find_Program_Unit_Name (Id : Node_Id) is
6965 Unit_Name : Entity_Id;
6966 Unit_Kind : Node_Kind;
6967 P : constant Node_Id := Parent (N);
6969 begin
6970 if Nkind (P) = N_Compilation_Unit then
6971 Unit_Kind := Nkind (Unit (P));
6973 if Unit_Kind in N_Subprogram_Declaration
6974 | N_Package_Declaration
6975 | N_Generic_Declaration
6976 then
6977 Unit_Name := Defining_Entity (Unit (P));
6979 if Chars (Id) = Chars (Unit_Name) then
6980 Set_Entity (Id, Unit_Name);
6981 Set_Etype (Id, Etype (Unit_Name));
6982 else
6983 Set_Etype (Id, Any_Type);
6984 Error_Pragma
6985 ("cannot find program unit referenced by pragma%");
6986 end if;
6988 else
6989 Set_Etype (Id, Any_Type);
6990 Error_Pragma ("pragma% inapplicable to this unit");
6991 end if;
6993 else
6994 Analyze (Id);
6995 end if;
6996 end Find_Program_Unit_Name;
6998 -----------------------------------------
6999 -- Find_Unique_Parameterless_Procedure --
7000 -----------------------------------------
7002 function Find_Unique_Parameterless_Procedure
7003 (Name : Entity_Id;
7004 Arg : Node_Id) return Entity_Id
7006 Proc : Entity_Id := Empty;
7008 begin
7009 -- The body of this procedure needs some comments ???
7011 if not Is_Entity_Name (Name) then
7012 Error_Pragma_Arg
7013 ("argument of pragma% must be entity name", Arg);
7015 elsif not Is_Overloaded (Name) then
7016 Proc := Entity (Name);
7018 if Ekind (Proc) /= E_Procedure
7019 or else Present (First_Formal (Proc))
7020 then
7021 Error_Pragma_Arg
7022 ("argument of pragma% must be parameterless procedure", Arg);
7023 end if;
7025 else
7026 declare
7027 Found : Boolean := False;
7028 It : Interp;
7029 Index : Interp_Index;
7031 begin
7032 Get_First_Interp (Name, Index, It);
7033 while Present (It.Nam) loop
7034 Proc := It.Nam;
7036 if Ekind (Proc) = E_Procedure
7037 and then No (First_Formal (Proc))
7038 then
7039 if not Found then
7040 Found := True;
7041 Set_Entity (Name, Proc);
7042 Set_Is_Overloaded (Name, False);
7043 else
7044 Error_Pragma_Arg
7045 ("ambiguous handler name for pragma% ", Arg);
7046 end if;
7047 end if;
7049 Get_Next_Interp (Index, It);
7050 end loop;
7052 if not Found then
7053 Error_Pragma_Arg
7054 ("argument of pragma% must be parameterless procedure",
7055 Arg);
7056 else
7057 Proc := Entity (Name);
7058 end if;
7059 end;
7060 end if;
7062 return Proc;
7063 end Find_Unique_Parameterless_Procedure;
7065 ---------------
7066 -- Fix_Error --
7067 ---------------
7069 function Fix_Error (Msg : String) return String is
7070 Res : String (Msg'Range) := Msg;
7071 Res_Last : Natural := Msg'Last;
7072 J : Natural;
7074 begin
7075 -- If we have a rewriting of another pragma, go to that pragma
7077 if Is_Rewrite_Substitution (N)
7078 and then Nkind (Original_Node (N)) = N_Pragma
7079 then
7080 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
7081 end if;
7083 -- Case where pragma comes from an aspect specification
7085 if From_Aspect_Specification (N) then
7087 -- Change appearence of "pragma" in message to "aspect"
7089 J := Res'First;
7090 while J <= Res_Last - 5 loop
7091 if Res (J .. J + 5) = "pragma" then
7092 Res (J .. J + 5) := "aspect";
7093 J := J + 6;
7095 else
7096 J := J + 1;
7097 end if;
7098 end loop;
7100 -- Change "argument of" at start of message to "entity for"
7102 if Res'Length > 11
7103 and then Res (Res'First .. Res'First + 10) = "argument of"
7104 then
7105 Res (Res'First .. Res'First + 9) := "entity for";
7106 Res (Res'First + 10 .. Res_Last - 1) :=
7107 Res (Res'First + 11 .. Res_Last);
7108 Res_Last := Res_Last - 1;
7109 end if;
7111 -- Change "argument" at start of message to "entity"
7113 if Res'Length > 8
7114 and then Res (Res'First .. Res'First + 7) = "argument"
7115 then
7116 Res (Res'First .. Res'First + 5) := "entity";
7117 Res (Res'First + 6 .. Res_Last - 2) :=
7118 Res (Res'First + 8 .. Res_Last);
7119 Res_Last := Res_Last - 2;
7120 end if;
7122 -- Get name from corresponding aspect
7124 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
7125 end if;
7127 -- Return possibly modified message
7129 return Res (Res'First .. Res_Last);
7130 end Fix_Error;
7132 -------------------------
7133 -- Gather_Associations --
7134 -------------------------
7136 procedure Gather_Associations
7137 (Names : Name_List;
7138 Args : out Args_List)
7140 Arg : Node_Id;
7142 begin
7143 -- Initialize all parameters to Empty
7145 for J in Args'Range loop
7146 Args (J) := Empty;
7147 end loop;
7149 -- That's all we have to do if there are no argument associations
7151 if No (Pragma_Argument_Associations (N)) then
7152 return;
7153 end if;
7155 -- Otherwise first deal with any positional parameters present
7157 Arg := First (Pragma_Argument_Associations (N));
7158 for Index in Args'Range loop
7159 exit when No (Arg) or else Chars (Arg) /= No_Name;
7160 Args (Index) := Get_Pragma_Arg (Arg);
7161 Next (Arg);
7162 end loop;
7164 -- Positional parameters all processed, if any left, then we
7165 -- have too many positional parameters.
7167 if Present (Arg) and then Chars (Arg) = No_Name then
7168 Error_Pragma_Arg
7169 ("too many positional associations for pragma%", Arg);
7170 end if;
7172 -- Process named parameters if any are present
7174 while Present (Arg) loop
7175 if Chars (Arg) = No_Name then
7176 Error_Pragma_Arg
7177 ("positional association cannot follow named association",
7178 Arg);
7180 else
7181 for Index in Names'Range loop
7182 if Names (Index) = Chars (Arg) then
7183 if Present (Args (Index)) then
7184 Error_Pragma_Arg
7185 ("duplicate argument association for pragma%", Arg);
7186 else
7187 Args (Index) := Get_Pragma_Arg (Arg);
7188 exit;
7189 end if;
7190 end if;
7192 if Index = Names'Last then
7193 Error_Msg_Name_1 := Pname;
7194 Error_Msg_N ("pragma% does not allow & argument", Arg);
7196 -- Check for possible misspelling
7198 for Index1 in Names'Range loop
7199 if Is_Bad_Spelling_Of
7200 (Chars (Arg), Names (Index1))
7201 then
7202 Error_Msg_Name_1 := Names (Index1);
7203 Error_Msg_N -- CODEFIX
7204 ("\possible misspelling of%", Arg);
7205 exit;
7206 end if;
7207 end loop;
7209 raise Pragma_Exit;
7210 end if;
7211 end loop;
7212 end if;
7214 Next (Arg);
7215 end loop;
7216 end Gather_Associations;
7218 -----------------
7219 -- GNAT_Pragma --
7220 -----------------
7222 procedure GNAT_Pragma is
7223 begin
7224 -- We need to check the No_Implementation_Pragmas restriction for
7225 -- the case of a pragma from source. Note that the case of aspects
7226 -- generating corresponding pragmas marks these pragmas as not being
7227 -- from source, so this test also catches that case.
7229 if Comes_From_Source (N) then
7230 Check_Restriction (No_Implementation_Pragmas, N);
7231 end if;
7232 end GNAT_Pragma;
7234 --------------------------
7235 -- Is_Before_First_Decl --
7236 --------------------------
7238 function Is_Before_First_Decl
7239 (Pragma_Node : Node_Id;
7240 Decls : List_Id) return Boolean
7242 Item : Node_Id := First (Decls);
7244 begin
7245 -- Only other pragmas can come before this pragma, but they might
7246 -- have been rewritten so check the original node.
7248 loop
7249 if No (Item) or else Nkind (Original_Node (Item)) /= N_Pragma then
7250 return False;
7252 elsif Item = Pragma_Node then
7253 return True;
7254 end if;
7256 Next (Item);
7257 end loop;
7258 end Is_Before_First_Decl;
7260 -----------------------------
7261 -- Is_Configuration_Pragma --
7262 -----------------------------
7264 -- A configuration pragma must appear in the context clause of a
7265 -- compilation unit, and only other pragmas may precede it. Note that
7266 -- the test below also permits use in a configuration pragma file.
7268 function Is_Configuration_Pragma return Boolean is
7269 Lis : constant List_Id := List_Containing (N);
7270 Par : constant Node_Id := Parent (N);
7271 Prg : Node_Id;
7273 begin
7274 -- If no parent, then we are in the configuration pragma file,
7275 -- so the placement is definitely appropriate.
7277 if No (Par) then
7278 return True;
7280 -- Otherwise we must be in the context clause of a compilation unit
7281 -- and the only thing allowed before us in the context list is more
7282 -- configuration pragmas.
7284 elsif Nkind (Par) = N_Compilation_Unit
7285 and then Context_Items (Par) = Lis
7286 then
7287 Prg := First (Lis);
7289 loop
7290 if Prg = N then
7291 return True;
7292 elsif Nkind (Prg) /= N_Pragma then
7293 return False;
7294 end if;
7296 Next (Prg);
7297 end loop;
7299 else
7300 return False;
7301 end if;
7302 end Is_Configuration_Pragma;
7304 --------------------------
7305 -- Is_In_Context_Clause --
7306 --------------------------
7308 function Is_In_Context_Clause return Boolean is
7309 Plist : List_Id;
7310 Parent_Node : Node_Id;
7312 begin
7313 if not Is_List_Member (N) then
7314 return False;
7316 else
7317 Plist := List_Containing (N);
7318 Parent_Node := Parent (Plist);
7320 if Parent_Node = Empty
7321 or else Nkind (Parent_Node) /= N_Compilation_Unit
7322 or else Context_Items (Parent_Node) /= Plist
7323 then
7324 return False;
7325 end if;
7326 end if;
7328 return True;
7329 end Is_In_Context_Clause;
7331 ---------------------------------
7332 -- Is_Static_String_Expression --
7333 ---------------------------------
7335 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
7336 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
7337 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
7339 begin
7340 Analyze_And_Resolve (Argx);
7342 -- Special case Ada 83, where the expression will never be static,
7343 -- but we will return true if we had a string literal to start with.
7345 if Ada_Version = Ada_83 then
7346 return Lit;
7348 -- Normal case, true only if we end up with a string literal that
7349 -- is marked as being the result of evaluating a static expression.
7351 else
7352 return Is_OK_Static_Expression (Argx)
7353 and then Nkind (Argx) = N_String_Literal;
7354 end if;
7356 end Is_Static_String_Expression;
7358 ----------------------
7359 -- Pragma_Misplaced --
7360 ----------------------
7362 procedure Pragma_Misplaced is
7363 begin
7364 Error_Pragma ("incorrect placement of pragma%");
7365 end Pragma_Misplaced;
7367 ------------------------------------------------
7368 -- Process_Atomic_Independent_Shared_Volatile --
7369 ------------------------------------------------
7371 procedure Process_Atomic_Independent_Shared_Volatile is
7372 procedure Check_VFA_Conflicts (Ent : Entity_Id);
7373 -- Check that Volatile_Full_Access and VFA do not conflict
7375 procedure Mark_Component_Or_Object (Ent : Entity_Id);
7376 -- Appropriately set flags on the given entity, either an array or
7377 -- record component, or an object declaration) according to the
7378 -- current pragma.
7380 procedure Mark_Type (Ent : Entity_Id);
7381 -- Appropriately set flags on the given entity, a type
7383 procedure Set_Atomic_VFA (Ent : Entity_Id);
7384 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
7385 -- no explicit alignment was given, set alignment to unknown, since
7386 -- back end knows what the alignment requirements are for atomic and
7387 -- full access arrays. Note: this is necessary for derived types.
7389 -------------------------
7390 -- Check_VFA_Conflicts --
7391 -------------------------
7393 procedure Check_VFA_Conflicts (Ent : Entity_Id) is
7394 Comp : Entity_Id;
7395 Typ : Entity_Id;
7397 VFA_And_Atomic : Boolean := False;
7398 -- Set True if both VFA and Atomic present
7400 begin
7401 -- Fetch the type in case we are dealing with an object or
7402 -- component.
7404 if Is_Type (Ent) then
7405 Typ := Ent;
7406 else
7407 pragma Assert (Is_Object (Ent)
7408 or else
7409 Nkind (Declaration_Node (Ent)) = N_Component_Declaration);
7411 Typ := Etype (Ent);
7412 end if;
7414 -- Check Atomic and VFA used together
7416 if Prag_Id = Pragma_Volatile_Full_Access
7417 or else Is_Volatile_Full_Access (Ent)
7418 then
7419 if Prag_Id = Pragma_Atomic
7420 or else Prag_Id = Pragma_Shared
7421 or else Is_Atomic (Ent)
7422 then
7423 VFA_And_Atomic := True;
7425 elsif Is_Array_Type (Typ) then
7426 VFA_And_Atomic := Has_Atomic_Components (Typ);
7428 -- Note: Has_Atomic_Components is not used below, as this flag
7429 -- represents the pragma of the same name, Atomic_Components,
7430 -- which only applies to arrays.
7432 elsif Is_Record_Type (Typ) then
7433 -- Attributes cannot be applied to discriminants, only
7434 -- regular record components.
7436 Comp := First_Component (Typ);
7437 while Present (Comp) loop
7438 if Is_Atomic (Comp)
7439 or else Is_Atomic (Typ)
7440 then
7441 VFA_And_Atomic := True;
7443 exit;
7444 end if;
7446 Next_Component (Comp);
7447 end loop;
7448 end if;
7450 if VFA_And_Atomic then
7451 Error_Pragma
7452 ("cannot have Volatile_Full_Access and Atomic for same "
7453 & "entity");
7454 end if;
7455 end if;
7456 end Check_VFA_Conflicts;
7458 ------------------------------
7459 -- Mark_Component_Or_Object --
7460 ------------------------------
7462 procedure Mark_Component_Or_Object (Ent : Entity_Id) is
7463 begin
7464 if Prag_Id = Pragma_Atomic
7465 or else Prag_Id = Pragma_Shared
7466 or else Prag_Id = Pragma_Volatile_Full_Access
7467 then
7468 if Prag_Id = Pragma_Volatile_Full_Access then
7469 Set_Is_Volatile_Full_Access (Ent);
7470 else
7471 Set_Is_Atomic (Ent);
7472 end if;
7474 -- If the object declaration has an explicit initialization, a
7475 -- temporary may have to be created to hold the expression, to
7476 -- ensure that access to the object remains atomic.
7478 if Nkind (Parent (Ent)) = N_Object_Declaration
7479 and then Present (Expression (Parent (Ent)))
7480 then
7481 Set_Has_Delayed_Freeze (Ent);
7482 end if;
7483 end if;
7485 -- Atomic/Shared/Volatile_Full_Access imply Independent
7487 if Prag_Id /= Pragma_Volatile then
7488 Set_Is_Independent (Ent);
7490 if Prag_Id = Pragma_Independent then
7491 Record_Independence_Check (N, Ent);
7492 end if;
7493 end if;
7495 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7497 if Prag_Id /= Pragma_Independent then
7498 Set_Is_Volatile (Ent);
7499 Set_Treat_As_Volatile (Ent);
7500 end if;
7501 end Mark_Component_Or_Object;
7503 ---------------
7504 -- Mark_Type --
7505 ---------------
7507 procedure Mark_Type (Ent : Entity_Id) is
7508 begin
7509 -- Attribute belongs on the base type. If the view of the type is
7510 -- currently private, it also belongs on the underlying type.
7512 -- In Ada 2020, the pragma can apply to a formal type, for which
7513 -- there may be no underlying type.
7515 if Prag_Id = Pragma_Atomic
7516 or else Prag_Id = Pragma_Shared
7517 or else Prag_Id = Pragma_Volatile_Full_Access
7518 then
7519 Set_Atomic_VFA (Ent);
7520 Set_Atomic_VFA (Base_Type (Ent));
7522 if not Is_Generic_Type (Ent) then
7523 Set_Atomic_VFA (Underlying_Type (Ent));
7524 end if;
7525 end if;
7527 -- Atomic/Shared/Volatile_Full_Access imply Independent
7529 if Prag_Id /= Pragma_Volatile then
7530 Set_Is_Independent (Ent);
7531 Set_Is_Independent (Base_Type (Ent));
7533 if not Is_Generic_Type (Ent) then
7534 Set_Is_Independent (Underlying_Type (Ent));
7536 if Prag_Id = Pragma_Independent then
7537 Record_Independence_Check (N, Base_Type (Ent));
7538 end if;
7539 end if;
7540 end if;
7542 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7544 if Prag_Id /= Pragma_Independent then
7545 Set_Is_Volatile (Ent);
7546 Set_Is_Volatile (Base_Type (Ent));
7548 if not Is_Generic_Type (Ent) then
7549 Set_Is_Volatile (Underlying_Type (Ent));
7550 Set_Treat_As_Volatile (Underlying_Type (Ent));
7551 end if;
7553 Set_Treat_As_Volatile (Ent);
7554 end if;
7556 -- Apply Volatile to the composite type's individual components,
7557 -- (RM C.6(8/3)).
7559 if Prag_Id = Pragma_Volatile
7560 and then Is_Record_Type (Etype (Ent))
7561 then
7562 declare
7563 Comp : Entity_Id;
7564 begin
7565 Comp := First_Component (Ent);
7566 while Present (Comp) loop
7567 Mark_Component_Or_Object (Comp);
7569 Next_Component (Comp);
7570 end loop;
7571 end;
7572 end if;
7573 end Mark_Type;
7575 --------------------
7576 -- Set_Atomic_VFA --
7577 --------------------
7579 procedure Set_Atomic_VFA (Ent : Entity_Id) is
7580 begin
7581 if Prag_Id = Pragma_Volatile_Full_Access then
7582 Set_Is_Volatile_Full_Access (Ent);
7583 else
7584 Set_Is_Atomic (Ent);
7585 end if;
7587 if not Has_Alignment_Clause (Ent) then
7588 Set_Alignment (Ent, Uint_0);
7589 end if;
7590 end Set_Atomic_VFA;
7592 -- Local variables
7594 Decl : Node_Id;
7595 E : Entity_Id;
7596 E_Arg : Node_Id;
7598 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
7600 begin
7601 Check_Ada_83_Warning;
7602 Check_No_Identifiers;
7603 Check_Arg_Count (1);
7604 Check_Arg_Is_Local_Name (Arg1);
7605 E_Arg := Get_Pragma_Arg (Arg1);
7607 if Etype (E_Arg) = Any_Type then
7608 return;
7609 end if;
7611 E := Entity (E_Arg);
7613 -- A pragma that applies to a Ghost entity becomes Ghost for the
7614 -- purposes of legality checks and removal of ignored Ghost code.
7616 Mark_Ghost_Pragma (N, E);
7618 -- Check duplicate before we chain ourselves
7620 Check_Duplicate_Pragma (E);
7622 -- Check appropriateness of the entity
7624 Decl := Declaration_Node (E);
7626 -- Deal with the case where the pragma/attribute is applied to a type
7628 if Is_Type (E) then
7629 if Rep_Item_Too_Early (E, N)
7630 or else Rep_Item_Too_Late (E, N)
7631 then
7632 return;
7633 else
7634 Check_First_Subtype (Arg1);
7635 end if;
7637 Mark_Type (E);
7639 -- Deal with the case where the pragma/attribute applies to a
7640 -- component or object declaration.
7642 elsif Nkind (Decl) = N_Object_Declaration
7643 or else (Nkind (Decl) = N_Component_Declaration
7644 and then Original_Record_Component (E) = E)
7645 then
7646 if Rep_Item_Too_Late (E, N) then
7647 return;
7648 end if;
7650 Mark_Component_Or_Object (E);
7652 -- In other cases give an error
7654 else
7655 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7656 end if;
7658 -- Check that Volatile_Full_Access and Atomic do not conflict
7660 Check_VFA_Conflicts (E);
7662 -- Check for the application of Atomic or Volatile_Full_Access to
7663 -- an entity that has [nonatomic] aliased, or else specified to be
7664 -- independently addressable, subcomponents.
7666 if (Prag_Id = Pragma_Atomic and then Ada_Version >= Ada_2020)
7667 or else Prag_Id = Pragma_Volatile_Full_Access
7668 then
7669 Check_Atomic_VFA (E, VFA => Prag_Id = Pragma_Volatile_Full_Access);
7670 end if;
7672 -- The following check is only relevant when SPARK_Mode is on as
7673 -- this is not a standard Ada legality rule. Pragma Volatile can
7674 -- only apply to a full type declaration or an object declaration
7675 -- (SPARK RM 7.1.3(2)). Original_Node is necessary to account for
7676 -- untagged derived types that are rewritten as subtypes of their
7677 -- respective root types.
7679 if SPARK_Mode = On
7680 and then Prag_Id = Pragma_Volatile
7681 and then Nkind (Original_Node (Decl)) not in
7682 N_Full_Type_Declaration |
7683 N_Formal_Type_Declaration |
7684 N_Object_Declaration |
7685 N_Single_Protected_Declaration |
7686 N_Single_Task_Declaration
7687 then
7688 Error_Pragma_Arg
7689 ("argument of pragma % must denote a full type or object "
7690 & "declaration", Arg1);
7691 end if;
7692 end Process_Atomic_Independent_Shared_Volatile;
7694 -------------------------------------------
7695 -- Process_Compile_Time_Warning_Or_Error --
7696 -------------------------------------------
7698 procedure Process_Compile_Time_Warning_Or_Error is
7699 P : Node_Id := Parent (N);
7700 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
7702 begin
7703 Check_Arg_Count (2);
7704 Check_No_Identifiers;
7705 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
7706 Analyze_And_Resolve (Arg1x, Standard_Boolean);
7708 -- In GNATprove mode, pragma Compile_Time_Error is translated as
7709 -- a Check pragma in GNATprove mode, handled as an assumption in
7710 -- GNATprove. This is correct as the compiler will issue an error
7711 -- if the condition cannot be statically evaluated to False.
7712 -- Compile_Time_Warning are ignored, as the analyzer may not have the
7713 -- same information as the compiler (in particular regarding size of
7714 -- objects decided in gigi) so it makes no sense to issue a warning
7715 -- in GNATprove.
7717 if GNATprove_Mode then
7718 if Prag_Id = Pragma_Compile_Time_Error then
7719 declare
7720 New_Args : List_Id;
7721 begin
7722 -- Implement Compile_Time_Error by generating
7723 -- a corresponding Check pragma:
7725 -- pragma Check (name, condition);
7727 -- where name is the identifier matching the pragma name. So
7728 -- rewrite pragma in this manner and analyze the result.
7730 New_Args := New_List
7731 (Make_Pragma_Argument_Association
7732 (Loc,
7733 Expression => Make_Identifier (Loc, Pname)),
7734 Make_Pragma_Argument_Association
7735 (Sloc (Arg1x),
7736 Expression => Arg1x));
7738 -- Rewrite as Check pragma
7740 Rewrite (N,
7741 Make_Pragma (Loc,
7742 Chars => Name_Check,
7743 Pragma_Argument_Associations => New_Args));
7745 Analyze (N);
7746 end;
7748 else
7749 Rewrite (N, Make_Null_Statement (Loc));
7750 end if;
7752 return;
7753 end if;
7755 -- If the condition is known at compile time (now), validate it now.
7756 -- Otherwise, register the expression for validation after the back
7757 -- end has been called, because it might be known at compile time
7758 -- then. For example, if the expression is "Record_Type'Size /= 32"
7759 -- it might be known after the back end has determined the size of
7760 -- Record_Type. We do not defer validation if we're inside a generic
7761 -- unit, because we will have more information in the instances.
7763 if Compile_Time_Known_Value (Arg1x) then
7764 Validate_Compile_Time_Warning_Or_Error (N, Sloc (Arg1));
7765 else
7766 while Present (P) and then Nkind (P) not in N_Generic_Declaration
7767 loop
7768 if Nkind (P) in N_Package_Body | N_Subprogram_Body then
7769 P := Corresponding_Spec (P);
7770 else
7771 P := Parent (P);
7772 end if;
7773 end loop;
7775 if No (P) then
7776 Defer_Compile_Time_Warning_Error_To_BE (N);
7777 end if;
7778 end if;
7779 end Process_Compile_Time_Warning_Or_Error;
7781 ------------------------
7782 -- Process_Convention --
7783 ------------------------
7785 procedure Process_Convention
7786 (C : out Convention_Id;
7787 Ent : out Entity_Id)
7789 Cname : Name_Id;
7791 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
7792 -- Called if we have more than one Export/Import/Convention pragma.
7793 -- This is generally illegal, but we have a special case of allowing
7794 -- Import and Interface to coexist if they specify the convention in
7795 -- a consistent manner. We are allowed to do this, since Interface is
7796 -- an implementation defined pragma, and we choose to do it since we
7797 -- know Rational allows this combination. S is the entity id of the
7798 -- subprogram in question. This procedure also sets the special flag
7799 -- Import_Interface_Present in both pragmas in the case where we do
7800 -- have matching Import and Interface pragmas.
7802 procedure Set_Convention_From_Pragma (E : Entity_Id);
7803 -- Set convention in entity E, and also flag that the entity has a
7804 -- convention pragma. If entity is for a private or incomplete type,
7805 -- also set convention and flag on underlying type. This procedure
7806 -- also deals with the special case of C_Pass_By_Copy convention,
7807 -- and error checks for inappropriate convention specification.
7809 -------------------------------
7810 -- Diagnose_Multiple_Pragmas --
7811 -------------------------------
7813 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
7814 Pdec : constant Node_Id := Declaration_Node (S);
7815 Decl : Node_Id;
7816 Err : Boolean;
7818 function Same_Convention (Decl : Node_Id) return Boolean;
7819 -- Decl is a pragma node. This function returns True if this
7820 -- pragma has a first argument that is an identifier with a
7821 -- Chars field corresponding to the Convention_Id C.
7823 function Same_Name (Decl : Node_Id) return Boolean;
7824 -- Decl is a pragma node. This function returns True if this
7825 -- pragma has a second argument that is an identifier with a
7826 -- Chars field that matches the Chars of the current subprogram.
7828 ---------------------
7829 -- Same_Convention --
7830 ---------------------
7832 function Same_Convention (Decl : Node_Id) return Boolean is
7833 Arg1 : constant Node_Id :=
7834 First (Pragma_Argument_Associations (Decl));
7836 begin
7837 if Present (Arg1) then
7838 declare
7839 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
7840 begin
7841 if Nkind (Arg) = N_Identifier
7842 and then Is_Convention_Name (Chars (Arg))
7843 and then Get_Convention_Id (Chars (Arg)) = C
7844 then
7845 return True;
7846 end if;
7847 end;
7848 end if;
7850 return False;
7851 end Same_Convention;
7853 ---------------
7854 -- Same_Name --
7855 ---------------
7857 function Same_Name (Decl : Node_Id) return Boolean is
7858 Arg1 : constant Node_Id :=
7859 First (Pragma_Argument_Associations (Decl));
7860 Arg2 : Node_Id;
7862 begin
7863 if No (Arg1) then
7864 return False;
7865 end if;
7867 Arg2 := Next (Arg1);
7869 if No (Arg2) then
7870 return False;
7871 end if;
7873 declare
7874 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
7875 begin
7876 if Nkind (Arg) = N_Identifier
7877 and then Chars (Arg) = Chars (S)
7878 then
7879 return True;
7880 end if;
7881 end;
7883 return False;
7884 end Same_Name;
7886 -- Start of processing for Diagnose_Multiple_Pragmas
7888 begin
7889 Err := True;
7891 -- Definitely give message if we have Convention/Export here
7893 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
7894 null;
7896 -- If we have an Import or Export, scan back from pragma to
7897 -- find any previous pragma applying to the same procedure.
7898 -- The scan will be terminated by the start of the list, or
7899 -- hitting the subprogram declaration. This won't allow one
7900 -- pragma to appear in the public part and one in the private
7901 -- part, but that seems very unlikely in practice.
7903 else
7904 Decl := Prev (N);
7905 while Present (Decl) and then Decl /= Pdec loop
7907 -- Look for pragma with same name as us
7909 if Nkind (Decl) = N_Pragma
7910 and then Same_Name (Decl)
7911 then
7912 -- Give error if same as our pragma or Export/Convention
7914 if Pragma_Name_Unmapped (Decl)
7915 in Name_Export
7916 | Name_Convention
7917 | Pragma_Name_Unmapped (N)
7918 then
7919 exit;
7921 -- Case of Import/Interface or the other way round
7923 elsif Pragma_Name_Unmapped (Decl)
7924 in Name_Interface | Name_Import
7925 then
7926 -- Here we know that we have Import and Interface. It
7927 -- doesn't matter which way round they are. See if
7928 -- they specify the same convention. If so, all OK,
7929 -- and set special flags to stop other messages
7931 if Same_Convention (Decl) then
7932 Set_Import_Interface_Present (N);
7933 Set_Import_Interface_Present (Decl);
7934 Err := False;
7936 -- If different conventions, special message
7938 else
7939 Error_Msg_Sloc := Sloc (Decl);
7940 Error_Pragma_Arg
7941 ("convention differs from that given#", Arg1);
7942 return;
7943 end if;
7944 end if;
7945 end if;
7947 Next (Decl);
7948 end loop;
7949 end if;
7951 -- Give message if needed if we fall through those tests
7952 -- except on Relaxed_RM_Semantics where we let go: either this
7953 -- is a case accepted/ignored by other Ada compilers (e.g.
7954 -- a mix of Convention and Import), or another error will be
7955 -- generated later (e.g. using both Import and Export).
7957 if Err and not Relaxed_RM_Semantics then
7958 Error_Pragma_Arg
7959 ("at most one Convention/Export/Import pragma is allowed",
7960 Arg2);
7961 end if;
7962 end Diagnose_Multiple_Pragmas;
7964 --------------------------------
7965 -- Set_Convention_From_Pragma --
7966 --------------------------------
7968 procedure Set_Convention_From_Pragma (E : Entity_Id) is
7969 begin
7970 -- Ada 2005 (AI-430): Check invalid attempt to change convention
7971 -- for an overridden dispatching operation. Technically this is
7972 -- an amendment and should only be done in Ada 2005 mode. However,
7973 -- this is clearly a mistake, since the problem that is addressed
7974 -- by this AI is that there is a clear gap in the RM.
7976 if Is_Dispatching_Operation (E)
7977 and then Present (Overridden_Operation (E))
7978 and then C /= Convention (Overridden_Operation (E))
7979 then
7980 Error_Pragma_Arg
7981 ("cannot change convention for overridden dispatching "
7982 & "operation", Arg1);
7984 -- Special check for convention Stdcall: a dispatching call is not
7985 -- allowed. A dispatching subprogram cannot be used to interface
7986 -- to the Win32 API, so this check actually does not impose any
7987 -- effective restriction.
7989 elsif Is_Dispatching_Operation (E)
7990 and then C = Convention_Stdcall
7991 then
7992 -- Note: make this unconditional so that if there is more
7993 -- than one call to which the pragma applies, we get a
7994 -- message for each call. Also don't use Error_Pragma,
7995 -- so that we get multiple messages.
7997 Error_Msg_Sloc := Sloc (E);
7998 Error_Msg_N
7999 ("dispatching subprogram# cannot use Stdcall convention!",
8000 Get_Pragma_Arg (Arg1));
8001 end if;
8003 -- Set the convention
8005 Set_Convention (E, C);
8006 Set_Has_Convention_Pragma (E);
8008 -- For the case of a record base type, also set the convention of
8009 -- any anonymous access types declared in the record which do not
8010 -- currently have a specified convention.
8011 -- Similarly for an array base type and anonymous access types
8012 -- components.
8014 if Is_Base_Type (E) then
8015 if Is_Record_Type (E) then
8016 declare
8017 Comp : Node_Id;
8019 begin
8020 Comp := First_Component (E);
8021 while Present (Comp) loop
8022 if Present (Etype (Comp))
8023 and then
8024 Ekind (Etype (Comp)) in
8025 E_Anonymous_Access_Type |
8026 E_Anonymous_Access_Subprogram_Type
8027 and then not Has_Convention_Pragma (Comp)
8028 then
8029 Set_Convention (Comp, C);
8030 end if;
8032 Next_Component (Comp);
8033 end loop;
8034 end;
8036 elsif Is_Array_Type (E)
8037 and then Ekind (Component_Type (E)) in
8038 E_Anonymous_Access_Type |
8039 E_Anonymous_Access_Subprogram_Type
8040 then
8041 Set_Convention (Designated_Type (Component_Type (E)), C);
8042 end if;
8043 end if;
8045 -- Deal with incomplete/private type case, where underlying type
8046 -- is available, so set convention of that underlying type.
8048 if Is_Incomplete_Or_Private_Type (E)
8049 and then Present (Underlying_Type (E))
8050 then
8051 Set_Convention (Underlying_Type (E), C);
8052 Set_Has_Convention_Pragma (Underlying_Type (E), True);
8053 end if;
8055 -- A class-wide type should inherit the convention of the specific
8056 -- root type (although this isn't specified clearly by the RM).
8058 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
8059 Set_Convention (Class_Wide_Type (E), C);
8060 end if;
8062 -- If the entity is a record type, then check for special case of
8063 -- C_Pass_By_Copy, which is treated the same as C except that the
8064 -- special record flag is set. This convention is only permitted
8065 -- on record types (see AI95-00131).
8067 if Cname = Name_C_Pass_By_Copy then
8068 if Is_Record_Type (E) then
8069 Set_C_Pass_By_Copy (Base_Type (E));
8070 elsif Is_Incomplete_Or_Private_Type (E)
8071 and then Is_Record_Type (Underlying_Type (E))
8072 then
8073 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
8074 else
8075 Error_Pragma_Arg
8076 ("C_Pass_By_Copy convention allowed only for record type",
8077 Arg2);
8078 end if;
8079 end if;
8081 -- If the entity is a derived boolean type, check for the special
8082 -- case of convention C, C++, or Fortran, where we consider any
8083 -- nonzero value to represent true.
8085 if Is_Discrete_Type (E)
8086 and then Root_Type (Etype (E)) = Standard_Boolean
8087 and then
8088 (C = Convention_C
8089 or else
8090 C = Convention_CPP
8091 or else
8092 C = Convention_Fortran)
8093 then
8094 Set_Nonzero_Is_True (Base_Type (E));
8095 end if;
8096 end Set_Convention_From_Pragma;
8098 -- Local variables
8100 Comp_Unit : Unit_Number_Type;
8101 E : Entity_Id;
8102 E1 : Entity_Id;
8103 Id : Node_Id;
8104 Subp : Entity_Id;
8106 -- Start of processing for Process_Convention
8108 begin
8109 Check_At_Least_N_Arguments (2);
8110 Check_Optional_Identifier (Arg1, Name_Convention);
8111 Check_Arg_Is_Identifier (Arg1);
8112 Cname := Chars (Get_Pragma_Arg (Arg1));
8114 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
8115 -- tested again below to set the critical flag).
8117 if Cname = Name_C_Pass_By_Copy then
8118 C := Convention_C;
8120 -- Otherwise we must have something in the standard convention list
8122 elsif Is_Convention_Name (Cname) then
8123 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
8125 -- Otherwise warn on unrecognized convention
8127 else
8128 if Warn_On_Export_Import then
8129 Error_Msg_N
8130 ("??unrecognized convention name, C assumed",
8131 Get_Pragma_Arg (Arg1));
8132 end if;
8134 C := Convention_C;
8135 end if;
8137 Check_Optional_Identifier (Arg2, Name_Entity);
8138 Check_Arg_Is_Local_Name (Arg2);
8140 Id := Get_Pragma_Arg (Arg2);
8141 Analyze (Id);
8143 if not Is_Entity_Name (Id) then
8144 Error_Pragma_Arg ("entity name required", Arg2);
8145 end if;
8147 E := Entity (Id);
8149 -- Set entity to return
8151 Ent := E;
8153 -- Ada_Pass_By_Copy special checking
8155 if C = Convention_Ada_Pass_By_Copy then
8156 if not Is_First_Subtype (E) then
8157 Error_Pragma_Arg
8158 ("convention `Ada_Pass_By_Copy` only allowed for types",
8159 Arg2);
8160 end if;
8162 if Is_By_Reference_Type (E) then
8163 Error_Pragma_Arg
8164 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
8165 & "type", Arg1);
8166 end if;
8168 -- Ada_Pass_By_Reference special checking
8170 elsif C = Convention_Ada_Pass_By_Reference then
8171 if not Is_First_Subtype (E) then
8172 Error_Pragma_Arg
8173 ("convention `Ada_Pass_By_Reference` only allowed for types",
8174 Arg2);
8175 end if;
8177 if Is_By_Copy_Type (E) then
8178 Error_Pragma_Arg
8179 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
8180 & "type", Arg1);
8181 end if;
8182 end if;
8184 -- Go to renamed subprogram if present, since convention applies to
8185 -- the actual renamed entity, not to the renaming entity. If the
8186 -- subprogram is inherited, go to parent subprogram.
8188 if Is_Subprogram (E)
8189 and then Present (Alias (E))
8190 then
8191 if Nkind (Parent (Declaration_Node (E))) =
8192 N_Subprogram_Renaming_Declaration
8193 then
8194 if Scope (E) /= Scope (Alias (E)) then
8195 Error_Pragma_Ref
8196 ("cannot apply pragma% to non-local entity&#", E);
8197 end if;
8199 E := Alias (E);
8201 elsif Nkind (Parent (E)) in
8202 N_Full_Type_Declaration | N_Private_Extension_Declaration
8203 and then Scope (E) = Scope (Alias (E))
8204 then
8205 E := Alias (E);
8207 -- Return the parent subprogram the entity was inherited from
8209 Ent := E;
8210 end if;
8211 end if;
8213 -- Check that we are not applying this to a specless body. Relax this
8214 -- check if Relaxed_RM_Semantics to accommodate other Ada compilers.
8216 if Is_Subprogram (E)
8217 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
8218 and then not Relaxed_RM_Semantics
8219 then
8220 Error_Pragma
8221 ("pragma% requires separate spec and must come before body");
8222 end if;
8224 -- Check that we are not applying this to a named constant
8226 if Ekind (E) in E_Named_Integer | E_Named_Real then
8227 Error_Msg_Name_1 := Pname;
8228 Error_Msg_N
8229 ("cannot apply pragma% to named constant!",
8230 Get_Pragma_Arg (Arg2));
8231 Error_Pragma_Arg
8232 ("\supply appropriate type for&!", Arg2);
8233 end if;
8235 if Ekind (E) = E_Enumeration_Literal then
8236 Error_Pragma ("enumeration literal not allowed for pragma%");
8237 end if;
8239 -- Check for rep item appearing too early or too late
8241 if Etype (E) = Any_Type
8242 or else Rep_Item_Too_Early (E, N)
8243 then
8244 raise Pragma_Exit;
8246 elsif Present (Underlying_Type (E)) then
8247 E := Underlying_Type (E);
8248 end if;
8250 if Rep_Item_Too_Late (E, N) then
8251 raise Pragma_Exit;
8252 end if;
8254 if Has_Convention_Pragma (E) then
8255 Diagnose_Multiple_Pragmas (E);
8257 elsif Convention (E) = Convention_Protected
8258 or else Ekind (Scope (E)) = E_Protected_Type
8259 then
8260 Error_Pragma_Arg
8261 ("a protected operation cannot be given a different convention",
8262 Arg2);
8263 end if;
8265 -- For Intrinsic, a subprogram is required
8267 if C = Convention_Intrinsic
8268 and then not Is_Subprogram_Or_Generic_Subprogram (E)
8269 then
8270 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
8272 if not (Is_Type (E) and then Relaxed_RM_Semantics) then
8273 Error_Pragma_Arg
8274 ("second argument of pragma% must be a subprogram", Arg2);
8275 end if;
8277 -- Special checks for C_Variadic_n
8279 elsif C in Convention_C_Variadic then
8281 -- Several allowed cases
8283 if Is_Subprogram_Or_Generic_Subprogram (E) then
8284 Subp := E;
8286 -- An access to subprogram is also allowed
8288 elsif Is_Access_Type (E)
8289 and then Ekind (Designated_Type (E)) = E_Subprogram_Type
8290 then
8291 Subp := Designated_Type (E);
8293 -- Allow internal call to set convention of subprogram type
8295 elsif Ekind (E) = E_Subprogram_Type then
8296 Subp := E;
8298 else
8299 Error_Pragma_Arg
8300 ("argument of pragma% must be subprogram or access type",
8301 Arg2);
8302 Subp := Empty;
8303 end if;
8305 -- ISO C requires a named parameter before the ellipsis, so a
8306 -- variadic C function taking 0 fixed parameter cannot exist.
8308 if C = Convention_C_Variadic_0 then
8310 Error_Msg_N
8311 ("??C_Variadic_0 cannot be used for an 'I'S'O C function",
8312 Get_Pragma_Arg (Arg2));
8314 -- Now check the number of parameters of the subprogram and give
8315 -- an error if it is lower than n.
8317 elsif Present (Subp) then
8318 declare
8319 Minimum : constant Nat :=
8320 Convention_Id'Pos (C) -
8321 Convention_Id'Pos (Convention_C_Variadic_0);
8323 Count : Nat;
8324 Formal : Entity_Id;
8326 begin
8327 Count := 0;
8328 Formal := First_Formal (Subp);
8329 while Present (Formal) loop
8330 Count := Count + 1;
8331 Next_Formal (Formal);
8332 end loop;
8334 if Count < Minimum then
8335 Error_Msg_Uint_1 := UI_From_Int (Minimum);
8336 Error_Pragma_Arg
8337 ("argument of pragma% must have at least"
8338 & "^ parameters", Arg2);
8339 end if;
8340 end;
8341 end if;
8343 -- Special checks for Stdcall
8345 elsif C = Convention_Stdcall then
8347 -- Several allowed cases
8349 if Is_Subprogram_Or_Generic_Subprogram (E)
8351 -- A variable is OK
8353 or else Ekind (E) = E_Variable
8355 -- A component as well. The entity does not have its Ekind
8356 -- set until the enclosing record declaration is fully
8357 -- analyzed.
8359 or else Nkind (Parent (E)) = N_Component_Declaration
8361 -- An access to subprogram is also allowed
8363 or else
8364 (Is_Access_Type (E)
8365 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
8367 -- Allow internal call to set convention of subprogram type
8369 or else Ekind (E) = E_Subprogram_Type
8370 then
8371 null;
8373 else
8374 Error_Pragma_Arg
8375 ("argument of pragma% must be subprogram or access type",
8376 Arg2);
8377 end if;
8378 end if;
8380 Set_Convention_From_Pragma (E);
8382 -- Deal with non-subprogram cases
8384 if not Is_Subprogram_Or_Generic_Subprogram (E) then
8385 if Is_Type (E) then
8387 -- The pragma must apply to a first subtype, but it can also
8388 -- apply to a generic type in a generic formal part, in which
8389 -- case it will also appear in the corresponding instance.
8391 if Is_Generic_Type (E) or else In_Instance then
8392 null;
8393 else
8394 Check_First_Subtype (Arg2);
8395 end if;
8397 Set_Convention_From_Pragma (Base_Type (E));
8399 -- For access subprograms, we must set the convention on the
8400 -- internally generated directly designated type as well.
8402 if Ekind (E) = E_Access_Subprogram_Type then
8403 Set_Convention_From_Pragma (Directly_Designated_Type (E));
8404 end if;
8405 end if;
8407 -- For the subprogram case, set proper convention for all homonyms
8408 -- in same scope and the same declarative part, i.e. the same
8409 -- compilation unit.
8411 else
8412 -- Treat a pragma Import as an implicit body, and pragma import
8413 -- as implicit reference (for navigation in GNAT Studio).
8415 if Prag_Id = Pragma_Import then
8416 Generate_Reference (E, Id, 'b');
8418 -- For exported entities we restrict the generation of references
8419 -- to entities exported to foreign languages since entities
8420 -- exported to Ada do not provide further information to
8421 -- GNAT Studio and add undesired references to the output of the
8422 -- gnatxref tool.
8424 elsif Prag_Id = Pragma_Export
8425 and then Convention (E) /= Convention_Ada
8426 then
8427 Generate_Reference (E, Id, 'i');
8428 end if;
8430 -- If the pragma comes from an aspect, it only applies to the
8431 -- given entity, not its homonyms.
8433 if From_Aspect_Specification (N) then
8434 if C = Convention_Intrinsic
8435 and then Nkind (Ent) = N_Defining_Operator_Symbol
8436 then
8437 if Is_Fixed_Point_Type (Etype (Ent))
8438 or else Is_Fixed_Point_Type (Etype (First_Entity (Ent)))
8439 or else Is_Fixed_Point_Type (Etype (Last_Entity (Ent)))
8440 then
8441 Error_Msg_N
8442 ("no intrinsic operator available for this fixed-point "
8443 & "operation", N);
8444 Error_Msg_N
8445 ("\use expression functions with the desired "
8446 & "conversions made explicit", N);
8447 end if;
8448 end if;
8450 return;
8451 end if;
8453 -- Otherwise Loop through the homonyms of the pragma argument's
8454 -- entity, an apply convention to those in the current scope.
8456 Comp_Unit := Get_Source_Unit (E);
8457 E1 := Ent;
8459 loop
8460 E1 := Homonym (E1);
8461 exit when No (E1) or else Scope (E1) /= Current_Scope;
8463 -- Ignore entry for which convention is already set
8465 if Has_Convention_Pragma (E1) then
8466 goto Continue;
8467 end if;
8469 if Is_Subprogram (E1)
8470 and then Nkind (Parent (Declaration_Node (E1))) =
8471 N_Subprogram_Body
8472 and then not Relaxed_RM_Semantics
8473 then
8474 Set_Has_Completion (E); -- to prevent cascaded error
8475 Error_Pragma_Ref
8476 ("pragma% requires separate spec and must come before "
8477 & "body#", E1);
8478 end if;
8480 -- Do not set the pragma on inherited operations or on formal
8481 -- subprograms.
8483 if Comes_From_Source (E1)
8484 and then Comp_Unit = Get_Source_Unit (E1)
8485 and then not Is_Formal_Subprogram (E1)
8486 and then Nkind (Original_Node (Parent (E1))) /=
8487 N_Full_Type_Declaration
8488 then
8489 if Present (Alias (E1))
8490 and then Scope (E1) /= Scope (Alias (E1))
8491 then
8492 Error_Pragma_Ref
8493 ("cannot apply pragma% to non-local entity& declared#",
8494 E1);
8495 end if;
8497 Set_Convention_From_Pragma (E1);
8499 if Prag_Id = Pragma_Import then
8500 Generate_Reference (E1, Id, 'b');
8501 end if;
8502 end if;
8504 <<Continue>>
8505 null;
8506 end loop;
8507 end if;
8508 end Process_Convention;
8510 ----------------------------------------
8511 -- Process_Disable_Enable_Atomic_Sync --
8512 ----------------------------------------
8514 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
8515 begin
8516 Check_No_Identifiers;
8517 Check_At_Most_N_Arguments (1);
8519 -- Modeled internally as
8520 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
8522 Rewrite (N,
8523 Make_Pragma (Loc,
8524 Chars => Nam,
8525 Pragma_Argument_Associations => New_List (
8526 Make_Pragma_Argument_Association (Loc,
8527 Expression =>
8528 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
8530 if Present (Arg1) then
8531 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
8532 end if;
8534 Analyze (N);
8535 end Process_Disable_Enable_Atomic_Sync;
8537 -------------------------------------------------
8538 -- Process_Extended_Import_Export_Internal_Arg --
8539 -------------------------------------------------
8541 procedure Process_Extended_Import_Export_Internal_Arg
8542 (Arg_Internal : Node_Id := Empty)
8544 begin
8545 if No (Arg_Internal) then
8546 Error_Pragma ("Internal parameter required for pragma%");
8547 end if;
8549 if Nkind (Arg_Internal) = N_Identifier then
8550 null;
8552 elsif Nkind (Arg_Internal) = N_Operator_Symbol
8553 and then (Prag_Id = Pragma_Import_Function
8554 or else
8555 Prag_Id = Pragma_Export_Function)
8556 then
8557 null;
8559 else
8560 Error_Pragma_Arg
8561 ("wrong form for Internal parameter for pragma%", Arg_Internal);
8562 end if;
8564 Check_Arg_Is_Local_Name (Arg_Internal);
8565 end Process_Extended_Import_Export_Internal_Arg;
8567 --------------------------------------------------
8568 -- Process_Extended_Import_Export_Object_Pragma --
8569 --------------------------------------------------
8571 procedure Process_Extended_Import_Export_Object_Pragma
8572 (Arg_Internal : Node_Id;
8573 Arg_External : Node_Id;
8574 Arg_Size : Node_Id)
8576 Def_Id : Entity_Id;
8578 begin
8579 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8580 Def_Id := Entity (Arg_Internal);
8582 if Ekind (Def_Id) not in E_Constant | E_Variable then
8583 Error_Pragma_Arg
8584 ("pragma% must designate an object", Arg_Internal);
8585 end if;
8587 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
8588 or else
8589 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
8590 then
8591 Error_Pragma_Arg
8592 ("previous Common/Psect_Object applies, pragma % not permitted",
8593 Arg_Internal);
8594 end if;
8596 if Rep_Item_Too_Late (Def_Id, N) then
8597 raise Pragma_Exit;
8598 end if;
8600 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
8602 if Present (Arg_Size) then
8603 Check_Arg_Is_External_Name (Arg_Size);
8604 end if;
8606 -- Export_Object case
8608 if Prag_Id = Pragma_Export_Object then
8609 if not Is_Library_Level_Entity (Def_Id) then
8610 Error_Pragma_Arg
8611 ("argument for pragma% must be library level entity",
8612 Arg_Internal);
8613 end if;
8615 if Ekind (Current_Scope) = E_Generic_Package then
8616 Error_Pragma ("pragma& cannot appear in a generic unit");
8617 end if;
8619 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
8620 Error_Pragma_Arg
8621 ("exported object must have compile time known size",
8622 Arg_Internal);
8623 end if;
8625 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
8626 Error_Msg_N ("??duplicate Export_Object pragma", N);
8627 else
8628 Set_Exported (Def_Id, Arg_Internal);
8629 end if;
8631 -- Import_Object case
8633 else
8634 if Is_Concurrent_Type (Etype (Def_Id)) then
8635 Error_Pragma_Arg
8636 ("cannot use pragma% for task/protected object",
8637 Arg_Internal);
8638 end if;
8640 if Ekind (Def_Id) = E_Constant then
8641 Error_Pragma_Arg
8642 ("cannot import a constant", Arg_Internal);
8643 end if;
8645 if Warn_On_Export_Import
8646 and then Has_Discriminants (Etype (Def_Id))
8647 then
8648 Error_Msg_N
8649 ("imported value must be initialized??", Arg_Internal);
8650 end if;
8652 if Warn_On_Export_Import
8653 and then Is_Access_Type (Etype (Def_Id))
8654 then
8655 Error_Pragma_Arg
8656 ("cannot import object of an access type??", Arg_Internal);
8657 end if;
8659 if Warn_On_Export_Import
8660 and then Is_Imported (Def_Id)
8661 then
8662 Error_Msg_N ("??duplicate Import_Object pragma", N);
8664 -- Check for explicit initialization present. Note that an
8665 -- initialization generated by the code generator, e.g. for an
8666 -- access type, does not count here.
8668 elsif Present (Expression (Parent (Def_Id)))
8669 and then
8670 Comes_From_Source
8671 (Original_Node (Expression (Parent (Def_Id))))
8672 then
8673 Error_Msg_Sloc := Sloc (Def_Id);
8674 Error_Pragma_Arg
8675 ("imported entities cannot be initialized (RM B.1(24))",
8676 "\no initialization allowed for & declared#", Arg1);
8677 else
8678 Set_Imported (Def_Id);
8679 Note_Possible_Modification (Arg_Internal, Sure => False);
8680 end if;
8681 end if;
8682 end Process_Extended_Import_Export_Object_Pragma;
8684 ------------------------------------------------------
8685 -- Process_Extended_Import_Export_Subprogram_Pragma --
8686 ------------------------------------------------------
8688 procedure Process_Extended_Import_Export_Subprogram_Pragma
8689 (Arg_Internal : Node_Id;
8690 Arg_External : Node_Id;
8691 Arg_Parameter_Types : Node_Id;
8692 Arg_Result_Type : Node_Id := Empty;
8693 Arg_Mechanism : Node_Id;
8694 Arg_Result_Mechanism : Node_Id := Empty)
8696 Ent : Entity_Id;
8697 Def_Id : Entity_Id;
8698 Hom_Id : Entity_Id;
8699 Formal : Entity_Id;
8700 Ambiguous : Boolean;
8701 Match : Boolean;
8703 function Same_Base_Type
8704 (Ptype : Node_Id;
8705 Formal : Entity_Id) return Boolean;
8706 -- Determines if Ptype references the type of Formal. Note that only
8707 -- the base types need to match according to the spec. Ptype here is
8708 -- the argument from the pragma, which is either a type name, or an
8709 -- access attribute.
8711 --------------------
8712 -- Same_Base_Type --
8713 --------------------
8715 function Same_Base_Type
8716 (Ptype : Node_Id;
8717 Formal : Entity_Id) return Boolean
8719 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
8720 Pref : Node_Id;
8722 begin
8723 -- Case where pragma argument is typ'Access
8725 if Nkind (Ptype) = N_Attribute_Reference
8726 and then Attribute_Name (Ptype) = Name_Access
8727 then
8728 Pref := Prefix (Ptype);
8729 Find_Type (Pref);
8731 if not Is_Entity_Name (Pref)
8732 or else Entity (Pref) = Any_Type
8733 then
8734 raise Pragma_Exit;
8735 end if;
8737 -- We have a match if the corresponding argument is of an
8738 -- anonymous access type, and its designated type matches the
8739 -- type of the prefix of the access attribute
8741 return Ekind (Ftyp) = E_Anonymous_Access_Type
8742 and then Base_Type (Entity (Pref)) =
8743 Base_Type (Etype (Designated_Type (Ftyp)));
8745 -- Case where pragma argument is a type name
8747 else
8748 Find_Type (Ptype);
8750 if not Is_Entity_Name (Ptype)
8751 or else Entity (Ptype) = Any_Type
8752 then
8753 raise Pragma_Exit;
8754 end if;
8756 -- We have a match if the corresponding argument is of the type
8757 -- given in the pragma (comparing base types)
8759 return Base_Type (Entity (Ptype)) = Ftyp;
8760 end if;
8761 end Same_Base_Type;
8763 -- Start of processing for
8764 -- Process_Extended_Import_Export_Subprogram_Pragma
8766 begin
8767 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8768 Ent := Empty;
8769 Ambiguous := False;
8771 -- Loop through homonyms (overloadings) of the entity
8773 Hom_Id := Entity (Arg_Internal);
8774 while Present (Hom_Id) loop
8775 Def_Id := Get_Base_Subprogram (Hom_Id);
8777 -- We need a subprogram in the current scope
8779 if not Is_Subprogram (Def_Id)
8780 or else Scope (Def_Id) /= Current_Scope
8781 then
8782 null;
8784 else
8785 Match := True;
8787 -- Pragma cannot apply to subprogram body
8789 if Is_Subprogram (Def_Id)
8790 and then Nkind (Parent (Declaration_Node (Def_Id))) =
8791 N_Subprogram_Body
8792 then
8793 Error_Pragma
8794 ("pragma% requires separate spec and must come before "
8795 & "body");
8796 end if;
8798 -- Test result type if given, note that the result type
8799 -- parameter can only be present for the function cases.
8801 if Present (Arg_Result_Type)
8802 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
8803 then
8804 Match := False;
8806 elsif Etype (Def_Id) /= Standard_Void_Type
8807 and then
8808 Pname in Name_Export_Procedure | Name_Import_Procedure
8809 then
8810 Match := False;
8812 -- Test parameter types if given. Note that this parameter has
8813 -- not been analyzed (and must not be, since it is semantic
8814 -- nonsense), so we get it as the parser left it.
8816 elsif Present (Arg_Parameter_Types) then
8817 Check_Matching_Types : declare
8818 Formal : Entity_Id;
8819 Ptype : Node_Id;
8821 begin
8822 Formal := First_Formal (Def_Id);
8824 if Nkind (Arg_Parameter_Types) = N_Null then
8825 if Present (Formal) then
8826 Match := False;
8827 end if;
8829 -- A list of one type, e.g. (List) is parsed as a
8830 -- parenthesized expression.
8832 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
8833 and then Paren_Count (Arg_Parameter_Types) = 1
8834 then
8835 if No (Formal)
8836 or else Present (Next_Formal (Formal))
8837 then
8838 Match := False;
8839 else
8840 Match :=
8841 Same_Base_Type (Arg_Parameter_Types, Formal);
8842 end if;
8844 -- A list of more than one type is parsed as a aggregate
8846 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
8847 and then Paren_Count (Arg_Parameter_Types) = 0
8848 then
8849 Ptype := First (Expressions (Arg_Parameter_Types));
8850 while Present (Ptype) or else Present (Formal) loop
8851 if No (Ptype)
8852 or else No (Formal)
8853 or else not Same_Base_Type (Ptype, Formal)
8854 then
8855 Match := False;
8856 exit;
8857 else
8858 Next_Formal (Formal);
8859 Next (Ptype);
8860 end if;
8861 end loop;
8863 -- Anything else is of the wrong form
8865 else
8866 Error_Pragma_Arg
8867 ("wrong form for Parameter_Types parameter",
8868 Arg_Parameter_Types);
8869 end if;
8870 end Check_Matching_Types;
8871 end if;
8873 -- Match is now False if the entry we found did not match
8874 -- either a supplied Parameter_Types or Result_Types argument
8876 if Match then
8877 if No (Ent) then
8878 Ent := Def_Id;
8880 -- Ambiguous case, the flag Ambiguous shows if we already
8881 -- detected this and output the initial messages.
8883 else
8884 if not Ambiguous then
8885 Ambiguous := True;
8886 Error_Msg_Name_1 := Pname;
8887 Error_Msg_N
8888 ("pragma% does not uniquely identify subprogram!",
8890 Error_Msg_Sloc := Sloc (Ent);
8891 Error_Msg_N ("matching subprogram #!", N);
8892 Ent := Empty;
8893 end if;
8895 Error_Msg_Sloc := Sloc (Def_Id);
8896 Error_Msg_N ("matching subprogram #!", N);
8897 end if;
8898 end if;
8899 end if;
8901 Hom_Id := Homonym (Hom_Id);
8902 end loop;
8904 -- See if we found an entry
8906 if No (Ent) then
8907 if not Ambiguous then
8908 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
8909 Error_Pragma
8910 ("pragma% cannot be given for generic subprogram");
8911 else
8912 Error_Pragma
8913 ("pragma% does not identify local subprogram");
8914 end if;
8915 end if;
8917 return;
8918 end if;
8920 -- Import pragmas must be for imported entities
8922 if Prag_Id = Pragma_Import_Function
8923 or else
8924 Prag_Id = Pragma_Import_Procedure
8925 or else
8926 Prag_Id = Pragma_Import_Valued_Procedure
8927 then
8928 if not Is_Imported (Ent) then
8929 Error_Pragma
8930 ("pragma Import or Interface must precede pragma%");
8931 end if;
8933 -- Here we have the Export case which can set the entity as exported
8935 -- But does not do so if the specified external name is null, since
8936 -- that is taken as a signal in DEC Ada 83 (with which we want to be
8937 -- compatible) to request no external name.
8939 elsif Nkind (Arg_External) = N_String_Literal
8940 and then String_Length (Strval (Arg_External)) = 0
8941 then
8942 null;
8944 -- In all other cases, set entity as exported
8946 else
8947 Set_Exported (Ent, Arg_Internal);
8948 end if;
8950 -- Special processing for Valued_Procedure cases
8952 if Prag_Id = Pragma_Import_Valued_Procedure
8953 or else
8954 Prag_Id = Pragma_Export_Valued_Procedure
8955 then
8956 Formal := First_Formal (Ent);
8958 if No (Formal) then
8959 Error_Pragma ("at least one parameter required for pragma%");
8961 elsif Ekind (Formal) /= E_Out_Parameter then
8962 Error_Pragma ("first parameter must have mode out for pragma%");
8964 else
8965 Set_Is_Valued_Procedure (Ent);
8966 end if;
8967 end if;
8969 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
8971 -- Process Result_Mechanism argument if present. We have already
8972 -- checked that this is only allowed for the function case.
8974 if Present (Arg_Result_Mechanism) then
8975 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
8976 end if;
8978 -- Process Mechanism parameter if present. Note that this parameter
8979 -- is not analyzed, and must not be analyzed since it is semantic
8980 -- nonsense, so we get it in exactly as the parser left it.
8982 if Present (Arg_Mechanism) then
8983 declare
8984 Formal : Entity_Id;
8985 Massoc : Node_Id;
8986 Mname : Node_Id;
8987 Choice : Node_Id;
8989 begin
8990 -- A single mechanism association without a formal parameter
8991 -- name is parsed as a parenthesized expression. All other
8992 -- cases are parsed as aggregates, so we rewrite the single
8993 -- parameter case as an aggregate for consistency.
8995 if Nkind (Arg_Mechanism) /= N_Aggregate
8996 and then Paren_Count (Arg_Mechanism) = 1
8997 then
8998 Rewrite (Arg_Mechanism,
8999 Make_Aggregate (Sloc (Arg_Mechanism),
9000 Expressions => New_List (
9001 Relocate_Node (Arg_Mechanism))));
9002 end if;
9004 -- Case of only mechanism name given, applies to all formals
9006 if Nkind (Arg_Mechanism) /= N_Aggregate then
9007 Formal := First_Formal (Ent);
9008 while Present (Formal) loop
9009 Set_Mechanism_Value (Formal, Arg_Mechanism);
9010 Next_Formal (Formal);
9011 end loop;
9013 -- Case of list of mechanism associations given
9015 else
9016 if Null_Record_Present (Arg_Mechanism) then
9017 Error_Pragma_Arg
9018 ("inappropriate form for Mechanism parameter",
9019 Arg_Mechanism);
9020 end if;
9022 -- Deal with positional ones first
9024 Formal := First_Formal (Ent);
9026 if Present (Expressions (Arg_Mechanism)) then
9027 Mname := First (Expressions (Arg_Mechanism));
9028 while Present (Mname) loop
9029 if No (Formal) then
9030 Error_Pragma_Arg
9031 ("too many mechanism associations", Mname);
9032 end if;
9034 Set_Mechanism_Value (Formal, Mname);
9035 Next_Formal (Formal);
9036 Next (Mname);
9037 end loop;
9038 end if;
9040 -- Deal with named entries
9042 if Present (Component_Associations (Arg_Mechanism)) then
9043 Massoc := First (Component_Associations (Arg_Mechanism));
9044 while Present (Massoc) loop
9045 Choice := First (Choices (Massoc));
9047 if Nkind (Choice) /= N_Identifier
9048 or else Present (Next (Choice))
9049 then
9050 Error_Pragma_Arg
9051 ("incorrect form for mechanism association",
9052 Massoc);
9053 end if;
9055 Formal := First_Formal (Ent);
9056 loop
9057 if No (Formal) then
9058 Error_Pragma_Arg
9059 ("parameter name & not present", Choice);
9060 end if;
9062 if Chars (Choice) = Chars (Formal) then
9063 Set_Mechanism_Value
9064 (Formal, Expression (Massoc));
9066 -- Set entity on identifier for proper tree
9067 -- structure.
9069 Set_Entity (Choice, Formal);
9071 exit;
9072 end if;
9074 Next_Formal (Formal);
9075 end loop;
9077 Next (Massoc);
9078 end loop;
9079 end if;
9080 end if;
9081 end;
9082 end if;
9083 end Process_Extended_Import_Export_Subprogram_Pragma;
9085 --------------------------
9086 -- Process_Generic_List --
9087 --------------------------
9089 procedure Process_Generic_List is
9090 Arg : Node_Id;
9091 Exp : Node_Id;
9093 begin
9094 Check_No_Identifiers;
9095 Check_At_Least_N_Arguments (1);
9097 -- Check all arguments are names of generic units or instances
9099 Arg := Arg1;
9100 while Present (Arg) loop
9101 Exp := Get_Pragma_Arg (Arg);
9102 Analyze (Exp);
9104 if not Is_Entity_Name (Exp)
9105 or else
9106 (not Is_Generic_Instance (Entity (Exp))
9107 and then
9108 not Is_Generic_Unit (Entity (Exp)))
9109 then
9110 Error_Pragma_Arg
9111 ("pragma% argument must be name of generic unit/instance",
9112 Arg);
9113 end if;
9115 Next (Arg);
9116 end loop;
9117 end Process_Generic_List;
9119 ------------------------------------
9120 -- Process_Import_Predefined_Type --
9121 ------------------------------------
9123 procedure Process_Import_Predefined_Type is
9124 Loc : constant Source_Ptr := Sloc (N);
9125 Elmt : Elmt_Id;
9126 Ftyp : Node_Id := Empty;
9127 Decl : Node_Id;
9128 Def : Node_Id;
9129 Nam : Name_Id;
9131 begin
9132 Nam := String_To_Name (Strval (Expression (Arg3)));
9134 Elmt := First_Elmt (Predefined_Float_Types);
9135 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
9136 Next_Elmt (Elmt);
9137 end loop;
9139 Ftyp := Node (Elmt);
9141 if Present (Ftyp) then
9143 -- Don't build a derived type declaration, because predefined C
9144 -- types have no declaration anywhere, so cannot really be named.
9145 -- Instead build a full type declaration, starting with an
9146 -- appropriate type definition is built
9148 if Is_Floating_Point_Type (Ftyp) then
9149 Def := Make_Floating_Point_Definition (Loc,
9150 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
9151 Make_Real_Range_Specification (Loc,
9152 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
9153 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
9155 -- Should never have a predefined type we cannot handle
9157 else
9158 raise Program_Error;
9159 end if;
9161 -- Build and insert a Full_Type_Declaration, which will be
9162 -- analyzed as soon as this list entry has been analyzed.
9164 Decl := Make_Full_Type_Declaration (Loc,
9165 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
9166 Type_Definition => Def);
9168 Insert_After (N, Decl);
9169 Mark_Rewrite_Insertion (Decl);
9171 else
9172 Error_Pragma_Arg ("no matching type found for pragma%", Arg2);
9173 end if;
9174 end Process_Import_Predefined_Type;
9176 ---------------------------------
9177 -- Process_Import_Or_Interface --
9178 ---------------------------------
9180 procedure Process_Import_Or_Interface is
9181 C : Convention_Id;
9182 Def_Id : Entity_Id;
9183 Hom_Id : Entity_Id;
9185 begin
9186 -- In Relaxed_RM_Semantics, support old Ada 83 style:
9187 -- pragma Import (Entity, "external name");
9189 if Relaxed_RM_Semantics
9190 and then Arg_Count = 2
9191 and then Prag_Id = Pragma_Import
9192 and then Nkind (Expression (Arg2)) = N_String_Literal
9193 then
9194 C := Convention_C;
9195 Def_Id := Get_Pragma_Arg (Arg1);
9196 Analyze (Def_Id);
9198 if not Is_Entity_Name (Def_Id) then
9199 Error_Pragma_Arg ("entity name required", Arg1);
9200 end if;
9202 Def_Id := Entity (Def_Id);
9203 Kill_Size_Check_Code (Def_Id);
9204 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
9206 else
9207 Process_Convention (C, Def_Id);
9209 -- A pragma that applies to a Ghost entity becomes Ghost for the
9210 -- purposes of legality checks and removal of ignored Ghost code.
9212 Mark_Ghost_Pragma (N, Def_Id);
9213 Kill_Size_Check_Code (Def_Id);
9214 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
9215 end if;
9217 -- Various error checks
9219 if Ekind (Def_Id) in E_Variable | E_Constant then
9221 -- We do not permit Import to apply to a renaming declaration
9223 if Present (Renamed_Object (Def_Id)) then
9224 Error_Pragma_Arg
9225 ("pragma% not allowed for object renaming", Arg2);
9227 -- User initialization is not allowed for imported object, but
9228 -- the object declaration may contain a default initialization,
9229 -- that will be discarded. Note that an explicit initialization
9230 -- only counts if it comes from source, otherwise it is simply
9231 -- the code generator making an implicit initialization explicit.
9233 elsif Present (Expression (Parent (Def_Id)))
9234 and then Comes_From_Source
9235 (Original_Node (Expression (Parent (Def_Id))))
9236 then
9237 -- Set imported flag to prevent cascaded errors
9239 Set_Is_Imported (Def_Id);
9241 Error_Msg_Sloc := Sloc (Def_Id);
9242 Error_Pragma_Arg
9243 ("no initialization allowed for declaration of& #",
9244 "\imported entities cannot be initialized (RM B.1(24))",
9245 Arg2);
9247 else
9248 -- If the pragma comes from an aspect specification the
9249 -- Is_Imported flag has already been set.
9251 if not From_Aspect_Specification (N) then
9252 Set_Imported (Def_Id);
9253 end if;
9255 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9257 -- Note that we do not set Is_Public here. That's because we
9258 -- only want to set it if there is no address clause, and we
9259 -- don't know that yet, so we delay that processing till
9260 -- freeze time.
9262 -- pragma Import completes deferred constants
9264 if Ekind (Def_Id) = E_Constant then
9265 Set_Has_Completion (Def_Id);
9266 end if;
9268 -- It is not possible to import a constant of an unconstrained
9269 -- array type (e.g. string) because there is no simple way to
9270 -- write a meaningful subtype for it.
9272 if Is_Array_Type (Etype (Def_Id))
9273 and then not Is_Constrained (Etype (Def_Id))
9274 then
9275 Error_Msg_NE
9276 ("imported constant& must have a constrained subtype",
9277 N, Def_Id);
9278 end if;
9279 end if;
9281 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9283 -- If the name is overloaded, pragma applies to all of the denoted
9284 -- entities in the same declarative part, unless the pragma comes
9285 -- from an aspect specification or was generated by the compiler
9286 -- (such as for pragma Provide_Shift_Operators).
9288 Hom_Id := Def_Id;
9289 while Present (Hom_Id) loop
9291 Def_Id := Get_Base_Subprogram (Hom_Id);
9293 -- Ignore inherited subprograms because the pragma will apply
9294 -- to the parent operation, which is the one called.
9296 if Is_Overloadable (Def_Id)
9297 and then Present (Alias (Def_Id))
9298 then
9299 null;
9301 -- If it is not a subprogram, it must be in an outer scope and
9302 -- pragma does not apply.
9304 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
9305 null;
9307 -- The pragma does not apply to primitives of interfaces
9309 elsif Is_Dispatching_Operation (Def_Id)
9310 and then Present (Find_Dispatching_Type (Def_Id))
9311 and then Is_Interface (Find_Dispatching_Type (Def_Id))
9312 then
9313 null;
9315 -- Verify that the homonym is in the same declarative part (not
9316 -- just the same scope). If the pragma comes from an aspect
9317 -- specification we know that it is part of the declaration.
9319 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
9320 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9321 and then not From_Aspect_Specification (N)
9322 then
9323 exit;
9325 else
9326 -- If the pragma comes from an aspect specification the
9327 -- Is_Imported flag has already been set.
9329 if not From_Aspect_Specification (N) then
9330 Set_Imported (Def_Id);
9331 end if;
9333 -- Reject an Import applied to an abstract subprogram
9335 if Is_Subprogram (Def_Id)
9336 and then Is_Abstract_Subprogram (Def_Id)
9337 then
9338 Error_Msg_Sloc := Sloc (Def_Id);
9339 Error_Msg_NE
9340 ("cannot import abstract subprogram& declared#",
9341 Arg2, Def_Id);
9342 end if;
9344 -- Special processing for Convention_Intrinsic
9346 if C = Convention_Intrinsic then
9348 -- Link_Name argument not allowed for intrinsic
9350 Check_No_Link_Name;
9352 Set_Is_Intrinsic_Subprogram (Def_Id);
9354 -- If no external name is present, then check that this
9355 -- is a valid intrinsic subprogram. If an external name
9356 -- is present, then this is handled by the back end.
9358 if No (Arg3) then
9359 Check_Intrinsic_Subprogram
9360 (Def_Id, Get_Pragma_Arg (Arg2));
9361 end if;
9362 end if;
9364 -- Verify that the subprogram does not have a completion
9365 -- through a renaming declaration. For other completions the
9366 -- pragma appears as a too late representation.
9368 declare
9369 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
9371 begin
9372 if Present (Decl)
9373 and then Nkind (Decl) = N_Subprogram_Declaration
9374 and then Present (Corresponding_Body (Decl))
9375 and then Nkind (Unit_Declaration_Node
9376 (Corresponding_Body (Decl))) =
9377 N_Subprogram_Renaming_Declaration
9378 then
9379 Error_Msg_Sloc := Sloc (Def_Id);
9380 Error_Msg_NE
9381 ("cannot import&, renaming already provided for "
9382 & "declaration #", N, Def_Id);
9383 end if;
9384 end;
9386 -- If the pragma comes from an aspect specification, there
9387 -- must be an Import aspect specified as well. In the rare
9388 -- case where Import is set to False, the suprogram needs to
9389 -- have a local completion.
9391 declare
9392 Imp_Aspect : constant Node_Id :=
9393 Find_Aspect (Def_Id, Aspect_Import);
9394 Expr : Node_Id;
9396 begin
9397 if Present (Imp_Aspect)
9398 and then Present (Expression (Imp_Aspect))
9399 then
9400 Expr := Expression (Imp_Aspect);
9401 Analyze_And_Resolve (Expr, Standard_Boolean);
9403 if Is_Entity_Name (Expr)
9404 and then Entity (Expr) = Standard_True
9405 then
9406 Set_Has_Completion (Def_Id);
9407 end if;
9409 -- If there is no expression, the default is True, as for
9410 -- all boolean aspects. Same for the older pragma.
9412 else
9413 Set_Has_Completion (Def_Id);
9414 end if;
9415 end;
9417 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9418 end if;
9420 if Is_Compilation_Unit (Hom_Id) then
9422 -- Its possible homonyms are not affected by the pragma.
9423 -- Such homonyms might be present in the context of other
9424 -- units being compiled.
9426 exit;
9428 elsif From_Aspect_Specification (N) then
9429 exit;
9431 -- If the pragma was created by the compiler, then we don't
9432 -- want it to apply to other homonyms. This kind of case can
9433 -- occur when using pragma Provide_Shift_Operators, which
9434 -- generates implicit shift and rotate operators with Import
9435 -- pragmas that might apply to earlier explicit or implicit
9436 -- declarations marked with Import (for example, coming from
9437 -- an earlier pragma Provide_Shift_Operators for another type),
9438 -- and we don't generally want other homonyms being treated
9439 -- as imported or the pragma flagged as an illegal duplicate.
9441 elsif not Comes_From_Source (N) then
9442 exit;
9444 else
9445 Hom_Id := Homonym (Hom_Id);
9446 end if;
9447 end loop;
9449 -- Import a CPP class
9451 elsif C = Convention_CPP
9452 and then (Is_Record_Type (Def_Id)
9453 or else Ekind (Def_Id) = E_Incomplete_Type)
9454 then
9455 if Ekind (Def_Id) = E_Incomplete_Type then
9456 if Present (Full_View (Def_Id)) then
9457 Def_Id := Full_View (Def_Id);
9459 else
9460 Error_Msg_N
9461 ("cannot import 'C'P'P type before full declaration seen",
9462 Get_Pragma_Arg (Arg2));
9464 -- Although we have reported the error we decorate it as
9465 -- CPP_Class to avoid reporting spurious errors
9467 Set_Is_CPP_Class (Def_Id);
9468 return;
9469 end if;
9470 end if;
9472 -- Types treated as CPP classes must be declared limited (note:
9473 -- this used to be a warning but there is no real benefit to it
9474 -- since we did effectively intend to treat the type as limited
9475 -- anyway).
9477 if not Is_Limited_Type (Def_Id) then
9478 Error_Msg_N
9479 ("imported 'C'P'P type must be limited",
9480 Get_Pragma_Arg (Arg2));
9481 end if;
9483 if Etype (Def_Id) /= Def_Id
9484 and then not Is_CPP_Class (Root_Type (Def_Id))
9485 then
9486 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
9487 end if;
9489 Set_Is_CPP_Class (Def_Id);
9491 -- Imported CPP types must not have discriminants (because C++
9492 -- classes do not have discriminants).
9494 if Has_Discriminants (Def_Id) then
9495 Error_Msg_N
9496 ("imported 'C'P'P type cannot have discriminants",
9497 First (Discriminant_Specifications
9498 (Declaration_Node (Def_Id))));
9499 end if;
9501 -- Check that components of imported CPP types do not have default
9502 -- expressions. For private types this check is performed when the
9503 -- full view is analyzed (see Process_Full_View).
9505 if not Is_Private_Type (Def_Id) then
9506 Check_CPP_Type_Has_No_Defaults (Def_Id);
9507 end if;
9509 -- Import a CPP exception
9511 elsif C = Convention_CPP
9512 and then Ekind (Def_Id) = E_Exception
9513 then
9514 if No (Arg3) then
9515 Error_Pragma_Arg
9516 ("'External_'Name arguments is required for 'Cpp exception",
9517 Arg3);
9518 else
9519 -- As only a string is allowed, Check_Arg_Is_External_Name
9520 -- isn't called.
9522 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9523 end if;
9525 if Present (Arg4) then
9526 Error_Pragma_Arg
9527 ("Link_Name argument not allowed for imported Cpp exception",
9528 Arg4);
9529 end if;
9531 -- Do not call Set_Interface_Name as the name of the exception
9532 -- shouldn't be modified (and in particular it shouldn't be
9533 -- the External_Name). For exceptions, the External_Name is the
9534 -- name of the RTTI structure.
9536 -- ??? Emit an error if pragma Import/Export_Exception is present
9538 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
9539 Check_No_Link_Name;
9540 Check_Arg_Count (3);
9541 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9543 Process_Import_Predefined_Type;
9545 else
9546 Error_Pragma_Arg
9547 ("second argument of pragma% must be object, subprogram "
9548 & "or incomplete type",
9549 Arg2);
9550 end if;
9552 -- If this pragma applies to a compilation unit, then the unit, which
9553 -- is a subprogram, does not require (or allow) a body. We also do
9554 -- not need to elaborate imported procedures.
9556 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9557 declare
9558 Cunit : constant Node_Id := Parent (Parent (N));
9559 begin
9560 Set_Body_Required (Cunit, False);
9561 end;
9562 end if;
9563 end Process_Import_Or_Interface;
9565 --------------------
9566 -- Process_Inline --
9567 --------------------
9569 procedure Process_Inline (Status : Inline_Status) is
9570 Applies : Boolean;
9571 Assoc : Node_Id;
9572 Decl : Node_Id;
9573 Subp : Entity_Id;
9574 Subp_Id : Node_Id;
9576 Ghost_Error_Posted : Boolean := False;
9577 -- Flag set when an error concerning the illegal mix of Ghost and
9578 -- non-Ghost subprograms is emitted.
9580 Ghost_Id : Entity_Id := Empty;
9581 -- The entity of the first Ghost subprogram encountered while
9582 -- processing the arguments of the pragma.
9584 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id);
9585 -- Verify the placement of pragma Inline_Always with respect to the
9586 -- initial declaration of subprogram Spec_Id.
9588 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
9589 -- Returns True if it can be determined at this stage that inlining
9590 -- is not possible, for example if the body is available and contains
9591 -- exception handlers, we prevent inlining, since otherwise we can
9592 -- get undefined symbols at link time. This function also emits a
9593 -- warning if the pragma appears too late.
9595 -- ??? is business with link symbols still valid, or does it relate
9596 -- to front end ZCX which is being phased out ???
9598 procedure Make_Inline (Subp : Entity_Id);
9599 -- Subp is the defining unit name of the subprogram declaration. If
9600 -- the pragma is valid, call Set_Inline_Flags on Subp, as well as on
9601 -- the corresponding body, if there is one present.
9603 procedure Set_Inline_Flags (Subp : Entity_Id);
9604 -- Set Has_Pragma_{No_Inline,Inline,Inline_Always} flag on Subp.
9605 -- Also set or clear Is_Inlined flag on Subp depending on Status.
9607 -----------------------------------
9608 -- Check_Inline_Always_Placement --
9609 -----------------------------------
9611 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id) is
9612 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id);
9614 function Compilation_Unit_OK return Boolean;
9615 pragma Inline (Compilation_Unit_OK);
9616 -- Determine whether pragma Inline_Always applies to a compatible
9617 -- compilation unit denoted by Spec_Id.
9619 function Declarative_List_OK return Boolean;
9620 pragma Inline (Declarative_List_OK);
9621 -- Determine whether the initial declaration of subprogram Spec_Id
9622 -- and the pragma appear in compatible declarative lists.
9624 function Subprogram_Body_OK return Boolean;
9625 pragma Inline (Subprogram_Body_OK);
9626 -- Determine whether pragma Inline_Always applies to a compatible
9627 -- subprogram body denoted by Spec_Id.
9629 -------------------------
9630 -- Compilation_Unit_OK --
9631 -------------------------
9633 function Compilation_Unit_OK return Boolean is
9634 Comp_Unit : constant Node_Id := Parent (Spec_Decl);
9636 begin
9637 -- The pragma appears after the initial declaration of a
9638 -- compilation unit.
9640 -- procedure Comp_Unit;
9641 -- pragma Inline_Always (Comp_Unit);
9643 -- Note that for compatibility reasons, the following case is
9644 -- also accepted.
9646 -- procedure Stand_Alone_Body_Comp_Unit is
9647 -- ...
9648 -- end Stand_Alone_Body_Comp_Unit;
9649 -- pragma Inline_Always (Stand_Alone_Body_Comp_Unit);
9651 return
9652 Nkind (Comp_Unit) = N_Compilation_Unit
9653 and then Present (Aux_Decls_Node (Comp_Unit))
9654 and then Is_List_Member (N)
9655 and then List_Containing (N) =
9656 Pragmas_After (Aux_Decls_Node (Comp_Unit));
9657 end Compilation_Unit_OK;
9659 -------------------------
9660 -- Declarative_List_OK --
9661 -------------------------
9663 function Declarative_List_OK return Boolean is
9664 Context : constant Node_Id := Parent (Spec_Decl);
9666 Init_Decl : Node_Id;
9667 Init_List : List_Id;
9668 Prag_List : List_Id;
9670 begin
9671 -- Determine the proper initial declaration. In general this is
9672 -- the declaration node of the subprogram except when the input
9673 -- denotes a generic instantiation.
9675 -- procedure Inst is new Gen;
9676 -- pragma Inline_Always (Inst);
9678 -- In this case the original subprogram is moved inside an
9679 -- anonymous package while pragma Inline_Always remains at the
9680 -- level of the anonymous package. Use the declaration of the
9681 -- package because it reflects the placement of the original
9682 -- instantiation.
9684 -- package Anon_Pack is
9685 -- procedure Inst is ... end Inst; -- original
9686 -- end Anon_Pack;
9688 -- procedure Inst renames Anon_Pack.Inst;
9689 -- pragma Inline_Always (Inst);
9691 if Is_Generic_Instance (Spec_Id) then
9692 Init_Decl := Parent (Parent (Spec_Decl));
9693 pragma Assert (Nkind (Init_Decl) = N_Package_Declaration);
9694 else
9695 Init_Decl := Spec_Decl;
9696 end if;
9698 if Is_List_Member (Init_Decl) and then Is_List_Member (N) then
9699 Init_List := List_Containing (Init_Decl);
9700 Prag_List := List_Containing (N);
9702 -- The pragma and then initial declaration appear within the
9703 -- same declarative list.
9705 if Init_List = Prag_List then
9706 return True;
9708 -- A special case of the above is when both the pragma and
9709 -- the initial declaration appear in different lists of a
9710 -- package spec, protected definition, or a task definition.
9712 -- package Pack is
9713 -- procedure Proc;
9714 -- private
9715 -- pragma Inline_Always (Proc);
9716 -- end Pack;
9718 elsif Nkind (Context) in N_Package_Specification
9719 | N_Protected_Definition
9720 | N_Task_Definition
9721 and then Init_List = Visible_Declarations (Context)
9722 and then Prag_List = Private_Declarations (Context)
9723 then
9724 return True;
9725 end if;
9726 end if;
9728 return False;
9729 end Declarative_List_OK;
9731 ------------------------
9732 -- Subprogram_Body_OK --
9733 ------------------------
9735 function Subprogram_Body_OK return Boolean is
9736 Body_Decl : Node_Id;
9738 begin
9739 -- The pragma appears within the declarative list of a stand-
9740 -- alone subprogram body.
9742 -- procedure Stand_Alone_Body is
9743 -- pragma Inline_Always (Stand_Alone_Body);
9744 -- begin
9745 -- ...
9746 -- end Stand_Alone_Body;
9748 -- The compiler creates a dummy spec in this case, however the
9749 -- pragma remains within the declarative list of the body.
9751 if Nkind (Spec_Decl) = N_Subprogram_Declaration
9752 and then not Comes_From_Source (Spec_Decl)
9753 and then Present (Corresponding_Body (Spec_Decl))
9754 then
9755 Body_Decl :=
9756 Unit_Declaration_Node (Corresponding_Body (Spec_Decl));
9758 if Present (Declarations (Body_Decl))
9759 and then Is_List_Member (N)
9760 and then List_Containing (N) = Declarations (Body_Decl)
9761 then
9762 return True;
9763 end if;
9764 end if;
9766 return False;
9767 end Subprogram_Body_OK;
9769 -- Start of processing for Check_Inline_Always_Placement
9771 begin
9772 -- This check is relevant only for pragma Inline_Always
9774 if Pname /= Name_Inline_Always then
9775 return;
9777 -- Nothing to do when the pragma is internally generated on the
9778 -- assumption that it is properly placed.
9780 elsif not Comes_From_Source (N) then
9781 return;
9783 -- Nothing to do for internally generated subprograms that act
9784 -- as accidental homonyms of a source subprogram being inlined.
9786 elsif not Comes_From_Source (Spec_Id) then
9787 return;
9789 -- Nothing to do for generic formal subprograms that act as
9790 -- homonyms of another source subprogram being inlined.
9792 elsif Is_Formal_Subprogram (Spec_Id) then
9793 return;
9795 elsif Compilation_Unit_OK
9796 or else Declarative_List_OK
9797 or else Subprogram_Body_OK
9798 then
9799 return;
9800 end if;
9802 -- At this point it is known that the pragma applies to or appears
9803 -- within a completing body, a completing stub, or a subunit.
9805 Error_Msg_Name_1 := Pname;
9806 Error_Msg_Name_2 := Chars (Spec_Id);
9807 Error_Msg_Sloc := Sloc (Spec_Id);
9809 Error_Msg_N
9810 ("pragma % must appear on initial declaration of subprogram "
9811 & "% defined #", N);
9812 end Check_Inline_Always_Placement;
9814 ---------------------------
9815 -- Inlining_Not_Possible --
9816 ---------------------------
9818 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
9819 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
9820 Stats : Node_Id;
9822 begin
9823 if Nkind (Decl) = N_Subprogram_Body then
9824 Stats := Handled_Statement_Sequence (Decl);
9825 return Present (Exception_Handlers (Stats))
9826 or else Present (At_End_Proc (Stats));
9828 elsif Nkind (Decl) = N_Subprogram_Declaration
9829 and then Present (Corresponding_Body (Decl))
9830 then
9831 if Analyzed (Corresponding_Body (Decl)) then
9832 Error_Msg_N ("pragma appears too late, ignored??", N);
9833 return True;
9835 -- If the subprogram is a renaming as body, the body is just a
9836 -- call to the renamed subprogram, and inlining is trivially
9837 -- possible.
9839 elsif
9840 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
9841 N_Subprogram_Renaming_Declaration
9842 then
9843 return False;
9845 else
9846 Stats :=
9847 Handled_Statement_Sequence
9848 (Unit_Declaration_Node (Corresponding_Body (Decl)));
9850 return
9851 Present (Exception_Handlers (Stats))
9852 or else Present (At_End_Proc (Stats));
9853 end if;
9855 else
9856 -- If body is not available, assume the best, the check is
9857 -- performed again when compiling enclosing package bodies.
9859 return False;
9860 end if;
9861 end Inlining_Not_Possible;
9863 -----------------
9864 -- Make_Inline --
9865 -----------------
9867 procedure Make_Inline (Subp : Entity_Id) is
9868 Kind : constant Entity_Kind := Ekind (Subp);
9869 Inner_Subp : Entity_Id := Subp;
9871 begin
9872 -- Ignore if bad type, avoid cascaded error
9874 if Etype (Subp) = Any_Type then
9875 Applies := True;
9876 return;
9878 -- If inlining is not possible, for now do not treat as an error
9880 elsif Status /= Suppressed
9881 and then Front_End_Inlining
9882 and then Inlining_Not_Possible (Subp)
9883 then
9884 Applies := True;
9885 return;
9887 -- Here we have a candidate for inlining, but we must exclude
9888 -- derived operations. Otherwise we would end up trying to inline
9889 -- a phantom declaration, and the result would be to drag in a
9890 -- body which has no direct inlining associated with it. That
9891 -- would not only be inefficient but would also result in the
9892 -- backend doing cross-unit inlining in cases where it was
9893 -- definitely inappropriate to do so.
9895 -- However, a simple Comes_From_Source test is insufficient, since
9896 -- we do want to allow inlining of generic instances which also do
9897 -- not come from source. We also need to recognize specs generated
9898 -- by the front-end for bodies that carry the pragma. Finally,
9899 -- predefined operators do not come from source but are not
9900 -- inlineable either.
9902 elsif Is_Generic_Instance (Subp)
9903 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
9904 then
9905 null;
9907 elsif not Comes_From_Source (Subp)
9908 and then Scope (Subp) /= Standard_Standard
9909 then
9910 Applies := True;
9911 return;
9912 end if;
9914 -- The referenced entity must either be the enclosing entity, or
9915 -- an entity declared within the current open scope.
9917 if Present (Scope (Subp))
9918 and then Scope (Subp) /= Current_Scope
9919 and then Subp /= Current_Scope
9920 then
9921 Error_Pragma_Arg
9922 ("argument of% must be entity in current scope", Assoc);
9923 return;
9924 end if;
9926 -- Processing for procedure, operator or function. If subprogram
9927 -- is aliased (as for an instance) indicate that the renamed
9928 -- entity (if declared in the same unit) is inlined.
9929 -- If this is the anonymous subprogram created for a subprogram
9930 -- instance, the inlining applies to it directly. Otherwise we
9931 -- retrieve it as the alias of the visible subprogram instance.
9933 if Is_Subprogram (Subp) then
9935 -- Ensure that pragma Inline_Always is associated with the
9936 -- initial declaration of the subprogram.
9938 Check_Inline_Always_Placement (Subp);
9940 if Is_Wrapper_Package (Scope (Subp)) then
9941 Inner_Subp := Subp;
9942 else
9943 Inner_Subp := Ultimate_Alias (Inner_Subp);
9944 end if;
9946 if In_Same_Source_Unit (Subp, Inner_Subp) then
9947 Set_Inline_Flags (Inner_Subp);
9949 Decl := Parent (Parent (Inner_Subp));
9951 if Nkind (Decl) = N_Subprogram_Declaration
9952 and then Present (Corresponding_Body (Decl))
9953 then
9954 Set_Inline_Flags (Corresponding_Body (Decl));
9956 elsif Is_Generic_Instance (Subp)
9957 and then Comes_From_Source (Subp)
9958 then
9959 -- Indicate that the body needs to be created for
9960 -- inlining subsequent calls. The instantiation node
9961 -- follows the declaration of the wrapper package
9962 -- created for it. The subprogram that requires the
9963 -- body is the anonymous one in the wrapper package.
9965 if Scope (Subp) /= Standard_Standard
9966 and then
9967 Need_Subprogram_Instance_Body
9968 (Next (Unit_Declaration_Node
9969 (Scope (Alias (Subp)))), Subp)
9970 then
9971 null;
9972 end if;
9974 -- Inline is a program unit pragma (RM 10.1.5) and cannot
9975 -- appear in a formal part to apply to a formal subprogram.
9976 -- Do not apply check within an instance or a formal package
9977 -- the test will have been applied to the original generic.
9979 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
9980 and then List_Containing (Decl) = List_Containing (N)
9981 and then not In_Instance
9982 then
9983 Error_Msg_N
9984 ("Inline cannot apply to a formal subprogram", N);
9985 end if;
9986 end if;
9988 Applies := True;
9990 -- For a generic subprogram set flag as well, for use at the point
9991 -- of instantiation, to determine whether the body should be
9992 -- generated.
9994 elsif Is_Generic_Subprogram (Subp) then
9995 Set_Inline_Flags (Subp);
9996 Applies := True;
9998 -- Literals are by definition inlined
10000 elsif Kind = E_Enumeration_Literal then
10001 null;
10003 -- Anything else is an error
10005 else
10006 Error_Pragma_Arg
10007 ("expect subprogram name for pragma%", Assoc);
10008 end if;
10009 end Make_Inline;
10011 ----------------------
10012 -- Set_Inline_Flags --
10013 ----------------------
10015 procedure Set_Inline_Flags (Subp : Entity_Id) is
10016 begin
10017 -- First set the Has_Pragma_XXX flags and issue the appropriate
10018 -- errors and warnings for suspicious combinations.
10020 if Prag_Id = Pragma_No_Inline then
10021 if Has_Pragma_Inline_Always (Subp) then
10022 Error_Msg_N
10023 ("Inline_Always and No_Inline are mutually exclusive", N);
10024 elsif Has_Pragma_Inline (Subp) then
10025 Error_Msg_NE
10026 ("Inline and No_Inline both specified for& ??",
10027 N, Entity (Subp_Id));
10028 end if;
10030 Set_Has_Pragma_No_Inline (Subp);
10031 else
10032 if Prag_Id = Pragma_Inline_Always then
10033 if Has_Pragma_No_Inline (Subp) then
10034 Error_Msg_N
10035 ("Inline_Always and No_Inline are mutually exclusive",
10037 end if;
10039 Set_Has_Pragma_Inline_Always (Subp);
10040 else
10041 if Has_Pragma_No_Inline (Subp) then
10042 Error_Msg_NE
10043 ("Inline and No_Inline both specified for& ??",
10044 N, Entity (Subp_Id));
10045 end if;
10046 end if;
10048 Set_Has_Pragma_Inline (Subp);
10049 end if;
10051 -- Then adjust the Is_Inlined flag. It can never be set if the
10052 -- subprogram is subject to pragma No_Inline.
10054 case Status is
10055 when Suppressed =>
10056 Set_Is_Inlined (Subp, False);
10058 when Disabled =>
10059 null;
10061 when Enabled =>
10062 if not Has_Pragma_No_Inline (Subp) then
10063 Set_Is_Inlined (Subp, True);
10064 end if;
10065 end case;
10067 -- A pragma that applies to a Ghost entity becomes Ghost for the
10068 -- purposes of legality checks and removal of ignored Ghost code.
10070 Mark_Ghost_Pragma (N, Subp);
10072 -- Capture the entity of the first Ghost subprogram being
10073 -- processed for error detection purposes.
10075 if Is_Ghost_Entity (Subp) then
10076 if No (Ghost_Id) then
10077 Ghost_Id := Subp;
10078 end if;
10080 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
10081 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
10083 elsif Present (Ghost_Id) and then not Ghost_Error_Posted then
10084 Ghost_Error_Posted := True;
10086 Error_Msg_Name_1 := Pname;
10087 Error_Msg_N
10088 ("pragma % cannot mention ghost and non-ghost subprograms",
10091 Error_Msg_Sloc := Sloc (Ghost_Id);
10092 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
10094 Error_Msg_Sloc := Sloc (Subp);
10095 Error_Msg_NE ("\& # declared as non-ghost", N, Subp);
10096 end if;
10097 end Set_Inline_Flags;
10099 -- Start of processing for Process_Inline
10101 begin
10102 -- An inlined subprogram may grant access to its private enclosing
10103 -- context depending on the placement of its body. From elaboration
10104 -- point of view, the flow of execution may enter this private
10105 -- context, and then reach an external unit, thus producing a
10106 -- dependency on that external unit. For such a path to be properly
10107 -- discovered and encoded in the ALI file of the main unit, let the
10108 -- ABE mechanism process the body of the main unit, and encode all
10109 -- relevant invocation constructs and the relations between them.
10111 Mark_Save_Invocation_Graph_Of_Body;
10113 Check_No_Identifiers;
10114 Check_At_Least_N_Arguments (1);
10116 if Status = Enabled then
10117 Inline_Processing_Required := True;
10118 end if;
10120 Assoc := Arg1;
10121 while Present (Assoc) loop
10122 Subp_Id := Get_Pragma_Arg (Assoc);
10123 Analyze (Subp_Id);
10124 Applies := False;
10126 if Is_Entity_Name (Subp_Id) then
10127 Subp := Entity (Subp_Id);
10129 if Subp = Any_Id then
10131 -- If previous error, avoid cascaded errors
10133 Check_Error_Detected;
10134 Applies := True;
10136 else
10137 -- Check for RM 13.1(9.2/4): If a [...] aspect_specification
10138 -- is given that directly specifies an aspect of an entity,
10139 -- then it is illegal to give another [...]
10140 -- aspect_specification that directly specifies the same
10141 -- aspect of the entity.
10142 -- We only check Subp directly as per "directly specifies"
10143 -- above and because the case of pragma Inline is really
10144 -- special given its pre aspect usage.
10146 Check_Duplicate_Pragma (Subp);
10147 Record_Rep_Item (Subp, N);
10149 Make_Inline (Subp);
10151 -- For the pragma case, climb homonym chain. This is
10152 -- what implements allowing the pragma in the renaming
10153 -- case, with the result applying to the ancestors, and
10154 -- also allows Inline to apply to all previous homonyms.
10156 if not From_Aspect_Specification (N) then
10157 while Present (Homonym (Subp))
10158 and then Scope (Homonym (Subp)) = Current_Scope
10159 loop
10160 Subp := Homonym (Subp);
10161 Make_Inline (Subp);
10162 end loop;
10163 end if;
10164 end if;
10165 end if;
10167 if not Applies then
10168 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
10169 end if;
10171 Next (Assoc);
10172 end loop;
10174 -- If the context is a package declaration, the pragma indicates
10175 -- that inlining will require the presence of the corresponding
10176 -- body. (this may be further refined).
10178 if not In_Instance
10179 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
10180 N_Package_Declaration
10181 then
10182 Set_Body_Needed_For_Inlining (Cunit_Entity (Current_Sem_Unit));
10183 end if;
10184 end Process_Inline;
10186 ----------------------------
10187 -- Process_Interface_Name --
10188 ----------------------------
10190 procedure Process_Interface_Name
10191 (Subprogram_Def : Entity_Id;
10192 Ext_Arg : Node_Id;
10193 Link_Arg : Node_Id;
10194 Prag : Node_Id)
10196 Ext_Nam : Node_Id;
10197 Link_Nam : Node_Id;
10198 String_Val : String_Id;
10200 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
10201 -- SN is a string literal node for an interface name. This routine
10202 -- performs some minimal checks that the name is reasonable. In
10203 -- particular that no spaces or other obviously incorrect characters
10204 -- appear. This is only a warning, since any characters are allowed.
10206 ----------------------------------
10207 -- Check_Form_Of_Interface_Name --
10208 ----------------------------------
10210 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
10211 S : constant String_Id := Strval (Expr_Value_S (SN));
10212 SL : constant Nat := String_Length (S);
10213 C : Char_Code;
10215 begin
10216 if SL = 0 then
10217 Error_Msg_N ("interface name cannot be null string", SN);
10218 end if;
10220 for J in 1 .. SL loop
10221 C := Get_String_Char (S, J);
10223 -- Look for dubious character and issue unconditional warning.
10224 -- Definitely dubious if not in character range.
10226 if not In_Character_Range (C)
10228 -- Commas, spaces and (back)slashes are dubious
10230 or else Get_Character (C) = ','
10231 or else Get_Character (C) = '\'
10232 or else Get_Character (C) = ' '
10233 or else Get_Character (C) = '/'
10234 then
10235 Error_Msg
10236 ("??interface name contains illegal character",
10237 Sloc (SN) + Source_Ptr (J));
10238 end if;
10239 end loop;
10240 end Check_Form_Of_Interface_Name;
10242 -- Start of processing for Process_Interface_Name
10244 begin
10245 -- If we are looking at a pragma that comes from an aspect then it
10246 -- needs to have its corresponding aspect argument expressions
10247 -- analyzed in addition to the generated pragma so that aspects
10248 -- within generic units get properly resolved.
10250 if Present (Prag) and then From_Aspect_Specification (Prag) then
10251 declare
10252 Asp : constant Node_Id := Corresponding_Aspect (Prag);
10253 Dummy_1 : Node_Id;
10254 Dummy_2 : Node_Id;
10255 Dummy_3 : Node_Id;
10256 EN : Node_Id;
10257 LN : Node_Id;
10259 begin
10260 -- Obtain all interfacing aspects used to construct the pragma
10262 Get_Interfacing_Aspects
10263 (Asp, Dummy_1, EN, Dummy_2, Dummy_3, LN);
10265 -- Analyze the expression of aspect External_Name
10267 if Present (EN) then
10268 Analyze (Expression (EN));
10269 end if;
10271 -- Analyze the expressio of aspect Link_Name
10273 if Present (LN) then
10274 Analyze (Expression (LN));
10275 end if;
10276 end;
10277 end if;
10279 if No (Link_Arg) then
10280 if No (Ext_Arg) then
10281 return;
10283 elsif Chars (Ext_Arg) = Name_Link_Name then
10284 Ext_Nam := Empty;
10285 Link_Nam := Expression (Ext_Arg);
10287 else
10288 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10289 Ext_Nam := Expression (Ext_Arg);
10290 Link_Nam := Empty;
10291 end if;
10293 else
10294 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
10295 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
10296 Ext_Nam := Expression (Ext_Arg);
10297 Link_Nam := Expression (Link_Arg);
10298 end if;
10300 -- Check expressions for external name and link name are static
10302 if Present (Ext_Nam) then
10303 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
10304 Check_Form_Of_Interface_Name (Ext_Nam);
10306 -- Verify that external name is not the name of a local entity,
10307 -- which would hide the imported one and could lead to run-time
10308 -- surprises. The problem can only arise for entities declared in
10309 -- a package body (otherwise the external name is fully qualified
10310 -- and will not conflict).
10312 declare
10313 Nam : Name_Id;
10314 E : Entity_Id;
10315 Par : Node_Id;
10317 begin
10318 if Prag_Id = Pragma_Import then
10319 Nam := String_To_Name (Strval (Expr_Value_S (Ext_Nam)));
10320 E := Entity_Id (Get_Name_Table_Int (Nam));
10322 if Nam /= Chars (Subprogram_Def)
10323 and then Present (E)
10324 and then not Is_Overloadable (E)
10325 and then Is_Immediately_Visible (E)
10326 and then not Is_Imported (E)
10327 and then Ekind (Scope (E)) = E_Package
10328 then
10329 Par := Parent (E);
10330 while Present (Par) loop
10331 if Nkind (Par) = N_Package_Body then
10332 Error_Msg_Sloc := Sloc (E);
10333 Error_Msg_NE
10334 ("imported entity is hidden by & declared#",
10335 Ext_Arg, E);
10336 exit;
10337 end if;
10339 Par := Parent (Par);
10340 end loop;
10341 end if;
10342 end if;
10343 end;
10344 end if;
10346 if Present (Link_Nam) then
10347 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
10348 Check_Form_Of_Interface_Name (Link_Nam);
10349 end if;
10351 -- If there is no link name, just set the external name
10353 if No (Link_Nam) then
10354 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
10356 -- For the Link_Name case, the given literal is preceded by an
10357 -- asterisk, which indicates to GCC that the given name should be
10358 -- taken literally, and in particular that no prepending of
10359 -- underlines should occur, even in systems where this is the
10360 -- normal default.
10362 else
10363 Start_String;
10364 Store_String_Char (Get_Char_Code ('*'));
10365 String_Val := Strval (Expr_Value_S (Link_Nam));
10366 Store_String_Chars (String_Val);
10367 Link_Nam :=
10368 Make_String_Literal (Sloc (Link_Nam),
10369 Strval => End_String);
10370 end if;
10372 -- Set the interface name. If the entity is a generic instance, use
10373 -- its alias, which is the callable entity.
10375 if Is_Generic_Instance (Subprogram_Def) then
10376 Set_Encoded_Interface_Name
10377 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
10378 else
10379 Set_Encoded_Interface_Name
10380 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
10381 end if;
10383 Check_Duplicated_Export_Name (Link_Nam);
10384 end Process_Interface_Name;
10386 -----------------------------------------
10387 -- Process_Interrupt_Or_Attach_Handler --
10388 -----------------------------------------
10390 procedure Process_Interrupt_Or_Attach_Handler is
10391 Handler : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
10392 Prot_Typ : constant Entity_Id := Scope (Handler);
10394 begin
10395 -- A pragma that applies to a Ghost entity becomes Ghost for the
10396 -- purposes of legality checks and removal of ignored Ghost code.
10398 Mark_Ghost_Pragma (N, Handler);
10399 Set_Is_Interrupt_Handler (Handler);
10401 pragma Assert (Ekind (Prot_Typ) = E_Protected_Type);
10403 Record_Rep_Item (Prot_Typ, N);
10405 -- Chain the pragma on the contract for completeness
10407 Add_Contract_Item (N, Handler);
10408 end Process_Interrupt_Or_Attach_Handler;
10410 --------------------------------------------------
10411 -- Process_Restrictions_Or_Restriction_Warnings --
10412 --------------------------------------------------
10414 -- Note: some of the simple identifier cases were handled in par-prag,
10415 -- but it is harmless (and more straightforward) to simply handle all
10416 -- cases here, even if it means we repeat a bit of work in some cases.
10418 procedure Process_Restrictions_Or_Restriction_Warnings
10419 (Warn : Boolean)
10421 Arg : Node_Id;
10422 R_Id : Restriction_Id;
10423 Id : Name_Id;
10424 Expr : Node_Id;
10425 Val : Uint;
10427 begin
10428 -- Ignore all Restrictions pragmas in CodePeer mode
10430 if CodePeer_Mode then
10431 return;
10432 end if;
10434 Check_Ada_83_Warning;
10435 Check_At_Least_N_Arguments (1);
10436 Check_Valid_Configuration_Pragma;
10438 Arg := Arg1;
10439 while Present (Arg) loop
10440 Id := Chars (Arg);
10441 Expr := Get_Pragma_Arg (Arg);
10443 -- Case of no restriction identifier present
10445 if Id = No_Name then
10446 if Nkind (Expr) /= N_Identifier then
10447 Error_Pragma_Arg
10448 ("invalid form for restriction", Arg);
10449 end if;
10451 R_Id :=
10452 Get_Restriction_Id
10453 (Process_Restriction_Synonyms (Expr));
10455 if R_Id not in All_Boolean_Restrictions then
10456 Error_Msg_Name_1 := Pname;
10457 Error_Msg_N
10458 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
10460 -- Check for possible misspelling
10462 for J in Restriction_Id loop
10463 declare
10464 Rnm : constant String := Restriction_Id'Image (J);
10466 begin
10467 Name_Buffer (1 .. Rnm'Length) := Rnm;
10468 Name_Len := Rnm'Length;
10469 Set_Casing (All_Lower_Case);
10471 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
10472 Set_Casing
10473 (Identifier_Casing
10474 (Source_Index (Current_Sem_Unit)));
10475 Error_Msg_String (1 .. Rnm'Length) :=
10476 Name_Buffer (1 .. Name_Len);
10477 Error_Msg_Strlen := Rnm'Length;
10478 Error_Msg_N -- CODEFIX
10479 ("\possible misspelling of ""~""",
10480 Get_Pragma_Arg (Arg));
10481 exit;
10482 end if;
10483 end;
10484 end loop;
10486 raise Pragma_Exit;
10487 end if;
10489 if Implementation_Restriction (R_Id) then
10490 Check_Restriction (No_Implementation_Restrictions, Arg);
10491 end if;
10493 -- Special processing for No_Elaboration_Code restriction
10495 if R_Id = No_Elaboration_Code then
10497 -- Restriction is only recognized within a configuration
10498 -- pragma file, or within a unit of the main extended
10499 -- program. Note: the test for Main_Unit is needed to
10500 -- properly include the case of configuration pragma files.
10502 if not (Current_Sem_Unit = Main_Unit
10503 or else In_Extended_Main_Source_Unit (N))
10504 then
10505 return;
10507 -- Don't allow in a subunit unless already specified in
10508 -- body or spec.
10510 elsif Nkind (Parent (N)) = N_Compilation_Unit
10511 and then Nkind (Unit (Parent (N))) = N_Subunit
10512 and then not Restriction_Active (No_Elaboration_Code)
10513 then
10514 Error_Msg_N
10515 ("invalid specification of ""No_Elaboration_Code""",
10517 Error_Msg_N
10518 ("\restriction cannot be specified in a subunit", N);
10519 Error_Msg_N
10520 ("\unless also specified in body or spec", N);
10521 return;
10523 -- If we accept a No_Elaboration_Code restriction, then it
10524 -- needs to be added to the configuration restriction set so
10525 -- that we get proper application to other units in the main
10526 -- extended source as required.
10528 else
10529 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
10530 end if;
10532 -- Special processing for No_Tasking restriction placed in
10533 -- a configuration pragmas file.
10535 elsif R_Id = No_Tasking and then No (Cunit (Main_Unit)) then
10536 Set_Global_No_Tasking;
10537 end if;
10539 Set_Restriction (R_Id, N, Warn);
10541 if R_Id = No_Dynamic_CPU_Assignment
10542 or else R_Id = No_Tasks_Unassigned_To_CPU
10543 then
10544 -- These imply No_Dependence =>
10545 -- "System.Multiprocessors.Dispatching_Domains".
10546 -- This is not strictly what the AI says, but it eliminates
10547 -- the need for run-time checks, which are undesirable in
10548 -- this context.
10550 Set_Restriction_No_Dependence
10551 (Sel_Comp
10552 (Sel_Comp ("system", "multiprocessors", Loc),
10553 "dispatching_domains"),
10554 Warn);
10555 end if;
10557 if R_Id = No_Tasks_Unassigned_To_CPU then
10558 -- Likewise, imply No_Dynamic_CPU_Assignment
10560 Set_Restriction (No_Dynamic_CPU_Assignment, N, Warn);
10561 end if;
10563 -- Check for obsolescent restrictions in Ada 2005 mode
10565 if not Warn
10566 and then Ada_Version >= Ada_2005
10567 and then (R_Id = No_Asynchronous_Control
10568 or else
10569 R_Id = No_Unchecked_Deallocation
10570 or else
10571 R_Id = No_Unchecked_Conversion)
10572 then
10573 Check_Restriction (No_Obsolescent_Features, N);
10574 end if;
10576 -- A very special case that must be processed here: pragma
10577 -- Restrictions (No_Exceptions) turns off all run-time
10578 -- checking. This is a bit dubious in terms of the formal
10579 -- language definition, but it is what is intended by RM
10580 -- H.4(12). Restriction_Warnings never affects generated code
10581 -- so this is done only in the real restriction case.
10583 -- Atomic_Synchronization is not a real check, so it is not
10584 -- affected by this processing).
10586 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
10587 -- run-time checks in CodePeer and GNATprove modes: we want to
10588 -- generate checks for analysis purposes, as set respectively
10589 -- by -gnatC and -gnatd.F
10591 if not Warn
10592 and then not (CodePeer_Mode or GNATprove_Mode)
10593 and then R_Id = No_Exceptions
10594 then
10595 for J in Scope_Suppress.Suppress'Range loop
10596 if J /= Atomic_Synchronization then
10597 Scope_Suppress.Suppress (J) := True;
10598 end if;
10599 end loop;
10600 end if;
10602 -- Case of No_Dependence => unit-name. Note that the parser
10603 -- already made the necessary entry in the No_Dependence table.
10605 elsif Id = Name_No_Dependence then
10606 if not OK_No_Dependence_Unit_Name (Expr) then
10607 raise Pragma_Exit;
10608 end if;
10610 -- Case of No_Specification_Of_Aspect => aspect-identifier
10612 elsif Id = Name_No_Specification_Of_Aspect then
10613 declare
10614 A_Id : Aspect_Id;
10616 begin
10617 if Nkind (Expr) /= N_Identifier then
10618 A_Id := No_Aspect;
10619 else
10620 A_Id := Get_Aspect_Id (Chars (Expr));
10621 end if;
10623 if A_Id = No_Aspect then
10624 Error_Pragma_Arg ("invalid restriction name", Arg);
10625 else
10626 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
10627 end if;
10628 end;
10630 -- Case of No_Use_Of_Attribute => attribute-identifier
10632 elsif Id = Name_No_Use_Of_Attribute then
10633 if Nkind (Expr) /= N_Identifier
10634 or else not Is_Attribute_Name (Chars (Expr))
10635 then
10636 Error_Msg_N ("unknown attribute name??", Expr);
10638 else
10639 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
10640 end if;
10642 -- Case of No_Use_Of_Entity => fully-qualified-name
10644 elsif Id = Name_No_Use_Of_Entity then
10646 -- Restriction is only recognized within a configuration
10647 -- pragma file, or within a unit of the main extended
10648 -- program. Note: the test for Main_Unit is needed to
10649 -- properly include the case of configuration pragma files.
10651 if Current_Sem_Unit = Main_Unit
10652 or else In_Extended_Main_Source_Unit (N)
10653 then
10654 if not OK_No_Dependence_Unit_Name (Expr) then
10655 Error_Msg_N ("wrong form for entity name", Expr);
10656 else
10657 Set_Restriction_No_Use_Of_Entity
10658 (Expr, Warn, No_Profile);
10659 end if;
10660 end if;
10662 -- Case of No_Use_Of_Pragma => pragma-identifier
10664 elsif Id = Name_No_Use_Of_Pragma then
10665 if Nkind (Expr) /= N_Identifier
10666 or else not Is_Pragma_Name (Chars (Expr))
10667 then
10668 Error_Msg_N ("unknown pragma name??", Expr);
10669 else
10670 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
10671 end if;
10673 -- All other cases of restriction identifier present
10675 else
10676 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
10677 Analyze_And_Resolve (Expr, Any_Integer);
10679 if R_Id not in All_Parameter_Restrictions then
10680 Error_Pragma_Arg
10681 ("invalid restriction parameter identifier", Arg);
10683 elsif not Is_OK_Static_Expression (Expr) then
10684 Flag_Non_Static_Expr
10685 ("value must be static expression!", Expr);
10686 raise Pragma_Exit;
10688 elsif not Is_Integer_Type (Etype (Expr))
10689 or else Expr_Value (Expr) < 0
10690 then
10691 Error_Pragma_Arg
10692 ("value must be non-negative integer", Arg);
10693 end if;
10695 -- Restriction pragma is active
10697 Val := Expr_Value (Expr);
10699 if not UI_Is_In_Int_Range (Val) then
10700 Error_Pragma_Arg
10701 ("pragma ignored, value too large??", Arg);
10702 end if;
10704 Set_Restriction (R_Id, N, Warn, Integer (UI_To_Int (Val)));
10705 end if;
10707 Next (Arg);
10708 end loop;
10709 end Process_Restrictions_Or_Restriction_Warnings;
10711 ---------------------------------
10712 -- Process_Suppress_Unsuppress --
10713 ---------------------------------
10715 -- Note: this procedure makes entries in the check suppress data
10716 -- structures managed by Sem. See spec of package Sem for full
10717 -- details on how we handle recording of check suppression.
10719 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
10720 C : Check_Id;
10721 E : Entity_Id;
10722 E_Id : Node_Id;
10724 In_Package_Spec : constant Boolean :=
10725 Is_Package_Or_Generic_Package (Current_Scope)
10726 and then not In_Package_Body (Current_Scope);
10728 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
10729 -- Used to suppress a single check on the given entity
10731 --------------------------------
10732 -- Suppress_Unsuppress_Echeck --
10733 --------------------------------
10735 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
10736 begin
10737 -- Check for error of trying to set atomic synchronization for
10738 -- a non-atomic variable.
10740 if C = Atomic_Synchronization
10741 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
10742 then
10743 Error_Msg_N
10744 ("pragma & requires atomic type or variable",
10745 Pragma_Identifier (Original_Node (N)));
10746 end if;
10748 Set_Checks_May_Be_Suppressed (E);
10750 if In_Package_Spec then
10751 Push_Global_Suppress_Stack_Entry
10752 (Entity => E,
10753 Check => C,
10754 Suppress => Suppress_Case);
10755 else
10756 Push_Local_Suppress_Stack_Entry
10757 (Entity => E,
10758 Check => C,
10759 Suppress => Suppress_Case);
10760 end if;
10762 -- If this is a first subtype, and the base type is distinct,
10763 -- then also set the suppress flags on the base type.
10765 if Is_First_Subtype (E) and then Etype (E) /= E then
10766 Suppress_Unsuppress_Echeck (Etype (E), C);
10767 end if;
10768 end Suppress_Unsuppress_Echeck;
10770 -- Start of processing for Process_Suppress_Unsuppress
10772 begin
10773 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
10774 -- on user code: we want to generate checks for analysis purposes, as
10775 -- set respectively by -gnatC and -gnatd.F
10777 if Comes_From_Source (N)
10778 and then (CodePeer_Mode or GNATprove_Mode)
10779 then
10780 return;
10781 end if;
10783 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
10784 -- declarative part or a package spec (RM 11.5(5)).
10786 if not Is_Configuration_Pragma then
10787 Check_Is_In_Decl_Part_Or_Package_Spec;
10788 end if;
10790 Check_At_Least_N_Arguments (1);
10791 Check_At_Most_N_Arguments (2);
10792 Check_No_Identifier (Arg1);
10793 Check_Arg_Is_Identifier (Arg1);
10795 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
10797 if C = No_Check_Id then
10798 Error_Pragma_Arg
10799 ("argument of pragma% is not valid check name", Arg1);
10800 end if;
10802 -- Warn that suppress of Elaboration_Check has no effect in SPARK
10804 if C = Elaboration_Check and then SPARK_Mode = On then
10805 Error_Pragma_Arg
10806 ("Suppress of Elaboration_Check ignored in SPARK??",
10807 "\elaboration checking rules are statically enforced "
10808 & "(SPARK RM 7.7)", Arg1);
10809 end if;
10811 -- One-argument case
10813 if Arg_Count = 1 then
10815 -- Make an entry in the local scope suppress table. This is the
10816 -- table that directly shows the current value of the scope
10817 -- suppress check for any check id value.
10819 if C = All_Checks then
10821 -- For All_Checks, we set all specific predefined checks with
10822 -- the exception of Elaboration_Check, which is handled
10823 -- specially because of not wanting All_Checks to have the
10824 -- effect of deactivating static elaboration order processing.
10825 -- Atomic_Synchronization is also not affected, since this is
10826 -- not a real check.
10828 for J in Scope_Suppress.Suppress'Range loop
10829 if J /= Elaboration_Check
10830 and then
10831 J /= Atomic_Synchronization
10832 then
10833 Scope_Suppress.Suppress (J) := Suppress_Case;
10834 end if;
10835 end loop;
10837 -- If not All_Checks, and predefined check, then set appropriate
10838 -- scope entry. Note that we will set Elaboration_Check if this
10839 -- is explicitly specified. Atomic_Synchronization is allowed
10840 -- only if internally generated and entity is atomic.
10842 elsif C in Predefined_Check_Id
10843 and then (not Comes_From_Source (N)
10844 or else C /= Atomic_Synchronization)
10845 then
10846 Scope_Suppress.Suppress (C) := Suppress_Case;
10847 end if;
10849 -- Also make an entry in the Local_Entity_Suppress table
10851 Push_Local_Suppress_Stack_Entry
10852 (Entity => Empty,
10853 Check => C,
10854 Suppress => Suppress_Case);
10856 -- Case of two arguments present, where the check is suppressed for
10857 -- a specified entity (given as the second argument of the pragma)
10859 else
10860 -- This is obsolescent in Ada 2005 mode
10862 if Ada_Version >= Ada_2005 then
10863 Check_Restriction (No_Obsolescent_Features, Arg2);
10864 end if;
10866 Check_Optional_Identifier (Arg2, Name_On);
10867 E_Id := Get_Pragma_Arg (Arg2);
10868 Analyze (E_Id);
10870 if not Is_Entity_Name (E_Id) then
10871 Error_Pragma_Arg
10872 ("second argument of pragma% must be entity name", Arg2);
10873 end if;
10875 E := Entity (E_Id);
10877 if E = Any_Id then
10878 return;
10879 end if;
10881 -- A pragma that applies to a Ghost entity becomes Ghost for the
10882 -- purposes of legality checks and removal of ignored Ghost code.
10884 Mark_Ghost_Pragma (N, E);
10886 -- Enforce RM 11.5(7) which requires that for a pragma that
10887 -- appears within a package spec, the named entity must be
10888 -- within the package spec. We allow the package name itself
10889 -- to be mentioned since that makes sense, although it is not
10890 -- strictly allowed by 11.5(7).
10892 if In_Package_Spec
10893 and then E /= Current_Scope
10894 and then Scope (E) /= Current_Scope
10895 then
10896 Error_Pragma_Arg
10897 ("entity in pragma% is not in package spec (RM 11.5(7))",
10898 Arg2);
10899 end if;
10901 -- Loop through homonyms. As noted below, in the case of a package
10902 -- spec, only homonyms within the package spec are considered.
10904 loop
10905 Suppress_Unsuppress_Echeck (E, C);
10907 if Is_Generic_Instance (E)
10908 and then Is_Subprogram (E)
10909 and then Present (Alias (E))
10910 then
10911 Suppress_Unsuppress_Echeck (Alias (E), C);
10912 end if;
10914 -- Move to next homonym if not aspect spec case
10916 exit when From_Aspect_Specification (N);
10917 E := Homonym (E);
10918 exit when No (E);
10920 -- If we are within a package specification, the pragma only
10921 -- applies to homonyms in the same scope.
10923 exit when In_Package_Spec
10924 and then Scope (E) /= Current_Scope;
10925 end loop;
10926 end if;
10927 end Process_Suppress_Unsuppress;
10929 -------------------------------
10930 -- Record_Independence_Check --
10931 -------------------------------
10933 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is
10934 pragma Unreferenced (N, E);
10935 begin
10936 -- For GCC back ends the validation is done a priori
10937 -- ??? This code is dead, might be useful in the future
10939 -- if not AAMP_On_Target then
10940 -- return;
10941 -- end if;
10943 -- Independence_Checks.Append ((N, E));
10945 return;
10946 end Record_Independence_Check;
10948 ------------------
10949 -- Set_Exported --
10950 ------------------
10952 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
10953 begin
10954 if Is_Imported (E) then
10955 Error_Pragma_Arg
10956 ("cannot export entity& that was previously imported", Arg);
10958 elsif Present (Address_Clause (E))
10959 and then not Relaxed_RM_Semantics
10960 then
10961 Error_Pragma_Arg
10962 ("cannot export entity& that has an address clause", Arg);
10963 end if;
10965 Set_Is_Exported (E);
10967 -- Generate a reference for entity explicitly, because the
10968 -- identifier may be overloaded and name resolution will not
10969 -- generate one.
10971 Generate_Reference (E, Arg);
10973 -- Deal with exporting non-library level entity
10975 if not Is_Library_Level_Entity (E) then
10977 -- Not allowed at all for subprograms
10979 if Is_Subprogram (E) then
10980 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
10982 -- Otherwise set public and statically allocated
10984 else
10985 Set_Is_Public (E);
10986 Set_Is_Statically_Allocated (E);
10988 -- Warn if the corresponding W flag is set
10990 if Warn_On_Export_Import
10992 -- Only do this for something that was in the source. Not
10993 -- clear if this can be False now (there used for sure to be
10994 -- cases on some systems where it was False), but anyway the
10995 -- test is harmless if not needed, so it is retained.
10997 and then Comes_From_Source (Arg)
10998 then
10999 Error_Msg_NE
11000 ("?x?& has been made static as a result of Export",
11001 Arg, E);
11002 Error_Msg_N
11003 ("\?x?this usage is non-standard and non-portable",
11004 Arg);
11005 end if;
11006 end if;
11007 end if;
11009 if Warn_On_Export_Import and then Is_Type (E) then
11010 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
11011 end if;
11013 if Warn_On_Export_Import and Inside_A_Generic then
11014 Error_Msg_NE
11015 ("all instances of& will have the same external name?x?",
11016 Arg, E);
11017 end if;
11018 end Set_Exported;
11020 ----------------------------------------------
11021 -- Set_Extended_Import_Export_External_Name --
11022 ----------------------------------------------
11024 procedure Set_Extended_Import_Export_External_Name
11025 (Internal_Ent : Entity_Id;
11026 Arg_External : Node_Id)
11028 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
11029 New_Name : Node_Id;
11031 begin
11032 if No (Arg_External) then
11033 return;
11034 end if;
11036 Check_Arg_Is_External_Name (Arg_External);
11038 if Nkind (Arg_External) = N_String_Literal then
11039 if String_Length (Strval (Arg_External)) = 0 then
11040 return;
11041 else
11042 New_Name := Adjust_External_Name_Case (Arg_External);
11043 end if;
11045 elsif Nkind (Arg_External) = N_Identifier then
11046 New_Name := Get_Default_External_Name (Arg_External);
11048 -- Check_Arg_Is_External_Name should let through only identifiers and
11049 -- string literals or static string expressions (which are folded to
11050 -- string literals).
11052 else
11053 raise Program_Error;
11054 end if;
11056 -- If we already have an external name set (by a prior normal Import
11057 -- or Export pragma), then the external names must match
11059 if Present (Interface_Name (Internal_Ent)) then
11061 -- Ignore mismatching names in CodePeer mode, to support some
11062 -- old compilers which would export the same procedure under
11063 -- different names, e.g:
11064 -- procedure P;
11065 -- pragma Export_Procedure (P, "a");
11066 -- pragma Export_Procedure (P, "b");
11068 if CodePeer_Mode then
11069 return;
11070 end if;
11072 Check_Matching_Internal_Names : declare
11073 S1 : constant String_Id := Strval (Old_Name);
11074 S2 : constant String_Id := Strval (New_Name);
11076 procedure Mismatch;
11077 pragma No_Return (Mismatch);
11078 -- Called if names do not match
11080 --------------
11081 -- Mismatch --
11082 --------------
11084 procedure Mismatch is
11085 begin
11086 Error_Msg_Sloc := Sloc (Old_Name);
11087 Error_Pragma_Arg
11088 ("external name does not match that given #",
11089 Arg_External);
11090 end Mismatch;
11092 -- Start of processing for Check_Matching_Internal_Names
11094 begin
11095 if String_Length (S1) /= String_Length (S2) then
11096 Mismatch;
11098 else
11099 for J in 1 .. String_Length (S1) loop
11100 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
11101 Mismatch;
11102 end if;
11103 end loop;
11104 end if;
11105 end Check_Matching_Internal_Names;
11107 -- Otherwise set the given name
11109 else
11110 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
11111 Check_Duplicated_Export_Name (New_Name);
11112 end if;
11113 end Set_Extended_Import_Export_External_Name;
11115 ------------------
11116 -- Set_Imported --
11117 ------------------
11119 procedure Set_Imported (E : Entity_Id) is
11120 begin
11121 -- Error message if already imported or exported
11123 if Is_Exported (E) or else Is_Imported (E) then
11125 -- Error if being set Exported twice
11127 if Is_Exported (E) then
11128 Error_Msg_NE ("entity& was previously exported", N, E);
11130 -- Ignore error in CodePeer mode where we treat all imported
11131 -- subprograms as unknown.
11133 elsif CodePeer_Mode then
11134 goto OK;
11136 -- OK if Import/Interface case
11138 elsif Import_Interface_Present (N) then
11139 goto OK;
11141 -- Error if being set Imported twice
11143 else
11144 Error_Msg_NE ("entity& was previously imported", N, E);
11145 end if;
11147 Error_Msg_Name_1 := Pname;
11148 Error_Msg_N
11149 ("\(pragma% applies to all previous entities)", N);
11151 Error_Msg_Sloc := Sloc (E);
11152 Error_Msg_NE ("\import not allowed for& declared#", N, E);
11154 -- Here if not previously imported or exported, OK to import
11156 else
11157 Set_Is_Imported (E);
11159 -- For subprogram, set Import_Pragma field
11161 if Is_Subprogram (E) then
11162 Set_Import_Pragma (E, N);
11163 end if;
11165 -- If the entity is an object that is not at the library level,
11166 -- then it is statically allocated. We do not worry about objects
11167 -- with address clauses in this context since they are not really
11168 -- imported in the linker sense.
11170 if Is_Object (E)
11171 and then not Is_Library_Level_Entity (E)
11172 and then No (Address_Clause (E))
11173 then
11174 Set_Is_Statically_Allocated (E);
11175 end if;
11176 end if;
11178 <<OK>> null;
11179 end Set_Imported;
11181 -------------------------
11182 -- Set_Mechanism_Value --
11183 -------------------------
11185 -- Note: the mechanism name has not been analyzed (and cannot indeed be
11186 -- analyzed, since it is semantic nonsense), so we get it in the exact
11187 -- form created by the parser.
11189 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
11190 procedure Bad_Mechanism;
11191 pragma No_Return (Bad_Mechanism);
11192 -- Signal bad mechanism name
11194 -------------------
11195 -- Bad_Mechanism --
11196 -------------------
11198 procedure Bad_Mechanism is
11199 begin
11200 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
11201 end Bad_Mechanism;
11203 -- Start of processing for Set_Mechanism_Value
11205 begin
11206 if Mechanism (Ent) /= Default_Mechanism then
11207 Error_Msg_NE
11208 ("mechanism for & has already been set", Mech_Name, Ent);
11209 end if;
11211 -- MECHANISM_NAME ::= value | reference
11213 if Nkind (Mech_Name) = N_Identifier then
11214 if Chars (Mech_Name) = Name_Value then
11215 Set_Mechanism (Ent, By_Copy);
11216 return;
11218 elsif Chars (Mech_Name) = Name_Reference then
11219 Set_Mechanism (Ent, By_Reference);
11220 return;
11222 elsif Chars (Mech_Name) = Name_Copy then
11223 Error_Pragma_Arg
11224 ("bad mechanism name, Value assumed", Mech_Name);
11226 else
11227 Bad_Mechanism;
11228 end if;
11230 else
11231 Bad_Mechanism;
11232 end if;
11233 end Set_Mechanism_Value;
11235 --------------------------
11236 -- Set_Rational_Profile --
11237 --------------------------
11239 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
11240 -- extension to the semantics of renaming declarations.
11242 procedure Set_Rational_Profile is
11243 begin
11244 Implicit_Packing := True;
11245 Overriding_Renamings := True;
11246 Use_VADS_Size := True;
11247 end Set_Rational_Profile;
11249 ---------------------------
11250 -- Set_Ravenscar_Profile --
11251 ---------------------------
11253 -- The tasks to be done here are
11255 -- Set required policies
11257 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11258 -- (For Ravenscar, Jorvik, and GNAT_Extended_Ravenscar profiles)
11259 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11260 -- (For GNAT_Ravenscar_EDF profile)
11261 -- pragma Locking_Policy (Ceiling_Locking)
11263 -- Set Detect_Blocking mode
11265 -- Set required restrictions (see System.Rident for detailed list)
11267 -- Set the No_Dependence rules
11268 -- No_Dependence => Ada.Asynchronous_Task_Control
11269 -- No_Dependence => Ada.Calendar
11270 -- No_Dependence => Ada.Execution_Time.Group_Budget
11271 -- No_Dependence => Ada.Execution_Time.Timers
11272 -- No_Dependence => Ada.Task_Attributes
11273 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11275 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id) is
11276 procedure Set_Error_Msg_To_Profile_Name;
11277 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
11278 -- profile.
11280 -----------------------------------
11281 -- Set_Error_Msg_To_Profile_Name --
11282 -----------------------------------
11284 procedure Set_Error_Msg_To_Profile_Name is
11285 Prof_Nam : constant Node_Id :=
11286 Get_Pragma_Arg
11287 (First (Pragma_Argument_Associations (N)));
11289 begin
11290 Get_Name_String (Chars (Prof_Nam));
11291 Adjust_Name_Case (Global_Name_Buffer, Sloc (Prof_Nam));
11292 Error_Msg_Strlen := Name_Len;
11293 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
11294 end Set_Error_Msg_To_Profile_Name;
11296 Profile_Dispatching_Policy : Character;
11298 -- Start of processing for Set_Ravenscar_Profile
11300 begin
11301 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
11303 if Profile = GNAT_Ravenscar_EDF then
11304 Profile_Dispatching_Policy := 'E';
11306 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
11308 else
11309 Profile_Dispatching_Policy := 'F';
11310 end if;
11312 if Task_Dispatching_Policy /= ' '
11313 and then Task_Dispatching_Policy /= Profile_Dispatching_Policy
11314 then
11315 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11316 Set_Error_Msg_To_Profile_Name;
11317 Error_Pragma ("Profile (~) incompatible with policy#");
11319 -- Set the FIFO_Within_Priorities policy, but always preserve
11320 -- System_Location since we like the error message with the run time
11321 -- name.
11323 else
11324 Task_Dispatching_Policy := Profile_Dispatching_Policy;
11326 if Task_Dispatching_Policy_Sloc /= System_Location then
11327 Task_Dispatching_Policy_Sloc := Loc;
11328 end if;
11329 end if;
11331 -- pragma Locking_Policy (Ceiling_Locking)
11333 if Locking_Policy /= ' '
11334 and then Locking_Policy /= 'C'
11335 then
11336 Error_Msg_Sloc := Locking_Policy_Sloc;
11337 Set_Error_Msg_To_Profile_Name;
11338 Error_Pragma ("Profile (~) incompatible with policy#");
11340 -- Set the Ceiling_Locking policy, but preserve System_Location since
11341 -- we like the error message with the run time name.
11343 else
11344 Locking_Policy := 'C';
11346 if Locking_Policy_Sloc /= System_Location then
11347 Locking_Policy_Sloc := Loc;
11348 end if;
11349 end if;
11351 -- pragma Detect_Blocking
11353 Detect_Blocking := True;
11355 -- Set the corresponding restrictions
11357 Set_Profile_Restrictions
11358 (Profile, N, Warn => Treat_Restrictions_As_Warnings);
11360 -- Set the No_Dependence restrictions
11362 -- The following No_Dependence restrictions:
11363 -- No_Dependence => Ada.Asynchronous_Task_Control
11364 -- No_Dependence => Ada.Calendar
11365 -- No_Dependence => Ada.Task_Attributes
11366 -- are already set by previous call to Set_Profile_Restrictions.
11367 -- Really???
11369 -- Set the following restrictions which were added to Ada 2005:
11370 -- No_Dependence => Ada.Execution_Time.Group_Budget
11371 -- No_Dependence => Ada.Execution_Time.Timers
11373 if Ada_Version >= Ada_2005 then
11374 declare
11375 Execution_Time : constant Node_Id :=
11376 Sel_Comp ("ada", "execution_time", Loc);
11377 Group_Budgets : constant Node_Id :=
11378 Sel_Comp (Execution_Time, "group_budgets");
11379 Timers : constant Node_Id :=
11380 Sel_Comp (Execution_Time, "timers");
11381 begin
11382 Set_Restriction_No_Dependence
11383 (Unit => Group_Budgets,
11384 Warn => Treat_Restrictions_As_Warnings,
11385 Profile => Ravenscar);
11386 Set_Restriction_No_Dependence
11387 (Unit => Timers,
11388 Warn => Treat_Restrictions_As_Warnings,
11389 Profile => Ravenscar);
11390 end;
11391 end if;
11393 -- Set the following restriction which was added to Ada 2012 (see
11394 -- AI05-0171):
11395 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11397 if Ada_Version >= Ada_2012 then
11398 Set_Restriction_No_Dependence
11399 (Sel_Comp
11400 (Sel_Comp ("system", "multiprocessors", Loc),
11401 "dispatching_domains"),
11402 Warn => Treat_Restrictions_As_Warnings,
11403 Profile => Ravenscar);
11405 -- Set the following restriction which was added to Ada 2020,
11406 -- but as a binding interpretation:
11407 -- No_Dependence => Ada.Synchronous_Barriers
11408 -- for Ravenscar (and therefore for Ravenscar variants) but not
11409 -- for Jorvik. The unit Ada.Synchronous_Barriers was introduced
11410 -- in Ada2012 (AI05-0174).
11412 if Profile /= Jorvik then
11413 Set_Restriction_No_Dependence
11414 (Sel_Comp ("ada", "synchronous_barriers", Loc),
11415 Warn => Treat_Restrictions_As_Warnings,
11416 Profile => Ravenscar);
11417 end if;
11418 end if;
11420 end Set_Ravenscar_Profile;
11422 -- Start of processing for Analyze_Pragma
11424 begin
11425 -- The following code is a defense against recursion. Not clear that
11426 -- this can happen legitimately, but perhaps some error situations can
11427 -- cause it, and we did see this recursion during testing.
11429 if Analyzed (N) then
11430 return;
11431 else
11432 Set_Analyzed (N);
11433 end if;
11435 Check_Restriction_No_Use_Of_Pragma (N);
11437 if Get_Aspect_Id (Chars (Pragma_Identifier (N))) /= No_Aspect then
11438 -- 6.1/3 No_Specification_of_Aspect: Identifies an aspect for which
11439 -- no aspect_specification, attribute_definition_clause, or pragma
11440 -- is given.
11441 Check_Restriction_No_Specification_Of_Aspect (N);
11442 end if;
11444 -- Ignore pragma if Ignore_Pragma applies. Also ignore pragma
11445 -- Default_Scalar_Storage_Order if the -gnatI switch was given.
11447 if Should_Ignore_Pragma_Sem (N)
11448 or else (Prag_Id = Pragma_Default_Scalar_Storage_Order
11449 and then Ignore_Rep_Clauses)
11450 then
11451 return;
11452 end if;
11454 -- Deal with unrecognized pragma
11456 if not Is_Pragma_Name (Pname) then
11457 if Warn_On_Unrecognized_Pragma then
11458 Error_Msg_Name_1 := Pname;
11459 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
11461 for PN in First_Pragma_Name .. Last_Pragma_Name loop
11462 if Is_Bad_Spelling_Of (Pname, PN) then
11463 Error_Msg_Name_1 := PN;
11464 Error_Msg_N -- CODEFIX
11465 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
11466 exit;
11467 end if;
11468 end loop;
11469 end if;
11471 return;
11472 end if;
11474 -- Here to start processing for recognized pragma
11476 Pname := Original_Aspect_Pragma_Name (N);
11478 -- Capture setting of Opt.Uneval_Old
11480 case Opt.Uneval_Old is
11481 when 'A' =>
11482 Set_Uneval_Old_Accept (N);
11484 when 'E' =>
11485 null;
11487 when 'W' =>
11488 Set_Uneval_Old_Warn (N);
11490 when others =>
11491 raise Program_Error;
11492 end case;
11494 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
11495 -- is already set, indicating that we have already checked the policy
11496 -- at the right point. This happens for example in the case of a pragma
11497 -- that is derived from an Aspect.
11499 if Is_Ignored (N) or else Is_Checked (N) then
11500 null;
11502 -- For a pragma that is a rewriting of another pragma, copy the
11503 -- Is_Checked/Is_Ignored status from the rewritten pragma.
11505 elsif Is_Rewrite_Substitution (N)
11506 and then Nkind (Original_Node (N)) = N_Pragma
11507 then
11508 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
11509 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
11511 -- Otherwise query the applicable policy at this point
11513 else
11514 Check_Applicable_Policy (N);
11516 -- If pragma is disabled, rewrite as NULL and skip analysis
11518 if Is_Disabled (N) then
11519 Rewrite (N, Make_Null_Statement (Loc));
11520 Analyze (N);
11521 raise Pragma_Exit;
11522 end if;
11523 end if;
11525 -- Preset arguments
11527 Arg_Count := 0;
11528 Arg1 := Empty;
11529 Arg2 := Empty;
11530 Arg3 := Empty;
11531 Arg4 := Empty;
11532 Arg5 := Empty;
11534 if Present (Pragma_Argument_Associations (N)) then
11535 Arg_Count := List_Length (Pragma_Argument_Associations (N));
11536 Arg1 := First (Pragma_Argument_Associations (N));
11538 if Present (Arg1) then
11539 Arg2 := Next (Arg1);
11541 if Present (Arg2) then
11542 Arg3 := Next (Arg2);
11544 if Present (Arg3) then
11545 Arg4 := Next (Arg3);
11547 if Present (Arg4) then
11548 Arg5 := Next (Arg4);
11549 end if;
11550 end if;
11551 end if;
11552 end if;
11553 end if;
11555 -- An enumeration type defines the pragmas that are supported by the
11556 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
11557 -- into the corresponding enumeration value for the following case.
11559 case Prag_Id is
11561 -----------------
11562 -- Abort_Defer --
11563 -----------------
11565 -- pragma Abort_Defer;
11567 when Pragma_Abort_Defer =>
11568 GNAT_Pragma;
11569 Check_Arg_Count (0);
11571 -- The only required semantic processing is to check the
11572 -- placement. This pragma must appear at the start of the
11573 -- statement sequence of a handled sequence of statements.
11575 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
11576 or else N /= First (Statements (Parent (N)))
11577 then
11578 Pragma_Misplaced;
11579 end if;
11581 --------------------
11582 -- Abstract_State --
11583 --------------------
11585 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
11587 -- ABSTRACT_STATE_LIST ::=
11588 -- null
11589 -- | STATE_NAME_WITH_OPTIONS
11590 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
11592 -- STATE_NAME_WITH_OPTIONS ::=
11593 -- STATE_NAME
11594 -- | (STATE_NAME with OPTION_LIST)
11596 -- OPTION_LIST ::= OPTION {, OPTION}
11598 -- OPTION ::=
11599 -- SIMPLE_OPTION
11600 -- | NAME_VALUE_OPTION
11602 -- SIMPLE_OPTION ::= Ghost | Relaxed_Initialization | Synchronous
11604 -- NAME_VALUE_OPTION ::=
11605 -- Part_Of => ABSTRACT_STATE
11606 -- | External [=> EXTERNAL_PROPERTY_LIST]
11608 -- EXTERNAL_PROPERTY_LIST ::=
11609 -- EXTERNAL_PROPERTY
11610 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
11612 -- EXTERNAL_PROPERTY ::=
11613 -- Async_Readers [=> boolean_EXPRESSION]
11614 -- | Async_Writers [=> boolean_EXPRESSION]
11615 -- | Effective_Reads [=> boolean_EXPRESSION]
11616 -- | Effective_Writes [=> boolean_EXPRESSION]
11617 -- others => boolean_EXPRESSION
11619 -- STATE_NAME ::= defining_identifier
11621 -- ABSTRACT_STATE ::= name
11623 -- Characteristics:
11625 -- * Analysis - The annotation is fully analyzed immediately upon
11626 -- elaboration as it cannot forward reference entities.
11628 -- * Expansion - None.
11630 -- * Template - The annotation utilizes the generic template of the
11631 -- related package declaration.
11633 -- * Globals - The annotation cannot reference global entities.
11635 -- * Instance - The annotation is instantiated automatically when
11636 -- the related generic package is instantiated.
11638 when Pragma_Abstract_State => Abstract_State : declare
11639 Missing_Parentheses : Boolean := False;
11640 -- Flag set when a state declaration with options is not properly
11641 -- parenthesized.
11643 -- Flags used to verify the consistency of states
11645 Non_Null_Seen : Boolean := False;
11646 Null_Seen : Boolean := False;
11648 procedure Analyze_Abstract_State
11649 (State : Node_Id;
11650 Pack_Id : Entity_Id);
11651 -- Verify the legality of a single state declaration. Create and
11652 -- decorate a state abstraction entity and introduce it into the
11653 -- visibility chain. Pack_Id denotes the entity or the related
11654 -- package where pragma Abstract_State appears.
11656 procedure Malformed_State_Error (State : Node_Id);
11657 -- Emit an error concerning the illegal declaration of abstract
11658 -- state State. This routine diagnoses syntax errors that lead to
11659 -- a different parse tree. The error is issued regardless of the
11660 -- SPARK mode in effect.
11662 ----------------------------
11663 -- Analyze_Abstract_State --
11664 ----------------------------
11666 procedure Analyze_Abstract_State
11667 (State : Node_Id;
11668 Pack_Id : Entity_Id)
11670 -- Flags used to verify the consistency of options
11672 AR_Seen : Boolean := False;
11673 AW_Seen : Boolean := False;
11674 ER_Seen : Boolean := False;
11675 EW_Seen : Boolean := False;
11676 External_Seen : Boolean := False;
11677 Ghost_Seen : Boolean := False;
11678 Others_Seen : Boolean := False;
11679 Part_Of_Seen : Boolean := False;
11680 Relaxed_Initialization_Seen : Boolean := False;
11681 Synchronous_Seen : Boolean := False;
11683 -- Flags used to store the static value of all external states'
11684 -- expressions.
11686 AR_Val : Boolean := False;
11687 AW_Val : Boolean := False;
11688 ER_Val : Boolean := False;
11689 EW_Val : Boolean := False;
11691 State_Id : Entity_Id := Empty;
11692 -- The entity to be generated for the current state declaration
11694 procedure Analyze_External_Option (Opt : Node_Id);
11695 -- Verify the legality of option External
11697 procedure Analyze_External_Property
11698 (Prop : Node_Id;
11699 Expr : Node_Id := Empty);
11700 -- Verify the legailty of a single external property. Prop
11701 -- denotes the external property. Expr is the expression used
11702 -- to set the property.
11704 procedure Analyze_Part_Of_Option (Opt : Node_Id);
11705 -- Verify the legality of option Part_Of
11707 procedure Check_Duplicate_Option
11708 (Opt : Node_Id;
11709 Status : in out Boolean);
11710 -- Flag Status denotes whether a particular option has been
11711 -- seen while processing a state. This routine verifies that
11712 -- Opt is not a duplicate option and sets the flag Status
11713 -- (SPARK RM 7.1.4(1)).
11715 procedure Check_Duplicate_Property
11716 (Prop : Node_Id;
11717 Status : in out Boolean);
11718 -- Flag Status denotes whether a particular property has been
11719 -- seen while processing option External. This routine verifies
11720 -- that Prop is not a duplicate property and sets flag Status.
11721 -- Opt is not a duplicate property and sets the flag Status.
11722 -- (SPARK RM 7.1.4(2))
11724 procedure Check_Ghost_Synchronous;
11725 -- Ensure that the abstract state is not subject to both Ghost
11726 -- and Synchronous simple options. Emit an error if this is the
11727 -- case.
11729 procedure Create_Abstract_State
11730 (Nam : Name_Id;
11731 Decl : Node_Id;
11732 Loc : Source_Ptr;
11733 Is_Null : Boolean);
11734 -- Generate an abstract state entity with name Nam and enter it
11735 -- into visibility. Decl is the "declaration" of the state as
11736 -- it appears in pragma Abstract_State. Loc is the location of
11737 -- the related state "declaration". Flag Is_Null should be set
11738 -- when the associated Abstract_State pragma defines a null
11739 -- state.
11741 -----------------------------
11742 -- Analyze_External_Option --
11743 -----------------------------
11745 procedure Analyze_External_Option (Opt : Node_Id) is
11746 Errors : constant Nat := Serious_Errors_Detected;
11747 Prop : Node_Id;
11748 Props : Node_Id := Empty;
11750 begin
11751 if Nkind (Opt) = N_Component_Association then
11752 Props := Expression (Opt);
11753 end if;
11755 -- External state with properties
11757 if Present (Props) then
11759 -- Multiple properties appear as an aggregate
11761 if Nkind (Props) = N_Aggregate then
11763 -- Simple property form
11765 Prop := First (Expressions (Props));
11766 while Present (Prop) loop
11767 Analyze_External_Property (Prop);
11768 Next (Prop);
11769 end loop;
11771 -- Property with expression form
11773 Prop := First (Component_Associations (Props));
11774 while Present (Prop) loop
11775 Analyze_External_Property
11776 (Prop => First (Choices (Prop)),
11777 Expr => Expression (Prop));
11779 Next (Prop);
11780 end loop;
11782 -- Single property
11784 else
11785 Analyze_External_Property (Props);
11786 end if;
11788 -- An external state defined without any properties defaults
11789 -- all properties to True.
11791 else
11792 AR_Val := True;
11793 AW_Val := True;
11794 ER_Val := True;
11795 EW_Val := True;
11796 end if;
11798 -- Once all external properties have been processed, verify
11799 -- their mutual interaction. Do not perform the check when
11800 -- at least one of the properties is illegal as this will
11801 -- produce a bogus error.
11803 if Errors = Serious_Errors_Detected then
11804 Check_External_Properties
11805 (State, AR_Val, AW_Val, ER_Val, EW_Val);
11806 end if;
11807 end Analyze_External_Option;
11809 -------------------------------
11810 -- Analyze_External_Property --
11811 -------------------------------
11813 procedure Analyze_External_Property
11814 (Prop : Node_Id;
11815 Expr : Node_Id := Empty)
11817 Expr_Val : Boolean;
11819 begin
11820 -- Check the placement of "others" (if available)
11822 if Nkind (Prop) = N_Others_Choice then
11823 if Others_Seen then
11824 SPARK_Msg_N
11825 ("only one others choice allowed in option External",
11826 Prop);
11827 else
11828 Others_Seen := True;
11829 end if;
11831 elsif Others_Seen then
11832 SPARK_Msg_N
11833 ("others must be the last property in option External",
11834 Prop);
11836 -- The only remaining legal options are the four predefined
11837 -- external properties.
11839 elsif Nkind (Prop) = N_Identifier
11840 and then Chars (Prop) in Name_Async_Readers
11841 | Name_Async_Writers
11842 | Name_Effective_Reads
11843 | Name_Effective_Writes
11844 then
11845 null;
11847 -- Otherwise the construct is not a valid property
11849 else
11850 SPARK_Msg_N ("invalid external state property", Prop);
11851 return;
11852 end if;
11854 -- Ensure that the expression of the external state property
11855 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
11857 if Present (Expr) then
11858 Analyze_And_Resolve (Expr, Standard_Boolean);
11860 if Is_OK_Static_Expression (Expr) then
11861 Expr_Val := Is_True (Expr_Value (Expr));
11862 else
11863 SPARK_Msg_N
11864 ("expression of external state property must be "
11865 & "static", Expr);
11866 return;
11867 end if;
11869 -- The lack of expression defaults the property to True
11871 else
11872 Expr_Val := True;
11873 end if;
11875 -- Named properties
11877 if Nkind (Prop) = N_Identifier then
11878 if Chars (Prop) = Name_Async_Readers then
11879 Check_Duplicate_Property (Prop, AR_Seen);
11880 AR_Val := Expr_Val;
11882 elsif Chars (Prop) = Name_Async_Writers then
11883 Check_Duplicate_Property (Prop, AW_Seen);
11884 AW_Val := Expr_Val;
11886 elsif Chars (Prop) = Name_Effective_Reads then
11887 Check_Duplicate_Property (Prop, ER_Seen);
11888 ER_Val := Expr_Val;
11890 else
11891 Check_Duplicate_Property (Prop, EW_Seen);
11892 EW_Val := Expr_Val;
11893 end if;
11895 -- The handling of property "others" must take into account
11896 -- all other named properties that have been encountered so
11897 -- far. Only those that have not been seen are affected by
11898 -- "others".
11900 else
11901 if not AR_Seen then
11902 AR_Val := Expr_Val;
11903 end if;
11905 if not AW_Seen then
11906 AW_Val := Expr_Val;
11907 end if;
11909 if not ER_Seen then
11910 ER_Val := Expr_Val;
11911 end if;
11913 if not EW_Seen then
11914 EW_Val := Expr_Val;
11915 end if;
11916 end if;
11917 end Analyze_External_Property;
11919 ----------------------------
11920 -- Analyze_Part_Of_Option --
11921 ----------------------------
11923 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
11924 Encap : constant Node_Id := Expression (Opt);
11925 Constits : Elist_Id;
11926 Encap_Id : Entity_Id;
11927 Legal : Boolean;
11929 begin
11930 Check_Duplicate_Option (Opt, Part_Of_Seen);
11932 Analyze_Part_Of
11933 (Indic => First (Choices (Opt)),
11934 Item_Id => State_Id,
11935 Encap => Encap,
11936 Encap_Id => Encap_Id,
11937 Legal => Legal);
11939 -- The Part_Of indicator transforms the abstract state into
11940 -- a constituent of the encapsulating state or single
11941 -- concurrent type.
11943 if Legal then
11944 pragma Assert (Present (Encap_Id));
11945 Constits := Part_Of_Constituents (Encap_Id);
11947 if No (Constits) then
11948 Constits := New_Elmt_List;
11949 Set_Part_Of_Constituents (Encap_Id, Constits);
11950 end if;
11952 Append_Elmt (State_Id, Constits);
11953 Set_Encapsulating_State (State_Id, Encap_Id);
11954 end if;
11955 end Analyze_Part_Of_Option;
11957 ----------------------------
11958 -- Check_Duplicate_Option --
11959 ----------------------------
11961 procedure Check_Duplicate_Option
11962 (Opt : Node_Id;
11963 Status : in out Boolean)
11965 begin
11966 if Status then
11967 SPARK_Msg_N ("duplicate state option", Opt);
11968 end if;
11970 Status := True;
11971 end Check_Duplicate_Option;
11973 ------------------------------
11974 -- Check_Duplicate_Property --
11975 ------------------------------
11977 procedure Check_Duplicate_Property
11978 (Prop : Node_Id;
11979 Status : in out Boolean)
11981 begin
11982 if Status then
11983 SPARK_Msg_N ("duplicate external property", Prop);
11984 end if;
11986 Status := True;
11987 end Check_Duplicate_Property;
11989 -----------------------------
11990 -- Check_Ghost_Synchronous --
11991 -----------------------------
11993 procedure Check_Ghost_Synchronous is
11994 begin
11995 -- A synchronized abstract state cannot be Ghost and vice
11996 -- versa (SPARK RM 6.9(19)).
11998 if Ghost_Seen and Synchronous_Seen then
11999 SPARK_Msg_N ("synchronized state cannot be ghost", State);
12000 end if;
12001 end Check_Ghost_Synchronous;
12003 ---------------------------
12004 -- Create_Abstract_State --
12005 ---------------------------
12007 procedure Create_Abstract_State
12008 (Nam : Name_Id;
12009 Decl : Node_Id;
12010 Loc : Source_Ptr;
12011 Is_Null : Boolean)
12013 begin
12014 -- The abstract state may be semi-declared when the related
12015 -- package was withed through a limited with clause. In that
12016 -- case reuse the entity to fully declare the state.
12018 if Present (Decl) and then Present (Entity (Decl)) then
12019 State_Id := Entity (Decl);
12021 -- Otherwise the elaboration of pragma Abstract_State
12022 -- declares the state.
12024 else
12025 State_Id := Make_Defining_Identifier (Loc, Nam);
12027 if Present (Decl) then
12028 Set_Entity (Decl, State_Id);
12029 end if;
12030 end if;
12032 -- Null states never come from source
12034 Set_Comes_From_Source (State_Id, not Is_Null);
12035 Set_Parent (State_Id, State);
12036 Set_Ekind (State_Id, E_Abstract_State);
12037 Set_Etype (State_Id, Standard_Void_Type);
12038 Set_Encapsulating_State (State_Id, Empty);
12040 -- Set the SPARK mode from the current context
12042 Set_SPARK_Pragma (State_Id, SPARK_Mode_Pragma);
12043 Set_SPARK_Pragma_Inherited (State_Id);
12045 -- An abstract state declared within a Ghost region becomes
12046 -- Ghost (SPARK RM 6.9(2)).
12048 if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then
12049 Set_Is_Ghost_Entity (State_Id);
12050 end if;
12052 -- Establish a link between the state declaration and the
12053 -- abstract state entity. Note that a null state remains as
12054 -- N_Null and does not carry any linkages.
12056 if not Is_Null then
12057 if Present (Decl) then
12058 Set_Entity (Decl, State_Id);
12059 Set_Etype (Decl, Standard_Void_Type);
12060 end if;
12062 -- Every non-null state must be defined, nameable and
12063 -- resolvable.
12065 Push_Scope (Pack_Id);
12066 Generate_Definition (State_Id);
12067 Enter_Name (State_Id);
12068 Pop_Scope;
12069 end if;
12070 end Create_Abstract_State;
12072 -- Local variables
12074 Opt : Node_Id;
12075 Opt_Nam : Node_Id;
12077 -- Start of processing for Analyze_Abstract_State
12079 begin
12080 -- A package with a null abstract state is not allowed to
12081 -- declare additional states.
12083 if Null_Seen then
12084 SPARK_Msg_NE
12085 ("package & has null abstract state", State, Pack_Id);
12087 -- Null states appear as internally generated entities
12089 elsif Nkind (State) = N_Null then
12090 Create_Abstract_State
12091 (Nam => New_Internal_Name ('S'),
12092 Decl => Empty,
12093 Loc => Sloc (State),
12094 Is_Null => True);
12095 Null_Seen := True;
12097 -- Catch a case where a null state appears in a list of
12098 -- non-null states.
12100 if Non_Null_Seen then
12101 SPARK_Msg_NE
12102 ("package & has non-null abstract state",
12103 State, Pack_Id);
12104 end if;
12106 -- Simple state declaration
12108 elsif Nkind (State) = N_Identifier then
12109 Create_Abstract_State
12110 (Nam => Chars (State),
12111 Decl => State,
12112 Loc => Sloc (State),
12113 Is_Null => False);
12114 Non_Null_Seen := True;
12116 -- State declaration with various options. This construct
12117 -- appears as an extension aggregate in the tree.
12119 elsif Nkind (State) = N_Extension_Aggregate then
12120 if Nkind (Ancestor_Part (State)) = N_Identifier then
12121 Create_Abstract_State
12122 (Nam => Chars (Ancestor_Part (State)),
12123 Decl => Ancestor_Part (State),
12124 Loc => Sloc (Ancestor_Part (State)),
12125 Is_Null => False);
12126 Non_Null_Seen := True;
12127 else
12128 SPARK_Msg_N
12129 ("state name must be an identifier",
12130 Ancestor_Part (State));
12131 end if;
12133 -- Options External, Ghost and Synchronous appear as
12134 -- expressions.
12136 Opt := First (Expressions (State));
12137 while Present (Opt) loop
12138 if Nkind (Opt) = N_Identifier then
12140 -- External
12142 if Chars (Opt) = Name_External then
12143 Check_Duplicate_Option (Opt, External_Seen);
12144 Analyze_External_Option (Opt);
12146 -- Ghost
12148 elsif Chars (Opt) = Name_Ghost then
12149 Check_Duplicate_Option (Opt, Ghost_Seen);
12150 Check_Ghost_Synchronous;
12152 if Present (State_Id) then
12153 Set_Is_Ghost_Entity (State_Id);
12154 end if;
12156 -- Synchronous
12158 elsif Chars (Opt) = Name_Synchronous then
12159 Check_Duplicate_Option (Opt, Synchronous_Seen);
12160 Check_Ghost_Synchronous;
12162 -- Relaxed_Initialization
12164 elsif Chars (Opt) = Name_Relaxed_Initialization then
12165 Check_Duplicate_Option
12166 (Opt, Relaxed_Initialization_Seen);
12168 -- Option Part_Of without an encapsulating state is
12169 -- illegal (SPARK RM 7.1.4(8)).
12171 elsif Chars (Opt) = Name_Part_Of then
12172 SPARK_Msg_N
12173 ("indicator Part_Of must denote abstract state, "
12174 & "single protected type or single task type",
12175 Opt);
12177 -- Do not emit an error message when a previous state
12178 -- declaration with options was not parenthesized as
12179 -- the option is actually another state declaration.
12181 -- with Abstract_State
12182 -- (State_1 with ..., -- missing parentheses
12183 -- (State_2 with ...),
12184 -- State_3) -- ok state declaration
12186 elsif Missing_Parentheses then
12187 null;
12189 -- Otherwise the option is not allowed. Note that it
12190 -- is not possible to distinguish between an option
12191 -- and a state declaration when a previous state with
12192 -- options not properly parentheses.
12194 -- with Abstract_State
12195 -- (State_1 with ..., -- missing parentheses
12196 -- State_2); -- could be an option
12198 else
12199 SPARK_Msg_N
12200 ("simple option not allowed in state declaration",
12201 Opt);
12202 end if;
12204 -- Catch a case where missing parentheses around a state
12205 -- declaration with options cause a subsequent state
12206 -- declaration with options to be treated as an option.
12208 -- with Abstract_State
12209 -- (State_1 with ..., -- missing parentheses
12210 -- (State_2 with ...))
12212 elsif Nkind (Opt) = N_Extension_Aggregate then
12213 Missing_Parentheses := True;
12214 SPARK_Msg_N
12215 ("state declaration must be parenthesized",
12216 Ancestor_Part (State));
12218 -- Otherwise the option is malformed
12220 else
12221 SPARK_Msg_N ("malformed option", Opt);
12222 end if;
12224 Next (Opt);
12225 end loop;
12227 -- Options External and Part_Of appear as component
12228 -- associations.
12230 Opt := First (Component_Associations (State));
12231 while Present (Opt) loop
12232 Opt_Nam := First (Choices (Opt));
12234 if Nkind (Opt_Nam) = N_Identifier then
12235 if Chars (Opt_Nam) = Name_External then
12236 Analyze_External_Option (Opt);
12238 elsif Chars (Opt_Nam) = Name_Part_Of then
12239 Analyze_Part_Of_Option (Opt);
12241 else
12242 SPARK_Msg_N ("invalid state option", Opt);
12243 end if;
12244 else
12245 SPARK_Msg_N ("invalid state option", Opt);
12246 end if;
12248 Next (Opt);
12249 end loop;
12251 -- Any other attempt to declare a state is illegal
12253 else
12254 Malformed_State_Error (State);
12255 return;
12256 end if;
12258 -- Guard against a junk state. In such cases no entity is
12259 -- generated and the subsequent checks cannot be applied.
12261 if Present (State_Id) then
12263 -- Verify whether the state does not introduce an illegal
12264 -- hidden state within a package subject to a null abstract
12265 -- state.
12267 Check_No_Hidden_State (State_Id);
12269 -- Check whether the lack of option Part_Of agrees with the
12270 -- placement of the abstract state with respect to the state
12271 -- space.
12273 if not Part_Of_Seen then
12274 Check_Missing_Part_Of (State_Id);
12275 end if;
12277 -- Associate the state with its related package
12279 if No (Abstract_States (Pack_Id)) then
12280 Set_Abstract_States (Pack_Id, New_Elmt_List);
12281 end if;
12283 Append_Elmt (State_Id, Abstract_States (Pack_Id));
12284 end if;
12285 end Analyze_Abstract_State;
12287 ---------------------------
12288 -- Malformed_State_Error --
12289 ---------------------------
12291 procedure Malformed_State_Error (State : Node_Id) is
12292 begin
12293 Error_Msg_N ("malformed abstract state declaration", State);
12295 -- An abstract state with a simple option is being declared
12296 -- with "=>" rather than the legal "with". The state appears
12297 -- as a component association.
12299 if Nkind (State) = N_Component_Association then
12300 Error_Msg_N ("\use WITH to specify simple option", State);
12301 end if;
12302 end Malformed_State_Error;
12304 -- Local variables
12306 Pack_Decl : Node_Id;
12307 Pack_Id : Entity_Id;
12308 State : Node_Id;
12309 States : Node_Id;
12311 -- Start of processing for Abstract_State
12313 begin
12314 GNAT_Pragma;
12315 Check_No_Identifiers;
12316 Check_Arg_Count (1);
12318 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
12320 if Nkind (Pack_Decl) not in
12321 N_Generic_Package_Declaration | N_Package_Declaration
12322 then
12323 Pragma_Misplaced;
12324 return;
12325 end if;
12327 Pack_Id := Defining_Entity (Pack_Decl);
12329 -- A pragma that applies to a Ghost entity becomes Ghost for the
12330 -- purposes of legality checks and removal of ignored Ghost code.
12332 Mark_Ghost_Pragma (N, Pack_Id);
12333 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
12335 -- Chain the pragma on the contract for completeness
12337 Add_Contract_Item (N, Pack_Id);
12339 -- The legality checks of pragmas Abstract_State, Initializes, and
12340 -- Initial_Condition are affected by the SPARK mode in effect. In
12341 -- addition, these three pragmas are subject to an inherent order:
12343 -- 1) Abstract_State
12344 -- 2) Initializes
12345 -- 3) Initial_Condition
12347 -- Analyze all these pragmas in the order outlined above
12349 Analyze_If_Present (Pragma_SPARK_Mode);
12350 States := Expression (Get_Argument (N, Pack_Id));
12352 -- Multiple non-null abstract states appear as an aggregate
12354 if Nkind (States) = N_Aggregate then
12355 State := First (Expressions (States));
12356 while Present (State) loop
12357 Analyze_Abstract_State (State, Pack_Id);
12358 Next (State);
12359 end loop;
12361 -- An abstract state with a simple option is being illegaly
12362 -- declared with "=>" rather than "with". In this case the
12363 -- state declaration appears as a component association.
12365 if Present (Component_Associations (States)) then
12366 State := First (Component_Associations (States));
12367 while Present (State) loop
12368 Malformed_State_Error (State);
12369 Next (State);
12370 end loop;
12371 end if;
12373 -- Various forms of a single abstract state. Note that these may
12374 -- include malformed state declarations.
12376 else
12377 Analyze_Abstract_State (States, Pack_Id);
12378 end if;
12380 Analyze_If_Present (Pragma_Initializes);
12381 Analyze_If_Present (Pragma_Initial_Condition);
12382 end Abstract_State;
12384 ------------
12385 -- Ada_83 --
12386 ------------
12388 -- pragma Ada_83;
12390 -- Note: this pragma also has some specific processing in Par.Prag
12391 -- because we want to set the Ada version mode during parsing.
12393 when Pragma_Ada_83 =>
12394 GNAT_Pragma;
12395 Check_Arg_Count (0);
12397 -- We really should check unconditionally for proper configuration
12398 -- pragma placement, since we really don't want mixed Ada modes
12399 -- within a single unit, and the GNAT reference manual has always
12400 -- said this was a configuration pragma, but we did not check and
12401 -- are hesitant to add the check now.
12403 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
12404 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
12405 -- or Ada 2012 mode.
12407 if Ada_Version >= Ada_2005 then
12408 Check_Valid_Configuration_Pragma;
12409 end if;
12411 -- Now set Ada 83 mode
12413 if Latest_Ada_Only then
12414 Error_Pragma ("??pragma% ignored");
12415 else
12416 Ada_Version := Ada_83;
12417 Ada_Version_Explicit := Ada_83;
12418 Ada_Version_Pragma := N;
12419 end if;
12421 ------------
12422 -- Ada_95 --
12423 ------------
12425 -- pragma Ada_95;
12427 -- Note: this pragma also has some specific processing in Par.Prag
12428 -- because we want to set the Ada 83 version mode during parsing.
12430 when Pragma_Ada_95 =>
12431 GNAT_Pragma;
12432 Check_Arg_Count (0);
12434 -- We really should check unconditionally for proper configuration
12435 -- pragma placement, since we really don't want mixed Ada modes
12436 -- within a single unit, and the GNAT reference manual has always
12437 -- said this was a configuration pragma, but we did not check and
12438 -- are hesitant to add the check now.
12440 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
12441 -- or Ada 95, so we must check if we are in Ada 2005 mode.
12443 if Ada_Version >= Ada_2005 then
12444 Check_Valid_Configuration_Pragma;
12445 end if;
12447 -- Now set Ada 95 mode
12449 if Latest_Ada_Only then
12450 Error_Pragma ("??pragma% ignored");
12451 else
12452 Ada_Version := Ada_95;
12453 Ada_Version_Explicit := Ada_95;
12454 Ada_Version_Pragma := N;
12455 end if;
12457 ---------------------
12458 -- Ada_05/Ada_2005 --
12459 ---------------------
12461 -- pragma Ada_05;
12462 -- pragma Ada_05 (LOCAL_NAME);
12464 -- pragma Ada_2005;
12465 -- pragma Ada_2005 (LOCAL_NAME):
12467 -- Note: these pragmas also have some specific processing in Par.Prag
12468 -- because we want to set the Ada 2005 version mode during parsing.
12470 -- The one argument form is used for managing the transition from
12471 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
12472 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
12473 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
12474 -- mode, a preference rule is established which does not choose
12475 -- such an entity unless it is unambiguously specified. This avoids
12476 -- extra subprograms marked this way from generating ambiguities in
12477 -- otherwise legal pre-Ada_2005 programs. The one argument form is
12478 -- intended for exclusive use in the GNAT run-time library.
12480 when Pragma_Ada_05
12481 | Pragma_Ada_2005
12483 declare
12484 E_Id : Node_Id;
12486 begin
12487 GNAT_Pragma;
12489 if Arg_Count = 1 then
12490 Check_Arg_Is_Local_Name (Arg1);
12491 E_Id := Get_Pragma_Arg (Arg1);
12493 if Etype (E_Id) = Any_Type then
12494 return;
12495 end if;
12497 Set_Is_Ada_2005_Only (Entity (E_Id));
12498 Record_Rep_Item (Entity (E_Id), N);
12500 else
12501 Check_Arg_Count (0);
12503 -- For Ada_2005 we unconditionally enforce the documented
12504 -- configuration pragma placement, since we do not want to
12505 -- tolerate mixed modes in a unit involving Ada 2005. That
12506 -- would cause real difficulties for those cases where there
12507 -- are incompatibilities between Ada 95 and Ada 2005.
12509 Check_Valid_Configuration_Pragma;
12511 -- Now set appropriate Ada mode
12513 if Latest_Ada_Only then
12514 Error_Pragma ("??pragma% ignored");
12515 else
12516 Ada_Version := Ada_2005;
12517 Ada_Version_Explicit := Ada_2005;
12518 Ada_Version_Pragma := N;
12519 end if;
12520 end if;
12521 end;
12523 ---------------------
12524 -- Ada_12/Ada_2012 --
12525 ---------------------
12527 -- pragma Ada_12;
12528 -- pragma Ada_12 (LOCAL_NAME);
12530 -- pragma Ada_2012;
12531 -- pragma Ada_2012 (LOCAL_NAME):
12533 -- Note: these pragmas also have some specific processing in Par.Prag
12534 -- because we want to set the Ada 2012 version mode during parsing.
12536 -- The one argument form is used for managing the transition from Ada
12537 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
12538 -- as Ada_2012 only, then referencing the entity in any pre-Ada_2012
12539 -- mode will generate a warning. In addition, in any pre-Ada_2012
12540 -- mode, a preference rule is established which does not choose
12541 -- such an entity unless it is unambiguously specified. This avoids
12542 -- extra subprograms marked this way from generating ambiguities in
12543 -- otherwise legal pre-Ada_2012 programs. The one argument form is
12544 -- intended for exclusive use in the GNAT run-time library.
12546 when Pragma_Ada_12
12547 | Pragma_Ada_2012
12549 declare
12550 E_Id : Node_Id;
12552 begin
12553 GNAT_Pragma;
12555 if Arg_Count = 1 then
12556 Check_Arg_Is_Local_Name (Arg1);
12557 E_Id := Get_Pragma_Arg (Arg1);
12559 if Etype (E_Id) = Any_Type then
12560 return;
12561 end if;
12563 Set_Is_Ada_2012_Only (Entity (E_Id));
12564 Record_Rep_Item (Entity (E_Id), N);
12566 else
12567 Check_Arg_Count (0);
12569 -- For Ada_2012 we unconditionally enforce the documented
12570 -- configuration pragma placement, since we do not want to
12571 -- tolerate mixed modes in a unit involving Ada 2012. That
12572 -- would cause real difficulties for those cases where there
12573 -- are incompatibilities between Ada 95 and Ada 2012. We could
12574 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
12576 Check_Valid_Configuration_Pragma;
12578 -- Now set appropriate Ada mode
12580 Ada_Version := Ada_2012;
12581 Ada_Version_Explicit := Ada_2012;
12582 Ada_Version_Pragma := N;
12583 end if;
12584 end;
12586 --------------
12587 -- Ada_2020 --
12588 --------------
12590 -- pragma Ada_2020;
12592 -- Note: this pragma also has some specific processing in Par.Prag
12593 -- because we want to set the Ada 2020 version mode during parsing.
12595 when Pragma_Ada_2020 =>
12596 GNAT_Pragma;
12598 Check_Arg_Count (0);
12600 Check_Valid_Configuration_Pragma;
12602 -- Now set appropriate Ada mode
12604 Ada_Version := Ada_2020;
12605 Ada_Version_Explicit := Ada_2020;
12606 Ada_Version_Pragma := N;
12608 -------------------------------------
12609 -- Aggregate_Individually_Assign --
12610 -------------------------------------
12612 -- pragma Aggregate_Individually_Assign;
12614 when Pragma_Aggregate_Individually_Assign =>
12615 GNAT_Pragma;
12616 Check_Arg_Count (0);
12617 Check_Valid_Configuration_Pragma;
12618 Aggregate_Individually_Assign := True;
12620 ----------------------
12621 -- All_Calls_Remote --
12622 ----------------------
12624 -- pragma All_Calls_Remote [(library_package_NAME)];
12626 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
12627 Lib_Entity : Entity_Id;
12629 begin
12630 Check_Ada_83_Warning;
12631 Check_Valid_Library_Unit_Pragma;
12633 if Nkind (N) = N_Null_Statement then
12634 return;
12635 end if;
12637 Lib_Entity := Find_Lib_Unit_Name;
12639 -- A pragma that applies to a Ghost entity becomes Ghost for the
12640 -- purposes of legality checks and removal of ignored Ghost code.
12642 Mark_Ghost_Pragma (N, Lib_Entity);
12644 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
12646 if Present (Lib_Entity) and then not Debug_Flag_U then
12647 if not Is_Remote_Call_Interface (Lib_Entity) then
12648 Error_Pragma ("pragma% only apply to rci unit");
12650 -- Set flag for entity of the library unit
12652 else
12653 Set_Has_All_Calls_Remote (Lib_Entity);
12654 end if;
12655 end if;
12656 end All_Calls_Remote;
12658 ---------------------------
12659 -- Allow_Integer_Address --
12660 ---------------------------
12662 -- pragma Allow_Integer_Address;
12664 when Pragma_Allow_Integer_Address =>
12665 GNAT_Pragma;
12666 Check_Valid_Configuration_Pragma;
12667 Check_Arg_Count (0);
12669 -- If Address is a private type, then set the flag to allow
12670 -- integer address values. If Address is not private, then this
12671 -- pragma has no purpose, so it is simply ignored. Not clear if
12672 -- there are any such targets now.
12674 if Opt.Address_Is_Private then
12675 Opt.Allow_Integer_Address := True;
12676 end if;
12678 --------------
12679 -- Annotate --
12680 --------------
12682 -- pragma Annotate
12683 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
12684 -- ARG ::= NAME | EXPRESSION
12686 -- The first two arguments are by convention intended to refer to an
12687 -- external tool and a tool-specific function. These arguments are
12688 -- not analyzed.
12690 when Pragma_Annotate => Annotate : declare
12691 Arg : Node_Id;
12692 Expr : Node_Id;
12693 Nam_Arg : Node_Id;
12695 --------------------------
12696 -- Inferred_String_Type --
12697 --------------------------
12699 function Preferred_String_Type (Expr : Node_Id) return Entity_Id;
12700 -- Infer the type to use for a string literal or a concatentation
12701 -- of operands whose types can be inferred. For such expressions,
12702 -- returns the "narrowest" of the three predefined string types
12703 -- that can represent the characters occurring in the expression.
12704 -- For other expressions, returns Empty.
12706 function Preferred_String_Type (Expr : Node_Id) return Entity_Id is
12707 begin
12708 case Nkind (Expr) is
12709 when N_String_Literal =>
12710 if Has_Wide_Wide_Character (Expr) then
12711 return Standard_Wide_Wide_String;
12712 elsif Has_Wide_Character (Expr) then
12713 return Standard_Wide_String;
12714 else
12715 return Standard_String;
12716 end if;
12718 when N_Op_Concat =>
12719 declare
12720 L_Type : constant Entity_Id
12721 := Preferred_String_Type (Left_Opnd (Expr));
12722 R_Type : constant Entity_Id
12723 := Preferred_String_Type (Right_Opnd (Expr));
12725 Type_Table : constant array (1 .. 4) of Entity_Id
12726 := (Empty,
12727 Standard_Wide_Wide_String,
12728 Standard_Wide_String,
12729 Standard_String);
12730 begin
12731 for Idx in Type_Table'Range loop
12732 if (L_Type = Type_Table (Idx)) or
12733 (R_Type = Type_Table (Idx))
12734 then
12735 return Type_Table (Idx);
12736 end if;
12737 end loop;
12738 raise Program_Error;
12739 end;
12741 when others =>
12742 return Empty;
12743 end case;
12744 end Preferred_String_Type;
12745 begin
12746 GNAT_Pragma;
12747 Check_At_Least_N_Arguments (1);
12749 Nam_Arg := Last (Pragma_Argument_Associations (N));
12751 -- Determine whether the last argument is "Entity => local_NAME"
12752 -- and if it is, perform the required semantic checks. Remove the
12753 -- argument from further processing.
12755 if Nkind (Nam_Arg) = N_Pragma_Argument_Association
12756 and then Chars (Nam_Arg) = Name_Entity
12757 then
12758 Check_Arg_Is_Local_Name (Nam_Arg);
12759 Arg_Count := Arg_Count - 1;
12761 -- A pragma that applies to a Ghost entity becomes Ghost for
12762 -- the purposes of legality checks and removal of ignored Ghost
12763 -- code.
12765 if Is_Entity_Name (Get_Pragma_Arg (Nam_Arg))
12766 and then Present (Entity (Get_Pragma_Arg (Nam_Arg)))
12767 then
12768 Mark_Ghost_Pragma (N, Entity (Get_Pragma_Arg (Nam_Arg)));
12769 end if;
12771 -- Not allowed in compiler units (bootstrap issues)
12773 Check_Compiler_Unit ("Entity for pragma Annotate", N);
12774 end if;
12776 -- Continue the processing with last argument removed for now
12778 Check_Arg_Is_Identifier (Arg1);
12779 Check_No_Identifiers;
12780 Store_Note (N);
12782 -- The second parameter is optional, it is never analyzed
12784 if No (Arg2) then
12785 null;
12787 -- Otherwise there is a second parameter
12789 else
12790 -- The second parameter must be an identifier
12792 Check_Arg_Is_Identifier (Arg2);
12794 -- Process the remaining parameters (if any)
12796 Arg := Next (Arg2);
12797 while Present (Arg) loop
12798 Expr := Get_Pragma_Arg (Arg);
12799 Analyze (Expr);
12801 if Is_Entity_Name (Expr) then
12802 null;
12804 -- For string literals and concatenations of string literals
12805 -- we assume Standard_String as the type, unless the string
12806 -- contains wide or wide_wide characters.
12808 elsif Present (Preferred_String_Type (Expr)) then
12809 Resolve (Expr, Preferred_String_Type (Expr));
12811 elsif Is_Overloaded (Expr) then
12812 Error_Pragma_Arg ("ambiguous argument for pragma%", Expr);
12814 else
12815 Resolve (Expr);
12816 end if;
12818 Next (Arg);
12819 end loop;
12820 end if;
12821 end Annotate;
12823 -------------------------------------------------
12824 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
12825 -------------------------------------------------
12827 -- pragma Assert
12828 -- ( [Check => ] Boolean_EXPRESSION
12829 -- [, [Message =>] Static_String_EXPRESSION]);
12831 -- pragma Assert_And_Cut
12832 -- ( [Check => ] Boolean_EXPRESSION
12833 -- [, [Message =>] Static_String_EXPRESSION]);
12835 -- pragma Assume
12836 -- ( [Check => ] Boolean_EXPRESSION
12837 -- [, [Message =>] Static_String_EXPRESSION]);
12839 -- pragma Loop_Invariant
12840 -- ( [Check => ] Boolean_EXPRESSION
12841 -- [, [Message =>] Static_String_EXPRESSION]);
12843 when Pragma_Assert
12844 | Pragma_Assert_And_Cut
12845 | Pragma_Assume
12846 | Pragma_Loop_Invariant
12848 Assert : declare
12849 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
12850 -- Determine whether expression Expr contains a Loop_Entry
12851 -- attribute reference.
12853 -------------------------
12854 -- Contains_Loop_Entry --
12855 -------------------------
12857 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
12858 Has_Loop_Entry : Boolean := False;
12860 function Process (N : Node_Id) return Traverse_Result;
12861 -- Process function for traversal to look for Loop_Entry
12863 -------------
12864 -- Process --
12865 -------------
12867 function Process (N : Node_Id) return Traverse_Result is
12868 begin
12869 if Nkind (N) = N_Attribute_Reference
12870 and then Attribute_Name (N) = Name_Loop_Entry
12871 then
12872 Has_Loop_Entry := True;
12873 return Abandon;
12874 else
12875 return OK;
12876 end if;
12877 end Process;
12879 procedure Traverse is new Traverse_Proc (Process);
12881 -- Start of processing for Contains_Loop_Entry
12883 begin
12884 Traverse (Expr);
12885 return Has_Loop_Entry;
12886 end Contains_Loop_Entry;
12888 -- Local variables
12890 Expr : Node_Id;
12891 New_Args : List_Id;
12893 -- Start of processing for Assert
12895 begin
12896 -- Assert is an Ada 2005 RM-defined pragma
12898 if Prag_Id = Pragma_Assert then
12899 Ada_2005_Pragma;
12901 -- The remaining ones are GNAT pragmas
12903 else
12904 GNAT_Pragma;
12905 end if;
12907 Check_At_Least_N_Arguments (1);
12908 Check_At_Most_N_Arguments (2);
12909 Check_Arg_Order ((Name_Check, Name_Message));
12910 Check_Optional_Identifier (Arg1, Name_Check);
12911 Expr := Get_Pragma_Arg (Arg1);
12913 -- Special processing for Loop_Invariant, Loop_Variant or for
12914 -- other cases where a Loop_Entry attribute is present. If the
12915 -- assertion pragma contains attribute Loop_Entry, ensure that
12916 -- the related pragma is within a loop.
12918 if Prag_Id = Pragma_Loop_Invariant
12919 or else Prag_Id = Pragma_Loop_Variant
12920 or else Contains_Loop_Entry (Expr)
12921 then
12922 Check_Loop_Pragma_Placement;
12924 -- Perform preanalysis to deal with embedded Loop_Entry
12925 -- attributes.
12927 Preanalyze_Assert_Expression (Expr, Any_Boolean);
12928 end if;
12930 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
12931 -- a corresponding Check pragma:
12933 -- pragma Check (name, condition [, msg]);
12935 -- Where name is the identifier matching the pragma name. So
12936 -- rewrite pragma in this manner, transfer the message argument
12937 -- if present, and analyze the result
12939 -- Note: When dealing with a semantically analyzed tree, the
12940 -- information that a Check node N corresponds to a source Assert,
12941 -- Assume, or Assert_And_Cut pragma can be retrieved from the
12942 -- pragma kind of Original_Node(N).
12944 New_Args := New_List (
12945 Make_Pragma_Argument_Association (Loc,
12946 Expression => Make_Identifier (Loc, Pname)),
12947 Make_Pragma_Argument_Association (Sloc (Expr),
12948 Expression => Expr));
12950 if Arg_Count > 1 then
12951 Check_Optional_Identifier (Arg2, Name_Message);
12953 -- Provide semantic annotations for optional argument, for
12954 -- ASIS use, before rewriting.
12955 -- Is this still needed???
12957 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
12958 Append_To (New_Args, New_Copy_Tree (Arg2));
12959 end if;
12961 -- Rewrite as Check pragma
12963 Rewrite (N,
12964 Make_Pragma (Loc,
12965 Chars => Name_Check,
12966 Pragma_Argument_Associations => New_Args));
12968 Analyze (N);
12969 end Assert;
12971 ----------------------
12972 -- Assertion_Policy --
12973 ----------------------
12975 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
12977 -- The following form is Ada 2012 only, but we allow it in all modes
12979 -- Pragma Assertion_Policy (
12980 -- ASSERTION_KIND => POLICY_IDENTIFIER
12981 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
12983 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
12985 -- RM_ASSERTION_KIND ::= Assert |
12986 -- Static_Predicate |
12987 -- Dynamic_Predicate |
12988 -- Pre |
12989 -- Pre'Class |
12990 -- Post |
12991 -- Post'Class |
12992 -- Type_Invariant |
12993 -- Type_Invariant'Class
12995 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
12996 -- Assume |
12997 -- Contract_Cases |
12998 -- Debug |
12999 -- Default_Initial_Condition |
13000 -- Ghost |
13001 -- Initial_Condition |
13002 -- Loop_Invariant |
13003 -- Loop_Variant |
13004 -- Postcondition |
13005 -- Precondition |
13006 -- Predicate |
13007 -- Refined_Post |
13008 -- Statement_Assertions
13010 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
13011 -- ID_ASSERTION_KIND list contains implementation-defined additions
13012 -- recognized by GNAT. The effect is to control the behavior of
13013 -- identically named aspects and pragmas, depending on the specified
13014 -- policy identifier:
13016 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
13018 -- Note: Check and Ignore are language-defined. Disable is a GNAT
13019 -- implementation-defined addition that results in totally ignoring
13020 -- the corresponding assertion. If Disable is specified, then the
13021 -- argument of the assertion is not even analyzed. This is useful
13022 -- when the aspect/pragma argument references entities in a with'ed
13023 -- package that is replaced by a dummy package in the final build.
13025 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
13026 -- and Type_Invariant'Class were recognized by the parser and
13027 -- transformed into references to the special internal identifiers
13028 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
13029 -- processing is required here.
13031 when Pragma_Assertion_Policy => Assertion_Policy : declare
13032 procedure Resolve_Suppressible (Policy : Node_Id);
13033 -- Converts the assertion policy 'Suppressible' to either Check or
13034 -- Ignore based on whether checks are suppressed via -gnatp.
13036 --------------------------
13037 -- Resolve_Suppressible --
13038 --------------------------
13040 procedure Resolve_Suppressible (Policy : Node_Id) is
13041 Arg : constant Node_Id := Get_Pragma_Arg (Policy);
13042 Nam : Name_Id;
13044 begin
13045 -- Transform policy argument Suppressible into either Ignore or
13046 -- Check depending on whether checks are enabled or suppressed.
13048 if Chars (Arg) = Name_Suppressible then
13049 if Suppress_Checks then
13050 Nam := Name_Ignore;
13051 else
13052 Nam := Name_Check;
13053 end if;
13055 Rewrite (Arg, Make_Identifier (Sloc (Arg), Nam));
13056 end if;
13057 end Resolve_Suppressible;
13059 -- Local variables
13061 Arg : Node_Id;
13062 Kind : Name_Id;
13063 LocP : Source_Ptr;
13064 Policy : Node_Id;
13066 begin
13067 Ada_2005_Pragma;
13069 -- This can always appear as a configuration pragma
13071 if Is_Configuration_Pragma then
13072 null;
13074 -- It can also appear in a declarative part or package spec in Ada
13075 -- 2012 mode. We allow this in other modes, but in that case we
13076 -- consider that we have an Ada 2012 pragma on our hands.
13078 else
13079 Check_Is_In_Decl_Part_Or_Package_Spec;
13080 Ada_2012_Pragma;
13081 end if;
13083 -- One argument case with no identifier (first form above)
13085 if Arg_Count = 1
13086 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
13087 or else Chars (Arg1) = No_Name)
13088 then
13089 Check_Arg_Is_One_Of (Arg1,
13090 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
13092 Resolve_Suppressible (Arg1);
13094 -- Treat one argument Assertion_Policy as equivalent to:
13096 -- pragma Check_Policy (Assertion, policy)
13098 -- So rewrite pragma in that manner and link on to the chain
13099 -- of Check_Policy pragmas, marking the pragma as analyzed.
13101 Policy := Get_Pragma_Arg (Arg1);
13103 Rewrite (N,
13104 Make_Pragma (Loc,
13105 Chars => Name_Check_Policy,
13106 Pragma_Argument_Associations => New_List (
13107 Make_Pragma_Argument_Association (Loc,
13108 Expression => Make_Identifier (Loc, Name_Assertion)),
13110 Make_Pragma_Argument_Association (Loc,
13111 Expression =>
13112 Make_Identifier (Sloc (Policy), Chars (Policy))))));
13113 Analyze (N);
13115 -- Here if we have two or more arguments
13117 else
13118 Check_At_Least_N_Arguments (1);
13119 Ada_2012_Pragma;
13121 -- Loop through arguments
13123 Arg := Arg1;
13124 while Present (Arg) loop
13125 LocP := Sloc (Arg);
13127 -- Kind must be specified
13129 if Nkind (Arg) /= N_Pragma_Argument_Association
13130 or else Chars (Arg) = No_Name
13131 then
13132 Error_Pragma_Arg
13133 ("missing assertion kind for pragma%", Arg);
13134 end if;
13136 -- Check Kind and Policy have allowed forms
13138 Kind := Chars (Arg);
13139 Policy := Get_Pragma_Arg (Arg);
13141 if not Is_Valid_Assertion_Kind (Kind) then
13142 Error_Pragma_Arg
13143 ("invalid assertion kind for pragma%", Arg);
13144 end if;
13146 Check_Arg_Is_One_Of (Arg,
13147 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
13149 Resolve_Suppressible (Arg);
13151 if Kind = Name_Ghost then
13153 -- The Ghost policy must be either Check or Ignore
13154 -- (SPARK RM 6.9(6)).
13156 if Chars (Policy) not in Name_Check | Name_Ignore then
13157 Error_Pragma_Arg
13158 ("argument of pragma % Ghost must be Check or "
13159 & "Ignore", Policy);
13160 end if;
13162 -- Pragma Assertion_Policy specifying a Ghost policy
13163 -- cannot occur within a Ghost subprogram or package
13164 -- (SPARK RM 6.9(14)).
13166 if Ghost_Mode > None then
13167 Error_Pragma
13168 ("pragma % cannot appear within ghost subprogram or "
13169 & "package");
13170 end if;
13171 end if;
13173 -- Rewrite the Assertion_Policy pragma as a series of
13174 -- Check_Policy pragmas of the form:
13176 -- Check_Policy (Kind, Policy);
13178 -- Note: the insertion of the pragmas cannot be done with
13179 -- Insert_Action because in the configuration case, there
13180 -- are no scopes on the scope stack and the mechanism will
13181 -- fail.
13183 Insert_Before_And_Analyze (N,
13184 Make_Pragma (LocP,
13185 Chars => Name_Check_Policy,
13186 Pragma_Argument_Associations => New_List (
13187 Make_Pragma_Argument_Association (LocP,
13188 Expression => Make_Identifier (LocP, Kind)),
13189 Make_Pragma_Argument_Association (LocP,
13190 Expression => Policy))));
13192 Arg := Next (Arg);
13193 end loop;
13195 -- Rewrite the Assertion_Policy pragma as null since we have
13196 -- now inserted all the equivalent Check pragmas.
13198 Rewrite (N, Make_Null_Statement (Loc));
13199 Analyze (N);
13200 end if;
13201 end Assertion_Policy;
13203 ------------------------------
13204 -- Assume_No_Invalid_Values --
13205 ------------------------------
13207 -- pragma Assume_No_Invalid_Values (On | Off);
13209 when Pragma_Assume_No_Invalid_Values =>
13210 GNAT_Pragma;
13211 Check_Valid_Configuration_Pragma;
13212 Check_Arg_Count (1);
13213 Check_No_Identifiers;
13214 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13216 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
13217 Assume_No_Invalid_Values := True;
13218 else
13219 Assume_No_Invalid_Values := False;
13220 end if;
13222 --------------------------
13223 -- Attribute_Definition --
13224 --------------------------
13226 -- pragma Attribute_Definition
13227 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
13228 -- [Entity =>] LOCAL_NAME,
13229 -- [Expression =>] EXPRESSION | NAME);
13231 when Pragma_Attribute_Definition => Attribute_Definition : declare
13232 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
13233 Aname : Name_Id;
13235 begin
13236 GNAT_Pragma;
13237 Check_Arg_Count (3);
13238 Check_Optional_Identifier (Arg1, "attribute");
13239 Check_Optional_Identifier (Arg2, "entity");
13240 Check_Optional_Identifier (Arg3, "expression");
13242 if Nkind (Attribute_Designator) /= N_Identifier then
13243 Error_Msg_N ("attribute name expected", Attribute_Designator);
13244 return;
13245 end if;
13247 Check_Arg_Is_Local_Name (Arg2);
13249 -- If the attribute is not recognized, then issue a warning (not
13250 -- an error), and ignore the pragma.
13252 Aname := Chars (Attribute_Designator);
13254 if not Is_Attribute_Name (Aname) then
13255 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
13256 return;
13257 end if;
13259 -- Otherwise, rewrite the pragma as an attribute definition clause
13261 Rewrite (N,
13262 Make_Attribute_Definition_Clause (Loc,
13263 Name => Get_Pragma_Arg (Arg2),
13264 Chars => Aname,
13265 Expression => Get_Pragma_Arg (Arg3)));
13266 Analyze (N);
13267 end Attribute_Definition;
13269 ------------------------------------------------------------------
13270 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
13271 -- No_Caching --
13272 ------------------------------------------------------------------
13274 -- pragma Async_Readers [ (boolean_EXPRESSION) ];
13275 -- pragma Async_Writers [ (boolean_EXPRESSION) ];
13276 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
13277 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
13278 -- pragma No_Caching [ (boolean_EXPRESSION) ];
13280 when Pragma_Async_Readers
13281 | Pragma_Async_Writers
13282 | Pragma_Effective_Reads
13283 | Pragma_Effective_Writes
13284 | Pragma_No_Caching
13286 Async_Effective : declare
13287 Obj_Or_Type_Decl : Node_Id;
13288 Obj_Or_Type_Id : Entity_Id;
13289 begin
13290 GNAT_Pragma;
13291 Check_No_Identifiers;
13292 Check_At_Most_N_Arguments (1);
13294 Obj_Or_Type_Decl := Find_Related_Context (N, Do_Checks => True);
13296 -- Pragma must apply to a object declaration or to a type
13297 -- declaration (only the former in the No_Caching case).
13298 -- Original_Node is necessary to account for untagged derived
13299 -- types that are rewritten as subtypes of their
13300 -- respective root types.
13302 if Nkind (Obj_Or_Type_Decl) /= N_Object_Declaration then
13303 if Prag_Id = Pragma_No_Caching
13304 or else Nkind (Original_Node (Obj_Or_Type_Decl)) not in
13305 N_Full_Type_Declaration |
13306 N_Private_Type_Declaration |
13307 N_Formal_Type_Declaration |
13308 N_Task_Type_Declaration |
13309 N_Protected_Type_Declaration
13310 then
13311 Pragma_Misplaced;
13312 return;
13313 end if;
13314 end if;
13316 Obj_Or_Type_Id := Defining_Entity (Obj_Or_Type_Decl);
13318 -- Perform minimal verification to ensure that the argument is at
13319 -- least a variable or a type. Subsequent finer grained checks
13320 -- will be done at the end of the declarative region that
13321 -- contains the pragma.
13323 if Ekind (Obj_Or_Type_Id) = E_Variable
13324 or else Is_Type (Obj_Or_Type_Id)
13325 then
13327 -- In the case of a type, pragma is a type-related
13328 -- representation item and so requires checks common to
13329 -- all type-related representation items.
13331 if Is_Type (Obj_Or_Type_Id)
13332 and then Rep_Item_Too_Late (Obj_Or_Type_Id, N)
13333 then
13334 return;
13335 end if;
13337 -- A pragma that applies to a Ghost entity becomes Ghost for
13338 -- the purposes of legality checks and removal of ignored Ghost
13339 -- code.
13341 Mark_Ghost_Pragma (N, Obj_Or_Type_Id);
13343 -- Chain the pragma on the contract for further processing by
13344 -- Analyze_External_Property_In_Decl_Part.
13346 Add_Contract_Item (N, Obj_Or_Type_Id);
13348 -- Analyze the Boolean expression (if any)
13350 if Present (Arg1) then
13351 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
13352 end if;
13354 -- Otherwise the external property applies to a constant
13356 else
13357 Error_Pragma
13358 ("pragma % must apply to a volatile type or object");
13359 end if;
13360 end Async_Effective;
13362 ------------------
13363 -- Asynchronous --
13364 ------------------
13366 -- pragma Asynchronous (LOCAL_NAME);
13368 when Pragma_Asynchronous => Asynchronous : declare
13369 C_Ent : Entity_Id;
13370 Decl : Node_Id;
13371 Formal : Entity_Id;
13372 L : List_Id;
13373 Nm : Entity_Id;
13374 S : Node_Id;
13376 procedure Process_Async_Pragma;
13377 -- Common processing for procedure and access-to-procedure case
13379 --------------------------
13380 -- Process_Async_Pragma --
13381 --------------------------
13383 procedure Process_Async_Pragma is
13384 begin
13385 if No (L) then
13386 Set_Is_Asynchronous (Nm);
13387 return;
13388 end if;
13390 -- The formals should be of mode IN (RM E.4.1(6))
13392 S := First (L);
13393 while Present (S) loop
13394 Formal := Defining_Identifier (S);
13396 if Nkind (Formal) = N_Defining_Identifier
13397 and then Ekind (Formal) /= E_In_Parameter
13398 then
13399 Error_Pragma_Arg
13400 ("pragma% procedure can only have IN parameter",
13401 Arg1);
13402 end if;
13404 Next (S);
13405 end loop;
13407 Set_Is_Asynchronous (Nm);
13408 end Process_Async_Pragma;
13410 -- Start of processing for pragma Asynchronous
13412 begin
13413 Check_Ada_83_Warning;
13414 Check_No_Identifiers;
13415 Check_Arg_Count (1);
13416 Check_Arg_Is_Local_Name (Arg1);
13418 if Debug_Flag_U then
13419 return;
13420 end if;
13422 C_Ent := Cunit_Entity (Current_Sem_Unit);
13423 Analyze (Get_Pragma_Arg (Arg1));
13424 Nm := Entity (Get_Pragma_Arg (Arg1));
13426 -- A pragma that applies to a Ghost entity becomes Ghost for the
13427 -- purposes of legality checks and removal of ignored Ghost code.
13429 Mark_Ghost_Pragma (N, Nm);
13431 if not Is_Remote_Call_Interface (C_Ent)
13432 and then not Is_Remote_Types (C_Ent)
13433 then
13434 -- This pragma should only appear in an RCI or Remote Types
13435 -- unit (RM E.4.1(4)).
13437 Error_Pragma
13438 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
13439 end if;
13441 if Ekind (Nm) = E_Procedure
13442 and then Nkind (Parent (Nm)) = N_Procedure_Specification
13443 then
13444 if not Is_Remote_Call_Interface (Nm) then
13445 Error_Pragma_Arg
13446 ("pragma% cannot be applied on non-remote procedure",
13447 Arg1);
13448 end if;
13450 L := Parameter_Specifications (Parent (Nm));
13451 Process_Async_Pragma;
13452 return;
13454 elsif Ekind (Nm) = E_Function then
13455 Error_Pragma_Arg
13456 ("pragma% cannot be applied to function", Arg1);
13458 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
13459 if Is_Record_Type (Nm) then
13461 -- A record type that is the Equivalent_Type for a remote
13462 -- access-to-subprogram type.
13464 Decl := Declaration_Node (Corresponding_Remote_Type (Nm));
13466 else
13467 -- A non-expanded RAS type (distribution is not enabled)
13469 Decl := Declaration_Node (Nm);
13470 end if;
13472 if Nkind (Decl) = N_Full_Type_Declaration
13473 and then Nkind (Type_Definition (Decl)) =
13474 N_Access_Procedure_Definition
13475 then
13476 L := Parameter_Specifications (Type_Definition (Decl));
13477 Process_Async_Pragma;
13479 if Is_Asynchronous (Nm)
13480 and then Expander_Active
13481 and then Get_PCS_Name /= Name_No_DSA
13482 then
13483 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
13484 end if;
13486 else
13487 Error_Pragma_Arg
13488 ("pragma% cannot reference access-to-function type",
13489 Arg1);
13490 end if;
13492 -- Only other possibility is Access-to-class-wide type
13494 elsif Is_Access_Type (Nm)
13495 and then Is_Class_Wide_Type (Designated_Type (Nm))
13496 then
13497 Check_First_Subtype (Arg1);
13498 Set_Is_Asynchronous (Nm);
13499 if Expander_Active then
13500 RACW_Type_Is_Asynchronous (Nm);
13501 end if;
13503 else
13504 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
13505 end if;
13506 end Asynchronous;
13508 ------------
13509 -- Atomic --
13510 ------------
13512 -- pragma Atomic (LOCAL_NAME);
13514 when Pragma_Atomic =>
13515 Process_Atomic_Independent_Shared_Volatile;
13517 -----------------------
13518 -- Atomic_Components --
13519 -----------------------
13521 -- pragma Atomic_Components (array_LOCAL_NAME);
13523 -- This processing is shared by Volatile_Components
13525 when Pragma_Atomic_Components
13526 | Pragma_Volatile_Components
13528 Atomic_Components : declare
13529 D : Node_Id;
13530 E : Entity_Id;
13531 E_Id : Node_Id;
13533 begin
13534 Check_Ada_83_Warning;
13535 Check_No_Identifiers;
13536 Check_Arg_Count (1);
13537 Check_Arg_Is_Local_Name (Arg1);
13538 E_Id := Get_Pragma_Arg (Arg1);
13540 if Etype (E_Id) = Any_Type then
13541 return;
13542 end if;
13544 E := Entity (E_Id);
13546 -- A pragma that applies to a Ghost entity becomes Ghost for the
13547 -- purposes of legality checks and removal of ignored Ghost code.
13549 Mark_Ghost_Pragma (N, E);
13550 Check_Duplicate_Pragma (E);
13552 if Rep_Item_Too_Early (E, N)
13553 or else
13554 Rep_Item_Too_Late (E, N)
13555 then
13556 return;
13557 end if;
13559 D := Declaration_Node (E);
13561 if (Nkind (D) = N_Full_Type_Declaration and then Is_Array_Type (E))
13562 or else
13563 (Nkind (D) = N_Object_Declaration
13564 and then Ekind (E) in E_Constant | E_Variable
13565 and then Nkind (Object_Definition (D)) =
13566 N_Constrained_Array_Definition)
13567 or else
13568 (Ada_Version >= Ada_2020
13569 and then Nkind (D) = N_Formal_Type_Declaration)
13570 then
13571 -- The flag is set on the base type, or on the object
13573 if Nkind (D) = N_Full_Type_Declaration then
13574 E := Base_Type (E);
13575 end if;
13577 -- Atomic implies both Independent and Volatile
13579 if Prag_Id = Pragma_Atomic_Components then
13580 if Ada_Version >= Ada_2020 then
13581 Check_Atomic_VFA
13582 (Component_Type (Etype (E)), VFA => False);
13583 end if;
13585 Set_Has_Atomic_Components (E);
13586 Set_Has_Independent_Components (E);
13587 end if;
13589 Set_Has_Volatile_Components (E);
13591 else
13592 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
13593 end if;
13594 end Atomic_Components;
13596 --------------------
13597 -- Attach_Handler --
13598 --------------------
13600 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
13602 when Pragma_Attach_Handler =>
13603 Check_Ada_83_Warning;
13604 Check_No_Identifiers;
13605 Check_Arg_Count (2);
13607 if No_Run_Time_Mode then
13608 Error_Msg_CRT ("Attach_Handler pragma", N);
13609 else
13610 Check_Interrupt_Or_Attach_Handler;
13612 -- The expression that designates the attribute may depend on a
13613 -- discriminant, and is therefore a per-object expression, to
13614 -- be expanded in the init proc. If expansion is enabled, then
13615 -- perform semantic checks on a copy only.
13617 declare
13618 Temp : Node_Id;
13619 Typ : Node_Id;
13620 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
13622 begin
13623 -- In Relaxed_RM_Semantics mode, we allow any static
13624 -- integer value, for compatibility with other compilers.
13626 if Relaxed_RM_Semantics
13627 and then Nkind (Parg2) = N_Integer_Literal
13628 then
13629 Typ := Standard_Integer;
13630 else
13631 Typ := RTE (RE_Interrupt_ID);
13632 end if;
13634 if Expander_Active then
13635 Temp := New_Copy_Tree (Parg2);
13636 Set_Parent (Temp, N);
13637 Preanalyze_And_Resolve (Temp, Typ);
13638 else
13639 Analyze (Parg2);
13640 Resolve (Parg2, Typ);
13641 end if;
13642 end;
13644 Process_Interrupt_Or_Attach_Handler;
13645 end if;
13647 --------------------
13648 -- C_Pass_By_Copy --
13649 --------------------
13651 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
13653 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
13654 Arg : Node_Id;
13655 Val : Uint;
13657 begin
13658 GNAT_Pragma;
13659 Check_Valid_Configuration_Pragma;
13660 Check_Arg_Count (1);
13661 Check_Optional_Identifier (Arg1, "max_size");
13663 Arg := Get_Pragma_Arg (Arg1);
13664 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
13666 Val := Expr_Value (Arg);
13668 if Val <= 0 then
13669 Error_Pragma_Arg
13670 ("maximum size for pragma% must be positive", Arg1);
13672 elsif UI_Is_In_Int_Range (Val) then
13673 Default_C_Record_Mechanism := UI_To_Int (Val);
13675 -- If a giant value is given, Int'Last will do well enough.
13676 -- If sometime someone complains that a record larger than
13677 -- two gigabytes is not copied, we will worry about it then.
13679 else
13680 Default_C_Record_Mechanism := Mechanism_Type'Last;
13681 end if;
13682 end C_Pass_By_Copy;
13684 -----------
13685 -- Check --
13686 -----------
13688 -- pragma Check ([Name =>] CHECK_KIND,
13689 -- [Check =>] Boolean_EXPRESSION
13690 -- [,[Message =>] String_EXPRESSION]);
13692 -- CHECK_KIND ::= IDENTIFIER |
13693 -- Pre'Class |
13694 -- Post'Class |
13695 -- Invariant'Class |
13696 -- Type_Invariant'Class
13698 -- The identifiers Assertions and Statement_Assertions are not
13699 -- allowed, since they have special meaning for Check_Policy.
13701 -- WARNING: The code below manages Ghost regions. Return statements
13702 -- must be replaced by gotos which jump to the end of the code and
13703 -- restore the Ghost mode.
13705 when Pragma_Check => Check : declare
13706 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
13707 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
13708 -- Save the Ghost-related attributes to restore on exit
13710 Cname : Name_Id;
13711 Eloc : Source_Ptr;
13712 Expr : Node_Id;
13713 Str : Node_Id;
13714 pragma Warnings (Off, Str);
13716 begin
13717 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
13718 -- the mode now to ensure that any nodes generated during analysis
13719 -- and expansion are marked as Ghost.
13721 Set_Ghost_Mode (N);
13723 GNAT_Pragma;
13724 Check_At_Least_N_Arguments (2);
13725 Check_At_Most_N_Arguments (3);
13726 Check_Optional_Identifier (Arg1, Name_Name);
13727 Check_Optional_Identifier (Arg2, Name_Check);
13729 if Arg_Count = 3 then
13730 Check_Optional_Identifier (Arg3, Name_Message);
13731 Str := Get_Pragma_Arg (Arg3);
13732 end if;
13734 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
13735 Check_Arg_Is_Identifier (Arg1);
13736 Cname := Chars (Get_Pragma_Arg (Arg1));
13738 -- Check forbidden name Assertions or Statement_Assertions
13740 case Cname is
13741 when Name_Assertions =>
13742 Error_Pragma_Arg
13743 ("""Assertions"" is not allowed as a check kind for "
13744 & "pragma%", Arg1);
13746 when Name_Statement_Assertions =>
13747 Error_Pragma_Arg
13748 ("""Statement_Assertions"" is not allowed as a check kind "
13749 & "for pragma%", Arg1);
13751 when others =>
13752 null;
13753 end case;
13755 -- Check applicable policy. We skip this if Checked/Ignored status
13756 -- is already set (e.g. in the case of a pragma from an aspect).
13758 if Is_Checked (N) or else Is_Ignored (N) then
13759 null;
13761 -- For a non-source pragma that is a rewriting of another pragma,
13762 -- copy the Is_Checked/Ignored status from the rewritten pragma.
13764 elsif Is_Rewrite_Substitution (N)
13765 and then Nkind (Original_Node (N)) = N_Pragma
13766 then
13767 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
13768 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
13770 -- Otherwise query the applicable policy at this point
13772 else
13773 case Check_Kind (Cname) is
13774 when Name_Ignore =>
13775 Set_Is_Ignored (N, True);
13776 Set_Is_Checked (N, False);
13778 when Name_Check =>
13779 Set_Is_Ignored (N, False);
13780 Set_Is_Checked (N, True);
13782 -- For disable, rewrite pragma as null statement and skip
13783 -- rest of the analysis of the pragma.
13785 when Name_Disable =>
13786 Rewrite (N, Make_Null_Statement (Loc));
13787 Analyze (N);
13788 raise Pragma_Exit;
13790 -- No other possibilities
13792 when others =>
13793 raise Program_Error;
13794 end case;
13795 end if;
13797 -- If check kind was not Disable, then continue pragma analysis
13799 Expr := Get_Pragma_Arg (Arg2);
13801 -- Mark the pragma (or, if rewritten from an aspect, the original
13802 -- aspect) as enabled. Nothing to do for an internally generated
13803 -- check for a dynamic predicate.
13805 if Is_Checked (N)
13806 and then not Split_PPC (N)
13807 and then Cname /= Name_Dynamic_Predicate
13808 then
13809 Set_SCO_Pragma_Enabled (Loc);
13810 end if;
13812 -- Deal with analyzing the string argument. If checks are not
13813 -- on we don't want any expansion (since such expansion would
13814 -- not get properly deleted) but we do want to analyze (to get
13815 -- proper references). The Preanalyze_And_Resolve routine does
13816 -- just what we want. Ditto if pragma is active, because it will
13817 -- be rewritten as an if-statement whose analysis will complete
13818 -- analysis and expansion of the string message. This makes a
13819 -- difference in the unusual case where the expression for the
13820 -- string may have a side effect, such as raising an exception.
13821 -- This is mandated by RM 11.4.2, which specifies that the string
13822 -- expression is only evaluated if the check fails and
13823 -- Assertion_Error is to be raised.
13825 if Arg_Count = 3 then
13826 Preanalyze_And_Resolve (Str, Standard_String);
13827 end if;
13829 -- Now you might think we could just do the same with the Boolean
13830 -- expression if checks are off (and expansion is on) and then
13831 -- rewrite the check as a null statement. This would work but we
13832 -- would lose the useful warnings about an assertion being bound
13833 -- to fail even if assertions are turned off.
13835 -- So instead we wrap the boolean expression in an if statement
13836 -- that looks like:
13838 -- if False and then condition then
13839 -- null;
13840 -- end if;
13842 -- The reason we do this rewriting during semantic analysis rather
13843 -- than as part of normal expansion is that we cannot analyze and
13844 -- expand the code for the boolean expression directly, or it may
13845 -- cause insertion of actions that would escape the attempt to
13846 -- suppress the check code.
13848 -- Note that the Sloc for the if statement corresponds to the
13849 -- argument condition, not the pragma itself. The reason for
13850 -- this is that we may generate a warning if the condition is
13851 -- False at compile time, and we do not want to delete this
13852 -- warning when we delete the if statement.
13854 if Expander_Active and Is_Ignored (N) then
13855 Eloc := Sloc (Expr);
13857 Rewrite (N,
13858 Make_If_Statement (Eloc,
13859 Condition =>
13860 Make_And_Then (Eloc,
13861 Left_Opnd => Make_Identifier (Eloc, Name_False),
13862 Right_Opnd => Expr),
13863 Then_Statements => New_List (
13864 Make_Null_Statement (Eloc))));
13866 -- Now go ahead and analyze the if statement
13868 In_Assertion_Expr := In_Assertion_Expr + 1;
13870 -- One rather special treatment. If we are now in Eliminated
13871 -- overflow mode, then suppress overflow checking since we do
13872 -- not want to drag in the bignum stuff if we are in Ignore
13873 -- mode anyway. This is particularly important if we are using
13874 -- a configurable run time that does not support bignum ops.
13876 if Scope_Suppress.Overflow_Mode_Assertions = Eliminated then
13877 declare
13878 Svo : constant Boolean :=
13879 Scope_Suppress.Suppress (Overflow_Check);
13880 begin
13881 Scope_Suppress.Overflow_Mode_Assertions := Strict;
13882 Scope_Suppress.Suppress (Overflow_Check) := True;
13883 Analyze (N);
13884 Scope_Suppress.Suppress (Overflow_Check) := Svo;
13885 Scope_Suppress.Overflow_Mode_Assertions := Eliminated;
13886 end;
13888 -- Not that special case
13890 else
13891 Analyze (N);
13892 end if;
13894 -- All done with this check
13896 In_Assertion_Expr := In_Assertion_Expr - 1;
13898 -- Check is active or expansion not active. In these cases we can
13899 -- just go ahead and analyze the boolean with no worries.
13901 else
13902 In_Assertion_Expr := In_Assertion_Expr + 1;
13903 Analyze_And_Resolve (Expr, Any_Boolean);
13904 In_Assertion_Expr := In_Assertion_Expr - 1;
13905 end if;
13907 Restore_Ghost_Region (Saved_GM, Saved_IGR);
13908 end Check;
13910 --------------------------
13911 -- Check_Float_Overflow --
13912 --------------------------
13914 -- pragma Check_Float_Overflow;
13916 when Pragma_Check_Float_Overflow =>
13917 GNAT_Pragma;
13918 Check_Valid_Configuration_Pragma;
13919 Check_Arg_Count (0);
13920 Check_Float_Overflow := not Machine_Overflows_On_Target;
13922 ----------------
13923 -- Check_Name --
13924 ----------------
13926 -- pragma Check_Name (check_IDENTIFIER);
13928 when Pragma_Check_Name =>
13929 GNAT_Pragma;
13930 Check_No_Identifiers;
13931 Check_Valid_Configuration_Pragma;
13932 Check_Arg_Count (1);
13933 Check_Arg_Is_Identifier (Arg1);
13935 declare
13936 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
13938 begin
13939 for J in Check_Names.First .. Check_Names.Last loop
13940 if Check_Names.Table (J) = Nam then
13941 return;
13942 end if;
13943 end loop;
13945 Check_Names.Append (Nam);
13946 end;
13948 ------------------
13949 -- Check_Policy --
13950 ------------------
13952 -- This is the old style syntax, which is still allowed in all modes:
13954 -- pragma Check_Policy ([Name =>] CHECK_KIND
13955 -- [Policy =>] POLICY_IDENTIFIER);
13957 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
13959 -- CHECK_KIND ::= IDENTIFIER |
13960 -- Pre'Class |
13961 -- Post'Class |
13962 -- Type_Invariant'Class |
13963 -- Invariant'Class
13965 -- This is the new style syntax, compatible with Assertion_Policy
13966 -- and also allowed in all modes.
13968 -- Pragma Check_Policy (
13969 -- CHECK_KIND => POLICY_IDENTIFIER
13970 -- {, CHECK_KIND => POLICY_IDENTIFIER});
13972 -- Note: the identifiers Name and Policy are not allowed as
13973 -- Check_Kind values. This avoids ambiguities between the old and
13974 -- new form syntax.
13976 when Pragma_Check_Policy => Check_Policy : declare
13977 Kind : Node_Id;
13979 begin
13980 GNAT_Pragma;
13981 Check_At_Least_N_Arguments (1);
13983 -- A Check_Policy pragma can appear either as a configuration
13984 -- pragma, or in a declarative part or a package spec (see RM
13985 -- 11.5(5) for rules for Suppress/Unsuppress which are also
13986 -- followed for Check_Policy).
13988 if not Is_Configuration_Pragma then
13989 Check_Is_In_Decl_Part_Or_Package_Spec;
13990 end if;
13992 -- Figure out if we have the old or new syntax. We have the
13993 -- old syntax if the first argument has no identifier, or the
13994 -- identifier is Name.
13996 if Nkind (Arg1) /= N_Pragma_Argument_Association
13997 or else Chars (Arg1) in No_Name | Name_Name
13998 then
13999 -- Old syntax
14001 Check_Arg_Count (2);
14002 Check_Optional_Identifier (Arg1, Name_Name);
14003 Kind := Get_Pragma_Arg (Arg1);
14004 Rewrite_Assertion_Kind (Kind,
14005 From_Policy => Comes_From_Source (N));
14006 Check_Arg_Is_Identifier (Arg1);
14008 -- Check forbidden check kind
14010 if Chars (Kind) in Name_Name | Name_Policy then
14011 Error_Msg_Name_2 := Chars (Kind);
14012 Error_Pragma_Arg
14013 ("pragma% does not allow% as check name", Arg1);
14014 end if;
14016 -- Check policy
14018 Check_Optional_Identifier (Arg2, Name_Policy);
14019 Check_Arg_Is_One_Of
14020 (Arg2,
14021 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
14023 -- And chain pragma on the Check_Policy_List for search
14025 Set_Next_Pragma (N, Opt.Check_Policy_List);
14026 Opt.Check_Policy_List := N;
14028 -- For the new syntax, what we do is to convert each argument to
14029 -- an old syntax equivalent. We do that because we want to chain
14030 -- old style Check_Policy pragmas for the search (we don't want
14031 -- to have to deal with multiple arguments in the search).
14033 else
14034 declare
14035 Arg : Node_Id;
14036 Argx : Node_Id;
14037 LocP : Source_Ptr;
14038 New_P : Node_Id;
14040 begin
14041 Arg := Arg1;
14042 while Present (Arg) loop
14043 LocP := Sloc (Arg);
14044 Argx := Get_Pragma_Arg (Arg);
14046 -- Kind must be specified
14048 if Nkind (Arg) /= N_Pragma_Argument_Association
14049 or else Chars (Arg) = No_Name
14050 then
14051 Error_Pragma_Arg
14052 ("missing assertion kind for pragma%", Arg);
14053 end if;
14055 -- Construct equivalent old form syntax Check_Policy
14056 -- pragma and insert it to get remaining checks.
14058 New_P :=
14059 Make_Pragma (LocP,
14060 Chars => Name_Check_Policy,
14061 Pragma_Argument_Associations => New_List (
14062 Make_Pragma_Argument_Association (LocP,
14063 Expression =>
14064 Make_Identifier (LocP, Chars (Arg))),
14065 Make_Pragma_Argument_Association (Sloc (Argx),
14066 Expression => Argx)));
14068 Arg := Next (Arg);
14070 -- For a configuration pragma, insert old form in
14071 -- the corresponding file.
14073 if Is_Configuration_Pragma then
14074 Insert_After (N, New_P);
14075 Analyze (New_P);
14077 else
14078 Insert_Action (N, New_P);
14079 end if;
14080 end loop;
14082 -- Rewrite original Check_Policy pragma to null, since we
14083 -- have converted it into a series of old syntax pragmas.
14085 Rewrite (N, Make_Null_Statement (Loc));
14086 Analyze (N);
14087 end;
14088 end if;
14089 end Check_Policy;
14091 -------------
14092 -- Comment --
14093 -------------
14095 -- pragma Comment (static_string_EXPRESSION)
14097 -- Processing for pragma Comment shares the circuitry for pragma
14098 -- Ident. The only differences are that Ident enforces a limit of 31
14099 -- characters on its argument, and also enforces limitations on
14100 -- placement for DEC compatibility. Pragma Comment shares neither of
14101 -- these restrictions.
14103 -------------------
14104 -- Common_Object --
14105 -------------------
14107 -- pragma Common_Object (
14108 -- [Internal =>] LOCAL_NAME
14109 -- [, [External =>] EXTERNAL_SYMBOL]
14110 -- [, [Size =>] EXTERNAL_SYMBOL]);
14112 -- Processing for this pragma is shared with Psect_Object
14114 ----------------------------------------------
14115 -- Compile_Time_Error, Compile_Time_Warning --
14116 ----------------------------------------------
14118 -- pragma Compile_Time_Error
14119 -- (boolean_EXPRESSION, static_string_EXPRESSION);
14121 -- pragma Compile_Time_Warning
14122 -- (boolean_EXPRESSION, static_string_EXPRESSION);
14124 when Pragma_Compile_Time_Error | Pragma_Compile_Time_Warning =>
14125 GNAT_Pragma;
14126 Process_Compile_Time_Warning_Or_Error;
14128 ---------------------------
14129 -- Compiler_Unit_Warning --
14130 ---------------------------
14132 -- pragma Compiler_Unit_Warning;
14134 -- Historical note
14136 -- Originally, we had only pragma Compiler_Unit, and it resulted in
14137 -- errors not warnings. This means that we had introduced a big extra
14138 -- inertia to compiler changes, since even if we implemented a new
14139 -- feature, and even if all versions to be used for bootstrapping
14140 -- implemented this new feature, we could not use it, since old
14141 -- compilers would give errors for using this feature in units
14142 -- having Compiler_Unit pragmas.
14144 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
14145 -- problem. We no longer have any units mentioning Compiler_Unit,
14146 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
14147 -- and thus generates a warning which can be ignored. So that deals
14148 -- with the problem of old compilers not implementing the newer form
14149 -- of the pragma.
14151 -- Newer compilers recognize the new pragma, but generate warning
14152 -- messages instead of errors, which again can be ignored in the
14153 -- case of an old compiler which implements a wanted new feature
14154 -- but at the time felt like warning about it for older compilers.
14156 -- We retain Compiler_Unit so that new compilers can be used to build
14157 -- older run-times that use this pragma. That's an unusual case, but
14158 -- it's easy enough to handle, so why not?
14160 when Pragma_Compiler_Unit
14161 | Pragma_Compiler_Unit_Warning
14163 GNAT_Pragma;
14164 Check_Arg_Count (0);
14166 -- Only recognized in main unit
14168 if Current_Sem_Unit = Main_Unit then
14169 Compiler_Unit := True;
14170 end if;
14172 -----------------------------
14173 -- Complete_Representation --
14174 -----------------------------
14176 -- pragma Complete_Representation;
14178 when Pragma_Complete_Representation =>
14179 GNAT_Pragma;
14180 Check_Arg_Count (0);
14182 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
14183 Error_Pragma
14184 ("pragma & must appear within record representation clause");
14185 end if;
14187 ----------------------------
14188 -- Complex_Representation --
14189 ----------------------------
14191 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
14193 when Pragma_Complex_Representation => Complex_Representation : declare
14194 E_Id : Node_Id;
14195 E : Entity_Id;
14196 Ent : Entity_Id;
14198 begin
14199 GNAT_Pragma;
14200 Check_Arg_Count (1);
14201 Check_Optional_Identifier (Arg1, Name_Entity);
14202 Check_Arg_Is_Local_Name (Arg1);
14203 E_Id := Get_Pragma_Arg (Arg1);
14205 if Etype (E_Id) = Any_Type then
14206 return;
14207 end if;
14209 E := Entity (E_Id);
14211 if not Is_Record_Type (E) then
14212 Error_Pragma_Arg
14213 ("argument for pragma% must be record type", Arg1);
14214 end if;
14216 Ent := First_Entity (E);
14218 if No (Ent)
14219 or else No (Next_Entity (Ent))
14220 or else Present (Next_Entity (Next_Entity (Ent)))
14221 or else not Is_Floating_Point_Type (Etype (Ent))
14222 or else Etype (Ent) /= Etype (Next_Entity (Ent))
14223 then
14224 Error_Pragma_Arg
14225 ("record for pragma% must have two fields of the same "
14226 & "floating-point type", Arg1);
14228 else
14229 Set_Has_Complex_Representation (Base_Type (E));
14231 -- We need to treat the type has having a non-standard
14232 -- representation, for back-end purposes, even though in
14233 -- general a complex will have the default representation
14234 -- of a record with two real components.
14236 Set_Has_Non_Standard_Rep (Base_Type (E));
14237 end if;
14238 end Complex_Representation;
14240 -------------------------
14241 -- Component_Alignment --
14242 -------------------------
14244 -- pragma Component_Alignment (
14245 -- [Form =>] ALIGNMENT_CHOICE
14246 -- [, [Name =>] type_LOCAL_NAME]);
14248 -- ALIGNMENT_CHOICE ::=
14249 -- Component_Size
14250 -- | Component_Size_4
14251 -- | Storage_Unit
14252 -- | Default
14254 when Pragma_Component_Alignment => Component_AlignmentP : declare
14255 Args : Args_List (1 .. 2);
14256 Names : constant Name_List (1 .. 2) := (
14257 Name_Form,
14258 Name_Name);
14260 Form : Node_Id renames Args (1);
14261 Name : Node_Id renames Args (2);
14263 Atype : Component_Alignment_Kind;
14264 Typ : Entity_Id;
14266 begin
14267 GNAT_Pragma;
14268 Gather_Associations (Names, Args);
14270 if No (Form) then
14271 Error_Pragma ("missing Form argument for pragma%");
14272 end if;
14274 Check_Arg_Is_Identifier (Form);
14276 -- Get proper alignment, note that Default = Component_Size on all
14277 -- machines we have so far, and we want to set this value rather
14278 -- than the default value to indicate that it has been explicitly
14279 -- set (and thus will not get overridden by the default component
14280 -- alignment for the current scope)
14282 if Chars (Form) = Name_Component_Size then
14283 Atype := Calign_Component_Size;
14285 elsif Chars (Form) = Name_Component_Size_4 then
14286 Atype := Calign_Component_Size_4;
14288 elsif Chars (Form) = Name_Default then
14289 Atype := Calign_Component_Size;
14291 elsif Chars (Form) = Name_Storage_Unit then
14292 Atype := Calign_Storage_Unit;
14294 else
14295 Error_Pragma_Arg
14296 ("invalid Form parameter for pragma%", Form);
14297 end if;
14299 -- The pragma appears in a configuration file
14301 if No (Parent (N)) then
14302 Check_Valid_Configuration_Pragma;
14304 -- Capture the component alignment in a global variable when
14305 -- the pragma appears in a configuration file. Note that the
14306 -- scope stack is empty at this point and cannot be used to
14307 -- store the alignment value.
14309 Configuration_Component_Alignment := Atype;
14311 -- Case with no name, supplied, affects scope table entry
14313 elsif No (Name) then
14314 Scope_Stack.Table
14315 (Scope_Stack.Last).Component_Alignment_Default := Atype;
14317 -- Case of name supplied
14319 else
14320 Check_Arg_Is_Local_Name (Name);
14321 Find_Type (Name);
14322 Typ := Entity (Name);
14324 if Typ = Any_Type
14325 or else Rep_Item_Too_Early (Typ, N)
14326 then
14327 return;
14328 else
14329 Typ := Underlying_Type (Typ);
14330 end if;
14332 if not Is_Record_Type (Typ)
14333 and then not Is_Array_Type (Typ)
14334 then
14335 Error_Pragma_Arg
14336 ("Name parameter of pragma% must identify record or "
14337 & "array type", Name);
14338 end if;
14340 -- An explicit Component_Alignment pragma overrides an
14341 -- implicit pragma Pack, but not an explicit one.
14343 if not Has_Pragma_Pack (Base_Type (Typ)) then
14344 Set_Is_Packed (Base_Type (Typ), False);
14345 Set_Component_Alignment (Base_Type (Typ), Atype);
14346 end if;
14347 end if;
14348 end Component_AlignmentP;
14350 --------------------------------
14351 -- Constant_After_Elaboration --
14352 --------------------------------
14354 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
14356 when Pragma_Constant_After_Elaboration => Constant_After_Elaboration :
14357 declare
14358 Obj_Decl : Node_Id;
14359 Obj_Id : Entity_Id;
14361 begin
14362 GNAT_Pragma;
14363 Check_No_Identifiers;
14364 Check_At_Most_N_Arguments (1);
14366 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
14368 if Nkind (Obj_Decl) /= N_Object_Declaration then
14369 Pragma_Misplaced;
14370 return;
14371 end if;
14373 Obj_Id := Defining_Entity (Obj_Decl);
14375 -- The object declaration must be a library-level variable which
14376 -- is either explicitly initialized or obtains a value during the
14377 -- elaboration of a package body (SPARK RM 3.3.1).
14379 if Ekind (Obj_Id) = E_Variable then
14380 if not Is_Library_Level_Entity (Obj_Id) then
14381 Error_Pragma
14382 ("pragma % must apply to a library level variable");
14383 return;
14384 end if;
14386 -- Otherwise the pragma applies to a constant, which is illegal
14388 else
14389 Error_Pragma ("pragma % must apply to a variable declaration");
14390 return;
14391 end if;
14393 -- A pragma that applies to a Ghost entity becomes Ghost for the
14394 -- purposes of legality checks and removal of ignored Ghost code.
14396 Mark_Ghost_Pragma (N, Obj_Id);
14398 -- Chain the pragma on the contract for completeness
14400 Add_Contract_Item (N, Obj_Id);
14402 -- Analyze the Boolean expression (if any)
14404 if Present (Arg1) then
14405 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
14406 end if;
14407 end Constant_After_Elaboration;
14409 --------------------
14410 -- Contract_Cases --
14411 --------------------
14413 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
14415 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
14417 -- CASE_GUARD ::= boolean_EXPRESSION | others
14419 -- CONSEQUENCE ::= boolean_EXPRESSION
14421 -- Characteristics:
14423 -- * Analysis - The annotation undergoes initial checks to verify
14424 -- the legal placement and context. Secondary checks preanalyze the
14425 -- expressions in:
14427 -- Analyze_Contract_Cases_In_Decl_Part
14429 -- * Expansion - The annotation is expanded during the expansion of
14430 -- the related subprogram [body] contract as performed in:
14432 -- Expand_Subprogram_Contract
14434 -- * Template - The annotation utilizes the generic template of the
14435 -- related subprogram [body] when it is:
14437 -- aspect on subprogram declaration
14438 -- aspect on stand-alone subprogram body
14439 -- pragma on stand-alone subprogram body
14441 -- The annotation must prepare its own template when it is:
14443 -- pragma on subprogram declaration
14445 -- * Globals - Capture of global references must occur after full
14446 -- analysis.
14448 -- * Instance - The annotation is instantiated automatically when
14449 -- the related generic subprogram [body] is instantiated except for
14450 -- the "pragma on subprogram declaration" case. In that scenario
14451 -- the annotation must instantiate itself.
14453 when Pragma_Contract_Cases => Contract_Cases : declare
14454 Spec_Id : Entity_Id;
14455 Subp_Decl : Node_Id;
14456 Subp_Spec : Node_Id;
14458 begin
14459 GNAT_Pragma;
14460 Check_No_Identifiers;
14461 Check_Arg_Count (1);
14463 -- Ensure the proper placement of the pragma. Contract_Cases must
14464 -- be associated with a subprogram declaration or a body that acts
14465 -- as a spec.
14467 Subp_Decl :=
14468 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
14470 -- Entry
14472 if Nkind (Subp_Decl) = N_Entry_Declaration then
14473 null;
14475 -- Generic subprogram
14477 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
14478 null;
14480 -- Body acts as spec
14482 elsif Nkind (Subp_Decl) = N_Subprogram_Body
14483 and then No (Corresponding_Spec (Subp_Decl))
14484 then
14485 null;
14487 -- Body stub acts as spec
14489 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
14490 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
14491 then
14492 null;
14494 -- Subprogram
14496 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
14497 Subp_Spec := Specification (Subp_Decl);
14499 -- Pragma Contract_Cases is forbidden on null procedures, as
14500 -- this may lead to potential ambiguities in behavior when
14501 -- interface null procedures are involved.
14503 if Nkind (Subp_Spec) = N_Procedure_Specification
14504 and then Null_Present (Subp_Spec)
14505 then
14506 Error_Msg_N (Fix_Error
14507 ("pragma % cannot apply to null procedure"), N);
14508 return;
14509 end if;
14511 else
14512 Pragma_Misplaced;
14513 return;
14514 end if;
14516 Spec_Id := Unique_Defining_Entity (Subp_Decl);
14518 -- A pragma that applies to a Ghost entity becomes Ghost for the
14519 -- purposes of legality checks and removal of ignored Ghost code.
14521 Mark_Ghost_Pragma (N, Spec_Id);
14522 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
14524 -- Chain the pragma on the contract for further processing by
14525 -- Analyze_Contract_Cases_In_Decl_Part.
14527 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
14529 -- Fully analyze the pragma when it appears inside an entry
14530 -- or subprogram body because it cannot benefit from forward
14531 -- references.
14533 if Nkind (Subp_Decl) in N_Entry_Body
14534 | N_Subprogram_Body
14535 | N_Subprogram_Body_Stub
14536 then
14537 -- The legality checks of pragma Contract_Cases are affected by
14538 -- the SPARK mode in effect and the volatility of the context.
14539 -- Analyze all pragmas in a specific order.
14541 Analyze_If_Present (Pragma_SPARK_Mode);
14542 Analyze_If_Present (Pragma_Volatile_Function);
14543 Analyze_Contract_Cases_In_Decl_Part (N);
14544 end if;
14545 end Contract_Cases;
14547 ----------------
14548 -- Controlled --
14549 ----------------
14551 -- pragma Controlled (first_subtype_LOCAL_NAME);
14553 when Pragma_Controlled => Controlled : declare
14554 Arg : Node_Id;
14556 begin
14557 Check_No_Identifiers;
14558 Check_Arg_Count (1);
14559 Check_Arg_Is_Local_Name (Arg1);
14560 Arg := Get_Pragma_Arg (Arg1);
14562 if not Is_Entity_Name (Arg)
14563 or else not Is_Access_Type (Entity (Arg))
14564 then
14565 Error_Pragma_Arg ("pragma% requires access type", Arg1);
14566 else
14567 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
14568 end if;
14569 end Controlled;
14571 ----------------
14572 -- Convention --
14573 ----------------
14575 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
14576 -- [Entity =>] LOCAL_NAME);
14578 when Pragma_Convention => Convention : declare
14579 C : Convention_Id;
14580 E : Entity_Id;
14581 pragma Warnings (Off, C);
14582 pragma Warnings (Off, E);
14584 begin
14585 Check_Arg_Order ((Name_Convention, Name_Entity));
14586 Check_Ada_83_Warning;
14587 Check_Arg_Count (2);
14588 Process_Convention (C, E);
14590 -- A pragma that applies to a Ghost entity becomes Ghost for the
14591 -- purposes of legality checks and removal of ignored Ghost code.
14593 Mark_Ghost_Pragma (N, E);
14594 end Convention;
14596 ---------------------------
14597 -- Convention_Identifier --
14598 ---------------------------
14600 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
14601 -- [Convention =>] convention_IDENTIFIER);
14603 when Pragma_Convention_Identifier => Convention_Identifier : declare
14604 Idnam : Name_Id;
14605 Cname : Name_Id;
14607 begin
14608 GNAT_Pragma;
14609 Check_Arg_Order ((Name_Name, Name_Convention));
14610 Check_Arg_Count (2);
14611 Check_Optional_Identifier (Arg1, Name_Name);
14612 Check_Optional_Identifier (Arg2, Name_Convention);
14613 Check_Arg_Is_Identifier (Arg1);
14614 Check_Arg_Is_Identifier (Arg2);
14615 Idnam := Chars (Get_Pragma_Arg (Arg1));
14616 Cname := Chars (Get_Pragma_Arg (Arg2));
14618 if Is_Convention_Name (Cname) then
14619 Record_Convention_Identifier
14620 (Idnam, Get_Convention_Id (Cname));
14621 else
14622 Error_Pragma_Arg
14623 ("second arg for % pragma must be convention", Arg2);
14624 end if;
14625 end Convention_Identifier;
14627 ---------------
14628 -- CPP_Class --
14629 ---------------
14631 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
14633 when Pragma_CPP_Class =>
14634 GNAT_Pragma;
14636 if Warn_On_Obsolescent_Feature then
14637 Error_Msg_N
14638 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
14639 & "effect; replace it by pragma import?j?", N);
14640 end if;
14642 Check_Arg_Count (1);
14644 Rewrite (N,
14645 Make_Pragma (Loc,
14646 Chars => Name_Import,
14647 Pragma_Argument_Associations => New_List (
14648 Make_Pragma_Argument_Association (Loc,
14649 Expression => Make_Identifier (Loc, Name_CPP)),
14650 New_Copy (First (Pragma_Argument_Associations (N))))));
14651 Analyze (N);
14653 ---------------------
14654 -- CPP_Constructor --
14655 ---------------------
14657 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
14658 -- [, [External_Name =>] static_string_EXPRESSION ]
14659 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14661 when Pragma_CPP_Constructor => CPP_Constructor : declare
14662 Elmt : Elmt_Id;
14663 Id : Entity_Id;
14664 Def_Id : Entity_Id;
14665 Tag_Typ : Entity_Id;
14667 begin
14668 GNAT_Pragma;
14669 Check_At_Least_N_Arguments (1);
14670 Check_At_Most_N_Arguments (3);
14671 Check_Optional_Identifier (Arg1, Name_Entity);
14672 Check_Arg_Is_Local_Name (Arg1);
14674 Id := Get_Pragma_Arg (Arg1);
14675 Find_Program_Unit_Name (Id);
14677 -- If we did not find the name, we are done
14679 if Etype (Id) = Any_Type then
14680 return;
14681 end if;
14683 Def_Id := Entity (Id);
14685 -- Check if already defined as constructor
14687 if Is_Constructor (Def_Id) then
14688 Error_Msg_N
14689 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
14690 return;
14691 end if;
14693 if Ekind (Def_Id) = E_Function
14694 and then (Is_CPP_Class (Etype (Def_Id))
14695 or else (Is_Class_Wide_Type (Etype (Def_Id))
14696 and then
14697 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
14698 then
14699 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
14700 Error_Msg_N
14701 ("'C'P'P constructor must be defined in the scope of "
14702 & "its returned type", Arg1);
14703 end if;
14705 if Arg_Count >= 2 then
14706 Set_Imported (Def_Id);
14707 Set_Is_Public (Def_Id);
14708 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
14709 end if;
14711 Set_Has_Completion (Def_Id);
14712 Set_Is_Constructor (Def_Id);
14713 Set_Convention (Def_Id, Convention_CPP);
14715 -- Imported C++ constructors are not dispatching primitives
14716 -- because in C++ they don't have a dispatch table slot.
14717 -- However, in Ada the constructor has the profile of a
14718 -- function that returns a tagged type and therefore it has
14719 -- been treated as a primitive operation during semantic
14720 -- analysis. We now remove it from the list of primitive
14721 -- operations of the type.
14723 if Is_Tagged_Type (Etype (Def_Id))
14724 and then not Is_Class_Wide_Type (Etype (Def_Id))
14725 and then Is_Dispatching_Operation (Def_Id)
14726 then
14727 Tag_Typ := Etype (Def_Id);
14729 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
14730 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
14731 Next_Elmt (Elmt);
14732 end loop;
14734 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
14735 Set_Is_Dispatching_Operation (Def_Id, False);
14736 end if;
14738 -- For backward compatibility, if the constructor returns a
14739 -- class wide type, and we internally change the return type to
14740 -- the corresponding root type.
14742 if Is_Class_Wide_Type (Etype (Def_Id)) then
14743 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
14744 end if;
14745 else
14746 Error_Pragma_Arg
14747 ("pragma% requires function returning a 'C'P'P_Class type",
14748 Arg1);
14749 end if;
14750 end CPP_Constructor;
14752 -----------------
14753 -- CPP_Virtual --
14754 -----------------
14756 when Pragma_CPP_Virtual =>
14757 GNAT_Pragma;
14759 if Warn_On_Obsolescent_Feature then
14760 Error_Msg_N
14761 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
14762 & "effect?j?", N);
14763 end if;
14765 --------------------
14766 -- CUDA_Execute --
14767 --------------------
14769 -- pragma CUDA_Execute (PROCEDURE_CALL_STATEMENT,
14770 -- EXPRESSION,
14771 -- EXPRESSION,
14772 -- [, EXPRESSION
14773 -- [, EXPRESSION]]);
14775 when Pragma_CUDA_Execute => CUDA_Execute : declare
14777 function Is_Acceptable_Dim3 (N : Node_Id) return Boolean;
14778 -- Returns True if N is an acceptable argument for CUDA_Execute,
14779 -- False otherwise.
14781 ------------------------
14782 -- Is_Acceptable_Dim3 --
14783 ------------------------
14785 function Is_Acceptable_Dim3 (N : Node_Id) return Boolean is
14786 Expr : Node_Id;
14787 begin
14788 if Is_RTE (Etype (N), RE_Dim3)
14789 or else Is_Integer_Type (Etype (N))
14790 then
14791 return True;
14792 end if;
14794 if Nkind (N) = N_Aggregate
14795 and then List_Length (Expressions (N)) = 3
14796 then
14797 Expr := First (Expressions (N));
14798 while Present (Expr) loop
14799 Analyze_And_Resolve (Expr, Any_Integer);
14800 Next (Expr);
14801 end loop;
14802 return True;
14803 end if;
14805 return False;
14806 end Is_Acceptable_Dim3;
14808 -- Local variables
14810 Block_Dimensions : constant Node_Id := Get_Pragma_Arg (Arg3);
14811 Grid_Dimensions : constant Node_Id := Get_Pragma_Arg (Arg2);
14812 Kernel_Call : constant Node_Id := Get_Pragma_Arg (Arg1);
14813 Shared_Memory : Node_Id;
14814 Stream : Node_Id;
14816 -- Start of processing for CUDA_Execute
14818 begin
14819 GNAT_Pragma;
14820 Check_At_Least_N_Arguments (3);
14821 Check_At_Most_N_Arguments (5);
14823 Analyze_And_Resolve (Kernel_Call);
14824 if Nkind (Kernel_Call) /= N_Function_Call
14825 or else Etype (Kernel_Call) /= Standard_Void_Type
14826 then
14827 -- In `pragma CUDA_Execute (Kernel_Call (...), ...)`,
14828 -- GNAT sees Kernel_Call as an N_Function_Call since
14829 -- Kernel_Call "looks" like an expression. However, only
14830 -- procedures can be kernels, so to make things easier for the
14831 -- user the error message complains about Kernel_Call not being
14832 -- a procedure call.
14834 Error_Msg_N ("first argument of & must be a procedure call", N);
14835 end if;
14837 Analyze (Grid_Dimensions);
14838 if not Is_Acceptable_Dim3 (Grid_Dimensions) then
14839 Error_Msg_N
14840 ("second argument of & must be an Integer, Dim3 or aggregate "
14841 & "containing 3 Integers", N);
14842 end if;
14844 Analyze (Block_Dimensions);
14845 if not Is_Acceptable_Dim3 (Block_Dimensions) then
14846 Error_Msg_N
14847 ("third argument of & must be an Integer, Dim3 or aggregate "
14848 & "containing 3 Integers", N);
14849 end if;
14851 if Present (Arg4) then
14852 Shared_Memory := Get_Pragma_Arg (Arg4);
14853 Analyze_And_Resolve (Shared_Memory, Any_Integer);
14855 if Present (Arg5) then
14856 Stream := Get_Pragma_Arg (Arg5);
14857 Analyze_And_Resolve (Stream, RTE (RE_Stream_T));
14858 end if;
14859 end if;
14860 end CUDA_Execute;
14862 -----------------
14863 -- CUDA_Global --
14864 -----------------
14866 -- pragma CUDA_Global (IDENTIFIER);
14868 when Pragma_CUDA_Global => CUDA_Global : declare
14869 Arg_Node : Node_Id;
14870 Kernel_Proc : Entity_Id;
14871 Pack_Id : Entity_Id;
14872 begin
14873 GNAT_Pragma;
14874 Check_At_Least_N_Arguments (1);
14875 Check_At_Most_N_Arguments (1);
14876 Check_Optional_Identifier (Arg1, Name_Entity);
14877 Check_Arg_Is_Local_Name (Arg1);
14879 Arg_Node := Get_Pragma_Arg (Arg1);
14880 Analyze (Arg_Node);
14882 Kernel_Proc := Entity (Arg_Node);
14883 Pack_Id := Scope (Kernel_Proc);
14885 if Ekind (Kernel_Proc) /= E_Procedure then
14886 Error_Msg_NE ("& must be a procedure", N, Kernel_Proc);
14888 elsif Ekind (Pack_Id) /= E_Package
14889 or else not Is_Library_Level_Entity (Pack_Id)
14890 then
14891 Error_Msg_NE
14892 ("& must reside in a library-level package", N, Kernel_Proc);
14894 else
14895 Set_Is_CUDA_Kernel (Kernel_Proc);
14896 Add_CUDA_Kernel (Pack_Id, Kernel_Proc);
14897 end if;
14898 end CUDA_Global;
14900 ----------------
14901 -- CPP_Vtable --
14902 ----------------
14904 when Pragma_CPP_Vtable =>
14905 GNAT_Pragma;
14907 if Warn_On_Obsolescent_Feature then
14908 Error_Msg_N
14909 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
14910 & "effect?j?", N);
14911 end if;
14913 ---------
14914 -- CPU --
14915 ---------
14917 -- pragma CPU (EXPRESSION);
14919 when Pragma_CPU => CPU : declare
14920 P : constant Node_Id := Parent (N);
14921 Arg : Node_Id;
14922 Ent : Entity_Id;
14924 begin
14925 Ada_2012_Pragma;
14926 Check_No_Identifiers;
14927 Check_Arg_Count (1);
14928 Arg := Get_Pragma_Arg (Arg1);
14930 -- Subprogram case
14932 if Nkind (P) = N_Subprogram_Body then
14933 Check_In_Main_Program;
14935 Analyze_And_Resolve (Arg, Any_Integer);
14937 Ent := Defining_Unit_Name (Specification (P));
14939 if Nkind (Ent) = N_Defining_Program_Unit_Name then
14940 Ent := Defining_Identifier (Ent);
14941 end if;
14943 -- Must be static
14945 if not Is_OK_Static_Expression (Arg) then
14946 Flag_Non_Static_Expr
14947 ("main subprogram affinity is not static!", Arg);
14948 raise Pragma_Exit;
14950 -- If constraint error, then we already signalled an error
14952 elsif Raises_Constraint_Error (Arg) then
14953 null;
14955 -- Otherwise check in range
14957 else
14958 declare
14959 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
14960 -- This is the entity System.Multiprocessors.CPU_Range;
14962 Val : constant Uint := Expr_Value (Arg);
14964 begin
14965 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
14966 or else
14967 Val > Expr_Value (Type_High_Bound (CPU_Id))
14968 then
14969 Error_Pragma_Arg
14970 ("main subprogram CPU is out of range", Arg1);
14971 end if;
14972 end;
14973 end if;
14975 Set_Main_CPU
14976 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
14978 -- Task case
14980 elsif Nkind (P) = N_Task_Definition then
14981 Ent := Defining_Identifier (Parent (P));
14983 -- The expression must be analyzed in the special manner
14984 -- described in "Handling of Default and Per-Object
14985 -- Expressions" in sem.ads.
14987 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
14989 -- See comment in Sem_Ch13 about the following restrictions
14991 if Is_OK_Static_Expression (Arg) then
14992 if Expr_Value (Arg) = Uint_0 then
14993 Check_Restriction (No_Tasks_Unassigned_To_CPU, N);
14994 end if;
14995 else
14996 Check_Restriction (No_Dynamic_CPU_Assignment, N);
14997 end if;
14999 -- Anything else is incorrect
15001 else
15002 Pragma_Misplaced;
15003 end if;
15005 -- Check duplicate pragma before we chain the pragma in the Rep
15006 -- Item chain of Ent.
15008 Check_Duplicate_Pragma (Ent);
15009 Record_Rep_Item (Ent, N);
15010 end CPU;
15012 --------------------
15013 -- Deadline_Floor --
15014 --------------------
15016 -- pragma Deadline_Floor (time_span_EXPRESSION);
15018 when Pragma_Deadline_Floor => Deadline_Floor : declare
15019 P : constant Node_Id := Parent (N);
15020 Arg : Node_Id;
15021 Ent : Entity_Id;
15023 begin
15024 GNAT_Pragma;
15025 Check_No_Identifiers;
15026 Check_Arg_Count (1);
15028 Arg := Get_Pragma_Arg (Arg1);
15030 -- The expression must be analyzed in the special manner described
15031 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
15033 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
15035 -- Only protected types allowed
15037 if Nkind (P) /= N_Protected_Definition then
15038 Pragma_Misplaced;
15040 else
15041 Ent := Defining_Identifier (Parent (P));
15043 -- Check duplicate pragma before we chain the pragma in the Rep
15044 -- Item chain of Ent.
15046 Check_Duplicate_Pragma (Ent);
15047 Record_Rep_Item (Ent, N);
15048 end if;
15049 end Deadline_Floor;
15051 -----------
15052 -- Debug --
15053 -----------
15055 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
15057 when Pragma_Debug => Debug : declare
15058 Cond : Node_Id;
15059 Call : Node_Id;
15061 begin
15062 GNAT_Pragma;
15064 -- The condition for executing the call is that the expander
15065 -- is active and that we are not ignoring this debug pragma.
15067 Cond :=
15068 New_Occurrence_Of
15069 (Boolean_Literals
15070 (Expander_Active and then not Is_Ignored (N)),
15071 Loc);
15073 if not Is_Ignored (N) then
15074 Set_SCO_Pragma_Enabled (Loc);
15075 end if;
15077 if Arg_Count = 2 then
15078 Cond :=
15079 Make_And_Then (Loc,
15080 Left_Opnd => Relocate_Node (Cond),
15081 Right_Opnd => Get_Pragma_Arg (Arg1));
15082 Call := Get_Pragma_Arg (Arg2);
15083 else
15084 Call := Get_Pragma_Arg (Arg1);
15085 end if;
15087 if Nkind (Call) in N_Expanded_Name
15088 | N_Function_Call
15089 | N_Identifier
15090 | N_Indexed_Component
15091 | N_Selected_Component
15092 then
15093 -- If this pragma Debug comes from source, its argument was
15094 -- parsed as a name form (which is syntactically identical).
15095 -- In a generic context a parameterless call will be left as
15096 -- an expanded name (if global) or selected_component if local.
15097 -- Change it to a procedure call statement now.
15099 Change_Name_To_Procedure_Call_Statement (Call);
15101 elsif Nkind (Call) = N_Procedure_Call_Statement then
15103 -- Already in the form of a procedure call statement: nothing
15104 -- to do (could happen in case of an internally generated
15105 -- pragma Debug).
15107 null;
15109 else
15110 -- All other cases: diagnose error
15112 Error_Msg
15113 ("argument of pragma ""Debug"" is not procedure call",
15114 Sloc (Call));
15115 return;
15116 end if;
15118 -- Rewrite into a conditional with an appropriate condition. We
15119 -- wrap the procedure call in a block so that overhead from e.g.
15120 -- use of the secondary stack does not generate execution overhead
15121 -- for suppressed conditions.
15123 -- Normally the analysis that follows will freeze the subprogram
15124 -- being called. However, if the call is to a null procedure,
15125 -- we want to freeze it before creating the block, because the
15126 -- analysis that follows may be done with expansion disabled, in
15127 -- which case the body will not be generated, leading to spurious
15128 -- errors.
15130 if Nkind (Call) = N_Procedure_Call_Statement
15131 and then Is_Entity_Name (Name (Call))
15132 then
15133 Analyze (Name (Call));
15134 Freeze_Before (N, Entity (Name (Call)));
15135 end if;
15137 Rewrite (N,
15138 Make_Implicit_If_Statement (N,
15139 Condition => Cond,
15140 Then_Statements => New_List (
15141 Make_Block_Statement (Loc,
15142 Handled_Statement_Sequence =>
15143 Make_Handled_Sequence_Of_Statements (Loc,
15144 Statements => New_List (Relocate_Node (Call)))))));
15145 Analyze (N);
15147 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
15148 -- after analysis of the normally rewritten node, to capture all
15149 -- references to entities, which avoids issuing wrong warnings
15150 -- about unused entities.
15152 if GNATprove_Mode then
15153 Rewrite (N, Make_Null_Statement (Loc));
15154 end if;
15155 end Debug;
15157 ------------------
15158 -- Debug_Policy --
15159 ------------------
15161 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
15163 when Pragma_Debug_Policy =>
15164 GNAT_Pragma;
15165 Check_Arg_Count (1);
15166 Check_No_Identifiers;
15167 Check_Arg_Is_Identifier (Arg1);
15169 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
15170 -- rewrite it that way, and let the rest of the checking come
15171 -- from analyzing the rewritten pragma.
15173 Rewrite (N,
15174 Make_Pragma (Loc,
15175 Chars => Name_Check_Policy,
15176 Pragma_Argument_Associations => New_List (
15177 Make_Pragma_Argument_Association (Loc,
15178 Expression => Make_Identifier (Loc, Name_Debug)),
15180 Make_Pragma_Argument_Association (Loc,
15181 Expression => Get_Pragma_Arg (Arg1)))));
15182 Analyze (N);
15184 -------------------------------
15185 -- Default_Initial_Condition --
15186 -------------------------------
15188 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
15190 when Pragma_Default_Initial_Condition => DIC : declare
15191 Discard : Boolean;
15192 Stmt : Node_Id;
15193 Typ : Entity_Id;
15195 begin
15196 GNAT_Pragma;
15197 Check_No_Identifiers;
15198 Check_At_Most_N_Arguments (1);
15200 Typ := Empty;
15201 Stmt := Prev (N);
15202 while Present (Stmt) loop
15204 -- Skip prior pragmas, but check for duplicates
15206 if Nkind (Stmt) = N_Pragma then
15207 if Pragma_Name (Stmt) = Pname then
15208 Duplication_Error
15209 (Prag => N,
15210 Prev => Stmt);
15211 raise Pragma_Exit;
15212 end if;
15214 -- Skip internally generated code. Note that derived type
15215 -- declarations of untagged types with discriminants are
15216 -- rewritten as private type declarations.
15218 elsif not Comes_From_Source (Stmt)
15219 and then Nkind (Stmt) /= N_Private_Type_Declaration
15220 then
15221 null;
15223 -- The associated private type [extension] has been found, stop
15224 -- the search.
15226 elsif Nkind (Stmt) in N_Private_Extension_Declaration
15227 | N_Private_Type_Declaration
15228 then
15229 Typ := Defining_Entity (Stmt);
15230 exit;
15232 -- The pragma does not apply to a legal construct, issue an
15233 -- error and stop the analysis.
15235 else
15236 Pragma_Misplaced;
15237 return;
15238 end if;
15240 Stmt := Prev (Stmt);
15241 end loop;
15243 -- The pragma does not apply to a legal construct, issue an error
15244 -- and stop the analysis.
15246 if No (Typ) then
15247 Pragma_Misplaced;
15248 return;
15249 end if;
15251 -- A pragma that applies to a Ghost entity becomes Ghost for the
15252 -- purposes of legality checks and removal of ignored Ghost code.
15254 Mark_Ghost_Pragma (N, Typ);
15256 -- The pragma signals that the type defines its own DIC assertion
15257 -- expression.
15259 Set_Has_Own_DIC (Typ);
15261 -- Chain the pragma on the rep item chain for further processing
15263 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
15265 -- Create the declaration of the procedure which verifies the
15266 -- assertion expression of pragma DIC at runtime.
15268 Build_DIC_Procedure_Declaration (Typ);
15269 end DIC;
15271 ----------------------------------
15272 -- Default_Scalar_Storage_Order --
15273 ----------------------------------
15275 -- pragma Default_Scalar_Storage_Order
15276 -- (High_Order_First | Low_Order_First);
15278 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
15279 Default : Character;
15281 begin
15282 GNAT_Pragma;
15283 Check_Arg_Count (1);
15285 -- Default_Scalar_Storage_Order can appear as a configuration
15286 -- pragma, or in a declarative part of a package spec.
15288 if not Is_Configuration_Pragma then
15289 Check_Is_In_Decl_Part_Or_Package_Spec;
15290 end if;
15292 Check_No_Identifiers;
15293 Check_Arg_Is_One_Of
15294 (Arg1, Name_High_Order_First, Name_Low_Order_First);
15295 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15296 Default := Fold_Upper (Name_Buffer (1));
15298 if not Support_Nondefault_SSO_On_Target
15299 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
15300 then
15301 if Warn_On_Unrecognized_Pragma then
15302 Error_Msg_N
15303 ("non-default Scalar_Storage_Order not supported "
15304 & "on target?g?", N);
15305 Error_Msg_N
15306 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
15307 end if;
15309 -- Here set the specified default
15311 else
15312 Opt.Default_SSO := Default;
15313 end if;
15314 end DSSO;
15316 --------------------------
15317 -- Default_Storage_Pool --
15318 --------------------------
15320 -- pragma Default_Storage_Pool (storage_pool_NAME | null | Standard);
15322 when Pragma_Default_Storage_Pool => Default_Storage_Pool : declare
15323 Pool : Node_Id;
15325 begin
15326 Ada_2012_Pragma;
15327 Check_Arg_Count (1);
15329 -- Default_Storage_Pool can appear as a configuration pragma, or
15330 -- in a declarative part of a package spec.
15332 if not Is_Configuration_Pragma then
15333 Check_Is_In_Decl_Part_Or_Package_Spec;
15334 end if;
15336 if From_Aspect_Specification (N) then
15337 declare
15338 E : constant Entity_Id := Entity (Corresponding_Aspect (N));
15339 begin
15340 if not In_Open_Scopes (E) then
15341 Error_Msg_N
15342 ("aspect must apply to package or subprogram", N);
15343 end if;
15344 end;
15345 end if;
15347 if Present (Arg1) then
15348 Pool := Get_Pragma_Arg (Arg1);
15350 -- Case of Default_Storage_Pool (null);
15352 if Nkind (Pool) = N_Null then
15353 Analyze (Pool);
15355 -- This is an odd case, this is not really an expression,
15356 -- so we don't have a type for it. So just set the type to
15357 -- Empty.
15359 Set_Etype (Pool, Empty);
15361 -- Case of Default_Storage_Pool (Standard);
15363 elsif Nkind (Pool) = N_Identifier
15364 and then Chars (Pool) = Name_Standard
15365 then
15366 Analyze (Pool);
15368 if Entity (Pool) /= Standard_Standard then
15369 Error_Pragma_Arg
15370 ("package Standard is not directly visible", Arg1);
15371 end if;
15373 -- Case of Default_Storage_Pool (storage_pool_NAME);
15375 else
15376 -- If it's a configuration pragma, then the only allowed
15377 -- argument is "null".
15379 if Is_Configuration_Pragma then
15380 Error_Pragma_Arg ("NULL or Standard expected", Arg1);
15381 end if;
15383 -- The expected type for a non-"null" argument is
15384 -- Root_Storage_Pool'Class, and the pool must be a variable.
15386 Analyze_And_Resolve
15387 (Pool, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
15389 if Is_Variable (Pool) then
15391 -- A pragma that applies to a Ghost entity becomes Ghost
15392 -- for the purposes of legality checks and removal of
15393 -- ignored Ghost code.
15395 Mark_Ghost_Pragma (N, Entity (Pool));
15397 else
15398 Error_Pragma_Arg
15399 ("default storage pool must be a variable", Arg1);
15400 end if;
15401 end if;
15403 -- Record the pool name (or null). Freeze.Freeze_Entity for an
15404 -- access type will use this information to set the appropriate
15405 -- attributes of the access type. If the pragma appears in a
15406 -- generic unit it is ignored, given that it may refer to a
15407 -- local entity.
15409 if not Inside_A_Generic then
15410 Default_Pool := Pool;
15411 end if;
15412 end if;
15413 end Default_Storage_Pool;
15415 -------------
15416 -- Depends --
15417 -------------
15419 -- pragma Depends (DEPENDENCY_RELATION);
15421 -- DEPENDENCY_RELATION ::=
15422 -- null
15423 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
15425 -- DEPENDENCY_CLAUSE ::=
15426 -- OUTPUT_LIST =>[+] INPUT_LIST
15427 -- | NULL_DEPENDENCY_CLAUSE
15429 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
15431 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
15433 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
15435 -- OUTPUT ::= NAME | FUNCTION_RESULT
15436 -- INPUT ::= NAME
15438 -- where FUNCTION_RESULT is a function Result attribute_reference
15440 -- Characteristics:
15442 -- * Analysis - The annotation undergoes initial checks to verify
15443 -- the legal placement and context. Secondary checks fully analyze
15444 -- the dependency clauses in:
15446 -- Analyze_Depends_In_Decl_Part
15448 -- * Expansion - None.
15450 -- * Template - The annotation utilizes the generic template of the
15451 -- related subprogram [body] when it is:
15453 -- aspect on subprogram declaration
15454 -- aspect on stand-alone subprogram body
15455 -- pragma on stand-alone subprogram body
15457 -- The annotation must prepare its own template when it is:
15459 -- pragma on subprogram declaration
15461 -- * Globals - Capture of global references must occur after full
15462 -- analysis.
15464 -- * Instance - The annotation is instantiated automatically when
15465 -- the related generic subprogram [body] is instantiated except for
15466 -- the "pragma on subprogram declaration" case. In that scenario
15467 -- the annotation must instantiate itself.
15469 when Pragma_Depends => Depends : declare
15470 Legal : Boolean;
15471 Spec_Id : Entity_Id;
15472 Subp_Decl : Node_Id;
15474 begin
15475 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
15477 if Legal then
15479 -- Chain the pragma on the contract for further processing by
15480 -- Analyze_Depends_In_Decl_Part.
15482 Add_Contract_Item (N, Spec_Id);
15484 -- Fully analyze the pragma when it appears inside an entry
15485 -- or subprogram body because it cannot benefit from forward
15486 -- references.
15488 if Nkind (Subp_Decl) in N_Entry_Body
15489 | N_Subprogram_Body
15490 | N_Subprogram_Body_Stub
15491 then
15492 -- The legality checks of pragmas Depends and Global are
15493 -- affected by the SPARK mode in effect and the volatility
15494 -- of the context. In addition these two pragmas are subject
15495 -- to an inherent order:
15497 -- 1) Global
15498 -- 2) Depends
15500 -- Analyze all these pragmas in the order outlined above
15502 Analyze_If_Present (Pragma_SPARK_Mode);
15503 Analyze_If_Present (Pragma_Volatile_Function);
15504 Analyze_If_Present (Pragma_Global);
15505 Analyze_Depends_In_Decl_Part (N);
15506 end if;
15507 end if;
15508 end Depends;
15510 ---------------------
15511 -- Detect_Blocking --
15512 ---------------------
15514 -- pragma Detect_Blocking;
15516 when Pragma_Detect_Blocking =>
15517 Ada_2005_Pragma;
15518 Check_Arg_Count (0);
15519 Check_Valid_Configuration_Pragma;
15520 Detect_Blocking := True;
15522 ------------------------------------
15523 -- Disable_Atomic_Synchronization --
15524 ------------------------------------
15526 -- pragma Disable_Atomic_Synchronization [(Entity)];
15528 when Pragma_Disable_Atomic_Synchronization =>
15529 GNAT_Pragma;
15530 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
15532 -------------------
15533 -- Discard_Names --
15534 -------------------
15536 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
15538 when Pragma_Discard_Names => Discard_Names : declare
15539 E : Entity_Id;
15540 E_Id : Node_Id;
15542 begin
15543 Check_Ada_83_Warning;
15545 -- Deal with configuration pragma case
15547 if Arg_Count = 0 and then Is_Configuration_Pragma then
15548 Global_Discard_Names := True;
15549 return;
15551 -- Otherwise, check correct appropriate context
15553 else
15554 Check_Is_In_Decl_Part_Or_Package_Spec;
15556 if Arg_Count = 0 then
15558 -- If there is no parameter, then from now on this pragma
15559 -- applies to any enumeration, exception or tagged type
15560 -- defined in the current declarative part, and recursively
15561 -- to any nested scope.
15563 Set_Discard_Names (Current_Scope);
15564 return;
15566 else
15567 Check_Arg_Count (1);
15568 Check_Optional_Identifier (Arg1, Name_On);
15569 Check_Arg_Is_Local_Name (Arg1);
15571 E_Id := Get_Pragma_Arg (Arg1);
15573 if Etype (E_Id) = Any_Type then
15574 return;
15575 end if;
15577 E := Entity (E_Id);
15579 -- A pragma that applies to a Ghost entity becomes Ghost for
15580 -- the purposes of legality checks and removal of ignored
15581 -- Ghost code.
15583 Mark_Ghost_Pragma (N, E);
15585 if (Is_First_Subtype (E)
15586 and then
15587 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
15588 or else Ekind (E) = E_Exception
15589 then
15590 Set_Discard_Names (E);
15591 Record_Rep_Item (E, N);
15593 else
15594 Error_Pragma_Arg
15595 ("inappropriate entity for pragma%", Arg1);
15596 end if;
15597 end if;
15598 end if;
15599 end Discard_Names;
15601 ------------------------
15602 -- Dispatching_Domain --
15603 ------------------------
15605 -- pragma Dispatching_Domain (EXPRESSION);
15607 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
15608 P : constant Node_Id := Parent (N);
15609 Arg : Node_Id;
15610 Ent : Entity_Id;
15612 begin
15613 Ada_2012_Pragma;
15614 Check_No_Identifiers;
15615 Check_Arg_Count (1);
15617 -- This pragma is born obsolete, but not the aspect
15619 if not From_Aspect_Specification (N) then
15620 Check_Restriction
15621 (No_Obsolescent_Features, Pragma_Identifier (N));
15622 end if;
15624 if Nkind (P) = N_Task_Definition then
15625 Arg := Get_Pragma_Arg (Arg1);
15626 Ent := Defining_Identifier (Parent (P));
15628 -- A pragma that applies to a Ghost entity becomes Ghost for
15629 -- the purposes of legality checks and removal of ignored Ghost
15630 -- code.
15632 Mark_Ghost_Pragma (N, Ent);
15634 -- The expression must be analyzed in the special manner
15635 -- described in "Handling of Default and Per-Object
15636 -- Expressions" in sem.ads.
15638 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
15640 -- Check duplicate pragma before we chain the pragma in the Rep
15641 -- Item chain of Ent.
15643 Check_Duplicate_Pragma (Ent);
15644 Record_Rep_Item (Ent, N);
15646 -- Anything else is incorrect
15648 else
15649 Pragma_Misplaced;
15650 end if;
15651 end Dispatching_Domain;
15653 ---------------
15654 -- Elaborate --
15655 ---------------
15657 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
15659 when Pragma_Elaborate => Elaborate : declare
15660 Arg : Node_Id;
15661 Citem : Node_Id;
15663 begin
15664 -- Pragma must be in context items list of a compilation unit
15666 if not Is_In_Context_Clause then
15667 Pragma_Misplaced;
15668 end if;
15670 -- Must be at least one argument
15672 if Arg_Count = 0 then
15673 Error_Pragma ("pragma% requires at least one argument");
15674 end if;
15676 -- In Ada 83 mode, there can be no items following it in the
15677 -- context list except other pragmas and implicit with clauses
15678 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
15679 -- placement rule does not apply.
15681 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
15682 Citem := Next (N);
15683 while Present (Citem) loop
15684 if Nkind (Citem) = N_Pragma
15685 or else (Nkind (Citem) = N_With_Clause
15686 and then Implicit_With (Citem))
15687 then
15688 null;
15689 else
15690 Error_Pragma
15691 ("(Ada 83) pragma% must be at end of context clause");
15692 end if;
15694 Next (Citem);
15695 end loop;
15696 end if;
15698 -- Finally, the arguments must all be units mentioned in a with
15699 -- clause in the same context clause. Note we already checked (in
15700 -- Par.Prag) that the arguments are all identifiers or selected
15701 -- components.
15703 Arg := Arg1;
15704 Outer : while Present (Arg) loop
15705 Citem := First (List_Containing (N));
15706 Inner : while Citem /= N loop
15707 if Nkind (Citem) = N_With_Clause
15708 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
15709 then
15710 Set_Elaborate_Present (Citem, True);
15711 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
15713 -- With the pragma present, elaboration calls on
15714 -- subprograms from the named unit need no further
15715 -- checks, as long as the pragma appears in the current
15716 -- compilation unit. If the pragma appears in some unit
15717 -- in the context, there might still be a need for an
15718 -- Elaborate_All_Desirable from the current compilation
15719 -- to the named unit, so we keep the check enabled. This
15720 -- does not apply in SPARK mode, where we allow pragma
15721 -- Elaborate, but we don't trust it to be right so we
15722 -- will still insist on the Elaborate_All.
15724 if Legacy_Elaboration_Checks
15725 and then In_Extended_Main_Source_Unit (N)
15726 and then SPARK_Mode /= On
15727 then
15728 Set_Suppress_Elaboration_Warnings
15729 (Entity (Name (Citem)));
15730 end if;
15732 exit Inner;
15733 end if;
15735 Next (Citem);
15736 end loop Inner;
15738 if Citem = N then
15739 Error_Pragma_Arg
15740 ("argument of pragma% is not withed unit", Arg);
15741 end if;
15743 Next (Arg);
15744 end loop Outer;
15745 end Elaborate;
15747 -------------------
15748 -- Elaborate_All --
15749 -------------------
15751 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
15753 when Pragma_Elaborate_All => Elaborate_All : declare
15754 Arg : Node_Id;
15755 Citem : Node_Id;
15757 begin
15758 Check_Ada_83_Warning;
15760 -- Pragma must be in context items list of a compilation unit
15762 if not Is_In_Context_Clause then
15763 Pragma_Misplaced;
15764 end if;
15766 -- Must be at least one argument
15768 if Arg_Count = 0 then
15769 Error_Pragma ("pragma% requires at least one argument");
15770 end if;
15772 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
15773 -- have to appear at the end of the context clause, but may
15774 -- appear mixed in with other items, even in Ada 83 mode.
15776 -- Final check: the arguments must all be units mentioned in
15777 -- a with clause in the same context clause. Note that we
15778 -- already checked (in Par.Prag) that all the arguments are
15779 -- either identifiers or selected components.
15781 Arg := Arg1;
15782 Outr : while Present (Arg) loop
15783 Citem := First (List_Containing (N));
15784 Innr : while Citem /= N loop
15785 if Nkind (Citem) = N_With_Clause
15786 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
15787 then
15788 Set_Elaborate_All_Present (Citem, True);
15789 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
15791 -- Suppress warnings and elaboration checks on the named
15792 -- unit if the pragma is in the current compilation, as
15793 -- for pragma Elaborate.
15795 if Legacy_Elaboration_Checks
15796 and then In_Extended_Main_Source_Unit (N)
15797 then
15798 Set_Suppress_Elaboration_Warnings
15799 (Entity (Name (Citem)));
15800 end if;
15802 exit Innr;
15803 end if;
15805 Next (Citem);
15806 end loop Innr;
15808 if Citem = N then
15809 Set_Error_Posted (N);
15810 Error_Pragma_Arg
15811 ("argument of pragma% is not withed unit", Arg);
15812 end if;
15814 Next (Arg);
15815 end loop Outr;
15816 end Elaborate_All;
15818 --------------------
15819 -- Elaborate_Body --
15820 --------------------
15822 -- pragma Elaborate_Body [( library_unit_NAME )];
15824 when Pragma_Elaborate_Body => Elaborate_Body : declare
15825 Cunit_Node : Node_Id;
15826 Cunit_Ent : Entity_Id;
15828 begin
15829 Check_Ada_83_Warning;
15830 Check_Valid_Library_Unit_Pragma;
15832 if Nkind (N) = N_Null_Statement then
15833 return;
15834 end if;
15836 Cunit_Node := Cunit (Current_Sem_Unit);
15837 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15839 -- A pragma that applies to a Ghost entity becomes Ghost for the
15840 -- purposes of legality checks and removal of ignored Ghost code.
15842 Mark_Ghost_Pragma (N, Cunit_Ent);
15844 if Nkind (Unit (Cunit_Node)) in
15845 N_Package_Body | N_Subprogram_Body
15846 then
15847 Error_Pragma ("pragma% must refer to a spec, not a body");
15848 else
15849 Set_Body_Required (Cunit_Node);
15850 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
15852 -- If we are in dynamic elaboration mode, then we suppress
15853 -- elaboration warnings for the unit, since it is definitely
15854 -- fine NOT to do dynamic checks at the first level (and such
15855 -- checks will be suppressed because no elaboration boolean
15856 -- is created for Elaborate_Body packages).
15858 -- But in the static model of elaboration, Elaborate_Body is
15859 -- definitely NOT good enough to ensure elaboration safety on
15860 -- its own, since the body may WITH other units that are not
15861 -- safe from an elaboration point of view, so a client must
15862 -- still do an Elaborate_All on such units.
15864 -- Debug flag -gnatdD restores the old behavior of 3.13, where
15865 -- Elaborate_Body always suppressed elab warnings.
15867 if Legacy_Elaboration_Checks
15868 and then (Dynamic_Elaboration_Checks or Debug_Flag_DD)
15869 then
15870 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
15871 end if;
15872 end if;
15873 end Elaborate_Body;
15875 ------------------------
15876 -- Elaboration_Checks --
15877 ------------------------
15879 -- pragma Elaboration_Checks (Static | Dynamic);
15881 when Pragma_Elaboration_Checks => Elaboration_Checks : declare
15882 procedure Check_Duplicate_Elaboration_Checks_Pragma;
15883 -- Emit an error if the current context list already contains
15884 -- a previous Elaboration_Checks pragma. This routine raises
15885 -- Pragma_Exit if a duplicate is found.
15887 procedure Ignore_Elaboration_Checks_Pragma;
15888 -- Warn that the effects of the pragma are ignored. This routine
15889 -- raises Pragma_Exit.
15891 -----------------------------------------------
15892 -- Check_Duplicate_Elaboration_Checks_Pragma --
15893 -----------------------------------------------
15895 procedure Check_Duplicate_Elaboration_Checks_Pragma is
15896 Item : Node_Id;
15898 begin
15899 Item := Prev (N);
15900 while Present (Item) loop
15901 if Nkind (Item) = N_Pragma
15902 and then Pragma_Name (Item) = Name_Elaboration_Checks
15903 then
15904 Duplication_Error
15905 (Prag => N,
15906 Prev => Item);
15907 raise Pragma_Exit;
15908 end if;
15910 Prev (Item);
15911 end loop;
15912 end Check_Duplicate_Elaboration_Checks_Pragma;
15914 --------------------------------------
15915 -- Ignore_Elaboration_Checks_Pragma --
15916 --------------------------------------
15918 procedure Ignore_Elaboration_Checks_Pragma is
15919 begin
15920 Error_Msg_Name_1 := Pname;
15921 Error_Msg_N ("??effects of pragma % are ignored", N);
15922 Error_Msg_N
15923 ("\place pragma on initial declaration of library unit", N);
15925 raise Pragma_Exit;
15926 end Ignore_Elaboration_Checks_Pragma;
15928 -- Local variables
15930 Context : constant Node_Id := Parent (N);
15931 Unt : Node_Id;
15933 -- Start of processing for Elaboration_Checks
15935 begin
15936 GNAT_Pragma;
15937 Check_Arg_Count (1);
15938 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
15940 -- The pragma appears in a configuration file
15942 if No (Context) then
15943 Check_Valid_Configuration_Pragma;
15944 Check_Duplicate_Elaboration_Checks_Pragma;
15946 -- The pragma acts as a configuration pragma in a compilation unit
15948 -- pragma Elaboration_Checks (...);
15949 -- package Pack is ...;
15951 elsif Nkind (Context) = N_Compilation_Unit
15952 and then List_Containing (N) = Context_Items (Context)
15953 then
15954 Check_Valid_Configuration_Pragma;
15955 Check_Duplicate_Elaboration_Checks_Pragma;
15957 Unt := Unit (Context);
15959 -- The pragma must appear on the initial declaration of a unit.
15960 -- If this is not the case, warn that the effects of the pragma
15961 -- are ignored.
15963 if Nkind (Unt) = N_Package_Body then
15964 Ignore_Elaboration_Checks_Pragma;
15966 -- Check the Acts_As_Spec flag of the compilation units itself
15967 -- to determine whether the subprogram body completes since it
15968 -- has not been analyzed yet. This is safe because compilation
15969 -- units are not overloadable.
15971 elsif Nkind (Unt) = N_Subprogram_Body
15972 and then not Acts_As_Spec (Context)
15973 then
15974 Ignore_Elaboration_Checks_Pragma;
15976 elsif Nkind (Unt) = N_Subunit then
15977 Ignore_Elaboration_Checks_Pragma;
15978 end if;
15980 -- Otherwise the pragma does not appear at the configuration level
15981 -- and is illegal.
15983 else
15984 Pragma_Misplaced;
15985 end if;
15987 -- At this point the pragma is not a duplicate, and appears in the
15988 -- proper context. Set the elaboration model in effect.
15990 Dynamic_Elaboration_Checks :=
15991 Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic;
15992 end Elaboration_Checks;
15994 ---------------
15995 -- Eliminate --
15996 ---------------
15998 -- pragma Eliminate (
15999 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
16000 -- [Entity =>] IDENTIFIER |
16001 -- SELECTED_COMPONENT |
16002 -- STRING_LITERAL]
16003 -- [, Source_Location => SOURCE_TRACE]);
16005 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
16006 -- SOURCE_TRACE ::= STRING_LITERAL
16008 when Pragma_Eliminate => Eliminate : declare
16009 Args : Args_List (1 .. 5);
16010 Names : constant Name_List (1 .. 5) := (
16011 Name_Unit_Name,
16012 Name_Entity,
16013 Name_Parameter_Types,
16014 Name_Result_Type,
16015 Name_Source_Location);
16017 -- Note : Parameter_Types and Result_Type are leftovers from
16018 -- prior implementations of the pragma. They are not generated
16019 -- by the gnatelim tool, and play no role in selecting which
16020 -- of a set of overloaded names is chosen for elimination.
16022 Unit_Name : Node_Id renames Args (1);
16023 Entity : Node_Id renames Args (2);
16024 Parameter_Types : Node_Id renames Args (3);
16025 Result_Type : Node_Id renames Args (4);
16026 Source_Location : Node_Id renames Args (5);
16028 begin
16029 GNAT_Pragma;
16030 Check_Valid_Configuration_Pragma;
16031 Gather_Associations (Names, Args);
16033 if No (Unit_Name) then
16034 Error_Pragma ("missing Unit_Name argument for pragma%");
16035 end if;
16037 if No (Entity)
16038 and then (Present (Parameter_Types)
16039 or else
16040 Present (Result_Type)
16041 or else
16042 Present (Source_Location))
16043 then
16044 Error_Pragma ("missing Entity argument for pragma%");
16045 end if;
16047 if (Present (Parameter_Types)
16048 or else
16049 Present (Result_Type))
16050 and then
16051 Present (Source_Location)
16052 then
16053 Error_Pragma
16054 ("parameter profile and source location cannot be used "
16055 & "together in pragma%");
16056 end if;
16058 Process_Eliminate_Pragma
16060 Unit_Name,
16061 Entity,
16062 Parameter_Types,
16063 Result_Type,
16064 Source_Location);
16065 end Eliminate;
16067 -----------------------------------
16068 -- Enable_Atomic_Synchronization --
16069 -----------------------------------
16071 -- pragma Enable_Atomic_Synchronization [(Entity)];
16073 when Pragma_Enable_Atomic_Synchronization =>
16074 GNAT_Pragma;
16075 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
16077 ------------
16078 -- Export --
16079 ------------
16081 -- pragma Export (
16082 -- [ Convention =>] convention_IDENTIFIER,
16083 -- [ Entity =>] LOCAL_NAME
16084 -- [, [External_Name =>] static_string_EXPRESSION ]
16085 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16087 when Pragma_Export => Export : declare
16088 C : Convention_Id;
16089 Def_Id : Entity_Id;
16091 pragma Warnings (Off, C);
16093 begin
16094 Check_Ada_83_Warning;
16095 Check_Arg_Order
16096 ((Name_Convention,
16097 Name_Entity,
16098 Name_External_Name,
16099 Name_Link_Name));
16101 Check_At_Least_N_Arguments (2);
16102 Check_At_Most_N_Arguments (4);
16104 -- In Relaxed_RM_Semantics, support old Ada 83 style:
16105 -- pragma Export (Entity, "external name");
16107 if Relaxed_RM_Semantics
16108 and then Arg_Count = 2
16109 and then Nkind (Expression (Arg2)) = N_String_Literal
16110 then
16111 C := Convention_C;
16112 Def_Id := Get_Pragma_Arg (Arg1);
16113 Analyze (Def_Id);
16115 if not Is_Entity_Name (Def_Id) then
16116 Error_Pragma_Arg ("entity name required", Arg1);
16117 end if;
16119 Def_Id := Entity (Def_Id);
16120 Set_Exported (Def_Id, Arg1);
16122 else
16123 Process_Convention (C, Def_Id);
16125 -- A pragma that applies to a Ghost entity becomes Ghost for
16126 -- the purposes of legality checks and removal of ignored Ghost
16127 -- code.
16129 Mark_Ghost_Pragma (N, Def_Id);
16131 if Ekind (Def_Id) /= E_Constant then
16132 Note_Possible_Modification
16133 (Get_Pragma_Arg (Arg2), Sure => False);
16134 end if;
16136 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
16137 Set_Exported (Def_Id, Arg2);
16138 end if;
16140 -- If the entity is a deferred constant, propagate the information
16141 -- to the full view, because gigi elaborates the full view only.
16143 if Ekind (Def_Id) = E_Constant
16144 and then Present (Full_View (Def_Id))
16145 then
16146 declare
16147 Id2 : constant Entity_Id := Full_View (Def_Id);
16148 begin
16149 Set_Is_Exported (Id2, Is_Exported (Def_Id));
16150 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
16151 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
16152 end;
16153 end if;
16154 end Export;
16156 ---------------------
16157 -- Export_Function --
16158 ---------------------
16160 -- pragma Export_Function (
16161 -- [Internal =>] LOCAL_NAME
16162 -- [, [External =>] EXTERNAL_SYMBOL]
16163 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16164 -- [, [Result_Type =>] TYPE_DESIGNATOR]
16165 -- [, [Mechanism =>] MECHANISM]
16166 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
16168 -- EXTERNAL_SYMBOL ::=
16169 -- IDENTIFIER
16170 -- | static_string_EXPRESSION
16172 -- PARAMETER_TYPES ::=
16173 -- null
16174 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16176 -- TYPE_DESIGNATOR ::=
16177 -- subtype_NAME
16178 -- | subtype_Name ' Access
16180 -- MECHANISM ::=
16181 -- MECHANISM_NAME
16182 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16184 -- MECHANISM_ASSOCIATION ::=
16185 -- [formal_parameter_NAME =>] MECHANISM_NAME
16187 -- MECHANISM_NAME ::=
16188 -- Value
16189 -- | Reference
16191 when Pragma_Export_Function => Export_Function : declare
16192 Args : Args_List (1 .. 6);
16193 Names : constant Name_List (1 .. 6) := (
16194 Name_Internal,
16195 Name_External,
16196 Name_Parameter_Types,
16197 Name_Result_Type,
16198 Name_Mechanism,
16199 Name_Result_Mechanism);
16201 Internal : Node_Id renames Args (1);
16202 External : Node_Id renames Args (2);
16203 Parameter_Types : Node_Id renames Args (3);
16204 Result_Type : Node_Id renames Args (4);
16205 Mechanism : Node_Id renames Args (5);
16206 Result_Mechanism : Node_Id renames Args (6);
16208 begin
16209 GNAT_Pragma;
16210 Gather_Associations (Names, Args);
16211 Process_Extended_Import_Export_Subprogram_Pragma (
16212 Arg_Internal => Internal,
16213 Arg_External => External,
16214 Arg_Parameter_Types => Parameter_Types,
16215 Arg_Result_Type => Result_Type,
16216 Arg_Mechanism => Mechanism,
16217 Arg_Result_Mechanism => Result_Mechanism);
16218 end Export_Function;
16220 -------------------
16221 -- Export_Object --
16222 -------------------
16224 -- pragma Export_Object (
16225 -- [Internal =>] LOCAL_NAME
16226 -- [, [External =>] EXTERNAL_SYMBOL]
16227 -- [, [Size =>] EXTERNAL_SYMBOL]);
16229 -- EXTERNAL_SYMBOL ::=
16230 -- IDENTIFIER
16231 -- | static_string_EXPRESSION
16233 -- PARAMETER_TYPES ::=
16234 -- null
16235 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16237 -- TYPE_DESIGNATOR ::=
16238 -- subtype_NAME
16239 -- | subtype_Name ' Access
16241 -- MECHANISM ::=
16242 -- MECHANISM_NAME
16243 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16245 -- MECHANISM_ASSOCIATION ::=
16246 -- [formal_parameter_NAME =>] MECHANISM_NAME
16248 -- MECHANISM_NAME ::=
16249 -- Value
16250 -- | Reference
16252 when Pragma_Export_Object => Export_Object : declare
16253 Args : Args_List (1 .. 3);
16254 Names : constant Name_List (1 .. 3) := (
16255 Name_Internal,
16256 Name_External,
16257 Name_Size);
16259 Internal : Node_Id renames Args (1);
16260 External : Node_Id renames Args (2);
16261 Size : Node_Id renames Args (3);
16263 begin
16264 GNAT_Pragma;
16265 Gather_Associations (Names, Args);
16266 Process_Extended_Import_Export_Object_Pragma (
16267 Arg_Internal => Internal,
16268 Arg_External => External,
16269 Arg_Size => Size);
16270 end Export_Object;
16272 ----------------------
16273 -- Export_Procedure --
16274 ----------------------
16276 -- pragma Export_Procedure (
16277 -- [Internal =>] LOCAL_NAME
16278 -- [, [External =>] EXTERNAL_SYMBOL]
16279 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16280 -- [, [Mechanism =>] MECHANISM]);
16282 -- EXTERNAL_SYMBOL ::=
16283 -- IDENTIFIER
16284 -- | static_string_EXPRESSION
16286 -- PARAMETER_TYPES ::=
16287 -- null
16288 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16290 -- TYPE_DESIGNATOR ::=
16291 -- subtype_NAME
16292 -- | subtype_Name ' Access
16294 -- MECHANISM ::=
16295 -- MECHANISM_NAME
16296 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16298 -- MECHANISM_ASSOCIATION ::=
16299 -- [formal_parameter_NAME =>] MECHANISM_NAME
16301 -- MECHANISM_NAME ::=
16302 -- Value
16303 -- | Reference
16305 when Pragma_Export_Procedure => Export_Procedure : declare
16306 Args : Args_List (1 .. 4);
16307 Names : constant Name_List (1 .. 4) := (
16308 Name_Internal,
16309 Name_External,
16310 Name_Parameter_Types,
16311 Name_Mechanism);
16313 Internal : Node_Id renames Args (1);
16314 External : Node_Id renames Args (2);
16315 Parameter_Types : Node_Id renames Args (3);
16316 Mechanism : Node_Id renames Args (4);
16318 begin
16319 GNAT_Pragma;
16320 Gather_Associations (Names, Args);
16321 Process_Extended_Import_Export_Subprogram_Pragma (
16322 Arg_Internal => Internal,
16323 Arg_External => External,
16324 Arg_Parameter_Types => Parameter_Types,
16325 Arg_Mechanism => Mechanism);
16326 end Export_Procedure;
16328 ------------------
16329 -- Export_Value --
16330 ------------------
16332 -- pragma Export_Value (
16333 -- [Value =>] static_integer_EXPRESSION,
16334 -- [Link_Name =>] static_string_EXPRESSION);
16336 when Pragma_Export_Value =>
16337 GNAT_Pragma;
16338 Check_Arg_Order ((Name_Value, Name_Link_Name));
16339 Check_Arg_Count (2);
16341 Check_Optional_Identifier (Arg1, Name_Value);
16342 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
16344 Check_Optional_Identifier (Arg2, Name_Link_Name);
16345 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16347 -----------------------------
16348 -- Export_Valued_Procedure --
16349 -----------------------------
16351 -- pragma Export_Valued_Procedure (
16352 -- [Internal =>] LOCAL_NAME
16353 -- [, [External =>] EXTERNAL_SYMBOL,]
16354 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16355 -- [, [Mechanism =>] MECHANISM]);
16357 -- EXTERNAL_SYMBOL ::=
16358 -- IDENTIFIER
16359 -- | static_string_EXPRESSION
16361 -- PARAMETER_TYPES ::=
16362 -- null
16363 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16365 -- TYPE_DESIGNATOR ::=
16366 -- subtype_NAME
16367 -- | subtype_Name ' Access
16369 -- MECHANISM ::=
16370 -- MECHANISM_NAME
16371 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16373 -- MECHANISM_ASSOCIATION ::=
16374 -- [formal_parameter_NAME =>] MECHANISM_NAME
16376 -- MECHANISM_NAME ::=
16377 -- Value
16378 -- | Reference
16380 when Pragma_Export_Valued_Procedure =>
16381 Export_Valued_Procedure : declare
16382 Args : Args_List (1 .. 4);
16383 Names : constant Name_List (1 .. 4) := (
16384 Name_Internal,
16385 Name_External,
16386 Name_Parameter_Types,
16387 Name_Mechanism);
16389 Internal : Node_Id renames Args (1);
16390 External : Node_Id renames Args (2);
16391 Parameter_Types : Node_Id renames Args (3);
16392 Mechanism : Node_Id renames Args (4);
16394 begin
16395 GNAT_Pragma;
16396 Gather_Associations (Names, Args);
16397 Process_Extended_Import_Export_Subprogram_Pragma (
16398 Arg_Internal => Internal,
16399 Arg_External => External,
16400 Arg_Parameter_Types => Parameter_Types,
16401 Arg_Mechanism => Mechanism);
16402 end Export_Valued_Procedure;
16404 -------------------
16405 -- Extend_System --
16406 -------------------
16408 -- pragma Extend_System ([Name =>] Identifier);
16410 when Pragma_Extend_System =>
16411 GNAT_Pragma;
16412 Check_Valid_Configuration_Pragma;
16413 Check_Arg_Count (1);
16414 Check_Optional_Identifier (Arg1, Name_Name);
16415 Check_Arg_Is_Identifier (Arg1);
16417 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16419 if Name_Len > 4
16420 and then Name_Buffer (1 .. 4) = "aux_"
16421 then
16422 if Present (System_Extend_Pragma_Arg) then
16423 if Chars (Get_Pragma_Arg (Arg1)) =
16424 Chars (Expression (System_Extend_Pragma_Arg))
16425 then
16426 null;
16427 else
16428 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
16429 Error_Pragma ("pragma% conflicts with that #");
16430 end if;
16432 else
16433 System_Extend_Pragma_Arg := Arg1;
16435 if not GNAT_Mode then
16436 System_Extend_Unit := Arg1;
16437 end if;
16438 end if;
16439 else
16440 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
16441 end if;
16443 ------------------------
16444 -- Extensions_Allowed --
16445 ------------------------
16447 -- pragma Extensions_Allowed (ON | OFF);
16449 when Pragma_Extensions_Allowed =>
16450 GNAT_Pragma;
16451 Check_Arg_Count (1);
16452 Check_No_Identifiers;
16453 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16455 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
16456 Extensions_Allowed := True;
16457 Ada_Version := Ada_Version_Type'Last;
16459 else
16460 Extensions_Allowed := False;
16461 Ada_Version := Ada_Version_Explicit;
16462 Ada_Version_Pragma := Empty;
16463 end if;
16465 ------------------------
16466 -- Extensions_Visible --
16467 ------------------------
16469 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
16471 -- Characteristics:
16473 -- * Analysis - The annotation is fully analyzed immediately upon
16474 -- elaboration as its expression must be static.
16476 -- * Expansion - None.
16478 -- * Template - The annotation utilizes the generic template of the
16479 -- related subprogram [body] when it is:
16481 -- aspect on subprogram declaration
16482 -- aspect on stand-alone subprogram body
16483 -- pragma on stand-alone subprogram body
16485 -- The annotation must prepare its own template when it is:
16487 -- pragma on subprogram declaration
16489 -- * Globals - Capture of global references must occur after full
16490 -- analysis.
16492 -- * Instance - The annotation is instantiated automatically when
16493 -- the related generic subprogram [body] is instantiated except for
16494 -- the "pragma on subprogram declaration" case. In that scenario
16495 -- the annotation must instantiate itself.
16497 when Pragma_Extensions_Visible => Extensions_Visible : declare
16498 Formal : Entity_Id;
16499 Has_OK_Formal : Boolean := False;
16500 Spec_Id : Entity_Id;
16501 Subp_Decl : Node_Id;
16503 begin
16504 GNAT_Pragma;
16505 Check_No_Identifiers;
16506 Check_At_Most_N_Arguments (1);
16508 Subp_Decl :=
16509 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
16511 -- Abstract subprogram declaration
16513 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
16514 null;
16516 -- Generic subprogram declaration
16518 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
16519 null;
16521 -- Body acts as spec
16523 elsif Nkind (Subp_Decl) = N_Subprogram_Body
16524 and then No (Corresponding_Spec (Subp_Decl))
16525 then
16526 null;
16528 -- Body stub acts as spec
16530 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
16531 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
16532 then
16533 null;
16535 -- Subprogram declaration
16537 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
16538 null;
16540 -- Otherwise the pragma is associated with an illegal construct
16542 else
16543 Error_Pragma ("pragma % must apply to a subprogram");
16544 return;
16545 end if;
16547 -- Mark the pragma as Ghost if the related subprogram is also
16548 -- Ghost. This also ensures that any expansion performed further
16549 -- below will produce Ghost nodes.
16551 Spec_Id := Unique_Defining_Entity (Subp_Decl);
16552 Mark_Ghost_Pragma (N, Spec_Id);
16554 -- Chain the pragma on the contract for completeness
16556 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
16558 -- The legality checks of pragma Extension_Visible are affected
16559 -- by the SPARK mode in effect. Analyze all pragmas in specific
16560 -- order.
16562 Analyze_If_Present (Pragma_SPARK_Mode);
16564 -- Examine the formals of the related subprogram
16566 Formal := First_Formal (Spec_Id);
16567 while Present (Formal) loop
16569 -- At least one of the formals is of a specific tagged type,
16570 -- the pragma is legal.
16572 if Is_Specific_Tagged_Type (Etype (Formal)) then
16573 Has_OK_Formal := True;
16574 exit;
16576 -- A generic subprogram with at least one formal of a private
16577 -- type ensures the legality of the pragma because the actual
16578 -- may be specifically tagged. Note that this is verified by
16579 -- the check above at instantiation time.
16581 elsif Is_Private_Type (Etype (Formal))
16582 and then Is_Generic_Type (Etype (Formal))
16583 then
16584 Has_OK_Formal := True;
16585 exit;
16586 end if;
16588 Next_Formal (Formal);
16589 end loop;
16591 if not Has_OK_Formal then
16592 Error_Msg_Name_1 := Pname;
16593 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
16594 Error_Msg_NE
16595 ("\subprogram & lacks parameter of specific tagged or "
16596 & "generic private type", N, Spec_Id);
16598 return;
16599 end if;
16601 -- Analyze the Boolean expression (if any)
16603 if Present (Arg1) then
16604 Check_Static_Boolean_Expression
16605 (Expression (Get_Argument (N, Spec_Id)));
16606 end if;
16607 end Extensions_Visible;
16609 --------------
16610 -- External --
16611 --------------
16613 -- pragma External (
16614 -- [ Convention =>] convention_IDENTIFIER,
16615 -- [ Entity =>] LOCAL_NAME
16616 -- [, [External_Name =>] static_string_EXPRESSION ]
16617 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16619 when Pragma_External => External : declare
16620 C : Convention_Id;
16621 E : Entity_Id;
16622 pragma Warnings (Off, C);
16624 begin
16625 GNAT_Pragma;
16626 Check_Arg_Order
16627 ((Name_Convention,
16628 Name_Entity,
16629 Name_External_Name,
16630 Name_Link_Name));
16631 Check_At_Least_N_Arguments (2);
16632 Check_At_Most_N_Arguments (4);
16633 Process_Convention (C, E);
16635 -- A pragma that applies to a Ghost entity becomes Ghost for the
16636 -- purposes of legality checks and removal of ignored Ghost code.
16638 Mark_Ghost_Pragma (N, E);
16640 Note_Possible_Modification
16641 (Get_Pragma_Arg (Arg2), Sure => False);
16642 Process_Interface_Name (E, Arg3, Arg4, N);
16643 Set_Exported (E, Arg2);
16644 end External;
16646 --------------------------
16647 -- External_Name_Casing --
16648 --------------------------
16650 -- pragma External_Name_Casing (
16651 -- UPPERCASE | LOWERCASE
16652 -- [, AS_IS | UPPERCASE | LOWERCASE]);
16654 when Pragma_External_Name_Casing =>
16655 GNAT_Pragma;
16656 Check_No_Identifiers;
16658 if Arg_Count = 2 then
16659 Check_Arg_Is_One_Of
16660 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
16662 case Chars (Get_Pragma_Arg (Arg2)) is
16663 when Name_As_Is =>
16664 Opt.External_Name_Exp_Casing := As_Is;
16666 when Name_Uppercase =>
16667 Opt.External_Name_Exp_Casing := Uppercase;
16669 when Name_Lowercase =>
16670 Opt.External_Name_Exp_Casing := Lowercase;
16672 when others =>
16673 null;
16674 end case;
16676 else
16677 Check_Arg_Count (1);
16678 end if;
16680 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
16682 case Chars (Get_Pragma_Arg (Arg1)) is
16683 when Name_Uppercase =>
16684 Opt.External_Name_Imp_Casing := Uppercase;
16686 when Name_Lowercase =>
16687 Opt.External_Name_Imp_Casing := Lowercase;
16689 when others =>
16690 null;
16691 end case;
16693 ---------------
16694 -- Fast_Math --
16695 ---------------
16697 -- pragma Fast_Math;
16699 when Pragma_Fast_Math =>
16700 GNAT_Pragma;
16701 Check_No_Identifiers;
16702 Check_Valid_Configuration_Pragma;
16703 Fast_Math := True;
16705 --------------------------
16706 -- Favor_Top_Level --
16707 --------------------------
16709 -- pragma Favor_Top_Level (type_NAME);
16711 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
16712 Typ : Entity_Id;
16714 begin
16715 GNAT_Pragma;
16716 Check_No_Identifiers;
16717 Check_Arg_Count (1);
16718 Check_Arg_Is_Local_Name (Arg1);
16719 Typ := Entity (Get_Pragma_Arg (Arg1));
16721 -- A pragma that applies to a Ghost entity becomes Ghost for the
16722 -- purposes of legality checks and removal of ignored Ghost code.
16724 Mark_Ghost_Pragma (N, Typ);
16726 -- If it's an access-to-subprogram type (in particular, not a
16727 -- subtype), set the flag on that type.
16729 if Is_Access_Subprogram_Type (Typ) then
16730 Set_Can_Use_Internal_Rep (Typ, False);
16732 -- Otherwise it's an error (name denotes the wrong sort of entity)
16734 else
16735 Error_Pragma_Arg
16736 ("access-to-subprogram type expected",
16737 Get_Pragma_Arg (Arg1));
16738 end if;
16739 end Favor_Top_Level;
16741 ---------------------------
16742 -- Finalize_Storage_Only --
16743 ---------------------------
16745 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
16747 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
16748 Assoc : constant Node_Id := Arg1;
16749 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
16750 Typ : Entity_Id;
16752 begin
16753 GNAT_Pragma;
16754 Check_No_Identifiers;
16755 Check_Arg_Count (1);
16756 Check_Arg_Is_Local_Name (Arg1);
16758 Find_Type (Type_Id);
16759 Typ := Entity (Type_Id);
16761 if Typ = Any_Type
16762 or else Rep_Item_Too_Early (Typ, N)
16763 then
16764 return;
16765 else
16766 Typ := Underlying_Type (Typ);
16767 end if;
16769 if not Is_Controlled (Typ) then
16770 Error_Pragma ("pragma% must specify controlled type");
16771 end if;
16773 Check_First_Subtype (Arg1);
16775 if Finalize_Storage_Only (Typ) then
16776 Error_Pragma ("duplicate pragma%, only one allowed");
16778 elsif not Rep_Item_Too_Late (Typ, N) then
16779 Set_Finalize_Storage_Only (Base_Type (Typ), True);
16780 end if;
16781 end Finalize_Storage;
16783 -----------
16784 -- Ghost --
16785 -----------
16787 -- pragma Ghost [ (boolean_EXPRESSION) ];
16789 when Pragma_Ghost => Ghost : declare
16790 Context : Node_Id;
16791 Expr : Node_Id;
16792 Id : Entity_Id;
16793 Orig_Stmt : Node_Id;
16794 Prev_Id : Entity_Id;
16795 Stmt : Node_Id;
16797 begin
16798 GNAT_Pragma;
16799 Check_No_Identifiers;
16800 Check_At_Most_N_Arguments (1);
16802 Id := Empty;
16803 Stmt := Prev (N);
16804 while Present (Stmt) loop
16806 -- Skip prior pragmas, but check for duplicates
16808 if Nkind (Stmt) = N_Pragma then
16809 if Pragma_Name (Stmt) = Pname then
16810 Duplication_Error
16811 (Prag => N,
16812 Prev => Stmt);
16813 raise Pragma_Exit;
16814 end if;
16816 -- Task unit declared without a definition cannot be subject to
16817 -- pragma Ghost (SPARK RM 6.9(19)).
16819 elsif Nkind (Stmt) in
16820 N_Single_Task_Declaration | N_Task_Type_Declaration
16821 then
16822 Error_Pragma ("pragma % cannot apply to a task type");
16823 return;
16825 -- Skip internally generated code
16827 elsif not Comes_From_Source (Stmt) then
16828 Orig_Stmt := Original_Node (Stmt);
16830 -- When pragma Ghost applies to an untagged derivation, the
16831 -- derivation is transformed into a [sub]type declaration.
16833 if Nkind (Stmt) in
16834 N_Full_Type_Declaration | N_Subtype_Declaration
16835 and then Comes_From_Source (Orig_Stmt)
16836 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
16837 and then Nkind (Type_Definition (Orig_Stmt)) =
16838 N_Derived_Type_Definition
16839 then
16840 Id := Defining_Entity (Stmt);
16841 exit;
16843 -- When pragma Ghost applies to an object declaration which
16844 -- is initialized by means of a function call that returns
16845 -- on the secondary stack, the object declaration becomes a
16846 -- renaming.
16848 elsif Nkind (Stmt) = N_Object_Renaming_Declaration
16849 and then Comes_From_Source (Orig_Stmt)
16850 and then Nkind (Orig_Stmt) = N_Object_Declaration
16851 then
16852 Id := Defining_Entity (Stmt);
16853 exit;
16855 -- When pragma Ghost applies to an expression function, the
16856 -- expression function is transformed into a subprogram.
16858 elsif Nkind (Stmt) = N_Subprogram_Declaration
16859 and then Comes_From_Source (Orig_Stmt)
16860 and then Nkind (Orig_Stmt) = N_Expression_Function
16861 then
16862 Id := Defining_Entity (Stmt);
16863 exit;
16864 end if;
16866 -- The pragma applies to a legal construct, stop the traversal
16868 elsif Nkind (Stmt) in N_Abstract_Subprogram_Declaration
16869 | N_Full_Type_Declaration
16870 | N_Generic_Subprogram_Declaration
16871 | N_Object_Declaration
16872 | N_Private_Extension_Declaration
16873 | N_Private_Type_Declaration
16874 | N_Subprogram_Declaration
16875 | N_Subtype_Declaration
16876 then
16877 Id := Defining_Entity (Stmt);
16878 exit;
16880 -- The pragma does not apply to a legal construct, issue an
16881 -- error and stop the analysis.
16883 else
16884 Error_Pragma
16885 ("pragma % must apply to an object, package, subprogram "
16886 & "or type");
16887 return;
16888 end if;
16890 Stmt := Prev (Stmt);
16891 end loop;
16893 Context := Parent (N);
16895 -- Handle compilation units
16897 if Nkind (Context) = N_Compilation_Unit_Aux then
16898 Context := Unit (Parent (Context));
16899 end if;
16901 -- Protected and task types cannot be subject to pragma Ghost
16902 -- (SPARK RM 6.9(19)).
16904 if Nkind (Context) in N_Protected_Body | N_Protected_Definition
16905 then
16906 Error_Pragma ("pragma % cannot apply to a protected type");
16907 return;
16909 elsif Nkind (Context) in N_Task_Body | N_Task_Definition then
16910 Error_Pragma ("pragma % cannot apply to a task type");
16911 return;
16912 end if;
16914 if No (Id) then
16916 -- When pragma Ghost is associated with a [generic] package, it
16917 -- appears in the visible declarations.
16919 if Nkind (Context) = N_Package_Specification
16920 and then Present (Visible_Declarations (Context))
16921 and then List_Containing (N) = Visible_Declarations (Context)
16922 then
16923 Id := Defining_Entity (Context);
16925 -- Pragma Ghost applies to a stand-alone subprogram body
16927 elsif Nkind (Context) = N_Subprogram_Body
16928 and then No (Corresponding_Spec (Context))
16929 then
16930 Id := Defining_Entity (Context);
16932 -- Pragma Ghost applies to a subprogram declaration that acts
16933 -- as a compilation unit.
16935 elsif Nkind (Context) = N_Subprogram_Declaration then
16936 Id := Defining_Entity (Context);
16938 -- Pragma Ghost applies to a generic subprogram
16940 elsif Nkind (Context) = N_Generic_Subprogram_Declaration then
16941 Id := Defining_Entity (Specification (Context));
16942 end if;
16943 end if;
16945 if No (Id) then
16946 Error_Pragma
16947 ("pragma % must apply to an object, package, subprogram or "
16948 & "type");
16949 return;
16950 end if;
16952 -- Handle completions of types and constants that are subject to
16953 -- pragma Ghost.
16955 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
16956 Prev_Id := Incomplete_Or_Partial_View (Id);
16958 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
16959 Error_Msg_Name_1 := Pname;
16961 -- The full declaration of a deferred constant cannot be
16962 -- subject to pragma Ghost unless the deferred declaration
16963 -- is also Ghost (SPARK RM 6.9(9)).
16965 if Ekind (Prev_Id) = E_Constant then
16966 Error_Msg_Name_1 := Pname;
16967 Error_Msg_NE (Fix_Error
16968 ("pragma % must apply to declaration of deferred "
16969 & "constant &"), N, Id);
16970 return;
16972 -- Pragma Ghost may appear on the full view of an incomplete
16973 -- type because the incomplete declaration lacks aspects and
16974 -- cannot be subject to pragma Ghost.
16976 elsif Ekind (Prev_Id) = E_Incomplete_Type then
16977 null;
16979 -- The full declaration of a type cannot be subject to
16980 -- pragma Ghost unless the partial view is also Ghost
16981 -- (SPARK RM 6.9(9)).
16983 else
16984 Error_Msg_NE (Fix_Error
16985 ("pragma % must apply to partial view of type &"),
16986 N, Id);
16987 return;
16988 end if;
16989 end if;
16991 -- A synchronized object cannot be subject to pragma Ghost
16992 -- (SPARK RM 6.9(19)).
16994 elsif Ekind (Id) = E_Variable then
16995 if Is_Protected_Type (Etype (Id)) then
16996 Error_Pragma ("pragma % cannot apply to a protected object");
16997 return;
16999 elsif Is_Task_Type (Etype (Id)) then
17000 Error_Pragma ("pragma % cannot apply to a task object");
17001 return;
17002 end if;
17003 end if;
17005 -- Analyze the Boolean expression (if any)
17007 if Present (Arg1) then
17008 Expr := Get_Pragma_Arg (Arg1);
17010 Analyze_And_Resolve (Expr, Standard_Boolean);
17012 if Is_OK_Static_Expression (Expr) then
17014 -- "Ghostness" cannot be turned off once enabled within a
17015 -- region (SPARK RM 6.9(6)).
17017 if Is_False (Expr_Value (Expr))
17018 and then Ghost_Mode > None
17019 then
17020 Error_Pragma
17021 ("pragma % with value False cannot appear in enabled "
17022 & "ghost region");
17023 return;
17024 end if;
17026 -- Otherwise the expression is not static
17028 else
17029 Error_Pragma_Arg
17030 ("expression of pragma % must be static", Expr);
17031 return;
17032 end if;
17033 end if;
17035 Set_Is_Ghost_Entity (Id);
17036 end Ghost;
17038 ------------
17039 -- Global --
17040 ------------
17042 -- pragma Global (GLOBAL_SPECIFICATION);
17044 -- GLOBAL_SPECIFICATION ::=
17045 -- null
17046 -- | (GLOBAL_LIST)
17047 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
17049 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
17051 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
17052 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
17053 -- GLOBAL_ITEM ::= NAME
17055 -- Characteristics:
17057 -- * Analysis - The annotation undergoes initial checks to verify
17058 -- the legal placement and context. Secondary checks fully analyze
17059 -- the dependency clauses in:
17061 -- Analyze_Global_In_Decl_Part
17063 -- * Expansion - None.
17065 -- * Template - The annotation utilizes the generic template of the
17066 -- related subprogram [body] when it is:
17068 -- aspect on subprogram declaration
17069 -- aspect on stand-alone subprogram body
17070 -- pragma on stand-alone subprogram body
17072 -- The annotation must prepare its own template when it is:
17074 -- pragma on subprogram declaration
17076 -- * Globals - Capture of global references must occur after full
17077 -- analysis.
17079 -- * Instance - The annotation is instantiated automatically when
17080 -- the related generic subprogram [body] is instantiated except for
17081 -- the "pragma on subprogram declaration" case. In that scenario
17082 -- the annotation must instantiate itself.
17084 when Pragma_Global => Global : declare
17085 Legal : Boolean;
17086 Spec_Id : Entity_Id;
17087 Subp_Decl : Node_Id;
17089 begin
17090 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
17092 if Legal then
17094 -- Chain the pragma on the contract for further processing by
17095 -- Analyze_Global_In_Decl_Part.
17097 Add_Contract_Item (N, Spec_Id);
17099 -- Fully analyze the pragma when it appears inside an entry
17100 -- or subprogram body because it cannot benefit from forward
17101 -- references.
17103 if Nkind (Subp_Decl) in N_Entry_Body
17104 | N_Subprogram_Body
17105 | N_Subprogram_Body_Stub
17106 then
17107 -- The legality checks of pragmas Depends and Global are
17108 -- affected by the SPARK mode in effect and the volatility
17109 -- of the context. In addition these two pragmas are subject
17110 -- to an inherent order:
17112 -- 1) Global
17113 -- 2) Depends
17115 -- Analyze all these pragmas in the order outlined above
17117 Analyze_If_Present (Pragma_SPARK_Mode);
17118 Analyze_If_Present (Pragma_Volatile_Function);
17119 Analyze_Global_In_Decl_Part (N);
17120 Analyze_If_Present (Pragma_Depends);
17121 end if;
17122 end if;
17123 end Global;
17125 -----------
17126 -- Ident --
17127 -----------
17129 -- pragma Ident (static_string_EXPRESSION)
17131 -- Note: pragma Comment shares this processing. Pragma Ident is
17132 -- identical in effect to pragma Commment.
17134 when Pragma_Comment
17135 | Pragma_Ident
17137 Ident : declare
17138 Str : Node_Id;
17140 begin
17141 GNAT_Pragma;
17142 Check_Arg_Count (1);
17143 Check_No_Identifiers;
17144 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17145 Store_Note (N);
17147 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
17149 declare
17150 CS : Node_Id;
17151 GP : Node_Id;
17153 begin
17154 GP := Parent (Parent (N));
17156 if Nkind (GP) in
17157 N_Package_Declaration | N_Generic_Package_Declaration
17158 then
17159 GP := Parent (GP);
17160 end if;
17162 -- If we have a compilation unit, then record the ident value,
17163 -- checking for improper duplication.
17165 if Nkind (GP) = N_Compilation_Unit then
17166 CS := Ident_String (Current_Sem_Unit);
17168 if Present (CS) then
17170 -- If we have multiple instances, concatenate them.
17172 Start_String (Strval (CS));
17173 Store_String_Char (' ');
17174 Store_String_Chars (Strval (Str));
17175 Set_Strval (CS, End_String);
17177 else
17178 Set_Ident_String (Current_Sem_Unit, Str);
17179 end if;
17181 -- For subunits, we just ignore the Ident, since in GNAT these
17182 -- are not separate object files, and hence not separate units
17183 -- in the unit table.
17185 elsif Nkind (GP) = N_Subunit then
17186 null;
17187 end if;
17188 end;
17189 end Ident;
17191 -------------------
17192 -- Ignore_Pragma --
17193 -------------------
17195 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
17197 -- Entirely handled in the parser, nothing to do here
17199 when Pragma_Ignore_Pragma =>
17200 null;
17202 ----------------------------
17203 -- Implementation_Defined --
17204 ----------------------------
17206 -- pragma Implementation_Defined (LOCAL_NAME);
17208 -- Marks previously declared entity as implementation defined. For
17209 -- an overloaded entity, applies to the most recent homonym.
17211 -- pragma Implementation_Defined;
17213 -- The form with no arguments appears anywhere within a scope, most
17214 -- typically a package spec, and indicates that all entities that are
17215 -- defined within the package spec are Implementation_Defined.
17217 when Pragma_Implementation_Defined => Implementation_Defined : declare
17218 Ent : Entity_Id;
17220 begin
17221 GNAT_Pragma;
17222 Check_No_Identifiers;
17224 -- Form with no arguments
17226 if Arg_Count = 0 then
17227 Set_Is_Implementation_Defined (Current_Scope);
17229 -- Form with one argument
17231 else
17232 Check_Arg_Count (1);
17233 Check_Arg_Is_Local_Name (Arg1);
17234 Ent := Entity (Get_Pragma_Arg (Arg1));
17235 Set_Is_Implementation_Defined (Ent);
17236 end if;
17237 end Implementation_Defined;
17239 -----------------
17240 -- Implemented --
17241 -----------------
17243 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
17245 -- IMPLEMENTATION_KIND ::=
17246 -- By_Entry | By_Protected_Procedure | By_Any | Optional
17248 -- "By_Any" and "Optional" are treated as synonyms in order to
17249 -- support Ada 2012 aspect Synchronization.
17251 when Pragma_Implemented => Implemented : declare
17252 Proc_Id : Entity_Id;
17253 Typ : Entity_Id;
17255 begin
17256 Ada_2012_Pragma;
17257 Check_Arg_Count (2);
17258 Check_No_Identifiers;
17259 Check_Arg_Is_Identifier (Arg1);
17260 Check_Arg_Is_Local_Name (Arg1);
17261 Check_Arg_Is_One_Of (Arg2,
17262 Name_By_Any,
17263 Name_By_Entry,
17264 Name_By_Protected_Procedure,
17265 Name_Optional);
17267 -- Extract the name of the local procedure
17269 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
17271 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
17272 -- primitive procedure of a synchronized tagged type.
17274 if Ekind (Proc_Id) = E_Procedure
17275 and then Is_Primitive (Proc_Id)
17276 and then Present (First_Formal (Proc_Id))
17277 then
17278 Typ := Etype (First_Formal (Proc_Id));
17280 if Is_Tagged_Type (Typ)
17281 and then
17283 -- Check for a protected, a synchronized or a task interface
17285 ((Is_Interface (Typ)
17286 and then Is_Synchronized_Interface (Typ))
17288 -- Check for a protected type or a task type that implements
17289 -- an interface.
17291 or else
17292 (Is_Concurrent_Record_Type (Typ)
17293 and then Present (Interfaces (Typ)))
17295 -- In analysis-only mode, examine original protected type
17297 or else
17298 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
17299 and then Present (Interface_List (Parent (Typ))))
17301 -- Check for a private record extension with keyword
17302 -- "synchronized".
17304 or else
17305 (Ekind (Typ) in E_Record_Type_With_Private
17306 | E_Record_Subtype_With_Private
17307 and then Synchronized_Present (Parent (Typ))))
17308 then
17309 null;
17310 else
17311 Error_Pragma_Arg
17312 ("controlling formal must be of synchronized tagged type",
17313 Arg1);
17314 return;
17315 end if;
17317 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
17318 -- By_Protected_Procedure to the primitive procedure of a task
17319 -- interface.
17321 if Chars (Get_Pragma_Arg (Arg2)) = Name_By_Protected_Procedure
17322 and then Is_Interface (Typ)
17323 and then Is_Task_Interface (Typ)
17324 then
17325 Error_Pragma_Arg
17326 ("implementation kind By_Protected_Procedure cannot be "
17327 & "applied to a task interface primitive", Arg2);
17328 return;
17329 end if;
17331 -- Procedures declared inside a protected type must be accepted
17333 elsif Ekind (Proc_Id) = E_Procedure
17334 and then Is_Protected_Type (Scope (Proc_Id))
17335 then
17336 null;
17338 -- The first argument is not a primitive procedure
17340 else
17341 Error_Pragma_Arg
17342 ("pragma % must be applied to a primitive procedure", Arg1);
17343 return;
17344 end if;
17346 -- Ada 2012 (AI12-0279): Cannot apply the implementation_kind
17347 -- By_Protected_Procedure to a procedure that has aspect Yield
17349 if Chars (Get_Pragma_Arg (Arg2)) = Name_By_Protected_Procedure
17350 and then Has_Yield_Aspect (Proc_Id)
17351 then
17352 Error_Pragma_Arg
17353 ("implementation kind By_Protected_Procedure cannot be "
17354 & "applied to entities with aspect 'Yield", Arg2);
17355 return;
17356 end if;
17358 Record_Rep_Item (Proc_Id, N);
17359 end Implemented;
17361 ----------------------
17362 -- Implicit_Packing --
17363 ----------------------
17365 -- pragma Implicit_Packing;
17367 when Pragma_Implicit_Packing =>
17368 GNAT_Pragma;
17369 Check_Arg_Count (0);
17370 Implicit_Packing := True;
17372 ------------
17373 -- Import --
17374 ------------
17376 -- pragma Import (
17377 -- [Convention =>] convention_IDENTIFIER,
17378 -- [Entity =>] LOCAL_NAME
17379 -- [, [External_Name =>] static_string_EXPRESSION ]
17380 -- [, [Link_Name =>] static_string_EXPRESSION ]);
17382 when Pragma_Import =>
17383 Check_Ada_83_Warning;
17384 Check_Arg_Order
17385 ((Name_Convention,
17386 Name_Entity,
17387 Name_External_Name,
17388 Name_Link_Name));
17390 Check_At_Least_N_Arguments (2);
17391 Check_At_Most_N_Arguments (4);
17392 Process_Import_Or_Interface;
17394 ---------------------
17395 -- Import_Function --
17396 ---------------------
17398 -- pragma Import_Function (
17399 -- [Internal =>] LOCAL_NAME,
17400 -- [, [External =>] EXTERNAL_SYMBOL]
17401 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17402 -- [, [Result_Type =>] SUBTYPE_MARK]
17403 -- [, [Mechanism =>] MECHANISM]
17404 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
17406 -- EXTERNAL_SYMBOL ::=
17407 -- IDENTIFIER
17408 -- | static_string_EXPRESSION
17410 -- PARAMETER_TYPES ::=
17411 -- null
17412 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17414 -- TYPE_DESIGNATOR ::=
17415 -- subtype_NAME
17416 -- | subtype_Name ' Access
17418 -- MECHANISM ::=
17419 -- MECHANISM_NAME
17420 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17422 -- MECHANISM_ASSOCIATION ::=
17423 -- [formal_parameter_NAME =>] MECHANISM_NAME
17425 -- MECHANISM_NAME ::=
17426 -- Value
17427 -- | Reference
17429 when Pragma_Import_Function => Import_Function : declare
17430 Args : Args_List (1 .. 6);
17431 Names : constant Name_List (1 .. 6) := (
17432 Name_Internal,
17433 Name_External,
17434 Name_Parameter_Types,
17435 Name_Result_Type,
17436 Name_Mechanism,
17437 Name_Result_Mechanism);
17439 Internal : Node_Id renames Args (1);
17440 External : Node_Id renames Args (2);
17441 Parameter_Types : Node_Id renames Args (3);
17442 Result_Type : Node_Id renames Args (4);
17443 Mechanism : Node_Id renames Args (5);
17444 Result_Mechanism : Node_Id renames Args (6);
17446 begin
17447 GNAT_Pragma;
17448 Gather_Associations (Names, Args);
17449 Process_Extended_Import_Export_Subprogram_Pragma (
17450 Arg_Internal => Internal,
17451 Arg_External => External,
17452 Arg_Parameter_Types => Parameter_Types,
17453 Arg_Result_Type => Result_Type,
17454 Arg_Mechanism => Mechanism,
17455 Arg_Result_Mechanism => Result_Mechanism);
17456 end Import_Function;
17458 -------------------
17459 -- Import_Object --
17460 -------------------
17462 -- pragma Import_Object (
17463 -- [Internal =>] LOCAL_NAME
17464 -- [, [External =>] EXTERNAL_SYMBOL]
17465 -- [, [Size =>] EXTERNAL_SYMBOL]);
17467 -- EXTERNAL_SYMBOL ::=
17468 -- IDENTIFIER
17469 -- | static_string_EXPRESSION
17471 when Pragma_Import_Object => Import_Object : declare
17472 Args : Args_List (1 .. 3);
17473 Names : constant Name_List (1 .. 3) := (
17474 Name_Internal,
17475 Name_External,
17476 Name_Size);
17478 Internal : Node_Id renames Args (1);
17479 External : Node_Id renames Args (2);
17480 Size : Node_Id renames Args (3);
17482 begin
17483 GNAT_Pragma;
17484 Gather_Associations (Names, Args);
17485 Process_Extended_Import_Export_Object_Pragma (
17486 Arg_Internal => Internal,
17487 Arg_External => External,
17488 Arg_Size => Size);
17489 end Import_Object;
17491 ----------------------
17492 -- Import_Procedure --
17493 ----------------------
17495 -- pragma Import_Procedure (
17496 -- [Internal =>] LOCAL_NAME
17497 -- [, [External =>] EXTERNAL_SYMBOL]
17498 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17499 -- [, [Mechanism =>] MECHANISM]);
17501 -- EXTERNAL_SYMBOL ::=
17502 -- IDENTIFIER
17503 -- | static_string_EXPRESSION
17505 -- PARAMETER_TYPES ::=
17506 -- null
17507 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17509 -- TYPE_DESIGNATOR ::=
17510 -- subtype_NAME
17511 -- | subtype_Name ' Access
17513 -- MECHANISM ::=
17514 -- MECHANISM_NAME
17515 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17517 -- MECHANISM_ASSOCIATION ::=
17518 -- [formal_parameter_NAME =>] MECHANISM_NAME
17520 -- MECHANISM_NAME ::=
17521 -- Value
17522 -- | Reference
17524 when Pragma_Import_Procedure => Import_Procedure : declare
17525 Args : Args_List (1 .. 4);
17526 Names : constant Name_List (1 .. 4) := (
17527 Name_Internal,
17528 Name_External,
17529 Name_Parameter_Types,
17530 Name_Mechanism);
17532 Internal : Node_Id renames Args (1);
17533 External : Node_Id renames Args (2);
17534 Parameter_Types : Node_Id renames Args (3);
17535 Mechanism : Node_Id renames Args (4);
17537 begin
17538 GNAT_Pragma;
17539 Gather_Associations (Names, Args);
17540 Process_Extended_Import_Export_Subprogram_Pragma (
17541 Arg_Internal => Internal,
17542 Arg_External => External,
17543 Arg_Parameter_Types => Parameter_Types,
17544 Arg_Mechanism => Mechanism);
17545 end Import_Procedure;
17547 -----------------------------
17548 -- Import_Valued_Procedure --
17549 -----------------------------
17551 -- pragma Import_Valued_Procedure (
17552 -- [Internal =>] LOCAL_NAME
17553 -- [, [External =>] EXTERNAL_SYMBOL]
17554 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
17555 -- [, [Mechanism =>] MECHANISM]);
17557 -- EXTERNAL_SYMBOL ::=
17558 -- IDENTIFIER
17559 -- | static_string_EXPRESSION
17561 -- PARAMETER_TYPES ::=
17562 -- null
17563 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
17565 -- TYPE_DESIGNATOR ::=
17566 -- subtype_NAME
17567 -- | subtype_Name ' Access
17569 -- MECHANISM ::=
17570 -- MECHANISM_NAME
17571 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
17573 -- MECHANISM_ASSOCIATION ::=
17574 -- [formal_parameter_NAME =>] MECHANISM_NAME
17576 -- MECHANISM_NAME ::=
17577 -- Value
17578 -- | Reference
17580 when Pragma_Import_Valued_Procedure =>
17581 Import_Valued_Procedure : declare
17582 Args : Args_List (1 .. 4);
17583 Names : constant Name_List (1 .. 4) := (
17584 Name_Internal,
17585 Name_External,
17586 Name_Parameter_Types,
17587 Name_Mechanism);
17589 Internal : Node_Id renames Args (1);
17590 External : Node_Id renames Args (2);
17591 Parameter_Types : Node_Id renames Args (3);
17592 Mechanism : Node_Id renames Args (4);
17594 begin
17595 GNAT_Pragma;
17596 Gather_Associations (Names, Args);
17597 Process_Extended_Import_Export_Subprogram_Pragma (
17598 Arg_Internal => Internal,
17599 Arg_External => External,
17600 Arg_Parameter_Types => Parameter_Types,
17601 Arg_Mechanism => Mechanism);
17602 end Import_Valued_Procedure;
17604 -----------------
17605 -- Independent --
17606 -----------------
17608 -- pragma Independent (LOCAL_NAME);
17610 when Pragma_Independent =>
17611 Process_Atomic_Independent_Shared_Volatile;
17613 ----------------------------
17614 -- Independent_Components --
17615 ----------------------------
17617 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
17619 when Pragma_Independent_Components => Independent_Components : declare
17620 C : Node_Id;
17621 D : Node_Id;
17622 E_Id : Node_Id;
17623 E : Entity_Id;
17625 begin
17626 Check_Ada_83_Warning;
17627 Ada_2012_Pragma;
17628 Check_No_Identifiers;
17629 Check_Arg_Count (1);
17630 Check_Arg_Is_Local_Name (Arg1);
17631 E_Id := Get_Pragma_Arg (Arg1);
17633 if Etype (E_Id) = Any_Type then
17634 return;
17635 end if;
17637 E := Entity (E_Id);
17639 -- A record type with a self-referential component of anonymous
17640 -- access type is given an incomplete view in order to handle the
17641 -- self reference:
17643 -- type Rec is record
17644 -- Self : access Rec;
17645 -- end record;
17647 -- becomes
17649 -- type Rec;
17650 -- type Ptr is access Rec;
17651 -- type Rec is record
17652 -- Self : Ptr;
17653 -- end record;
17655 -- Since the incomplete view is now the initial view of the type,
17656 -- the argument of the pragma will reference the incomplete view,
17657 -- but this view is illegal according to the semantics of the
17658 -- pragma.
17660 -- Obtain the full view of an internally-generated incomplete type
17661 -- only. This way an attempt to associate the pragma with a source
17662 -- incomplete type is still caught.
17664 if Ekind (E) = E_Incomplete_Type
17665 and then not Comes_From_Source (E)
17666 and then Present (Full_View (E))
17667 then
17668 E := Full_View (E);
17669 end if;
17671 -- A pragma that applies to a Ghost entity becomes Ghost for the
17672 -- purposes of legality checks and removal of ignored Ghost code.
17674 Mark_Ghost_Pragma (N, E);
17676 -- Check duplicate before we chain ourselves
17678 Check_Duplicate_Pragma (E);
17680 -- Check appropriate entity
17682 if Rep_Item_Too_Early (E, N)
17683 or else
17684 Rep_Item_Too_Late (E, N)
17685 then
17686 return;
17687 end if;
17689 D := Declaration_Node (E);
17691 -- The flag is set on the base type, or on the object
17693 if Nkind (D) = N_Full_Type_Declaration
17694 and then (Is_Array_Type (E) or else Is_Record_Type (E))
17695 then
17696 Set_Has_Independent_Components (Base_Type (E));
17697 Record_Independence_Check (N, Base_Type (E));
17699 -- For record type, set all components independent
17701 if Is_Record_Type (E) then
17702 C := First_Component (E);
17703 while Present (C) loop
17704 Set_Is_Independent (C);
17705 Next_Component (C);
17706 end loop;
17707 end if;
17709 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
17710 and then Nkind (D) = N_Object_Declaration
17711 and then Nkind (Object_Definition (D)) =
17712 N_Constrained_Array_Definition
17713 then
17714 Set_Has_Independent_Components (E);
17715 Record_Independence_Check (N, E);
17717 else
17718 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
17719 end if;
17720 end Independent_Components;
17722 -----------------------
17723 -- Initial_Condition --
17724 -----------------------
17726 -- pragma Initial_Condition (boolean_EXPRESSION);
17728 -- Characteristics:
17730 -- * Analysis - The annotation undergoes initial checks to verify
17731 -- the legal placement and context. Secondary checks preanalyze the
17732 -- expression in:
17734 -- Analyze_Initial_Condition_In_Decl_Part
17736 -- * Expansion - The annotation is expanded during the expansion of
17737 -- the package body whose declaration is subject to the annotation
17738 -- as done in:
17740 -- Expand_Pragma_Initial_Condition
17742 -- * Template - The annotation utilizes the generic template of the
17743 -- related package declaration.
17745 -- * Globals - Capture of global references must occur after full
17746 -- analysis.
17748 -- * Instance - The annotation is instantiated automatically when
17749 -- the related generic package is instantiated.
17751 when Pragma_Initial_Condition => Initial_Condition : declare
17752 Pack_Decl : Node_Id;
17753 Pack_Id : Entity_Id;
17755 begin
17756 GNAT_Pragma;
17757 Check_No_Identifiers;
17758 Check_Arg_Count (1);
17760 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
17762 if Nkind (Pack_Decl) not in
17763 N_Generic_Package_Declaration | N_Package_Declaration
17764 then
17765 Pragma_Misplaced;
17766 return;
17767 end if;
17769 Pack_Id := Defining_Entity (Pack_Decl);
17771 -- A pragma that applies to a Ghost entity becomes Ghost for the
17772 -- purposes of legality checks and removal of ignored Ghost code.
17774 Mark_Ghost_Pragma (N, Pack_Id);
17776 -- Chain the pragma on the contract for further processing by
17777 -- Analyze_Initial_Condition_In_Decl_Part.
17779 Add_Contract_Item (N, Pack_Id);
17781 -- The legality checks of pragmas Abstract_State, Initializes, and
17782 -- Initial_Condition are affected by the SPARK mode in effect. In
17783 -- addition, these three pragmas are subject to an inherent order:
17785 -- 1) Abstract_State
17786 -- 2) Initializes
17787 -- 3) Initial_Condition
17789 -- Analyze all these pragmas in the order outlined above
17791 Analyze_If_Present (Pragma_SPARK_Mode);
17792 Analyze_If_Present (Pragma_Abstract_State);
17793 Analyze_If_Present (Pragma_Initializes);
17794 end Initial_Condition;
17796 ------------------------
17797 -- Initialize_Scalars --
17798 ------------------------
17800 -- pragma Initialize_Scalars
17801 -- [ ( TYPE_VALUE_PAIR {, TYPE_VALUE_PAIR} ) ];
17803 -- TYPE_VALUE_PAIR ::=
17804 -- SCALAR_TYPE => static_EXPRESSION
17806 -- SCALAR_TYPE :=
17807 -- Short_Float
17808 -- | Float
17809 -- | Long_Float
17810 -- | Long_Long_Flat
17811 -- | Signed_8
17812 -- | Signed_16
17813 -- | Signed_32
17814 -- | Signed_64
17815 -- | Unsigned_8
17816 -- | Unsigned_16
17817 -- | Unsigned_32
17818 -- | Unsigned_64
17820 when Pragma_Initialize_Scalars => Do_Initialize_Scalars : declare
17821 Seen : array (Scalar_Id) of Node_Id := (others => Empty);
17822 -- This collection holds the individual pairs which specify the
17823 -- invalid values of their respective scalar types.
17825 procedure Analyze_Float_Value
17826 (Scal_Typ : Float_Scalar_Id;
17827 Val_Expr : Node_Id);
17828 -- Analyze a type value pair associated with float type Scal_Typ
17829 -- and expression Val_Expr.
17831 procedure Analyze_Integer_Value
17832 (Scal_Typ : Integer_Scalar_Id;
17833 Val_Expr : Node_Id);
17834 -- Analyze a type value pair associated with integer type Scal_Typ
17835 -- and expression Val_Expr.
17837 procedure Analyze_Type_Value_Pair (Pair : Node_Id);
17838 -- Analyze type value pair Pair
17840 -------------------------
17841 -- Analyze_Float_Value --
17842 -------------------------
17844 procedure Analyze_Float_Value
17845 (Scal_Typ : Float_Scalar_Id;
17846 Val_Expr : Node_Id)
17848 begin
17849 Analyze_And_Resolve (Val_Expr, Any_Real);
17851 if Is_OK_Static_Expression (Val_Expr) then
17852 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value_R (Val_Expr));
17854 else
17855 Error_Msg_Name_1 := Scal_Typ;
17856 Error_Msg_N ("value for type % must be static", Val_Expr);
17857 end if;
17858 end Analyze_Float_Value;
17860 ---------------------------
17861 -- Analyze_Integer_Value --
17862 ---------------------------
17864 procedure Analyze_Integer_Value
17865 (Scal_Typ : Integer_Scalar_Id;
17866 Val_Expr : Node_Id)
17868 begin
17869 Analyze_And_Resolve (Val_Expr, Any_Integer);
17871 if Is_OK_Static_Expression (Val_Expr) then
17872 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value (Val_Expr));
17874 else
17875 Error_Msg_Name_1 := Scal_Typ;
17876 Error_Msg_N ("value for type % must be static", Val_Expr);
17877 end if;
17878 end Analyze_Integer_Value;
17880 -----------------------------
17881 -- Analyze_Type_Value_Pair --
17882 -----------------------------
17884 procedure Analyze_Type_Value_Pair (Pair : Node_Id) is
17885 Scal_Typ : constant Name_Id := Chars (Pair);
17886 Val_Expr : constant Node_Id := Expression (Pair);
17887 Prev_Pair : Node_Id;
17889 begin
17890 if Scal_Typ in Scalar_Id then
17891 Prev_Pair := Seen (Scal_Typ);
17893 -- Prevent multiple attempts to set a value for a scalar
17894 -- type.
17896 if Present (Prev_Pair) then
17897 Error_Msg_Name_1 := Scal_Typ;
17898 Error_Msg_N
17899 ("cannot specify multiple invalid values for type %",
17900 Pair);
17902 Error_Msg_Sloc := Sloc (Prev_Pair);
17903 Error_Msg_N ("previous value set #", Pair);
17905 -- Ignore the effects of the pair, but do not halt the
17906 -- analysis of the pragma altogether.
17908 return;
17910 -- Otherwise capture the first pair for this scalar type
17912 else
17913 Seen (Scal_Typ) := Pair;
17914 end if;
17916 if Scal_Typ in Float_Scalar_Id then
17917 Analyze_Float_Value (Scal_Typ, Val_Expr);
17919 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
17920 Analyze_Integer_Value (Scal_Typ, Val_Expr);
17921 end if;
17923 -- Otherwise the scalar family is illegal
17925 else
17926 Error_Msg_Name_1 := Pname;
17927 Error_Msg_N
17928 ("argument of pragma % must denote valid scalar family",
17929 Pair);
17930 end if;
17931 end Analyze_Type_Value_Pair;
17933 -- Local variables
17935 Pairs : constant List_Id := Pragma_Argument_Associations (N);
17936 Pair : Node_Id;
17938 -- Start of processing for Do_Initialize_Scalars
17940 begin
17941 GNAT_Pragma;
17942 Check_Valid_Configuration_Pragma;
17943 Check_Restriction (No_Initialize_Scalars, N);
17945 -- Ignore the effects of the pragma when No_Initialize_Scalars is
17946 -- in effect.
17948 if Restriction_Active (No_Initialize_Scalars) then
17949 null;
17951 -- Initialize_Scalars creates false positives in CodePeer, and
17952 -- incorrect negative results in GNATprove mode, so ignore this
17953 -- pragma in these modes.
17955 elsif CodePeer_Mode or GNATprove_Mode then
17956 null;
17958 -- Otherwise analyze the pragma
17960 else
17961 if Present (Pairs) then
17963 -- Install Standard in order to provide access to primitive
17964 -- types in case the expressions contain attributes such as
17965 -- Integer'Last.
17967 Push_Scope (Standard_Standard);
17969 Pair := First (Pairs);
17970 while Present (Pair) loop
17971 Analyze_Type_Value_Pair (Pair);
17972 Next (Pair);
17973 end loop;
17975 -- Remove Standard
17977 Pop_Scope;
17978 end if;
17980 Init_Or_Norm_Scalars := True;
17981 Initialize_Scalars := True;
17982 end if;
17983 end Do_Initialize_Scalars;
17985 -----------------
17986 -- Initializes --
17987 -----------------
17989 -- pragma Initializes (INITIALIZATION_LIST);
17991 -- INITIALIZATION_LIST ::=
17992 -- null
17993 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
17995 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
17997 -- INPUT_LIST ::=
17998 -- null
17999 -- | INPUT
18000 -- | (INPUT {, INPUT})
18002 -- INPUT ::= name
18004 -- Characteristics:
18006 -- * Analysis - The annotation undergoes initial checks to verify
18007 -- the legal placement and context. Secondary checks preanalyze the
18008 -- expression in:
18010 -- Analyze_Initializes_In_Decl_Part
18012 -- * Expansion - None.
18014 -- * Template - The annotation utilizes the generic template of the
18015 -- related package declaration.
18017 -- * Globals - Capture of global references must occur after full
18018 -- analysis.
18020 -- * Instance - The annotation is instantiated automatically when
18021 -- the related generic package is instantiated.
18023 when Pragma_Initializes => Initializes : declare
18024 Pack_Decl : Node_Id;
18025 Pack_Id : Entity_Id;
18027 begin
18028 GNAT_Pragma;
18029 Check_No_Identifiers;
18030 Check_Arg_Count (1);
18032 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
18034 if Nkind (Pack_Decl) not in
18035 N_Generic_Package_Declaration | N_Package_Declaration
18036 then
18037 Pragma_Misplaced;
18038 return;
18039 end if;
18041 Pack_Id := Defining_Entity (Pack_Decl);
18043 -- A pragma that applies to a Ghost entity becomes Ghost for the
18044 -- purposes of legality checks and removal of ignored Ghost code.
18046 Mark_Ghost_Pragma (N, Pack_Id);
18047 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
18049 -- Chain the pragma on the contract for further processing by
18050 -- Analyze_Initializes_In_Decl_Part.
18052 Add_Contract_Item (N, Pack_Id);
18054 -- The legality checks of pragmas Abstract_State, Initializes, and
18055 -- Initial_Condition are affected by the SPARK mode in effect. In
18056 -- addition, these three pragmas are subject to an inherent order:
18058 -- 1) Abstract_State
18059 -- 2) Initializes
18060 -- 3) Initial_Condition
18062 -- Analyze all these pragmas in the order outlined above
18064 Analyze_If_Present (Pragma_SPARK_Mode);
18065 Analyze_If_Present (Pragma_Abstract_State);
18066 Analyze_If_Present (Pragma_Initial_Condition);
18067 end Initializes;
18069 ------------
18070 -- Inline --
18071 ------------
18073 -- pragma Inline ( NAME {, NAME} );
18075 when Pragma_Inline =>
18077 -- Pragma always active unless in GNATprove mode. It is disabled
18078 -- in GNATprove mode because frontend inlining is applied
18079 -- independently of pragmas Inline and Inline_Always for
18080 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
18081 -- in inline.ads.
18083 if not GNATprove_Mode then
18085 -- Inline status is Enabled if option -gnatn is specified.
18086 -- However this status determines only the value of the
18087 -- Is_Inlined flag on the subprogram and does not prevent
18088 -- the pragma itself from being recorded for later use,
18089 -- in particular for a later modification of Is_Inlined
18090 -- independently of the -gnatn option.
18092 -- In other words, if -gnatn is specified for a unit, then
18093 -- all Inline pragmas processed for the compilation of this
18094 -- unit, including those in the spec of other units, are
18095 -- activated, so subprograms will be inlined across units.
18097 -- If -gnatn is not specified, no Inline pragma is activated
18098 -- here, which means that subprograms will not be inlined
18099 -- across units. The Is_Inlined flag will nevertheless be
18100 -- set later when bodies are analyzed, so subprograms will
18101 -- be inlined within the unit.
18103 if Inline_Active then
18104 Process_Inline (Enabled);
18105 else
18106 Process_Inline (Disabled);
18107 end if;
18108 end if;
18110 -------------------
18111 -- Inline_Always --
18112 -------------------
18114 -- pragma Inline_Always ( NAME {, NAME} );
18116 when Pragma_Inline_Always =>
18117 GNAT_Pragma;
18119 -- Pragma always active unless in CodePeer mode or GNATprove
18120 -- mode. It is disabled in CodePeer mode because inlining is
18121 -- not helpful, and enabling it caused walk order issues. It
18122 -- is disabled in GNATprove mode because frontend inlining is
18123 -- applied independently of pragmas Inline and Inline_Always for
18124 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
18125 -- inline.ads.
18127 if not CodePeer_Mode and not GNATprove_Mode then
18128 Process_Inline (Enabled);
18129 end if;
18131 --------------------
18132 -- Inline_Generic --
18133 --------------------
18135 -- pragma Inline_Generic (NAME {, NAME});
18137 when Pragma_Inline_Generic =>
18138 GNAT_Pragma;
18139 Process_Generic_List;
18141 ----------------------
18142 -- Inspection_Point --
18143 ----------------------
18145 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
18147 when Pragma_Inspection_Point => Inspection_Point : declare
18148 Arg : Node_Id;
18149 Exp : Node_Id;
18151 begin
18154 if Arg_Count > 0 then
18155 Arg := Arg1;
18156 loop
18157 Exp := Get_Pragma_Arg (Arg);
18158 Analyze (Exp);
18160 if not Is_Entity_Name (Exp)
18161 or else not Is_Object (Entity (Exp))
18162 then
18163 Error_Pragma_Arg ("object name required", Arg);
18164 end if;
18166 Next (Arg);
18167 exit when No (Arg);
18168 end loop;
18169 end if;
18170 end Inspection_Point;
18172 ---------------
18173 -- Interface --
18174 ---------------
18176 -- pragma Interface (
18177 -- [ Convention =>] convention_IDENTIFIER,
18178 -- [ Entity =>] LOCAL_NAME
18179 -- [, [External_Name =>] static_string_EXPRESSION ]
18180 -- [, [Link_Name =>] static_string_EXPRESSION ]);
18182 when Pragma_Interface =>
18183 GNAT_Pragma;
18184 Check_Arg_Order
18185 ((Name_Convention,
18186 Name_Entity,
18187 Name_External_Name,
18188 Name_Link_Name));
18189 Check_At_Least_N_Arguments (2);
18190 Check_At_Most_N_Arguments (4);
18191 Process_Import_Or_Interface;
18193 -- In Ada 2005, the permission to use Interface (a reserved word)
18194 -- as a pragma name is considered an obsolescent feature, and this
18195 -- pragma was already obsolescent in Ada 95.
18197 if Ada_Version >= Ada_95 then
18198 Check_Restriction
18199 (No_Obsolescent_Features, Pragma_Identifier (N));
18201 if Warn_On_Obsolescent_Feature then
18202 Error_Msg_N
18203 ("pragma Interface is an obsolescent feature?j?", N);
18204 Error_Msg_N
18205 ("|use pragma Import instead?j?", N);
18206 end if;
18207 end if;
18209 --------------------
18210 -- Interface_Name --
18211 --------------------
18213 -- pragma Interface_Name (
18214 -- [ Entity =>] LOCAL_NAME
18215 -- [,[External_Name =>] static_string_EXPRESSION ]
18216 -- [,[Link_Name =>] static_string_EXPRESSION ]);
18218 when Pragma_Interface_Name => Interface_Name : declare
18219 Id : Node_Id;
18220 Def_Id : Entity_Id;
18221 Hom_Id : Entity_Id;
18222 Found : Boolean;
18224 begin
18225 GNAT_Pragma;
18226 Check_Arg_Order
18227 ((Name_Entity, Name_External_Name, Name_Link_Name));
18228 Check_At_Least_N_Arguments (2);
18229 Check_At_Most_N_Arguments (3);
18230 Id := Get_Pragma_Arg (Arg1);
18231 Analyze (Id);
18233 -- This is obsolete from Ada 95 on, but it is an implementation
18234 -- defined pragma, so we do not consider that it violates the
18235 -- restriction (No_Obsolescent_Features).
18237 if Ada_Version >= Ada_95 then
18238 if Warn_On_Obsolescent_Feature then
18239 Error_Msg_N
18240 ("pragma Interface_Name is an obsolescent feature?j?", N);
18241 Error_Msg_N
18242 ("|use pragma Import instead?j?", N);
18243 end if;
18244 end if;
18246 if not Is_Entity_Name (Id) then
18247 Error_Pragma_Arg
18248 ("first argument for pragma% must be entity name", Arg1);
18249 elsif Etype (Id) = Any_Type then
18250 return;
18251 else
18252 Def_Id := Entity (Id);
18253 end if;
18255 -- Special DEC-compatible processing for the object case, forces
18256 -- object to be imported.
18258 if Ekind (Def_Id) = E_Variable then
18259 Kill_Size_Check_Code (Def_Id);
18260 Note_Possible_Modification (Id, Sure => False);
18262 -- Initialization is not allowed for imported variable
18264 if Present (Expression (Parent (Def_Id)))
18265 and then Comes_From_Source (Expression (Parent (Def_Id)))
18266 then
18267 Error_Msg_Sloc := Sloc (Def_Id);
18268 Error_Pragma_Arg
18269 ("no initialization allowed for declaration of& #",
18270 Arg2);
18272 else
18273 -- For compatibility, support VADS usage of providing both
18274 -- pragmas Interface and Interface_Name to obtain the effect
18275 -- of a single Import pragma.
18277 if Is_Imported (Def_Id)
18278 and then Present (First_Rep_Item (Def_Id))
18279 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
18280 and then Pragma_Name (First_Rep_Item (Def_Id)) =
18281 Name_Interface
18282 then
18283 null;
18284 else
18285 Set_Imported (Def_Id);
18286 end if;
18288 Set_Is_Public (Def_Id);
18289 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
18290 end if;
18292 -- Otherwise must be subprogram
18294 elsif not Is_Subprogram (Def_Id) then
18295 Error_Pragma_Arg
18296 ("argument of pragma% is not subprogram", Arg1);
18298 else
18299 Check_At_Most_N_Arguments (3);
18300 Hom_Id := Def_Id;
18301 Found := False;
18303 -- Loop through homonyms
18305 loop
18306 Def_Id := Get_Base_Subprogram (Hom_Id);
18308 if Is_Imported (Def_Id) then
18309 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
18310 Found := True;
18311 end if;
18313 exit when From_Aspect_Specification (N);
18314 Hom_Id := Homonym (Hom_Id);
18316 exit when No (Hom_Id)
18317 or else Scope (Hom_Id) /= Current_Scope;
18318 end loop;
18320 if not Found then
18321 Error_Pragma_Arg
18322 ("argument of pragma% is not imported subprogram",
18323 Arg1);
18324 end if;
18325 end if;
18326 end Interface_Name;
18328 -----------------------
18329 -- Interrupt_Handler --
18330 -----------------------
18332 -- pragma Interrupt_Handler (handler_NAME);
18334 when Pragma_Interrupt_Handler =>
18335 Check_Ada_83_Warning;
18336 Check_Arg_Count (1);
18337 Check_No_Identifiers;
18339 if No_Run_Time_Mode then
18340 Error_Msg_CRT ("Interrupt_Handler pragma", N);
18341 else
18342 Check_Interrupt_Or_Attach_Handler;
18343 Process_Interrupt_Or_Attach_Handler;
18344 end if;
18346 ------------------------
18347 -- Interrupt_Priority --
18348 ------------------------
18350 -- pragma Interrupt_Priority [(EXPRESSION)];
18352 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
18353 P : constant Node_Id := Parent (N);
18354 Arg : Node_Id;
18355 Ent : Entity_Id;
18357 begin
18358 Check_Ada_83_Warning;
18360 if Arg_Count /= 0 then
18361 Arg := Get_Pragma_Arg (Arg1);
18362 Check_Arg_Count (1);
18363 Check_No_Identifiers;
18365 -- The expression must be analyzed in the special manner
18366 -- described in "Handling of Default and Per-Object
18367 -- Expressions" in sem.ads.
18369 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
18370 end if;
18372 if Nkind (P) not in N_Task_Definition | N_Protected_Definition then
18373 Pragma_Misplaced;
18374 return;
18376 else
18377 Ent := Defining_Identifier (Parent (P));
18379 -- Check duplicate pragma before we chain the pragma in the Rep
18380 -- Item chain of Ent.
18382 Check_Duplicate_Pragma (Ent);
18383 Record_Rep_Item (Ent, N);
18385 -- Check the No_Task_At_Interrupt_Priority restriction
18387 if Nkind (P) = N_Task_Definition then
18388 Check_Restriction (No_Task_At_Interrupt_Priority, N);
18389 end if;
18390 end if;
18391 end Interrupt_Priority;
18393 ---------------------
18394 -- Interrupt_State --
18395 ---------------------
18397 -- pragma Interrupt_State (
18398 -- [Name =>] INTERRUPT_ID,
18399 -- [State =>] INTERRUPT_STATE);
18401 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
18402 -- INTERRUPT_STATE => System | Runtime | User
18404 -- Note: if the interrupt id is given as an identifier, then it must
18405 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
18406 -- given as a static integer expression which must be in the range of
18407 -- Ada.Interrupts.Interrupt_ID.
18409 when Pragma_Interrupt_State => Interrupt_State : declare
18410 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
18411 -- This is the entity Ada.Interrupts.Interrupt_ID;
18413 State_Type : Character;
18414 -- Set to 's'/'r'/'u' for System/Runtime/User
18416 IST_Num : Pos;
18417 -- Index to entry in Interrupt_States table
18419 Int_Val : Uint;
18420 -- Value of interrupt
18422 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
18423 -- The first argument to the pragma
18425 Int_Ent : Entity_Id;
18426 -- Interrupt entity in Ada.Interrupts.Names
18428 begin
18429 GNAT_Pragma;
18430 Check_Arg_Order ((Name_Name, Name_State));
18431 Check_Arg_Count (2);
18433 Check_Optional_Identifier (Arg1, Name_Name);
18434 Check_Optional_Identifier (Arg2, Name_State);
18435 Check_Arg_Is_Identifier (Arg2);
18437 -- First argument is identifier
18439 if Nkind (Arg1X) = N_Identifier then
18441 -- Search list of names in Ada.Interrupts.Names
18443 Int_Ent := First_Entity (RTE (RE_Names));
18444 loop
18445 if No (Int_Ent) then
18446 Error_Pragma_Arg ("invalid interrupt name", Arg1);
18448 elsif Chars (Int_Ent) = Chars (Arg1X) then
18449 Int_Val := Expr_Value (Constant_Value (Int_Ent));
18450 exit;
18451 end if;
18453 Next_Entity (Int_Ent);
18454 end loop;
18456 -- First argument is not an identifier, so it must be a static
18457 -- expression of type Ada.Interrupts.Interrupt_ID.
18459 else
18460 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
18461 Int_Val := Expr_Value (Arg1X);
18463 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
18464 or else
18465 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
18466 then
18467 Error_Pragma_Arg
18468 ("value not in range of type "
18469 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
18470 end if;
18471 end if;
18473 -- Check OK state
18475 case Chars (Get_Pragma_Arg (Arg2)) is
18476 when Name_Runtime => State_Type := 'r';
18477 when Name_System => State_Type := 's';
18478 when Name_User => State_Type := 'u';
18480 when others =>
18481 Error_Pragma_Arg ("invalid interrupt state", Arg2);
18482 end case;
18484 -- Check if entry is already stored
18486 IST_Num := Interrupt_States.First;
18487 loop
18488 -- If entry not found, add it
18490 if IST_Num > Interrupt_States.Last then
18491 Interrupt_States.Append
18492 ((Interrupt_Number => UI_To_Int (Int_Val),
18493 Interrupt_State => State_Type,
18494 Pragma_Loc => Loc));
18495 exit;
18497 -- Case of entry for the same entry
18499 elsif Int_Val = Interrupt_States.Table (IST_Num).
18500 Interrupt_Number
18501 then
18502 -- If state matches, done, no need to make redundant entry
18504 exit when
18505 State_Type = Interrupt_States.Table (IST_Num).
18506 Interrupt_State;
18508 -- Otherwise if state does not match, error
18510 Error_Msg_Sloc :=
18511 Interrupt_States.Table (IST_Num).Pragma_Loc;
18512 Error_Pragma_Arg
18513 ("state conflicts with that given #", Arg2);
18514 exit;
18515 end if;
18517 IST_Num := IST_Num + 1;
18518 end loop;
18519 end Interrupt_State;
18521 ---------------
18522 -- Invariant --
18523 ---------------
18525 -- pragma Invariant
18526 -- ([Entity =>] type_LOCAL_NAME,
18527 -- [Check =>] EXPRESSION
18528 -- [,[Message =>] String_Expression]);
18530 when Pragma_Invariant => Invariant : declare
18531 Discard : Boolean;
18532 Typ : Entity_Id;
18533 Typ_Arg : Node_Id;
18535 begin
18536 GNAT_Pragma;
18537 Check_At_Least_N_Arguments (2);
18538 Check_At_Most_N_Arguments (3);
18539 Check_Optional_Identifier (Arg1, Name_Entity);
18540 Check_Optional_Identifier (Arg2, Name_Check);
18542 if Arg_Count = 3 then
18543 Check_Optional_Identifier (Arg3, Name_Message);
18544 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
18545 end if;
18547 Check_Arg_Is_Local_Name (Arg1);
18549 Typ_Arg := Get_Pragma_Arg (Arg1);
18550 Find_Type (Typ_Arg);
18551 Typ := Entity (Typ_Arg);
18553 -- Nothing to do of the related type is erroneous in some way
18555 if Typ = Any_Type then
18556 return;
18558 -- AI12-0041: Invariants are allowed in interface types
18560 elsif Is_Interface (Typ) then
18561 null;
18563 -- An invariant must apply to a private type, or appear in the
18564 -- private part of a package spec and apply to a completion.
18565 -- a class-wide invariant can only appear on a private declaration
18566 -- or private extension, not a completion.
18568 -- A [class-wide] invariant may be associated a [limited] private
18569 -- type or a private extension.
18571 elsif Ekind (Typ) in E_Limited_Private_Type
18572 | E_Private_Type
18573 | E_Record_Type_With_Private
18574 then
18575 null;
18577 -- A non-class-wide invariant may be associated with the full view
18578 -- of a [limited] private type or a private extension.
18580 elsif Has_Private_Declaration (Typ)
18581 and then not Class_Present (N)
18582 then
18583 null;
18585 -- A class-wide invariant may appear on the partial view only
18587 elsif Class_Present (N) then
18588 Error_Pragma_Arg
18589 ("pragma % only allowed for private type", Arg1);
18590 return;
18592 -- A regular invariant may appear on both views
18594 else
18595 Error_Pragma_Arg
18596 ("pragma % only allowed for private type or corresponding "
18597 & "full view", Arg1);
18598 return;
18599 end if;
18601 -- An invariant associated with an abstract type (this includes
18602 -- interfaces) must be class-wide.
18604 if Is_Abstract_Type (Typ) and then not Class_Present (N) then
18605 Error_Pragma_Arg
18606 ("pragma % not allowed for abstract type", Arg1);
18607 return;
18608 end if;
18610 -- A pragma that applies to a Ghost entity becomes Ghost for the
18611 -- purposes of legality checks and removal of ignored Ghost code.
18613 Mark_Ghost_Pragma (N, Typ);
18615 -- The pragma defines a type-specific invariant, the type is said
18616 -- to have invariants of its "own".
18618 Set_Has_Own_Invariants (Typ);
18620 -- If the invariant is class-wide, then it can be inherited by
18621 -- derived or interface implementing types. The type is said to
18622 -- have "inheritable" invariants.
18624 if Class_Present (N) then
18625 Set_Has_Inheritable_Invariants (Typ);
18626 end if;
18628 -- Chain the pragma on to the rep item chain, for processing when
18629 -- the type is frozen.
18631 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
18633 -- Create the declaration of the invariant procedure that will
18634 -- verify the invariant at run time. Interfaces are treated as the
18635 -- partial view of a private type in order to achieve uniformity
18636 -- with the general case. As a result, an interface receives only
18637 -- a "partial" invariant procedure, which is never called.
18639 Build_Invariant_Procedure_Declaration
18640 (Typ => Typ,
18641 Partial_Invariant => Is_Interface (Typ));
18642 end Invariant;
18644 ----------------
18645 -- Keep_Names --
18646 ----------------
18648 -- pragma Keep_Names ([On => ] LOCAL_NAME);
18650 when Pragma_Keep_Names => Keep_Names : declare
18651 Arg : Node_Id;
18653 begin
18654 GNAT_Pragma;
18655 Check_Arg_Count (1);
18656 Check_Optional_Identifier (Arg1, Name_On);
18657 Check_Arg_Is_Local_Name (Arg1);
18659 Arg := Get_Pragma_Arg (Arg1);
18660 Analyze (Arg);
18662 if Etype (Arg) = Any_Type then
18663 return;
18664 end if;
18666 if not Is_Entity_Name (Arg)
18667 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
18668 then
18669 Error_Pragma_Arg
18670 ("pragma% requires a local enumeration type", Arg1);
18671 end if;
18673 Set_Discard_Names (Entity (Arg), False);
18674 end Keep_Names;
18676 -------------
18677 -- License --
18678 -------------
18680 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
18682 when Pragma_License =>
18683 GNAT_Pragma;
18685 -- Do not analyze pragma any further in CodePeer mode, to avoid
18686 -- extraneous errors in this implementation-dependent pragma,
18687 -- which has a different profile on other compilers.
18689 if CodePeer_Mode then
18690 return;
18691 end if;
18693 Check_Arg_Count (1);
18694 Check_No_Identifiers;
18695 Check_Valid_Configuration_Pragma;
18696 Check_Arg_Is_Identifier (Arg1);
18698 declare
18699 Sind : constant Source_File_Index :=
18700 Source_Index (Current_Sem_Unit);
18702 begin
18703 case Chars (Get_Pragma_Arg (Arg1)) is
18704 when Name_GPL =>
18705 Set_License (Sind, GPL);
18707 when Name_Modified_GPL =>
18708 Set_License (Sind, Modified_GPL);
18710 when Name_Restricted =>
18711 Set_License (Sind, Restricted);
18713 when Name_Unrestricted =>
18714 Set_License (Sind, Unrestricted);
18716 when others =>
18717 Error_Pragma_Arg ("invalid license name", Arg1);
18718 end case;
18719 end;
18721 ---------------
18722 -- Link_With --
18723 ---------------
18725 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
18727 when Pragma_Link_With => Link_With : declare
18728 Arg : Node_Id;
18730 begin
18731 GNAT_Pragma;
18733 if Operating_Mode = Generate_Code
18734 and then In_Extended_Main_Source_Unit (N)
18735 then
18736 Check_At_Least_N_Arguments (1);
18737 Check_No_Identifiers;
18738 Check_Is_In_Decl_Part_Or_Package_Spec;
18739 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
18740 Start_String;
18742 Arg := Arg1;
18743 while Present (Arg) loop
18744 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
18746 -- Store argument, converting sequences of spaces to a
18747 -- single null character (this is one of the differences
18748 -- in processing between Link_With and Linker_Options).
18750 Arg_Store : declare
18751 C : constant Char_Code := Get_Char_Code (' ');
18752 S : constant String_Id :=
18753 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
18754 L : constant Nat := String_Length (S);
18755 F : Nat := 1;
18757 procedure Skip_Spaces;
18758 -- Advance F past any spaces
18760 -----------------
18761 -- Skip_Spaces --
18762 -----------------
18764 procedure Skip_Spaces is
18765 begin
18766 while F <= L and then Get_String_Char (S, F) = C loop
18767 F := F + 1;
18768 end loop;
18769 end Skip_Spaces;
18771 -- Start of processing for Arg_Store
18773 begin
18774 Skip_Spaces; -- skip leading spaces
18776 -- Loop through characters, changing any embedded
18777 -- sequence of spaces to a single null character (this
18778 -- is how Link_With/Linker_Options differ)
18780 while F <= L loop
18781 if Get_String_Char (S, F) = C then
18782 Skip_Spaces;
18783 exit when F > L;
18784 Store_String_Char (ASCII.NUL);
18786 else
18787 Store_String_Char (Get_String_Char (S, F));
18788 F := F + 1;
18789 end if;
18790 end loop;
18791 end Arg_Store;
18793 Arg := Next (Arg);
18795 if Present (Arg) then
18796 Store_String_Char (ASCII.NUL);
18797 end if;
18798 end loop;
18800 Store_Linker_Option_String (End_String);
18801 end if;
18802 end Link_With;
18804 ------------------
18805 -- Linker_Alias --
18806 ------------------
18808 -- pragma Linker_Alias (
18809 -- [Entity =>] LOCAL_NAME
18810 -- [Target =>] static_string_EXPRESSION);
18812 when Pragma_Linker_Alias =>
18813 GNAT_Pragma;
18814 Check_Arg_Order ((Name_Entity, Name_Target));
18815 Check_Arg_Count (2);
18816 Check_Optional_Identifier (Arg1, Name_Entity);
18817 Check_Optional_Identifier (Arg2, Name_Target);
18818 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18819 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
18821 -- The only processing required is to link this item on to the
18822 -- list of rep items for the given entity. This is accomplished
18823 -- by the call to Rep_Item_Too_Late (when no error is detected
18824 -- and False is returned).
18826 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
18827 return;
18828 else
18829 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
18830 end if;
18832 ------------------------
18833 -- Linker_Constructor --
18834 ------------------------
18836 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
18838 -- Code is shared with Linker_Destructor
18840 -----------------------
18841 -- Linker_Destructor --
18842 -----------------------
18844 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
18846 when Pragma_Linker_Constructor
18847 | Pragma_Linker_Destructor
18849 Linker_Constructor : declare
18850 Arg1_X : Node_Id;
18851 Proc : Entity_Id;
18853 begin
18854 GNAT_Pragma;
18855 Check_Arg_Count (1);
18856 Check_No_Identifiers;
18857 Check_Arg_Is_Local_Name (Arg1);
18858 Arg1_X := Get_Pragma_Arg (Arg1);
18859 Analyze (Arg1_X);
18860 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
18862 if not Is_Library_Level_Entity (Proc) then
18863 Error_Pragma_Arg
18864 ("argument for pragma% must be library level entity", Arg1);
18865 end if;
18867 -- The only processing required is to link this item on to the
18868 -- list of rep items for the given entity. This is accomplished
18869 -- by the call to Rep_Item_Too_Late (when no error is detected
18870 -- and False is returned).
18872 if Rep_Item_Too_Late (Proc, N) then
18873 return;
18874 else
18875 Set_Has_Gigi_Rep_Item (Proc);
18876 end if;
18877 end Linker_Constructor;
18879 --------------------
18880 -- Linker_Options --
18881 --------------------
18883 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
18885 when Pragma_Linker_Options => Linker_Options : declare
18886 Arg : Node_Id;
18888 begin
18889 Check_Ada_83_Warning;
18890 Check_No_Identifiers;
18891 Check_Arg_Count (1);
18892 Check_Is_In_Decl_Part_Or_Package_Spec;
18893 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
18894 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
18896 Arg := Arg2;
18897 while Present (Arg) loop
18898 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
18899 Store_String_Char (ASCII.NUL);
18900 Store_String_Chars
18901 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
18902 Arg := Next (Arg);
18903 end loop;
18905 if Operating_Mode = Generate_Code
18906 and then In_Extended_Main_Source_Unit (N)
18907 then
18908 Store_Linker_Option_String (End_String);
18909 end if;
18910 end Linker_Options;
18912 --------------------
18913 -- Linker_Section --
18914 --------------------
18916 -- pragma Linker_Section (
18917 -- [Entity =>] LOCAL_NAME
18918 -- [Section =>] static_string_EXPRESSION);
18920 when Pragma_Linker_Section => Linker_Section : declare
18921 Arg : Node_Id;
18922 Ent : Entity_Id;
18923 LPE : Node_Id;
18925 Ghost_Error_Posted : Boolean := False;
18926 -- Flag set when an error concerning the illegal mix of Ghost and
18927 -- non-Ghost subprograms is emitted.
18929 Ghost_Id : Entity_Id := Empty;
18930 -- The entity of the first Ghost subprogram encountered while
18931 -- processing the arguments of the pragma.
18933 begin
18934 GNAT_Pragma;
18935 Check_Arg_Order ((Name_Entity, Name_Section));
18936 Check_Arg_Count (2);
18937 Check_Optional_Identifier (Arg1, Name_Entity);
18938 Check_Optional_Identifier (Arg2, Name_Section);
18939 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18940 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
18942 -- Check kind of entity
18944 Arg := Get_Pragma_Arg (Arg1);
18945 Ent := Entity (Arg);
18947 case Ekind (Ent) is
18949 -- Objects (constants and variables) and types. For these cases
18950 -- all we need to do is to set the Linker_Section_pragma field,
18951 -- checking that we do not have a duplicate.
18953 when Type_Kind
18954 | E_Constant
18955 | E_Variable
18957 LPE := Linker_Section_Pragma (Ent);
18959 if Present (LPE) then
18960 Error_Msg_Sloc := Sloc (LPE);
18961 Error_Msg_NE
18962 ("Linker_Section already specified for &#", Arg1, Ent);
18963 end if;
18965 Set_Linker_Section_Pragma (Ent, N);
18967 -- A pragma that applies to a Ghost entity becomes Ghost for
18968 -- the purposes of legality checks and removal of ignored
18969 -- Ghost code.
18971 Mark_Ghost_Pragma (N, Ent);
18973 -- Subprograms
18975 when Subprogram_Kind =>
18977 -- Aspect case, entity already set
18979 if From_Aspect_Specification (N) then
18980 Set_Linker_Section_Pragma
18981 (Entity (Corresponding_Aspect (N)), N);
18983 -- Propagate it to its ultimate aliased entity to
18984 -- facilitate the backend processing this attribute
18985 -- in instantiations of generic subprograms.
18987 if Present (Alias (Entity (Corresponding_Aspect (N))))
18988 then
18989 Set_Linker_Section_Pragma
18990 (Ultimate_Alias
18991 (Entity (Corresponding_Aspect (N))), N);
18992 end if;
18994 -- Pragma case, we must climb the homonym chain, but skip
18995 -- any for which the linker section is already set.
18997 else
18998 loop
18999 if No (Linker_Section_Pragma (Ent)) then
19000 Set_Linker_Section_Pragma (Ent, N);
19002 -- Propagate it to its ultimate aliased entity to
19003 -- facilitate the backend processing this attribute
19004 -- in instantiations of generic subprograms.
19006 if Present (Alias (Ent)) then
19007 Set_Linker_Section_Pragma
19008 (Ultimate_Alias (Ent), N);
19009 end if;
19011 -- A pragma that applies to a Ghost entity becomes
19012 -- Ghost for the purposes of legality checks and
19013 -- removal of ignored Ghost code.
19015 Mark_Ghost_Pragma (N, Ent);
19017 -- Capture the entity of the first Ghost subprogram
19018 -- being processed for error detection purposes.
19020 if Is_Ghost_Entity (Ent) then
19021 if No (Ghost_Id) then
19022 Ghost_Id := Ent;
19023 end if;
19025 -- Otherwise the subprogram is non-Ghost. It is
19026 -- illegal to mix references to Ghost and non-Ghost
19027 -- entities (SPARK RM 6.9).
19029 elsif Present (Ghost_Id)
19030 and then not Ghost_Error_Posted
19031 then
19032 Ghost_Error_Posted := True;
19034 Error_Msg_Name_1 := Pname;
19035 Error_Msg_N
19036 ("pragma % cannot mention ghost and "
19037 & "non-ghost subprograms", N);
19039 Error_Msg_Sloc := Sloc (Ghost_Id);
19040 Error_Msg_NE
19041 ("\& # declared as ghost", N, Ghost_Id);
19043 Error_Msg_Sloc := Sloc (Ent);
19044 Error_Msg_NE
19045 ("\& # declared as non-ghost", N, Ent);
19046 end if;
19047 end if;
19049 Ent := Homonym (Ent);
19050 exit when No (Ent)
19051 or else Scope (Ent) /= Current_Scope;
19052 end loop;
19053 end if;
19055 -- All other cases are illegal
19057 when others =>
19058 Error_Pragma_Arg
19059 ("pragma% applies only to objects, subprograms, and types",
19060 Arg1);
19061 end case;
19062 end Linker_Section;
19064 ----------
19065 -- List --
19066 ----------
19068 -- pragma List (On | Off)
19070 -- There is nothing to do here, since we did all the processing for
19071 -- this pragma in Par.Prag (so that it works properly even in syntax
19072 -- only mode).
19074 when Pragma_List =>
19075 null;
19077 ---------------
19078 -- Lock_Free --
19079 ---------------
19081 -- pragma Lock_Free [(Boolean_EXPRESSION)];
19083 when Pragma_Lock_Free => Lock_Free : declare
19084 P : constant Node_Id := Parent (N);
19085 Arg : Node_Id;
19086 Ent : Entity_Id;
19087 Val : Boolean;
19089 begin
19090 Check_No_Identifiers;
19091 Check_At_Most_N_Arguments (1);
19093 -- Protected definition case
19095 if Nkind (P) = N_Protected_Definition then
19096 Ent := Defining_Identifier (Parent (P));
19098 -- One argument
19100 if Arg_Count = 1 then
19101 Arg := Get_Pragma_Arg (Arg1);
19102 Val := Is_True (Static_Boolean (Arg));
19104 -- No arguments (expression is considered to be True)
19106 else
19107 Val := True;
19108 end if;
19110 -- Check duplicate pragma before we chain the pragma in the Rep
19111 -- Item chain of Ent.
19113 Check_Duplicate_Pragma (Ent);
19114 Record_Rep_Item (Ent, N);
19115 Set_Uses_Lock_Free (Ent, Val);
19117 -- Anything else is incorrect placement
19119 else
19120 Pragma_Misplaced;
19121 end if;
19122 end Lock_Free;
19124 --------------------
19125 -- Locking_Policy --
19126 --------------------
19128 -- pragma Locking_Policy (policy_IDENTIFIER);
19130 when Pragma_Locking_Policy => declare
19131 subtype LP_Range is Name_Id
19132 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
19133 LP_Val : LP_Range;
19134 LP : Character;
19136 begin
19137 Check_Ada_83_Warning;
19138 Check_Arg_Count (1);
19139 Check_No_Identifiers;
19140 Check_Arg_Is_Locking_Policy (Arg1);
19141 Check_Valid_Configuration_Pragma;
19142 LP_Val := Chars (Get_Pragma_Arg (Arg1));
19144 case LP_Val is
19145 when Name_Ceiling_Locking => LP := 'C';
19146 when Name_Concurrent_Readers_Locking => LP := 'R';
19147 when Name_Inheritance_Locking => LP := 'I';
19148 end case;
19150 if Locking_Policy /= ' '
19151 and then Locking_Policy /= LP
19152 then
19153 Error_Msg_Sloc := Locking_Policy_Sloc;
19154 Error_Pragma ("locking policy incompatible with policy#");
19156 -- Set new policy, but always preserve System_Location since we
19157 -- like the error message with the run time name.
19159 else
19160 Locking_Policy := LP;
19162 if Locking_Policy_Sloc /= System_Location then
19163 Locking_Policy_Sloc := Loc;
19164 end if;
19165 end if;
19166 end;
19168 -------------------
19169 -- Loop_Optimize --
19170 -------------------
19172 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
19174 -- OPTIMIZATION_HINT ::=
19175 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
19177 when Pragma_Loop_Optimize => Loop_Optimize : declare
19178 Hint : Node_Id;
19180 begin
19181 GNAT_Pragma;
19182 Check_At_Least_N_Arguments (1);
19183 Check_No_Identifiers;
19185 Hint := First (Pragma_Argument_Associations (N));
19186 while Present (Hint) loop
19187 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
19188 Name_No_Unroll,
19189 Name_Unroll,
19190 Name_No_Vector,
19191 Name_Vector);
19192 Next (Hint);
19193 end loop;
19195 Check_Loop_Pragma_Placement;
19196 end Loop_Optimize;
19198 ------------------
19199 -- Loop_Variant --
19200 ------------------
19202 -- pragma Loop_Variant
19203 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
19205 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
19207 -- CHANGE_DIRECTION ::= Increases | Decreases
19209 when Pragma_Loop_Variant => Loop_Variant : declare
19210 Variant : Node_Id;
19212 begin
19213 GNAT_Pragma;
19214 Check_At_Least_N_Arguments (1);
19215 Check_Loop_Pragma_Placement;
19217 -- Process all increasing / decreasing expressions
19219 Variant := First (Pragma_Argument_Associations (N));
19220 while Present (Variant) loop
19221 if Chars (Variant) = No_Name then
19222 Error_Pragma_Arg_Ident ("expect name `Increases`", Variant);
19224 elsif Chars (Variant) not in Name_Decreases | Name_Increases
19225 then
19226 declare
19227 Name : String := Get_Name_String (Chars (Variant));
19229 begin
19230 -- It is a common mistake to write "Increasing" for
19231 -- "Increases" or "Decreasing" for "Decreases". Recognize
19232 -- specially names starting with "incr" or "decr" to
19233 -- suggest the corresponding name.
19235 System.Case_Util.To_Lower (Name);
19237 if Name'Length >= 4
19238 and then Name (1 .. 4) = "incr"
19239 then
19240 Error_Pragma_Arg_Ident
19241 ("expect name `Increases`", Variant);
19243 elsif Name'Length >= 4
19244 and then Name (1 .. 4) = "decr"
19245 then
19246 Error_Pragma_Arg_Ident
19247 ("expect name `Decreases`", Variant);
19249 else
19250 Error_Pragma_Arg_Ident
19251 ("expect name `Increases` or `Decreases`", Variant);
19252 end if;
19253 end;
19254 end if;
19256 Preanalyze_Assert_Expression
19257 (Expression (Variant), Any_Discrete);
19259 Next (Variant);
19260 end loop;
19261 end Loop_Variant;
19263 -----------------------
19264 -- Machine_Attribute --
19265 -----------------------
19267 -- pragma Machine_Attribute (
19268 -- [Entity =>] LOCAL_NAME,
19269 -- [Attribute_Name =>] static_string_EXPRESSION
19270 -- [, [Info =>] static_EXPRESSION {, static_EXPRESSION}] );
19272 when Pragma_Machine_Attribute => Machine_Attribute : declare
19273 Arg : Node_Id;
19274 Def_Id : Entity_Id;
19276 begin
19277 GNAT_Pragma;
19278 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
19280 if Arg_Count >= 3 then
19281 Check_Optional_Identifier (Arg3, Name_Info);
19282 Arg := Arg3;
19283 while Present (Arg) loop
19284 Check_Arg_Is_OK_Static_Expression (Arg);
19285 Arg := Next (Arg);
19286 end loop;
19287 else
19288 Check_Arg_Count (2);
19289 end if;
19291 Check_Optional_Identifier (Arg1, Name_Entity);
19292 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
19293 Check_Arg_Is_Local_Name (Arg1);
19294 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
19295 Def_Id := Entity (Get_Pragma_Arg (Arg1));
19297 if Is_Access_Type (Def_Id) then
19298 Def_Id := Designated_Type (Def_Id);
19299 end if;
19301 if Rep_Item_Too_Early (Def_Id, N) then
19302 return;
19303 end if;
19305 Def_Id := Underlying_Type (Def_Id);
19307 -- The only processing required is to link this item on to the
19308 -- list of rep items for the given entity. This is accomplished
19309 -- by the call to Rep_Item_Too_Late (when no error is detected
19310 -- and False is returned).
19312 if Rep_Item_Too_Late (Def_Id, N) then
19313 return;
19314 else
19315 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
19316 end if;
19317 end Machine_Attribute;
19319 ----------
19320 -- Main --
19321 ----------
19323 -- pragma Main
19324 -- (MAIN_OPTION [, MAIN_OPTION]);
19326 -- MAIN_OPTION ::=
19327 -- [STACK_SIZE =>] static_integer_EXPRESSION
19328 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
19329 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
19331 when Pragma_Main => Main : declare
19332 Args : Args_List (1 .. 3);
19333 Names : constant Name_List (1 .. 3) := (
19334 Name_Stack_Size,
19335 Name_Task_Stack_Size_Default,
19336 Name_Time_Slicing_Enabled);
19338 Nod : Node_Id;
19340 begin
19341 GNAT_Pragma;
19342 Gather_Associations (Names, Args);
19344 for J in 1 .. 2 loop
19345 if Present (Args (J)) then
19346 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
19347 end if;
19348 end loop;
19350 if Present (Args (3)) then
19351 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
19352 end if;
19354 Nod := Next (N);
19355 while Present (Nod) loop
19356 if Nkind (Nod) = N_Pragma
19357 and then Pragma_Name (Nod) = Name_Main
19358 then
19359 Error_Msg_Name_1 := Pname;
19360 Error_Msg_N ("duplicate pragma% not permitted", Nod);
19361 end if;
19363 Next (Nod);
19364 end loop;
19365 end Main;
19367 ------------------
19368 -- Main_Storage --
19369 ------------------
19371 -- pragma Main_Storage
19372 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
19374 -- MAIN_STORAGE_OPTION ::=
19375 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
19376 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
19378 when Pragma_Main_Storage => Main_Storage : declare
19379 Args : Args_List (1 .. 2);
19380 Names : constant Name_List (1 .. 2) := (
19381 Name_Working_Storage,
19382 Name_Top_Guard);
19384 Nod : Node_Id;
19386 begin
19387 GNAT_Pragma;
19388 Gather_Associations (Names, Args);
19390 for J in 1 .. 2 loop
19391 if Present (Args (J)) then
19392 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
19393 end if;
19394 end loop;
19396 Check_In_Main_Program;
19398 Nod := Next (N);
19399 while Present (Nod) loop
19400 if Nkind (Nod) = N_Pragma
19401 and then Pragma_Name (Nod) = Name_Main_Storage
19402 then
19403 Error_Msg_Name_1 := Pname;
19404 Error_Msg_N ("duplicate pragma% not permitted", Nod);
19405 end if;
19407 Next (Nod);
19408 end loop;
19409 end Main_Storage;
19411 ----------------------------
19412 -- Max_Entry_Queue_Length --
19413 ----------------------------
19415 -- pragma Max_Entry_Queue_Length (static_integer_EXPRESSION);
19417 -- This processing is shared by Pragma_Max_Entry_Queue_Depth and
19418 -- Pragma_Max_Queue_Length.
19420 when Pragma_Max_Entry_Queue_Length
19421 | Pragma_Max_Entry_Queue_Depth
19422 | Pragma_Max_Queue_Length
19424 Max_Entry_Queue_Length : declare
19425 Arg : Node_Id;
19426 Entry_Decl : Node_Id;
19427 Entry_Id : Entity_Id;
19428 Val : Uint;
19430 begin
19431 if Prag_Id = Pragma_Max_Entry_Queue_Depth
19432 or else Prag_Id = Pragma_Max_Queue_Length
19433 then
19434 GNAT_Pragma;
19435 end if;
19437 Check_Arg_Count (1);
19439 Entry_Decl :=
19440 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
19442 -- Entry declaration
19444 if Nkind (Entry_Decl) = N_Entry_Declaration then
19446 -- Entry illegally within a task
19448 if Nkind (Parent (N)) = N_Task_Definition then
19449 Error_Pragma ("pragma % cannot apply to task entries");
19450 return;
19451 end if;
19453 Entry_Id := Defining_Entity (Entry_Decl);
19455 -- Otherwise the pragma is associated with an illegal construct
19457 else
19458 Error_Pragma
19459 ("pragma % must apply to a protected entry declaration");
19460 return;
19461 end if;
19463 -- Mark the pragma as Ghost if the related subprogram is also
19464 -- Ghost. This also ensures that any expansion performed further
19465 -- below will produce Ghost nodes.
19467 Mark_Ghost_Pragma (N, Entry_Id);
19469 -- Analyze the Integer expression
19471 Arg := Get_Pragma_Arg (Arg1);
19472 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
19474 Val := Expr_Value (Arg);
19476 if Val < -1 then
19477 Error_Pragma_Arg
19478 ("argument for pragma% cannot be less than -1", Arg1);
19480 elsif not UI_Is_In_Int_Range (Val) then
19481 Error_Pragma_Arg
19482 ("argument for pragma% out of range of Integer", Arg1);
19484 end if;
19486 Record_Rep_Item (Entry_Id, N);
19487 end Max_Entry_Queue_Length;
19489 -----------------
19490 -- Memory_Size --
19491 -----------------
19493 -- pragma Memory_Size (NUMERIC_LITERAL)
19495 when Pragma_Memory_Size =>
19496 GNAT_Pragma;
19498 -- Memory size is simply ignored
19500 Check_No_Identifiers;
19501 Check_Arg_Count (1);
19502 Check_Arg_Is_Integer_Literal (Arg1);
19504 -------------
19505 -- No_Body --
19506 -------------
19508 -- pragma No_Body;
19510 -- The only correct use of this pragma is on its own in a file, in
19511 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
19512 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
19513 -- check for a file containing nothing but a No_Body pragma). If we
19514 -- attempt to process it during normal semantics processing, it means
19515 -- it was misplaced.
19517 when Pragma_No_Body =>
19518 GNAT_Pragma;
19519 Pragma_Misplaced;
19521 -----------------------------
19522 -- No_Elaboration_Code_All --
19523 -----------------------------
19525 -- pragma No_Elaboration_Code_All;
19527 when Pragma_No_Elaboration_Code_All =>
19528 GNAT_Pragma;
19529 Check_Valid_Library_Unit_Pragma;
19531 if Nkind (N) = N_Null_Statement then
19532 return;
19533 end if;
19535 -- Must appear for a spec or generic spec
19537 if Nkind (Unit (Cunit (Current_Sem_Unit))) not in
19538 N_Generic_Package_Declaration |
19539 N_Generic_Subprogram_Declaration |
19540 N_Package_Declaration |
19541 N_Subprogram_Declaration
19542 then
19543 Error_Pragma
19544 (Fix_Error
19545 ("pragma% can only occur for package "
19546 & "or subprogram spec"));
19547 end if;
19549 -- Set flag in unit table
19551 Set_No_Elab_Code_All (Current_Sem_Unit);
19553 -- Set restriction No_Elaboration_Code if this is the main unit
19555 if Current_Sem_Unit = Main_Unit then
19556 Set_Restriction (No_Elaboration_Code, N);
19557 end if;
19559 -- If we are in the main unit or in an extended main source unit,
19560 -- then we also add it to the configuration restrictions so that
19561 -- it will apply to all units in the extended main source.
19563 if Current_Sem_Unit = Main_Unit
19564 or else In_Extended_Main_Source_Unit (N)
19565 then
19566 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
19567 end if;
19569 -- If in main extended unit, activate transitive with test
19571 if In_Extended_Main_Source_Unit (N) then
19572 Opt.No_Elab_Code_All_Pragma := N;
19573 end if;
19575 -----------------------------
19576 -- No_Component_Reordering --
19577 -----------------------------
19579 -- pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)];
19581 when Pragma_No_Component_Reordering => No_Comp_Reordering : declare
19582 E : Entity_Id;
19583 E_Id : Node_Id;
19585 begin
19586 GNAT_Pragma;
19587 Check_At_Most_N_Arguments (1);
19589 if Arg_Count = 0 then
19590 Check_Valid_Configuration_Pragma;
19591 Opt.No_Component_Reordering := True;
19593 else
19594 Check_Optional_Identifier (Arg2, Name_Entity);
19595 Check_Arg_Is_Local_Name (Arg1);
19596 E_Id := Get_Pragma_Arg (Arg1);
19598 if Etype (E_Id) = Any_Type then
19599 return;
19600 end if;
19602 E := Entity (E_Id);
19604 if not Is_Record_Type (E) then
19605 Error_Pragma_Arg ("pragma% requires record type", Arg1);
19606 end if;
19608 Set_No_Reordering (Base_Type (E));
19609 end if;
19610 end No_Comp_Reordering;
19612 --------------------------
19613 -- No_Heap_Finalization --
19614 --------------------------
19616 -- pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ];
19618 when Pragma_No_Heap_Finalization => No_Heap_Finalization : declare
19619 Context : constant Node_Id := Parent (N);
19620 Typ_Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
19621 Prev : Node_Id;
19622 Typ : Entity_Id;
19624 begin
19625 GNAT_Pragma;
19626 Check_No_Identifiers;
19628 -- The pragma appears in a configuration file
19630 if No (Context) then
19631 Check_Arg_Count (0);
19632 Check_Valid_Configuration_Pragma;
19634 -- Detect a duplicate pragma
19636 if Present (No_Heap_Finalization_Pragma) then
19637 Duplication_Error
19638 (Prag => N,
19639 Prev => No_Heap_Finalization_Pragma);
19640 raise Pragma_Exit;
19641 end if;
19643 No_Heap_Finalization_Pragma := N;
19645 -- Otherwise the pragma should be associated with a library-level
19646 -- named access-to-object type.
19648 else
19649 Check_Arg_Count (1);
19650 Check_Arg_Is_Local_Name (Arg1);
19652 Find_Type (Typ_Arg);
19653 Typ := Entity (Typ_Arg);
19655 -- The type being subjected to the pragma is erroneous
19657 if Typ = Any_Type then
19658 Error_Pragma ("cannot find type referenced by pragma %");
19660 -- The pragma is applied to an incomplete or generic formal
19661 -- type way too early.
19663 elsif Rep_Item_Too_Early (Typ, N) then
19664 return;
19666 else
19667 Typ := Underlying_Type (Typ);
19668 end if;
19670 -- The pragma must apply to an access-to-object type
19672 if Ekind (Typ) in E_Access_Type | E_General_Access_Type then
19673 null;
19675 -- Give a detailed error message on all other access type kinds
19677 elsif Ekind (Typ) = E_Access_Protected_Subprogram_Type then
19678 Error_Pragma
19679 ("pragma % cannot apply to access protected subprogram "
19680 & "type");
19682 elsif Ekind (Typ) = E_Access_Subprogram_Type then
19683 Error_Pragma
19684 ("pragma % cannot apply to access subprogram type");
19686 elsif Is_Anonymous_Access_Type (Typ) then
19687 Error_Pragma
19688 ("pragma % cannot apply to anonymous access type");
19690 -- Give a general error message in case the pragma applies to a
19691 -- non-access type.
19693 else
19694 Error_Pragma
19695 ("pragma % must apply to library level access type");
19696 end if;
19698 -- At this point the argument denotes an access-to-object type.
19699 -- Ensure that the type is declared at the library level.
19701 if Is_Library_Level_Entity (Typ) then
19702 null;
19704 -- Quietly ignore an access-to-object type originally declared
19705 -- at the library level within a generic, but instantiated at
19706 -- a non-library level. As a result the access-to-object type
19707 -- "loses" its No_Heap_Finalization property.
19709 elsif In_Instance then
19710 raise Pragma_Exit;
19712 else
19713 Error_Pragma
19714 ("pragma % must apply to library level access type");
19715 end if;
19717 -- Detect a duplicate pragma
19719 if Present (No_Heap_Finalization_Pragma) then
19720 Duplication_Error
19721 (Prag => N,
19722 Prev => No_Heap_Finalization_Pragma);
19723 raise Pragma_Exit;
19725 else
19726 Prev := Get_Pragma (Typ, Pragma_No_Heap_Finalization);
19728 if Present (Prev) then
19729 Duplication_Error
19730 (Prag => N,
19731 Prev => Prev);
19732 raise Pragma_Exit;
19733 end if;
19734 end if;
19736 Record_Rep_Item (Typ, N);
19737 end if;
19738 end No_Heap_Finalization;
19740 ---------------
19741 -- No_Inline --
19742 ---------------
19744 -- pragma No_Inline ( NAME {, NAME} );
19746 when Pragma_No_Inline =>
19747 GNAT_Pragma;
19748 Process_Inline (Suppressed);
19750 ---------------
19751 -- No_Return --
19752 ---------------
19754 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
19756 when Pragma_No_Return => No_Return : declare
19757 Arg : Node_Id;
19758 E : Entity_Id;
19759 Found : Boolean;
19760 Id : Node_Id;
19762 Ghost_Error_Posted : Boolean := False;
19763 -- Flag set when an error concerning the illegal mix of Ghost and
19764 -- non-Ghost subprograms is emitted.
19766 Ghost_Id : Entity_Id := Empty;
19767 -- The entity of the first Ghost procedure encountered while
19768 -- processing the arguments of the pragma.
19770 begin
19771 Ada_2005_Pragma;
19772 Check_At_Least_N_Arguments (1);
19774 -- Loop through arguments of pragma
19776 Arg := Arg1;
19777 while Present (Arg) loop
19778 Check_Arg_Is_Local_Name (Arg);
19779 Id := Get_Pragma_Arg (Arg);
19780 Analyze (Id);
19782 if not Is_Entity_Name (Id) then
19783 Error_Pragma_Arg ("entity name required", Arg);
19784 end if;
19786 if Etype (Id) = Any_Type then
19787 raise Pragma_Exit;
19788 end if;
19790 -- Loop to find matching procedures or functions (Ada 2020)
19792 E := Entity (Id);
19794 Found := False;
19795 while Present (E)
19796 and then Scope (E) = Current_Scope
19797 loop
19798 -- Ada 2020 (AI12-0269): A function can be No_Return
19800 if Ekind (E) in E_Generic_Procedure | E_Procedure
19801 or else (Ada_Version >= Ada_2020
19802 and then
19803 Ekind (E) in E_Generic_Function | E_Function)
19804 then
19805 -- Check that the pragma is not applied to a body.
19806 -- First check the specless body case, to give a
19807 -- different error message. These checks do not apply
19808 -- if Relaxed_RM_Semantics, to accommodate other Ada
19809 -- compilers. Disable these checks under -gnatd.J.
19811 if not Debug_Flag_Dot_JJ then
19812 if Nkind (Parent (Declaration_Node (E))) =
19813 N_Subprogram_Body
19814 and then not Relaxed_RM_Semantics
19815 then
19816 Error_Pragma
19817 ("pragma% requires separate spec and must come "
19818 & "before body");
19819 end if;
19821 -- Now the "specful" body case
19823 if Rep_Item_Too_Late (E, N) then
19824 raise Pragma_Exit;
19825 end if;
19826 end if;
19828 Set_No_Return (E);
19830 -- A pragma that applies to a Ghost entity becomes Ghost
19831 -- for the purposes of legality checks and removal of
19832 -- ignored Ghost code.
19834 Mark_Ghost_Pragma (N, E);
19836 -- Capture the entity of the first Ghost procedure being
19837 -- processed for error detection purposes.
19839 if Is_Ghost_Entity (E) then
19840 if No (Ghost_Id) then
19841 Ghost_Id := E;
19842 end if;
19844 -- Otherwise the subprogram is non-Ghost. It is illegal
19845 -- to mix references to Ghost and non-Ghost entities
19846 -- (SPARK RM 6.9).
19848 elsif Present (Ghost_Id)
19849 and then not Ghost_Error_Posted
19850 then
19851 Ghost_Error_Posted := True;
19853 Error_Msg_Name_1 := Pname;
19854 Error_Msg_N
19855 ("pragma % cannot mention ghost and non-ghost "
19856 & "procedures", N);
19858 Error_Msg_Sloc := Sloc (Ghost_Id);
19859 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
19861 Error_Msg_Sloc := Sloc (E);
19862 Error_Msg_NE ("\& # declared as non-ghost", N, E);
19863 end if;
19865 -- Set flag on any alias as well
19867 if Is_Overloadable (E) and then Present (Alias (E)) then
19868 Set_No_Return (Alias (E));
19869 end if;
19871 Found := True;
19872 end if;
19874 exit when From_Aspect_Specification (N);
19875 E := Homonym (E);
19876 end loop;
19878 -- If entity in not in current scope it may be the enclosing
19879 -- suprogram body to which the aspect applies.
19881 if not Found then
19882 if Entity (Id) = Current_Scope
19883 and then From_Aspect_Specification (N)
19884 then
19885 Set_No_Return (Entity (Id));
19887 elsif Ada_Version >= Ada_2020 then
19888 Error_Pragma_Arg
19889 ("no subprogram& found for pragma%", Arg);
19891 else
19892 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
19893 end if;
19894 end if;
19896 Next (Arg);
19897 end loop;
19898 end No_Return;
19900 -----------------
19901 -- No_Run_Time --
19902 -----------------
19904 -- pragma No_Run_Time;
19906 -- Note: this pragma is retained for backwards compatibility. See
19907 -- body of Rtsfind for full details on its handling.
19909 when Pragma_No_Run_Time =>
19910 GNAT_Pragma;
19911 Check_Valid_Configuration_Pragma;
19912 Check_Arg_Count (0);
19914 -- Remove backward compatibility if Build_Type is FSF or GPL and
19915 -- generate a warning.
19917 declare
19918 Ignore : constant Boolean := Build_Type in FSF .. GPL;
19919 begin
19920 if Ignore then
19921 Error_Pragma ("pragma% is ignored, has no effect??");
19922 else
19923 No_Run_Time_Mode := True;
19924 Configurable_Run_Time_Mode := True;
19926 -- Set Duration to 32 bits if word size is 32
19928 if Ttypes.System_Word_Size = 32 then
19929 Duration_32_Bits_On_Target := True;
19930 end if;
19932 -- Set appropriate restrictions
19934 Set_Restriction (No_Finalization, N);
19935 Set_Restriction (No_Exception_Handlers, N);
19936 Set_Restriction (Max_Tasks, N, 0);
19937 Set_Restriction (No_Tasking, N);
19938 end if;
19939 end;
19941 -----------------------
19942 -- No_Tagged_Streams --
19943 -----------------------
19945 -- pragma No_Tagged_Streams [([Entity => ]tagged_type_local_NAME)];
19947 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
19948 E : Entity_Id;
19949 E_Id : Node_Id;
19951 begin
19952 GNAT_Pragma;
19953 Check_At_Most_N_Arguments (1);
19955 -- One argument case
19957 if Arg_Count = 1 then
19958 Check_Optional_Identifier (Arg1, Name_Entity);
19959 Check_Arg_Is_Local_Name (Arg1);
19960 E_Id := Get_Pragma_Arg (Arg1);
19962 if Etype (E_Id) = Any_Type then
19963 return;
19964 end if;
19966 E := Entity (E_Id);
19968 Check_Duplicate_Pragma (E);
19970 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
19971 Error_Pragma_Arg
19972 ("argument for pragma% must be root tagged type", Arg1);
19973 end if;
19975 if Rep_Item_Too_Early (E, N)
19976 or else
19977 Rep_Item_Too_Late (E, N)
19978 then
19979 return;
19980 else
19981 Set_No_Tagged_Streams_Pragma (E, N);
19982 end if;
19984 -- Zero argument case
19986 else
19987 Check_Is_In_Decl_Part_Or_Package_Spec;
19988 No_Tagged_Streams := N;
19989 end if;
19990 end No_Tagged_Strms;
19992 ------------------------
19993 -- No_Strict_Aliasing --
19994 ------------------------
19996 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
19998 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
19999 E : Entity_Id;
20000 E_Id : Node_Id;
20002 begin
20003 GNAT_Pragma;
20004 Check_At_Most_N_Arguments (1);
20006 if Arg_Count = 0 then
20007 Check_Valid_Configuration_Pragma;
20008 Opt.No_Strict_Aliasing := True;
20010 else
20011 Check_Optional_Identifier (Arg2, Name_Entity);
20012 Check_Arg_Is_Local_Name (Arg1);
20013 E_Id := Get_Pragma_Arg (Arg1);
20015 if Etype (E_Id) = Any_Type then
20016 return;
20017 end if;
20019 E := Entity (E_Id);
20021 if not Is_Access_Type (E) then
20022 Error_Pragma_Arg ("pragma% requires access type", Arg1);
20023 end if;
20025 Set_No_Strict_Aliasing (Base_Type (E));
20026 end if;
20027 end No_Strict_Aliasing;
20029 -----------------------
20030 -- Normalize_Scalars --
20031 -----------------------
20033 -- pragma Normalize_Scalars;
20035 when Pragma_Normalize_Scalars =>
20036 Check_Ada_83_Warning;
20037 Check_Arg_Count (0);
20038 Check_Valid_Configuration_Pragma;
20040 -- Normalize_Scalars creates false positives in CodePeer, and
20041 -- incorrect negative results in GNATprove mode, so ignore this
20042 -- pragma in these modes.
20044 if not (CodePeer_Mode or GNATprove_Mode) then
20045 Normalize_Scalars := True;
20046 Init_Or_Norm_Scalars := True;
20047 end if;
20049 -----------------
20050 -- Obsolescent --
20051 -----------------
20053 -- pragma Obsolescent;
20055 -- pragma Obsolescent (
20056 -- [Message =>] static_string_EXPRESSION
20057 -- [,[Version =>] Ada_05]]);
20059 -- pragma Obsolescent (
20060 -- [Entity =>] NAME
20061 -- [,[Message =>] static_string_EXPRESSION
20062 -- [,[Version =>] Ada_05]] );
20064 when Pragma_Obsolescent => Obsolescent : declare
20065 Decl : Node_Id;
20066 Ename : Node_Id;
20068 procedure Set_Obsolescent (E : Entity_Id);
20069 -- Given an entity Ent, mark it as obsolescent if appropriate
20071 ---------------------
20072 -- Set_Obsolescent --
20073 ---------------------
20075 procedure Set_Obsolescent (E : Entity_Id) is
20076 Active : Boolean;
20077 Ent : Entity_Id;
20078 S : String_Id;
20080 begin
20081 Active := True;
20082 Ent := E;
20084 -- A pragma that applies to a Ghost entity becomes Ghost for
20085 -- the purposes of legality checks and removal of ignored Ghost
20086 -- code.
20088 Mark_Ghost_Pragma (N, E);
20090 -- Entity name was given
20092 if Present (Ename) then
20094 -- If entity name matches, we are fine.
20096 if Chars (Ename) = Chars (Ent) then
20097 Set_Entity (Ename, Ent);
20098 Generate_Reference (Ent, Ename);
20100 -- If entity name does not match, only possibility is an
20101 -- enumeration literal from an enumeration type declaration.
20103 elsif Ekind (Ent) /= E_Enumeration_Type then
20104 Error_Pragma
20105 ("pragma % entity name does not match declaration");
20107 else
20108 Ent := First_Literal (E);
20109 loop
20110 if No (Ent) then
20111 Error_Pragma
20112 ("pragma % entity name does not match any "
20113 & "enumeration literal");
20115 elsif Chars (Ent) = Chars (Ename) then
20116 Set_Entity (Ename, Ent);
20117 Generate_Reference (Ent, Ename);
20118 exit;
20120 else
20121 Next_Literal (Ent);
20122 end if;
20123 end loop;
20124 end if;
20125 end if;
20127 -- Ent points to entity to be marked
20129 if Arg_Count >= 1 then
20131 -- Deal with static string argument
20133 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
20134 S := Strval (Get_Pragma_Arg (Arg1));
20136 for J in 1 .. String_Length (S) loop
20137 if not In_Character_Range (Get_String_Char (S, J)) then
20138 Error_Pragma_Arg
20139 ("pragma% argument does not allow wide characters",
20140 Arg1);
20141 end if;
20142 end loop;
20144 Obsolescent_Warnings.Append
20145 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
20147 -- Check for Ada_05 parameter
20149 if Arg_Count /= 1 then
20150 Check_Arg_Count (2);
20152 declare
20153 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
20155 begin
20156 Check_Arg_Is_Identifier (Argx);
20158 if Chars (Argx) /= Name_Ada_05 then
20159 Error_Msg_Name_2 := Name_Ada_05;
20160 Error_Pragma_Arg
20161 ("only allowed argument for pragma% is %", Argx);
20162 end if;
20164 if Ada_Version_Explicit < Ada_2005
20165 or else not Warn_On_Ada_2005_Compatibility
20166 then
20167 Active := False;
20168 end if;
20169 end;
20170 end if;
20171 end if;
20173 -- Set flag if pragma active
20175 if Active then
20176 Set_Is_Obsolescent (Ent);
20177 end if;
20179 return;
20180 end Set_Obsolescent;
20182 -- Start of processing for pragma Obsolescent
20184 begin
20185 GNAT_Pragma;
20187 Check_At_Most_N_Arguments (3);
20189 -- See if first argument specifies an entity name
20191 if Arg_Count >= 1
20192 and then
20193 (Chars (Arg1) = Name_Entity
20194 or else
20195 Nkind (Get_Pragma_Arg (Arg1)) in
20196 N_Character_Literal | N_Identifier | N_Operator_Symbol)
20197 then
20198 Ename := Get_Pragma_Arg (Arg1);
20200 -- Eliminate first argument, so we can share processing
20202 Arg1 := Arg2;
20203 Arg2 := Arg3;
20204 Arg_Count := Arg_Count - 1;
20206 -- No Entity name argument given
20208 else
20209 Ename := Empty;
20210 end if;
20212 if Arg_Count >= 1 then
20213 Check_Optional_Identifier (Arg1, Name_Message);
20215 if Arg_Count = 2 then
20216 Check_Optional_Identifier (Arg2, Name_Version);
20217 end if;
20218 end if;
20220 -- Get immediately preceding declaration
20222 Decl := Prev (N);
20223 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
20224 Prev (Decl);
20225 end loop;
20227 -- Cases where we do not follow anything other than another pragma
20229 if No (Decl) then
20231 -- First case: library level compilation unit declaration with
20232 -- the pragma immediately following the declaration.
20234 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
20235 Set_Obsolescent
20236 (Defining_Entity (Unit (Parent (Parent (N)))));
20237 return;
20239 -- Case 2: library unit placement for package
20241 else
20242 declare
20243 Ent : constant Entity_Id := Find_Lib_Unit_Name;
20244 begin
20245 if Is_Package_Or_Generic_Package (Ent) then
20246 Set_Obsolescent (Ent);
20247 return;
20248 end if;
20249 end;
20250 end if;
20252 -- Cases where we must follow a declaration, including an
20253 -- abstract subprogram declaration, which is not in the
20254 -- other node subtypes.
20256 else
20257 if Nkind (Decl) not in N_Declaration
20258 and then Nkind (Decl) not in N_Later_Decl_Item
20259 and then Nkind (Decl) not in N_Generic_Declaration
20260 and then Nkind (Decl) not in N_Renaming_Declaration
20261 and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration
20262 then
20263 Error_Pragma
20264 ("pragma% misplaced, "
20265 & "must immediately follow a declaration");
20267 else
20268 Set_Obsolescent (Defining_Entity (Decl));
20269 return;
20270 end if;
20271 end if;
20272 end Obsolescent;
20274 --------------
20275 -- Optimize --
20276 --------------
20278 -- pragma Optimize (Time | Space | Off);
20280 -- The actual check for optimize is done in Gigi. Note that this
20281 -- pragma does not actually change the optimization setting, it
20282 -- simply checks that it is consistent with the pragma.
20284 when Pragma_Optimize =>
20285 Check_No_Identifiers;
20286 Check_Arg_Count (1);
20287 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
20289 ------------------------
20290 -- Optimize_Alignment --
20291 ------------------------
20293 -- pragma Optimize_Alignment (Time | Space | Off);
20295 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
20296 GNAT_Pragma;
20297 Check_No_Identifiers;
20298 Check_Arg_Count (1);
20299 Check_Valid_Configuration_Pragma;
20301 declare
20302 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
20303 begin
20304 case Nam is
20305 when Name_Off => Opt.Optimize_Alignment := 'O';
20306 when Name_Space => Opt.Optimize_Alignment := 'S';
20307 when Name_Time => Opt.Optimize_Alignment := 'T';
20309 when others =>
20310 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
20311 end case;
20312 end;
20314 -- Set indication that mode is set locally. If we are in fact in a
20315 -- configuration pragma file, this setting is harmless since the
20316 -- switch will get reset anyway at the start of each unit.
20318 Optimize_Alignment_Local := True;
20319 end Optimize_Alignment;
20321 -------------
20322 -- Ordered --
20323 -------------
20325 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
20327 when Pragma_Ordered => Ordered : declare
20328 Assoc : constant Node_Id := Arg1;
20329 Type_Id : Node_Id;
20330 Typ : Entity_Id;
20332 begin
20333 GNAT_Pragma;
20334 Check_No_Identifiers;
20335 Check_Arg_Count (1);
20336 Check_Arg_Is_Local_Name (Arg1);
20338 Type_Id := Get_Pragma_Arg (Assoc);
20339 Find_Type (Type_Id);
20340 Typ := Entity (Type_Id);
20342 if Typ = Any_Type then
20343 return;
20344 else
20345 Typ := Underlying_Type (Typ);
20346 end if;
20348 if not Is_Enumeration_Type (Typ) then
20349 Error_Pragma ("pragma% must specify enumeration type");
20350 end if;
20352 Check_First_Subtype (Arg1);
20353 Set_Has_Pragma_Ordered (Base_Type (Typ));
20354 end Ordered;
20356 -------------------
20357 -- Overflow_Mode --
20358 -------------------
20360 -- pragma Overflow_Mode
20361 -- ([General => ] MODE [, [Assertions => ] MODE]);
20363 -- MODE := STRICT | MINIMIZED | ELIMINATED
20365 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
20366 -- since System.Bignums makes this assumption. This is true of nearly
20367 -- all (all?) targets.
20369 when Pragma_Overflow_Mode => Overflow_Mode : declare
20370 function Get_Overflow_Mode
20371 (Name : Name_Id;
20372 Arg : Node_Id) return Overflow_Mode_Type;
20373 -- Function to process one pragma argument, Arg. If an identifier
20374 -- is present, it must be Name. Mode type is returned if a valid
20375 -- argument exists, otherwise an error is signalled.
20377 -----------------------
20378 -- Get_Overflow_Mode --
20379 -----------------------
20381 function Get_Overflow_Mode
20382 (Name : Name_Id;
20383 Arg : Node_Id) return Overflow_Mode_Type
20385 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
20387 begin
20388 Check_Optional_Identifier (Arg, Name);
20389 Check_Arg_Is_Identifier (Argx);
20391 if Chars (Argx) = Name_Strict then
20392 return Strict;
20394 elsif Chars (Argx) = Name_Minimized then
20395 return Minimized;
20397 elsif Chars (Argx) = Name_Eliminated then
20398 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
20399 Error_Pragma_Arg
20400 ("Eliminated not implemented on this target", Argx);
20401 else
20402 return Eliminated;
20403 end if;
20405 else
20406 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
20407 end if;
20408 end Get_Overflow_Mode;
20410 -- Start of processing for Overflow_Mode
20412 begin
20413 GNAT_Pragma;
20414 Check_At_Least_N_Arguments (1);
20415 Check_At_Most_N_Arguments (2);
20417 -- Process first argument
20419 Scope_Suppress.Overflow_Mode_General :=
20420 Get_Overflow_Mode (Name_General, Arg1);
20422 -- Case of only one argument
20424 if Arg_Count = 1 then
20425 Scope_Suppress.Overflow_Mode_Assertions :=
20426 Scope_Suppress.Overflow_Mode_General;
20428 -- Case of two arguments present
20430 else
20431 Scope_Suppress.Overflow_Mode_Assertions :=
20432 Get_Overflow_Mode (Name_Assertions, Arg2);
20433 end if;
20434 end Overflow_Mode;
20436 --------------------------
20437 -- Overriding Renamings --
20438 --------------------------
20440 -- pragma Overriding_Renamings;
20442 when Pragma_Overriding_Renamings =>
20443 GNAT_Pragma;
20444 Check_Arg_Count (0);
20445 Check_Valid_Configuration_Pragma;
20446 Overriding_Renamings := True;
20448 ----------
20449 -- Pack --
20450 ----------
20452 -- pragma Pack (first_subtype_LOCAL_NAME);
20454 when Pragma_Pack => Pack : declare
20455 Assoc : constant Node_Id := Arg1;
20456 Ctyp : Entity_Id;
20457 Ignore : Boolean := False;
20458 Typ : Entity_Id;
20459 Type_Id : Node_Id;
20461 begin
20462 Check_No_Identifiers;
20463 Check_Arg_Count (1);
20464 Check_Arg_Is_Local_Name (Arg1);
20465 Type_Id := Get_Pragma_Arg (Assoc);
20467 if not Is_Entity_Name (Type_Id)
20468 or else not Is_Type (Entity (Type_Id))
20469 then
20470 Error_Pragma_Arg
20471 ("argument for pragma% must be type or subtype", Arg1);
20472 end if;
20474 Find_Type (Type_Id);
20475 Typ := Entity (Type_Id);
20477 if Typ = Any_Type
20478 or else Rep_Item_Too_Early (Typ, N)
20479 then
20480 return;
20481 else
20482 Typ := Underlying_Type (Typ);
20483 end if;
20485 -- A pragma that applies to a Ghost entity becomes Ghost for the
20486 -- purposes of legality checks and removal of ignored Ghost code.
20488 Mark_Ghost_Pragma (N, Typ);
20490 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
20491 Error_Pragma ("pragma% must specify array or record type");
20492 end if;
20494 Check_First_Subtype (Arg1);
20495 Check_Duplicate_Pragma (Typ);
20497 -- Array type
20499 if Is_Array_Type (Typ) then
20500 Ctyp := Component_Type (Typ);
20502 -- Ignore pack that does nothing
20504 if Known_Static_Esize (Ctyp)
20505 and then Known_Static_RM_Size (Ctyp)
20506 and then Esize (Ctyp) = RM_Size (Ctyp)
20507 and then Addressable (Esize (Ctyp))
20508 then
20509 Ignore := True;
20510 end if;
20512 -- Process OK pragma Pack. Note that if there is a separate
20513 -- component clause present, the Pack will be cancelled. This
20514 -- processing is in Freeze.
20516 if not Rep_Item_Too_Late (Typ, N) then
20518 -- In CodePeer mode, we do not need complex front-end
20519 -- expansions related to pragma Pack, so disable handling
20520 -- of pragma Pack.
20522 if CodePeer_Mode then
20523 null;
20525 -- Normal case where we do the pack action
20527 else
20528 if not Ignore then
20529 Set_Is_Packed (Base_Type (Typ));
20530 Set_Has_Non_Standard_Rep (Base_Type (Typ));
20531 end if;
20533 Set_Has_Pragma_Pack (Base_Type (Typ));
20534 end if;
20535 end if;
20537 -- For record types, the pack is always effective
20539 else pragma Assert (Is_Record_Type (Typ));
20540 if not Rep_Item_Too_Late (Typ, N) then
20541 Set_Is_Packed (Base_Type (Typ));
20542 Set_Has_Pragma_Pack (Base_Type (Typ));
20543 Set_Has_Non_Standard_Rep (Base_Type (Typ));
20544 end if;
20545 end if;
20546 end Pack;
20548 ----------
20549 -- Page --
20550 ----------
20552 -- pragma Page;
20554 -- There is nothing to do here, since we did all the processing for
20555 -- this pragma in Par.Prag (so that it works properly even in syntax
20556 -- only mode).
20558 when Pragma_Page =>
20559 null;
20561 -------------
20562 -- Part_Of --
20563 -------------
20565 -- pragma Part_Of (ABSTRACT_STATE);
20567 -- ABSTRACT_STATE ::= NAME
20569 when Pragma_Part_Of => Part_Of : declare
20570 procedure Propagate_Part_Of
20571 (Pack_Id : Entity_Id;
20572 State_Id : Entity_Id;
20573 Instance : Node_Id);
20574 -- Propagate the Part_Of indicator to all abstract states and
20575 -- objects declared in the visible state space of a package
20576 -- denoted by Pack_Id. State_Id is the encapsulating state.
20577 -- Instance is the package instantiation node.
20579 -----------------------
20580 -- Propagate_Part_Of --
20581 -----------------------
20583 procedure Propagate_Part_Of
20584 (Pack_Id : Entity_Id;
20585 State_Id : Entity_Id;
20586 Instance : Node_Id)
20588 Has_Item : Boolean := False;
20589 -- Flag set when the visible state space contains at least one
20590 -- abstract state or variable.
20592 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
20593 -- Propagate the Part_Of indicator to all abstract states and
20594 -- objects declared in the visible state space of a package
20595 -- denoted by Pack_Id.
20597 -----------------------
20598 -- Propagate_Part_Of --
20599 -----------------------
20601 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
20602 Constits : Elist_Id;
20603 Item_Id : Entity_Id;
20605 begin
20606 -- Traverse the entity chain of the package and set relevant
20607 -- attributes of abstract states and objects declared in the
20608 -- visible state space of the package.
20610 Item_Id := First_Entity (Pack_Id);
20611 while Present (Item_Id)
20612 and then not In_Private_Part (Item_Id)
20613 loop
20614 -- Do not consider internally generated items
20616 if not Comes_From_Source (Item_Id) then
20617 null;
20619 -- Do not consider generic formals or their corresponding
20620 -- actuals because they are not part of a visible state.
20621 -- Note that both entities are marked as hidden.
20623 elsif Is_Hidden (Item_Id) then
20624 null;
20626 -- The Part_Of indicator turns an abstract state or an
20627 -- object into a constituent of the encapsulating state.
20628 -- Note that constants are considered here even though
20629 -- they may not depend on variable input. This check is
20630 -- left to the SPARK prover.
20632 elsif Ekind (Item_Id) in
20633 E_Abstract_State | E_Constant | E_Variable
20634 then
20635 Has_Item := True;
20636 Constits := Part_Of_Constituents (State_Id);
20638 if No (Constits) then
20639 Constits := New_Elmt_List;
20640 Set_Part_Of_Constituents (State_Id, Constits);
20641 end if;
20643 Append_Elmt (Item_Id, Constits);
20644 Set_Encapsulating_State (Item_Id, State_Id);
20646 -- Recursively handle nested packages and instantiations
20648 elsif Ekind (Item_Id) = E_Package then
20649 Propagate_Part_Of (Item_Id);
20650 end if;
20652 Next_Entity (Item_Id);
20653 end loop;
20654 end Propagate_Part_Of;
20656 -- Start of processing for Propagate_Part_Of
20658 begin
20659 Propagate_Part_Of (Pack_Id);
20661 -- Detect a package instantiation that is subject to a Part_Of
20662 -- indicator, but has no visible state.
20664 if not Has_Item then
20665 SPARK_Msg_NE
20666 ("package instantiation & has Part_Of indicator but "
20667 & "lacks visible state", Instance, Pack_Id);
20668 end if;
20669 end Propagate_Part_Of;
20671 -- Local variables
20673 Constits : Elist_Id;
20674 Encap : Node_Id;
20675 Encap_Id : Entity_Id;
20676 Item_Id : Entity_Id;
20677 Legal : Boolean;
20678 Stmt : Node_Id;
20680 -- Start of processing for Part_Of
20682 begin
20683 GNAT_Pragma;
20684 Check_No_Identifiers;
20685 Check_Arg_Count (1);
20687 Stmt := Find_Related_Context (N, Do_Checks => True);
20689 -- Object declaration
20691 if Nkind (Stmt) = N_Object_Declaration then
20692 null;
20694 -- Package instantiation
20696 elsif Nkind (Stmt) = N_Package_Instantiation then
20697 null;
20699 -- Single concurrent type declaration
20701 elsif Is_Single_Concurrent_Type_Declaration (Stmt) then
20702 null;
20704 -- Otherwise the pragma is associated with an illegal construct
20706 else
20707 Pragma_Misplaced;
20708 return;
20709 end if;
20711 -- Extract the entity of the related object declaration or package
20712 -- instantiation. In the case of the instantiation, use the entity
20713 -- of the instance spec.
20715 if Nkind (Stmt) = N_Package_Instantiation then
20716 Stmt := Instance_Spec (Stmt);
20717 end if;
20719 Item_Id := Defining_Entity (Stmt);
20721 -- A pragma that applies to a Ghost entity becomes Ghost for the
20722 -- purposes of legality checks and removal of ignored Ghost code.
20724 Mark_Ghost_Pragma (N, Item_Id);
20726 -- Chain the pragma on the contract for further processing by
20727 -- Analyze_Part_Of_In_Decl_Part or for completeness.
20729 Add_Contract_Item (N, Item_Id);
20731 -- A variable may act as constituent of a single concurrent type
20732 -- which in turn could be declared after the variable. Due to this
20733 -- discrepancy, the full analysis of indicator Part_Of is delayed
20734 -- until the end of the enclosing declarative region (see routine
20735 -- Analyze_Part_Of_In_Decl_Part).
20737 if Ekind (Item_Id) = E_Variable then
20738 null;
20740 -- Otherwise indicator Part_Of applies to a constant or a package
20741 -- instantiation.
20743 else
20744 Encap := Get_Pragma_Arg (Arg1);
20746 -- Detect any discrepancies between the placement of the
20747 -- constant or package instantiation with respect to state
20748 -- space and the encapsulating state.
20750 Analyze_Part_Of
20751 (Indic => N,
20752 Item_Id => Item_Id,
20753 Encap => Encap,
20754 Encap_Id => Encap_Id,
20755 Legal => Legal);
20757 if Legal then
20758 pragma Assert (Present (Encap_Id));
20760 if Ekind (Item_Id) = E_Constant then
20761 Constits := Part_Of_Constituents (Encap_Id);
20763 if No (Constits) then
20764 Constits := New_Elmt_List;
20765 Set_Part_Of_Constituents (Encap_Id, Constits);
20766 end if;
20768 Append_Elmt (Item_Id, Constits);
20769 Set_Encapsulating_State (Item_Id, Encap_Id);
20771 -- Propagate the Part_Of indicator to the visible state
20772 -- space of the package instantiation.
20774 else
20775 Propagate_Part_Of
20776 (Pack_Id => Item_Id,
20777 State_Id => Encap_Id,
20778 Instance => Stmt);
20779 end if;
20780 end if;
20781 end if;
20782 end Part_Of;
20784 ----------------------------------
20785 -- Partition_Elaboration_Policy --
20786 ----------------------------------
20788 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
20790 when Pragma_Partition_Elaboration_Policy => PEP : declare
20791 subtype PEP_Range is Name_Id
20792 range First_Partition_Elaboration_Policy_Name
20793 .. Last_Partition_Elaboration_Policy_Name;
20794 PEP_Val : PEP_Range;
20795 PEP : Character;
20797 begin
20798 Ada_2005_Pragma;
20799 Check_Arg_Count (1);
20800 Check_No_Identifiers;
20801 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
20802 Check_Valid_Configuration_Pragma;
20803 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
20805 case PEP_Val is
20806 when Name_Concurrent => PEP := 'C';
20807 when Name_Sequential => PEP := 'S';
20808 end case;
20810 if Partition_Elaboration_Policy /= ' '
20811 and then Partition_Elaboration_Policy /= PEP
20812 then
20813 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
20814 Error_Pragma
20815 ("partition elaboration policy incompatible with policy#");
20817 -- Set new policy, but always preserve System_Location since we
20818 -- like the error message with the run time name.
20820 else
20821 Partition_Elaboration_Policy := PEP;
20823 if Partition_Elaboration_Policy_Sloc /= System_Location then
20824 Partition_Elaboration_Policy_Sloc := Loc;
20825 end if;
20826 end if;
20827 end PEP;
20829 -------------
20830 -- Passive --
20831 -------------
20833 -- pragma Passive [(PASSIVE_FORM)];
20835 -- PASSIVE_FORM ::= Semaphore | No
20837 when Pragma_Passive =>
20838 GNAT_Pragma;
20840 if Nkind (Parent (N)) /= N_Task_Definition then
20841 Error_Pragma ("pragma% must be within task definition");
20842 end if;
20844 if Arg_Count /= 0 then
20845 Check_Arg_Count (1);
20846 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
20847 end if;
20849 ----------------------------------
20850 -- Preelaborable_Initialization --
20851 ----------------------------------
20853 -- pragma Preelaborable_Initialization (DIRECT_NAME);
20855 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
20856 Ent : Entity_Id;
20858 begin
20859 Ada_2005_Pragma;
20860 Check_Arg_Count (1);
20861 Check_No_Identifiers;
20862 Check_Arg_Is_Identifier (Arg1);
20863 Check_Arg_Is_Local_Name (Arg1);
20864 Check_First_Subtype (Arg1);
20865 Ent := Entity (Get_Pragma_Arg (Arg1));
20867 -- A pragma that applies to a Ghost entity becomes Ghost for the
20868 -- purposes of legality checks and removal of ignored Ghost code.
20870 Mark_Ghost_Pragma (N, Ent);
20872 -- The pragma may come from an aspect on a private declaration,
20873 -- even if the freeze point at which this is analyzed in the
20874 -- private part after the full view.
20876 if Has_Private_Declaration (Ent)
20877 and then From_Aspect_Specification (N)
20878 then
20879 null;
20881 -- Check appropriate type argument
20883 elsif Is_Private_Type (Ent)
20884 or else Is_Protected_Type (Ent)
20885 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
20887 -- AI05-0028: The pragma applies to all composite types. Note
20888 -- that we apply this binding interpretation to earlier versions
20889 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
20890 -- choice since there are other compilers that do the same.
20892 or else Is_Composite_Type (Ent)
20893 then
20894 null;
20896 else
20897 Error_Pragma_Arg
20898 ("pragma % can only be applied to private, formal derived, "
20899 & "protected, or composite type", Arg1);
20900 end if;
20902 -- Give an error if the pragma is applied to a protected type that
20903 -- does not qualify (due to having entries, or due to components
20904 -- that do not qualify).
20906 if Is_Protected_Type (Ent)
20907 and then not Has_Preelaborable_Initialization (Ent)
20908 then
20909 Error_Msg_N
20910 ("protected type & does not have preelaborable "
20911 & "initialization", Ent);
20913 -- Otherwise mark the type as definitely having preelaborable
20914 -- initialization.
20916 else
20917 Set_Known_To_Have_Preelab_Init (Ent);
20918 end if;
20920 if Has_Pragma_Preelab_Init (Ent)
20921 and then Warn_On_Redundant_Constructs
20922 then
20923 Error_Pragma ("?r?duplicate pragma%!");
20924 else
20925 Set_Has_Pragma_Preelab_Init (Ent);
20926 end if;
20927 end Preelab_Init;
20929 --------------------
20930 -- Persistent_BSS --
20931 --------------------
20933 -- pragma Persistent_BSS [(object_NAME)];
20935 when Pragma_Persistent_BSS => Persistent_BSS : declare
20936 Decl : Node_Id;
20937 Ent : Entity_Id;
20938 Prag : Node_Id;
20940 begin
20941 GNAT_Pragma;
20942 Check_At_Most_N_Arguments (1);
20944 -- Case of application to specific object (one argument)
20946 if Arg_Count = 1 then
20947 Check_Arg_Is_Library_Level_Local_Name (Arg1);
20949 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
20950 or else
20951 Ekind (Entity (Get_Pragma_Arg (Arg1))) not in
20952 E_Variable | E_Constant
20953 then
20954 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
20955 end if;
20957 Ent := Entity (Get_Pragma_Arg (Arg1));
20959 -- A pragma that applies to a Ghost entity becomes Ghost for
20960 -- the purposes of legality checks and removal of ignored Ghost
20961 -- code.
20963 Mark_Ghost_Pragma (N, Ent);
20965 -- Check for duplication before inserting in list of
20966 -- representation items.
20968 Check_Duplicate_Pragma (Ent);
20970 if Rep_Item_Too_Late (Ent, N) then
20971 return;
20972 end if;
20974 Decl := Parent (Ent);
20976 if Present (Expression (Decl)) then
20977 -- Variables in Persistent_BSS cannot be initialized, so
20978 -- turn off any initialization that might be caused by
20979 -- pragmas Initialize_Scalars or Normalize_Scalars.
20981 if Kill_Range_Check (Expression (Decl)) then
20982 Prag :=
20983 Make_Pragma (Loc,
20984 Name_Suppress_Initialization,
20985 Pragma_Argument_Associations => New_List (
20986 Make_Pragma_Argument_Association (Loc,
20987 Expression => New_Occurrence_Of (Ent, Loc))));
20988 Insert_Before (N, Prag);
20989 Analyze (Prag);
20991 else
20992 Error_Pragma_Arg
20993 ("object for pragma% cannot have initialization", Arg1);
20994 end if;
20995 end if;
20997 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
20998 Error_Pragma_Arg
20999 ("object type for pragma% is not potentially persistent",
21000 Arg1);
21001 end if;
21003 Prag :=
21004 Make_Linker_Section_Pragma
21005 (Ent, Loc, ".persistent.bss");
21006 Insert_After (N, Prag);
21007 Analyze (Prag);
21009 -- Case of use as configuration pragma with no arguments
21011 else
21012 Check_Valid_Configuration_Pragma;
21013 Persistent_BSS_Mode := True;
21014 end if;
21015 end Persistent_BSS;
21017 --------------------
21018 -- Rename_Pragma --
21019 --------------------
21021 -- pragma Rename_Pragma (
21022 -- [New_Name =>] IDENTIFIER,
21023 -- [Renamed =>] pragma_IDENTIFIER);
21025 when Pragma_Rename_Pragma => Rename_Pragma : declare
21026 New_Name : constant Node_Id := Get_Pragma_Arg (Arg1);
21027 Old_Name : constant Node_Id := Get_Pragma_Arg (Arg2);
21029 begin
21030 GNAT_Pragma;
21031 Check_Valid_Configuration_Pragma;
21032 Check_Arg_Count (2);
21033 Check_Optional_Identifier (Arg1, Name_New_Name);
21034 Check_Optional_Identifier (Arg2, Name_Renamed);
21036 if Nkind (New_Name) /= N_Identifier then
21037 Error_Pragma_Arg ("identifier expected", Arg1);
21038 end if;
21040 if Nkind (Old_Name) /= N_Identifier then
21041 Error_Pragma_Arg ("identifier expected", Arg2);
21042 end if;
21044 -- The New_Name arg should not be an existing pragma (but we allow
21045 -- it; it's just a warning). The Old_Name arg must be an existing
21046 -- pragma.
21048 if Is_Pragma_Name (Chars (New_Name)) then
21049 Error_Pragma_Arg ("??pragma is already defined", Arg1);
21050 end if;
21052 if not Is_Pragma_Name (Chars (Old_Name)) then
21053 Error_Pragma_Arg ("existing pragma name expected", Arg1);
21054 end if;
21056 Map_Pragma_Name (From => Chars (New_Name), To => Chars (Old_Name));
21057 end Rename_Pragma;
21059 -----------------------------------
21060 -- Post/Post_Class/Postcondition --
21061 -----------------------------------
21063 -- pragma Post (Boolean_EXPRESSION);
21064 -- pragma Post_Class (Boolean_EXPRESSION);
21065 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
21066 -- [,[Message =>] String_EXPRESSION]);
21068 -- Characteristics:
21070 -- * Analysis - The annotation undergoes initial checks to verify
21071 -- the legal placement and context. Secondary checks preanalyze the
21072 -- expression in:
21074 -- Analyze_Pre_Post_Condition_In_Decl_Part
21076 -- * Expansion - The annotation is expanded during the expansion of
21077 -- the related subprogram [body] contract as performed in:
21079 -- Expand_Subprogram_Contract
21081 -- * Template - The annotation utilizes the generic template of the
21082 -- related subprogram [body] when it is:
21084 -- aspect on subprogram declaration
21085 -- aspect on stand-alone subprogram body
21086 -- pragma on stand-alone subprogram body
21088 -- The annotation must prepare its own template when it is:
21090 -- pragma on subprogram declaration
21092 -- * Globals - Capture of global references must occur after full
21093 -- analysis.
21095 -- * Instance - The annotation is instantiated automatically when
21096 -- the related generic subprogram [body] is instantiated except for
21097 -- the "pragma on subprogram declaration" case. In that scenario
21098 -- the annotation must instantiate itself.
21100 when Pragma_Post
21101 | Pragma_Post_Class
21102 | Pragma_Postcondition
21104 Analyze_Pre_Post_Condition;
21106 --------------------------------
21107 -- Pre/Pre_Class/Precondition --
21108 --------------------------------
21110 -- pragma Pre (Boolean_EXPRESSION);
21111 -- pragma Pre_Class (Boolean_EXPRESSION);
21112 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
21113 -- [,[Message =>] String_EXPRESSION]);
21115 -- Characteristics:
21117 -- * Analysis - The annotation undergoes initial checks to verify
21118 -- the legal placement and context. Secondary checks preanalyze the
21119 -- expression in:
21121 -- Analyze_Pre_Post_Condition_In_Decl_Part
21123 -- * Expansion - The annotation is expanded during the expansion of
21124 -- the related subprogram [body] contract as performed in:
21126 -- Expand_Subprogram_Contract
21128 -- * Template - The annotation utilizes the generic template of the
21129 -- related subprogram [body] when it is:
21131 -- aspect on subprogram declaration
21132 -- aspect on stand-alone subprogram body
21133 -- pragma on stand-alone subprogram body
21135 -- The annotation must prepare its own template when it is:
21137 -- pragma on subprogram declaration
21139 -- * Globals - Capture of global references must occur after full
21140 -- analysis.
21142 -- * Instance - The annotation is instantiated automatically when
21143 -- the related generic subprogram [body] is instantiated except for
21144 -- the "pragma on subprogram declaration" case. In that scenario
21145 -- the annotation must instantiate itself.
21147 when Pragma_Pre
21148 | Pragma_Pre_Class
21149 | Pragma_Precondition
21151 Analyze_Pre_Post_Condition;
21153 ---------------
21154 -- Predicate --
21155 ---------------
21157 -- pragma Predicate
21158 -- ([Entity =>] type_LOCAL_NAME,
21159 -- [Check =>] boolean_EXPRESSION);
21161 when Pragma_Predicate => Predicate : declare
21162 Discard : Boolean;
21163 Typ : Entity_Id;
21164 Type_Id : Node_Id;
21166 begin
21167 GNAT_Pragma;
21168 Check_Arg_Count (2);
21169 Check_Optional_Identifier (Arg1, Name_Entity);
21170 Check_Optional_Identifier (Arg2, Name_Check);
21172 Check_Arg_Is_Local_Name (Arg1);
21174 Type_Id := Get_Pragma_Arg (Arg1);
21175 Find_Type (Type_Id);
21176 Typ := Entity (Type_Id);
21178 if Typ = Any_Type then
21179 return;
21180 end if;
21182 -- A pragma that applies to a Ghost entity becomes Ghost for the
21183 -- purposes of legality checks and removal of ignored Ghost code.
21185 Mark_Ghost_Pragma (N, Typ);
21187 -- The remaining processing is simply to link the pragma on to
21188 -- the rep item chain, for processing when the type is frozen.
21189 -- This is accomplished by a call to Rep_Item_Too_Late. We also
21190 -- mark the type as having predicates.
21192 -- If the current policy for predicate checking is Ignore mark the
21193 -- subtype accordingly. In the case of predicates we consider them
21194 -- enabled unless Ignore is specified (either directly or with a
21195 -- general Assertion_Policy pragma) to preserve existing warnings.
21197 Set_Has_Predicates (Typ);
21199 -- Indicate that the pragma must be processed at the point the
21200 -- type is frozen, as is done for the corresponding aspect.
21202 Set_Has_Delayed_Aspects (Typ);
21203 Set_Has_Delayed_Freeze (Typ);
21205 Set_Predicates_Ignored (Typ,
21206 Policy_In_Effect (Name_Dynamic_Predicate) = Name_Ignore);
21207 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
21208 end Predicate;
21210 -----------------------
21211 -- Predicate_Failure --
21212 -----------------------
21214 -- pragma Predicate_Failure
21215 -- ([Entity =>] type_LOCAL_NAME,
21216 -- [Message =>] string_EXPRESSION);
21218 when Pragma_Predicate_Failure => Predicate_Failure : declare
21219 Discard : Boolean;
21220 Typ : Entity_Id;
21221 Type_Id : Node_Id;
21223 begin
21224 GNAT_Pragma;
21225 Check_Arg_Count (2);
21226 Check_Optional_Identifier (Arg1, Name_Entity);
21227 Check_Optional_Identifier (Arg2, Name_Message);
21229 Check_Arg_Is_Local_Name (Arg1);
21231 Type_Id := Get_Pragma_Arg (Arg1);
21232 Find_Type (Type_Id);
21233 Typ := Entity (Type_Id);
21235 if Typ = Any_Type then
21236 return;
21237 end if;
21239 -- A pragma that applies to a Ghost entity becomes Ghost for the
21240 -- purposes of legality checks and removal of ignored Ghost code.
21242 Mark_Ghost_Pragma (N, Typ);
21244 -- The remaining processing is simply to link the pragma on to
21245 -- the rep item chain, for processing when the type is frozen.
21246 -- This is accomplished by a call to Rep_Item_Too_Late.
21248 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
21249 end Predicate_Failure;
21251 ------------------
21252 -- Preelaborate --
21253 ------------------
21255 -- pragma Preelaborate [(library_unit_NAME)];
21257 -- Set the flag Is_Preelaborated of program unit name entity
21259 when Pragma_Preelaborate => Preelaborate : declare
21260 Pa : constant Node_Id := Parent (N);
21261 Pk : constant Node_Kind := Nkind (Pa);
21262 Ent : Entity_Id;
21264 begin
21265 Check_Ada_83_Warning;
21266 Check_Valid_Library_Unit_Pragma;
21268 if Nkind (N) = N_Null_Statement then
21269 return;
21270 end if;
21272 Ent := Find_Lib_Unit_Name;
21274 -- A pragma that applies to a Ghost entity becomes Ghost for the
21275 -- purposes of legality checks and removal of ignored Ghost code.
21277 Mark_Ghost_Pragma (N, Ent);
21278 Check_Duplicate_Pragma (Ent);
21280 -- This filters out pragmas inside generic parents that show up
21281 -- inside instantiations. Pragmas that come from aspects in the
21282 -- unit are not ignored.
21284 if Present (Ent) then
21285 if Pk = N_Package_Specification
21286 and then Present (Generic_Parent (Pa))
21287 and then not From_Aspect_Specification (N)
21288 then
21289 null;
21291 else
21292 if not Debug_Flag_U then
21293 Set_Is_Preelaborated (Ent);
21295 if Legacy_Elaboration_Checks then
21296 Set_Suppress_Elaboration_Warnings (Ent);
21297 end if;
21298 end if;
21299 end if;
21300 end if;
21301 end Preelaborate;
21303 -------------------------------
21304 -- Prefix_Exception_Messages --
21305 -------------------------------
21307 -- pragma Prefix_Exception_Messages;
21309 when Pragma_Prefix_Exception_Messages =>
21310 GNAT_Pragma;
21311 Check_Valid_Configuration_Pragma;
21312 Check_Arg_Count (0);
21313 Prefix_Exception_Messages := True;
21315 --------------
21316 -- Priority --
21317 --------------
21319 -- pragma Priority (EXPRESSION);
21321 when Pragma_Priority => Priority : declare
21322 P : constant Node_Id := Parent (N);
21323 Arg : Node_Id;
21324 Ent : Entity_Id;
21326 begin
21327 Check_No_Identifiers;
21328 Check_Arg_Count (1);
21330 -- Subprogram case
21332 if Nkind (P) = N_Subprogram_Body then
21333 Check_In_Main_Program;
21335 Ent := Defining_Unit_Name (Specification (P));
21337 if Nkind (Ent) = N_Defining_Program_Unit_Name then
21338 Ent := Defining_Identifier (Ent);
21339 end if;
21341 Arg := Get_Pragma_Arg (Arg1);
21342 Analyze_And_Resolve (Arg, Standard_Integer);
21344 -- Must be static
21346 if not Is_OK_Static_Expression (Arg) then
21347 Flag_Non_Static_Expr
21348 ("main subprogram priority is not static!", Arg);
21349 raise Pragma_Exit;
21351 -- If constraint error, then we already signalled an error
21353 elsif Raises_Constraint_Error (Arg) then
21354 null;
21356 -- Otherwise check in range except if Relaxed_RM_Semantics
21357 -- where we ignore the value if out of range.
21359 else
21360 if not Relaxed_RM_Semantics
21361 and then not Is_In_Range (Arg, RTE (RE_Priority))
21362 then
21363 Error_Pragma_Arg
21364 ("main subprogram priority is out of range", Arg1);
21365 else
21366 Set_Main_Priority
21367 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
21368 end if;
21369 end if;
21371 -- Load an arbitrary entity from System.Tasking.Stages or
21372 -- System.Tasking.Restricted.Stages (depending on the
21373 -- supported profile) to make sure that one of these packages
21374 -- is implicitly with'ed, since we need to have the tasking
21375 -- run time active for the pragma Priority to have any effect.
21376 -- Previously we with'ed the package System.Tasking, but this
21377 -- package does not trigger the required initialization of the
21378 -- run-time library.
21380 declare
21381 Discard : Entity_Id;
21382 pragma Warnings (Off, Discard);
21383 begin
21384 if Restricted_Profile then
21385 Discard := RTE (RE_Activate_Restricted_Tasks);
21386 else
21387 Discard := RTE (RE_Activate_Tasks);
21388 end if;
21389 end;
21391 -- Task or Protected, must be of type Integer
21393 elsif Nkind (P) in N_Protected_Definition | N_Task_Definition then
21394 Arg := Get_Pragma_Arg (Arg1);
21395 Ent := Defining_Identifier (Parent (P));
21397 -- The expression must be analyzed in the special manner
21398 -- described in "Handling of Default and Per-Object
21399 -- Expressions" in sem.ads.
21401 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
21403 if not Is_OK_Static_Expression (Arg) then
21404 Check_Restriction (Static_Priorities, Arg);
21405 end if;
21407 -- Anything else is incorrect
21409 else
21410 Pragma_Misplaced;
21411 end if;
21413 -- Check duplicate pragma before we chain the pragma in the Rep
21414 -- Item chain of Ent.
21416 Check_Duplicate_Pragma (Ent);
21417 Record_Rep_Item (Ent, N);
21418 end Priority;
21420 -----------------------------------
21421 -- Priority_Specific_Dispatching --
21422 -----------------------------------
21424 -- pragma Priority_Specific_Dispatching (
21425 -- policy_IDENTIFIER,
21426 -- first_priority_EXPRESSION,
21427 -- last_priority_EXPRESSION);
21429 when Pragma_Priority_Specific_Dispatching =>
21430 Priority_Specific_Dispatching : declare
21431 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
21432 -- This is the entity System.Any_Priority;
21434 DP : Character;
21435 Lower_Bound : Node_Id;
21436 Upper_Bound : Node_Id;
21437 Lower_Val : Uint;
21438 Upper_Val : Uint;
21440 begin
21441 Ada_2005_Pragma;
21442 Check_Arg_Count (3);
21443 Check_No_Identifiers;
21444 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
21445 Check_Valid_Configuration_Pragma;
21446 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21447 DP := Fold_Upper (Name_Buffer (1));
21449 Lower_Bound := Get_Pragma_Arg (Arg2);
21450 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
21451 Lower_Val := Expr_Value (Lower_Bound);
21453 Upper_Bound := Get_Pragma_Arg (Arg3);
21454 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
21455 Upper_Val := Expr_Value (Upper_Bound);
21457 -- It is not allowed to use Task_Dispatching_Policy and
21458 -- Priority_Specific_Dispatching in the same partition.
21460 if Task_Dispatching_Policy /= ' ' then
21461 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21462 Error_Pragma
21463 ("pragma% incompatible with Task_Dispatching_Policy#");
21465 -- Check lower bound in range
21467 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
21468 or else
21469 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
21470 then
21471 Error_Pragma_Arg
21472 ("first_priority is out of range", Arg2);
21474 -- Check upper bound in range
21476 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
21477 or else
21478 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
21479 then
21480 Error_Pragma_Arg
21481 ("last_priority is out of range", Arg3);
21483 -- Check that the priority range is valid
21485 elsif Lower_Val > Upper_Val then
21486 Error_Pragma
21487 ("last_priority_expression must be greater than or equal to "
21488 & "first_priority_expression");
21490 -- Store the new policy, but always preserve System_Location since
21491 -- we like the error message with the run-time name.
21493 else
21494 -- Check overlapping in the priority ranges specified in other
21495 -- Priority_Specific_Dispatching pragmas within the same
21496 -- partition. We can only check those we know about.
21498 for J in
21499 Specific_Dispatching.First .. Specific_Dispatching.Last
21500 loop
21501 if Specific_Dispatching.Table (J).First_Priority in
21502 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
21503 or else Specific_Dispatching.Table (J).Last_Priority in
21504 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
21505 then
21506 Error_Msg_Sloc :=
21507 Specific_Dispatching.Table (J).Pragma_Loc;
21508 Error_Pragma
21509 ("priority range overlaps with "
21510 & "Priority_Specific_Dispatching#");
21511 end if;
21512 end loop;
21514 -- The use of Priority_Specific_Dispatching is incompatible
21515 -- with Task_Dispatching_Policy.
21517 if Task_Dispatching_Policy /= ' ' then
21518 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21519 Error_Pragma
21520 ("Priority_Specific_Dispatching incompatible "
21521 & "with Task_Dispatching_Policy#");
21522 end if;
21524 -- The use of Priority_Specific_Dispatching forces ceiling
21525 -- locking policy.
21527 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
21528 Error_Msg_Sloc := Locking_Policy_Sloc;
21529 Error_Pragma
21530 ("Priority_Specific_Dispatching incompatible "
21531 & "with Locking_Policy#");
21533 -- Set the Ceiling_Locking policy, but preserve System_Location
21534 -- since we like the error message with the run time name.
21536 else
21537 Locking_Policy := 'C';
21539 if Locking_Policy_Sloc /= System_Location then
21540 Locking_Policy_Sloc := Loc;
21541 end if;
21542 end if;
21544 -- Add entry in the table
21546 Specific_Dispatching.Append
21547 ((Dispatching_Policy => DP,
21548 First_Priority => UI_To_Int (Lower_Val),
21549 Last_Priority => UI_To_Int (Upper_Val),
21550 Pragma_Loc => Loc));
21551 end if;
21552 end Priority_Specific_Dispatching;
21554 -------------
21555 -- Profile --
21556 -------------
21558 -- pragma Profile (profile_IDENTIFIER);
21560 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
21562 when Pragma_Profile =>
21563 Ada_2005_Pragma;
21564 Check_Arg_Count (1);
21565 Check_Valid_Configuration_Pragma;
21566 Check_No_Identifiers;
21568 declare
21569 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21571 begin
21572 if Chars (Argx) = Name_Ravenscar then
21573 Set_Ravenscar_Profile (Ravenscar, N);
21575 elsif Chars (Argx) = Name_Jorvik then
21576 Set_Ravenscar_Profile (Jorvik, N);
21578 elsif Chars (Argx) = Name_Gnat_Extended_Ravenscar then
21579 Set_Ravenscar_Profile (GNAT_Extended_Ravenscar, N);
21581 elsif Chars (Argx) = Name_Gnat_Ravenscar_EDF then
21582 Set_Ravenscar_Profile (GNAT_Ravenscar_EDF, N);
21584 elsif Chars (Argx) = Name_Restricted then
21585 Set_Profile_Restrictions
21586 (Restricted,
21587 N, Warn => Treat_Restrictions_As_Warnings);
21589 elsif Chars (Argx) = Name_Rational then
21590 Set_Rational_Profile;
21592 elsif Chars (Argx) = Name_No_Implementation_Extensions then
21593 Set_Profile_Restrictions
21594 (No_Implementation_Extensions,
21595 N, Warn => Treat_Restrictions_As_Warnings);
21597 else
21598 Error_Pragma_Arg ("& is not a valid profile", Argx);
21599 end if;
21600 end;
21602 ----------------------
21603 -- Profile_Warnings --
21604 ----------------------
21606 -- pragma Profile_Warnings (profile_IDENTIFIER);
21608 -- profile_IDENTIFIER => Restricted | Ravenscar
21610 when Pragma_Profile_Warnings =>
21611 GNAT_Pragma;
21612 Check_Arg_Count (1);
21613 Check_Valid_Configuration_Pragma;
21614 Check_No_Identifiers;
21616 declare
21617 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21619 begin
21620 if Chars (Argx) = Name_Ravenscar then
21621 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
21623 elsif Chars (Argx) = Name_Restricted then
21624 Set_Profile_Restrictions (Restricted, N, Warn => True);
21626 elsif Chars (Argx) = Name_No_Implementation_Extensions then
21627 Set_Profile_Restrictions
21628 (No_Implementation_Extensions, N, Warn => True);
21630 else
21631 Error_Pragma_Arg ("& is not a valid profile", Argx);
21632 end if;
21633 end;
21635 --------------------------
21636 -- Propagate_Exceptions --
21637 --------------------------
21639 -- pragma Propagate_Exceptions;
21641 -- Note: this pragma is obsolete and has no effect
21643 when Pragma_Propagate_Exceptions =>
21644 GNAT_Pragma;
21645 Check_Arg_Count (0);
21647 if Warn_On_Obsolescent_Feature then
21648 Error_Msg_N
21649 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
21650 "and has no effect?j?", N);
21651 end if;
21653 -----------------------------
21654 -- Provide_Shift_Operators --
21655 -----------------------------
21657 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
21659 when Pragma_Provide_Shift_Operators =>
21660 Provide_Shift_Operators : declare
21661 Ent : Entity_Id;
21663 procedure Declare_Shift_Operator (Nam : Name_Id);
21664 -- Insert declaration and pragma Instrinsic for named shift op
21666 ----------------------------
21667 -- Declare_Shift_Operator --
21668 ----------------------------
21670 procedure Declare_Shift_Operator (Nam : Name_Id) is
21671 Func : Node_Id;
21672 Import : Node_Id;
21674 begin
21675 Func :=
21676 Make_Subprogram_Declaration (Loc,
21677 Make_Function_Specification (Loc,
21678 Defining_Unit_Name =>
21679 Make_Defining_Identifier (Loc, Chars => Nam),
21681 Result_Definition =>
21682 Make_Identifier (Loc, Chars => Chars (Ent)),
21684 Parameter_Specifications => New_List (
21685 Make_Parameter_Specification (Loc,
21686 Defining_Identifier =>
21687 Make_Defining_Identifier (Loc, Name_Value),
21688 Parameter_Type =>
21689 Make_Identifier (Loc, Chars => Chars (Ent))),
21691 Make_Parameter_Specification (Loc,
21692 Defining_Identifier =>
21693 Make_Defining_Identifier (Loc, Name_Amount),
21694 Parameter_Type =>
21695 New_Occurrence_Of (Standard_Natural, Loc)))));
21697 Import :=
21698 Make_Pragma (Loc,
21699 Chars => Name_Import,
21700 Pragma_Argument_Associations => New_List (
21701 Make_Pragma_Argument_Association (Loc,
21702 Expression => Make_Identifier (Loc, Name_Intrinsic)),
21703 Make_Pragma_Argument_Association (Loc,
21704 Expression => Make_Identifier (Loc, Nam))));
21706 Insert_After (N, Import);
21707 Insert_After (N, Func);
21708 end Declare_Shift_Operator;
21710 -- Start of processing for Provide_Shift_Operators
21712 begin
21713 GNAT_Pragma;
21714 Check_Arg_Count (1);
21715 Check_Arg_Is_Local_Name (Arg1);
21717 Arg1 := Get_Pragma_Arg (Arg1);
21719 -- We must have an entity name
21721 if not Is_Entity_Name (Arg1) then
21722 Error_Pragma_Arg
21723 ("pragma % must apply to integer first subtype", Arg1);
21724 end if;
21726 -- If no Entity, means there was a prior error so ignore
21728 if Present (Entity (Arg1)) then
21729 Ent := Entity (Arg1);
21731 -- Apply error checks
21733 if not Is_First_Subtype (Ent) then
21734 Error_Pragma_Arg
21735 ("cannot apply pragma %",
21736 "\& is not a first subtype",
21737 Arg1);
21739 elsif not Is_Integer_Type (Ent) then
21740 Error_Pragma_Arg
21741 ("cannot apply pragma %",
21742 "\& is not an integer type",
21743 Arg1);
21745 elsif Has_Shift_Operator (Ent) then
21746 Error_Pragma_Arg
21747 ("cannot apply pragma %",
21748 "\& already has declared shift operators",
21749 Arg1);
21751 elsif Is_Frozen (Ent) then
21752 Error_Pragma_Arg
21753 ("pragma % appears too late",
21754 "\& is already frozen",
21755 Arg1);
21756 end if;
21758 -- Now declare the operators. We do this during analysis rather
21759 -- than expansion, since we want the operators available if we
21760 -- are operating in -gnatc mode.
21762 Declare_Shift_Operator (Name_Rotate_Left);
21763 Declare_Shift_Operator (Name_Rotate_Right);
21764 Declare_Shift_Operator (Name_Shift_Left);
21765 Declare_Shift_Operator (Name_Shift_Right);
21766 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
21767 end if;
21768 end Provide_Shift_Operators;
21770 ------------------
21771 -- Psect_Object --
21772 ------------------
21774 -- pragma Psect_Object (
21775 -- [Internal =>] LOCAL_NAME,
21776 -- [, [External =>] EXTERNAL_SYMBOL]
21777 -- [, [Size =>] EXTERNAL_SYMBOL]);
21779 when Pragma_Common_Object
21780 | Pragma_Psect_Object
21782 Psect_Object : declare
21783 Args : Args_List (1 .. 3);
21784 Names : constant Name_List (1 .. 3) := (
21785 Name_Internal,
21786 Name_External,
21787 Name_Size);
21789 Internal : Node_Id renames Args (1);
21790 External : Node_Id renames Args (2);
21791 Size : Node_Id renames Args (3);
21793 Def_Id : Entity_Id;
21795 procedure Check_Arg (Arg : Node_Id);
21796 -- Checks that argument is either a string literal or an
21797 -- identifier, and posts error message if not.
21799 ---------------
21800 -- Check_Arg --
21801 ---------------
21803 procedure Check_Arg (Arg : Node_Id) is
21804 begin
21805 if Nkind (Original_Node (Arg)) not in
21806 N_String_Literal | N_Identifier
21807 then
21808 Error_Pragma_Arg
21809 ("inappropriate argument for pragma %", Arg);
21810 end if;
21811 end Check_Arg;
21813 -- Start of processing for Common_Object/Psect_Object
21815 begin
21816 GNAT_Pragma;
21817 Gather_Associations (Names, Args);
21818 Process_Extended_Import_Export_Internal_Arg (Internal);
21820 Def_Id := Entity (Internal);
21822 if Ekind (Def_Id) not in E_Constant | E_Variable then
21823 Error_Pragma_Arg
21824 ("pragma% must designate an object", Internal);
21825 end if;
21827 Check_Arg (Internal);
21829 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
21830 Error_Pragma_Arg
21831 ("cannot use pragma% for imported/exported object",
21832 Internal);
21833 end if;
21835 if Is_Concurrent_Type (Etype (Internal)) then
21836 Error_Pragma_Arg
21837 ("cannot specify pragma % for task/protected object",
21838 Internal);
21839 end if;
21841 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
21842 or else
21843 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
21844 then
21845 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
21846 end if;
21848 if Ekind (Def_Id) = E_Constant then
21849 Error_Pragma_Arg
21850 ("cannot specify pragma % for a constant", Internal);
21851 end if;
21853 if Is_Record_Type (Etype (Internal)) then
21854 declare
21855 Ent : Entity_Id;
21856 Decl : Entity_Id;
21858 begin
21859 Ent := First_Entity (Etype (Internal));
21860 while Present (Ent) loop
21861 Decl := Declaration_Node (Ent);
21863 if Ekind (Ent) = E_Component
21864 and then Nkind (Decl) = N_Component_Declaration
21865 and then Present (Expression (Decl))
21866 and then Warn_On_Export_Import
21867 then
21868 Error_Msg_N
21869 ("?x?object for pragma % has defaults", Internal);
21870 exit;
21872 else
21873 Next_Entity (Ent);
21874 end if;
21875 end loop;
21876 end;
21877 end if;
21879 if Present (Size) then
21880 Check_Arg (Size);
21881 end if;
21883 if Present (External) then
21884 Check_Arg_Is_External_Name (External);
21885 end if;
21887 -- If all error tests pass, link pragma on to the rep item chain
21889 Record_Rep_Item (Def_Id, N);
21890 end Psect_Object;
21892 ----------
21893 -- Pure --
21894 ----------
21896 -- pragma Pure [(library_unit_NAME)];
21898 when Pragma_Pure => Pure : declare
21899 Ent : Entity_Id;
21901 begin
21902 Check_Ada_83_Warning;
21904 -- If the pragma comes from a subprogram instantiation, nothing to
21905 -- check, this can happen at any level of nesting.
21907 if Is_Wrapper_Package (Current_Scope) then
21908 return;
21909 else
21910 Check_Valid_Library_Unit_Pragma;
21911 end if;
21913 if Nkind (N) = N_Null_Statement then
21914 return;
21915 end if;
21917 Ent := Find_Lib_Unit_Name;
21919 -- A pragma that applies to a Ghost entity becomes Ghost for the
21920 -- purposes of legality checks and removal of ignored Ghost code.
21922 Mark_Ghost_Pragma (N, Ent);
21924 if not Debug_Flag_U then
21925 Set_Is_Pure (Ent);
21926 Set_Has_Pragma_Pure (Ent);
21928 if Legacy_Elaboration_Checks then
21929 Set_Suppress_Elaboration_Warnings (Ent);
21930 end if;
21931 end if;
21932 end Pure;
21934 -------------------
21935 -- Pure_Function --
21936 -------------------
21938 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
21940 when Pragma_Pure_Function => Pure_Function : declare
21941 Def_Id : Entity_Id;
21942 E : Entity_Id;
21943 E_Id : Node_Id;
21944 Effective : Boolean := False;
21945 Orig_Def : Entity_Id;
21946 Same_Decl : Boolean := False;
21948 begin
21949 GNAT_Pragma;
21950 Check_Arg_Count (1);
21951 Check_Optional_Identifier (Arg1, Name_Entity);
21952 Check_Arg_Is_Local_Name (Arg1);
21953 E_Id := Get_Pragma_Arg (Arg1);
21955 if Etype (E_Id) = Any_Type then
21956 return;
21957 end if;
21959 -- Loop through homonyms (overloadings) of referenced entity
21961 E := Entity (E_Id);
21963 -- A pragma that applies to a Ghost entity becomes Ghost for the
21964 -- purposes of legality checks and removal of ignored Ghost code.
21966 Mark_Ghost_Pragma (N, E);
21968 if Present (E) then
21969 loop
21970 Def_Id := Get_Base_Subprogram (E);
21972 if Ekind (Def_Id) not in
21973 E_Function | E_Generic_Function | E_Operator
21974 then
21975 Error_Pragma_Arg
21976 ("pragma% requires a function name", Arg1);
21977 end if;
21979 -- When we have a generic function we must jump up a level
21980 -- to the declaration of the wrapper package itself.
21982 Orig_Def := Def_Id;
21984 if Is_Generic_Instance (Def_Id) then
21985 while Nkind (Orig_Def) /= N_Package_Declaration loop
21986 Orig_Def := Parent (Orig_Def);
21987 end loop;
21988 end if;
21990 if In_Same_Declarative_Part (Parent (N), Orig_Def) then
21991 Same_Decl := True;
21992 Set_Is_Pure (Def_Id);
21994 if not Has_Pragma_Pure_Function (Def_Id) then
21995 Set_Has_Pragma_Pure_Function (Def_Id);
21996 Effective := True;
21997 end if;
21998 end if;
22000 exit when From_Aspect_Specification (N);
22001 E := Homonym (E);
22002 exit when No (E) or else Scope (E) /= Current_Scope;
22003 end loop;
22005 if not Effective
22006 and then Warn_On_Redundant_Constructs
22007 then
22008 Error_Msg_NE
22009 ("pragma Pure_Function on& is redundant?r?",
22010 N, Entity (E_Id));
22012 elsif not Same_Decl then
22013 Error_Pragma_Arg
22014 ("pragma% argument must be in same declarative part",
22015 Arg1);
22016 end if;
22017 end if;
22018 end Pure_Function;
22020 --------------------
22021 -- Queuing_Policy --
22022 --------------------
22024 -- pragma Queuing_Policy (policy_IDENTIFIER);
22026 when Pragma_Queuing_Policy => declare
22027 QP : Character;
22029 begin
22030 Check_Ada_83_Warning;
22031 Check_Arg_Count (1);
22032 Check_No_Identifiers;
22033 Check_Arg_Is_Queuing_Policy (Arg1);
22034 Check_Valid_Configuration_Pragma;
22035 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
22036 QP := Fold_Upper (Name_Buffer (1));
22038 if Queuing_Policy /= ' '
22039 and then Queuing_Policy /= QP
22040 then
22041 Error_Msg_Sloc := Queuing_Policy_Sloc;
22042 Error_Pragma ("queuing policy incompatible with policy#");
22044 -- Set new policy, but always preserve System_Location since we
22045 -- like the error message with the run time name.
22047 else
22048 Queuing_Policy := QP;
22050 if Queuing_Policy_Sloc /= System_Location then
22051 Queuing_Policy_Sloc := Loc;
22052 end if;
22053 end if;
22054 end;
22056 --------------
22057 -- Rational --
22058 --------------
22060 -- pragma Rational, for compatibility with foreign compiler
22062 when Pragma_Rational =>
22063 Set_Rational_Profile;
22065 ---------------------
22066 -- Refined_Depends --
22067 ---------------------
22069 -- pragma Refined_Depends (DEPENDENCY_RELATION);
22071 -- DEPENDENCY_RELATION ::=
22072 -- null
22073 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
22075 -- DEPENDENCY_CLAUSE ::=
22076 -- OUTPUT_LIST =>[+] INPUT_LIST
22077 -- | NULL_DEPENDENCY_CLAUSE
22079 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
22081 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
22083 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
22085 -- OUTPUT ::= NAME | FUNCTION_RESULT
22086 -- INPUT ::= NAME
22088 -- where FUNCTION_RESULT is a function Result attribute_reference
22090 -- Characteristics:
22092 -- * Analysis - The annotation undergoes initial checks to verify
22093 -- the legal placement and context. Secondary checks fully analyze
22094 -- the dependency clauses/global list in:
22096 -- Analyze_Refined_Depends_In_Decl_Part
22098 -- * Expansion - None.
22100 -- * Template - The annotation utilizes the generic template of the
22101 -- related subprogram body.
22103 -- * Globals - Capture of global references must occur after full
22104 -- analysis.
22106 -- * Instance - The annotation is instantiated automatically when
22107 -- the related generic subprogram body is instantiated.
22109 when Pragma_Refined_Depends => Refined_Depends : declare
22110 Body_Id : Entity_Id;
22111 Legal : Boolean;
22112 Spec_Id : Entity_Id;
22114 begin
22115 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22117 if Legal then
22119 -- Chain the pragma on the contract for further processing by
22120 -- Analyze_Refined_Depends_In_Decl_Part.
22122 Add_Contract_Item (N, Body_Id);
22124 -- The legality checks of pragmas Refined_Depends and
22125 -- Refined_Global are affected by the SPARK mode in effect and
22126 -- the volatility of the context. In addition these two pragmas
22127 -- are subject to an inherent order:
22129 -- 1) Refined_Global
22130 -- 2) Refined_Depends
22132 -- Analyze all these pragmas in the order outlined above
22134 Analyze_If_Present (Pragma_SPARK_Mode);
22135 Analyze_If_Present (Pragma_Volatile_Function);
22136 Analyze_If_Present (Pragma_Refined_Global);
22137 Analyze_Refined_Depends_In_Decl_Part (N);
22138 end if;
22139 end Refined_Depends;
22141 --------------------
22142 -- Refined_Global --
22143 --------------------
22145 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
22147 -- GLOBAL_SPECIFICATION ::=
22148 -- null
22149 -- | (GLOBAL_LIST)
22150 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
22152 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
22154 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
22155 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
22156 -- GLOBAL_ITEM ::= NAME
22158 -- Characteristics:
22160 -- * Analysis - The annotation undergoes initial checks to verify
22161 -- the legal placement and context. Secondary checks fully analyze
22162 -- the dependency clauses/global list in:
22164 -- Analyze_Refined_Global_In_Decl_Part
22166 -- * Expansion - None.
22168 -- * Template - The annotation utilizes the generic template of the
22169 -- related subprogram body.
22171 -- * Globals - Capture of global references must occur after full
22172 -- analysis.
22174 -- * Instance - The annotation is instantiated automatically when
22175 -- the related generic subprogram body is instantiated.
22177 when Pragma_Refined_Global => Refined_Global : declare
22178 Body_Id : Entity_Id;
22179 Legal : Boolean;
22180 Spec_Id : Entity_Id;
22182 begin
22183 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22185 if Legal then
22187 -- Chain the pragma on the contract for further processing by
22188 -- Analyze_Refined_Global_In_Decl_Part.
22190 Add_Contract_Item (N, Body_Id);
22192 -- The legality checks of pragmas Refined_Depends and
22193 -- Refined_Global are affected by the SPARK mode in effect and
22194 -- the volatility of the context. In addition these two pragmas
22195 -- are subject to an inherent order:
22197 -- 1) Refined_Global
22198 -- 2) Refined_Depends
22200 -- Analyze all these pragmas in the order outlined above
22202 Analyze_If_Present (Pragma_SPARK_Mode);
22203 Analyze_If_Present (Pragma_Volatile_Function);
22204 Analyze_Refined_Global_In_Decl_Part (N);
22205 Analyze_If_Present (Pragma_Refined_Depends);
22206 end if;
22207 end Refined_Global;
22209 ------------------
22210 -- Refined_Post --
22211 ------------------
22213 -- pragma Refined_Post (boolean_EXPRESSION);
22215 -- Characteristics:
22217 -- * Analysis - The annotation is fully analyzed immediately upon
22218 -- elaboration as it cannot forward reference entities.
22220 -- * Expansion - The annotation is expanded during the expansion of
22221 -- the related subprogram body contract as performed in:
22223 -- Expand_Subprogram_Contract
22225 -- * Template - The annotation utilizes the generic template of the
22226 -- related subprogram body.
22228 -- * Globals - Capture of global references must occur after full
22229 -- analysis.
22231 -- * Instance - The annotation is instantiated automatically when
22232 -- the related generic subprogram body is instantiated.
22234 when Pragma_Refined_Post => Refined_Post : declare
22235 Body_Id : Entity_Id;
22236 Legal : Boolean;
22237 Spec_Id : Entity_Id;
22239 begin
22240 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
22242 -- Fully analyze the pragma when it appears inside a subprogram
22243 -- body because it cannot benefit from forward references.
22245 if Legal then
22247 -- Chain the pragma on the contract for completeness
22249 Add_Contract_Item (N, Body_Id);
22251 -- The legality checks of pragma Refined_Post are affected by
22252 -- the SPARK mode in effect and the volatility of the context.
22253 -- Analyze all pragmas in a specific order.
22255 Analyze_If_Present (Pragma_SPARK_Mode);
22256 Analyze_If_Present (Pragma_Volatile_Function);
22257 Analyze_Pre_Post_Condition_In_Decl_Part (N);
22259 -- Currently it is not possible to inline pre/postconditions on
22260 -- a subprogram subject to pragma Inline_Always.
22262 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
22263 end if;
22264 end Refined_Post;
22266 -------------------
22267 -- Refined_State --
22268 -------------------
22270 -- pragma Refined_State (REFINEMENT_LIST);
22272 -- REFINEMENT_LIST ::=
22273 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
22275 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
22277 -- CONSTITUENT_LIST ::=
22278 -- null
22279 -- | CONSTITUENT
22280 -- | (CONSTITUENT {, CONSTITUENT})
22282 -- CONSTITUENT ::= object_NAME | state_NAME
22284 -- Characteristics:
22286 -- * Analysis - The annotation undergoes initial checks to verify
22287 -- the legal placement and context. Secondary checks preanalyze the
22288 -- refinement clauses in:
22290 -- Analyze_Refined_State_In_Decl_Part
22292 -- * Expansion - None.
22294 -- * Template - The annotation utilizes the template of the related
22295 -- package body.
22297 -- * Globals - Capture of global references must occur after full
22298 -- analysis.
22300 -- * Instance - The annotation is instantiated automatically when
22301 -- the related generic package body is instantiated.
22303 when Pragma_Refined_State => Refined_State : declare
22304 Pack_Decl : Node_Id;
22305 Spec_Id : Entity_Id;
22307 begin
22308 GNAT_Pragma;
22309 Check_No_Identifiers;
22310 Check_Arg_Count (1);
22312 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
22314 if Nkind (Pack_Decl) /= N_Package_Body then
22315 Pragma_Misplaced;
22316 return;
22317 end if;
22319 Spec_Id := Corresponding_Spec (Pack_Decl);
22321 -- A pragma that applies to a Ghost entity becomes Ghost for the
22322 -- purposes of legality checks and removal of ignored Ghost code.
22324 Mark_Ghost_Pragma (N, Spec_Id);
22326 -- Chain the pragma on the contract for further processing by
22327 -- Analyze_Refined_State_In_Decl_Part.
22329 Add_Contract_Item (N, Defining_Entity (Pack_Decl));
22331 -- The legality checks of pragma Refined_State are affected by the
22332 -- SPARK mode in effect. Analyze all pragmas in a specific order.
22334 Analyze_If_Present (Pragma_SPARK_Mode);
22336 -- State refinement is allowed only when the corresponding package
22337 -- declaration has non-null pragma Abstract_State. Refinement not
22338 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
22340 if SPARK_Mode /= Off
22341 and then
22342 (No (Abstract_States (Spec_Id))
22343 or else Has_Null_Abstract_State (Spec_Id))
22344 then
22345 Error_Msg_NE
22346 ("useless refinement, package & does not define abstract "
22347 & "states", N, Spec_Id);
22348 return;
22349 end if;
22350 end Refined_State;
22352 -----------------------
22353 -- Relative_Deadline --
22354 -----------------------
22356 -- pragma Relative_Deadline (time_span_EXPRESSION);
22358 when Pragma_Relative_Deadline => Relative_Deadline : declare
22359 P : constant Node_Id := Parent (N);
22360 Arg : Node_Id;
22362 begin
22363 Ada_2005_Pragma;
22364 Check_No_Identifiers;
22365 Check_Arg_Count (1);
22367 Arg := Get_Pragma_Arg (Arg1);
22369 -- The expression must be analyzed in the special manner described
22370 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
22372 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
22374 -- Subprogram case
22376 if Nkind (P) = N_Subprogram_Body then
22377 Check_In_Main_Program;
22379 -- Only Task and subprogram cases allowed
22381 elsif Nkind (P) /= N_Task_Definition then
22382 Pragma_Misplaced;
22383 end if;
22385 -- Check duplicate pragma before we set the corresponding flag
22387 if Has_Relative_Deadline_Pragma (P) then
22388 Error_Pragma ("duplicate pragma% not allowed");
22389 end if;
22391 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
22392 -- Relative_Deadline pragma node cannot be inserted in the Rep
22393 -- Item chain of Ent since it is rewritten by the expander as a
22394 -- procedure call statement that will break the chain.
22396 Set_Has_Relative_Deadline_Pragma (P);
22397 end Relative_Deadline;
22399 ------------------------
22400 -- Remote_Access_Type --
22401 ------------------------
22403 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
22405 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
22406 E : Entity_Id;
22408 begin
22409 GNAT_Pragma;
22410 Check_Arg_Count (1);
22411 Check_Optional_Identifier (Arg1, Name_Entity);
22412 Check_Arg_Is_Local_Name (Arg1);
22414 E := Entity (Get_Pragma_Arg (Arg1));
22416 -- A pragma that applies to a Ghost entity becomes Ghost for the
22417 -- purposes of legality checks and removal of ignored Ghost code.
22419 Mark_Ghost_Pragma (N, E);
22421 if Nkind (Parent (E)) = N_Formal_Type_Declaration
22422 and then Ekind (E) = E_General_Access_Type
22423 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
22424 and then Scope (Root_Type (Directly_Designated_Type (E)))
22425 = Scope (E)
22426 and then Is_Valid_Remote_Object_Type
22427 (Root_Type (Directly_Designated_Type (E)))
22428 then
22429 Set_Is_Remote_Types (E);
22431 else
22432 Error_Pragma_Arg
22433 ("pragma% applies only to formal access-to-class-wide types",
22434 Arg1);
22435 end if;
22436 end Remote_Access_Type;
22438 ---------------------------
22439 -- Remote_Call_Interface --
22440 ---------------------------
22442 -- pragma Remote_Call_Interface [(library_unit_NAME)];
22444 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
22445 Cunit_Node : Node_Id;
22446 Cunit_Ent : Entity_Id;
22447 K : Node_Kind;
22449 begin
22450 Check_Ada_83_Warning;
22451 Check_Valid_Library_Unit_Pragma;
22453 if Nkind (N) = N_Null_Statement then
22454 return;
22455 end if;
22457 Cunit_Node := Cunit (Current_Sem_Unit);
22458 K := Nkind (Unit (Cunit_Node));
22459 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22461 -- A pragma that applies to a Ghost entity becomes Ghost for the
22462 -- purposes of legality checks and removal of ignored Ghost code.
22464 Mark_Ghost_Pragma (N, Cunit_Ent);
22466 if K = N_Package_Declaration
22467 or else K = N_Generic_Package_Declaration
22468 or else K = N_Subprogram_Declaration
22469 or else K = N_Generic_Subprogram_Declaration
22470 or else (K = N_Subprogram_Body
22471 and then Acts_As_Spec (Unit (Cunit_Node)))
22472 then
22473 null;
22474 else
22475 Error_Pragma (
22476 "pragma% must apply to package or subprogram declaration");
22477 end if;
22479 Set_Is_Remote_Call_Interface (Cunit_Ent);
22480 end Remote_Call_Interface;
22482 ------------------
22483 -- Remote_Types --
22484 ------------------
22486 -- pragma Remote_Types [(library_unit_NAME)];
22488 when Pragma_Remote_Types => Remote_Types : declare
22489 Cunit_Node : Node_Id;
22490 Cunit_Ent : Entity_Id;
22492 begin
22493 Check_Ada_83_Warning;
22494 Check_Valid_Library_Unit_Pragma;
22496 if Nkind (N) = N_Null_Statement then
22497 return;
22498 end if;
22500 Cunit_Node := Cunit (Current_Sem_Unit);
22501 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22503 -- A pragma that applies to a Ghost entity becomes Ghost for the
22504 -- purposes of legality checks and removal of ignored Ghost code.
22506 Mark_Ghost_Pragma (N, Cunit_Ent);
22508 if Nkind (Unit (Cunit_Node)) not in
22509 N_Package_Declaration | N_Generic_Package_Declaration
22510 then
22511 Error_Pragma
22512 ("pragma% can only apply to a package declaration");
22513 end if;
22515 Set_Is_Remote_Types (Cunit_Ent);
22516 end Remote_Types;
22518 ---------------
22519 -- Ravenscar --
22520 ---------------
22522 -- pragma Ravenscar;
22524 when Pragma_Ravenscar =>
22525 GNAT_Pragma;
22526 Check_Arg_Count (0);
22527 Check_Valid_Configuration_Pragma;
22528 Set_Ravenscar_Profile (Ravenscar, N);
22530 if Warn_On_Obsolescent_Feature then
22531 Error_Msg_N
22532 ("pragma Ravenscar is an obsolescent feature?j?", N);
22533 Error_Msg_N
22534 ("|use pragma Profile (Ravenscar) instead?j?", N);
22535 end if;
22537 -------------------------
22538 -- Restricted_Run_Time --
22539 -------------------------
22541 -- pragma Restricted_Run_Time;
22543 when Pragma_Restricted_Run_Time =>
22544 GNAT_Pragma;
22545 Check_Arg_Count (0);
22546 Check_Valid_Configuration_Pragma;
22547 Set_Profile_Restrictions
22548 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
22550 if Warn_On_Obsolescent_Feature then
22551 Error_Msg_N
22552 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
22554 Error_Msg_N
22555 ("|use pragma Profile (Restricted) instead?j?", N);
22556 end if;
22558 ------------------
22559 -- Restrictions --
22560 ------------------
22562 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
22564 -- RESTRICTION ::=
22565 -- restriction_IDENTIFIER
22566 -- | restriction_parameter_IDENTIFIER => EXPRESSION
22568 when Pragma_Restrictions =>
22569 Process_Restrictions_Or_Restriction_Warnings
22570 (Warn => Treat_Restrictions_As_Warnings);
22572 --------------------------
22573 -- Restriction_Warnings --
22574 --------------------------
22576 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
22578 -- RESTRICTION ::=
22579 -- restriction_IDENTIFIER
22580 -- | restriction_parameter_IDENTIFIER => EXPRESSION
22582 when Pragma_Restriction_Warnings =>
22583 GNAT_Pragma;
22584 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
22586 ----------------
22587 -- Reviewable --
22588 ----------------
22590 -- pragma Reviewable;
22592 when Pragma_Reviewable =>
22593 Check_Ada_83_Warning;
22594 Check_Arg_Count (0);
22596 -- Call dummy debugging function rv. This is done to assist front
22597 -- end debugging. By placing a Reviewable pragma in the source
22598 -- program, a breakpoint on rv catches this place in the source,
22599 -- allowing convenient stepping to the point of interest.
22603 --------------------------
22604 -- Secondary_Stack_Size --
22605 --------------------------
22607 -- pragma Secondary_Stack_Size (EXPRESSION);
22609 when Pragma_Secondary_Stack_Size => Secondary_Stack_Size : declare
22610 P : constant Node_Id := Parent (N);
22611 Arg : Node_Id;
22612 Ent : Entity_Id;
22614 begin
22615 GNAT_Pragma;
22616 Check_No_Identifiers;
22617 Check_Arg_Count (1);
22619 if Nkind (P) = N_Task_Definition then
22620 Arg := Get_Pragma_Arg (Arg1);
22621 Ent := Defining_Identifier (Parent (P));
22623 -- The expression must be analyzed in the special manner
22624 -- described in "Handling of Default Expressions" in sem.ads.
22626 Preanalyze_Spec_Expression (Arg, Any_Integer);
22628 -- The pragma cannot appear if the No_Secondary_Stack
22629 -- restriction is in effect.
22631 Check_Restriction (No_Secondary_Stack, Arg);
22633 -- Anything else is incorrect
22635 else
22636 Pragma_Misplaced;
22637 end if;
22639 -- Check duplicate pragma before we chain the pragma in the Rep
22640 -- Item chain of Ent.
22642 Check_Duplicate_Pragma (Ent);
22643 Record_Rep_Item (Ent, N);
22644 end Secondary_Stack_Size;
22646 --------------------------
22647 -- Short_Circuit_And_Or --
22648 --------------------------
22650 -- pragma Short_Circuit_And_Or;
22652 when Pragma_Short_Circuit_And_Or =>
22653 GNAT_Pragma;
22654 Check_Arg_Count (0);
22655 Check_Valid_Configuration_Pragma;
22656 Short_Circuit_And_Or := True;
22658 -------------------
22659 -- Share_Generic --
22660 -------------------
22662 -- pragma Share_Generic (GNAME {, GNAME});
22664 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
22666 when Pragma_Share_Generic =>
22667 GNAT_Pragma;
22668 Process_Generic_List;
22670 ------------
22671 -- Shared --
22672 ------------
22674 -- pragma Shared (LOCAL_NAME);
22676 when Pragma_Shared =>
22677 GNAT_Pragma;
22678 Process_Atomic_Independent_Shared_Volatile;
22680 --------------------
22681 -- Shared_Passive --
22682 --------------------
22684 -- pragma Shared_Passive [(library_unit_NAME)];
22686 -- Set the flag Is_Shared_Passive of program unit name entity
22688 when Pragma_Shared_Passive => Shared_Passive : declare
22689 Cunit_Node : Node_Id;
22690 Cunit_Ent : Entity_Id;
22692 begin
22693 Check_Ada_83_Warning;
22694 Check_Valid_Library_Unit_Pragma;
22696 if Nkind (N) = N_Null_Statement then
22697 return;
22698 end if;
22700 Cunit_Node := Cunit (Current_Sem_Unit);
22701 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22703 -- A pragma that applies to a Ghost entity becomes Ghost for the
22704 -- purposes of legality checks and removal of ignored Ghost code.
22706 Mark_Ghost_Pragma (N, Cunit_Ent);
22708 if Nkind (Unit (Cunit_Node)) not in
22709 N_Package_Declaration | N_Generic_Package_Declaration
22710 then
22711 Error_Pragma
22712 ("pragma% can only apply to a package declaration");
22713 end if;
22715 Set_Is_Shared_Passive (Cunit_Ent);
22716 end Shared_Passive;
22718 -----------------------
22719 -- Short_Descriptors --
22720 -----------------------
22722 -- pragma Short_Descriptors;
22724 -- Recognize and validate, but otherwise ignore
22726 when Pragma_Short_Descriptors =>
22727 GNAT_Pragma;
22728 Check_Arg_Count (0);
22729 Check_Valid_Configuration_Pragma;
22731 ------------------------------
22732 -- Simple_Storage_Pool_Type --
22733 ------------------------------
22735 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
22737 when Pragma_Simple_Storage_Pool_Type =>
22738 Simple_Storage_Pool_Type : declare
22739 Typ : Entity_Id;
22740 Type_Id : Node_Id;
22742 begin
22743 GNAT_Pragma;
22744 Check_Arg_Count (1);
22745 Check_Arg_Is_Library_Level_Local_Name (Arg1);
22747 Type_Id := Get_Pragma_Arg (Arg1);
22748 Find_Type (Type_Id);
22749 Typ := Entity (Type_Id);
22751 if Typ = Any_Type then
22752 return;
22753 end if;
22755 -- A pragma that applies to a Ghost entity becomes Ghost for the
22756 -- purposes of legality checks and removal of ignored Ghost code.
22758 Mark_Ghost_Pragma (N, Typ);
22760 -- We require the pragma to apply to a type declared in a package
22761 -- declaration, but not (immediately) within a package body.
22763 if Ekind (Current_Scope) /= E_Package
22764 or else In_Package_Body (Current_Scope)
22765 then
22766 Error_Pragma
22767 ("pragma% can only apply to type declared immediately "
22768 & "within a package declaration");
22769 end if;
22771 -- A simple storage pool type must be an immutably limited record
22772 -- or private type. If the pragma is given for a private type,
22773 -- the full type is similarly restricted (which is checked later
22774 -- in Freeze_Entity).
22776 if Is_Record_Type (Typ)
22777 and then not Is_Limited_View (Typ)
22778 then
22779 Error_Pragma
22780 ("pragma% can only apply to explicitly limited record type");
22782 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
22783 Error_Pragma
22784 ("pragma% can only apply to a private type that is limited");
22786 elsif not Is_Record_Type (Typ)
22787 and then not Is_Private_Type (Typ)
22788 then
22789 Error_Pragma
22790 ("pragma% can only apply to limited record or private type");
22791 end if;
22793 Record_Rep_Item (Typ, N);
22794 end Simple_Storage_Pool_Type;
22796 ----------------------
22797 -- Source_File_Name --
22798 ----------------------
22800 -- There are five forms for this pragma:
22802 -- pragma Source_File_Name (
22803 -- [UNIT_NAME =>] unit_NAME,
22804 -- BODY_FILE_NAME => STRING_LITERAL
22805 -- [, [INDEX =>] INTEGER_LITERAL]);
22807 -- pragma Source_File_Name (
22808 -- [UNIT_NAME =>] unit_NAME,
22809 -- SPEC_FILE_NAME => STRING_LITERAL
22810 -- [, [INDEX =>] INTEGER_LITERAL]);
22812 -- pragma Source_File_Name (
22813 -- BODY_FILE_NAME => STRING_LITERAL
22814 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22815 -- [, CASING => CASING_SPEC]);
22817 -- pragma Source_File_Name (
22818 -- SPEC_FILE_NAME => STRING_LITERAL
22819 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22820 -- [, CASING => CASING_SPEC]);
22822 -- pragma Source_File_Name (
22823 -- SUBUNIT_FILE_NAME => STRING_LITERAL
22824 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22825 -- [, CASING => CASING_SPEC]);
22827 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
22829 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
22830 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
22831 -- only be used when no project file is used, while SFNP can only be
22832 -- used when a project file is used.
22834 -- No processing here. Processing was completed during parsing, since
22835 -- we need to have file names set as early as possible. Units are
22836 -- loaded well before semantic processing starts.
22838 -- The only processing we defer to this point is the check for
22839 -- correct placement.
22841 when Pragma_Source_File_Name =>
22842 GNAT_Pragma;
22843 Check_Valid_Configuration_Pragma;
22845 ------------------------------
22846 -- Source_File_Name_Project --
22847 ------------------------------
22849 -- See Source_File_Name for syntax
22851 -- No processing here. Processing was completed during parsing, since
22852 -- we need to have file names set as early as possible. Units are
22853 -- loaded well before semantic processing starts.
22855 -- The only processing we defer to this point is the check for
22856 -- correct placement.
22858 when Pragma_Source_File_Name_Project =>
22859 GNAT_Pragma;
22860 Check_Valid_Configuration_Pragma;
22862 -- Check that a pragma Source_File_Name_Project is used only in a
22863 -- configuration pragmas file.
22865 -- Pragmas Source_File_Name_Project should only be generated by
22866 -- the Project Manager in configuration pragmas files.
22868 -- This is really an ugly test. It seems to depend on some
22869 -- accidental and undocumented property. At the very least it
22870 -- needs to be documented, but it would be better to have a
22871 -- clean way of testing if we are in a configuration file???
22873 if Present (Parent (N)) then
22874 Error_Pragma
22875 ("pragma% can only appear in a configuration pragmas file");
22876 end if;
22878 ----------------------
22879 -- Source_Reference --
22880 ----------------------
22882 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
22884 -- Nothing to do, all processing completed in Par.Prag, since we need
22885 -- the information for possible parser messages that are output.
22887 when Pragma_Source_Reference =>
22888 GNAT_Pragma;
22890 ----------------
22891 -- SPARK_Mode --
22892 ----------------
22894 -- pragma SPARK_Mode [(On | Off)];
22896 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
22897 Mode_Id : SPARK_Mode_Type;
22899 procedure Check_Pragma_Conformance
22900 (Context_Pragma : Node_Id;
22901 Entity : Entity_Id;
22902 Entity_Pragma : Node_Id);
22903 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
22904 -- conformance of pragma N depending the following scenarios:
22906 -- If pragma Context_Pragma is not Empty, verify that pragma N is
22907 -- compatible with the pragma Context_Pragma that was inherited
22908 -- from the context:
22909 -- * If the mode of Context_Pragma is ON, then the new mode can
22910 -- be anything.
22911 -- * If the mode of Context_Pragma is OFF, then the only allowed
22912 -- new mode is also OFF. Emit error if this is not the case.
22914 -- If Entity is not Empty, verify that pragma N is compatible with
22915 -- pragma Entity_Pragma that belongs to Entity.
22916 -- * If Entity_Pragma is Empty, always issue an error as this
22917 -- corresponds to the case where a previous section of Entity
22918 -- has no SPARK_Mode set.
22919 -- * If the mode of Entity_Pragma is ON, then the new mode can
22920 -- be anything.
22921 -- * If the mode of Entity_Pragma is OFF, then the only allowed
22922 -- new mode is also OFF. Emit error if this is not the case.
22924 procedure Check_Library_Level_Entity (E : Entity_Id);
22925 -- Subsidiary to routines Process_xxx. Verify that the related
22926 -- entity E subject to pragma SPARK_Mode is library-level.
22928 procedure Process_Body (Decl : Node_Id);
22929 -- Verify the legality of pragma SPARK_Mode when it appears as the
22930 -- top of the body declarations of entry, package, protected unit,
22931 -- subprogram or task unit body denoted by Decl.
22933 procedure Process_Overloadable (Decl : Node_Id);
22934 -- Verify the legality of pragma SPARK_Mode when it applies to an
22935 -- entry or [generic] subprogram declaration denoted by Decl.
22937 procedure Process_Private_Part (Decl : Node_Id);
22938 -- Verify the legality of pragma SPARK_Mode when it appears at the
22939 -- top of the private declarations of a package spec, protected or
22940 -- task unit declaration denoted by Decl.
22942 procedure Process_Statement_Part (Decl : Node_Id);
22943 -- Verify the legality of pragma SPARK_Mode when it appears at the
22944 -- top of the statement sequence of a package body denoted by node
22945 -- Decl.
22947 procedure Process_Visible_Part (Decl : Node_Id);
22948 -- Verify the legality of pragma SPARK_Mode when it appears at the
22949 -- top of the visible declarations of a package spec, protected or
22950 -- task unit declaration denoted by Decl. The routine is also used
22951 -- on protected or task units declared without a definition.
22953 procedure Set_SPARK_Context;
22954 -- Subsidiary to routines Process_xxx. Set the global variables
22955 -- which represent the mode of the context from pragma N. Ensure
22956 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
22958 ------------------------------
22959 -- Check_Pragma_Conformance --
22960 ------------------------------
22962 procedure Check_Pragma_Conformance
22963 (Context_Pragma : Node_Id;
22964 Entity : Entity_Id;
22965 Entity_Pragma : Node_Id)
22967 Err_Id : Entity_Id;
22968 Err_N : Node_Id;
22970 begin
22971 -- The current pragma may appear without an argument. If this
22972 -- is the case, associate all error messages with the pragma
22973 -- itself.
22975 if Present (Arg1) then
22976 Err_N := Arg1;
22977 else
22978 Err_N := N;
22979 end if;
22981 -- The mode of the current pragma is compared against that of
22982 -- an enclosing context.
22984 if Present (Context_Pragma) then
22985 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
22987 -- Issue an error if the new mode is less restrictive than
22988 -- that of the context.
22990 if Get_SPARK_Mode_From_Annotation (Context_Pragma) = Off
22991 and then Get_SPARK_Mode_From_Annotation (N) = On
22992 then
22993 Error_Msg_N
22994 ("cannot change SPARK_Mode from Off to On", Err_N);
22995 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
22996 Error_Msg_N ("\SPARK_Mode was set to Off#", Err_N);
22997 raise Pragma_Exit;
22998 end if;
22999 end if;
23001 -- The mode of the current pragma is compared against that of
23002 -- an initial package, protected type, subprogram or task type
23003 -- declaration.
23005 if Present (Entity) then
23007 -- A simple protected or task type is transformed into an
23008 -- anonymous type whose name cannot be used to issue error
23009 -- messages. Recover the original entity of the type.
23011 if Ekind (Entity) in E_Protected_Type | E_Task_Type then
23012 Err_Id :=
23013 Defining_Entity
23014 (Original_Node (Unit_Declaration_Node (Entity)));
23015 else
23016 Err_Id := Entity;
23017 end if;
23019 -- Both the initial declaration and the completion carry
23020 -- SPARK_Mode pragmas.
23022 if Present (Entity_Pragma) then
23023 pragma Assert (Nkind (Entity_Pragma) = N_Pragma);
23025 -- Issue an error if the new mode is less restrictive
23026 -- than that of the initial declaration.
23028 if Get_SPARK_Mode_From_Annotation (Entity_Pragma) = Off
23029 and then Get_SPARK_Mode_From_Annotation (N) = On
23030 then
23031 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
23032 Error_Msg_Sloc := Sloc (Entity_Pragma);
23033 Error_Msg_NE
23034 ("\value Off was set for SPARK_Mode on&#",
23035 Err_N, Err_Id);
23036 raise Pragma_Exit;
23037 end if;
23039 -- Otherwise the initial declaration lacks a SPARK_Mode
23040 -- pragma in which case the current pragma is illegal as
23041 -- it cannot "complete".
23043 elsif Get_SPARK_Mode_From_Annotation (N) = Off
23044 and then (Is_Generic_Unit (Entity) or else In_Instance)
23045 then
23046 null;
23048 else
23049 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
23050 Error_Msg_Sloc := Sloc (Err_Id);
23051 Error_Msg_NE
23052 ("\no value was set for SPARK_Mode on&#",
23053 Err_N, Err_Id);
23054 raise Pragma_Exit;
23055 end if;
23056 end if;
23057 end Check_Pragma_Conformance;
23059 --------------------------------
23060 -- Check_Library_Level_Entity --
23061 --------------------------------
23063 procedure Check_Library_Level_Entity (E : Entity_Id) is
23064 procedure Add_Entity_To_Name_Buffer;
23065 -- Add the E_Kind of entity E to the name buffer
23067 -------------------------------
23068 -- Add_Entity_To_Name_Buffer --
23069 -------------------------------
23071 procedure Add_Entity_To_Name_Buffer is
23072 begin
23073 if Ekind (E) in E_Entry | E_Entry_Family then
23074 Add_Str_To_Name_Buffer ("entry");
23076 elsif Ekind (E) in E_Generic_Package
23077 | E_Package
23078 | E_Package_Body
23079 then
23080 Add_Str_To_Name_Buffer ("package");
23082 elsif Ekind (E) in E_Protected_Body | E_Protected_Type then
23083 Add_Str_To_Name_Buffer ("protected type");
23085 elsif Ekind (E) in E_Function
23086 | E_Generic_Function
23087 | E_Generic_Procedure
23088 | E_Procedure
23089 | E_Subprogram_Body
23090 then
23091 Add_Str_To_Name_Buffer ("subprogram");
23093 else
23094 pragma Assert (Ekind (E) in E_Task_Body | E_Task_Type);
23095 Add_Str_To_Name_Buffer ("task type");
23096 end if;
23097 end Add_Entity_To_Name_Buffer;
23099 -- Local variables
23101 Msg_1 : constant String := "incorrect placement of pragma%";
23102 Msg_2 : Name_Id;
23104 -- Start of processing for Check_Library_Level_Entity
23106 begin
23107 -- A SPARK_Mode of On shall only apply to library-level
23108 -- entities, except for those in generic instances, which are
23109 -- ignored (even if the entity gets SPARK_Mode pragma attached
23110 -- in the AST, its effect is not taken into account unless the
23111 -- context already provides SPARK_Mode of On in GNATprove).
23113 if Get_SPARK_Mode_From_Annotation (N) = On
23114 and then not Is_Library_Level_Entity (E)
23115 and then Instantiation_Location (Sloc (N)) = No_Location
23116 then
23117 Error_Msg_Name_1 := Pname;
23118 Error_Msg_N (Fix_Error (Msg_1), N);
23120 Name_Len := 0;
23121 Add_Str_To_Name_Buffer ("\& is not a library-level ");
23122 Add_Entity_To_Name_Buffer;
23124 Msg_2 := Name_Find;
23125 Error_Msg_NE (Get_Name_String (Msg_2), N, E);
23127 raise Pragma_Exit;
23128 end if;
23129 end Check_Library_Level_Entity;
23131 ------------------
23132 -- Process_Body --
23133 ------------------
23135 procedure Process_Body (Decl : Node_Id) is
23136 Body_Id : constant Entity_Id := Defining_Entity (Decl);
23137 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
23139 begin
23140 -- Ignore pragma when applied to the special body created for
23141 -- inlining, recognized by its internal name _Parent.
23143 if Chars (Body_Id) = Name_uParent then
23144 return;
23145 end if;
23147 Check_Library_Level_Entity (Body_Id);
23149 -- For entry bodies, verify the legality against:
23150 -- * The mode of the context
23151 -- * The mode of the spec (if any)
23153 if Nkind (Decl) in N_Entry_Body | N_Subprogram_Body then
23155 -- A stand-alone subprogram body
23157 if Body_Id = Spec_Id then
23158 Check_Pragma_Conformance
23159 (Context_Pragma => SPARK_Pragma (Body_Id),
23160 Entity => Empty,
23161 Entity_Pragma => Empty);
23163 -- An entry or subprogram body that completes a previous
23164 -- declaration.
23166 else
23167 Check_Pragma_Conformance
23168 (Context_Pragma => SPARK_Pragma (Body_Id),
23169 Entity => Spec_Id,
23170 Entity_Pragma => SPARK_Pragma (Spec_Id));
23171 end if;
23173 Set_SPARK_Context;
23174 Set_SPARK_Pragma (Body_Id, N);
23175 Set_SPARK_Pragma_Inherited (Body_Id, False);
23177 -- For package bodies, verify the legality against:
23178 -- * The mode of the context
23179 -- * The mode of the private part
23181 -- This case is separated from protected and task bodies
23182 -- because the statement part of the package body inherits
23183 -- the mode of the body declarations.
23185 elsif Nkind (Decl) = N_Package_Body then
23186 Check_Pragma_Conformance
23187 (Context_Pragma => SPARK_Pragma (Body_Id),
23188 Entity => Spec_Id,
23189 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
23191 Set_SPARK_Context;
23192 Set_SPARK_Pragma (Body_Id, N);
23193 Set_SPARK_Pragma_Inherited (Body_Id, False);
23194 Set_SPARK_Aux_Pragma (Body_Id, N);
23195 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
23197 -- For protected and task bodies, verify the legality against:
23198 -- * The mode of the context
23199 -- * The mode of the private part
23201 else
23202 pragma Assert
23203 (Nkind (Decl) in N_Protected_Body | N_Task_Body);
23205 Check_Pragma_Conformance
23206 (Context_Pragma => SPARK_Pragma (Body_Id),
23207 Entity => Spec_Id,
23208 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
23210 Set_SPARK_Context;
23211 Set_SPARK_Pragma (Body_Id, N);
23212 Set_SPARK_Pragma_Inherited (Body_Id, False);
23213 end if;
23214 end Process_Body;
23216 --------------------------
23217 -- Process_Overloadable --
23218 --------------------------
23220 procedure Process_Overloadable (Decl : Node_Id) is
23221 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23222 Spec_Typ : constant Entity_Id := Etype (Spec_Id);
23224 begin
23225 Check_Library_Level_Entity (Spec_Id);
23227 -- Verify the legality against:
23228 -- * The mode of the context
23230 Check_Pragma_Conformance
23231 (Context_Pragma => SPARK_Pragma (Spec_Id),
23232 Entity => Empty,
23233 Entity_Pragma => Empty);
23235 Set_SPARK_Pragma (Spec_Id, N);
23236 Set_SPARK_Pragma_Inherited (Spec_Id, False);
23238 -- When the pragma applies to the anonymous object created for
23239 -- a single task type, decorate the type as well. This scenario
23240 -- arises when the single task type lacks a task definition,
23241 -- therefore there is no issue with respect to a potential
23242 -- pragma SPARK_Mode in the private part.
23244 -- task type Anon_Task_Typ;
23245 -- Obj : Anon_Task_Typ;
23246 -- pragma SPARK_Mode ...;
23248 if Is_Single_Task_Object (Spec_Id) then
23249 Set_SPARK_Pragma (Spec_Typ, N);
23250 Set_SPARK_Pragma_Inherited (Spec_Typ, False);
23251 Set_SPARK_Aux_Pragma (Spec_Typ, N);
23252 Set_SPARK_Aux_Pragma_Inherited (Spec_Typ, True);
23253 end if;
23254 end Process_Overloadable;
23256 --------------------------
23257 -- Process_Private_Part --
23258 --------------------------
23260 procedure Process_Private_Part (Decl : Node_Id) is
23261 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23263 begin
23264 Check_Library_Level_Entity (Spec_Id);
23266 -- Verify the legality against:
23267 -- * The mode of the visible declarations
23269 Check_Pragma_Conformance
23270 (Context_Pragma => Empty,
23271 Entity => Spec_Id,
23272 Entity_Pragma => SPARK_Pragma (Spec_Id));
23274 Set_SPARK_Context;
23275 Set_SPARK_Aux_Pragma (Spec_Id, N);
23276 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
23277 end Process_Private_Part;
23279 ----------------------------
23280 -- Process_Statement_Part --
23281 ----------------------------
23283 procedure Process_Statement_Part (Decl : Node_Id) is
23284 Body_Id : constant Entity_Id := Defining_Entity (Decl);
23286 begin
23287 Check_Library_Level_Entity (Body_Id);
23289 -- Verify the legality against:
23290 -- * The mode of the body declarations
23292 Check_Pragma_Conformance
23293 (Context_Pragma => Empty,
23294 Entity => Body_Id,
23295 Entity_Pragma => SPARK_Pragma (Body_Id));
23297 Set_SPARK_Context;
23298 Set_SPARK_Aux_Pragma (Body_Id, N);
23299 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
23300 end Process_Statement_Part;
23302 --------------------------
23303 -- Process_Visible_Part --
23304 --------------------------
23306 procedure Process_Visible_Part (Decl : Node_Id) is
23307 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
23308 Obj_Id : Entity_Id;
23310 begin
23311 Check_Library_Level_Entity (Spec_Id);
23313 -- Verify the legality against:
23314 -- * The mode of the context
23316 Check_Pragma_Conformance
23317 (Context_Pragma => SPARK_Pragma (Spec_Id),
23318 Entity => Empty,
23319 Entity_Pragma => Empty);
23321 -- A task unit declared without a definition does not set the
23322 -- SPARK_Mode of the context because the task does not have any
23323 -- entries that could inherit the mode.
23325 if Nkind (Decl) not in
23326 N_Single_Task_Declaration | N_Task_Type_Declaration
23327 then
23328 Set_SPARK_Context;
23329 end if;
23331 Set_SPARK_Pragma (Spec_Id, N);
23332 Set_SPARK_Pragma_Inherited (Spec_Id, False);
23333 Set_SPARK_Aux_Pragma (Spec_Id, N);
23334 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
23336 -- When the pragma applies to a single protected or task type,
23337 -- decorate the corresponding anonymous object as well.
23339 -- protected Anon_Prot_Typ is
23340 -- pragma SPARK_Mode ...;
23341 -- ...
23342 -- end Anon_Prot_Typ;
23344 -- Obj : Anon_Prot_Typ;
23346 if Is_Single_Concurrent_Type (Spec_Id) then
23347 Obj_Id := Anonymous_Object (Spec_Id);
23349 Set_SPARK_Pragma (Obj_Id, N);
23350 Set_SPARK_Pragma_Inherited (Obj_Id, False);
23351 end if;
23352 end Process_Visible_Part;
23354 -----------------------
23355 -- Set_SPARK_Context --
23356 -----------------------
23358 procedure Set_SPARK_Context is
23359 begin
23360 SPARK_Mode := Mode_Id;
23361 SPARK_Mode_Pragma := N;
23362 end Set_SPARK_Context;
23364 -- Local variables
23366 Context : Node_Id;
23367 Mode : Name_Id;
23368 Stmt : Node_Id;
23370 -- Start of processing for Do_SPARK_Mode
23372 begin
23373 GNAT_Pragma;
23374 Check_No_Identifiers;
23375 Check_At_Most_N_Arguments (1);
23377 -- Check the legality of the mode (no argument = ON)
23379 if Arg_Count = 1 then
23380 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23381 Mode := Chars (Get_Pragma_Arg (Arg1));
23382 else
23383 Mode := Name_On;
23384 end if;
23386 Mode_Id := Get_SPARK_Mode_Type (Mode);
23387 Context := Parent (N);
23389 -- When a SPARK_Mode pragma appears inside an instantiation whose
23390 -- enclosing context has SPARK_Mode set to "off", the pragma has
23391 -- no semantic effect.
23393 if Ignore_SPARK_Mode_Pragmas_In_Instance
23394 and then Mode_Id /= Off
23395 then
23396 Rewrite (N, Make_Null_Statement (Loc));
23397 Analyze (N);
23398 return;
23399 end if;
23401 -- The pragma appears in a configuration file
23403 if No (Context) then
23404 Check_Valid_Configuration_Pragma;
23406 if Present (SPARK_Mode_Pragma) then
23407 Duplication_Error
23408 (Prag => N,
23409 Prev => SPARK_Mode_Pragma);
23410 raise Pragma_Exit;
23411 end if;
23413 Set_SPARK_Context;
23415 -- The pragma acts as a configuration pragma in a compilation unit
23417 -- pragma SPARK_Mode ...;
23418 -- package Pack is ...;
23420 elsif Nkind (Context) = N_Compilation_Unit
23421 and then List_Containing (N) = Context_Items (Context)
23422 then
23423 Check_Valid_Configuration_Pragma;
23424 Set_SPARK_Context;
23426 -- Otherwise the placement of the pragma within the tree dictates
23427 -- its associated construct. Inspect the declarative list where
23428 -- the pragma resides to find a potential construct.
23430 else
23431 Stmt := Prev (N);
23432 while Present (Stmt) loop
23434 -- Skip prior pragmas, but check for duplicates. Note that
23435 -- this also takes care of pragmas generated for aspects.
23437 if Nkind (Stmt) = N_Pragma then
23438 if Pragma_Name (Stmt) = Pname then
23439 Duplication_Error
23440 (Prag => N,
23441 Prev => Stmt);
23442 raise Pragma_Exit;
23443 end if;
23445 -- The pragma applies to an expression function that has
23446 -- already been rewritten into a subprogram declaration.
23448 -- function Expr_Func return ... is (...);
23449 -- pragma SPARK_Mode ...;
23451 elsif Nkind (Stmt) = N_Subprogram_Declaration
23452 and then Nkind (Original_Node (Stmt)) =
23453 N_Expression_Function
23454 then
23455 Process_Overloadable (Stmt);
23456 return;
23458 -- The pragma applies to the anonymous object created for a
23459 -- single concurrent type.
23461 -- protected type Anon_Prot_Typ ...;
23462 -- Obj : Anon_Prot_Typ;
23463 -- pragma SPARK_Mode ...;
23465 elsif Nkind (Stmt) = N_Object_Declaration
23466 and then Is_Single_Concurrent_Object
23467 (Defining_Entity (Stmt))
23468 then
23469 Process_Overloadable (Stmt);
23470 return;
23472 -- Skip internally generated code
23474 elsif not Comes_From_Source (Stmt) then
23475 null;
23477 -- The pragma applies to an entry or [generic] subprogram
23478 -- declaration.
23480 -- entry Ent ...;
23481 -- pragma SPARK_Mode ...;
23483 -- [generic]
23484 -- procedure Proc ...;
23485 -- pragma SPARK_Mode ...;
23487 elsif Nkind (Stmt) in N_Generic_Subprogram_Declaration
23488 | N_Subprogram_Declaration
23489 or else (Nkind (Stmt) = N_Entry_Declaration
23490 and then Is_Protected_Type
23491 (Scope (Defining_Entity (Stmt))))
23492 then
23493 Process_Overloadable (Stmt);
23494 return;
23496 -- Otherwise the pragma does not apply to a legal construct
23497 -- or it does not appear at the top of a declarative or a
23498 -- statement list. Issue an error and stop the analysis.
23500 else
23501 Pragma_Misplaced;
23502 exit;
23503 end if;
23505 Prev (Stmt);
23506 end loop;
23508 -- The pragma applies to a package or a subprogram that acts as
23509 -- a compilation unit.
23511 -- procedure Proc ...;
23512 -- pragma SPARK_Mode ...;
23514 if Nkind (Context) = N_Compilation_Unit_Aux then
23515 Context := Unit (Parent (Context));
23516 end if;
23518 -- The pragma appears at the top of entry, package, protected
23519 -- unit, subprogram or task unit body declarations.
23521 -- entry Ent when ... is
23522 -- pragma SPARK_Mode ...;
23524 -- package body Pack is
23525 -- pragma SPARK_Mode ...;
23527 -- procedure Proc ... is
23528 -- pragma SPARK_Mode;
23530 -- protected body Prot is
23531 -- pragma SPARK_Mode ...;
23533 if Nkind (Context) in N_Entry_Body
23534 | N_Package_Body
23535 | N_Protected_Body
23536 | N_Subprogram_Body
23537 | N_Task_Body
23538 then
23539 Process_Body (Context);
23541 -- The pragma appears at the top of the visible or private
23542 -- declaration of a package spec, protected or task unit.
23544 -- package Pack is
23545 -- pragma SPARK_Mode ...;
23546 -- private
23547 -- pragma SPARK_Mode ...;
23549 -- protected [type] Prot is
23550 -- pragma SPARK_Mode ...;
23551 -- private
23552 -- pragma SPARK_Mode ...;
23554 elsif Nkind (Context) in N_Package_Specification
23555 | N_Protected_Definition
23556 | N_Task_Definition
23557 then
23558 if List_Containing (N) = Visible_Declarations (Context) then
23559 Process_Visible_Part (Parent (Context));
23560 else
23561 Process_Private_Part (Parent (Context));
23562 end if;
23564 -- The pragma appears at the top of package body statements
23566 -- package body Pack is
23567 -- begin
23568 -- pragma SPARK_Mode;
23570 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
23571 and then Nkind (Parent (Context)) = N_Package_Body
23572 then
23573 Process_Statement_Part (Parent (Context));
23575 -- The pragma appeared as an aspect of a [generic] subprogram
23576 -- declaration that acts as a compilation unit.
23578 -- [generic]
23579 -- procedure Proc ...;
23580 -- pragma SPARK_Mode ...;
23582 elsif Nkind (Context) in N_Generic_Subprogram_Declaration
23583 | N_Subprogram_Declaration
23584 then
23585 Process_Overloadable (Context);
23587 -- The pragma does not apply to a legal construct, issue error
23589 else
23590 Pragma_Misplaced;
23591 end if;
23592 end if;
23593 end Do_SPARK_Mode;
23595 --------------------------------
23596 -- Static_Elaboration_Desired --
23597 --------------------------------
23599 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
23601 when Pragma_Static_Elaboration_Desired =>
23602 GNAT_Pragma;
23603 Check_At_Most_N_Arguments (1);
23605 if Is_Compilation_Unit (Current_Scope)
23606 and then Ekind (Current_Scope) = E_Package
23607 then
23608 Set_Static_Elaboration_Desired (Current_Scope, True);
23609 else
23610 Error_Pragma ("pragma% must apply to a library-level package");
23611 end if;
23613 ------------------
23614 -- Storage_Size --
23615 ------------------
23617 -- pragma Storage_Size (EXPRESSION);
23619 when Pragma_Storage_Size => Storage_Size : declare
23620 P : constant Node_Id := Parent (N);
23621 Arg : Node_Id;
23623 begin
23624 Check_No_Identifiers;
23625 Check_Arg_Count (1);
23627 -- The expression must be analyzed in the special manner described
23628 -- in "Handling of Default Expressions" in sem.ads.
23630 Arg := Get_Pragma_Arg (Arg1);
23631 Preanalyze_Spec_Expression (Arg, Any_Integer);
23633 if not Is_OK_Static_Expression (Arg) then
23634 Check_Restriction (Static_Storage_Size, Arg);
23635 end if;
23637 if Nkind (P) /= N_Task_Definition then
23638 Pragma_Misplaced;
23639 return;
23641 else
23642 if Has_Storage_Size_Pragma (P) then
23643 Error_Pragma ("duplicate pragma% not allowed");
23644 else
23645 Set_Has_Storage_Size_Pragma (P, True);
23646 end if;
23648 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
23649 end if;
23650 end Storage_Size;
23652 ------------------
23653 -- Storage_Unit --
23654 ------------------
23656 -- pragma Storage_Unit (NUMERIC_LITERAL);
23658 -- Only permitted argument is System'Storage_Unit value
23660 when Pragma_Storage_Unit =>
23661 Check_No_Identifiers;
23662 Check_Arg_Count (1);
23663 Check_Arg_Is_Integer_Literal (Arg1);
23665 if Intval (Get_Pragma_Arg (Arg1)) /=
23666 UI_From_Int (Ttypes.System_Storage_Unit)
23667 then
23668 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
23669 Error_Pragma_Arg
23670 ("the only allowed argument for pragma% is ^", Arg1);
23671 end if;
23673 --------------------
23674 -- Stream_Convert --
23675 --------------------
23677 -- pragma Stream_Convert (
23678 -- [Entity =>] type_LOCAL_NAME,
23679 -- [Read =>] function_NAME,
23680 -- [Write =>] function NAME);
23682 when Pragma_Stream_Convert => Stream_Convert : declare
23683 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
23684 -- Check that the given argument is the name of a local function
23685 -- of one argument that is not overloaded earlier in the current
23686 -- local scope. A check is also made that the argument is a
23687 -- function with one parameter.
23689 --------------------------------------
23690 -- Check_OK_Stream_Convert_Function --
23691 --------------------------------------
23693 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
23694 Ent : Entity_Id;
23696 begin
23697 Check_Arg_Is_Local_Name (Arg);
23698 Ent := Entity (Get_Pragma_Arg (Arg));
23700 if Has_Homonym (Ent) then
23701 Error_Pragma_Arg
23702 ("argument for pragma% may not be overloaded", Arg);
23703 end if;
23705 if Ekind (Ent) /= E_Function
23706 or else No (First_Formal (Ent))
23707 or else Present (Next_Formal (First_Formal (Ent)))
23708 then
23709 Error_Pragma_Arg
23710 ("argument for pragma% must be function of one argument",
23711 Arg);
23712 elsif Is_Abstract_Subprogram (Ent) then
23713 Error_Pragma_Arg
23714 ("argument for pragma% cannot be abstract", Arg);
23715 end if;
23716 end Check_OK_Stream_Convert_Function;
23718 -- Start of processing for Stream_Convert
23720 begin
23721 GNAT_Pragma;
23722 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
23723 Check_Arg_Count (3);
23724 Check_Optional_Identifier (Arg1, Name_Entity);
23725 Check_Optional_Identifier (Arg2, Name_Read);
23726 Check_Optional_Identifier (Arg3, Name_Write);
23727 Check_Arg_Is_Local_Name (Arg1);
23728 Check_OK_Stream_Convert_Function (Arg2);
23729 Check_OK_Stream_Convert_Function (Arg3);
23731 declare
23732 Typ : constant Entity_Id :=
23733 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
23734 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
23735 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
23737 begin
23738 Check_First_Subtype (Arg1);
23740 -- Check for too early or too late. Note that we don't enforce
23741 -- the rule about primitive operations in this case, since, as
23742 -- is the case for explicit stream attributes themselves, these
23743 -- restrictions are not appropriate. Note that the chaining of
23744 -- the pragma by Rep_Item_Too_Late is actually the critical
23745 -- processing done for this pragma.
23747 if Rep_Item_Too_Early (Typ, N)
23748 or else
23749 Rep_Item_Too_Late (Typ, N, FOnly => True)
23750 then
23751 return;
23752 end if;
23754 -- Return if previous error
23756 if Etype (Typ) = Any_Type
23757 or else
23758 Etype (Read) = Any_Type
23759 or else
23760 Etype (Write) = Any_Type
23761 then
23762 return;
23763 end if;
23765 -- Error checks
23767 if Underlying_Type (Etype (Read)) /= Typ then
23768 Error_Pragma_Arg
23769 ("incorrect return type for function&", Arg2);
23770 end if;
23772 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
23773 Error_Pragma_Arg
23774 ("incorrect parameter type for function&", Arg3);
23775 end if;
23777 if Underlying_Type (Etype (First_Formal (Read))) /=
23778 Underlying_Type (Etype (Write))
23779 then
23780 Error_Pragma_Arg
23781 ("result type of & does not match Read parameter type",
23782 Arg3);
23783 end if;
23784 end;
23785 end Stream_Convert;
23787 ------------------
23788 -- Style_Checks --
23789 ------------------
23791 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
23793 -- This is processed by the parser since some of the style checks
23794 -- take place during source scanning and parsing. This means that
23795 -- we don't need to issue error messages here.
23797 when Pragma_Style_Checks => Style_Checks : declare
23798 A : constant Node_Id := Get_Pragma_Arg (Arg1);
23799 S : String_Id;
23800 C : Char_Code;
23802 begin
23803 GNAT_Pragma;
23804 Check_No_Identifiers;
23806 -- Two argument form
23808 if Arg_Count = 2 then
23809 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23811 declare
23812 E_Id : Node_Id;
23813 E : Entity_Id;
23815 begin
23816 E_Id := Get_Pragma_Arg (Arg2);
23817 Analyze (E_Id);
23819 if not Is_Entity_Name (E_Id) then
23820 Error_Pragma_Arg
23821 ("second argument of pragma% must be entity name",
23822 Arg2);
23823 end if;
23825 E := Entity (E_Id);
23827 if not Ignore_Style_Checks_Pragmas then
23828 if E = Any_Id then
23829 return;
23830 else
23831 loop
23832 Set_Suppress_Style_Checks
23833 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
23834 exit when No (Homonym (E));
23835 E := Homonym (E);
23836 end loop;
23837 end if;
23838 end if;
23839 end;
23841 -- One argument form
23843 else
23844 Check_Arg_Count (1);
23846 if Nkind (A) = N_String_Literal then
23847 S := Strval (A);
23849 declare
23850 Slen : constant Natural := Natural (String_Length (S));
23851 Options : String (1 .. Slen);
23852 J : Positive;
23854 begin
23855 J := 1;
23856 loop
23857 C := Get_String_Char (S, Pos (J));
23858 exit when not In_Character_Range (C);
23859 Options (J) := Get_Character (C);
23861 -- If at end of string, set options. As per discussion
23862 -- above, no need to check for errors, since we issued
23863 -- them in the parser.
23865 if J = Slen then
23866 if not Ignore_Style_Checks_Pragmas then
23867 Set_Style_Check_Options (Options);
23868 end if;
23870 exit;
23871 end if;
23873 J := J + 1;
23874 end loop;
23875 end;
23877 elsif Nkind (A) = N_Identifier then
23878 if Chars (A) = Name_All_Checks then
23879 if not Ignore_Style_Checks_Pragmas then
23880 if GNAT_Mode then
23881 Set_GNAT_Style_Check_Options;
23882 else
23883 Set_Default_Style_Check_Options;
23884 end if;
23885 end if;
23887 elsif Chars (A) = Name_On then
23888 if not Ignore_Style_Checks_Pragmas then
23889 Style_Check := True;
23890 end if;
23892 elsif Chars (A) = Name_Off then
23893 if not Ignore_Style_Checks_Pragmas then
23894 Style_Check := False;
23895 end if;
23896 end if;
23897 end if;
23898 end if;
23899 end Style_Checks;
23901 --------------
23902 -- Subtitle --
23903 --------------
23905 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
23907 when Pragma_Subtitle =>
23908 GNAT_Pragma;
23909 Check_Arg_Count (1);
23910 Check_Optional_Identifier (Arg1, Name_Subtitle);
23911 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
23912 Store_Note (N);
23914 --------------
23915 -- Suppress --
23916 --------------
23918 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
23920 when Pragma_Suppress =>
23921 Process_Suppress_Unsuppress (Suppress_Case => True);
23923 ------------------
23924 -- Suppress_All --
23925 ------------------
23927 -- pragma Suppress_All;
23929 -- The only check made here is that the pragma has no arguments.
23930 -- There are no placement rules, and the processing required (setting
23931 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
23932 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
23933 -- then creates and inserts a pragma Suppress (All_Checks).
23935 when Pragma_Suppress_All =>
23936 GNAT_Pragma;
23937 Check_Arg_Count (0);
23939 -------------------------
23940 -- Suppress_Debug_Info --
23941 -------------------------
23943 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
23945 when Pragma_Suppress_Debug_Info => Suppress_Debug_Info : declare
23946 Nam_Id : Entity_Id;
23948 begin
23949 GNAT_Pragma;
23950 Check_Arg_Count (1);
23951 Check_Optional_Identifier (Arg1, Name_Entity);
23952 Check_Arg_Is_Local_Name (Arg1);
23954 Nam_Id := Entity (Get_Pragma_Arg (Arg1));
23956 -- A pragma that applies to a Ghost entity becomes Ghost for the
23957 -- purposes of legality checks and removal of ignored Ghost code.
23959 Mark_Ghost_Pragma (N, Nam_Id);
23960 Set_Debug_Info_Off (Nam_Id);
23961 end Suppress_Debug_Info;
23963 ----------------------------------
23964 -- Suppress_Exception_Locations --
23965 ----------------------------------
23967 -- pragma Suppress_Exception_Locations;
23969 when Pragma_Suppress_Exception_Locations =>
23970 GNAT_Pragma;
23971 Check_Arg_Count (0);
23972 Check_Valid_Configuration_Pragma;
23973 Exception_Locations_Suppressed := True;
23975 -----------------------------
23976 -- Suppress_Initialization --
23977 -----------------------------
23979 -- pragma Suppress_Initialization ([Entity =>] type_Name);
23981 when Pragma_Suppress_Initialization => Suppress_Init : declare
23982 E : Entity_Id;
23983 E_Id : Node_Id;
23985 begin
23986 GNAT_Pragma;
23987 Check_Arg_Count (1);
23988 Check_Optional_Identifier (Arg1, Name_Entity);
23989 Check_Arg_Is_Local_Name (Arg1);
23991 E_Id := Get_Pragma_Arg (Arg1);
23993 if Etype (E_Id) = Any_Type then
23994 return;
23995 end if;
23997 E := Entity (E_Id);
23999 -- A pragma that applies to a Ghost entity becomes Ghost for the
24000 -- purposes of legality checks and removal of ignored Ghost code.
24002 Mark_Ghost_Pragma (N, E);
24004 if not Is_Type (E) and then Ekind (E) /= E_Variable then
24005 Error_Pragma_Arg
24006 ("pragma% requires variable, type or subtype", Arg1);
24007 end if;
24009 if Rep_Item_Too_Early (E, N)
24010 or else
24011 Rep_Item_Too_Late (E, N, FOnly => True)
24012 then
24013 return;
24014 end if;
24016 -- For incomplete/private type, set flag on full view
24018 if Is_Incomplete_Or_Private_Type (E) then
24019 if No (Full_View (Base_Type (E))) then
24020 Error_Pragma_Arg
24021 ("argument of pragma% cannot be an incomplete type", Arg1);
24022 else
24023 Set_Suppress_Initialization (Full_View (E));
24024 end if;
24026 -- For first subtype, set flag on base type
24028 elsif Is_First_Subtype (E) then
24029 Set_Suppress_Initialization (Base_Type (E));
24031 -- For other than first subtype, set flag on subtype or variable
24033 else
24034 Set_Suppress_Initialization (E);
24035 end if;
24036 end Suppress_Init;
24038 -----------------
24039 -- System_Name --
24040 -----------------
24042 -- pragma System_Name (DIRECT_NAME);
24044 -- Syntax check: one argument, which must be the identifier GNAT or
24045 -- the identifier GCC, no other identifiers are acceptable.
24047 when Pragma_System_Name =>
24048 GNAT_Pragma;
24049 Check_No_Identifiers;
24050 Check_Arg_Count (1);
24051 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
24053 -----------------------------
24054 -- Task_Dispatching_Policy --
24055 -----------------------------
24057 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
24059 when Pragma_Task_Dispatching_Policy => declare
24060 DP : Character;
24062 begin
24063 Check_Ada_83_Warning;
24064 Check_Arg_Count (1);
24065 Check_No_Identifiers;
24066 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
24067 Check_Valid_Configuration_Pragma;
24068 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
24069 DP := Fold_Upper (Name_Buffer (1));
24071 if Task_Dispatching_Policy /= ' '
24072 and then Task_Dispatching_Policy /= DP
24073 then
24074 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
24075 Error_Pragma
24076 ("task dispatching policy incompatible with policy#");
24078 -- Set new policy, but always preserve System_Location since we
24079 -- like the error message with the run time name.
24081 else
24082 Task_Dispatching_Policy := DP;
24084 if Task_Dispatching_Policy_Sloc /= System_Location then
24085 Task_Dispatching_Policy_Sloc := Loc;
24086 end if;
24087 end if;
24088 end;
24090 ---------------
24091 -- Task_Info --
24092 ---------------
24094 -- pragma Task_Info (EXPRESSION);
24096 when Pragma_Task_Info => Task_Info : declare
24097 P : constant Node_Id := Parent (N);
24098 Ent : Entity_Id;
24100 begin
24101 GNAT_Pragma;
24103 if Warn_On_Obsolescent_Feature then
24104 Error_Msg_N
24105 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
24106 & "instead?j?", N);
24107 end if;
24109 if Nkind (P) /= N_Task_Definition then
24110 Error_Pragma ("pragma% must appear in task definition");
24111 end if;
24113 Check_No_Identifiers;
24114 Check_Arg_Count (1);
24116 Analyze_And_Resolve
24117 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
24119 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
24120 return;
24121 end if;
24123 Ent := Defining_Identifier (Parent (P));
24125 -- Check duplicate pragma before we chain the pragma in the Rep
24126 -- Item chain of Ent.
24128 if Has_Rep_Pragma
24129 (Ent, Name_Task_Info, Check_Parents => False)
24130 then
24131 Error_Pragma ("duplicate pragma% not allowed");
24132 end if;
24134 Record_Rep_Item (Ent, N);
24135 end Task_Info;
24137 ---------------
24138 -- Task_Name --
24139 ---------------
24141 -- pragma Task_Name (string_EXPRESSION);
24143 when Pragma_Task_Name => Task_Name : declare
24144 P : constant Node_Id := Parent (N);
24145 Arg : Node_Id;
24146 Ent : Entity_Id;
24148 begin
24149 Check_No_Identifiers;
24150 Check_Arg_Count (1);
24152 Arg := Get_Pragma_Arg (Arg1);
24154 -- The expression is used in the call to Create_Task, and must be
24155 -- expanded there, not in the context of the current spec. It must
24156 -- however be analyzed to capture global references, in case it
24157 -- appears in a generic context.
24159 Preanalyze_And_Resolve (Arg, Standard_String);
24161 if Nkind (P) /= N_Task_Definition then
24162 Pragma_Misplaced;
24163 end if;
24165 Ent := Defining_Identifier (Parent (P));
24167 -- Check duplicate pragma before we chain the pragma in the Rep
24168 -- Item chain of Ent.
24170 if Has_Rep_Pragma
24171 (Ent, Name_Task_Name, Check_Parents => False)
24172 then
24173 Error_Pragma ("duplicate pragma% not allowed");
24174 end if;
24176 Record_Rep_Item (Ent, N);
24177 end Task_Name;
24179 ------------------
24180 -- Task_Storage --
24181 ------------------
24183 -- pragma Task_Storage (
24184 -- [Task_Type =>] LOCAL_NAME,
24185 -- [Top_Guard =>] static_integer_EXPRESSION);
24187 when Pragma_Task_Storage => Task_Storage : declare
24188 Args : Args_List (1 .. 2);
24189 Names : constant Name_List (1 .. 2) := (
24190 Name_Task_Type,
24191 Name_Top_Guard);
24193 Task_Type : Node_Id renames Args (1);
24194 Top_Guard : Node_Id renames Args (2);
24196 Ent : Entity_Id;
24198 begin
24199 GNAT_Pragma;
24200 Gather_Associations (Names, Args);
24202 if No (Task_Type) then
24203 Error_Pragma
24204 ("missing task_type argument for pragma%");
24205 end if;
24207 Check_Arg_Is_Local_Name (Task_Type);
24209 Ent := Entity (Task_Type);
24211 if not Is_Task_Type (Ent) then
24212 Error_Pragma_Arg
24213 ("argument for pragma% must be task type", Task_Type);
24214 end if;
24216 if No (Top_Guard) then
24217 Error_Pragma_Arg
24218 ("pragma% takes two arguments", Task_Type);
24219 else
24220 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
24221 end if;
24223 Check_First_Subtype (Task_Type);
24225 if Rep_Item_Too_Late (Ent, N) then
24226 raise Pragma_Exit;
24227 end if;
24228 end Task_Storage;
24230 ---------------
24231 -- Test_Case --
24232 ---------------
24234 -- pragma Test_Case
24235 -- ([Name =>] Static_String_EXPRESSION
24236 -- ,[Mode =>] MODE_TYPE
24237 -- [, Requires => Boolean_EXPRESSION]
24238 -- [, Ensures => Boolean_EXPRESSION]);
24240 -- MODE_TYPE ::= Nominal | Robustness
24242 -- Characteristics:
24244 -- * Analysis - The annotation undergoes initial checks to verify
24245 -- the legal placement and context. Secondary checks preanalyze the
24246 -- expressions in:
24248 -- Analyze_Test_Case_In_Decl_Part
24250 -- * Expansion - None.
24252 -- * Template - The annotation utilizes the generic template of the
24253 -- related subprogram when it is:
24255 -- aspect on subprogram declaration
24257 -- The annotation must prepare its own template when it is:
24259 -- pragma on subprogram declaration
24261 -- * Globals - Capture of global references must occur after full
24262 -- analysis.
24264 -- * Instance - The annotation is instantiated automatically when
24265 -- the related generic subprogram is instantiated except for the
24266 -- "pragma on subprogram declaration" case. In that scenario the
24267 -- annotation must instantiate itself.
24269 when Pragma_Test_Case => Test_Case : declare
24270 procedure Check_Distinct_Name (Subp_Id : Entity_Id);
24271 -- Ensure that the contract of subprogram Subp_Id does not contain
24272 -- another Test_Case pragma with the same Name as the current one.
24274 -------------------------
24275 -- Check_Distinct_Name --
24276 -------------------------
24278 procedure Check_Distinct_Name (Subp_Id : Entity_Id) is
24279 Items : constant Node_Id := Contract (Subp_Id);
24280 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
24281 Prag : Node_Id;
24283 begin
24284 -- Inspect all Test_Case pragma of the related subprogram
24285 -- looking for one with a duplicate "Name" argument.
24287 if Present (Items) then
24288 Prag := Contract_Test_Cases (Items);
24289 while Present (Prag) loop
24290 if Pragma_Name (Prag) = Name_Test_Case
24291 and then Prag /= N
24292 and then String_Equal
24293 (Name, Get_Name_From_CTC_Pragma (Prag))
24294 then
24295 Error_Msg_Sloc := Sloc (Prag);
24296 Error_Pragma ("name for pragma % is already used #");
24297 end if;
24299 Prag := Next_Pragma (Prag);
24300 end loop;
24301 end if;
24302 end Check_Distinct_Name;
24304 -- Local variables
24306 Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit));
24307 Asp_Arg : Node_Id;
24308 Context : Node_Id;
24309 Subp_Decl : Node_Id;
24310 Subp_Id : Entity_Id;
24312 -- Start of processing for Test_Case
24314 begin
24315 GNAT_Pragma;
24316 Check_At_Least_N_Arguments (2);
24317 Check_At_Most_N_Arguments (4);
24318 Check_Arg_Order
24319 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
24321 -- Argument "Name"
24323 Check_Optional_Identifier (Arg1, Name_Name);
24324 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
24326 -- Argument "Mode"
24328 Check_Optional_Identifier (Arg2, Name_Mode);
24329 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
24331 -- Arguments "Requires" and "Ensures"
24333 if Present (Arg3) then
24334 if Present (Arg4) then
24335 Check_Identifier (Arg3, Name_Requires);
24336 Check_Identifier (Arg4, Name_Ensures);
24337 else
24338 Check_Identifier_Is_One_Of
24339 (Arg3, Name_Requires, Name_Ensures);
24340 end if;
24341 end if;
24343 -- Pragma Test_Case must be associated with a subprogram declared
24344 -- in a library-level package. First determine whether the current
24345 -- compilation unit is a legal context.
24347 if Nkind (Pack_Decl) in N_Package_Declaration
24348 | N_Generic_Package_Declaration
24349 then
24350 null;
24352 -- Otherwise the placement is illegal
24354 else
24355 Error_Pragma
24356 ("pragma % must be specified within a package declaration");
24357 return;
24358 end if;
24360 Subp_Decl := Find_Related_Declaration_Or_Body (N);
24362 -- Find the enclosing context
24364 Context := Parent (Subp_Decl);
24366 if Present (Context) then
24367 Context := Parent (Context);
24368 end if;
24370 -- Verify the placement of the pragma
24372 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
24373 Error_Pragma
24374 ("pragma % cannot be applied to abstract subprogram");
24375 return;
24377 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
24378 Error_Pragma ("pragma % cannot be applied to entry");
24379 return;
24381 -- The context is a [generic] subprogram declared at the top level
24382 -- of the [generic] package unit.
24384 elsif Nkind (Subp_Decl) in N_Generic_Subprogram_Declaration
24385 | N_Subprogram_Declaration
24386 and then Present (Context)
24387 and then Nkind (Context) in N_Generic_Package_Declaration
24388 | N_Package_Declaration
24389 then
24390 null;
24392 -- Otherwise the placement is illegal
24394 else
24395 Error_Pragma
24396 ("pragma % must be applied to a library-level subprogram "
24397 & "declaration");
24398 return;
24399 end if;
24401 Subp_Id := Defining_Entity (Subp_Decl);
24403 -- A pragma that applies to a Ghost entity becomes Ghost for the
24404 -- purposes of legality checks and removal of ignored Ghost code.
24406 Mark_Ghost_Pragma (N, Subp_Id);
24408 -- Chain the pragma on the contract for further processing by
24409 -- Analyze_Test_Case_In_Decl_Part.
24411 Add_Contract_Item (N, Subp_Id);
24413 -- Preanalyze the original aspect argument "Name" for a generic
24414 -- subprogram to properly capture global references.
24416 if Is_Generic_Subprogram (Subp_Id) then
24417 Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True);
24419 if Present (Asp_Arg) then
24421 -- The argument appears with an identifier in association
24422 -- form.
24424 if Nkind (Asp_Arg) = N_Component_Association then
24425 Asp_Arg := Expression (Asp_Arg);
24426 end if;
24428 Check_Expr_Is_OK_Static_Expression
24429 (Asp_Arg, Standard_String);
24430 end if;
24431 end if;
24433 -- Ensure that the all Test_Case pragmas of the related subprogram
24434 -- have distinct names.
24436 Check_Distinct_Name (Subp_Id);
24438 -- Fully analyze the pragma when it appears inside an entry
24439 -- or subprogram body because it cannot benefit from forward
24440 -- references.
24442 if Nkind (Subp_Decl) in N_Entry_Body
24443 | N_Subprogram_Body
24444 | N_Subprogram_Body_Stub
24445 then
24446 -- The legality checks of pragma Test_Case are affected by the
24447 -- SPARK mode in effect and the volatility of the context.
24448 -- Analyze all pragmas in a specific order.
24450 Analyze_If_Present (Pragma_SPARK_Mode);
24451 Analyze_If_Present (Pragma_Volatile_Function);
24452 Analyze_Test_Case_In_Decl_Part (N);
24453 end if;
24454 end Test_Case;
24456 --------------------------
24457 -- Thread_Local_Storage --
24458 --------------------------
24460 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
24462 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
24463 E : Entity_Id;
24464 Id : Node_Id;
24466 begin
24467 GNAT_Pragma;
24468 Check_Arg_Count (1);
24469 Check_Optional_Identifier (Arg1, Name_Entity);
24470 Check_Arg_Is_Library_Level_Local_Name (Arg1);
24472 Id := Get_Pragma_Arg (Arg1);
24473 Analyze (Id);
24475 if not Is_Entity_Name (Id)
24476 or else Ekind (Entity (Id)) /= E_Variable
24477 then
24478 Error_Pragma_Arg ("local variable name required", Arg1);
24479 end if;
24481 E := Entity (Id);
24483 -- A pragma that applies to a Ghost entity becomes Ghost for the
24484 -- purposes of legality checks and removal of ignored Ghost code.
24486 Mark_Ghost_Pragma (N, E);
24488 if Rep_Item_Too_Early (E, N)
24489 or else
24490 Rep_Item_Too_Late (E, N)
24491 then
24492 raise Pragma_Exit;
24493 end if;
24495 Set_Has_Pragma_Thread_Local_Storage (E);
24496 Set_Has_Gigi_Rep_Item (E);
24497 end Thread_Local_Storage;
24499 ----------------
24500 -- Time_Slice --
24501 ----------------
24503 -- pragma Time_Slice (static_duration_EXPRESSION);
24505 when Pragma_Time_Slice => Time_Slice : declare
24506 Val : Ureal;
24507 Nod : Node_Id;
24509 begin
24510 GNAT_Pragma;
24511 Check_Arg_Count (1);
24512 Check_No_Identifiers;
24513 Check_In_Main_Program;
24514 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
24516 if not Error_Posted (Arg1) then
24517 Nod := Next (N);
24518 while Present (Nod) loop
24519 if Nkind (Nod) = N_Pragma
24520 and then Pragma_Name (Nod) = Name_Time_Slice
24521 then
24522 Error_Msg_Name_1 := Pname;
24523 Error_Msg_N ("duplicate pragma% not permitted", Nod);
24524 end if;
24526 Next (Nod);
24527 end loop;
24528 end if;
24530 -- Process only if in main unit
24532 if Get_Source_Unit (Loc) = Main_Unit then
24533 Opt.Time_Slice_Set := True;
24534 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
24536 if Val <= Ureal_0 then
24537 Opt.Time_Slice_Value := 0;
24539 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
24540 Opt.Time_Slice_Value := 1_000_000_000;
24542 else
24543 Opt.Time_Slice_Value :=
24544 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
24545 end if;
24546 end if;
24547 end Time_Slice;
24549 -----------
24550 -- Title --
24551 -----------
24553 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
24555 -- TITLING_OPTION ::=
24556 -- [Title =>] STRING_LITERAL
24557 -- | [Subtitle =>] STRING_LITERAL
24559 when Pragma_Title => Title : declare
24560 Args : Args_List (1 .. 2);
24561 Names : constant Name_List (1 .. 2) := (
24562 Name_Title,
24563 Name_Subtitle);
24565 begin
24566 GNAT_Pragma;
24567 Gather_Associations (Names, Args);
24568 Store_Note (N);
24570 for J in 1 .. 2 loop
24571 if Present (Args (J)) then
24572 Check_Arg_Is_OK_Static_Expression
24573 (Args (J), Standard_String);
24574 end if;
24575 end loop;
24576 end Title;
24578 ----------------------------
24579 -- Type_Invariant[_Class] --
24580 ----------------------------
24582 -- pragma Type_Invariant[_Class]
24583 -- ([Entity =>] type_LOCAL_NAME,
24584 -- [Check =>] EXPRESSION);
24586 when Pragma_Type_Invariant
24587 | Pragma_Type_Invariant_Class
24589 Type_Invariant : declare
24590 I_Pragma : Node_Id;
24592 begin
24593 Check_Arg_Count (2);
24595 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
24596 -- setting Class_Present for the Type_Invariant_Class case.
24598 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
24599 I_Pragma := New_Copy (N);
24600 Set_Pragma_Identifier
24601 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
24602 Rewrite (N, I_Pragma);
24603 Set_Analyzed (N, False);
24604 Analyze (N);
24605 end Type_Invariant;
24607 ---------------------
24608 -- Unchecked_Union --
24609 ---------------------
24611 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
24613 when Pragma_Unchecked_Union => Unchecked_Union : declare
24614 Assoc : constant Node_Id := Arg1;
24615 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
24616 Clist : Node_Id;
24617 Comp : Node_Id;
24618 Tdef : Node_Id;
24619 Typ : Entity_Id;
24620 Variant : Node_Id;
24621 Vpart : Node_Id;
24623 begin
24624 Ada_2005_Pragma;
24625 Check_No_Identifiers;
24626 Check_Arg_Count (1);
24627 Check_Arg_Is_Local_Name (Arg1);
24629 Find_Type (Type_Id);
24631 Typ := Entity (Type_Id);
24633 -- A pragma that applies to a Ghost entity becomes Ghost for the
24634 -- purposes of legality checks and removal of ignored Ghost code.
24636 Mark_Ghost_Pragma (N, Typ);
24638 if Typ = Any_Type
24639 or else Rep_Item_Too_Early (Typ, N)
24640 then
24641 return;
24642 else
24643 Typ := Underlying_Type (Typ);
24644 end if;
24646 if Rep_Item_Too_Late (Typ, N) then
24647 return;
24648 end if;
24650 Check_First_Subtype (Arg1);
24652 -- Note remaining cases are references to a type in the current
24653 -- declarative part. If we find an error, we post the error on
24654 -- the relevant type declaration at an appropriate point.
24656 if not Is_Record_Type (Typ) then
24657 Error_Msg_N ("unchecked union must be record type", Typ);
24658 return;
24660 elsif Is_Tagged_Type (Typ) then
24661 Error_Msg_N ("unchecked union must not be tagged", Typ);
24662 return;
24664 elsif not Has_Discriminants (Typ) then
24665 Error_Msg_N
24666 ("unchecked union must have one discriminant", Typ);
24667 return;
24669 -- Note: in previous versions of GNAT we used to check for limited
24670 -- types and give an error, but in fact the standard does allow
24671 -- Unchecked_Union on limited types, so this check was removed.
24673 -- Similarly, GNAT used to require that all discriminants have
24674 -- default values, but this is not mandated by the RM.
24676 -- Proceed with basic error checks completed
24678 else
24679 Tdef := Type_Definition (Declaration_Node (Typ));
24680 Clist := Component_List (Tdef);
24682 -- Check presence of component list and variant part
24684 if No (Clist) or else No (Variant_Part (Clist)) then
24685 Error_Msg_N
24686 ("unchecked union must have variant part", Tdef);
24687 return;
24688 end if;
24690 -- Check components
24692 Comp := First_Non_Pragma (Component_Items (Clist));
24693 while Present (Comp) loop
24694 Check_Component (Comp, Typ);
24695 Next_Non_Pragma (Comp);
24696 end loop;
24698 -- Check variant part
24700 Vpart := Variant_Part (Clist);
24702 Variant := First_Non_Pragma (Variants (Vpart));
24703 while Present (Variant) loop
24704 Check_Variant (Variant, Typ);
24705 Next_Non_Pragma (Variant);
24706 end loop;
24707 end if;
24709 Set_Is_Unchecked_Union (Typ);
24710 Set_Convention (Typ, Convention_C);
24711 Set_Has_Unchecked_Union (Base_Type (Typ));
24712 Set_Is_Unchecked_Union (Base_Type (Typ));
24713 end Unchecked_Union;
24715 ----------------------------
24716 -- Unevaluated_Use_Of_Old --
24717 ----------------------------
24719 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
24721 when Pragma_Unevaluated_Use_Of_Old =>
24722 GNAT_Pragma;
24723 Check_Arg_Count (1);
24724 Check_No_Identifiers;
24725 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
24727 -- Suppress/Unsuppress can appear as a configuration pragma, or in
24728 -- a declarative part or a package spec.
24730 if not Is_Configuration_Pragma then
24731 Check_Is_In_Decl_Part_Or_Package_Spec;
24732 end if;
24734 -- Store proper setting of Uneval_Old
24736 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
24737 Uneval_Old := Fold_Upper (Name_Buffer (1));
24739 ------------------------
24740 -- Unimplemented_Unit --
24741 ------------------------
24743 -- pragma Unimplemented_Unit;
24745 -- Note: this only gives an error if we are generating code, or if
24746 -- we are in a generic library unit (where the pragma appears in the
24747 -- body, not in the spec).
24749 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
24750 Cunitent : constant Entity_Id :=
24751 Cunit_Entity (Get_Source_Unit (Loc));
24752 Ent_Kind : constant Entity_Kind := Ekind (Cunitent);
24754 begin
24755 GNAT_Pragma;
24756 Check_Arg_Count (0);
24758 if Operating_Mode = Generate_Code
24759 or else Ent_Kind = E_Generic_Function
24760 or else Ent_Kind = E_Generic_Procedure
24761 or else Ent_Kind = E_Generic_Package
24762 then
24763 Get_Name_String (Chars (Cunitent));
24764 Set_Casing (Mixed_Case);
24765 Write_Str (Name_Buffer (1 .. Name_Len));
24766 Write_Str (" is not supported in this configuration");
24767 Write_Eol;
24768 raise Unrecoverable_Error;
24769 end if;
24770 end Unimplemented_Unit;
24772 ------------------------
24773 -- Universal_Aliasing --
24774 ------------------------
24776 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
24778 when Pragma_Universal_Aliasing => Universal_Alias : declare
24779 E : Entity_Id;
24780 E_Id : Node_Id;
24782 begin
24783 GNAT_Pragma;
24784 Check_Arg_Count (1);
24785 Check_Optional_Identifier (Arg2, Name_Entity);
24786 Check_Arg_Is_Local_Name (Arg1);
24787 E_Id := Get_Pragma_Arg (Arg1);
24789 if Etype (E_Id) = Any_Type then
24790 return;
24791 end if;
24793 E := Entity (E_Id);
24795 if not Is_Type (E) then
24796 Error_Pragma_Arg ("pragma% requires type", Arg1);
24797 end if;
24799 -- A pragma that applies to a Ghost entity becomes Ghost for the
24800 -- purposes of legality checks and removal of ignored Ghost code.
24802 Mark_Ghost_Pragma (N, E);
24803 Set_Universal_Aliasing (Base_Type (E));
24804 Record_Rep_Item (E, N);
24805 end Universal_Alias;
24807 --------------------
24808 -- Universal_Data --
24809 --------------------
24811 -- pragma Universal_Data [(library_unit_NAME)];
24813 when Pragma_Universal_Data =>
24814 GNAT_Pragma;
24815 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
24817 ----------------
24818 -- Unmodified --
24819 ----------------
24821 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
24823 when Pragma_Unmodified =>
24824 Analyze_Unmodified_Or_Unused;
24826 ------------------
24827 -- Unreferenced --
24828 ------------------
24830 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
24832 -- or when used in a context clause:
24834 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
24836 when Pragma_Unreferenced =>
24837 Analyze_Unreferenced_Or_Unused;
24839 --------------------------
24840 -- Unreferenced_Objects --
24841 --------------------------
24843 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
24845 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
24846 Arg : Node_Id;
24847 Arg_Expr : Node_Id;
24848 Arg_Id : Entity_Id;
24850 Ghost_Error_Posted : Boolean := False;
24851 -- Flag set when an error concerning the illegal mix of Ghost and
24852 -- non-Ghost types is emitted.
24854 Ghost_Id : Entity_Id := Empty;
24855 -- The entity of the first Ghost type encountered while processing
24856 -- the arguments of the pragma.
24858 begin
24859 GNAT_Pragma;
24860 Check_At_Least_N_Arguments (1);
24862 Arg := Arg1;
24863 while Present (Arg) loop
24864 Check_No_Identifier (Arg);
24865 Check_Arg_Is_Local_Name (Arg);
24866 Arg_Expr := Get_Pragma_Arg (Arg);
24868 if Is_Entity_Name (Arg_Expr) then
24869 Arg_Id := Entity (Arg_Expr);
24871 if Is_Type (Arg_Id) then
24872 Set_Has_Pragma_Unreferenced_Objects (Arg_Id);
24874 -- A pragma that applies to a Ghost entity becomes Ghost
24875 -- for the purposes of legality checks and removal of
24876 -- ignored Ghost code.
24878 Mark_Ghost_Pragma (N, Arg_Id);
24880 -- Capture the entity of the first Ghost type being
24881 -- processed for error detection purposes.
24883 if Is_Ghost_Entity (Arg_Id) then
24884 if No (Ghost_Id) then
24885 Ghost_Id := Arg_Id;
24886 end if;
24888 -- Otherwise the type is non-Ghost. It is illegal to mix
24889 -- references to Ghost and non-Ghost entities
24890 -- (SPARK RM 6.9).
24892 elsif Present (Ghost_Id)
24893 and then not Ghost_Error_Posted
24894 then
24895 Ghost_Error_Posted := True;
24897 Error_Msg_Name_1 := Pname;
24898 Error_Msg_N
24899 ("pragma % cannot mention ghost and non-ghost types",
24902 Error_Msg_Sloc := Sloc (Ghost_Id);
24903 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
24905 Error_Msg_Sloc := Sloc (Arg_Id);
24906 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
24907 end if;
24908 else
24909 Error_Pragma_Arg
24910 ("argument for pragma% must be type or subtype", Arg);
24911 end if;
24912 else
24913 Error_Pragma_Arg
24914 ("argument for pragma% must be type or subtype", Arg);
24915 end if;
24917 Next (Arg);
24918 end loop;
24919 end Unreferenced_Objects;
24921 ------------------------------
24922 -- Unreserve_All_Interrupts --
24923 ------------------------------
24925 -- pragma Unreserve_All_Interrupts;
24927 when Pragma_Unreserve_All_Interrupts =>
24928 GNAT_Pragma;
24929 Check_Arg_Count (0);
24931 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
24932 Unreserve_All_Interrupts := True;
24933 end if;
24935 ----------------
24936 -- Unsuppress --
24937 ----------------
24939 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
24941 when Pragma_Unsuppress =>
24942 Ada_2005_Pragma;
24943 Process_Suppress_Unsuppress (Suppress_Case => False);
24945 ------------
24946 -- Unused --
24947 ------------
24949 -- pragma Unused (LOCAL_NAME {, LOCAL_NAME});
24951 when Pragma_Unused =>
24952 Analyze_Unmodified_Or_Unused (Is_Unused => True);
24953 Analyze_Unreferenced_Or_Unused (Is_Unused => True);
24955 -------------------
24956 -- Use_VADS_Size --
24957 -------------------
24959 -- pragma Use_VADS_Size;
24961 when Pragma_Use_VADS_Size =>
24962 GNAT_Pragma;
24963 Check_Arg_Count (0);
24964 Check_Valid_Configuration_Pragma;
24965 Use_VADS_Size := True;
24967 ---------------------
24968 -- Validity_Checks --
24969 ---------------------
24971 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
24973 when Pragma_Validity_Checks => Validity_Checks : declare
24974 A : constant Node_Id := Get_Pragma_Arg (Arg1);
24975 S : String_Id;
24976 C : Char_Code;
24978 begin
24979 GNAT_Pragma;
24980 Check_Arg_Count (1);
24981 Check_No_Identifiers;
24983 -- Pragma always active unless in CodePeer or GNATprove modes,
24984 -- which use a fixed configuration of validity checks.
24986 if not (CodePeer_Mode or GNATprove_Mode) then
24987 if Nkind (A) = N_String_Literal then
24988 S := Strval (A);
24990 declare
24991 Slen : constant Natural := Natural (String_Length (S));
24992 Options : String (1 .. Slen);
24993 J : Positive;
24995 begin
24996 -- Couldn't we use a for loop here over Options'Range???
24998 J := 1;
24999 loop
25000 C := Get_String_Char (S, Pos (J));
25002 -- This is a weird test, it skips setting validity
25003 -- checks entirely if any element of S is out of
25004 -- range of Character, what is that about ???
25006 exit when not In_Character_Range (C);
25007 Options (J) := Get_Character (C);
25009 if J = Slen then
25010 Set_Validity_Check_Options (Options);
25011 exit;
25012 else
25013 J := J + 1;
25014 end if;
25015 end loop;
25016 end;
25018 elsif Nkind (A) = N_Identifier then
25019 if Chars (A) = Name_All_Checks then
25020 Set_Validity_Check_Options ("a");
25021 elsif Chars (A) = Name_On then
25022 Validity_Checks_On := True;
25023 elsif Chars (A) = Name_Off then
25024 Validity_Checks_On := False;
25025 end if;
25026 end if;
25027 end if;
25028 end Validity_Checks;
25030 --------------
25031 -- Volatile --
25032 --------------
25034 -- pragma Volatile (LOCAL_NAME);
25036 when Pragma_Volatile =>
25037 Process_Atomic_Independent_Shared_Volatile;
25039 -------------------------
25040 -- Volatile_Components --
25041 -------------------------
25043 -- pragma Volatile_Components (array_LOCAL_NAME);
25045 -- Volatile is handled by the same circuit as Atomic_Components
25047 --------------------------
25048 -- Volatile_Full_Access --
25049 --------------------------
25051 -- pragma Volatile_Full_Access (LOCAL_NAME);
25053 when Pragma_Volatile_Full_Access =>
25054 GNAT_Pragma;
25055 Process_Atomic_Independent_Shared_Volatile;
25057 -----------------------
25058 -- Volatile_Function --
25059 -----------------------
25061 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
25063 when Pragma_Volatile_Function => Volatile_Function : declare
25064 Over_Id : Entity_Id;
25065 Spec_Id : Entity_Id;
25066 Subp_Decl : Node_Id;
25068 begin
25069 GNAT_Pragma;
25070 Check_No_Identifiers;
25071 Check_At_Most_N_Arguments (1);
25073 Subp_Decl :=
25074 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
25076 -- Generic subprogram
25078 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
25079 null;
25081 -- Body acts as spec
25083 elsif Nkind (Subp_Decl) = N_Subprogram_Body
25084 and then No (Corresponding_Spec (Subp_Decl))
25085 then
25086 null;
25088 -- Body stub acts as spec
25090 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
25091 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
25092 then
25093 null;
25095 -- Subprogram
25097 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
25098 null;
25100 else
25101 Pragma_Misplaced;
25102 return;
25103 end if;
25105 Spec_Id := Unique_Defining_Entity (Subp_Decl);
25107 if Ekind (Spec_Id) not in E_Function | E_Generic_Function then
25108 Pragma_Misplaced;
25109 return;
25110 end if;
25112 -- A pragma that applies to a Ghost entity becomes Ghost for the
25113 -- purposes of legality checks and removal of ignored Ghost code.
25115 Mark_Ghost_Pragma (N, Spec_Id);
25117 -- Chain the pragma on the contract for completeness
25119 Add_Contract_Item (N, Spec_Id);
25121 -- The legality checks of pragma Volatile_Function are affected by
25122 -- the SPARK mode in effect. Analyze all pragmas in a specific
25123 -- order.
25125 Analyze_If_Present (Pragma_SPARK_Mode);
25127 -- A volatile function cannot override a non-volatile function
25128 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
25129 -- in New_Overloaded_Entity, however at that point the pragma has
25130 -- not been processed yet.
25132 Over_Id := Overridden_Operation (Spec_Id);
25134 if Present (Over_Id)
25135 and then not Is_Volatile_Function (Over_Id)
25136 then
25137 Error_Msg_N
25138 ("incompatible volatile function values in effect", Spec_Id);
25140 Error_Msg_Sloc := Sloc (Over_Id);
25141 Error_Msg_N
25142 ("\& declared # with Volatile_Function value False",
25143 Spec_Id);
25145 Error_Msg_Sloc := Sloc (Spec_Id);
25146 Error_Msg_N
25147 ("\overridden # with Volatile_Function value True",
25148 Spec_Id);
25149 end if;
25151 -- Analyze the Boolean expression (if any)
25153 if Present (Arg1) then
25154 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
25155 end if;
25156 end Volatile_Function;
25158 ----------------------
25159 -- Warning_As_Error --
25160 ----------------------
25162 -- pragma Warning_As_Error (static_string_EXPRESSION);
25164 when Pragma_Warning_As_Error =>
25165 GNAT_Pragma;
25166 Check_Arg_Count (1);
25167 Check_No_Identifiers;
25168 Check_Valid_Configuration_Pragma;
25170 if not Is_Static_String_Expression (Arg1) then
25171 Error_Pragma_Arg
25172 ("argument of pragma% must be static string expression",
25173 Arg1);
25175 -- OK static string expression
25177 else
25178 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
25179 Warnings_As_Errors (Warnings_As_Errors_Count) :=
25180 new String'(Acquire_Warning_Match_String
25181 (Expr_Value_S (Get_Pragma_Arg (Arg1))));
25182 end if;
25184 --------------
25185 -- Warnings --
25186 --------------
25188 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
25190 -- DETAILS ::= On | Off
25191 -- DETAILS ::= On | Off, local_NAME
25192 -- DETAILS ::= static_string_EXPRESSION
25193 -- DETAILS ::= On | Off, static_string_EXPRESSION
25195 -- TOOL_NAME ::= GNAT | GNATprove
25197 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
25199 -- Note: If the first argument matches an allowed tool name, it is
25200 -- always considered to be a tool name, even if there is a string
25201 -- variable of that name.
25203 -- Note if the second argument of DETAILS is a local_NAME then the
25204 -- second form is always understood. If the intention is to use
25205 -- the fourth form, then you can write NAME & "" to force the
25206 -- intepretation as a static_string_EXPRESSION.
25208 when Pragma_Warnings => Warnings : declare
25209 Reason : String_Id;
25211 begin
25212 GNAT_Pragma;
25213 Check_At_Least_N_Arguments (1);
25215 -- See if last argument is labeled Reason. If so, make sure we
25216 -- have a string literal or a concatenation of string literals,
25217 -- and acquire the REASON string. Then remove the REASON argument
25218 -- by decreasing Num_Args by one; Remaining processing looks only
25219 -- at first Num_Args arguments).
25221 declare
25222 Last_Arg : constant Node_Id :=
25223 Last (Pragma_Argument_Associations (N));
25225 begin
25226 if Nkind (Last_Arg) = N_Pragma_Argument_Association
25227 and then Chars (Last_Arg) = Name_Reason
25228 then
25229 Start_String;
25230 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
25231 Reason := End_String;
25232 Arg_Count := Arg_Count - 1;
25234 -- Not allowed in compiler units (bootstrap issues)
25236 Check_Compiler_Unit ("Reason for pragma Warnings", N);
25238 -- No REASON string, set null string as reason
25240 else
25241 Reason := Null_String_Id;
25242 end if;
25243 end;
25245 -- Now proceed with REASON taken care of and eliminated
25247 Check_No_Identifiers;
25249 -- If debug flag -gnatd.i is set, pragma is ignored
25251 if Debug_Flag_Dot_I then
25252 return;
25253 end if;
25255 -- Process various forms of the pragma
25257 declare
25258 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
25259 Shifted_Args : List_Id;
25261 begin
25262 -- See if first argument is a tool name, currently either
25263 -- GNAT or GNATprove. If so, either ignore the pragma if the
25264 -- tool used does not match, or continue as if no tool name
25265 -- was given otherwise, by shifting the arguments.
25267 if Nkind (Argx) = N_Identifier
25268 and then Chars (Argx) in Name_Gnat | Name_Gnatprove
25269 then
25270 if Chars (Argx) = Name_Gnat then
25271 if CodePeer_Mode or GNATprove_Mode then
25272 Rewrite (N, Make_Null_Statement (Loc));
25273 Analyze (N);
25274 raise Pragma_Exit;
25275 end if;
25277 elsif Chars (Argx) = Name_Gnatprove then
25278 if not GNATprove_Mode then
25279 Rewrite (N, Make_Null_Statement (Loc));
25280 Analyze (N);
25281 raise Pragma_Exit;
25282 end if;
25284 else
25285 raise Program_Error;
25286 end if;
25288 -- At this point, the pragma Warnings applies to the tool,
25289 -- so continue with shifted arguments.
25291 Arg_Count := Arg_Count - 1;
25293 if Arg_Count = 1 then
25294 Shifted_Args := New_List (New_Copy (Arg2));
25295 elsif Arg_Count = 2 then
25296 Shifted_Args := New_List (New_Copy (Arg2),
25297 New_Copy (Arg3));
25298 elsif Arg_Count = 3 then
25299 Shifted_Args := New_List (New_Copy (Arg2),
25300 New_Copy (Arg3),
25301 New_Copy (Arg4));
25302 else
25303 raise Program_Error;
25304 end if;
25306 Rewrite (N,
25307 Make_Pragma (Loc,
25308 Chars => Name_Warnings,
25309 Pragma_Argument_Associations => Shifted_Args));
25310 Analyze (N);
25311 raise Pragma_Exit;
25312 end if;
25314 -- One argument case
25316 if Arg_Count = 1 then
25318 -- On/Off one argument case was processed by parser
25320 if Nkind (Argx) = N_Identifier
25321 and then Chars (Argx) in Name_On | Name_Off
25322 then
25323 null;
25325 -- One argument case must be ON/OFF or static string expr
25327 elsif not Is_Static_String_Expression (Arg1) then
25328 Error_Pragma_Arg
25329 ("argument of pragma% must be On/Off or static string "
25330 & "expression", Arg1);
25332 -- One argument string expression case
25334 else
25335 declare
25336 Lit : constant Node_Id := Expr_Value_S (Argx);
25337 Str : constant String_Id := Strval (Lit);
25338 Len : constant Nat := String_Length (Str);
25339 C : Char_Code;
25340 J : Nat;
25341 OK : Boolean;
25342 Chr : Character;
25344 begin
25345 J := 1;
25346 while J <= Len loop
25347 C := Get_String_Char (Str, J);
25348 OK := In_Character_Range (C);
25350 if OK then
25351 Chr := Get_Character (C);
25353 -- Dash case: only -Wxxx is accepted
25355 if J = 1
25356 and then J < Len
25357 and then Chr = '-'
25358 then
25359 J := J + 1;
25360 C := Get_String_Char (Str, J);
25361 Chr := Get_Character (C);
25362 exit when Chr = 'W';
25363 OK := False;
25365 -- Dot case
25367 elsif J < Len and then Chr = '.' then
25368 J := J + 1;
25369 C := Get_String_Char (Str, J);
25370 Chr := Get_Character (C);
25372 if not Set_Dot_Warning_Switch (Chr) then
25373 Error_Pragma_Arg
25374 ("invalid warning switch character "
25375 & '.' & Chr, Arg1);
25376 end if;
25378 -- Non-Dot case
25380 else
25381 OK := Set_Warning_Switch (Chr);
25382 end if;
25384 if not OK then
25385 Error_Pragma_Arg
25386 ("invalid warning switch character " & Chr,
25387 Arg1);
25388 end if;
25390 else
25391 Error_Pragma_Arg
25392 ("invalid wide character in warning switch ",
25393 Arg1);
25394 end if;
25396 J := J + 1;
25397 end loop;
25398 end;
25399 end if;
25401 -- Two or more arguments (must be two)
25403 else
25404 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
25405 Check_Arg_Count (2);
25407 declare
25408 E_Id : Node_Id;
25409 E : Entity_Id;
25410 Err : Boolean;
25412 begin
25413 E_Id := Get_Pragma_Arg (Arg2);
25414 Analyze (E_Id);
25416 -- In the expansion of an inlined body, a reference to
25417 -- the formal may be wrapped in a conversion if the
25418 -- actual is a conversion. Retrieve the real entity name.
25420 if (In_Instance_Body or In_Inlined_Body)
25421 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
25422 then
25423 E_Id := Expression (E_Id);
25424 end if;
25426 -- Entity name case
25428 if Is_Entity_Name (E_Id) then
25429 E := Entity (E_Id);
25431 if E = Any_Id then
25432 return;
25433 else
25434 loop
25435 Set_Warnings_Off
25436 (E, (Chars (Get_Pragma_Arg (Arg1)) =
25437 Name_Off));
25439 -- Suppress elaboration warnings if the entity
25440 -- denotes an elaboration target.
25442 if Is_Elaboration_Target (E) then
25443 Set_Is_Elaboration_Warnings_OK_Id (E, False);
25444 end if;
25446 -- For OFF case, make entry in warnings off
25447 -- pragma table for later processing. But we do
25448 -- not do that within an instance, since these
25449 -- warnings are about what is needed in the
25450 -- template, not an instance of it.
25452 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
25453 and then Warn_On_Warnings_Off
25454 and then not In_Instance
25455 then
25456 Warnings_Off_Pragmas.Append ((N, E, Reason));
25457 end if;
25459 if Is_Enumeration_Type (E) then
25460 declare
25461 Lit : Entity_Id;
25462 begin
25463 Lit := First_Literal (E);
25464 while Present (Lit) loop
25465 Set_Warnings_Off (Lit);
25466 Next_Literal (Lit);
25467 end loop;
25468 end;
25469 end if;
25471 exit when No (Homonym (E));
25472 E := Homonym (E);
25473 end loop;
25474 end if;
25476 -- Error if not entity or static string expression case
25478 elsif not Is_Static_String_Expression (Arg2) then
25479 Error_Pragma_Arg
25480 ("second argument of pragma% must be entity name "
25481 & "or static string expression", Arg2);
25483 -- Static string expression case
25485 else
25486 -- Note on configuration pragma case: If this is a
25487 -- configuration pragma, then for an OFF pragma, we
25488 -- just set Config True in the call, which is all
25489 -- that needs to be done. For the case of ON, this
25490 -- is normally an error, unless it is canceling the
25491 -- effect of a previous OFF pragma in the same file.
25492 -- In any other case, an error will be signalled (ON
25493 -- with no matching OFF).
25495 -- Note: We set Used if we are inside a generic to
25496 -- disable the test that the non-config case actually
25497 -- cancels a warning. That's because we can't be sure
25498 -- there isn't an instantiation in some other unit
25499 -- where a warning is suppressed.
25501 -- We could do a little better here by checking if the
25502 -- generic unit we are inside is public, but for now
25503 -- we don't bother with that refinement.
25505 declare
25506 Message : constant String :=
25507 Acquire_Warning_Match_String
25508 (Expr_Value_S (Get_Pragma_Arg (Arg2)));
25509 begin
25510 if Chars (Argx) = Name_Off then
25511 Set_Specific_Warning_Off
25512 (Loc, Message, Reason,
25513 Config => Is_Configuration_Pragma,
25514 Used => Inside_A_Generic or else In_Instance);
25516 elsif Chars (Argx) = Name_On then
25517 Set_Specific_Warning_On (Loc, Message, Err);
25519 if Err then
25520 Error_Msg
25521 ("??pragma Warnings On with no matching "
25522 & "Warnings Off", Loc);
25523 end if;
25524 end if;
25525 end;
25526 end if;
25527 end;
25528 end if;
25529 end;
25530 end Warnings;
25532 -------------------
25533 -- Weak_External --
25534 -------------------
25536 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
25538 when Pragma_Weak_External => Weak_External : declare
25539 Ent : Entity_Id;
25541 begin
25542 GNAT_Pragma;
25543 Check_Arg_Count (1);
25544 Check_Optional_Identifier (Arg1, Name_Entity);
25545 Check_Arg_Is_Library_Level_Local_Name (Arg1);
25546 Ent := Entity (Get_Pragma_Arg (Arg1));
25548 if Rep_Item_Too_Early (Ent, N) then
25549 return;
25550 else
25551 Ent := Underlying_Type (Ent);
25552 end if;
25554 -- The pragma applies to entities with addresses
25556 if Is_Type (Ent) then
25557 Error_Pragma ("pragma applies to objects and subprograms");
25558 end if;
25560 -- The only processing required is to link this item on to the
25561 -- list of rep items for the given entity. This is accomplished
25562 -- by the call to Rep_Item_Too_Late (when no error is detected
25563 -- and False is returned).
25565 if Rep_Item_Too_Late (Ent, N) then
25566 return;
25567 else
25568 Set_Has_Gigi_Rep_Item (Ent);
25569 end if;
25570 end Weak_External;
25572 -----------------------------
25573 -- Wide_Character_Encoding --
25574 -----------------------------
25576 -- pragma Wide_Character_Encoding (IDENTIFIER);
25578 when Pragma_Wide_Character_Encoding =>
25579 GNAT_Pragma;
25581 -- Nothing to do, handled in parser. Note that we do not enforce
25582 -- configuration pragma placement, this pragma can appear at any
25583 -- place in the source, allowing mixed encodings within a single
25584 -- source program.
25586 null;
25588 --------------------
25589 -- Unknown_Pragma --
25590 --------------------
25592 -- Should be impossible, since the case of an unknown pragma is
25593 -- separately processed before the case statement is entered.
25595 when Unknown_Pragma =>
25596 raise Program_Error;
25597 end case;
25599 -- AI05-0144: detect dangerous order dependence. Disabled for now,
25600 -- until AI is formally approved.
25602 -- Check_Order_Dependence;
25604 exception
25605 when Pragma_Exit => null;
25606 end Analyze_Pragma;
25608 ---------------------------------------------
25609 -- Analyze_Pre_Post_Condition_In_Decl_Part --
25610 ---------------------------------------------
25612 -- WARNING: This routine manages Ghost regions. Return statements must be
25613 -- replaced by gotos which jump to the end of the routine and restore the
25614 -- Ghost mode.
25616 procedure Analyze_Pre_Post_Condition_In_Decl_Part
25617 (N : Node_Id;
25618 Freeze_Id : Entity_Id := Empty)
25620 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
25621 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
25623 Disp_Typ : Entity_Id;
25624 -- The dispatching type of the subprogram subject to the pre- or
25625 -- postcondition.
25627 function Check_References (Nod : Node_Id) return Traverse_Result;
25628 -- Check that expression Nod does not mention non-primitives of the
25629 -- type, global objects of the type, or other illegalities described
25630 -- and implied by AI12-0113.
25632 ----------------------
25633 -- Check_References --
25634 ----------------------
25636 function Check_References (Nod : Node_Id) return Traverse_Result is
25637 begin
25638 if Nkind (Nod) = N_Function_Call
25639 and then Is_Entity_Name (Name (Nod))
25640 then
25641 declare
25642 Func : constant Entity_Id := Entity (Name (Nod));
25643 Form : Entity_Id;
25645 begin
25646 -- An operation of the type must be a primitive
25648 if No (Find_Dispatching_Type (Func)) then
25649 Form := First_Formal (Func);
25650 while Present (Form) loop
25651 if Etype (Form) = Disp_Typ then
25652 Error_Msg_NE
25653 ("operation in class-wide condition must be "
25654 & "primitive of &", Nod, Disp_Typ);
25655 end if;
25657 Next_Formal (Form);
25658 end loop;
25660 -- A return object of the type is illegal as well
25662 if Etype (Func) = Disp_Typ
25663 or else Etype (Func) = Class_Wide_Type (Disp_Typ)
25664 then
25665 Error_Msg_NE
25666 ("operation in class-wide condition must be primitive "
25667 & "of &", Nod, Disp_Typ);
25668 end if;
25670 -- Otherwise we have a call to an overridden primitive, and we
25671 -- will create a common class-wide clone for the body of
25672 -- original operation and its eventual inherited versions. If
25673 -- the original operation dispatches on result it is never
25674 -- inherited and there is no need for a clone. There is not
25675 -- need for a clone either in GNATprove mode, as cases that
25676 -- would require it are rejected (when an inherited primitive
25677 -- calls an overridden operation in a class-wide contract), and
25678 -- the clone would make proof impossible in some cases.
25680 elsif not Is_Abstract_Subprogram (Spec_Id)
25681 and then No (Class_Wide_Clone (Spec_Id))
25682 and then not Has_Controlling_Result (Spec_Id)
25683 and then not GNATprove_Mode
25684 then
25685 Build_Class_Wide_Clone_Decl (Spec_Id);
25686 end if;
25687 end;
25689 elsif Is_Entity_Name (Nod)
25690 and then
25691 (Etype (Nod) = Disp_Typ
25692 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
25693 and then Ekind (Entity (Nod)) in E_Constant | E_Variable
25694 then
25695 Error_Msg_NE
25696 ("object in class-wide condition must be formal of type &",
25697 Nod, Disp_Typ);
25699 elsif Nkind (Nod) = N_Explicit_Dereference
25700 and then (Etype (Nod) = Disp_Typ
25701 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
25702 and then (not Is_Entity_Name (Prefix (Nod))
25703 or else not Is_Formal (Entity (Prefix (Nod))))
25704 then
25705 Error_Msg_NE
25706 ("operation in class-wide condition must be primitive of &",
25707 Nod, Disp_Typ);
25708 end if;
25710 return OK;
25711 end Check_References;
25713 procedure Check_Class_Wide_Condition is
25714 new Traverse_Proc (Check_References);
25716 -- Local variables
25718 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
25720 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
25721 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
25722 -- Save the Ghost-related attributes to restore on exit
25724 Errors : Nat;
25725 Restore_Scope : Boolean := False;
25727 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
25729 begin
25730 -- Do not analyze the pragma multiple times
25732 if Is_Analyzed_Pragma (N) then
25733 return;
25734 end if;
25736 -- Set the Ghost mode in effect from the pragma. Due to the delayed
25737 -- analysis of the pragma, the Ghost mode at point of declaration and
25738 -- point of analysis may not necessarily be the same. Use the mode in
25739 -- effect at the point of declaration.
25741 Set_Ghost_Mode (N);
25743 -- Ensure that the subprogram and its formals are visible when analyzing
25744 -- the expression of the pragma.
25746 if not In_Open_Scopes (Spec_Id) then
25747 Restore_Scope := True;
25748 Push_Scope (Spec_Id);
25750 if Is_Generic_Subprogram (Spec_Id) then
25751 Install_Generic_Formals (Spec_Id);
25752 else
25753 Install_Formals (Spec_Id);
25754 end if;
25755 end if;
25757 Errors := Serious_Errors_Detected;
25758 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
25760 -- Emit a clarification message when the expression contains at least
25761 -- one undefined reference, possibly due to contract freezing.
25763 if Errors /= Serious_Errors_Detected
25764 and then Present (Freeze_Id)
25765 and then Has_Undefined_Reference (Expr)
25766 then
25767 Contract_Freeze_Error (Spec_Id, Freeze_Id);
25768 end if;
25770 if Class_Present (N) then
25772 -- Verify that a class-wide condition is legal, i.e. the operation is
25773 -- a primitive of a tagged type. Note that a generic subprogram is
25774 -- not a primitive operation.
25776 Disp_Typ := Find_Dispatching_Type (Spec_Id);
25778 if No (Disp_Typ) or else Is_Generic_Subprogram (Spec_Id) then
25779 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
25781 if From_Aspect_Specification (N) then
25782 Error_Msg_N
25783 ("aspect % can only be specified for a primitive operation "
25784 & "of a tagged type", Corresponding_Aspect (N));
25786 -- The pragma is a source construct
25788 else
25789 Error_Msg_N
25790 ("pragma % can only be specified for a primitive operation "
25791 & "of a tagged type", N);
25792 end if;
25794 -- Remaining semantic checks require a full tree traversal
25796 else
25797 Check_Class_Wide_Condition (Expr);
25798 end if;
25800 end if;
25802 if Restore_Scope then
25803 End_Scope;
25804 end if;
25806 -- If analysis of the condition indicates that a class-wide clone
25807 -- has been created, build and analyze its declaration.
25809 if Is_Subprogram (Spec_Id)
25810 and then Present (Class_Wide_Clone (Spec_Id))
25811 then
25812 Analyze (Unit_Declaration_Node (Class_Wide_Clone (Spec_Id)));
25813 end if;
25815 -- Currently it is not possible to inline pre/postconditions on a
25816 -- subprogram subject to pragma Inline_Always.
25818 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
25819 Set_Is_Analyzed_Pragma (N);
25821 Restore_Ghost_Region (Saved_GM, Saved_IGR);
25822 end Analyze_Pre_Post_Condition_In_Decl_Part;
25824 ------------------------------------------
25825 -- Analyze_Refined_Depends_In_Decl_Part --
25826 ------------------------------------------
25828 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
25829 procedure Check_Dependency_Clause
25830 (Spec_Id : Entity_Id;
25831 Dep_Clause : Node_Id;
25832 Dep_States : Elist_Id;
25833 Refinements : List_Id;
25834 Matched_Items : in out Elist_Id);
25835 -- Try to match a single dependency clause Dep_Clause against one or
25836 -- more refinement clauses found in list Refinements. Each successful
25837 -- match eliminates at least one refinement clause from Refinements.
25838 -- Spec_Id denotes the entity of the related subprogram. Dep_States
25839 -- denotes the entities of all abstract states which appear in pragma
25840 -- Depends. Matched_Items contains the entities of all successfully
25841 -- matched items found in pragma Depends.
25843 procedure Check_Output_States
25844 (Spec_Inputs : Elist_Id;
25845 Spec_Outputs : Elist_Id;
25846 Body_Inputs : Elist_Id;
25847 Body_Outputs : Elist_Id);
25848 -- Determine whether pragma Depends contains an output state with a
25849 -- visible refinement and if so, ensure that pragma Refined_Depends
25850 -- mentions all its constituents as outputs. Spec_Inputs and
25851 -- Spec_Outputs denote the inputs and outputs of the subprogram spec
25852 -- synthesized from pragma Depends. Body_Inputs and Body_Outputs denote
25853 -- the inputs and outputs of the subprogram body synthesized from pragma
25854 -- Refined_Depends.
25856 function Collect_States (Clauses : List_Id) return Elist_Id;
25857 -- Given a normalized list of dependencies obtained from calling
25858 -- Normalize_Clauses, return a list containing the entities of all
25859 -- states appearing in dependencies. It helps in checking refinements
25860 -- involving a state and a corresponding constituent which is not a
25861 -- direct constituent of the state.
25863 procedure Normalize_Clauses (Clauses : List_Id);
25864 -- Given a list of dependence or refinement clauses Clauses, normalize
25865 -- each clause by creating multiple dependencies with exactly one input
25866 -- and one output.
25868 procedure Remove_Extra_Clauses
25869 (Clauses : List_Id;
25870 Matched_Items : Elist_Id);
25871 -- Given a list of refinement clauses Clauses, remove all clauses whose
25872 -- inputs and/or outputs have been previously matched. See the body for
25873 -- all special cases. Matched_Items contains the entities of all matched
25874 -- items found in pragma Depends.
25876 procedure Report_Extra_Clauses (Clauses : List_Id);
25877 -- Emit an error for each extra clause found in list Clauses
25879 -----------------------------
25880 -- Check_Dependency_Clause --
25881 -----------------------------
25883 procedure Check_Dependency_Clause
25884 (Spec_Id : Entity_Id;
25885 Dep_Clause : Node_Id;
25886 Dep_States : Elist_Id;
25887 Refinements : List_Id;
25888 Matched_Items : in out Elist_Id)
25890 Dep_Input : constant Node_Id := Expression (Dep_Clause);
25891 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
25893 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean;
25894 -- Determine whether dependency item Dep_Item has been matched in a
25895 -- previous clause.
25897 function Is_In_Out_State_Clause return Boolean;
25898 -- Determine whether dependence clause Dep_Clause denotes an abstract
25899 -- state that depends on itself (State => State).
25901 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
25902 -- Determine whether item Item denotes an abstract state with visible
25903 -- null refinement.
25905 procedure Match_Items
25906 (Dep_Item : Node_Id;
25907 Ref_Item : Node_Id;
25908 Matched : out Boolean);
25909 -- Try to match dependence item Dep_Item against refinement item
25910 -- Ref_Item. To match against a possible null refinement (see 2, 9),
25911 -- set Ref_Item to Empty. Flag Matched is set to True when one of
25912 -- the following conformance scenarios is in effect:
25913 -- 1) Both items denote null
25914 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
25915 -- 3) Both items denote attribute 'Result
25916 -- 4) Both items denote the same object
25917 -- 5) Both items denote the same formal parameter
25918 -- 6) Both items denote the same current instance of a type
25919 -- 7) Both items denote the same discriminant
25920 -- 8) Dep_Item is an abstract state with visible null refinement
25921 -- and Ref_Item denotes null.
25922 -- 9) Dep_Item is an abstract state with visible null refinement
25923 -- and Ref_Item is Empty (special case).
25924 -- 10) Dep_Item is an abstract state with full or partial visible
25925 -- non-null refinement and Ref_Item denotes one of its
25926 -- constituents.
25927 -- 11) Dep_Item is an abstract state without a full visible
25928 -- refinement and Ref_Item denotes the same state.
25929 -- When scenario 10 is in effect, the entity of the abstract state
25930 -- denoted by Dep_Item is added to list Refined_States.
25932 procedure Record_Item (Item_Id : Entity_Id);
25933 -- Store the entity of an item denoted by Item_Id in Matched_Items
25935 ------------------------
25936 -- Is_Already_Matched --
25937 ------------------------
25939 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean is
25940 Item_Id : Entity_Id := Empty;
25942 begin
25943 -- When the dependency item denotes attribute 'Result, check for
25944 -- the entity of the related subprogram.
25946 if Is_Attribute_Result (Dep_Item) then
25947 Item_Id := Spec_Id;
25949 elsif Is_Entity_Name (Dep_Item) then
25950 Item_Id := Available_View (Entity_Of (Dep_Item));
25951 end if;
25953 return
25954 Present (Item_Id) and then Contains (Matched_Items, Item_Id);
25955 end Is_Already_Matched;
25957 ----------------------------
25958 -- Is_In_Out_State_Clause --
25959 ----------------------------
25961 function Is_In_Out_State_Clause return Boolean is
25962 Dep_Input_Id : Entity_Id;
25963 Dep_Output_Id : Entity_Id;
25965 begin
25966 -- Detect the following clause:
25967 -- State => State
25969 if Is_Entity_Name (Dep_Input)
25970 and then Is_Entity_Name (Dep_Output)
25971 then
25972 -- Handle abstract views generated for limited with clauses
25974 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
25975 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
25977 return
25978 Ekind (Dep_Input_Id) = E_Abstract_State
25979 and then Dep_Input_Id = Dep_Output_Id;
25980 else
25981 return False;
25982 end if;
25983 end Is_In_Out_State_Clause;
25985 ---------------------------
25986 -- Is_Null_Refined_State --
25987 ---------------------------
25989 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
25990 Item_Id : Entity_Id;
25992 begin
25993 if Is_Entity_Name (Item) then
25995 -- Handle abstract views generated for limited with clauses
25997 Item_Id := Available_View (Entity_Of (Item));
25999 return
26000 Ekind (Item_Id) = E_Abstract_State
26001 and then Has_Null_Visible_Refinement (Item_Id);
26002 else
26003 return False;
26004 end if;
26005 end Is_Null_Refined_State;
26007 -----------------
26008 -- Match_Items --
26009 -----------------
26011 procedure Match_Items
26012 (Dep_Item : Node_Id;
26013 Ref_Item : Node_Id;
26014 Matched : out Boolean)
26016 Dep_Item_Id : Entity_Id;
26017 Ref_Item_Id : Entity_Id;
26019 begin
26020 -- Assume that the two items do not match
26022 Matched := False;
26024 -- A null matches null or Empty (special case)
26026 if Nkind (Dep_Item) = N_Null
26027 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
26028 then
26029 Matched := True;
26031 -- Attribute 'Result matches attribute 'Result
26033 elsif Is_Attribute_Result (Dep_Item)
26034 and then Is_Attribute_Result (Ref_Item)
26035 then
26036 -- Put the entity of the related function on the list of
26037 -- matched items because attribute 'Result does not carry
26038 -- an entity similar to states and constituents.
26040 Record_Item (Spec_Id);
26041 Matched := True;
26043 -- Abstract states, current instances of concurrent types,
26044 -- discriminants, formal parameters and objects.
26046 elsif Is_Entity_Name (Dep_Item) then
26048 -- Handle abstract views generated for limited with clauses
26050 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
26052 if Ekind (Dep_Item_Id) = E_Abstract_State then
26054 -- An abstract state with visible null refinement matches
26055 -- null or Empty (special case).
26057 if Has_Null_Visible_Refinement (Dep_Item_Id)
26058 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
26059 then
26060 Record_Item (Dep_Item_Id);
26061 Matched := True;
26063 -- An abstract state with visible non-null refinement
26064 -- matches one of its constituents, or itself for an
26065 -- abstract state with partial visible refinement.
26067 elsif Has_Non_Null_Visible_Refinement (Dep_Item_Id) then
26068 if Is_Entity_Name (Ref_Item) then
26069 Ref_Item_Id := Entity_Of (Ref_Item);
26071 if Ekind (Ref_Item_Id) in
26072 E_Abstract_State | E_Constant | E_Variable
26073 and then Present (Encapsulating_State (Ref_Item_Id))
26074 and then Find_Encapsulating_State
26075 (Dep_States, Ref_Item_Id) = Dep_Item_Id
26076 then
26077 Record_Item (Dep_Item_Id);
26078 Matched := True;
26080 elsif not Has_Visible_Refinement (Dep_Item_Id)
26081 and then Ref_Item_Id = Dep_Item_Id
26082 then
26083 Record_Item (Dep_Item_Id);
26084 Matched := True;
26085 end if;
26086 end if;
26088 -- An abstract state without a visible refinement matches
26089 -- itself.
26091 elsif Is_Entity_Name (Ref_Item)
26092 and then Entity_Of (Ref_Item) = Dep_Item_Id
26093 then
26094 Record_Item (Dep_Item_Id);
26095 Matched := True;
26096 end if;
26098 -- A current instance of a concurrent type, discriminant,
26099 -- formal parameter or an object matches itself.
26101 elsif Is_Entity_Name (Ref_Item)
26102 and then Entity_Of (Ref_Item) = Dep_Item_Id
26103 then
26104 Record_Item (Dep_Item_Id);
26105 Matched := True;
26106 end if;
26107 end if;
26108 end Match_Items;
26110 -----------------
26111 -- Record_Item --
26112 -----------------
26114 procedure Record_Item (Item_Id : Entity_Id) is
26115 begin
26116 if No (Matched_Items) then
26117 Matched_Items := New_Elmt_List;
26118 end if;
26120 Append_Unique_Elmt (Item_Id, Matched_Items);
26121 end Record_Item;
26123 -- Local variables
26125 Clause_Matched : Boolean := False;
26126 Dummy : Boolean := False;
26127 Inputs_Match : Boolean;
26128 Next_Ref_Clause : Node_Id;
26129 Outputs_Match : Boolean;
26130 Ref_Clause : Node_Id;
26131 Ref_Input : Node_Id;
26132 Ref_Output : Node_Id;
26134 -- Start of processing for Check_Dependency_Clause
26136 begin
26137 -- Do not perform this check in an instance because it was already
26138 -- performed successfully in the generic template.
26140 if In_Instance then
26141 return;
26142 end if;
26144 -- Examine all refinement clauses and compare them against the
26145 -- dependence clause.
26147 Ref_Clause := First (Refinements);
26148 while Present (Ref_Clause) loop
26149 Next_Ref_Clause := Next (Ref_Clause);
26151 -- Obtain the attributes of the current refinement clause
26153 Ref_Input := Expression (Ref_Clause);
26154 Ref_Output := First (Choices (Ref_Clause));
26156 -- The current refinement clause matches the dependence clause
26157 -- when both outputs match and both inputs match. See routine
26158 -- Match_Items for all possible conformance scenarios.
26160 -- Depends Dep_Output => Dep_Input
26161 -- ^ ^
26162 -- match ? match ?
26163 -- v v
26164 -- Refined_Depends Ref_Output => Ref_Input
26166 Match_Items
26167 (Dep_Item => Dep_Input,
26168 Ref_Item => Ref_Input,
26169 Matched => Inputs_Match);
26171 Match_Items
26172 (Dep_Item => Dep_Output,
26173 Ref_Item => Ref_Output,
26174 Matched => Outputs_Match);
26176 -- An In_Out state clause may be matched against a refinement with
26177 -- a null input or null output as long as the non-null side of the
26178 -- relation contains a valid constituent of the In_Out_State.
26180 if Is_In_Out_State_Clause then
26182 -- Depends => (State => State)
26183 -- Refined_Depends => (null => Constit) -- OK
26185 if Inputs_Match
26186 and then not Outputs_Match
26187 and then Nkind (Ref_Output) = N_Null
26188 then
26189 Outputs_Match := True;
26190 end if;
26192 -- Depends => (State => State)
26193 -- Refined_Depends => (Constit => null) -- OK
26195 if not Inputs_Match
26196 and then Outputs_Match
26197 and then Nkind (Ref_Input) = N_Null
26198 then
26199 Inputs_Match := True;
26200 end if;
26201 end if;
26203 -- The current refinement clause is legally constructed following
26204 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
26205 -- the pool of candidates. The seach continues because a single
26206 -- dependence clause may have multiple matching refinements.
26208 if Inputs_Match and Outputs_Match then
26209 Clause_Matched := True;
26210 Remove (Ref_Clause);
26211 end if;
26213 Ref_Clause := Next_Ref_Clause;
26214 end loop;
26216 -- Depending on the order or composition of refinement clauses, an
26217 -- In_Out state clause may not be directly refinable.
26219 -- Refined_State => (State => (Constit_1, Constit_2))
26220 -- Depends => ((Output, State) => (Input, State))
26221 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
26223 -- Matching normalized clause (State => State) fails because there is
26224 -- no direct refinement capable of satisfying this relation. Another
26225 -- similar case arises when clauses (Constit_1 => Input) and (Output
26226 -- => Constit_2) are matched first, leaving no candidates for clause
26227 -- (State => State). Both scenarios are legal as long as one of the
26228 -- previous clauses mentioned a valid constituent of State.
26230 if not Clause_Matched
26231 and then Is_In_Out_State_Clause
26232 and then Is_Already_Matched (Dep_Input)
26233 then
26234 Clause_Matched := True;
26235 end if;
26237 -- A clause where the input is an abstract state with visible null
26238 -- refinement or a 'Result attribute is implicitly matched when the
26239 -- output has already been matched in a previous clause.
26241 -- Refined_State => (State => null)
26242 -- Depends => (Output => State) -- implicitly OK
26243 -- Refined_Depends => (Output => ...)
26244 -- Depends => (...'Result => State) -- implicitly OK
26245 -- Refined_Depends => (...'Result => ...)
26247 if not Clause_Matched
26248 and then Is_Null_Refined_State (Dep_Input)
26249 and then Is_Already_Matched (Dep_Output)
26250 then
26251 Clause_Matched := True;
26252 end if;
26254 -- A clause where the output is an abstract state with visible null
26255 -- refinement is implicitly matched when the input has already been
26256 -- matched in a previous clause.
26258 -- Refined_State => (State => null)
26259 -- Depends => (State => Input) -- implicitly OK
26260 -- Refined_Depends => (... => Input)
26262 if not Clause_Matched
26263 and then Is_Null_Refined_State (Dep_Output)
26264 and then Is_Already_Matched (Dep_Input)
26265 then
26266 Clause_Matched := True;
26267 end if;
26269 -- At this point either all refinement clauses have been examined or
26270 -- pragma Refined_Depends contains a solitary null. Only an abstract
26271 -- state with null refinement can possibly match these cases.
26273 -- Refined_State => (State => null)
26274 -- Depends => (State => null)
26275 -- Refined_Depends => null -- OK
26277 if not Clause_Matched then
26278 Match_Items
26279 (Dep_Item => Dep_Input,
26280 Ref_Item => Empty,
26281 Matched => Inputs_Match);
26283 Match_Items
26284 (Dep_Item => Dep_Output,
26285 Ref_Item => Empty,
26286 Matched => Outputs_Match);
26288 Clause_Matched := Inputs_Match and Outputs_Match;
26289 end if;
26291 -- If the contents of Refined_Depends are legal, then the current
26292 -- dependence clause should be satisfied either by an explicit match
26293 -- or by one of the special cases.
26295 if not Clause_Matched then
26296 SPARK_Msg_NE
26297 (Fix_Msg (Spec_Id, "dependence clause of subprogram & has no "
26298 & "matching refinement in body"), Dep_Clause, Spec_Id);
26299 end if;
26300 end Check_Dependency_Clause;
26302 -------------------------
26303 -- Check_Output_States --
26304 -------------------------
26306 procedure Check_Output_States
26307 (Spec_Inputs : Elist_Id;
26308 Spec_Outputs : Elist_Id;
26309 Body_Inputs : Elist_Id;
26310 Body_Outputs : Elist_Id)
26312 procedure Check_Constituent_Usage (State_Id : Entity_Id);
26313 -- Determine whether all constituents of state State_Id with full
26314 -- visible refinement are used as outputs in pragma Refined_Depends.
26315 -- Emit an error if this is not the case (SPARK RM 7.2.4(5)).
26317 -----------------------------
26318 -- Check_Constituent_Usage --
26319 -----------------------------
26321 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
26322 Constits : constant Elist_Id :=
26323 Partial_Refinement_Constituents (State_Id);
26324 Constit_Elmt : Elmt_Id;
26325 Constit_Id : Entity_Id;
26326 Only_Partial : constant Boolean :=
26327 not Has_Visible_Refinement (State_Id);
26328 Posted : Boolean := False;
26330 begin
26331 if Present (Constits) then
26332 Constit_Elmt := First_Elmt (Constits);
26333 while Present (Constit_Elmt) loop
26334 Constit_Id := Node (Constit_Elmt);
26336 -- Issue an error when a constituent of State_Id is used,
26337 -- and State_Id has only partial visible refinement
26338 -- (SPARK RM 7.2.4(3d)).
26340 if Only_Partial then
26341 if (Present (Body_Inputs)
26342 and then Appears_In (Body_Inputs, Constit_Id))
26343 or else
26344 (Present (Body_Outputs)
26345 and then Appears_In (Body_Outputs, Constit_Id))
26346 then
26347 Error_Msg_Name_1 := Chars (State_Id);
26348 SPARK_Msg_NE
26349 ("constituent & of state % cannot be used in "
26350 & "dependence refinement", N, Constit_Id);
26351 Error_Msg_Name_1 := Chars (State_Id);
26352 SPARK_Msg_N ("\use state % instead", N);
26353 end if;
26355 -- The constituent acts as an input (SPARK RM 7.2.5(3))
26357 elsif Present (Body_Inputs)
26358 and then Appears_In (Body_Inputs, Constit_Id)
26359 then
26360 Error_Msg_Name_1 := Chars (State_Id);
26361 SPARK_Msg_NE
26362 ("constituent & of state % must act as output in "
26363 & "dependence refinement", N, Constit_Id);
26365 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
26367 elsif No (Body_Outputs)
26368 or else not Appears_In (Body_Outputs, Constit_Id)
26369 then
26370 if not Posted then
26371 Posted := True;
26372 SPARK_Msg_NE
26373 ("output state & must be replaced by all its "
26374 & "constituents in dependence refinement",
26375 N, State_Id);
26376 end if;
26378 SPARK_Msg_NE
26379 ("\constituent & is missing in output list",
26380 N, Constit_Id);
26381 end if;
26383 Next_Elmt (Constit_Elmt);
26384 end loop;
26385 end if;
26386 end Check_Constituent_Usage;
26388 -- Local variables
26390 Item : Node_Id;
26391 Item_Elmt : Elmt_Id;
26392 Item_Id : Entity_Id;
26394 -- Start of processing for Check_Output_States
26396 begin
26397 -- Do not perform this check in an instance because it was already
26398 -- performed successfully in the generic template.
26400 if In_Instance then
26401 null;
26403 -- Inspect the outputs of pragma Depends looking for a state with a
26404 -- visible refinement.
26406 elsif Present (Spec_Outputs) then
26407 Item_Elmt := First_Elmt (Spec_Outputs);
26408 while Present (Item_Elmt) loop
26409 Item := Node (Item_Elmt);
26411 -- Deal with the mixed nature of the input and output lists
26413 if Nkind (Item) = N_Defining_Identifier then
26414 Item_Id := Item;
26415 else
26416 Item_Id := Available_View (Entity_Of (Item));
26417 end if;
26419 if Ekind (Item_Id) = E_Abstract_State then
26421 -- The state acts as an input-output, skip it
26423 if Present (Spec_Inputs)
26424 and then Appears_In (Spec_Inputs, Item_Id)
26425 then
26426 null;
26428 -- Ensure that all of the constituents are utilized as
26429 -- outputs in pragma Refined_Depends.
26431 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
26432 Check_Constituent_Usage (Item_Id);
26433 end if;
26434 end if;
26436 Next_Elmt (Item_Elmt);
26437 end loop;
26438 end if;
26439 end Check_Output_States;
26441 --------------------
26442 -- Collect_States --
26443 --------------------
26445 function Collect_States (Clauses : List_Id) return Elist_Id is
26446 procedure Collect_State
26447 (Item : Node_Id;
26448 States : in out Elist_Id);
26449 -- Add the entity of Item to list States when it denotes to a state
26451 -------------------
26452 -- Collect_State --
26453 -------------------
26455 procedure Collect_State
26456 (Item : Node_Id;
26457 States : in out Elist_Id)
26459 Id : Entity_Id;
26461 begin
26462 if Is_Entity_Name (Item) then
26463 Id := Entity_Of (Item);
26465 if Ekind (Id) = E_Abstract_State then
26466 if No (States) then
26467 States := New_Elmt_List;
26468 end if;
26470 Append_Unique_Elmt (Id, States);
26471 end if;
26472 end if;
26473 end Collect_State;
26475 -- Local variables
26477 Clause : Node_Id;
26478 Input : Node_Id;
26479 Output : Node_Id;
26480 States : Elist_Id := No_Elist;
26482 -- Start of processing for Collect_States
26484 begin
26485 Clause := First (Clauses);
26486 while Present (Clause) loop
26487 Input := Expression (Clause);
26488 Output := First (Choices (Clause));
26490 Collect_State (Input, States);
26491 Collect_State (Output, States);
26493 Next (Clause);
26494 end loop;
26496 return States;
26497 end Collect_States;
26499 -----------------------
26500 -- Normalize_Clauses --
26501 -----------------------
26503 procedure Normalize_Clauses (Clauses : List_Id) is
26504 procedure Normalize_Inputs (Clause : Node_Id);
26505 -- Normalize clause Clause by creating multiple clauses for each
26506 -- input item of Clause. It is assumed that Clause has exactly one
26507 -- output. The transformation is as follows:
26509 -- Output => (Input_1, Input_2) -- original
26511 -- Output => Input_1 -- normalizations
26512 -- Output => Input_2
26514 procedure Normalize_Outputs (Clause : Node_Id);
26515 -- Normalize clause Clause by creating multiple clause for each
26516 -- output item of Clause. The transformation is as follows:
26518 -- (Output_1, Output_2) => Input -- original
26520 -- Output_1 => Input -- normalization
26521 -- Output_2 => Input
26523 ----------------------
26524 -- Normalize_Inputs --
26525 ----------------------
26527 procedure Normalize_Inputs (Clause : Node_Id) is
26528 Inputs : constant Node_Id := Expression (Clause);
26529 Loc : constant Source_Ptr := Sloc (Clause);
26530 Output : constant List_Id := Choices (Clause);
26531 Last_Input : Node_Id;
26532 Input : Node_Id;
26533 New_Clause : Node_Id;
26534 Next_Input : Node_Id;
26536 begin
26537 -- Normalization is performed only when the original clause has
26538 -- more than one input. Multiple inputs appear as an aggregate.
26540 if Nkind (Inputs) = N_Aggregate then
26541 Last_Input := Last (Expressions (Inputs));
26543 -- Create a new clause for each input
26545 Input := First (Expressions (Inputs));
26546 while Present (Input) loop
26547 Next_Input := Next (Input);
26549 -- Unhook the current input from the original input list
26550 -- because it will be relocated to a new clause.
26552 Remove (Input);
26554 -- Special processing for the last input. At this point the
26555 -- original aggregate has been stripped down to one element.
26556 -- Replace the aggregate by the element itself.
26558 if Input = Last_Input then
26559 Rewrite (Inputs, Input);
26561 -- Generate a clause of the form:
26562 -- Output => Input
26564 else
26565 New_Clause :=
26566 Make_Component_Association (Loc,
26567 Choices => New_Copy_List_Tree (Output),
26568 Expression => Input);
26570 -- The new clause contains replicated content that has
26571 -- already been analyzed, mark the clause as analyzed.
26573 Set_Analyzed (New_Clause);
26574 Insert_After (Clause, New_Clause);
26575 end if;
26577 Input := Next_Input;
26578 end loop;
26579 end if;
26580 end Normalize_Inputs;
26582 -----------------------
26583 -- Normalize_Outputs --
26584 -----------------------
26586 procedure Normalize_Outputs (Clause : Node_Id) is
26587 Inputs : constant Node_Id := Expression (Clause);
26588 Loc : constant Source_Ptr := Sloc (Clause);
26589 Outputs : constant Node_Id := First (Choices (Clause));
26590 Last_Output : Node_Id;
26591 New_Clause : Node_Id;
26592 Next_Output : Node_Id;
26593 Output : Node_Id;
26595 begin
26596 -- Multiple outputs appear as an aggregate. Nothing to do when
26597 -- the clause has exactly one output.
26599 if Nkind (Outputs) = N_Aggregate then
26600 Last_Output := Last (Expressions (Outputs));
26602 -- Create a clause for each output. Note that each time a new
26603 -- clause is created, the original output list slowly shrinks
26604 -- until there is one item left.
26606 Output := First (Expressions (Outputs));
26607 while Present (Output) loop
26608 Next_Output := Next (Output);
26610 -- Unhook the output from the original output list as it
26611 -- will be relocated to a new clause.
26613 Remove (Output);
26615 -- Special processing for the last output. At this point
26616 -- the original aggregate has been stripped down to one
26617 -- element. Replace the aggregate by the element itself.
26619 if Output = Last_Output then
26620 Rewrite (Outputs, Output);
26622 else
26623 -- Generate a clause of the form:
26624 -- (Output => Inputs)
26626 New_Clause :=
26627 Make_Component_Association (Loc,
26628 Choices => New_List (Output),
26629 Expression => New_Copy_Tree (Inputs));
26631 -- The new clause contains replicated content that has
26632 -- already been analyzed. There is not need to reanalyze
26633 -- them.
26635 Set_Analyzed (New_Clause);
26636 Insert_After (Clause, New_Clause);
26637 end if;
26639 Output := Next_Output;
26640 end loop;
26641 end if;
26642 end Normalize_Outputs;
26644 -- Local variables
26646 Clause : Node_Id;
26648 -- Start of processing for Normalize_Clauses
26650 begin
26651 Clause := First (Clauses);
26652 while Present (Clause) loop
26653 Normalize_Outputs (Clause);
26654 Next (Clause);
26655 end loop;
26657 Clause := First (Clauses);
26658 while Present (Clause) loop
26659 Normalize_Inputs (Clause);
26660 Next (Clause);
26661 end loop;
26662 end Normalize_Clauses;
26664 --------------------------
26665 -- Remove_Extra_Clauses --
26666 --------------------------
26668 procedure Remove_Extra_Clauses
26669 (Clauses : List_Id;
26670 Matched_Items : Elist_Id)
26672 Clause : Node_Id;
26673 Input : Node_Id;
26674 Input_Id : Entity_Id;
26675 Next_Clause : Node_Id;
26676 Output : Node_Id;
26677 State_Id : Entity_Id;
26679 begin
26680 Clause := First (Clauses);
26681 while Present (Clause) loop
26682 Next_Clause := Next (Clause);
26684 Input := Expression (Clause);
26685 Output := First (Choices (Clause));
26687 -- Recognize a clause of the form
26689 -- null => Input
26691 -- where Input is a constituent of a state which was already
26692 -- successfully matched. This clause must be removed because it
26693 -- simply indicates that some of the constituents of the state
26694 -- are not used.
26696 -- Refined_State => (State => (Constit_1, Constit_2))
26697 -- Depends => (Output => State)
26698 -- Refined_Depends => ((Output => Constit_1), -- State matched
26699 -- (null => Constit_2)) -- OK
26701 if Nkind (Output) = N_Null and then Is_Entity_Name (Input) then
26703 -- Handle abstract views generated for limited with clauses
26705 Input_Id := Available_View (Entity_Of (Input));
26707 -- The input must be a constituent of a state
26709 if Ekind (Input_Id) in
26710 E_Abstract_State | E_Constant | E_Variable
26711 and then Present (Encapsulating_State (Input_Id))
26712 then
26713 State_Id := Encapsulating_State (Input_Id);
26715 -- The state must have a non-null visible refinement and be
26716 -- matched in a previous clause.
26718 if Has_Non_Null_Visible_Refinement (State_Id)
26719 and then Contains (Matched_Items, State_Id)
26720 then
26721 Remove (Clause);
26722 end if;
26723 end if;
26725 -- Recognize a clause of the form
26727 -- Output => null
26729 -- where Output is an arbitrary item. This clause must be removed
26730 -- because a null input legitimately matches anything.
26732 elsif Nkind (Input) = N_Null then
26733 Remove (Clause);
26734 end if;
26736 Clause := Next_Clause;
26737 end loop;
26738 end Remove_Extra_Clauses;
26740 --------------------------
26741 -- Report_Extra_Clauses --
26742 --------------------------
26744 procedure Report_Extra_Clauses (Clauses : List_Id) is
26745 Clause : Node_Id;
26747 begin
26748 -- Do not perform this check in an instance because it was already
26749 -- performed successfully in the generic template.
26751 if In_Instance then
26752 null;
26754 elsif Present (Clauses) then
26755 Clause := First (Clauses);
26756 while Present (Clause) loop
26757 SPARK_Msg_N
26758 ("unmatched or extra clause in dependence refinement",
26759 Clause);
26761 Next (Clause);
26762 end loop;
26763 end if;
26764 end Report_Extra_Clauses;
26766 -- Local variables
26768 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
26769 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
26770 Errors : constant Nat := Serious_Errors_Detected;
26772 Clause : Node_Id;
26773 Deps : Node_Id;
26774 Dummy : Boolean;
26775 Refs : Node_Id;
26777 Body_Inputs : Elist_Id := No_Elist;
26778 Body_Outputs : Elist_Id := No_Elist;
26779 -- The inputs and outputs of the subprogram body synthesized from pragma
26780 -- Refined_Depends.
26782 Dependencies : List_Id := No_List;
26783 Depends : Node_Id;
26784 -- The corresponding Depends pragma along with its clauses
26786 Matched_Items : Elist_Id := No_Elist;
26787 -- A list containing the entities of all successfully matched items
26788 -- found in pragma Depends.
26790 Refinements : List_Id := No_List;
26791 -- The clauses of pragma Refined_Depends
26793 Spec_Id : Entity_Id;
26794 -- The entity of the subprogram subject to pragma Refined_Depends
26796 Spec_Inputs : Elist_Id := No_Elist;
26797 Spec_Outputs : Elist_Id := No_Elist;
26798 -- The inputs and outputs of the subprogram spec synthesized from pragma
26799 -- Depends.
26801 States : Elist_Id := No_Elist;
26802 -- A list containing the entities of all states whose constituents
26803 -- appear in pragma Depends.
26805 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
26807 begin
26808 -- Do not analyze the pragma multiple times
26810 if Is_Analyzed_Pragma (N) then
26811 return;
26812 end if;
26814 Spec_Id := Unique_Defining_Entity (Body_Decl);
26816 -- Use the anonymous object as the proper spec when Refined_Depends
26817 -- applies to the body of a single task type. The object carries the
26818 -- proper Chars as well as all non-refined versions of pragmas.
26820 if Is_Single_Concurrent_Type (Spec_Id) then
26821 Spec_Id := Anonymous_Object (Spec_Id);
26822 end if;
26824 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
26826 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
26827 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
26829 if No (Depends) then
26830 SPARK_Msg_NE
26831 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
26832 & "& lacks aspect or pragma Depends"), N, Spec_Id);
26833 goto Leave;
26834 end if;
26836 Deps := Expression (Get_Argument (Depends, Spec_Id));
26838 -- A null dependency relation renders the refinement useless because it
26839 -- cannot possibly mention abstract states with visible refinement. Note
26840 -- that the inverse is not true as states may be refined to null
26841 -- (SPARK RM 7.2.5(2)).
26843 if Nkind (Deps) = N_Null then
26844 SPARK_Msg_NE
26845 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
26846 & "depend on abstract state with visible refinement"), N, Spec_Id);
26847 goto Leave;
26848 end if;
26850 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
26851 -- This ensures that the categorization of all refined dependency items
26852 -- is consistent with their role.
26854 Analyze_Depends_In_Decl_Part (N);
26856 -- Do not match dependencies against refinements if Refined_Depends is
26857 -- illegal to avoid emitting misleading error.
26859 if Serious_Errors_Detected = Errors then
26861 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
26862 -- the inputs and outputs of the subprogram spec and body to verify
26863 -- the use of states with visible refinement and their constituents.
26865 if No (Get_Pragma (Spec_Id, Pragma_Global))
26866 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
26867 then
26868 Collect_Subprogram_Inputs_Outputs
26869 (Subp_Id => Spec_Id,
26870 Synthesize => True,
26871 Subp_Inputs => Spec_Inputs,
26872 Subp_Outputs => Spec_Outputs,
26873 Global_Seen => Dummy);
26875 Collect_Subprogram_Inputs_Outputs
26876 (Subp_Id => Body_Id,
26877 Synthesize => True,
26878 Subp_Inputs => Body_Inputs,
26879 Subp_Outputs => Body_Outputs,
26880 Global_Seen => Dummy);
26882 -- For an output state with a visible refinement, ensure that all
26883 -- constituents appear as outputs in the dependency refinement.
26885 Check_Output_States
26886 (Spec_Inputs => Spec_Inputs,
26887 Spec_Outputs => Spec_Outputs,
26888 Body_Inputs => Body_Inputs,
26889 Body_Outputs => Body_Outputs);
26890 end if;
26892 -- Multiple dependency clauses appear as component associations of an
26893 -- aggregate. Note that the clauses are copied because the algorithm
26894 -- modifies them and this should not be visible in Depends.
26896 pragma Assert (Nkind (Deps) = N_Aggregate);
26897 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
26898 Normalize_Clauses (Dependencies);
26900 -- Gather all states which appear in Depends
26902 States := Collect_States (Dependencies);
26904 Refs := Expression (Get_Argument (N, Spec_Id));
26906 if Nkind (Refs) = N_Null then
26907 Refinements := No_List;
26909 -- Multiple dependency clauses appear as component associations of an
26910 -- aggregate. Note that the clauses are copied because the algorithm
26911 -- modifies them and this should not be visible in Refined_Depends.
26913 else pragma Assert (Nkind (Refs) = N_Aggregate);
26914 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
26915 Normalize_Clauses (Refinements);
26916 end if;
26918 -- At this point the clauses of pragmas Depends and Refined_Depends
26919 -- have been normalized into simple dependencies between one output
26920 -- and one input. Examine all clauses of pragma Depends looking for
26921 -- matching clauses in pragma Refined_Depends.
26923 Clause := First (Dependencies);
26924 while Present (Clause) loop
26925 Check_Dependency_Clause
26926 (Spec_Id => Spec_Id,
26927 Dep_Clause => Clause,
26928 Dep_States => States,
26929 Refinements => Refinements,
26930 Matched_Items => Matched_Items);
26932 Next (Clause);
26933 end loop;
26935 -- Pragma Refined_Depends may contain multiple clarification clauses
26936 -- which indicate that certain constituents do not influence the data
26937 -- flow in any way. Such clauses must be removed as long as the state
26938 -- has been matched, otherwise they will be incorrectly flagged as
26939 -- unmatched.
26941 -- Refined_State => (State => (Constit_1, Constit_2))
26942 -- Depends => (Output => State)
26943 -- Refined_Depends => ((Output => Constit_1), -- State matched
26944 -- (null => Constit_2)) -- must be removed
26946 Remove_Extra_Clauses (Refinements, Matched_Items);
26948 if Serious_Errors_Detected = Errors then
26949 Report_Extra_Clauses (Refinements);
26950 end if;
26951 end if;
26953 <<Leave>>
26954 Set_Is_Analyzed_Pragma (N);
26955 end Analyze_Refined_Depends_In_Decl_Part;
26957 -----------------------------------------
26958 -- Analyze_Refined_Global_In_Decl_Part --
26959 -----------------------------------------
26961 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
26962 Global : Node_Id;
26963 -- The corresponding Global pragma
26965 Has_In_State : Boolean := False;
26966 Has_In_Out_State : Boolean := False;
26967 Has_Out_State : Boolean := False;
26968 Has_Proof_In_State : Boolean := False;
26969 -- These flags are set when the corresponding Global pragma has a state
26970 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
26971 -- refinement.
26973 Has_Null_State : Boolean := False;
26974 -- This flag is set when the corresponding Global pragma has at least
26975 -- one state with a null refinement.
26977 In_Constits : Elist_Id := No_Elist;
26978 In_Out_Constits : Elist_Id := No_Elist;
26979 Out_Constits : Elist_Id := No_Elist;
26980 Proof_In_Constits : Elist_Id := No_Elist;
26981 -- These lists contain the entities of all Input, In_Out, Output and
26982 -- Proof_In constituents that appear in Refined_Global and participate
26983 -- in state refinement.
26985 In_Items : Elist_Id := No_Elist;
26986 In_Out_Items : Elist_Id := No_Elist;
26987 Out_Items : Elist_Id := No_Elist;
26988 Proof_In_Items : Elist_Id := No_Elist;
26989 -- These lists contain the entities of all Input, In_Out, Output and
26990 -- Proof_In items defined in the corresponding Global pragma.
26992 Repeat_Items : Elist_Id := No_Elist;
26993 -- A list of all global items without full visible refinement found
26994 -- in pragma Global. These states should be repeated in the global
26995 -- refinement (SPARK RM 7.2.4(3c)) unless they have a partial visible
26996 -- refinement, in which case they may be repeated (SPARK RM 7.2.4(3d)).
26998 Spec_Id : Entity_Id;
26999 -- The entity of the subprogram subject to pragma Refined_Global
27001 States : Elist_Id := No_Elist;
27002 -- A list of all states with full or partial visible refinement found in
27003 -- pragma Global.
27005 procedure Check_In_Out_States;
27006 -- Determine whether the corresponding Global pragma mentions In_Out
27007 -- states with visible refinement and if so, ensure that one of the
27008 -- following completions apply to the constituents of the state:
27009 -- 1) there is at least one constituent of mode In_Out
27010 -- 2) there is at least one Input and one Output constituent
27011 -- 3) not all constituents are present and one of them is of mode
27012 -- Output.
27013 -- This routine may remove elements from In_Constits, In_Out_Constits,
27014 -- Out_Constits and Proof_In_Constits.
27016 procedure Check_Input_States;
27017 -- Determine whether the corresponding Global pragma mentions Input
27018 -- states with visible refinement and if so, ensure that at least one of
27019 -- its constituents appears as an Input item in Refined_Global.
27020 -- This routine may remove elements from In_Constits, In_Out_Constits,
27021 -- Out_Constits and Proof_In_Constits.
27023 procedure Check_Output_States;
27024 -- Determine whether the corresponding Global pragma mentions Output
27025 -- states with visible refinement and if so, ensure that all of its
27026 -- constituents appear as Output items in Refined_Global.
27027 -- This routine may remove elements from In_Constits, In_Out_Constits,
27028 -- Out_Constits and Proof_In_Constits.
27030 procedure Check_Proof_In_States;
27031 -- Determine whether the corresponding Global pragma mentions Proof_In
27032 -- states with visible refinement and if so, ensure that at least one of
27033 -- its constituents appears as a Proof_In item in Refined_Global.
27034 -- This routine may remove elements from In_Constits, In_Out_Constits,
27035 -- Out_Constits and Proof_In_Constits.
27037 procedure Check_Refined_Global_List
27038 (List : Node_Id;
27039 Global_Mode : Name_Id := Name_Input);
27040 -- Verify the legality of a single global list declaration. Global_Mode
27041 -- denotes the current mode in effect.
27043 procedure Collect_Global_Items
27044 (List : Node_Id;
27045 Mode : Name_Id := Name_Input);
27046 -- Gather all Input, In_Out, Output and Proof_In items from node List
27047 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
27048 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
27049 -- and Has_Proof_In_State are set when there is at least one abstract
27050 -- state with full or partial visible refinement available in the
27051 -- corresponding mode. Flag Has_Null_State is set when at least state
27052 -- has a null refinement. Mode denotes the current global mode in
27053 -- effect.
27055 function Present_Then_Remove
27056 (List : Elist_Id;
27057 Item : Entity_Id) return Boolean;
27058 -- Search List for a particular entity Item. If Item has been found,
27059 -- remove it from List. This routine is used to strip lists In_Constits,
27060 -- In_Out_Constits and Out_Constits of valid constituents.
27062 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id);
27063 -- Same as function Present_Then_Remove, but do not report the presence
27064 -- of Item in List.
27066 procedure Report_Extra_Constituents;
27067 -- Emit an error for each constituent found in lists In_Constits,
27068 -- In_Out_Constits and Out_Constits.
27070 procedure Report_Missing_Items;
27071 -- Emit an error for each global item not repeated found in list
27072 -- Repeat_Items.
27074 -------------------------
27075 -- Check_In_Out_States --
27076 -------------------------
27078 procedure Check_In_Out_States is
27079 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27080 -- Determine whether one of the following coverage scenarios is in
27081 -- effect:
27082 -- 1) there is at least one constituent of mode In_Out or Output
27083 -- 2) there is at least one pair of constituents with modes Input
27084 -- and Output, or Proof_In and Output.
27085 -- 3) there is at least one constituent of mode Output and not all
27086 -- constituents are present.
27087 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
27089 -----------------------------
27090 -- Check_Constituent_Usage --
27091 -----------------------------
27093 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27094 Constits : constant Elist_Id :=
27095 Partial_Refinement_Constituents (State_Id);
27096 Constit_Elmt : Elmt_Id;
27097 Constit_Id : Entity_Id;
27098 Has_Missing : Boolean := False;
27099 In_Out_Seen : Boolean := False;
27100 Input_Seen : Boolean := False;
27101 Output_Seen : Boolean := False;
27102 Proof_In_Seen : Boolean := False;
27104 begin
27105 -- Process all the constituents of the state and note their modes
27106 -- within the global refinement.
27108 if Present (Constits) then
27109 Constit_Elmt := First_Elmt (Constits);
27110 while Present (Constit_Elmt) loop
27111 Constit_Id := Node (Constit_Elmt);
27113 if Present_Then_Remove (In_Constits, Constit_Id) then
27114 Input_Seen := True;
27116 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
27117 In_Out_Seen := True;
27119 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
27120 Output_Seen := True;
27122 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
27123 then
27124 Proof_In_Seen := True;
27126 else
27127 Has_Missing := True;
27128 end if;
27130 Next_Elmt (Constit_Elmt);
27131 end loop;
27132 end if;
27134 -- An In_Out constituent is a valid completion
27136 if In_Out_Seen then
27137 null;
27139 -- A pair of one Input/Proof_In and one Output constituent is a
27140 -- valid completion.
27142 elsif (Input_Seen or Proof_In_Seen) and Output_Seen then
27143 null;
27145 elsif Output_Seen then
27147 -- A single Output constituent is a valid completion only when
27148 -- some of the other constituents are missing.
27150 if Has_Missing then
27151 null;
27153 -- Otherwise all constituents are of mode Output
27155 else
27156 SPARK_Msg_NE
27157 ("global refinement of state & must include at least one "
27158 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
27159 N, State_Id);
27160 end if;
27162 -- The state lacks a completion. When full refinement is visible,
27163 -- always emit an error (SPARK RM 7.2.4(3a)). When only partial
27164 -- refinement is visible, emit an error if the abstract state
27165 -- itself is not utilized (SPARK RM 7.2.4(3d)). In the case where
27166 -- both are utilized, Check_State_And_Constituent_Use. will issue
27167 -- the error.
27169 elsif not Input_Seen
27170 and then not In_Out_Seen
27171 and then not Output_Seen
27172 and then not Proof_In_Seen
27173 then
27174 if Has_Visible_Refinement (State_Id)
27175 or else Contains (Repeat_Items, State_Id)
27176 then
27177 SPARK_Msg_NE
27178 ("missing global refinement of state &", N, State_Id);
27179 end if;
27181 -- Otherwise the state has a malformed completion where at least
27182 -- one of the constituents has a different mode.
27184 else
27185 SPARK_Msg_NE
27186 ("global refinement of state & redefines the mode of its "
27187 & "constituents", N, State_Id);
27188 end if;
27189 end Check_Constituent_Usage;
27191 -- Local variables
27193 Item_Elmt : Elmt_Id;
27194 Item_Id : Entity_Id;
27196 -- Start of processing for Check_In_Out_States
27198 begin
27199 -- Do not perform this check in an instance because it was already
27200 -- performed successfully in the generic template.
27202 if In_Instance then
27203 null;
27205 -- Inspect the In_Out items of the corresponding Global pragma
27206 -- looking for a state with a visible refinement.
27208 elsif Has_In_Out_State and then Present (In_Out_Items) then
27209 Item_Elmt := First_Elmt (In_Out_Items);
27210 while Present (Item_Elmt) loop
27211 Item_Id := Node (Item_Elmt);
27213 -- Ensure that one of the three coverage variants is satisfied
27215 if Ekind (Item_Id) = E_Abstract_State
27216 and then Has_Non_Null_Visible_Refinement (Item_Id)
27217 then
27218 Check_Constituent_Usage (Item_Id);
27219 end if;
27221 Next_Elmt (Item_Elmt);
27222 end loop;
27223 end if;
27224 end Check_In_Out_States;
27226 ------------------------
27227 -- Check_Input_States --
27228 ------------------------
27230 procedure Check_Input_States is
27231 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27232 -- Determine whether at least one constituent of state State_Id with
27233 -- full or partial visible refinement is used and has mode Input.
27234 -- Ensure that the remaining constituents do not have In_Out or
27235 -- Output modes. Emit an error if this is not the case
27236 -- (SPARK RM 7.2.4(5)).
27238 -----------------------------
27239 -- Check_Constituent_Usage --
27240 -----------------------------
27242 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27243 Constits : constant Elist_Id :=
27244 Partial_Refinement_Constituents (State_Id);
27245 Constit_Elmt : Elmt_Id;
27246 Constit_Id : Entity_Id;
27247 In_Seen : Boolean := False;
27249 begin
27250 if Present (Constits) then
27251 Constit_Elmt := First_Elmt (Constits);
27252 while Present (Constit_Elmt) loop
27253 Constit_Id := Node (Constit_Elmt);
27255 -- At least one of the constituents appears as an Input
27257 if Present_Then_Remove (In_Constits, Constit_Id) then
27258 In_Seen := True;
27260 -- A Proof_In constituent can refine an Input state as long
27261 -- as there is at least one Input constituent present.
27263 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
27264 then
27265 null;
27267 -- The constituent appears in the global refinement, but has
27268 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
27270 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
27271 or else Present_Then_Remove (Out_Constits, Constit_Id)
27272 then
27273 Error_Msg_Name_1 := Chars (State_Id);
27274 SPARK_Msg_NE
27275 ("constituent & of state % must have mode `Input` in "
27276 & "global refinement", N, Constit_Id);
27277 end if;
27279 Next_Elmt (Constit_Elmt);
27280 end loop;
27281 end if;
27283 -- Not one of the constituents appeared as Input. Always emit an
27284 -- error when the full refinement is visible (SPARK RM 7.2.4(3a)).
27285 -- When only partial refinement is visible, emit an error if the
27286 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
27287 -- the case where both are utilized, an error will be issued in
27288 -- Check_State_And_Constituent_Use.
27290 if not In_Seen
27291 and then (Has_Visible_Refinement (State_Id)
27292 or else Contains (Repeat_Items, State_Id))
27293 then
27294 SPARK_Msg_NE
27295 ("global refinement of state & must include at least one "
27296 & "constituent of mode `Input`", N, State_Id);
27297 end if;
27298 end Check_Constituent_Usage;
27300 -- Local variables
27302 Item_Elmt : Elmt_Id;
27303 Item_Id : Entity_Id;
27305 -- Start of processing for Check_Input_States
27307 begin
27308 -- Do not perform this check in an instance because it was already
27309 -- performed successfully in the generic template.
27311 if In_Instance then
27312 null;
27314 -- Inspect the Input items of the corresponding Global pragma looking
27315 -- for a state with a visible refinement.
27317 elsif Has_In_State and then Present (In_Items) then
27318 Item_Elmt := First_Elmt (In_Items);
27319 while Present (Item_Elmt) loop
27320 Item_Id := Node (Item_Elmt);
27322 -- When full refinement is visible, ensure that at least one of
27323 -- the constituents is utilized and is of mode Input. When only
27324 -- partial refinement is visible, ensure that either one of
27325 -- the constituents is utilized and is of mode Input, or the
27326 -- abstract state is repeated and no constituent is utilized.
27328 if Ekind (Item_Id) = E_Abstract_State
27329 and then Has_Non_Null_Visible_Refinement (Item_Id)
27330 then
27331 Check_Constituent_Usage (Item_Id);
27332 end if;
27334 Next_Elmt (Item_Elmt);
27335 end loop;
27336 end if;
27337 end Check_Input_States;
27339 -------------------------
27340 -- Check_Output_States --
27341 -------------------------
27343 procedure Check_Output_States is
27344 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27345 -- Determine whether all constituents of state State_Id with full
27346 -- visible refinement are used and have mode Output. Emit an error
27347 -- if this is not the case (SPARK RM 7.2.4(5)).
27349 -----------------------------
27350 -- Check_Constituent_Usage --
27351 -----------------------------
27353 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27354 Constits : constant Elist_Id :=
27355 Partial_Refinement_Constituents (State_Id);
27356 Only_Partial : constant Boolean :=
27357 not Has_Visible_Refinement (State_Id);
27358 Constit_Elmt : Elmt_Id;
27359 Constit_Id : Entity_Id;
27360 Posted : Boolean := False;
27362 begin
27363 if Present (Constits) then
27364 Constit_Elmt := First_Elmt (Constits);
27365 while Present (Constit_Elmt) loop
27366 Constit_Id := Node (Constit_Elmt);
27368 -- Issue an error when a constituent of State_Id is utilized
27369 -- and State_Id has only partial visible refinement
27370 -- (SPARK RM 7.2.4(3d)).
27372 if Only_Partial then
27373 if Present_Then_Remove (Out_Constits, Constit_Id)
27374 or else Present_Then_Remove (In_Constits, Constit_Id)
27375 or else
27376 Present_Then_Remove (In_Out_Constits, Constit_Id)
27377 or else
27378 Present_Then_Remove (Proof_In_Constits, Constit_Id)
27379 then
27380 Error_Msg_Name_1 := Chars (State_Id);
27381 SPARK_Msg_NE
27382 ("constituent & of state % cannot be used in global "
27383 & "refinement", N, Constit_Id);
27384 Error_Msg_Name_1 := Chars (State_Id);
27385 SPARK_Msg_N ("\use state % instead", N);
27386 end if;
27388 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
27389 null;
27391 -- The constituent appears in the global refinement, but has
27392 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
27394 elsif Present_Then_Remove (In_Constits, Constit_Id)
27395 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
27396 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
27397 then
27398 Error_Msg_Name_1 := Chars (State_Id);
27399 SPARK_Msg_NE
27400 ("constituent & of state % must have mode `Output` in "
27401 & "global refinement", N, Constit_Id);
27403 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
27405 else
27406 if not Posted then
27407 Posted := True;
27408 SPARK_Msg_NE
27409 ("`Output` state & must be replaced by all its "
27410 & "constituents in global refinement", N, State_Id);
27411 end if;
27413 SPARK_Msg_NE
27414 ("\constituent & is missing in output list",
27415 N, Constit_Id);
27416 end if;
27418 Next_Elmt (Constit_Elmt);
27419 end loop;
27420 end if;
27421 end Check_Constituent_Usage;
27423 -- Local variables
27425 Item_Elmt : Elmt_Id;
27426 Item_Id : Entity_Id;
27428 -- Start of processing for Check_Output_States
27430 begin
27431 -- Do not perform this check in an instance because it was already
27432 -- performed successfully in the generic template.
27434 if In_Instance then
27435 null;
27437 -- Inspect the Output items of the corresponding Global pragma
27438 -- looking for a state with a visible refinement.
27440 elsif Has_Out_State and then Present (Out_Items) then
27441 Item_Elmt := First_Elmt (Out_Items);
27442 while Present (Item_Elmt) loop
27443 Item_Id := Node (Item_Elmt);
27445 -- When full refinement is visible, ensure that all of the
27446 -- constituents are utilized and they have mode Output. When
27447 -- only partial refinement is visible, ensure that no
27448 -- constituent is utilized.
27450 if Ekind (Item_Id) = E_Abstract_State
27451 and then Has_Non_Null_Visible_Refinement (Item_Id)
27452 then
27453 Check_Constituent_Usage (Item_Id);
27454 end if;
27456 Next_Elmt (Item_Elmt);
27457 end loop;
27458 end if;
27459 end Check_Output_States;
27461 ---------------------------
27462 -- Check_Proof_In_States --
27463 ---------------------------
27465 procedure Check_Proof_In_States is
27466 procedure Check_Constituent_Usage (State_Id : Entity_Id);
27467 -- Determine whether at least one constituent of state State_Id with
27468 -- full or partial visible refinement is used and has mode Proof_In.
27469 -- Ensure that the remaining constituents do not have Input, In_Out,
27470 -- or Output modes. Emit an error if this is not the case
27471 -- (SPARK RM 7.2.4(5)).
27473 -----------------------------
27474 -- Check_Constituent_Usage --
27475 -----------------------------
27477 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
27478 Constits : constant Elist_Id :=
27479 Partial_Refinement_Constituents (State_Id);
27480 Constit_Elmt : Elmt_Id;
27481 Constit_Id : Entity_Id;
27482 Proof_In_Seen : Boolean := False;
27484 begin
27485 if Present (Constits) then
27486 Constit_Elmt := First_Elmt (Constits);
27487 while Present (Constit_Elmt) loop
27488 Constit_Id := Node (Constit_Elmt);
27490 -- At least one of the constituents appears as Proof_In
27492 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
27493 Proof_In_Seen := True;
27495 -- The constituent appears in the global refinement, but has
27496 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
27498 elsif Present_Then_Remove (In_Constits, Constit_Id)
27499 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
27500 or else Present_Then_Remove (Out_Constits, Constit_Id)
27501 then
27502 Error_Msg_Name_1 := Chars (State_Id);
27503 SPARK_Msg_NE
27504 ("constituent & of state % must have mode `Proof_In` "
27505 & "in global refinement", N, Constit_Id);
27506 end if;
27508 Next_Elmt (Constit_Elmt);
27509 end loop;
27510 end if;
27512 -- Not one of the constituents appeared as Proof_In. Always emit
27513 -- an error when full refinement is visible (SPARK RM 7.2.4(3a)).
27514 -- When only partial refinement is visible, emit an error if the
27515 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
27516 -- the case where both are utilized, an error will be issued by
27517 -- Check_State_And_Constituent_Use.
27519 if not Proof_In_Seen
27520 and then (Has_Visible_Refinement (State_Id)
27521 or else Contains (Repeat_Items, State_Id))
27522 then
27523 SPARK_Msg_NE
27524 ("global refinement of state & must include at least one "
27525 & "constituent of mode `Proof_In`", N, State_Id);
27526 end if;
27527 end Check_Constituent_Usage;
27529 -- Local variables
27531 Item_Elmt : Elmt_Id;
27532 Item_Id : Entity_Id;
27534 -- Start of processing for Check_Proof_In_States
27536 begin
27537 -- Do not perform this check in an instance because it was already
27538 -- performed successfully in the generic template.
27540 if In_Instance then
27541 null;
27543 -- Inspect the Proof_In items of the corresponding Global pragma
27544 -- looking for a state with a visible refinement.
27546 elsif Has_Proof_In_State and then Present (Proof_In_Items) then
27547 Item_Elmt := First_Elmt (Proof_In_Items);
27548 while Present (Item_Elmt) loop
27549 Item_Id := Node (Item_Elmt);
27551 -- Ensure that at least one of the constituents is utilized
27552 -- and is of mode Proof_In. When only partial refinement is
27553 -- visible, ensure that either one of the constituents is
27554 -- utilized and is of mode Proof_In, or the abstract state
27555 -- is repeated and no constituent is utilized.
27557 if Ekind (Item_Id) = E_Abstract_State
27558 and then Has_Non_Null_Visible_Refinement (Item_Id)
27559 then
27560 Check_Constituent_Usage (Item_Id);
27561 end if;
27563 Next_Elmt (Item_Elmt);
27564 end loop;
27565 end if;
27566 end Check_Proof_In_States;
27568 -------------------------------
27569 -- Check_Refined_Global_List --
27570 -------------------------------
27572 procedure Check_Refined_Global_List
27573 (List : Node_Id;
27574 Global_Mode : Name_Id := Name_Input)
27576 procedure Check_Refined_Global_Item
27577 (Item : Node_Id;
27578 Global_Mode : Name_Id);
27579 -- Verify the legality of a single global item declaration. Parameter
27580 -- Global_Mode denotes the current mode in effect.
27582 -------------------------------
27583 -- Check_Refined_Global_Item --
27584 -------------------------------
27586 procedure Check_Refined_Global_Item
27587 (Item : Node_Id;
27588 Global_Mode : Name_Id)
27590 Item_Id : constant Entity_Id := Entity_Of (Item);
27592 procedure Inconsistent_Mode_Error (Expect : Name_Id);
27593 -- Issue a common error message for all mode mismatches. Expect
27594 -- denotes the expected mode.
27596 -----------------------------
27597 -- Inconsistent_Mode_Error --
27598 -----------------------------
27600 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
27601 begin
27602 SPARK_Msg_NE
27603 ("global item & has inconsistent modes", Item, Item_Id);
27605 Error_Msg_Name_1 := Global_Mode;
27606 Error_Msg_Name_2 := Expect;
27607 SPARK_Msg_N ("\expected mode %, found mode %", Item);
27608 end Inconsistent_Mode_Error;
27610 -- Local variables
27612 Enc_State : Entity_Id := Empty;
27613 -- Encapsulating state for constituent, Empty otherwise
27615 -- Start of processing for Check_Refined_Global_Item
27617 begin
27618 if Ekind (Item_Id) in E_Abstract_State | E_Constant | E_Variable
27619 then
27620 Enc_State := Find_Encapsulating_State (States, Item_Id);
27621 end if;
27623 -- When the state or object acts as a constituent of another
27624 -- state with a visible refinement, collect it for the state
27625 -- completeness checks performed later on. Note that the item
27626 -- acts as a constituent only when the encapsulating state is
27627 -- present in pragma Global.
27629 if Present (Enc_State)
27630 and then (Has_Visible_Refinement (Enc_State)
27631 or else Has_Partial_Visible_Refinement (Enc_State))
27632 and then Contains (States, Enc_State)
27633 then
27634 -- If the state has only partial visible refinement, remove it
27635 -- from the list of items that should be repeated from pragma
27636 -- Global.
27638 if not Has_Visible_Refinement (Enc_State) then
27639 Present_Then_Remove (Repeat_Items, Enc_State);
27640 end if;
27642 if Global_Mode = Name_Input then
27643 Append_New_Elmt (Item_Id, In_Constits);
27645 elsif Global_Mode = Name_In_Out then
27646 Append_New_Elmt (Item_Id, In_Out_Constits);
27648 elsif Global_Mode = Name_Output then
27649 Append_New_Elmt (Item_Id, Out_Constits);
27651 elsif Global_Mode = Name_Proof_In then
27652 Append_New_Elmt (Item_Id, Proof_In_Constits);
27653 end if;
27655 -- When not a constituent, ensure that both occurrences of the
27656 -- item in pragmas Global and Refined_Global match. Also remove
27657 -- it when present from the list of items that should be repeated
27658 -- from pragma Global.
27660 else
27661 Present_Then_Remove (Repeat_Items, Item_Id);
27663 if Contains (In_Items, Item_Id) then
27664 if Global_Mode /= Name_Input then
27665 Inconsistent_Mode_Error (Name_Input);
27666 end if;
27668 elsif Contains (In_Out_Items, Item_Id) then
27669 if Global_Mode /= Name_In_Out then
27670 Inconsistent_Mode_Error (Name_In_Out);
27671 end if;
27673 elsif Contains (Out_Items, Item_Id) then
27674 if Global_Mode /= Name_Output then
27675 Inconsistent_Mode_Error (Name_Output);
27676 end if;
27678 elsif Contains (Proof_In_Items, Item_Id) then
27679 null;
27681 -- The item does not appear in the corresponding Global pragma,
27682 -- it must be an extra (SPARK RM 7.2.4(3)).
27684 else
27685 pragma Assert (Present (Global));
27686 Error_Msg_Sloc := Sloc (Global);
27687 SPARK_Msg_NE
27688 ("extra global item & does not refine or repeat any "
27689 & "global item #", Item, Item_Id);
27690 end if;
27691 end if;
27692 end Check_Refined_Global_Item;
27694 -- Local variables
27696 Item : Node_Id;
27698 -- Start of processing for Check_Refined_Global_List
27700 begin
27701 -- Do not perform this check in an instance because it was already
27702 -- performed successfully in the generic template.
27704 if In_Instance then
27705 null;
27707 elsif Nkind (List) = N_Null then
27708 null;
27710 -- Single global item declaration
27712 elsif Nkind (List) in N_Expanded_Name
27713 | N_Identifier
27714 | N_Selected_Component
27715 then
27716 Check_Refined_Global_Item (List, Global_Mode);
27718 -- Simple global list or moded global list declaration
27720 elsif Nkind (List) = N_Aggregate then
27722 -- The declaration of a simple global list appear as a collection
27723 -- of expressions.
27725 if Present (Expressions (List)) then
27726 Item := First (Expressions (List));
27727 while Present (Item) loop
27728 Check_Refined_Global_Item (Item, Global_Mode);
27729 Next (Item);
27730 end loop;
27732 -- The declaration of a moded global list appears as a collection
27733 -- of component associations where individual choices denote
27734 -- modes.
27736 elsif Present (Component_Associations (List)) then
27737 Item := First (Component_Associations (List));
27738 while Present (Item) loop
27739 Check_Refined_Global_List
27740 (List => Expression (Item),
27741 Global_Mode => Chars (First (Choices (Item))));
27743 Next (Item);
27744 end loop;
27746 -- Invalid tree
27748 else
27749 raise Program_Error;
27750 end if;
27752 -- Invalid list
27754 else
27755 raise Program_Error;
27756 end if;
27757 end Check_Refined_Global_List;
27759 --------------------------
27760 -- Collect_Global_Items --
27761 --------------------------
27763 procedure Collect_Global_Items
27764 (List : Node_Id;
27765 Mode : Name_Id := Name_Input)
27767 procedure Collect_Global_Item
27768 (Item : Node_Id;
27769 Item_Mode : Name_Id);
27770 -- Add a single item to the appropriate list. Item_Mode denotes the
27771 -- current mode in effect.
27773 -------------------------
27774 -- Collect_Global_Item --
27775 -------------------------
27777 procedure Collect_Global_Item
27778 (Item : Node_Id;
27779 Item_Mode : Name_Id)
27781 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
27782 -- The above handles abstract views of variables and states built
27783 -- for limited with clauses.
27785 begin
27786 -- Signal that the global list contains at least one abstract
27787 -- state with a visible refinement. Note that the refinement may
27788 -- be null in which case there are no constituents.
27790 if Ekind (Item_Id) = E_Abstract_State then
27791 if Has_Null_Visible_Refinement (Item_Id) then
27792 Has_Null_State := True;
27794 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
27795 Append_New_Elmt (Item_Id, States);
27797 if Item_Mode = Name_Input then
27798 Has_In_State := True;
27799 elsif Item_Mode = Name_In_Out then
27800 Has_In_Out_State := True;
27801 elsif Item_Mode = Name_Output then
27802 Has_Out_State := True;
27803 elsif Item_Mode = Name_Proof_In then
27804 Has_Proof_In_State := True;
27805 end if;
27806 end if;
27807 end if;
27809 -- Record global items without full visible refinement found in
27810 -- pragma Global which should be repeated in the global refinement
27811 -- (SPARK RM 7.2.4(3c), SPARK RM 7.2.4(3d)).
27813 if Ekind (Item_Id) /= E_Abstract_State
27814 or else not Has_Visible_Refinement (Item_Id)
27815 then
27816 Append_New_Elmt (Item_Id, Repeat_Items);
27817 end if;
27819 -- Add the item to the proper list
27821 if Item_Mode = Name_Input then
27822 Append_New_Elmt (Item_Id, In_Items);
27823 elsif Item_Mode = Name_In_Out then
27824 Append_New_Elmt (Item_Id, In_Out_Items);
27825 elsif Item_Mode = Name_Output then
27826 Append_New_Elmt (Item_Id, Out_Items);
27827 elsif Item_Mode = Name_Proof_In then
27828 Append_New_Elmt (Item_Id, Proof_In_Items);
27829 end if;
27830 end Collect_Global_Item;
27832 -- Local variables
27834 Item : Node_Id;
27836 -- Start of processing for Collect_Global_Items
27838 begin
27839 if Nkind (List) = N_Null then
27840 null;
27842 -- Single global item declaration
27844 elsif Nkind (List) in N_Expanded_Name
27845 | N_Identifier
27846 | N_Selected_Component
27847 then
27848 Collect_Global_Item (List, Mode);
27850 -- Single global list or moded global list declaration
27852 elsif Nkind (List) = N_Aggregate then
27854 -- The declaration of a simple global list appear as a collection
27855 -- of expressions.
27857 if Present (Expressions (List)) then
27858 Item := First (Expressions (List));
27859 while Present (Item) loop
27860 Collect_Global_Item (Item, Mode);
27861 Next (Item);
27862 end loop;
27864 -- The declaration of a moded global list appears as a collection
27865 -- of component associations where individual choices denote mode.
27867 elsif Present (Component_Associations (List)) then
27868 Item := First (Component_Associations (List));
27869 while Present (Item) loop
27870 Collect_Global_Items
27871 (List => Expression (Item),
27872 Mode => Chars (First (Choices (Item))));
27874 Next (Item);
27875 end loop;
27877 -- Invalid tree
27879 else
27880 raise Program_Error;
27881 end if;
27883 -- To accommodate partial decoration of disabled SPARK features, this
27884 -- routine may be called with illegal input. If this is the case, do
27885 -- not raise Program_Error.
27887 else
27888 null;
27889 end if;
27890 end Collect_Global_Items;
27892 -------------------------
27893 -- Present_Then_Remove --
27894 -------------------------
27896 function Present_Then_Remove
27897 (List : Elist_Id;
27898 Item : Entity_Id) return Boolean
27900 Elmt : Elmt_Id;
27902 begin
27903 if Present (List) then
27904 Elmt := First_Elmt (List);
27905 while Present (Elmt) loop
27906 if Node (Elmt) = Item then
27907 Remove_Elmt (List, Elmt);
27908 return True;
27909 end if;
27911 Next_Elmt (Elmt);
27912 end loop;
27913 end if;
27915 return False;
27916 end Present_Then_Remove;
27918 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id) is
27919 Ignore : Boolean;
27920 begin
27921 Ignore := Present_Then_Remove (List, Item);
27922 end Present_Then_Remove;
27924 -------------------------------
27925 -- Report_Extra_Constituents --
27926 -------------------------------
27928 procedure Report_Extra_Constituents is
27929 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
27930 -- Emit an error for every element of List
27932 ---------------------------------------
27933 -- Report_Extra_Constituents_In_List --
27934 ---------------------------------------
27936 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
27937 Constit_Elmt : Elmt_Id;
27939 begin
27940 if Present (List) then
27941 Constit_Elmt := First_Elmt (List);
27942 while Present (Constit_Elmt) loop
27943 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
27944 Next_Elmt (Constit_Elmt);
27945 end loop;
27946 end if;
27947 end Report_Extra_Constituents_In_List;
27949 -- Start of processing for Report_Extra_Constituents
27951 begin
27952 -- Do not perform this check in an instance because it was already
27953 -- performed successfully in the generic template.
27955 if In_Instance then
27956 null;
27958 else
27959 Report_Extra_Constituents_In_List (In_Constits);
27960 Report_Extra_Constituents_In_List (In_Out_Constits);
27961 Report_Extra_Constituents_In_List (Out_Constits);
27962 Report_Extra_Constituents_In_List (Proof_In_Constits);
27963 end if;
27964 end Report_Extra_Constituents;
27966 --------------------------
27967 -- Report_Missing_Items --
27968 --------------------------
27970 procedure Report_Missing_Items is
27971 Item_Elmt : Elmt_Id;
27972 Item_Id : Entity_Id;
27974 begin
27975 -- Do not perform this check in an instance because it was already
27976 -- performed successfully in the generic template.
27978 if In_Instance then
27979 null;
27981 else
27982 if Present (Repeat_Items) then
27983 Item_Elmt := First_Elmt (Repeat_Items);
27984 while Present (Item_Elmt) loop
27985 Item_Id := Node (Item_Elmt);
27986 SPARK_Msg_NE ("missing global item &", N, Item_Id);
27987 Next_Elmt (Item_Elmt);
27988 end loop;
27989 end if;
27990 end if;
27991 end Report_Missing_Items;
27993 -- Local variables
27995 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
27996 Errors : constant Nat := Serious_Errors_Detected;
27997 Items : Node_Id;
27998 No_Constit : Boolean;
28000 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
28002 begin
28003 -- Do not analyze the pragma multiple times
28005 if Is_Analyzed_Pragma (N) then
28006 return;
28007 end if;
28009 Spec_Id := Unique_Defining_Entity (Body_Decl);
28011 -- Use the anonymous object as the proper spec when Refined_Global
28012 -- applies to the body of a single task type. The object carries the
28013 -- proper Chars as well as all non-refined versions of pragmas.
28015 if Is_Single_Concurrent_Type (Spec_Id) then
28016 Spec_Id := Anonymous_Object (Spec_Id);
28017 end if;
28019 Global := Get_Pragma (Spec_Id, Pragma_Global);
28020 Items := Expression (Get_Argument (N, Spec_Id));
28022 -- The subprogram declaration lacks pragma Global. This renders
28023 -- Refined_Global useless as there is nothing to refine.
28025 if No (Global) then
28026 SPARK_Msg_NE
28027 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
28028 & "& lacks aspect or pragma Global"), N, Spec_Id);
28029 goto Leave;
28030 end if;
28032 -- Extract all relevant items from the corresponding Global pragma
28034 Collect_Global_Items (Expression (Get_Argument (Global, Spec_Id)));
28036 -- Package and subprogram bodies are instantiated individually in
28037 -- a separate compiler pass. Due to this mode of instantiation, the
28038 -- refinement of a state may no longer be visible when a subprogram
28039 -- body contract is instantiated. Since the generic template is legal,
28040 -- do not perform this check in the instance to circumvent this oddity.
28042 if In_Instance then
28043 null;
28045 -- Non-instance case
28047 else
28048 -- The corresponding Global pragma must mention at least one
28049 -- state with a visible refinement at the point Refined_Global
28050 -- is processed. States with null refinements need Refined_Global
28051 -- pragma (SPARK RM 7.2.4(2)).
28053 if not Has_In_State
28054 and then not Has_In_Out_State
28055 and then not Has_Out_State
28056 and then not Has_Proof_In_State
28057 and then not Has_Null_State
28058 then
28059 SPARK_Msg_NE
28060 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
28061 & "depend on abstract state with visible refinement"),
28062 N, Spec_Id);
28063 goto Leave;
28065 -- The global refinement of inputs and outputs cannot be null when
28066 -- the corresponding Global pragma contains at least one item except
28067 -- in the case where we have states with null refinements.
28069 elsif Nkind (Items) = N_Null
28070 and then
28071 (Present (In_Items)
28072 or else Present (In_Out_Items)
28073 or else Present (Out_Items)
28074 or else Present (Proof_In_Items))
28075 and then not Has_Null_State
28076 then
28077 SPARK_Msg_NE
28078 (Fix_Msg (Spec_Id, "refinement cannot be null, subprogram & has "
28079 & "global items"), N, Spec_Id);
28080 goto Leave;
28081 end if;
28082 end if;
28084 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
28085 -- This ensures that the categorization of all refined global items is
28086 -- consistent with their role.
28088 Analyze_Global_In_Decl_Part (N);
28090 -- Perform all refinement checks with respect to completeness and mode
28091 -- matching.
28093 if Serious_Errors_Detected = Errors then
28094 Check_Refined_Global_List (Items);
28095 end if;
28097 -- Store the information that no constituent is used in the global
28098 -- refinement, prior to calling checking procedures which remove items
28099 -- from the list of constituents.
28101 No_Constit :=
28102 No (In_Constits)
28103 and then No (In_Out_Constits)
28104 and then No (Out_Constits)
28105 and then No (Proof_In_Constits);
28107 -- For Input states with visible refinement, at least one constituent
28108 -- must be used as an Input in the global refinement.
28110 if Serious_Errors_Detected = Errors then
28111 Check_Input_States;
28112 end if;
28114 -- Verify all possible completion variants for In_Out states with
28115 -- visible refinement.
28117 if Serious_Errors_Detected = Errors then
28118 Check_In_Out_States;
28119 end if;
28121 -- For Output states with visible refinement, all constituents must be
28122 -- used as Outputs in the global refinement.
28124 if Serious_Errors_Detected = Errors then
28125 Check_Output_States;
28126 end if;
28128 -- For Proof_In states with visible refinement, at least one constituent
28129 -- must be used as Proof_In in the global refinement.
28131 if Serious_Errors_Detected = Errors then
28132 Check_Proof_In_States;
28133 end if;
28135 -- Emit errors for all constituents that belong to other states with
28136 -- visible refinement that do not appear in Global.
28138 if Serious_Errors_Detected = Errors then
28139 Report_Extra_Constituents;
28140 end if;
28142 -- Emit errors for all items in Global that are not repeated in the
28143 -- global refinement and for which there is no full visible refinement
28144 -- and, in the case of states with partial visible refinement, no
28145 -- constituent is mentioned in the global refinement.
28147 if Serious_Errors_Detected = Errors then
28148 Report_Missing_Items;
28149 end if;
28151 -- Emit an error if no constituent is used in the global refinement
28152 -- (SPARK RM 7.2.4(3f)). Emit this error last, in case a more precise
28153 -- one may be issued by the checking procedures. Do not perform this
28154 -- check in an instance because it was already performed successfully
28155 -- in the generic template.
28157 if Serious_Errors_Detected = Errors
28158 and then not In_Instance
28159 and then not Has_Null_State
28160 and then No_Constit
28161 then
28162 SPARK_Msg_N ("missing refinement", N);
28163 end if;
28165 <<Leave>>
28166 Set_Is_Analyzed_Pragma (N);
28167 end Analyze_Refined_Global_In_Decl_Part;
28169 ----------------------------------------
28170 -- Analyze_Refined_State_In_Decl_Part --
28171 ----------------------------------------
28173 procedure Analyze_Refined_State_In_Decl_Part
28174 (N : Node_Id;
28175 Freeze_Id : Entity_Id := Empty)
28177 Body_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
28178 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
28179 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
28181 Available_States : Elist_Id := No_Elist;
28182 -- A list of all abstract states defined in the package declaration that
28183 -- are available for refinement. The list is used to report unrefined
28184 -- states.
28186 Body_States : Elist_Id := No_Elist;
28187 -- A list of all hidden states that appear in the body of the related
28188 -- package. The list is used to report unused hidden states.
28190 Constituents_Seen : Elist_Id := No_Elist;
28191 -- A list that contains all constituents processed so far. The list is
28192 -- used to detect multiple uses of the same constituent.
28194 Freeze_Posted : Boolean := False;
28195 -- A flag that controls the output of a freezing-related error (see use
28196 -- below).
28198 Refined_States_Seen : Elist_Id := No_Elist;
28199 -- A list that contains all refined states processed so far. The list is
28200 -- used to detect duplicate refinements.
28202 procedure Analyze_Refinement_Clause (Clause : Node_Id);
28203 -- Perform full analysis of a single refinement clause
28205 procedure Report_Unrefined_States (States : Elist_Id);
28206 -- Emit errors for all unrefined abstract states found in list States
28208 -------------------------------
28209 -- Analyze_Refinement_Clause --
28210 -------------------------------
28212 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
28213 AR_Constit : Entity_Id := Empty;
28214 AW_Constit : Entity_Id := Empty;
28215 ER_Constit : Entity_Id := Empty;
28216 EW_Constit : Entity_Id := Empty;
28217 -- The entities of external constituents that contain one of the
28218 -- following enabled properties: Async_Readers, Async_Writers,
28219 -- Effective_Reads and Effective_Writes.
28221 External_Constit_Seen : Boolean := False;
28222 -- Flag used to mark when at least one external constituent is part
28223 -- of the state refinement.
28225 Non_Null_Seen : Boolean := False;
28226 Null_Seen : Boolean := False;
28227 -- Flags used to detect multiple uses of null in a single clause or a
28228 -- mixture of null and non-null constituents.
28230 Part_Of_Constits : Elist_Id := No_Elist;
28231 -- A list of all candidate constituents subject to indicator Part_Of
28232 -- where the encapsulating state is the current state.
28234 State : Node_Id;
28235 State_Id : Entity_Id;
28236 -- The current state being refined
28238 procedure Analyze_Constituent (Constit : Node_Id);
28239 -- Perform full analysis of a single constituent
28241 procedure Check_External_Property
28242 (Prop_Nam : Name_Id;
28243 Enabled : Boolean;
28244 Constit : Entity_Id);
28245 -- Determine whether a property denoted by name Prop_Nam is present
28246 -- in the refined state. Emit an error if this is not the case. Flag
28247 -- Enabled should be set when the property applies to the refined
28248 -- state. Constit denotes the constituent (if any) which introduces
28249 -- the property in the refinement.
28251 procedure Match_State;
28252 -- Determine whether the state being refined appears in list
28253 -- Available_States. Emit an error when attempting to re-refine the
28254 -- state or when the state is not defined in the package declaration,
28255 -- otherwise remove the state from Available_States.
28257 procedure Report_Unused_Constituents (Constits : Elist_Id);
28258 -- Emit errors for all unused Part_Of constituents in list Constits
28260 -------------------------
28261 -- Analyze_Constituent --
28262 -------------------------
28264 procedure Analyze_Constituent (Constit : Node_Id) is
28265 procedure Match_Constituent (Constit_Id : Entity_Id);
28266 -- Determine whether constituent Constit denoted by its entity
28267 -- Constit_Id appears in Body_States. Emit an error when the
28268 -- constituent is not a valid hidden state of the related package
28269 -- or when it is used more than once. Otherwise remove the
28270 -- constituent from Body_States.
28272 -----------------------
28273 -- Match_Constituent --
28274 -----------------------
28276 procedure Match_Constituent (Constit_Id : Entity_Id) is
28277 procedure Collect_Constituent;
28278 -- Verify the legality of constituent Constit_Id and add it to
28279 -- the refinements of State_Id.
28281 -------------------------
28282 -- Collect_Constituent --
28283 -------------------------
28285 procedure Collect_Constituent is
28286 Constits : Elist_Id;
28288 begin
28289 -- The Ghost policy in effect at the point of abstract state
28290 -- declaration and constituent must match (SPARK RM 6.9(15))
28292 Check_Ghost_Refinement
28293 (State, State_Id, Constit, Constit_Id);
28295 -- A synchronized state must be refined by a synchronized
28296 -- object or another synchronized state (SPARK RM 9.6).
28298 if Is_Synchronized_State (State_Id)
28299 and then not Is_Synchronized_Object (Constit_Id)
28300 and then not Is_Synchronized_State (Constit_Id)
28301 then
28302 SPARK_Msg_NE
28303 ("constituent of synchronized state & must be "
28304 & "synchronized", Constit, State_Id);
28305 end if;
28307 -- Add the constituent to the list of processed items to aid
28308 -- with the detection of duplicates.
28310 Append_New_Elmt (Constit_Id, Constituents_Seen);
28312 -- Collect the constituent in the list of refinement items
28313 -- and establish a relation between the refined state and
28314 -- the item.
28316 Constits := Refinement_Constituents (State_Id);
28318 if No (Constits) then
28319 Constits := New_Elmt_List;
28320 Set_Refinement_Constituents (State_Id, Constits);
28321 end if;
28323 Append_Elmt (Constit_Id, Constits);
28324 Set_Encapsulating_State (Constit_Id, State_Id);
28326 -- The state has at least one legal constituent, mark the
28327 -- start of the refinement region. The region ends when the
28328 -- body declarations end (see routine Analyze_Declarations).
28330 Set_Has_Visible_Refinement (State_Id);
28332 -- When the constituent is external, save its relevant
28333 -- property for further checks.
28335 if Async_Readers_Enabled (Constit_Id) then
28336 AR_Constit := Constit_Id;
28337 External_Constit_Seen := True;
28338 end if;
28340 if Async_Writers_Enabled (Constit_Id) then
28341 AW_Constit := Constit_Id;
28342 External_Constit_Seen := True;
28343 end if;
28345 if Effective_Reads_Enabled (Constit_Id) then
28346 ER_Constit := Constit_Id;
28347 External_Constit_Seen := True;
28348 end if;
28350 if Effective_Writes_Enabled (Constit_Id) then
28351 EW_Constit := Constit_Id;
28352 External_Constit_Seen := True;
28353 end if;
28354 end Collect_Constituent;
28356 -- Local variables
28358 State_Elmt : Elmt_Id;
28360 -- Start of processing for Match_Constituent
28362 begin
28363 -- Detect a duplicate use of a constituent
28365 if Contains (Constituents_Seen, Constit_Id) then
28366 SPARK_Msg_NE
28367 ("duplicate use of constituent &", Constit, Constit_Id);
28368 return;
28369 end if;
28371 -- The constituent is subject to a Part_Of indicator
28373 if Present (Encapsulating_State (Constit_Id)) then
28374 if Encapsulating_State (Constit_Id) = State_Id then
28375 Remove (Part_Of_Constits, Constit_Id);
28376 Collect_Constituent;
28378 -- The constituent is part of another state and is used
28379 -- incorrectly in the refinement of the current state.
28381 else
28382 Error_Msg_Name_1 := Chars (State_Id);
28383 SPARK_Msg_NE
28384 ("& cannot act as constituent of state %",
28385 Constit, Constit_Id);
28386 SPARK_Msg_NE
28387 ("\Part_Of indicator specifies encapsulator &",
28388 Constit, Encapsulating_State (Constit_Id));
28389 end if;
28391 -- The only other source of legal constituents is the body
28392 -- state space of the related package.
28394 else
28395 if Present (Body_States) then
28396 State_Elmt := First_Elmt (Body_States);
28397 while Present (State_Elmt) loop
28399 -- Consume a valid constituent to signal that it has
28400 -- been encountered.
28402 if Node (State_Elmt) = Constit_Id then
28403 Remove_Elmt (Body_States, State_Elmt);
28404 Collect_Constituent;
28405 return;
28406 end if;
28408 Next_Elmt (State_Elmt);
28409 end loop;
28410 end if;
28412 -- At this point it is known that the constituent is not
28413 -- part of the package hidden state and cannot be used in
28414 -- a refinement (SPARK RM 7.2.2(9)).
28416 Error_Msg_Name_1 := Chars (Spec_Id);
28417 SPARK_Msg_NE
28418 ("cannot use & in refinement, constituent is not a hidden "
28419 & "state of package %", Constit, Constit_Id);
28420 end if;
28421 end Match_Constituent;
28423 -- Local variables
28425 Constit_Id : Entity_Id;
28426 Constits : Elist_Id;
28428 -- Start of processing for Analyze_Constituent
28430 begin
28431 -- Detect multiple uses of null in a single refinement clause or a
28432 -- mixture of null and non-null constituents.
28434 if Nkind (Constit) = N_Null then
28435 if Null_Seen then
28436 SPARK_Msg_N
28437 ("multiple null constituents not allowed", Constit);
28439 elsif Non_Null_Seen then
28440 SPARK_Msg_N
28441 ("cannot mix null and non-null constituents", Constit);
28443 else
28444 Null_Seen := True;
28446 -- Collect the constituent in the list of refinement items
28448 Constits := Refinement_Constituents (State_Id);
28450 if No (Constits) then
28451 Constits := New_Elmt_List;
28452 Set_Refinement_Constituents (State_Id, Constits);
28453 end if;
28455 Append_Elmt (Constit, Constits);
28457 -- The state has at least one legal constituent, mark the
28458 -- start of the refinement region. The region ends when the
28459 -- body declarations end (see Analyze_Declarations).
28461 Set_Has_Visible_Refinement (State_Id);
28462 end if;
28464 -- Non-null constituents
28466 else
28467 Non_Null_Seen := True;
28469 if Null_Seen then
28470 SPARK_Msg_N
28471 ("cannot mix null and non-null constituents", Constit);
28472 end if;
28474 Analyze (Constit);
28475 Resolve_State (Constit);
28477 -- Ensure that the constituent denotes a valid state or a
28478 -- whole object (SPARK RM 7.2.2(5)).
28480 if Is_Entity_Name (Constit) then
28481 Constit_Id := Entity_Of (Constit);
28483 -- When a constituent is declared after a subprogram body
28484 -- that caused freezing of the related contract where
28485 -- pragma Refined_State resides, the constituent appears
28486 -- undefined and carries Any_Id as its entity.
28488 -- package body Pack
28489 -- with Refined_State => (State => Constit)
28490 -- is
28491 -- procedure Proc
28492 -- with Refined_Global => (Input => Constit)
28493 -- is
28494 -- ...
28495 -- end Proc;
28497 -- Constit : ...;
28498 -- end Pack;
28500 if Constit_Id = Any_Id then
28501 SPARK_Msg_NE ("& is undefined", Constit, Constit_Id);
28503 -- Emit a specialized info message when the contract of
28504 -- the related package body was "frozen" by another body.
28505 -- Note that it is not possible to precisely identify why
28506 -- the constituent is undefined because it is not visible
28507 -- when pragma Refined_State is analyzed. This message is
28508 -- a reasonable approximation.
28510 if Present (Freeze_Id) and then not Freeze_Posted then
28511 Freeze_Posted := True;
28513 Error_Msg_Name_1 := Chars (Body_Id);
28514 Error_Msg_Sloc := Sloc (Freeze_Id);
28515 SPARK_Msg_NE
28516 ("body & declared # freezes the contract of %",
28517 N, Freeze_Id);
28518 SPARK_Msg_N
28519 ("\all constituents must be declared before body #",
28522 -- A misplaced constituent is a critical error because
28523 -- pragma Refined_Depends or Refined_Global depends on
28524 -- the proper link between a state and a constituent.
28525 -- Stop the compilation, as this leads to a multitude
28526 -- of misleading cascaded errors.
28528 raise Unrecoverable_Error;
28529 end if;
28531 -- The constituent is a valid state or object
28533 elsif Ekind (Constit_Id) in
28534 E_Abstract_State | E_Constant | E_Variable
28535 then
28536 Match_Constituent (Constit_Id);
28538 -- The variable may eventually become a constituent of a
28539 -- single protected/task type. Record the reference now
28540 -- and verify its legality when analyzing the contract of
28541 -- the variable (SPARK RM 9.3).
28543 if Ekind (Constit_Id) = E_Variable then
28544 Record_Possible_Part_Of_Reference
28545 (Var_Id => Constit_Id,
28546 Ref => Constit);
28547 end if;
28549 -- Otherwise the constituent is illegal
28551 else
28552 SPARK_Msg_NE
28553 ("constituent & must denote object or state",
28554 Constit, Constit_Id);
28555 end if;
28557 -- The constituent is illegal
28559 else
28560 SPARK_Msg_N ("malformed constituent", Constit);
28561 end if;
28562 end if;
28563 end Analyze_Constituent;
28565 -----------------------------
28566 -- Check_External_Property --
28567 -----------------------------
28569 procedure Check_External_Property
28570 (Prop_Nam : Name_Id;
28571 Enabled : Boolean;
28572 Constit : Entity_Id)
28574 begin
28575 -- The property is missing in the declaration of the state, but
28576 -- a constituent is introducing it in the state refinement
28577 -- (SPARK RM 7.2.8(2)).
28579 if not Enabled and then Present (Constit) then
28580 Error_Msg_Name_1 := Prop_Nam;
28581 Error_Msg_Name_2 := Chars (State_Id);
28582 SPARK_Msg_NE
28583 ("constituent & introduces external property % in refinement "
28584 & "of state %", State, Constit);
28586 Error_Msg_Sloc := Sloc (State_Id);
28587 SPARK_Msg_N
28588 ("\property is missing in abstract state declaration #",
28589 State);
28590 end if;
28591 end Check_External_Property;
28593 -----------------
28594 -- Match_State --
28595 -----------------
28597 procedure Match_State is
28598 State_Elmt : Elmt_Id;
28600 begin
28601 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
28603 if Contains (Refined_States_Seen, State_Id) then
28604 SPARK_Msg_NE
28605 ("duplicate refinement of state &", State, State_Id);
28606 return;
28607 end if;
28609 -- Inspect the abstract states defined in the package declaration
28610 -- looking for a match.
28612 State_Elmt := First_Elmt (Available_States);
28613 while Present (State_Elmt) loop
28615 -- A valid abstract state is being refined in the body. Add
28616 -- the state to the list of processed refined states to aid
28617 -- with the detection of duplicate refinements. Remove the
28618 -- state from Available_States to signal that it has already
28619 -- been refined.
28621 if Node (State_Elmt) = State_Id then
28622 Append_New_Elmt (State_Id, Refined_States_Seen);
28623 Remove_Elmt (Available_States, State_Elmt);
28624 return;
28625 end if;
28627 Next_Elmt (State_Elmt);
28628 end loop;
28630 -- If we get here, we are refining a state that is not defined in
28631 -- the package declaration.
28633 Error_Msg_Name_1 := Chars (Spec_Id);
28634 SPARK_Msg_NE
28635 ("cannot refine state, & is not defined in package %",
28636 State, State_Id);
28637 end Match_State;
28639 --------------------------------
28640 -- Report_Unused_Constituents --
28641 --------------------------------
28643 procedure Report_Unused_Constituents (Constits : Elist_Id) is
28644 Constit_Elmt : Elmt_Id;
28645 Constit_Id : Entity_Id;
28646 Posted : Boolean := False;
28648 begin
28649 if Present (Constits) then
28650 Constit_Elmt := First_Elmt (Constits);
28651 while Present (Constit_Elmt) loop
28652 Constit_Id := Node (Constit_Elmt);
28654 -- Generate an error message of the form:
28656 -- state ... has unused Part_Of constituents
28657 -- abstract state ... defined at ...
28658 -- constant ... defined at ...
28659 -- variable ... defined at ...
28661 if not Posted then
28662 Posted := True;
28663 SPARK_Msg_NE
28664 ("state & has unused Part_Of constituents",
28665 State, State_Id);
28666 end if;
28668 Error_Msg_Sloc := Sloc (Constit_Id);
28670 if Ekind (Constit_Id) = E_Abstract_State then
28671 SPARK_Msg_NE
28672 ("\abstract state & defined #", State, Constit_Id);
28674 elsif Ekind (Constit_Id) = E_Constant then
28675 SPARK_Msg_NE
28676 ("\constant & defined #", State, Constit_Id);
28678 else
28679 pragma Assert (Ekind (Constit_Id) = E_Variable);
28680 SPARK_Msg_NE ("\variable & defined #", State, Constit_Id);
28681 end if;
28683 Next_Elmt (Constit_Elmt);
28684 end loop;
28685 end if;
28686 end Report_Unused_Constituents;
28688 -- Local declarations
28690 Body_Ref : Node_Id;
28691 Body_Ref_Elmt : Elmt_Id;
28692 Constit : Node_Id;
28693 Extra_State : Node_Id;
28695 -- Start of processing for Analyze_Refinement_Clause
28697 begin
28698 -- A refinement clause appears as a component association where the
28699 -- sole choice is the state and the expressions are the constituents.
28700 -- This is a syntax error, always report.
28702 if Nkind (Clause) /= N_Component_Association then
28703 Error_Msg_N ("malformed state refinement clause", Clause);
28704 return;
28705 end if;
28707 -- Analyze the state name of a refinement clause
28709 State := First (Choices (Clause));
28711 Analyze (State);
28712 Resolve_State (State);
28714 -- Ensure that the state name denotes a valid abstract state that is
28715 -- defined in the spec of the related package.
28717 if Is_Entity_Name (State) then
28718 State_Id := Entity_Of (State);
28720 -- When the abstract state is undefined, it appears as Any_Id. Do
28721 -- not continue with the analysis of the clause.
28723 if State_Id = Any_Id then
28724 return;
28726 -- Catch any attempts to re-refine a state or refine a state that
28727 -- is not defined in the package declaration.
28729 elsif Ekind (State_Id) = E_Abstract_State then
28730 Match_State;
28732 else
28733 SPARK_Msg_NE ("& must denote abstract state", State, State_Id);
28734 return;
28735 end if;
28737 -- References to a state with visible refinement are illegal.
28738 -- When nested packages are involved, detecting such references is
28739 -- tricky because pragma Refined_State is analyzed later than the
28740 -- offending pragma Depends or Global. References that occur in
28741 -- such nested context are stored in a list. Emit errors for all
28742 -- references found in Body_References (SPARK RM 6.1.4(8)).
28744 if Present (Body_References (State_Id)) then
28745 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
28746 while Present (Body_Ref_Elmt) loop
28747 Body_Ref := Node (Body_Ref_Elmt);
28749 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
28750 Error_Msg_Sloc := Sloc (State);
28751 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
28753 Next_Elmt (Body_Ref_Elmt);
28754 end loop;
28755 end if;
28757 -- The state name is illegal. This is a syntax error, always report.
28759 else
28760 Error_Msg_N ("malformed state name in refinement clause", State);
28761 return;
28762 end if;
28764 -- A refinement clause may only refine one state at a time
28766 Extra_State := Next (State);
28768 if Present (Extra_State) then
28769 SPARK_Msg_N
28770 ("refinement clause cannot cover multiple states", Extra_State);
28771 end if;
28773 -- Replicate the Part_Of constituents of the refined state because
28774 -- the algorithm will consume items.
28776 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
28778 -- Analyze all constituents of the refinement. Multiple constituents
28779 -- appear as an aggregate.
28781 Constit := Expression (Clause);
28783 if Nkind (Constit) = N_Aggregate then
28784 if Present (Component_Associations (Constit)) then
28785 SPARK_Msg_N
28786 ("constituents of refinement clause must appear in "
28787 & "positional form", Constit);
28789 else pragma Assert (Present (Expressions (Constit)));
28790 Constit := First (Expressions (Constit));
28791 while Present (Constit) loop
28792 Analyze_Constituent (Constit);
28793 Next (Constit);
28794 end loop;
28795 end if;
28797 -- Various forms of a single constituent. Note that these may include
28798 -- malformed constituents.
28800 else
28801 Analyze_Constituent (Constit);
28802 end if;
28804 -- Verify that external constituents do not introduce new external
28805 -- property in the state refinement (SPARK RM 7.2.8(2)).
28807 if Is_External_State (State_Id) then
28808 Check_External_Property
28809 (Prop_Nam => Name_Async_Readers,
28810 Enabled => Async_Readers_Enabled (State_Id),
28811 Constit => AR_Constit);
28813 Check_External_Property
28814 (Prop_Nam => Name_Async_Writers,
28815 Enabled => Async_Writers_Enabled (State_Id),
28816 Constit => AW_Constit);
28818 Check_External_Property
28819 (Prop_Nam => Name_Effective_Reads,
28820 Enabled => Effective_Reads_Enabled (State_Id),
28821 Constit => ER_Constit);
28823 Check_External_Property
28824 (Prop_Nam => Name_Effective_Writes,
28825 Enabled => Effective_Writes_Enabled (State_Id),
28826 Constit => EW_Constit);
28828 -- When a refined state is not external, it should not have external
28829 -- constituents (SPARK RM 7.2.8(1)).
28831 elsif External_Constit_Seen then
28832 SPARK_Msg_NE
28833 ("non-external state & cannot contain external constituents in "
28834 & "refinement", State, State_Id);
28835 end if;
28837 -- Ensure that all Part_Of candidate constituents have been mentioned
28838 -- in the refinement clause.
28840 Report_Unused_Constituents (Part_Of_Constits);
28841 end Analyze_Refinement_Clause;
28843 -----------------------------
28844 -- Report_Unrefined_States --
28845 -----------------------------
28847 procedure Report_Unrefined_States (States : Elist_Id) is
28848 State_Elmt : Elmt_Id;
28850 begin
28851 if Present (States) then
28852 State_Elmt := First_Elmt (States);
28853 while Present (State_Elmt) loop
28854 SPARK_Msg_N
28855 ("abstract state & must be refined", Node (State_Elmt));
28857 Next_Elmt (State_Elmt);
28858 end loop;
28859 end if;
28860 end Report_Unrefined_States;
28862 -- Local declarations
28864 Clauses : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
28865 Clause : Node_Id;
28867 -- Start of processing for Analyze_Refined_State_In_Decl_Part
28869 begin
28870 -- Do not analyze the pragma multiple times
28872 if Is_Analyzed_Pragma (N) then
28873 return;
28874 end if;
28876 -- Save the scenario for examination by the ABE Processing phase
28878 Record_Elaboration_Scenario (N);
28880 -- Replicate the abstract states declared by the package because the
28881 -- matching algorithm will consume states.
28883 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
28885 -- Gather all abstract states and objects declared in the visible
28886 -- state space of the package body. These items must be utilized as
28887 -- constituents in a state refinement.
28889 Body_States := Collect_Body_States (Body_Id);
28891 -- Multiple non-null state refinements appear as an aggregate
28893 if Nkind (Clauses) = N_Aggregate then
28894 if Present (Expressions (Clauses)) then
28895 SPARK_Msg_N
28896 ("state refinements must appear as component associations",
28897 Clauses);
28899 else pragma Assert (Present (Component_Associations (Clauses)));
28900 Clause := First (Component_Associations (Clauses));
28901 while Present (Clause) loop
28902 Analyze_Refinement_Clause (Clause);
28903 Next (Clause);
28904 end loop;
28905 end if;
28907 -- Various forms of a single state refinement. Note that these may
28908 -- include malformed refinements.
28910 else
28911 Analyze_Refinement_Clause (Clauses);
28912 end if;
28914 -- List all abstract states that were left unrefined
28916 Report_Unrefined_States (Available_States);
28918 Set_Is_Analyzed_Pragma (N);
28919 end Analyze_Refined_State_In_Decl_Part;
28921 ------------------------------------
28922 -- Analyze_Test_Case_In_Decl_Part --
28923 ------------------------------------
28925 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is
28926 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
28927 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
28929 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id);
28930 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
28931 -- denoted by Arg_Nam.
28933 ------------------------------
28934 -- Preanalyze_Test_Case_Arg --
28935 ------------------------------
28937 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id) is
28938 Arg : Node_Id;
28940 begin
28941 -- Preanalyze the original aspect argument for a generic subprogram
28942 -- to properly capture global references.
28944 if Is_Generic_Subprogram (Spec_Id) then
28945 Arg :=
28946 Test_Case_Arg
28947 (Prag => N,
28948 Arg_Nam => Arg_Nam,
28949 From_Aspect => True);
28951 if Present (Arg) then
28952 Preanalyze_Assert_Expression
28953 (Expression (Arg), Standard_Boolean);
28954 end if;
28955 end if;
28957 Arg := Test_Case_Arg (N, Arg_Nam);
28959 if Present (Arg) then
28960 Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean);
28961 end if;
28962 end Preanalyze_Test_Case_Arg;
28964 -- Local variables
28966 Restore_Scope : Boolean := False;
28968 -- Start of processing for Analyze_Test_Case_In_Decl_Part
28970 begin
28971 -- Do not analyze the pragma multiple times
28973 if Is_Analyzed_Pragma (N) then
28974 return;
28975 end if;
28977 -- Ensure that the formal parameters are visible when analyzing all
28978 -- clauses. This falls out of the general rule of aspects pertaining
28979 -- to subprogram declarations.
28981 if not In_Open_Scopes (Spec_Id) then
28982 Restore_Scope := True;
28983 Push_Scope (Spec_Id);
28985 if Is_Generic_Subprogram (Spec_Id) then
28986 Install_Generic_Formals (Spec_Id);
28987 else
28988 Install_Formals (Spec_Id);
28989 end if;
28990 end if;
28992 Preanalyze_Test_Case_Arg (Name_Requires);
28993 Preanalyze_Test_Case_Arg (Name_Ensures);
28995 if Restore_Scope then
28996 End_Scope;
28997 end if;
28999 -- Currently it is not possible to inline pre/postconditions on a
29000 -- subprogram subject to pragma Inline_Always.
29002 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
29004 Set_Is_Analyzed_Pragma (N);
29005 end Analyze_Test_Case_In_Decl_Part;
29007 ----------------
29008 -- Appears_In --
29009 ----------------
29011 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
29012 Elmt : Elmt_Id;
29013 Id : Entity_Id;
29015 begin
29016 if Present (List) then
29017 Elmt := First_Elmt (List);
29018 while Present (Elmt) loop
29019 if Nkind (Node (Elmt)) = N_Defining_Identifier then
29020 Id := Node (Elmt);
29021 else
29022 Id := Entity_Of (Node (Elmt));
29023 end if;
29025 if Id = Item_Id then
29026 return True;
29027 end if;
29029 Next_Elmt (Elmt);
29030 end loop;
29031 end if;
29033 return False;
29034 end Appears_In;
29036 -----------------------------------
29037 -- Build_Pragma_Check_Equivalent --
29038 -----------------------------------
29040 function Build_Pragma_Check_Equivalent
29041 (Prag : Node_Id;
29042 Subp_Id : Entity_Id := Empty;
29043 Inher_Id : Entity_Id := Empty;
29044 Keep_Pragma_Id : Boolean := False) return Node_Id
29046 function Suppress_Reference (N : Node_Id) return Traverse_Result;
29047 -- Detect whether node N references a formal parameter subject to
29048 -- pragma Unreferenced. If this is the case, set Comes_From_Source
29049 -- to False to suppress the generation of a reference when analyzing
29050 -- N later on.
29052 ------------------------
29053 -- Suppress_Reference --
29054 ------------------------
29056 function Suppress_Reference (N : Node_Id) return Traverse_Result is
29057 Formal : Entity_Id;
29059 begin
29060 if Is_Entity_Name (N) and then Present (Entity (N)) then
29061 Formal := Entity (N);
29063 -- The formal parameter is subject to pragma Unreferenced. Prevent
29064 -- the generation of references by resetting the Comes_From_Source
29065 -- flag.
29067 if Is_Formal (Formal)
29068 and then Has_Pragma_Unreferenced (Formal)
29069 then
29070 Set_Comes_From_Source (N, False);
29071 end if;
29072 end if;
29074 return OK;
29075 end Suppress_Reference;
29077 procedure Suppress_References is
29078 new Traverse_Proc (Suppress_Reference);
29080 -- Local variables
29082 Loc : constant Source_Ptr := Sloc (Prag);
29083 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
29084 Check_Prag : Node_Id;
29085 Msg_Arg : Node_Id;
29086 Nam : Name_Id;
29088 Needs_Wrapper : Boolean;
29089 pragma Unreferenced (Needs_Wrapper);
29091 -- Start of processing for Build_Pragma_Check_Equivalent
29093 begin
29094 -- When the pre- or postcondition is inherited, map the formals of the
29095 -- inherited subprogram to those of the current subprogram. In addition,
29096 -- map primitive operations of the parent type into the corresponding
29097 -- primitive operations of the descendant.
29099 if Present (Inher_Id) then
29100 pragma Assert (Present (Subp_Id));
29102 Update_Primitives_Mapping (Inher_Id, Subp_Id);
29104 -- Use generic machinery to copy inherited pragma, as if it were an
29105 -- instantiation, resetting source locations appropriately, so that
29106 -- expressions inside the inherited pragma use chained locations.
29107 -- This is used in particular in GNATprove to locate precisely
29108 -- messages on a given inherited pragma.
29110 Set_Copied_Sloc_For_Inherited_Pragma
29111 (Unit_Declaration_Node (Subp_Id), Inher_Id);
29112 Check_Prag := New_Copy_Tree (Source => Prag);
29114 -- Build the inherited class-wide condition
29116 Build_Class_Wide_Expression
29117 (Prag => Check_Prag,
29118 Subp => Subp_Id,
29119 Par_Subp => Inher_Id,
29120 Adjust_Sloc => True,
29121 Needs_Wrapper => Needs_Wrapper);
29123 -- If not an inherited condition simply copy the original pragma
29125 else
29126 Check_Prag := New_Copy_Tree (Source => Prag);
29127 end if;
29129 -- Mark the pragma as being internally generated and reset the Analyzed
29130 -- flag.
29132 Set_Analyzed (Check_Prag, False);
29133 Set_Comes_From_Source (Check_Prag, False);
29135 -- The tree of the original pragma may contain references to the
29136 -- formal parameters of the related subprogram. At the same time
29137 -- the corresponding body may mark the formals as unreferenced:
29139 -- procedure Proc (Formal : ...)
29140 -- with Pre => Formal ...;
29142 -- procedure Proc (Formal : ...) is
29143 -- pragma Unreferenced (Formal);
29144 -- ...
29146 -- This creates problems because all pragma Check equivalents are
29147 -- analyzed at the end of the body declarations. Since all source
29148 -- references have already been accounted for, reset any references
29149 -- to such formals in the generated pragma Check equivalent.
29151 Suppress_References (Check_Prag);
29153 if Present (Corresponding_Aspect (Prag)) then
29154 Nam := Chars (Identifier (Corresponding_Aspect (Prag)));
29155 else
29156 Nam := Prag_Nam;
29157 end if;
29159 -- Unless Keep_Pragma_Id is True in order to keep the identifier of
29160 -- the copied pragma in the newly created pragma, convert the copy into
29161 -- pragma Check by correcting the name and adding a check_kind argument.
29163 if not Keep_Pragma_Id then
29164 Set_Class_Present (Check_Prag, False);
29166 Set_Pragma_Identifier
29167 (Check_Prag, Make_Identifier (Loc, Name_Check));
29169 Prepend_To (Pragma_Argument_Associations (Check_Prag),
29170 Make_Pragma_Argument_Association (Loc,
29171 Expression => Make_Identifier (Loc, Nam)));
29172 end if;
29174 -- Update the error message when the pragma is inherited
29176 if Present (Inher_Id) then
29177 Msg_Arg := Last (Pragma_Argument_Associations (Check_Prag));
29179 if Chars (Msg_Arg) = Name_Message then
29180 String_To_Name_Buffer (Strval (Expression (Msg_Arg)));
29182 -- Insert "inherited" to improve the error message
29184 if Name_Buffer (1 .. 8) = "failed p" then
29185 Insert_Str_In_Name_Buffer ("inherited ", 8);
29186 Set_Strval (Expression (Msg_Arg), String_From_Name_Buffer);
29187 end if;
29188 end if;
29189 end if;
29191 return Check_Prag;
29192 end Build_Pragma_Check_Equivalent;
29194 -----------------------------
29195 -- Check_Applicable_Policy --
29196 -----------------------------
29198 procedure Check_Applicable_Policy (N : Node_Id) is
29199 PP : Node_Id;
29200 Policy : Name_Id;
29202 Ename : constant Name_Id := Original_Aspect_Pragma_Name (N);
29204 begin
29205 -- No effect if not valid assertion kind name
29207 if not Is_Valid_Assertion_Kind (Ename) then
29208 return;
29209 end if;
29211 -- Loop through entries in check policy list
29213 PP := Opt.Check_Policy_List;
29214 while Present (PP) loop
29215 declare
29216 PPA : constant List_Id := Pragma_Argument_Associations (PP);
29217 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
29219 begin
29220 if Ename = Pnm
29221 or else Pnm = Name_Assertion
29222 or else (Pnm = Name_Statement_Assertions
29223 and then Ename in Name_Assert
29224 | Name_Assert_And_Cut
29225 | Name_Assume
29226 | Name_Loop_Invariant
29227 | Name_Loop_Variant)
29228 then
29229 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
29231 case Policy is
29232 when Name_Ignore
29233 | Name_Off
29235 -- In CodePeer mode and GNATprove mode, we need to
29236 -- consider all assertions, unless they are disabled.
29237 -- Force Is_Checked on ignored assertions, in particular
29238 -- because transformations of the AST may depend on
29239 -- assertions being checked (e.g. the translation of
29240 -- attribute 'Loop_Entry).
29242 if CodePeer_Mode or GNATprove_Mode then
29243 Set_Is_Checked (N, True);
29244 Set_Is_Ignored (N, False);
29245 else
29246 Set_Is_Checked (N, False);
29247 Set_Is_Ignored (N, True);
29248 end if;
29250 when Name_Check
29251 | Name_On
29253 Set_Is_Checked (N, True);
29254 Set_Is_Ignored (N, False);
29256 when Name_Disable =>
29257 Set_Is_Ignored (N, True);
29258 Set_Is_Checked (N, False);
29259 Set_Is_Disabled (N, True);
29261 -- That should be exhaustive, the null here is a defence
29262 -- against a malformed tree from previous errors.
29264 when others =>
29265 null;
29266 end case;
29268 return;
29269 end if;
29271 PP := Next_Pragma (PP);
29272 end;
29273 end loop;
29275 -- If there are no specific entries that matched, then we let the
29276 -- setting of assertions govern. Note that this provides the needed
29277 -- compatibility with the RM for the cases of assertion, invariant,
29278 -- precondition, predicate, and postcondition. Note also that
29279 -- Assertions_Enabled is forced in CodePeer mode and GNATprove mode.
29281 if Assertions_Enabled then
29282 Set_Is_Checked (N, True);
29283 Set_Is_Ignored (N, False);
29284 else
29285 Set_Is_Checked (N, False);
29286 Set_Is_Ignored (N, True);
29287 end if;
29288 end Check_Applicable_Policy;
29290 -------------------------------
29291 -- Check_External_Properties --
29292 -------------------------------
29294 procedure Check_External_Properties
29295 (Item : Node_Id;
29296 AR : Boolean;
29297 AW : Boolean;
29298 ER : Boolean;
29299 EW : Boolean)
29301 begin
29302 -- All properties enabled
29304 if AR and AW and ER and EW then
29305 null;
29307 -- Async_Readers + Effective_Writes
29308 -- Async_Readers + Async_Writers + Effective_Writes
29310 elsif AR and EW and not ER then
29311 null;
29313 -- Async_Writers + Effective_Reads
29314 -- Async_Readers + Async_Writers + Effective_Reads
29316 elsif AW and ER and not EW then
29317 null;
29319 -- Async_Readers + Async_Writers
29321 elsif AR and AW and not ER and not EW then
29322 null;
29324 -- Async_Readers
29326 elsif AR and not AW and not ER and not EW then
29327 null;
29329 -- Async_Writers
29331 elsif AW and not AR and not ER and not EW then
29332 null;
29334 else
29335 SPARK_Msg_N
29336 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
29337 Item);
29338 end if;
29339 end Check_External_Properties;
29341 ----------------
29342 -- Check_Kind --
29343 ----------------
29345 function Check_Kind (Nam : Name_Id) return Name_Id is
29346 PP : Node_Id;
29348 begin
29349 -- Loop through entries in check policy list
29351 PP := Opt.Check_Policy_List;
29352 while Present (PP) loop
29353 declare
29354 PPA : constant List_Id := Pragma_Argument_Associations (PP);
29355 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
29357 begin
29358 if Nam = Pnm
29359 or else (Pnm = Name_Assertion
29360 and then Is_Valid_Assertion_Kind (Nam))
29361 or else (Pnm = Name_Statement_Assertions
29362 and then Nam in Name_Assert
29363 | Name_Assert_And_Cut
29364 | Name_Assume
29365 | Name_Loop_Invariant
29366 | Name_Loop_Variant)
29367 then
29368 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
29369 when Name_Check
29370 | Name_On
29372 return Name_Check;
29374 when Name_Ignore
29375 | Name_Off
29377 return Name_Ignore;
29379 when Name_Disable =>
29380 return Name_Disable;
29382 when others =>
29383 raise Program_Error;
29384 end case;
29386 else
29387 PP := Next_Pragma (PP);
29388 end if;
29389 end;
29390 end loop;
29392 -- If there are no specific entries that matched, then we let the
29393 -- setting of assertions govern. Note that this provides the needed
29394 -- compatibility with the RM for the cases of assertion, invariant,
29395 -- precondition, predicate, and postcondition.
29397 if Assertions_Enabled then
29398 return Name_Check;
29399 else
29400 return Name_Ignore;
29401 end if;
29402 end Check_Kind;
29404 ---------------------------
29405 -- Check_Missing_Part_Of --
29406 ---------------------------
29408 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
29409 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
29410 -- Determine whether a package denoted by Pack_Id declares at least one
29411 -- visible state.
29413 -----------------------
29414 -- Has_Visible_State --
29415 -----------------------
29417 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
29418 Item_Id : Entity_Id;
29420 begin
29421 -- Traverse the entity chain of the package trying to find at least
29422 -- one visible abstract state, variable or a package [instantiation]
29423 -- that declares a visible state.
29425 Item_Id := First_Entity (Pack_Id);
29426 while Present (Item_Id)
29427 and then not In_Private_Part (Item_Id)
29428 loop
29429 -- Do not consider internally generated items
29431 if not Comes_From_Source (Item_Id) then
29432 null;
29434 -- Do not consider generic formals or their corresponding actuals
29435 -- because they are not part of a visible state. Note that both
29436 -- entities are marked as hidden.
29438 elsif Is_Hidden (Item_Id) then
29439 null;
29441 -- A visible state has been found. Note that constants are not
29442 -- considered here because it is not possible to determine whether
29443 -- they depend on variable input. This check is left to the SPARK
29444 -- prover.
29446 elsif Ekind (Item_Id) in E_Abstract_State | E_Variable then
29447 return True;
29449 -- Recursively peek into nested packages and instantiations
29451 elsif Ekind (Item_Id) = E_Package
29452 and then Has_Visible_State (Item_Id)
29453 then
29454 return True;
29455 end if;
29457 Next_Entity (Item_Id);
29458 end loop;
29460 return False;
29461 end Has_Visible_State;
29463 -- Local variables
29465 Pack_Id : Entity_Id;
29466 Placement : State_Space_Kind;
29468 -- Start of processing for Check_Missing_Part_Of
29470 begin
29471 -- Do not consider abstract states, variables or package instantiations
29472 -- coming from an instance as those always inherit the Part_Of indicator
29473 -- of the instance itself.
29475 if In_Instance then
29476 return;
29478 -- Do not consider internally generated entities as these can never
29479 -- have a Part_Of indicator.
29481 elsif not Comes_From_Source (Item_Id) then
29482 return;
29484 -- Perform these checks only when SPARK_Mode is enabled as they will
29485 -- interfere with standard Ada rules and produce false positives.
29487 elsif SPARK_Mode /= On then
29488 return;
29490 -- Do not consider constants, because the compiler cannot accurately
29491 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
29492 -- act as a hidden state of a package.
29494 elsif Ekind (Item_Id) = E_Constant then
29495 return;
29496 end if;
29498 -- Find where the abstract state, variable or package instantiation
29499 -- lives with respect to the state space.
29501 Find_Placement_In_State_Space
29502 (Item_Id => Item_Id,
29503 Placement => Placement,
29504 Pack_Id => Pack_Id);
29506 -- Items that appear in a non-package construct (subprogram, block, etc)
29507 -- do not require a Part_Of indicator because they can never act as a
29508 -- hidden state.
29510 if Placement = Not_In_Package then
29511 null;
29513 -- An item declared in the body state space of a package always act as a
29514 -- constituent and does not need explicit Part_Of indicator.
29516 elsif Placement = Body_State_Space then
29517 null;
29519 -- In general an item declared in the visible state space of a package
29520 -- does not require a Part_Of indicator. The only exception is when the
29521 -- related package is a nongeneric private child unit, in which case
29522 -- Part_Of must denote a state in the parent unit or in one of its
29523 -- descendants.
29525 elsif Placement = Visible_State_Space then
29526 if Is_Child_Unit (Pack_Id)
29527 and then not Is_Generic_Unit (Pack_Id)
29528 and then Is_Private_Descendant (Pack_Id)
29529 then
29530 -- A package instantiation does not need a Part_Of indicator when
29531 -- the related generic template has no visible state.
29533 if Ekind (Item_Id) = E_Package
29534 and then Is_Generic_Instance (Item_Id)
29535 and then not Has_Visible_State (Item_Id)
29536 then
29537 null;
29539 -- All other cases require Part_Of
29541 else
29542 Error_Msg_N
29543 ("indicator Part_Of is required in this context "
29544 & "(SPARK RM 7.2.6(3))", Item_Id);
29545 Error_Msg_Name_1 := Chars (Pack_Id);
29546 Error_Msg_N
29547 ("\& is declared in the visible part of private child "
29548 & "unit %", Item_Id);
29549 end if;
29550 end if;
29552 -- When the item appears in the private state space of a package, it
29553 -- must be a part of some state declared by the said package.
29555 else pragma Assert (Placement = Private_State_Space);
29557 -- The related package does not declare a state, the item cannot act
29558 -- as a Part_Of constituent.
29560 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
29561 null;
29563 -- A package instantiation does not need a Part_Of indicator when the
29564 -- related generic template has no visible state.
29566 elsif Ekind (Item_Id) = E_Package
29567 and then Is_Generic_Instance (Item_Id)
29568 and then not Has_Visible_State (Item_Id)
29569 then
29570 null;
29572 -- All other cases require Part_Of
29574 else
29575 Error_Msg_N
29576 ("indicator Part_Of is required in this context "
29577 & "(SPARK RM 7.2.6(2))", Item_Id);
29578 Error_Msg_Name_1 := Chars (Pack_Id);
29579 Error_Msg_N
29580 ("\& is declared in the private part of package %", Item_Id);
29581 end if;
29582 end if;
29583 end Check_Missing_Part_Of;
29585 ---------------------------------------------------
29586 -- Check_Postcondition_Use_In_Inlined_Subprogram --
29587 ---------------------------------------------------
29589 procedure Check_Postcondition_Use_In_Inlined_Subprogram
29590 (Prag : Node_Id;
29591 Spec_Id : Entity_Id)
29593 begin
29594 if Warn_On_Redundant_Constructs
29595 and then Has_Pragma_Inline_Always (Spec_Id)
29596 and then Assertions_Enabled
29597 then
29598 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
29600 if From_Aspect_Specification (Prag) then
29601 Error_Msg_NE
29602 ("aspect % not enforced on inlined subprogram &?r?",
29603 Corresponding_Aspect (Prag), Spec_Id);
29604 else
29605 Error_Msg_NE
29606 ("pragma % not enforced on inlined subprogram &?r?",
29607 Prag, Spec_Id);
29608 end if;
29609 end if;
29610 end Check_Postcondition_Use_In_Inlined_Subprogram;
29612 -------------------------------------
29613 -- Check_State_And_Constituent_Use --
29614 -------------------------------------
29616 procedure Check_State_And_Constituent_Use
29617 (States : Elist_Id;
29618 Constits : Elist_Id;
29619 Context : Node_Id)
29621 Constit_Elmt : Elmt_Id;
29622 Constit_Id : Entity_Id;
29623 State_Id : Entity_Id;
29625 begin
29626 -- Nothing to do if there are no states or constituents
29628 if No (States) or else No (Constits) then
29629 return;
29630 end if;
29632 -- Inspect the list of constituents and try to determine whether its
29633 -- encapsulating state is in list States.
29635 Constit_Elmt := First_Elmt (Constits);
29636 while Present (Constit_Elmt) loop
29637 Constit_Id := Node (Constit_Elmt);
29639 -- Determine whether the constituent is part of an encapsulating
29640 -- state that appears in the same context and if this is the case,
29641 -- emit an error (SPARK RM 7.2.6(7)).
29643 State_Id := Find_Encapsulating_State (States, Constit_Id);
29645 if Present (State_Id) then
29646 Error_Msg_Name_1 := Chars (Constit_Id);
29647 SPARK_Msg_NE
29648 ("cannot mention state & and its constituent % in the same "
29649 & "context", Context, State_Id);
29650 exit;
29651 end if;
29653 Next_Elmt (Constit_Elmt);
29654 end loop;
29655 end Check_State_And_Constituent_Use;
29657 ---------------------------------------------
29658 -- Collect_Inherited_Class_Wide_Conditions --
29659 ---------------------------------------------
29661 procedure Collect_Inherited_Class_Wide_Conditions (Subp : Entity_Id) is
29662 Parent_Subp : constant Entity_Id :=
29663 Ultimate_Alias (Overridden_Operation (Subp));
29664 -- The Overridden_Operation may itself be inherited and as such have no
29665 -- explicit contract.
29667 Prags : constant Node_Id := Contract (Parent_Subp);
29668 In_Spec_Expr : Boolean := In_Spec_Expression;
29669 Installed : Boolean;
29670 Prag : Node_Id;
29671 New_Prag : Node_Id;
29673 begin
29674 Installed := False;
29676 -- Iterate over the contract of the overridden subprogram to find all
29677 -- inherited class-wide pre- and postconditions.
29679 if Present (Prags) then
29680 Prag := Pre_Post_Conditions (Prags);
29682 while Present (Prag) loop
29683 if Pragma_Name_Unmapped (Prag)
29684 in Name_Precondition | Name_Postcondition
29685 and then Class_Present (Prag)
29686 then
29687 -- The generated pragma must be analyzed in the context of
29688 -- the subprogram, to make its formals visible. In addition,
29689 -- we must inhibit freezing and full analysis because the
29690 -- controlling type of the subprogram is not frozen yet, and
29691 -- may have further primitives.
29693 if not Installed then
29694 Installed := True;
29695 Push_Scope (Subp);
29696 Install_Formals (Subp);
29697 In_Spec_Expr := In_Spec_Expression;
29698 In_Spec_Expression := True;
29699 end if;
29701 New_Prag :=
29702 Build_Pragma_Check_Equivalent
29703 (Prag, Subp, Parent_Subp, Keep_Pragma_Id => True);
29705 Insert_After (Unit_Declaration_Node (Subp), New_Prag);
29706 Preanalyze (New_Prag);
29708 -- Prevent further analysis in subsequent processing of the
29709 -- current list of declarations
29711 Set_Analyzed (New_Prag);
29712 end if;
29714 Prag := Next_Pragma (Prag);
29715 end loop;
29717 if Installed then
29718 In_Spec_Expression := In_Spec_Expr;
29719 End_Scope;
29720 end if;
29721 end if;
29722 end Collect_Inherited_Class_Wide_Conditions;
29724 ---------------------------------------
29725 -- Collect_Subprogram_Inputs_Outputs --
29726 ---------------------------------------
29728 procedure Collect_Subprogram_Inputs_Outputs
29729 (Subp_Id : Entity_Id;
29730 Synthesize : Boolean := False;
29731 Subp_Inputs : in out Elist_Id;
29732 Subp_Outputs : in out Elist_Id;
29733 Global_Seen : out Boolean)
29735 procedure Collect_Dependency_Clause (Clause : Node_Id);
29736 -- Collect all relevant items from a dependency clause
29738 procedure Collect_Global_List
29739 (List : Node_Id;
29740 Mode : Name_Id := Name_Input);
29741 -- Collect all relevant items from a global list
29743 -------------------------------
29744 -- Collect_Dependency_Clause --
29745 -------------------------------
29747 procedure Collect_Dependency_Clause (Clause : Node_Id) is
29748 procedure Collect_Dependency_Item
29749 (Item : Node_Id;
29750 Is_Input : Boolean);
29751 -- Add an item to the proper subprogram input or output collection
29753 -----------------------------
29754 -- Collect_Dependency_Item --
29755 -----------------------------
29757 procedure Collect_Dependency_Item
29758 (Item : Node_Id;
29759 Is_Input : Boolean)
29761 Extra : Node_Id;
29763 begin
29764 -- Nothing to collect when the item is null
29766 if Nkind (Item) = N_Null then
29767 null;
29769 -- Ditto for attribute 'Result
29771 elsif Is_Attribute_Result (Item) then
29772 null;
29774 -- Multiple items appear as an aggregate
29776 elsif Nkind (Item) = N_Aggregate then
29777 Extra := First (Expressions (Item));
29778 while Present (Extra) loop
29779 Collect_Dependency_Item (Extra, Is_Input);
29780 Next (Extra);
29781 end loop;
29783 -- Otherwise this is a solitary item
29785 else
29786 if Is_Input then
29787 Append_New_Elmt (Item, Subp_Inputs);
29788 else
29789 Append_New_Elmt (Item, Subp_Outputs);
29790 end if;
29791 end if;
29792 end Collect_Dependency_Item;
29794 -- Start of processing for Collect_Dependency_Clause
29796 begin
29797 if Nkind (Clause) = N_Null then
29798 null;
29800 -- A dependency clause appears as component association
29802 elsif Nkind (Clause) = N_Component_Association then
29803 Collect_Dependency_Item
29804 (Item => Expression (Clause),
29805 Is_Input => True);
29807 Collect_Dependency_Item
29808 (Item => First (Choices (Clause)),
29809 Is_Input => False);
29811 -- To accommodate partial decoration of disabled SPARK features, this
29812 -- routine may be called with illegal input. If this is the case, do
29813 -- not raise Program_Error.
29815 else
29816 null;
29817 end if;
29818 end Collect_Dependency_Clause;
29820 -------------------------
29821 -- Collect_Global_List --
29822 -------------------------
29824 procedure Collect_Global_List
29825 (List : Node_Id;
29826 Mode : Name_Id := Name_Input)
29828 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
29829 -- Add an item to the proper subprogram input or output collection
29831 -------------------------
29832 -- Collect_Global_Item --
29833 -------------------------
29835 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
29836 begin
29837 if Mode in Name_In_Out | Name_Input then
29838 Append_New_Elmt (Item, Subp_Inputs);
29839 end if;
29841 if Mode in Name_In_Out | Name_Output then
29842 Append_New_Elmt (Item, Subp_Outputs);
29843 end if;
29844 end Collect_Global_Item;
29846 -- Local variables
29848 Assoc : Node_Id;
29849 Item : Node_Id;
29851 -- Start of processing for Collect_Global_List
29853 begin
29854 if Nkind (List) = N_Null then
29855 null;
29857 -- Single global item declaration
29859 elsif Nkind (List) in N_Expanded_Name
29860 | N_Identifier
29861 | N_Selected_Component
29862 then
29863 Collect_Global_Item (List, Mode);
29865 -- Simple global list or moded global list declaration
29867 elsif Nkind (List) = N_Aggregate then
29868 if Present (Expressions (List)) then
29869 Item := First (Expressions (List));
29870 while Present (Item) loop
29871 Collect_Global_Item (Item, Mode);
29872 Next (Item);
29873 end loop;
29875 else
29876 Assoc := First (Component_Associations (List));
29877 while Present (Assoc) loop
29878 Collect_Global_List
29879 (List => Expression (Assoc),
29880 Mode => Chars (First (Choices (Assoc))));
29881 Next (Assoc);
29882 end loop;
29883 end if;
29885 -- To accommodate partial decoration of disabled SPARK features, this
29886 -- routine may be called with illegal input. If this is the case, do
29887 -- not raise Program_Error.
29889 else
29890 null;
29891 end if;
29892 end Collect_Global_List;
29894 -- Local variables
29896 Clause : Node_Id;
29897 Clauses : Node_Id;
29898 Depends : Node_Id;
29899 Formal : Entity_Id;
29900 Global : Node_Id;
29901 Spec_Id : Entity_Id := Empty;
29902 Subp_Decl : Node_Id;
29903 Typ : Entity_Id;
29905 -- Start of processing for Collect_Subprogram_Inputs_Outputs
29907 begin
29908 Global_Seen := False;
29910 -- Process all formal parameters of entries, [generic] subprograms, and
29911 -- their bodies.
29913 if Ekind (Subp_Id) in E_Entry
29914 | E_Entry_Family
29915 | E_Function
29916 | E_Generic_Function
29917 | E_Generic_Procedure
29918 | E_Procedure
29919 | E_Subprogram_Body
29920 then
29921 Subp_Decl := Unit_Declaration_Node (Subp_Id);
29922 Spec_Id := Unique_Defining_Entity (Subp_Decl);
29924 -- Process all formal parameters
29926 Formal := First_Entity (Spec_Id);
29927 while Present (Formal) loop
29928 if Ekind (Formal) in E_In_Out_Parameter | E_In_Parameter then
29929 Append_New_Elmt (Formal, Subp_Inputs);
29930 end if;
29932 if Ekind (Formal) in E_In_Out_Parameter | E_Out_Parameter then
29933 Append_New_Elmt (Formal, Subp_Outputs);
29935 -- Out parameters can act as inputs when the related type is
29936 -- tagged, unconstrained array, unconstrained record, or record
29937 -- with unconstrained components.
29939 if Ekind (Formal) = E_Out_Parameter
29940 and then Is_Unconstrained_Or_Tagged_Item (Formal)
29941 then
29942 Append_New_Elmt (Formal, Subp_Inputs);
29943 end if;
29944 end if;
29946 Next_Entity (Formal);
29947 end loop;
29949 -- Otherwise the input denotes a task type, a task body, or the
29950 -- anonymous object created for a single task type.
29952 elsif Ekind (Subp_Id) in E_Task_Type | E_Task_Body
29953 or else Is_Single_Task_Object (Subp_Id)
29954 then
29955 Subp_Decl := Declaration_Node (Subp_Id);
29956 Spec_Id := Unique_Defining_Entity (Subp_Decl);
29957 end if;
29959 -- When processing an entry, subprogram or task body, look for pragmas
29960 -- Refined_Depends and Refined_Global as they specify the inputs and
29961 -- outputs.
29963 if Is_Entry_Body (Subp_Id)
29964 or else Ekind (Subp_Id) in E_Subprogram_Body | E_Task_Body
29965 then
29966 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
29967 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
29969 -- Subprogram declaration or stand-alone body case, look for pragmas
29970 -- Depends and Global
29972 else
29973 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
29974 Global := Get_Pragma (Spec_Id, Pragma_Global);
29975 end if;
29977 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
29978 -- because it provides finer granularity of inputs and outputs.
29980 if Present (Global) then
29981 Global_Seen := True;
29982 Collect_Global_List (Expression (Get_Argument (Global, Spec_Id)));
29984 -- When the related subprogram lacks pragma [Refined_]Global, fall back
29985 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
29986 -- the inputs and outputs from [Refined_]Depends.
29988 elsif Synthesize and then Present (Depends) then
29989 Clauses := Expression (Get_Argument (Depends, Spec_Id));
29991 -- Multiple dependency clauses appear as an aggregate
29993 if Nkind (Clauses) = N_Aggregate then
29994 Clause := First (Component_Associations (Clauses));
29995 while Present (Clause) loop
29996 Collect_Dependency_Clause (Clause);
29997 Next (Clause);
29998 end loop;
30000 -- Otherwise this is a single dependency clause
30002 else
30003 Collect_Dependency_Clause (Clauses);
30004 end if;
30005 end if;
30007 -- The current instance of a protected type acts as a formal parameter
30008 -- of mode IN for functions and IN OUT for entries and procedures
30009 -- (SPARK RM 6.1.4).
30011 if Ekind (Scope (Spec_Id)) = E_Protected_Type then
30012 Typ := Scope (Spec_Id);
30014 -- Use the anonymous object when the type is single protected
30016 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
30017 Typ := Anonymous_Object (Typ);
30018 end if;
30020 Append_New_Elmt (Typ, Subp_Inputs);
30022 if Ekind (Spec_Id) in E_Entry | E_Entry_Family | E_Procedure then
30023 Append_New_Elmt (Typ, Subp_Outputs);
30024 end if;
30026 -- The current instance of a task type acts as a formal parameter of
30027 -- mode IN OUT (SPARK RM 6.1.4).
30029 elsif Ekind (Spec_Id) = E_Task_Type then
30030 Typ := Spec_Id;
30032 -- Use the anonymous object when the type is single task
30034 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
30035 Typ := Anonymous_Object (Typ);
30036 end if;
30038 Append_New_Elmt (Typ, Subp_Inputs);
30039 Append_New_Elmt (Typ, Subp_Outputs);
30041 elsif Is_Single_Task_Object (Spec_Id) then
30042 Append_New_Elmt (Spec_Id, Subp_Inputs);
30043 Append_New_Elmt (Spec_Id, Subp_Outputs);
30044 end if;
30045 end Collect_Subprogram_Inputs_Outputs;
30047 ---------------------------
30048 -- Contract_Freeze_Error --
30049 ---------------------------
30051 procedure Contract_Freeze_Error
30052 (Contract_Id : Entity_Id;
30053 Freeze_Id : Entity_Id)
30055 begin
30056 Error_Msg_Name_1 := Chars (Contract_Id);
30057 Error_Msg_Sloc := Sloc (Freeze_Id);
30059 SPARK_Msg_NE
30060 ("body & declared # freezes the contract of%", Contract_Id, Freeze_Id);
30061 SPARK_Msg_N
30062 ("\all contractual items must be declared before body #", Contract_Id);
30063 end Contract_Freeze_Error;
30065 ---------------------------------
30066 -- Delay_Config_Pragma_Analyze --
30067 ---------------------------------
30069 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
30070 begin
30071 return Pragma_Name_Unmapped (N)
30072 in Name_Interrupt_State | Name_Priority_Specific_Dispatching;
30073 end Delay_Config_Pragma_Analyze;
30075 -----------------------
30076 -- Duplication_Error --
30077 -----------------------
30079 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is
30080 Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag);
30081 Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev);
30083 begin
30084 Error_Msg_Sloc := Sloc (Prev);
30085 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
30087 -- Emit a precise message to distinguish between source pragmas and
30088 -- pragmas generated from aspects. The ordering of the two pragmas is
30089 -- the following:
30091 -- Prev -- ok
30092 -- Prag -- duplicate
30094 -- No error is emitted when both pragmas come from aspects because this
30095 -- is already detected by the general aspect analysis mechanism.
30097 if Prag_From_Asp and Prev_From_Asp then
30098 null;
30099 elsif Prag_From_Asp then
30100 Error_Msg_N ("aspect % duplicates pragma declared #", Prag);
30101 elsif Prev_From_Asp then
30102 Error_Msg_N ("pragma % duplicates aspect declared #", Prag);
30103 else
30104 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
30105 end if;
30106 end Duplication_Error;
30108 ------------------------------
30109 -- Find_Encapsulating_State --
30110 ------------------------------
30112 function Find_Encapsulating_State
30113 (States : Elist_Id;
30114 Constit_Id : Entity_Id) return Entity_Id
30116 State_Id : Entity_Id;
30118 begin
30119 -- Since a constituent may be part of a larger constituent set, climb
30120 -- the encapsulating state chain looking for a state that appears in
30121 -- States.
30123 State_Id := Encapsulating_State (Constit_Id);
30124 while Present (State_Id) loop
30125 if Contains (States, State_Id) then
30126 return State_Id;
30127 end if;
30129 State_Id := Encapsulating_State (State_Id);
30130 end loop;
30132 return Empty;
30133 end Find_Encapsulating_State;
30135 --------------------------
30136 -- Find_Related_Context --
30137 --------------------------
30139 function Find_Related_Context
30140 (Prag : Node_Id;
30141 Do_Checks : Boolean := False) return Node_Id
30143 Stmt : Node_Id;
30145 begin
30146 Stmt := Prev (Prag);
30147 while Present (Stmt) loop
30149 -- Skip prior pragmas, but check for duplicates
30151 if Nkind (Stmt) = N_Pragma then
30152 if Do_Checks
30153 and then Pragma_Name (Stmt) = Pragma_Name (Prag)
30154 then
30155 Duplication_Error
30156 (Prag => Prag,
30157 Prev => Stmt);
30158 end if;
30160 -- Skip internally generated code
30162 elsif not Comes_From_Source (Stmt)
30163 and then not Comes_From_Source (Original_Node (Stmt))
30164 then
30166 -- The anonymous object created for a single concurrent type is a
30167 -- suitable context.
30169 if Nkind (Stmt) = N_Object_Declaration
30170 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
30171 then
30172 return Stmt;
30173 end if;
30175 -- Return the current source construct
30177 else
30178 return Stmt;
30179 end if;
30181 Prev (Stmt);
30182 end loop;
30184 return Empty;
30185 end Find_Related_Context;
30187 --------------------------------------
30188 -- Find_Related_Declaration_Or_Body --
30189 --------------------------------------
30191 function Find_Related_Declaration_Or_Body
30192 (Prag : Node_Id;
30193 Do_Checks : Boolean := False) return Node_Id
30195 Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
30197 procedure Expression_Function_Error;
30198 -- Emit an error concerning pragma Prag that illegaly applies to an
30199 -- expression function.
30201 -------------------------------
30202 -- Expression_Function_Error --
30203 -------------------------------
30205 procedure Expression_Function_Error is
30206 begin
30207 Error_Msg_Name_1 := Prag_Nam;
30209 -- Emit a precise message to distinguish between source pragmas and
30210 -- pragmas generated from aspects.
30212 if From_Aspect_Specification (Prag) then
30213 Error_Msg_N
30214 ("aspect % cannot apply to a stand alone expression function",
30215 Prag);
30216 else
30217 Error_Msg_N
30218 ("pragma % cannot apply to a stand alone expression function",
30219 Prag);
30220 end if;
30221 end Expression_Function_Error;
30223 -- Local variables
30225 Context : constant Node_Id := Parent (Prag);
30226 Stmt : Node_Id;
30228 Look_For_Body : constant Boolean :=
30229 Prag_Nam in Name_Refined_Depends
30230 | Name_Refined_Global
30231 | Name_Refined_Post
30232 | Name_Refined_State;
30233 -- Refinement pragmas must be associated with a subprogram body [stub]
30235 -- Start of processing for Find_Related_Declaration_Or_Body
30237 begin
30238 Stmt := Prev (Prag);
30239 while Present (Stmt) loop
30241 -- Skip prior pragmas, but check for duplicates. Pragmas produced
30242 -- by splitting a complex pre/postcondition are not considered to
30243 -- be duplicates.
30245 if Nkind (Stmt) = N_Pragma then
30246 if Do_Checks
30247 and then not Split_PPC (Stmt)
30248 and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam
30249 then
30250 Duplication_Error
30251 (Prag => Prag,
30252 Prev => Stmt);
30253 end if;
30255 -- Emit an error when a refinement pragma appears on an expression
30256 -- function without a completion.
30258 elsif Do_Checks
30259 and then Look_For_Body
30260 and then Nkind (Stmt) = N_Subprogram_Declaration
30261 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
30262 and then not Has_Completion (Defining_Entity (Stmt))
30263 then
30264 Expression_Function_Error;
30265 return Empty;
30267 -- The refinement pragma applies to a subprogram body stub
30269 elsif Look_For_Body
30270 and then Nkind (Stmt) = N_Subprogram_Body_Stub
30271 then
30272 return Stmt;
30274 -- Skip internally generated code
30276 elsif not Comes_From_Source (Stmt) then
30278 -- The anonymous object created for a single concurrent type is a
30279 -- suitable context.
30281 if Nkind (Stmt) = N_Object_Declaration
30282 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
30283 then
30284 return Stmt;
30286 elsif Nkind (Stmt) = N_Subprogram_Declaration then
30288 -- The subprogram declaration is an internally generated spec
30289 -- for an expression function.
30291 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
30292 return Stmt;
30294 -- The subprogram declaration is an internally generated spec
30295 -- for a stand-alone subrogram body declared inside a protected
30296 -- body.
30298 elsif Present (Corresponding_Body (Stmt))
30299 and then Comes_From_Source (Corresponding_Body (Stmt))
30300 and then Is_Protected_Type (Current_Scope)
30301 then
30302 return Stmt;
30304 -- The subprogram is actually an instance housed within an
30305 -- anonymous wrapper package.
30307 elsif Present (Generic_Parent (Specification (Stmt))) then
30308 return Stmt;
30310 -- Ada 2020: contract on formal subprogram or on generated
30311 -- Access_Subprogram_Wrapper, which appears after the related
30312 -- Access_Subprogram declaration.
30314 elsif Is_Generic_Actual_Subprogram (Defining_Entity (Stmt))
30315 and then Ada_Version >= Ada_2020
30316 then
30317 return Stmt;
30319 elsif Is_Access_Subprogram_Wrapper (Defining_Entity (Stmt))
30320 and then Ada_Version >= Ada_2020
30321 then
30322 return Stmt;
30323 end if;
30324 end if;
30326 -- Return the current construct which is either a subprogram body,
30327 -- a subprogram declaration or is illegal.
30329 else
30330 return Stmt;
30331 end if;
30333 Prev (Stmt);
30334 end loop;
30336 -- If we fall through, then the pragma was either the first declaration
30337 -- or it was preceded by other pragmas and no source constructs.
30339 -- The pragma is associated with a library-level subprogram
30341 if Nkind (Context) = N_Compilation_Unit_Aux then
30342 return Unit (Parent (Context));
30344 -- The pragma appears inside the declarations of an entry body
30346 elsif Nkind (Context) = N_Entry_Body then
30347 return Context;
30349 -- The pragma appears inside the statements of a subprogram body. This
30350 -- placement is the result of subprogram contract expansion.
30352 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
30353 return Parent (Context);
30355 -- The pragma appears inside the declarative part of a package body
30357 elsif Nkind (Context) = N_Package_Body then
30358 return Context;
30360 -- The pragma appears inside the declarative part of a subprogram body
30362 elsif Nkind (Context) = N_Subprogram_Body then
30363 return Context;
30365 -- The pragma appears inside the declarative part of a task body
30367 elsif Nkind (Context) = N_Task_Body then
30368 return Context;
30370 -- The pragma appears inside the visible part of a package specification
30372 elsif Nkind (Context) = N_Package_Specification then
30373 return Parent (Context);
30375 -- The pragma is a byproduct of aspect expansion, return the related
30376 -- context of the original aspect. This case has a lower priority as
30377 -- the above circuitry pinpoints precisely the related context.
30379 elsif Present (Corresponding_Aspect (Prag)) then
30380 return Parent (Corresponding_Aspect (Prag));
30382 -- No candidate subprogram [body] found
30384 else
30385 return Empty;
30386 end if;
30387 end Find_Related_Declaration_Or_Body;
30389 ----------------------------------
30390 -- Find_Related_Package_Or_Body --
30391 ----------------------------------
30393 function Find_Related_Package_Or_Body
30394 (Prag : Node_Id;
30395 Do_Checks : Boolean := False) return Node_Id
30397 Context : constant Node_Id := Parent (Prag);
30398 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
30399 Stmt : Node_Id;
30401 begin
30402 Stmt := Prev (Prag);
30403 while Present (Stmt) loop
30405 -- Skip prior pragmas, but check for duplicates
30407 if Nkind (Stmt) = N_Pragma then
30408 if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then
30409 Duplication_Error
30410 (Prag => Prag,
30411 Prev => Stmt);
30412 end if;
30414 -- Skip internally generated code
30416 elsif not Comes_From_Source (Stmt) then
30417 if Nkind (Stmt) = N_Subprogram_Declaration then
30419 -- The subprogram declaration is an internally generated spec
30420 -- for an expression function.
30422 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
30423 return Stmt;
30425 -- The subprogram is actually an instance housed within an
30426 -- anonymous wrapper package.
30428 elsif Present (Generic_Parent (Specification (Stmt))) then
30429 return Stmt;
30430 end if;
30431 end if;
30433 -- Return the current source construct which is illegal
30435 else
30436 return Stmt;
30437 end if;
30439 Prev (Stmt);
30440 end loop;
30442 -- If we fall through, then the pragma was either the first declaration
30443 -- or it was preceded by other pragmas and no source constructs.
30445 -- The pragma is associated with a package. The immediate context in
30446 -- this case is the specification of the package.
30448 if Nkind (Context) = N_Package_Specification then
30449 return Parent (Context);
30451 -- The pragma appears in the declarations of a package body
30453 elsif Nkind (Context) = N_Package_Body then
30454 return Context;
30456 -- The pragma appears in the statements of a package body
30458 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
30459 and then Nkind (Parent (Context)) = N_Package_Body
30460 then
30461 return Parent (Context);
30463 -- The pragma is a byproduct of aspect expansion, return the related
30464 -- context of the original aspect. This case has a lower priority as
30465 -- the above circuitry pinpoints precisely the related context.
30467 elsif Present (Corresponding_Aspect (Prag)) then
30468 return Parent (Corresponding_Aspect (Prag));
30470 -- No candidate package [body] found
30472 else
30473 return Empty;
30474 end if;
30475 end Find_Related_Package_Or_Body;
30477 ------------------
30478 -- Get_Argument --
30479 ------------------
30481 function Get_Argument
30482 (Prag : Node_Id;
30483 Context_Id : Entity_Id := Empty) return Node_Id
30485 Args : constant List_Id := Pragma_Argument_Associations (Prag);
30487 begin
30488 -- Use the expression of the original aspect when analyzing the template
30489 -- of a generic unit. In both cases the aspect's tree must be decorated
30490 -- to save the global references in the generic context.
30492 if From_Aspect_Specification (Prag)
30493 and then (Present (Context_Id) and then Is_Generic_Unit (Context_Id))
30494 then
30495 return Corresponding_Aspect (Prag);
30497 -- Otherwise use the expression of the pragma
30499 elsif Present (Args) then
30500 return First (Args);
30502 else
30503 return Empty;
30504 end if;
30505 end Get_Argument;
30507 -------------------------
30508 -- Get_Base_Subprogram --
30509 -------------------------
30511 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
30512 begin
30513 -- Follow subprogram renaming chain
30515 if Is_Subprogram (Def_Id)
30516 and then Nkind (Parent (Declaration_Node (Def_Id))) =
30517 N_Subprogram_Renaming_Declaration
30518 and then Present (Alias (Def_Id))
30519 then
30520 return Alias (Def_Id);
30521 else
30522 return Def_Id;
30523 end if;
30524 end Get_Base_Subprogram;
30526 -----------------------
30527 -- Get_SPARK_Mode_Type --
30528 -----------------------
30530 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
30531 begin
30532 if N = Name_On then
30533 return On;
30534 elsif N = Name_Off then
30535 return Off;
30537 -- Any other argument is illegal. Assume that no SPARK mode applies to
30538 -- avoid potential cascaded errors.
30540 else
30541 return None;
30542 end if;
30543 end Get_SPARK_Mode_Type;
30545 ------------------------------------
30546 -- Get_SPARK_Mode_From_Annotation --
30547 ------------------------------------
30549 function Get_SPARK_Mode_From_Annotation
30550 (N : Node_Id) return SPARK_Mode_Type
30552 Mode : Node_Id;
30554 begin
30555 if Nkind (N) = N_Aspect_Specification then
30556 Mode := Expression (N);
30558 else pragma Assert (Nkind (N) = N_Pragma);
30559 Mode := First (Pragma_Argument_Associations (N));
30561 if Present (Mode) then
30562 Mode := Get_Pragma_Arg (Mode);
30563 end if;
30564 end if;
30566 -- Aspect or pragma SPARK_Mode specifies an explicit mode
30568 if Present (Mode) then
30569 if Nkind (Mode) = N_Identifier then
30570 return Get_SPARK_Mode_Type (Chars (Mode));
30572 -- In case of a malformed aspect or pragma, return the default None
30574 else
30575 return None;
30576 end if;
30578 -- Otherwise the lack of an expression defaults SPARK_Mode to On
30580 else
30581 return On;
30582 end if;
30583 end Get_SPARK_Mode_From_Annotation;
30585 ---------------------------
30586 -- Has_Extra_Parentheses --
30587 ---------------------------
30589 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
30590 Expr : Node_Id;
30592 begin
30593 -- The aggregate should not have an expression list because a clause
30594 -- is always interpreted as a component association. The only way an
30595 -- expression list can sneak in is by adding extra parentheses around
30596 -- the individual clauses:
30598 -- Depends (Output => Input) -- proper form
30599 -- Depends ((Output => Input)) -- extra parentheses
30601 -- Since the extra parentheses are not allowed by the syntax of the
30602 -- pragma, flag them now to avoid emitting misleading errors down the
30603 -- line.
30605 if Nkind (Clause) = N_Aggregate
30606 and then Present (Expressions (Clause))
30607 then
30608 Expr := First (Expressions (Clause));
30609 while Present (Expr) loop
30611 -- A dependency clause surrounded by extra parentheses appears
30612 -- as an aggregate of component associations with an optional
30613 -- Paren_Count set.
30615 if Nkind (Expr) = N_Aggregate
30616 and then Present (Component_Associations (Expr))
30617 then
30618 SPARK_Msg_N
30619 ("dependency clause contains extra parentheses", Expr);
30621 -- Otherwise the expression is a malformed construct
30623 else
30624 SPARK_Msg_N ("malformed dependency clause", Expr);
30625 end if;
30627 Next (Expr);
30628 end loop;
30630 return True;
30631 end if;
30633 return False;
30634 end Has_Extra_Parentheses;
30636 ----------------
30637 -- Initialize --
30638 ----------------
30640 procedure Initialize is
30641 begin
30642 Externals.Init;
30643 Compile_Time_Warnings_Errors.Init;
30644 end Initialize;
30646 --------
30647 -- ip --
30648 --------
30650 procedure ip is
30651 begin
30652 Dummy := Dummy + 1;
30653 end ip;
30655 -----------------------------
30656 -- Is_Config_Static_String --
30657 -----------------------------
30659 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
30661 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
30662 -- This is an internal recursive function that is just like the outer
30663 -- function except that it adds the string to the name buffer rather
30664 -- than placing the string in the name buffer.
30666 ------------------------------
30667 -- Add_Config_Static_String --
30668 ------------------------------
30670 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
30671 N : Node_Id;
30672 C : Char_Code;
30674 begin
30675 N := Arg;
30677 if Nkind (N) = N_Op_Concat then
30678 if Add_Config_Static_String (Left_Opnd (N)) then
30679 N := Right_Opnd (N);
30680 else
30681 return False;
30682 end if;
30683 end if;
30685 if Nkind (N) /= N_String_Literal then
30686 Error_Msg_N ("string literal expected for pragma argument", N);
30687 return False;
30689 else
30690 for J in 1 .. String_Length (Strval (N)) loop
30691 C := Get_String_Char (Strval (N), J);
30693 if not In_Character_Range (C) then
30694 Error_Msg
30695 ("string literal contains invalid wide character",
30696 Sloc (N) + 1 + Source_Ptr (J));
30697 return False;
30698 end if;
30700 Add_Char_To_Name_Buffer (Get_Character (C));
30701 end loop;
30702 end if;
30704 return True;
30705 end Add_Config_Static_String;
30707 -- Start of processing for Is_Config_Static_String
30709 begin
30710 Name_Len := 0;
30712 return Add_Config_Static_String (Arg);
30713 end Is_Config_Static_String;
30715 -------------------------------
30716 -- Is_Elaboration_SPARK_Mode --
30717 -------------------------------
30719 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
30720 begin
30721 pragma Assert
30722 (Nkind (N) = N_Pragma
30723 and then Pragma_Name (N) = Name_SPARK_Mode
30724 and then Is_List_Member (N));
30726 -- Pragma SPARK_Mode affects the elaboration of a package body when it
30727 -- appears in the statement part of the body.
30729 return
30730 Present (Parent (N))
30731 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
30732 and then List_Containing (N) = Statements (Parent (N))
30733 and then Present (Parent (Parent (N)))
30734 and then Nkind (Parent (Parent (N))) = N_Package_Body;
30735 end Is_Elaboration_SPARK_Mode;
30737 -----------------------
30738 -- Is_Enabled_Pragma --
30739 -----------------------
30741 function Is_Enabled_Pragma (Prag : Node_Id) return Boolean is
30742 Arg : Node_Id;
30744 begin
30745 if Present (Prag) then
30746 Arg := First (Pragma_Argument_Associations (Prag));
30748 if Present (Arg) then
30749 return Is_True (Expr_Value (Get_Pragma_Arg (Arg)));
30751 -- The lack of a Boolean argument automatically enables the pragma
30753 else
30754 return True;
30755 end if;
30757 -- The pragma is missing, therefore it is not enabled
30759 else
30760 return False;
30761 end if;
30762 end Is_Enabled_Pragma;
30764 -----------------------------------------
30765 -- Is_Non_Significant_Pragma_Reference --
30766 -----------------------------------------
30768 -- This function makes use of the following static table which indicates
30769 -- whether appearance of some name in a given pragma is to be considered
30770 -- as a reference for the purposes of warnings about unreferenced objects.
30772 -- -1 indicates that appearence in any argument is significant
30773 -- 0 indicates that appearance in any argument is not significant
30774 -- +n indicates that appearance as argument n is significant, but all
30775 -- other arguments are not significant
30776 -- 9n arguments from n on are significant, before n insignificant
30778 Sig_Flags : constant array (Pragma_Id) of Int :=
30779 (Pragma_Abort_Defer => -1,
30780 Pragma_Abstract_State => -1,
30781 Pragma_Ada_83 => -1,
30782 Pragma_Ada_95 => -1,
30783 Pragma_Ada_05 => -1,
30784 Pragma_Ada_2005 => -1,
30785 Pragma_Ada_12 => -1,
30786 Pragma_Ada_2012 => -1,
30787 Pragma_Ada_2020 => -1,
30788 Pragma_Aggregate_Individually_Assign => 0,
30789 Pragma_All_Calls_Remote => -1,
30790 Pragma_Allow_Integer_Address => -1,
30791 Pragma_Annotate => 93,
30792 Pragma_Assert => -1,
30793 Pragma_Assert_And_Cut => -1,
30794 Pragma_Assertion_Policy => 0,
30795 Pragma_Assume => -1,
30796 Pragma_Assume_No_Invalid_Values => 0,
30797 Pragma_Async_Readers => 0,
30798 Pragma_Async_Writers => 0,
30799 Pragma_Asynchronous => 0,
30800 Pragma_Atomic => 0,
30801 Pragma_Atomic_Components => 0,
30802 Pragma_Attach_Handler => -1,
30803 Pragma_Attribute_Definition => 92,
30804 Pragma_Check => -1,
30805 Pragma_Check_Float_Overflow => 0,
30806 Pragma_Check_Name => 0,
30807 Pragma_Check_Policy => 0,
30808 Pragma_CPP_Class => 0,
30809 Pragma_CPP_Constructor => 0,
30810 Pragma_CPP_Virtual => 0,
30811 Pragma_CPP_Vtable => 0,
30812 Pragma_CPU => -1,
30813 Pragma_C_Pass_By_Copy => 0,
30814 Pragma_Comment => -1,
30815 Pragma_Common_Object => 0,
30816 Pragma_CUDA_Execute => -1,
30817 Pragma_CUDA_Global => -1,
30818 Pragma_Compile_Time_Error => -1,
30819 Pragma_Compile_Time_Warning => -1,
30820 Pragma_Compiler_Unit => -1,
30821 Pragma_Compiler_Unit_Warning => -1,
30822 Pragma_Complete_Representation => 0,
30823 Pragma_Complex_Representation => 0,
30824 Pragma_Component_Alignment => 0,
30825 Pragma_Constant_After_Elaboration => 0,
30826 Pragma_Contract_Cases => -1,
30827 Pragma_Controlled => 0,
30828 Pragma_Convention => 0,
30829 Pragma_Convention_Identifier => 0,
30830 Pragma_Deadline_Floor => -1,
30831 Pragma_Debug => -1,
30832 Pragma_Debug_Policy => 0,
30833 Pragma_Default_Initial_Condition => -1,
30834 Pragma_Default_Scalar_Storage_Order => 0,
30835 Pragma_Default_Storage_Pool => 0,
30836 Pragma_Depends => -1,
30837 Pragma_Detect_Blocking => 0,
30838 Pragma_Disable_Atomic_Synchronization => 0,
30839 Pragma_Discard_Names => 0,
30840 Pragma_Dispatching_Domain => -1,
30841 Pragma_Effective_Reads => 0,
30842 Pragma_Effective_Writes => 0,
30843 Pragma_Elaborate => 0,
30844 Pragma_Elaborate_All => 0,
30845 Pragma_Elaborate_Body => 0,
30846 Pragma_Elaboration_Checks => 0,
30847 Pragma_Eliminate => 0,
30848 Pragma_Enable_Atomic_Synchronization => 0,
30849 Pragma_Export => -1,
30850 Pragma_Export_Function => -1,
30851 Pragma_Export_Object => -1,
30852 Pragma_Export_Procedure => -1,
30853 Pragma_Export_Value => -1,
30854 Pragma_Export_Valued_Procedure => -1,
30855 Pragma_Extend_System => -1,
30856 Pragma_Extensions_Allowed => 0,
30857 Pragma_Extensions_Visible => 0,
30858 Pragma_External => -1,
30859 Pragma_External_Name_Casing => 0,
30860 Pragma_Fast_Math => 0,
30861 Pragma_Favor_Top_Level => 0,
30862 Pragma_Finalize_Storage_Only => 0,
30863 Pragma_Ghost => 0,
30864 Pragma_Global => -1,
30865 Pragma_Ident => -1,
30866 Pragma_Ignore_Pragma => 0,
30867 Pragma_Implementation_Defined => -1,
30868 Pragma_Implemented => -1,
30869 Pragma_Implicit_Packing => 0,
30870 Pragma_Import => 93,
30871 Pragma_Import_Function => 0,
30872 Pragma_Import_Object => 0,
30873 Pragma_Import_Procedure => 0,
30874 Pragma_Import_Valued_Procedure => 0,
30875 Pragma_Independent => 0,
30876 Pragma_Independent_Components => 0,
30877 Pragma_Initial_Condition => -1,
30878 Pragma_Initialize_Scalars => 0,
30879 Pragma_Initializes => -1,
30880 Pragma_Inline => 0,
30881 Pragma_Inline_Always => 0,
30882 Pragma_Inline_Generic => 0,
30883 Pragma_Inspection_Point => -1,
30884 Pragma_Interface => 92,
30885 Pragma_Interface_Name => 0,
30886 Pragma_Interrupt_Handler => -1,
30887 Pragma_Interrupt_Priority => -1,
30888 Pragma_Interrupt_State => -1,
30889 Pragma_Invariant => -1,
30890 Pragma_Keep_Names => 0,
30891 Pragma_License => 0,
30892 Pragma_Link_With => -1,
30893 Pragma_Linker_Alias => -1,
30894 Pragma_Linker_Constructor => -1,
30895 Pragma_Linker_Destructor => -1,
30896 Pragma_Linker_Options => -1,
30897 Pragma_Linker_Section => -1,
30898 Pragma_List => 0,
30899 Pragma_Lock_Free => 0,
30900 Pragma_Locking_Policy => 0,
30901 Pragma_Loop_Invariant => -1,
30902 Pragma_Loop_Optimize => 0,
30903 Pragma_Loop_Variant => -1,
30904 Pragma_Machine_Attribute => -1,
30905 Pragma_Main => -1,
30906 Pragma_Main_Storage => -1,
30907 Pragma_Max_Entry_Queue_Depth => 0,
30908 Pragma_Max_Entry_Queue_Length => 0,
30909 Pragma_Max_Queue_Length => 0,
30910 Pragma_Memory_Size => 0,
30911 Pragma_No_Body => 0,
30912 Pragma_No_Caching => 0,
30913 Pragma_No_Component_Reordering => -1,
30914 Pragma_No_Elaboration_Code_All => 0,
30915 Pragma_No_Heap_Finalization => 0,
30916 Pragma_No_Inline => 0,
30917 Pragma_No_Return => 0,
30918 Pragma_No_Run_Time => -1,
30919 Pragma_No_Strict_Aliasing => -1,
30920 Pragma_No_Tagged_Streams => 0,
30921 Pragma_Normalize_Scalars => 0,
30922 Pragma_Obsolescent => 0,
30923 Pragma_Optimize => 0,
30924 Pragma_Optimize_Alignment => 0,
30925 Pragma_Ordered => 0,
30926 Pragma_Overflow_Mode => 0,
30927 Pragma_Overriding_Renamings => 0,
30928 Pragma_Pack => 0,
30929 Pragma_Page => 0,
30930 Pragma_Part_Of => 0,
30931 Pragma_Partition_Elaboration_Policy => 0,
30932 Pragma_Passive => 0,
30933 Pragma_Persistent_BSS => 0,
30934 Pragma_Post => -1,
30935 Pragma_Postcondition => -1,
30936 Pragma_Post_Class => -1,
30937 Pragma_Pre => -1,
30938 Pragma_Precondition => -1,
30939 Pragma_Predicate => -1,
30940 Pragma_Predicate_Failure => -1,
30941 Pragma_Preelaborable_Initialization => -1,
30942 Pragma_Preelaborate => 0,
30943 Pragma_Prefix_Exception_Messages => 0,
30944 Pragma_Pre_Class => -1,
30945 Pragma_Priority => -1,
30946 Pragma_Priority_Specific_Dispatching => 0,
30947 Pragma_Profile => 0,
30948 Pragma_Profile_Warnings => 0,
30949 Pragma_Propagate_Exceptions => 0,
30950 Pragma_Provide_Shift_Operators => 0,
30951 Pragma_Psect_Object => 0,
30952 Pragma_Pure => 0,
30953 Pragma_Pure_Function => 0,
30954 Pragma_Queuing_Policy => 0,
30955 Pragma_Rational => 0,
30956 Pragma_Ravenscar => 0,
30957 Pragma_Refined_Depends => -1,
30958 Pragma_Refined_Global => -1,
30959 Pragma_Refined_Post => -1,
30960 Pragma_Refined_State => -1,
30961 Pragma_Relative_Deadline => 0,
30962 Pragma_Remote_Access_Type => -1,
30963 Pragma_Remote_Call_Interface => -1,
30964 Pragma_Remote_Types => -1,
30965 Pragma_Rename_Pragma => 0,
30966 Pragma_Restricted_Run_Time => 0,
30967 Pragma_Restriction_Warnings => 0,
30968 Pragma_Restrictions => 0,
30969 Pragma_Reviewable => -1,
30970 Pragma_Secondary_Stack_Size => -1,
30971 Pragma_Share_Generic => 0,
30972 Pragma_Shared => 0,
30973 Pragma_Shared_Passive => 0,
30974 Pragma_Short_Circuit_And_Or => 0,
30975 Pragma_Short_Descriptors => 0,
30976 Pragma_Simple_Storage_Pool_Type => 0,
30977 Pragma_Source_File_Name => 0,
30978 Pragma_Source_File_Name_Project => 0,
30979 Pragma_Source_Reference => 0,
30980 Pragma_SPARK_Mode => 0,
30981 Pragma_Static_Elaboration_Desired => 0,
30982 Pragma_Storage_Size => -1,
30983 Pragma_Storage_Unit => 0,
30984 Pragma_Stream_Convert => 0,
30985 Pragma_Style_Checks => 0,
30986 Pragma_Subtitle => 0,
30987 Pragma_Suppress => 0,
30988 Pragma_Suppress_All => 0,
30989 Pragma_Suppress_Debug_Info => 0,
30990 Pragma_Suppress_Exception_Locations => 0,
30991 Pragma_Suppress_Initialization => 0,
30992 Pragma_System_Name => 0,
30993 Pragma_Task_Dispatching_Policy => 0,
30994 Pragma_Task_Info => -1,
30995 Pragma_Task_Name => -1,
30996 Pragma_Task_Storage => -1,
30997 Pragma_Test_Case => -1,
30998 Pragma_Thread_Local_Storage => -1,
30999 Pragma_Time_Slice => -1,
31000 Pragma_Title => 0,
31001 Pragma_Type_Invariant => -1,
31002 Pragma_Type_Invariant_Class => -1,
31003 Pragma_Unchecked_Union => 0,
31004 Pragma_Unevaluated_Use_Of_Old => 0,
31005 Pragma_Unimplemented_Unit => 0,
31006 Pragma_Universal_Aliasing => 0,
31007 Pragma_Universal_Data => 0,
31008 Pragma_Unmodified => 0,
31009 Pragma_Unreferenced => 0,
31010 Pragma_Unreferenced_Objects => 0,
31011 Pragma_Unreserve_All_Interrupts => 0,
31012 Pragma_Unsuppress => 0,
31013 Pragma_Unused => 0,
31014 Pragma_Use_VADS_Size => 0,
31015 Pragma_Validity_Checks => 0,
31016 Pragma_Volatile => 0,
31017 Pragma_Volatile_Components => 0,
31018 Pragma_Volatile_Full_Access => 0,
31019 Pragma_Volatile_Function => 0,
31020 Pragma_Warning_As_Error => 0,
31021 Pragma_Warnings => 0,
31022 Pragma_Weak_External => 0,
31023 Pragma_Wide_Character_Encoding => 0,
31024 Unknown_Pragma => 0);
31026 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
31027 Id : Pragma_Id;
31028 P : Node_Id;
31029 C : Int;
31030 AN : Nat;
31032 function Arg_No return Nat;
31033 -- Returns an integer showing what argument we are in. A value of
31034 -- zero means we are not in any of the arguments.
31036 ------------
31037 -- Arg_No --
31038 ------------
31040 function Arg_No return Nat is
31041 A : Node_Id;
31042 N : Nat;
31044 begin
31045 A := First (Pragma_Argument_Associations (Parent (P)));
31046 N := 1;
31047 loop
31048 if No (A) then
31049 return 0;
31050 elsif A = P then
31051 return N;
31052 end if;
31054 Next (A);
31055 N := N + 1;
31056 end loop;
31057 end Arg_No;
31059 -- Start of processing for Non_Significant_Pragma_Reference
31061 begin
31062 P := Parent (N);
31064 if Nkind (P) /= N_Pragma_Argument_Association then
31065 return False;
31067 else
31068 Id := Get_Pragma_Id (Parent (P));
31069 C := Sig_Flags (Id);
31070 AN := Arg_No;
31072 if AN = 0 then
31073 return False;
31074 end if;
31076 case C is
31077 when -1 =>
31078 return False;
31080 when 0 =>
31081 return True;
31083 when 92 .. 99 =>
31084 return AN < (C - 90);
31086 when others =>
31087 return AN /= C;
31088 end case;
31089 end if;
31090 end Is_Non_Significant_Pragma_Reference;
31092 ------------------------------
31093 -- Is_Pragma_String_Literal --
31094 ------------------------------
31096 -- This function returns true if the corresponding pragma argument is a
31097 -- static string expression. These are the only cases in which string
31098 -- literals can appear as pragma arguments. We also allow a string literal
31099 -- as the first argument to pragma Assert (although it will of course
31100 -- always generate a type error).
31102 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
31103 Pragn : constant Node_Id := Parent (Par);
31104 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
31105 Pname : constant Name_Id := Pragma_Name (Pragn);
31106 Argn : Natural;
31107 N : Node_Id;
31109 begin
31110 Argn := 1;
31111 N := First (Assoc);
31112 loop
31113 exit when N = Par;
31114 Argn := Argn + 1;
31115 Next (N);
31116 end loop;
31118 if Pname = Name_Assert then
31119 return True;
31121 elsif Pname = Name_Export then
31122 return Argn > 2;
31124 elsif Pname = Name_Ident then
31125 return Argn = 1;
31127 elsif Pname = Name_Import then
31128 return Argn > 2;
31130 elsif Pname = Name_Interface_Name then
31131 return Argn > 1;
31133 elsif Pname = Name_Linker_Alias then
31134 return Argn = 2;
31136 elsif Pname = Name_Linker_Section then
31137 return Argn = 2;
31139 elsif Pname = Name_Machine_Attribute then
31140 return Argn = 2;
31142 elsif Pname = Name_Source_File_Name then
31143 return True;
31145 elsif Pname = Name_Source_Reference then
31146 return Argn = 2;
31148 elsif Pname = Name_Title then
31149 return True;
31151 elsif Pname = Name_Subtitle then
31152 return True;
31154 else
31155 return False;
31156 end if;
31157 end Is_Pragma_String_Literal;
31159 ---------------------------
31160 -- Is_Private_SPARK_Mode --
31161 ---------------------------
31163 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
31164 begin
31165 pragma Assert
31166 (Nkind (N) = N_Pragma
31167 and then Pragma_Name (N) = Name_SPARK_Mode
31168 and then Is_List_Member (N));
31170 -- For pragma SPARK_Mode to be private, it has to appear in the private
31171 -- declarations of a package.
31173 return
31174 Present (Parent (N))
31175 and then Nkind (Parent (N)) = N_Package_Specification
31176 and then List_Containing (N) = Private_Declarations (Parent (N));
31177 end Is_Private_SPARK_Mode;
31179 -------------------------------------
31180 -- Is_Unconstrained_Or_Tagged_Item --
31181 -------------------------------------
31183 function Is_Unconstrained_Or_Tagged_Item
31184 (Item : Entity_Id) return Boolean
31186 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
31187 -- Determine whether record type Typ has at least one unconstrained
31188 -- component.
31190 ---------------------------------
31191 -- Has_Unconstrained_Component --
31192 ---------------------------------
31194 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
31195 Comp : Entity_Id;
31197 begin
31198 Comp := First_Component (Typ);
31199 while Present (Comp) loop
31200 if Is_Unconstrained_Or_Tagged_Item (Comp) then
31201 return True;
31202 end if;
31204 Next_Component (Comp);
31205 end loop;
31207 return False;
31208 end Has_Unconstrained_Component;
31210 -- Local variables
31212 Typ : constant Entity_Id := Etype (Item);
31214 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
31216 begin
31217 if Is_Tagged_Type (Typ) then
31218 return True;
31220 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
31221 return True;
31223 elsif Is_Record_Type (Typ) then
31224 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
31225 return True;
31226 else
31227 return Has_Unconstrained_Component (Typ);
31228 end if;
31230 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
31231 return True;
31233 else
31234 return False;
31235 end if;
31236 end Is_Unconstrained_Or_Tagged_Item;
31238 -----------------------------
31239 -- Is_Valid_Assertion_Kind --
31240 -----------------------------
31242 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
31243 begin
31244 case Nam is
31245 when
31246 -- RM defined
31248 Name_Assert
31249 | Name_Assertion_Policy
31250 | Name_Static_Predicate
31251 | Name_Dynamic_Predicate
31252 | Name_Pre
31253 | Name_uPre
31254 | Name_Post
31255 | Name_uPost
31256 | Name_Type_Invariant
31257 | Name_uType_Invariant
31259 -- Impl defined
31261 | Name_Assert_And_Cut
31262 | Name_Assume
31263 | Name_Contract_Cases
31264 | Name_Debug
31265 | Name_Default_Initial_Condition
31266 | Name_Ghost
31267 | Name_Initial_Condition
31268 | Name_Invariant
31269 | Name_uInvariant
31270 | Name_Loop_Invariant
31271 | Name_Loop_Variant
31272 | Name_Postcondition
31273 | Name_Precondition
31274 | Name_Predicate
31275 | Name_Refined_Post
31276 | Name_Statement_Assertions
31278 return True;
31280 when others =>
31281 return False;
31282 end case;
31283 end Is_Valid_Assertion_Kind;
31285 --------------------------------------
31286 -- Process_Compilation_Unit_Pragmas --
31287 --------------------------------------
31289 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
31290 begin
31291 -- A special check for pragma Suppress_All, a very strange DEC pragma,
31292 -- strange because it comes at the end of the unit. Rational has the
31293 -- same name for a pragma, but treats it as a program unit pragma, In
31294 -- GNAT we just decide to allow it anywhere at all. If it appeared then
31295 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
31296 -- node, and we insert a pragma Suppress (All_Checks) at the start of
31297 -- the context clause to ensure the correct processing.
31299 if Has_Pragma_Suppress_All (N) then
31300 Prepend_To (Context_Items (N),
31301 Make_Pragma (Sloc (N),
31302 Chars => Name_Suppress,
31303 Pragma_Argument_Associations => New_List (
31304 Make_Pragma_Argument_Association (Sloc (N),
31305 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
31306 end if;
31308 -- Nothing else to do at the current time
31310 end Process_Compilation_Unit_Pragmas;
31312 --------------------------------------------
31313 -- Validate_Compile_Time_Warning_Or_Error --
31314 --------------------------------------------
31316 procedure Validate_Compile_Time_Warning_Or_Error
31317 (N : Node_Id;
31318 Eloc : Source_Ptr)
31320 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
31321 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
31322 Arg2 : constant Node_Id := Next (Arg1);
31324 Pname : constant Name_Id := Pragma_Name_Unmapped (N);
31325 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
31327 begin
31328 Analyze_And_Resolve (Arg1x, Standard_Boolean);
31330 if Compile_Time_Known_Value (Arg1x) then
31331 if Is_True (Expr_Value (Arg1x)) then
31333 -- We have already verified that the second argument is a static
31334 -- string expression. Its string value must be retrieved
31335 -- explicitly if it is a declared constant, otherwise it has
31336 -- been constant-folded previously.
31338 declare
31339 Cent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
31340 Str : constant String_Id :=
31341 Strval (Expr_Value_S (Get_Pragma_Arg (Arg2)));
31342 Str_Len : constant Nat := String_Length (Str);
31344 Force : constant Boolean :=
31345 Prag_Id = Pragma_Compile_Time_Warning
31346 and then Is_Spec_Name (Unit_Name (Current_Sem_Unit))
31347 and then (Ekind (Cent) /= E_Package
31348 or else not In_Private_Part (Cent));
31349 -- Set True if this is the warning case, and we are in the
31350 -- visible part of a package spec, or in a subprogram spec,
31351 -- in which case we want to force the client to see the
31352 -- warning, even though it is not in the main unit.
31354 C : Character;
31355 CC : Char_Code;
31356 Cont : Boolean;
31357 Ptr : Nat;
31359 begin
31360 -- Loop through segments of message separated by line feeds.
31361 -- We output these segments as separate messages with
31362 -- continuation marks for all but the first.
31364 Cont := False;
31365 Ptr := 1;
31366 loop
31367 Error_Msg_Strlen := 0;
31369 -- Loop to copy characters from argument to error message
31370 -- string buffer.
31372 loop
31373 exit when Ptr > Str_Len;
31374 CC := Get_String_Char (Str, Ptr);
31375 Ptr := Ptr + 1;
31377 -- Ignore wide chars ??? else store character
31379 if In_Character_Range (CC) then
31380 C := Get_Character (CC);
31381 exit when C = ASCII.LF;
31382 Error_Msg_Strlen := Error_Msg_Strlen + 1;
31383 Error_Msg_String (Error_Msg_Strlen) := C;
31384 end if;
31385 end loop;
31387 -- Here with one line ready to go
31389 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
31391 -- If this is a warning in a spec, then we want clients
31392 -- to see the warning, so mark the message with the
31393 -- special sequence !! to force the warning. In the case
31394 -- of a package spec, we do not force this if we are in
31395 -- the private part of the spec.
31397 if Force then
31398 if Cont = False then
31399 Error_Msg
31400 ("<<~!!", Eloc, Is_Compile_Time_Pragma => True);
31401 Cont := True;
31402 else
31403 Error_Msg
31404 ("\<<~!!", Eloc, Is_Compile_Time_Pragma => True);
31405 end if;
31407 -- Error, rather than warning, or in a body, so we do not
31408 -- need to force visibility for client (error will be
31409 -- output in any case, and this is the situation in which
31410 -- we do not want a client to get a warning, since the
31411 -- warning is in the body or the spec private part).
31413 else
31414 if Cont = False then
31415 Error_Msg
31416 ("<<~", Eloc, Is_Compile_Time_Pragma => True);
31417 Cont := True;
31418 else
31419 Error_Msg
31420 ("\<<~", Eloc, Is_Compile_Time_Pragma => True);
31421 end if;
31422 end if;
31424 exit when Ptr > Str_Len;
31425 end loop;
31426 end;
31427 end if;
31429 -- Arg1x is not known at compile time, so possibly issue an error
31430 -- or warning. This can happen only if the pragma's processing
31431 -- was deferred until after the back end is run (see
31432 -- Process_Compile_Time_Warning_Or_Error). Note that the warning
31433 -- control switch applies to only the warning case.
31435 elsif Prag_Id = Pragma_Compile_Time_Error then
31436 Error_Msg_N ("condition is not known at compile time", Arg1x);
31438 elsif Warn_On_Unknown_Compile_Time_Warning then
31439 Error_Msg_N ("??condition is not known at compile time", Arg1x);
31440 end if;
31441 end Validate_Compile_Time_Warning_Or_Error;
31443 ------------------------------------
31444 -- Record_Possible_Body_Reference --
31445 ------------------------------------
31447 procedure Record_Possible_Body_Reference
31448 (State_Id : Entity_Id;
31449 Ref : Node_Id)
31451 Context : Node_Id;
31452 Spec_Id : Entity_Id;
31454 begin
31455 -- Ensure that we are dealing with a reference to a state
31457 pragma Assert (Ekind (State_Id) = E_Abstract_State);
31459 -- Climb the tree starting from the reference looking for a package body
31460 -- whose spec declares the referenced state. This criteria automatically
31461 -- excludes references in package specs which are legal. Note that it is
31462 -- not wise to emit an error now as the package body may lack pragma
31463 -- Refined_State or the referenced state may not be mentioned in the
31464 -- refinement. This approach avoids the generation of misleading errors.
31466 Context := Ref;
31467 while Present (Context) loop
31468 if Nkind (Context) = N_Package_Body then
31469 Spec_Id := Corresponding_Spec (Context);
31471 if Present (Abstract_States (Spec_Id))
31472 and then Contains (Abstract_States (Spec_Id), State_Id)
31473 then
31474 if No (Body_References (State_Id)) then
31475 Set_Body_References (State_Id, New_Elmt_List);
31476 end if;
31478 Append_Elmt (Ref, To => Body_References (State_Id));
31479 exit;
31480 end if;
31481 end if;
31483 Context := Parent (Context);
31484 end loop;
31485 end Record_Possible_Body_Reference;
31487 ------------------------------------------
31488 -- Relocate_Pragmas_To_Anonymous_Object --
31489 ------------------------------------------
31491 procedure Relocate_Pragmas_To_Anonymous_Object
31492 (Typ_Decl : Node_Id;
31493 Obj_Decl : Node_Id)
31495 Decl : Node_Id;
31496 Def : Node_Id;
31497 Next_Decl : Node_Id;
31499 begin
31500 if Nkind (Typ_Decl) = N_Protected_Type_Declaration then
31501 Def := Protected_Definition (Typ_Decl);
31502 else
31503 pragma Assert (Nkind (Typ_Decl) = N_Task_Type_Declaration);
31504 Def := Task_Definition (Typ_Decl);
31505 end if;
31507 -- The concurrent definition has a visible declaration list. Inspect it
31508 -- and relocate all canidate pragmas.
31510 if Present (Def) and then Present (Visible_Declarations (Def)) then
31511 Decl := First (Visible_Declarations (Def));
31512 while Present (Decl) loop
31514 -- Preserve the following declaration for iteration purposes due
31515 -- to possible relocation of a pragma.
31517 Next_Decl := Next (Decl);
31519 if Nkind (Decl) = N_Pragma
31520 and then Pragma_On_Anonymous_Object_OK (Get_Pragma_Id (Decl))
31521 then
31522 Remove (Decl);
31523 Insert_After (Obj_Decl, Decl);
31525 -- Skip internally generated code
31527 elsif not Comes_From_Source (Decl) then
31528 null;
31530 -- No candidate pragmas are available for relocation
31532 else
31533 exit;
31534 end if;
31536 Decl := Next_Decl;
31537 end loop;
31538 end if;
31539 end Relocate_Pragmas_To_Anonymous_Object;
31541 ------------------------------
31542 -- Relocate_Pragmas_To_Body --
31543 ------------------------------
31545 procedure Relocate_Pragmas_To_Body
31546 (Subp_Body : Node_Id;
31547 Target_Body : Node_Id := Empty)
31549 procedure Relocate_Pragma (Prag : Node_Id);
31550 -- Remove a single pragma from its current list and add it to the
31551 -- declarations of the proper body (either Subp_Body or Target_Body).
31553 ---------------------
31554 -- Relocate_Pragma --
31555 ---------------------
31557 procedure Relocate_Pragma (Prag : Node_Id) is
31558 Decls : List_Id;
31559 Target : Node_Id;
31561 begin
31562 -- When subprogram stubs or expression functions are involves, the
31563 -- destination declaration list belongs to the proper body.
31565 if Present (Target_Body) then
31566 Target := Target_Body;
31567 else
31568 Target := Subp_Body;
31569 end if;
31571 Decls := Declarations (Target);
31573 if No (Decls) then
31574 Decls := New_List;
31575 Set_Declarations (Target, Decls);
31576 end if;
31578 -- Unhook the pragma from its current list
31580 Remove (Prag);
31581 Prepend (Prag, Decls);
31582 end Relocate_Pragma;
31584 -- Local variables
31586 Body_Id : constant Entity_Id :=
31587 Defining_Unit_Name (Specification (Subp_Body));
31588 Next_Stmt : Node_Id;
31589 Stmt : Node_Id;
31591 -- Start of processing for Relocate_Pragmas_To_Body
31593 begin
31594 -- Do not process a body that comes from a separate unit as no construct
31595 -- can possibly follow it.
31597 if not Is_List_Member (Subp_Body) then
31598 return;
31600 -- Do not relocate pragmas that follow a stub if the stub does not have
31601 -- a proper body.
31603 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
31604 and then No (Target_Body)
31605 then
31606 return;
31608 -- Do not process internally generated routine _Postconditions
31610 elsif Ekind (Body_Id) = E_Procedure
31611 and then Chars (Body_Id) = Name_uPostconditions
31612 then
31613 return;
31614 end if;
31616 -- Look at what is following the body. We are interested in certain kind
31617 -- of pragmas (either from source or byproducts of expansion) that can
31618 -- apply to a body [stub].
31620 Stmt := Next (Subp_Body);
31621 while Present (Stmt) loop
31623 -- Preserve the following statement for iteration purposes due to a
31624 -- possible relocation of a pragma.
31626 Next_Stmt := Next (Stmt);
31628 -- Move a candidate pragma following the body to the declarations of
31629 -- the body.
31631 if Nkind (Stmt) = N_Pragma
31632 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
31633 then
31635 -- If a source pragma Warnings follows the body, it applies to
31636 -- following statements and does not belong in the body.
31638 if Get_Pragma_Id (Stmt) = Pragma_Warnings
31639 and then Comes_From_Source (Stmt)
31640 then
31641 null;
31642 else
31643 Relocate_Pragma (Stmt);
31644 end if;
31646 -- Skip internally generated code
31648 elsif not Comes_From_Source (Stmt) then
31649 null;
31651 -- No candidate pragmas are available for relocation
31653 else
31654 exit;
31655 end if;
31657 Stmt := Next_Stmt;
31658 end loop;
31659 end Relocate_Pragmas_To_Body;
31661 -------------------
31662 -- Resolve_State --
31663 -------------------
31665 procedure Resolve_State (N : Node_Id) is
31666 Func : Entity_Id;
31667 State : Entity_Id;
31669 begin
31670 if Is_Entity_Name (N) and then Present (Entity (N)) then
31671 Func := Entity (N);
31673 -- Handle overloading of state names by functions. Traverse the
31674 -- homonym chain looking for an abstract state.
31676 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
31677 pragma Assert (Is_Overloaded (N));
31679 State := Homonym (Func);
31680 while Present (State) loop
31681 if Ekind (State) = E_Abstract_State then
31683 -- Resolve the overloading by setting the proper entity of
31684 -- the reference to that of the state.
31686 Set_Etype (N, Standard_Void_Type);
31687 Set_Entity (N, State);
31688 Set_Is_Overloaded (N, False);
31690 Generate_Reference (State, N);
31691 return;
31692 end if;
31694 State := Homonym (State);
31695 end loop;
31697 -- A function can never act as a state. If the homonym chain does
31698 -- not contain a corresponding state, then something went wrong in
31699 -- the overloading mechanism.
31701 raise Program_Error;
31702 end if;
31703 end if;
31704 end Resolve_State;
31706 ----------------------------
31707 -- Rewrite_Assertion_Kind --
31708 ----------------------------
31710 procedure Rewrite_Assertion_Kind
31711 (N : Node_Id;
31712 From_Policy : Boolean := False)
31714 Nam : Name_Id;
31716 begin
31717 Nam := No_Name;
31718 if Nkind (N) = N_Attribute_Reference
31719 and then Attribute_Name (N) = Name_Class
31720 and then Nkind (Prefix (N)) = N_Identifier
31721 then
31722 case Chars (Prefix (N)) is
31723 when Name_Pre =>
31724 Nam := Name_uPre;
31726 when Name_Post =>
31727 Nam := Name_uPost;
31729 when Name_Type_Invariant =>
31730 Nam := Name_uType_Invariant;
31732 when Name_Invariant =>
31733 Nam := Name_uInvariant;
31735 when others =>
31736 return;
31737 end case;
31739 -- Recommend standard use of aspect names Pre/Post
31741 elsif Nkind (N) = N_Identifier
31742 and then From_Policy
31743 and then Serious_Errors_Detected = 0
31744 then
31745 if Chars (N) = Name_Precondition
31746 or else Chars (N) = Name_Postcondition
31747 then
31748 Error_Msg_N ("Check_Policy is a non-standard pragma??", N);
31749 Error_Msg_N
31750 ("\use Assertion_Policy and aspect names Pre/Post for "
31751 & "Ada2012 conformance?", N);
31752 end if;
31754 return;
31755 end if;
31757 if Nam /= No_Name then
31758 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
31759 end if;
31760 end Rewrite_Assertion_Kind;
31762 --------
31763 -- rv --
31764 --------
31766 procedure rv is
31767 begin
31768 Dummy := Dummy + 1;
31769 end rv;
31771 --------------------------------
31772 -- Set_Encoded_Interface_Name --
31773 --------------------------------
31775 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
31776 Str : constant String_Id := Strval (S);
31777 Len : constant Nat := String_Length (Str);
31778 CC : Char_Code;
31779 C : Character;
31780 J : Pos;
31782 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
31784 procedure Encode;
31785 -- Stores encoded value of character code CC. The encoding we use an
31786 -- underscore followed by four lower case hex digits.
31788 ------------
31789 -- Encode --
31790 ------------
31792 procedure Encode is
31793 begin
31794 Store_String_Char (Get_Char_Code ('_'));
31795 Store_String_Char
31796 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
31797 Store_String_Char
31798 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
31799 Store_String_Char
31800 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
31801 Store_String_Char
31802 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
31803 end Encode;
31805 -- Start of processing for Set_Encoded_Interface_Name
31807 begin
31808 -- If first character is asterisk, this is a link name, and we leave it
31809 -- completely unmodified. We also ignore null strings (the latter case
31810 -- happens only in error cases).
31812 if Len = 0
31813 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
31814 then
31815 Set_Interface_Name (E, S);
31817 else
31818 J := 1;
31819 loop
31820 CC := Get_String_Char (Str, J);
31822 exit when not In_Character_Range (CC);
31824 C := Get_Character (CC);
31826 exit when C /= '_' and then C /= '$'
31827 and then C not in '0' .. '9'
31828 and then C not in 'a' .. 'z'
31829 and then C not in 'A' .. 'Z';
31831 if J = Len then
31832 Set_Interface_Name (E, S);
31833 return;
31835 else
31836 J := J + 1;
31837 end if;
31838 end loop;
31840 -- Here we need to encode. The encoding we use as follows:
31841 -- three underscores + four hex digits (lower case)
31843 Start_String;
31845 for J in 1 .. String_Length (Str) loop
31846 CC := Get_String_Char (Str, J);
31848 if not In_Character_Range (CC) then
31849 Encode;
31850 else
31851 C := Get_Character (CC);
31853 if C = '_' or else C = '$'
31854 or else C in '0' .. '9'
31855 or else C in 'a' .. 'z'
31856 or else C in 'A' .. 'Z'
31857 then
31858 Store_String_Char (CC);
31859 else
31860 Encode;
31861 end if;
31862 end if;
31863 end loop;
31865 Set_Interface_Name (E,
31866 Make_String_Literal (Sloc (S),
31867 Strval => End_String));
31868 end if;
31869 end Set_Encoded_Interface_Name;
31871 ------------------------
31872 -- Set_Elab_Unit_Name --
31873 ------------------------
31875 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is
31876 Pref : Node_Id;
31877 Scop : Entity_Id;
31879 begin
31880 if Nkind (N) = N_Identifier
31881 and then Nkind (With_Item) = N_Identifier
31882 then
31883 Set_Entity (N, Entity (With_Item));
31885 elsif Nkind (N) = N_Selected_Component then
31886 Change_Selected_Component_To_Expanded_Name (N);
31887 Set_Entity (N, Entity (With_Item));
31888 Set_Entity (Selector_Name (N), Entity (N));
31890 Pref := Prefix (N);
31891 Scop := Scope (Entity (N));
31892 while Nkind (Pref) = N_Selected_Component loop
31893 Change_Selected_Component_To_Expanded_Name (Pref);
31894 Set_Entity (Selector_Name (Pref), Scop);
31895 Set_Entity (Pref, Scop);
31896 Pref := Prefix (Pref);
31897 Scop := Scope (Scop);
31898 end loop;
31900 Set_Entity (Pref, Scop);
31901 end if;
31903 Generate_Reference (Entity (With_Item), N, Set_Ref => False);
31904 end Set_Elab_Unit_Name;
31906 -----------------------
31907 -- Set_Overflow_Mode --
31908 -----------------------
31910 procedure Set_Overflow_Mode (N : Node_Id) is
31912 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type;
31913 -- Function to process one pragma argument, Arg
31915 -----------------------
31916 -- Get_Overflow_Mode --
31917 -----------------------
31919 function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type is
31920 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
31922 begin
31923 if Chars (Argx) = Name_Strict then
31924 return Strict;
31926 elsif Chars (Argx) = Name_Minimized then
31927 return Minimized;
31929 elsif Chars (Argx) = Name_Eliminated then
31930 return Eliminated;
31932 else
31933 raise Program_Error;
31934 end if;
31935 end Get_Overflow_Mode;
31937 -- Local variables
31939 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
31940 Arg2 : constant Node_Id := Next (Arg1);
31942 -- Start of processing for Set_Overflow_Mode
31944 begin
31945 -- Process first argument
31947 Scope_Suppress.Overflow_Mode_General :=
31948 Get_Overflow_Mode (Arg1);
31950 -- Case of only one argument
31952 if No (Arg2) then
31953 Scope_Suppress.Overflow_Mode_Assertions :=
31954 Scope_Suppress.Overflow_Mode_General;
31956 -- Case of two arguments present
31958 else
31959 Scope_Suppress.Overflow_Mode_Assertions :=
31960 Get_Overflow_Mode (Arg2);
31961 end if;
31962 end Set_Overflow_Mode;
31964 -------------------
31965 -- Test_Case_Arg --
31966 -------------------
31968 function Test_Case_Arg
31969 (Prag : Node_Id;
31970 Arg_Nam : Name_Id;
31971 From_Aspect : Boolean := False) return Node_Id
31973 Aspect : constant Node_Id := Corresponding_Aspect (Prag);
31974 Arg : Node_Id;
31975 Args : Node_Id;
31977 begin
31978 pragma Assert
31979 (Arg_Nam in Name_Ensures | Name_Mode | Name_Name | Name_Requires);
31981 -- The caller requests the aspect argument
31983 if From_Aspect then
31984 if Present (Aspect)
31985 and then Nkind (Expression (Aspect)) = N_Aggregate
31986 then
31987 Args := Expression (Aspect);
31989 -- "Name" and "Mode" may appear without an identifier as a
31990 -- positional association.
31992 if Present (Expressions (Args)) then
31993 Arg := First (Expressions (Args));
31995 if Present (Arg) and then Arg_Nam = Name_Name then
31996 return Arg;
31997 end if;
31999 -- Skip "Name"
32001 Arg := Next (Arg);
32003 if Present (Arg) and then Arg_Nam = Name_Mode then
32004 return Arg;
32005 end if;
32006 end if;
32008 -- Some or all arguments may appear as component associatons
32010 if Present (Component_Associations (Args)) then
32011 Arg := First (Component_Associations (Args));
32012 while Present (Arg) loop
32013 if Chars (First (Choices (Arg))) = Arg_Nam then
32014 return Arg;
32015 end if;
32017 Next (Arg);
32018 end loop;
32019 end if;
32020 end if;
32022 -- Otherwise retrieve the argument directly from the pragma
32024 else
32025 Arg := First (Pragma_Argument_Associations (Prag));
32027 if Present (Arg) and then Arg_Nam = Name_Name then
32028 return Arg;
32029 end if;
32031 -- Skip argument "Name"
32033 Arg := Next (Arg);
32035 if Present (Arg) and then Arg_Nam = Name_Mode then
32036 return Arg;
32037 end if;
32039 -- Skip argument "Mode"
32041 Arg := Next (Arg);
32043 -- Arguments "Requires" and "Ensures" are optional and may not be
32044 -- present at all.
32046 while Present (Arg) loop
32047 if Chars (Arg) = Arg_Nam then
32048 return Arg;
32049 end if;
32051 Next (Arg);
32052 end loop;
32053 end if;
32055 return Empty;
32056 end Test_Case_Arg;
32058 --------------------------------------------
32059 -- Defer_Compile_Time_Warning_Error_To_BE --
32060 --------------------------------------------
32062 procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id) is
32063 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
32064 begin
32065 Compile_Time_Warnings_Errors.Append
32066 (New_Val => CTWE_Entry'(Eloc => Sloc (Arg1),
32067 Scope => Current_Scope,
32068 Prag => N));
32070 -- If the Boolean expression contains T'Size, and we're not in the main
32071 -- unit being compiled, then we need to copy the pragma into the main
32072 -- unit, because otherwise T'Size might never be computed, leaving it
32073 -- as 0.
32075 if not In_Extended_Main_Code_Unit (N) then
32076 Insert_Library_Level_Action (New_Copy_Tree (N));
32077 end if;
32078 end Defer_Compile_Time_Warning_Error_To_BE;
32080 ------------------------------------------
32081 -- Validate_Compile_Time_Warning_Errors --
32082 ------------------------------------------
32084 procedure Validate_Compile_Time_Warning_Errors is
32085 procedure Set_Scope (S : Entity_Id);
32086 -- Install all enclosing scopes of S along with S itself
32088 procedure Unset_Scope (S : Entity_Id);
32089 -- Uninstall all enclosing scopes of S along with S itself
32091 ---------------
32092 -- Set_Scope --
32093 ---------------
32095 procedure Set_Scope (S : Entity_Id) is
32096 begin
32097 if S /= Standard_Standard then
32098 Set_Scope (Scope (S));
32099 end if;
32101 Push_Scope (S);
32102 end Set_Scope;
32104 -----------------
32105 -- Unset_Scope --
32106 -----------------
32108 procedure Unset_Scope (S : Entity_Id) is
32109 begin
32110 if S /= Standard_Standard then
32111 Unset_Scope (Scope (S));
32112 end if;
32114 Pop_Scope;
32115 end Unset_Scope;
32117 -- Start of processing for Validate_Compile_Time_Warning_Errors
32119 begin
32120 Expander_Mode_Save_And_Set (False);
32121 In_Compile_Time_Warning_Or_Error := True;
32123 for N in Compile_Time_Warnings_Errors.First ..
32124 Compile_Time_Warnings_Errors.Last
32125 loop
32126 declare
32127 T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N);
32129 begin
32130 Set_Scope (T.Scope);
32131 Reset_Analyzed_Flags (T.Prag);
32132 Validate_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc);
32133 Unset_Scope (T.Scope);
32134 end;
32135 end loop;
32137 In_Compile_Time_Warning_Or_Error := False;
32138 Expander_Mode_Restore;
32139 end Validate_Compile_Time_Warning_Errors;
32141 end Sem_Prag;