Fix failure when -fno-rtti test is run in C++17 or later
[official-gcc.git] / gcc / ada / sem_prag.adb
blobf1f463c23da1992e2cdb14f6469ee7fcf7987eb4
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-2018, 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 Freeze; use Freeze;
45 with Ghost; use Ghost;
46 with Gnatvsn; use Gnatvsn;
47 with Lib; use Lib;
48 with Lib.Writ; use Lib.Writ;
49 with Lib.Xref; use Lib.Xref;
50 with Namet.Sp; use Namet.Sp;
51 with Nlists; use Nlists;
52 with Nmake; use Nmake;
53 with Output; use Output;
54 with Par_SCO; use Par_SCO;
55 with Restrict; use Restrict;
56 with Rident; use Rident;
57 with Rtsfind; use Rtsfind;
58 with Sem; use Sem;
59 with Sem_Aux; use Sem_Aux;
60 with Sem_Ch3; use Sem_Ch3;
61 with Sem_Ch6; use Sem_Ch6;
62 with Sem_Ch8; use Sem_Ch8;
63 with Sem_Ch12; use Sem_Ch12;
64 with Sem_Ch13; use Sem_Ch13;
65 with Sem_Disp; use Sem_Disp;
66 with Sem_Dist; use Sem_Dist;
67 with Sem_Elab; use Sem_Elab;
68 with Sem_Elim; use Sem_Elim;
69 with Sem_Eval; use Sem_Eval;
70 with Sem_Intr; use Sem_Intr;
71 with Sem_Mech; use Sem_Mech;
72 with Sem_Res; use Sem_Res;
73 with Sem_Type; use Sem_Type;
74 with Sem_Util; use Sem_Util;
75 with Sem_Warn; use Sem_Warn;
76 with Stand; use Stand;
77 with Sinfo; use Sinfo;
78 with Sinfo.CN; use Sinfo.CN;
79 with Sinput; use Sinput;
80 with Stringt; use Stringt;
81 with Stylesw; use Stylesw;
82 with Table;
83 with Targparm; use Targparm;
84 with Tbuild; use Tbuild;
85 with Ttypes;
86 with Uintp; use Uintp;
87 with Uname; use Uname;
88 with Urealp; use Urealp;
89 with Validsw; use Validsw;
90 with Warnsw; use Warnsw;
92 with System.Case_Util;
94 package body Sem_Prag is
96 ----------------------------------------------
97 -- Common Handling of Import-Export Pragmas --
98 ----------------------------------------------
100 -- In the following section, a number of Import_xxx and Export_xxx pragmas
101 -- are defined by GNAT. These are compatible with the DEC pragmas of the
102 -- same name, and all have the following common form and processing:
104 -- pragma Export_xxx
105 -- [Internal =>] LOCAL_NAME
106 -- [, [External =>] EXTERNAL_SYMBOL]
107 -- [, other optional parameters ]);
109 -- pragma Import_xxx
110 -- [Internal =>] LOCAL_NAME
111 -- [, [External =>] EXTERNAL_SYMBOL]
112 -- [, other optional parameters ]);
114 -- EXTERNAL_SYMBOL ::=
115 -- IDENTIFIER
116 -- | static_string_EXPRESSION
118 -- The internal LOCAL_NAME designates the entity that is imported or
119 -- exported, and must refer to an entity in the current declarative
120 -- part (as required by the rules for LOCAL_NAME).
122 -- The external linker name is designated by the External parameter if
123 -- given, or the Internal parameter if not (if there is no External
124 -- parameter, the External parameter is a copy of the Internal name).
126 -- If the External parameter is given as a string, then this string is
127 -- treated as an external name (exactly as though it had been given as an
128 -- External_Name parameter for a normal Import pragma).
130 -- If the External parameter is given as an identifier (or there is no
131 -- External parameter, so that the Internal identifier is used), then
132 -- the external name is the characters of the identifier, translated
133 -- to all lower case letters.
135 -- Note: the external name specified or implied by any of these special
136 -- Import_xxx or Export_xxx pragmas override an external or link name
137 -- specified in a previous Import or Export pragma.
139 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
140 -- named notation, following the standard rules for subprogram calls, i.e.
141 -- parameters can be given in any order if named notation is used, and
142 -- positional and named notation can be mixed, subject to the rule that all
143 -- positional parameters must appear first.
145 -- Note: All these pragmas are implemented exactly following the DEC design
146 -- and implementation and are intended to be fully compatible with the use
147 -- of these pragmas in the DEC Ada compiler.
149 --------------------------------------------
150 -- Checking for Duplicated External Names --
151 --------------------------------------------
153 -- It is suspicious if two separate Export pragmas use the same external
154 -- name. The following table is used to diagnose this situation so that
155 -- an appropriate warning can be issued.
157 -- The Node_Id stored is for the N_String_Literal node created to hold
158 -- the value of the external name. The Sloc of this node is used to
159 -- cross-reference the location of the duplication.
161 package Externals is new Table.Table (
162 Table_Component_Type => Node_Id,
163 Table_Index_Type => Int,
164 Table_Low_Bound => 0,
165 Table_Initial => 100,
166 Table_Increment => 100,
167 Table_Name => "Name_Externals");
169 -------------------------------------
170 -- Local Subprograms and Variables --
171 -------------------------------------
173 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
174 -- This routine is used for possible casing adjustment of an explicit
175 -- external name supplied as a string literal (the node N), according to
176 -- the casing requirement of Opt.External_Name_Casing. If this is set to
177 -- As_Is, then the string literal is returned unchanged, but if it is set
178 -- to Uppercase or Lowercase, then a new string literal with appropriate
179 -- casing is constructed.
181 procedure Analyze_Part_Of
182 (Indic : Node_Id;
183 Item_Id : Entity_Id;
184 Encap : Node_Id;
185 Encap_Id : out Entity_Id;
186 Legal : out Boolean);
187 -- Subsidiary to Analyze_Part_Of_In_Decl_Part, Analyze_Part_Of_Option and
188 -- Analyze_Pragma. Perform full analysis of indicator Part_Of. Indic is the
189 -- Part_Of indicator. Item_Id is the entity of an abstract state, object or
190 -- package instantiation. Encap denotes the encapsulating state or single
191 -- concurrent type. Encap_Id is the entity of Encap. Flag Legal is set when
192 -- the indicator is legal.
194 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
195 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
196 -- Query whether a particular item appears in a mixed list of nodes and
197 -- entities. It is assumed that all nodes in the list have entities.
199 procedure Check_Postcondition_Use_In_Inlined_Subprogram
200 (Prag : Node_Id;
201 Spec_Id : Entity_Id);
202 -- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition,
203 -- Precondition, Refined_Post, and Test_Case. Emit a warning when pragma
204 -- Prag is associated with subprogram Spec_Id subject to Inline_Always,
205 -- and assertions are enabled.
207 procedure Check_State_And_Constituent_Use
208 (States : Elist_Id;
209 Constits : Elist_Id;
210 Context : Node_Id);
211 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
212 -- Global and Initializes. Determine whether a state from list States and a
213 -- corresponding constituent from list Constits (if any) appear in the same
214 -- context denoted by Context. If this is the case, emit an error.
216 procedure Contract_Freeze_Error
217 (Contract_Id : Entity_Id;
218 Freeze_Id : Entity_Id);
219 -- Subsidiary to the analysis of pragmas Contract_Cases, Part_Of, Post, and
220 -- Pre. Emit a freezing-related error message where Freeze_Id is the entity
221 -- of a body which caused contract freezing and Contract_Id denotes the
222 -- entity of the affected contstruct.
224 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id);
225 -- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma
226 -- Prag that duplicates previous pragma Prev.
228 function Find_Encapsulating_State
229 (States : Elist_Id;
230 Constit_Id : Entity_Id) return Entity_Id;
231 -- Given the entity of a constituent Constit_Id, find the corresponding
232 -- encapsulating state which appears in States. The routine returns Empty
233 -- if no such state is found.
235 function Find_Related_Context
236 (Prag : Node_Id;
237 Do_Checks : Boolean := False) return Node_Id;
238 -- Subsidiary to the analysis of pragmas
239 -- Async_Readers
240 -- Async_Writers
241 -- Constant_After_Elaboration
242 -- Effective_Reads
243 -- Effective_Writers
244 -- Part_Of
245 -- Find the first source declaration or statement found while traversing
246 -- the previous node chain starting from pragma Prag. If flag Do_Checks is
247 -- set, the routine reports duplicate pragmas. The routine returns Empty
248 -- when reaching the start of the node chain.
250 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
251 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
252 -- original one, following the renaming chain) is returned. Otherwise the
253 -- entity is returned unchanged. Should be in Einfo???
255 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
256 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
257 -- Get_SPARK_Mode_From_Annotation. Convert a name into a corresponding
258 -- value of type SPARK_Mode_Type.
260 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
261 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
262 -- Determine whether dependency clause Clause is surrounded by extra
263 -- parentheses. If this is the case, issue an error message.
265 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
266 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
267 -- pragma Depends. Determine whether the type of dependency item Item is
268 -- tagged, unconstrained array, unconstrained record or a record with at
269 -- least one unconstrained component.
271 procedure Record_Possible_Body_Reference
272 (State_Id : Entity_Id;
273 Ref : Node_Id);
274 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
275 -- Global. Given an abstract state denoted by State_Id and a reference Ref
276 -- to it, determine whether the reference appears in a package body that
277 -- will eventually refine the state. If this is the case, record the
278 -- reference for future checks (see Analyze_Refined_State_In_Decls).
280 procedure Resolve_State (N : Node_Id);
281 -- Handle the overloading of state names by functions. When N denotes a
282 -- function, this routine finds the corresponding state and sets the entity
283 -- of N to that of the state.
285 procedure Rewrite_Assertion_Kind
286 (N : Node_Id;
287 From_Policy : Boolean := False);
288 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
289 -- then it is rewritten as an identifier with the corresponding special
290 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
291 -- and Check_Policy. If the names are Precondition or Postcondition, this
292 -- combination is deprecated in favor of Assertion_Policy and Ada2012
293 -- Aspect names. The parameter From_Policy indicates that the pragma
294 -- is the old non-standard Check_Policy and not a rewritten pragma.
296 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id);
297 -- Place semantic information on the argument of an Elaborate/Elaborate_All
298 -- pragma. Entity name for unit and its parents is taken from item in
299 -- previous with_clause that mentions the unit.
301 Dummy : Integer := 0;
302 pragma Volatile (Dummy);
303 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
305 procedure ip;
306 pragma No_Inline (ip);
307 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
308 -- is just to help debugging the front end. If a pragma Inspection_Point
309 -- is added to a source program, then breaking on ip will get you to that
310 -- point in the program.
312 procedure rv;
313 pragma No_Inline (rv);
314 -- This is a dummy function called by the processing for pragma Reviewable.
315 -- It is there for assisting front end debugging. By placing a Reviewable
316 -- pragma in the source program, a breakpoint on rv catches this place in
317 -- the source, allowing convenient stepping to the point of interest.
319 -------------------------------
320 -- Adjust_External_Name_Case --
321 -------------------------------
323 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
324 CC : Char_Code;
326 begin
327 -- Adjust case of literal if required
329 if Opt.External_Name_Exp_Casing = As_Is then
330 return N;
332 else
333 -- Copy existing string
335 Start_String;
337 -- Set proper casing
339 for J in 1 .. String_Length (Strval (N)) loop
340 CC := Get_String_Char (Strval (N), J);
342 if Opt.External_Name_Exp_Casing = Uppercase
343 and then CC >= Get_Char_Code ('a')
344 and then CC <= Get_Char_Code ('z')
345 then
346 Store_String_Char (CC - 32);
348 elsif Opt.External_Name_Exp_Casing = Lowercase
349 and then CC >= Get_Char_Code ('A')
350 and then CC <= Get_Char_Code ('Z')
351 then
352 Store_String_Char (CC + 32);
354 else
355 Store_String_Char (CC);
356 end if;
357 end loop;
359 return
360 Make_String_Literal (Sloc (N),
361 Strval => End_String);
362 end if;
363 end Adjust_External_Name_Case;
365 -----------------------------------------
366 -- Analyze_Contract_Cases_In_Decl_Part --
367 -----------------------------------------
369 -- WARNING: This routine manages Ghost regions. Return statements must be
370 -- replaced by gotos which jump to the end of the routine and restore the
371 -- Ghost mode.
373 procedure Analyze_Contract_Cases_In_Decl_Part
374 (N : Node_Id;
375 Freeze_Id : Entity_Id := Empty)
377 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
378 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
380 Others_Seen : Boolean := False;
381 -- This flag is set when an "others" choice is encountered. It is used
382 -- to detect multiple illegal occurrences of "others".
384 procedure Analyze_Contract_Case (CCase : Node_Id);
385 -- Verify the legality of a single contract case
387 ---------------------------
388 -- Analyze_Contract_Case --
389 ---------------------------
391 procedure Analyze_Contract_Case (CCase : Node_Id) is
392 Case_Guard : Node_Id;
393 Conseq : Node_Id;
394 Errors : Nat;
395 Extra_Guard : Node_Id;
397 begin
398 if Nkind (CCase) = N_Component_Association then
399 Case_Guard := First (Choices (CCase));
400 Conseq := Expression (CCase);
402 -- Each contract case must have exactly one case guard
404 Extra_Guard := Next (Case_Guard);
406 if Present (Extra_Guard) then
407 Error_Msg_N
408 ("contract case must have exactly one case guard",
409 Extra_Guard);
410 end if;
412 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
414 if Nkind (Case_Guard) = N_Others_Choice then
415 if Others_Seen then
416 Error_Msg_N
417 ("only one others choice allowed in contract cases",
418 Case_Guard);
419 else
420 Others_Seen := True;
421 end if;
423 elsif Others_Seen then
424 Error_Msg_N
425 ("others must be the last choice in contract cases", N);
426 end if;
428 -- Preanalyze the case guard and consequence
430 if Nkind (Case_Guard) /= N_Others_Choice then
431 Errors := Serious_Errors_Detected;
432 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
434 -- Emit a clarification message when the case guard contains
435 -- at least one undefined reference, possibly due to contract
436 -- freezing.
438 if Errors /= Serious_Errors_Detected
439 and then Present (Freeze_Id)
440 and then Has_Undefined_Reference (Case_Guard)
441 then
442 Contract_Freeze_Error (Spec_Id, Freeze_Id);
443 end if;
444 end if;
446 Errors := Serious_Errors_Detected;
447 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
449 -- Emit a clarification message when the consequence contains
450 -- at least one undefined reference, possibly due to contract
451 -- freezing.
453 if Errors /= Serious_Errors_Detected
454 and then Present (Freeze_Id)
455 and then Has_Undefined_Reference (Conseq)
456 then
457 Contract_Freeze_Error (Spec_Id, Freeze_Id);
458 end if;
460 -- The contract case is malformed
462 else
463 Error_Msg_N ("wrong syntax in contract case", CCase);
464 end if;
465 end Analyze_Contract_Case;
467 -- Local variables
469 CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
471 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
472 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
473 -- Save the Ghost-related attributes to restore on exit
475 CCase : Node_Id;
476 Restore_Scope : Boolean := False;
478 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
480 begin
481 -- Do not analyze the pragma multiple times
483 if Is_Analyzed_Pragma (N) then
484 return;
485 end if;
487 -- Set the Ghost mode in effect from the pragma. Due to the delayed
488 -- analysis of the pragma, the Ghost mode at point of declaration and
489 -- point of analysis may not necessarily be the same. Use the mode in
490 -- effect at the point of declaration.
492 Set_Ghost_Mode (N);
494 -- Single and multiple contract cases must appear in aggregate form. If
495 -- this is not the case, then either the parser of the analysis of the
496 -- pragma failed to produce an aggregate.
498 pragma Assert (Nkind (CCases) = N_Aggregate);
500 if Present (Component_Associations (CCases)) then
502 -- Ensure that the formal parameters are visible when analyzing all
503 -- clauses. This falls out of the general rule of aspects pertaining
504 -- to subprogram declarations.
506 if not In_Open_Scopes (Spec_Id) then
507 Restore_Scope := True;
508 Push_Scope (Spec_Id);
510 if Is_Generic_Subprogram (Spec_Id) then
511 Install_Generic_Formals (Spec_Id);
512 else
513 Install_Formals (Spec_Id);
514 end if;
515 end if;
517 CCase := First (Component_Associations (CCases));
518 while Present (CCase) loop
519 Analyze_Contract_Case (CCase);
520 Next (CCase);
521 end loop;
523 if Restore_Scope then
524 End_Scope;
525 end if;
527 -- Currently it is not possible to inline pre/postconditions on a
528 -- subprogram subject to pragma Inline_Always.
530 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
532 -- Otherwise the pragma is illegal
534 else
535 Error_Msg_N ("wrong syntax for constract cases", N);
536 end if;
538 Set_Is_Analyzed_Pragma (N);
540 Restore_Ghost_Region (Saved_GM, Saved_IGR);
541 end Analyze_Contract_Cases_In_Decl_Part;
543 ----------------------------------
544 -- Analyze_Depends_In_Decl_Part --
545 ----------------------------------
547 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
548 Loc : constant Source_Ptr := Sloc (N);
549 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
550 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
552 All_Inputs_Seen : Elist_Id := No_Elist;
553 -- A list containing the entities of all the inputs processed so far.
554 -- The list is populated with unique entities because the same input
555 -- may appear in multiple input lists.
557 All_Outputs_Seen : Elist_Id := No_Elist;
558 -- A list containing the entities of all the outputs processed so far.
559 -- The list is populated with unique entities because output items are
560 -- unique in a dependence relation.
562 Constits_Seen : Elist_Id := No_Elist;
563 -- A list containing the entities of all constituents processed so far.
564 -- It aids in detecting illegal usage of a state and a corresponding
565 -- constituent in pragma [Refinde_]Depends.
567 Global_Seen : Boolean := False;
568 -- A flag set when pragma Global has been processed
570 Null_Output_Seen : Boolean := False;
571 -- A flag used to track the legality of a null output
573 Result_Seen : Boolean := False;
574 -- A flag set when Spec_Id'Result is processed
576 States_Seen : Elist_Id := No_Elist;
577 -- A list containing the entities of all states processed so far. It
578 -- helps in detecting illegal usage of a state and a corresponding
579 -- constituent in pragma [Refined_]Depends.
581 Subp_Inputs : Elist_Id := No_Elist;
582 Subp_Outputs : Elist_Id := No_Elist;
583 -- Two lists containing the full set of inputs and output of the related
584 -- subprograms. Note that these lists contain both nodes and entities.
586 Task_Input_Seen : Boolean := False;
587 Task_Output_Seen : Boolean := False;
588 -- Flags used to track the implicit dependence of a task unit on itself
590 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
591 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
592 -- to the name buffer. The individual kinds are as follows:
593 -- E_Abstract_State - "state"
594 -- E_Constant - "constant"
595 -- E_Generic_In_Out_Parameter - "generic parameter"
596 -- E_Generic_In_Parameter - "generic parameter"
597 -- E_In_Parameter - "parameter"
598 -- E_In_Out_Parameter - "parameter"
599 -- E_Loop_Parameter - "loop parameter"
600 -- E_Out_Parameter - "parameter"
601 -- E_Protected_Type - "current instance of protected type"
602 -- E_Task_Type - "current instance of task type"
603 -- E_Variable - "global"
605 procedure Analyze_Dependency_Clause
606 (Clause : Node_Id;
607 Is_Last : Boolean);
608 -- Verify the legality of a single dependency clause. Flag Is_Last
609 -- denotes whether Clause is the last clause in the relation.
611 procedure Check_Function_Return;
612 -- Verify that Funtion'Result appears as one of the outputs
613 -- (SPARK RM 6.1.5(10)).
615 procedure Check_Role
616 (Item : Node_Id;
617 Item_Id : Entity_Id;
618 Is_Input : Boolean;
619 Self_Ref : Boolean);
620 -- Ensure that an item fulfills its designated input and/or output role
621 -- as specified by pragma Global (if any) or the enclosing context. If
622 -- this is not the case, emit an error. Item and Item_Id denote the
623 -- attributes of an item. Flag Is_Input should be set when item comes
624 -- from an input list. Flag Self_Ref should be set when the item is an
625 -- output and the dependency clause has operator "+".
627 procedure Check_Usage
628 (Subp_Items : Elist_Id;
629 Used_Items : Elist_Id;
630 Is_Input : Boolean);
631 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
632 -- error if this is not the case.
634 procedure Normalize_Clause (Clause : Node_Id);
635 -- Remove a self-dependency "+" from the input list of a clause
637 -----------------------------
638 -- Add_Item_To_Name_Buffer --
639 -----------------------------
641 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
642 begin
643 if Ekind (Item_Id) = E_Abstract_State then
644 Add_Str_To_Name_Buffer ("state");
646 elsif Ekind (Item_Id) = E_Constant then
647 Add_Str_To_Name_Buffer ("constant");
649 elsif Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
650 E_Generic_In_Parameter)
651 then
652 Add_Str_To_Name_Buffer ("generic parameter");
654 elsif Is_Formal (Item_Id) then
655 Add_Str_To_Name_Buffer ("parameter");
657 elsif Ekind (Item_Id) = E_Loop_Parameter then
658 Add_Str_To_Name_Buffer ("loop parameter");
660 elsif Ekind (Item_Id) = E_Protected_Type
661 or else Is_Single_Protected_Object (Item_Id)
662 then
663 Add_Str_To_Name_Buffer ("current instance of protected type");
665 elsif Ekind (Item_Id) = E_Task_Type
666 or else Is_Single_Task_Object (Item_Id)
667 then
668 Add_Str_To_Name_Buffer ("current instance of task type");
670 elsif Ekind (Item_Id) = E_Variable then
671 Add_Str_To_Name_Buffer ("global");
673 -- The routine should not be called with non-SPARK items
675 else
676 raise Program_Error;
677 end if;
678 end Add_Item_To_Name_Buffer;
680 -------------------------------
681 -- Analyze_Dependency_Clause --
682 -------------------------------
684 procedure Analyze_Dependency_Clause
685 (Clause : Node_Id;
686 Is_Last : Boolean)
688 procedure Analyze_Input_List (Inputs : Node_Id);
689 -- Verify the legality of a single input list
691 procedure Analyze_Input_Output
692 (Item : Node_Id;
693 Is_Input : Boolean;
694 Self_Ref : Boolean;
695 Top_Level : Boolean;
696 Seen : in out Elist_Id;
697 Null_Seen : in out Boolean;
698 Non_Null_Seen : in out Boolean);
699 -- Verify the legality of a single input or output item. Flag
700 -- Is_Input should be set whenever Item is an input, False when it
701 -- denotes an output. Flag Self_Ref should be set when the item is an
702 -- output and the dependency clause has a "+". Flag Top_Level should
703 -- be set whenever Item appears immediately within an input or output
704 -- list. Seen is a collection of all abstract states, objects and
705 -- formals processed so far. Flag Null_Seen denotes whether a null
706 -- input or output has been encountered. Flag Non_Null_Seen denotes
707 -- whether a non-null input or output has been encountered.
709 ------------------------
710 -- Analyze_Input_List --
711 ------------------------
713 procedure Analyze_Input_List (Inputs : Node_Id) is
714 Inputs_Seen : Elist_Id := No_Elist;
715 -- A list containing the entities of all inputs that appear in the
716 -- current input list.
718 Non_Null_Input_Seen : Boolean := False;
719 Null_Input_Seen : Boolean := False;
720 -- Flags used to check the legality of an input list
722 Input : Node_Id;
724 begin
725 -- Multiple inputs appear as an aggregate
727 if Nkind (Inputs) = N_Aggregate then
728 if Present (Component_Associations (Inputs)) then
729 SPARK_Msg_N
730 ("nested dependency relations not allowed", Inputs);
732 elsif Present (Expressions (Inputs)) then
733 Input := First (Expressions (Inputs));
734 while Present (Input) loop
735 Analyze_Input_Output
736 (Item => Input,
737 Is_Input => True,
738 Self_Ref => False,
739 Top_Level => False,
740 Seen => Inputs_Seen,
741 Null_Seen => Null_Input_Seen,
742 Non_Null_Seen => Non_Null_Input_Seen);
744 Next (Input);
745 end loop;
747 -- Syntax error, always report
749 else
750 Error_Msg_N ("malformed input dependency list", Inputs);
751 end if;
753 -- Process a solitary input
755 else
756 Analyze_Input_Output
757 (Item => Inputs,
758 Is_Input => True,
759 Self_Ref => False,
760 Top_Level => False,
761 Seen => Inputs_Seen,
762 Null_Seen => Null_Input_Seen,
763 Non_Null_Seen => Non_Null_Input_Seen);
764 end if;
766 -- Detect an illegal dependency clause of the form
768 -- (null =>[+] null)
770 if Null_Output_Seen and then Null_Input_Seen then
771 SPARK_Msg_N
772 ("null dependency clause cannot have a null input list",
773 Inputs);
774 end if;
775 end Analyze_Input_List;
777 --------------------------
778 -- Analyze_Input_Output --
779 --------------------------
781 procedure Analyze_Input_Output
782 (Item : Node_Id;
783 Is_Input : Boolean;
784 Self_Ref : Boolean;
785 Top_Level : Boolean;
786 Seen : in out Elist_Id;
787 Null_Seen : in out Boolean;
788 Non_Null_Seen : in out Boolean)
790 procedure Current_Task_Instance_Seen;
791 -- Set the appropriate global flag when the current instance of a
792 -- task unit is encountered.
794 --------------------------------
795 -- Current_Task_Instance_Seen --
796 --------------------------------
798 procedure Current_Task_Instance_Seen is
799 begin
800 if Is_Input then
801 Task_Input_Seen := True;
802 else
803 Task_Output_Seen := True;
804 end if;
805 end Current_Task_Instance_Seen;
807 -- Local variables
809 Is_Output : constant Boolean := not Is_Input;
810 Grouped : Node_Id;
811 Item_Id : Entity_Id;
813 -- Start of processing for Analyze_Input_Output
815 begin
816 -- Multiple input or output items appear as an aggregate
818 if Nkind (Item) = N_Aggregate then
819 if not Top_Level then
820 SPARK_Msg_N ("nested grouping of items not allowed", Item);
822 elsif Present (Component_Associations (Item)) then
823 SPARK_Msg_N
824 ("nested dependency relations not allowed", Item);
826 -- Recursively analyze the grouped items
828 elsif Present (Expressions (Item)) then
829 Grouped := First (Expressions (Item));
830 while Present (Grouped) loop
831 Analyze_Input_Output
832 (Item => Grouped,
833 Is_Input => Is_Input,
834 Self_Ref => Self_Ref,
835 Top_Level => False,
836 Seen => Seen,
837 Null_Seen => Null_Seen,
838 Non_Null_Seen => Non_Null_Seen);
840 Next (Grouped);
841 end loop;
843 -- Syntax error, always report
845 else
846 Error_Msg_N ("malformed dependency list", Item);
847 end if;
849 -- Process attribute 'Result in the context of a dependency clause
851 elsif Is_Attribute_Result (Item) then
852 Non_Null_Seen := True;
854 Analyze (Item);
856 -- Attribute 'Result is allowed to appear on the output side of
857 -- a dependency clause (SPARK RM 6.1.5(6)).
859 if Is_Input then
860 SPARK_Msg_N ("function result cannot act as input", Item);
862 elsif Null_Seen then
863 SPARK_Msg_N
864 ("cannot mix null and non-null dependency items", Item);
866 else
867 Result_Seen := True;
868 end if;
870 -- Detect multiple uses of null in a single dependency list or
871 -- throughout the whole relation. Verify the placement of a null
872 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
874 elsif Nkind (Item) = N_Null then
875 if Null_Seen then
876 SPARK_Msg_N
877 ("multiple null dependency relations not allowed", Item);
879 elsif Non_Null_Seen then
880 SPARK_Msg_N
881 ("cannot mix null and non-null dependency items", Item);
883 else
884 Null_Seen := True;
886 if Is_Output then
887 if not Is_Last then
888 SPARK_Msg_N
889 ("null output list must be the last clause in a "
890 & "dependency relation", Item);
892 -- Catch a useless dependence of the form:
893 -- null =>+ ...
895 elsif Self_Ref then
896 SPARK_Msg_N
897 ("useless dependence, null depends on itself", Item);
898 end if;
899 end if;
900 end if;
902 -- Default case
904 else
905 Non_Null_Seen := True;
907 if Null_Seen then
908 SPARK_Msg_N ("cannot mix null and non-null items", Item);
909 end if;
911 Analyze (Item);
912 Resolve_State (Item);
914 -- Find the entity of the item. If this is a renaming, climb
915 -- the renaming chain to reach the root object. Renamings of
916 -- non-entire objects do not yield an entity (Empty).
918 Item_Id := Entity_Of (Item);
920 if Present (Item_Id) then
922 -- Constants
924 if Ekind_In (Item_Id, E_Constant, E_Loop_Parameter)
925 or else
927 -- Current instances of concurrent types
929 Ekind_In (Item_Id, E_Protected_Type, E_Task_Type)
930 or else
932 -- Formal parameters
934 Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
935 E_Generic_In_Parameter,
936 E_In_Parameter,
937 E_In_Out_Parameter,
938 E_Out_Parameter)
939 or else
941 -- States, variables
943 Ekind_In (Item_Id, E_Abstract_State, E_Variable)
944 then
945 -- A [generic] function is not allowed to have Output
946 -- items in its dependency relations. Note that "null"
947 -- and attribute 'Result are still valid items.
949 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
950 and then not Is_Input
951 then
952 SPARK_Msg_N
953 ("output item is not applicable to function", Item);
954 end if;
956 -- The item denotes a concurrent type. Note that single
957 -- protected/task types are not considered here because
958 -- they behave as objects in the context of pragma
959 -- [Refined_]Depends.
961 if Ekind_In (Item_Id, E_Protected_Type, E_Task_Type) then
963 -- This use is legal as long as the concurrent type is
964 -- the current instance of an enclosing type.
966 if Is_CCT_Instance (Item_Id, Spec_Id) then
968 -- The dependence of a task unit on itself is
969 -- implicit and may or may not be explicitly
970 -- specified (SPARK RM 6.1.4).
972 if Ekind (Item_Id) = E_Task_Type then
973 Current_Task_Instance_Seen;
974 end if;
976 -- Otherwise this is not the current instance
978 else
979 SPARK_Msg_N
980 ("invalid use of subtype mark in dependency "
981 & "relation", Item);
982 end if;
984 -- The dependency of a task unit on itself is implicit
985 -- and may or may not be explicitly specified
986 -- (SPARK RM 6.1.4).
988 elsif Is_Single_Task_Object (Item_Id)
989 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
990 then
991 Current_Task_Instance_Seen;
992 end if;
994 -- Ensure that the item fulfills its role as input and/or
995 -- output as specified by pragma Global or the enclosing
996 -- context.
998 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
1000 -- Detect multiple uses of the same state, variable or
1001 -- formal parameter. If this is not the case, add the
1002 -- item to the list of processed relations.
1004 if Contains (Seen, Item_Id) then
1005 SPARK_Msg_NE
1006 ("duplicate use of item &", Item, Item_Id);
1007 else
1008 Append_New_Elmt (Item_Id, Seen);
1009 end if;
1011 -- Detect illegal use of an input related to a null
1012 -- output. Such input items cannot appear in other
1013 -- input lists (SPARK RM 6.1.5(13)).
1015 if Is_Input
1016 and then Null_Output_Seen
1017 and then Contains (All_Inputs_Seen, Item_Id)
1018 then
1019 SPARK_Msg_N
1020 ("input of a null output list cannot appear in "
1021 & "multiple input lists", Item);
1022 end if;
1024 -- Add an input or a self-referential output to the list
1025 -- of all processed inputs.
1027 if Is_Input or else Self_Ref then
1028 Append_New_Elmt (Item_Id, All_Inputs_Seen);
1029 end if;
1031 -- State related checks (SPARK RM 6.1.5(3))
1033 if Ekind (Item_Id) = E_Abstract_State then
1035 -- Package and subprogram bodies are instantiated
1036 -- individually in a separate compiler pass. Due to
1037 -- this mode of instantiation, the refinement of a
1038 -- state may no longer be visible when a subprogram
1039 -- body contract is instantiated. Since the generic
1040 -- template is legal, do not perform this check in
1041 -- the instance to circumvent this oddity.
1043 if Is_Generic_Instance (Spec_Id) then
1044 null;
1046 -- An abstract state with visible refinement cannot
1047 -- appear in pragma [Refined_]Depends as its place
1048 -- must be taken by some of its constituents
1049 -- (SPARK RM 6.1.4(7)).
1051 elsif Has_Visible_Refinement (Item_Id) then
1052 SPARK_Msg_NE
1053 ("cannot mention state & in dependence relation",
1054 Item, Item_Id);
1055 SPARK_Msg_N ("\use its constituents instead", Item);
1056 return;
1058 -- If the reference to the abstract state appears in
1059 -- an enclosing package body that will eventually
1060 -- refine the state, record the reference for future
1061 -- checks.
1063 else
1064 Record_Possible_Body_Reference
1065 (State_Id => Item_Id,
1066 Ref => Item);
1067 end if;
1068 end if;
1070 -- When the item renames an entire object, replace the
1071 -- item with a reference to the object.
1073 if Entity (Item) /= Item_Id then
1074 Rewrite (Item,
1075 New_Occurrence_Of (Item_Id, Sloc (Item)));
1076 Analyze (Item);
1077 end if;
1079 -- Add the entity of the current item to the list of
1080 -- processed items.
1082 if Ekind (Item_Id) = E_Abstract_State then
1083 Append_New_Elmt (Item_Id, States_Seen);
1085 -- The variable may eventually become a constituent of a
1086 -- single protected/task type. Record the reference now
1087 -- and verify its legality when analyzing the contract of
1088 -- the variable (SPARK RM 9.3).
1090 elsif Ekind (Item_Id) = E_Variable then
1091 Record_Possible_Part_Of_Reference
1092 (Var_Id => Item_Id,
1093 Ref => Item);
1094 end if;
1096 if Ekind_In (Item_Id, E_Abstract_State,
1097 E_Constant,
1098 E_Variable)
1099 and then Present (Encapsulating_State (Item_Id))
1100 then
1101 Append_New_Elmt (Item_Id, Constits_Seen);
1102 end if;
1104 -- All other input/output items are illegal
1105 -- (SPARK RM 6.1.5(1)).
1107 else
1108 SPARK_Msg_N
1109 ("item must denote parameter, variable, state or "
1110 & "current instance of concurrent type", Item);
1111 end if;
1113 -- All other input/output items are illegal
1114 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1116 else
1117 Error_Msg_N
1118 ("item must denote parameter, variable, state or current "
1119 & "instance of concurrent type", Item);
1120 end if;
1121 end if;
1122 end Analyze_Input_Output;
1124 -- Local variables
1126 Inputs : Node_Id;
1127 Output : Node_Id;
1128 Self_Ref : Boolean;
1130 Non_Null_Output_Seen : Boolean := False;
1131 -- Flag used to check the legality of an output list
1133 -- Start of processing for Analyze_Dependency_Clause
1135 begin
1136 Inputs := Expression (Clause);
1137 Self_Ref := False;
1139 -- An input list with a self-dependency appears as operator "+" where
1140 -- the actuals inputs are the right operand.
1142 if Nkind (Inputs) = N_Op_Plus then
1143 Inputs := Right_Opnd (Inputs);
1144 Self_Ref := True;
1145 end if;
1147 -- Process the output_list of a dependency_clause
1149 Output := First (Choices (Clause));
1150 while Present (Output) loop
1151 Analyze_Input_Output
1152 (Item => Output,
1153 Is_Input => False,
1154 Self_Ref => Self_Ref,
1155 Top_Level => True,
1156 Seen => All_Outputs_Seen,
1157 Null_Seen => Null_Output_Seen,
1158 Non_Null_Seen => Non_Null_Output_Seen);
1160 Next (Output);
1161 end loop;
1163 -- Process the input_list of a dependency_clause
1165 Analyze_Input_List (Inputs);
1166 end Analyze_Dependency_Clause;
1168 ---------------------------
1169 -- Check_Function_Return --
1170 ---------------------------
1172 procedure Check_Function_Return is
1173 begin
1174 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
1175 and then not Result_Seen
1176 then
1177 SPARK_Msg_NE
1178 ("result of & must appear in exactly one output list",
1179 N, Spec_Id);
1180 end if;
1181 end Check_Function_Return;
1183 ----------------
1184 -- Check_Role --
1185 ----------------
1187 procedure Check_Role
1188 (Item : Node_Id;
1189 Item_Id : Entity_Id;
1190 Is_Input : Boolean;
1191 Self_Ref : Boolean)
1193 procedure Find_Role
1194 (Item_Is_Input : out Boolean;
1195 Item_Is_Output : out Boolean);
1196 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1197 -- Item_Is_Output are set depending on the role.
1199 procedure Role_Error
1200 (Item_Is_Input : Boolean;
1201 Item_Is_Output : Boolean);
1202 -- Emit an error message concerning the incorrect use of Item in
1203 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1204 -- denote whether the item is an input and/or an output.
1206 ---------------
1207 -- Find_Role --
1208 ---------------
1210 procedure Find_Role
1211 (Item_Is_Input : out Boolean;
1212 Item_Is_Output : out Boolean)
1214 begin
1215 case Ekind (Item_Id) is
1217 -- Abstract states
1219 when E_Abstract_State =>
1221 -- When pragma Global is present it determines the mode of
1222 -- the abstract state.
1224 if Global_Seen then
1225 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1226 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1228 -- Otherwise the state has a default IN OUT mode, because it
1229 -- behaves as a variable.
1231 else
1232 Item_Is_Input := True;
1233 Item_Is_Output := True;
1234 end if;
1236 -- Constants and IN parameters
1238 when E_Constant
1239 | E_Generic_In_Parameter
1240 | E_In_Parameter
1241 | E_Loop_Parameter
1243 -- When pragma Global is present it determines the mode
1244 -- of constant objects as inputs (and such objects cannot
1245 -- appear as outputs in the Global contract).
1247 if Global_Seen then
1248 Item_Is_Input := Appears_In (Subp_Inputs, Item_Id);
1249 else
1250 Item_Is_Input := True;
1251 end if;
1253 Item_Is_Output := False;
1255 -- Variables and IN OUT parameters
1257 when E_Generic_In_Out_Parameter
1258 | E_In_Out_Parameter
1259 | E_Variable
1261 -- When pragma Global is present it determines the mode of
1262 -- the object.
1264 if Global_Seen then
1266 -- A variable has mode IN when its type is unconstrained
1267 -- or tagged because array bounds, discriminants or tags
1268 -- can be read.
1270 Item_Is_Input :=
1271 Appears_In (Subp_Inputs, Item_Id)
1272 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1274 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1276 -- Otherwise the variable has a default IN OUT mode
1278 else
1279 Item_Is_Input := True;
1280 Item_Is_Output := True;
1281 end if;
1283 when E_Out_Parameter =>
1285 -- An OUT parameter of the related subprogram; it cannot
1286 -- appear in Global.
1288 if Scope (Item_Id) = Spec_Id then
1290 -- The parameter has mode IN if its type is unconstrained
1291 -- or tagged because array bounds, discriminants or tags
1292 -- can be read.
1294 Item_Is_Input :=
1295 Is_Unconstrained_Or_Tagged_Item (Item_Id);
1297 Item_Is_Output := True;
1299 -- An OUT parameter of an enclosing subprogram; it can
1300 -- appear in Global and behaves as a read-write variable.
1302 else
1303 -- When pragma Global is present it determines the mode
1304 -- of the object.
1306 if Global_Seen then
1308 -- A variable has mode IN when its type is
1309 -- unconstrained or tagged because array
1310 -- bounds, discriminants or tags can be read.
1312 Item_Is_Input :=
1313 Appears_In (Subp_Inputs, Item_Id)
1314 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1316 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1318 -- Otherwise the variable has a default IN OUT mode
1320 else
1321 Item_Is_Input := True;
1322 Item_Is_Output := True;
1323 end if;
1324 end if;
1326 -- Protected types
1328 when E_Protected_Type =>
1329 if Global_Seen then
1331 -- A variable has mode IN when its type is unconstrained
1332 -- or tagged because array bounds, discriminants or tags
1333 -- can be read.
1335 Item_Is_Input :=
1336 Appears_In (Subp_Inputs, Item_Id)
1337 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1339 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1341 else
1342 -- A protected type acts as a formal parameter of mode IN
1343 -- when it applies to a protected function.
1345 if Ekind (Spec_Id) = E_Function then
1346 Item_Is_Input := True;
1347 Item_Is_Output := False;
1349 -- Otherwise the protected type acts as a formal of mode
1350 -- IN OUT.
1352 else
1353 Item_Is_Input := True;
1354 Item_Is_Output := True;
1355 end if;
1356 end if;
1358 -- Task types
1360 when E_Task_Type =>
1362 -- When pragma Global is present it determines the mode of
1363 -- the object.
1365 if Global_Seen then
1366 Item_Is_Input :=
1367 Appears_In (Subp_Inputs, Item_Id)
1368 or else Is_Unconstrained_Or_Tagged_Item (Item_Id);
1370 Item_Is_Output := Appears_In (Subp_Outputs, Item_Id);
1372 -- Otherwise task types act as IN OUT parameters
1374 else
1375 Item_Is_Input := True;
1376 Item_Is_Output := True;
1377 end if;
1379 when others =>
1380 raise Program_Error;
1381 end case;
1382 end Find_Role;
1384 ----------------
1385 -- Role_Error --
1386 ----------------
1388 procedure Role_Error
1389 (Item_Is_Input : Boolean;
1390 Item_Is_Output : Boolean)
1392 Error_Msg : Name_Id;
1394 begin
1395 Name_Len := 0;
1397 -- When the item is not part of the input and the output set of
1398 -- the related subprogram, then it appears as extra in pragma
1399 -- [Refined_]Depends.
1401 if not Item_Is_Input and then not Item_Is_Output then
1402 Add_Item_To_Name_Buffer (Item_Id);
1403 Add_Str_To_Name_Buffer
1404 (" & cannot appear in dependence relation");
1406 Error_Msg := Name_Find;
1407 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1409 Error_Msg_Name_1 := Chars (Spec_Id);
1410 SPARK_Msg_NE
1411 (Fix_Msg (Spec_Id, "\& is not part of the input or output "
1412 & "set of subprogram %"), Item, Item_Id);
1414 -- The mode of the item and its role in pragma [Refined_]Depends
1415 -- are in conflict. Construct a detailed message explaining the
1416 -- illegality (SPARK RM 6.1.5(5-6)).
1418 else
1419 if Item_Is_Input then
1420 Add_Str_To_Name_Buffer ("read-only");
1421 else
1422 Add_Str_To_Name_Buffer ("write-only");
1423 end if;
1425 Add_Char_To_Name_Buffer (' ');
1426 Add_Item_To_Name_Buffer (Item_Id);
1427 Add_Str_To_Name_Buffer (" & cannot appear as ");
1429 if Item_Is_Input then
1430 Add_Str_To_Name_Buffer ("output");
1431 else
1432 Add_Str_To_Name_Buffer ("input");
1433 end if;
1435 Add_Str_To_Name_Buffer (" in dependence relation");
1436 Error_Msg := Name_Find;
1437 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1438 end if;
1439 end Role_Error;
1441 -- Local variables
1443 Item_Is_Input : Boolean;
1444 Item_Is_Output : Boolean;
1446 -- Start of processing for Check_Role
1448 begin
1449 Find_Role (Item_Is_Input, Item_Is_Output);
1451 -- Input item
1453 if Is_Input then
1454 if not Item_Is_Input then
1455 Role_Error (Item_Is_Input, Item_Is_Output);
1456 end if;
1458 -- Self-referential item
1460 elsif Self_Ref then
1461 if not Item_Is_Input or else not Item_Is_Output then
1462 Role_Error (Item_Is_Input, Item_Is_Output);
1463 end if;
1465 -- Output item
1467 elsif not Item_Is_Output then
1468 Role_Error (Item_Is_Input, Item_Is_Output);
1469 end if;
1470 end Check_Role;
1472 -----------------
1473 -- Check_Usage --
1474 -----------------
1476 procedure Check_Usage
1477 (Subp_Items : Elist_Id;
1478 Used_Items : Elist_Id;
1479 Is_Input : Boolean)
1481 procedure Usage_Error (Item_Id : Entity_Id);
1482 -- Emit an error concerning the illegal usage of an item
1484 -----------------
1485 -- Usage_Error --
1486 -----------------
1488 procedure Usage_Error (Item_Id : Entity_Id) is
1489 Error_Msg : Name_Id;
1491 begin
1492 -- Input case
1494 if Is_Input then
1496 -- Unconstrained and tagged items are not part of the explicit
1497 -- input set of the related subprogram, they do not have to be
1498 -- present in a dependence relation and should not be flagged
1499 -- (SPARK RM 6.1.5(5)).
1501 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1502 Name_Len := 0;
1504 Add_Item_To_Name_Buffer (Item_Id);
1505 Add_Str_To_Name_Buffer
1506 (" & is missing from input dependence list");
1508 Error_Msg := Name_Find;
1509 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1510 SPARK_Msg_NE
1511 ("\add `null ='> &` dependency to ignore this input",
1512 N, Item_Id);
1513 end if;
1515 -- Output case (SPARK RM 6.1.5(10))
1517 else
1518 Name_Len := 0;
1520 Add_Item_To_Name_Buffer (Item_Id);
1521 Add_Str_To_Name_Buffer
1522 (" & is missing from output dependence list");
1524 Error_Msg := Name_Find;
1525 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1526 end if;
1527 end Usage_Error;
1529 -- Local variables
1531 Elmt : Elmt_Id;
1532 Item : Node_Id;
1533 Item_Id : Entity_Id;
1535 -- Start of processing for Check_Usage
1537 begin
1538 if No (Subp_Items) then
1539 return;
1540 end if;
1542 -- Each input or output of the subprogram must appear in a dependency
1543 -- relation.
1545 Elmt := First_Elmt (Subp_Items);
1546 while Present (Elmt) loop
1547 Item := Node (Elmt);
1549 if Nkind (Item) = N_Defining_Identifier then
1550 Item_Id := Item;
1551 else
1552 Item_Id := Entity_Of (Item);
1553 end if;
1555 -- The item does not appear in a dependency
1557 if Present (Item_Id)
1558 and then not Contains (Used_Items, Item_Id)
1559 then
1560 if Is_Formal (Item_Id) then
1561 Usage_Error (Item_Id);
1563 -- The current instance of a protected type behaves as a formal
1564 -- parameter (SPARK RM 6.1.4).
1566 elsif Ekind (Item_Id) = E_Protected_Type
1567 or else Is_Single_Protected_Object (Item_Id)
1568 then
1569 Usage_Error (Item_Id);
1571 -- The current instance of a task type behaves as a formal
1572 -- parameter (SPARK RM 6.1.4).
1574 elsif Ekind (Item_Id) = E_Task_Type
1575 or else Is_Single_Task_Object (Item_Id)
1576 then
1577 -- The dependence of a task unit on itself is implicit and
1578 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1579 -- Emit an error if only one input/output is present.
1581 if Task_Input_Seen /= Task_Output_Seen then
1582 Usage_Error (Item_Id);
1583 end if;
1585 -- States and global objects are not used properly only when
1586 -- the subprogram is subject to pragma Global.
1588 elsif Global_Seen then
1589 Usage_Error (Item_Id);
1590 end if;
1591 end if;
1593 Next_Elmt (Elmt);
1594 end loop;
1595 end Check_Usage;
1597 ----------------------
1598 -- Normalize_Clause --
1599 ----------------------
1601 procedure Normalize_Clause (Clause : Node_Id) is
1602 procedure Create_Or_Modify_Clause
1603 (Output : Node_Id;
1604 Outputs : Node_Id;
1605 Inputs : Node_Id;
1606 After : Node_Id;
1607 In_Place : Boolean;
1608 Multiple : Boolean);
1609 -- Create a brand new clause to represent the self-reference or
1610 -- modify the input and/or output lists of an existing clause. Output
1611 -- denotes a self-referencial output. Outputs is the output list of a
1612 -- clause. Inputs is the input list of a clause. After denotes the
1613 -- clause after which the new clause is to be inserted. Flag In_Place
1614 -- should be set when normalizing the last output of an output list.
1615 -- Flag Multiple should be set when Output comes from a list with
1616 -- multiple items.
1618 -----------------------------
1619 -- Create_Or_Modify_Clause --
1620 -----------------------------
1622 procedure Create_Or_Modify_Clause
1623 (Output : Node_Id;
1624 Outputs : Node_Id;
1625 Inputs : Node_Id;
1626 After : Node_Id;
1627 In_Place : Boolean;
1628 Multiple : Boolean)
1630 procedure Propagate_Output
1631 (Output : Node_Id;
1632 Inputs : Node_Id);
1633 -- Handle the various cases of output propagation to the input
1634 -- list. Output denotes a self-referencial output item. Inputs
1635 -- is the input list of a clause.
1637 ----------------------
1638 -- Propagate_Output --
1639 ----------------------
1641 procedure Propagate_Output
1642 (Output : Node_Id;
1643 Inputs : Node_Id)
1645 function In_Input_List
1646 (Item : Entity_Id;
1647 Inputs : List_Id) return Boolean;
1648 -- Determine whether a particulat item appears in the input
1649 -- list of a clause.
1651 -------------------
1652 -- In_Input_List --
1653 -------------------
1655 function In_Input_List
1656 (Item : Entity_Id;
1657 Inputs : List_Id) return Boolean
1659 Elmt : Node_Id;
1661 begin
1662 Elmt := First (Inputs);
1663 while Present (Elmt) loop
1664 if Entity_Of (Elmt) = Item then
1665 return True;
1666 end if;
1668 Next (Elmt);
1669 end loop;
1671 return False;
1672 end In_Input_List;
1674 -- Local variables
1676 Output_Id : constant Entity_Id := Entity_Of (Output);
1677 Grouped : List_Id;
1679 -- Start of processing for Propagate_Output
1681 begin
1682 -- The clause is of the form:
1684 -- (Output =>+ null)
1686 -- Remove null input and replace it with a copy of the output:
1688 -- (Output => Output)
1690 if Nkind (Inputs) = N_Null then
1691 Rewrite (Inputs, New_Copy_Tree (Output));
1693 -- The clause is of the form:
1695 -- (Output =>+ (Input1, ..., InputN))
1697 -- Determine whether the output is not already mentioned in the
1698 -- input list and if not, add it to the list of inputs:
1700 -- (Output => (Output, Input1, ..., InputN))
1702 elsif Nkind (Inputs) = N_Aggregate then
1703 Grouped := Expressions (Inputs);
1705 if not In_Input_List
1706 (Item => Output_Id,
1707 Inputs => Grouped)
1708 then
1709 Prepend_To (Grouped, New_Copy_Tree (Output));
1710 end if;
1712 -- The clause is of the form:
1714 -- (Output =>+ Input)
1716 -- If the input does not mention the output, group the two
1717 -- together:
1719 -- (Output => (Output, Input))
1721 elsif Entity_Of (Inputs) /= Output_Id then
1722 Rewrite (Inputs,
1723 Make_Aggregate (Loc,
1724 Expressions => New_List (
1725 New_Copy_Tree (Output),
1726 New_Copy_Tree (Inputs))));
1727 end if;
1728 end Propagate_Output;
1730 -- Local variables
1732 Loc : constant Source_Ptr := Sloc (Clause);
1733 New_Clause : Node_Id;
1735 -- Start of processing for Create_Or_Modify_Clause
1737 begin
1738 -- A null output depending on itself does not require any
1739 -- normalization.
1741 if Nkind (Output) = N_Null then
1742 return;
1744 -- A function result cannot depend on itself because it cannot
1745 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1747 elsif Is_Attribute_Result (Output) then
1748 SPARK_Msg_N ("function result cannot depend on itself", Output);
1749 return;
1750 end if;
1752 -- When performing the transformation in place, simply add the
1753 -- output to the list of inputs (if not already there). This
1754 -- case arises when dealing with the last output of an output
1755 -- list. Perform the normalization in place to avoid generating
1756 -- a malformed tree.
1758 if In_Place then
1759 Propagate_Output (Output, Inputs);
1761 -- A list with multiple outputs is slowly trimmed until only
1762 -- one element remains. When this happens, replace aggregate
1763 -- with the element itself.
1765 if Multiple then
1766 Remove (Output);
1767 Rewrite (Outputs, Output);
1768 end if;
1770 -- Default case
1772 else
1773 -- Unchain the output from its output list as it will appear in
1774 -- a new clause. Note that we cannot simply rewrite the output
1775 -- as null because this will violate the semantics of pragma
1776 -- Depends.
1778 Remove (Output);
1780 -- Generate a new clause of the form:
1781 -- (Output => Inputs)
1783 New_Clause :=
1784 Make_Component_Association (Loc,
1785 Choices => New_List (Output),
1786 Expression => New_Copy_Tree (Inputs));
1788 -- The new clause contains replicated content that has already
1789 -- been analyzed. There is not need to reanalyze or renormalize
1790 -- it again.
1792 Set_Analyzed (New_Clause);
1794 Propagate_Output
1795 (Output => First (Choices (New_Clause)),
1796 Inputs => Expression (New_Clause));
1798 Insert_After (After, New_Clause);
1799 end if;
1800 end Create_Or_Modify_Clause;
1802 -- Local variables
1804 Outputs : constant Node_Id := First (Choices (Clause));
1805 Inputs : Node_Id;
1806 Last_Output : Node_Id;
1807 Next_Output : Node_Id;
1808 Output : Node_Id;
1810 -- Start of processing for Normalize_Clause
1812 begin
1813 -- A self-dependency appears as operator "+". Remove the "+" from the
1814 -- tree by moving the real inputs to their proper place.
1816 if Nkind (Expression (Clause)) = N_Op_Plus then
1817 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1818 Inputs := Expression (Clause);
1820 -- Multiple outputs appear as an aggregate
1822 if Nkind (Outputs) = N_Aggregate then
1823 Last_Output := Last (Expressions (Outputs));
1825 Output := First (Expressions (Outputs));
1826 while Present (Output) loop
1828 -- Normalization may remove an output from its list,
1829 -- preserve the subsequent output now.
1831 Next_Output := Next (Output);
1833 Create_Or_Modify_Clause
1834 (Output => Output,
1835 Outputs => Outputs,
1836 Inputs => Inputs,
1837 After => Clause,
1838 In_Place => Output = Last_Output,
1839 Multiple => True);
1841 Output := Next_Output;
1842 end loop;
1844 -- Solitary output
1846 else
1847 Create_Or_Modify_Clause
1848 (Output => Outputs,
1849 Outputs => Empty,
1850 Inputs => Inputs,
1851 After => Empty,
1852 In_Place => True,
1853 Multiple => False);
1854 end if;
1855 end if;
1856 end Normalize_Clause;
1858 -- Local variables
1860 Deps : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
1861 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
1863 Clause : Node_Id;
1864 Errors : Nat;
1865 Last_Clause : Node_Id;
1866 Restore_Scope : Boolean := False;
1868 -- Start of processing for Analyze_Depends_In_Decl_Part
1870 begin
1871 -- Do not analyze the pragma multiple times
1873 if Is_Analyzed_Pragma (N) then
1874 return;
1875 end if;
1877 -- Empty dependency list
1879 if Nkind (Deps) = N_Null then
1881 -- Gather all states, objects and formal parameters that the
1882 -- subprogram may depend on. These items are obtained from the
1883 -- parameter profile or pragma [Refined_]Global (if available).
1885 Collect_Subprogram_Inputs_Outputs
1886 (Subp_Id => Subp_Id,
1887 Subp_Inputs => Subp_Inputs,
1888 Subp_Outputs => Subp_Outputs,
1889 Global_Seen => Global_Seen);
1891 -- Verify that every input or output of the subprogram appear in a
1892 -- dependency.
1894 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1895 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1896 Check_Function_Return;
1898 -- Dependency clauses appear as component associations of an aggregate
1900 elsif Nkind (Deps) = N_Aggregate then
1902 -- Do not attempt to perform analysis of a syntactically illegal
1903 -- clause as this will lead to misleading errors.
1905 if Has_Extra_Parentheses (Deps) then
1906 return;
1907 end if;
1909 if Present (Component_Associations (Deps)) then
1910 Last_Clause := Last (Component_Associations (Deps));
1912 -- Gather all states, objects and formal parameters that the
1913 -- subprogram may depend on. These items are obtained from the
1914 -- parameter profile or pragma [Refined_]Global (if available).
1916 Collect_Subprogram_Inputs_Outputs
1917 (Subp_Id => Subp_Id,
1918 Subp_Inputs => Subp_Inputs,
1919 Subp_Outputs => Subp_Outputs,
1920 Global_Seen => Global_Seen);
1922 -- When pragma [Refined_]Depends appears on a single concurrent
1923 -- type, it is relocated to the anonymous object.
1925 if Is_Single_Concurrent_Object (Spec_Id) then
1926 null;
1928 -- Ensure that the formal parameters are visible when analyzing
1929 -- all clauses. This falls out of the general rule of aspects
1930 -- pertaining to subprogram declarations.
1932 elsif not In_Open_Scopes (Spec_Id) then
1933 Restore_Scope := True;
1934 Push_Scope (Spec_Id);
1936 if Ekind (Spec_Id) = E_Task_Type then
1937 if Has_Discriminants (Spec_Id) then
1938 Install_Discriminants (Spec_Id);
1939 end if;
1941 elsif Is_Generic_Subprogram (Spec_Id) then
1942 Install_Generic_Formals (Spec_Id);
1944 else
1945 Install_Formals (Spec_Id);
1946 end if;
1947 end if;
1949 Clause := First (Component_Associations (Deps));
1950 while Present (Clause) loop
1951 Errors := Serious_Errors_Detected;
1953 -- The normalization mechanism may create extra clauses that
1954 -- contain replicated input and output names. There is no need
1955 -- to reanalyze them.
1957 if not Analyzed (Clause) then
1958 Set_Analyzed (Clause);
1960 Analyze_Dependency_Clause
1961 (Clause => Clause,
1962 Is_Last => Clause = Last_Clause);
1963 end if;
1965 -- Do not normalize a clause if errors were detected (count
1966 -- of Serious_Errors has increased) because the inputs and/or
1967 -- outputs may denote illegal items. Normalization is disabled
1968 -- in ASIS mode as it alters the tree by introducing new nodes
1969 -- similar to expansion.
1971 if Serious_Errors_Detected = Errors and then not ASIS_Mode then
1972 Normalize_Clause (Clause);
1973 end if;
1975 Next (Clause);
1976 end loop;
1978 if Restore_Scope then
1979 End_Scope;
1980 end if;
1982 -- Verify that every input or output of the subprogram appear in a
1983 -- dependency.
1985 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1986 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1987 Check_Function_Return;
1989 -- The dependency list is malformed. This is a syntax error, always
1990 -- report.
1992 else
1993 Error_Msg_N ("malformed dependency relation", Deps);
1994 return;
1995 end if;
1997 -- The top level dependency relation is malformed. This is a syntax
1998 -- error, always report.
2000 else
2001 Error_Msg_N ("malformed dependency relation", Deps);
2002 goto Leave;
2003 end if;
2005 -- Ensure that a state and a corresponding constituent do not appear
2006 -- together in pragma [Refined_]Depends.
2008 Check_State_And_Constituent_Use
2009 (States => States_Seen,
2010 Constits => Constits_Seen,
2011 Context => N);
2013 <<Leave>>
2014 Set_Is_Analyzed_Pragma (N);
2015 end Analyze_Depends_In_Decl_Part;
2017 --------------------------------------------
2018 -- Analyze_External_Property_In_Decl_Part --
2019 --------------------------------------------
2021 procedure Analyze_External_Property_In_Decl_Part
2022 (N : Node_Id;
2023 Expr_Val : out Boolean)
2025 Arg1 : constant Node_Id :=
2026 First (Pragma_Argument_Associations (N));
2027 Obj_Decl : constant Node_Id := Find_Related_Context (N);
2028 Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl);
2029 Expr : Node_Id;
2031 begin
2032 Expr_Val := False;
2034 -- Do not analyze the pragma multiple times
2036 if Is_Analyzed_Pragma (N) then
2037 return;
2038 end if;
2040 Error_Msg_Name_1 := Pragma_Name (N);
2042 -- An external property pragma must apply to an effectively volatile
2043 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
2044 -- The check is performed at the end of the declarative region due to a
2045 -- possible out-of-order arrangement of pragmas:
2047 -- Obj : ...;
2048 -- pragma Async_Readers (Obj);
2049 -- pragma Volatile (Obj);
2051 if not Is_Effectively_Volatile (Obj_Id) then
2052 SPARK_Msg_N
2053 ("external property % must apply to a volatile object", N);
2054 end if;
2056 -- Ensure that the Boolean expression (if present) is static. A missing
2057 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
2059 Expr_Val := True;
2061 if Present (Arg1) then
2062 Expr := Get_Pragma_Arg (Arg1);
2064 if Is_OK_Static_Expression (Expr) then
2065 Expr_Val := Is_True (Expr_Value (Expr));
2066 end if;
2067 end if;
2069 Set_Is_Analyzed_Pragma (N);
2070 end Analyze_External_Property_In_Decl_Part;
2072 ---------------------------------
2073 -- Analyze_Global_In_Decl_Part --
2074 ---------------------------------
2076 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
2077 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
2078 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
2079 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
2081 Constits_Seen : Elist_Id := No_Elist;
2082 -- A list containing the entities of all constituents processed so far.
2083 -- It aids in detecting illegal usage of a state and a corresponding
2084 -- constituent in pragma [Refinde_]Global.
2086 Seen : Elist_Id := No_Elist;
2087 -- A list containing the entities of all the items processed so far. It
2088 -- plays a role in detecting distinct entities.
2090 States_Seen : Elist_Id := No_Elist;
2091 -- A list containing the entities of all states processed so far. It
2092 -- helps in detecting illegal usage of a state and a corresponding
2093 -- constituent in pragma [Refined_]Global.
2095 In_Out_Seen : Boolean := False;
2096 Input_Seen : Boolean := False;
2097 Output_Seen : Boolean := False;
2098 Proof_Seen : Boolean := False;
2099 -- Flags used to verify the consistency of modes
2101 procedure Analyze_Global_List
2102 (List : Node_Id;
2103 Global_Mode : Name_Id := Name_Input);
2104 -- Verify the legality of a single global list declaration. Global_Mode
2105 -- denotes the current mode in effect.
2107 -------------------------
2108 -- Analyze_Global_List --
2109 -------------------------
2111 procedure Analyze_Global_List
2112 (List : Node_Id;
2113 Global_Mode : Name_Id := Name_Input)
2115 procedure Analyze_Global_Item
2116 (Item : Node_Id;
2117 Global_Mode : Name_Id);
2118 -- Verify the legality of a single global item declaration denoted by
2119 -- Item. Global_Mode denotes the current mode in effect.
2121 procedure Check_Duplicate_Mode
2122 (Mode : Node_Id;
2123 Status : in out Boolean);
2124 -- Flag Status denotes whether a particular mode has been seen while
2125 -- processing a global list. This routine verifies that Mode is not a
2126 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2128 procedure Check_Mode_Restriction_In_Enclosing_Context
2129 (Item : Node_Id;
2130 Item_Id : Entity_Id);
2131 -- Verify that an item of mode In_Out or Output does not appear as
2132 -- an input in the Global aspect of an enclosing subprogram or task
2133 -- unit. If this is the case, emit an error. Item and Item_Id are
2134 -- respectively the item and its entity.
2136 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
2137 -- Mode denotes either In_Out or Output. Depending on the kind of the
2138 -- related subprogram, emit an error if those two modes apply to a
2139 -- function (SPARK RM 6.1.4(10)).
2141 -------------------------
2142 -- Analyze_Global_Item --
2143 -------------------------
2145 procedure Analyze_Global_Item
2146 (Item : Node_Id;
2147 Global_Mode : Name_Id)
2149 Item_Id : Entity_Id;
2151 begin
2152 -- Detect one of the following cases
2154 -- with Global => (null, Name)
2155 -- with Global => (Name_1, null, Name_2)
2156 -- with Global => (Name, null)
2158 if Nkind (Item) = N_Null then
2159 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
2160 return;
2161 end if;
2163 Analyze (Item);
2164 Resolve_State (Item);
2166 -- Find the entity of the item. If this is a renaming, climb the
2167 -- renaming chain to reach the root object. Renamings of non-
2168 -- entire objects do not yield an entity (Empty).
2170 Item_Id := Entity_Of (Item);
2172 if Present (Item_Id) then
2174 -- A global item may denote a formal parameter of an enclosing
2175 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2176 -- provide a better error diagnostic.
2178 if Is_Formal (Item_Id) then
2179 if Scope (Item_Id) = Spec_Id then
2180 SPARK_Msg_NE
2181 (Fix_Msg (Spec_Id, "global item cannot reference "
2182 & "parameter of subprogram &"), Item, Spec_Id);
2183 return;
2184 end if;
2186 -- A global item may denote a concurrent type as long as it is
2187 -- the current instance of an enclosing protected or task type
2188 -- (SPARK RM 6.1.4).
2190 elsif Ekind_In (Item_Id, E_Protected_Type, E_Task_Type) then
2191 if Is_CCT_Instance (Item_Id, Spec_Id) then
2193 -- Pragma [Refined_]Global associated with a protected
2194 -- subprogram cannot mention the current instance of a
2195 -- protected type because the instance behaves as a
2196 -- formal parameter.
2198 if Ekind (Item_Id) = E_Protected_Type then
2199 if Scope (Spec_Id) = Item_Id then
2200 Error_Msg_Name_1 := Chars (Item_Id);
2201 SPARK_Msg_NE
2202 (Fix_Msg (Spec_Id, "global item of subprogram & "
2203 & "cannot reference current instance of "
2204 & "protected type %"), Item, Spec_Id);
2205 return;
2206 end if;
2208 -- Pragma [Refined_]Global associated with a task type
2209 -- cannot mention the current instance of a task type
2210 -- because the instance behaves as a formal parameter.
2212 else pragma Assert (Ekind (Item_Id) = E_Task_Type);
2213 if Spec_Id = Item_Id then
2214 Error_Msg_Name_1 := Chars (Item_Id);
2215 SPARK_Msg_NE
2216 (Fix_Msg (Spec_Id, "global item of subprogram & "
2217 & "cannot reference current instance of task "
2218 & "type %"), Item, Spec_Id);
2219 return;
2220 end if;
2221 end if;
2223 -- Otherwise the global item denotes a subtype mark that is
2224 -- not a current instance.
2226 else
2227 SPARK_Msg_N
2228 ("invalid use of subtype mark in global list", Item);
2229 return;
2230 end if;
2232 -- A global item may denote the anonymous object created for a
2233 -- single protected/task type as long as the current instance
2234 -- is the same single type (SPARK RM 6.1.4).
2236 elsif Is_Single_Concurrent_Object (Item_Id)
2237 and then Is_CCT_Instance (Etype (Item_Id), Spec_Id)
2238 then
2239 -- Pragma [Refined_]Global associated with a protected
2240 -- subprogram cannot mention the current instance of a
2241 -- protected type because the instance behaves as a formal
2242 -- parameter.
2244 if Is_Single_Protected_Object (Item_Id) then
2245 if Scope (Spec_Id) = Etype (Item_Id) then
2246 Error_Msg_Name_1 := Chars (Item_Id);
2247 SPARK_Msg_NE
2248 (Fix_Msg (Spec_Id, "global item of subprogram & "
2249 & "cannot reference current instance of protected "
2250 & "type %"), Item, Spec_Id);
2251 return;
2252 end if;
2254 -- Pragma [Refined_]Global associated with a task type
2255 -- cannot mention the current instance of a task type
2256 -- because the instance behaves as a formal parameter.
2258 else pragma Assert (Is_Single_Task_Object (Item_Id));
2259 if Spec_Id = Item_Id then
2260 Error_Msg_Name_1 := Chars (Item_Id);
2261 SPARK_Msg_NE
2262 (Fix_Msg (Spec_Id, "global item of subprogram & "
2263 & "cannot reference current instance of task "
2264 & "type %"), Item, Spec_Id);
2265 return;
2266 end if;
2267 end if;
2269 -- A formal object may act as a global item inside a generic
2271 elsif Is_Formal_Object (Item_Id) then
2272 null;
2274 -- The only legal references are those to abstract states,
2275 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2277 elsif not Ekind_In (Item_Id, E_Abstract_State,
2278 E_Constant,
2279 E_Loop_Parameter,
2280 E_Variable)
2281 then
2282 SPARK_Msg_N
2283 ("global item must denote object, state or current "
2284 & "instance of concurrent type", Item);
2285 return;
2286 end if;
2288 -- State related checks
2290 if Ekind (Item_Id) = E_Abstract_State then
2292 -- Package and subprogram bodies are instantiated
2293 -- individually in a separate compiler pass. Due to this
2294 -- mode of instantiation, the refinement of a state may
2295 -- no longer be visible when a subprogram body contract
2296 -- is instantiated. Since the generic template is legal,
2297 -- do not perform this check in the instance to circumvent
2298 -- this oddity.
2300 if Is_Generic_Instance (Spec_Id) then
2301 null;
2303 -- An abstract state with visible refinement cannot appear
2304 -- in pragma [Refined_]Global as its place must be taken by
2305 -- some of its constituents (SPARK RM 6.1.4(7)).
2307 elsif Has_Visible_Refinement (Item_Id) then
2308 SPARK_Msg_NE
2309 ("cannot mention state & in global refinement",
2310 Item, Item_Id);
2311 SPARK_Msg_N ("\use its constituents instead", Item);
2312 return;
2314 -- An external state cannot appear as a global item of a
2315 -- nonvolatile function (SPARK RM 7.1.3(8)).
2317 elsif Is_External_State (Item_Id)
2318 and then Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2319 and then not Is_Volatile_Function (Spec_Id)
2320 then
2321 SPARK_Msg_NE
2322 ("external state & cannot act as global item of "
2323 & "nonvolatile function", Item, Item_Id);
2324 return;
2326 -- If the reference to the abstract state appears in an
2327 -- enclosing package body that will eventually refine the
2328 -- state, record the reference for future checks.
2330 else
2331 Record_Possible_Body_Reference
2332 (State_Id => Item_Id,
2333 Ref => Item);
2334 end if;
2336 -- Constant related checks
2338 elsif Ekind (Item_Id) = E_Constant then
2340 -- A constant is a read-only item, therefore it cannot act
2341 -- as an output.
2343 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2344 SPARK_Msg_NE
2345 ("constant & cannot act as output", Item, Item_Id);
2346 return;
2347 end if;
2349 -- Loop parameter related checks
2351 elsif Ekind (Item_Id) = E_Loop_Parameter then
2353 -- A loop parameter is a read-only item, therefore it cannot
2354 -- act as an output.
2356 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2357 SPARK_Msg_NE
2358 ("loop parameter & cannot act as output",
2359 Item, Item_Id);
2360 return;
2361 end if;
2363 -- Variable related checks. These are only relevant when
2364 -- SPARK_Mode is on as they are not standard Ada legality
2365 -- rules.
2367 elsif SPARK_Mode = On
2368 and then Ekind (Item_Id) = E_Variable
2369 and then Is_Effectively_Volatile (Item_Id)
2370 then
2371 -- An effectively volatile object cannot appear as a global
2372 -- item of a nonvolatile function (SPARK RM 7.1.3(8)).
2374 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2375 and then not Is_Volatile_Function (Spec_Id)
2376 then
2377 Error_Msg_NE
2378 ("volatile object & cannot act as global item of a "
2379 & "function", Item, Item_Id);
2380 return;
2382 -- An effectively volatile object with external property
2383 -- Effective_Reads set to True must have mode Output or
2384 -- In_Out (SPARK RM 7.1.3(10)).
2386 elsif Effective_Reads_Enabled (Item_Id)
2387 and then Global_Mode = Name_Input
2388 then
2389 Error_Msg_NE
2390 ("volatile object & with property Effective_Reads must "
2391 & "have mode In_Out or Output", Item, Item_Id);
2392 return;
2393 end if;
2394 end if;
2396 -- When the item renames an entire object, replace the item
2397 -- with a reference to the object.
2399 if Entity (Item) /= Item_Id then
2400 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2401 Analyze (Item);
2402 end if;
2404 -- Some form of illegal construct masquerading as a name
2405 -- (SPARK RM 6.1.4(4)).
2407 else
2408 Error_Msg_N
2409 ("global item must denote object, state or current instance "
2410 & "of concurrent type", Item);
2411 return;
2412 end if;
2414 -- Verify that an output does not appear as an input in an
2415 -- enclosing subprogram.
2417 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2418 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
2419 end if;
2421 -- The same entity might be referenced through various way.
2422 -- Check the entity of the item rather than the item itself
2423 -- (SPARK RM 6.1.4(10)).
2425 if Contains (Seen, Item_Id) then
2426 SPARK_Msg_N ("duplicate global item", Item);
2428 -- Add the entity of the current item to the list of processed
2429 -- items.
2431 else
2432 Append_New_Elmt (Item_Id, Seen);
2434 if Ekind (Item_Id) = E_Abstract_State then
2435 Append_New_Elmt (Item_Id, States_Seen);
2437 -- The variable may eventually become a constituent of a single
2438 -- protected/task type. Record the reference now and verify its
2439 -- legality when analyzing the contract of the variable
2440 -- (SPARK RM 9.3).
2442 elsif Ekind (Item_Id) = E_Variable then
2443 Record_Possible_Part_Of_Reference
2444 (Var_Id => Item_Id,
2445 Ref => Item);
2446 end if;
2448 if Ekind_In (Item_Id, E_Abstract_State, E_Constant, E_Variable)
2449 and then Present (Encapsulating_State (Item_Id))
2450 then
2451 Append_New_Elmt (Item_Id, Constits_Seen);
2452 end if;
2453 end if;
2454 end Analyze_Global_Item;
2456 --------------------------
2457 -- Check_Duplicate_Mode --
2458 --------------------------
2460 procedure Check_Duplicate_Mode
2461 (Mode : Node_Id;
2462 Status : in out Boolean)
2464 begin
2465 if Status then
2466 SPARK_Msg_N ("duplicate global mode", Mode);
2467 end if;
2469 Status := True;
2470 end Check_Duplicate_Mode;
2472 -------------------------------------------------
2473 -- Check_Mode_Restriction_In_Enclosing_Context --
2474 -------------------------------------------------
2476 procedure Check_Mode_Restriction_In_Enclosing_Context
2477 (Item : Node_Id;
2478 Item_Id : Entity_Id)
2480 Context : Entity_Id;
2481 Dummy : Boolean;
2482 Inputs : Elist_Id := No_Elist;
2483 Outputs : Elist_Id := No_Elist;
2485 begin
2486 -- Traverse the scope stack looking for enclosing subprograms or
2487 -- tasks subject to pragma [Refined_]Global.
2489 Context := Scope (Subp_Id);
2490 while Present (Context) and then Context /= Standard_Standard loop
2492 -- For a single task type, retrieve the corresponding object to
2493 -- which pragma [Refined_]Global is attached.
2495 if Ekind (Context) = E_Task_Type
2496 and then Is_Single_Concurrent_Type (Context)
2497 then
2498 Context := Anonymous_Object (Context);
2499 end if;
2501 if (Is_Subprogram (Context)
2502 or else Ekind (Context) = E_Task_Type
2503 or else Is_Single_Task_Object (Context))
2504 and then
2505 (Present (Get_Pragma (Context, Pragma_Global))
2506 or else
2507 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2508 then
2509 Collect_Subprogram_Inputs_Outputs
2510 (Subp_Id => Context,
2511 Subp_Inputs => Inputs,
2512 Subp_Outputs => Outputs,
2513 Global_Seen => Dummy);
2515 -- The item is classified as In_Out or Output but appears as
2516 -- an Input in an enclosing subprogram or task unit (SPARK
2517 -- RM 6.1.4(12)).
2519 if Appears_In (Inputs, Item_Id)
2520 and then not Appears_In (Outputs, Item_Id)
2521 then
2522 SPARK_Msg_NE
2523 ("global item & cannot have mode In_Out or Output",
2524 Item, Item_Id);
2526 if Is_Subprogram (Context) then
2527 SPARK_Msg_NE
2528 (Fix_Msg (Subp_Id, "\item already appears as input "
2529 & "of subprogram &"), Item, Context);
2530 else
2531 SPARK_Msg_NE
2532 (Fix_Msg (Subp_Id, "\item already appears as input "
2533 & "of task &"), Item, Context);
2534 end if;
2536 -- Stop the traversal once an error has been detected
2538 exit;
2539 end if;
2540 end if;
2542 Context := Scope (Context);
2543 end loop;
2544 end Check_Mode_Restriction_In_Enclosing_Context;
2546 ----------------------------------------
2547 -- Check_Mode_Restriction_In_Function --
2548 ----------------------------------------
2550 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2551 begin
2552 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
2553 SPARK_Msg_N
2554 ("global mode & is not applicable to functions", Mode);
2555 end if;
2556 end Check_Mode_Restriction_In_Function;
2558 -- Local variables
2560 Assoc : Node_Id;
2561 Item : Node_Id;
2562 Mode : Node_Id;
2564 -- Start of processing for Analyze_Global_List
2566 begin
2567 if Nkind (List) = N_Null then
2568 Set_Analyzed (List);
2570 -- Single global item declaration
2572 elsif Nkind_In (List, N_Expanded_Name,
2573 N_Identifier,
2574 N_Selected_Component)
2575 then
2576 Analyze_Global_Item (List, Global_Mode);
2578 -- Simple global list or moded global list declaration
2580 elsif Nkind (List) = N_Aggregate then
2581 Set_Analyzed (List);
2583 -- The declaration of a simple global list appear as a collection
2584 -- of expressions.
2586 if Present (Expressions (List)) then
2587 if Present (Component_Associations (List)) then
2588 SPARK_Msg_N
2589 ("cannot mix moded and non-moded global lists", List);
2590 end if;
2592 Item := First (Expressions (List));
2593 while Present (Item) loop
2594 Analyze_Global_Item (Item, Global_Mode);
2595 Next (Item);
2596 end loop;
2598 -- The declaration of a moded global list appears as a collection
2599 -- of component associations where individual choices denote
2600 -- modes.
2602 elsif Present (Component_Associations (List)) then
2603 if Present (Expressions (List)) then
2604 SPARK_Msg_N
2605 ("cannot mix moded and non-moded global lists", List);
2606 end if;
2608 Assoc := First (Component_Associations (List));
2609 while Present (Assoc) loop
2610 Mode := First (Choices (Assoc));
2612 if Nkind (Mode) = N_Identifier then
2613 if Chars (Mode) = Name_In_Out then
2614 Check_Duplicate_Mode (Mode, In_Out_Seen);
2615 Check_Mode_Restriction_In_Function (Mode);
2617 elsif Chars (Mode) = Name_Input then
2618 Check_Duplicate_Mode (Mode, Input_Seen);
2620 elsif Chars (Mode) = Name_Output then
2621 Check_Duplicate_Mode (Mode, Output_Seen);
2622 Check_Mode_Restriction_In_Function (Mode);
2624 elsif Chars (Mode) = Name_Proof_In then
2625 Check_Duplicate_Mode (Mode, Proof_Seen);
2627 else
2628 SPARK_Msg_N ("invalid mode selector", Mode);
2629 end if;
2631 else
2632 SPARK_Msg_N ("invalid mode selector", Mode);
2633 end if;
2635 -- Items in a moded list appear as a collection of
2636 -- expressions. Reuse the existing machinery to analyze
2637 -- them.
2639 Analyze_Global_List
2640 (List => Expression (Assoc),
2641 Global_Mode => Chars (Mode));
2643 Next (Assoc);
2644 end loop;
2646 -- Invalid tree
2648 else
2649 raise Program_Error;
2650 end if;
2652 -- Any other attempt to declare a global item is illegal. This is a
2653 -- syntax error, always report.
2655 else
2656 Error_Msg_N ("malformed global list", List);
2657 end if;
2658 end Analyze_Global_List;
2660 -- Local variables
2662 Items : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
2664 Restore_Scope : Boolean := False;
2666 -- Start of processing for Analyze_Global_In_Decl_Part
2668 begin
2669 -- Do not analyze the pragma multiple times
2671 if Is_Analyzed_Pragma (N) then
2672 return;
2673 end if;
2675 -- There is nothing to be done for a null global list
2677 if Nkind (Items) = N_Null then
2678 Set_Analyzed (Items);
2680 -- Analyze the various forms of global lists and items. Note that some
2681 -- of these may be malformed in which case the analysis emits error
2682 -- messages.
2684 else
2685 -- When pragma [Refined_]Global appears on a single concurrent type,
2686 -- it is relocated to the anonymous object.
2688 if Is_Single_Concurrent_Object (Spec_Id) then
2689 null;
2691 -- Ensure that the formal parameters are visible when processing an
2692 -- item. This falls out of the general rule of aspects pertaining to
2693 -- subprogram declarations.
2695 elsif not In_Open_Scopes (Spec_Id) then
2696 Restore_Scope := True;
2697 Push_Scope (Spec_Id);
2699 if Ekind (Spec_Id) = E_Task_Type then
2700 if Has_Discriminants (Spec_Id) then
2701 Install_Discriminants (Spec_Id);
2702 end if;
2704 elsif Is_Generic_Subprogram (Spec_Id) then
2705 Install_Generic_Formals (Spec_Id);
2707 else
2708 Install_Formals (Spec_Id);
2709 end if;
2710 end if;
2712 Analyze_Global_List (Items);
2714 if Restore_Scope then
2715 End_Scope;
2716 end if;
2717 end if;
2719 -- Ensure that a state and a corresponding constituent do not appear
2720 -- together in pragma [Refined_]Global.
2722 Check_State_And_Constituent_Use
2723 (States => States_Seen,
2724 Constits => Constits_Seen,
2725 Context => N);
2727 Set_Is_Analyzed_Pragma (N);
2728 end Analyze_Global_In_Decl_Part;
2730 --------------------------------------------
2731 -- Analyze_Initial_Condition_In_Decl_Part --
2732 --------------------------------------------
2734 -- WARNING: This routine manages Ghost regions. Return statements must be
2735 -- replaced by gotos which jump to the end of the routine and restore the
2736 -- Ghost mode.
2738 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2739 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2740 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2741 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
2743 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
2744 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
2745 -- Save the Ghost-related attributes to restore on exit
2747 begin
2748 -- Do not analyze the pragma multiple times
2750 if Is_Analyzed_Pragma (N) then
2751 return;
2752 end if;
2754 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2755 -- analysis of the pragma, the Ghost mode at point of declaration and
2756 -- point of analysis may not necessarily be the same. Use the mode in
2757 -- effect at the point of declaration.
2759 Set_Ghost_Mode (N);
2761 -- The expression is preanalyzed because it has not been moved to its
2762 -- final place yet. A direct analysis may generate side effects and this
2763 -- is not desired at this point.
2765 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2766 Set_Is_Analyzed_Pragma (N);
2768 Restore_Ghost_Region (Saved_GM, Saved_IGR);
2769 end Analyze_Initial_Condition_In_Decl_Part;
2771 --------------------------------------
2772 -- Analyze_Initializes_In_Decl_Part --
2773 --------------------------------------
2775 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2776 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2777 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2779 Constits_Seen : Elist_Id := No_Elist;
2780 -- A list containing the entities of all constituents processed so far.
2781 -- It aids in detecting illegal usage of a state and a corresponding
2782 -- constituent in pragma Initializes.
2784 Items_Seen : Elist_Id := No_Elist;
2785 -- A list of all initialization items processed so far. This list is
2786 -- used to detect duplicate items.
2788 States_And_Objs : Elist_Id := No_Elist;
2789 -- A list of all abstract states and objects declared in the visible
2790 -- declarations of the related package. This list is used to detect the
2791 -- legality of initialization items.
2793 States_Seen : Elist_Id := No_Elist;
2794 -- A list containing the entities of all states processed so far. It
2795 -- helps in detecting illegal usage of a state and a corresponding
2796 -- constituent in pragma Initializes.
2798 procedure Analyze_Initialization_Item (Item : Node_Id);
2799 -- Verify the legality of a single initialization item
2801 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2802 -- Verify the legality of a single initialization item followed by a
2803 -- list of input items.
2805 procedure Collect_States_And_Objects;
2806 -- Inspect the visible declarations of the related package and gather
2807 -- the entities of all abstract states and objects in States_And_Objs.
2809 ---------------------------------
2810 -- Analyze_Initialization_Item --
2811 ---------------------------------
2813 procedure Analyze_Initialization_Item (Item : Node_Id) is
2814 Item_Id : Entity_Id;
2816 begin
2817 Analyze (Item);
2818 Resolve_State (Item);
2820 if Is_Entity_Name (Item) then
2821 Item_Id := Entity_Of (Item);
2823 if Present (Item_Id)
2824 and then Ekind_In (Item_Id, E_Abstract_State,
2825 E_Constant,
2826 E_Variable)
2827 then
2828 -- When the initialization item is undefined, it appears as
2829 -- Any_Id. Do not continue with the analysis of the item.
2831 if Item_Id = Any_Id then
2832 null;
2834 -- The state or variable must be declared in the visible
2835 -- declarations of the package (SPARK RM 7.1.5(7)).
2837 elsif not Contains (States_And_Objs, Item_Id) then
2838 Error_Msg_Name_1 := Chars (Pack_Id);
2839 SPARK_Msg_NE
2840 ("initialization item & must appear in the visible "
2841 & "declarations of package %", Item, Item_Id);
2843 -- Detect a duplicate use of the same initialization item
2844 -- (SPARK RM 7.1.5(5)).
2846 elsif Contains (Items_Seen, Item_Id) then
2847 SPARK_Msg_N ("duplicate initialization item", Item);
2849 -- The item is legal, add it to the list of processed states
2850 -- and variables.
2852 else
2853 Append_New_Elmt (Item_Id, Items_Seen);
2855 if Ekind (Item_Id) = E_Abstract_State then
2856 Append_New_Elmt (Item_Id, States_Seen);
2857 end if;
2859 if Present (Encapsulating_State (Item_Id)) then
2860 Append_New_Elmt (Item_Id, Constits_Seen);
2861 end if;
2862 end if;
2864 -- The item references something that is not a state or object
2865 -- (SPARK RM 7.1.5(3)).
2867 else
2868 SPARK_Msg_N
2869 ("initialization item must denote object or state", Item);
2870 end if;
2872 -- Some form of illegal construct masquerading as a name
2873 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2875 else
2876 Error_Msg_N
2877 ("initialization item must denote object or state", Item);
2878 end if;
2879 end Analyze_Initialization_Item;
2881 ---------------------------------------------
2882 -- Analyze_Initialization_Item_With_Inputs --
2883 ---------------------------------------------
2885 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2886 Inputs_Seen : Elist_Id := No_Elist;
2887 -- A list of all inputs processed so far. This list is used to detect
2888 -- duplicate uses of an input.
2890 Non_Null_Seen : Boolean := False;
2891 Null_Seen : Boolean := False;
2892 -- Flags used to check the legality of an input list
2894 procedure Analyze_Input_Item (Input : Node_Id);
2895 -- Verify the legality of a single input item
2897 ------------------------
2898 -- Analyze_Input_Item --
2899 ------------------------
2901 procedure Analyze_Input_Item (Input : Node_Id) is
2902 Input_Id : Entity_Id;
2904 begin
2905 -- Null input list
2907 if Nkind (Input) = N_Null then
2908 if Null_Seen then
2909 SPARK_Msg_N
2910 ("multiple null initializations not allowed", Item);
2912 elsif Non_Null_Seen then
2913 SPARK_Msg_N
2914 ("cannot mix null and non-null initialization item", Item);
2915 else
2916 Null_Seen := True;
2917 end if;
2919 -- Input item
2921 else
2922 Non_Null_Seen := True;
2924 if Null_Seen then
2925 SPARK_Msg_N
2926 ("cannot mix null and non-null initialization item", Item);
2927 end if;
2929 Analyze (Input);
2930 Resolve_State (Input);
2932 if Is_Entity_Name (Input) then
2933 Input_Id := Entity_Of (Input);
2935 if Present (Input_Id)
2936 and then Ekind_In (Input_Id, E_Abstract_State,
2937 E_Constant,
2938 E_Generic_In_Out_Parameter,
2939 E_Generic_In_Parameter,
2940 E_In_Parameter,
2941 E_In_Out_Parameter,
2942 E_Out_Parameter,
2943 E_Protected_Type,
2944 E_Task_Type,
2945 E_Variable)
2946 then
2947 -- The input cannot denote states or objects declared
2948 -- within the related package (SPARK RM 7.1.5(4)).
2950 if Within_Scope (Input_Id, Current_Scope) then
2952 -- Do not consider generic formal parameters or their
2953 -- respective mappings to generic formals. Even though
2954 -- the formals appear within the scope of the package,
2955 -- it is allowed for an initialization item to depend
2956 -- on an input item.
2958 if Ekind_In (Input_Id, E_Generic_In_Out_Parameter,
2959 E_Generic_In_Parameter)
2960 then
2961 null;
2963 elsif Ekind_In (Input_Id, E_Constant, E_Variable)
2964 and then Present (Corresponding_Generic_Association
2965 (Declaration_Node (Input_Id)))
2966 then
2967 null;
2969 else
2970 Error_Msg_Name_1 := Chars (Pack_Id);
2971 SPARK_Msg_NE
2972 ("input item & cannot denote a visible object or "
2973 & "state of package %", Input, Input_Id);
2974 return;
2975 end if;
2976 end if;
2978 -- Detect a duplicate use of the same input item
2979 -- (SPARK RM 7.1.5(5)).
2981 if Contains (Inputs_Seen, Input_Id) then
2982 SPARK_Msg_N ("duplicate input item", Input);
2983 return;
2984 end if;
2986 -- At this point it is known that the input is legal. Add
2987 -- it to the list of processed inputs.
2989 Append_New_Elmt (Input_Id, Inputs_Seen);
2991 if Ekind (Input_Id) = E_Abstract_State then
2992 Append_New_Elmt (Input_Id, States_Seen);
2993 end if;
2995 if Ekind_In (Input_Id, E_Abstract_State,
2996 E_Constant,
2997 E_Variable)
2998 and then Present (Encapsulating_State (Input_Id))
2999 then
3000 Append_New_Elmt (Input_Id, Constits_Seen);
3001 end if;
3003 -- The input references something that is not a state or an
3004 -- object (SPARK RM 7.1.5(3)).
3006 else
3007 SPARK_Msg_N
3008 ("input item must denote object or state", Input);
3009 end if;
3011 -- Some form of illegal construct masquerading as a name
3012 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
3014 else
3015 Error_Msg_N
3016 ("input item must denote object or state", Input);
3017 end if;
3018 end if;
3019 end Analyze_Input_Item;
3021 -- Local variables
3023 Inputs : constant Node_Id := Expression (Item);
3024 Elmt : Node_Id;
3025 Input : Node_Id;
3027 Name_Seen : Boolean := False;
3028 -- A flag used to detect multiple item names
3030 -- Start of processing for Analyze_Initialization_Item_With_Inputs
3032 begin
3033 -- Inspect the name of an item with inputs
3035 Elmt := First (Choices (Item));
3036 while Present (Elmt) loop
3037 if Name_Seen then
3038 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
3039 else
3040 Name_Seen := True;
3041 Analyze_Initialization_Item (Elmt);
3042 end if;
3044 Next (Elmt);
3045 end loop;
3047 -- Multiple input items appear as an aggregate
3049 if Nkind (Inputs) = N_Aggregate then
3050 if Present (Expressions (Inputs)) then
3051 Input := First (Expressions (Inputs));
3052 while Present (Input) loop
3053 Analyze_Input_Item (Input);
3054 Next (Input);
3055 end loop;
3056 end if;
3058 if Present (Component_Associations (Inputs)) then
3059 SPARK_Msg_N
3060 ("inputs must appear in named association form", Inputs);
3061 end if;
3063 -- Single input item
3065 else
3066 Analyze_Input_Item (Inputs);
3067 end if;
3068 end Analyze_Initialization_Item_With_Inputs;
3070 --------------------------------
3071 -- Collect_States_And_Objects --
3072 --------------------------------
3074 procedure Collect_States_And_Objects is
3075 Pack_Spec : constant Node_Id := Specification (Pack_Decl);
3076 Decl : Node_Id;
3078 begin
3079 -- Collect the abstract states defined in the package (if any)
3081 if Present (Abstract_States (Pack_Id)) then
3082 States_And_Objs := New_Copy_Elist (Abstract_States (Pack_Id));
3083 end if;
3085 -- Collect all objects that appear in the visible declarations of the
3086 -- related package.
3088 if Present (Visible_Declarations (Pack_Spec)) then
3089 Decl := First (Visible_Declarations (Pack_Spec));
3090 while Present (Decl) loop
3091 if Comes_From_Source (Decl)
3092 and then Nkind_In (Decl, N_Object_Declaration,
3093 N_Object_Renaming_Declaration)
3094 then
3095 Append_New_Elmt (Defining_Entity (Decl), States_And_Objs);
3097 elsif Is_Single_Concurrent_Type_Declaration (Decl) then
3098 Append_New_Elmt
3099 (Anonymous_Object (Defining_Entity (Decl)),
3100 States_And_Objs);
3101 end if;
3103 Next (Decl);
3104 end loop;
3105 end if;
3106 end Collect_States_And_Objects;
3108 -- Local variables
3110 Inits : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
3111 Init : Node_Id;
3113 -- Start of processing for Analyze_Initializes_In_Decl_Part
3115 begin
3116 -- Do not analyze the pragma multiple times
3118 if Is_Analyzed_Pragma (N) then
3119 return;
3120 end if;
3122 -- Nothing to do when the initialization list is empty
3124 if Nkind (Inits) = N_Null then
3125 return;
3126 end if;
3128 -- Single and multiple initialization clauses appear as an aggregate. If
3129 -- this is not the case, then either the parser or the analysis of the
3130 -- pragma failed to produce an aggregate.
3132 pragma Assert (Nkind (Inits) = N_Aggregate);
3134 -- Initialize the various lists used during analysis
3136 Collect_States_And_Objects;
3138 if Present (Expressions (Inits)) then
3139 Init := First (Expressions (Inits));
3140 while Present (Init) loop
3141 Analyze_Initialization_Item (Init);
3142 Next (Init);
3143 end loop;
3144 end if;
3146 if Present (Component_Associations (Inits)) then
3147 Init := First (Component_Associations (Inits));
3148 while Present (Init) loop
3149 Analyze_Initialization_Item_With_Inputs (Init);
3150 Next (Init);
3151 end loop;
3152 end if;
3154 -- Ensure that a state and a corresponding constituent do not appear
3155 -- together in pragma Initializes.
3157 Check_State_And_Constituent_Use
3158 (States => States_Seen,
3159 Constits => Constits_Seen,
3160 Context => N);
3162 Set_Is_Analyzed_Pragma (N);
3163 end Analyze_Initializes_In_Decl_Part;
3165 ---------------------
3166 -- Analyze_Part_Of --
3167 ---------------------
3169 procedure Analyze_Part_Of
3170 (Indic : Node_Id;
3171 Item_Id : Entity_Id;
3172 Encap : Node_Id;
3173 Encap_Id : out Entity_Id;
3174 Legal : out Boolean)
3176 procedure Check_Part_Of_Abstract_State;
3177 pragma Inline (Check_Part_Of_Abstract_State);
3178 -- Verify the legality of indicator Part_Of when the encapsulator is an
3179 -- abstract state.
3181 procedure Check_Part_Of_Concurrent_Type;
3182 pragma Inline (Check_Part_Of_Concurrent_Type);
3183 -- Verify the legality of indicator Part_Of when the encapsulator is a
3184 -- single concurrent type.
3186 ----------------------------------
3187 -- Check_Part_Of_Abstract_State --
3188 ----------------------------------
3190 procedure Check_Part_Of_Abstract_State is
3191 Pack_Id : Entity_Id;
3192 Placement : State_Space_Kind;
3193 Parent_Unit : Entity_Id;
3195 begin
3196 -- Determine where the object, package instantiation or state lives
3197 -- with respect to the enclosing packages or package bodies.
3199 Find_Placement_In_State_Space
3200 (Item_Id => Item_Id,
3201 Placement => Placement,
3202 Pack_Id => Pack_Id);
3204 -- The item appears in a non-package construct with a declarative
3205 -- part (subprogram, block, etc). As such, the item is not allowed
3206 -- to be a part of an encapsulating state because the item is not
3207 -- visible.
3209 if Placement = Not_In_Package then
3210 SPARK_Msg_N
3211 ("indicator Part_Of cannot appear in this context "
3212 & "(SPARK RM 7.2.6(5))", Indic);
3214 Error_Msg_Name_1 := Chars (Scope (Encap_Id));
3215 SPARK_Msg_NE
3216 ("\& is not part of the hidden state of package %",
3217 Indic, Item_Id);
3218 return;
3220 -- The item appears in the visible state space of some package. In
3221 -- general this scenario does not warrant Part_Of except when the
3222 -- package is a nongeneric private child unit and the encapsulating
3223 -- state is declared in a parent unit or a public descendant of that
3224 -- parent unit.
3226 elsif Placement = Visible_State_Space then
3227 if Is_Child_Unit (Pack_Id)
3228 and then not Is_Generic_Unit (Pack_Id)
3229 and then Is_Private_Descendant (Pack_Id)
3230 then
3231 -- A variable or state abstraction which is part of the visible
3232 -- state of a nongeneric private child unit or its public
3233 -- descendants must have its Part_Of indicator specified. The
3234 -- Part_Of indicator must denote a state declared by either the
3235 -- parent unit of the private unit or by a public descendant of
3236 -- that parent unit.
3238 -- Find the nearest private ancestor (which can be the current
3239 -- unit itself).
3241 Parent_Unit := Pack_Id;
3242 while Present (Parent_Unit) loop
3243 exit when
3244 Private_Present
3245 (Parent (Unit_Declaration_Node (Parent_Unit)));
3246 Parent_Unit := Scope (Parent_Unit);
3247 end loop;
3249 Parent_Unit := Scope (Parent_Unit);
3251 if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then
3252 SPARK_Msg_NE
3253 ("indicator Part_Of must denote abstract state of & or of "
3254 & "its public descendant (SPARK RM 7.2.6(3))",
3255 Indic, Parent_Unit);
3256 return;
3258 elsif Scope (Encap_Id) = Parent_Unit
3259 or else
3260 (Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id))
3261 and then not Is_Private_Descendant (Scope (Encap_Id)))
3262 then
3263 null;
3265 else
3266 SPARK_Msg_NE
3267 ("indicator Part_Of must denote abstract state of & or of "
3268 & "its public descendant (SPARK RM 7.2.6(3))",
3269 Indic, Parent_Unit);
3270 return;
3271 end if;
3273 -- Indicator Part_Of is not needed when the related package is
3274 -- not a nongeneric private child unit or a public descendant
3275 -- thereof.
3277 else
3278 SPARK_Msg_N
3279 ("indicator Part_Of cannot appear in this context "
3280 & "(SPARK RM 7.2.6(5))", Indic);
3282 Error_Msg_Name_1 := Chars (Pack_Id);
3283 SPARK_Msg_NE
3284 ("\& is declared in the visible part of package %",
3285 Indic, Item_Id);
3286 return;
3287 end if;
3289 -- When the item appears in the private state space of a package, the
3290 -- encapsulating state must be declared in the same package.
3292 elsif Placement = Private_State_Space then
3293 if Scope (Encap_Id) /= Pack_Id then
3294 SPARK_Msg_NE
3295 ("indicator Part_Of must denote an abstract state of "
3296 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3298 Error_Msg_Name_1 := Chars (Pack_Id);
3299 SPARK_Msg_NE
3300 ("\& is declared in the private part of package %",
3301 Indic, Item_Id);
3302 return;
3303 end if;
3305 -- Items declared in the body state space of a package do not need
3306 -- Part_Of indicators as the refinement has already been seen.
3308 else
3309 SPARK_Msg_N
3310 ("indicator Part_Of cannot appear in this context "
3311 & "(SPARK RM 7.2.6(5))", Indic);
3313 if Scope (Encap_Id) = Pack_Id then
3314 Error_Msg_Name_1 := Chars (Pack_Id);
3315 SPARK_Msg_NE
3316 ("\& is declared in the body of package %", Indic, Item_Id);
3317 end if;
3319 return;
3320 end if;
3322 -- At this point it is known that the Part_Of indicator is legal
3324 Legal := True;
3325 end Check_Part_Of_Abstract_State;
3327 -----------------------------------
3328 -- Check_Part_Of_Concurrent_Type --
3329 -----------------------------------
3331 procedure Check_Part_Of_Concurrent_Type is
3332 function In_Proper_Order
3333 (First : Node_Id;
3334 Second : Node_Id) return Boolean;
3335 pragma Inline (In_Proper_Order);
3336 -- Determine whether node First precedes node Second
3338 procedure Placement_Error;
3339 pragma Inline (Placement_Error);
3340 -- Emit an error concerning the illegal placement of the item with
3341 -- respect to the single concurrent type.
3343 ---------------------
3344 -- In_Proper_Order --
3345 ---------------------
3347 function In_Proper_Order
3348 (First : Node_Id;
3349 Second : Node_Id) return Boolean
3351 N : Node_Id;
3353 begin
3354 if List_Containing (First) = List_Containing (Second) then
3355 N := First;
3356 while Present (N) loop
3357 if N = Second then
3358 return True;
3359 end if;
3361 Next (N);
3362 end loop;
3363 end if;
3365 return False;
3366 end In_Proper_Order;
3368 ---------------------
3369 -- Placement_Error --
3370 ---------------------
3372 procedure Placement_Error is
3373 begin
3374 SPARK_Msg_N
3375 ("indicator Part_Of must denote a previously declared single "
3376 & "protected type or single task type", Encap);
3377 end Placement_Error;
3379 -- Local variables
3381 Conc_Typ : constant Entity_Id := Etype (Encap_Id);
3382 Encap_Decl : constant Node_Id := Declaration_Node (Encap_Id);
3383 Encap_Context : constant Node_Id := Parent (Encap_Decl);
3385 Item_Context : Node_Id;
3386 Item_Decl : Node_Id;
3387 Prv_Decls : List_Id;
3388 Vis_Decls : List_Id;
3390 -- Start of processing for Check_Part_Of_Concurrent_Type
3392 begin
3393 -- Only abstract states and variables can act as constituents of an
3394 -- encapsulating single concurrent type.
3396 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
3397 null;
3399 -- The constituent is a constant
3401 elsif Ekind (Item_Id) = E_Constant then
3402 Error_Msg_Name_1 := Chars (Encap_Id);
3403 SPARK_Msg_NE
3404 (Fix_Msg (Conc_Typ, "constant & cannot act as constituent of "
3405 & "single protected type %"), Indic, Item_Id);
3406 return;
3408 -- The constituent is a package instantiation
3410 else
3411 Error_Msg_Name_1 := Chars (Encap_Id);
3412 SPARK_Msg_NE
3413 (Fix_Msg (Conc_Typ, "package instantiation & cannot act as "
3414 & "constituent of single protected type %"), Indic, Item_Id);
3415 return;
3416 end if;
3418 -- When the item denotes an abstract state of a nested package, use
3419 -- the declaration of the package to detect proper placement.
3421 -- package Pack is
3422 -- task T;
3423 -- package Nested
3424 -- with Abstract_State => (State with Part_Of => T)
3426 if Ekind (Item_Id) = E_Abstract_State then
3427 Item_Decl := Unit_Declaration_Node (Scope (Item_Id));
3428 else
3429 Item_Decl := Declaration_Node (Item_Id);
3430 end if;
3432 Item_Context := Parent (Item_Decl);
3434 -- The item and the single concurrent type must appear in the same
3435 -- declarative region, with the item following the declaration of
3436 -- the single concurrent type (SPARK RM 9(3)).
3438 if Item_Context = Encap_Context then
3439 if Nkind_In (Item_Context, N_Package_Specification,
3440 N_Protected_Definition,
3441 N_Task_Definition)
3442 then
3443 Prv_Decls := Private_Declarations (Item_Context);
3444 Vis_Decls := Visible_Declarations (Item_Context);
3446 -- The placement is OK when the single concurrent type appears
3447 -- within the visible declarations and the item in the private
3448 -- declarations.
3450 -- package Pack is
3451 -- protected PO ...
3452 -- private
3453 -- Constit : ... with Part_Of => PO;
3454 -- end Pack;
3456 if List_Containing (Encap_Decl) = Vis_Decls
3457 and then List_Containing (Item_Decl) = Prv_Decls
3458 then
3459 null;
3461 -- The placement is illegal when the item appears within the
3462 -- visible declarations and the single concurrent type is in
3463 -- the private declarations.
3465 -- package Pack is
3466 -- Constit : ... with Part_Of => PO;
3467 -- private
3468 -- protected PO ...
3469 -- end Pack;
3471 elsif List_Containing (Item_Decl) = Vis_Decls
3472 and then List_Containing (Encap_Decl) = Prv_Decls
3473 then
3474 Placement_Error;
3475 return;
3477 -- Otherwise both the item and the single concurrent type are
3478 -- in the same list. Ensure that the declaration of the single
3479 -- concurrent type precedes that of the item.
3481 elsif not In_Proper_Order
3482 (First => Encap_Decl,
3483 Second => Item_Decl)
3484 then
3485 Placement_Error;
3486 return;
3487 end if;
3489 -- Otherwise both the item and the single concurrent type are
3490 -- in the same list. Ensure that the declaration of the single
3491 -- concurrent type precedes that of the item.
3493 elsif not In_Proper_Order
3494 (First => Encap_Decl,
3495 Second => Item_Decl)
3496 then
3497 Placement_Error;
3498 return;
3499 end if;
3501 -- Otherwise the item and the single concurrent type reside within
3502 -- unrelated regions.
3504 else
3505 Error_Msg_Name_1 := Chars (Encap_Id);
3506 SPARK_Msg_NE
3507 (Fix_Msg (Conc_Typ, "constituent & must be declared "
3508 & "immediately within the same region as single protected "
3509 & "type %"), Indic, Item_Id);
3510 return;
3511 end if;
3513 -- At this point it is known that the Part_Of indicator is legal
3515 Legal := True;
3516 end Check_Part_Of_Concurrent_Type;
3518 -- Start of processing for Analyze_Part_Of
3520 begin
3521 -- Assume that the indicator is illegal
3523 Encap_Id := Empty;
3524 Legal := False;
3526 if Nkind_In (Encap, N_Expanded_Name,
3527 N_Identifier,
3528 N_Selected_Component)
3529 then
3530 Analyze (Encap);
3531 Resolve_State (Encap);
3533 Encap_Id := Entity (Encap);
3535 -- The encapsulator is an abstract state
3537 if Ekind (Encap_Id) = E_Abstract_State then
3538 null;
3540 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3542 elsif Is_Single_Concurrent_Object (Encap_Id) then
3543 null;
3545 -- Otherwise the encapsulator is not a legal choice
3547 else
3548 SPARK_Msg_N
3549 ("indicator Part_Of must denote abstract state, single "
3550 & "protected type or single task type", Encap);
3551 return;
3552 end if;
3554 -- This is a syntax error, always report
3556 else
3557 Error_Msg_N
3558 ("indicator Part_Of must denote abstract state, single protected "
3559 & "type or single task type", Encap);
3560 return;
3561 end if;
3563 -- Catch a case where indicator Part_Of denotes the abstract view of a
3564 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3566 if From_Limited_With (Encap_Id)
3567 and then Present (Non_Limited_View (Encap_Id))
3568 and then Ekind (Non_Limited_View (Encap_Id)) = E_Variable
3569 then
3570 SPARK_Msg_N ("indicator Part_Of must denote abstract state", Encap);
3571 SPARK_Msg_N ("\& denotes abstract view of object", Encap);
3572 return;
3573 end if;
3575 -- The encapsulator is an abstract state
3577 if Ekind (Encap_Id) = E_Abstract_State then
3578 Check_Part_Of_Abstract_State;
3580 -- The encapsulator is a single concurrent type
3582 else
3583 Check_Part_Of_Concurrent_Type;
3584 end if;
3585 end Analyze_Part_Of;
3587 ----------------------------------
3588 -- Analyze_Part_Of_In_Decl_Part --
3589 ----------------------------------
3591 procedure Analyze_Part_Of_In_Decl_Part
3592 (N : Node_Id;
3593 Freeze_Id : Entity_Id := Empty)
3595 Encap : constant Node_Id :=
3596 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
3597 Errors : constant Nat := Serious_Errors_Detected;
3598 Var_Decl : constant Node_Id := Find_Related_Context (N);
3599 Var_Id : constant Entity_Id := Defining_Entity (Var_Decl);
3600 Constits : Elist_Id;
3601 Encap_Id : Entity_Id;
3602 Legal : Boolean;
3604 begin
3605 -- Detect any discrepancies between the placement of the variable with
3606 -- respect to general state space and the encapsulating state or single
3607 -- concurrent type.
3609 Analyze_Part_Of
3610 (Indic => N,
3611 Item_Id => Var_Id,
3612 Encap => Encap,
3613 Encap_Id => Encap_Id,
3614 Legal => Legal);
3616 -- The Part_Of indicator turns the variable into a constituent of the
3617 -- encapsulating state or single concurrent type.
3619 if Legal then
3620 pragma Assert (Present (Encap_Id));
3621 Constits := Part_Of_Constituents (Encap_Id);
3623 if No (Constits) then
3624 Constits := New_Elmt_List;
3625 Set_Part_Of_Constituents (Encap_Id, Constits);
3626 end if;
3628 Append_Elmt (Var_Id, Constits);
3629 Set_Encapsulating_State (Var_Id, Encap_Id);
3631 -- A Part_Of constituent partially refines an abstract state. This
3632 -- property does not apply to protected or task units.
3634 if Ekind (Encap_Id) = E_Abstract_State then
3635 Set_Has_Partial_Visible_Refinement (Encap_Id);
3636 end if;
3637 end if;
3639 -- Emit a clarification message when the encapsulator is undefined,
3640 -- possibly due to contract freezing.
3642 if Errors /= Serious_Errors_Detected
3643 and then Present (Freeze_Id)
3644 and then Has_Undefined_Reference (Encap)
3645 then
3646 Contract_Freeze_Error (Var_Id, Freeze_Id);
3647 end if;
3648 end Analyze_Part_Of_In_Decl_Part;
3650 --------------------
3651 -- Analyze_Pragma --
3652 --------------------
3654 procedure Analyze_Pragma (N : Node_Id) is
3655 Loc : constant Source_Ptr := Sloc (N);
3657 Pname : Name_Id := Pragma_Name (N);
3658 -- Name of the source pragma, or name of the corresponding aspect for
3659 -- pragmas which originate in a source aspect. In the latter case, the
3660 -- name may be different from the pragma name.
3662 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
3664 Pragma_Exit : exception;
3665 -- This exception is used to exit pragma processing completely. It
3666 -- is used when an error is detected, and no further processing is
3667 -- required. It is also used if an earlier error has left the tree in
3668 -- a state where the pragma should not be processed.
3670 Arg_Count : Nat;
3671 -- Number of pragma argument associations
3673 Arg1 : Node_Id;
3674 Arg2 : Node_Id;
3675 Arg3 : Node_Id;
3676 Arg4 : Node_Id;
3677 -- First four pragma arguments (pragma argument association nodes, or
3678 -- Empty if the corresponding argument does not exist).
3680 type Name_List is array (Natural range <>) of Name_Id;
3681 type Args_List is array (Natural range <>) of Node_Id;
3682 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3684 -----------------------
3685 -- Local Subprograms --
3686 -----------------------
3688 procedure Acquire_Warning_Match_String (Arg : Node_Id);
3689 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
3690 -- get the given string argument, and place it in Name_Buffer, adding
3691 -- leading and trailing asterisks if they are not already present. The
3692 -- caller has already checked that Arg is a static string expression.
3694 procedure Ada_2005_Pragma;
3695 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3696 -- Ada 95 mode, these are implementation defined pragmas, so should be
3697 -- caught by the No_Implementation_Pragmas restriction.
3699 procedure Ada_2012_Pragma;
3700 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3701 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3702 -- should be caught by the No_Implementation_Pragmas restriction.
3704 procedure Analyze_Depends_Global
3705 (Spec_Id : out Entity_Id;
3706 Subp_Decl : out Node_Id;
3707 Legal : out Boolean);
3708 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3709 -- legality of the placement and related context of the pragma. Spec_Id
3710 -- is the entity of the related subprogram. Subp_Decl is the declaration
3711 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3713 procedure Analyze_If_Present (Id : Pragma_Id);
3714 -- Inspect the remainder of the list containing pragma N and look for
3715 -- a pragma that matches Id. If found, analyze the pragma.
3717 procedure Analyze_Pre_Post_Condition;
3718 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3720 procedure Analyze_Refined_Depends_Global_Post
3721 (Spec_Id : out Entity_Id;
3722 Body_Id : out Entity_Id;
3723 Legal : out Boolean);
3724 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3725 -- Refined_Global and Refined_Post. Verify the legality of the placement
3726 -- and related context of the pragma. Spec_Id is the entity of the
3727 -- related subprogram. Body_Id is the entity of the subprogram body.
3728 -- Flag Legal is set when the pragma is legal.
3730 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False);
3731 -- Perform full analysis of pragma Unmodified and the write aspect of
3732 -- pragma Unused. Flag Is_Unused should be set when verifying the
3733 -- semantics of pragma Unused.
3735 procedure Analyze_Unreferenced_Or_Unused (Is_Unused : Boolean := False);
3736 -- Perform full analysis of pragma Unreferenced and the read aspect of
3737 -- pragma Unused. Flag Is_Unused should be set when verifying the
3738 -- semantics of pragma Unused.
3740 procedure Check_Ada_83_Warning;
3741 -- Issues a warning message for the current pragma if operating in Ada
3742 -- 83 mode (used for language pragmas that are not a standard part of
3743 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3744 -- of 95 pragma.
3746 procedure Check_Arg_Count (Required : Nat);
3747 -- Check argument count for pragma is equal to given parameter. If not,
3748 -- then issue an error message and raise Pragma_Exit.
3750 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3751 -- Arg which can either be a pragma argument association, in which case
3752 -- the check is applied to the expression of the association or an
3753 -- expression directly.
3755 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
3756 -- Check that an argument has the right form for an EXTERNAL_NAME
3757 -- parameter of an extended import/export pragma. The rule is that the
3758 -- name must be an identifier or string literal (in Ada 83 mode) or a
3759 -- static string expression (in Ada 95 mode).
3761 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
3762 -- Check the specified argument Arg to make sure that it is an
3763 -- identifier. If not give error and raise Pragma_Exit.
3765 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
3766 -- Check the specified argument Arg to make sure that it is an integer
3767 -- literal. If not give error and raise Pragma_Exit.
3769 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
3770 -- Check the specified argument Arg to make sure that it has the proper
3771 -- syntactic form for a local name and meets the semantic requirements
3772 -- for a local name. The local name is analyzed as part of the
3773 -- processing for this call. In addition, the local name is required
3774 -- to represent an entity at the library level.
3776 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
3777 -- Check the specified argument Arg to make sure that it has the proper
3778 -- syntactic form for a local name and meets the semantic requirements
3779 -- for a local name. The local name is analyzed as part of the
3780 -- processing for this call.
3782 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
3783 -- Check the specified argument Arg to make sure that it is a valid
3784 -- locking policy name. If not give error and raise Pragma_Exit.
3786 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
3787 -- Check the specified argument Arg to make sure that it is a valid
3788 -- elaboration policy name. If not give error and raise Pragma_Exit.
3790 procedure Check_Arg_Is_One_Of
3791 (Arg : Node_Id;
3792 N1, N2 : Name_Id);
3793 procedure Check_Arg_Is_One_Of
3794 (Arg : Node_Id;
3795 N1, N2, N3 : Name_Id);
3796 procedure Check_Arg_Is_One_Of
3797 (Arg : Node_Id;
3798 N1, N2, N3, N4 : Name_Id);
3799 procedure Check_Arg_Is_One_Of
3800 (Arg : Node_Id;
3801 N1, N2, N3, N4, N5 : Name_Id);
3802 -- Check the specified argument Arg to make sure that it is an
3803 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3804 -- present). If not then give error and raise Pragma_Exit.
3806 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
3807 -- Check the specified argument Arg to make sure that it is a valid
3808 -- queuing policy name. If not give error and raise Pragma_Exit.
3810 procedure Check_Arg_Is_OK_Static_Expression
3811 (Arg : Node_Id;
3812 Typ : Entity_Id := Empty);
3813 -- Check the specified argument Arg to make sure that it is a static
3814 -- expression of the given type (i.e. it will be analyzed and resolved
3815 -- using this type, which can be any valid argument to Resolve, e.g.
3816 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3817 -- Typ is left Empty, then any static expression is allowed. Includes
3818 -- checking that the argument does not raise Constraint_Error.
3820 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
3821 -- Check the specified argument Arg to make sure that it is a valid task
3822 -- dispatching policy name. If not give error and raise Pragma_Exit.
3824 procedure Check_Arg_Order (Names : Name_List);
3825 -- Checks for an instance of two arguments with identifiers for the
3826 -- current pragma which are not in the sequence indicated by Names,
3827 -- and if so, generates a fatal message about bad order of arguments.
3829 procedure Check_At_Least_N_Arguments (N : Nat);
3830 -- Check there are at least N arguments present
3832 procedure Check_At_Most_N_Arguments (N : Nat);
3833 -- Check there are no more than N arguments present
3835 procedure Check_Component
3836 (Comp : Node_Id;
3837 UU_Typ : Entity_Id;
3838 In_Variant_Part : Boolean := False);
3839 -- Examine an Unchecked_Union component for correct use of per-object
3840 -- constrained subtypes, and for restrictions on finalizable components.
3841 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3842 -- should be set when Comp comes from a record variant.
3844 procedure Check_Duplicate_Pragma (E : Entity_Id);
3845 -- Check if a rep item of the same name as the current pragma is already
3846 -- chained as a rep pragma to the given entity. If so give a message
3847 -- about the duplicate, and then raise Pragma_Exit so does not return.
3848 -- Note that if E is a type, then this routine avoids flagging a pragma
3849 -- which applies to a parent type from which E is derived.
3851 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
3852 -- Nam is an N_String_Literal node containing the external name set by
3853 -- an Import or Export pragma (or extended Import or Export pragma).
3854 -- This procedure checks for possible duplications if this is the export
3855 -- case, and if found, issues an appropriate error message.
3857 procedure Check_Expr_Is_OK_Static_Expression
3858 (Expr : Node_Id;
3859 Typ : Entity_Id := Empty);
3860 -- Check the specified expression Expr to make sure that it is a static
3861 -- expression of the given type (i.e. it will be analyzed and resolved
3862 -- using this type, which can be any valid argument to Resolve, e.g.
3863 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3864 -- Typ is left Empty, then any static expression is allowed. Includes
3865 -- checking that the expression does not raise Constraint_Error.
3867 procedure Check_First_Subtype (Arg : Node_Id);
3868 -- Checks that Arg, whose expression is an entity name, references a
3869 -- first subtype.
3871 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
3872 -- Checks that the given argument has an identifier, and if so, requires
3873 -- it to match the given identifier name. If there is no identifier, or
3874 -- a non-matching identifier, then an error message is given and
3875 -- Pragma_Exit is raised.
3877 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
3878 -- Checks that the given argument has an identifier, and if so, requires
3879 -- it to match one of the given identifier names. If there is no
3880 -- identifier, or a non-matching identifier, then an error message is
3881 -- given and Pragma_Exit is raised.
3883 procedure Check_In_Main_Program;
3884 -- Common checks for pragmas that appear within a main program
3885 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
3887 procedure Check_Interrupt_Or_Attach_Handler;
3888 -- Common processing for first argument of pragma Interrupt_Handler or
3889 -- pragma Attach_Handler.
3891 procedure Check_Loop_Pragma_Placement;
3892 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
3893 -- appear immediately within a construct restricted to loops, and that
3894 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
3896 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
3897 -- Check that pragma appears in a declarative part, or in a package
3898 -- specification, i.e. that it does not occur in a statement sequence
3899 -- in a body.
3901 procedure Check_No_Identifier (Arg : Node_Id);
3902 -- Checks that the given argument does not have an identifier. If
3903 -- an identifier is present, then an error message is issued, and
3904 -- Pragma_Exit is raised.
3906 procedure Check_No_Identifiers;
3907 -- Checks that none of the arguments to the pragma has an identifier.
3908 -- If any argument has an identifier, then an error message is issued,
3909 -- and Pragma_Exit is raised.
3911 procedure Check_No_Link_Name;
3912 -- Checks that no link name is specified
3914 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
3915 -- Checks if the given argument has an identifier, and if so, requires
3916 -- it to match the given identifier name. If there is a non-matching
3917 -- identifier, then an error message is given and Pragma_Exit is raised.
3919 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
3920 -- Checks if the given argument has an identifier, and if so, requires
3921 -- it to match the given identifier name. If there is a non-matching
3922 -- identifier, then an error message is given and Pragma_Exit is raised.
3923 -- In this version of the procedure, the identifier name is given as
3924 -- a string with lower case letters.
3926 procedure Check_Static_Boolean_Expression (Expr : Node_Id);
3927 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
3928 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
3929 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
3930 -- is an OK static boolean expression. Emit an error if this is not the
3931 -- case.
3933 procedure Check_Static_Constraint (Constr : Node_Id);
3934 -- Constr is a constraint from an N_Subtype_Indication node from a
3935 -- component constraint in an Unchecked_Union type. This routine checks
3936 -- that the constraint is static as required by the restrictions for
3937 -- Unchecked_Union.
3939 procedure Check_Valid_Configuration_Pragma;
3940 -- Legality checks for placement of a configuration pragma
3942 procedure Check_Valid_Library_Unit_Pragma;
3943 -- Legality checks for library unit pragmas. A special case arises for
3944 -- pragmas in generic instances that come from copies of the original
3945 -- library unit pragmas in the generic templates. In the case of other
3946 -- than library level instantiations these can appear in contexts which
3947 -- would normally be invalid (they only apply to the original template
3948 -- and to library level instantiations), and they are simply ignored,
3949 -- which is implemented by rewriting them as null statements.
3951 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
3952 -- Check an Unchecked_Union variant for lack of nested variants and
3953 -- presence of at least one component. UU_Typ is the related Unchecked_
3954 -- Union type.
3956 procedure Ensure_Aggregate_Form (Arg : Node_Id);
3957 -- Subsidiary routine to the processing of pragmas Abstract_State,
3958 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
3959 -- Refined_Global and Refined_State. Transform argument Arg into
3960 -- an aggregate if not one already. N_Null is never transformed.
3961 -- Arg may denote an aspect specification or a pragma argument
3962 -- association.
3964 procedure Error_Pragma (Msg : String);
3965 pragma No_Return (Error_Pragma);
3966 -- Outputs error message for current pragma. The message contains a %
3967 -- that will be replaced with the pragma name, and the flag is placed
3968 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
3969 -- calls Fix_Error (see spec of that procedure for details).
3971 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
3972 pragma No_Return (Error_Pragma_Arg);
3973 -- Outputs error message for current pragma. The message may contain
3974 -- a % that will be replaced with the pragma name. The parameter Arg
3975 -- may either be a pragma argument association, in which case the flag
3976 -- is placed on the expression of this association, or an expression,
3977 -- in which case the flag is placed directly on the expression. The
3978 -- message is placed using Error_Msg_N, so the message may also contain
3979 -- an & insertion character which will reference the given Arg value.
3980 -- After placing the message, Pragma_Exit is raised. Note: this routine
3981 -- calls Fix_Error (see spec of that procedure for details).
3983 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
3984 pragma No_Return (Error_Pragma_Arg);
3985 -- Similar to above form of Error_Pragma_Arg except that two messages
3986 -- are provided, the second is a continuation comment starting with \.
3988 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
3989 pragma No_Return (Error_Pragma_Arg_Ident);
3990 -- Outputs error message for current pragma. The message may contain a %
3991 -- that will be replaced with the pragma name. The parameter Arg must be
3992 -- a pragma argument association with a non-empty identifier (i.e. its
3993 -- Chars field must be set), and the error message is placed on the
3994 -- identifier. The message is placed using Error_Msg_N so the message
3995 -- may also contain an & insertion character which will reference
3996 -- the identifier. After placing the message, Pragma_Exit is raised.
3997 -- Note: this routine calls Fix_Error (see spec of that procedure for
3998 -- details).
4000 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
4001 pragma No_Return (Error_Pragma_Ref);
4002 -- Outputs error message for current pragma. The message may contain
4003 -- a % that will be replaced with the pragma name. The parameter Ref
4004 -- must be an entity whose name can be referenced by & and sloc by #.
4005 -- After placing the message, Pragma_Exit is raised. Note: this routine
4006 -- calls Fix_Error (see spec of that procedure for details).
4008 function Find_Lib_Unit_Name return Entity_Id;
4009 -- Used for a library unit pragma to find the entity to which the
4010 -- library unit pragma applies, returns the entity found.
4012 procedure Find_Program_Unit_Name (Id : Node_Id);
4013 -- If the pragma is a compilation unit pragma, the id must denote the
4014 -- compilation unit in the same compilation, and the pragma must appear
4015 -- in the list of preceding or trailing pragmas. If it is a program
4016 -- unit pragma that is not a compilation unit pragma, then the
4017 -- identifier must be visible.
4019 function Find_Unique_Parameterless_Procedure
4020 (Name : Entity_Id;
4021 Arg : Node_Id) return Entity_Id;
4022 -- Used for a procedure pragma to find the unique parameterless
4023 -- procedure identified by Name, returns it if it exists, otherwise
4024 -- errors out and uses Arg as the pragma argument for the message.
4026 function Fix_Error (Msg : String) return String;
4027 -- This is called prior to issuing an error message. Msg is the normal
4028 -- error message issued in the pragma case. This routine checks for the
4029 -- case of a pragma coming from an aspect in the source, and returns a
4030 -- message suitable for the aspect case as follows:
4032 -- Each substring "pragma" is replaced by "aspect"
4034 -- If "argument of" is at the start of the error message text, it is
4035 -- replaced by "entity for".
4037 -- If "argument" is at the start of the error message text, it is
4038 -- replaced by "entity".
4040 -- So for example, "argument of pragma X must be discrete type"
4041 -- returns "entity for aspect X must be a discrete type".
4043 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
4044 -- be different from the pragma name). If the current pragma results
4045 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
4046 -- original pragma name.
4048 procedure Gather_Associations
4049 (Names : Name_List;
4050 Args : out Args_List);
4051 -- This procedure is used to gather the arguments for a pragma that
4052 -- permits arbitrary ordering of parameters using the normal rules
4053 -- for named and positional parameters. The Names argument is a list
4054 -- of Name_Id values that corresponds to the allowed pragma argument
4055 -- association identifiers in order. The result returned in Args is
4056 -- a list of corresponding expressions that are the pragma arguments.
4057 -- Note that this is a list of expressions, not of pragma argument
4058 -- associations (Gather_Associations has completely checked all the
4059 -- optional identifiers when it returns). An entry in Args is Empty
4060 -- on return if the corresponding argument is not present.
4062 procedure GNAT_Pragma;
4063 -- Called for all GNAT defined pragmas to check the relevant restriction
4064 -- (No_Implementation_Pragmas).
4066 function Is_Before_First_Decl
4067 (Pragma_Node : Node_Id;
4068 Decls : List_Id) return Boolean;
4069 -- Return True if Pragma_Node is before the first declarative item in
4070 -- Decls where Decls is the list of declarative items.
4072 function Is_Configuration_Pragma return Boolean;
4073 -- Determines if the placement of the current pragma is appropriate
4074 -- for a configuration pragma.
4076 function Is_In_Context_Clause return Boolean;
4077 -- Returns True if pragma appears within the context clause of a unit,
4078 -- and False for any other placement (does not generate any messages).
4080 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
4081 -- Analyzes the argument, and determines if it is a static string
4082 -- expression, returns True if so, False if non-static or not String.
4083 -- A special case is that a string literal returns True in Ada 83 mode
4084 -- (which has no such thing as static string expressions). Note that
4085 -- the call analyzes its argument, so this cannot be used for the case
4086 -- where an identifier might not be declared.
4088 procedure Pragma_Misplaced;
4089 pragma No_Return (Pragma_Misplaced);
4090 -- Issue fatal error message for misplaced pragma
4092 procedure Process_Atomic_Independent_Shared_Volatile;
4093 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
4094 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
4095 -- and treated as being identical in effect to pragma Atomic.
4097 procedure Process_Compile_Time_Warning_Or_Error;
4098 -- Common processing for Compile_Time_Error and Compile_Time_Warning
4100 procedure Process_Convention
4101 (C : out Convention_Id;
4102 Ent : out Entity_Id);
4103 -- Common processing for Convention, Interface, Import and Export.
4104 -- Checks first two arguments of pragma, and sets the appropriate
4105 -- convention value in the specified entity or entities. On return
4106 -- C is the convention, Ent is the referenced entity.
4108 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
4109 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
4110 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
4112 procedure Process_Extended_Import_Export_Object_Pragma
4113 (Arg_Internal : Node_Id;
4114 Arg_External : Node_Id;
4115 Arg_Size : Node_Id);
4116 -- Common processing for the pragmas Import/Export_Object. The three
4117 -- arguments correspond to the three named parameters of the pragmas. An
4118 -- argument is empty if the corresponding parameter is not present in
4119 -- the pragma.
4121 procedure Process_Extended_Import_Export_Internal_Arg
4122 (Arg_Internal : Node_Id := Empty);
4123 -- Common processing for all extended Import and Export pragmas. The
4124 -- argument is the pragma parameter for the Internal argument. If
4125 -- Arg_Internal is empty or inappropriate, an error message is posted.
4126 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
4127 -- set to identify the referenced entity.
4129 procedure Process_Extended_Import_Export_Subprogram_Pragma
4130 (Arg_Internal : Node_Id;
4131 Arg_External : Node_Id;
4132 Arg_Parameter_Types : Node_Id;
4133 Arg_Result_Type : Node_Id := Empty;
4134 Arg_Mechanism : Node_Id;
4135 Arg_Result_Mechanism : Node_Id := Empty);
4136 -- Common processing for all extended Import and Export pragmas applying
4137 -- to subprograms. The caller omits any arguments that do not apply to
4138 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
4139 -- only in the Import_Function and Export_Function cases). The argument
4140 -- names correspond to the allowed pragma association identifiers.
4142 procedure Process_Generic_List;
4143 -- Common processing for Share_Generic and Inline_Generic
4145 procedure Process_Import_Or_Interface;
4146 -- Common processing for Import or Interface
4148 procedure Process_Import_Predefined_Type;
4149 -- Processing for completing a type with pragma Import. This is used
4150 -- to declare types that match predefined C types, especially for cases
4151 -- without corresponding Ada predefined type.
4153 type Inline_Status is (Suppressed, Disabled, Enabled);
4154 -- Inline status of a subprogram, indicated as follows:
4155 -- Suppressed: inlining is suppressed for the subprogram
4156 -- Disabled: no inlining is requested for the subprogram
4157 -- Enabled: inlining is requested/required for the subprogram
4159 procedure Process_Inline (Status : Inline_Status);
4160 -- Common processing for No_Inline, Inline and Inline_Always. Parameter
4161 -- indicates the inline status specified by the pragma.
4163 procedure Process_Interface_Name
4164 (Subprogram_Def : Entity_Id;
4165 Ext_Arg : Node_Id;
4166 Link_Arg : Node_Id;
4167 Prag : Node_Id);
4168 -- Given the last two arguments of pragma Import, pragma Export, or
4169 -- pragma Interface_Name, performs validity checks and sets the
4170 -- Interface_Name field of the given subprogram entity to the
4171 -- appropriate external or link name, depending on the arguments given.
4172 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
4173 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
4174 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
4175 -- nor Link_Arg is present, the interface name is set to the default
4176 -- from the subprogram name. In addition, the pragma itself is passed
4177 -- to analyze any expressions in the case the pragma came from an aspect
4178 -- specification.
4180 procedure Process_Interrupt_Or_Attach_Handler;
4181 -- Common processing for Interrupt and Attach_Handler pragmas
4183 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
4184 -- Common processing for Restrictions and Restriction_Warnings pragmas.
4185 -- Warn is True for Restriction_Warnings, or for Restrictions if the
4186 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
4187 -- is not set in the Restrictions case.
4189 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
4190 -- Common processing for Suppress and Unsuppress. The boolean parameter
4191 -- Suppress_Case is True for the Suppress case, and False for the
4192 -- Unsuppress case.
4194 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id);
4195 -- Subsidiary to the analysis of pragmas Independent[_Components].
4196 -- Record such a pragma N applied to entity E for future checks.
4198 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
4199 -- This procedure sets the Is_Exported flag for the given entity,
4200 -- checking that the entity was not previously imported. Arg is
4201 -- the argument that specified the entity. A check is also made
4202 -- for exporting inappropriate entities.
4204 procedure Set_Extended_Import_Export_External_Name
4205 (Internal_Ent : Entity_Id;
4206 Arg_External : Node_Id);
4207 -- Common processing for all extended import export pragmas. The first
4208 -- argument, Internal_Ent, is the internal entity, which has already
4209 -- been checked for validity by the caller. Arg_External is from the
4210 -- Import or Export pragma, and may be null if no External parameter
4211 -- was present. If Arg_External is present and is a non-null string
4212 -- (a null string is treated as the default), then the Interface_Name
4213 -- field of Internal_Ent is set appropriately.
4215 procedure Set_Imported (E : Entity_Id);
4216 -- This procedure sets the Is_Imported flag for the given entity,
4217 -- checking that it is not previously exported or imported.
4219 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
4220 -- Mech is a parameter passing mechanism (see Import_Function syntax
4221 -- for MECHANISM_NAME). This routine checks that the mechanism argument
4222 -- has the right form, and if not issues an error message. If the
4223 -- argument has the right form then the Mechanism field of Ent is
4224 -- set appropriately.
4226 procedure Set_Rational_Profile;
4227 -- Activate the set of configuration pragmas and permissions that make
4228 -- up the Rational profile.
4230 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id);
4231 -- Activate the set of configuration pragmas and restrictions that make
4232 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar,
4233 -- GNAT_Ravenscar_EDF, or Ravenscar. N is the corresponding pragma node,
4234 -- which is used for error messages on any constructs violating the
4235 -- profile.
4237 ----------------------------------
4238 -- Acquire_Warning_Match_String --
4239 ----------------------------------
4241 procedure Acquire_Warning_Match_String (Arg : Node_Id) is
4242 begin
4243 String_To_Name_Buffer
4244 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
4246 -- Add asterisk at start if not already there
4248 if Name_Len > 0 and then Name_Buffer (1) /= '*' then
4249 Name_Buffer (2 .. Name_Len + 1) :=
4250 Name_Buffer (1 .. Name_Len);
4251 Name_Buffer (1) := '*';
4252 Name_Len := Name_Len + 1;
4253 end if;
4255 -- Add asterisk at end if not already there
4257 if Name_Buffer (Name_Len) /= '*' then
4258 Name_Len := Name_Len + 1;
4259 Name_Buffer (Name_Len) := '*';
4260 end if;
4261 end Acquire_Warning_Match_String;
4263 ---------------------
4264 -- Ada_2005_Pragma --
4265 ---------------------
4267 procedure Ada_2005_Pragma is
4268 begin
4269 if Ada_Version <= Ada_95 then
4270 Check_Restriction (No_Implementation_Pragmas, N);
4271 end if;
4272 end Ada_2005_Pragma;
4274 ---------------------
4275 -- Ada_2012_Pragma --
4276 ---------------------
4278 procedure Ada_2012_Pragma is
4279 begin
4280 if Ada_Version <= Ada_2005 then
4281 Check_Restriction (No_Implementation_Pragmas, N);
4282 end if;
4283 end Ada_2012_Pragma;
4285 ----------------------------
4286 -- Analyze_Depends_Global --
4287 ----------------------------
4289 procedure Analyze_Depends_Global
4290 (Spec_Id : out Entity_Id;
4291 Subp_Decl : out Node_Id;
4292 Legal : out Boolean)
4294 begin
4295 -- Assume that the pragma is illegal
4297 Spec_Id := Empty;
4298 Subp_Decl := Empty;
4299 Legal := False;
4301 GNAT_Pragma;
4302 Check_Arg_Count (1);
4304 -- Ensure the proper placement of the pragma. Depends/Global must be
4305 -- associated with a subprogram declaration or a body that acts as a
4306 -- spec.
4308 Subp_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4310 -- Entry
4312 if Nkind (Subp_Decl) = N_Entry_Declaration then
4313 null;
4315 -- Generic subprogram
4317 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4318 null;
4320 -- Object declaration of a single concurrent type
4322 elsif Nkind (Subp_Decl) = N_Object_Declaration
4323 and then Is_Single_Concurrent_Object
4324 (Unique_Defining_Entity (Subp_Decl))
4325 then
4326 null;
4328 -- Single task type
4330 elsif Nkind (Subp_Decl) = N_Single_Task_Declaration then
4331 null;
4333 -- Subprogram body acts as spec
4335 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4336 and then No (Corresponding_Spec (Subp_Decl))
4337 then
4338 null;
4340 -- Subprogram body stub acts as spec
4342 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4343 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
4344 then
4345 null;
4347 -- Subprogram declaration
4349 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4350 null;
4352 -- Task type
4354 elsif Nkind (Subp_Decl) = N_Task_Type_Declaration then
4355 null;
4357 else
4358 Pragma_Misplaced;
4359 return;
4360 end if;
4362 -- If we get here, then the pragma is legal
4364 Legal := True;
4365 Spec_Id := Unique_Defining_Entity (Subp_Decl);
4367 -- When the related context is an entry, the entry must belong to a
4368 -- protected unit (SPARK RM 6.1.4(6)).
4370 if Is_Entry_Declaration (Spec_Id)
4371 and then Ekind (Scope (Spec_Id)) /= E_Protected_Type
4372 then
4373 Pragma_Misplaced;
4374 return;
4376 -- When the related context is an anonymous object created for a
4377 -- simple concurrent type, the type must be a task
4378 -- (SPARK RM 6.1.4(6)).
4380 elsif Is_Single_Concurrent_Object (Spec_Id)
4381 and then Ekind (Etype (Spec_Id)) /= E_Task_Type
4382 then
4383 Pragma_Misplaced;
4384 return;
4385 end if;
4387 -- A pragma that applies to a Ghost entity becomes Ghost for the
4388 -- purposes of legality checks and removal of ignored Ghost code.
4390 Mark_Ghost_Pragma (N, Spec_Id);
4391 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4392 end Analyze_Depends_Global;
4394 ------------------------
4395 -- Analyze_If_Present --
4396 ------------------------
4398 procedure Analyze_If_Present (Id : Pragma_Id) is
4399 Stmt : Node_Id;
4401 begin
4402 pragma Assert (Is_List_Member (N));
4404 -- Inspect the declarations or statements following pragma N looking
4405 -- for another pragma whose Id matches the caller's request. If it is
4406 -- available, analyze it.
4408 Stmt := Next (N);
4409 while Present (Stmt) loop
4410 if Nkind (Stmt) = N_Pragma and then Get_Pragma_Id (Stmt) = Id then
4411 Analyze_Pragma (Stmt);
4412 exit;
4414 -- The first source declaration or statement immediately following
4415 -- N ends the region where a pragma may appear.
4417 elsif Comes_From_Source (Stmt) then
4418 exit;
4419 end if;
4421 Next (Stmt);
4422 end loop;
4423 end Analyze_If_Present;
4425 --------------------------------
4426 -- Analyze_Pre_Post_Condition --
4427 --------------------------------
4429 procedure Analyze_Pre_Post_Condition is
4430 Prag_Iden : constant Node_Id := Pragma_Identifier (N);
4431 Subp_Decl : Node_Id;
4432 Subp_Id : Entity_Id;
4434 Duplicates_OK : Boolean := False;
4435 -- Flag set when a pre/postcondition allows multiple pragmas of the
4436 -- same kind.
4438 In_Body_OK : Boolean := False;
4439 -- Flag set when a pre/postcondition is allowed to appear on a body
4440 -- even though the subprogram may have a spec.
4442 Is_Pre_Post : Boolean := False;
4443 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4444 -- Post_Class.
4446 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean;
4447 -- Implement rules in AI12-0131: an overriding operation can have
4448 -- a class-wide precondition only if one of its ancestors has an
4449 -- explicit class-wide precondition.
4451 -----------------------------
4452 -- Inherits_Class_Wide_Pre --
4453 -----------------------------
4455 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean is
4456 Typ : constant Entity_Id := Find_Dispatching_Type (E);
4457 Cont : Node_Id;
4458 Prag : Node_Id;
4459 Prev : Entity_Id := Overridden_Operation (E);
4461 begin
4462 -- Check ancestors on the overriding operation to examine the
4463 -- preconditions that may apply to them.
4465 while Present (Prev) loop
4466 Cont := Contract (Prev);
4467 if Present (Cont) then
4468 Prag := Pre_Post_Conditions (Cont);
4469 while Present (Prag) loop
4470 if Pragma_Name (Prag) = Name_Precondition
4471 and then Class_Present (Prag)
4472 then
4473 return True;
4474 end if;
4476 Prag := Next_Pragma (Prag);
4477 end loop;
4478 end if;
4480 -- For a type derived from a generic formal type, the operation
4481 -- inheriting the condition is a renaming, not an overriding of
4482 -- the operation of the formal. Ditto for an inherited
4483 -- operation which has no explicit contracts.
4485 if Is_Generic_Type (Find_Dispatching_Type (Prev))
4486 or else not Comes_From_Source (Prev)
4487 then
4488 Prev := Alias (Prev);
4489 else
4490 Prev := Overridden_Operation (Prev);
4491 end if;
4492 end loop;
4494 -- If the controlling type of the subprogram has progenitors, an
4495 -- interface operation implemented by the current operation may
4496 -- have a class-wide precondition.
4498 if Has_Interfaces (Typ) then
4499 declare
4500 Elmt : Elmt_Id;
4501 Ints : Elist_Id;
4502 Prim : Entity_Id;
4503 Prim_Elmt : Elmt_Id;
4504 Prim_List : Elist_Id;
4506 begin
4507 Collect_Interfaces (Typ, Ints);
4508 Elmt := First_Elmt (Ints);
4510 -- Iterate over the primitive operations of each interface
4512 while Present (Elmt) loop
4513 Prim_List := Direct_Primitive_Operations (Node (Elmt));
4514 Prim_Elmt := First_Elmt (Prim_List);
4515 while Present (Prim_Elmt) loop
4516 Prim := Node (Prim_Elmt);
4517 if Chars (Prim) = Chars (E)
4518 and then Present (Contract (Prim))
4519 and then Class_Present
4520 (Pre_Post_Conditions (Contract (Prim)))
4521 then
4522 return True;
4523 end if;
4525 Next_Elmt (Prim_Elmt);
4526 end loop;
4528 Next_Elmt (Elmt);
4529 end loop;
4530 end;
4531 end if;
4533 return False;
4534 end Inherits_Class_Wide_Pre;
4536 -- Start of processing for Analyze_Pre_Post_Condition
4538 begin
4539 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4540 -- offer uniformity among the various kinds of pre/postconditions by
4541 -- rewriting the pragma identifier. This allows the retrieval of the
4542 -- original pragma name by routine Original_Aspect_Pragma_Name.
4544 if Comes_From_Source (N) then
4545 if Nam_In (Pname, Name_Pre, Name_Pre_Class) then
4546 Is_Pre_Post := True;
4547 Set_Class_Present (N, Pname = Name_Pre_Class);
4548 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition));
4550 elsif Nam_In (Pname, Name_Post, Name_Post_Class) then
4551 Is_Pre_Post := True;
4552 Set_Class_Present (N, Pname = Name_Post_Class);
4553 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition));
4554 end if;
4555 end if;
4557 -- Determine the semantics with respect to duplicates and placement
4558 -- in a body. Pragmas Precondition and Postcondition were introduced
4559 -- before aspects and are not subject to the same aspect-like rules.
4561 if Nam_In (Pname, Name_Precondition, Name_Postcondition) then
4562 Duplicates_OK := True;
4563 In_Body_OK := True;
4564 end if;
4566 GNAT_Pragma;
4568 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4569 -- argument without an identifier.
4571 if Is_Pre_Post then
4572 Check_Arg_Count (1);
4573 Check_No_Identifiers;
4575 -- Pragmas Precondition and Postcondition have complex argument
4576 -- profile.
4578 else
4579 Check_At_Least_N_Arguments (1);
4580 Check_At_Most_N_Arguments (2);
4581 Check_Optional_Identifier (Arg1, Name_Check);
4583 if Present (Arg2) then
4584 Check_Optional_Identifier (Arg2, Name_Message);
4585 Preanalyze_Spec_Expression
4586 (Get_Pragma_Arg (Arg2), Standard_String);
4587 end if;
4588 end if;
4590 -- For a pragma PPC in the extended main source unit, record enabled
4591 -- status in SCO.
4592 -- ??? nothing checks that the pragma is in the main source unit
4594 if Is_Checked (N) and then not Split_PPC (N) then
4595 Set_SCO_Pragma_Enabled (Loc);
4596 end if;
4598 -- Ensure the proper placement of the pragma
4600 Subp_Decl :=
4601 Find_Related_Declaration_Or_Body
4602 (N, Do_Checks => not Duplicates_OK);
4604 -- When a pre/postcondition pragma applies to an abstract subprogram,
4605 -- its original form must be an aspect with 'Class.
4607 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
4608 if not From_Aspect_Specification (N) then
4609 Error_Pragma
4610 ("pragma % cannot be applied to abstract subprogram");
4612 elsif not Class_Present (N) then
4613 Error_Pragma
4614 ("aspect % requires ''Class for abstract subprogram");
4615 end if;
4617 -- Entry declaration
4619 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
4620 null;
4622 -- Generic subprogram declaration
4624 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4625 null;
4627 -- Subprogram body
4629 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4630 and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK)
4631 then
4632 null;
4634 -- Subprogram body stub
4636 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4637 and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK)
4638 then
4639 null;
4641 -- Subprogram declaration
4643 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4645 -- AI05-0230: When a pre/postcondition pragma applies to a null
4646 -- procedure, its original form must be an aspect with 'Class.
4648 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
4649 and then Null_Present (Specification (Subp_Decl))
4650 and then From_Aspect_Specification (N)
4651 and then not Class_Present (N)
4652 then
4653 Error_Pragma ("aspect % requires ''Class for null procedure");
4654 end if;
4656 -- Implement the legality checks mandated by AI12-0131:
4657 -- Pre'Class shall not be specified for an overriding primitive
4658 -- subprogram of a tagged type T unless the Pre'Class aspect is
4659 -- specified for the corresponding primitive subprogram of some
4660 -- ancestor of T.
4662 declare
4663 E : constant Entity_Id := Defining_Entity (Subp_Decl);
4665 begin
4666 if Class_Present (N)
4667 and then Pragma_Name (N) = Name_Precondition
4668 and then Present (Overridden_Operation (E))
4669 and then not Inherits_Class_Wide_Pre (E)
4670 then
4671 Error_Msg_N
4672 ("illegal class-wide precondition on overriding operation",
4673 Corresponding_Aspect (N));
4674 end if;
4675 end;
4677 -- A renaming declaration may inherit a generated pragma, its
4678 -- placement comes from expansion, not from source.
4680 elsif Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration
4681 and then not Comes_From_Source (N)
4682 then
4683 null;
4685 -- Otherwise the placement is illegal
4687 else
4688 Pragma_Misplaced;
4689 return;
4690 end if;
4692 Subp_Id := Defining_Entity (Subp_Decl);
4694 -- A pragma that applies to a Ghost entity becomes Ghost for the
4695 -- purposes of legality checks and removal of ignored Ghost code.
4697 Mark_Ghost_Pragma (N, Subp_Id);
4699 -- Chain the pragma on the contract for further processing by
4700 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4702 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
4704 -- Fully analyze the pragma when it appears inside an entry or
4705 -- subprogram body because it cannot benefit from forward references.
4707 if Nkind_In (Subp_Decl, N_Entry_Body,
4708 N_Subprogram_Body,
4709 N_Subprogram_Body_Stub)
4710 then
4711 -- The legality checks of pragmas Precondition and Postcondition
4712 -- are affected by the SPARK mode in effect and the volatility of
4713 -- the context. Analyze all pragmas in a specific order.
4715 Analyze_If_Present (Pragma_SPARK_Mode);
4716 Analyze_If_Present (Pragma_Volatile_Function);
4717 Analyze_Pre_Post_Condition_In_Decl_Part (N);
4718 end if;
4719 end Analyze_Pre_Post_Condition;
4721 -----------------------------------------
4722 -- Analyze_Refined_Depends_Global_Post --
4723 -----------------------------------------
4725 procedure Analyze_Refined_Depends_Global_Post
4726 (Spec_Id : out Entity_Id;
4727 Body_Id : out Entity_Id;
4728 Legal : out Boolean)
4730 Body_Decl : Node_Id;
4731 Spec_Decl : Node_Id;
4733 begin
4734 -- Assume that the pragma is illegal
4736 Spec_Id := Empty;
4737 Body_Id := Empty;
4738 Legal := False;
4740 GNAT_Pragma;
4741 Check_Arg_Count (1);
4742 Check_No_Identifiers;
4744 -- Verify the placement of the pragma and check for duplicates. The
4745 -- pragma must apply to a subprogram body [stub].
4747 Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4749 if not Nkind_In (Body_Decl, N_Entry_Body,
4750 N_Subprogram_Body,
4751 N_Subprogram_Body_Stub,
4752 N_Task_Body,
4753 N_Task_Body_Stub)
4754 then
4755 Pragma_Misplaced;
4756 return;
4757 end if;
4759 Body_Id := Defining_Entity (Body_Decl);
4760 Spec_Id := Unique_Defining_Entity (Body_Decl);
4762 -- The pragma must apply to the second declaration of a subprogram.
4763 -- In other words, the body [stub] cannot acts as a spec.
4765 if No (Spec_Id) then
4766 Error_Pragma ("pragma % cannot apply to a stand alone body");
4767 return;
4769 -- Catch the case where the subprogram body is a subunit and acts as
4770 -- the third declaration of the subprogram.
4772 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
4773 Error_Pragma ("pragma % cannot apply to a subunit");
4774 return;
4775 end if;
4777 -- A refined pragma can only apply to the body [stub] of a subprogram
4778 -- declared in the visible part of a package. Retrieve the context of
4779 -- the subprogram declaration.
4781 Spec_Decl := Unit_Declaration_Node (Spec_Id);
4783 -- When dealing with protected entries or protected subprograms, use
4784 -- the enclosing protected type as the proper context.
4786 if Ekind_In (Spec_Id, E_Entry,
4787 E_Entry_Family,
4788 E_Function,
4789 E_Procedure)
4790 and then Ekind (Scope (Spec_Id)) = E_Protected_Type
4791 then
4792 Spec_Decl := Declaration_Node (Scope (Spec_Id));
4793 end if;
4795 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
4796 Error_Pragma
4797 (Fix_Msg (Spec_Id, "pragma % must apply to the body of "
4798 & "subprogram declared in a package specification"));
4799 return;
4800 end if;
4802 -- If we get here, then the pragma is legal
4804 Legal := True;
4806 -- A pragma that applies to a Ghost entity becomes Ghost for the
4807 -- purposes of legality checks and removal of ignored Ghost code.
4809 Mark_Ghost_Pragma (N, Spec_Id);
4811 if Nam_In (Pname, Name_Refined_Depends, Name_Refined_Global) then
4812 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4813 end if;
4814 end Analyze_Refined_Depends_Global_Post;
4816 ----------------------------------
4817 -- Analyze_Unmodified_Or_Unused --
4818 ----------------------------------
4820 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False) is
4821 Arg : Node_Id;
4822 Arg_Expr : Node_Id;
4823 Arg_Id : Entity_Id;
4825 Ghost_Error_Posted : Boolean := False;
4826 -- Flag set when an error concerning the illegal mix of Ghost and
4827 -- non-Ghost variables is emitted.
4829 Ghost_Id : Entity_Id := Empty;
4830 -- The entity of the first Ghost variable encountered while
4831 -- processing the arguments of the pragma.
4833 begin
4834 GNAT_Pragma;
4835 Check_At_Least_N_Arguments (1);
4837 -- Loop through arguments
4839 Arg := Arg1;
4840 while Present (Arg) loop
4841 Check_No_Identifier (Arg);
4843 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4844 -- in fact generate reference, so that the entity will have a
4845 -- reference, which will inhibit any warnings about it not
4846 -- being referenced, and also properly show up in the ali file
4847 -- as a reference. But this reference is recorded before the
4848 -- Has_Pragma_Unreferenced flag is set, so that no warning is
4849 -- generated for this reference.
4851 Check_Arg_Is_Local_Name (Arg);
4852 Arg_Expr := Get_Pragma_Arg (Arg);
4854 if Is_Entity_Name (Arg_Expr) then
4855 Arg_Id := Entity (Arg_Expr);
4857 -- Skip processing the argument if already flagged
4859 if Is_Assignable (Arg_Id)
4860 and then not Has_Pragma_Unmodified (Arg_Id)
4861 and then not Has_Pragma_Unused (Arg_Id)
4862 then
4863 Set_Has_Pragma_Unmodified (Arg_Id);
4865 if Is_Unused then
4866 Set_Has_Pragma_Unused (Arg_Id);
4867 end if;
4869 -- A pragma that applies to a Ghost entity becomes Ghost for
4870 -- the purposes of legality checks and removal of ignored
4871 -- Ghost code.
4873 Mark_Ghost_Pragma (N, Arg_Id);
4875 -- Capture the entity of the first Ghost variable being
4876 -- processed for error detection purposes.
4878 if Is_Ghost_Entity (Arg_Id) then
4879 if No (Ghost_Id) then
4880 Ghost_Id := Arg_Id;
4881 end if;
4883 -- Otherwise the variable is non-Ghost. It is illegal to mix
4884 -- references to Ghost and non-Ghost entities
4885 -- (SPARK RM 6.9).
4887 elsif Present (Ghost_Id)
4888 and then not Ghost_Error_Posted
4889 then
4890 Ghost_Error_Posted := True;
4892 Error_Msg_Name_1 := Pname;
4893 Error_Msg_N
4894 ("pragma % cannot mention ghost and non-ghost "
4895 & "variables", N);
4897 Error_Msg_Sloc := Sloc (Ghost_Id);
4898 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
4900 Error_Msg_Sloc := Sloc (Arg_Id);
4901 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
4902 end if;
4904 -- Warn if already flagged as Unused or Unmodified
4906 elsif Has_Pragma_Unmodified (Arg_Id) then
4907 if Has_Pragma_Unused (Arg_Id) then
4908 Error_Msg_NE
4909 ("??pragma Unused already given for &!", Arg_Expr,
4910 Arg_Id);
4911 else
4912 Error_Msg_NE
4913 ("??pragma Unmodified already given for &!", Arg_Expr,
4914 Arg_Id);
4915 end if;
4917 -- Otherwise the pragma referenced an illegal entity
4919 else
4920 Error_Pragma_Arg
4921 ("pragma% can only be applied to a variable", Arg_Expr);
4922 end if;
4923 end if;
4925 Next (Arg);
4926 end loop;
4927 end Analyze_Unmodified_Or_Unused;
4929 ------------------------------------
4930 -- Analyze_Unreferenced_Or_Unused --
4931 ------------------------------------
4933 procedure Analyze_Unreferenced_Or_Unused
4934 (Is_Unused : Boolean := False)
4936 Arg : Node_Id;
4937 Arg_Expr : Node_Id;
4938 Arg_Id : Entity_Id;
4939 Citem : Node_Id;
4941 Ghost_Error_Posted : Boolean := False;
4942 -- Flag set when an error concerning the illegal mix of Ghost and
4943 -- non-Ghost names is emitted.
4945 Ghost_Id : Entity_Id := Empty;
4946 -- The entity of the first Ghost name encountered while processing
4947 -- the arguments of the pragma.
4949 begin
4950 GNAT_Pragma;
4951 Check_At_Least_N_Arguments (1);
4953 -- Check case of appearing within context clause
4955 if not Is_Unused and then Is_In_Context_Clause then
4957 -- The arguments must all be units mentioned in a with clause in
4958 -- the same context clause. Note that Par.Prag already checked
4959 -- that the arguments are either identifiers or selected
4960 -- components.
4962 Arg := Arg1;
4963 while Present (Arg) loop
4964 Citem := First (List_Containing (N));
4965 while Citem /= N loop
4966 Arg_Expr := Get_Pragma_Arg (Arg);
4968 if Nkind (Citem) = N_With_Clause
4969 and then Same_Name (Name (Citem), Arg_Expr)
4970 then
4971 Set_Has_Pragma_Unreferenced
4972 (Cunit_Entity
4973 (Get_Source_Unit
4974 (Library_Unit (Citem))));
4975 Set_Elab_Unit_Name (Arg_Expr, Name (Citem));
4976 exit;
4977 end if;
4979 Next (Citem);
4980 end loop;
4982 if Citem = N then
4983 Error_Pragma_Arg
4984 ("argument of pragma% is not withed unit", Arg);
4985 end if;
4987 Next (Arg);
4988 end loop;
4990 -- Case of not in list of context items
4992 else
4993 Arg := Arg1;
4994 while Present (Arg) loop
4995 Check_No_Identifier (Arg);
4997 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4998 -- in fact generate reference, so that the entity will have a
4999 -- reference, which will inhibit any warnings about it not
5000 -- being referenced, and also properly show up in the ali file
5001 -- as a reference. But this reference is recorded before the
5002 -- Has_Pragma_Unreferenced flag is set, so that no warning is
5003 -- generated for this reference.
5005 Check_Arg_Is_Local_Name (Arg);
5006 Arg_Expr := Get_Pragma_Arg (Arg);
5008 if Is_Entity_Name (Arg_Expr) then
5009 Arg_Id := Entity (Arg_Expr);
5011 -- Warn if already flagged as Unused or Unreferenced and
5012 -- skip processing the argument.
5014 if Has_Pragma_Unreferenced (Arg_Id) then
5015 if Has_Pragma_Unused (Arg_Id) then
5016 Error_Msg_NE
5017 ("??pragma Unused already given for &!", Arg_Expr,
5018 Arg_Id);
5019 else
5020 Error_Msg_NE
5021 ("??pragma Unreferenced already given for &!",
5022 Arg_Expr, Arg_Id);
5023 end if;
5025 -- Apply Unreferenced to the entity
5027 else
5028 -- If the entity is overloaded, the pragma applies to the
5029 -- most recent overloading, as documented. In this case,
5030 -- name resolution does not generate a reference, so it
5031 -- must be done here explicitly.
5033 if Is_Overloaded (Arg_Expr) then
5034 Generate_Reference (Arg_Id, N);
5035 end if;
5037 Set_Has_Pragma_Unreferenced (Arg_Id);
5039 if Is_Unused then
5040 Set_Has_Pragma_Unused (Arg_Id);
5041 end if;
5043 -- A pragma that applies to a Ghost entity becomes Ghost
5044 -- for the purposes of legality checks and removal of
5045 -- ignored Ghost code.
5047 Mark_Ghost_Pragma (N, Arg_Id);
5049 -- Capture the entity of the first Ghost name being
5050 -- processed for error detection purposes.
5052 if Is_Ghost_Entity (Arg_Id) then
5053 if No (Ghost_Id) then
5054 Ghost_Id := Arg_Id;
5055 end if;
5057 -- Otherwise the name is non-Ghost. It is illegal to mix
5058 -- references to Ghost and non-Ghost entities
5059 -- (SPARK RM 6.9).
5061 elsif Present (Ghost_Id)
5062 and then not Ghost_Error_Posted
5063 then
5064 Ghost_Error_Posted := True;
5066 Error_Msg_Name_1 := Pname;
5067 Error_Msg_N
5068 ("pragma % cannot mention ghost and non-ghost "
5069 & "names", N);
5071 Error_Msg_Sloc := Sloc (Ghost_Id);
5072 Error_Msg_NE
5073 ("\& # declared as ghost", N, Ghost_Id);
5075 Error_Msg_Sloc := Sloc (Arg_Id);
5076 Error_Msg_NE
5077 ("\& # declared as non-ghost", N, Arg_Id);
5078 end if;
5079 end if;
5080 end if;
5082 Next (Arg);
5083 end loop;
5084 end if;
5085 end Analyze_Unreferenced_Or_Unused;
5087 --------------------------
5088 -- Check_Ada_83_Warning --
5089 --------------------------
5091 procedure Check_Ada_83_Warning is
5092 begin
5093 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5094 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
5095 end if;
5096 end Check_Ada_83_Warning;
5098 ---------------------
5099 -- Check_Arg_Count --
5100 ---------------------
5102 procedure Check_Arg_Count (Required : Nat) is
5103 begin
5104 if Arg_Count /= Required then
5105 Error_Pragma ("wrong number of arguments for pragma%");
5106 end if;
5107 end Check_Arg_Count;
5109 --------------------------------
5110 -- Check_Arg_Is_External_Name --
5111 --------------------------------
5113 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
5114 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5116 begin
5117 if Nkind (Argx) = N_Identifier then
5118 return;
5120 else
5121 Analyze_And_Resolve (Argx, Standard_String);
5123 if Is_OK_Static_Expression (Argx) then
5124 return;
5126 elsif Etype (Argx) = Any_Type then
5127 raise Pragma_Exit;
5129 -- An interesting special case, if we have a string literal and
5130 -- we are in Ada 83 mode, then we allow it even though it will
5131 -- not be flagged as static. This allows expected Ada 83 mode
5132 -- use of external names which are string literals, even though
5133 -- technically these are not static in Ada 83.
5135 elsif Ada_Version = Ada_83
5136 and then Nkind (Argx) = N_String_Literal
5137 then
5138 return;
5140 -- Here we have a real error (non-static expression)
5142 else
5143 Error_Msg_Name_1 := Pname;
5144 Flag_Non_Static_Expr
5145 (Fix_Error ("argument for pragma% must be a identifier or "
5146 & "static string expression!"), Argx);
5148 raise Pragma_Exit;
5149 end if;
5150 end if;
5151 end Check_Arg_Is_External_Name;
5153 -----------------------------
5154 -- Check_Arg_Is_Identifier --
5155 -----------------------------
5157 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
5158 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5159 begin
5160 if Nkind (Argx) /= N_Identifier then
5161 Error_Pragma_Arg ("argument for pragma% must be identifier", Argx);
5162 end if;
5163 end Check_Arg_Is_Identifier;
5165 ----------------------------------
5166 -- Check_Arg_Is_Integer_Literal --
5167 ----------------------------------
5169 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
5170 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5171 begin
5172 if Nkind (Argx) /= N_Integer_Literal then
5173 Error_Pragma_Arg
5174 ("argument for pragma% must be integer literal", Argx);
5175 end if;
5176 end Check_Arg_Is_Integer_Literal;
5178 -------------------------------------------
5179 -- Check_Arg_Is_Library_Level_Local_Name --
5180 -------------------------------------------
5182 -- LOCAL_NAME ::=
5183 -- DIRECT_NAME
5184 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5185 -- | library_unit_NAME
5187 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
5188 begin
5189 Check_Arg_Is_Local_Name (Arg);
5191 -- If it came from an aspect, we want to give the error just as if it
5192 -- came from source.
5194 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
5195 and then (Comes_From_Source (N)
5196 or else Present (Corresponding_Aspect (Parent (Arg))))
5197 then
5198 Error_Pragma_Arg
5199 ("argument for pragma% must be library level entity", Arg);
5200 end if;
5201 end Check_Arg_Is_Library_Level_Local_Name;
5203 -----------------------------
5204 -- Check_Arg_Is_Local_Name --
5205 -----------------------------
5207 -- LOCAL_NAME ::=
5208 -- DIRECT_NAME
5209 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5210 -- | library_unit_NAME
5212 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
5213 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5215 begin
5216 -- If this pragma came from an aspect specification, we don't want to
5217 -- check for this error, because that would cause spurious errors, in
5218 -- case a type is frozen in a scope more nested than the type. The
5219 -- aspect itself of course can't be anywhere but on the declaration
5220 -- itself.
5222 if Nkind (Arg) = N_Pragma_Argument_Association then
5223 if From_Aspect_Specification (Parent (Arg)) then
5224 return;
5225 end if;
5227 -- Arg is the Expression of an N_Pragma_Argument_Association
5229 else
5230 if From_Aspect_Specification (Parent (Parent (Arg))) then
5231 return;
5232 end if;
5233 end if;
5235 Analyze (Argx);
5237 if Nkind (Argx) not in N_Direct_Name
5238 and then (Nkind (Argx) /= N_Attribute_Reference
5239 or else Present (Expressions (Argx))
5240 or else Nkind (Prefix (Argx)) /= N_Identifier)
5241 and then (not Is_Entity_Name (Argx)
5242 or else not Is_Compilation_Unit (Entity (Argx)))
5243 then
5244 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
5245 end if;
5247 -- No further check required if not an entity name
5249 if not Is_Entity_Name (Argx) then
5250 null;
5252 else
5253 declare
5254 OK : Boolean;
5255 Ent : constant Entity_Id := Entity (Argx);
5256 Scop : constant Entity_Id := Scope (Ent);
5258 begin
5259 -- Case of a pragma applied to a compilation unit: pragma must
5260 -- occur immediately after the program unit in the compilation.
5262 if Is_Compilation_Unit (Ent) then
5263 declare
5264 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
5266 begin
5267 -- Case of pragma placed immediately after spec
5269 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
5270 OK := True;
5272 -- Case of pragma placed immediately after body
5274 elsif Nkind (Decl) = N_Subprogram_Declaration
5275 and then Present (Corresponding_Body (Decl))
5276 then
5277 OK := Parent (N) =
5278 Aux_Decls_Node
5279 (Parent (Unit_Declaration_Node
5280 (Corresponding_Body (Decl))));
5282 -- All other cases are illegal
5284 else
5285 OK := False;
5286 end if;
5287 end;
5289 -- Special restricted placement rule from 10.2.1(11.8/2)
5291 elsif Is_Generic_Formal (Ent)
5292 and then Prag_Id = Pragma_Preelaborable_Initialization
5293 then
5294 OK := List_Containing (N) =
5295 Generic_Formal_Declarations
5296 (Unit_Declaration_Node (Scop));
5298 -- If this is an aspect applied to a subprogram body, the
5299 -- pragma is inserted in its declarative part.
5301 elsif From_Aspect_Specification (N)
5302 and then Ent = Current_Scope
5303 and then
5304 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
5305 then
5306 OK := True;
5308 -- If the aspect is a predicate (possibly others ???) and the
5309 -- context is a record type, this is a discriminant expression
5310 -- within a type declaration, that freezes the predicated
5311 -- subtype.
5313 elsif From_Aspect_Specification (N)
5314 and then Prag_Id = Pragma_Predicate
5315 and then Ekind (Current_Scope) = E_Record_Type
5316 and then Scop = Scope (Current_Scope)
5317 then
5318 OK := True;
5320 -- Default case, just check that the pragma occurs in the scope
5321 -- of the entity denoted by the name.
5323 else
5324 OK := Current_Scope = Scop;
5325 end if;
5327 if not OK then
5328 Error_Pragma_Arg
5329 ("pragma% argument must be in same declarative part", Arg);
5330 end if;
5331 end;
5332 end if;
5333 end Check_Arg_Is_Local_Name;
5335 ---------------------------------
5336 -- Check_Arg_Is_Locking_Policy --
5337 ---------------------------------
5339 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
5340 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5342 begin
5343 Check_Arg_Is_Identifier (Argx);
5345 if not Is_Locking_Policy_Name (Chars (Argx)) then
5346 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
5347 end if;
5348 end Check_Arg_Is_Locking_Policy;
5350 -----------------------------------------------
5351 -- Check_Arg_Is_Partition_Elaboration_Policy --
5352 -----------------------------------------------
5354 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
5355 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5357 begin
5358 Check_Arg_Is_Identifier (Argx);
5360 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
5361 Error_Pragma_Arg
5362 ("& is not a valid partition elaboration policy name", Argx);
5363 end if;
5364 end Check_Arg_Is_Partition_Elaboration_Policy;
5366 -------------------------
5367 -- Check_Arg_Is_One_Of --
5368 -------------------------
5370 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5371 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5373 begin
5374 Check_Arg_Is_Identifier (Argx);
5376 if not Nam_In (Chars (Argx), N1, N2) then
5377 Error_Msg_Name_2 := N1;
5378 Error_Msg_Name_3 := N2;
5379 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
5380 end if;
5381 end Check_Arg_Is_One_Of;
5383 procedure Check_Arg_Is_One_Of
5384 (Arg : Node_Id;
5385 N1, N2, N3 : Name_Id)
5387 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5389 begin
5390 Check_Arg_Is_Identifier (Argx);
5392 if not Nam_In (Chars (Argx), N1, N2, N3) then
5393 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5394 end if;
5395 end Check_Arg_Is_One_Of;
5397 procedure Check_Arg_Is_One_Of
5398 (Arg : Node_Id;
5399 N1, N2, N3, N4 : Name_Id)
5401 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5403 begin
5404 Check_Arg_Is_Identifier (Argx);
5406 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
5407 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5408 end if;
5409 end Check_Arg_Is_One_Of;
5411 procedure Check_Arg_Is_One_Of
5412 (Arg : Node_Id;
5413 N1, N2, N3, N4, N5 : Name_Id)
5415 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5417 begin
5418 Check_Arg_Is_Identifier (Argx);
5420 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
5421 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5422 end if;
5423 end Check_Arg_Is_One_Of;
5425 ---------------------------------
5426 -- Check_Arg_Is_Queuing_Policy --
5427 ---------------------------------
5429 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
5430 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5432 begin
5433 Check_Arg_Is_Identifier (Argx);
5435 if not Is_Queuing_Policy_Name (Chars (Argx)) then
5436 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
5437 end if;
5438 end Check_Arg_Is_Queuing_Policy;
5440 ---------------------------------------
5441 -- Check_Arg_Is_OK_Static_Expression --
5442 ---------------------------------------
5444 procedure Check_Arg_Is_OK_Static_Expression
5445 (Arg : Node_Id;
5446 Typ : Entity_Id := Empty)
5448 begin
5449 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
5450 end Check_Arg_Is_OK_Static_Expression;
5452 ------------------------------------------
5453 -- Check_Arg_Is_Task_Dispatching_Policy --
5454 ------------------------------------------
5456 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
5457 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5459 begin
5460 Check_Arg_Is_Identifier (Argx);
5462 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
5463 Error_Pragma_Arg
5464 ("& is not an allowed task dispatching policy name", Argx);
5465 end if;
5466 end Check_Arg_Is_Task_Dispatching_Policy;
5468 ---------------------
5469 -- Check_Arg_Order --
5470 ---------------------
5472 procedure Check_Arg_Order (Names : Name_List) is
5473 Arg : Node_Id;
5475 Highest_So_Far : Natural := 0;
5476 -- Highest index in Names seen do far
5478 begin
5479 Arg := Arg1;
5480 for J in 1 .. Arg_Count loop
5481 if Chars (Arg) /= No_Name then
5482 for K in Names'Range loop
5483 if Chars (Arg) = Names (K) then
5484 if K < Highest_So_Far then
5485 Error_Msg_Name_1 := Pname;
5486 Error_Msg_N
5487 ("parameters out of order for pragma%", Arg);
5488 Error_Msg_Name_1 := Names (K);
5489 Error_Msg_Name_2 := Names (Highest_So_Far);
5490 Error_Msg_N ("\% must appear before %", Arg);
5491 raise Pragma_Exit;
5493 else
5494 Highest_So_Far := K;
5495 end if;
5496 end if;
5497 end loop;
5498 end if;
5500 Arg := Next (Arg);
5501 end loop;
5502 end Check_Arg_Order;
5504 --------------------------------
5505 -- Check_At_Least_N_Arguments --
5506 --------------------------------
5508 procedure Check_At_Least_N_Arguments (N : Nat) is
5509 begin
5510 if Arg_Count < N then
5511 Error_Pragma ("too few arguments for pragma%");
5512 end if;
5513 end Check_At_Least_N_Arguments;
5515 -------------------------------
5516 -- Check_At_Most_N_Arguments --
5517 -------------------------------
5519 procedure Check_At_Most_N_Arguments (N : Nat) is
5520 Arg : Node_Id;
5521 begin
5522 if Arg_Count > N then
5523 Arg := Arg1;
5524 for J in 1 .. N loop
5525 Next (Arg);
5526 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
5527 end loop;
5528 end if;
5529 end Check_At_Most_N_Arguments;
5531 ---------------------
5532 -- Check_Component --
5533 ---------------------
5535 procedure Check_Component
5536 (Comp : Node_Id;
5537 UU_Typ : Entity_Id;
5538 In_Variant_Part : Boolean := False)
5540 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
5541 Sindic : constant Node_Id :=
5542 Subtype_Indication (Component_Definition (Comp));
5543 Typ : constant Entity_Id := Etype (Comp_Id);
5545 begin
5546 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
5547 -- object constraint, then the component type shall be an Unchecked_
5548 -- Union.
5550 if Nkind (Sindic) = N_Subtype_Indication
5551 and then Has_Per_Object_Constraint (Comp_Id)
5552 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
5553 then
5554 Error_Msg_N
5555 ("component subtype subject to per-object constraint "
5556 & "must be an Unchecked_Union", Comp);
5558 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
5559 -- the body of a generic unit, or within the body of any of its
5560 -- descendant library units, no part of the type of a component
5561 -- declared in a variant_part of the unchecked union type shall be of
5562 -- a formal private type or formal private extension declared within
5563 -- the formal part of the generic unit.
5565 elsif Ada_Version >= Ada_2012
5566 and then In_Generic_Body (UU_Typ)
5567 and then In_Variant_Part
5568 and then Is_Private_Type (Typ)
5569 and then Is_Generic_Type (Typ)
5570 then
5571 Error_Msg_N
5572 ("component of unchecked union cannot be of generic type", Comp);
5574 elsif Needs_Finalization (Typ) then
5575 Error_Msg_N
5576 ("component of unchecked union cannot be controlled", Comp);
5578 elsif Has_Task (Typ) then
5579 Error_Msg_N
5580 ("component of unchecked union cannot have tasks", Comp);
5581 end if;
5582 end Check_Component;
5584 ----------------------------
5585 -- Check_Duplicate_Pragma --
5586 ----------------------------
5588 procedure Check_Duplicate_Pragma (E : Entity_Id) is
5589 Id : Entity_Id := E;
5590 P : Node_Id;
5592 begin
5593 -- Nothing to do if this pragma comes from an aspect specification,
5594 -- since we could not be duplicating a pragma, and we dealt with the
5595 -- case of duplicated aspects in Analyze_Aspect_Specifications.
5597 if From_Aspect_Specification (N) then
5598 return;
5599 end if;
5601 -- Otherwise current pragma may duplicate previous pragma or a
5602 -- previously given aspect specification or attribute definition
5603 -- clause for the same pragma.
5605 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
5607 if Present (P) then
5609 -- If the entity is a type, then we have to make sure that the
5610 -- ostensible duplicate is not for a parent type from which this
5611 -- type is derived.
5613 if Is_Type (E) then
5614 if Nkind (P) = N_Pragma then
5615 declare
5616 Args : constant List_Id :=
5617 Pragma_Argument_Associations (P);
5618 begin
5619 if Present (Args)
5620 and then Is_Entity_Name (Expression (First (Args)))
5621 and then Is_Type (Entity (Expression (First (Args))))
5622 and then Entity (Expression (First (Args))) /= E
5623 then
5624 return;
5625 end if;
5626 end;
5628 elsif Nkind (P) = N_Aspect_Specification
5629 and then Is_Type (Entity (P))
5630 and then Entity (P) /= E
5631 then
5632 return;
5633 end if;
5634 end if;
5636 -- Here we have a definite duplicate
5638 Error_Msg_Name_1 := Pragma_Name (N);
5639 Error_Msg_Sloc := Sloc (P);
5641 -- For a single protected or a single task object, the error is
5642 -- issued on the original entity.
5644 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
5645 Id := Defining_Identifier (Original_Node (Parent (Id)));
5646 end if;
5648 if Nkind (P) = N_Aspect_Specification
5649 or else From_Aspect_Specification (P)
5650 then
5651 Error_Msg_NE ("aspect% for & previously given#", N, Id);
5652 else
5653 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
5654 end if;
5656 raise Pragma_Exit;
5657 end if;
5658 end Check_Duplicate_Pragma;
5660 ----------------------------------
5661 -- Check_Duplicated_Export_Name --
5662 ----------------------------------
5664 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
5665 String_Val : constant String_Id := Strval (Nam);
5667 begin
5668 -- We are only interested in the export case, and in the case of
5669 -- generics, it is the instance, not the template, that is the
5670 -- problem (the template will generate a warning in any case).
5672 if not Inside_A_Generic
5673 and then (Prag_Id = Pragma_Export
5674 or else
5675 Prag_Id = Pragma_Export_Procedure
5676 or else
5677 Prag_Id = Pragma_Export_Valued_Procedure
5678 or else
5679 Prag_Id = Pragma_Export_Function)
5680 then
5681 for J in Externals.First .. Externals.Last loop
5682 if String_Equal (String_Val, Strval (Externals.Table (J))) then
5683 Error_Msg_Sloc := Sloc (Externals.Table (J));
5684 Error_Msg_N ("external name duplicates name given#", Nam);
5685 exit;
5686 end if;
5687 end loop;
5689 Externals.Append (Nam);
5690 end if;
5691 end Check_Duplicated_Export_Name;
5693 ----------------------------------------
5694 -- Check_Expr_Is_OK_Static_Expression --
5695 ----------------------------------------
5697 procedure Check_Expr_Is_OK_Static_Expression
5698 (Expr : Node_Id;
5699 Typ : Entity_Id := Empty)
5701 begin
5702 if Present (Typ) then
5703 Analyze_And_Resolve (Expr, Typ);
5704 else
5705 Analyze_And_Resolve (Expr);
5706 end if;
5708 -- An expression cannot be considered static if its resolution failed
5709 -- or if it's erroneous. Stop the analysis of the related pragma.
5711 if Etype (Expr) = Any_Type or else Error_Posted (Expr) then
5712 raise Pragma_Exit;
5714 elsif Is_OK_Static_Expression (Expr) then
5715 return;
5717 -- An interesting special case, if we have a string literal and we
5718 -- are in Ada 83 mode, then we allow it even though it will not be
5719 -- flagged as static. This allows the use of Ada 95 pragmas like
5720 -- Import in Ada 83 mode. They will of course be flagged with
5721 -- warnings as usual, but will not cause errors.
5723 elsif Ada_Version = Ada_83
5724 and then Nkind (Expr) = N_String_Literal
5725 then
5726 return;
5728 -- Finally, we have a real error
5730 else
5731 Error_Msg_Name_1 := Pname;
5732 Flag_Non_Static_Expr
5733 (Fix_Error ("argument for pragma% must be a static expression!"),
5734 Expr);
5735 raise Pragma_Exit;
5736 end if;
5737 end Check_Expr_Is_OK_Static_Expression;
5739 -------------------------
5740 -- Check_First_Subtype --
5741 -------------------------
5743 procedure Check_First_Subtype (Arg : Node_Id) is
5744 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5745 Ent : constant Entity_Id := Entity (Argx);
5747 begin
5748 if Is_First_Subtype (Ent) then
5749 null;
5751 elsif Is_Type (Ent) then
5752 Error_Pragma_Arg
5753 ("pragma% cannot apply to subtype", Argx);
5755 elsif Is_Object (Ent) then
5756 Error_Pragma_Arg
5757 ("pragma% cannot apply to object, requires a type", Argx);
5759 else
5760 Error_Pragma_Arg
5761 ("pragma% cannot apply to&, requires a type", Argx);
5762 end if;
5763 end Check_First_Subtype;
5765 ----------------------
5766 -- Check_Identifier --
5767 ----------------------
5769 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
5770 begin
5771 if Present (Arg)
5772 and then Nkind (Arg) = N_Pragma_Argument_Association
5773 then
5774 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
5775 Error_Msg_Name_1 := Pname;
5776 Error_Msg_Name_2 := Id;
5777 Error_Msg_N ("pragma% argument expects identifier%", Arg);
5778 raise Pragma_Exit;
5779 end if;
5780 end if;
5781 end Check_Identifier;
5783 --------------------------------
5784 -- Check_Identifier_Is_One_Of --
5785 --------------------------------
5787 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5788 begin
5789 if Present (Arg)
5790 and then Nkind (Arg) = N_Pragma_Argument_Association
5791 then
5792 if Chars (Arg) = No_Name then
5793 Error_Msg_Name_1 := Pname;
5794 Error_Msg_N ("pragma% argument expects an identifier", Arg);
5795 raise Pragma_Exit;
5797 elsif Chars (Arg) /= N1
5798 and then Chars (Arg) /= N2
5799 then
5800 Error_Msg_Name_1 := Pname;
5801 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
5802 raise Pragma_Exit;
5803 end if;
5804 end if;
5805 end Check_Identifier_Is_One_Of;
5807 ---------------------------
5808 -- Check_In_Main_Program --
5809 ---------------------------
5811 procedure Check_In_Main_Program is
5812 P : constant Node_Id := Parent (N);
5814 begin
5815 -- Must be in subprogram body
5817 if Nkind (P) /= N_Subprogram_Body then
5818 Error_Pragma ("% pragma allowed only in subprogram");
5820 -- Otherwise warn if obviously not main program
5822 elsif Present (Parameter_Specifications (Specification (P)))
5823 or else not Is_Compilation_Unit (Defining_Entity (P))
5824 then
5825 Error_Msg_Name_1 := Pname;
5826 Error_Msg_N
5827 ("??pragma% is only effective in main program", N);
5828 end if;
5829 end Check_In_Main_Program;
5831 ---------------------------------------
5832 -- Check_Interrupt_Or_Attach_Handler --
5833 ---------------------------------------
5835 procedure Check_Interrupt_Or_Attach_Handler is
5836 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5837 Handler_Proc, Proc_Scope : Entity_Id;
5839 begin
5840 Analyze (Arg1_X);
5842 if Prag_Id = Pragma_Interrupt_Handler then
5843 Check_Restriction (No_Dynamic_Attachment, N);
5844 end if;
5846 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
5847 Proc_Scope := Scope (Handler_Proc);
5849 if Ekind (Proc_Scope) /= E_Protected_Type then
5850 Error_Pragma_Arg
5851 ("argument of pragma% must be protected procedure", Arg1);
5852 end if;
5854 -- For pragma case (as opposed to access case), check placement.
5855 -- We don't need to do that for aspects, because we have the
5856 -- check that they aspect applies an appropriate procedure.
5858 if not From_Aspect_Specification (N)
5859 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
5860 then
5861 Error_Pragma ("pragma% must be in protected definition");
5862 end if;
5864 if not Is_Library_Level_Entity (Proc_Scope) then
5865 Error_Pragma_Arg
5866 ("argument for pragma% must be library level entity", Arg1);
5867 end if;
5869 -- AI05-0033: A pragma cannot appear within a generic body, because
5870 -- instance can be in a nested scope. The check that protected type
5871 -- is itself a library-level declaration is done elsewhere.
5873 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
5874 -- handle code prior to AI-0033. Analysis tools typically are not
5875 -- interested in this pragma in any case, so no need to worry too
5876 -- much about its placement.
5878 if Inside_A_Generic then
5879 if Ekind (Scope (Current_Scope)) = E_Generic_Package
5880 and then In_Package_Body (Scope (Current_Scope))
5881 and then not Relaxed_RM_Semantics
5882 then
5883 Error_Pragma ("pragma% cannot be used inside a generic");
5884 end if;
5885 end if;
5886 end Check_Interrupt_Or_Attach_Handler;
5888 ---------------------------------
5889 -- Check_Loop_Pragma_Placement --
5890 ---------------------------------
5892 procedure Check_Loop_Pragma_Placement is
5893 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
5894 -- Verify whether the current pragma is properly grouped with other
5895 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
5896 -- related loop where the pragma appears.
5898 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
5899 -- Determine whether an arbitrary statement Stmt denotes pragma
5900 -- Loop_Invariant or Loop_Variant.
5902 procedure Placement_Error (Constr : Node_Id);
5903 pragma No_Return (Placement_Error);
5904 -- Node Constr denotes the last loop restricted construct before we
5905 -- encountered an illegal relation between enclosing constructs. Emit
5906 -- an error depending on what Constr was.
5908 --------------------------------
5909 -- Check_Loop_Pragma_Grouping --
5910 --------------------------------
5912 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
5913 Stop_Search : exception;
5914 -- This exception is used to terminate the recursive descent of
5915 -- routine Check_Grouping.
5917 procedure Check_Grouping (L : List_Id);
5918 -- Find the first group of pragmas in list L and if successful,
5919 -- ensure that the current pragma is part of that group. The
5920 -- routine raises Stop_Search once such a check is performed to
5921 -- halt the recursive descent.
5923 procedure Grouping_Error (Prag : Node_Id);
5924 pragma No_Return (Grouping_Error);
5925 -- Emit an error concerning the current pragma indicating that it
5926 -- should be placed after pragma Prag.
5928 --------------------
5929 -- Check_Grouping --
5930 --------------------
5932 procedure Check_Grouping (L : List_Id) is
5933 HSS : Node_Id;
5934 Stmt : Node_Id;
5935 Prag : Node_Id := Empty; -- init to avoid warning
5937 begin
5938 -- Inspect the list of declarations or statements looking for
5939 -- the first grouping of pragmas:
5941 -- loop
5942 -- pragma Loop_Invariant ...;
5943 -- pragma Loop_Variant ...;
5944 -- . . . -- (1)
5945 -- pragma Loop_Variant ...; -- current pragma
5947 -- If the current pragma is not in the grouping, then it must
5948 -- either appear in a different declarative or statement list
5949 -- or the construct at (1) is separating the pragma from the
5950 -- grouping.
5952 Stmt := First (L);
5953 while Present (Stmt) loop
5955 -- First pragma of the first topmost grouping has been found
5957 if Is_Loop_Pragma (Stmt) then
5959 -- The group and the current pragma are not in the same
5960 -- declarative or statement list.
5962 if List_Containing (Stmt) /= List_Containing (N) then
5963 Grouping_Error (Stmt);
5965 -- Try to reach the current pragma from the first pragma
5966 -- of the grouping while skipping other members:
5968 -- pragma Loop_Invariant ...; -- first pragma
5969 -- pragma Loop_Variant ...; -- member
5970 -- . . .
5971 -- pragma Loop_Variant ...; -- current pragma
5973 else
5974 while Present (Stmt) loop
5975 -- The current pragma is either the first pragma
5976 -- of the group or is a member of the group.
5977 -- Stop the search as the placement is legal.
5979 if Stmt = N then
5980 raise Stop_Search;
5982 -- Skip group members, but keep track of the
5983 -- last pragma in the group.
5985 elsif Is_Loop_Pragma (Stmt) then
5986 Prag := Stmt;
5988 -- Skip declarations and statements generated by
5989 -- the compiler during expansion. Note that some
5990 -- source statements (e.g. pragma Assert) may have
5991 -- been transformed so that they do not appear as
5992 -- coming from source anymore, so we instead look
5993 -- at their Original_Node.
5995 elsif not Comes_From_Source (Original_Node (Stmt))
5996 then
5997 null;
5999 -- A non-pragma is separating the group from the
6000 -- current pragma, the placement is illegal.
6002 else
6003 Grouping_Error (Prag);
6004 end if;
6006 Next (Stmt);
6007 end loop;
6009 -- If the traversal did not reach the current pragma,
6010 -- then the list must be malformed.
6012 raise Program_Error;
6013 end if;
6015 -- Pragmas Loop_Invariant and Loop_Variant may only appear
6016 -- inside a loop or a block housed inside a loop. Inspect
6017 -- the declarations and statements of the block as they may
6018 -- contain the first grouping. This case follows the one for
6019 -- loop pragmas, as block statements which originate in a
6020 -- loop pragma (and so Is_Loop_Pragma will return True on
6021 -- that block statement) should be treated in the previous
6022 -- case.
6024 elsif Nkind (Stmt) = N_Block_Statement then
6025 HSS := Handled_Statement_Sequence (Stmt);
6027 Check_Grouping (Declarations (Stmt));
6029 if Present (HSS) then
6030 Check_Grouping (Statements (HSS));
6031 end if;
6032 end if;
6034 Next (Stmt);
6035 end loop;
6036 end Check_Grouping;
6038 --------------------
6039 -- Grouping_Error --
6040 --------------------
6042 procedure Grouping_Error (Prag : Node_Id) is
6043 begin
6044 Error_Msg_Sloc := Sloc (Prag);
6045 Error_Pragma ("pragma% must appear next to pragma#");
6046 end Grouping_Error;
6048 -- Start of processing for Check_Loop_Pragma_Grouping
6050 begin
6051 -- Inspect the statements of the loop or nested blocks housed
6052 -- within to determine whether the current pragma is part of the
6053 -- first topmost grouping of Loop_Invariant and Loop_Variant.
6055 Check_Grouping (Statements (Loop_Stmt));
6057 exception
6058 when Stop_Search => null;
6059 end Check_Loop_Pragma_Grouping;
6061 --------------------
6062 -- Is_Loop_Pragma --
6063 --------------------
6065 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
6066 begin
6067 -- Inspect the original node as Loop_Invariant and Loop_Variant
6068 -- pragmas are rewritten to null when assertions are disabled.
6070 if Nkind (Original_Node (Stmt)) = N_Pragma then
6071 return
6072 Nam_In (Pragma_Name_Unmapped (Original_Node (Stmt)),
6073 Name_Loop_Invariant,
6074 Name_Loop_Variant);
6075 else
6076 return False;
6077 end if;
6078 end Is_Loop_Pragma;
6080 ---------------------
6081 -- Placement_Error --
6082 ---------------------
6084 procedure Placement_Error (Constr : Node_Id) is
6085 LA : constant String := " with Loop_Entry";
6087 begin
6088 if Prag_Id = Pragma_Assert then
6089 Error_Msg_String (1 .. LA'Length) := LA;
6090 Error_Msg_Strlen := LA'Length;
6091 else
6092 Error_Msg_Strlen := 0;
6093 end if;
6095 if Nkind (Constr) = N_Pragma then
6096 Error_Pragma
6097 ("pragma %~ must appear immediately within the statements "
6098 & "of a loop");
6099 else
6100 Error_Pragma_Arg
6101 ("block containing pragma %~ must appear immediately within "
6102 & "the statements of a loop", Constr);
6103 end if;
6104 end Placement_Error;
6106 -- Local declarations
6108 Prev : Node_Id;
6109 Stmt : Node_Id;
6111 -- Start of processing for Check_Loop_Pragma_Placement
6113 begin
6114 -- Check that pragma appears immediately within a loop statement,
6115 -- ignoring intervening block statements.
6117 Prev := N;
6118 Stmt := Parent (N);
6119 while Present (Stmt) loop
6121 -- The pragma or previous block must appear immediately within the
6122 -- current block's declarative or statement part.
6124 if Nkind (Stmt) = N_Block_Statement then
6125 if (No (Declarations (Stmt))
6126 or else List_Containing (Prev) /= Declarations (Stmt))
6127 and then
6128 List_Containing (Prev) /=
6129 Statements (Handled_Statement_Sequence (Stmt))
6130 then
6131 Placement_Error (Prev);
6132 return;
6134 -- Keep inspecting the parents because we are now within a
6135 -- chain of nested blocks.
6137 else
6138 Prev := Stmt;
6139 Stmt := Parent (Stmt);
6140 end if;
6142 -- The pragma or previous block must appear immediately within the
6143 -- statements of the loop.
6145 elsif Nkind (Stmt) = N_Loop_Statement then
6146 if List_Containing (Prev) /= Statements (Stmt) then
6147 Placement_Error (Prev);
6148 end if;
6150 -- Stop the traversal because we reached the innermost loop
6151 -- regardless of whether we encountered an error or not.
6153 exit;
6155 -- Ignore a handled statement sequence. Note that this node may
6156 -- be related to a subprogram body in which case we will emit an
6157 -- error on the next iteration of the search.
6159 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
6160 Stmt := Parent (Stmt);
6162 -- Any other statement breaks the chain from the pragma to the
6163 -- loop.
6165 else
6166 Placement_Error (Prev);
6167 return;
6168 end if;
6169 end loop;
6171 -- Check that the current pragma Loop_Invariant or Loop_Variant is
6172 -- grouped together with other such pragmas.
6174 if Is_Loop_Pragma (N) then
6176 -- The previous check should have located the related loop
6178 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
6179 Check_Loop_Pragma_Grouping (Stmt);
6180 end if;
6181 end Check_Loop_Pragma_Placement;
6183 -------------------------------------------
6184 -- Check_Is_In_Decl_Part_Or_Package_Spec --
6185 -------------------------------------------
6187 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
6188 P : Node_Id;
6190 begin
6191 P := Parent (N);
6192 loop
6193 if No (P) then
6194 exit;
6196 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
6197 exit;
6199 elsif Nkind_In (P, N_Package_Specification,
6200 N_Block_Statement)
6201 then
6202 return;
6204 -- Note: the following tests seem a little peculiar, because
6205 -- they test for bodies, but if we were in the statement part
6206 -- of the body, we would already have hit the handled statement
6207 -- sequence, so the only way we get here is by being in the
6208 -- declarative part of the body.
6210 elsif Nkind_In (P, N_Subprogram_Body,
6211 N_Package_Body,
6212 N_Task_Body,
6213 N_Entry_Body)
6214 then
6215 return;
6216 end if;
6218 P := Parent (P);
6219 end loop;
6221 Error_Pragma ("pragma% is not in declarative part or package spec");
6222 end Check_Is_In_Decl_Part_Or_Package_Spec;
6224 -------------------------
6225 -- Check_No_Identifier --
6226 -------------------------
6228 procedure Check_No_Identifier (Arg : Node_Id) is
6229 begin
6230 if Nkind (Arg) = N_Pragma_Argument_Association
6231 and then Chars (Arg) /= No_Name
6232 then
6233 Error_Pragma_Arg_Ident
6234 ("pragma% does not permit identifier& here", Arg);
6235 end if;
6236 end Check_No_Identifier;
6238 --------------------------
6239 -- Check_No_Identifiers --
6240 --------------------------
6242 procedure Check_No_Identifiers is
6243 Arg_Node : Node_Id;
6244 begin
6245 Arg_Node := Arg1;
6246 for J in 1 .. Arg_Count loop
6247 Check_No_Identifier (Arg_Node);
6248 Next (Arg_Node);
6249 end loop;
6250 end Check_No_Identifiers;
6252 ------------------------
6253 -- Check_No_Link_Name --
6254 ------------------------
6256 procedure Check_No_Link_Name is
6257 begin
6258 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
6259 Arg4 := Arg3;
6260 end if;
6262 if Present (Arg4) then
6263 Error_Pragma_Arg
6264 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
6265 end if;
6266 end Check_No_Link_Name;
6268 -------------------------------
6269 -- Check_Optional_Identifier --
6270 -------------------------------
6272 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
6273 begin
6274 if Present (Arg)
6275 and then Nkind (Arg) = N_Pragma_Argument_Association
6276 and then Chars (Arg) /= No_Name
6277 then
6278 if Chars (Arg) /= Id then
6279 Error_Msg_Name_1 := Pname;
6280 Error_Msg_Name_2 := Id;
6281 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6282 raise Pragma_Exit;
6283 end if;
6284 end if;
6285 end Check_Optional_Identifier;
6287 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
6288 begin
6289 Check_Optional_Identifier (Arg, Name_Find (Id));
6290 end Check_Optional_Identifier;
6292 -------------------------------------
6293 -- Check_Static_Boolean_Expression --
6294 -------------------------------------
6296 procedure Check_Static_Boolean_Expression (Expr : Node_Id) is
6297 begin
6298 if Present (Expr) then
6299 Analyze_And_Resolve (Expr, Standard_Boolean);
6301 if not Is_OK_Static_Expression (Expr) then
6302 Error_Pragma_Arg
6303 ("expression of pragma % must be static", Expr);
6304 end if;
6305 end if;
6306 end Check_Static_Boolean_Expression;
6308 -----------------------------
6309 -- Check_Static_Constraint --
6310 -----------------------------
6312 -- Note: for convenience in writing this procedure, in addition to
6313 -- the officially (i.e. by spec) allowed argument which is always a
6314 -- constraint, it also allows ranges and discriminant associations.
6315 -- Above is not clear ???
6317 procedure Check_Static_Constraint (Constr : Node_Id) is
6319 procedure Require_Static (E : Node_Id);
6320 -- Require given expression to be static expression
6322 --------------------
6323 -- Require_Static --
6324 --------------------
6326 procedure Require_Static (E : Node_Id) is
6327 begin
6328 if not Is_OK_Static_Expression (E) then
6329 Flag_Non_Static_Expr
6330 ("non-static constraint not allowed in Unchecked_Union!", E);
6331 raise Pragma_Exit;
6332 end if;
6333 end Require_Static;
6335 -- Start of processing for Check_Static_Constraint
6337 begin
6338 case Nkind (Constr) is
6339 when N_Discriminant_Association =>
6340 Require_Static (Expression (Constr));
6342 when N_Range =>
6343 Require_Static (Low_Bound (Constr));
6344 Require_Static (High_Bound (Constr));
6346 when N_Attribute_Reference =>
6347 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
6348 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
6350 when N_Range_Constraint =>
6351 Check_Static_Constraint (Range_Expression (Constr));
6353 when N_Index_Or_Discriminant_Constraint =>
6354 declare
6355 IDC : Entity_Id;
6356 begin
6357 IDC := First (Constraints (Constr));
6358 while Present (IDC) loop
6359 Check_Static_Constraint (IDC);
6360 Next (IDC);
6361 end loop;
6362 end;
6364 when others =>
6365 null;
6366 end case;
6367 end Check_Static_Constraint;
6369 --------------------------------------
6370 -- Check_Valid_Configuration_Pragma --
6371 --------------------------------------
6373 -- A configuration pragma must appear in the context clause of a
6374 -- compilation unit, and only other pragmas may precede it. Note that
6375 -- the test also allows use in a configuration pragma file.
6377 procedure Check_Valid_Configuration_Pragma is
6378 begin
6379 if not Is_Configuration_Pragma then
6380 Error_Pragma ("incorrect placement for configuration pragma%");
6381 end if;
6382 end Check_Valid_Configuration_Pragma;
6384 -------------------------------------
6385 -- Check_Valid_Library_Unit_Pragma --
6386 -------------------------------------
6388 procedure Check_Valid_Library_Unit_Pragma is
6389 Plist : List_Id;
6390 Parent_Node : Node_Id;
6391 Unit_Name : Entity_Id;
6392 Unit_Kind : Node_Kind;
6393 Unit_Node : Node_Id;
6394 Sindex : Source_File_Index;
6396 begin
6397 if not Is_List_Member (N) then
6398 Pragma_Misplaced;
6400 else
6401 Plist := List_Containing (N);
6402 Parent_Node := Parent (Plist);
6404 if Parent_Node = Empty then
6405 Pragma_Misplaced;
6407 -- Case of pragma appearing after a compilation unit. In this case
6408 -- it must have an argument with the corresponding name and must
6409 -- be part of the following pragmas of its parent.
6411 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
6412 if Plist /= Pragmas_After (Parent_Node) then
6413 Pragma_Misplaced;
6415 elsif Arg_Count = 0 then
6416 Error_Pragma
6417 ("argument required if outside compilation unit");
6419 else
6420 Check_No_Identifiers;
6421 Check_Arg_Count (1);
6422 Unit_Node := Unit (Parent (Parent_Node));
6423 Unit_Kind := Nkind (Unit_Node);
6425 Analyze (Get_Pragma_Arg (Arg1));
6427 if Unit_Kind = N_Generic_Subprogram_Declaration
6428 or else Unit_Kind = N_Subprogram_Declaration
6429 then
6430 Unit_Name := Defining_Entity (Unit_Node);
6432 elsif Unit_Kind in N_Generic_Instantiation then
6433 Unit_Name := Defining_Entity (Unit_Node);
6435 else
6436 Unit_Name := Cunit_Entity (Current_Sem_Unit);
6437 end if;
6439 if Chars (Unit_Name) /=
6440 Chars (Entity (Get_Pragma_Arg (Arg1)))
6441 then
6442 Error_Pragma_Arg
6443 ("pragma% argument is not current unit name", Arg1);
6444 end if;
6446 if Ekind (Unit_Name) = E_Package
6447 and then Present (Renamed_Entity (Unit_Name))
6448 then
6449 Error_Pragma ("pragma% not allowed for renamed package");
6450 end if;
6451 end if;
6453 -- Pragma appears other than after a compilation unit
6455 else
6456 -- Here we check for the generic instantiation case and also
6457 -- for the case of processing a generic formal package. We
6458 -- detect these cases by noting that the Sloc on the node
6459 -- does not belong to the current compilation unit.
6461 Sindex := Source_Index (Current_Sem_Unit);
6463 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
6464 Rewrite (N, Make_Null_Statement (Loc));
6465 return;
6467 -- If before first declaration, the pragma applies to the
6468 -- enclosing unit, and the name if present must be this name.
6470 elsif Is_Before_First_Decl (N, Plist) then
6471 Unit_Node := Unit_Declaration_Node (Current_Scope);
6472 Unit_Kind := Nkind (Unit_Node);
6474 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
6475 Pragma_Misplaced;
6477 elsif Unit_Kind = N_Subprogram_Body
6478 and then not Acts_As_Spec (Unit_Node)
6479 then
6480 Pragma_Misplaced;
6482 elsif Nkind (Parent_Node) = N_Package_Body then
6483 Pragma_Misplaced;
6485 elsif Nkind (Parent_Node) = N_Package_Specification
6486 and then Plist = Private_Declarations (Parent_Node)
6487 then
6488 Pragma_Misplaced;
6490 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
6491 or else Nkind (Parent_Node) =
6492 N_Generic_Subprogram_Declaration)
6493 and then Plist = Generic_Formal_Declarations (Parent_Node)
6494 then
6495 Pragma_Misplaced;
6497 elsif Arg_Count > 0 then
6498 Analyze (Get_Pragma_Arg (Arg1));
6500 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
6501 Error_Pragma_Arg
6502 ("name in pragma% must be enclosing unit", Arg1);
6503 end if;
6505 -- It is legal to have no argument in this context
6507 else
6508 return;
6509 end if;
6511 -- Error if not before first declaration. This is because a
6512 -- library unit pragma argument must be the name of a library
6513 -- unit (RM 10.1.5(7)), but the only names permitted in this
6514 -- context are (RM 10.1.5(6)) names of subprogram declarations,
6515 -- generic subprogram declarations or generic instantiations.
6517 else
6518 Error_Pragma
6519 ("pragma% misplaced, must be before first declaration");
6520 end if;
6521 end if;
6522 end if;
6523 end Check_Valid_Library_Unit_Pragma;
6525 -------------------
6526 -- Check_Variant --
6527 -------------------
6529 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
6530 Clist : constant Node_Id := Component_List (Variant);
6531 Comp : Node_Id;
6533 begin
6534 Comp := First_Non_Pragma (Component_Items (Clist));
6535 while Present (Comp) loop
6536 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
6537 Next_Non_Pragma (Comp);
6538 end loop;
6539 end Check_Variant;
6541 ---------------------------
6542 -- Ensure_Aggregate_Form --
6543 ---------------------------
6545 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
6546 CFSD : constant Boolean := Get_Comes_From_Source_Default;
6547 Expr : constant Node_Id := Expression (Arg);
6548 Loc : constant Source_Ptr := Sloc (Expr);
6549 Comps : List_Id := No_List;
6550 Exprs : List_Id := No_List;
6551 Nam : Name_Id := No_Name;
6552 Nam_Loc : Source_Ptr;
6554 begin
6555 -- The pragma argument is in positional form:
6557 -- pragma Depends (Nam => ...)
6558 -- ^
6559 -- Chars field
6561 -- Note that the Sloc of the Chars field is the Sloc of the pragma
6562 -- argument association.
6564 if Nkind (Arg) = N_Pragma_Argument_Association then
6565 Nam := Chars (Arg);
6566 Nam_Loc := Sloc (Arg);
6568 -- Remove the pragma argument name as this will be captured in the
6569 -- aggregate.
6571 Set_Chars (Arg, No_Name);
6572 end if;
6574 -- The argument is already in aggregate form, but the presence of a
6575 -- name causes this to be interpreted as named association which in
6576 -- turn must be converted into an aggregate.
6578 -- pragma Global (In_Out => (A, B, C))
6579 -- ^ ^
6580 -- name aggregate
6582 -- pragma Global ((In_Out => (A, B, C)))
6583 -- ^ ^
6584 -- aggregate aggregate
6586 if Nkind (Expr) = N_Aggregate then
6587 if Nam = No_Name then
6588 return;
6589 end if;
6591 -- Do not transform a null argument into an aggregate as N_Null has
6592 -- special meaning in formal verification pragmas.
6594 elsif Nkind (Expr) = N_Null then
6595 return;
6596 end if;
6598 -- Everything comes from source if the original comes from source
6600 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
6602 -- Positional argument is transformed into an aggregate with an
6603 -- Expressions list.
6605 if Nam = No_Name then
6606 Exprs := New_List (Relocate_Node (Expr));
6608 -- An associative argument is transformed into an aggregate with
6609 -- Component_Associations.
6611 else
6612 Comps := New_List (
6613 Make_Component_Association (Loc,
6614 Choices => New_List (Make_Identifier (Nam_Loc, Nam)),
6615 Expression => Relocate_Node (Expr)));
6616 end if;
6618 Set_Expression (Arg,
6619 Make_Aggregate (Loc,
6620 Component_Associations => Comps,
6621 Expressions => Exprs));
6623 -- Restore Comes_From_Source default
6625 Set_Comes_From_Source_Default (CFSD);
6626 end Ensure_Aggregate_Form;
6628 ------------------
6629 -- Error_Pragma --
6630 ------------------
6632 procedure Error_Pragma (Msg : String) is
6633 begin
6634 Error_Msg_Name_1 := Pname;
6635 Error_Msg_N (Fix_Error (Msg), N);
6636 raise Pragma_Exit;
6637 end Error_Pragma;
6639 ----------------------
6640 -- Error_Pragma_Arg --
6641 ----------------------
6643 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
6644 begin
6645 Error_Msg_Name_1 := Pname;
6646 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
6647 raise Pragma_Exit;
6648 end Error_Pragma_Arg;
6650 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
6651 begin
6652 Error_Msg_Name_1 := Pname;
6653 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
6654 Error_Pragma_Arg (Msg2, Arg);
6655 end Error_Pragma_Arg;
6657 ----------------------------
6658 -- Error_Pragma_Arg_Ident --
6659 ----------------------------
6661 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
6662 begin
6663 Error_Msg_Name_1 := Pname;
6664 Error_Msg_N (Fix_Error (Msg), Arg);
6665 raise Pragma_Exit;
6666 end Error_Pragma_Arg_Ident;
6668 ----------------------
6669 -- Error_Pragma_Ref --
6670 ----------------------
6672 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
6673 begin
6674 Error_Msg_Name_1 := Pname;
6675 Error_Msg_Sloc := Sloc (Ref);
6676 Error_Msg_NE (Fix_Error (Msg), N, Ref);
6677 raise Pragma_Exit;
6678 end Error_Pragma_Ref;
6680 ------------------------
6681 -- Find_Lib_Unit_Name --
6682 ------------------------
6684 function Find_Lib_Unit_Name return Entity_Id is
6685 begin
6686 -- Return inner compilation unit entity, for case of nested
6687 -- categorization pragmas. This happens in generic unit.
6689 if Nkind (Parent (N)) = N_Package_Specification
6690 and then Defining_Entity (Parent (N)) /= Current_Scope
6691 then
6692 return Defining_Entity (Parent (N));
6693 else
6694 return Current_Scope;
6695 end if;
6696 end Find_Lib_Unit_Name;
6698 ----------------------------
6699 -- Find_Program_Unit_Name --
6700 ----------------------------
6702 procedure Find_Program_Unit_Name (Id : Node_Id) is
6703 Unit_Name : Entity_Id;
6704 Unit_Kind : Node_Kind;
6705 P : constant Node_Id := Parent (N);
6707 begin
6708 if Nkind (P) = N_Compilation_Unit then
6709 Unit_Kind := Nkind (Unit (P));
6711 if Nkind_In (Unit_Kind, N_Subprogram_Declaration,
6712 N_Package_Declaration)
6713 or else Unit_Kind in N_Generic_Declaration
6714 then
6715 Unit_Name := Defining_Entity (Unit (P));
6717 if Chars (Id) = Chars (Unit_Name) then
6718 Set_Entity (Id, Unit_Name);
6719 Set_Etype (Id, Etype (Unit_Name));
6720 else
6721 Set_Etype (Id, Any_Type);
6722 Error_Pragma
6723 ("cannot find program unit referenced by pragma%");
6724 end if;
6726 else
6727 Set_Etype (Id, Any_Type);
6728 Error_Pragma ("pragma% inapplicable to this unit");
6729 end if;
6731 else
6732 Analyze (Id);
6733 end if;
6734 end Find_Program_Unit_Name;
6736 -----------------------------------------
6737 -- Find_Unique_Parameterless_Procedure --
6738 -----------------------------------------
6740 function Find_Unique_Parameterless_Procedure
6741 (Name : Entity_Id;
6742 Arg : Node_Id) return Entity_Id
6744 Proc : Entity_Id := Empty;
6746 begin
6747 -- The body of this procedure needs some comments ???
6749 if not Is_Entity_Name (Name) then
6750 Error_Pragma_Arg
6751 ("argument of pragma% must be entity name", Arg);
6753 elsif not Is_Overloaded (Name) then
6754 Proc := Entity (Name);
6756 if Ekind (Proc) /= E_Procedure
6757 or else Present (First_Formal (Proc))
6758 then
6759 Error_Pragma_Arg
6760 ("argument of pragma% must be parameterless procedure", Arg);
6761 end if;
6763 else
6764 declare
6765 Found : Boolean := False;
6766 It : Interp;
6767 Index : Interp_Index;
6769 begin
6770 Get_First_Interp (Name, Index, It);
6771 while Present (It.Nam) loop
6772 Proc := It.Nam;
6774 if Ekind (Proc) = E_Procedure
6775 and then No (First_Formal (Proc))
6776 then
6777 if not Found then
6778 Found := True;
6779 Set_Entity (Name, Proc);
6780 Set_Is_Overloaded (Name, False);
6781 else
6782 Error_Pragma_Arg
6783 ("ambiguous handler name for pragma% ", Arg);
6784 end if;
6785 end if;
6787 Get_Next_Interp (Index, It);
6788 end loop;
6790 if not Found then
6791 Error_Pragma_Arg
6792 ("argument of pragma% must be parameterless procedure",
6793 Arg);
6794 else
6795 Proc := Entity (Name);
6796 end if;
6797 end;
6798 end if;
6800 return Proc;
6801 end Find_Unique_Parameterless_Procedure;
6803 ---------------
6804 -- Fix_Error --
6805 ---------------
6807 function Fix_Error (Msg : String) return String is
6808 Res : String (Msg'Range) := Msg;
6809 Res_Last : Natural := Msg'Last;
6810 J : Natural;
6812 begin
6813 -- If we have a rewriting of another pragma, go to that pragma
6815 if Is_Rewrite_Substitution (N)
6816 and then Nkind (Original_Node (N)) = N_Pragma
6817 then
6818 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
6819 end if;
6821 -- Case where pragma comes from an aspect specification
6823 if From_Aspect_Specification (N) then
6825 -- Change appearence of "pragma" in message to "aspect"
6827 J := Res'First;
6828 while J <= Res_Last - 5 loop
6829 if Res (J .. J + 5) = "pragma" then
6830 Res (J .. J + 5) := "aspect";
6831 J := J + 6;
6833 else
6834 J := J + 1;
6835 end if;
6836 end loop;
6838 -- Change "argument of" at start of message to "entity for"
6840 if Res'Length > 11
6841 and then Res (Res'First .. Res'First + 10) = "argument of"
6842 then
6843 Res (Res'First .. Res'First + 9) := "entity for";
6844 Res (Res'First + 10 .. Res_Last - 1) :=
6845 Res (Res'First + 11 .. Res_Last);
6846 Res_Last := Res_Last - 1;
6847 end if;
6849 -- Change "argument" at start of message to "entity"
6851 if Res'Length > 8
6852 and then Res (Res'First .. Res'First + 7) = "argument"
6853 then
6854 Res (Res'First .. Res'First + 5) := "entity";
6855 Res (Res'First + 6 .. Res_Last - 2) :=
6856 Res (Res'First + 8 .. Res_Last);
6857 Res_Last := Res_Last - 2;
6858 end if;
6860 -- Get name from corresponding aspect
6862 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
6863 end if;
6865 -- Return possibly modified message
6867 return Res (Res'First .. Res_Last);
6868 end Fix_Error;
6870 -------------------------
6871 -- Gather_Associations --
6872 -------------------------
6874 procedure Gather_Associations
6875 (Names : Name_List;
6876 Args : out Args_List)
6878 Arg : Node_Id;
6880 begin
6881 -- Initialize all parameters to Empty
6883 for J in Args'Range loop
6884 Args (J) := Empty;
6885 end loop;
6887 -- That's all we have to do if there are no argument associations
6889 if No (Pragma_Argument_Associations (N)) then
6890 return;
6891 end if;
6893 -- Otherwise first deal with any positional parameters present
6895 Arg := First (Pragma_Argument_Associations (N));
6896 for Index in Args'Range loop
6897 exit when No (Arg) or else Chars (Arg) /= No_Name;
6898 Args (Index) := Get_Pragma_Arg (Arg);
6899 Next (Arg);
6900 end loop;
6902 -- Positional parameters all processed, if any left, then we
6903 -- have too many positional parameters.
6905 if Present (Arg) and then Chars (Arg) = No_Name then
6906 Error_Pragma_Arg
6907 ("too many positional associations for pragma%", Arg);
6908 end if;
6910 -- Process named parameters if any are present
6912 while Present (Arg) loop
6913 if Chars (Arg) = No_Name then
6914 Error_Pragma_Arg
6915 ("positional association cannot follow named association",
6916 Arg);
6918 else
6919 for Index in Names'Range loop
6920 if Names (Index) = Chars (Arg) then
6921 if Present (Args (Index)) then
6922 Error_Pragma_Arg
6923 ("duplicate argument association for pragma%", Arg);
6924 else
6925 Args (Index) := Get_Pragma_Arg (Arg);
6926 exit;
6927 end if;
6928 end if;
6930 if Index = Names'Last then
6931 Error_Msg_Name_1 := Pname;
6932 Error_Msg_N ("pragma% does not allow & argument", Arg);
6934 -- Check for possible misspelling
6936 for Index1 in Names'Range loop
6937 if Is_Bad_Spelling_Of
6938 (Chars (Arg), Names (Index1))
6939 then
6940 Error_Msg_Name_1 := Names (Index1);
6941 Error_Msg_N -- CODEFIX
6942 ("\possible misspelling of%", Arg);
6943 exit;
6944 end if;
6945 end loop;
6947 raise Pragma_Exit;
6948 end if;
6949 end loop;
6950 end if;
6952 Next (Arg);
6953 end loop;
6954 end Gather_Associations;
6956 -----------------
6957 -- GNAT_Pragma --
6958 -----------------
6960 procedure GNAT_Pragma is
6961 begin
6962 -- We need to check the No_Implementation_Pragmas restriction for
6963 -- the case of a pragma from source. Note that the case of aspects
6964 -- generating corresponding pragmas marks these pragmas as not being
6965 -- from source, so this test also catches that case.
6967 if Comes_From_Source (N) then
6968 Check_Restriction (No_Implementation_Pragmas, N);
6969 end if;
6970 end GNAT_Pragma;
6972 --------------------------
6973 -- Is_Before_First_Decl --
6974 --------------------------
6976 function Is_Before_First_Decl
6977 (Pragma_Node : Node_Id;
6978 Decls : List_Id) return Boolean
6980 Item : Node_Id := First (Decls);
6982 begin
6983 -- Only other pragmas can come before this pragma
6985 loop
6986 if No (Item) or else Nkind (Item) /= N_Pragma then
6987 return False;
6989 elsif Item = Pragma_Node then
6990 return True;
6991 end if;
6993 Next (Item);
6994 end loop;
6995 end Is_Before_First_Decl;
6997 -----------------------------
6998 -- Is_Configuration_Pragma --
6999 -----------------------------
7001 -- A configuration pragma must appear in the context clause of a
7002 -- compilation unit, and only other pragmas may precede it. Note that
7003 -- the test below also permits use in a configuration pragma file.
7005 function Is_Configuration_Pragma return Boolean is
7006 Lis : constant List_Id := List_Containing (N);
7007 Par : constant Node_Id := Parent (N);
7008 Prg : Node_Id;
7010 begin
7011 -- If no parent, then we are in the configuration pragma file,
7012 -- so the placement is definitely appropriate.
7014 if No (Par) then
7015 return True;
7017 -- Otherwise we must be in the context clause of a compilation unit
7018 -- and the only thing allowed before us in the context list is more
7019 -- configuration pragmas.
7021 elsif Nkind (Par) = N_Compilation_Unit
7022 and then Context_Items (Par) = Lis
7023 then
7024 Prg := First (Lis);
7026 loop
7027 if Prg = N then
7028 return True;
7029 elsif Nkind (Prg) /= N_Pragma then
7030 return False;
7031 end if;
7033 Next (Prg);
7034 end loop;
7036 else
7037 return False;
7038 end if;
7039 end Is_Configuration_Pragma;
7041 --------------------------
7042 -- Is_In_Context_Clause --
7043 --------------------------
7045 function Is_In_Context_Clause return Boolean is
7046 Plist : List_Id;
7047 Parent_Node : Node_Id;
7049 begin
7050 if not Is_List_Member (N) then
7051 return False;
7053 else
7054 Plist := List_Containing (N);
7055 Parent_Node := Parent (Plist);
7057 if Parent_Node = Empty
7058 or else Nkind (Parent_Node) /= N_Compilation_Unit
7059 or else Context_Items (Parent_Node) /= Plist
7060 then
7061 return False;
7062 end if;
7063 end if;
7065 return True;
7066 end Is_In_Context_Clause;
7068 ---------------------------------
7069 -- Is_Static_String_Expression --
7070 ---------------------------------
7072 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
7073 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
7074 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
7076 begin
7077 Analyze_And_Resolve (Argx);
7079 -- Special case Ada 83, where the expression will never be static,
7080 -- but we will return true if we had a string literal to start with.
7082 if Ada_Version = Ada_83 then
7083 return Lit;
7085 -- Normal case, true only if we end up with a string literal that
7086 -- is marked as being the result of evaluating a static expression.
7088 else
7089 return Is_OK_Static_Expression (Argx)
7090 and then Nkind (Argx) = N_String_Literal;
7091 end if;
7093 end Is_Static_String_Expression;
7095 ----------------------
7096 -- Pragma_Misplaced --
7097 ----------------------
7099 procedure Pragma_Misplaced is
7100 begin
7101 Error_Pragma ("incorrect placement of pragma%");
7102 end Pragma_Misplaced;
7104 ------------------------------------------------
7105 -- Process_Atomic_Independent_Shared_Volatile --
7106 ------------------------------------------------
7108 procedure Process_Atomic_Independent_Shared_Volatile is
7109 procedure Check_VFA_Conflicts (Ent : Entity_Id);
7110 -- Apply additional checks for the GNAT pragma Volatile_Full_Access
7112 procedure Mark_Component_Or_Object (Ent : Entity_Id);
7113 -- Appropriately set flags on the given entity (either an array or
7114 -- record component, or an object declaration) according to the
7115 -- current pragma.
7117 procedure Set_Atomic_VFA (Ent : Entity_Id);
7118 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
7119 -- no explicit alignment was given, set alignment to unknown, since
7120 -- back end knows what the alignment requirements are for atomic and
7121 -- full access arrays. Note: this is necessary for derived types.
7123 -------------------------
7124 -- Check_VFA_Conflicts --
7125 -------------------------
7127 procedure Check_VFA_Conflicts (Ent : Entity_Id) is
7128 Comp : Entity_Id;
7129 Typ : Entity_Id;
7131 VFA_And_Atomic : Boolean := False;
7132 -- Set True if atomic component present
7134 VFA_And_Aliased : Boolean := False;
7135 -- Set True if aliased component present
7137 begin
7138 -- Fetch the type in case we are dealing with an object or
7139 -- component.
7141 if Is_Type (Ent) then
7142 Typ := Ent;
7143 else
7144 pragma Assert (Is_Object (Ent)
7145 or else
7146 Nkind (Declaration_Node (Ent)) = N_Component_Declaration);
7148 Typ := Etype (Ent);
7149 end if;
7151 -- Check Atomic and VFA used together
7153 if Prag_Id = Pragma_Volatile_Full_Access
7154 or else Is_Volatile_Full_Access (Ent)
7155 then
7156 if Prag_Id = Pragma_Atomic
7157 or else Prag_Id = Pragma_Shared
7158 or else Is_Atomic (Ent)
7159 then
7160 VFA_And_Atomic := True;
7162 elsif Is_Array_Type (Typ) then
7163 VFA_And_Atomic := Has_Atomic_Components (Typ);
7165 -- Note: Has_Atomic_Components is not used below, as this flag
7166 -- represents the pragma of the same name, Atomic_Components,
7167 -- which only applies to arrays.
7169 elsif Is_Record_Type (Typ) then
7170 -- Attributes cannot be applied to discriminants, only
7171 -- regular record components.
7173 Comp := First_Component (Typ);
7174 while Present (Comp) loop
7175 if Is_Atomic (Comp)
7176 or else Is_Atomic (Typ)
7177 then
7178 VFA_And_Atomic := True;
7180 exit;
7181 end if;
7183 Next_Component (Comp);
7184 end loop;
7185 end if;
7187 if VFA_And_Atomic then
7188 Error_Pragma
7189 ("cannot have Volatile_Full_Access and Atomic for same "
7190 & "entity");
7191 end if;
7192 end if;
7194 -- Check for the application of VFA to an entity that has aliased
7195 -- components.
7197 if Prag_Id = Pragma_Volatile_Full_Access then
7198 if Is_Array_Type (Typ)
7199 and then Has_Aliased_Components (Typ)
7200 then
7201 VFA_And_Aliased := True;
7203 -- Note: Has_Aliased_Components, like Has_Atomic_Components,
7204 -- and Has_Independent_Components, applies only to arrays.
7205 -- However, this flag does not have a corresponding pragma, so
7206 -- perhaps it should be possible to apply it to record types as
7207 -- well. Should this be done ???
7209 elsif Is_Record_Type (Typ) then
7210 -- It is possible to have an aliased discriminant, so they
7211 -- must be checked along with normal components.
7213 Comp := First_Component_Or_Discriminant (Typ);
7214 while Present (Comp) loop
7215 if Is_Aliased (Comp)
7216 or else Is_Aliased (Etype (Comp))
7217 then
7218 VFA_And_Aliased := True;
7219 Check_SPARK_05_Restriction
7220 ("aliased is not allowed", Comp);
7222 exit;
7223 end if;
7225 Next_Component_Or_Discriminant (Comp);
7226 end loop;
7227 end if;
7229 if VFA_And_Aliased then
7230 Error_Pragma
7231 ("cannot apply Volatile_Full_Access (aliased component "
7232 & "present)");
7233 end if;
7234 end if;
7235 end Check_VFA_Conflicts;
7237 ------------------------------
7238 -- Mark_Component_Or_Object --
7239 ------------------------------
7241 procedure Mark_Component_Or_Object (Ent : Entity_Id) is
7242 begin
7243 if Prag_Id = Pragma_Atomic
7244 or else Prag_Id = Pragma_Shared
7245 or else Prag_Id = Pragma_Volatile_Full_Access
7246 then
7247 if Prag_Id = Pragma_Volatile_Full_Access then
7248 Set_Is_Volatile_Full_Access (Ent);
7249 else
7250 Set_Is_Atomic (Ent);
7251 end if;
7253 -- If the object declaration has an explicit initialization, a
7254 -- temporary may have to be created to hold the expression, to
7255 -- ensure that access to the object remains atomic.
7257 if Nkind (Parent (Ent)) = N_Object_Declaration
7258 and then Present (Expression (Parent (Ent)))
7259 then
7260 Set_Has_Delayed_Freeze (Ent);
7261 end if;
7262 end if;
7264 -- Atomic/Shared/Volatile_Full_Access imply Independent
7266 if Prag_Id /= Pragma_Volatile then
7267 Set_Is_Independent (Ent);
7269 if Prag_Id = Pragma_Independent then
7270 Record_Independence_Check (N, Ent);
7271 end if;
7272 end if;
7274 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7276 if Prag_Id /= Pragma_Independent then
7277 Set_Is_Volatile (Ent);
7278 Set_Treat_As_Volatile (Ent);
7279 end if;
7280 end Mark_Component_Or_Object;
7282 --------------------
7283 -- Set_Atomic_VFA --
7284 --------------------
7286 procedure Set_Atomic_VFA (Ent : Entity_Id) is
7287 begin
7288 if Prag_Id = Pragma_Volatile_Full_Access then
7289 Set_Is_Volatile_Full_Access (Ent);
7290 else
7291 Set_Is_Atomic (Ent);
7292 end if;
7294 if not Has_Alignment_Clause (Ent) then
7295 Set_Alignment (Ent, Uint_0);
7296 end if;
7297 end Set_Atomic_VFA;
7299 -- Local variables
7301 Decl : Node_Id;
7302 E : Entity_Id;
7303 E_Arg : Node_Id;
7305 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
7307 begin
7308 Check_Ada_83_Warning;
7309 Check_No_Identifiers;
7310 Check_Arg_Count (1);
7311 Check_Arg_Is_Local_Name (Arg1);
7312 E_Arg := Get_Pragma_Arg (Arg1);
7314 if Etype (E_Arg) = Any_Type then
7315 return;
7316 end if;
7318 E := Entity (E_Arg);
7320 -- A pragma that applies to a Ghost entity becomes Ghost for the
7321 -- purposes of legality checks and removal of ignored Ghost code.
7323 Mark_Ghost_Pragma (N, E);
7325 -- Check duplicate before we chain ourselves
7327 Check_Duplicate_Pragma (E);
7329 -- Check appropriateness of the entity
7331 Decl := Declaration_Node (E);
7333 -- Deal with the case where the pragma/attribute is applied to a type
7335 if Is_Type (E) then
7336 if Rep_Item_Too_Early (E, N)
7337 or else Rep_Item_Too_Late (E, N)
7338 then
7339 return;
7340 else
7341 Check_First_Subtype (Arg1);
7342 end if;
7344 -- Attribute belongs on the base type. If the view of the type is
7345 -- currently private, it also belongs on the underlying type.
7347 if Prag_Id = Pragma_Atomic
7348 or else Prag_Id = Pragma_Shared
7349 or else Prag_Id = Pragma_Volatile_Full_Access
7350 then
7351 Set_Atomic_VFA (E);
7352 Set_Atomic_VFA (Base_Type (E));
7353 Set_Atomic_VFA (Underlying_Type (E));
7354 end if;
7356 -- Atomic/Shared/Volatile_Full_Access imply Independent
7358 if Prag_Id /= Pragma_Volatile then
7359 Set_Is_Independent (E);
7360 Set_Is_Independent (Base_Type (E));
7361 Set_Is_Independent (Underlying_Type (E));
7363 if Prag_Id = Pragma_Independent then
7364 Record_Independence_Check (N, Base_Type (E));
7365 end if;
7366 end if;
7368 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7370 if Prag_Id /= Pragma_Independent then
7371 Set_Is_Volatile (E);
7372 Set_Is_Volatile (Base_Type (E));
7373 Set_Is_Volatile (Underlying_Type (E));
7375 Set_Treat_As_Volatile (E);
7376 Set_Treat_As_Volatile (Underlying_Type (E));
7377 end if;
7379 -- Apply Volatile to the composite type's individual components,
7380 -- (RM C.6(8/3)).
7382 if Prag_Id = Pragma_Volatile
7383 and then Is_Record_Type (Etype (E))
7384 then
7385 declare
7386 Comp : Entity_Id;
7387 begin
7388 Comp := First_Component (E);
7389 while Present (Comp) loop
7390 Mark_Component_Or_Object (Comp);
7392 Next_Component (Comp);
7393 end loop;
7394 end;
7395 end if;
7397 -- Deal with the case where the pragma/attribute applies to a
7398 -- component or object declaration.
7400 elsif Nkind (Decl) = N_Object_Declaration
7401 or else (Nkind (Decl) = N_Component_Declaration
7402 and then Original_Record_Component (E) = E)
7403 then
7404 if Rep_Item_Too_Late (E, N) then
7405 return;
7406 end if;
7408 Mark_Component_Or_Object (E);
7409 else
7410 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7411 end if;
7413 -- Perform the checks needed to assure the proper use of the GNAT
7414 -- pragma Volatile_Full_Access.
7416 Check_VFA_Conflicts (E);
7418 -- The following check is only relevant when SPARK_Mode is on as
7419 -- this is not a standard Ada legality rule. Pragma Volatile can
7420 -- only apply to a full type declaration or an object declaration
7421 -- (SPARK RM 7.1.3(2)). Original_Node is necessary to account for
7422 -- untagged derived types that are rewritten as subtypes of their
7423 -- respective root types.
7425 if SPARK_Mode = On
7426 and then Prag_Id = Pragma_Volatile
7427 and then not Nkind_In (Original_Node (Decl),
7428 N_Full_Type_Declaration,
7429 N_Object_Declaration,
7430 N_Single_Protected_Declaration,
7431 N_Single_Task_Declaration)
7432 then
7433 Error_Pragma_Arg
7434 ("argument of pragma % must denote a full type or object "
7435 & "declaration", Arg1);
7436 end if;
7437 end Process_Atomic_Independent_Shared_Volatile;
7439 -------------------------------------------
7440 -- Process_Compile_Time_Warning_Or_Error --
7441 -------------------------------------------
7443 procedure Process_Compile_Time_Warning_Or_Error is
7444 Validation_Needed : Boolean := False;
7446 function Check_Node (N : Node_Id) return Traverse_Result;
7447 -- Tree visitor that checks if N is an attribute reference that can
7448 -- be statically computed by the back end. Validation_Needed is set
7449 -- to True if found.
7451 ----------------
7452 -- Check_Node --
7453 ----------------
7455 function Check_Node (N : Node_Id) return Traverse_Result is
7456 begin
7457 if Nkind (N) = N_Attribute_Reference
7458 and then Is_Entity_Name (Prefix (N))
7459 then
7460 declare
7461 Attr_Id : constant Attribute_Id :=
7462 Get_Attribute_Id (Attribute_Name (N));
7463 begin
7464 if Attr_Id = Attribute_Alignment
7465 or else Attr_Id = Attribute_Size
7466 then
7467 Validation_Needed := True;
7468 end if;
7469 end;
7470 end if;
7472 return OK;
7473 end Check_Node;
7475 procedure Check_Expression is new Traverse_Proc (Check_Node);
7477 -- Local variables
7479 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
7481 -- Start of processing for Process_Compile_Time_Warning_Or_Error
7483 begin
7484 Check_Arg_Count (2);
7485 Check_No_Identifiers;
7486 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
7487 Analyze_And_Resolve (Arg1x, Standard_Boolean);
7489 if Compile_Time_Known_Value (Arg1x) then
7490 Process_Compile_Time_Warning_Or_Error (N, Sloc (Arg1));
7492 -- Register the expression for its validation after the back end has
7493 -- been called if it has occurrences of attributes Size or Alignment
7494 -- (because they may be statically computed by the back end and hence
7495 -- the whole expression needs to be reevaluated).
7497 else
7498 Check_Expression (Arg1x);
7500 if Validation_Needed then
7501 Sem_Ch13.Validate_Compile_Time_Warning_Error (N);
7502 end if;
7503 end if;
7504 end Process_Compile_Time_Warning_Or_Error;
7506 ------------------------
7507 -- Process_Convention --
7508 ------------------------
7510 procedure Process_Convention
7511 (C : out Convention_Id;
7512 Ent : out Entity_Id)
7514 Cname : Name_Id;
7516 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
7517 -- Called if we have more than one Export/Import/Convention pragma.
7518 -- This is generally illegal, but we have a special case of allowing
7519 -- Import and Interface to coexist if they specify the convention in
7520 -- a consistent manner. We are allowed to do this, since Interface is
7521 -- an implementation defined pragma, and we choose to do it since we
7522 -- know Rational allows this combination. S is the entity id of the
7523 -- subprogram in question. This procedure also sets the special flag
7524 -- Import_Interface_Present in both pragmas in the case where we do
7525 -- have matching Import and Interface pragmas.
7527 procedure Set_Convention_From_Pragma (E : Entity_Id);
7528 -- Set convention in entity E, and also flag that the entity has a
7529 -- convention pragma. If entity is for a private or incomplete type,
7530 -- also set convention and flag on underlying type. This procedure
7531 -- also deals with the special case of C_Pass_By_Copy convention,
7532 -- and error checks for inappropriate convention specification.
7534 -------------------------------
7535 -- Diagnose_Multiple_Pragmas --
7536 -------------------------------
7538 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
7539 Pdec : constant Node_Id := Declaration_Node (S);
7540 Decl : Node_Id;
7541 Err : Boolean;
7543 function Same_Convention (Decl : Node_Id) return Boolean;
7544 -- Decl is a pragma node. This function returns True if this
7545 -- pragma has a first argument that is an identifier with a
7546 -- Chars field corresponding to the Convention_Id C.
7548 function Same_Name (Decl : Node_Id) return Boolean;
7549 -- Decl is a pragma node. This function returns True if this
7550 -- pragma has a second argument that is an identifier with a
7551 -- Chars field that matches the Chars of the current subprogram.
7553 ---------------------
7554 -- Same_Convention --
7555 ---------------------
7557 function Same_Convention (Decl : Node_Id) return Boolean is
7558 Arg1 : constant Node_Id :=
7559 First (Pragma_Argument_Associations (Decl));
7561 begin
7562 if Present (Arg1) then
7563 declare
7564 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
7565 begin
7566 if Nkind (Arg) = N_Identifier
7567 and then Is_Convention_Name (Chars (Arg))
7568 and then Get_Convention_Id (Chars (Arg)) = C
7569 then
7570 return True;
7571 end if;
7572 end;
7573 end if;
7575 return False;
7576 end Same_Convention;
7578 ---------------
7579 -- Same_Name --
7580 ---------------
7582 function Same_Name (Decl : Node_Id) return Boolean is
7583 Arg1 : constant Node_Id :=
7584 First (Pragma_Argument_Associations (Decl));
7585 Arg2 : Node_Id;
7587 begin
7588 if No (Arg1) then
7589 return False;
7590 end if;
7592 Arg2 := Next (Arg1);
7594 if No (Arg2) then
7595 return False;
7596 end if;
7598 declare
7599 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
7600 begin
7601 if Nkind (Arg) = N_Identifier
7602 and then Chars (Arg) = Chars (S)
7603 then
7604 return True;
7605 end if;
7606 end;
7608 return False;
7609 end Same_Name;
7611 -- Start of processing for Diagnose_Multiple_Pragmas
7613 begin
7614 Err := True;
7616 -- Definitely give message if we have Convention/Export here
7618 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
7619 null;
7621 -- If we have an Import or Export, scan back from pragma to
7622 -- find any previous pragma applying to the same procedure.
7623 -- The scan will be terminated by the start of the list, or
7624 -- hitting the subprogram declaration. This won't allow one
7625 -- pragma to appear in the public part and one in the private
7626 -- part, but that seems very unlikely in practice.
7628 else
7629 Decl := Prev (N);
7630 while Present (Decl) and then Decl /= Pdec loop
7632 -- Look for pragma with same name as us
7634 if Nkind (Decl) = N_Pragma
7635 and then Same_Name (Decl)
7636 then
7637 -- Give error if same as our pragma or Export/Convention
7639 if Nam_In (Pragma_Name_Unmapped (Decl),
7640 Name_Export,
7641 Name_Convention,
7642 Pragma_Name_Unmapped (N))
7643 then
7644 exit;
7646 -- Case of Import/Interface or the other way round
7648 elsif Nam_In (Pragma_Name_Unmapped (Decl),
7649 Name_Interface, Name_Import)
7650 then
7651 -- Here we know that we have Import and Interface. It
7652 -- doesn't matter which way round they are. See if
7653 -- they specify the same convention. If so, all OK,
7654 -- and set special flags to stop other messages
7656 if Same_Convention (Decl) then
7657 Set_Import_Interface_Present (N);
7658 Set_Import_Interface_Present (Decl);
7659 Err := False;
7661 -- If different conventions, special message
7663 else
7664 Error_Msg_Sloc := Sloc (Decl);
7665 Error_Pragma_Arg
7666 ("convention differs from that given#", Arg1);
7667 return;
7668 end if;
7669 end if;
7670 end if;
7672 Next (Decl);
7673 end loop;
7674 end if;
7676 -- Give message if needed if we fall through those tests
7677 -- except on Relaxed_RM_Semantics where we let go: either this
7678 -- is a case accepted/ignored by other Ada compilers (e.g.
7679 -- a mix of Convention and Import), or another error will be
7680 -- generated later (e.g. using both Import and Export).
7682 if Err and not Relaxed_RM_Semantics then
7683 Error_Pragma_Arg
7684 ("at most one Convention/Export/Import pragma is allowed",
7685 Arg2);
7686 end if;
7687 end Diagnose_Multiple_Pragmas;
7689 --------------------------------
7690 -- Set_Convention_From_Pragma --
7691 --------------------------------
7693 procedure Set_Convention_From_Pragma (E : Entity_Id) is
7694 begin
7695 -- Ada 2005 (AI-430): Check invalid attempt to change convention
7696 -- for an overridden dispatching operation. Technically this is
7697 -- an amendment and should only be done in Ada 2005 mode. However,
7698 -- this is clearly a mistake, since the problem that is addressed
7699 -- by this AI is that there is a clear gap in the RM.
7701 if Is_Dispatching_Operation (E)
7702 and then Present (Overridden_Operation (E))
7703 and then C /= Convention (Overridden_Operation (E))
7704 then
7705 Error_Pragma_Arg
7706 ("cannot change convention for overridden dispatching "
7707 & "operation", Arg1);
7708 end if;
7710 -- Special checks for Convention_Stdcall
7712 if C = Convention_Stdcall then
7714 -- A dispatching call is not allowed. A dispatching subprogram
7715 -- cannot be used to interface to the Win32 API, so in fact
7716 -- this check does not impose any effective restriction.
7718 if Is_Dispatching_Operation (E) then
7719 Error_Msg_Sloc := Sloc (E);
7721 -- Note: make this unconditional so that if there is more
7722 -- than one call to which the pragma applies, we get a
7723 -- message for each call. Also don't use Error_Pragma,
7724 -- so that we get multiple messages.
7726 Error_Msg_N
7727 ("dispatching subprogram# cannot use Stdcall convention!",
7728 Arg1);
7730 -- Several allowed cases
7732 elsif Is_Subprogram_Or_Generic_Subprogram (E)
7734 -- A variable is OK
7736 or else Ekind (E) = E_Variable
7738 -- A component as well. The entity does not have its Ekind
7739 -- set until the enclosing record declaration is fully
7740 -- analyzed.
7742 or else Nkind (Parent (E)) = N_Component_Declaration
7744 -- An access to subprogram is also allowed
7746 or else
7747 (Is_Access_Type (E)
7748 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
7750 -- Allow internal call to set convention of subprogram type
7752 or else Ekind (E) = E_Subprogram_Type
7753 then
7754 null;
7756 else
7757 Error_Pragma_Arg
7758 ("second argument of pragma% must be subprogram (type)",
7759 Arg2);
7760 end if;
7761 end if;
7763 -- Set the convention
7765 Set_Convention (E, C);
7766 Set_Has_Convention_Pragma (E);
7768 -- For the case of a record base type, also set the convention of
7769 -- any anonymous access types declared in the record which do not
7770 -- currently have a specified convention.
7772 if Is_Record_Type (E) and then Is_Base_Type (E) then
7773 declare
7774 Comp : Node_Id;
7776 begin
7777 Comp := First_Component (E);
7778 while Present (Comp) loop
7779 if Present (Etype (Comp))
7780 and then Ekind_In (Etype (Comp),
7781 E_Anonymous_Access_Type,
7782 E_Anonymous_Access_Subprogram_Type)
7783 and then not Has_Convention_Pragma (Comp)
7784 then
7785 Set_Convention (Comp, C);
7786 end if;
7788 Next_Component (Comp);
7789 end loop;
7790 end;
7791 end if;
7793 -- Deal with incomplete/private type case, where underlying type
7794 -- is available, so set convention of that underlying type.
7796 if Is_Incomplete_Or_Private_Type (E)
7797 and then Present (Underlying_Type (E))
7798 then
7799 Set_Convention (Underlying_Type (E), C);
7800 Set_Has_Convention_Pragma (Underlying_Type (E), True);
7801 end if;
7803 -- A class-wide type should inherit the convention of the specific
7804 -- root type (although this isn't specified clearly by the RM).
7806 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
7807 Set_Convention (Class_Wide_Type (E), C);
7808 end if;
7810 -- If the entity is a record type, then check for special case of
7811 -- C_Pass_By_Copy, which is treated the same as C except that the
7812 -- special record flag is set. This convention is only permitted
7813 -- on record types (see AI95-00131).
7815 if Cname = Name_C_Pass_By_Copy then
7816 if Is_Record_Type (E) then
7817 Set_C_Pass_By_Copy (Base_Type (E));
7818 elsif Is_Incomplete_Or_Private_Type (E)
7819 and then Is_Record_Type (Underlying_Type (E))
7820 then
7821 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
7822 else
7823 Error_Pragma_Arg
7824 ("C_Pass_By_Copy convention allowed only for record type",
7825 Arg2);
7826 end if;
7827 end if;
7829 -- If the entity is a derived boolean type, check for the special
7830 -- case of convention C, C++, or Fortran, where we consider any
7831 -- nonzero value to represent true.
7833 if Is_Discrete_Type (E)
7834 and then Root_Type (Etype (E)) = Standard_Boolean
7835 and then
7836 (C = Convention_C
7837 or else
7838 C = Convention_CPP
7839 or else
7840 C = Convention_Fortran)
7841 then
7842 Set_Nonzero_Is_True (Base_Type (E));
7843 end if;
7844 end Set_Convention_From_Pragma;
7846 -- Local variables
7848 Comp_Unit : Unit_Number_Type;
7849 E : Entity_Id;
7850 E1 : Entity_Id;
7851 Id : Node_Id;
7853 -- Start of processing for Process_Convention
7855 begin
7856 Check_At_Least_N_Arguments (2);
7857 Check_Optional_Identifier (Arg1, Name_Convention);
7858 Check_Arg_Is_Identifier (Arg1);
7859 Cname := Chars (Get_Pragma_Arg (Arg1));
7861 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
7862 -- tested again below to set the critical flag).
7864 if Cname = Name_C_Pass_By_Copy then
7865 C := Convention_C;
7867 -- Otherwise we must have something in the standard convention list
7869 elsif Is_Convention_Name (Cname) then
7870 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
7872 -- Otherwise warn on unrecognized convention
7874 else
7875 if Warn_On_Export_Import then
7876 Error_Msg_N
7877 ("??unrecognized convention name, C assumed",
7878 Get_Pragma_Arg (Arg1));
7879 end if;
7881 C := Convention_C;
7882 end if;
7884 Check_Optional_Identifier (Arg2, Name_Entity);
7885 Check_Arg_Is_Local_Name (Arg2);
7887 Id := Get_Pragma_Arg (Arg2);
7888 Analyze (Id);
7890 if not Is_Entity_Name (Id) then
7891 Error_Pragma_Arg ("entity name required", Arg2);
7892 end if;
7894 E := Entity (Id);
7896 -- Set entity to return
7898 Ent := E;
7900 -- Ada_Pass_By_Copy special checking
7902 if C = Convention_Ada_Pass_By_Copy then
7903 if not Is_First_Subtype (E) then
7904 Error_Pragma_Arg
7905 ("convention `Ada_Pass_By_Copy` only allowed for types",
7906 Arg2);
7907 end if;
7909 if Is_By_Reference_Type (E) then
7910 Error_Pragma_Arg
7911 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
7912 & "type", Arg1);
7913 end if;
7915 -- Ada_Pass_By_Reference special checking
7917 elsif C = Convention_Ada_Pass_By_Reference then
7918 if not Is_First_Subtype (E) then
7919 Error_Pragma_Arg
7920 ("convention `Ada_Pass_By_Reference` only allowed for types",
7921 Arg2);
7922 end if;
7924 if Is_By_Copy_Type (E) then
7925 Error_Pragma_Arg
7926 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
7927 & "type", Arg1);
7928 end if;
7929 end if;
7931 -- Go to renamed subprogram if present, since convention applies to
7932 -- the actual renamed entity, not to the renaming entity. If the
7933 -- subprogram is inherited, go to parent subprogram.
7935 if Is_Subprogram (E)
7936 and then Present (Alias (E))
7937 then
7938 if Nkind (Parent (Declaration_Node (E))) =
7939 N_Subprogram_Renaming_Declaration
7940 then
7941 if Scope (E) /= Scope (Alias (E)) then
7942 Error_Pragma_Ref
7943 ("cannot apply pragma% to non-local entity&#", E);
7944 end if;
7946 E := Alias (E);
7948 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
7949 N_Private_Extension_Declaration)
7950 and then Scope (E) = Scope (Alias (E))
7951 then
7952 E := Alias (E);
7954 -- Return the parent subprogram the entity was inherited from
7956 Ent := E;
7957 end if;
7958 end if;
7960 -- Check that we are not applying this to a specless body. Relax this
7961 -- check if Relaxed_RM_Semantics to accommodate other Ada compilers.
7963 if Is_Subprogram (E)
7964 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
7965 and then not Relaxed_RM_Semantics
7966 then
7967 Error_Pragma
7968 ("pragma% requires separate spec and must come before body");
7969 end if;
7971 -- Check that we are not applying this to a named constant
7973 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
7974 Error_Msg_Name_1 := Pname;
7975 Error_Msg_N
7976 ("cannot apply pragma% to named constant!",
7977 Get_Pragma_Arg (Arg2));
7978 Error_Pragma_Arg
7979 ("\supply appropriate type for&!", Arg2);
7980 end if;
7982 if Ekind (E) = E_Enumeration_Literal then
7983 Error_Pragma ("enumeration literal not allowed for pragma%");
7984 end if;
7986 -- Check for rep item appearing too early or too late
7988 if Etype (E) = Any_Type
7989 or else Rep_Item_Too_Early (E, N)
7990 then
7991 raise Pragma_Exit;
7993 elsif Present (Underlying_Type (E)) then
7994 E := Underlying_Type (E);
7995 end if;
7997 if Rep_Item_Too_Late (E, N) then
7998 raise Pragma_Exit;
7999 end if;
8001 if Has_Convention_Pragma (E) then
8002 Diagnose_Multiple_Pragmas (E);
8004 elsif Convention (E) = Convention_Protected
8005 or else Ekind (Scope (E)) = E_Protected_Type
8006 then
8007 Error_Pragma_Arg
8008 ("a protected operation cannot be given a different convention",
8009 Arg2);
8010 end if;
8012 -- For Intrinsic, a subprogram is required
8014 if C = Convention_Intrinsic
8015 and then not Is_Subprogram_Or_Generic_Subprogram (E)
8016 then
8017 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
8019 if not (Is_Type (E) and then Relaxed_RM_Semantics) then
8020 Error_Pragma_Arg
8021 ("second argument of pragma% must be a subprogram", Arg2);
8022 end if;
8023 end if;
8025 -- Deal with non-subprogram cases
8027 if not Is_Subprogram_Or_Generic_Subprogram (E) then
8028 Set_Convention_From_Pragma (E);
8030 if Is_Type (E) then
8032 -- The pragma must apply to a first subtype, but it can also
8033 -- apply to a generic type in a generic formal part, in which
8034 -- case it will also appear in the corresponding instance.
8036 if Is_Generic_Type (E) or else In_Instance then
8037 null;
8038 else
8039 Check_First_Subtype (Arg2);
8040 end if;
8042 Set_Convention_From_Pragma (Base_Type (E));
8044 -- For access subprograms, we must set the convention on the
8045 -- internally generated directly designated type as well.
8047 if Ekind (E) = E_Access_Subprogram_Type then
8048 Set_Convention_From_Pragma (Directly_Designated_Type (E));
8049 end if;
8050 end if;
8052 -- For the subprogram case, set proper convention for all homonyms
8053 -- in same scope and the same declarative part, i.e. the same
8054 -- compilation unit.
8056 else
8057 Comp_Unit := Get_Source_Unit (E);
8058 Set_Convention_From_Pragma (E);
8060 -- Treat a pragma Import as an implicit body, and pragma import
8061 -- as implicit reference (for navigation in GPS).
8063 if Prag_Id = Pragma_Import then
8064 Generate_Reference (E, Id, 'b');
8066 -- For exported entities we restrict the generation of references
8067 -- to entities exported to foreign languages since entities
8068 -- exported to Ada do not provide further information to GPS and
8069 -- add undesired references to the output of the gnatxref tool.
8071 elsif Prag_Id = Pragma_Export
8072 and then Convention (E) /= Convention_Ada
8073 then
8074 Generate_Reference (E, Id, 'i');
8075 end if;
8077 -- If the pragma comes from an aspect, it only applies to the
8078 -- given entity, not its homonyms.
8080 if From_Aspect_Specification (N) then
8081 if C = Convention_Intrinsic
8082 and then Nkind (Ent) = N_Defining_Operator_Symbol
8083 then
8084 if Is_Fixed_Point_Type (Etype (Ent))
8085 or else Is_Fixed_Point_Type (Etype (First_Entity (Ent)))
8086 or else Is_Fixed_Point_Type (Etype (Last_Entity (Ent)))
8087 then
8088 Error_Msg_N
8089 ("no intrinsic operator available for this fixed-point "
8090 & "operation", N);
8091 Error_Msg_N
8092 ("\use expression functions with the desired "
8093 & "conversions made explicit", N);
8094 end if;
8095 end if;
8097 return;
8098 end if;
8100 -- Otherwise Loop through the homonyms of the pragma argument's
8101 -- entity, an apply convention to those in the current scope.
8103 E1 := Ent;
8105 loop
8106 E1 := Homonym (E1);
8107 exit when No (E1) or else Scope (E1) /= Current_Scope;
8109 -- Ignore entry for which convention is already set
8111 if Has_Convention_Pragma (E1) then
8112 goto Continue;
8113 end if;
8115 if Is_Subprogram (E1)
8116 and then Nkind (Parent (Declaration_Node (E1))) =
8117 N_Subprogram_Body
8118 and then not Relaxed_RM_Semantics
8119 then
8120 Set_Has_Completion (E); -- to prevent cascaded error
8121 Error_Pragma_Ref
8122 ("pragma% requires separate spec and must come before "
8123 & "body#", E1);
8124 end if;
8126 -- Do not set the pragma on inherited operations or on formal
8127 -- subprograms.
8129 if Comes_From_Source (E1)
8130 and then Comp_Unit = Get_Source_Unit (E1)
8131 and then not Is_Formal_Subprogram (E1)
8132 and then Nkind (Original_Node (Parent (E1))) /=
8133 N_Full_Type_Declaration
8134 then
8135 if Present (Alias (E1))
8136 and then Scope (E1) /= Scope (Alias (E1))
8137 then
8138 Error_Pragma_Ref
8139 ("cannot apply pragma% to non-local entity& declared#",
8140 E1);
8141 end if;
8143 Set_Convention_From_Pragma (E1);
8145 if Prag_Id = Pragma_Import then
8146 Generate_Reference (E1, Id, 'b');
8147 end if;
8148 end if;
8150 <<Continue>>
8151 null;
8152 end loop;
8153 end if;
8154 end Process_Convention;
8156 ----------------------------------------
8157 -- Process_Disable_Enable_Atomic_Sync --
8158 ----------------------------------------
8160 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
8161 begin
8162 Check_No_Identifiers;
8163 Check_At_Most_N_Arguments (1);
8165 -- Modeled internally as
8166 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
8168 Rewrite (N,
8169 Make_Pragma (Loc,
8170 Chars => Nam,
8171 Pragma_Argument_Associations => New_List (
8172 Make_Pragma_Argument_Association (Loc,
8173 Expression =>
8174 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
8176 if Present (Arg1) then
8177 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
8178 end if;
8180 Analyze (N);
8181 end Process_Disable_Enable_Atomic_Sync;
8183 -------------------------------------------------
8184 -- Process_Extended_Import_Export_Internal_Arg --
8185 -------------------------------------------------
8187 procedure Process_Extended_Import_Export_Internal_Arg
8188 (Arg_Internal : Node_Id := Empty)
8190 begin
8191 if No (Arg_Internal) then
8192 Error_Pragma ("Internal parameter required for pragma%");
8193 end if;
8195 if Nkind (Arg_Internal) = N_Identifier then
8196 null;
8198 elsif Nkind (Arg_Internal) = N_Operator_Symbol
8199 and then (Prag_Id = Pragma_Import_Function
8200 or else
8201 Prag_Id = Pragma_Export_Function)
8202 then
8203 null;
8205 else
8206 Error_Pragma_Arg
8207 ("wrong form for Internal parameter for pragma%", Arg_Internal);
8208 end if;
8210 Check_Arg_Is_Local_Name (Arg_Internal);
8211 end Process_Extended_Import_Export_Internal_Arg;
8213 --------------------------------------------------
8214 -- Process_Extended_Import_Export_Object_Pragma --
8215 --------------------------------------------------
8217 procedure Process_Extended_Import_Export_Object_Pragma
8218 (Arg_Internal : Node_Id;
8219 Arg_External : Node_Id;
8220 Arg_Size : Node_Id)
8222 Def_Id : Entity_Id;
8224 begin
8225 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8226 Def_Id := Entity (Arg_Internal);
8228 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
8229 Error_Pragma_Arg
8230 ("pragma% must designate an object", Arg_Internal);
8231 end if;
8233 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
8234 or else
8235 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
8236 then
8237 Error_Pragma_Arg
8238 ("previous Common/Psect_Object applies, pragma % not permitted",
8239 Arg_Internal);
8240 end if;
8242 if Rep_Item_Too_Late (Def_Id, N) then
8243 raise Pragma_Exit;
8244 end if;
8246 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
8248 if Present (Arg_Size) then
8249 Check_Arg_Is_External_Name (Arg_Size);
8250 end if;
8252 -- Export_Object case
8254 if Prag_Id = Pragma_Export_Object then
8255 if not Is_Library_Level_Entity (Def_Id) then
8256 Error_Pragma_Arg
8257 ("argument for pragma% must be library level entity",
8258 Arg_Internal);
8259 end if;
8261 if Ekind (Current_Scope) = E_Generic_Package then
8262 Error_Pragma ("pragma& cannot appear in a generic unit");
8263 end if;
8265 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
8266 Error_Pragma_Arg
8267 ("exported object must have compile time known size",
8268 Arg_Internal);
8269 end if;
8271 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
8272 Error_Msg_N ("??duplicate Export_Object pragma", N);
8273 else
8274 Set_Exported (Def_Id, Arg_Internal);
8275 end if;
8277 -- Import_Object case
8279 else
8280 if Is_Concurrent_Type (Etype (Def_Id)) then
8281 Error_Pragma_Arg
8282 ("cannot use pragma% for task/protected object",
8283 Arg_Internal);
8284 end if;
8286 if Ekind (Def_Id) = E_Constant then
8287 Error_Pragma_Arg
8288 ("cannot import a constant", Arg_Internal);
8289 end if;
8291 if Warn_On_Export_Import
8292 and then Has_Discriminants (Etype (Def_Id))
8293 then
8294 Error_Msg_N
8295 ("imported value must be initialized??", Arg_Internal);
8296 end if;
8298 if Warn_On_Export_Import
8299 and then Is_Access_Type (Etype (Def_Id))
8300 then
8301 Error_Pragma_Arg
8302 ("cannot import object of an access type??", Arg_Internal);
8303 end if;
8305 if Warn_On_Export_Import
8306 and then Is_Imported (Def_Id)
8307 then
8308 Error_Msg_N ("??duplicate Import_Object pragma", N);
8310 -- Check for explicit initialization present. Note that an
8311 -- initialization generated by the code generator, e.g. for an
8312 -- access type, does not count here.
8314 elsif Present (Expression (Parent (Def_Id)))
8315 and then
8316 Comes_From_Source
8317 (Original_Node (Expression (Parent (Def_Id))))
8318 then
8319 Error_Msg_Sloc := Sloc (Def_Id);
8320 Error_Pragma_Arg
8321 ("imported entities cannot be initialized (RM B.1(24))",
8322 "\no initialization allowed for & declared#", Arg1);
8323 else
8324 Set_Imported (Def_Id);
8325 Note_Possible_Modification (Arg_Internal, Sure => False);
8326 end if;
8327 end if;
8328 end Process_Extended_Import_Export_Object_Pragma;
8330 ------------------------------------------------------
8331 -- Process_Extended_Import_Export_Subprogram_Pragma --
8332 ------------------------------------------------------
8334 procedure Process_Extended_Import_Export_Subprogram_Pragma
8335 (Arg_Internal : Node_Id;
8336 Arg_External : Node_Id;
8337 Arg_Parameter_Types : Node_Id;
8338 Arg_Result_Type : Node_Id := Empty;
8339 Arg_Mechanism : Node_Id;
8340 Arg_Result_Mechanism : Node_Id := Empty)
8342 Ent : Entity_Id;
8343 Def_Id : Entity_Id;
8344 Hom_Id : Entity_Id;
8345 Formal : Entity_Id;
8346 Ambiguous : Boolean;
8347 Match : Boolean;
8349 function Same_Base_Type
8350 (Ptype : Node_Id;
8351 Formal : Entity_Id) return Boolean;
8352 -- Determines if Ptype references the type of Formal. Note that only
8353 -- the base types need to match according to the spec. Ptype here is
8354 -- the argument from the pragma, which is either a type name, or an
8355 -- access attribute.
8357 --------------------
8358 -- Same_Base_Type --
8359 --------------------
8361 function Same_Base_Type
8362 (Ptype : Node_Id;
8363 Formal : Entity_Id) return Boolean
8365 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
8366 Pref : Node_Id;
8368 begin
8369 -- Case where pragma argument is typ'Access
8371 if Nkind (Ptype) = N_Attribute_Reference
8372 and then Attribute_Name (Ptype) = Name_Access
8373 then
8374 Pref := Prefix (Ptype);
8375 Find_Type (Pref);
8377 if not Is_Entity_Name (Pref)
8378 or else Entity (Pref) = Any_Type
8379 then
8380 raise Pragma_Exit;
8381 end if;
8383 -- We have a match if the corresponding argument is of an
8384 -- anonymous access type, and its designated type matches the
8385 -- type of the prefix of the access attribute
8387 return Ekind (Ftyp) = E_Anonymous_Access_Type
8388 and then Base_Type (Entity (Pref)) =
8389 Base_Type (Etype (Designated_Type (Ftyp)));
8391 -- Case where pragma argument is a type name
8393 else
8394 Find_Type (Ptype);
8396 if not Is_Entity_Name (Ptype)
8397 or else Entity (Ptype) = Any_Type
8398 then
8399 raise Pragma_Exit;
8400 end if;
8402 -- We have a match if the corresponding argument is of the type
8403 -- given in the pragma (comparing base types)
8405 return Base_Type (Entity (Ptype)) = Ftyp;
8406 end if;
8407 end Same_Base_Type;
8409 -- Start of processing for
8410 -- Process_Extended_Import_Export_Subprogram_Pragma
8412 begin
8413 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8414 Ent := Empty;
8415 Ambiguous := False;
8417 -- Loop through homonyms (overloadings) of the entity
8419 Hom_Id := Entity (Arg_Internal);
8420 while Present (Hom_Id) loop
8421 Def_Id := Get_Base_Subprogram (Hom_Id);
8423 -- We need a subprogram in the current scope
8425 if not Is_Subprogram (Def_Id)
8426 or else Scope (Def_Id) /= Current_Scope
8427 then
8428 null;
8430 else
8431 Match := True;
8433 -- Pragma cannot apply to subprogram body
8435 if Is_Subprogram (Def_Id)
8436 and then Nkind (Parent (Declaration_Node (Def_Id))) =
8437 N_Subprogram_Body
8438 then
8439 Error_Pragma
8440 ("pragma% requires separate spec and must come before "
8441 & "body");
8442 end if;
8444 -- Test result type if given, note that the result type
8445 -- parameter can only be present for the function cases.
8447 if Present (Arg_Result_Type)
8448 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
8449 then
8450 Match := False;
8452 elsif Etype (Def_Id) /= Standard_Void_Type
8453 and then Nam_In (Pname, Name_Export_Procedure,
8454 Name_Import_Procedure)
8455 then
8456 Match := False;
8458 -- Test parameter types if given. Note that this parameter has
8459 -- not been analyzed (and must not be, since it is semantic
8460 -- nonsense), so we get it as the parser left it.
8462 elsif Present (Arg_Parameter_Types) then
8463 Check_Matching_Types : declare
8464 Formal : Entity_Id;
8465 Ptype : Node_Id;
8467 begin
8468 Formal := First_Formal (Def_Id);
8470 if Nkind (Arg_Parameter_Types) = N_Null then
8471 if Present (Formal) then
8472 Match := False;
8473 end if;
8475 -- A list of one type, e.g. (List) is parsed as a
8476 -- parenthesized expression.
8478 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
8479 and then Paren_Count (Arg_Parameter_Types) = 1
8480 then
8481 if No (Formal)
8482 or else Present (Next_Formal (Formal))
8483 then
8484 Match := False;
8485 else
8486 Match :=
8487 Same_Base_Type (Arg_Parameter_Types, Formal);
8488 end if;
8490 -- A list of more than one type is parsed as a aggregate
8492 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
8493 and then Paren_Count (Arg_Parameter_Types) = 0
8494 then
8495 Ptype := First (Expressions (Arg_Parameter_Types));
8496 while Present (Ptype) or else Present (Formal) loop
8497 if No (Ptype)
8498 or else No (Formal)
8499 or else not Same_Base_Type (Ptype, Formal)
8500 then
8501 Match := False;
8502 exit;
8503 else
8504 Next_Formal (Formal);
8505 Next (Ptype);
8506 end if;
8507 end loop;
8509 -- Anything else is of the wrong form
8511 else
8512 Error_Pragma_Arg
8513 ("wrong form for Parameter_Types parameter",
8514 Arg_Parameter_Types);
8515 end if;
8516 end Check_Matching_Types;
8517 end if;
8519 -- Match is now False if the entry we found did not match
8520 -- either a supplied Parameter_Types or Result_Types argument
8522 if Match then
8523 if No (Ent) then
8524 Ent := Def_Id;
8526 -- Ambiguous case, the flag Ambiguous shows if we already
8527 -- detected this and output the initial messages.
8529 else
8530 if not Ambiguous then
8531 Ambiguous := True;
8532 Error_Msg_Name_1 := Pname;
8533 Error_Msg_N
8534 ("pragma% does not uniquely identify subprogram!",
8536 Error_Msg_Sloc := Sloc (Ent);
8537 Error_Msg_N ("matching subprogram #!", N);
8538 Ent := Empty;
8539 end if;
8541 Error_Msg_Sloc := Sloc (Def_Id);
8542 Error_Msg_N ("matching subprogram #!", N);
8543 end if;
8544 end if;
8545 end if;
8547 Hom_Id := Homonym (Hom_Id);
8548 end loop;
8550 -- See if we found an entry
8552 if No (Ent) then
8553 if not Ambiguous then
8554 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
8555 Error_Pragma
8556 ("pragma% cannot be given for generic subprogram");
8557 else
8558 Error_Pragma
8559 ("pragma% does not identify local subprogram");
8560 end if;
8561 end if;
8563 return;
8564 end if;
8566 -- Import pragmas must be for imported entities
8568 if Prag_Id = Pragma_Import_Function
8569 or else
8570 Prag_Id = Pragma_Import_Procedure
8571 or else
8572 Prag_Id = Pragma_Import_Valued_Procedure
8573 then
8574 if not Is_Imported (Ent) then
8575 Error_Pragma
8576 ("pragma Import or Interface must precede pragma%");
8577 end if;
8579 -- Here we have the Export case which can set the entity as exported
8581 -- But does not do so if the specified external name is null, since
8582 -- that is taken as a signal in DEC Ada 83 (with which we want to be
8583 -- compatible) to request no external name.
8585 elsif Nkind (Arg_External) = N_String_Literal
8586 and then String_Length (Strval (Arg_External)) = 0
8587 then
8588 null;
8590 -- In all other cases, set entity as exported
8592 else
8593 Set_Exported (Ent, Arg_Internal);
8594 end if;
8596 -- Special processing for Valued_Procedure cases
8598 if Prag_Id = Pragma_Import_Valued_Procedure
8599 or else
8600 Prag_Id = Pragma_Export_Valued_Procedure
8601 then
8602 Formal := First_Formal (Ent);
8604 if No (Formal) then
8605 Error_Pragma ("at least one parameter required for pragma%");
8607 elsif Ekind (Formal) /= E_Out_Parameter then
8608 Error_Pragma ("first parameter must have mode out for pragma%");
8610 else
8611 Set_Is_Valued_Procedure (Ent);
8612 end if;
8613 end if;
8615 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
8617 -- Process Result_Mechanism argument if present. We have already
8618 -- checked that this is only allowed for the function case.
8620 if Present (Arg_Result_Mechanism) then
8621 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
8622 end if;
8624 -- Process Mechanism parameter if present. Note that this parameter
8625 -- is not analyzed, and must not be analyzed since it is semantic
8626 -- nonsense, so we get it in exactly as the parser left it.
8628 if Present (Arg_Mechanism) then
8629 declare
8630 Formal : Entity_Id;
8631 Massoc : Node_Id;
8632 Mname : Node_Id;
8633 Choice : Node_Id;
8635 begin
8636 -- A single mechanism association without a formal parameter
8637 -- name is parsed as a parenthesized expression. All other
8638 -- cases are parsed as aggregates, so we rewrite the single
8639 -- parameter case as an aggregate for consistency.
8641 if Nkind (Arg_Mechanism) /= N_Aggregate
8642 and then Paren_Count (Arg_Mechanism) = 1
8643 then
8644 Rewrite (Arg_Mechanism,
8645 Make_Aggregate (Sloc (Arg_Mechanism),
8646 Expressions => New_List (
8647 Relocate_Node (Arg_Mechanism))));
8648 end if;
8650 -- Case of only mechanism name given, applies to all formals
8652 if Nkind (Arg_Mechanism) /= N_Aggregate then
8653 Formal := First_Formal (Ent);
8654 while Present (Formal) loop
8655 Set_Mechanism_Value (Formal, Arg_Mechanism);
8656 Next_Formal (Formal);
8657 end loop;
8659 -- Case of list of mechanism associations given
8661 else
8662 if Null_Record_Present (Arg_Mechanism) then
8663 Error_Pragma_Arg
8664 ("inappropriate form for Mechanism parameter",
8665 Arg_Mechanism);
8666 end if;
8668 -- Deal with positional ones first
8670 Formal := First_Formal (Ent);
8672 if Present (Expressions (Arg_Mechanism)) then
8673 Mname := First (Expressions (Arg_Mechanism));
8674 while Present (Mname) loop
8675 if No (Formal) then
8676 Error_Pragma_Arg
8677 ("too many mechanism associations", Mname);
8678 end if;
8680 Set_Mechanism_Value (Formal, Mname);
8681 Next_Formal (Formal);
8682 Next (Mname);
8683 end loop;
8684 end if;
8686 -- Deal with named entries
8688 if Present (Component_Associations (Arg_Mechanism)) then
8689 Massoc := First (Component_Associations (Arg_Mechanism));
8690 while Present (Massoc) loop
8691 Choice := First (Choices (Massoc));
8693 if Nkind (Choice) /= N_Identifier
8694 or else Present (Next (Choice))
8695 then
8696 Error_Pragma_Arg
8697 ("incorrect form for mechanism association",
8698 Massoc);
8699 end if;
8701 Formal := First_Formal (Ent);
8702 loop
8703 if No (Formal) then
8704 Error_Pragma_Arg
8705 ("parameter name & not present", Choice);
8706 end if;
8708 if Chars (Choice) = Chars (Formal) then
8709 Set_Mechanism_Value
8710 (Formal, Expression (Massoc));
8712 -- Set entity on identifier (needed by ASIS)
8714 Set_Entity (Choice, Formal);
8716 exit;
8717 end if;
8719 Next_Formal (Formal);
8720 end loop;
8722 Next (Massoc);
8723 end loop;
8724 end if;
8725 end if;
8726 end;
8727 end if;
8728 end Process_Extended_Import_Export_Subprogram_Pragma;
8730 --------------------------
8731 -- Process_Generic_List --
8732 --------------------------
8734 procedure Process_Generic_List is
8735 Arg : Node_Id;
8736 Exp : Node_Id;
8738 begin
8739 Check_No_Identifiers;
8740 Check_At_Least_N_Arguments (1);
8742 -- Check all arguments are names of generic units or instances
8744 Arg := Arg1;
8745 while Present (Arg) loop
8746 Exp := Get_Pragma_Arg (Arg);
8747 Analyze (Exp);
8749 if not Is_Entity_Name (Exp)
8750 or else
8751 (not Is_Generic_Instance (Entity (Exp))
8752 and then
8753 not Is_Generic_Unit (Entity (Exp)))
8754 then
8755 Error_Pragma_Arg
8756 ("pragma% argument must be name of generic unit/instance",
8757 Arg);
8758 end if;
8760 Next (Arg);
8761 end loop;
8762 end Process_Generic_List;
8764 ------------------------------------
8765 -- Process_Import_Predefined_Type --
8766 ------------------------------------
8768 procedure Process_Import_Predefined_Type is
8769 Loc : constant Source_Ptr := Sloc (N);
8770 Elmt : Elmt_Id;
8771 Ftyp : Node_Id := Empty;
8772 Decl : Node_Id;
8773 Def : Node_Id;
8774 Nam : Name_Id;
8776 begin
8777 Nam := String_To_Name (Strval (Expression (Arg3)));
8779 Elmt := First_Elmt (Predefined_Float_Types);
8780 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
8781 Next_Elmt (Elmt);
8782 end loop;
8784 Ftyp := Node (Elmt);
8786 if Present (Ftyp) then
8788 -- Don't build a derived type declaration, because predefined C
8789 -- types have no declaration anywhere, so cannot really be named.
8790 -- Instead build a full type declaration, starting with an
8791 -- appropriate type definition is built
8793 if Is_Floating_Point_Type (Ftyp) then
8794 Def := Make_Floating_Point_Definition (Loc,
8795 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
8796 Make_Real_Range_Specification (Loc,
8797 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
8798 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
8800 -- Should never have a predefined type we cannot handle
8802 else
8803 raise Program_Error;
8804 end if;
8806 -- Build and insert a Full_Type_Declaration, which will be
8807 -- analyzed as soon as this list entry has been analyzed.
8809 Decl := Make_Full_Type_Declaration (Loc,
8810 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
8811 Type_Definition => Def);
8813 Insert_After (N, Decl);
8814 Mark_Rewrite_Insertion (Decl);
8816 else
8817 Error_Pragma_Arg ("no matching type found for pragma%",
8818 Arg2);
8819 end if;
8820 end Process_Import_Predefined_Type;
8822 ---------------------------------
8823 -- Process_Import_Or_Interface --
8824 ---------------------------------
8826 procedure Process_Import_Or_Interface is
8827 C : Convention_Id;
8828 Def_Id : Entity_Id;
8829 Hom_Id : Entity_Id;
8831 begin
8832 -- In Relaxed_RM_Semantics, support old Ada 83 style:
8833 -- pragma Import (Entity, "external name");
8835 if Relaxed_RM_Semantics
8836 and then Arg_Count = 2
8837 and then Prag_Id = Pragma_Import
8838 and then Nkind (Expression (Arg2)) = N_String_Literal
8839 then
8840 C := Convention_C;
8841 Def_Id := Get_Pragma_Arg (Arg1);
8842 Analyze (Def_Id);
8844 if not Is_Entity_Name (Def_Id) then
8845 Error_Pragma_Arg ("entity name required", Arg1);
8846 end if;
8848 Def_Id := Entity (Def_Id);
8849 Kill_Size_Check_Code (Def_Id);
8850 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
8852 else
8853 Process_Convention (C, Def_Id);
8855 -- A pragma that applies to a Ghost entity becomes Ghost for the
8856 -- purposes of legality checks and removal of ignored Ghost code.
8858 Mark_Ghost_Pragma (N, Def_Id);
8859 Kill_Size_Check_Code (Def_Id);
8860 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
8861 end if;
8863 -- Various error checks
8865 if Ekind_In (Def_Id, E_Variable, E_Constant) then
8867 -- We do not permit Import to apply to a renaming declaration
8869 if Present (Renamed_Object (Def_Id)) then
8870 Error_Pragma_Arg
8871 ("pragma% not allowed for object renaming", Arg2);
8873 -- User initialization is not allowed for imported object, but
8874 -- the object declaration may contain a default initialization,
8875 -- that will be discarded. Note that an explicit initialization
8876 -- only counts if it comes from source, otherwise it is simply
8877 -- the code generator making an implicit initialization explicit.
8879 elsif Present (Expression (Parent (Def_Id)))
8880 and then Comes_From_Source
8881 (Original_Node (Expression (Parent (Def_Id))))
8882 then
8883 -- Set imported flag to prevent cascaded errors
8885 Set_Is_Imported (Def_Id);
8887 Error_Msg_Sloc := Sloc (Def_Id);
8888 Error_Pragma_Arg
8889 ("no initialization allowed for declaration of& #",
8890 "\imported entities cannot be initialized (RM B.1(24))",
8891 Arg2);
8893 else
8894 -- If the pragma comes from an aspect specification the
8895 -- Is_Imported flag has already been set.
8897 if not From_Aspect_Specification (N) then
8898 Set_Imported (Def_Id);
8899 end if;
8901 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
8903 -- Note that we do not set Is_Public here. That's because we
8904 -- only want to set it if there is no address clause, and we
8905 -- don't know that yet, so we delay that processing till
8906 -- freeze time.
8908 -- pragma Import completes deferred constants
8910 if Ekind (Def_Id) = E_Constant then
8911 Set_Has_Completion (Def_Id);
8912 end if;
8914 -- It is not possible to import a constant of an unconstrained
8915 -- array type (e.g. string) because there is no simple way to
8916 -- write a meaningful subtype for it.
8918 if Is_Array_Type (Etype (Def_Id))
8919 and then not Is_Constrained (Etype (Def_Id))
8920 then
8921 Error_Msg_NE
8922 ("imported constant& must have a constrained subtype",
8923 N, Def_Id);
8924 end if;
8925 end if;
8927 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
8929 -- If the name is overloaded, pragma applies to all of the denoted
8930 -- entities in the same declarative part, unless the pragma comes
8931 -- from an aspect specification or was generated by the compiler
8932 -- (such as for pragma Provide_Shift_Operators).
8934 Hom_Id := Def_Id;
8935 while Present (Hom_Id) loop
8937 Def_Id := Get_Base_Subprogram (Hom_Id);
8939 -- Ignore inherited subprograms because the pragma will apply
8940 -- to the parent operation, which is the one called.
8942 if Is_Overloadable (Def_Id)
8943 and then Present (Alias (Def_Id))
8944 then
8945 null;
8947 -- If it is not a subprogram, it must be in an outer scope and
8948 -- pragma does not apply.
8950 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
8951 null;
8953 -- The pragma does not apply to primitives of interfaces
8955 elsif Is_Dispatching_Operation (Def_Id)
8956 and then Present (Find_Dispatching_Type (Def_Id))
8957 and then Is_Interface (Find_Dispatching_Type (Def_Id))
8958 then
8959 null;
8961 -- Verify that the homonym is in the same declarative part (not
8962 -- just the same scope). If the pragma comes from an aspect
8963 -- specification we know that it is part of the declaration.
8965 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
8966 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
8967 and then not From_Aspect_Specification (N)
8968 then
8969 exit;
8971 else
8972 -- If the pragma comes from an aspect specification the
8973 -- Is_Imported flag has already been set.
8975 if not From_Aspect_Specification (N) then
8976 Set_Imported (Def_Id);
8977 end if;
8979 -- Reject an Import applied to an abstract subprogram
8981 if Is_Subprogram (Def_Id)
8982 and then Is_Abstract_Subprogram (Def_Id)
8983 then
8984 Error_Msg_Sloc := Sloc (Def_Id);
8985 Error_Msg_NE
8986 ("cannot import abstract subprogram& declared#",
8987 Arg2, Def_Id);
8988 end if;
8990 -- Special processing for Convention_Intrinsic
8992 if C = Convention_Intrinsic then
8994 -- Link_Name argument not allowed for intrinsic
8996 Check_No_Link_Name;
8998 Set_Is_Intrinsic_Subprogram (Def_Id);
9000 -- If no external name is present, then check that this
9001 -- is a valid intrinsic subprogram. If an external name
9002 -- is present, then this is handled by the back end.
9004 if No (Arg3) then
9005 Check_Intrinsic_Subprogram
9006 (Def_Id, Get_Pragma_Arg (Arg2));
9007 end if;
9008 end if;
9010 -- Verify that the subprogram does not have a completion
9011 -- through a renaming declaration. For other completions the
9012 -- pragma appears as a too late representation.
9014 declare
9015 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
9017 begin
9018 if Present (Decl)
9019 and then Nkind (Decl) = N_Subprogram_Declaration
9020 and then Present (Corresponding_Body (Decl))
9021 and then Nkind (Unit_Declaration_Node
9022 (Corresponding_Body (Decl))) =
9023 N_Subprogram_Renaming_Declaration
9024 then
9025 Error_Msg_Sloc := Sloc (Def_Id);
9026 Error_Msg_NE
9027 ("cannot import&, renaming already provided for "
9028 & "declaration #", N, Def_Id);
9029 end if;
9030 end;
9032 -- If the pragma comes from an aspect specification, there
9033 -- must be an Import aspect specified as well. In the rare
9034 -- case where Import is set to False, the suprogram needs to
9035 -- have a local completion.
9037 declare
9038 Imp_Aspect : constant Node_Id :=
9039 Find_Aspect (Def_Id, Aspect_Import);
9040 Expr : Node_Id;
9042 begin
9043 if Present (Imp_Aspect)
9044 and then Present (Expression (Imp_Aspect))
9045 then
9046 Expr := Expression (Imp_Aspect);
9047 Analyze_And_Resolve (Expr, Standard_Boolean);
9049 if Is_Entity_Name (Expr)
9050 and then Entity (Expr) = Standard_True
9051 then
9052 Set_Has_Completion (Def_Id);
9053 end if;
9055 -- If there is no expression, the default is True, as for
9056 -- all boolean aspects. Same for the older pragma.
9058 else
9059 Set_Has_Completion (Def_Id);
9060 end if;
9061 end;
9063 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
9064 end if;
9066 if Is_Compilation_Unit (Hom_Id) then
9068 -- Its possible homonyms are not affected by the pragma.
9069 -- Such homonyms might be present in the context of other
9070 -- units being compiled.
9072 exit;
9074 elsif From_Aspect_Specification (N) then
9075 exit;
9077 -- If the pragma was created by the compiler, then we don't
9078 -- want it to apply to other homonyms. This kind of case can
9079 -- occur when using pragma Provide_Shift_Operators, which
9080 -- generates implicit shift and rotate operators with Import
9081 -- pragmas that might apply to earlier explicit or implicit
9082 -- declarations marked with Import (for example, coming from
9083 -- an earlier pragma Provide_Shift_Operators for another type),
9084 -- and we don't generally want other homonyms being treated
9085 -- as imported or the pragma flagged as an illegal duplicate.
9087 elsif not Comes_From_Source (N) then
9088 exit;
9090 else
9091 Hom_Id := Homonym (Hom_Id);
9092 end if;
9093 end loop;
9095 -- Import a CPP class
9097 elsif C = Convention_CPP
9098 and then (Is_Record_Type (Def_Id)
9099 or else Ekind (Def_Id) = E_Incomplete_Type)
9100 then
9101 if Ekind (Def_Id) = E_Incomplete_Type then
9102 if Present (Full_View (Def_Id)) then
9103 Def_Id := Full_View (Def_Id);
9105 else
9106 Error_Msg_N
9107 ("cannot import 'C'P'P type before full declaration seen",
9108 Get_Pragma_Arg (Arg2));
9110 -- Although we have reported the error we decorate it as
9111 -- CPP_Class to avoid reporting spurious errors
9113 Set_Is_CPP_Class (Def_Id);
9114 return;
9115 end if;
9116 end if;
9118 -- Types treated as CPP classes must be declared limited (note:
9119 -- this used to be a warning but there is no real benefit to it
9120 -- since we did effectively intend to treat the type as limited
9121 -- anyway).
9123 if not Is_Limited_Type (Def_Id) then
9124 Error_Msg_N
9125 ("imported 'C'P'P type must be limited",
9126 Get_Pragma_Arg (Arg2));
9127 end if;
9129 if Etype (Def_Id) /= Def_Id
9130 and then not Is_CPP_Class (Root_Type (Def_Id))
9131 then
9132 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
9133 end if;
9135 Set_Is_CPP_Class (Def_Id);
9137 -- Imported CPP types must not have discriminants (because C++
9138 -- classes do not have discriminants).
9140 if Has_Discriminants (Def_Id) then
9141 Error_Msg_N
9142 ("imported 'C'P'P type cannot have discriminants",
9143 First (Discriminant_Specifications
9144 (Declaration_Node (Def_Id))));
9145 end if;
9147 -- Check that components of imported CPP types do not have default
9148 -- expressions. For private types this check is performed when the
9149 -- full view is analyzed (see Process_Full_View).
9151 if not Is_Private_Type (Def_Id) then
9152 Check_CPP_Type_Has_No_Defaults (Def_Id);
9153 end if;
9155 -- Import a CPP exception
9157 elsif C = Convention_CPP
9158 and then Ekind (Def_Id) = E_Exception
9159 then
9160 if No (Arg3) then
9161 Error_Pragma_Arg
9162 ("'External_'Name arguments is required for 'Cpp exception",
9163 Arg3);
9164 else
9165 -- As only a string is allowed, Check_Arg_Is_External_Name
9166 -- isn't called.
9168 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9169 end if;
9171 if Present (Arg4) then
9172 Error_Pragma_Arg
9173 ("Link_Name argument not allowed for imported Cpp exception",
9174 Arg4);
9175 end if;
9177 -- Do not call Set_Interface_Name as the name of the exception
9178 -- shouldn't be modified (and in particular it shouldn't be
9179 -- the External_Name). For exceptions, the External_Name is the
9180 -- name of the RTTI structure.
9182 -- ??? Emit an error if pragma Import/Export_Exception is present
9184 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
9185 Check_No_Link_Name;
9186 Check_Arg_Count (3);
9187 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
9189 Process_Import_Predefined_Type;
9191 else
9192 Error_Pragma_Arg
9193 ("second argument of pragma% must be object, subprogram "
9194 & "or incomplete type",
9195 Arg2);
9196 end if;
9198 -- If this pragma applies to a compilation unit, then the unit, which
9199 -- is a subprogram, does not require (or allow) a body. We also do
9200 -- not need to elaborate imported procedures.
9202 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9203 declare
9204 Cunit : constant Node_Id := Parent (Parent (N));
9205 begin
9206 Set_Body_Required (Cunit, False);
9207 end;
9208 end if;
9209 end Process_Import_Or_Interface;
9211 --------------------
9212 -- Process_Inline --
9213 --------------------
9215 procedure Process_Inline (Status : Inline_Status) is
9216 Applies : Boolean;
9217 Assoc : Node_Id;
9218 Decl : Node_Id;
9219 Subp : Entity_Id;
9220 Subp_Id : Node_Id;
9222 Ghost_Error_Posted : Boolean := False;
9223 -- Flag set when an error concerning the illegal mix of Ghost and
9224 -- non-Ghost subprograms is emitted.
9226 Ghost_Id : Entity_Id := Empty;
9227 -- The entity of the first Ghost subprogram encountered while
9228 -- processing the arguments of the pragma.
9230 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id);
9231 -- Verify the placement of pragma Inline_Always with respect to the
9232 -- initial declaration of subprogram Spec_Id.
9234 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
9235 -- Returns True if it can be determined at this stage that inlining
9236 -- is not possible, for example if the body is available and contains
9237 -- exception handlers, we prevent inlining, since otherwise we can
9238 -- get undefined symbols at link time. This function also emits a
9239 -- warning if the pragma appears too late.
9241 -- ??? is business with link symbols still valid, or does it relate
9242 -- to front end ZCX which is being phased out ???
9244 procedure Make_Inline (Subp : Entity_Id);
9245 -- Subp is the defining unit name of the subprogram declaration. If
9246 -- the pragma is valid, call Set_Inline_Flags on Subp, as well as on
9247 -- the corresponding body, if there is one present.
9249 procedure Set_Inline_Flags (Subp : Entity_Id);
9250 -- Set Has_Pragma_{No_Inline,Inline,Inline_Always} flag on Subp.
9251 -- Also set or clear Is_Inlined flag on Subp depending on Status.
9253 -----------------------------------
9254 -- Check_Inline_Always_Placement --
9255 -----------------------------------
9257 procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id) is
9258 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id);
9260 function Compilation_Unit_OK return Boolean;
9261 pragma Inline (Compilation_Unit_OK);
9262 -- Determine whether pragma Inline_Always applies to a compatible
9263 -- compilation unit denoted by Spec_Id.
9265 function Declarative_List_OK return Boolean;
9266 pragma Inline (Declarative_List_OK);
9267 -- Determine whether the initial declaration of subprogram Spec_Id
9268 -- and the pragma appear in compatible declarative lists.
9270 function Subprogram_Body_OK return Boolean;
9271 pragma Inline (Subprogram_Body_OK);
9272 -- Determine whether pragma Inline_Always applies to a compatible
9273 -- subprogram body denoted by Spec_Id.
9275 -------------------------
9276 -- Compilation_Unit_OK --
9277 -------------------------
9279 function Compilation_Unit_OK return Boolean is
9280 Comp_Unit : constant Node_Id := Parent (Spec_Decl);
9282 begin
9283 -- The pragma appears after the initial declaration of a
9284 -- compilation unit.
9286 -- procedure Comp_Unit;
9287 -- pragma Inline_Always (Comp_Unit);
9289 -- Note that for compatibility reasons, the following case is
9290 -- also accepted.
9292 -- procedure Stand_Alone_Body_Comp_Unit is
9293 -- ...
9294 -- end Stand_Alone_Body_Comp_Unit;
9295 -- pragma Inline_Always (Stand_Alone_Body_Comp_Unit);
9297 return
9298 Nkind (Comp_Unit) = N_Compilation_Unit
9299 and then Present (Aux_Decls_Node (Comp_Unit))
9300 and then Is_List_Member (N)
9301 and then List_Containing (N) =
9302 Pragmas_After (Aux_Decls_Node (Comp_Unit));
9303 end Compilation_Unit_OK;
9305 -------------------------
9306 -- Declarative_List_OK --
9307 -------------------------
9309 function Declarative_List_OK return Boolean is
9310 Context : constant Node_Id := Parent (Spec_Decl);
9312 Init_Decl : Node_Id;
9313 Init_List : List_Id;
9314 Prag_List : List_Id;
9316 begin
9317 -- Determine the proper initial declaration. In general this is
9318 -- the declaration node of the subprogram except when the input
9319 -- denotes a generic instantiation.
9321 -- procedure Inst is new Gen;
9322 -- pragma Inline_Always (Inst);
9324 -- In this case the original subprogram is moved inside an
9325 -- anonymous package while pragma Inline_Always remains at the
9326 -- level of the anonymous package. Use the declaration of the
9327 -- package because it reflects the placement of the original
9328 -- instantiation.
9330 -- package Anon_Pack is
9331 -- procedure Inst is ... end Inst; -- original
9332 -- end Anon_Pack;
9334 -- procedure Inst renames Anon_Pack.Inst;
9335 -- pragma Inline_Always (Inst);
9337 if Is_Generic_Instance (Spec_Id) then
9338 Init_Decl := Parent (Parent (Spec_Decl));
9339 pragma Assert (Nkind (Init_Decl) = N_Package_Declaration);
9340 else
9341 Init_Decl := Spec_Decl;
9342 end if;
9344 if Is_List_Member (Init_Decl) and then Is_List_Member (N) then
9345 Init_List := List_Containing (Init_Decl);
9346 Prag_List := List_Containing (N);
9348 -- The pragma and then initial declaration appear within the
9349 -- same declarative list.
9351 if Init_List = Prag_List then
9352 return True;
9354 -- A special case of the above is when both the pragma and
9355 -- the initial declaration appear in different lists of a
9356 -- package spec, protected definition, or a task definition.
9358 -- package Pack is
9359 -- procedure Proc;
9360 -- private
9361 -- pragma Inline_Always (Proc);
9362 -- end Pack;
9364 elsif Nkind_In (Context, N_Package_Specification,
9365 N_Protected_Definition,
9366 N_Task_Definition)
9367 and then Init_List = Visible_Declarations (Context)
9368 and then Prag_List = Private_Declarations (Context)
9369 then
9370 return True;
9371 end if;
9372 end if;
9374 return False;
9375 end Declarative_List_OK;
9377 ------------------------
9378 -- Subprogram_Body_OK --
9379 ------------------------
9381 function Subprogram_Body_OK return Boolean is
9382 Body_Decl : Node_Id;
9384 begin
9385 -- The pragma appears within the declarative list of a stand-
9386 -- alone subprogram body.
9388 -- procedure Stand_Alone_Body is
9389 -- pragma Inline_Always (Stand_Alone_Body);
9390 -- begin
9391 -- ...
9392 -- end Stand_Alone_Body;
9394 -- The compiler creates a dummy spec in this case, however the
9395 -- pragma remains within the declarative list of the body.
9397 if Nkind (Spec_Decl) = N_Subprogram_Declaration
9398 and then not Comes_From_Source (Spec_Decl)
9399 and then Present (Corresponding_Body (Spec_Decl))
9400 then
9401 Body_Decl :=
9402 Unit_Declaration_Node (Corresponding_Body (Spec_Decl));
9404 if Present (Declarations (Body_Decl))
9405 and then Is_List_Member (N)
9406 and then List_Containing (N) = Declarations (Body_Decl)
9407 then
9408 return True;
9409 end if;
9410 end if;
9412 return False;
9413 end Subprogram_Body_OK;
9415 -- Start of processing for Check_Inline_Always_Placement
9417 begin
9418 -- This check is relevant only for pragma Inline_Always
9420 if Pname /= Name_Inline_Always then
9421 return;
9423 -- Nothing to do when the pragma is internally generated on the
9424 -- assumption that it is properly placed.
9426 elsif not Comes_From_Source (N) then
9427 return;
9429 -- Nothing to do for internally generated subprograms that act
9430 -- as accidental homonyms of a source subprogram being inlined.
9432 elsif not Comes_From_Source (Spec_Id) then
9433 return;
9435 -- Nothing to do for generic formal subprograms that act as
9436 -- homonyms of another source subprogram being inlined.
9438 elsif Is_Formal_Subprogram (Spec_Id) then
9439 return;
9441 elsif Compilation_Unit_OK
9442 or else Declarative_List_OK
9443 or else Subprogram_Body_OK
9444 then
9445 return;
9446 end if;
9448 -- At this point it is known that the pragma applies to or appears
9449 -- within a completing body, a completing stub, or a subunit.
9451 Error_Msg_Name_1 := Pname;
9452 Error_Msg_Name_2 := Chars (Spec_Id);
9453 Error_Msg_Sloc := Sloc (Spec_Id);
9455 Error_Msg_N
9456 ("pragma % must appear on initial declaration of subprogram "
9457 & "% defined #", N);
9458 end Check_Inline_Always_Placement;
9460 ---------------------------
9461 -- Inlining_Not_Possible --
9462 ---------------------------
9464 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
9465 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
9466 Stats : Node_Id;
9468 begin
9469 if Nkind (Decl) = N_Subprogram_Body then
9470 Stats := Handled_Statement_Sequence (Decl);
9471 return Present (Exception_Handlers (Stats))
9472 or else Present (At_End_Proc (Stats));
9474 elsif Nkind (Decl) = N_Subprogram_Declaration
9475 and then Present (Corresponding_Body (Decl))
9476 then
9477 if Analyzed (Corresponding_Body (Decl)) then
9478 Error_Msg_N ("pragma appears too late, ignored??", N);
9479 return True;
9481 -- If the subprogram is a renaming as body, the body is just a
9482 -- call to the renamed subprogram, and inlining is trivially
9483 -- possible.
9485 elsif
9486 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
9487 N_Subprogram_Renaming_Declaration
9488 then
9489 return False;
9491 else
9492 Stats :=
9493 Handled_Statement_Sequence
9494 (Unit_Declaration_Node (Corresponding_Body (Decl)));
9496 return
9497 Present (Exception_Handlers (Stats))
9498 or else Present (At_End_Proc (Stats));
9499 end if;
9501 else
9502 -- If body is not available, assume the best, the check is
9503 -- performed again when compiling enclosing package bodies.
9505 return False;
9506 end if;
9507 end Inlining_Not_Possible;
9509 -----------------
9510 -- Make_Inline --
9511 -----------------
9513 procedure Make_Inline (Subp : Entity_Id) is
9514 Kind : constant Entity_Kind := Ekind (Subp);
9515 Inner_Subp : Entity_Id := Subp;
9517 begin
9518 -- Ignore if bad type, avoid cascaded error
9520 if Etype (Subp) = Any_Type then
9521 Applies := True;
9522 return;
9524 -- If inlining is not possible, for now do not treat as an error
9526 elsif Status /= Suppressed
9527 and then Front_End_Inlining
9528 and then Inlining_Not_Possible (Subp)
9529 then
9530 Applies := True;
9531 return;
9533 -- Here we have a candidate for inlining, but we must exclude
9534 -- derived operations. Otherwise we would end up trying to inline
9535 -- a phantom declaration, and the result would be to drag in a
9536 -- body which has no direct inlining associated with it. That
9537 -- would not only be inefficient but would also result in the
9538 -- backend doing cross-unit inlining in cases where it was
9539 -- definitely inappropriate to do so.
9541 -- However, a simple Comes_From_Source test is insufficient, since
9542 -- we do want to allow inlining of generic instances which also do
9543 -- not come from source. We also need to recognize specs generated
9544 -- by the front-end for bodies that carry the pragma. Finally,
9545 -- predefined operators do not come from source but are not
9546 -- inlineable either.
9548 elsif Is_Generic_Instance (Subp)
9549 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
9550 then
9551 null;
9553 elsif not Comes_From_Source (Subp)
9554 and then Scope (Subp) /= Standard_Standard
9555 then
9556 Applies := True;
9557 return;
9558 end if;
9560 -- The referenced entity must either be the enclosing entity, or
9561 -- an entity declared within the current open scope.
9563 if Present (Scope (Subp))
9564 and then Scope (Subp) /= Current_Scope
9565 and then Subp /= Current_Scope
9566 then
9567 Error_Pragma_Arg
9568 ("argument of% must be entity in current scope", Assoc);
9569 return;
9570 end if;
9572 -- Processing for procedure, operator or function. If subprogram
9573 -- is aliased (as for an instance) indicate that the renamed
9574 -- entity (if declared in the same unit) is inlined.
9575 -- If this is the anonymous subprogram created for a subprogram
9576 -- instance, the inlining applies to it directly. Otherwise we
9577 -- retrieve it as the alias of the visible subprogram instance.
9579 if Is_Subprogram (Subp) then
9581 -- Ensure that pragma Inline_Always is associated with the
9582 -- initial declaration of the subprogram.
9584 Check_Inline_Always_Placement (Subp);
9586 if Is_Wrapper_Package (Scope (Subp)) then
9587 Inner_Subp := Subp;
9588 else
9589 Inner_Subp := Ultimate_Alias (Inner_Subp);
9590 end if;
9592 if In_Same_Source_Unit (Subp, Inner_Subp) then
9593 Set_Inline_Flags (Inner_Subp);
9595 Decl := Parent (Parent (Inner_Subp));
9597 if Nkind (Decl) = N_Subprogram_Declaration
9598 and then Present (Corresponding_Body (Decl))
9599 then
9600 Set_Inline_Flags (Corresponding_Body (Decl));
9602 elsif Is_Generic_Instance (Subp)
9603 and then Comes_From_Source (Subp)
9604 then
9605 -- Indicate that the body needs to be created for
9606 -- inlining subsequent calls. The instantiation node
9607 -- follows the declaration of the wrapper package
9608 -- created for it. The subprogram that requires the
9609 -- body is the anonymous one in the wrapper package.
9611 if Scope (Subp) /= Standard_Standard
9612 and then
9613 Need_Subprogram_Instance_Body
9614 (Next (Unit_Declaration_Node
9615 (Scope (Alias (Subp)))), Subp)
9616 then
9617 null;
9618 end if;
9620 -- Inline is a program unit pragma (RM 10.1.5) and cannot
9621 -- appear in a formal part to apply to a formal subprogram.
9622 -- Do not apply check within an instance or a formal package
9623 -- the test will have been applied to the original generic.
9625 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
9626 and then List_Containing (Decl) = List_Containing (N)
9627 and then not In_Instance
9628 then
9629 Error_Msg_N
9630 ("Inline cannot apply to a formal subprogram", N);
9632 -- If Subp is a renaming, it is the renamed entity that
9633 -- will appear in any call, and be inlined. However, for
9634 -- ASIS uses it is convenient to indicate that the renaming
9635 -- itself is an inlined subprogram, so that some gnatcheck
9636 -- rules can be applied in the absence of expansion.
9638 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
9639 Set_Inline_Flags (Subp);
9640 end if;
9641 end if;
9643 Applies := True;
9645 -- For a generic subprogram set flag as well, for use at the point
9646 -- of instantiation, to determine whether the body should be
9647 -- generated.
9649 elsif Is_Generic_Subprogram (Subp) then
9650 Set_Inline_Flags (Subp);
9651 Applies := True;
9653 -- Literals are by definition inlined
9655 elsif Kind = E_Enumeration_Literal then
9656 null;
9658 -- Anything else is an error
9660 else
9661 Error_Pragma_Arg
9662 ("expect subprogram name for pragma%", Assoc);
9663 end if;
9664 end Make_Inline;
9666 ----------------------
9667 -- Set_Inline_Flags --
9668 ----------------------
9670 procedure Set_Inline_Flags (Subp : Entity_Id) is
9671 begin
9672 -- First set the Has_Pragma_XXX flags and issue the appropriate
9673 -- errors and warnings for suspicious combinations.
9675 if Prag_Id = Pragma_No_Inline then
9676 if Has_Pragma_Inline_Always (Subp) then
9677 Error_Msg_N
9678 ("Inline_Always and No_Inline are mutually exclusive", N);
9679 elsif Has_Pragma_Inline (Subp) then
9680 Error_Msg_NE
9681 ("Inline and No_Inline both specified for& ??",
9682 N, Entity (Subp_Id));
9683 end if;
9685 Set_Has_Pragma_No_Inline (Subp);
9686 else
9687 if Prag_Id = Pragma_Inline_Always then
9688 if Has_Pragma_No_Inline (Subp) then
9689 Error_Msg_N
9690 ("Inline_Always and No_Inline are mutually exclusive",
9692 end if;
9694 Set_Has_Pragma_Inline_Always (Subp);
9695 else
9696 if Has_Pragma_No_Inline (Subp) then
9697 Error_Msg_NE
9698 ("Inline and No_Inline both specified for& ??",
9699 N, Entity (Subp_Id));
9700 end if;
9701 end if;
9703 Set_Has_Pragma_Inline (Subp);
9704 end if;
9706 -- Then adjust the Is_Inlined flag. It can never be set if the
9707 -- subprogram is subject to pragma No_Inline.
9709 case Status is
9710 when Suppressed =>
9711 Set_Is_Inlined (Subp, False);
9713 when Disabled =>
9714 null;
9716 when Enabled =>
9717 if not Has_Pragma_No_Inline (Subp) then
9718 Set_Is_Inlined (Subp, True);
9719 end if;
9720 end case;
9722 -- A pragma that applies to a Ghost entity becomes Ghost for the
9723 -- purposes of legality checks and removal of ignored Ghost code.
9725 Mark_Ghost_Pragma (N, Subp);
9727 -- Capture the entity of the first Ghost subprogram being
9728 -- processed for error detection purposes.
9730 if Is_Ghost_Entity (Subp) then
9731 if No (Ghost_Id) then
9732 Ghost_Id := Subp;
9733 end if;
9735 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
9736 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
9738 elsif Present (Ghost_Id) and then not Ghost_Error_Posted then
9739 Ghost_Error_Posted := True;
9741 Error_Msg_Name_1 := Pname;
9742 Error_Msg_N
9743 ("pragma % cannot mention ghost and non-ghost subprograms",
9746 Error_Msg_Sloc := Sloc (Ghost_Id);
9747 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
9749 Error_Msg_Sloc := Sloc (Subp);
9750 Error_Msg_NE ("\& # declared as non-ghost", N, Subp);
9751 end if;
9752 end Set_Inline_Flags;
9754 -- Start of processing for Process_Inline
9756 begin
9757 Check_No_Identifiers;
9758 Check_At_Least_N_Arguments (1);
9760 if Status = Enabled then
9761 Inline_Processing_Required := True;
9762 end if;
9764 Assoc := Arg1;
9765 while Present (Assoc) loop
9766 Subp_Id := Get_Pragma_Arg (Assoc);
9767 Analyze (Subp_Id);
9768 Applies := False;
9770 if Is_Entity_Name (Subp_Id) then
9771 Subp := Entity (Subp_Id);
9773 if Subp = Any_Id then
9775 -- If previous error, avoid cascaded errors
9777 Check_Error_Detected;
9778 Applies := True;
9780 else
9781 Make_Inline (Subp);
9783 -- For the pragma case, climb homonym chain. This is
9784 -- what implements allowing the pragma in the renaming
9785 -- case, with the result applying to the ancestors, and
9786 -- also allows Inline to apply to all previous homonyms.
9788 if not From_Aspect_Specification (N) then
9789 while Present (Homonym (Subp))
9790 and then Scope (Homonym (Subp)) = Current_Scope
9791 loop
9792 Make_Inline (Homonym (Subp));
9793 Subp := Homonym (Subp);
9794 end loop;
9795 end if;
9796 end if;
9797 end if;
9799 if not Applies then
9800 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
9801 end if;
9803 Next (Assoc);
9804 end loop;
9806 -- If the context is a package declaration, the pragma indicates
9807 -- that inlining will require the presence of the corresponding
9808 -- body. (this may be further refined).
9810 if not In_Instance
9811 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
9812 N_Package_Declaration
9813 then
9814 Set_Body_Needed_For_Inlining (Cunit_Entity (Current_Sem_Unit));
9815 end if;
9816 end Process_Inline;
9818 ----------------------------
9819 -- Process_Interface_Name --
9820 ----------------------------
9822 procedure Process_Interface_Name
9823 (Subprogram_Def : Entity_Id;
9824 Ext_Arg : Node_Id;
9825 Link_Arg : Node_Id;
9826 Prag : Node_Id)
9828 Ext_Nam : Node_Id;
9829 Link_Nam : Node_Id;
9830 String_Val : String_Id;
9832 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
9833 -- SN is a string literal node for an interface name. This routine
9834 -- performs some minimal checks that the name is reasonable. In
9835 -- particular that no spaces or other obviously incorrect characters
9836 -- appear. This is only a warning, since any characters are allowed.
9838 ----------------------------------
9839 -- Check_Form_Of_Interface_Name --
9840 ----------------------------------
9842 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
9843 S : constant String_Id := Strval (Expr_Value_S (SN));
9844 SL : constant Nat := String_Length (S);
9845 C : Char_Code;
9847 begin
9848 if SL = 0 then
9849 Error_Msg_N ("interface name cannot be null string", SN);
9850 end if;
9852 for J in 1 .. SL loop
9853 C := Get_String_Char (S, J);
9855 -- Look for dubious character and issue unconditional warning.
9856 -- Definitely dubious if not in character range.
9858 if not In_Character_Range (C)
9860 -- Commas, spaces and (back)slashes are dubious
9862 or else Get_Character (C) = ','
9863 or else Get_Character (C) = '\'
9864 or else Get_Character (C) = ' '
9865 or else Get_Character (C) = '/'
9866 then
9867 Error_Msg
9868 ("??interface name contains illegal character",
9869 Sloc (SN) + Source_Ptr (J));
9870 end if;
9871 end loop;
9872 end Check_Form_Of_Interface_Name;
9874 -- Start of processing for Process_Interface_Name
9876 begin
9877 -- If we are looking at a pragma that comes from an aspect then it
9878 -- needs to have its corresponding aspect argument expressions
9879 -- analyzed in addition to the generated pragma so that aspects
9880 -- within generic units get properly resolved.
9882 if Present (Prag) and then From_Aspect_Specification (Prag) then
9883 declare
9884 Asp : constant Node_Id := Corresponding_Aspect (Prag);
9885 Dummy_1 : Node_Id;
9886 Dummy_2 : Node_Id;
9887 Dummy_3 : Node_Id;
9888 EN : Node_Id;
9889 LN : Node_Id;
9891 begin
9892 -- Obtain all interfacing aspects used to construct the pragma
9894 Get_Interfacing_Aspects
9895 (Asp, Dummy_1, EN, Dummy_2, Dummy_3, LN);
9897 -- Analyze the expression of aspect External_Name
9899 if Present (EN) then
9900 Analyze (Expression (EN));
9901 end if;
9903 -- Analyze the expressio of aspect Link_Name
9905 if Present (LN) then
9906 Analyze (Expression (LN));
9907 end if;
9908 end;
9909 end if;
9911 if No (Link_Arg) then
9912 if No (Ext_Arg) then
9913 return;
9915 elsif Chars (Ext_Arg) = Name_Link_Name then
9916 Ext_Nam := Empty;
9917 Link_Nam := Expression (Ext_Arg);
9919 else
9920 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
9921 Ext_Nam := Expression (Ext_Arg);
9922 Link_Nam := Empty;
9923 end if;
9925 else
9926 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
9927 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
9928 Ext_Nam := Expression (Ext_Arg);
9929 Link_Nam := Expression (Link_Arg);
9930 end if;
9932 -- Check expressions for external name and link name are static
9934 if Present (Ext_Nam) then
9935 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
9936 Check_Form_Of_Interface_Name (Ext_Nam);
9938 -- Verify that external name is not the name of a local entity,
9939 -- which would hide the imported one and could lead to run-time
9940 -- surprises. The problem can only arise for entities declared in
9941 -- a package body (otherwise the external name is fully qualified
9942 -- and will not conflict).
9944 declare
9945 Nam : Name_Id;
9946 E : Entity_Id;
9947 Par : Node_Id;
9949 begin
9950 if Prag_Id = Pragma_Import then
9951 Nam := String_To_Name (Strval (Expr_Value_S (Ext_Nam)));
9952 E := Entity_Id (Get_Name_Table_Int (Nam));
9954 if Nam /= Chars (Subprogram_Def)
9955 and then Present (E)
9956 and then not Is_Overloadable (E)
9957 and then Is_Immediately_Visible (E)
9958 and then not Is_Imported (E)
9959 and then Ekind (Scope (E)) = E_Package
9960 then
9961 Par := Parent (E);
9962 while Present (Par) loop
9963 if Nkind (Par) = N_Package_Body then
9964 Error_Msg_Sloc := Sloc (E);
9965 Error_Msg_NE
9966 ("imported entity is hidden by & declared#",
9967 Ext_Arg, E);
9968 exit;
9969 end if;
9971 Par := Parent (Par);
9972 end loop;
9973 end if;
9974 end if;
9975 end;
9976 end if;
9978 if Present (Link_Nam) then
9979 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
9980 Check_Form_Of_Interface_Name (Link_Nam);
9981 end if;
9983 -- If there is no link name, just set the external name
9985 if No (Link_Nam) then
9986 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
9988 -- For the Link_Name case, the given literal is preceded by an
9989 -- asterisk, which indicates to GCC that the given name should be
9990 -- taken literally, and in particular that no prepending of
9991 -- underlines should occur, even in systems where this is the
9992 -- normal default.
9994 else
9995 Start_String;
9996 Store_String_Char (Get_Char_Code ('*'));
9997 String_Val := Strval (Expr_Value_S (Link_Nam));
9998 Store_String_Chars (String_Val);
9999 Link_Nam :=
10000 Make_String_Literal (Sloc (Link_Nam),
10001 Strval => End_String);
10002 end if;
10004 -- Set the interface name. If the entity is a generic instance, use
10005 -- its alias, which is the callable entity.
10007 if Is_Generic_Instance (Subprogram_Def) then
10008 Set_Encoded_Interface_Name
10009 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
10010 else
10011 Set_Encoded_Interface_Name
10012 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
10013 end if;
10015 Check_Duplicated_Export_Name (Link_Nam);
10016 end Process_Interface_Name;
10018 -----------------------------------------
10019 -- Process_Interrupt_Or_Attach_Handler --
10020 -----------------------------------------
10022 procedure Process_Interrupt_Or_Attach_Handler is
10023 Handler : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
10024 Prot_Typ : constant Entity_Id := Scope (Handler);
10026 begin
10027 -- A pragma that applies to a Ghost entity becomes Ghost for the
10028 -- purposes of legality checks and removal of ignored Ghost code.
10030 Mark_Ghost_Pragma (N, Handler);
10031 Set_Is_Interrupt_Handler (Handler);
10033 pragma Assert (Ekind (Prot_Typ) = E_Protected_Type);
10035 Record_Rep_Item (Prot_Typ, N);
10037 -- Chain the pragma on the contract for completeness
10039 Add_Contract_Item (N, Handler);
10040 end Process_Interrupt_Or_Attach_Handler;
10042 --------------------------------------------------
10043 -- Process_Restrictions_Or_Restriction_Warnings --
10044 --------------------------------------------------
10046 -- Note: some of the simple identifier cases were handled in par-prag,
10047 -- but it is harmless (and more straightforward) to simply handle all
10048 -- cases here, even if it means we repeat a bit of work in some cases.
10050 procedure Process_Restrictions_Or_Restriction_Warnings
10051 (Warn : Boolean)
10053 Arg : Node_Id;
10054 R_Id : Restriction_Id;
10055 Id : Name_Id;
10056 Expr : Node_Id;
10057 Val : Uint;
10059 begin
10060 -- Ignore all Restrictions pragmas in CodePeer mode
10062 if CodePeer_Mode then
10063 return;
10064 end if;
10066 Check_Ada_83_Warning;
10067 Check_At_Least_N_Arguments (1);
10068 Check_Valid_Configuration_Pragma;
10070 Arg := Arg1;
10071 while Present (Arg) loop
10072 Id := Chars (Arg);
10073 Expr := Get_Pragma_Arg (Arg);
10075 -- Case of no restriction identifier present
10077 if Id = No_Name then
10078 if Nkind (Expr) /= N_Identifier then
10079 Error_Pragma_Arg
10080 ("invalid form for restriction", Arg);
10081 end if;
10083 R_Id :=
10084 Get_Restriction_Id
10085 (Process_Restriction_Synonyms (Expr));
10087 if R_Id not in All_Boolean_Restrictions then
10088 Error_Msg_Name_1 := Pname;
10089 Error_Msg_N
10090 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
10092 -- Check for possible misspelling
10094 for J in Restriction_Id loop
10095 declare
10096 Rnm : constant String := Restriction_Id'Image (J);
10098 begin
10099 Name_Buffer (1 .. Rnm'Length) := Rnm;
10100 Name_Len := Rnm'Length;
10101 Set_Casing (All_Lower_Case);
10103 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
10104 Set_Casing
10105 (Identifier_Casing
10106 (Source_Index (Current_Sem_Unit)));
10107 Error_Msg_String (1 .. Rnm'Length) :=
10108 Name_Buffer (1 .. Name_Len);
10109 Error_Msg_Strlen := Rnm'Length;
10110 Error_Msg_N -- CODEFIX
10111 ("\possible misspelling of ""~""",
10112 Get_Pragma_Arg (Arg));
10113 exit;
10114 end if;
10115 end;
10116 end loop;
10118 raise Pragma_Exit;
10119 end if;
10121 if Implementation_Restriction (R_Id) then
10122 Check_Restriction (No_Implementation_Restrictions, Arg);
10123 end if;
10125 -- Special processing for No_Elaboration_Code restriction
10127 if R_Id = No_Elaboration_Code then
10129 -- Restriction is only recognized within a configuration
10130 -- pragma file, or within a unit of the main extended
10131 -- program. Note: the test for Main_Unit is needed to
10132 -- properly include the case of configuration pragma files.
10134 if not (Current_Sem_Unit = Main_Unit
10135 or else In_Extended_Main_Source_Unit (N))
10136 then
10137 return;
10139 -- Don't allow in a subunit unless already specified in
10140 -- body or spec.
10142 elsif Nkind (Parent (N)) = N_Compilation_Unit
10143 and then Nkind (Unit (Parent (N))) = N_Subunit
10144 and then not Restriction_Active (No_Elaboration_Code)
10145 then
10146 Error_Msg_N
10147 ("invalid specification of ""No_Elaboration_Code""",
10149 Error_Msg_N
10150 ("\restriction cannot be specified in a subunit", N);
10151 Error_Msg_N
10152 ("\unless also specified in body or spec", N);
10153 return;
10155 -- If we accept a No_Elaboration_Code restriction, then it
10156 -- needs to be added to the configuration restriction set so
10157 -- that we get proper application to other units in the main
10158 -- extended source as required.
10160 else
10161 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
10162 end if;
10163 end if;
10165 -- If this is a warning, then set the warning unless we already
10166 -- have a real restriction active (we never want a warning to
10167 -- override a real restriction).
10169 if Warn then
10170 if not Restriction_Active (R_Id) then
10171 Set_Restriction (R_Id, N);
10172 Restriction_Warnings (R_Id) := True;
10173 end if;
10175 -- If real restriction case, then set it and make sure that the
10176 -- restriction warning flag is off, since a real restriction
10177 -- always overrides a warning.
10179 else
10180 Set_Restriction (R_Id, N);
10181 Restriction_Warnings (R_Id) := False;
10182 end if;
10184 -- Check for obsolescent restrictions in Ada 2005 mode
10186 if not Warn
10187 and then Ada_Version >= Ada_2005
10188 and then (R_Id = No_Asynchronous_Control
10189 or else
10190 R_Id = No_Unchecked_Deallocation
10191 or else
10192 R_Id = No_Unchecked_Conversion)
10193 then
10194 Check_Restriction (No_Obsolescent_Features, N);
10195 end if;
10197 -- A very special case that must be processed here: pragma
10198 -- Restrictions (No_Exceptions) turns off all run-time
10199 -- checking. This is a bit dubious in terms of the formal
10200 -- language definition, but it is what is intended by RM
10201 -- H.4(12). Restriction_Warnings never affects generated code
10202 -- so this is done only in the real restriction case.
10204 -- Atomic_Synchronization is not a real check, so it is not
10205 -- affected by this processing).
10207 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
10208 -- run-time checks in CodePeer and GNATprove modes: we want to
10209 -- generate checks for analysis purposes, as set respectively
10210 -- by -gnatC and -gnatd.F
10212 if not Warn
10213 and then not (CodePeer_Mode or GNATprove_Mode)
10214 and then R_Id = No_Exceptions
10215 then
10216 for J in Scope_Suppress.Suppress'Range loop
10217 if J /= Atomic_Synchronization then
10218 Scope_Suppress.Suppress (J) := True;
10219 end if;
10220 end loop;
10221 end if;
10223 -- Case of No_Dependence => unit-name. Note that the parser
10224 -- already made the necessary entry in the No_Dependence table.
10226 elsif Id = Name_No_Dependence then
10227 if not OK_No_Dependence_Unit_Name (Expr) then
10228 raise Pragma_Exit;
10229 end if;
10231 -- Case of No_Specification_Of_Aspect => aspect-identifier
10233 elsif Id = Name_No_Specification_Of_Aspect then
10234 declare
10235 A_Id : Aspect_Id;
10237 begin
10238 if Nkind (Expr) /= N_Identifier then
10239 A_Id := No_Aspect;
10240 else
10241 A_Id := Get_Aspect_Id (Chars (Expr));
10242 end if;
10244 if A_Id = No_Aspect then
10245 Error_Pragma_Arg ("invalid restriction name", Arg);
10246 else
10247 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
10248 end if;
10249 end;
10251 -- Case of No_Use_Of_Attribute => attribute-identifier
10253 elsif Id = Name_No_Use_Of_Attribute then
10254 if Nkind (Expr) /= N_Identifier
10255 or else not Is_Attribute_Name (Chars (Expr))
10256 then
10257 Error_Msg_N ("unknown attribute name??", Expr);
10259 else
10260 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
10261 end if;
10263 -- Case of No_Use_Of_Entity => fully-qualified-name
10265 elsif Id = Name_No_Use_Of_Entity then
10267 -- Restriction is only recognized within a configuration
10268 -- pragma file, or within a unit of the main extended
10269 -- program. Note: the test for Main_Unit is needed to
10270 -- properly include the case of configuration pragma files.
10272 if Current_Sem_Unit = Main_Unit
10273 or else In_Extended_Main_Source_Unit (N)
10274 then
10275 if not OK_No_Dependence_Unit_Name (Expr) then
10276 Error_Msg_N ("wrong form for entity name", Expr);
10277 else
10278 Set_Restriction_No_Use_Of_Entity
10279 (Expr, Warn, No_Profile);
10280 end if;
10281 end if;
10283 -- Case of No_Use_Of_Pragma => pragma-identifier
10285 elsif Id = Name_No_Use_Of_Pragma then
10286 if Nkind (Expr) /= N_Identifier
10287 or else not Is_Pragma_Name (Chars (Expr))
10288 then
10289 Error_Msg_N ("unknown pragma name??", Expr);
10290 else
10291 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
10292 end if;
10294 -- All other cases of restriction identifier present
10296 else
10297 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
10298 Analyze_And_Resolve (Expr, Any_Integer);
10300 if R_Id not in All_Parameter_Restrictions then
10301 Error_Pragma_Arg
10302 ("invalid restriction parameter identifier", Arg);
10304 elsif not Is_OK_Static_Expression (Expr) then
10305 Flag_Non_Static_Expr
10306 ("value must be static expression!", Expr);
10307 raise Pragma_Exit;
10309 elsif not Is_Integer_Type (Etype (Expr))
10310 or else Expr_Value (Expr) < 0
10311 then
10312 Error_Pragma_Arg
10313 ("value must be non-negative integer", Arg);
10314 end if;
10316 -- Restriction pragma is active
10318 Val := Expr_Value (Expr);
10320 if not UI_Is_In_Int_Range (Val) then
10321 Error_Pragma_Arg
10322 ("pragma ignored, value too large??", Arg);
10323 end if;
10325 -- Warning case. If the real restriction is active, then we
10326 -- ignore the request, since warning never overrides a real
10327 -- restriction. Otherwise we set the proper warning. Note that
10328 -- this circuit sets the warning again if it is already set,
10329 -- which is what we want, since the constant may have changed.
10331 if Warn then
10332 if not Restriction_Active (R_Id) then
10333 Set_Restriction
10334 (R_Id, N, Integer (UI_To_Int (Val)));
10335 Restriction_Warnings (R_Id) := True;
10336 end if;
10338 -- Real restriction case, set restriction and make sure warning
10339 -- flag is off since real restriction always overrides warning.
10341 else
10342 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
10343 Restriction_Warnings (R_Id) := False;
10344 end if;
10345 end if;
10347 Next (Arg);
10348 end loop;
10349 end Process_Restrictions_Or_Restriction_Warnings;
10351 ---------------------------------
10352 -- Process_Suppress_Unsuppress --
10353 ---------------------------------
10355 -- Note: this procedure makes entries in the check suppress data
10356 -- structures managed by Sem. See spec of package Sem for full
10357 -- details on how we handle recording of check suppression.
10359 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
10360 C : Check_Id;
10361 E : Entity_Id;
10362 E_Id : Node_Id;
10364 In_Package_Spec : constant Boolean :=
10365 Is_Package_Or_Generic_Package (Current_Scope)
10366 and then not In_Package_Body (Current_Scope);
10368 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
10369 -- Used to suppress a single check on the given entity
10371 --------------------------------
10372 -- Suppress_Unsuppress_Echeck --
10373 --------------------------------
10375 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
10376 begin
10377 -- Check for error of trying to set atomic synchronization for
10378 -- a non-atomic variable.
10380 if C = Atomic_Synchronization
10381 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
10382 then
10383 Error_Msg_N
10384 ("pragma & requires atomic type or variable",
10385 Pragma_Identifier (Original_Node (N)));
10386 end if;
10388 Set_Checks_May_Be_Suppressed (E);
10390 if In_Package_Spec then
10391 Push_Global_Suppress_Stack_Entry
10392 (Entity => E,
10393 Check => C,
10394 Suppress => Suppress_Case);
10395 else
10396 Push_Local_Suppress_Stack_Entry
10397 (Entity => E,
10398 Check => C,
10399 Suppress => Suppress_Case);
10400 end if;
10402 -- If this is a first subtype, and the base type is distinct,
10403 -- then also set the suppress flags on the base type.
10405 if Is_First_Subtype (E) and then Etype (E) /= E then
10406 Suppress_Unsuppress_Echeck (Etype (E), C);
10407 end if;
10408 end Suppress_Unsuppress_Echeck;
10410 -- Start of processing for Process_Suppress_Unsuppress
10412 begin
10413 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
10414 -- on user code: we want to generate checks for analysis purposes, as
10415 -- set respectively by -gnatC and -gnatd.F
10417 if Comes_From_Source (N)
10418 and then (CodePeer_Mode or GNATprove_Mode)
10419 then
10420 return;
10421 end if;
10423 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
10424 -- declarative part or a package spec (RM 11.5(5)).
10426 if not Is_Configuration_Pragma then
10427 Check_Is_In_Decl_Part_Or_Package_Spec;
10428 end if;
10430 Check_At_Least_N_Arguments (1);
10431 Check_At_Most_N_Arguments (2);
10432 Check_No_Identifier (Arg1);
10433 Check_Arg_Is_Identifier (Arg1);
10435 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
10437 if C = No_Check_Id then
10438 Error_Pragma_Arg
10439 ("argument of pragma% is not valid check name", Arg1);
10440 end if;
10442 -- Warn that suppress of Elaboration_Check has no effect in SPARK
10444 if C = Elaboration_Check and then SPARK_Mode = On then
10445 Error_Pragma_Arg
10446 ("Suppress of Elaboration_Check ignored in SPARK??",
10447 "\elaboration checking rules are statically enforced "
10448 & "(SPARK RM 7.7)", Arg1);
10449 end if;
10451 -- One-argument case
10453 if Arg_Count = 1 then
10455 -- Make an entry in the local scope suppress table. This is the
10456 -- table that directly shows the current value of the scope
10457 -- suppress check for any check id value.
10459 if C = All_Checks then
10461 -- For All_Checks, we set all specific predefined checks with
10462 -- the exception of Elaboration_Check, which is handled
10463 -- specially because of not wanting All_Checks to have the
10464 -- effect of deactivating static elaboration order processing.
10465 -- Atomic_Synchronization is also not affected, since this is
10466 -- not a real check.
10468 for J in Scope_Suppress.Suppress'Range loop
10469 if J /= Elaboration_Check
10470 and then
10471 J /= Atomic_Synchronization
10472 then
10473 Scope_Suppress.Suppress (J) := Suppress_Case;
10474 end if;
10475 end loop;
10477 -- If not All_Checks, and predefined check, then set appropriate
10478 -- scope entry. Note that we will set Elaboration_Check if this
10479 -- is explicitly specified. Atomic_Synchronization is allowed
10480 -- only if internally generated and entity is atomic.
10482 elsif C in Predefined_Check_Id
10483 and then (not Comes_From_Source (N)
10484 or else C /= Atomic_Synchronization)
10485 then
10486 Scope_Suppress.Suppress (C) := Suppress_Case;
10487 end if;
10489 -- Also make an entry in the Local_Entity_Suppress table
10491 Push_Local_Suppress_Stack_Entry
10492 (Entity => Empty,
10493 Check => C,
10494 Suppress => Suppress_Case);
10496 -- Case of two arguments present, where the check is suppressed for
10497 -- a specified entity (given as the second argument of the pragma)
10499 else
10500 -- This is obsolescent in Ada 2005 mode
10502 if Ada_Version >= Ada_2005 then
10503 Check_Restriction (No_Obsolescent_Features, Arg2);
10504 end if;
10506 Check_Optional_Identifier (Arg2, Name_On);
10507 E_Id := Get_Pragma_Arg (Arg2);
10508 Analyze (E_Id);
10510 if not Is_Entity_Name (E_Id) then
10511 Error_Pragma_Arg
10512 ("second argument of pragma% must be entity name", Arg2);
10513 end if;
10515 E := Entity (E_Id);
10517 if E = Any_Id then
10518 return;
10519 end if;
10521 -- A pragma that applies to a Ghost entity becomes Ghost for the
10522 -- purposes of legality checks and removal of ignored Ghost code.
10524 Mark_Ghost_Pragma (N, E);
10526 -- Enforce RM 11.5(7) which requires that for a pragma that
10527 -- appears within a package spec, the named entity must be
10528 -- within the package spec. We allow the package name itself
10529 -- to be mentioned since that makes sense, although it is not
10530 -- strictly allowed by 11.5(7).
10532 if In_Package_Spec
10533 and then E /= Current_Scope
10534 and then Scope (E) /= Current_Scope
10535 then
10536 Error_Pragma_Arg
10537 ("entity in pragma% is not in package spec (RM 11.5(7))",
10538 Arg2);
10539 end if;
10541 -- Loop through homonyms. As noted below, in the case of a package
10542 -- spec, only homonyms within the package spec are considered.
10544 loop
10545 Suppress_Unsuppress_Echeck (E, C);
10547 if Is_Generic_Instance (E)
10548 and then Is_Subprogram (E)
10549 and then Present (Alias (E))
10550 then
10551 Suppress_Unsuppress_Echeck (Alias (E), C);
10552 end if;
10554 -- Move to next homonym if not aspect spec case
10556 exit when From_Aspect_Specification (N);
10557 E := Homonym (E);
10558 exit when No (E);
10560 -- If we are within a package specification, the pragma only
10561 -- applies to homonyms in the same scope.
10563 exit when In_Package_Spec
10564 and then Scope (E) /= Current_Scope;
10565 end loop;
10566 end if;
10567 end Process_Suppress_Unsuppress;
10569 -------------------------------
10570 -- Record_Independence_Check --
10571 -------------------------------
10573 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is
10574 pragma Unreferenced (N, E);
10575 begin
10576 -- For GCC back ends the validation is done a priori
10577 -- ??? This code is dead, might be useful in the future
10579 -- if not AAMP_On_Target then
10580 -- return;
10581 -- end if;
10583 -- Independence_Checks.Append ((N, E));
10585 return;
10586 end Record_Independence_Check;
10588 ------------------
10589 -- Set_Exported --
10590 ------------------
10592 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
10593 begin
10594 if Is_Imported (E) then
10595 Error_Pragma_Arg
10596 ("cannot export entity& that was previously imported", Arg);
10598 elsif Present (Address_Clause (E))
10599 and then not Relaxed_RM_Semantics
10600 then
10601 Error_Pragma_Arg
10602 ("cannot export entity& that has an address clause", Arg);
10603 end if;
10605 Set_Is_Exported (E);
10607 -- Generate a reference for entity explicitly, because the
10608 -- identifier may be overloaded and name resolution will not
10609 -- generate one.
10611 Generate_Reference (E, Arg);
10613 -- Deal with exporting non-library level entity
10615 if not Is_Library_Level_Entity (E) then
10617 -- Not allowed at all for subprograms
10619 if Is_Subprogram (E) then
10620 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
10622 -- Otherwise set public and statically allocated
10624 else
10625 Set_Is_Public (E);
10626 Set_Is_Statically_Allocated (E);
10628 -- Warn if the corresponding W flag is set
10630 if Warn_On_Export_Import
10632 -- Only do this for something that was in the source. Not
10633 -- clear if this can be False now (there used for sure to be
10634 -- cases on some systems where it was False), but anyway the
10635 -- test is harmless if not needed, so it is retained.
10637 and then Comes_From_Source (Arg)
10638 then
10639 Error_Msg_NE
10640 ("?x?& has been made static as a result of Export",
10641 Arg, E);
10642 Error_Msg_N
10643 ("\?x?this usage is non-standard and non-portable",
10644 Arg);
10645 end if;
10646 end if;
10647 end if;
10649 if Warn_On_Export_Import and then Is_Type (E) then
10650 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
10651 end if;
10653 if Warn_On_Export_Import and Inside_A_Generic then
10654 Error_Msg_NE
10655 ("all instances of& will have the same external name?x?",
10656 Arg, E);
10657 end if;
10658 end Set_Exported;
10660 ----------------------------------------------
10661 -- Set_Extended_Import_Export_External_Name --
10662 ----------------------------------------------
10664 procedure Set_Extended_Import_Export_External_Name
10665 (Internal_Ent : Entity_Id;
10666 Arg_External : Node_Id)
10668 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
10669 New_Name : Node_Id;
10671 begin
10672 if No (Arg_External) then
10673 return;
10674 end if;
10676 Check_Arg_Is_External_Name (Arg_External);
10678 if Nkind (Arg_External) = N_String_Literal then
10679 if String_Length (Strval (Arg_External)) = 0 then
10680 return;
10681 else
10682 New_Name := Adjust_External_Name_Case (Arg_External);
10683 end if;
10685 elsif Nkind (Arg_External) = N_Identifier then
10686 New_Name := Get_Default_External_Name (Arg_External);
10688 -- Check_Arg_Is_External_Name should let through only identifiers and
10689 -- string literals or static string expressions (which are folded to
10690 -- string literals).
10692 else
10693 raise Program_Error;
10694 end if;
10696 -- If we already have an external name set (by a prior normal Import
10697 -- or Export pragma), then the external names must match
10699 if Present (Interface_Name (Internal_Ent)) then
10701 -- Ignore mismatching names in CodePeer mode, to support some
10702 -- old compilers which would export the same procedure under
10703 -- different names, e.g:
10704 -- procedure P;
10705 -- pragma Export_Procedure (P, "a");
10706 -- pragma Export_Procedure (P, "b");
10708 if CodePeer_Mode then
10709 return;
10710 end if;
10712 Check_Matching_Internal_Names : declare
10713 S1 : constant String_Id := Strval (Old_Name);
10714 S2 : constant String_Id := Strval (New_Name);
10716 procedure Mismatch;
10717 pragma No_Return (Mismatch);
10718 -- Called if names do not match
10720 --------------
10721 -- Mismatch --
10722 --------------
10724 procedure Mismatch is
10725 begin
10726 Error_Msg_Sloc := Sloc (Old_Name);
10727 Error_Pragma_Arg
10728 ("external name does not match that given #",
10729 Arg_External);
10730 end Mismatch;
10732 -- Start of processing for Check_Matching_Internal_Names
10734 begin
10735 if String_Length (S1) /= String_Length (S2) then
10736 Mismatch;
10738 else
10739 for J in 1 .. String_Length (S1) loop
10740 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
10741 Mismatch;
10742 end if;
10743 end loop;
10744 end if;
10745 end Check_Matching_Internal_Names;
10747 -- Otherwise set the given name
10749 else
10750 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
10751 Check_Duplicated_Export_Name (New_Name);
10752 end if;
10753 end Set_Extended_Import_Export_External_Name;
10755 ------------------
10756 -- Set_Imported --
10757 ------------------
10759 procedure Set_Imported (E : Entity_Id) is
10760 begin
10761 -- Error message if already imported or exported
10763 if Is_Exported (E) or else Is_Imported (E) then
10765 -- Error if being set Exported twice
10767 if Is_Exported (E) then
10768 Error_Msg_NE ("entity& was previously exported", N, E);
10770 -- Ignore error in CodePeer mode where we treat all imported
10771 -- subprograms as unknown.
10773 elsif CodePeer_Mode then
10774 goto OK;
10776 -- OK if Import/Interface case
10778 elsif Import_Interface_Present (N) then
10779 goto OK;
10781 -- Error if being set Imported twice
10783 else
10784 Error_Msg_NE ("entity& was previously imported", N, E);
10785 end if;
10787 Error_Msg_Name_1 := Pname;
10788 Error_Msg_N
10789 ("\(pragma% applies to all previous entities)", N);
10791 Error_Msg_Sloc := Sloc (E);
10792 Error_Msg_NE ("\import not allowed for& declared#", N, E);
10794 -- Here if not previously imported or exported, OK to import
10796 else
10797 Set_Is_Imported (E);
10799 -- For subprogram, set Import_Pragma field
10801 if Is_Subprogram (E) then
10802 Set_Import_Pragma (E, N);
10803 end if;
10805 -- If the entity is an object that is not at the library level,
10806 -- then it is statically allocated. We do not worry about objects
10807 -- with address clauses in this context since they are not really
10808 -- imported in the linker sense.
10810 if Is_Object (E)
10811 and then not Is_Library_Level_Entity (E)
10812 and then No (Address_Clause (E))
10813 then
10814 Set_Is_Statically_Allocated (E);
10815 end if;
10816 end if;
10818 <<OK>> null;
10819 end Set_Imported;
10821 -------------------------
10822 -- Set_Mechanism_Value --
10823 -------------------------
10825 -- Note: the mechanism name has not been analyzed (and cannot indeed be
10826 -- analyzed, since it is semantic nonsense), so we get it in the exact
10827 -- form created by the parser.
10829 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
10830 procedure Bad_Mechanism;
10831 pragma No_Return (Bad_Mechanism);
10832 -- Signal bad mechanism name
10834 -------------------
10835 -- Bad_Mechanism --
10836 -------------------
10838 procedure Bad_Mechanism is
10839 begin
10840 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
10841 end Bad_Mechanism;
10843 -- Start of processing for Set_Mechanism_Value
10845 begin
10846 if Mechanism (Ent) /= Default_Mechanism then
10847 Error_Msg_NE
10848 ("mechanism for & has already been set", Mech_Name, Ent);
10849 end if;
10851 -- MECHANISM_NAME ::= value | reference
10853 if Nkind (Mech_Name) = N_Identifier then
10854 if Chars (Mech_Name) = Name_Value then
10855 Set_Mechanism (Ent, By_Copy);
10856 return;
10858 elsif Chars (Mech_Name) = Name_Reference then
10859 Set_Mechanism (Ent, By_Reference);
10860 return;
10862 elsif Chars (Mech_Name) = Name_Copy then
10863 Error_Pragma_Arg
10864 ("bad mechanism name, Value assumed", Mech_Name);
10866 else
10867 Bad_Mechanism;
10868 end if;
10870 else
10871 Bad_Mechanism;
10872 end if;
10873 end Set_Mechanism_Value;
10875 --------------------------
10876 -- Set_Rational_Profile --
10877 --------------------------
10879 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
10880 -- extension to the semantics of renaming declarations.
10882 procedure Set_Rational_Profile is
10883 begin
10884 Implicit_Packing := True;
10885 Overriding_Renamings := True;
10886 Use_VADS_Size := True;
10887 end Set_Rational_Profile;
10889 ---------------------------
10890 -- Set_Ravenscar_Profile --
10891 ---------------------------
10893 -- The tasks to be done here are
10895 -- Set required policies
10897 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
10898 -- (For Ravenscar and GNAT_Extended_Ravenscar profiles)
10899 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
10900 -- (For GNAT_Ravenscar_EDF profile)
10901 -- pragma Locking_Policy (Ceiling_Locking)
10903 -- Set Detect_Blocking mode
10905 -- Set required restrictions (see System.Rident for detailed list)
10907 -- Set the No_Dependence rules
10908 -- No_Dependence => Ada.Asynchronous_Task_Control
10909 -- No_Dependence => Ada.Calendar
10910 -- No_Dependence => Ada.Execution_Time.Group_Budget
10911 -- No_Dependence => Ada.Execution_Time.Timers
10912 -- No_Dependence => Ada.Task_Attributes
10913 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
10915 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id) is
10916 procedure Set_Error_Msg_To_Profile_Name;
10917 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
10918 -- profile.
10920 -----------------------------------
10921 -- Set_Error_Msg_To_Profile_Name --
10922 -----------------------------------
10924 procedure Set_Error_Msg_To_Profile_Name is
10925 Prof_Nam : constant Node_Id :=
10926 Get_Pragma_Arg
10927 (First (Pragma_Argument_Associations (N)));
10929 begin
10930 Get_Name_String (Chars (Prof_Nam));
10931 Adjust_Name_Case (Global_Name_Buffer, Sloc (Prof_Nam));
10932 Error_Msg_Strlen := Name_Len;
10933 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
10934 end Set_Error_Msg_To_Profile_Name;
10936 -- Local variables
10938 Nod : Node_Id;
10939 Pref : Node_Id;
10940 Pref_Id : Node_Id;
10941 Sel_Id : Node_Id;
10943 Profile_Dispatching_Policy : Character;
10945 -- Start of processing for Set_Ravenscar_Profile
10947 begin
10948 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
10950 if Profile = GNAT_Ravenscar_EDF then
10951 Profile_Dispatching_Policy := 'E';
10953 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
10955 else
10956 Profile_Dispatching_Policy := 'F';
10957 end if;
10959 if Task_Dispatching_Policy /= ' '
10960 and then Task_Dispatching_Policy /= Profile_Dispatching_Policy
10961 then
10962 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10963 Set_Error_Msg_To_Profile_Name;
10964 Error_Pragma ("Profile (~) incompatible with policy#");
10966 -- Set the FIFO_Within_Priorities policy, but always preserve
10967 -- System_Location since we like the error message with the run time
10968 -- name.
10970 else
10971 Task_Dispatching_Policy := Profile_Dispatching_Policy;
10973 if Task_Dispatching_Policy_Sloc /= System_Location then
10974 Task_Dispatching_Policy_Sloc := Loc;
10975 end if;
10976 end if;
10978 -- pragma Locking_Policy (Ceiling_Locking)
10980 if Locking_Policy /= ' '
10981 and then Locking_Policy /= 'C'
10982 then
10983 Error_Msg_Sloc := Locking_Policy_Sloc;
10984 Set_Error_Msg_To_Profile_Name;
10985 Error_Pragma ("Profile (~) incompatible with policy#");
10987 -- Set the Ceiling_Locking policy, but preserve System_Location since
10988 -- we like the error message with the run time name.
10990 else
10991 Locking_Policy := 'C';
10993 if Locking_Policy_Sloc /= System_Location then
10994 Locking_Policy_Sloc := Loc;
10995 end if;
10996 end if;
10998 -- pragma Detect_Blocking
11000 Detect_Blocking := True;
11002 -- Set the corresponding restrictions
11004 Set_Profile_Restrictions
11005 (Profile, N, Warn => Treat_Restrictions_As_Warnings);
11007 -- Set the No_Dependence restrictions
11009 -- The following No_Dependence restrictions:
11010 -- No_Dependence => Ada.Asynchronous_Task_Control
11011 -- No_Dependence => Ada.Calendar
11012 -- No_Dependence => Ada.Task_Attributes
11013 -- are already set by previous call to Set_Profile_Restrictions.
11015 -- Set the following restrictions which were added to Ada 2005:
11016 -- No_Dependence => Ada.Execution_Time.Group_Budget
11017 -- No_Dependence => Ada.Execution_Time.Timers
11019 if Ada_Version >= Ada_2005 then
11020 Pref_Id := Make_Identifier (Loc, Name_Find ("ada"));
11021 Sel_Id := Make_Identifier (Loc, Name_Find ("execution_time"));
11023 Pref :=
11024 Make_Selected_Component
11025 (Sloc => Loc,
11026 Prefix => Pref_Id,
11027 Selector_Name => Sel_Id);
11029 Sel_Id := Make_Identifier (Loc, Name_Find ("group_budgets"));
11031 Nod :=
11032 Make_Selected_Component
11033 (Sloc => Loc,
11034 Prefix => Pref,
11035 Selector_Name => Sel_Id);
11037 Set_Restriction_No_Dependence
11038 (Unit => Nod,
11039 Warn => Treat_Restrictions_As_Warnings,
11040 Profile => Ravenscar);
11042 Sel_Id := Make_Identifier (Loc, Name_Find ("timers"));
11044 Nod :=
11045 Make_Selected_Component
11046 (Sloc => Loc,
11047 Prefix => Pref,
11048 Selector_Name => Sel_Id);
11050 Set_Restriction_No_Dependence
11051 (Unit => Nod,
11052 Warn => Treat_Restrictions_As_Warnings,
11053 Profile => Ravenscar);
11054 end if;
11056 -- Set the following restriction which was added to Ada 2012 (see
11057 -- AI-0171):
11058 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11060 if Ada_Version >= Ada_2012 then
11061 Pref_Id := Make_Identifier (Loc, Name_Find ("system"));
11062 Sel_Id := Make_Identifier (Loc, Name_Find ("multiprocessors"));
11064 Pref :=
11065 Make_Selected_Component
11066 (Sloc => Loc,
11067 Prefix => Pref_Id,
11068 Selector_Name => Sel_Id);
11070 Sel_Id := Make_Identifier (Loc, Name_Find ("dispatching_domains"));
11072 Nod :=
11073 Make_Selected_Component
11074 (Sloc => Loc,
11075 Prefix => Pref,
11076 Selector_Name => Sel_Id);
11078 Set_Restriction_No_Dependence
11079 (Unit => Nod,
11080 Warn => Treat_Restrictions_As_Warnings,
11081 Profile => Ravenscar);
11082 end if;
11083 end Set_Ravenscar_Profile;
11085 -- Start of processing for Analyze_Pragma
11087 begin
11088 -- The following code is a defense against recursion. Not clear that
11089 -- this can happen legitimately, but perhaps some error situations can
11090 -- cause it, and we did see this recursion during testing.
11092 if Analyzed (N) then
11093 return;
11094 else
11095 Set_Analyzed (N);
11096 end if;
11098 Check_Restriction_No_Use_Of_Pragma (N);
11100 -- Ignore pragma if Ignore_Pragma applies. Also ignore pragma
11101 -- Default_Scalar_Storage_Order if the -gnatI switch was given.
11103 if Should_Ignore_Pragma_Sem (N)
11104 or else (Prag_Id = Pragma_Default_Scalar_Storage_Order
11105 and then Ignore_Rep_Clauses)
11106 then
11107 return;
11108 end if;
11110 -- Deal with unrecognized pragma
11112 if not Is_Pragma_Name (Pname) then
11113 if Warn_On_Unrecognized_Pragma then
11114 Error_Msg_Name_1 := Pname;
11115 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
11117 for PN in First_Pragma_Name .. Last_Pragma_Name loop
11118 if Is_Bad_Spelling_Of (Pname, PN) then
11119 Error_Msg_Name_1 := PN;
11120 Error_Msg_N -- CODEFIX
11121 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
11122 exit;
11123 end if;
11124 end loop;
11125 end if;
11127 return;
11128 end if;
11130 -- Here to start processing for recognized pragma
11132 Pname := Original_Aspect_Pragma_Name (N);
11134 -- Capture setting of Opt.Uneval_Old
11136 case Opt.Uneval_Old is
11137 when 'A' =>
11138 Set_Uneval_Old_Accept (N);
11140 when 'E' =>
11141 null;
11143 when 'W' =>
11144 Set_Uneval_Old_Warn (N);
11146 when others =>
11147 raise Program_Error;
11148 end case;
11150 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
11151 -- is already set, indicating that we have already checked the policy
11152 -- at the right point. This happens for example in the case of a pragma
11153 -- that is derived from an Aspect.
11155 if Is_Ignored (N) or else Is_Checked (N) then
11156 null;
11158 -- For a pragma that is a rewriting of another pragma, copy the
11159 -- Is_Checked/Is_Ignored status from the rewritten pragma.
11161 elsif Is_Rewrite_Substitution (N)
11162 and then Nkind (Original_Node (N)) = N_Pragma
11163 then
11164 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
11165 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
11167 -- Otherwise query the applicable policy at this point
11169 else
11170 Check_Applicable_Policy (N);
11172 -- If pragma is disabled, rewrite as NULL and skip analysis
11174 if Is_Disabled (N) then
11175 Rewrite (N, Make_Null_Statement (Loc));
11176 Analyze (N);
11177 raise Pragma_Exit;
11178 end if;
11179 end if;
11181 -- Preset arguments
11183 Arg_Count := 0;
11184 Arg1 := Empty;
11185 Arg2 := Empty;
11186 Arg3 := Empty;
11187 Arg4 := Empty;
11189 if Present (Pragma_Argument_Associations (N)) then
11190 Arg_Count := List_Length (Pragma_Argument_Associations (N));
11191 Arg1 := First (Pragma_Argument_Associations (N));
11193 if Present (Arg1) then
11194 Arg2 := Next (Arg1);
11196 if Present (Arg2) then
11197 Arg3 := Next (Arg2);
11199 if Present (Arg3) then
11200 Arg4 := Next (Arg3);
11201 end if;
11202 end if;
11203 end if;
11204 end if;
11206 -- An enumeration type defines the pragmas that are supported by the
11207 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
11208 -- into the corresponding enumeration value for the following case.
11210 case Prag_Id is
11212 -----------------
11213 -- Abort_Defer --
11214 -----------------
11216 -- pragma Abort_Defer;
11218 when Pragma_Abort_Defer =>
11219 GNAT_Pragma;
11220 Check_Arg_Count (0);
11222 -- The only required semantic processing is to check the
11223 -- placement. This pragma must appear at the start of the
11224 -- statement sequence of a handled sequence of statements.
11226 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
11227 or else N /= First (Statements (Parent (N)))
11228 then
11229 Pragma_Misplaced;
11230 end if;
11232 --------------------
11233 -- Abstract_State --
11234 --------------------
11236 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
11238 -- ABSTRACT_STATE_LIST ::=
11239 -- null
11240 -- | STATE_NAME_WITH_OPTIONS
11241 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
11243 -- STATE_NAME_WITH_OPTIONS ::=
11244 -- STATE_NAME
11245 -- | (STATE_NAME with OPTION_LIST)
11247 -- OPTION_LIST ::= OPTION {, OPTION}
11249 -- OPTION ::=
11250 -- SIMPLE_OPTION
11251 -- | NAME_VALUE_OPTION
11253 -- SIMPLE_OPTION ::= Ghost | Synchronous
11255 -- NAME_VALUE_OPTION ::=
11256 -- Part_Of => ABSTRACT_STATE
11257 -- | External [=> EXTERNAL_PROPERTY_LIST]
11259 -- EXTERNAL_PROPERTY_LIST ::=
11260 -- EXTERNAL_PROPERTY
11261 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
11263 -- EXTERNAL_PROPERTY ::=
11264 -- Async_Readers [=> boolean_EXPRESSION]
11265 -- | Async_Writers [=> boolean_EXPRESSION]
11266 -- | Effective_Reads [=> boolean_EXPRESSION]
11267 -- | Effective_Writes [=> boolean_EXPRESSION]
11268 -- others => boolean_EXPRESSION
11270 -- STATE_NAME ::= defining_identifier
11272 -- ABSTRACT_STATE ::= name
11274 -- Characteristics:
11276 -- * Analysis - The annotation is fully analyzed immediately upon
11277 -- elaboration as it cannot forward reference entities.
11279 -- * Expansion - None.
11281 -- * Template - The annotation utilizes the generic template of the
11282 -- related package declaration.
11284 -- * Globals - The annotation cannot reference global entities.
11286 -- * Instance - The annotation is instantiated automatically when
11287 -- the related generic package is instantiated.
11289 when Pragma_Abstract_State => Abstract_State : declare
11290 Missing_Parentheses : Boolean := False;
11291 -- Flag set when a state declaration with options is not properly
11292 -- parenthesized.
11294 -- Flags used to verify the consistency of states
11296 Non_Null_Seen : Boolean := False;
11297 Null_Seen : Boolean := False;
11299 procedure Analyze_Abstract_State
11300 (State : Node_Id;
11301 Pack_Id : Entity_Id);
11302 -- Verify the legality of a single state declaration. Create and
11303 -- decorate a state abstraction entity and introduce it into the
11304 -- visibility chain. Pack_Id denotes the entity or the related
11305 -- package where pragma Abstract_State appears.
11307 procedure Malformed_State_Error (State : Node_Id);
11308 -- Emit an error concerning the illegal declaration of abstract
11309 -- state State. This routine diagnoses syntax errors that lead to
11310 -- a different parse tree. The error is issued regardless of the
11311 -- SPARK mode in effect.
11313 ----------------------------
11314 -- Analyze_Abstract_State --
11315 ----------------------------
11317 procedure Analyze_Abstract_State
11318 (State : Node_Id;
11319 Pack_Id : Entity_Id)
11321 -- Flags used to verify the consistency of options
11323 AR_Seen : Boolean := False;
11324 AW_Seen : Boolean := False;
11325 ER_Seen : Boolean := False;
11326 EW_Seen : Boolean := False;
11327 External_Seen : Boolean := False;
11328 Ghost_Seen : Boolean := False;
11329 Others_Seen : Boolean := False;
11330 Part_Of_Seen : Boolean := False;
11331 Synchronous_Seen : Boolean := False;
11333 -- Flags used to store the static value of all external states'
11334 -- expressions.
11336 AR_Val : Boolean := False;
11337 AW_Val : Boolean := False;
11338 ER_Val : Boolean := False;
11339 EW_Val : Boolean := False;
11341 State_Id : Entity_Id := Empty;
11342 -- The entity to be generated for the current state declaration
11344 procedure Analyze_External_Option (Opt : Node_Id);
11345 -- Verify the legality of option External
11347 procedure Analyze_External_Property
11348 (Prop : Node_Id;
11349 Expr : Node_Id := Empty);
11350 -- Verify the legailty of a single external property. Prop
11351 -- denotes the external property. Expr is the expression used
11352 -- to set the property.
11354 procedure Analyze_Part_Of_Option (Opt : Node_Id);
11355 -- Verify the legality of option Part_Of
11357 procedure Check_Duplicate_Option
11358 (Opt : Node_Id;
11359 Status : in out Boolean);
11360 -- Flag Status denotes whether a particular option has been
11361 -- seen while processing a state. This routine verifies that
11362 -- Opt is not a duplicate option and sets the flag Status
11363 -- (SPARK RM 7.1.4(1)).
11365 procedure Check_Duplicate_Property
11366 (Prop : Node_Id;
11367 Status : in out Boolean);
11368 -- Flag Status denotes whether a particular property has been
11369 -- seen while processing option External. This routine verifies
11370 -- that Prop is not a duplicate property and sets flag Status.
11371 -- Opt is not a duplicate property and sets the flag Status.
11372 -- (SPARK RM 7.1.4(2))
11374 procedure Check_Ghost_Synchronous;
11375 -- Ensure that the abstract state is not subject to both Ghost
11376 -- and Synchronous simple options. Emit an error if this is the
11377 -- case.
11379 procedure Create_Abstract_State
11380 (Nam : Name_Id;
11381 Decl : Node_Id;
11382 Loc : Source_Ptr;
11383 Is_Null : Boolean);
11384 -- Generate an abstract state entity with name Nam and enter it
11385 -- into visibility. Decl is the "declaration" of the state as
11386 -- it appears in pragma Abstract_State. Loc is the location of
11387 -- the related state "declaration". Flag Is_Null should be set
11388 -- when the associated Abstract_State pragma defines a null
11389 -- state.
11391 -----------------------------
11392 -- Analyze_External_Option --
11393 -----------------------------
11395 procedure Analyze_External_Option (Opt : Node_Id) is
11396 Errors : constant Nat := Serious_Errors_Detected;
11397 Prop : Node_Id;
11398 Props : Node_Id := Empty;
11400 begin
11401 if Nkind (Opt) = N_Component_Association then
11402 Props := Expression (Opt);
11403 end if;
11405 -- External state with properties
11407 if Present (Props) then
11409 -- Multiple properties appear as an aggregate
11411 if Nkind (Props) = N_Aggregate then
11413 -- Simple property form
11415 Prop := First (Expressions (Props));
11416 while Present (Prop) loop
11417 Analyze_External_Property (Prop);
11418 Next (Prop);
11419 end loop;
11421 -- Property with expression form
11423 Prop := First (Component_Associations (Props));
11424 while Present (Prop) loop
11425 Analyze_External_Property
11426 (Prop => First (Choices (Prop)),
11427 Expr => Expression (Prop));
11429 Next (Prop);
11430 end loop;
11432 -- Single property
11434 else
11435 Analyze_External_Property (Props);
11436 end if;
11438 -- An external state defined without any properties defaults
11439 -- all properties to True.
11441 else
11442 AR_Val := True;
11443 AW_Val := True;
11444 ER_Val := True;
11445 EW_Val := True;
11446 end if;
11448 -- Once all external properties have been processed, verify
11449 -- their mutual interaction. Do not perform the check when
11450 -- at least one of the properties is illegal as this will
11451 -- produce a bogus error.
11453 if Errors = Serious_Errors_Detected then
11454 Check_External_Properties
11455 (State, AR_Val, AW_Val, ER_Val, EW_Val);
11456 end if;
11457 end Analyze_External_Option;
11459 -------------------------------
11460 -- Analyze_External_Property --
11461 -------------------------------
11463 procedure Analyze_External_Property
11464 (Prop : Node_Id;
11465 Expr : Node_Id := Empty)
11467 Expr_Val : Boolean;
11469 begin
11470 -- Check the placement of "others" (if available)
11472 if Nkind (Prop) = N_Others_Choice then
11473 if Others_Seen then
11474 SPARK_Msg_N
11475 ("only one others choice allowed in option External",
11476 Prop);
11477 else
11478 Others_Seen := True;
11479 end if;
11481 elsif Others_Seen then
11482 SPARK_Msg_N
11483 ("others must be the last property in option External",
11484 Prop);
11486 -- The only remaining legal options are the four predefined
11487 -- external properties.
11489 elsif Nkind (Prop) = N_Identifier
11490 and then Nam_In (Chars (Prop), Name_Async_Readers,
11491 Name_Async_Writers,
11492 Name_Effective_Reads,
11493 Name_Effective_Writes)
11494 then
11495 null;
11497 -- Otherwise the construct is not a valid property
11499 else
11500 SPARK_Msg_N ("invalid external state property", Prop);
11501 return;
11502 end if;
11504 -- Ensure that the expression of the external state property
11505 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
11507 if Present (Expr) then
11508 Analyze_And_Resolve (Expr, Standard_Boolean);
11510 if Is_OK_Static_Expression (Expr) then
11511 Expr_Val := Is_True (Expr_Value (Expr));
11512 else
11513 SPARK_Msg_N
11514 ("expression of external state property must be "
11515 & "static", Expr);
11516 return;
11517 end if;
11519 -- The lack of expression defaults the property to True
11521 else
11522 Expr_Val := True;
11523 end if;
11525 -- Named properties
11527 if Nkind (Prop) = N_Identifier then
11528 if Chars (Prop) = Name_Async_Readers then
11529 Check_Duplicate_Property (Prop, AR_Seen);
11530 AR_Val := Expr_Val;
11532 elsif Chars (Prop) = Name_Async_Writers then
11533 Check_Duplicate_Property (Prop, AW_Seen);
11534 AW_Val := Expr_Val;
11536 elsif Chars (Prop) = Name_Effective_Reads then
11537 Check_Duplicate_Property (Prop, ER_Seen);
11538 ER_Val := Expr_Val;
11540 else
11541 Check_Duplicate_Property (Prop, EW_Seen);
11542 EW_Val := Expr_Val;
11543 end if;
11545 -- The handling of property "others" must take into account
11546 -- all other named properties that have been encountered so
11547 -- far. Only those that have not been seen are affected by
11548 -- "others".
11550 else
11551 if not AR_Seen then
11552 AR_Val := Expr_Val;
11553 end if;
11555 if not AW_Seen then
11556 AW_Val := Expr_Val;
11557 end if;
11559 if not ER_Seen then
11560 ER_Val := Expr_Val;
11561 end if;
11563 if not EW_Seen then
11564 EW_Val := Expr_Val;
11565 end if;
11566 end if;
11567 end Analyze_External_Property;
11569 ----------------------------
11570 -- Analyze_Part_Of_Option --
11571 ----------------------------
11573 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
11574 Encap : constant Node_Id := Expression (Opt);
11575 Constits : Elist_Id;
11576 Encap_Id : Entity_Id;
11577 Legal : Boolean;
11579 begin
11580 Check_Duplicate_Option (Opt, Part_Of_Seen);
11582 Analyze_Part_Of
11583 (Indic => First (Choices (Opt)),
11584 Item_Id => State_Id,
11585 Encap => Encap,
11586 Encap_Id => Encap_Id,
11587 Legal => Legal);
11589 -- The Part_Of indicator transforms the abstract state into
11590 -- a constituent of the encapsulating state or single
11591 -- concurrent type.
11593 if Legal then
11594 pragma Assert (Present (Encap_Id));
11595 Constits := Part_Of_Constituents (Encap_Id);
11597 if No (Constits) then
11598 Constits := New_Elmt_List;
11599 Set_Part_Of_Constituents (Encap_Id, Constits);
11600 end if;
11602 Append_Elmt (State_Id, Constits);
11603 Set_Encapsulating_State (State_Id, Encap_Id);
11604 end if;
11605 end Analyze_Part_Of_Option;
11607 ----------------------------
11608 -- Check_Duplicate_Option --
11609 ----------------------------
11611 procedure Check_Duplicate_Option
11612 (Opt : Node_Id;
11613 Status : in out Boolean)
11615 begin
11616 if Status then
11617 SPARK_Msg_N ("duplicate state option", Opt);
11618 end if;
11620 Status := True;
11621 end Check_Duplicate_Option;
11623 ------------------------------
11624 -- Check_Duplicate_Property --
11625 ------------------------------
11627 procedure Check_Duplicate_Property
11628 (Prop : Node_Id;
11629 Status : in out Boolean)
11631 begin
11632 if Status then
11633 SPARK_Msg_N ("duplicate external property", Prop);
11634 end if;
11636 Status := True;
11637 end Check_Duplicate_Property;
11639 -----------------------------
11640 -- Check_Ghost_Synchronous --
11641 -----------------------------
11643 procedure Check_Ghost_Synchronous is
11644 begin
11645 -- A synchronized abstract state cannot be Ghost and vice
11646 -- versa (SPARK RM 6.9(19)).
11648 if Ghost_Seen and Synchronous_Seen then
11649 SPARK_Msg_N ("synchronized state cannot be ghost", State);
11650 end if;
11651 end Check_Ghost_Synchronous;
11653 ---------------------------
11654 -- Create_Abstract_State --
11655 ---------------------------
11657 procedure Create_Abstract_State
11658 (Nam : Name_Id;
11659 Decl : Node_Id;
11660 Loc : Source_Ptr;
11661 Is_Null : Boolean)
11663 begin
11664 -- The abstract state may be semi-declared when the related
11665 -- package was withed through a limited with clause. In that
11666 -- case reuse the entity to fully declare the state.
11668 if Present (Decl) and then Present (Entity (Decl)) then
11669 State_Id := Entity (Decl);
11671 -- Otherwise the elaboration of pragma Abstract_State
11672 -- declares the state.
11674 else
11675 State_Id := Make_Defining_Identifier (Loc, Nam);
11677 if Present (Decl) then
11678 Set_Entity (Decl, State_Id);
11679 end if;
11680 end if;
11682 -- Null states never come from source
11684 Set_Comes_From_Source (State_Id, not Is_Null);
11685 Set_Parent (State_Id, State);
11686 Set_Ekind (State_Id, E_Abstract_State);
11687 Set_Etype (State_Id, Standard_Void_Type);
11688 Set_Encapsulating_State (State_Id, Empty);
11690 -- Set the SPARK mode from the current context
11692 Set_SPARK_Pragma (State_Id, SPARK_Mode_Pragma);
11693 Set_SPARK_Pragma_Inherited (State_Id);
11695 -- An abstract state declared within a Ghost region becomes
11696 -- Ghost (SPARK RM 6.9(2)).
11698 if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then
11699 Set_Is_Ghost_Entity (State_Id);
11700 end if;
11702 -- Establish a link between the state declaration and the
11703 -- abstract state entity. Note that a null state remains as
11704 -- N_Null and does not carry any linkages.
11706 if not Is_Null then
11707 if Present (Decl) then
11708 Set_Entity (Decl, State_Id);
11709 Set_Etype (Decl, Standard_Void_Type);
11710 end if;
11712 -- Every non-null state must be defined, nameable and
11713 -- resolvable.
11715 Push_Scope (Pack_Id);
11716 Generate_Definition (State_Id);
11717 Enter_Name (State_Id);
11718 Pop_Scope;
11719 end if;
11720 end Create_Abstract_State;
11722 -- Local variables
11724 Opt : Node_Id;
11725 Opt_Nam : Node_Id;
11727 -- Start of processing for Analyze_Abstract_State
11729 begin
11730 -- A package with a null abstract state is not allowed to
11731 -- declare additional states.
11733 if Null_Seen then
11734 SPARK_Msg_NE
11735 ("package & has null abstract state", State, Pack_Id);
11737 -- Null states appear as internally generated entities
11739 elsif Nkind (State) = N_Null then
11740 Create_Abstract_State
11741 (Nam => New_Internal_Name ('S'),
11742 Decl => Empty,
11743 Loc => Sloc (State),
11744 Is_Null => True);
11745 Null_Seen := True;
11747 -- Catch a case where a null state appears in a list of
11748 -- non-null states.
11750 if Non_Null_Seen then
11751 SPARK_Msg_NE
11752 ("package & has non-null abstract state",
11753 State, Pack_Id);
11754 end if;
11756 -- Simple state declaration
11758 elsif Nkind (State) = N_Identifier then
11759 Create_Abstract_State
11760 (Nam => Chars (State),
11761 Decl => State,
11762 Loc => Sloc (State),
11763 Is_Null => False);
11764 Non_Null_Seen := True;
11766 -- State declaration with various options. This construct
11767 -- appears as an extension aggregate in the tree.
11769 elsif Nkind (State) = N_Extension_Aggregate then
11770 if Nkind (Ancestor_Part (State)) = N_Identifier then
11771 Create_Abstract_State
11772 (Nam => Chars (Ancestor_Part (State)),
11773 Decl => Ancestor_Part (State),
11774 Loc => Sloc (Ancestor_Part (State)),
11775 Is_Null => False);
11776 Non_Null_Seen := True;
11777 else
11778 SPARK_Msg_N
11779 ("state name must be an identifier",
11780 Ancestor_Part (State));
11781 end if;
11783 -- Options External, Ghost and Synchronous appear as
11784 -- expressions.
11786 Opt := First (Expressions (State));
11787 while Present (Opt) loop
11788 if Nkind (Opt) = N_Identifier then
11790 -- External
11792 if Chars (Opt) = Name_External then
11793 Check_Duplicate_Option (Opt, External_Seen);
11794 Analyze_External_Option (Opt);
11796 -- Ghost
11798 elsif Chars (Opt) = Name_Ghost then
11799 Check_Duplicate_Option (Opt, Ghost_Seen);
11800 Check_Ghost_Synchronous;
11802 if Present (State_Id) then
11803 Set_Is_Ghost_Entity (State_Id);
11804 end if;
11806 -- Synchronous
11808 elsif Chars (Opt) = Name_Synchronous then
11809 Check_Duplicate_Option (Opt, Synchronous_Seen);
11810 Check_Ghost_Synchronous;
11812 -- Option Part_Of without an encapsulating state is
11813 -- illegal (SPARK RM 7.1.4(9)).
11815 elsif Chars (Opt) = Name_Part_Of then
11816 SPARK_Msg_N
11817 ("indicator Part_Of must denote abstract state, "
11818 & "single protected type or single task type",
11819 Opt);
11821 -- Do not emit an error message when a previous state
11822 -- declaration with options was not parenthesized as
11823 -- the option is actually another state declaration.
11825 -- with Abstract_State
11826 -- (State_1 with ..., -- missing parentheses
11827 -- (State_2 with ...),
11828 -- State_3) -- ok state declaration
11830 elsif Missing_Parentheses then
11831 null;
11833 -- Otherwise the option is not allowed. Note that it
11834 -- is not possible to distinguish between an option
11835 -- and a state declaration when a previous state with
11836 -- options not properly parentheses.
11838 -- with Abstract_State
11839 -- (State_1 with ..., -- missing parentheses
11840 -- State_2); -- could be an option
11842 else
11843 SPARK_Msg_N
11844 ("simple option not allowed in state declaration",
11845 Opt);
11846 end if;
11848 -- Catch a case where missing parentheses around a state
11849 -- declaration with options cause a subsequent state
11850 -- declaration with options to be treated as an option.
11852 -- with Abstract_State
11853 -- (State_1 with ..., -- missing parentheses
11854 -- (State_2 with ...))
11856 elsif Nkind (Opt) = N_Extension_Aggregate then
11857 Missing_Parentheses := True;
11858 SPARK_Msg_N
11859 ("state declaration must be parenthesized",
11860 Ancestor_Part (State));
11862 -- Otherwise the option is malformed
11864 else
11865 SPARK_Msg_N ("malformed option", Opt);
11866 end if;
11868 Next (Opt);
11869 end loop;
11871 -- Options External and Part_Of appear as component
11872 -- associations.
11874 Opt := First (Component_Associations (State));
11875 while Present (Opt) loop
11876 Opt_Nam := First (Choices (Opt));
11878 if Nkind (Opt_Nam) = N_Identifier then
11879 if Chars (Opt_Nam) = Name_External then
11880 Analyze_External_Option (Opt);
11882 elsif Chars (Opt_Nam) = Name_Part_Of then
11883 Analyze_Part_Of_Option (Opt);
11885 else
11886 SPARK_Msg_N ("invalid state option", Opt);
11887 end if;
11888 else
11889 SPARK_Msg_N ("invalid state option", Opt);
11890 end if;
11892 Next (Opt);
11893 end loop;
11895 -- Any other attempt to declare a state is illegal
11897 else
11898 Malformed_State_Error (State);
11899 return;
11900 end if;
11902 -- Guard against a junk state. In such cases no entity is
11903 -- generated and the subsequent checks cannot be applied.
11905 if Present (State_Id) then
11907 -- Verify whether the state does not introduce an illegal
11908 -- hidden state within a package subject to a null abstract
11909 -- state.
11911 Check_No_Hidden_State (State_Id);
11913 -- Check whether the lack of option Part_Of agrees with the
11914 -- placement of the abstract state with respect to the state
11915 -- space.
11917 if not Part_Of_Seen then
11918 Check_Missing_Part_Of (State_Id);
11919 end if;
11921 -- Associate the state with its related package
11923 if No (Abstract_States (Pack_Id)) then
11924 Set_Abstract_States (Pack_Id, New_Elmt_List);
11925 end if;
11927 Append_Elmt (State_Id, Abstract_States (Pack_Id));
11928 end if;
11929 end Analyze_Abstract_State;
11931 ---------------------------
11932 -- Malformed_State_Error --
11933 ---------------------------
11935 procedure Malformed_State_Error (State : Node_Id) is
11936 begin
11937 Error_Msg_N ("malformed abstract state declaration", State);
11939 -- An abstract state with a simple option is being declared
11940 -- with "=>" rather than the legal "with". The state appears
11941 -- as a component association.
11943 if Nkind (State) = N_Component_Association then
11944 Error_Msg_N ("\use WITH to specify simple option", State);
11945 end if;
11946 end Malformed_State_Error;
11948 -- Local variables
11950 Pack_Decl : Node_Id;
11951 Pack_Id : Entity_Id;
11952 State : Node_Id;
11953 States : Node_Id;
11955 -- Start of processing for Abstract_State
11957 begin
11958 GNAT_Pragma;
11959 Check_No_Identifiers;
11960 Check_Arg_Count (1);
11962 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
11964 if not Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
11965 N_Package_Declaration)
11966 then
11967 Pragma_Misplaced;
11968 return;
11969 end if;
11971 Pack_Id := Defining_Entity (Pack_Decl);
11973 -- A pragma that applies to a Ghost entity becomes Ghost for the
11974 -- purposes of legality checks and removal of ignored Ghost code.
11976 Mark_Ghost_Pragma (N, Pack_Id);
11977 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
11979 -- Chain the pragma on the contract for completeness
11981 Add_Contract_Item (N, Pack_Id);
11983 -- The legality checks of pragmas Abstract_State, Initializes, and
11984 -- Initial_Condition are affected by the SPARK mode in effect. In
11985 -- addition, these three pragmas are subject to an inherent order:
11987 -- 1) Abstract_State
11988 -- 2) Initializes
11989 -- 3) Initial_Condition
11991 -- Analyze all these pragmas in the order outlined above
11993 Analyze_If_Present (Pragma_SPARK_Mode);
11994 States := Expression (Get_Argument (N, Pack_Id));
11996 -- Multiple non-null abstract states appear as an aggregate
11998 if Nkind (States) = N_Aggregate then
11999 State := First (Expressions (States));
12000 while Present (State) loop
12001 Analyze_Abstract_State (State, Pack_Id);
12002 Next (State);
12003 end loop;
12005 -- An abstract state with a simple option is being illegaly
12006 -- declared with "=>" rather than "with". In this case the
12007 -- state declaration appears as a component association.
12009 if Present (Component_Associations (States)) then
12010 State := First (Component_Associations (States));
12011 while Present (State) loop
12012 Malformed_State_Error (State);
12013 Next (State);
12014 end loop;
12015 end if;
12017 -- Various forms of a single abstract state. Note that these may
12018 -- include malformed state declarations.
12020 else
12021 Analyze_Abstract_State (States, Pack_Id);
12022 end if;
12024 Analyze_If_Present (Pragma_Initializes);
12025 Analyze_If_Present (Pragma_Initial_Condition);
12026 end Abstract_State;
12028 ------------
12029 -- Ada_83 --
12030 ------------
12032 -- pragma Ada_83;
12034 -- Note: this pragma also has some specific processing in Par.Prag
12035 -- because we want to set the Ada version mode during parsing.
12037 when Pragma_Ada_83 =>
12038 GNAT_Pragma;
12039 Check_Arg_Count (0);
12041 -- We really should check unconditionally for proper configuration
12042 -- pragma placement, since we really don't want mixed Ada modes
12043 -- within a single unit, and the GNAT reference manual has always
12044 -- said this was a configuration pragma, but we did not check and
12045 -- are hesitant to add the check now.
12047 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
12048 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
12049 -- or Ada 2012 mode.
12051 if Ada_Version >= Ada_2005 then
12052 Check_Valid_Configuration_Pragma;
12053 end if;
12055 -- Now set Ada 83 mode
12057 if Latest_Ada_Only then
12058 Error_Pragma ("??pragma% ignored");
12059 else
12060 Ada_Version := Ada_83;
12061 Ada_Version_Explicit := Ada_83;
12062 Ada_Version_Pragma := N;
12063 end if;
12065 ------------
12066 -- Ada_95 --
12067 ------------
12069 -- pragma Ada_95;
12071 -- Note: this pragma also has some specific processing in Par.Prag
12072 -- because we want to set the Ada 83 version mode during parsing.
12074 when Pragma_Ada_95 =>
12075 GNAT_Pragma;
12076 Check_Arg_Count (0);
12078 -- We really should check unconditionally for proper configuration
12079 -- pragma placement, since we really don't want mixed Ada modes
12080 -- within a single unit, and the GNAT reference manual has always
12081 -- said this was a configuration pragma, but we did not check and
12082 -- are hesitant to add the check now.
12084 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
12085 -- or Ada 95, so we must check if we are in Ada 2005 mode.
12087 if Ada_Version >= Ada_2005 then
12088 Check_Valid_Configuration_Pragma;
12089 end if;
12091 -- Now set Ada 95 mode
12093 if Latest_Ada_Only then
12094 Error_Pragma ("??pragma% ignored");
12095 else
12096 Ada_Version := Ada_95;
12097 Ada_Version_Explicit := Ada_95;
12098 Ada_Version_Pragma := N;
12099 end if;
12101 ---------------------
12102 -- Ada_05/Ada_2005 --
12103 ---------------------
12105 -- pragma Ada_05;
12106 -- pragma Ada_05 (LOCAL_NAME);
12108 -- pragma Ada_2005;
12109 -- pragma Ada_2005 (LOCAL_NAME):
12111 -- Note: these pragmas also have some specific processing in Par.Prag
12112 -- because we want to set the Ada 2005 version mode during parsing.
12114 -- The one argument form is used for managing the transition from
12115 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
12116 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
12117 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
12118 -- mode, a preference rule is established which does not choose
12119 -- such an entity unless it is unambiguously specified. This avoids
12120 -- extra subprograms marked this way from generating ambiguities in
12121 -- otherwise legal pre-Ada_2005 programs. The one argument form is
12122 -- intended for exclusive use in the GNAT run-time library.
12124 when Pragma_Ada_05
12125 | Pragma_Ada_2005
12127 declare
12128 E_Id : Node_Id;
12130 begin
12131 GNAT_Pragma;
12133 if Arg_Count = 1 then
12134 Check_Arg_Is_Local_Name (Arg1);
12135 E_Id := Get_Pragma_Arg (Arg1);
12137 if Etype (E_Id) = Any_Type then
12138 return;
12139 end if;
12141 Set_Is_Ada_2005_Only (Entity (E_Id));
12142 Record_Rep_Item (Entity (E_Id), N);
12144 else
12145 Check_Arg_Count (0);
12147 -- For Ada_2005 we unconditionally enforce the documented
12148 -- configuration pragma placement, since we do not want to
12149 -- tolerate mixed modes in a unit involving Ada 2005. That
12150 -- would cause real difficulties for those cases where there
12151 -- are incompatibilities between Ada 95 and Ada 2005.
12153 Check_Valid_Configuration_Pragma;
12155 -- Now set appropriate Ada mode
12157 if Latest_Ada_Only then
12158 Error_Pragma ("??pragma% ignored");
12159 else
12160 Ada_Version := Ada_2005;
12161 Ada_Version_Explicit := Ada_2005;
12162 Ada_Version_Pragma := N;
12163 end if;
12164 end if;
12165 end;
12167 ---------------------
12168 -- Ada_12/Ada_2012 --
12169 ---------------------
12171 -- pragma Ada_12;
12172 -- pragma Ada_12 (LOCAL_NAME);
12174 -- pragma Ada_2012;
12175 -- pragma Ada_2012 (LOCAL_NAME):
12177 -- Note: these pragmas also have some specific processing in Par.Prag
12178 -- because we want to set the Ada 2012 version mode during parsing.
12180 -- The one argument form is used for managing the transition from Ada
12181 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
12182 -- as Ada_2012 only, then referencing the entity in any pre-Ada_2012
12183 -- mode will generate a warning. In addition, in any pre-Ada_2012
12184 -- mode, a preference rule is established which does not choose
12185 -- such an entity unless it is unambiguously specified. This avoids
12186 -- extra subprograms marked this way from generating ambiguities in
12187 -- otherwise legal pre-Ada_2012 programs. The one argument form is
12188 -- intended for exclusive use in the GNAT run-time library.
12190 when Pragma_Ada_12
12191 | Pragma_Ada_2012
12193 declare
12194 E_Id : Node_Id;
12196 begin
12197 GNAT_Pragma;
12199 if Arg_Count = 1 then
12200 Check_Arg_Is_Local_Name (Arg1);
12201 E_Id := Get_Pragma_Arg (Arg1);
12203 if Etype (E_Id) = Any_Type then
12204 return;
12205 end if;
12207 Set_Is_Ada_2012_Only (Entity (E_Id));
12208 Record_Rep_Item (Entity (E_Id), N);
12210 else
12211 Check_Arg_Count (0);
12213 -- For Ada_2012 we unconditionally enforce the documented
12214 -- configuration pragma placement, since we do not want to
12215 -- tolerate mixed modes in a unit involving Ada 2012. That
12216 -- would cause real difficulties for those cases where there
12217 -- are incompatibilities between Ada 95 and Ada 2012. We could
12218 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
12220 Check_Valid_Configuration_Pragma;
12222 -- Now set appropriate Ada mode
12224 Ada_Version := Ada_2012;
12225 Ada_Version_Explicit := Ada_2012;
12226 Ada_Version_Pragma := N;
12227 end if;
12228 end;
12230 --------------
12231 -- Ada_2020 --
12232 --------------
12234 -- pragma Ada_2020;
12236 -- Note: this pragma also has some specific processing in Par.Prag
12237 -- because we want to set the Ada 2020 version mode during parsing.
12239 when Pragma_Ada_2020 =>
12240 GNAT_Pragma;
12242 Check_Arg_Count (0);
12244 Check_Valid_Configuration_Pragma;
12246 -- Now set appropriate Ada mode
12248 Ada_Version := Ada_2020;
12249 Ada_Version_Explicit := Ada_2020;
12250 Ada_Version_Pragma := N;
12252 ----------------------
12253 -- All_Calls_Remote --
12254 ----------------------
12256 -- pragma All_Calls_Remote [(library_package_NAME)];
12258 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
12259 Lib_Entity : Entity_Id;
12261 begin
12262 Check_Ada_83_Warning;
12263 Check_Valid_Library_Unit_Pragma;
12265 if Nkind (N) = N_Null_Statement then
12266 return;
12267 end if;
12269 Lib_Entity := Find_Lib_Unit_Name;
12271 -- A pragma that applies to a Ghost entity becomes Ghost for the
12272 -- purposes of legality checks and removal of ignored Ghost code.
12274 Mark_Ghost_Pragma (N, Lib_Entity);
12276 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
12278 if Present (Lib_Entity) and then not Debug_Flag_U then
12279 if not Is_Remote_Call_Interface (Lib_Entity) then
12280 Error_Pragma ("pragma% only apply to rci unit");
12282 -- Set flag for entity of the library unit
12284 else
12285 Set_Has_All_Calls_Remote (Lib_Entity);
12286 end if;
12287 end if;
12288 end All_Calls_Remote;
12290 ---------------------------
12291 -- Allow_Integer_Address --
12292 ---------------------------
12294 -- pragma Allow_Integer_Address;
12296 when Pragma_Allow_Integer_Address =>
12297 GNAT_Pragma;
12298 Check_Valid_Configuration_Pragma;
12299 Check_Arg_Count (0);
12301 -- If Address is a private type, then set the flag to allow
12302 -- integer address values. If Address is not private, then this
12303 -- pragma has no purpose, so it is simply ignored. Not clear if
12304 -- there are any such targets now.
12306 if Opt.Address_Is_Private then
12307 Opt.Allow_Integer_Address := True;
12308 end if;
12310 --------------
12311 -- Annotate --
12312 --------------
12314 -- pragma Annotate
12315 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
12316 -- ARG ::= NAME | EXPRESSION
12318 -- The first two arguments are by convention intended to refer to an
12319 -- external tool and a tool-specific function. These arguments are
12320 -- not analyzed.
12322 when Pragma_Annotate => Annotate : declare
12323 Arg : Node_Id;
12324 Expr : Node_Id;
12325 Nam_Arg : Node_Id;
12327 begin
12328 GNAT_Pragma;
12329 Check_At_Least_N_Arguments (1);
12331 Nam_Arg := Last (Pragma_Argument_Associations (N));
12333 -- Determine whether the last argument is "Entity => local_NAME"
12334 -- and if it is, perform the required semantic checks. Remove the
12335 -- argument from further processing.
12337 if Nkind (Nam_Arg) = N_Pragma_Argument_Association
12338 and then Chars (Nam_Arg) = Name_Entity
12339 then
12340 Check_Arg_Is_Local_Name (Nam_Arg);
12341 Arg_Count := Arg_Count - 1;
12343 -- A pragma that applies to a Ghost entity becomes Ghost for
12344 -- the purposes of legality checks and removal of ignored Ghost
12345 -- code.
12347 if Is_Entity_Name (Get_Pragma_Arg (Nam_Arg))
12348 and then Present (Entity (Get_Pragma_Arg (Nam_Arg)))
12349 then
12350 Mark_Ghost_Pragma (N, Entity (Get_Pragma_Arg (Nam_Arg)));
12351 end if;
12353 -- Not allowed in compiler units (bootstrap issues)
12355 Check_Compiler_Unit ("Entity for pragma Annotate", N);
12356 end if;
12358 -- Continue the processing with last argument removed for now
12360 Check_Arg_Is_Identifier (Arg1);
12361 Check_No_Identifiers;
12362 Store_Note (N);
12364 -- The second parameter is optional, it is never analyzed
12366 if No (Arg2) then
12367 null;
12369 -- Otherwise there is a second parameter
12371 else
12372 -- The second parameter must be an identifier
12374 Check_Arg_Is_Identifier (Arg2);
12376 -- Process the remaining parameters (if any)
12378 Arg := Next (Arg2);
12379 while Present (Arg) loop
12380 Expr := Get_Pragma_Arg (Arg);
12381 Analyze (Expr);
12383 if Is_Entity_Name (Expr) then
12384 null;
12386 -- For string literals, we assume Standard_String as the
12387 -- type, unless the string contains wide or wide_wide
12388 -- characters.
12390 elsif Nkind (Expr) = N_String_Literal then
12391 if Has_Wide_Wide_Character (Expr) then
12392 Resolve (Expr, Standard_Wide_Wide_String);
12393 elsif Has_Wide_Character (Expr) then
12394 Resolve (Expr, Standard_Wide_String);
12395 else
12396 Resolve (Expr, Standard_String);
12397 end if;
12399 elsif Is_Overloaded (Expr) then
12400 Error_Pragma_Arg ("ambiguous argument for pragma%", Expr);
12402 else
12403 Resolve (Expr);
12404 end if;
12406 Next (Arg);
12407 end loop;
12408 end if;
12409 end Annotate;
12411 -------------------------------------------------
12412 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
12413 -------------------------------------------------
12415 -- pragma Assert
12416 -- ( [Check => ] Boolean_EXPRESSION
12417 -- [, [Message =>] Static_String_EXPRESSION]);
12419 -- pragma Assert_And_Cut
12420 -- ( [Check => ] Boolean_EXPRESSION
12421 -- [, [Message =>] Static_String_EXPRESSION]);
12423 -- pragma Assume
12424 -- ( [Check => ] Boolean_EXPRESSION
12425 -- [, [Message =>] Static_String_EXPRESSION]);
12427 -- pragma Loop_Invariant
12428 -- ( [Check => ] Boolean_EXPRESSION
12429 -- [, [Message =>] Static_String_EXPRESSION]);
12431 when Pragma_Assert
12432 | Pragma_Assert_And_Cut
12433 | Pragma_Assume
12434 | Pragma_Loop_Invariant
12436 Assert : declare
12437 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
12438 -- Determine whether expression Expr contains a Loop_Entry
12439 -- attribute reference.
12441 -------------------------
12442 -- Contains_Loop_Entry --
12443 -------------------------
12445 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
12446 Has_Loop_Entry : Boolean := False;
12448 function Process (N : Node_Id) return Traverse_Result;
12449 -- Process function for traversal to look for Loop_Entry
12451 -------------
12452 -- Process --
12453 -------------
12455 function Process (N : Node_Id) return Traverse_Result is
12456 begin
12457 if Nkind (N) = N_Attribute_Reference
12458 and then Attribute_Name (N) = Name_Loop_Entry
12459 then
12460 Has_Loop_Entry := True;
12461 return Abandon;
12462 else
12463 return OK;
12464 end if;
12465 end Process;
12467 procedure Traverse is new Traverse_Proc (Process);
12469 -- Start of processing for Contains_Loop_Entry
12471 begin
12472 Traverse (Expr);
12473 return Has_Loop_Entry;
12474 end Contains_Loop_Entry;
12476 -- Local variables
12478 Expr : Node_Id;
12479 New_Args : List_Id;
12481 -- Start of processing for Assert
12483 begin
12484 -- Assert is an Ada 2005 RM-defined pragma
12486 if Prag_Id = Pragma_Assert then
12487 Ada_2005_Pragma;
12489 -- The remaining ones are GNAT pragmas
12491 else
12492 GNAT_Pragma;
12493 end if;
12495 Check_At_Least_N_Arguments (1);
12496 Check_At_Most_N_Arguments (2);
12497 Check_Arg_Order ((Name_Check, Name_Message));
12498 Check_Optional_Identifier (Arg1, Name_Check);
12499 Expr := Get_Pragma_Arg (Arg1);
12501 -- Special processing for Loop_Invariant, Loop_Variant or for
12502 -- other cases where a Loop_Entry attribute is present. If the
12503 -- assertion pragma contains attribute Loop_Entry, ensure that
12504 -- the related pragma is within a loop.
12506 if Prag_Id = Pragma_Loop_Invariant
12507 or else Prag_Id = Pragma_Loop_Variant
12508 or else Contains_Loop_Entry (Expr)
12509 then
12510 Check_Loop_Pragma_Placement;
12512 -- Perform preanalysis to deal with embedded Loop_Entry
12513 -- attributes.
12515 Preanalyze_Assert_Expression (Expr, Any_Boolean);
12516 end if;
12518 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
12519 -- a corresponding Check pragma:
12521 -- pragma Check (name, condition [, msg]);
12523 -- Where name is the identifier matching the pragma name. So
12524 -- rewrite pragma in this manner, transfer the message argument
12525 -- if present, and analyze the result
12527 -- Note: When dealing with a semantically analyzed tree, the
12528 -- information that a Check node N corresponds to a source Assert,
12529 -- Assume, or Assert_And_Cut pragma can be retrieved from the
12530 -- pragma kind of Original_Node(N).
12532 New_Args := New_List (
12533 Make_Pragma_Argument_Association (Loc,
12534 Expression => Make_Identifier (Loc, Pname)),
12535 Make_Pragma_Argument_Association (Sloc (Expr),
12536 Expression => Expr));
12538 if Arg_Count > 1 then
12539 Check_Optional_Identifier (Arg2, Name_Message);
12541 -- Provide semantic annnotations for optional argument, for
12542 -- ASIS use, before rewriting.
12544 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
12545 Append_To (New_Args, New_Copy_Tree (Arg2));
12546 end if;
12548 -- Rewrite as Check pragma
12550 Rewrite (N,
12551 Make_Pragma (Loc,
12552 Chars => Name_Check,
12553 Pragma_Argument_Associations => New_Args));
12555 Analyze (N);
12556 end Assert;
12558 ----------------------
12559 -- Assertion_Policy --
12560 ----------------------
12562 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
12564 -- The following form is Ada 2012 only, but we allow it in all modes
12566 -- Pragma Assertion_Policy (
12567 -- ASSERTION_KIND => POLICY_IDENTIFIER
12568 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
12570 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
12572 -- RM_ASSERTION_KIND ::= Assert |
12573 -- Static_Predicate |
12574 -- Dynamic_Predicate |
12575 -- Pre |
12576 -- Pre'Class |
12577 -- Post |
12578 -- Post'Class |
12579 -- Type_Invariant |
12580 -- Type_Invariant'Class
12582 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
12583 -- Assume |
12584 -- Contract_Cases |
12585 -- Debug |
12586 -- Default_Initial_Condition |
12587 -- Ghost |
12588 -- Initial_Condition |
12589 -- Loop_Invariant |
12590 -- Loop_Variant |
12591 -- Postcondition |
12592 -- Precondition |
12593 -- Predicate |
12594 -- Refined_Post |
12595 -- Statement_Assertions
12597 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
12598 -- ID_ASSERTION_KIND list contains implementation-defined additions
12599 -- recognized by GNAT. The effect is to control the behavior of
12600 -- identically named aspects and pragmas, depending on the specified
12601 -- policy identifier:
12603 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
12605 -- Note: Check and Ignore are language-defined. Disable is a GNAT
12606 -- implementation-defined addition that results in totally ignoring
12607 -- the corresponding assertion. If Disable is specified, then the
12608 -- argument of the assertion is not even analyzed. This is useful
12609 -- when the aspect/pragma argument references entities in a with'ed
12610 -- package that is replaced by a dummy package in the final build.
12612 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
12613 -- and Type_Invariant'Class were recognized by the parser and
12614 -- transformed into references to the special internal identifiers
12615 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
12616 -- processing is required here.
12618 when Pragma_Assertion_Policy => Assertion_Policy : declare
12619 procedure Resolve_Suppressible (Policy : Node_Id);
12620 -- Converts the assertion policy 'Suppressible' to either Check or
12621 -- Ignore based on whether checks are suppressed via -gnatp.
12623 --------------------------
12624 -- Resolve_Suppressible --
12625 --------------------------
12627 procedure Resolve_Suppressible (Policy : Node_Id) is
12628 Arg : constant Node_Id := Get_Pragma_Arg (Policy);
12629 Nam : Name_Id;
12631 begin
12632 -- Transform policy argument Suppressible into either Ignore or
12633 -- Check depending on whether checks are enabled or suppressed.
12635 if Chars (Arg) = Name_Suppressible then
12636 if Suppress_Checks then
12637 Nam := Name_Ignore;
12638 else
12639 Nam := Name_Check;
12640 end if;
12642 Rewrite (Arg, Make_Identifier (Sloc (Arg), Nam));
12643 end if;
12644 end Resolve_Suppressible;
12646 -- Local variables
12648 Arg : Node_Id;
12649 Kind : Name_Id;
12650 LocP : Source_Ptr;
12651 Policy : Node_Id;
12653 begin
12654 Ada_2005_Pragma;
12656 -- This can always appear as a configuration pragma
12658 if Is_Configuration_Pragma then
12659 null;
12661 -- It can also appear in a declarative part or package spec in Ada
12662 -- 2012 mode. We allow this in other modes, but in that case we
12663 -- consider that we have an Ada 2012 pragma on our hands.
12665 else
12666 Check_Is_In_Decl_Part_Or_Package_Spec;
12667 Ada_2012_Pragma;
12668 end if;
12670 -- One argument case with no identifier (first form above)
12672 if Arg_Count = 1
12673 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
12674 or else Chars (Arg1) = No_Name)
12675 then
12676 Check_Arg_Is_One_Of (Arg1,
12677 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
12679 Resolve_Suppressible (Arg1);
12681 -- Treat one argument Assertion_Policy as equivalent to:
12683 -- pragma Check_Policy (Assertion, policy)
12685 -- So rewrite pragma in that manner and link on to the chain
12686 -- of Check_Policy pragmas, marking the pragma as analyzed.
12688 Policy := Get_Pragma_Arg (Arg1);
12690 Rewrite (N,
12691 Make_Pragma (Loc,
12692 Chars => Name_Check_Policy,
12693 Pragma_Argument_Associations => New_List (
12694 Make_Pragma_Argument_Association (Loc,
12695 Expression => Make_Identifier (Loc, Name_Assertion)),
12697 Make_Pragma_Argument_Association (Loc,
12698 Expression =>
12699 Make_Identifier (Sloc (Policy), Chars (Policy))))));
12700 Analyze (N);
12702 -- Here if we have two or more arguments
12704 else
12705 Check_At_Least_N_Arguments (1);
12706 Ada_2012_Pragma;
12708 -- Loop through arguments
12710 Arg := Arg1;
12711 while Present (Arg) loop
12712 LocP := Sloc (Arg);
12714 -- Kind must be specified
12716 if Nkind (Arg) /= N_Pragma_Argument_Association
12717 or else Chars (Arg) = No_Name
12718 then
12719 Error_Pragma_Arg
12720 ("missing assertion kind for pragma%", Arg);
12721 end if;
12723 -- Check Kind and Policy have allowed forms
12725 Kind := Chars (Arg);
12726 Policy := Get_Pragma_Arg (Arg);
12728 if not Is_Valid_Assertion_Kind (Kind) then
12729 Error_Pragma_Arg
12730 ("invalid assertion kind for pragma%", Arg);
12731 end if;
12733 Check_Arg_Is_One_Of (Arg,
12734 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
12736 Resolve_Suppressible (Arg);
12738 if Kind = Name_Ghost then
12740 -- The Ghost policy must be either Check or Ignore
12741 -- (SPARK RM 6.9(6)).
12743 if not Nam_In (Chars (Policy), Name_Check,
12744 Name_Ignore)
12745 then
12746 Error_Pragma_Arg
12747 ("argument of pragma % Ghost must be Check or "
12748 & "Ignore", Policy);
12749 end if;
12751 -- Pragma Assertion_Policy specifying a Ghost policy
12752 -- cannot occur within a Ghost subprogram or package
12753 -- (SPARK RM 6.9(14)).
12755 if Ghost_Mode > None then
12756 Error_Pragma
12757 ("pragma % cannot appear within ghost subprogram or "
12758 & "package");
12759 end if;
12760 end if;
12762 -- Rewrite the Assertion_Policy pragma as a series of
12763 -- Check_Policy pragmas of the form:
12765 -- Check_Policy (Kind, Policy);
12767 -- Note: the insertion of the pragmas cannot be done with
12768 -- Insert_Action because in the configuration case, there
12769 -- are no scopes on the scope stack and the mechanism will
12770 -- fail.
12772 Insert_Before_And_Analyze (N,
12773 Make_Pragma (LocP,
12774 Chars => Name_Check_Policy,
12775 Pragma_Argument_Associations => New_List (
12776 Make_Pragma_Argument_Association (LocP,
12777 Expression => Make_Identifier (LocP, Kind)),
12778 Make_Pragma_Argument_Association (LocP,
12779 Expression => Policy))));
12781 Arg := Next (Arg);
12782 end loop;
12784 -- Rewrite the Assertion_Policy pragma as null since we have
12785 -- now inserted all the equivalent Check pragmas.
12787 Rewrite (N, Make_Null_Statement (Loc));
12788 Analyze (N);
12789 end if;
12790 end Assertion_Policy;
12792 ------------------------------
12793 -- Assume_No_Invalid_Values --
12794 ------------------------------
12796 -- pragma Assume_No_Invalid_Values (On | Off);
12798 when Pragma_Assume_No_Invalid_Values =>
12799 GNAT_Pragma;
12800 Check_Valid_Configuration_Pragma;
12801 Check_Arg_Count (1);
12802 Check_No_Identifiers;
12803 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12805 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
12806 Assume_No_Invalid_Values := True;
12807 else
12808 Assume_No_Invalid_Values := False;
12809 end if;
12811 --------------------------
12812 -- Attribute_Definition --
12813 --------------------------
12815 -- pragma Attribute_Definition
12816 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
12817 -- [Entity =>] LOCAL_NAME,
12818 -- [Expression =>] EXPRESSION | NAME);
12820 when Pragma_Attribute_Definition => Attribute_Definition : declare
12821 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
12822 Aname : Name_Id;
12824 begin
12825 GNAT_Pragma;
12826 Check_Arg_Count (3);
12827 Check_Optional_Identifier (Arg1, "attribute");
12828 Check_Optional_Identifier (Arg2, "entity");
12829 Check_Optional_Identifier (Arg3, "expression");
12831 if Nkind (Attribute_Designator) /= N_Identifier then
12832 Error_Msg_N ("attribute name expected", Attribute_Designator);
12833 return;
12834 end if;
12836 Check_Arg_Is_Local_Name (Arg2);
12838 -- If the attribute is not recognized, then issue a warning (not
12839 -- an error), and ignore the pragma.
12841 Aname := Chars (Attribute_Designator);
12843 if not Is_Attribute_Name (Aname) then
12844 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
12845 return;
12846 end if;
12848 -- Otherwise, rewrite the pragma as an attribute definition clause
12850 Rewrite (N,
12851 Make_Attribute_Definition_Clause (Loc,
12852 Name => Get_Pragma_Arg (Arg2),
12853 Chars => Aname,
12854 Expression => Get_Pragma_Arg (Arg3)));
12855 Analyze (N);
12856 end Attribute_Definition;
12858 ------------------------------------------------------------------
12859 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
12860 ------------------------------------------------------------------
12862 -- pragma Asynch_Readers [ (boolean_EXPRESSION) ];
12863 -- pragma Asynch_Writers [ (boolean_EXPRESSION) ];
12864 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
12865 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
12867 when Pragma_Async_Readers
12868 | Pragma_Async_Writers
12869 | Pragma_Effective_Reads
12870 | Pragma_Effective_Writes
12872 Async_Effective : declare
12873 Obj_Decl : Node_Id;
12874 Obj_Id : Entity_Id;
12876 begin
12877 GNAT_Pragma;
12878 Check_No_Identifiers;
12879 Check_At_Most_N_Arguments (1);
12881 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
12883 -- Object declaration
12885 if Nkind (Obj_Decl) /= N_Object_Declaration then
12886 Pragma_Misplaced;
12887 return;
12888 end if;
12890 Obj_Id := Defining_Entity (Obj_Decl);
12892 -- Perform minimal verification to ensure that the argument is at
12893 -- least a variable. Subsequent finer grained checks will be done
12894 -- at the end of the declarative region the contains the pragma.
12896 if Ekind (Obj_Id) = E_Variable then
12898 -- A pragma that applies to a Ghost entity becomes Ghost for
12899 -- the purposes of legality checks and removal of ignored Ghost
12900 -- code.
12902 Mark_Ghost_Pragma (N, Obj_Id);
12904 -- Chain the pragma on the contract for further processing by
12905 -- Analyze_External_Property_In_Decl_Part.
12907 Add_Contract_Item (N, Obj_Id);
12909 -- Analyze the Boolean expression (if any)
12911 if Present (Arg1) then
12912 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
12913 end if;
12915 -- Otherwise the external property applies to a constant
12917 else
12918 Error_Pragma ("pragma % must apply to a volatile object");
12919 end if;
12920 end Async_Effective;
12922 ------------------
12923 -- Asynchronous --
12924 ------------------
12926 -- pragma Asynchronous (LOCAL_NAME);
12928 when Pragma_Asynchronous => Asynchronous : declare
12929 C_Ent : Entity_Id;
12930 Decl : Node_Id;
12931 Formal : Entity_Id;
12932 L : List_Id;
12933 Nm : Entity_Id;
12934 S : Node_Id;
12936 procedure Process_Async_Pragma;
12937 -- Common processing for procedure and access-to-procedure case
12939 --------------------------
12940 -- Process_Async_Pragma --
12941 --------------------------
12943 procedure Process_Async_Pragma is
12944 begin
12945 if No (L) then
12946 Set_Is_Asynchronous (Nm);
12947 return;
12948 end if;
12950 -- The formals should be of mode IN (RM E.4.1(6))
12952 S := First (L);
12953 while Present (S) loop
12954 Formal := Defining_Identifier (S);
12956 if Nkind (Formal) = N_Defining_Identifier
12957 and then Ekind (Formal) /= E_In_Parameter
12958 then
12959 Error_Pragma_Arg
12960 ("pragma% procedure can only have IN parameter",
12961 Arg1);
12962 end if;
12964 Next (S);
12965 end loop;
12967 Set_Is_Asynchronous (Nm);
12968 end Process_Async_Pragma;
12970 -- Start of processing for pragma Asynchronous
12972 begin
12973 Check_Ada_83_Warning;
12974 Check_No_Identifiers;
12975 Check_Arg_Count (1);
12976 Check_Arg_Is_Local_Name (Arg1);
12978 if Debug_Flag_U then
12979 return;
12980 end if;
12982 C_Ent := Cunit_Entity (Current_Sem_Unit);
12983 Analyze (Get_Pragma_Arg (Arg1));
12984 Nm := Entity (Get_Pragma_Arg (Arg1));
12986 -- A pragma that applies to a Ghost entity becomes Ghost for the
12987 -- purposes of legality checks and removal of ignored Ghost code.
12989 Mark_Ghost_Pragma (N, Nm);
12991 if not Is_Remote_Call_Interface (C_Ent)
12992 and then not Is_Remote_Types (C_Ent)
12993 then
12994 -- This pragma should only appear in an RCI or Remote Types
12995 -- unit (RM E.4.1(4)).
12997 Error_Pragma
12998 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
12999 end if;
13001 if Ekind (Nm) = E_Procedure
13002 and then Nkind (Parent (Nm)) = N_Procedure_Specification
13003 then
13004 if not Is_Remote_Call_Interface (Nm) then
13005 Error_Pragma_Arg
13006 ("pragma% cannot be applied on non-remote procedure",
13007 Arg1);
13008 end if;
13010 L := Parameter_Specifications (Parent (Nm));
13011 Process_Async_Pragma;
13012 return;
13014 elsif Ekind (Nm) = E_Function then
13015 Error_Pragma_Arg
13016 ("pragma% cannot be applied to function", Arg1);
13018 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
13019 if Is_Record_Type (Nm) then
13021 -- A record type that is the Equivalent_Type for a remote
13022 -- access-to-subprogram type.
13024 Decl := Declaration_Node (Corresponding_Remote_Type (Nm));
13026 else
13027 -- A non-expanded RAS type (distribution is not enabled)
13029 Decl := Declaration_Node (Nm);
13030 end if;
13032 if Nkind (Decl) = N_Full_Type_Declaration
13033 and then Nkind (Type_Definition (Decl)) =
13034 N_Access_Procedure_Definition
13035 then
13036 L := Parameter_Specifications (Type_Definition (Decl));
13037 Process_Async_Pragma;
13039 if Is_Asynchronous (Nm)
13040 and then Expander_Active
13041 and then Get_PCS_Name /= Name_No_DSA
13042 then
13043 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
13044 end if;
13046 else
13047 Error_Pragma_Arg
13048 ("pragma% cannot reference access-to-function type",
13049 Arg1);
13050 end if;
13052 -- Only other possibility is Access-to-class-wide type
13054 elsif Is_Access_Type (Nm)
13055 and then Is_Class_Wide_Type (Designated_Type (Nm))
13056 then
13057 Check_First_Subtype (Arg1);
13058 Set_Is_Asynchronous (Nm);
13059 if Expander_Active then
13060 RACW_Type_Is_Asynchronous (Nm);
13061 end if;
13063 else
13064 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
13065 end if;
13066 end Asynchronous;
13068 ------------
13069 -- Atomic --
13070 ------------
13072 -- pragma Atomic (LOCAL_NAME);
13074 when Pragma_Atomic =>
13075 Process_Atomic_Independent_Shared_Volatile;
13077 -----------------------
13078 -- Atomic_Components --
13079 -----------------------
13081 -- pragma Atomic_Components (array_LOCAL_NAME);
13083 -- This processing is shared by Volatile_Components
13085 when Pragma_Atomic_Components
13086 | Pragma_Volatile_Components
13088 Atomic_Components : declare
13089 D : Node_Id;
13090 E : Entity_Id;
13091 E_Id : Node_Id;
13092 K : Node_Kind;
13094 begin
13095 Check_Ada_83_Warning;
13096 Check_No_Identifiers;
13097 Check_Arg_Count (1);
13098 Check_Arg_Is_Local_Name (Arg1);
13099 E_Id := Get_Pragma_Arg (Arg1);
13101 if Etype (E_Id) = Any_Type then
13102 return;
13103 end if;
13105 E := Entity (E_Id);
13107 -- A pragma that applies to a Ghost entity becomes Ghost for the
13108 -- purposes of legality checks and removal of ignored Ghost code.
13110 Mark_Ghost_Pragma (N, E);
13111 Check_Duplicate_Pragma (E);
13113 if Rep_Item_Too_Early (E, N)
13114 or else
13115 Rep_Item_Too_Late (E, N)
13116 then
13117 return;
13118 end if;
13120 D := Declaration_Node (E);
13121 K := Nkind (D);
13123 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
13124 or else
13125 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
13126 and then Nkind (D) = N_Object_Declaration
13127 and then Nkind (Object_Definition (D)) =
13128 N_Constrained_Array_Definition)
13129 then
13130 -- The flag is set on the object, or on the base type
13132 if Nkind (D) /= N_Object_Declaration then
13133 E := Base_Type (E);
13134 end if;
13136 -- Atomic implies both Independent and Volatile
13138 if Prag_Id = Pragma_Atomic_Components then
13139 Set_Has_Atomic_Components (E);
13140 Set_Has_Independent_Components (E);
13141 end if;
13143 Set_Has_Volatile_Components (E);
13145 else
13146 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
13147 end if;
13148 end Atomic_Components;
13150 --------------------
13151 -- Attach_Handler --
13152 --------------------
13154 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
13156 when Pragma_Attach_Handler =>
13157 Check_Ada_83_Warning;
13158 Check_No_Identifiers;
13159 Check_Arg_Count (2);
13161 if No_Run_Time_Mode then
13162 Error_Msg_CRT ("Attach_Handler pragma", N);
13163 else
13164 Check_Interrupt_Or_Attach_Handler;
13166 -- The expression that designates the attribute may depend on a
13167 -- discriminant, and is therefore a per-object expression, to
13168 -- be expanded in the init proc. If expansion is enabled, then
13169 -- perform semantic checks on a copy only.
13171 declare
13172 Temp : Node_Id;
13173 Typ : Node_Id;
13174 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
13176 begin
13177 -- In Relaxed_RM_Semantics mode, we allow any static
13178 -- integer value, for compatibility with other compilers.
13180 if Relaxed_RM_Semantics
13181 and then Nkind (Parg2) = N_Integer_Literal
13182 then
13183 Typ := Standard_Integer;
13184 else
13185 Typ := RTE (RE_Interrupt_ID);
13186 end if;
13188 if Expander_Active then
13189 Temp := New_Copy_Tree (Parg2);
13190 Set_Parent (Temp, N);
13191 Preanalyze_And_Resolve (Temp, Typ);
13192 else
13193 Analyze (Parg2);
13194 Resolve (Parg2, Typ);
13195 end if;
13196 end;
13198 Process_Interrupt_Or_Attach_Handler;
13199 end if;
13201 --------------------
13202 -- C_Pass_By_Copy --
13203 --------------------
13205 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
13207 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
13208 Arg : Node_Id;
13209 Val : Uint;
13211 begin
13212 GNAT_Pragma;
13213 Check_Valid_Configuration_Pragma;
13214 Check_Arg_Count (1);
13215 Check_Optional_Identifier (Arg1, "max_size");
13217 Arg := Get_Pragma_Arg (Arg1);
13218 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
13220 Val := Expr_Value (Arg);
13222 if Val <= 0 then
13223 Error_Pragma_Arg
13224 ("maximum size for pragma% must be positive", Arg1);
13226 elsif UI_Is_In_Int_Range (Val) then
13227 Default_C_Record_Mechanism := UI_To_Int (Val);
13229 -- If a giant value is given, Int'Last will do well enough.
13230 -- If sometime someone complains that a record larger than
13231 -- two gigabytes is not copied, we will worry about it then.
13233 else
13234 Default_C_Record_Mechanism := Mechanism_Type'Last;
13235 end if;
13236 end C_Pass_By_Copy;
13238 -----------
13239 -- Check --
13240 -----------
13242 -- pragma Check ([Name =>] CHECK_KIND,
13243 -- [Check =>] Boolean_EXPRESSION
13244 -- [,[Message =>] String_EXPRESSION]);
13246 -- CHECK_KIND ::= IDENTIFIER |
13247 -- Pre'Class |
13248 -- Post'Class |
13249 -- Invariant'Class |
13250 -- Type_Invariant'Class
13252 -- The identifiers Assertions and Statement_Assertions are not
13253 -- allowed, since they have special meaning for Check_Policy.
13255 -- WARNING: The code below manages Ghost regions. Return statements
13256 -- must be replaced by gotos which jump to the end of the code and
13257 -- restore the Ghost mode.
13259 when Pragma_Check => Check : declare
13260 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
13261 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
13262 -- Save the Ghost-related attributes to restore on exit
13264 Cname : Name_Id;
13265 Eloc : Source_Ptr;
13266 Expr : Node_Id;
13267 Str : Node_Id;
13268 pragma Warnings (Off, Str);
13270 begin
13271 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
13272 -- the mode now to ensure that any nodes generated during analysis
13273 -- and expansion are marked as Ghost.
13275 Set_Ghost_Mode (N);
13277 GNAT_Pragma;
13278 Check_At_Least_N_Arguments (2);
13279 Check_At_Most_N_Arguments (3);
13280 Check_Optional_Identifier (Arg1, Name_Name);
13281 Check_Optional_Identifier (Arg2, Name_Check);
13283 if Arg_Count = 3 then
13284 Check_Optional_Identifier (Arg3, Name_Message);
13285 Str := Get_Pragma_Arg (Arg3);
13286 end if;
13288 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
13289 Check_Arg_Is_Identifier (Arg1);
13290 Cname := Chars (Get_Pragma_Arg (Arg1));
13292 -- Check forbidden name Assertions or Statement_Assertions
13294 case Cname is
13295 when Name_Assertions =>
13296 Error_Pragma_Arg
13297 ("""Assertions"" is not allowed as a check kind for "
13298 & "pragma%", Arg1);
13300 when Name_Statement_Assertions =>
13301 Error_Pragma_Arg
13302 ("""Statement_Assertions"" is not allowed as a check kind "
13303 & "for pragma%", Arg1);
13305 when others =>
13306 null;
13307 end case;
13309 -- Check applicable policy. We skip this if Checked/Ignored status
13310 -- is already set (e.g. in the case of a pragma from an aspect).
13312 if Is_Checked (N) or else Is_Ignored (N) then
13313 null;
13315 -- For a non-source pragma that is a rewriting of another pragma,
13316 -- copy the Is_Checked/Ignored status from the rewritten pragma.
13318 elsif Is_Rewrite_Substitution (N)
13319 and then Nkind (Original_Node (N)) = N_Pragma
13320 then
13321 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
13322 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
13324 -- Otherwise query the applicable policy at this point
13326 else
13327 case Check_Kind (Cname) is
13328 when Name_Ignore =>
13329 Set_Is_Ignored (N, True);
13330 Set_Is_Checked (N, False);
13332 when Name_Check =>
13333 Set_Is_Ignored (N, False);
13334 Set_Is_Checked (N, True);
13336 -- For disable, rewrite pragma as null statement and skip
13337 -- rest of the analysis of the pragma.
13339 when Name_Disable =>
13340 Rewrite (N, Make_Null_Statement (Loc));
13341 Analyze (N);
13342 raise Pragma_Exit;
13344 -- No other possibilities
13346 when others =>
13347 raise Program_Error;
13348 end case;
13349 end if;
13351 -- If check kind was not Disable, then continue pragma analysis
13353 Expr := Get_Pragma_Arg (Arg2);
13355 -- Deal with SCO generation
13357 if Is_Checked (N) and then not Split_PPC (N) then
13358 Set_SCO_Pragma_Enabled (Loc);
13359 end if;
13361 -- Deal with analyzing the string argument. If checks are not
13362 -- on we don't want any expansion (since such expansion would
13363 -- not get properly deleted) but we do want to analyze (to get
13364 -- proper references). The Preanalyze_And_Resolve routine does
13365 -- just what we want. Ditto if pragma is active, because it will
13366 -- be rewritten as an if-statement whose analysis will complete
13367 -- analysis and expansion of the string message. This makes a
13368 -- difference in the unusual case where the expression for the
13369 -- string may have a side effect, such as raising an exception.
13370 -- This is mandated by RM 11.4.2, which specifies that the string
13371 -- expression is only evaluated if the check fails and
13372 -- Assertion_Error is to be raised.
13374 if Arg_Count = 3 then
13375 Preanalyze_And_Resolve (Str, Standard_String);
13376 end if;
13378 -- Now you might think we could just do the same with the Boolean
13379 -- expression if checks are off (and expansion is on) and then
13380 -- rewrite the check as a null statement. This would work but we
13381 -- would lose the useful warnings about an assertion being bound
13382 -- to fail even if assertions are turned off.
13384 -- So instead we wrap the boolean expression in an if statement
13385 -- that looks like:
13387 -- if False and then condition then
13388 -- null;
13389 -- end if;
13391 -- The reason we do this rewriting during semantic analysis rather
13392 -- than as part of normal expansion is that we cannot analyze and
13393 -- expand the code for the boolean expression directly, or it may
13394 -- cause insertion of actions that would escape the attempt to
13395 -- suppress the check code.
13397 -- Note that the Sloc for the if statement corresponds to the
13398 -- argument condition, not the pragma itself. The reason for
13399 -- this is that we may generate a warning if the condition is
13400 -- False at compile time, and we do not want to delete this
13401 -- warning when we delete the if statement.
13403 if Expander_Active and Is_Ignored (N) then
13404 Eloc := Sloc (Expr);
13406 Rewrite (N,
13407 Make_If_Statement (Eloc,
13408 Condition =>
13409 Make_And_Then (Eloc,
13410 Left_Opnd => Make_Identifier (Eloc, Name_False),
13411 Right_Opnd => Expr),
13412 Then_Statements => New_List (
13413 Make_Null_Statement (Eloc))));
13415 -- Now go ahead and analyze the if statement
13417 In_Assertion_Expr := In_Assertion_Expr + 1;
13419 -- One rather special treatment. If we are now in Eliminated
13420 -- overflow mode, then suppress overflow checking since we do
13421 -- not want to drag in the bignum stuff if we are in Ignore
13422 -- mode anyway. This is particularly important if we are using
13423 -- a configurable run time that does not support bignum ops.
13425 if Scope_Suppress.Overflow_Mode_Assertions = Eliminated then
13426 declare
13427 Svo : constant Boolean :=
13428 Scope_Suppress.Suppress (Overflow_Check);
13429 begin
13430 Scope_Suppress.Overflow_Mode_Assertions := Strict;
13431 Scope_Suppress.Suppress (Overflow_Check) := True;
13432 Analyze (N);
13433 Scope_Suppress.Suppress (Overflow_Check) := Svo;
13434 Scope_Suppress.Overflow_Mode_Assertions := Eliminated;
13435 end;
13437 -- Not that special case
13439 else
13440 Analyze (N);
13441 end if;
13443 -- All done with this check
13445 In_Assertion_Expr := In_Assertion_Expr - 1;
13447 -- Check is active or expansion not active. In these cases we can
13448 -- just go ahead and analyze the boolean with no worries.
13450 else
13451 In_Assertion_Expr := In_Assertion_Expr + 1;
13452 Analyze_And_Resolve (Expr, Any_Boolean);
13453 In_Assertion_Expr := In_Assertion_Expr - 1;
13454 end if;
13456 Restore_Ghost_Region (Saved_GM, Saved_IGR);
13457 end Check;
13459 --------------------------
13460 -- Check_Float_Overflow --
13461 --------------------------
13463 -- pragma Check_Float_Overflow;
13465 when Pragma_Check_Float_Overflow =>
13466 GNAT_Pragma;
13467 Check_Valid_Configuration_Pragma;
13468 Check_Arg_Count (0);
13469 Check_Float_Overflow := not Machine_Overflows_On_Target;
13471 ----------------
13472 -- Check_Name --
13473 ----------------
13475 -- pragma Check_Name (check_IDENTIFIER);
13477 when Pragma_Check_Name =>
13478 GNAT_Pragma;
13479 Check_No_Identifiers;
13480 Check_Valid_Configuration_Pragma;
13481 Check_Arg_Count (1);
13482 Check_Arg_Is_Identifier (Arg1);
13484 declare
13485 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
13487 begin
13488 for J in Check_Names.First .. Check_Names.Last loop
13489 if Check_Names.Table (J) = Nam then
13490 return;
13491 end if;
13492 end loop;
13494 Check_Names.Append (Nam);
13495 end;
13497 ------------------
13498 -- Check_Policy --
13499 ------------------
13501 -- This is the old style syntax, which is still allowed in all modes:
13503 -- pragma Check_Policy ([Name =>] CHECK_KIND
13504 -- [Policy =>] POLICY_IDENTIFIER);
13506 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
13508 -- CHECK_KIND ::= IDENTIFIER |
13509 -- Pre'Class |
13510 -- Post'Class |
13511 -- Type_Invariant'Class |
13512 -- Invariant'Class
13514 -- This is the new style syntax, compatible with Assertion_Policy
13515 -- and also allowed in all modes.
13517 -- Pragma Check_Policy (
13518 -- CHECK_KIND => POLICY_IDENTIFIER
13519 -- {, CHECK_KIND => POLICY_IDENTIFIER});
13521 -- Note: the identifiers Name and Policy are not allowed as
13522 -- Check_Kind values. This avoids ambiguities between the old and
13523 -- new form syntax.
13525 when Pragma_Check_Policy => Check_Policy : declare
13526 Kind : Node_Id;
13528 begin
13529 GNAT_Pragma;
13530 Check_At_Least_N_Arguments (1);
13532 -- A Check_Policy pragma can appear either as a configuration
13533 -- pragma, or in a declarative part or a package spec (see RM
13534 -- 11.5(5) for rules for Suppress/Unsuppress which are also
13535 -- followed for Check_Policy).
13537 if not Is_Configuration_Pragma then
13538 Check_Is_In_Decl_Part_Or_Package_Spec;
13539 end if;
13541 -- Figure out if we have the old or new syntax. We have the
13542 -- old syntax if the first argument has no identifier, or the
13543 -- identifier is Name.
13545 if Nkind (Arg1) /= N_Pragma_Argument_Association
13546 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
13547 then
13548 -- Old syntax
13550 Check_Arg_Count (2);
13551 Check_Optional_Identifier (Arg1, Name_Name);
13552 Kind := Get_Pragma_Arg (Arg1);
13553 Rewrite_Assertion_Kind (Kind,
13554 From_Policy => Comes_From_Source (N));
13555 Check_Arg_Is_Identifier (Arg1);
13557 -- Check forbidden check kind
13559 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
13560 Error_Msg_Name_2 := Chars (Kind);
13561 Error_Pragma_Arg
13562 ("pragma% does not allow% as check name", Arg1);
13563 end if;
13565 -- Check policy
13567 Check_Optional_Identifier (Arg2, Name_Policy);
13568 Check_Arg_Is_One_Of
13569 (Arg2,
13570 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
13572 -- And chain pragma on the Check_Policy_List for search
13574 Set_Next_Pragma (N, Opt.Check_Policy_List);
13575 Opt.Check_Policy_List := N;
13577 -- For the new syntax, what we do is to convert each argument to
13578 -- an old syntax equivalent. We do that because we want to chain
13579 -- old style Check_Policy pragmas for the search (we don't want
13580 -- to have to deal with multiple arguments in the search).
13582 else
13583 declare
13584 Arg : Node_Id;
13585 Argx : Node_Id;
13586 LocP : Source_Ptr;
13587 New_P : Node_Id;
13589 begin
13590 Arg := Arg1;
13591 while Present (Arg) loop
13592 LocP := Sloc (Arg);
13593 Argx := Get_Pragma_Arg (Arg);
13595 -- Kind must be specified
13597 if Nkind (Arg) /= N_Pragma_Argument_Association
13598 or else Chars (Arg) = No_Name
13599 then
13600 Error_Pragma_Arg
13601 ("missing assertion kind for pragma%", Arg);
13602 end if;
13604 -- Construct equivalent old form syntax Check_Policy
13605 -- pragma and insert it to get remaining checks.
13607 New_P :=
13608 Make_Pragma (LocP,
13609 Chars => Name_Check_Policy,
13610 Pragma_Argument_Associations => New_List (
13611 Make_Pragma_Argument_Association (LocP,
13612 Expression =>
13613 Make_Identifier (LocP, Chars (Arg))),
13614 Make_Pragma_Argument_Association (Sloc (Argx),
13615 Expression => Argx)));
13617 Arg := Next (Arg);
13619 -- For a configuration pragma, insert old form in
13620 -- the corresponding file.
13622 if Is_Configuration_Pragma then
13623 Insert_After (N, New_P);
13624 Analyze (New_P);
13626 else
13627 Insert_Action (N, New_P);
13628 end if;
13629 end loop;
13631 -- Rewrite original Check_Policy pragma to null, since we
13632 -- have converted it into a series of old syntax pragmas.
13634 Rewrite (N, Make_Null_Statement (Loc));
13635 Analyze (N);
13636 end;
13637 end if;
13638 end Check_Policy;
13640 -------------
13641 -- Comment --
13642 -------------
13644 -- pragma Comment (static_string_EXPRESSION)
13646 -- Processing for pragma Comment shares the circuitry for pragma
13647 -- Ident. The only differences are that Ident enforces a limit of 31
13648 -- characters on its argument, and also enforces limitations on
13649 -- placement for DEC compatibility. Pragma Comment shares neither of
13650 -- these restrictions.
13652 -------------------
13653 -- Common_Object --
13654 -------------------
13656 -- pragma Common_Object (
13657 -- [Internal =>] LOCAL_NAME
13658 -- [, [External =>] EXTERNAL_SYMBOL]
13659 -- [, [Size =>] EXTERNAL_SYMBOL]);
13661 -- Processing for this pragma is shared with Psect_Object
13663 ------------------------
13664 -- Compile_Time_Error --
13665 ------------------------
13667 -- pragma Compile_Time_Error
13668 -- (boolean_EXPRESSION, static_string_EXPRESSION);
13670 when Pragma_Compile_Time_Error =>
13671 GNAT_Pragma;
13672 Process_Compile_Time_Warning_Or_Error;
13674 --------------------------
13675 -- Compile_Time_Warning --
13676 --------------------------
13678 -- pragma Compile_Time_Warning
13679 -- (boolean_EXPRESSION, static_string_EXPRESSION);
13681 when Pragma_Compile_Time_Warning =>
13682 GNAT_Pragma;
13683 Process_Compile_Time_Warning_Or_Error;
13685 ---------------------------
13686 -- Compiler_Unit_Warning --
13687 ---------------------------
13689 -- pragma Compiler_Unit_Warning;
13691 -- Historical note
13693 -- Originally, we had only pragma Compiler_Unit, and it resulted in
13694 -- errors not warnings. This means that we had introduced a big extra
13695 -- inertia to compiler changes, since even if we implemented a new
13696 -- feature, and even if all versions to be used for bootstrapping
13697 -- implemented this new feature, we could not use it, since old
13698 -- compilers would give errors for using this feature in units
13699 -- having Compiler_Unit pragmas.
13701 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
13702 -- problem. We no longer have any units mentioning Compiler_Unit,
13703 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
13704 -- and thus generates a warning which can be ignored. So that deals
13705 -- with the problem of old compilers not implementing the newer form
13706 -- of the pragma.
13708 -- Newer compilers recognize the new pragma, but generate warning
13709 -- messages instead of errors, which again can be ignored in the
13710 -- case of an old compiler which implements a wanted new feature
13711 -- but at the time felt like warning about it for older compilers.
13713 -- We retain Compiler_Unit so that new compilers can be used to build
13714 -- older run-times that use this pragma. That's an unusual case, but
13715 -- it's easy enough to handle, so why not?
13717 when Pragma_Compiler_Unit
13718 | Pragma_Compiler_Unit_Warning
13720 GNAT_Pragma;
13721 Check_Arg_Count (0);
13723 -- Only recognized in main unit
13725 if Current_Sem_Unit = Main_Unit then
13726 Compiler_Unit := True;
13727 end if;
13729 -----------------------------
13730 -- Complete_Representation --
13731 -----------------------------
13733 -- pragma Complete_Representation;
13735 when Pragma_Complete_Representation =>
13736 GNAT_Pragma;
13737 Check_Arg_Count (0);
13739 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
13740 Error_Pragma
13741 ("pragma & must appear within record representation clause");
13742 end if;
13744 ----------------------------
13745 -- Complex_Representation --
13746 ----------------------------
13748 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
13750 when Pragma_Complex_Representation => Complex_Representation : declare
13751 E_Id : Entity_Id;
13752 E : Entity_Id;
13753 Ent : Entity_Id;
13755 begin
13756 GNAT_Pragma;
13757 Check_Arg_Count (1);
13758 Check_Optional_Identifier (Arg1, Name_Entity);
13759 Check_Arg_Is_Local_Name (Arg1);
13760 E_Id := Get_Pragma_Arg (Arg1);
13762 if Etype (E_Id) = Any_Type then
13763 return;
13764 end if;
13766 E := Entity (E_Id);
13768 if not Is_Record_Type (E) then
13769 Error_Pragma_Arg
13770 ("argument for pragma% must be record type", Arg1);
13771 end if;
13773 Ent := First_Entity (E);
13775 if No (Ent)
13776 or else No (Next_Entity (Ent))
13777 or else Present (Next_Entity (Next_Entity (Ent)))
13778 or else not Is_Floating_Point_Type (Etype (Ent))
13779 or else Etype (Ent) /= Etype (Next_Entity (Ent))
13780 then
13781 Error_Pragma_Arg
13782 ("record for pragma% must have two fields of the same "
13783 & "floating-point type", Arg1);
13785 else
13786 Set_Has_Complex_Representation (Base_Type (E));
13788 -- We need to treat the type has having a non-standard
13789 -- representation, for back-end purposes, even though in
13790 -- general a complex will have the default representation
13791 -- of a record with two real components.
13793 Set_Has_Non_Standard_Rep (Base_Type (E));
13794 end if;
13795 end Complex_Representation;
13797 -------------------------
13798 -- Component_Alignment --
13799 -------------------------
13801 -- pragma Component_Alignment (
13802 -- [Form =>] ALIGNMENT_CHOICE
13803 -- [, [Name =>] type_LOCAL_NAME]);
13805 -- ALIGNMENT_CHOICE ::=
13806 -- Component_Size
13807 -- | Component_Size_4
13808 -- | Storage_Unit
13809 -- | Default
13811 when Pragma_Component_Alignment => Component_AlignmentP : declare
13812 Args : Args_List (1 .. 2);
13813 Names : constant Name_List (1 .. 2) := (
13814 Name_Form,
13815 Name_Name);
13817 Form : Node_Id renames Args (1);
13818 Name : Node_Id renames Args (2);
13820 Atype : Component_Alignment_Kind;
13821 Typ : Entity_Id;
13823 begin
13824 GNAT_Pragma;
13825 Gather_Associations (Names, Args);
13827 if No (Form) then
13828 Error_Pragma ("missing Form argument for pragma%");
13829 end if;
13831 Check_Arg_Is_Identifier (Form);
13833 -- Get proper alignment, note that Default = Component_Size on all
13834 -- machines we have so far, and we want to set this value rather
13835 -- than the default value to indicate that it has been explicitly
13836 -- set (and thus will not get overridden by the default component
13837 -- alignment for the current scope)
13839 if Chars (Form) = Name_Component_Size then
13840 Atype := Calign_Component_Size;
13842 elsif Chars (Form) = Name_Component_Size_4 then
13843 Atype := Calign_Component_Size_4;
13845 elsif Chars (Form) = Name_Default then
13846 Atype := Calign_Component_Size;
13848 elsif Chars (Form) = Name_Storage_Unit then
13849 Atype := Calign_Storage_Unit;
13851 else
13852 Error_Pragma_Arg
13853 ("invalid Form parameter for pragma%", Form);
13854 end if;
13856 -- The pragma appears in a configuration file
13858 if No (Parent (N)) then
13859 Check_Valid_Configuration_Pragma;
13861 -- Capture the component alignment in a global variable when
13862 -- the pragma appears in a configuration file. Note that the
13863 -- scope stack is empty at this point and cannot be used to
13864 -- store the alignment value.
13866 Configuration_Component_Alignment := Atype;
13868 -- Case with no name, supplied, affects scope table entry
13870 elsif No (Name) then
13871 Scope_Stack.Table
13872 (Scope_Stack.Last).Component_Alignment_Default := Atype;
13874 -- Case of name supplied
13876 else
13877 Check_Arg_Is_Local_Name (Name);
13878 Find_Type (Name);
13879 Typ := Entity (Name);
13881 if Typ = Any_Type
13882 or else Rep_Item_Too_Early (Typ, N)
13883 then
13884 return;
13885 else
13886 Typ := Underlying_Type (Typ);
13887 end if;
13889 if not Is_Record_Type (Typ)
13890 and then not Is_Array_Type (Typ)
13891 then
13892 Error_Pragma_Arg
13893 ("Name parameter of pragma% must identify record or "
13894 & "array type", Name);
13895 end if;
13897 -- An explicit Component_Alignment pragma overrides an
13898 -- implicit pragma Pack, but not an explicit one.
13900 if not Has_Pragma_Pack (Base_Type (Typ)) then
13901 Set_Is_Packed (Base_Type (Typ), False);
13902 Set_Component_Alignment (Base_Type (Typ), Atype);
13903 end if;
13904 end if;
13905 end Component_AlignmentP;
13907 --------------------------------
13908 -- Constant_After_Elaboration --
13909 --------------------------------
13911 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
13913 when Pragma_Constant_After_Elaboration => Constant_After_Elaboration :
13914 declare
13915 Obj_Decl : Node_Id;
13916 Obj_Id : Entity_Id;
13918 begin
13919 GNAT_Pragma;
13920 Check_No_Identifiers;
13921 Check_At_Most_N_Arguments (1);
13923 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
13925 if Nkind (Obj_Decl) /= N_Object_Declaration then
13926 Pragma_Misplaced;
13927 return;
13928 end if;
13930 Obj_Id := Defining_Entity (Obj_Decl);
13932 -- The object declaration must be a library-level variable which
13933 -- is either explicitly initialized or obtains a value during the
13934 -- elaboration of a package body (SPARK RM 3.3.1).
13936 if Ekind (Obj_Id) = E_Variable then
13937 if not Is_Library_Level_Entity (Obj_Id) then
13938 Error_Pragma
13939 ("pragma % must apply to a library level variable");
13940 return;
13941 end if;
13943 -- Otherwise the pragma applies to a constant, which is illegal
13945 else
13946 Error_Pragma ("pragma % must apply to a variable declaration");
13947 return;
13948 end if;
13950 -- A pragma that applies to a Ghost entity becomes Ghost for the
13951 -- purposes of legality checks and removal of ignored Ghost code.
13953 Mark_Ghost_Pragma (N, Obj_Id);
13955 -- Chain the pragma on the contract for completeness
13957 Add_Contract_Item (N, Obj_Id);
13959 -- Analyze the Boolean expression (if any)
13961 if Present (Arg1) then
13962 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
13963 end if;
13964 end Constant_After_Elaboration;
13966 --------------------
13967 -- Contract_Cases --
13968 --------------------
13970 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
13972 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
13974 -- CASE_GUARD ::= boolean_EXPRESSION | others
13976 -- CONSEQUENCE ::= boolean_EXPRESSION
13978 -- Characteristics:
13980 -- * Analysis - The annotation undergoes initial checks to verify
13981 -- the legal placement and context. Secondary checks preanalyze the
13982 -- expressions in:
13984 -- Analyze_Contract_Cases_In_Decl_Part
13986 -- * Expansion - The annotation is expanded during the expansion of
13987 -- the related subprogram [body] contract as performed in:
13989 -- Expand_Subprogram_Contract
13991 -- * Template - The annotation utilizes the generic template of the
13992 -- related subprogram [body] when it is:
13994 -- aspect on subprogram declaration
13995 -- aspect on stand-alone subprogram body
13996 -- pragma on stand-alone subprogram body
13998 -- The annotation must prepare its own template when it is:
14000 -- pragma on subprogram declaration
14002 -- * Globals - Capture of global references must occur after full
14003 -- analysis.
14005 -- * Instance - The annotation is instantiated automatically when
14006 -- the related generic subprogram [body] is instantiated except for
14007 -- the "pragma on subprogram declaration" case. In that scenario
14008 -- the annotation must instantiate itself.
14010 when Pragma_Contract_Cases => Contract_Cases : declare
14011 Spec_Id : Entity_Id;
14012 Subp_Decl : Node_Id;
14013 Subp_Spec : Node_Id;
14015 begin
14016 GNAT_Pragma;
14017 Check_No_Identifiers;
14018 Check_Arg_Count (1);
14020 -- Ensure the proper placement of the pragma. Contract_Cases must
14021 -- be associated with a subprogram declaration or a body that acts
14022 -- as a spec.
14024 Subp_Decl :=
14025 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
14027 -- Entry
14029 if Nkind (Subp_Decl) = N_Entry_Declaration then
14030 null;
14032 -- Generic subprogram
14034 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
14035 null;
14037 -- Body acts as spec
14039 elsif Nkind (Subp_Decl) = N_Subprogram_Body
14040 and then No (Corresponding_Spec (Subp_Decl))
14041 then
14042 null;
14044 -- Body stub acts as spec
14046 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
14047 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
14048 then
14049 null;
14051 -- Subprogram
14053 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
14054 Subp_Spec := Specification (Subp_Decl);
14056 -- Pragma Contract_Cases is forbidden on null procedures, as
14057 -- this may lead to potential ambiguities in behavior when
14058 -- interface null procedures are involved.
14060 if Nkind (Subp_Spec) = N_Procedure_Specification
14061 and then Null_Present (Subp_Spec)
14062 then
14063 Error_Msg_N (Fix_Error
14064 ("pragma % cannot apply to null procedure"), N);
14065 return;
14066 end if;
14068 else
14069 Pragma_Misplaced;
14070 return;
14071 end if;
14073 Spec_Id := Unique_Defining_Entity (Subp_Decl);
14075 -- A pragma that applies to a Ghost entity becomes Ghost for the
14076 -- purposes of legality checks and removal of ignored Ghost code.
14078 Mark_Ghost_Pragma (N, Spec_Id);
14079 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
14081 -- Chain the pragma on the contract for further processing by
14082 -- Analyze_Contract_Cases_In_Decl_Part.
14084 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
14086 -- Fully analyze the pragma when it appears inside an entry
14087 -- or subprogram body because it cannot benefit from forward
14088 -- references.
14090 if Nkind_In (Subp_Decl, N_Entry_Body,
14091 N_Subprogram_Body,
14092 N_Subprogram_Body_Stub)
14093 then
14094 -- The legality checks of pragma Contract_Cases are affected by
14095 -- the SPARK mode in effect and the volatility of the context.
14096 -- Analyze all pragmas in a specific order.
14098 Analyze_If_Present (Pragma_SPARK_Mode);
14099 Analyze_If_Present (Pragma_Volatile_Function);
14100 Analyze_Contract_Cases_In_Decl_Part (N);
14101 end if;
14102 end Contract_Cases;
14104 ----------------
14105 -- Controlled --
14106 ----------------
14108 -- pragma Controlled (first_subtype_LOCAL_NAME);
14110 when Pragma_Controlled => Controlled : declare
14111 Arg : Node_Id;
14113 begin
14114 Check_No_Identifiers;
14115 Check_Arg_Count (1);
14116 Check_Arg_Is_Local_Name (Arg1);
14117 Arg := Get_Pragma_Arg (Arg1);
14119 if not Is_Entity_Name (Arg)
14120 or else not Is_Access_Type (Entity (Arg))
14121 then
14122 Error_Pragma_Arg ("pragma% requires access type", Arg1);
14123 else
14124 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
14125 end if;
14126 end Controlled;
14128 ----------------
14129 -- Convention --
14130 ----------------
14132 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
14133 -- [Entity =>] LOCAL_NAME);
14135 when Pragma_Convention => Convention : declare
14136 C : Convention_Id;
14137 E : Entity_Id;
14138 pragma Warnings (Off, C);
14139 pragma Warnings (Off, E);
14141 begin
14142 Check_Arg_Order ((Name_Convention, Name_Entity));
14143 Check_Ada_83_Warning;
14144 Check_Arg_Count (2);
14145 Process_Convention (C, E);
14147 -- A pragma that applies to a Ghost entity becomes Ghost for the
14148 -- purposes of legality checks and removal of ignored Ghost code.
14150 Mark_Ghost_Pragma (N, E);
14151 end Convention;
14153 ---------------------------
14154 -- Convention_Identifier --
14155 ---------------------------
14157 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
14158 -- [Convention =>] convention_IDENTIFIER);
14160 when Pragma_Convention_Identifier => Convention_Identifier : declare
14161 Idnam : Name_Id;
14162 Cname : Name_Id;
14164 begin
14165 GNAT_Pragma;
14166 Check_Arg_Order ((Name_Name, Name_Convention));
14167 Check_Arg_Count (2);
14168 Check_Optional_Identifier (Arg1, Name_Name);
14169 Check_Optional_Identifier (Arg2, Name_Convention);
14170 Check_Arg_Is_Identifier (Arg1);
14171 Check_Arg_Is_Identifier (Arg2);
14172 Idnam := Chars (Get_Pragma_Arg (Arg1));
14173 Cname := Chars (Get_Pragma_Arg (Arg2));
14175 if Is_Convention_Name (Cname) then
14176 Record_Convention_Identifier
14177 (Idnam, Get_Convention_Id (Cname));
14178 else
14179 Error_Pragma_Arg
14180 ("second arg for % pragma must be convention", Arg2);
14181 end if;
14182 end Convention_Identifier;
14184 ---------------
14185 -- CPP_Class --
14186 ---------------
14188 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
14190 when Pragma_CPP_Class =>
14191 GNAT_Pragma;
14193 if Warn_On_Obsolescent_Feature then
14194 Error_Msg_N
14195 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
14196 & "effect; replace it by pragma import?j?", N);
14197 end if;
14199 Check_Arg_Count (1);
14201 Rewrite (N,
14202 Make_Pragma (Loc,
14203 Chars => Name_Import,
14204 Pragma_Argument_Associations => New_List (
14205 Make_Pragma_Argument_Association (Loc,
14206 Expression => Make_Identifier (Loc, Name_CPP)),
14207 New_Copy (First (Pragma_Argument_Associations (N))))));
14208 Analyze (N);
14210 ---------------------
14211 -- CPP_Constructor --
14212 ---------------------
14214 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
14215 -- [, [External_Name =>] static_string_EXPRESSION ]
14216 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14218 when Pragma_CPP_Constructor => CPP_Constructor : declare
14219 Elmt : Elmt_Id;
14220 Id : Entity_Id;
14221 Def_Id : Entity_Id;
14222 Tag_Typ : Entity_Id;
14224 begin
14225 GNAT_Pragma;
14226 Check_At_Least_N_Arguments (1);
14227 Check_At_Most_N_Arguments (3);
14228 Check_Optional_Identifier (Arg1, Name_Entity);
14229 Check_Arg_Is_Local_Name (Arg1);
14231 Id := Get_Pragma_Arg (Arg1);
14232 Find_Program_Unit_Name (Id);
14234 -- If we did not find the name, we are done
14236 if Etype (Id) = Any_Type then
14237 return;
14238 end if;
14240 Def_Id := Entity (Id);
14242 -- Check if already defined as constructor
14244 if Is_Constructor (Def_Id) then
14245 Error_Msg_N
14246 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
14247 return;
14248 end if;
14250 if Ekind (Def_Id) = E_Function
14251 and then (Is_CPP_Class (Etype (Def_Id))
14252 or else (Is_Class_Wide_Type (Etype (Def_Id))
14253 and then
14254 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
14255 then
14256 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
14257 Error_Msg_N
14258 ("'C'P'P constructor must be defined in the scope of "
14259 & "its returned type", Arg1);
14260 end if;
14262 if Arg_Count >= 2 then
14263 Set_Imported (Def_Id);
14264 Set_Is_Public (Def_Id);
14265 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
14266 end if;
14268 Set_Has_Completion (Def_Id);
14269 Set_Is_Constructor (Def_Id);
14270 Set_Convention (Def_Id, Convention_CPP);
14272 -- Imported C++ constructors are not dispatching primitives
14273 -- because in C++ they don't have a dispatch table slot.
14274 -- However, in Ada the constructor has the profile of a
14275 -- function that returns a tagged type and therefore it has
14276 -- been treated as a primitive operation during semantic
14277 -- analysis. We now remove it from the list of primitive
14278 -- operations of the type.
14280 if Is_Tagged_Type (Etype (Def_Id))
14281 and then not Is_Class_Wide_Type (Etype (Def_Id))
14282 and then Is_Dispatching_Operation (Def_Id)
14283 then
14284 Tag_Typ := Etype (Def_Id);
14286 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
14287 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
14288 Next_Elmt (Elmt);
14289 end loop;
14291 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
14292 Set_Is_Dispatching_Operation (Def_Id, False);
14293 end if;
14295 -- For backward compatibility, if the constructor returns a
14296 -- class wide type, and we internally change the return type to
14297 -- the corresponding root type.
14299 if Is_Class_Wide_Type (Etype (Def_Id)) then
14300 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
14301 end if;
14302 else
14303 Error_Pragma_Arg
14304 ("pragma% requires function returning a 'C'P'P_Class type",
14305 Arg1);
14306 end if;
14307 end CPP_Constructor;
14309 -----------------
14310 -- CPP_Virtual --
14311 -----------------
14313 when Pragma_CPP_Virtual =>
14314 GNAT_Pragma;
14316 if Warn_On_Obsolescent_Feature then
14317 Error_Msg_N
14318 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
14319 & "effect?j?", N);
14320 end if;
14322 ----------------
14323 -- CPP_Vtable --
14324 ----------------
14326 when Pragma_CPP_Vtable =>
14327 GNAT_Pragma;
14329 if Warn_On_Obsolescent_Feature then
14330 Error_Msg_N
14331 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
14332 & "effect?j?", N);
14333 end if;
14335 ---------
14336 -- CPU --
14337 ---------
14339 -- pragma CPU (EXPRESSION);
14341 when Pragma_CPU => CPU : declare
14342 P : constant Node_Id := Parent (N);
14343 Arg : Node_Id;
14344 Ent : Entity_Id;
14346 begin
14347 Ada_2012_Pragma;
14348 Check_No_Identifiers;
14349 Check_Arg_Count (1);
14351 -- Subprogram case
14353 if Nkind (P) = N_Subprogram_Body then
14354 Check_In_Main_Program;
14356 Arg := Get_Pragma_Arg (Arg1);
14357 Analyze_And_Resolve (Arg, Any_Integer);
14359 Ent := Defining_Unit_Name (Specification (P));
14361 if Nkind (Ent) = N_Defining_Program_Unit_Name then
14362 Ent := Defining_Identifier (Ent);
14363 end if;
14365 -- Must be static
14367 if not Is_OK_Static_Expression (Arg) then
14368 Flag_Non_Static_Expr
14369 ("main subprogram affinity is not static!", Arg);
14370 raise Pragma_Exit;
14372 -- If constraint error, then we already signalled an error
14374 elsif Raises_Constraint_Error (Arg) then
14375 null;
14377 -- Otherwise check in range
14379 else
14380 declare
14381 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
14382 -- This is the entity System.Multiprocessors.CPU_Range;
14384 Val : constant Uint := Expr_Value (Arg);
14386 begin
14387 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
14388 or else
14389 Val > Expr_Value (Type_High_Bound (CPU_Id))
14390 then
14391 Error_Pragma_Arg
14392 ("main subprogram CPU is out of range", Arg1);
14393 end if;
14394 end;
14395 end if;
14397 Set_Main_CPU
14398 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
14400 -- Task case
14402 elsif Nkind (P) = N_Task_Definition then
14403 Arg := Get_Pragma_Arg (Arg1);
14404 Ent := Defining_Identifier (Parent (P));
14406 -- The expression must be analyzed in the special manner
14407 -- described in "Handling of Default and Per-Object
14408 -- Expressions" in sem.ads.
14410 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
14412 -- Anything else is incorrect
14414 else
14415 Pragma_Misplaced;
14416 end if;
14418 -- Check duplicate pragma before we chain the pragma in the Rep
14419 -- Item chain of Ent.
14421 Check_Duplicate_Pragma (Ent);
14422 Record_Rep_Item (Ent, N);
14423 end CPU;
14425 --------------------
14426 -- Deadline_Floor --
14427 --------------------
14429 -- pragma Deadline_Floor (time_span_EXPRESSION);
14431 when Pragma_Deadline_Floor => Deadline_Floor : declare
14432 P : constant Node_Id := Parent (N);
14433 Arg : Node_Id;
14434 Ent : Entity_Id;
14436 begin
14437 GNAT_Pragma;
14438 Check_No_Identifiers;
14439 Check_Arg_Count (1);
14441 Arg := Get_Pragma_Arg (Arg1);
14443 -- The expression must be analyzed in the special manner described
14444 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
14446 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
14448 -- Only protected types allowed
14450 if Nkind (P) /= N_Protected_Definition then
14451 Pragma_Misplaced;
14453 else
14454 Ent := Defining_Identifier (Parent (P));
14456 -- Check duplicate pragma before we chain the pragma in the Rep
14457 -- Item chain of Ent.
14459 Check_Duplicate_Pragma (Ent);
14460 Record_Rep_Item (Ent, N);
14461 end if;
14462 end Deadline_Floor;
14464 -----------
14465 -- Debug --
14466 -----------
14468 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
14470 when Pragma_Debug => Debug : declare
14471 Cond : Node_Id;
14472 Call : Node_Id;
14474 begin
14475 GNAT_Pragma;
14477 -- The condition for executing the call is that the expander
14478 -- is active and that we are not ignoring this debug pragma.
14480 Cond :=
14481 New_Occurrence_Of
14482 (Boolean_Literals
14483 (Expander_Active and then not Is_Ignored (N)),
14484 Loc);
14486 if not Is_Ignored (N) then
14487 Set_SCO_Pragma_Enabled (Loc);
14488 end if;
14490 if Arg_Count = 2 then
14491 Cond :=
14492 Make_And_Then (Loc,
14493 Left_Opnd => Relocate_Node (Cond),
14494 Right_Opnd => Get_Pragma_Arg (Arg1));
14495 Call := Get_Pragma_Arg (Arg2);
14496 else
14497 Call := Get_Pragma_Arg (Arg1);
14498 end if;
14500 if Nkind_In (Call, N_Expanded_Name,
14501 N_Function_Call,
14502 N_Identifier,
14503 N_Indexed_Component,
14504 N_Selected_Component)
14505 then
14506 -- If this pragma Debug comes from source, its argument was
14507 -- parsed as a name form (which is syntactically identical).
14508 -- In a generic context a parameterless call will be left as
14509 -- an expanded name (if global) or selected_component if local.
14510 -- Change it to a procedure call statement now.
14512 Change_Name_To_Procedure_Call_Statement (Call);
14514 elsif Nkind (Call) = N_Procedure_Call_Statement then
14516 -- Already in the form of a procedure call statement: nothing
14517 -- to do (could happen in case of an internally generated
14518 -- pragma Debug).
14520 null;
14522 else
14523 -- All other cases: diagnose error
14525 Error_Msg
14526 ("argument of pragma ""Debug"" is not procedure call",
14527 Sloc (Call));
14528 return;
14529 end if;
14531 -- Rewrite into a conditional with an appropriate condition. We
14532 -- wrap the procedure call in a block so that overhead from e.g.
14533 -- use of the secondary stack does not generate execution overhead
14534 -- for suppressed conditions.
14536 -- Normally the analysis that follows will freeze the subprogram
14537 -- being called. However, if the call is to a null procedure,
14538 -- we want to freeze it before creating the block, because the
14539 -- analysis that follows may be done with expansion disabled, in
14540 -- which case the body will not be generated, leading to spurious
14541 -- errors.
14543 if Nkind (Call) = N_Procedure_Call_Statement
14544 and then Is_Entity_Name (Name (Call))
14545 then
14546 Analyze (Name (Call));
14547 Freeze_Before (N, Entity (Name (Call)));
14548 end if;
14550 Rewrite (N,
14551 Make_Implicit_If_Statement (N,
14552 Condition => Cond,
14553 Then_Statements => New_List (
14554 Make_Block_Statement (Loc,
14555 Handled_Statement_Sequence =>
14556 Make_Handled_Sequence_Of_Statements (Loc,
14557 Statements => New_List (Relocate_Node (Call)))))));
14558 Analyze (N);
14560 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
14561 -- after analysis of the normally rewritten node, to capture all
14562 -- references to entities, which avoids issuing wrong warnings
14563 -- about unused entities.
14565 if GNATprove_Mode then
14566 Rewrite (N, Make_Null_Statement (Loc));
14567 end if;
14568 end Debug;
14570 ------------------
14571 -- Debug_Policy --
14572 ------------------
14574 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
14576 when Pragma_Debug_Policy =>
14577 GNAT_Pragma;
14578 Check_Arg_Count (1);
14579 Check_No_Identifiers;
14580 Check_Arg_Is_Identifier (Arg1);
14582 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
14583 -- rewrite it that way, and let the rest of the checking come
14584 -- from analyzing the rewritten pragma.
14586 Rewrite (N,
14587 Make_Pragma (Loc,
14588 Chars => Name_Check_Policy,
14589 Pragma_Argument_Associations => New_List (
14590 Make_Pragma_Argument_Association (Loc,
14591 Expression => Make_Identifier (Loc, Name_Debug)),
14593 Make_Pragma_Argument_Association (Loc,
14594 Expression => Get_Pragma_Arg (Arg1)))));
14595 Analyze (N);
14597 -------------------------------
14598 -- Default_Initial_Condition --
14599 -------------------------------
14601 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
14603 when Pragma_Default_Initial_Condition => DIC : declare
14604 Discard : Boolean;
14605 Stmt : Node_Id;
14606 Typ : Entity_Id;
14608 begin
14609 GNAT_Pragma;
14610 Check_No_Identifiers;
14611 Check_At_Most_N_Arguments (1);
14613 Typ := Empty;
14614 Stmt := Prev (N);
14615 while Present (Stmt) loop
14617 -- Skip prior pragmas, but check for duplicates
14619 if Nkind (Stmt) = N_Pragma then
14620 if Pragma_Name (Stmt) = Pname then
14621 Duplication_Error
14622 (Prag => N,
14623 Prev => Stmt);
14624 raise Pragma_Exit;
14625 end if;
14627 -- Skip internally generated code. Note that derived type
14628 -- declarations of untagged types with discriminants are
14629 -- rewritten as private type declarations.
14631 elsif not Comes_From_Source (Stmt)
14632 and then Nkind (Stmt) /= N_Private_Type_Declaration
14633 then
14634 null;
14636 -- The associated private type [extension] has been found, stop
14637 -- the search.
14639 elsif Nkind_In (Stmt, N_Private_Extension_Declaration,
14640 N_Private_Type_Declaration)
14641 then
14642 Typ := Defining_Entity (Stmt);
14643 exit;
14645 -- The pragma does not apply to a legal construct, issue an
14646 -- error and stop the analysis.
14648 else
14649 Pragma_Misplaced;
14650 return;
14651 end if;
14653 Stmt := Prev (Stmt);
14654 end loop;
14656 -- The pragma does not apply to a legal construct, issue an error
14657 -- and stop the analysis.
14659 if No (Typ) then
14660 Pragma_Misplaced;
14661 return;
14662 end if;
14664 -- A pragma that applies to a Ghost entity becomes Ghost for the
14665 -- purposes of legality checks and removal of ignored Ghost code.
14667 Mark_Ghost_Pragma (N, Typ);
14669 -- The pragma signals that the type defines its own DIC assertion
14670 -- expression.
14672 Set_Has_Own_DIC (Typ);
14674 -- Chain the pragma on the rep item chain for further processing
14676 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
14678 -- Create the declaration of the procedure which verifies the
14679 -- assertion expression of pragma DIC at runtime.
14681 Build_DIC_Procedure_Declaration (Typ);
14682 end DIC;
14684 ----------------------------------
14685 -- Default_Scalar_Storage_Order --
14686 ----------------------------------
14688 -- pragma Default_Scalar_Storage_Order
14689 -- (High_Order_First | Low_Order_First);
14691 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
14692 Default : Character;
14694 begin
14695 GNAT_Pragma;
14696 Check_Arg_Count (1);
14698 -- Default_Scalar_Storage_Order can appear as a configuration
14699 -- pragma, or in a declarative part of a package spec.
14701 if not Is_Configuration_Pragma then
14702 Check_Is_In_Decl_Part_Or_Package_Spec;
14703 end if;
14705 Check_No_Identifiers;
14706 Check_Arg_Is_One_Of
14707 (Arg1, Name_High_Order_First, Name_Low_Order_First);
14708 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
14709 Default := Fold_Upper (Name_Buffer (1));
14711 if not Support_Nondefault_SSO_On_Target
14712 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
14713 then
14714 if Warn_On_Unrecognized_Pragma then
14715 Error_Msg_N
14716 ("non-default Scalar_Storage_Order not supported "
14717 & "on target?g?", N);
14718 Error_Msg_N
14719 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
14720 end if;
14722 -- Here set the specified default
14724 else
14725 Opt.Default_SSO := Default;
14726 end if;
14727 end DSSO;
14729 --------------------------
14730 -- Default_Storage_Pool --
14731 --------------------------
14733 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
14735 when Pragma_Default_Storage_Pool => Default_Storage_Pool : declare
14736 Pool : Node_Id;
14738 begin
14739 Ada_2012_Pragma;
14740 Check_Arg_Count (1);
14742 -- Default_Storage_Pool can appear as a configuration pragma, or
14743 -- in a declarative part of a package spec.
14745 if not Is_Configuration_Pragma then
14746 Check_Is_In_Decl_Part_Or_Package_Spec;
14747 end if;
14749 if From_Aspect_Specification (N) then
14750 declare
14751 E : constant Entity_Id := Entity (Corresponding_Aspect (N));
14752 begin
14753 if not In_Open_Scopes (E) then
14754 Error_Msg_N
14755 ("aspect must apply to package or subprogram", N);
14756 end if;
14757 end;
14758 end if;
14760 if Present (Arg1) then
14761 Pool := Get_Pragma_Arg (Arg1);
14763 -- Case of Default_Storage_Pool (null);
14765 if Nkind (Pool) = N_Null then
14766 Analyze (Pool);
14768 -- This is an odd case, this is not really an expression,
14769 -- so we don't have a type for it. So just set the type to
14770 -- Empty.
14772 Set_Etype (Pool, Empty);
14774 -- Case of Default_Storage_Pool (storage_pool_NAME);
14776 else
14777 -- If it's a configuration pragma, then the only allowed
14778 -- argument is "null".
14780 if Is_Configuration_Pragma then
14781 Error_Pragma_Arg ("NULL expected", Arg1);
14782 end if;
14784 -- The expected type for a non-"null" argument is
14785 -- Root_Storage_Pool'Class, and the pool must be a variable.
14787 Analyze_And_Resolve
14788 (Pool, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
14790 if Is_Variable (Pool) then
14792 -- A pragma that applies to a Ghost entity becomes Ghost
14793 -- for the purposes of legality checks and removal of
14794 -- ignored Ghost code.
14796 Mark_Ghost_Pragma (N, Entity (Pool));
14798 else
14799 Error_Pragma_Arg
14800 ("default storage pool must be a variable", Arg1);
14801 end if;
14802 end if;
14804 -- Record the pool name (or null). Freeze.Freeze_Entity for an
14805 -- access type will use this information to set the appropriate
14806 -- attributes of the access type. If the pragma appears in a
14807 -- generic unit it is ignored, given that it may refer to a
14808 -- local entity.
14810 if not Inside_A_Generic then
14811 Default_Pool := Pool;
14812 end if;
14813 end if;
14814 end Default_Storage_Pool;
14816 -------------
14817 -- Depends --
14818 -------------
14820 -- pragma Depends (DEPENDENCY_RELATION);
14822 -- DEPENDENCY_RELATION ::=
14823 -- null
14824 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
14826 -- DEPENDENCY_CLAUSE ::=
14827 -- OUTPUT_LIST =>[+] INPUT_LIST
14828 -- | NULL_DEPENDENCY_CLAUSE
14830 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
14832 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
14834 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
14836 -- OUTPUT ::= NAME | FUNCTION_RESULT
14837 -- INPUT ::= NAME
14839 -- where FUNCTION_RESULT is a function Result attribute_reference
14841 -- Characteristics:
14843 -- * Analysis - The annotation undergoes initial checks to verify
14844 -- the legal placement and context. Secondary checks fully analyze
14845 -- the dependency clauses in:
14847 -- Analyze_Depends_In_Decl_Part
14849 -- * Expansion - None.
14851 -- * Template - The annotation utilizes the generic template of the
14852 -- related subprogram [body] when it is:
14854 -- aspect on subprogram declaration
14855 -- aspect on stand-alone subprogram body
14856 -- pragma on stand-alone subprogram body
14858 -- The annotation must prepare its own template when it is:
14860 -- pragma on subprogram declaration
14862 -- * Globals - Capture of global references must occur after full
14863 -- analysis.
14865 -- * Instance - The annotation is instantiated automatically when
14866 -- the related generic subprogram [body] is instantiated except for
14867 -- the "pragma on subprogram declaration" case. In that scenario
14868 -- the annotation must instantiate itself.
14870 when Pragma_Depends => Depends : declare
14871 Legal : Boolean;
14872 Spec_Id : Entity_Id;
14873 Subp_Decl : Node_Id;
14875 begin
14876 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
14878 if Legal then
14880 -- Chain the pragma on the contract for further processing by
14881 -- Analyze_Depends_In_Decl_Part.
14883 Add_Contract_Item (N, Spec_Id);
14885 -- Fully analyze the pragma when it appears inside an entry
14886 -- or subprogram body because it cannot benefit from forward
14887 -- references.
14889 if Nkind_In (Subp_Decl, N_Entry_Body,
14890 N_Subprogram_Body,
14891 N_Subprogram_Body_Stub)
14892 then
14893 -- The legality checks of pragmas Depends and Global are
14894 -- affected by the SPARK mode in effect and the volatility
14895 -- of the context. In addition these two pragmas are subject
14896 -- to an inherent order:
14898 -- 1) Global
14899 -- 2) Depends
14901 -- Analyze all these pragmas in the order outlined above
14903 Analyze_If_Present (Pragma_SPARK_Mode);
14904 Analyze_If_Present (Pragma_Volatile_Function);
14905 Analyze_If_Present (Pragma_Global);
14906 Analyze_Depends_In_Decl_Part (N);
14907 end if;
14908 end if;
14909 end Depends;
14911 ---------------------
14912 -- Detect_Blocking --
14913 ---------------------
14915 -- pragma Detect_Blocking;
14917 when Pragma_Detect_Blocking =>
14918 Ada_2005_Pragma;
14919 Check_Arg_Count (0);
14920 Check_Valid_Configuration_Pragma;
14921 Detect_Blocking := True;
14923 ------------------------------------
14924 -- Disable_Atomic_Synchronization --
14925 ------------------------------------
14927 -- pragma Disable_Atomic_Synchronization [(Entity)];
14929 when Pragma_Disable_Atomic_Synchronization =>
14930 GNAT_Pragma;
14931 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
14933 -------------------
14934 -- Discard_Names --
14935 -------------------
14937 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
14939 when Pragma_Discard_Names => Discard_Names : declare
14940 E : Entity_Id;
14941 E_Id : Node_Id;
14943 begin
14944 Check_Ada_83_Warning;
14946 -- Deal with configuration pragma case
14948 if Arg_Count = 0 and then Is_Configuration_Pragma then
14949 Global_Discard_Names := True;
14950 return;
14952 -- Otherwise, check correct appropriate context
14954 else
14955 Check_Is_In_Decl_Part_Or_Package_Spec;
14957 if Arg_Count = 0 then
14959 -- If there is no parameter, then from now on this pragma
14960 -- applies to any enumeration, exception or tagged type
14961 -- defined in the current declarative part, and recursively
14962 -- to any nested scope.
14964 Set_Discard_Names (Current_Scope);
14965 return;
14967 else
14968 Check_Arg_Count (1);
14969 Check_Optional_Identifier (Arg1, Name_On);
14970 Check_Arg_Is_Local_Name (Arg1);
14972 E_Id := Get_Pragma_Arg (Arg1);
14974 if Etype (E_Id) = Any_Type then
14975 return;
14976 end if;
14978 E := Entity (E_Id);
14980 -- A pragma that applies to a Ghost entity becomes Ghost for
14981 -- the purposes of legality checks and removal of ignored
14982 -- Ghost code.
14984 Mark_Ghost_Pragma (N, E);
14986 if (Is_First_Subtype (E)
14987 and then
14988 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
14989 or else Ekind (E) = E_Exception
14990 then
14991 Set_Discard_Names (E);
14992 Record_Rep_Item (E, N);
14994 else
14995 Error_Pragma_Arg
14996 ("inappropriate entity for pragma%", Arg1);
14997 end if;
14998 end if;
14999 end if;
15000 end Discard_Names;
15002 ------------------------
15003 -- Dispatching_Domain --
15004 ------------------------
15006 -- pragma Dispatching_Domain (EXPRESSION);
15008 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
15009 P : constant Node_Id := Parent (N);
15010 Arg : Node_Id;
15011 Ent : Entity_Id;
15013 begin
15014 Ada_2012_Pragma;
15015 Check_No_Identifiers;
15016 Check_Arg_Count (1);
15018 -- This pragma is born obsolete, but not the aspect
15020 if not From_Aspect_Specification (N) then
15021 Check_Restriction
15022 (No_Obsolescent_Features, Pragma_Identifier (N));
15023 end if;
15025 if Nkind (P) = N_Task_Definition then
15026 Arg := Get_Pragma_Arg (Arg1);
15027 Ent := Defining_Identifier (Parent (P));
15029 -- A pragma that applies to a Ghost entity becomes Ghost for
15030 -- the purposes of legality checks and removal of ignored Ghost
15031 -- code.
15033 Mark_Ghost_Pragma (N, Ent);
15035 -- The expression must be analyzed in the special manner
15036 -- described in "Handling of Default and Per-Object
15037 -- Expressions" in sem.ads.
15039 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
15041 -- Check duplicate pragma before we chain the pragma in the Rep
15042 -- Item chain of Ent.
15044 Check_Duplicate_Pragma (Ent);
15045 Record_Rep_Item (Ent, N);
15047 -- Anything else is incorrect
15049 else
15050 Pragma_Misplaced;
15051 end if;
15052 end Dispatching_Domain;
15054 ---------------
15055 -- Elaborate --
15056 ---------------
15058 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
15060 when Pragma_Elaborate => Elaborate : declare
15061 Arg : Node_Id;
15062 Citem : Node_Id;
15064 begin
15065 -- Pragma must be in context items list of a compilation unit
15067 if not Is_In_Context_Clause then
15068 Pragma_Misplaced;
15069 end if;
15071 -- Must be at least one argument
15073 if Arg_Count = 0 then
15074 Error_Pragma ("pragma% requires at least one argument");
15075 end if;
15077 -- In Ada 83 mode, there can be no items following it in the
15078 -- context list except other pragmas and implicit with clauses
15079 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
15080 -- placement rule does not apply.
15082 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
15083 Citem := Next (N);
15084 while Present (Citem) loop
15085 if Nkind (Citem) = N_Pragma
15086 or else (Nkind (Citem) = N_With_Clause
15087 and then Implicit_With (Citem))
15088 then
15089 null;
15090 else
15091 Error_Pragma
15092 ("(Ada 83) pragma% must be at end of context clause");
15093 end if;
15095 Next (Citem);
15096 end loop;
15097 end if;
15099 -- Finally, the arguments must all be units mentioned in a with
15100 -- clause in the same context clause. Note we already checked (in
15101 -- Par.Prag) that the arguments are all identifiers or selected
15102 -- components.
15104 Arg := Arg1;
15105 Outer : while Present (Arg) loop
15106 Citem := First (List_Containing (N));
15107 Inner : while Citem /= N loop
15108 if Nkind (Citem) = N_With_Clause
15109 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
15110 then
15111 Set_Elaborate_Present (Citem, True);
15112 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
15114 -- With the pragma present, elaboration calls on
15115 -- subprograms from the named unit need no further
15116 -- checks, as long as the pragma appears in the current
15117 -- compilation unit. If the pragma appears in some unit
15118 -- in the context, there might still be a need for an
15119 -- Elaborate_All_Desirable from the current compilation
15120 -- to the named unit, so we keep the check enabled. This
15121 -- does not apply in SPARK mode, where we allow pragma
15122 -- Elaborate, but we don't trust it to be right so we
15123 -- will still insist on the Elaborate_All.
15125 if Legacy_Elaboration_Checks
15126 and then In_Extended_Main_Source_Unit (N)
15127 and then SPARK_Mode /= On
15128 then
15129 Set_Suppress_Elaboration_Warnings
15130 (Entity (Name (Citem)));
15131 end if;
15133 exit Inner;
15134 end if;
15136 Next (Citem);
15137 end loop Inner;
15139 if Citem = N then
15140 Error_Pragma_Arg
15141 ("argument of pragma% is not withed unit", Arg);
15142 end if;
15144 Next (Arg);
15145 end loop Outer;
15146 end Elaborate;
15148 -------------------
15149 -- Elaborate_All --
15150 -------------------
15152 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
15154 when Pragma_Elaborate_All => Elaborate_All : declare
15155 Arg : Node_Id;
15156 Citem : Node_Id;
15158 begin
15159 Check_Ada_83_Warning;
15161 -- Pragma must be in context items list of a compilation unit
15163 if not Is_In_Context_Clause then
15164 Pragma_Misplaced;
15165 end if;
15167 -- Must be at least one argument
15169 if Arg_Count = 0 then
15170 Error_Pragma ("pragma% requires at least one argument");
15171 end if;
15173 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
15174 -- have to appear at the end of the context clause, but may
15175 -- appear mixed in with other items, even in Ada 83 mode.
15177 -- Final check: the arguments must all be units mentioned in
15178 -- a with clause in the same context clause. Note that we
15179 -- already checked (in Par.Prag) that all the arguments are
15180 -- either identifiers or selected components.
15182 Arg := Arg1;
15183 Outr : while Present (Arg) loop
15184 Citem := First (List_Containing (N));
15185 Innr : while Citem /= N loop
15186 if Nkind (Citem) = N_With_Clause
15187 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
15188 then
15189 Set_Elaborate_All_Present (Citem, True);
15190 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
15192 -- Suppress warnings and elaboration checks on the named
15193 -- unit if the pragma is in the current compilation, as
15194 -- for pragma Elaborate.
15196 if Legacy_Elaboration_Checks
15197 and then In_Extended_Main_Source_Unit (N)
15198 then
15199 Set_Suppress_Elaboration_Warnings
15200 (Entity (Name (Citem)));
15201 end if;
15203 exit Innr;
15204 end if;
15206 Next (Citem);
15207 end loop Innr;
15209 if Citem = N then
15210 Set_Error_Posted (N);
15211 Error_Pragma_Arg
15212 ("argument of pragma% is not withed unit", Arg);
15213 end if;
15215 Next (Arg);
15216 end loop Outr;
15217 end Elaborate_All;
15219 --------------------
15220 -- Elaborate_Body --
15221 --------------------
15223 -- pragma Elaborate_Body [( library_unit_NAME )];
15225 when Pragma_Elaborate_Body => Elaborate_Body : declare
15226 Cunit_Node : Node_Id;
15227 Cunit_Ent : Entity_Id;
15229 begin
15230 Check_Ada_83_Warning;
15231 Check_Valid_Library_Unit_Pragma;
15233 if Nkind (N) = N_Null_Statement then
15234 return;
15235 end if;
15237 Cunit_Node := Cunit (Current_Sem_Unit);
15238 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15240 -- A pragma that applies to a Ghost entity becomes Ghost for the
15241 -- purposes of legality checks and removal of ignored Ghost code.
15243 Mark_Ghost_Pragma (N, Cunit_Ent);
15245 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
15246 N_Subprogram_Body)
15247 then
15248 Error_Pragma ("pragma% must refer to a spec, not a body");
15249 else
15250 Set_Body_Required (Cunit_Node);
15251 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
15253 -- If we are in dynamic elaboration mode, then we suppress
15254 -- elaboration warnings for the unit, since it is definitely
15255 -- fine NOT to do dynamic checks at the first level (and such
15256 -- checks will be suppressed because no elaboration boolean
15257 -- is created for Elaborate_Body packages).
15259 -- But in the static model of elaboration, Elaborate_Body is
15260 -- definitely NOT good enough to ensure elaboration safety on
15261 -- its own, since the body may WITH other units that are not
15262 -- safe from an elaboration point of view, so a client must
15263 -- still do an Elaborate_All on such units.
15265 -- Debug flag -gnatdD restores the old behavior of 3.13, where
15266 -- Elaborate_Body always suppressed elab warnings.
15268 if Legacy_Elaboration_Checks
15269 and then (Dynamic_Elaboration_Checks or Debug_Flag_DD)
15270 then
15271 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
15272 end if;
15273 end if;
15274 end Elaborate_Body;
15276 ------------------------
15277 -- Elaboration_Checks --
15278 ------------------------
15280 -- pragma Elaboration_Checks (Static | Dynamic);
15282 when Pragma_Elaboration_Checks => Elaboration_Checks : declare
15283 procedure Check_Duplicate_Elaboration_Checks_Pragma;
15284 -- Emit an error if the current context list already contains
15285 -- a previous Elaboration_Checks pragma. This routine raises
15286 -- Pragma_Exit if a duplicate is found.
15288 procedure Ignore_Elaboration_Checks_Pragma;
15289 -- Warn that the effects of the pragma are ignored. This routine
15290 -- raises Pragma_Exit.
15292 -----------------------------------------------
15293 -- Check_Duplicate_Elaboration_Checks_Pragma --
15294 -----------------------------------------------
15296 procedure Check_Duplicate_Elaboration_Checks_Pragma is
15297 Item : Node_Id;
15299 begin
15300 Item := Prev (N);
15301 while Present (Item) loop
15302 if Nkind (Item) = N_Pragma
15303 and then Pragma_Name (Item) = Name_Elaboration_Checks
15304 then
15305 Duplication_Error
15306 (Prag => N,
15307 Prev => Item);
15308 raise Pragma_Exit;
15309 end if;
15311 Prev (Item);
15312 end loop;
15313 end Check_Duplicate_Elaboration_Checks_Pragma;
15315 --------------------------------------
15316 -- Ignore_Elaboration_Checks_Pragma --
15317 --------------------------------------
15319 procedure Ignore_Elaboration_Checks_Pragma is
15320 begin
15321 Error_Msg_Name_1 := Pname;
15322 Error_Msg_N ("??effects of pragma % are ignored", N);
15323 Error_Msg_N
15324 ("\place pragma on initial declaration of library unit", N);
15326 raise Pragma_Exit;
15327 end Ignore_Elaboration_Checks_Pragma;
15329 -- Local variables
15331 Context : constant Node_Id := Parent (N);
15332 Unt : Node_Id;
15334 -- Start of processing for Elaboration_Checks
15336 begin
15337 GNAT_Pragma;
15338 Check_Arg_Count (1);
15339 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
15341 -- The pragma appears in a configuration file
15343 if No (Context) then
15344 Check_Valid_Configuration_Pragma;
15345 Check_Duplicate_Elaboration_Checks_Pragma;
15347 -- The pragma acts as a configuration pragma in a compilation unit
15349 -- pragma Elaboration_Checks (...);
15350 -- package Pack is ...;
15352 elsif Nkind (Context) = N_Compilation_Unit
15353 and then List_Containing (N) = Context_Items (Context)
15354 then
15355 Check_Valid_Configuration_Pragma;
15356 Check_Duplicate_Elaboration_Checks_Pragma;
15358 Unt := Unit (Context);
15360 -- The pragma must appear on the initial declaration of a unit.
15361 -- If this is not the case, warn that the effects of the pragma
15362 -- are ignored.
15364 if Nkind (Unt) = N_Package_Body then
15365 Ignore_Elaboration_Checks_Pragma;
15367 -- Check the Acts_As_Spec flag of the compilation units itself
15368 -- to determine whether the subprogram body completes since it
15369 -- has not been analyzed yet. This is safe because compilation
15370 -- units are not overloadable.
15372 elsif Nkind (Unt) = N_Subprogram_Body
15373 and then not Acts_As_Spec (Context)
15374 then
15375 Ignore_Elaboration_Checks_Pragma;
15377 elsif Nkind (Unt) = N_Subunit then
15378 Ignore_Elaboration_Checks_Pragma;
15379 end if;
15381 -- Otherwise the pragma does not appear at the configuration level
15382 -- and is illegal.
15384 else
15385 Pragma_Misplaced;
15386 end if;
15388 -- At this point the pragma is not a duplicate, and appears in the
15389 -- proper context. Set the elaboration model in effect.
15391 Dynamic_Elaboration_Checks :=
15392 Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic;
15393 end Elaboration_Checks;
15395 ---------------
15396 -- Eliminate --
15397 ---------------
15399 -- pragma Eliminate (
15400 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
15401 -- [Entity =>] IDENTIFIER |
15402 -- SELECTED_COMPONENT |
15403 -- STRING_LITERAL]
15404 -- [, Source_Location => SOURCE_TRACE]);
15406 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
15407 -- SOURCE_TRACE ::= STRING_LITERAL
15409 when Pragma_Eliminate => Eliminate : declare
15410 Args : Args_List (1 .. 5);
15411 Names : constant Name_List (1 .. 5) := (
15412 Name_Unit_Name,
15413 Name_Entity,
15414 Name_Parameter_Types,
15415 Name_Result_Type,
15416 Name_Source_Location);
15418 -- Note : Parameter_Types and Result_Type are leftovers from
15419 -- prior implementations of the pragma. They are not generated
15420 -- by the gnatelim tool, and play no role in selecting which
15421 -- of a set of overloaded names is chosen for elimination.
15423 Unit_Name : Node_Id renames Args (1);
15424 Entity : Node_Id renames Args (2);
15425 Parameter_Types : Node_Id renames Args (3);
15426 Result_Type : Node_Id renames Args (4);
15427 Source_Location : Node_Id renames Args (5);
15429 begin
15430 GNAT_Pragma;
15431 Check_Valid_Configuration_Pragma;
15432 Gather_Associations (Names, Args);
15434 if No (Unit_Name) then
15435 Error_Pragma ("missing Unit_Name argument for pragma%");
15436 end if;
15438 if No (Entity)
15439 and then (Present (Parameter_Types)
15440 or else
15441 Present (Result_Type)
15442 or else
15443 Present (Source_Location))
15444 then
15445 Error_Pragma ("missing Entity argument for pragma%");
15446 end if;
15448 if (Present (Parameter_Types)
15449 or else
15450 Present (Result_Type))
15451 and then
15452 Present (Source_Location)
15453 then
15454 Error_Pragma
15455 ("parameter profile and source location cannot be used "
15456 & "together in pragma%");
15457 end if;
15459 Process_Eliminate_Pragma
15461 Unit_Name,
15462 Entity,
15463 Parameter_Types,
15464 Result_Type,
15465 Source_Location);
15466 end Eliminate;
15468 -----------------------------------
15469 -- Enable_Atomic_Synchronization --
15470 -----------------------------------
15472 -- pragma Enable_Atomic_Synchronization [(Entity)];
15474 when Pragma_Enable_Atomic_Synchronization =>
15475 GNAT_Pragma;
15476 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
15478 ------------
15479 -- Export --
15480 ------------
15482 -- pragma Export (
15483 -- [ Convention =>] convention_IDENTIFIER,
15484 -- [ Entity =>] LOCAL_NAME
15485 -- [, [External_Name =>] static_string_EXPRESSION ]
15486 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15488 when Pragma_Export => Export : declare
15489 C : Convention_Id;
15490 Def_Id : Entity_Id;
15492 pragma Warnings (Off, C);
15494 begin
15495 Check_Ada_83_Warning;
15496 Check_Arg_Order
15497 ((Name_Convention,
15498 Name_Entity,
15499 Name_External_Name,
15500 Name_Link_Name));
15502 Check_At_Least_N_Arguments (2);
15503 Check_At_Most_N_Arguments (4);
15505 -- In Relaxed_RM_Semantics, support old Ada 83 style:
15506 -- pragma Export (Entity, "external name");
15508 if Relaxed_RM_Semantics
15509 and then Arg_Count = 2
15510 and then Nkind (Expression (Arg2)) = N_String_Literal
15511 then
15512 C := Convention_C;
15513 Def_Id := Get_Pragma_Arg (Arg1);
15514 Analyze (Def_Id);
15516 if not Is_Entity_Name (Def_Id) then
15517 Error_Pragma_Arg ("entity name required", Arg1);
15518 end if;
15520 Def_Id := Entity (Def_Id);
15521 Set_Exported (Def_Id, Arg1);
15523 else
15524 Process_Convention (C, Def_Id);
15526 -- A pragma that applies to a Ghost entity becomes Ghost for
15527 -- the purposes of legality checks and removal of ignored Ghost
15528 -- code.
15530 Mark_Ghost_Pragma (N, Def_Id);
15532 if Ekind (Def_Id) /= E_Constant then
15533 Note_Possible_Modification
15534 (Get_Pragma_Arg (Arg2), Sure => False);
15535 end if;
15537 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
15538 Set_Exported (Def_Id, Arg2);
15539 end if;
15541 -- If the entity is a deferred constant, propagate the information
15542 -- to the full view, because gigi elaborates the full view only.
15544 if Ekind (Def_Id) = E_Constant
15545 and then Present (Full_View (Def_Id))
15546 then
15547 declare
15548 Id2 : constant Entity_Id := Full_View (Def_Id);
15549 begin
15550 Set_Is_Exported (Id2, Is_Exported (Def_Id));
15551 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
15552 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
15553 end;
15554 end if;
15555 end Export;
15557 ---------------------
15558 -- Export_Function --
15559 ---------------------
15561 -- pragma Export_Function (
15562 -- [Internal =>] LOCAL_NAME
15563 -- [, [External =>] EXTERNAL_SYMBOL]
15564 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15565 -- [, [Result_Type =>] TYPE_DESIGNATOR]
15566 -- [, [Mechanism =>] MECHANISM]
15567 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
15569 -- EXTERNAL_SYMBOL ::=
15570 -- IDENTIFIER
15571 -- | static_string_EXPRESSION
15573 -- PARAMETER_TYPES ::=
15574 -- null
15575 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15577 -- TYPE_DESIGNATOR ::=
15578 -- subtype_NAME
15579 -- | subtype_Name ' Access
15581 -- MECHANISM ::=
15582 -- MECHANISM_NAME
15583 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15585 -- MECHANISM_ASSOCIATION ::=
15586 -- [formal_parameter_NAME =>] MECHANISM_NAME
15588 -- MECHANISM_NAME ::=
15589 -- Value
15590 -- | Reference
15592 when Pragma_Export_Function => Export_Function : declare
15593 Args : Args_List (1 .. 6);
15594 Names : constant Name_List (1 .. 6) := (
15595 Name_Internal,
15596 Name_External,
15597 Name_Parameter_Types,
15598 Name_Result_Type,
15599 Name_Mechanism,
15600 Name_Result_Mechanism);
15602 Internal : Node_Id renames Args (1);
15603 External : Node_Id renames Args (2);
15604 Parameter_Types : Node_Id renames Args (3);
15605 Result_Type : Node_Id renames Args (4);
15606 Mechanism : Node_Id renames Args (5);
15607 Result_Mechanism : Node_Id renames Args (6);
15609 begin
15610 GNAT_Pragma;
15611 Gather_Associations (Names, Args);
15612 Process_Extended_Import_Export_Subprogram_Pragma (
15613 Arg_Internal => Internal,
15614 Arg_External => External,
15615 Arg_Parameter_Types => Parameter_Types,
15616 Arg_Result_Type => Result_Type,
15617 Arg_Mechanism => Mechanism,
15618 Arg_Result_Mechanism => Result_Mechanism);
15619 end Export_Function;
15621 -------------------
15622 -- Export_Object --
15623 -------------------
15625 -- pragma Export_Object (
15626 -- [Internal =>] LOCAL_NAME
15627 -- [, [External =>] EXTERNAL_SYMBOL]
15628 -- [, [Size =>] EXTERNAL_SYMBOL]);
15630 -- EXTERNAL_SYMBOL ::=
15631 -- IDENTIFIER
15632 -- | static_string_EXPRESSION
15634 -- PARAMETER_TYPES ::=
15635 -- null
15636 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15638 -- TYPE_DESIGNATOR ::=
15639 -- subtype_NAME
15640 -- | subtype_Name ' Access
15642 -- MECHANISM ::=
15643 -- MECHANISM_NAME
15644 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15646 -- MECHANISM_ASSOCIATION ::=
15647 -- [formal_parameter_NAME =>] MECHANISM_NAME
15649 -- MECHANISM_NAME ::=
15650 -- Value
15651 -- | Reference
15653 when Pragma_Export_Object => Export_Object : declare
15654 Args : Args_List (1 .. 3);
15655 Names : constant Name_List (1 .. 3) := (
15656 Name_Internal,
15657 Name_External,
15658 Name_Size);
15660 Internal : Node_Id renames Args (1);
15661 External : Node_Id renames Args (2);
15662 Size : Node_Id renames Args (3);
15664 begin
15665 GNAT_Pragma;
15666 Gather_Associations (Names, Args);
15667 Process_Extended_Import_Export_Object_Pragma (
15668 Arg_Internal => Internal,
15669 Arg_External => External,
15670 Arg_Size => Size);
15671 end Export_Object;
15673 ----------------------
15674 -- Export_Procedure --
15675 ----------------------
15677 -- pragma Export_Procedure (
15678 -- [Internal =>] LOCAL_NAME
15679 -- [, [External =>] EXTERNAL_SYMBOL]
15680 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15681 -- [, [Mechanism =>] MECHANISM]);
15683 -- EXTERNAL_SYMBOL ::=
15684 -- IDENTIFIER
15685 -- | static_string_EXPRESSION
15687 -- PARAMETER_TYPES ::=
15688 -- null
15689 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15691 -- TYPE_DESIGNATOR ::=
15692 -- subtype_NAME
15693 -- | subtype_Name ' Access
15695 -- MECHANISM ::=
15696 -- MECHANISM_NAME
15697 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15699 -- MECHANISM_ASSOCIATION ::=
15700 -- [formal_parameter_NAME =>] MECHANISM_NAME
15702 -- MECHANISM_NAME ::=
15703 -- Value
15704 -- | Reference
15706 when Pragma_Export_Procedure => Export_Procedure : declare
15707 Args : Args_List (1 .. 4);
15708 Names : constant Name_List (1 .. 4) := (
15709 Name_Internal,
15710 Name_External,
15711 Name_Parameter_Types,
15712 Name_Mechanism);
15714 Internal : Node_Id renames Args (1);
15715 External : Node_Id renames Args (2);
15716 Parameter_Types : Node_Id renames Args (3);
15717 Mechanism : Node_Id renames Args (4);
15719 begin
15720 GNAT_Pragma;
15721 Gather_Associations (Names, Args);
15722 Process_Extended_Import_Export_Subprogram_Pragma (
15723 Arg_Internal => Internal,
15724 Arg_External => External,
15725 Arg_Parameter_Types => Parameter_Types,
15726 Arg_Mechanism => Mechanism);
15727 end Export_Procedure;
15729 ------------------
15730 -- Export_Value --
15731 ------------------
15733 -- pragma Export_Value (
15734 -- [Value =>] static_integer_EXPRESSION,
15735 -- [Link_Name =>] static_string_EXPRESSION);
15737 when Pragma_Export_Value =>
15738 GNAT_Pragma;
15739 Check_Arg_Order ((Name_Value, Name_Link_Name));
15740 Check_Arg_Count (2);
15742 Check_Optional_Identifier (Arg1, Name_Value);
15743 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
15745 Check_Optional_Identifier (Arg2, Name_Link_Name);
15746 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
15748 -----------------------------
15749 -- Export_Valued_Procedure --
15750 -----------------------------
15752 -- pragma Export_Valued_Procedure (
15753 -- [Internal =>] LOCAL_NAME
15754 -- [, [External =>] EXTERNAL_SYMBOL,]
15755 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15756 -- [, [Mechanism =>] MECHANISM]);
15758 -- EXTERNAL_SYMBOL ::=
15759 -- IDENTIFIER
15760 -- | static_string_EXPRESSION
15762 -- PARAMETER_TYPES ::=
15763 -- null
15764 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15766 -- TYPE_DESIGNATOR ::=
15767 -- subtype_NAME
15768 -- | subtype_Name ' Access
15770 -- MECHANISM ::=
15771 -- MECHANISM_NAME
15772 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15774 -- MECHANISM_ASSOCIATION ::=
15775 -- [formal_parameter_NAME =>] MECHANISM_NAME
15777 -- MECHANISM_NAME ::=
15778 -- Value
15779 -- | Reference
15781 when Pragma_Export_Valued_Procedure =>
15782 Export_Valued_Procedure : declare
15783 Args : Args_List (1 .. 4);
15784 Names : constant Name_List (1 .. 4) := (
15785 Name_Internal,
15786 Name_External,
15787 Name_Parameter_Types,
15788 Name_Mechanism);
15790 Internal : Node_Id renames Args (1);
15791 External : Node_Id renames Args (2);
15792 Parameter_Types : Node_Id renames Args (3);
15793 Mechanism : Node_Id renames Args (4);
15795 begin
15796 GNAT_Pragma;
15797 Gather_Associations (Names, Args);
15798 Process_Extended_Import_Export_Subprogram_Pragma (
15799 Arg_Internal => Internal,
15800 Arg_External => External,
15801 Arg_Parameter_Types => Parameter_Types,
15802 Arg_Mechanism => Mechanism);
15803 end Export_Valued_Procedure;
15805 -------------------
15806 -- Extend_System --
15807 -------------------
15809 -- pragma Extend_System ([Name =>] Identifier);
15811 when Pragma_Extend_System =>
15812 GNAT_Pragma;
15813 Check_Valid_Configuration_Pragma;
15814 Check_Arg_Count (1);
15815 Check_Optional_Identifier (Arg1, Name_Name);
15816 Check_Arg_Is_Identifier (Arg1);
15818 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15820 if Name_Len > 4
15821 and then Name_Buffer (1 .. 4) = "aux_"
15822 then
15823 if Present (System_Extend_Pragma_Arg) then
15824 if Chars (Get_Pragma_Arg (Arg1)) =
15825 Chars (Expression (System_Extend_Pragma_Arg))
15826 then
15827 null;
15828 else
15829 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
15830 Error_Pragma ("pragma% conflicts with that #");
15831 end if;
15833 else
15834 System_Extend_Pragma_Arg := Arg1;
15836 if not GNAT_Mode then
15837 System_Extend_Unit := Arg1;
15838 end if;
15839 end if;
15840 else
15841 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
15842 end if;
15844 ------------------------
15845 -- Extensions_Allowed --
15846 ------------------------
15848 -- pragma Extensions_Allowed (ON | OFF);
15850 when Pragma_Extensions_Allowed =>
15851 GNAT_Pragma;
15852 Check_Arg_Count (1);
15853 Check_No_Identifiers;
15854 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
15856 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
15857 Extensions_Allowed := True;
15858 Ada_Version := Ada_Version_Type'Last;
15860 else
15861 Extensions_Allowed := False;
15862 Ada_Version := Ada_Version_Explicit;
15863 Ada_Version_Pragma := Empty;
15864 end if;
15866 ------------------------
15867 -- Extensions_Visible --
15868 ------------------------
15870 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
15872 -- Characteristics:
15874 -- * Analysis - The annotation is fully analyzed immediately upon
15875 -- elaboration as its expression must be static.
15877 -- * Expansion - None.
15879 -- * Template - The annotation utilizes the generic template of the
15880 -- related subprogram [body] when it is:
15882 -- aspect on subprogram declaration
15883 -- aspect on stand-alone subprogram body
15884 -- pragma on stand-alone subprogram body
15886 -- The annotation must prepare its own template when it is:
15888 -- pragma on subprogram declaration
15890 -- * Globals - Capture of global references must occur after full
15891 -- analysis.
15893 -- * Instance - The annotation is instantiated automatically when
15894 -- the related generic subprogram [body] is instantiated except for
15895 -- the "pragma on subprogram declaration" case. In that scenario
15896 -- the annotation must instantiate itself.
15898 when Pragma_Extensions_Visible => Extensions_Visible : declare
15899 Formal : Entity_Id;
15900 Has_OK_Formal : Boolean := False;
15901 Spec_Id : Entity_Id;
15902 Subp_Decl : Node_Id;
15904 begin
15905 GNAT_Pragma;
15906 Check_No_Identifiers;
15907 Check_At_Most_N_Arguments (1);
15909 Subp_Decl :=
15910 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
15912 -- Abstract subprogram declaration
15914 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
15915 null;
15917 -- Generic subprogram declaration
15919 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
15920 null;
15922 -- Body acts as spec
15924 elsif Nkind (Subp_Decl) = N_Subprogram_Body
15925 and then No (Corresponding_Spec (Subp_Decl))
15926 then
15927 null;
15929 -- Body stub acts as spec
15931 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
15932 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
15933 then
15934 null;
15936 -- Subprogram declaration
15938 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
15939 null;
15941 -- Otherwise the pragma is associated with an illegal construct
15943 else
15944 Error_Pragma ("pragma % must apply to a subprogram");
15945 return;
15946 end if;
15948 -- Mark the pragma as Ghost if the related subprogram is also
15949 -- Ghost. This also ensures that any expansion performed further
15950 -- below will produce Ghost nodes.
15952 Spec_Id := Unique_Defining_Entity (Subp_Decl);
15953 Mark_Ghost_Pragma (N, Spec_Id);
15955 -- Chain the pragma on the contract for completeness
15957 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
15959 -- The legality checks of pragma Extension_Visible are affected
15960 -- by the SPARK mode in effect. Analyze all pragmas in specific
15961 -- order.
15963 Analyze_If_Present (Pragma_SPARK_Mode);
15965 -- Examine the formals of the related subprogram
15967 Formal := First_Formal (Spec_Id);
15968 while Present (Formal) loop
15970 -- At least one of the formals is of a specific tagged type,
15971 -- the pragma is legal.
15973 if Is_Specific_Tagged_Type (Etype (Formal)) then
15974 Has_OK_Formal := True;
15975 exit;
15977 -- A generic subprogram with at least one formal of a private
15978 -- type ensures the legality of the pragma because the actual
15979 -- may be specifically tagged. Note that this is verified by
15980 -- the check above at instantiation time.
15982 elsif Is_Private_Type (Etype (Formal))
15983 and then Is_Generic_Type (Etype (Formal))
15984 then
15985 Has_OK_Formal := True;
15986 exit;
15987 end if;
15989 Next_Formal (Formal);
15990 end loop;
15992 if not Has_OK_Formal then
15993 Error_Msg_Name_1 := Pname;
15994 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
15995 Error_Msg_NE
15996 ("\subprogram & lacks parameter of specific tagged or "
15997 & "generic private type", N, Spec_Id);
15999 return;
16000 end if;
16002 -- Analyze the Boolean expression (if any)
16004 if Present (Arg1) then
16005 Check_Static_Boolean_Expression
16006 (Expression (Get_Argument (N, Spec_Id)));
16007 end if;
16008 end Extensions_Visible;
16010 --------------
16011 -- External --
16012 --------------
16014 -- pragma External (
16015 -- [ Convention =>] convention_IDENTIFIER,
16016 -- [ Entity =>] LOCAL_NAME
16017 -- [, [External_Name =>] static_string_EXPRESSION ]
16018 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16020 when Pragma_External => External : declare
16021 C : Convention_Id;
16022 E : Entity_Id;
16023 pragma Warnings (Off, C);
16025 begin
16026 GNAT_Pragma;
16027 Check_Arg_Order
16028 ((Name_Convention,
16029 Name_Entity,
16030 Name_External_Name,
16031 Name_Link_Name));
16032 Check_At_Least_N_Arguments (2);
16033 Check_At_Most_N_Arguments (4);
16034 Process_Convention (C, E);
16036 -- A pragma that applies to a Ghost entity becomes Ghost for the
16037 -- purposes of legality checks and removal of ignored Ghost code.
16039 Mark_Ghost_Pragma (N, E);
16041 Note_Possible_Modification
16042 (Get_Pragma_Arg (Arg2), Sure => False);
16043 Process_Interface_Name (E, Arg3, Arg4, N);
16044 Set_Exported (E, Arg2);
16045 end External;
16047 --------------------------
16048 -- External_Name_Casing --
16049 --------------------------
16051 -- pragma External_Name_Casing (
16052 -- UPPERCASE | LOWERCASE
16053 -- [, AS_IS | UPPERCASE | LOWERCASE]);
16055 when Pragma_External_Name_Casing =>
16056 GNAT_Pragma;
16057 Check_No_Identifiers;
16059 if Arg_Count = 2 then
16060 Check_Arg_Is_One_Of
16061 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
16063 case Chars (Get_Pragma_Arg (Arg2)) is
16064 when Name_As_Is =>
16065 Opt.External_Name_Exp_Casing := As_Is;
16067 when Name_Uppercase =>
16068 Opt.External_Name_Exp_Casing := Uppercase;
16070 when Name_Lowercase =>
16071 Opt.External_Name_Exp_Casing := Lowercase;
16073 when others =>
16074 null;
16075 end case;
16077 else
16078 Check_Arg_Count (1);
16079 end if;
16081 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
16083 case Chars (Get_Pragma_Arg (Arg1)) is
16084 when Name_Uppercase =>
16085 Opt.External_Name_Imp_Casing := Uppercase;
16087 when Name_Lowercase =>
16088 Opt.External_Name_Imp_Casing := Lowercase;
16090 when others =>
16091 null;
16092 end case;
16094 ---------------
16095 -- Fast_Math --
16096 ---------------
16098 -- pragma Fast_Math;
16100 when Pragma_Fast_Math =>
16101 GNAT_Pragma;
16102 Check_No_Identifiers;
16103 Check_Valid_Configuration_Pragma;
16104 Fast_Math := True;
16106 --------------------------
16107 -- Favor_Top_Level --
16108 --------------------------
16110 -- pragma Favor_Top_Level (type_NAME);
16112 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
16113 Typ : Entity_Id;
16115 begin
16116 GNAT_Pragma;
16117 Check_No_Identifiers;
16118 Check_Arg_Count (1);
16119 Check_Arg_Is_Local_Name (Arg1);
16120 Typ := Entity (Get_Pragma_Arg (Arg1));
16122 -- A pragma that applies to a Ghost entity becomes Ghost for the
16123 -- purposes of legality checks and removal of ignored Ghost code.
16125 Mark_Ghost_Pragma (N, Typ);
16127 -- If it's an access-to-subprogram type (in particular, not a
16128 -- subtype), set the flag on that type.
16130 if Is_Access_Subprogram_Type (Typ) then
16131 Set_Can_Use_Internal_Rep (Typ, False);
16133 -- Otherwise it's an error (name denotes the wrong sort of entity)
16135 else
16136 Error_Pragma_Arg
16137 ("access-to-subprogram type expected",
16138 Get_Pragma_Arg (Arg1));
16139 end if;
16140 end Favor_Top_Level;
16142 ---------------------------
16143 -- Finalize_Storage_Only --
16144 ---------------------------
16146 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
16148 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
16149 Assoc : constant Node_Id := Arg1;
16150 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
16151 Typ : Entity_Id;
16153 begin
16154 GNAT_Pragma;
16155 Check_No_Identifiers;
16156 Check_Arg_Count (1);
16157 Check_Arg_Is_Local_Name (Arg1);
16159 Find_Type (Type_Id);
16160 Typ := Entity (Type_Id);
16162 if Typ = Any_Type
16163 or else Rep_Item_Too_Early (Typ, N)
16164 then
16165 return;
16166 else
16167 Typ := Underlying_Type (Typ);
16168 end if;
16170 if not Is_Controlled (Typ) then
16171 Error_Pragma ("pragma% must specify controlled type");
16172 end if;
16174 Check_First_Subtype (Arg1);
16176 if Finalize_Storage_Only (Typ) then
16177 Error_Pragma ("duplicate pragma%, only one allowed");
16179 elsif not Rep_Item_Too_Late (Typ, N) then
16180 Set_Finalize_Storage_Only (Base_Type (Typ), True);
16181 end if;
16182 end Finalize_Storage;
16184 -----------
16185 -- Ghost --
16186 -----------
16188 -- pragma Ghost [ (boolean_EXPRESSION) ];
16190 when Pragma_Ghost => Ghost : declare
16191 Context : Node_Id;
16192 Expr : Node_Id;
16193 Id : Entity_Id;
16194 Orig_Stmt : Node_Id;
16195 Prev_Id : Entity_Id;
16196 Stmt : Node_Id;
16198 begin
16199 GNAT_Pragma;
16200 Check_No_Identifiers;
16201 Check_At_Most_N_Arguments (1);
16203 Id := Empty;
16204 Stmt := Prev (N);
16205 while Present (Stmt) loop
16207 -- Skip prior pragmas, but check for duplicates
16209 if Nkind (Stmt) = N_Pragma then
16210 if Pragma_Name (Stmt) = Pname then
16211 Duplication_Error
16212 (Prag => N,
16213 Prev => Stmt);
16214 raise Pragma_Exit;
16215 end if;
16217 -- Task unit declared without a definition cannot be subject to
16218 -- pragma Ghost (SPARK RM 6.9(19)).
16220 elsif Nkind_In (Stmt, N_Single_Task_Declaration,
16221 N_Task_Type_Declaration)
16222 then
16223 Error_Pragma ("pragma % cannot apply to a task type");
16224 return;
16226 -- Skip internally generated code
16228 elsif not Comes_From_Source (Stmt) then
16229 Orig_Stmt := Original_Node (Stmt);
16231 -- When pragma Ghost applies to an untagged derivation, the
16232 -- derivation is transformed into a [sub]type declaration.
16234 if Nkind_In (Stmt, N_Full_Type_Declaration,
16235 N_Subtype_Declaration)
16236 and then Comes_From_Source (Orig_Stmt)
16237 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
16238 and then Nkind (Type_Definition (Orig_Stmt)) =
16239 N_Derived_Type_Definition
16240 then
16241 Id := Defining_Entity (Stmt);
16242 exit;
16244 -- When pragma Ghost applies to an object declaration which
16245 -- is initialized by means of a function call that returns
16246 -- on the secondary stack, the object declaration becomes a
16247 -- renaming.
16249 elsif Nkind (Stmt) = N_Object_Renaming_Declaration
16250 and then Comes_From_Source (Orig_Stmt)
16251 and then Nkind (Orig_Stmt) = N_Object_Declaration
16252 then
16253 Id := Defining_Entity (Stmt);
16254 exit;
16256 -- When pragma Ghost applies to an expression function, the
16257 -- expression function is transformed into a subprogram.
16259 elsif Nkind (Stmt) = N_Subprogram_Declaration
16260 and then Comes_From_Source (Orig_Stmt)
16261 and then Nkind (Orig_Stmt) = N_Expression_Function
16262 then
16263 Id := Defining_Entity (Stmt);
16264 exit;
16265 end if;
16267 -- The pragma applies to a legal construct, stop the traversal
16269 elsif Nkind_In (Stmt, N_Abstract_Subprogram_Declaration,
16270 N_Full_Type_Declaration,
16271 N_Generic_Subprogram_Declaration,
16272 N_Object_Declaration,
16273 N_Private_Extension_Declaration,
16274 N_Private_Type_Declaration,
16275 N_Subprogram_Declaration,
16276 N_Subtype_Declaration)
16277 then
16278 Id := Defining_Entity (Stmt);
16279 exit;
16281 -- The pragma does not apply to a legal construct, issue an
16282 -- error and stop the analysis.
16284 else
16285 Error_Pragma
16286 ("pragma % must apply to an object, package, subprogram "
16287 & "or type");
16288 return;
16289 end if;
16291 Stmt := Prev (Stmt);
16292 end loop;
16294 Context := Parent (N);
16296 -- Handle compilation units
16298 if Nkind (Context) = N_Compilation_Unit_Aux then
16299 Context := Unit (Parent (Context));
16300 end if;
16302 -- Protected and task types cannot be subject to pragma Ghost
16303 -- (SPARK RM 6.9(19)).
16305 if Nkind_In (Context, N_Protected_Body, N_Protected_Definition)
16306 then
16307 Error_Pragma ("pragma % cannot apply to a protected type");
16308 return;
16310 elsif Nkind_In (Context, N_Task_Body, N_Task_Definition) then
16311 Error_Pragma ("pragma % cannot apply to a task type");
16312 return;
16313 end if;
16315 if No (Id) then
16317 -- When pragma Ghost is associated with a [generic] package, it
16318 -- appears in the visible declarations.
16320 if Nkind (Context) = N_Package_Specification
16321 and then Present (Visible_Declarations (Context))
16322 and then List_Containing (N) = Visible_Declarations (Context)
16323 then
16324 Id := Defining_Entity (Context);
16326 -- Pragma Ghost applies to a stand-alone subprogram body
16328 elsif Nkind (Context) = N_Subprogram_Body
16329 and then No (Corresponding_Spec (Context))
16330 then
16331 Id := Defining_Entity (Context);
16333 -- Pragma Ghost applies to a subprogram declaration that acts
16334 -- as a compilation unit.
16336 elsif Nkind (Context) = N_Subprogram_Declaration then
16337 Id := Defining_Entity (Context);
16339 -- Pragma Ghost applies to a generic subprogram
16341 elsif Nkind (Context) = N_Generic_Subprogram_Declaration then
16342 Id := Defining_Entity (Specification (Context));
16343 end if;
16344 end if;
16346 if No (Id) then
16347 Error_Pragma
16348 ("pragma % must apply to an object, package, subprogram or "
16349 & "type");
16350 return;
16351 end if;
16353 -- Handle completions of types and constants that are subject to
16354 -- pragma Ghost.
16356 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
16357 Prev_Id := Incomplete_Or_Partial_View (Id);
16359 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
16360 Error_Msg_Name_1 := Pname;
16362 -- The full declaration of a deferred constant cannot be
16363 -- subject to pragma Ghost unless the deferred declaration
16364 -- is also Ghost (SPARK RM 6.9(9)).
16366 if Ekind (Prev_Id) = E_Constant then
16367 Error_Msg_Name_1 := Pname;
16368 Error_Msg_NE (Fix_Error
16369 ("pragma % must apply to declaration of deferred "
16370 & "constant &"), N, Id);
16371 return;
16373 -- Pragma Ghost may appear on the full view of an incomplete
16374 -- type because the incomplete declaration lacks aspects and
16375 -- cannot be subject to pragma Ghost.
16377 elsif Ekind (Prev_Id) = E_Incomplete_Type then
16378 null;
16380 -- The full declaration of a type cannot be subject to
16381 -- pragma Ghost unless the partial view is also Ghost
16382 -- (SPARK RM 6.9(9)).
16384 else
16385 Error_Msg_NE (Fix_Error
16386 ("pragma % must apply to partial view of type &"),
16387 N, Id);
16388 return;
16389 end if;
16390 end if;
16392 -- A synchronized object cannot be subject to pragma Ghost
16393 -- (SPARK RM 6.9(19)).
16395 elsif Ekind (Id) = E_Variable then
16396 if Is_Protected_Type (Etype (Id)) then
16397 Error_Pragma ("pragma % cannot apply to a protected object");
16398 return;
16400 elsif Is_Task_Type (Etype (Id)) then
16401 Error_Pragma ("pragma % cannot apply to a task object");
16402 return;
16403 end if;
16404 end if;
16406 -- Analyze the Boolean expression (if any)
16408 if Present (Arg1) then
16409 Expr := Get_Pragma_Arg (Arg1);
16411 Analyze_And_Resolve (Expr, Standard_Boolean);
16413 if Is_OK_Static_Expression (Expr) then
16415 -- "Ghostness" cannot be turned off once enabled within a
16416 -- region (SPARK RM 6.9(6)).
16418 if Is_False (Expr_Value (Expr))
16419 and then Ghost_Mode > None
16420 then
16421 Error_Pragma
16422 ("pragma % with value False cannot appear in enabled "
16423 & "ghost region");
16424 return;
16425 end if;
16427 -- Otherwie the expression is not static
16429 else
16430 Error_Pragma_Arg
16431 ("expression of pragma % must be static", Expr);
16432 return;
16433 end if;
16434 end if;
16436 Set_Is_Ghost_Entity (Id);
16437 end Ghost;
16439 ------------
16440 -- Global --
16441 ------------
16443 -- pragma Global (GLOBAL_SPECIFICATION);
16445 -- GLOBAL_SPECIFICATION ::=
16446 -- null
16447 -- | (GLOBAL_LIST)
16448 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
16450 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
16452 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
16453 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
16454 -- GLOBAL_ITEM ::= NAME
16456 -- Characteristics:
16458 -- * Analysis - The annotation undergoes initial checks to verify
16459 -- the legal placement and context. Secondary checks fully analyze
16460 -- the dependency clauses in:
16462 -- Analyze_Global_In_Decl_Part
16464 -- * Expansion - None.
16466 -- * Template - The annotation utilizes the generic template of the
16467 -- related subprogram [body] when it is:
16469 -- aspect on subprogram declaration
16470 -- aspect on stand-alone subprogram body
16471 -- pragma on stand-alone subprogram body
16473 -- The annotation must prepare its own template when it is:
16475 -- pragma on subprogram declaration
16477 -- * Globals - Capture of global references must occur after full
16478 -- analysis.
16480 -- * Instance - The annotation is instantiated automatically when
16481 -- the related generic subprogram [body] is instantiated except for
16482 -- the "pragma on subprogram declaration" case. In that scenario
16483 -- the annotation must instantiate itself.
16485 when Pragma_Global => Global : declare
16486 Legal : Boolean;
16487 Spec_Id : Entity_Id;
16488 Subp_Decl : Node_Id;
16490 begin
16491 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
16493 if Legal then
16495 -- Chain the pragma on the contract for further processing by
16496 -- Analyze_Global_In_Decl_Part.
16498 Add_Contract_Item (N, Spec_Id);
16500 -- Fully analyze the pragma when it appears inside an entry
16501 -- or subprogram body because it cannot benefit from forward
16502 -- references.
16504 if Nkind_In (Subp_Decl, N_Entry_Body,
16505 N_Subprogram_Body,
16506 N_Subprogram_Body_Stub)
16507 then
16508 -- The legality checks of pragmas Depends and Global are
16509 -- affected by the SPARK mode in effect and the volatility
16510 -- of the context. In addition these two pragmas are subject
16511 -- to an inherent order:
16513 -- 1) Global
16514 -- 2) Depends
16516 -- Analyze all these pragmas in the order outlined above
16518 Analyze_If_Present (Pragma_SPARK_Mode);
16519 Analyze_If_Present (Pragma_Volatile_Function);
16520 Analyze_Global_In_Decl_Part (N);
16521 Analyze_If_Present (Pragma_Depends);
16522 end if;
16523 end if;
16524 end Global;
16526 -----------
16527 -- Ident --
16528 -----------
16530 -- pragma Ident (static_string_EXPRESSION)
16532 -- Note: pragma Comment shares this processing. Pragma Ident is
16533 -- identical in effect to pragma Commment.
16535 when Pragma_Comment
16536 | Pragma_Ident
16538 Ident : declare
16539 Str : Node_Id;
16541 begin
16542 GNAT_Pragma;
16543 Check_Arg_Count (1);
16544 Check_No_Identifiers;
16545 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
16546 Store_Note (N);
16548 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
16550 declare
16551 CS : Node_Id;
16552 GP : Node_Id;
16554 begin
16555 GP := Parent (Parent (N));
16557 if Nkind_In (GP, N_Package_Declaration,
16558 N_Generic_Package_Declaration)
16559 then
16560 GP := Parent (GP);
16561 end if;
16563 -- If we have a compilation unit, then record the ident value,
16564 -- checking for improper duplication.
16566 if Nkind (GP) = N_Compilation_Unit then
16567 CS := Ident_String (Current_Sem_Unit);
16569 if Present (CS) then
16571 -- If we have multiple instances, concatenate them, but
16572 -- not in ASIS, where we want the original tree.
16574 if not ASIS_Mode then
16575 Start_String (Strval (CS));
16576 Store_String_Char (' ');
16577 Store_String_Chars (Strval (Str));
16578 Set_Strval (CS, End_String);
16579 end if;
16581 else
16582 Set_Ident_String (Current_Sem_Unit, Str);
16583 end if;
16585 -- For subunits, we just ignore the Ident, since in GNAT these
16586 -- are not separate object files, and hence not separate units
16587 -- in the unit table.
16589 elsif Nkind (GP) = N_Subunit then
16590 null;
16591 end if;
16592 end;
16593 end Ident;
16595 -------------------
16596 -- Ignore_Pragma --
16597 -------------------
16599 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
16601 -- Entirely handled in the parser, nothing to do here
16603 when Pragma_Ignore_Pragma =>
16604 null;
16606 ----------------------------
16607 -- Implementation_Defined --
16608 ----------------------------
16610 -- pragma Implementation_Defined (LOCAL_NAME);
16612 -- Marks previously declared entity as implementation defined. For
16613 -- an overloaded entity, applies to the most recent homonym.
16615 -- pragma Implementation_Defined;
16617 -- The form with no arguments appears anywhere within a scope, most
16618 -- typically a package spec, and indicates that all entities that are
16619 -- defined within the package spec are Implementation_Defined.
16621 when Pragma_Implementation_Defined => Implementation_Defined : declare
16622 Ent : Entity_Id;
16624 begin
16625 GNAT_Pragma;
16626 Check_No_Identifiers;
16628 -- Form with no arguments
16630 if Arg_Count = 0 then
16631 Set_Is_Implementation_Defined (Current_Scope);
16633 -- Form with one argument
16635 else
16636 Check_Arg_Count (1);
16637 Check_Arg_Is_Local_Name (Arg1);
16638 Ent := Entity (Get_Pragma_Arg (Arg1));
16639 Set_Is_Implementation_Defined (Ent);
16640 end if;
16641 end Implementation_Defined;
16643 -----------------
16644 -- Implemented --
16645 -----------------
16647 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
16649 -- IMPLEMENTATION_KIND ::=
16650 -- By_Entry | By_Protected_Procedure | By_Any | Optional
16652 -- "By_Any" and "Optional" are treated as synonyms in order to
16653 -- support Ada 2012 aspect Synchronization.
16655 when Pragma_Implemented => Implemented : declare
16656 Proc_Id : Entity_Id;
16657 Typ : Entity_Id;
16659 begin
16660 Ada_2012_Pragma;
16661 Check_Arg_Count (2);
16662 Check_No_Identifiers;
16663 Check_Arg_Is_Identifier (Arg1);
16664 Check_Arg_Is_Local_Name (Arg1);
16665 Check_Arg_Is_One_Of (Arg2,
16666 Name_By_Any,
16667 Name_By_Entry,
16668 Name_By_Protected_Procedure,
16669 Name_Optional);
16671 -- Extract the name of the local procedure
16673 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
16675 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
16676 -- primitive procedure of a synchronized tagged type.
16678 if Ekind (Proc_Id) = E_Procedure
16679 and then Is_Primitive (Proc_Id)
16680 and then Present (First_Formal (Proc_Id))
16681 then
16682 Typ := Etype (First_Formal (Proc_Id));
16684 if Is_Tagged_Type (Typ)
16685 and then
16687 -- Check for a protected, a synchronized or a task interface
16689 ((Is_Interface (Typ)
16690 and then Is_Synchronized_Interface (Typ))
16692 -- Check for a protected type or a task type that implements
16693 -- an interface.
16695 or else
16696 (Is_Concurrent_Record_Type (Typ)
16697 and then Present (Interfaces (Typ)))
16699 -- In analysis-only mode, examine original protected type
16701 or else
16702 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
16703 and then Present (Interface_List (Parent (Typ))))
16705 -- Check for a private record extension with keyword
16706 -- "synchronized".
16708 or else
16709 (Ekind_In (Typ, E_Record_Type_With_Private,
16710 E_Record_Subtype_With_Private)
16711 and then Synchronized_Present (Parent (Typ))))
16712 then
16713 null;
16714 else
16715 Error_Pragma_Arg
16716 ("controlling formal must be of synchronized tagged type",
16717 Arg1);
16718 return;
16719 end if;
16721 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
16722 -- By_Protected_Procedure to the primitive procedure of a task
16723 -- interface.
16725 if Chars (Arg2) = Name_By_Protected_Procedure
16726 and then Is_Interface (Typ)
16727 and then Is_Task_Interface (Typ)
16728 then
16729 Error_Pragma_Arg
16730 ("implementation kind By_Protected_Procedure cannot be "
16731 & "applied to a task interface primitive", Arg2);
16732 return;
16733 end if;
16735 -- Procedures declared inside a protected type must be accepted
16737 elsif Ekind (Proc_Id) = E_Procedure
16738 and then Is_Protected_Type (Scope (Proc_Id))
16739 then
16740 null;
16742 -- The first argument is not a primitive procedure
16744 else
16745 Error_Pragma_Arg
16746 ("pragma % must be applied to a primitive procedure", Arg1);
16747 return;
16748 end if;
16750 Record_Rep_Item (Proc_Id, N);
16751 end Implemented;
16753 ----------------------
16754 -- Implicit_Packing --
16755 ----------------------
16757 -- pragma Implicit_Packing;
16759 when Pragma_Implicit_Packing =>
16760 GNAT_Pragma;
16761 Check_Arg_Count (0);
16762 Implicit_Packing := True;
16764 ------------
16765 -- Import --
16766 ------------
16768 -- pragma Import (
16769 -- [Convention =>] convention_IDENTIFIER,
16770 -- [Entity =>] LOCAL_NAME
16771 -- [, [External_Name =>] static_string_EXPRESSION ]
16772 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16774 when Pragma_Import =>
16775 Check_Ada_83_Warning;
16776 Check_Arg_Order
16777 ((Name_Convention,
16778 Name_Entity,
16779 Name_External_Name,
16780 Name_Link_Name));
16782 Check_At_Least_N_Arguments (2);
16783 Check_At_Most_N_Arguments (4);
16784 Process_Import_Or_Interface;
16786 ---------------------
16787 -- Import_Function --
16788 ---------------------
16790 -- pragma Import_Function (
16791 -- [Internal =>] LOCAL_NAME,
16792 -- [, [External =>] EXTERNAL_SYMBOL]
16793 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16794 -- [, [Result_Type =>] SUBTYPE_MARK]
16795 -- [, [Mechanism =>] MECHANISM]
16796 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
16798 -- EXTERNAL_SYMBOL ::=
16799 -- IDENTIFIER
16800 -- | static_string_EXPRESSION
16802 -- PARAMETER_TYPES ::=
16803 -- null
16804 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16806 -- TYPE_DESIGNATOR ::=
16807 -- subtype_NAME
16808 -- | subtype_Name ' Access
16810 -- MECHANISM ::=
16811 -- MECHANISM_NAME
16812 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16814 -- MECHANISM_ASSOCIATION ::=
16815 -- [formal_parameter_NAME =>] MECHANISM_NAME
16817 -- MECHANISM_NAME ::=
16818 -- Value
16819 -- | Reference
16821 when Pragma_Import_Function => Import_Function : declare
16822 Args : Args_List (1 .. 6);
16823 Names : constant Name_List (1 .. 6) := (
16824 Name_Internal,
16825 Name_External,
16826 Name_Parameter_Types,
16827 Name_Result_Type,
16828 Name_Mechanism,
16829 Name_Result_Mechanism);
16831 Internal : Node_Id renames Args (1);
16832 External : Node_Id renames Args (2);
16833 Parameter_Types : Node_Id renames Args (3);
16834 Result_Type : Node_Id renames Args (4);
16835 Mechanism : Node_Id renames Args (5);
16836 Result_Mechanism : Node_Id renames Args (6);
16838 begin
16839 GNAT_Pragma;
16840 Gather_Associations (Names, Args);
16841 Process_Extended_Import_Export_Subprogram_Pragma (
16842 Arg_Internal => Internal,
16843 Arg_External => External,
16844 Arg_Parameter_Types => Parameter_Types,
16845 Arg_Result_Type => Result_Type,
16846 Arg_Mechanism => Mechanism,
16847 Arg_Result_Mechanism => Result_Mechanism);
16848 end Import_Function;
16850 -------------------
16851 -- Import_Object --
16852 -------------------
16854 -- pragma Import_Object (
16855 -- [Internal =>] LOCAL_NAME
16856 -- [, [External =>] EXTERNAL_SYMBOL]
16857 -- [, [Size =>] EXTERNAL_SYMBOL]);
16859 -- EXTERNAL_SYMBOL ::=
16860 -- IDENTIFIER
16861 -- | static_string_EXPRESSION
16863 when Pragma_Import_Object => Import_Object : declare
16864 Args : Args_List (1 .. 3);
16865 Names : constant Name_List (1 .. 3) := (
16866 Name_Internal,
16867 Name_External,
16868 Name_Size);
16870 Internal : Node_Id renames Args (1);
16871 External : Node_Id renames Args (2);
16872 Size : Node_Id renames Args (3);
16874 begin
16875 GNAT_Pragma;
16876 Gather_Associations (Names, Args);
16877 Process_Extended_Import_Export_Object_Pragma (
16878 Arg_Internal => Internal,
16879 Arg_External => External,
16880 Arg_Size => Size);
16881 end Import_Object;
16883 ----------------------
16884 -- Import_Procedure --
16885 ----------------------
16887 -- pragma Import_Procedure (
16888 -- [Internal =>] LOCAL_NAME
16889 -- [, [External =>] EXTERNAL_SYMBOL]
16890 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16891 -- [, [Mechanism =>] MECHANISM]);
16893 -- EXTERNAL_SYMBOL ::=
16894 -- IDENTIFIER
16895 -- | static_string_EXPRESSION
16897 -- PARAMETER_TYPES ::=
16898 -- null
16899 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16901 -- TYPE_DESIGNATOR ::=
16902 -- subtype_NAME
16903 -- | subtype_Name ' Access
16905 -- MECHANISM ::=
16906 -- MECHANISM_NAME
16907 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16909 -- MECHANISM_ASSOCIATION ::=
16910 -- [formal_parameter_NAME =>] MECHANISM_NAME
16912 -- MECHANISM_NAME ::=
16913 -- Value
16914 -- | Reference
16916 when Pragma_Import_Procedure => Import_Procedure : declare
16917 Args : Args_List (1 .. 4);
16918 Names : constant Name_List (1 .. 4) := (
16919 Name_Internal,
16920 Name_External,
16921 Name_Parameter_Types,
16922 Name_Mechanism);
16924 Internal : Node_Id renames Args (1);
16925 External : Node_Id renames Args (2);
16926 Parameter_Types : Node_Id renames Args (3);
16927 Mechanism : Node_Id renames Args (4);
16929 begin
16930 GNAT_Pragma;
16931 Gather_Associations (Names, Args);
16932 Process_Extended_Import_Export_Subprogram_Pragma (
16933 Arg_Internal => Internal,
16934 Arg_External => External,
16935 Arg_Parameter_Types => Parameter_Types,
16936 Arg_Mechanism => Mechanism);
16937 end Import_Procedure;
16939 -----------------------------
16940 -- Import_Valued_Procedure --
16941 -----------------------------
16943 -- pragma Import_Valued_Procedure (
16944 -- [Internal =>] LOCAL_NAME
16945 -- [, [External =>] EXTERNAL_SYMBOL]
16946 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16947 -- [, [Mechanism =>] MECHANISM]);
16949 -- EXTERNAL_SYMBOL ::=
16950 -- IDENTIFIER
16951 -- | static_string_EXPRESSION
16953 -- PARAMETER_TYPES ::=
16954 -- null
16955 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16957 -- TYPE_DESIGNATOR ::=
16958 -- subtype_NAME
16959 -- | subtype_Name ' Access
16961 -- MECHANISM ::=
16962 -- MECHANISM_NAME
16963 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16965 -- MECHANISM_ASSOCIATION ::=
16966 -- [formal_parameter_NAME =>] MECHANISM_NAME
16968 -- MECHANISM_NAME ::=
16969 -- Value
16970 -- | Reference
16972 when Pragma_Import_Valued_Procedure =>
16973 Import_Valued_Procedure : declare
16974 Args : Args_List (1 .. 4);
16975 Names : constant Name_List (1 .. 4) := (
16976 Name_Internal,
16977 Name_External,
16978 Name_Parameter_Types,
16979 Name_Mechanism);
16981 Internal : Node_Id renames Args (1);
16982 External : Node_Id renames Args (2);
16983 Parameter_Types : Node_Id renames Args (3);
16984 Mechanism : Node_Id renames Args (4);
16986 begin
16987 GNAT_Pragma;
16988 Gather_Associations (Names, Args);
16989 Process_Extended_Import_Export_Subprogram_Pragma (
16990 Arg_Internal => Internal,
16991 Arg_External => External,
16992 Arg_Parameter_Types => Parameter_Types,
16993 Arg_Mechanism => Mechanism);
16994 end Import_Valued_Procedure;
16996 -----------------
16997 -- Independent --
16998 -----------------
17000 -- pragma Independent (LOCAL_NAME);
17002 when Pragma_Independent =>
17003 Process_Atomic_Independent_Shared_Volatile;
17005 ----------------------------
17006 -- Independent_Components --
17007 ----------------------------
17009 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
17011 when Pragma_Independent_Components => Independent_Components : declare
17012 C : Node_Id;
17013 D : Node_Id;
17014 E_Id : Node_Id;
17015 E : Entity_Id;
17016 K : Node_Kind;
17018 begin
17019 Check_Ada_83_Warning;
17020 Ada_2012_Pragma;
17021 Check_No_Identifiers;
17022 Check_Arg_Count (1);
17023 Check_Arg_Is_Local_Name (Arg1);
17024 E_Id := Get_Pragma_Arg (Arg1);
17026 if Etype (E_Id) = Any_Type then
17027 return;
17028 end if;
17030 E := Entity (E_Id);
17032 -- A record type with a self-referential component of anonymous
17033 -- access type is given an incomplete view in order to handle the
17034 -- self reference:
17036 -- type Rec is record
17037 -- Self : access Rec;
17038 -- end record;
17040 -- becomes
17042 -- type Rec;
17043 -- type Ptr is access Rec;
17044 -- type Rec is record
17045 -- Self : Ptr;
17046 -- end record;
17048 -- Since the incomplete view is now the initial view of the type,
17049 -- the argument of the pragma will reference the incomplete view,
17050 -- but this view is illegal according to the semantics of the
17051 -- pragma.
17053 -- Obtain the full view of an internally-generated incomplete type
17054 -- only. This way an attempt to associate the pragma with a source
17055 -- incomplete type is still caught.
17057 if Ekind (E) = E_Incomplete_Type
17058 and then not Comes_From_Source (E)
17059 and then Present (Full_View (E))
17060 then
17061 E := Full_View (E);
17062 end if;
17064 -- A pragma that applies to a Ghost entity becomes Ghost for the
17065 -- purposes of legality checks and removal of ignored Ghost code.
17067 Mark_Ghost_Pragma (N, E);
17069 -- Check duplicate before we chain ourselves
17071 Check_Duplicate_Pragma (E);
17073 -- Check appropriate entity
17075 if Rep_Item_Too_Early (E, N)
17076 or else
17077 Rep_Item_Too_Late (E, N)
17078 then
17079 return;
17080 end if;
17082 D := Declaration_Node (E);
17083 K := Nkind (D);
17085 -- The flag is set on the base type, or on the object
17087 if K = N_Full_Type_Declaration
17088 and then (Is_Array_Type (E) or else Is_Record_Type (E))
17089 then
17090 Set_Has_Independent_Components (Base_Type (E));
17091 Record_Independence_Check (N, Base_Type (E));
17093 -- For record type, set all components independent
17095 if Is_Record_Type (E) then
17096 C := First_Component (E);
17097 while Present (C) loop
17098 Set_Is_Independent (C);
17099 Next_Component (C);
17100 end loop;
17101 end if;
17103 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
17104 and then Nkind (D) = N_Object_Declaration
17105 and then Nkind (Object_Definition (D)) =
17106 N_Constrained_Array_Definition
17107 then
17108 Set_Has_Independent_Components (E);
17109 Record_Independence_Check (N, E);
17111 else
17112 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
17113 end if;
17114 end Independent_Components;
17116 -----------------------
17117 -- Initial_Condition --
17118 -----------------------
17120 -- pragma Initial_Condition (boolean_EXPRESSION);
17122 -- Characteristics:
17124 -- * Analysis - The annotation undergoes initial checks to verify
17125 -- the legal placement and context. Secondary checks preanalyze the
17126 -- expression in:
17128 -- Analyze_Initial_Condition_In_Decl_Part
17130 -- * Expansion - The annotation is expanded during the expansion of
17131 -- the package body whose declaration is subject to the annotation
17132 -- as done in:
17134 -- Expand_Pragma_Initial_Condition
17136 -- * Template - The annotation utilizes the generic template of the
17137 -- related package declaration.
17139 -- * Globals - Capture of global references must occur after full
17140 -- analysis.
17142 -- * Instance - The annotation is instantiated automatically when
17143 -- the related generic package is instantiated.
17145 when Pragma_Initial_Condition => Initial_Condition : declare
17146 Pack_Decl : Node_Id;
17147 Pack_Id : Entity_Id;
17149 begin
17150 GNAT_Pragma;
17151 Check_No_Identifiers;
17152 Check_Arg_Count (1);
17154 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
17156 if not Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
17157 N_Package_Declaration)
17158 then
17159 Pragma_Misplaced;
17160 return;
17161 end if;
17163 Pack_Id := Defining_Entity (Pack_Decl);
17165 -- A pragma that applies to a Ghost entity becomes Ghost for the
17166 -- purposes of legality checks and removal of ignored Ghost code.
17168 Mark_Ghost_Pragma (N, Pack_Id);
17170 -- Chain the pragma on the contract for further processing by
17171 -- Analyze_Initial_Condition_In_Decl_Part.
17173 Add_Contract_Item (N, Pack_Id);
17175 -- The legality checks of pragmas Abstract_State, Initializes, and
17176 -- Initial_Condition are affected by the SPARK mode in effect. In
17177 -- addition, these three pragmas are subject to an inherent order:
17179 -- 1) Abstract_State
17180 -- 2) Initializes
17181 -- 3) Initial_Condition
17183 -- Analyze all these pragmas in the order outlined above
17185 Analyze_If_Present (Pragma_SPARK_Mode);
17186 Analyze_If_Present (Pragma_Abstract_State);
17187 Analyze_If_Present (Pragma_Initializes);
17188 end Initial_Condition;
17190 ------------------------
17191 -- Initialize_Scalars --
17192 ------------------------
17194 -- pragma Initialize_Scalars
17195 -- [ ( TYPE_VALUE_PAIR {, TYPE_VALUE_PAIR} ) ];
17197 -- TYPE_VALUE_PAIR ::=
17198 -- SCALAR_TYPE => static_EXPRESSION
17200 -- SCALAR_TYPE :=
17201 -- Short_Float
17202 -- | Float
17203 -- | Long_Float
17204 -- | Long_Long_Flat
17205 -- | Signed_8
17206 -- | Signed_16
17207 -- | Signed_32
17208 -- | Signed_64
17209 -- | Unsigned_8
17210 -- | Unsigned_16
17211 -- | Unsigned_32
17212 -- | Unsigned_64
17214 when Pragma_Initialize_Scalars => Do_Initialize_Scalars : declare
17215 Seen : array (Scalar_Id) of Node_Id := (others => Empty);
17216 -- This collection holds the individual pairs which specify the
17217 -- invalid values of their respective scalar types.
17219 procedure Analyze_Float_Value
17220 (Scal_Typ : Float_Scalar_Id;
17221 Val_Expr : Node_Id);
17222 -- Analyze a type value pair associated with float type Scal_Typ
17223 -- and expression Val_Expr.
17225 procedure Analyze_Integer_Value
17226 (Scal_Typ : Integer_Scalar_Id;
17227 Val_Expr : Node_Id);
17228 -- Analyze a type value pair associated with integer type Scal_Typ
17229 -- and expression Val_Expr.
17231 procedure Analyze_Type_Value_Pair (Pair : Node_Id);
17232 -- Analyze type value pair Pair
17234 -------------------------
17235 -- Analyze_Float_Value --
17236 -------------------------
17238 procedure Analyze_Float_Value
17239 (Scal_Typ : Float_Scalar_Id;
17240 Val_Expr : Node_Id)
17242 begin
17243 Analyze_And_Resolve (Val_Expr, Any_Real);
17245 if Is_OK_Static_Expression (Val_Expr) then
17246 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value_R (Val_Expr));
17248 else
17249 Error_Msg_Name_1 := Scal_Typ;
17250 Error_Msg_N ("value for type % must be static", Val_Expr);
17251 end if;
17252 end Analyze_Float_Value;
17254 ---------------------------
17255 -- Analyze_Integer_Value --
17256 ---------------------------
17258 procedure Analyze_Integer_Value
17259 (Scal_Typ : Integer_Scalar_Id;
17260 Val_Expr : Node_Id)
17262 begin
17263 Analyze_And_Resolve (Val_Expr, Any_Integer);
17265 if Is_OK_Static_Expression (Val_Expr) then
17266 Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value (Val_Expr));
17268 else
17269 Error_Msg_Name_1 := Scal_Typ;
17270 Error_Msg_N ("value for type % must be static", Val_Expr);
17271 end if;
17272 end Analyze_Integer_Value;
17274 -----------------------------
17275 -- Analyze_Type_Value_Pair --
17276 -----------------------------
17278 procedure Analyze_Type_Value_Pair (Pair : Node_Id) is
17279 Scal_Typ : constant Name_Id := Chars (Pair);
17280 Val_Expr : constant Node_Id := Expression (Pair);
17281 Prev_Pair : Node_Id;
17283 begin
17284 if Scal_Typ in Scalar_Id then
17285 Prev_Pair := Seen (Scal_Typ);
17287 -- Prevent multiple attempts to set a value for a scalar
17288 -- type.
17290 if Present (Prev_Pair) then
17291 Error_Msg_Name_1 := Scal_Typ;
17292 Error_Msg_N
17293 ("cannot specify multiple invalid values for type %",
17294 Pair);
17296 Error_Msg_Sloc := Sloc (Prev_Pair);
17297 Error_Msg_N ("previous value set #", Pair);
17299 -- Ignore the effects of the pair, but do not halt the
17300 -- analysis of the pragma altogether.
17302 return;
17304 -- Otherwise capture the first pair for this scalar type
17306 else
17307 Seen (Scal_Typ) := Pair;
17308 end if;
17310 if Scal_Typ in Float_Scalar_Id then
17311 Analyze_Float_Value (Scal_Typ, Val_Expr);
17313 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
17314 Analyze_Integer_Value (Scal_Typ, Val_Expr);
17315 end if;
17317 -- Otherwise the scalar family is illegal
17319 else
17320 Error_Msg_Name_1 := Pname;
17321 Error_Msg_N
17322 ("argument of pragma % must denote valid scalar family",
17323 Pair);
17324 end if;
17325 end Analyze_Type_Value_Pair;
17327 -- Local variables
17329 Pairs : constant List_Id := Pragma_Argument_Associations (N);
17330 Pair : Node_Id;
17332 -- Start of processing for Do_Initialize_Scalars
17334 begin
17335 GNAT_Pragma;
17336 Check_Valid_Configuration_Pragma;
17337 Check_Restriction (No_Initialize_Scalars, N);
17339 -- Ignore the effects of the pragma when No_Initialize_Scalars is
17340 -- in effect.
17342 if Restriction_Active (No_Initialize_Scalars) then
17343 null;
17345 -- Initialize_Scalars creates false positives in CodePeer, and
17346 -- incorrect negative results in GNATprove mode, so ignore this
17347 -- pragma in these modes.
17349 elsif CodePeer_Mode or GNATprove_Mode then
17350 null;
17352 -- Otherwise analyze the pragma
17354 else
17355 if Present (Pairs) then
17357 -- Install Standard in order to provide access to primitive
17358 -- types in case the expressions contain attributes such as
17359 -- Integer'Last.
17361 Push_Scope (Standard_Standard);
17363 Pair := First (Pairs);
17364 while Present (Pair) loop
17365 Analyze_Type_Value_Pair (Pair);
17366 Next (Pair);
17367 end loop;
17369 -- Remove Standard
17371 Pop_Scope;
17372 end if;
17374 Init_Or_Norm_Scalars := True;
17375 Initialize_Scalars := True;
17376 end if;
17377 end Do_Initialize_Scalars;
17379 -----------------
17380 -- Initializes --
17381 -----------------
17383 -- pragma Initializes (INITIALIZATION_LIST);
17385 -- INITIALIZATION_LIST ::=
17386 -- null
17387 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
17389 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
17391 -- INPUT_LIST ::=
17392 -- null
17393 -- | INPUT
17394 -- | (INPUT {, INPUT})
17396 -- INPUT ::= name
17398 -- Characteristics:
17400 -- * Analysis - The annotation undergoes initial checks to verify
17401 -- the legal placement and context. Secondary checks preanalyze the
17402 -- expression in:
17404 -- Analyze_Initializes_In_Decl_Part
17406 -- * Expansion - None.
17408 -- * Template - The annotation utilizes the generic template of the
17409 -- related package declaration.
17411 -- * Globals - Capture of global references must occur after full
17412 -- analysis.
17414 -- * Instance - The annotation is instantiated automatically when
17415 -- the related generic package is instantiated.
17417 when Pragma_Initializes => Initializes : declare
17418 Pack_Decl : Node_Id;
17419 Pack_Id : Entity_Id;
17421 begin
17422 GNAT_Pragma;
17423 Check_No_Identifiers;
17424 Check_Arg_Count (1);
17426 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
17428 if not Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
17429 N_Package_Declaration)
17430 then
17431 Pragma_Misplaced;
17432 return;
17433 end if;
17435 Pack_Id := Defining_Entity (Pack_Decl);
17437 -- A pragma that applies to a Ghost entity becomes Ghost for the
17438 -- purposes of legality checks and removal of ignored Ghost code.
17440 Mark_Ghost_Pragma (N, Pack_Id);
17441 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
17443 -- Chain the pragma on the contract for further processing by
17444 -- Analyze_Initializes_In_Decl_Part.
17446 Add_Contract_Item (N, Pack_Id);
17448 -- The legality checks of pragmas Abstract_State, Initializes, and
17449 -- Initial_Condition are affected by the SPARK mode in effect. In
17450 -- addition, these three pragmas are subject to an inherent order:
17452 -- 1) Abstract_State
17453 -- 2) Initializes
17454 -- 3) Initial_Condition
17456 -- Analyze all these pragmas in the order outlined above
17458 Analyze_If_Present (Pragma_SPARK_Mode);
17459 Analyze_If_Present (Pragma_Abstract_State);
17460 Analyze_If_Present (Pragma_Initial_Condition);
17461 end Initializes;
17463 ------------
17464 -- Inline --
17465 ------------
17467 -- pragma Inline ( NAME {, NAME} );
17469 when Pragma_Inline =>
17471 -- Pragma always active unless in GNATprove mode. It is disabled
17472 -- in GNATprove mode because frontend inlining is applied
17473 -- independently of pragmas Inline and Inline_Always for
17474 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
17475 -- in inline.ads.
17477 if not GNATprove_Mode then
17479 -- Inline status is Enabled if option -gnatn is specified.
17480 -- However this status determines only the value of the
17481 -- Is_Inlined flag on the subprogram and does not prevent
17482 -- the pragma itself from being recorded for later use,
17483 -- in particular for a later modification of Is_Inlined
17484 -- independently of the -gnatn option.
17486 -- In other words, if -gnatn is specified for a unit, then
17487 -- all Inline pragmas processed for the compilation of this
17488 -- unit, including those in the spec of other units, are
17489 -- activated, so subprograms will be inlined across units.
17491 -- If -gnatn is not specified, no Inline pragma is activated
17492 -- here, which means that subprograms will not be inlined
17493 -- across units. The Is_Inlined flag will nevertheless be
17494 -- set later when bodies are analyzed, so subprograms will
17495 -- be inlined within the unit.
17497 if Inline_Active then
17498 Process_Inline (Enabled);
17499 else
17500 Process_Inline (Disabled);
17501 end if;
17502 end if;
17504 -------------------
17505 -- Inline_Always --
17506 -------------------
17508 -- pragma Inline_Always ( NAME {, NAME} );
17510 when Pragma_Inline_Always =>
17511 GNAT_Pragma;
17513 -- Pragma always active unless in CodePeer mode or GNATprove
17514 -- mode. It is disabled in CodePeer mode because inlining is
17515 -- not helpful, and enabling it caused walk order issues. It
17516 -- is disabled in GNATprove mode because frontend inlining is
17517 -- applied independently of pragmas Inline and Inline_Always for
17518 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
17519 -- inline.ads.
17521 if not CodePeer_Mode and not GNATprove_Mode then
17522 Process_Inline (Enabled);
17523 end if;
17525 --------------------
17526 -- Inline_Generic --
17527 --------------------
17529 -- pragma Inline_Generic (NAME {, NAME});
17531 when Pragma_Inline_Generic =>
17532 GNAT_Pragma;
17533 Process_Generic_List;
17535 ----------------------
17536 -- Inspection_Point --
17537 ----------------------
17539 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
17541 when Pragma_Inspection_Point => Inspection_Point : declare
17542 Arg : Node_Id;
17543 Exp : Node_Id;
17545 begin
17548 if Arg_Count > 0 then
17549 Arg := Arg1;
17550 loop
17551 Exp := Get_Pragma_Arg (Arg);
17552 Analyze (Exp);
17554 if not Is_Entity_Name (Exp)
17555 or else not Is_Object (Entity (Exp))
17556 then
17557 Error_Pragma_Arg ("object name required", Arg);
17558 end if;
17560 Next (Arg);
17561 exit when No (Arg);
17562 end loop;
17563 end if;
17564 end Inspection_Point;
17566 ---------------
17567 -- Interface --
17568 ---------------
17570 -- pragma Interface (
17571 -- [ Convention =>] convention_IDENTIFIER,
17572 -- [ Entity =>] LOCAL_NAME
17573 -- [, [External_Name =>] static_string_EXPRESSION ]
17574 -- [, [Link_Name =>] static_string_EXPRESSION ]);
17576 when Pragma_Interface =>
17577 GNAT_Pragma;
17578 Check_Arg_Order
17579 ((Name_Convention,
17580 Name_Entity,
17581 Name_External_Name,
17582 Name_Link_Name));
17583 Check_At_Least_N_Arguments (2);
17584 Check_At_Most_N_Arguments (4);
17585 Process_Import_Or_Interface;
17587 -- In Ada 2005, the permission to use Interface (a reserved word)
17588 -- as a pragma name is considered an obsolescent feature, and this
17589 -- pragma was already obsolescent in Ada 95.
17591 if Ada_Version >= Ada_95 then
17592 Check_Restriction
17593 (No_Obsolescent_Features, Pragma_Identifier (N));
17595 if Warn_On_Obsolescent_Feature then
17596 Error_Msg_N
17597 ("pragma Interface is an obsolescent feature?j?", N);
17598 Error_Msg_N
17599 ("|use pragma Import instead?j?", N);
17600 end if;
17601 end if;
17603 --------------------
17604 -- Interface_Name --
17605 --------------------
17607 -- pragma Interface_Name (
17608 -- [ Entity =>] LOCAL_NAME
17609 -- [,[External_Name =>] static_string_EXPRESSION ]
17610 -- [,[Link_Name =>] static_string_EXPRESSION ]);
17612 when Pragma_Interface_Name => Interface_Name : declare
17613 Id : Node_Id;
17614 Def_Id : Entity_Id;
17615 Hom_Id : Entity_Id;
17616 Found : Boolean;
17618 begin
17619 GNAT_Pragma;
17620 Check_Arg_Order
17621 ((Name_Entity, Name_External_Name, Name_Link_Name));
17622 Check_At_Least_N_Arguments (2);
17623 Check_At_Most_N_Arguments (3);
17624 Id := Get_Pragma_Arg (Arg1);
17625 Analyze (Id);
17627 -- This is obsolete from Ada 95 on, but it is an implementation
17628 -- defined pragma, so we do not consider that it violates the
17629 -- restriction (No_Obsolescent_Features).
17631 if Ada_Version >= Ada_95 then
17632 if Warn_On_Obsolescent_Feature then
17633 Error_Msg_N
17634 ("pragma Interface_Name is an obsolescent feature?j?", N);
17635 Error_Msg_N
17636 ("|use pragma Import instead?j?", N);
17637 end if;
17638 end if;
17640 if not Is_Entity_Name (Id) then
17641 Error_Pragma_Arg
17642 ("first argument for pragma% must be entity name", Arg1);
17643 elsif Etype (Id) = Any_Type then
17644 return;
17645 else
17646 Def_Id := Entity (Id);
17647 end if;
17649 -- Special DEC-compatible processing for the object case, forces
17650 -- object to be imported.
17652 if Ekind (Def_Id) = E_Variable then
17653 Kill_Size_Check_Code (Def_Id);
17654 Note_Possible_Modification (Id, Sure => False);
17656 -- Initialization is not allowed for imported variable
17658 if Present (Expression (Parent (Def_Id)))
17659 and then Comes_From_Source (Expression (Parent (Def_Id)))
17660 then
17661 Error_Msg_Sloc := Sloc (Def_Id);
17662 Error_Pragma_Arg
17663 ("no initialization allowed for declaration of& #",
17664 Arg2);
17666 else
17667 -- For compatibility, support VADS usage of providing both
17668 -- pragmas Interface and Interface_Name to obtain the effect
17669 -- of a single Import pragma.
17671 if Is_Imported (Def_Id)
17672 and then Present (First_Rep_Item (Def_Id))
17673 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
17674 and then Pragma_Name (First_Rep_Item (Def_Id)) =
17675 Name_Interface
17676 then
17677 null;
17678 else
17679 Set_Imported (Def_Id);
17680 end if;
17682 Set_Is_Public (Def_Id);
17683 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
17684 end if;
17686 -- Otherwise must be subprogram
17688 elsif not Is_Subprogram (Def_Id) then
17689 Error_Pragma_Arg
17690 ("argument of pragma% is not subprogram", Arg1);
17692 else
17693 Check_At_Most_N_Arguments (3);
17694 Hom_Id := Def_Id;
17695 Found := False;
17697 -- Loop through homonyms
17699 loop
17700 Def_Id := Get_Base_Subprogram (Hom_Id);
17702 if Is_Imported (Def_Id) then
17703 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
17704 Found := True;
17705 end if;
17707 exit when From_Aspect_Specification (N);
17708 Hom_Id := Homonym (Hom_Id);
17710 exit when No (Hom_Id)
17711 or else Scope (Hom_Id) /= Current_Scope;
17712 end loop;
17714 if not Found then
17715 Error_Pragma_Arg
17716 ("argument of pragma% is not imported subprogram",
17717 Arg1);
17718 end if;
17719 end if;
17720 end Interface_Name;
17722 -----------------------
17723 -- Interrupt_Handler --
17724 -----------------------
17726 -- pragma Interrupt_Handler (handler_NAME);
17728 when Pragma_Interrupt_Handler =>
17729 Check_Ada_83_Warning;
17730 Check_Arg_Count (1);
17731 Check_No_Identifiers;
17733 if No_Run_Time_Mode then
17734 Error_Msg_CRT ("Interrupt_Handler pragma", N);
17735 else
17736 Check_Interrupt_Or_Attach_Handler;
17737 Process_Interrupt_Or_Attach_Handler;
17738 end if;
17740 ------------------------
17741 -- Interrupt_Priority --
17742 ------------------------
17744 -- pragma Interrupt_Priority [(EXPRESSION)];
17746 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
17747 P : constant Node_Id := Parent (N);
17748 Arg : Node_Id;
17749 Ent : Entity_Id;
17751 begin
17752 Check_Ada_83_Warning;
17754 if Arg_Count /= 0 then
17755 Arg := Get_Pragma_Arg (Arg1);
17756 Check_Arg_Count (1);
17757 Check_No_Identifiers;
17759 -- The expression must be analyzed in the special manner
17760 -- described in "Handling of Default and Per-Object
17761 -- Expressions" in sem.ads.
17763 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
17764 end if;
17766 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
17767 Pragma_Misplaced;
17768 return;
17770 else
17771 Ent := Defining_Identifier (Parent (P));
17773 -- Check duplicate pragma before we chain the pragma in the Rep
17774 -- Item chain of Ent.
17776 Check_Duplicate_Pragma (Ent);
17777 Record_Rep_Item (Ent, N);
17779 -- Check the No_Task_At_Interrupt_Priority restriction
17781 if Nkind (P) = N_Task_Definition then
17782 Check_Restriction (No_Task_At_Interrupt_Priority, N);
17783 end if;
17784 end if;
17785 end Interrupt_Priority;
17787 ---------------------
17788 -- Interrupt_State --
17789 ---------------------
17791 -- pragma Interrupt_State (
17792 -- [Name =>] INTERRUPT_ID,
17793 -- [State =>] INTERRUPT_STATE);
17795 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
17796 -- INTERRUPT_STATE => System | Runtime | User
17798 -- Note: if the interrupt id is given as an identifier, then it must
17799 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
17800 -- given as a static integer expression which must be in the range of
17801 -- Ada.Interrupts.Interrupt_ID.
17803 when Pragma_Interrupt_State => Interrupt_State : declare
17804 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
17805 -- This is the entity Ada.Interrupts.Interrupt_ID;
17807 State_Type : Character;
17808 -- Set to 's'/'r'/'u' for System/Runtime/User
17810 IST_Num : Pos;
17811 -- Index to entry in Interrupt_States table
17813 Int_Val : Uint;
17814 -- Value of interrupt
17816 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
17817 -- The first argument to the pragma
17819 Int_Ent : Entity_Id;
17820 -- Interrupt entity in Ada.Interrupts.Names
17822 begin
17823 GNAT_Pragma;
17824 Check_Arg_Order ((Name_Name, Name_State));
17825 Check_Arg_Count (2);
17827 Check_Optional_Identifier (Arg1, Name_Name);
17828 Check_Optional_Identifier (Arg2, Name_State);
17829 Check_Arg_Is_Identifier (Arg2);
17831 -- First argument is identifier
17833 if Nkind (Arg1X) = N_Identifier then
17835 -- Search list of names in Ada.Interrupts.Names
17837 Int_Ent := First_Entity (RTE (RE_Names));
17838 loop
17839 if No (Int_Ent) then
17840 Error_Pragma_Arg ("invalid interrupt name", Arg1);
17842 elsif Chars (Int_Ent) = Chars (Arg1X) then
17843 Int_Val := Expr_Value (Constant_Value (Int_Ent));
17844 exit;
17845 end if;
17847 Next_Entity (Int_Ent);
17848 end loop;
17850 -- First argument is not an identifier, so it must be a static
17851 -- expression of type Ada.Interrupts.Interrupt_ID.
17853 else
17854 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
17855 Int_Val := Expr_Value (Arg1X);
17857 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
17858 or else
17859 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
17860 then
17861 Error_Pragma_Arg
17862 ("value not in range of type "
17863 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
17864 end if;
17865 end if;
17867 -- Check OK state
17869 case Chars (Get_Pragma_Arg (Arg2)) is
17870 when Name_Runtime => State_Type := 'r';
17871 when Name_System => State_Type := 's';
17872 when Name_User => State_Type := 'u';
17874 when others =>
17875 Error_Pragma_Arg ("invalid interrupt state", Arg2);
17876 end case;
17878 -- Check if entry is already stored
17880 IST_Num := Interrupt_States.First;
17881 loop
17882 -- If entry not found, add it
17884 if IST_Num > Interrupt_States.Last then
17885 Interrupt_States.Append
17886 ((Interrupt_Number => UI_To_Int (Int_Val),
17887 Interrupt_State => State_Type,
17888 Pragma_Loc => Loc));
17889 exit;
17891 -- Case of entry for the same entry
17893 elsif Int_Val = Interrupt_States.Table (IST_Num).
17894 Interrupt_Number
17895 then
17896 -- If state matches, done, no need to make redundant entry
17898 exit when
17899 State_Type = Interrupt_States.Table (IST_Num).
17900 Interrupt_State;
17902 -- Otherwise if state does not match, error
17904 Error_Msg_Sloc :=
17905 Interrupt_States.Table (IST_Num).Pragma_Loc;
17906 Error_Pragma_Arg
17907 ("state conflicts with that given #", Arg2);
17908 exit;
17909 end if;
17911 IST_Num := IST_Num + 1;
17912 end loop;
17913 end Interrupt_State;
17915 ---------------
17916 -- Invariant --
17917 ---------------
17919 -- pragma Invariant
17920 -- ([Entity =>] type_LOCAL_NAME,
17921 -- [Check =>] EXPRESSION
17922 -- [,[Message =>] String_Expression]);
17924 when Pragma_Invariant => Invariant : declare
17925 Discard : Boolean;
17926 Typ : Entity_Id;
17927 Typ_Arg : Node_Id;
17929 begin
17930 GNAT_Pragma;
17931 Check_At_Least_N_Arguments (2);
17932 Check_At_Most_N_Arguments (3);
17933 Check_Optional_Identifier (Arg1, Name_Entity);
17934 Check_Optional_Identifier (Arg2, Name_Check);
17936 if Arg_Count = 3 then
17937 Check_Optional_Identifier (Arg3, Name_Message);
17938 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
17939 end if;
17941 Check_Arg_Is_Local_Name (Arg1);
17943 Typ_Arg := Get_Pragma_Arg (Arg1);
17944 Find_Type (Typ_Arg);
17945 Typ := Entity (Typ_Arg);
17947 -- Nothing to do of the related type is erroneous in some way
17949 if Typ = Any_Type then
17950 return;
17952 -- AI12-0041: Invariants are allowed in interface types
17954 elsif Is_Interface (Typ) then
17955 null;
17957 -- An invariant must apply to a private type, or appear in the
17958 -- private part of a package spec and apply to a completion.
17959 -- a class-wide invariant can only appear on a private declaration
17960 -- or private extension, not a completion.
17962 -- A [class-wide] invariant may be associated a [limited] private
17963 -- type or a private extension.
17965 elsif Ekind_In (Typ, E_Limited_Private_Type,
17966 E_Private_Type,
17967 E_Record_Type_With_Private)
17968 then
17969 null;
17971 -- A non-class-wide invariant may be associated with the full view
17972 -- of a [limited] private type or a private extension.
17974 elsif Has_Private_Declaration (Typ)
17975 and then not Class_Present (N)
17976 then
17977 null;
17979 -- A class-wide invariant may appear on the partial view only
17981 elsif Class_Present (N) then
17982 Error_Pragma_Arg
17983 ("pragma % only allowed for private type", Arg1);
17984 return;
17986 -- A regular invariant may appear on both views
17988 else
17989 Error_Pragma_Arg
17990 ("pragma % only allowed for private type or corresponding "
17991 & "full view", Arg1);
17992 return;
17993 end if;
17995 -- An invariant associated with an abstract type (this includes
17996 -- interfaces) must be class-wide.
17998 if Is_Abstract_Type (Typ) and then not Class_Present (N) then
17999 Error_Pragma_Arg
18000 ("pragma % not allowed for abstract type", Arg1);
18001 return;
18002 end if;
18004 -- A pragma that applies to a Ghost entity becomes Ghost for the
18005 -- purposes of legality checks and removal of ignored Ghost code.
18007 Mark_Ghost_Pragma (N, Typ);
18009 -- The pragma defines a type-specific invariant, the type is said
18010 -- to have invariants of its "own".
18012 Set_Has_Own_Invariants (Typ);
18014 -- If the invariant is class-wide, then it can be inherited by
18015 -- derived or interface implementing types. The type is said to
18016 -- have "inheritable" invariants.
18018 if Class_Present (N) then
18019 Set_Has_Inheritable_Invariants (Typ);
18020 end if;
18022 -- Chain the pragma on to the rep item chain, for processing when
18023 -- the type is frozen.
18025 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
18027 -- Create the declaration of the invariant procedure that will
18028 -- verify the invariant at run time. Interfaces are treated as the
18029 -- partial view of a private type in order to achieve uniformity
18030 -- with the general case. As a result, an interface receives only
18031 -- a "partial" invariant procedure, which is never called.
18033 Build_Invariant_Procedure_Declaration
18034 (Typ => Typ,
18035 Partial_Invariant => Is_Interface (Typ));
18036 end Invariant;
18038 ----------------
18039 -- Keep_Names --
18040 ----------------
18042 -- pragma Keep_Names ([On => ] LOCAL_NAME);
18044 when Pragma_Keep_Names => Keep_Names : declare
18045 Arg : Node_Id;
18047 begin
18048 GNAT_Pragma;
18049 Check_Arg_Count (1);
18050 Check_Optional_Identifier (Arg1, Name_On);
18051 Check_Arg_Is_Local_Name (Arg1);
18053 Arg := Get_Pragma_Arg (Arg1);
18054 Analyze (Arg);
18056 if Etype (Arg) = Any_Type then
18057 return;
18058 end if;
18060 if not Is_Entity_Name (Arg)
18061 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
18062 then
18063 Error_Pragma_Arg
18064 ("pragma% requires a local enumeration type", Arg1);
18065 end if;
18067 Set_Discard_Names (Entity (Arg), False);
18068 end Keep_Names;
18070 -------------
18071 -- License --
18072 -------------
18074 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
18076 when Pragma_License =>
18077 GNAT_Pragma;
18079 -- Do not analyze pragma any further in CodePeer mode, to avoid
18080 -- extraneous errors in this implementation-dependent pragma,
18081 -- which has a different profile on other compilers.
18083 if CodePeer_Mode then
18084 return;
18085 end if;
18087 Check_Arg_Count (1);
18088 Check_No_Identifiers;
18089 Check_Valid_Configuration_Pragma;
18090 Check_Arg_Is_Identifier (Arg1);
18092 declare
18093 Sind : constant Source_File_Index :=
18094 Source_Index (Current_Sem_Unit);
18096 begin
18097 case Chars (Get_Pragma_Arg (Arg1)) is
18098 when Name_GPL =>
18099 Set_License (Sind, GPL);
18101 when Name_Modified_GPL =>
18102 Set_License (Sind, Modified_GPL);
18104 when Name_Restricted =>
18105 Set_License (Sind, Restricted);
18107 when Name_Unrestricted =>
18108 Set_License (Sind, Unrestricted);
18110 when others =>
18111 Error_Pragma_Arg ("invalid license name", Arg1);
18112 end case;
18113 end;
18115 ---------------
18116 -- Link_With --
18117 ---------------
18119 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
18121 when Pragma_Link_With => Link_With : declare
18122 Arg : Node_Id;
18124 begin
18125 GNAT_Pragma;
18127 if Operating_Mode = Generate_Code
18128 and then In_Extended_Main_Source_Unit (N)
18129 then
18130 Check_At_Least_N_Arguments (1);
18131 Check_No_Identifiers;
18132 Check_Is_In_Decl_Part_Or_Package_Spec;
18133 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
18134 Start_String;
18136 Arg := Arg1;
18137 while Present (Arg) loop
18138 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
18140 -- Store argument, converting sequences of spaces to a
18141 -- single null character (this is one of the differences
18142 -- in processing between Link_With and Linker_Options).
18144 Arg_Store : declare
18145 C : constant Char_Code := Get_Char_Code (' ');
18146 S : constant String_Id :=
18147 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
18148 L : constant Nat := String_Length (S);
18149 F : Nat := 1;
18151 procedure Skip_Spaces;
18152 -- Advance F past any spaces
18154 -----------------
18155 -- Skip_Spaces --
18156 -----------------
18158 procedure Skip_Spaces is
18159 begin
18160 while F <= L and then Get_String_Char (S, F) = C loop
18161 F := F + 1;
18162 end loop;
18163 end Skip_Spaces;
18165 -- Start of processing for Arg_Store
18167 begin
18168 Skip_Spaces; -- skip leading spaces
18170 -- Loop through characters, changing any embedded
18171 -- sequence of spaces to a single null character (this
18172 -- is how Link_With/Linker_Options differ)
18174 while F <= L loop
18175 if Get_String_Char (S, F) = C then
18176 Skip_Spaces;
18177 exit when F > L;
18178 Store_String_Char (ASCII.NUL);
18180 else
18181 Store_String_Char (Get_String_Char (S, F));
18182 F := F + 1;
18183 end if;
18184 end loop;
18185 end Arg_Store;
18187 Arg := Next (Arg);
18189 if Present (Arg) then
18190 Store_String_Char (ASCII.NUL);
18191 end if;
18192 end loop;
18194 Store_Linker_Option_String (End_String);
18195 end if;
18196 end Link_With;
18198 ------------------
18199 -- Linker_Alias --
18200 ------------------
18202 -- pragma Linker_Alias (
18203 -- [Entity =>] LOCAL_NAME
18204 -- [Target =>] static_string_EXPRESSION);
18206 when Pragma_Linker_Alias =>
18207 GNAT_Pragma;
18208 Check_Arg_Order ((Name_Entity, Name_Target));
18209 Check_Arg_Count (2);
18210 Check_Optional_Identifier (Arg1, Name_Entity);
18211 Check_Optional_Identifier (Arg2, Name_Target);
18212 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18213 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
18215 -- The only processing required is to link this item on to the
18216 -- list of rep items for the given entity. This is accomplished
18217 -- by the call to Rep_Item_Too_Late (when no error is detected
18218 -- and False is returned).
18220 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
18221 return;
18222 else
18223 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
18224 end if;
18226 ------------------------
18227 -- Linker_Constructor --
18228 ------------------------
18230 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
18232 -- Code is shared with Linker_Destructor
18234 -----------------------
18235 -- Linker_Destructor --
18236 -----------------------
18238 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
18240 when Pragma_Linker_Constructor
18241 | Pragma_Linker_Destructor
18243 Linker_Constructor : declare
18244 Arg1_X : Node_Id;
18245 Proc : Entity_Id;
18247 begin
18248 GNAT_Pragma;
18249 Check_Arg_Count (1);
18250 Check_No_Identifiers;
18251 Check_Arg_Is_Local_Name (Arg1);
18252 Arg1_X := Get_Pragma_Arg (Arg1);
18253 Analyze (Arg1_X);
18254 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
18256 if not Is_Library_Level_Entity (Proc) then
18257 Error_Pragma_Arg
18258 ("argument for pragma% must be library level entity", Arg1);
18259 end if;
18261 -- The only processing required is to link this item on to the
18262 -- list of rep items for the given entity. This is accomplished
18263 -- by the call to Rep_Item_Too_Late (when no error is detected
18264 -- and False is returned).
18266 if Rep_Item_Too_Late (Proc, N) then
18267 return;
18268 else
18269 Set_Has_Gigi_Rep_Item (Proc);
18270 end if;
18271 end Linker_Constructor;
18273 --------------------
18274 -- Linker_Options --
18275 --------------------
18277 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
18279 when Pragma_Linker_Options => Linker_Options : declare
18280 Arg : Node_Id;
18282 begin
18283 Check_Ada_83_Warning;
18284 Check_No_Identifiers;
18285 Check_Arg_Count (1);
18286 Check_Is_In_Decl_Part_Or_Package_Spec;
18287 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
18288 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
18290 Arg := Arg2;
18291 while Present (Arg) loop
18292 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
18293 Store_String_Char (ASCII.NUL);
18294 Store_String_Chars
18295 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
18296 Arg := Next (Arg);
18297 end loop;
18299 if Operating_Mode = Generate_Code
18300 and then In_Extended_Main_Source_Unit (N)
18301 then
18302 Store_Linker_Option_String (End_String);
18303 end if;
18304 end Linker_Options;
18306 --------------------
18307 -- Linker_Section --
18308 --------------------
18310 -- pragma Linker_Section (
18311 -- [Entity =>] LOCAL_NAME
18312 -- [Section =>] static_string_EXPRESSION);
18314 when Pragma_Linker_Section => Linker_Section : declare
18315 Arg : Node_Id;
18316 Ent : Entity_Id;
18317 LPE : Node_Id;
18319 Ghost_Error_Posted : Boolean := False;
18320 -- Flag set when an error concerning the illegal mix of Ghost and
18321 -- non-Ghost subprograms is emitted.
18323 Ghost_Id : Entity_Id := Empty;
18324 -- The entity of the first Ghost subprogram encountered while
18325 -- processing the arguments of the pragma.
18327 begin
18328 GNAT_Pragma;
18329 Check_Arg_Order ((Name_Entity, Name_Section));
18330 Check_Arg_Count (2);
18331 Check_Optional_Identifier (Arg1, Name_Entity);
18332 Check_Optional_Identifier (Arg2, Name_Section);
18333 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18334 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
18336 -- Check kind of entity
18338 Arg := Get_Pragma_Arg (Arg1);
18339 Ent := Entity (Arg);
18341 case Ekind (Ent) is
18343 -- Objects (constants and variables) and types. For these cases
18344 -- all we need to do is to set the Linker_Section_pragma field,
18345 -- checking that we do not have a duplicate.
18347 when Type_Kind
18348 | E_Constant
18349 | E_Variable
18351 LPE := Linker_Section_Pragma (Ent);
18353 if Present (LPE) then
18354 Error_Msg_Sloc := Sloc (LPE);
18355 Error_Msg_NE
18356 ("Linker_Section already specified for &#", Arg1, Ent);
18357 end if;
18359 Set_Linker_Section_Pragma (Ent, N);
18361 -- A pragma that applies to a Ghost entity becomes Ghost for
18362 -- the purposes of legality checks and removal of ignored
18363 -- Ghost code.
18365 Mark_Ghost_Pragma (N, Ent);
18367 -- Subprograms
18369 when Subprogram_Kind =>
18371 -- Aspect case, entity already set
18373 if From_Aspect_Specification (N) then
18374 Set_Linker_Section_Pragma
18375 (Entity (Corresponding_Aspect (N)), N);
18377 -- Pragma case, we must climb the homonym chain, but skip
18378 -- any for which the linker section is already set.
18380 else
18381 loop
18382 if No (Linker_Section_Pragma (Ent)) then
18383 Set_Linker_Section_Pragma (Ent, N);
18385 -- A pragma that applies to a Ghost entity becomes
18386 -- Ghost for the purposes of legality checks and
18387 -- removal of ignored Ghost code.
18389 Mark_Ghost_Pragma (N, Ent);
18391 -- Capture the entity of the first Ghost subprogram
18392 -- being processed for error detection purposes.
18394 if Is_Ghost_Entity (Ent) then
18395 if No (Ghost_Id) then
18396 Ghost_Id := Ent;
18397 end if;
18399 -- Otherwise the subprogram is non-Ghost. It is
18400 -- illegal to mix references to Ghost and non-Ghost
18401 -- entities (SPARK RM 6.9).
18403 elsif Present (Ghost_Id)
18404 and then not Ghost_Error_Posted
18405 then
18406 Ghost_Error_Posted := True;
18408 Error_Msg_Name_1 := Pname;
18409 Error_Msg_N
18410 ("pragma % cannot mention ghost and "
18411 & "non-ghost subprograms", N);
18413 Error_Msg_Sloc := Sloc (Ghost_Id);
18414 Error_Msg_NE
18415 ("\& # declared as ghost", N, Ghost_Id);
18417 Error_Msg_Sloc := Sloc (Ent);
18418 Error_Msg_NE
18419 ("\& # declared as non-ghost", N, Ent);
18420 end if;
18421 end if;
18423 Ent := Homonym (Ent);
18424 exit when No (Ent)
18425 or else Scope (Ent) /= Current_Scope;
18426 end loop;
18427 end if;
18429 -- All other cases are illegal
18431 when others =>
18432 Error_Pragma_Arg
18433 ("pragma% applies only to objects, subprograms, and types",
18434 Arg1);
18435 end case;
18436 end Linker_Section;
18438 ----------
18439 -- List --
18440 ----------
18442 -- pragma List (On | Off)
18444 -- There is nothing to do here, since we did all the processing for
18445 -- this pragma in Par.Prag (so that it works properly even in syntax
18446 -- only mode).
18448 when Pragma_List =>
18449 null;
18451 ---------------
18452 -- Lock_Free --
18453 ---------------
18455 -- pragma Lock_Free [(Boolean_EXPRESSION)];
18457 when Pragma_Lock_Free => Lock_Free : declare
18458 P : constant Node_Id := Parent (N);
18459 Arg : Node_Id;
18460 Ent : Entity_Id;
18461 Val : Boolean;
18463 begin
18464 Check_No_Identifiers;
18465 Check_At_Most_N_Arguments (1);
18467 -- Protected definition case
18469 if Nkind (P) = N_Protected_Definition then
18470 Ent := Defining_Identifier (Parent (P));
18472 -- One argument
18474 if Arg_Count = 1 then
18475 Arg := Get_Pragma_Arg (Arg1);
18476 Val := Is_True (Static_Boolean (Arg));
18478 -- No arguments (expression is considered to be True)
18480 else
18481 Val := True;
18482 end if;
18484 -- Check duplicate pragma before we chain the pragma in the Rep
18485 -- Item chain of Ent.
18487 Check_Duplicate_Pragma (Ent);
18488 Record_Rep_Item (Ent, N);
18489 Set_Uses_Lock_Free (Ent, Val);
18491 -- Anything else is incorrect placement
18493 else
18494 Pragma_Misplaced;
18495 end if;
18496 end Lock_Free;
18498 --------------------
18499 -- Locking_Policy --
18500 --------------------
18502 -- pragma Locking_Policy (policy_IDENTIFIER);
18504 when Pragma_Locking_Policy => declare
18505 subtype LP_Range is Name_Id
18506 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
18507 LP_Val : LP_Range;
18508 LP : Character;
18510 begin
18511 Check_Ada_83_Warning;
18512 Check_Arg_Count (1);
18513 Check_No_Identifiers;
18514 Check_Arg_Is_Locking_Policy (Arg1);
18515 Check_Valid_Configuration_Pragma;
18516 LP_Val := Chars (Get_Pragma_Arg (Arg1));
18518 case LP_Val is
18519 when Name_Ceiling_Locking => LP := 'C';
18520 when Name_Concurrent_Readers_Locking => LP := 'R';
18521 when Name_Inheritance_Locking => LP := 'I';
18522 end case;
18524 if Locking_Policy /= ' '
18525 and then Locking_Policy /= LP
18526 then
18527 Error_Msg_Sloc := Locking_Policy_Sloc;
18528 Error_Pragma ("locking policy incompatible with policy#");
18530 -- Set new policy, but always preserve System_Location since we
18531 -- like the error message with the run time name.
18533 else
18534 Locking_Policy := LP;
18536 if Locking_Policy_Sloc /= System_Location then
18537 Locking_Policy_Sloc := Loc;
18538 end if;
18539 end if;
18540 end;
18542 -------------------
18543 -- Loop_Optimize --
18544 -------------------
18546 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
18548 -- OPTIMIZATION_HINT ::=
18549 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
18551 when Pragma_Loop_Optimize => Loop_Optimize : declare
18552 Hint : Node_Id;
18554 begin
18555 GNAT_Pragma;
18556 Check_At_Least_N_Arguments (1);
18557 Check_No_Identifiers;
18559 Hint := First (Pragma_Argument_Associations (N));
18560 while Present (Hint) loop
18561 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
18562 Name_No_Unroll,
18563 Name_Unroll,
18564 Name_No_Vector,
18565 Name_Vector);
18566 Next (Hint);
18567 end loop;
18569 Check_Loop_Pragma_Placement;
18570 end Loop_Optimize;
18572 ------------------
18573 -- Loop_Variant --
18574 ------------------
18576 -- pragma Loop_Variant
18577 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
18579 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
18581 -- CHANGE_DIRECTION ::= Increases | Decreases
18583 when Pragma_Loop_Variant => Loop_Variant : declare
18584 Variant : Node_Id;
18586 begin
18587 GNAT_Pragma;
18588 Check_At_Least_N_Arguments (1);
18589 Check_Loop_Pragma_Placement;
18591 -- Process all increasing / decreasing expressions
18593 Variant := First (Pragma_Argument_Associations (N));
18594 while Present (Variant) loop
18595 if Chars (Variant) = No_Name then
18596 Error_Pragma_Arg_Ident ("expect name `Increases`", Variant);
18598 elsif not Nam_In (Chars (Variant), Name_Decreases,
18599 Name_Increases)
18600 then
18601 declare
18602 Name : String := Get_Name_String (Chars (Variant));
18604 begin
18605 -- It is a common mistake to write "Increasing" for
18606 -- "Increases" or "Decreasing" for "Decreases". Recognize
18607 -- specially names starting with "incr" or "decr" to
18608 -- suggest the corresponding name.
18610 System.Case_Util.To_Lower (Name);
18612 if Name'Length >= 4
18613 and then Name (1 .. 4) = "incr"
18614 then
18615 Error_Pragma_Arg_Ident
18616 ("expect name `Increases`", Variant);
18618 elsif Name'Length >= 4
18619 and then Name (1 .. 4) = "decr"
18620 then
18621 Error_Pragma_Arg_Ident
18622 ("expect name `Decreases`", Variant);
18624 else
18625 Error_Pragma_Arg_Ident
18626 ("expect name `Increases` or `Decreases`", Variant);
18627 end if;
18628 end;
18629 end if;
18631 Preanalyze_Assert_Expression
18632 (Expression (Variant), Any_Discrete);
18634 Next (Variant);
18635 end loop;
18636 end Loop_Variant;
18638 -----------------------
18639 -- Machine_Attribute --
18640 -----------------------
18642 -- pragma Machine_Attribute (
18643 -- [Entity =>] LOCAL_NAME,
18644 -- [Attribute_Name =>] static_string_EXPRESSION
18645 -- [, [Info =>] static_EXPRESSION] );
18647 when Pragma_Machine_Attribute => Machine_Attribute : declare
18648 Def_Id : Entity_Id;
18650 begin
18651 GNAT_Pragma;
18652 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
18654 if Arg_Count = 3 then
18655 Check_Optional_Identifier (Arg3, Name_Info);
18656 Check_Arg_Is_OK_Static_Expression (Arg3);
18657 else
18658 Check_Arg_Count (2);
18659 end if;
18661 Check_Optional_Identifier (Arg1, Name_Entity);
18662 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
18663 Check_Arg_Is_Local_Name (Arg1);
18664 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
18665 Def_Id := Entity (Get_Pragma_Arg (Arg1));
18667 if Is_Access_Type (Def_Id) then
18668 Def_Id := Designated_Type (Def_Id);
18669 end if;
18671 if Rep_Item_Too_Early (Def_Id, N) then
18672 return;
18673 end if;
18675 Def_Id := Underlying_Type (Def_Id);
18677 -- The only processing required is to link this item on to the
18678 -- list of rep items for the given entity. This is accomplished
18679 -- by the call to Rep_Item_Too_Late (when no error is detected
18680 -- and False is returned).
18682 if Rep_Item_Too_Late (Def_Id, N) then
18683 return;
18684 else
18685 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
18686 end if;
18687 end Machine_Attribute;
18689 ----------
18690 -- Main --
18691 ----------
18693 -- pragma Main
18694 -- (MAIN_OPTION [, MAIN_OPTION]);
18696 -- MAIN_OPTION ::=
18697 -- [STACK_SIZE =>] static_integer_EXPRESSION
18698 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
18699 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
18701 when Pragma_Main => Main : declare
18702 Args : Args_List (1 .. 3);
18703 Names : constant Name_List (1 .. 3) := (
18704 Name_Stack_Size,
18705 Name_Task_Stack_Size_Default,
18706 Name_Time_Slicing_Enabled);
18708 Nod : Node_Id;
18710 begin
18711 GNAT_Pragma;
18712 Gather_Associations (Names, Args);
18714 for J in 1 .. 2 loop
18715 if Present (Args (J)) then
18716 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
18717 end if;
18718 end loop;
18720 if Present (Args (3)) then
18721 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
18722 end if;
18724 Nod := Next (N);
18725 while Present (Nod) loop
18726 if Nkind (Nod) = N_Pragma
18727 and then Pragma_Name (Nod) = Name_Main
18728 then
18729 Error_Msg_Name_1 := Pname;
18730 Error_Msg_N ("duplicate pragma% not permitted", Nod);
18731 end if;
18733 Next (Nod);
18734 end loop;
18735 end Main;
18737 ------------------
18738 -- Main_Storage --
18739 ------------------
18741 -- pragma Main_Storage
18742 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
18744 -- MAIN_STORAGE_OPTION ::=
18745 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
18746 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
18748 when Pragma_Main_Storage => Main_Storage : declare
18749 Args : Args_List (1 .. 2);
18750 Names : constant Name_List (1 .. 2) := (
18751 Name_Working_Storage,
18752 Name_Top_Guard);
18754 Nod : Node_Id;
18756 begin
18757 GNAT_Pragma;
18758 Gather_Associations (Names, Args);
18760 for J in 1 .. 2 loop
18761 if Present (Args (J)) then
18762 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
18763 end if;
18764 end loop;
18766 Check_In_Main_Program;
18768 Nod := Next (N);
18769 while Present (Nod) loop
18770 if Nkind (Nod) = N_Pragma
18771 and then Pragma_Name (Nod) = Name_Main_Storage
18772 then
18773 Error_Msg_Name_1 := Pname;
18774 Error_Msg_N ("duplicate pragma% not permitted", Nod);
18775 end if;
18777 Next (Nod);
18778 end loop;
18779 end Main_Storage;
18781 ----------------------
18782 -- Max_Queue_Length --
18783 ----------------------
18785 -- pragma Max_Queue_Length (static_integer_EXPRESSION);
18787 -- This processing is shared by Pragma_Max_Entry_Queue_Depth
18789 when Pragma_Max_Queue_Length
18790 | Pragma_Max_Entry_Queue_Depth
18792 Max_Queue_Length : declare
18793 Arg : Node_Id;
18794 Entry_Decl : Node_Id;
18795 Entry_Id : Entity_Id;
18796 Val : Uint;
18798 begin
18799 if Prag_Id = Pragma_Max_Queue_Length then
18800 GNAT_Pragma;
18801 end if;
18803 Check_Arg_Count (1);
18805 Entry_Decl :=
18806 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
18808 -- Entry declaration
18810 if Nkind (Entry_Decl) = N_Entry_Declaration then
18812 -- Entry illegally within a task
18814 if Nkind (Parent (N)) = N_Task_Definition then
18815 Error_Pragma ("pragma % cannot apply to task entries");
18816 return;
18817 end if;
18819 Entry_Id := Defining_Entity (Entry_Decl);
18821 -- Otherwise the pragma is associated with an illegal construct
18823 else
18824 Error_Pragma ("pragma % must apply to a protected entry");
18825 return;
18826 end if;
18828 -- Mark the pragma as Ghost if the related subprogram is also
18829 -- Ghost. This also ensures that any expansion performed further
18830 -- below will produce Ghost nodes.
18832 Mark_Ghost_Pragma (N, Entry_Id);
18834 -- Analyze the Integer expression
18836 Arg := Get_Pragma_Arg (Arg1);
18837 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
18839 Val := Expr_Value (Arg);
18841 if Val <= 0 then
18842 Error_Pragma_Arg
18843 ("argument for pragma% must be positive", Arg1);
18845 elsif not UI_Is_In_Int_Range (Val) then
18846 Error_Pragma_Arg
18847 ("argument for pragma% out of range of Integer", Arg1);
18849 end if;
18851 -- Manually substitute the expression value of the pragma argument
18852 -- if it's not an integer literal because this is not taken care
18853 -- of automatically elsewhere.
18855 if Nkind (Arg) /= N_Integer_Literal then
18856 Rewrite (Arg, Make_Integer_Literal (Sloc (Arg), Val));
18857 Set_Etype (Arg, Etype (Original_Node (Arg)));
18858 end if;
18860 Record_Rep_Item (Entry_Id, N);
18861 end Max_Queue_Length;
18863 -----------------
18864 -- Memory_Size --
18865 -----------------
18867 -- pragma Memory_Size (NUMERIC_LITERAL)
18869 when Pragma_Memory_Size =>
18870 GNAT_Pragma;
18872 -- Memory size is simply ignored
18874 Check_No_Identifiers;
18875 Check_Arg_Count (1);
18876 Check_Arg_Is_Integer_Literal (Arg1);
18878 -------------
18879 -- No_Body --
18880 -------------
18882 -- pragma No_Body;
18884 -- The only correct use of this pragma is on its own in a file, in
18885 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
18886 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
18887 -- check for a file containing nothing but a No_Body pragma). If we
18888 -- attempt to process it during normal semantics processing, it means
18889 -- it was misplaced.
18891 when Pragma_No_Body =>
18892 GNAT_Pragma;
18893 Pragma_Misplaced;
18895 -----------------------------
18896 -- No_Elaboration_Code_All --
18897 -----------------------------
18899 -- pragma No_Elaboration_Code_All;
18901 when Pragma_No_Elaboration_Code_All =>
18902 GNAT_Pragma;
18903 Check_Valid_Library_Unit_Pragma;
18905 if Nkind (N) = N_Null_Statement then
18906 return;
18907 end if;
18909 -- Must appear for a spec or generic spec
18911 if not Nkind_In (Unit (Cunit (Current_Sem_Unit)),
18912 N_Generic_Package_Declaration,
18913 N_Generic_Subprogram_Declaration,
18914 N_Package_Declaration,
18915 N_Subprogram_Declaration)
18916 then
18917 Error_Pragma
18918 (Fix_Error
18919 ("pragma% can only occur for package "
18920 & "or subprogram spec"));
18921 end if;
18923 -- Set flag in unit table
18925 Set_No_Elab_Code_All (Current_Sem_Unit);
18927 -- Set restriction No_Elaboration_Code if this is the main unit
18929 if Current_Sem_Unit = Main_Unit then
18930 Set_Restriction (No_Elaboration_Code, N);
18931 end if;
18933 -- If we are in the main unit or in an extended main source unit,
18934 -- then we also add it to the configuration restrictions so that
18935 -- it will apply to all units in the extended main source.
18937 if Current_Sem_Unit = Main_Unit
18938 or else In_Extended_Main_Source_Unit (N)
18939 then
18940 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
18941 end if;
18943 -- If in main extended unit, activate transitive with test
18945 if In_Extended_Main_Source_Unit (N) then
18946 Opt.No_Elab_Code_All_Pragma := N;
18947 end if;
18949 -----------------------------
18950 -- No_Component_Reordering --
18951 -----------------------------
18953 -- pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)];
18955 when Pragma_No_Component_Reordering => No_Comp_Reordering : declare
18956 E : Entity_Id;
18957 E_Id : Node_Id;
18959 begin
18960 GNAT_Pragma;
18961 Check_At_Most_N_Arguments (1);
18963 if Arg_Count = 0 then
18964 Check_Valid_Configuration_Pragma;
18965 Opt.No_Component_Reordering := True;
18967 else
18968 Check_Optional_Identifier (Arg2, Name_Entity);
18969 Check_Arg_Is_Local_Name (Arg1);
18970 E_Id := Get_Pragma_Arg (Arg1);
18972 if Etype (E_Id) = Any_Type then
18973 return;
18974 end if;
18976 E := Entity (E_Id);
18978 if not Is_Record_Type (E) then
18979 Error_Pragma_Arg ("pragma% requires record type", Arg1);
18980 end if;
18982 Set_No_Reordering (Base_Type (E));
18983 end if;
18984 end No_Comp_Reordering;
18986 --------------------------
18987 -- No_Heap_Finalization --
18988 --------------------------
18990 -- pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ];
18992 when Pragma_No_Heap_Finalization => No_Heap_Finalization : declare
18993 Context : constant Node_Id := Parent (N);
18994 Typ_Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
18995 Prev : Node_Id;
18996 Typ : Entity_Id;
18998 begin
18999 GNAT_Pragma;
19000 Check_No_Identifiers;
19002 -- The pragma appears in a configuration file
19004 if No (Context) then
19005 Check_Arg_Count (0);
19006 Check_Valid_Configuration_Pragma;
19008 -- Detect a duplicate pragma
19010 if Present (No_Heap_Finalization_Pragma) then
19011 Duplication_Error
19012 (Prag => N,
19013 Prev => No_Heap_Finalization_Pragma);
19014 raise Pragma_Exit;
19015 end if;
19017 No_Heap_Finalization_Pragma := N;
19019 -- Otherwise the pragma should be associated with a library-level
19020 -- named access-to-object type.
19022 else
19023 Check_Arg_Count (1);
19024 Check_Arg_Is_Local_Name (Arg1);
19026 Find_Type (Typ_Arg);
19027 Typ := Entity (Typ_Arg);
19029 -- The type being subjected to the pragma is erroneous
19031 if Typ = Any_Type then
19032 Error_Pragma ("cannot find type referenced by pragma %");
19034 -- The pragma is applied to an incomplete or generic formal
19035 -- type way too early.
19037 elsif Rep_Item_Too_Early (Typ, N) then
19038 return;
19040 else
19041 Typ := Underlying_Type (Typ);
19042 end if;
19044 -- The pragma must apply to an access-to-object type
19046 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type) then
19047 null;
19049 -- Give a detailed error message on all other access type kinds
19051 elsif Ekind (Typ) = E_Access_Protected_Subprogram_Type then
19052 Error_Pragma
19053 ("pragma % cannot apply to access protected subprogram "
19054 & "type");
19056 elsif Ekind (Typ) = E_Access_Subprogram_Type then
19057 Error_Pragma
19058 ("pragma % cannot apply to access subprogram type");
19060 elsif Is_Anonymous_Access_Type (Typ) then
19061 Error_Pragma
19062 ("pragma % cannot apply to anonymous access type");
19064 -- Give a general error message in case the pragma applies to a
19065 -- non-access type.
19067 else
19068 Error_Pragma
19069 ("pragma % must apply to library level access type");
19070 end if;
19072 -- At this point the argument denotes an access-to-object type.
19073 -- Ensure that the type is declared at the library level.
19075 if Is_Library_Level_Entity (Typ) then
19076 null;
19078 -- Quietly ignore an access-to-object type originally declared
19079 -- at the library level within a generic, but instantiated at
19080 -- a non-library level. As a result the access-to-object type
19081 -- "loses" its No_Heap_Finalization property.
19083 elsif In_Instance then
19084 raise Pragma_Exit;
19086 else
19087 Error_Pragma
19088 ("pragma % must apply to library level access type");
19089 end if;
19091 -- Detect a duplicate pragma
19093 if Present (No_Heap_Finalization_Pragma) then
19094 Duplication_Error
19095 (Prag => N,
19096 Prev => No_Heap_Finalization_Pragma);
19097 raise Pragma_Exit;
19099 else
19100 Prev := Get_Pragma (Typ, Pragma_No_Heap_Finalization);
19102 if Present (Prev) then
19103 Duplication_Error
19104 (Prag => N,
19105 Prev => Prev);
19106 raise Pragma_Exit;
19107 end if;
19108 end if;
19110 Record_Rep_Item (Typ, N);
19111 end if;
19112 end No_Heap_Finalization;
19114 ---------------
19115 -- No_Inline --
19116 ---------------
19118 -- pragma No_Inline ( NAME {, NAME} );
19120 when Pragma_No_Inline =>
19121 GNAT_Pragma;
19122 Process_Inline (Suppressed);
19124 ---------------
19125 -- No_Return --
19126 ---------------
19128 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
19130 when Pragma_No_Return => No_Return : declare
19131 Arg : Node_Id;
19132 E : Entity_Id;
19133 Found : Boolean;
19134 Id : Node_Id;
19136 Ghost_Error_Posted : Boolean := False;
19137 -- Flag set when an error concerning the illegal mix of Ghost and
19138 -- non-Ghost subprograms is emitted.
19140 Ghost_Id : Entity_Id := Empty;
19141 -- The entity of the first Ghost procedure encountered while
19142 -- processing the arguments of the pragma.
19144 begin
19145 Ada_2005_Pragma;
19146 Check_At_Least_N_Arguments (1);
19148 -- Loop through arguments of pragma
19150 Arg := Arg1;
19151 while Present (Arg) loop
19152 Check_Arg_Is_Local_Name (Arg);
19153 Id := Get_Pragma_Arg (Arg);
19154 Analyze (Id);
19156 if not Is_Entity_Name (Id) then
19157 Error_Pragma_Arg ("entity name required", Arg);
19158 end if;
19160 if Etype (Id) = Any_Type then
19161 raise Pragma_Exit;
19162 end if;
19164 -- Loop to find matching procedures
19166 E := Entity (Id);
19168 Found := False;
19169 while Present (E)
19170 and then Scope (E) = Current_Scope
19171 loop
19172 if Ekind_In (E, E_Generic_Procedure, E_Procedure) then
19174 -- Check that the pragma is not applied to a body.
19175 -- First check the specless body case, to give a
19176 -- different error message. These checks do not apply
19177 -- if Relaxed_RM_Semantics, to accommodate other Ada
19178 -- compilers. Disable these checks under -gnatd.J.
19180 if not Debug_Flag_Dot_JJ then
19181 if Nkind (Parent (Declaration_Node (E))) =
19182 N_Subprogram_Body
19183 and then not Relaxed_RM_Semantics
19184 then
19185 Error_Pragma
19186 ("pragma% requires separate spec and must come "
19187 & "before body");
19188 end if;
19190 -- Now the "specful" body case
19192 if Rep_Item_Too_Late (E, N) then
19193 raise Pragma_Exit;
19194 end if;
19195 end if;
19197 Set_No_Return (E);
19199 -- A pragma that applies to a Ghost entity becomes Ghost
19200 -- for the purposes of legality checks and removal of
19201 -- ignored Ghost code.
19203 Mark_Ghost_Pragma (N, E);
19205 -- Capture the entity of the first Ghost procedure being
19206 -- processed for error detection purposes.
19208 if Is_Ghost_Entity (E) then
19209 if No (Ghost_Id) then
19210 Ghost_Id := E;
19211 end if;
19213 -- Otherwise the subprogram is non-Ghost. It is illegal
19214 -- to mix references to Ghost and non-Ghost entities
19215 -- (SPARK RM 6.9).
19217 elsif Present (Ghost_Id)
19218 and then not Ghost_Error_Posted
19219 then
19220 Ghost_Error_Posted := True;
19222 Error_Msg_Name_1 := Pname;
19223 Error_Msg_N
19224 ("pragma % cannot mention ghost and non-ghost "
19225 & "procedures", N);
19227 Error_Msg_Sloc := Sloc (Ghost_Id);
19228 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
19230 Error_Msg_Sloc := Sloc (E);
19231 Error_Msg_NE ("\& # declared as non-ghost", N, E);
19232 end if;
19234 -- Set flag on any alias as well
19236 if Is_Overloadable (E) and then Present (Alias (E)) then
19237 Set_No_Return (Alias (E));
19238 end if;
19240 Found := True;
19241 end if;
19243 exit when From_Aspect_Specification (N);
19244 E := Homonym (E);
19245 end loop;
19247 -- If entity in not in current scope it may be the enclosing
19248 -- suprogram body to which the aspect applies.
19250 if not Found then
19251 if Entity (Id) = Current_Scope
19252 and then From_Aspect_Specification (N)
19253 then
19254 Set_No_Return (Entity (Id));
19255 else
19256 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
19257 end if;
19258 end if;
19260 Next (Arg);
19261 end loop;
19262 end No_Return;
19264 -----------------
19265 -- No_Run_Time --
19266 -----------------
19268 -- pragma No_Run_Time;
19270 -- Note: this pragma is retained for backwards compatibility. See
19271 -- body of Rtsfind for full details on its handling.
19273 when Pragma_No_Run_Time =>
19274 GNAT_Pragma;
19275 Check_Valid_Configuration_Pragma;
19276 Check_Arg_Count (0);
19278 -- Remove backward compatibility if Build_Type is FSF or GPL and
19279 -- generate a warning.
19281 declare
19282 Ignore : constant Boolean := Build_Type in FSF .. GPL;
19283 begin
19284 if Ignore then
19285 Error_Pragma ("pragma% is ignored, has no effect??");
19286 else
19287 No_Run_Time_Mode := True;
19288 Configurable_Run_Time_Mode := True;
19290 -- Set Duration to 32 bits if word size is 32
19292 if Ttypes.System_Word_Size = 32 then
19293 Duration_32_Bits_On_Target := True;
19294 end if;
19296 -- Set appropriate restrictions
19298 Set_Restriction (No_Finalization, N);
19299 Set_Restriction (No_Exception_Handlers, N);
19300 Set_Restriction (Max_Tasks, N, 0);
19301 Set_Restriction (No_Tasking, N);
19302 end if;
19303 end;
19305 -----------------------
19306 -- No_Tagged_Streams --
19307 -----------------------
19309 -- pragma No_Tagged_Streams [([Entity => ]tagged_type_local_NAME)];
19311 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
19312 E : Entity_Id;
19313 E_Id : Node_Id;
19315 begin
19316 GNAT_Pragma;
19317 Check_At_Most_N_Arguments (1);
19319 -- One argument case
19321 if Arg_Count = 1 then
19322 Check_Optional_Identifier (Arg1, Name_Entity);
19323 Check_Arg_Is_Local_Name (Arg1);
19324 E_Id := Get_Pragma_Arg (Arg1);
19326 if Etype (E_Id) = Any_Type then
19327 return;
19328 end if;
19330 E := Entity (E_Id);
19332 Check_Duplicate_Pragma (E);
19334 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
19335 Error_Pragma_Arg
19336 ("argument for pragma% must be root tagged type", Arg1);
19337 end if;
19339 if Rep_Item_Too_Early (E, N)
19340 or else
19341 Rep_Item_Too_Late (E, N)
19342 then
19343 return;
19344 else
19345 Set_No_Tagged_Streams_Pragma (E, N);
19346 end if;
19348 -- Zero argument case
19350 else
19351 Check_Is_In_Decl_Part_Or_Package_Spec;
19352 No_Tagged_Streams := N;
19353 end if;
19354 end No_Tagged_Strms;
19356 ------------------------
19357 -- No_Strict_Aliasing --
19358 ------------------------
19360 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
19362 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
19363 E : Entity_Id;
19364 E_Id : Node_Id;
19366 begin
19367 GNAT_Pragma;
19368 Check_At_Most_N_Arguments (1);
19370 if Arg_Count = 0 then
19371 Check_Valid_Configuration_Pragma;
19372 Opt.No_Strict_Aliasing := True;
19374 else
19375 Check_Optional_Identifier (Arg2, Name_Entity);
19376 Check_Arg_Is_Local_Name (Arg1);
19377 E_Id := Get_Pragma_Arg (Arg1);
19379 if Etype (E_Id) = Any_Type then
19380 return;
19381 end if;
19383 E := Entity (E_Id);
19385 if not Is_Access_Type (E) then
19386 Error_Pragma_Arg ("pragma% requires access type", Arg1);
19387 end if;
19389 Set_No_Strict_Aliasing (Base_Type (E));
19390 end if;
19391 end No_Strict_Aliasing;
19393 -----------------------
19394 -- Normalize_Scalars --
19395 -----------------------
19397 -- pragma Normalize_Scalars;
19399 when Pragma_Normalize_Scalars =>
19400 Check_Ada_83_Warning;
19401 Check_Arg_Count (0);
19402 Check_Valid_Configuration_Pragma;
19404 -- Normalize_Scalars creates false positives in CodePeer, and
19405 -- incorrect negative results in GNATprove mode, so ignore this
19406 -- pragma in these modes.
19408 if not (CodePeer_Mode or GNATprove_Mode) then
19409 Normalize_Scalars := True;
19410 Init_Or_Norm_Scalars := True;
19411 end if;
19413 -----------------
19414 -- Obsolescent --
19415 -----------------
19417 -- pragma Obsolescent;
19419 -- pragma Obsolescent (
19420 -- [Message =>] static_string_EXPRESSION
19421 -- [,[Version =>] Ada_05]]);
19423 -- pragma Obsolescent (
19424 -- [Entity =>] NAME
19425 -- [,[Message =>] static_string_EXPRESSION
19426 -- [,[Version =>] Ada_05]] );
19428 when Pragma_Obsolescent => Obsolescent : declare
19429 Decl : Node_Id;
19430 Ename : Node_Id;
19432 procedure Set_Obsolescent (E : Entity_Id);
19433 -- Given an entity Ent, mark it as obsolescent if appropriate
19435 ---------------------
19436 -- Set_Obsolescent --
19437 ---------------------
19439 procedure Set_Obsolescent (E : Entity_Id) is
19440 Active : Boolean;
19441 Ent : Entity_Id;
19442 S : String_Id;
19444 begin
19445 Active := True;
19446 Ent := E;
19448 -- A pragma that applies to a Ghost entity becomes Ghost for
19449 -- the purposes of legality checks and removal of ignored Ghost
19450 -- code.
19452 Mark_Ghost_Pragma (N, E);
19454 -- Entity name was given
19456 if Present (Ename) then
19458 -- If entity name matches, we are fine. Save entity in
19459 -- pragma argument, for ASIS use.
19461 if Chars (Ename) = Chars (Ent) then
19462 Set_Entity (Ename, Ent);
19463 Generate_Reference (Ent, Ename);
19465 -- If entity name does not match, only possibility is an
19466 -- enumeration literal from an enumeration type declaration.
19468 elsif Ekind (Ent) /= E_Enumeration_Type then
19469 Error_Pragma
19470 ("pragma % entity name does not match declaration");
19472 else
19473 Ent := First_Literal (E);
19474 loop
19475 if No (Ent) then
19476 Error_Pragma
19477 ("pragma % entity name does not match any "
19478 & "enumeration literal");
19480 elsif Chars (Ent) = Chars (Ename) then
19481 Set_Entity (Ename, Ent);
19482 Generate_Reference (Ent, Ename);
19483 exit;
19485 else
19486 Ent := Next_Literal (Ent);
19487 end if;
19488 end loop;
19489 end if;
19490 end if;
19492 -- Ent points to entity to be marked
19494 if Arg_Count >= 1 then
19496 -- Deal with static string argument
19498 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
19499 S := Strval (Get_Pragma_Arg (Arg1));
19501 for J in 1 .. String_Length (S) loop
19502 if not In_Character_Range (Get_String_Char (S, J)) then
19503 Error_Pragma_Arg
19504 ("pragma% argument does not allow wide characters",
19505 Arg1);
19506 end if;
19507 end loop;
19509 Obsolescent_Warnings.Append
19510 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
19512 -- Check for Ada_05 parameter
19514 if Arg_Count /= 1 then
19515 Check_Arg_Count (2);
19517 declare
19518 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
19520 begin
19521 Check_Arg_Is_Identifier (Argx);
19523 if Chars (Argx) /= Name_Ada_05 then
19524 Error_Msg_Name_2 := Name_Ada_05;
19525 Error_Pragma_Arg
19526 ("only allowed argument for pragma% is %", Argx);
19527 end if;
19529 if Ada_Version_Explicit < Ada_2005
19530 or else not Warn_On_Ada_2005_Compatibility
19531 then
19532 Active := False;
19533 end if;
19534 end;
19535 end if;
19536 end if;
19538 -- Set flag if pragma active
19540 if Active then
19541 Set_Is_Obsolescent (Ent);
19542 end if;
19544 return;
19545 end Set_Obsolescent;
19547 -- Start of processing for pragma Obsolescent
19549 begin
19550 GNAT_Pragma;
19552 Check_At_Most_N_Arguments (3);
19554 -- See if first argument specifies an entity name
19556 if Arg_Count >= 1
19557 and then
19558 (Chars (Arg1) = Name_Entity
19559 or else
19560 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
19561 N_Identifier,
19562 N_Operator_Symbol))
19563 then
19564 Ename := Get_Pragma_Arg (Arg1);
19566 -- Eliminate first argument, so we can share processing
19568 Arg1 := Arg2;
19569 Arg2 := Arg3;
19570 Arg_Count := Arg_Count - 1;
19572 -- No Entity name argument given
19574 else
19575 Ename := Empty;
19576 end if;
19578 if Arg_Count >= 1 then
19579 Check_Optional_Identifier (Arg1, Name_Message);
19581 if Arg_Count = 2 then
19582 Check_Optional_Identifier (Arg2, Name_Version);
19583 end if;
19584 end if;
19586 -- Get immediately preceding declaration
19588 Decl := Prev (N);
19589 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
19590 Prev (Decl);
19591 end loop;
19593 -- Cases where we do not follow anything other than another pragma
19595 if No (Decl) then
19597 -- First case: library level compilation unit declaration with
19598 -- the pragma immediately following the declaration.
19600 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
19601 Set_Obsolescent
19602 (Defining_Entity (Unit (Parent (Parent (N)))));
19603 return;
19605 -- Case 2: library unit placement for package
19607 else
19608 declare
19609 Ent : constant Entity_Id := Find_Lib_Unit_Name;
19610 begin
19611 if Is_Package_Or_Generic_Package (Ent) then
19612 Set_Obsolescent (Ent);
19613 return;
19614 end if;
19615 end;
19616 end if;
19618 -- Cases where we must follow a declaration, including an
19619 -- abstract subprogram declaration, which is not in the
19620 -- other node subtypes.
19622 else
19623 if Nkind (Decl) not in N_Declaration
19624 and then Nkind (Decl) not in N_Later_Decl_Item
19625 and then Nkind (Decl) not in N_Generic_Declaration
19626 and then Nkind (Decl) not in N_Renaming_Declaration
19627 and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration
19628 then
19629 Error_Pragma
19630 ("pragma% misplaced, "
19631 & "must immediately follow a declaration");
19633 else
19634 Set_Obsolescent (Defining_Entity (Decl));
19635 return;
19636 end if;
19637 end if;
19638 end Obsolescent;
19640 --------------
19641 -- Optimize --
19642 --------------
19644 -- pragma Optimize (Time | Space | Off);
19646 -- The actual check for optimize is done in Gigi. Note that this
19647 -- pragma does not actually change the optimization setting, it
19648 -- simply checks that it is consistent with the pragma.
19650 when Pragma_Optimize =>
19651 Check_No_Identifiers;
19652 Check_Arg_Count (1);
19653 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
19655 ------------------------
19656 -- Optimize_Alignment --
19657 ------------------------
19659 -- pragma Optimize_Alignment (Time | Space | Off);
19661 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
19662 GNAT_Pragma;
19663 Check_No_Identifiers;
19664 Check_Arg_Count (1);
19665 Check_Valid_Configuration_Pragma;
19667 declare
19668 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
19669 begin
19670 case Nam is
19671 when Name_Off => Opt.Optimize_Alignment := 'O';
19672 when Name_Space => Opt.Optimize_Alignment := 'S';
19673 when Name_Time => Opt.Optimize_Alignment := 'T';
19675 when others =>
19676 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
19677 end case;
19678 end;
19680 -- Set indication that mode is set locally. If we are in fact in a
19681 -- configuration pragma file, this setting is harmless since the
19682 -- switch will get reset anyway at the start of each unit.
19684 Optimize_Alignment_Local := True;
19685 end Optimize_Alignment;
19687 -------------
19688 -- Ordered --
19689 -------------
19691 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
19693 when Pragma_Ordered => Ordered : declare
19694 Assoc : constant Node_Id := Arg1;
19695 Type_Id : Node_Id;
19696 Typ : Entity_Id;
19698 begin
19699 GNAT_Pragma;
19700 Check_No_Identifiers;
19701 Check_Arg_Count (1);
19702 Check_Arg_Is_Local_Name (Arg1);
19704 Type_Id := Get_Pragma_Arg (Assoc);
19705 Find_Type (Type_Id);
19706 Typ := Entity (Type_Id);
19708 if Typ = Any_Type then
19709 return;
19710 else
19711 Typ := Underlying_Type (Typ);
19712 end if;
19714 if not Is_Enumeration_Type (Typ) then
19715 Error_Pragma ("pragma% must specify enumeration type");
19716 end if;
19718 Check_First_Subtype (Arg1);
19719 Set_Has_Pragma_Ordered (Base_Type (Typ));
19720 end Ordered;
19722 -------------------
19723 -- Overflow_Mode --
19724 -------------------
19726 -- pragma Overflow_Mode
19727 -- ([General => ] MODE [, [Assertions => ] MODE]);
19729 -- MODE := STRICT | MINIMIZED | ELIMINATED
19731 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
19732 -- since System.Bignums makes this assumption. This is true of nearly
19733 -- all (all?) targets.
19735 when Pragma_Overflow_Mode => Overflow_Mode : declare
19736 function Get_Overflow_Mode
19737 (Name : Name_Id;
19738 Arg : Node_Id) return Overflow_Mode_Type;
19739 -- Function to process one pragma argument, Arg. If an identifier
19740 -- is present, it must be Name. Mode type is returned if a valid
19741 -- argument exists, otherwise an error is signalled.
19743 -----------------------
19744 -- Get_Overflow_Mode --
19745 -----------------------
19747 function Get_Overflow_Mode
19748 (Name : Name_Id;
19749 Arg : Node_Id) return Overflow_Mode_Type
19751 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
19753 begin
19754 Check_Optional_Identifier (Arg, Name);
19755 Check_Arg_Is_Identifier (Argx);
19757 if Chars (Argx) = Name_Strict then
19758 return Strict;
19760 elsif Chars (Argx) = Name_Minimized then
19761 return Minimized;
19763 elsif Chars (Argx) = Name_Eliminated then
19764 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
19765 Error_Pragma_Arg
19766 ("Eliminated not implemented on this target", Argx);
19767 else
19768 return Eliminated;
19769 end if;
19771 else
19772 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
19773 end if;
19774 end Get_Overflow_Mode;
19776 -- Start of processing for Overflow_Mode
19778 begin
19779 GNAT_Pragma;
19780 Check_At_Least_N_Arguments (1);
19781 Check_At_Most_N_Arguments (2);
19783 -- Process first argument
19785 Scope_Suppress.Overflow_Mode_General :=
19786 Get_Overflow_Mode (Name_General, Arg1);
19788 -- Case of only one argument
19790 if Arg_Count = 1 then
19791 Scope_Suppress.Overflow_Mode_Assertions :=
19792 Scope_Suppress.Overflow_Mode_General;
19794 -- Case of two arguments present
19796 else
19797 Scope_Suppress.Overflow_Mode_Assertions :=
19798 Get_Overflow_Mode (Name_Assertions, Arg2);
19799 end if;
19800 end Overflow_Mode;
19802 --------------------------
19803 -- Overriding Renamings --
19804 --------------------------
19806 -- pragma Overriding_Renamings;
19808 when Pragma_Overriding_Renamings =>
19809 GNAT_Pragma;
19810 Check_Arg_Count (0);
19811 Check_Valid_Configuration_Pragma;
19812 Overriding_Renamings := True;
19814 ----------
19815 -- Pack --
19816 ----------
19818 -- pragma Pack (first_subtype_LOCAL_NAME);
19820 when Pragma_Pack => Pack : declare
19821 Assoc : constant Node_Id := Arg1;
19822 Ctyp : Entity_Id;
19823 Ignore : Boolean := False;
19824 Typ : Entity_Id;
19825 Type_Id : Node_Id;
19827 begin
19828 Check_No_Identifiers;
19829 Check_Arg_Count (1);
19830 Check_Arg_Is_Local_Name (Arg1);
19831 Type_Id := Get_Pragma_Arg (Assoc);
19833 if not Is_Entity_Name (Type_Id)
19834 or else not Is_Type (Entity (Type_Id))
19835 then
19836 Error_Pragma_Arg
19837 ("argument for pragma% must be type or subtype", Arg1);
19838 end if;
19840 Find_Type (Type_Id);
19841 Typ := Entity (Type_Id);
19843 if Typ = Any_Type
19844 or else Rep_Item_Too_Early (Typ, N)
19845 then
19846 return;
19847 else
19848 Typ := Underlying_Type (Typ);
19849 end if;
19851 -- A pragma that applies to a Ghost entity becomes Ghost for the
19852 -- purposes of legality checks and removal of ignored Ghost code.
19854 Mark_Ghost_Pragma (N, Typ);
19856 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
19857 Error_Pragma ("pragma% must specify array or record type");
19858 end if;
19860 Check_First_Subtype (Arg1);
19861 Check_Duplicate_Pragma (Typ);
19863 -- Array type
19865 if Is_Array_Type (Typ) then
19866 Ctyp := Component_Type (Typ);
19868 -- Ignore pack that does nothing
19870 if Known_Static_Esize (Ctyp)
19871 and then Known_Static_RM_Size (Ctyp)
19872 and then Esize (Ctyp) = RM_Size (Ctyp)
19873 and then Addressable (Esize (Ctyp))
19874 then
19875 Ignore := True;
19876 end if;
19878 -- Process OK pragma Pack. Note that if there is a separate
19879 -- component clause present, the Pack will be cancelled. This
19880 -- processing is in Freeze.
19882 if not Rep_Item_Too_Late (Typ, N) then
19884 -- In CodePeer mode, we do not need complex front-end
19885 -- expansions related to pragma Pack, so disable handling
19886 -- of pragma Pack.
19888 if CodePeer_Mode then
19889 null;
19891 -- Normal case where we do the pack action
19893 else
19894 if not Ignore then
19895 Set_Is_Packed (Base_Type (Typ));
19896 Set_Has_Non_Standard_Rep (Base_Type (Typ));
19897 end if;
19899 Set_Has_Pragma_Pack (Base_Type (Typ));
19900 end if;
19901 end if;
19903 -- For record types, the pack is always effective
19905 else pragma Assert (Is_Record_Type (Typ));
19906 if not Rep_Item_Too_Late (Typ, N) then
19907 Set_Is_Packed (Base_Type (Typ));
19908 Set_Has_Pragma_Pack (Base_Type (Typ));
19909 Set_Has_Non_Standard_Rep (Base_Type (Typ));
19910 end if;
19911 end if;
19912 end Pack;
19914 ----------
19915 -- Page --
19916 ----------
19918 -- pragma Page;
19920 -- There is nothing to do here, since we did all the processing for
19921 -- this pragma in Par.Prag (so that it works properly even in syntax
19922 -- only mode).
19924 when Pragma_Page =>
19925 null;
19927 -------------
19928 -- Part_Of --
19929 -------------
19931 -- pragma Part_Of (ABSTRACT_STATE);
19933 -- ABSTRACT_STATE ::= NAME
19935 when Pragma_Part_Of => Part_Of : declare
19936 procedure Propagate_Part_Of
19937 (Pack_Id : Entity_Id;
19938 State_Id : Entity_Id;
19939 Instance : Node_Id);
19940 -- Propagate the Part_Of indicator to all abstract states and
19941 -- objects declared in the visible state space of a package
19942 -- denoted by Pack_Id. State_Id is the encapsulating state.
19943 -- Instance is the package instantiation node.
19945 -----------------------
19946 -- Propagate_Part_Of --
19947 -----------------------
19949 procedure Propagate_Part_Of
19950 (Pack_Id : Entity_Id;
19951 State_Id : Entity_Id;
19952 Instance : Node_Id)
19954 Has_Item : Boolean := False;
19955 -- Flag set when the visible state space contains at least one
19956 -- abstract state or variable.
19958 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
19959 -- Propagate the Part_Of indicator to all abstract states and
19960 -- objects declared in the visible state space of a package
19961 -- denoted by Pack_Id.
19963 -----------------------
19964 -- Propagate_Part_Of --
19965 -----------------------
19967 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
19968 Constits : Elist_Id;
19969 Item_Id : Entity_Id;
19971 begin
19972 -- Traverse the entity chain of the package and set relevant
19973 -- attributes of abstract states and objects declared in the
19974 -- visible state space of the package.
19976 Item_Id := First_Entity (Pack_Id);
19977 while Present (Item_Id)
19978 and then not In_Private_Part (Item_Id)
19979 loop
19980 -- Do not consider internally generated items
19982 if not Comes_From_Source (Item_Id) then
19983 null;
19985 -- Do not consider generic formals or their corresponding
19986 -- actuals because they are not part of a visible state.
19987 -- Note that both entities are marked as hidden.
19989 elsif Is_Hidden (Item_Id) then
19990 null;
19992 -- The Part_Of indicator turns an abstract state or an
19993 -- object into a constituent of the encapsulating state.
19994 -- Note that constants are considered here even though
19995 -- they may not depend on variable input. This check is
19996 -- left to the SPARK prover.
19998 elsif Ekind_In (Item_Id, E_Abstract_State,
19999 E_Constant,
20000 E_Variable)
20001 then
20002 Has_Item := True;
20003 Constits := Part_Of_Constituents (State_Id);
20005 if No (Constits) then
20006 Constits := New_Elmt_List;
20007 Set_Part_Of_Constituents (State_Id, Constits);
20008 end if;
20010 Append_Elmt (Item_Id, Constits);
20011 Set_Encapsulating_State (Item_Id, State_Id);
20013 -- Recursively handle nested packages and instantiations
20015 elsif Ekind (Item_Id) = E_Package then
20016 Propagate_Part_Of (Item_Id);
20017 end if;
20019 Next_Entity (Item_Id);
20020 end loop;
20021 end Propagate_Part_Of;
20023 -- Start of processing for Propagate_Part_Of
20025 begin
20026 Propagate_Part_Of (Pack_Id);
20028 -- Detect a package instantiation that is subject to a Part_Of
20029 -- indicator, but has no visible state.
20031 if not Has_Item then
20032 SPARK_Msg_NE
20033 ("package instantiation & has Part_Of indicator but "
20034 & "lacks visible state", Instance, Pack_Id);
20035 end if;
20036 end Propagate_Part_Of;
20038 -- Local variables
20040 Constits : Elist_Id;
20041 Encap : Node_Id;
20042 Encap_Id : Entity_Id;
20043 Item_Id : Entity_Id;
20044 Legal : Boolean;
20045 Stmt : Node_Id;
20047 -- Start of processing for Part_Of
20049 begin
20050 GNAT_Pragma;
20051 Check_No_Identifiers;
20052 Check_Arg_Count (1);
20054 Stmt := Find_Related_Context (N, Do_Checks => True);
20056 -- Object declaration
20058 if Nkind (Stmt) = N_Object_Declaration then
20059 null;
20061 -- Package instantiation
20063 elsif Nkind (Stmt) = N_Package_Instantiation then
20064 null;
20066 -- Single concurrent type declaration
20068 elsif Is_Single_Concurrent_Type_Declaration (Stmt) then
20069 null;
20071 -- Otherwise the pragma is associated with an illegal construct
20073 else
20074 Pragma_Misplaced;
20075 return;
20076 end if;
20078 -- Extract the entity of the related object declaration or package
20079 -- instantiation. In the case of the instantiation, use the entity
20080 -- of the instance spec.
20082 if Nkind (Stmt) = N_Package_Instantiation then
20083 Stmt := Instance_Spec (Stmt);
20084 end if;
20086 Item_Id := Defining_Entity (Stmt);
20088 -- A pragma that applies to a Ghost entity becomes Ghost for the
20089 -- purposes of legality checks and removal of ignored Ghost code.
20091 Mark_Ghost_Pragma (N, Item_Id);
20093 -- Chain the pragma on the contract for further processing by
20094 -- Analyze_Part_Of_In_Decl_Part or for completeness.
20096 Add_Contract_Item (N, Item_Id);
20098 -- A variable may act as constituent of a single concurrent type
20099 -- which in turn could be declared after the variable. Due to this
20100 -- discrepancy, the full analysis of indicator Part_Of is delayed
20101 -- until the end of the enclosing declarative region (see routine
20102 -- Analyze_Part_Of_In_Decl_Part).
20104 if Ekind (Item_Id) = E_Variable then
20105 null;
20107 -- Otherwise indicator Part_Of applies to a constant or a package
20108 -- instantiation.
20110 else
20111 Encap := Get_Pragma_Arg (Arg1);
20113 -- Detect any discrepancies between the placement of the
20114 -- constant or package instantiation with respect to state
20115 -- space and the encapsulating state.
20117 Analyze_Part_Of
20118 (Indic => N,
20119 Item_Id => Item_Id,
20120 Encap => Encap,
20121 Encap_Id => Encap_Id,
20122 Legal => Legal);
20124 if Legal then
20125 pragma Assert (Present (Encap_Id));
20127 if Ekind (Item_Id) = E_Constant then
20128 Constits := Part_Of_Constituents (Encap_Id);
20130 if No (Constits) then
20131 Constits := New_Elmt_List;
20132 Set_Part_Of_Constituents (Encap_Id, Constits);
20133 end if;
20135 Append_Elmt (Item_Id, Constits);
20136 Set_Encapsulating_State (Item_Id, Encap_Id);
20138 -- Propagate the Part_Of indicator to the visible state
20139 -- space of the package instantiation.
20141 else
20142 Propagate_Part_Of
20143 (Pack_Id => Item_Id,
20144 State_Id => Encap_Id,
20145 Instance => Stmt);
20146 end if;
20147 end if;
20148 end if;
20149 end Part_Of;
20151 ----------------------------------
20152 -- Partition_Elaboration_Policy --
20153 ----------------------------------
20155 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
20157 when Pragma_Partition_Elaboration_Policy => PEP : declare
20158 subtype PEP_Range is Name_Id
20159 range First_Partition_Elaboration_Policy_Name
20160 .. Last_Partition_Elaboration_Policy_Name;
20161 PEP_Val : PEP_Range;
20162 PEP : Character;
20164 begin
20165 Ada_2005_Pragma;
20166 Check_Arg_Count (1);
20167 Check_No_Identifiers;
20168 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
20169 Check_Valid_Configuration_Pragma;
20170 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
20172 case PEP_Val is
20173 when Name_Concurrent => PEP := 'C';
20174 when Name_Sequential => PEP := 'S';
20175 end case;
20177 if Partition_Elaboration_Policy /= ' '
20178 and then Partition_Elaboration_Policy /= PEP
20179 then
20180 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
20181 Error_Pragma
20182 ("partition elaboration policy incompatible with policy#");
20184 -- Set new policy, but always preserve System_Location since we
20185 -- like the error message with the run time name.
20187 else
20188 Partition_Elaboration_Policy := PEP;
20190 if Partition_Elaboration_Policy_Sloc /= System_Location then
20191 Partition_Elaboration_Policy_Sloc := Loc;
20192 end if;
20193 end if;
20194 end PEP;
20196 -------------
20197 -- Passive --
20198 -------------
20200 -- pragma Passive [(PASSIVE_FORM)];
20202 -- PASSIVE_FORM ::= Semaphore | No
20204 when Pragma_Passive =>
20205 GNAT_Pragma;
20207 if Nkind (Parent (N)) /= N_Task_Definition then
20208 Error_Pragma ("pragma% must be within task definition");
20209 end if;
20211 if Arg_Count /= 0 then
20212 Check_Arg_Count (1);
20213 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
20214 end if;
20216 ----------------------------------
20217 -- Preelaborable_Initialization --
20218 ----------------------------------
20220 -- pragma Preelaborable_Initialization (DIRECT_NAME);
20222 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
20223 Ent : Entity_Id;
20225 begin
20226 Ada_2005_Pragma;
20227 Check_Arg_Count (1);
20228 Check_No_Identifiers;
20229 Check_Arg_Is_Identifier (Arg1);
20230 Check_Arg_Is_Local_Name (Arg1);
20231 Check_First_Subtype (Arg1);
20232 Ent := Entity (Get_Pragma_Arg (Arg1));
20234 -- A pragma that applies to a Ghost entity becomes Ghost for the
20235 -- purposes of legality checks and removal of ignored Ghost code.
20237 Mark_Ghost_Pragma (N, Ent);
20239 -- The pragma may come from an aspect on a private declaration,
20240 -- even if the freeze point at which this is analyzed in the
20241 -- private part after the full view.
20243 if Has_Private_Declaration (Ent)
20244 and then From_Aspect_Specification (N)
20245 then
20246 null;
20248 -- Check appropriate type argument
20250 elsif Is_Private_Type (Ent)
20251 or else Is_Protected_Type (Ent)
20252 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
20254 -- AI05-0028: The pragma applies to all composite types. Note
20255 -- that we apply this binding interpretation to earlier versions
20256 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
20257 -- choice since there are other compilers that do the same.
20259 or else Is_Composite_Type (Ent)
20260 then
20261 null;
20263 else
20264 Error_Pragma_Arg
20265 ("pragma % can only be applied to private, formal derived, "
20266 & "protected, or composite type", Arg1);
20267 end if;
20269 -- Give an error if the pragma is applied to a protected type that
20270 -- does not qualify (due to having entries, or due to components
20271 -- that do not qualify).
20273 if Is_Protected_Type (Ent)
20274 and then not Has_Preelaborable_Initialization (Ent)
20275 then
20276 Error_Msg_N
20277 ("protected type & does not have preelaborable "
20278 & "initialization", Ent);
20280 -- Otherwise mark the type as definitely having preelaborable
20281 -- initialization.
20283 else
20284 Set_Known_To_Have_Preelab_Init (Ent);
20285 end if;
20287 if Has_Pragma_Preelab_Init (Ent)
20288 and then Warn_On_Redundant_Constructs
20289 then
20290 Error_Pragma ("?r?duplicate pragma%!");
20291 else
20292 Set_Has_Pragma_Preelab_Init (Ent);
20293 end if;
20294 end Preelab_Init;
20296 --------------------
20297 -- Persistent_BSS --
20298 --------------------
20300 -- pragma Persistent_BSS [(object_NAME)];
20302 when Pragma_Persistent_BSS => Persistent_BSS : declare
20303 Decl : Node_Id;
20304 Ent : Entity_Id;
20305 Prag : Node_Id;
20307 begin
20308 GNAT_Pragma;
20309 Check_At_Most_N_Arguments (1);
20311 -- Case of application to specific object (one argument)
20313 if Arg_Count = 1 then
20314 Check_Arg_Is_Library_Level_Local_Name (Arg1);
20316 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
20317 or else not
20318 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
20319 E_Constant)
20320 then
20321 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
20322 end if;
20324 Ent := Entity (Get_Pragma_Arg (Arg1));
20326 -- A pragma that applies to a Ghost entity becomes Ghost for
20327 -- the purposes of legality checks and removal of ignored Ghost
20328 -- code.
20330 Mark_Ghost_Pragma (N, Ent);
20332 -- Check for duplication before inserting in list of
20333 -- representation items.
20335 Check_Duplicate_Pragma (Ent);
20337 if Rep_Item_Too_Late (Ent, N) then
20338 return;
20339 end if;
20341 Decl := Parent (Ent);
20343 if Present (Expression (Decl)) then
20344 Error_Pragma_Arg
20345 ("object for pragma% cannot have initialization", Arg1);
20346 end if;
20348 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
20349 Error_Pragma_Arg
20350 ("object type for pragma% is not potentially persistent",
20351 Arg1);
20352 end if;
20354 Prag :=
20355 Make_Linker_Section_Pragma
20356 (Ent, Sloc (N), ".persistent.bss");
20357 Insert_After (N, Prag);
20358 Analyze (Prag);
20360 -- Case of use as configuration pragma with no arguments
20362 else
20363 Check_Valid_Configuration_Pragma;
20364 Persistent_BSS_Mode := True;
20365 end if;
20366 end Persistent_BSS;
20368 --------------------
20369 -- Rename_Pragma --
20370 --------------------
20372 -- pragma Rename_Pragma (
20373 -- [New_Name =>] IDENTIFIER,
20374 -- [Renamed =>] pragma_IDENTIFIER);
20376 when Pragma_Rename_Pragma => Rename_Pragma : declare
20377 New_Name : constant Node_Id := Get_Pragma_Arg (Arg1);
20378 Old_Name : constant Node_Id := Get_Pragma_Arg (Arg2);
20380 begin
20381 GNAT_Pragma;
20382 Check_Valid_Configuration_Pragma;
20383 Check_Arg_Count (2);
20384 Check_Optional_Identifier (Arg1, Name_New_Name);
20385 Check_Optional_Identifier (Arg2, Name_Renamed);
20387 if Nkind (New_Name) /= N_Identifier then
20388 Error_Pragma_Arg ("identifier expected", Arg1);
20389 end if;
20391 if Nkind (Old_Name) /= N_Identifier then
20392 Error_Pragma_Arg ("identifier expected", Arg2);
20393 end if;
20395 -- The New_Name arg should not be an existing pragma (but we allow
20396 -- it; it's just a warning). The Old_Name arg must be an existing
20397 -- pragma.
20399 if Is_Pragma_Name (Chars (New_Name)) then
20400 Error_Pragma_Arg ("??pragma is already defined", Arg1);
20401 end if;
20403 if not Is_Pragma_Name (Chars (Old_Name)) then
20404 Error_Pragma_Arg ("existing pragma name expected", Arg1);
20405 end if;
20407 Map_Pragma_Name (From => Chars (New_Name), To => Chars (Old_Name));
20408 end Rename_Pragma;
20410 -------------
20411 -- Polling --
20412 -------------
20414 -- pragma Polling (ON | OFF);
20416 when Pragma_Polling =>
20417 GNAT_Pragma;
20418 Check_Arg_Count (1);
20419 Check_No_Identifiers;
20420 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
20421 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
20423 -----------------------------------
20424 -- Post/Post_Class/Postcondition --
20425 -----------------------------------
20427 -- pragma Post (Boolean_EXPRESSION);
20428 -- pragma Post_Class (Boolean_EXPRESSION);
20429 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
20430 -- [,[Message =>] String_EXPRESSION]);
20432 -- Characteristics:
20434 -- * Analysis - The annotation undergoes initial checks to verify
20435 -- the legal placement and context. Secondary checks preanalyze the
20436 -- expression in:
20438 -- Analyze_Pre_Post_Condition_In_Decl_Part
20440 -- * Expansion - The annotation is expanded during the expansion of
20441 -- the related subprogram [body] contract as performed in:
20443 -- Expand_Subprogram_Contract
20445 -- * Template - The annotation utilizes the generic template of the
20446 -- related subprogram [body] when it is:
20448 -- aspect on subprogram declaration
20449 -- aspect on stand-alone subprogram body
20450 -- pragma on stand-alone subprogram body
20452 -- The annotation must prepare its own template when it is:
20454 -- pragma on subprogram declaration
20456 -- * Globals - Capture of global references must occur after full
20457 -- analysis.
20459 -- * Instance - The annotation is instantiated automatically when
20460 -- the related generic subprogram [body] is instantiated except for
20461 -- the "pragma on subprogram declaration" case. In that scenario
20462 -- the annotation must instantiate itself.
20464 when Pragma_Post
20465 | Pragma_Post_Class
20466 | Pragma_Postcondition
20468 Analyze_Pre_Post_Condition;
20470 --------------------------------
20471 -- Pre/Pre_Class/Precondition --
20472 --------------------------------
20474 -- pragma Pre (Boolean_EXPRESSION);
20475 -- pragma Pre_Class (Boolean_EXPRESSION);
20476 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
20477 -- [,[Message =>] String_EXPRESSION]);
20479 -- Characteristics:
20481 -- * Analysis - The annotation undergoes initial checks to verify
20482 -- the legal placement and context. Secondary checks preanalyze the
20483 -- expression in:
20485 -- Analyze_Pre_Post_Condition_In_Decl_Part
20487 -- * Expansion - The annotation is expanded during the expansion of
20488 -- the related subprogram [body] contract as performed in:
20490 -- Expand_Subprogram_Contract
20492 -- * Template - The annotation utilizes the generic template of the
20493 -- related subprogram [body] when it is:
20495 -- aspect on subprogram declaration
20496 -- aspect on stand-alone subprogram body
20497 -- pragma on stand-alone subprogram body
20499 -- The annotation must prepare its own template when it is:
20501 -- pragma on subprogram declaration
20503 -- * Globals - Capture of global references must occur after full
20504 -- analysis.
20506 -- * Instance - The annotation is instantiated automatically when
20507 -- the related generic subprogram [body] is instantiated except for
20508 -- the "pragma on subprogram declaration" case. In that scenario
20509 -- the annotation must instantiate itself.
20511 when Pragma_Pre
20512 | Pragma_Pre_Class
20513 | Pragma_Precondition
20515 Analyze_Pre_Post_Condition;
20517 ---------------
20518 -- Predicate --
20519 ---------------
20521 -- pragma Predicate
20522 -- ([Entity =>] type_LOCAL_NAME,
20523 -- [Check =>] boolean_EXPRESSION);
20525 when Pragma_Predicate => Predicate : declare
20526 Discard : Boolean;
20527 Typ : Entity_Id;
20528 Type_Id : Node_Id;
20530 begin
20531 GNAT_Pragma;
20532 Check_Arg_Count (2);
20533 Check_Optional_Identifier (Arg1, Name_Entity);
20534 Check_Optional_Identifier (Arg2, Name_Check);
20536 Check_Arg_Is_Local_Name (Arg1);
20538 Type_Id := Get_Pragma_Arg (Arg1);
20539 Find_Type (Type_Id);
20540 Typ := Entity (Type_Id);
20542 if Typ = Any_Type then
20543 return;
20544 end if;
20546 -- A pragma that applies to a Ghost entity becomes Ghost for the
20547 -- purposes of legality checks and removal of ignored Ghost code.
20549 Mark_Ghost_Pragma (N, Typ);
20551 -- The remaining processing is simply to link the pragma on to
20552 -- the rep item chain, for processing when the type is frozen.
20553 -- This is accomplished by a call to Rep_Item_Too_Late. We also
20554 -- mark the type as having predicates.
20556 -- If the current policy for predicate checking is Ignore mark the
20557 -- subtype accordingly. In the case of predicates we consider them
20558 -- enabled unless Ignore is specified (either directly or with a
20559 -- general Assertion_Policy pragma) to preserve existing warnings.
20561 Set_Has_Predicates (Typ);
20563 -- Indicate that the pragma must be processed at the point the
20564 -- type is frozen, as is done for the corresponding aspect.
20566 Set_Has_Delayed_Aspects (Typ);
20567 Set_Has_Delayed_Freeze (Typ);
20569 Set_Predicates_Ignored (Typ,
20570 Present (Check_Policy_List)
20571 and then
20572 Policy_In_Effect (Name_Dynamic_Predicate) = Name_Ignore);
20573 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
20574 end Predicate;
20576 -----------------------
20577 -- Predicate_Failure --
20578 -----------------------
20580 -- pragma Predicate_Failure
20581 -- ([Entity =>] type_LOCAL_NAME,
20582 -- [Message =>] string_EXPRESSION);
20584 when Pragma_Predicate_Failure => Predicate_Failure : declare
20585 Discard : Boolean;
20586 Typ : Entity_Id;
20587 Type_Id : Node_Id;
20589 begin
20590 GNAT_Pragma;
20591 Check_Arg_Count (2);
20592 Check_Optional_Identifier (Arg1, Name_Entity);
20593 Check_Optional_Identifier (Arg2, Name_Message);
20595 Check_Arg_Is_Local_Name (Arg1);
20597 Type_Id := Get_Pragma_Arg (Arg1);
20598 Find_Type (Type_Id);
20599 Typ := Entity (Type_Id);
20601 if Typ = Any_Type then
20602 return;
20603 end if;
20605 -- A pragma that applies to a Ghost entity becomes Ghost for the
20606 -- purposes of legality checks and removal of ignored Ghost code.
20608 Mark_Ghost_Pragma (N, Typ);
20610 -- The remaining processing is simply to link the pragma on to
20611 -- the rep item chain, for processing when the type is frozen.
20612 -- This is accomplished by a call to Rep_Item_Too_Late.
20614 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
20615 end Predicate_Failure;
20617 ------------------
20618 -- Preelaborate --
20619 ------------------
20621 -- pragma Preelaborate [(library_unit_NAME)];
20623 -- Set the flag Is_Preelaborated of program unit name entity
20625 when Pragma_Preelaborate => Preelaborate : declare
20626 Pa : constant Node_Id := Parent (N);
20627 Pk : constant Node_Kind := Nkind (Pa);
20628 Ent : Entity_Id;
20630 begin
20631 Check_Ada_83_Warning;
20632 Check_Valid_Library_Unit_Pragma;
20634 if Nkind (N) = N_Null_Statement then
20635 return;
20636 end if;
20638 Ent := Find_Lib_Unit_Name;
20640 -- A pragma that applies to a Ghost entity becomes Ghost for the
20641 -- purposes of legality checks and removal of ignored Ghost code.
20643 Mark_Ghost_Pragma (N, Ent);
20644 Check_Duplicate_Pragma (Ent);
20646 -- This filters out pragmas inside generic parents that show up
20647 -- inside instantiations. Pragmas that come from aspects in the
20648 -- unit are not ignored.
20650 if Present (Ent) then
20651 if Pk = N_Package_Specification
20652 and then Present (Generic_Parent (Pa))
20653 and then not From_Aspect_Specification (N)
20654 then
20655 null;
20657 else
20658 if not Debug_Flag_U then
20659 Set_Is_Preelaborated (Ent);
20661 if Legacy_Elaboration_Checks then
20662 Set_Suppress_Elaboration_Warnings (Ent);
20663 end if;
20664 end if;
20665 end if;
20666 end if;
20667 end Preelaborate;
20669 -------------------------------
20670 -- Prefix_Exception_Messages --
20671 -------------------------------
20673 -- pragma Prefix_Exception_Messages;
20675 when Pragma_Prefix_Exception_Messages =>
20676 GNAT_Pragma;
20677 Check_Valid_Configuration_Pragma;
20678 Check_Arg_Count (0);
20679 Prefix_Exception_Messages := True;
20681 --------------
20682 -- Priority --
20683 --------------
20685 -- pragma Priority (EXPRESSION);
20687 when Pragma_Priority => Priority : declare
20688 P : constant Node_Id := Parent (N);
20689 Arg : Node_Id;
20690 Ent : Entity_Id;
20692 begin
20693 Check_No_Identifiers;
20694 Check_Arg_Count (1);
20696 -- Subprogram case
20698 if Nkind (P) = N_Subprogram_Body then
20699 Check_In_Main_Program;
20701 Ent := Defining_Unit_Name (Specification (P));
20703 if Nkind (Ent) = N_Defining_Program_Unit_Name then
20704 Ent := Defining_Identifier (Ent);
20705 end if;
20707 Arg := Get_Pragma_Arg (Arg1);
20708 Analyze_And_Resolve (Arg, Standard_Integer);
20710 -- Must be static
20712 if not Is_OK_Static_Expression (Arg) then
20713 Flag_Non_Static_Expr
20714 ("main subprogram priority is not static!", Arg);
20715 raise Pragma_Exit;
20717 -- If constraint error, then we already signalled an error
20719 elsif Raises_Constraint_Error (Arg) then
20720 null;
20722 -- Otherwise check in range except if Relaxed_RM_Semantics
20723 -- where we ignore the value if out of range.
20725 else
20726 if not Relaxed_RM_Semantics
20727 and then not Is_In_Range (Arg, RTE (RE_Priority))
20728 then
20729 Error_Pragma_Arg
20730 ("main subprogram priority is out of range", Arg1);
20731 else
20732 Set_Main_Priority
20733 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
20734 end if;
20735 end if;
20737 -- Load an arbitrary entity from System.Tasking.Stages or
20738 -- System.Tasking.Restricted.Stages (depending on the
20739 -- supported profile) to make sure that one of these packages
20740 -- is implicitly with'ed, since we need to have the tasking
20741 -- run time active for the pragma Priority to have any effect.
20742 -- Previously we with'ed the package System.Tasking, but this
20743 -- package does not trigger the required initialization of the
20744 -- run-time library.
20746 declare
20747 Discard : Entity_Id;
20748 pragma Warnings (Off, Discard);
20749 begin
20750 if Restricted_Profile then
20751 Discard := RTE (RE_Activate_Restricted_Tasks);
20752 else
20753 Discard := RTE (RE_Activate_Tasks);
20754 end if;
20755 end;
20757 -- Task or Protected, must be of type Integer
20759 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
20760 Arg := Get_Pragma_Arg (Arg1);
20761 Ent := Defining_Identifier (Parent (P));
20763 -- The expression must be analyzed in the special manner
20764 -- described in "Handling of Default and Per-Object
20765 -- Expressions" in sem.ads.
20767 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
20769 if not Is_OK_Static_Expression (Arg) then
20770 Check_Restriction (Static_Priorities, Arg);
20771 end if;
20773 -- Anything else is incorrect
20775 else
20776 Pragma_Misplaced;
20777 end if;
20779 -- Check duplicate pragma before we chain the pragma in the Rep
20780 -- Item chain of Ent.
20782 Check_Duplicate_Pragma (Ent);
20783 Record_Rep_Item (Ent, N);
20784 end Priority;
20786 -----------------------------------
20787 -- Priority_Specific_Dispatching --
20788 -----------------------------------
20790 -- pragma Priority_Specific_Dispatching (
20791 -- policy_IDENTIFIER,
20792 -- first_priority_EXPRESSION,
20793 -- last_priority_EXPRESSION);
20795 when Pragma_Priority_Specific_Dispatching =>
20796 Priority_Specific_Dispatching : declare
20797 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
20798 -- This is the entity System.Any_Priority;
20800 DP : Character;
20801 Lower_Bound : Node_Id;
20802 Upper_Bound : Node_Id;
20803 Lower_Val : Uint;
20804 Upper_Val : Uint;
20806 begin
20807 Ada_2005_Pragma;
20808 Check_Arg_Count (3);
20809 Check_No_Identifiers;
20810 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
20811 Check_Valid_Configuration_Pragma;
20812 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
20813 DP := Fold_Upper (Name_Buffer (1));
20815 Lower_Bound := Get_Pragma_Arg (Arg2);
20816 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
20817 Lower_Val := Expr_Value (Lower_Bound);
20819 Upper_Bound := Get_Pragma_Arg (Arg3);
20820 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
20821 Upper_Val := Expr_Value (Upper_Bound);
20823 -- It is not allowed to use Task_Dispatching_Policy and
20824 -- Priority_Specific_Dispatching in the same partition.
20826 if Task_Dispatching_Policy /= ' ' then
20827 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
20828 Error_Pragma
20829 ("pragma% incompatible with Task_Dispatching_Policy#");
20831 -- Check lower bound in range
20833 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
20834 or else
20835 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
20836 then
20837 Error_Pragma_Arg
20838 ("first_priority is out of range", Arg2);
20840 -- Check upper bound in range
20842 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
20843 or else
20844 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
20845 then
20846 Error_Pragma_Arg
20847 ("last_priority is out of range", Arg3);
20849 -- Check that the priority range is valid
20851 elsif Lower_Val > Upper_Val then
20852 Error_Pragma
20853 ("last_priority_expression must be greater than or equal to "
20854 & "first_priority_expression");
20856 -- Store the new policy, but always preserve System_Location since
20857 -- we like the error message with the run-time name.
20859 else
20860 -- Check overlapping in the priority ranges specified in other
20861 -- Priority_Specific_Dispatching pragmas within the same
20862 -- partition. We can only check those we know about.
20864 for J in
20865 Specific_Dispatching.First .. Specific_Dispatching.Last
20866 loop
20867 if Specific_Dispatching.Table (J).First_Priority in
20868 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
20869 or else Specific_Dispatching.Table (J).Last_Priority in
20870 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
20871 then
20872 Error_Msg_Sloc :=
20873 Specific_Dispatching.Table (J).Pragma_Loc;
20874 Error_Pragma
20875 ("priority range overlaps with "
20876 & "Priority_Specific_Dispatching#");
20877 end if;
20878 end loop;
20880 -- The use of Priority_Specific_Dispatching is incompatible
20881 -- with Task_Dispatching_Policy.
20883 if Task_Dispatching_Policy /= ' ' then
20884 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
20885 Error_Pragma
20886 ("Priority_Specific_Dispatching incompatible "
20887 & "with Task_Dispatching_Policy#");
20888 end if;
20890 -- The use of Priority_Specific_Dispatching forces ceiling
20891 -- locking policy.
20893 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
20894 Error_Msg_Sloc := Locking_Policy_Sloc;
20895 Error_Pragma
20896 ("Priority_Specific_Dispatching incompatible "
20897 & "with Locking_Policy#");
20899 -- Set the Ceiling_Locking policy, but preserve System_Location
20900 -- since we like the error message with the run time name.
20902 else
20903 Locking_Policy := 'C';
20905 if Locking_Policy_Sloc /= System_Location then
20906 Locking_Policy_Sloc := Loc;
20907 end if;
20908 end if;
20910 -- Add entry in the table
20912 Specific_Dispatching.Append
20913 ((Dispatching_Policy => DP,
20914 First_Priority => UI_To_Int (Lower_Val),
20915 Last_Priority => UI_To_Int (Upper_Val),
20916 Pragma_Loc => Loc));
20917 end if;
20918 end Priority_Specific_Dispatching;
20920 -------------
20921 -- Profile --
20922 -------------
20924 -- pragma Profile (profile_IDENTIFIER);
20926 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
20928 when Pragma_Profile =>
20929 Ada_2005_Pragma;
20930 Check_Arg_Count (1);
20931 Check_Valid_Configuration_Pragma;
20932 Check_No_Identifiers;
20934 declare
20935 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
20937 begin
20938 if Chars (Argx) = Name_Ravenscar then
20939 Set_Ravenscar_Profile (Ravenscar, N);
20941 elsif Chars (Argx) = Name_Gnat_Extended_Ravenscar then
20942 Set_Ravenscar_Profile (GNAT_Extended_Ravenscar, N);
20944 elsif Chars (Argx) = Name_Gnat_Ravenscar_EDF then
20945 Set_Ravenscar_Profile (GNAT_Ravenscar_EDF, N);
20947 elsif Chars (Argx) = Name_Restricted then
20948 Set_Profile_Restrictions
20949 (Restricted,
20950 N, Warn => Treat_Restrictions_As_Warnings);
20952 elsif Chars (Argx) = Name_Rational then
20953 Set_Rational_Profile;
20955 elsif Chars (Argx) = Name_No_Implementation_Extensions then
20956 Set_Profile_Restrictions
20957 (No_Implementation_Extensions,
20958 N, Warn => Treat_Restrictions_As_Warnings);
20960 else
20961 Error_Pragma_Arg ("& is not a valid profile", Argx);
20962 end if;
20963 end;
20965 ----------------------
20966 -- Profile_Warnings --
20967 ----------------------
20969 -- pragma Profile_Warnings (profile_IDENTIFIER);
20971 -- profile_IDENTIFIER => Restricted | Ravenscar
20973 when Pragma_Profile_Warnings =>
20974 GNAT_Pragma;
20975 Check_Arg_Count (1);
20976 Check_Valid_Configuration_Pragma;
20977 Check_No_Identifiers;
20979 declare
20980 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
20982 begin
20983 if Chars (Argx) = Name_Ravenscar then
20984 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
20986 elsif Chars (Argx) = Name_Restricted then
20987 Set_Profile_Restrictions (Restricted, N, Warn => True);
20989 elsif Chars (Argx) = Name_No_Implementation_Extensions then
20990 Set_Profile_Restrictions
20991 (No_Implementation_Extensions, N, Warn => True);
20993 else
20994 Error_Pragma_Arg ("& is not a valid profile", Argx);
20995 end if;
20996 end;
20998 --------------------------
20999 -- Propagate_Exceptions --
21000 --------------------------
21002 -- pragma Propagate_Exceptions;
21004 -- Note: this pragma is obsolete and has no effect
21006 when Pragma_Propagate_Exceptions =>
21007 GNAT_Pragma;
21008 Check_Arg_Count (0);
21010 if Warn_On_Obsolescent_Feature then
21011 Error_Msg_N
21012 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
21013 "and has no effect?j?", N);
21014 end if;
21016 -----------------------------
21017 -- Provide_Shift_Operators --
21018 -----------------------------
21020 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
21022 when Pragma_Provide_Shift_Operators =>
21023 Provide_Shift_Operators : declare
21024 Ent : Entity_Id;
21026 procedure Declare_Shift_Operator (Nam : Name_Id);
21027 -- Insert declaration and pragma Instrinsic for named shift op
21029 ----------------------------
21030 -- Declare_Shift_Operator --
21031 ----------------------------
21033 procedure Declare_Shift_Operator (Nam : Name_Id) is
21034 Func : Node_Id;
21035 Import : Node_Id;
21037 begin
21038 Func :=
21039 Make_Subprogram_Declaration (Loc,
21040 Make_Function_Specification (Loc,
21041 Defining_Unit_Name =>
21042 Make_Defining_Identifier (Loc, Chars => Nam),
21044 Result_Definition =>
21045 Make_Identifier (Loc, Chars => Chars (Ent)),
21047 Parameter_Specifications => New_List (
21048 Make_Parameter_Specification (Loc,
21049 Defining_Identifier =>
21050 Make_Defining_Identifier (Loc, Name_Value),
21051 Parameter_Type =>
21052 Make_Identifier (Loc, Chars => Chars (Ent))),
21054 Make_Parameter_Specification (Loc,
21055 Defining_Identifier =>
21056 Make_Defining_Identifier (Loc, Name_Amount),
21057 Parameter_Type =>
21058 New_Occurrence_Of (Standard_Natural, Loc)))));
21060 Import :=
21061 Make_Pragma (Loc,
21062 Chars => Name_Import,
21063 Pragma_Argument_Associations => New_List (
21064 Make_Pragma_Argument_Association (Loc,
21065 Expression => Make_Identifier (Loc, Name_Intrinsic)),
21066 Make_Pragma_Argument_Association (Loc,
21067 Expression => Make_Identifier (Loc, Nam))));
21069 Insert_After (N, Import);
21070 Insert_After (N, Func);
21071 end Declare_Shift_Operator;
21073 -- Start of processing for Provide_Shift_Operators
21075 begin
21076 GNAT_Pragma;
21077 Check_Arg_Count (1);
21078 Check_Arg_Is_Local_Name (Arg1);
21080 Arg1 := Get_Pragma_Arg (Arg1);
21082 -- We must have an entity name
21084 if not Is_Entity_Name (Arg1) then
21085 Error_Pragma_Arg
21086 ("pragma % must apply to integer first subtype", Arg1);
21087 end if;
21089 -- If no Entity, means there was a prior error so ignore
21091 if Present (Entity (Arg1)) then
21092 Ent := Entity (Arg1);
21094 -- Apply error checks
21096 if not Is_First_Subtype (Ent) then
21097 Error_Pragma_Arg
21098 ("cannot apply pragma %",
21099 "\& is not a first subtype",
21100 Arg1);
21102 elsif not Is_Integer_Type (Ent) then
21103 Error_Pragma_Arg
21104 ("cannot apply pragma %",
21105 "\& is not an integer type",
21106 Arg1);
21108 elsif Has_Shift_Operator (Ent) then
21109 Error_Pragma_Arg
21110 ("cannot apply pragma %",
21111 "\& already has declared shift operators",
21112 Arg1);
21114 elsif Is_Frozen (Ent) then
21115 Error_Pragma_Arg
21116 ("pragma % appears too late",
21117 "\& is already frozen",
21118 Arg1);
21119 end if;
21121 -- Now declare the operators. We do this during analysis rather
21122 -- than expansion, since we want the operators available if we
21123 -- are operating in -gnatc or ASIS mode.
21125 Declare_Shift_Operator (Name_Rotate_Left);
21126 Declare_Shift_Operator (Name_Rotate_Right);
21127 Declare_Shift_Operator (Name_Shift_Left);
21128 Declare_Shift_Operator (Name_Shift_Right);
21129 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
21130 end if;
21131 end Provide_Shift_Operators;
21133 ------------------
21134 -- Psect_Object --
21135 ------------------
21137 -- pragma Psect_Object (
21138 -- [Internal =>] LOCAL_NAME,
21139 -- [, [External =>] EXTERNAL_SYMBOL]
21140 -- [, [Size =>] EXTERNAL_SYMBOL]);
21142 when Pragma_Common_Object
21143 | Pragma_Psect_Object
21145 Psect_Object : declare
21146 Args : Args_List (1 .. 3);
21147 Names : constant Name_List (1 .. 3) := (
21148 Name_Internal,
21149 Name_External,
21150 Name_Size);
21152 Internal : Node_Id renames Args (1);
21153 External : Node_Id renames Args (2);
21154 Size : Node_Id renames Args (3);
21156 Def_Id : Entity_Id;
21158 procedure Check_Arg (Arg : Node_Id);
21159 -- Checks that argument is either a string literal or an
21160 -- identifier, and posts error message if not.
21162 ---------------
21163 -- Check_Arg --
21164 ---------------
21166 procedure Check_Arg (Arg : Node_Id) is
21167 begin
21168 if not Nkind_In (Original_Node (Arg),
21169 N_String_Literal,
21170 N_Identifier)
21171 then
21172 Error_Pragma_Arg
21173 ("inappropriate argument for pragma %", Arg);
21174 end if;
21175 end Check_Arg;
21177 -- Start of processing for Common_Object/Psect_Object
21179 begin
21180 GNAT_Pragma;
21181 Gather_Associations (Names, Args);
21182 Process_Extended_Import_Export_Internal_Arg (Internal);
21184 Def_Id := Entity (Internal);
21186 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
21187 Error_Pragma_Arg
21188 ("pragma% must designate an object", Internal);
21189 end if;
21191 Check_Arg (Internal);
21193 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
21194 Error_Pragma_Arg
21195 ("cannot use pragma% for imported/exported object",
21196 Internal);
21197 end if;
21199 if Is_Concurrent_Type (Etype (Internal)) then
21200 Error_Pragma_Arg
21201 ("cannot specify pragma % for task/protected object",
21202 Internal);
21203 end if;
21205 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
21206 or else
21207 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
21208 then
21209 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
21210 end if;
21212 if Ekind (Def_Id) = E_Constant then
21213 Error_Pragma_Arg
21214 ("cannot specify pragma % for a constant", Internal);
21215 end if;
21217 if Is_Record_Type (Etype (Internal)) then
21218 declare
21219 Ent : Entity_Id;
21220 Decl : Entity_Id;
21222 begin
21223 Ent := First_Entity (Etype (Internal));
21224 while Present (Ent) loop
21225 Decl := Declaration_Node (Ent);
21227 if Ekind (Ent) = E_Component
21228 and then Nkind (Decl) = N_Component_Declaration
21229 and then Present (Expression (Decl))
21230 and then Warn_On_Export_Import
21231 then
21232 Error_Msg_N
21233 ("?x?object for pragma % has defaults", Internal);
21234 exit;
21236 else
21237 Next_Entity (Ent);
21238 end if;
21239 end loop;
21240 end;
21241 end if;
21243 if Present (Size) then
21244 Check_Arg (Size);
21245 end if;
21247 if Present (External) then
21248 Check_Arg_Is_External_Name (External);
21249 end if;
21251 -- If all error tests pass, link pragma on to the rep item chain
21253 Record_Rep_Item (Def_Id, N);
21254 end Psect_Object;
21256 ----------
21257 -- Pure --
21258 ----------
21260 -- pragma Pure [(library_unit_NAME)];
21262 when Pragma_Pure => Pure : declare
21263 Ent : Entity_Id;
21265 begin
21266 Check_Ada_83_Warning;
21268 -- If the pragma comes from a subprogram instantiation, nothing to
21269 -- check, this can happen at any level of nesting.
21271 if Is_Wrapper_Package (Current_Scope) then
21272 return;
21273 else
21274 Check_Valid_Library_Unit_Pragma;
21275 end if;
21277 if Nkind (N) = N_Null_Statement then
21278 return;
21279 end if;
21281 Ent := Find_Lib_Unit_Name;
21283 -- A pragma that applies to a Ghost entity becomes Ghost for the
21284 -- purposes of legality checks and removal of ignored Ghost code.
21286 Mark_Ghost_Pragma (N, Ent);
21288 if not Debug_Flag_U then
21289 Set_Is_Pure (Ent);
21290 Set_Has_Pragma_Pure (Ent);
21292 if Legacy_Elaboration_Checks then
21293 Set_Suppress_Elaboration_Warnings (Ent);
21294 end if;
21295 end if;
21296 end Pure;
21298 -------------------
21299 -- Pure_Function --
21300 -------------------
21302 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
21304 when Pragma_Pure_Function => Pure_Function : declare
21305 Def_Id : Entity_Id;
21306 E : Entity_Id;
21307 E_Id : Node_Id;
21308 Effective : Boolean := False;
21309 Orig_Def : Entity_Id;
21310 Same_Decl : Boolean := False;
21312 begin
21313 GNAT_Pragma;
21314 Check_Arg_Count (1);
21315 Check_Optional_Identifier (Arg1, Name_Entity);
21316 Check_Arg_Is_Local_Name (Arg1);
21317 E_Id := Get_Pragma_Arg (Arg1);
21319 if Etype (E_Id) = Any_Type then
21320 return;
21321 end if;
21323 -- Loop through homonyms (overloadings) of referenced entity
21325 E := Entity (E_Id);
21327 -- A pragma that applies to a Ghost entity becomes Ghost for the
21328 -- purposes of legality checks and removal of ignored Ghost code.
21330 Mark_Ghost_Pragma (N, E);
21332 if Present (E) then
21333 loop
21334 Def_Id := Get_Base_Subprogram (E);
21336 if not Ekind_In (Def_Id, E_Function,
21337 E_Generic_Function,
21338 E_Operator)
21339 then
21340 Error_Pragma_Arg
21341 ("pragma% requires a function name", Arg1);
21342 end if;
21344 -- When we have a generic function we must jump up a level
21345 -- to the declaration of the wrapper package itself.
21347 Orig_Def := Def_Id;
21349 if Is_Generic_Instance (Def_Id) then
21350 while Nkind (Orig_Def) /= N_Package_Declaration loop
21351 Orig_Def := Parent (Orig_Def);
21352 end loop;
21353 end if;
21355 if In_Same_Declarative_Part (Parent (N), Orig_Def) then
21356 Same_Decl := True;
21357 Set_Is_Pure (Def_Id);
21359 if not Has_Pragma_Pure_Function (Def_Id) then
21360 Set_Has_Pragma_Pure_Function (Def_Id);
21361 Effective := True;
21362 end if;
21363 end if;
21365 exit when From_Aspect_Specification (N);
21366 E := Homonym (E);
21367 exit when No (E) or else Scope (E) /= Current_Scope;
21368 end loop;
21370 if not Effective
21371 and then Warn_On_Redundant_Constructs
21372 then
21373 Error_Msg_NE
21374 ("pragma Pure_Function on& is redundant?r?",
21375 N, Entity (E_Id));
21377 elsif not Same_Decl then
21378 Error_Pragma_Arg
21379 ("pragma% argument must be in same declarative part",
21380 Arg1);
21381 end if;
21382 end if;
21383 end Pure_Function;
21385 --------------------
21386 -- Queuing_Policy --
21387 --------------------
21389 -- pragma Queuing_Policy (policy_IDENTIFIER);
21391 when Pragma_Queuing_Policy => declare
21392 QP : Character;
21394 begin
21395 Check_Ada_83_Warning;
21396 Check_Arg_Count (1);
21397 Check_No_Identifiers;
21398 Check_Arg_Is_Queuing_Policy (Arg1);
21399 Check_Valid_Configuration_Pragma;
21400 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21401 QP := Fold_Upper (Name_Buffer (1));
21403 if Queuing_Policy /= ' '
21404 and then Queuing_Policy /= QP
21405 then
21406 Error_Msg_Sloc := Queuing_Policy_Sloc;
21407 Error_Pragma ("queuing policy incompatible with policy#");
21409 -- Set new policy, but always preserve System_Location since we
21410 -- like the error message with the run time name.
21412 else
21413 Queuing_Policy := QP;
21415 if Queuing_Policy_Sloc /= System_Location then
21416 Queuing_Policy_Sloc := Loc;
21417 end if;
21418 end if;
21419 end;
21421 --------------
21422 -- Rational --
21423 --------------
21425 -- pragma Rational, for compatibility with foreign compiler
21427 when Pragma_Rational =>
21428 Set_Rational_Profile;
21430 ---------------------
21431 -- Refined_Depends --
21432 ---------------------
21434 -- pragma Refined_Depends (DEPENDENCY_RELATION);
21436 -- DEPENDENCY_RELATION ::=
21437 -- null
21438 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
21440 -- DEPENDENCY_CLAUSE ::=
21441 -- OUTPUT_LIST =>[+] INPUT_LIST
21442 -- | NULL_DEPENDENCY_CLAUSE
21444 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
21446 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
21448 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
21450 -- OUTPUT ::= NAME | FUNCTION_RESULT
21451 -- INPUT ::= NAME
21453 -- where FUNCTION_RESULT is a function Result attribute_reference
21455 -- Characteristics:
21457 -- * Analysis - The annotation undergoes initial checks to verify
21458 -- the legal placement and context. Secondary checks fully analyze
21459 -- the dependency clauses/global list in:
21461 -- Analyze_Refined_Depends_In_Decl_Part
21463 -- * Expansion - None.
21465 -- * Template - The annotation utilizes the generic template of the
21466 -- related subprogram body.
21468 -- * Globals - Capture of global references must occur after full
21469 -- analysis.
21471 -- * Instance - The annotation is instantiated automatically when
21472 -- the related generic subprogram body is instantiated.
21474 when Pragma_Refined_Depends => Refined_Depends : declare
21475 Body_Id : Entity_Id;
21476 Legal : Boolean;
21477 Spec_Id : Entity_Id;
21479 begin
21480 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
21482 if Legal then
21484 -- Chain the pragma on the contract for further processing by
21485 -- Analyze_Refined_Depends_In_Decl_Part.
21487 Add_Contract_Item (N, Body_Id);
21489 -- The legality checks of pragmas Refined_Depends and
21490 -- Refined_Global are affected by the SPARK mode in effect and
21491 -- the volatility of the context. In addition these two pragmas
21492 -- are subject to an inherent order:
21494 -- 1) Refined_Global
21495 -- 2) Refined_Depends
21497 -- Analyze all these pragmas in the order outlined above
21499 Analyze_If_Present (Pragma_SPARK_Mode);
21500 Analyze_If_Present (Pragma_Volatile_Function);
21501 Analyze_If_Present (Pragma_Refined_Global);
21502 Analyze_Refined_Depends_In_Decl_Part (N);
21503 end if;
21504 end Refined_Depends;
21506 --------------------
21507 -- Refined_Global --
21508 --------------------
21510 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
21512 -- GLOBAL_SPECIFICATION ::=
21513 -- null
21514 -- | (GLOBAL_LIST)
21515 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
21517 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
21519 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
21520 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
21521 -- GLOBAL_ITEM ::= NAME
21523 -- Characteristics:
21525 -- * Analysis - The annotation undergoes initial checks to verify
21526 -- the legal placement and context. Secondary checks fully analyze
21527 -- the dependency clauses/global list in:
21529 -- Analyze_Refined_Global_In_Decl_Part
21531 -- * Expansion - None.
21533 -- * Template - The annotation utilizes the generic template of the
21534 -- related subprogram body.
21536 -- * Globals - Capture of global references must occur after full
21537 -- analysis.
21539 -- * Instance - The annotation is instantiated automatically when
21540 -- the related generic subprogram body is instantiated.
21542 when Pragma_Refined_Global => Refined_Global : declare
21543 Body_Id : Entity_Id;
21544 Legal : Boolean;
21545 Spec_Id : Entity_Id;
21547 begin
21548 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
21550 if Legal then
21552 -- Chain the pragma on the contract for further processing by
21553 -- Analyze_Refined_Global_In_Decl_Part.
21555 Add_Contract_Item (N, Body_Id);
21557 -- The legality checks of pragmas Refined_Depends and
21558 -- Refined_Global are affected by the SPARK mode in effect and
21559 -- the volatility of the context. In addition these two pragmas
21560 -- are subject to an inherent order:
21562 -- 1) Refined_Global
21563 -- 2) Refined_Depends
21565 -- Analyze all these pragmas in the order outlined above
21567 Analyze_If_Present (Pragma_SPARK_Mode);
21568 Analyze_If_Present (Pragma_Volatile_Function);
21569 Analyze_Refined_Global_In_Decl_Part (N);
21570 Analyze_If_Present (Pragma_Refined_Depends);
21571 end if;
21572 end Refined_Global;
21574 ------------------
21575 -- Refined_Post --
21576 ------------------
21578 -- pragma Refined_Post (boolean_EXPRESSION);
21580 -- Characteristics:
21582 -- * Analysis - The annotation is fully analyzed immediately upon
21583 -- elaboration as it cannot forward reference entities.
21585 -- * Expansion - The annotation is expanded during the expansion of
21586 -- the related subprogram body contract as performed in:
21588 -- Expand_Subprogram_Contract
21590 -- * Template - The annotation utilizes the generic template of the
21591 -- related subprogram body.
21593 -- * Globals - Capture of global references must occur after full
21594 -- analysis.
21596 -- * Instance - The annotation is instantiated automatically when
21597 -- the related generic subprogram body is instantiated.
21599 when Pragma_Refined_Post => Refined_Post : declare
21600 Body_Id : Entity_Id;
21601 Legal : Boolean;
21602 Spec_Id : Entity_Id;
21604 begin
21605 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
21607 -- Fully analyze the pragma when it appears inside a subprogram
21608 -- body because it cannot benefit from forward references.
21610 if Legal then
21612 -- Chain the pragma on the contract for completeness
21614 Add_Contract_Item (N, Body_Id);
21616 -- The legality checks of pragma Refined_Post are affected by
21617 -- the SPARK mode in effect and the volatility of the context.
21618 -- Analyze all pragmas in a specific order.
21620 Analyze_If_Present (Pragma_SPARK_Mode);
21621 Analyze_If_Present (Pragma_Volatile_Function);
21622 Analyze_Pre_Post_Condition_In_Decl_Part (N);
21624 -- Currently it is not possible to inline pre/postconditions on
21625 -- a subprogram subject to pragma Inline_Always.
21627 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
21628 end if;
21629 end Refined_Post;
21631 -------------------
21632 -- Refined_State --
21633 -------------------
21635 -- pragma Refined_State (REFINEMENT_LIST);
21637 -- REFINEMENT_LIST ::=
21638 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
21640 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
21642 -- CONSTITUENT_LIST ::=
21643 -- null
21644 -- | CONSTITUENT
21645 -- | (CONSTITUENT {, CONSTITUENT})
21647 -- CONSTITUENT ::= object_NAME | state_NAME
21649 -- Characteristics:
21651 -- * Analysis - The annotation undergoes initial checks to verify
21652 -- the legal placement and context. Secondary checks preanalyze the
21653 -- refinement clauses in:
21655 -- Analyze_Refined_State_In_Decl_Part
21657 -- * Expansion - None.
21659 -- * Template - The annotation utilizes the template of the related
21660 -- package body.
21662 -- * Globals - Capture of global references must occur after full
21663 -- analysis.
21665 -- * Instance - The annotation is instantiated automatically when
21666 -- the related generic package body is instantiated.
21668 when Pragma_Refined_State => Refined_State : declare
21669 Pack_Decl : Node_Id;
21670 Spec_Id : Entity_Id;
21672 begin
21673 GNAT_Pragma;
21674 Check_No_Identifiers;
21675 Check_Arg_Count (1);
21677 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
21679 if Nkind (Pack_Decl) /= N_Package_Body then
21680 Pragma_Misplaced;
21681 return;
21682 end if;
21684 Spec_Id := Corresponding_Spec (Pack_Decl);
21686 -- A pragma that applies to a Ghost entity becomes Ghost for the
21687 -- purposes of legality checks and removal of ignored Ghost code.
21689 Mark_Ghost_Pragma (N, Spec_Id);
21691 -- Chain the pragma on the contract for further processing by
21692 -- Analyze_Refined_State_In_Decl_Part.
21694 Add_Contract_Item (N, Defining_Entity (Pack_Decl));
21696 -- The legality checks of pragma Refined_State are affected by the
21697 -- SPARK mode in effect. Analyze all pragmas in a specific order.
21699 Analyze_If_Present (Pragma_SPARK_Mode);
21701 -- State refinement is allowed only when the corresponding package
21702 -- declaration has non-null pragma Abstract_State. Refinement not
21703 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
21705 if SPARK_Mode /= Off
21706 and then
21707 (No (Abstract_States (Spec_Id))
21708 or else Has_Null_Abstract_State (Spec_Id))
21709 then
21710 Error_Msg_NE
21711 ("useless refinement, package & does not define abstract "
21712 & "states", N, Spec_Id);
21713 return;
21714 end if;
21715 end Refined_State;
21717 -----------------------
21718 -- Relative_Deadline --
21719 -----------------------
21721 -- pragma Relative_Deadline (time_span_EXPRESSION);
21723 when Pragma_Relative_Deadline => Relative_Deadline : declare
21724 P : constant Node_Id := Parent (N);
21725 Arg : Node_Id;
21727 begin
21728 Ada_2005_Pragma;
21729 Check_No_Identifiers;
21730 Check_Arg_Count (1);
21732 Arg := Get_Pragma_Arg (Arg1);
21734 -- The expression must be analyzed in the special manner described
21735 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
21737 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
21739 -- Subprogram case
21741 if Nkind (P) = N_Subprogram_Body then
21742 Check_In_Main_Program;
21744 -- Only Task and subprogram cases allowed
21746 elsif Nkind (P) /= N_Task_Definition then
21747 Pragma_Misplaced;
21748 end if;
21750 -- Check duplicate pragma before we set the corresponding flag
21752 if Has_Relative_Deadline_Pragma (P) then
21753 Error_Pragma ("duplicate pragma% not allowed");
21754 end if;
21756 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
21757 -- Relative_Deadline pragma node cannot be inserted in the Rep
21758 -- Item chain of Ent since it is rewritten by the expander as a
21759 -- procedure call statement that will break the chain.
21761 Set_Has_Relative_Deadline_Pragma (P);
21762 end Relative_Deadline;
21764 ------------------------
21765 -- Remote_Access_Type --
21766 ------------------------
21768 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
21770 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
21771 E : Entity_Id;
21773 begin
21774 GNAT_Pragma;
21775 Check_Arg_Count (1);
21776 Check_Optional_Identifier (Arg1, Name_Entity);
21777 Check_Arg_Is_Local_Name (Arg1);
21779 E := Entity (Get_Pragma_Arg (Arg1));
21781 -- A pragma that applies to a Ghost entity becomes Ghost for the
21782 -- purposes of legality checks and removal of ignored Ghost code.
21784 Mark_Ghost_Pragma (N, E);
21786 if Nkind (Parent (E)) = N_Formal_Type_Declaration
21787 and then Ekind (E) = E_General_Access_Type
21788 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
21789 and then Scope (Root_Type (Directly_Designated_Type (E)))
21790 = Scope (E)
21791 and then Is_Valid_Remote_Object_Type
21792 (Root_Type (Directly_Designated_Type (E)))
21793 then
21794 Set_Is_Remote_Types (E);
21796 else
21797 Error_Pragma_Arg
21798 ("pragma% applies only to formal access-to-class-wide types",
21799 Arg1);
21800 end if;
21801 end Remote_Access_Type;
21803 ---------------------------
21804 -- Remote_Call_Interface --
21805 ---------------------------
21807 -- pragma Remote_Call_Interface [(library_unit_NAME)];
21809 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
21810 Cunit_Node : Node_Id;
21811 Cunit_Ent : Entity_Id;
21812 K : Node_Kind;
21814 begin
21815 Check_Ada_83_Warning;
21816 Check_Valid_Library_Unit_Pragma;
21818 if Nkind (N) = N_Null_Statement then
21819 return;
21820 end if;
21822 Cunit_Node := Cunit (Current_Sem_Unit);
21823 K := Nkind (Unit (Cunit_Node));
21824 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
21826 -- A pragma that applies to a Ghost entity becomes Ghost for the
21827 -- purposes of legality checks and removal of ignored Ghost code.
21829 Mark_Ghost_Pragma (N, Cunit_Ent);
21831 if K = N_Package_Declaration
21832 or else K = N_Generic_Package_Declaration
21833 or else K = N_Subprogram_Declaration
21834 or else K = N_Generic_Subprogram_Declaration
21835 or else (K = N_Subprogram_Body
21836 and then Acts_As_Spec (Unit (Cunit_Node)))
21837 then
21838 null;
21839 else
21840 Error_Pragma (
21841 "pragma% must apply to package or subprogram declaration");
21842 end if;
21844 Set_Is_Remote_Call_Interface (Cunit_Ent);
21845 end Remote_Call_Interface;
21847 ------------------
21848 -- Remote_Types --
21849 ------------------
21851 -- pragma Remote_Types [(library_unit_NAME)];
21853 when Pragma_Remote_Types => Remote_Types : declare
21854 Cunit_Node : Node_Id;
21855 Cunit_Ent : Entity_Id;
21857 begin
21858 Check_Ada_83_Warning;
21859 Check_Valid_Library_Unit_Pragma;
21861 if Nkind (N) = N_Null_Statement then
21862 return;
21863 end if;
21865 Cunit_Node := Cunit (Current_Sem_Unit);
21866 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
21868 -- A pragma that applies to a Ghost entity becomes Ghost for the
21869 -- purposes of legality checks and removal of ignored Ghost code.
21871 Mark_Ghost_Pragma (N, Cunit_Ent);
21873 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
21874 N_Generic_Package_Declaration)
21875 then
21876 Error_Pragma
21877 ("pragma% can only apply to a package declaration");
21878 end if;
21880 Set_Is_Remote_Types (Cunit_Ent);
21881 end Remote_Types;
21883 ---------------
21884 -- Ravenscar --
21885 ---------------
21887 -- pragma Ravenscar;
21889 when Pragma_Ravenscar =>
21890 GNAT_Pragma;
21891 Check_Arg_Count (0);
21892 Check_Valid_Configuration_Pragma;
21893 Set_Ravenscar_Profile (Ravenscar, N);
21895 if Warn_On_Obsolescent_Feature then
21896 Error_Msg_N
21897 ("pragma Ravenscar is an obsolescent feature?j?", N);
21898 Error_Msg_N
21899 ("|use pragma Profile (Ravenscar) instead?j?", N);
21900 end if;
21902 -------------------------
21903 -- Restricted_Run_Time --
21904 -------------------------
21906 -- pragma Restricted_Run_Time;
21908 when Pragma_Restricted_Run_Time =>
21909 GNAT_Pragma;
21910 Check_Arg_Count (0);
21911 Check_Valid_Configuration_Pragma;
21912 Set_Profile_Restrictions
21913 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
21915 if Warn_On_Obsolescent_Feature then
21916 Error_Msg_N
21917 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
21919 Error_Msg_N
21920 ("|use pragma Profile (Restricted) instead?j?", N);
21921 end if;
21923 ------------------
21924 -- Restrictions --
21925 ------------------
21927 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
21929 -- RESTRICTION ::=
21930 -- restriction_IDENTIFIER
21931 -- | restriction_parameter_IDENTIFIER => EXPRESSION
21933 when Pragma_Restrictions =>
21934 Process_Restrictions_Or_Restriction_Warnings
21935 (Warn => Treat_Restrictions_As_Warnings);
21937 --------------------------
21938 -- Restriction_Warnings --
21939 --------------------------
21941 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
21943 -- RESTRICTION ::=
21944 -- restriction_IDENTIFIER
21945 -- | restriction_parameter_IDENTIFIER => EXPRESSION
21947 when Pragma_Restriction_Warnings =>
21948 GNAT_Pragma;
21949 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
21951 ----------------
21952 -- Reviewable --
21953 ----------------
21955 -- pragma Reviewable;
21957 when Pragma_Reviewable =>
21958 Check_Ada_83_Warning;
21959 Check_Arg_Count (0);
21961 -- Call dummy debugging function rv. This is done to assist front
21962 -- end debugging. By placing a Reviewable pragma in the source
21963 -- program, a breakpoint on rv catches this place in the source,
21964 -- allowing convenient stepping to the point of interest.
21968 --------------------------
21969 -- Secondary_Stack_Size --
21970 --------------------------
21972 -- pragma Secondary_Stack_Size (EXPRESSION);
21974 when Pragma_Secondary_Stack_Size => Secondary_Stack_Size : declare
21975 P : constant Node_Id := Parent (N);
21976 Arg : Node_Id;
21977 Ent : Entity_Id;
21979 begin
21980 GNAT_Pragma;
21981 Check_No_Identifiers;
21982 Check_Arg_Count (1);
21984 if Nkind (P) = N_Task_Definition then
21985 Arg := Get_Pragma_Arg (Arg1);
21986 Ent := Defining_Identifier (Parent (P));
21988 -- The expression must be analyzed in the special manner
21989 -- described in "Handling of Default Expressions" in sem.ads.
21991 Preanalyze_Spec_Expression (Arg, Any_Integer);
21993 -- The pragma cannot appear if the No_Secondary_Stack
21994 -- restriction is in effect.
21996 Check_Restriction (No_Secondary_Stack, Arg);
21998 -- Anything else is incorrect
22000 else
22001 Pragma_Misplaced;
22002 end if;
22004 -- Check duplicate pragma before we chain the pragma in the Rep
22005 -- Item chain of Ent.
22007 Check_Duplicate_Pragma (Ent);
22008 Record_Rep_Item (Ent, N);
22009 end Secondary_Stack_Size;
22011 --------------------------
22012 -- Short_Circuit_And_Or --
22013 --------------------------
22015 -- pragma Short_Circuit_And_Or;
22017 when Pragma_Short_Circuit_And_Or =>
22018 GNAT_Pragma;
22019 Check_Arg_Count (0);
22020 Check_Valid_Configuration_Pragma;
22021 Short_Circuit_And_Or := True;
22023 -------------------
22024 -- Share_Generic --
22025 -------------------
22027 -- pragma Share_Generic (GNAME {, GNAME});
22029 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
22031 when Pragma_Share_Generic =>
22032 GNAT_Pragma;
22033 Process_Generic_List;
22035 ------------
22036 -- Shared --
22037 ------------
22039 -- pragma Shared (LOCAL_NAME);
22041 when Pragma_Shared =>
22042 GNAT_Pragma;
22043 Process_Atomic_Independent_Shared_Volatile;
22045 --------------------
22046 -- Shared_Passive --
22047 --------------------
22049 -- pragma Shared_Passive [(library_unit_NAME)];
22051 -- Set the flag Is_Shared_Passive of program unit name entity
22053 when Pragma_Shared_Passive => Shared_Passive : declare
22054 Cunit_Node : Node_Id;
22055 Cunit_Ent : Entity_Id;
22057 begin
22058 Check_Ada_83_Warning;
22059 Check_Valid_Library_Unit_Pragma;
22061 if Nkind (N) = N_Null_Statement then
22062 return;
22063 end if;
22065 Cunit_Node := Cunit (Current_Sem_Unit);
22066 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
22068 -- A pragma that applies to a Ghost entity becomes Ghost for the
22069 -- purposes of legality checks and removal of ignored Ghost code.
22071 Mark_Ghost_Pragma (N, Cunit_Ent);
22073 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
22074 N_Generic_Package_Declaration)
22075 then
22076 Error_Pragma
22077 ("pragma% can only apply to a package declaration");
22078 end if;
22080 Set_Is_Shared_Passive (Cunit_Ent);
22081 end Shared_Passive;
22083 -----------------------
22084 -- Short_Descriptors --
22085 -----------------------
22087 -- pragma Short_Descriptors;
22089 -- Recognize and validate, but otherwise ignore
22091 when Pragma_Short_Descriptors =>
22092 GNAT_Pragma;
22093 Check_Arg_Count (0);
22094 Check_Valid_Configuration_Pragma;
22096 ------------------------------
22097 -- Simple_Storage_Pool_Type --
22098 ------------------------------
22100 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
22102 when Pragma_Simple_Storage_Pool_Type =>
22103 Simple_Storage_Pool_Type : declare
22104 Typ : Entity_Id;
22105 Type_Id : Node_Id;
22107 begin
22108 GNAT_Pragma;
22109 Check_Arg_Count (1);
22110 Check_Arg_Is_Library_Level_Local_Name (Arg1);
22112 Type_Id := Get_Pragma_Arg (Arg1);
22113 Find_Type (Type_Id);
22114 Typ := Entity (Type_Id);
22116 if Typ = Any_Type then
22117 return;
22118 end if;
22120 -- A pragma that applies to a Ghost entity becomes Ghost for the
22121 -- purposes of legality checks and removal of ignored Ghost code.
22123 Mark_Ghost_Pragma (N, Typ);
22125 -- We require the pragma to apply to a type declared in a package
22126 -- declaration, but not (immediately) within a package body.
22128 if Ekind (Current_Scope) /= E_Package
22129 or else In_Package_Body (Current_Scope)
22130 then
22131 Error_Pragma
22132 ("pragma% can only apply to type declared immediately "
22133 & "within a package declaration");
22134 end if;
22136 -- A simple storage pool type must be an immutably limited record
22137 -- or private type. If the pragma is given for a private type,
22138 -- the full type is similarly restricted (which is checked later
22139 -- in Freeze_Entity).
22141 if Is_Record_Type (Typ)
22142 and then not Is_Limited_View (Typ)
22143 then
22144 Error_Pragma
22145 ("pragma% can only apply to explicitly limited record type");
22147 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
22148 Error_Pragma
22149 ("pragma% can only apply to a private type that is limited");
22151 elsif not Is_Record_Type (Typ)
22152 and then not Is_Private_Type (Typ)
22153 then
22154 Error_Pragma
22155 ("pragma% can only apply to limited record or private type");
22156 end if;
22158 Record_Rep_Item (Typ, N);
22159 end Simple_Storage_Pool_Type;
22161 ----------------------
22162 -- Source_File_Name --
22163 ----------------------
22165 -- There are five forms for this pragma:
22167 -- pragma Source_File_Name (
22168 -- [UNIT_NAME =>] unit_NAME,
22169 -- BODY_FILE_NAME => STRING_LITERAL
22170 -- [, [INDEX =>] INTEGER_LITERAL]);
22172 -- pragma Source_File_Name (
22173 -- [UNIT_NAME =>] unit_NAME,
22174 -- SPEC_FILE_NAME => STRING_LITERAL
22175 -- [, [INDEX =>] INTEGER_LITERAL]);
22177 -- pragma Source_File_Name (
22178 -- BODY_FILE_NAME => STRING_LITERAL
22179 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22180 -- [, CASING => CASING_SPEC]);
22182 -- pragma Source_File_Name (
22183 -- SPEC_FILE_NAME => STRING_LITERAL
22184 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22185 -- [, CASING => CASING_SPEC]);
22187 -- pragma Source_File_Name (
22188 -- SUBUNIT_FILE_NAME => STRING_LITERAL
22189 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22190 -- [, CASING => CASING_SPEC]);
22192 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
22194 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
22195 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
22196 -- only be used when no project file is used, while SFNP can only be
22197 -- used when a project file is used.
22199 -- No processing here. Processing was completed during parsing, since
22200 -- we need to have file names set as early as possible. Units are
22201 -- loaded well before semantic processing starts.
22203 -- The only processing we defer to this point is the check for
22204 -- correct placement.
22206 when Pragma_Source_File_Name =>
22207 GNAT_Pragma;
22208 Check_Valid_Configuration_Pragma;
22210 ------------------------------
22211 -- Source_File_Name_Project --
22212 ------------------------------
22214 -- See Source_File_Name for syntax
22216 -- No processing here. Processing was completed during parsing, since
22217 -- we need to have file names set as early as possible. Units are
22218 -- loaded well before semantic processing starts.
22220 -- The only processing we defer to this point is the check for
22221 -- correct placement.
22223 when Pragma_Source_File_Name_Project =>
22224 GNAT_Pragma;
22225 Check_Valid_Configuration_Pragma;
22227 -- Check that a pragma Source_File_Name_Project is used only in a
22228 -- configuration pragmas file.
22230 -- Pragmas Source_File_Name_Project should only be generated by
22231 -- the Project Manager in configuration pragmas files.
22233 -- This is really an ugly test. It seems to depend on some
22234 -- accidental and undocumented property. At the very least it
22235 -- needs to be documented, but it would be better to have a
22236 -- clean way of testing if we are in a configuration file???
22238 if Present (Parent (N)) then
22239 Error_Pragma
22240 ("pragma% can only appear in a configuration pragmas file");
22241 end if;
22243 ----------------------
22244 -- Source_Reference --
22245 ----------------------
22247 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
22249 -- Nothing to do, all processing completed in Par.Prag, since we need
22250 -- the information for possible parser messages that are output.
22252 when Pragma_Source_Reference =>
22253 GNAT_Pragma;
22255 ----------------
22256 -- SPARK_Mode --
22257 ----------------
22259 -- pragma SPARK_Mode [(On | Off)];
22261 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
22262 Mode_Id : SPARK_Mode_Type;
22264 procedure Check_Pragma_Conformance
22265 (Context_Pragma : Node_Id;
22266 Entity : Entity_Id;
22267 Entity_Pragma : Node_Id);
22268 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
22269 -- conformance of pragma N depending the following scenarios:
22271 -- If pragma Context_Pragma is not Empty, verify that pragma N is
22272 -- compatible with the pragma Context_Pragma that was inherited
22273 -- from the context:
22274 -- * If the mode of Context_Pragma is ON, then the new mode can
22275 -- be anything.
22276 -- * If the mode of Context_Pragma is OFF, then the only allowed
22277 -- new mode is also OFF. Emit error if this is not the case.
22279 -- If Entity is not Empty, verify that pragma N is compatible with
22280 -- pragma Entity_Pragma that belongs to Entity.
22281 -- * If Entity_Pragma is Empty, always issue an error as this
22282 -- corresponds to the case where a previous section of Entity
22283 -- has no SPARK_Mode set.
22284 -- * If the mode of Entity_Pragma is ON, then the new mode can
22285 -- be anything.
22286 -- * If the mode of Entity_Pragma is OFF, then the only allowed
22287 -- new mode is also OFF. Emit error if this is not the case.
22289 procedure Check_Library_Level_Entity (E : Entity_Id);
22290 -- Subsidiary to routines Process_xxx. Verify that the related
22291 -- entity E subject to pragma SPARK_Mode is library-level.
22293 procedure Process_Body (Decl : Node_Id);
22294 -- Verify the legality of pragma SPARK_Mode when it appears as the
22295 -- top of the body declarations of entry, package, protected unit,
22296 -- subprogram or task unit body denoted by Decl.
22298 procedure Process_Overloadable (Decl : Node_Id);
22299 -- Verify the legality of pragma SPARK_Mode when it applies to an
22300 -- entry or [generic] subprogram declaration denoted by Decl.
22302 procedure Process_Private_Part (Decl : Node_Id);
22303 -- Verify the legality of pragma SPARK_Mode when it appears at the
22304 -- top of the private declarations of a package spec, protected or
22305 -- task unit declaration denoted by Decl.
22307 procedure Process_Statement_Part (Decl : Node_Id);
22308 -- Verify the legality of pragma SPARK_Mode when it appears at the
22309 -- top of the statement sequence of a package body denoted by node
22310 -- Decl.
22312 procedure Process_Visible_Part (Decl : Node_Id);
22313 -- Verify the legality of pragma SPARK_Mode when it appears at the
22314 -- top of the visible declarations of a package spec, protected or
22315 -- task unit declaration denoted by Decl. The routine is also used
22316 -- on protected or task units declared without a definition.
22318 procedure Set_SPARK_Context;
22319 -- Subsidiary to routines Process_xxx. Set the global variables
22320 -- which represent the mode of the context from pragma N. Ensure
22321 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
22323 ------------------------------
22324 -- Check_Pragma_Conformance --
22325 ------------------------------
22327 procedure Check_Pragma_Conformance
22328 (Context_Pragma : Node_Id;
22329 Entity : Entity_Id;
22330 Entity_Pragma : Node_Id)
22332 Err_Id : Entity_Id;
22333 Err_N : Node_Id;
22335 begin
22336 -- The current pragma may appear without an argument. If this
22337 -- is the case, associate all error messages with the pragma
22338 -- itself.
22340 if Present (Arg1) then
22341 Err_N := Arg1;
22342 else
22343 Err_N := N;
22344 end if;
22346 -- The mode of the current pragma is compared against that of
22347 -- an enclosing context.
22349 if Present (Context_Pragma) then
22350 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
22352 -- Issue an error if the new mode is less restrictive than
22353 -- that of the context.
22355 if Get_SPARK_Mode_From_Annotation (Context_Pragma) = Off
22356 and then Get_SPARK_Mode_From_Annotation (N) = On
22357 then
22358 Error_Msg_N
22359 ("cannot change SPARK_Mode from Off to On", Err_N);
22360 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
22361 Error_Msg_N ("\SPARK_Mode was set to Off#", Err_N);
22362 raise Pragma_Exit;
22363 end if;
22364 end if;
22366 -- The mode of the current pragma is compared against that of
22367 -- an initial package, protected type, subprogram or task type
22368 -- declaration.
22370 if Present (Entity) then
22372 -- A simple protected or task type is transformed into an
22373 -- anonymous type whose name cannot be used to issue error
22374 -- messages. Recover the original entity of the type.
22376 if Ekind_In (Entity, E_Protected_Type, E_Task_Type) then
22377 Err_Id :=
22378 Defining_Entity
22379 (Original_Node (Unit_Declaration_Node (Entity)));
22380 else
22381 Err_Id := Entity;
22382 end if;
22384 -- Both the initial declaration and the completion carry
22385 -- SPARK_Mode pragmas.
22387 if Present (Entity_Pragma) then
22388 pragma Assert (Nkind (Entity_Pragma) = N_Pragma);
22390 -- Issue an error if the new mode is less restrictive
22391 -- than that of the initial declaration.
22393 if Get_SPARK_Mode_From_Annotation (Entity_Pragma) = Off
22394 and then Get_SPARK_Mode_From_Annotation (N) = On
22395 then
22396 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
22397 Error_Msg_Sloc := Sloc (Entity_Pragma);
22398 Error_Msg_NE
22399 ("\value Off was set for SPARK_Mode on&#",
22400 Err_N, Err_Id);
22401 raise Pragma_Exit;
22402 end if;
22404 -- Otherwise the initial declaration lacks a SPARK_Mode
22405 -- pragma in which case the current pragma is illegal as
22406 -- it cannot "complete".
22408 else
22409 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
22410 Error_Msg_Sloc := Sloc (Err_Id);
22411 Error_Msg_NE
22412 ("\no value was set for SPARK_Mode on&#",
22413 Err_N, Err_Id);
22414 raise Pragma_Exit;
22415 end if;
22416 end if;
22417 end Check_Pragma_Conformance;
22419 --------------------------------
22420 -- Check_Library_Level_Entity --
22421 --------------------------------
22423 procedure Check_Library_Level_Entity (E : Entity_Id) is
22424 procedure Add_Entity_To_Name_Buffer;
22425 -- Add the E_Kind of entity E to the name buffer
22427 -------------------------------
22428 -- Add_Entity_To_Name_Buffer --
22429 -------------------------------
22431 procedure Add_Entity_To_Name_Buffer is
22432 begin
22433 if Ekind_In (E, E_Entry, E_Entry_Family) then
22434 Add_Str_To_Name_Buffer ("entry");
22436 elsif Ekind_In (E, E_Generic_Package,
22437 E_Package,
22438 E_Package_Body)
22439 then
22440 Add_Str_To_Name_Buffer ("package");
22442 elsif Ekind_In (E, E_Protected_Body, E_Protected_Type) then
22443 Add_Str_To_Name_Buffer ("protected type");
22445 elsif Ekind_In (E, E_Function,
22446 E_Generic_Function,
22447 E_Generic_Procedure,
22448 E_Procedure,
22449 E_Subprogram_Body)
22450 then
22451 Add_Str_To_Name_Buffer ("subprogram");
22453 else
22454 pragma Assert (Ekind_In (E, E_Task_Body, E_Task_Type));
22455 Add_Str_To_Name_Buffer ("task type");
22456 end if;
22457 end Add_Entity_To_Name_Buffer;
22459 -- Local variables
22461 Msg_1 : constant String := "incorrect placement of pragma%";
22462 Msg_2 : Name_Id;
22464 -- Start of processing for Check_Library_Level_Entity
22466 begin
22467 if not Is_Library_Level_Entity (E) then
22468 Error_Msg_Name_1 := Pname;
22469 Error_Msg_N (Fix_Error (Msg_1), N);
22471 Name_Len := 0;
22472 Add_Str_To_Name_Buffer ("\& is not a library-level ");
22473 Add_Entity_To_Name_Buffer;
22475 Msg_2 := Name_Find;
22476 Error_Msg_NE (Get_Name_String (Msg_2), N, E);
22478 raise Pragma_Exit;
22479 end if;
22480 end Check_Library_Level_Entity;
22482 ------------------
22483 -- Process_Body --
22484 ------------------
22486 procedure Process_Body (Decl : Node_Id) is
22487 Body_Id : constant Entity_Id := Defining_Entity (Decl);
22488 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
22490 begin
22491 -- Ignore pragma when applied to the special body created for
22492 -- inlining, recognized by its internal name _Parent.
22494 if Chars (Body_Id) = Name_uParent then
22495 return;
22496 end if;
22498 Check_Library_Level_Entity (Body_Id);
22500 -- For entry bodies, verify the legality against:
22501 -- * The mode of the context
22502 -- * The mode of the spec (if any)
22504 if Nkind_In (Decl, N_Entry_Body, N_Subprogram_Body) then
22506 -- A stand-alone subprogram body
22508 if Body_Id = Spec_Id then
22509 Check_Pragma_Conformance
22510 (Context_Pragma => SPARK_Pragma (Body_Id),
22511 Entity => Empty,
22512 Entity_Pragma => Empty);
22514 -- An entry or subprogram body that completes a previous
22515 -- declaration.
22517 else
22518 Check_Pragma_Conformance
22519 (Context_Pragma => SPARK_Pragma (Body_Id),
22520 Entity => Spec_Id,
22521 Entity_Pragma => SPARK_Pragma (Spec_Id));
22522 end if;
22524 Set_SPARK_Context;
22525 Set_SPARK_Pragma (Body_Id, N);
22526 Set_SPARK_Pragma_Inherited (Body_Id, False);
22528 -- For package bodies, verify the legality against:
22529 -- * The mode of the context
22530 -- * The mode of the private part
22532 -- This case is separated from protected and task bodies
22533 -- because the statement part of the package body inherits
22534 -- the mode of the body declarations.
22536 elsif Nkind (Decl) = N_Package_Body then
22537 Check_Pragma_Conformance
22538 (Context_Pragma => SPARK_Pragma (Body_Id),
22539 Entity => Spec_Id,
22540 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
22542 Set_SPARK_Context;
22543 Set_SPARK_Pragma (Body_Id, N);
22544 Set_SPARK_Pragma_Inherited (Body_Id, False);
22545 Set_SPARK_Aux_Pragma (Body_Id, N);
22546 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
22548 -- For protected and task bodies, verify the legality against:
22549 -- * The mode of the context
22550 -- * The mode of the private part
22552 else
22553 pragma Assert
22554 (Nkind_In (Decl, N_Protected_Body, N_Task_Body));
22556 Check_Pragma_Conformance
22557 (Context_Pragma => SPARK_Pragma (Body_Id),
22558 Entity => Spec_Id,
22559 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
22561 Set_SPARK_Context;
22562 Set_SPARK_Pragma (Body_Id, N);
22563 Set_SPARK_Pragma_Inherited (Body_Id, False);
22564 end if;
22565 end Process_Body;
22567 --------------------------
22568 -- Process_Overloadable --
22569 --------------------------
22571 procedure Process_Overloadable (Decl : Node_Id) is
22572 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
22573 Spec_Typ : constant Entity_Id := Etype (Spec_Id);
22575 begin
22576 Check_Library_Level_Entity (Spec_Id);
22578 -- Verify the legality against:
22579 -- * The mode of the context
22581 Check_Pragma_Conformance
22582 (Context_Pragma => SPARK_Pragma (Spec_Id),
22583 Entity => Empty,
22584 Entity_Pragma => Empty);
22586 Set_SPARK_Pragma (Spec_Id, N);
22587 Set_SPARK_Pragma_Inherited (Spec_Id, False);
22589 -- When the pragma applies to the anonymous object created for
22590 -- a single task type, decorate the type as well. This scenario
22591 -- arises when the single task type lacks a task definition,
22592 -- therefore there is no issue with respect to a potential
22593 -- pragma SPARK_Mode in the private part.
22595 -- task type Anon_Task_Typ;
22596 -- Obj : Anon_Task_Typ;
22597 -- pragma SPARK_Mode ...;
22599 if Is_Single_Task_Object (Spec_Id) then
22600 Set_SPARK_Pragma (Spec_Typ, N);
22601 Set_SPARK_Pragma_Inherited (Spec_Typ, False);
22602 Set_SPARK_Aux_Pragma (Spec_Typ, N);
22603 Set_SPARK_Aux_Pragma_Inherited (Spec_Typ, True);
22604 end if;
22605 end Process_Overloadable;
22607 --------------------------
22608 -- Process_Private_Part --
22609 --------------------------
22611 procedure Process_Private_Part (Decl : Node_Id) is
22612 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
22614 begin
22615 Check_Library_Level_Entity (Spec_Id);
22617 -- Verify the legality against:
22618 -- * The mode of the visible declarations
22620 Check_Pragma_Conformance
22621 (Context_Pragma => Empty,
22622 Entity => Spec_Id,
22623 Entity_Pragma => SPARK_Pragma (Spec_Id));
22625 Set_SPARK_Context;
22626 Set_SPARK_Aux_Pragma (Spec_Id, N);
22627 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
22628 end Process_Private_Part;
22630 ----------------------------
22631 -- Process_Statement_Part --
22632 ----------------------------
22634 procedure Process_Statement_Part (Decl : Node_Id) is
22635 Body_Id : constant Entity_Id := Defining_Entity (Decl);
22637 begin
22638 Check_Library_Level_Entity (Body_Id);
22640 -- Verify the legality against:
22641 -- * The mode of the body declarations
22643 Check_Pragma_Conformance
22644 (Context_Pragma => Empty,
22645 Entity => Body_Id,
22646 Entity_Pragma => SPARK_Pragma (Body_Id));
22648 Set_SPARK_Context;
22649 Set_SPARK_Aux_Pragma (Body_Id, N);
22650 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
22651 end Process_Statement_Part;
22653 --------------------------
22654 -- Process_Visible_Part --
22655 --------------------------
22657 procedure Process_Visible_Part (Decl : Node_Id) is
22658 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
22659 Obj_Id : Entity_Id;
22661 begin
22662 Check_Library_Level_Entity (Spec_Id);
22664 -- Verify the legality against:
22665 -- * The mode of the context
22667 Check_Pragma_Conformance
22668 (Context_Pragma => SPARK_Pragma (Spec_Id),
22669 Entity => Empty,
22670 Entity_Pragma => Empty);
22672 -- A task unit declared without a definition does not set the
22673 -- SPARK_Mode of the context because the task does not have any
22674 -- entries that could inherit the mode.
22676 if not Nkind_In (Decl, N_Single_Task_Declaration,
22677 N_Task_Type_Declaration)
22678 then
22679 Set_SPARK_Context;
22680 end if;
22682 Set_SPARK_Pragma (Spec_Id, N);
22683 Set_SPARK_Pragma_Inherited (Spec_Id, False);
22684 Set_SPARK_Aux_Pragma (Spec_Id, N);
22685 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
22687 -- When the pragma applies to a single protected or task type,
22688 -- decorate the corresponding anonymous object as well.
22690 -- protected Anon_Prot_Typ is
22691 -- pragma SPARK_Mode ...;
22692 -- ...
22693 -- end Anon_Prot_Typ;
22695 -- Obj : Anon_Prot_Typ;
22697 if Is_Single_Concurrent_Type (Spec_Id) then
22698 Obj_Id := Anonymous_Object (Spec_Id);
22700 Set_SPARK_Pragma (Obj_Id, N);
22701 Set_SPARK_Pragma_Inherited (Obj_Id, False);
22702 end if;
22703 end Process_Visible_Part;
22705 -----------------------
22706 -- Set_SPARK_Context --
22707 -----------------------
22709 procedure Set_SPARK_Context is
22710 begin
22711 SPARK_Mode := Mode_Id;
22712 SPARK_Mode_Pragma := N;
22713 end Set_SPARK_Context;
22715 -- Local variables
22717 Context : Node_Id;
22718 Mode : Name_Id;
22719 Stmt : Node_Id;
22721 -- Start of processing for Do_SPARK_Mode
22723 begin
22724 -- When a SPARK_Mode pragma appears inside an instantiation whose
22725 -- enclosing context has SPARK_Mode set to "off", the pragma has
22726 -- no semantic effect.
22728 if Ignore_SPARK_Mode_Pragmas_In_Instance then
22729 Rewrite (N, Make_Null_Statement (Loc));
22730 Analyze (N);
22731 return;
22732 end if;
22734 GNAT_Pragma;
22735 Check_No_Identifiers;
22736 Check_At_Most_N_Arguments (1);
22738 -- Check the legality of the mode (no argument = ON)
22740 if Arg_Count = 1 then
22741 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
22742 Mode := Chars (Get_Pragma_Arg (Arg1));
22743 else
22744 Mode := Name_On;
22745 end if;
22747 Mode_Id := Get_SPARK_Mode_Type (Mode);
22748 Context := Parent (N);
22750 -- The pragma appears in a configuration file
22752 if No (Context) then
22753 Check_Valid_Configuration_Pragma;
22755 if Present (SPARK_Mode_Pragma) then
22756 Duplication_Error
22757 (Prag => N,
22758 Prev => SPARK_Mode_Pragma);
22759 raise Pragma_Exit;
22760 end if;
22762 Set_SPARK_Context;
22764 -- The pragma acts as a configuration pragma in a compilation unit
22766 -- pragma SPARK_Mode ...;
22767 -- package Pack is ...;
22769 elsif Nkind (Context) = N_Compilation_Unit
22770 and then List_Containing (N) = Context_Items (Context)
22771 then
22772 Check_Valid_Configuration_Pragma;
22773 Set_SPARK_Context;
22775 -- Otherwise the placement of the pragma within the tree dictates
22776 -- its associated construct. Inspect the declarative list where
22777 -- the pragma resides to find a potential construct.
22779 else
22780 Stmt := Prev (N);
22781 while Present (Stmt) loop
22783 -- Skip prior pragmas, but check for duplicates. Note that
22784 -- this also takes care of pragmas generated for aspects.
22786 if Nkind (Stmt) = N_Pragma then
22787 if Pragma_Name (Stmt) = Pname then
22788 Duplication_Error
22789 (Prag => N,
22790 Prev => Stmt);
22791 raise Pragma_Exit;
22792 end if;
22794 -- The pragma applies to an expression function that has
22795 -- already been rewritten into a subprogram declaration.
22797 -- function Expr_Func return ... is (...);
22798 -- pragma SPARK_Mode ...;
22800 elsif Nkind (Stmt) = N_Subprogram_Declaration
22801 and then Nkind (Original_Node (Stmt)) =
22802 N_Expression_Function
22803 then
22804 Process_Overloadable (Stmt);
22805 return;
22807 -- The pragma applies to the anonymous object created for a
22808 -- single concurrent type.
22810 -- protected type Anon_Prot_Typ ...;
22811 -- Obj : Anon_Prot_Typ;
22812 -- pragma SPARK_Mode ...;
22814 elsif Nkind (Stmt) = N_Object_Declaration
22815 and then Is_Single_Concurrent_Object
22816 (Defining_Entity (Stmt))
22817 then
22818 Process_Overloadable (Stmt);
22819 return;
22821 -- Skip internally generated code
22823 elsif not Comes_From_Source (Stmt) then
22824 null;
22826 -- The pragma applies to an entry or [generic] subprogram
22827 -- declaration.
22829 -- entry Ent ...;
22830 -- pragma SPARK_Mode ...;
22832 -- [generic]
22833 -- procedure Proc ...;
22834 -- pragma SPARK_Mode ...;
22836 elsif Nkind_In (Stmt, N_Generic_Subprogram_Declaration,
22837 N_Subprogram_Declaration)
22838 or else (Nkind (Stmt) = N_Entry_Declaration
22839 and then Is_Protected_Type
22840 (Scope (Defining_Entity (Stmt))))
22841 then
22842 Process_Overloadable (Stmt);
22843 return;
22845 -- Otherwise the pragma does not apply to a legal construct
22846 -- or it does not appear at the top of a declarative or a
22847 -- statement list. Issue an error and stop the analysis.
22849 else
22850 Pragma_Misplaced;
22851 exit;
22852 end if;
22854 Prev (Stmt);
22855 end loop;
22857 -- The pragma applies to a package or a subprogram that acts as
22858 -- a compilation unit.
22860 -- procedure Proc ...;
22861 -- pragma SPARK_Mode ...;
22863 if Nkind (Context) = N_Compilation_Unit_Aux then
22864 Context := Unit (Parent (Context));
22865 end if;
22867 -- The pragma appears at the top of entry, package, protected
22868 -- unit, subprogram or task unit body declarations.
22870 -- entry Ent when ... is
22871 -- pragma SPARK_Mode ...;
22873 -- package body Pack is
22874 -- pragma SPARK_Mode ...;
22876 -- procedure Proc ... is
22877 -- pragma SPARK_Mode;
22879 -- protected body Prot is
22880 -- pragma SPARK_Mode ...;
22882 if Nkind_In (Context, N_Entry_Body,
22883 N_Package_Body,
22884 N_Protected_Body,
22885 N_Subprogram_Body,
22886 N_Task_Body)
22887 then
22888 Process_Body (Context);
22890 -- The pragma appears at the top of the visible or private
22891 -- declaration of a package spec, protected or task unit.
22893 -- package Pack is
22894 -- pragma SPARK_Mode ...;
22895 -- private
22896 -- pragma SPARK_Mode ...;
22898 -- protected [type] Prot is
22899 -- pragma SPARK_Mode ...;
22900 -- private
22901 -- pragma SPARK_Mode ...;
22903 elsif Nkind_In (Context, N_Package_Specification,
22904 N_Protected_Definition,
22905 N_Task_Definition)
22906 then
22907 if List_Containing (N) = Visible_Declarations (Context) then
22908 Process_Visible_Part (Parent (Context));
22909 else
22910 Process_Private_Part (Parent (Context));
22911 end if;
22913 -- The pragma appears at the top of package body statements
22915 -- package body Pack is
22916 -- begin
22917 -- pragma SPARK_Mode;
22919 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
22920 and then Nkind (Parent (Context)) = N_Package_Body
22921 then
22922 Process_Statement_Part (Parent (Context));
22924 -- The pragma appeared as an aspect of a [generic] subprogram
22925 -- declaration that acts as a compilation unit.
22927 -- [generic]
22928 -- procedure Proc ...;
22929 -- pragma SPARK_Mode ...;
22931 elsif Nkind_In (Context, N_Generic_Subprogram_Declaration,
22932 N_Subprogram_Declaration)
22933 then
22934 Process_Overloadable (Context);
22936 -- The pragma does not apply to a legal construct, issue error
22938 else
22939 Pragma_Misplaced;
22940 end if;
22941 end if;
22942 end Do_SPARK_Mode;
22944 --------------------------------
22945 -- Static_Elaboration_Desired --
22946 --------------------------------
22948 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
22950 when Pragma_Static_Elaboration_Desired =>
22951 GNAT_Pragma;
22952 Check_At_Most_N_Arguments (1);
22954 if Is_Compilation_Unit (Current_Scope)
22955 and then Ekind (Current_Scope) = E_Package
22956 then
22957 Set_Static_Elaboration_Desired (Current_Scope, True);
22958 else
22959 Error_Pragma ("pragma% must apply to a library-level package");
22960 end if;
22962 ------------------
22963 -- Storage_Size --
22964 ------------------
22966 -- pragma Storage_Size (EXPRESSION);
22968 when Pragma_Storage_Size => Storage_Size : declare
22969 P : constant Node_Id := Parent (N);
22970 Arg : Node_Id;
22972 begin
22973 Check_No_Identifiers;
22974 Check_Arg_Count (1);
22976 -- The expression must be analyzed in the special manner described
22977 -- in "Handling of Default Expressions" in sem.ads.
22979 Arg := Get_Pragma_Arg (Arg1);
22980 Preanalyze_Spec_Expression (Arg, Any_Integer);
22982 if not Is_OK_Static_Expression (Arg) then
22983 Check_Restriction (Static_Storage_Size, Arg);
22984 end if;
22986 if Nkind (P) /= N_Task_Definition then
22987 Pragma_Misplaced;
22988 return;
22990 else
22991 if Has_Storage_Size_Pragma (P) then
22992 Error_Pragma ("duplicate pragma% not allowed");
22993 else
22994 Set_Has_Storage_Size_Pragma (P, True);
22995 end if;
22997 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
22998 end if;
22999 end Storage_Size;
23001 ------------------
23002 -- Storage_Unit --
23003 ------------------
23005 -- pragma Storage_Unit (NUMERIC_LITERAL);
23007 -- Only permitted argument is System'Storage_Unit value
23009 when Pragma_Storage_Unit =>
23010 Check_No_Identifiers;
23011 Check_Arg_Count (1);
23012 Check_Arg_Is_Integer_Literal (Arg1);
23014 if Intval (Get_Pragma_Arg (Arg1)) /=
23015 UI_From_Int (Ttypes.System_Storage_Unit)
23016 then
23017 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
23018 Error_Pragma_Arg
23019 ("the only allowed argument for pragma% is ^", Arg1);
23020 end if;
23022 --------------------
23023 -- Stream_Convert --
23024 --------------------
23026 -- pragma Stream_Convert (
23027 -- [Entity =>] type_LOCAL_NAME,
23028 -- [Read =>] function_NAME,
23029 -- [Write =>] function NAME);
23031 when Pragma_Stream_Convert => Stream_Convert : declare
23032 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
23033 -- Check that the given argument is the name of a local function
23034 -- of one argument that is not overloaded earlier in the current
23035 -- local scope. A check is also made that the argument is a
23036 -- function with one parameter.
23038 --------------------------------------
23039 -- Check_OK_Stream_Convert_Function --
23040 --------------------------------------
23042 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
23043 Ent : Entity_Id;
23045 begin
23046 Check_Arg_Is_Local_Name (Arg);
23047 Ent := Entity (Get_Pragma_Arg (Arg));
23049 if Has_Homonym (Ent) then
23050 Error_Pragma_Arg
23051 ("argument for pragma% may not be overloaded", Arg);
23052 end if;
23054 if Ekind (Ent) /= E_Function
23055 or else No (First_Formal (Ent))
23056 or else Present (Next_Formal (First_Formal (Ent)))
23057 then
23058 Error_Pragma_Arg
23059 ("argument for pragma% must be function of one argument",
23060 Arg);
23061 end if;
23062 end Check_OK_Stream_Convert_Function;
23064 -- Start of processing for Stream_Convert
23066 begin
23067 GNAT_Pragma;
23068 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
23069 Check_Arg_Count (3);
23070 Check_Optional_Identifier (Arg1, Name_Entity);
23071 Check_Optional_Identifier (Arg2, Name_Read);
23072 Check_Optional_Identifier (Arg3, Name_Write);
23073 Check_Arg_Is_Local_Name (Arg1);
23074 Check_OK_Stream_Convert_Function (Arg2);
23075 Check_OK_Stream_Convert_Function (Arg3);
23077 declare
23078 Typ : constant Entity_Id :=
23079 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
23080 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
23081 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
23083 begin
23084 Check_First_Subtype (Arg1);
23086 -- Check for too early or too late. Note that we don't enforce
23087 -- the rule about primitive operations in this case, since, as
23088 -- is the case for explicit stream attributes themselves, these
23089 -- restrictions are not appropriate. Note that the chaining of
23090 -- the pragma by Rep_Item_Too_Late is actually the critical
23091 -- processing done for this pragma.
23093 if Rep_Item_Too_Early (Typ, N)
23094 or else
23095 Rep_Item_Too_Late (Typ, N, FOnly => True)
23096 then
23097 return;
23098 end if;
23100 -- Return if previous error
23102 if Etype (Typ) = Any_Type
23103 or else
23104 Etype (Read) = Any_Type
23105 or else
23106 Etype (Write) = Any_Type
23107 then
23108 return;
23109 end if;
23111 -- Error checks
23113 if Underlying_Type (Etype (Read)) /= Typ then
23114 Error_Pragma_Arg
23115 ("incorrect return type for function&", Arg2);
23116 end if;
23118 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
23119 Error_Pragma_Arg
23120 ("incorrect parameter type for function&", Arg3);
23121 end if;
23123 if Underlying_Type (Etype (First_Formal (Read))) /=
23124 Underlying_Type (Etype (Write))
23125 then
23126 Error_Pragma_Arg
23127 ("result type of & does not match Read parameter type",
23128 Arg3);
23129 end if;
23130 end;
23131 end Stream_Convert;
23133 ------------------
23134 -- Style_Checks --
23135 ------------------
23137 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
23139 -- This is processed by the parser since some of the style checks
23140 -- take place during source scanning and parsing. This means that
23141 -- we don't need to issue error messages here.
23143 when Pragma_Style_Checks => Style_Checks : declare
23144 A : constant Node_Id := Get_Pragma_Arg (Arg1);
23145 S : String_Id;
23146 C : Char_Code;
23148 begin
23149 GNAT_Pragma;
23150 Check_No_Identifiers;
23152 -- Two argument form
23154 if Arg_Count = 2 then
23155 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23157 declare
23158 E_Id : Node_Id;
23159 E : Entity_Id;
23161 begin
23162 E_Id := Get_Pragma_Arg (Arg2);
23163 Analyze (E_Id);
23165 if not Is_Entity_Name (E_Id) then
23166 Error_Pragma_Arg
23167 ("second argument of pragma% must be entity name",
23168 Arg2);
23169 end if;
23171 E := Entity (E_Id);
23173 if not Ignore_Style_Checks_Pragmas then
23174 if E = Any_Id then
23175 return;
23176 else
23177 loop
23178 Set_Suppress_Style_Checks
23179 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
23180 exit when No (Homonym (E));
23181 E := Homonym (E);
23182 end loop;
23183 end if;
23184 end if;
23185 end;
23187 -- One argument form
23189 else
23190 Check_Arg_Count (1);
23192 if Nkind (A) = N_String_Literal then
23193 S := Strval (A);
23195 declare
23196 Slen : constant Natural := Natural (String_Length (S));
23197 Options : String (1 .. Slen);
23198 J : Positive;
23200 begin
23201 J := 1;
23202 loop
23203 C := Get_String_Char (S, Pos (J));
23204 exit when not In_Character_Range (C);
23205 Options (J) := Get_Character (C);
23207 -- If at end of string, set options. As per discussion
23208 -- above, no need to check for errors, since we issued
23209 -- them in the parser.
23211 if J = Slen then
23212 if not Ignore_Style_Checks_Pragmas then
23213 Set_Style_Check_Options (Options);
23214 end if;
23216 exit;
23217 end if;
23219 J := J + 1;
23220 end loop;
23221 end;
23223 elsif Nkind (A) = N_Identifier then
23224 if Chars (A) = Name_All_Checks then
23225 if not Ignore_Style_Checks_Pragmas then
23226 if GNAT_Mode then
23227 Set_GNAT_Style_Check_Options;
23228 else
23229 Set_Default_Style_Check_Options;
23230 end if;
23231 end if;
23233 elsif Chars (A) = Name_On then
23234 if not Ignore_Style_Checks_Pragmas then
23235 Style_Check := True;
23236 end if;
23238 elsif Chars (A) = Name_Off then
23239 if not Ignore_Style_Checks_Pragmas then
23240 Style_Check := False;
23241 end if;
23242 end if;
23243 end if;
23244 end if;
23245 end Style_Checks;
23247 --------------
23248 -- Subtitle --
23249 --------------
23251 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
23253 when Pragma_Subtitle =>
23254 GNAT_Pragma;
23255 Check_Arg_Count (1);
23256 Check_Optional_Identifier (Arg1, Name_Subtitle);
23257 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
23258 Store_Note (N);
23260 --------------
23261 -- Suppress --
23262 --------------
23264 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
23266 when Pragma_Suppress =>
23267 Process_Suppress_Unsuppress (Suppress_Case => True);
23269 ------------------
23270 -- Suppress_All --
23271 ------------------
23273 -- pragma Suppress_All;
23275 -- The only check made here is that the pragma has no arguments.
23276 -- There are no placement rules, and the processing required (setting
23277 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
23278 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
23279 -- then creates and inserts a pragma Suppress (All_Checks).
23281 when Pragma_Suppress_All =>
23282 GNAT_Pragma;
23283 Check_Arg_Count (0);
23285 -------------------------
23286 -- Suppress_Debug_Info --
23287 -------------------------
23289 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
23291 when Pragma_Suppress_Debug_Info => Suppress_Debug_Info : declare
23292 Nam_Id : Entity_Id;
23294 begin
23295 GNAT_Pragma;
23296 Check_Arg_Count (1);
23297 Check_Optional_Identifier (Arg1, Name_Entity);
23298 Check_Arg_Is_Local_Name (Arg1);
23300 Nam_Id := Entity (Get_Pragma_Arg (Arg1));
23302 -- A pragma that applies to a Ghost entity becomes Ghost for the
23303 -- purposes of legality checks and removal of ignored Ghost code.
23305 Mark_Ghost_Pragma (N, Nam_Id);
23306 Set_Debug_Info_Off (Nam_Id);
23307 end Suppress_Debug_Info;
23309 ----------------------------------
23310 -- Suppress_Exception_Locations --
23311 ----------------------------------
23313 -- pragma Suppress_Exception_Locations;
23315 when Pragma_Suppress_Exception_Locations =>
23316 GNAT_Pragma;
23317 Check_Arg_Count (0);
23318 Check_Valid_Configuration_Pragma;
23319 Exception_Locations_Suppressed := True;
23321 -----------------------------
23322 -- Suppress_Initialization --
23323 -----------------------------
23325 -- pragma Suppress_Initialization ([Entity =>] type_Name);
23327 when Pragma_Suppress_Initialization => Suppress_Init : declare
23328 E : Entity_Id;
23329 E_Id : Node_Id;
23331 begin
23332 GNAT_Pragma;
23333 Check_Arg_Count (1);
23334 Check_Optional_Identifier (Arg1, Name_Entity);
23335 Check_Arg_Is_Local_Name (Arg1);
23337 E_Id := Get_Pragma_Arg (Arg1);
23339 if Etype (E_Id) = Any_Type then
23340 return;
23341 end if;
23343 E := Entity (E_Id);
23345 -- A pragma that applies to a Ghost entity becomes Ghost for the
23346 -- purposes of legality checks and removal of ignored Ghost code.
23348 Mark_Ghost_Pragma (N, E);
23350 if not Is_Type (E) and then Ekind (E) /= E_Variable then
23351 Error_Pragma_Arg
23352 ("pragma% requires variable, type or subtype", Arg1);
23353 end if;
23355 if Rep_Item_Too_Early (E, N)
23356 or else
23357 Rep_Item_Too_Late (E, N, FOnly => True)
23358 then
23359 return;
23360 end if;
23362 -- For incomplete/private type, set flag on full view
23364 if Is_Incomplete_Or_Private_Type (E) then
23365 if No (Full_View (Base_Type (E))) then
23366 Error_Pragma_Arg
23367 ("argument of pragma% cannot be an incomplete type", Arg1);
23368 else
23369 Set_Suppress_Initialization (Full_View (Base_Type (E)));
23370 end if;
23372 -- For first subtype, set flag on base type
23374 elsif Is_First_Subtype (E) then
23375 Set_Suppress_Initialization (Base_Type (E));
23377 -- For other than first subtype, set flag on subtype or variable
23379 else
23380 Set_Suppress_Initialization (E);
23381 end if;
23382 end Suppress_Init;
23384 -----------------
23385 -- System_Name --
23386 -----------------
23388 -- pragma System_Name (DIRECT_NAME);
23390 -- Syntax check: one argument, which must be the identifier GNAT or
23391 -- the identifier GCC, no other identifiers are acceptable.
23393 when Pragma_System_Name =>
23394 GNAT_Pragma;
23395 Check_No_Identifiers;
23396 Check_Arg_Count (1);
23397 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
23399 -----------------------------
23400 -- Task_Dispatching_Policy --
23401 -----------------------------
23403 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
23405 when Pragma_Task_Dispatching_Policy => declare
23406 DP : Character;
23408 begin
23409 Check_Ada_83_Warning;
23410 Check_Arg_Count (1);
23411 Check_No_Identifiers;
23412 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
23413 Check_Valid_Configuration_Pragma;
23414 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
23415 DP := Fold_Upper (Name_Buffer (1));
23417 if Task_Dispatching_Policy /= ' '
23418 and then Task_Dispatching_Policy /= DP
23419 then
23420 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
23421 Error_Pragma
23422 ("task dispatching policy incompatible with policy#");
23424 -- Set new policy, but always preserve System_Location since we
23425 -- like the error message with the run time name.
23427 else
23428 Task_Dispatching_Policy := DP;
23430 if Task_Dispatching_Policy_Sloc /= System_Location then
23431 Task_Dispatching_Policy_Sloc := Loc;
23432 end if;
23433 end if;
23434 end;
23436 ---------------
23437 -- Task_Info --
23438 ---------------
23440 -- pragma Task_Info (EXPRESSION);
23442 when Pragma_Task_Info => Task_Info : declare
23443 P : constant Node_Id := Parent (N);
23444 Ent : Entity_Id;
23446 begin
23447 GNAT_Pragma;
23449 if Warn_On_Obsolescent_Feature then
23450 Error_Msg_N
23451 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
23452 & "instead?j?", N);
23453 end if;
23455 if Nkind (P) /= N_Task_Definition then
23456 Error_Pragma ("pragma% must appear in task definition");
23457 end if;
23459 Check_No_Identifiers;
23460 Check_Arg_Count (1);
23462 Analyze_And_Resolve
23463 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
23465 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
23466 return;
23467 end if;
23469 Ent := Defining_Identifier (Parent (P));
23471 -- Check duplicate pragma before we chain the pragma in the Rep
23472 -- Item chain of Ent.
23474 if Has_Rep_Pragma
23475 (Ent, Name_Task_Info, Check_Parents => False)
23476 then
23477 Error_Pragma ("duplicate pragma% not allowed");
23478 end if;
23480 Record_Rep_Item (Ent, N);
23481 end Task_Info;
23483 ---------------
23484 -- Task_Name --
23485 ---------------
23487 -- pragma Task_Name (string_EXPRESSION);
23489 when Pragma_Task_Name => Task_Name : declare
23490 P : constant Node_Id := Parent (N);
23491 Arg : Node_Id;
23492 Ent : Entity_Id;
23494 begin
23495 Check_No_Identifiers;
23496 Check_Arg_Count (1);
23498 Arg := Get_Pragma_Arg (Arg1);
23500 -- The expression is used in the call to Create_Task, and must be
23501 -- expanded there, not in the context of the current spec. It must
23502 -- however be analyzed to capture global references, in case it
23503 -- appears in a generic context.
23505 Preanalyze_And_Resolve (Arg, Standard_String);
23507 if Nkind (P) /= N_Task_Definition then
23508 Pragma_Misplaced;
23509 end if;
23511 Ent := Defining_Identifier (Parent (P));
23513 -- Check duplicate pragma before we chain the pragma in the Rep
23514 -- Item chain of Ent.
23516 if Has_Rep_Pragma
23517 (Ent, Name_Task_Name, Check_Parents => False)
23518 then
23519 Error_Pragma ("duplicate pragma% not allowed");
23520 end if;
23522 Record_Rep_Item (Ent, N);
23523 end Task_Name;
23525 ------------------
23526 -- Task_Storage --
23527 ------------------
23529 -- pragma Task_Storage (
23530 -- [Task_Type =>] LOCAL_NAME,
23531 -- [Top_Guard =>] static_integer_EXPRESSION);
23533 when Pragma_Task_Storage => Task_Storage : declare
23534 Args : Args_List (1 .. 2);
23535 Names : constant Name_List (1 .. 2) := (
23536 Name_Task_Type,
23537 Name_Top_Guard);
23539 Task_Type : Node_Id renames Args (1);
23540 Top_Guard : Node_Id renames Args (2);
23542 Ent : Entity_Id;
23544 begin
23545 GNAT_Pragma;
23546 Gather_Associations (Names, Args);
23548 if No (Task_Type) then
23549 Error_Pragma
23550 ("missing task_type argument for pragma%");
23551 end if;
23553 Check_Arg_Is_Local_Name (Task_Type);
23555 Ent := Entity (Task_Type);
23557 if not Is_Task_Type (Ent) then
23558 Error_Pragma_Arg
23559 ("argument for pragma% must be task type", Task_Type);
23560 end if;
23562 if No (Top_Guard) then
23563 Error_Pragma_Arg
23564 ("pragma% takes two arguments", Task_Type);
23565 else
23566 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
23567 end if;
23569 Check_First_Subtype (Task_Type);
23571 if Rep_Item_Too_Late (Ent, N) then
23572 raise Pragma_Exit;
23573 end if;
23574 end Task_Storage;
23576 ---------------
23577 -- Test_Case --
23578 ---------------
23580 -- pragma Test_Case
23581 -- ([Name =>] Static_String_EXPRESSION
23582 -- ,[Mode =>] MODE_TYPE
23583 -- [, Requires => Boolean_EXPRESSION]
23584 -- [, Ensures => Boolean_EXPRESSION]);
23586 -- MODE_TYPE ::= Nominal | Robustness
23588 -- Characteristics:
23590 -- * Analysis - The annotation undergoes initial checks to verify
23591 -- the legal placement and context. Secondary checks preanalyze the
23592 -- expressions in:
23594 -- Analyze_Test_Case_In_Decl_Part
23596 -- * Expansion - None.
23598 -- * Template - The annotation utilizes the generic template of the
23599 -- related subprogram when it is:
23601 -- aspect on subprogram declaration
23603 -- The annotation must prepare its own template when it is:
23605 -- pragma on subprogram declaration
23607 -- * Globals - Capture of global references must occur after full
23608 -- analysis.
23610 -- * Instance - The annotation is instantiated automatically when
23611 -- the related generic subprogram is instantiated except for the
23612 -- "pragma on subprogram declaration" case. In that scenario the
23613 -- annotation must instantiate itself.
23615 when Pragma_Test_Case => Test_Case : declare
23616 procedure Check_Distinct_Name (Subp_Id : Entity_Id);
23617 -- Ensure that the contract of subprogram Subp_Id does not contain
23618 -- another Test_Case pragma with the same Name as the current one.
23620 -------------------------
23621 -- Check_Distinct_Name --
23622 -------------------------
23624 procedure Check_Distinct_Name (Subp_Id : Entity_Id) is
23625 Items : constant Node_Id := Contract (Subp_Id);
23626 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
23627 Prag : Node_Id;
23629 begin
23630 -- Inspect all Test_Case pragma of the related subprogram
23631 -- looking for one with a duplicate "Name" argument.
23633 if Present (Items) then
23634 Prag := Contract_Test_Cases (Items);
23635 while Present (Prag) loop
23636 if Pragma_Name (Prag) = Name_Test_Case
23637 and then Prag /= N
23638 and then String_Equal
23639 (Name, Get_Name_From_CTC_Pragma (Prag))
23640 then
23641 Error_Msg_Sloc := Sloc (Prag);
23642 Error_Pragma ("name for pragma % is already used #");
23643 end if;
23645 Prag := Next_Pragma (Prag);
23646 end loop;
23647 end if;
23648 end Check_Distinct_Name;
23650 -- Local variables
23652 Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit));
23653 Asp_Arg : Node_Id;
23654 Context : Node_Id;
23655 Subp_Decl : Node_Id;
23656 Subp_Id : Entity_Id;
23658 -- Start of processing for Test_Case
23660 begin
23661 GNAT_Pragma;
23662 Check_At_Least_N_Arguments (2);
23663 Check_At_Most_N_Arguments (4);
23664 Check_Arg_Order
23665 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
23667 -- Argument "Name"
23669 Check_Optional_Identifier (Arg1, Name_Name);
23670 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
23672 -- Argument "Mode"
23674 Check_Optional_Identifier (Arg2, Name_Mode);
23675 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
23677 -- Arguments "Requires" and "Ensures"
23679 if Present (Arg3) then
23680 if Present (Arg4) then
23681 Check_Identifier (Arg3, Name_Requires);
23682 Check_Identifier (Arg4, Name_Ensures);
23683 else
23684 Check_Identifier_Is_One_Of
23685 (Arg3, Name_Requires, Name_Ensures);
23686 end if;
23687 end if;
23689 -- Pragma Test_Case must be associated with a subprogram declared
23690 -- in a library-level package. First determine whether the current
23691 -- compilation unit is a legal context.
23693 if Nkind_In (Pack_Decl, N_Package_Declaration,
23694 N_Generic_Package_Declaration)
23695 then
23696 null;
23698 -- Otherwise the placement is illegal
23700 else
23701 Error_Pragma
23702 ("pragma % must be specified within a package declaration");
23703 return;
23704 end if;
23706 Subp_Decl := Find_Related_Declaration_Or_Body (N);
23708 -- Find the enclosing context
23710 Context := Parent (Subp_Decl);
23712 if Present (Context) then
23713 Context := Parent (Context);
23714 end if;
23716 -- Verify the placement of the pragma
23718 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
23719 Error_Pragma
23720 ("pragma % cannot be applied to abstract subprogram");
23721 return;
23723 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
23724 Error_Pragma ("pragma % cannot be applied to entry");
23725 return;
23727 -- The context is a [generic] subprogram declared at the top level
23728 -- of the [generic] package unit.
23730 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
23731 N_Subprogram_Declaration)
23732 and then Present (Context)
23733 and then Nkind_In (Context, N_Generic_Package_Declaration,
23734 N_Package_Declaration)
23735 then
23736 null;
23738 -- Otherwise the placement is illegal
23740 else
23741 Error_Pragma
23742 ("pragma % must be applied to a library-level subprogram "
23743 & "declaration");
23744 return;
23745 end if;
23747 Subp_Id := Defining_Entity (Subp_Decl);
23749 -- A pragma that applies to a Ghost entity becomes Ghost for the
23750 -- purposes of legality checks and removal of ignored Ghost code.
23752 Mark_Ghost_Pragma (N, Subp_Id);
23754 -- Chain the pragma on the contract for further processing by
23755 -- Analyze_Test_Case_In_Decl_Part.
23757 Add_Contract_Item (N, Subp_Id);
23759 -- Preanalyze the original aspect argument "Name" for ASIS or for
23760 -- a generic subprogram to properly capture global references.
23762 if ASIS_Mode or else Is_Generic_Subprogram (Subp_Id) then
23763 Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True);
23765 if Present (Asp_Arg) then
23767 -- The argument appears with an identifier in association
23768 -- form.
23770 if Nkind (Asp_Arg) = N_Component_Association then
23771 Asp_Arg := Expression (Asp_Arg);
23772 end if;
23774 Check_Expr_Is_OK_Static_Expression
23775 (Asp_Arg, Standard_String);
23776 end if;
23777 end if;
23779 -- Ensure that the all Test_Case pragmas of the related subprogram
23780 -- have distinct names.
23782 Check_Distinct_Name (Subp_Id);
23784 -- Fully analyze the pragma when it appears inside an entry
23785 -- or subprogram body because it cannot benefit from forward
23786 -- references.
23788 if Nkind_In (Subp_Decl, N_Entry_Body,
23789 N_Subprogram_Body,
23790 N_Subprogram_Body_Stub)
23791 then
23792 -- The legality checks of pragma Test_Case are affected by the
23793 -- SPARK mode in effect and the volatility of the context.
23794 -- Analyze all pragmas in a specific order.
23796 Analyze_If_Present (Pragma_SPARK_Mode);
23797 Analyze_If_Present (Pragma_Volatile_Function);
23798 Analyze_Test_Case_In_Decl_Part (N);
23799 end if;
23800 end Test_Case;
23802 --------------------------
23803 -- Thread_Local_Storage --
23804 --------------------------
23806 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
23808 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
23809 E : Entity_Id;
23810 Id : Node_Id;
23812 begin
23813 GNAT_Pragma;
23814 Check_Arg_Count (1);
23815 Check_Optional_Identifier (Arg1, Name_Entity);
23816 Check_Arg_Is_Library_Level_Local_Name (Arg1);
23818 Id := Get_Pragma_Arg (Arg1);
23819 Analyze (Id);
23821 if not Is_Entity_Name (Id)
23822 or else Ekind (Entity (Id)) /= E_Variable
23823 then
23824 Error_Pragma_Arg ("local variable name required", Arg1);
23825 end if;
23827 E := Entity (Id);
23829 -- A pragma that applies to a Ghost entity becomes Ghost for the
23830 -- purposes of legality checks and removal of ignored Ghost code.
23832 Mark_Ghost_Pragma (N, E);
23834 if Rep_Item_Too_Early (E, N)
23835 or else
23836 Rep_Item_Too_Late (E, N)
23837 then
23838 raise Pragma_Exit;
23839 end if;
23841 Set_Has_Pragma_Thread_Local_Storage (E);
23842 Set_Has_Gigi_Rep_Item (E);
23843 end Thread_Local_Storage;
23845 ----------------
23846 -- Time_Slice --
23847 ----------------
23849 -- pragma Time_Slice (static_duration_EXPRESSION);
23851 when Pragma_Time_Slice => Time_Slice : declare
23852 Val : Ureal;
23853 Nod : Node_Id;
23855 begin
23856 GNAT_Pragma;
23857 Check_Arg_Count (1);
23858 Check_No_Identifiers;
23859 Check_In_Main_Program;
23860 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
23862 if not Error_Posted (Arg1) then
23863 Nod := Next (N);
23864 while Present (Nod) loop
23865 if Nkind (Nod) = N_Pragma
23866 and then Pragma_Name (Nod) = Name_Time_Slice
23867 then
23868 Error_Msg_Name_1 := Pname;
23869 Error_Msg_N ("duplicate pragma% not permitted", Nod);
23870 end if;
23872 Next (Nod);
23873 end loop;
23874 end if;
23876 -- Process only if in main unit
23878 if Get_Source_Unit (Loc) = Main_Unit then
23879 Opt.Time_Slice_Set := True;
23880 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
23882 if Val <= Ureal_0 then
23883 Opt.Time_Slice_Value := 0;
23885 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
23886 Opt.Time_Slice_Value := 1_000_000_000;
23888 else
23889 Opt.Time_Slice_Value :=
23890 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
23891 end if;
23892 end if;
23893 end Time_Slice;
23895 -----------
23896 -- Title --
23897 -----------
23899 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
23901 -- TITLING_OPTION ::=
23902 -- [Title =>] STRING_LITERAL
23903 -- | [Subtitle =>] STRING_LITERAL
23905 when Pragma_Title => Title : declare
23906 Args : Args_List (1 .. 2);
23907 Names : constant Name_List (1 .. 2) := (
23908 Name_Title,
23909 Name_Subtitle);
23911 begin
23912 GNAT_Pragma;
23913 Gather_Associations (Names, Args);
23914 Store_Note (N);
23916 for J in 1 .. 2 loop
23917 if Present (Args (J)) then
23918 Check_Arg_Is_OK_Static_Expression
23919 (Args (J), Standard_String);
23920 end if;
23921 end loop;
23922 end Title;
23924 ----------------------------
23925 -- Type_Invariant[_Class] --
23926 ----------------------------
23928 -- pragma Type_Invariant[_Class]
23929 -- ([Entity =>] type_LOCAL_NAME,
23930 -- [Check =>] EXPRESSION);
23932 when Pragma_Type_Invariant
23933 | Pragma_Type_Invariant_Class
23935 Type_Invariant : declare
23936 I_Pragma : Node_Id;
23938 begin
23939 Check_Arg_Count (2);
23941 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
23942 -- setting Class_Present for the Type_Invariant_Class case.
23944 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
23945 I_Pragma := New_Copy (N);
23946 Set_Pragma_Identifier
23947 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
23948 Rewrite (N, I_Pragma);
23949 Set_Analyzed (N, False);
23950 Analyze (N);
23951 end Type_Invariant;
23953 ---------------------
23954 -- Unchecked_Union --
23955 ---------------------
23957 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
23959 when Pragma_Unchecked_Union => Unchecked_Union : declare
23960 Assoc : constant Node_Id := Arg1;
23961 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
23962 Clist : Node_Id;
23963 Comp : Node_Id;
23964 Tdef : Node_Id;
23965 Typ : Entity_Id;
23966 Variant : Node_Id;
23967 Vpart : Node_Id;
23969 begin
23970 Ada_2005_Pragma;
23971 Check_No_Identifiers;
23972 Check_Arg_Count (1);
23973 Check_Arg_Is_Local_Name (Arg1);
23975 Find_Type (Type_Id);
23977 Typ := Entity (Type_Id);
23979 -- A pragma that applies to a Ghost entity becomes Ghost for the
23980 -- purposes of legality checks and removal of ignored Ghost code.
23982 Mark_Ghost_Pragma (N, Typ);
23984 if Typ = Any_Type
23985 or else Rep_Item_Too_Early (Typ, N)
23986 then
23987 return;
23988 else
23989 Typ := Underlying_Type (Typ);
23990 end if;
23992 if Rep_Item_Too_Late (Typ, N) then
23993 return;
23994 end if;
23996 Check_First_Subtype (Arg1);
23998 -- Note remaining cases are references to a type in the current
23999 -- declarative part. If we find an error, we post the error on
24000 -- the relevant type declaration at an appropriate point.
24002 if not Is_Record_Type (Typ) then
24003 Error_Msg_N ("unchecked union must be record type", Typ);
24004 return;
24006 elsif Is_Tagged_Type (Typ) then
24007 Error_Msg_N ("unchecked union must not be tagged", Typ);
24008 return;
24010 elsif not Has_Discriminants (Typ) then
24011 Error_Msg_N
24012 ("unchecked union must have one discriminant", Typ);
24013 return;
24015 -- Note: in previous versions of GNAT we used to check for limited
24016 -- types and give an error, but in fact the standard does allow
24017 -- Unchecked_Union on limited types, so this check was removed.
24019 -- Similarly, GNAT used to require that all discriminants have
24020 -- default values, but this is not mandated by the RM.
24022 -- Proceed with basic error checks completed
24024 else
24025 Tdef := Type_Definition (Declaration_Node (Typ));
24026 Clist := Component_List (Tdef);
24028 -- Check presence of component list and variant part
24030 if No (Clist) or else No (Variant_Part (Clist)) then
24031 Error_Msg_N
24032 ("unchecked union must have variant part", Tdef);
24033 return;
24034 end if;
24036 -- Check components
24038 Comp := First_Non_Pragma (Component_Items (Clist));
24039 while Present (Comp) loop
24040 Check_Component (Comp, Typ);
24041 Next_Non_Pragma (Comp);
24042 end loop;
24044 -- Check variant part
24046 Vpart := Variant_Part (Clist);
24048 Variant := First_Non_Pragma (Variants (Vpart));
24049 while Present (Variant) loop
24050 Check_Variant (Variant, Typ);
24051 Next_Non_Pragma (Variant);
24052 end loop;
24053 end if;
24055 Set_Is_Unchecked_Union (Typ);
24056 Set_Convention (Typ, Convention_C);
24057 Set_Has_Unchecked_Union (Base_Type (Typ));
24058 Set_Is_Unchecked_Union (Base_Type (Typ));
24059 end Unchecked_Union;
24061 ----------------------------
24062 -- Unevaluated_Use_Of_Old --
24063 ----------------------------
24065 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
24067 when Pragma_Unevaluated_Use_Of_Old =>
24068 GNAT_Pragma;
24069 Check_Arg_Count (1);
24070 Check_No_Identifiers;
24071 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
24073 -- Suppress/Unsuppress can appear as a configuration pragma, or in
24074 -- a declarative part or a package spec.
24076 if not Is_Configuration_Pragma then
24077 Check_Is_In_Decl_Part_Or_Package_Spec;
24078 end if;
24080 -- Store proper setting of Uneval_Old
24082 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
24083 Uneval_Old := Fold_Upper (Name_Buffer (1));
24085 ------------------------
24086 -- Unimplemented_Unit --
24087 ------------------------
24089 -- pragma Unimplemented_Unit;
24091 -- Note: this only gives an error if we are generating code, or if
24092 -- we are in a generic library unit (where the pragma appears in the
24093 -- body, not in the spec).
24095 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
24096 Cunitent : constant Entity_Id :=
24097 Cunit_Entity (Get_Source_Unit (Loc));
24098 Ent_Kind : constant Entity_Kind := Ekind (Cunitent);
24100 begin
24101 GNAT_Pragma;
24102 Check_Arg_Count (0);
24104 if Operating_Mode = Generate_Code
24105 or else Ent_Kind = E_Generic_Function
24106 or else Ent_Kind = E_Generic_Procedure
24107 or else Ent_Kind = E_Generic_Package
24108 then
24109 Get_Name_String (Chars (Cunitent));
24110 Set_Casing (Mixed_Case);
24111 Write_Str (Name_Buffer (1 .. Name_Len));
24112 Write_Str (" is not supported in this configuration");
24113 Write_Eol;
24114 raise Unrecoverable_Error;
24115 end if;
24116 end Unimplemented_Unit;
24118 ------------------------
24119 -- Universal_Aliasing --
24120 ------------------------
24122 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
24124 when Pragma_Universal_Aliasing => Universal_Alias : declare
24125 E : Entity_Id;
24126 E_Id : Node_Id;
24128 begin
24129 GNAT_Pragma;
24130 Check_Arg_Count (1);
24131 Check_Optional_Identifier (Arg2, Name_Entity);
24132 Check_Arg_Is_Local_Name (Arg1);
24133 E_Id := Get_Pragma_Arg (Arg1);
24135 if Etype (E_Id) = Any_Type then
24136 return;
24137 end if;
24139 E := Entity (E_Id);
24141 if not Is_Type (E) then
24142 Error_Pragma_Arg ("pragma% requires type", Arg1);
24143 end if;
24145 -- A pragma that applies to a Ghost entity becomes Ghost for the
24146 -- purposes of legality checks and removal of ignored Ghost code.
24148 Mark_Ghost_Pragma (N, E);
24149 Set_Universal_Aliasing (Base_Type (E));
24150 Record_Rep_Item (E, N);
24151 end Universal_Alias;
24153 --------------------
24154 -- Universal_Data --
24155 --------------------
24157 -- pragma Universal_Data [(library_unit_NAME)];
24159 when Pragma_Universal_Data =>
24160 GNAT_Pragma;
24161 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
24163 ----------------
24164 -- Unmodified --
24165 ----------------
24167 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
24169 when Pragma_Unmodified =>
24170 Analyze_Unmodified_Or_Unused;
24172 ------------------
24173 -- Unreferenced --
24174 ------------------
24176 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
24178 -- or when used in a context clause:
24180 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
24182 when Pragma_Unreferenced =>
24183 Analyze_Unreferenced_Or_Unused;
24185 --------------------------
24186 -- Unreferenced_Objects --
24187 --------------------------
24189 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
24191 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
24192 Arg : Node_Id;
24193 Arg_Expr : Node_Id;
24194 Arg_Id : Entity_Id;
24196 Ghost_Error_Posted : Boolean := False;
24197 -- Flag set when an error concerning the illegal mix of Ghost and
24198 -- non-Ghost types is emitted.
24200 Ghost_Id : Entity_Id := Empty;
24201 -- The entity of the first Ghost type encountered while processing
24202 -- the arguments of the pragma.
24204 begin
24205 GNAT_Pragma;
24206 Check_At_Least_N_Arguments (1);
24208 Arg := Arg1;
24209 while Present (Arg) loop
24210 Check_No_Identifier (Arg);
24211 Check_Arg_Is_Local_Name (Arg);
24212 Arg_Expr := Get_Pragma_Arg (Arg);
24214 if Is_Entity_Name (Arg_Expr) then
24215 Arg_Id := Entity (Arg_Expr);
24217 if Is_Type (Arg_Id) then
24218 Set_Has_Pragma_Unreferenced_Objects (Arg_Id);
24220 -- A pragma that applies to a Ghost entity becomes Ghost
24221 -- for the purposes of legality checks and removal of
24222 -- ignored Ghost code.
24224 Mark_Ghost_Pragma (N, Arg_Id);
24226 -- Capture the entity of the first Ghost type being
24227 -- processed for error detection purposes.
24229 if Is_Ghost_Entity (Arg_Id) then
24230 if No (Ghost_Id) then
24231 Ghost_Id := Arg_Id;
24232 end if;
24234 -- Otherwise the type is non-Ghost. It is illegal to mix
24235 -- references to Ghost and non-Ghost entities
24236 -- (SPARK RM 6.9).
24238 elsif Present (Ghost_Id)
24239 and then not Ghost_Error_Posted
24240 then
24241 Ghost_Error_Posted := True;
24243 Error_Msg_Name_1 := Pname;
24244 Error_Msg_N
24245 ("pragma % cannot mention ghost and non-ghost types",
24248 Error_Msg_Sloc := Sloc (Ghost_Id);
24249 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
24251 Error_Msg_Sloc := Sloc (Arg_Id);
24252 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
24253 end if;
24254 else
24255 Error_Pragma_Arg
24256 ("argument for pragma% must be type or subtype", Arg);
24257 end if;
24258 else
24259 Error_Pragma_Arg
24260 ("argument for pragma% must be type or subtype", Arg);
24261 end if;
24263 Next (Arg);
24264 end loop;
24265 end Unreferenced_Objects;
24267 ------------------------------
24268 -- Unreserve_All_Interrupts --
24269 ------------------------------
24271 -- pragma Unreserve_All_Interrupts;
24273 when Pragma_Unreserve_All_Interrupts =>
24274 GNAT_Pragma;
24275 Check_Arg_Count (0);
24277 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
24278 Unreserve_All_Interrupts := True;
24279 end if;
24281 ----------------
24282 -- Unsuppress --
24283 ----------------
24285 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
24287 when Pragma_Unsuppress =>
24288 Ada_2005_Pragma;
24289 Process_Suppress_Unsuppress (Suppress_Case => False);
24291 ------------
24292 -- Unused --
24293 ------------
24295 -- pragma Unused (LOCAL_NAME {, LOCAL_NAME});
24297 when Pragma_Unused =>
24298 Analyze_Unmodified_Or_Unused (Is_Unused => True);
24299 Analyze_Unreferenced_Or_Unused (Is_Unused => True);
24301 -------------------
24302 -- Use_VADS_Size --
24303 -------------------
24305 -- pragma Use_VADS_Size;
24307 when Pragma_Use_VADS_Size =>
24308 GNAT_Pragma;
24309 Check_Arg_Count (0);
24310 Check_Valid_Configuration_Pragma;
24311 Use_VADS_Size := True;
24313 ---------------------
24314 -- Validity_Checks --
24315 ---------------------
24317 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
24319 when Pragma_Validity_Checks => Validity_Checks : declare
24320 A : constant Node_Id := Get_Pragma_Arg (Arg1);
24321 S : String_Id;
24322 C : Char_Code;
24324 begin
24325 GNAT_Pragma;
24326 Check_Arg_Count (1);
24327 Check_No_Identifiers;
24329 -- Pragma always active unless in CodePeer or GNATprove modes,
24330 -- which use a fixed configuration of validity checks.
24332 if not (CodePeer_Mode or GNATprove_Mode) then
24333 if Nkind (A) = N_String_Literal then
24334 S := Strval (A);
24336 declare
24337 Slen : constant Natural := Natural (String_Length (S));
24338 Options : String (1 .. Slen);
24339 J : Positive;
24341 begin
24342 -- Couldn't we use a for loop here over Options'Range???
24344 J := 1;
24345 loop
24346 C := Get_String_Char (S, Pos (J));
24348 -- This is a weird test, it skips setting validity
24349 -- checks entirely if any element of S is out of
24350 -- range of Character, what is that about ???
24352 exit when not In_Character_Range (C);
24353 Options (J) := Get_Character (C);
24355 if J = Slen then
24356 Set_Validity_Check_Options (Options);
24357 exit;
24358 else
24359 J := J + 1;
24360 end if;
24361 end loop;
24362 end;
24364 elsif Nkind (A) = N_Identifier then
24365 if Chars (A) = Name_All_Checks then
24366 Set_Validity_Check_Options ("a");
24367 elsif Chars (A) = Name_On then
24368 Validity_Checks_On := True;
24369 elsif Chars (A) = Name_Off then
24370 Validity_Checks_On := False;
24371 end if;
24372 end if;
24373 end if;
24374 end Validity_Checks;
24376 --------------
24377 -- Volatile --
24378 --------------
24380 -- pragma Volatile (LOCAL_NAME);
24382 when Pragma_Volatile =>
24383 Process_Atomic_Independent_Shared_Volatile;
24385 -------------------------
24386 -- Volatile_Components --
24387 -------------------------
24389 -- pragma Volatile_Components (array_LOCAL_NAME);
24391 -- Volatile is handled by the same circuit as Atomic_Components
24393 --------------------------
24394 -- Volatile_Full_Access --
24395 --------------------------
24397 -- pragma Volatile_Full_Access (LOCAL_NAME);
24399 when Pragma_Volatile_Full_Access =>
24400 GNAT_Pragma;
24401 Process_Atomic_Independent_Shared_Volatile;
24403 -----------------------
24404 -- Volatile_Function --
24405 -----------------------
24407 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
24409 when Pragma_Volatile_Function => Volatile_Function : declare
24410 Over_Id : Entity_Id;
24411 Spec_Id : Entity_Id;
24412 Subp_Decl : Node_Id;
24414 begin
24415 GNAT_Pragma;
24416 Check_No_Identifiers;
24417 Check_At_Most_N_Arguments (1);
24419 Subp_Decl :=
24420 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
24422 -- Generic subprogram
24424 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
24425 null;
24427 -- Body acts as spec
24429 elsif Nkind (Subp_Decl) = N_Subprogram_Body
24430 and then No (Corresponding_Spec (Subp_Decl))
24431 then
24432 null;
24434 -- Body stub acts as spec
24436 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
24437 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
24438 then
24439 null;
24441 -- Subprogram
24443 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
24444 null;
24446 else
24447 Pragma_Misplaced;
24448 return;
24449 end if;
24451 Spec_Id := Unique_Defining_Entity (Subp_Decl);
24453 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
24454 Pragma_Misplaced;
24455 return;
24456 end if;
24458 -- A pragma that applies to a Ghost entity becomes Ghost for the
24459 -- purposes of legality checks and removal of ignored Ghost code.
24461 Mark_Ghost_Pragma (N, Spec_Id);
24463 -- Chain the pragma on the contract for completeness
24465 Add_Contract_Item (N, Spec_Id);
24467 -- The legality checks of pragma Volatile_Function are affected by
24468 -- the SPARK mode in effect. Analyze all pragmas in a specific
24469 -- order.
24471 Analyze_If_Present (Pragma_SPARK_Mode);
24473 -- A volatile function cannot override a non-volatile function
24474 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
24475 -- in New_Overloaded_Entity, however at that point the pragma has
24476 -- not been processed yet.
24478 Over_Id := Overridden_Operation (Spec_Id);
24480 if Present (Over_Id)
24481 and then not Is_Volatile_Function (Over_Id)
24482 then
24483 Error_Msg_N
24484 ("incompatible volatile function values in effect", Spec_Id);
24486 Error_Msg_Sloc := Sloc (Over_Id);
24487 Error_Msg_N
24488 ("\& declared # with Volatile_Function value False",
24489 Spec_Id);
24491 Error_Msg_Sloc := Sloc (Spec_Id);
24492 Error_Msg_N
24493 ("\overridden # with Volatile_Function value True",
24494 Spec_Id);
24495 end if;
24497 -- Analyze the Boolean expression (if any)
24499 if Present (Arg1) then
24500 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
24501 end if;
24502 end Volatile_Function;
24504 ----------------------
24505 -- Warning_As_Error --
24506 ----------------------
24508 -- pragma Warning_As_Error (static_string_EXPRESSION);
24510 when Pragma_Warning_As_Error =>
24511 GNAT_Pragma;
24512 Check_Arg_Count (1);
24513 Check_No_Identifiers;
24514 Check_Valid_Configuration_Pragma;
24516 if not Is_Static_String_Expression (Arg1) then
24517 Error_Pragma_Arg
24518 ("argument of pragma% must be static string expression",
24519 Arg1);
24521 -- OK static string expression
24523 else
24524 Acquire_Warning_Match_String (Arg1);
24525 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
24526 Warnings_As_Errors (Warnings_As_Errors_Count) :=
24527 new String'(Name_Buffer (1 .. Name_Len));
24528 end if;
24530 --------------
24531 -- Warnings --
24532 --------------
24534 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
24536 -- DETAILS ::= On | Off
24537 -- DETAILS ::= On | Off, local_NAME
24538 -- DETAILS ::= static_string_EXPRESSION
24539 -- DETAILS ::= On | Off, static_string_EXPRESSION
24541 -- TOOL_NAME ::= GNAT | GNATProve
24543 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
24545 -- Note: If the first argument matches an allowed tool name, it is
24546 -- always considered to be a tool name, even if there is a string
24547 -- variable of that name.
24549 -- Note if the second argument of DETAILS is a local_NAME then the
24550 -- second form is always understood. If the intention is to use
24551 -- the fourth form, then you can write NAME & "" to force the
24552 -- intepretation as a static_string_EXPRESSION.
24554 when Pragma_Warnings => Warnings : declare
24555 Reason : String_Id;
24557 begin
24558 GNAT_Pragma;
24559 Check_At_Least_N_Arguments (1);
24561 -- See if last argument is labeled Reason. If so, make sure we
24562 -- have a string literal or a concatenation of string literals,
24563 -- and acquire the REASON string. Then remove the REASON argument
24564 -- by decreasing Num_Args by one; Remaining processing looks only
24565 -- at first Num_Args arguments).
24567 declare
24568 Last_Arg : constant Node_Id :=
24569 Last (Pragma_Argument_Associations (N));
24571 begin
24572 if Nkind (Last_Arg) = N_Pragma_Argument_Association
24573 and then Chars (Last_Arg) = Name_Reason
24574 then
24575 Start_String;
24576 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
24577 Reason := End_String;
24578 Arg_Count := Arg_Count - 1;
24580 -- Not allowed in compiler units (bootstrap issues)
24582 Check_Compiler_Unit ("Reason for pragma Warnings", N);
24584 -- No REASON string, set null string as reason
24586 else
24587 Reason := Null_String_Id;
24588 end if;
24589 end;
24591 -- Now proceed with REASON taken care of and eliminated
24593 Check_No_Identifiers;
24595 -- If debug flag -gnatd.i is set, pragma is ignored
24597 if Debug_Flag_Dot_I then
24598 return;
24599 end if;
24601 -- Process various forms of the pragma
24603 declare
24604 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
24605 Shifted_Args : List_Id;
24607 begin
24608 -- See if first argument is a tool name, currently either
24609 -- GNAT or GNATprove. If so, either ignore the pragma if the
24610 -- tool used does not match, or continue as if no tool name
24611 -- was given otherwise, by shifting the arguments.
24613 if Nkind (Argx) = N_Identifier
24614 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
24615 then
24616 if Chars (Argx) = Name_Gnat then
24617 if CodePeer_Mode or GNATprove_Mode or ASIS_Mode then
24618 Rewrite (N, Make_Null_Statement (Loc));
24619 Analyze (N);
24620 raise Pragma_Exit;
24621 end if;
24623 elsif Chars (Argx) = Name_Gnatprove then
24624 if not GNATprove_Mode then
24625 Rewrite (N, Make_Null_Statement (Loc));
24626 Analyze (N);
24627 raise Pragma_Exit;
24628 end if;
24630 else
24631 raise Program_Error;
24632 end if;
24634 -- At this point, the pragma Warnings applies to the tool,
24635 -- so continue with shifted arguments.
24637 Arg_Count := Arg_Count - 1;
24639 if Arg_Count = 1 then
24640 Shifted_Args := New_List (New_Copy (Arg2));
24641 elsif Arg_Count = 2 then
24642 Shifted_Args := New_List (New_Copy (Arg2),
24643 New_Copy (Arg3));
24644 elsif Arg_Count = 3 then
24645 Shifted_Args := New_List (New_Copy (Arg2),
24646 New_Copy (Arg3),
24647 New_Copy (Arg4));
24648 else
24649 raise Program_Error;
24650 end if;
24652 Rewrite (N,
24653 Make_Pragma (Loc,
24654 Chars => Name_Warnings,
24655 Pragma_Argument_Associations => Shifted_Args));
24656 Analyze (N);
24657 raise Pragma_Exit;
24658 end if;
24660 -- One argument case
24662 if Arg_Count = 1 then
24664 -- On/Off one argument case was processed by parser
24666 if Nkind (Argx) = N_Identifier
24667 and then Nam_In (Chars (Argx), Name_On, Name_Off)
24668 then
24669 null;
24671 -- One argument case must be ON/OFF or static string expr
24673 elsif not Is_Static_String_Expression (Arg1) then
24674 Error_Pragma_Arg
24675 ("argument of pragma% must be On/Off or static string "
24676 & "expression", Arg1);
24678 -- One argument string expression case
24680 else
24681 declare
24682 Lit : constant Node_Id := Expr_Value_S (Argx);
24683 Str : constant String_Id := Strval (Lit);
24684 Len : constant Nat := String_Length (Str);
24685 C : Char_Code;
24686 J : Nat;
24687 OK : Boolean;
24688 Chr : Character;
24690 begin
24691 J := 1;
24692 while J <= Len loop
24693 C := Get_String_Char (Str, J);
24694 OK := In_Character_Range (C);
24696 if OK then
24697 Chr := Get_Character (C);
24699 -- Dash case: only -Wxxx is accepted
24701 if J = 1
24702 and then J < Len
24703 and then Chr = '-'
24704 then
24705 J := J + 1;
24706 C := Get_String_Char (Str, J);
24707 Chr := Get_Character (C);
24708 exit when Chr = 'W';
24709 OK := False;
24711 -- Dot case
24713 elsif J < Len and then Chr = '.' then
24714 J := J + 1;
24715 C := Get_String_Char (Str, J);
24716 Chr := Get_Character (C);
24718 if not Set_Dot_Warning_Switch (Chr) then
24719 Error_Pragma_Arg
24720 ("invalid warning switch character "
24721 & '.' & Chr, Arg1);
24722 end if;
24724 -- Non-Dot case
24726 else
24727 OK := Set_Warning_Switch (Chr);
24728 end if;
24730 if not OK then
24731 Error_Pragma_Arg
24732 ("invalid warning switch character " & Chr,
24733 Arg1);
24734 end if;
24736 else
24737 Error_Pragma_Arg
24738 ("invalid wide character in warning switch ",
24739 Arg1);
24740 end if;
24742 J := J + 1;
24743 end loop;
24744 end;
24745 end if;
24747 -- Two or more arguments (must be two)
24749 else
24750 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
24751 Check_Arg_Count (2);
24753 declare
24754 E_Id : Node_Id;
24755 E : Entity_Id;
24756 Err : Boolean;
24758 begin
24759 E_Id := Get_Pragma_Arg (Arg2);
24760 Analyze (E_Id);
24762 -- In the expansion of an inlined body, a reference to
24763 -- the formal may be wrapped in a conversion if the
24764 -- actual is a conversion. Retrieve the real entity name.
24766 if (In_Instance_Body or In_Inlined_Body)
24767 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
24768 then
24769 E_Id := Expression (E_Id);
24770 end if;
24772 -- Entity name case
24774 if Is_Entity_Name (E_Id) then
24775 E := Entity (E_Id);
24777 if E = Any_Id then
24778 return;
24779 else
24780 loop
24781 Set_Warnings_Off
24782 (E, (Chars (Get_Pragma_Arg (Arg1)) =
24783 Name_Off));
24785 -- Suppress elaboration warnings if the entity
24786 -- denotes an elaboration target.
24788 if Is_Elaboration_Target (E) then
24789 Set_Is_Elaboration_Warnings_OK_Id (E, False);
24790 end if;
24792 -- For OFF case, make entry in warnings off
24793 -- pragma table for later processing. But we do
24794 -- not do that within an instance, since these
24795 -- warnings are about what is needed in the
24796 -- template, not an instance of it.
24798 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
24799 and then Warn_On_Warnings_Off
24800 and then not In_Instance
24801 then
24802 Warnings_Off_Pragmas.Append ((N, E, Reason));
24803 end if;
24805 if Is_Enumeration_Type (E) then
24806 declare
24807 Lit : Entity_Id;
24808 begin
24809 Lit := First_Literal (E);
24810 while Present (Lit) loop
24811 Set_Warnings_Off (Lit);
24812 Next_Literal (Lit);
24813 end loop;
24814 end;
24815 end if;
24817 exit when No (Homonym (E));
24818 E := Homonym (E);
24819 end loop;
24820 end if;
24822 -- Error if not entity or static string expression case
24824 elsif not Is_Static_String_Expression (Arg2) then
24825 Error_Pragma_Arg
24826 ("second argument of pragma% must be entity name "
24827 & "or static string expression", Arg2);
24829 -- Static string expression case
24831 else
24832 Acquire_Warning_Match_String (Arg2);
24834 -- Note on configuration pragma case: If this is a
24835 -- configuration pragma, then for an OFF pragma, we
24836 -- just set Config True in the call, which is all
24837 -- that needs to be done. For the case of ON, this
24838 -- is normally an error, unless it is canceling the
24839 -- effect of a previous OFF pragma in the same file.
24840 -- In any other case, an error will be signalled (ON
24841 -- with no matching OFF).
24843 -- Note: We set Used if we are inside a generic to
24844 -- disable the test that the non-config case actually
24845 -- cancels a warning. That's because we can't be sure
24846 -- there isn't an instantiation in some other unit
24847 -- where a warning is suppressed.
24849 -- We could do a little better here by checking if the
24850 -- generic unit we are inside is public, but for now
24851 -- we don't bother with that refinement.
24853 if Chars (Argx) = Name_Off then
24854 Set_Specific_Warning_Off
24855 (Loc, Name_Buffer (1 .. Name_Len), Reason,
24856 Config => Is_Configuration_Pragma,
24857 Used => Inside_A_Generic or else In_Instance);
24859 elsif Chars (Argx) = Name_On then
24860 Set_Specific_Warning_On
24861 (Loc, Name_Buffer (1 .. Name_Len), Err);
24863 if Err then
24864 Error_Msg
24865 ("??pragma Warnings On with no matching "
24866 & "Warnings Off", Loc);
24867 end if;
24868 end if;
24869 end if;
24870 end;
24871 end if;
24872 end;
24873 end Warnings;
24875 -------------------
24876 -- Weak_External --
24877 -------------------
24879 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
24881 when Pragma_Weak_External => Weak_External : declare
24882 Ent : Entity_Id;
24884 begin
24885 GNAT_Pragma;
24886 Check_Arg_Count (1);
24887 Check_Optional_Identifier (Arg1, Name_Entity);
24888 Check_Arg_Is_Library_Level_Local_Name (Arg1);
24889 Ent := Entity (Get_Pragma_Arg (Arg1));
24891 if Rep_Item_Too_Early (Ent, N) then
24892 return;
24893 else
24894 Ent := Underlying_Type (Ent);
24895 end if;
24897 -- The only processing required is to link this item on to the
24898 -- list of rep items for the given entity. This is accomplished
24899 -- by the call to Rep_Item_Too_Late (when no error is detected
24900 -- and False is returned).
24902 if Rep_Item_Too_Late (Ent, N) then
24903 return;
24904 else
24905 Set_Has_Gigi_Rep_Item (Ent);
24906 end if;
24907 end Weak_External;
24909 -----------------------------
24910 -- Wide_Character_Encoding --
24911 -----------------------------
24913 -- pragma Wide_Character_Encoding (IDENTIFIER);
24915 when Pragma_Wide_Character_Encoding =>
24916 GNAT_Pragma;
24918 -- Nothing to do, handled in parser. Note that we do not enforce
24919 -- configuration pragma placement, this pragma can appear at any
24920 -- place in the source, allowing mixed encodings within a single
24921 -- source program.
24923 null;
24925 --------------------
24926 -- Unknown_Pragma --
24927 --------------------
24929 -- Should be impossible, since the case of an unknown pragma is
24930 -- separately processed before the case statement is entered.
24932 when Unknown_Pragma =>
24933 raise Program_Error;
24934 end case;
24936 -- AI05-0144: detect dangerous order dependence. Disabled for now,
24937 -- until AI is formally approved.
24939 -- Check_Order_Dependence;
24941 exception
24942 when Pragma_Exit => null;
24943 end Analyze_Pragma;
24945 ---------------------------------------------
24946 -- Analyze_Pre_Post_Condition_In_Decl_Part --
24947 ---------------------------------------------
24949 -- WARNING: This routine manages Ghost regions. Return statements must be
24950 -- replaced by gotos which jump to the end of the routine and restore the
24951 -- Ghost mode.
24953 procedure Analyze_Pre_Post_Condition_In_Decl_Part
24954 (N : Node_Id;
24955 Freeze_Id : Entity_Id := Empty)
24957 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
24958 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
24960 Disp_Typ : Entity_Id;
24961 -- The dispatching type of the subprogram subject to the pre- or
24962 -- postcondition.
24964 function Check_References (Nod : Node_Id) return Traverse_Result;
24965 -- Check that expression Nod does not mention non-primitives of the
24966 -- type, global objects of the type, or other illegalities described
24967 -- and implied by AI12-0113.
24969 ----------------------
24970 -- Check_References --
24971 ----------------------
24973 function Check_References (Nod : Node_Id) return Traverse_Result is
24974 begin
24975 if Nkind (Nod) = N_Function_Call
24976 and then Is_Entity_Name (Name (Nod))
24977 then
24978 declare
24979 Func : constant Entity_Id := Entity (Name (Nod));
24980 Form : Entity_Id;
24982 begin
24983 -- An operation of the type must be a primitive
24985 if No (Find_Dispatching_Type (Func)) then
24986 Form := First_Formal (Func);
24987 while Present (Form) loop
24988 if Etype (Form) = Disp_Typ then
24989 Error_Msg_NE
24990 ("operation in class-wide condition must be "
24991 & "primitive of &", Nod, Disp_Typ);
24992 end if;
24994 Next_Formal (Form);
24995 end loop;
24997 -- A return object of the type is illegal as well
24999 if Etype (Func) = Disp_Typ
25000 or else Etype (Func) = Class_Wide_Type (Disp_Typ)
25001 then
25002 Error_Msg_NE
25003 ("operation in class-wide condition must be primitive "
25004 & "of &", Nod, Disp_Typ);
25005 end if;
25007 -- Otherwise we have a call to an overridden primitive, and we
25008 -- will create a common class-wide clone for the body of
25009 -- original operation and its eventual inherited versions. If
25010 -- the original operation dispatches on result it is never
25011 -- inherited and there is no need for a clone. There is not
25012 -- need for a clone either in GNATprove mode, as cases that
25013 -- would require it are rejected (when an inherited primitive
25014 -- calls an overridden operation in a class-wide contract), and
25015 -- the clone would make proof impossible in some cases.
25017 elsif not Is_Abstract_Subprogram (Spec_Id)
25018 and then No (Class_Wide_Clone (Spec_Id))
25019 and then not Has_Controlling_Result (Spec_Id)
25020 and then not GNATprove_Mode
25021 then
25022 Build_Class_Wide_Clone_Decl (Spec_Id);
25023 end if;
25024 end;
25026 elsif Is_Entity_Name (Nod)
25027 and then
25028 (Etype (Nod) = Disp_Typ
25029 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
25030 and then Ekind_In (Entity (Nod), E_Constant, E_Variable)
25031 then
25032 Error_Msg_NE
25033 ("object in class-wide condition must be formal of type &",
25034 Nod, Disp_Typ);
25036 elsif Nkind (Nod) = N_Explicit_Dereference
25037 and then (Etype (Nod) = Disp_Typ
25038 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
25039 and then (not Is_Entity_Name (Prefix (Nod))
25040 or else not Is_Formal (Entity (Prefix (Nod))))
25041 then
25042 Error_Msg_NE
25043 ("operation in class-wide condition must be primitive of &",
25044 Nod, Disp_Typ);
25045 end if;
25047 return OK;
25048 end Check_References;
25050 procedure Check_Class_Wide_Condition is
25051 new Traverse_Proc (Check_References);
25053 -- Local variables
25055 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
25057 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
25058 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
25059 -- Save the Ghost-related attributes to restore on exit
25061 Errors : Nat;
25062 Restore_Scope : Boolean := False;
25064 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
25066 begin
25067 -- Do not analyze the pragma multiple times
25069 if Is_Analyzed_Pragma (N) then
25070 return;
25071 end if;
25073 -- Set the Ghost mode in effect from the pragma. Due to the delayed
25074 -- analysis of the pragma, the Ghost mode at point of declaration and
25075 -- point of analysis may not necessarily be the same. Use the mode in
25076 -- effect at the point of declaration.
25078 Set_Ghost_Mode (N);
25080 -- Ensure that the subprogram and its formals are visible when analyzing
25081 -- the expression of the pragma.
25083 if not In_Open_Scopes (Spec_Id) then
25084 Restore_Scope := True;
25085 Push_Scope (Spec_Id);
25087 if Is_Generic_Subprogram (Spec_Id) then
25088 Install_Generic_Formals (Spec_Id);
25089 else
25090 Install_Formals (Spec_Id);
25091 end if;
25092 end if;
25094 Errors := Serious_Errors_Detected;
25095 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
25097 -- Emit a clarification message when the expression contains at least
25098 -- one undefined reference, possibly due to contract freezing.
25100 if Errors /= Serious_Errors_Detected
25101 and then Present (Freeze_Id)
25102 and then Has_Undefined_Reference (Expr)
25103 then
25104 Contract_Freeze_Error (Spec_Id, Freeze_Id);
25105 end if;
25107 if Class_Present (N) then
25109 -- Verify that a class-wide condition is legal, i.e. the operation is
25110 -- a primitive of a tagged type. Note that a generic subprogram is
25111 -- not a primitive operation.
25113 Disp_Typ := Find_Dispatching_Type (Spec_Id);
25115 if No (Disp_Typ) or else Is_Generic_Subprogram (Spec_Id) then
25116 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
25118 if From_Aspect_Specification (N) then
25119 Error_Msg_N
25120 ("aspect % can only be specified for a primitive operation "
25121 & "of a tagged type", Corresponding_Aspect (N));
25123 -- The pragma is a source construct
25125 else
25126 Error_Msg_N
25127 ("pragma % can only be specified for a primitive operation "
25128 & "of a tagged type", N);
25129 end if;
25131 -- Remaining semantic checks require a full tree traversal
25133 else
25134 Check_Class_Wide_Condition (Expr);
25135 end if;
25137 end if;
25139 if Restore_Scope then
25140 End_Scope;
25141 end if;
25143 -- If analysis of the condition indicates that a class-wide clone
25144 -- has been created, build and analyze its declaration.
25146 if Is_Subprogram (Spec_Id)
25147 and then Present (Class_Wide_Clone (Spec_Id))
25148 then
25149 Analyze (Unit_Declaration_Node (Class_Wide_Clone (Spec_Id)));
25150 end if;
25152 -- Currently it is not possible to inline pre/postconditions on a
25153 -- subprogram subject to pragma Inline_Always.
25155 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
25156 Set_Is_Analyzed_Pragma (N);
25158 Restore_Ghost_Region (Saved_GM, Saved_IGR);
25159 end Analyze_Pre_Post_Condition_In_Decl_Part;
25161 ------------------------------------------
25162 -- Analyze_Refined_Depends_In_Decl_Part --
25163 ------------------------------------------
25165 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
25166 procedure Check_Dependency_Clause
25167 (Spec_Id : Entity_Id;
25168 Dep_Clause : Node_Id;
25169 Dep_States : Elist_Id;
25170 Refinements : List_Id;
25171 Matched_Items : in out Elist_Id);
25172 -- Try to match a single dependency clause Dep_Clause against one or
25173 -- more refinement clauses found in list Refinements. Each successful
25174 -- match eliminates at least one refinement clause from Refinements.
25175 -- Spec_Id denotes the entity of the related subprogram. Dep_States
25176 -- denotes the entities of all abstract states which appear in pragma
25177 -- Depends. Matched_Items contains the entities of all successfully
25178 -- matched items found in pragma Depends.
25180 procedure Check_Output_States
25181 (Spec_Id : Entity_Id;
25182 Spec_Inputs : Elist_Id;
25183 Spec_Outputs : Elist_Id;
25184 Body_Inputs : Elist_Id;
25185 Body_Outputs : Elist_Id);
25186 -- Determine whether pragma Depends contains an output state with a
25187 -- visible refinement and if so, ensure that pragma Refined_Depends
25188 -- mentions all its constituents as outputs. Spec_Id is the entity of
25189 -- the related subprograms. Spec_Inputs and Spec_Outputs denote the
25190 -- inputs and outputs of the subprogram spec synthesized from pragma
25191 -- Depends. Body_Inputs and Body_Outputs denote the inputs and outputs
25192 -- of the subprogram body synthesized from pragma Refined_Depends.
25194 function Collect_States (Clauses : List_Id) return Elist_Id;
25195 -- Given a normalized list of dependencies obtained from calling
25196 -- Normalize_Clauses, return a list containing the entities of all
25197 -- states appearing in dependencies. It helps in checking refinements
25198 -- involving a state and a corresponding constituent which is not a
25199 -- direct constituent of the state.
25201 procedure Normalize_Clauses (Clauses : List_Id);
25202 -- Given a list of dependence or refinement clauses Clauses, normalize
25203 -- each clause by creating multiple dependencies with exactly one input
25204 -- and one output.
25206 procedure Remove_Extra_Clauses
25207 (Clauses : List_Id;
25208 Matched_Items : Elist_Id);
25209 -- Given a list of refinement clauses Clauses, remove all clauses whose
25210 -- inputs and/or outputs have been previously matched. See the body for
25211 -- all special cases. Matched_Items contains the entities of all matched
25212 -- items found in pragma Depends.
25214 procedure Report_Extra_Clauses
25215 (Spec_Id : Entity_Id;
25216 Clauses : List_Id);
25217 -- Emit an error for each extra clause found in list Clauses. Spec_Id
25218 -- denotes the entity of the related subprogram.
25220 -----------------------------
25221 -- Check_Dependency_Clause --
25222 -----------------------------
25224 procedure Check_Dependency_Clause
25225 (Spec_Id : Entity_Id;
25226 Dep_Clause : Node_Id;
25227 Dep_States : Elist_Id;
25228 Refinements : List_Id;
25229 Matched_Items : in out Elist_Id)
25231 Dep_Input : constant Node_Id := Expression (Dep_Clause);
25232 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
25234 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean;
25235 -- Determine whether dependency item Dep_Item has been matched in a
25236 -- previous clause.
25238 function Is_In_Out_State_Clause return Boolean;
25239 -- Determine whether dependence clause Dep_Clause denotes an abstract
25240 -- state that depends on itself (State => State).
25242 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
25243 -- Determine whether item Item denotes an abstract state with visible
25244 -- null refinement.
25246 procedure Match_Items
25247 (Dep_Item : Node_Id;
25248 Ref_Item : Node_Id;
25249 Matched : out Boolean);
25250 -- Try to match dependence item Dep_Item against refinement item
25251 -- Ref_Item. To match against a possible null refinement (see 2, 9),
25252 -- set Ref_Item to Empty. Flag Matched is set to True when one of
25253 -- the following conformance scenarios is in effect:
25254 -- 1) Both items denote null
25255 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
25256 -- 3) Both items denote attribute 'Result
25257 -- 4) Both items denote the same object
25258 -- 5) Both items denote the same formal parameter
25259 -- 6) Both items denote the same current instance of a type
25260 -- 7) Both items denote the same discriminant
25261 -- 8) Dep_Item is an abstract state with visible null refinement
25262 -- and Ref_Item denotes null.
25263 -- 9) Dep_Item is an abstract state with visible null refinement
25264 -- and Ref_Item is Empty (special case).
25265 -- 10) Dep_Item is an abstract state with full or partial visible
25266 -- non-null refinement and Ref_Item denotes one of its
25267 -- constituents.
25268 -- 11) Dep_Item is an abstract state without a full visible
25269 -- refinement and Ref_Item denotes the same state.
25270 -- When scenario 10 is in effect, the entity of the abstract state
25271 -- denoted by Dep_Item is added to list Refined_States.
25273 procedure Record_Item (Item_Id : Entity_Id);
25274 -- Store the entity of an item denoted by Item_Id in Matched_Items
25276 ------------------------
25277 -- Is_Already_Matched --
25278 ------------------------
25280 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean is
25281 Item_Id : Entity_Id := Empty;
25283 begin
25284 -- When the dependency item denotes attribute 'Result, check for
25285 -- the entity of the related subprogram.
25287 if Is_Attribute_Result (Dep_Item) then
25288 Item_Id := Spec_Id;
25290 elsif Is_Entity_Name (Dep_Item) then
25291 Item_Id := Available_View (Entity_Of (Dep_Item));
25292 end if;
25294 return
25295 Present (Item_Id) and then Contains (Matched_Items, Item_Id);
25296 end Is_Already_Matched;
25298 ----------------------------
25299 -- Is_In_Out_State_Clause --
25300 ----------------------------
25302 function Is_In_Out_State_Clause return Boolean is
25303 Dep_Input_Id : Entity_Id;
25304 Dep_Output_Id : Entity_Id;
25306 begin
25307 -- Detect the following clause:
25308 -- State => State
25310 if Is_Entity_Name (Dep_Input)
25311 and then Is_Entity_Name (Dep_Output)
25312 then
25313 -- Handle abstract views generated for limited with clauses
25315 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
25316 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
25318 return
25319 Ekind (Dep_Input_Id) = E_Abstract_State
25320 and then Dep_Input_Id = Dep_Output_Id;
25321 else
25322 return False;
25323 end if;
25324 end Is_In_Out_State_Clause;
25326 ---------------------------
25327 -- Is_Null_Refined_State --
25328 ---------------------------
25330 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
25331 Item_Id : Entity_Id;
25333 begin
25334 if Is_Entity_Name (Item) then
25336 -- Handle abstract views generated for limited with clauses
25338 Item_Id := Available_View (Entity_Of (Item));
25340 return
25341 Ekind (Item_Id) = E_Abstract_State
25342 and then Has_Null_Visible_Refinement (Item_Id);
25343 else
25344 return False;
25345 end if;
25346 end Is_Null_Refined_State;
25348 -----------------
25349 -- Match_Items --
25350 -----------------
25352 procedure Match_Items
25353 (Dep_Item : Node_Id;
25354 Ref_Item : Node_Id;
25355 Matched : out Boolean)
25357 Dep_Item_Id : Entity_Id;
25358 Ref_Item_Id : Entity_Id;
25360 begin
25361 -- Assume that the two items do not match
25363 Matched := False;
25365 -- A null matches null or Empty (special case)
25367 if Nkind (Dep_Item) = N_Null
25368 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
25369 then
25370 Matched := True;
25372 -- Attribute 'Result matches attribute 'Result
25374 elsif Is_Attribute_Result (Dep_Item)
25375 and then Is_Attribute_Result (Ref_Item)
25376 then
25377 -- Put the entity of the related function on the list of
25378 -- matched items because attribute 'Result does not carry
25379 -- an entity similar to states and constituents.
25381 Record_Item (Spec_Id);
25382 Matched := True;
25384 -- Abstract states, current instances of concurrent types,
25385 -- discriminants, formal parameters and objects.
25387 elsif Is_Entity_Name (Dep_Item) then
25389 -- Handle abstract views generated for limited with clauses
25391 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
25393 if Ekind (Dep_Item_Id) = E_Abstract_State then
25395 -- An abstract state with visible null refinement matches
25396 -- null or Empty (special case).
25398 if Has_Null_Visible_Refinement (Dep_Item_Id)
25399 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
25400 then
25401 Record_Item (Dep_Item_Id);
25402 Matched := True;
25404 -- An abstract state with visible non-null refinement
25405 -- matches one of its constituents, or itself for an
25406 -- abstract state with partial visible refinement.
25408 elsif Has_Non_Null_Visible_Refinement (Dep_Item_Id) then
25409 if Is_Entity_Name (Ref_Item) then
25410 Ref_Item_Id := Entity_Of (Ref_Item);
25412 if Ekind_In (Ref_Item_Id, E_Abstract_State,
25413 E_Constant,
25414 E_Variable)
25415 and then Present (Encapsulating_State (Ref_Item_Id))
25416 and then Find_Encapsulating_State
25417 (Dep_States, Ref_Item_Id) = Dep_Item_Id
25418 then
25419 Record_Item (Dep_Item_Id);
25420 Matched := True;
25422 elsif not Has_Visible_Refinement (Dep_Item_Id)
25423 and then Ref_Item_Id = Dep_Item_Id
25424 then
25425 Record_Item (Dep_Item_Id);
25426 Matched := True;
25427 end if;
25428 end if;
25430 -- An abstract state without a visible refinement matches
25431 -- itself.
25433 elsif Is_Entity_Name (Ref_Item)
25434 and then Entity_Of (Ref_Item) = Dep_Item_Id
25435 then
25436 Record_Item (Dep_Item_Id);
25437 Matched := True;
25438 end if;
25440 -- A current instance of a concurrent type, discriminant,
25441 -- formal parameter or an object matches itself.
25443 elsif Is_Entity_Name (Ref_Item)
25444 and then Entity_Of (Ref_Item) = Dep_Item_Id
25445 then
25446 Record_Item (Dep_Item_Id);
25447 Matched := True;
25448 end if;
25449 end if;
25450 end Match_Items;
25452 -----------------
25453 -- Record_Item --
25454 -----------------
25456 procedure Record_Item (Item_Id : Entity_Id) is
25457 begin
25458 if No (Matched_Items) then
25459 Matched_Items := New_Elmt_List;
25460 end if;
25462 Append_Unique_Elmt (Item_Id, Matched_Items);
25463 end Record_Item;
25465 -- Local variables
25467 Clause_Matched : Boolean := False;
25468 Dummy : Boolean := False;
25469 Inputs_Match : Boolean;
25470 Next_Ref_Clause : Node_Id;
25471 Outputs_Match : Boolean;
25472 Ref_Clause : Node_Id;
25473 Ref_Input : Node_Id;
25474 Ref_Output : Node_Id;
25476 -- Start of processing for Check_Dependency_Clause
25478 begin
25479 -- Do not perform this check in an instance because it was already
25480 -- performed successfully in the generic template.
25482 if Is_Generic_Instance (Spec_Id) then
25483 return;
25484 end if;
25486 -- Examine all refinement clauses and compare them against the
25487 -- dependence clause.
25489 Ref_Clause := First (Refinements);
25490 while Present (Ref_Clause) loop
25491 Next_Ref_Clause := Next (Ref_Clause);
25493 -- Obtain the attributes of the current refinement clause
25495 Ref_Input := Expression (Ref_Clause);
25496 Ref_Output := First (Choices (Ref_Clause));
25498 -- The current refinement clause matches the dependence clause
25499 -- when both outputs match and both inputs match. See routine
25500 -- Match_Items for all possible conformance scenarios.
25502 -- Depends Dep_Output => Dep_Input
25503 -- ^ ^
25504 -- match ? match ?
25505 -- v v
25506 -- Refined_Depends Ref_Output => Ref_Input
25508 Match_Items
25509 (Dep_Item => Dep_Input,
25510 Ref_Item => Ref_Input,
25511 Matched => Inputs_Match);
25513 Match_Items
25514 (Dep_Item => Dep_Output,
25515 Ref_Item => Ref_Output,
25516 Matched => Outputs_Match);
25518 -- An In_Out state clause may be matched against a refinement with
25519 -- a null input or null output as long as the non-null side of the
25520 -- relation contains a valid constituent of the In_Out_State.
25522 if Is_In_Out_State_Clause then
25524 -- Depends => (State => State)
25525 -- Refined_Depends => (null => Constit) -- OK
25527 if Inputs_Match
25528 and then not Outputs_Match
25529 and then Nkind (Ref_Output) = N_Null
25530 then
25531 Outputs_Match := True;
25532 end if;
25534 -- Depends => (State => State)
25535 -- Refined_Depends => (Constit => null) -- OK
25537 if not Inputs_Match
25538 and then Outputs_Match
25539 and then Nkind (Ref_Input) = N_Null
25540 then
25541 Inputs_Match := True;
25542 end if;
25543 end if;
25545 -- The current refinement clause is legally constructed following
25546 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
25547 -- the pool of candidates. The seach continues because a single
25548 -- dependence clause may have multiple matching refinements.
25550 if Inputs_Match and Outputs_Match then
25551 Clause_Matched := True;
25552 Remove (Ref_Clause);
25553 end if;
25555 Ref_Clause := Next_Ref_Clause;
25556 end loop;
25558 -- Depending on the order or composition of refinement clauses, an
25559 -- In_Out state clause may not be directly refinable.
25561 -- Refined_State => (State => (Constit_1, Constit_2))
25562 -- Depends => ((Output, State) => (Input, State))
25563 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
25565 -- Matching normalized clause (State => State) fails because there is
25566 -- no direct refinement capable of satisfying this relation. Another
25567 -- similar case arises when clauses (Constit_1 => Input) and (Output
25568 -- => Constit_2) are matched first, leaving no candidates for clause
25569 -- (State => State). Both scenarios are legal as long as one of the
25570 -- previous clauses mentioned a valid constituent of State.
25572 if not Clause_Matched
25573 and then Is_In_Out_State_Clause
25574 and then Is_Already_Matched (Dep_Input)
25575 then
25576 Clause_Matched := True;
25577 end if;
25579 -- A clause where the input is an abstract state with visible null
25580 -- refinement or a 'Result attribute is implicitly matched when the
25581 -- output has already been matched in a previous clause.
25583 -- Refined_State => (State => null)
25584 -- Depends => (Output => State) -- implicitly OK
25585 -- Refined_Depends => (Output => ...)
25586 -- Depends => (...'Result => State) -- implicitly OK
25587 -- Refined_Depends => (...'Result => ...)
25589 if not Clause_Matched
25590 and then Is_Null_Refined_State (Dep_Input)
25591 and then Is_Already_Matched (Dep_Output)
25592 then
25593 Clause_Matched := True;
25594 end if;
25596 -- A clause where the output is an abstract state with visible null
25597 -- refinement is implicitly matched when the input has already been
25598 -- matched in a previous clause.
25600 -- Refined_State => (State => null)
25601 -- Depends => (State => Input) -- implicitly OK
25602 -- Refined_Depends => (... => Input)
25604 if not Clause_Matched
25605 and then Is_Null_Refined_State (Dep_Output)
25606 and then Is_Already_Matched (Dep_Input)
25607 then
25608 Clause_Matched := True;
25609 end if;
25611 -- At this point either all refinement clauses have been examined or
25612 -- pragma Refined_Depends contains a solitary null. Only an abstract
25613 -- state with null refinement can possibly match these cases.
25615 -- Refined_State => (State => null)
25616 -- Depends => (State => null)
25617 -- Refined_Depends => null -- OK
25619 if not Clause_Matched then
25620 Match_Items
25621 (Dep_Item => Dep_Input,
25622 Ref_Item => Empty,
25623 Matched => Inputs_Match);
25625 Match_Items
25626 (Dep_Item => Dep_Output,
25627 Ref_Item => Empty,
25628 Matched => Outputs_Match);
25630 Clause_Matched := Inputs_Match and Outputs_Match;
25631 end if;
25633 -- If the contents of Refined_Depends are legal, then the current
25634 -- dependence clause should be satisfied either by an explicit match
25635 -- or by one of the special cases.
25637 if not Clause_Matched then
25638 SPARK_Msg_NE
25639 (Fix_Msg (Spec_Id, "dependence clause of subprogram & has no "
25640 & "matching refinement in body"), Dep_Clause, Spec_Id);
25641 end if;
25642 end Check_Dependency_Clause;
25644 -------------------------
25645 -- Check_Output_States --
25646 -------------------------
25648 procedure Check_Output_States
25649 (Spec_Id : Entity_Id;
25650 Spec_Inputs : Elist_Id;
25651 Spec_Outputs : Elist_Id;
25652 Body_Inputs : Elist_Id;
25653 Body_Outputs : Elist_Id)
25655 procedure Check_Constituent_Usage (State_Id : Entity_Id);
25656 -- Determine whether all constituents of state State_Id with full
25657 -- visible refinement are used as outputs in pragma Refined_Depends.
25658 -- Emit an error if this is not the case (SPARK RM 7.2.4(5)).
25660 -----------------------------
25661 -- Check_Constituent_Usage --
25662 -----------------------------
25664 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
25665 Constits : constant Elist_Id :=
25666 Partial_Refinement_Constituents (State_Id);
25667 Constit_Elmt : Elmt_Id;
25668 Constit_Id : Entity_Id;
25669 Only_Partial : constant Boolean :=
25670 not Has_Visible_Refinement (State_Id);
25671 Posted : Boolean := False;
25673 begin
25674 if Present (Constits) then
25675 Constit_Elmt := First_Elmt (Constits);
25676 while Present (Constit_Elmt) loop
25677 Constit_Id := Node (Constit_Elmt);
25679 -- Issue an error when a constituent of State_Id is used,
25680 -- and State_Id has only partial visible refinement
25681 -- (SPARK RM 7.2.4(3d)).
25683 if Only_Partial then
25684 if (Present (Body_Inputs)
25685 and then Appears_In (Body_Inputs, Constit_Id))
25686 or else
25687 (Present (Body_Outputs)
25688 and then Appears_In (Body_Outputs, Constit_Id))
25689 then
25690 Error_Msg_Name_1 := Chars (State_Id);
25691 SPARK_Msg_NE
25692 ("constituent & of state % cannot be used in "
25693 & "dependence refinement", N, Constit_Id);
25694 Error_Msg_Name_1 := Chars (State_Id);
25695 SPARK_Msg_N ("\use state % instead", N);
25696 end if;
25698 -- The constituent acts as an input (SPARK RM 7.2.5(3))
25700 elsif Present (Body_Inputs)
25701 and then Appears_In (Body_Inputs, Constit_Id)
25702 then
25703 Error_Msg_Name_1 := Chars (State_Id);
25704 SPARK_Msg_NE
25705 ("constituent & of state % must act as output in "
25706 & "dependence refinement", N, Constit_Id);
25708 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
25710 elsif No (Body_Outputs)
25711 or else not Appears_In (Body_Outputs, Constit_Id)
25712 then
25713 if not Posted then
25714 Posted := True;
25715 SPARK_Msg_NE
25716 ("output state & must be replaced by all its "
25717 & "constituents in dependence refinement",
25718 N, State_Id);
25719 end if;
25721 SPARK_Msg_NE
25722 ("\constituent & is missing in output list",
25723 N, Constit_Id);
25724 end if;
25726 Next_Elmt (Constit_Elmt);
25727 end loop;
25728 end if;
25729 end Check_Constituent_Usage;
25731 -- Local variables
25733 Item : Node_Id;
25734 Item_Elmt : Elmt_Id;
25735 Item_Id : Entity_Id;
25737 -- Start of processing for Check_Output_States
25739 begin
25740 -- Do not perform this check in an instance because it was already
25741 -- performed successfully in the generic template.
25743 if Is_Generic_Instance (Spec_Id) then
25744 null;
25746 -- Inspect the outputs of pragma Depends looking for a state with a
25747 -- visible refinement.
25749 elsif Present (Spec_Outputs) then
25750 Item_Elmt := First_Elmt (Spec_Outputs);
25751 while Present (Item_Elmt) loop
25752 Item := Node (Item_Elmt);
25754 -- Deal with the mixed nature of the input and output lists
25756 if Nkind (Item) = N_Defining_Identifier then
25757 Item_Id := Item;
25758 else
25759 Item_Id := Available_View (Entity_Of (Item));
25760 end if;
25762 if Ekind (Item_Id) = E_Abstract_State then
25764 -- The state acts as an input-output, skip it
25766 if Present (Spec_Inputs)
25767 and then Appears_In (Spec_Inputs, Item_Id)
25768 then
25769 null;
25771 -- Ensure that all of the constituents are utilized as
25772 -- outputs in pragma Refined_Depends.
25774 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
25775 Check_Constituent_Usage (Item_Id);
25776 end if;
25777 end if;
25779 Next_Elmt (Item_Elmt);
25780 end loop;
25781 end if;
25782 end Check_Output_States;
25784 --------------------
25785 -- Collect_States --
25786 --------------------
25788 function Collect_States (Clauses : List_Id) return Elist_Id is
25789 procedure Collect_State
25790 (Item : Node_Id;
25791 States : in out Elist_Id);
25792 -- Add the entity of Item to list States when it denotes to a state
25794 -------------------
25795 -- Collect_State --
25796 -------------------
25798 procedure Collect_State
25799 (Item : Node_Id;
25800 States : in out Elist_Id)
25802 Id : Entity_Id;
25804 begin
25805 if Is_Entity_Name (Item) then
25806 Id := Entity_Of (Item);
25808 if Ekind (Id) = E_Abstract_State then
25809 if No (States) then
25810 States := New_Elmt_List;
25811 end if;
25813 Append_Unique_Elmt (Id, States);
25814 end if;
25815 end if;
25816 end Collect_State;
25818 -- Local variables
25820 Clause : Node_Id;
25821 Input : Node_Id;
25822 Output : Node_Id;
25823 States : Elist_Id := No_Elist;
25825 -- Start of processing for Collect_States
25827 begin
25828 Clause := First (Clauses);
25829 while Present (Clause) loop
25830 Input := Expression (Clause);
25831 Output := First (Choices (Clause));
25833 Collect_State (Input, States);
25834 Collect_State (Output, States);
25836 Next (Clause);
25837 end loop;
25839 return States;
25840 end Collect_States;
25842 -----------------------
25843 -- Normalize_Clauses --
25844 -----------------------
25846 procedure Normalize_Clauses (Clauses : List_Id) is
25847 procedure Normalize_Inputs (Clause : Node_Id);
25848 -- Normalize clause Clause by creating multiple clauses for each
25849 -- input item of Clause. It is assumed that Clause has exactly one
25850 -- output. The transformation is as follows:
25852 -- Output => (Input_1, Input_2) -- original
25854 -- Output => Input_1 -- normalizations
25855 -- Output => Input_2
25857 procedure Normalize_Outputs (Clause : Node_Id);
25858 -- Normalize clause Clause by creating multiple clause for each
25859 -- output item of Clause. The transformation is as follows:
25861 -- (Output_1, Output_2) => Input -- original
25863 -- Output_1 => Input -- normalization
25864 -- Output_2 => Input
25866 ----------------------
25867 -- Normalize_Inputs --
25868 ----------------------
25870 procedure Normalize_Inputs (Clause : Node_Id) is
25871 Inputs : constant Node_Id := Expression (Clause);
25872 Loc : constant Source_Ptr := Sloc (Clause);
25873 Output : constant List_Id := Choices (Clause);
25874 Last_Input : Node_Id;
25875 Input : Node_Id;
25876 New_Clause : Node_Id;
25877 Next_Input : Node_Id;
25879 begin
25880 -- Normalization is performed only when the original clause has
25881 -- more than one input. Multiple inputs appear as an aggregate.
25883 if Nkind (Inputs) = N_Aggregate then
25884 Last_Input := Last (Expressions (Inputs));
25886 -- Create a new clause for each input
25888 Input := First (Expressions (Inputs));
25889 while Present (Input) loop
25890 Next_Input := Next (Input);
25892 -- Unhook the current input from the original input list
25893 -- because it will be relocated to a new clause.
25895 Remove (Input);
25897 -- Special processing for the last input. At this point the
25898 -- original aggregate has been stripped down to one element.
25899 -- Replace the aggregate by the element itself.
25901 if Input = Last_Input then
25902 Rewrite (Inputs, Input);
25904 -- Generate a clause of the form:
25905 -- Output => Input
25907 else
25908 New_Clause :=
25909 Make_Component_Association (Loc,
25910 Choices => New_Copy_List_Tree (Output),
25911 Expression => Input);
25913 -- The new clause contains replicated content that has
25914 -- already been analyzed, mark the clause as analyzed.
25916 Set_Analyzed (New_Clause);
25917 Insert_After (Clause, New_Clause);
25918 end if;
25920 Input := Next_Input;
25921 end loop;
25922 end if;
25923 end Normalize_Inputs;
25925 -----------------------
25926 -- Normalize_Outputs --
25927 -----------------------
25929 procedure Normalize_Outputs (Clause : Node_Id) is
25930 Inputs : constant Node_Id := Expression (Clause);
25931 Loc : constant Source_Ptr := Sloc (Clause);
25932 Outputs : constant Node_Id := First (Choices (Clause));
25933 Last_Output : Node_Id;
25934 New_Clause : Node_Id;
25935 Next_Output : Node_Id;
25936 Output : Node_Id;
25938 begin
25939 -- Multiple outputs appear as an aggregate. Nothing to do when
25940 -- the clause has exactly one output.
25942 if Nkind (Outputs) = N_Aggregate then
25943 Last_Output := Last (Expressions (Outputs));
25945 -- Create a clause for each output. Note that each time a new
25946 -- clause is created, the original output list slowly shrinks
25947 -- until there is one item left.
25949 Output := First (Expressions (Outputs));
25950 while Present (Output) loop
25951 Next_Output := Next (Output);
25953 -- Unhook the output from the original output list as it
25954 -- will be relocated to a new clause.
25956 Remove (Output);
25958 -- Special processing for the last output. At this point
25959 -- the original aggregate has been stripped down to one
25960 -- element. Replace the aggregate by the element itself.
25962 if Output = Last_Output then
25963 Rewrite (Outputs, Output);
25965 else
25966 -- Generate a clause of the form:
25967 -- (Output => Inputs)
25969 New_Clause :=
25970 Make_Component_Association (Loc,
25971 Choices => New_List (Output),
25972 Expression => New_Copy_Tree (Inputs));
25974 -- The new clause contains replicated content that has
25975 -- already been analyzed. There is not need to reanalyze
25976 -- them.
25978 Set_Analyzed (New_Clause);
25979 Insert_After (Clause, New_Clause);
25980 end if;
25982 Output := Next_Output;
25983 end loop;
25984 end if;
25985 end Normalize_Outputs;
25987 -- Local variables
25989 Clause : Node_Id;
25991 -- Start of processing for Normalize_Clauses
25993 begin
25994 Clause := First (Clauses);
25995 while Present (Clause) loop
25996 Normalize_Outputs (Clause);
25997 Next (Clause);
25998 end loop;
26000 Clause := First (Clauses);
26001 while Present (Clause) loop
26002 Normalize_Inputs (Clause);
26003 Next (Clause);
26004 end loop;
26005 end Normalize_Clauses;
26007 --------------------------
26008 -- Remove_Extra_Clauses --
26009 --------------------------
26011 procedure Remove_Extra_Clauses
26012 (Clauses : List_Id;
26013 Matched_Items : Elist_Id)
26015 Clause : Node_Id;
26016 Input : Node_Id;
26017 Input_Id : Entity_Id;
26018 Next_Clause : Node_Id;
26019 Output : Node_Id;
26020 State_Id : Entity_Id;
26022 begin
26023 Clause := First (Clauses);
26024 while Present (Clause) loop
26025 Next_Clause := Next (Clause);
26027 Input := Expression (Clause);
26028 Output := First (Choices (Clause));
26030 -- Recognize a clause of the form
26032 -- null => Input
26034 -- where Input is a constituent of a state which was already
26035 -- successfully matched. This clause must be removed because it
26036 -- simply indicates that some of the constituents of the state
26037 -- are not used.
26039 -- Refined_State => (State => (Constit_1, Constit_2))
26040 -- Depends => (Output => State)
26041 -- Refined_Depends => ((Output => Constit_1), -- State matched
26042 -- (null => Constit_2)) -- OK
26044 if Nkind (Output) = N_Null and then Is_Entity_Name (Input) then
26046 -- Handle abstract views generated for limited with clauses
26048 Input_Id := Available_View (Entity_Of (Input));
26050 -- The input must be a constituent of a state
26052 if Ekind_In (Input_Id, E_Abstract_State,
26053 E_Constant,
26054 E_Variable)
26055 and then Present (Encapsulating_State (Input_Id))
26056 then
26057 State_Id := Encapsulating_State (Input_Id);
26059 -- The state must have a non-null visible refinement and be
26060 -- matched in a previous clause.
26062 if Has_Non_Null_Visible_Refinement (State_Id)
26063 and then Contains (Matched_Items, State_Id)
26064 then
26065 Remove (Clause);
26066 end if;
26067 end if;
26069 -- Recognize a clause of the form
26071 -- Output => null
26073 -- where Output is an arbitrary item. This clause must be removed
26074 -- because a null input legitimately matches anything.
26076 elsif Nkind (Input) = N_Null then
26077 Remove (Clause);
26078 end if;
26080 Clause := Next_Clause;
26081 end loop;
26082 end Remove_Extra_Clauses;
26084 --------------------------
26085 -- Report_Extra_Clauses --
26086 --------------------------
26088 procedure Report_Extra_Clauses
26089 (Spec_Id : Entity_Id;
26090 Clauses : List_Id)
26092 Clause : Node_Id;
26094 begin
26095 -- Do not perform this check in an instance because it was already
26096 -- performed successfully in the generic template.
26098 if Is_Generic_Instance (Spec_Id) then
26099 null;
26101 elsif Present (Clauses) then
26102 Clause := First (Clauses);
26103 while Present (Clause) loop
26104 SPARK_Msg_N
26105 ("unmatched or extra clause in dependence refinement",
26106 Clause);
26108 Next (Clause);
26109 end loop;
26110 end if;
26111 end Report_Extra_Clauses;
26113 -- Local variables
26115 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
26116 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
26117 Errors : constant Nat := Serious_Errors_Detected;
26119 Clause : Node_Id;
26120 Deps : Node_Id;
26121 Dummy : Boolean;
26122 Refs : Node_Id;
26124 Body_Inputs : Elist_Id := No_Elist;
26125 Body_Outputs : Elist_Id := No_Elist;
26126 -- The inputs and outputs of the subprogram body synthesized from pragma
26127 -- Refined_Depends.
26129 Dependencies : List_Id := No_List;
26130 Depends : Node_Id;
26131 -- The corresponding Depends pragma along with its clauses
26133 Matched_Items : Elist_Id := No_Elist;
26134 -- A list containing the entities of all successfully matched items
26135 -- found in pragma Depends.
26137 Refinements : List_Id := No_List;
26138 -- The clauses of pragma Refined_Depends
26140 Spec_Id : Entity_Id;
26141 -- The entity of the subprogram subject to pragma Refined_Depends
26143 Spec_Inputs : Elist_Id := No_Elist;
26144 Spec_Outputs : Elist_Id := No_Elist;
26145 -- The inputs and outputs of the subprogram spec synthesized from pragma
26146 -- Depends.
26148 States : Elist_Id := No_Elist;
26149 -- A list containing the entities of all states whose constituents
26150 -- appear in pragma Depends.
26152 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
26154 begin
26155 -- Do not analyze the pragma multiple times
26157 if Is_Analyzed_Pragma (N) then
26158 return;
26159 end if;
26161 Spec_Id := Unique_Defining_Entity (Body_Decl);
26163 -- Use the anonymous object as the proper spec when Refined_Depends
26164 -- applies to the body of a single task type. The object carries the
26165 -- proper Chars as well as all non-refined versions of pragmas.
26167 if Is_Single_Concurrent_Type (Spec_Id) then
26168 Spec_Id := Anonymous_Object (Spec_Id);
26169 end if;
26171 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
26173 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
26174 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
26176 if No (Depends) then
26177 SPARK_Msg_NE
26178 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
26179 & "& lacks aspect or pragma Depends"), N, Spec_Id);
26180 goto Leave;
26181 end if;
26183 Deps := Expression (Get_Argument (Depends, Spec_Id));
26185 -- A null dependency relation renders the refinement useless because it
26186 -- cannot possibly mention abstract states with visible refinement. Note
26187 -- that the inverse is not true as states may be refined to null
26188 -- (SPARK RM 7.2.5(2)).
26190 if Nkind (Deps) = N_Null then
26191 SPARK_Msg_NE
26192 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
26193 & "depend on abstract state with visible refinement"), N, Spec_Id);
26194 goto Leave;
26195 end if;
26197 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
26198 -- This ensures that the categorization of all refined dependency items
26199 -- is consistent with their role.
26201 Analyze_Depends_In_Decl_Part (N);
26203 -- Do not match dependencies against refinements if Refined_Depends is
26204 -- illegal to avoid emitting misleading error.
26206 if Serious_Errors_Detected = Errors then
26208 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
26209 -- the inputs and outputs of the subprogram spec and body to verify
26210 -- the use of states with visible refinement and their constituents.
26212 if No (Get_Pragma (Spec_Id, Pragma_Global))
26213 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
26214 then
26215 Collect_Subprogram_Inputs_Outputs
26216 (Subp_Id => Spec_Id,
26217 Synthesize => True,
26218 Subp_Inputs => Spec_Inputs,
26219 Subp_Outputs => Spec_Outputs,
26220 Global_Seen => Dummy);
26222 Collect_Subprogram_Inputs_Outputs
26223 (Subp_Id => Body_Id,
26224 Synthesize => True,
26225 Subp_Inputs => Body_Inputs,
26226 Subp_Outputs => Body_Outputs,
26227 Global_Seen => Dummy);
26229 -- For an output state with a visible refinement, ensure that all
26230 -- constituents appear as outputs in the dependency refinement.
26232 Check_Output_States
26233 (Spec_Id => Spec_Id,
26234 Spec_Inputs => Spec_Inputs,
26235 Spec_Outputs => Spec_Outputs,
26236 Body_Inputs => Body_Inputs,
26237 Body_Outputs => Body_Outputs);
26238 end if;
26240 -- Matching is disabled in ASIS because clauses are not normalized as
26241 -- this is a tree altering activity similar to expansion.
26243 if ASIS_Mode then
26244 goto Leave;
26245 end if;
26247 -- Multiple dependency clauses appear as component associations of an
26248 -- aggregate. Note that the clauses are copied because the algorithm
26249 -- modifies them and this should not be visible in Depends.
26251 pragma Assert (Nkind (Deps) = N_Aggregate);
26252 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
26253 Normalize_Clauses (Dependencies);
26255 -- Gather all states which appear in Depends
26257 States := Collect_States (Dependencies);
26259 Refs := Expression (Get_Argument (N, Spec_Id));
26261 if Nkind (Refs) = N_Null then
26262 Refinements := No_List;
26264 -- Multiple dependency clauses appear as component associations of an
26265 -- aggregate. Note that the clauses are copied because the algorithm
26266 -- modifies them and this should not be visible in Refined_Depends.
26268 else pragma Assert (Nkind (Refs) = N_Aggregate);
26269 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
26270 Normalize_Clauses (Refinements);
26271 end if;
26273 -- At this point the clauses of pragmas Depends and Refined_Depends
26274 -- have been normalized into simple dependencies between one output
26275 -- and one input. Examine all clauses of pragma Depends looking for
26276 -- matching clauses in pragma Refined_Depends.
26278 Clause := First (Dependencies);
26279 while Present (Clause) loop
26280 Check_Dependency_Clause
26281 (Spec_Id => Spec_Id,
26282 Dep_Clause => Clause,
26283 Dep_States => States,
26284 Refinements => Refinements,
26285 Matched_Items => Matched_Items);
26287 Next (Clause);
26288 end loop;
26290 -- Pragma Refined_Depends may contain multiple clarification clauses
26291 -- which indicate that certain constituents do not influence the data
26292 -- flow in any way. Such clauses must be removed as long as the state
26293 -- has been matched, otherwise they will be incorrectly flagged as
26294 -- unmatched.
26296 -- Refined_State => (State => (Constit_1, Constit_2))
26297 -- Depends => (Output => State)
26298 -- Refined_Depends => ((Output => Constit_1), -- State matched
26299 -- (null => Constit_2)) -- must be removed
26301 Remove_Extra_Clauses (Refinements, Matched_Items);
26303 if Serious_Errors_Detected = Errors then
26304 Report_Extra_Clauses (Spec_Id, Refinements);
26305 end if;
26306 end if;
26308 <<Leave>>
26309 Set_Is_Analyzed_Pragma (N);
26310 end Analyze_Refined_Depends_In_Decl_Part;
26312 -----------------------------------------
26313 -- Analyze_Refined_Global_In_Decl_Part --
26314 -----------------------------------------
26316 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
26317 Global : Node_Id;
26318 -- The corresponding Global pragma
26320 Has_In_State : Boolean := False;
26321 Has_In_Out_State : Boolean := False;
26322 Has_Out_State : Boolean := False;
26323 Has_Proof_In_State : Boolean := False;
26324 -- These flags are set when the corresponding Global pragma has a state
26325 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
26326 -- refinement.
26328 Has_Null_State : Boolean := False;
26329 -- This flag is set when the corresponding Global pragma has at least
26330 -- one state with a null refinement.
26332 In_Constits : Elist_Id := No_Elist;
26333 In_Out_Constits : Elist_Id := No_Elist;
26334 Out_Constits : Elist_Id := No_Elist;
26335 Proof_In_Constits : Elist_Id := No_Elist;
26336 -- These lists contain the entities of all Input, In_Out, Output and
26337 -- Proof_In constituents that appear in Refined_Global and participate
26338 -- in state refinement.
26340 In_Items : Elist_Id := No_Elist;
26341 In_Out_Items : Elist_Id := No_Elist;
26342 Out_Items : Elist_Id := No_Elist;
26343 Proof_In_Items : Elist_Id := No_Elist;
26344 -- These lists contain the entities of all Input, In_Out, Output and
26345 -- Proof_In items defined in the corresponding Global pragma.
26347 Repeat_Items : Elist_Id := No_Elist;
26348 -- A list of all global items without full visible refinement found
26349 -- in pragma Global. These states should be repeated in the global
26350 -- refinement (SPARK RM 7.2.4(3c)) unless they have a partial visible
26351 -- refinement, in which case they may be repeated (SPARK RM 7.2.4(3d)).
26353 Spec_Id : Entity_Id;
26354 -- The entity of the subprogram subject to pragma Refined_Global
26356 States : Elist_Id := No_Elist;
26357 -- A list of all states with full or partial visible refinement found in
26358 -- pragma Global.
26360 procedure Check_In_Out_States;
26361 -- Determine whether the corresponding Global pragma mentions In_Out
26362 -- states with visible refinement and if so, ensure that one of the
26363 -- following completions apply to the constituents of the state:
26364 -- 1) there is at least one constituent of mode In_Out
26365 -- 2) there is at least one Input and one Output constituent
26366 -- 3) not all constituents are present and one of them is of mode
26367 -- Output.
26368 -- This routine may remove elements from In_Constits, In_Out_Constits,
26369 -- Out_Constits and Proof_In_Constits.
26371 procedure Check_Input_States;
26372 -- Determine whether the corresponding Global pragma mentions Input
26373 -- states with visible refinement and if so, ensure that at least one of
26374 -- its constituents appears as an Input item in Refined_Global.
26375 -- This routine may remove elements from In_Constits, In_Out_Constits,
26376 -- Out_Constits and Proof_In_Constits.
26378 procedure Check_Output_States;
26379 -- Determine whether the corresponding Global pragma mentions Output
26380 -- states with visible refinement and if so, ensure that all of its
26381 -- constituents appear as Output items in Refined_Global.
26382 -- This routine may remove elements from In_Constits, In_Out_Constits,
26383 -- Out_Constits and Proof_In_Constits.
26385 procedure Check_Proof_In_States;
26386 -- Determine whether the corresponding Global pragma mentions Proof_In
26387 -- states with visible refinement and if so, ensure that at least one of
26388 -- its constituents appears as a Proof_In item in Refined_Global.
26389 -- This routine may remove elements from In_Constits, In_Out_Constits,
26390 -- Out_Constits and Proof_In_Constits.
26392 procedure Check_Refined_Global_List
26393 (List : Node_Id;
26394 Global_Mode : Name_Id := Name_Input);
26395 -- Verify the legality of a single global list declaration. Global_Mode
26396 -- denotes the current mode in effect.
26398 procedure Collect_Global_Items
26399 (List : Node_Id;
26400 Mode : Name_Id := Name_Input);
26401 -- Gather all Input, In_Out, Output and Proof_In items from node List
26402 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
26403 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
26404 -- and Has_Proof_In_State are set when there is at least one abstract
26405 -- state with full or partial visible refinement available in the
26406 -- corresponding mode. Flag Has_Null_State is set when at least state
26407 -- has a null refinement. Mode denotes the current global mode in
26408 -- effect.
26410 function Present_Then_Remove
26411 (List : Elist_Id;
26412 Item : Entity_Id) return Boolean;
26413 -- Search List for a particular entity Item. If Item has been found,
26414 -- remove it from List. This routine is used to strip lists In_Constits,
26415 -- In_Out_Constits and Out_Constits of valid constituents.
26417 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id);
26418 -- Same as function Present_Then_Remove, but do not report the presence
26419 -- of Item in List.
26421 procedure Report_Extra_Constituents;
26422 -- Emit an error for each constituent found in lists In_Constits,
26423 -- In_Out_Constits and Out_Constits.
26425 procedure Report_Missing_Items;
26426 -- Emit an error for each global item not repeated found in list
26427 -- Repeat_Items.
26429 -------------------------
26430 -- Check_In_Out_States --
26431 -------------------------
26433 procedure Check_In_Out_States is
26434 procedure Check_Constituent_Usage (State_Id : Entity_Id);
26435 -- Determine whether one of the following coverage scenarios is in
26436 -- effect:
26437 -- 1) there is at least one constituent of mode In_Out or Output
26438 -- 2) there is at least one pair of constituents with modes Input
26439 -- and Output, or Proof_In and Output.
26440 -- 3) there is at least one constituent of mode Output and not all
26441 -- constituents are present.
26442 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
26444 -----------------------------
26445 -- Check_Constituent_Usage --
26446 -----------------------------
26448 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
26449 Constits : constant Elist_Id :=
26450 Partial_Refinement_Constituents (State_Id);
26451 Constit_Elmt : Elmt_Id;
26452 Constit_Id : Entity_Id;
26453 Has_Missing : Boolean := False;
26454 In_Out_Seen : Boolean := False;
26455 Input_Seen : Boolean := False;
26456 Output_Seen : Boolean := False;
26457 Proof_In_Seen : Boolean := False;
26459 begin
26460 -- Process all the constituents of the state and note their modes
26461 -- within the global refinement.
26463 if Present (Constits) then
26464 Constit_Elmt := First_Elmt (Constits);
26465 while Present (Constit_Elmt) loop
26466 Constit_Id := Node (Constit_Elmt);
26468 if Present_Then_Remove (In_Constits, Constit_Id) then
26469 Input_Seen := True;
26471 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
26472 In_Out_Seen := True;
26474 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
26475 Output_Seen := True;
26477 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
26478 then
26479 Proof_In_Seen := True;
26481 else
26482 Has_Missing := True;
26483 end if;
26485 Next_Elmt (Constit_Elmt);
26486 end loop;
26487 end if;
26489 -- An In_Out constituent is a valid completion
26491 if In_Out_Seen then
26492 null;
26494 -- A pair of one Input/Proof_In and one Output constituent is a
26495 -- valid completion.
26497 elsif (Input_Seen or Proof_In_Seen) and Output_Seen then
26498 null;
26500 elsif Output_Seen then
26502 -- A single Output constituent is a valid completion only when
26503 -- some of the other constituents are missing.
26505 if Has_Missing then
26506 null;
26508 -- Otherwise all constituents are of mode Output
26510 else
26511 SPARK_Msg_NE
26512 ("global refinement of state & must include at least one "
26513 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
26514 N, State_Id);
26515 end if;
26517 -- The state lacks a completion. When full refinement is visible,
26518 -- always emit an error (SPARK RM 7.2.4(3a)). When only partial
26519 -- refinement is visible, emit an error if the abstract state
26520 -- itself is not utilized (SPARK RM 7.2.4(3d)). In the case where
26521 -- both are utilized, Check_State_And_Constituent_Use. will issue
26522 -- the error.
26524 elsif not Input_Seen
26525 and then not In_Out_Seen
26526 and then not Output_Seen
26527 and then not Proof_In_Seen
26528 then
26529 if Has_Visible_Refinement (State_Id)
26530 or else Contains (Repeat_Items, State_Id)
26531 then
26532 SPARK_Msg_NE
26533 ("missing global refinement of state &", N, State_Id);
26534 end if;
26536 -- Otherwise the state has a malformed completion where at least
26537 -- one of the constituents has a different mode.
26539 else
26540 SPARK_Msg_NE
26541 ("global refinement of state & redefines the mode of its "
26542 & "constituents", N, State_Id);
26543 end if;
26544 end Check_Constituent_Usage;
26546 -- Local variables
26548 Item_Elmt : Elmt_Id;
26549 Item_Id : Entity_Id;
26551 -- Start of processing for Check_In_Out_States
26553 begin
26554 -- Do not perform this check in an instance because it was already
26555 -- performed successfully in the generic template.
26557 if Is_Generic_Instance (Spec_Id) then
26558 null;
26560 -- Inspect the In_Out items of the corresponding Global pragma
26561 -- looking for a state with a visible refinement.
26563 elsif Has_In_Out_State and then Present (In_Out_Items) then
26564 Item_Elmt := First_Elmt (In_Out_Items);
26565 while Present (Item_Elmt) loop
26566 Item_Id := Node (Item_Elmt);
26568 -- Ensure that one of the three coverage variants is satisfied
26570 if Ekind (Item_Id) = E_Abstract_State
26571 and then Has_Non_Null_Visible_Refinement (Item_Id)
26572 then
26573 Check_Constituent_Usage (Item_Id);
26574 end if;
26576 Next_Elmt (Item_Elmt);
26577 end loop;
26578 end if;
26579 end Check_In_Out_States;
26581 ------------------------
26582 -- Check_Input_States --
26583 ------------------------
26585 procedure Check_Input_States is
26586 procedure Check_Constituent_Usage (State_Id : Entity_Id);
26587 -- Determine whether at least one constituent of state State_Id with
26588 -- full or partial visible refinement is used and has mode Input.
26589 -- Ensure that the remaining constituents do not have In_Out or
26590 -- Output modes. Emit an error if this is not the case
26591 -- (SPARK RM 7.2.4(5)).
26593 -----------------------------
26594 -- Check_Constituent_Usage --
26595 -----------------------------
26597 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
26598 Constits : constant Elist_Id :=
26599 Partial_Refinement_Constituents (State_Id);
26600 Constit_Elmt : Elmt_Id;
26601 Constit_Id : Entity_Id;
26602 In_Seen : Boolean := False;
26604 begin
26605 if Present (Constits) then
26606 Constit_Elmt := First_Elmt (Constits);
26607 while Present (Constit_Elmt) loop
26608 Constit_Id := Node (Constit_Elmt);
26610 -- At least one of the constituents appears as an Input
26612 if Present_Then_Remove (In_Constits, Constit_Id) then
26613 In_Seen := True;
26615 -- A Proof_In constituent can refine an Input state as long
26616 -- as there is at least one Input constituent present.
26618 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
26619 then
26620 null;
26622 -- The constituent appears in the global refinement, but has
26623 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
26625 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
26626 or else Present_Then_Remove (Out_Constits, Constit_Id)
26627 then
26628 Error_Msg_Name_1 := Chars (State_Id);
26629 SPARK_Msg_NE
26630 ("constituent & of state % must have mode `Input` in "
26631 & "global refinement", N, Constit_Id);
26632 end if;
26634 Next_Elmt (Constit_Elmt);
26635 end loop;
26636 end if;
26638 -- Not one of the constituents appeared as Input. Always emit an
26639 -- error when the full refinement is visible (SPARK RM 7.2.4(3a)).
26640 -- When only partial refinement is visible, emit an error if the
26641 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
26642 -- the case where both are utilized, an error will be issued in
26643 -- Check_State_And_Constituent_Use.
26645 if not In_Seen
26646 and then (Has_Visible_Refinement (State_Id)
26647 or else Contains (Repeat_Items, State_Id))
26648 then
26649 SPARK_Msg_NE
26650 ("global refinement of state & must include at least one "
26651 & "constituent of mode `Input`", N, State_Id);
26652 end if;
26653 end Check_Constituent_Usage;
26655 -- Local variables
26657 Item_Elmt : Elmt_Id;
26658 Item_Id : Entity_Id;
26660 -- Start of processing for Check_Input_States
26662 begin
26663 -- Do not perform this check in an instance because it was already
26664 -- performed successfully in the generic template.
26666 if Is_Generic_Instance (Spec_Id) then
26667 null;
26669 -- Inspect the Input items of the corresponding Global pragma looking
26670 -- for a state with a visible refinement.
26672 elsif Has_In_State and then Present (In_Items) then
26673 Item_Elmt := First_Elmt (In_Items);
26674 while Present (Item_Elmt) loop
26675 Item_Id := Node (Item_Elmt);
26677 -- When full refinement is visible, ensure that at least one of
26678 -- the constituents is utilized and is of mode Input. When only
26679 -- partial refinement is visible, ensure that either one of
26680 -- the constituents is utilized and is of mode Input, or the
26681 -- abstract state is repeated and no constituent is utilized.
26683 if Ekind (Item_Id) = E_Abstract_State
26684 and then Has_Non_Null_Visible_Refinement (Item_Id)
26685 then
26686 Check_Constituent_Usage (Item_Id);
26687 end if;
26689 Next_Elmt (Item_Elmt);
26690 end loop;
26691 end if;
26692 end Check_Input_States;
26694 -------------------------
26695 -- Check_Output_States --
26696 -------------------------
26698 procedure Check_Output_States is
26699 procedure Check_Constituent_Usage (State_Id : Entity_Id);
26700 -- Determine whether all constituents of state State_Id with full
26701 -- visible refinement are used and have mode Output. Emit an error
26702 -- if this is not the case (SPARK RM 7.2.4(5)).
26704 -----------------------------
26705 -- Check_Constituent_Usage --
26706 -----------------------------
26708 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
26709 Constits : constant Elist_Id :=
26710 Partial_Refinement_Constituents (State_Id);
26711 Only_Partial : constant Boolean :=
26712 not Has_Visible_Refinement (State_Id);
26713 Constit_Elmt : Elmt_Id;
26714 Constit_Id : Entity_Id;
26715 Posted : Boolean := False;
26717 begin
26718 if Present (Constits) then
26719 Constit_Elmt := First_Elmt (Constits);
26720 while Present (Constit_Elmt) loop
26721 Constit_Id := Node (Constit_Elmt);
26723 -- Issue an error when a constituent of State_Id is utilized
26724 -- and State_Id has only partial visible refinement
26725 -- (SPARK RM 7.2.4(3d)).
26727 if Only_Partial then
26728 if Present_Then_Remove (Out_Constits, Constit_Id)
26729 or else Present_Then_Remove (In_Constits, Constit_Id)
26730 or else
26731 Present_Then_Remove (In_Out_Constits, Constit_Id)
26732 or else
26733 Present_Then_Remove (Proof_In_Constits, Constit_Id)
26734 then
26735 Error_Msg_Name_1 := Chars (State_Id);
26736 SPARK_Msg_NE
26737 ("constituent & of state % cannot be used in global "
26738 & "refinement", N, Constit_Id);
26739 Error_Msg_Name_1 := Chars (State_Id);
26740 SPARK_Msg_N ("\use state % instead", N);
26741 end if;
26743 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
26744 null;
26746 -- The constituent appears in the global refinement, but has
26747 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
26749 elsif Present_Then_Remove (In_Constits, Constit_Id)
26750 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
26751 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
26752 then
26753 Error_Msg_Name_1 := Chars (State_Id);
26754 SPARK_Msg_NE
26755 ("constituent & of state % must have mode `Output` in "
26756 & "global refinement", N, Constit_Id);
26758 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
26760 else
26761 if not Posted then
26762 Posted := True;
26763 SPARK_Msg_NE
26764 ("`Output` state & must be replaced by all its "
26765 & "constituents in global refinement", N, State_Id);
26766 end if;
26768 SPARK_Msg_NE
26769 ("\constituent & is missing in output list",
26770 N, Constit_Id);
26771 end if;
26773 Next_Elmt (Constit_Elmt);
26774 end loop;
26775 end if;
26776 end Check_Constituent_Usage;
26778 -- Local variables
26780 Item_Elmt : Elmt_Id;
26781 Item_Id : Entity_Id;
26783 -- Start of processing for Check_Output_States
26785 begin
26786 -- Do not perform this check in an instance because it was already
26787 -- performed successfully in the generic template.
26789 if Is_Generic_Instance (Spec_Id) then
26790 null;
26792 -- Inspect the Output items of the corresponding Global pragma
26793 -- looking for a state with a visible refinement.
26795 elsif Has_Out_State and then Present (Out_Items) then
26796 Item_Elmt := First_Elmt (Out_Items);
26797 while Present (Item_Elmt) loop
26798 Item_Id := Node (Item_Elmt);
26800 -- When full refinement is visible, ensure that all of the
26801 -- constituents are utilized and they have mode Output. When
26802 -- only partial refinement is visible, ensure that no
26803 -- constituent is utilized.
26805 if Ekind (Item_Id) = E_Abstract_State
26806 and then Has_Non_Null_Visible_Refinement (Item_Id)
26807 then
26808 Check_Constituent_Usage (Item_Id);
26809 end if;
26811 Next_Elmt (Item_Elmt);
26812 end loop;
26813 end if;
26814 end Check_Output_States;
26816 ---------------------------
26817 -- Check_Proof_In_States --
26818 ---------------------------
26820 procedure Check_Proof_In_States is
26821 procedure Check_Constituent_Usage (State_Id : Entity_Id);
26822 -- Determine whether at least one constituent of state State_Id with
26823 -- full or partial visible refinement is used and has mode Proof_In.
26824 -- Ensure that the remaining constituents do not have Input, In_Out,
26825 -- or Output modes. Emit an error if this is not the case
26826 -- (SPARK RM 7.2.4(5)).
26828 -----------------------------
26829 -- Check_Constituent_Usage --
26830 -----------------------------
26832 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
26833 Constits : constant Elist_Id :=
26834 Partial_Refinement_Constituents (State_Id);
26835 Constit_Elmt : Elmt_Id;
26836 Constit_Id : Entity_Id;
26837 Proof_In_Seen : Boolean := False;
26839 begin
26840 if Present (Constits) then
26841 Constit_Elmt := First_Elmt (Constits);
26842 while Present (Constit_Elmt) loop
26843 Constit_Id := Node (Constit_Elmt);
26845 -- At least one of the constituents appears as Proof_In
26847 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
26848 Proof_In_Seen := True;
26850 -- The constituent appears in the global refinement, but has
26851 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
26853 elsif Present_Then_Remove (In_Constits, Constit_Id)
26854 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
26855 or else Present_Then_Remove (Out_Constits, Constit_Id)
26856 then
26857 Error_Msg_Name_1 := Chars (State_Id);
26858 SPARK_Msg_NE
26859 ("constituent & of state % must have mode `Proof_In` "
26860 & "in global refinement", N, Constit_Id);
26861 end if;
26863 Next_Elmt (Constit_Elmt);
26864 end loop;
26865 end if;
26867 -- Not one of the constituents appeared as Proof_In. Always emit
26868 -- an error when full refinement is visible (SPARK RM 7.2.4(3a)).
26869 -- When only partial refinement is visible, emit an error if the
26870 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
26871 -- the case where both are utilized, an error will be issued by
26872 -- Check_State_And_Constituent_Use.
26874 if not Proof_In_Seen
26875 and then (Has_Visible_Refinement (State_Id)
26876 or else Contains (Repeat_Items, State_Id))
26877 then
26878 SPARK_Msg_NE
26879 ("global refinement of state & must include at least one "
26880 & "constituent of mode `Proof_In`", N, State_Id);
26881 end if;
26882 end Check_Constituent_Usage;
26884 -- Local variables
26886 Item_Elmt : Elmt_Id;
26887 Item_Id : Entity_Id;
26889 -- Start of processing for Check_Proof_In_States
26891 begin
26892 -- Do not perform this check in an instance because it was already
26893 -- performed successfully in the generic template.
26895 if Is_Generic_Instance (Spec_Id) then
26896 null;
26898 -- Inspect the Proof_In items of the corresponding Global pragma
26899 -- looking for a state with a visible refinement.
26901 elsif Has_Proof_In_State and then Present (Proof_In_Items) then
26902 Item_Elmt := First_Elmt (Proof_In_Items);
26903 while Present (Item_Elmt) loop
26904 Item_Id := Node (Item_Elmt);
26906 -- Ensure that at least one of the constituents is utilized
26907 -- and is of mode Proof_In. When only partial refinement is
26908 -- visible, ensure that either one of the constituents is
26909 -- utilized and is of mode Proof_In, or the abstract state
26910 -- is repeated and no constituent is utilized.
26912 if Ekind (Item_Id) = E_Abstract_State
26913 and then Has_Non_Null_Visible_Refinement (Item_Id)
26914 then
26915 Check_Constituent_Usage (Item_Id);
26916 end if;
26918 Next_Elmt (Item_Elmt);
26919 end loop;
26920 end if;
26921 end Check_Proof_In_States;
26923 -------------------------------
26924 -- Check_Refined_Global_List --
26925 -------------------------------
26927 procedure Check_Refined_Global_List
26928 (List : Node_Id;
26929 Global_Mode : Name_Id := Name_Input)
26931 procedure Check_Refined_Global_Item
26932 (Item : Node_Id;
26933 Global_Mode : Name_Id);
26934 -- Verify the legality of a single global item declaration. Parameter
26935 -- Global_Mode denotes the current mode in effect.
26937 -------------------------------
26938 -- Check_Refined_Global_Item --
26939 -------------------------------
26941 procedure Check_Refined_Global_Item
26942 (Item : Node_Id;
26943 Global_Mode : Name_Id)
26945 Item_Id : constant Entity_Id := Entity_Of (Item);
26947 procedure Inconsistent_Mode_Error (Expect : Name_Id);
26948 -- Issue a common error message for all mode mismatches. Expect
26949 -- denotes the expected mode.
26951 -----------------------------
26952 -- Inconsistent_Mode_Error --
26953 -----------------------------
26955 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
26956 begin
26957 SPARK_Msg_NE
26958 ("global item & has inconsistent modes", Item, Item_Id);
26960 Error_Msg_Name_1 := Global_Mode;
26961 Error_Msg_Name_2 := Expect;
26962 SPARK_Msg_N ("\expected mode %, found mode %", Item);
26963 end Inconsistent_Mode_Error;
26965 -- Local variables
26967 Enc_State : Entity_Id := Empty;
26968 -- Encapsulating state for constituent, Empty otherwise
26970 -- Start of processing for Check_Refined_Global_Item
26972 begin
26973 if Ekind_In (Item_Id, E_Abstract_State,
26974 E_Constant,
26975 E_Variable)
26976 then
26977 Enc_State := Find_Encapsulating_State (States, Item_Id);
26978 end if;
26980 -- When the state or object acts as a constituent of another
26981 -- state with a visible refinement, collect it for the state
26982 -- completeness checks performed later on. Note that the item
26983 -- acts as a constituent only when the encapsulating state is
26984 -- present in pragma Global.
26986 if Present (Enc_State)
26987 and then (Has_Visible_Refinement (Enc_State)
26988 or else Has_Partial_Visible_Refinement (Enc_State))
26989 and then Contains (States, Enc_State)
26990 then
26991 -- If the state has only partial visible refinement, remove it
26992 -- from the list of items that should be repeated from pragma
26993 -- Global.
26995 if not Has_Visible_Refinement (Enc_State) then
26996 Present_Then_Remove (Repeat_Items, Enc_State);
26997 end if;
26999 if Global_Mode = Name_Input then
27000 Append_New_Elmt (Item_Id, In_Constits);
27002 elsif Global_Mode = Name_In_Out then
27003 Append_New_Elmt (Item_Id, In_Out_Constits);
27005 elsif Global_Mode = Name_Output then
27006 Append_New_Elmt (Item_Id, Out_Constits);
27008 elsif Global_Mode = Name_Proof_In then
27009 Append_New_Elmt (Item_Id, Proof_In_Constits);
27010 end if;
27012 -- When not a constituent, ensure that both occurrences of the
27013 -- item in pragmas Global and Refined_Global match. Also remove
27014 -- it when present from the list of items that should be repeated
27015 -- from pragma Global.
27017 else
27018 Present_Then_Remove (Repeat_Items, Item_Id);
27020 if Contains (In_Items, Item_Id) then
27021 if Global_Mode /= Name_Input then
27022 Inconsistent_Mode_Error (Name_Input);
27023 end if;
27025 elsif Contains (In_Out_Items, Item_Id) then
27026 if Global_Mode /= Name_In_Out then
27027 Inconsistent_Mode_Error (Name_In_Out);
27028 end if;
27030 elsif Contains (Out_Items, Item_Id) then
27031 if Global_Mode /= Name_Output then
27032 Inconsistent_Mode_Error (Name_Output);
27033 end if;
27035 elsif Contains (Proof_In_Items, Item_Id) then
27036 null;
27038 -- The item does not appear in the corresponding Global pragma,
27039 -- it must be an extra (SPARK RM 7.2.4(3)).
27041 else
27042 SPARK_Msg_NE ("extra global item &", Item, Item_Id);
27043 end if;
27044 end if;
27045 end Check_Refined_Global_Item;
27047 -- Local variables
27049 Item : Node_Id;
27051 -- Start of processing for Check_Refined_Global_List
27053 begin
27054 -- Do not perform this check in an instance because it was already
27055 -- performed successfully in the generic template.
27057 if Is_Generic_Instance (Spec_Id) then
27058 null;
27060 elsif Nkind (List) = N_Null then
27061 null;
27063 -- Single global item declaration
27065 elsif Nkind_In (List, N_Expanded_Name,
27066 N_Identifier,
27067 N_Selected_Component)
27068 then
27069 Check_Refined_Global_Item (List, Global_Mode);
27071 -- Simple global list or moded global list declaration
27073 elsif Nkind (List) = N_Aggregate then
27075 -- The declaration of a simple global list appear as a collection
27076 -- of expressions.
27078 if Present (Expressions (List)) then
27079 Item := First (Expressions (List));
27080 while Present (Item) loop
27081 Check_Refined_Global_Item (Item, Global_Mode);
27082 Next (Item);
27083 end loop;
27085 -- The declaration of a moded global list appears as a collection
27086 -- of component associations where individual choices denote
27087 -- modes.
27089 elsif Present (Component_Associations (List)) then
27090 Item := First (Component_Associations (List));
27091 while Present (Item) loop
27092 Check_Refined_Global_List
27093 (List => Expression (Item),
27094 Global_Mode => Chars (First (Choices (Item))));
27096 Next (Item);
27097 end loop;
27099 -- Invalid tree
27101 else
27102 raise Program_Error;
27103 end if;
27105 -- Invalid list
27107 else
27108 raise Program_Error;
27109 end if;
27110 end Check_Refined_Global_List;
27112 --------------------------
27113 -- Collect_Global_Items --
27114 --------------------------
27116 procedure Collect_Global_Items
27117 (List : Node_Id;
27118 Mode : Name_Id := Name_Input)
27120 procedure Collect_Global_Item
27121 (Item : Node_Id;
27122 Item_Mode : Name_Id);
27123 -- Add a single item to the appropriate list. Item_Mode denotes the
27124 -- current mode in effect.
27126 -------------------------
27127 -- Collect_Global_Item --
27128 -------------------------
27130 procedure Collect_Global_Item
27131 (Item : Node_Id;
27132 Item_Mode : Name_Id)
27134 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
27135 -- The above handles abstract views of variables and states built
27136 -- for limited with clauses.
27138 begin
27139 -- Signal that the global list contains at least one abstract
27140 -- state with a visible refinement. Note that the refinement may
27141 -- be null in which case there are no constituents.
27143 if Ekind (Item_Id) = E_Abstract_State then
27144 if Has_Null_Visible_Refinement (Item_Id) then
27145 Has_Null_State := True;
27147 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
27148 Append_New_Elmt (Item_Id, States);
27150 if Item_Mode = Name_Input then
27151 Has_In_State := True;
27152 elsif Item_Mode = Name_In_Out then
27153 Has_In_Out_State := True;
27154 elsif Item_Mode = Name_Output then
27155 Has_Out_State := True;
27156 elsif Item_Mode = Name_Proof_In then
27157 Has_Proof_In_State := True;
27158 end if;
27159 end if;
27160 end if;
27162 -- Record global items without full visible refinement found in
27163 -- pragma Global which should be repeated in the global refinement
27164 -- (SPARK RM 7.2.4(3c), SPARK RM 7.2.4(3d)).
27166 if Ekind (Item_Id) /= E_Abstract_State
27167 or else not Has_Visible_Refinement (Item_Id)
27168 then
27169 Append_New_Elmt (Item_Id, Repeat_Items);
27170 end if;
27172 -- Add the item to the proper list
27174 if Item_Mode = Name_Input then
27175 Append_New_Elmt (Item_Id, In_Items);
27176 elsif Item_Mode = Name_In_Out then
27177 Append_New_Elmt (Item_Id, In_Out_Items);
27178 elsif Item_Mode = Name_Output then
27179 Append_New_Elmt (Item_Id, Out_Items);
27180 elsif Item_Mode = Name_Proof_In then
27181 Append_New_Elmt (Item_Id, Proof_In_Items);
27182 end if;
27183 end Collect_Global_Item;
27185 -- Local variables
27187 Item : Node_Id;
27189 -- Start of processing for Collect_Global_Items
27191 begin
27192 if Nkind (List) = N_Null then
27193 null;
27195 -- Single global item declaration
27197 elsif Nkind_In (List, N_Expanded_Name,
27198 N_Identifier,
27199 N_Selected_Component)
27200 then
27201 Collect_Global_Item (List, Mode);
27203 -- Single global list or moded global list declaration
27205 elsif Nkind (List) = N_Aggregate then
27207 -- The declaration of a simple global list appear as a collection
27208 -- of expressions.
27210 if Present (Expressions (List)) then
27211 Item := First (Expressions (List));
27212 while Present (Item) loop
27213 Collect_Global_Item (Item, Mode);
27214 Next (Item);
27215 end loop;
27217 -- The declaration of a moded global list appears as a collection
27218 -- of component associations where individual choices denote mode.
27220 elsif Present (Component_Associations (List)) then
27221 Item := First (Component_Associations (List));
27222 while Present (Item) loop
27223 Collect_Global_Items
27224 (List => Expression (Item),
27225 Mode => Chars (First (Choices (Item))));
27227 Next (Item);
27228 end loop;
27230 -- Invalid tree
27232 else
27233 raise Program_Error;
27234 end if;
27236 -- To accommodate partial decoration of disabled SPARK features, this
27237 -- routine may be called with illegal input. If this is the case, do
27238 -- not raise Program_Error.
27240 else
27241 null;
27242 end if;
27243 end Collect_Global_Items;
27245 -------------------------
27246 -- Present_Then_Remove --
27247 -------------------------
27249 function Present_Then_Remove
27250 (List : Elist_Id;
27251 Item : Entity_Id) return Boolean
27253 Elmt : Elmt_Id;
27255 begin
27256 if Present (List) then
27257 Elmt := First_Elmt (List);
27258 while Present (Elmt) loop
27259 if Node (Elmt) = Item then
27260 Remove_Elmt (List, Elmt);
27261 return True;
27262 end if;
27264 Next_Elmt (Elmt);
27265 end loop;
27266 end if;
27268 return False;
27269 end Present_Then_Remove;
27271 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id) is
27272 Ignore : Boolean;
27273 begin
27274 Ignore := Present_Then_Remove (List, Item);
27275 end Present_Then_Remove;
27277 -------------------------------
27278 -- Report_Extra_Constituents --
27279 -------------------------------
27281 procedure Report_Extra_Constituents is
27282 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
27283 -- Emit an error for every element of List
27285 ---------------------------------------
27286 -- Report_Extra_Constituents_In_List --
27287 ---------------------------------------
27289 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
27290 Constit_Elmt : Elmt_Id;
27292 begin
27293 if Present (List) then
27294 Constit_Elmt := First_Elmt (List);
27295 while Present (Constit_Elmt) loop
27296 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
27297 Next_Elmt (Constit_Elmt);
27298 end loop;
27299 end if;
27300 end Report_Extra_Constituents_In_List;
27302 -- Start of processing for Report_Extra_Constituents
27304 begin
27305 -- Do not perform this check in an instance because it was already
27306 -- performed successfully in the generic template.
27308 if Is_Generic_Instance (Spec_Id) then
27309 null;
27311 else
27312 Report_Extra_Constituents_In_List (In_Constits);
27313 Report_Extra_Constituents_In_List (In_Out_Constits);
27314 Report_Extra_Constituents_In_List (Out_Constits);
27315 Report_Extra_Constituents_In_List (Proof_In_Constits);
27316 end if;
27317 end Report_Extra_Constituents;
27319 --------------------------
27320 -- Report_Missing_Items --
27321 --------------------------
27323 procedure Report_Missing_Items is
27324 Item_Elmt : Elmt_Id;
27325 Item_Id : Entity_Id;
27327 begin
27328 -- Do not perform this check in an instance because it was already
27329 -- performed successfully in the generic template.
27331 if Is_Generic_Instance (Spec_Id) then
27332 null;
27334 else
27335 if Present (Repeat_Items) then
27336 Item_Elmt := First_Elmt (Repeat_Items);
27337 while Present (Item_Elmt) loop
27338 Item_Id := Node (Item_Elmt);
27339 SPARK_Msg_NE ("missing global item &", N, Item_Id);
27340 Next_Elmt (Item_Elmt);
27341 end loop;
27342 end if;
27343 end if;
27344 end Report_Missing_Items;
27346 -- Local variables
27348 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
27349 Errors : constant Nat := Serious_Errors_Detected;
27350 Items : Node_Id;
27351 No_Constit : Boolean;
27353 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
27355 begin
27356 -- Do not analyze the pragma multiple times
27358 if Is_Analyzed_Pragma (N) then
27359 return;
27360 end if;
27362 Spec_Id := Unique_Defining_Entity (Body_Decl);
27364 -- Use the anonymous object as the proper spec when Refined_Global
27365 -- applies to the body of a single task type. The object carries the
27366 -- proper Chars as well as all non-refined versions of pragmas.
27368 if Is_Single_Concurrent_Type (Spec_Id) then
27369 Spec_Id := Anonymous_Object (Spec_Id);
27370 end if;
27372 Global := Get_Pragma (Spec_Id, Pragma_Global);
27373 Items := Expression (Get_Argument (N, Spec_Id));
27375 -- The subprogram declaration lacks pragma Global. This renders
27376 -- Refined_Global useless as there is nothing to refine.
27378 if No (Global) then
27379 SPARK_Msg_NE
27380 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
27381 & "& lacks aspect or pragma Global"), N, Spec_Id);
27382 goto Leave;
27383 end if;
27385 -- Extract all relevant items from the corresponding Global pragma
27387 Collect_Global_Items (Expression (Get_Argument (Global, Spec_Id)));
27389 -- Package and subprogram bodies are instantiated individually in
27390 -- a separate compiler pass. Due to this mode of instantiation, the
27391 -- refinement of a state may no longer be visible when a subprogram
27392 -- body contract is instantiated. Since the generic template is legal,
27393 -- do not perform this check in the instance to circumvent this oddity.
27395 if Is_Generic_Instance (Spec_Id) then
27396 null;
27398 -- Non-instance case
27400 else
27401 -- The corresponding Global pragma must mention at least one
27402 -- state with a visible refinement at the point Refined_Global
27403 -- is processed. States with null refinements need Refined_Global
27404 -- pragma (SPARK RM 7.2.4(2)).
27406 if not Has_In_State
27407 and then not Has_In_Out_State
27408 and then not Has_Out_State
27409 and then not Has_Proof_In_State
27410 and then not Has_Null_State
27411 then
27412 SPARK_Msg_NE
27413 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
27414 & "depend on abstract state with visible refinement"),
27415 N, Spec_Id);
27416 goto Leave;
27418 -- The global refinement of inputs and outputs cannot be null when
27419 -- the corresponding Global pragma contains at least one item except
27420 -- in the case where we have states with null refinements.
27422 elsif Nkind (Items) = N_Null
27423 and then
27424 (Present (In_Items)
27425 or else Present (In_Out_Items)
27426 or else Present (Out_Items)
27427 or else Present (Proof_In_Items))
27428 and then not Has_Null_State
27429 then
27430 SPARK_Msg_NE
27431 (Fix_Msg (Spec_Id, "refinement cannot be null, subprogram & has "
27432 & "global items"), N, Spec_Id);
27433 goto Leave;
27434 end if;
27435 end if;
27437 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
27438 -- This ensures that the categorization of all refined global items is
27439 -- consistent with their role.
27441 Analyze_Global_In_Decl_Part (N);
27443 -- Perform all refinement checks with respect to completeness and mode
27444 -- matching.
27446 if Serious_Errors_Detected = Errors then
27447 Check_Refined_Global_List (Items);
27448 end if;
27450 -- Store the information that no constituent is used in the global
27451 -- refinement, prior to calling checking procedures which remove items
27452 -- from the list of constituents.
27454 No_Constit :=
27455 No (In_Constits)
27456 and then No (In_Out_Constits)
27457 and then No (Out_Constits)
27458 and then No (Proof_In_Constits);
27460 -- For Input states with visible refinement, at least one constituent
27461 -- must be used as an Input in the global refinement.
27463 if Serious_Errors_Detected = Errors then
27464 Check_Input_States;
27465 end if;
27467 -- Verify all possible completion variants for In_Out states with
27468 -- visible refinement.
27470 if Serious_Errors_Detected = Errors then
27471 Check_In_Out_States;
27472 end if;
27474 -- For Output states with visible refinement, all constituents must be
27475 -- used as Outputs in the global refinement.
27477 if Serious_Errors_Detected = Errors then
27478 Check_Output_States;
27479 end if;
27481 -- For Proof_In states with visible refinement, at least one constituent
27482 -- must be used as Proof_In in the global refinement.
27484 if Serious_Errors_Detected = Errors then
27485 Check_Proof_In_States;
27486 end if;
27488 -- Emit errors for all constituents that belong to other states with
27489 -- visible refinement that do not appear in Global.
27491 if Serious_Errors_Detected = Errors then
27492 Report_Extra_Constituents;
27493 end if;
27495 -- Emit errors for all items in Global that are not repeated in the
27496 -- global refinement and for which there is no full visible refinement
27497 -- and, in the case of states with partial visible refinement, no
27498 -- constituent is mentioned in the global refinement.
27500 if Serious_Errors_Detected = Errors then
27501 Report_Missing_Items;
27502 end if;
27504 -- Emit an error if no constituent is used in the global refinement
27505 -- (SPARK RM 7.2.4(3f)). Emit this error last, in case a more precise
27506 -- one may be issued by the checking procedures. Do not perform this
27507 -- check in an instance because it was already performed successfully
27508 -- in the generic template.
27510 if Serious_Errors_Detected = Errors
27511 and then not Is_Generic_Instance (Spec_Id)
27512 and then not Has_Null_State
27513 and then No_Constit
27514 then
27515 SPARK_Msg_N ("missing refinement", N);
27516 end if;
27518 <<Leave>>
27519 Set_Is_Analyzed_Pragma (N);
27520 end Analyze_Refined_Global_In_Decl_Part;
27522 ----------------------------------------
27523 -- Analyze_Refined_State_In_Decl_Part --
27524 ----------------------------------------
27526 procedure Analyze_Refined_State_In_Decl_Part
27527 (N : Node_Id;
27528 Freeze_Id : Entity_Id := Empty)
27530 Body_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
27531 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
27532 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
27534 Available_States : Elist_Id := No_Elist;
27535 -- A list of all abstract states defined in the package declaration that
27536 -- are available for refinement. The list is used to report unrefined
27537 -- states.
27539 Body_States : Elist_Id := No_Elist;
27540 -- A list of all hidden states that appear in the body of the related
27541 -- package. The list is used to report unused hidden states.
27543 Constituents_Seen : Elist_Id := No_Elist;
27544 -- A list that contains all constituents processed so far. The list is
27545 -- used to detect multiple uses of the same constituent.
27547 Freeze_Posted : Boolean := False;
27548 -- A flag that controls the output of a freezing-related error (see use
27549 -- below).
27551 Refined_States_Seen : Elist_Id := No_Elist;
27552 -- A list that contains all refined states processed so far. The list is
27553 -- used to detect duplicate refinements.
27555 procedure Analyze_Refinement_Clause (Clause : Node_Id);
27556 -- Perform full analysis of a single refinement clause
27558 procedure Report_Unrefined_States (States : Elist_Id);
27559 -- Emit errors for all unrefined abstract states found in list States
27561 -------------------------------
27562 -- Analyze_Refinement_Clause --
27563 -------------------------------
27565 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
27566 AR_Constit : Entity_Id := Empty;
27567 AW_Constit : Entity_Id := Empty;
27568 ER_Constit : Entity_Id := Empty;
27569 EW_Constit : Entity_Id := Empty;
27570 -- The entities of external constituents that contain one of the
27571 -- following enabled properties: Async_Readers, Async_Writers,
27572 -- Effective_Reads and Effective_Writes.
27574 External_Constit_Seen : Boolean := False;
27575 -- Flag used to mark when at least one external constituent is part
27576 -- of the state refinement.
27578 Non_Null_Seen : Boolean := False;
27579 Null_Seen : Boolean := False;
27580 -- Flags used to detect multiple uses of null in a single clause or a
27581 -- mixture of null and non-null constituents.
27583 Part_Of_Constits : Elist_Id := No_Elist;
27584 -- A list of all candidate constituents subject to indicator Part_Of
27585 -- where the encapsulating state is the current state.
27587 State : Node_Id;
27588 State_Id : Entity_Id;
27589 -- The current state being refined
27591 procedure Analyze_Constituent (Constit : Node_Id);
27592 -- Perform full analysis of a single constituent
27594 procedure Check_External_Property
27595 (Prop_Nam : Name_Id;
27596 Enabled : Boolean;
27597 Constit : Entity_Id);
27598 -- Determine whether a property denoted by name Prop_Nam is present
27599 -- in the refined state. Emit an error if this is not the case. Flag
27600 -- Enabled should be set when the property applies to the refined
27601 -- state. Constit denotes the constituent (if any) which introduces
27602 -- the property in the refinement.
27604 procedure Match_State;
27605 -- Determine whether the state being refined appears in list
27606 -- Available_States. Emit an error when attempting to re-refine the
27607 -- state or when the state is not defined in the package declaration,
27608 -- otherwise remove the state from Available_States.
27610 procedure Report_Unused_Constituents (Constits : Elist_Id);
27611 -- Emit errors for all unused Part_Of constituents in list Constits
27613 -------------------------
27614 -- Analyze_Constituent --
27615 -------------------------
27617 procedure Analyze_Constituent (Constit : Node_Id) is
27618 procedure Match_Constituent (Constit_Id : Entity_Id);
27619 -- Determine whether constituent Constit denoted by its entity
27620 -- Constit_Id appears in Body_States. Emit an error when the
27621 -- constituent is not a valid hidden state of the related package
27622 -- or when it is used more than once. Otherwise remove the
27623 -- constituent from Body_States.
27625 -----------------------
27626 -- Match_Constituent --
27627 -----------------------
27629 procedure Match_Constituent (Constit_Id : Entity_Id) is
27630 procedure Collect_Constituent;
27631 -- Verify the legality of constituent Constit_Id and add it to
27632 -- the refinements of State_Id.
27634 -------------------------
27635 -- Collect_Constituent --
27636 -------------------------
27638 procedure Collect_Constituent is
27639 Constits : Elist_Id;
27641 begin
27642 -- The Ghost policy in effect at the point of abstract state
27643 -- declaration and constituent must match (SPARK RM 6.9(15))
27645 Check_Ghost_Refinement
27646 (State, State_Id, Constit, Constit_Id);
27648 -- A synchronized state must be refined by a synchronized
27649 -- object or another synchronized state (SPARK RM 9.6).
27651 if Is_Synchronized_State (State_Id)
27652 and then not Is_Synchronized_Object (Constit_Id)
27653 and then not Is_Synchronized_State (Constit_Id)
27654 then
27655 SPARK_Msg_NE
27656 ("constituent of synchronized state & must be "
27657 & "synchronized", Constit, State_Id);
27658 end if;
27660 -- Add the constituent to the list of processed items to aid
27661 -- with the detection of duplicates.
27663 Append_New_Elmt (Constit_Id, Constituents_Seen);
27665 -- Collect the constituent in the list of refinement items
27666 -- and establish a relation between the refined state and
27667 -- the item.
27669 Constits := Refinement_Constituents (State_Id);
27671 if No (Constits) then
27672 Constits := New_Elmt_List;
27673 Set_Refinement_Constituents (State_Id, Constits);
27674 end if;
27676 Append_Elmt (Constit_Id, Constits);
27677 Set_Encapsulating_State (Constit_Id, State_Id);
27679 -- The state has at least one legal constituent, mark the
27680 -- start of the refinement region. The region ends when the
27681 -- body declarations end (see routine Analyze_Declarations).
27683 Set_Has_Visible_Refinement (State_Id);
27685 -- When the constituent is external, save its relevant
27686 -- property for further checks.
27688 if Async_Readers_Enabled (Constit_Id) then
27689 AR_Constit := Constit_Id;
27690 External_Constit_Seen := True;
27691 end if;
27693 if Async_Writers_Enabled (Constit_Id) then
27694 AW_Constit := Constit_Id;
27695 External_Constit_Seen := True;
27696 end if;
27698 if Effective_Reads_Enabled (Constit_Id) then
27699 ER_Constit := Constit_Id;
27700 External_Constit_Seen := True;
27701 end if;
27703 if Effective_Writes_Enabled (Constit_Id) then
27704 EW_Constit := Constit_Id;
27705 External_Constit_Seen := True;
27706 end if;
27707 end Collect_Constituent;
27709 -- Local variables
27711 State_Elmt : Elmt_Id;
27713 -- Start of processing for Match_Constituent
27715 begin
27716 -- Detect a duplicate use of a constituent
27718 if Contains (Constituents_Seen, Constit_Id) then
27719 SPARK_Msg_NE
27720 ("duplicate use of constituent &", Constit, Constit_Id);
27721 return;
27722 end if;
27724 -- The constituent is subject to a Part_Of indicator
27726 if Present (Encapsulating_State (Constit_Id)) then
27727 if Encapsulating_State (Constit_Id) = State_Id then
27728 Remove (Part_Of_Constits, Constit_Id);
27729 Collect_Constituent;
27731 -- The constituent is part of another state and is used
27732 -- incorrectly in the refinement of the current state.
27734 else
27735 Error_Msg_Name_1 := Chars (State_Id);
27736 SPARK_Msg_NE
27737 ("& cannot act as constituent of state %",
27738 Constit, Constit_Id);
27739 SPARK_Msg_NE
27740 ("\Part_Of indicator specifies encapsulator &",
27741 Constit, Encapsulating_State (Constit_Id));
27742 end if;
27744 -- The only other source of legal constituents is the body
27745 -- state space of the related package.
27747 else
27748 if Present (Body_States) then
27749 State_Elmt := First_Elmt (Body_States);
27750 while Present (State_Elmt) loop
27752 -- Consume a valid constituent to signal that it has
27753 -- been encountered.
27755 if Node (State_Elmt) = Constit_Id then
27756 Remove_Elmt (Body_States, State_Elmt);
27757 Collect_Constituent;
27758 return;
27759 end if;
27761 Next_Elmt (State_Elmt);
27762 end loop;
27763 end if;
27765 -- At this point it is known that the constituent is not
27766 -- part of the package hidden state and cannot be used in
27767 -- a refinement (SPARK RM 7.2.2(9)).
27769 Error_Msg_Name_1 := Chars (Spec_Id);
27770 SPARK_Msg_NE
27771 ("cannot use & in refinement, constituent is not a hidden "
27772 & "state of package %", Constit, Constit_Id);
27773 end if;
27774 end Match_Constituent;
27776 -- Local variables
27778 Constit_Id : Entity_Id;
27779 Constits : Elist_Id;
27781 -- Start of processing for Analyze_Constituent
27783 begin
27784 -- Detect multiple uses of null in a single refinement clause or a
27785 -- mixture of null and non-null constituents.
27787 if Nkind (Constit) = N_Null then
27788 if Null_Seen then
27789 SPARK_Msg_N
27790 ("multiple null constituents not allowed", Constit);
27792 elsif Non_Null_Seen then
27793 SPARK_Msg_N
27794 ("cannot mix null and non-null constituents", Constit);
27796 else
27797 Null_Seen := True;
27799 -- Collect the constituent in the list of refinement items
27801 Constits := Refinement_Constituents (State_Id);
27803 if No (Constits) then
27804 Constits := New_Elmt_List;
27805 Set_Refinement_Constituents (State_Id, Constits);
27806 end if;
27808 Append_Elmt (Constit, Constits);
27810 -- The state has at least one legal constituent, mark the
27811 -- start of the refinement region. The region ends when the
27812 -- body declarations end (see Analyze_Declarations).
27814 Set_Has_Visible_Refinement (State_Id);
27815 end if;
27817 -- Non-null constituents
27819 else
27820 Non_Null_Seen := True;
27822 if Null_Seen then
27823 SPARK_Msg_N
27824 ("cannot mix null and non-null constituents", Constit);
27825 end if;
27827 Analyze (Constit);
27828 Resolve_State (Constit);
27830 -- Ensure that the constituent denotes a valid state or a
27831 -- whole object (SPARK RM 7.2.2(5)).
27833 if Is_Entity_Name (Constit) then
27834 Constit_Id := Entity_Of (Constit);
27836 -- When a constituent is declared after a subprogram body
27837 -- that caused freezing of the related contract where
27838 -- pragma Refined_State resides, the constituent appears
27839 -- undefined and carries Any_Id as its entity.
27841 -- package body Pack
27842 -- with Refined_State => (State => Constit)
27843 -- is
27844 -- procedure Proc
27845 -- with Refined_Global => (Input => Constit)
27846 -- is
27847 -- ...
27848 -- end Proc;
27850 -- Constit : ...;
27851 -- end Pack;
27853 if Constit_Id = Any_Id then
27854 SPARK_Msg_NE ("& is undefined", Constit, Constit_Id);
27856 -- Emit a specialized info message when the contract of
27857 -- the related package body was "frozen" by another body.
27858 -- Note that it is not possible to precisely identify why
27859 -- the constituent is undefined because it is not visible
27860 -- when pragma Refined_State is analyzed. This message is
27861 -- a reasonable approximation.
27863 if Present (Freeze_Id) and then not Freeze_Posted then
27864 Freeze_Posted := True;
27866 Error_Msg_Name_1 := Chars (Body_Id);
27867 Error_Msg_Sloc := Sloc (Freeze_Id);
27868 SPARK_Msg_NE
27869 ("body & declared # freezes the contract of %",
27870 N, Freeze_Id);
27871 SPARK_Msg_N
27872 ("\all constituents must be declared before body #",
27875 -- A misplaced constituent is a critical error because
27876 -- pragma Refined_Depends or Refined_Global depends on
27877 -- the proper link between a state and a constituent.
27878 -- Stop the compilation, as this leads to a multitude
27879 -- of misleading cascaded errors.
27881 raise Unrecoverable_Error;
27882 end if;
27884 -- The constituent is a valid state or object
27886 elsif Ekind_In (Constit_Id, E_Abstract_State,
27887 E_Constant,
27888 E_Variable)
27889 then
27890 Match_Constituent (Constit_Id);
27892 -- The variable may eventually become a constituent of a
27893 -- single protected/task type. Record the reference now
27894 -- and verify its legality when analyzing the contract of
27895 -- the variable (SPARK RM 9.3).
27897 if Ekind (Constit_Id) = E_Variable then
27898 Record_Possible_Part_Of_Reference
27899 (Var_Id => Constit_Id,
27900 Ref => Constit);
27901 end if;
27903 -- Otherwise the constituent is illegal
27905 else
27906 SPARK_Msg_NE
27907 ("constituent & must denote object or state",
27908 Constit, Constit_Id);
27909 end if;
27911 -- The constituent is illegal
27913 else
27914 SPARK_Msg_N ("malformed constituent", Constit);
27915 end if;
27916 end if;
27917 end Analyze_Constituent;
27919 -----------------------------
27920 -- Check_External_Property --
27921 -----------------------------
27923 procedure Check_External_Property
27924 (Prop_Nam : Name_Id;
27925 Enabled : Boolean;
27926 Constit : Entity_Id)
27928 begin
27929 -- The property is missing in the declaration of the state, but
27930 -- a constituent is introducing it in the state refinement
27931 -- (SPARK RM 7.2.8(2)).
27933 if not Enabled and then Present (Constit) then
27934 Error_Msg_Name_1 := Prop_Nam;
27935 Error_Msg_Name_2 := Chars (State_Id);
27936 SPARK_Msg_NE
27937 ("constituent & introduces external property % in refinement "
27938 & "of state %", State, Constit);
27940 Error_Msg_Sloc := Sloc (State_Id);
27941 SPARK_Msg_N
27942 ("\property is missing in abstract state declaration #",
27943 State);
27944 end if;
27945 end Check_External_Property;
27947 -----------------
27948 -- Match_State --
27949 -----------------
27951 procedure Match_State is
27952 State_Elmt : Elmt_Id;
27954 begin
27955 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
27957 if Contains (Refined_States_Seen, State_Id) then
27958 SPARK_Msg_NE
27959 ("duplicate refinement of state &", State, State_Id);
27960 return;
27961 end if;
27963 -- Inspect the abstract states defined in the package declaration
27964 -- looking for a match.
27966 State_Elmt := First_Elmt (Available_States);
27967 while Present (State_Elmt) loop
27969 -- A valid abstract state is being refined in the body. Add
27970 -- the state to the list of processed refined states to aid
27971 -- with the detection of duplicate refinements. Remove the
27972 -- state from Available_States to signal that it has already
27973 -- been refined.
27975 if Node (State_Elmt) = State_Id then
27976 Append_New_Elmt (State_Id, Refined_States_Seen);
27977 Remove_Elmt (Available_States, State_Elmt);
27978 return;
27979 end if;
27981 Next_Elmt (State_Elmt);
27982 end loop;
27984 -- If we get here, we are refining a state that is not defined in
27985 -- the package declaration.
27987 Error_Msg_Name_1 := Chars (Spec_Id);
27988 SPARK_Msg_NE
27989 ("cannot refine state, & is not defined in package %",
27990 State, State_Id);
27991 end Match_State;
27993 --------------------------------
27994 -- Report_Unused_Constituents --
27995 --------------------------------
27997 procedure Report_Unused_Constituents (Constits : Elist_Id) is
27998 Constit_Elmt : Elmt_Id;
27999 Constit_Id : Entity_Id;
28000 Posted : Boolean := False;
28002 begin
28003 if Present (Constits) then
28004 Constit_Elmt := First_Elmt (Constits);
28005 while Present (Constit_Elmt) loop
28006 Constit_Id := Node (Constit_Elmt);
28008 -- Generate an error message of the form:
28010 -- state ... has unused Part_Of constituents
28011 -- abstract state ... defined at ...
28012 -- constant ... defined at ...
28013 -- variable ... defined at ...
28015 if not Posted then
28016 Posted := True;
28017 SPARK_Msg_NE
28018 ("state & has unused Part_Of constituents",
28019 State, State_Id);
28020 end if;
28022 Error_Msg_Sloc := Sloc (Constit_Id);
28024 if Ekind (Constit_Id) = E_Abstract_State then
28025 SPARK_Msg_NE
28026 ("\abstract state & defined #", State, Constit_Id);
28028 elsif Ekind (Constit_Id) = E_Constant then
28029 SPARK_Msg_NE
28030 ("\constant & defined #", State, Constit_Id);
28032 else
28033 pragma Assert (Ekind (Constit_Id) = E_Variable);
28034 SPARK_Msg_NE ("\variable & defined #", State, Constit_Id);
28035 end if;
28037 Next_Elmt (Constit_Elmt);
28038 end loop;
28039 end if;
28040 end Report_Unused_Constituents;
28042 -- Local declarations
28044 Body_Ref : Node_Id;
28045 Body_Ref_Elmt : Elmt_Id;
28046 Constit : Node_Id;
28047 Extra_State : Node_Id;
28049 -- Start of processing for Analyze_Refinement_Clause
28051 begin
28052 -- A refinement clause appears as a component association where the
28053 -- sole choice is the state and the expressions are the constituents.
28054 -- This is a syntax error, always report.
28056 if Nkind (Clause) /= N_Component_Association then
28057 Error_Msg_N ("malformed state refinement clause", Clause);
28058 return;
28059 end if;
28061 -- Analyze the state name of a refinement clause
28063 State := First (Choices (Clause));
28065 Analyze (State);
28066 Resolve_State (State);
28068 -- Ensure that the state name denotes a valid abstract state that is
28069 -- defined in the spec of the related package.
28071 if Is_Entity_Name (State) then
28072 State_Id := Entity_Of (State);
28074 -- When the abstract state is undefined, it appears as Any_Id. Do
28075 -- not continue with the analysis of the clause.
28077 if State_Id = Any_Id then
28078 return;
28080 -- Catch any attempts to re-refine a state or refine a state that
28081 -- is not defined in the package declaration.
28083 elsif Ekind (State_Id) = E_Abstract_State then
28084 Match_State;
28086 else
28087 SPARK_Msg_NE ("& must denote abstract state", State, State_Id);
28088 return;
28089 end if;
28091 -- References to a state with visible refinement are illegal.
28092 -- When nested packages are involved, detecting such references is
28093 -- tricky because pragma Refined_State is analyzed later than the
28094 -- offending pragma Depends or Global. References that occur in
28095 -- such nested context are stored in a list. Emit errors for all
28096 -- references found in Body_References (SPARK RM 6.1.4(8)).
28098 if Present (Body_References (State_Id)) then
28099 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
28100 while Present (Body_Ref_Elmt) loop
28101 Body_Ref := Node (Body_Ref_Elmt);
28103 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
28104 Error_Msg_Sloc := Sloc (State);
28105 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
28107 Next_Elmt (Body_Ref_Elmt);
28108 end loop;
28109 end if;
28111 -- The state name is illegal. This is a syntax error, always report.
28113 else
28114 Error_Msg_N ("malformed state name in refinement clause", State);
28115 return;
28116 end if;
28118 -- A refinement clause may only refine one state at a time
28120 Extra_State := Next (State);
28122 if Present (Extra_State) then
28123 SPARK_Msg_N
28124 ("refinement clause cannot cover multiple states", Extra_State);
28125 end if;
28127 -- Replicate the Part_Of constituents of the refined state because
28128 -- the algorithm will consume items.
28130 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
28132 -- Analyze all constituents of the refinement. Multiple constituents
28133 -- appear as an aggregate.
28135 Constit := Expression (Clause);
28137 if Nkind (Constit) = N_Aggregate then
28138 if Present (Component_Associations (Constit)) then
28139 SPARK_Msg_N
28140 ("constituents of refinement clause must appear in "
28141 & "positional form", Constit);
28143 else pragma Assert (Present (Expressions (Constit)));
28144 Constit := First (Expressions (Constit));
28145 while Present (Constit) loop
28146 Analyze_Constituent (Constit);
28147 Next (Constit);
28148 end loop;
28149 end if;
28151 -- Various forms of a single constituent. Note that these may include
28152 -- malformed constituents.
28154 else
28155 Analyze_Constituent (Constit);
28156 end if;
28158 -- Verify that external constituents do not introduce new external
28159 -- property in the state refinement (SPARK RM 7.2.8(2)).
28161 if Is_External_State (State_Id) then
28162 Check_External_Property
28163 (Prop_Nam => Name_Async_Readers,
28164 Enabled => Async_Readers_Enabled (State_Id),
28165 Constit => AR_Constit);
28167 Check_External_Property
28168 (Prop_Nam => Name_Async_Writers,
28169 Enabled => Async_Writers_Enabled (State_Id),
28170 Constit => AW_Constit);
28172 Check_External_Property
28173 (Prop_Nam => Name_Effective_Reads,
28174 Enabled => Effective_Reads_Enabled (State_Id),
28175 Constit => ER_Constit);
28177 Check_External_Property
28178 (Prop_Nam => Name_Effective_Writes,
28179 Enabled => Effective_Writes_Enabled (State_Id),
28180 Constit => EW_Constit);
28182 -- When a refined state is not external, it should not have external
28183 -- constituents (SPARK RM 7.2.8(1)).
28185 elsif External_Constit_Seen then
28186 SPARK_Msg_NE
28187 ("non-external state & cannot contain external constituents in "
28188 & "refinement", State, State_Id);
28189 end if;
28191 -- Ensure that all Part_Of candidate constituents have been mentioned
28192 -- in the refinement clause.
28194 Report_Unused_Constituents (Part_Of_Constits);
28195 end Analyze_Refinement_Clause;
28197 -----------------------------
28198 -- Report_Unrefined_States --
28199 -----------------------------
28201 procedure Report_Unrefined_States (States : Elist_Id) is
28202 State_Elmt : Elmt_Id;
28204 begin
28205 if Present (States) then
28206 State_Elmt := First_Elmt (States);
28207 while Present (State_Elmt) loop
28208 SPARK_Msg_N
28209 ("abstract state & must be refined", Node (State_Elmt));
28211 Next_Elmt (State_Elmt);
28212 end loop;
28213 end if;
28214 end Report_Unrefined_States;
28216 -- Local declarations
28218 Clauses : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
28219 Clause : Node_Id;
28221 -- Start of processing for Analyze_Refined_State_In_Decl_Part
28223 begin
28224 -- Do not analyze the pragma multiple times
28226 if Is_Analyzed_Pragma (N) then
28227 return;
28228 end if;
28230 -- Save the scenario for examination by the ABE Processing phase
28232 Record_Elaboration_Scenario (N);
28234 -- Replicate the abstract states declared by the package because the
28235 -- matching algorithm will consume states.
28237 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
28239 -- Gather all abstract states and objects declared in the visible
28240 -- state space of the package body. These items must be utilized as
28241 -- constituents in a state refinement.
28243 Body_States := Collect_Body_States (Body_Id);
28245 -- Multiple non-null state refinements appear as an aggregate
28247 if Nkind (Clauses) = N_Aggregate then
28248 if Present (Expressions (Clauses)) then
28249 SPARK_Msg_N
28250 ("state refinements must appear as component associations",
28251 Clauses);
28253 else pragma Assert (Present (Component_Associations (Clauses)));
28254 Clause := First (Component_Associations (Clauses));
28255 while Present (Clause) loop
28256 Analyze_Refinement_Clause (Clause);
28257 Next (Clause);
28258 end loop;
28259 end if;
28261 -- Various forms of a single state refinement. Note that these may
28262 -- include malformed refinements.
28264 else
28265 Analyze_Refinement_Clause (Clauses);
28266 end if;
28268 -- List all abstract states that were left unrefined
28270 Report_Unrefined_States (Available_States);
28272 Set_Is_Analyzed_Pragma (N);
28273 end Analyze_Refined_State_In_Decl_Part;
28275 ------------------------------------
28276 -- Analyze_Test_Case_In_Decl_Part --
28277 ------------------------------------
28279 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is
28280 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
28281 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
28283 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id);
28284 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
28285 -- denoted by Arg_Nam.
28287 ------------------------------
28288 -- Preanalyze_Test_Case_Arg --
28289 ------------------------------
28291 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id) is
28292 Arg : Node_Id;
28294 begin
28295 -- Preanalyze the original aspect argument for ASIS or for a generic
28296 -- subprogram to properly capture global references.
28298 if ASIS_Mode or else Is_Generic_Subprogram (Spec_Id) then
28299 Arg :=
28300 Test_Case_Arg
28301 (Prag => N,
28302 Arg_Nam => Arg_Nam,
28303 From_Aspect => True);
28305 if Present (Arg) then
28306 Preanalyze_Assert_Expression
28307 (Expression (Arg), Standard_Boolean);
28308 end if;
28309 end if;
28311 Arg := Test_Case_Arg (N, Arg_Nam);
28313 if Present (Arg) then
28314 Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean);
28315 end if;
28316 end Preanalyze_Test_Case_Arg;
28318 -- Local variables
28320 Restore_Scope : Boolean := False;
28322 -- Start of processing for Analyze_Test_Case_In_Decl_Part
28324 begin
28325 -- Do not analyze the pragma multiple times
28327 if Is_Analyzed_Pragma (N) then
28328 return;
28329 end if;
28331 -- Ensure that the formal parameters are visible when analyzing all
28332 -- clauses. This falls out of the general rule of aspects pertaining
28333 -- to subprogram declarations.
28335 if not In_Open_Scopes (Spec_Id) then
28336 Restore_Scope := True;
28337 Push_Scope (Spec_Id);
28339 if Is_Generic_Subprogram (Spec_Id) then
28340 Install_Generic_Formals (Spec_Id);
28341 else
28342 Install_Formals (Spec_Id);
28343 end if;
28344 end if;
28346 Preanalyze_Test_Case_Arg (Name_Requires);
28347 Preanalyze_Test_Case_Arg (Name_Ensures);
28349 if Restore_Scope then
28350 End_Scope;
28351 end if;
28353 -- Currently it is not possible to inline pre/postconditions on a
28354 -- subprogram subject to pragma Inline_Always.
28356 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
28358 Set_Is_Analyzed_Pragma (N);
28359 end Analyze_Test_Case_In_Decl_Part;
28361 ----------------
28362 -- Appears_In --
28363 ----------------
28365 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
28366 Elmt : Elmt_Id;
28367 Id : Entity_Id;
28369 begin
28370 if Present (List) then
28371 Elmt := First_Elmt (List);
28372 while Present (Elmt) loop
28373 if Nkind (Node (Elmt)) = N_Defining_Identifier then
28374 Id := Node (Elmt);
28375 else
28376 Id := Entity_Of (Node (Elmt));
28377 end if;
28379 if Id = Item_Id then
28380 return True;
28381 end if;
28383 Next_Elmt (Elmt);
28384 end loop;
28385 end if;
28387 return False;
28388 end Appears_In;
28390 -----------------------------------
28391 -- Build_Pragma_Check_Equivalent --
28392 -----------------------------------
28394 function Build_Pragma_Check_Equivalent
28395 (Prag : Node_Id;
28396 Subp_Id : Entity_Id := Empty;
28397 Inher_Id : Entity_Id := Empty;
28398 Keep_Pragma_Id : Boolean := False) return Node_Id
28400 function Suppress_Reference (N : Node_Id) return Traverse_Result;
28401 -- Detect whether node N references a formal parameter subject to
28402 -- pragma Unreferenced. If this is the case, set Comes_From_Source
28403 -- to False to suppress the generation of a reference when analyzing
28404 -- N later on.
28406 ------------------------
28407 -- Suppress_Reference --
28408 ------------------------
28410 function Suppress_Reference (N : Node_Id) return Traverse_Result is
28411 Formal : Entity_Id;
28413 begin
28414 if Is_Entity_Name (N) and then Present (Entity (N)) then
28415 Formal := Entity (N);
28417 -- The formal parameter is subject to pragma Unreferenced. Prevent
28418 -- the generation of references by resetting the Comes_From_Source
28419 -- flag.
28421 if Is_Formal (Formal)
28422 and then Has_Pragma_Unreferenced (Formal)
28423 then
28424 Set_Comes_From_Source (N, False);
28425 end if;
28426 end if;
28428 return OK;
28429 end Suppress_Reference;
28431 procedure Suppress_References is
28432 new Traverse_Proc (Suppress_Reference);
28434 -- Local variables
28436 Loc : constant Source_Ptr := Sloc (Prag);
28437 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
28438 Check_Prag : Node_Id;
28439 Msg_Arg : Node_Id;
28440 Nam : Name_Id;
28442 Needs_Wrapper : Boolean;
28443 pragma Unreferenced (Needs_Wrapper);
28445 -- Start of processing for Build_Pragma_Check_Equivalent
28447 begin
28448 -- When the pre- or postcondition is inherited, map the formals of the
28449 -- inherited subprogram to those of the current subprogram. In addition,
28450 -- map primitive operations of the parent type into the corresponding
28451 -- primitive operations of the descendant.
28453 if Present (Inher_Id) then
28454 pragma Assert (Present (Subp_Id));
28456 Update_Primitives_Mapping (Inher_Id, Subp_Id);
28458 -- Use generic machinery to copy inherited pragma, as if it were an
28459 -- instantiation, resetting source locations appropriately, so that
28460 -- expressions inside the inherited pragma use chained locations.
28461 -- This is used in particular in GNATprove to locate precisely
28462 -- messages on a given inherited pragma.
28464 Set_Copied_Sloc_For_Inherited_Pragma
28465 (Unit_Declaration_Node (Subp_Id), Inher_Id);
28466 Check_Prag := New_Copy_Tree (Source => Prag);
28468 -- Build the inherited class-wide condition
28470 Build_Class_Wide_Expression
28471 (Prag => Check_Prag,
28472 Subp => Subp_Id,
28473 Par_Subp => Inher_Id,
28474 Adjust_Sloc => True,
28475 Needs_Wrapper => Needs_Wrapper);
28477 -- If not an inherited condition simply copy the original pragma
28479 else
28480 Check_Prag := New_Copy_Tree (Source => Prag);
28481 end if;
28483 -- Mark the pragma as being internally generated and reset the Analyzed
28484 -- flag.
28486 Set_Analyzed (Check_Prag, False);
28487 Set_Comes_From_Source (Check_Prag, False);
28489 -- The tree of the original pragma may contain references to the
28490 -- formal parameters of the related subprogram. At the same time
28491 -- the corresponding body may mark the formals as unreferenced:
28493 -- procedure Proc (Formal : ...)
28494 -- with Pre => Formal ...;
28496 -- procedure Proc (Formal : ...) is
28497 -- pragma Unreferenced (Formal);
28498 -- ...
28500 -- This creates problems because all pragma Check equivalents are
28501 -- analyzed at the end of the body declarations. Since all source
28502 -- references have already been accounted for, reset any references
28503 -- to such formals in the generated pragma Check equivalent.
28505 Suppress_References (Check_Prag);
28507 if Present (Corresponding_Aspect (Prag)) then
28508 Nam := Chars (Identifier (Corresponding_Aspect (Prag)));
28509 else
28510 Nam := Prag_Nam;
28511 end if;
28513 -- Unless Keep_Pragma_Id is True in order to keep the identifier of
28514 -- the copied pragma in the newly created pragma, convert the copy into
28515 -- pragma Check by correcting the name and adding a check_kind argument.
28517 if not Keep_Pragma_Id then
28518 Set_Class_Present (Check_Prag, False);
28520 Set_Pragma_Identifier
28521 (Check_Prag, Make_Identifier (Loc, Name_Check));
28523 Prepend_To (Pragma_Argument_Associations (Check_Prag),
28524 Make_Pragma_Argument_Association (Loc,
28525 Expression => Make_Identifier (Loc, Nam)));
28526 end if;
28528 -- Update the error message when the pragma is inherited
28530 if Present (Inher_Id) then
28531 Msg_Arg := Last (Pragma_Argument_Associations (Check_Prag));
28533 if Chars (Msg_Arg) = Name_Message then
28534 String_To_Name_Buffer (Strval (Expression (Msg_Arg)));
28536 -- Insert "inherited" to improve the error message
28538 if Name_Buffer (1 .. 8) = "failed p" then
28539 Insert_Str_In_Name_Buffer ("inherited ", 8);
28540 Set_Strval (Expression (Msg_Arg), String_From_Name_Buffer);
28541 end if;
28542 end if;
28543 end if;
28545 return Check_Prag;
28546 end Build_Pragma_Check_Equivalent;
28548 -----------------------------
28549 -- Check_Applicable_Policy --
28550 -----------------------------
28552 procedure Check_Applicable_Policy (N : Node_Id) is
28553 PP : Node_Id;
28554 Policy : Name_Id;
28556 Ename : constant Name_Id := Original_Aspect_Pragma_Name (N);
28558 begin
28559 -- No effect if not valid assertion kind name
28561 if not Is_Valid_Assertion_Kind (Ename) then
28562 return;
28563 end if;
28565 -- Loop through entries in check policy list
28567 PP := Opt.Check_Policy_List;
28568 while Present (PP) loop
28569 declare
28570 PPA : constant List_Id := Pragma_Argument_Associations (PP);
28571 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
28573 begin
28574 if Ename = Pnm
28575 or else Pnm = Name_Assertion
28576 or else (Pnm = Name_Statement_Assertions
28577 and then Nam_In (Ename, Name_Assert,
28578 Name_Assert_And_Cut,
28579 Name_Assume,
28580 Name_Loop_Invariant,
28581 Name_Loop_Variant))
28582 then
28583 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
28585 case Policy is
28586 when Name_Ignore
28587 | Name_Off
28589 -- In CodePeer mode and GNATprove mode, we need to
28590 -- consider all assertions, unless they are disabled.
28591 -- Force Is_Checked on ignored assertions, in particular
28592 -- because transformations of the AST may depend on
28593 -- assertions being checked (e.g. the translation of
28594 -- attribute 'Loop_Entry).
28596 if CodePeer_Mode or GNATprove_Mode then
28597 Set_Is_Checked (N, True);
28598 Set_Is_Ignored (N, False);
28599 else
28600 Set_Is_Checked (N, False);
28601 Set_Is_Ignored (N, True);
28602 end if;
28604 when Name_Check
28605 | Name_On
28607 Set_Is_Checked (N, True);
28608 Set_Is_Ignored (N, False);
28610 when Name_Disable =>
28611 Set_Is_Ignored (N, True);
28612 Set_Is_Checked (N, False);
28613 Set_Is_Disabled (N, True);
28615 -- That should be exhaustive, the null here is a defence
28616 -- against a malformed tree from previous errors.
28618 when others =>
28619 null;
28620 end case;
28622 return;
28623 end if;
28625 PP := Next_Pragma (PP);
28626 end;
28627 end loop;
28629 -- If there are no specific entries that matched, then we let the
28630 -- setting of assertions govern. Note that this provides the needed
28631 -- compatibility with the RM for the cases of assertion, invariant,
28632 -- precondition, predicate, and postcondition. Note also that
28633 -- Assertions_Enabled is forced in CodePeer mode and GNATprove mode.
28635 if Assertions_Enabled then
28636 Set_Is_Checked (N, True);
28637 Set_Is_Ignored (N, False);
28638 else
28639 Set_Is_Checked (N, False);
28640 Set_Is_Ignored (N, True);
28641 end if;
28642 end Check_Applicable_Policy;
28644 -------------------------------
28645 -- Check_External_Properties --
28646 -------------------------------
28648 procedure Check_External_Properties
28649 (Item : Node_Id;
28650 AR : Boolean;
28651 AW : Boolean;
28652 ER : Boolean;
28653 EW : Boolean)
28655 begin
28656 -- All properties enabled
28658 if AR and AW and ER and EW then
28659 null;
28661 -- Async_Readers + Effective_Writes
28662 -- Async_Readers + Async_Writers + Effective_Writes
28664 elsif AR and EW and not ER then
28665 null;
28667 -- Async_Writers + Effective_Reads
28668 -- Async_Readers + Async_Writers + Effective_Reads
28670 elsif AW and ER and not EW then
28671 null;
28673 -- Async_Readers + Async_Writers
28675 elsif AR and AW and not ER and not EW then
28676 null;
28678 -- Async_Readers
28680 elsif AR and not AW and not ER and not EW then
28681 null;
28683 -- Async_Writers
28685 elsif AW and not AR and not ER and not EW then
28686 null;
28688 else
28689 SPARK_Msg_N
28690 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
28691 Item);
28692 end if;
28693 end Check_External_Properties;
28695 ----------------
28696 -- Check_Kind --
28697 ----------------
28699 function Check_Kind (Nam : Name_Id) return Name_Id is
28700 PP : Node_Id;
28702 begin
28703 -- Loop through entries in check policy list
28705 PP := Opt.Check_Policy_List;
28706 while Present (PP) loop
28707 declare
28708 PPA : constant List_Id := Pragma_Argument_Associations (PP);
28709 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
28711 begin
28712 if Nam = Pnm
28713 or else (Pnm = Name_Assertion
28714 and then Is_Valid_Assertion_Kind (Nam))
28715 or else (Pnm = Name_Statement_Assertions
28716 and then Nam_In (Nam, Name_Assert,
28717 Name_Assert_And_Cut,
28718 Name_Assume,
28719 Name_Loop_Invariant,
28720 Name_Loop_Variant))
28721 then
28722 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
28723 when Name_Check
28724 | Name_On
28726 return Name_Check;
28728 when Name_Ignore
28729 | Name_Off
28731 return Name_Ignore;
28733 when Name_Disable =>
28734 return Name_Disable;
28736 when others =>
28737 raise Program_Error;
28738 end case;
28740 else
28741 PP := Next_Pragma (PP);
28742 end if;
28743 end;
28744 end loop;
28746 -- If there are no specific entries that matched, then we let the
28747 -- setting of assertions govern. Note that this provides the needed
28748 -- compatibility with the RM for the cases of assertion, invariant,
28749 -- precondition, predicate, and postcondition.
28751 if Assertions_Enabled then
28752 return Name_Check;
28753 else
28754 return Name_Ignore;
28755 end if;
28756 end Check_Kind;
28758 ---------------------------
28759 -- Check_Missing_Part_Of --
28760 ---------------------------
28762 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
28763 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
28764 -- Determine whether a package denoted by Pack_Id declares at least one
28765 -- visible state.
28767 -----------------------
28768 -- Has_Visible_State --
28769 -----------------------
28771 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
28772 Item_Id : Entity_Id;
28774 begin
28775 -- Traverse the entity chain of the package trying to find at least
28776 -- one visible abstract state, variable or a package [instantiation]
28777 -- that declares a visible state.
28779 Item_Id := First_Entity (Pack_Id);
28780 while Present (Item_Id)
28781 and then not In_Private_Part (Item_Id)
28782 loop
28783 -- Do not consider internally generated items
28785 if not Comes_From_Source (Item_Id) then
28786 null;
28788 -- Do not consider generic formals or their corresponding actuals
28789 -- because they are not part of a visible state. Note that both
28790 -- entities are marked as hidden.
28792 elsif Is_Hidden (Item_Id) then
28793 null;
28795 -- A visible state has been found. Note that constants are not
28796 -- considered here because it is not possible to determine whether
28797 -- they depend on variable input. This check is left to the SPARK
28798 -- prover.
28800 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
28801 return True;
28803 -- Recursively peek into nested packages and instantiations
28805 elsif Ekind (Item_Id) = E_Package
28806 and then Has_Visible_State (Item_Id)
28807 then
28808 return True;
28809 end if;
28811 Next_Entity (Item_Id);
28812 end loop;
28814 return False;
28815 end Has_Visible_State;
28817 -- Local variables
28819 Pack_Id : Entity_Id;
28820 Placement : State_Space_Kind;
28822 -- Start of processing for Check_Missing_Part_Of
28824 begin
28825 -- Do not consider abstract states, variables or package instantiations
28826 -- coming from an instance as those always inherit the Part_Of indicator
28827 -- of the instance itself.
28829 if In_Instance then
28830 return;
28832 -- Do not consider internally generated entities as these can never
28833 -- have a Part_Of indicator.
28835 elsif not Comes_From_Source (Item_Id) then
28836 return;
28838 -- Perform these checks only when SPARK_Mode is enabled as they will
28839 -- interfere with standard Ada rules and produce false positives.
28841 elsif SPARK_Mode /= On then
28842 return;
28844 -- Do not consider constants, because the compiler cannot accurately
28845 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
28846 -- act as a hidden state of a package.
28848 elsif Ekind (Item_Id) = E_Constant then
28849 return;
28850 end if;
28852 -- Find where the abstract state, variable or package instantiation
28853 -- lives with respect to the state space.
28855 Find_Placement_In_State_Space
28856 (Item_Id => Item_Id,
28857 Placement => Placement,
28858 Pack_Id => Pack_Id);
28860 -- Items that appear in a non-package construct (subprogram, block, etc)
28861 -- do not require a Part_Of indicator because they can never act as a
28862 -- hidden state.
28864 if Placement = Not_In_Package then
28865 null;
28867 -- An item declared in the body state space of a package always act as a
28868 -- constituent and does not need explicit Part_Of indicator.
28870 elsif Placement = Body_State_Space then
28871 null;
28873 -- In general an item declared in the visible state space of a package
28874 -- does not require a Part_Of indicator. The only exception is when the
28875 -- related package is a nongeneric private child unit, in which case
28876 -- Part_Of must denote a state in the parent unit or in one of its
28877 -- descendants.
28879 elsif Placement = Visible_State_Space then
28880 if Is_Child_Unit (Pack_Id)
28881 and then not Is_Generic_Unit (Pack_Id)
28882 and then Is_Private_Descendant (Pack_Id)
28883 then
28884 -- A package instantiation does not need a Part_Of indicator when
28885 -- the related generic template has no visible state.
28887 if Ekind (Item_Id) = E_Package
28888 and then Is_Generic_Instance (Item_Id)
28889 and then not Has_Visible_State (Item_Id)
28890 then
28891 null;
28893 -- All other cases require Part_Of
28895 else
28896 Error_Msg_N
28897 ("indicator Part_Of is required in this context "
28898 & "(SPARK RM 7.2.6(3))", Item_Id);
28899 Error_Msg_Name_1 := Chars (Pack_Id);
28900 Error_Msg_N
28901 ("\& is declared in the visible part of private child "
28902 & "unit %", Item_Id);
28903 end if;
28904 end if;
28906 -- When the item appears in the private state space of a package, it
28907 -- must be a part of some state declared by the said package.
28909 else pragma Assert (Placement = Private_State_Space);
28911 -- The related package does not declare a state, the item cannot act
28912 -- as a Part_Of constituent.
28914 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
28915 null;
28917 -- A package instantiation does not need a Part_Of indicator when the
28918 -- related generic template has no visible state.
28920 elsif Ekind (Item_Id) = E_Package
28921 and then Is_Generic_Instance (Item_Id)
28922 and then not Has_Visible_State (Item_Id)
28923 then
28924 null;
28926 -- All other cases require Part_Of
28928 else
28929 Error_Msg_N
28930 ("indicator Part_Of is required in this context "
28931 & "(SPARK RM 7.2.6(2))", Item_Id);
28932 Error_Msg_Name_1 := Chars (Pack_Id);
28933 Error_Msg_N
28934 ("\& is declared in the private part of package %", Item_Id);
28935 end if;
28936 end if;
28937 end Check_Missing_Part_Of;
28939 ---------------------------------------------------
28940 -- Check_Postcondition_Use_In_Inlined_Subprogram --
28941 ---------------------------------------------------
28943 procedure Check_Postcondition_Use_In_Inlined_Subprogram
28944 (Prag : Node_Id;
28945 Spec_Id : Entity_Id)
28947 begin
28948 if Warn_On_Redundant_Constructs
28949 and then Has_Pragma_Inline_Always (Spec_Id)
28950 and then Assertions_Enabled
28951 then
28952 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
28954 if From_Aspect_Specification (Prag) then
28955 Error_Msg_NE
28956 ("aspect % not enforced on inlined subprogram &?r?",
28957 Corresponding_Aspect (Prag), Spec_Id);
28958 else
28959 Error_Msg_NE
28960 ("pragma % not enforced on inlined subprogram &?r?",
28961 Prag, Spec_Id);
28962 end if;
28963 end if;
28964 end Check_Postcondition_Use_In_Inlined_Subprogram;
28966 -------------------------------------
28967 -- Check_State_And_Constituent_Use --
28968 -------------------------------------
28970 procedure Check_State_And_Constituent_Use
28971 (States : Elist_Id;
28972 Constits : Elist_Id;
28973 Context : Node_Id)
28975 Constit_Elmt : Elmt_Id;
28976 Constit_Id : Entity_Id;
28977 State_Id : Entity_Id;
28979 begin
28980 -- Nothing to do if there are no states or constituents
28982 if No (States) or else No (Constits) then
28983 return;
28984 end if;
28986 -- Inspect the list of constituents and try to determine whether its
28987 -- encapsulating state is in list States.
28989 Constit_Elmt := First_Elmt (Constits);
28990 while Present (Constit_Elmt) loop
28991 Constit_Id := Node (Constit_Elmt);
28993 -- Determine whether the constituent is part of an encapsulating
28994 -- state that appears in the same context and if this is the case,
28995 -- emit an error (SPARK RM 7.2.6(7)).
28997 State_Id := Find_Encapsulating_State (States, Constit_Id);
28999 if Present (State_Id) then
29000 Error_Msg_Name_1 := Chars (Constit_Id);
29001 SPARK_Msg_NE
29002 ("cannot mention state & and its constituent % in the same "
29003 & "context", Context, State_Id);
29004 exit;
29005 end if;
29007 Next_Elmt (Constit_Elmt);
29008 end loop;
29009 end Check_State_And_Constituent_Use;
29011 ---------------------------------------------
29012 -- Collect_Inherited_Class_Wide_Conditions --
29013 ---------------------------------------------
29015 procedure Collect_Inherited_Class_Wide_Conditions (Subp : Entity_Id) is
29016 Parent_Subp : constant Entity_Id :=
29017 Ultimate_Alias (Overridden_Operation (Subp));
29018 -- The Overridden_Operation may itself be inherited and as such have no
29019 -- explicit contract.
29021 Prags : constant Node_Id := Contract (Parent_Subp);
29022 In_Spec_Expr : Boolean;
29023 Installed : Boolean;
29024 Prag : Node_Id;
29025 New_Prag : Node_Id;
29027 begin
29028 Installed := False;
29030 -- Iterate over the contract of the overridden subprogram to find all
29031 -- inherited class-wide pre- and postconditions.
29033 if Present (Prags) then
29034 Prag := Pre_Post_Conditions (Prags);
29036 while Present (Prag) loop
29037 if Nam_In (Pragma_Name_Unmapped (Prag),
29038 Name_Precondition, Name_Postcondition)
29039 and then Class_Present (Prag)
29040 then
29041 -- The generated pragma must be analyzed in the context of
29042 -- the subprogram, to make its formals visible. In addition,
29043 -- we must inhibit freezing and full analysis because the
29044 -- controlling type of the subprogram is not frozen yet, and
29045 -- may have further primitives.
29047 if not Installed then
29048 Installed := True;
29049 Push_Scope (Subp);
29050 Install_Formals (Subp);
29051 In_Spec_Expr := In_Spec_Expression;
29052 In_Spec_Expression := True;
29053 end if;
29055 New_Prag :=
29056 Build_Pragma_Check_Equivalent
29057 (Prag, Subp, Parent_Subp, Keep_Pragma_Id => True);
29059 Insert_After (Unit_Declaration_Node (Subp), New_Prag);
29060 Preanalyze (New_Prag);
29062 -- Prevent further analysis in subsequent processing of the
29063 -- current list of declarations
29065 Set_Analyzed (New_Prag);
29066 end if;
29068 Prag := Next_Pragma (Prag);
29069 end loop;
29071 if Installed then
29072 In_Spec_Expression := In_Spec_Expr;
29073 End_Scope;
29074 end if;
29075 end if;
29076 end Collect_Inherited_Class_Wide_Conditions;
29078 ---------------------------------------
29079 -- Collect_Subprogram_Inputs_Outputs --
29080 ---------------------------------------
29082 procedure Collect_Subprogram_Inputs_Outputs
29083 (Subp_Id : Entity_Id;
29084 Synthesize : Boolean := False;
29085 Subp_Inputs : in out Elist_Id;
29086 Subp_Outputs : in out Elist_Id;
29087 Global_Seen : out Boolean)
29089 procedure Collect_Dependency_Clause (Clause : Node_Id);
29090 -- Collect all relevant items from a dependency clause
29092 procedure Collect_Global_List
29093 (List : Node_Id;
29094 Mode : Name_Id := Name_Input);
29095 -- Collect all relevant items from a global list
29097 -------------------------------
29098 -- Collect_Dependency_Clause --
29099 -------------------------------
29101 procedure Collect_Dependency_Clause (Clause : Node_Id) is
29102 procedure Collect_Dependency_Item
29103 (Item : Node_Id;
29104 Is_Input : Boolean);
29105 -- Add an item to the proper subprogram input or output collection
29107 -----------------------------
29108 -- Collect_Dependency_Item --
29109 -----------------------------
29111 procedure Collect_Dependency_Item
29112 (Item : Node_Id;
29113 Is_Input : Boolean)
29115 Extra : Node_Id;
29117 begin
29118 -- Nothing to collect when the item is null
29120 if Nkind (Item) = N_Null then
29121 null;
29123 -- Ditto for attribute 'Result
29125 elsif Is_Attribute_Result (Item) then
29126 null;
29128 -- Multiple items appear as an aggregate
29130 elsif Nkind (Item) = N_Aggregate then
29131 Extra := First (Expressions (Item));
29132 while Present (Extra) loop
29133 Collect_Dependency_Item (Extra, Is_Input);
29134 Next (Extra);
29135 end loop;
29137 -- Otherwise this is a solitary item
29139 else
29140 if Is_Input then
29141 Append_New_Elmt (Item, Subp_Inputs);
29142 else
29143 Append_New_Elmt (Item, Subp_Outputs);
29144 end if;
29145 end if;
29146 end Collect_Dependency_Item;
29148 -- Start of processing for Collect_Dependency_Clause
29150 begin
29151 if Nkind (Clause) = N_Null then
29152 null;
29154 -- A dependency clause appears as component association
29156 elsif Nkind (Clause) = N_Component_Association then
29157 Collect_Dependency_Item
29158 (Item => Expression (Clause),
29159 Is_Input => True);
29161 Collect_Dependency_Item
29162 (Item => First (Choices (Clause)),
29163 Is_Input => False);
29165 -- To accommodate partial decoration of disabled SPARK features, this
29166 -- routine may be called with illegal input. If this is the case, do
29167 -- not raise Program_Error.
29169 else
29170 null;
29171 end if;
29172 end Collect_Dependency_Clause;
29174 -------------------------
29175 -- Collect_Global_List --
29176 -------------------------
29178 procedure Collect_Global_List
29179 (List : Node_Id;
29180 Mode : Name_Id := Name_Input)
29182 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
29183 -- Add an item to the proper subprogram input or output collection
29185 -------------------------
29186 -- Collect_Global_Item --
29187 -------------------------
29189 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
29190 begin
29191 if Nam_In (Mode, Name_In_Out, Name_Input) then
29192 Append_New_Elmt (Item, Subp_Inputs);
29193 end if;
29195 if Nam_In (Mode, Name_In_Out, Name_Output) then
29196 Append_New_Elmt (Item, Subp_Outputs);
29197 end if;
29198 end Collect_Global_Item;
29200 -- Local variables
29202 Assoc : Node_Id;
29203 Item : Node_Id;
29205 -- Start of processing for Collect_Global_List
29207 begin
29208 if Nkind (List) = N_Null then
29209 null;
29211 -- Single global item declaration
29213 elsif Nkind_In (List, N_Expanded_Name,
29214 N_Identifier,
29215 N_Selected_Component)
29216 then
29217 Collect_Global_Item (List, Mode);
29219 -- Simple global list or moded global list declaration
29221 elsif Nkind (List) = N_Aggregate then
29222 if Present (Expressions (List)) then
29223 Item := First (Expressions (List));
29224 while Present (Item) loop
29225 Collect_Global_Item (Item, Mode);
29226 Next (Item);
29227 end loop;
29229 else
29230 Assoc := First (Component_Associations (List));
29231 while Present (Assoc) loop
29232 Collect_Global_List
29233 (List => Expression (Assoc),
29234 Mode => Chars (First (Choices (Assoc))));
29235 Next (Assoc);
29236 end loop;
29237 end if;
29239 -- To accommodate partial decoration of disabled SPARK features, this
29240 -- routine may be called with illegal input. If this is the case, do
29241 -- not raise Program_Error.
29243 else
29244 null;
29245 end if;
29246 end Collect_Global_List;
29248 -- Local variables
29250 Clause : Node_Id;
29251 Clauses : Node_Id;
29252 Depends : Node_Id;
29253 Formal : Entity_Id;
29254 Global : Node_Id;
29255 Spec_Id : Entity_Id := Empty;
29256 Subp_Decl : Node_Id;
29257 Typ : Entity_Id;
29259 -- Start of processing for Collect_Subprogram_Inputs_Outputs
29261 begin
29262 Global_Seen := False;
29264 -- Process all formal parameters of entries, [generic] subprograms, and
29265 -- their bodies.
29267 if Ekind_In (Subp_Id, E_Entry,
29268 E_Entry_Family,
29269 E_Function,
29270 E_Generic_Function,
29271 E_Generic_Procedure,
29272 E_Procedure,
29273 E_Subprogram_Body)
29274 then
29275 Subp_Decl := Unit_Declaration_Node (Subp_Id);
29276 Spec_Id := Unique_Defining_Entity (Subp_Decl);
29278 -- Process all formal parameters
29280 Formal := First_Entity (Spec_Id);
29281 while Present (Formal) loop
29282 if Ekind_In (Formal, E_In_Out_Parameter, E_In_Parameter) then
29283 Append_New_Elmt (Formal, Subp_Inputs);
29284 end if;
29286 if Ekind_In (Formal, E_In_Out_Parameter, E_Out_Parameter) then
29287 Append_New_Elmt (Formal, Subp_Outputs);
29289 -- Out parameters can act as inputs when the related type is
29290 -- tagged, unconstrained array, unconstrained record, or record
29291 -- with unconstrained components.
29293 if Ekind (Formal) = E_Out_Parameter
29294 and then Is_Unconstrained_Or_Tagged_Item (Formal)
29295 then
29296 Append_New_Elmt (Formal, Subp_Inputs);
29297 end if;
29298 end if;
29300 Next_Entity (Formal);
29301 end loop;
29303 -- Otherwise the input denotes a task type, a task body, or the
29304 -- anonymous object created for a single task type.
29306 elsif Ekind_In (Subp_Id, E_Task_Type, E_Task_Body)
29307 or else Is_Single_Task_Object (Subp_Id)
29308 then
29309 Subp_Decl := Declaration_Node (Subp_Id);
29310 Spec_Id := Unique_Defining_Entity (Subp_Decl);
29311 end if;
29313 -- When processing an entry, subprogram or task body, look for pragmas
29314 -- Refined_Depends and Refined_Global as they specify the inputs and
29315 -- outputs.
29317 if Is_Entry_Body (Subp_Id)
29318 or else Ekind_In (Subp_Id, E_Subprogram_Body, E_Task_Body)
29319 then
29320 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
29321 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
29323 -- Subprogram declaration or stand-alone body case, look for pragmas
29324 -- Depends and Global
29326 else
29327 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
29328 Global := Get_Pragma (Spec_Id, Pragma_Global);
29329 end if;
29331 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
29332 -- because it provides finer granularity of inputs and outputs.
29334 if Present (Global) then
29335 Global_Seen := True;
29336 Collect_Global_List (Expression (Get_Argument (Global, Spec_Id)));
29338 -- When the related subprogram lacks pragma [Refined_]Global, fall back
29339 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
29340 -- the inputs and outputs from [Refined_]Depends.
29342 elsif Synthesize and then Present (Depends) then
29343 Clauses := Expression (Get_Argument (Depends, Spec_Id));
29345 -- Multiple dependency clauses appear as an aggregate
29347 if Nkind (Clauses) = N_Aggregate then
29348 Clause := First (Component_Associations (Clauses));
29349 while Present (Clause) loop
29350 Collect_Dependency_Clause (Clause);
29351 Next (Clause);
29352 end loop;
29354 -- Otherwise this is a single dependency clause
29356 else
29357 Collect_Dependency_Clause (Clauses);
29358 end if;
29359 end if;
29361 -- The current instance of a protected type acts as a formal parameter
29362 -- of mode IN for functions and IN OUT for entries and procedures
29363 -- (SPARK RM 6.1.4).
29365 if Ekind (Scope (Spec_Id)) = E_Protected_Type then
29366 Typ := Scope (Spec_Id);
29368 -- Use the anonymous object when the type is single protected
29370 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
29371 Typ := Anonymous_Object (Typ);
29372 end if;
29374 Append_New_Elmt (Typ, Subp_Inputs);
29376 if Ekind_In (Spec_Id, E_Entry, E_Entry_Family, E_Procedure) then
29377 Append_New_Elmt (Typ, Subp_Outputs);
29378 end if;
29380 -- The current instance of a task type acts as a formal parameter of
29381 -- mode IN OUT (SPARK RM 6.1.4).
29383 elsif Ekind (Spec_Id) = E_Task_Type then
29384 Typ := Spec_Id;
29386 -- Use the anonymous object when the type is single task
29388 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
29389 Typ := Anonymous_Object (Typ);
29390 end if;
29392 Append_New_Elmt (Typ, Subp_Inputs);
29393 Append_New_Elmt (Typ, Subp_Outputs);
29395 elsif Is_Single_Task_Object (Spec_Id) then
29396 Append_New_Elmt (Spec_Id, Subp_Inputs);
29397 Append_New_Elmt (Spec_Id, Subp_Outputs);
29398 end if;
29399 end Collect_Subprogram_Inputs_Outputs;
29401 ---------------------------
29402 -- Contract_Freeze_Error --
29403 ---------------------------
29405 procedure Contract_Freeze_Error
29406 (Contract_Id : Entity_Id;
29407 Freeze_Id : Entity_Id)
29409 begin
29410 Error_Msg_Name_1 := Chars (Contract_Id);
29411 Error_Msg_Sloc := Sloc (Freeze_Id);
29413 SPARK_Msg_NE
29414 ("body & declared # freezes the contract of%", Contract_Id, Freeze_Id);
29415 SPARK_Msg_N
29416 ("\all contractual items must be declared before body #", Contract_Id);
29417 end Contract_Freeze_Error;
29419 ---------------------------------
29420 -- Delay_Config_Pragma_Analyze --
29421 ---------------------------------
29423 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
29424 begin
29425 return Nam_In (Pragma_Name_Unmapped (N),
29426 Name_Interrupt_State, Name_Priority_Specific_Dispatching);
29427 end Delay_Config_Pragma_Analyze;
29429 -----------------------
29430 -- Duplication_Error --
29431 -----------------------
29433 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is
29434 Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag);
29435 Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev);
29437 begin
29438 Error_Msg_Sloc := Sloc (Prev);
29439 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
29441 -- Emit a precise message to distinguish between source pragmas and
29442 -- pragmas generated from aspects. The ordering of the two pragmas is
29443 -- the following:
29445 -- Prev -- ok
29446 -- Prag -- duplicate
29448 -- No error is emitted when both pragmas come from aspects because this
29449 -- is already detected by the general aspect analysis mechanism.
29451 if Prag_From_Asp and Prev_From_Asp then
29452 null;
29453 elsif Prag_From_Asp then
29454 Error_Msg_N ("aspect % duplicates pragma declared #", Prag);
29455 elsif Prev_From_Asp then
29456 Error_Msg_N ("pragma % duplicates aspect declared #", Prag);
29457 else
29458 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
29459 end if;
29460 end Duplication_Error;
29462 ------------------------------
29463 -- Find_Encapsulating_State --
29464 ------------------------------
29466 function Find_Encapsulating_State
29467 (States : Elist_Id;
29468 Constit_Id : Entity_Id) return Entity_Id
29470 State_Id : Entity_Id;
29472 begin
29473 -- Since a constituent may be part of a larger constituent set, climb
29474 -- the encapsulating state chain looking for a state that appears in
29475 -- States.
29477 State_Id := Encapsulating_State (Constit_Id);
29478 while Present (State_Id) loop
29479 if Contains (States, State_Id) then
29480 return State_Id;
29481 end if;
29483 State_Id := Encapsulating_State (State_Id);
29484 end loop;
29486 return Empty;
29487 end Find_Encapsulating_State;
29489 --------------------------
29490 -- Find_Related_Context --
29491 --------------------------
29493 function Find_Related_Context
29494 (Prag : Node_Id;
29495 Do_Checks : Boolean := False) return Node_Id
29497 Stmt : Node_Id;
29499 begin
29500 Stmt := Prev (Prag);
29501 while Present (Stmt) loop
29503 -- Skip prior pragmas, but check for duplicates
29505 if Nkind (Stmt) = N_Pragma then
29506 if Do_Checks
29507 and then Pragma_Name (Stmt) = Pragma_Name (Prag)
29508 then
29509 Duplication_Error
29510 (Prag => Prag,
29511 Prev => Stmt);
29512 end if;
29514 -- Skip internally generated code
29516 elsif not Comes_From_Source (Stmt) then
29518 -- The anonymous object created for a single concurrent type is a
29519 -- suitable context.
29521 if Nkind (Stmt) = N_Object_Declaration
29522 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
29523 then
29524 return Stmt;
29525 end if;
29527 -- Return the current source construct
29529 else
29530 return Stmt;
29531 end if;
29533 Prev (Stmt);
29534 end loop;
29536 return Empty;
29537 end Find_Related_Context;
29539 --------------------------------------
29540 -- Find_Related_Declaration_Or_Body --
29541 --------------------------------------
29543 function Find_Related_Declaration_Or_Body
29544 (Prag : Node_Id;
29545 Do_Checks : Boolean := False) return Node_Id
29547 Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
29549 procedure Expression_Function_Error;
29550 -- Emit an error concerning pragma Prag that illegaly applies to an
29551 -- expression function.
29553 -------------------------------
29554 -- Expression_Function_Error --
29555 -------------------------------
29557 procedure Expression_Function_Error is
29558 begin
29559 Error_Msg_Name_1 := Prag_Nam;
29561 -- Emit a precise message to distinguish between source pragmas and
29562 -- pragmas generated from aspects.
29564 if From_Aspect_Specification (Prag) then
29565 Error_Msg_N
29566 ("aspect % cannot apply to a stand alone expression function",
29567 Prag);
29568 else
29569 Error_Msg_N
29570 ("pragma % cannot apply to a stand alone expression function",
29571 Prag);
29572 end if;
29573 end Expression_Function_Error;
29575 -- Local variables
29577 Context : constant Node_Id := Parent (Prag);
29578 Stmt : Node_Id;
29580 Look_For_Body : constant Boolean :=
29581 Nam_In (Prag_Nam, Name_Refined_Depends,
29582 Name_Refined_Global,
29583 Name_Refined_Post,
29584 Name_Refined_State);
29585 -- Refinement pragmas must be associated with a subprogram body [stub]
29587 -- Start of processing for Find_Related_Declaration_Or_Body
29589 begin
29590 Stmt := Prev (Prag);
29591 while Present (Stmt) loop
29593 -- Skip prior pragmas, but check for duplicates. Pragmas produced
29594 -- by splitting a complex pre/postcondition are not considered to
29595 -- be duplicates.
29597 if Nkind (Stmt) = N_Pragma then
29598 if Do_Checks
29599 and then not Split_PPC (Stmt)
29600 and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam
29601 then
29602 Duplication_Error
29603 (Prag => Prag,
29604 Prev => Stmt);
29605 end if;
29607 -- Emit an error when a refinement pragma appears on an expression
29608 -- function without a completion.
29610 elsif Do_Checks
29611 and then Look_For_Body
29612 and then Nkind (Stmt) = N_Subprogram_Declaration
29613 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
29614 and then not Has_Completion (Defining_Entity (Stmt))
29615 then
29616 Expression_Function_Error;
29617 return Empty;
29619 -- The refinement pragma applies to a subprogram body stub
29621 elsif Look_For_Body
29622 and then Nkind (Stmt) = N_Subprogram_Body_Stub
29623 then
29624 return Stmt;
29626 -- Skip internally generated code
29628 elsif not Comes_From_Source (Stmt) then
29630 -- The anonymous object created for a single concurrent type is a
29631 -- suitable context.
29633 if Nkind (Stmt) = N_Object_Declaration
29634 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
29635 then
29636 return Stmt;
29638 elsif Nkind (Stmt) = N_Subprogram_Declaration then
29640 -- The subprogram declaration is an internally generated spec
29641 -- for an expression function.
29643 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
29644 return Stmt;
29646 -- The subprogram declaration is an internally generated spec
29647 -- for a stand-alone subrogram body declared inside a protected
29648 -- body.
29650 elsif Present (Corresponding_Body (Stmt))
29651 and then Comes_From_Source (Corresponding_Body (Stmt))
29652 and then Is_Protected_Type (Current_Scope)
29653 then
29654 return Stmt;
29656 -- The subprogram is actually an instance housed within an
29657 -- anonymous wrapper package.
29659 elsif Present (Generic_Parent (Specification (Stmt))) then
29660 return Stmt;
29661 end if;
29662 end if;
29664 -- Return the current construct which is either a subprogram body,
29665 -- a subprogram declaration or is illegal.
29667 else
29668 return Stmt;
29669 end if;
29671 Prev (Stmt);
29672 end loop;
29674 -- If we fall through, then the pragma was either the first declaration
29675 -- or it was preceded by other pragmas and no source constructs.
29677 -- The pragma is associated with a library-level subprogram
29679 if Nkind (Context) = N_Compilation_Unit_Aux then
29680 return Unit (Parent (Context));
29682 -- The pragma appears inside the declarations of an entry body
29684 elsif Nkind (Context) = N_Entry_Body then
29685 return Context;
29687 -- The pragma appears inside the statements of a subprogram body. This
29688 -- placement is the result of subprogram contract expansion.
29690 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
29691 return Parent (Context);
29693 -- The pragma appears inside the declarative part of a package body
29695 elsif Nkind (Context) = N_Package_Body then
29696 return Context;
29698 -- The pragma appears inside the declarative part of a subprogram body
29700 elsif Nkind (Context) = N_Subprogram_Body then
29701 return Context;
29703 -- The pragma appears inside the declarative part of a task body
29705 elsif Nkind (Context) = N_Task_Body then
29706 return Context;
29708 -- The pragma appears inside the visible part of a package specification
29710 elsif Nkind (Context) = N_Package_Specification then
29711 return Parent (Context);
29713 -- The pragma is a byproduct of aspect expansion, return the related
29714 -- context of the original aspect. This case has a lower priority as
29715 -- the above circuitry pinpoints precisely the related context.
29717 elsif Present (Corresponding_Aspect (Prag)) then
29718 return Parent (Corresponding_Aspect (Prag));
29720 -- No candidate subprogram [body] found
29722 else
29723 return Empty;
29724 end if;
29725 end Find_Related_Declaration_Or_Body;
29727 ----------------------------------
29728 -- Find_Related_Package_Or_Body --
29729 ----------------------------------
29731 function Find_Related_Package_Or_Body
29732 (Prag : Node_Id;
29733 Do_Checks : Boolean := False) return Node_Id
29735 Context : constant Node_Id := Parent (Prag);
29736 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
29737 Stmt : Node_Id;
29739 begin
29740 Stmt := Prev (Prag);
29741 while Present (Stmt) loop
29743 -- Skip prior pragmas, but check for duplicates
29745 if Nkind (Stmt) = N_Pragma then
29746 if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then
29747 Duplication_Error
29748 (Prag => Prag,
29749 Prev => Stmt);
29750 end if;
29752 -- Skip internally generated code
29754 elsif not Comes_From_Source (Stmt) then
29755 if Nkind (Stmt) = N_Subprogram_Declaration then
29757 -- The subprogram declaration is an internally generated spec
29758 -- for an expression function.
29760 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
29761 return Stmt;
29763 -- The subprogram is actually an instance housed within an
29764 -- anonymous wrapper package.
29766 elsif Present (Generic_Parent (Specification (Stmt))) then
29767 return Stmt;
29768 end if;
29769 end if;
29771 -- Return the current source construct which is illegal
29773 else
29774 return Stmt;
29775 end if;
29777 Prev (Stmt);
29778 end loop;
29780 -- If we fall through, then the pragma was either the first declaration
29781 -- or it was preceded by other pragmas and no source constructs.
29783 -- The pragma is associated with a package. The immediate context in
29784 -- this case is the specification of the package.
29786 if Nkind (Context) = N_Package_Specification then
29787 return Parent (Context);
29789 -- The pragma appears in the declarations of a package body
29791 elsif Nkind (Context) = N_Package_Body then
29792 return Context;
29794 -- The pragma appears in the statements of a package body
29796 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
29797 and then Nkind (Parent (Context)) = N_Package_Body
29798 then
29799 return Parent (Context);
29801 -- The pragma is a byproduct of aspect expansion, return the related
29802 -- context of the original aspect. This case has a lower priority as
29803 -- the above circuitry pinpoints precisely the related context.
29805 elsif Present (Corresponding_Aspect (Prag)) then
29806 return Parent (Corresponding_Aspect (Prag));
29808 -- No candidate package [body] found
29810 else
29811 return Empty;
29812 end if;
29813 end Find_Related_Package_Or_Body;
29815 ------------------
29816 -- Get_Argument --
29817 ------------------
29819 function Get_Argument
29820 (Prag : Node_Id;
29821 Context_Id : Entity_Id := Empty) return Node_Id
29823 Args : constant List_Id := Pragma_Argument_Associations (Prag);
29825 begin
29826 -- Use the expression of the original aspect when compiling for ASIS or
29827 -- when analyzing the template of a generic unit. In both cases the
29828 -- aspect's tree must be decorated to allow for ASIS queries or to save
29829 -- the global references in the generic context.
29831 if From_Aspect_Specification (Prag)
29832 and then (ASIS_Mode or else (Present (Context_Id)
29833 and then Is_Generic_Unit (Context_Id)))
29834 then
29835 return Corresponding_Aspect (Prag);
29837 -- Otherwise use the expression of the pragma
29839 elsif Present (Args) then
29840 return First (Args);
29842 else
29843 return Empty;
29844 end if;
29845 end Get_Argument;
29847 -------------------------
29848 -- Get_Base_Subprogram --
29849 -------------------------
29851 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
29852 begin
29853 -- Follow subprogram renaming chain
29855 if Is_Subprogram (Def_Id)
29856 and then Nkind (Parent (Declaration_Node (Def_Id))) =
29857 N_Subprogram_Renaming_Declaration
29858 and then Present (Alias (Def_Id))
29859 then
29860 return Alias (Def_Id);
29861 else
29862 return Def_Id;
29863 end if;
29864 end Get_Base_Subprogram;
29866 -----------------------
29867 -- Get_SPARK_Mode_Type --
29868 -----------------------
29870 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
29871 begin
29872 if N = Name_On then
29873 return On;
29874 elsif N = Name_Off then
29875 return Off;
29877 -- Any other argument is illegal. Assume that no SPARK mode applies to
29878 -- avoid potential cascaded errors.
29880 else
29881 return None;
29882 end if;
29883 end Get_SPARK_Mode_Type;
29885 ------------------------------------
29886 -- Get_SPARK_Mode_From_Annotation --
29887 ------------------------------------
29889 function Get_SPARK_Mode_From_Annotation
29890 (N : Node_Id) return SPARK_Mode_Type
29892 Mode : Node_Id;
29894 begin
29895 if Nkind (N) = N_Aspect_Specification then
29896 Mode := Expression (N);
29898 else pragma Assert (Nkind (N) = N_Pragma);
29899 Mode := First (Pragma_Argument_Associations (N));
29901 if Present (Mode) then
29902 Mode := Get_Pragma_Arg (Mode);
29903 end if;
29904 end if;
29906 -- Aspect or pragma SPARK_Mode specifies an explicit mode
29908 if Present (Mode) then
29909 if Nkind (Mode) = N_Identifier then
29910 return Get_SPARK_Mode_Type (Chars (Mode));
29912 -- In case of a malformed aspect or pragma, return the default None
29914 else
29915 return None;
29916 end if;
29918 -- Otherwise the lack of an expression defaults SPARK_Mode to On
29920 else
29921 return On;
29922 end if;
29923 end Get_SPARK_Mode_From_Annotation;
29925 ---------------------------
29926 -- Has_Extra_Parentheses --
29927 ---------------------------
29929 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
29930 Expr : Node_Id;
29932 begin
29933 -- The aggregate should not have an expression list because a clause
29934 -- is always interpreted as a component association. The only way an
29935 -- expression list can sneak in is by adding extra parentheses around
29936 -- the individual clauses:
29938 -- Depends (Output => Input) -- proper form
29939 -- Depends ((Output => Input)) -- extra parentheses
29941 -- Since the extra parentheses are not allowed by the syntax of the
29942 -- pragma, flag them now to avoid emitting misleading errors down the
29943 -- line.
29945 if Nkind (Clause) = N_Aggregate
29946 and then Present (Expressions (Clause))
29947 then
29948 Expr := First (Expressions (Clause));
29949 while Present (Expr) loop
29951 -- A dependency clause surrounded by extra parentheses appears
29952 -- as an aggregate of component associations with an optional
29953 -- Paren_Count set.
29955 if Nkind (Expr) = N_Aggregate
29956 and then Present (Component_Associations (Expr))
29957 then
29958 SPARK_Msg_N
29959 ("dependency clause contains extra parentheses", Expr);
29961 -- Otherwise the expression is a malformed construct
29963 else
29964 SPARK_Msg_N ("malformed dependency clause", Expr);
29965 end if;
29967 Next (Expr);
29968 end loop;
29970 return True;
29971 end if;
29973 return False;
29974 end Has_Extra_Parentheses;
29976 ----------------
29977 -- Initialize --
29978 ----------------
29980 procedure Initialize is
29981 begin
29982 Externals.Init;
29983 end Initialize;
29985 --------
29986 -- ip --
29987 --------
29989 procedure ip is
29990 begin
29991 Dummy := Dummy + 1;
29992 end ip;
29994 -----------------------------
29995 -- Is_Config_Static_String --
29996 -----------------------------
29998 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
30000 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
30001 -- This is an internal recursive function that is just like the outer
30002 -- function except that it adds the string to the name buffer rather
30003 -- than placing the string in the name buffer.
30005 ------------------------------
30006 -- Add_Config_Static_String --
30007 ------------------------------
30009 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
30010 N : Node_Id;
30011 C : Char_Code;
30013 begin
30014 N := Arg;
30016 if Nkind (N) = N_Op_Concat then
30017 if Add_Config_Static_String (Left_Opnd (N)) then
30018 N := Right_Opnd (N);
30019 else
30020 return False;
30021 end if;
30022 end if;
30024 if Nkind (N) /= N_String_Literal then
30025 Error_Msg_N ("string literal expected for pragma argument", N);
30026 return False;
30028 else
30029 for J in 1 .. String_Length (Strval (N)) loop
30030 C := Get_String_Char (Strval (N), J);
30032 if not In_Character_Range (C) then
30033 Error_Msg
30034 ("string literal contains invalid wide character",
30035 Sloc (N) + 1 + Source_Ptr (J));
30036 return False;
30037 end if;
30039 Add_Char_To_Name_Buffer (Get_Character (C));
30040 end loop;
30041 end if;
30043 return True;
30044 end Add_Config_Static_String;
30046 -- Start of processing for Is_Config_Static_String
30048 begin
30049 Name_Len := 0;
30051 return Add_Config_Static_String (Arg);
30052 end Is_Config_Static_String;
30054 -------------------------------
30055 -- Is_Elaboration_SPARK_Mode --
30056 -------------------------------
30058 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
30059 begin
30060 pragma Assert
30061 (Nkind (N) = N_Pragma
30062 and then Pragma_Name (N) = Name_SPARK_Mode
30063 and then Is_List_Member (N));
30065 -- Pragma SPARK_Mode affects the elaboration of a package body when it
30066 -- appears in the statement part of the body.
30068 return
30069 Present (Parent (N))
30070 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
30071 and then List_Containing (N) = Statements (Parent (N))
30072 and then Present (Parent (Parent (N)))
30073 and then Nkind (Parent (Parent (N))) = N_Package_Body;
30074 end Is_Elaboration_SPARK_Mode;
30076 -----------------------
30077 -- Is_Enabled_Pragma --
30078 -----------------------
30080 function Is_Enabled_Pragma (Prag : Node_Id) return Boolean is
30081 Arg : Node_Id;
30083 begin
30084 if Present (Prag) then
30085 Arg := First (Pragma_Argument_Associations (Prag));
30087 if Present (Arg) then
30088 return Is_True (Expr_Value (Get_Pragma_Arg (Arg)));
30090 -- The lack of a Boolean argument automatically enables the pragma
30092 else
30093 return True;
30094 end if;
30096 -- The pragma is missing, therefore it is not enabled
30098 else
30099 return False;
30100 end if;
30101 end Is_Enabled_Pragma;
30103 -----------------------------------------
30104 -- Is_Non_Significant_Pragma_Reference --
30105 -----------------------------------------
30107 -- This function makes use of the following static table which indicates
30108 -- whether appearance of some name in a given pragma is to be considered
30109 -- as a reference for the purposes of warnings about unreferenced objects.
30111 -- -1 indicates that appearence in any argument is significant
30112 -- 0 indicates that appearance in any argument is not significant
30113 -- +n indicates that appearance as argument n is significant, but all
30114 -- other arguments are not significant
30115 -- 9n arguments from n on are significant, before n insignificant
30117 Sig_Flags : constant array (Pragma_Id) of Int :=
30118 (Pragma_Abort_Defer => -1,
30119 Pragma_Abstract_State => -1,
30120 Pragma_Ada_83 => -1,
30121 Pragma_Ada_95 => -1,
30122 Pragma_Ada_05 => -1,
30123 Pragma_Ada_2005 => -1,
30124 Pragma_Ada_12 => -1,
30125 Pragma_Ada_2012 => -1,
30126 Pragma_Ada_2020 => -1,
30127 Pragma_All_Calls_Remote => -1,
30128 Pragma_Allow_Integer_Address => -1,
30129 Pragma_Annotate => 93,
30130 Pragma_Assert => -1,
30131 Pragma_Assert_And_Cut => -1,
30132 Pragma_Assertion_Policy => 0,
30133 Pragma_Assume => -1,
30134 Pragma_Assume_No_Invalid_Values => 0,
30135 Pragma_Async_Readers => 0,
30136 Pragma_Async_Writers => 0,
30137 Pragma_Asynchronous => 0,
30138 Pragma_Atomic => 0,
30139 Pragma_Atomic_Components => 0,
30140 Pragma_Attach_Handler => -1,
30141 Pragma_Attribute_Definition => 92,
30142 Pragma_Check => -1,
30143 Pragma_Check_Float_Overflow => 0,
30144 Pragma_Check_Name => 0,
30145 Pragma_Check_Policy => 0,
30146 Pragma_CPP_Class => 0,
30147 Pragma_CPP_Constructor => 0,
30148 Pragma_CPP_Virtual => 0,
30149 Pragma_CPP_Vtable => 0,
30150 Pragma_CPU => -1,
30151 Pragma_C_Pass_By_Copy => 0,
30152 Pragma_Comment => -1,
30153 Pragma_Common_Object => 0,
30154 Pragma_Compile_Time_Error => -1,
30155 Pragma_Compile_Time_Warning => -1,
30156 Pragma_Compiler_Unit => -1,
30157 Pragma_Compiler_Unit_Warning => -1,
30158 Pragma_Complete_Representation => 0,
30159 Pragma_Complex_Representation => 0,
30160 Pragma_Component_Alignment => 0,
30161 Pragma_Constant_After_Elaboration => 0,
30162 Pragma_Contract_Cases => -1,
30163 Pragma_Controlled => 0,
30164 Pragma_Convention => 0,
30165 Pragma_Convention_Identifier => 0,
30166 Pragma_Deadline_Floor => -1,
30167 Pragma_Debug => -1,
30168 Pragma_Debug_Policy => 0,
30169 Pragma_Detect_Blocking => 0,
30170 Pragma_Default_Initial_Condition => -1,
30171 Pragma_Default_Scalar_Storage_Order => 0,
30172 Pragma_Default_Storage_Pool => 0,
30173 Pragma_Depends => -1,
30174 Pragma_Disable_Atomic_Synchronization => 0,
30175 Pragma_Discard_Names => 0,
30176 Pragma_Dispatching_Domain => -1,
30177 Pragma_Effective_Reads => 0,
30178 Pragma_Effective_Writes => 0,
30179 Pragma_Elaborate => 0,
30180 Pragma_Elaborate_All => 0,
30181 Pragma_Elaborate_Body => 0,
30182 Pragma_Elaboration_Checks => 0,
30183 Pragma_Eliminate => 0,
30184 Pragma_Enable_Atomic_Synchronization => 0,
30185 Pragma_Export => -1,
30186 Pragma_Export_Function => -1,
30187 Pragma_Export_Object => -1,
30188 Pragma_Export_Procedure => -1,
30189 Pragma_Export_Value => -1,
30190 Pragma_Export_Valued_Procedure => -1,
30191 Pragma_Extend_System => -1,
30192 Pragma_Extensions_Allowed => 0,
30193 Pragma_Extensions_Visible => 0,
30194 Pragma_External => -1,
30195 Pragma_Favor_Top_Level => 0,
30196 Pragma_External_Name_Casing => 0,
30197 Pragma_Fast_Math => 0,
30198 Pragma_Finalize_Storage_Only => 0,
30199 Pragma_Ghost => 0,
30200 Pragma_Global => -1,
30201 Pragma_Ident => -1,
30202 Pragma_Ignore_Pragma => 0,
30203 Pragma_Implementation_Defined => -1,
30204 Pragma_Implemented => -1,
30205 Pragma_Implicit_Packing => 0,
30206 Pragma_Import => 93,
30207 Pragma_Import_Function => 0,
30208 Pragma_Import_Object => 0,
30209 Pragma_Import_Procedure => 0,
30210 Pragma_Import_Valued_Procedure => 0,
30211 Pragma_Independent => 0,
30212 Pragma_Independent_Components => 0,
30213 Pragma_Initial_Condition => -1,
30214 Pragma_Initialize_Scalars => 0,
30215 Pragma_Initializes => -1,
30216 Pragma_Inline => 0,
30217 Pragma_Inline_Always => 0,
30218 Pragma_Inline_Generic => 0,
30219 Pragma_Inspection_Point => -1,
30220 Pragma_Interface => 92,
30221 Pragma_Interface_Name => 0,
30222 Pragma_Interrupt_Handler => -1,
30223 Pragma_Interrupt_Priority => -1,
30224 Pragma_Interrupt_State => -1,
30225 Pragma_Invariant => -1,
30226 Pragma_Keep_Names => 0,
30227 Pragma_License => 0,
30228 Pragma_Link_With => -1,
30229 Pragma_Linker_Alias => -1,
30230 Pragma_Linker_Constructor => -1,
30231 Pragma_Linker_Destructor => -1,
30232 Pragma_Linker_Options => -1,
30233 Pragma_Linker_Section => -1,
30234 Pragma_List => 0,
30235 Pragma_Lock_Free => 0,
30236 Pragma_Locking_Policy => 0,
30237 Pragma_Loop_Invariant => -1,
30238 Pragma_Loop_Optimize => 0,
30239 Pragma_Loop_Variant => -1,
30240 Pragma_Machine_Attribute => -1,
30241 Pragma_Main => -1,
30242 Pragma_Main_Storage => -1,
30243 Pragma_Max_Entry_Queue_Depth => 0,
30244 Pragma_Max_Queue_Length => 0,
30245 Pragma_Memory_Size => 0,
30246 Pragma_No_Return => 0,
30247 Pragma_No_Body => 0,
30248 Pragma_No_Component_Reordering => -1,
30249 Pragma_No_Elaboration_Code_All => 0,
30250 Pragma_No_Heap_Finalization => 0,
30251 Pragma_No_Inline => 0,
30252 Pragma_No_Run_Time => -1,
30253 Pragma_No_Strict_Aliasing => -1,
30254 Pragma_No_Tagged_Streams => 0,
30255 Pragma_Normalize_Scalars => 0,
30256 Pragma_Obsolescent => 0,
30257 Pragma_Optimize => 0,
30258 Pragma_Optimize_Alignment => 0,
30259 Pragma_Overflow_Mode => 0,
30260 Pragma_Overriding_Renamings => 0,
30261 Pragma_Ordered => 0,
30262 Pragma_Pack => 0,
30263 Pragma_Page => 0,
30264 Pragma_Part_Of => 0,
30265 Pragma_Partition_Elaboration_Policy => 0,
30266 Pragma_Passive => 0,
30267 Pragma_Persistent_BSS => 0,
30268 Pragma_Polling => 0,
30269 Pragma_Prefix_Exception_Messages => 0,
30270 Pragma_Post => -1,
30271 Pragma_Postcondition => -1,
30272 Pragma_Post_Class => -1,
30273 Pragma_Pre => -1,
30274 Pragma_Precondition => -1,
30275 Pragma_Predicate => -1,
30276 Pragma_Predicate_Failure => -1,
30277 Pragma_Preelaborable_Initialization => -1,
30278 Pragma_Preelaborate => 0,
30279 Pragma_Pre_Class => -1,
30280 Pragma_Priority => -1,
30281 Pragma_Priority_Specific_Dispatching => 0,
30282 Pragma_Profile => 0,
30283 Pragma_Profile_Warnings => 0,
30284 Pragma_Propagate_Exceptions => 0,
30285 Pragma_Provide_Shift_Operators => 0,
30286 Pragma_Psect_Object => 0,
30287 Pragma_Pure => 0,
30288 Pragma_Pure_Function => 0,
30289 Pragma_Queuing_Policy => 0,
30290 Pragma_Rational => 0,
30291 Pragma_Ravenscar => 0,
30292 Pragma_Refined_Depends => -1,
30293 Pragma_Refined_Global => -1,
30294 Pragma_Refined_Post => -1,
30295 Pragma_Refined_State => -1,
30296 Pragma_Relative_Deadline => 0,
30297 Pragma_Rename_Pragma => 0,
30298 Pragma_Remote_Access_Type => -1,
30299 Pragma_Remote_Call_Interface => -1,
30300 Pragma_Remote_Types => -1,
30301 Pragma_Restricted_Run_Time => 0,
30302 Pragma_Restriction_Warnings => 0,
30303 Pragma_Restrictions => 0,
30304 Pragma_Reviewable => -1,
30305 Pragma_Secondary_Stack_Size => -1,
30306 Pragma_Short_Circuit_And_Or => 0,
30307 Pragma_Share_Generic => 0,
30308 Pragma_Shared => 0,
30309 Pragma_Shared_Passive => 0,
30310 Pragma_Short_Descriptors => 0,
30311 Pragma_Simple_Storage_Pool_Type => 0,
30312 Pragma_Source_File_Name => 0,
30313 Pragma_Source_File_Name_Project => 0,
30314 Pragma_Source_Reference => 0,
30315 Pragma_SPARK_Mode => 0,
30316 Pragma_Storage_Size => -1,
30317 Pragma_Storage_Unit => 0,
30318 Pragma_Static_Elaboration_Desired => 0,
30319 Pragma_Stream_Convert => 0,
30320 Pragma_Style_Checks => 0,
30321 Pragma_Subtitle => 0,
30322 Pragma_Suppress => 0,
30323 Pragma_Suppress_Exception_Locations => 0,
30324 Pragma_Suppress_All => 0,
30325 Pragma_Suppress_Debug_Info => 0,
30326 Pragma_Suppress_Initialization => 0,
30327 Pragma_System_Name => 0,
30328 Pragma_Task_Dispatching_Policy => 0,
30329 Pragma_Task_Info => -1,
30330 Pragma_Task_Name => -1,
30331 Pragma_Task_Storage => -1,
30332 Pragma_Test_Case => -1,
30333 Pragma_Thread_Local_Storage => -1,
30334 Pragma_Time_Slice => -1,
30335 Pragma_Title => 0,
30336 Pragma_Type_Invariant => -1,
30337 Pragma_Type_Invariant_Class => -1,
30338 Pragma_Unchecked_Union => 0,
30339 Pragma_Unevaluated_Use_Of_Old => 0,
30340 Pragma_Unimplemented_Unit => 0,
30341 Pragma_Universal_Aliasing => 0,
30342 Pragma_Universal_Data => 0,
30343 Pragma_Unmodified => 0,
30344 Pragma_Unreferenced => 0,
30345 Pragma_Unreferenced_Objects => 0,
30346 Pragma_Unreserve_All_Interrupts => 0,
30347 Pragma_Unsuppress => 0,
30348 Pragma_Unused => 0,
30349 Pragma_Use_VADS_Size => 0,
30350 Pragma_Validity_Checks => 0,
30351 Pragma_Volatile => 0,
30352 Pragma_Volatile_Components => 0,
30353 Pragma_Volatile_Full_Access => 0,
30354 Pragma_Volatile_Function => 0,
30355 Pragma_Warning_As_Error => 0,
30356 Pragma_Warnings => 0,
30357 Pragma_Weak_External => 0,
30358 Pragma_Wide_Character_Encoding => 0,
30359 Unknown_Pragma => 0);
30361 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
30362 Id : Pragma_Id;
30363 P : Node_Id;
30364 C : Int;
30365 AN : Nat;
30367 function Arg_No return Nat;
30368 -- Returns an integer showing what argument we are in. A value of
30369 -- zero means we are not in any of the arguments.
30371 ------------
30372 -- Arg_No --
30373 ------------
30375 function Arg_No return Nat is
30376 A : Node_Id;
30377 N : Nat;
30379 begin
30380 A := First (Pragma_Argument_Associations (Parent (P)));
30381 N := 1;
30382 loop
30383 if No (A) then
30384 return 0;
30385 elsif A = P then
30386 return N;
30387 end if;
30389 Next (A);
30390 N := N + 1;
30391 end loop;
30392 end Arg_No;
30394 -- Start of processing for Non_Significant_Pragma_Reference
30396 begin
30397 P := Parent (N);
30399 if Nkind (P) /= N_Pragma_Argument_Association then
30400 return False;
30402 else
30403 Id := Get_Pragma_Id (Parent (P));
30404 C := Sig_Flags (Id);
30405 AN := Arg_No;
30407 if AN = 0 then
30408 return False;
30409 end if;
30411 case C is
30412 when -1 =>
30413 return False;
30415 when 0 =>
30416 return True;
30418 when 92 .. 99 =>
30419 return AN < (C - 90);
30421 when others =>
30422 return AN /= C;
30423 end case;
30424 end if;
30425 end Is_Non_Significant_Pragma_Reference;
30427 ------------------------------
30428 -- Is_Pragma_String_Literal --
30429 ------------------------------
30431 -- This function returns true if the corresponding pragma argument is a
30432 -- static string expression. These are the only cases in which string
30433 -- literals can appear as pragma arguments. We also allow a string literal
30434 -- as the first argument to pragma Assert (although it will of course
30435 -- always generate a type error).
30437 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
30438 Pragn : constant Node_Id := Parent (Par);
30439 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
30440 Pname : constant Name_Id := Pragma_Name (Pragn);
30441 Argn : Natural;
30442 N : Node_Id;
30444 begin
30445 Argn := 1;
30446 N := First (Assoc);
30447 loop
30448 exit when N = Par;
30449 Argn := Argn + 1;
30450 Next (N);
30451 end loop;
30453 if Pname = Name_Assert then
30454 return True;
30456 elsif Pname = Name_Export then
30457 return Argn > 2;
30459 elsif Pname = Name_Ident then
30460 return Argn = 1;
30462 elsif Pname = Name_Import then
30463 return Argn > 2;
30465 elsif Pname = Name_Interface_Name then
30466 return Argn > 1;
30468 elsif Pname = Name_Linker_Alias then
30469 return Argn = 2;
30471 elsif Pname = Name_Linker_Section then
30472 return Argn = 2;
30474 elsif Pname = Name_Machine_Attribute then
30475 return Argn = 2;
30477 elsif Pname = Name_Source_File_Name then
30478 return True;
30480 elsif Pname = Name_Source_Reference then
30481 return Argn = 2;
30483 elsif Pname = Name_Title then
30484 return True;
30486 elsif Pname = Name_Subtitle then
30487 return True;
30489 else
30490 return False;
30491 end if;
30492 end Is_Pragma_String_Literal;
30494 ---------------------------
30495 -- Is_Private_SPARK_Mode --
30496 ---------------------------
30498 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
30499 begin
30500 pragma Assert
30501 (Nkind (N) = N_Pragma
30502 and then Pragma_Name (N) = Name_SPARK_Mode
30503 and then Is_List_Member (N));
30505 -- For pragma SPARK_Mode to be private, it has to appear in the private
30506 -- declarations of a package.
30508 return
30509 Present (Parent (N))
30510 and then Nkind (Parent (N)) = N_Package_Specification
30511 and then List_Containing (N) = Private_Declarations (Parent (N));
30512 end Is_Private_SPARK_Mode;
30514 -------------------------------------
30515 -- Is_Unconstrained_Or_Tagged_Item --
30516 -------------------------------------
30518 function Is_Unconstrained_Or_Tagged_Item
30519 (Item : Entity_Id) return Boolean
30521 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
30522 -- Determine whether record type Typ has at least one unconstrained
30523 -- component.
30525 ---------------------------------
30526 -- Has_Unconstrained_Component --
30527 ---------------------------------
30529 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
30530 Comp : Entity_Id;
30532 begin
30533 Comp := First_Component (Typ);
30534 while Present (Comp) loop
30535 if Is_Unconstrained_Or_Tagged_Item (Comp) then
30536 return True;
30537 end if;
30539 Next_Component (Comp);
30540 end loop;
30542 return False;
30543 end Has_Unconstrained_Component;
30545 -- Local variables
30547 Typ : constant Entity_Id := Etype (Item);
30549 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
30551 begin
30552 if Is_Tagged_Type (Typ) then
30553 return True;
30555 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
30556 return True;
30558 elsif Is_Record_Type (Typ) then
30559 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
30560 return True;
30561 else
30562 return Has_Unconstrained_Component (Typ);
30563 end if;
30565 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
30566 return True;
30568 else
30569 return False;
30570 end if;
30571 end Is_Unconstrained_Or_Tagged_Item;
30573 -----------------------------
30574 -- Is_Valid_Assertion_Kind --
30575 -----------------------------
30577 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
30578 begin
30579 case Nam is
30580 when
30581 -- RM defined
30583 Name_Assert
30584 | Name_Assertion_Policy
30585 | Name_Static_Predicate
30586 | Name_Dynamic_Predicate
30587 | Name_Pre
30588 | Name_uPre
30589 | Name_Post
30590 | Name_uPost
30591 | Name_Type_Invariant
30592 | Name_uType_Invariant
30594 -- Impl defined
30596 | Name_Assert_And_Cut
30597 | Name_Assume
30598 | Name_Contract_Cases
30599 | Name_Debug
30600 | Name_Default_Initial_Condition
30601 | Name_Ghost
30602 | Name_Initial_Condition
30603 | Name_Invariant
30604 | Name_uInvariant
30605 | Name_Loop_Invariant
30606 | Name_Loop_Variant
30607 | Name_Postcondition
30608 | Name_Precondition
30609 | Name_Predicate
30610 | Name_Refined_Post
30611 | Name_Statement_Assertions
30613 return True;
30615 when others =>
30616 return False;
30617 end case;
30618 end Is_Valid_Assertion_Kind;
30620 --------------------------------------
30621 -- Process_Compilation_Unit_Pragmas --
30622 --------------------------------------
30624 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
30625 begin
30626 -- A special check for pragma Suppress_All, a very strange DEC pragma,
30627 -- strange because it comes at the end of the unit. Rational has the
30628 -- same name for a pragma, but treats it as a program unit pragma, In
30629 -- GNAT we just decide to allow it anywhere at all. If it appeared then
30630 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
30631 -- node, and we insert a pragma Suppress (All_Checks) at the start of
30632 -- the context clause to ensure the correct processing.
30634 if Has_Pragma_Suppress_All (N) then
30635 Prepend_To (Context_Items (N),
30636 Make_Pragma (Sloc (N),
30637 Chars => Name_Suppress,
30638 Pragma_Argument_Associations => New_List (
30639 Make_Pragma_Argument_Association (Sloc (N),
30640 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
30641 end if;
30643 -- Nothing else to do at the current time
30645 end Process_Compilation_Unit_Pragmas;
30647 -------------------------------------------
30648 -- Process_Compile_Time_Warning_Or_Error --
30649 -------------------------------------------
30651 procedure Process_Compile_Time_Warning_Or_Error
30652 (N : Node_Id;
30653 Eloc : Source_Ptr)
30655 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
30656 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
30657 Arg2 : constant Node_Id := Next (Arg1);
30659 begin
30660 Analyze_And_Resolve (Arg1x, Standard_Boolean);
30662 if Compile_Time_Known_Value (Arg1x) then
30663 if Is_True (Expr_Value (Arg1x)) then
30665 -- We have already verified that the second argument is a static
30666 -- string expression. Its string value must be retrieved
30667 -- explicitly if it is a declared constant, otherwise it has
30668 -- been constant-folded previously.
30670 declare
30671 Cent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
30672 Pname : constant Name_Id := Pragma_Name_Unmapped (N);
30673 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
30674 Str : constant String_Id :=
30675 Strval (Expr_Value_S (Get_Pragma_Arg (Arg2)));
30676 Str_Len : constant Nat := String_Length (Str);
30678 Force : constant Boolean :=
30679 Prag_Id = Pragma_Compile_Time_Warning
30680 and then Is_Spec_Name (Unit_Name (Current_Sem_Unit))
30681 and then (Ekind (Cent) /= E_Package
30682 or else not In_Private_Part (Cent));
30683 -- Set True if this is the warning case, and we are in the
30684 -- visible part of a package spec, or in a subprogram spec,
30685 -- in which case we want to force the client to see the
30686 -- warning, even though it is not in the main unit.
30688 C : Character;
30689 CC : Char_Code;
30690 Cont : Boolean;
30691 Ptr : Nat;
30693 begin
30694 -- Loop through segments of message separated by line feeds.
30695 -- We output these segments as separate messages with
30696 -- continuation marks for all but the first.
30698 Cont := False;
30699 Ptr := 1;
30700 loop
30701 Error_Msg_Strlen := 0;
30703 -- Loop to copy characters from argument to error message
30704 -- string buffer.
30706 loop
30707 exit when Ptr > Str_Len;
30708 CC := Get_String_Char (Str, Ptr);
30709 Ptr := Ptr + 1;
30711 -- Ignore wide chars ??? else store character
30713 if In_Character_Range (CC) then
30714 C := Get_Character (CC);
30715 exit when C = ASCII.LF;
30716 Error_Msg_Strlen := Error_Msg_Strlen + 1;
30717 Error_Msg_String (Error_Msg_Strlen) := C;
30718 end if;
30719 end loop;
30721 -- Here with one line ready to go
30723 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
30725 -- If this is a warning in a spec, then we want clients
30726 -- to see the warning, so mark the message with the
30727 -- special sequence !! to force the warning. In the case
30728 -- of a package spec, we do not force this if we are in
30729 -- the private part of the spec.
30731 if Force then
30732 if Cont = False then
30733 Error_Msg ("<<~!!", Eloc);
30734 Cont := True;
30735 else
30736 Error_Msg ("\<<~!!", Eloc);
30737 end if;
30739 -- Error, rather than warning, or in a body, so we do not
30740 -- need to force visibility for client (error will be
30741 -- output in any case, and this is the situation in which
30742 -- we do not want a client to get a warning, since the
30743 -- warning is in the body or the spec private part).
30745 else
30746 if Cont = False then
30747 Error_Msg ("<<~", Eloc);
30748 Cont := True;
30749 else
30750 Error_Msg ("\<<~", Eloc);
30751 end if;
30752 end if;
30754 exit when Ptr > Str_Len;
30755 end loop;
30756 end;
30757 end if;
30758 end if;
30759 end Process_Compile_Time_Warning_Or_Error;
30761 ------------------------------------
30762 -- Record_Possible_Body_Reference --
30763 ------------------------------------
30765 procedure Record_Possible_Body_Reference
30766 (State_Id : Entity_Id;
30767 Ref : Node_Id)
30769 Context : Node_Id;
30770 Spec_Id : Entity_Id;
30772 begin
30773 -- Ensure that we are dealing with a reference to a state
30775 pragma Assert (Ekind (State_Id) = E_Abstract_State);
30777 -- Climb the tree starting from the reference looking for a package body
30778 -- whose spec declares the referenced state. This criteria automatically
30779 -- excludes references in package specs which are legal. Note that it is
30780 -- not wise to emit an error now as the package body may lack pragma
30781 -- Refined_State or the referenced state may not be mentioned in the
30782 -- refinement. This approach avoids the generation of misleading errors.
30784 Context := Ref;
30785 while Present (Context) loop
30786 if Nkind (Context) = N_Package_Body then
30787 Spec_Id := Corresponding_Spec (Context);
30789 if Present (Abstract_States (Spec_Id))
30790 and then Contains (Abstract_States (Spec_Id), State_Id)
30791 then
30792 if No (Body_References (State_Id)) then
30793 Set_Body_References (State_Id, New_Elmt_List);
30794 end if;
30796 Append_Elmt (Ref, To => Body_References (State_Id));
30797 exit;
30798 end if;
30799 end if;
30801 Context := Parent (Context);
30802 end loop;
30803 end Record_Possible_Body_Reference;
30805 ------------------------------------------
30806 -- Relocate_Pragmas_To_Anonymous_Object --
30807 ------------------------------------------
30809 procedure Relocate_Pragmas_To_Anonymous_Object
30810 (Typ_Decl : Node_Id;
30811 Obj_Decl : Node_Id)
30813 Decl : Node_Id;
30814 Def : Node_Id;
30815 Next_Decl : Node_Id;
30817 begin
30818 if Nkind (Typ_Decl) = N_Protected_Type_Declaration then
30819 Def := Protected_Definition (Typ_Decl);
30820 else
30821 pragma Assert (Nkind (Typ_Decl) = N_Task_Type_Declaration);
30822 Def := Task_Definition (Typ_Decl);
30823 end if;
30825 -- The concurrent definition has a visible declaration list. Inspect it
30826 -- and relocate all canidate pragmas.
30828 if Present (Def) and then Present (Visible_Declarations (Def)) then
30829 Decl := First (Visible_Declarations (Def));
30830 while Present (Decl) loop
30832 -- Preserve the following declaration for iteration purposes due
30833 -- to possible relocation of a pragma.
30835 Next_Decl := Next (Decl);
30837 if Nkind (Decl) = N_Pragma
30838 and then Pragma_On_Anonymous_Object_OK (Get_Pragma_Id (Decl))
30839 then
30840 Remove (Decl);
30841 Insert_After (Obj_Decl, Decl);
30843 -- Skip internally generated code
30845 elsif not Comes_From_Source (Decl) then
30846 null;
30848 -- No candidate pragmas are available for relocation
30850 else
30851 exit;
30852 end if;
30854 Decl := Next_Decl;
30855 end loop;
30856 end if;
30857 end Relocate_Pragmas_To_Anonymous_Object;
30859 ------------------------------
30860 -- Relocate_Pragmas_To_Body --
30861 ------------------------------
30863 procedure Relocate_Pragmas_To_Body
30864 (Subp_Body : Node_Id;
30865 Target_Body : Node_Id := Empty)
30867 procedure Relocate_Pragma (Prag : Node_Id);
30868 -- Remove a single pragma from its current list and add it to the
30869 -- declarations of the proper body (either Subp_Body or Target_Body).
30871 ---------------------
30872 -- Relocate_Pragma --
30873 ---------------------
30875 procedure Relocate_Pragma (Prag : Node_Id) is
30876 Decls : List_Id;
30877 Target : Node_Id;
30879 begin
30880 -- When subprogram stubs or expression functions are involves, the
30881 -- destination declaration list belongs to the proper body.
30883 if Present (Target_Body) then
30884 Target := Target_Body;
30885 else
30886 Target := Subp_Body;
30887 end if;
30889 Decls := Declarations (Target);
30891 if No (Decls) then
30892 Decls := New_List;
30893 Set_Declarations (Target, Decls);
30894 end if;
30896 -- Unhook the pragma from its current list
30898 Remove (Prag);
30899 Prepend (Prag, Decls);
30900 end Relocate_Pragma;
30902 -- Local variables
30904 Body_Id : constant Entity_Id :=
30905 Defining_Unit_Name (Specification (Subp_Body));
30906 Next_Stmt : Node_Id;
30907 Stmt : Node_Id;
30909 -- Start of processing for Relocate_Pragmas_To_Body
30911 begin
30912 -- Do not process a body that comes from a separate unit as no construct
30913 -- can possibly follow it.
30915 if not Is_List_Member (Subp_Body) then
30916 return;
30918 -- Do not relocate pragmas that follow a stub if the stub does not have
30919 -- a proper body.
30921 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
30922 and then No (Target_Body)
30923 then
30924 return;
30926 -- Do not process internally generated routine _Postconditions
30928 elsif Ekind (Body_Id) = E_Procedure
30929 and then Chars (Body_Id) = Name_uPostconditions
30930 then
30931 return;
30932 end if;
30934 -- Look at what is following the body. We are interested in certain kind
30935 -- of pragmas (either from source or byproducts of expansion) that can
30936 -- apply to a body [stub].
30938 Stmt := Next (Subp_Body);
30939 while Present (Stmt) loop
30941 -- Preserve the following statement for iteration purposes due to a
30942 -- possible relocation of a pragma.
30944 Next_Stmt := Next (Stmt);
30946 -- Move a candidate pragma following the body to the declarations of
30947 -- the body.
30949 if Nkind (Stmt) = N_Pragma
30950 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
30951 then
30953 -- If a source pragma Warnings follows the body, it applies to
30954 -- following statements and does not belong in the body.
30956 if Get_Pragma_Id (Stmt) = Pragma_Warnings
30957 and then Comes_From_Source (Stmt)
30958 then
30959 null;
30960 else
30961 Relocate_Pragma (Stmt);
30962 end if;
30964 -- Skip internally generated code
30966 elsif not Comes_From_Source (Stmt) then
30967 null;
30969 -- No candidate pragmas are available for relocation
30971 else
30972 exit;
30973 end if;
30975 Stmt := Next_Stmt;
30976 end loop;
30977 end Relocate_Pragmas_To_Body;
30979 -------------------
30980 -- Resolve_State --
30981 -------------------
30983 procedure Resolve_State (N : Node_Id) is
30984 Func : Entity_Id;
30985 State : Entity_Id;
30987 begin
30988 if Is_Entity_Name (N) and then Present (Entity (N)) then
30989 Func := Entity (N);
30991 -- Handle overloading of state names by functions. Traverse the
30992 -- homonym chain looking for an abstract state.
30994 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
30995 pragma Assert (Is_Overloaded (N));
30997 State := Homonym (Func);
30998 while Present (State) loop
30999 if Ekind (State) = E_Abstract_State then
31001 -- Resolve the overloading by setting the proper entity of
31002 -- the reference to that of the state.
31004 Set_Etype (N, Standard_Void_Type);
31005 Set_Entity (N, State);
31006 Set_Is_Overloaded (N, False);
31008 Generate_Reference (State, N);
31009 return;
31010 end if;
31012 State := Homonym (State);
31013 end loop;
31015 -- A function can never act as a state. If the homonym chain does
31016 -- not contain a corresponding state, then something went wrong in
31017 -- the overloading mechanism.
31019 raise Program_Error;
31020 end if;
31021 end if;
31022 end Resolve_State;
31024 ----------------------------
31025 -- Rewrite_Assertion_Kind --
31026 ----------------------------
31028 procedure Rewrite_Assertion_Kind
31029 (N : Node_Id;
31030 From_Policy : Boolean := False)
31032 Nam : Name_Id;
31034 begin
31035 Nam := No_Name;
31036 if Nkind (N) = N_Attribute_Reference
31037 and then Attribute_Name (N) = Name_Class
31038 and then Nkind (Prefix (N)) = N_Identifier
31039 then
31040 case Chars (Prefix (N)) is
31041 when Name_Pre =>
31042 Nam := Name_uPre;
31044 when Name_Post =>
31045 Nam := Name_uPost;
31047 when Name_Type_Invariant =>
31048 Nam := Name_uType_Invariant;
31050 when Name_Invariant =>
31051 Nam := Name_uInvariant;
31053 when others =>
31054 return;
31055 end case;
31057 -- Recommend standard use of aspect names Pre/Post
31059 elsif Nkind (N) = N_Identifier
31060 and then From_Policy
31061 and then Serious_Errors_Detected = 0
31062 and then not ASIS_Mode
31063 then
31064 if Chars (N) = Name_Precondition
31065 or else Chars (N) = Name_Postcondition
31066 then
31067 Error_Msg_N ("Check_Policy is a non-standard pragma??", N);
31068 Error_Msg_N
31069 ("\use Assertion_Policy and aspect names Pre/Post for "
31070 & "Ada2012 conformance?", N);
31071 end if;
31073 return;
31074 end if;
31076 if Nam /= No_Name then
31077 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
31078 end if;
31079 end Rewrite_Assertion_Kind;
31081 --------
31082 -- rv --
31083 --------
31085 procedure rv is
31086 begin
31087 Dummy := Dummy + 1;
31088 end rv;
31090 --------------------------------
31091 -- Set_Encoded_Interface_Name --
31092 --------------------------------
31094 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
31095 Str : constant String_Id := Strval (S);
31096 Len : constant Nat := String_Length (Str);
31097 CC : Char_Code;
31098 C : Character;
31099 J : Pos;
31101 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
31103 procedure Encode;
31104 -- Stores encoded value of character code CC. The encoding we use an
31105 -- underscore followed by four lower case hex digits.
31107 ------------
31108 -- Encode --
31109 ------------
31111 procedure Encode is
31112 begin
31113 Store_String_Char (Get_Char_Code ('_'));
31114 Store_String_Char
31115 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
31116 Store_String_Char
31117 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
31118 Store_String_Char
31119 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
31120 Store_String_Char
31121 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
31122 end Encode;
31124 -- Start of processing for Set_Encoded_Interface_Name
31126 begin
31127 -- If first character is asterisk, this is a link name, and we leave it
31128 -- completely unmodified. We also ignore null strings (the latter case
31129 -- happens only in error cases).
31131 if Len = 0
31132 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
31133 then
31134 Set_Interface_Name (E, S);
31136 else
31137 J := 1;
31138 loop
31139 CC := Get_String_Char (Str, J);
31141 exit when not In_Character_Range (CC);
31143 C := Get_Character (CC);
31145 exit when C /= '_' and then C /= '$'
31146 and then C not in '0' .. '9'
31147 and then C not in 'a' .. 'z'
31148 and then C not in 'A' .. 'Z';
31150 if J = Len then
31151 Set_Interface_Name (E, S);
31152 return;
31154 else
31155 J := J + 1;
31156 end if;
31157 end loop;
31159 -- Here we need to encode. The encoding we use as follows:
31160 -- three underscores + four hex digits (lower case)
31162 Start_String;
31164 for J in 1 .. String_Length (Str) loop
31165 CC := Get_String_Char (Str, J);
31167 if not In_Character_Range (CC) then
31168 Encode;
31169 else
31170 C := Get_Character (CC);
31172 if C = '_' or else C = '$'
31173 or else C in '0' .. '9'
31174 or else C in 'a' .. 'z'
31175 or else C in 'A' .. 'Z'
31176 then
31177 Store_String_Char (CC);
31178 else
31179 Encode;
31180 end if;
31181 end if;
31182 end loop;
31184 Set_Interface_Name (E,
31185 Make_String_Literal (Sloc (S),
31186 Strval => End_String));
31187 end if;
31188 end Set_Encoded_Interface_Name;
31190 ------------------------
31191 -- Set_Elab_Unit_Name --
31192 ------------------------
31194 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is
31195 Pref : Node_Id;
31196 Scop : Entity_Id;
31198 begin
31199 if Nkind (N) = N_Identifier
31200 and then Nkind (With_Item) = N_Identifier
31201 then
31202 Set_Entity (N, Entity (With_Item));
31204 elsif Nkind (N) = N_Selected_Component then
31205 Change_Selected_Component_To_Expanded_Name (N);
31206 Set_Entity (N, Entity (With_Item));
31207 Set_Entity (Selector_Name (N), Entity (N));
31209 Pref := Prefix (N);
31210 Scop := Scope (Entity (N));
31211 while Nkind (Pref) = N_Selected_Component loop
31212 Change_Selected_Component_To_Expanded_Name (Pref);
31213 Set_Entity (Selector_Name (Pref), Scop);
31214 Set_Entity (Pref, Scop);
31215 Pref := Prefix (Pref);
31216 Scop := Scope (Scop);
31217 end loop;
31219 Set_Entity (Pref, Scop);
31220 end if;
31222 Generate_Reference (Entity (With_Item), N, Set_Ref => False);
31223 end Set_Elab_Unit_Name;
31225 -------------------
31226 -- Test_Case_Arg --
31227 -------------------
31229 function Test_Case_Arg
31230 (Prag : Node_Id;
31231 Arg_Nam : Name_Id;
31232 From_Aspect : Boolean := False) return Node_Id
31234 Aspect : constant Node_Id := Corresponding_Aspect (Prag);
31235 Arg : Node_Id;
31236 Args : Node_Id;
31238 begin
31239 pragma Assert (Nam_In (Arg_Nam, Name_Ensures,
31240 Name_Mode,
31241 Name_Name,
31242 Name_Requires));
31244 -- The caller requests the aspect argument
31246 if From_Aspect then
31247 if Present (Aspect)
31248 and then Nkind (Expression (Aspect)) = N_Aggregate
31249 then
31250 Args := Expression (Aspect);
31252 -- "Name" and "Mode" may appear without an identifier as a
31253 -- positional association.
31255 if Present (Expressions (Args)) then
31256 Arg := First (Expressions (Args));
31258 if Present (Arg) and then Arg_Nam = Name_Name then
31259 return Arg;
31260 end if;
31262 -- Skip "Name"
31264 Arg := Next (Arg);
31266 if Present (Arg) and then Arg_Nam = Name_Mode then
31267 return Arg;
31268 end if;
31269 end if;
31271 -- Some or all arguments may appear as component associatons
31273 if Present (Component_Associations (Args)) then
31274 Arg := First (Component_Associations (Args));
31275 while Present (Arg) loop
31276 if Chars (First (Choices (Arg))) = Arg_Nam then
31277 return Arg;
31278 end if;
31280 Next (Arg);
31281 end loop;
31282 end if;
31283 end if;
31285 -- Otherwise retrieve the argument directly from the pragma
31287 else
31288 Arg := First (Pragma_Argument_Associations (Prag));
31290 if Present (Arg) and then Arg_Nam = Name_Name then
31291 return Arg;
31292 end if;
31294 -- Skip argument "Name"
31296 Arg := Next (Arg);
31298 if Present (Arg) and then Arg_Nam = Name_Mode then
31299 return Arg;
31300 end if;
31302 -- Skip argument "Mode"
31304 Arg := Next (Arg);
31306 -- Arguments "Requires" and "Ensures" are optional and may not be
31307 -- present at all.
31309 while Present (Arg) loop
31310 if Chars (Arg) = Arg_Nam then
31311 return Arg;
31312 end if;
31314 Next (Arg);
31315 end loop;
31316 end if;
31318 return Empty;
31319 end Test_Case_Arg;
31321 end Sem_Prag;