2016-04-27 Hristian Kirtchev <kirtchev@adacore.com>
[official-gcc.git] / gcc / ada / sem_prag.adb
blob613ccdb414c5ab8cc8270be1394a4c79208da6d2
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-2016, 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 Lib; use Lib;
47 with Lib.Writ; use Lib.Writ;
48 with Lib.Xref; use Lib.Xref;
49 with Namet.Sp; use Namet.Sp;
50 with Nlists; use Nlists;
51 with Nmake; use Nmake;
52 with Output; use Output;
53 with Par_SCO; use Par_SCO;
54 with Restrict; use Restrict;
55 with Rident; use Rident;
56 with Rtsfind; use Rtsfind;
57 with Sem; use Sem;
58 with Sem_Aux; use Sem_Aux;
59 with Sem_Ch3; use Sem_Ch3;
60 with Sem_Ch6; use Sem_Ch6;
61 with Sem_Ch8; use Sem_Ch8;
62 with Sem_Ch12; use Sem_Ch12;
63 with Sem_Ch13; use Sem_Ch13;
64 with Sem_Disp; use Sem_Disp;
65 with Sem_Dist; use Sem_Dist;
66 with Sem_Elim; use Sem_Elim;
67 with Sem_Eval; use Sem_Eval;
68 with Sem_Intr; use Sem_Intr;
69 with Sem_Mech; use Sem_Mech;
70 with Sem_Res; use Sem_Res;
71 with Sem_Type; use Sem_Type;
72 with Sem_Util; use Sem_Util;
73 with Sem_Warn; use Sem_Warn;
74 with Stand; use Stand;
75 with Sinfo; use Sinfo;
76 with Sinfo.CN; use Sinfo.CN;
77 with Sinput; use Sinput;
78 with Stringt; use Stringt;
79 with Stylesw; use Stylesw;
80 with Table;
81 with Targparm; use Targparm;
82 with Tbuild; use Tbuild;
83 with Ttypes;
84 with Uintp; use Uintp;
85 with Uname; use Uname;
86 with Urealp; use Urealp;
87 with Validsw; use Validsw;
88 with Warnsw; use Warnsw;
90 package body Sem_Prag is
92 ----------------------------------------------
93 -- Common Handling of Import-Export Pragmas --
94 ----------------------------------------------
96 -- In the following section, a number of Import_xxx and Export_xxx pragmas
97 -- are defined by GNAT. These are compatible with the DEC pragmas of the
98 -- same name, and all have the following common form and processing:
100 -- pragma Export_xxx
101 -- [Internal =>] LOCAL_NAME
102 -- [, [External =>] EXTERNAL_SYMBOL]
103 -- [, other optional parameters ]);
105 -- pragma Import_xxx
106 -- [Internal =>] LOCAL_NAME
107 -- [, [External =>] EXTERNAL_SYMBOL]
108 -- [, other optional parameters ]);
110 -- EXTERNAL_SYMBOL ::=
111 -- IDENTIFIER
112 -- | static_string_EXPRESSION
114 -- The internal LOCAL_NAME designates the entity that is imported or
115 -- exported, and must refer to an entity in the current declarative
116 -- part (as required by the rules for LOCAL_NAME).
118 -- The external linker name is designated by the External parameter if
119 -- given, or the Internal parameter if not (if there is no External
120 -- parameter, the External parameter is a copy of the Internal name).
122 -- If the External parameter is given as a string, then this string is
123 -- treated as an external name (exactly as though it had been given as an
124 -- External_Name parameter for a normal Import pragma).
126 -- If the External parameter is given as an identifier (or there is no
127 -- External parameter, so that the Internal identifier is used), then
128 -- the external name is the characters of the identifier, translated
129 -- to all lower case letters.
131 -- Note: the external name specified or implied by any of these special
132 -- Import_xxx or Export_xxx pragmas override an external or link name
133 -- specified in a previous Import or Export pragma.
135 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
136 -- named notation, following the standard rules for subprogram calls, i.e.
137 -- parameters can be given in any order if named notation is used, and
138 -- positional and named notation can be mixed, subject to the rule that all
139 -- positional parameters must appear first.
141 -- Note: All these pragmas are implemented exactly following the DEC design
142 -- and implementation and are intended to be fully compatible with the use
143 -- of these pragmas in the DEC Ada compiler.
145 --------------------------------------------
146 -- Checking for Duplicated External Names --
147 --------------------------------------------
149 -- It is suspicious if two separate Export pragmas use the same external
150 -- name. The following table is used to diagnose this situation so that
151 -- an appropriate warning can be issued.
153 -- The Node_Id stored is for the N_String_Literal node created to hold
154 -- the value of the external name. The Sloc of this node is used to
155 -- cross-reference the location of the duplication.
157 package Externals is new Table.Table (
158 Table_Component_Type => Node_Id,
159 Table_Index_Type => Int,
160 Table_Low_Bound => 0,
161 Table_Initial => 100,
162 Table_Increment => 100,
163 Table_Name => "Name_Externals");
165 -------------------------------------
166 -- Local Subprograms and Variables --
167 -------------------------------------
169 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
170 -- This routine is used for possible casing adjustment of an explicit
171 -- external name supplied as a string literal (the node N), according to
172 -- the casing requirement of Opt.External_Name_Casing. If this is set to
173 -- As_Is, then the string literal is returned unchanged, but if it is set
174 -- to Uppercase or Lowercase, then a new string literal with appropriate
175 -- casing is constructed.
177 procedure Analyze_Part_Of
178 (Indic : Node_Id;
179 Item_Id : Entity_Id;
180 Encap : Node_Id;
181 Encap_Id : out Entity_Id;
182 Legal : out Boolean);
183 -- Subsidiary to Analyze_Part_Of_In_Decl_Part, Analyze_Part_Of_Option and
184 -- Analyze_Pragma. Perform full analysis of indicator Part_Of. Indic is the
185 -- Part_Of indicator. Item_Id is the entity of an abstract state, object or
186 -- package instantiation. Encap denotes the encapsulating state or single
187 -- concurrent type. Encap_Id is the entity of Encap. Flag Legal is set when
188 -- the indicator is legal.
190 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
191 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
192 -- Query whether a particular item appears in a mixed list of nodes and
193 -- entities. It is assumed that all nodes in the list have entities.
195 procedure Check_Postcondition_Use_In_Inlined_Subprogram
196 (Prag : Node_Id;
197 Spec_Id : Entity_Id);
198 -- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition,
199 -- Precondition, Refined_Post and Test_Case. Emit a warning when pragma
200 -- Prag is associated with subprogram Spec_Id subject to Inline_Always.
202 procedure Check_State_And_Constituent_Use
203 (States : Elist_Id;
204 Constits : Elist_Id;
205 Context : Node_Id);
206 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
207 -- Global and Initializes. Determine whether a state from list States and a
208 -- corresponding constituent from list Constits (if any) appear in the same
209 -- context denoted by Context. If this is the case, emit an error.
211 procedure Contract_Freeze_Error
212 (Contract_Id : Entity_Id;
213 Freeze_Id : Entity_Id);
214 -- Subsidiary to the analysis of pragmas Contract_Cases, Part_Of, Post, and
215 -- Pre. Emit a freezing-related error message where Freeze_Id is the entity
216 -- of a body which caused contract "freezing" and Contract_Id denotes the
217 -- entity of the affected contstruct.
219 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id);
220 -- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma
221 -- Prag that duplicates previous pragma Prev.
223 function Find_Related_Context
224 (Prag : Node_Id;
225 Do_Checks : Boolean := False) return Node_Id;
226 -- Subsidiaty to the analysis of pragmas Async_Readers, Async_Writers,
227 -- Constant_After_Elaboration, Effective_Reads, Effective_Writers and
228 -- Part_Of. Find the first source declaration or statement found while
229 -- traversing the previous node chain starting from pragma Prag. If flag
230 -- Do_Checks is set, the routine reports duplicate pragmas. The routine
231 -- returns Empty when reaching the start of the node chain.
233 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
234 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
235 -- original one, following the renaming chain) is returned. Otherwise the
236 -- entity is returned unchanged. Should be in Einfo???
238 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
239 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
240 -- Get_SPARK_Mode_From_Annotation. Convert a name into a corresponding
241 -- value of type SPARK_Mode_Type.
243 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
244 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
245 -- Determine whether dependency clause Clause is surrounded by extra
246 -- parentheses. If this is the case, issue an error message.
248 function Is_CCT_Instance
249 (Ref_Id : Entity_Id;
250 Context_Id : Entity_Id) return Boolean;
251 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
252 -- Global. Determine whether entity Ref_Id denotes the current instance of
253 -- a concurrent type. Context_Id denotes the associated context where the
254 -- pragma appears.
256 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
257 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
258 -- pragma Depends. Determine whether the type of dependency item Item is
259 -- tagged, unconstrained array, unconstrained record or a record with at
260 -- least one unconstrained component.
262 procedure Record_Possible_Body_Reference
263 (State_Id : Entity_Id;
264 Ref : Node_Id);
265 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
266 -- Global. Given an abstract state denoted by State_Id and a reference Ref
267 -- to it, determine whether the reference appears in a package body that
268 -- will eventually refine the state. If this is the case, record the
269 -- reference for future checks (see Analyze_Refined_State_In_Decls).
271 procedure Resolve_State (N : Node_Id);
272 -- Handle the overloading of state names by functions. When N denotes a
273 -- function, this routine finds the corresponding state and sets the entity
274 -- of N to that of the state.
276 procedure Rewrite_Assertion_Kind (N : Node_Id);
277 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
278 -- then it is rewritten as an identifier with the corresponding special
279 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
280 -- and Check_Policy.
282 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id);
283 -- Place semantic information on the argument of an Elaborate/Elaborate_All
284 -- pragma. Entity name for unit and its parents is taken from item in
285 -- previous with_clause that mentions the unit.
287 Dummy : Integer := 0;
288 pragma Volatile (Dummy);
289 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
291 procedure ip;
292 pragma No_Inline (ip);
293 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
294 -- is just to help debugging the front end. If a pragma Inspection_Point
295 -- is added to a source program, then breaking on ip will get you to that
296 -- point in the program.
298 procedure rv;
299 pragma No_Inline (rv);
300 -- This is a dummy function called by the processing for pragma Reviewable.
301 -- It is there for assisting front end debugging. By placing a Reviewable
302 -- pragma in the source program, a breakpoint on rv catches this place in
303 -- the source, allowing convenient stepping to the point of interest.
305 -------------------------------
306 -- Adjust_External_Name_Case --
307 -------------------------------
309 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
310 CC : Char_Code;
312 begin
313 -- Adjust case of literal if required
315 if Opt.External_Name_Exp_Casing = As_Is then
316 return N;
318 else
319 -- Copy existing string
321 Start_String;
323 -- Set proper casing
325 for J in 1 .. String_Length (Strval (N)) loop
326 CC := Get_String_Char (Strval (N), J);
328 if Opt.External_Name_Exp_Casing = Uppercase
329 and then CC >= Get_Char_Code ('a')
330 and then CC <= Get_Char_Code ('z')
331 then
332 Store_String_Char (CC - 32);
334 elsif Opt.External_Name_Exp_Casing = Lowercase
335 and then CC >= Get_Char_Code ('A')
336 and then CC <= Get_Char_Code ('Z')
337 then
338 Store_String_Char (CC + 32);
340 else
341 Store_String_Char (CC);
342 end if;
343 end loop;
345 return
346 Make_String_Literal (Sloc (N),
347 Strval => End_String);
348 end if;
349 end Adjust_External_Name_Case;
351 -----------------------------------------
352 -- Analyze_Contract_Cases_In_Decl_Part --
353 -----------------------------------------
355 procedure Analyze_Contract_Cases_In_Decl_Part
356 (N : Node_Id;
357 Freeze_Id : Entity_Id := Empty)
359 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
360 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
362 Others_Seen : Boolean := False;
363 -- This flag is set when an "others" choice is encountered. It is used
364 -- to detect multiple illegal occurrences of "others".
366 procedure Analyze_Contract_Case (CCase : Node_Id);
367 -- Verify the legality of a single contract case
369 ---------------------------
370 -- Analyze_Contract_Case --
371 ---------------------------
373 procedure Analyze_Contract_Case (CCase : Node_Id) is
374 Case_Guard : Node_Id;
375 Conseq : Node_Id;
376 Errors : Nat;
377 Extra_Guard : Node_Id;
379 begin
380 if Nkind (CCase) = N_Component_Association then
381 Case_Guard := First (Choices (CCase));
382 Conseq := Expression (CCase);
384 -- Each contract case must have exactly one case guard
386 Extra_Guard := Next (Case_Guard);
388 if Present (Extra_Guard) then
389 Error_Msg_N
390 ("contract case must have exactly one case guard",
391 Extra_Guard);
392 end if;
394 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
396 if Nkind (Case_Guard) = N_Others_Choice then
397 if Others_Seen then
398 Error_Msg_N
399 ("only one others choice allowed in contract cases",
400 Case_Guard);
401 else
402 Others_Seen := True;
403 end if;
405 elsif Others_Seen then
406 Error_Msg_N
407 ("others must be the last choice in contract cases", N);
408 end if;
410 -- Preanalyze the case guard and consequence
412 if Nkind (Case_Guard) /= N_Others_Choice then
413 Errors := Serious_Errors_Detected;
414 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
416 -- Emit a clarification message when the case guard contains
417 -- at least one undefined reference, possibly due to contract
418 -- "freezing".
420 if Errors /= Serious_Errors_Detected
421 and then Present (Freeze_Id)
422 and then Has_Undefined_Reference (Case_Guard)
423 then
424 Contract_Freeze_Error (Spec_Id, Freeze_Id);
425 end if;
426 end if;
428 Errors := Serious_Errors_Detected;
429 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
431 -- Emit a clarification message when the consequence contains
432 -- at least one undefined reference, possibly due to contract
433 -- "freezing".
435 if Errors /= Serious_Errors_Detected
436 and then Present (Freeze_Id)
437 and then Has_Undefined_Reference (Conseq)
438 then
439 Contract_Freeze_Error (Spec_Id, Freeze_Id);
440 end if;
442 -- The contract case is malformed
444 else
445 Error_Msg_N ("wrong syntax in contract case", CCase);
446 end if;
447 end Analyze_Contract_Case;
449 -- Local variables
451 CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
453 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
455 CCase : Node_Id;
456 Restore_Scope : Boolean := False;
458 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
460 begin
461 -- Do not analyze the pragma multiple times
463 if Is_Analyzed_Pragma (N) then
464 return;
465 end if;
467 -- Set the Ghost mode in effect from the pragma. Due to the delayed
468 -- analysis of the pragma, the Ghost mode at point of declaration and
469 -- point of analysis may not necessarely be the same. Use the mode in
470 -- effect at the point of declaration.
472 Set_Ghost_Mode (N);
474 -- Single and multiple contract cases must appear in aggregate form. If
475 -- this is not the case, then either the parser of the analysis of the
476 -- pragma failed to produce an aggregate.
478 pragma Assert (Nkind (CCases) = N_Aggregate);
480 if Present (Component_Associations (CCases)) then
482 -- Ensure that the formal parameters are visible when analyzing all
483 -- clauses. This falls out of the general rule of aspects pertaining
484 -- to subprogram declarations.
486 if not In_Open_Scopes (Spec_Id) then
487 Restore_Scope := True;
488 Push_Scope (Spec_Id);
490 if Is_Generic_Subprogram (Spec_Id) then
491 Install_Generic_Formals (Spec_Id);
492 else
493 Install_Formals (Spec_Id);
494 end if;
495 end if;
497 CCase := First (Component_Associations (CCases));
498 while Present (CCase) loop
499 Analyze_Contract_Case (CCase);
500 Next (CCase);
501 end loop;
503 if Restore_Scope then
504 End_Scope;
505 end if;
507 -- Currently it is not possible to inline pre/postconditions on a
508 -- subprogram subject to pragma Inline_Always.
510 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
512 -- Otherwise the pragma is illegal
514 else
515 Error_Msg_N ("wrong syntax for constract cases", N);
516 end if;
518 Ghost_Mode := Save_Ghost_Mode;
519 Set_Is_Analyzed_Pragma (N);
520 end Analyze_Contract_Cases_In_Decl_Part;
522 ----------------------------------
523 -- Analyze_Depends_In_Decl_Part --
524 ----------------------------------
526 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
527 Loc : constant Source_Ptr := Sloc (N);
528 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
529 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
531 All_Inputs_Seen : Elist_Id := No_Elist;
532 -- A list containing the entities of all the inputs processed so far.
533 -- The list is populated with unique entities because the same input
534 -- may appear in multiple input lists.
536 All_Outputs_Seen : Elist_Id := No_Elist;
537 -- A list containing the entities of all the outputs processed so far.
538 -- The list is populated with unique entities because output items are
539 -- unique in a dependence relation.
541 Constits_Seen : Elist_Id := No_Elist;
542 -- A list containing the entities of all constituents processed so far.
543 -- It aids in detecting illegal usage of a state and a corresponding
544 -- constituent in pragma [Refinde_]Depends.
546 Global_Seen : Boolean := False;
547 -- A flag set when pragma Global has been processed
549 Null_Output_Seen : Boolean := False;
550 -- A flag used to track the legality of a null output
552 Result_Seen : Boolean := False;
553 -- A flag set when Spec_Id'Result is processed
555 States_Seen : Elist_Id := No_Elist;
556 -- A list containing the entities of all states processed so far. It
557 -- helps in detecting illegal usage of a state and a corresponding
558 -- constituent in pragma [Refined_]Depends.
560 Subp_Inputs : Elist_Id := No_Elist;
561 Subp_Outputs : Elist_Id := No_Elist;
562 -- Two lists containing the full set of inputs and output of the related
563 -- subprograms. Note that these lists contain both nodes and entities.
565 Task_Input_Seen : Boolean := False;
566 Task_Output_Seen : Boolean := False;
567 -- Flags used to track the implicit dependence of a task unit on itself
569 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
570 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
571 -- to the name buffer. The individual kinds are as follows:
572 -- E_Abstract_State - "state"
573 -- E_Constant - "constant"
574 -- E_Discriminant - "discriminant"
575 -- E_Generic_In_Out_Parameter - "generic parameter"
576 -- E_Generic_In_Parameter - "generic parameter"
577 -- E_In_Parameter - "parameter"
578 -- E_In_Out_Parameter - "parameter"
579 -- E_Loop_Parameter - "loop parameter"
580 -- E_Out_Parameter - "parameter"
581 -- E_Protected_Type - "current instance of protected type"
582 -- E_Task_Type - "current instance of task type"
583 -- E_Variable - "global"
585 procedure Analyze_Dependency_Clause
586 (Clause : Node_Id;
587 Is_Last : Boolean);
588 -- Verify the legality of a single dependency clause. Flag Is_Last
589 -- denotes whether Clause is the last clause in the relation.
591 procedure Check_Function_Return;
592 -- Verify that Funtion'Result appears as one of the outputs
593 -- (SPARK RM 6.1.5(10)).
595 procedure Check_Role
596 (Item : Node_Id;
597 Item_Id : Entity_Id;
598 Is_Input : Boolean;
599 Self_Ref : Boolean);
600 -- Ensure that an item fulfills its designated input and/or output role
601 -- as specified by pragma Global (if any) or the enclosing context. If
602 -- this is not the case, emit an error. Item and Item_Id denote the
603 -- attributes of an item. Flag Is_Input should be set when item comes
604 -- from an input list. Flag Self_Ref should be set when the item is an
605 -- output and the dependency clause has operator "+".
607 procedure Check_Usage
608 (Subp_Items : Elist_Id;
609 Used_Items : Elist_Id;
610 Is_Input : Boolean);
611 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
612 -- error if this is not the case.
614 procedure Normalize_Clause (Clause : Node_Id);
615 -- Remove a self-dependency "+" from the input list of a clause
617 -----------------------------
618 -- Add_Item_To_Name_Buffer --
619 -----------------------------
621 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
622 begin
623 if Ekind (Item_Id) = E_Abstract_State then
624 Add_Str_To_Name_Buffer ("state");
626 elsif Ekind (Item_Id) = E_Constant then
627 Add_Str_To_Name_Buffer ("constant");
629 elsif Ekind (Item_Id) = E_Discriminant then
630 Add_Str_To_Name_Buffer ("discriminant");
632 elsif Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
633 E_Generic_In_Parameter)
634 then
635 Add_Str_To_Name_Buffer ("generic parameter");
637 elsif Is_Formal (Item_Id) then
638 Add_Str_To_Name_Buffer ("parameter");
640 elsif Ekind (Item_Id) = E_Loop_Parameter then
641 Add_Str_To_Name_Buffer ("loop parameter");
643 elsif Ekind (Item_Id) = E_Protected_Type
644 or else Is_Single_Protected_Object (Item_Id)
645 then
646 Add_Str_To_Name_Buffer ("current instance of protected type");
648 elsif Ekind (Item_Id) = E_Task_Type
649 or else Is_Single_Task_Object (Item_Id)
650 then
651 Add_Str_To_Name_Buffer ("current instance of task type");
653 elsif Ekind (Item_Id) = E_Variable then
654 Add_Str_To_Name_Buffer ("global");
656 -- The routine should not be called with non-SPARK items
658 else
659 raise Program_Error;
660 end if;
661 end Add_Item_To_Name_Buffer;
663 -------------------------------
664 -- Analyze_Dependency_Clause --
665 -------------------------------
667 procedure Analyze_Dependency_Clause
668 (Clause : Node_Id;
669 Is_Last : Boolean)
671 procedure Analyze_Input_List (Inputs : Node_Id);
672 -- Verify the legality of a single input list
674 procedure Analyze_Input_Output
675 (Item : Node_Id;
676 Is_Input : Boolean;
677 Self_Ref : Boolean;
678 Top_Level : Boolean;
679 Seen : in out Elist_Id;
680 Null_Seen : in out Boolean;
681 Non_Null_Seen : in out Boolean);
682 -- Verify the legality of a single input or output item. Flag
683 -- Is_Input should be set whenever Item is an input, False when it
684 -- denotes an output. Flag Self_Ref should be set when the item is an
685 -- output and the dependency clause has a "+". Flag Top_Level should
686 -- be set whenever Item appears immediately within an input or output
687 -- list. Seen is a collection of all abstract states, objects and
688 -- formals processed so far. Flag Null_Seen denotes whether a null
689 -- input or output has been encountered. Flag Non_Null_Seen denotes
690 -- whether a non-null input or output has been encountered.
692 ------------------------
693 -- Analyze_Input_List --
694 ------------------------
696 procedure Analyze_Input_List (Inputs : Node_Id) is
697 Inputs_Seen : Elist_Id := No_Elist;
698 -- A list containing the entities of all inputs that appear in the
699 -- current input list.
701 Non_Null_Input_Seen : Boolean := False;
702 Null_Input_Seen : Boolean := False;
703 -- Flags used to check the legality of an input list
705 Input : Node_Id;
707 begin
708 -- Multiple inputs appear as an aggregate
710 if Nkind (Inputs) = N_Aggregate then
711 if Present (Component_Associations (Inputs)) then
712 SPARK_Msg_N
713 ("nested dependency relations not allowed", Inputs);
715 elsif Present (Expressions (Inputs)) then
716 Input := First (Expressions (Inputs));
717 while Present (Input) loop
718 Analyze_Input_Output
719 (Item => Input,
720 Is_Input => True,
721 Self_Ref => False,
722 Top_Level => False,
723 Seen => Inputs_Seen,
724 Null_Seen => Null_Input_Seen,
725 Non_Null_Seen => Non_Null_Input_Seen);
727 Next (Input);
728 end loop;
730 -- Syntax error, always report
732 else
733 Error_Msg_N ("malformed input dependency list", Inputs);
734 end if;
736 -- Process a solitary input
738 else
739 Analyze_Input_Output
740 (Item => Inputs,
741 Is_Input => True,
742 Self_Ref => False,
743 Top_Level => False,
744 Seen => Inputs_Seen,
745 Null_Seen => Null_Input_Seen,
746 Non_Null_Seen => Non_Null_Input_Seen);
747 end if;
749 -- Detect an illegal dependency clause of the form
751 -- (null =>[+] null)
753 if Null_Output_Seen and then Null_Input_Seen then
754 SPARK_Msg_N
755 ("null dependency clause cannot have a null input list",
756 Inputs);
757 end if;
758 end Analyze_Input_List;
760 --------------------------
761 -- Analyze_Input_Output --
762 --------------------------
764 procedure Analyze_Input_Output
765 (Item : Node_Id;
766 Is_Input : Boolean;
767 Self_Ref : Boolean;
768 Top_Level : Boolean;
769 Seen : in out Elist_Id;
770 Null_Seen : in out Boolean;
771 Non_Null_Seen : in out Boolean)
773 procedure Current_Task_Instance_Seen;
774 -- Set the appropriate global flag when the current instance of a
775 -- task unit is encountered.
777 --------------------------------
778 -- Current_Task_Instance_Seen --
779 --------------------------------
781 procedure Current_Task_Instance_Seen is
782 begin
783 if Is_Input then
784 Task_Input_Seen := True;
785 else
786 Task_Output_Seen := True;
787 end if;
788 end Current_Task_Instance_Seen;
790 -- Local variables
792 Is_Output : constant Boolean := not Is_Input;
793 Grouped : Node_Id;
794 Item_Id : Entity_Id;
796 -- Start of processing for Analyze_Input_Output
798 begin
799 -- Multiple input or output items appear as an aggregate
801 if Nkind (Item) = N_Aggregate then
802 if not Top_Level then
803 SPARK_Msg_N ("nested grouping of items not allowed", Item);
805 elsif Present (Component_Associations (Item)) then
806 SPARK_Msg_N
807 ("nested dependency relations not allowed", Item);
809 -- Recursively analyze the grouped items
811 elsif Present (Expressions (Item)) then
812 Grouped := First (Expressions (Item));
813 while Present (Grouped) loop
814 Analyze_Input_Output
815 (Item => Grouped,
816 Is_Input => Is_Input,
817 Self_Ref => Self_Ref,
818 Top_Level => False,
819 Seen => Seen,
820 Null_Seen => Null_Seen,
821 Non_Null_Seen => Non_Null_Seen);
823 Next (Grouped);
824 end loop;
826 -- Syntax error, always report
828 else
829 Error_Msg_N ("malformed dependency list", Item);
830 end if;
832 -- Process attribute 'Result in the context of a dependency clause
834 elsif Is_Attribute_Result (Item) then
835 Non_Null_Seen := True;
837 Analyze (Item);
839 -- Attribute 'Result is allowed to appear on the output side of
840 -- a dependency clause (SPARK RM 6.1.5(6)).
842 if Is_Input then
843 SPARK_Msg_N ("function result cannot act as input", Item);
845 elsif Null_Seen then
846 SPARK_Msg_N
847 ("cannot mix null and non-null dependency items", Item);
849 else
850 Result_Seen := True;
851 end if;
853 -- Detect multiple uses of null in a single dependency list or
854 -- throughout the whole relation. Verify the placement of a null
855 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
857 elsif Nkind (Item) = N_Null then
858 if Null_Seen then
859 SPARK_Msg_N
860 ("multiple null dependency relations not allowed", Item);
862 elsif Non_Null_Seen then
863 SPARK_Msg_N
864 ("cannot mix null and non-null dependency items", Item);
866 else
867 Null_Seen := True;
869 if Is_Output then
870 if not Is_Last then
871 SPARK_Msg_N
872 ("null output list must be the last clause in a "
873 & "dependency relation", Item);
875 -- Catch a useless dependence of the form:
876 -- null =>+ ...
878 elsif Self_Ref then
879 SPARK_Msg_N
880 ("useless dependence, null depends on itself", Item);
881 end if;
882 end if;
883 end if;
885 -- Default case
887 else
888 Non_Null_Seen := True;
890 if Null_Seen then
891 SPARK_Msg_N ("cannot mix null and non-null items", Item);
892 end if;
894 Analyze (Item);
895 Resolve_State (Item);
897 -- Find the entity of the item. If this is a renaming, climb
898 -- the renaming chain to reach the root object. Renamings of
899 -- non-entire objects do not yield an entity (Empty).
901 Item_Id := Entity_Of (Item);
903 if Present (Item_Id) then
905 -- Constants
907 if Ekind_In (Item_Id, E_Constant,
908 E_Discriminant,
909 E_Loop_Parameter)
910 or else
912 -- Current instances of concurrent types
914 Ekind_In (Item_Id, E_Protected_Type, E_Task_Type)
915 or else
917 -- Formal parameters
919 Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
920 E_Generic_In_Parameter,
921 E_In_Parameter,
922 E_In_Out_Parameter,
923 E_Out_Parameter)
924 or else
926 -- States, variables
928 Ekind_In (Item_Id, E_Abstract_State, E_Variable)
929 then
930 -- The item denotes a concurrent type. Note that single
931 -- protected/task types are not considered here because
932 -- they behave as objects in the context of pragma
933 -- [Refined_]Depends.
935 if Ekind_In (Item_Id, E_Protected_Type, E_Task_Type) then
937 -- This use is legal as long as the concurrent type is
938 -- the current instance of an enclosing type.
940 if Is_CCT_Instance (Item_Id, Spec_Id) then
942 -- The dependence of a task unit on itself is
943 -- implicit and may or may not be explicitly
944 -- specified (SPARK RM 6.1.4).
946 if Ekind (Item_Id) = E_Task_Type then
947 Current_Task_Instance_Seen;
948 end if;
950 -- Otherwise this is not the current instance
952 else
953 SPARK_Msg_N
954 ("invalid use of subtype mark in dependency "
955 & "relation", Item);
956 end if;
958 -- The dependency of a task unit on itself is implicit
959 -- and may or may not be explicitly specified
960 -- (SPARK RM 6.1.4).
962 elsif Is_Single_Task_Object (Item_Id)
963 and then Is_CCT_Instance (Item_Id, Spec_Id)
964 then
965 Current_Task_Instance_Seen;
966 end if;
968 -- Ensure that the item fulfills its role as input and/or
969 -- output as specified by pragma Global or the enclosing
970 -- context.
972 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
974 -- Detect multiple uses of the same state, variable or
975 -- formal parameter. If this is not the case, add the
976 -- item to the list of processed relations.
978 if Contains (Seen, Item_Id) then
979 SPARK_Msg_NE
980 ("duplicate use of item &", Item, Item_Id);
981 else
982 Append_New_Elmt (Item_Id, Seen);
983 end if;
985 -- Detect illegal use of an input related to a null
986 -- output. Such input items cannot appear in other
987 -- input lists (SPARK RM 6.1.5(13)).
989 if Is_Input
990 and then Null_Output_Seen
991 and then Contains (All_Inputs_Seen, Item_Id)
992 then
993 SPARK_Msg_N
994 ("input of a null output list cannot appear in "
995 & "multiple input lists", Item);
996 end if;
998 -- Add an input or a self-referential output to the list
999 -- of all processed inputs.
1001 if Is_Input or else Self_Ref then
1002 Append_New_Elmt (Item_Id, All_Inputs_Seen);
1003 end if;
1005 -- State related checks (SPARK RM 6.1.5(3))
1007 if Ekind (Item_Id) = E_Abstract_State then
1009 -- Package and subprogram bodies are instantiated
1010 -- individually in a separate compiler pass. Due to
1011 -- this mode of instantiation, the refinement of a
1012 -- state may no longer be visible when a subprogram
1013 -- body contract is instantiated. Since the generic
1014 -- template is legal, do not perform this check in
1015 -- the instance to circumvent this oddity.
1017 if Is_Generic_Instance (Spec_Id) then
1018 null;
1020 -- An abstract state with visible refinement cannot
1021 -- appear in pragma [Refined_]Depends as its place
1022 -- must be taken by some of its constituents
1023 -- (SPARK RM 6.1.4(7)).
1025 elsif Has_Visible_Refinement (Item_Id) then
1026 SPARK_Msg_NE
1027 ("cannot mention state & in dependence relation",
1028 Item, Item_Id);
1029 SPARK_Msg_N ("\use its constituents instead", Item);
1030 return;
1032 -- If the reference to the abstract state appears in
1033 -- an enclosing package body that will eventually
1034 -- refine the state, record the reference for future
1035 -- checks.
1037 else
1038 Record_Possible_Body_Reference
1039 (State_Id => Item_Id,
1040 Ref => Item);
1041 end if;
1042 end if;
1044 -- When the item renames an entire object, replace the
1045 -- item with a reference to the object.
1047 if Entity (Item) /= Item_Id then
1048 Rewrite (Item,
1049 New_Occurrence_Of (Item_Id, Sloc (Item)));
1050 Analyze (Item);
1051 end if;
1053 -- Add the entity of the current item to the list of
1054 -- processed items.
1056 if Ekind (Item_Id) = E_Abstract_State then
1057 Append_New_Elmt (Item_Id, States_Seen);
1059 -- The variable may eventually become a constituent of a
1060 -- single protected/task type. Record the reference now
1061 -- and verify its legality when analyzing the contract of
1062 -- the variable (SPARK RM 9.3).
1064 elsif Ekind (Item_Id) = E_Variable then
1065 Record_Possible_Part_Of_Reference
1066 (Var_Id => Item_Id,
1067 Ref => Item);
1068 end if;
1070 if Ekind_In (Item_Id, E_Abstract_State,
1071 E_Constant,
1072 E_Variable)
1073 and then Present (Encapsulating_State (Item_Id))
1074 then
1075 Append_New_Elmt (Item_Id, Constits_Seen);
1076 end if;
1078 -- All other input/output items are illegal
1079 -- (SPARK RM 6.1.5(1)).
1081 else
1082 SPARK_Msg_N
1083 ("item must denote parameter, variable, state or "
1084 & "current instance of concurren type", Item);
1085 end if;
1087 -- All other input/output items are illegal
1088 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1090 else
1091 Error_Msg_N
1092 ("item must denote parameter, variable, state or current "
1093 & "instance of concurrent type", Item);
1094 end if;
1095 end if;
1096 end Analyze_Input_Output;
1098 -- Local variables
1100 Inputs : Node_Id;
1101 Output : Node_Id;
1102 Self_Ref : Boolean;
1104 Non_Null_Output_Seen : Boolean := False;
1105 -- Flag used to check the legality of an output list
1107 -- Start of processing for Analyze_Dependency_Clause
1109 begin
1110 Inputs := Expression (Clause);
1111 Self_Ref := False;
1113 -- An input list with a self-dependency appears as operator "+" where
1114 -- the actuals inputs are the right operand.
1116 if Nkind (Inputs) = N_Op_Plus then
1117 Inputs := Right_Opnd (Inputs);
1118 Self_Ref := True;
1119 end if;
1121 -- Process the output_list of a dependency_clause
1123 Output := First (Choices (Clause));
1124 while Present (Output) loop
1125 Analyze_Input_Output
1126 (Item => Output,
1127 Is_Input => False,
1128 Self_Ref => Self_Ref,
1129 Top_Level => True,
1130 Seen => All_Outputs_Seen,
1131 Null_Seen => Null_Output_Seen,
1132 Non_Null_Seen => Non_Null_Output_Seen);
1134 Next (Output);
1135 end loop;
1137 -- Process the input_list of a dependency_clause
1139 Analyze_Input_List (Inputs);
1140 end Analyze_Dependency_Clause;
1142 ---------------------------
1143 -- Check_Function_Return --
1144 ---------------------------
1146 procedure Check_Function_Return is
1147 begin
1148 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
1149 and then not Result_Seen
1150 then
1151 SPARK_Msg_NE
1152 ("result of & must appear in exactly one output list",
1153 N, Spec_Id);
1154 end if;
1155 end Check_Function_Return;
1157 ----------------
1158 -- Check_Role --
1159 ----------------
1161 procedure Check_Role
1162 (Item : Node_Id;
1163 Item_Id : Entity_Id;
1164 Is_Input : Boolean;
1165 Self_Ref : Boolean)
1167 procedure Find_Role
1168 (Item_Is_Input : out Boolean;
1169 Item_Is_Output : out Boolean);
1170 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1171 -- Item_Is_Output are set depending on the role.
1173 procedure Role_Error
1174 (Item_Is_Input : Boolean;
1175 Item_Is_Output : Boolean);
1176 -- Emit an error message concerning the incorrect use of Item in
1177 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1178 -- denote whether the item is an input and/or an output.
1180 ---------------
1181 -- Find_Role --
1182 ---------------
1184 procedure Find_Role
1185 (Item_Is_Input : out Boolean;
1186 Item_Is_Output : out Boolean)
1188 begin
1189 Item_Is_Input := False;
1190 Item_Is_Output := False;
1192 -- Abstract states
1194 if Ekind (Item_Id) = E_Abstract_State then
1196 -- When pragma Global is present, the mode of the state may be
1197 -- further constrained by setting a more restrictive mode.
1199 if Global_Seen then
1200 if Appears_In (Subp_Inputs, Item_Id) then
1201 Item_Is_Input := True;
1202 end if;
1204 if Appears_In (Subp_Outputs, Item_Id) then
1205 Item_Is_Output := True;
1206 end if;
1208 -- Otherwise the state has a default IN OUT mode
1210 else
1211 Item_Is_Input := True;
1212 Item_Is_Output := True;
1213 end if;
1215 -- Constants
1217 elsif Ekind_In (Item_Id, E_Constant,
1218 E_Discriminant,
1219 E_Loop_Parameter)
1220 then
1221 Item_Is_Input := True;
1223 -- Parameters
1225 elsif Ekind_In (Item_Id, E_Generic_In_Parameter,
1226 E_In_Parameter)
1227 then
1228 Item_Is_Input := True;
1230 elsif Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
1231 E_In_Out_Parameter)
1232 then
1233 Item_Is_Input := True;
1234 Item_Is_Output := True;
1236 elsif Ekind (Item_Id) = E_Out_Parameter then
1237 if Scope (Item_Id) = Spec_Id then
1239 -- An OUT parameter of the related subprogram has mode IN
1240 -- if its type is unconstrained or tagged because array
1241 -- bounds, discriminants or tags can be read.
1243 if Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1244 Item_Is_Input := True;
1245 end if;
1247 Item_Is_Output := True;
1249 -- An OUT parameter of an enclosing subprogram behaves as a
1250 -- read-write variable in which case the mode is IN OUT.
1252 else
1253 Item_Is_Input := True;
1254 Item_Is_Output := True;
1255 end if;
1257 -- Protected types
1259 elsif Ekind (Item_Id) = E_Protected_Type then
1261 -- A protected type acts as a formal parameter of mode IN when
1262 -- it applies to a protected function.
1264 if Ekind (Spec_Id) = E_Function then
1265 Item_Is_Input := True;
1267 -- Otherwise the protected type acts as a formal of mode IN OUT
1269 else
1270 Item_Is_Input := True;
1271 Item_Is_Output := True;
1272 end if;
1274 -- Task types
1276 elsif Ekind (Item_Id) = E_Task_Type then
1277 Item_Is_Input := True;
1278 Item_Is_Output := True;
1280 -- Variable case
1282 else pragma Assert (Ekind (Item_Id) = E_Variable);
1284 -- When pragma Global is present, the mode of the variable may
1285 -- be further constrained by setting a more restrictive mode.
1287 if Global_Seen then
1289 -- A variable has mode IN when its type is unconstrained or
1290 -- tagged because array bounds, discriminants or tags can be
1291 -- read.
1293 if Appears_In (Subp_Inputs, Item_Id)
1294 or else Is_Unconstrained_Or_Tagged_Item (Item_Id)
1295 then
1296 Item_Is_Input := True;
1297 end if;
1299 if Appears_In (Subp_Outputs, Item_Id) then
1300 Item_Is_Output := True;
1301 end if;
1303 -- Otherwise the variable has a default IN OUT mode
1305 else
1306 Item_Is_Input := True;
1307 Item_Is_Output := True;
1308 end if;
1309 end if;
1310 end Find_Role;
1312 ----------------
1313 -- Role_Error --
1314 ----------------
1316 procedure Role_Error
1317 (Item_Is_Input : Boolean;
1318 Item_Is_Output : Boolean)
1320 Error_Msg : Name_Id;
1322 begin
1323 Name_Len := 0;
1325 -- When the item is not part of the input and the output set of
1326 -- the related subprogram, then it appears as extra in pragma
1327 -- [Refined_]Depends.
1329 if not Item_Is_Input and then not Item_Is_Output then
1330 Add_Item_To_Name_Buffer (Item_Id);
1331 Add_Str_To_Name_Buffer
1332 (" & cannot appear in dependence relation");
1334 Error_Msg := Name_Find;
1335 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1337 Error_Msg_Name_1 := Chars (Spec_Id);
1338 SPARK_Msg_NE
1339 (Fix_Msg (Spec_Id, "\& is not part of the input or output "
1340 & "set of subprogram %"), Item, Item_Id);
1342 -- The mode of the item and its role in pragma [Refined_]Depends
1343 -- are in conflict. Construct a detailed message explaining the
1344 -- illegality (SPARK RM 6.1.5(5-6)).
1346 else
1347 if Item_Is_Input then
1348 Add_Str_To_Name_Buffer ("read-only");
1349 else
1350 Add_Str_To_Name_Buffer ("write-only");
1351 end if;
1353 Add_Char_To_Name_Buffer (' ');
1354 Add_Item_To_Name_Buffer (Item_Id);
1355 Add_Str_To_Name_Buffer (" & cannot appear as ");
1357 if Item_Is_Input then
1358 Add_Str_To_Name_Buffer ("output");
1359 else
1360 Add_Str_To_Name_Buffer ("input");
1361 end if;
1363 Add_Str_To_Name_Buffer (" in dependence relation");
1364 Error_Msg := Name_Find;
1365 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1366 end if;
1367 end Role_Error;
1369 -- Local variables
1371 Item_Is_Input : Boolean;
1372 Item_Is_Output : Boolean;
1374 -- Start of processing for Check_Role
1376 begin
1377 Find_Role (Item_Is_Input, Item_Is_Output);
1379 -- Input item
1381 if Is_Input then
1382 if not Item_Is_Input then
1383 Role_Error (Item_Is_Input, Item_Is_Output);
1384 end if;
1386 -- Self-referential item
1388 elsif Self_Ref then
1389 if not Item_Is_Input or else not Item_Is_Output then
1390 Role_Error (Item_Is_Input, Item_Is_Output);
1391 end if;
1393 -- Output item
1395 elsif not Item_Is_Output then
1396 Role_Error (Item_Is_Input, Item_Is_Output);
1397 end if;
1398 end Check_Role;
1400 -----------------
1401 -- Check_Usage --
1402 -----------------
1404 procedure Check_Usage
1405 (Subp_Items : Elist_Id;
1406 Used_Items : Elist_Id;
1407 Is_Input : Boolean)
1409 procedure Usage_Error (Item_Id : Entity_Id);
1410 -- Emit an error concerning the illegal usage of an item
1412 -----------------
1413 -- Usage_Error --
1414 -----------------
1416 procedure Usage_Error (Item_Id : Entity_Id) is
1417 Error_Msg : Name_Id;
1419 begin
1420 -- Input case
1422 if Is_Input then
1424 -- Unconstrained and tagged items are not part of the explicit
1425 -- input set of the related subprogram, they do not have to be
1426 -- present in a dependence relation and should not be flagged
1427 -- (SPARK RM 6.1.5(8)).
1429 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1430 Name_Len := 0;
1432 Add_Item_To_Name_Buffer (Item_Id);
1433 Add_Str_To_Name_Buffer
1434 (" & is missing from input dependence list");
1436 Error_Msg := Name_Find;
1437 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1438 end if;
1440 -- Output case (SPARK RM 6.1.5(10))
1442 else
1443 Name_Len := 0;
1445 Add_Item_To_Name_Buffer (Item_Id);
1446 Add_Str_To_Name_Buffer
1447 (" & is missing from output dependence list");
1449 Error_Msg := Name_Find;
1450 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1451 end if;
1452 end Usage_Error;
1454 -- Local variables
1456 Elmt : Elmt_Id;
1457 Item : Node_Id;
1458 Item_Id : Entity_Id;
1460 -- Start of processing for Check_Usage
1462 begin
1463 if No (Subp_Items) then
1464 return;
1465 end if;
1467 -- Each input or output of the subprogram must appear in a dependency
1468 -- relation.
1470 Elmt := First_Elmt (Subp_Items);
1471 while Present (Elmt) loop
1472 Item := Node (Elmt);
1474 if Nkind (Item) = N_Defining_Identifier then
1475 Item_Id := Item;
1476 else
1477 Item_Id := Entity_Of (Item);
1478 end if;
1480 -- The item does not appear in a dependency
1482 if Present (Item_Id)
1483 and then not Contains (Used_Items, Item_Id)
1484 then
1485 if Is_Formal (Item_Id) then
1486 Usage_Error (Item_Id);
1488 -- The current instance of a protected type behaves as a formal
1489 -- parameter (SPARK RM 6.1.4).
1491 elsif Ekind (Item_Id) = E_Protected_Type
1492 or else Is_Single_Protected_Object (Item_Id)
1493 then
1494 Usage_Error (Item_Id);
1496 -- The current instance of a task type behaves as a formal
1497 -- parameter (SPARK RM 6.1.4).
1499 elsif Ekind (Item_Id) = E_Task_Type
1500 or else Is_Single_Task_Object (Item_Id)
1501 then
1502 -- The dependence of a task unit on itself is implicit and
1503 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1504 -- Emit an error if only one input/output is present.
1506 if Task_Input_Seen /= Task_Output_Seen then
1507 Usage_Error (Item_Id);
1508 end if;
1510 -- States and global objects are not used properly only when
1511 -- the subprogram is subject to pragma Global.
1513 elsif Global_Seen then
1514 Usage_Error (Item_Id);
1515 end if;
1516 end if;
1518 Next_Elmt (Elmt);
1519 end loop;
1520 end Check_Usage;
1522 ----------------------
1523 -- Normalize_Clause --
1524 ----------------------
1526 procedure Normalize_Clause (Clause : Node_Id) is
1527 procedure Create_Or_Modify_Clause
1528 (Output : Node_Id;
1529 Outputs : Node_Id;
1530 Inputs : Node_Id;
1531 After : Node_Id;
1532 In_Place : Boolean;
1533 Multiple : Boolean);
1534 -- Create a brand new clause to represent the self-reference or
1535 -- modify the input and/or output lists of an existing clause. Output
1536 -- denotes a self-referencial output. Outputs is the output list of a
1537 -- clause. Inputs is the input list of a clause. After denotes the
1538 -- clause after which the new clause is to be inserted. Flag In_Place
1539 -- should be set when normalizing the last output of an output list.
1540 -- Flag Multiple should be set when Output comes from a list with
1541 -- multiple items.
1543 -----------------------------
1544 -- Create_Or_Modify_Clause --
1545 -----------------------------
1547 procedure Create_Or_Modify_Clause
1548 (Output : Node_Id;
1549 Outputs : Node_Id;
1550 Inputs : Node_Id;
1551 After : Node_Id;
1552 In_Place : Boolean;
1553 Multiple : Boolean)
1555 procedure Propagate_Output
1556 (Output : Node_Id;
1557 Inputs : Node_Id);
1558 -- Handle the various cases of output propagation to the input
1559 -- list. Output denotes a self-referencial output item. Inputs
1560 -- is the input list of a clause.
1562 ----------------------
1563 -- Propagate_Output --
1564 ----------------------
1566 procedure Propagate_Output
1567 (Output : Node_Id;
1568 Inputs : Node_Id)
1570 function In_Input_List
1571 (Item : Entity_Id;
1572 Inputs : List_Id) return Boolean;
1573 -- Determine whether a particulat item appears in the input
1574 -- list of a clause.
1576 -------------------
1577 -- In_Input_List --
1578 -------------------
1580 function In_Input_List
1581 (Item : Entity_Id;
1582 Inputs : List_Id) return Boolean
1584 Elmt : Node_Id;
1586 begin
1587 Elmt := First (Inputs);
1588 while Present (Elmt) loop
1589 if Entity_Of (Elmt) = Item then
1590 return True;
1591 end if;
1593 Next (Elmt);
1594 end loop;
1596 return False;
1597 end In_Input_List;
1599 -- Local variables
1601 Output_Id : constant Entity_Id := Entity_Of (Output);
1602 Grouped : List_Id;
1604 -- Start of processing for Propagate_Output
1606 begin
1607 -- The clause is of the form:
1609 -- (Output =>+ null)
1611 -- Remove null input and replace it with a copy of the output:
1613 -- (Output => Output)
1615 if Nkind (Inputs) = N_Null then
1616 Rewrite (Inputs, New_Copy_Tree (Output));
1618 -- The clause is of the form:
1620 -- (Output =>+ (Input1, ..., InputN))
1622 -- Determine whether the output is not already mentioned in the
1623 -- input list and if not, add it to the list of inputs:
1625 -- (Output => (Output, Input1, ..., InputN))
1627 elsif Nkind (Inputs) = N_Aggregate then
1628 Grouped := Expressions (Inputs);
1630 if not In_Input_List
1631 (Item => Output_Id,
1632 Inputs => Grouped)
1633 then
1634 Prepend_To (Grouped, New_Copy_Tree (Output));
1635 end if;
1637 -- The clause is of the form:
1639 -- (Output =>+ Input)
1641 -- If the input does not mention the output, group the two
1642 -- together:
1644 -- (Output => (Output, Input))
1646 elsif Entity_Of (Inputs) /= Output_Id then
1647 Rewrite (Inputs,
1648 Make_Aggregate (Loc,
1649 Expressions => New_List (
1650 New_Copy_Tree (Output),
1651 New_Copy_Tree (Inputs))));
1652 end if;
1653 end Propagate_Output;
1655 -- Local variables
1657 Loc : constant Source_Ptr := Sloc (Clause);
1658 New_Clause : Node_Id;
1660 -- Start of processing for Create_Or_Modify_Clause
1662 begin
1663 -- A null output depending on itself does not require any
1664 -- normalization.
1666 if Nkind (Output) = N_Null then
1667 return;
1669 -- A function result cannot depend on itself because it cannot
1670 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1672 elsif Is_Attribute_Result (Output) then
1673 SPARK_Msg_N ("function result cannot depend on itself", Output);
1674 return;
1675 end if;
1677 -- When performing the transformation in place, simply add the
1678 -- output to the list of inputs (if not already there). This
1679 -- case arises when dealing with the last output of an output
1680 -- list. Perform the normalization in place to avoid generating
1681 -- a malformed tree.
1683 if In_Place then
1684 Propagate_Output (Output, Inputs);
1686 -- A list with multiple outputs is slowly trimmed until only
1687 -- one element remains. When this happens, replace aggregate
1688 -- with the element itself.
1690 if Multiple then
1691 Remove (Output);
1692 Rewrite (Outputs, Output);
1693 end if;
1695 -- Default case
1697 else
1698 -- Unchain the output from its output list as it will appear in
1699 -- a new clause. Note that we cannot simply rewrite the output
1700 -- as null because this will violate the semantics of pragma
1701 -- Depends.
1703 Remove (Output);
1705 -- Generate a new clause of the form:
1706 -- (Output => Inputs)
1708 New_Clause :=
1709 Make_Component_Association (Loc,
1710 Choices => New_List (Output),
1711 Expression => New_Copy_Tree (Inputs));
1713 -- The new clause contains replicated content that has already
1714 -- been analyzed. There is not need to reanalyze or renormalize
1715 -- it again.
1717 Set_Analyzed (New_Clause);
1719 Propagate_Output
1720 (Output => First (Choices (New_Clause)),
1721 Inputs => Expression (New_Clause));
1723 Insert_After (After, New_Clause);
1724 end if;
1725 end Create_Or_Modify_Clause;
1727 -- Local variables
1729 Outputs : constant Node_Id := First (Choices (Clause));
1730 Inputs : Node_Id;
1731 Last_Output : Node_Id;
1732 Next_Output : Node_Id;
1733 Output : Node_Id;
1735 -- Start of processing for Normalize_Clause
1737 begin
1738 -- A self-dependency appears as operator "+". Remove the "+" from the
1739 -- tree by moving the real inputs to their proper place.
1741 if Nkind (Expression (Clause)) = N_Op_Plus then
1742 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1743 Inputs := Expression (Clause);
1745 -- Multiple outputs appear as an aggregate
1747 if Nkind (Outputs) = N_Aggregate then
1748 Last_Output := Last (Expressions (Outputs));
1750 Output := First (Expressions (Outputs));
1751 while Present (Output) loop
1753 -- Normalization may remove an output from its list,
1754 -- preserve the subsequent output now.
1756 Next_Output := Next (Output);
1758 Create_Or_Modify_Clause
1759 (Output => Output,
1760 Outputs => Outputs,
1761 Inputs => Inputs,
1762 After => Clause,
1763 In_Place => Output = Last_Output,
1764 Multiple => True);
1766 Output := Next_Output;
1767 end loop;
1769 -- Solitary output
1771 else
1772 Create_Or_Modify_Clause
1773 (Output => Outputs,
1774 Outputs => Empty,
1775 Inputs => Inputs,
1776 After => Empty,
1777 In_Place => True,
1778 Multiple => False);
1779 end if;
1780 end if;
1781 end Normalize_Clause;
1783 -- Local variables
1785 Deps : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
1786 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
1788 Clause : Node_Id;
1789 Errors : Nat;
1790 Last_Clause : Node_Id;
1791 Restore_Scope : Boolean := False;
1793 -- Start of processing for Analyze_Depends_In_Decl_Part
1795 begin
1796 -- Do not analyze the pragma multiple times
1798 if Is_Analyzed_Pragma (N) then
1799 return;
1800 end if;
1802 -- Empty dependency list
1804 if Nkind (Deps) = N_Null then
1806 -- Gather all states, objects and formal parameters that the
1807 -- subprogram may depend on. These items are obtained from the
1808 -- parameter profile or pragma [Refined_]Global (if available).
1810 Collect_Subprogram_Inputs_Outputs
1811 (Subp_Id => Subp_Id,
1812 Subp_Inputs => Subp_Inputs,
1813 Subp_Outputs => Subp_Outputs,
1814 Global_Seen => Global_Seen);
1816 -- Verify that every input or output of the subprogram appear in a
1817 -- dependency.
1819 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1820 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1821 Check_Function_Return;
1823 -- Dependency clauses appear as component associations of an aggregate
1825 elsif Nkind (Deps) = N_Aggregate then
1827 -- Do not attempt to perform analysis of a syntactically illegal
1828 -- clause as this will lead to misleading errors.
1830 if Has_Extra_Parentheses (Deps) then
1831 return;
1832 end if;
1834 if Present (Component_Associations (Deps)) then
1835 Last_Clause := Last (Component_Associations (Deps));
1837 -- Gather all states, objects and formal parameters that the
1838 -- subprogram may depend on. These items are obtained from the
1839 -- parameter profile or pragma [Refined_]Global (if available).
1841 Collect_Subprogram_Inputs_Outputs
1842 (Subp_Id => Subp_Id,
1843 Subp_Inputs => Subp_Inputs,
1844 Subp_Outputs => Subp_Outputs,
1845 Global_Seen => Global_Seen);
1847 -- When pragma [Refined_]Depends appears on a single concurrent
1848 -- type, it is relocated to the anonymous object.
1850 if Is_Single_Concurrent_Object (Spec_Id) then
1851 null;
1853 -- Ensure that the formal parameters are visible when analyzing
1854 -- all clauses. This falls out of the general rule of aspects
1855 -- pertaining to subprogram declarations.
1857 elsif not In_Open_Scopes (Spec_Id) then
1858 Restore_Scope := True;
1859 Push_Scope (Spec_Id);
1861 if Ekind (Spec_Id) = E_Task_Type then
1862 if Has_Discriminants (Spec_Id) then
1863 Install_Discriminants (Spec_Id);
1864 end if;
1866 elsif Is_Generic_Subprogram (Spec_Id) then
1867 Install_Generic_Formals (Spec_Id);
1869 else
1870 Install_Formals (Spec_Id);
1871 end if;
1872 end if;
1874 Clause := First (Component_Associations (Deps));
1875 while Present (Clause) loop
1876 Errors := Serious_Errors_Detected;
1878 -- The normalization mechanism may create extra clauses that
1879 -- contain replicated input and output names. There is no need
1880 -- to reanalyze them.
1882 if not Analyzed (Clause) then
1883 Set_Analyzed (Clause);
1885 Analyze_Dependency_Clause
1886 (Clause => Clause,
1887 Is_Last => Clause = Last_Clause);
1888 end if;
1890 -- Do not normalize a clause if errors were detected (count
1891 -- of Serious_Errors has increased) because the inputs and/or
1892 -- outputs may denote illegal items. Normalization is disabled
1893 -- in ASIS mode as it alters the tree by introducing new nodes
1894 -- similar to expansion.
1896 if Serious_Errors_Detected = Errors and then not ASIS_Mode then
1897 Normalize_Clause (Clause);
1898 end if;
1900 Next (Clause);
1901 end loop;
1903 if Restore_Scope then
1904 End_Scope;
1905 end if;
1907 -- Verify that every input or output of the subprogram appear in a
1908 -- dependency.
1910 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1911 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1912 Check_Function_Return;
1914 -- The dependency list is malformed. This is a syntax error, always
1915 -- report.
1917 else
1918 Error_Msg_N ("malformed dependency relation", Deps);
1919 return;
1920 end if;
1922 -- The top level dependency relation is malformed. This is a syntax
1923 -- error, always report.
1925 else
1926 Error_Msg_N ("malformed dependency relation", Deps);
1927 goto Leave;
1928 end if;
1930 -- Ensure that a state and a corresponding constituent do not appear
1931 -- together in pragma [Refined_]Depends.
1933 Check_State_And_Constituent_Use
1934 (States => States_Seen,
1935 Constits => Constits_Seen,
1936 Context => N);
1938 <<Leave>>
1939 Set_Is_Analyzed_Pragma (N);
1940 end Analyze_Depends_In_Decl_Part;
1942 --------------------------------------------
1943 -- Analyze_External_Property_In_Decl_Part --
1944 --------------------------------------------
1946 procedure Analyze_External_Property_In_Decl_Part
1947 (N : Node_Id;
1948 Expr_Val : out Boolean)
1950 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
1951 Obj_Decl : constant Node_Id := Find_Related_Context (N);
1952 Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl);
1953 Expr : Node_Id;
1955 begin
1956 Expr_Val := False;
1958 -- Do not analyze the pragma multiple times
1960 if Is_Analyzed_Pragma (N) then
1961 return;
1962 end if;
1964 Error_Msg_Name_1 := Pragma_Name (N);
1966 -- An external property pragma must apply to an effectively volatile
1967 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
1968 -- The check is performed at the end of the declarative region due to a
1969 -- possible out-of-order arrangement of pragmas:
1971 -- Obj : ...;
1972 -- pragma Async_Readers (Obj);
1973 -- pragma Volatile (Obj);
1975 if not Is_Effectively_Volatile (Obj_Id) then
1976 SPARK_Msg_N
1977 ("external property % must apply to a volatile object", N);
1978 end if;
1980 -- Ensure that the Boolean expression (if present) is static. A missing
1981 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
1983 Expr_Val := True;
1985 if Present (Arg1) then
1986 Expr := Get_Pragma_Arg (Arg1);
1988 if Is_OK_Static_Expression (Expr) then
1989 Expr_Val := Is_True (Expr_Value (Expr));
1990 end if;
1991 end if;
1993 Set_Is_Analyzed_Pragma (N);
1994 end Analyze_External_Property_In_Decl_Part;
1996 ---------------------------------
1997 -- Analyze_Global_In_Decl_Part --
1998 ---------------------------------
2000 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
2001 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
2002 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
2003 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
2005 Constits_Seen : Elist_Id := No_Elist;
2006 -- A list containing the entities of all constituents processed so far.
2007 -- It aids in detecting illegal usage of a state and a corresponding
2008 -- constituent in pragma [Refinde_]Global.
2010 Seen : Elist_Id := No_Elist;
2011 -- A list containing the entities of all the items processed so far. It
2012 -- plays a role in detecting distinct entities.
2014 States_Seen : Elist_Id := No_Elist;
2015 -- A list containing the entities of all states processed so far. It
2016 -- helps in detecting illegal usage of a state and a corresponding
2017 -- constituent in pragma [Refined_]Global.
2019 In_Out_Seen : Boolean := False;
2020 Input_Seen : Boolean := False;
2021 Output_Seen : Boolean := False;
2022 Proof_Seen : Boolean := False;
2023 -- Flags used to verify the consistency of modes
2025 procedure Analyze_Global_List
2026 (List : Node_Id;
2027 Global_Mode : Name_Id := Name_Input);
2028 -- Verify the legality of a single global list declaration. Global_Mode
2029 -- denotes the current mode in effect.
2031 -------------------------
2032 -- Analyze_Global_List --
2033 -------------------------
2035 procedure Analyze_Global_List
2036 (List : Node_Id;
2037 Global_Mode : Name_Id := Name_Input)
2039 procedure Analyze_Global_Item
2040 (Item : Node_Id;
2041 Global_Mode : Name_Id);
2042 -- Verify the legality of a single global item declaration denoted by
2043 -- Item. Global_Mode denotes the current mode in effect.
2045 procedure Check_Duplicate_Mode
2046 (Mode : Node_Id;
2047 Status : in out Boolean);
2048 -- Flag Status denotes whether a particular mode has been seen while
2049 -- processing a global list. This routine verifies that Mode is not a
2050 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2052 procedure Check_Mode_Restriction_In_Enclosing_Context
2053 (Item : Node_Id;
2054 Item_Id : Entity_Id);
2055 -- Verify that an item of mode In_Out or Output does not appear as an
2056 -- input in the Global aspect of an enclosing subprogram. If this is
2057 -- the case, emit an error. Item and Item_Id are respectively the
2058 -- item and its entity.
2060 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
2061 -- Mode denotes either In_Out or Output. Depending on the kind of the
2062 -- related subprogram, emit an error if those two modes apply to a
2063 -- function (SPARK RM 6.1.4(10)).
2065 -------------------------
2066 -- Analyze_Global_Item --
2067 -------------------------
2069 procedure Analyze_Global_Item
2070 (Item : Node_Id;
2071 Global_Mode : Name_Id)
2073 Item_Id : Entity_Id;
2075 begin
2076 -- Detect one of the following cases
2078 -- with Global => (null, Name)
2079 -- with Global => (Name_1, null, Name_2)
2080 -- with Global => (Name, null)
2082 if Nkind (Item) = N_Null then
2083 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
2084 return;
2085 end if;
2087 Analyze (Item);
2088 Resolve_State (Item);
2090 -- Find the entity of the item. If this is a renaming, climb the
2091 -- renaming chain to reach the root object. Renamings of non-
2092 -- entire objects do not yield an entity (Empty).
2094 Item_Id := Entity_Of (Item);
2096 if Present (Item_Id) then
2098 -- A global item may denote a formal parameter of an enclosing
2099 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2100 -- provide a better error diagnostic.
2102 if Is_Formal (Item_Id) then
2103 if Scope (Item_Id) = Spec_Id then
2104 SPARK_Msg_NE
2105 (Fix_Msg (Spec_Id, "global item cannot reference "
2106 & "parameter of subprogram &"), Item, Spec_Id);
2107 return;
2108 end if;
2110 -- A global item may denote a concurrent type as long as it is
2111 -- the current instance of an enclosing protected or task type
2112 -- (SPARK RM 6.1.4).
2114 elsif Ekind_In (Item_Id, E_Protected_Type, E_Task_Type) then
2115 if Is_CCT_Instance (Item_Id, Spec_Id) then
2117 -- Pragma [Refined_]Global associated with a protected
2118 -- subprogram cannot mention the current instance of a
2119 -- protected type because the instance behaves as a
2120 -- formal parameter.
2122 if Ekind (Item_Id) = E_Protected_Type then
2123 Error_Msg_Name_1 := Chars (Item_Id);
2124 SPARK_Msg_NE
2125 (Fix_Msg (Spec_Id, "global item of subprogram & "
2126 & "cannot reference current instance of protected "
2127 & "type %"), Item, Spec_Id);
2128 return;
2130 -- Pragma [Refined_]Global associated with a task type
2131 -- cannot mention the current instance of a task type
2132 -- because the instance behaves as a formal parameter.
2134 else pragma Assert (Ekind (Item_Id) = E_Task_Type);
2135 Error_Msg_Name_1 := Chars (Item_Id);
2136 SPARK_Msg_NE
2137 (Fix_Msg (Spec_Id, "global item of subprogram & "
2138 & "cannot reference current instance of task type "
2139 & "%"), Item, Spec_Id);
2140 return;
2141 end if;
2143 -- Otherwise the global item denotes a subtype mark that is
2144 -- not a current instance.
2146 else
2147 SPARK_Msg_N
2148 ("invalid use of subtype mark in global list", Item);
2149 return;
2150 end if;
2152 -- A global item may denote the anonymous object created for a
2153 -- single protected/task type as long as the current instance
2154 -- is the same single type (SPARK RM 6.1.4).
2156 elsif Is_Single_Concurrent_Object (Item_Id)
2157 and then Is_CCT_Instance (Item_Id, Spec_Id)
2158 then
2159 -- Pragma [Refined_]Global associated with a protected
2160 -- subprogram cannot mention the current instance of a
2161 -- protected type because the instance behaves as a formal
2162 -- parameter.
2164 if Is_Single_Protected_Object (Item_Id) then
2165 Error_Msg_Name_1 := Chars (Item_Id);
2166 SPARK_Msg_NE
2167 (Fix_Msg (Spec_Id, "global item of subprogram & cannot "
2168 & "reference current instance of protected type %"),
2169 Item, Spec_Id);
2170 return;
2172 -- Pragma [Refined_]Global associated with a task type
2173 -- cannot mention the current instance of a task type
2174 -- because the instance behaves as a formal parameter.
2176 else pragma Assert (Is_Single_Task_Object (Item_Id));
2177 Error_Msg_Name_1 := Chars (Item_Id);
2178 SPARK_Msg_NE
2179 (Fix_Msg (Spec_Id, "global item of subprogram & cannot "
2180 & "reference current instance of task type %"),
2181 Item, Spec_Id);
2182 return;
2183 end if;
2185 -- A formal object may act as a global item inside a generic
2187 elsif Is_Formal_Object (Item_Id) then
2188 null;
2190 -- The only legal references are those to abstract states,
2191 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2193 elsif not Ekind_In (Item_Id, E_Abstract_State,
2194 E_Constant,
2195 E_Discriminant,
2196 E_Loop_Parameter,
2197 E_Variable)
2198 then
2199 SPARK_Msg_N
2200 ("global item must denote object, state or current "
2201 & "instance of concurrent type", Item);
2202 return;
2203 end if;
2205 -- State related checks
2207 if Ekind (Item_Id) = E_Abstract_State then
2209 -- Package and subprogram bodies are instantiated
2210 -- individually in a separate compiler pass. Due to this
2211 -- mode of instantiation, the refinement of a state may
2212 -- no longer be visible when a subprogram body contract
2213 -- is instantiated. Since the generic template is legal,
2214 -- do not perform this check in the instance to circumvent
2215 -- this oddity.
2217 if Is_Generic_Instance (Spec_Id) then
2218 null;
2220 -- An abstract state with visible refinement cannot appear
2221 -- in pragma [Refined_]Global as its place must be taken by
2222 -- some of its constituents (SPARK RM 6.1.4(7)).
2224 elsif Has_Visible_Refinement (Item_Id) then
2225 SPARK_Msg_NE
2226 ("cannot mention state & in global refinement",
2227 Item, Item_Id);
2228 SPARK_Msg_N ("\use its constituents instead", Item);
2229 return;
2231 -- An external state cannot appear as a global item of a
2232 -- nonvolatile function (SPARK RM 7.1.3(8)).
2234 elsif Is_External_State (Item_Id)
2235 and then Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2236 and then not Is_Volatile_Function (Spec_Id)
2237 then
2238 SPARK_Msg_NE
2239 ("external state & cannot act as global item of "
2240 & "nonvolatile function", Item, Item_Id);
2241 return;
2243 -- If the reference to the abstract state appears in an
2244 -- enclosing package body that will eventually refine the
2245 -- state, record the reference for future checks.
2247 else
2248 Record_Possible_Body_Reference
2249 (State_Id => Item_Id,
2250 Ref => Item);
2251 end if;
2253 -- Constant related checks
2255 elsif Ekind (Item_Id) = E_Constant then
2257 -- A constant is a read-only item, therefore it cannot act
2258 -- as an output.
2260 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2261 SPARK_Msg_NE
2262 ("constant & cannot act as output", Item, Item_Id);
2263 return;
2264 end if;
2266 -- Discriminant related checks
2268 elsif Ekind (Item_Id) = E_Discriminant then
2270 -- A discriminant is a read-only item, therefore it cannot
2271 -- act as an output.
2273 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2274 SPARK_Msg_NE
2275 ("discriminant & cannot act as output", Item, Item_Id);
2276 return;
2277 end if;
2279 -- Loop parameter related checks
2281 elsif Ekind (Item_Id) = E_Loop_Parameter then
2283 -- A loop parameter is a read-only item, therefore it cannot
2284 -- act as an output.
2286 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2287 SPARK_Msg_NE
2288 ("loop parameter & cannot act as output",
2289 Item, Item_Id);
2290 return;
2291 end if;
2293 -- Variable related checks. These are only relevant when
2294 -- SPARK_Mode is on as they are not standard Ada legality
2295 -- rules.
2297 elsif SPARK_Mode = On
2298 and then Ekind (Item_Id) = E_Variable
2299 and then Is_Effectively_Volatile (Item_Id)
2300 then
2301 -- An effectively volatile object cannot appear as a global
2302 -- item of a nonvolatile function (SPARK RM 7.1.3(8)).
2304 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2305 and then not Is_Volatile_Function (Spec_Id)
2306 then
2307 Error_Msg_NE
2308 ("volatile object & cannot act as global item of a "
2309 & "function", Item, Item_Id);
2310 return;
2312 -- An effectively volatile object with external property
2313 -- Effective_Reads set to True must have mode Output or
2314 -- In_Out (SPARK RM 7.1.3(10)).
2316 elsif Effective_Reads_Enabled (Item_Id)
2317 and then Global_Mode = Name_Input
2318 then
2319 Error_Msg_NE
2320 ("volatile object & with property Effective_Reads must "
2321 & "have mode In_Out or Output", Item, Item_Id);
2322 return;
2323 end if;
2324 end if;
2326 -- When the item renames an entire object, replace the item
2327 -- with a reference to the object.
2329 if Entity (Item) /= Item_Id then
2330 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2331 Analyze (Item);
2332 end if;
2334 -- Some form of illegal construct masquerading as a name
2335 -- (SPARK RM 6.1.4(4)).
2337 else
2338 Error_Msg_N
2339 ("global item must denote object, state or current instance "
2340 & "of concurrent type", Item);
2341 return;
2342 end if;
2344 -- Verify that an output does not appear as an input in an
2345 -- enclosing subprogram.
2347 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2348 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
2349 end if;
2351 -- The same entity might be referenced through various way.
2352 -- Check the entity of the item rather than the item itself
2353 -- (SPARK RM 6.1.4(10)).
2355 if Contains (Seen, Item_Id) then
2356 SPARK_Msg_N ("duplicate global item", Item);
2358 -- Add the entity of the current item to the list of processed
2359 -- items.
2361 else
2362 Append_New_Elmt (Item_Id, Seen);
2364 if Ekind (Item_Id) = E_Abstract_State then
2365 Append_New_Elmt (Item_Id, States_Seen);
2367 -- The variable may eventually become a constituent of a single
2368 -- protected/task type. Record the reference now and verify its
2369 -- legality when analyzing the contract of the variable
2370 -- (SPARK RM 9.3).
2372 elsif Ekind (Item_Id) = E_Variable then
2373 Record_Possible_Part_Of_Reference
2374 (Var_Id => Item_Id,
2375 Ref => Item);
2376 end if;
2378 if Ekind_In (Item_Id, E_Abstract_State, E_Constant, E_Variable)
2379 and then Present (Encapsulating_State (Item_Id))
2380 then
2381 Append_New_Elmt (Item_Id, Constits_Seen);
2382 end if;
2383 end if;
2384 end Analyze_Global_Item;
2386 --------------------------
2387 -- Check_Duplicate_Mode --
2388 --------------------------
2390 procedure Check_Duplicate_Mode
2391 (Mode : Node_Id;
2392 Status : in out Boolean)
2394 begin
2395 if Status then
2396 SPARK_Msg_N ("duplicate global mode", Mode);
2397 end if;
2399 Status := True;
2400 end Check_Duplicate_Mode;
2402 -------------------------------------------------
2403 -- Check_Mode_Restriction_In_Enclosing_Context --
2404 -------------------------------------------------
2406 procedure Check_Mode_Restriction_In_Enclosing_Context
2407 (Item : Node_Id;
2408 Item_Id : Entity_Id)
2410 Context : Entity_Id;
2411 Dummy : Boolean;
2412 Inputs : Elist_Id := No_Elist;
2413 Outputs : Elist_Id := No_Elist;
2415 begin
2416 -- Traverse the scope stack looking for enclosing subprograms
2417 -- subject to pragma [Refined_]Global.
2419 Context := Scope (Subp_Id);
2420 while Present (Context) and then Context /= Standard_Standard loop
2421 if Is_Subprogram (Context)
2422 and then
2423 (Present (Get_Pragma (Context, Pragma_Global))
2424 or else
2425 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2426 then
2427 Collect_Subprogram_Inputs_Outputs
2428 (Subp_Id => Context,
2429 Subp_Inputs => Inputs,
2430 Subp_Outputs => Outputs,
2431 Global_Seen => Dummy);
2433 -- The item is classified as In_Out or Output but appears as
2434 -- an Input in an enclosing subprogram (SPARK RM 6.1.4(11)).
2436 if Appears_In (Inputs, Item_Id)
2437 and then not Appears_In (Outputs, Item_Id)
2438 then
2439 SPARK_Msg_NE
2440 ("global item & cannot have mode In_Out or Output",
2441 Item, Item_Id);
2443 SPARK_Msg_NE
2444 (Fix_Msg (Subp_Id, "\item already appears as input of "
2445 & "subprogram &"), Item, Context);
2447 -- Stop the traversal once an error has been detected
2449 exit;
2450 end if;
2451 end if;
2453 Context := Scope (Context);
2454 end loop;
2455 end Check_Mode_Restriction_In_Enclosing_Context;
2457 ----------------------------------------
2458 -- Check_Mode_Restriction_In_Function --
2459 ----------------------------------------
2461 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2462 begin
2463 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
2464 SPARK_Msg_N
2465 ("global mode & is not applicable to functions", Mode);
2466 end if;
2467 end Check_Mode_Restriction_In_Function;
2469 -- Local variables
2471 Assoc : Node_Id;
2472 Item : Node_Id;
2473 Mode : Node_Id;
2475 -- Start of processing for Analyze_Global_List
2477 begin
2478 if Nkind (List) = N_Null then
2479 Set_Analyzed (List);
2481 -- Single global item declaration
2483 elsif Nkind_In (List, N_Expanded_Name,
2484 N_Identifier,
2485 N_Selected_Component)
2486 then
2487 Analyze_Global_Item (List, Global_Mode);
2489 -- Simple global list or moded global list declaration
2491 elsif Nkind (List) = N_Aggregate then
2492 Set_Analyzed (List);
2494 -- The declaration of a simple global list appear as a collection
2495 -- of expressions.
2497 if Present (Expressions (List)) then
2498 if Present (Component_Associations (List)) then
2499 SPARK_Msg_N
2500 ("cannot mix moded and non-moded global lists", List);
2501 end if;
2503 Item := First (Expressions (List));
2504 while Present (Item) loop
2505 Analyze_Global_Item (Item, Global_Mode);
2506 Next (Item);
2507 end loop;
2509 -- The declaration of a moded global list appears as a collection
2510 -- of component associations where individual choices denote
2511 -- modes.
2513 elsif Present (Component_Associations (List)) then
2514 if Present (Expressions (List)) then
2515 SPARK_Msg_N
2516 ("cannot mix moded and non-moded global lists", List);
2517 end if;
2519 Assoc := First (Component_Associations (List));
2520 while Present (Assoc) loop
2521 Mode := First (Choices (Assoc));
2523 if Nkind (Mode) = N_Identifier then
2524 if Chars (Mode) = Name_In_Out then
2525 Check_Duplicate_Mode (Mode, In_Out_Seen);
2526 Check_Mode_Restriction_In_Function (Mode);
2528 elsif Chars (Mode) = Name_Input then
2529 Check_Duplicate_Mode (Mode, Input_Seen);
2531 elsif Chars (Mode) = Name_Output then
2532 Check_Duplicate_Mode (Mode, Output_Seen);
2533 Check_Mode_Restriction_In_Function (Mode);
2535 elsif Chars (Mode) = Name_Proof_In then
2536 Check_Duplicate_Mode (Mode, Proof_Seen);
2538 else
2539 SPARK_Msg_N ("invalid mode selector", Mode);
2540 end if;
2542 else
2543 SPARK_Msg_N ("invalid mode selector", Mode);
2544 end if;
2546 -- Items in a moded list appear as a collection of
2547 -- expressions. Reuse the existing machinery to analyze
2548 -- them.
2550 Analyze_Global_List
2551 (List => Expression (Assoc),
2552 Global_Mode => Chars (Mode));
2554 Next (Assoc);
2555 end loop;
2557 -- Invalid tree
2559 else
2560 raise Program_Error;
2561 end if;
2563 -- Any other attempt to declare a global item is illegal. This is a
2564 -- syntax error, always report.
2566 else
2567 Error_Msg_N ("malformed global list", List);
2568 end if;
2569 end Analyze_Global_List;
2571 -- Local variables
2573 Items : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
2575 Restore_Scope : Boolean := False;
2577 -- Start of processing for Analyze_Global_In_Decl_Part
2579 begin
2580 -- Do not analyze the pragma multiple times
2582 if Is_Analyzed_Pragma (N) then
2583 return;
2584 end if;
2586 -- There is nothing to be done for a null global list
2588 if Nkind (Items) = N_Null then
2589 Set_Analyzed (Items);
2591 -- Analyze the various forms of global lists and items. Note that some
2592 -- of these may be malformed in which case the analysis emits error
2593 -- messages.
2595 else
2596 -- When pragma [Refined_]Global appears on a single concurrent type,
2597 -- it is relocated to the anonymous object.
2599 if Is_Single_Concurrent_Object (Spec_Id) then
2600 null;
2602 -- Ensure that the formal parameters are visible when processing an
2603 -- item. This falls out of the general rule of aspects pertaining to
2604 -- subprogram declarations.
2606 elsif not In_Open_Scopes (Spec_Id) then
2607 Restore_Scope := True;
2608 Push_Scope (Spec_Id);
2610 if Ekind (Spec_Id) = E_Task_Type then
2611 if Has_Discriminants (Spec_Id) then
2612 Install_Discriminants (Spec_Id);
2613 end if;
2615 elsif Is_Generic_Subprogram (Spec_Id) then
2616 Install_Generic_Formals (Spec_Id);
2618 else
2619 Install_Formals (Spec_Id);
2620 end if;
2621 end if;
2623 Analyze_Global_List (Items);
2625 if Restore_Scope then
2626 End_Scope;
2627 end if;
2628 end if;
2630 -- Ensure that a state and a corresponding constituent do not appear
2631 -- together in pragma [Refined_]Global.
2633 Check_State_And_Constituent_Use
2634 (States => States_Seen,
2635 Constits => Constits_Seen,
2636 Context => N);
2638 Set_Is_Analyzed_Pragma (N);
2639 end Analyze_Global_In_Decl_Part;
2641 --------------------------------------------
2642 -- Analyze_Initial_Condition_In_Decl_Part --
2643 --------------------------------------------
2645 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2646 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2647 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2648 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
2650 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
2652 begin
2653 -- Do not analyze the pragma multiple times
2655 if Is_Analyzed_Pragma (N) then
2656 return;
2657 end if;
2659 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2660 -- analysis of the pragma, the Ghost mode at point of declaration and
2661 -- point of analysis may not necessarely be the same. Use the mode in
2662 -- effect at the point of declaration.
2664 Set_Ghost_Mode (N);
2666 -- The expression is preanalyzed because it has not been moved to its
2667 -- final place yet. A direct analysis may generate side effects and this
2668 -- is not desired at this point.
2670 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2671 Ghost_Mode := Save_Ghost_Mode;
2673 Set_Is_Analyzed_Pragma (N);
2674 end Analyze_Initial_Condition_In_Decl_Part;
2676 --------------------------------------
2677 -- Analyze_Initializes_In_Decl_Part --
2678 --------------------------------------
2680 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2681 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2682 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2684 Constits_Seen : Elist_Id := No_Elist;
2685 -- A list containing the entities of all constituents processed so far.
2686 -- It aids in detecting illegal usage of a state and a corresponding
2687 -- constituent in pragma Initializes.
2689 Items_Seen : Elist_Id := No_Elist;
2690 -- A list of all initialization items processed so far. This list is
2691 -- used to detect duplicate items.
2693 Non_Null_Seen : Boolean := False;
2694 Null_Seen : Boolean := False;
2695 -- Flags used to check the legality of a null initialization list
2697 States_And_Objs : Elist_Id := No_Elist;
2698 -- A list of all abstract states and objects declared in the visible
2699 -- declarations of the related package. This list is used to detect the
2700 -- legality of initialization items.
2702 States_Seen : Elist_Id := No_Elist;
2703 -- A list containing the entities of all states processed so far. It
2704 -- helps in detecting illegal usage of a state and a corresponding
2705 -- constituent in pragma Initializes.
2707 procedure Analyze_Initialization_Item (Item : Node_Id);
2708 -- Verify the legality of a single initialization item
2710 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2711 -- Verify the legality of a single initialization item followed by a
2712 -- list of input items.
2714 procedure Collect_States_And_Objects;
2715 -- Inspect the visible declarations of the related package and gather
2716 -- the entities of all abstract states and objects in States_And_Objs.
2718 ---------------------------------
2719 -- Analyze_Initialization_Item --
2720 ---------------------------------
2722 procedure Analyze_Initialization_Item (Item : Node_Id) is
2723 Item_Id : Entity_Id;
2725 begin
2726 -- Null initialization list
2728 if Nkind (Item) = N_Null then
2729 if Null_Seen then
2730 SPARK_Msg_N ("multiple null initializations not allowed", Item);
2732 elsif Non_Null_Seen then
2733 SPARK_Msg_N
2734 ("cannot mix null and non-null initialization items", Item);
2735 else
2736 Null_Seen := True;
2737 end if;
2739 -- Initialization item
2741 else
2742 Non_Null_Seen := True;
2744 if Null_Seen then
2745 SPARK_Msg_N
2746 ("cannot mix null and non-null initialization items", Item);
2747 end if;
2749 Analyze (Item);
2750 Resolve_State (Item);
2752 if Is_Entity_Name (Item) then
2753 Item_Id := Entity_Of (Item);
2755 if Ekind_In (Item_Id, E_Abstract_State,
2756 E_Constant,
2757 E_Variable)
2758 then
2759 -- The state or variable must be declared in the visible
2760 -- declarations of the package (SPARK RM 7.1.5(7)).
2762 if not Contains (States_And_Objs, Item_Id) then
2763 Error_Msg_Name_1 := Chars (Pack_Id);
2764 SPARK_Msg_NE
2765 ("initialization item & must appear in the visible "
2766 & "declarations of package %", Item, Item_Id);
2768 -- Detect a duplicate use of the same initialization item
2769 -- (SPARK RM 7.1.5(5)).
2771 elsif Contains (Items_Seen, Item_Id) then
2772 SPARK_Msg_N ("duplicate initialization item", Item);
2774 -- The item is legal, add it to the list of processed states
2775 -- and variables.
2777 else
2778 Append_New_Elmt (Item_Id, Items_Seen);
2780 if Ekind (Item_Id) = E_Abstract_State then
2781 Append_New_Elmt (Item_Id, States_Seen);
2782 end if;
2784 if Present (Encapsulating_State (Item_Id)) then
2785 Append_New_Elmt (Item_Id, Constits_Seen);
2786 end if;
2787 end if;
2789 -- The item references something that is not a state or object
2790 -- (SPARK RM 7.1.5(3)).
2792 else
2793 SPARK_Msg_N
2794 ("initialization item must denote object or state", Item);
2795 end if;
2797 -- Some form of illegal construct masquerading as a name
2798 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2800 else
2801 Error_Msg_N
2802 ("initialization item must denote object or state", Item);
2803 end if;
2804 end if;
2805 end Analyze_Initialization_Item;
2807 ---------------------------------------------
2808 -- Analyze_Initialization_Item_With_Inputs --
2809 ---------------------------------------------
2811 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2812 Inputs_Seen : Elist_Id := No_Elist;
2813 -- A list of all inputs processed so far. This list is used to detect
2814 -- duplicate uses of an input.
2816 Non_Null_Seen : Boolean := False;
2817 Null_Seen : Boolean := False;
2818 -- Flags used to check the legality of an input list
2820 procedure Analyze_Input_Item (Input : Node_Id);
2821 -- Verify the legality of a single input item
2823 ------------------------
2824 -- Analyze_Input_Item --
2825 ------------------------
2827 procedure Analyze_Input_Item (Input : Node_Id) is
2828 Input_Id : Entity_Id;
2829 Input_OK : Boolean := True;
2831 begin
2832 -- Null input list
2834 if Nkind (Input) = N_Null then
2835 if Null_Seen then
2836 SPARK_Msg_N
2837 ("multiple null initializations not allowed", Item);
2839 elsif Non_Null_Seen then
2840 SPARK_Msg_N
2841 ("cannot mix null and non-null initialization item", Item);
2842 else
2843 Null_Seen := True;
2844 end if;
2846 -- Input item
2848 else
2849 Non_Null_Seen := True;
2851 if Null_Seen then
2852 SPARK_Msg_N
2853 ("cannot mix null and non-null initialization item", Item);
2854 end if;
2856 Analyze (Input);
2857 Resolve_State (Input);
2859 if Is_Entity_Name (Input) then
2860 Input_Id := Entity_Of (Input);
2862 if Ekind_In (Input_Id, E_Abstract_State,
2863 E_Constant,
2864 E_Generic_In_Out_Parameter,
2865 E_Generic_In_Parameter,
2866 E_In_Parameter,
2867 E_In_Out_Parameter,
2868 E_Out_Parameter,
2869 E_Variable)
2870 then
2871 -- The input cannot denote states or objects declared
2872 -- within the related package (SPARK RM 7.1.5(4)).
2874 if Within_Scope (Input_Id, Current_Scope) then
2876 -- Do not consider generic formal parameters or their
2877 -- respective mappings to generic formals. Even though
2878 -- the formals appear within the scope of the package,
2879 -- it is allowed for an initialization item to depend
2880 -- on an input item.
2882 if Ekind_In (Input_Id, E_Generic_In_Out_Parameter,
2883 E_Generic_In_Parameter)
2884 then
2885 null;
2887 elsif Ekind_In (Input_Id, E_Constant, E_Variable)
2888 and then Present (Corresponding_Generic_Association
2889 (Declaration_Node (Input_Id)))
2890 then
2891 null;
2893 else
2894 Input_OK := False;
2895 Error_Msg_Name_1 := Chars (Pack_Id);
2896 SPARK_Msg_NE
2897 ("input item & cannot denote a visible object or "
2898 & "state of package %", Input, Input_Id);
2899 end if;
2900 end if;
2902 -- Detect a duplicate use of the same input item
2903 -- (SPARK RM 7.1.5(5)).
2905 if Contains (Inputs_Seen, Input_Id) then
2906 Input_OK := False;
2907 SPARK_Msg_N ("duplicate input item", Input);
2908 end if;
2910 -- Input is legal, add it to the list of processed inputs
2912 if Input_OK then
2913 Append_New_Elmt (Input_Id, Inputs_Seen);
2915 if Ekind (Input_Id) = E_Abstract_State then
2916 Append_New_Elmt (Input_Id, States_Seen);
2917 end if;
2919 if Ekind_In (Input_Id, E_Abstract_State,
2920 E_Constant,
2921 E_Variable)
2922 and then Present (Encapsulating_State (Input_Id))
2923 then
2924 Append_New_Elmt (Input_Id, Constits_Seen);
2925 end if;
2926 end if;
2928 -- The input references something that is not a state or an
2929 -- object (SPARK RM 7.1.5(3)).
2931 else
2932 SPARK_Msg_N
2933 ("input item must denote object or state", Input);
2934 end if;
2936 -- Some form of illegal construct masquerading as a name
2937 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2939 else
2940 Error_Msg_N
2941 ("input item must denote object or state", Input);
2942 end if;
2943 end if;
2944 end Analyze_Input_Item;
2946 -- Local variables
2948 Inputs : constant Node_Id := Expression (Item);
2949 Elmt : Node_Id;
2950 Input : Node_Id;
2952 Name_Seen : Boolean := False;
2953 -- A flag used to detect multiple item names
2955 -- Start of processing for Analyze_Initialization_Item_With_Inputs
2957 begin
2958 -- Inspect the name of an item with inputs
2960 Elmt := First (Choices (Item));
2961 while Present (Elmt) loop
2962 if Name_Seen then
2963 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
2964 else
2965 Name_Seen := True;
2966 Analyze_Initialization_Item (Elmt);
2967 end if;
2969 Next (Elmt);
2970 end loop;
2972 -- Multiple input items appear as an aggregate
2974 if Nkind (Inputs) = N_Aggregate then
2975 if Present (Expressions (Inputs)) then
2976 Input := First (Expressions (Inputs));
2977 while Present (Input) loop
2978 Analyze_Input_Item (Input);
2979 Next (Input);
2980 end loop;
2981 end if;
2983 if Present (Component_Associations (Inputs)) then
2984 SPARK_Msg_N
2985 ("inputs must appear in named association form", Inputs);
2986 end if;
2988 -- Single input item
2990 else
2991 Analyze_Input_Item (Inputs);
2992 end if;
2993 end Analyze_Initialization_Item_With_Inputs;
2995 --------------------------------
2996 -- Collect_States_And_Objects --
2997 --------------------------------
2999 procedure Collect_States_And_Objects is
3000 Pack_Spec : constant Node_Id := Specification (Pack_Decl);
3001 Decl : Node_Id;
3003 begin
3004 -- Collect the abstract states defined in the package (if any)
3006 if Present (Abstract_States (Pack_Id)) then
3007 States_And_Objs := New_Copy_Elist (Abstract_States (Pack_Id));
3008 end if;
3010 -- Collect all objects the appear in the visible declarations of the
3011 -- related package.
3013 if Present (Visible_Declarations (Pack_Spec)) then
3014 Decl := First (Visible_Declarations (Pack_Spec));
3015 while Present (Decl) loop
3016 if Comes_From_Source (Decl)
3017 and then Nkind (Decl) = N_Object_Declaration
3018 then
3019 Append_New_Elmt (Defining_Entity (Decl), States_And_Objs);
3020 end if;
3022 Next (Decl);
3023 end loop;
3024 end if;
3025 end Collect_States_And_Objects;
3027 -- Local variables
3029 Inits : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
3030 Init : Node_Id;
3032 -- Start of processing for Analyze_Initializes_In_Decl_Part
3034 begin
3035 -- Do not analyze the pragma multiple times
3037 if Is_Analyzed_Pragma (N) then
3038 return;
3039 end if;
3041 -- Nothing to do when the initialization list is empty
3043 if Nkind (Inits) = N_Null then
3044 return;
3045 end if;
3047 -- Single and multiple initialization clauses appear as an aggregate. If
3048 -- this is not the case, then either the parser or the analysis of the
3049 -- pragma failed to produce an aggregate.
3051 pragma Assert (Nkind (Inits) = N_Aggregate);
3053 -- Initialize the various lists used during analysis
3055 Collect_States_And_Objects;
3057 if Present (Expressions (Inits)) then
3058 Init := First (Expressions (Inits));
3059 while Present (Init) loop
3060 Analyze_Initialization_Item (Init);
3061 Next (Init);
3062 end loop;
3063 end if;
3065 if Present (Component_Associations (Inits)) then
3066 Init := First (Component_Associations (Inits));
3067 while Present (Init) loop
3068 Analyze_Initialization_Item_With_Inputs (Init);
3069 Next (Init);
3070 end loop;
3071 end if;
3073 -- Ensure that a state and a corresponding constituent do not appear
3074 -- together in pragma Initializes.
3076 Check_State_And_Constituent_Use
3077 (States => States_Seen,
3078 Constits => Constits_Seen,
3079 Context => N);
3081 Set_Is_Analyzed_Pragma (N);
3082 end Analyze_Initializes_In_Decl_Part;
3084 ---------------------
3085 -- Analyze_Part_Of --
3086 ---------------------
3088 procedure Analyze_Part_Of
3089 (Indic : Node_Id;
3090 Item_Id : Entity_Id;
3091 Encap : Node_Id;
3092 Encap_Id : out Entity_Id;
3093 Legal : out Boolean)
3095 Encap_Typ : Entity_Id;
3096 Item_Decl : Node_Id;
3097 Pack_Id : Entity_Id;
3098 Placement : State_Space_Kind;
3099 Parent_Unit : Entity_Id;
3101 begin
3102 -- Assume that the indicator is illegal
3104 Encap_Id := Empty;
3105 Legal := False;
3107 if Nkind_In (Encap, N_Expanded_Name,
3108 N_Identifier,
3109 N_Selected_Component)
3110 then
3111 Analyze (Encap);
3112 Resolve_State (Encap);
3114 Encap_Id := Entity (Encap);
3116 -- The encapsulator is an abstract state
3118 if Ekind (Encap_Id) = E_Abstract_State then
3119 null;
3121 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3123 elsif Is_Single_Concurrent_Object (Encap_Id) then
3124 null;
3126 -- Otherwise the encapsulator is not a legal choice
3128 else
3129 SPARK_Msg_N
3130 ("indicator Part_Of must denote abstract state, single "
3131 & "protected type or single task type", Encap);
3132 return;
3133 end if;
3135 -- This is a syntax error, always report
3137 else
3138 Error_Msg_N
3139 ("indicator Part_Of must denote abstract state, single protected "
3140 & "type or single task type", Encap);
3141 return;
3142 end if;
3144 -- Catch a case where indicator Part_Of denotes the abstract view of a
3145 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3147 if From_Limited_With (Encap_Id)
3148 and then Present (Non_Limited_View (Encap_Id))
3149 and then Ekind (Non_Limited_View (Encap_Id)) = E_Variable
3150 then
3151 SPARK_Msg_N ("indicator Part_Of must denote abstract state", Encap);
3152 SPARK_Msg_N ("\& denotes abstract view of object", Encap);
3153 return;
3154 end if;
3156 -- The encapsulator is an abstract state
3158 if Ekind (Encap_Id) = E_Abstract_State then
3160 -- Determine where the object, package instantiation or state lives
3161 -- with respect to the enclosing packages or package bodies.
3163 Find_Placement_In_State_Space
3164 (Item_Id => Item_Id,
3165 Placement => Placement,
3166 Pack_Id => Pack_Id);
3168 -- The item appears in a non-package construct with a declarative
3169 -- part (subprogram, block, etc). As such, the item is not allowed
3170 -- to be a part of an encapsulating state because the item is not
3171 -- visible.
3173 if Placement = Not_In_Package then
3174 SPARK_Msg_N
3175 ("indicator Part_Of cannot appear in this context "
3176 & "(SPARK RM 7.2.6(5))", Indic);
3177 Error_Msg_Name_1 := Chars (Scope (Encap_Id));
3178 SPARK_Msg_NE
3179 ("\& is not part of the hidden state of package %",
3180 Indic, Item_Id);
3182 -- The item appears in the visible state space of some package. In
3183 -- general this scenario does not warrant Part_Of except when the
3184 -- package is a private child unit and the encapsulating state is
3185 -- declared in a parent unit or a public descendant of that parent
3186 -- unit.
3188 elsif Placement = Visible_State_Space then
3189 if Is_Child_Unit (Pack_Id)
3190 and then Is_Private_Descendant (Pack_Id)
3191 then
3192 -- A variable or state abstraction which is part of the visible
3193 -- state of a private child unit (or one of its public
3194 -- descendants) must have its Part_Of indicator specified. The
3195 -- Part_Of indicator must denote a state abstraction declared
3196 -- by either the parent unit of the private unit or by a public
3197 -- descendant of that parent unit.
3199 -- Find nearest private ancestor (which can be the current unit
3200 -- itself).
3202 Parent_Unit := Pack_Id;
3203 while Present (Parent_Unit) loop
3204 exit when
3205 Private_Present
3206 (Parent (Unit_Declaration_Node (Parent_Unit)));
3207 Parent_Unit := Scope (Parent_Unit);
3208 end loop;
3210 Parent_Unit := Scope (Parent_Unit);
3212 if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then
3213 SPARK_Msg_NE
3214 ("indicator Part_Of must denote abstract state or public "
3215 & "descendant of & (SPARK RM 7.2.6(3))",
3216 Indic, Parent_Unit);
3218 elsif Scope (Encap_Id) = Parent_Unit
3219 or else
3220 (Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id))
3221 and then not Is_Private_Descendant (Scope (Encap_Id)))
3222 then
3223 null;
3225 else
3226 SPARK_Msg_NE
3227 ("indicator Part_Of must denote abstract state or public "
3228 & "descendant of & (SPARK RM 7.2.6(3))",
3229 Indic, Parent_Unit);
3230 end if;
3232 -- Indicator Part_Of is not needed when the related package is not
3233 -- a private child unit or a public descendant thereof.
3235 else
3236 SPARK_Msg_N
3237 ("indicator Part_Of cannot appear in this context "
3238 & "(SPARK RM 7.2.6(5))", Indic);
3239 Error_Msg_Name_1 := Chars (Pack_Id);
3240 SPARK_Msg_NE
3241 ("\& is declared in the visible part of package %",
3242 Indic, Item_Id);
3243 end if;
3245 -- When the item appears in the private state space of a package, the
3246 -- encapsulating state must be declared in the same package.
3248 elsif Placement = Private_State_Space then
3249 if Scope (Encap_Id) /= Pack_Id then
3250 SPARK_Msg_NE
3251 ("indicator Part_Of must designate an abstract state of "
3252 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3253 Error_Msg_Name_1 := Chars (Pack_Id);
3254 SPARK_Msg_NE
3255 ("\& is declared in the private part of package %",
3256 Indic, Item_Id);
3257 end if;
3259 -- Items declared in the body state space of a package do not need
3260 -- Part_Of indicators as the refinement has already been seen.
3262 else
3263 SPARK_Msg_N
3264 ("indicator Part_Of cannot appear in this context "
3265 & "(SPARK RM 7.2.6(5))", Indic);
3267 if Scope (Encap_Id) = Pack_Id then
3268 Error_Msg_Name_1 := Chars (Pack_Id);
3269 SPARK_Msg_NE
3270 ("\& is declared in the body of package %", Indic, Item_Id);
3271 end if;
3272 end if;
3274 -- The encapsulator is a single concurrent type
3276 else
3277 Encap_Typ := Etype (Encap_Id);
3279 -- Only abstract states and variables can act as constituents of an
3280 -- encapsulating single concurrent type.
3282 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
3283 null;
3285 -- The constituent is a constant
3287 elsif Ekind (Item_Id) = E_Constant then
3288 Error_Msg_Name_1 := Chars (Encap_Id);
3289 SPARK_Msg_NE
3290 (Fix_Msg (Encap_Typ, "consant & cannot act as constituent of "
3291 & "single protected type %"), Indic, Item_Id);
3293 -- The constituent is a package instantiation
3295 else
3296 Error_Msg_Name_1 := Chars (Encap_Id);
3297 SPARK_Msg_NE
3298 (Fix_Msg (Encap_Typ, "package instantiation & cannot act as "
3299 & "constituent of single protected type %"), Indic, Item_Id);
3300 end if;
3302 -- When the item denotes an abstract state of a nested package, use
3303 -- the declaration of the package to detect proper placement.
3305 -- package Pack is
3306 -- task T;
3307 -- package Nested
3308 -- with Abstract_State => (State with Part_Of => T)
3310 if Ekind (Item_Id) = E_Abstract_State then
3311 Item_Decl := Unit_Declaration_Node (Scope (Item_Id));
3312 else
3313 Item_Decl := Declaration_Node (Item_Id);
3314 end if;
3316 -- Both the item and its encapsulating single concurrent type must
3317 -- appear in the same declarative region (SPARK RM 9.3). Note that
3318 -- privacy is ignored.
3320 if Parent (Item_Decl) /= Parent (Declaration_Node (Encap_Id)) then
3321 Error_Msg_Name_1 := Chars (Encap_Id);
3322 SPARK_Msg_NE
3323 (Fix_Msg (Encap_Typ, "constituent & must be declared "
3324 & "immediately within the same region as single protected "
3325 & "type %"), Indic, Item_Id);
3326 end if;
3327 end if;
3329 Legal := True;
3330 end Analyze_Part_Of;
3332 ----------------------------------
3333 -- Analyze_Part_Of_In_Decl_Part --
3334 ----------------------------------
3336 procedure Analyze_Part_Of_In_Decl_Part
3337 (N : Node_Id;
3338 Freeze_Id : Entity_Id := Empty)
3340 Encap : constant Node_Id :=
3341 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
3342 Errors : constant Nat := Serious_Errors_Detected;
3343 Var_Decl : constant Node_Id := Find_Related_Context (N);
3344 Var_Id : constant Entity_Id := Defining_Entity (Var_Decl);
3345 Constits : Elist_Id;
3346 Encap_Id : Entity_Id;
3347 Legal : Boolean;
3349 begin
3350 -- Detect any discrepancies between the placement of the variable with
3351 -- respect to general state space and the encapsulating state or single
3352 -- concurrent type.
3354 Analyze_Part_Of
3355 (Indic => N,
3356 Item_Id => Var_Id,
3357 Encap => Encap,
3358 Encap_Id => Encap_Id,
3359 Legal => Legal);
3361 -- The Part_Of indicator turns the variable into a constituent of the
3362 -- encapsulating state or single concurrent type.
3364 if Legal then
3365 pragma Assert (Present (Encap_Id));
3366 Constits := Part_Of_Constituents (Encap_Id);
3368 if No (Constits) then
3369 Constits := New_Elmt_List;
3370 Set_Part_Of_Constituents (Encap_Id, Constits);
3371 end if;
3373 Append_Elmt (Var_Id, Constits);
3374 Set_Encapsulating_State (Var_Id, Encap_Id);
3375 end if;
3377 -- Emit a clarification message when the encapsulator is undefined,
3378 -- possibly due to contract "freezing".
3380 if Errors /= Serious_Errors_Detected
3381 and then Present (Freeze_Id)
3382 and then Has_Undefined_Reference (Encap)
3383 then
3384 Contract_Freeze_Error (Var_Id, Freeze_Id);
3385 end if;
3386 end Analyze_Part_Of_In_Decl_Part;
3388 --------------------
3389 -- Analyze_Pragma --
3390 --------------------
3392 procedure Analyze_Pragma (N : Node_Id) is
3393 Loc : constant Source_Ptr := Sloc (N);
3394 Prag_Id : Pragma_Id;
3396 Pname : Name_Id;
3397 -- Name of the source pragma, or name of the corresponding aspect for
3398 -- pragmas which originate in a source aspect. In the latter case, the
3399 -- name may be different from the pragma name.
3401 Pragma_Exit : exception;
3402 -- This exception is used to exit pragma processing completely. It
3403 -- is used when an error is detected, and no further processing is
3404 -- required. It is also used if an earlier error has left the tree in
3405 -- a state where the pragma should not be processed.
3407 Arg_Count : Nat;
3408 -- Number of pragma argument associations
3410 Arg1 : Node_Id;
3411 Arg2 : Node_Id;
3412 Arg3 : Node_Id;
3413 Arg4 : Node_Id;
3414 -- First four pragma arguments (pragma argument association nodes, or
3415 -- Empty if the corresponding argument does not exist).
3417 type Name_List is array (Natural range <>) of Name_Id;
3418 type Args_List is array (Natural range <>) of Node_Id;
3419 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3421 -----------------------
3422 -- Local Subprograms --
3423 -----------------------
3425 procedure Acquire_Warning_Match_String (Arg : Node_Id);
3426 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
3427 -- get the given string argument, and place it in Name_Buffer, adding
3428 -- leading and trailing asterisks if they are not already present. The
3429 -- caller has already checked that Arg is a static string expression.
3431 procedure Ada_2005_Pragma;
3432 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3433 -- Ada 95 mode, these are implementation defined pragmas, so should be
3434 -- caught by the No_Implementation_Pragmas restriction.
3436 procedure Ada_2012_Pragma;
3437 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3438 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3439 -- should be caught by the No_Implementation_Pragmas restriction.
3441 procedure Analyze_Depends_Global
3442 (Spec_Id : out Entity_Id;
3443 Subp_Decl : out Node_Id;
3444 Legal : out Boolean);
3445 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3446 -- legality of the placement and related context of the pragma. Spec_Id
3447 -- is the entity of the related subprogram. Subp_Decl is the declaration
3448 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3450 procedure Analyze_If_Present (Id : Pragma_Id);
3451 -- Inspect the remainder of the list containing pragma N and look for
3452 -- a pragma that matches Id. If found, analyze the pragma.
3454 procedure Analyze_Pre_Post_Condition;
3455 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3457 procedure Analyze_Refined_Depends_Global_Post
3458 (Spec_Id : out Entity_Id;
3459 Body_Id : out Entity_Id;
3460 Legal : out Boolean);
3461 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3462 -- Refined_Global and Refined_Post. Verify the legality of the placement
3463 -- and related context of the pragma. Spec_Id is the entity of the
3464 -- related subprogram. Body_Id is the entity of the subprogram body.
3465 -- Flag Legal is set when the pragma is legal.
3467 procedure Check_Ada_83_Warning;
3468 -- Issues a warning message for the current pragma if operating in Ada
3469 -- 83 mode (used for language pragmas that are not a standard part of
3470 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3471 -- of 95 pragma.
3473 procedure Check_Arg_Count (Required : Nat);
3474 -- Check argument count for pragma is equal to given parameter. If not,
3475 -- then issue an error message and raise Pragma_Exit.
3477 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3478 -- Arg which can either be a pragma argument association, in which case
3479 -- the check is applied to the expression of the association or an
3480 -- expression directly.
3482 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
3483 -- Check that an argument has the right form for an EXTERNAL_NAME
3484 -- parameter of an extended import/export pragma. The rule is that the
3485 -- name must be an identifier or string literal (in Ada 83 mode) or a
3486 -- static string expression (in Ada 95 mode).
3488 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
3489 -- Check the specified argument Arg to make sure that it is an
3490 -- identifier. If not give error and raise Pragma_Exit.
3492 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
3493 -- Check the specified argument Arg to make sure that it is an integer
3494 -- literal. If not give error and raise Pragma_Exit.
3496 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
3497 -- Check the specified argument Arg to make sure that it has the proper
3498 -- syntactic form for a local name and meets the semantic requirements
3499 -- for a local name. The local name is analyzed as part of the
3500 -- processing for this call. In addition, the local name is required
3501 -- to represent an entity at the library level.
3503 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
3504 -- Check the specified argument Arg to make sure that it has the proper
3505 -- syntactic form for a local name and meets the semantic requirements
3506 -- for a local name. The local name is analyzed as part of the
3507 -- processing for this call.
3509 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
3510 -- Check the specified argument Arg to make sure that it is a valid
3511 -- locking policy name. If not give error and raise Pragma_Exit.
3513 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
3514 -- Check the specified argument Arg to make sure that it is a valid
3515 -- elaboration policy name. If not give error and raise Pragma_Exit.
3517 procedure Check_Arg_Is_One_Of
3518 (Arg : Node_Id;
3519 N1, N2 : Name_Id);
3520 procedure Check_Arg_Is_One_Of
3521 (Arg : Node_Id;
3522 N1, N2, N3 : Name_Id);
3523 procedure Check_Arg_Is_One_Of
3524 (Arg : Node_Id;
3525 N1, N2, N3, N4 : Name_Id);
3526 procedure Check_Arg_Is_One_Of
3527 (Arg : Node_Id;
3528 N1, N2, N3, N4, N5 : Name_Id);
3529 -- Check the specified argument Arg to make sure that it is an
3530 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3531 -- present). If not then give error and raise Pragma_Exit.
3533 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
3534 -- Check the specified argument Arg to make sure that it is a valid
3535 -- queuing policy name. If not give error and raise Pragma_Exit.
3537 procedure Check_Arg_Is_OK_Static_Expression
3538 (Arg : Node_Id;
3539 Typ : Entity_Id := Empty);
3540 -- Check the specified argument Arg to make sure that it is a static
3541 -- expression of the given type (i.e. it will be analyzed and resolved
3542 -- using this type, which can be any valid argument to Resolve, e.g.
3543 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3544 -- Typ is left Empty, then any static expression is allowed. Includes
3545 -- checking that the argument does not raise Constraint_Error.
3547 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
3548 -- Check the specified argument Arg to make sure that it is a valid task
3549 -- dispatching policy name. If not give error and raise Pragma_Exit.
3551 procedure Check_Arg_Order (Names : Name_List);
3552 -- Checks for an instance of two arguments with identifiers for the
3553 -- current pragma which are not in the sequence indicated by Names,
3554 -- and if so, generates a fatal message about bad order of arguments.
3556 procedure Check_At_Least_N_Arguments (N : Nat);
3557 -- Check there are at least N arguments present
3559 procedure Check_At_Most_N_Arguments (N : Nat);
3560 -- Check there are no more than N arguments present
3562 procedure Check_Component
3563 (Comp : Node_Id;
3564 UU_Typ : Entity_Id;
3565 In_Variant_Part : Boolean := False);
3566 -- Examine an Unchecked_Union component for correct use of per-object
3567 -- constrained subtypes, and for restrictions on finalizable components.
3568 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3569 -- should be set when Comp comes from a record variant.
3571 procedure Check_Duplicate_Pragma (E : Entity_Id);
3572 -- Check if a rep item of the same name as the current pragma is already
3573 -- chained as a rep pragma to the given entity. If so give a message
3574 -- about the duplicate, and then raise Pragma_Exit so does not return.
3575 -- Note that if E is a type, then this routine avoids flagging a pragma
3576 -- which applies to a parent type from which E is derived.
3578 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
3579 -- Nam is an N_String_Literal node containing the external name set by
3580 -- an Import or Export pragma (or extended Import or Export pragma).
3581 -- This procedure checks for possible duplications if this is the export
3582 -- case, and if found, issues an appropriate error message.
3584 procedure Check_Expr_Is_OK_Static_Expression
3585 (Expr : Node_Id;
3586 Typ : Entity_Id := Empty);
3587 -- Check the specified expression Expr to make sure that it is a static
3588 -- expression of the given type (i.e. it will be analyzed and resolved
3589 -- using this type, which can be any valid argument to Resolve, e.g.
3590 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3591 -- Typ is left Empty, then any static expression is allowed. Includes
3592 -- checking that the expression does not raise Constraint_Error.
3594 procedure Check_First_Subtype (Arg : Node_Id);
3595 -- Checks that Arg, whose expression is an entity name, references a
3596 -- first subtype.
3598 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
3599 -- Checks that the given argument has an identifier, and if so, requires
3600 -- it to match the given identifier name. If there is no identifier, or
3601 -- a non-matching identifier, then an error message is given and
3602 -- Pragma_Exit is raised.
3604 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
3605 -- Checks that the given argument has an identifier, and if so, requires
3606 -- it to match one of the given identifier names. If there is no
3607 -- identifier, or a non-matching identifier, then an error message is
3608 -- given and Pragma_Exit is raised.
3610 procedure Check_In_Main_Program;
3611 -- Common checks for pragmas that appear within a main program
3612 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
3614 procedure Check_Interrupt_Or_Attach_Handler;
3615 -- Common processing for first argument of pragma Interrupt_Handler or
3616 -- pragma Attach_Handler.
3618 procedure Check_Loop_Pragma_Placement;
3619 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
3620 -- appear immediately within a construct restricted to loops, and that
3621 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
3623 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
3624 -- Check that pragma appears in a declarative part, or in a package
3625 -- specification, i.e. that it does not occur in a statement sequence
3626 -- in a body.
3628 procedure Check_No_Identifier (Arg : Node_Id);
3629 -- Checks that the given argument does not have an identifier. If
3630 -- an identifier is present, then an error message is issued, and
3631 -- Pragma_Exit is raised.
3633 procedure Check_No_Identifiers;
3634 -- Checks that none of the arguments to the pragma has an identifier.
3635 -- If any argument has an identifier, then an error message is issued,
3636 -- and Pragma_Exit is raised.
3638 procedure Check_No_Link_Name;
3639 -- Checks that no link name is specified
3641 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
3642 -- Checks if the given argument has an identifier, and if so, requires
3643 -- it to match the given identifier name. If there is a non-matching
3644 -- identifier, then an error message is given and Pragma_Exit is raised.
3646 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
3647 -- Checks if the given argument has an identifier, and if so, requires
3648 -- it to match the given identifier name. If there is a non-matching
3649 -- identifier, then an error message is given and Pragma_Exit is raised.
3650 -- In this version of the procedure, the identifier name is given as
3651 -- a string with lower case letters.
3653 procedure Check_Static_Boolean_Expression (Expr : Node_Id);
3654 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
3655 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
3656 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
3657 -- is an OK static boolean expression. Emit an error if this is not the
3658 -- case.
3660 procedure Check_Static_Constraint (Constr : Node_Id);
3661 -- Constr is a constraint from an N_Subtype_Indication node from a
3662 -- component constraint in an Unchecked_Union type. This routine checks
3663 -- that the constraint is static as required by the restrictions for
3664 -- Unchecked_Union.
3666 procedure Check_Valid_Configuration_Pragma;
3667 -- Legality checks for placement of a configuration pragma
3669 procedure Check_Valid_Library_Unit_Pragma;
3670 -- Legality checks for library unit pragmas. A special case arises for
3671 -- pragmas in generic instances that come from copies of the original
3672 -- library unit pragmas in the generic templates. In the case of other
3673 -- than library level instantiations these can appear in contexts which
3674 -- would normally be invalid (they only apply to the original template
3675 -- and to library level instantiations), and they are simply ignored,
3676 -- which is implemented by rewriting them as null statements.
3678 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
3679 -- Check an Unchecked_Union variant for lack of nested variants and
3680 -- presence of at least one component. UU_Typ is the related Unchecked_
3681 -- Union type.
3683 procedure Ensure_Aggregate_Form (Arg : Node_Id);
3684 -- Subsidiary routine to the processing of pragmas Abstract_State,
3685 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
3686 -- Refined_Global and Refined_State. Transform argument Arg into
3687 -- an aggregate if not one already. N_Null is never transformed.
3688 -- Arg may denote an aspect specification or a pragma argument
3689 -- association.
3691 procedure Error_Pragma (Msg : String);
3692 pragma No_Return (Error_Pragma);
3693 -- Outputs error message for current pragma. The message contains a %
3694 -- that will be replaced with the pragma name, and the flag is placed
3695 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
3696 -- calls Fix_Error (see spec of that procedure for details).
3698 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
3699 pragma No_Return (Error_Pragma_Arg);
3700 -- Outputs error message for current pragma. The message may contain
3701 -- a % that will be replaced with the pragma name. The parameter Arg
3702 -- may either be a pragma argument association, in which case the flag
3703 -- is placed on the expression of this association, or an expression,
3704 -- in which case the flag is placed directly on the expression. The
3705 -- message is placed using Error_Msg_N, so the message may also contain
3706 -- an & insertion character which will reference the given Arg value.
3707 -- After placing the message, Pragma_Exit is raised. Note: this routine
3708 -- calls Fix_Error (see spec of that procedure for details).
3710 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
3711 pragma No_Return (Error_Pragma_Arg);
3712 -- Similar to above form of Error_Pragma_Arg except that two messages
3713 -- are provided, the second is a continuation comment starting with \.
3715 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
3716 pragma No_Return (Error_Pragma_Arg_Ident);
3717 -- Outputs error message for current pragma. The message may contain a %
3718 -- that will be replaced with the pragma name. The parameter Arg must be
3719 -- a pragma argument association with a non-empty identifier (i.e. its
3720 -- Chars field must be set), and the error message is placed on the
3721 -- identifier. The message is placed using Error_Msg_N so the message
3722 -- may also contain an & insertion character which will reference
3723 -- the identifier. After placing the message, Pragma_Exit is raised.
3724 -- Note: this routine calls Fix_Error (see spec of that procedure for
3725 -- details).
3727 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
3728 pragma No_Return (Error_Pragma_Ref);
3729 -- Outputs error message for current pragma. The message may contain
3730 -- a % that will be replaced with the pragma name. The parameter Ref
3731 -- must be an entity whose name can be referenced by & and sloc by #.
3732 -- After placing the message, Pragma_Exit is raised. Note: this routine
3733 -- calls Fix_Error (see spec of that procedure for details).
3735 function Find_Lib_Unit_Name return Entity_Id;
3736 -- Used for a library unit pragma to find the entity to which the
3737 -- library unit pragma applies, returns the entity found.
3739 procedure Find_Program_Unit_Name (Id : Node_Id);
3740 -- If the pragma is a compilation unit pragma, the id must denote the
3741 -- compilation unit in the same compilation, and the pragma must appear
3742 -- in the list of preceding or trailing pragmas. If it is a program
3743 -- unit pragma that is not a compilation unit pragma, then the
3744 -- identifier must be visible.
3746 function Find_Unique_Parameterless_Procedure
3747 (Name : Entity_Id;
3748 Arg : Node_Id) return Entity_Id;
3749 -- Used for a procedure pragma to find the unique parameterless
3750 -- procedure identified by Name, returns it if it exists, otherwise
3751 -- errors out and uses Arg as the pragma argument for the message.
3753 function Fix_Error (Msg : String) return String;
3754 -- This is called prior to issuing an error message. Msg is the normal
3755 -- error message issued in the pragma case. This routine checks for the
3756 -- case of a pragma coming from an aspect in the source, and returns a
3757 -- message suitable for the aspect case as follows:
3759 -- Each substring "pragma" is replaced by "aspect"
3761 -- If "argument of" is at the start of the error message text, it is
3762 -- replaced by "entity for".
3764 -- If "argument" is at the start of the error message text, it is
3765 -- replaced by "entity".
3767 -- So for example, "argument of pragma X must be discrete type"
3768 -- returns "entity for aspect X must be a discrete type".
3770 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
3771 -- be different from the pragma name). If the current pragma results
3772 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
3773 -- original pragma name.
3775 procedure Gather_Associations
3776 (Names : Name_List;
3777 Args : out Args_List);
3778 -- This procedure is used to gather the arguments for a pragma that
3779 -- permits arbitrary ordering of parameters using the normal rules
3780 -- for named and positional parameters. The Names argument is a list
3781 -- of Name_Id values that corresponds to the allowed pragma argument
3782 -- association identifiers in order. The result returned in Args is
3783 -- a list of corresponding expressions that are the pragma arguments.
3784 -- Note that this is a list of expressions, not of pragma argument
3785 -- associations (Gather_Associations has completely checked all the
3786 -- optional identifiers when it returns). An entry in Args is Empty
3787 -- on return if the corresponding argument is not present.
3789 procedure GNAT_Pragma;
3790 -- Called for all GNAT defined pragmas to check the relevant restriction
3791 -- (No_Implementation_Pragmas).
3793 function Is_Before_First_Decl
3794 (Pragma_Node : Node_Id;
3795 Decls : List_Id) return Boolean;
3796 -- Return True if Pragma_Node is before the first declarative item in
3797 -- Decls where Decls is the list of declarative items.
3799 function Is_Configuration_Pragma return Boolean;
3800 -- Determines if the placement of the current pragma is appropriate
3801 -- for a configuration pragma.
3803 function Is_In_Context_Clause return Boolean;
3804 -- Returns True if pragma appears within the context clause of a unit,
3805 -- and False for any other placement (does not generate any messages).
3807 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
3808 -- Analyzes the argument, and determines if it is a static string
3809 -- expression, returns True if so, False if non-static or not String.
3810 -- A special case is that a string literal returns True in Ada 83 mode
3811 -- (which has no such thing as static string expressions). Note that
3812 -- the call analyzes its argument, so this cannot be used for the case
3813 -- where an identifier might not be declared.
3815 procedure Pragma_Misplaced;
3816 pragma No_Return (Pragma_Misplaced);
3817 -- Issue fatal error message for misplaced pragma
3819 procedure Process_Atomic_Independent_Shared_Volatile;
3820 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
3821 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
3822 -- and treated as being identical in effect to pragma Atomic.
3824 procedure Process_Compile_Time_Warning_Or_Error;
3825 -- Common processing for Compile_Time_Error and Compile_Time_Warning
3827 procedure Process_Convention
3828 (C : out Convention_Id;
3829 Ent : out Entity_Id);
3830 -- Common processing for Convention, Interface, Import and Export.
3831 -- Checks first two arguments of pragma, and sets the appropriate
3832 -- convention value in the specified entity or entities. On return
3833 -- C is the convention, Ent is the referenced entity.
3835 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
3836 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
3837 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
3839 procedure Process_Extended_Import_Export_Object_Pragma
3840 (Arg_Internal : Node_Id;
3841 Arg_External : Node_Id;
3842 Arg_Size : Node_Id);
3843 -- Common processing for the pragmas Import/Export_Object. The three
3844 -- arguments correspond to the three named parameters of the pragmas. An
3845 -- argument is empty if the corresponding parameter is not present in
3846 -- the pragma.
3848 procedure Process_Extended_Import_Export_Internal_Arg
3849 (Arg_Internal : Node_Id := Empty);
3850 -- Common processing for all extended Import and Export pragmas. The
3851 -- argument is the pragma parameter for the Internal argument. If
3852 -- Arg_Internal is empty or inappropriate, an error message is posted.
3853 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
3854 -- set to identify the referenced entity.
3856 procedure Process_Extended_Import_Export_Subprogram_Pragma
3857 (Arg_Internal : Node_Id;
3858 Arg_External : Node_Id;
3859 Arg_Parameter_Types : Node_Id;
3860 Arg_Result_Type : Node_Id := Empty;
3861 Arg_Mechanism : Node_Id;
3862 Arg_Result_Mechanism : Node_Id := Empty);
3863 -- Common processing for all extended Import and Export pragmas applying
3864 -- to subprograms. The caller omits any arguments that do not apply to
3865 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
3866 -- only in the Import_Function and Export_Function cases). The argument
3867 -- names correspond to the allowed pragma association identifiers.
3869 procedure Process_Generic_List;
3870 -- Common processing for Share_Generic and Inline_Generic
3872 procedure Process_Import_Or_Interface;
3873 -- Common processing for Import or Interface
3875 procedure Process_Import_Predefined_Type;
3876 -- Processing for completing a type with pragma Import. This is used
3877 -- to declare types that match predefined C types, especially for cases
3878 -- without corresponding Ada predefined type.
3880 type Inline_Status is (Suppressed, Disabled, Enabled);
3881 -- Inline status of a subprogram, indicated as follows:
3882 -- Suppressed: inlining is suppressed for the subprogram
3883 -- Disabled: no inlining is requested for the subprogram
3884 -- Enabled: inlining is requested/required for the subprogram
3886 procedure Process_Inline (Status : Inline_Status);
3887 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
3888 -- indicates the inline status specified by the pragma.
3890 procedure Process_Interface_Name
3891 (Subprogram_Def : Entity_Id;
3892 Ext_Arg : Node_Id;
3893 Link_Arg : Node_Id);
3894 -- Given the last two arguments of pragma Import, pragma Export, or
3895 -- pragma Interface_Name, performs validity checks and sets the
3896 -- Interface_Name field of the given subprogram entity to the
3897 -- appropriate external or link name, depending on the arguments given.
3898 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
3899 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
3900 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
3901 -- nor Link_Arg is present, the interface name is set to the default
3902 -- from the subprogram name.
3904 procedure Process_Interrupt_Or_Attach_Handler;
3905 -- Common processing for Interrupt and Attach_Handler pragmas
3907 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
3908 -- Common processing for Restrictions and Restriction_Warnings pragmas.
3909 -- Warn is True for Restriction_Warnings, or for Restrictions if the
3910 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
3911 -- is not set in the Restrictions case.
3913 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
3914 -- Common processing for Suppress and Unsuppress. The boolean parameter
3915 -- Suppress_Case is True for the Suppress case, and False for the
3916 -- Unsuppress case.
3918 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id);
3919 -- Subsidiary to the analysis of pragmas Independent[_Components].
3920 -- Record such a pragma N applied to entity E for future checks.
3922 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
3923 -- This procedure sets the Is_Exported flag for the given entity,
3924 -- checking that the entity was not previously imported. Arg is
3925 -- the argument that specified the entity. A check is also made
3926 -- for exporting inappropriate entities.
3928 procedure Set_Extended_Import_Export_External_Name
3929 (Internal_Ent : Entity_Id;
3930 Arg_External : Node_Id);
3931 -- Common processing for all extended import export pragmas. The first
3932 -- argument, Internal_Ent, is the internal entity, which has already
3933 -- been checked for validity by the caller. Arg_External is from the
3934 -- Import or Export pragma, and may be null if no External parameter
3935 -- was present. If Arg_External is present and is a non-null string
3936 -- (a null string is treated as the default), then the Interface_Name
3937 -- field of Internal_Ent is set appropriately.
3939 procedure Set_Imported (E : Entity_Id);
3940 -- This procedure sets the Is_Imported flag for the given entity,
3941 -- checking that it is not previously exported or imported.
3943 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
3944 -- Mech is a parameter passing mechanism (see Import_Function syntax
3945 -- for MECHANISM_NAME). This routine checks that the mechanism argument
3946 -- has the right form, and if not issues an error message. If the
3947 -- argument has the right form then the Mechanism field of Ent is
3948 -- set appropriately.
3950 procedure Set_Rational_Profile;
3951 -- Activate the set of configuration pragmas and permissions that make
3952 -- up the Rational profile.
3954 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id);
3955 -- Activate the set of configuration pragmas and restrictions that make
3956 -- up the Profile. Profile must be either GNAT_Extended_Ravencar or
3957 -- Ravenscar. N is the corresponding pragma node, which is used for
3958 -- error messages on any constructs violating the profile.
3960 ----------------------------------
3961 -- Acquire_Warning_Match_String --
3962 ----------------------------------
3964 procedure Acquire_Warning_Match_String (Arg : Node_Id) is
3965 begin
3966 String_To_Name_Buffer
3967 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
3969 -- Add asterisk at start if not already there
3971 if Name_Len > 0 and then Name_Buffer (1) /= '*' then
3972 Name_Buffer (2 .. Name_Len + 1) :=
3973 Name_Buffer (1 .. Name_Len);
3974 Name_Buffer (1) := '*';
3975 Name_Len := Name_Len + 1;
3976 end if;
3978 -- Add asterisk at end if not already there
3980 if Name_Buffer (Name_Len) /= '*' then
3981 Name_Len := Name_Len + 1;
3982 Name_Buffer (Name_Len) := '*';
3983 end if;
3984 end Acquire_Warning_Match_String;
3986 ---------------------
3987 -- Ada_2005_Pragma --
3988 ---------------------
3990 procedure Ada_2005_Pragma is
3991 begin
3992 if Ada_Version <= Ada_95 then
3993 Check_Restriction (No_Implementation_Pragmas, N);
3994 end if;
3995 end Ada_2005_Pragma;
3997 ---------------------
3998 -- Ada_2012_Pragma --
3999 ---------------------
4001 procedure Ada_2012_Pragma is
4002 begin
4003 if Ada_Version <= Ada_2005 then
4004 Check_Restriction (No_Implementation_Pragmas, N);
4005 end if;
4006 end Ada_2012_Pragma;
4008 ----------------------------
4009 -- Analyze_Depends_Global --
4010 ----------------------------
4012 procedure Analyze_Depends_Global
4013 (Spec_Id : out Entity_Id;
4014 Subp_Decl : out Node_Id;
4015 Legal : out Boolean)
4017 begin
4018 -- Assume that the pragma is illegal
4020 Spec_Id := Empty;
4021 Subp_Decl := Empty;
4022 Legal := False;
4024 GNAT_Pragma;
4025 Check_Arg_Count (1);
4027 -- Ensure the proper placement of the pragma. Depends/Global must be
4028 -- associated with a subprogram declaration or a body that acts as a
4029 -- spec.
4031 Subp_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4033 -- Entry
4035 if Nkind (Subp_Decl) = N_Entry_Declaration then
4036 null;
4038 -- Generic subprogram
4040 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4041 null;
4043 -- Object declaration of a single concurrent type
4045 elsif Nkind (Subp_Decl) = N_Object_Declaration then
4046 null;
4048 -- Single task type
4050 elsif Nkind (Subp_Decl) = N_Single_Task_Declaration then
4051 null;
4053 -- Subprogram body acts as spec
4055 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4056 and then No (Corresponding_Spec (Subp_Decl))
4057 then
4058 null;
4060 -- Subprogram body stub acts as spec
4062 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4063 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
4064 then
4065 null;
4067 -- Subprogram declaration
4069 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4070 null;
4072 -- Task type
4074 elsif Nkind (Subp_Decl) = N_Task_Type_Declaration then
4075 null;
4077 else
4078 Pragma_Misplaced;
4079 return;
4080 end if;
4082 -- If we get here, then the pragma is legal
4084 Legal := True;
4085 Spec_Id := Unique_Defining_Entity (Subp_Decl);
4087 -- When the related context is an entry, the entry must belong to a
4088 -- protected unit (SPARK RM 6.1.4(6)).
4090 if Is_Entry_Declaration (Spec_Id)
4091 and then Ekind (Scope (Spec_Id)) /= E_Protected_Type
4092 then
4093 Pragma_Misplaced;
4094 return;
4096 -- When the related context is an anonymous object created for a
4097 -- simple concurrent type, the type must be a task
4098 -- (SPARK RM 6.1.4(6)).
4100 elsif Is_Single_Concurrent_Object (Spec_Id)
4101 and then Ekind (Etype (Spec_Id)) /= E_Task_Type
4102 then
4103 Pragma_Misplaced;
4104 return;
4105 end if;
4107 -- A pragma that applies to a Ghost entity becomes Ghost for the
4108 -- purposes of legality checks and removal of ignored Ghost code.
4110 Mark_Pragma_As_Ghost (N, Spec_Id);
4111 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4112 end Analyze_Depends_Global;
4114 ------------------------
4115 -- Analyze_If_Present --
4116 ------------------------
4118 procedure Analyze_If_Present (Id : Pragma_Id) is
4119 Stmt : Node_Id;
4121 begin
4122 pragma Assert (Is_List_Member (N));
4124 -- Inspect the declarations or statements following pragma N looking
4125 -- for another pragma whose Id matches the caller's request. If it is
4126 -- available, analyze it.
4128 Stmt := Next (N);
4129 while Present (Stmt) loop
4130 if Nkind (Stmt) = N_Pragma and then Get_Pragma_Id (Stmt) = Id then
4131 Analyze_Pragma (Stmt);
4132 exit;
4134 -- The first source declaration or statement immediately following
4135 -- N ends the region where a pragma may appear.
4137 elsif Comes_From_Source (Stmt) then
4138 exit;
4139 end if;
4141 Next (Stmt);
4142 end loop;
4143 end Analyze_If_Present;
4145 --------------------------------
4146 -- Analyze_Pre_Post_Condition --
4147 --------------------------------
4149 procedure Analyze_Pre_Post_Condition is
4150 Prag_Iden : constant Node_Id := Pragma_Identifier (N);
4151 Subp_Decl : Node_Id;
4152 Subp_Id : Entity_Id;
4154 Duplicates_OK : Boolean := False;
4155 -- Flag set when a pre/postcondition allows multiple pragmas of the
4156 -- same kind.
4158 In_Body_OK : Boolean := False;
4159 -- Flag set when a pre/postcondition is allowed to appear on a body
4160 -- even though the subprogram may have a spec.
4162 Is_Pre_Post : Boolean := False;
4163 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4164 -- Post_Class.
4166 begin
4167 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4168 -- offer uniformity among the various kinds of pre/postconditions by
4169 -- rewriting the pragma identifier. This allows the retrieval of the
4170 -- original pragma name by routine Original_Aspect_Pragma_Name.
4172 if Comes_From_Source (N) then
4173 if Nam_In (Pname, Name_Pre, Name_Pre_Class) then
4174 Is_Pre_Post := True;
4175 Set_Class_Present (N, Pname = Name_Pre_Class);
4176 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition));
4178 elsif Nam_In (Pname, Name_Post, Name_Post_Class) then
4179 Is_Pre_Post := True;
4180 Set_Class_Present (N, Pname = Name_Post_Class);
4181 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition));
4182 end if;
4183 end if;
4185 -- Determine the semantics with respect to duplicates and placement
4186 -- in a body. Pragmas Precondition and Postcondition were introduced
4187 -- before aspects and are not subject to the same aspect-like rules.
4189 if Nam_In (Pname, Name_Precondition, Name_Postcondition) then
4190 Duplicates_OK := True;
4191 In_Body_OK := True;
4192 end if;
4194 GNAT_Pragma;
4196 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4197 -- argument without an identifier.
4199 if Is_Pre_Post then
4200 Check_Arg_Count (1);
4201 Check_No_Identifiers;
4203 -- Pragmas Precondition and Postcondition have complex argument
4204 -- profile.
4206 else
4207 Check_At_Least_N_Arguments (1);
4208 Check_At_Most_N_Arguments (2);
4209 Check_Optional_Identifier (Arg1, Name_Check);
4211 if Present (Arg2) then
4212 Check_Optional_Identifier (Arg2, Name_Message);
4213 Preanalyze_Spec_Expression
4214 (Get_Pragma_Arg (Arg2), Standard_String);
4215 end if;
4216 end if;
4218 -- For a pragma PPC in the extended main source unit, record enabled
4219 -- status in SCO.
4220 -- ??? nothing checks that the pragma is in the main source unit
4222 if Is_Checked (N) and then not Split_PPC (N) then
4223 Set_SCO_Pragma_Enabled (Loc);
4224 end if;
4226 -- Ensure the proper placement of the pragma
4228 Subp_Decl :=
4229 Find_Related_Declaration_Or_Body
4230 (N, Do_Checks => not Duplicates_OK);
4232 -- When a pre/postcondition pragma applies to an abstract subprogram,
4233 -- its original form must be an aspect with 'Class.
4235 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
4236 if not From_Aspect_Specification (N) then
4237 Error_Pragma
4238 ("pragma % cannot be applied to abstract subprogram");
4240 elsif not Class_Present (N) then
4241 Error_Pragma
4242 ("aspect % requires ''Class for abstract subprogram");
4243 end if;
4245 -- Entry declaration
4247 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
4248 null;
4250 -- Generic subprogram declaration
4252 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4253 null;
4255 -- Subprogram body
4257 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4258 and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK)
4259 then
4260 null;
4262 -- Subprogram body stub
4264 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4265 and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK)
4266 then
4267 null;
4269 -- Subprogram declaration
4271 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4273 -- AI05-0230: When a pre/postcondition pragma applies to a null
4274 -- procedure, its original form must be an aspect with 'Class.
4276 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
4277 and then Null_Present (Specification (Subp_Decl))
4278 and then From_Aspect_Specification (N)
4279 and then not Class_Present (N)
4280 then
4281 Error_Pragma ("aspect % requires ''Class for null procedure");
4282 end if;
4284 -- Otherwise the placement is illegal
4286 else
4287 Pragma_Misplaced;
4288 return;
4289 end if;
4291 Subp_Id := Defining_Entity (Subp_Decl);
4293 -- Chain the pragma on the contract for further processing by
4294 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4296 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
4298 -- A pragma that applies to a Ghost entity becomes Ghost for the
4299 -- purposes of legality checks and removal of ignored Ghost code.
4301 Mark_Pragma_As_Ghost (N, Subp_Id);
4303 -- Fully analyze the pragma when it appears inside an entry or
4304 -- subprogram body because it cannot benefit from forward references.
4306 if Nkind_In (Subp_Decl, N_Entry_Body,
4307 N_Subprogram_Body,
4308 N_Subprogram_Body_Stub)
4309 then
4310 -- The legality checks of pragmas Precondition and Postcondition
4311 -- are affected by the SPARK mode in effect and the volatility of
4312 -- the context. Analyze all pragmas in a specific order.
4314 Analyze_If_Present (Pragma_SPARK_Mode);
4315 Analyze_If_Present (Pragma_Volatile_Function);
4316 Analyze_Pre_Post_Condition_In_Decl_Part (N);
4317 end if;
4318 end Analyze_Pre_Post_Condition;
4320 -----------------------------------------
4321 -- Analyze_Refined_Depends_Global_Post --
4322 -----------------------------------------
4324 procedure Analyze_Refined_Depends_Global_Post
4325 (Spec_Id : out Entity_Id;
4326 Body_Id : out Entity_Id;
4327 Legal : out Boolean)
4329 Body_Decl : Node_Id;
4330 Spec_Decl : Node_Id;
4332 begin
4333 -- Assume that the pragma is illegal
4335 Spec_Id := Empty;
4336 Body_Id := Empty;
4337 Legal := False;
4339 GNAT_Pragma;
4340 Check_Arg_Count (1);
4341 Check_No_Identifiers;
4343 -- Verify the placement of the pragma and check for duplicates. The
4344 -- pragma must apply to a subprogram body [stub].
4346 Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4348 -- Entry body
4350 if Nkind (Body_Decl) = N_Entry_Body then
4351 null;
4353 -- Subprogram body
4355 elsif Nkind (Body_Decl) = N_Subprogram_Body then
4356 null;
4358 -- Subprogram body stub
4360 elsif Nkind (Body_Decl) = N_Subprogram_Body_Stub then
4361 null;
4363 -- Task body
4365 elsif Nkind (Body_Decl) = N_Task_Body then
4366 null;
4368 else
4369 Pragma_Misplaced;
4370 return;
4371 end if;
4373 Body_Id := Defining_Entity (Body_Decl);
4374 Spec_Id := Unique_Defining_Entity (Body_Decl);
4376 -- The pragma must apply to the second declaration of a subprogram.
4377 -- In other words, the body [stub] cannot acts as a spec.
4379 if No (Spec_Id) then
4380 Error_Pragma ("pragma % cannot apply to a stand alone body");
4381 return;
4383 -- Catch the case where the subprogram body is a subunit and acts as
4384 -- the third declaration of the subprogram.
4386 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
4387 Error_Pragma ("pragma % cannot apply to a subunit");
4388 return;
4389 end if;
4391 -- A refined pragma can only apply to the body [stub] of a subprogram
4392 -- declared in the visible part of a package. Retrieve the context of
4393 -- the subprogram declaration.
4395 Spec_Decl := Unit_Declaration_Node (Spec_Id);
4397 -- When dealing with protected entries or protected subprograms, use
4398 -- the enclosing protected type as the proper context.
4400 if Ekind_In (Spec_Id, E_Entry,
4401 E_Entry_Family,
4402 E_Function,
4403 E_Procedure)
4404 and then Ekind (Scope (Spec_Id)) = E_Protected_Type
4405 then
4406 Spec_Decl := Declaration_Node (Scope (Spec_Id));
4407 end if;
4409 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
4410 Error_Pragma
4411 (Fix_Msg (Spec_Id, "pragma % must apply to the body of "
4412 & "subprogram declared in a package specification"));
4413 return;
4414 end if;
4416 -- If we get here, then the pragma is legal
4418 Legal := True;
4420 -- A pragma that applies to a Ghost entity becomes Ghost for the
4421 -- purposes of legality checks and removal of ignored Ghost code.
4423 Mark_Pragma_As_Ghost (N, Spec_Id);
4425 if Nam_In (Pname, Name_Refined_Depends, Name_Refined_Global) then
4426 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4427 end if;
4428 end Analyze_Refined_Depends_Global_Post;
4430 --------------------------
4431 -- Check_Ada_83_Warning --
4432 --------------------------
4434 procedure Check_Ada_83_Warning is
4435 begin
4436 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
4437 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
4438 end if;
4439 end Check_Ada_83_Warning;
4441 ---------------------
4442 -- Check_Arg_Count --
4443 ---------------------
4445 procedure Check_Arg_Count (Required : Nat) is
4446 begin
4447 if Arg_Count /= Required then
4448 Error_Pragma ("wrong number of arguments for pragma%");
4449 end if;
4450 end Check_Arg_Count;
4452 --------------------------------
4453 -- Check_Arg_Is_External_Name --
4454 --------------------------------
4456 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
4457 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4459 begin
4460 if Nkind (Argx) = N_Identifier then
4461 return;
4463 else
4464 Analyze_And_Resolve (Argx, Standard_String);
4466 if Is_OK_Static_Expression (Argx) then
4467 return;
4469 elsif Etype (Argx) = Any_Type then
4470 raise Pragma_Exit;
4472 -- An interesting special case, if we have a string literal and
4473 -- we are in Ada 83 mode, then we allow it even though it will
4474 -- not be flagged as static. This allows expected Ada 83 mode
4475 -- use of external names which are string literals, even though
4476 -- technically these are not static in Ada 83.
4478 elsif Ada_Version = Ada_83
4479 and then Nkind (Argx) = N_String_Literal
4480 then
4481 return;
4483 -- Static expression that raises Constraint_Error. This has
4484 -- already been flagged, so just exit from pragma processing.
4486 elsif Is_OK_Static_Expression (Argx) then
4487 raise Pragma_Exit;
4489 -- Here we have a real error (non-static expression)
4491 else
4492 Error_Msg_Name_1 := Pname;
4494 declare
4495 Msg : constant String :=
4496 "argument for pragma% must be a identifier or "
4497 & "static string expression!";
4498 begin
4499 Flag_Non_Static_Expr (Fix_Error (Msg), Argx);
4500 raise Pragma_Exit;
4501 end;
4502 end if;
4503 end if;
4504 end Check_Arg_Is_External_Name;
4506 -----------------------------
4507 -- Check_Arg_Is_Identifier --
4508 -----------------------------
4510 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
4511 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4512 begin
4513 if Nkind (Argx) /= N_Identifier then
4514 Error_Pragma_Arg
4515 ("argument for pragma% must be identifier", Argx);
4516 end if;
4517 end Check_Arg_Is_Identifier;
4519 ----------------------------------
4520 -- Check_Arg_Is_Integer_Literal --
4521 ----------------------------------
4523 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
4524 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4525 begin
4526 if Nkind (Argx) /= N_Integer_Literal then
4527 Error_Pragma_Arg
4528 ("argument for pragma% must be integer literal", Argx);
4529 end if;
4530 end Check_Arg_Is_Integer_Literal;
4532 -------------------------------------------
4533 -- Check_Arg_Is_Library_Level_Local_Name --
4534 -------------------------------------------
4536 -- LOCAL_NAME ::=
4537 -- DIRECT_NAME
4538 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
4539 -- | library_unit_NAME
4541 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
4542 begin
4543 Check_Arg_Is_Local_Name (Arg);
4545 -- If it came from an aspect, we want to give the error just as if it
4546 -- came from source.
4548 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
4549 and then (Comes_From_Source (N)
4550 or else Present (Corresponding_Aspect (Parent (Arg))))
4551 then
4552 Error_Pragma_Arg
4553 ("argument for pragma% must be library level entity", Arg);
4554 end if;
4555 end Check_Arg_Is_Library_Level_Local_Name;
4557 -----------------------------
4558 -- Check_Arg_Is_Local_Name --
4559 -----------------------------
4561 -- LOCAL_NAME ::=
4562 -- DIRECT_NAME
4563 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
4564 -- | library_unit_NAME
4566 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
4567 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4569 begin
4570 -- If this pragma came from an aspect specification, we don't want to
4571 -- check for this error, because that would cause spurious errors, in
4572 -- case a type is frozen in a scope more nested than the type. The
4573 -- aspect itself of course can't be anywhere but on the declaration
4574 -- itself.
4576 if Nkind (Arg) = N_Pragma_Argument_Association then
4577 if From_Aspect_Specification (Parent (Arg)) then
4578 return;
4579 end if;
4581 -- Arg is the Expression of an N_Pragma_Argument_Association
4583 else
4584 if From_Aspect_Specification (Parent (Parent (Arg))) then
4585 return;
4586 end if;
4587 end if;
4589 Analyze (Argx);
4591 if Nkind (Argx) not in N_Direct_Name
4592 and then (Nkind (Argx) /= N_Attribute_Reference
4593 or else Present (Expressions (Argx))
4594 or else Nkind (Prefix (Argx)) /= N_Identifier)
4595 and then (not Is_Entity_Name (Argx)
4596 or else not Is_Compilation_Unit (Entity (Argx)))
4597 then
4598 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
4599 end if;
4601 -- No further check required if not an entity name
4603 if not Is_Entity_Name (Argx) then
4604 null;
4606 else
4607 declare
4608 OK : Boolean;
4609 Ent : constant Entity_Id := Entity (Argx);
4610 Scop : constant Entity_Id := Scope (Ent);
4612 begin
4613 -- Case of a pragma applied to a compilation unit: pragma must
4614 -- occur immediately after the program unit in the compilation.
4616 if Is_Compilation_Unit (Ent) then
4617 declare
4618 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
4620 begin
4621 -- Case of pragma placed immediately after spec
4623 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
4624 OK := True;
4626 -- Case of pragma placed immediately after body
4628 elsif Nkind (Decl) = N_Subprogram_Declaration
4629 and then Present (Corresponding_Body (Decl))
4630 then
4631 OK := Parent (N) =
4632 Aux_Decls_Node
4633 (Parent (Unit_Declaration_Node
4634 (Corresponding_Body (Decl))));
4636 -- All other cases are illegal
4638 else
4639 OK := False;
4640 end if;
4641 end;
4643 -- Special restricted placement rule from 10.2.1(11.8/2)
4645 elsif Is_Generic_Formal (Ent)
4646 and then Prag_Id = Pragma_Preelaborable_Initialization
4647 then
4648 OK := List_Containing (N) =
4649 Generic_Formal_Declarations
4650 (Unit_Declaration_Node (Scop));
4652 -- If this is an aspect applied to a subprogram body, the
4653 -- pragma is inserted in its declarative part.
4655 elsif From_Aspect_Specification (N)
4656 and then Ent = Current_Scope
4657 and then
4658 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
4659 then
4660 OK := True;
4662 -- If the aspect is a predicate (possibly others ???) and the
4663 -- context is a record type, this is a discriminant expression
4664 -- within a type declaration, that freezes the predicated
4665 -- subtype.
4667 elsif From_Aspect_Specification (N)
4668 and then Prag_Id = Pragma_Predicate
4669 and then Ekind (Current_Scope) = E_Record_Type
4670 and then Scop = Scope (Current_Scope)
4671 then
4672 OK := True;
4674 -- Default case, just check that the pragma occurs in the scope
4675 -- of the entity denoted by the name.
4677 else
4678 OK := Current_Scope = Scop;
4679 end if;
4681 if not OK then
4682 Error_Pragma_Arg
4683 ("pragma% argument must be in same declarative part", Arg);
4684 end if;
4685 end;
4686 end if;
4687 end Check_Arg_Is_Local_Name;
4689 ---------------------------------
4690 -- Check_Arg_Is_Locking_Policy --
4691 ---------------------------------
4693 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
4694 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4696 begin
4697 Check_Arg_Is_Identifier (Argx);
4699 if not Is_Locking_Policy_Name (Chars (Argx)) then
4700 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
4701 end if;
4702 end Check_Arg_Is_Locking_Policy;
4704 -----------------------------------------------
4705 -- Check_Arg_Is_Partition_Elaboration_Policy --
4706 -----------------------------------------------
4708 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
4709 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4711 begin
4712 Check_Arg_Is_Identifier (Argx);
4714 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
4715 Error_Pragma_Arg
4716 ("& is not a valid partition elaboration policy name", Argx);
4717 end if;
4718 end Check_Arg_Is_Partition_Elaboration_Policy;
4720 -------------------------
4721 -- Check_Arg_Is_One_Of --
4722 -------------------------
4724 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
4725 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4727 begin
4728 Check_Arg_Is_Identifier (Argx);
4730 if not Nam_In (Chars (Argx), N1, N2) then
4731 Error_Msg_Name_2 := N1;
4732 Error_Msg_Name_3 := N2;
4733 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
4734 end if;
4735 end Check_Arg_Is_One_Of;
4737 procedure Check_Arg_Is_One_Of
4738 (Arg : Node_Id;
4739 N1, N2, N3 : Name_Id)
4741 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4743 begin
4744 Check_Arg_Is_Identifier (Argx);
4746 if not Nam_In (Chars (Argx), N1, N2, N3) then
4747 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
4748 end if;
4749 end Check_Arg_Is_One_Of;
4751 procedure Check_Arg_Is_One_Of
4752 (Arg : Node_Id;
4753 N1, N2, N3, N4 : Name_Id)
4755 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4757 begin
4758 Check_Arg_Is_Identifier (Argx);
4760 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
4761 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
4762 end if;
4763 end Check_Arg_Is_One_Of;
4765 procedure Check_Arg_Is_One_Of
4766 (Arg : Node_Id;
4767 N1, N2, N3, N4, N5 : Name_Id)
4769 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4771 begin
4772 Check_Arg_Is_Identifier (Argx);
4774 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
4775 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
4776 end if;
4777 end Check_Arg_Is_One_Of;
4779 ---------------------------------
4780 -- Check_Arg_Is_Queuing_Policy --
4781 ---------------------------------
4783 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
4784 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4786 begin
4787 Check_Arg_Is_Identifier (Argx);
4789 if not Is_Queuing_Policy_Name (Chars (Argx)) then
4790 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
4791 end if;
4792 end Check_Arg_Is_Queuing_Policy;
4794 ---------------------------------------
4795 -- Check_Arg_Is_OK_Static_Expression --
4796 ---------------------------------------
4798 procedure Check_Arg_Is_OK_Static_Expression
4799 (Arg : Node_Id;
4800 Typ : Entity_Id := Empty)
4802 begin
4803 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
4804 end Check_Arg_Is_OK_Static_Expression;
4806 ------------------------------------------
4807 -- Check_Arg_Is_Task_Dispatching_Policy --
4808 ------------------------------------------
4810 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
4811 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4813 begin
4814 Check_Arg_Is_Identifier (Argx);
4816 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
4817 Error_Pragma_Arg
4818 ("& is not an allowed task dispatching policy name", Argx);
4819 end if;
4820 end Check_Arg_Is_Task_Dispatching_Policy;
4822 ---------------------
4823 -- Check_Arg_Order --
4824 ---------------------
4826 procedure Check_Arg_Order (Names : Name_List) is
4827 Arg : Node_Id;
4829 Highest_So_Far : Natural := 0;
4830 -- Highest index in Names seen do far
4832 begin
4833 Arg := Arg1;
4834 for J in 1 .. Arg_Count loop
4835 if Chars (Arg) /= No_Name then
4836 for K in Names'Range loop
4837 if Chars (Arg) = Names (K) then
4838 if K < Highest_So_Far then
4839 Error_Msg_Name_1 := Pname;
4840 Error_Msg_N
4841 ("parameters out of order for pragma%", Arg);
4842 Error_Msg_Name_1 := Names (K);
4843 Error_Msg_Name_2 := Names (Highest_So_Far);
4844 Error_Msg_N ("\% must appear before %", Arg);
4845 raise Pragma_Exit;
4847 else
4848 Highest_So_Far := K;
4849 end if;
4850 end if;
4851 end loop;
4852 end if;
4854 Arg := Next (Arg);
4855 end loop;
4856 end Check_Arg_Order;
4858 --------------------------------
4859 -- Check_At_Least_N_Arguments --
4860 --------------------------------
4862 procedure Check_At_Least_N_Arguments (N : Nat) is
4863 begin
4864 if Arg_Count < N then
4865 Error_Pragma ("too few arguments for pragma%");
4866 end if;
4867 end Check_At_Least_N_Arguments;
4869 -------------------------------
4870 -- Check_At_Most_N_Arguments --
4871 -------------------------------
4873 procedure Check_At_Most_N_Arguments (N : Nat) is
4874 Arg : Node_Id;
4875 begin
4876 if Arg_Count > N then
4877 Arg := Arg1;
4878 for J in 1 .. N loop
4879 Next (Arg);
4880 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
4881 end loop;
4882 end if;
4883 end Check_At_Most_N_Arguments;
4885 ---------------------
4886 -- Check_Component --
4887 ---------------------
4889 procedure Check_Component
4890 (Comp : Node_Id;
4891 UU_Typ : Entity_Id;
4892 In_Variant_Part : Boolean := False)
4894 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
4895 Sindic : constant Node_Id :=
4896 Subtype_Indication (Component_Definition (Comp));
4897 Typ : constant Entity_Id := Etype (Comp_Id);
4899 begin
4900 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
4901 -- object constraint, then the component type shall be an Unchecked_
4902 -- Union.
4904 if Nkind (Sindic) = N_Subtype_Indication
4905 and then Has_Per_Object_Constraint (Comp_Id)
4906 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
4907 then
4908 Error_Msg_N
4909 ("component subtype subject to per-object constraint "
4910 & "must be an Unchecked_Union", Comp);
4912 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
4913 -- the body of a generic unit, or within the body of any of its
4914 -- descendant library units, no part of the type of a component
4915 -- declared in a variant_part of the unchecked union type shall be of
4916 -- a formal private type or formal private extension declared within
4917 -- the formal part of the generic unit.
4919 elsif Ada_Version >= Ada_2012
4920 and then In_Generic_Body (UU_Typ)
4921 and then In_Variant_Part
4922 and then Is_Private_Type (Typ)
4923 and then Is_Generic_Type (Typ)
4924 then
4925 Error_Msg_N
4926 ("component of unchecked union cannot be of generic type", Comp);
4928 elsif Needs_Finalization (Typ) then
4929 Error_Msg_N
4930 ("component of unchecked union cannot be controlled", Comp);
4932 elsif Has_Task (Typ) then
4933 Error_Msg_N
4934 ("component of unchecked union cannot have tasks", Comp);
4935 end if;
4936 end Check_Component;
4938 ----------------------------
4939 -- Check_Duplicate_Pragma --
4940 ----------------------------
4942 procedure Check_Duplicate_Pragma (E : Entity_Id) is
4943 Id : Entity_Id := E;
4944 P : Node_Id;
4946 begin
4947 -- Nothing to do if this pragma comes from an aspect specification,
4948 -- since we could not be duplicating a pragma, and we dealt with the
4949 -- case of duplicated aspects in Analyze_Aspect_Specifications.
4951 if From_Aspect_Specification (N) then
4952 return;
4953 end if;
4955 -- Otherwise current pragma may duplicate previous pragma or a
4956 -- previously given aspect specification or attribute definition
4957 -- clause for the same pragma.
4959 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
4961 if Present (P) then
4963 -- If the entity is a type, then we have to make sure that the
4964 -- ostensible duplicate is not for a parent type from which this
4965 -- type is derived.
4967 if Is_Type (E) then
4968 if Nkind (P) = N_Pragma then
4969 declare
4970 Args : constant List_Id :=
4971 Pragma_Argument_Associations (P);
4972 begin
4973 if Present (Args)
4974 and then Is_Entity_Name (Expression (First (Args)))
4975 and then Is_Type (Entity (Expression (First (Args))))
4976 and then Entity (Expression (First (Args))) /= E
4977 then
4978 return;
4979 end if;
4980 end;
4982 elsif Nkind (P) = N_Aspect_Specification
4983 and then Is_Type (Entity (P))
4984 and then Entity (P) /= E
4985 then
4986 return;
4987 end if;
4988 end if;
4990 -- Here we have a definite duplicate
4992 Error_Msg_Name_1 := Pragma_Name (N);
4993 Error_Msg_Sloc := Sloc (P);
4995 -- For a single protected or a single task object, the error is
4996 -- issued on the original entity.
4998 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
4999 Id := Defining_Identifier (Original_Node (Parent (Id)));
5000 end if;
5002 if Nkind (P) = N_Aspect_Specification
5003 or else From_Aspect_Specification (P)
5004 then
5005 Error_Msg_NE ("aspect% for & previously given#", N, Id);
5006 else
5007 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
5008 end if;
5010 raise Pragma_Exit;
5011 end if;
5012 end Check_Duplicate_Pragma;
5014 ----------------------------------
5015 -- Check_Duplicated_Export_Name --
5016 ----------------------------------
5018 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
5019 String_Val : constant String_Id := Strval (Nam);
5021 begin
5022 -- We are only interested in the export case, and in the case of
5023 -- generics, it is the instance, not the template, that is the
5024 -- problem (the template will generate a warning in any case).
5026 if not Inside_A_Generic
5027 and then (Prag_Id = Pragma_Export
5028 or else
5029 Prag_Id = Pragma_Export_Procedure
5030 or else
5031 Prag_Id = Pragma_Export_Valued_Procedure
5032 or else
5033 Prag_Id = Pragma_Export_Function)
5034 then
5035 for J in Externals.First .. Externals.Last loop
5036 if String_Equal (String_Val, Strval (Externals.Table (J))) then
5037 Error_Msg_Sloc := Sloc (Externals.Table (J));
5038 Error_Msg_N ("external name duplicates name given#", Nam);
5039 exit;
5040 end if;
5041 end loop;
5043 Externals.Append (Nam);
5044 end if;
5045 end Check_Duplicated_Export_Name;
5047 ----------------------------------------
5048 -- Check_Expr_Is_OK_Static_Expression --
5049 ----------------------------------------
5051 procedure Check_Expr_Is_OK_Static_Expression
5052 (Expr : Node_Id;
5053 Typ : Entity_Id := Empty)
5055 begin
5056 if Present (Typ) then
5057 Analyze_And_Resolve (Expr, Typ);
5058 else
5059 Analyze_And_Resolve (Expr);
5060 end if;
5062 if Is_OK_Static_Expression (Expr) then
5063 return;
5065 elsif Etype (Expr) = Any_Type then
5066 raise Pragma_Exit;
5068 -- An interesting special case, if we have a string literal and we
5069 -- are in Ada 83 mode, then we allow it even though it will not be
5070 -- flagged as static. This allows the use of Ada 95 pragmas like
5071 -- Import in Ada 83 mode. They will of course be flagged with
5072 -- warnings as usual, but will not cause errors.
5074 elsif Ada_Version = Ada_83
5075 and then Nkind (Expr) = N_String_Literal
5076 then
5077 return;
5079 -- Static expression that raises Constraint_Error. This has already
5080 -- been flagged, so just exit from pragma processing.
5082 elsif Is_OK_Static_Expression (Expr) then
5083 raise Pragma_Exit;
5085 -- Finally, we have a real error
5087 else
5088 Error_Msg_Name_1 := Pname;
5089 Flag_Non_Static_Expr
5090 (Fix_Error ("argument for pragma% must be a static expression!"),
5091 Expr);
5092 raise Pragma_Exit;
5093 end if;
5094 end Check_Expr_Is_OK_Static_Expression;
5096 -------------------------
5097 -- Check_First_Subtype --
5098 -------------------------
5100 procedure Check_First_Subtype (Arg : Node_Id) is
5101 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5102 Ent : constant Entity_Id := Entity (Argx);
5104 begin
5105 if Is_First_Subtype (Ent) then
5106 null;
5108 elsif Is_Type (Ent) then
5109 Error_Pragma_Arg
5110 ("pragma% cannot apply to subtype", Argx);
5112 elsif Is_Object (Ent) then
5113 Error_Pragma_Arg
5114 ("pragma% cannot apply to object, requires a type", Argx);
5116 else
5117 Error_Pragma_Arg
5118 ("pragma% cannot apply to&, requires a type", Argx);
5119 end if;
5120 end Check_First_Subtype;
5122 ----------------------
5123 -- Check_Identifier --
5124 ----------------------
5126 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
5127 begin
5128 if Present (Arg)
5129 and then Nkind (Arg) = N_Pragma_Argument_Association
5130 then
5131 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
5132 Error_Msg_Name_1 := Pname;
5133 Error_Msg_Name_2 := Id;
5134 Error_Msg_N ("pragma% argument expects identifier%", Arg);
5135 raise Pragma_Exit;
5136 end if;
5137 end if;
5138 end Check_Identifier;
5140 --------------------------------
5141 -- Check_Identifier_Is_One_Of --
5142 --------------------------------
5144 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5145 begin
5146 if Present (Arg)
5147 and then Nkind (Arg) = N_Pragma_Argument_Association
5148 then
5149 if Chars (Arg) = No_Name then
5150 Error_Msg_Name_1 := Pname;
5151 Error_Msg_N ("pragma% argument expects an identifier", Arg);
5152 raise Pragma_Exit;
5154 elsif Chars (Arg) /= N1
5155 and then Chars (Arg) /= N2
5156 then
5157 Error_Msg_Name_1 := Pname;
5158 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
5159 raise Pragma_Exit;
5160 end if;
5161 end if;
5162 end Check_Identifier_Is_One_Of;
5164 ---------------------------
5165 -- Check_In_Main_Program --
5166 ---------------------------
5168 procedure Check_In_Main_Program is
5169 P : constant Node_Id := Parent (N);
5171 begin
5172 -- Must be in subprogram body
5174 if Nkind (P) /= N_Subprogram_Body then
5175 Error_Pragma ("% pragma allowed only in subprogram");
5177 -- Otherwise warn if obviously not main program
5179 elsif Present (Parameter_Specifications (Specification (P)))
5180 or else not Is_Compilation_Unit (Defining_Entity (P))
5181 then
5182 Error_Msg_Name_1 := Pname;
5183 Error_Msg_N
5184 ("??pragma% is only effective in main program", N);
5185 end if;
5186 end Check_In_Main_Program;
5188 ---------------------------------------
5189 -- Check_Interrupt_Or_Attach_Handler --
5190 ---------------------------------------
5192 procedure Check_Interrupt_Or_Attach_Handler is
5193 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5194 Handler_Proc, Proc_Scope : Entity_Id;
5196 begin
5197 Analyze (Arg1_X);
5199 if Prag_Id = Pragma_Interrupt_Handler then
5200 Check_Restriction (No_Dynamic_Attachment, N);
5201 end if;
5203 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
5204 Proc_Scope := Scope (Handler_Proc);
5206 -- On AAMP only, a pragma Interrupt_Handler is supported for
5207 -- nonprotected parameterless procedures.
5209 if not AAMP_On_Target
5210 or else Prag_Id = Pragma_Attach_Handler
5211 then
5212 if Ekind (Proc_Scope) /= E_Protected_Type then
5213 Error_Pragma_Arg
5214 ("argument of pragma% must be protected procedure", Arg1);
5215 end if;
5217 -- For pragma case (as opposed to access case), check placement.
5218 -- We don't need to do that for aspects, because we have the
5219 -- check that they aspect applies an appropriate procedure.
5221 if not From_Aspect_Specification (N)
5222 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
5223 then
5224 Error_Pragma ("pragma% must be in protected definition");
5225 end if;
5226 end if;
5228 if not Is_Library_Level_Entity (Proc_Scope)
5229 or else (AAMP_On_Target
5230 and then not Is_Library_Level_Entity (Handler_Proc))
5231 then
5232 Error_Pragma_Arg
5233 ("argument for pragma% must be library level entity", Arg1);
5234 end if;
5236 -- AI05-0033: A pragma cannot appear within a generic body, because
5237 -- instance can be in a nested scope. The check that protected type
5238 -- is itself a library-level declaration is done elsewhere.
5240 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
5241 -- handle code prior to AI-0033. Analysis tools typically are not
5242 -- interested in this pragma in any case, so no need to worry too
5243 -- much about its placement.
5245 if Inside_A_Generic then
5246 if Ekind (Scope (Current_Scope)) = E_Generic_Package
5247 and then In_Package_Body (Scope (Current_Scope))
5248 and then not Relaxed_RM_Semantics
5249 then
5250 Error_Pragma ("pragma% cannot be used inside a generic");
5251 end if;
5252 end if;
5253 end Check_Interrupt_Or_Attach_Handler;
5255 ---------------------------------
5256 -- Check_Loop_Pragma_Placement --
5257 ---------------------------------
5259 procedure Check_Loop_Pragma_Placement is
5260 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
5261 -- Verify whether the current pragma is properly grouped with other
5262 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
5263 -- related loop where the pragma appears.
5265 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
5266 -- Determine whether an arbitrary statement Stmt denotes pragma
5267 -- Loop_Invariant or Loop_Variant.
5269 procedure Placement_Error (Constr : Node_Id);
5270 pragma No_Return (Placement_Error);
5271 -- Node Constr denotes the last loop restricted construct before we
5272 -- encountered an illegal relation between enclosing constructs. Emit
5273 -- an error depending on what Constr was.
5275 --------------------------------
5276 -- Check_Loop_Pragma_Grouping --
5277 --------------------------------
5279 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
5280 Stop_Search : exception;
5281 -- This exception is used to terminate the recursive descent of
5282 -- routine Check_Grouping.
5284 procedure Check_Grouping (L : List_Id);
5285 -- Find the first group of pragmas in list L and if successful,
5286 -- ensure that the current pragma is part of that group. The
5287 -- routine raises Stop_Search once such a check is performed to
5288 -- halt the recursive descent.
5290 procedure Grouping_Error (Prag : Node_Id);
5291 pragma No_Return (Grouping_Error);
5292 -- Emit an error concerning the current pragma indicating that it
5293 -- should be placed after pragma Prag.
5295 --------------------
5296 -- Check_Grouping --
5297 --------------------
5299 procedure Check_Grouping (L : List_Id) is
5300 HSS : Node_Id;
5301 Prag : Node_Id;
5302 Stmt : Node_Id;
5304 begin
5305 -- Inspect the list of declarations or statements looking for
5306 -- the first grouping of pragmas:
5308 -- loop
5309 -- pragma Loop_Invariant ...;
5310 -- pragma Loop_Variant ...;
5311 -- . . . -- (1)
5312 -- pragma Loop_Variant ...; -- current pragma
5314 -- If the current pragma is not in the grouping, then it must
5315 -- either appear in a different declarative or statement list
5316 -- or the construct at (1) is separating the pragma from the
5317 -- grouping.
5319 Stmt := First (L);
5320 while Present (Stmt) loop
5322 -- Pragmas Loop_Invariant and Loop_Variant may only appear
5323 -- inside a loop or a block housed inside a loop. Inspect
5324 -- the declarations and statements of the block as they may
5325 -- contain the first grouping.
5327 if Nkind (Stmt) = N_Block_Statement then
5328 HSS := Handled_Statement_Sequence (Stmt);
5330 Check_Grouping (Declarations (Stmt));
5332 if Present (HSS) then
5333 Check_Grouping (Statements (HSS));
5334 end if;
5336 -- First pragma of the first topmost grouping has been found
5338 elsif Is_Loop_Pragma (Stmt) then
5340 -- The group and the current pragma are not in the same
5341 -- declarative or statement list.
5343 if List_Containing (Stmt) /= List_Containing (N) then
5344 Grouping_Error (Stmt);
5346 -- Try to reach the current pragma from the first pragma
5347 -- of the grouping while skipping other members:
5349 -- pragma Loop_Invariant ...; -- first pragma
5350 -- pragma Loop_Variant ...; -- member
5351 -- . . .
5352 -- pragma Loop_Variant ...; -- current pragma
5354 else
5355 while Present (Stmt) loop
5357 -- The current pragma is either the first pragma
5358 -- of the group or is a member of the group. Stop
5359 -- the search as the placement is legal.
5361 if Stmt = N then
5362 raise Stop_Search;
5364 -- Skip group members, but keep track of the last
5365 -- pragma in the group.
5367 elsif Is_Loop_Pragma (Stmt) then
5368 Prag := Stmt;
5370 -- Skip declarations and statements generated by
5371 -- the compiler during expansion.
5373 elsif not Comes_From_Source (Stmt) then
5374 null;
5376 -- A non-pragma is separating the group from the
5377 -- current pragma, the placement is illegal.
5379 else
5380 Grouping_Error (Prag);
5381 end if;
5383 Next (Stmt);
5384 end loop;
5386 -- If the traversal did not reach the current pragma,
5387 -- then the list must be malformed.
5389 raise Program_Error;
5390 end if;
5391 end if;
5393 Next (Stmt);
5394 end loop;
5395 end Check_Grouping;
5397 --------------------
5398 -- Grouping_Error --
5399 --------------------
5401 procedure Grouping_Error (Prag : Node_Id) is
5402 begin
5403 Error_Msg_Sloc := Sloc (Prag);
5404 Error_Pragma ("pragma% must appear next to pragma#");
5405 end Grouping_Error;
5407 -- Start of processing for Check_Loop_Pragma_Grouping
5409 begin
5410 -- Inspect the statements of the loop or nested blocks housed
5411 -- within to determine whether the current pragma is part of the
5412 -- first topmost grouping of Loop_Invariant and Loop_Variant.
5414 Check_Grouping (Statements (Loop_Stmt));
5416 exception
5417 when Stop_Search => null;
5418 end Check_Loop_Pragma_Grouping;
5420 --------------------
5421 -- Is_Loop_Pragma --
5422 --------------------
5424 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
5425 begin
5426 -- Inspect the original node as Loop_Invariant and Loop_Variant
5427 -- pragmas are rewritten to null when assertions are disabled.
5429 if Nkind (Original_Node (Stmt)) = N_Pragma then
5430 return
5431 Nam_In (Pragma_Name (Original_Node (Stmt)),
5432 Name_Loop_Invariant,
5433 Name_Loop_Variant);
5434 else
5435 return False;
5436 end if;
5437 end Is_Loop_Pragma;
5439 ---------------------
5440 -- Placement_Error --
5441 ---------------------
5443 procedure Placement_Error (Constr : Node_Id) is
5444 LA : constant String := " with Loop_Entry";
5446 begin
5447 if Prag_Id = Pragma_Assert then
5448 Error_Msg_String (1 .. LA'Length) := LA;
5449 Error_Msg_Strlen := LA'Length;
5450 else
5451 Error_Msg_Strlen := 0;
5452 end if;
5454 if Nkind (Constr) = N_Pragma then
5455 Error_Pragma
5456 ("pragma %~ must appear immediately within the statements "
5457 & "of a loop");
5458 else
5459 Error_Pragma_Arg
5460 ("block containing pragma %~ must appear immediately within "
5461 & "the statements of a loop", Constr);
5462 end if;
5463 end Placement_Error;
5465 -- Local declarations
5467 Prev : Node_Id;
5468 Stmt : Node_Id;
5470 -- Start of processing for Check_Loop_Pragma_Placement
5472 begin
5473 -- Check that pragma appears immediately within a loop statement,
5474 -- ignoring intervening block statements.
5476 Prev := N;
5477 Stmt := Parent (N);
5478 while Present (Stmt) loop
5480 -- The pragma or previous block must appear immediately within the
5481 -- current block's declarative or statement part.
5483 if Nkind (Stmt) = N_Block_Statement then
5484 if (No (Declarations (Stmt))
5485 or else List_Containing (Prev) /= Declarations (Stmt))
5486 and then
5487 List_Containing (Prev) /=
5488 Statements (Handled_Statement_Sequence (Stmt))
5489 then
5490 Placement_Error (Prev);
5491 return;
5493 -- Keep inspecting the parents because we are now within a
5494 -- chain of nested blocks.
5496 else
5497 Prev := Stmt;
5498 Stmt := Parent (Stmt);
5499 end if;
5501 -- The pragma or previous block must appear immediately within the
5502 -- statements of the loop.
5504 elsif Nkind (Stmt) = N_Loop_Statement then
5505 if List_Containing (Prev) /= Statements (Stmt) then
5506 Placement_Error (Prev);
5507 end if;
5509 -- Stop the traversal because we reached the innermost loop
5510 -- regardless of whether we encountered an error or not.
5512 exit;
5514 -- Ignore a handled statement sequence. Note that this node may
5515 -- be related to a subprogram body in which case we will emit an
5516 -- error on the next iteration of the search.
5518 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
5519 Stmt := Parent (Stmt);
5521 -- Any other statement breaks the chain from the pragma to the
5522 -- loop.
5524 else
5525 Placement_Error (Prev);
5526 return;
5527 end if;
5528 end loop;
5530 -- Check that the current pragma Loop_Invariant or Loop_Variant is
5531 -- grouped together with other such pragmas.
5533 if Is_Loop_Pragma (N) then
5535 -- The previous check should have located the related loop
5537 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
5538 Check_Loop_Pragma_Grouping (Stmt);
5539 end if;
5540 end Check_Loop_Pragma_Placement;
5542 -------------------------------------------
5543 -- Check_Is_In_Decl_Part_Or_Package_Spec --
5544 -------------------------------------------
5546 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
5547 P : Node_Id;
5549 begin
5550 P := Parent (N);
5551 loop
5552 if No (P) then
5553 exit;
5555 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
5556 exit;
5558 elsif Nkind_In (P, N_Package_Specification,
5559 N_Block_Statement)
5560 then
5561 return;
5563 -- Note: the following tests seem a little peculiar, because
5564 -- they test for bodies, but if we were in the statement part
5565 -- of the body, we would already have hit the handled statement
5566 -- sequence, so the only way we get here is by being in the
5567 -- declarative part of the body.
5569 elsif Nkind_In (P, N_Subprogram_Body,
5570 N_Package_Body,
5571 N_Task_Body,
5572 N_Entry_Body)
5573 then
5574 return;
5575 end if;
5577 P := Parent (P);
5578 end loop;
5580 Error_Pragma ("pragma% is not in declarative part or package spec");
5581 end Check_Is_In_Decl_Part_Or_Package_Spec;
5583 -------------------------
5584 -- Check_No_Identifier --
5585 -------------------------
5587 procedure Check_No_Identifier (Arg : Node_Id) is
5588 begin
5589 if Nkind (Arg) = N_Pragma_Argument_Association
5590 and then Chars (Arg) /= No_Name
5591 then
5592 Error_Pragma_Arg_Ident
5593 ("pragma% does not permit identifier& here", Arg);
5594 end if;
5595 end Check_No_Identifier;
5597 --------------------------
5598 -- Check_No_Identifiers --
5599 --------------------------
5601 procedure Check_No_Identifiers is
5602 Arg_Node : Node_Id;
5603 begin
5604 Arg_Node := Arg1;
5605 for J in 1 .. Arg_Count loop
5606 Check_No_Identifier (Arg_Node);
5607 Next (Arg_Node);
5608 end loop;
5609 end Check_No_Identifiers;
5611 ------------------------
5612 -- Check_No_Link_Name --
5613 ------------------------
5615 procedure Check_No_Link_Name is
5616 begin
5617 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
5618 Arg4 := Arg3;
5619 end if;
5621 if Present (Arg4) then
5622 Error_Pragma_Arg
5623 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
5624 end if;
5625 end Check_No_Link_Name;
5627 -------------------------------
5628 -- Check_Optional_Identifier --
5629 -------------------------------
5631 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
5632 begin
5633 if Present (Arg)
5634 and then Nkind (Arg) = N_Pragma_Argument_Association
5635 and then Chars (Arg) /= No_Name
5636 then
5637 if Chars (Arg) /= Id then
5638 Error_Msg_Name_1 := Pname;
5639 Error_Msg_Name_2 := Id;
5640 Error_Msg_N ("pragma% argument expects identifier%", Arg);
5641 raise Pragma_Exit;
5642 end if;
5643 end if;
5644 end Check_Optional_Identifier;
5646 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
5647 begin
5648 Name_Buffer (1 .. Id'Length) := Id;
5649 Name_Len := Id'Length;
5650 Check_Optional_Identifier (Arg, Name_Find);
5651 end Check_Optional_Identifier;
5653 -------------------------------------
5654 -- Check_Static_Boolean_Expression --
5655 -------------------------------------
5657 procedure Check_Static_Boolean_Expression (Expr : Node_Id) is
5658 begin
5659 if Present (Expr) then
5660 Analyze_And_Resolve (Expr, Standard_Boolean);
5662 if not Is_OK_Static_Expression (Expr) then
5663 Error_Pragma_Arg
5664 ("expression of pragma % must be static", Expr);
5665 end if;
5666 end if;
5667 end Check_Static_Boolean_Expression;
5669 -----------------------------
5670 -- Check_Static_Constraint --
5671 -----------------------------
5673 -- Note: for convenience in writing this procedure, in addition to
5674 -- the officially (i.e. by spec) allowed argument which is always a
5675 -- constraint, it also allows ranges and discriminant associations.
5676 -- Above is not clear ???
5678 procedure Check_Static_Constraint (Constr : Node_Id) is
5680 procedure Require_Static (E : Node_Id);
5681 -- Require given expression to be static expression
5683 --------------------
5684 -- Require_Static --
5685 --------------------
5687 procedure Require_Static (E : Node_Id) is
5688 begin
5689 if not Is_OK_Static_Expression (E) then
5690 Flag_Non_Static_Expr
5691 ("non-static constraint not allowed in Unchecked_Union!", E);
5692 raise Pragma_Exit;
5693 end if;
5694 end Require_Static;
5696 -- Start of processing for Check_Static_Constraint
5698 begin
5699 case Nkind (Constr) is
5700 when N_Discriminant_Association =>
5701 Require_Static (Expression (Constr));
5703 when N_Range =>
5704 Require_Static (Low_Bound (Constr));
5705 Require_Static (High_Bound (Constr));
5707 when N_Attribute_Reference =>
5708 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
5709 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
5711 when N_Range_Constraint =>
5712 Check_Static_Constraint (Range_Expression (Constr));
5714 when N_Index_Or_Discriminant_Constraint =>
5715 declare
5716 IDC : Entity_Id;
5717 begin
5718 IDC := First (Constraints (Constr));
5719 while Present (IDC) loop
5720 Check_Static_Constraint (IDC);
5721 Next (IDC);
5722 end loop;
5723 end;
5725 when others =>
5726 null;
5727 end case;
5728 end Check_Static_Constraint;
5730 --------------------------------------
5731 -- Check_Valid_Configuration_Pragma --
5732 --------------------------------------
5734 -- A configuration pragma must appear in the context clause of a
5735 -- compilation unit, and only other pragmas may precede it. Note that
5736 -- the test also allows use in a configuration pragma file.
5738 procedure Check_Valid_Configuration_Pragma is
5739 begin
5740 if not Is_Configuration_Pragma then
5741 Error_Pragma ("incorrect placement for configuration pragma%");
5742 end if;
5743 end Check_Valid_Configuration_Pragma;
5745 -------------------------------------
5746 -- Check_Valid_Library_Unit_Pragma --
5747 -------------------------------------
5749 procedure Check_Valid_Library_Unit_Pragma is
5750 Plist : List_Id;
5751 Parent_Node : Node_Id;
5752 Unit_Name : Entity_Id;
5753 Unit_Kind : Node_Kind;
5754 Unit_Node : Node_Id;
5755 Sindex : Source_File_Index;
5757 begin
5758 if not Is_List_Member (N) then
5759 Pragma_Misplaced;
5761 else
5762 Plist := List_Containing (N);
5763 Parent_Node := Parent (Plist);
5765 if Parent_Node = Empty then
5766 Pragma_Misplaced;
5768 -- Case of pragma appearing after a compilation unit. In this case
5769 -- it must have an argument with the corresponding name and must
5770 -- be part of the following pragmas of its parent.
5772 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
5773 if Plist /= Pragmas_After (Parent_Node) then
5774 Pragma_Misplaced;
5776 elsif Arg_Count = 0 then
5777 Error_Pragma
5778 ("argument required if outside compilation unit");
5780 else
5781 Check_No_Identifiers;
5782 Check_Arg_Count (1);
5783 Unit_Node := Unit (Parent (Parent_Node));
5784 Unit_Kind := Nkind (Unit_Node);
5786 Analyze (Get_Pragma_Arg (Arg1));
5788 if Unit_Kind = N_Generic_Subprogram_Declaration
5789 or else Unit_Kind = N_Subprogram_Declaration
5790 then
5791 Unit_Name := Defining_Entity (Unit_Node);
5793 elsif Unit_Kind in N_Generic_Instantiation then
5794 Unit_Name := Defining_Entity (Unit_Node);
5796 else
5797 Unit_Name := Cunit_Entity (Current_Sem_Unit);
5798 end if;
5800 if Chars (Unit_Name) /=
5801 Chars (Entity (Get_Pragma_Arg (Arg1)))
5802 then
5803 Error_Pragma_Arg
5804 ("pragma% argument is not current unit name", Arg1);
5805 end if;
5807 if Ekind (Unit_Name) = E_Package
5808 and then Present (Renamed_Entity (Unit_Name))
5809 then
5810 Error_Pragma ("pragma% not allowed for renamed package");
5811 end if;
5812 end if;
5814 -- Pragma appears other than after a compilation unit
5816 else
5817 -- Here we check for the generic instantiation case and also
5818 -- for the case of processing a generic formal package. We
5819 -- detect these cases by noting that the Sloc on the node
5820 -- does not belong to the current compilation unit.
5822 Sindex := Source_Index (Current_Sem_Unit);
5824 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
5825 Rewrite (N, Make_Null_Statement (Loc));
5826 return;
5828 -- If before first declaration, the pragma applies to the
5829 -- enclosing unit, and the name if present must be this name.
5831 elsif Is_Before_First_Decl (N, Plist) then
5832 Unit_Node := Unit_Declaration_Node (Current_Scope);
5833 Unit_Kind := Nkind (Unit_Node);
5835 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
5836 Pragma_Misplaced;
5838 elsif Unit_Kind = N_Subprogram_Body
5839 and then not Acts_As_Spec (Unit_Node)
5840 then
5841 Pragma_Misplaced;
5843 elsif Nkind (Parent_Node) = N_Package_Body then
5844 Pragma_Misplaced;
5846 elsif Nkind (Parent_Node) = N_Package_Specification
5847 and then Plist = Private_Declarations (Parent_Node)
5848 then
5849 Pragma_Misplaced;
5851 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
5852 or else Nkind (Parent_Node) =
5853 N_Generic_Subprogram_Declaration)
5854 and then Plist = Generic_Formal_Declarations (Parent_Node)
5855 then
5856 Pragma_Misplaced;
5858 elsif Arg_Count > 0 then
5859 Analyze (Get_Pragma_Arg (Arg1));
5861 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
5862 Error_Pragma_Arg
5863 ("name in pragma% must be enclosing unit", Arg1);
5864 end if;
5866 -- It is legal to have no argument in this context
5868 else
5869 return;
5870 end if;
5872 -- Error if not before first declaration. This is because a
5873 -- library unit pragma argument must be the name of a library
5874 -- unit (RM 10.1.5(7)), but the only names permitted in this
5875 -- context are (RM 10.1.5(6)) names of subprogram declarations,
5876 -- generic subprogram declarations or generic instantiations.
5878 else
5879 Error_Pragma
5880 ("pragma% misplaced, must be before first declaration");
5881 end if;
5882 end if;
5883 end if;
5884 end Check_Valid_Library_Unit_Pragma;
5886 -------------------
5887 -- Check_Variant --
5888 -------------------
5890 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
5891 Clist : constant Node_Id := Component_List (Variant);
5892 Comp : Node_Id;
5894 begin
5895 Comp := First (Component_Items (Clist));
5896 while Present (Comp) loop
5897 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
5898 Next (Comp);
5899 end loop;
5900 end Check_Variant;
5902 ---------------------------
5903 -- Ensure_Aggregate_Form --
5904 ---------------------------
5906 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
5907 CFSD : constant Boolean := Get_Comes_From_Source_Default;
5908 Expr : constant Node_Id := Expression (Arg);
5909 Loc : constant Source_Ptr := Sloc (Expr);
5910 Comps : List_Id := No_List;
5911 Exprs : List_Id := No_List;
5912 Nam : Name_Id := No_Name;
5913 Nam_Loc : Source_Ptr;
5915 begin
5916 -- The pragma argument is in positional form:
5918 -- pragma Depends (Nam => ...)
5919 -- ^
5920 -- Chars field
5922 -- Note that the Sloc of the Chars field is the Sloc of the pragma
5923 -- argument association.
5925 if Nkind (Arg) = N_Pragma_Argument_Association then
5926 Nam := Chars (Arg);
5927 Nam_Loc := Sloc (Arg);
5929 -- Remove the pragma argument name as this will be captured in the
5930 -- aggregate.
5932 Set_Chars (Arg, No_Name);
5933 end if;
5935 -- The argument is already in aggregate form, but the presence of a
5936 -- name causes this to be interpreted as named association which in
5937 -- turn must be converted into an aggregate.
5939 -- pragma Global (In_Out => (A, B, C))
5940 -- ^ ^
5941 -- name aggregate
5943 -- pragma Global ((In_Out => (A, B, C)))
5944 -- ^ ^
5945 -- aggregate aggregate
5947 if Nkind (Expr) = N_Aggregate then
5948 if Nam = No_Name then
5949 return;
5950 end if;
5952 -- Do not transform a null argument into an aggregate as N_Null has
5953 -- special meaning in formal verification pragmas.
5955 elsif Nkind (Expr) = N_Null then
5956 return;
5957 end if;
5959 -- Everything comes from source if the original comes from source
5961 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
5963 -- Positional argument is transformed into an aggregate with an
5964 -- Expressions list.
5966 if Nam = No_Name then
5967 Exprs := New_List (Relocate_Node (Expr));
5969 -- An associative argument is transformed into an aggregate with
5970 -- Component_Associations.
5972 else
5973 Comps := New_List (
5974 Make_Component_Association (Loc,
5975 Choices => New_List (Make_Identifier (Nam_Loc, Nam)),
5976 Expression => Relocate_Node (Expr)));
5977 end if;
5979 Set_Expression (Arg,
5980 Make_Aggregate (Loc,
5981 Component_Associations => Comps,
5982 Expressions => Exprs));
5984 -- Restore Comes_From_Source default
5986 Set_Comes_From_Source_Default (CFSD);
5987 end Ensure_Aggregate_Form;
5989 ------------------
5990 -- Error_Pragma --
5991 ------------------
5993 procedure Error_Pragma (Msg : String) is
5994 begin
5995 Error_Msg_Name_1 := Pname;
5996 Error_Msg_N (Fix_Error (Msg), N);
5997 raise Pragma_Exit;
5998 end Error_Pragma;
6000 ----------------------
6001 -- Error_Pragma_Arg --
6002 ----------------------
6004 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
6005 begin
6006 Error_Msg_Name_1 := Pname;
6007 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
6008 raise Pragma_Exit;
6009 end Error_Pragma_Arg;
6011 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
6012 begin
6013 Error_Msg_Name_1 := Pname;
6014 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
6015 Error_Pragma_Arg (Msg2, Arg);
6016 end Error_Pragma_Arg;
6018 ----------------------------
6019 -- Error_Pragma_Arg_Ident --
6020 ----------------------------
6022 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
6023 begin
6024 Error_Msg_Name_1 := Pname;
6025 Error_Msg_N (Fix_Error (Msg), Arg);
6026 raise Pragma_Exit;
6027 end Error_Pragma_Arg_Ident;
6029 ----------------------
6030 -- Error_Pragma_Ref --
6031 ----------------------
6033 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
6034 begin
6035 Error_Msg_Name_1 := Pname;
6036 Error_Msg_Sloc := Sloc (Ref);
6037 Error_Msg_NE (Fix_Error (Msg), N, Ref);
6038 raise Pragma_Exit;
6039 end Error_Pragma_Ref;
6041 ------------------------
6042 -- Find_Lib_Unit_Name --
6043 ------------------------
6045 function Find_Lib_Unit_Name return Entity_Id is
6046 begin
6047 -- Return inner compilation unit entity, for case of nested
6048 -- categorization pragmas. This happens in generic unit.
6050 if Nkind (Parent (N)) = N_Package_Specification
6051 and then Defining_Entity (Parent (N)) /= Current_Scope
6052 then
6053 return Defining_Entity (Parent (N));
6054 else
6055 return Current_Scope;
6056 end if;
6057 end Find_Lib_Unit_Name;
6059 ----------------------------
6060 -- Find_Program_Unit_Name --
6061 ----------------------------
6063 procedure Find_Program_Unit_Name (Id : Node_Id) is
6064 Unit_Name : Entity_Id;
6065 Unit_Kind : Node_Kind;
6066 P : constant Node_Id := Parent (N);
6068 begin
6069 if Nkind (P) = N_Compilation_Unit then
6070 Unit_Kind := Nkind (Unit (P));
6072 if Nkind_In (Unit_Kind, N_Subprogram_Declaration,
6073 N_Package_Declaration)
6074 or else Unit_Kind in N_Generic_Declaration
6075 then
6076 Unit_Name := Defining_Entity (Unit (P));
6078 if Chars (Id) = Chars (Unit_Name) then
6079 Set_Entity (Id, Unit_Name);
6080 Set_Etype (Id, Etype (Unit_Name));
6081 else
6082 Set_Etype (Id, Any_Type);
6083 Error_Pragma
6084 ("cannot find program unit referenced by pragma%");
6085 end if;
6087 else
6088 Set_Etype (Id, Any_Type);
6089 Error_Pragma ("pragma% inapplicable to this unit");
6090 end if;
6092 else
6093 Analyze (Id);
6094 end if;
6095 end Find_Program_Unit_Name;
6097 -----------------------------------------
6098 -- Find_Unique_Parameterless_Procedure --
6099 -----------------------------------------
6101 function Find_Unique_Parameterless_Procedure
6102 (Name : Entity_Id;
6103 Arg : Node_Id) return Entity_Id
6105 Proc : Entity_Id := Empty;
6107 begin
6108 -- The body of this procedure needs some comments ???
6110 if not Is_Entity_Name (Name) then
6111 Error_Pragma_Arg
6112 ("argument of pragma% must be entity name", Arg);
6114 elsif not Is_Overloaded (Name) then
6115 Proc := Entity (Name);
6117 if Ekind (Proc) /= E_Procedure
6118 or else Present (First_Formal (Proc))
6119 then
6120 Error_Pragma_Arg
6121 ("argument of pragma% must be parameterless procedure", Arg);
6122 end if;
6124 else
6125 declare
6126 Found : Boolean := False;
6127 It : Interp;
6128 Index : Interp_Index;
6130 begin
6131 Get_First_Interp (Name, Index, It);
6132 while Present (It.Nam) loop
6133 Proc := It.Nam;
6135 if Ekind (Proc) = E_Procedure
6136 and then No (First_Formal (Proc))
6137 then
6138 if not Found then
6139 Found := True;
6140 Set_Entity (Name, Proc);
6141 Set_Is_Overloaded (Name, False);
6142 else
6143 Error_Pragma_Arg
6144 ("ambiguous handler name for pragma% ", Arg);
6145 end if;
6146 end if;
6148 Get_Next_Interp (Index, It);
6149 end loop;
6151 if not Found then
6152 Error_Pragma_Arg
6153 ("argument of pragma% must be parameterless procedure",
6154 Arg);
6155 else
6156 Proc := Entity (Name);
6157 end if;
6158 end;
6159 end if;
6161 return Proc;
6162 end Find_Unique_Parameterless_Procedure;
6164 ---------------
6165 -- Fix_Error --
6166 ---------------
6168 function Fix_Error (Msg : String) return String is
6169 Res : String (Msg'Range) := Msg;
6170 Res_Last : Natural := Msg'Last;
6171 J : Natural;
6173 begin
6174 -- If we have a rewriting of another pragma, go to that pragma
6176 if Is_Rewrite_Substitution (N)
6177 and then Nkind (Original_Node (N)) = N_Pragma
6178 then
6179 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
6180 end if;
6182 -- Case where pragma comes from an aspect specification
6184 if From_Aspect_Specification (N) then
6186 -- Change appearence of "pragma" in message to "aspect"
6188 J := Res'First;
6189 while J <= Res_Last - 5 loop
6190 if Res (J .. J + 5) = "pragma" then
6191 Res (J .. J + 5) := "aspect";
6192 J := J + 6;
6194 else
6195 J := J + 1;
6196 end if;
6197 end loop;
6199 -- Change "argument of" at start of message to "entity for"
6201 if Res'Length > 11
6202 and then Res (Res'First .. Res'First + 10) = "argument of"
6203 then
6204 Res (Res'First .. Res'First + 9) := "entity for";
6205 Res (Res'First + 10 .. Res_Last - 1) :=
6206 Res (Res'First + 11 .. Res_Last);
6207 Res_Last := Res_Last - 1;
6208 end if;
6210 -- Change "argument" at start of message to "entity"
6212 if Res'Length > 8
6213 and then Res (Res'First .. Res'First + 7) = "argument"
6214 then
6215 Res (Res'First .. Res'First + 5) := "entity";
6216 Res (Res'First + 6 .. Res_Last - 2) :=
6217 Res (Res'First + 8 .. Res_Last);
6218 Res_Last := Res_Last - 2;
6219 end if;
6221 -- Get name from corresponding aspect
6223 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
6224 end if;
6226 -- Return possibly modified message
6228 return Res (Res'First .. Res_Last);
6229 end Fix_Error;
6231 -------------------------
6232 -- Gather_Associations --
6233 -------------------------
6235 procedure Gather_Associations
6236 (Names : Name_List;
6237 Args : out Args_List)
6239 Arg : Node_Id;
6241 begin
6242 -- Initialize all parameters to Empty
6244 for J in Args'Range loop
6245 Args (J) := Empty;
6246 end loop;
6248 -- That's all we have to do if there are no argument associations
6250 if No (Pragma_Argument_Associations (N)) then
6251 return;
6252 end if;
6254 -- Otherwise first deal with any positional parameters present
6256 Arg := First (Pragma_Argument_Associations (N));
6257 for Index in Args'Range loop
6258 exit when No (Arg) or else Chars (Arg) /= No_Name;
6259 Args (Index) := Get_Pragma_Arg (Arg);
6260 Next (Arg);
6261 end loop;
6263 -- Positional parameters all processed, if any left, then we
6264 -- have too many positional parameters.
6266 if Present (Arg) and then Chars (Arg) = No_Name then
6267 Error_Pragma_Arg
6268 ("too many positional associations for pragma%", Arg);
6269 end if;
6271 -- Process named parameters if any are present
6273 while Present (Arg) loop
6274 if Chars (Arg) = No_Name then
6275 Error_Pragma_Arg
6276 ("positional association cannot follow named association",
6277 Arg);
6279 else
6280 for Index in Names'Range loop
6281 if Names (Index) = Chars (Arg) then
6282 if Present (Args (Index)) then
6283 Error_Pragma_Arg
6284 ("duplicate argument association for pragma%", Arg);
6285 else
6286 Args (Index) := Get_Pragma_Arg (Arg);
6287 exit;
6288 end if;
6289 end if;
6291 if Index = Names'Last then
6292 Error_Msg_Name_1 := Pname;
6293 Error_Msg_N ("pragma% does not allow & argument", Arg);
6295 -- Check for possible misspelling
6297 for Index1 in Names'Range loop
6298 if Is_Bad_Spelling_Of
6299 (Chars (Arg), Names (Index1))
6300 then
6301 Error_Msg_Name_1 := Names (Index1);
6302 Error_Msg_N -- CODEFIX
6303 ("\possible misspelling of%", Arg);
6304 exit;
6305 end if;
6306 end loop;
6308 raise Pragma_Exit;
6309 end if;
6310 end loop;
6311 end if;
6313 Next (Arg);
6314 end loop;
6315 end Gather_Associations;
6317 -----------------
6318 -- GNAT_Pragma --
6319 -----------------
6321 procedure GNAT_Pragma is
6322 begin
6323 -- We need to check the No_Implementation_Pragmas restriction for
6324 -- the case of a pragma from source. Note that the case of aspects
6325 -- generating corresponding pragmas marks these pragmas as not being
6326 -- from source, so this test also catches that case.
6328 if Comes_From_Source (N) then
6329 Check_Restriction (No_Implementation_Pragmas, N);
6330 end if;
6331 end GNAT_Pragma;
6333 --------------------------
6334 -- Is_Before_First_Decl --
6335 --------------------------
6337 function Is_Before_First_Decl
6338 (Pragma_Node : Node_Id;
6339 Decls : List_Id) return Boolean
6341 Item : Node_Id := First (Decls);
6343 begin
6344 -- Only other pragmas can come before this pragma
6346 loop
6347 if No (Item) or else Nkind (Item) /= N_Pragma then
6348 return False;
6350 elsif Item = Pragma_Node then
6351 return True;
6352 end if;
6354 Next (Item);
6355 end loop;
6356 end Is_Before_First_Decl;
6358 -----------------------------
6359 -- Is_Configuration_Pragma --
6360 -----------------------------
6362 -- A configuration pragma must appear in the context clause of a
6363 -- compilation unit, and only other pragmas may precede it. Note that
6364 -- the test below also permits use in a configuration pragma file.
6366 function Is_Configuration_Pragma return Boolean is
6367 Lis : constant List_Id := List_Containing (N);
6368 Par : constant Node_Id := Parent (N);
6369 Prg : Node_Id;
6371 begin
6372 -- If no parent, then we are in the configuration pragma file,
6373 -- so the placement is definitely appropriate.
6375 if No (Par) then
6376 return True;
6378 -- Otherwise we must be in the context clause of a compilation unit
6379 -- and the only thing allowed before us in the context list is more
6380 -- configuration pragmas.
6382 elsif Nkind (Par) = N_Compilation_Unit
6383 and then Context_Items (Par) = Lis
6384 then
6385 Prg := First (Lis);
6387 loop
6388 if Prg = N then
6389 return True;
6390 elsif Nkind (Prg) /= N_Pragma then
6391 return False;
6392 end if;
6394 Next (Prg);
6395 end loop;
6397 else
6398 return False;
6399 end if;
6400 end Is_Configuration_Pragma;
6402 --------------------------
6403 -- Is_In_Context_Clause --
6404 --------------------------
6406 function Is_In_Context_Clause return Boolean is
6407 Plist : List_Id;
6408 Parent_Node : Node_Id;
6410 begin
6411 if not Is_List_Member (N) then
6412 return False;
6414 else
6415 Plist := List_Containing (N);
6416 Parent_Node := Parent (Plist);
6418 if Parent_Node = Empty
6419 or else Nkind (Parent_Node) /= N_Compilation_Unit
6420 or else Context_Items (Parent_Node) /= Plist
6421 then
6422 return False;
6423 end if;
6424 end if;
6426 return True;
6427 end Is_In_Context_Clause;
6429 ---------------------------------
6430 -- Is_Static_String_Expression --
6431 ---------------------------------
6433 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
6434 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6435 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
6437 begin
6438 Analyze_And_Resolve (Argx);
6440 -- Special case Ada 83, where the expression will never be static,
6441 -- but we will return true if we had a string literal to start with.
6443 if Ada_Version = Ada_83 then
6444 return Lit;
6446 -- Normal case, true only if we end up with a string literal that
6447 -- is marked as being the result of evaluating a static expression.
6449 else
6450 return Is_OK_Static_Expression (Argx)
6451 and then Nkind (Argx) = N_String_Literal;
6452 end if;
6454 end Is_Static_String_Expression;
6456 ----------------------
6457 -- Pragma_Misplaced --
6458 ----------------------
6460 procedure Pragma_Misplaced is
6461 begin
6462 Error_Pragma ("incorrect placement of pragma%");
6463 end Pragma_Misplaced;
6465 ------------------------------------------------
6466 -- Process_Atomic_Independent_Shared_Volatile --
6467 ------------------------------------------------
6469 procedure Process_Atomic_Independent_Shared_Volatile is
6470 procedure Set_Atomic_VFA (E : Entity_Id);
6471 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
6472 -- no explicit alignment was given, set alignment to unknown, since
6473 -- back end knows what the alignment requirements are for atomic and
6474 -- full access arrays. Note: this is necessary for derived types.
6476 --------------------
6477 -- Set_Atomic_VFA --
6478 --------------------
6480 procedure Set_Atomic_VFA (E : Entity_Id) is
6481 begin
6482 if Prag_Id = Pragma_Volatile_Full_Access then
6483 Set_Is_Volatile_Full_Access (E);
6484 else
6485 Set_Is_Atomic (E);
6486 end if;
6488 if not Has_Alignment_Clause (E) then
6489 Set_Alignment (E, Uint_0);
6490 end if;
6491 end Set_Atomic_VFA;
6493 -- Local variables
6495 Decl : Node_Id;
6496 E : Entity_Id;
6497 E_Arg : Node_Id;
6499 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
6501 begin
6502 Check_Ada_83_Warning;
6503 Check_No_Identifiers;
6504 Check_Arg_Count (1);
6505 Check_Arg_Is_Local_Name (Arg1);
6506 E_Arg := Get_Pragma_Arg (Arg1);
6508 if Etype (E_Arg) = Any_Type then
6509 return;
6510 end if;
6512 E := Entity (E_Arg);
6513 Decl := Declaration_Node (E);
6515 -- A pragma that applies to a Ghost entity becomes Ghost for the
6516 -- purposes of legality checks and removal of ignored Ghost code.
6518 Mark_Pragma_As_Ghost (N, E);
6520 -- Check duplicate before we chain ourselves
6522 Check_Duplicate_Pragma (E);
6524 -- Check Atomic and VFA used together
6526 if (Is_Atomic (E) and then Prag_Id = Pragma_Volatile_Full_Access)
6527 or else (Is_Volatile_Full_Access (E)
6528 and then (Prag_Id = Pragma_Atomic
6529 or else
6530 Prag_Id = Pragma_Shared))
6531 then
6532 Error_Pragma
6533 ("cannot have Volatile_Full_Access and Atomic for same entity");
6534 end if;
6536 -- Check for applying VFA to an entity which has aliased component
6538 if Prag_Id = Pragma_Volatile_Full_Access then
6539 declare
6540 Comp : Entity_Id;
6541 Aliased_Comp : Boolean := False;
6542 -- Set True if aliased component present
6544 begin
6545 if Is_Array_Type (Etype (E)) then
6546 Aliased_Comp := Has_Aliased_Components (Etype (E));
6548 -- Record case, too bad Has_Aliased_Components is not also
6549 -- set for records, should it be ???
6551 elsif Is_Record_Type (Etype (E)) then
6552 Comp := First_Component_Or_Discriminant (Etype (E));
6553 while Present (Comp) loop
6554 if Is_Aliased (Comp)
6555 or else Is_Aliased (Etype (Comp))
6556 then
6557 Aliased_Comp := True;
6558 exit;
6559 end if;
6561 Next_Component_Or_Discriminant (Comp);
6562 end loop;
6563 end if;
6565 if Aliased_Comp then
6566 Error_Pragma
6567 ("cannot apply Volatile_Full_Access (aliased component "
6568 & "present)");
6569 end if;
6570 end;
6571 end if;
6573 -- Now check appropriateness of the entity
6575 if Is_Type (E) then
6576 if Rep_Item_Too_Early (E, N)
6577 or else
6578 Rep_Item_Too_Late (E, N)
6579 then
6580 return;
6581 else
6582 Check_First_Subtype (Arg1);
6583 end if;
6585 -- Attribute belongs on the base type. If the view of the type is
6586 -- currently private, it also belongs on the underlying type.
6588 if Prag_Id = Pragma_Atomic
6589 or else
6590 Prag_Id = Pragma_Shared
6591 or else
6592 Prag_Id = Pragma_Volatile_Full_Access
6593 then
6594 Set_Atomic_VFA (E);
6595 Set_Atomic_VFA (Base_Type (E));
6596 Set_Atomic_VFA (Underlying_Type (E));
6597 end if;
6599 -- Atomic/Shared/Volatile_Full_Access imply Independent
6601 if Prag_Id /= Pragma_Volatile then
6602 Set_Is_Independent (E);
6603 Set_Is_Independent (Base_Type (E));
6604 Set_Is_Independent (Underlying_Type (E));
6606 if Prag_Id = Pragma_Independent then
6607 Record_Independence_Check (N, Base_Type (E));
6608 end if;
6609 end if;
6611 -- Atomic/Shared/Volatile_Full_Access imply Volatile
6613 if Prag_Id /= Pragma_Independent then
6614 Set_Is_Volatile (E);
6615 Set_Is_Volatile (Base_Type (E));
6616 Set_Is_Volatile (Underlying_Type (E));
6618 Set_Treat_As_Volatile (E);
6619 Set_Treat_As_Volatile (Underlying_Type (E));
6620 end if;
6622 elsif Nkind (Decl) = N_Object_Declaration
6623 or else (Nkind (Decl) = N_Component_Declaration
6624 and then Original_Record_Component (E) = E)
6625 then
6626 if Rep_Item_Too_Late (E, N) then
6627 return;
6628 end if;
6630 if Prag_Id = Pragma_Atomic
6631 or else
6632 Prag_Id = Pragma_Shared
6633 or else
6634 Prag_Id = Pragma_Volatile_Full_Access
6635 then
6636 if Prag_Id = Pragma_Volatile_Full_Access then
6637 Set_Is_Volatile_Full_Access (E);
6638 else
6639 Set_Is_Atomic (E);
6640 end if;
6642 -- If the object declaration has an explicit initialization, a
6643 -- temporary may have to be created to hold the expression, to
6644 -- ensure that access to the object remain atomic.
6646 if Nkind (Parent (E)) = N_Object_Declaration
6647 and then Present (Expression (Parent (E)))
6648 then
6649 Set_Has_Delayed_Freeze (E);
6650 end if;
6651 end if;
6653 -- Atomic/Shared/Volatile_Full_Access imply Independent
6655 if Prag_Id /= Pragma_Volatile then
6656 Set_Is_Independent (E);
6658 if Prag_Id = Pragma_Independent then
6659 Record_Independence_Check (N, E);
6660 end if;
6661 end if;
6663 -- Atomic/Shared/Volatile_Full_Access imply Volatile
6665 if Prag_Id /= Pragma_Independent then
6666 Set_Is_Volatile (E);
6667 Set_Treat_As_Volatile (E);
6668 end if;
6670 else
6671 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6672 end if;
6674 -- The following check is only relevant when SPARK_Mode is on as
6675 -- this is not a standard Ada legality rule. Pragma Volatile can
6676 -- only apply to a full type declaration or an object declaration
6677 -- (SPARK RM C.6(1)). Original_Node is necessary to account for
6678 -- untagged derived types that are rewritten as subtypes of their
6679 -- respective root types.
6681 if SPARK_Mode = On
6682 and then Prag_Id = Pragma_Volatile
6683 and then
6684 not Nkind_In (Original_Node (Decl), N_Full_Type_Declaration,
6685 N_Object_Declaration)
6686 then
6687 Error_Pragma_Arg
6688 ("argument of pragma % must denote a full type or object "
6689 & "declaration", Arg1);
6690 end if;
6691 end Process_Atomic_Independent_Shared_Volatile;
6693 -------------------------------------------
6694 -- Process_Compile_Time_Warning_Or_Error --
6695 -------------------------------------------
6697 procedure Process_Compile_Time_Warning_Or_Error is
6698 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
6700 begin
6701 Check_Arg_Count (2);
6702 Check_No_Identifiers;
6703 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
6704 Analyze_And_Resolve (Arg1x, Standard_Boolean);
6706 if Compile_Time_Known_Value (Arg1x) then
6707 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
6708 declare
6709 Str : constant String_Id :=
6710 Strval (Get_Pragma_Arg (Arg2));
6711 Len : constant Nat := String_Length (Str);
6712 Cont : Boolean;
6713 Ptr : Nat;
6714 CC : Char_Code;
6715 C : Character;
6716 Cent : constant Entity_Id :=
6717 Cunit_Entity (Current_Sem_Unit);
6719 Force : constant Boolean :=
6720 Prag_Id = Pragma_Compile_Time_Warning
6721 and then
6722 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
6723 and then (Ekind (Cent) /= E_Package
6724 or else not In_Private_Part (Cent));
6725 -- Set True if this is the warning case, and we are in the
6726 -- visible part of a package spec, or in a subprogram spec,
6727 -- in which case we want to force the client to see the
6728 -- warning, even though it is not in the main unit.
6730 begin
6731 -- Loop through segments of message separated by line feeds.
6732 -- We output these segments as separate messages with
6733 -- continuation marks for all but the first.
6735 Cont := False;
6736 Ptr := 1;
6737 loop
6738 Error_Msg_Strlen := 0;
6740 -- Loop to copy characters from argument to error message
6741 -- string buffer.
6743 loop
6744 exit when Ptr > Len;
6745 CC := Get_String_Char (Str, Ptr);
6746 Ptr := Ptr + 1;
6748 -- Ignore wide chars ??? else store character
6750 if In_Character_Range (CC) then
6751 C := Get_Character (CC);
6752 exit when C = ASCII.LF;
6753 Error_Msg_Strlen := Error_Msg_Strlen + 1;
6754 Error_Msg_String (Error_Msg_Strlen) := C;
6755 end if;
6756 end loop;
6758 -- Here with one line ready to go
6760 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
6762 -- If this is a warning in a spec, then we want clients
6763 -- to see the warning, so mark the message with the
6764 -- special sequence !! to force the warning. In the case
6765 -- of a package spec, we do not force this if we are in
6766 -- the private part of the spec.
6768 if Force then
6769 if Cont = False then
6770 Error_Msg_N ("<<~!!", Arg1);
6771 Cont := True;
6772 else
6773 Error_Msg_N ("\<<~!!", Arg1);
6774 end if;
6776 -- Error, rather than warning, or in a body, so we do not
6777 -- need to force visibility for client (error will be
6778 -- output in any case, and this is the situation in which
6779 -- we do not want a client to get a warning, since the
6780 -- warning is in the body or the spec private part).
6782 else
6783 if Cont = False then
6784 Error_Msg_N ("<<~", Arg1);
6785 Cont := True;
6786 else
6787 Error_Msg_N ("\<<~", Arg1);
6788 end if;
6789 end if;
6791 exit when Ptr > Len;
6792 end loop;
6793 end;
6794 end if;
6795 end if;
6796 end Process_Compile_Time_Warning_Or_Error;
6798 ------------------------
6799 -- Process_Convention --
6800 ------------------------
6802 procedure Process_Convention
6803 (C : out Convention_Id;
6804 Ent : out Entity_Id)
6806 Cname : Name_Id;
6808 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
6809 -- Called if we have more than one Export/Import/Convention pragma.
6810 -- This is generally illegal, but we have a special case of allowing
6811 -- Import and Interface to coexist if they specify the convention in
6812 -- a consistent manner. We are allowed to do this, since Interface is
6813 -- an implementation defined pragma, and we choose to do it since we
6814 -- know Rational allows this combination. S is the entity id of the
6815 -- subprogram in question. This procedure also sets the special flag
6816 -- Import_Interface_Present in both pragmas in the case where we do
6817 -- have matching Import and Interface pragmas.
6819 procedure Set_Convention_From_Pragma (E : Entity_Id);
6820 -- Set convention in entity E, and also flag that the entity has a
6821 -- convention pragma. If entity is for a private or incomplete type,
6822 -- also set convention and flag on underlying type. This procedure
6823 -- also deals with the special case of C_Pass_By_Copy convention,
6824 -- and error checks for inappropriate convention specification.
6826 -------------------------------
6827 -- Diagnose_Multiple_Pragmas --
6828 -------------------------------
6830 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
6831 Pdec : constant Node_Id := Declaration_Node (S);
6832 Decl : Node_Id;
6833 Err : Boolean;
6835 function Same_Convention (Decl : Node_Id) return Boolean;
6836 -- Decl is a pragma node. This function returns True if this
6837 -- pragma has a first argument that is an identifier with a
6838 -- Chars field corresponding to the Convention_Id C.
6840 function Same_Name (Decl : Node_Id) return Boolean;
6841 -- Decl is a pragma node. This function returns True if this
6842 -- pragma has a second argument that is an identifier with a
6843 -- Chars field that matches the Chars of the current subprogram.
6845 ---------------------
6846 -- Same_Convention --
6847 ---------------------
6849 function Same_Convention (Decl : Node_Id) return Boolean is
6850 Arg1 : constant Node_Id :=
6851 First (Pragma_Argument_Associations (Decl));
6853 begin
6854 if Present (Arg1) then
6855 declare
6856 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
6857 begin
6858 if Nkind (Arg) = N_Identifier
6859 and then Is_Convention_Name (Chars (Arg))
6860 and then Get_Convention_Id (Chars (Arg)) = C
6861 then
6862 return True;
6863 end if;
6864 end;
6865 end if;
6867 return False;
6868 end Same_Convention;
6870 ---------------
6871 -- Same_Name --
6872 ---------------
6874 function Same_Name (Decl : Node_Id) return Boolean is
6875 Arg1 : constant Node_Id :=
6876 First (Pragma_Argument_Associations (Decl));
6877 Arg2 : Node_Id;
6879 begin
6880 if No (Arg1) then
6881 return False;
6882 end if;
6884 Arg2 := Next (Arg1);
6886 if No (Arg2) then
6887 return False;
6888 end if;
6890 declare
6891 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
6892 begin
6893 if Nkind (Arg) = N_Identifier
6894 and then Chars (Arg) = Chars (S)
6895 then
6896 return True;
6897 end if;
6898 end;
6900 return False;
6901 end Same_Name;
6903 -- Start of processing for Diagnose_Multiple_Pragmas
6905 begin
6906 Err := True;
6908 -- Definitely give message if we have Convention/Export here
6910 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
6911 null;
6913 -- If we have an Import or Export, scan back from pragma to
6914 -- find any previous pragma applying to the same procedure.
6915 -- The scan will be terminated by the start of the list, or
6916 -- hitting the subprogram declaration. This won't allow one
6917 -- pragma to appear in the public part and one in the private
6918 -- part, but that seems very unlikely in practice.
6920 else
6921 Decl := Prev (N);
6922 while Present (Decl) and then Decl /= Pdec loop
6924 -- Look for pragma with same name as us
6926 if Nkind (Decl) = N_Pragma
6927 and then Same_Name (Decl)
6928 then
6929 -- Give error if same as our pragma or Export/Convention
6931 if Nam_In (Pragma_Name (Decl), Name_Export,
6932 Name_Convention,
6933 Pragma_Name (N))
6934 then
6935 exit;
6937 -- Case of Import/Interface or the other way round
6939 elsif Nam_In (Pragma_Name (Decl), Name_Interface,
6940 Name_Import)
6941 then
6942 -- Here we know that we have Import and Interface. It
6943 -- doesn't matter which way round they are. See if
6944 -- they specify the same convention. If so, all OK,
6945 -- and set special flags to stop other messages
6947 if Same_Convention (Decl) then
6948 Set_Import_Interface_Present (N);
6949 Set_Import_Interface_Present (Decl);
6950 Err := False;
6952 -- If different conventions, special message
6954 else
6955 Error_Msg_Sloc := Sloc (Decl);
6956 Error_Pragma_Arg
6957 ("convention differs from that given#", Arg1);
6958 return;
6959 end if;
6960 end if;
6961 end if;
6963 Next (Decl);
6964 end loop;
6965 end if;
6967 -- Give message if needed if we fall through those tests
6968 -- except on Relaxed_RM_Semantics where we let go: either this
6969 -- is a case accepted/ignored by other Ada compilers (e.g.
6970 -- a mix of Convention and Import), or another error will be
6971 -- generated later (e.g. using both Import and Export).
6973 if Err and not Relaxed_RM_Semantics then
6974 Error_Pragma_Arg
6975 ("at most one Convention/Export/Import pragma is allowed",
6976 Arg2);
6977 end if;
6978 end Diagnose_Multiple_Pragmas;
6980 --------------------------------
6981 -- Set_Convention_From_Pragma --
6982 --------------------------------
6984 procedure Set_Convention_From_Pragma (E : Entity_Id) is
6985 begin
6986 -- Ada 2005 (AI-430): Check invalid attempt to change convention
6987 -- for an overridden dispatching operation. Technically this is
6988 -- an amendment and should only be done in Ada 2005 mode. However,
6989 -- this is clearly a mistake, since the problem that is addressed
6990 -- by this AI is that there is a clear gap in the RM.
6992 if Is_Dispatching_Operation (E)
6993 and then Present (Overridden_Operation (E))
6994 and then C /= Convention (Overridden_Operation (E))
6995 then
6996 Error_Pragma_Arg
6997 ("cannot change convention for overridden dispatching "
6998 & "operation", Arg1);
6999 end if;
7001 -- Special checks for Convention_Stdcall
7003 if C = Convention_Stdcall then
7005 -- A dispatching call is not allowed. A dispatching subprogram
7006 -- cannot be used to interface to the Win32 API, so in fact
7007 -- this check does not impose any effective restriction.
7009 if Is_Dispatching_Operation (E) then
7010 Error_Msg_Sloc := Sloc (E);
7012 -- Note: make this unconditional so that if there is more
7013 -- than one call to which the pragma applies, we get a
7014 -- message for each call. Also don't use Error_Pragma,
7015 -- so that we get multiple messages.
7017 Error_Msg_N
7018 ("dispatching subprogram# cannot use Stdcall convention!",
7019 Arg1);
7021 -- Subprograms are not allowed
7023 elsif not Is_Subprogram_Or_Generic_Subprogram (E)
7025 -- A variable is OK
7027 and then Ekind (E) /= E_Variable
7029 -- An access to subprogram is also allowed
7031 and then not
7032 (Is_Access_Type (E)
7033 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
7035 -- Allow internal call to set convention of subprogram type
7037 and then not (Ekind (E) = E_Subprogram_Type)
7038 then
7039 Error_Pragma_Arg
7040 ("second argument of pragma% must be subprogram (type)",
7041 Arg2);
7042 end if;
7043 end if;
7045 -- Set the convention
7047 Set_Convention (E, C);
7048 Set_Has_Convention_Pragma (E);
7050 -- For the case of a record base type, also set the convention of
7051 -- any anonymous access types declared in the record which do not
7052 -- currently have a specified convention.
7054 if Is_Record_Type (E) and then Is_Base_Type (E) then
7055 declare
7056 Comp : Node_Id;
7058 begin
7059 Comp := First_Component (E);
7060 while Present (Comp) loop
7061 if Present (Etype (Comp))
7062 and then Ekind_In (Etype (Comp),
7063 E_Anonymous_Access_Type,
7064 E_Anonymous_Access_Subprogram_Type)
7065 and then not Has_Convention_Pragma (Comp)
7066 then
7067 Set_Convention (Comp, C);
7068 end if;
7070 Next_Component (Comp);
7071 end loop;
7072 end;
7073 end if;
7075 -- Deal with incomplete/private type case, where underlying type
7076 -- is available, so set convention of that underlying type.
7078 if Is_Incomplete_Or_Private_Type (E)
7079 and then Present (Underlying_Type (E))
7080 then
7081 Set_Convention (Underlying_Type (E), C);
7082 Set_Has_Convention_Pragma (Underlying_Type (E), True);
7083 end if;
7085 -- A class-wide type should inherit the convention of the specific
7086 -- root type (although this isn't specified clearly by the RM).
7088 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
7089 Set_Convention (Class_Wide_Type (E), C);
7090 end if;
7092 -- If the entity is a record type, then check for special case of
7093 -- C_Pass_By_Copy, which is treated the same as C except that the
7094 -- special record flag is set. This convention is only permitted
7095 -- on record types (see AI95-00131).
7097 if Cname = Name_C_Pass_By_Copy then
7098 if Is_Record_Type (E) then
7099 Set_C_Pass_By_Copy (Base_Type (E));
7100 elsif Is_Incomplete_Or_Private_Type (E)
7101 and then Is_Record_Type (Underlying_Type (E))
7102 then
7103 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
7104 else
7105 Error_Pragma_Arg
7106 ("C_Pass_By_Copy convention allowed only for record type",
7107 Arg2);
7108 end if;
7109 end if;
7111 -- If the entity is a derived boolean type, check for the special
7112 -- case of convention C, C++, or Fortran, where we consider any
7113 -- nonzero value to represent true.
7115 if Is_Discrete_Type (E)
7116 and then Root_Type (Etype (E)) = Standard_Boolean
7117 and then
7118 (C = Convention_C
7119 or else
7120 C = Convention_CPP
7121 or else
7122 C = Convention_Fortran)
7123 then
7124 Set_Nonzero_Is_True (Base_Type (E));
7125 end if;
7126 end Set_Convention_From_Pragma;
7128 -- Local variables
7130 Comp_Unit : Unit_Number_Type;
7131 E : Entity_Id;
7132 E1 : Entity_Id;
7133 Id : Node_Id;
7135 -- Start of processing for Process_Convention
7137 begin
7138 Check_At_Least_N_Arguments (2);
7139 Check_Optional_Identifier (Arg1, Name_Convention);
7140 Check_Arg_Is_Identifier (Arg1);
7141 Cname := Chars (Get_Pragma_Arg (Arg1));
7143 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
7144 -- tested again below to set the critical flag).
7146 if Cname = Name_C_Pass_By_Copy then
7147 C := Convention_C;
7149 -- Otherwise we must have something in the standard convention list
7151 elsif Is_Convention_Name (Cname) then
7152 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
7154 -- Otherwise warn on unrecognized convention
7156 else
7157 if Warn_On_Export_Import then
7158 Error_Msg_N
7159 ("??unrecognized convention name, C assumed",
7160 Get_Pragma_Arg (Arg1));
7161 end if;
7163 C := Convention_C;
7164 end if;
7166 Check_Optional_Identifier (Arg2, Name_Entity);
7167 Check_Arg_Is_Local_Name (Arg2);
7169 Id := Get_Pragma_Arg (Arg2);
7170 Analyze (Id);
7172 if not Is_Entity_Name (Id) then
7173 Error_Pragma_Arg ("entity name required", Arg2);
7174 end if;
7176 E := Entity (Id);
7178 -- Set entity to return
7180 Ent := E;
7182 -- Ada_Pass_By_Copy special checking
7184 if C = Convention_Ada_Pass_By_Copy then
7185 if not Is_First_Subtype (E) then
7186 Error_Pragma_Arg
7187 ("convention `Ada_Pass_By_Copy` only allowed for types",
7188 Arg2);
7189 end if;
7191 if Is_By_Reference_Type (E) then
7192 Error_Pragma_Arg
7193 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
7194 & "type", Arg1);
7195 end if;
7197 -- Ada_Pass_By_Reference special checking
7199 elsif C = Convention_Ada_Pass_By_Reference then
7200 if not Is_First_Subtype (E) then
7201 Error_Pragma_Arg
7202 ("convention `Ada_Pass_By_Reference` only allowed for types",
7203 Arg2);
7204 end if;
7206 if Is_By_Copy_Type (E) then
7207 Error_Pragma_Arg
7208 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
7209 & "type", Arg1);
7210 end if;
7211 end if;
7213 -- Go to renamed subprogram if present, since convention applies to
7214 -- the actual renamed entity, not to the renaming entity. If the
7215 -- subprogram is inherited, go to parent subprogram.
7217 if Is_Subprogram (E)
7218 and then Present (Alias (E))
7219 then
7220 if Nkind (Parent (Declaration_Node (E))) =
7221 N_Subprogram_Renaming_Declaration
7222 then
7223 if Scope (E) /= Scope (Alias (E)) then
7224 Error_Pragma_Ref
7225 ("cannot apply pragma% to non-local entity&#", E);
7226 end if;
7228 E := Alias (E);
7230 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
7231 N_Private_Extension_Declaration)
7232 and then Scope (E) = Scope (Alias (E))
7233 then
7234 E := Alias (E);
7236 -- Return the parent subprogram the entity was inherited from
7238 Ent := E;
7239 end if;
7240 end if;
7242 -- Check that we are not applying this to a specless body. Relax this
7243 -- check if Relaxed_RM_Semantics to accomodate other Ada compilers.
7245 if Is_Subprogram (E)
7246 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
7247 and then not Relaxed_RM_Semantics
7248 then
7249 Error_Pragma
7250 ("pragma% requires separate spec and must come before body");
7251 end if;
7253 -- Check that we are not applying this to a named constant
7255 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
7256 Error_Msg_Name_1 := Pname;
7257 Error_Msg_N
7258 ("cannot apply pragma% to named constant!",
7259 Get_Pragma_Arg (Arg2));
7260 Error_Pragma_Arg
7261 ("\supply appropriate type for&!", Arg2);
7262 end if;
7264 if Ekind (E) = E_Enumeration_Literal then
7265 Error_Pragma ("enumeration literal not allowed for pragma%");
7266 end if;
7268 -- Check for rep item appearing too early or too late
7270 if Etype (E) = Any_Type
7271 or else Rep_Item_Too_Early (E, N)
7272 then
7273 raise Pragma_Exit;
7275 elsif Present (Underlying_Type (E)) then
7276 E := Underlying_Type (E);
7277 end if;
7279 if Rep_Item_Too_Late (E, N) then
7280 raise Pragma_Exit;
7281 end if;
7283 if Has_Convention_Pragma (E) then
7284 Diagnose_Multiple_Pragmas (E);
7286 elsif Convention (E) = Convention_Protected
7287 or else Ekind (Scope (E)) = E_Protected_Type
7288 then
7289 Error_Pragma_Arg
7290 ("a protected operation cannot be given a different convention",
7291 Arg2);
7292 end if;
7294 -- For Intrinsic, a subprogram is required
7296 if C = Convention_Intrinsic
7297 and then not Is_Subprogram_Or_Generic_Subprogram (E)
7298 then
7299 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
7301 if not (Is_Type (E) and then Relaxed_RM_Semantics) then
7302 Error_Pragma_Arg
7303 ("second argument of pragma% must be a subprogram", Arg2);
7304 end if;
7305 end if;
7307 -- Deal with non-subprogram cases
7309 if not Is_Subprogram_Or_Generic_Subprogram (E) then
7310 Set_Convention_From_Pragma (E);
7312 if Is_Type (E) then
7314 -- The pragma must apply to a first subtype, but it can also
7315 -- apply to a generic type in a generic formal part, in which
7316 -- case it will also appear in the corresponding instance.
7318 if Is_Generic_Type (E) or else In_Instance then
7319 null;
7320 else
7321 Check_First_Subtype (Arg2);
7322 end if;
7324 Set_Convention_From_Pragma (Base_Type (E));
7326 -- For access subprograms, we must set the convention on the
7327 -- internally generated directly designated type as well.
7329 if Ekind (E) = E_Access_Subprogram_Type then
7330 Set_Convention_From_Pragma (Directly_Designated_Type (E));
7331 end if;
7332 end if;
7334 -- For the subprogram case, set proper convention for all homonyms
7335 -- in same scope and the same declarative part, i.e. the same
7336 -- compilation unit.
7338 else
7339 Comp_Unit := Get_Source_Unit (E);
7340 Set_Convention_From_Pragma (E);
7342 -- Treat a pragma Import as an implicit body, and pragma import
7343 -- as implicit reference (for navigation in GPS).
7345 if Prag_Id = Pragma_Import then
7346 Generate_Reference (E, Id, 'b');
7348 -- For exported entities we restrict the generation of references
7349 -- to entities exported to foreign languages since entities
7350 -- exported to Ada do not provide further information to GPS and
7351 -- add undesired references to the output of the gnatxref tool.
7353 elsif Prag_Id = Pragma_Export
7354 and then Convention (E) /= Convention_Ada
7355 then
7356 Generate_Reference (E, Id, 'i');
7357 end if;
7359 -- If the pragma comes from an aspect, it only applies to the
7360 -- given entity, not its homonyms.
7362 if From_Aspect_Specification (N) then
7363 return;
7364 end if;
7366 -- Otherwise Loop through the homonyms of the pragma argument's
7367 -- entity, an apply convention to those in the current scope.
7369 E1 := Ent;
7371 loop
7372 E1 := Homonym (E1);
7373 exit when No (E1) or else Scope (E1) /= Current_Scope;
7375 -- Ignore entry for which convention is already set
7377 if Has_Convention_Pragma (E1) then
7378 goto Continue;
7379 end if;
7381 -- Do not set the pragma on inherited operations or on formal
7382 -- subprograms.
7384 if Comes_From_Source (E1)
7385 and then Comp_Unit = Get_Source_Unit (E1)
7386 and then not Is_Formal_Subprogram (E1)
7387 and then Nkind (Original_Node (Parent (E1))) /=
7388 N_Full_Type_Declaration
7389 then
7390 if Present (Alias (E1))
7391 and then Scope (E1) /= Scope (Alias (E1))
7392 then
7393 Error_Pragma_Ref
7394 ("cannot apply pragma% to non-local entity& declared#",
7395 E1);
7396 end if;
7398 Set_Convention_From_Pragma (E1);
7400 if Prag_Id = Pragma_Import then
7401 Generate_Reference (E1, Id, 'b');
7402 end if;
7403 end if;
7405 <<Continue>>
7406 null;
7407 end loop;
7408 end if;
7409 end Process_Convention;
7411 ----------------------------------------
7412 -- Process_Disable_Enable_Atomic_Sync --
7413 ----------------------------------------
7415 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
7416 begin
7417 Check_No_Identifiers;
7418 Check_At_Most_N_Arguments (1);
7420 -- Modeled internally as
7421 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
7423 Rewrite (N,
7424 Make_Pragma (Loc,
7425 Pragma_Identifier =>
7426 Make_Identifier (Loc, Nam),
7427 Pragma_Argument_Associations => New_List (
7428 Make_Pragma_Argument_Association (Loc,
7429 Expression =>
7430 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
7432 if Present (Arg1) then
7433 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
7434 end if;
7436 Analyze (N);
7437 end Process_Disable_Enable_Atomic_Sync;
7439 -------------------------------------------------
7440 -- Process_Extended_Import_Export_Internal_Arg --
7441 -------------------------------------------------
7443 procedure Process_Extended_Import_Export_Internal_Arg
7444 (Arg_Internal : Node_Id := Empty)
7446 begin
7447 if No (Arg_Internal) then
7448 Error_Pragma ("Internal parameter required for pragma%");
7449 end if;
7451 if Nkind (Arg_Internal) = N_Identifier then
7452 null;
7454 elsif Nkind (Arg_Internal) = N_Operator_Symbol
7455 and then (Prag_Id = Pragma_Import_Function
7456 or else
7457 Prag_Id = Pragma_Export_Function)
7458 then
7459 null;
7461 else
7462 Error_Pragma_Arg
7463 ("wrong form for Internal parameter for pragma%", Arg_Internal);
7464 end if;
7466 Check_Arg_Is_Local_Name (Arg_Internal);
7467 end Process_Extended_Import_Export_Internal_Arg;
7469 --------------------------------------------------
7470 -- Process_Extended_Import_Export_Object_Pragma --
7471 --------------------------------------------------
7473 procedure Process_Extended_Import_Export_Object_Pragma
7474 (Arg_Internal : Node_Id;
7475 Arg_External : Node_Id;
7476 Arg_Size : Node_Id)
7478 Def_Id : Entity_Id;
7480 begin
7481 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7482 Def_Id := Entity (Arg_Internal);
7484 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
7485 Error_Pragma_Arg
7486 ("pragma% must designate an object", Arg_Internal);
7487 end if;
7489 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
7490 or else
7491 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
7492 then
7493 Error_Pragma_Arg
7494 ("previous Common/Psect_Object applies, pragma % not permitted",
7495 Arg_Internal);
7496 end if;
7498 if Rep_Item_Too_Late (Def_Id, N) then
7499 raise Pragma_Exit;
7500 end if;
7502 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
7504 if Present (Arg_Size) then
7505 Check_Arg_Is_External_Name (Arg_Size);
7506 end if;
7508 -- Export_Object case
7510 if Prag_Id = Pragma_Export_Object then
7511 if not Is_Library_Level_Entity (Def_Id) then
7512 Error_Pragma_Arg
7513 ("argument for pragma% must be library level entity",
7514 Arg_Internal);
7515 end if;
7517 if Ekind (Current_Scope) = E_Generic_Package then
7518 Error_Pragma ("pragma& cannot appear in a generic unit");
7519 end if;
7521 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
7522 Error_Pragma_Arg
7523 ("exported object must have compile time known size",
7524 Arg_Internal);
7525 end if;
7527 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
7528 Error_Msg_N ("??duplicate Export_Object pragma", N);
7529 else
7530 Set_Exported (Def_Id, Arg_Internal);
7531 end if;
7533 -- Import_Object case
7535 else
7536 if Is_Concurrent_Type (Etype (Def_Id)) then
7537 Error_Pragma_Arg
7538 ("cannot use pragma% for task/protected object",
7539 Arg_Internal);
7540 end if;
7542 if Ekind (Def_Id) = E_Constant then
7543 Error_Pragma_Arg
7544 ("cannot import a constant", Arg_Internal);
7545 end if;
7547 if Warn_On_Export_Import
7548 and then Has_Discriminants (Etype (Def_Id))
7549 then
7550 Error_Msg_N
7551 ("imported value must be initialized??", Arg_Internal);
7552 end if;
7554 if Warn_On_Export_Import
7555 and then Is_Access_Type (Etype (Def_Id))
7556 then
7557 Error_Pragma_Arg
7558 ("cannot import object of an access type??", Arg_Internal);
7559 end if;
7561 if Warn_On_Export_Import
7562 and then Is_Imported (Def_Id)
7563 then
7564 Error_Msg_N ("??duplicate Import_Object pragma", N);
7566 -- Check for explicit initialization present. Note that an
7567 -- initialization generated by the code generator, e.g. for an
7568 -- access type, does not count here.
7570 elsif Present (Expression (Parent (Def_Id)))
7571 and then
7572 Comes_From_Source
7573 (Original_Node (Expression (Parent (Def_Id))))
7574 then
7575 Error_Msg_Sloc := Sloc (Def_Id);
7576 Error_Pragma_Arg
7577 ("imported entities cannot be initialized (RM B.1(24))",
7578 "\no initialization allowed for & declared#", Arg1);
7579 else
7580 Set_Imported (Def_Id);
7581 Note_Possible_Modification (Arg_Internal, Sure => False);
7582 end if;
7583 end if;
7584 end Process_Extended_Import_Export_Object_Pragma;
7586 ------------------------------------------------------
7587 -- Process_Extended_Import_Export_Subprogram_Pragma --
7588 ------------------------------------------------------
7590 procedure Process_Extended_Import_Export_Subprogram_Pragma
7591 (Arg_Internal : Node_Id;
7592 Arg_External : Node_Id;
7593 Arg_Parameter_Types : Node_Id;
7594 Arg_Result_Type : Node_Id := Empty;
7595 Arg_Mechanism : Node_Id;
7596 Arg_Result_Mechanism : Node_Id := Empty)
7598 Ent : Entity_Id;
7599 Def_Id : Entity_Id;
7600 Hom_Id : Entity_Id;
7601 Formal : Entity_Id;
7602 Ambiguous : Boolean;
7603 Match : Boolean;
7605 function Same_Base_Type
7606 (Ptype : Node_Id;
7607 Formal : Entity_Id) return Boolean;
7608 -- Determines if Ptype references the type of Formal. Note that only
7609 -- the base types need to match according to the spec. Ptype here is
7610 -- the argument from the pragma, which is either a type name, or an
7611 -- access attribute.
7613 --------------------
7614 -- Same_Base_Type --
7615 --------------------
7617 function Same_Base_Type
7618 (Ptype : Node_Id;
7619 Formal : Entity_Id) return Boolean
7621 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
7622 Pref : Node_Id;
7624 begin
7625 -- Case where pragma argument is typ'Access
7627 if Nkind (Ptype) = N_Attribute_Reference
7628 and then Attribute_Name (Ptype) = Name_Access
7629 then
7630 Pref := Prefix (Ptype);
7631 Find_Type (Pref);
7633 if not Is_Entity_Name (Pref)
7634 or else Entity (Pref) = Any_Type
7635 then
7636 raise Pragma_Exit;
7637 end if;
7639 -- We have a match if the corresponding argument is of an
7640 -- anonymous access type, and its designated type matches the
7641 -- type of the prefix of the access attribute
7643 return Ekind (Ftyp) = E_Anonymous_Access_Type
7644 and then Base_Type (Entity (Pref)) =
7645 Base_Type (Etype (Designated_Type (Ftyp)));
7647 -- Case where pragma argument is a type name
7649 else
7650 Find_Type (Ptype);
7652 if not Is_Entity_Name (Ptype)
7653 or else Entity (Ptype) = Any_Type
7654 then
7655 raise Pragma_Exit;
7656 end if;
7658 -- We have a match if the corresponding argument is of the type
7659 -- given in the pragma (comparing base types)
7661 return Base_Type (Entity (Ptype)) = Ftyp;
7662 end if;
7663 end Same_Base_Type;
7665 -- Start of processing for
7666 -- Process_Extended_Import_Export_Subprogram_Pragma
7668 begin
7669 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7670 Ent := Empty;
7671 Ambiguous := False;
7673 -- Loop through homonyms (overloadings) of the entity
7675 Hom_Id := Entity (Arg_Internal);
7676 while Present (Hom_Id) loop
7677 Def_Id := Get_Base_Subprogram (Hom_Id);
7679 -- We need a subprogram in the current scope
7681 if not Is_Subprogram (Def_Id)
7682 or else Scope (Def_Id) /= Current_Scope
7683 then
7684 null;
7686 else
7687 Match := True;
7689 -- Pragma cannot apply to subprogram body
7691 if Is_Subprogram (Def_Id)
7692 and then Nkind (Parent (Declaration_Node (Def_Id))) =
7693 N_Subprogram_Body
7694 then
7695 Error_Pragma
7696 ("pragma% requires separate spec"
7697 & " and must come before body");
7698 end if;
7700 -- Test result type if given, note that the result type
7701 -- parameter can only be present for the function cases.
7703 if Present (Arg_Result_Type)
7704 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
7705 then
7706 Match := False;
7708 elsif Etype (Def_Id) /= Standard_Void_Type
7709 and then
7710 Nam_In (Pname, Name_Export_Procedure, Name_Import_Procedure)
7711 then
7712 Match := False;
7714 -- Test parameter types if given. Note that this parameter
7715 -- has not been analyzed (and must not be, since it is
7716 -- semantic nonsense), so we get it as the parser left it.
7718 elsif Present (Arg_Parameter_Types) then
7719 Check_Matching_Types : declare
7720 Formal : Entity_Id;
7721 Ptype : Node_Id;
7723 begin
7724 Formal := First_Formal (Def_Id);
7726 if Nkind (Arg_Parameter_Types) = N_Null then
7727 if Present (Formal) then
7728 Match := False;
7729 end if;
7731 -- A list of one type, e.g. (List) is parsed as
7732 -- a parenthesized expression.
7734 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
7735 and then Paren_Count (Arg_Parameter_Types) = 1
7736 then
7737 if No (Formal)
7738 or else Present (Next_Formal (Formal))
7739 then
7740 Match := False;
7741 else
7742 Match :=
7743 Same_Base_Type (Arg_Parameter_Types, Formal);
7744 end if;
7746 -- A list of more than one type is parsed as a aggregate
7748 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
7749 and then Paren_Count (Arg_Parameter_Types) = 0
7750 then
7751 Ptype := First (Expressions (Arg_Parameter_Types));
7752 while Present (Ptype) or else Present (Formal) loop
7753 if No (Ptype)
7754 or else No (Formal)
7755 or else not Same_Base_Type (Ptype, Formal)
7756 then
7757 Match := False;
7758 exit;
7759 else
7760 Next_Formal (Formal);
7761 Next (Ptype);
7762 end if;
7763 end loop;
7765 -- Anything else is of the wrong form
7767 else
7768 Error_Pragma_Arg
7769 ("wrong form for Parameter_Types parameter",
7770 Arg_Parameter_Types);
7771 end if;
7772 end Check_Matching_Types;
7773 end if;
7775 -- Match is now False if the entry we found did not match
7776 -- either a supplied Parameter_Types or Result_Types argument
7778 if Match then
7779 if No (Ent) then
7780 Ent := Def_Id;
7782 -- Ambiguous case, the flag Ambiguous shows if we already
7783 -- detected this and output the initial messages.
7785 else
7786 if not Ambiguous then
7787 Ambiguous := True;
7788 Error_Msg_Name_1 := Pname;
7789 Error_Msg_N
7790 ("pragma% does not uniquely identify subprogram!",
7792 Error_Msg_Sloc := Sloc (Ent);
7793 Error_Msg_N ("matching subprogram #!", N);
7794 Ent := Empty;
7795 end if;
7797 Error_Msg_Sloc := Sloc (Def_Id);
7798 Error_Msg_N ("matching subprogram #!", N);
7799 end if;
7800 end if;
7801 end if;
7803 Hom_Id := Homonym (Hom_Id);
7804 end loop;
7806 -- See if we found an entry
7808 if No (Ent) then
7809 if not Ambiguous then
7810 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
7811 Error_Pragma
7812 ("pragma% cannot be given for generic subprogram");
7813 else
7814 Error_Pragma
7815 ("pragma% does not identify local subprogram");
7816 end if;
7817 end if;
7819 return;
7820 end if;
7822 -- Import pragmas must be for imported entities
7824 if Prag_Id = Pragma_Import_Function
7825 or else
7826 Prag_Id = Pragma_Import_Procedure
7827 or else
7828 Prag_Id = Pragma_Import_Valued_Procedure
7829 then
7830 if not Is_Imported (Ent) then
7831 Error_Pragma
7832 ("pragma Import or Interface must precede pragma%");
7833 end if;
7835 -- Here we have the Export case which can set the entity as exported
7837 -- But does not do so if the specified external name is null, since
7838 -- that is taken as a signal in DEC Ada 83 (with which we want to be
7839 -- compatible) to request no external name.
7841 elsif Nkind (Arg_External) = N_String_Literal
7842 and then String_Length (Strval (Arg_External)) = 0
7843 then
7844 null;
7846 -- In all other cases, set entity as exported
7848 else
7849 Set_Exported (Ent, Arg_Internal);
7850 end if;
7852 -- Special processing for Valued_Procedure cases
7854 if Prag_Id = Pragma_Import_Valued_Procedure
7855 or else
7856 Prag_Id = Pragma_Export_Valued_Procedure
7857 then
7858 Formal := First_Formal (Ent);
7860 if No (Formal) then
7861 Error_Pragma ("at least one parameter required for pragma%");
7863 elsif Ekind (Formal) /= E_Out_Parameter then
7864 Error_Pragma ("first parameter must have mode out for pragma%");
7866 else
7867 Set_Is_Valued_Procedure (Ent);
7868 end if;
7869 end if;
7871 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
7873 -- Process Result_Mechanism argument if present. We have already
7874 -- checked that this is only allowed for the function case.
7876 if Present (Arg_Result_Mechanism) then
7877 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
7878 end if;
7880 -- Process Mechanism parameter if present. Note that this parameter
7881 -- is not analyzed, and must not be analyzed since it is semantic
7882 -- nonsense, so we get it in exactly as the parser left it.
7884 if Present (Arg_Mechanism) then
7885 declare
7886 Formal : Entity_Id;
7887 Massoc : Node_Id;
7888 Mname : Node_Id;
7889 Choice : Node_Id;
7891 begin
7892 -- A single mechanism association without a formal parameter
7893 -- name is parsed as a parenthesized expression. All other
7894 -- cases are parsed as aggregates, so we rewrite the single
7895 -- parameter case as an aggregate for consistency.
7897 if Nkind (Arg_Mechanism) /= N_Aggregate
7898 and then Paren_Count (Arg_Mechanism) = 1
7899 then
7900 Rewrite (Arg_Mechanism,
7901 Make_Aggregate (Sloc (Arg_Mechanism),
7902 Expressions => New_List (
7903 Relocate_Node (Arg_Mechanism))));
7904 end if;
7906 -- Case of only mechanism name given, applies to all formals
7908 if Nkind (Arg_Mechanism) /= N_Aggregate then
7909 Formal := First_Formal (Ent);
7910 while Present (Formal) loop
7911 Set_Mechanism_Value (Formal, Arg_Mechanism);
7912 Next_Formal (Formal);
7913 end loop;
7915 -- Case of list of mechanism associations given
7917 else
7918 if Null_Record_Present (Arg_Mechanism) then
7919 Error_Pragma_Arg
7920 ("inappropriate form for Mechanism parameter",
7921 Arg_Mechanism);
7922 end if;
7924 -- Deal with positional ones first
7926 Formal := First_Formal (Ent);
7928 if Present (Expressions (Arg_Mechanism)) then
7929 Mname := First (Expressions (Arg_Mechanism));
7930 while Present (Mname) loop
7931 if No (Formal) then
7932 Error_Pragma_Arg
7933 ("too many mechanism associations", Mname);
7934 end if;
7936 Set_Mechanism_Value (Formal, Mname);
7937 Next_Formal (Formal);
7938 Next (Mname);
7939 end loop;
7940 end if;
7942 -- Deal with named entries
7944 if Present (Component_Associations (Arg_Mechanism)) then
7945 Massoc := First (Component_Associations (Arg_Mechanism));
7946 while Present (Massoc) loop
7947 Choice := First (Choices (Massoc));
7949 if Nkind (Choice) /= N_Identifier
7950 or else Present (Next (Choice))
7951 then
7952 Error_Pragma_Arg
7953 ("incorrect form for mechanism association",
7954 Massoc);
7955 end if;
7957 Formal := First_Formal (Ent);
7958 loop
7959 if No (Formal) then
7960 Error_Pragma_Arg
7961 ("parameter name & not present", Choice);
7962 end if;
7964 if Chars (Choice) = Chars (Formal) then
7965 Set_Mechanism_Value
7966 (Formal, Expression (Massoc));
7968 -- Set entity on identifier (needed by ASIS)
7970 Set_Entity (Choice, Formal);
7972 exit;
7973 end if;
7975 Next_Formal (Formal);
7976 end loop;
7978 Next (Massoc);
7979 end loop;
7980 end if;
7981 end if;
7982 end;
7983 end if;
7984 end Process_Extended_Import_Export_Subprogram_Pragma;
7986 --------------------------
7987 -- Process_Generic_List --
7988 --------------------------
7990 procedure Process_Generic_List is
7991 Arg : Node_Id;
7992 Exp : Node_Id;
7994 begin
7995 Check_No_Identifiers;
7996 Check_At_Least_N_Arguments (1);
7998 -- Check all arguments are names of generic units or instances
8000 Arg := Arg1;
8001 while Present (Arg) loop
8002 Exp := Get_Pragma_Arg (Arg);
8003 Analyze (Exp);
8005 if not Is_Entity_Name (Exp)
8006 or else
8007 (not Is_Generic_Instance (Entity (Exp))
8008 and then
8009 not Is_Generic_Unit (Entity (Exp)))
8010 then
8011 Error_Pragma_Arg
8012 ("pragma% argument must be name of generic unit/instance",
8013 Arg);
8014 end if;
8016 Next (Arg);
8017 end loop;
8018 end Process_Generic_List;
8020 ------------------------------------
8021 -- Process_Import_Predefined_Type --
8022 ------------------------------------
8024 procedure Process_Import_Predefined_Type is
8025 Loc : constant Source_Ptr := Sloc (N);
8026 Elmt : Elmt_Id;
8027 Ftyp : Node_Id := Empty;
8028 Decl : Node_Id;
8029 Def : Node_Id;
8030 Nam : Name_Id;
8032 begin
8033 String_To_Name_Buffer (Strval (Expression (Arg3)));
8034 Nam := Name_Find;
8036 Elmt := First_Elmt (Predefined_Float_Types);
8037 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
8038 Next_Elmt (Elmt);
8039 end loop;
8041 Ftyp := Node (Elmt);
8043 if Present (Ftyp) then
8045 -- Don't build a derived type declaration, because predefined C
8046 -- types have no declaration anywhere, so cannot really be named.
8047 -- Instead build a full type declaration, starting with an
8048 -- appropriate type definition is built
8050 if Is_Floating_Point_Type (Ftyp) then
8051 Def := Make_Floating_Point_Definition (Loc,
8052 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
8053 Make_Real_Range_Specification (Loc,
8054 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
8055 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
8057 -- Should never have a predefined type we cannot handle
8059 else
8060 raise Program_Error;
8061 end if;
8063 -- Build and insert a Full_Type_Declaration, which will be
8064 -- analyzed as soon as this list entry has been analyzed.
8066 Decl := Make_Full_Type_Declaration (Loc,
8067 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
8068 Type_Definition => Def);
8070 Insert_After (N, Decl);
8071 Mark_Rewrite_Insertion (Decl);
8073 else
8074 Error_Pragma_Arg ("no matching type found for pragma%",
8075 Arg2);
8076 end if;
8077 end Process_Import_Predefined_Type;
8079 ---------------------------------
8080 -- Process_Import_Or_Interface --
8081 ---------------------------------
8083 procedure Process_Import_Or_Interface is
8084 C : Convention_Id;
8085 Def_Id : Entity_Id;
8086 Hom_Id : Entity_Id;
8088 begin
8089 -- In Relaxed_RM_Semantics, support old Ada 83 style:
8090 -- pragma Import (Entity, "external name");
8092 if Relaxed_RM_Semantics
8093 and then Arg_Count = 2
8094 and then Prag_Id = Pragma_Import
8095 and then Nkind (Expression (Arg2)) = N_String_Literal
8096 then
8097 C := Convention_C;
8098 Def_Id := Get_Pragma_Arg (Arg1);
8099 Analyze (Def_Id);
8101 if not Is_Entity_Name (Def_Id) then
8102 Error_Pragma_Arg ("entity name required", Arg1);
8103 end if;
8105 Def_Id := Entity (Def_Id);
8106 Kill_Size_Check_Code (Def_Id);
8107 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
8109 else
8110 Process_Convention (C, Def_Id);
8112 -- A pragma that applies to a Ghost entity becomes Ghost for the
8113 -- purposes of legality checks and removal of ignored Ghost code.
8115 Mark_Pragma_As_Ghost (N, Def_Id);
8116 Kill_Size_Check_Code (Def_Id);
8117 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
8118 end if;
8120 -- Various error checks
8122 if Ekind_In (Def_Id, E_Variable, E_Constant) then
8124 -- We do not permit Import to apply to a renaming declaration
8126 if Present (Renamed_Object (Def_Id)) then
8127 Error_Pragma_Arg
8128 ("pragma% not allowed for object renaming", Arg2);
8130 -- User initialization is not allowed for imported object, but
8131 -- the object declaration may contain a default initialization,
8132 -- that will be discarded. Note that an explicit initialization
8133 -- only counts if it comes from source, otherwise it is simply
8134 -- the code generator making an implicit initialization explicit.
8136 elsif Present (Expression (Parent (Def_Id)))
8137 and then Comes_From_Source
8138 (Original_Node (Expression (Parent (Def_Id))))
8139 then
8140 -- Set imported flag to prevent cascaded errors
8142 Set_Is_Imported (Def_Id);
8144 Error_Msg_Sloc := Sloc (Def_Id);
8145 Error_Pragma_Arg
8146 ("no initialization allowed for declaration of& #",
8147 "\imported entities cannot be initialized (RM B.1(24))",
8148 Arg2);
8150 else
8151 -- If the pragma comes from an aspect specification the
8152 -- Is_Imported flag has already been set.
8154 if not From_Aspect_Specification (N) then
8155 Set_Imported (Def_Id);
8156 end if;
8158 Process_Interface_Name (Def_Id, Arg3, Arg4);
8160 -- Note that we do not set Is_Public here. That's because we
8161 -- only want to set it if there is no address clause, and we
8162 -- don't know that yet, so we delay that processing till
8163 -- freeze time.
8165 -- pragma Import completes deferred constants
8167 if Ekind (Def_Id) = E_Constant then
8168 Set_Has_Completion (Def_Id);
8169 end if;
8171 -- It is not possible to import a constant of an unconstrained
8172 -- array type (e.g. string) because there is no simple way to
8173 -- write a meaningful subtype for it.
8175 if Is_Array_Type (Etype (Def_Id))
8176 and then not Is_Constrained (Etype (Def_Id))
8177 then
8178 Error_Msg_NE
8179 ("imported constant& must have a constrained subtype",
8180 N, Def_Id);
8181 end if;
8182 end if;
8184 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
8186 -- If the name is overloaded, pragma applies to all of the denoted
8187 -- entities in the same declarative part, unless the pragma comes
8188 -- from an aspect specification or was generated by the compiler
8189 -- (such as for pragma Provide_Shift_Operators).
8191 Hom_Id := Def_Id;
8192 while Present (Hom_Id) loop
8194 Def_Id := Get_Base_Subprogram (Hom_Id);
8196 -- Ignore inherited subprograms because the pragma will apply
8197 -- to the parent operation, which is the one called.
8199 if Is_Overloadable (Def_Id)
8200 and then Present (Alias (Def_Id))
8201 then
8202 null;
8204 -- If it is not a subprogram, it must be in an outer scope and
8205 -- pragma does not apply.
8207 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
8208 null;
8210 -- The pragma does not apply to primitives of interfaces
8212 elsif Is_Dispatching_Operation (Def_Id)
8213 and then Present (Find_Dispatching_Type (Def_Id))
8214 and then Is_Interface (Find_Dispatching_Type (Def_Id))
8215 then
8216 null;
8218 -- Verify that the homonym is in the same declarative part (not
8219 -- just the same scope). If the pragma comes from an aspect
8220 -- specification we know that it is part of the declaration.
8222 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
8223 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
8224 and then not From_Aspect_Specification (N)
8225 then
8226 exit;
8228 else
8229 -- If the pragma comes from an aspect specification the
8230 -- Is_Imported flag has already been set.
8232 if not From_Aspect_Specification (N) then
8233 Set_Imported (Def_Id);
8234 end if;
8236 -- Reject an Import applied to an abstract subprogram
8238 if Is_Subprogram (Def_Id)
8239 and then Is_Abstract_Subprogram (Def_Id)
8240 then
8241 Error_Msg_Sloc := Sloc (Def_Id);
8242 Error_Msg_NE
8243 ("cannot import abstract subprogram& declared#",
8244 Arg2, Def_Id);
8245 end if;
8247 -- Special processing for Convention_Intrinsic
8249 if C = Convention_Intrinsic then
8251 -- Link_Name argument not allowed for intrinsic
8253 Check_No_Link_Name;
8255 Set_Is_Intrinsic_Subprogram (Def_Id);
8257 -- If no external name is present, then check that this
8258 -- is a valid intrinsic subprogram. If an external name
8259 -- is present, then this is handled by the back end.
8261 if No (Arg3) then
8262 Check_Intrinsic_Subprogram
8263 (Def_Id, Get_Pragma_Arg (Arg2));
8264 end if;
8265 end if;
8267 -- Verify that the subprogram does not have a completion
8268 -- through a renaming declaration. For other completions the
8269 -- pragma appears as a too late representation.
8271 declare
8272 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
8274 begin
8275 if Present (Decl)
8276 and then Nkind (Decl) = N_Subprogram_Declaration
8277 and then Present (Corresponding_Body (Decl))
8278 and then Nkind (Unit_Declaration_Node
8279 (Corresponding_Body (Decl))) =
8280 N_Subprogram_Renaming_Declaration
8281 then
8282 Error_Msg_Sloc := Sloc (Def_Id);
8283 Error_Msg_NE
8284 ("cannot import&, renaming already provided for "
8285 & "declaration #", N, Def_Id);
8286 end if;
8287 end;
8289 -- If the pragma comes from an aspect specification, there
8290 -- must be an Import aspect specified as well. In the rare
8291 -- case where Import is set to False, the suprogram needs to
8292 -- have a local completion.
8294 declare
8295 Imp_Aspect : constant Node_Id :=
8296 Find_Aspect (Def_Id, Aspect_Import);
8297 Expr : Node_Id;
8299 begin
8300 if Present (Imp_Aspect)
8301 and then Present (Expression (Imp_Aspect))
8302 then
8303 Expr := Expression (Imp_Aspect);
8304 Analyze_And_Resolve (Expr, Standard_Boolean);
8306 if Is_Entity_Name (Expr)
8307 and then Entity (Expr) = Standard_True
8308 then
8309 Set_Has_Completion (Def_Id);
8310 end if;
8312 -- If there is no expression, the default is True, as for
8313 -- all boolean aspects. Same for the older pragma.
8315 else
8316 Set_Has_Completion (Def_Id);
8317 end if;
8318 end;
8320 Process_Interface_Name (Def_Id, Arg3, Arg4);
8321 end if;
8323 if Is_Compilation_Unit (Hom_Id) then
8325 -- Its possible homonyms are not affected by the pragma.
8326 -- Such homonyms might be present in the context of other
8327 -- units being compiled.
8329 exit;
8331 elsif From_Aspect_Specification (N) then
8332 exit;
8334 -- If the pragma was created by the compiler, then we don't
8335 -- want it to apply to other homonyms. This kind of case can
8336 -- occur when using pragma Provide_Shift_Operators, which
8337 -- generates implicit shift and rotate operators with Import
8338 -- pragmas that might apply to earlier explicit or implicit
8339 -- declarations marked with Import (for example, coming from
8340 -- an earlier pragma Provide_Shift_Operators for another type),
8341 -- and we don't generally want other homonyms being treated
8342 -- as imported or the pragma flagged as an illegal duplicate.
8344 elsif not Comes_From_Source (N) then
8345 exit;
8347 else
8348 Hom_Id := Homonym (Hom_Id);
8349 end if;
8350 end loop;
8352 -- Import a CPP class
8354 elsif C = Convention_CPP
8355 and then (Is_Record_Type (Def_Id)
8356 or else Ekind (Def_Id) = E_Incomplete_Type)
8357 then
8358 if Ekind (Def_Id) = E_Incomplete_Type then
8359 if Present (Full_View (Def_Id)) then
8360 Def_Id := Full_View (Def_Id);
8362 else
8363 Error_Msg_N
8364 ("cannot import 'C'P'P type before full declaration seen",
8365 Get_Pragma_Arg (Arg2));
8367 -- Although we have reported the error we decorate it as
8368 -- CPP_Class to avoid reporting spurious errors
8370 Set_Is_CPP_Class (Def_Id);
8371 return;
8372 end if;
8373 end if;
8375 -- Types treated as CPP classes must be declared limited (note:
8376 -- this used to be a warning but there is no real benefit to it
8377 -- since we did effectively intend to treat the type as limited
8378 -- anyway).
8380 if not Is_Limited_Type (Def_Id) then
8381 Error_Msg_N
8382 ("imported 'C'P'P type must be limited",
8383 Get_Pragma_Arg (Arg2));
8384 end if;
8386 if Etype (Def_Id) /= Def_Id
8387 and then not Is_CPP_Class (Root_Type (Def_Id))
8388 then
8389 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
8390 end if;
8392 Set_Is_CPP_Class (Def_Id);
8394 -- Imported CPP types must not have discriminants (because C++
8395 -- classes do not have discriminants).
8397 if Has_Discriminants (Def_Id) then
8398 Error_Msg_N
8399 ("imported 'C'P'P type cannot have discriminants",
8400 First (Discriminant_Specifications
8401 (Declaration_Node (Def_Id))));
8402 end if;
8404 -- Check that components of imported CPP types do not have default
8405 -- expressions. For private types this check is performed when the
8406 -- full view is analyzed (see Process_Full_View).
8408 if not Is_Private_Type (Def_Id) then
8409 Check_CPP_Type_Has_No_Defaults (Def_Id);
8410 end if;
8412 -- Import a CPP exception
8414 elsif C = Convention_CPP
8415 and then Ekind (Def_Id) = E_Exception
8416 then
8417 if No (Arg3) then
8418 Error_Pragma_Arg
8419 ("'External_'Name arguments is required for 'Cpp exception",
8420 Arg3);
8421 else
8422 -- As only a string is allowed, Check_Arg_Is_External_Name
8423 -- isn't called.
8425 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8426 end if;
8428 if Present (Arg4) then
8429 Error_Pragma_Arg
8430 ("Link_Name argument not allowed for imported Cpp exception",
8431 Arg4);
8432 end if;
8434 -- Do not call Set_Interface_Name as the name of the exception
8435 -- shouldn't be modified (and in particular it shouldn't be
8436 -- the External_Name). For exceptions, the External_Name is the
8437 -- name of the RTTI structure.
8439 -- ??? Emit an error if pragma Import/Export_Exception is present
8441 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
8442 Check_No_Link_Name;
8443 Check_Arg_Count (3);
8444 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8446 Process_Import_Predefined_Type;
8448 else
8449 Error_Pragma_Arg
8450 ("second argument of pragma% must be object, subprogram "
8451 & "or incomplete type",
8452 Arg2);
8453 end if;
8455 -- If this pragma applies to a compilation unit, then the unit, which
8456 -- is a subprogram, does not require (or allow) a body. We also do
8457 -- not need to elaborate imported procedures.
8459 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
8460 declare
8461 Cunit : constant Node_Id := Parent (Parent (N));
8462 begin
8463 Set_Body_Required (Cunit, False);
8464 end;
8465 end if;
8466 end Process_Import_Or_Interface;
8468 --------------------
8469 -- Process_Inline --
8470 --------------------
8472 procedure Process_Inline (Status : Inline_Status) is
8473 Applies : Boolean;
8474 Assoc : Node_Id;
8475 Decl : Node_Id;
8476 Subp : Entity_Id;
8477 Subp_Id : Node_Id;
8479 Ghost_Error_Posted : Boolean := False;
8480 -- Flag set when an error concerning the illegal mix of Ghost and
8481 -- non-Ghost subprograms is emitted.
8483 Ghost_Id : Entity_Id := Empty;
8484 -- The entity of the first Ghost subprogram encountered while
8485 -- processing the arguments of the pragma.
8487 procedure Make_Inline (Subp : Entity_Id);
8488 -- Subp is the defining unit name of the subprogram declaration. Set
8489 -- the flag, as well as the flag in the corresponding body, if there
8490 -- is one present.
8492 procedure Set_Inline_Flags (Subp : Entity_Id);
8493 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
8494 -- Has_Pragma_Inline_Always for the Inline_Always case.
8496 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
8497 -- Returns True if it can be determined at this stage that inlining
8498 -- is not possible, for example if the body is available and contains
8499 -- exception handlers, we prevent inlining, since otherwise we can
8500 -- get undefined symbols at link time. This function also emits a
8501 -- warning if front-end inlining is enabled and the pragma appears
8502 -- too late.
8504 -- ??? is business with link symbols still valid, or does it relate
8505 -- to front end ZCX which is being phased out ???
8507 ---------------------------
8508 -- Inlining_Not_Possible --
8509 ---------------------------
8511 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
8512 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
8513 Stats : Node_Id;
8515 begin
8516 if Nkind (Decl) = N_Subprogram_Body then
8517 Stats := Handled_Statement_Sequence (Decl);
8518 return Present (Exception_Handlers (Stats))
8519 or else Present (At_End_Proc (Stats));
8521 elsif Nkind (Decl) = N_Subprogram_Declaration
8522 and then Present (Corresponding_Body (Decl))
8523 then
8524 if Front_End_Inlining
8525 and then Analyzed (Corresponding_Body (Decl))
8526 then
8527 Error_Msg_N ("pragma appears too late, ignored??", N);
8528 return True;
8530 -- If the subprogram is a renaming as body, the body is just a
8531 -- call to the renamed subprogram, and inlining is trivially
8532 -- possible.
8534 elsif
8535 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
8536 N_Subprogram_Renaming_Declaration
8537 then
8538 return False;
8540 else
8541 Stats :=
8542 Handled_Statement_Sequence
8543 (Unit_Declaration_Node (Corresponding_Body (Decl)));
8545 return
8546 Present (Exception_Handlers (Stats))
8547 or else Present (At_End_Proc (Stats));
8548 end if;
8550 else
8551 -- If body is not available, assume the best, the check is
8552 -- performed again when compiling enclosing package bodies.
8554 return False;
8555 end if;
8556 end Inlining_Not_Possible;
8558 -----------------
8559 -- Make_Inline --
8560 -----------------
8562 procedure Make_Inline (Subp : Entity_Id) is
8563 Kind : constant Entity_Kind := Ekind (Subp);
8564 Inner_Subp : Entity_Id := Subp;
8566 begin
8567 -- Ignore if bad type, avoid cascaded error
8569 if Etype (Subp) = Any_Type then
8570 Applies := True;
8571 return;
8573 -- If inlining is not possible, for now do not treat as an error
8575 elsif Status /= Suppressed
8576 and then Inlining_Not_Possible (Subp)
8577 then
8578 Applies := True;
8579 return;
8581 -- Here we have a candidate for inlining, but we must exclude
8582 -- derived operations. Otherwise we would end up trying to inline
8583 -- a phantom declaration, and the result would be to drag in a
8584 -- body which has no direct inlining associated with it. That
8585 -- would not only be inefficient but would also result in the
8586 -- backend doing cross-unit inlining in cases where it was
8587 -- definitely inappropriate to do so.
8589 -- However, a simple Comes_From_Source test is insufficient, since
8590 -- we do want to allow inlining of generic instances which also do
8591 -- not come from source. We also need to recognize specs generated
8592 -- by the front-end for bodies that carry the pragma. Finally,
8593 -- predefined operators do not come from source but are not
8594 -- inlineable either.
8596 elsif Is_Generic_Instance (Subp)
8597 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
8598 then
8599 null;
8601 elsif not Comes_From_Source (Subp)
8602 and then Scope (Subp) /= Standard_Standard
8603 then
8604 Applies := True;
8605 return;
8606 end if;
8608 -- The referenced entity must either be the enclosing entity, or
8609 -- an entity declared within the current open scope.
8611 if Present (Scope (Subp))
8612 and then Scope (Subp) /= Current_Scope
8613 and then Subp /= Current_Scope
8614 then
8615 Error_Pragma_Arg
8616 ("argument of% must be entity in current scope", Assoc);
8617 return;
8618 end if;
8620 -- Processing for procedure, operator or function. If subprogram
8621 -- is aliased (as for an instance) indicate that the renamed
8622 -- entity (if declared in the same unit) is inlined.
8623 -- If this is the anonymous subprogram created for a subprogram
8624 -- instance, the inlining applies to it directly. Otherwise we
8625 -- retrieve it as the alias of the visible subprogram instance.
8627 if Is_Subprogram (Subp) then
8628 if Is_Wrapper_Package (Scope (Subp)) then
8629 Inner_Subp := Subp;
8630 else
8631 Inner_Subp := Ultimate_Alias (Inner_Subp);
8632 end if;
8634 if In_Same_Source_Unit (Subp, Inner_Subp) then
8635 Set_Inline_Flags (Inner_Subp);
8637 Decl := Parent (Parent (Inner_Subp));
8639 if Nkind (Decl) = N_Subprogram_Declaration
8640 and then Present (Corresponding_Body (Decl))
8641 then
8642 Set_Inline_Flags (Corresponding_Body (Decl));
8644 elsif Is_Generic_Instance (Subp)
8645 and then Comes_From_Source (Subp)
8646 then
8647 -- Indicate that the body needs to be created for
8648 -- inlining subsequent calls. The instantiation node
8649 -- follows the declaration of the wrapper package
8650 -- created for it. The subprogram that requires the
8651 -- body is the anonymous one in the wrapper package.
8653 if Scope (Subp) /= Standard_Standard
8654 and then
8655 Need_Subprogram_Instance_Body
8656 (Next (Unit_Declaration_Node
8657 (Scope (Alias (Subp)))), Subp)
8658 then
8659 null;
8660 end if;
8662 -- Inline is a program unit pragma (RM 10.1.5) and cannot
8663 -- appear in a formal part to apply to a formal subprogram.
8664 -- Do not apply check within an instance or a formal package
8665 -- the test will have been applied to the original generic.
8667 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
8668 and then List_Containing (Decl) = List_Containing (N)
8669 and then not In_Instance
8670 then
8671 Error_Msg_N
8672 ("Inline cannot apply to a formal subprogram", N);
8674 -- If Subp is a renaming, it is the renamed entity that
8675 -- will appear in any call, and be inlined. However, for
8676 -- ASIS uses it is convenient to indicate that the renaming
8677 -- itself is an inlined subprogram, so that some gnatcheck
8678 -- rules can be applied in the absence of expansion.
8680 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
8681 Set_Inline_Flags (Subp);
8682 end if;
8683 end if;
8685 Applies := True;
8687 -- For a generic subprogram set flag as well, for use at the point
8688 -- of instantiation, to determine whether the body should be
8689 -- generated.
8691 elsif Is_Generic_Subprogram (Subp) then
8692 Set_Inline_Flags (Subp);
8693 Applies := True;
8695 -- Literals are by definition inlined
8697 elsif Kind = E_Enumeration_Literal then
8698 null;
8700 -- Anything else is an error
8702 else
8703 Error_Pragma_Arg
8704 ("expect subprogram name for pragma%", Assoc);
8705 end if;
8706 end Make_Inline;
8708 ----------------------
8709 -- Set_Inline_Flags --
8710 ----------------------
8712 procedure Set_Inline_Flags (Subp : Entity_Id) is
8713 begin
8714 -- First set the Has_Pragma_XXX flags and issue the appropriate
8715 -- errors and warnings for suspicious combinations.
8717 if Prag_Id = Pragma_No_Inline then
8718 if Has_Pragma_Inline_Always (Subp) then
8719 Error_Msg_N
8720 ("Inline_Always and No_Inline are mutually exclusive", N);
8721 elsif Has_Pragma_Inline (Subp) then
8722 Error_Msg_NE
8723 ("Inline and No_Inline both specified for& ??",
8724 N, Entity (Subp_Id));
8725 end if;
8727 Set_Has_Pragma_No_Inline (Subp);
8728 else
8729 if Prag_Id = Pragma_Inline_Always then
8730 if Has_Pragma_No_Inline (Subp) then
8731 Error_Msg_N
8732 ("Inline_Always and No_Inline are mutually exclusive",
8734 end if;
8736 Set_Has_Pragma_Inline_Always (Subp);
8737 else
8738 if Has_Pragma_No_Inline (Subp) then
8739 Error_Msg_NE
8740 ("Inline and No_Inline both specified for& ??",
8741 N, Entity (Subp_Id));
8742 end if;
8743 end if;
8745 if not Has_Pragma_Inline (Subp) then
8746 Set_Has_Pragma_Inline (Subp);
8747 end if;
8748 end if;
8750 -- Then adjust the Is_Inlined flag. It can never be set if the
8751 -- subprogram is subject to pragma No_Inline.
8753 case Status is
8754 when Suppressed =>
8755 Set_Is_Inlined (Subp, False);
8756 when Disabled =>
8757 null;
8758 when Enabled =>
8759 if not Has_Pragma_No_Inline (Subp) then
8760 Set_Is_Inlined (Subp, True);
8761 end if;
8762 end case;
8764 -- A pragma that applies to a Ghost entity becomes Ghost for the
8765 -- purposes of legality checks and removal of ignored Ghost code.
8767 Mark_Pragma_As_Ghost (N, Subp);
8769 -- Capture the entity of the first Ghost subprogram being
8770 -- processed for error detection purposes.
8772 if Is_Ghost_Entity (Subp) then
8773 if No (Ghost_Id) then
8774 Ghost_Id := Subp;
8775 end if;
8777 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
8778 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
8780 elsif Present (Ghost_Id) and then not Ghost_Error_Posted then
8781 Ghost_Error_Posted := True;
8783 Error_Msg_Name_1 := Pname;
8784 Error_Msg_N
8785 ("pragma % cannot mention ghost and non-ghost subprograms",
8788 Error_Msg_Sloc := Sloc (Ghost_Id);
8789 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
8791 Error_Msg_Sloc := Sloc (Subp);
8792 Error_Msg_NE ("\& # declared as non-ghost", N, Subp);
8793 end if;
8794 end Set_Inline_Flags;
8796 -- Start of processing for Process_Inline
8798 begin
8799 Check_No_Identifiers;
8800 Check_At_Least_N_Arguments (1);
8802 if Status = Enabled then
8803 Inline_Processing_Required := True;
8804 end if;
8806 Assoc := Arg1;
8807 while Present (Assoc) loop
8808 Subp_Id := Get_Pragma_Arg (Assoc);
8809 Analyze (Subp_Id);
8810 Applies := False;
8812 if Is_Entity_Name (Subp_Id) then
8813 Subp := Entity (Subp_Id);
8815 if Subp = Any_Id then
8817 -- If previous error, avoid cascaded errors
8819 Check_Error_Detected;
8820 Applies := True;
8822 else
8823 Make_Inline (Subp);
8825 -- For the pragma case, climb homonym chain. This is
8826 -- what implements allowing the pragma in the renaming
8827 -- case, with the result applying to the ancestors, and
8828 -- also allows Inline to apply to all previous homonyms.
8830 if not From_Aspect_Specification (N) then
8831 while Present (Homonym (Subp))
8832 and then Scope (Homonym (Subp)) = Current_Scope
8833 loop
8834 Make_Inline (Homonym (Subp));
8835 Subp := Homonym (Subp);
8836 end loop;
8837 end if;
8838 end if;
8839 end if;
8841 if not Applies then
8842 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
8843 end if;
8845 Next (Assoc);
8846 end loop;
8847 end Process_Inline;
8849 ----------------------------
8850 -- Process_Interface_Name --
8851 ----------------------------
8853 procedure Process_Interface_Name
8854 (Subprogram_Def : Entity_Id;
8855 Ext_Arg : Node_Id;
8856 Link_Arg : Node_Id)
8858 Ext_Nam : Node_Id;
8859 Link_Nam : Node_Id;
8860 String_Val : String_Id;
8862 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
8863 -- SN is a string literal node for an interface name. This routine
8864 -- performs some minimal checks that the name is reasonable. In
8865 -- particular that no spaces or other obviously incorrect characters
8866 -- appear. This is only a warning, since any characters are allowed.
8868 ----------------------------------
8869 -- Check_Form_Of_Interface_Name --
8870 ----------------------------------
8872 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
8873 S : constant String_Id := Strval (Expr_Value_S (SN));
8874 SL : constant Nat := String_Length (S);
8875 C : Char_Code;
8877 begin
8878 if SL = 0 then
8879 Error_Msg_N ("interface name cannot be null string", SN);
8880 end if;
8882 for J in 1 .. SL loop
8883 C := Get_String_Char (S, J);
8885 -- Look for dubious character and issue unconditional warning.
8886 -- Definitely dubious if not in character range.
8888 if not In_Character_Range (C)
8890 -- Commas, spaces and (back)slashes are dubious
8892 or else Get_Character (C) = ','
8893 or else Get_Character (C) = '\'
8894 or else Get_Character (C) = ' '
8895 or else Get_Character (C) = '/'
8896 then
8897 Error_Msg
8898 ("??interface name contains illegal character",
8899 Sloc (SN) + Source_Ptr (J));
8900 end if;
8901 end loop;
8902 end Check_Form_Of_Interface_Name;
8904 -- Start of processing for Process_Interface_Name
8906 begin
8907 if No (Link_Arg) then
8908 if No (Ext_Arg) then
8909 return;
8911 elsif Chars (Ext_Arg) = Name_Link_Name then
8912 Ext_Nam := Empty;
8913 Link_Nam := Expression (Ext_Arg);
8915 else
8916 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
8917 Ext_Nam := Expression (Ext_Arg);
8918 Link_Nam := Empty;
8919 end if;
8921 else
8922 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
8923 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
8924 Ext_Nam := Expression (Ext_Arg);
8925 Link_Nam := Expression (Link_Arg);
8926 end if;
8928 -- Check expressions for external name and link name are static
8930 if Present (Ext_Nam) then
8931 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
8932 Check_Form_Of_Interface_Name (Ext_Nam);
8934 -- Verify that external name is not the name of a local entity,
8935 -- which would hide the imported one and could lead to run-time
8936 -- surprises. The problem can only arise for entities declared in
8937 -- a package body (otherwise the external name is fully qualified
8938 -- and will not conflict).
8940 declare
8941 Nam : Name_Id;
8942 E : Entity_Id;
8943 Par : Node_Id;
8945 begin
8946 if Prag_Id = Pragma_Import then
8947 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
8948 Nam := Name_Find;
8949 E := Entity_Id (Get_Name_Table_Int (Nam));
8951 if Nam /= Chars (Subprogram_Def)
8952 and then Present (E)
8953 and then not Is_Overloadable (E)
8954 and then Is_Immediately_Visible (E)
8955 and then not Is_Imported (E)
8956 and then Ekind (Scope (E)) = E_Package
8957 then
8958 Par := Parent (E);
8959 while Present (Par) loop
8960 if Nkind (Par) = N_Package_Body then
8961 Error_Msg_Sloc := Sloc (E);
8962 Error_Msg_NE
8963 ("imported entity is hidden by & declared#",
8964 Ext_Arg, E);
8965 exit;
8966 end if;
8968 Par := Parent (Par);
8969 end loop;
8970 end if;
8971 end if;
8972 end;
8973 end if;
8975 if Present (Link_Nam) then
8976 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
8977 Check_Form_Of_Interface_Name (Link_Nam);
8978 end if;
8980 -- If there is no link name, just set the external name
8982 if No (Link_Nam) then
8983 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
8985 -- For the Link_Name case, the given literal is preceded by an
8986 -- asterisk, which indicates to GCC that the given name should be
8987 -- taken literally, and in particular that no prepending of
8988 -- underlines should occur, even in systems where this is the
8989 -- normal default.
8991 else
8992 Start_String;
8993 Store_String_Char (Get_Char_Code ('*'));
8994 String_Val := Strval (Expr_Value_S (Link_Nam));
8995 Store_String_Chars (String_Val);
8996 Link_Nam :=
8997 Make_String_Literal (Sloc (Link_Nam),
8998 Strval => End_String);
8999 end if;
9001 -- Set the interface name. If the entity is a generic instance, use
9002 -- its alias, which is the callable entity.
9004 if Is_Generic_Instance (Subprogram_Def) then
9005 Set_Encoded_Interface_Name
9006 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
9007 else
9008 Set_Encoded_Interface_Name
9009 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
9010 end if;
9012 Check_Duplicated_Export_Name (Link_Nam);
9013 end Process_Interface_Name;
9015 -----------------------------------------
9016 -- Process_Interrupt_Or_Attach_Handler --
9017 -----------------------------------------
9019 procedure Process_Interrupt_Or_Attach_Handler is
9020 Handler : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
9021 Prot_Typ : constant Entity_Id := Scope (Handler);
9023 begin
9024 -- A pragma that applies to a Ghost entity becomes Ghost for the
9025 -- purposes of legality checks and removal of ignored Ghost code.
9027 Mark_Pragma_As_Ghost (N, Handler);
9028 Set_Is_Interrupt_Handler (Handler);
9030 -- If the pragma is not associated with a handler procedure within a
9031 -- protected type, then it must be for a nonprotected procedure for
9032 -- the AAMP target, in which case we don't associate a representation
9033 -- item with the procedure's scope.
9035 if Ekind (Prot_Typ) = E_Protected_Type then
9036 Record_Rep_Item (Prot_Typ, N);
9037 end if;
9039 -- Chain the pragma on the contract for completeness
9041 Add_Contract_Item (N, Handler);
9042 end Process_Interrupt_Or_Attach_Handler;
9044 --------------------------------------------------
9045 -- Process_Restrictions_Or_Restriction_Warnings --
9046 --------------------------------------------------
9048 -- Note: some of the simple identifier cases were handled in par-prag,
9049 -- but it is harmless (and more straightforward) to simply handle all
9050 -- cases here, even if it means we repeat a bit of work in some cases.
9052 procedure Process_Restrictions_Or_Restriction_Warnings
9053 (Warn : Boolean)
9055 Arg : Node_Id;
9056 R_Id : Restriction_Id;
9057 Id : Name_Id;
9058 Expr : Node_Id;
9059 Val : Uint;
9061 begin
9062 -- Ignore all Restrictions pragmas in CodePeer mode
9064 if CodePeer_Mode then
9065 return;
9066 end if;
9068 Check_Ada_83_Warning;
9069 Check_At_Least_N_Arguments (1);
9070 Check_Valid_Configuration_Pragma;
9072 Arg := Arg1;
9073 while Present (Arg) loop
9074 Id := Chars (Arg);
9075 Expr := Get_Pragma_Arg (Arg);
9077 -- Case of no restriction identifier present
9079 if Id = No_Name then
9080 if Nkind (Expr) /= N_Identifier then
9081 Error_Pragma_Arg
9082 ("invalid form for restriction", Arg);
9083 end if;
9085 R_Id :=
9086 Get_Restriction_Id
9087 (Process_Restriction_Synonyms (Expr));
9089 if R_Id not in All_Boolean_Restrictions then
9090 Error_Msg_Name_1 := Pname;
9091 Error_Msg_N
9092 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
9094 -- Check for possible misspelling
9096 for J in Restriction_Id loop
9097 declare
9098 Rnm : constant String := Restriction_Id'Image (J);
9100 begin
9101 Name_Buffer (1 .. Rnm'Length) := Rnm;
9102 Name_Len := Rnm'Length;
9103 Set_Casing (All_Lower_Case);
9105 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
9106 Set_Casing
9107 (Identifier_Casing (Current_Source_File));
9108 Error_Msg_String (1 .. Rnm'Length) :=
9109 Name_Buffer (1 .. Name_Len);
9110 Error_Msg_Strlen := Rnm'Length;
9111 Error_Msg_N -- CODEFIX
9112 ("\possible misspelling of ""~""",
9113 Get_Pragma_Arg (Arg));
9114 exit;
9115 end if;
9116 end;
9117 end loop;
9119 raise Pragma_Exit;
9120 end if;
9122 if Implementation_Restriction (R_Id) then
9123 Check_Restriction (No_Implementation_Restrictions, Arg);
9124 end if;
9126 -- Special processing for No_Elaboration_Code restriction
9128 if R_Id = No_Elaboration_Code then
9130 -- Restriction is only recognized within a configuration
9131 -- pragma file, or within a unit of the main extended
9132 -- program. Note: the test for Main_Unit is needed to
9133 -- properly include the case of configuration pragma files.
9135 if not (Current_Sem_Unit = Main_Unit
9136 or else In_Extended_Main_Source_Unit (N))
9137 then
9138 return;
9140 -- Don't allow in a subunit unless already specified in
9141 -- body or spec.
9143 elsif Nkind (Parent (N)) = N_Compilation_Unit
9144 and then Nkind (Unit (Parent (N))) = N_Subunit
9145 and then not Restriction_Active (No_Elaboration_Code)
9146 then
9147 Error_Msg_N
9148 ("invalid specification of ""No_Elaboration_Code""",
9150 Error_Msg_N
9151 ("\restriction cannot be specified in a subunit", N);
9152 Error_Msg_N
9153 ("\unless also specified in body or spec", N);
9154 return;
9156 -- If we accept a No_Elaboration_Code restriction, then it
9157 -- needs to be added to the configuration restriction set so
9158 -- that we get proper application to other units in the main
9159 -- extended source as required.
9161 else
9162 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
9163 end if;
9164 end if;
9166 -- If this is a warning, then set the warning unless we already
9167 -- have a real restriction active (we never want a warning to
9168 -- override a real restriction).
9170 if Warn then
9171 if not Restriction_Active (R_Id) then
9172 Set_Restriction (R_Id, N);
9173 Restriction_Warnings (R_Id) := True;
9174 end if;
9176 -- If real restriction case, then set it and make sure that the
9177 -- restriction warning flag is off, since a real restriction
9178 -- always overrides a warning.
9180 else
9181 Set_Restriction (R_Id, N);
9182 Restriction_Warnings (R_Id) := False;
9183 end if;
9185 -- Check for obsolescent restrictions in Ada 2005 mode
9187 if not Warn
9188 and then Ada_Version >= Ada_2005
9189 and then (R_Id = No_Asynchronous_Control
9190 or else
9191 R_Id = No_Unchecked_Deallocation
9192 or else
9193 R_Id = No_Unchecked_Conversion)
9194 then
9195 Check_Restriction (No_Obsolescent_Features, N);
9196 end if;
9198 -- A very special case that must be processed here: pragma
9199 -- Restrictions (No_Exceptions) turns off all run-time
9200 -- checking. This is a bit dubious in terms of the formal
9201 -- language definition, but it is what is intended by RM
9202 -- H.4(12). Restriction_Warnings never affects generated code
9203 -- so this is done only in the real restriction case.
9205 -- Atomic_Synchronization is not a real check, so it is not
9206 -- affected by this processing).
9208 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
9209 -- run-time checks in CodePeer and GNATprove modes: we want to
9210 -- generate checks for analysis purposes, as set respectively
9211 -- by -gnatC and -gnatd.F
9213 if not Warn
9214 and then not (CodePeer_Mode or GNATprove_Mode)
9215 and then R_Id = No_Exceptions
9216 then
9217 for J in Scope_Suppress.Suppress'Range loop
9218 if J /= Atomic_Synchronization then
9219 Scope_Suppress.Suppress (J) := True;
9220 end if;
9221 end loop;
9222 end if;
9224 -- Case of No_Dependence => unit-name. Note that the parser
9225 -- already made the necessary entry in the No_Dependence table.
9227 elsif Id = Name_No_Dependence then
9228 if not OK_No_Dependence_Unit_Name (Expr) then
9229 raise Pragma_Exit;
9230 end if;
9232 -- Case of No_Specification_Of_Aspect => aspect-identifier
9234 elsif Id = Name_No_Specification_Of_Aspect then
9235 declare
9236 A_Id : Aspect_Id;
9238 begin
9239 if Nkind (Expr) /= N_Identifier then
9240 A_Id := No_Aspect;
9241 else
9242 A_Id := Get_Aspect_Id (Chars (Expr));
9243 end if;
9245 if A_Id = No_Aspect then
9246 Error_Pragma_Arg ("invalid restriction name", Arg);
9247 else
9248 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
9249 end if;
9250 end;
9252 -- Case of No_Use_Of_Attribute => attribute-identifier
9254 elsif Id = Name_No_Use_Of_Attribute then
9255 if Nkind (Expr) /= N_Identifier
9256 or else not Is_Attribute_Name (Chars (Expr))
9257 then
9258 Error_Msg_N ("unknown attribute name??", Expr);
9260 else
9261 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
9262 end if;
9264 -- Case of No_Use_Of_Entity => fully-qualified-name
9266 elsif Id = Name_No_Use_Of_Entity then
9268 -- Restriction is only recognized within a configuration
9269 -- pragma file, or within a unit of the main extended
9270 -- program. Note: the test for Main_Unit is needed to
9271 -- properly include the case of configuration pragma files.
9273 if Current_Sem_Unit = Main_Unit
9274 or else In_Extended_Main_Source_Unit (N)
9275 then
9276 if not OK_No_Dependence_Unit_Name (Expr) then
9277 Error_Msg_N ("wrong form for entity name", Expr);
9278 else
9279 Set_Restriction_No_Use_Of_Entity
9280 (Expr, Warn, No_Profile);
9281 end if;
9282 end if;
9284 -- Case of No_Use_Of_Pragma => pragma-identifier
9286 elsif Id = Name_No_Use_Of_Pragma then
9287 if Nkind (Expr) /= N_Identifier
9288 or else not Is_Pragma_Name (Chars (Expr))
9289 then
9290 Error_Msg_N ("unknown pragma name??", Expr);
9291 else
9292 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
9293 end if;
9295 -- All other cases of restriction identifier present
9297 else
9298 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
9299 Analyze_And_Resolve (Expr, Any_Integer);
9301 if R_Id not in All_Parameter_Restrictions then
9302 Error_Pragma_Arg
9303 ("invalid restriction parameter identifier", Arg);
9305 elsif not Is_OK_Static_Expression (Expr) then
9306 Flag_Non_Static_Expr
9307 ("value must be static expression!", Expr);
9308 raise Pragma_Exit;
9310 elsif not Is_Integer_Type (Etype (Expr))
9311 or else Expr_Value (Expr) < 0
9312 then
9313 Error_Pragma_Arg
9314 ("value must be non-negative integer", Arg);
9315 end if;
9317 -- Restriction pragma is active
9319 Val := Expr_Value (Expr);
9321 if not UI_Is_In_Int_Range (Val) then
9322 Error_Pragma_Arg
9323 ("pragma ignored, value too large??", Arg);
9324 end if;
9326 -- Warning case. If the real restriction is active, then we
9327 -- ignore the request, since warning never overrides a real
9328 -- restriction. Otherwise we set the proper warning. Note that
9329 -- this circuit sets the warning again if it is already set,
9330 -- which is what we want, since the constant may have changed.
9332 if Warn then
9333 if not Restriction_Active (R_Id) then
9334 Set_Restriction
9335 (R_Id, N, Integer (UI_To_Int (Val)));
9336 Restriction_Warnings (R_Id) := True;
9337 end if;
9339 -- Real restriction case, set restriction and make sure warning
9340 -- flag is off since real restriction always overrides warning.
9342 else
9343 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
9344 Restriction_Warnings (R_Id) := False;
9345 end if;
9346 end if;
9348 Next (Arg);
9349 end loop;
9350 end Process_Restrictions_Or_Restriction_Warnings;
9352 ---------------------------------
9353 -- Process_Suppress_Unsuppress --
9354 ---------------------------------
9356 -- Note: this procedure makes entries in the check suppress data
9357 -- structures managed by Sem. See spec of package Sem for full
9358 -- details on how we handle recording of check suppression.
9360 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
9361 C : Check_Id;
9362 E : Entity_Id;
9363 E_Id : Node_Id;
9365 In_Package_Spec : constant Boolean :=
9366 Is_Package_Or_Generic_Package (Current_Scope)
9367 and then not In_Package_Body (Current_Scope);
9369 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
9370 -- Used to suppress a single check on the given entity
9372 --------------------------------
9373 -- Suppress_Unsuppress_Echeck --
9374 --------------------------------
9376 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
9377 begin
9378 -- Check for error of trying to set atomic synchronization for
9379 -- a non-atomic variable.
9381 if C = Atomic_Synchronization
9382 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
9383 then
9384 Error_Msg_N
9385 ("pragma & requires atomic type or variable",
9386 Pragma_Identifier (Original_Node (N)));
9387 end if;
9389 Set_Checks_May_Be_Suppressed (E);
9391 if In_Package_Spec then
9392 Push_Global_Suppress_Stack_Entry
9393 (Entity => E,
9394 Check => C,
9395 Suppress => Suppress_Case);
9396 else
9397 Push_Local_Suppress_Stack_Entry
9398 (Entity => E,
9399 Check => C,
9400 Suppress => Suppress_Case);
9401 end if;
9403 -- If this is a first subtype, and the base type is distinct,
9404 -- then also set the suppress flags on the base type.
9406 if Is_First_Subtype (E) and then Etype (E) /= E then
9407 Suppress_Unsuppress_Echeck (Etype (E), C);
9408 end if;
9409 end Suppress_Unsuppress_Echeck;
9411 -- Start of processing for Process_Suppress_Unsuppress
9413 begin
9414 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
9415 -- on user code: we want to generate checks for analysis purposes, as
9416 -- set respectively by -gnatC and -gnatd.F
9418 if Comes_From_Source (N)
9419 and then (CodePeer_Mode or GNATprove_Mode)
9420 then
9421 return;
9422 end if;
9424 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
9425 -- declarative part or a package spec (RM 11.5(5)).
9427 if not Is_Configuration_Pragma then
9428 Check_Is_In_Decl_Part_Or_Package_Spec;
9429 end if;
9431 Check_At_Least_N_Arguments (1);
9432 Check_At_Most_N_Arguments (2);
9433 Check_No_Identifier (Arg1);
9434 Check_Arg_Is_Identifier (Arg1);
9436 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
9438 if C = No_Check_Id then
9439 Error_Pragma_Arg
9440 ("argument of pragma% is not valid check name", Arg1);
9441 end if;
9443 -- Warn that suppress of Elaboration_Check has no effect in SPARK
9445 if C = Elaboration_Check and then SPARK_Mode = On then
9446 Error_Pragma_Arg
9447 ("Suppress of Elaboration_Check ignored in SPARK??",
9448 "\elaboration checking rules are statically enforced "
9449 & "(SPARK RM 7.7)", Arg1);
9450 end if;
9452 -- One-argument case
9454 if Arg_Count = 1 then
9456 -- Make an entry in the local scope suppress table. This is the
9457 -- table that directly shows the current value of the scope
9458 -- suppress check for any check id value.
9460 if C = All_Checks then
9462 -- For All_Checks, we set all specific predefined checks with
9463 -- the exception of Elaboration_Check, which is handled
9464 -- specially because of not wanting All_Checks to have the
9465 -- effect of deactivating static elaboration order processing.
9466 -- Atomic_Synchronization is also not affected, since this is
9467 -- not a real check.
9469 for J in Scope_Suppress.Suppress'Range loop
9470 if J /= Elaboration_Check
9471 and then
9472 J /= Atomic_Synchronization
9473 then
9474 Scope_Suppress.Suppress (J) := Suppress_Case;
9475 end if;
9476 end loop;
9478 -- If not All_Checks, and predefined check, then set appropriate
9479 -- scope entry. Note that we will set Elaboration_Check if this
9480 -- is explicitly specified. Atomic_Synchronization is allowed
9481 -- only if internally generated and entity is atomic.
9483 elsif C in Predefined_Check_Id
9484 and then (not Comes_From_Source (N)
9485 or else C /= Atomic_Synchronization)
9486 then
9487 Scope_Suppress.Suppress (C) := Suppress_Case;
9488 end if;
9490 -- Also make an entry in the Local_Entity_Suppress table
9492 Push_Local_Suppress_Stack_Entry
9493 (Entity => Empty,
9494 Check => C,
9495 Suppress => Suppress_Case);
9497 -- Case of two arguments present, where the check is suppressed for
9498 -- a specified entity (given as the second argument of the pragma)
9500 else
9501 -- This is obsolescent in Ada 2005 mode
9503 if Ada_Version >= Ada_2005 then
9504 Check_Restriction (No_Obsolescent_Features, Arg2);
9505 end if;
9507 Check_Optional_Identifier (Arg2, Name_On);
9508 E_Id := Get_Pragma_Arg (Arg2);
9509 Analyze (E_Id);
9511 if not Is_Entity_Name (E_Id) then
9512 Error_Pragma_Arg
9513 ("second argument of pragma% must be entity name", Arg2);
9514 end if;
9516 E := Entity (E_Id);
9518 if E = Any_Id then
9519 return;
9520 end if;
9522 -- A pragma that applies to a Ghost entity becomes Ghost for the
9523 -- purposes of legality checks and removal of ignored Ghost code.
9525 Mark_Pragma_As_Ghost (N, E);
9527 -- Enforce RM 11.5(7) which requires that for a pragma that
9528 -- appears within a package spec, the named entity must be
9529 -- within the package spec. We allow the package name itself
9530 -- to be mentioned since that makes sense, although it is not
9531 -- strictly allowed by 11.5(7).
9533 if In_Package_Spec
9534 and then E /= Current_Scope
9535 and then Scope (E) /= Current_Scope
9536 then
9537 Error_Pragma_Arg
9538 ("entity in pragma% is not in package spec (RM 11.5(7))",
9539 Arg2);
9540 end if;
9542 -- Loop through homonyms. As noted below, in the case of a package
9543 -- spec, only homonyms within the package spec are considered.
9545 loop
9546 Suppress_Unsuppress_Echeck (E, C);
9548 if Is_Generic_Instance (E)
9549 and then Is_Subprogram (E)
9550 and then Present (Alias (E))
9551 then
9552 Suppress_Unsuppress_Echeck (Alias (E), C);
9553 end if;
9555 -- Move to next homonym if not aspect spec case
9557 exit when From_Aspect_Specification (N);
9558 E := Homonym (E);
9559 exit when No (E);
9561 -- If we are within a package specification, the pragma only
9562 -- applies to homonyms in the same scope.
9564 exit when In_Package_Spec
9565 and then Scope (E) /= Current_Scope;
9566 end loop;
9567 end if;
9568 end Process_Suppress_Unsuppress;
9570 -------------------------------
9571 -- Record_Independence_Check --
9572 -------------------------------
9574 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is
9575 begin
9576 -- For GCC back ends the validation is done a priori
9578 if not AAMP_On_Target then
9579 return;
9580 end if;
9582 Independence_Checks.Append ((N, E));
9583 end Record_Independence_Check;
9585 ------------------
9586 -- Set_Exported --
9587 ------------------
9589 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
9590 begin
9591 if Is_Imported (E) then
9592 Error_Pragma_Arg
9593 ("cannot export entity& that was previously imported", Arg);
9595 elsif Present (Address_Clause (E))
9596 and then not Relaxed_RM_Semantics
9597 then
9598 Error_Pragma_Arg
9599 ("cannot export entity& that has an address clause", Arg);
9600 end if;
9602 Set_Is_Exported (E);
9604 -- Generate a reference for entity explicitly, because the
9605 -- identifier may be overloaded and name resolution will not
9606 -- generate one.
9608 Generate_Reference (E, Arg);
9610 -- Deal with exporting non-library level entity
9612 if not Is_Library_Level_Entity (E) then
9614 -- Not allowed at all for subprograms
9616 if Is_Subprogram (E) then
9617 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
9619 -- Otherwise set public and statically allocated
9621 else
9622 Set_Is_Public (E);
9623 Set_Is_Statically_Allocated (E);
9625 -- Warn if the corresponding W flag is set
9627 if Warn_On_Export_Import
9629 -- Only do this for something that was in the source. Not
9630 -- clear if this can be False now (there used for sure to be
9631 -- cases on some systems where it was False), but anyway the
9632 -- test is harmless if not needed, so it is retained.
9634 and then Comes_From_Source (Arg)
9635 then
9636 Error_Msg_NE
9637 ("?x?& has been made static as a result of Export",
9638 Arg, E);
9639 Error_Msg_N
9640 ("\?x?this usage is non-standard and non-portable",
9641 Arg);
9642 end if;
9643 end if;
9644 end if;
9646 if Warn_On_Export_Import and then Is_Type (E) then
9647 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
9648 end if;
9650 if Warn_On_Export_Import and Inside_A_Generic then
9651 Error_Msg_NE
9652 ("all instances of& will have the same external name?x?",
9653 Arg, E);
9654 end if;
9655 end Set_Exported;
9657 ----------------------------------------------
9658 -- Set_Extended_Import_Export_External_Name --
9659 ----------------------------------------------
9661 procedure Set_Extended_Import_Export_External_Name
9662 (Internal_Ent : Entity_Id;
9663 Arg_External : Node_Id)
9665 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
9666 New_Name : Node_Id;
9668 begin
9669 if No (Arg_External) then
9670 return;
9671 end if;
9673 Check_Arg_Is_External_Name (Arg_External);
9675 if Nkind (Arg_External) = N_String_Literal then
9676 if String_Length (Strval (Arg_External)) = 0 then
9677 return;
9678 else
9679 New_Name := Adjust_External_Name_Case (Arg_External);
9680 end if;
9682 elsif Nkind (Arg_External) = N_Identifier then
9683 New_Name := Get_Default_External_Name (Arg_External);
9685 -- Check_Arg_Is_External_Name should let through only identifiers and
9686 -- string literals or static string expressions (which are folded to
9687 -- string literals).
9689 else
9690 raise Program_Error;
9691 end if;
9693 -- If we already have an external name set (by a prior normal Import
9694 -- or Export pragma), then the external names must match
9696 if Present (Interface_Name (Internal_Ent)) then
9698 -- Ignore mismatching names in CodePeer mode, to support some
9699 -- old compilers which would export the same procedure under
9700 -- different names, e.g:
9701 -- procedure P;
9702 -- pragma Export_Procedure (P, "a");
9703 -- pragma Export_Procedure (P, "b");
9705 if CodePeer_Mode then
9706 return;
9707 end if;
9709 Check_Matching_Internal_Names : declare
9710 S1 : constant String_Id := Strval (Old_Name);
9711 S2 : constant String_Id := Strval (New_Name);
9713 procedure Mismatch;
9714 pragma No_Return (Mismatch);
9715 -- Called if names do not match
9717 --------------
9718 -- Mismatch --
9719 --------------
9721 procedure Mismatch is
9722 begin
9723 Error_Msg_Sloc := Sloc (Old_Name);
9724 Error_Pragma_Arg
9725 ("external name does not match that given #",
9726 Arg_External);
9727 end Mismatch;
9729 -- Start of processing for Check_Matching_Internal_Names
9731 begin
9732 if String_Length (S1) /= String_Length (S2) then
9733 Mismatch;
9735 else
9736 for J in 1 .. String_Length (S1) loop
9737 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
9738 Mismatch;
9739 end if;
9740 end loop;
9741 end if;
9742 end Check_Matching_Internal_Names;
9744 -- Otherwise set the given name
9746 else
9747 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
9748 Check_Duplicated_Export_Name (New_Name);
9749 end if;
9750 end Set_Extended_Import_Export_External_Name;
9752 ------------------
9753 -- Set_Imported --
9754 ------------------
9756 procedure Set_Imported (E : Entity_Id) is
9757 begin
9758 -- Error message if already imported or exported
9760 if Is_Exported (E) or else Is_Imported (E) then
9762 -- Error if being set Exported twice
9764 if Is_Exported (E) then
9765 Error_Msg_NE ("entity& was previously exported", N, E);
9767 -- Ignore error in CodePeer mode where we treat all imported
9768 -- subprograms as unknown.
9770 elsif CodePeer_Mode then
9771 goto OK;
9773 -- OK if Import/Interface case
9775 elsif Import_Interface_Present (N) then
9776 goto OK;
9778 -- Error if being set Imported twice
9780 else
9781 Error_Msg_NE ("entity& was previously imported", N, E);
9782 end if;
9784 Error_Msg_Name_1 := Pname;
9785 Error_Msg_N
9786 ("\(pragma% applies to all previous entities)", N);
9788 Error_Msg_Sloc := Sloc (E);
9789 Error_Msg_NE ("\import not allowed for& declared#", N, E);
9791 -- Here if not previously imported or exported, OK to import
9793 else
9794 Set_Is_Imported (E);
9796 -- For subprogram, set Import_Pragma field
9798 if Is_Subprogram (E) then
9799 Set_Import_Pragma (E, N);
9800 end if;
9802 -- If the entity is an object that is not at the library level,
9803 -- then it is statically allocated. We do not worry about objects
9804 -- with address clauses in this context since they are not really
9805 -- imported in the linker sense.
9807 if Is_Object (E)
9808 and then not Is_Library_Level_Entity (E)
9809 and then No (Address_Clause (E))
9810 then
9811 Set_Is_Statically_Allocated (E);
9812 end if;
9813 end if;
9815 <<OK>> null;
9816 end Set_Imported;
9818 -------------------------
9819 -- Set_Mechanism_Value --
9820 -------------------------
9822 -- Note: the mechanism name has not been analyzed (and cannot indeed be
9823 -- analyzed, since it is semantic nonsense), so we get it in the exact
9824 -- form created by the parser.
9826 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
9827 procedure Bad_Mechanism;
9828 pragma No_Return (Bad_Mechanism);
9829 -- Signal bad mechanism name
9831 -------------------------
9832 -- Bad_Mechanism_Value --
9833 -------------------------
9835 procedure Bad_Mechanism is
9836 begin
9837 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
9838 end Bad_Mechanism;
9840 -- Start of processing for Set_Mechanism_Value
9842 begin
9843 if Mechanism (Ent) /= Default_Mechanism then
9844 Error_Msg_NE
9845 ("mechanism for & has already been set", Mech_Name, Ent);
9846 end if;
9848 -- MECHANISM_NAME ::= value | reference
9850 if Nkind (Mech_Name) = N_Identifier then
9851 if Chars (Mech_Name) = Name_Value then
9852 Set_Mechanism (Ent, By_Copy);
9853 return;
9855 elsif Chars (Mech_Name) = Name_Reference then
9856 Set_Mechanism (Ent, By_Reference);
9857 return;
9859 elsif Chars (Mech_Name) = Name_Copy then
9860 Error_Pragma_Arg
9861 ("bad mechanism name, Value assumed", Mech_Name);
9863 else
9864 Bad_Mechanism;
9865 end if;
9867 else
9868 Bad_Mechanism;
9869 end if;
9870 end Set_Mechanism_Value;
9872 --------------------------
9873 -- Set_Rational_Profile --
9874 --------------------------
9876 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
9877 -- extension to the semantics of renaming declarations.
9879 procedure Set_Rational_Profile is
9880 begin
9881 Implicit_Packing := True;
9882 Overriding_Renamings := True;
9883 Use_VADS_Size := True;
9884 end Set_Rational_Profile;
9886 ---------------------------
9887 -- Set_Ravenscar_Profile --
9888 ---------------------------
9890 -- The tasks to be done here are
9892 -- Set required policies
9894 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9895 -- pragma Locking_Policy (Ceiling_Locking)
9897 -- Set Detect_Blocking mode
9899 -- Set required restrictions (see System.Rident for detailed list)
9901 -- Set the No_Dependence rules
9902 -- No_Dependence => Ada.Asynchronous_Task_Control
9903 -- No_Dependence => Ada.Calendar
9904 -- No_Dependence => Ada.Execution_Time.Group_Budget
9905 -- No_Dependence => Ada.Execution_Time.Timers
9906 -- No_Dependence => Ada.Task_Attributes
9907 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9909 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id) is
9910 procedure Set_Error_Msg_To_Profile_Name;
9911 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
9912 -- profile.
9914 -----------------------------------
9915 -- Set_Error_Msg_To_Profile_Name --
9916 -----------------------------------
9918 procedure Set_Error_Msg_To_Profile_Name is
9919 Prof_Nam : constant Node_Id :=
9920 Get_Pragma_Arg
9921 (First (Pragma_Argument_Associations (N)));
9923 begin
9924 Get_Name_String (Chars (Prof_Nam));
9925 Adjust_Name_Case (Global_Name_Buffer, Sloc (Prof_Nam));
9926 Error_Msg_Strlen := Name_Len;
9927 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
9928 end Set_Error_Msg_To_Profile_Name;
9930 -- Local variables
9932 Nod : Node_Id;
9933 Pref : Node_Id;
9934 Pref_Id : Node_Id;
9935 Sel_Id : Node_Id;
9937 -- Start of processing for Set_Ravenscar_Profile
9939 begin
9940 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9942 if Task_Dispatching_Policy /= ' '
9943 and then Task_Dispatching_Policy /= 'F'
9944 then
9945 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9946 Set_Error_Msg_To_Profile_Name;
9947 Error_Pragma ("Profile (~) incompatible with policy#");
9949 -- Set the FIFO_Within_Priorities policy, but always preserve
9950 -- System_Location since we like the error message with the run time
9951 -- name.
9953 else
9954 Task_Dispatching_Policy := 'F';
9956 if Task_Dispatching_Policy_Sloc /= System_Location then
9957 Task_Dispatching_Policy_Sloc := Loc;
9958 end if;
9959 end if;
9961 -- pragma Locking_Policy (Ceiling_Locking)
9963 if Locking_Policy /= ' '
9964 and then Locking_Policy /= 'C'
9965 then
9966 Error_Msg_Sloc := Locking_Policy_Sloc;
9967 Set_Error_Msg_To_Profile_Name;
9968 Error_Pragma ("Profile (~) incompatible with policy#");
9970 -- Set the Ceiling_Locking policy, but preserve System_Location since
9971 -- we like the error message with the run time name.
9973 else
9974 Locking_Policy := 'C';
9976 if Locking_Policy_Sloc /= System_Location then
9977 Locking_Policy_Sloc := Loc;
9978 end if;
9979 end if;
9981 -- pragma Detect_Blocking
9983 Detect_Blocking := True;
9985 -- Set the corresponding restrictions
9987 Set_Profile_Restrictions
9988 (Profile, N, Warn => Treat_Restrictions_As_Warnings);
9990 -- Set the No_Dependence restrictions
9992 -- The following No_Dependence restrictions:
9993 -- No_Dependence => Ada.Asynchronous_Task_Control
9994 -- No_Dependence => Ada.Calendar
9995 -- No_Dependence => Ada.Task_Attributes
9996 -- are already set by previous call to Set_Profile_Restrictions.
9998 -- Set the following restrictions which were added to Ada 2005:
9999 -- No_Dependence => Ada.Execution_Time.Group_Budget
10000 -- No_Dependence => Ada.Execution_Time.Timers
10002 -- ??? The use of Name_Buffer here is suspicious. The names should
10003 -- be registered in snames.ads-tmpl and used to build the qualified
10004 -- names of units.
10006 if Ada_Version >= Ada_2005 then
10007 Name_Buffer (1 .. 3) := "ada";
10008 Name_Len := 3;
10010 Pref_Id := Make_Identifier (Loc, Name_Find);
10012 Name_Buffer (1 .. 14) := "execution_time";
10013 Name_Len := 14;
10015 Sel_Id := Make_Identifier (Loc, Name_Find);
10017 Pref :=
10018 Make_Selected_Component
10019 (Sloc => Loc,
10020 Prefix => Pref_Id,
10021 Selector_Name => Sel_Id);
10023 Name_Buffer (1 .. 13) := "group_budgets";
10024 Name_Len := 13;
10026 Sel_Id := Make_Identifier (Loc, Name_Find);
10028 Nod :=
10029 Make_Selected_Component
10030 (Sloc => Loc,
10031 Prefix => Pref,
10032 Selector_Name => Sel_Id);
10034 Set_Restriction_No_Dependence
10035 (Unit => Nod,
10036 Warn => Treat_Restrictions_As_Warnings,
10037 Profile => Ravenscar);
10039 Name_Buffer (1 .. 6) := "timers";
10040 Name_Len := 6;
10042 Sel_Id := Make_Identifier (Loc, Name_Find);
10044 Nod :=
10045 Make_Selected_Component
10046 (Sloc => Loc,
10047 Prefix => Pref,
10048 Selector_Name => Sel_Id);
10050 Set_Restriction_No_Dependence
10051 (Unit => Nod,
10052 Warn => Treat_Restrictions_As_Warnings,
10053 Profile => Ravenscar);
10054 end if;
10056 -- Set the following restriction which was added to Ada 2012 (see
10057 -- AI-0171):
10058 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
10060 if Ada_Version >= Ada_2012 then
10061 Name_Buffer (1 .. 6) := "system";
10062 Name_Len := 6;
10064 Pref_Id := Make_Identifier (Loc, Name_Find);
10066 Name_Buffer (1 .. 15) := "multiprocessors";
10067 Name_Len := 15;
10069 Sel_Id := Make_Identifier (Loc, Name_Find);
10071 Pref :=
10072 Make_Selected_Component
10073 (Sloc => Loc,
10074 Prefix => Pref_Id,
10075 Selector_Name => Sel_Id);
10077 Name_Buffer (1 .. 19) := "dispatching_domains";
10078 Name_Len := 19;
10080 Sel_Id := Make_Identifier (Loc, Name_Find);
10082 Nod :=
10083 Make_Selected_Component
10084 (Sloc => Loc,
10085 Prefix => Pref,
10086 Selector_Name => Sel_Id);
10088 Set_Restriction_No_Dependence
10089 (Unit => Nod,
10090 Warn => Treat_Restrictions_As_Warnings,
10091 Profile => Ravenscar);
10092 end if;
10093 end Set_Ravenscar_Profile;
10095 -- Start of processing for Analyze_Pragma
10097 begin
10098 -- The following code is a defense against recursion. Not clear that
10099 -- this can happen legitimately, but perhaps some error situations can
10100 -- cause it, and we did see this recursion during testing.
10102 if Analyzed (N) then
10103 return;
10104 else
10105 Set_Analyzed (N);
10106 end if;
10108 Check_Restriction_No_Use_Of_Pragma (N);
10110 -- Deal with unrecognized pragma
10112 Pname := Pragma_Name (N);
10114 if not Is_Pragma_Name (Pname) then
10115 if Warn_On_Unrecognized_Pragma then
10116 Error_Msg_Name_1 := Pname;
10117 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
10119 for PN in First_Pragma_Name .. Last_Pragma_Name loop
10120 if Is_Bad_Spelling_Of (Pname, PN) then
10121 Error_Msg_Name_1 := PN;
10122 Error_Msg_N -- CODEFIX
10123 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
10124 exit;
10125 end if;
10126 end loop;
10127 end if;
10129 return;
10130 end if;
10132 -- Ignore pragma if Ignore_Pragma applies
10134 if Get_Name_Table_Boolean3 (Pname) then
10135 return;
10136 end if;
10138 -- Here to start processing for recognized pragma
10140 Prag_Id := Get_Pragma_Id (Pname);
10141 Pname := Original_Aspect_Pragma_Name (N);
10143 -- Capture setting of Opt.Uneval_Old
10145 case Opt.Uneval_Old is
10146 when 'A' =>
10147 Set_Uneval_Old_Accept (N);
10148 when 'E' =>
10149 null;
10150 when 'W' =>
10151 Set_Uneval_Old_Warn (N);
10152 when others =>
10153 raise Program_Error;
10154 end case;
10156 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
10157 -- is already set, indicating that we have already checked the policy
10158 -- at the right point. This happens for example in the case of a pragma
10159 -- that is derived from an Aspect.
10161 if Is_Ignored (N) or else Is_Checked (N) then
10162 null;
10164 -- For a pragma that is a rewriting of another pragma, copy the
10165 -- Is_Checked/Is_Ignored status from the rewritten pragma.
10167 elsif Is_Rewrite_Substitution (N)
10168 and then Nkind (Original_Node (N)) = N_Pragma
10169 and then Original_Node (N) /= N
10170 then
10171 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
10172 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
10174 -- Otherwise query the applicable policy at this point
10176 else
10177 Check_Applicable_Policy (N);
10179 -- If pragma is disabled, rewrite as NULL and skip analysis
10181 if Is_Disabled (N) then
10182 Rewrite (N, Make_Null_Statement (Loc));
10183 Analyze (N);
10184 raise Pragma_Exit;
10185 end if;
10186 end if;
10188 -- Preset arguments
10190 Arg_Count := 0;
10191 Arg1 := Empty;
10192 Arg2 := Empty;
10193 Arg3 := Empty;
10194 Arg4 := Empty;
10196 if Present (Pragma_Argument_Associations (N)) then
10197 Arg_Count := List_Length (Pragma_Argument_Associations (N));
10198 Arg1 := First (Pragma_Argument_Associations (N));
10200 if Present (Arg1) then
10201 Arg2 := Next (Arg1);
10203 if Present (Arg2) then
10204 Arg3 := Next (Arg2);
10206 if Present (Arg3) then
10207 Arg4 := Next (Arg3);
10208 end if;
10209 end if;
10210 end if;
10211 end if;
10213 -- An enumeration type defines the pragmas that are supported by the
10214 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
10215 -- into the corresponding enumeration value for the following case.
10217 case Prag_Id is
10219 -----------------
10220 -- Abort_Defer --
10221 -----------------
10223 -- pragma Abort_Defer;
10225 when Pragma_Abort_Defer =>
10226 GNAT_Pragma;
10227 Check_Arg_Count (0);
10229 -- The only required semantic processing is to check the
10230 -- placement. This pragma must appear at the start of the
10231 -- statement sequence of a handled sequence of statements.
10233 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
10234 or else N /= First (Statements (Parent (N)))
10235 then
10236 Pragma_Misplaced;
10237 end if;
10239 --------------------
10240 -- Abstract_State --
10241 --------------------
10243 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
10245 -- ABSTRACT_STATE_LIST ::=
10246 -- null
10247 -- | STATE_NAME_WITH_OPTIONS
10248 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
10250 -- STATE_NAME_WITH_OPTIONS ::=
10251 -- STATE_NAME
10252 -- | (STATE_NAME with OPTION_LIST)
10254 -- OPTION_LIST ::= OPTION {, OPTION}
10256 -- OPTION ::=
10257 -- SIMPLE_OPTION
10258 -- | NAME_VALUE_OPTION
10260 -- SIMPLE_OPTION ::= Ghost | Synchronous
10262 -- NAME_VALUE_OPTION ::=
10263 -- Part_Of => ABSTRACT_STATE
10264 -- | External [=> EXTERNAL_PROPERTY_LIST]
10266 -- EXTERNAL_PROPERTY_LIST ::=
10267 -- EXTERNAL_PROPERTY
10268 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
10270 -- EXTERNAL_PROPERTY ::=
10271 -- Async_Readers [=> boolean_EXPRESSION]
10272 -- | Async_Writers [=> boolean_EXPRESSION]
10273 -- | Effective_Reads [=> boolean_EXPRESSION]
10274 -- | Effective_Writes [=> boolean_EXPRESSION]
10275 -- others => boolean_EXPRESSION
10277 -- STATE_NAME ::= defining_identifier
10279 -- ABSTRACT_STATE ::= name
10281 -- Characteristics:
10283 -- * Analysis - The annotation is fully analyzed immediately upon
10284 -- elaboration as it cannot forward reference entities.
10286 -- * Expansion - None.
10288 -- * Template - The annotation utilizes the generic template of the
10289 -- related package declaration.
10291 -- * Globals - The annotation cannot reference global entities.
10293 -- * Instance - The annotation is instantiated automatically when
10294 -- the related generic package is instantiated.
10296 when Pragma_Abstract_State => Abstract_State : declare
10297 Missing_Parentheses : Boolean := False;
10298 -- Flag set when a state declaration with options is not properly
10299 -- parenthesized.
10301 -- Flags used to verify the consistency of states
10303 Non_Null_Seen : Boolean := False;
10304 Null_Seen : Boolean := False;
10306 procedure Analyze_Abstract_State
10307 (State : Node_Id;
10308 Pack_Id : Entity_Id);
10309 -- Verify the legality of a single state declaration. Create and
10310 -- decorate a state abstraction entity and introduce it into the
10311 -- visibility chain. Pack_Id denotes the entity or the related
10312 -- package where pragma Abstract_State appears.
10314 procedure Malformed_State_Error (State : Node_Id);
10315 -- Emit an error concerning the illegal declaration of abstract
10316 -- state State. This routine diagnoses syntax errors that lead to
10317 -- a different parse tree. The error is issued regardless of the
10318 -- SPARK mode in effect.
10320 ----------------------------
10321 -- Analyze_Abstract_State --
10322 ----------------------------
10324 procedure Analyze_Abstract_State
10325 (State : Node_Id;
10326 Pack_Id : Entity_Id)
10328 -- Flags used to verify the consistency of options
10330 AR_Seen : Boolean := False;
10331 AW_Seen : Boolean := False;
10332 ER_Seen : Boolean := False;
10333 EW_Seen : Boolean := False;
10334 External_Seen : Boolean := False;
10335 Ghost_Seen : Boolean := False;
10336 Others_Seen : Boolean := False;
10337 Part_Of_Seen : Boolean := False;
10338 Synchronous_Seen : Boolean := False;
10340 -- Flags used to store the static value of all external states'
10341 -- expressions.
10343 AR_Val : Boolean := False;
10344 AW_Val : Boolean := False;
10345 ER_Val : Boolean := False;
10346 EW_Val : Boolean := False;
10348 State_Id : Entity_Id := Empty;
10349 -- The entity to be generated for the current state declaration
10351 procedure Analyze_External_Option (Opt : Node_Id);
10352 -- Verify the legality of option External
10354 procedure Analyze_External_Property
10355 (Prop : Node_Id;
10356 Expr : Node_Id := Empty);
10357 -- Verify the legailty of a single external property. Prop
10358 -- denotes the external property. Expr is the expression used
10359 -- to set the property.
10361 procedure Analyze_Part_Of_Option (Opt : Node_Id);
10362 -- Verify the legality of option Part_Of
10364 procedure Check_Duplicate_Option
10365 (Opt : Node_Id;
10366 Status : in out Boolean);
10367 -- Flag Status denotes whether a particular option has been
10368 -- seen while processing a state. This routine verifies that
10369 -- Opt is not a duplicate option and sets the flag Status
10370 -- (SPARK RM 7.1.4(1)).
10372 procedure Check_Duplicate_Property
10373 (Prop : Node_Id;
10374 Status : in out Boolean);
10375 -- Flag Status denotes whether a particular property has been
10376 -- seen while processing option External. This routine verifies
10377 -- that Prop is not a duplicate property and sets flag Status.
10378 -- Opt is not a duplicate property and sets the flag Status.
10379 -- (SPARK RM 7.1.4(2))
10381 procedure Check_Ghost_Synchronous;
10382 -- Ensure that the abstract state is not subject to both Ghost
10383 -- and Synchronous simple options. Emit an error if this is the
10384 -- case.
10386 procedure Create_Abstract_State
10387 (Nam : Name_Id;
10388 Decl : Node_Id;
10389 Loc : Source_Ptr;
10390 Is_Null : Boolean);
10391 -- Generate an abstract state entity with name Nam and enter it
10392 -- into visibility. Decl is the "declaration" of the state as
10393 -- it appears in pragma Abstract_State. Loc is the location of
10394 -- the related state "declaration". Flag Is_Null should be set
10395 -- when the associated Abstract_State pragma defines a null
10396 -- state.
10398 -----------------------------
10399 -- Analyze_External_Option --
10400 -----------------------------
10402 procedure Analyze_External_Option (Opt : Node_Id) is
10403 Errors : constant Nat := Serious_Errors_Detected;
10404 Prop : Node_Id;
10405 Props : Node_Id := Empty;
10407 begin
10408 if Nkind (Opt) = N_Component_Association then
10409 Props := Expression (Opt);
10410 end if;
10412 -- External state with properties
10414 if Present (Props) then
10416 -- Multiple properties appear as an aggregate
10418 if Nkind (Props) = N_Aggregate then
10420 -- Simple property form
10422 Prop := First (Expressions (Props));
10423 while Present (Prop) loop
10424 Analyze_External_Property (Prop);
10425 Next (Prop);
10426 end loop;
10428 -- Property with expression form
10430 Prop := First (Component_Associations (Props));
10431 while Present (Prop) loop
10432 Analyze_External_Property
10433 (Prop => First (Choices (Prop)),
10434 Expr => Expression (Prop));
10436 Next (Prop);
10437 end loop;
10439 -- Single property
10441 else
10442 Analyze_External_Property (Props);
10443 end if;
10445 -- An external state defined without any properties defaults
10446 -- all properties to True.
10448 else
10449 AR_Val := True;
10450 AW_Val := True;
10451 ER_Val := True;
10452 EW_Val := True;
10453 end if;
10455 -- Once all external properties have been processed, verify
10456 -- their mutual interaction. Do not perform the check when
10457 -- at least one of the properties is illegal as this will
10458 -- produce a bogus error.
10460 if Errors = Serious_Errors_Detected then
10461 Check_External_Properties
10462 (State, AR_Val, AW_Val, ER_Val, EW_Val);
10463 end if;
10464 end Analyze_External_Option;
10466 -------------------------------
10467 -- Analyze_External_Property --
10468 -------------------------------
10470 procedure Analyze_External_Property
10471 (Prop : Node_Id;
10472 Expr : Node_Id := Empty)
10474 Expr_Val : Boolean;
10476 begin
10477 -- Check the placement of "others" (if available)
10479 if Nkind (Prop) = N_Others_Choice then
10480 if Others_Seen then
10481 SPARK_Msg_N
10482 ("only one others choice allowed in option External",
10483 Prop);
10484 else
10485 Others_Seen := True;
10486 end if;
10488 elsif Others_Seen then
10489 SPARK_Msg_N
10490 ("others must be the last property in option External",
10491 Prop);
10493 -- The only remaining legal options are the four predefined
10494 -- external properties.
10496 elsif Nkind (Prop) = N_Identifier
10497 and then Nam_In (Chars (Prop), Name_Async_Readers,
10498 Name_Async_Writers,
10499 Name_Effective_Reads,
10500 Name_Effective_Writes)
10501 then
10502 null;
10504 -- Otherwise the construct is not a valid property
10506 else
10507 SPARK_Msg_N ("invalid external state property", Prop);
10508 return;
10509 end if;
10511 -- Ensure that the expression of the external state property
10512 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
10514 if Present (Expr) then
10515 Analyze_And_Resolve (Expr, Standard_Boolean);
10517 if Is_OK_Static_Expression (Expr) then
10518 Expr_Val := Is_True (Expr_Value (Expr));
10519 else
10520 SPARK_Msg_N
10521 ("expression of external state property must be "
10522 & "static", Expr);
10523 end if;
10525 -- The lack of expression defaults the property to True
10527 else
10528 Expr_Val := True;
10529 end if;
10531 -- Named properties
10533 if Nkind (Prop) = N_Identifier then
10534 if Chars (Prop) = Name_Async_Readers then
10535 Check_Duplicate_Property (Prop, AR_Seen);
10536 AR_Val := Expr_Val;
10538 elsif Chars (Prop) = Name_Async_Writers then
10539 Check_Duplicate_Property (Prop, AW_Seen);
10540 AW_Val := Expr_Val;
10542 elsif Chars (Prop) = Name_Effective_Reads then
10543 Check_Duplicate_Property (Prop, ER_Seen);
10544 ER_Val := Expr_Val;
10546 else
10547 Check_Duplicate_Property (Prop, EW_Seen);
10548 EW_Val := Expr_Val;
10549 end if;
10551 -- The handling of property "others" must take into account
10552 -- all other named properties that have been encountered so
10553 -- far. Only those that have not been seen are affected by
10554 -- "others".
10556 else
10557 if not AR_Seen then
10558 AR_Val := Expr_Val;
10559 end if;
10561 if not AW_Seen then
10562 AW_Val := Expr_Val;
10563 end if;
10565 if not ER_Seen then
10566 ER_Val := Expr_Val;
10567 end if;
10569 if not EW_Seen then
10570 EW_Val := Expr_Val;
10571 end if;
10572 end if;
10573 end Analyze_External_Property;
10575 ----------------------------
10576 -- Analyze_Part_Of_Option --
10577 ----------------------------
10579 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
10580 Encap : constant Node_Id := Expression (Opt);
10581 Constits : Elist_Id;
10582 Encap_Id : Entity_Id;
10583 Legal : Boolean;
10585 begin
10586 Check_Duplicate_Option (Opt, Part_Of_Seen);
10588 Analyze_Part_Of
10589 (Indic => First (Choices (Opt)),
10590 Item_Id => State_Id,
10591 Encap => Encap,
10592 Encap_Id => Encap_Id,
10593 Legal => Legal);
10595 -- The Part_Of indicator transforms the abstract state into
10596 -- a constituent of the encapsulating state or single
10597 -- concurrent type.
10599 if Legal then
10600 pragma Assert (Present (Encap_Id));
10601 Constits := Part_Of_Constituents (Encap_Id);
10603 if No (Constits) then
10604 Constits := New_Elmt_List;
10605 Set_Part_Of_Constituents (Encap_Id, Constits);
10606 end if;
10608 Append_Elmt (State_Id, Constits);
10609 Set_Encapsulating_State (State_Id, Encap_Id);
10610 end if;
10611 end Analyze_Part_Of_Option;
10613 ----------------------------
10614 -- Check_Duplicate_Option --
10615 ----------------------------
10617 procedure Check_Duplicate_Option
10618 (Opt : Node_Id;
10619 Status : in out Boolean)
10621 begin
10622 if Status then
10623 SPARK_Msg_N ("duplicate state option", Opt);
10624 end if;
10626 Status := True;
10627 end Check_Duplicate_Option;
10629 ------------------------------
10630 -- Check_Duplicate_Property --
10631 ------------------------------
10633 procedure Check_Duplicate_Property
10634 (Prop : Node_Id;
10635 Status : in out Boolean)
10637 begin
10638 if Status then
10639 SPARK_Msg_N ("duplicate external property", Prop);
10640 end if;
10642 Status := True;
10643 end Check_Duplicate_Property;
10645 -----------------------------
10646 -- Check_Ghost_Synchronous --
10647 -----------------------------
10649 procedure Check_Ghost_Synchronous is
10650 begin
10651 -- A synchronized abstract state cannot be Ghost and vice
10652 -- versa (SPARK RM 6.9(19)).
10654 if Ghost_Seen and Synchronous_Seen then
10655 SPARK_Msg_N ("synchronized state cannot be ghost", State);
10656 end if;
10657 end Check_Ghost_Synchronous;
10659 ---------------------------
10660 -- Create_Abstract_State --
10661 ---------------------------
10663 procedure Create_Abstract_State
10664 (Nam : Name_Id;
10665 Decl : Node_Id;
10666 Loc : Source_Ptr;
10667 Is_Null : Boolean)
10669 begin
10670 -- The abstract state may be semi-declared when the related
10671 -- package was withed through a limited with clause. In that
10672 -- case reuse the entity to fully declare the state.
10674 if Present (Decl) and then Present (Entity (Decl)) then
10675 State_Id := Entity (Decl);
10677 -- Otherwise the elaboration of pragma Abstract_State
10678 -- declares the state.
10680 else
10681 State_Id := Make_Defining_Identifier (Loc, Nam);
10683 if Present (Decl) then
10684 Set_Entity (Decl, State_Id);
10685 end if;
10686 end if;
10688 -- Null states never come from source
10690 Set_Comes_From_Source (State_Id, not Is_Null);
10691 Set_Parent (State_Id, State);
10692 Set_Ekind (State_Id, E_Abstract_State);
10693 Set_Etype (State_Id, Standard_Void_Type);
10694 Set_Encapsulating_State (State_Id, Empty);
10696 -- An abstract state declared within a Ghost region becomes
10697 -- Ghost (SPARK RM 6.9(2)).
10699 if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then
10700 Set_Is_Ghost_Entity (State_Id);
10701 end if;
10703 -- Establish a link between the state declaration and the
10704 -- abstract state entity. Note that a null state remains as
10705 -- N_Null and does not carry any linkages.
10707 if not Is_Null then
10708 if Present (Decl) then
10709 Set_Entity (Decl, State_Id);
10710 Set_Etype (Decl, Standard_Void_Type);
10711 end if;
10713 -- Every non-null state must be defined, nameable and
10714 -- resolvable.
10716 Push_Scope (Pack_Id);
10717 Generate_Definition (State_Id);
10718 Enter_Name (State_Id);
10719 Pop_Scope;
10720 end if;
10721 end Create_Abstract_State;
10723 -- Local variables
10725 Opt : Node_Id;
10726 Opt_Nam : Node_Id;
10728 -- Start of processing for Analyze_Abstract_State
10730 begin
10731 -- A package with a null abstract state is not allowed to
10732 -- declare additional states.
10734 if Null_Seen then
10735 SPARK_Msg_NE
10736 ("package & has null abstract state", State, Pack_Id);
10738 -- Null states appear as internally generated entities
10740 elsif Nkind (State) = N_Null then
10741 Create_Abstract_State
10742 (Nam => New_Internal_Name ('S'),
10743 Decl => Empty,
10744 Loc => Sloc (State),
10745 Is_Null => True);
10746 Null_Seen := True;
10748 -- Catch a case where a null state appears in a list of
10749 -- non-null states.
10751 if Non_Null_Seen then
10752 SPARK_Msg_NE
10753 ("package & has non-null abstract state",
10754 State, Pack_Id);
10755 end if;
10757 -- Simple state declaration
10759 elsif Nkind (State) = N_Identifier then
10760 Create_Abstract_State
10761 (Nam => Chars (State),
10762 Decl => State,
10763 Loc => Sloc (State),
10764 Is_Null => False);
10765 Non_Null_Seen := True;
10767 -- State declaration with various options. This construct
10768 -- appears as an extension aggregate in the tree.
10770 elsif Nkind (State) = N_Extension_Aggregate then
10771 if Nkind (Ancestor_Part (State)) = N_Identifier then
10772 Create_Abstract_State
10773 (Nam => Chars (Ancestor_Part (State)),
10774 Decl => Ancestor_Part (State),
10775 Loc => Sloc (Ancestor_Part (State)),
10776 Is_Null => False);
10777 Non_Null_Seen := True;
10778 else
10779 SPARK_Msg_N
10780 ("state name must be an identifier",
10781 Ancestor_Part (State));
10782 end if;
10784 -- Options External, Ghost and Synchronous appear as
10785 -- expressions.
10787 Opt := First (Expressions (State));
10788 while Present (Opt) loop
10789 if Nkind (Opt) = N_Identifier then
10791 -- External
10793 if Chars (Opt) = Name_External then
10794 Check_Duplicate_Option (Opt, External_Seen);
10795 Analyze_External_Option (Opt);
10797 -- Ghost
10799 elsif Chars (Opt) = Name_Ghost then
10800 Check_Duplicate_Option (Opt, Ghost_Seen);
10801 Check_Ghost_Synchronous;
10803 if Present (State_Id) then
10804 Set_Is_Ghost_Entity (State_Id);
10805 end if;
10807 -- Synchronous
10809 elsif Chars (Opt) = Name_Synchronous then
10810 Check_Duplicate_Option (Opt, Synchronous_Seen);
10811 Check_Ghost_Synchronous;
10813 -- Option Part_Of without an encapsulating state is
10814 -- illegal (SPARK RM 7.1.4(9)).
10816 elsif Chars (Opt) = Name_Part_Of then
10817 SPARK_Msg_N
10818 ("indicator Part_Of must denote abstract state, "
10819 & "single protected type or single task type",
10820 Opt);
10822 -- Do not emit an error message when a previous state
10823 -- declaration with options was not parenthesized as
10824 -- the option is actually another state declaration.
10826 -- with Abstract_State
10827 -- (State_1 with ..., -- missing parentheses
10828 -- (State_2 with ...),
10829 -- State_3) -- ok state declaration
10831 elsif Missing_Parentheses then
10832 null;
10834 -- Otherwise the option is not allowed. Note that it
10835 -- is not possible to distinguish between an option
10836 -- and a state declaration when a previous state with
10837 -- options not properly parentheses.
10839 -- with Abstract_State
10840 -- (State_1 with ..., -- missing parentheses
10841 -- State_2); -- could be an option
10843 else
10844 SPARK_Msg_N
10845 ("simple option not allowed in state declaration",
10846 Opt);
10847 end if;
10849 -- Catch a case where missing parentheses around a state
10850 -- declaration with options cause a subsequent state
10851 -- declaration with options to be treated as an option.
10853 -- with Abstract_State
10854 -- (State_1 with ..., -- missing parentheses
10855 -- (State_2 with ...))
10857 elsif Nkind (Opt) = N_Extension_Aggregate then
10858 Missing_Parentheses := True;
10859 SPARK_Msg_N
10860 ("state declaration must be parenthesized",
10861 Ancestor_Part (State));
10863 -- Otherwise the option is malformed
10865 else
10866 SPARK_Msg_N ("malformed option", Opt);
10867 end if;
10869 Next (Opt);
10870 end loop;
10872 -- Options External and Part_Of appear as component
10873 -- associations.
10875 Opt := First (Component_Associations (State));
10876 while Present (Opt) loop
10877 Opt_Nam := First (Choices (Opt));
10879 if Nkind (Opt_Nam) = N_Identifier then
10880 if Chars (Opt_Nam) = Name_External then
10881 Analyze_External_Option (Opt);
10883 elsif Chars (Opt_Nam) = Name_Part_Of then
10884 Analyze_Part_Of_Option (Opt);
10886 else
10887 SPARK_Msg_N ("invalid state option", Opt);
10888 end if;
10889 else
10890 SPARK_Msg_N ("invalid state option", Opt);
10891 end if;
10893 Next (Opt);
10894 end loop;
10896 -- Any other attempt to declare a state is illegal
10898 else
10899 Malformed_State_Error (State);
10900 return;
10901 end if;
10903 -- Guard against a junk state. In such cases no entity is
10904 -- generated and the subsequent checks cannot be applied.
10906 if Present (State_Id) then
10908 -- Verify whether the state does not introduce an illegal
10909 -- hidden state within a package subject to a null abstract
10910 -- state.
10912 Check_No_Hidden_State (State_Id);
10914 -- Check whether the lack of option Part_Of agrees with the
10915 -- placement of the abstract state with respect to the state
10916 -- space.
10918 if not Part_Of_Seen then
10919 Check_Missing_Part_Of (State_Id);
10920 end if;
10922 -- Associate the state with its related package
10924 if No (Abstract_States (Pack_Id)) then
10925 Set_Abstract_States (Pack_Id, New_Elmt_List);
10926 end if;
10928 Append_Elmt (State_Id, Abstract_States (Pack_Id));
10929 end if;
10930 end Analyze_Abstract_State;
10932 ---------------------------
10933 -- Malformed_State_Error --
10934 ---------------------------
10936 procedure Malformed_State_Error (State : Node_Id) is
10937 begin
10938 Error_Msg_N ("malformed abstract state declaration", State);
10940 -- An abstract state with a simple option is being declared
10941 -- with "=>" rather than the legal "with". The state appears
10942 -- as a component association.
10944 if Nkind (State) = N_Component_Association then
10945 Error_Msg_N ("\use WITH to specify simple option", State);
10946 end if;
10947 end Malformed_State_Error;
10949 -- Local variables
10951 Pack_Decl : Node_Id;
10952 Pack_Id : Entity_Id;
10953 State : Node_Id;
10954 States : Node_Id;
10956 -- Start of processing for Abstract_State
10958 begin
10959 GNAT_Pragma;
10960 Check_No_Identifiers;
10961 Check_Arg_Count (1);
10963 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
10965 -- Ensure the proper placement of the pragma. Abstract states must
10966 -- be associated with a package declaration.
10968 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
10969 N_Package_Declaration)
10970 then
10971 null;
10973 -- Otherwise the pragma is associated with an illegal construct
10975 else
10976 Pragma_Misplaced;
10977 return;
10978 end if;
10980 Pack_Id := Defining_Entity (Pack_Decl);
10982 -- Chain the pragma on the contract for completeness
10984 Add_Contract_Item (N, Pack_Id);
10986 -- The legality checks of pragmas Abstract_State, Initializes, and
10987 -- Initial_Condition are affected by the SPARK mode in effect. In
10988 -- addition, these three pragmas are subject to an inherent order:
10990 -- 1) Abstract_State
10991 -- 2) Initializes
10992 -- 3) Initial_Condition
10994 -- Analyze all these pragmas in the order outlined above
10996 Analyze_If_Present (Pragma_SPARK_Mode);
10998 -- A pragma that applies to a Ghost entity becomes Ghost for the
10999 -- purposes of legality checks and removal of ignored Ghost code.
11001 Mark_Pragma_As_Ghost (N, Pack_Id);
11002 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
11004 States := Expression (Get_Argument (N, Pack_Id));
11006 -- Multiple non-null abstract states appear as an aggregate
11008 if Nkind (States) = N_Aggregate then
11009 State := First (Expressions (States));
11010 while Present (State) loop
11011 Analyze_Abstract_State (State, Pack_Id);
11012 Next (State);
11013 end loop;
11015 -- An abstract state with a simple option is being illegaly
11016 -- declared with "=>" rather than "with". In this case the
11017 -- state declaration appears as a component association.
11019 if Present (Component_Associations (States)) then
11020 State := First (Component_Associations (States));
11021 while Present (State) loop
11022 Malformed_State_Error (State);
11023 Next (State);
11024 end loop;
11025 end if;
11027 -- Various forms of a single abstract state. Note that these may
11028 -- include malformed state declarations.
11030 else
11031 Analyze_Abstract_State (States, Pack_Id);
11032 end if;
11034 Analyze_If_Present (Pragma_Initializes);
11035 Analyze_If_Present (Pragma_Initial_Condition);
11036 end Abstract_State;
11038 ------------
11039 -- Ada_83 --
11040 ------------
11042 -- pragma Ada_83;
11044 -- Note: this pragma also has some specific processing in Par.Prag
11045 -- because we want to set the Ada version mode during parsing.
11047 when Pragma_Ada_83 =>
11048 GNAT_Pragma;
11049 Check_Arg_Count (0);
11051 -- We really should check unconditionally for proper configuration
11052 -- pragma placement, since we really don't want mixed Ada modes
11053 -- within a single unit, and the GNAT reference manual has always
11054 -- said this was a configuration pragma, but we did not check and
11055 -- are hesitant to add the check now.
11057 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
11058 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
11059 -- or Ada 2012 mode.
11061 if Ada_Version >= Ada_2005 then
11062 Check_Valid_Configuration_Pragma;
11063 end if;
11065 -- Now set Ada 83 mode
11067 Ada_Version := Ada_83;
11068 Ada_Version_Explicit := Ada_83;
11069 Ada_Version_Pragma := N;
11071 ------------
11072 -- Ada_95 --
11073 ------------
11075 -- pragma Ada_95;
11077 -- Note: this pragma also has some specific processing in Par.Prag
11078 -- because we want to set the Ada 83 version mode during parsing.
11080 when Pragma_Ada_95 =>
11081 GNAT_Pragma;
11082 Check_Arg_Count (0);
11084 -- We really should check unconditionally for proper configuration
11085 -- pragma placement, since we really don't want mixed Ada modes
11086 -- within a single unit, and the GNAT reference manual has always
11087 -- said this was a configuration pragma, but we did not check and
11088 -- are hesitant to add the check now.
11090 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
11091 -- or Ada 95, so we must check if we are in Ada 2005 mode.
11093 if Ada_Version >= Ada_2005 then
11094 Check_Valid_Configuration_Pragma;
11095 end if;
11097 -- Now set Ada 95 mode
11099 Ada_Version := Ada_95;
11100 Ada_Version_Explicit := Ada_95;
11101 Ada_Version_Pragma := N;
11103 ---------------------
11104 -- Ada_05/Ada_2005 --
11105 ---------------------
11107 -- pragma Ada_05;
11108 -- pragma Ada_05 (LOCAL_NAME);
11110 -- pragma Ada_2005;
11111 -- pragma Ada_2005 (LOCAL_NAME):
11113 -- Note: these pragmas also have some specific processing in Par.Prag
11114 -- because we want to set the Ada 2005 version mode during parsing.
11116 -- The one argument form is used for managing the transition from
11117 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
11118 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
11119 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
11120 -- mode, a preference rule is established which does not choose
11121 -- such an entity unless it is unambiguously specified. This avoids
11122 -- extra subprograms marked this way from generating ambiguities in
11123 -- otherwise legal pre-Ada_2005 programs. The one argument form is
11124 -- intended for exclusive use in the GNAT run-time library.
11126 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
11127 E_Id : Node_Id;
11129 begin
11130 GNAT_Pragma;
11132 if Arg_Count = 1 then
11133 Check_Arg_Is_Local_Name (Arg1);
11134 E_Id := Get_Pragma_Arg (Arg1);
11136 if Etype (E_Id) = Any_Type then
11137 return;
11138 end if;
11140 Set_Is_Ada_2005_Only (Entity (E_Id));
11141 Record_Rep_Item (Entity (E_Id), N);
11143 else
11144 Check_Arg_Count (0);
11146 -- For Ada_2005 we unconditionally enforce the documented
11147 -- configuration pragma placement, since we do not want to
11148 -- tolerate mixed modes in a unit involving Ada 2005. That
11149 -- would cause real difficulties for those cases where there
11150 -- are incompatibilities between Ada 95 and Ada 2005.
11152 Check_Valid_Configuration_Pragma;
11154 -- Now set appropriate Ada mode
11156 Ada_Version := Ada_2005;
11157 Ada_Version_Explicit := Ada_2005;
11158 Ada_Version_Pragma := N;
11159 end if;
11160 end;
11162 ---------------------
11163 -- Ada_12/Ada_2012 --
11164 ---------------------
11166 -- pragma Ada_12;
11167 -- pragma Ada_12 (LOCAL_NAME);
11169 -- pragma Ada_2012;
11170 -- pragma Ada_2012 (LOCAL_NAME):
11172 -- Note: these pragmas also have some specific processing in Par.Prag
11173 -- because we want to set the Ada 2012 version mode during parsing.
11175 -- The one argument form is used for managing the transition from Ada
11176 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
11177 -- as Ada_201 only, then referencing the entity in any pre-Ada_2012
11178 -- mode will generate a warning. In addition, in any pre-Ada_2012
11179 -- mode, a preference rule is established which does not choose
11180 -- such an entity unless it is unambiguously specified. This avoids
11181 -- extra subprograms marked this way from generating ambiguities in
11182 -- otherwise legal pre-Ada_2012 programs. The one argument form is
11183 -- intended for exclusive use in the GNAT run-time library.
11185 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
11186 E_Id : Node_Id;
11188 begin
11189 GNAT_Pragma;
11191 if Arg_Count = 1 then
11192 Check_Arg_Is_Local_Name (Arg1);
11193 E_Id := Get_Pragma_Arg (Arg1);
11195 if Etype (E_Id) = Any_Type then
11196 return;
11197 end if;
11199 Set_Is_Ada_2012_Only (Entity (E_Id));
11200 Record_Rep_Item (Entity (E_Id), N);
11202 else
11203 Check_Arg_Count (0);
11205 -- For Ada_2012 we unconditionally enforce the documented
11206 -- configuration pragma placement, since we do not want to
11207 -- tolerate mixed modes in a unit involving Ada 2012. That
11208 -- would cause real difficulties for those cases where there
11209 -- are incompatibilities between Ada 95 and Ada 2012. We could
11210 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
11212 Check_Valid_Configuration_Pragma;
11214 -- Now set appropriate Ada mode
11216 Ada_Version := Ada_2012;
11217 Ada_Version_Explicit := Ada_2012;
11218 Ada_Version_Pragma := N;
11219 end if;
11220 end;
11222 ----------------------
11223 -- All_Calls_Remote --
11224 ----------------------
11226 -- pragma All_Calls_Remote [(library_package_NAME)];
11228 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
11229 Lib_Entity : Entity_Id;
11231 begin
11232 Check_Ada_83_Warning;
11233 Check_Valid_Library_Unit_Pragma;
11235 if Nkind (N) = N_Null_Statement then
11236 return;
11237 end if;
11239 Lib_Entity := Find_Lib_Unit_Name;
11241 -- A pragma that applies to a Ghost entity becomes Ghost for the
11242 -- purposes of legality checks and removal of ignored Ghost code.
11244 Mark_Pragma_As_Ghost (N, Lib_Entity);
11246 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
11248 if Present (Lib_Entity) and then not Debug_Flag_U then
11249 if not Is_Remote_Call_Interface (Lib_Entity) then
11250 Error_Pragma ("pragma% only apply to rci unit");
11252 -- Set flag for entity of the library unit
11254 else
11255 Set_Has_All_Calls_Remote (Lib_Entity);
11256 end if;
11257 end if;
11258 end All_Calls_Remote;
11260 ---------------------------
11261 -- Allow_Integer_Address --
11262 ---------------------------
11264 -- pragma Allow_Integer_Address;
11266 when Pragma_Allow_Integer_Address =>
11267 GNAT_Pragma;
11268 Check_Valid_Configuration_Pragma;
11269 Check_Arg_Count (0);
11271 -- If Address is a private type, then set the flag to allow
11272 -- integer address values. If Address is not private, then this
11273 -- pragma has no purpose, so it is simply ignored. Not clear if
11274 -- there are any such targets now.
11276 if Opt.Address_Is_Private then
11277 Opt.Allow_Integer_Address := True;
11278 end if;
11280 --------------
11281 -- Annotate --
11282 --------------
11284 -- pragma Annotate
11285 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
11286 -- ARG ::= NAME | EXPRESSION
11288 -- The first two arguments are by convention intended to refer to an
11289 -- external tool and a tool-specific function. These arguments are
11290 -- not analyzed.
11292 when Pragma_Annotate => Annotate : declare
11293 Arg : Node_Id;
11294 Expr : Node_Id;
11295 Nam_Arg : Node_Id;
11297 begin
11298 GNAT_Pragma;
11299 Check_At_Least_N_Arguments (1);
11301 Nam_Arg := Last (Pragma_Argument_Associations (N));
11303 -- Determine whether the last argument is "Entity => local_NAME"
11304 -- and if it is, perform the required semantic checks. Remove the
11305 -- argument from further processing.
11307 if Nkind (Nam_Arg) = N_Pragma_Argument_Association
11308 and then Chars (Nam_Arg) = Name_Entity
11309 then
11310 Check_Arg_Is_Local_Name (Nam_Arg);
11311 Arg_Count := Arg_Count - 1;
11313 -- A pragma that applies to a Ghost entity becomes Ghost for
11314 -- the purposes of legality checks and removal of ignored Ghost
11315 -- code.
11317 if Is_Entity_Name (Get_Pragma_Arg (Nam_Arg))
11318 and then Present (Entity (Get_Pragma_Arg (Nam_Arg)))
11319 then
11320 Mark_Pragma_As_Ghost (N, Entity (Get_Pragma_Arg (Nam_Arg)));
11321 end if;
11323 -- Not allowed in compiler units (bootstrap issues)
11325 Check_Compiler_Unit ("Entity for pragma Annotate", N);
11326 end if;
11328 -- Continue the processing with last argument removed for now
11330 Check_Arg_Is_Identifier (Arg1);
11331 Check_No_Identifiers;
11332 Store_Note (N);
11334 -- The second parameter is optional, it is never analyzed
11336 if No (Arg2) then
11337 null;
11339 -- Otherwise there is a second parameter
11341 else
11342 -- The second parameter must be an identifier
11344 Check_Arg_Is_Identifier (Arg2);
11346 -- Process the remaining parameters (if any)
11348 Arg := Next (Arg2);
11349 while Present (Arg) loop
11350 Expr := Get_Pragma_Arg (Arg);
11351 Analyze (Expr);
11353 if Is_Entity_Name (Expr) then
11354 null;
11356 -- For string literals, we assume Standard_String as the
11357 -- type, unless the string contains wide or wide_wide
11358 -- characters.
11360 elsif Nkind (Expr) = N_String_Literal then
11361 if Has_Wide_Wide_Character (Expr) then
11362 Resolve (Expr, Standard_Wide_Wide_String);
11363 elsif Has_Wide_Character (Expr) then
11364 Resolve (Expr, Standard_Wide_String);
11365 else
11366 Resolve (Expr, Standard_String);
11367 end if;
11369 elsif Is_Overloaded (Expr) then
11370 Error_Pragma_Arg ("ambiguous argument for pragma%", Expr);
11372 else
11373 Resolve (Expr);
11374 end if;
11376 Next (Arg);
11377 end loop;
11378 end if;
11379 end Annotate;
11381 -------------------------------------------------
11382 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
11383 -------------------------------------------------
11385 -- pragma Assert
11386 -- ( [Check => ] Boolean_EXPRESSION
11387 -- [, [Message =>] Static_String_EXPRESSION]);
11389 -- pragma Assert_And_Cut
11390 -- ( [Check => ] Boolean_EXPRESSION
11391 -- [, [Message =>] Static_String_EXPRESSION]);
11393 -- pragma Assume
11394 -- ( [Check => ] Boolean_EXPRESSION
11395 -- [, [Message =>] Static_String_EXPRESSION]);
11397 -- pragma Loop_Invariant
11398 -- ( [Check => ] Boolean_EXPRESSION
11399 -- [, [Message =>] Static_String_EXPRESSION]);
11401 when Pragma_Assert |
11402 Pragma_Assert_And_Cut |
11403 Pragma_Assume |
11404 Pragma_Loop_Invariant =>
11405 Assert : declare
11406 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
11407 -- Determine whether expression Expr contains a Loop_Entry
11408 -- attribute reference.
11410 -------------------------
11411 -- Contains_Loop_Entry --
11412 -------------------------
11414 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
11415 Has_Loop_Entry : Boolean := False;
11417 function Process (N : Node_Id) return Traverse_Result;
11418 -- Process function for traversal to look for Loop_Entry
11420 -------------
11421 -- Process --
11422 -------------
11424 function Process (N : Node_Id) return Traverse_Result is
11425 begin
11426 if Nkind (N) = N_Attribute_Reference
11427 and then Attribute_Name (N) = Name_Loop_Entry
11428 then
11429 Has_Loop_Entry := True;
11430 return Abandon;
11431 else
11432 return OK;
11433 end if;
11434 end Process;
11436 procedure Traverse is new Traverse_Proc (Process);
11438 -- Start of processing for Contains_Loop_Entry
11440 begin
11441 Traverse (Expr);
11442 return Has_Loop_Entry;
11443 end Contains_Loop_Entry;
11445 -- Local variables
11447 Expr : Node_Id;
11448 New_Args : List_Id;
11450 -- Start of processing for Assert
11452 begin
11453 -- Assert is an Ada 2005 RM-defined pragma
11455 if Prag_Id = Pragma_Assert then
11456 Ada_2005_Pragma;
11458 -- The remaining ones are GNAT pragmas
11460 else
11461 GNAT_Pragma;
11462 end if;
11464 Check_At_Least_N_Arguments (1);
11465 Check_At_Most_N_Arguments (2);
11466 Check_Arg_Order ((Name_Check, Name_Message));
11467 Check_Optional_Identifier (Arg1, Name_Check);
11468 Expr := Get_Pragma_Arg (Arg1);
11470 -- Special processing for Loop_Invariant, Loop_Variant or for
11471 -- other cases where a Loop_Entry attribute is present. If the
11472 -- assertion pragma contains attribute Loop_Entry, ensure that
11473 -- the related pragma is within a loop.
11475 if Prag_Id = Pragma_Loop_Invariant
11476 or else Prag_Id = Pragma_Loop_Variant
11477 or else Contains_Loop_Entry (Expr)
11478 then
11479 Check_Loop_Pragma_Placement;
11481 -- Perform preanalysis to deal with embedded Loop_Entry
11482 -- attributes.
11484 Preanalyze_Assert_Expression (Expr, Any_Boolean);
11485 end if;
11487 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
11488 -- a corresponding Check pragma:
11490 -- pragma Check (name, condition [, msg]);
11492 -- Where name is the identifier matching the pragma name. So
11493 -- rewrite pragma in this manner, transfer the message argument
11494 -- if present, and analyze the result
11496 -- Note: When dealing with a semantically analyzed tree, the
11497 -- information that a Check node N corresponds to a source Assert,
11498 -- Assume, or Assert_And_Cut pragma can be retrieved from the
11499 -- pragma kind of Original_Node(N).
11501 New_Args := New_List (
11502 Make_Pragma_Argument_Association (Loc,
11503 Expression => Make_Identifier (Loc, Pname)),
11504 Make_Pragma_Argument_Association (Sloc (Expr),
11505 Expression => Expr));
11507 if Arg_Count > 1 then
11508 Check_Optional_Identifier (Arg2, Name_Message);
11510 -- Provide semantic annnotations for optional argument, for
11511 -- ASIS use, before rewriting.
11513 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
11514 Append_To (New_Args, New_Copy_Tree (Arg2));
11515 end if;
11517 -- Rewrite as Check pragma
11519 Rewrite (N,
11520 Make_Pragma (Loc,
11521 Chars => Name_Check,
11522 Pragma_Argument_Associations => New_Args));
11524 Analyze (N);
11525 end Assert;
11527 ----------------------
11528 -- Assertion_Policy --
11529 ----------------------
11531 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
11533 -- The following form is Ada 2012 only, but we allow it in all modes
11535 -- Pragma Assertion_Policy (
11536 -- ASSERTION_KIND => POLICY_IDENTIFIER
11537 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
11539 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
11541 -- RM_ASSERTION_KIND ::= Assert |
11542 -- Static_Predicate |
11543 -- Dynamic_Predicate |
11544 -- Pre |
11545 -- Pre'Class |
11546 -- Post |
11547 -- Post'Class |
11548 -- Type_Invariant |
11549 -- Type_Invariant'Class
11551 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
11552 -- Assume |
11553 -- Contract_Cases |
11554 -- Debug |
11555 -- Default_Initial_Condition |
11556 -- Ghost |
11557 -- Initial_Condition |
11558 -- Loop_Invariant |
11559 -- Loop_Variant |
11560 -- Postcondition |
11561 -- Precondition |
11562 -- Predicate |
11563 -- Refined_Post |
11564 -- Statement_Assertions
11566 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
11567 -- ID_ASSERTION_KIND list contains implementation-defined additions
11568 -- recognized by GNAT. The effect is to control the behavior of
11569 -- identically named aspects and pragmas, depending on the specified
11570 -- policy identifier:
11572 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore
11574 -- Note: Check and Ignore are language-defined. Disable is a GNAT
11575 -- implementation-defined addition that results in totally ignoring
11576 -- the corresponding assertion. If Disable is specified, then the
11577 -- argument of the assertion is not even analyzed. This is useful
11578 -- when the aspect/pragma argument references entities in a with'ed
11579 -- package that is replaced by a dummy package in the final build.
11581 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
11582 -- and Type_Invariant'Class were recognized by the parser and
11583 -- transformed into references to the special internal identifiers
11584 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
11585 -- processing is required here.
11587 when Pragma_Assertion_Policy => Assertion_Policy : declare
11588 Arg : Node_Id;
11589 Kind : Name_Id;
11590 LocP : Source_Ptr;
11591 Policy : Node_Id;
11593 begin
11594 Ada_2005_Pragma;
11596 -- This can always appear as a configuration pragma
11598 if Is_Configuration_Pragma then
11599 null;
11601 -- It can also appear in a declarative part or package spec in Ada
11602 -- 2012 mode. We allow this in other modes, but in that case we
11603 -- consider that we have an Ada 2012 pragma on our hands.
11605 else
11606 Check_Is_In_Decl_Part_Or_Package_Spec;
11607 Ada_2012_Pragma;
11608 end if;
11610 -- One argument case with no identifier (first form above)
11612 if Arg_Count = 1
11613 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
11614 or else Chars (Arg1) = No_Name)
11615 then
11616 Check_Arg_Is_One_Of
11617 (Arg1, Name_Check, Name_Disable, Name_Ignore);
11619 -- Treat one argument Assertion_Policy as equivalent to:
11621 -- pragma Check_Policy (Assertion, policy)
11623 -- So rewrite pragma in that manner and link on to the chain
11624 -- of Check_Policy pragmas, marking the pragma as analyzed.
11626 Policy := Get_Pragma_Arg (Arg1);
11628 Rewrite (N,
11629 Make_Pragma (Loc,
11630 Chars => Name_Check_Policy,
11631 Pragma_Argument_Associations => New_List (
11632 Make_Pragma_Argument_Association (Loc,
11633 Expression => Make_Identifier (Loc, Name_Assertion)),
11635 Make_Pragma_Argument_Association (Loc,
11636 Expression =>
11637 Make_Identifier (Sloc (Policy), Chars (Policy))))));
11638 Analyze (N);
11640 -- Here if we have two or more arguments
11642 else
11643 Check_At_Least_N_Arguments (1);
11644 Ada_2012_Pragma;
11646 -- Loop through arguments
11648 Arg := Arg1;
11649 while Present (Arg) loop
11650 LocP := Sloc (Arg);
11652 -- Kind must be specified
11654 if Nkind (Arg) /= N_Pragma_Argument_Association
11655 or else Chars (Arg) = No_Name
11656 then
11657 Error_Pragma_Arg
11658 ("missing assertion kind for pragma%", Arg);
11659 end if;
11661 -- Check Kind and Policy have allowed forms
11663 Kind := Chars (Arg);
11664 Policy := Get_Pragma_Arg (Arg);
11666 if not Is_Valid_Assertion_Kind (Kind) then
11667 Error_Pragma_Arg
11668 ("invalid assertion kind for pragma%", Arg);
11669 end if;
11671 Check_Arg_Is_One_Of
11672 (Arg, Name_Check, Name_Disable, Name_Ignore);
11674 if Kind = Name_Ghost then
11676 -- The Ghost policy must be either Check or Ignore
11677 -- (SPARK RM 6.9(6)).
11679 if not Nam_In (Chars (Policy), Name_Check,
11680 Name_Ignore)
11681 then
11682 Error_Pragma_Arg
11683 ("argument of pragma % Ghost must be Check or "
11684 & "Ignore", Policy);
11685 end if;
11687 -- Pragma Assertion_Policy specifying a Ghost policy
11688 -- cannot occur within a Ghost subprogram or package
11689 -- (SPARK RM 6.9(14)).
11691 if Ghost_Mode > None then
11692 Error_Pragma
11693 ("pragma % cannot appear within ghost subprogram or "
11694 & "package");
11695 end if;
11696 end if;
11698 -- Rewrite the Assertion_Policy pragma as a series of
11699 -- Check_Policy pragmas of the form:
11701 -- Check_Policy (Kind, Policy);
11703 -- Note: the insertion of the pragmas cannot be done with
11704 -- Insert_Action because in the configuration case, there
11705 -- are no scopes on the scope stack and the mechanism will
11706 -- fail.
11708 Insert_Before_And_Analyze (N,
11709 Make_Pragma (LocP,
11710 Chars => Name_Check_Policy,
11711 Pragma_Argument_Associations => New_List (
11712 Make_Pragma_Argument_Association (LocP,
11713 Expression => Make_Identifier (LocP, Kind)),
11714 Make_Pragma_Argument_Association (LocP,
11715 Expression => Policy))));
11717 Arg := Next (Arg);
11718 end loop;
11720 -- Rewrite the Assertion_Policy pragma as null since we have
11721 -- now inserted all the equivalent Check pragmas.
11723 Rewrite (N, Make_Null_Statement (Loc));
11724 Analyze (N);
11725 end if;
11726 end Assertion_Policy;
11728 ------------------------------
11729 -- Assume_No_Invalid_Values --
11730 ------------------------------
11732 -- pragma Assume_No_Invalid_Values (On | Off);
11734 when Pragma_Assume_No_Invalid_Values =>
11735 GNAT_Pragma;
11736 Check_Valid_Configuration_Pragma;
11737 Check_Arg_Count (1);
11738 Check_No_Identifiers;
11739 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11741 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
11742 Assume_No_Invalid_Values := True;
11743 else
11744 Assume_No_Invalid_Values := False;
11745 end if;
11747 --------------------------
11748 -- Attribute_Definition --
11749 --------------------------
11751 -- pragma Attribute_Definition
11752 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
11753 -- [Entity =>] LOCAL_NAME,
11754 -- [Expression =>] EXPRESSION | NAME);
11756 when Pragma_Attribute_Definition => Attribute_Definition : declare
11757 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
11758 Aname : Name_Id;
11760 begin
11761 GNAT_Pragma;
11762 Check_Arg_Count (3);
11763 Check_Optional_Identifier (Arg1, "attribute");
11764 Check_Optional_Identifier (Arg2, "entity");
11765 Check_Optional_Identifier (Arg3, "expression");
11767 if Nkind (Attribute_Designator) /= N_Identifier then
11768 Error_Msg_N ("attribute name expected", Attribute_Designator);
11769 return;
11770 end if;
11772 Check_Arg_Is_Local_Name (Arg2);
11774 -- If the attribute is not recognized, then issue a warning (not
11775 -- an error), and ignore the pragma.
11777 Aname := Chars (Attribute_Designator);
11779 if not Is_Attribute_Name (Aname) then
11780 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
11781 return;
11782 end if;
11784 -- Otherwise, rewrite the pragma as an attribute definition clause
11786 Rewrite (N,
11787 Make_Attribute_Definition_Clause (Loc,
11788 Name => Get_Pragma_Arg (Arg2),
11789 Chars => Aname,
11790 Expression => Get_Pragma_Arg (Arg3)));
11791 Analyze (N);
11792 end Attribute_Definition;
11794 ------------------------------------------------------------------
11795 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
11796 ------------------------------------------------------------------
11798 -- pragma Asynch_Readers [ (boolean_EXPRESSION) ];
11799 -- pragma Asynch_Writers [ (boolean_EXPRESSION) ];
11800 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
11801 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
11803 when Pragma_Async_Readers |
11804 Pragma_Async_Writers |
11805 Pragma_Effective_Reads |
11806 Pragma_Effective_Writes =>
11807 Async_Effective : declare
11808 Obj_Decl : Node_Id;
11809 Obj_Id : Entity_Id;
11811 begin
11812 GNAT_Pragma;
11813 Check_No_Identifiers;
11814 Check_At_Most_N_Arguments (1);
11816 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
11818 -- Object declaration
11820 if Nkind (Obj_Decl) = N_Object_Declaration then
11821 null;
11823 -- Otherwise the pragma is associated with an illegal construact
11825 else
11826 Pragma_Misplaced;
11827 return;
11828 end if;
11830 Obj_Id := Defining_Entity (Obj_Decl);
11832 -- Perform minimal verification to ensure that the argument is at
11833 -- least a variable. Subsequent finer grained checks will be done
11834 -- at the end of the declarative region the contains the pragma.
11836 if Ekind (Obj_Id) = E_Variable then
11838 -- Chain the pragma on the contract for further processing by
11839 -- Analyze_External_Property_In_Decl_Part.
11841 Add_Contract_Item (N, Obj_Id);
11843 -- A pragma that applies to a Ghost entity becomes Ghost for
11844 -- the purposes of legality checks and removal of ignored Ghost
11845 -- code.
11847 Mark_Pragma_As_Ghost (N, Obj_Id);
11849 -- Analyze the Boolean expression (if any)
11851 if Present (Arg1) then
11852 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
11853 end if;
11855 -- Otherwise the external property applies to a constant
11857 else
11858 Error_Pragma ("pragma % must apply to a volatile object");
11859 end if;
11860 end Async_Effective;
11862 ------------------
11863 -- Asynchronous --
11864 ------------------
11866 -- pragma Asynchronous (LOCAL_NAME);
11868 when Pragma_Asynchronous => Asynchronous : declare
11869 C_Ent : Entity_Id;
11870 Decl : Node_Id;
11871 Formal : Entity_Id;
11872 L : List_Id;
11873 Nm : Entity_Id;
11874 S : Node_Id;
11876 procedure Process_Async_Pragma;
11877 -- Common processing for procedure and access-to-procedure case
11879 --------------------------
11880 -- Process_Async_Pragma --
11881 --------------------------
11883 procedure Process_Async_Pragma is
11884 begin
11885 if No (L) then
11886 Set_Is_Asynchronous (Nm);
11887 return;
11888 end if;
11890 -- The formals should be of mode IN (RM E.4.1(6))
11892 S := First (L);
11893 while Present (S) loop
11894 Formal := Defining_Identifier (S);
11896 if Nkind (Formal) = N_Defining_Identifier
11897 and then Ekind (Formal) /= E_In_Parameter
11898 then
11899 Error_Pragma_Arg
11900 ("pragma% procedure can only have IN parameter",
11901 Arg1);
11902 end if;
11904 Next (S);
11905 end loop;
11907 Set_Is_Asynchronous (Nm);
11908 end Process_Async_Pragma;
11910 -- Start of processing for pragma Asynchronous
11912 begin
11913 Check_Ada_83_Warning;
11914 Check_No_Identifiers;
11915 Check_Arg_Count (1);
11916 Check_Arg_Is_Local_Name (Arg1);
11918 if Debug_Flag_U then
11919 return;
11920 end if;
11922 C_Ent := Cunit_Entity (Current_Sem_Unit);
11923 Analyze (Get_Pragma_Arg (Arg1));
11924 Nm := Entity (Get_Pragma_Arg (Arg1));
11926 -- A pragma that applies to a Ghost entity becomes Ghost for the
11927 -- purposes of legality checks and removal of ignored Ghost code.
11929 Mark_Pragma_As_Ghost (N, Nm);
11931 if not Is_Remote_Call_Interface (C_Ent)
11932 and then not Is_Remote_Types (C_Ent)
11933 then
11934 -- This pragma should only appear in an RCI or Remote Types
11935 -- unit (RM E.4.1(4)).
11937 Error_Pragma
11938 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
11939 end if;
11941 if Ekind (Nm) = E_Procedure
11942 and then Nkind (Parent (Nm)) = N_Procedure_Specification
11943 then
11944 if not Is_Remote_Call_Interface (Nm) then
11945 Error_Pragma_Arg
11946 ("pragma% cannot be applied on non-remote procedure",
11947 Arg1);
11948 end if;
11950 L := Parameter_Specifications (Parent (Nm));
11951 Process_Async_Pragma;
11952 return;
11954 elsif Ekind (Nm) = E_Function then
11955 Error_Pragma_Arg
11956 ("pragma% cannot be applied to function", Arg1);
11958 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
11959 if Is_Record_Type (Nm) then
11961 -- A record type that is the Equivalent_Type for a remote
11962 -- access-to-subprogram type.
11964 Decl := Declaration_Node (Corresponding_Remote_Type (Nm));
11966 else
11967 -- A non-expanded RAS type (distribution is not enabled)
11969 Decl := Declaration_Node (Nm);
11970 end if;
11972 if Nkind (Decl) = N_Full_Type_Declaration
11973 and then Nkind (Type_Definition (Decl)) =
11974 N_Access_Procedure_Definition
11975 then
11976 L := Parameter_Specifications (Type_Definition (Decl));
11977 Process_Async_Pragma;
11979 if Is_Asynchronous (Nm)
11980 and then Expander_Active
11981 and then Get_PCS_Name /= Name_No_DSA
11982 then
11983 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
11984 end if;
11986 else
11987 Error_Pragma_Arg
11988 ("pragma% cannot reference access-to-function type",
11989 Arg1);
11990 end if;
11992 -- Only other possibility is Access-to-class-wide type
11994 elsif Is_Access_Type (Nm)
11995 and then Is_Class_Wide_Type (Designated_Type (Nm))
11996 then
11997 Check_First_Subtype (Arg1);
11998 Set_Is_Asynchronous (Nm);
11999 if Expander_Active then
12000 RACW_Type_Is_Asynchronous (Nm);
12001 end if;
12003 else
12004 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
12005 end if;
12006 end Asynchronous;
12008 ------------
12009 -- Atomic --
12010 ------------
12012 -- pragma Atomic (LOCAL_NAME);
12014 when Pragma_Atomic =>
12015 Process_Atomic_Independent_Shared_Volatile;
12017 -----------------------
12018 -- Atomic_Components --
12019 -----------------------
12021 -- pragma Atomic_Components (array_LOCAL_NAME);
12023 -- This processing is shared by Volatile_Components
12025 when Pragma_Atomic_Components |
12026 Pragma_Volatile_Components =>
12027 Atomic_Components : declare
12028 D : Node_Id;
12029 E : Entity_Id;
12030 E_Id : Node_Id;
12031 K : Node_Kind;
12033 begin
12034 Check_Ada_83_Warning;
12035 Check_No_Identifiers;
12036 Check_Arg_Count (1);
12037 Check_Arg_Is_Local_Name (Arg1);
12038 E_Id := Get_Pragma_Arg (Arg1);
12040 if Etype (E_Id) = Any_Type then
12041 return;
12042 end if;
12044 E := Entity (E_Id);
12046 -- A pragma that applies to a Ghost entity becomes Ghost for the
12047 -- purposes of legality checks and removal of ignored Ghost code.
12049 Mark_Pragma_As_Ghost (N, E);
12050 Check_Duplicate_Pragma (E);
12052 if Rep_Item_Too_Early (E, N)
12053 or else
12054 Rep_Item_Too_Late (E, N)
12055 then
12056 return;
12057 end if;
12059 D := Declaration_Node (E);
12060 K := Nkind (D);
12062 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
12063 or else
12064 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
12065 and then Nkind (D) = N_Object_Declaration
12066 and then Nkind (Object_Definition (D)) =
12067 N_Constrained_Array_Definition)
12068 then
12069 -- The flag is set on the object, or on the base type
12071 if Nkind (D) /= N_Object_Declaration then
12072 E := Base_Type (E);
12073 end if;
12075 -- Atomic implies both Independent and Volatile
12077 if Prag_Id = Pragma_Atomic_Components then
12078 Set_Has_Atomic_Components (E);
12079 Set_Has_Independent_Components (E);
12080 end if;
12082 Set_Has_Volatile_Components (E);
12084 else
12085 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
12086 end if;
12087 end Atomic_Components;
12089 --------------------
12090 -- Attach_Handler --
12091 --------------------
12093 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
12095 when Pragma_Attach_Handler =>
12096 Check_Ada_83_Warning;
12097 Check_No_Identifiers;
12098 Check_Arg_Count (2);
12100 if No_Run_Time_Mode then
12101 Error_Msg_CRT ("Attach_Handler pragma", N);
12102 else
12103 Check_Interrupt_Or_Attach_Handler;
12105 -- The expression that designates the attribute may depend on a
12106 -- discriminant, and is therefore a per-object expression, to
12107 -- be expanded in the init proc. If expansion is enabled, then
12108 -- perform semantic checks on a copy only.
12110 declare
12111 Temp : Node_Id;
12112 Typ : Node_Id;
12113 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
12115 begin
12116 -- In Relaxed_RM_Semantics mode, we allow any static
12117 -- integer value, for compatibility with other compilers.
12119 if Relaxed_RM_Semantics
12120 and then Nkind (Parg2) = N_Integer_Literal
12121 then
12122 Typ := Standard_Integer;
12123 else
12124 Typ := RTE (RE_Interrupt_ID);
12125 end if;
12127 if Expander_Active then
12128 Temp := New_Copy_Tree (Parg2);
12129 Set_Parent (Temp, N);
12130 Preanalyze_And_Resolve (Temp, Typ);
12131 else
12132 Analyze (Parg2);
12133 Resolve (Parg2, Typ);
12134 end if;
12135 end;
12137 Process_Interrupt_Or_Attach_Handler;
12138 end if;
12140 --------------------
12141 -- C_Pass_By_Copy --
12142 --------------------
12144 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
12146 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
12147 Arg : Node_Id;
12148 Val : Uint;
12150 begin
12151 GNAT_Pragma;
12152 Check_Valid_Configuration_Pragma;
12153 Check_Arg_Count (1);
12154 Check_Optional_Identifier (Arg1, "max_size");
12156 Arg := Get_Pragma_Arg (Arg1);
12157 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
12159 Val := Expr_Value (Arg);
12161 if Val <= 0 then
12162 Error_Pragma_Arg
12163 ("maximum size for pragma% must be positive", Arg1);
12165 elsif UI_Is_In_Int_Range (Val) then
12166 Default_C_Record_Mechanism := UI_To_Int (Val);
12168 -- If a giant value is given, Int'Last will do well enough.
12169 -- If sometime someone complains that a record larger than
12170 -- two gigabytes is not copied, we will worry about it then.
12172 else
12173 Default_C_Record_Mechanism := Mechanism_Type'Last;
12174 end if;
12175 end C_Pass_By_Copy;
12177 -----------
12178 -- Check --
12179 -----------
12181 -- pragma Check ([Name =>] CHECK_KIND,
12182 -- [Check =>] Boolean_EXPRESSION
12183 -- [,[Message =>] String_EXPRESSION]);
12185 -- CHECK_KIND ::= IDENTIFIER |
12186 -- Pre'Class |
12187 -- Post'Class |
12188 -- Invariant'Class |
12189 -- Type_Invariant'Class
12191 -- The identifiers Assertions and Statement_Assertions are not
12192 -- allowed, since they have special meaning for Check_Policy.
12194 when Pragma_Check => Check : declare
12195 Cname : Name_Id;
12196 Eloc : Source_Ptr;
12197 Expr : Node_Id;
12198 Str : Node_Id;
12200 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
12202 begin
12203 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
12204 -- the mode now to ensure that any nodes generated during analysis
12205 -- and expansion are marked as Ghost.
12207 Set_Ghost_Mode (N);
12209 GNAT_Pragma;
12210 Check_At_Least_N_Arguments (2);
12211 Check_At_Most_N_Arguments (3);
12212 Check_Optional_Identifier (Arg1, Name_Name);
12213 Check_Optional_Identifier (Arg2, Name_Check);
12215 if Arg_Count = 3 then
12216 Check_Optional_Identifier (Arg3, Name_Message);
12217 Str := Get_Pragma_Arg (Arg3);
12218 end if;
12220 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
12221 Check_Arg_Is_Identifier (Arg1);
12222 Cname := Chars (Get_Pragma_Arg (Arg1));
12224 -- Check forbidden name Assertions or Statement_Assertions
12226 case Cname is
12227 when Name_Assertions =>
12228 Error_Pragma_Arg
12229 ("""Assertions"" is not allowed as a check kind for "
12230 & "pragma%", Arg1);
12232 when Name_Statement_Assertions =>
12233 Error_Pragma_Arg
12234 ("""Statement_Assertions"" is not allowed as a check kind "
12235 & "for pragma%", Arg1);
12237 when others =>
12238 null;
12239 end case;
12241 -- Check applicable policy. We skip this if Checked/Ignored status
12242 -- is already set (e.g. in the case of a pragma from an aspect).
12244 if Is_Checked (N) or else Is_Ignored (N) then
12245 null;
12247 -- For a non-source pragma that is a rewriting of another pragma,
12248 -- copy the Is_Checked/Ignored status from the rewritten pragma.
12250 elsif Is_Rewrite_Substitution (N)
12251 and then Nkind (Original_Node (N)) = N_Pragma
12252 and then Original_Node (N) /= N
12253 then
12254 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
12255 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
12257 -- Otherwise query the applicable policy at this point
12259 else
12260 case Check_Kind (Cname) is
12261 when Name_Ignore =>
12262 Set_Is_Ignored (N, True);
12263 Set_Is_Checked (N, False);
12265 when Name_Check =>
12266 Set_Is_Ignored (N, False);
12267 Set_Is_Checked (N, True);
12269 -- For disable, rewrite pragma as null statement and skip
12270 -- rest of the analysis of the pragma.
12272 when Name_Disable =>
12273 Rewrite (N, Make_Null_Statement (Loc));
12274 Analyze (N);
12275 raise Pragma_Exit;
12277 -- No other possibilities
12279 when others =>
12280 raise Program_Error;
12281 end case;
12282 end if;
12284 -- If check kind was not Disable, then continue pragma analysis
12286 Expr := Get_Pragma_Arg (Arg2);
12288 -- Deal with SCO generation
12290 case Cname is
12292 -- Nothing to do for predicates as the checks occur in the
12293 -- client units. The SCO for the aspect in the declaration
12294 -- unit is conservatively always enabled.
12296 when Name_Predicate =>
12297 null;
12299 -- Otherwise mark aspect/pragma SCO as enabled
12301 when others =>
12302 if Is_Checked (N) and then not Split_PPC (N) then
12303 Set_SCO_Pragma_Enabled (Loc);
12304 end if;
12305 end case;
12307 -- Deal with analyzing the string argument
12309 if Arg_Count = 3 then
12311 -- If checks are not on we don't want any expansion (since
12312 -- such expansion would not get properly deleted) but
12313 -- we do want to analyze (to get proper references).
12314 -- The Preanalyze_And_Resolve routine does just what we want
12316 if Is_Ignored (N) then
12317 Preanalyze_And_Resolve (Str, Standard_String);
12319 -- Otherwise we need a proper analysis and expansion
12321 else
12322 Analyze_And_Resolve (Str, Standard_String);
12323 end if;
12324 end if;
12326 -- Now you might think we could just do the same with the Boolean
12327 -- expression if checks are off (and expansion is on) and then
12328 -- rewrite the check as a null statement. This would work but we
12329 -- would lose the useful warnings about an assertion being bound
12330 -- to fail even if assertions are turned off.
12332 -- So instead we wrap the boolean expression in an if statement
12333 -- that looks like:
12335 -- if False and then condition then
12336 -- null;
12337 -- end if;
12339 -- The reason we do this rewriting during semantic analysis rather
12340 -- than as part of normal expansion is that we cannot analyze and
12341 -- expand the code for the boolean expression directly, or it may
12342 -- cause insertion of actions that would escape the attempt to
12343 -- suppress the check code.
12345 -- Note that the Sloc for the if statement corresponds to the
12346 -- argument condition, not the pragma itself. The reason for
12347 -- this is that we may generate a warning if the condition is
12348 -- False at compile time, and we do not want to delete this
12349 -- warning when we delete the if statement.
12351 if Expander_Active and Is_Ignored (N) then
12352 Eloc := Sloc (Expr);
12354 Rewrite (N,
12355 Make_If_Statement (Eloc,
12356 Condition =>
12357 Make_And_Then (Eloc,
12358 Left_Opnd => Make_Identifier (Eloc, Name_False),
12359 Right_Opnd => Expr),
12360 Then_Statements => New_List (
12361 Make_Null_Statement (Eloc))));
12363 -- Now go ahead and analyze the if statement
12365 In_Assertion_Expr := In_Assertion_Expr + 1;
12367 -- One rather special treatment. If we are now in Eliminated
12368 -- overflow mode, then suppress overflow checking since we do
12369 -- not want to drag in the bignum stuff if we are in Ignore
12370 -- mode anyway. This is particularly important if we are using
12371 -- a configurable run time that does not support bignum ops.
12373 if Scope_Suppress.Overflow_Mode_Assertions = Eliminated then
12374 declare
12375 Svo : constant Boolean :=
12376 Scope_Suppress.Suppress (Overflow_Check);
12377 begin
12378 Scope_Suppress.Overflow_Mode_Assertions := Strict;
12379 Scope_Suppress.Suppress (Overflow_Check) := True;
12380 Analyze (N);
12381 Scope_Suppress.Suppress (Overflow_Check) := Svo;
12382 Scope_Suppress.Overflow_Mode_Assertions := Eliminated;
12383 end;
12385 -- Not that special case
12387 else
12388 Analyze (N);
12389 end if;
12391 -- All done with this check
12393 In_Assertion_Expr := In_Assertion_Expr - 1;
12395 -- Check is active or expansion not active. In these cases we can
12396 -- just go ahead and analyze the boolean with no worries.
12398 else
12399 In_Assertion_Expr := In_Assertion_Expr + 1;
12400 Analyze_And_Resolve (Expr, Any_Boolean);
12401 In_Assertion_Expr := In_Assertion_Expr - 1;
12402 end if;
12404 Ghost_Mode := Save_Ghost_Mode;
12405 end Check;
12407 --------------------------
12408 -- Check_Float_Overflow --
12409 --------------------------
12411 -- pragma Check_Float_Overflow;
12413 when Pragma_Check_Float_Overflow =>
12414 GNAT_Pragma;
12415 Check_Valid_Configuration_Pragma;
12416 Check_Arg_Count (0);
12417 Check_Float_Overflow := not Machine_Overflows_On_Target;
12419 ----------------
12420 -- Check_Name --
12421 ----------------
12423 -- pragma Check_Name (check_IDENTIFIER);
12425 when Pragma_Check_Name =>
12426 GNAT_Pragma;
12427 Check_No_Identifiers;
12428 Check_Valid_Configuration_Pragma;
12429 Check_Arg_Count (1);
12430 Check_Arg_Is_Identifier (Arg1);
12432 declare
12433 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
12435 begin
12436 for J in Check_Names.First .. Check_Names.Last loop
12437 if Check_Names.Table (J) = Nam then
12438 return;
12439 end if;
12440 end loop;
12442 Check_Names.Append (Nam);
12443 end;
12445 ------------------
12446 -- Check_Policy --
12447 ------------------
12449 -- This is the old style syntax, which is still allowed in all modes:
12451 -- pragma Check_Policy ([Name =>] CHECK_KIND
12452 -- [Policy =>] POLICY_IDENTIFIER);
12454 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
12456 -- CHECK_KIND ::= IDENTIFIER |
12457 -- Pre'Class |
12458 -- Post'Class |
12459 -- Type_Invariant'Class |
12460 -- Invariant'Class
12462 -- This is the new style syntax, compatible with Assertion_Policy
12463 -- and also allowed in all modes.
12465 -- Pragma Check_Policy (
12466 -- CHECK_KIND => POLICY_IDENTIFIER
12467 -- {, CHECK_KIND => POLICY_IDENTIFIER});
12469 -- Note: the identifiers Name and Policy are not allowed as
12470 -- Check_Kind values. This avoids ambiguities between the old and
12471 -- new form syntax.
12473 when Pragma_Check_Policy => Check_Policy : declare
12474 Kind : Node_Id;
12476 begin
12477 GNAT_Pragma;
12478 Check_At_Least_N_Arguments (1);
12480 -- A Check_Policy pragma can appear either as a configuration
12481 -- pragma, or in a declarative part or a package spec (see RM
12482 -- 11.5(5) for rules for Suppress/Unsuppress which are also
12483 -- followed for Check_Policy).
12485 if not Is_Configuration_Pragma then
12486 Check_Is_In_Decl_Part_Or_Package_Spec;
12487 end if;
12489 -- Figure out if we have the old or new syntax. We have the
12490 -- old syntax if the first argument has no identifier, or the
12491 -- identifier is Name.
12493 if Nkind (Arg1) /= N_Pragma_Argument_Association
12494 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
12495 then
12496 -- Old syntax
12498 Check_Arg_Count (2);
12499 Check_Optional_Identifier (Arg1, Name_Name);
12500 Kind := Get_Pragma_Arg (Arg1);
12501 Rewrite_Assertion_Kind (Kind);
12502 Check_Arg_Is_Identifier (Arg1);
12504 -- Check forbidden check kind
12506 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
12507 Error_Msg_Name_2 := Chars (Kind);
12508 Error_Pragma_Arg
12509 ("pragma% does not allow% as check name", Arg1);
12510 end if;
12512 -- Check policy
12514 Check_Optional_Identifier (Arg2, Name_Policy);
12515 Check_Arg_Is_One_Of
12516 (Arg2,
12517 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
12519 -- And chain pragma on the Check_Policy_List for search
12521 Set_Next_Pragma (N, Opt.Check_Policy_List);
12522 Opt.Check_Policy_List := N;
12524 -- For the new syntax, what we do is to convert each argument to
12525 -- an old syntax equivalent. We do that because we want to chain
12526 -- old style Check_Policy pragmas for the search (we don't want
12527 -- to have to deal with multiple arguments in the search).
12529 else
12530 declare
12531 Arg : Node_Id;
12532 Argx : Node_Id;
12533 LocP : Source_Ptr;
12534 New_P : Node_Id;
12536 begin
12537 Arg := Arg1;
12538 while Present (Arg) loop
12539 LocP := Sloc (Arg);
12540 Argx := Get_Pragma_Arg (Arg);
12542 -- Kind must be specified
12544 if Nkind (Arg) /= N_Pragma_Argument_Association
12545 or else Chars (Arg) = No_Name
12546 then
12547 Error_Pragma_Arg
12548 ("missing assertion kind for pragma%", Arg);
12549 end if;
12551 -- Construct equivalent old form syntax Check_Policy
12552 -- pragma and insert it to get remaining checks.
12554 New_P :=
12555 Make_Pragma (LocP,
12556 Chars => Name_Check_Policy,
12557 Pragma_Argument_Associations => New_List (
12558 Make_Pragma_Argument_Association (LocP,
12559 Expression =>
12560 Make_Identifier (LocP, Chars (Arg))),
12561 Make_Pragma_Argument_Association (Sloc (Argx),
12562 Expression => Argx)));
12564 Arg := Next (Arg);
12566 -- For a configuration pragma, insert old form in
12567 -- the corresponding file.
12569 if Is_Configuration_Pragma then
12570 Insert_After (N, New_P);
12571 Analyze (New_P);
12573 else
12574 Insert_Action (N, New_P);
12575 end if;
12576 end loop;
12578 -- Rewrite original Check_Policy pragma to null, since we
12579 -- have converted it into a series of old syntax pragmas.
12581 Rewrite (N, Make_Null_Statement (Loc));
12582 Analyze (N);
12583 end;
12584 end if;
12585 end Check_Policy;
12587 -------------
12588 -- Comment --
12589 -------------
12591 -- pragma Comment (static_string_EXPRESSION)
12593 -- Processing for pragma Comment shares the circuitry for pragma
12594 -- Ident. The only differences are that Ident enforces a limit of 31
12595 -- characters on its argument, and also enforces limitations on
12596 -- placement for DEC compatibility. Pragma Comment shares neither of
12597 -- these restrictions.
12599 -------------------
12600 -- Common_Object --
12601 -------------------
12603 -- pragma Common_Object (
12604 -- [Internal =>] LOCAL_NAME
12605 -- [, [External =>] EXTERNAL_SYMBOL]
12606 -- [, [Size =>] EXTERNAL_SYMBOL]);
12608 -- Processing for this pragma is shared with Psect_Object
12610 ------------------------
12611 -- Compile_Time_Error --
12612 ------------------------
12614 -- pragma Compile_Time_Error
12615 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12617 when Pragma_Compile_Time_Error =>
12618 GNAT_Pragma;
12619 Process_Compile_Time_Warning_Or_Error;
12621 --------------------------
12622 -- Compile_Time_Warning --
12623 --------------------------
12625 -- pragma Compile_Time_Warning
12626 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12628 when Pragma_Compile_Time_Warning =>
12629 GNAT_Pragma;
12630 Process_Compile_Time_Warning_Or_Error;
12632 ---------------------------
12633 -- Compiler_Unit_Warning --
12634 ---------------------------
12636 -- pragma Compiler_Unit_Warning;
12638 -- Historical note
12640 -- Originally, we had only pragma Compiler_Unit, and it resulted in
12641 -- errors not warnings. This means that we had introduced a big extra
12642 -- inertia to compiler changes, since even if we implemented a new
12643 -- feature, and even if all versions to be used for bootstrapping
12644 -- implemented this new feature, we could not use it, since old
12645 -- compilers would give errors for using this feature in units
12646 -- having Compiler_Unit pragmas.
12648 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
12649 -- problem. We no longer have any units mentioning Compiler_Unit,
12650 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
12651 -- and thus generates a warning which can be ignored. So that deals
12652 -- with the problem of old compilers not implementing the newer form
12653 -- of the pragma.
12655 -- Newer compilers recognize the new pragma, but generate warning
12656 -- messages instead of errors, which again can be ignored in the
12657 -- case of an old compiler which implements a wanted new feature
12658 -- but at the time felt like warning about it for older compilers.
12660 -- We retain Compiler_Unit so that new compilers can be used to build
12661 -- older run-times that use this pragma. That's an unusual case, but
12662 -- it's easy enough to handle, so why not?
12664 when Pragma_Compiler_Unit | Pragma_Compiler_Unit_Warning =>
12665 GNAT_Pragma;
12666 Check_Arg_Count (0);
12668 -- Only recognized in main unit
12670 if Current_Sem_Unit = Main_Unit then
12671 Compiler_Unit := True;
12672 end if;
12674 -----------------------------
12675 -- Complete_Representation --
12676 -----------------------------
12678 -- pragma Complete_Representation;
12680 when Pragma_Complete_Representation =>
12681 GNAT_Pragma;
12682 Check_Arg_Count (0);
12684 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
12685 Error_Pragma
12686 ("pragma & must appear within record representation clause");
12687 end if;
12689 ----------------------------
12690 -- Complex_Representation --
12691 ----------------------------
12693 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
12695 when Pragma_Complex_Representation => Complex_Representation : declare
12696 E_Id : Entity_Id;
12697 E : Entity_Id;
12698 Ent : Entity_Id;
12700 begin
12701 GNAT_Pragma;
12702 Check_Arg_Count (1);
12703 Check_Optional_Identifier (Arg1, Name_Entity);
12704 Check_Arg_Is_Local_Name (Arg1);
12705 E_Id := Get_Pragma_Arg (Arg1);
12707 if Etype (E_Id) = Any_Type then
12708 return;
12709 end if;
12711 E := Entity (E_Id);
12713 if not Is_Record_Type (E) then
12714 Error_Pragma_Arg
12715 ("argument for pragma% must be record type", Arg1);
12716 end if;
12718 Ent := First_Entity (E);
12720 if No (Ent)
12721 or else No (Next_Entity (Ent))
12722 or else Present (Next_Entity (Next_Entity (Ent)))
12723 or else not Is_Floating_Point_Type (Etype (Ent))
12724 or else Etype (Ent) /= Etype (Next_Entity (Ent))
12725 then
12726 Error_Pragma_Arg
12727 ("record for pragma% must have two fields of the same "
12728 & "floating-point type", Arg1);
12730 else
12731 Set_Has_Complex_Representation (Base_Type (E));
12733 -- We need to treat the type has having a non-standard
12734 -- representation, for back-end purposes, even though in
12735 -- general a complex will have the default representation
12736 -- of a record with two real components.
12738 Set_Has_Non_Standard_Rep (Base_Type (E));
12739 end if;
12740 end Complex_Representation;
12742 -------------------------
12743 -- Component_Alignment --
12744 -------------------------
12746 -- pragma Component_Alignment (
12747 -- [Form =>] ALIGNMENT_CHOICE
12748 -- [, [Name =>] type_LOCAL_NAME]);
12750 -- ALIGNMENT_CHOICE ::=
12751 -- Component_Size
12752 -- | Component_Size_4
12753 -- | Storage_Unit
12754 -- | Default
12756 when Pragma_Component_Alignment => Component_AlignmentP : declare
12757 Args : Args_List (1 .. 2);
12758 Names : constant Name_List (1 .. 2) := (
12759 Name_Form,
12760 Name_Name);
12762 Form : Node_Id renames Args (1);
12763 Name : Node_Id renames Args (2);
12765 Atype : Component_Alignment_Kind;
12766 Typ : Entity_Id;
12768 begin
12769 GNAT_Pragma;
12770 Gather_Associations (Names, Args);
12772 if No (Form) then
12773 Error_Pragma ("missing Form argument for pragma%");
12774 end if;
12776 Check_Arg_Is_Identifier (Form);
12778 -- Get proper alignment, note that Default = Component_Size on all
12779 -- machines we have so far, and we want to set this value rather
12780 -- than the default value to indicate that it has been explicitly
12781 -- set (and thus will not get overridden by the default component
12782 -- alignment for the current scope)
12784 if Chars (Form) = Name_Component_Size then
12785 Atype := Calign_Component_Size;
12787 elsif Chars (Form) = Name_Component_Size_4 then
12788 Atype := Calign_Component_Size_4;
12790 elsif Chars (Form) = Name_Default then
12791 Atype := Calign_Component_Size;
12793 elsif Chars (Form) = Name_Storage_Unit then
12794 Atype := Calign_Storage_Unit;
12796 else
12797 Error_Pragma_Arg
12798 ("invalid Form parameter for pragma%", Form);
12799 end if;
12801 -- Case with no name, supplied, affects scope table entry
12803 if No (Name) then
12804 Scope_Stack.Table
12805 (Scope_Stack.Last).Component_Alignment_Default := Atype;
12807 -- Case of name supplied
12809 else
12810 Check_Arg_Is_Local_Name (Name);
12811 Find_Type (Name);
12812 Typ := Entity (Name);
12814 if Typ = Any_Type
12815 or else Rep_Item_Too_Early (Typ, N)
12816 then
12817 return;
12818 else
12819 Typ := Underlying_Type (Typ);
12820 end if;
12822 if not Is_Record_Type (Typ)
12823 and then not Is_Array_Type (Typ)
12824 then
12825 Error_Pragma_Arg
12826 ("Name parameter of pragma% must identify record or "
12827 & "array type", Name);
12828 end if;
12830 -- An explicit Component_Alignment pragma overrides an
12831 -- implicit pragma Pack, but not an explicit one.
12833 if not Has_Pragma_Pack (Base_Type (Typ)) then
12834 Set_Is_Packed (Base_Type (Typ), False);
12835 Set_Component_Alignment (Base_Type (Typ), Atype);
12836 end if;
12837 end if;
12838 end Component_AlignmentP;
12840 --------------------------------
12841 -- Constant_After_Elaboration --
12842 --------------------------------
12844 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
12846 when Pragma_Constant_After_Elaboration => Constant_After_Elaboration :
12847 declare
12848 Obj_Decl : Node_Id;
12849 Obj_Id : Entity_Id;
12851 begin
12852 GNAT_Pragma;
12853 Check_No_Identifiers;
12854 Check_At_Most_N_Arguments (1);
12856 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
12858 -- Object declaration
12860 if Nkind (Obj_Decl) = N_Object_Declaration then
12861 null;
12863 -- Otherwise the pragma is associated with an illegal construct
12865 else
12866 Pragma_Misplaced;
12867 return;
12868 end if;
12870 Obj_Id := Defining_Entity (Obj_Decl);
12872 -- The object declaration must be a library-level variable which
12873 -- is either explicitly initialized or obtains a value during the
12874 -- elaboration of a package body (SPARK RM 3.3.1).
12876 if Ekind (Obj_Id) = E_Variable then
12877 if not Is_Library_Level_Entity (Obj_Id) then
12878 Error_Pragma
12879 ("pragma % must apply to a library level variable");
12880 return;
12881 end if;
12883 -- Otherwise the pragma applies to a constant, which is illegal
12885 else
12886 Error_Pragma ("pragma % must apply to a variable declaration");
12887 return;
12888 end if;
12890 -- Chain the pragma on the contract for completeness
12892 Add_Contract_Item (N, Obj_Id);
12894 -- A pragma that applies to a Ghost entity becomes Ghost for the
12895 -- purposes of legality checks and removal of ignored Ghost code.
12897 Mark_Pragma_As_Ghost (N, Obj_Id);
12899 -- Analyze the Boolean expression (if any)
12901 if Present (Arg1) then
12902 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
12903 end if;
12904 end Constant_After_Elaboration;
12906 --------------------
12907 -- Contract_Cases --
12908 --------------------
12910 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
12912 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
12914 -- CASE_GUARD ::= boolean_EXPRESSION | others
12916 -- CONSEQUENCE ::= boolean_EXPRESSION
12918 -- Characteristics:
12920 -- * Analysis - The annotation undergoes initial checks to verify
12921 -- the legal placement and context. Secondary checks preanalyze the
12922 -- expressions in:
12924 -- Analyze_Contract_Cases_In_Decl_Part
12926 -- * Expansion - The annotation is expanded during the expansion of
12927 -- the related subprogram [body] contract as performed in:
12929 -- Expand_Subprogram_Contract
12931 -- * Template - The annotation utilizes the generic template of the
12932 -- related subprogram [body] when it is:
12934 -- aspect on subprogram declaration
12935 -- aspect on stand alone subprogram body
12936 -- pragma on stand alone subprogram body
12938 -- The annotation must prepare its own template when it is:
12940 -- pragma on subprogram declaration
12942 -- * Globals - Capture of global references must occur after full
12943 -- analysis.
12945 -- * Instance - The annotation is instantiated automatically when
12946 -- the related generic subprogram [body] is instantiated except for
12947 -- the "pragma on subprogram declaration" case. In that scenario
12948 -- the annotation must instantiate itself.
12950 when Pragma_Contract_Cases => Contract_Cases : declare
12951 Spec_Id : Entity_Id;
12952 Subp_Decl : Node_Id;
12954 begin
12955 GNAT_Pragma;
12956 Check_No_Identifiers;
12957 Check_Arg_Count (1);
12959 -- Ensure the proper placement of the pragma. Contract_Cases must
12960 -- be associated with a subprogram declaration or a body that acts
12961 -- as a spec.
12963 Subp_Decl :=
12964 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
12966 -- Entry
12968 if Nkind (Subp_Decl) = N_Entry_Declaration then
12969 null;
12971 -- Generic subprogram
12973 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
12974 null;
12976 -- Body acts as spec
12978 elsif Nkind (Subp_Decl) = N_Subprogram_Body
12979 and then No (Corresponding_Spec (Subp_Decl))
12980 then
12981 null;
12983 -- Body stub acts as spec
12985 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
12986 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
12987 then
12988 null;
12990 -- Subprogram
12992 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
12993 null;
12995 else
12996 Pragma_Misplaced;
12997 return;
12998 end if;
13000 Spec_Id := Unique_Defining_Entity (Subp_Decl);
13002 -- Chain the pragma on the contract for further processing by
13003 -- Analyze_Contract_Cases_In_Decl_Part.
13005 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
13007 -- A pragma that applies to a Ghost entity becomes Ghost for the
13008 -- purposes of legality checks and removal of ignored Ghost code.
13010 Mark_Pragma_As_Ghost (N, Spec_Id);
13011 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
13013 -- Fully analyze the pragma when it appears inside an entry
13014 -- or subprogram body because it cannot benefit from forward
13015 -- references.
13017 if Nkind_In (Subp_Decl, N_Entry_Body,
13018 N_Subprogram_Body,
13019 N_Subprogram_Body_Stub)
13020 then
13021 -- The legality checks of pragma Contract_Cases are affected by
13022 -- the SPARK mode in effect and the volatility of the context.
13023 -- Analyze all pragmas in a specific order.
13025 Analyze_If_Present (Pragma_SPARK_Mode);
13026 Analyze_If_Present (Pragma_Volatile_Function);
13027 Analyze_Contract_Cases_In_Decl_Part (N);
13028 end if;
13029 end Contract_Cases;
13031 ----------------
13032 -- Controlled --
13033 ----------------
13035 -- pragma Controlled (first_subtype_LOCAL_NAME);
13037 when Pragma_Controlled => Controlled : declare
13038 Arg : Node_Id;
13040 begin
13041 Check_No_Identifiers;
13042 Check_Arg_Count (1);
13043 Check_Arg_Is_Local_Name (Arg1);
13044 Arg := Get_Pragma_Arg (Arg1);
13046 if not Is_Entity_Name (Arg)
13047 or else not Is_Access_Type (Entity (Arg))
13048 then
13049 Error_Pragma_Arg ("pragma% requires access type", Arg1);
13050 else
13051 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
13052 end if;
13053 end Controlled;
13055 ----------------
13056 -- Convention --
13057 ----------------
13059 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
13060 -- [Entity =>] LOCAL_NAME);
13062 when Pragma_Convention => Convention : declare
13063 C : Convention_Id;
13064 E : Entity_Id;
13065 pragma Warnings (Off, C);
13066 pragma Warnings (Off, E);
13067 begin
13068 Check_Arg_Order ((Name_Convention, Name_Entity));
13069 Check_Ada_83_Warning;
13070 Check_Arg_Count (2);
13071 Process_Convention (C, E);
13073 -- A pragma that applies to a Ghost entity becomes Ghost for the
13074 -- purposes of legality checks and removal of ignored Ghost code.
13076 Mark_Pragma_As_Ghost (N, E);
13077 end Convention;
13079 ---------------------------
13080 -- Convention_Identifier --
13081 ---------------------------
13083 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
13084 -- [Convention =>] convention_IDENTIFIER);
13086 when Pragma_Convention_Identifier => Convention_Identifier : declare
13087 Idnam : Name_Id;
13088 Cname : Name_Id;
13090 begin
13091 GNAT_Pragma;
13092 Check_Arg_Order ((Name_Name, Name_Convention));
13093 Check_Arg_Count (2);
13094 Check_Optional_Identifier (Arg1, Name_Name);
13095 Check_Optional_Identifier (Arg2, Name_Convention);
13096 Check_Arg_Is_Identifier (Arg1);
13097 Check_Arg_Is_Identifier (Arg2);
13098 Idnam := Chars (Get_Pragma_Arg (Arg1));
13099 Cname := Chars (Get_Pragma_Arg (Arg2));
13101 if Is_Convention_Name (Cname) then
13102 Record_Convention_Identifier
13103 (Idnam, Get_Convention_Id (Cname));
13104 else
13105 Error_Pragma_Arg
13106 ("second arg for % pragma must be convention", Arg2);
13107 end if;
13108 end Convention_Identifier;
13110 ---------------
13111 -- CPP_Class --
13112 ---------------
13114 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
13116 when Pragma_CPP_Class => CPP_Class : declare
13117 begin
13118 GNAT_Pragma;
13120 if Warn_On_Obsolescent_Feature then
13121 Error_Msg_N
13122 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
13123 & "effect; replace it by pragma import?j?", N);
13124 end if;
13126 Check_Arg_Count (1);
13128 Rewrite (N,
13129 Make_Pragma (Loc,
13130 Chars => Name_Import,
13131 Pragma_Argument_Associations => New_List (
13132 Make_Pragma_Argument_Association (Loc,
13133 Expression => Make_Identifier (Loc, Name_CPP)),
13134 New_Copy (First (Pragma_Argument_Associations (N))))));
13135 Analyze (N);
13136 end CPP_Class;
13138 ---------------------
13139 -- CPP_Constructor --
13140 ---------------------
13142 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
13143 -- [, [External_Name =>] static_string_EXPRESSION ]
13144 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13146 when Pragma_CPP_Constructor => CPP_Constructor : declare
13147 Elmt : Elmt_Id;
13148 Id : Entity_Id;
13149 Def_Id : Entity_Id;
13150 Tag_Typ : Entity_Id;
13152 begin
13153 GNAT_Pragma;
13154 Check_At_Least_N_Arguments (1);
13155 Check_At_Most_N_Arguments (3);
13156 Check_Optional_Identifier (Arg1, Name_Entity);
13157 Check_Arg_Is_Local_Name (Arg1);
13159 Id := Get_Pragma_Arg (Arg1);
13160 Find_Program_Unit_Name (Id);
13162 -- If we did not find the name, we are done
13164 if Etype (Id) = Any_Type then
13165 return;
13166 end if;
13168 Def_Id := Entity (Id);
13170 -- Check if already defined as constructor
13172 if Is_Constructor (Def_Id) then
13173 Error_Msg_N
13174 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
13175 return;
13176 end if;
13178 if Ekind (Def_Id) = E_Function
13179 and then (Is_CPP_Class (Etype (Def_Id))
13180 or else (Is_Class_Wide_Type (Etype (Def_Id))
13181 and then
13182 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
13183 then
13184 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
13185 Error_Msg_N
13186 ("'C'P'P constructor must be defined in the scope of "
13187 & "its returned type", Arg1);
13188 end if;
13190 if Arg_Count >= 2 then
13191 Set_Imported (Def_Id);
13192 Set_Is_Public (Def_Id);
13193 Process_Interface_Name (Def_Id, Arg2, Arg3);
13194 end if;
13196 Set_Has_Completion (Def_Id);
13197 Set_Is_Constructor (Def_Id);
13198 Set_Convention (Def_Id, Convention_CPP);
13200 -- Imported C++ constructors are not dispatching primitives
13201 -- because in C++ they don't have a dispatch table slot.
13202 -- However, in Ada the constructor has the profile of a
13203 -- function that returns a tagged type and therefore it has
13204 -- been treated as a primitive operation during semantic
13205 -- analysis. We now remove it from the list of primitive
13206 -- operations of the type.
13208 if Is_Tagged_Type (Etype (Def_Id))
13209 and then not Is_Class_Wide_Type (Etype (Def_Id))
13210 and then Is_Dispatching_Operation (Def_Id)
13211 then
13212 Tag_Typ := Etype (Def_Id);
13214 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
13215 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
13216 Next_Elmt (Elmt);
13217 end loop;
13219 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
13220 Set_Is_Dispatching_Operation (Def_Id, False);
13221 end if;
13223 -- For backward compatibility, if the constructor returns a
13224 -- class wide type, and we internally change the return type to
13225 -- the corresponding root type.
13227 if Is_Class_Wide_Type (Etype (Def_Id)) then
13228 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
13229 end if;
13230 else
13231 Error_Pragma_Arg
13232 ("pragma% requires function returning a 'C'P'P_Class type",
13233 Arg1);
13234 end if;
13235 end CPP_Constructor;
13237 -----------------
13238 -- CPP_Virtual --
13239 -----------------
13241 when Pragma_CPP_Virtual => CPP_Virtual : declare
13242 begin
13243 GNAT_Pragma;
13245 if Warn_On_Obsolescent_Feature then
13246 Error_Msg_N
13247 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
13248 & "effect?j?", N);
13249 end if;
13250 end CPP_Virtual;
13252 ----------------
13253 -- CPP_Vtable --
13254 ----------------
13256 when Pragma_CPP_Vtable => CPP_Vtable : declare
13257 begin
13258 GNAT_Pragma;
13260 if Warn_On_Obsolescent_Feature then
13261 Error_Msg_N
13262 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
13263 & "effect?j?", N);
13264 end if;
13265 end CPP_Vtable;
13267 ---------
13268 -- CPU --
13269 ---------
13271 -- pragma CPU (EXPRESSION);
13273 when Pragma_CPU => CPU : declare
13274 P : constant Node_Id := Parent (N);
13275 Arg : Node_Id;
13276 Ent : Entity_Id;
13278 begin
13279 Ada_2012_Pragma;
13280 Check_No_Identifiers;
13281 Check_Arg_Count (1);
13283 -- Subprogram case
13285 if Nkind (P) = N_Subprogram_Body then
13286 Check_In_Main_Program;
13288 Arg := Get_Pragma_Arg (Arg1);
13289 Analyze_And_Resolve (Arg, Any_Integer);
13291 Ent := Defining_Unit_Name (Specification (P));
13293 if Nkind (Ent) = N_Defining_Program_Unit_Name then
13294 Ent := Defining_Identifier (Ent);
13295 end if;
13297 -- Must be static
13299 if not Is_OK_Static_Expression (Arg) then
13300 Flag_Non_Static_Expr
13301 ("main subprogram affinity is not static!", Arg);
13302 raise Pragma_Exit;
13304 -- If constraint error, then we already signalled an error
13306 elsif Raises_Constraint_Error (Arg) then
13307 null;
13309 -- Otherwise check in range
13311 else
13312 declare
13313 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
13314 -- This is the entity System.Multiprocessors.CPU_Range;
13316 Val : constant Uint := Expr_Value (Arg);
13318 begin
13319 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
13320 or else
13321 Val > Expr_Value (Type_High_Bound (CPU_Id))
13322 then
13323 Error_Pragma_Arg
13324 ("main subprogram CPU is out of range", Arg1);
13325 end if;
13326 end;
13327 end if;
13329 Set_Main_CPU
13330 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
13332 -- Task case
13334 elsif Nkind (P) = N_Task_Definition then
13335 Arg := Get_Pragma_Arg (Arg1);
13336 Ent := Defining_Identifier (Parent (P));
13338 -- The expression must be analyzed in the special manner
13339 -- described in "Handling of Default and Per-Object
13340 -- Expressions" in sem.ads.
13342 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
13344 -- Anything else is incorrect
13346 else
13347 Pragma_Misplaced;
13348 end if;
13350 -- Check duplicate pragma before we chain the pragma in the Rep
13351 -- Item chain of Ent.
13353 Check_Duplicate_Pragma (Ent);
13354 Record_Rep_Item (Ent, N);
13355 end CPU;
13357 -----------
13358 -- Debug --
13359 -----------
13361 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
13363 when Pragma_Debug => Debug : declare
13364 Cond : Node_Id;
13365 Call : Node_Id;
13367 begin
13368 GNAT_Pragma;
13370 -- The condition for executing the call is that the expander
13371 -- is active and that we are not ignoring this debug pragma.
13373 Cond :=
13374 New_Occurrence_Of
13375 (Boolean_Literals
13376 (Expander_Active and then not Is_Ignored (N)),
13377 Loc);
13379 if not Is_Ignored (N) then
13380 Set_SCO_Pragma_Enabled (Loc);
13381 end if;
13383 if Arg_Count = 2 then
13384 Cond :=
13385 Make_And_Then (Loc,
13386 Left_Opnd => Relocate_Node (Cond),
13387 Right_Opnd => Get_Pragma_Arg (Arg1));
13388 Call := Get_Pragma_Arg (Arg2);
13389 else
13390 Call := Get_Pragma_Arg (Arg1);
13391 end if;
13393 if Nkind_In (Call,
13394 N_Indexed_Component,
13395 N_Function_Call,
13396 N_Identifier,
13397 N_Expanded_Name,
13398 N_Selected_Component)
13399 then
13400 -- If this pragma Debug comes from source, its argument was
13401 -- parsed as a name form (which is syntactically identical).
13402 -- In a generic context a parameterless call will be left as
13403 -- an expanded name (if global) or selected_component if local.
13404 -- Change it to a procedure call statement now.
13406 Change_Name_To_Procedure_Call_Statement (Call);
13408 elsif Nkind (Call) = N_Procedure_Call_Statement then
13410 -- Already in the form of a procedure call statement: nothing
13411 -- to do (could happen in case of an internally generated
13412 -- pragma Debug).
13414 null;
13416 else
13417 -- All other cases: diagnose error
13419 Error_Msg
13420 ("argument of pragma ""Debug"" is not procedure call",
13421 Sloc (Call));
13422 return;
13423 end if;
13425 -- Rewrite into a conditional with an appropriate condition. We
13426 -- wrap the procedure call in a block so that overhead from e.g.
13427 -- use of the secondary stack does not generate execution overhead
13428 -- for suppressed conditions.
13430 -- Normally the analysis that follows will freeze the subprogram
13431 -- being called. However, if the call is to a null procedure,
13432 -- we want to freeze it before creating the block, because the
13433 -- analysis that follows may be done with expansion disabled, in
13434 -- which case the body will not be generated, leading to spurious
13435 -- errors.
13437 if Nkind (Call) = N_Procedure_Call_Statement
13438 and then Is_Entity_Name (Name (Call))
13439 then
13440 Analyze (Name (Call));
13441 Freeze_Before (N, Entity (Name (Call)));
13442 end if;
13444 Rewrite (N,
13445 Make_Implicit_If_Statement (N,
13446 Condition => Cond,
13447 Then_Statements => New_List (
13448 Make_Block_Statement (Loc,
13449 Handled_Statement_Sequence =>
13450 Make_Handled_Sequence_Of_Statements (Loc,
13451 Statements => New_List (Relocate_Node (Call)))))));
13452 Analyze (N);
13454 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
13455 -- after analysis of the normally rewritten node, to capture all
13456 -- references to entities, which avoids issuing wrong warnings
13457 -- about unused entities.
13459 if GNATprove_Mode then
13460 Rewrite (N, Make_Null_Statement (Loc));
13461 end if;
13462 end Debug;
13464 ------------------
13465 -- Debug_Policy --
13466 ------------------
13468 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
13470 when Pragma_Debug_Policy =>
13471 GNAT_Pragma;
13472 Check_Arg_Count (1);
13473 Check_No_Identifiers;
13474 Check_Arg_Is_Identifier (Arg1);
13476 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
13477 -- rewrite it that way, and let the rest of the checking come
13478 -- from analyzing the rewritten pragma.
13480 Rewrite (N,
13481 Make_Pragma (Loc,
13482 Chars => Name_Check_Policy,
13483 Pragma_Argument_Associations => New_List (
13484 Make_Pragma_Argument_Association (Loc,
13485 Expression => Make_Identifier (Loc, Name_Debug)),
13487 Make_Pragma_Argument_Association (Loc,
13488 Expression => Get_Pragma_Arg (Arg1)))));
13489 Analyze (N);
13491 -------------------------------
13492 -- Default_Initial_Condition --
13493 -------------------------------
13495 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
13497 when Pragma_Default_Initial_Condition => Default_Init_Cond : declare
13498 Discard : Boolean;
13499 Stmt : Node_Id;
13500 Typ : Entity_Id;
13502 begin
13503 GNAT_Pragma;
13504 Check_No_Identifiers;
13505 Check_At_Most_N_Arguments (1);
13507 Stmt := Prev (N);
13508 while Present (Stmt) loop
13510 -- Skip prior pragmas, but check for duplicates
13512 if Nkind (Stmt) = N_Pragma then
13513 if Pragma_Name (Stmt) = Pname then
13514 Error_Msg_Name_1 := Pname;
13515 Error_Msg_Sloc := Sloc (Stmt);
13516 Error_Msg_N ("pragma % duplicates pragma declared#", N);
13517 end if;
13519 -- Skip internally generated code
13521 elsif not Comes_From_Source (Stmt) then
13522 null;
13524 -- The associated private type [extension] has been found, stop
13525 -- the search.
13527 elsif Nkind_In (Stmt, N_Private_Extension_Declaration,
13528 N_Private_Type_Declaration)
13529 then
13530 Typ := Defining_Entity (Stmt);
13531 exit;
13533 -- The pragma does not apply to a legal construct, issue an
13534 -- error and stop the analysis.
13536 else
13537 Pragma_Misplaced;
13538 return;
13539 end if;
13541 Stmt := Prev (Stmt);
13542 end loop;
13544 -- A pragma that applies to a Ghost entity becomes Ghost for the
13545 -- purposes of legality checks and removal of ignored Ghost code.
13547 Mark_Pragma_As_Ghost (N, Typ);
13548 Set_Has_Default_Init_Cond (Typ);
13549 Set_Has_Inherited_Default_Init_Cond (Typ, False);
13551 -- Chain the pragma on the rep item chain for further processing
13553 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
13554 end Default_Init_Cond;
13556 ----------------------------------
13557 -- Default_Scalar_Storage_Order --
13558 ----------------------------------
13560 -- pragma Default_Scalar_Storage_Order
13561 -- (High_Order_First | Low_Order_First);
13563 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
13564 Default : Character;
13566 begin
13567 GNAT_Pragma;
13568 Check_Arg_Count (1);
13570 -- Default_Scalar_Storage_Order can appear as a configuration
13571 -- pragma, or in a declarative part of a package spec.
13573 if not Is_Configuration_Pragma then
13574 Check_Is_In_Decl_Part_Or_Package_Spec;
13575 end if;
13577 Check_No_Identifiers;
13578 Check_Arg_Is_One_Of
13579 (Arg1, Name_High_Order_First, Name_Low_Order_First);
13580 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13581 Default := Fold_Upper (Name_Buffer (1));
13583 if not Support_Nondefault_SSO_On_Target
13584 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
13585 then
13586 if Warn_On_Unrecognized_Pragma then
13587 Error_Msg_N
13588 ("non-default Scalar_Storage_Order not supported "
13589 & "on target?g?", N);
13590 Error_Msg_N
13591 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
13592 end if;
13594 -- Here set the specified default
13596 else
13597 Opt.Default_SSO := Default;
13598 end if;
13599 end DSSO;
13601 --------------------------
13602 -- Default_Storage_Pool --
13603 --------------------------
13605 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
13607 when Pragma_Default_Storage_Pool => Default_Storage_Pool : declare
13608 Pool : Node_Id;
13610 begin
13611 Ada_2012_Pragma;
13612 Check_Arg_Count (1);
13614 -- Default_Storage_Pool can appear as a configuration pragma, or
13615 -- in a declarative part of a package spec.
13617 if not Is_Configuration_Pragma then
13618 Check_Is_In_Decl_Part_Or_Package_Spec;
13619 end if;
13621 if From_Aspect_Specification (N) then
13622 declare
13623 E : constant Entity_Id := Entity (Corresponding_Aspect (N));
13624 begin
13625 if not In_Open_Scopes (E) then
13626 Error_Msg_N
13627 ("aspect must apply to package or subprogram", N);
13628 end if;
13629 end;
13630 end if;
13632 if Present (Arg1) then
13633 Pool := Get_Pragma_Arg (Arg1);
13635 -- Case of Default_Storage_Pool (null);
13637 if Nkind (Pool) = N_Null then
13638 Analyze (Pool);
13640 -- This is an odd case, this is not really an expression,
13641 -- so we don't have a type for it. So just set the type to
13642 -- Empty.
13644 Set_Etype (Pool, Empty);
13646 -- Case of Default_Storage_Pool (storage_pool_NAME);
13648 else
13649 -- If it's a configuration pragma, then the only allowed
13650 -- argument is "null".
13652 if Is_Configuration_Pragma then
13653 Error_Pragma_Arg ("NULL expected", Arg1);
13654 end if;
13656 -- The expected type for a non-"null" argument is
13657 -- Root_Storage_Pool'Class, and the pool must be a variable.
13659 Analyze_And_Resolve
13660 (Pool, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
13662 if Is_Variable (Pool) then
13664 -- A pragma that applies to a Ghost entity becomes Ghost
13665 -- for the purposes of legality checks and removal of
13666 -- ignored Ghost code.
13668 Mark_Pragma_As_Ghost (N, Entity (Pool));
13670 else
13671 Error_Pragma_Arg
13672 ("default storage pool must be a variable", Arg1);
13673 end if;
13674 end if;
13676 -- Record the pool name (or null). Freeze.Freeze_Entity for an
13677 -- access type will use this information to set the appropriate
13678 -- attributes of the access type.
13680 Default_Pool := Pool;
13681 end if;
13682 end Default_Storage_Pool;
13684 -------------
13685 -- Depends --
13686 -------------
13688 -- pragma Depends (DEPENDENCY_RELATION);
13690 -- DEPENDENCY_RELATION ::=
13691 -- null
13692 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
13694 -- DEPENDENCY_CLAUSE ::=
13695 -- OUTPUT_LIST =>[+] INPUT_LIST
13696 -- | NULL_DEPENDENCY_CLAUSE
13698 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
13700 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
13702 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
13704 -- OUTPUT ::= NAME | FUNCTION_RESULT
13705 -- INPUT ::= NAME
13707 -- where FUNCTION_RESULT is a function Result attribute_reference
13709 -- Characteristics:
13711 -- * Analysis - The annotation undergoes initial checks to verify
13712 -- the legal placement and context. Secondary checks fully analyze
13713 -- the dependency clauses in:
13715 -- Analyze_Depends_In_Decl_Part
13717 -- * Expansion - None.
13719 -- * Template - The annotation utilizes the generic template of the
13720 -- related subprogram [body] when it is:
13722 -- aspect on subprogram declaration
13723 -- aspect on stand alone subprogram body
13724 -- pragma on stand alone subprogram body
13726 -- The annotation must prepare its own template when it is:
13728 -- pragma on subprogram declaration
13730 -- * Globals - Capture of global references must occur after full
13731 -- analysis.
13733 -- * Instance - The annotation is instantiated automatically when
13734 -- the related generic subprogram [body] is instantiated except for
13735 -- the "pragma on subprogram declaration" case. In that scenario
13736 -- the annotation must instantiate itself.
13738 when Pragma_Depends => Depends : declare
13739 Legal : Boolean;
13740 Spec_Id : Entity_Id;
13741 Subp_Decl : Node_Id;
13743 begin
13744 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
13746 if Legal then
13748 -- Chain the pragma on the contract for further processing by
13749 -- Analyze_Depends_In_Decl_Part.
13751 Add_Contract_Item (N, Spec_Id);
13753 -- Fully analyze the pragma when it appears inside an entry
13754 -- or subprogram body because it cannot benefit from forward
13755 -- references.
13757 if Nkind_In (Subp_Decl, N_Entry_Body,
13758 N_Subprogram_Body,
13759 N_Subprogram_Body_Stub)
13760 then
13761 -- The legality checks of pragmas Depends and Global are
13762 -- affected by the SPARK mode in effect and the volatility
13763 -- of the context. In addition these two pragmas are subject
13764 -- to an inherent order:
13766 -- 1) Global
13767 -- 2) Depends
13769 -- Analyze all these pragmas in the order outlined above
13771 Analyze_If_Present (Pragma_SPARK_Mode);
13772 Analyze_If_Present (Pragma_Volatile_Function);
13773 Analyze_If_Present (Pragma_Global);
13774 Analyze_Depends_In_Decl_Part (N);
13775 end if;
13776 end if;
13777 end Depends;
13779 ---------------------
13780 -- Detect_Blocking --
13781 ---------------------
13783 -- pragma Detect_Blocking;
13785 when Pragma_Detect_Blocking =>
13786 Ada_2005_Pragma;
13787 Check_Arg_Count (0);
13788 Check_Valid_Configuration_Pragma;
13789 Detect_Blocking := True;
13791 ------------------------------------
13792 -- Disable_Atomic_Synchronization --
13793 ------------------------------------
13795 -- pragma Disable_Atomic_Synchronization [(Entity)];
13797 when Pragma_Disable_Atomic_Synchronization =>
13798 GNAT_Pragma;
13799 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
13801 -------------------
13802 -- Discard_Names --
13803 -------------------
13805 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
13807 when Pragma_Discard_Names => Discard_Names : declare
13808 E : Entity_Id;
13809 E_Id : Node_Id;
13811 begin
13812 Check_Ada_83_Warning;
13814 -- Deal with configuration pragma case
13816 if Arg_Count = 0 and then Is_Configuration_Pragma then
13817 Global_Discard_Names := True;
13818 return;
13820 -- Otherwise, check correct appropriate context
13822 else
13823 Check_Is_In_Decl_Part_Or_Package_Spec;
13825 if Arg_Count = 0 then
13827 -- If there is no parameter, then from now on this pragma
13828 -- applies to any enumeration, exception or tagged type
13829 -- defined in the current declarative part, and recursively
13830 -- to any nested scope.
13832 Set_Discard_Names (Current_Scope);
13833 return;
13835 else
13836 Check_Arg_Count (1);
13837 Check_Optional_Identifier (Arg1, Name_On);
13838 Check_Arg_Is_Local_Name (Arg1);
13840 E_Id := Get_Pragma_Arg (Arg1);
13842 if Etype (E_Id) = Any_Type then
13843 return;
13844 else
13845 E := Entity (E_Id);
13846 end if;
13848 -- A pragma that applies to a Ghost entity becomes Ghost for
13849 -- the purposes of legality checks and removal of ignored
13850 -- Ghost code.
13852 Mark_Pragma_As_Ghost (N, E);
13854 if (Is_First_Subtype (E)
13855 and then
13856 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
13857 or else Ekind (E) = E_Exception
13858 then
13859 Set_Discard_Names (E);
13860 Record_Rep_Item (E, N);
13862 else
13863 Error_Pragma_Arg
13864 ("inappropriate entity for pragma%", Arg1);
13865 end if;
13866 end if;
13867 end if;
13868 end Discard_Names;
13870 ------------------------
13871 -- Dispatching_Domain --
13872 ------------------------
13874 -- pragma Dispatching_Domain (EXPRESSION);
13876 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
13877 P : constant Node_Id := Parent (N);
13878 Arg : Node_Id;
13879 Ent : Entity_Id;
13881 begin
13882 Ada_2012_Pragma;
13883 Check_No_Identifiers;
13884 Check_Arg_Count (1);
13886 -- This pragma is born obsolete, but not the aspect
13888 if not From_Aspect_Specification (N) then
13889 Check_Restriction
13890 (No_Obsolescent_Features, Pragma_Identifier (N));
13891 end if;
13893 if Nkind (P) = N_Task_Definition then
13894 Arg := Get_Pragma_Arg (Arg1);
13895 Ent := Defining_Identifier (Parent (P));
13897 -- A pragma that applies to a Ghost entity becomes Ghost for
13898 -- the purposes of legality checks and removal of ignored Ghost
13899 -- code.
13901 Mark_Pragma_As_Ghost (N, Ent);
13903 -- The expression must be analyzed in the special manner
13904 -- described in "Handling of Default and Per-Object
13905 -- Expressions" in sem.ads.
13907 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
13909 -- Check duplicate pragma before we chain the pragma in the Rep
13910 -- Item chain of Ent.
13912 Check_Duplicate_Pragma (Ent);
13913 Record_Rep_Item (Ent, N);
13915 -- Anything else is incorrect
13917 else
13918 Pragma_Misplaced;
13919 end if;
13920 end Dispatching_Domain;
13922 ---------------
13923 -- Elaborate --
13924 ---------------
13926 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
13928 when Pragma_Elaborate => Elaborate : declare
13929 Arg : Node_Id;
13930 Citem : Node_Id;
13932 begin
13933 -- Pragma must be in context items list of a compilation unit
13935 if not Is_In_Context_Clause then
13936 Pragma_Misplaced;
13937 end if;
13939 -- Must be at least one argument
13941 if Arg_Count = 0 then
13942 Error_Pragma ("pragma% requires at least one argument");
13943 end if;
13945 -- In Ada 83 mode, there can be no items following it in the
13946 -- context list except other pragmas and implicit with clauses
13947 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
13948 -- placement rule does not apply.
13950 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
13951 Citem := Next (N);
13952 while Present (Citem) loop
13953 if Nkind (Citem) = N_Pragma
13954 or else (Nkind (Citem) = N_With_Clause
13955 and then Implicit_With (Citem))
13956 then
13957 null;
13958 else
13959 Error_Pragma
13960 ("(Ada 83) pragma% must be at end of context clause");
13961 end if;
13963 Next (Citem);
13964 end loop;
13965 end if;
13967 -- Finally, the arguments must all be units mentioned in a with
13968 -- clause in the same context clause. Note we already checked (in
13969 -- Par.Prag) that the arguments are all identifiers or selected
13970 -- components.
13972 Arg := Arg1;
13973 Outer : while Present (Arg) loop
13974 Citem := First (List_Containing (N));
13975 Inner : while Citem /= N loop
13976 if Nkind (Citem) = N_With_Clause
13977 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
13978 then
13979 Set_Elaborate_Present (Citem, True);
13980 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
13982 -- With the pragma present, elaboration calls on
13983 -- subprograms from the named unit need no further
13984 -- checks, as long as the pragma appears in the current
13985 -- compilation unit. If the pragma appears in some unit
13986 -- in the context, there might still be a need for an
13987 -- Elaborate_All_Desirable from the current compilation
13988 -- to the named unit, so we keep the check enabled.
13990 if In_Extended_Main_Source_Unit (N) then
13992 -- This does not apply in SPARK mode, where we allow
13993 -- pragma Elaborate, but we don't trust it to be right
13994 -- so we will still insist on the Elaborate_All.
13996 if SPARK_Mode /= On then
13997 Set_Suppress_Elaboration_Warnings
13998 (Entity (Name (Citem)));
13999 end if;
14000 end if;
14002 exit Inner;
14003 end if;
14005 Next (Citem);
14006 end loop Inner;
14008 if Citem = N then
14009 Error_Pragma_Arg
14010 ("argument of pragma% is not withed unit", Arg);
14011 end if;
14013 Next (Arg);
14014 end loop Outer;
14016 -- Give a warning if operating in static mode with one of the
14017 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set.
14019 if Elab_Warnings
14020 and not Dynamic_Elaboration_Checks
14022 -- pragma Elaborate not allowed in SPARK mode anyway. We
14023 -- already complained about it, no point in generating any
14024 -- further complaint.
14026 and SPARK_Mode /= On
14027 then
14028 Error_Msg_N
14029 ("?l?use of pragma Elaborate may not be safe", N);
14030 Error_Msg_N
14031 ("?l?use pragma Elaborate_All instead if possible", N);
14032 end if;
14033 end Elaborate;
14035 -------------------
14036 -- Elaborate_All --
14037 -------------------
14039 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
14041 when Pragma_Elaborate_All => Elaborate_All : declare
14042 Arg : Node_Id;
14043 Citem : Node_Id;
14045 begin
14046 Check_Ada_83_Warning;
14048 -- Pragma must be in context items list of a compilation unit
14050 if not Is_In_Context_Clause then
14051 Pragma_Misplaced;
14052 end if;
14054 -- Must be at least one argument
14056 if Arg_Count = 0 then
14057 Error_Pragma ("pragma% requires at least one argument");
14058 end if;
14060 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
14061 -- have to appear at the end of the context clause, but may
14062 -- appear mixed in with other items, even in Ada 83 mode.
14064 -- Final check: the arguments must all be units mentioned in
14065 -- a with clause in the same context clause. Note that we
14066 -- already checked (in Par.Prag) that all the arguments are
14067 -- either identifiers or selected components.
14069 Arg := Arg1;
14070 Outr : while Present (Arg) loop
14071 Citem := First (List_Containing (N));
14072 Innr : while Citem /= N loop
14073 if Nkind (Citem) = N_With_Clause
14074 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
14075 then
14076 Set_Elaborate_All_Present (Citem, True);
14077 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
14079 -- Suppress warnings and elaboration checks on the named
14080 -- unit if the pragma is in the current compilation, as
14081 -- for pragma Elaborate.
14083 if In_Extended_Main_Source_Unit (N) then
14084 Set_Suppress_Elaboration_Warnings
14085 (Entity (Name (Citem)));
14086 end if;
14087 exit Innr;
14088 end if;
14090 Next (Citem);
14091 end loop Innr;
14093 if Citem = N then
14094 Set_Error_Posted (N);
14095 Error_Pragma_Arg
14096 ("argument of pragma% is not withed unit", Arg);
14097 end if;
14099 Next (Arg);
14100 end loop Outr;
14101 end Elaborate_All;
14103 --------------------
14104 -- Elaborate_Body --
14105 --------------------
14107 -- pragma Elaborate_Body [( library_unit_NAME )];
14109 when Pragma_Elaborate_Body => Elaborate_Body : declare
14110 Cunit_Node : Node_Id;
14111 Cunit_Ent : Entity_Id;
14113 begin
14114 Check_Ada_83_Warning;
14115 Check_Valid_Library_Unit_Pragma;
14117 if Nkind (N) = N_Null_Statement then
14118 return;
14119 end if;
14121 Cunit_Node := Cunit (Current_Sem_Unit);
14122 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14124 -- A pragma that applies to a Ghost entity becomes Ghost for the
14125 -- purposes of legality checks and removal of ignored Ghost code.
14127 Mark_Pragma_As_Ghost (N, Cunit_Ent);
14129 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
14130 N_Subprogram_Body)
14131 then
14132 Error_Pragma ("pragma% must refer to a spec, not a body");
14133 else
14134 Set_Body_Required (Cunit_Node, True);
14135 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
14137 -- If we are in dynamic elaboration mode, then we suppress
14138 -- elaboration warnings for the unit, since it is definitely
14139 -- fine NOT to do dynamic checks at the first level (and such
14140 -- checks will be suppressed because no elaboration boolean
14141 -- is created for Elaborate_Body packages).
14143 -- But in the static model of elaboration, Elaborate_Body is
14144 -- definitely NOT good enough to ensure elaboration safety on
14145 -- its own, since the body may WITH other units that are not
14146 -- safe from an elaboration point of view, so a client must
14147 -- still do an Elaborate_All on such units.
14149 -- Debug flag -gnatdD restores the old behavior of 3.13, where
14150 -- Elaborate_Body always suppressed elab warnings.
14152 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
14153 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
14154 end if;
14155 end if;
14156 end Elaborate_Body;
14158 ------------------------
14159 -- Elaboration_Checks --
14160 ------------------------
14162 -- pragma Elaboration_Checks (Static | Dynamic);
14164 when Pragma_Elaboration_Checks =>
14165 GNAT_Pragma;
14166 Check_Arg_Count (1);
14167 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
14169 -- Set flag accordingly (ignore attempt at dynamic elaboration
14170 -- checks in SPARK mode).
14172 Dynamic_Elaboration_Checks :=
14173 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic)
14174 and then SPARK_Mode /= On;
14176 ---------------
14177 -- Eliminate --
14178 ---------------
14180 -- pragma Eliminate (
14181 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
14182 -- [,[Entity =>] IDENTIFIER |
14183 -- SELECTED_COMPONENT |
14184 -- STRING_LITERAL]
14185 -- [, OVERLOADING_RESOLUTION]);
14187 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
14188 -- SOURCE_LOCATION
14190 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
14191 -- FUNCTION_PROFILE
14193 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
14195 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
14196 -- Result_Type => result_SUBTYPE_NAME]
14198 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
14199 -- SUBTYPE_NAME ::= STRING_LITERAL
14201 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
14202 -- SOURCE_TRACE ::= STRING_LITERAL
14204 when Pragma_Eliminate => Eliminate : declare
14205 Args : Args_List (1 .. 5);
14206 Names : constant Name_List (1 .. 5) := (
14207 Name_Unit_Name,
14208 Name_Entity,
14209 Name_Parameter_Types,
14210 Name_Result_Type,
14211 Name_Source_Location);
14213 Unit_Name : Node_Id renames Args (1);
14214 Entity : Node_Id renames Args (2);
14215 Parameter_Types : Node_Id renames Args (3);
14216 Result_Type : Node_Id renames Args (4);
14217 Source_Location : Node_Id renames Args (5);
14219 begin
14220 GNAT_Pragma;
14221 Check_Valid_Configuration_Pragma;
14222 Gather_Associations (Names, Args);
14224 if No (Unit_Name) then
14225 Error_Pragma ("missing Unit_Name argument for pragma%");
14226 end if;
14228 if No (Entity)
14229 and then (Present (Parameter_Types)
14230 or else
14231 Present (Result_Type)
14232 or else
14233 Present (Source_Location))
14234 then
14235 Error_Pragma ("missing Entity argument for pragma%");
14236 end if;
14238 if (Present (Parameter_Types)
14239 or else
14240 Present (Result_Type))
14241 and then
14242 Present (Source_Location)
14243 then
14244 Error_Pragma
14245 ("parameter profile and source location cannot be used "
14246 & "together in pragma%");
14247 end if;
14249 Process_Eliminate_Pragma
14251 Unit_Name,
14252 Entity,
14253 Parameter_Types,
14254 Result_Type,
14255 Source_Location);
14256 end Eliminate;
14258 -----------------------------------
14259 -- Enable_Atomic_Synchronization --
14260 -----------------------------------
14262 -- pragma Enable_Atomic_Synchronization [(Entity)];
14264 when Pragma_Enable_Atomic_Synchronization =>
14265 GNAT_Pragma;
14266 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
14268 ------------
14269 -- Export --
14270 ------------
14272 -- pragma Export (
14273 -- [ Convention =>] convention_IDENTIFIER,
14274 -- [ Entity =>] LOCAL_NAME
14275 -- [, [External_Name =>] static_string_EXPRESSION ]
14276 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14278 when Pragma_Export => Export : declare
14279 C : Convention_Id;
14280 Def_Id : Entity_Id;
14282 pragma Warnings (Off, C);
14284 begin
14285 Check_Ada_83_Warning;
14286 Check_Arg_Order
14287 ((Name_Convention,
14288 Name_Entity,
14289 Name_External_Name,
14290 Name_Link_Name));
14292 Check_At_Least_N_Arguments (2);
14293 Check_At_Most_N_Arguments (4);
14295 -- In Relaxed_RM_Semantics, support old Ada 83 style:
14296 -- pragma Export (Entity, "external name");
14298 if Relaxed_RM_Semantics
14299 and then Arg_Count = 2
14300 and then Nkind (Expression (Arg2)) = N_String_Literal
14301 then
14302 C := Convention_C;
14303 Def_Id := Get_Pragma_Arg (Arg1);
14304 Analyze (Def_Id);
14306 if not Is_Entity_Name (Def_Id) then
14307 Error_Pragma_Arg ("entity name required", Arg1);
14308 end if;
14310 Def_Id := Entity (Def_Id);
14311 Set_Exported (Def_Id, Arg1);
14313 else
14314 Process_Convention (C, Def_Id);
14316 -- A pragma that applies to a Ghost entity becomes Ghost for
14317 -- the purposes of legality checks and removal of ignored Ghost
14318 -- code.
14320 Mark_Pragma_As_Ghost (N, Def_Id);
14322 if Ekind (Def_Id) /= E_Constant then
14323 Note_Possible_Modification
14324 (Get_Pragma_Arg (Arg2), Sure => False);
14325 end if;
14327 Process_Interface_Name (Def_Id, Arg3, Arg4);
14328 Set_Exported (Def_Id, Arg2);
14329 end if;
14331 -- If the entity is a deferred constant, propagate the information
14332 -- to the full view, because gigi elaborates the full view only.
14334 if Ekind (Def_Id) = E_Constant
14335 and then Present (Full_View (Def_Id))
14336 then
14337 declare
14338 Id2 : constant Entity_Id := Full_View (Def_Id);
14339 begin
14340 Set_Is_Exported (Id2, Is_Exported (Def_Id));
14341 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
14342 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
14343 end;
14344 end if;
14345 end Export;
14347 ---------------------
14348 -- Export_Function --
14349 ---------------------
14351 -- pragma Export_Function (
14352 -- [Internal =>] LOCAL_NAME
14353 -- [, [External =>] EXTERNAL_SYMBOL]
14354 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14355 -- [, [Result_Type =>] TYPE_DESIGNATOR]
14356 -- [, [Mechanism =>] MECHANISM]
14357 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
14359 -- EXTERNAL_SYMBOL ::=
14360 -- IDENTIFIER
14361 -- | static_string_EXPRESSION
14363 -- PARAMETER_TYPES ::=
14364 -- null
14365 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14367 -- TYPE_DESIGNATOR ::=
14368 -- subtype_NAME
14369 -- | subtype_Name ' Access
14371 -- MECHANISM ::=
14372 -- MECHANISM_NAME
14373 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14375 -- MECHANISM_ASSOCIATION ::=
14376 -- [formal_parameter_NAME =>] MECHANISM_NAME
14378 -- MECHANISM_NAME ::=
14379 -- Value
14380 -- | Reference
14382 when Pragma_Export_Function => Export_Function : declare
14383 Args : Args_List (1 .. 6);
14384 Names : constant Name_List (1 .. 6) := (
14385 Name_Internal,
14386 Name_External,
14387 Name_Parameter_Types,
14388 Name_Result_Type,
14389 Name_Mechanism,
14390 Name_Result_Mechanism);
14392 Internal : Node_Id renames Args (1);
14393 External : Node_Id renames Args (2);
14394 Parameter_Types : Node_Id renames Args (3);
14395 Result_Type : Node_Id renames Args (4);
14396 Mechanism : Node_Id renames Args (5);
14397 Result_Mechanism : Node_Id renames Args (6);
14399 begin
14400 GNAT_Pragma;
14401 Gather_Associations (Names, Args);
14402 Process_Extended_Import_Export_Subprogram_Pragma (
14403 Arg_Internal => Internal,
14404 Arg_External => External,
14405 Arg_Parameter_Types => Parameter_Types,
14406 Arg_Result_Type => Result_Type,
14407 Arg_Mechanism => Mechanism,
14408 Arg_Result_Mechanism => Result_Mechanism);
14409 end Export_Function;
14411 -------------------
14412 -- Export_Object --
14413 -------------------
14415 -- pragma Export_Object (
14416 -- [Internal =>] LOCAL_NAME
14417 -- [, [External =>] EXTERNAL_SYMBOL]
14418 -- [, [Size =>] EXTERNAL_SYMBOL]);
14420 -- EXTERNAL_SYMBOL ::=
14421 -- IDENTIFIER
14422 -- | static_string_EXPRESSION
14424 -- PARAMETER_TYPES ::=
14425 -- null
14426 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14428 -- TYPE_DESIGNATOR ::=
14429 -- subtype_NAME
14430 -- | subtype_Name ' Access
14432 -- MECHANISM ::=
14433 -- MECHANISM_NAME
14434 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14436 -- MECHANISM_ASSOCIATION ::=
14437 -- [formal_parameter_NAME =>] MECHANISM_NAME
14439 -- MECHANISM_NAME ::=
14440 -- Value
14441 -- | Reference
14443 when Pragma_Export_Object => Export_Object : declare
14444 Args : Args_List (1 .. 3);
14445 Names : constant Name_List (1 .. 3) := (
14446 Name_Internal,
14447 Name_External,
14448 Name_Size);
14450 Internal : Node_Id renames Args (1);
14451 External : Node_Id renames Args (2);
14452 Size : Node_Id renames Args (3);
14454 begin
14455 GNAT_Pragma;
14456 Gather_Associations (Names, Args);
14457 Process_Extended_Import_Export_Object_Pragma (
14458 Arg_Internal => Internal,
14459 Arg_External => External,
14460 Arg_Size => Size);
14461 end Export_Object;
14463 ----------------------
14464 -- Export_Procedure --
14465 ----------------------
14467 -- pragma Export_Procedure (
14468 -- [Internal =>] LOCAL_NAME
14469 -- [, [External =>] EXTERNAL_SYMBOL]
14470 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14471 -- [, [Mechanism =>] MECHANISM]);
14473 -- EXTERNAL_SYMBOL ::=
14474 -- IDENTIFIER
14475 -- | static_string_EXPRESSION
14477 -- PARAMETER_TYPES ::=
14478 -- null
14479 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14481 -- TYPE_DESIGNATOR ::=
14482 -- subtype_NAME
14483 -- | subtype_Name ' Access
14485 -- MECHANISM ::=
14486 -- MECHANISM_NAME
14487 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14489 -- MECHANISM_ASSOCIATION ::=
14490 -- [formal_parameter_NAME =>] MECHANISM_NAME
14492 -- MECHANISM_NAME ::=
14493 -- Value
14494 -- | Reference
14496 when Pragma_Export_Procedure => Export_Procedure : declare
14497 Args : Args_List (1 .. 4);
14498 Names : constant Name_List (1 .. 4) := (
14499 Name_Internal,
14500 Name_External,
14501 Name_Parameter_Types,
14502 Name_Mechanism);
14504 Internal : Node_Id renames Args (1);
14505 External : Node_Id renames Args (2);
14506 Parameter_Types : Node_Id renames Args (3);
14507 Mechanism : Node_Id renames Args (4);
14509 begin
14510 GNAT_Pragma;
14511 Gather_Associations (Names, Args);
14512 Process_Extended_Import_Export_Subprogram_Pragma (
14513 Arg_Internal => Internal,
14514 Arg_External => External,
14515 Arg_Parameter_Types => Parameter_Types,
14516 Arg_Mechanism => Mechanism);
14517 end Export_Procedure;
14519 ------------------
14520 -- Export_Value --
14521 ------------------
14523 -- pragma Export_Value (
14524 -- [Value =>] static_integer_EXPRESSION,
14525 -- [Link_Name =>] static_string_EXPRESSION);
14527 when Pragma_Export_Value =>
14528 GNAT_Pragma;
14529 Check_Arg_Order ((Name_Value, Name_Link_Name));
14530 Check_Arg_Count (2);
14532 Check_Optional_Identifier (Arg1, Name_Value);
14533 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
14535 Check_Optional_Identifier (Arg2, Name_Link_Name);
14536 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
14538 -----------------------------
14539 -- Export_Valued_Procedure --
14540 -----------------------------
14542 -- pragma Export_Valued_Procedure (
14543 -- [Internal =>] LOCAL_NAME
14544 -- [, [External =>] EXTERNAL_SYMBOL,]
14545 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14546 -- [, [Mechanism =>] MECHANISM]);
14548 -- EXTERNAL_SYMBOL ::=
14549 -- IDENTIFIER
14550 -- | static_string_EXPRESSION
14552 -- PARAMETER_TYPES ::=
14553 -- null
14554 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14556 -- TYPE_DESIGNATOR ::=
14557 -- subtype_NAME
14558 -- | subtype_Name ' Access
14560 -- MECHANISM ::=
14561 -- MECHANISM_NAME
14562 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14564 -- MECHANISM_ASSOCIATION ::=
14565 -- [formal_parameter_NAME =>] MECHANISM_NAME
14567 -- MECHANISM_NAME ::=
14568 -- Value
14569 -- | Reference
14571 when Pragma_Export_Valued_Procedure =>
14572 Export_Valued_Procedure : declare
14573 Args : Args_List (1 .. 4);
14574 Names : constant Name_List (1 .. 4) := (
14575 Name_Internal,
14576 Name_External,
14577 Name_Parameter_Types,
14578 Name_Mechanism);
14580 Internal : Node_Id renames Args (1);
14581 External : Node_Id renames Args (2);
14582 Parameter_Types : Node_Id renames Args (3);
14583 Mechanism : Node_Id renames Args (4);
14585 begin
14586 GNAT_Pragma;
14587 Gather_Associations (Names, Args);
14588 Process_Extended_Import_Export_Subprogram_Pragma (
14589 Arg_Internal => Internal,
14590 Arg_External => External,
14591 Arg_Parameter_Types => Parameter_Types,
14592 Arg_Mechanism => Mechanism);
14593 end Export_Valued_Procedure;
14595 -------------------
14596 -- Extend_System --
14597 -------------------
14599 -- pragma Extend_System ([Name =>] Identifier);
14601 when Pragma_Extend_System => Extend_System : declare
14602 begin
14603 GNAT_Pragma;
14604 Check_Valid_Configuration_Pragma;
14605 Check_Arg_Count (1);
14606 Check_Optional_Identifier (Arg1, Name_Name);
14607 Check_Arg_Is_Identifier (Arg1);
14609 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
14611 if Name_Len > 4
14612 and then Name_Buffer (1 .. 4) = "aux_"
14613 then
14614 if Present (System_Extend_Pragma_Arg) then
14615 if Chars (Get_Pragma_Arg (Arg1)) =
14616 Chars (Expression (System_Extend_Pragma_Arg))
14617 then
14618 null;
14619 else
14620 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
14621 Error_Pragma ("pragma% conflicts with that #");
14622 end if;
14624 else
14625 System_Extend_Pragma_Arg := Arg1;
14627 if not GNAT_Mode then
14628 System_Extend_Unit := Arg1;
14629 end if;
14630 end if;
14631 else
14632 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
14633 end if;
14634 end Extend_System;
14636 ------------------------
14637 -- Extensions_Allowed --
14638 ------------------------
14640 -- pragma Extensions_Allowed (ON | OFF);
14642 when Pragma_Extensions_Allowed =>
14643 GNAT_Pragma;
14644 Check_Arg_Count (1);
14645 Check_No_Identifiers;
14646 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14648 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
14649 Extensions_Allowed := True;
14650 Ada_Version := Ada_Version_Type'Last;
14652 else
14653 Extensions_Allowed := False;
14654 Ada_Version := Ada_Version_Explicit;
14655 Ada_Version_Pragma := Empty;
14656 end if;
14658 ------------------------
14659 -- Extensions_Visible --
14660 ------------------------
14662 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
14664 -- Characteristics:
14666 -- * Analysis - The annotation is fully analyzed immediately upon
14667 -- elaboration as its expression must be static.
14669 -- * Expansion - None.
14671 -- * Template - The annotation utilizes the generic template of the
14672 -- related subprogram [body] when it is:
14674 -- aspect on subprogram declaration
14675 -- aspect on stand alone subprogram body
14676 -- pragma on stand alone subprogram body
14678 -- The annotation must prepare its own template when it is:
14680 -- pragma on subprogram declaration
14682 -- * Globals - Capture of global references must occur after full
14683 -- analysis.
14685 -- * Instance - The annotation is instantiated automatically when
14686 -- the related generic subprogram [body] is instantiated except for
14687 -- the "pragma on subprogram declaration" case. In that scenario
14688 -- the annotation must instantiate itself.
14690 when Pragma_Extensions_Visible => Extensions_Visible : declare
14691 Formal : Entity_Id;
14692 Has_OK_Formal : Boolean := False;
14693 Spec_Id : Entity_Id;
14694 Subp_Decl : Node_Id;
14696 begin
14697 GNAT_Pragma;
14698 Check_No_Identifiers;
14699 Check_At_Most_N_Arguments (1);
14701 Subp_Decl :=
14702 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
14704 -- Abstract subprogram declaration
14706 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
14707 null;
14709 -- Generic subprogram declaration
14711 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
14712 null;
14714 -- Body acts as spec
14716 elsif Nkind (Subp_Decl) = N_Subprogram_Body
14717 and then No (Corresponding_Spec (Subp_Decl))
14718 then
14719 null;
14721 -- Body stub acts as spec
14723 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
14724 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
14725 then
14726 null;
14728 -- Subprogram declaration
14730 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
14731 null;
14733 -- Otherwise the pragma is associated with an illegal construct
14735 else
14736 Error_Pragma ("pragma % must apply to a subprogram");
14737 return;
14738 end if;
14740 -- Chain the pragma on the contract for completeness
14742 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
14744 -- The legality checks of pragma Extension_Visible are affected
14745 -- by the SPARK mode in effect. Analyze all pragmas in specific
14746 -- order.
14748 Analyze_If_Present (Pragma_SPARK_Mode);
14750 -- Mark the pragma as Ghost if the related subprogram is also
14751 -- Ghost. This also ensures that any expansion performed further
14752 -- below will produce Ghost nodes.
14754 Spec_Id := Unique_Defining_Entity (Subp_Decl);
14755 Mark_Pragma_As_Ghost (N, Spec_Id);
14757 -- Examine the formals of the related subprogram
14759 Formal := First_Formal (Spec_Id);
14760 while Present (Formal) loop
14762 -- At least one of the formals is of a specific tagged type,
14763 -- the pragma is legal.
14765 if Is_Specific_Tagged_Type (Etype (Formal)) then
14766 Has_OK_Formal := True;
14767 exit;
14769 -- A generic subprogram with at least one formal of a private
14770 -- type ensures the legality of the pragma because the actual
14771 -- may be specifically tagged. Note that this is verified by
14772 -- the check above at instantiation time.
14774 elsif Is_Private_Type (Etype (Formal))
14775 and then Is_Generic_Type (Etype (Formal))
14776 then
14777 Has_OK_Formal := True;
14778 exit;
14779 end if;
14781 Next_Formal (Formal);
14782 end loop;
14784 if not Has_OK_Formal then
14785 Error_Msg_Name_1 := Pname;
14786 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
14787 Error_Msg_NE
14788 ("\subprogram & lacks parameter of specific tagged or "
14789 & "generic private type", N, Spec_Id);
14791 return;
14792 end if;
14794 -- Analyze the Boolean expression (if any)
14796 if Present (Arg1) then
14797 Check_Static_Boolean_Expression
14798 (Expression (Get_Argument (N, Spec_Id)));
14799 end if;
14800 end Extensions_Visible;
14802 --------------
14803 -- External --
14804 --------------
14806 -- pragma External (
14807 -- [ Convention =>] convention_IDENTIFIER,
14808 -- [ Entity =>] LOCAL_NAME
14809 -- [, [External_Name =>] static_string_EXPRESSION ]
14810 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14812 when Pragma_External => External : declare
14813 C : Convention_Id;
14814 E : Entity_Id;
14815 pragma Warnings (Off, C);
14817 begin
14818 GNAT_Pragma;
14819 Check_Arg_Order
14820 ((Name_Convention,
14821 Name_Entity,
14822 Name_External_Name,
14823 Name_Link_Name));
14824 Check_At_Least_N_Arguments (2);
14825 Check_At_Most_N_Arguments (4);
14826 Process_Convention (C, E);
14828 -- A pragma that applies to a Ghost entity becomes Ghost for the
14829 -- purposes of legality checks and removal of ignored Ghost code.
14831 Mark_Pragma_As_Ghost (N, E);
14833 Note_Possible_Modification
14834 (Get_Pragma_Arg (Arg2), Sure => False);
14835 Process_Interface_Name (E, Arg3, Arg4);
14836 Set_Exported (E, Arg2);
14837 end External;
14839 --------------------------
14840 -- External_Name_Casing --
14841 --------------------------
14843 -- pragma External_Name_Casing (
14844 -- UPPERCASE | LOWERCASE
14845 -- [, AS_IS | UPPERCASE | LOWERCASE]);
14847 when Pragma_External_Name_Casing => External_Name_Casing : declare
14848 begin
14849 GNAT_Pragma;
14850 Check_No_Identifiers;
14852 if Arg_Count = 2 then
14853 Check_Arg_Is_One_Of
14854 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
14856 case Chars (Get_Pragma_Arg (Arg2)) is
14857 when Name_As_Is =>
14858 Opt.External_Name_Exp_Casing := As_Is;
14860 when Name_Uppercase =>
14861 Opt.External_Name_Exp_Casing := Uppercase;
14863 when Name_Lowercase =>
14864 Opt.External_Name_Exp_Casing := Lowercase;
14866 when others =>
14867 null;
14868 end case;
14870 else
14871 Check_Arg_Count (1);
14872 end if;
14874 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
14876 case Chars (Get_Pragma_Arg (Arg1)) is
14877 when Name_Uppercase =>
14878 Opt.External_Name_Imp_Casing := Uppercase;
14880 when Name_Lowercase =>
14881 Opt.External_Name_Imp_Casing := Lowercase;
14883 when others =>
14884 null;
14885 end case;
14886 end External_Name_Casing;
14888 ---------------
14889 -- Fast_Math --
14890 ---------------
14892 -- pragma Fast_Math;
14894 when Pragma_Fast_Math =>
14895 GNAT_Pragma;
14896 Check_No_Identifiers;
14897 Check_Valid_Configuration_Pragma;
14898 Fast_Math := True;
14900 --------------------------
14901 -- Favor_Top_Level --
14902 --------------------------
14904 -- pragma Favor_Top_Level (type_NAME);
14906 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
14907 Typ : Entity_Id;
14909 begin
14910 GNAT_Pragma;
14911 Check_No_Identifiers;
14912 Check_Arg_Count (1);
14913 Check_Arg_Is_Local_Name (Arg1);
14914 Typ := Entity (Get_Pragma_Arg (Arg1));
14916 -- A pragma that applies to a Ghost entity becomes Ghost for the
14917 -- purposes of legality checks and removal of ignored Ghost code.
14919 Mark_Pragma_As_Ghost (N, Typ);
14921 -- If it's an access-to-subprogram type (in particular, not a
14922 -- subtype), set the flag on that type.
14924 if Is_Access_Subprogram_Type (Typ) then
14925 Set_Can_Use_Internal_Rep (Typ, False);
14927 -- Otherwise it's an error (name denotes the wrong sort of entity)
14929 else
14930 Error_Pragma_Arg
14931 ("access-to-subprogram type expected",
14932 Get_Pragma_Arg (Arg1));
14933 end if;
14934 end Favor_Top_Level;
14936 ---------------------------
14937 -- Finalize_Storage_Only --
14938 ---------------------------
14940 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
14942 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
14943 Assoc : constant Node_Id := Arg1;
14944 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
14945 Typ : Entity_Id;
14947 begin
14948 GNAT_Pragma;
14949 Check_No_Identifiers;
14950 Check_Arg_Count (1);
14951 Check_Arg_Is_Local_Name (Arg1);
14953 Find_Type (Type_Id);
14954 Typ := Entity (Type_Id);
14956 if Typ = Any_Type
14957 or else Rep_Item_Too_Early (Typ, N)
14958 then
14959 return;
14960 else
14961 Typ := Underlying_Type (Typ);
14962 end if;
14964 if not Is_Controlled (Typ) then
14965 Error_Pragma ("pragma% must specify controlled type");
14966 end if;
14968 Check_First_Subtype (Arg1);
14970 if Finalize_Storage_Only (Typ) then
14971 Error_Pragma ("duplicate pragma%, only one allowed");
14973 elsif not Rep_Item_Too_Late (Typ, N) then
14974 Set_Finalize_Storage_Only (Base_Type (Typ), True);
14975 end if;
14976 end Finalize_Storage;
14978 -----------
14979 -- Ghost --
14980 -----------
14982 -- pragma Ghost [ (boolean_EXPRESSION) ];
14984 when Pragma_Ghost => Ghost : declare
14985 Context : Node_Id;
14986 Expr : Node_Id;
14987 Id : Entity_Id;
14988 Orig_Stmt : Node_Id;
14989 Prev_Id : Entity_Id;
14990 Stmt : Node_Id;
14992 begin
14993 GNAT_Pragma;
14994 Check_No_Identifiers;
14995 Check_At_Most_N_Arguments (1);
14997 Id := Empty;
14998 Stmt := Prev (N);
14999 while Present (Stmt) loop
15001 -- Skip prior pragmas, but check for duplicates
15003 if Nkind (Stmt) = N_Pragma then
15004 if Pragma_Name (Stmt) = Pname then
15005 Error_Msg_Name_1 := Pname;
15006 Error_Msg_Sloc := Sloc (Stmt);
15007 Error_Msg_N ("pragma % duplicates pragma declared#", N);
15008 end if;
15010 -- Task unit declared without a definition cannot be subject to
15011 -- pragma Ghost (SPARK RM 6.9(19)).
15013 elsif Nkind_In (Stmt, N_Single_Task_Declaration,
15014 N_Task_Type_Declaration)
15015 then
15016 Error_Pragma ("pragma % cannot apply to a task type");
15017 return;
15019 -- Skip internally generated code
15021 elsif not Comes_From_Source (Stmt) then
15022 Orig_Stmt := Original_Node (Stmt);
15024 -- When pragma Ghost applies to an untagged derivation, the
15025 -- derivation is transformed into a [sub]type declaration.
15027 if Nkind_In (Stmt, N_Full_Type_Declaration,
15028 N_Subtype_Declaration)
15029 and then Comes_From_Source (Orig_Stmt)
15030 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
15031 and then Nkind (Type_Definition (Orig_Stmt)) =
15032 N_Derived_Type_Definition
15033 then
15034 Id := Defining_Entity (Stmt);
15035 exit;
15037 -- When pragma Ghost applies to an expression function, the
15038 -- expression function is transformed into a subprogram.
15040 elsif Nkind (Stmt) = N_Subprogram_Declaration
15041 and then Comes_From_Source (Orig_Stmt)
15042 and then Nkind (Orig_Stmt) = N_Expression_Function
15043 then
15044 Id := Defining_Entity (Stmt);
15045 exit;
15046 end if;
15048 -- The pragma applies to a legal construct, stop the traversal
15050 elsif Nkind_In (Stmt, N_Abstract_Subprogram_Declaration,
15051 N_Full_Type_Declaration,
15052 N_Generic_Subprogram_Declaration,
15053 N_Object_Declaration,
15054 N_Private_Extension_Declaration,
15055 N_Private_Type_Declaration,
15056 N_Subprogram_Declaration,
15057 N_Subtype_Declaration)
15058 then
15059 Id := Defining_Entity (Stmt);
15060 exit;
15062 -- The pragma does not apply to a legal construct, issue an
15063 -- error and stop the analysis.
15065 else
15066 Error_Pragma
15067 ("pragma % must apply to an object, package, subprogram "
15068 & "or type");
15069 return;
15070 end if;
15072 Stmt := Prev (Stmt);
15073 end loop;
15075 Context := Parent (N);
15077 -- Handle compilation units
15079 if Nkind (Context) = N_Compilation_Unit_Aux then
15080 Context := Unit (Parent (Context));
15081 end if;
15083 -- Protected and task types cannot be subject to pragma Ghost
15084 -- (SPARK RM 6.9(19)).
15086 if Nkind_In (Context, N_Protected_Body, N_Protected_Definition)
15087 then
15088 Error_Pragma ("pragma % cannot apply to a protected type");
15089 return;
15091 elsif Nkind_In (Context, N_Task_Body, N_Task_Definition) then
15092 Error_Pragma ("pragma % cannot apply to a task type");
15093 return;
15094 end if;
15096 if No (Id) then
15098 -- When pragma Ghost is associated with a [generic] package, it
15099 -- appears in the visible declarations.
15101 if Nkind (Context) = N_Package_Specification
15102 and then Present (Visible_Declarations (Context))
15103 and then List_Containing (N) = Visible_Declarations (Context)
15104 then
15105 Id := Defining_Entity (Context);
15107 -- Pragma Ghost applies to a stand alone subprogram body
15109 elsif Nkind (Context) = N_Subprogram_Body
15110 and then No (Corresponding_Spec (Context))
15111 then
15112 Id := Defining_Entity (Context);
15114 -- Pragma Ghost applies to a subprogram declaration that acts
15115 -- as a compilation unit.
15117 elsif Nkind (Context) = N_Subprogram_Declaration then
15118 Id := Defining_Entity (Context);
15119 end if;
15120 end if;
15122 if No (Id) then
15123 Error_Pragma
15124 ("pragma % must apply to an object, package, subprogram or "
15125 & "type");
15126 return;
15127 end if;
15129 -- Handle completions of types and constants that are subject to
15130 -- pragma Ghost.
15132 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
15133 Prev_Id := Incomplete_Or_Partial_View (Id);
15135 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
15136 Error_Msg_Name_1 := Pname;
15138 -- The full declaration of a deferred constant cannot be
15139 -- subject to pragma Ghost unless the deferred declaration
15140 -- is also Ghost (SPARK RM 6.9(9)).
15142 if Ekind (Prev_Id) = E_Constant then
15143 Error_Msg_Name_1 := Pname;
15144 Error_Msg_NE (Fix_Error
15145 ("pragma % must apply to declaration of deferred "
15146 & "constant &"), N, Id);
15147 return;
15149 -- Pragma Ghost may appear on the full view of an incomplete
15150 -- type because the incomplete declaration lacks aspects and
15151 -- cannot be subject to pragma Ghost.
15153 elsif Ekind (Prev_Id) = E_Incomplete_Type then
15154 null;
15156 -- The full declaration of a type cannot be subject to
15157 -- pragma Ghost unless the partial view is also Ghost
15158 -- (SPARK RM 6.9(9)).
15160 else
15161 Error_Msg_NE (Fix_Error
15162 ("pragma % must apply to partial view of type &"),
15163 N, Id);
15164 return;
15165 end if;
15166 end if;
15168 -- A synchronized object cannot be subject to pragma Ghost
15169 -- (SPARK RM 6.9(19)).
15171 elsif Ekind (Id) = E_Variable then
15172 if Is_Protected_Type (Etype (Id)) then
15173 Error_Pragma ("pragma % cannot apply to a protected object");
15174 return;
15176 elsif Is_Task_Type (Etype (Id)) then
15177 Error_Pragma ("pragma % cannot apply to a task object");
15178 return;
15179 end if;
15180 end if;
15182 -- Analyze the Boolean expression (if any)
15184 if Present (Arg1) then
15185 Expr := Get_Pragma_Arg (Arg1);
15187 Analyze_And_Resolve (Expr, Standard_Boolean);
15189 if Is_OK_Static_Expression (Expr) then
15191 -- "Ghostness" cannot be turned off once enabled within a
15192 -- region (SPARK RM 6.9(6)).
15194 if Is_False (Expr_Value (Expr))
15195 and then Ghost_Mode > None
15196 then
15197 Error_Pragma
15198 ("pragma % with value False cannot appear in enabled "
15199 & "ghost region");
15200 return;
15201 end if;
15203 -- Otherwie the expression is not static
15205 else
15206 Error_Pragma_Arg
15207 ("expression of pragma % must be static", Expr);
15208 return;
15209 end if;
15210 end if;
15212 Set_Is_Ghost_Entity (Id);
15213 end Ghost;
15215 ------------
15216 -- Global --
15217 ------------
15219 -- pragma Global (GLOBAL_SPECIFICATION);
15221 -- GLOBAL_SPECIFICATION ::=
15222 -- null
15223 -- | (GLOBAL_LIST)
15224 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
15226 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
15228 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
15229 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
15230 -- GLOBAL_ITEM ::= NAME
15232 -- Characteristics:
15234 -- * Analysis - The annotation undergoes initial checks to verify
15235 -- the legal placement and context. Secondary checks fully analyze
15236 -- the dependency clauses in:
15238 -- Analyze_Global_In_Decl_Part
15240 -- * Expansion - None.
15242 -- * Template - The annotation utilizes the generic template of the
15243 -- related subprogram [body] when it is:
15245 -- aspect on subprogram declaration
15246 -- aspect on stand alone subprogram body
15247 -- pragma on stand alone subprogram body
15249 -- The annotation must prepare its own template when it is:
15251 -- pragma on subprogram declaration
15253 -- * Globals - Capture of global references must occur after full
15254 -- analysis.
15256 -- * Instance - The annotation is instantiated automatically when
15257 -- the related generic subprogram [body] is instantiated except for
15258 -- the "pragma on subprogram declaration" case. In that scenario
15259 -- the annotation must instantiate itself.
15261 when Pragma_Global => Global : declare
15262 Legal : Boolean;
15263 Spec_Id : Entity_Id;
15264 Subp_Decl : Node_Id;
15266 begin
15267 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
15269 if Legal then
15271 -- Chain the pragma on the contract for further processing by
15272 -- Analyze_Global_In_Decl_Part.
15274 Add_Contract_Item (N, Spec_Id);
15276 -- Fully analyze the pragma when it appears inside an entry
15277 -- or subprogram body because it cannot benefit from forward
15278 -- references.
15280 if Nkind_In (Subp_Decl, N_Entry_Body,
15281 N_Subprogram_Body,
15282 N_Subprogram_Body_Stub)
15283 then
15284 -- The legality checks of pragmas Depends and Global are
15285 -- affected by the SPARK mode in effect and the volatility
15286 -- of the context. In addition these two pragmas are subject
15287 -- to an inherent order:
15289 -- 1) Global
15290 -- 2) Depends
15292 -- Analyze all these pragmas in the order outlined above
15294 Analyze_If_Present (Pragma_SPARK_Mode);
15295 Analyze_If_Present (Pragma_Volatile_Function);
15296 Analyze_Global_In_Decl_Part (N);
15297 Analyze_If_Present (Pragma_Depends);
15298 end if;
15299 end if;
15300 end Global;
15302 -----------
15303 -- Ident --
15304 -----------
15306 -- pragma Ident (static_string_EXPRESSION)
15308 -- Note: pragma Comment shares this processing. Pragma Ident is
15309 -- identical in effect to pragma Commment.
15311 when Pragma_Ident | Pragma_Comment => Ident : declare
15312 Str : Node_Id;
15314 begin
15315 GNAT_Pragma;
15316 Check_Arg_Count (1);
15317 Check_No_Identifiers;
15318 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
15319 Store_Note (N);
15321 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
15323 declare
15324 CS : Node_Id;
15325 GP : Node_Id;
15327 begin
15328 GP := Parent (Parent (N));
15330 if Nkind_In (GP, N_Package_Declaration,
15331 N_Generic_Package_Declaration)
15332 then
15333 GP := Parent (GP);
15334 end if;
15336 -- If we have a compilation unit, then record the ident value,
15337 -- checking for improper duplication.
15339 if Nkind (GP) = N_Compilation_Unit then
15340 CS := Ident_String (Current_Sem_Unit);
15342 if Present (CS) then
15344 -- If we have multiple instances, concatenate them, but
15345 -- not in ASIS, where we want the original tree.
15347 if not ASIS_Mode then
15348 Start_String (Strval (CS));
15349 Store_String_Char (' ');
15350 Store_String_Chars (Strval (Str));
15351 Set_Strval (CS, End_String);
15352 end if;
15354 else
15355 Set_Ident_String (Current_Sem_Unit, Str);
15356 end if;
15358 -- For subunits, we just ignore the Ident, since in GNAT these
15359 -- are not separate object files, and hence not separate units
15360 -- in the unit table.
15362 elsif Nkind (GP) = N_Subunit then
15363 null;
15364 end if;
15365 end;
15366 end Ident;
15368 -------------------
15369 -- Ignore_Pragma --
15370 -------------------
15372 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
15374 -- Entirely handled in the parser, nothing to do here
15376 when Pragma_Ignore_Pragma =>
15377 null;
15379 ----------------------------
15380 -- Implementation_Defined --
15381 ----------------------------
15383 -- pragma Implementation_Defined (LOCAL_NAME);
15385 -- Marks previously declared entity as implementation defined. For
15386 -- an overloaded entity, applies to the most recent homonym.
15388 -- pragma Implementation_Defined;
15390 -- The form with no arguments appears anywhere within a scope, most
15391 -- typically a package spec, and indicates that all entities that are
15392 -- defined within the package spec are Implementation_Defined.
15394 when Pragma_Implementation_Defined => Implementation_Defined : declare
15395 Ent : Entity_Id;
15397 begin
15398 GNAT_Pragma;
15399 Check_No_Identifiers;
15401 -- Form with no arguments
15403 if Arg_Count = 0 then
15404 Set_Is_Implementation_Defined (Current_Scope);
15406 -- Form with one argument
15408 else
15409 Check_Arg_Count (1);
15410 Check_Arg_Is_Local_Name (Arg1);
15411 Ent := Entity (Get_Pragma_Arg (Arg1));
15412 Set_Is_Implementation_Defined (Ent);
15413 end if;
15414 end Implementation_Defined;
15416 -----------------
15417 -- Implemented --
15418 -----------------
15420 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
15422 -- IMPLEMENTATION_KIND ::=
15423 -- By_Entry | By_Protected_Procedure | By_Any | Optional
15425 -- "By_Any" and "Optional" are treated as synonyms in order to
15426 -- support Ada 2012 aspect Synchronization.
15428 when Pragma_Implemented => Implemented : declare
15429 Proc_Id : Entity_Id;
15430 Typ : Entity_Id;
15432 begin
15433 Ada_2012_Pragma;
15434 Check_Arg_Count (2);
15435 Check_No_Identifiers;
15436 Check_Arg_Is_Identifier (Arg1);
15437 Check_Arg_Is_Local_Name (Arg1);
15438 Check_Arg_Is_One_Of (Arg2,
15439 Name_By_Any,
15440 Name_By_Entry,
15441 Name_By_Protected_Procedure,
15442 Name_Optional);
15444 -- Extract the name of the local procedure
15446 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
15448 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
15449 -- primitive procedure of a synchronized tagged type.
15451 if Ekind (Proc_Id) = E_Procedure
15452 and then Is_Primitive (Proc_Id)
15453 and then Present (First_Formal (Proc_Id))
15454 then
15455 Typ := Etype (First_Formal (Proc_Id));
15457 if Is_Tagged_Type (Typ)
15458 and then
15460 -- Check for a protected, a synchronized or a task interface
15462 ((Is_Interface (Typ)
15463 and then Is_Synchronized_Interface (Typ))
15465 -- Check for a protected type or a task type that implements
15466 -- an interface.
15468 or else
15469 (Is_Concurrent_Record_Type (Typ)
15470 and then Present (Interfaces (Typ)))
15472 -- In analysis-only mode, examine original protected type
15474 or else
15475 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
15476 and then Present (Interface_List (Parent (Typ))))
15478 -- Check for a private record extension with keyword
15479 -- "synchronized".
15481 or else
15482 (Ekind_In (Typ, E_Record_Type_With_Private,
15483 E_Record_Subtype_With_Private)
15484 and then Synchronized_Present (Parent (Typ))))
15485 then
15486 null;
15487 else
15488 Error_Pragma_Arg
15489 ("controlling formal must be of synchronized tagged type",
15490 Arg1);
15491 return;
15492 end if;
15494 -- Procedures declared inside a protected type must be accepted
15496 elsif Ekind (Proc_Id) = E_Procedure
15497 and then Is_Protected_Type (Scope (Proc_Id))
15498 then
15499 null;
15501 -- The first argument is not a primitive procedure
15503 else
15504 Error_Pragma_Arg
15505 ("pragma % must be applied to a primitive procedure", Arg1);
15506 return;
15507 end if;
15509 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
15510 -- By_Protected_Procedure to the primitive procedure of a task
15511 -- interface.
15513 if Chars (Arg2) = Name_By_Protected_Procedure
15514 and then Is_Interface (Typ)
15515 and then Is_Task_Interface (Typ)
15516 then
15517 Error_Pragma_Arg
15518 ("implementation kind By_Protected_Procedure cannot be "
15519 & "applied to a task interface primitive", Arg2);
15520 return;
15521 end if;
15523 Record_Rep_Item (Proc_Id, N);
15524 end Implemented;
15526 ----------------------
15527 -- Implicit_Packing --
15528 ----------------------
15530 -- pragma Implicit_Packing;
15532 when Pragma_Implicit_Packing =>
15533 GNAT_Pragma;
15534 Check_Arg_Count (0);
15535 Implicit_Packing := True;
15537 ------------
15538 -- Import --
15539 ------------
15541 -- pragma Import (
15542 -- [Convention =>] convention_IDENTIFIER,
15543 -- [Entity =>] LOCAL_NAME
15544 -- [, [External_Name =>] static_string_EXPRESSION ]
15545 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15547 when Pragma_Import =>
15548 Check_Ada_83_Warning;
15549 Check_Arg_Order
15550 ((Name_Convention,
15551 Name_Entity,
15552 Name_External_Name,
15553 Name_Link_Name));
15555 Check_At_Least_N_Arguments (2);
15556 Check_At_Most_N_Arguments (4);
15557 Process_Import_Or_Interface;
15559 ---------------------
15560 -- Import_Function --
15561 ---------------------
15563 -- pragma Import_Function (
15564 -- [Internal =>] LOCAL_NAME,
15565 -- [, [External =>] EXTERNAL_SYMBOL]
15566 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15567 -- [, [Result_Type =>] SUBTYPE_MARK]
15568 -- [, [Mechanism =>] MECHANISM]
15569 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
15571 -- EXTERNAL_SYMBOL ::=
15572 -- IDENTIFIER
15573 -- | static_string_EXPRESSION
15575 -- PARAMETER_TYPES ::=
15576 -- null
15577 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15579 -- TYPE_DESIGNATOR ::=
15580 -- subtype_NAME
15581 -- | subtype_Name ' Access
15583 -- MECHANISM ::=
15584 -- MECHANISM_NAME
15585 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15587 -- MECHANISM_ASSOCIATION ::=
15588 -- [formal_parameter_NAME =>] MECHANISM_NAME
15590 -- MECHANISM_NAME ::=
15591 -- Value
15592 -- | Reference
15594 when Pragma_Import_Function => Import_Function : declare
15595 Args : Args_List (1 .. 6);
15596 Names : constant Name_List (1 .. 6) := (
15597 Name_Internal,
15598 Name_External,
15599 Name_Parameter_Types,
15600 Name_Result_Type,
15601 Name_Mechanism,
15602 Name_Result_Mechanism);
15604 Internal : Node_Id renames Args (1);
15605 External : Node_Id renames Args (2);
15606 Parameter_Types : Node_Id renames Args (3);
15607 Result_Type : Node_Id renames Args (4);
15608 Mechanism : Node_Id renames Args (5);
15609 Result_Mechanism : Node_Id renames Args (6);
15611 begin
15612 GNAT_Pragma;
15613 Gather_Associations (Names, Args);
15614 Process_Extended_Import_Export_Subprogram_Pragma (
15615 Arg_Internal => Internal,
15616 Arg_External => External,
15617 Arg_Parameter_Types => Parameter_Types,
15618 Arg_Result_Type => Result_Type,
15619 Arg_Mechanism => Mechanism,
15620 Arg_Result_Mechanism => Result_Mechanism);
15621 end Import_Function;
15623 -------------------
15624 -- Import_Object --
15625 -------------------
15627 -- pragma Import_Object (
15628 -- [Internal =>] LOCAL_NAME
15629 -- [, [External =>] EXTERNAL_SYMBOL]
15630 -- [, [Size =>] EXTERNAL_SYMBOL]);
15632 -- EXTERNAL_SYMBOL ::=
15633 -- IDENTIFIER
15634 -- | static_string_EXPRESSION
15636 when Pragma_Import_Object => Import_Object : declare
15637 Args : Args_List (1 .. 3);
15638 Names : constant Name_List (1 .. 3) := (
15639 Name_Internal,
15640 Name_External,
15641 Name_Size);
15643 Internal : Node_Id renames Args (1);
15644 External : Node_Id renames Args (2);
15645 Size : Node_Id renames Args (3);
15647 begin
15648 GNAT_Pragma;
15649 Gather_Associations (Names, Args);
15650 Process_Extended_Import_Export_Object_Pragma (
15651 Arg_Internal => Internal,
15652 Arg_External => External,
15653 Arg_Size => Size);
15654 end Import_Object;
15656 ----------------------
15657 -- Import_Procedure --
15658 ----------------------
15660 -- pragma Import_Procedure (
15661 -- [Internal =>] LOCAL_NAME
15662 -- [, [External =>] EXTERNAL_SYMBOL]
15663 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15664 -- [, [Mechanism =>] MECHANISM]);
15666 -- EXTERNAL_SYMBOL ::=
15667 -- IDENTIFIER
15668 -- | static_string_EXPRESSION
15670 -- PARAMETER_TYPES ::=
15671 -- null
15672 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15674 -- TYPE_DESIGNATOR ::=
15675 -- subtype_NAME
15676 -- | subtype_Name ' Access
15678 -- MECHANISM ::=
15679 -- MECHANISM_NAME
15680 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15682 -- MECHANISM_ASSOCIATION ::=
15683 -- [formal_parameter_NAME =>] MECHANISM_NAME
15685 -- MECHANISM_NAME ::=
15686 -- Value
15687 -- | Reference
15689 when Pragma_Import_Procedure => Import_Procedure : declare
15690 Args : Args_List (1 .. 4);
15691 Names : constant Name_List (1 .. 4) := (
15692 Name_Internal,
15693 Name_External,
15694 Name_Parameter_Types,
15695 Name_Mechanism);
15697 Internal : Node_Id renames Args (1);
15698 External : Node_Id renames Args (2);
15699 Parameter_Types : Node_Id renames Args (3);
15700 Mechanism : Node_Id renames Args (4);
15702 begin
15703 GNAT_Pragma;
15704 Gather_Associations (Names, Args);
15705 Process_Extended_Import_Export_Subprogram_Pragma (
15706 Arg_Internal => Internal,
15707 Arg_External => External,
15708 Arg_Parameter_Types => Parameter_Types,
15709 Arg_Mechanism => Mechanism);
15710 end Import_Procedure;
15712 -----------------------------
15713 -- Import_Valued_Procedure --
15714 -----------------------------
15716 -- pragma Import_Valued_Procedure (
15717 -- [Internal =>] LOCAL_NAME
15718 -- [, [External =>] EXTERNAL_SYMBOL]
15719 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15720 -- [, [Mechanism =>] MECHANISM]);
15722 -- EXTERNAL_SYMBOL ::=
15723 -- IDENTIFIER
15724 -- | static_string_EXPRESSION
15726 -- PARAMETER_TYPES ::=
15727 -- null
15728 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15730 -- TYPE_DESIGNATOR ::=
15731 -- subtype_NAME
15732 -- | subtype_Name ' Access
15734 -- MECHANISM ::=
15735 -- MECHANISM_NAME
15736 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15738 -- MECHANISM_ASSOCIATION ::=
15739 -- [formal_parameter_NAME =>] MECHANISM_NAME
15741 -- MECHANISM_NAME ::=
15742 -- Value
15743 -- | Reference
15745 when Pragma_Import_Valued_Procedure =>
15746 Import_Valued_Procedure : declare
15747 Args : Args_List (1 .. 4);
15748 Names : constant Name_List (1 .. 4) := (
15749 Name_Internal,
15750 Name_External,
15751 Name_Parameter_Types,
15752 Name_Mechanism);
15754 Internal : Node_Id renames Args (1);
15755 External : Node_Id renames Args (2);
15756 Parameter_Types : Node_Id renames Args (3);
15757 Mechanism : Node_Id renames Args (4);
15759 begin
15760 GNAT_Pragma;
15761 Gather_Associations (Names, Args);
15762 Process_Extended_Import_Export_Subprogram_Pragma (
15763 Arg_Internal => Internal,
15764 Arg_External => External,
15765 Arg_Parameter_Types => Parameter_Types,
15766 Arg_Mechanism => Mechanism);
15767 end Import_Valued_Procedure;
15769 -----------------
15770 -- Independent --
15771 -----------------
15773 -- pragma Independent (LOCAL_NAME);
15775 when Pragma_Independent =>
15776 Process_Atomic_Independent_Shared_Volatile;
15778 ----------------------------
15779 -- Independent_Components --
15780 ----------------------------
15782 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
15784 when Pragma_Independent_Components => Independent_Components : declare
15785 C : Node_Id;
15786 D : Node_Id;
15787 E_Id : Node_Id;
15788 E : Entity_Id;
15789 K : Node_Kind;
15791 begin
15792 Check_Ada_83_Warning;
15793 Ada_2012_Pragma;
15794 Check_No_Identifiers;
15795 Check_Arg_Count (1);
15796 Check_Arg_Is_Local_Name (Arg1);
15797 E_Id := Get_Pragma_Arg (Arg1);
15799 if Etype (E_Id) = Any_Type then
15800 return;
15801 end if;
15803 E := Entity (E_Id);
15805 -- A pragma that applies to a Ghost entity becomes Ghost for the
15806 -- purposes of legality checks and removal of ignored Ghost code.
15808 Mark_Pragma_As_Ghost (N, E);
15810 -- Check duplicate before we chain ourselves
15812 Check_Duplicate_Pragma (E);
15814 -- Check appropriate entity
15816 if Rep_Item_Too_Early (E, N)
15817 or else
15818 Rep_Item_Too_Late (E, N)
15819 then
15820 return;
15821 end if;
15823 D := Declaration_Node (E);
15824 K := Nkind (D);
15826 -- The flag is set on the base type, or on the object
15828 if K = N_Full_Type_Declaration
15829 and then (Is_Array_Type (E) or else Is_Record_Type (E))
15830 then
15831 Set_Has_Independent_Components (Base_Type (E));
15832 Record_Independence_Check (N, Base_Type (E));
15834 -- For record type, set all components independent
15836 if Is_Record_Type (E) then
15837 C := First_Component (E);
15838 while Present (C) loop
15839 Set_Is_Independent (C);
15840 Next_Component (C);
15841 end loop;
15842 end if;
15844 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
15845 and then Nkind (D) = N_Object_Declaration
15846 and then Nkind (Object_Definition (D)) =
15847 N_Constrained_Array_Definition
15848 then
15849 Set_Has_Independent_Components (E);
15850 Record_Independence_Check (N, E);
15852 else
15853 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
15854 end if;
15855 end Independent_Components;
15857 -----------------------
15858 -- Initial_Condition --
15859 -----------------------
15861 -- pragma Initial_Condition (boolean_EXPRESSION);
15863 -- Characteristics:
15865 -- * Analysis - The annotation undergoes initial checks to verify
15866 -- the legal placement and context. Secondary checks preanalyze the
15867 -- expression in:
15869 -- Analyze_Initial_Condition_In_Decl_Part
15871 -- * Expansion - The annotation is expanded during the expansion of
15872 -- the package body whose declaration is subject to the annotation
15873 -- as done in:
15875 -- Expand_Pragma_Initial_Condition
15877 -- * Template - The annotation utilizes the generic template of the
15878 -- related package declaration.
15880 -- * Globals - Capture of global references must occur after full
15881 -- analysis.
15883 -- * Instance - The annotation is instantiated automatically when
15884 -- the related generic package is instantiated.
15886 when Pragma_Initial_Condition => Initial_Condition : declare
15887 Pack_Decl : Node_Id;
15888 Pack_Id : Entity_Id;
15890 begin
15891 GNAT_Pragma;
15892 Check_No_Identifiers;
15893 Check_Arg_Count (1);
15895 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
15897 -- Ensure the proper placement of the pragma. Initial_Condition
15898 -- must be associated with a package declaration.
15900 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
15901 N_Package_Declaration)
15902 then
15903 null;
15905 -- Otherwise the pragma is associated with an illegal context
15907 else
15908 Pragma_Misplaced;
15909 return;
15910 end if;
15912 Pack_Id := Defining_Entity (Pack_Decl);
15914 -- Chain the pragma on the contract for further processing by
15915 -- Analyze_Initial_Condition_In_Decl_Part.
15917 Add_Contract_Item (N, Pack_Id);
15919 -- The legality checks of pragmas Abstract_State, Initializes, and
15920 -- Initial_Condition are affected by the SPARK mode in effect. In
15921 -- addition, these three pragmas are subject to an inherent order:
15923 -- 1) Abstract_State
15924 -- 2) Initializes
15925 -- 3) Initial_Condition
15927 -- Analyze all these pragmas in the order outlined above
15929 Analyze_If_Present (Pragma_SPARK_Mode);
15930 Analyze_If_Present (Pragma_Abstract_State);
15931 Analyze_If_Present (Pragma_Initializes);
15933 -- A pragma that applies to a Ghost entity becomes Ghost for the
15934 -- purposes of legality checks and removal of ignored Ghost code.
15936 Mark_Pragma_As_Ghost (N, Pack_Id);
15937 end Initial_Condition;
15939 ------------------------
15940 -- Initialize_Scalars --
15941 ------------------------
15943 -- pragma Initialize_Scalars;
15945 when Pragma_Initialize_Scalars =>
15946 GNAT_Pragma;
15947 Check_Arg_Count (0);
15948 Check_Valid_Configuration_Pragma;
15949 Check_Restriction (No_Initialize_Scalars, N);
15951 -- Initialize_Scalars creates false positives in CodePeer, and
15952 -- incorrect negative results in GNATprove mode, so ignore this
15953 -- pragma in these modes.
15955 if not Restriction_Active (No_Initialize_Scalars)
15956 and then not (CodePeer_Mode or GNATprove_Mode)
15957 then
15958 Init_Or_Norm_Scalars := True;
15959 Initialize_Scalars := True;
15960 end if;
15962 -----------------
15963 -- Initializes --
15964 -----------------
15966 -- pragma Initializes (INITIALIZATION_LIST);
15968 -- INITIALIZATION_LIST ::=
15969 -- null
15970 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
15972 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
15974 -- INPUT_LIST ::=
15975 -- null
15976 -- | INPUT
15977 -- | (INPUT {, INPUT})
15979 -- INPUT ::= name
15981 -- Characteristics:
15983 -- * Analysis - The annotation undergoes initial checks to verify
15984 -- the legal placement and context. Secondary checks preanalyze the
15985 -- expression in:
15987 -- Analyze_Initializes_In_Decl_Part
15989 -- * Expansion - None.
15991 -- * Template - The annotation utilizes the generic template of the
15992 -- related package declaration.
15994 -- * Globals - Capture of global references must occur after full
15995 -- analysis.
15997 -- * Instance - The annotation is instantiated automatically when
15998 -- the related generic package is instantiated.
16000 when Pragma_Initializes => Initializes : declare
16001 Pack_Decl : Node_Id;
16002 Pack_Id : Entity_Id;
16004 begin
16005 GNAT_Pragma;
16006 Check_No_Identifiers;
16007 Check_Arg_Count (1);
16009 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
16011 -- Ensure the proper placement of the pragma. Initializes must be
16012 -- associated with a package declaration.
16014 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
16015 N_Package_Declaration)
16016 then
16017 null;
16019 -- Otherwise the pragma is associated with an illegal construc
16021 else
16022 Pragma_Misplaced;
16023 return;
16024 end if;
16026 Pack_Id := Defining_Entity (Pack_Decl);
16028 -- Chain the pragma on the contract for further processing by
16029 -- Analyze_Initializes_In_Decl_Part.
16031 Add_Contract_Item (N, Pack_Id);
16033 -- The legality checks of pragmas Abstract_State, Initializes, and
16034 -- Initial_Condition are affected by the SPARK mode in effect. In
16035 -- addition, these three pragmas are subject to an inherent order:
16037 -- 1) Abstract_State
16038 -- 2) Initializes
16039 -- 3) Initial_Condition
16041 -- Analyze all these pragmas in the order outlined above
16043 Analyze_If_Present (Pragma_SPARK_Mode);
16044 Analyze_If_Present (Pragma_Abstract_State);
16046 -- A pragma that applies to a Ghost entity becomes Ghost for the
16047 -- purposes of legality checks and removal of ignored Ghost code.
16049 Mark_Pragma_As_Ghost (N, Pack_Id);
16050 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
16052 Analyze_If_Present (Pragma_Initial_Condition);
16053 end Initializes;
16055 ------------
16056 -- Inline --
16057 ------------
16059 -- pragma Inline ( NAME {, NAME} );
16061 when Pragma_Inline =>
16063 -- Pragma always active unless in GNATprove mode. It is disabled
16064 -- in GNATprove mode because frontend inlining is applied
16065 -- independently of pragmas Inline and Inline_Always for
16066 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
16067 -- in inline.ads.
16069 if not GNATprove_Mode then
16071 -- Inline status is Enabled if inlining option is active
16073 if Inline_Active then
16074 Process_Inline (Enabled);
16075 else
16076 Process_Inline (Disabled);
16077 end if;
16078 end if;
16080 -------------------
16081 -- Inline_Always --
16082 -------------------
16084 -- pragma Inline_Always ( NAME {, NAME} );
16086 when Pragma_Inline_Always =>
16087 GNAT_Pragma;
16089 -- Pragma always active unless in CodePeer mode or GNATprove
16090 -- mode. It is disabled in CodePeer mode because inlining is
16091 -- not helpful, and enabling it caused walk order issues. It
16092 -- is disabled in GNATprove mode because frontend inlining is
16093 -- applied independently of pragmas Inline and Inline_Always for
16094 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
16095 -- inline.ads.
16097 if not CodePeer_Mode and not GNATprove_Mode then
16098 Process_Inline (Enabled);
16099 end if;
16101 --------------------
16102 -- Inline_Generic --
16103 --------------------
16105 -- pragma Inline_Generic (NAME {, NAME});
16107 when Pragma_Inline_Generic =>
16108 GNAT_Pragma;
16109 Process_Generic_List;
16111 ----------------------
16112 -- Inspection_Point --
16113 ----------------------
16115 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
16117 when Pragma_Inspection_Point => Inspection_Point : declare
16118 Arg : Node_Id;
16119 Exp : Node_Id;
16121 begin
16124 if Arg_Count > 0 then
16125 Arg := Arg1;
16126 loop
16127 Exp := Get_Pragma_Arg (Arg);
16128 Analyze (Exp);
16130 if not Is_Entity_Name (Exp)
16131 or else not Is_Object (Entity (Exp))
16132 then
16133 Error_Pragma_Arg ("object name required", Arg);
16134 end if;
16136 Next (Arg);
16137 exit when No (Arg);
16138 end loop;
16139 end if;
16140 end Inspection_Point;
16142 ---------------
16143 -- Interface --
16144 ---------------
16146 -- pragma Interface (
16147 -- [ Convention =>] convention_IDENTIFIER,
16148 -- [ Entity =>] LOCAL_NAME
16149 -- [, [External_Name =>] static_string_EXPRESSION ]
16150 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16152 when Pragma_Interface =>
16153 GNAT_Pragma;
16154 Check_Arg_Order
16155 ((Name_Convention,
16156 Name_Entity,
16157 Name_External_Name,
16158 Name_Link_Name));
16159 Check_At_Least_N_Arguments (2);
16160 Check_At_Most_N_Arguments (4);
16161 Process_Import_Or_Interface;
16163 -- In Ada 2005, the permission to use Interface (a reserved word)
16164 -- as a pragma name is considered an obsolescent feature, and this
16165 -- pragma was already obsolescent in Ada 95.
16167 if Ada_Version >= Ada_95 then
16168 Check_Restriction
16169 (No_Obsolescent_Features, Pragma_Identifier (N));
16171 if Warn_On_Obsolescent_Feature then
16172 Error_Msg_N
16173 ("pragma Interface is an obsolescent feature?j?", N);
16174 Error_Msg_N
16175 ("|use pragma Import instead?j?", N);
16176 end if;
16177 end if;
16179 --------------------
16180 -- Interface_Name --
16181 --------------------
16183 -- pragma Interface_Name (
16184 -- [ Entity =>] LOCAL_NAME
16185 -- [,[External_Name =>] static_string_EXPRESSION ]
16186 -- [,[Link_Name =>] static_string_EXPRESSION ]);
16188 when Pragma_Interface_Name => Interface_Name : declare
16189 Id : Node_Id;
16190 Def_Id : Entity_Id;
16191 Hom_Id : Entity_Id;
16192 Found : Boolean;
16194 begin
16195 GNAT_Pragma;
16196 Check_Arg_Order
16197 ((Name_Entity, Name_External_Name, Name_Link_Name));
16198 Check_At_Least_N_Arguments (2);
16199 Check_At_Most_N_Arguments (3);
16200 Id := Get_Pragma_Arg (Arg1);
16201 Analyze (Id);
16203 -- This is obsolete from Ada 95 on, but it is an implementation
16204 -- defined pragma, so we do not consider that it violates the
16205 -- restriction (No_Obsolescent_Features).
16207 if Ada_Version >= Ada_95 then
16208 if Warn_On_Obsolescent_Feature then
16209 Error_Msg_N
16210 ("pragma Interface_Name is an obsolescent feature?j?", N);
16211 Error_Msg_N
16212 ("|use pragma Import instead?j?", N);
16213 end if;
16214 end if;
16216 if not Is_Entity_Name (Id) then
16217 Error_Pragma_Arg
16218 ("first argument for pragma% must be entity name", Arg1);
16219 elsif Etype (Id) = Any_Type then
16220 return;
16221 else
16222 Def_Id := Entity (Id);
16223 end if;
16225 -- Special DEC-compatible processing for the object case, forces
16226 -- object to be imported.
16228 if Ekind (Def_Id) = E_Variable then
16229 Kill_Size_Check_Code (Def_Id);
16230 Note_Possible_Modification (Id, Sure => False);
16232 -- Initialization is not allowed for imported variable
16234 if Present (Expression (Parent (Def_Id)))
16235 and then Comes_From_Source (Expression (Parent (Def_Id)))
16236 then
16237 Error_Msg_Sloc := Sloc (Def_Id);
16238 Error_Pragma_Arg
16239 ("no initialization allowed for declaration of& #",
16240 Arg2);
16242 else
16243 -- For compatibility, support VADS usage of providing both
16244 -- pragmas Interface and Interface_Name to obtain the effect
16245 -- of a single Import pragma.
16247 if Is_Imported (Def_Id)
16248 and then Present (First_Rep_Item (Def_Id))
16249 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
16250 and then
16251 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
16252 then
16253 null;
16254 else
16255 Set_Imported (Def_Id);
16256 end if;
16258 Set_Is_Public (Def_Id);
16259 Process_Interface_Name (Def_Id, Arg2, Arg3);
16260 end if;
16262 -- Otherwise must be subprogram
16264 elsif not Is_Subprogram (Def_Id) then
16265 Error_Pragma_Arg
16266 ("argument of pragma% is not subprogram", Arg1);
16268 else
16269 Check_At_Most_N_Arguments (3);
16270 Hom_Id := Def_Id;
16271 Found := False;
16273 -- Loop through homonyms
16275 loop
16276 Def_Id := Get_Base_Subprogram (Hom_Id);
16278 if Is_Imported (Def_Id) then
16279 Process_Interface_Name (Def_Id, Arg2, Arg3);
16280 Found := True;
16281 end if;
16283 exit when From_Aspect_Specification (N);
16284 Hom_Id := Homonym (Hom_Id);
16286 exit when No (Hom_Id)
16287 or else Scope (Hom_Id) /= Current_Scope;
16288 end loop;
16290 if not Found then
16291 Error_Pragma_Arg
16292 ("argument of pragma% is not imported subprogram",
16293 Arg1);
16294 end if;
16295 end if;
16296 end Interface_Name;
16298 -----------------------
16299 -- Interrupt_Handler --
16300 -----------------------
16302 -- pragma Interrupt_Handler (handler_NAME);
16304 when Pragma_Interrupt_Handler =>
16305 Check_Ada_83_Warning;
16306 Check_Arg_Count (1);
16307 Check_No_Identifiers;
16309 if No_Run_Time_Mode then
16310 Error_Msg_CRT ("Interrupt_Handler pragma", N);
16311 else
16312 Check_Interrupt_Or_Attach_Handler;
16313 Process_Interrupt_Or_Attach_Handler;
16314 end if;
16316 ------------------------
16317 -- Interrupt_Priority --
16318 ------------------------
16320 -- pragma Interrupt_Priority [(EXPRESSION)];
16322 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
16323 P : constant Node_Id := Parent (N);
16324 Arg : Node_Id;
16325 Ent : Entity_Id;
16327 begin
16328 Check_Ada_83_Warning;
16330 if Arg_Count /= 0 then
16331 Arg := Get_Pragma_Arg (Arg1);
16332 Check_Arg_Count (1);
16333 Check_No_Identifiers;
16335 -- The expression must be analyzed in the special manner
16336 -- described in "Handling of Default and Per-Object
16337 -- Expressions" in sem.ads.
16339 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
16340 end if;
16342 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
16343 Pragma_Misplaced;
16344 return;
16346 else
16347 Ent := Defining_Identifier (Parent (P));
16349 -- Check duplicate pragma before we chain the pragma in the Rep
16350 -- Item chain of Ent.
16352 Check_Duplicate_Pragma (Ent);
16353 Record_Rep_Item (Ent, N);
16355 -- Check the No_Task_At_Interrupt_Priority restriction
16357 if Nkind (P) = N_Task_Definition then
16358 Check_Restriction (No_Task_At_Interrupt_Priority, N);
16359 end if;
16360 end if;
16361 end Interrupt_Priority;
16363 ---------------------
16364 -- Interrupt_State --
16365 ---------------------
16367 -- pragma Interrupt_State (
16368 -- [Name =>] INTERRUPT_ID,
16369 -- [State =>] INTERRUPT_STATE);
16371 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
16372 -- INTERRUPT_STATE => System | Runtime | User
16374 -- Note: if the interrupt id is given as an identifier, then it must
16375 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
16376 -- given as a static integer expression which must be in the range of
16377 -- Ada.Interrupts.Interrupt_ID.
16379 when Pragma_Interrupt_State => Interrupt_State : declare
16380 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
16381 -- This is the entity Ada.Interrupts.Interrupt_ID;
16383 State_Type : Character;
16384 -- Set to 's'/'r'/'u' for System/Runtime/User
16386 IST_Num : Pos;
16387 -- Index to entry in Interrupt_States table
16389 Int_Val : Uint;
16390 -- Value of interrupt
16392 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
16393 -- The first argument to the pragma
16395 Int_Ent : Entity_Id;
16396 -- Interrupt entity in Ada.Interrupts.Names
16398 begin
16399 GNAT_Pragma;
16400 Check_Arg_Order ((Name_Name, Name_State));
16401 Check_Arg_Count (2);
16403 Check_Optional_Identifier (Arg1, Name_Name);
16404 Check_Optional_Identifier (Arg2, Name_State);
16405 Check_Arg_Is_Identifier (Arg2);
16407 -- First argument is identifier
16409 if Nkind (Arg1X) = N_Identifier then
16411 -- Search list of names in Ada.Interrupts.Names
16413 Int_Ent := First_Entity (RTE (RE_Names));
16414 loop
16415 if No (Int_Ent) then
16416 Error_Pragma_Arg ("invalid interrupt name", Arg1);
16418 elsif Chars (Int_Ent) = Chars (Arg1X) then
16419 Int_Val := Expr_Value (Constant_Value (Int_Ent));
16420 exit;
16421 end if;
16423 Next_Entity (Int_Ent);
16424 end loop;
16426 -- First argument is not an identifier, so it must be a static
16427 -- expression of type Ada.Interrupts.Interrupt_ID.
16429 else
16430 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
16431 Int_Val := Expr_Value (Arg1X);
16433 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
16434 or else
16435 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
16436 then
16437 Error_Pragma_Arg
16438 ("value not in range of type "
16439 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
16440 end if;
16441 end if;
16443 -- Check OK state
16445 case Chars (Get_Pragma_Arg (Arg2)) is
16446 when Name_Runtime => State_Type := 'r';
16447 when Name_System => State_Type := 's';
16448 when Name_User => State_Type := 'u';
16450 when others =>
16451 Error_Pragma_Arg ("invalid interrupt state", Arg2);
16452 end case;
16454 -- Check if entry is already stored
16456 IST_Num := Interrupt_States.First;
16457 loop
16458 -- If entry not found, add it
16460 if IST_Num > Interrupt_States.Last then
16461 Interrupt_States.Append
16462 ((Interrupt_Number => UI_To_Int (Int_Val),
16463 Interrupt_State => State_Type,
16464 Pragma_Loc => Loc));
16465 exit;
16467 -- Case of entry for the same entry
16469 elsif Int_Val = Interrupt_States.Table (IST_Num).
16470 Interrupt_Number
16471 then
16472 -- If state matches, done, no need to make redundant entry
16474 exit when
16475 State_Type = Interrupt_States.Table (IST_Num).
16476 Interrupt_State;
16478 -- Otherwise if state does not match, error
16480 Error_Msg_Sloc :=
16481 Interrupt_States.Table (IST_Num).Pragma_Loc;
16482 Error_Pragma_Arg
16483 ("state conflicts with that given #", Arg2);
16484 exit;
16485 end if;
16487 IST_Num := IST_Num + 1;
16488 end loop;
16489 end Interrupt_State;
16491 ---------------
16492 -- Invariant --
16493 ---------------
16495 -- pragma Invariant
16496 -- ([Entity =>] type_LOCAL_NAME,
16497 -- [Check =>] EXPRESSION
16498 -- [,[Message =>] String_Expression]);
16500 when Pragma_Invariant => Invariant : declare
16501 Discard : Boolean;
16502 Typ : Entity_Id;
16503 Type_Id : Node_Id;
16505 begin
16506 GNAT_Pragma;
16507 Check_At_Least_N_Arguments (2);
16508 Check_At_Most_N_Arguments (3);
16509 Check_Optional_Identifier (Arg1, Name_Entity);
16510 Check_Optional_Identifier (Arg2, Name_Check);
16512 if Arg_Count = 3 then
16513 Check_Optional_Identifier (Arg3, Name_Message);
16514 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
16515 end if;
16517 Check_Arg_Is_Local_Name (Arg1);
16519 Type_Id := Get_Pragma_Arg (Arg1);
16520 Find_Type (Type_Id);
16521 Typ := Entity (Type_Id);
16523 if Typ = Any_Type then
16524 return;
16526 -- Invariants allowed in interface types (RM 7.3.2(3/3))
16528 elsif Is_Interface (Typ) then
16529 null;
16531 -- An invariant must apply to a private type, or appear in the
16532 -- private part of a package spec and apply to a completion.
16533 -- a class-wide invariant can only appear on a private declaration
16534 -- or private extension, not a completion.
16536 elsif Ekind_In (Typ, E_Private_Type,
16537 E_Record_Type_With_Private,
16538 E_Limited_Private_Type)
16539 then
16540 null;
16542 elsif In_Private_Part (Current_Scope)
16543 and then Has_Private_Declaration (Typ)
16544 and then not Class_Present (N)
16545 then
16546 null;
16548 elsif In_Private_Part (Current_Scope) then
16549 Error_Pragma_Arg
16550 ("pragma% only allowed for private type declared in "
16551 & "visible part", Arg1);
16553 else
16554 Error_Pragma_Arg
16555 ("pragma% only allowed for private type", Arg1);
16556 end if;
16558 -- A pragma that applies to a Ghost entity becomes Ghost for the
16559 -- purposes of legality checks and removal of ignored Ghost code.
16561 Mark_Pragma_As_Ghost (N, Typ);
16563 -- Not allowed for abstract type in the non-class case (it is
16564 -- allowed to use Invariant'Class for abstract types).
16566 if Is_Abstract_Type (Typ) and then not Class_Present (N) then
16567 Error_Pragma_Arg
16568 ("pragma% not allowed for abstract type", Arg1);
16569 end if;
16571 -- Link the pragma on to the rep item chain, for processing when
16572 -- the type is frozen.
16574 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
16576 -- Note that the type has at least one invariant, and also that
16577 -- it has inheritable invariants if we have Invariant'Class
16578 -- or Type_Invariant'Class. Build the corresponding invariant
16579 -- procedure declaration, so that calls to it can be generated
16580 -- before the body is built (e.g. within an expression function).
16582 -- Interface types have no invariant procedure; their invariants
16583 -- are propagated to the build invariant procedure of all the
16584 -- types covering the interface type.
16586 if not Is_Interface (Typ) then
16587 Insert_After_And_Analyze
16588 (N, Build_Invariant_Procedure_Declaration (Typ));
16589 end if;
16591 if Class_Present (N) then
16592 Set_Has_Inheritable_Invariants (Typ);
16593 end if;
16594 end Invariant;
16596 ----------------
16597 -- Keep_Names --
16598 ----------------
16600 -- pragma Keep_Names ([On => ] LOCAL_NAME);
16602 when Pragma_Keep_Names => Keep_Names : declare
16603 Arg : Node_Id;
16605 begin
16606 GNAT_Pragma;
16607 Check_Arg_Count (1);
16608 Check_Optional_Identifier (Arg1, Name_On);
16609 Check_Arg_Is_Local_Name (Arg1);
16611 Arg := Get_Pragma_Arg (Arg1);
16612 Analyze (Arg);
16614 if Etype (Arg) = Any_Type then
16615 return;
16616 end if;
16618 if not Is_Entity_Name (Arg)
16619 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
16620 then
16621 Error_Pragma_Arg
16622 ("pragma% requires a local enumeration type", Arg1);
16623 end if;
16625 Set_Discard_Names (Entity (Arg), False);
16626 end Keep_Names;
16628 -------------
16629 -- License --
16630 -------------
16632 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
16634 when Pragma_License =>
16635 GNAT_Pragma;
16637 -- Do not analyze pragma any further in CodePeer mode, to avoid
16638 -- extraneous errors in this implementation-dependent pragma,
16639 -- which has a different profile on other compilers.
16641 if CodePeer_Mode then
16642 return;
16643 end if;
16645 Check_Arg_Count (1);
16646 Check_No_Identifiers;
16647 Check_Valid_Configuration_Pragma;
16648 Check_Arg_Is_Identifier (Arg1);
16650 declare
16651 Sind : constant Source_File_Index :=
16652 Source_Index (Current_Sem_Unit);
16654 begin
16655 case Chars (Get_Pragma_Arg (Arg1)) is
16656 when Name_GPL =>
16657 Set_License (Sind, GPL);
16659 when Name_Modified_GPL =>
16660 Set_License (Sind, Modified_GPL);
16662 when Name_Restricted =>
16663 Set_License (Sind, Restricted);
16665 when Name_Unrestricted =>
16666 Set_License (Sind, Unrestricted);
16668 when others =>
16669 Error_Pragma_Arg ("invalid license name", Arg1);
16670 end case;
16671 end;
16673 ---------------
16674 -- Link_With --
16675 ---------------
16677 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
16679 when Pragma_Link_With => Link_With : declare
16680 Arg : Node_Id;
16682 begin
16683 GNAT_Pragma;
16685 if Operating_Mode = Generate_Code
16686 and then In_Extended_Main_Source_Unit (N)
16687 then
16688 Check_At_Least_N_Arguments (1);
16689 Check_No_Identifiers;
16690 Check_Is_In_Decl_Part_Or_Package_Spec;
16691 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
16692 Start_String;
16694 Arg := Arg1;
16695 while Present (Arg) loop
16696 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
16698 -- Store argument, converting sequences of spaces to a
16699 -- single null character (this is one of the differences
16700 -- in processing between Link_With and Linker_Options).
16702 Arg_Store : declare
16703 C : constant Char_Code := Get_Char_Code (' ');
16704 S : constant String_Id :=
16705 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
16706 L : constant Nat := String_Length (S);
16707 F : Nat := 1;
16709 procedure Skip_Spaces;
16710 -- Advance F past any spaces
16712 -----------------
16713 -- Skip_Spaces --
16714 -----------------
16716 procedure Skip_Spaces is
16717 begin
16718 while F <= L and then Get_String_Char (S, F) = C loop
16719 F := F + 1;
16720 end loop;
16721 end Skip_Spaces;
16723 -- Start of processing for Arg_Store
16725 begin
16726 Skip_Spaces; -- skip leading spaces
16728 -- Loop through characters, changing any embedded
16729 -- sequence of spaces to a single null character (this
16730 -- is how Link_With/Linker_Options differ)
16732 while F <= L loop
16733 if Get_String_Char (S, F) = C then
16734 Skip_Spaces;
16735 exit when F > L;
16736 Store_String_Char (ASCII.NUL);
16738 else
16739 Store_String_Char (Get_String_Char (S, F));
16740 F := F + 1;
16741 end if;
16742 end loop;
16743 end Arg_Store;
16745 Arg := Next (Arg);
16747 if Present (Arg) then
16748 Store_String_Char (ASCII.NUL);
16749 end if;
16750 end loop;
16752 Store_Linker_Option_String (End_String);
16753 end if;
16754 end Link_With;
16756 ------------------
16757 -- Linker_Alias --
16758 ------------------
16760 -- pragma Linker_Alias (
16761 -- [Entity =>] LOCAL_NAME
16762 -- [Target =>] static_string_EXPRESSION);
16764 when Pragma_Linker_Alias =>
16765 GNAT_Pragma;
16766 Check_Arg_Order ((Name_Entity, Name_Target));
16767 Check_Arg_Count (2);
16768 Check_Optional_Identifier (Arg1, Name_Entity);
16769 Check_Optional_Identifier (Arg2, Name_Target);
16770 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16771 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16773 -- The only processing required is to link this item on to the
16774 -- list of rep items for the given entity. This is accomplished
16775 -- by the call to Rep_Item_Too_Late (when no error is detected
16776 -- and False is returned).
16778 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
16779 return;
16780 else
16781 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
16782 end if;
16784 ------------------------
16785 -- Linker_Constructor --
16786 ------------------------
16788 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
16790 -- Code is shared with Linker_Destructor
16792 -----------------------
16793 -- Linker_Destructor --
16794 -----------------------
16796 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
16798 when Pragma_Linker_Constructor |
16799 Pragma_Linker_Destructor =>
16800 Linker_Constructor : declare
16801 Arg1_X : Node_Id;
16802 Proc : Entity_Id;
16804 begin
16805 GNAT_Pragma;
16806 Check_Arg_Count (1);
16807 Check_No_Identifiers;
16808 Check_Arg_Is_Local_Name (Arg1);
16809 Arg1_X := Get_Pragma_Arg (Arg1);
16810 Analyze (Arg1_X);
16811 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
16813 if not Is_Library_Level_Entity (Proc) then
16814 Error_Pragma_Arg
16815 ("argument for pragma% must be library level entity", Arg1);
16816 end if;
16818 -- The only processing required is to link this item on to the
16819 -- list of rep items for the given entity. This is accomplished
16820 -- by the call to Rep_Item_Too_Late (when no error is detected
16821 -- and False is returned).
16823 if Rep_Item_Too_Late (Proc, N) then
16824 return;
16825 else
16826 Set_Has_Gigi_Rep_Item (Proc);
16827 end if;
16828 end Linker_Constructor;
16830 --------------------
16831 -- Linker_Options --
16832 --------------------
16834 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
16836 when Pragma_Linker_Options => Linker_Options : declare
16837 Arg : Node_Id;
16839 begin
16840 Check_Ada_83_Warning;
16841 Check_No_Identifiers;
16842 Check_Arg_Count (1);
16843 Check_Is_In_Decl_Part_Or_Package_Spec;
16844 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
16845 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
16847 Arg := Arg2;
16848 while Present (Arg) loop
16849 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
16850 Store_String_Char (ASCII.NUL);
16851 Store_String_Chars
16852 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
16853 Arg := Next (Arg);
16854 end loop;
16856 if Operating_Mode = Generate_Code
16857 and then In_Extended_Main_Source_Unit (N)
16858 then
16859 Store_Linker_Option_String (End_String);
16860 end if;
16861 end Linker_Options;
16863 --------------------
16864 -- Linker_Section --
16865 --------------------
16867 -- pragma Linker_Section (
16868 -- [Entity =>] LOCAL_NAME
16869 -- [Section =>] static_string_EXPRESSION);
16871 when Pragma_Linker_Section => Linker_Section : declare
16872 Arg : Node_Id;
16873 Ent : Entity_Id;
16874 LPE : Node_Id;
16876 Ghost_Error_Posted : Boolean := False;
16877 -- Flag set when an error concerning the illegal mix of Ghost and
16878 -- non-Ghost subprograms is emitted.
16880 Ghost_Id : Entity_Id := Empty;
16881 -- The entity of the first Ghost subprogram encountered while
16882 -- processing the arguments of the pragma.
16884 begin
16885 GNAT_Pragma;
16886 Check_Arg_Order ((Name_Entity, Name_Section));
16887 Check_Arg_Count (2);
16888 Check_Optional_Identifier (Arg1, Name_Entity);
16889 Check_Optional_Identifier (Arg2, Name_Section);
16890 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16891 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16893 -- Check kind of entity
16895 Arg := Get_Pragma_Arg (Arg1);
16896 Ent := Entity (Arg);
16898 case Ekind (Ent) is
16900 -- Objects (constants and variables) and types. For these cases
16901 -- all we need to do is to set the Linker_Section_pragma field,
16902 -- checking that we do not have a duplicate.
16904 when E_Constant | E_Variable | Type_Kind =>
16905 LPE := Linker_Section_Pragma (Ent);
16907 if Present (LPE) then
16908 Error_Msg_Sloc := Sloc (LPE);
16909 Error_Msg_NE
16910 ("Linker_Section already specified for &#", Arg1, Ent);
16911 end if;
16913 Set_Linker_Section_Pragma (Ent, N);
16915 -- A pragma that applies to a Ghost entity becomes Ghost for
16916 -- the purposes of legality checks and removal of ignored
16917 -- Ghost code.
16919 Mark_Pragma_As_Ghost (N, Ent);
16921 -- Subprograms
16923 when Subprogram_Kind =>
16925 -- Aspect case, entity already set
16927 if From_Aspect_Specification (N) then
16928 Set_Linker_Section_Pragma
16929 (Entity (Corresponding_Aspect (N)), N);
16931 -- Pragma case, we must climb the homonym chain, but skip
16932 -- any for which the linker section is already set.
16934 else
16935 loop
16936 if No (Linker_Section_Pragma (Ent)) then
16937 Set_Linker_Section_Pragma (Ent, N);
16939 -- A pragma that applies to a Ghost entity becomes
16940 -- Ghost for the purposes of legality checks and
16941 -- removal of ignored Ghost code.
16943 Mark_Pragma_As_Ghost (N, Ent);
16945 -- Capture the entity of the first Ghost subprogram
16946 -- being processed for error detection purposes.
16948 if Is_Ghost_Entity (Ent) then
16949 if No (Ghost_Id) then
16950 Ghost_Id := Ent;
16951 end if;
16953 -- Otherwise the subprogram is non-Ghost. It is
16954 -- illegal to mix references to Ghost and non-Ghost
16955 -- entities (SPARK RM 6.9).
16957 elsif Present (Ghost_Id)
16958 and then not Ghost_Error_Posted
16959 then
16960 Ghost_Error_Posted := True;
16962 Error_Msg_Name_1 := Pname;
16963 Error_Msg_N
16964 ("pragma % cannot mention ghost and "
16965 & "non-ghost subprograms", N);
16967 Error_Msg_Sloc := Sloc (Ghost_Id);
16968 Error_Msg_NE
16969 ("\& # declared as ghost", N, Ghost_Id);
16971 Error_Msg_Sloc := Sloc (Ent);
16972 Error_Msg_NE
16973 ("\& # declared as non-ghost", N, Ent);
16974 end if;
16975 end if;
16977 Ent := Homonym (Ent);
16978 exit when No (Ent)
16979 or else Scope (Ent) /= Current_Scope;
16980 end loop;
16981 end if;
16983 -- All other cases are illegal
16985 when others =>
16986 Error_Pragma_Arg
16987 ("pragma% applies only to objects, subprograms, and types",
16988 Arg1);
16989 end case;
16990 end Linker_Section;
16992 ----------
16993 -- List --
16994 ----------
16996 -- pragma List (On | Off)
16998 -- There is nothing to do here, since we did all the processing for
16999 -- this pragma in Par.Prag (so that it works properly even in syntax
17000 -- only mode).
17002 when Pragma_List =>
17003 null;
17005 ---------------
17006 -- Lock_Free --
17007 ---------------
17009 -- pragma Lock_Free [(Boolean_EXPRESSION)];
17011 when Pragma_Lock_Free => Lock_Free : declare
17012 P : constant Node_Id := Parent (N);
17013 Arg : Node_Id;
17014 Ent : Entity_Id;
17015 Val : Boolean;
17017 begin
17018 Check_No_Identifiers;
17019 Check_At_Most_N_Arguments (1);
17021 -- Protected definition case
17023 if Nkind (P) = N_Protected_Definition then
17024 Ent := Defining_Identifier (Parent (P));
17026 -- One argument
17028 if Arg_Count = 1 then
17029 Arg := Get_Pragma_Arg (Arg1);
17030 Val := Is_True (Static_Boolean (Arg));
17032 -- No arguments (expression is considered to be True)
17034 else
17035 Val := True;
17036 end if;
17038 -- Check duplicate pragma before we chain the pragma in the Rep
17039 -- Item chain of Ent.
17041 Check_Duplicate_Pragma (Ent);
17042 Record_Rep_Item (Ent, N);
17043 Set_Uses_Lock_Free (Ent, Val);
17045 -- Anything else is incorrect placement
17047 else
17048 Pragma_Misplaced;
17049 end if;
17050 end Lock_Free;
17052 --------------------
17053 -- Locking_Policy --
17054 --------------------
17056 -- pragma Locking_Policy (policy_IDENTIFIER);
17058 when Pragma_Locking_Policy => declare
17059 subtype LP_Range is Name_Id
17060 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
17061 LP_Val : LP_Range;
17062 LP : Character;
17064 begin
17065 Check_Ada_83_Warning;
17066 Check_Arg_Count (1);
17067 Check_No_Identifiers;
17068 Check_Arg_Is_Locking_Policy (Arg1);
17069 Check_Valid_Configuration_Pragma;
17070 LP_Val := Chars (Get_Pragma_Arg (Arg1));
17072 case LP_Val is
17073 when Name_Ceiling_Locking =>
17074 LP := 'C';
17075 when Name_Inheritance_Locking =>
17076 LP := 'I';
17077 when Name_Concurrent_Readers_Locking =>
17078 LP := 'R';
17079 end case;
17081 if Locking_Policy /= ' '
17082 and then Locking_Policy /= LP
17083 then
17084 Error_Msg_Sloc := Locking_Policy_Sloc;
17085 Error_Pragma ("locking policy incompatible with policy#");
17087 -- Set new policy, but always preserve System_Location since we
17088 -- like the error message with the run time name.
17090 else
17091 Locking_Policy := LP;
17093 if Locking_Policy_Sloc /= System_Location then
17094 Locking_Policy_Sloc := Loc;
17095 end if;
17096 end if;
17097 end;
17099 -------------------
17100 -- Loop_Optimize --
17101 -------------------
17103 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
17105 -- OPTIMIZATION_HINT ::=
17106 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
17108 when Pragma_Loop_Optimize => Loop_Optimize : declare
17109 Hint : Node_Id;
17111 begin
17112 GNAT_Pragma;
17113 Check_At_Least_N_Arguments (1);
17114 Check_No_Identifiers;
17116 Hint := First (Pragma_Argument_Associations (N));
17117 while Present (Hint) loop
17118 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
17119 Name_No_Unroll,
17120 Name_Unroll,
17121 Name_No_Vector,
17122 Name_Vector);
17123 Next (Hint);
17124 end loop;
17126 Check_Loop_Pragma_Placement;
17127 end Loop_Optimize;
17129 ------------------
17130 -- Loop_Variant --
17131 ------------------
17133 -- pragma Loop_Variant
17134 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
17136 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
17138 -- CHANGE_DIRECTION ::= Increases | Decreases
17140 when Pragma_Loop_Variant => Loop_Variant : declare
17141 Variant : Node_Id;
17143 begin
17144 GNAT_Pragma;
17145 Check_At_Least_N_Arguments (1);
17146 Check_Loop_Pragma_Placement;
17148 -- Process all increasing / decreasing expressions
17150 Variant := First (Pragma_Argument_Associations (N));
17151 while Present (Variant) loop
17152 if not Nam_In (Chars (Variant), Name_Decreases,
17153 Name_Increases)
17154 then
17155 Error_Pragma_Arg ("wrong change modifier", Variant);
17156 end if;
17158 Preanalyze_Assert_Expression
17159 (Expression (Variant), Any_Discrete);
17161 Next (Variant);
17162 end loop;
17163 end Loop_Variant;
17165 -----------------------
17166 -- Machine_Attribute --
17167 -----------------------
17169 -- pragma Machine_Attribute (
17170 -- [Entity =>] LOCAL_NAME,
17171 -- [Attribute_Name =>] static_string_EXPRESSION
17172 -- [, [Info =>] static_EXPRESSION] );
17174 when Pragma_Machine_Attribute => Machine_Attribute : declare
17175 Def_Id : Entity_Id;
17177 begin
17178 GNAT_Pragma;
17179 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
17181 if Arg_Count = 3 then
17182 Check_Optional_Identifier (Arg3, Name_Info);
17183 Check_Arg_Is_OK_Static_Expression (Arg3);
17184 else
17185 Check_Arg_Count (2);
17186 end if;
17188 Check_Optional_Identifier (Arg1, Name_Entity);
17189 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
17190 Check_Arg_Is_Local_Name (Arg1);
17191 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
17192 Def_Id := Entity (Get_Pragma_Arg (Arg1));
17194 if Is_Access_Type (Def_Id) then
17195 Def_Id := Designated_Type (Def_Id);
17196 end if;
17198 if Rep_Item_Too_Early (Def_Id, N) then
17199 return;
17200 end if;
17202 Def_Id := Underlying_Type (Def_Id);
17204 -- The only processing required is to link this item on to the
17205 -- list of rep items for the given entity. This is accomplished
17206 -- by the call to Rep_Item_Too_Late (when no error is detected
17207 -- and False is returned).
17209 if Rep_Item_Too_Late (Def_Id, N) then
17210 return;
17211 else
17212 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
17213 end if;
17214 end Machine_Attribute;
17216 ----------
17217 -- Main --
17218 ----------
17220 -- pragma Main
17221 -- (MAIN_OPTION [, MAIN_OPTION]);
17223 -- MAIN_OPTION ::=
17224 -- [STACK_SIZE =>] static_integer_EXPRESSION
17225 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
17226 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
17228 when Pragma_Main => Main : declare
17229 Args : Args_List (1 .. 3);
17230 Names : constant Name_List (1 .. 3) := (
17231 Name_Stack_Size,
17232 Name_Task_Stack_Size_Default,
17233 Name_Time_Slicing_Enabled);
17235 Nod : Node_Id;
17237 begin
17238 GNAT_Pragma;
17239 Gather_Associations (Names, Args);
17241 for J in 1 .. 2 loop
17242 if Present (Args (J)) then
17243 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
17244 end if;
17245 end loop;
17247 if Present (Args (3)) then
17248 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
17249 end if;
17251 Nod := Next (N);
17252 while Present (Nod) loop
17253 if Nkind (Nod) = N_Pragma
17254 and then Pragma_Name (Nod) = Name_Main
17255 then
17256 Error_Msg_Name_1 := Pname;
17257 Error_Msg_N ("duplicate pragma% not permitted", Nod);
17258 end if;
17260 Next (Nod);
17261 end loop;
17262 end Main;
17264 ------------------
17265 -- Main_Storage --
17266 ------------------
17268 -- pragma Main_Storage
17269 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
17271 -- MAIN_STORAGE_OPTION ::=
17272 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
17273 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
17275 when Pragma_Main_Storage => Main_Storage : declare
17276 Args : Args_List (1 .. 2);
17277 Names : constant Name_List (1 .. 2) := (
17278 Name_Working_Storage,
17279 Name_Top_Guard);
17281 Nod : Node_Id;
17283 begin
17284 GNAT_Pragma;
17285 Gather_Associations (Names, Args);
17287 for J in 1 .. 2 loop
17288 if Present (Args (J)) then
17289 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
17290 end if;
17291 end loop;
17293 Check_In_Main_Program;
17295 Nod := Next (N);
17296 while Present (Nod) loop
17297 if Nkind (Nod) = N_Pragma
17298 and then Pragma_Name (Nod) = Name_Main_Storage
17299 then
17300 Error_Msg_Name_1 := Pname;
17301 Error_Msg_N ("duplicate pragma% not permitted", Nod);
17302 end if;
17304 Next (Nod);
17305 end loop;
17306 end Main_Storage;
17308 -----------------
17309 -- Memory_Size --
17310 -----------------
17312 -- pragma Memory_Size (NUMERIC_LITERAL)
17314 when Pragma_Memory_Size =>
17315 GNAT_Pragma;
17317 -- Memory size is simply ignored
17319 Check_No_Identifiers;
17320 Check_Arg_Count (1);
17321 Check_Arg_Is_Integer_Literal (Arg1);
17323 -------------
17324 -- No_Body --
17325 -------------
17327 -- pragma No_Body;
17329 -- The only correct use of this pragma is on its own in a file, in
17330 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
17331 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
17332 -- check for a file containing nothing but a No_Body pragma). If we
17333 -- attempt to process it during normal semantics processing, it means
17334 -- it was misplaced.
17336 when Pragma_No_Body =>
17337 GNAT_Pragma;
17338 Pragma_Misplaced;
17340 -----------------------------
17341 -- No_Elaboration_Code_All --
17342 -----------------------------
17344 -- pragma No_Elaboration_Code_All;
17346 when Pragma_No_Elaboration_Code_All =>
17347 GNAT_Pragma;
17348 Check_Valid_Library_Unit_Pragma;
17350 if Nkind (N) = N_Null_Statement then
17351 return;
17352 end if;
17354 -- Must appear for a spec or generic spec
17356 if not Nkind_In (Unit (Cunit (Current_Sem_Unit)),
17357 N_Generic_Package_Declaration,
17358 N_Generic_Subprogram_Declaration,
17359 N_Package_Declaration,
17360 N_Subprogram_Declaration)
17361 then
17362 Error_Pragma
17363 (Fix_Error
17364 ("pragma% can only occur for package "
17365 & "or subprogram spec"));
17366 end if;
17368 -- Set flag in unit table
17370 Set_No_Elab_Code_All (Current_Sem_Unit);
17372 -- Set restriction No_Elaboration_Code if this is the main unit
17374 if Current_Sem_Unit = Main_Unit then
17375 Set_Restriction (No_Elaboration_Code, N);
17376 end if;
17378 -- If we are in the main unit or in an extended main source unit,
17379 -- then we also add it to the configuration restrictions so that
17380 -- it will apply to all units in the extended main source.
17382 if Current_Sem_Unit = Main_Unit
17383 or else In_Extended_Main_Source_Unit (N)
17384 then
17385 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
17386 end if;
17388 -- If in main extended unit, activate transitive with test
17390 if In_Extended_Main_Source_Unit (N) then
17391 Opt.No_Elab_Code_All_Pragma := N;
17392 end if;
17394 ---------------
17395 -- No_Inline --
17396 ---------------
17398 -- pragma No_Inline ( NAME {, NAME} );
17400 when Pragma_No_Inline =>
17401 GNAT_Pragma;
17402 Process_Inline (Suppressed);
17404 ---------------
17405 -- No_Return --
17406 ---------------
17408 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
17410 when Pragma_No_Return => No_Return : declare
17411 Arg : Node_Id;
17412 E : Entity_Id;
17413 Found : Boolean;
17414 Id : Node_Id;
17416 Ghost_Error_Posted : Boolean := False;
17417 -- Flag set when an error concerning the illegal mix of Ghost and
17418 -- non-Ghost subprograms is emitted.
17420 Ghost_Id : Entity_Id := Empty;
17421 -- The entity of the first Ghost procedure encountered while
17422 -- processing the arguments of the pragma.
17424 begin
17425 Ada_2005_Pragma;
17426 Check_At_Least_N_Arguments (1);
17428 -- Loop through arguments of pragma
17430 Arg := Arg1;
17431 while Present (Arg) loop
17432 Check_Arg_Is_Local_Name (Arg);
17433 Id := Get_Pragma_Arg (Arg);
17434 Analyze (Id);
17436 if not Is_Entity_Name (Id) then
17437 Error_Pragma_Arg ("entity name required", Arg);
17438 end if;
17440 if Etype (Id) = Any_Type then
17441 raise Pragma_Exit;
17442 end if;
17444 -- Loop to find matching procedures
17446 E := Entity (Id);
17448 Found := False;
17449 while Present (E)
17450 and then Scope (E) = Current_Scope
17451 loop
17452 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
17453 Set_No_Return (E);
17455 -- A pragma that applies to a Ghost entity becomes Ghost
17456 -- for the purposes of legality checks and removal of
17457 -- ignored Ghost code.
17459 Mark_Pragma_As_Ghost (N, E);
17461 -- Capture the entity of the first Ghost procedure being
17462 -- processed for error detection purposes.
17464 if Is_Ghost_Entity (E) then
17465 if No (Ghost_Id) then
17466 Ghost_Id := E;
17467 end if;
17469 -- Otherwise the subprogram is non-Ghost. It is illegal
17470 -- to mix references to Ghost and non-Ghost entities
17471 -- (SPARK RM 6.9).
17473 elsif Present (Ghost_Id)
17474 and then not Ghost_Error_Posted
17475 then
17476 Ghost_Error_Posted := True;
17478 Error_Msg_Name_1 := Pname;
17479 Error_Msg_N
17480 ("pragma % cannot mention ghost and non-ghost "
17481 & "procedures", N);
17483 Error_Msg_Sloc := Sloc (Ghost_Id);
17484 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
17486 Error_Msg_Sloc := Sloc (E);
17487 Error_Msg_NE ("\& # declared as non-ghost", N, E);
17488 end if;
17490 -- Set flag on any alias as well
17492 if Is_Overloadable (E) and then Present (Alias (E)) then
17493 Set_No_Return (Alias (E));
17494 end if;
17496 Found := True;
17497 end if;
17499 exit when From_Aspect_Specification (N);
17500 E := Homonym (E);
17501 end loop;
17503 -- If entity in not in current scope it may be the enclosing
17504 -- suprogram body to which the aspect applies.
17506 if not Found then
17507 if Entity (Id) = Current_Scope
17508 and then From_Aspect_Specification (N)
17509 then
17510 Set_No_Return (Entity (Id));
17511 else
17512 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
17513 end if;
17514 end if;
17516 Next (Arg);
17517 end loop;
17518 end No_Return;
17520 -----------------
17521 -- No_Run_Time --
17522 -----------------
17524 -- pragma No_Run_Time;
17526 -- Note: this pragma is retained for backwards compatibility. See
17527 -- body of Rtsfind for full details on its handling.
17529 when Pragma_No_Run_Time =>
17530 GNAT_Pragma;
17531 Check_Valid_Configuration_Pragma;
17532 Check_Arg_Count (0);
17534 No_Run_Time_Mode := True;
17535 Configurable_Run_Time_Mode := True;
17537 -- Set Duration to 32 bits if word size is 32
17539 if Ttypes.System_Word_Size = 32 then
17540 Duration_32_Bits_On_Target := True;
17541 end if;
17543 -- Set appropriate restrictions
17545 Set_Restriction (No_Finalization, N);
17546 Set_Restriction (No_Exception_Handlers, N);
17547 Set_Restriction (Max_Tasks, N, 0);
17548 Set_Restriction (No_Tasking, N);
17550 -----------------------
17551 -- No_Tagged_Streams --
17552 -----------------------
17554 -- pragma No_Tagged_Streams;
17555 -- pragma No_Tagged_Streams ([Entity => ]tagged_type_local_NAME);
17557 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
17558 E : Entity_Id;
17559 E_Id : Node_Id;
17561 begin
17562 GNAT_Pragma;
17563 Check_At_Most_N_Arguments (1);
17565 -- One argument case
17567 if Arg_Count = 1 then
17568 Check_Optional_Identifier (Arg1, Name_Entity);
17569 Check_Arg_Is_Local_Name (Arg1);
17570 E_Id := Get_Pragma_Arg (Arg1);
17572 if Etype (E_Id) = Any_Type then
17573 return;
17574 end if;
17576 E := Entity (E_Id);
17578 Check_Duplicate_Pragma (E);
17580 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
17581 Error_Pragma_Arg
17582 ("argument for pragma% must be root tagged type", Arg1);
17583 end if;
17585 if Rep_Item_Too_Early (E, N)
17586 or else
17587 Rep_Item_Too_Late (E, N)
17588 then
17589 return;
17590 else
17591 Set_No_Tagged_Streams_Pragma (E, N);
17592 end if;
17594 -- Zero argument case
17596 else
17597 Check_Is_In_Decl_Part_Or_Package_Spec;
17598 No_Tagged_Streams := N;
17599 end if;
17600 end No_Tagged_Strms;
17602 ------------------------
17603 -- No_Strict_Aliasing --
17604 ------------------------
17606 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
17608 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
17609 E_Id : Entity_Id;
17611 begin
17612 GNAT_Pragma;
17613 Check_At_Most_N_Arguments (1);
17615 if Arg_Count = 0 then
17616 Check_Valid_Configuration_Pragma;
17617 Opt.No_Strict_Aliasing := True;
17619 else
17620 Check_Optional_Identifier (Arg2, Name_Entity);
17621 Check_Arg_Is_Local_Name (Arg1);
17622 E_Id := Entity (Get_Pragma_Arg (Arg1));
17624 if E_Id = Any_Type then
17625 return;
17626 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
17627 Error_Pragma_Arg ("pragma% requires access type", Arg1);
17628 end if;
17630 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
17631 end if;
17632 end No_Strict_Aliasing;
17634 -----------------------
17635 -- Normalize_Scalars --
17636 -----------------------
17638 -- pragma Normalize_Scalars;
17640 when Pragma_Normalize_Scalars =>
17641 Check_Ada_83_Warning;
17642 Check_Arg_Count (0);
17643 Check_Valid_Configuration_Pragma;
17645 -- Normalize_Scalars creates false positives in CodePeer, and
17646 -- incorrect negative results in GNATprove mode, so ignore this
17647 -- pragma in these modes.
17649 if not (CodePeer_Mode or GNATprove_Mode) then
17650 Normalize_Scalars := True;
17651 Init_Or_Norm_Scalars := True;
17652 end if;
17654 -----------------
17655 -- Obsolescent --
17656 -----------------
17658 -- pragma Obsolescent;
17660 -- pragma Obsolescent (
17661 -- [Message =>] static_string_EXPRESSION
17662 -- [,[Version =>] Ada_05]]);
17664 -- pragma Obsolescent (
17665 -- [Entity =>] NAME
17666 -- [,[Message =>] static_string_EXPRESSION
17667 -- [,[Version =>] Ada_05]] );
17669 when Pragma_Obsolescent => Obsolescent : declare
17670 Decl : Node_Id;
17671 Ename : Node_Id;
17673 procedure Set_Obsolescent (E : Entity_Id);
17674 -- Given an entity Ent, mark it as obsolescent if appropriate
17676 ---------------------
17677 -- Set_Obsolescent --
17678 ---------------------
17680 procedure Set_Obsolescent (E : Entity_Id) is
17681 Active : Boolean;
17682 Ent : Entity_Id;
17683 S : String_Id;
17685 begin
17686 Active := True;
17687 Ent := E;
17689 -- A pragma that applies to a Ghost entity becomes Ghost for
17690 -- the purposes of legality checks and removal of ignored Ghost
17691 -- code.
17693 Mark_Pragma_As_Ghost (N, E);
17695 -- Entity name was given
17697 if Present (Ename) then
17699 -- If entity name matches, we are fine. Save entity in
17700 -- pragma argument, for ASIS use.
17702 if Chars (Ename) = Chars (Ent) then
17703 Set_Entity (Ename, Ent);
17704 Generate_Reference (Ent, Ename);
17706 -- If entity name does not match, only possibility is an
17707 -- enumeration literal from an enumeration type declaration.
17709 elsif Ekind (Ent) /= E_Enumeration_Type then
17710 Error_Pragma
17711 ("pragma % entity name does not match declaration");
17713 else
17714 Ent := First_Literal (E);
17715 loop
17716 if No (Ent) then
17717 Error_Pragma
17718 ("pragma % entity name does not match any "
17719 & "enumeration literal");
17721 elsif Chars (Ent) = Chars (Ename) then
17722 Set_Entity (Ename, Ent);
17723 Generate_Reference (Ent, Ename);
17724 exit;
17726 else
17727 Ent := Next_Literal (Ent);
17728 end if;
17729 end loop;
17730 end if;
17731 end if;
17733 -- Ent points to entity to be marked
17735 if Arg_Count >= 1 then
17737 -- Deal with static string argument
17739 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17740 S := Strval (Get_Pragma_Arg (Arg1));
17742 for J in 1 .. String_Length (S) loop
17743 if not In_Character_Range (Get_String_Char (S, J)) then
17744 Error_Pragma_Arg
17745 ("pragma% argument does not allow wide characters",
17746 Arg1);
17747 end if;
17748 end loop;
17750 Obsolescent_Warnings.Append
17751 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
17753 -- Check for Ada_05 parameter
17755 if Arg_Count /= 1 then
17756 Check_Arg_Count (2);
17758 declare
17759 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
17761 begin
17762 Check_Arg_Is_Identifier (Argx);
17764 if Chars (Argx) /= Name_Ada_05 then
17765 Error_Msg_Name_2 := Name_Ada_05;
17766 Error_Pragma_Arg
17767 ("only allowed argument for pragma% is %", Argx);
17768 end if;
17770 if Ada_Version_Explicit < Ada_2005
17771 or else not Warn_On_Ada_2005_Compatibility
17772 then
17773 Active := False;
17774 end if;
17775 end;
17776 end if;
17777 end if;
17779 -- Set flag if pragma active
17781 if Active then
17782 Set_Is_Obsolescent (Ent);
17783 end if;
17785 return;
17786 end Set_Obsolescent;
17788 -- Start of processing for pragma Obsolescent
17790 begin
17791 GNAT_Pragma;
17793 Check_At_Most_N_Arguments (3);
17795 -- See if first argument specifies an entity name
17797 if Arg_Count >= 1
17798 and then
17799 (Chars (Arg1) = Name_Entity
17800 or else
17801 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
17802 N_Identifier,
17803 N_Operator_Symbol))
17804 then
17805 Ename := Get_Pragma_Arg (Arg1);
17807 -- Eliminate first argument, so we can share processing
17809 Arg1 := Arg2;
17810 Arg2 := Arg3;
17811 Arg_Count := Arg_Count - 1;
17813 -- No Entity name argument given
17815 else
17816 Ename := Empty;
17817 end if;
17819 if Arg_Count >= 1 then
17820 Check_Optional_Identifier (Arg1, Name_Message);
17822 if Arg_Count = 2 then
17823 Check_Optional_Identifier (Arg2, Name_Version);
17824 end if;
17825 end if;
17827 -- Get immediately preceding declaration
17829 Decl := Prev (N);
17830 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
17831 Prev (Decl);
17832 end loop;
17834 -- Cases where we do not follow anything other than another pragma
17836 if No (Decl) then
17838 -- First case: library level compilation unit declaration with
17839 -- the pragma immediately following the declaration.
17841 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
17842 Set_Obsolescent
17843 (Defining_Entity (Unit (Parent (Parent (N)))));
17844 return;
17846 -- Case 2: library unit placement for package
17848 else
17849 declare
17850 Ent : constant Entity_Id := Find_Lib_Unit_Name;
17851 begin
17852 if Is_Package_Or_Generic_Package (Ent) then
17853 Set_Obsolescent (Ent);
17854 return;
17855 end if;
17856 end;
17857 end if;
17859 -- Cases where we must follow a declaration, including an
17860 -- abstract subprogram declaration, which is not in the
17861 -- other node subtypes.
17863 else
17864 if Nkind (Decl) not in N_Declaration
17865 and then Nkind (Decl) not in N_Later_Decl_Item
17866 and then Nkind (Decl) not in N_Generic_Declaration
17867 and then Nkind (Decl) not in N_Renaming_Declaration
17868 and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration
17869 then
17870 Error_Pragma
17871 ("pragma% misplaced, "
17872 & "must immediately follow a declaration");
17874 else
17875 Set_Obsolescent (Defining_Entity (Decl));
17876 return;
17877 end if;
17878 end if;
17879 end Obsolescent;
17881 --------------
17882 -- Optimize --
17883 --------------
17885 -- pragma Optimize (Time | Space | Off);
17887 -- The actual check for optimize is done in Gigi. Note that this
17888 -- pragma does not actually change the optimization setting, it
17889 -- simply checks that it is consistent with the pragma.
17891 when Pragma_Optimize =>
17892 Check_No_Identifiers;
17893 Check_Arg_Count (1);
17894 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
17896 ------------------------
17897 -- Optimize_Alignment --
17898 ------------------------
17900 -- pragma Optimize_Alignment (Time | Space | Off);
17902 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
17903 GNAT_Pragma;
17904 Check_No_Identifiers;
17905 Check_Arg_Count (1);
17906 Check_Valid_Configuration_Pragma;
17908 declare
17909 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
17910 begin
17911 case Nam is
17912 when Name_Time =>
17913 Opt.Optimize_Alignment := 'T';
17914 when Name_Space =>
17915 Opt.Optimize_Alignment := 'S';
17916 when Name_Off =>
17917 Opt.Optimize_Alignment := 'O';
17918 when others =>
17919 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
17920 end case;
17921 end;
17923 -- Set indication that mode is set locally. If we are in fact in a
17924 -- configuration pragma file, this setting is harmless since the
17925 -- switch will get reset anyway at the start of each unit.
17927 Optimize_Alignment_Local := True;
17928 end Optimize_Alignment;
17930 -------------
17931 -- Ordered --
17932 -------------
17934 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
17936 when Pragma_Ordered => Ordered : declare
17937 Assoc : constant Node_Id := Arg1;
17938 Type_Id : Node_Id;
17939 Typ : Entity_Id;
17941 begin
17942 GNAT_Pragma;
17943 Check_No_Identifiers;
17944 Check_Arg_Count (1);
17945 Check_Arg_Is_Local_Name (Arg1);
17947 Type_Id := Get_Pragma_Arg (Assoc);
17948 Find_Type (Type_Id);
17949 Typ := Entity (Type_Id);
17951 if Typ = Any_Type then
17952 return;
17953 else
17954 Typ := Underlying_Type (Typ);
17955 end if;
17957 if not Is_Enumeration_Type (Typ) then
17958 Error_Pragma ("pragma% must specify enumeration type");
17959 end if;
17961 Check_First_Subtype (Arg1);
17962 Set_Has_Pragma_Ordered (Base_Type (Typ));
17963 end Ordered;
17965 -------------------
17966 -- Overflow_Mode --
17967 -------------------
17969 -- pragma Overflow_Mode
17970 -- ([General => ] MODE [, [Assertions => ] MODE]);
17972 -- MODE := STRICT | MINIMIZED | ELIMINATED
17974 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
17975 -- since System.Bignums makes this assumption. This is true of nearly
17976 -- all (all?) targets.
17978 when Pragma_Overflow_Mode => Overflow_Mode : declare
17979 function Get_Overflow_Mode
17980 (Name : Name_Id;
17981 Arg : Node_Id) return Overflow_Mode_Type;
17982 -- Function to process one pragma argument, Arg. If an identifier
17983 -- is present, it must be Name. Mode type is returned if a valid
17984 -- argument exists, otherwise an error is signalled.
17986 -----------------------
17987 -- Get_Overflow_Mode --
17988 -----------------------
17990 function Get_Overflow_Mode
17991 (Name : Name_Id;
17992 Arg : Node_Id) return Overflow_Mode_Type
17994 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
17996 begin
17997 Check_Optional_Identifier (Arg, Name);
17998 Check_Arg_Is_Identifier (Argx);
18000 if Chars (Argx) = Name_Strict then
18001 return Strict;
18003 elsif Chars (Argx) = Name_Minimized then
18004 return Minimized;
18006 elsif Chars (Argx) = Name_Eliminated then
18007 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
18008 Error_Pragma_Arg
18009 ("Eliminated not implemented on this target", Argx);
18010 else
18011 return Eliminated;
18012 end if;
18014 else
18015 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
18016 end if;
18017 end Get_Overflow_Mode;
18019 -- Start of processing for Overflow_Mode
18021 begin
18022 GNAT_Pragma;
18023 Check_At_Least_N_Arguments (1);
18024 Check_At_Most_N_Arguments (2);
18026 -- Process first argument
18028 Scope_Suppress.Overflow_Mode_General :=
18029 Get_Overflow_Mode (Name_General, Arg1);
18031 -- Case of only one argument
18033 if Arg_Count = 1 then
18034 Scope_Suppress.Overflow_Mode_Assertions :=
18035 Scope_Suppress.Overflow_Mode_General;
18037 -- Case of two arguments present
18039 else
18040 Scope_Suppress.Overflow_Mode_Assertions :=
18041 Get_Overflow_Mode (Name_Assertions, Arg2);
18042 end if;
18043 end Overflow_Mode;
18045 --------------------------
18046 -- Overriding Renamings --
18047 --------------------------
18049 -- pragma Overriding_Renamings;
18051 when Pragma_Overriding_Renamings =>
18052 GNAT_Pragma;
18053 Check_Arg_Count (0);
18054 Check_Valid_Configuration_Pragma;
18055 Overriding_Renamings := True;
18057 ----------
18058 -- Pack --
18059 ----------
18061 -- pragma Pack (first_subtype_LOCAL_NAME);
18063 when Pragma_Pack => Pack : declare
18064 Assoc : constant Node_Id := Arg1;
18065 Ctyp : Entity_Id;
18066 Ignore : Boolean := False;
18067 Typ : Entity_Id;
18068 Type_Id : Node_Id;
18070 begin
18071 Check_No_Identifiers;
18072 Check_Arg_Count (1);
18073 Check_Arg_Is_Local_Name (Arg1);
18074 Type_Id := Get_Pragma_Arg (Assoc);
18076 if not Is_Entity_Name (Type_Id)
18077 or else not Is_Type (Entity (Type_Id))
18078 then
18079 Error_Pragma_Arg
18080 ("argument for pragma% must be type or subtype", Arg1);
18081 end if;
18083 Find_Type (Type_Id);
18084 Typ := Entity (Type_Id);
18086 if Typ = Any_Type
18087 or else Rep_Item_Too_Early (Typ, N)
18088 then
18089 return;
18090 else
18091 Typ := Underlying_Type (Typ);
18092 end if;
18094 -- A pragma that applies to a Ghost entity becomes Ghost for the
18095 -- purposes of legality checks and removal of ignored Ghost code.
18097 Mark_Pragma_As_Ghost (N, Typ);
18099 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
18100 Error_Pragma ("pragma% must specify array or record type");
18101 end if;
18103 Check_First_Subtype (Arg1);
18104 Check_Duplicate_Pragma (Typ);
18106 -- Array type
18108 if Is_Array_Type (Typ) then
18109 Ctyp := Component_Type (Typ);
18111 -- Ignore pack that does nothing
18113 if Known_Static_Esize (Ctyp)
18114 and then Known_Static_RM_Size (Ctyp)
18115 and then Esize (Ctyp) = RM_Size (Ctyp)
18116 and then Addressable (Esize (Ctyp))
18117 then
18118 Ignore := True;
18119 end if;
18121 -- Process OK pragma Pack. Note that if there is a separate
18122 -- component clause present, the Pack will be cancelled. This
18123 -- processing is in Freeze.
18125 if not Rep_Item_Too_Late (Typ, N) then
18127 -- In CodePeer mode, we do not need complex front-end
18128 -- expansions related to pragma Pack, so disable handling
18129 -- of pragma Pack.
18131 if CodePeer_Mode then
18132 null;
18134 -- Normal case where we do the pack action
18136 else
18137 if not Ignore then
18138 Set_Is_Packed (Base_Type (Typ));
18139 Set_Has_Non_Standard_Rep (Base_Type (Typ));
18140 end if;
18142 Set_Has_Pragma_Pack (Base_Type (Typ));
18143 end if;
18144 end if;
18146 -- For record types, the pack is always effective
18148 else pragma Assert (Is_Record_Type (Typ));
18149 if not Rep_Item_Too_Late (Typ, N) then
18150 Set_Is_Packed (Base_Type (Typ));
18151 Set_Has_Pragma_Pack (Base_Type (Typ));
18152 Set_Has_Non_Standard_Rep (Base_Type (Typ));
18153 end if;
18154 end if;
18155 end Pack;
18157 ----------
18158 -- Page --
18159 ----------
18161 -- pragma Page;
18163 -- There is nothing to do here, since we did all the processing for
18164 -- this pragma in Par.Prag (so that it works properly even in syntax
18165 -- only mode).
18167 when Pragma_Page =>
18168 null;
18170 -------------
18171 -- Part_Of --
18172 -------------
18174 -- pragma Part_Of (ABSTRACT_STATE);
18176 -- ABSTRACT_STATE ::= NAME
18178 when Pragma_Part_Of => Part_Of : declare
18179 procedure Propagate_Part_Of
18180 (Pack_Id : Entity_Id;
18181 State_Id : Entity_Id;
18182 Instance : Node_Id);
18183 -- Propagate the Part_Of indicator to all abstract states and
18184 -- objects declared in the visible state space of a package
18185 -- denoted by Pack_Id. State_Id is the encapsulating state.
18186 -- Instance is the package instantiation node.
18188 -----------------------
18189 -- Propagate_Part_Of --
18190 -----------------------
18192 procedure Propagate_Part_Of
18193 (Pack_Id : Entity_Id;
18194 State_Id : Entity_Id;
18195 Instance : Node_Id)
18197 Has_Item : Boolean := False;
18198 -- Flag set when the visible state space contains at least one
18199 -- abstract state or variable.
18201 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
18202 -- Propagate the Part_Of indicator to all abstract states and
18203 -- objects declared in the visible state space of a package
18204 -- denoted by Pack_Id.
18206 -----------------------
18207 -- Propagate_Part_Of --
18208 -----------------------
18210 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
18211 Constits : Elist_Id;
18212 Item_Id : Entity_Id;
18214 begin
18215 -- Traverse the entity chain of the package and set relevant
18216 -- attributes of abstract states and objects declared in the
18217 -- visible state space of the package.
18219 Item_Id := First_Entity (Pack_Id);
18220 while Present (Item_Id)
18221 and then not In_Private_Part (Item_Id)
18222 loop
18223 -- Do not consider internally generated items
18225 if not Comes_From_Source (Item_Id) then
18226 null;
18228 -- The Part_Of indicator turns an abstract state or an
18229 -- object into a constituent of the encapsulating state.
18231 elsif Ekind_In (Item_Id, E_Abstract_State,
18232 E_Constant,
18233 E_Variable)
18234 then
18235 Has_Item := True;
18236 Constits := Part_Of_Constituents (State_Id);
18238 if No (Constits) then
18239 Constits := New_Elmt_List;
18240 Set_Part_Of_Constituents (State_Id, Constits);
18241 end if;
18243 Append_Elmt (Item_Id, Constits);
18244 Set_Encapsulating_State (Item_Id, State_Id);
18246 -- Recursively handle nested packages and instantiations
18248 elsif Ekind (Item_Id) = E_Package then
18249 Propagate_Part_Of (Item_Id);
18250 end if;
18252 Next_Entity (Item_Id);
18253 end loop;
18254 end Propagate_Part_Of;
18256 -- Start of processing for Propagate_Part_Of
18258 begin
18259 Propagate_Part_Of (Pack_Id);
18261 -- Detect a package instantiation that is subject to a Part_Of
18262 -- indicator, but has no visible state.
18264 if not Has_Item then
18265 SPARK_Msg_NE
18266 ("package instantiation & has Part_Of indicator but "
18267 & "lacks visible state", Instance, Pack_Id);
18268 end if;
18269 end Propagate_Part_Of;
18271 -- Local variables
18273 Constits : Elist_Id;
18274 Encap : Node_Id;
18275 Encap_Id : Entity_Id;
18276 Item_Id : Entity_Id;
18277 Legal : Boolean;
18278 Stmt : Node_Id;
18280 -- Start of processing for Part_Of
18282 begin
18283 GNAT_Pragma;
18284 Check_No_Identifiers;
18285 Check_Arg_Count (1);
18287 Stmt := Find_Related_Context (N, Do_Checks => True);
18289 -- Object declaration
18291 if Nkind (Stmt) = N_Object_Declaration then
18292 null;
18294 -- Package instantiation
18296 elsif Nkind (Stmt) = N_Package_Instantiation then
18297 null;
18299 -- Single concurrent type declaration
18301 elsif Is_Single_Concurrent_Type_Declaration (Stmt) then
18302 null;
18304 -- Otherwise the pragma is associated with an illegal construct
18306 else
18307 Pragma_Misplaced;
18308 return;
18309 end if;
18311 -- Extract the entity of the related object declaration or package
18312 -- instantiation. In the case of the instantiation, use the entity
18313 -- of the instance spec.
18315 if Nkind (Stmt) = N_Package_Instantiation then
18316 Stmt := Instance_Spec (Stmt);
18317 end if;
18319 Item_Id := Defining_Entity (Stmt);
18320 Encap := Get_Pragma_Arg (Arg1);
18322 -- A pragma that applies to a Ghost entity becomes Ghost for the
18323 -- purposes of legality checks and removal of ignored Ghost code.
18325 Mark_Pragma_As_Ghost (N, Item_Id);
18327 -- Chain the pragma on the contract for further processing by
18328 -- Analyze_Part_Of_In_Decl_Part or for completeness.
18330 Add_Contract_Item (N, Item_Id);
18332 -- A variable may act as consituent of a single concurrent type
18333 -- which in turn could be declared after the variable. Due to this
18334 -- discrepancy, the full analysis of indicator Part_Of is delayed
18335 -- until the end of the enclosing declarative region (see routine
18336 -- Analyze_Part_Of_In_Decl_Part).
18338 if Ekind (Item_Id) = E_Variable then
18339 null;
18341 -- Otherwise indicator Part_Of applies to a constant or a package
18342 -- instantiation.
18344 else
18345 -- Detect any discrepancies between the placement of the
18346 -- constant or package instantiation with respect to state
18347 -- space and the encapsulating state.
18349 Analyze_Part_Of
18350 (Indic => N,
18351 Item_Id => Item_Id,
18352 Encap => Encap,
18353 Encap_Id => Encap_Id,
18354 Legal => Legal);
18356 if Legal then
18357 pragma Assert (Present (Encap_Id));
18359 if Ekind (Item_Id) = E_Constant then
18360 Constits := Part_Of_Constituents (Encap_Id);
18362 if No (Constits) then
18363 Constits := New_Elmt_List;
18364 Set_Part_Of_Constituents (Encap_Id, Constits);
18365 end if;
18367 Append_Elmt (Item_Id, Constits);
18368 Set_Encapsulating_State (Item_Id, Encap_Id);
18370 -- Propagate the Part_Of indicator to the visible state
18371 -- space of the package instantiation.
18373 else
18374 Propagate_Part_Of
18375 (Pack_Id => Item_Id,
18376 State_Id => Encap_Id,
18377 Instance => Stmt);
18378 end if;
18379 end if;
18380 end if;
18381 end Part_Of;
18383 ----------------------------------
18384 -- Partition_Elaboration_Policy --
18385 ----------------------------------
18387 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
18389 when Pragma_Partition_Elaboration_Policy => declare
18390 subtype PEP_Range is Name_Id
18391 range First_Partition_Elaboration_Policy_Name
18392 .. Last_Partition_Elaboration_Policy_Name;
18393 PEP_Val : PEP_Range;
18394 PEP : Character;
18396 begin
18397 Ada_2005_Pragma;
18398 Check_Arg_Count (1);
18399 Check_No_Identifiers;
18400 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
18401 Check_Valid_Configuration_Pragma;
18402 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
18404 case PEP_Val is
18405 when Name_Concurrent =>
18406 PEP := 'C';
18407 when Name_Sequential =>
18408 PEP := 'S';
18409 end case;
18411 if Partition_Elaboration_Policy /= ' '
18412 and then Partition_Elaboration_Policy /= PEP
18413 then
18414 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
18415 Error_Pragma
18416 ("partition elaboration policy incompatible with policy#");
18418 -- Set new policy, but always preserve System_Location since we
18419 -- like the error message with the run time name.
18421 else
18422 Partition_Elaboration_Policy := PEP;
18424 if Partition_Elaboration_Policy_Sloc /= System_Location then
18425 Partition_Elaboration_Policy_Sloc := Loc;
18426 end if;
18427 end if;
18428 end;
18430 -------------
18431 -- Passive --
18432 -------------
18434 -- pragma Passive [(PASSIVE_FORM)];
18436 -- PASSIVE_FORM ::= Semaphore | No
18438 when Pragma_Passive =>
18439 GNAT_Pragma;
18441 if Nkind (Parent (N)) /= N_Task_Definition then
18442 Error_Pragma ("pragma% must be within task definition");
18443 end if;
18445 if Arg_Count /= 0 then
18446 Check_Arg_Count (1);
18447 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
18448 end if;
18450 ----------------------------------
18451 -- Preelaborable_Initialization --
18452 ----------------------------------
18454 -- pragma Preelaborable_Initialization (DIRECT_NAME);
18456 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
18457 Ent : Entity_Id;
18459 begin
18460 Ada_2005_Pragma;
18461 Check_Arg_Count (1);
18462 Check_No_Identifiers;
18463 Check_Arg_Is_Identifier (Arg1);
18464 Check_Arg_Is_Local_Name (Arg1);
18465 Check_First_Subtype (Arg1);
18466 Ent := Entity (Get_Pragma_Arg (Arg1));
18468 -- A pragma that applies to a Ghost entity becomes Ghost for the
18469 -- purposes of legality checks and removal of ignored Ghost code.
18471 Mark_Pragma_As_Ghost (N, Ent);
18473 -- The pragma may come from an aspect on a private declaration,
18474 -- even if the freeze point at which this is analyzed in the
18475 -- private part after the full view.
18477 if Has_Private_Declaration (Ent)
18478 and then From_Aspect_Specification (N)
18479 then
18480 null;
18482 -- Check appropriate type argument
18484 elsif Is_Private_Type (Ent)
18485 or else Is_Protected_Type (Ent)
18486 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
18488 -- AI05-0028: The pragma applies to all composite types. Note
18489 -- that we apply this binding interpretation to earlier versions
18490 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
18491 -- choice since there are other compilers that do the same.
18493 or else Is_Composite_Type (Ent)
18494 then
18495 null;
18497 else
18498 Error_Pragma_Arg
18499 ("pragma % can only be applied to private, formal derived, "
18500 & "protected, or composite type", Arg1);
18501 end if;
18503 -- Give an error if the pragma is applied to a protected type that
18504 -- does not qualify (due to having entries, or due to components
18505 -- that do not qualify).
18507 if Is_Protected_Type (Ent)
18508 and then not Has_Preelaborable_Initialization (Ent)
18509 then
18510 Error_Msg_N
18511 ("protected type & does not have preelaborable "
18512 & "initialization", Ent);
18514 -- Otherwise mark the type as definitely having preelaborable
18515 -- initialization.
18517 else
18518 Set_Known_To_Have_Preelab_Init (Ent);
18519 end if;
18521 if Has_Pragma_Preelab_Init (Ent)
18522 and then Warn_On_Redundant_Constructs
18523 then
18524 Error_Pragma ("?r?duplicate pragma%!");
18525 else
18526 Set_Has_Pragma_Preelab_Init (Ent);
18527 end if;
18528 end Preelab_Init;
18530 --------------------
18531 -- Persistent_BSS --
18532 --------------------
18534 -- pragma Persistent_BSS [(object_NAME)];
18536 when Pragma_Persistent_BSS => Persistent_BSS : declare
18537 Decl : Node_Id;
18538 Ent : Entity_Id;
18539 Prag : Node_Id;
18541 begin
18542 GNAT_Pragma;
18543 Check_At_Most_N_Arguments (1);
18545 -- Case of application to specific object (one argument)
18547 if Arg_Count = 1 then
18548 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18550 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
18551 or else not
18552 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
18553 E_Constant)
18554 then
18555 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
18556 end if;
18558 Ent := Entity (Get_Pragma_Arg (Arg1));
18559 Decl := Parent (Ent);
18561 -- A pragma that applies to a Ghost entity becomes Ghost for
18562 -- the purposes of legality checks and removal of ignored Ghost
18563 -- code.
18565 Mark_Pragma_As_Ghost (N, Ent);
18567 -- Check for duplication before inserting in list of
18568 -- representation items.
18570 Check_Duplicate_Pragma (Ent);
18572 if Rep_Item_Too_Late (Ent, N) then
18573 return;
18574 end if;
18576 if Present (Expression (Decl)) then
18577 Error_Pragma_Arg
18578 ("object for pragma% cannot have initialization", Arg1);
18579 end if;
18581 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
18582 Error_Pragma_Arg
18583 ("object type for pragma% is not potentially persistent",
18584 Arg1);
18585 end if;
18587 Prag :=
18588 Make_Linker_Section_Pragma
18589 (Ent, Sloc (N), ".persistent.bss");
18590 Insert_After (N, Prag);
18591 Analyze (Prag);
18593 -- Case of use as configuration pragma with no arguments
18595 else
18596 Check_Valid_Configuration_Pragma;
18597 Persistent_BSS_Mode := True;
18598 end if;
18599 end Persistent_BSS;
18601 -------------
18602 -- Polling --
18603 -------------
18605 -- pragma Polling (ON | OFF);
18607 when Pragma_Polling =>
18608 GNAT_Pragma;
18609 Check_Arg_Count (1);
18610 Check_No_Identifiers;
18611 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
18612 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
18614 -----------------------------------
18615 -- Post/Post_Class/Postcondition --
18616 -----------------------------------
18618 -- pragma Post (Boolean_EXPRESSION);
18619 -- pragma Post_Class (Boolean_EXPRESSION);
18620 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
18621 -- [,[Message =>] String_EXPRESSION]);
18623 -- Characteristics:
18625 -- * Analysis - The annotation undergoes initial checks to verify
18626 -- the legal placement and context. Secondary checks preanalyze the
18627 -- expression in:
18629 -- Analyze_Pre_Post_Condition_In_Decl_Part
18631 -- * Expansion - The annotation is expanded during the expansion of
18632 -- the related subprogram [body] contract as performed in:
18634 -- Expand_Subprogram_Contract
18636 -- * Template - The annotation utilizes the generic template of the
18637 -- related subprogram [body] when it is:
18639 -- aspect on subprogram declaration
18640 -- aspect on stand alone subprogram body
18641 -- pragma on stand alone subprogram body
18643 -- The annotation must prepare its own template when it is:
18645 -- pragma on subprogram declaration
18647 -- * Globals - Capture of global references must occur after full
18648 -- analysis.
18650 -- * Instance - The annotation is instantiated automatically when
18651 -- the related generic subprogram [body] is instantiated except for
18652 -- the "pragma on subprogram declaration" case. In that scenario
18653 -- the annotation must instantiate itself.
18655 when Pragma_Post |
18656 Pragma_Post_Class |
18657 Pragma_Postcondition =>
18658 Analyze_Pre_Post_Condition;
18660 --------------------------------
18661 -- Pre/Pre_Class/Precondition --
18662 --------------------------------
18664 -- pragma Pre (Boolean_EXPRESSION);
18665 -- pragma Pre_Class (Boolean_EXPRESSION);
18666 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
18667 -- [,[Message =>] String_EXPRESSION]);
18669 -- Characteristics:
18671 -- * Analysis - The annotation undergoes initial checks to verify
18672 -- the legal placement and context. Secondary checks preanalyze the
18673 -- expression in:
18675 -- Analyze_Pre_Post_Condition_In_Decl_Part
18677 -- * Expansion - The annotation is expanded during the expansion of
18678 -- the related subprogram [body] contract as performed in:
18680 -- Expand_Subprogram_Contract
18682 -- * Template - The annotation utilizes the generic template of the
18683 -- related subprogram [body] when it is:
18685 -- aspect on subprogram declaration
18686 -- aspect on stand alone subprogram body
18687 -- pragma on stand alone subprogram body
18689 -- The annotation must prepare its own template when it is:
18691 -- pragma on subprogram declaration
18693 -- * Globals - Capture of global references must occur after full
18694 -- analysis.
18696 -- * Instance - The annotation is instantiated automatically when
18697 -- the related generic subprogram [body] is instantiated except for
18698 -- the "pragma on subprogram declaration" case. In that scenario
18699 -- the annotation must instantiate itself.
18701 when Pragma_Pre |
18702 Pragma_Pre_Class |
18703 Pragma_Precondition =>
18704 Analyze_Pre_Post_Condition;
18706 ---------------
18707 -- Predicate --
18708 ---------------
18710 -- pragma Predicate
18711 -- ([Entity =>] type_LOCAL_NAME,
18712 -- [Check =>] boolean_EXPRESSION);
18714 when Pragma_Predicate => Predicate : declare
18715 Discard : Boolean;
18716 Typ : Entity_Id;
18717 Type_Id : Node_Id;
18719 begin
18720 GNAT_Pragma;
18721 Check_Arg_Count (2);
18722 Check_Optional_Identifier (Arg1, Name_Entity);
18723 Check_Optional_Identifier (Arg2, Name_Check);
18725 Check_Arg_Is_Local_Name (Arg1);
18727 Type_Id := Get_Pragma_Arg (Arg1);
18728 Find_Type (Type_Id);
18729 Typ := Entity (Type_Id);
18731 if Typ = Any_Type then
18732 return;
18733 end if;
18735 -- A pragma that applies to a Ghost entity becomes Ghost for the
18736 -- purposes of legality checks and removal of ignored Ghost code.
18738 Mark_Pragma_As_Ghost (N, Typ);
18740 -- The remaining processing is simply to link the pragma on to
18741 -- the rep item chain, for processing when the type is frozen.
18742 -- This is accomplished by a call to Rep_Item_Too_Late. We also
18743 -- mark the type as having predicates.
18745 Set_Has_Predicates (Typ);
18746 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
18747 end Predicate;
18749 -----------------------
18750 -- Predicate_Failure --
18751 -----------------------
18753 -- pragma Predicate_Failure
18754 -- ([Entity =>] type_LOCAL_NAME,
18755 -- [Message =>] string_EXPRESSION);
18757 when Pragma_Predicate_Failure => Predicate_Failure : declare
18758 Discard : Boolean;
18759 Typ : Entity_Id;
18760 Type_Id : Node_Id;
18762 begin
18763 GNAT_Pragma;
18764 Check_Arg_Count (2);
18765 Check_Optional_Identifier (Arg1, Name_Entity);
18766 Check_Optional_Identifier (Arg2, Name_Message);
18768 Check_Arg_Is_Local_Name (Arg1);
18770 Type_Id := Get_Pragma_Arg (Arg1);
18771 Find_Type (Type_Id);
18772 Typ := Entity (Type_Id);
18774 if Typ = Any_Type then
18775 return;
18776 end if;
18778 -- A pragma that applies to a Ghost entity becomes Ghost for the
18779 -- purposes of legality checks and removal of ignored Ghost code.
18781 Mark_Pragma_As_Ghost (N, Typ);
18783 -- The remaining processing is simply to link the pragma on to
18784 -- the rep item chain, for processing when the type is frozen.
18785 -- This is accomplished by a call to Rep_Item_Too_Late.
18787 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
18788 end Predicate_Failure;
18790 ------------------
18791 -- Preelaborate --
18792 ------------------
18794 -- pragma Preelaborate [(library_unit_NAME)];
18796 -- Set the flag Is_Preelaborated of program unit name entity
18798 when Pragma_Preelaborate => Preelaborate : declare
18799 Pa : constant Node_Id := Parent (N);
18800 Pk : constant Node_Kind := Nkind (Pa);
18801 Ent : Entity_Id;
18803 begin
18804 Check_Ada_83_Warning;
18805 Check_Valid_Library_Unit_Pragma;
18807 if Nkind (N) = N_Null_Statement then
18808 return;
18809 end if;
18811 Ent := Find_Lib_Unit_Name;
18813 -- A pragma that applies to a Ghost entity becomes Ghost for the
18814 -- purposes of legality checks and removal of ignored Ghost code.
18816 Mark_Pragma_As_Ghost (N, Ent);
18817 Check_Duplicate_Pragma (Ent);
18819 -- This filters out pragmas inside generic parents that show up
18820 -- inside instantiations. Pragmas that come from aspects in the
18821 -- unit are not ignored.
18823 if Present (Ent) then
18824 if Pk = N_Package_Specification
18825 and then Present (Generic_Parent (Pa))
18826 and then not From_Aspect_Specification (N)
18827 then
18828 null;
18830 else
18831 if not Debug_Flag_U then
18832 Set_Is_Preelaborated (Ent);
18833 Set_Suppress_Elaboration_Warnings (Ent);
18834 end if;
18835 end if;
18836 end if;
18837 end Preelaborate;
18839 -------------------------------
18840 -- Prefix_Exception_Messages --
18841 -------------------------------
18843 -- pragma Prefix_Exception_Messages;
18845 when Pragma_Prefix_Exception_Messages =>
18846 GNAT_Pragma;
18847 Check_Valid_Configuration_Pragma;
18848 Check_Arg_Count (0);
18849 Prefix_Exception_Messages := True;
18851 --------------
18852 -- Priority --
18853 --------------
18855 -- pragma Priority (EXPRESSION);
18857 when Pragma_Priority => Priority : declare
18858 P : constant Node_Id := Parent (N);
18859 Arg : Node_Id;
18860 Ent : Entity_Id;
18862 begin
18863 Check_No_Identifiers;
18864 Check_Arg_Count (1);
18866 -- Subprogram case
18868 if Nkind (P) = N_Subprogram_Body then
18869 Check_In_Main_Program;
18871 Ent := Defining_Unit_Name (Specification (P));
18873 if Nkind (Ent) = N_Defining_Program_Unit_Name then
18874 Ent := Defining_Identifier (Ent);
18875 end if;
18877 Arg := Get_Pragma_Arg (Arg1);
18878 Analyze_And_Resolve (Arg, Standard_Integer);
18880 -- Must be static
18882 if not Is_OK_Static_Expression (Arg) then
18883 Flag_Non_Static_Expr
18884 ("main subprogram priority is not static!", Arg);
18885 raise Pragma_Exit;
18887 -- If constraint error, then we already signalled an error
18889 elsif Raises_Constraint_Error (Arg) then
18890 null;
18892 -- Otherwise check in range except if Relaxed_RM_Semantics
18893 -- where we ignore the value if out of range.
18895 else
18896 declare
18897 Val : constant Uint := Expr_Value (Arg);
18898 begin
18899 if not Relaxed_RM_Semantics
18900 and then
18901 (Val < 0
18902 or else Val > Expr_Value (Expression
18903 (Parent (RTE (RE_Max_Priority)))))
18904 then
18905 Error_Pragma_Arg
18906 ("main subprogram priority is out of range", Arg1);
18907 else
18908 Set_Main_Priority
18909 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
18910 end if;
18911 end;
18912 end if;
18914 -- Load an arbitrary entity from System.Tasking.Stages or
18915 -- System.Tasking.Restricted.Stages (depending on the
18916 -- supported profile) to make sure that one of these packages
18917 -- is implicitly with'ed, since we need to have the tasking
18918 -- run time active for the pragma Priority to have any effect.
18919 -- Previously we with'ed the package System.Tasking, but this
18920 -- package does not trigger the required initialization of the
18921 -- run-time library.
18923 declare
18924 Discard : Entity_Id;
18925 pragma Warnings (Off, Discard);
18926 begin
18927 if Restricted_Profile then
18928 Discard := RTE (RE_Activate_Restricted_Tasks);
18929 else
18930 Discard := RTE (RE_Activate_Tasks);
18931 end if;
18932 end;
18934 -- Task or Protected, must be of type Integer
18936 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
18937 Arg := Get_Pragma_Arg (Arg1);
18938 Ent := Defining_Identifier (Parent (P));
18940 -- The expression must be analyzed in the special manner
18941 -- described in "Handling of Default and Per-Object
18942 -- Expressions" in sem.ads.
18944 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
18946 if not Is_OK_Static_Expression (Arg) then
18947 Check_Restriction (Static_Priorities, Arg);
18948 end if;
18950 -- Anything else is incorrect
18952 else
18953 Pragma_Misplaced;
18954 end if;
18956 -- Check duplicate pragma before we chain the pragma in the Rep
18957 -- Item chain of Ent.
18959 Check_Duplicate_Pragma (Ent);
18960 Record_Rep_Item (Ent, N);
18961 end Priority;
18963 -----------------------------------
18964 -- Priority_Specific_Dispatching --
18965 -----------------------------------
18967 -- pragma Priority_Specific_Dispatching (
18968 -- policy_IDENTIFIER,
18969 -- first_priority_EXPRESSION,
18970 -- last_priority_EXPRESSION);
18972 when Pragma_Priority_Specific_Dispatching =>
18973 Priority_Specific_Dispatching : declare
18974 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
18975 -- This is the entity System.Any_Priority;
18977 DP : Character;
18978 Lower_Bound : Node_Id;
18979 Upper_Bound : Node_Id;
18980 Lower_Val : Uint;
18981 Upper_Val : Uint;
18983 begin
18984 Ada_2005_Pragma;
18985 Check_Arg_Count (3);
18986 Check_No_Identifiers;
18987 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
18988 Check_Valid_Configuration_Pragma;
18989 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
18990 DP := Fold_Upper (Name_Buffer (1));
18992 Lower_Bound := Get_Pragma_Arg (Arg2);
18993 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
18994 Lower_Val := Expr_Value (Lower_Bound);
18996 Upper_Bound := Get_Pragma_Arg (Arg3);
18997 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
18998 Upper_Val := Expr_Value (Upper_Bound);
19000 -- It is not allowed to use Task_Dispatching_Policy and
19001 -- Priority_Specific_Dispatching in the same partition.
19003 if Task_Dispatching_Policy /= ' ' then
19004 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
19005 Error_Pragma
19006 ("pragma% incompatible with Task_Dispatching_Policy#");
19008 -- Check lower bound in range
19010 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
19011 or else
19012 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
19013 then
19014 Error_Pragma_Arg
19015 ("first_priority is out of range", Arg2);
19017 -- Check upper bound in range
19019 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
19020 or else
19021 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
19022 then
19023 Error_Pragma_Arg
19024 ("last_priority is out of range", Arg3);
19026 -- Check that the priority range is valid
19028 elsif Lower_Val > Upper_Val then
19029 Error_Pragma
19030 ("last_priority_expression must be greater than or equal to "
19031 & "first_priority_expression");
19033 -- Store the new policy, but always preserve System_Location since
19034 -- we like the error message with the run-time name.
19036 else
19037 -- Check overlapping in the priority ranges specified in other
19038 -- Priority_Specific_Dispatching pragmas within the same
19039 -- partition. We can only check those we know about.
19041 for J in
19042 Specific_Dispatching.First .. Specific_Dispatching.Last
19043 loop
19044 if Specific_Dispatching.Table (J).First_Priority in
19045 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
19046 or else Specific_Dispatching.Table (J).Last_Priority in
19047 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
19048 then
19049 Error_Msg_Sloc :=
19050 Specific_Dispatching.Table (J).Pragma_Loc;
19051 Error_Pragma
19052 ("priority range overlaps with "
19053 & "Priority_Specific_Dispatching#");
19054 end if;
19055 end loop;
19057 -- The use of Priority_Specific_Dispatching is incompatible
19058 -- with Task_Dispatching_Policy.
19060 if Task_Dispatching_Policy /= ' ' then
19061 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
19062 Error_Pragma
19063 ("Priority_Specific_Dispatching incompatible "
19064 & "with Task_Dispatching_Policy#");
19065 end if;
19067 -- The use of Priority_Specific_Dispatching forces ceiling
19068 -- locking policy.
19070 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
19071 Error_Msg_Sloc := Locking_Policy_Sloc;
19072 Error_Pragma
19073 ("Priority_Specific_Dispatching incompatible "
19074 & "with Locking_Policy#");
19076 -- Set the Ceiling_Locking policy, but preserve System_Location
19077 -- since we like the error message with the run time name.
19079 else
19080 Locking_Policy := 'C';
19082 if Locking_Policy_Sloc /= System_Location then
19083 Locking_Policy_Sloc := Loc;
19084 end if;
19085 end if;
19087 -- Add entry in the table
19089 Specific_Dispatching.Append
19090 ((Dispatching_Policy => DP,
19091 First_Priority => UI_To_Int (Lower_Val),
19092 Last_Priority => UI_To_Int (Upper_Val),
19093 Pragma_Loc => Loc));
19094 end if;
19095 end Priority_Specific_Dispatching;
19097 -------------
19098 -- Profile --
19099 -------------
19101 -- pragma Profile (profile_IDENTIFIER);
19103 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
19105 when Pragma_Profile =>
19106 Ada_2005_Pragma;
19107 Check_Arg_Count (1);
19108 Check_Valid_Configuration_Pragma;
19109 Check_No_Identifiers;
19111 declare
19112 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
19114 begin
19115 if Chars (Argx) = Name_Ravenscar then
19116 Set_Ravenscar_Profile (Ravenscar, N);
19118 elsif Chars (Argx) = Name_Gnat_Extended_Ravenscar then
19119 Set_Ravenscar_Profile (GNAT_Extended_Ravenscar, N);
19121 elsif Chars (Argx) = Name_Restricted then
19122 Set_Profile_Restrictions
19123 (Restricted,
19124 N, Warn => Treat_Restrictions_As_Warnings);
19126 elsif Chars (Argx) = Name_Rational then
19127 Set_Rational_Profile;
19129 elsif Chars (Argx) = Name_No_Implementation_Extensions then
19130 Set_Profile_Restrictions
19131 (No_Implementation_Extensions,
19132 N, Warn => Treat_Restrictions_As_Warnings);
19134 else
19135 Error_Pragma_Arg ("& is not a valid profile", Argx);
19136 end if;
19137 end;
19139 ----------------------
19140 -- Profile_Warnings --
19141 ----------------------
19143 -- pragma Profile_Warnings (profile_IDENTIFIER);
19145 -- profile_IDENTIFIER => Restricted | Ravenscar
19147 when Pragma_Profile_Warnings =>
19148 GNAT_Pragma;
19149 Check_Arg_Count (1);
19150 Check_Valid_Configuration_Pragma;
19151 Check_No_Identifiers;
19153 declare
19154 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
19156 begin
19157 if Chars (Argx) = Name_Ravenscar then
19158 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
19160 elsif Chars (Argx) = Name_Restricted then
19161 Set_Profile_Restrictions (Restricted, N, Warn => True);
19163 elsif Chars (Argx) = Name_No_Implementation_Extensions then
19164 Set_Profile_Restrictions
19165 (No_Implementation_Extensions, N, Warn => True);
19167 else
19168 Error_Pragma_Arg ("& is not a valid profile", Argx);
19169 end if;
19170 end;
19172 --------------------------
19173 -- Propagate_Exceptions --
19174 --------------------------
19176 -- pragma Propagate_Exceptions;
19178 -- Note: this pragma is obsolete and has no effect
19180 when Pragma_Propagate_Exceptions =>
19181 GNAT_Pragma;
19182 Check_Arg_Count (0);
19184 if Warn_On_Obsolescent_Feature then
19185 Error_Msg_N
19186 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
19187 "and has no effect?j?", N);
19188 end if;
19190 -----------------------------
19191 -- Provide_Shift_Operators --
19192 -----------------------------
19194 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
19196 when Pragma_Provide_Shift_Operators =>
19197 Provide_Shift_Operators : declare
19198 Ent : Entity_Id;
19200 procedure Declare_Shift_Operator (Nam : Name_Id);
19201 -- Insert declaration and pragma Instrinsic for named shift op
19203 ----------------------------
19204 -- Declare_Shift_Operator --
19205 ----------------------------
19207 procedure Declare_Shift_Operator (Nam : Name_Id) is
19208 Func : Node_Id;
19209 Import : Node_Id;
19211 begin
19212 Func :=
19213 Make_Subprogram_Declaration (Loc,
19214 Make_Function_Specification (Loc,
19215 Defining_Unit_Name =>
19216 Make_Defining_Identifier (Loc, Chars => Nam),
19218 Result_Definition =>
19219 Make_Identifier (Loc, Chars => Chars (Ent)),
19221 Parameter_Specifications => New_List (
19222 Make_Parameter_Specification (Loc,
19223 Defining_Identifier =>
19224 Make_Defining_Identifier (Loc, Name_Value),
19225 Parameter_Type =>
19226 Make_Identifier (Loc, Chars => Chars (Ent))),
19228 Make_Parameter_Specification (Loc,
19229 Defining_Identifier =>
19230 Make_Defining_Identifier (Loc, Name_Amount),
19231 Parameter_Type =>
19232 New_Occurrence_Of (Standard_Natural, Loc)))));
19234 Import :=
19235 Make_Pragma (Loc,
19236 Pragma_Identifier => Make_Identifier (Loc, Name_Import),
19237 Pragma_Argument_Associations => New_List (
19238 Make_Pragma_Argument_Association (Loc,
19239 Expression => Make_Identifier (Loc, Name_Intrinsic)),
19240 Make_Pragma_Argument_Association (Loc,
19241 Expression => Make_Identifier (Loc, Nam))));
19243 Insert_After (N, Import);
19244 Insert_After (N, Func);
19245 end Declare_Shift_Operator;
19247 -- Start of processing for Provide_Shift_Operators
19249 begin
19250 GNAT_Pragma;
19251 Check_Arg_Count (1);
19252 Check_Arg_Is_Local_Name (Arg1);
19254 Arg1 := Get_Pragma_Arg (Arg1);
19256 -- We must have an entity name
19258 if not Is_Entity_Name (Arg1) then
19259 Error_Pragma_Arg
19260 ("pragma % must apply to integer first subtype", Arg1);
19261 end if;
19263 -- If no Entity, means there was a prior error so ignore
19265 if Present (Entity (Arg1)) then
19266 Ent := Entity (Arg1);
19268 -- Apply error checks
19270 if not Is_First_Subtype (Ent) then
19271 Error_Pragma_Arg
19272 ("cannot apply pragma %",
19273 "\& is not a first subtype",
19274 Arg1);
19276 elsif not Is_Integer_Type (Ent) then
19277 Error_Pragma_Arg
19278 ("cannot apply pragma %",
19279 "\& is not an integer type",
19280 Arg1);
19282 elsif Has_Shift_Operator (Ent) then
19283 Error_Pragma_Arg
19284 ("cannot apply pragma %",
19285 "\& already has declared shift operators",
19286 Arg1);
19288 elsif Is_Frozen (Ent) then
19289 Error_Pragma_Arg
19290 ("pragma % appears too late",
19291 "\& is already frozen",
19292 Arg1);
19293 end if;
19295 -- Now declare the operators. We do this during analysis rather
19296 -- than expansion, since we want the operators available if we
19297 -- are operating in -gnatc or ASIS mode.
19299 Declare_Shift_Operator (Name_Rotate_Left);
19300 Declare_Shift_Operator (Name_Rotate_Right);
19301 Declare_Shift_Operator (Name_Shift_Left);
19302 Declare_Shift_Operator (Name_Shift_Right);
19303 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
19304 end if;
19305 end Provide_Shift_Operators;
19307 ------------------
19308 -- Psect_Object --
19309 ------------------
19311 -- pragma Psect_Object (
19312 -- [Internal =>] LOCAL_NAME,
19313 -- [, [External =>] EXTERNAL_SYMBOL]
19314 -- [, [Size =>] EXTERNAL_SYMBOL]);
19316 when Pragma_Psect_Object | Pragma_Common_Object =>
19317 Psect_Object : declare
19318 Args : Args_List (1 .. 3);
19319 Names : constant Name_List (1 .. 3) := (
19320 Name_Internal,
19321 Name_External,
19322 Name_Size);
19324 Internal : Node_Id renames Args (1);
19325 External : Node_Id renames Args (2);
19326 Size : Node_Id renames Args (3);
19328 Def_Id : Entity_Id;
19330 procedure Check_Arg (Arg : Node_Id);
19331 -- Checks that argument is either a string literal or an
19332 -- identifier, and posts error message if not.
19334 ---------------
19335 -- Check_Arg --
19336 ---------------
19338 procedure Check_Arg (Arg : Node_Id) is
19339 begin
19340 if not Nkind_In (Original_Node (Arg),
19341 N_String_Literal,
19342 N_Identifier)
19343 then
19344 Error_Pragma_Arg
19345 ("inappropriate argument for pragma %", Arg);
19346 end if;
19347 end Check_Arg;
19349 -- Start of processing for Common_Object/Psect_Object
19351 begin
19352 GNAT_Pragma;
19353 Gather_Associations (Names, Args);
19354 Process_Extended_Import_Export_Internal_Arg (Internal);
19356 Def_Id := Entity (Internal);
19358 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
19359 Error_Pragma_Arg
19360 ("pragma% must designate an object", Internal);
19361 end if;
19363 Check_Arg (Internal);
19365 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
19366 Error_Pragma_Arg
19367 ("cannot use pragma% for imported/exported object",
19368 Internal);
19369 end if;
19371 if Is_Concurrent_Type (Etype (Internal)) then
19372 Error_Pragma_Arg
19373 ("cannot specify pragma % for task/protected object",
19374 Internal);
19375 end if;
19377 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
19378 or else
19379 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
19380 then
19381 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
19382 end if;
19384 if Ekind (Def_Id) = E_Constant then
19385 Error_Pragma_Arg
19386 ("cannot specify pragma % for a constant", Internal);
19387 end if;
19389 if Is_Record_Type (Etype (Internal)) then
19390 declare
19391 Ent : Entity_Id;
19392 Decl : Entity_Id;
19394 begin
19395 Ent := First_Entity (Etype (Internal));
19396 while Present (Ent) loop
19397 Decl := Declaration_Node (Ent);
19399 if Ekind (Ent) = E_Component
19400 and then Nkind (Decl) = N_Component_Declaration
19401 and then Present (Expression (Decl))
19402 and then Warn_On_Export_Import
19403 then
19404 Error_Msg_N
19405 ("?x?object for pragma % has defaults", Internal);
19406 exit;
19408 else
19409 Next_Entity (Ent);
19410 end if;
19411 end loop;
19412 end;
19413 end if;
19415 if Present (Size) then
19416 Check_Arg (Size);
19417 end if;
19419 if Present (External) then
19420 Check_Arg_Is_External_Name (External);
19421 end if;
19423 -- If all error tests pass, link pragma on to the rep item chain
19425 Record_Rep_Item (Def_Id, N);
19426 end Psect_Object;
19428 ----------
19429 -- Pure --
19430 ----------
19432 -- pragma Pure [(library_unit_NAME)];
19434 when Pragma_Pure => Pure : declare
19435 Ent : Entity_Id;
19437 begin
19438 Check_Ada_83_Warning;
19440 -- If the pragma comes from a subprogram instantiation, nothing to
19441 -- check, this can happen at any level of nesting.
19443 if Is_Wrapper_Package (Current_Scope) then
19444 return;
19445 else
19446 Check_Valid_Library_Unit_Pragma;
19447 end if;
19449 if Nkind (N) = N_Null_Statement then
19450 return;
19451 end if;
19453 Ent := Find_Lib_Unit_Name;
19455 -- A pragma that applies to a Ghost entity becomes Ghost for the
19456 -- purposes of legality checks and removal of ignored Ghost code.
19458 Mark_Pragma_As_Ghost (N, Ent);
19460 if not Debug_Flag_U then
19461 Set_Is_Pure (Ent);
19462 Set_Has_Pragma_Pure (Ent);
19463 Set_Suppress_Elaboration_Warnings (Ent);
19464 end if;
19465 end Pure;
19467 -------------------
19468 -- Pure_Function --
19469 -------------------
19471 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
19473 when Pragma_Pure_Function => Pure_Function : declare
19474 Def_Id : Entity_Id;
19475 E : Entity_Id;
19476 E_Id : Node_Id;
19477 Effective : Boolean := False;
19479 begin
19480 GNAT_Pragma;
19481 Check_Arg_Count (1);
19482 Check_Optional_Identifier (Arg1, Name_Entity);
19483 Check_Arg_Is_Local_Name (Arg1);
19484 E_Id := Get_Pragma_Arg (Arg1);
19486 if Error_Posted (E_Id) then
19487 return;
19488 end if;
19490 -- Loop through homonyms (overloadings) of referenced entity
19492 E := Entity (E_Id);
19494 -- A pragma that applies to a Ghost entity becomes Ghost for the
19495 -- purposes of legality checks and removal of ignored Ghost code.
19497 Mark_Pragma_As_Ghost (N, E);
19499 if Present (E) then
19500 loop
19501 Def_Id := Get_Base_Subprogram (E);
19503 if not Ekind_In (Def_Id, E_Function,
19504 E_Generic_Function,
19505 E_Operator)
19506 then
19507 Error_Pragma_Arg
19508 ("pragma% requires a function name", Arg1);
19509 end if;
19511 Set_Is_Pure (Def_Id);
19513 if not Has_Pragma_Pure_Function (Def_Id) then
19514 Set_Has_Pragma_Pure_Function (Def_Id);
19515 Effective := True;
19516 end if;
19518 exit when From_Aspect_Specification (N);
19519 E := Homonym (E);
19520 exit when No (E) or else Scope (E) /= Current_Scope;
19521 end loop;
19523 if not Effective
19524 and then Warn_On_Redundant_Constructs
19525 then
19526 Error_Msg_NE
19527 ("pragma Pure_Function on& is redundant?r?",
19528 N, Entity (E_Id));
19529 end if;
19530 end if;
19531 end Pure_Function;
19533 --------------------
19534 -- Queuing_Policy --
19535 --------------------
19537 -- pragma Queuing_Policy (policy_IDENTIFIER);
19539 when Pragma_Queuing_Policy => declare
19540 QP : Character;
19542 begin
19543 Check_Ada_83_Warning;
19544 Check_Arg_Count (1);
19545 Check_No_Identifiers;
19546 Check_Arg_Is_Queuing_Policy (Arg1);
19547 Check_Valid_Configuration_Pragma;
19548 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
19549 QP := Fold_Upper (Name_Buffer (1));
19551 if Queuing_Policy /= ' '
19552 and then Queuing_Policy /= QP
19553 then
19554 Error_Msg_Sloc := Queuing_Policy_Sloc;
19555 Error_Pragma ("queuing policy incompatible with policy#");
19557 -- Set new policy, but always preserve System_Location since we
19558 -- like the error message with the run time name.
19560 else
19561 Queuing_Policy := QP;
19563 if Queuing_Policy_Sloc /= System_Location then
19564 Queuing_Policy_Sloc := Loc;
19565 end if;
19566 end if;
19567 end;
19569 --------------
19570 -- Rational --
19571 --------------
19573 -- pragma Rational, for compatibility with foreign compiler
19575 when Pragma_Rational =>
19576 Set_Rational_Profile;
19578 ---------------------
19579 -- Refined_Depends --
19580 ---------------------
19582 -- pragma Refined_Depends (DEPENDENCY_RELATION);
19584 -- DEPENDENCY_RELATION ::=
19585 -- null
19586 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
19588 -- DEPENDENCY_CLAUSE ::=
19589 -- OUTPUT_LIST =>[+] INPUT_LIST
19590 -- | NULL_DEPENDENCY_CLAUSE
19592 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
19594 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
19596 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
19598 -- OUTPUT ::= NAME | FUNCTION_RESULT
19599 -- INPUT ::= NAME
19601 -- where FUNCTION_RESULT is a function Result attribute_reference
19603 -- Characteristics:
19605 -- * Analysis - The annotation undergoes initial checks to verify
19606 -- the legal placement and context. Secondary checks fully analyze
19607 -- the dependency clauses/global list in:
19609 -- Analyze_Refined_Depends_In_Decl_Part
19611 -- * Expansion - None.
19613 -- * Template - The annotation utilizes the generic template of the
19614 -- related subprogram body.
19616 -- * Globals - Capture of global references must occur after full
19617 -- analysis.
19619 -- * Instance - The annotation is instantiated automatically when
19620 -- the related generic subprogram body is instantiated.
19622 when Pragma_Refined_Depends => Refined_Depends : declare
19623 Body_Id : Entity_Id;
19624 Legal : Boolean;
19625 Spec_Id : Entity_Id;
19627 begin
19628 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
19630 if Legal then
19632 -- Chain the pragma on the contract for further processing by
19633 -- Analyze_Refined_Depends_In_Decl_Part.
19635 Add_Contract_Item (N, Body_Id);
19637 -- The legality checks of pragmas Refined_Depends and
19638 -- Refined_Global are affected by the SPARK mode in effect and
19639 -- the volatility of the context. In addition these two pragmas
19640 -- are subject to an inherent order:
19642 -- 1) Refined_Global
19643 -- 2) Refined_Depends
19645 -- Analyze all these pragmas in the order outlined above
19647 Analyze_If_Present (Pragma_SPARK_Mode);
19648 Analyze_If_Present (Pragma_Volatile_Function);
19649 Analyze_If_Present (Pragma_Refined_Global);
19650 Analyze_Refined_Depends_In_Decl_Part (N);
19651 end if;
19652 end Refined_Depends;
19654 --------------------
19655 -- Refined_Global --
19656 --------------------
19658 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
19660 -- GLOBAL_SPECIFICATION ::=
19661 -- null
19662 -- | (GLOBAL_LIST)
19663 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
19665 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
19667 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
19668 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
19669 -- GLOBAL_ITEM ::= NAME
19671 -- Characteristics:
19673 -- * Analysis - The annotation undergoes initial checks to verify
19674 -- the legal placement and context. Secondary checks fully analyze
19675 -- the dependency clauses/global list in:
19677 -- Analyze_Refined_Global_In_Decl_Part
19679 -- * Expansion - None.
19681 -- * Template - The annotation utilizes the generic template of the
19682 -- related subprogram body.
19684 -- * Globals - Capture of global references must occur after full
19685 -- analysis.
19687 -- * Instance - The annotation is instantiated automatically when
19688 -- the related generic subprogram body is instantiated.
19690 when Pragma_Refined_Global => Refined_Global : declare
19691 Body_Id : Entity_Id;
19692 Legal : Boolean;
19693 Spec_Id : Entity_Id;
19695 begin
19696 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
19698 if Legal then
19700 -- Chain the pragma on the contract for further processing by
19701 -- Analyze_Refined_Global_In_Decl_Part.
19703 Add_Contract_Item (N, Body_Id);
19705 -- The legality checks of pragmas Refined_Depends and
19706 -- Refined_Global are affected by the SPARK mode in effect and
19707 -- the volatility of the context. In addition these two pragmas
19708 -- are subject to an inherent order:
19710 -- 1) Refined_Global
19711 -- 2) Refined_Depends
19713 -- Analyze all these pragmas in the order outlined above
19715 Analyze_If_Present (Pragma_SPARK_Mode);
19716 Analyze_If_Present (Pragma_Volatile_Function);
19717 Analyze_Refined_Global_In_Decl_Part (N);
19718 Analyze_If_Present (Pragma_Refined_Depends);
19719 end if;
19720 end Refined_Global;
19722 ------------------
19723 -- Refined_Post --
19724 ------------------
19726 -- pragma Refined_Post (boolean_EXPRESSION);
19728 -- Characteristics:
19730 -- * Analysis - The annotation is fully analyzed immediately upon
19731 -- elaboration as it cannot forward reference entities.
19733 -- * Expansion - The annotation is expanded during the expansion of
19734 -- the related subprogram body contract as performed in:
19736 -- Expand_Subprogram_Contract
19738 -- * Template - The annotation utilizes the generic template of the
19739 -- related subprogram body.
19741 -- * Globals - Capture of global references must occur after full
19742 -- analysis.
19744 -- * Instance - The annotation is instantiated automatically when
19745 -- the related generic subprogram body is instantiated.
19747 when Pragma_Refined_Post => Refined_Post : declare
19748 Body_Id : Entity_Id;
19749 Legal : Boolean;
19750 Spec_Id : Entity_Id;
19752 begin
19753 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
19755 -- Fully analyze the pragma when it appears inside a subprogram
19756 -- body because it cannot benefit from forward references.
19758 if Legal then
19760 -- Chain the pragma on the contract for completeness
19762 Add_Contract_Item (N, Body_Id);
19764 -- The legality checks of pragma Refined_Post are affected by
19765 -- the SPARK mode in effect and the volatility of the context.
19766 -- Analyze all pragmas in a specific order.
19768 Analyze_If_Present (Pragma_SPARK_Mode);
19769 Analyze_If_Present (Pragma_Volatile_Function);
19770 Analyze_Pre_Post_Condition_In_Decl_Part (N);
19772 -- Currently it is not possible to inline pre/postconditions on
19773 -- a subprogram subject to pragma Inline_Always.
19775 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
19776 end if;
19777 end Refined_Post;
19779 -------------------
19780 -- Refined_State --
19781 -------------------
19783 -- pragma Refined_State (REFINEMENT_LIST);
19785 -- REFINEMENT_LIST ::=
19786 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
19788 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
19790 -- CONSTITUENT_LIST ::=
19791 -- null
19792 -- | CONSTITUENT
19793 -- | (CONSTITUENT {, CONSTITUENT})
19795 -- CONSTITUENT ::= object_NAME | state_NAME
19797 -- Characteristics:
19799 -- * Analysis - The annotation undergoes initial checks to verify
19800 -- the legal placement and context. Secondary checks preanalyze the
19801 -- refinement clauses in:
19803 -- Analyze_Refined_State_In_Decl_Part
19805 -- * Expansion - None.
19807 -- * Template - The annotation utilizes the template of the related
19808 -- package body.
19810 -- * Globals - Capture of global references must occur after full
19811 -- analysis.
19813 -- * Instance - The annotation is instantiated automatically when
19814 -- the related generic package body is instantiated.
19816 when Pragma_Refined_State => Refined_State : declare
19817 Pack_Decl : Node_Id;
19818 Spec_Id : Entity_Id;
19820 begin
19821 GNAT_Pragma;
19822 Check_No_Identifiers;
19823 Check_Arg_Count (1);
19825 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
19827 -- Ensure the proper placement of the pragma. Refined states must
19828 -- be associated with a package body.
19830 if Nkind (Pack_Decl) = N_Package_Body then
19831 null;
19833 -- Otherwise the pragma is associated with an illegal construct
19835 else
19836 Pragma_Misplaced;
19837 return;
19838 end if;
19840 Spec_Id := Corresponding_Spec (Pack_Decl);
19842 -- Chain the pragma on the contract for further processing by
19843 -- Analyze_Refined_State_In_Decl_Part.
19845 Add_Contract_Item (N, Defining_Entity (Pack_Decl));
19847 -- The legality checks of pragma Refined_State are affected by the
19848 -- SPARK mode in effect. Analyze all pragmas in a specific order.
19850 Analyze_If_Present (Pragma_SPARK_Mode);
19852 -- A pragma that applies to a Ghost entity becomes Ghost for the
19853 -- purposes of legality checks and removal of ignored Ghost code.
19855 Mark_Pragma_As_Ghost (N, Spec_Id);
19857 -- State refinement is allowed only when the corresponding package
19858 -- declaration has non-null pragma Abstract_State. Refinement not
19859 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
19861 if SPARK_Mode /= Off
19862 and then
19863 (No (Abstract_States (Spec_Id))
19864 or else Has_Null_Abstract_State (Spec_Id))
19865 then
19866 Error_Msg_NE
19867 ("useless refinement, package & does not define abstract "
19868 & "states", N, Spec_Id);
19869 return;
19870 end if;
19871 end Refined_State;
19873 -----------------------
19874 -- Relative_Deadline --
19875 -----------------------
19877 -- pragma Relative_Deadline (time_span_EXPRESSION);
19879 when Pragma_Relative_Deadline => Relative_Deadline : declare
19880 P : constant Node_Id := Parent (N);
19881 Arg : Node_Id;
19883 begin
19884 Ada_2005_Pragma;
19885 Check_No_Identifiers;
19886 Check_Arg_Count (1);
19888 Arg := Get_Pragma_Arg (Arg1);
19890 -- The expression must be analyzed in the special manner described
19891 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
19893 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
19895 -- Subprogram case
19897 if Nkind (P) = N_Subprogram_Body then
19898 Check_In_Main_Program;
19900 -- Only Task and subprogram cases allowed
19902 elsif Nkind (P) /= N_Task_Definition then
19903 Pragma_Misplaced;
19904 end if;
19906 -- Check duplicate pragma before we set the corresponding flag
19908 if Has_Relative_Deadline_Pragma (P) then
19909 Error_Pragma ("duplicate pragma% not allowed");
19910 end if;
19912 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
19913 -- Relative_Deadline pragma node cannot be inserted in the Rep
19914 -- Item chain of Ent since it is rewritten by the expander as a
19915 -- procedure call statement that will break the chain.
19917 Set_Has_Relative_Deadline_Pragma (P);
19918 end Relative_Deadline;
19920 ------------------------
19921 -- Remote_Access_Type --
19922 ------------------------
19924 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
19926 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
19927 E : Entity_Id;
19929 begin
19930 GNAT_Pragma;
19931 Check_Arg_Count (1);
19932 Check_Optional_Identifier (Arg1, Name_Entity);
19933 Check_Arg_Is_Local_Name (Arg1);
19935 E := Entity (Get_Pragma_Arg (Arg1));
19937 -- A pragma that applies to a Ghost entity becomes Ghost for the
19938 -- purposes of legality checks and removal of ignored Ghost code.
19940 Mark_Pragma_As_Ghost (N, E);
19942 if Nkind (Parent (E)) = N_Formal_Type_Declaration
19943 and then Ekind (E) = E_General_Access_Type
19944 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
19945 and then Scope (Root_Type (Directly_Designated_Type (E)))
19946 = Scope (E)
19947 and then Is_Valid_Remote_Object_Type
19948 (Root_Type (Directly_Designated_Type (E)))
19949 then
19950 Set_Is_Remote_Types (E);
19952 else
19953 Error_Pragma_Arg
19954 ("pragma% applies only to formal access to classwide types",
19955 Arg1);
19956 end if;
19957 end Remote_Access_Type;
19959 ---------------------------
19960 -- Remote_Call_Interface --
19961 ---------------------------
19963 -- pragma Remote_Call_Interface [(library_unit_NAME)];
19965 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
19966 Cunit_Node : Node_Id;
19967 Cunit_Ent : Entity_Id;
19968 K : Node_Kind;
19970 begin
19971 Check_Ada_83_Warning;
19972 Check_Valid_Library_Unit_Pragma;
19974 if Nkind (N) = N_Null_Statement then
19975 return;
19976 end if;
19978 Cunit_Node := Cunit (Current_Sem_Unit);
19979 K := Nkind (Unit (Cunit_Node));
19980 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
19982 -- A pragma that applies to a Ghost entity becomes Ghost for the
19983 -- purposes of legality checks and removal of ignored Ghost code.
19985 Mark_Pragma_As_Ghost (N, Cunit_Ent);
19987 if K = N_Package_Declaration
19988 or else K = N_Generic_Package_Declaration
19989 or else K = N_Subprogram_Declaration
19990 or else K = N_Generic_Subprogram_Declaration
19991 or else (K = N_Subprogram_Body
19992 and then Acts_As_Spec (Unit (Cunit_Node)))
19993 then
19994 null;
19995 else
19996 Error_Pragma (
19997 "pragma% must apply to package or subprogram declaration");
19998 end if;
20000 Set_Is_Remote_Call_Interface (Cunit_Ent);
20001 end Remote_Call_Interface;
20003 ------------------
20004 -- Remote_Types --
20005 ------------------
20007 -- pragma Remote_Types [(library_unit_NAME)];
20009 when Pragma_Remote_Types => Remote_Types : declare
20010 Cunit_Node : Node_Id;
20011 Cunit_Ent : Entity_Id;
20013 begin
20014 Check_Ada_83_Warning;
20015 Check_Valid_Library_Unit_Pragma;
20017 if Nkind (N) = N_Null_Statement then
20018 return;
20019 end if;
20021 Cunit_Node := Cunit (Current_Sem_Unit);
20022 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
20024 -- A pragma that applies to a Ghost entity becomes Ghost for the
20025 -- purposes of legality checks and removal of ignored Ghost code.
20027 Mark_Pragma_As_Ghost (N, Cunit_Ent);
20029 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
20030 N_Generic_Package_Declaration)
20031 then
20032 Error_Pragma
20033 ("pragma% can only apply to a package declaration");
20034 end if;
20036 Set_Is_Remote_Types (Cunit_Ent);
20037 end Remote_Types;
20039 ---------------
20040 -- Ravenscar --
20041 ---------------
20043 -- pragma Ravenscar;
20045 when Pragma_Ravenscar =>
20046 GNAT_Pragma;
20047 Check_Arg_Count (0);
20048 Check_Valid_Configuration_Pragma;
20049 Set_Ravenscar_Profile (Ravenscar, N);
20051 if Warn_On_Obsolescent_Feature then
20052 Error_Msg_N
20053 ("pragma Ravenscar is an obsolescent feature?j?", N);
20054 Error_Msg_N
20055 ("|use pragma Profile (Ravenscar) instead?j?", N);
20056 end if;
20058 -------------------------
20059 -- Restricted_Run_Time --
20060 -------------------------
20062 -- pragma Restricted_Run_Time;
20064 when Pragma_Restricted_Run_Time =>
20065 GNAT_Pragma;
20066 Check_Arg_Count (0);
20067 Check_Valid_Configuration_Pragma;
20068 Set_Profile_Restrictions
20069 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
20071 if Warn_On_Obsolescent_Feature then
20072 Error_Msg_N
20073 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
20075 Error_Msg_N
20076 ("|use pragma Profile (Restricted) instead?j?", N);
20077 end if;
20079 ------------------
20080 -- Restrictions --
20081 ------------------
20083 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
20085 -- RESTRICTION ::=
20086 -- restriction_IDENTIFIER
20087 -- | restriction_parameter_IDENTIFIER => EXPRESSION
20089 when Pragma_Restrictions =>
20090 Process_Restrictions_Or_Restriction_Warnings
20091 (Warn => Treat_Restrictions_As_Warnings);
20093 --------------------------
20094 -- Restriction_Warnings --
20095 --------------------------
20097 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
20099 -- RESTRICTION ::=
20100 -- restriction_IDENTIFIER
20101 -- | restriction_parameter_IDENTIFIER => EXPRESSION
20103 when Pragma_Restriction_Warnings =>
20104 GNAT_Pragma;
20105 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
20107 ----------------
20108 -- Reviewable --
20109 ----------------
20111 -- pragma Reviewable;
20113 when Pragma_Reviewable =>
20114 Check_Ada_83_Warning;
20115 Check_Arg_Count (0);
20117 -- Call dummy debugging function rv. This is done to assist front
20118 -- end debugging. By placing a Reviewable pragma in the source
20119 -- program, a breakpoint on rv catches this place in the source,
20120 -- allowing convenient stepping to the point of interest.
20124 --------------------------
20125 -- Short_Circuit_And_Or --
20126 --------------------------
20128 -- pragma Short_Circuit_And_Or;
20130 when Pragma_Short_Circuit_And_Or =>
20131 GNAT_Pragma;
20132 Check_Arg_Count (0);
20133 Check_Valid_Configuration_Pragma;
20134 Short_Circuit_And_Or := True;
20136 -------------------
20137 -- Share_Generic --
20138 -------------------
20140 -- pragma Share_Generic (GNAME {, GNAME});
20142 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
20144 when Pragma_Share_Generic =>
20145 GNAT_Pragma;
20146 Process_Generic_List;
20148 ------------
20149 -- Shared --
20150 ------------
20152 -- pragma Shared (LOCAL_NAME);
20154 when Pragma_Shared =>
20155 GNAT_Pragma;
20156 Process_Atomic_Independent_Shared_Volatile;
20158 --------------------
20159 -- Shared_Passive --
20160 --------------------
20162 -- pragma Shared_Passive [(library_unit_NAME)];
20164 -- Set the flag Is_Shared_Passive of program unit name entity
20166 when Pragma_Shared_Passive => Shared_Passive : declare
20167 Cunit_Node : Node_Id;
20168 Cunit_Ent : Entity_Id;
20170 begin
20171 Check_Ada_83_Warning;
20172 Check_Valid_Library_Unit_Pragma;
20174 if Nkind (N) = N_Null_Statement then
20175 return;
20176 end if;
20178 Cunit_Node := Cunit (Current_Sem_Unit);
20179 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
20181 -- A pragma that applies to a Ghost entity becomes Ghost for the
20182 -- purposes of legality checks and removal of ignored Ghost code.
20184 Mark_Pragma_As_Ghost (N, Cunit_Ent);
20186 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
20187 N_Generic_Package_Declaration)
20188 then
20189 Error_Pragma
20190 ("pragma% can only apply to a package declaration");
20191 end if;
20193 Set_Is_Shared_Passive (Cunit_Ent);
20194 end Shared_Passive;
20196 -----------------------
20197 -- Short_Descriptors --
20198 -----------------------
20200 -- pragma Short_Descriptors;
20202 -- Recognize and validate, but otherwise ignore
20204 when Pragma_Short_Descriptors =>
20205 GNAT_Pragma;
20206 Check_Arg_Count (0);
20207 Check_Valid_Configuration_Pragma;
20209 ------------------------------
20210 -- Simple_Storage_Pool_Type --
20211 ------------------------------
20213 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
20215 when Pragma_Simple_Storage_Pool_Type =>
20216 Simple_Storage_Pool_Type : declare
20217 Typ : Entity_Id;
20218 Type_Id : Node_Id;
20220 begin
20221 GNAT_Pragma;
20222 Check_Arg_Count (1);
20223 Check_Arg_Is_Library_Level_Local_Name (Arg1);
20225 Type_Id := Get_Pragma_Arg (Arg1);
20226 Find_Type (Type_Id);
20227 Typ := Entity (Type_Id);
20229 if Typ = Any_Type then
20230 return;
20231 end if;
20233 -- A pragma that applies to a Ghost entity becomes Ghost for the
20234 -- purposes of legality checks and removal of ignored Ghost code.
20236 Mark_Pragma_As_Ghost (N, Typ);
20238 -- We require the pragma to apply to a type declared in a package
20239 -- declaration, but not (immediately) within a package body.
20241 if Ekind (Current_Scope) /= E_Package
20242 or else In_Package_Body (Current_Scope)
20243 then
20244 Error_Pragma
20245 ("pragma% can only apply to type declared immediately "
20246 & "within a package declaration");
20247 end if;
20249 -- A simple storage pool type must be an immutably limited record
20250 -- or private type. If the pragma is given for a private type,
20251 -- the full type is similarly restricted (which is checked later
20252 -- in Freeze_Entity).
20254 if Is_Record_Type (Typ)
20255 and then not Is_Limited_View (Typ)
20256 then
20257 Error_Pragma
20258 ("pragma% can only apply to explicitly limited record type");
20260 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
20261 Error_Pragma
20262 ("pragma% can only apply to a private type that is limited");
20264 elsif not Is_Record_Type (Typ)
20265 and then not Is_Private_Type (Typ)
20266 then
20267 Error_Pragma
20268 ("pragma% can only apply to limited record or private type");
20269 end if;
20271 Record_Rep_Item (Typ, N);
20272 end Simple_Storage_Pool_Type;
20274 ----------------------
20275 -- Source_File_Name --
20276 ----------------------
20278 -- There are five forms for this pragma:
20280 -- pragma Source_File_Name (
20281 -- [UNIT_NAME =>] unit_NAME,
20282 -- BODY_FILE_NAME => STRING_LITERAL
20283 -- [, [INDEX =>] INTEGER_LITERAL]);
20285 -- pragma Source_File_Name (
20286 -- [UNIT_NAME =>] unit_NAME,
20287 -- SPEC_FILE_NAME => STRING_LITERAL
20288 -- [, [INDEX =>] INTEGER_LITERAL]);
20290 -- pragma Source_File_Name (
20291 -- BODY_FILE_NAME => STRING_LITERAL
20292 -- [, DOT_REPLACEMENT => STRING_LITERAL]
20293 -- [, CASING => CASING_SPEC]);
20295 -- pragma Source_File_Name (
20296 -- SPEC_FILE_NAME => STRING_LITERAL
20297 -- [, DOT_REPLACEMENT => STRING_LITERAL]
20298 -- [, CASING => CASING_SPEC]);
20300 -- pragma Source_File_Name (
20301 -- SUBUNIT_FILE_NAME => STRING_LITERAL
20302 -- [, DOT_REPLACEMENT => STRING_LITERAL]
20303 -- [, CASING => CASING_SPEC]);
20305 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
20307 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
20308 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
20309 -- only be used when no project file is used, while SFNP can only be
20310 -- used when a project file is used.
20312 -- No processing here. Processing was completed during parsing, since
20313 -- we need to have file names set as early as possible. Units are
20314 -- loaded well before semantic processing starts.
20316 -- The only processing we defer to this point is the check for
20317 -- correct placement.
20319 when Pragma_Source_File_Name =>
20320 GNAT_Pragma;
20321 Check_Valid_Configuration_Pragma;
20323 ------------------------------
20324 -- Source_File_Name_Project --
20325 ------------------------------
20327 -- See Source_File_Name for syntax
20329 -- No processing here. Processing was completed during parsing, since
20330 -- we need to have file names set as early as possible. Units are
20331 -- loaded well before semantic processing starts.
20333 -- The only processing we defer to this point is the check for
20334 -- correct placement.
20336 when Pragma_Source_File_Name_Project =>
20337 GNAT_Pragma;
20338 Check_Valid_Configuration_Pragma;
20340 -- Check that a pragma Source_File_Name_Project is used only in a
20341 -- configuration pragmas file.
20343 -- Pragmas Source_File_Name_Project should only be generated by
20344 -- the Project Manager in configuration pragmas files.
20346 -- This is really an ugly test. It seems to depend on some
20347 -- accidental and undocumented property. At the very least it
20348 -- needs to be documented, but it would be better to have a
20349 -- clean way of testing if we are in a configuration file???
20351 if Present (Parent (N)) then
20352 Error_Pragma
20353 ("pragma% can only appear in a configuration pragmas file");
20354 end if;
20356 ----------------------
20357 -- Source_Reference --
20358 ----------------------
20360 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
20362 -- Nothing to do, all processing completed in Par.Prag, since we need
20363 -- the information for possible parser messages that are output.
20365 when Pragma_Source_Reference =>
20366 GNAT_Pragma;
20368 ----------------
20369 -- SPARK_Mode --
20370 ----------------
20372 -- pragma SPARK_Mode [(On | Off)];
20374 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
20375 Mode_Id : SPARK_Mode_Type;
20377 procedure Check_Pragma_Conformance
20378 (Context_Pragma : Node_Id;
20379 Entity : Entity_Id;
20380 Entity_Pragma : Node_Id);
20381 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
20382 -- conformance of pragma N depending the following scenarios:
20384 -- If pragma Context_Pragma is not Empty, verify that pragma N is
20385 -- compatible with the pragma Context_Pragma that was inherited
20386 -- from the context:
20387 -- * If the mode of Context_Pragma is ON, then the new mode can
20388 -- be anything.
20389 -- * If the mode of Context_Pragma is OFF, then the only allowed
20390 -- new mode is also OFF. Emit error if this is not the case.
20392 -- If Entity is not Empty, verify that pragma N is compatible with
20393 -- pragma Entity_Pragma that belongs to Entity.
20394 -- * If Entity_Pragma is Empty, always issue an error as this
20395 -- corresponds to the case where a previous section of Entity
20396 -- has no SPARK_Mode set.
20397 -- * If the mode of Entity_Pragma is ON, then the new mode can
20398 -- be anything.
20399 -- * If the mode of Entity_Pragma is OFF, then the only allowed
20400 -- new mode is also OFF. Emit error if this is not the case.
20402 procedure Check_Library_Level_Entity (E : Entity_Id);
20403 -- Subsidiary to routines Process_xxx. Verify that the related
20404 -- entity E subject to pragma SPARK_Mode is library-level.
20406 procedure Process_Body (Decl : Node_Id);
20407 -- Verify the legality of pragma SPARK_Mode when it appears as the
20408 -- top of the body declarations of entry, package, protected unit,
20409 -- subprogram or task unit body denoted by Decl.
20411 procedure Process_Overloadable (Decl : Node_Id);
20412 -- Verify the legality of pragma SPARK_Mode when it applies to an
20413 -- entry or [generic] subprogram declaration denoted by Decl.
20415 procedure Process_Private_Part (Decl : Node_Id);
20416 -- Verify the legality of pragma SPARK_Mode when it appears at the
20417 -- top of the private declarations of a package spec, protected or
20418 -- task unit declaration denoted by Decl.
20420 procedure Process_Statement_Part (Decl : Node_Id);
20421 -- Verify the legality of pragma SPARK_Mode when it appears at the
20422 -- top of the statement sequence of a package body denoted by node
20423 -- Decl.
20425 procedure Process_Visible_Part (Decl : Node_Id);
20426 -- Verify the legality of pragma SPARK_Mode when it appears at the
20427 -- top of the visible declarations of a package spec, protected or
20428 -- task unit declaration denoted by Decl. The routine is also used
20429 -- on protected or task units declared without a definition.
20431 procedure Set_SPARK_Context;
20432 -- Subsidiary to routines Process_xxx. Set the global variables
20433 -- which represent the mode of the context from pragma N. Ensure
20434 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
20436 ------------------------------
20437 -- Check_Pragma_Conformance --
20438 ------------------------------
20440 procedure Check_Pragma_Conformance
20441 (Context_Pragma : Node_Id;
20442 Entity : Entity_Id;
20443 Entity_Pragma : Node_Id)
20445 Err_Id : Entity_Id;
20446 Err_N : Node_Id;
20448 begin
20449 -- The current pragma may appear without an argument. If this
20450 -- is the case, associate all error messages with the pragma
20451 -- itself.
20453 if Present (Arg1) then
20454 Err_N := Arg1;
20455 else
20456 Err_N := N;
20457 end if;
20459 -- The mode of the current pragma is compared against that of
20460 -- an enclosing context.
20462 if Present (Context_Pragma) then
20463 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
20465 -- Issue an error if the new mode is less restrictive than
20466 -- that of the context.
20468 if Get_SPARK_Mode_From_Annotation (Context_Pragma) = Off
20469 and then Get_SPARK_Mode_From_Annotation (N) = On
20470 then
20471 Error_Msg_N
20472 ("cannot change SPARK_Mode from Off to On", Err_N);
20473 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
20474 Error_Msg_N ("\SPARK_Mode was set to Off#", Err_N);
20475 raise Pragma_Exit;
20476 end if;
20477 end if;
20479 -- The mode of the current pragma is compared against that of
20480 -- an initial package, protected type, subprogram or task type
20481 -- declaration.
20483 if Present (Entity) then
20485 -- A simple protected or task type is transformed into an
20486 -- anonymous type whose name cannot be used to issue error
20487 -- messages. Recover the original entity of the type.
20489 if Ekind_In (Entity, E_Protected_Type, E_Task_Type) then
20490 Err_Id :=
20491 Defining_Entity
20492 (Original_Node (Unit_Declaration_Node (Entity)));
20493 else
20494 Err_Id := Entity;
20495 end if;
20497 -- Both the initial declaration and the completion carry
20498 -- SPARK_Mode pragmas.
20500 if Present (Entity_Pragma) then
20501 pragma Assert (Nkind (Entity_Pragma) = N_Pragma);
20503 -- Issue an error if the new mode is less restrictive
20504 -- than that of the initial declaration.
20506 if Get_SPARK_Mode_From_Annotation (Entity_Pragma) = Off
20507 and then Get_SPARK_Mode_From_Annotation (N) = On
20508 then
20509 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
20510 Error_Msg_Sloc := Sloc (Entity_Pragma);
20511 Error_Msg_NE
20512 ("\value Off was set for SPARK_Mode on&#",
20513 Err_N, Err_Id);
20514 raise Pragma_Exit;
20515 end if;
20517 -- Otherwise the initial declaration lacks a SPARK_Mode
20518 -- pragma in which case the current pragma is illegal as
20519 -- it cannot "complete".
20521 else
20522 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
20523 Error_Msg_Sloc := Sloc (Err_Id);
20524 Error_Msg_NE
20525 ("\no value was set for SPARK_Mode on&#",
20526 Err_N, Err_Id);
20527 raise Pragma_Exit;
20528 end if;
20529 end if;
20530 end Check_Pragma_Conformance;
20532 --------------------------------
20533 -- Check_Library_Level_Entity --
20534 --------------------------------
20536 procedure Check_Library_Level_Entity (E : Entity_Id) is
20537 procedure Add_Entity_To_Name_Buffer;
20538 -- Add the E_Kind of entity E to the name buffer
20540 -------------------------------
20541 -- Add_Entity_To_Name_Buffer --
20542 -------------------------------
20544 procedure Add_Entity_To_Name_Buffer is
20545 begin
20546 if Ekind_In (E, E_Entry, E_Entry_Family) then
20547 Add_Str_To_Name_Buffer ("entry");
20549 elsif Ekind_In (E, E_Generic_Package,
20550 E_Package,
20551 E_Package_Body)
20552 then
20553 Add_Str_To_Name_Buffer ("package");
20555 elsif Ekind_In (E, E_Protected_Body, E_Protected_Type) then
20556 Add_Str_To_Name_Buffer ("protected type");
20558 elsif Ekind_In (E, E_Function,
20559 E_Generic_Function,
20560 E_Generic_Procedure,
20561 E_Procedure,
20562 E_Subprogram_Body)
20563 then
20564 Add_Str_To_Name_Buffer ("subprogram");
20566 else
20567 pragma Assert (Ekind_In (E, E_Task_Body, E_Task_Type));
20568 Add_Str_To_Name_Buffer ("task type");
20569 end if;
20570 end Add_Entity_To_Name_Buffer;
20572 -- Local variables
20574 Msg_1 : constant String := "incorrect placement of pragma%";
20575 Msg_2 : Name_Id;
20577 -- Start of processing for Check_Library_Level_Entity
20579 begin
20580 if not Is_Library_Level_Entity (E) then
20581 Error_Msg_Name_1 := Pname;
20582 Error_Msg_N (Fix_Error (Msg_1), N);
20584 Name_Len := 0;
20585 Add_Str_To_Name_Buffer ("\& is not a library-level ");
20586 Add_Entity_To_Name_Buffer;
20588 Msg_2 := Name_Find;
20589 Error_Msg_NE (Get_Name_String (Msg_2), N, E);
20591 raise Pragma_Exit;
20592 end if;
20593 end Check_Library_Level_Entity;
20595 ------------------
20596 -- Process_Body --
20597 ------------------
20599 procedure Process_Body (Decl : Node_Id) is
20600 Body_Id : constant Entity_Id := Defining_Entity (Decl);
20601 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
20603 begin
20604 -- Ignore pragma when applied to the special body created for
20605 -- inlining, recognized by its internal name _Parent.
20607 if Chars (Body_Id) = Name_uParent then
20608 return;
20609 end if;
20611 Check_Library_Level_Entity (Body_Id);
20613 -- For entry bodies, verify the legality against:
20614 -- * The mode of the context
20615 -- * The mode of the spec (if any)
20617 if Nkind_In (Decl, N_Entry_Body, N_Subprogram_Body) then
20619 -- A stand alone subprogram body
20621 if Body_Id = Spec_Id then
20622 Check_Pragma_Conformance
20623 (Context_Pragma => SPARK_Pragma (Body_Id),
20624 Entity => Empty,
20625 Entity_Pragma => Empty);
20627 -- An entry or subprogram body that completes a previous
20628 -- declaration.
20630 else
20631 Check_Pragma_Conformance
20632 (Context_Pragma => SPARK_Pragma (Body_Id),
20633 Entity => Spec_Id,
20634 Entity_Pragma => SPARK_Pragma (Spec_Id));
20635 end if;
20637 Set_SPARK_Context;
20638 Set_SPARK_Pragma (Body_Id, N);
20639 Set_SPARK_Pragma_Inherited (Body_Id, False);
20641 -- For package bodies, verify the legality against:
20642 -- * The mode of the context
20643 -- * The mode of the private part
20645 -- This case is separated from protected and task bodies
20646 -- because the statement part of the package body inherits
20647 -- the mode of the body declarations.
20649 elsif Nkind (Decl) = N_Package_Body then
20650 Check_Pragma_Conformance
20651 (Context_Pragma => SPARK_Pragma (Body_Id),
20652 Entity => Spec_Id,
20653 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
20655 Set_SPARK_Context;
20656 Set_SPARK_Pragma (Body_Id, N);
20657 Set_SPARK_Pragma_Inherited (Body_Id, False);
20658 Set_SPARK_Aux_Pragma (Body_Id, N);
20659 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
20661 -- For protected and task bodies, verify the legality against:
20662 -- * The mode of the context
20663 -- * The mode of the private part
20665 else
20666 pragma Assert
20667 (Nkind_In (Decl, N_Protected_Body, N_Task_Body));
20669 Check_Pragma_Conformance
20670 (Context_Pragma => SPARK_Pragma (Body_Id),
20671 Entity => Spec_Id,
20672 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
20674 Set_SPARK_Context;
20675 Set_SPARK_Pragma (Body_Id, N);
20676 Set_SPARK_Pragma_Inherited (Body_Id, False);
20677 end if;
20678 end Process_Body;
20680 --------------------------
20681 -- Process_Overloadable --
20682 --------------------------
20684 procedure Process_Overloadable (Decl : Node_Id) is
20685 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
20686 Spec_Typ : constant Entity_Id := Etype (Spec_Id);
20688 begin
20689 Check_Library_Level_Entity (Spec_Id);
20691 -- Verify the legality against:
20692 -- * The mode of the context
20694 Check_Pragma_Conformance
20695 (Context_Pragma => SPARK_Pragma (Spec_Id),
20696 Entity => Empty,
20697 Entity_Pragma => Empty);
20699 Set_SPARK_Pragma (Spec_Id, N);
20700 Set_SPARK_Pragma_Inherited (Spec_Id, False);
20702 -- When the pragma applies to the anonymous object created for
20703 -- a single task type, decorate the type as well. This scenario
20704 -- arises when the single task type lacks a task definition,
20705 -- therefore there is no issue with respect to a potential
20706 -- pragma SPARK_Mode in the private part.
20708 -- task type Anon_Task_Typ;
20709 -- Obj : Anon_Task_Typ;
20710 -- pragma SPARK_Mode ...;
20712 if Is_Single_Task_Object (Spec_Id) then
20713 Set_SPARK_Pragma (Spec_Typ, N);
20714 Set_SPARK_Pragma_Inherited (Spec_Typ, False);
20715 Set_SPARK_Aux_Pragma (Spec_Typ, N);
20716 Set_SPARK_Aux_Pragma_Inherited (Spec_Typ, True);
20717 end if;
20718 end Process_Overloadable;
20720 --------------------------
20721 -- Process_Private_Part --
20722 --------------------------
20724 procedure Process_Private_Part (Decl : Node_Id) is
20725 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
20727 begin
20728 Check_Library_Level_Entity (Spec_Id);
20730 -- Verify the legality against:
20731 -- * The mode of the visible declarations
20733 Check_Pragma_Conformance
20734 (Context_Pragma => Empty,
20735 Entity => Spec_Id,
20736 Entity_Pragma => SPARK_Pragma (Spec_Id));
20738 Set_SPARK_Context;
20739 Set_SPARK_Aux_Pragma (Spec_Id, N);
20740 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
20741 end Process_Private_Part;
20743 ----------------------------
20744 -- Process_Statement_Part --
20745 ----------------------------
20747 procedure Process_Statement_Part (Decl : Node_Id) is
20748 Body_Id : constant Entity_Id := Defining_Entity (Decl);
20750 begin
20751 Check_Library_Level_Entity (Body_Id);
20753 -- Verify the legality against:
20754 -- * The mode of the body declarations
20756 Check_Pragma_Conformance
20757 (Context_Pragma => Empty,
20758 Entity => Body_Id,
20759 Entity_Pragma => SPARK_Pragma (Body_Id));
20761 Set_SPARK_Context;
20762 Set_SPARK_Aux_Pragma (Body_Id, N);
20763 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
20764 end Process_Statement_Part;
20766 --------------------------
20767 -- Process_Visible_Part --
20768 --------------------------
20770 procedure Process_Visible_Part (Decl : Node_Id) is
20771 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
20772 Obj_Id : Entity_Id;
20774 begin
20775 Check_Library_Level_Entity (Spec_Id);
20777 -- Verify the legality against:
20778 -- * The mode of the context
20780 Check_Pragma_Conformance
20781 (Context_Pragma => SPARK_Pragma (Spec_Id),
20782 Entity => Empty,
20783 Entity_Pragma => Empty);
20785 -- A task unit declared without a definition does not set the
20786 -- SPARK_Mode of the context because the task does not have any
20787 -- entries that could inherit the mode.
20789 if not Nkind_In (Decl, N_Single_Task_Declaration,
20790 N_Task_Type_Declaration)
20791 then
20792 Set_SPARK_Context;
20793 end if;
20795 Set_SPARK_Pragma (Spec_Id, N);
20796 Set_SPARK_Pragma_Inherited (Spec_Id, False);
20797 Set_SPARK_Aux_Pragma (Spec_Id, N);
20798 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
20800 -- When the pragma applies to a single protected or task type,
20801 -- decorate the corresponding anonymous object as well.
20803 -- protected Anon_Prot_Typ is
20804 -- pragma SPARK_Mode ...;
20805 -- ...
20806 -- end Anon_Prot_Typ;
20808 -- Obj : Anon_Prot_Typ;
20810 if Is_Single_Concurrent_Type (Spec_Id) then
20811 Obj_Id := Anonymous_Object (Spec_Id);
20813 Set_SPARK_Pragma (Obj_Id, N);
20814 Set_SPARK_Pragma_Inherited (Obj_Id, False);
20815 end if;
20816 end Process_Visible_Part;
20818 -----------------------
20819 -- Set_SPARK_Context --
20820 -----------------------
20822 procedure Set_SPARK_Context is
20823 begin
20824 SPARK_Mode := Mode_Id;
20825 SPARK_Mode_Pragma := N;
20827 if SPARK_Mode = On then
20828 Dynamic_Elaboration_Checks := False;
20829 end if;
20830 end Set_SPARK_Context;
20832 -- Local variables
20834 Context : Node_Id;
20835 Mode : Name_Id;
20836 Stmt : Node_Id;
20838 -- Start of processing for Do_SPARK_Mode
20840 begin
20841 -- When a SPARK_Mode pragma appears inside an instantiation whose
20842 -- enclosing context has SPARK_Mode set to "off", the pragma has
20843 -- no semantic effect.
20845 if Ignore_Pragma_SPARK_Mode then
20846 Rewrite (N, Make_Null_Statement (Loc));
20847 Analyze (N);
20848 return;
20849 end if;
20851 GNAT_Pragma;
20852 Check_No_Identifiers;
20853 Check_At_Most_N_Arguments (1);
20855 -- Check the legality of the mode (no argument = ON)
20857 if Arg_Count = 1 then
20858 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
20859 Mode := Chars (Get_Pragma_Arg (Arg1));
20860 else
20861 Mode := Name_On;
20862 end if;
20864 Mode_Id := Get_SPARK_Mode_Type (Mode);
20865 Context := Parent (N);
20867 -- The pragma appears in a configuration pragmas file
20869 if No (Context) then
20870 Check_Valid_Configuration_Pragma;
20872 if Present (SPARK_Mode_Pragma) then
20873 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
20874 Error_Msg_N ("pragma% duplicates pragma declared#", N);
20875 raise Pragma_Exit;
20876 end if;
20878 Set_SPARK_Context;
20880 -- The pragma acts as a configuration pragma in a compilation unit
20882 -- pragma SPARK_Mode ...;
20883 -- package Pack is ...;
20885 elsif Nkind (Context) = N_Compilation_Unit
20886 and then List_Containing (N) = Context_Items (Context)
20887 then
20888 Check_Valid_Configuration_Pragma;
20889 Set_SPARK_Context;
20891 -- Otherwise the placement of the pragma within the tree dictates
20892 -- its associated construct. Inspect the declarative list where
20893 -- the pragma resides to find a potential construct.
20895 else
20896 Stmt := Prev (N);
20897 while Present (Stmt) loop
20899 -- Skip prior pragmas, but check for duplicates. Note that
20900 -- this also takes care of pragmas generated for aspects.
20902 if Nkind (Stmt) = N_Pragma then
20903 if Pragma_Name (Stmt) = Pname then
20904 Error_Msg_Name_1 := Pname;
20905 Error_Msg_Sloc := Sloc (Stmt);
20906 Error_Msg_N ("pragma% duplicates pragma declared#", N);
20907 raise Pragma_Exit;
20908 end if;
20910 -- The pragma applies to an expression function that has
20911 -- already been rewritten into a subprogram declaration.
20913 -- function Expr_Func return ... is (...);
20914 -- pragma SPARK_Mode ...;
20916 elsif Nkind (Stmt) = N_Subprogram_Declaration
20917 and then Nkind (Original_Node (Stmt)) =
20918 N_Expression_Function
20919 then
20920 Process_Overloadable (Stmt);
20921 return;
20923 -- The pragma applies to the anonymous object created for a
20924 -- single concurrent type.
20926 -- protected type Anon_Prot_Typ ...;
20927 -- Obj : Anon_Prot_Typ;
20928 -- pragma SPARK_Mode ...;
20930 elsif Nkind (Stmt) = N_Object_Declaration
20931 and then Is_Single_Concurrent_Object
20932 (Defining_Entity (Stmt))
20933 then
20934 Process_Overloadable (Stmt);
20935 return;
20937 -- Skip internally generated code
20939 elsif not Comes_From_Source (Stmt) then
20940 null;
20942 -- The pragma applies to an entry or [generic] subprogram
20943 -- declaration.
20945 -- entry Ent ...;
20946 -- pragma SPARK_Mode ...;
20948 -- [generic]
20949 -- procedure Proc ...;
20950 -- pragma SPARK_Mode ...;
20952 elsif Nkind_In (Stmt, N_Generic_Subprogram_Declaration,
20953 N_Subprogram_Declaration)
20954 or else (Nkind (Stmt) = N_Entry_Declaration
20955 and then Is_Protected_Type
20956 (Scope (Defining_Entity (Stmt))))
20957 then
20958 Process_Overloadable (Stmt);
20959 return;
20961 -- Otherwise the pragma does not apply to a legal construct
20962 -- or it does not appear at the top of a declarative or a
20963 -- statement list. Issue an error and stop the analysis.
20965 else
20966 Pragma_Misplaced;
20967 exit;
20968 end if;
20970 Prev (Stmt);
20971 end loop;
20973 -- The pragma applies to a package or a subprogram that acts as
20974 -- a compilation unit.
20976 -- procedure Proc ...;
20977 -- pragma SPARK_Mode ...;
20979 if Nkind (Context) = N_Compilation_Unit_Aux then
20980 Context := Unit (Parent (Context));
20981 end if;
20983 -- The pragma appears at the top of entry, package, protected
20984 -- unit, subprogram or task unit body declarations.
20986 -- entry Ent when ... is
20987 -- pragma SPARK_Mode ...;
20989 -- package body Pack is
20990 -- pragma SPARK_Mode ...;
20992 -- procedure Proc ... is
20993 -- pragma SPARK_Mode;
20995 -- protected body Prot is
20996 -- pragma SPARK_Mode ...;
20998 if Nkind_In (Context, N_Entry_Body,
20999 N_Package_Body,
21000 N_Protected_Body,
21001 N_Subprogram_Body,
21002 N_Task_Body)
21003 then
21004 Process_Body (Context);
21006 -- The pragma appears at the top of the visible or private
21007 -- declaration of a package spec, protected or task unit.
21009 -- package Pack is
21010 -- pragma SPARK_Mode ...;
21011 -- private
21012 -- pragma SPARK_Mode ...;
21014 -- protected [type] Prot is
21015 -- pragma SPARK_Mode ...;
21016 -- private
21017 -- pragma SPARK_Mode ...;
21019 elsif Nkind_In (Context, N_Package_Specification,
21020 N_Protected_Definition,
21021 N_Task_Definition)
21022 then
21023 if List_Containing (N) = Visible_Declarations (Context) then
21024 Process_Visible_Part (Parent (Context));
21025 else
21026 Process_Private_Part (Parent (Context));
21027 end if;
21029 -- The pragma appears at the top of package body statements
21031 -- package body Pack is
21032 -- begin
21033 -- pragma SPARK_Mode;
21035 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
21036 and then Nkind (Parent (Context)) = N_Package_Body
21037 then
21038 Process_Statement_Part (Parent (Context));
21040 -- The pragma appeared as an aspect of a [generic] subprogram
21041 -- declaration that acts as a compilation unit.
21043 -- [generic]
21044 -- procedure Proc ...;
21045 -- pragma SPARK_Mode ...;
21047 elsif Nkind_In (Context, N_Generic_Subprogram_Declaration,
21048 N_Subprogram_Declaration)
21049 then
21050 Process_Overloadable (Context);
21052 -- The pragma does not apply to a legal construct, issue error
21054 else
21055 Pragma_Misplaced;
21056 end if;
21057 end if;
21058 end Do_SPARK_Mode;
21060 --------------------------------
21061 -- Static_Elaboration_Desired --
21062 --------------------------------
21064 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
21066 when Pragma_Static_Elaboration_Desired =>
21067 GNAT_Pragma;
21068 Check_At_Most_N_Arguments (1);
21070 if Is_Compilation_Unit (Current_Scope)
21071 and then Ekind (Current_Scope) = E_Package
21072 then
21073 Set_Static_Elaboration_Desired (Current_Scope, True);
21074 else
21075 Error_Pragma ("pragma% must apply to a library-level package");
21076 end if;
21078 ------------------
21079 -- Storage_Size --
21080 ------------------
21082 -- pragma Storage_Size (EXPRESSION);
21084 when Pragma_Storage_Size => Storage_Size : declare
21085 P : constant Node_Id := Parent (N);
21086 Arg : Node_Id;
21088 begin
21089 Check_No_Identifiers;
21090 Check_Arg_Count (1);
21092 -- The expression must be analyzed in the special manner described
21093 -- in "Handling of Default Expressions" in sem.ads.
21095 Arg := Get_Pragma_Arg (Arg1);
21096 Preanalyze_Spec_Expression (Arg, Any_Integer);
21098 if not Is_OK_Static_Expression (Arg) then
21099 Check_Restriction (Static_Storage_Size, Arg);
21100 end if;
21102 if Nkind (P) /= N_Task_Definition then
21103 Pragma_Misplaced;
21104 return;
21106 else
21107 if Has_Storage_Size_Pragma (P) then
21108 Error_Pragma ("duplicate pragma% not allowed");
21109 else
21110 Set_Has_Storage_Size_Pragma (P, True);
21111 end if;
21113 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
21114 end if;
21115 end Storage_Size;
21117 ------------------
21118 -- Storage_Unit --
21119 ------------------
21121 -- pragma Storage_Unit (NUMERIC_LITERAL);
21123 -- Only permitted argument is System'Storage_Unit value
21125 when Pragma_Storage_Unit =>
21126 Check_No_Identifiers;
21127 Check_Arg_Count (1);
21128 Check_Arg_Is_Integer_Literal (Arg1);
21130 if Intval (Get_Pragma_Arg (Arg1)) /=
21131 UI_From_Int (Ttypes.System_Storage_Unit)
21132 then
21133 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
21134 Error_Pragma_Arg
21135 ("the only allowed argument for pragma% is ^", Arg1);
21136 end if;
21138 --------------------
21139 -- Stream_Convert --
21140 --------------------
21142 -- pragma Stream_Convert (
21143 -- [Entity =>] type_LOCAL_NAME,
21144 -- [Read =>] function_NAME,
21145 -- [Write =>] function NAME);
21147 when Pragma_Stream_Convert => Stream_Convert : declare
21149 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
21150 -- Check that the given argument is the name of a local function
21151 -- of one argument that is not overloaded earlier in the current
21152 -- local scope. A check is also made that the argument is a
21153 -- function with one parameter.
21155 --------------------------------------
21156 -- Check_OK_Stream_Convert_Function --
21157 --------------------------------------
21159 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
21160 Ent : Entity_Id;
21162 begin
21163 Check_Arg_Is_Local_Name (Arg);
21164 Ent := Entity (Get_Pragma_Arg (Arg));
21166 if Has_Homonym (Ent) then
21167 Error_Pragma_Arg
21168 ("argument for pragma% may not be overloaded", Arg);
21169 end if;
21171 if Ekind (Ent) /= E_Function
21172 or else No (First_Formal (Ent))
21173 or else Present (Next_Formal (First_Formal (Ent)))
21174 then
21175 Error_Pragma_Arg
21176 ("argument for pragma% must be function of one argument",
21177 Arg);
21178 end if;
21179 end Check_OK_Stream_Convert_Function;
21181 -- Start of processing for Stream_Convert
21183 begin
21184 GNAT_Pragma;
21185 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
21186 Check_Arg_Count (3);
21187 Check_Optional_Identifier (Arg1, Name_Entity);
21188 Check_Optional_Identifier (Arg2, Name_Read);
21189 Check_Optional_Identifier (Arg3, Name_Write);
21190 Check_Arg_Is_Local_Name (Arg1);
21191 Check_OK_Stream_Convert_Function (Arg2);
21192 Check_OK_Stream_Convert_Function (Arg3);
21194 declare
21195 Typ : constant Entity_Id :=
21196 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
21197 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
21198 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
21200 begin
21201 Check_First_Subtype (Arg1);
21203 -- Check for too early or too late. Note that we don't enforce
21204 -- the rule about primitive operations in this case, since, as
21205 -- is the case for explicit stream attributes themselves, these
21206 -- restrictions are not appropriate. Note that the chaining of
21207 -- the pragma by Rep_Item_Too_Late is actually the critical
21208 -- processing done for this pragma.
21210 if Rep_Item_Too_Early (Typ, N)
21211 or else
21212 Rep_Item_Too_Late (Typ, N, FOnly => True)
21213 then
21214 return;
21215 end if;
21217 -- Return if previous error
21219 if Etype (Typ) = Any_Type
21220 or else
21221 Etype (Read) = Any_Type
21222 or else
21223 Etype (Write) = Any_Type
21224 then
21225 return;
21226 end if;
21228 -- Error checks
21230 if Underlying_Type (Etype (Read)) /= Typ then
21231 Error_Pragma_Arg
21232 ("incorrect return type for function&", Arg2);
21233 end if;
21235 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
21236 Error_Pragma_Arg
21237 ("incorrect parameter type for function&", Arg3);
21238 end if;
21240 if Underlying_Type (Etype (First_Formal (Read))) /=
21241 Underlying_Type (Etype (Write))
21242 then
21243 Error_Pragma_Arg
21244 ("result type of & does not match Read parameter type",
21245 Arg3);
21246 end if;
21247 end;
21248 end Stream_Convert;
21250 ------------------
21251 -- Style_Checks --
21252 ------------------
21254 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
21256 -- This is processed by the parser since some of the style checks
21257 -- take place during source scanning and parsing. This means that
21258 -- we don't need to issue error messages here.
21260 when Pragma_Style_Checks => Style_Checks : declare
21261 A : constant Node_Id := Get_Pragma_Arg (Arg1);
21262 S : String_Id;
21263 C : Char_Code;
21265 begin
21266 GNAT_Pragma;
21267 Check_No_Identifiers;
21269 -- Two argument form
21271 if Arg_Count = 2 then
21272 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
21274 declare
21275 E_Id : Node_Id;
21276 E : Entity_Id;
21278 begin
21279 E_Id := Get_Pragma_Arg (Arg2);
21280 Analyze (E_Id);
21282 if not Is_Entity_Name (E_Id) then
21283 Error_Pragma_Arg
21284 ("second argument of pragma% must be entity name",
21285 Arg2);
21286 end if;
21288 E := Entity (E_Id);
21290 if not Ignore_Style_Checks_Pragmas then
21291 if E = Any_Id then
21292 return;
21293 else
21294 loop
21295 Set_Suppress_Style_Checks
21296 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
21297 exit when No (Homonym (E));
21298 E := Homonym (E);
21299 end loop;
21300 end if;
21301 end if;
21302 end;
21304 -- One argument form
21306 else
21307 Check_Arg_Count (1);
21309 if Nkind (A) = N_String_Literal then
21310 S := Strval (A);
21312 declare
21313 Slen : constant Natural := Natural (String_Length (S));
21314 Options : String (1 .. Slen);
21315 J : Positive;
21317 begin
21318 J := 1;
21319 loop
21320 C := Get_String_Char (S, Pos (J));
21321 exit when not In_Character_Range (C);
21322 Options (J) := Get_Character (C);
21324 -- If at end of string, set options. As per discussion
21325 -- above, no need to check for errors, since we issued
21326 -- them in the parser.
21328 if J = Slen then
21329 if not Ignore_Style_Checks_Pragmas then
21330 Set_Style_Check_Options (Options);
21331 end if;
21333 exit;
21334 end if;
21336 J := J + 1;
21337 end loop;
21338 end;
21340 elsif Nkind (A) = N_Identifier then
21341 if Chars (A) = Name_All_Checks then
21342 if not Ignore_Style_Checks_Pragmas then
21343 if GNAT_Mode then
21344 Set_GNAT_Style_Check_Options;
21345 else
21346 Set_Default_Style_Check_Options;
21347 end if;
21348 end if;
21350 elsif Chars (A) = Name_On then
21351 if not Ignore_Style_Checks_Pragmas then
21352 Style_Check := True;
21353 end if;
21355 elsif Chars (A) = Name_Off then
21356 if not Ignore_Style_Checks_Pragmas then
21357 Style_Check := False;
21358 end if;
21359 end if;
21360 end if;
21361 end if;
21362 end Style_Checks;
21364 --------------
21365 -- Subtitle --
21366 --------------
21368 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
21370 when Pragma_Subtitle =>
21371 GNAT_Pragma;
21372 Check_Arg_Count (1);
21373 Check_Optional_Identifier (Arg1, Name_Subtitle);
21374 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
21375 Store_Note (N);
21377 --------------
21378 -- Suppress --
21379 --------------
21381 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
21383 when Pragma_Suppress =>
21384 Process_Suppress_Unsuppress (Suppress_Case => True);
21386 ------------------
21387 -- Suppress_All --
21388 ------------------
21390 -- pragma Suppress_All;
21392 -- The only check made here is that the pragma has no arguments.
21393 -- There are no placement rules, and the processing required (setting
21394 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
21395 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
21396 -- then creates and inserts a pragma Suppress (All_Checks).
21398 when Pragma_Suppress_All =>
21399 GNAT_Pragma;
21400 Check_Arg_Count (0);
21402 -------------------------
21403 -- Suppress_Debug_Info --
21404 -------------------------
21406 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
21408 when Pragma_Suppress_Debug_Info => Suppress_Debug_Info : declare
21409 Nam_Id : Entity_Id;
21411 begin
21412 GNAT_Pragma;
21413 Check_Arg_Count (1);
21414 Check_Optional_Identifier (Arg1, Name_Entity);
21415 Check_Arg_Is_Local_Name (Arg1);
21417 Nam_Id := Entity (Get_Pragma_Arg (Arg1));
21419 -- A pragma that applies to a Ghost entity becomes Ghost for the
21420 -- purposes of legality checks and removal of ignored Ghost code.
21422 Mark_Pragma_As_Ghost (N, Nam_Id);
21423 Set_Debug_Info_Off (Nam_Id);
21424 end Suppress_Debug_Info;
21426 ----------------------------------
21427 -- Suppress_Exception_Locations --
21428 ----------------------------------
21430 -- pragma Suppress_Exception_Locations;
21432 when Pragma_Suppress_Exception_Locations =>
21433 GNAT_Pragma;
21434 Check_Arg_Count (0);
21435 Check_Valid_Configuration_Pragma;
21436 Exception_Locations_Suppressed := True;
21438 -----------------------------
21439 -- Suppress_Initialization --
21440 -----------------------------
21442 -- pragma Suppress_Initialization ([Entity =>] type_Name);
21444 when Pragma_Suppress_Initialization => Suppress_Init : declare
21445 E : Entity_Id;
21446 E_Id : Node_Id;
21448 begin
21449 GNAT_Pragma;
21450 Check_Arg_Count (1);
21451 Check_Optional_Identifier (Arg1, Name_Entity);
21452 Check_Arg_Is_Local_Name (Arg1);
21454 E_Id := Get_Pragma_Arg (Arg1);
21456 if Etype (E_Id) = Any_Type then
21457 return;
21458 end if;
21460 E := Entity (E_Id);
21462 -- A pragma that applies to a Ghost entity becomes Ghost for the
21463 -- purposes of legality checks and removal of ignored Ghost code.
21465 Mark_Pragma_As_Ghost (N, E);
21467 if not Is_Type (E) and then Ekind (E) /= E_Variable then
21468 Error_Pragma_Arg
21469 ("pragma% requires variable, type or subtype", Arg1);
21470 end if;
21472 if Rep_Item_Too_Early (E, N)
21473 or else
21474 Rep_Item_Too_Late (E, N, FOnly => True)
21475 then
21476 return;
21477 end if;
21479 -- For incomplete/private type, set flag on full view
21481 if Is_Incomplete_Or_Private_Type (E) then
21482 if No (Full_View (Base_Type (E))) then
21483 Error_Pragma_Arg
21484 ("argument of pragma% cannot be an incomplete type", Arg1);
21485 else
21486 Set_Suppress_Initialization (Full_View (Base_Type (E)));
21487 end if;
21489 -- For first subtype, set flag on base type
21491 elsif Is_First_Subtype (E) then
21492 Set_Suppress_Initialization (Base_Type (E));
21494 -- For other than first subtype, set flag on subtype or variable
21496 else
21497 Set_Suppress_Initialization (E);
21498 end if;
21499 end Suppress_Init;
21501 -----------------
21502 -- System_Name --
21503 -----------------
21505 -- pragma System_Name (DIRECT_NAME);
21507 -- Syntax check: one argument, which must be the identifier GNAT or
21508 -- the identifier GCC, no other identifiers are acceptable.
21510 when Pragma_System_Name =>
21511 GNAT_Pragma;
21512 Check_No_Identifiers;
21513 Check_Arg_Count (1);
21514 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
21516 -----------------------------
21517 -- Task_Dispatching_Policy --
21518 -----------------------------
21520 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
21522 when Pragma_Task_Dispatching_Policy => declare
21523 DP : Character;
21525 begin
21526 Check_Ada_83_Warning;
21527 Check_Arg_Count (1);
21528 Check_No_Identifiers;
21529 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
21530 Check_Valid_Configuration_Pragma;
21531 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21532 DP := Fold_Upper (Name_Buffer (1));
21534 if Task_Dispatching_Policy /= ' '
21535 and then Task_Dispatching_Policy /= DP
21536 then
21537 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21538 Error_Pragma
21539 ("task dispatching policy incompatible with policy#");
21541 -- Set new policy, but always preserve System_Location since we
21542 -- like the error message with the run time name.
21544 else
21545 Task_Dispatching_Policy := DP;
21547 if Task_Dispatching_Policy_Sloc /= System_Location then
21548 Task_Dispatching_Policy_Sloc := Loc;
21549 end if;
21550 end if;
21551 end;
21553 ---------------
21554 -- Task_Info --
21555 ---------------
21557 -- pragma Task_Info (EXPRESSION);
21559 when Pragma_Task_Info => Task_Info : declare
21560 P : constant Node_Id := Parent (N);
21561 Ent : Entity_Id;
21563 begin
21564 GNAT_Pragma;
21566 if Warn_On_Obsolescent_Feature then
21567 Error_Msg_N
21568 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
21569 & "instead?j?", N);
21570 end if;
21572 if Nkind (P) /= N_Task_Definition then
21573 Error_Pragma ("pragma% must appear in task definition");
21574 end if;
21576 Check_No_Identifiers;
21577 Check_Arg_Count (1);
21579 Analyze_And_Resolve
21580 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
21582 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
21583 return;
21584 end if;
21586 Ent := Defining_Identifier (Parent (P));
21588 -- Check duplicate pragma before we chain the pragma in the Rep
21589 -- Item chain of Ent.
21591 if Has_Rep_Pragma
21592 (Ent, Name_Task_Info, Check_Parents => False)
21593 then
21594 Error_Pragma ("duplicate pragma% not allowed");
21595 end if;
21597 Record_Rep_Item (Ent, N);
21598 end Task_Info;
21600 ---------------
21601 -- Task_Name --
21602 ---------------
21604 -- pragma Task_Name (string_EXPRESSION);
21606 when Pragma_Task_Name => Task_Name : declare
21607 P : constant Node_Id := Parent (N);
21608 Arg : Node_Id;
21609 Ent : Entity_Id;
21611 begin
21612 Check_No_Identifiers;
21613 Check_Arg_Count (1);
21615 Arg := Get_Pragma_Arg (Arg1);
21617 -- The expression is used in the call to Create_Task, and must be
21618 -- expanded there, not in the context of the current spec. It must
21619 -- however be analyzed to capture global references, in case it
21620 -- appears in a generic context.
21622 Preanalyze_And_Resolve (Arg, Standard_String);
21624 if Nkind (P) /= N_Task_Definition then
21625 Pragma_Misplaced;
21626 end if;
21628 Ent := Defining_Identifier (Parent (P));
21630 -- Check duplicate pragma before we chain the pragma in the Rep
21631 -- Item chain of Ent.
21633 if Has_Rep_Pragma
21634 (Ent, Name_Task_Name, Check_Parents => False)
21635 then
21636 Error_Pragma ("duplicate pragma% not allowed");
21637 end if;
21639 Record_Rep_Item (Ent, N);
21640 end Task_Name;
21642 ------------------
21643 -- Task_Storage --
21644 ------------------
21646 -- pragma Task_Storage (
21647 -- [Task_Type =>] LOCAL_NAME,
21648 -- [Top_Guard =>] static_integer_EXPRESSION);
21650 when Pragma_Task_Storage => Task_Storage : declare
21651 Args : Args_List (1 .. 2);
21652 Names : constant Name_List (1 .. 2) := (
21653 Name_Task_Type,
21654 Name_Top_Guard);
21656 Task_Type : Node_Id renames Args (1);
21657 Top_Guard : Node_Id renames Args (2);
21659 Ent : Entity_Id;
21661 begin
21662 GNAT_Pragma;
21663 Gather_Associations (Names, Args);
21665 if No (Task_Type) then
21666 Error_Pragma
21667 ("missing task_type argument for pragma%");
21668 end if;
21670 Check_Arg_Is_Local_Name (Task_Type);
21672 Ent := Entity (Task_Type);
21674 if not Is_Task_Type (Ent) then
21675 Error_Pragma_Arg
21676 ("argument for pragma% must be task type", Task_Type);
21677 end if;
21679 if No (Top_Guard) then
21680 Error_Pragma_Arg
21681 ("pragma% takes two arguments", Task_Type);
21682 else
21683 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
21684 end if;
21686 Check_First_Subtype (Task_Type);
21688 if Rep_Item_Too_Late (Ent, N) then
21689 raise Pragma_Exit;
21690 end if;
21691 end Task_Storage;
21693 ---------------
21694 -- Test_Case --
21695 ---------------
21697 -- pragma Test_Case
21698 -- ([Name =>] Static_String_EXPRESSION
21699 -- ,[Mode =>] MODE_TYPE
21700 -- [, Requires => Boolean_EXPRESSION]
21701 -- [, Ensures => Boolean_EXPRESSION]);
21703 -- MODE_TYPE ::= Nominal | Robustness
21705 -- Characteristics:
21707 -- * Analysis - The annotation undergoes initial checks to verify
21708 -- the legal placement and context. Secondary checks preanalyze the
21709 -- expressions in:
21711 -- Analyze_Test_Case_In_Decl_Part
21713 -- * Expansion - None.
21715 -- * Template - The annotation utilizes the generic template of the
21716 -- related subprogram when it is:
21718 -- aspect on subprogram declaration
21720 -- The annotation must prepare its own template when it is:
21722 -- pragma on subprogram declaration
21724 -- * Globals - Capture of global references must occur after full
21725 -- analysis.
21727 -- * Instance - The annotation is instantiated automatically when
21728 -- the related generic subprogram is instantiated except for the
21729 -- "pragma on subprogram declaration" case. In that scenario the
21730 -- annotation must instantiate itself.
21732 when Pragma_Test_Case => Test_Case : declare
21733 procedure Check_Distinct_Name (Subp_Id : Entity_Id);
21734 -- Ensure that the contract of subprogram Subp_Id does not contain
21735 -- another Test_Case pragma with the same Name as the current one.
21737 -------------------------
21738 -- Check_Distinct_Name --
21739 -------------------------
21741 procedure Check_Distinct_Name (Subp_Id : Entity_Id) is
21742 Items : constant Node_Id := Contract (Subp_Id);
21743 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
21744 Prag : Node_Id;
21746 begin
21747 -- Inspect all Test_Case pragma of the related subprogram
21748 -- looking for one with a duplicate "Name" argument.
21750 if Present (Items) then
21751 Prag := Contract_Test_Cases (Items);
21752 while Present (Prag) loop
21753 if Pragma_Name (Prag) = Name_Test_Case
21754 and then Prag /= N
21755 and then String_Equal
21756 (Name, Get_Name_From_CTC_Pragma (Prag))
21757 then
21758 Error_Msg_Sloc := Sloc (Prag);
21759 Error_Pragma ("name for pragma % is already used #");
21760 end if;
21762 Prag := Next_Pragma (Prag);
21763 end loop;
21764 end if;
21765 end Check_Distinct_Name;
21767 -- Local variables
21769 Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit));
21770 Asp_Arg : Node_Id;
21771 Context : Node_Id;
21772 Subp_Decl : Node_Id;
21773 Subp_Id : Entity_Id;
21775 -- Start of processing for Test_Case
21777 begin
21778 GNAT_Pragma;
21779 Check_At_Least_N_Arguments (2);
21780 Check_At_Most_N_Arguments (4);
21781 Check_Arg_Order
21782 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
21784 -- Argument "Name"
21786 Check_Optional_Identifier (Arg1, Name_Name);
21787 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
21789 -- Argument "Mode"
21791 Check_Optional_Identifier (Arg2, Name_Mode);
21792 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
21794 -- Arguments "Requires" and "Ensures"
21796 if Present (Arg3) then
21797 if Present (Arg4) then
21798 Check_Identifier (Arg3, Name_Requires);
21799 Check_Identifier (Arg4, Name_Ensures);
21800 else
21801 Check_Identifier_Is_One_Of
21802 (Arg3, Name_Requires, Name_Ensures);
21803 end if;
21804 end if;
21806 -- Pragma Test_Case must be associated with a subprogram declared
21807 -- in a library-level package. First determine whether the current
21808 -- compilation unit is a legal context.
21810 if Nkind_In (Pack_Decl, N_Package_Declaration,
21811 N_Generic_Package_Declaration)
21812 then
21813 null;
21815 -- Otherwise the placement is illegal
21817 else
21818 Error_Pragma
21819 ("pragma % must be specified within a package declaration");
21820 return;
21821 end if;
21823 Subp_Decl := Find_Related_Declaration_Or_Body (N);
21825 -- Find the enclosing context
21827 Context := Parent (Subp_Decl);
21829 if Present (Context) then
21830 Context := Parent (Context);
21831 end if;
21833 -- Verify the placement of the pragma
21835 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
21836 Error_Pragma
21837 ("pragma % cannot be applied to abstract subprogram");
21838 return;
21840 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
21841 Error_Pragma ("pragma % cannot be applied to entry");
21842 return;
21844 -- The context is a [generic] subprogram declared at the top level
21845 -- of the [generic] package unit.
21847 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
21848 N_Subprogram_Declaration)
21849 and then Present (Context)
21850 and then Nkind_In (Context, N_Generic_Package_Declaration,
21851 N_Package_Declaration)
21852 then
21853 null;
21855 -- Otherwise the placement is illegal
21857 else
21858 Error_Pragma
21859 ("pragma % must be applied to a library-level subprogram "
21860 & "declaration");
21861 return;
21862 end if;
21864 Subp_Id := Defining_Entity (Subp_Decl);
21866 -- Chain the pragma on the contract for further processing by
21867 -- Analyze_Test_Case_In_Decl_Part.
21869 Add_Contract_Item (N, Subp_Id);
21871 -- A pragma that applies to a Ghost entity becomes Ghost for the
21872 -- purposes of legality checks and removal of ignored Ghost code.
21874 Mark_Pragma_As_Ghost (N, Subp_Id);
21876 -- Preanalyze the original aspect argument "Name" for ASIS or for
21877 -- a generic subprogram to properly capture global references.
21879 if ASIS_Mode or else Is_Generic_Subprogram (Subp_Id) then
21880 Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True);
21882 if Present (Asp_Arg) then
21884 -- The argument appears with an identifier in association
21885 -- form.
21887 if Nkind (Asp_Arg) = N_Component_Association then
21888 Asp_Arg := Expression (Asp_Arg);
21889 end if;
21891 Check_Expr_Is_OK_Static_Expression
21892 (Asp_Arg, Standard_String);
21893 end if;
21894 end if;
21896 -- Ensure that the all Test_Case pragmas of the related subprogram
21897 -- have distinct names.
21899 Check_Distinct_Name (Subp_Id);
21901 -- Fully analyze the pragma when it appears inside an entry
21902 -- or subprogram body because it cannot benefit from forward
21903 -- references.
21905 if Nkind_In (Subp_Decl, N_Entry_Body,
21906 N_Subprogram_Body,
21907 N_Subprogram_Body_Stub)
21908 then
21909 -- The legality checks of pragma Test_Case are affected by the
21910 -- SPARK mode in effect and the volatility of the context.
21911 -- Analyze all pragmas in a specific order.
21913 Analyze_If_Present (Pragma_SPARK_Mode);
21914 Analyze_If_Present (Pragma_Volatile_Function);
21915 Analyze_Test_Case_In_Decl_Part (N);
21916 end if;
21917 end Test_Case;
21919 --------------------------
21920 -- Thread_Local_Storage --
21921 --------------------------
21923 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
21925 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
21926 E : Entity_Id;
21927 Id : Node_Id;
21929 begin
21930 GNAT_Pragma;
21931 Check_Arg_Count (1);
21932 Check_Optional_Identifier (Arg1, Name_Entity);
21933 Check_Arg_Is_Library_Level_Local_Name (Arg1);
21935 Id := Get_Pragma_Arg (Arg1);
21936 Analyze (Id);
21938 if not Is_Entity_Name (Id)
21939 or else Ekind (Entity (Id)) /= E_Variable
21940 then
21941 Error_Pragma_Arg ("local variable name required", Arg1);
21942 end if;
21944 E := Entity (Id);
21946 -- A pragma that applies to a Ghost entity becomes Ghost for the
21947 -- purposes of legality checks and removal of ignored Ghost code.
21949 Mark_Pragma_As_Ghost (N, E);
21951 if Rep_Item_Too_Early (E, N)
21952 or else
21953 Rep_Item_Too_Late (E, N)
21954 then
21955 raise Pragma_Exit;
21956 end if;
21958 Set_Has_Pragma_Thread_Local_Storage (E);
21959 Set_Has_Gigi_Rep_Item (E);
21960 end Thread_Local_Storage;
21962 ----------------
21963 -- Time_Slice --
21964 ----------------
21966 -- pragma Time_Slice (static_duration_EXPRESSION);
21968 when Pragma_Time_Slice => Time_Slice : declare
21969 Val : Ureal;
21970 Nod : Node_Id;
21972 begin
21973 GNAT_Pragma;
21974 Check_Arg_Count (1);
21975 Check_No_Identifiers;
21976 Check_In_Main_Program;
21977 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
21979 if not Error_Posted (Arg1) then
21980 Nod := Next (N);
21981 while Present (Nod) loop
21982 if Nkind (Nod) = N_Pragma
21983 and then Pragma_Name (Nod) = Name_Time_Slice
21984 then
21985 Error_Msg_Name_1 := Pname;
21986 Error_Msg_N ("duplicate pragma% not permitted", Nod);
21987 end if;
21989 Next (Nod);
21990 end loop;
21991 end if;
21993 -- Process only if in main unit
21995 if Get_Source_Unit (Loc) = Main_Unit then
21996 Opt.Time_Slice_Set := True;
21997 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
21999 if Val <= Ureal_0 then
22000 Opt.Time_Slice_Value := 0;
22002 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
22003 Opt.Time_Slice_Value := 1_000_000_000;
22005 else
22006 Opt.Time_Slice_Value :=
22007 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
22008 end if;
22009 end if;
22010 end Time_Slice;
22012 -----------
22013 -- Title --
22014 -----------
22016 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
22018 -- TITLING_OPTION ::=
22019 -- [Title =>] STRING_LITERAL
22020 -- | [Subtitle =>] STRING_LITERAL
22022 when Pragma_Title => Title : declare
22023 Args : Args_List (1 .. 2);
22024 Names : constant Name_List (1 .. 2) := (
22025 Name_Title,
22026 Name_Subtitle);
22028 begin
22029 GNAT_Pragma;
22030 Gather_Associations (Names, Args);
22031 Store_Note (N);
22033 for J in 1 .. 2 loop
22034 if Present (Args (J)) then
22035 Check_Arg_Is_OK_Static_Expression
22036 (Args (J), Standard_String);
22037 end if;
22038 end loop;
22039 end Title;
22041 ----------------------------
22042 -- Type_Invariant[_Class] --
22043 ----------------------------
22045 -- pragma Type_Invariant[_Class]
22046 -- ([Entity =>] type_LOCAL_NAME,
22047 -- [Check =>] EXPRESSION);
22049 when Pragma_Type_Invariant |
22050 Pragma_Type_Invariant_Class =>
22051 Type_Invariant : declare
22052 I_Pragma : Node_Id;
22054 begin
22055 Check_Arg_Count (2);
22057 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
22058 -- setting Class_Present for the Type_Invariant_Class case.
22060 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
22061 I_Pragma := New_Copy (N);
22062 Set_Pragma_Identifier
22063 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
22064 Rewrite (N, I_Pragma);
22065 Set_Analyzed (N, False);
22066 Analyze (N);
22067 end Type_Invariant;
22069 ---------------------
22070 -- Unchecked_Union --
22071 ---------------------
22073 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
22075 when Pragma_Unchecked_Union => Unchecked_Union : declare
22076 Assoc : constant Node_Id := Arg1;
22077 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
22078 Clist : Node_Id;
22079 Comp : Node_Id;
22080 Tdef : Node_Id;
22081 Typ : Entity_Id;
22082 Variant : Node_Id;
22083 Vpart : Node_Id;
22085 begin
22086 Ada_2005_Pragma;
22087 Check_No_Identifiers;
22088 Check_Arg_Count (1);
22089 Check_Arg_Is_Local_Name (Arg1);
22091 Find_Type (Type_Id);
22093 Typ := Entity (Type_Id);
22095 -- A pragma that applies to a Ghost entity becomes Ghost for the
22096 -- purposes of legality checks and removal of ignored Ghost code.
22098 Mark_Pragma_As_Ghost (N, Typ);
22100 if Typ = Any_Type
22101 or else Rep_Item_Too_Early (Typ, N)
22102 then
22103 return;
22104 else
22105 Typ := Underlying_Type (Typ);
22106 end if;
22108 if Rep_Item_Too_Late (Typ, N) then
22109 return;
22110 end if;
22112 Check_First_Subtype (Arg1);
22114 -- Note remaining cases are references to a type in the current
22115 -- declarative part. If we find an error, we post the error on
22116 -- the relevant type declaration at an appropriate point.
22118 if not Is_Record_Type (Typ) then
22119 Error_Msg_N ("unchecked union must be record type", Typ);
22120 return;
22122 elsif Is_Tagged_Type (Typ) then
22123 Error_Msg_N ("unchecked union must not be tagged", Typ);
22124 return;
22126 elsif not Has_Discriminants (Typ) then
22127 Error_Msg_N
22128 ("unchecked union must have one discriminant", Typ);
22129 return;
22131 -- Note: in previous versions of GNAT we used to check for limited
22132 -- types and give an error, but in fact the standard does allow
22133 -- Unchecked_Union on limited types, so this check was removed.
22135 -- Similarly, GNAT used to require that all discriminants have
22136 -- default values, but this is not mandated by the RM.
22138 -- Proceed with basic error checks completed
22140 else
22141 Tdef := Type_Definition (Declaration_Node (Typ));
22142 Clist := Component_List (Tdef);
22144 -- Check presence of component list and variant part
22146 if No (Clist) or else No (Variant_Part (Clist)) then
22147 Error_Msg_N
22148 ("unchecked union must have variant part", Tdef);
22149 return;
22150 end if;
22152 -- Check components
22154 Comp := First (Component_Items (Clist));
22155 while Present (Comp) loop
22156 Check_Component (Comp, Typ);
22157 Next (Comp);
22158 end loop;
22160 -- Check variant part
22162 Vpart := Variant_Part (Clist);
22164 Variant := First (Variants (Vpart));
22165 while Present (Variant) loop
22166 Check_Variant (Variant, Typ);
22167 Next (Variant);
22168 end loop;
22169 end if;
22171 Set_Is_Unchecked_Union (Typ);
22172 Set_Convention (Typ, Convention_C);
22173 Set_Has_Unchecked_Union (Base_Type (Typ));
22174 Set_Is_Unchecked_Union (Base_Type (Typ));
22175 end Unchecked_Union;
22177 ------------------------
22178 -- Unimplemented_Unit --
22179 ------------------------
22181 -- pragma Unimplemented_Unit;
22183 -- Note: this only gives an error if we are generating code, or if
22184 -- we are in a generic library unit (where the pragma appears in the
22185 -- body, not in the spec).
22187 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
22188 Cunitent : constant Entity_Id :=
22189 Cunit_Entity (Get_Source_Unit (Loc));
22190 Ent_Kind : constant Entity_Kind :=
22191 Ekind (Cunitent);
22193 begin
22194 GNAT_Pragma;
22195 Check_Arg_Count (0);
22197 if Operating_Mode = Generate_Code
22198 or else Ent_Kind = E_Generic_Function
22199 or else Ent_Kind = E_Generic_Procedure
22200 or else Ent_Kind = E_Generic_Package
22201 then
22202 Get_Name_String (Chars (Cunitent));
22203 Set_Casing (Mixed_Case);
22204 Write_Str (Name_Buffer (1 .. Name_Len));
22205 Write_Str (" is not supported in this configuration");
22206 Write_Eol;
22207 raise Unrecoverable_Error;
22208 end if;
22209 end Unimplemented_Unit;
22211 ------------------------
22212 -- Universal_Aliasing --
22213 ------------------------
22215 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
22217 when Pragma_Universal_Aliasing => Universal_Alias : declare
22218 E_Id : Entity_Id;
22220 begin
22221 GNAT_Pragma;
22222 Check_Arg_Count (1);
22223 Check_Optional_Identifier (Arg2, Name_Entity);
22224 Check_Arg_Is_Local_Name (Arg1);
22225 E_Id := Entity (Get_Pragma_Arg (Arg1));
22227 if E_Id = Any_Type then
22228 return;
22229 elsif No (E_Id) or else not Is_Type (E_Id) then
22230 Error_Pragma_Arg ("pragma% requires type", Arg1);
22231 end if;
22233 -- A pragma that applies to a Ghost entity becomes Ghost for the
22234 -- purposes of legality checks and removal of ignored Ghost code.
22236 Mark_Pragma_As_Ghost (N, E_Id);
22237 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
22238 Record_Rep_Item (E_Id, N);
22239 end Universal_Alias;
22241 --------------------
22242 -- Universal_Data --
22243 --------------------
22245 -- pragma Universal_Data [(library_unit_NAME)];
22247 when Pragma_Universal_Data =>
22248 GNAT_Pragma;
22250 -- If this is a configuration pragma, then set the universal
22251 -- addressing option, otherwise confirm that the pragma satisfies
22252 -- the requirements of library unit pragma placement and leave it
22253 -- to the GNAAMP back end to detect the pragma (avoids transitive
22254 -- setting of the option due to withed units).
22256 if Is_Configuration_Pragma then
22257 Universal_Addressing_On_AAMP := True;
22258 else
22259 Check_Valid_Library_Unit_Pragma;
22260 end if;
22262 if not AAMP_On_Target then
22263 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
22264 end if;
22266 ----------------
22267 -- Unmodified --
22268 ----------------
22270 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
22272 when Pragma_Unmodified => Unmodified : declare
22273 Arg : Node_Id;
22274 Arg_Expr : Node_Id;
22275 Arg_Id : Entity_Id;
22277 Ghost_Error_Posted : Boolean := False;
22278 -- Flag set when an error concerning the illegal mix of Ghost and
22279 -- non-Ghost variables is emitted.
22281 Ghost_Id : Entity_Id := Empty;
22282 -- The entity of the first Ghost variable encountered while
22283 -- processing the arguments of the pragma.
22285 begin
22286 GNAT_Pragma;
22287 Check_At_Least_N_Arguments (1);
22289 -- Loop through arguments
22291 Arg := Arg1;
22292 while Present (Arg) loop
22293 Check_No_Identifier (Arg);
22295 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
22296 -- in fact generate reference, so that the entity will have a
22297 -- reference, which will inhibit any warnings about it not
22298 -- being referenced, and also properly show up in the ali file
22299 -- as a reference. But this reference is recorded before the
22300 -- Has_Pragma_Unreferenced flag is set, so that no warning is
22301 -- generated for this reference.
22303 Check_Arg_Is_Local_Name (Arg);
22304 Arg_Expr := Get_Pragma_Arg (Arg);
22306 if Is_Entity_Name (Arg_Expr) then
22307 Arg_Id := Entity (Arg_Expr);
22309 if Is_Assignable (Arg_Id) then
22310 Set_Has_Pragma_Unmodified (Arg_Id);
22312 -- A pragma that applies to a Ghost entity becomes Ghost
22313 -- for the purposes of legality checks and removal of
22314 -- ignored Ghost code.
22316 Mark_Pragma_As_Ghost (N, Arg_Id);
22318 -- Capture the entity of the first Ghost variable being
22319 -- processed for error detection purposes.
22321 if Is_Ghost_Entity (Arg_Id) then
22322 if No (Ghost_Id) then
22323 Ghost_Id := Arg_Id;
22324 end if;
22326 -- Otherwise the variable is non-Ghost. It is illegal
22327 -- to mix references to Ghost and non-Ghost entities
22328 -- (SPARK RM 6.9).
22330 elsif Present (Ghost_Id)
22331 and then not Ghost_Error_Posted
22332 then
22333 Ghost_Error_Posted := True;
22335 Error_Msg_Name_1 := Pname;
22336 Error_Msg_N
22337 ("pragma % cannot mention ghost and non-ghost "
22338 & "variables", N);
22340 Error_Msg_Sloc := Sloc (Ghost_Id);
22341 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
22343 Error_Msg_Sloc := Sloc (Arg_Id);
22344 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
22345 end if;
22347 -- Otherwise the pragma referenced an illegal entity
22349 else
22350 Error_Pragma_Arg
22351 ("pragma% can only be applied to a variable", Arg_Expr);
22352 end if;
22353 end if;
22355 Next (Arg);
22356 end loop;
22357 end Unmodified;
22359 ------------------
22360 -- Unreferenced --
22361 ------------------
22363 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
22365 -- or when used in a context clause:
22367 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
22369 when Pragma_Unreferenced => Unreferenced : declare
22370 Arg : Node_Id;
22371 Arg_Expr : Node_Id;
22372 Arg_Id : Entity_Id;
22373 Citem : Node_Id;
22375 Ghost_Error_Posted : Boolean := False;
22376 -- Flag set when an error concerning the illegal mix of Ghost and
22377 -- non-Ghost names is emitted.
22379 Ghost_Id : Entity_Id := Empty;
22380 -- The entity of the first Ghost name encountered while processing
22381 -- the arguments of the pragma.
22383 begin
22384 GNAT_Pragma;
22385 Check_At_Least_N_Arguments (1);
22387 -- Check case of appearing within context clause
22389 if Is_In_Context_Clause then
22391 -- The arguments must all be units mentioned in a with clause
22392 -- in the same context clause. Note we already checked (in
22393 -- Par.Prag) that the arguments are either identifiers or
22394 -- selected components.
22396 Arg := Arg1;
22397 while Present (Arg) loop
22398 Citem := First (List_Containing (N));
22399 while Citem /= N loop
22400 Arg_Expr := Get_Pragma_Arg (Arg);
22402 if Nkind (Citem) = N_With_Clause
22403 and then Same_Name (Name (Citem), Arg_Expr)
22404 then
22405 Set_Has_Pragma_Unreferenced
22406 (Cunit_Entity
22407 (Get_Source_Unit
22408 (Library_Unit (Citem))));
22409 Set_Elab_Unit_Name (Arg_Expr, Name (Citem));
22410 exit;
22411 end if;
22413 Next (Citem);
22414 end loop;
22416 if Citem = N then
22417 Error_Pragma_Arg
22418 ("argument of pragma% is not withed unit", Arg);
22419 end if;
22421 Next (Arg);
22422 end loop;
22424 -- Case of not in list of context items
22426 else
22427 Arg := Arg1;
22428 while Present (Arg) loop
22429 Check_No_Identifier (Arg);
22431 -- Note: the analyze call done by Check_Arg_Is_Local_Name
22432 -- will in fact generate reference, so that the entity will
22433 -- have a reference, which will inhibit any warnings about
22434 -- it not being referenced, and also properly show up in the
22435 -- ali file as a reference. But this reference is recorded
22436 -- before the Has_Pragma_Unreferenced flag is set, so that
22437 -- no warning is generated for this reference.
22439 Check_Arg_Is_Local_Name (Arg);
22440 Arg_Expr := Get_Pragma_Arg (Arg);
22442 if Is_Entity_Name (Arg_Expr) then
22443 Arg_Id := Entity (Arg_Expr);
22445 -- If the entity is overloaded, the pragma applies to the
22446 -- most recent overloading, as documented. In this case,
22447 -- name resolution does not generate a reference, so it
22448 -- must be done here explicitly.
22450 if Is_Overloaded (Arg_Expr) then
22451 Generate_Reference (Arg_Id, N);
22452 end if;
22454 Set_Has_Pragma_Unreferenced (Arg_Id);
22456 -- A pragma that applies to a Ghost entity becomes Ghost
22457 -- for the purposes of legality checks and removal of
22458 -- ignored Ghost code.
22460 Mark_Pragma_As_Ghost (N, Arg_Id);
22462 -- Capture the entity of the first Ghost name being
22463 -- processed for error detection purposes.
22465 if Is_Ghost_Entity (Arg_Id) then
22466 if No (Ghost_Id) then
22467 Ghost_Id := Arg_Id;
22468 end if;
22470 -- Otherwise the name is non-Ghost. It is illegal to mix
22471 -- references to Ghost and non-Ghost entities
22472 -- (SPARK RM 6.9).
22474 elsif Present (Ghost_Id)
22475 and then not Ghost_Error_Posted
22476 then
22477 Ghost_Error_Posted := True;
22479 Error_Msg_Name_1 := Pname;
22480 Error_Msg_N
22481 ("pragma % cannot mention ghost and non-ghost names",
22484 Error_Msg_Sloc := Sloc (Ghost_Id);
22485 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
22487 Error_Msg_Sloc := Sloc (Arg_Id);
22488 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
22489 end if;
22490 end if;
22492 Next (Arg);
22493 end loop;
22494 end if;
22495 end Unreferenced;
22497 --------------------------
22498 -- Unreferenced_Objects --
22499 --------------------------
22501 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
22503 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
22504 Arg : Node_Id;
22505 Arg_Expr : Node_Id;
22506 Arg_Id : Entity_Id;
22508 Ghost_Error_Posted : Boolean := False;
22509 -- Flag set when an error concerning the illegal mix of Ghost and
22510 -- non-Ghost types is emitted.
22512 Ghost_Id : Entity_Id := Empty;
22513 -- The entity of the first Ghost type encountered while processing
22514 -- the arguments of the pragma.
22516 begin
22517 GNAT_Pragma;
22518 Check_At_Least_N_Arguments (1);
22520 Arg := Arg1;
22521 while Present (Arg) loop
22522 Check_No_Identifier (Arg);
22523 Check_Arg_Is_Local_Name (Arg);
22524 Arg_Expr := Get_Pragma_Arg (Arg);
22526 if Is_Entity_Name (Arg_Expr) then
22527 Arg_Id := Entity (Arg_Expr);
22529 if Is_Type (Arg_Id) then
22530 Set_Has_Pragma_Unreferenced_Objects (Arg_Id);
22532 -- A pragma that applies to a Ghost entity becomes Ghost
22533 -- for the purposes of legality checks and removal of
22534 -- ignored Ghost code.
22536 Mark_Pragma_As_Ghost (N, Arg_Id);
22538 -- Capture the entity of the first Ghost type being
22539 -- processed for error detection purposes.
22541 if Is_Ghost_Entity (Arg_Id) then
22542 if No (Ghost_Id) then
22543 Ghost_Id := Arg_Id;
22544 end if;
22546 -- Otherwise the type is non-Ghost. It is illegal to mix
22547 -- references to Ghost and non-Ghost entities
22548 -- (SPARK RM 6.9).
22550 elsif Present (Ghost_Id)
22551 and then not Ghost_Error_Posted
22552 then
22553 Ghost_Error_Posted := True;
22555 Error_Msg_Name_1 := Pname;
22556 Error_Msg_N
22557 ("pragma % cannot mention ghost and non-ghost types",
22560 Error_Msg_Sloc := Sloc (Ghost_Id);
22561 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
22563 Error_Msg_Sloc := Sloc (Arg_Id);
22564 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
22565 end if;
22566 else
22567 Error_Pragma_Arg
22568 ("argument for pragma% must be type or subtype", Arg);
22569 end if;
22570 else
22571 Error_Pragma_Arg
22572 ("argument for pragma% must be type or subtype", Arg);
22573 end if;
22575 Next (Arg);
22576 end loop;
22577 end Unreferenced_Objects;
22579 ------------------------------
22580 -- Unreserve_All_Interrupts --
22581 ------------------------------
22583 -- pragma Unreserve_All_Interrupts;
22585 when Pragma_Unreserve_All_Interrupts =>
22586 GNAT_Pragma;
22587 Check_Arg_Count (0);
22589 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
22590 Unreserve_All_Interrupts := True;
22591 end if;
22593 ----------------
22594 -- Unsuppress --
22595 ----------------
22597 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
22599 when Pragma_Unsuppress =>
22600 Ada_2005_Pragma;
22601 Process_Suppress_Unsuppress (Suppress_Case => False);
22603 ----------------------------
22604 -- Unevaluated_Use_Of_Old --
22605 ----------------------------
22607 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
22609 when Pragma_Unevaluated_Use_Of_Old =>
22610 GNAT_Pragma;
22611 Check_Arg_Count (1);
22612 Check_No_Identifiers;
22613 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
22615 -- Suppress/Unsuppress can appear as a configuration pragma, or in
22616 -- a declarative part or a package spec.
22618 if not Is_Configuration_Pragma then
22619 Check_Is_In_Decl_Part_Or_Package_Spec;
22620 end if;
22622 -- Store proper setting of Uneval_Old
22624 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
22625 Uneval_Old := Fold_Upper (Name_Buffer (1));
22627 -------------------
22628 -- Use_VADS_Size --
22629 -------------------
22631 -- pragma Use_VADS_Size;
22633 when Pragma_Use_VADS_Size =>
22634 GNAT_Pragma;
22635 Check_Arg_Count (0);
22636 Check_Valid_Configuration_Pragma;
22637 Use_VADS_Size := True;
22639 ---------------------
22640 -- Validity_Checks --
22641 ---------------------
22643 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
22645 when Pragma_Validity_Checks => Validity_Checks : declare
22646 A : constant Node_Id := Get_Pragma_Arg (Arg1);
22647 S : String_Id;
22648 C : Char_Code;
22650 begin
22651 GNAT_Pragma;
22652 Check_Arg_Count (1);
22653 Check_No_Identifiers;
22655 -- Pragma always active unless in CodePeer or GNATprove modes,
22656 -- which use a fixed configuration of validity checks.
22658 if not (CodePeer_Mode or GNATprove_Mode) then
22659 if Nkind (A) = N_String_Literal then
22660 S := Strval (A);
22662 declare
22663 Slen : constant Natural := Natural (String_Length (S));
22664 Options : String (1 .. Slen);
22665 J : Positive;
22667 begin
22668 -- Couldn't we use a for loop here over Options'Range???
22670 J := 1;
22671 loop
22672 C := Get_String_Char (S, Pos (J));
22674 -- This is a weird test, it skips setting validity
22675 -- checks entirely if any element of S is out of
22676 -- range of Character, what is that about ???
22678 exit when not In_Character_Range (C);
22679 Options (J) := Get_Character (C);
22681 if J = Slen then
22682 Set_Validity_Check_Options (Options);
22683 exit;
22684 else
22685 J := J + 1;
22686 end if;
22687 end loop;
22688 end;
22690 elsif Nkind (A) = N_Identifier then
22691 if Chars (A) = Name_All_Checks then
22692 Set_Validity_Check_Options ("a");
22693 elsif Chars (A) = Name_On then
22694 Validity_Checks_On := True;
22695 elsif Chars (A) = Name_Off then
22696 Validity_Checks_On := False;
22697 end if;
22698 end if;
22699 end if;
22700 end Validity_Checks;
22702 --------------
22703 -- Volatile --
22704 --------------
22706 -- pragma Volatile (LOCAL_NAME);
22708 when Pragma_Volatile =>
22709 Process_Atomic_Independent_Shared_Volatile;
22711 -------------------------
22712 -- Volatile_Components --
22713 -------------------------
22715 -- pragma Volatile_Components (array_LOCAL_NAME);
22717 -- Volatile is handled by the same circuit as Atomic_Components
22719 --------------------------
22720 -- Volatile_Full_Access --
22721 --------------------------
22723 -- pragma Volatile_Full_Access (LOCAL_NAME);
22725 when Pragma_Volatile_Full_Access =>
22726 GNAT_Pragma;
22727 Process_Atomic_Independent_Shared_Volatile;
22729 -----------------------
22730 -- Volatile_Function --
22731 -----------------------
22733 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
22735 when Pragma_Volatile_Function => Volatile_Function : declare
22736 Over_Id : Entity_Id;
22737 Spec_Id : Entity_Id;
22738 Subp_Decl : Node_Id;
22740 begin
22741 GNAT_Pragma;
22742 Check_No_Identifiers;
22743 Check_At_Most_N_Arguments (1);
22745 Subp_Decl :=
22746 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
22748 -- Generic subprogram
22750 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
22751 null;
22753 -- Body acts as spec
22755 elsif Nkind (Subp_Decl) = N_Subprogram_Body
22756 and then No (Corresponding_Spec (Subp_Decl))
22757 then
22758 null;
22760 -- Body stub acts as spec
22762 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
22763 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
22764 then
22765 null;
22767 -- Subprogram
22769 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
22770 null;
22772 else
22773 Pragma_Misplaced;
22774 return;
22775 end if;
22777 Spec_Id := Unique_Defining_Entity (Subp_Decl);
22779 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
22780 Pragma_Misplaced;
22781 return;
22782 end if;
22784 -- Chain the pragma on the contract for completeness
22786 Add_Contract_Item (N, Spec_Id);
22788 -- The legality checks of pragma Volatile_Function are affected by
22789 -- the SPARK mode in effect. Analyze all pragmas in a specific
22790 -- order.
22792 Analyze_If_Present (Pragma_SPARK_Mode);
22794 -- A pragma that applies to a Ghost entity becomes Ghost for the
22795 -- purposes of legality checks and removal of ignored Ghost code.
22797 Mark_Pragma_As_Ghost (N, Spec_Id);
22799 -- A volatile function cannot override a non-volatile function
22800 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
22801 -- in New_Overloaded_Entity, however at that point the pragma has
22802 -- not been processed yet.
22804 Over_Id := Overridden_Operation (Spec_Id);
22806 if Present (Over_Id)
22807 and then not Is_Volatile_Function (Over_Id)
22808 then
22809 Error_Msg_N
22810 ("incompatible volatile function values in effect", Spec_Id);
22812 Error_Msg_Sloc := Sloc (Over_Id);
22813 Error_Msg_N
22814 ("\& declared # with Volatile_Function value `False`",
22815 Spec_Id);
22817 Error_Msg_Sloc := Sloc (Spec_Id);
22818 Error_Msg_N
22819 ("\overridden # with Volatile_Function value `True`",
22820 Spec_Id);
22821 end if;
22823 -- Analyze the Boolean expression (if any)
22825 if Present (Arg1) then
22826 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
22827 end if;
22828 end Volatile_Function;
22830 ----------------------
22831 -- Warning_As_Error --
22832 ----------------------
22834 -- pragma Warning_As_Error (static_string_EXPRESSION);
22836 when Pragma_Warning_As_Error =>
22837 GNAT_Pragma;
22838 Check_Arg_Count (1);
22839 Check_No_Identifiers;
22840 Check_Valid_Configuration_Pragma;
22842 if not Is_Static_String_Expression (Arg1) then
22843 Error_Pragma_Arg
22844 ("argument of pragma% must be static string expression",
22845 Arg1);
22847 -- OK static string expression
22849 else
22850 Acquire_Warning_Match_String (Arg1);
22851 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
22852 Warnings_As_Errors (Warnings_As_Errors_Count) :=
22853 new String'(Name_Buffer (1 .. Name_Len));
22854 end if;
22856 --------------
22857 -- Warnings --
22858 --------------
22860 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
22862 -- DETAILS ::= On | Off
22863 -- DETAILS ::= On | Off, local_NAME
22864 -- DETAILS ::= static_string_EXPRESSION
22865 -- DETAILS ::= On | Off, static_string_EXPRESSION
22867 -- TOOL_NAME ::= GNAT | GNATProve
22869 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
22871 -- Note: If the first argument matches an allowed tool name, it is
22872 -- always considered to be a tool name, even if there is a string
22873 -- variable of that name.
22875 -- Note if the second argument of DETAILS is a local_NAME then the
22876 -- second form is always understood. If the intention is to use
22877 -- the fourth form, then you can write NAME & "" to force the
22878 -- intepretation as a static_string_EXPRESSION.
22880 when Pragma_Warnings => Warnings : declare
22881 Reason : String_Id;
22883 begin
22884 GNAT_Pragma;
22885 Check_At_Least_N_Arguments (1);
22887 -- See if last argument is labeled Reason. If so, make sure we
22888 -- have a string literal or a concatenation of string literals,
22889 -- and acquire the REASON string. Then remove the REASON argument
22890 -- by decreasing Num_Args by one; Remaining processing looks only
22891 -- at first Num_Args arguments).
22893 declare
22894 Last_Arg : constant Node_Id :=
22895 Last (Pragma_Argument_Associations (N));
22897 begin
22898 if Nkind (Last_Arg) = N_Pragma_Argument_Association
22899 and then Chars (Last_Arg) = Name_Reason
22900 then
22901 Start_String;
22902 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
22903 Reason := End_String;
22904 Arg_Count := Arg_Count - 1;
22906 -- Not allowed in compiler units (bootstrap issues)
22908 Check_Compiler_Unit ("Reason for pragma Warnings", N);
22910 -- No REASON string, set null string as reason
22912 else
22913 Reason := Null_String_Id;
22914 end if;
22915 end;
22917 -- Now proceed with REASON taken care of and eliminated
22919 Check_No_Identifiers;
22921 -- If debug flag -gnatd.i is set, pragma is ignored
22923 if Debug_Flag_Dot_I then
22924 return;
22925 end if;
22927 -- Process various forms of the pragma
22929 declare
22930 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
22931 Shifted_Args : List_Id;
22933 begin
22934 -- See if first argument is a tool name, currently either
22935 -- GNAT or GNATprove. If so, either ignore the pragma if the
22936 -- tool used does not match, or continue as if no tool name
22937 -- was given otherwise, by shifting the arguments.
22939 if Nkind (Argx) = N_Identifier
22940 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
22941 then
22942 if Chars (Argx) = Name_Gnat then
22943 if CodePeer_Mode or GNATprove_Mode or ASIS_Mode then
22944 Rewrite (N, Make_Null_Statement (Loc));
22945 Analyze (N);
22946 raise Pragma_Exit;
22947 end if;
22949 elsif Chars (Argx) = Name_Gnatprove then
22950 if not GNATprove_Mode then
22951 Rewrite (N, Make_Null_Statement (Loc));
22952 Analyze (N);
22953 raise Pragma_Exit;
22954 end if;
22956 else
22957 raise Program_Error;
22958 end if;
22960 -- At this point, the pragma Warnings applies to the tool,
22961 -- so continue with shifted arguments.
22963 Arg_Count := Arg_Count - 1;
22965 if Arg_Count = 1 then
22966 Shifted_Args := New_List (New_Copy (Arg2));
22967 elsif Arg_Count = 2 then
22968 Shifted_Args := New_List (New_Copy (Arg2),
22969 New_Copy (Arg3));
22970 elsif Arg_Count = 3 then
22971 Shifted_Args := New_List (New_Copy (Arg2),
22972 New_Copy (Arg3),
22973 New_Copy (Arg4));
22974 else
22975 raise Program_Error;
22976 end if;
22978 Rewrite (N,
22979 Make_Pragma (Loc,
22980 Chars => Name_Warnings,
22981 Pragma_Argument_Associations => Shifted_Args));
22982 Analyze (N);
22983 raise Pragma_Exit;
22984 end if;
22986 -- One argument case
22988 if Arg_Count = 1 then
22990 -- On/Off one argument case was processed by parser
22992 if Nkind (Argx) = N_Identifier
22993 and then Nam_In (Chars (Argx), Name_On, Name_Off)
22994 then
22995 null;
22997 -- One argument case must be ON/OFF or static string expr
22999 elsif not Is_Static_String_Expression (Arg1) then
23000 Error_Pragma_Arg
23001 ("argument of pragma% must be On/Off or static string "
23002 & "expression", Arg1);
23004 -- One argument string expression case
23006 else
23007 declare
23008 Lit : constant Node_Id := Expr_Value_S (Argx);
23009 Str : constant String_Id := Strval (Lit);
23010 Len : constant Nat := String_Length (Str);
23011 C : Char_Code;
23012 J : Nat;
23013 OK : Boolean;
23014 Chr : Character;
23016 begin
23017 J := 1;
23018 while J <= Len loop
23019 C := Get_String_Char (Str, J);
23020 OK := In_Character_Range (C);
23022 if OK then
23023 Chr := Get_Character (C);
23025 -- Dash case: only -Wxxx is accepted
23027 if J = 1
23028 and then J < Len
23029 and then Chr = '-'
23030 then
23031 J := J + 1;
23032 C := Get_String_Char (Str, J);
23033 Chr := Get_Character (C);
23034 exit when Chr = 'W';
23035 OK := False;
23037 -- Dot case
23039 elsif J < Len and then Chr = '.' then
23040 J := J + 1;
23041 C := Get_String_Char (Str, J);
23042 Chr := Get_Character (C);
23044 if not Set_Dot_Warning_Switch (Chr) then
23045 Error_Pragma_Arg
23046 ("invalid warning switch character "
23047 & '.' & Chr, Arg1);
23048 end if;
23050 -- Non-Dot case
23052 else
23053 OK := Set_Warning_Switch (Chr);
23054 end if;
23055 end if;
23057 if not OK then
23058 Error_Pragma_Arg
23059 ("invalid warning switch character " & Chr,
23060 Arg1);
23061 end if;
23063 J := J + 1;
23064 end loop;
23065 end;
23066 end if;
23068 -- Two or more arguments (must be two)
23070 else
23071 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23072 Check_Arg_Count (2);
23074 declare
23075 E_Id : Node_Id;
23076 E : Entity_Id;
23077 Err : Boolean;
23079 begin
23080 E_Id := Get_Pragma_Arg (Arg2);
23081 Analyze (E_Id);
23083 -- In the expansion of an inlined body, a reference to
23084 -- the formal may be wrapped in a conversion if the
23085 -- actual is a conversion. Retrieve the real entity name.
23087 if (In_Instance_Body or In_Inlined_Body)
23088 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
23089 then
23090 E_Id := Expression (E_Id);
23091 end if;
23093 -- Entity name case
23095 if Is_Entity_Name (E_Id) then
23096 E := Entity (E_Id);
23098 if E = Any_Id then
23099 return;
23100 else
23101 loop
23102 Set_Warnings_Off
23103 (E, (Chars (Get_Pragma_Arg (Arg1)) =
23104 Name_Off));
23106 -- For OFF case, make entry in warnings off
23107 -- pragma table for later processing. But we do
23108 -- not do that within an instance, since these
23109 -- warnings are about what is needed in the
23110 -- template, not an instance of it.
23112 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
23113 and then Warn_On_Warnings_Off
23114 and then not In_Instance
23115 then
23116 Warnings_Off_Pragmas.Append ((N, E, Reason));
23117 end if;
23119 if Is_Enumeration_Type (E) then
23120 declare
23121 Lit : Entity_Id;
23122 begin
23123 Lit := First_Literal (E);
23124 while Present (Lit) loop
23125 Set_Warnings_Off (Lit);
23126 Next_Literal (Lit);
23127 end loop;
23128 end;
23129 end if;
23131 exit when No (Homonym (E));
23132 E := Homonym (E);
23133 end loop;
23134 end if;
23136 -- Error if not entity or static string expression case
23138 elsif not Is_Static_String_Expression (Arg2) then
23139 Error_Pragma_Arg
23140 ("second argument of pragma% must be entity name "
23141 & "or static string expression", Arg2);
23143 -- Static string expression case
23145 else
23146 Acquire_Warning_Match_String (Arg2);
23148 -- Note on configuration pragma case: If this is a
23149 -- configuration pragma, then for an OFF pragma, we
23150 -- just set Config True in the call, which is all
23151 -- that needs to be done. For the case of ON, this
23152 -- is normally an error, unless it is canceling the
23153 -- effect of a previous OFF pragma in the same file.
23154 -- In any other case, an error will be signalled (ON
23155 -- with no matching OFF).
23157 -- Note: We set Used if we are inside a generic to
23158 -- disable the test that the non-config case actually
23159 -- cancels a warning. That's because we can't be sure
23160 -- there isn't an instantiation in some other unit
23161 -- where a warning is suppressed.
23163 -- We could do a little better here by checking if the
23164 -- generic unit we are inside is public, but for now
23165 -- we don't bother with that refinement.
23167 if Chars (Argx) = Name_Off then
23168 Set_Specific_Warning_Off
23169 (Loc, Name_Buffer (1 .. Name_Len), Reason,
23170 Config => Is_Configuration_Pragma,
23171 Used => Inside_A_Generic or else In_Instance);
23173 elsif Chars (Argx) = Name_On then
23174 Set_Specific_Warning_On
23175 (Loc, Name_Buffer (1 .. Name_Len), Err);
23177 if Err then
23178 Error_Msg
23179 ("??pragma Warnings On with no matching "
23180 & "Warnings Off", Loc);
23181 end if;
23182 end if;
23183 end if;
23184 end;
23185 end if;
23186 end;
23187 end Warnings;
23189 -------------------
23190 -- Weak_External --
23191 -------------------
23193 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
23195 when Pragma_Weak_External => Weak_External : declare
23196 Ent : Entity_Id;
23198 begin
23199 GNAT_Pragma;
23200 Check_Arg_Count (1);
23201 Check_Optional_Identifier (Arg1, Name_Entity);
23202 Check_Arg_Is_Library_Level_Local_Name (Arg1);
23203 Ent := Entity (Get_Pragma_Arg (Arg1));
23205 if Rep_Item_Too_Early (Ent, N) then
23206 return;
23207 else
23208 Ent := Underlying_Type (Ent);
23209 end if;
23211 -- The only processing required is to link this item on to the
23212 -- list of rep items for the given entity. This is accomplished
23213 -- by the call to Rep_Item_Too_Late (when no error is detected
23214 -- and False is returned).
23216 if Rep_Item_Too_Late (Ent, N) then
23217 return;
23218 else
23219 Set_Has_Gigi_Rep_Item (Ent);
23220 end if;
23221 end Weak_External;
23223 -----------------------------
23224 -- Wide_Character_Encoding --
23225 -----------------------------
23227 -- pragma Wide_Character_Encoding (IDENTIFIER);
23229 when Pragma_Wide_Character_Encoding =>
23230 GNAT_Pragma;
23232 -- Nothing to do, handled in parser. Note that we do not enforce
23233 -- configuration pragma placement, this pragma can appear at any
23234 -- place in the source, allowing mixed encodings within a single
23235 -- source program.
23237 null;
23239 --------------------
23240 -- Unknown_Pragma --
23241 --------------------
23243 -- Should be impossible, since the case of an unknown pragma is
23244 -- separately processed before the case statement is entered.
23246 when Unknown_Pragma =>
23247 raise Program_Error;
23248 end case;
23250 -- AI05-0144: detect dangerous order dependence. Disabled for now,
23251 -- until AI is formally approved.
23253 -- Check_Order_Dependence;
23255 exception
23256 when Pragma_Exit => null;
23257 end Analyze_Pragma;
23259 ---------------------------------------------
23260 -- Analyze_Pre_Post_Condition_In_Decl_Part --
23261 ---------------------------------------------
23263 procedure Analyze_Pre_Post_Condition_In_Decl_Part
23264 (N : Node_Id;
23265 Freeze_Id : Entity_Id := Empty)
23267 -- Local variables
23269 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
23270 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
23271 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
23273 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
23275 Errors : Nat;
23276 Disp_Typ : Entity_Id;
23277 Restore_Scope : Boolean := False;
23279 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
23281 begin
23282 -- Do not analyze the pragma multiple times
23284 if Is_Analyzed_Pragma (N) then
23285 return;
23286 end if;
23288 -- Set the Ghost mode in effect from the pragma. Due to the delayed
23289 -- analysis of the pragma, the Ghost mode at point of declaration and
23290 -- point of analysis may not necessarely be the same. Use the mode in
23291 -- effect at the point of declaration.
23293 Set_Ghost_Mode (N);
23295 -- Ensure that the subprogram and its formals are visible when analyzing
23296 -- the expression of the pragma.
23298 if not In_Open_Scopes (Spec_Id) then
23299 Restore_Scope := True;
23300 Push_Scope (Spec_Id);
23302 if Is_Generic_Subprogram (Spec_Id) then
23303 Install_Generic_Formals (Spec_Id);
23304 else
23305 Install_Formals (Spec_Id);
23306 end if;
23307 end if;
23309 Errors := Serious_Errors_Detected;
23310 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
23312 -- Emit a clarification message when the expression contains at least
23313 -- one undefined reference, possibly due to contract "freezing".
23315 if Errors /= Serious_Errors_Detected
23316 and then Present (Freeze_Id)
23317 and then Has_Undefined_Reference (Expr)
23318 then
23319 Contract_Freeze_Error (Spec_Id, Freeze_Id);
23320 end if;
23322 if Class_Present (N) then
23324 -- Verify that a class-wide condition is legal, i.e. the operation is
23325 -- a primitive of a tagged type. Note that a generic subprogram is
23326 -- not a primitive operation.
23328 Disp_Typ := Find_Dispatching_Type (Spec_Id);
23330 if No (Disp_Typ) or else Is_Generic_Subprogram (Spec_Id) then
23331 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
23333 if From_Aspect_Specification (N) then
23334 Error_Msg_N
23335 ("aspect % can only be specified for a primitive operation "
23336 & "of a tagged type", Corresponding_Aspect (N));
23338 -- The pragma is a source construct
23340 else
23341 Error_Msg_N
23342 ("pragma % can only be specified for a primitive operation "
23343 & "of a tagged type", N);
23344 end if;
23345 end if;
23346 end if;
23348 if Restore_Scope then
23349 End_Scope;
23350 end if;
23352 -- Currently it is not possible to inline pre/postconditions on a
23353 -- subprogram subject to pragma Inline_Always.
23355 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
23356 Ghost_Mode := Save_Ghost_Mode;
23358 Set_Is_Analyzed_Pragma (N);
23359 end Analyze_Pre_Post_Condition_In_Decl_Part;
23361 ------------------------------------------
23362 -- Analyze_Refined_Depends_In_Decl_Part --
23363 ------------------------------------------
23365 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
23366 Body_Inputs : Elist_Id := No_Elist;
23367 Body_Outputs : Elist_Id := No_Elist;
23368 -- The inputs and outputs of the subprogram body synthesized from pragma
23369 -- Refined_Depends.
23371 Dependencies : List_Id := No_List;
23372 Depends : Node_Id;
23373 -- The corresponding Depends pragma along with its clauses
23375 Matched_Items : Elist_Id := No_Elist;
23376 -- A list containing the entities of all successfully matched items
23377 -- found in pragma Depends.
23379 Refinements : List_Id := No_List;
23380 -- The clauses of pragma Refined_Depends
23382 Spec_Id : Entity_Id;
23383 -- The entity of the subprogram subject to pragma Refined_Depends
23385 Spec_Inputs : Elist_Id := No_Elist;
23386 Spec_Outputs : Elist_Id := No_Elist;
23387 -- The inputs and outputs of the subprogram spec synthesized from pragma
23388 -- Depends.
23390 procedure Check_Dependency_Clause (Dep_Clause : Node_Id);
23391 -- Try to match a single dependency clause Dep_Clause against one or
23392 -- more refinement clauses found in list Refinements. Each successful
23393 -- match eliminates at least one refinement clause from Refinements.
23395 procedure Check_Output_States;
23396 -- Determine whether pragma Depends contains an output state with a
23397 -- visible refinement and if so, ensure that pragma Refined_Depends
23398 -- mentions all its constituents as outputs.
23400 procedure Normalize_Clauses (Clauses : List_Id);
23401 -- Given a list of dependence or refinement clauses Clauses, normalize
23402 -- each clause by creating multiple dependencies with exactly one input
23403 -- and one output.
23405 procedure Report_Extra_Clauses;
23406 -- Emit an error for each extra clause found in list Refinements
23408 -----------------------------
23409 -- Check_Dependency_Clause --
23410 -----------------------------
23412 procedure Check_Dependency_Clause (Dep_Clause : Node_Id) is
23413 Dep_Input : constant Node_Id := Expression (Dep_Clause);
23414 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
23416 function Is_In_Out_State_Clause return Boolean;
23417 -- Determine whether dependence clause Dep_Clause denotes an abstract
23418 -- state that depends on itself (State => State).
23420 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
23421 -- Determine whether item Item denotes an abstract state with visible
23422 -- null refinement.
23424 procedure Match_Items
23425 (Dep_Item : Node_Id;
23426 Ref_Item : Node_Id;
23427 Matched : out Boolean);
23428 -- Try to match dependence item Dep_Item against refinement item
23429 -- Ref_Item. To match against a possible null refinement (see 2, 7),
23430 -- set Ref_Item to Empty. Flag Matched is set to True when one of
23431 -- the following conformance scenarios is in effect:
23432 -- 1) Both items denote null
23433 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
23434 -- 3) Both items denote attribute 'Result
23435 -- 4) Both items denote the same object
23436 -- 5) Both items denote the same formal parameter
23437 -- 6) Both items denote the same current instance of a type
23438 -- 7) Both items denote the same discriminant
23439 -- 8) Dep_Item is an abstract state with visible null refinement
23440 -- and Ref_Item denotes null.
23441 -- 9) Dep_Item is an abstract state with visible null refinement
23442 -- and Ref_Item is Empty (special case).
23443 -- 10) Dep_Item is an abstract state with visible non-null
23444 -- refinement and Ref_Item denotes one of its constituents.
23445 -- 11) Dep_Item is an abstract state without a visible refinement
23446 -- and Ref_Item denotes the same state.
23447 -- When scenario 10 is in effect, the entity of the abstract state
23448 -- denoted by Dep_Item is added to list Refined_States.
23450 procedure Record_Item (Item_Id : Entity_Id);
23451 -- Store the entity of an item denoted by Item_Id in Matched_Items
23453 ----------------------------
23454 -- Is_In_Out_State_Clause --
23455 ----------------------------
23457 function Is_In_Out_State_Clause return Boolean is
23458 Dep_Input_Id : Entity_Id;
23459 Dep_Output_Id : Entity_Id;
23461 begin
23462 -- Detect the following clause:
23463 -- State => State
23465 if Is_Entity_Name (Dep_Input)
23466 and then Is_Entity_Name (Dep_Output)
23467 then
23468 -- Handle abstract views generated for limited with clauses
23470 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
23471 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
23473 return
23474 Ekind (Dep_Input_Id) = E_Abstract_State
23475 and then Dep_Input_Id = Dep_Output_Id;
23476 else
23477 return False;
23478 end if;
23479 end Is_In_Out_State_Clause;
23481 ---------------------------
23482 -- Is_Null_Refined_State --
23483 ---------------------------
23485 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
23486 Item_Id : Entity_Id;
23488 begin
23489 if Is_Entity_Name (Item) then
23491 -- Handle abstract views generated for limited with clauses
23493 Item_Id := Available_View (Entity_Of (Item));
23495 return
23496 Ekind (Item_Id) = E_Abstract_State
23497 and then Has_Null_Visible_Refinement (Item_Id);
23498 else
23499 return False;
23500 end if;
23501 end Is_Null_Refined_State;
23503 -----------------
23504 -- Match_Items --
23505 -----------------
23507 procedure Match_Items
23508 (Dep_Item : Node_Id;
23509 Ref_Item : Node_Id;
23510 Matched : out Boolean)
23512 Dep_Item_Id : Entity_Id;
23513 Ref_Item_Id : Entity_Id;
23515 begin
23516 -- Assume that the two items do not match
23518 Matched := False;
23520 -- A null matches null or Empty (special case)
23522 if Nkind (Dep_Item) = N_Null
23523 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
23524 then
23525 Matched := True;
23527 -- Attribute 'Result matches attribute 'Result
23529 elsif Is_Attribute_Result (Dep_Item)
23530 and then Is_Attribute_Result (Dep_Item)
23531 then
23532 Matched := True;
23534 -- Abstract states, current instances of concurrent types,
23535 -- discriminants, formal parameters and objects.
23537 elsif Is_Entity_Name (Dep_Item) then
23539 -- Handle abstract views generated for limited with clauses
23541 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
23543 if Ekind (Dep_Item_Id) = E_Abstract_State then
23545 -- An abstract state with visible null refinement matches
23546 -- null or Empty (special case).
23548 if Has_Null_Visible_Refinement (Dep_Item_Id)
23549 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
23550 then
23551 Record_Item (Dep_Item_Id);
23552 Matched := True;
23554 -- An abstract state with visible non-null refinement
23555 -- matches one of its constituents.
23557 elsif Has_Non_Null_Visible_Refinement (Dep_Item_Id) then
23558 if Is_Entity_Name (Ref_Item) then
23559 Ref_Item_Id := Entity_Of (Ref_Item);
23561 if Ekind_In (Ref_Item_Id, E_Abstract_State,
23562 E_Constant,
23563 E_Variable)
23564 and then Present (Encapsulating_State (Ref_Item_Id))
23565 and then Encapsulating_State (Ref_Item_Id) =
23566 Dep_Item_Id
23567 then
23568 Record_Item (Dep_Item_Id);
23569 Matched := True;
23570 end if;
23571 end if;
23573 -- An abstract state without a visible refinement matches
23574 -- itself.
23576 elsif Is_Entity_Name (Ref_Item)
23577 and then Entity_Of (Ref_Item) = Dep_Item_Id
23578 then
23579 Record_Item (Dep_Item_Id);
23580 Matched := True;
23581 end if;
23583 -- A current instance of a concurrent type, discriminant,
23584 -- formal parameter or an object matches itself.
23586 elsif Is_Entity_Name (Ref_Item)
23587 and then Entity_Of (Ref_Item) = Dep_Item_Id
23588 then
23589 Record_Item (Dep_Item_Id);
23590 Matched := True;
23591 end if;
23592 end if;
23593 end Match_Items;
23595 -----------------
23596 -- Record_Item --
23597 -----------------
23599 procedure Record_Item (Item_Id : Entity_Id) is
23600 begin
23601 if not Contains (Matched_Items, Item_Id) then
23602 Append_New_Elmt (Item_Id, Matched_Items);
23603 end if;
23604 end Record_Item;
23606 -- Local variables
23608 Clause_Matched : Boolean := False;
23609 Dummy : Boolean := False;
23610 Inputs_Match : Boolean;
23611 Next_Ref_Clause : Node_Id;
23612 Outputs_Match : Boolean;
23613 Ref_Clause : Node_Id;
23614 Ref_Input : Node_Id;
23615 Ref_Output : Node_Id;
23617 -- Start of processing for Check_Dependency_Clause
23619 begin
23620 -- Do not perform this check in an instance because it was already
23621 -- performed successfully in the generic template.
23623 if Is_Generic_Instance (Spec_Id) then
23624 return;
23625 end if;
23627 -- Examine all refinement clauses and compare them against the
23628 -- dependence clause.
23630 Ref_Clause := First (Refinements);
23631 while Present (Ref_Clause) loop
23632 Next_Ref_Clause := Next (Ref_Clause);
23634 -- Obtain the attributes of the current refinement clause
23636 Ref_Input := Expression (Ref_Clause);
23637 Ref_Output := First (Choices (Ref_Clause));
23639 -- The current refinement clause matches the dependence clause
23640 -- when both outputs match and both inputs match. See routine
23641 -- Match_Items for all possible conformance scenarios.
23643 -- Depends Dep_Output => Dep_Input
23644 -- ^ ^
23645 -- match ? match ?
23646 -- v v
23647 -- Refined_Depends Ref_Output => Ref_Input
23649 Match_Items
23650 (Dep_Item => Dep_Input,
23651 Ref_Item => Ref_Input,
23652 Matched => Inputs_Match);
23654 Match_Items
23655 (Dep_Item => Dep_Output,
23656 Ref_Item => Ref_Output,
23657 Matched => Outputs_Match);
23659 -- An In_Out state clause may be matched against a refinement with
23660 -- a null input or null output as long as the non-null side of the
23661 -- relation contains a valid constituent of the In_Out_State.
23663 if Is_In_Out_State_Clause then
23665 -- Depends => (State => State)
23666 -- Refined_Depends => (null => Constit) -- OK
23668 if Inputs_Match
23669 and then not Outputs_Match
23670 and then Nkind (Ref_Output) = N_Null
23671 then
23672 Outputs_Match := True;
23673 end if;
23675 -- Depends => (State => State)
23676 -- Refined_Depends => (Constit => null) -- OK
23678 if not Inputs_Match
23679 and then Outputs_Match
23680 and then Nkind (Ref_Input) = N_Null
23681 then
23682 Inputs_Match := True;
23683 end if;
23684 end if;
23686 -- The current refinement clause is legally constructed following
23687 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
23688 -- the pool of candidates. The seach continues because a single
23689 -- dependence clause may have multiple matching refinements.
23691 if Inputs_Match and Outputs_Match then
23692 Clause_Matched := True;
23693 Remove (Ref_Clause);
23694 end if;
23696 Ref_Clause := Next_Ref_Clause;
23697 end loop;
23699 -- Depending on the order or composition of refinement clauses, an
23700 -- In_Out state clause may not be directly refinable.
23702 -- Depends => ((Output, State) => (Input, State))
23703 -- Refined_State => (State => (Constit_1, Constit_2))
23704 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
23706 -- Matching normalized clause (State => State) fails because there is
23707 -- no direct refinement capable of satisfying this relation. Another
23708 -- similar case arises when clauses (Constit_1 => Input) and (Output
23709 -- => Constit_2) are matched first, leaving no candidates for clause
23710 -- (State => State). Both scenarios are legal as long as one of the
23711 -- previous clauses mentioned a valid constituent of State.
23713 if not Clause_Matched
23714 and then Is_In_Out_State_Clause
23715 and then
23716 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
23717 then
23718 Clause_Matched := True;
23719 end if;
23721 -- A clause where the input is an abstract state with visible null
23722 -- refinement is implicitly matched when the output has already been
23723 -- matched in a previous clause.
23725 -- Depends => (Output => State) -- implicitly OK
23726 -- Refined_State => (State => null)
23727 -- Refined_Depends => (Output => ...)
23729 if not Clause_Matched
23730 and then Is_Null_Refined_State (Dep_Input)
23731 and then Is_Entity_Name (Dep_Output)
23732 and then
23733 Contains (Matched_Items, Available_View (Entity_Of (Dep_Output)))
23734 then
23735 Clause_Matched := True;
23736 end if;
23738 -- A clause where the output is an abstract state with visible null
23739 -- refinement is implicitly matched when the input has already been
23740 -- matched in a previous clause.
23742 -- Depends => (State => Input) -- implicitly OK
23743 -- Refined_State => (State => null)
23744 -- Refined_Depends => (... => Input)
23746 if not Clause_Matched
23747 and then Is_Null_Refined_State (Dep_Output)
23748 and then Is_Entity_Name (Dep_Input)
23749 and then
23750 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
23751 then
23752 Clause_Matched := True;
23753 end if;
23755 -- At this point either all refinement clauses have been examined or
23756 -- pragma Refined_Depends contains a solitary null. Only an abstract
23757 -- state with null refinement can possibly match these cases.
23759 -- Depends => (State => null)
23760 -- Refined_State => (State => null)
23761 -- Refined_Depends => null -- OK
23763 if not Clause_Matched then
23764 Match_Items
23765 (Dep_Item => Dep_Input,
23766 Ref_Item => Empty,
23767 Matched => Inputs_Match);
23769 Match_Items
23770 (Dep_Item => Dep_Output,
23771 Ref_Item => Empty,
23772 Matched => Outputs_Match);
23774 Clause_Matched := Inputs_Match and Outputs_Match;
23775 end if;
23777 -- If the contents of Refined_Depends are legal, then the current
23778 -- dependence clause should be satisfied either by an explicit match
23779 -- or by one of the special cases.
23781 if not Clause_Matched then
23782 SPARK_Msg_NE
23783 (Fix_Msg (Spec_Id, "dependence clause of subprogram & has no "
23784 & "matching refinement in body"), Dep_Clause, Spec_Id);
23785 end if;
23786 end Check_Dependency_Clause;
23788 -------------------------
23789 -- Check_Output_States --
23790 -------------------------
23792 procedure Check_Output_States is
23793 procedure Check_Constituent_Usage (State_Id : Entity_Id);
23794 -- Determine whether all constituents of state State_Id with visible
23795 -- refinement are used as outputs in pragma Refined_Depends. Emit an
23796 -- error if this is not the case.
23798 -----------------------------
23799 -- Check_Constituent_Usage --
23800 -----------------------------
23802 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
23803 Constits : constant Elist_Id :=
23804 Refinement_Constituents (State_Id);
23805 Constit_Elmt : Elmt_Id;
23806 Constit_Id : Entity_Id;
23807 Posted : Boolean := False;
23809 begin
23810 if Present (Constits) then
23811 Constit_Elmt := First_Elmt (Constits);
23812 while Present (Constit_Elmt) loop
23813 Constit_Id := Node (Constit_Elmt);
23815 -- The constituent acts as an input (SPARK RM 7.2.5(3))
23817 if Present (Body_Inputs)
23818 and then Appears_In (Body_Inputs, Constit_Id)
23819 then
23820 Error_Msg_Name_1 := Chars (State_Id);
23821 SPARK_Msg_NE
23822 ("constituent & of state % must act as output in "
23823 & "dependence refinement", N, Constit_Id);
23825 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
23827 elsif No (Body_Outputs)
23828 or else not Appears_In (Body_Outputs, Constit_Id)
23829 then
23830 if not Posted then
23831 Posted := True;
23832 SPARK_Msg_NE
23833 ("output state & must be replaced by all its "
23834 & "constituents in dependence refinement",
23835 N, State_Id);
23836 end if;
23838 SPARK_Msg_NE
23839 ("\constituent & is missing in output list",
23840 N, Constit_Id);
23841 end if;
23843 Next_Elmt (Constit_Elmt);
23844 end loop;
23845 end if;
23846 end Check_Constituent_Usage;
23848 -- Local variables
23850 Item : Node_Id;
23851 Item_Elmt : Elmt_Id;
23852 Item_Id : Entity_Id;
23854 -- Start of processing for Check_Output_States
23856 begin
23857 -- Do not perform this check in an instance because it was already
23858 -- performed successfully in the generic template.
23860 if Is_Generic_Instance (Spec_Id) then
23861 null;
23863 -- Inspect the outputs of pragma Depends looking for a state with a
23864 -- visible refinement.
23866 elsif Present (Spec_Outputs) then
23867 Item_Elmt := First_Elmt (Spec_Outputs);
23868 while Present (Item_Elmt) loop
23869 Item := Node (Item_Elmt);
23871 -- Deal with the mixed nature of the input and output lists
23873 if Nkind (Item) = N_Defining_Identifier then
23874 Item_Id := Item;
23875 else
23876 Item_Id := Available_View (Entity_Of (Item));
23877 end if;
23879 if Ekind (Item_Id) = E_Abstract_State then
23881 -- The state acts as an input-output, skip it
23883 if Present (Spec_Inputs)
23884 and then Appears_In (Spec_Inputs, Item_Id)
23885 then
23886 null;
23888 -- Ensure that all of the constituents are utilized as
23889 -- outputs in pragma Refined_Depends.
23891 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
23892 Check_Constituent_Usage (Item_Id);
23893 end if;
23894 end if;
23896 Next_Elmt (Item_Elmt);
23897 end loop;
23898 end if;
23899 end Check_Output_States;
23901 -----------------------
23902 -- Normalize_Clauses --
23903 -----------------------
23905 procedure Normalize_Clauses (Clauses : List_Id) is
23906 procedure Normalize_Inputs (Clause : Node_Id);
23907 -- Normalize clause Clause by creating multiple clauses for each
23908 -- input item of Clause. It is assumed that Clause has exactly one
23909 -- output. The transformation is as follows:
23911 -- Output => (Input_1, Input_2) -- original
23913 -- Output => Input_1 -- normalizations
23914 -- Output => Input_2
23916 procedure Normalize_Outputs (Clause : Node_Id);
23917 -- Normalize clause Clause by creating multiple clause for each
23918 -- output item of Clause. The transformation is as follows:
23920 -- (Output_1, Output_2) => Input -- original
23922 -- Output_1 => Input -- normalization
23923 -- Output_2 => Input
23925 ----------------------
23926 -- Normalize_Inputs --
23927 ----------------------
23929 procedure Normalize_Inputs (Clause : Node_Id) is
23930 Inputs : constant Node_Id := Expression (Clause);
23931 Loc : constant Source_Ptr := Sloc (Clause);
23932 Output : constant List_Id := Choices (Clause);
23933 Last_Input : Node_Id;
23934 Input : Node_Id;
23935 New_Clause : Node_Id;
23936 Next_Input : Node_Id;
23938 begin
23939 -- Normalization is performed only when the original clause has
23940 -- more than one input. Multiple inputs appear as an aggregate.
23942 if Nkind (Inputs) = N_Aggregate then
23943 Last_Input := Last (Expressions (Inputs));
23945 -- Create a new clause for each input
23947 Input := First (Expressions (Inputs));
23948 while Present (Input) loop
23949 Next_Input := Next (Input);
23951 -- Unhook the current input from the original input list
23952 -- because it will be relocated to a new clause.
23954 Remove (Input);
23956 -- Special processing for the last input. At this point the
23957 -- original aggregate has been stripped down to one element.
23958 -- Replace the aggregate by the element itself.
23960 if Input = Last_Input then
23961 Rewrite (Inputs, Input);
23963 -- Generate a clause of the form:
23964 -- Output => Input
23966 else
23967 New_Clause :=
23968 Make_Component_Association (Loc,
23969 Choices => New_Copy_List_Tree (Output),
23970 Expression => Input);
23972 -- The new clause contains replicated content that has
23973 -- already been analyzed, mark the clause as analyzed.
23975 Set_Analyzed (New_Clause);
23976 Insert_After (Clause, New_Clause);
23977 end if;
23979 Input := Next_Input;
23980 end loop;
23981 end if;
23982 end Normalize_Inputs;
23984 -----------------------
23985 -- Normalize_Outputs --
23986 -----------------------
23988 procedure Normalize_Outputs (Clause : Node_Id) is
23989 Inputs : constant Node_Id := Expression (Clause);
23990 Loc : constant Source_Ptr := Sloc (Clause);
23991 Outputs : constant Node_Id := First (Choices (Clause));
23992 Last_Output : Node_Id;
23993 New_Clause : Node_Id;
23994 Next_Output : Node_Id;
23995 Output : Node_Id;
23997 begin
23998 -- Multiple outputs appear as an aggregate. Nothing to do when
23999 -- the clause has exactly one output.
24001 if Nkind (Outputs) = N_Aggregate then
24002 Last_Output := Last (Expressions (Outputs));
24004 -- Create a clause for each output. Note that each time a new
24005 -- clause is created, the original output list slowly shrinks
24006 -- until there is one item left.
24008 Output := First (Expressions (Outputs));
24009 while Present (Output) loop
24010 Next_Output := Next (Output);
24012 -- Unhook the output from the original output list as it
24013 -- will be relocated to a new clause.
24015 Remove (Output);
24017 -- Special processing for the last output. At this point
24018 -- the original aggregate has been stripped down to one
24019 -- element. Replace the aggregate by the element itself.
24021 if Output = Last_Output then
24022 Rewrite (Outputs, Output);
24024 else
24025 -- Generate a clause of the form:
24026 -- (Output => Inputs)
24028 New_Clause :=
24029 Make_Component_Association (Loc,
24030 Choices => New_List (Output),
24031 Expression => New_Copy_Tree (Inputs));
24033 -- The new clause contains replicated content that has
24034 -- already been analyzed. There is not need to reanalyze
24035 -- them.
24037 Set_Analyzed (New_Clause);
24038 Insert_After (Clause, New_Clause);
24039 end if;
24041 Output := Next_Output;
24042 end loop;
24043 end if;
24044 end Normalize_Outputs;
24046 -- Local variables
24048 Clause : Node_Id;
24050 -- Start of processing for Normalize_Clauses
24052 begin
24053 Clause := First (Clauses);
24054 while Present (Clause) loop
24055 Normalize_Outputs (Clause);
24056 Next (Clause);
24057 end loop;
24059 Clause := First (Clauses);
24060 while Present (Clause) loop
24061 Normalize_Inputs (Clause);
24062 Next (Clause);
24063 end loop;
24064 end Normalize_Clauses;
24066 --------------------------
24067 -- Report_Extra_Clauses --
24068 --------------------------
24070 procedure Report_Extra_Clauses is
24071 Clause : Node_Id;
24073 begin
24074 -- Do not perform this check in an instance because it was already
24075 -- performed successfully in the generic template.
24077 if Is_Generic_Instance (Spec_Id) then
24078 null;
24080 elsif Present (Refinements) then
24081 Clause := First (Refinements);
24082 while Present (Clause) loop
24084 -- Do not complain about a null input refinement, since a null
24085 -- input legitimately matches anything.
24087 if Nkind (Clause) = N_Component_Association
24088 and then Nkind (Expression (Clause)) = N_Null
24089 then
24090 null;
24092 else
24093 SPARK_Msg_N
24094 ("unmatched or extra clause in dependence refinement",
24095 Clause);
24096 end if;
24098 Next (Clause);
24099 end loop;
24100 end if;
24101 end Report_Extra_Clauses;
24103 -- Local variables
24105 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
24106 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
24107 Errors : constant Nat := Serious_Errors_Detected;
24108 Clause : Node_Id;
24109 Deps : Node_Id;
24110 Dummy : Boolean;
24111 Refs : Node_Id;
24113 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
24115 begin
24116 -- Do not analyze the pragma multiple times
24118 if Is_Analyzed_Pragma (N) then
24119 return;
24120 end if;
24122 Spec_Id := Unique_Defining_Entity (Body_Decl);
24124 -- Use the anonymous object as the proper spec when Refined_Depends
24125 -- applies to the body of a single task type. The object carries the
24126 -- proper Chars as well as all non-refined versions of pragmas.
24128 if Is_Single_Concurrent_Type (Spec_Id) then
24129 Spec_Id := Anonymous_Object (Spec_Id);
24130 end if;
24132 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
24134 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
24135 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
24137 if No (Depends) then
24138 SPARK_Msg_NE
24139 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
24140 & "& lacks aspect or pragma Depends"), N, Spec_Id);
24141 goto Leave;
24142 end if;
24144 Deps := Expression (Get_Argument (Depends, Spec_Id));
24146 -- A null dependency relation renders the refinement useless because it
24147 -- cannot possibly mention abstract states with visible refinement. Note
24148 -- that the inverse is not true as states may be refined to null
24149 -- (SPARK RM 7.2.5(2)).
24151 if Nkind (Deps) = N_Null then
24152 SPARK_Msg_NE
24153 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
24154 & "depend on abstract state with visible refinement"), N, Spec_Id);
24155 goto Leave;
24156 end if;
24158 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
24159 -- This ensures that the categorization of all refined dependency items
24160 -- is consistent with their role.
24162 Analyze_Depends_In_Decl_Part (N);
24164 -- Do not match dependencies against refinements if Refined_Depends is
24165 -- illegal to avoid emitting misleading error.
24167 if Serious_Errors_Detected = Errors then
24169 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
24170 -- the inputs and outputs of the subprogram spec and body to verify
24171 -- the use of states with visible refinement and their constituents.
24173 if No (Get_Pragma (Spec_Id, Pragma_Global))
24174 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
24175 then
24176 Collect_Subprogram_Inputs_Outputs
24177 (Subp_Id => Spec_Id,
24178 Synthesize => True,
24179 Subp_Inputs => Spec_Inputs,
24180 Subp_Outputs => Spec_Outputs,
24181 Global_Seen => Dummy);
24183 Collect_Subprogram_Inputs_Outputs
24184 (Subp_Id => Body_Id,
24185 Synthesize => True,
24186 Subp_Inputs => Body_Inputs,
24187 Subp_Outputs => Body_Outputs,
24188 Global_Seen => Dummy);
24190 -- For an output state with a visible refinement, ensure that all
24191 -- constituents appear as outputs in the dependency refinement.
24193 Check_Output_States;
24194 end if;
24196 -- Matching is disabled in ASIS because clauses are not normalized as
24197 -- this is a tree altering activity similar to expansion.
24199 if ASIS_Mode then
24200 goto Leave;
24201 end if;
24203 -- Multiple dependency clauses appear as component associations of an
24204 -- aggregate. Note that the clauses are copied because the algorithm
24205 -- modifies them and this should not be visible in Depends.
24207 pragma Assert (Nkind (Deps) = N_Aggregate);
24208 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
24209 Normalize_Clauses (Dependencies);
24211 Refs := Expression (Get_Argument (N, Spec_Id));
24213 if Nkind (Refs) = N_Null then
24214 Refinements := No_List;
24216 -- Multiple dependency clauses appear as component associations of an
24217 -- aggregate. Note that the clauses are copied because the algorithm
24218 -- modifies them and this should not be visible in Refined_Depends.
24220 else pragma Assert (Nkind (Refs) = N_Aggregate);
24221 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
24222 Normalize_Clauses (Refinements);
24223 end if;
24225 -- At this point the clauses of pragmas Depends and Refined_Depends
24226 -- have been normalized into simple dependencies between one output
24227 -- and one input. Examine all clauses of pragma Depends looking for
24228 -- matching clauses in pragma Refined_Depends.
24230 Clause := First (Dependencies);
24231 while Present (Clause) loop
24232 Check_Dependency_Clause (Clause);
24233 Next (Clause);
24234 end loop;
24236 if Serious_Errors_Detected = Errors then
24237 Report_Extra_Clauses;
24238 end if;
24239 end if;
24241 <<Leave>>
24242 Set_Is_Analyzed_Pragma (N);
24243 end Analyze_Refined_Depends_In_Decl_Part;
24245 -----------------------------------------
24246 -- Analyze_Refined_Global_In_Decl_Part --
24247 -----------------------------------------
24249 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
24250 Global : Node_Id;
24251 -- The corresponding Global pragma
24253 Has_In_State : Boolean := False;
24254 Has_In_Out_State : Boolean := False;
24255 Has_Out_State : Boolean := False;
24256 Has_Proof_In_State : Boolean := False;
24257 -- These flags are set when the corresponding Global pragma has a state
24258 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
24259 -- refinement.
24261 Has_Null_State : Boolean := False;
24262 -- This flag is set when the corresponding Global pragma has at least
24263 -- one state with a null refinement.
24265 In_Constits : Elist_Id := No_Elist;
24266 In_Out_Constits : Elist_Id := No_Elist;
24267 Out_Constits : Elist_Id := No_Elist;
24268 Proof_In_Constits : Elist_Id := No_Elist;
24269 -- These lists contain the entities of all Input, In_Out, Output and
24270 -- Proof_In constituents that appear in Refined_Global and participate
24271 -- in state refinement.
24273 In_Items : Elist_Id := No_Elist;
24274 In_Out_Items : Elist_Id := No_Elist;
24275 Out_Items : Elist_Id := No_Elist;
24276 Proof_In_Items : Elist_Id := No_Elist;
24277 -- These list contain the entities of all Input, In_Out, Output and
24278 -- Proof_In items defined in the corresponding Global pragma.
24280 Spec_Id : Entity_Id;
24281 -- The entity of the subprogram subject to pragma Refined_Global
24283 States : Elist_Id := No_Elist;
24284 -- A list of all states with visible refinement found in pragma Global
24286 procedure Check_In_Out_States;
24287 -- Determine whether the corresponding Global pragma mentions In_Out
24288 -- states with visible refinement and if so, ensure that one of the
24289 -- following completions apply to the constituents of the state:
24290 -- 1) there is at least one constituent of mode In_Out
24291 -- 2) there is at least one Input and one Output constituent
24292 -- 3) not all constituents are present and one of them is of mode
24293 -- Output.
24294 -- This routine may remove elements from In_Constits, In_Out_Constits,
24295 -- Out_Constits and Proof_In_Constits.
24297 procedure Check_Input_States;
24298 -- Determine whether the corresponding Global pragma mentions Input
24299 -- states with visible refinement and if so, ensure that at least one of
24300 -- its constituents appears as an Input item in Refined_Global.
24301 -- This routine may remove elements from In_Constits, In_Out_Constits,
24302 -- Out_Constits and Proof_In_Constits.
24304 procedure Check_Output_States;
24305 -- Determine whether the corresponding Global pragma mentions Output
24306 -- states with visible refinement and if so, ensure that all of its
24307 -- constituents appear as Output items in Refined_Global.
24308 -- This routine may remove elements from In_Constits, In_Out_Constits,
24309 -- Out_Constits and Proof_In_Constits.
24311 procedure Check_Proof_In_States;
24312 -- Determine whether the corresponding Global pragma mentions Proof_In
24313 -- states with visible refinement and if so, ensure that at least one of
24314 -- its constituents appears as a Proof_In item in Refined_Global.
24315 -- This routine may remove elements from In_Constits, In_Out_Constits,
24316 -- Out_Constits and Proof_In_Constits.
24318 procedure Check_Refined_Global_List
24319 (List : Node_Id;
24320 Global_Mode : Name_Id := Name_Input);
24321 -- Verify the legality of a single global list declaration. Global_Mode
24322 -- denotes the current mode in effect.
24324 procedure Collect_Global_Items
24325 (List : Node_Id;
24326 Mode : Name_Id := Name_Input);
24327 -- Gather all input, in out, output and Proof_In items from node List
24328 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
24329 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
24330 -- and Has_Proof_In_State are set when there is at least one abstract
24331 -- state with visible refinement available in the corresponding mode.
24332 -- Flag Has_Null_State is set when at least state has a null refinement.
24333 -- Mode enotes the current global mode in effect.
24335 function Present_Then_Remove
24336 (List : Elist_Id;
24337 Item : Entity_Id) return Boolean;
24338 -- Search List for a particular entity Item. If Item has been found,
24339 -- remove it from List. This routine is used to strip lists In_Constits,
24340 -- In_Out_Constits and Out_Constits of valid constituents.
24342 procedure Report_Extra_Constituents;
24343 -- Emit an error for each constituent found in lists In_Constits,
24344 -- In_Out_Constits and Out_Constits.
24346 -------------------------
24347 -- Check_In_Out_States --
24348 -------------------------
24350 procedure Check_In_Out_States is
24351 procedure Check_Constituent_Usage (State_Id : Entity_Id);
24352 -- Determine whether one of the following coverage scenarios is in
24353 -- effect:
24354 -- 1) there is at least one constituent of mode In_Out or Output
24355 -- 2) there is at least one pair of constituents with modes Input
24356 -- and Output, or Proof_In and Output.
24357 -- 3) there is at least one constituent of mode Output and not all
24358 -- constituents are present.
24359 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
24361 -----------------------------
24362 -- Check_Constituent_Usage --
24363 -----------------------------
24365 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
24366 Constits : constant Elist_Id :=
24367 Refinement_Constituents (State_Id);
24368 Constit_Elmt : Elmt_Id;
24369 Constit_Id : Entity_Id;
24370 Has_Missing : Boolean := False;
24371 In_Out_Seen : Boolean := False;
24372 Input_Seen : Boolean := False;
24373 Output_Seen : Boolean := False;
24374 Proof_In_Seen : Boolean := False;
24376 begin
24377 -- Process all the constituents of the state and note their modes
24378 -- within the global refinement.
24380 if Present (Constits) then
24381 Constit_Elmt := First_Elmt (Constits);
24382 while Present (Constit_Elmt) loop
24383 Constit_Id := Node (Constit_Elmt);
24385 if Present_Then_Remove (In_Constits, Constit_Id) then
24386 Input_Seen := True;
24388 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
24389 In_Out_Seen := True;
24391 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
24392 Output_Seen := True;
24394 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
24395 then
24396 Proof_In_Seen := True;
24398 else
24399 Has_Missing := True;
24400 end if;
24402 Next_Elmt (Constit_Elmt);
24403 end loop;
24404 end if;
24406 -- An In_Out constituent is a valid completion
24408 if In_Out_Seen then
24409 null;
24411 -- A pair of one Input/Proof_In and one Output constituent is a
24412 -- valid completion.
24414 elsif (Input_Seen or Proof_In_Seen) and Output_Seen then
24415 null;
24417 elsif Output_Seen then
24419 -- A single Output constituent is a valid completion only when
24420 -- some of the other constituents are missing.
24422 if Has_Missing then
24423 null;
24425 -- Otherwise all constituents are of mode Output
24427 else
24428 SPARK_Msg_NE
24429 ("global refinement of state & must include at least one "
24430 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
24431 N, State_Id);
24432 end if;
24434 -- The state lacks a completion
24436 elsif not Input_Seen
24437 and not In_Out_Seen
24438 and not Output_Seen
24439 and not Proof_In_Seen
24440 then
24441 SPARK_Msg_NE
24442 ("missing global refinement of state &", N, State_Id);
24444 -- Otherwise the state has a malformed completion where at least
24445 -- one of the constituents has a different mode.
24447 else
24448 SPARK_Msg_NE
24449 ("global refinement of state & redefines the mode of its "
24450 & "constituents", N, State_Id);
24451 end if;
24452 end Check_Constituent_Usage;
24454 -- Local variables
24456 Item_Elmt : Elmt_Id;
24457 Item_Id : Entity_Id;
24459 -- Start of processing for Check_In_Out_States
24461 begin
24462 -- Do not perform this check in an instance because it was already
24463 -- performed successfully in the generic template.
24465 if Is_Generic_Instance (Spec_Id) then
24466 null;
24468 -- Inspect the In_Out items of the corresponding Global pragma
24469 -- looking for a state with a visible refinement.
24471 elsif Has_In_Out_State and then Present (In_Out_Items) then
24472 Item_Elmt := First_Elmt (In_Out_Items);
24473 while Present (Item_Elmt) loop
24474 Item_Id := Node (Item_Elmt);
24476 -- Ensure that one of the three coverage variants is satisfied
24478 if Ekind (Item_Id) = E_Abstract_State
24479 and then Has_Non_Null_Visible_Refinement (Item_Id)
24480 then
24481 Check_Constituent_Usage (Item_Id);
24482 end if;
24484 Next_Elmt (Item_Elmt);
24485 end loop;
24486 end if;
24487 end Check_In_Out_States;
24489 ------------------------
24490 -- Check_Input_States --
24491 ------------------------
24493 procedure Check_Input_States is
24494 procedure Check_Constituent_Usage (State_Id : Entity_Id);
24495 -- Determine whether at least one constituent of state State_Id with
24496 -- visible refinement is used and has mode Input. Ensure that the
24497 -- remaining constituents do not have In_Out or Output modes. Emit an
24498 -- error if this is not the case (SPARK RM 7.2.4(5)).
24500 -----------------------------
24501 -- Check_Constituent_Usage --
24502 -----------------------------
24504 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
24505 Constits : constant Elist_Id :=
24506 Refinement_Constituents (State_Id);
24507 Constit_Elmt : Elmt_Id;
24508 Constit_Id : Entity_Id;
24509 In_Seen : Boolean := False;
24511 begin
24512 if Present (Constits) then
24513 Constit_Elmt := First_Elmt (Constits);
24514 while Present (Constit_Elmt) loop
24515 Constit_Id := Node (Constit_Elmt);
24517 -- At least one of the constituents appears as an Input
24519 if Present_Then_Remove (In_Constits, Constit_Id) then
24520 In_Seen := True;
24522 -- A Proof_In constituent can refine an Input state as long
24523 -- as there is at least one Input constituent present.
24525 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
24526 then
24527 null;
24529 -- The constituent appears in the global refinement, but has
24530 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
24532 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
24533 or else Present_Then_Remove (Out_Constits, Constit_Id)
24534 then
24535 Error_Msg_Name_1 := Chars (State_Id);
24536 SPARK_Msg_NE
24537 ("constituent & of state % must have mode `Input` in "
24538 & "global refinement", N, Constit_Id);
24539 end if;
24541 Next_Elmt (Constit_Elmt);
24542 end loop;
24543 end if;
24545 -- Not one of the constituents appeared as Input
24547 if not In_Seen then
24548 SPARK_Msg_NE
24549 ("global refinement of state & must include at least one "
24550 & "constituent of mode `Input`", N, State_Id);
24551 end if;
24552 end Check_Constituent_Usage;
24554 -- Local variables
24556 Item_Elmt : Elmt_Id;
24557 Item_Id : Entity_Id;
24559 -- Start of processing for Check_Input_States
24561 begin
24562 -- Do not perform this check in an instance because it was already
24563 -- performed successfully in the generic template.
24565 if Is_Generic_Instance (Spec_Id) then
24566 null;
24568 -- Inspect the Input items of the corresponding Global pragma looking
24569 -- for a state with a visible refinement.
24571 elsif Has_In_State and then Present (In_Items) then
24572 Item_Elmt := First_Elmt (In_Items);
24573 while Present (Item_Elmt) loop
24574 Item_Id := Node (Item_Elmt);
24576 -- Ensure that at least one of the constituents is utilized and
24577 -- is of mode Input.
24579 if Ekind (Item_Id) = E_Abstract_State
24580 and then Has_Non_Null_Visible_Refinement (Item_Id)
24581 then
24582 Check_Constituent_Usage (Item_Id);
24583 end if;
24585 Next_Elmt (Item_Elmt);
24586 end loop;
24587 end if;
24588 end Check_Input_States;
24590 -------------------------
24591 -- Check_Output_States --
24592 -------------------------
24594 procedure Check_Output_States is
24595 procedure Check_Constituent_Usage (State_Id : Entity_Id);
24596 -- Determine whether all constituents of state State_Id with visible
24597 -- refinement are used and have mode Output. Emit an error if this is
24598 -- not the case (SPARK RM 7.2.4(5)).
24600 -----------------------------
24601 -- Check_Constituent_Usage --
24602 -----------------------------
24604 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
24605 Constits : constant Elist_Id :=
24606 Refinement_Constituents (State_Id);
24607 Constit_Elmt : Elmt_Id;
24608 Constit_Id : Entity_Id;
24609 Posted : Boolean := False;
24611 begin
24612 if Present (Constits) then
24613 Constit_Elmt := First_Elmt (Constits);
24614 while Present (Constit_Elmt) loop
24615 Constit_Id := Node (Constit_Elmt);
24617 if Present_Then_Remove (Out_Constits, Constit_Id) then
24618 null;
24620 -- The constituent appears in the global refinement, but has
24621 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
24623 elsif Present_Then_Remove (In_Constits, Constit_Id)
24624 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
24625 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
24626 then
24627 Error_Msg_Name_1 := Chars (State_Id);
24628 SPARK_Msg_NE
24629 ("constituent & of state % must have mode `Output` in "
24630 & "global refinement", N, Constit_Id);
24632 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
24634 else
24635 if not Posted then
24636 Posted := True;
24637 SPARK_Msg_NE
24638 ("`Output` state & must be replaced by all its "
24639 & "constituents in global refinement", N, State_Id);
24640 end if;
24642 SPARK_Msg_NE
24643 ("\constituent & is missing in output list",
24644 N, Constit_Id);
24645 end if;
24647 Next_Elmt (Constit_Elmt);
24648 end loop;
24649 end if;
24650 end Check_Constituent_Usage;
24652 -- Local variables
24654 Item_Elmt : Elmt_Id;
24655 Item_Id : Entity_Id;
24657 -- Start of processing for Check_Output_States
24659 begin
24660 -- Do not perform this check in an instance because it was already
24661 -- performed successfully in the generic template.
24663 if Is_Generic_Instance (Spec_Id) then
24664 null;
24666 -- Inspect the Output items of the corresponding Global pragma
24667 -- looking for a state with a visible refinement.
24669 elsif Has_Out_State and then Present (Out_Items) then
24670 Item_Elmt := First_Elmt (Out_Items);
24671 while Present (Item_Elmt) loop
24672 Item_Id := Node (Item_Elmt);
24674 -- Ensure that all of the constituents are utilized and they
24675 -- have mode Output.
24677 if Ekind (Item_Id) = E_Abstract_State
24678 and then Has_Non_Null_Visible_Refinement (Item_Id)
24679 then
24680 Check_Constituent_Usage (Item_Id);
24681 end if;
24683 Next_Elmt (Item_Elmt);
24684 end loop;
24685 end if;
24686 end Check_Output_States;
24688 ---------------------------
24689 -- Check_Proof_In_States --
24690 ---------------------------
24692 procedure Check_Proof_In_States is
24693 procedure Check_Constituent_Usage (State_Id : Entity_Id);
24694 -- Determine whether at least one constituent of state State_Id with
24695 -- visible refinement is used and has mode Proof_In. Ensure that the
24696 -- remaining constituents do not have Input, In_Out or Output modes.
24697 -- Emit an error of this is not the case (SPARK RM 7.2.4(5)).
24699 -----------------------------
24700 -- Check_Constituent_Usage --
24701 -----------------------------
24703 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
24704 Constits : constant Elist_Id :=
24705 Refinement_Constituents (State_Id);
24706 Constit_Elmt : Elmt_Id;
24707 Constit_Id : Entity_Id;
24708 Proof_In_Seen : Boolean := False;
24710 begin
24711 if Present (Constits) then
24712 Constit_Elmt := First_Elmt (Constits);
24713 while Present (Constit_Elmt) loop
24714 Constit_Id := Node (Constit_Elmt);
24716 -- At least one of the constituents appears as Proof_In
24718 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
24719 Proof_In_Seen := True;
24721 -- The constituent appears in the global refinement, but has
24722 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
24724 elsif Present_Then_Remove (In_Constits, Constit_Id)
24725 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
24726 or else Present_Then_Remove (Out_Constits, Constit_Id)
24727 then
24728 Error_Msg_Name_1 := Chars (State_Id);
24729 SPARK_Msg_NE
24730 ("constituent & of state % must have mode `Proof_In` "
24731 & "in global refinement", N, Constit_Id);
24732 end if;
24734 Next_Elmt (Constit_Elmt);
24735 end loop;
24736 end if;
24738 -- Not one of the constituents appeared as Proof_In
24740 if not Proof_In_Seen then
24741 SPARK_Msg_NE
24742 ("global refinement of state & must include at least one "
24743 & "constituent of mode `Proof_In`", N, State_Id);
24744 end if;
24745 end Check_Constituent_Usage;
24747 -- Local variables
24749 Item_Elmt : Elmt_Id;
24750 Item_Id : Entity_Id;
24752 -- Start of processing for Check_Proof_In_States
24754 begin
24755 -- Do not perform this check in an instance because it was already
24756 -- performed successfully in the generic template.
24758 if Is_Generic_Instance (Spec_Id) then
24759 null;
24761 -- Inspect the Proof_In items of the corresponding Global pragma
24762 -- looking for a state with a visible refinement.
24764 elsif Has_Proof_In_State and then Present (Proof_In_Items) then
24765 Item_Elmt := First_Elmt (Proof_In_Items);
24766 while Present (Item_Elmt) loop
24767 Item_Id := Node (Item_Elmt);
24769 -- Ensure that at least one of the constituents is utilized and
24770 -- is of mode Proof_In
24772 if Ekind (Item_Id) = E_Abstract_State
24773 and then Has_Non_Null_Visible_Refinement (Item_Id)
24774 then
24775 Check_Constituent_Usage (Item_Id);
24776 end if;
24778 Next_Elmt (Item_Elmt);
24779 end loop;
24780 end if;
24781 end Check_Proof_In_States;
24783 -------------------------------
24784 -- Check_Refined_Global_List --
24785 -------------------------------
24787 procedure Check_Refined_Global_List
24788 (List : Node_Id;
24789 Global_Mode : Name_Id := Name_Input)
24791 procedure Check_Refined_Global_Item
24792 (Item : Node_Id;
24793 Global_Mode : Name_Id);
24794 -- Verify the legality of a single global item declaration. Parameter
24795 -- Global_Mode denotes the current mode in effect.
24797 -------------------------------
24798 -- Check_Refined_Global_Item --
24799 -------------------------------
24801 procedure Check_Refined_Global_Item
24802 (Item : Node_Id;
24803 Global_Mode : Name_Id)
24805 Item_Id : constant Entity_Id := Entity_Of (Item);
24807 procedure Inconsistent_Mode_Error (Expect : Name_Id);
24808 -- Issue a common error message for all mode mismatches. Expect
24809 -- denotes the expected mode.
24811 -----------------------------
24812 -- Inconsistent_Mode_Error --
24813 -----------------------------
24815 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
24816 begin
24817 SPARK_Msg_NE
24818 ("global item & has inconsistent modes", Item, Item_Id);
24820 Error_Msg_Name_1 := Global_Mode;
24821 Error_Msg_Name_2 := Expect;
24822 SPARK_Msg_N ("\expected mode %, found mode %", Item);
24823 end Inconsistent_Mode_Error;
24825 -- Start of processing for Check_Refined_Global_Item
24827 begin
24828 -- When the state or object acts as a constituent of another
24829 -- state with a visible refinement, collect it for the state
24830 -- completeness checks performed later on. Note that the item
24831 -- acts as a constituent only when the encapsulating state is
24832 -- present in pragma Global.
24834 if Ekind_In (Item_Id, E_Abstract_State, E_Constant, E_Variable)
24835 and then Present (Encapsulating_State (Item_Id))
24836 and then Has_Visible_Refinement (Encapsulating_State (Item_Id))
24837 and then Contains (States, Encapsulating_State (Item_Id))
24838 then
24839 if Global_Mode = Name_Input then
24840 Append_New_Elmt (Item_Id, In_Constits);
24842 elsif Global_Mode = Name_In_Out then
24843 Append_New_Elmt (Item_Id, In_Out_Constits);
24845 elsif Global_Mode = Name_Output then
24846 Append_New_Elmt (Item_Id, Out_Constits);
24848 elsif Global_Mode = Name_Proof_In then
24849 Append_New_Elmt (Item_Id, Proof_In_Constits);
24850 end if;
24852 -- When not a constituent, ensure that both occurrences of the
24853 -- item in pragmas Global and Refined_Global match.
24855 elsif Contains (In_Items, Item_Id) then
24856 if Global_Mode /= Name_Input then
24857 Inconsistent_Mode_Error (Name_Input);
24858 end if;
24860 elsif Contains (In_Out_Items, Item_Id) then
24861 if Global_Mode /= Name_In_Out then
24862 Inconsistent_Mode_Error (Name_In_Out);
24863 end if;
24865 elsif Contains (Out_Items, Item_Id) then
24866 if Global_Mode /= Name_Output then
24867 Inconsistent_Mode_Error (Name_Output);
24868 end if;
24870 elsif Contains (Proof_In_Items, Item_Id) then
24871 null;
24873 -- The item does not appear in the corresponding Global pragma,
24874 -- it must be an extra (SPARK RM 7.2.4(3)).
24876 else
24877 SPARK_Msg_NE ("extra global item &", Item, Item_Id);
24878 end if;
24879 end Check_Refined_Global_Item;
24881 -- Local variables
24883 Item : Node_Id;
24885 -- Start of processing for Check_Refined_Global_List
24887 begin
24888 -- Do not perform this check in an instance because it was already
24889 -- performed successfully in the generic template.
24891 if Is_Generic_Instance (Spec_Id) then
24892 null;
24894 elsif Nkind (List) = N_Null then
24895 null;
24897 -- Single global item declaration
24899 elsif Nkind_In (List, N_Expanded_Name,
24900 N_Identifier,
24901 N_Selected_Component)
24902 then
24903 Check_Refined_Global_Item (List, Global_Mode);
24905 -- Simple global list or moded global list declaration
24907 elsif Nkind (List) = N_Aggregate then
24909 -- The declaration of a simple global list appear as a collection
24910 -- of expressions.
24912 if Present (Expressions (List)) then
24913 Item := First (Expressions (List));
24914 while Present (Item) loop
24915 Check_Refined_Global_Item (Item, Global_Mode);
24916 Next (Item);
24917 end loop;
24919 -- The declaration of a moded global list appears as a collection
24920 -- of component associations where individual choices denote
24921 -- modes.
24923 elsif Present (Component_Associations (List)) then
24924 Item := First (Component_Associations (List));
24925 while Present (Item) loop
24926 Check_Refined_Global_List
24927 (List => Expression (Item),
24928 Global_Mode => Chars (First (Choices (Item))));
24930 Next (Item);
24931 end loop;
24933 -- Invalid tree
24935 else
24936 raise Program_Error;
24937 end if;
24939 -- Invalid list
24941 else
24942 raise Program_Error;
24943 end if;
24944 end Check_Refined_Global_List;
24946 --------------------------
24947 -- Collect_Global_Items --
24948 --------------------------
24950 procedure Collect_Global_Items
24951 (List : Node_Id;
24952 Mode : Name_Id := Name_Input)
24954 procedure Collect_Global_Item
24955 (Item : Node_Id;
24956 Item_Mode : Name_Id);
24957 -- Add a single item to the appropriate list. Item_Mode denotes the
24958 -- current mode in effect.
24960 -------------------------
24961 -- Collect_Global_Item --
24962 -------------------------
24964 procedure Collect_Global_Item
24965 (Item : Node_Id;
24966 Item_Mode : Name_Id)
24968 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
24969 -- The above handles abstract views of variables and states built
24970 -- for limited with clauses.
24972 begin
24973 -- Signal that the global list contains at least one abstract
24974 -- state with a visible refinement. Note that the refinement may
24975 -- be null in which case there are no constituents.
24977 if Ekind (Item_Id) = E_Abstract_State then
24978 if Has_Null_Visible_Refinement (Item_Id) then
24979 Has_Null_State := True;
24981 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
24982 Append_New_Elmt (Item_Id, States);
24984 if Item_Mode = Name_Input then
24985 Has_In_State := True;
24986 elsif Item_Mode = Name_In_Out then
24987 Has_In_Out_State := True;
24988 elsif Item_Mode = Name_Output then
24989 Has_Out_State := True;
24990 elsif Item_Mode = Name_Proof_In then
24991 Has_Proof_In_State := True;
24992 end if;
24993 end if;
24994 end if;
24996 -- Add the item to the proper list
24998 if Item_Mode = Name_Input then
24999 Append_New_Elmt (Item_Id, In_Items);
25000 elsif Item_Mode = Name_In_Out then
25001 Append_New_Elmt (Item_Id, In_Out_Items);
25002 elsif Item_Mode = Name_Output then
25003 Append_New_Elmt (Item_Id, Out_Items);
25004 elsif Item_Mode = Name_Proof_In then
25005 Append_New_Elmt (Item_Id, Proof_In_Items);
25006 end if;
25007 end Collect_Global_Item;
25009 -- Local variables
25011 Item : Node_Id;
25013 -- Start of processing for Collect_Global_Items
25015 begin
25016 if Nkind (List) = N_Null then
25017 null;
25019 -- Single global item declaration
25021 elsif Nkind_In (List, N_Expanded_Name,
25022 N_Identifier,
25023 N_Selected_Component)
25024 then
25025 Collect_Global_Item (List, Mode);
25027 -- Single global list or moded global list declaration
25029 elsif Nkind (List) = N_Aggregate then
25031 -- The declaration of a simple global list appear as a collection
25032 -- of expressions.
25034 if Present (Expressions (List)) then
25035 Item := First (Expressions (List));
25036 while Present (Item) loop
25037 Collect_Global_Item (Item, Mode);
25038 Next (Item);
25039 end loop;
25041 -- The declaration of a moded global list appears as a collection
25042 -- of component associations where individual choices denote mode.
25044 elsif Present (Component_Associations (List)) then
25045 Item := First (Component_Associations (List));
25046 while Present (Item) loop
25047 Collect_Global_Items
25048 (List => Expression (Item),
25049 Mode => Chars (First (Choices (Item))));
25051 Next (Item);
25052 end loop;
25054 -- Invalid tree
25056 else
25057 raise Program_Error;
25058 end if;
25060 -- To accomodate partial decoration of disabled SPARK features, this
25061 -- routine may be called with illegal input. If this is the case, do
25062 -- not raise Program_Error.
25064 else
25065 null;
25066 end if;
25067 end Collect_Global_Items;
25069 -------------------------
25070 -- Present_Then_Remove --
25071 -------------------------
25073 function Present_Then_Remove
25074 (List : Elist_Id;
25075 Item : Entity_Id) return Boolean
25077 Elmt : Elmt_Id;
25079 begin
25080 if Present (List) then
25081 Elmt := First_Elmt (List);
25082 while Present (Elmt) loop
25083 if Node (Elmt) = Item then
25084 Remove_Elmt (List, Elmt);
25085 return True;
25086 end if;
25088 Next_Elmt (Elmt);
25089 end loop;
25090 end if;
25092 return False;
25093 end Present_Then_Remove;
25095 -------------------------------
25096 -- Report_Extra_Constituents --
25097 -------------------------------
25099 procedure Report_Extra_Constituents is
25100 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
25101 -- Emit an error for every element of List
25103 ---------------------------------------
25104 -- Report_Extra_Constituents_In_List --
25105 ---------------------------------------
25107 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
25108 Constit_Elmt : Elmt_Id;
25110 begin
25111 if Present (List) then
25112 Constit_Elmt := First_Elmt (List);
25113 while Present (Constit_Elmt) loop
25114 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
25115 Next_Elmt (Constit_Elmt);
25116 end loop;
25117 end if;
25118 end Report_Extra_Constituents_In_List;
25120 -- Start of processing for Report_Extra_Constituents
25122 begin
25123 -- Do not perform this check in an instance because it was already
25124 -- performed successfully in the generic template.
25126 if Is_Generic_Instance (Spec_Id) then
25127 null;
25129 else
25130 Report_Extra_Constituents_In_List (In_Constits);
25131 Report_Extra_Constituents_In_List (In_Out_Constits);
25132 Report_Extra_Constituents_In_List (Out_Constits);
25133 Report_Extra_Constituents_In_List (Proof_In_Constits);
25134 end if;
25135 end Report_Extra_Constituents;
25137 -- Local variables
25139 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
25140 Errors : constant Nat := Serious_Errors_Detected;
25141 Items : Node_Id;
25143 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
25145 begin
25146 -- Do not analyze the pragma multiple times
25148 if Is_Analyzed_Pragma (N) then
25149 return;
25150 end if;
25152 Spec_Id := Unique_Defining_Entity (Body_Decl);
25154 -- Use the anonymous object as the proper spec when Refined_Global
25155 -- applies to the body of a single task type. The object carries the
25156 -- proper Chars as well as all non-refined versions of pragmas.
25158 if Is_Single_Concurrent_Type (Spec_Id) then
25159 Spec_Id := Anonymous_Object (Spec_Id);
25160 end if;
25162 Global := Get_Pragma (Spec_Id, Pragma_Global);
25163 Items := Expression (Get_Argument (N, Spec_Id));
25165 -- The subprogram declaration lacks pragma Global. This renders
25166 -- Refined_Global useless as there is nothing to refine.
25168 if No (Global) then
25169 SPARK_Msg_NE
25170 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
25171 & "& lacks aspect or pragma Global"), N, Spec_Id);
25172 goto Leave;
25173 end if;
25175 -- Extract all relevant items from the corresponding Global pragma
25177 Collect_Global_Items (Expression (Get_Argument (Global, Spec_Id)));
25179 -- Package and subprogram bodies are instantiated individually in
25180 -- a separate compiler pass. Due to this mode of instantiation, the
25181 -- refinement of a state may no longer be visible when a subprogram
25182 -- body contract is instantiated. Since the generic template is legal,
25183 -- do not perform this check in the instance to circumvent this oddity.
25185 if Is_Generic_Instance (Spec_Id) then
25186 null;
25188 -- Non-instance case
25190 else
25191 -- The corresponding Global pragma must mention at least one state
25192 -- witha visible refinement at the point Refined_Global is processed.
25193 -- States with null refinements need Refined_Global pragma
25194 -- (SPARK RM 7.2.4(2)).
25196 if not Has_In_State
25197 and then not Has_In_Out_State
25198 and then not Has_Out_State
25199 and then not Has_Proof_In_State
25200 and then not Has_Null_State
25201 then
25202 SPARK_Msg_NE
25203 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
25204 & "depend on abstract state with visible refinement"),
25205 N, Spec_Id);
25206 goto Leave;
25208 -- The global refinement of inputs and outputs cannot be null when
25209 -- the corresponding Global pragma contains at least one item except
25210 -- in the case where we have states with null refinements.
25212 elsif Nkind (Items) = N_Null
25213 and then
25214 (Present (In_Items)
25215 or else Present (In_Out_Items)
25216 or else Present (Out_Items)
25217 or else Present (Proof_In_Items))
25218 and then not Has_Null_State
25219 then
25220 SPARK_Msg_NE
25221 (Fix_Msg (Spec_Id, "refinement cannot be null, subprogram & has "
25222 & "global items"), N, Spec_Id);
25223 goto Leave;
25224 end if;
25225 end if;
25227 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
25228 -- This ensures that the categorization of all refined global items is
25229 -- consistent with their role.
25231 Analyze_Global_In_Decl_Part (N);
25233 -- Perform all refinement checks with respect to completeness and mode
25234 -- matching.
25236 if Serious_Errors_Detected = Errors then
25237 Check_Refined_Global_List (Items);
25238 end if;
25240 -- For Input states with visible refinement, at least one constituent
25241 -- must be used as an Input in the global refinement.
25243 if Serious_Errors_Detected = Errors then
25244 Check_Input_States;
25245 end if;
25247 -- Verify all possible completion variants for In_Out states with
25248 -- visible refinement.
25250 if Serious_Errors_Detected = Errors then
25251 Check_In_Out_States;
25252 end if;
25254 -- For Output states with visible refinement, all constituents must be
25255 -- used as Outputs in the global refinement.
25257 if Serious_Errors_Detected = Errors then
25258 Check_Output_States;
25259 end if;
25261 -- For Proof_In states with visible refinement, at least one constituent
25262 -- must be used as Proof_In in the global refinement.
25264 if Serious_Errors_Detected = Errors then
25265 Check_Proof_In_States;
25266 end if;
25268 -- Emit errors for all constituents that belong to other states with
25269 -- visible refinement that do not appear in Global.
25271 if Serious_Errors_Detected = Errors then
25272 Report_Extra_Constituents;
25273 end if;
25275 <<Leave>>
25276 Set_Is_Analyzed_Pragma (N);
25277 end Analyze_Refined_Global_In_Decl_Part;
25279 ----------------------------------------
25280 -- Analyze_Refined_State_In_Decl_Part --
25281 ----------------------------------------
25283 procedure Analyze_Refined_State_In_Decl_Part
25284 (N : Node_Id;
25285 Freeze_Id : Entity_Id := Empty)
25287 Body_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
25288 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
25289 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
25291 Available_States : Elist_Id := No_Elist;
25292 -- A list of all abstract states defined in the package declaration that
25293 -- are available for refinement. The list is used to report unrefined
25294 -- states.
25296 Body_States : Elist_Id := No_Elist;
25297 -- A list of all hidden states that appear in the body of the related
25298 -- package. The list is used to report unused hidden states.
25300 Constituents_Seen : Elist_Id := No_Elist;
25301 -- A list that contains all constituents processed so far. The list is
25302 -- used to detect multiple uses of the same constituent.
25304 Freeze_Posted : Boolean := False;
25305 -- A flag that controls the output of a freezing-related error (see use
25306 -- below).
25308 Refined_States_Seen : Elist_Id := No_Elist;
25309 -- A list that contains all refined states processed so far. The list is
25310 -- used to detect duplicate refinements.
25312 procedure Analyze_Refinement_Clause (Clause : Node_Id);
25313 -- Perform full analysis of a single refinement clause
25315 procedure Report_Unrefined_States (States : Elist_Id);
25316 -- Emit errors for all unrefined abstract states found in list States
25318 -------------------------------
25319 -- Analyze_Refinement_Clause --
25320 -------------------------------
25322 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
25323 AR_Constit : Entity_Id := Empty;
25324 AW_Constit : Entity_Id := Empty;
25325 ER_Constit : Entity_Id := Empty;
25326 EW_Constit : Entity_Id := Empty;
25327 -- The entities of external constituents that contain one of the
25328 -- following enabled properties: Async_Readers, Async_Writers,
25329 -- Effective_Reads and Effective_Writes.
25331 External_Constit_Seen : Boolean := False;
25332 -- Flag used to mark when at least one external constituent is part
25333 -- of the state refinement.
25335 Non_Null_Seen : Boolean := False;
25336 Null_Seen : Boolean := False;
25337 -- Flags used to detect multiple uses of null in a single clause or a
25338 -- mixture of null and non-null constituents.
25340 Part_Of_Constits : Elist_Id := No_Elist;
25341 -- A list of all candidate constituents subject to indicator Part_Of
25342 -- where the encapsulating state is the current state.
25344 State : Node_Id;
25345 State_Id : Entity_Id;
25346 -- The current state being refined
25348 procedure Analyze_Constituent (Constit : Node_Id);
25349 -- Perform full analysis of a single constituent
25351 procedure Check_External_Property
25352 (Prop_Nam : Name_Id;
25353 Enabled : Boolean;
25354 Constit : Entity_Id);
25355 -- Determine whether a property denoted by name Prop_Nam is present
25356 -- in the refined state. Emit an error if this is not the case. Flag
25357 -- Enabled should be set when the property applies to the refined
25358 -- state. Constit denotes the constituent (if any) which introduces
25359 -- the property in the refinement.
25361 procedure Match_State;
25362 -- Determine whether the state being refined appears in list
25363 -- Available_States. Emit an error when attempting to re-refine the
25364 -- state or when the state is not defined in the package declaration,
25365 -- otherwise remove the state from Available_States.
25367 procedure Report_Unused_Constituents (Constits : Elist_Id);
25368 -- Emit errors for all unused Part_Of constituents in list Constits
25370 -------------------------
25371 -- Analyze_Constituent --
25372 -------------------------
25374 procedure Analyze_Constituent (Constit : Node_Id) is
25375 procedure Match_Constituent (Constit_Id : Entity_Id);
25376 -- Determine whether constituent Constit denoted by its entity
25377 -- Constit_Id appears in Body_States. Emit an error when the
25378 -- constituent is not a valid hidden state of the related package
25379 -- or when it is used more than once. Otherwise remove the
25380 -- constituent from Body_States.
25382 -----------------------
25383 -- Match_Constituent --
25384 -----------------------
25386 procedure Match_Constituent (Constit_Id : Entity_Id) is
25387 procedure Collect_Constituent;
25388 -- Verify the legality of constituent Constit_Id and add it to
25389 -- the refinements of State_Id.
25391 -------------------------
25392 -- Collect_Constituent --
25393 -------------------------
25395 procedure Collect_Constituent is
25396 Constits : Elist_Id;
25398 begin
25399 -- The Ghost policy in effect at the point of abstract state
25400 -- declaration and constituent must match (SPARK RM 6.9(15))
25402 Check_Ghost_Refinement
25403 (State, State_Id, Constit, Constit_Id);
25405 -- A synchronized state must be refined by a synchronized
25406 -- object or another synchronized state (SPARK RM 9.6).
25408 if Is_Synchronized_State (State_Id)
25409 and then not Is_Synchronized_Object (Constit_Id)
25410 and then not Is_Synchronized_State (Constit_Id)
25411 then
25412 SPARK_Msg_NE
25413 ("constituent of synchronized state & must be "
25414 & "synchronized", Constit, State_Id);
25415 end if;
25417 -- Add the constituent to the list of processed items to aid
25418 -- with the detection of duplicates.
25420 Append_New_Elmt (Constit_Id, Constituents_Seen);
25422 -- Collect the constituent in the list of refinement items
25423 -- and establish a relation between the refined state and
25424 -- the item.
25426 Constits := Refinement_Constituents (State_Id);
25428 if No (Constits) then
25429 Constits := New_Elmt_List;
25430 Set_Refinement_Constituents (State_Id, Constits);
25431 end if;
25433 Append_Elmt (Constit_Id, Constits);
25434 Set_Encapsulating_State (Constit_Id, State_Id);
25436 -- The state has at least one legal constituent, mark the
25437 -- start of the refinement region. The region ends when the
25438 -- body declarations end (see routine Analyze_Declarations).
25440 Set_Has_Visible_Refinement (State_Id);
25442 -- When the constituent is external, save its relevant
25443 -- property for further checks.
25445 if Async_Readers_Enabled (Constit_Id) then
25446 AR_Constit := Constit_Id;
25447 External_Constit_Seen := True;
25448 end if;
25450 if Async_Writers_Enabled (Constit_Id) then
25451 AW_Constit := Constit_Id;
25452 External_Constit_Seen := True;
25453 end if;
25455 if Effective_Reads_Enabled (Constit_Id) then
25456 ER_Constit := Constit_Id;
25457 External_Constit_Seen := True;
25458 end if;
25460 if Effective_Writes_Enabled (Constit_Id) then
25461 EW_Constit := Constit_Id;
25462 External_Constit_Seen := True;
25463 end if;
25464 end Collect_Constituent;
25466 -- Local variables
25468 State_Elmt : Elmt_Id;
25470 -- Start of processing for Match_Constituent
25472 begin
25473 -- Detect a duplicate use of a constituent
25475 if Contains (Constituents_Seen, Constit_Id) then
25476 SPARK_Msg_NE
25477 ("duplicate use of constituent &", Constit, Constit_Id);
25478 return;
25479 end if;
25481 -- The constituent is subject to a Part_Of indicator
25483 if Present (Encapsulating_State (Constit_Id)) then
25484 if Encapsulating_State (Constit_Id) = State_Id then
25485 Remove (Part_Of_Constits, Constit_Id);
25486 Collect_Constituent;
25488 -- The constituent is part of another state and is used
25489 -- incorrectly in the refinement of the current state.
25491 else
25492 Error_Msg_Name_1 := Chars (State_Id);
25493 SPARK_Msg_NE
25494 ("& cannot act as constituent of state %",
25495 Constit, Constit_Id);
25496 SPARK_Msg_NE
25497 ("\Part_Of indicator specifies encapsulator &",
25498 Constit, Encapsulating_State (Constit_Id));
25499 end if;
25501 -- The only other source of legal constituents is the body
25502 -- state space of the related package.
25504 else
25505 if Present (Body_States) then
25506 State_Elmt := First_Elmt (Body_States);
25507 while Present (State_Elmt) loop
25509 -- Consume a valid constituent to signal that it has
25510 -- been encountered.
25512 if Node (State_Elmt) = Constit_Id then
25513 Remove_Elmt (Body_States, State_Elmt);
25514 Collect_Constituent;
25515 return;
25516 end if;
25518 Next_Elmt (State_Elmt);
25519 end loop;
25520 end if;
25522 -- Constants are part of the hidden state of a package, but
25523 -- the compiler cannot determine whether they have variable
25524 -- input (SPARK RM 7.1.1(2)) and cannot classify them as a
25525 -- hidden state. Accept the constant quietly even if it is
25526 -- a visible state or lacks a Part_Of indicator.
25528 if Ekind (Constit_Id) = E_Constant then
25529 Collect_Constituent;
25531 -- If we get here, then the constituent is not a hidden
25532 -- state of the related package and may not be used in a
25533 -- refinement (SPARK RM 7.2.2(9)).
25535 else
25536 Error_Msg_Name_1 := Chars (Spec_Id);
25537 SPARK_Msg_NE
25538 ("cannot use & in refinement, constituent is not a "
25539 & "hidden state of package %", Constit, Constit_Id);
25540 end if;
25541 end if;
25542 end Match_Constituent;
25544 -- Local variables
25546 Constit_Id : Entity_Id;
25547 Constits : Elist_Id;
25549 -- Start of processing for Analyze_Constituent
25551 begin
25552 -- Detect multiple uses of null in a single refinement clause or a
25553 -- mixture of null and non-null constituents.
25555 if Nkind (Constit) = N_Null then
25556 if Null_Seen then
25557 SPARK_Msg_N
25558 ("multiple null constituents not allowed", Constit);
25560 elsif Non_Null_Seen then
25561 SPARK_Msg_N
25562 ("cannot mix null and non-null constituents", Constit);
25564 else
25565 Null_Seen := True;
25567 -- Collect the constituent in the list of refinement items
25569 Constits := Refinement_Constituents (State_Id);
25571 if No (Constits) then
25572 Constits := New_Elmt_List;
25573 Set_Refinement_Constituents (State_Id, Constits);
25574 end if;
25576 Append_Elmt (Constit, Constits);
25578 -- The state has at least one legal constituent, mark the
25579 -- start of the refinement region. The region ends when the
25580 -- body declarations end (see Analyze_Declarations).
25582 Set_Has_Visible_Refinement (State_Id);
25583 end if;
25585 -- Non-null constituents
25587 else
25588 Non_Null_Seen := True;
25590 if Null_Seen then
25591 SPARK_Msg_N
25592 ("cannot mix null and non-null constituents", Constit);
25593 end if;
25595 Analyze (Constit);
25596 Resolve_State (Constit);
25598 -- Ensure that the constituent denotes a valid state or a
25599 -- whole object (SPARK RM 7.2.2(5)).
25601 if Is_Entity_Name (Constit) then
25602 Constit_Id := Entity_Of (Constit);
25604 -- When a constituent is declared after a subprogram body
25605 -- that caused "freezing" of the related contract where
25606 -- pragma Refined_State resides, the constituent appears
25607 -- undefined and carries Any_Id as its entity.
25609 -- package body Pack
25610 -- with Refined_State => (State => Constit)
25611 -- is
25612 -- procedure Proc
25613 -- with Refined_Global => (Input => Constit)
25614 -- is
25615 -- ...
25616 -- end Proc;
25618 -- Constit : ...;
25619 -- end Pack;
25621 if Constit_Id = Any_Id then
25622 SPARK_Msg_NE ("& is undefined", Constit, Constit_Id);
25624 -- Emit a specialized info message when the contract of
25625 -- the related package body was "frozen" by another body.
25626 -- Note that it is not possible to precisely identify why
25627 -- the constituent is undefined because it is not visible
25628 -- when pragma Refined_State is analyzed. This message is
25629 -- a reasonable approximation.
25631 if Present (Freeze_Id) and then not Freeze_Posted then
25632 Freeze_Posted := True;
25634 Error_Msg_Name_1 := Chars (Body_Id);
25635 Error_Msg_Sloc := Sloc (Freeze_Id);
25636 SPARK_Msg_NE
25637 ("body & declared # freezes the contract of %",
25638 N, Freeze_Id);
25639 SPARK_Msg_N
25640 ("\all constituents must be declared before body #",
25643 -- A misplaced constituent is a critical error because
25644 -- pragma Refined_Depends or Refined_Global depends on
25645 -- the proper link between a state and a constituent.
25646 -- Stop the compilation, as this leads to a multitude
25647 -- of misleading cascaded errors.
25649 raise Program_Error;
25650 end if;
25652 -- The constituent is a valid state or object
25654 elsif Ekind_In (Constit_Id, E_Abstract_State,
25655 E_Constant,
25656 E_Variable)
25657 then
25658 Match_Constituent (Constit_Id);
25660 -- The variable may eventually become a constituent of a
25661 -- single protected/task type. Record the reference now
25662 -- and verify its legality when analyzing the contract of
25663 -- the variable (SPARK RM 9.3).
25665 if Ekind (Constit_Id) = E_Variable then
25666 Record_Possible_Part_Of_Reference
25667 (Var_Id => Constit_Id,
25668 Ref => Constit);
25669 end if;
25671 -- Otherwise the constituent is illegal
25673 else
25674 SPARK_Msg_NE
25675 ("constituent & must denote object or state",
25676 Constit, Constit_Id);
25677 end if;
25679 -- The constituent is illegal
25681 else
25682 SPARK_Msg_N ("malformed constituent", Constit);
25683 end if;
25684 end if;
25685 end Analyze_Constituent;
25687 -----------------------------
25688 -- Check_External_Property --
25689 -----------------------------
25691 procedure Check_External_Property
25692 (Prop_Nam : Name_Id;
25693 Enabled : Boolean;
25694 Constit : Entity_Id)
25696 begin
25697 -- The property is missing in the declaration of the state, but
25698 -- a constituent is introducing it in the state refinement
25699 -- (SPARK RM 7.2.8(2)).
25701 if not Enabled and then Present (Constit) then
25702 Error_Msg_Name_1 := Prop_Nam;
25703 Error_Msg_Name_2 := Chars (State_Id);
25704 SPARK_Msg_NE
25705 ("constituent & introduces external property % in refinement "
25706 & "of state %", State, Constit);
25708 Error_Msg_Sloc := Sloc (State_Id);
25709 SPARK_Msg_N
25710 ("\property is missing in abstract state declaration #",
25711 State);
25712 end if;
25713 end Check_External_Property;
25715 -----------------
25716 -- Match_State --
25717 -----------------
25719 procedure Match_State is
25720 State_Elmt : Elmt_Id;
25722 begin
25723 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
25725 if Contains (Refined_States_Seen, State_Id) then
25726 SPARK_Msg_NE
25727 ("duplicate refinement of state &", State, State_Id);
25728 return;
25729 end if;
25731 -- Inspect the abstract states defined in the package declaration
25732 -- looking for a match.
25734 State_Elmt := First_Elmt (Available_States);
25735 while Present (State_Elmt) loop
25737 -- A valid abstract state is being refined in the body. Add
25738 -- the state to the list of processed refined states to aid
25739 -- with the detection of duplicate refinements. Remove the
25740 -- state from Available_States to signal that it has already
25741 -- been refined.
25743 if Node (State_Elmt) = State_Id then
25744 Append_New_Elmt (State_Id, Refined_States_Seen);
25745 Remove_Elmt (Available_States, State_Elmt);
25746 return;
25747 end if;
25749 Next_Elmt (State_Elmt);
25750 end loop;
25752 -- If we get here, we are refining a state that is not defined in
25753 -- the package declaration.
25755 Error_Msg_Name_1 := Chars (Spec_Id);
25756 SPARK_Msg_NE
25757 ("cannot refine state, & is not defined in package %",
25758 State, State_Id);
25759 end Match_State;
25761 --------------------------------
25762 -- Report_Unused_Constituents --
25763 --------------------------------
25765 procedure Report_Unused_Constituents (Constits : Elist_Id) is
25766 Constit_Elmt : Elmt_Id;
25767 Constit_Id : Entity_Id;
25768 Posted : Boolean := False;
25770 begin
25771 if Present (Constits) then
25772 Constit_Elmt := First_Elmt (Constits);
25773 while Present (Constit_Elmt) loop
25774 Constit_Id := Node (Constit_Elmt);
25776 -- Generate an error message of the form:
25778 -- state ... has unused Part_Of constituents
25779 -- abstract state ... defined at ...
25780 -- constant ... defined at ...
25781 -- variable ... defined at ...
25783 if not Posted then
25784 Posted := True;
25785 SPARK_Msg_NE
25786 ("state & has unused Part_Of constituents",
25787 State, State_Id);
25788 end if;
25790 Error_Msg_Sloc := Sloc (Constit_Id);
25792 if Ekind (Constit_Id) = E_Abstract_State then
25793 SPARK_Msg_NE
25794 ("\abstract state & defined #", State, Constit_Id);
25796 elsif Ekind (Constit_Id) = E_Constant then
25797 SPARK_Msg_NE
25798 ("\constant & defined #", State, Constit_Id);
25800 else
25801 pragma Assert (Ekind (Constit_Id) = E_Variable);
25802 SPARK_Msg_NE ("\variable & defined #", State, Constit_Id);
25803 end if;
25805 Next_Elmt (Constit_Elmt);
25806 end loop;
25807 end if;
25808 end Report_Unused_Constituents;
25810 -- Local declarations
25812 Body_Ref : Node_Id;
25813 Body_Ref_Elmt : Elmt_Id;
25814 Constit : Node_Id;
25815 Extra_State : Node_Id;
25817 -- Start of processing for Analyze_Refinement_Clause
25819 begin
25820 -- A refinement clause appears as a component association where the
25821 -- sole choice is the state and the expressions are the constituents.
25822 -- This is a syntax error, always report.
25824 if Nkind (Clause) /= N_Component_Association then
25825 Error_Msg_N ("malformed state refinement clause", Clause);
25826 return;
25827 end if;
25829 -- Analyze the state name of a refinement clause
25831 State := First (Choices (Clause));
25833 Analyze (State);
25834 Resolve_State (State);
25836 -- Ensure that the state name denotes a valid abstract state that is
25837 -- defined in the spec of the related package.
25839 if Is_Entity_Name (State) then
25840 State_Id := Entity_Of (State);
25842 -- When the abstract state is undefined, it appears as Any_Id. Do
25843 -- not continue with the analysis of the clause.
25845 if State_Id = Any_Id then
25846 return;
25848 -- Catch any attempts to re-refine a state or refine a state that
25849 -- is not defined in the package declaration.
25851 elsif Ekind (State_Id) = E_Abstract_State then
25852 Match_State;
25854 else
25855 SPARK_Msg_NE ("& must denote abstract state", State, State_Id);
25856 return;
25857 end if;
25859 -- References to a state with visible refinement are illegal.
25860 -- When nested packages are involved, detecting such references is
25861 -- tricky because pragma Refined_State is analyzed later than the
25862 -- offending pragma Depends or Global. References that occur in
25863 -- such nested context are stored in a list. Emit errors for all
25864 -- references found in Body_References (SPARK RM 6.1.4(8)).
25866 if Present (Body_References (State_Id)) then
25867 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
25868 while Present (Body_Ref_Elmt) loop
25869 Body_Ref := Node (Body_Ref_Elmt);
25871 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
25872 Error_Msg_Sloc := Sloc (State);
25873 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
25875 Next_Elmt (Body_Ref_Elmt);
25876 end loop;
25877 end if;
25879 -- The state name is illegal. This is a syntax error, always report.
25881 else
25882 Error_Msg_N ("malformed state name in refinement clause", State);
25883 return;
25884 end if;
25886 -- A refinement clause may only refine one state at a time
25888 Extra_State := Next (State);
25890 if Present (Extra_State) then
25891 SPARK_Msg_N
25892 ("refinement clause cannot cover multiple states", Extra_State);
25893 end if;
25895 -- Replicate the Part_Of constituents of the refined state because
25896 -- the algorithm will consume items.
25898 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
25900 -- Analyze all constituents of the refinement. Multiple constituents
25901 -- appear as an aggregate.
25903 Constit := Expression (Clause);
25905 if Nkind (Constit) = N_Aggregate then
25906 if Present (Component_Associations (Constit)) then
25907 SPARK_Msg_N
25908 ("constituents of refinement clause must appear in "
25909 & "positional form", Constit);
25911 else pragma Assert (Present (Expressions (Constit)));
25912 Constit := First (Expressions (Constit));
25913 while Present (Constit) loop
25914 Analyze_Constituent (Constit);
25915 Next (Constit);
25916 end loop;
25917 end if;
25919 -- Various forms of a single constituent. Note that these may include
25920 -- malformed constituents.
25922 else
25923 Analyze_Constituent (Constit);
25924 end if;
25926 -- Verify that external constituents do not introduce new external
25927 -- property in the state refinement (SPARK RM 7.2.8(2)).
25929 if Is_External_State (State_Id) then
25930 Check_External_Property
25931 (Prop_Nam => Name_Async_Readers,
25932 Enabled => Async_Readers_Enabled (State_Id),
25933 Constit => AR_Constit);
25935 Check_External_Property
25936 (Prop_Nam => Name_Async_Writers,
25937 Enabled => Async_Writers_Enabled (State_Id),
25938 Constit => AW_Constit);
25940 Check_External_Property
25941 (Prop_Nam => Name_Effective_Reads,
25942 Enabled => Effective_Reads_Enabled (State_Id),
25943 Constit => ER_Constit);
25945 Check_External_Property
25946 (Prop_Nam => Name_Effective_Writes,
25947 Enabled => Effective_Writes_Enabled (State_Id),
25948 Constit => EW_Constit);
25950 -- When a refined state is not external, it should not have external
25951 -- constituents (SPARK RM 7.2.8(1)).
25953 elsif External_Constit_Seen then
25954 SPARK_Msg_NE
25955 ("non-external state & cannot contain external constituents in "
25956 & "refinement", State, State_Id);
25957 end if;
25959 -- Ensure that all Part_Of candidate constituents have been mentioned
25960 -- in the refinement clause.
25962 Report_Unused_Constituents (Part_Of_Constits);
25963 end Analyze_Refinement_Clause;
25965 -----------------------------
25966 -- Report_Unrefined_States --
25967 -----------------------------
25969 procedure Report_Unrefined_States (States : Elist_Id) is
25970 State_Elmt : Elmt_Id;
25972 begin
25973 if Present (States) then
25974 State_Elmt := First_Elmt (States);
25975 while Present (State_Elmt) loop
25976 SPARK_Msg_N
25977 ("abstract state & must be refined", Node (State_Elmt));
25979 Next_Elmt (State_Elmt);
25980 end loop;
25981 end if;
25982 end Report_Unrefined_States;
25984 -- Local declarations
25986 Clauses : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
25987 Clause : Node_Id;
25989 -- Start of processing for Analyze_Refined_State_In_Decl_Part
25991 begin
25992 -- Do not analyze the pragma multiple times
25994 if Is_Analyzed_Pragma (N) then
25995 return;
25996 end if;
25998 -- Replicate the abstract states declared by the package because the
25999 -- matching algorithm will consume states.
26001 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
26003 -- Gather all abstract states and objects declared in the visible
26004 -- state space of the package body. These items must be utilized as
26005 -- constituents in a state refinement.
26007 Body_States := Collect_Body_States (Body_Id);
26009 -- Multiple non-null state refinements appear as an aggregate
26011 if Nkind (Clauses) = N_Aggregate then
26012 if Present (Expressions (Clauses)) then
26013 SPARK_Msg_N
26014 ("state refinements must appear as component associations",
26015 Clauses);
26017 else pragma Assert (Present (Component_Associations (Clauses)));
26018 Clause := First (Component_Associations (Clauses));
26019 while Present (Clause) loop
26020 Analyze_Refinement_Clause (Clause);
26021 Next (Clause);
26022 end loop;
26023 end if;
26025 -- Various forms of a single state refinement. Note that these may
26026 -- include malformed refinements.
26028 else
26029 Analyze_Refinement_Clause (Clauses);
26030 end if;
26032 -- List all abstract states that were left unrefined
26034 Report_Unrefined_States (Available_States);
26036 Set_Is_Analyzed_Pragma (N);
26037 end Analyze_Refined_State_In_Decl_Part;
26039 ------------------------------------
26040 -- Analyze_Test_Case_In_Decl_Part --
26041 ------------------------------------
26043 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is
26044 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
26045 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
26047 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id);
26048 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
26049 -- denoted by Arg_Nam.
26051 ------------------------------
26052 -- Preanalyze_Test_Case_Arg --
26053 ------------------------------
26055 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id) is
26056 Arg : Node_Id;
26058 begin
26059 -- Preanalyze the original aspect argument for ASIS or for a generic
26060 -- subprogram to properly capture global references.
26062 if ASIS_Mode or else Is_Generic_Subprogram (Spec_Id) then
26063 Arg :=
26064 Test_Case_Arg
26065 (Prag => N,
26066 Arg_Nam => Arg_Nam,
26067 From_Aspect => True);
26069 if Present (Arg) then
26070 Preanalyze_Assert_Expression
26071 (Expression (Arg), Standard_Boolean);
26072 end if;
26073 end if;
26075 Arg := Test_Case_Arg (N, Arg_Nam);
26077 if Present (Arg) then
26078 Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean);
26079 end if;
26080 end Preanalyze_Test_Case_Arg;
26082 -- Local variables
26084 Restore_Scope : Boolean := False;
26086 -- Start of processing for Analyze_Test_Case_In_Decl_Part
26088 begin
26089 -- Do not analyze the pragma multiple times
26091 if Is_Analyzed_Pragma (N) then
26092 return;
26093 end if;
26095 -- Ensure that the formal parameters are visible when analyzing all
26096 -- clauses. This falls out of the general rule of aspects pertaining
26097 -- to subprogram declarations.
26099 if not In_Open_Scopes (Spec_Id) then
26100 Restore_Scope := True;
26101 Push_Scope (Spec_Id);
26103 if Is_Generic_Subprogram (Spec_Id) then
26104 Install_Generic_Formals (Spec_Id);
26105 else
26106 Install_Formals (Spec_Id);
26107 end if;
26108 end if;
26110 Preanalyze_Test_Case_Arg (Name_Requires);
26111 Preanalyze_Test_Case_Arg (Name_Ensures);
26113 if Restore_Scope then
26114 End_Scope;
26115 end if;
26117 -- Currently it is not possible to inline pre/postconditions on a
26118 -- subprogram subject to pragma Inline_Always.
26120 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
26122 Set_Is_Analyzed_Pragma (N);
26123 end Analyze_Test_Case_In_Decl_Part;
26125 ----------------
26126 -- Appears_In --
26127 ----------------
26129 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
26130 Elmt : Elmt_Id;
26131 Id : Entity_Id;
26133 begin
26134 if Present (List) then
26135 Elmt := First_Elmt (List);
26136 while Present (Elmt) loop
26137 if Nkind (Node (Elmt)) = N_Defining_Identifier then
26138 Id := Node (Elmt);
26139 else
26140 Id := Entity_Of (Node (Elmt));
26141 end if;
26143 if Id = Item_Id then
26144 return True;
26145 end if;
26147 Next_Elmt (Elmt);
26148 end loop;
26149 end if;
26151 return False;
26152 end Appears_In;
26154 -----------------------------------
26155 -- Build_Pragma_Check_Equivalent --
26156 -----------------------------------
26158 function Build_Pragma_Check_Equivalent
26159 (Prag : Node_Id;
26160 Subp_Id : Entity_Id := Empty;
26161 Inher_Id : Entity_Id := Empty) return Node_Id
26163 Map : Elist_Id;
26164 -- List containing the following mappings
26165 -- * Formal parameters of inherited subprogram Inher_Id and subprogram
26166 -- Subp_Id.
26168 -- * The dispatching type of Inher_Id and the dispatching type of
26169 -- Subp_Id.
26171 -- * Primitives of the dispatching type of Inher_Id and primitives of
26172 -- the dispatching type of Subp_Id.
26174 function Replace_Entity (N : Node_Id) return Traverse_Result;
26175 -- Replace reference to formal of inherited operation or to primitive
26176 -- operation of root type, with corresponding entity for derived type.
26178 function Suppress_Reference (N : Node_Id) return Traverse_Result;
26179 -- Detect whether node N references a formal parameter subject to
26180 -- pragma Unreferenced. If this is the case, set Comes_From_Source
26181 -- to False to suppress the generation of a reference when analyzing
26182 -- N later on.
26184 --------------------
26185 -- Replace_Entity --
26186 --------------------
26188 function Replace_Entity (N : Node_Id) return Traverse_Result is
26189 Elmt : Elmt_Id;
26190 New_E : Entity_Id;
26192 begin
26193 if Nkind (N) = N_Identifier
26194 and then Present (Entity (N))
26195 and then
26196 (Is_Formal (Entity (N)) or else Is_Subprogram (Entity (N)))
26197 and then
26198 (Nkind (Parent (N)) /= N_Attribute_Reference
26199 or else Attribute_Name (Parent (N)) /= Name_Class)
26200 then
26201 -- The replacement does not apply to dispatching calls within the
26202 -- condition, but only to calls whose static tag is that of the
26203 -- parent type.
26205 if Is_Subprogram (Entity (N))
26206 and then Nkind (Parent (N)) = N_Function_Call
26207 and then Present (Controlling_Argument (Parent (N)))
26208 then
26209 return OK;
26210 end if;
26212 -- Loop to find out if entity has a renaming
26214 New_E := Empty;
26215 Elmt := First_Elmt (Map);
26216 while Present (Elmt) loop
26217 if Node (Elmt) = Entity (N) then
26218 New_E := Node (Next_Elmt (Elmt));
26219 exit;
26220 end if;
26222 Next_Elmt (Elmt);
26223 end loop;
26225 if Present (New_E) then
26226 Rewrite (N, New_Occurrence_Of (New_E, Sloc (N)));
26227 end if;
26229 -- Check that there are no calls left to abstract operations
26230 -- if the current subprogram is not abstract.
26232 if Nkind (Parent (N)) = N_Function_Call
26233 and then N = Name (Parent (N))
26234 and then not Is_Abstract_Subprogram (Subp_Id)
26235 and then Is_Abstract_Subprogram (Entity (N))
26236 then
26237 Error_Msg_Sloc := Sloc (Current_Scope);
26238 Error_Msg_NE
26239 ("cannot call abstract subprogram in inherited condition "
26240 & "for&#", N, Current_Scope);
26241 end if;
26243 -- The whole expression will be reanalyzed
26245 elsif Nkind (N) in N_Has_Etype then
26246 Set_Analyzed (N, False);
26247 end if;
26249 return OK;
26250 end Replace_Entity;
26252 ------------------------
26253 -- Suppress_Reference --
26254 ------------------------
26256 function Suppress_Reference (N : Node_Id) return Traverse_Result is
26257 Formal : Entity_Id;
26259 begin
26260 if Is_Entity_Name (N) and then Present (Entity (N)) then
26261 Formal := Entity (N);
26263 -- The formal parameter is subject to pragma Unreferenced.
26264 -- Prevent the generation of a reference by resetting the
26265 -- Comes_From_Source flag.
26267 if Is_Formal (Formal)
26268 and then Has_Pragma_Unreferenced (Formal)
26269 then
26270 Set_Comes_From_Source (N, False);
26271 end if;
26272 end if;
26274 return OK;
26275 end Suppress_Reference;
26277 procedure Replace_Condition_Entities is
26278 new Traverse_Proc (Replace_Entity);
26280 procedure Suppress_References is
26281 new Traverse_Proc (Suppress_Reference);
26283 -- Local variables
26285 Loc : constant Source_Ptr := Sloc (Prag);
26286 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
26287 Check_Prag : Node_Id;
26288 Inher_Formal : Entity_Id;
26289 Msg_Arg : Node_Id;
26290 Nam : Name_Id;
26291 Subp_Formal : Entity_Id;
26293 -- Start of processing for Build_Pragma_Check_Equivalent
26295 begin
26296 Map := No_Elist;
26298 -- When the pre- or postcondition is inherited, map the formals of the
26299 -- inherited subprogram to those of the current subprogram. In addition,
26300 -- map primitive operations of the parent type into the corresponding
26301 -- primitive operations of the descendant.
26303 if Present (Inher_Id) then
26304 pragma Assert (Present (Subp_Id));
26306 Map := New_Elmt_List;
26308 -- Create a mapping <inherited formal> => <subprogram formal>
26310 Inher_Formal := First_Formal (Inher_Id);
26311 Subp_Formal := First_Formal (Subp_Id);
26312 while Present (Inher_Formal) and then Present (Subp_Formal) loop
26313 Append_Elmt (Inher_Formal, Map);
26314 Append_Elmt (Subp_Formal, Map);
26316 Next_Formal (Inher_Formal);
26317 Next_Formal (Subp_Formal);
26318 end loop;
26320 -- Map primitive operations of the parent type to the corresponding
26321 -- operations of the descendant. Note that the descendant type may
26322 -- not be frozen yet, so we cannot use the dispatch table directly.
26324 -- Note : the construction of the map involves a full traversal of
26325 -- the list of primitive operations, as well as a scan of the
26326 -- declarations in the scope of the operation. Given that class-wide
26327 -- conditions are typically short expressions, it might be much more
26328 -- efficient to collect the identifiers in the expression first, and
26329 -- then determine the ones that have to be mapped. Optimization ???
26331 Primitive_Mapping : declare
26332 function Overridden_Ancestor (S : Entity_Id) return Entity_Id;
26333 -- Given the controlling type of the overridden operation and a
26334 -- primitive of the current type, find the corresponding operation
26335 -- of the parent type.
26337 -------------------------
26338 -- Overridden_Ancestor --
26339 -------------------------
26341 function Overridden_Ancestor (S : Entity_Id) return Entity_Id is
26342 Anc : Entity_Id;
26344 begin
26345 Anc := S;
26346 while Present (Overridden_Operation (Anc)) loop
26347 exit when Scope (Anc) = Scope (Inher_Id);
26348 Anc := Overridden_Operation (Anc);
26349 end loop;
26351 return Anc;
26352 end Overridden_Ancestor;
26354 -- Local variables
26356 Old_Typ : constant Entity_Id := Find_Dispatching_Type (Inher_Id);
26357 Typ : constant Entity_Id := Find_Dispatching_Type (Subp_Id);
26358 Decl : Node_Id;
26359 Old_Elmt : Elmt_Id;
26360 Old_Prim : Entity_Id;
26361 Prim : Entity_Id;
26363 -- Start of processing for Primitive_Mapping
26365 begin
26366 Decl := First (List_Containing (Unit_Declaration_Node (Subp_Id)));
26368 -- Look for primitive operations of the current type that have
26369 -- overridden an operation of the type related to the original
26370 -- class-wide precondition. There may be several intermediate
26371 -- overridings between them.
26373 while Present (Decl) loop
26374 if Nkind (Decl) = N_Subprogram_Declaration then
26375 Prim := Defining_Entity (Decl);
26377 if Is_Subprogram (Prim)
26378 and then Present (Overridden_Operation (Prim))
26379 and then Find_Dispatching_Type (Prim) = Typ
26380 then
26381 Old_Prim := Overridden_Ancestor (Prim);
26383 Append_Elmt (Old_Prim, Map);
26384 Append_Elmt (Prim, Map);
26385 end if;
26386 end if;
26388 Next (Decl);
26389 end loop;
26391 -- Now examine inherited operations. These do not override, but
26392 -- have an alias, which is the entity used in a call. In turn
26393 -- that alias may be inherited or comes from source, in which
26394 -- case it may override an earlier operation. We only need to
26395 -- examine inherited functions, that may appear within the
26396 -- inherited expression.
26398 Prim := First_Entity (Scope (Subp_Id));
26399 while Present (Prim) loop
26400 if not Comes_From_Source (Prim)
26401 and then Ekind (Prim) = E_Function
26402 and then Present (Alias (Prim))
26403 then
26404 Old_Prim := Alias (Prim);
26406 if Comes_From_Source (Old_Prim) then
26407 Old_Prim := Overridden_Ancestor (Old_Prim);
26409 else
26410 while Present (Alias (Old_Prim))
26411 and then Scope (Old_Prim) /= Scope (Inher_Id)
26412 loop
26413 Old_Prim := Alias (Old_Prim);
26415 if Comes_From_Source (Old_Prim) then
26416 Old_Prim := Overridden_Ancestor (Old_Prim);
26417 exit;
26418 end if;
26419 end loop;
26420 end if;
26422 Append_Elmt (Old_Prim, Map);
26423 Append_Elmt (Prim, Map);
26424 end if;
26426 Next_Entity (Prim);
26427 end loop;
26429 -- If the parent operation is an interface operation, the
26430 -- overriding indicator is not present. Instead, we get from
26431 -- the interface operation the primitive of the current type
26432 -- that implements it.
26434 if Is_Interface (Old_Typ) then
26435 Old_Elmt := First_Elmt (Collect_Primitive_Operations (Old_Typ));
26436 while Present (Old_Elmt) loop
26437 Old_Prim := Node (Old_Elmt);
26438 Prim := Find_Primitive_Covering_Interface (Typ, Old_Prim);
26440 if Present (Prim) then
26441 Append_Elmt (Old_Prim, Map);
26442 Append_Elmt (Prim, Map);
26443 end if;
26445 Next_Elmt (Old_Elmt);
26446 end loop;
26447 end if;
26449 if Map /= No_Elist then
26450 Append_Elmt (Old_Typ, Map);
26451 Append_Elmt (Typ, Map);
26452 end if;
26453 end Primitive_Mapping;
26454 end if;
26456 -- Copy the original pragma while performing substitutions (if
26457 -- applicable).
26459 Check_Prag := New_Copy_Tree (Source => Prag);
26461 if Map /= No_Elist then
26462 Replace_Condition_Entities (Check_Prag);
26463 end if;
26465 -- Mark the pragma as being internally generated and reset the Analyzed
26466 -- flag.
26468 Set_Analyzed (Check_Prag, False);
26469 Set_Comes_From_Source (Check_Prag, False);
26470 Set_Class_Present (Check_Prag, False);
26472 -- The tree of the original pragma may contain references to the
26473 -- formal parameters of the related subprogram. At the same time
26474 -- the corresponding body may mark the formals as unreferenced:
26476 -- procedure Proc (Formal : ...)
26477 -- with Pre => Formal ...;
26479 -- procedure Proc (Formal : ...) is
26480 -- pragma Unreferenced (Formal);
26481 -- ...
26483 -- This creates problems because all pragma Check equivalents are
26484 -- analyzed at the end of the body declarations. Since all source
26485 -- references have already been accounted for, reset any references
26486 -- to such formals in the generated pragma Check equivalent.
26488 Suppress_References (Check_Prag);
26490 if Present (Corresponding_Aspect (Prag)) then
26491 Nam := Chars (Identifier (Corresponding_Aspect (Prag)));
26492 else
26493 Nam := Prag_Nam;
26494 end if;
26496 -- Convert the copy into pragma Check by correcting the name and adding
26497 -- a check_kind argument.
26499 Set_Pragma_Identifier
26500 (Check_Prag, Make_Identifier (Loc, Name_Check));
26502 Prepend_To (Pragma_Argument_Associations (Check_Prag),
26503 Make_Pragma_Argument_Association (Loc,
26504 Expression => Make_Identifier (Loc, Nam)));
26506 -- Update the error message when the pragma is inherited
26508 if Present (Inher_Id) then
26509 Msg_Arg := Last (Pragma_Argument_Associations (Check_Prag));
26511 if Chars (Msg_Arg) = Name_Message then
26512 String_To_Name_Buffer (Strval (Expression (Msg_Arg)));
26514 -- Insert "inherited" to improve the error message
26516 if Name_Buffer (1 .. 8) = "failed p" then
26517 Insert_Str_In_Name_Buffer ("inherited ", 8);
26518 Set_Strval (Expression (Msg_Arg), String_From_Name_Buffer);
26519 end if;
26520 end if;
26521 end if;
26523 return Check_Prag;
26524 end Build_Pragma_Check_Equivalent;
26526 -----------------------------
26527 -- Check_Applicable_Policy --
26528 -----------------------------
26530 procedure Check_Applicable_Policy (N : Node_Id) is
26531 PP : Node_Id;
26532 Policy : Name_Id;
26534 Ename : constant Name_Id := Original_Aspect_Pragma_Name (N);
26536 begin
26537 -- No effect if not valid assertion kind name
26539 if not Is_Valid_Assertion_Kind (Ename) then
26540 return;
26541 end if;
26543 -- Loop through entries in check policy list
26545 PP := Opt.Check_Policy_List;
26546 while Present (PP) loop
26547 declare
26548 PPA : constant List_Id := Pragma_Argument_Associations (PP);
26549 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
26551 begin
26552 if Ename = Pnm
26553 or else Pnm = Name_Assertion
26554 or else (Pnm = Name_Statement_Assertions
26555 and then Nam_In (Ename, Name_Assert,
26556 Name_Assert_And_Cut,
26557 Name_Assume,
26558 Name_Loop_Invariant,
26559 Name_Loop_Variant))
26560 then
26561 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
26563 case Policy is
26564 when Name_Off | Name_Ignore =>
26565 Set_Is_Ignored (N, True);
26566 Set_Is_Checked (N, False);
26568 when Name_On | Name_Check =>
26569 Set_Is_Checked (N, True);
26570 Set_Is_Ignored (N, False);
26572 when Name_Disable =>
26573 Set_Is_Ignored (N, True);
26574 Set_Is_Checked (N, False);
26575 Set_Is_Disabled (N, True);
26577 -- That should be exhaustive, the null here is a defence
26578 -- against a malformed tree from previous errors.
26580 when others =>
26581 null;
26582 end case;
26584 return;
26585 end if;
26587 PP := Next_Pragma (PP);
26588 end;
26589 end loop;
26591 -- If there are no specific entries that matched, then we let the
26592 -- setting of assertions govern. Note that this provides the needed
26593 -- compatibility with the RM for the cases of assertion, invariant,
26594 -- precondition, predicate, and postcondition.
26596 if Assertions_Enabled then
26597 Set_Is_Checked (N, True);
26598 Set_Is_Ignored (N, False);
26599 else
26600 Set_Is_Checked (N, False);
26601 Set_Is_Ignored (N, True);
26602 end if;
26603 end Check_Applicable_Policy;
26605 -------------------------------
26606 -- Check_External_Properties --
26607 -------------------------------
26609 procedure Check_External_Properties
26610 (Item : Node_Id;
26611 AR : Boolean;
26612 AW : Boolean;
26613 ER : Boolean;
26614 EW : Boolean)
26616 begin
26617 -- All properties enabled
26619 if AR and AW and ER and EW then
26620 null;
26622 -- Async_Readers + Effective_Writes
26623 -- Async_Readers + Async_Writers + Effective_Writes
26625 elsif AR and EW and not ER then
26626 null;
26628 -- Async_Writers + Effective_Reads
26629 -- Async_Readers + Async_Writers + Effective_Reads
26631 elsif AW and ER and not EW then
26632 null;
26634 -- Async_Readers + Async_Writers
26636 elsif AR and AW and not ER and not EW then
26637 null;
26639 -- Async_Readers
26641 elsif AR and not AW and not ER and not EW then
26642 null;
26644 -- Async_Writers
26646 elsif AW and not AR and not ER and not EW then
26647 null;
26649 else
26650 SPARK_Msg_N
26651 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
26652 Item);
26653 end if;
26654 end Check_External_Properties;
26656 ----------------
26657 -- Check_Kind --
26658 ----------------
26660 function Check_Kind (Nam : Name_Id) return Name_Id is
26661 PP : Node_Id;
26663 begin
26664 -- Loop through entries in check policy list
26666 PP := Opt.Check_Policy_List;
26667 while Present (PP) loop
26668 declare
26669 PPA : constant List_Id := Pragma_Argument_Associations (PP);
26670 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
26672 begin
26673 if Nam = Pnm
26674 or else (Pnm = Name_Assertion
26675 and then Is_Valid_Assertion_Kind (Nam))
26676 or else (Pnm = Name_Statement_Assertions
26677 and then Nam_In (Nam, Name_Assert,
26678 Name_Assert_And_Cut,
26679 Name_Assume,
26680 Name_Loop_Invariant,
26681 Name_Loop_Variant))
26682 then
26683 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
26684 when Name_On | Name_Check =>
26685 return Name_Check;
26686 when Name_Off | Name_Ignore =>
26687 return Name_Ignore;
26688 when Name_Disable =>
26689 return Name_Disable;
26690 when others =>
26691 raise Program_Error;
26692 end case;
26694 else
26695 PP := Next_Pragma (PP);
26696 end if;
26697 end;
26698 end loop;
26700 -- If there are no specific entries that matched, then we let the
26701 -- setting of assertions govern. Note that this provides the needed
26702 -- compatibility with the RM for the cases of assertion, invariant,
26703 -- precondition, predicate, and postcondition.
26705 if Assertions_Enabled then
26706 return Name_Check;
26707 else
26708 return Name_Ignore;
26709 end if;
26710 end Check_Kind;
26712 ---------------------------
26713 -- Check_Missing_Part_Of --
26714 ---------------------------
26716 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
26717 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
26718 -- Determine whether a package denoted by Pack_Id declares at least one
26719 -- visible state.
26721 -----------------------
26722 -- Has_Visible_State --
26723 -----------------------
26725 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
26726 Item_Id : Entity_Id;
26728 begin
26729 -- Traverse the entity chain of the package trying to find at least
26730 -- one visible abstract state, variable or a package [instantiation]
26731 -- that declares a visible state.
26733 Item_Id := First_Entity (Pack_Id);
26734 while Present (Item_Id)
26735 and then not In_Private_Part (Item_Id)
26736 loop
26737 -- Do not consider internally generated items
26739 if not Comes_From_Source (Item_Id) then
26740 null;
26742 -- A visible state has been found
26744 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
26745 return True;
26747 -- Recursively peek into nested packages and instantiations
26749 elsif Ekind (Item_Id) = E_Package
26750 and then Has_Visible_State (Item_Id)
26751 then
26752 return True;
26753 end if;
26755 Next_Entity (Item_Id);
26756 end loop;
26758 return False;
26759 end Has_Visible_State;
26761 -- Local variables
26763 Pack_Id : Entity_Id;
26764 Placement : State_Space_Kind;
26766 -- Start of processing for Check_Missing_Part_Of
26768 begin
26769 -- Do not consider abstract states, variables or package instantiations
26770 -- coming from an instance as those always inherit the Part_Of indicator
26771 -- of the instance itself.
26773 if In_Instance then
26774 return;
26776 -- Do not consider internally generated entities as these can never
26777 -- have a Part_Of indicator.
26779 elsif not Comes_From_Source (Item_Id) then
26780 return;
26782 -- Perform these checks only when SPARK_Mode is enabled as they will
26783 -- interfere with standard Ada rules and produce false positives.
26785 elsif SPARK_Mode /= On then
26786 return;
26788 -- Do not consider constants, because the compiler cannot accurately
26789 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
26790 -- act as a hidden state of a package.
26792 elsif Ekind (Item_Id) = E_Constant then
26793 return;
26794 end if;
26796 -- Find where the abstract state, variable or package instantiation
26797 -- lives with respect to the state space.
26799 Find_Placement_In_State_Space
26800 (Item_Id => Item_Id,
26801 Placement => Placement,
26802 Pack_Id => Pack_Id);
26804 -- Items that appear in a non-package construct (subprogram, block, etc)
26805 -- do not require a Part_Of indicator because they can never act as a
26806 -- hidden state.
26808 if Placement = Not_In_Package then
26809 null;
26811 -- An item declared in the body state space of a package always act as a
26812 -- constituent and does not need explicit Part_Of indicator.
26814 elsif Placement = Body_State_Space then
26815 null;
26817 -- In general an item declared in the visible state space of a package
26818 -- does not require a Part_Of indicator. The only exception is when the
26819 -- related package is a private child unit in which case Part_Of must
26820 -- denote a state in the parent unit or in one of its descendants.
26822 elsif Placement = Visible_State_Space then
26823 if Is_Child_Unit (Pack_Id)
26824 and then Is_Private_Descendant (Pack_Id)
26825 then
26826 -- A package instantiation does not need a Part_Of indicator when
26827 -- the related generic template has no visible state.
26829 if Ekind (Item_Id) = E_Package
26830 and then Is_Generic_Instance (Item_Id)
26831 and then not Has_Visible_State (Item_Id)
26832 then
26833 null;
26835 -- All other cases require Part_Of
26837 else
26838 Error_Msg_N
26839 ("indicator Part_Of is required in this context "
26840 & "(SPARK RM 7.2.6(3))", Item_Id);
26841 Error_Msg_Name_1 := Chars (Pack_Id);
26842 Error_Msg_N
26843 ("\& is declared in the visible part of private child "
26844 & "unit %", Item_Id);
26845 end if;
26846 end if;
26848 -- When the item appears in the private state space of a packge, it must
26849 -- be a part of some state declared by the said package.
26851 else pragma Assert (Placement = Private_State_Space);
26853 -- The related package does not declare a state, the item cannot act
26854 -- as a Part_Of constituent.
26856 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
26857 null;
26859 -- A package instantiation does not need a Part_Of indicator when the
26860 -- related generic template has no visible state.
26862 elsif Ekind (Pack_Id) = E_Package
26863 and then Is_Generic_Instance (Pack_Id)
26864 and then not Has_Visible_State (Pack_Id)
26865 then
26866 null;
26868 -- All other cases require Part_Of
26870 else
26871 Error_Msg_N
26872 ("indicator Part_Of is required in this context "
26873 & "(SPARK RM 7.2.6(2))", Item_Id);
26874 Error_Msg_Name_1 := Chars (Pack_Id);
26875 Error_Msg_N
26876 ("\& is declared in the private part of package %", Item_Id);
26877 end if;
26878 end if;
26879 end Check_Missing_Part_Of;
26881 ---------------------------------------------------
26882 -- Check_Postcondition_Use_In_Inlined_Subprogram --
26883 ---------------------------------------------------
26885 procedure Check_Postcondition_Use_In_Inlined_Subprogram
26886 (Prag : Node_Id;
26887 Spec_Id : Entity_Id)
26889 begin
26890 if Warn_On_Redundant_Constructs
26891 and then Has_Pragma_Inline_Always (Spec_Id)
26892 then
26893 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
26895 if From_Aspect_Specification (Prag) then
26896 Error_Msg_NE
26897 ("aspect % not enforced on inlined subprogram &?r?",
26898 Corresponding_Aspect (Prag), Spec_Id);
26899 else
26900 Error_Msg_NE
26901 ("pragma % not enforced on inlined subprogram &?r?",
26902 Prag, Spec_Id);
26903 end if;
26904 end if;
26905 end Check_Postcondition_Use_In_Inlined_Subprogram;
26907 -------------------------------------
26908 -- Check_State_And_Constituent_Use --
26909 -------------------------------------
26911 procedure Check_State_And_Constituent_Use
26912 (States : Elist_Id;
26913 Constits : Elist_Id;
26914 Context : Node_Id)
26916 function Find_Encapsulating_State
26917 (Constit_Id : Entity_Id) return Entity_Id;
26918 -- Given the entity of a constituent, try to find a corresponding
26919 -- encapsulating state that appears in the same context. The routine
26920 -- returns Empty is no such state is found.
26922 ------------------------------
26923 -- Find_Encapsulating_State --
26924 ------------------------------
26926 function Find_Encapsulating_State
26927 (Constit_Id : Entity_Id) return Entity_Id
26929 State_Id : Entity_Id;
26931 begin
26932 -- Since a constituent may be part of a larger constituent set, climb
26933 -- the encapsulating state chain looking for a state that appears in
26934 -- the same context.
26936 State_Id := Encapsulating_State (Constit_Id);
26937 while Present (State_Id) loop
26938 if Contains (States, State_Id) then
26939 return State_Id;
26940 end if;
26942 State_Id := Encapsulating_State (State_Id);
26943 end loop;
26945 return Empty;
26946 end Find_Encapsulating_State;
26948 -- Local variables
26950 Constit_Elmt : Elmt_Id;
26951 Constit_Id : Entity_Id;
26952 State_Id : Entity_Id;
26954 -- Start of processing for Check_State_And_Constituent_Use
26956 begin
26957 -- Nothing to do if there are no states or constituents
26959 if No (States) or else No (Constits) then
26960 return;
26961 end if;
26963 -- Inspect the list of constituents and try to determine whether its
26964 -- encapsulating state is in list States.
26966 Constit_Elmt := First_Elmt (Constits);
26967 while Present (Constit_Elmt) loop
26968 Constit_Id := Node (Constit_Elmt);
26970 -- Determine whether the constituent is part of an encapsulating
26971 -- state that appears in the same context and if this is the case,
26972 -- emit an error (SPARK RM 7.2.6(7)).
26974 State_Id := Find_Encapsulating_State (Constit_Id);
26976 if Present (State_Id) then
26977 Error_Msg_Name_1 := Chars (Constit_Id);
26978 SPARK_Msg_NE
26979 ("cannot mention state & and its constituent % in the same "
26980 & "context", Context, State_Id);
26981 exit;
26982 end if;
26984 Next_Elmt (Constit_Elmt);
26985 end loop;
26986 end Check_State_And_Constituent_Use;
26988 ---------------------------------------------
26989 -- Collect_Inherited_Class_Wide_Conditions --
26990 ---------------------------------------------
26992 procedure Collect_Inherited_Class_Wide_Conditions (Subp : Entity_Id) is
26993 Parent_Subp : constant Entity_Id := Overridden_Operation (Subp);
26994 Prags : constant Node_Id := Contract (Parent_Subp);
26995 In_Spec_Expr : Boolean;
26996 Installed : Boolean;
26997 Prag : Node_Id;
26998 New_Prag : Node_Id;
27000 begin
27001 Installed := False;
27003 -- Iterate over the contract of the overridden subprogram to find all
27004 -- inherited class-wide pre- and postconditions.
27006 if Present (Prags) then
27007 Prag := Pre_Post_Conditions (Prags);
27009 while Present (Prag) loop
27010 if Nam_In (Pragma_Name (Prag), Name_Precondition,
27011 Name_Postcondition)
27012 and then Class_Present (Prag)
27013 then
27014 -- The generated pragma must be analyzed in the context of
27015 -- the subprogram, to make its formals visible. In addition,
27016 -- we must inhibit freezing and full analysis because the
27017 -- controlling type of the subprogram is not frozen yet, and
27018 -- may have further primitives.
27020 if not Installed then
27021 Installed := True;
27022 Push_Scope (Subp);
27023 Install_Formals (Subp);
27024 In_Spec_Expr := In_Spec_Expression;
27025 In_Spec_Expression := True;
27026 end if;
27028 New_Prag :=
27029 Build_Pragma_Check_Equivalent (Prag, Subp, Parent_Subp);
27030 Insert_After (Unit_Declaration_Node (Subp), New_Prag);
27031 Preanalyze (New_Prag);
27033 -- Prevent further analysis in subsequent processing of the
27034 -- current list of declarations
27036 Set_Analyzed (New_Prag);
27037 end if;
27039 Prag := Next_Pragma (Prag);
27040 end loop;
27042 if Installed then
27043 In_Spec_Expression := In_Spec_Expr;
27044 End_Scope;
27045 end if;
27046 end if;
27047 end Collect_Inherited_Class_Wide_Conditions;
27049 ---------------------------------------
27050 -- Collect_Subprogram_Inputs_Outputs --
27051 ---------------------------------------
27053 procedure Collect_Subprogram_Inputs_Outputs
27054 (Subp_Id : Entity_Id;
27055 Synthesize : Boolean := False;
27056 Subp_Inputs : in out Elist_Id;
27057 Subp_Outputs : in out Elist_Id;
27058 Global_Seen : out Boolean)
27060 procedure Collect_Dependency_Clause (Clause : Node_Id);
27061 -- Collect all relevant items from a dependency clause
27063 procedure Collect_Global_List
27064 (List : Node_Id;
27065 Mode : Name_Id := Name_Input);
27066 -- Collect all relevant items from a global list
27068 -------------------------------
27069 -- Collect_Dependency_Clause --
27070 -------------------------------
27072 procedure Collect_Dependency_Clause (Clause : Node_Id) is
27073 procedure Collect_Dependency_Item
27074 (Item : Node_Id;
27075 Is_Input : Boolean);
27076 -- Add an item to the proper subprogram input or output collection
27078 -----------------------------
27079 -- Collect_Dependency_Item --
27080 -----------------------------
27082 procedure Collect_Dependency_Item
27083 (Item : Node_Id;
27084 Is_Input : Boolean)
27086 Extra : Node_Id;
27088 begin
27089 -- Nothing to collect when the item is null
27091 if Nkind (Item) = N_Null then
27092 null;
27094 -- Ditto for attribute 'Result
27096 elsif Is_Attribute_Result (Item) then
27097 null;
27099 -- Multiple items appear as an aggregate
27101 elsif Nkind (Item) = N_Aggregate then
27102 Extra := First (Expressions (Item));
27103 while Present (Extra) loop
27104 Collect_Dependency_Item (Extra, Is_Input);
27105 Next (Extra);
27106 end loop;
27108 -- Otherwise this is a solitary item
27110 else
27111 if Is_Input then
27112 Append_New_Elmt (Item, Subp_Inputs);
27113 else
27114 Append_New_Elmt (Item, Subp_Outputs);
27115 end if;
27116 end if;
27117 end Collect_Dependency_Item;
27119 -- Start of processing for Collect_Dependency_Clause
27121 begin
27122 if Nkind (Clause) = N_Null then
27123 null;
27125 -- A dependency cause appears as component association
27127 elsif Nkind (Clause) = N_Component_Association then
27128 Collect_Dependency_Item
27129 (Item => Expression (Clause),
27130 Is_Input => True);
27132 Collect_Dependency_Item
27133 (Item => First (Choices (Clause)),
27134 Is_Input => False);
27136 -- To accomodate partial decoration of disabled SPARK features, this
27137 -- routine may be called with illegal input. If this is the case, do
27138 -- not raise Program_Error.
27140 else
27141 null;
27142 end if;
27143 end Collect_Dependency_Clause;
27145 -------------------------
27146 -- Collect_Global_List --
27147 -------------------------
27149 procedure Collect_Global_List
27150 (List : Node_Id;
27151 Mode : Name_Id := Name_Input)
27153 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
27154 -- Add an item to the proper subprogram input or output collection
27156 -------------------------
27157 -- Collect_Global_Item --
27158 -------------------------
27160 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
27161 begin
27162 if Nam_In (Mode, Name_In_Out, Name_Input) then
27163 Append_New_Elmt (Item, Subp_Inputs);
27164 end if;
27166 if Nam_In (Mode, Name_In_Out, Name_Output) then
27167 Append_New_Elmt (Item, Subp_Outputs);
27168 end if;
27169 end Collect_Global_Item;
27171 -- Local variables
27173 Assoc : Node_Id;
27174 Item : Node_Id;
27176 -- Start of processing for Collect_Global_List
27178 begin
27179 if Nkind (List) = N_Null then
27180 null;
27182 -- Single global item declaration
27184 elsif Nkind_In (List, N_Expanded_Name,
27185 N_Identifier,
27186 N_Selected_Component)
27187 then
27188 Collect_Global_Item (List, Mode);
27190 -- Simple global list or moded global list declaration
27192 elsif Nkind (List) = N_Aggregate then
27193 if Present (Expressions (List)) then
27194 Item := First (Expressions (List));
27195 while Present (Item) loop
27196 Collect_Global_Item (Item, Mode);
27197 Next (Item);
27198 end loop;
27200 else
27201 Assoc := First (Component_Associations (List));
27202 while Present (Assoc) loop
27203 Collect_Global_List
27204 (List => Expression (Assoc),
27205 Mode => Chars (First (Choices (Assoc))));
27206 Next (Assoc);
27207 end loop;
27208 end if;
27210 -- To accomodate partial decoration of disabled SPARK features, this
27211 -- routine may be called with illegal input. If this is the case, do
27212 -- not raise Program_Error.
27214 else
27215 null;
27216 end if;
27217 end Collect_Global_List;
27219 -- Local variables
27221 Clause : Node_Id;
27222 Clauses : Node_Id;
27223 Depends : Node_Id;
27224 Formal : Entity_Id;
27225 Global : Node_Id;
27226 Spec_Id : Entity_Id;
27227 Subp_Decl : Node_Id;
27228 Typ : Entity_Id;
27230 -- Start of processing for Collect_Subprogram_Inputs_Outputs
27232 begin
27233 Global_Seen := False;
27235 -- Process all formal parameters of entries, [generic] subprograms, and
27236 -- their bodies.
27238 if Ekind_In (Subp_Id, E_Entry,
27239 E_Entry_Family,
27240 E_Function,
27241 E_Generic_Function,
27242 E_Generic_Procedure,
27243 E_Procedure,
27244 E_Subprogram_Body)
27245 then
27246 Subp_Decl := Unit_Declaration_Node (Subp_Id);
27247 Spec_Id := Unique_Defining_Entity (Subp_Decl);
27249 -- Process all [generic] formal parameters
27251 Formal := First_Entity (Spec_Id);
27252 while Present (Formal) loop
27253 if Ekind_In (Formal, E_Generic_In_Parameter,
27254 E_In_Out_Parameter,
27255 E_In_Parameter)
27256 then
27257 Append_New_Elmt (Formal, Subp_Inputs);
27258 end if;
27260 if Ekind_In (Formal, E_Generic_In_Out_Parameter,
27261 E_In_Out_Parameter,
27262 E_Out_Parameter)
27263 then
27264 Append_New_Elmt (Formal, Subp_Outputs);
27266 -- Out parameters can act as inputs when the related type is
27267 -- tagged, unconstrained array, unconstrained record, or record
27268 -- with unconstrained components.
27270 if Ekind (Formal) = E_Out_Parameter
27271 and then Is_Unconstrained_Or_Tagged_Item (Formal)
27272 then
27273 Append_New_Elmt (Formal, Subp_Inputs);
27274 end if;
27275 end if;
27277 Next_Entity (Formal);
27278 end loop;
27280 -- Otherwise the input denotes a task type, a task body, or the
27281 -- anonymous object created for a single task type.
27283 elsif Ekind_In (Subp_Id, E_Task_Type, E_Task_Body)
27284 or else Is_Single_Task_Object (Subp_Id)
27285 then
27286 Subp_Decl := Declaration_Node (Subp_Id);
27287 Spec_Id := Unique_Defining_Entity (Subp_Decl);
27288 end if;
27290 -- When processing an entry, subprogram or task body, look for pragmas
27291 -- Refined_Depends and Refined_Global as they specify the inputs and
27292 -- outputs.
27294 if Is_Entry_Body (Subp_Id)
27295 or else Ekind_In (Subp_Id, E_Subprogram_Body, E_Task_Body)
27296 then
27297 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
27298 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
27300 -- Subprogram declaration or stand alone body case, look for pragmas
27301 -- Depends and Global
27303 else
27304 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
27305 Global := Get_Pragma (Spec_Id, Pragma_Global);
27306 end if;
27308 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
27309 -- because it provides finer granularity of inputs and outputs.
27311 if Present (Global) then
27312 Global_Seen := True;
27313 Collect_Global_List (Expression (Get_Argument (Global, Spec_Id)));
27315 -- When the related subprogram lacks pragma [Refined_]Global, fall back
27316 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
27317 -- the inputs and outputs from [Refined_]Depends.
27319 elsif Synthesize and then Present (Depends) then
27320 Clauses := Expression (Get_Argument (Depends, Spec_Id));
27322 -- Multiple dependency clauses appear as an aggregate
27324 if Nkind (Clauses) = N_Aggregate then
27325 Clause := First (Component_Associations (Clauses));
27326 while Present (Clause) loop
27327 Collect_Dependency_Clause (Clause);
27328 Next (Clause);
27329 end loop;
27331 -- Otherwise this is a single dependency clause
27333 else
27334 Collect_Dependency_Clause (Clauses);
27335 end if;
27336 end if;
27338 -- The current instance of a protected type acts as a formal parameter
27339 -- of mode IN for functions and IN OUT for entries and procedures
27340 -- (SPARK RM 6.1.4).
27342 if Ekind (Scope (Spec_Id)) = E_Protected_Type then
27343 Typ := Scope (Spec_Id);
27345 -- Use the anonymous object when the type is single protected
27347 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
27348 Typ := Anonymous_Object (Typ);
27349 end if;
27351 Append_New_Elmt (Typ, Subp_Inputs);
27353 if Ekind_In (Spec_Id, E_Entry, E_Entry_Family, E_Procedure) then
27354 Append_New_Elmt (Typ, Subp_Outputs);
27355 end if;
27357 -- The current instance of a task type acts as a formal parameter of
27358 -- mode IN OUT (SPARK RM 6.1.4).
27360 elsif Ekind (Spec_Id) = E_Task_Type then
27361 Typ := Spec_Id;
27363 -- Use the anonymous object when the type is single task
27365 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
27366 Typ := Anonymous_Object (Typ);
27367 end if;
27369 Append_New_Elmt (Typ, Subp_Inputs);
27370 Append_New_Elmt (Typ, Subp_Outputs);
27372 elsif Is_Single_Task_Object (Spec_Id) then
27373 Append_New_Elmt (Spec_Id, Subp_Inputs);
27374 Append_New_Elmt (Spec_Id, Subp_Outputs);
27375 end if;
27376 end Collect_Subprogram_Inputs_Outputs;
27378 ---------------------------
27379 -- Contract_Freeze_Error --
27380 ---------------------------
27382 procedure Contract_Freeze_Error
27383 (Contract_Id : Entity_Id;
27384 Freeze_Id : Entity_Id)
27386 begin
27387 Error_Msg_Name_1 := Chars (Contract_Id);
27388 Error_Msg_Sloc := Sloc (Freeze_Id);
27390 SPARK_Msg_NE
27391 ("body & declared # freezes the contract of%", Contract_Id, Freeze_Id);
27392 SPARK_Msg_N
27393 ("\all contractual items must be declared before body #", Contract_Id);
27394 end Contract_Freeze_Error;
27396 ---------------------------------
27397 -- Delay_Config_Pragma_Analyze --
27398 ---------------------------------
27400 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
27401 begin
27402 return Nam_In (Pragma_Name (N), Name_Interrupt_State,
27403 Name_Priority_Specific_Dispatching);
27404 end Delay_Config_Pragma_Analyze;
27406 -----------------------
27407 -- Duplication_Error --
27408 -----------------------
27410 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is
27411 Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag);
27412 Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev);
27414 begin
27415 Error_Msg_Sloc := Sloc (Prev);
27416 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
27418 -- Emit a precise message to distinguish between source pragmas and
27419 -- pragmas generated from aspects. The ordering of the two pragmas is
27420 -- the following:
27422 -- Prev -- ok
27423 -- Prag -- duplicate
27425 -- No error is emitted when both pragmas come from aspects because this
27426 -- is already detected by the general aspect analysis mechanism.
27428 if Prag_From_Asp and Prev_From_Asp then
27429 null;
27430 elsif Prag_From_Asp then
27431 Error_Msg_N ("aspect % duplicates pragma declared #", Prag);
27432 elsif Prev_From_Asp then
27433 Error_Msg_N ("pragma % duplicates aspect declared #", Prag);
27434 else
27435 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
27436 end if;
27437 end Duplication_Error;
27439 --------------------------
27440 -- Find_Related_Context --
27441 --------------------------
27443 function Find_Related_Context
27444 (Prag : Node_Id;
27445 Do_Checks : Boolean := False) return Node_Id
27447 Stmt : Node_Id;
27449 begin
27450 Stmt := Prev (Prag);
27451 while Present (Stmt) loop
27453 -- Skip prior pragmas, but check for duplicates
27455 if Nkind (Stmt) = N_Pragma then
27456 if Do_Checks and then Pragma_Name (Stmt) = Pragma_Name (Prag) then
27457 Duplication_Error
27458 (Prag => Prag,
27459 Prev => Stmt);
27460 end if;
27462 -- Skip internally generated code
27464 elsif not Comes_From_Source (Stmt) then
27466 -- The anonymous object created for a single concurrent type is a
27467 -- suitable context.
27469 if Nkind (Stmt) = N_Object_Declaration
27470 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
27471 then
27472 return Stmt;
27473 end if;
27475 -- Return the current source construct
27477 else
27478 return Stmt;
27479 end if;
27481 Prev (Stmt);
27482 end loop;
27484 return Empty;
27485 end Find_Related_Context;
27487 --------------------------------------
27488 -- Find_Related_Declaration_Or_Body --
27489 --------------------------------------
27491 function Find_Related_Declaration_Or_Body
27492 (Prag : Node_Id;
27493 Do_Checks : Boolean := False) return Node_Id
27495 Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
27497 procedure Expression_Function_Error;
27498 -- Emit an error concerning pragma Prag that illegaly applies to an
27499 -- expression function.
27501 -------------------------------
27502 -- Expression_Function_Error --
27503 -------------------------------
27505 procedure Expression_Function_Error is
27506 begin
27507 Error_Msg_Name_1 := Prag_Nam;
27509 -- Emit a precise message to distinguish between source pragmas and
27510 -- pragmas generated from aspects.
27512 if From_Aspect_Specification (Prag) then
27513 Error_Msg_N
27514 ("aspect % cannot apply to a stand alone expression function",
27515 Prag);
27516 else
27517 Error_Msg_N
27518 ("pragma % cannot apply to a stand alone expression function",
27519 Prag);
27520 end if;
27521 end Expression_Function_Error;
27523 -- Local variables
27525 Context : constant Node_Id := Parent (Prag);
27526 Stmt : Node_Id;
27528 Look_For_Body : constant Boolean :=
27529 Nam_In (Prag_Nam, Name_Refined_Depends,
27530 Name_Refined_Global,
27531 Name_Refined_Post);
27532 -- Refinement pragmas must be associated with a subprogram body [stub]
27534 -- Start of processing for Find_Related_Declaration_Or_Body
27536 begin
27537 Stmt := Prev (Prag);
27538 while Present (Stmt) loop
27540 -- Skip prior pragmas, but check for duplicates. Pragmas produced
27541 -- by splitting a complex pre/postcondition are not considered to
27542 -- be duplicates.
27544 if Nkind (Stmt) = N_Pragma then
27545 if Do_Checks
27546 and then not Split_PPC (Stmt)
27547 and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam
27548 then
27549 Duplication_Error
27550 (Prag => Prag,
27551 Prev => Stmt);
27552 end if;
27554 -- Emit an error when a refinement pragma appears on an expression
27555 -- function without a completion.
27557 elsif Do_Checks
27558 and then Look_For_Body
27559 and then Nkind (Stmt) = N_Subprogram_Declaration
27560 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
27561 and then not Has_Completion (Defining_Entity (Stmt))
27562 then
27563 Expression_Function_Error;
27564 return Empty;
27566 -- The refinement pragma applies to a subprogram body stub
27568 elsif Look_For_Body
27569 and then Nkind (Stmt) = N_Subprogram_Body_Stub
27570 then
27571 return Stmt;
27573 -- Skip internally generated code
27575 elsif not Comes_From_Source (Stmt) then
27577 -- The anonymous object created for a single concurrent type is a
27578 -- suitable context.
27580 if Nkind (Stmt) = N_Object_Declaration
27581 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
27582 then
27583 return Stmt;
27585 elsif Nkind (Stmt) = N_Subprogram_Declaration then
27587 -- The subprogram declaration is an internally generated spec
27588 -- for an expression function.
27590 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
27591 return Stmt;
27593 -- The subprogram is actually an instance housed within an
27594 -- anonymous wrapper package.
27596 elsif Present (Generic_Parent (Specification (Stmt))) then
27597 return Stmt;
27598 end if;
27599 end if;
27601 -- Return the current construct which is either a subprogram body,
27602 -- a subprogram declaration or is illegal.
27604 else
27605 return Stmt;
27606 end if;
27608 Prev (Stmt);
27609 end loop;
27611 -- If we fall through, then the pragma was either the first declaration
27612 -- or it was preceded by other pragmas and no source constructs.
27614 -- The pragma is associated with a library-level subprogram
27616 if Nkind (Context) = N_Compilation_Unit_Aux then
27617 return Unit (Parent (Context));
27619 -- The pragma appears inside the declarations of an entry body
27621 elsif Nkind (Context) = N_Entry_Body then
27622 return Context;
27624 -- The pragma appears inside the statements of a subprogram body. This
27625 -- placement is the result of subprogram contract expansion.
27627 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
27628 return Parent (Context);
27630 -- The pragma appears inside the declarative part of a subprogram body
27632 elsif Nkind (Context) = N_Subprogram_Body then
27633 return Context;
27635 -- The pragma appears inside the declarative part of a task body
27637 elsif Nkind (Context) = N_Task_Body then
27638 return Context;
27640 -- The pragma is a byproduct of aspect expansion, return the related
27641 -- context of the original aspect. This case has a lower priority as
27642 -- the above circuitry pinpoints precisely the related context.
27644 elsif Present (Corresponding_Aspect (Prag)) then
27645 return Parent (Corresponding_Aspect (Prag));
27647 -- No candidate subprogram [body] found
27649 else
27650 return Empty;
27651 end if;
27652 end Find_Related_Declaration_Or_Body;
27654 ----------------------------------
27655 -- Find_Related_Package_Or_Body --
27656 ----------------------------------
27658 function Find_Related_Package_Or_Body
27659 (Prag : Node_Id;
27660 Do_Checks : Boolean := False) return Node_Id
27662 Context : constant Node_Id := Parent (Prag);
27663 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
27664 Stmt : Node_Id;
27666 begin
27667 Stmt := Prev (Prag);
27668 while Present (Stmt) loop
27670 -- Skip prior pragmas, but check for duplicates
27672 if Nkind (Stmt) = N_Pragma then
27673 if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then
27674 Duplication_Error
27675 (Prag => Prag,
27676 Prev => Stmt);
27677 end if;
27679 -- Skip internally generated code
27681 elsif not Comes_From_Source (Stmt) then
27682 if Nkind (Stmt) = N_Subprogram_Declaration then
27684 -- The subprogram declaration is an internally generated spec
27685 -- for an expression function.
27687 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
27688 return Stmt;
27690 -- The subprogram is actually an instance housed within an
27691 -- anonymous wrapper package.
27693 elsif Present (Generic_Parent (Specification (Stmt))) then
27694 return Stmt;
27695 end if;
27696 end if;
27698 -- Return the current source construct which is illegal
27700 else
27701 return Stmt;
27702 end if;
27704 Prev (Stmt);
27705 end loop;
27707 -- If we fall through, then the pragma was either the first declaration
27708 -- or it was preceded by other pragmas and no source constructs.
27710 -- The pragma is associated with a package. The immediate context in
27711 -- this case is the specification of the package.
27713 if Nkind (Context) = N_Package_Specification then
27714 return Parent (Context);
27716 -- The pragma appears in the declarations of a package body
27718 elsif Nkind (Context) = N_Package_Body then
27719 return Context;
27721 -- The pragma appears in the statements of a package body
27723 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
27724 and then Nkind (Parent (Context)) = N_Package_Body
27725 then
27726 return Parent (Context);
27728 -- The pragma is a byproduct of aspect expansion, return the related
27729 -- context of the original aspect. This case has a lower priority as
27730 -- the above circuitry pinpoints precisely the related context.
27732 elsif Present (Corresponding_Aspect (Prag)) then
27733 return Parent (Corresponding_Aspect (Prag));
27735 -- No candidate packge [body] found
27737 else
27738 return Empty;
27739 end if;
27740 end Find_Related_Package_Or_Body;
27742 ------------------
27743 -- Get_Argument --
27744 ------------------
27746 function Get_Argument
27747 (Prag : Node_Id;
27748 Context_Id : Entity_Id := Empty) return Node_Id
27750 Args : constant List_Id := Pragma_Argument_Associations (Prag);
27752 begin
27753 -- Use the expression of the original aspect when compiling for ASIS or
27754 -- when analyzing the template of a generic unit. In both cases the
27755 -- aspect's tree must be decorated to allow for ASIS queries or to save
27756 -- the global references in the generic context.
27758 if From_Aspect_Specification (Prag)
27759 and then (ASIS_Mode or else (Present (Context_Id)
27760 and then Is_Generic_Unit (Context_Id)))
27761 then
27762 return Corresponding_Aspect (Prag);
27764 -- Otherwise use the expression of the pragma
27766 elsif Present (Args) then
27767 return First (Args);
27769 else
27770 return Empty;
27771 end if;
27772 end Get_Argument;
27774 -------------------------
27775 -- Get_Base_Subprogram --
27776 -------------------------
27778 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
27779 Result : Entity_Id;
27781 begin
27782 -- Follow subprogram renaming chain
27784 Result := Def_Id;
27786 if Is_Subprogram (Result)
27787 and then
27788 Nkind (Parent (Declaration_Node (Result))) =
27789 N_Subprogram_Renaming_Declaration
27790 and then Present (Alias (Result))
27791 then
27792 Result := Alias (Result);
27793 end if;
27795 return Result;
27796 end Get_Base_Subprogram;
27798 -----------------------
27799 -- Get_SPARK_Mode_Type --
27800 -----------------------
27802 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
27803 begin
27804 if N = Name_On then
27805 return On;
27806 elsif N = Name_Off then
27807 return Off;
27809 -- Any other argument is illegal
27811 else
27812 raise Program_Error;
27813 end if;
27814 end Get_SPARK_Mode_Type;
27816 ------------------------------------
27817 -- Get_SPARK_Mode_From_Annotation --
27818 ------------------------------------
27820 function Get_SPARK_Mode_From_Annotation
27821 (N : Node_Id) return SPARK_Mode_Type
27823 Mode : Node_Id;
27825 begin
27826 if Nkind (N) = N_Aspect_Specification then
27827 Mode := Expression (N);
27829 else pragma Assert (Nkind (N) = N_Pragma);
27830 Mode := First (Pragma_Argument_Associations (N));
27832 if Present (Mode) then
27833 Mode := Get_Pragma_Arg (Mode);
27834 end if;
27835 end if;
27837 -- Aspect or pragma SPARK_Mode specifies an explicit mode
27839 if Present (Mode) then
27840 if Nkind (Mode) = N_Identifier then
27841 return Get_SPARK_Mode_Type (Chars (Mode));
27843 -- In case of a malformed aspect or pragma, return the default None
27845 else
27846 return None;
27847 end if;
27849 -- Otherwise the lack of an expression defaults SPARK_Mode to On
27851 else
27852 return On;
27853 end if;
27854 end Get_SPARK_Mode_From_Annotation;
27856 ---------------------------
27857 -- Has_Extra_Parentheses --
27858 ---------------------------
27860 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
27861 Expr : Node_Id;
27863 begin
27864 -- The aggregate should not have an expression list because a clause
27865 -- is always interpreted as a component association. The only way an
27866 -- expression list can sneak in is by adding extra parentheses around
27867 -- the individual clauses:
27869 -- Depends (Output => Input) -- proper form
27870 -- Depends ((Output => Input)) -- extra parentheses
27872 -- Since the extra parentheses are not allowed by the syntax of the
27873 -- pragma, flag them now to avoid emitting misleading errors down the
27874 -- line.
27876 if Nkind (Clause) = N_Aggregate
27877 and then Present (Expressions (Clause))
27878 then
27879 Expr := First (Expressions (Clause));
27880 while Present (Expr) loop
27882 -- A dependency clause surrounded by extra parentheses appears
27883 -- as an aggregate of component associations with an optional
27884 -- Paren_Count set.
27886 if Nkind (Expr) = N_Aggregate
27887 and then Present (Component_Associations (Expr))
27888 then
27889 SPARK_Msg_N
27890 ("dependency clause contains extra parentheses", Expr);
27892 -- Otherwise the expression is a malformed construct
27894 else
27895 SPARK_Msg_N ("malformed dependency clause", Expr);
27896 end if;
27898 Next (Expr);
27899 end loop;
27901 return True;
27902 end if;
27904 return False;
27905 end Has_Extra_Parentheses;
27907 ----------------
27908 -- Initialize --
27909 ----------------
27911 procedure Initialize is
27912 begin
27913 Externals.Init;
27914 end Initialize;
27916 --------
27917 -- ip --
27918 --------
27920 procedure ip is
27921 begin
27922 Dummy := Dummy + 1;
27923 end ip;
27925 -----------------------------
27926 -- Is_Config_Static_String --
27927 -----------------------------
27929 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
27931 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
27932 -- This is an internal recursive function that is just like the outer
27933 -- function except that it adds the string to the name buffer rather
27934 -- than placing the string in the name buffer.
27936 ------------------------------
27937 -- Add_Config_Static_String --
27938 ------------------------------
27940 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
27941 N : Node_Id;
27942 C : Char_Code;
27944 begin
27945 N := Arg;
27947 if Nkind (N) = N_Op_Concat then
27948 if Add_Config_Static_String (Left_Opnd (N)) then
27949 N := Right_Opnd (N);
27950 else
27951 return False;
27952 end if;
27953 end if;
27955 if Nkind (N) /= N_String_Literal then
27956 Error_Msg_N ("string literal expected for pragma argument", N);
27957 return False;
27959 else
27960 for J in 1 .. String_Length (Strval (N)) loop
27961 C := Get_String_Char (Strval (N), J);
27963 if not In_Character_Range (C) then
27964 Error_Msg
27965 ("string literal contains invalid wide character",
27966 Sloc (N) + 1 + Source_Ptr (J));
27967 return False;
27968 end if;
27970 Add_Char_To_Name_Buffer (Get_Character (C));
27971 end loop;
27972 end if;
27974 return True;
27975 end Add_Config_Static_String;
27977 -- Start of processing for Is_Config_Static_String
27979 begin
27980 Name_Len := 0;
27982 return Add_Config_Static_String (Arg);
27983 end Is_Config_Static_String;
27985 ---------------------
27986 -- Is_CCT_Instance --
27987 ---------------------
27989 function Is_CCT_Instance
27990 (Ref_Id : Entity_Id;
27991 Context_Id : Entity_Id) return Boolean
27993 S : Entity_Id;
27994 Typ : Entity_Id;
27996 begin
27997 -- When the reference denotes a single protected type, the context is
27998 -- either a protected subprogram or its body.
28000 if Is_Single_Protected_Object (Ref_Id) then
28001 Typ := Scope (Context_Id);
28003 return
28004 Ekind (Typ) = E_Protected_Type
28005 and then Present (Anonymous_Object (Typ))
28006 and then Anonymous_Object (Typ) = Ref_Id;
28008 -- When the reference denotes a single task type, the context is either
28009 -- the same type or if inside the body, the anonymous task type.
28011 elsif Is_Single_Task_Object (Ref_Id) then
28012 if Ekind (Context_Id) = E_Task_Type then
28013 return
28014 Present (Anonymous_Object (Context_Id))
28015 and then Anonymous_Object (Context_Id) = Ref_Id;
28016 else
28017 return Ref_Id = Context_Id;
28018 end if;
28020 -- Otherwise the reference denotes a protected or a task type. Climb the
28021 -- scope chain looking for an enclosing concurrent type that matches the
28022 -- referenced entity.
28024 else
28025 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
28027 S := Current_Scope;
28028 while Present (S) and then S /= Standard_Standard loop
28029 if Ekind_In (S, E_Protected_Type, E_Task_Type)
28030 and then S = Ref_Id
28031 then
28032 return True;
28033 end if;
28035 S := Scope (S);
28036 end loop;
28037 end if;
28039 return False;
28040 end Is_CCT_Instance;
28042 -------------------------------
28043 -- Is_Elaboration_SPARK_Mode --
28044 -------------------------------
28046 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
28047 begin
28048 pragma Assert
28049 (Nkind (N) = N_Pragma
28050 and then Pragma_Name (N) = Name_SPARK_Mode
28051 and then Is_List_Member (N));
28053 -- Pragma SPARK_Mode affects the elaboration of a package body when it
28054 -- appears in the statement part of the body.
28056 return
28057 Present (Parent (N))
28058 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
28059 and then List_Containing (N) = Statements (Parent (N))
28060 and then Present (Parent (Parent (N)))
28061 and then Nkind (Parent (Parent (N))) = N_Package_Body;
28062 end Is_Elaboration_SPARK_Mode;
28064 -----------------------
28065 -- Is_Enabled_Pragma --
28066 -----------------------
28068 function Is_Enabled_Pragma (Prag : Node_Id) return Boolean is
28069 Arg : Node_Id;
28071 begin
28072 if Present (Prag) then
28073 Arg := First (Pragma_Argument_Associations (Prag));
28075 if Present (Arg) then
28076 return Is_True (Expr_Value (Get_Pragma_Arg (Arg)));
28078 -- The lack of a Boolean argument automatically enables the pragma
28080 else
28081 return True;
28082 end if;
28084 -- The pragma is missing, therefore it is not enabled
28086 else
28087 return False;
28088 end if;
28089 end Is_Enabled_Pragma;
28091 -----------------------------------------
28092 -- Is_Non_Significant_Pragma_Reference --
28093 -----------------------------------------
28095 -- This function makes use of the following static table which indicates
28096 -- whether appearance of some name in a given pragma is to be considered
28097 -- as a reference for the purposes of warnings about unreferenced objects.
28099 -- -1 indicates that appearence in any argument is significant
28100 -- 0 indicates that appearance in any argument is not significant
28101 -- +n indicates that appearance as argument n is significant, but all
28102 -- other arguments are not significant
28103 -- 9n arguments from n on are significant, before n insignificant
28105 Sig_Flags : constant array (Pragma_Id) of Int :=
28106 (Pragma_Abort_Defer => -1,
28107 Pragma_Abstract_State => -1,
28108 Pragma_Ada_83 => -1,
28109 Pragma_Ada_95 => -1,
28110 Pragma_Ada_05 => -1,
28111 Pragma_Ada_2005 => -1,
28112 Pragma_Ada_12 => -1,
28113 Pragma_Ada_2012 => -1,
28114 Pragma_All_Calls_Remote => -1,
28115 Pragma_Allow_Integer_Address => -1,
28116 Pragma_Annotate => 93,
28117 Pragma_Assert => -1,
28118 Pragma_Assert_And_Cut => -1,
28119 Pragma_Assertion_Policy => 0,
28120 Pragma_Assume => -1,
28121 Pragma_Assume_No_Invalid_Values => 0,
28122 Pragma_Async_Readers => 0,
28123 Pragma_Async_Writers => 0,
28124 Pragma_Asynchronous => 0,
28125 Pragma_Atomic => 0,
28126 Pragma_Atomic_Components => 0,
28127 Pragma_Attach_Handler => -1,
28128 Pragma_Attribute_Definition => 92,
28129 Pragma_Check => -1,
28130 Pragma_Check_Float_Overflow => 0,
28131 Pragma_Check_Name => 0,
28132 Pragma_Check_Policy => 0,
28133 Pragma_CPP_Class => 0,
28134 Pragma_CPP_Constructor => 0,
28135 Pragma_CPP_Virtual => 0,
28136 Pragma_CPP_Vtable => 0,
28137 Pragma_CPU => -1,
28138 Pragma_C_Pass_By_Copy => 0,
28139 Pragma_Comment => -1,
28140 Pragma_Common_Object => 0,
28141 Pragma_Compile_Time_Error => -1,
28142 Pragma_Compile_Time_Warning => -1,
28143 Pragma_Compiler_Unit => -1,
28144 Pragma_Compiler_Unit_Warning => -1,
28145 Pragma_Complete_Representation => 0,
28146 Pragma_Complex_Representation => 0,
28147 Pragma_Component_Alignment => 0,
28148 Pragma_Constant_After_Elaboration => 0,
28149 Pragma_Contract_Cases => -1,
28150 Pragma_Controlled => 0,
28151 Pragma_Convention => 0,
28152 Pragma_Convention_Identifier => 0,
28153 Pragma_Debug => -1,
28154 Pragma_Debug_Policy => 0,
28155 Pragma_Detect_Blocking => 0,
28156 Pragma_Default_Initial_Condition => -1,
28157 Pragma_Default_Scalar_Storage_Order => 0,
28158 Pragma_Default_Storage_Pool => 0,
28159 Pragma_Depends => -1,
28160 Pragma_Disable_Atomic_Synchronization => 0,
28161 Pragma_Discard_Names => 0,
28162 Pragma_Dispatching_Domain => -1,
28163 Pragma_Effective_Reads => 0,
28164 Pragma_Effective_Writes => 0,
28165 Pragma_Elaborate => 0,
28166 Pragma_Elaborate_All => 0,
28167 Pragma_Elaborate_Body => 0,
28168 Pragma_Elaboration_Checks => 0,
28169 Pragma_Eliminate => 0,
28170 Pragma_Enable_Atomic_Synchronization => 0,
28171 Pragma_Export => -1,
28172 Pragma_Export_Function => -1,
28173 Pragma_Export_Object => -1,
28174 Pragma_Export_Procedure => -1,
28175 Pragma_Export_Value => -1,
28176 Pragma_Export_Valued_Procedure => -1,
28177 Pragma_Extend_System => -1,
28178 Pragma_Extensions_Allowed => 0,
28179 Pragma_Extensions_Visible => 0,
28180 Pragma_External => -1,
28181 Pragma_Favor_Top_Level => 0,
28182 Pragma_External_Name_Casing => 0,
28183 Pragma_Fast_Math => 0,
28184 Pragma_Finalize_Storage_Only => 0,
28185 Pragma_Ghost => 0,
28186 Pragma_Global => -1,
28187 Pragma_Ident => -1,
28188 Pragma_Ignore_Pragma => 0,
28189 Pragma_Implementation_Defined => -1,
28190 Pragma_Implemented => -1,
28191 Pragma_Implicit_Packing => 0,
28192 Pragma_Import => 93,
28193 Pragma_Import_Function => 0,
28194 Pragma_Import_Object => 0,
28195 Pragma_Import_Procedure => 0,
28196 Pragma_Import_Valued_Procedure => 0,
28197 Pragma_Independent => 0,
28198 Pragma_Independent_Components => 0,
28199 Pragma_Initial_Condition => -1,
28200 Pragma_Initialize_Scalars => 0,
28201 Pragma_Initializes => -1,
28202 Pragma_Inline => 0,
28203 Pragma_Inline_Always => 0,
28204 Pragma_Inline_Generic => 0,
28205 Pragma_Inspection_Point => -1,
28206 Pragma_Interface => 92,
28207 Pragma_Interface_Name => 0,
28208 Pragma_Interrupt_Handler => -1,
28209 Pragma_Interrupt_Priority => -1,
28210 Pragma_Interrupt_State => -1,
28211 Pragma_Invariant => -1,
28212 Pragma_Keep_Names => 0,
28213 Pragma_License => 0,
28214 Pragma_Link_With => -1,
28215 Pragma_Linker_Alias => -1,
28216 Pragma_Linker_Constructor => -1,
28217 Pragma_Linker_Destructor => -1,
28218 Pragma_Linker_Options => -1,
28219 Pragma_Linker_Section => 0,
28220 Pragma_List => 0,
28221 Pragma_Lock_Free => 0,
28222 Pragma_Locking_Policy => 0,
28223 Pragma_Loop_Invariant => -1,
28224 Pragma_Loop_Optimize => 0,
28225 Pragma_Loop_Variant => -1,
28226 Pragma_Machine_Attribute => -1,
28227 Pragma_Main => -1,
28228 Pragma_Main_Storage => -1,
28229 Pragma_Memory_Size => 0,
28230 Pragma_No_Return => 0,
28231 Pragma_No_Body => 0,
28232 Pragma_No_Elaboration_Code_All => 0,
28233 Pragma_No_Inline => 0,
28234 Pragma_No_Run_Time => -1,
28235 Pragma_No_Strict_Aliasing => -1,
28236 Pragma_No_Tagged_Streams => 0,
28237 Pragma_Normalize_Scalars => 0,
28238 Pragma_Obsolescent => 0,
28239 Pragma_Optimize => 0,
28240 Pragma_Optimize_Alignment => 0,
28241 Pragma_Overflow_Mode => 0,
28242 Pragma_Overriding_Renamings => 0,
28243 Pragma_Ordered => 0,
28244 Pragma_Pack => 0,
28245 Pragma_Page => 0,
28246 Pragma_Part_Of => 0,
28247 Pragma_Partition_Elaboration_Policy => 0,
28248 Pragma_Passive => 0,
28249 Pragma_Persistent_BSS => 0,
28250 Pragma_Polling => 0,
28251 Pragma_Prefix_Exception_Messages => 0,
28252 Pragma_Post => -1,
28253 Pragma_Postcondition => -1,
28254 Pragma_Post_Class => -1,
28255 Pragma_Pre => -1,
28256 Pragma_Precondition => -1,
28257 Pragma_Predicate => -1,
28258 Pragma_Predicate_Failure => -1,
28259 Pragma_Preelaborable_Initialization => -1,
28260 Pragma_Preelaborate => 0,
28261 Pragma_Pre_Class => -1,
28262 Pragma_Priority => -1,
28263 Pragma_Priority_Specific_Dispatching => 0,
28264 Pragma_Profile => 0,
28265 Pragma_Profile_Warnings => 0,
28266 Pragma_Propagate_Exceptions => 0,
28267 Pragma_Provide_Shift_Operators => 0,
28268 Pragma_Psect_Object => 0,
28269 Pragma_Pure => 0,
28270 Pragma_Pure_Function => 0,
28271 Pragma_Queuing_Policy => 0,
28272 Pragma_Rational => 0,
28273 Pragma_Ravenscar => 0,
28274 Pragma_Refined_Depends => -1,
28275 Pragma_Refined_Global => -1,
28276 Pragma_Refined_Post => -1,
28277 Pragma_Refined_State => -1,
28278 Pragma_Relative_Deadline => 0,
28279 Pragma_Remote_Access_Type => -1,
28280 Pragma_Remote_Call_Interface => -1,
28281 Pragma_Remote_Types => -1,
28282 Pragma_Restricted_Run_Time => 0,
28283 Pragma_Restriction_Warnings => 0,
28284 Pragma_Restrictions => 0,
28285 Pragma_Reviewable => -1,
28286 Pragma_Short_Circuit_And_Or => 0,
28287 Pragma_Share_Generic => 0,
28288 Pragma_Shared => 0,
28289 Pragma_Shared_Passive => 0,
28290 Pragma_Short_Descriptors => 0,
28291 Pragma_Simple_Storage_Pool_Type => 0,
28292 Pragma_Source_File_Name => 0,
28293 Pragma_Source_File_Name_Project => 0,
28294 Pragma_Source_Reference => 0,
28295 Pragma_SPARK_Mode => 0,
28296 Pragma_Storage_Size => -1,
28297 Pragma_Storage_Unit => 0,
28298 Pragma_Static_Elaboration_Desired => 0,
28299 Pragma_Stream_Convert => 0,
28300 Pragma_Style_Checks => 0,
28301 Pragma_Subtitle => 0,
28302 Pragma_Suppress => 0,
28303 Pragma_Suppress_Exception_Locations => 0,
28304 Pragma_Suppress_All => 0,
28305 Pragma_Suppress_Debug_Info => 0,
28306 Pragma_Suppress_Initialization => 0,
28307 Pragma_System_Name => 0,
28308 Pragma_Task_Dispatching_Policy => 0,
28309 Pragma_Task_Info => -1,
28310 Pragma_Task_Name => -1,
28311 Pragma_Task_Storage => -1,
28312 Pragma_Test_Case => -1,
28313 Pragma_Thread_Local_Storage => -1,
28314 Pragma_Time_Slice => -1,
28315 Pragma_Title => 0,
28316 Pragma_Type_Invariant => -1,
28317 Pragma_Type_Invariant_Class => -1,
28318 Pragma_Unchecked_Union => 0,
28319 Pragma_Unimplemented_Unit => 0,
28320 Pragma_Universal_Aliasing => 0,
28321 Pragma_Universal_Data => 0,
28322 Pragma_Unmodified => 0,
28323 Pragma_Unreferenced => 0,
28324 Pragma_Unreferenced_Objects => 0,
28325 Pragma_Unreserve_All_Interrupts => 0,
28326 Pragma_Unsuppress => 0,
28327 Pragma_Unevaluated_Use_Of_Old => 0,
28328 Pragma_Use_VADS_Size => 0,
28329 Pragma_Validity_Checks => 0,
28330 Pragma_Volatile => 0,
28331 Pragma_Volatile_Components => 0,
28332 Pragma_Volatile_Full_Access => 0,
28333 Pragma_Volatile_Function => 0,
28334 Pragma_Warning_As_Error => 0,
28335 Pragma_Warnings => 0,
28336 Pragma_Weak_External => 0,
28337 Pragma_Wide_Character_Encoding => 0,
28338 Unknown_Pragma => 0);
28340 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
28341 Id : Pragma_Id;
28342 P : Node_Id;
28343 C : Int;
28344 AN : Nat;
28346 function Arg_No return Nat;
28347 -- Returns an integer showing what argument we are in. A value of
28348 -- zero means we are not in any of the arguments.
28350 ------------
28351 -- Arg_No --
28352 ------------
28354 function Arg_No return Nat is
28355 A : Node_Id;
28356 N : Nat;
28358 begin
28359 A := First (Pragma_Argument_Associations (Parent (P)));
28360 N := 1;
28361 loop
28362 if No (A) then
28363 return 0;
28364 elsif A = P then
28365 return N;
28366 end if;
28368 Next (A);
28369 N := N + 1;
28370 end loop;
28371 end Arg_No;
28373 -- Start of processing for Non_Significant_Pragma_Reference
28375 begin
28376 P := Parent (N);
28378 if Nkind (P) /= N_Pragma_Argument_Association then
28379 return False;
28381 else
28382 Id := Get_Pragma_Id (Parent (P));
28383 C := Sig_Flags (Id);
28384 AN := Arg_No;
28386 if AN = 0 then
28387 return False;
28388 end if;
28390 case C is
28391 when -1 =>
28392 return False;
28394 when 0 =>
28395 return True;
28397 when 92 .. 99 =>
28398 return AN < (C - 90);
28400 when others =>
28401 return AN /= C;
28402 end case;
28403 end if;
28404 end Is_Non_Significant_Pragma_Reference;
28406 ------------------------------
28407 -- Is_Pragma_String_Literal --
28408 ------------------------------
28410 -- This function returns true if the corresponding pragma argument is a
28411 -- static string expression. These are the only cases in which string
28412 -- literals can appear as pragma arguments. We also allow a string literal
28413 -- as the first argument to pragma Assert (although it will of course
28414 -- always generate a type error).
28416 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
28417 Pragn : constant Node_Id := Parent (Par);
28418 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
28419 Pname : constant Name_Id := Pragma_Name (Pragn);
28420 Argn : Natural;
28421 N : Node_Id;
28423 begin
28424 Argn := 1;
28425 N := First (Assoc);
28426 loop
28427 exit when N = Par;
28428 Argn := Argn + 1;
28429 Next (N);
28430 end loop;
28432 if Pname = Name_Assert then
28433 return True;
28435 elsif Pname = Name_Export then
28436 return Argn > 2;
28438 elsif Pname = Name_Ident then
28439 return Argn = 1;
28441 elsif Pname = Name_Import then
28442 return Argn > 2;
28444 elsif Pname = Name_Interface_Name then
28445 return Argn > 1;
28447 elsif Pname = Name_Linker_Alias then
28448 return Argn = 2;
28450 elsif Pname = Name_Linker_Section then
28451 return Argn = 2;
28453 elsif Pname = Name_Machine_Attribute then
28454 return Argn = 2;
28456 elsif Pname = Name_Source_File_Name then
28457 return True;
28459 elsif Pname = Name_Source_Reference then
28460 return Argn = 2;
28462 elsif Pname = Name_Title then
28463 return True;
28465 elsif Pname = Name_Subtitle then
28466 return True;
28468 else
28469 return False;
28470 end if;
28471 end Is_Pragma_String_Literal;
28473 ---------------------------
28474 -- Is_Private_SPARK_Mode --
28475 ---------------------------
28477 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
28478 begin
28479 pragma Assert
28480 (Nkind (N) = N_Pragma
28481 and then Pragma_Name (N) = Name_SPARK_Mode
28482 and then Is_List_Member (N));
28484 -- For pragma SPARK_Mode to be private, it has to appear in the private
28485 -- declarations of a package.
28487 return
28488 Present (Parent (N))
28489 and then Nkind (Parent (N)) = N_Package_Specification
28490 and then List_Containing (N) = Private_Declarations (Parent (N));
28491 end Is_Private_SPARK_Mode;
28493 -------------------------------------
28494 -- Is_Unconstrained_Or_Tagged_Item --
28495 -------------------------------------
28497 function Is_Unconstrained_Or_Tagged_Item
28498 (Item : Entity_Id) return Boolean
28500 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
28501 -- Determine whether record type Typ has at least one unconstrained
28502 -- component.
28504 ---------------------------------
28505 -- Has_Unconstrained_Component --
28506 ---------------------------------
28508 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
28509 Comp : Entity_Id;
28511 begin
28512 Comp := First_Component (Typ);
28513 while Present (Comp) loop
28514 if Is_Unconstrained_Or_Tagged_Item (Comp) then
28515 return True;
28516 end if;
28518 Next_Component (Comp);
28519 end loop;
28521 return False;
28522 end Has_Unconstrained_Component;
28524 -- Local variables
28526 Typ : constant Entity_Id := Etype (Item);
28528 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
28530 begin
28531 if Is_Tagged_Type (Typ) then
28532 return True;
28534 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
28535 return True;
28537 elsif Is_Record_Type (Typ) then
28538 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
28539 return True;
28540 else
28541 return Has_Unconstrained_Component (Typ);
28542 end if;
28544 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
28545 return True;
28547 else
28548 return False;
28549 end if;
28550 end Is_Unconstrained_Or_Tagged_Item;
28552 -----------------------------
28553 -- Is_Valid_Assertion_Kind --
28554 -----------------------------
28556 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
28557 begin
28558 case Nam is
28559 when
28560 -- RM defined
28562 Name_Assert |
28563 Name_Static_Predicate |
28564 Name_Dynamic_Predicate |
28565 Name_Pre |
28566 Name_uPre |
28567 Name_Post |
28568 Name_uPost |
28569 Name_Type_Invariant |
28570 Name_uType_Invariant |
28572 -- Impl defined
28574 Name_Assert_And_Cut |
28575 Name_Assume |
28576 Name_Contract_Cases |
28577 Name_Debug |
28578 Name_Default_Initial_Condition |
28579 Name_Ghost |
28580 Name_Initial_Condition |
28581 Name_Invariant |
28582 Name_uInvariant |
28583 Name_Loop_Invariant |
28584 Name_Loop_Variant |
28585 Name_Postcondition |
28586 Name_Precondition |
28587 Name_Predicate |
28588 Name_Refined_Post |
28589 Name_Statement_Assertions => return True;
28591 when others => return False;
28592 end case;
28593 end Is_Valid_Assertion_Kind;
28595 --------------------------------------
28596 -- Process_Compilation_Unit_Pragmas --
28597 --------------------------------------
28599 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
28600 begin
28601 -- A special check for pragma Suppress_All, a very strange DEC pragma,
28602 -- strange because it comes at the end of the unit. Rational has the
28603 -- same name for a pragma, but treats it as a program unit pragma, In
28604 -- GNAT we just decide to allow it anywhere at all. If it appeared then
28605 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
28606 -- node, and we insert a pragma Suppress (All_Checks) at the start of
28607 -- the context clause to ensure the correct processing.
28609 if Has_Pragma_Suppress_All (N) then
28610 Prepend_To (Context_Items (N),
28611 Make_Pragma (Sloc (N),
28612 Chars => Name_Suppress,
28613 Pragma_Argument_Associations => New_List (
28614 Make_Pragma_Argument_Association (Sloc (N),
28615 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
28616 end if;
28618 -- Nothing else to do at the current time
28620 end Process_Compilation_Unit_Pragmas;
28622 ------------------------------------
28623 -- Record_Possible_Body_Reference --
28624 ------------------------------------
28626 procedure Record_Possible_Body_Reference
28627 (State_Id : Entity_Id;
28628 Ref : Node_Id)
28630 Context : Node_Id;
28631 Spec_Id : Entity_Id;
28633 begin
28634 -- Ensure that we are dealing with a reference to a state
28636 pragma Assert (Ekind (State_Id) = E_Abstract_State);
28638 -- Climb the tree starting from the reference looking for a package body
28639 -- whose spec declares the referenced state. This criteria automatically
28640 -- excludes references in package specs which are legal. Note that it is
28641 -- not wise to emit an error now as the package body may lack pragma
28642 -- Refined_State or the referenced state may not be mentioned in the
28643 -- refinement. This approach avoids the generation of misleading errors.
28645 Context := Ref;
28646 while Present (Context) loop
28647 if Nkind (Context) = N_Package_Body then
28648 Spec_Id := Corresponding_Spec (Context);
28650 if Present (Abstract_States (Spec_Id))
28651 and then Contains (Abstract_States (Spec_Id), State_Id)
28652 then
28653 if No (Body_References (State_Id)) then
28654 Set_Body_References (State_Id, New_Elmt_List);
28655 end if;
28657 Append_Elmt (Ref, To => Body_References (State_Id));
28658 exit;
28659 end if;
28660 end if;
28662 Context := Parent (Context);
28663 end loop;
28664 end Record_Possible_Body_Reference;
28666 ------------------------------------------
28667 -- Relocate_Pragmas_To_Anonymous_Object --
28668 ------------------------------------------
28670 procedure Relocate_Pragmas_To_Anonymous_Object
28671 (Typ_Decl : Node_Id;
28672 Obj_Decl : Node_Id)
28674 Decl : Node_Id;
28675 Def : Node_Id;
28676 Next_Decl : Node_Id;
28678 begin
28679 if Nkind (Typ_Decl) = N_Protected_Type_Declaration then
28680 Def := Protected_Definition (Typ_Decl);
28681 else
28682 pragma Assert (Nkind (Typ_Decl) = N_Task_Type_Declaration);
28683 Def := Task_Definition (Typ_Decl);
28684 end if;
28686 -- The concurrent definition has a visible declaration list. Inspect it
28687 -- and relocate all canidate pragmas.
28689 if Present (Def) and then Present (Visible_Declarations (Def)) then
28690 Decl := First (Visible_Declarations (Def));
28691 while Present (Decl) loop
28693 -- Preserve the following declaration for iteration purposes due
28694 -- to possible relocation of a pragma.
28696 Next_Decl := Next (Decl);
28698 if Nkind (Decl) = N_Pragma
28699 and then Pragma_On_Anonymous_Object_OK (Get_Pragma_Id (Decl))
28700 then
28701 Remove (Decl);
28702 Insert_After (Obj_Decl, Decl);
28704 -- Skip internally generated code
28706 elsif not Comes_From_Source (Decl) then
28707 null;
28709 -- No candidate pragmas are available for relocation
28711 else
28712 exit;
28713 end if;
28715 Decl := Next_Decl;
28716 end loop;
28717 end if;
28718 end Relocate_Pragmas_To_Anonymous_Object;
28720 ------------------------------
28721 -- Relocate_Pragmas_To_Body --
28722 ------------------------------
28724 procedure Relocate_Pragmas_To_Body
28725 (Subp_Body : Node_Id;
28726 Target_Body : Node_Id := Empty)
28728 procedure Relocate_Pragma (Prag : Node_Id);
28729 -- Remove a single pragma from its current list and add it to the
28730 -- declarations of the proper body (either Subp_Body or Target_Body).
28732 ---------------------
28733 -- Relocate_Pragma --
28734 ---------------------
28736 procedure Relocate_Pragma (Prag : Node_Id) is
28737 Decls : List_Id;
28738 Target : Node_Id;
28740 begin
28741 -- When subprogram stubs or expression functions are involves, the
28742 -- destination declaration list belongs to the proper body.
28744 if Present (Target_Body) then
28745 Target := Target_Body;
28746 else
28747 Target := Subp_Body;
28748 end if;
28750 Decls := Declarations (Target);
28752 if No (Decls) then
28753 Decls := New_List;
28754 Set_Declarations (Target, Decls);
28755 end if;
28757 -- Unhook the pragma from its current list
28759 Remove (Prag);
28760 Prepend (Prag, Decls);
28761 end Relocate_Pragma;
28763 -- Local variables
28765 Body_Id : constant Entity_Id :=
28766 Defining_Unit_Name (Specification (Subp_Body));
28767 Next_Stmt : Node_Id;
28768 Stmt : Node_Id;
28770 -- Start of processing for Relocate_Pragmas_To_Body
28772 begin
28773 -- Do not process a body that comes from a separate unit as no construct
28774 -- can possibly follow it.
28776 if not Is_List_Member (Subp_Body) then
28777 return;
28779 -- Do not relocate pragmas that follow a stub if the stub does not have
28780 -- a proper body.
28782 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
28783 and then No (Target_Body)
28784 then
28785 return;
28787 -- Do not process internally generated routine _Postconditions
28789 elsif Ekind (Body_Id) = E_Procedure
28790 and then Chars (Body_Id) = Name_uPostconditions
28791 then
28792 return;
28793 end if;
28795 -- Look at what is following the body. We are interested in certain kind
28796 -- of pragmas (either from source or byproducts of expansion) that can
28797 -- apply to a body [stub].
28799 Stmt := Next (Subp_Body);
28800 while Present (Stmt) loop
28802 -- Preserve the following statement for iteration purposes due to a
28803 -- possible relocation of a pragma.
28805 Next_Stmt := Next (Stmt);
28807 -- Move a candidate pragma following the body to the declarations of
28808 -- the body.
28810 if Nkind (Stmt) = N_Pragma
28811 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
28812 then
28813 Relocate_Pragma (Stmt);
28815 -- Skip internally generated code
28817 elsif not Comes_From_Source (Stmt) then
28818 null;
28820 -- No candidate pragmas are available for relocation
28822 else
28823 exit;
28824 end if;
28826 Stmt := Next_Stmt;
28827 end loop;
28828 end Relocate_Pragmas_To_Body;
28830 -------------------
28831 -- Resolve_State --
28832 -------------------
28834 procedure Resolve_State (N : Node_Id) is
28835 Func : Entity_Id;
28836 State : Entity_Id;
28838 begin
28839 if Is_Entity_Name (N) and then Present (Entity (N)) then
28840 Func := Entity (N);
28842 -- Handle overloading of state names by functions. Traverse the
28843 -- homonym chain looking for an abstract state.
28845 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
28846 State := Homonym (Func);
28847 while Present (State) loop
28849 -- Resolve the overloading by setting the proper entity of the
28850 -- reference to that of the state.
28852 if Ekind (State) = E_Abstract_State then
28853 Set_Etype (N, Standard_Void_Type);
28854 Set_Entity (N, State);
28855 Set_Associated_Node (N, State);
28856 return;
28857 end if;
28859 State := Homonym (State);
28860 end loop;
28862 -- A function can never act as a state. If the homonym chain does
28863 -- not contain a corresponding state, then something went wrong in
28864 -- the overloading mechanism.
28866 raise Program_Error;
28867 end if;
28868 end if;
28869 end Resolve_State;
28871 ----------------------------
28872 -- Rewrite_Assertion_Kind --
28873 ----------------------------
28875 procedure Rewrite_Assertion_Kind (N : Node_Id) is
28876 Nam : Name_Id;
28878 begin
28879 if Nkind (N) = N_Attribute_Reference
28880 and then Attribute_Name (N) = Name_Class
28881 and then Nkind (Prefix (N)) = N_Identifier
28882 then
28883 case Chars (Prefix (N)) is
28884 when Name_Pre =>
28885 Nam := Name_uPre;
28886 when Name_Post =>
28887 Nam := Name_uPost;
28888 when Name_Type_Invariant =>
28889 Nam := Name_uType_Invariant;
28890 when Name_Invariant =>
28891 Nam := Name_uInvariant;
28892 when others =>
28893 return;
28894 end case;
28896 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
28897 end if;
28898 end Rewrite_Assertion_Kind;
28900 --------
28901 -- rv --
28902 --------
28904 procedure rv is
28905 begin
28906 Dummy := Dummy + 1;
28907 end rv;
28909 --------------------------------
28910 -- Set_Encoded_Interface_Name --
28911 --------------------------------
28913 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
28914 Str : constant String_Id := Strval (S);
28915 Len : constant Nat := String_Length (Str);
28916 CC : Char_Code;
28917 C : Character;
28918 J : Pos;
28920 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
28922 procedure Encode;
28923 -- Stores encoded value of character code CC. The encoding we use an
28924 -- underscore followed by four lower case hex digits.
28926 ------------
28927 -- Encode --
28928 ------------
28930 procedure Encode is
28931 begin
28932 Store_String_Char (Get_Char_Code ('_'));
28933 Store_String_Char
28934 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
28935 Store_String_Char
28936 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
28937 Store_String_Char
28938 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
28939 Store_String_Char
28940 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
28941 end Encode;
28943 -- Start of processing for Set_Encoded_Interface_Name
28945 begin
28946 -- If first character is asterisk, this is a link name, and we leave it
28947 -- completely unmodified. We also ignore null strings (the latter case
28948 -- happens only in error cases) and no encoding should occur for AAMP
28949 -- interface names.
28951 if Len = 0
28952 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
28953 or else AAMP_On_Target
28954 then
28955 Set_Interface_Name (E, S);
28957 else
28958 J := 1;
28959 loop
28960 CC := Get_String_Char (Str, J);
28962 exit when not In_Character_Range (CC);
28964 C := Get_Character (CC);
28966 exit when C /= '_' and then C /= '$'
28967 and then C not in '0' .. '9'
28968 and then C not in 'a' .. 'z'
28969 and then C not in 'A' .. 'Z';
28971 if J = Len then
28972 Set_Interface_Name (E, S);
28973 return;
28975 else
28976 J := J + 1;
28977 end if;
28978 end loop;
28980 -- Here we need to encode. The encoding we use as follows:
28981 -- three underscores + four hex digits (lower case)
28983 Start_String;
28985 for J in 1 .. String_Length (Str) loop
28986 CC := Get_String_Char (Str, J);
28988 if not In_Character_Range (CC) then
28989 Encode;
28990 else
28991 C := Get_Character (CC);
28993 if C = '_' or else C = '$'
28994 or else C in '0' .. '9'
28995 or else C in 'a' .. 'z'
28996 or else C in 'A' .. 'Z'
28997 then
28998 Store_String_Char (CC);
28999 else
29000 Encode;
29001 end if;
29002 end if;
29003 end loop;
29005 Set_Interface_Name (E,
29006 Make_String_Literal (Sloc (S),
29007 Strval => End_String));
29008 end if;
29009 end Set_Encoded_Interface_Name;
29011 ------------------------
29012 -- Set_Elab_Unit_Name --
29013 ------------------------
29015 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is
29016 Pref : Node_Id;
29017 Scop : Entity_Id;
29019 begin
29020 if Nkind (N) = N_Identifier
29021 and then Nkind (With_Item) = N_Identifier
29022 then
29023 Set_Entity (N, Entity (With_Item));
29025 elsif Nkind (N) = N_Selected_Component then
29026 Change_Selected_Component_To_Expanded_Name (N);
29027 Set_Entity (N, Entity (With_Item));
29028 Set_Entity (Selector_Name (N), Entity (N));
29030 Pref := Prefix (N);
29031 Scop := Scope (Entity (N));
29032 while Nkind (Pref) = N_Selected_Component loop
29033 Change_Selected_Component_To_Expanded_Name (Pref);
29034 Set_Entity (Selector_Name (Pref), Scop);
29035 Set_Entity (Pref, Scop);
29036 Pref := Prefix (Pref);
29037 Scop := Scope (Scop);
29038 end loop;
29040 Set_Entity (Pref, Scop);
29041 end if;
29043 Generate_Reference (Entity (With_Item), N, Set_Ref => False);
29044 end Set_Elab_Unit_Name;
29046 -------------------
29047 -- Test_Case_Arg --
29048 -------------------
29050 function Test_Case_Arg
29051 (Prag : Node_Id;
29052 Arg_Nam : Name_Id;
29053 From_Aspect : Boolean := False) return Node_Id
29055 Aspect : constant Node_Id := Corresponding_Aspect (Prag);
29056 Arg : Node_Id;
29057 Args : Node_Id;
29059 begin
29060 pragma Assert (Nam_In (Arg_Nam, Name_Ensures,
29061 Name_Mode,
29062 Name_Name,
29063 Name_Requires));
29065 -- The caller requests the aspect argument
29067 if From_Aspect then
29068 if Present (Aspect)
29069 and then Nkind (Expression (Aspect)) = N_Aggregate
29070 then
29071 Args := Expression (Aspect);
29073 -- "Name" and "Mode" may appear without an identifier as a
29074 -- positional association.
29076 if Present (Expressions (Args)) then
29077 Arg := First (Expressions (Args));
29079 if Present (Arg) and then Arg_Nam = Name_Name then
29080 return Arg;
29081 end if;
29083 -- Skip "Name"
29085 Arg := Next (Arg);
29087 if Present (Arg) and then Arg_Nam = Name_Mode then
29088 return Arg;
29089 end if;
29090 end if;
29092 -- Some or all arguments may appear as component associatons
29094 if Present (Component_Associations (Args)) then
29095 Arg := First (Component_Associations (Args));
29096 while Present (Arg) loop
29097 if Chars (First (Choices (Arg))) = Arg_Nam then
29098 return Arg;
29099 end if;
29101 Next (Arg);
29102 end loop;
29103 end if;
29104 end if;
29106 -- Otherwise retrieve the argument directly from the pragma
29108 else
29109 Arg := First (Pragma_Argument_Associations (Prag));
29111 if Present (Arg) and then Arg_Nam = Name_Name then
29112 return Arg;
29113 end if;
29115 -- Skip argument "Name"
29117 Arg := Next (Arg);
29119 if Present (Arg) and then Arg_Nam = Name_Mode then
29120 return Arg;
29121 end if;
29123 -- Skip argument "Mode"
29125 Arg := Next (Arg);
29127 -- Arguments "Requires" and "Ensures" are optional and may not be
29128 -- present at all.
29130 while Present (Arg) loop
29131 if Chars (Arg) = Arg_Nam then
29132 return Arg;
29133 end if;
29135 Next (Arg);
29136 end loop;
29137 end if;
29139 return Empty;
29140 end Test_Case_Arg;
29142 end Sem_Prag;