2015-05-22 Eric Botcazou <ebotcazou@adacore.com>
[official-gcc.git] / gcc / ada / sem_prag.adb
blob391d546ae7840a5d66200772b270f9b4104c10fc
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-2015, 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 Csets; use Csets;
37 with Debug; use Debug;
38 with Einfo; use Einfo;
39 with Elists; use Elists;
40 with Errout; use Errout;
41 with Exp_Dist; use Exp_Dist;
42 with Exp_Util; use Exp_Util;
43 with Freeze; use Freeze;
44 with Ghost; use Ghost;
45 with Lib; use Lib;
46 with Lib.Writ; use Lib.Writ;
47 with Lib.Xref; use Lib.Xref;
48 with Namet.Sp; use Namet.Sp;
49 with Nlists; use Nlists;
50 with Nmake; use Nmake;
51 with Output; use Output;
52 with Par_SCO; use Par_SCO;
53 with Restrict; use Restrict;
54 with Rident; use Rident;
55 with Rtsfind; use Rtsfind;
56 with Sem; use Sem;
57 with Sem_Aux; use Sem_Aux;
58 with Sem_Ch3; use Sem_Ch3;
59 with Sem_Ch6; use Sem_Ch6;
60 with Sem_Ch8; use Sem_Ch8;
61 with Sem_Ch12; use Sem_Ch12;
62 with Sem_Ch13; use Sem_Ch13;
63 with Sem_Disp; use Sem_Disp;
64 with Sem_Dist; use Sem_Dist;
65 with Sem_Elim; use Sem_Elim;
66 with Sem_Eval; use Sem_Eval;
67 with Sem_Intr; use Sem_Intr;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Res; use Sem_Res;
70 with Sem_Type; use Sem_Type;
71 with Sem_Util; use Sem_Util;
72 with Sem_Warn; use Sem_Warn;
73 with Stand; use Stand;
74 with Sinfo; use Sinfo;
75 with Sinfo.CN; use Sinfo.CN;
76 with Sinput; use Sinput;
77 with Stringt; use Stringt;
78 with Stylesw; use Stylesw;
79 with Table;
80 with Targparm; use Targparm;
81 with Tbuild; use Tbuild;
82 with Ttypes;
83 with Uintp; use Uintp;
84 with Uname; use Uname;
85 with Urealp; use Urealp;
86 with Validsw; use Validsw;
87 with Warnsw; use Warnsw;
89 package body Sem_Prag is
91 ----------------------------------------------
92 -- Common Handling of Import-Export Pragmas --
93 ----------------------------------------------
95 -- In the following section, a number of Import_xxx and Export_xxx pragmas
96 -- are defined by GNAT. These are compatible with the DEC pragmas of the
97 -- same name, and all have the following common form and processing:
99 -- pragma Export_xxx
100 -- [Internal =>] LOCAL_NAME
101 -- [, [External =>] EXTERNAL_SYMBOL]
102 -- [, other optional parameters ]);
104 -- pragma Import_xxx
105 -- [Internal =>] LOCAL_NAME
106 -- [, [External =>] EXTERNAL_SYMBOL]
107 -- [, other optional parameters ]);
109 -- EXTERNAL_SYMBOL ::=
110 -- IDENTIFIER
111 -- | static_string_EXPRESSION
113 -- The internal LOCAL_NAME designates the entity that is imported or
114 -- exported, and must refer to an entity in the current declarative
115 -- part (as required by the rules for LOCAL_NAME).
117 -- The external linker name is designated by the External parameter if
118 -- given, or the Internal parameter if not (if there is no External
119 -- parameter, the External parameter is a copy of the Internal name).
121 -- If the External parameter is given as a string, then this string is
122 -- treated as an external name (exactly as though it had been given as an
123 -- External_Name parameter for a normal Import pragma).
125 -- If the External parameter is given as an identifier (or there is no
126 -- External parameter, so that the Internal identifier is used), then
127 -- the external name is the characters of the identifier, translated
128 -- to all lower case letters.
130 -- Note: the external name specified or implied by any of these special
131 -- Import_xxx or Export_xxx pragmas override an external or link name
132 -- specified in a previous Import or Export pragma.
134 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
135 -- named notation, following the standard rules for subprogram calls, i.e.
136 -- parameters can be given in any order if named notation is used, and
137 -- positional and named notation can be mixed, subject to the rule that all
138 -- positional parameters must appear first.
140 -- Note: All these pragmas are implemented exactly following the DEC design
141 -- and implementation and are intended to be fully compatible with the use
142 -- of these pragmas in the DEC Ada compiler.
144 --------------------------------------------
145 -- Checking for Duplicated External Names --
146 --------------------------------------------
148 -- It is suspicious if two separate Export pragmas use the same external
149 -- name. The following table is used to diagnose this situation so that
150 -- an appropriate warning can be issued.
152 -- The Node_Id stored is for the N_String_Literal node created to hold
153 -- the value of the external name. The Sloc of this node is used to
154 -- cross-reference the location of the duplication.
156 package Externals is new Table.Table (
157 Table_Component_Type => Node_Id,
158 Table_Index_Type => Int,
159 Table_Low_Bound => 0,
160 Table_Initial => 100,
161 Table_Increment => 100,
162 Table_Name => "Name_Externals");
164 -------------------------------------
165 -- Local Subprograms and Variables --
166 -------------------------------------
168 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id);
169 -- Subsidiary routine to the analysis of pragmas Depends, Global and
170 -- Refined_State. Append an entity to a list. If the list is empty, create
171 -- a new list.
173 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
174 -- This routine is used for possible casing adjustment of an explicit
175 -- external name supplied as a string literal (the node N), according to
176 -- the casing requirement of Opt.External_Name_Casing. If this is set to
177 -- As_Is, then the string literal is returned unchanged, but if it is set
178 -- to Uppercase or Lowercase, then a new string literal with appropriate
179 -- casing is constructed.
181 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
182 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
183 -- Query whether a particular item appears in a mixed list of nodes and
184 -- entities. It is assumed that all nodes in the list have entities.
186 function Check_Kind (Nam : Name_Id) return Name_Id;
187 -- This function is used in connection with pragmas Assert, Check,
188 -- and assertion aspects and pragmas, to determine if Check pragmas
189 -- (or corresponding assertion aspects or pragmas) are currently active
190 -- as determined by the presence of -gnata on the command line (which
191 -- sets the default), and the appearance of pragmas Check_Policy and
192 -- Assertion_Policy as configuration pragmas either in a configuration
193 -- pragma file, or at the start of the current unit, or locally given
194 -- Check_Policy and Assertion_Policy pragmas that are currently active.
196 -- The value returned is one of the names Check, Ignore, Disable (On
197 -- returns Check, and Off returns Ignore).
199 -- Note: for assertion kinds Pre'Class, Post'Class, Invariant'Class,
200 -- and Type_Invariant'Class, the name passed is Name_uPre, Name_uPost,
201 -- Name_uInvariant, or Name_uType_Invariant, which corresponds to _Pre,
202 -- _Post, _Invariant, or _Type_Invariant, which are special names used
203 -- in identifiers to represent these attribute references.
205 procedure Check_Postcondition_Use_In_Inlined_Subprogram
206 (Prag : Node_Id;
207 Spec_Id : Entity_Id);
208 -- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition,
209 -- Precondition, Refined_Post and Test_Case. Emit a warning when pragma
210 -- Prag is associated with subprogram Spec_Id subject to Inline_Always.
212 procedure Check_State_And_Constituent_Use
213 (States : Elist_Id;
214 Constits : Elist_Id;
215 Context : Node_Id);
216 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
217 -- Global and Initializes. Determine whether a state from list States and a
218 -- corresponding constituent from list Constits (if any) appear in the same
219 -- context denoted by Context. If this is the case, emit an error.
221 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id);
222 -- Subsidiary to routines Find_Related_Package_Or_Body and
223 -- Find_Related_Subprogram_Or_Body. Emit an error on pragma Prag that
224 -- duplicates previous pragma Prev.
226 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
227 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
228 -- original one, following the renaming chain) is returned. Otherwise the
229 -- entity is returned unchanged. Should be in Einfo???
231 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
232 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
233 -- Get_SPARK_Mode_Type. Convert a name into a corresponding value of type
234 -- SPARK_Mode_Type.
236 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
237 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
238 -- Determine whether dependency clause Clause is surrounded by extra
239 -- parentheses. If this is the case, issue an error message.
241 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
242 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
243 -- pragma Depends. Determine whether the type of dependency item Item is
244 -- tagged, unconstrained array, unconstrained record or a record with at
245 -- least one unconstrained component.
247 procedure Record_Possible_Body_Reference
248 (State_Id : Entity_Id;
249 Ref : Node_Id);
250 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
251 -- Global. Given an abstract state denoted by State_Id and a reference Ref
252 -- to it, determine whether the reference appears in a package body that
253 -- will eventually refine the state. If this is the case, record the
254 -- reference for future checks (see Analyze_Refined_State_In_Decls).
256 procedure Resolve_State (N : Node_Id);
257 -- Handle the overloading of state names by functions. When N denotes a
258 -- function, this routine finds the corresponding state and sets the entity
259 -- of N to that of the state.
261 procedure Rewrite_Assertion_Kind (N : Node_Id);
262 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
263 -- then it is rewritten as an identifier with the corresponding special
264 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
265 -- and Check_Policy.
267 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id);
268 -- Place semantic information on the argument of an Elaborate/Elaborate_All
269 -- pragma. Entity name for unit and its parents is taken from item in
270 -- previous with_clause that mentions the unit.
272 Dummy : Integer := 0;
273 pragma Volatile (Dummy);
274 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
276 procedure ip;
277 pragma No_Inline (ip);
278 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
279 -- is just to help debugging the front end. If a pragma Inspection_Point
280 -- is added to a source program, then breaking on ip will get you to that
281 -- point in the program.
283 procedure rv;
284 pragma No_Inline (rv);
285 -- This is a dummy function called by the processing for pragma Reviewable.
286 -- It is there for assisting front end debugging. By placing a Reviewable
287 -- pragma in the source program, a breakpoint on rv catches this place in
288 -- the source, allowing convenient stepping to the point of interest.
290 --------------
291 -- Add_Item --
292 --------------
294 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id) is
295 begin
296 Append_New_Elmt (Item, To => To_List);
297 end Add_Item;
299 -------------------------------
300 -- Adjust_External_Name_Case --
301 -------------------------------
303 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
304 CC : Char_Code;
306 begin
307 -- Adjust case of literal if required
309 if Opt.External_Name_Exp_Casing = As_Is then
310 return N;
312 else
313 -- Copy existing string
315 Start_String;
317 -- Set proper casing
319 for J in 1 .. String_Length (Strval (N)) loop
320 CC := Get_String_Char (Strval (N), J);
322 if Opt.External_Name_Exp_Casing = Uppercase
323 and then CC >= Get_Char_Code ('a')
324 and then CC <= Get_Char_Code ('z')
325 then
326 Store_String_Char (CC - 32);
328 elsif Opt.External_Name_Exp_Casing = Lowercase
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 else
335 Store_String_Char (CC);
336 end if;
337 end loop;
339 return
340 Make_String_Literal (Sloc (N),
341 Strval => End_String);
342 end if;
343 end Adjust_External_Name_Case;
345 -----------------------------------------
346 -- Analyze_Contract_Cases_In_Decl_Part --
347 -----------------------------------------
349 procedure Analyze_Contract_Cases_In_Decl_Part (N : Node_Id) is
350 Others_Seen : Boolean := False;
352 procedure Analyze_Contract_Case (CCase : Node_Id);
353 -- Verify the legality of a single contract case
355 ---------------------------
356 -- Analyze_Contract_Case --
357 ---------------------------
359 procedure Analyze_Contract_Case (CCase : Node_Id) is
360 Case_Guard : Node_Id;
361 Conseq : Node_Id;
362 Extra_Guard : Node_Id;
364 begin
365 if Nkind (CCase) = N_Component_Association then
366 Case_Guard := First (Choices (CCase));
367 Conseq := Expression (CCase);
369 -- Each contract case must have exactly one case guard
371 Extra_Guard := Next (Case_Guard);
373 if Present (Extra_Guard) then
374 Error_Msg_N
375 ("contract case must have exactly one case guard",
376 Extra_Guard);
377 end if;
379 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
381 if Nkind (Case_Guard) = N_Others_Choice then
382 if Others_Seen then
383 Error_Msg_N
384 ("only one others choice allowed in contract cases",
385 Case_Guard);
386 else
387 Others_Seen := True;
388 end if;
390 elsif Others_Seen then
391 Error_Msg_N
392 ("others must be the last choice in contract cases", N);
393 end if;
395 -- Preanalyze the case guard and consequence
397 if Nkind (Case_Guard) /= N_Others_Choice then
398 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
399 end if;
401 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
403 -- The contract case is malformed
405 else
406 Error_Msg_N ("wrong syntax in contract case", CCase);
407 end if;
408 end Analyze_Contract_Case;
410 -- Local variables
412 Subp_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
413 Spec_Id : constant Entity_Id := Corresponding_Spec_Of (Subp_Decl);
414 CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
416 CCase : Node_Id;
417 Restore_Scope : Boolean := False;
419 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
421 begin
422 Set_Analyzed (N);
424 -- Single and multiple contract cases must appear in aggregate form. If
425 -- this is not the case, then either the parser of the analysis of the
426 -- pragma failed to produce an aggregate.
428 pragma Assert (Nkind (CCases) = N_Aggregate);
430 if Present (Component_Associations (CCases)) then
432 -- Ensure that the formal parameters are visible when analyzing all
433 -- clauses. This falls out of the general rule of aspects pertaining
434 -- to subprogram declarations.
436 if not In_Open_Scopes (Spec_Id) then
437 Restore_Scope := True;
438 Push_Scope (Spec_Id);
440 if Is_Generic_Subprogram (Spec_Id) then
441 Install_Generic_Formals (Spec_Id);
442 else
443 Install_Formals (Spec_Id);
444 end if;
445 end if;
447 CCase := First (Component_Associations (CCases));
448 while Present (CCase) loop
449 Analyze_Contract_Case (CCase);
450 Next (CCase);
451 end loop;
453 if Restore_Scope then
454 End_Scope;
455 end if;
457 -- Currently it is not possible to inline pre/postconditions on a
458 -- subprogram subject to pragma Inline_Always.
460 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
462 -- Otherwise the pragma is illegal
464 else
465 Error_Msg_N ("wrong syntax for constract cases", N);
466 end if;
467 end Analyze_Contract_Cases_In_Decl_Part;
469 ----------------------------------
470 -- Analyze_Depends_In_Decl_Part --
471 ----------------------------------
473 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
474 Loc : constant Source_Ptr := Sloc (N);
475 Subp_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
476 Spec_Id : constant Entity_Id := Corresponding_Spec_Of (Subp_Decl);
478 All_Inputs_Seen : Elist_Id := No_Elist;
479 -- A list containing the entities of all the inputs processed so far.
480 -- The list is populated with unique entities because the same input
481 -- may appear in multiple input lists.
483 All_Outputs_Seen : Elist_Id := No_Elist;
484 -- A list containing the entities of all the outputs processed so far.
485 -- The list is populated with unique entities because output items are
486 -- unique in a dependence relation.
488 Constits_Seen : Elist_Id := No_Elist;
489 -- A list containing the entities of all constituents processed so far.
490 -- It aids in detecting illegal usage of a state and a corresponding
491 -- constituent in pragma [Refinde_]Depends.
493 Global_Seen : Boolean := False;
494 -- A flag set when pragma Global has been processed
496 Null_Output_Seen : Boolean := False;
497 -- A flag used to track the legality of a null output
499 Result_Seen : Boolean := False;
500 -- A flag set when Spec_Id'Result is processed
502 States_Seen : Elist_Id := No_Elist;
503 -- A list containing the entities of all states processed so far. It
504 -- helps in detecting illegal usage of a state and a corresponding
505 -- constituent in pragma [Refined_]Depends.
507 Subp_Inputs : Elist_Id := No_Elist;
508 Subp_Outputs : Elist_Id := No_Elist;
509 -- Two lists containing the full set of inputs and output of the related
510 -- subprograms. Note that these lists contain both nodes and entities.
512 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
513 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
514 -- to the name buffer. The individual kinds are as follows:
515 -- E_Abstract_State - "state"
516 -- E_Constant - "constant"
517 -- E_Generic_In_Out_Parameter - "generic parameter"
518 -- E_Generic_Out_Parameter - "generic parameter"
519 -- E_In_Parameter - "parameter"
520 -- E_In_Out_Parameter - "parameter"
521 -- E_Out_Parameter - "parameter"
522 -- E_Variable - "global"
524 procedure Analyze_Dependency_Clause
525 (Clause : Node_Id;
526 Is_Last : Boolean);
527 -- Verify the legality of a single dependency clause. Flag Is_Last
528 -- denotes whether Clause is the last clause in the relation.
530 procedure Check_Function_Return;
531 -- Verify that Funtion'Result appears as one of the outputs
532 -- (SPARK RM 6.1.5(10)).
534 procedure Check_Role
535 (Item : Node_Id;
536 Item_Id : Entity_Id;
537 Is_Input : Boolean;
538 Self_Ref : Boolean);
539 -- Ensure that an item fulfils its designated input and/or output role
540 -- as specified by pragma Global (if any) or the enclosing context. If
541 -- this is not the case, emit an error. Item and Item_Id denote the
542 -- attributes of an item. Flag Is_Input should be set when item comes
543 -- from an input list. Flag Self_Ref should be set when the item is an
544 -- output and the dependency clause has operator "+".
546 procedure Check_Usage
547 (Subp_Items : Elist_Id;
548 Used_Items : Elist_Id;
549 Is_Input : Boolean);
550 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
551 -- error if this is not the case.
553 procedure Normalize_Clause (Clause : Node_Id);
554 -- Remove a self-dependency "+" from the input list of a clause
556 -----------------------------
557 -- Add_Item_To_Name_Buffer --
558 -----------------------------
560 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
561 begin
562 if Ekind (Item_Id) = E_Abstract_State then
563 Add_Str_To_Name_Buffer ("state");
565 elsif Ekind (Item_Id) = E_Constant then
566 Add_Str_To_Name_Buffer ("constant");
568 elsif Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
569 E_Generic_In_Parameter)
570 then
571 Add_Str_To_Name_Buffer ("generic parameter");
573 elsif Is_Formal (Item_Id) then
574 Add_Str_To_Name_Buffer ("parameter");
576 elsif Ekind (Item_Id) = E_Variable then
577 Add_Str_To_Name_Buffer ("global");
579 -- The routine should not be called with non-SPARK items
581 else
582 raise Program_Error;
583 end if;
584 end Add_Item_To_Name_Buffer;
586 -------------------------------
587 -- Analyze_Dependency_Clause --
588 -------------------------------
590 procedure Analyze_Dependency_Clause
591 (Clause : Node_Id;
592 Is_Last : Boolean)
594 procedure Analyze_Input_List (Inputs : Node_Id);
595 -- Verify the legality of a single input list
597 procedure Analyze_Input_Output
598 (Item : Node_Id;
599 Is_Input : Boolean;
600 Self_Ref : Boolean;
601 Top_Level : Boolean;
602 Seen : in out Elist_Id;
603 Null_Seen : in out Boolean;
604 Non_Null_Seen : in out Boolean);
605 -- Verify the legality of a single input or output item. Flag
606 -- Is_Input should be set whenever Item is an input, False when it
607 -- denotes an output. Flag Self_Ref should be set when the item is an
608 -- output and the dependency clause has a "+". Flag Top_Level should
609 -- be set whenever Item appears immediately within an input or output
610 -- list. Seen is a collection of all abstract states, objects and
611 -- formals processed so far. Flag Null_Seen denotes whether a null
612 -- input or output has been encountered. Flag Non_Null_Seen denotes
613 -- whether a non-null input or output has been encountered.
615 ------------------------
616 -- Analyze_Input_List --
617 ------------------------
619 procedure Analyze_Input_List (Inputs : Node_Id) is
620 Inputs_Seen : Elist_Id := No_Elist;
621 -- A list containing the entities of all inputs that appear in the
622 -- current input list.
624 Non_Null_Input_Seen : Boolean := False;
625 Null_Input_Seen : Boolean := False;
626 -- Flags used to check the legality of an input list
628 Input : Node_Id;
630 begin
631 -- Multiple inputs appear as an aggregate
633 if Nkind (Inputs) = N_Aggregate then
634 if Present (Component_Associations (Inputs)) then
635 SPARK_Msg_N
636 ("nested dependency relations not allowed", Inputs);
638 elsif Present (Expressions (Inputs)) then
639 Input := First (Expressions (Inputs));
640 while Present (Input) loop
641 Analyze_Input_Output
642 (Item => Input,
643 Is_Input => True,
644 Self_Ref => False,
645 Top_Level => False,
646 Seen => Inputs_Seen,
647 Null_Seen => Null_Input_Seen,
648 Non_Null_Seen => Non_Null_Input_Seen);
650 Next (Input);
651 end loop;
653 -- Syntax error, always report
655 else
656 Error_Msg_N ("malformed input dependency list", Inputs);
657 end if;
659 -- Process a solitary input
661 else
662 Analyze_Input_Output
663 (Item => Inputs,
664 Is_Input => True,
665 Self_Ref => False,
666 Top_Level => False,
667 Seen => Inputs_Seen,
668 Null_Seen => Null_Input_Seen,
669 Non_Null_Seen => Non_Null_Input_Seen);
670 end if;
672 -- Detect an illegal dependency clause of the form
674 -- (null =>[+] null)
676 if Null_Output_Seen and then Null_Input_Seen then
677 SPARK_Msg_N
678 ("null dependency clause cannot have a null input list",
679 Inputs);
680 end if;
681 end Analyze_Input_List;
683 --------------------------
684 -- Analyze_Input_Output --
685 --------------------------
687 procedure Analyze_Input_Output
688 (Item : Node_Id;
689 Is_Input : Boolean;
690 Self_Ref : Boolean;
691 Top_Level : Boolean;
692 Seen : in out Elist_Id;
693 Null_Seen : in out Boolean;
694 Non_Null_Seen : in out Boolean)
696 Is_Output : constant Boolean := not Is_Input;
697 Grouped : Node_Id;
698 Item_Id : Entity_Id;
700 begin
701 -- Multiple input or output items appear as an aggregate
703 if Nkind (Item) = N_Aggregate then
704 if not Top_Level then
705 SPARK_Msg_N ("nested grouping of items not allowed", Item);
707 elsif Present (Component_Associations (Item)) then
708 SPARK_Msg_N
709 ("nested dependency relations not allowed", Item);
711 -- Recursively analyze the grouped items
713 elsif Present (Expressions (Item)) then
714 Grouped := First (Expressions (Item));
715 while Present (Grouped) loop
716 Analyze_Input_Output
717 (Item => Grouped,
718 Is_Input => Is_Input,
719 Self_Ref => Self_Ref,
720 Top_Level => False,
721 Seen => Seen,
722 Null_Seen => Null_Seen,
723 Non_Null_Seen => Non_Null_Seen);
725 Next (Grouped);
726 end loop;
728 -- Syntax error, always report
730 else
731 Error_Msg_N ("malformed dependency list", Item);
732 end if;
734 -- Process attribute 'Result in the context of a dependency clause
736 elsif Is_Attribute_Result (Item) then
737 Non_Null_Seen := True;
739 Analyze (Item);
741 -- Attribute 'Result is allowed to appear on the output side of
742 -- a dependency clause (SPARK RM 6.1.5(6)).
744 if Is_Input then
745 SPARK_Msg_N ("function result cannot act as input", Item);
747 elsif Null_Seen then
748 SPARK_Msg_N
749 ("cannot mix null and non-null dependency items", Item);
751 else
752 Result_Seen := True;
753 end if;
755 -- Detect multiple uses of null in a single dependency list or
756 -- throughout the whole relation. Verify the placement of a null
757 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
759 elsif Nkind (Item) = N_Null then
760 if Null_Seen then
761 SPARK_Msg_N
762 ("multiple null dependency relations not allowed", Item);
764 elsif Non_Null_Seen then
765 SPARK_Msg_N
766 ("cannot mix null and non-null dependency items", Item);
768 else
769 Null_Seen := True;
771 if Is_Output then
772 if not Is_Last then
773 SPARK_Msg_N
774 ("null output list must be the last clause in a "
775 & "dependency relation", Item);
777 -- Catch a useless dependence of the form:
778 -- null =>+ ...
780 elsif Self_Ref then
781 SPARK_Msg_N
782 ("useless dependence, null depends on itself", Item);
783 end if;
784 end if;
785 end if;
787 -- Default case
789 else
790 Non_Null_Seen := True;
792 if Null_Seen then
793 SPARK_Msg_N ("cannot mix null and non-null items", Item);
794 end if;
796 Analyze (Item);
797 Resolve_State (Item);
799 -- Find the entity of the item. If this is a renaming, climb
800 -- the renaming chain to reach the root object. Renamings of
801 -- non-entire objects do not yield an entity (Empty).
803 Item_Id := Entity_Of (Item);
805 if Present (Item_Id) then
806 if Ekind_In (Item_Id, E_Abstract_State,
807 E_Constant,
808 E_Generic_In_Out_Parameter,
809 E_Generic_In_Parameter,
810 E_In_Parameter,
811 E_In_Out_Parameter,
812 E_Out_Parameter,
813 E_Variable)
814 then
815 -- Ensure that the item fulfils its role as input and/or
816 -- output as specified by pragma Global or the enclosing
817 -- context.
819 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
821 -- Detect multiple uses of the same state, variable or
822 -- formal parameter. If this is not the case, add the
823 -- item to the list of processed relations.
825 if Contains (Seen, Item_Id) then
826 SPARK_Msg_NE
827 ("duplicate use of item &", Item, Item_Id);
828 else
829 Add_Item (Item_Id, Seen);
830 end if;
832 -- Detect illegal use of an input related to a null
833 -- output. Such input items cannot appear in other
834 -- input lists (SPARK RM 6.1.5(13)).
836 if Is_Input
837 and then Null_Output_Seen
838 and then Contains (All_Inputs_Seen, Item_Id)
839 then
840 SPARK_Msg_N
841 ("input of a null output list cannot appear in "
842 & "multiple input lists", Item);
843 end if;
845 -- Add an input or a self-referential output to the list
846 -- of all processed inputs.
848 if Is_Input or else Self_Ref then
849 Add_Item (Item_Id, All_Inputs_Seen);
850 end if;
852 -- State related checks (SPARK RM 6.1.5(3))
854 if Ekind (Item_Id) = E_Abstract_State then
856 -- Package and subprogram bodies are instantiated
857 -- individually in a separate compiler pass. Due to
858 -- this mode of instantiation, the refinement of a
859 -- state may no longer be visible when a subprogram
860 -- body contract is instantiated. Since the generic
861 -- template is legal, do not perform this check in
862 -- the instance to circumvent this oddity.
864 if Is_Generic_Instance (Spec_Id) then
865 null;
867 -- An abstract state with visible refinement cannot
868 -- appear in pragma [Refined_]Depends as its place
869 -- must be taken by some of its constituents
870 -- (SPARK RM 6.1.4(7)).
872 elsif Has_Visible_Refinement (Item_Id) then
873 SPARK_Msg_NE
874 ("cannot mention state & in dependence relation",
875 Item, Item_Id);
876 SPARK_Msg_N ("\use its constituents instead", Item);
877 return;
879 -- If the reference to the abstract state appears in
880 -- an enclosing package body that will eventually
881 -- refine the state, record the reference for future
882 -- checks.
884 else
885 Record_Possible_Body_Reference
886 (State_Id => Item_Id,
887 Ref => Item);
888 end if;
889 end if;
891 -- When the item renames an entire object, replace the
892 -- item with a reference to the object.
894 if Entity (Item) /= Item_Id then
895 Rewrite (Item,
896 New_Occurrence_Of (Item_Id, Sloc (Item)));
897 Analyze (Item);
898 end if;
900 -- Add the entity of the current item to the list of
901 -- processed items.
903 if Ekind (Item_Id) = E_Abstract_State then
904 Add_Item (Item_Id, States_Seen);
905 end if;
907 if Ekind_In (Item_Id, E_Abstract_State,
908 E_Constant,
909 E_Variable)
910 and then Present (Encapsulating_State (Item_Id))
911 then
912 Add_Item (Item_Id, Constits_Seen);
913 end if;
915 -- All other input/output items are illegal
916 -- (SPARK RM 6.1.5(1)).
918 else
919 SPARK_Msg_N
920 ("item must denote parameter, variable, or state",
921 Item);
922 end if;
924 -- All other input/output items are illegal
925 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
927 else
928 Error_Msg_N
929 ("item must denote parameter, variable, or state", Item);
930 end if;
931 end if;
932 end Analyze_Input_Output;
934 -- Local variables
936 Inputs : Node_Id;
937 Output : Node_Id;
938 Self_Ref : Boolean;
940 Non_Null_Output_Seen : Boolean := False;
941 -- Flag used to check the legality of an output list
943 -- Start of processing for Analyze_Dependency_Clause
945 begin
946 Inputs := Expression (Clause);
947 Self_Ref := False;
949 -- An input list with a self-dependency appears as operator "+" where
950 -- the actuals inputs are the right operand.
952 if Nkind (Inputs) = N_Op_Plus then
953 Inputs := Right_Opnd (Inputs);
954 Self_Ref := True;
955 end if;
957 -- Process the output_list of a dependency_clause
959 Output := First (Choices (Clause));
960 while Present (Output) loop
961 Analyze_Input_Output
962 (Item => Output,
963 Is_Input => False,
964 Self_Ref => Self_Ref,
965 Top_Level => True,
966 Seen => All_Outputs_Seen,
967 Null_Seen => Null_Output_Seen,
968 Non_Null_Seen => Non_Null_Output_Seen);
970 Next (Output);
971 end loop;
973 -- Process the input_list of a dependency_clause
975 Analyze_Input_List (Inputs);
976 end Analyze_Dependency_Clause;
978 ---------------------------
979 -- Check_Function_Return --
980 ---------------------------
982 procedure Check_Function_Return is
983 begin
984 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
985 and then not Result_Seen
986 then
987 SPARK_Msg_NE
988 ("result of & must appear in exactly one output list",
989 N, Spec_Id);
990 end if;
991 end Check_Function_Return;
993 ----------------
994 -- Check_Role --
995 ----------------
997 procedure Check_Role
998 (Item : Node_Id;
999 Item_Id : Entity_Id;
1000 Is_Input : Boolean;
1001 Self_Ref : Boolean)
1003 procedure Find_Role
1004 (Item_Is_Input : out Boolean;
1005 Item_Is_Output : out Boolean);
1006 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1007 -- Item_Is_Output are set depending on the role.
1009 procedure Role_Error
1010 (Item_Is_Input : Boolean;
1011 Item_Is_Output : Boolean);
1012 -- Emit an error message concerning the incorrect use of Item in
1013 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1014 -- denote whether the item is an input and/or an output.
1016 ---------------
1017 -- Find_Role --
1018 ---------------
1020 procedure Find_Role
1021 (Item_Is_Input : out Boolean;
1022 Item_Is_Output : out Boolean)
1024 begin
1025 Item_Is_Input := False;
1026 Item_Is_Output := False;
1028 -- Abstract state cases
1030 if Ekind (Item_Id) = E_Abstract_State then
1032 -- When pragma Global is present, the mode of the state may be
1033 -- further constrained by setting a more restrictive mode.
1035 if Global_Seen then
1036 if Appears_In (Subp_Inputs, Item_Id) then
1037 Item_Is_Input := True;
1038 end if;
1040 if Appears_In (Subp_Outputs, Item_Id) then
1041 Item_Is_Output := True;
1042 end if;
1044 -- Otherwise the state has a default IN OUT mode
1046 else
1047 Item_Is_Input := True;
1048 Item_Is_Output := True;
1049 end if;
1051 -- Constant case
1053 elsif Ekind (Item_Id) = E_Constant then
1054 Item_Is_Input := True;
1056 -- Generic parameter cases
1058 elsif Ekind (Item_Id) = E_Generic_In_Parameter then
1059 Item_Is_Input := True;
1061 elsif Ekind (Item_Id) = E_Generic_In_Out_Parameter then
1062 Item_Is_Input := True;
1063 Item_Is_Output := True;
1065 -- Parameter cases
1067 elsif Ekind (Item_Id) = E_In_Parameter then
1068 Item_Is_Input := True;
1070 elsif Ekind (Item_Id) = E_In_Out_Parameter then
1071 Item_Is_Input := True;
1072 Item_Is_Output := True;
1074 elsif Ekind (Item_Id) = E_Out_Parameter then
1075 if Scope (Item_Id) = Spec_Id then
1077 -- An OUT parameter of the related subprogram has mode IN
1078 -- if its type is unconstrained or tagged because array
1079 -- bounds, discriminants or tags can be read.
1081 if Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1082 Item_Is_Input := True;
1083 end if;
1085 Item_Is_Output := True;
1087 -- An OUT parameter of an enclosing subprogram behaves as a
1088 -- read-write variable in which case the mode is IN OUT.
1090 else
1091 Item_Is_Input := True;
1092 Item_Is_Output := True;
1093 end if;
1095 -- Variable case
1097 else pragma Assert (Ekind (Item_Id) = E_Variable);
1099 -- When pragma Global is present, the mode of the variable may
1100 -- be further constrained by setting a more restrictive mode.
1102 if Global_Seen then
1104 -- A variable has mode IN when its type is unconstrained or
1105 -- tagged because array bounds, discriminants or tags can be
1106 -- read.
1108 if Appears_In (Subp_Inputs, Item_Id)
1109 or else Is_Unconstrained_Or_Tagged_Item (Item_Id)
1110 then
1111 Item_Is_Input := True;
1112 end if;
1114 if Appears_In (Subp_Outputs, Item_Id) then
1115 Item_Is_Output := True;
1116 end if;
1118 -- Otherwise the variable has a default IN OUT mode
1120 else
1121 Item_Is_Input := True;
1122 Item_Is_Output := True;
1123 end if;
1124 end if;
1125 end Find_Role;
1127 ----------------
1128 -- Role_Error --
1129 ----------------
1131 procedure Role_Error
1132 (Item_Is_Input : Boolean;
1133 Item_Is_Output : Boolean)
1135 Error_Msg : Name_Id;
1137 begin
1138 Name_Len := 0;
1140 -- When the item is not part of the input and the output set of
1141 -- the related subprogram, then it appears as extra in pragma
1142 -- [Refined_]Depends.
1144 if not Item_Is_Input and then not Item_Is_Output then
1145 Add_Item_To_Name_Buffer (Item_Id);
1146 Add_Str_To_Name_Buffer
1147 (" & cannot appear in dependence relation");
1149 Error_Msg := Name_Find;
1150 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1152 Error_Msg_Name_1 := Chars (Spec_Id);
1153 SPARK_Msg_NE
1154 ("\& is not part of the input or output set of subprogram %",
1155 Item, Item_Id);
1157 -- The mode of the item and its role in pragma [Refined_]Depends
1158 -- are in conflict. Construct a detailed message explaining the
1159 -- illegality (SPARK RM 6.1.5(5-6)).
1161 else
1162 if Item_Is_Input then
1163 Add_Str_To_Name_Buffer ("read-only");
1164 else
1165 Add_Str_To_Name_Buffer ("write-only");
1166 end if;
1168 Add_Char_To_Name_Buffer (' ');
1169 Add_Item_To_Name_Buffer (Item_Id);
1170 Add_Str_To_Name_Buffer (" & cannot appear as ");
1172 if Item_Is_Input then
1173 Add_Str_To_Name_Buffer ("output");
1174 else
1175 Add_Str_To_Name_Buffer ("input");
1176 end if;
1178 Add_Str_To_Name_Buffer (" in dependence relation");
1179 Error_Msg := Name_Find;
1180 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1181 end if;
1182 end Role_Error;
1184 -- Local variables
1186 Item_Is_Input : Boolean;
1187 Item_Is_Output : Boolean;
1189 -- Start of processing for Check_Role
1191 begin
1192 Find_Role (Item_Is_Input, Item_Is_Output);
1194 -- Input item
1196 if Is_Input then
1197 if not Item_Is_Input then
1198 Role_Error (Item_Is_Input, Item_Is_Output);
1199 end if;
1201 -- Self-referential item
1203 elsif Self_Ref then
1204 if not Item_Is_Input or else not Item_Is_Output then
1205 Role_Error (Item_Is_Input, Item_Is_Output);
1206 end if;
1208 -- Output item
1210 elsif not Item_Is_Output then
1211 Role_Error (Item_Is_Input, Item_Is_Output);
1212 end if;
1213 end Check_Role;
1215 -----------------
1216 -- Check_Usage --
1217 -----------------
1219 procedure Check_Usage
1220 (Subp_Items : Elist_Id;
1221 Used_Items : Elist_Id;
1222 Is_Input : Boolean)
1224 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id);
1225 -- Emit an error concerning the illegal usage of an item
1227 -----------------
1228 -- Usage_Error --
1229 -----------------
1231 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id) is
1232 Error_Msg : Name_Id;
1234 begin
1235 -- Input case
1237 if Is_Input then
1239 -- Unconstrained and tagged items are not part of the explicit
1240 -- input set of the related subprogram, they do not have to be
1241 -- present in a dependence relation and should not be flagged
1242 -- (SPARK RM 6.1.5(8)).
1244 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1245 Name_Len := 0;
1247 Add_Item_To_Name_Buffer (Item_Id);
1248 Add_Str_To_Name_Buffer
1249 (" & must appear in at least one input dependence list");
1251 Error_Msg := Name_Find;
1252 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1253 end if;
1255 -- Output case (SPARK RM 6.1.5(10))
1257 else
1258 Name_Len := 0;
1260 Add_Item_To_Name_Buffer (Item_Id);
1261 Add_Str_To_Name_Buffer
1262 (" & must appear in exactly one output dependence list");
1264 Error_Msg := Name_Find;
1265 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1266 end if;
1267 end Usage_Error;
1269 -- Local variables
1271 Elmt : Elmt_Id;
1272 Item : Node_Id;
1273 Item_Id : Entity_Id;
1275 -- Start of processing for Check_Usage
1277 begin
1278 if No (Subp_Items) then
1279 return;
1280 end if;
1282 -- Each input or output of the subprogram must appear in a dependency
1283 -- relation.
1285 Elmt := First_Elmt (Subp_Items);
1286 while Present (Elmt) loop
1287 Item := Node (Elmt);
1289 if Nkind (Item) = N_Defining_Identifier then
1290 Item_Id := Item;
1291 else
1292 Item_Id := Entity_Of (Item);
1293 end if;
1295 -- The item does not appear in a dependency
1297 if Present (Item_Id)
1298 and then not Contains (Used_Items, Item_Id)
1299 then
1300 if Is_Formal (Item_Id) then
1301 Usage_Error (Item, Item_Id);
1303 -- States and global objects are not used properly only when
1304 -- the subprogram is subject to pragma Global.
1306 elsif Global_Seen then
1307 Usage_Error (Item, Item_Id);
1308 end if;
1309 end if;
1311 Next_Elmt (Elmt);
1312 end loop;
1313 end Check_Usage;
1315 ----------------------
1316 -- Normalize_Clause --
1317 ----------------------
1319 procedure Normalize_Clause (Clause : Node_Id) is
1320 procedure Create_Or_Modify_Clause
1321 (Output : Node_Id;
1322 Outputs : Node_Id;
1323 Inputs : Node_Id;
1324 After : Node_Id;
1325 In_Place : Boolean;
1326 Multiple : Boolean);
1327 -- Create a brand new clause to represent the self-reference or
1328 -- modify the input and/or output lists of an existing clause. Output
1329 -- denotes a self-referencial output. Outputs is the output list of a
1330 -- clause. Inputs is the input list of a clause. After denotes the
1331 -- clause after which the new clause is to be inserted. Flag In_Place
1332 -- should be set when normalizing the last output of an output list.
1333 -- Flag Multiple should be set when Output comes from a list with
1334 -- multiple items.
1336 -----------------------------
1337 -- Create_Or_Modify_Clause --
1338 -----------------------------
1340 procedure Create_Or_Modify_Clause
1341 (Output : Node_Id;
1342 Outputs : Node_Id;
1343 Inputs : Node_Id;
1344 After : Node_Id;
1345 In_Place : Boolean;
1346 Multiple : Boolean)
1348 procedure Propagate_Output
1349 (Output : Node_Id;
1350 Inputs : Node_Id);
1351 -- Handle the various cases of output propagation to the input
1352 -- list. Output denotes a self-referencial output item. Inputs
1353 -- is the input list of a clause.
1355 ----------------------
1356 -- Propagate_Output --
1357 ----------------------
1359 procedure Propagate_Output
1360 (Output : Node_Id;
1361 Inputs : Node_Id)
1363 function In_Input_List
1364 (Item : Entity_Id;
1365 Inputs : List_Id) return Boolean;
1366 -- Determine whether a particulat item appears in the input
1367 -- list of a clause.
1369 -------------------
1370 -- In_Input_List --
1371 -------------------
1373 function In_Input_List
1374 (Item : Entity_Id;
1375 Inputs : List_Id) return Boolean
1377 Elmt : Node_Id;
1379 begin
1380 Elmt := First (Inputs);
1381 while Present (Elmt) loop
1382 if Entity_Of (Elmt) = Item then
1383 return True;
1384 end if;
1386 Next (Elmt);
1387 end loop;
1389 return False;
1390 end In_Input_List;
1392 -- Local variables
1394 Output_Id : constant Entity_Id := Entity_Of (Output);
1395 Grouped : List_Id;
1397 -- Start of processing for Propagate_Output
1399 begin
1400 -- The clause is of the form:
1402 -- (Output =>+ null)
1404 -- Remove null input and replace it with a copy of the output:
1406 -- (Output => Output)
1408 if Nkind (Inputs) = N_Null then
1409 Rewrite (Inputs, New_Copy_Tree (Output));
1411 -- The clause is of the form:
1413 -- (Output =>+ (Input1, ..., InputN))
1415 -- Determine whether the output is not already mentioned in the
1416 -- input list and if not, add it to the list of inputs:
1418 -- (Output => (Output, Input1, ..., InputN))
1420 elsif Nkind (Inputs) = N_Aggregate then
1421 Grouped := Expressions (Inputs);
1423 if not In_Input_List
1424 (Item => Output_Id,
1425 Inputs => Grouped)
1426 then
1427 Prepend_To (Grouped, New_Copy_Tree (Output));
1428 end if;
1430 -- The clause is of the form:
1432 -- (Output =>+ Input)
1434 -- If the input does not mention the output, group the two
1435 -- together:
1437 -- (Output => (Output, Input))
1439 elsif Entity_Of (Inputs) /= Output_Id then
1440 Rewrite (Inputs,
1441 Make_Aggregate (Loc,
1442 Expressions => New_List (
1443 New_Copy_Tree (Output),
1444 New_Copy_Tree (Inputs))));
1445 end if;
1446 end Propagate_Output;
1448 -- Local variables
1450 Loc : constant Source_Ptr := Sloc (Clause);
1451 New_Clause : Node_Id;
1453 -- Start of processing for Create_Or_Modify_Clause
1455 begin
1456 -- A null output depending on itself does not require any
1457 -- normalization.
1459 if Nkind (Output) = N_Null then
1460 return;
1462 -- A function result cannot depend on itself because it cannot
1463 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1465 elsif Is_Attribute_Result (Output) then
1466 SPARK_Msg_N ("function result cannot depend on itself", Output);
1467 return;
1468 end if;
1470 -- When performing the transformation in place, simply add the
1471 -- output to the list of inputs (if not already there). This
1472 -- case arises when dealing with the last output of an output
1473 -- list. Perform the normalization in place to avoid generating
1474 -- a malformed tree.
1476 if In_Place then
1477 Propagate_Output (Output, Inputs);
1479 -- A list with multiple outputs is slowly trimmed until only
1480 -- one element remains. When this happens, replace aggregate
1481 -- with the element itself.
1483 if Multiple then
1484 Remove (Output);
1485 Rewrite (Outputs, Output);
1486 end if;
1488 -- Default case
1490 else
1491 -- Unchain the output from its output list as it will appear in
1492 -- a new clause. Note that we cannot simply rewrite the output
1493 -- as null because this will violate the semantics of pragma
1494 -- Depends.
1496 Remove (Output);
1498 -- Generate a new clause of the form:
1499 -- (Output => Inputs)
1501 New_Clause :=
1502 Make_Component_Association (Loc,
1503 Choices => New_List (Output),
1504 Expression => New_Copy_Tree (Inputs));
1506 -- The new clause contains replicated content that has already
1507 -- been analyzed. There is not need to reanalyze or renormalize
1508 -- it again.
1510 Set_Analyzed (New_Clause);
1512 Propagate_Output
1513 (Output => First (Choices (New_Clause)),
1514 Inputs => Expression (New_Clause));
1516 Insert_After (After, New_Clause);
1517 end if;
1518 end Create_Or_Modify_Clause;
1520 -- Local variables
1522 Outputs : constant Node_Id := First (Choices (Clause));
1523 Inputs : Node_Id;
1524 Last_Output : Node_Id;
1525 Next_Output : Node_Id;
1526 Output : Node_Id;
1528 -- Start of processing for Normalize_Clause
1530 begin
1531 -- A self-dependency appears as operator "+". Remove the "+" from the
1532 -- tree by moving the real inputs to their proper place.
1534 if Nkind (Expression (Clause)) = N_Op_Plus then
1535 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1536 Inputs := Expression (Clause);
1538 -- Multiple outputs appear as an aggregate
1540 if Nkind (Outputs) = N_Aggregate then
1541 Last_Output := Last (Expressions (Outputs));
1543 Output := First (Expressions (Outputs));
1544 while Present (Output) loop
1546 -- Normalization may remove an output from its list,
1547 -- preserve the subsequent output now.
1549 Next_Output := Next (Output);
1551 Create_Or_Modify_Clause
1552 (Output => Output,
1553 Outputs => Outputs,
1554 Inputs => Inputs,
1555 After => Clause,
1556 In_Place => Output = Last_Output,
1557 Multiple => True);
1559 Output := Next_Output;
1560 end loop;
1562 -- Solitary output
1564 else
1565 Create_Or_Modify_Clause
1566 (Output => Outputs,
1567 Outputs => Empty,
1568 Inputs => Inputs,
1569 After => Empty,
1570 In_Place => True,
1571 Multiple => False);
1572 end if;
1573 end if;
1574 end Normalize_Clause;
1576 -- Local variables
1578 Deps : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
1579 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
1581 Clause : Node_Id;
1582 Errors : Nat;
1583 Last_Clause : Node_Id;
1584 Restore_Scope : Boolean := False;
1586 -- Start of processing for Analyze_Depends_In_Decl_Part
1588 begin
1589 Set_Analyzed (N);
1591 -- Empty dependency list
1593 if Nkind (Deps) = N_Null then
1595 -- Gather all states, objects and formal parameters that the
1596 -- subprogram may depend on. These items are obtained from the
1597 -- parameter profile or pragma [Refined_]Global (if available).
1599 Collect_Subprogram_Inputs_Outputs
1600 (Subp_Id => Subp_Id,
1601 Subp_Inputs => Subp_Inputs,
1602 Subp_Outputs => Subp_Outputs,
1603 Global_Seen => Global_Seen);
1605 -- Verify that every input or output of the subprogram appear in a
1606 -- dependency.
1608 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1609 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1610 Check_Function_Return;
1612 -- Dependency clauses appear as component associations of an aggregate
1614 elsif Nkind (Deps) = N_Aggregate then
1616 -- Do not attempt to perform analysis of a syntactically illegal
1617 -- clause as this will lead to misleading errors.
1619 if Has_Extra_Parentheses (Deps) then
1620 return;
1621 end if;
1623 if Present (Component_Associations (Deps)) then
1624 Last_Clause := Last (Component_Associations (Deps));
1626 -- Gather all states, objects and formal parameters that the
1627 -- subprogram may depend on. These items are obtained from the
1628 -- parameter profile or pragma [Refined_]Global (if available).
1630 Collect_Subprogram_Inputs_Outputs
1631 (Subp_Id => Subp_Id,
1632 Subp_Inputs => Subp_Inputs,
1633 Subp_Outputs => Subp_Outputs,
1634 Global_Seen => Global_Seen);
1636 -- Ensure that the formal parameters are visible when analyzing
1637 -- all clauses. This falls out of the general rule of aspects
1638 -- pertaining to subprogram declarations.
1640 if not In_Open_Scopes (Spec_Id) then
1641 Restore_Scope := True;
1642 Push_Scope (Spec_Id);
1644 if Is_Generic_Subprogram (Spec_Id) then
1645 Install_Generic_Formals (Spec_Id);
1646 else
1647 Install_Formals (Spec_Id);
1648 end if;
1649 end if;
1651 Clause := First (Component_Associations (Deps));
1652 while Present (Clause) loop
1653 Errors := Serious_Errors_Detected;
1655 -- The normalization mechanism may create extra clauses that
1656 -- contain replicated input and output names. There is no need
1657 -- to reanalyze them.
1659 if not Analyzed (Clause) then
1660 Set_Analyzed (Clause);
1662 Analyze_Dependency_Clause
1663 (Clause => Clause,
1664 Is_Last => Clause = Last_Clause);
1665 end if;
1667 -- Do not normalize a clause if errors were detected (count
1668 -- of Serious_Errors has increased) because the inputs and/or
1669 -- outputs may denote illegal items. Normalization is disabled
1670 -- in ASIS mode as it alters the tree by introducing new nodes
1671 -- similar to expansion.
1673 if Serious_Errors_Detected = Errors and then not ASIS_Mode then
1674 Normalize_Clause (Clause);
1675 end if;
1677 Next (Clause);
1678 end loop;
1680 if Restore_Scope then
1681 End_Scope;
1682 end if;
1684 -- Verify that every input or output of the subprogram appear in a
1685 -- dependency.
1687 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1688 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1689 Check_Function_Return;
1691 -- The dependency list is malformed. This is a syntax error, always
1692 -- report.
1694 else
1695 Error_Msg_N ("malformed dependency relation", Deps);
1696 return;
1697 end if;
1699 -- The top level dependency relation is malformed. This is a syntax
1700 -- error, always report.
1702 else
1703 Error_Msg_N ("malformed dependency relation", Deps);
1704 return;
1705 end if;
1707 -- Ensure that a state and a corresponding constituent do not appear
1708 -- together in pragma [Refined_]Depends.
1710 Check_State_And_Constituent_Use
1711 (States => States_Seen,
1712 Constits => Constits_Seen,
1713 Context => N);
1714 end Analyze_Depends_In_Decl_Part;
1716 --------------------------------------------
1717 -- Analyze_External_Property_In_Decl_Part --
1718 --------------------------------------------
1720 procedure Analyze_External_Property_In_Decl_Part
1721 (N : Node_Id;
1722 Expr_Val : out Boolean)
1724 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
1725 Obj_Id : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
1726 Expr : constant Node_Id := Get_Pragma_Arg (Next (Arg1));
1728 begin
1729 Error_Msg_Name_1 := Pragma_Name (N);
1731 -- An external property pragma must apply to an effectively volatile
1732 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
1733 -- The check is performed at the end of the declarative region due to a
1734 -- possible out-of-order arrangement of pragmas:
1736 -- Obj : ...;
1737 -- pragma Async_Readers (Obj);
1738 -- pragma Volatile (Obj);
1740 if not Is_Effectively_Volatile (Obj_Id) then
1741 SPARK_Msg_N
1742 ("external property % must apply to a volatile object", N);
1743 end if;
1745 -- Ensure that the Boolean expression (if present) is static. A missing
1746 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
1748 Expr_Val := True;
1750 if Present (Expr) then
1751 Analyze_And_Resolve (Expr, Standard_Boolean);
1753 if Is_OK_Static_Expression (Expr) then
1754 Expr_Val := Is_True (Expr_Value (Expr));
1755 else
1756 SPARK_Msg_N ("expression of % must be static", Expr);
1757 end if;
1758 end if;
1759 end Analyze_External_Property_In_Decl_Part;
1761 ---------------------------------
1762 -- Analyze_Global_In_Decl_Part --
1763 ---------------------------------
1765 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
1766 Subp_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
1767 Spec_Id : constant Entity_Id := Corresponding_Spec_Of (Subp_Decl);
1768 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
1770 Constits_Seen : Elist_Id := No_Elist;
1771 -- A list containing the entities of all constituents processed so far.
1772 -- It aids in detecting illegal usage of a state and a corresponding
1773 -- constituent in pragma [Refinde_]Global.
1775 Seen : Elist_Id := No_Elist;
1776 -- A list containing the entities of all the items processed so far. It
1777 -- plays a role in detecting distinct entities.
1779 States_Seen : Elist_Id := No_Elist;
1780 -- A list containing the entities of all states processed so far. It
1781 -- helps in detecting illegal usage of a state and a corresponding
1782 -- constituent in pragma [Refined_]Global.
1784 In_Out_Seen : Boolean := False;
1785 Input_Seen : Boolean := False;
1786 Output_Seen : Boolean := False;
1787 Proof_Seen : Boolean := False;
1788 -- Flags used to verify the consistency of modes
1790 procedure Analyze_Global_List
1791 (List : Node_Id;
1792 Global_Mode : Name_Id := Name_Input);
1793 -- Verify the legality of a single global list declaration. Global_Mode
1794 -- denotes the current mode in effect.
1796 -------------------------
1797 -- Analyze_Global_List --
1798 -------------------------
1800 procedure Analyze_Global_List
1801 (List : Node_Id;
1802 Global_Mode : Name_Id := Name_Input)
1804 procedure Analyze_Global_Item
1805 (Item : Node_Id;
1806 Global_Mode : Name_Id);
1807 -- Verify the legality of a single global item declaration denoted by
1808 -- Item. Global_Mode denotes the current mode in effect.
1810 procedure Check_Duplicate_Mode
1811 (Mode : Node_Id;
1812 Status : in out Boolean);
1813 -- Flag Status denotes whether a particular mode has been seen while
1814 -- processing a global list. This routine verifies that Mode is not a
1815 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
1817 procedure Check_Mode_Restriction_In_Enclosing_Context
1818 (Item : Node_Id;
1819 Item_Id : Entity_Id);
1820 -- Verify that an item of mode In_Out or Output does not appear as an
1821 -- input in the Global aspect of an enclosing subprogram. If this is
1822 -- the case, emit an error. Item and Item_Id are respectively the
1823 -- item and its entity.
1825 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
1826 -- Mode denotes either In_Out or Output. Depending on the kind of the
1827 -- related subprogram, emit an error if those two modes apply to a
1828 -- function (SPARK RM 6.1.4(10)).
1830 -------------------------
1831 -- Analyze_Global_Item --
1832 -------------------------
1834 procedure Analyze_Global_Item
1835 (Item : Node_Id;
1836 Global_Mode : Name_Id)
1838 Item_Id : Entity_Id;
1840 begin
1841 -- Detect one of the following cases
1843 -- with Global => (null, Name)
1844 -- with Global => (Name_1, null, Name_2)
1845 -- with Global => (Name, null)
1847 if Nkind (Item) = N_Null then
1848 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
1849 return;
1850 end if;
1852 Analyze (Item);
1853 Resolve_State (Item);
1855 -- Find the entity of the item. If this is a renaming, climb the
1856 -- renaming chain to reach the root object. Renamings of non-
1857 -- entire objects do not yield an entity (Empty).
1859 Item_Id := Entity_Of (Item);
1861 if Present (Item_Id) then
1863 -- A global item may denote a formal parameter of an enclosing
1864 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
1865 -- provide a better error diagnostic.
1867 if Is_Formal (Item_Id) then
1868 if Scope (Item_Id) = Spec_Id then
1869 SPARK_Msg_NE
1870 ("global item cannot reference parameter of "
1871 & "subprogram &", Item, Spec_Id);
1872 return;
1873 end if;
1875 -- A formal object may act as a global item inside a generic
1877 elsif Is_Formal_Object (Item_Id) then
1878 null;
1880 -- The only legal references are those to abstract states and
1881 -- objects (SPARK RM 6.1.4(4)).
1883 elsif not Ekind_In (Item_Id, E_Abstract_State,
1884 E_Constant,
1885 E_Variable)
1886 then
1887 SPARK_Msg_N
1888 ("global item must denote object or state", Item);
1889 return;
1890 end if;
1892 -- State related checks
1894 if Ekind (Item_Id) = E_Abstract_State then
1896 -- Package and subprogram bodies are instantiated
1897 -- individually in a separate compiler pass. Due to this
1898 -- mode of instantiation, the refinement of a state may
1899 -- no longer be visible when a subprogram body contract
1900 -- is instantiated. Since the generic template is legal,
1901 -- do not perform this check in the instance to circumvent
1902 -- this oddity.
1904 if Is_Generic_Instance (Spec_Id) then
1905 null;
1907 -- An abstract state with visible refinement cannot appear
1908 -- in pragma [Refined_]Global as its place must be taken by
1909 -- some of its constituents (SPARK RM 6.1.4(7)).
1911 elsif Has_Visible_Refinement (Item_Id) then
1912 SPARK_Msg_NE
1913 ("cannot mention state & in global refinement",
1914 Item, Item_Id);
1915 SPARK_Msg_N ("\use its constituents instead", Item);
1916 return;
1918 -- If the reference to the abstract state appears in an
1919 -- enclosing package body that will eventually refine the
1920 -- state, record the reference for future checks.
1922 else
1923 Record_Possible_Body_Reference
1924 (State_Id => Item_Id,
1925 Ref => Item);
1926 end if;
1928 -- Constant related checks
1930 elsif Ekind (Item_Id) = E_Constant then
1932 -- A constant is read-only item, therefore it cannot act as
1933 -- an output.
1935 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
1936 SPARK_Msg_NE
1937 ("constant & cannot act as output", Item, Item_Id);
1938 return;
1939 end if;
1941 -- Variable related checks. These are only relevant when
1942 -- SPARK_Mode is on as they are not standard Ada legality
1943 -- rules.
1945 elsif SPARK_Mode = On
1946 and then Ekind (Item_Id) = E_Variable
1947 and then Is_Effectively_Volatile (Item_Id)
1948 then
1949 -- An effectively volatile object cannot appear as a global
1950 -- item of a function (SPARK RM 7.1.3(9)).
1952 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
1953 Error_Msg_NE
1954 ("volatile object & cannot act as global item of a "
1955 & "function", Item, Item_Id);
1956 return;
1958 -- An effectively volatile object with external property
1959 -- Effective_Reads set to True must have mode Output or
1960 -- In_Out (SPARK RM 7.1.3(11)).
1962 elsif Effective_Reads_Enabled (Item_Id)
1963 and then Global_Mode = Name_Input
1964 then
1965 Error_Msg_NE
1966 ("volatile object & with property Effective_Reads must "
1967 & "have mode In_Out or Output", Item, Item_Id);
1968 return;
1969 end if;
1970 end if;
1972 -- When the item renames an entire object, replace the item
1973 -- with a reference to the object.
1975 if Entity (Item) /= Item_Id then
1976 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
1977 Analyze (Item);
1978 end if;
1980 -- Some form of illegal construct masquerading as a name
1981 -- (SPARK RM 6.1.4(4)).
1983 else
1984 Error_Msg_N ("global item must denote object or state", Item);
1985 return;
1986 end if;
1988 -- Verify that an output does not appear as an input in an
1989 -- enclosing subprogram.
1991 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
1992 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
1993 end if;
1995 -- The same entity might be referenced through various way.
1996 -- Check the entity of the item rather than the item itself
1997 -- (SPARK RM 6.1.4(10)).
1999 if Contains (Seen, Item_Id) then
2000 SPARK_Msg_N ("duplicate global item", Item);
2002 -- Add the entity of the current item to the list of processed
2003 -- items.
2005 else
2006 Add_Item (Item_Id, Seen);
2008 if Ekind (Item_Id) = E_Abstract_State then
2009 Add_Item (Item_Id, States_Seen);
2010 end if;
2012 if Ekind_In (Item_Id, E_Abstract_State, E_Constant, E_Variable)
2013 and then Present (Encapsulating_State (Item_Id))
2014 then
2015 Add_Item (Item_Id, Constits_Seen);
2016 end if;
2017 end if;
2018 end Analyze_Global_Item;
2020 --------------------------
2021 -- Check_Duplicate_Mode --
2022 --------------------------
2024 procedure Check_Duplicate_Mode
2025 (Mode : Node_Id;
2026 Status : in out Boolean)
2028 begin
2029 if Status then
2030 SPARK_Msg_N ("duplicate global mode", Mode);
2031 end if;
2033 Status := True;
2034 end Check_Duplicate_Mode;
2036 -------------------------------------------------
2037 -- Check_Mode_Restriction_In_Enclosing_Context --
2038 -------------------------------------------------
2040 procedure Check_Mode_Restriction_In_Enclosing_Context
2041 (Item : Node_Id;
2042 Item_Id : Entity_Id)
2044 Context : Entity_Id;
2045 Dummy : Boolean;
2046 Inputs : Elist_Id := No_Elist;
2047 Outputs : Elist_Id := No_Elist;
2049 begin
2050 -- Traverse the scope stack looking for enclosing subprograms
2051 -- subject to pragma [Refined_]Global.
2053 Context := Scope (Subp_Id);
2054 while Present (Context) and then Context /= Standard_Standard loop
2055 if Is_Subprogram (Context)
2056 and then
2057 (Present (Get_Pragma (Context, Pragma_Global))
2058 or else
2059 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2060 then
2061 Collect_Subprogram_Inputs_Outputs
2062 (Subp_Id => Context,
2063 Subp_Inputs => Inputs,
2064 Subp_Outputs => Outputs,
2065 Global_Seen => Dummy);
2067 -- The item is classified as In_Out or Output but appears as
2068 -- an Input in an enclosing subprogram (SPARK RM 6.1.4(11)).
2070 if Appears_In (Inputs, Item_Id)
2071 and then not Appears_In (Outputs, Item_Id)
2072 then
2073 SPARK_Msg_NE
2074 ("global item & cannot have mode In_Out or Output",
2075 Item, Item_Id);
2076 SPARK_Msg_NE
2077 ("\item already appears as input of subprogram &",
2078 Item, Context);
2080 -- Stop the traversal once an error has been detected
2082 exit;
2083 end if;
2084 end if;
2086 Context := Scope (Context);
2087 end loop;
2088 end Check_Mode_Restriction_In_Enclosing_Context;
2090 ----------------------------------------
2091 -- Check_Mode_Restriction_In_Function --
2092 ----------------------------------------
2094 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2095 begin
2096 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
2097 SPARK_Msg_N
2098 ("global mode & is not applicable to functions", Mode);
2099 end if;
2100 end Check_Mode_Restriction_In_Function;
2102 -- Local variables
2104 Assoc : Node_Id;
2105 Item : Node_Id;
2106 Mode : Node_Id;
2108 -- Start of processing for Analyze_Global_List
2110 begin
2111 if Nkind (List) = N_Null then
2112 Set_Analyzed (List);
2114 -- Single global item declaration
2116 elsif Nkind_In (List, N_Expanded_Name,
2117 N_Identifier,
2118 N_Selected_Component)
2119 then
2120 Analyze_Global_Item (List, Global_Mode);
2122 -- Simple global list or moded global list declaration
2124 elsif Nkind (List) = N_Aggregate then
2125 Set_Analyzed (List);
2127 -- The declaration of a simple global list appear as a collection
2128 -- of expressions.
2130 if Present (Expressions (List)) then
2131 if Present (Component_Associations (List)) then
2132 SPARK_Msg_N
2133 ("cannot mix moded and non-moded global lists", List);
2134 end if;
2136 Item := First (Expressions (List));
2137 while Present (Item) loop
2138 Analyze_Global_Item (Item, Global_Mode);
2139 Next (Item);
2140 end loop;
2142 -- The declaration of a moded global list appears as a collection
2143 -- of component associations where individual choices denote
2144 -- modes.
2146 elsif Present (Component_Associations (List)) then
2147 if Present (Expressions (List)) then
2148 SPARK_Msg_N
2149 ("cannot mix moded and non-moded global lists", List);
2150 end if;
2152 Assoc := First (Component_Associations (List));
2153 while Present (Assoc) loop
2154 Mode := First (Choices (Assoc));
2156 if Nkind (Mode) = N_Identifier then
2157 if Chars (Mode) = Name_In_Out then
2158 Check_Duplicate_Mode (Mode, In_Out_Seen);
2159 Check_Mode_Restriction_In_Function (Mode);
2161 elsif Chars (Mode) = Name_Input then
2162 Check_Duplicate_Mode (Mode, Input_Seen);
2164 elsif Chars (Mode) = Name_Output then
2165 Check_Duplicate_Mode (Mode, Output_Seen);
2166 Check_Mode_Restriction_In_Function (Mode);
2168 elsif Chars (Mode) = Name_Proof_In then
2169 Check_Duplicate_Mode (Mode, Proof_Seen);
2171 else
2172 SPARK_Msg_N ("invalid mode selector", Mode);
2173 end if;
2175 else
2176 SPARK_Msg_N ("invalid mode selector", Mode);
2177 end if;
2179 -- Items in a moded list appear as a collection of
2180 -- expressions. Reuse the existing machinery to analyze
2181 -- them.
2183 Analyze_Global_List
2184 (List => Expression (Assoc),
2185 Global_Mode => Chars (Mode));
2187 Next (Assoc);
2188 end loop;
2190 -- Invalid tree
2192 else
2193 raise Program_Error;
2194 end if;
2196 -- Any other attempt to declare a global item is illegal. This is a
2197 -- syntax error, always report.
2199 else
2200 Error_Msg_N ("malformed global list", List);
2201 end if;
2202 end Analyze_Global_List;
2204 -- Local variables
2206 Items : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
2208 Restore_Scope : Boolean := False;
2210 -- Start of processing for Analyze_Global_In_Decl_Part
2212 begin
2213 Set_Analyzed (N);
2215 -- There is nothing to be done for a null global list
2217 if Nkind (Items) = N_Null then
2218 Set_Analyzed (Items);
2220 -- Analyze the various forms of global lists and items. Note that some
2221 -- of these may be malformed in which case the analysis emits error
2222 -- messages.
2224 else
2225 -- Ensure that the formal parameters are visible when processing an
2226 -- item. This falls out of the general rule of aspects pertaining to
2227 -- subprogram declarations.
2229 if not In_Open_Scopes (Spec_Id) then
2230 Restore_Scope := True;
2231 Push_Scope (Spec_Id);
2233 if Is_Generic_Subprogram (Spec_Id) then
2234 Install_Generic_Formals (Spec_Id);
2235 else
2236 Install_Formals (Spec_Id);
2237 end if;
2238 end if;
2240 Analyze_Global_List (Items);
2242 if Restore_Scope then
2243 End_Scope;
2244 end if;
2245 end if;
2247 -- Ensure that a state and a corresponding constituent do not appear
2248 -- together in pragma [Refined_]Global.
2250 Check_State_And_Constituent_Use
2251 (States => States_Seen,
2252 Constits => Constits_Seen,
2253 Context => N);
2254 end Analyze_Global_In_Decl_Part;
2256 --------------------------------------------
2257 -- Analyze_Initial_Condition_In_Decl_Part --
2258 --------------------------------------------
2260 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2261 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2262 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2263 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
2265 begin
2266 Set_Analyzed (N);
2268 -- The expression is preanalyzed because it has not been moved to its
2269 -- final place yet. A direct analysis may generate side effects and this
2270 -- is not desired at this point.
2272 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2273 end Analyze_Initial_Condition_In_Decl_Part;
2275 --------------------------------------
2276 -- Analyze_Initializes_In_Decl_Part --
2277 --------------------------------------
2279 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2280 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2281 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2283 Constits_Seen : Elist_Id := No_Elist;
2284 -- A list containing the entities of all constituents processed so far.
2285 -- It aids in detecting illegal usage of a state and a corresponding
2286 -- constituent in pragma Initializes.
2288 Items_Seen : Elist_Id := No_Elist;
2289 -- A list of all initialization items processed so far. This list is
2290 -- used to detect duplicate items.
2292 Non_Null_Seen : Boolean := False;
2293 Null_Seen : Boolean := False;
2294 -- Flags used to check the legality of a null initialization list
2296 States_And_Objs : Elist_Id := No_Elist;
2297 -- A list of all abstract states and objects declared in the visible
2298 -- declarations of the related package. This list is used to detect the
2299 -- legality of initialization items.
2301 States_Seen : Elist_Id := No_Elist;
2302 -- A list containing the entities of all states processed so far. It
2303 -- helps in detecting illegal usage of a state and a corresponding
2304 -- constituent in pragma Initializes.
2306 procedure Analyze_Initialization_Item (Item : Node_Id);
2307 -- Verify the legality of a single initialization item
2309 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2310 -- Verify the legality of a single initialization item followed by a
2311 -- list of input items.
2313 procedure Collect_States_And_Objects;
2314 -- Inspect the visible declarations of the related package and gather
2315 -- the entities of all abstract states and objects in States_And_Objs.
2317 ---------------------------------
2318 -- Analyze_Initialization_Item --
2319 ---------------------------------
2321 procedure Analyze_Initialization_Item (Item : Node_Id) is
2322 Item_Id : Entity_Id;
2324 begin
2325 -- Null initialization list
2327 if Nkind (Item) = N_Null then
2328 if Null_Seen then
2329 SPARK_Msg_N ("multiple null initializations not allowed", Item);
2331 elsif Non_Null_Seen then
2332 SPARK_Msg_N
2333 ("cannot mix null and non-null initialization items", Item);
2334 else
2335 Null_Seen := True;
2336 end if;
2338 -- Initialization item
2340 else
2341 Non_Null_Seen := True;
2343 if Null_Seen then
2344 SPARK_Msg_N
2345 ("cannot mix null and non-null initialization items", Item);
2346 end if;
2348 Analyze (Item);
2349 Resolve_State (Item);
2351 if Is_Entity_Name (Item) then
2352 Item_Id := Entity_Of (Item);
2354 if Ekind_In (Item_Id, E_Abstract_State,
2355 E_Constant,
2356 E_Variable)
2357 then
2358 -- The state or variable must be declared in the visible
2359 -- declarations of the package (SPARK RM 7.1.5(7)).
2361 if not Contains (States_And_Objs, Item_Id) then
2362 Error_Msg_Name_1 := Chars (Pack_Id);
2363 SPARK_Msg_NE
2364 ("initialization item & must appear in the visible "
2365 & "declarations of package %", Item, Item_Id);
2367 -- Detect a duplicate use of the same initialization item
2368 -- (SPARK RM 7.1.5(5)).
2370 elsif Contains (Items_Seen, Item_Id) then
2371 SPARK_Msg_N ("duplicate initialization item", Item);
2373 -- The item is legal, add it to the list of processed states
2374 -- and variables.
2376 else
2377 Add_Item (Item_Id, Items_Seen);
2379 if Ekind (Item_Id) = E_Abstract_State then
2380 Add_Item (Item_Id, States_Seen);
2381 end if;
2383 if Present (Encapsulating_State (Item_Id)) then
2384 Add_Item (Item_Id, Constits_Seen);
2385 end if;
2386 end if;
2388 -- The item references something that is not a state or object
2389 -- (SPARK RM 7.1.5(3)).
2391 else
2392 SPARK_Msg_N
2393 ("initialization item must denote object or state", Item);
2394 end if;
2396 -- Some form of illegal construct masquerading as a name
2397 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2399 else
2400 Error_Msg_N
2401 ("initialization item must denote object or state", Item);
2402 end if;
2403 end if;
2404 end Analyze_Initialization_Item;
2406 ---------------------------------------------
2407 -- Analyze_Initialization_Item_With_Inputs --
2408 ---------------------------------------------
2410 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2411 Inputs_Seen : Elist_Id := No_Elist;
2412 -- A list of all inputs processed so far. This list is used to detect
2413 -- duplicate uses of an input.
2415 Non_Null_Seen : Boolean := False;
2416 Null_Seen : Boolean := False;
2417 -- Flags used to check the legality of an input list
2419 procedure Analyze_Input_Item (Input : Node_Id);
2420 -- Verify the legality of a single input item
2422 ------------------------
2423 -- Analyze_Input_Item --
2424 ------------------------
2426 procedure Analyze_Input_Item (Input : Node_Id) is
2427 Input_Id : Entity_Id;
2429 begin
2430 -- Null input list
2432 if Nkind (Input) = N_Null then
2433 if Null_Seen then
2434 SPARK_Msg_N
2435 ("multiple null initializations not allowed", Item);
2437 elsif Non_Null_Seen then
2438 SPARK_Msg_N
2439 ("cannot mix null and non-null initialization item", Item);
2440 else
2441 Null_Seen := True;
2442 end if;
2444 -- Input item
2446 else
2447 Non_Null_Seen := True;
2449 if Null_Seen then
2450 SPARK_Msg_N
2451 ("cannot mix null and non-null initialization item", Item);
2452 end if;
2454 Analyze (Input);
2455 Resolve_State (Input);
2457 if Is_Entity_Name (Input) then
2458 Input_Id := Entity_Of (Input);
2460 if Ekind_In (Input_Id, E_Abstract_State,
2461 E_Constant,
2462 E_In_Parameter,
2463 E_In_Out_Parameter,
2464 E_Out_Parameter,
2465 E_Variable)
2466 then
2467 -- The input cannot denote states or objects declared
2468 -- within the related package (SPARK RM 7.1.5(4)).
2470 if Within_Scope (Input_Id, Current_Scope) then
2471 Error_Msg_Name_1 := Chars (Pack_Id);
2472 SPARK_Msg_NE
2473 ("input item & cannot denote a visible object or "
2474 & "state of package %", Input, Input_Id);
2476 -- Detect a duplicate use of the same input item
2477 -- (SPARK RM 7.1.5(5)).
2479 elsif Contains (Inputs_Seen, Input_Id) then
2480 SPARK_Msg_N ("duplicate input item", Input);
2482 -- Input is legal, add it to the list of processed inputs
2484 else
2485 Add_Item (Input_Id, Inputs_Seen);
2487 if Ekind (Input_Id) = E_Abstract_State then
2488 Add_Item (Input_Id, States_Seen);
2489 end if;
2491 if Ekind_In (Input_Id, E_Abstract_State,
2492 E_Constant,
2493 E_Variable)
2494 and then Present (Encapsulating_State (Input_Id))
2495 then
2496 Add_Item (Input_Id, Constits_Seen);
2497 end if;
2498 end if;
2500 -- The input references something that is not a state or an
2501 -- object (SPARK RM 7.1.5(3)).
2503 else
2504 SPARK_Msg_N
2505 ("input item must denote object or state", Input);
2506 end if;
2508 -- Some form of illegal construct masquerading as a name
2509 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2511 else
2512 Error_Msg_N
2513 ("input item must denote object or state", Input);
2514 end if;
2515 end if;
2516 end Analyze_Input_Item;
2518 -- Local variables
2520 Inputs : constant Node_Id := Expression (Item);
2521 Elmt : Node_Id;
2522 Input : Node_Id;
2524 Name_Seen : Boolean := False;
2525 -- A flag used to detect multiple item names
2527 -- Start of processing for Analyze_Initialization_Item_With_Inputs
2529 begin
2530 -- Inspect the name of an item with inputs
2532 Elmt := First (Choices (Item));
2533 while Present (Elmt) loop
2534 if Name_Seen then
2535 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
2536 else
2537 Name_Seen := True;
2538 Analyze_Initialization_Item (Elmt);
2539 end if;
2541 Next (Elmt);
2542 end loop;
2544 -- Multiple input items appear as an aggregate
2546 if Nkind (Inputs) = N_Aggregate then
2547 if Present (Expressions (Inputs)) then
2548 Input := First (Expressions (Inputs));
2549 while Present (Input) loop
2550 Analyze_Input_Item (Input);
2551 Next (Input);
2552 end loop;
2553 end if;
2555 if Present (Component_Associations (Inputs)) then
2556 SPARK_Msg_N
2557 ("inputs must appear in named association form", Inputs);
2558 end if;
2560 -- Single input item
2562 else
2563 Analyze_Input_Item (Inputs);
2564 end if;
2565 end Analyze_Initialization_Item_With_Inputs;
2567 --------------------------------
2568 -- Collect_States_And_Objects --
2569 --------------------------------
2571 procedure Collect_States_And_Objects is
2572 Pack_Spec : constant Node_Id := Specification (Pack_Decl);
2573 Decl : Node_Id;
2575 begin
2576 -- Collect the abstract states defined in the package (if any)
2578 if Present (Abstract_States (Pack_Id)) then
2579 States_And_Objs := New_Copy_Elist (Abstract_States (Pack_Id));
2580 end if;
2582 -- Collect all objects the appear in the visible declarations of the
2583 -- related package.
2585 if Present (Visible_Declarations (Pack_Spec)) then
2586 Decl := First (Visible_Declarations (Pack_Spec));
2587 while Present (Decl) loop
2588 if Comes_From_Source (Decl)
2589 and then Nkind (Decl) = N_Object_Declaration
2590 then
2591 Add_Item (Defining_Entity (Decl), States_And_Objs);
2592 end if;
2594 Next (Decl);
2595 end loop;
2596 end if;
2597 end Collect_States_And_Objects;
2599 -- Local variables
2601 Inits : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
2602 Init : Node_Id;
2604 -- Start of processing for Analyze_Initializes_In_Decl_Part
2606 begin
2607 Set_Analyzed (N);
2609 -- Nothing to do when the initialization list is empty
2611 if Nkind (Inits) = N_Null then
2612 return;
2613 end if;
2615 -- Single and multiple initialization clauses appear as an aggregate. If
2616 -- this is not the case, then either the parser or the analysis of the
2617 -- pragma failed to produce an aggregate.
2619 pragma Assert (Nkind (Inits) = N_Aggregate);
2621 -- Initialize the various lists used during analysis
2623 Collect_States_And_Objects;
2625 if Present (Expressions (Inits)) then
2626 Init := First (Expressions (Inits));
2627 while Present (Init) loop
2628 Analyze_Initialization_Item (Init);
2629 Next (Init);
2630 end loop;
2631 end if;
2633 if Present (Component_Associations (Inits)) then
2634 Init := First (Component_Associations (Inits));
2635 while Present (Init) loop
2636 Analyze_Initialization_Item_With_Inputs (Init);
2637 Next (Init);
2638 end loop;
2639 end if;
2641 -- Ensure that a state and a corresponding constituent do not appear
2642 -- together in pragma Initializes.
2644 Check_State_And_Constituent_Use
2645 (States => States_Seen,
2646 Constits => Constits_Seen,
2647 Context => N);
2648 end Analyze_Initializes_In_Decl_Part;
2650 --------------------
2651 -- Analyze_Pragma --
2652 --------------------
2654 procedure Analyze_Pragma (N : Node_Id) is
2655 Loc : constant Source_Ptr := Sloc (N);
2656 Prag_Id : Pragma_Id;
2658 Pname : Name_Id;
2659 -- Name of the source pragma, or name of the corresponding aspect for
2660 -- pragmas which originate in a source aspect. In the latter case, the
2661 -- name may be different from the pragma name.
2663 Pragma_Exit : exception;
2664 -- This exception is used to exit pragma processing completely. It
2665 -- is used when an error is detected, and no further processing is
2666 -- required. It is also used if an earlier error has left the tree in
2667 -- a state where the pragma should not be processed.
2669 Arg_Count : Nat;
2670 -- Number of pragma argument associations
2672 Arg1 : Node_Id;
2673 Arg2 : Node_Id;
2674 Arg3 : Node_Id;
2675 Arg4 : Node_Id;
2676 -- First four pragma arguments (pragma argument association nodes, or
2677 -- Empty if the corresponding argument does not exist).
2679 type Name_List is array (Natural range <>) of Name_Id;
2680 type Args_List is array (Natural range <>) of Node_Id;
2681 -- Types used for arguments to Check_Arg_Order and Gather_Associations
2683 -----------------------
2684 -- Local Subprograms --
2685 -----------------------
2687 procedure Acquire_Warning_Match_String (Arg : Node_Id);
2688 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
2689 -- get the given string argument, and place it in Name_Buffer, adding
2690 -- leading and trailing asterisks if they are not already present. The
2691 -- caller has already checked that Arg is a static string expression.
2693 procedure Ada_2005_Pragma;
2694 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
2695 -- Ada 95 mode, these are implementation defined pragmas, so should be
2696 -- caught by the No_Implementation_Pragmas restriction.
2698 procedure Ada_2012_Pragma;
2699 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
2700 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
2701 -- should be caught by the No_Implementation_Pragmas restriction.
2703 procedure Analyze_Depends_Global;
2704 -- Subsidiary to the analysis of pragma Depends and Global
2706 procedure Analyze_Part_Of
2707 (Item_Id : Entity_Id;
2708 State : Node_Id;
2709 Indic : Node_Id;
2710 Legal : out Boolean);
2711 -- Subsidiary to the analysis of pragmas Abstract_State and Part_Of.
2712 -- Perform full analysis of indicator Part_Of. Item_Id is the entity of
2713 -- an abstract state, object, or package instantiation. State is the
2714 -- encapsulating state. Indic is the Part_Of indicator. Flag Legal is
2715 -- set when the indicator is legal.
2717 procedure Analyze_Pre_Post_Condition;
2718 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
2720 procedure Analyze_Refined_Depends_Global_Post
2721 (Spec_Id : out Entity_Id;
2722 Body_Id : out Entity_Id;
2723 Legal : out Boolean);
2724 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
2725 -- Refined_Global and Refined_Post. Check the placement and related
2726 -- context of the pragma. Spec_Id is the entity of the related
2727 -- subprogram. Body_Id is the entity of the subprogram body. Flag
2728 -- Legal is set when the pragma is properly placed.
2730 procedure Check_Ada_83_Warning;
2731 -- Issues a warning message for the current pragma if operating in Ada
2732 -- 83 mode (used for language pragmas that are not a standard part of
2733 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
2734 -- of 95 pragma.
2736 procedure Check_Arg_Count (Required : Nat);
2737 -- Check argument count for pragma is equal to given parameter. If not,
2738 -- then issue an error message and raise Pragma_Exit.
2740 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
2741 -- Arg which can either be a pragma argument association, in which case
2742 -- the check is applied to the expression of the association or an
2743 -- expression directly.
2745 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
2746 -- Check that an argument has the right form for an EXTERNAL_NAME
2747 -- parameter of an extended import/export pragma. The rule is that the
2748 -- name must be an identifier or string literal (in Ada 83 mode) or a
2749 -- static string expression (in Ada 95 mode).
2751 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
2752 -- Check the specified argument Arg to make sure that it is an
2753 -- identifier. If not give error and raise Pragma_Exit.
2755 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
2756 -- Check the specified argument Arg to make sure that it is an integer
2757 -- literal. If not give error and raise Pragma_Exit.
2759 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
2760 -- Check the specified argument Arg to make sure that it has the proper
2761 -- syntactic form for a local name and meets the semantic requirements
2762 -- for a local name. The local name is analyzed as part of the
2763 -- processing for this call. In addition, the local name is required
2764 -- to represent an entity at the library level.
2766 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
2767 -- Check the specified argument Arg to make sure that it has the proper
2768 -- syntactic form for a local name and meets the semantic requirements
2769 -- for a local name. The local name is analyzed as part of the
2770 -- processing for this call.
2772 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
2773 -- Check the specified argument Arg to make sure that it is a valid
2774 -- locking policy name. If not give error and raise Pragma_Exit.
2776 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
2777 -- Check the specified argument Arg to make sure that it is a valid
2778 -- elaboration policy name. If not give error and raise Pragma_Exit.
2780 procedure Check_Arg_Is_One_Of
2781 (Arg : Node_Id;
2782 N1, N2 : Name_Id);
2783 procedure Check_Arg_Is_One_Of
2784 (Arg : Node_Id;
2785 N1, N2, N3 : Name_Id);
2786 procedure Check_Arg_Is_One_Of
2787 (Arg : Node_Id;
2788 N1, N2, N3, N4 : Name_Id);
2789 procedure Check_Arg_Is_One_Of
2790 (Arg : Node_Id;
2791 N1, N2, N3, N4, N5 : Name_Id);
2792 -- Check the specified argument Arg to make sure that it is an
2793 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
2794 -- present). If not then give error and raise Pragma_Exit.
2796 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
2797 -- Check the specified argument Arg to make sure that it is a valid
2798 -- queuing policy name. If not give error and raise Pragma_Exit.
2800 procedure Check_Arg_Is_OK_Static_Expression
2801 (Arg : Node_Id;
2802 Typ : Entity_Id := Empty);
2803 -- Check the specified argument Arg to make sure that it is a static
2804 -- expression of the given type (i.e. it will be analyzed and resolved
2805 -- using this type, which can be any valid argument to Resolve, e.g.
2806 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2807 -- Typ is left Empty, then any static expression is allowed. Includes
2808 -- checking that the argument does not raise Constraint_Error.
2810 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
2811 -- Check the specified argument Arg to make sure that it is a valid task
2812 -- dispatching policy name. If not give error and raise Pragma_Exit.
2814 procedure Check_Arg_Order (Names : Name_List);
2815 -- Checks for an instance of two arguments with identifiers for the
2816 -- current pragma which are not in the sequence indicated by Names,
2817 -- and if so, generates a fatal message about bad order of arguments.
2819 procedure Check_At_Least_N_Arguments (N : Nat);
2820 -- Check there are at least N arguments present
2822 procedure Check_At_Most_N_Arguments (N : Nat);
2823 -- Check there are no more than N arguments present
2825 procedure Check_Component
2826 (Comp : Node_Id;
2827 UU_Typ : Entity_Id;
2828 In_Variant_Part : Boolean := False);
2829 -- Examine an Unchecked_Union component for correct use of per-object
2830 -- constrained subtypes, and for restrictions on finalizable components.
2831 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
2832 -- should be set when Comp comes from a record variant.
2834 procedure Check_Declaration_Order (First : Node_Id; Second : Node_Id);
2835 -- Subsidiary routine to the analysis of pragmas Abstract_State,
2836 -- Initial_Condition and Initializes. Determine whether pragma First
2837 -- appears before pragma Second. If this is not the case, emit an error.
2839 procedure Check_Duplicate_Pragma (E : Entity_Id);
2840 -- Check if a rep item of the same name as the current pragma is already
2841 -- chained as a rep pragma to the given entity. If so give a message
2842 -- about the duplicate, and then raise Pragma_Exit so does not return.
2843 -- Note that if E is a type, then this routine avoids flagging a pragma
2844 -- which applies to a parent type from which E is derived.
2846 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
2847 -- Nam is an N_String_Literal node containing the external name set by
2848 -- an Import or Export pragma (or extended Import or Export pragma).
2849 -- This procedure checks for possible duplications if this is the export
2850 -- case, and if found, issues an appropriate error message.
2852 procedure Check_Expr_Is_OK_Static_Expression
2853 (Expr : Node_Id;
2854 Typ : Entity_Id := Empty);
2855 -- Check the specified expression Expr to make sure that it is a static
2856 -- expression of the given type (i.e. it will be analyzed and resolved
2857 -- using this type, which can be any valid argument to Resolve, e.g.
2858 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2859 -- Typ is left Empty, then any static expression is allowed. Includes
2860 -- checking that the expression does not raise Constraint_Error.
2862 procedure Check_First_Subtype (Arg : Node_Id);
2863 -- Checks that Arg, whose expression is an entity name, references a
2864 -- first subtype.
2866 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
2867 -- Checks that the given argument has an identifier, and if so, requires
2868 -- it to match the given identifier name. If there is no identifier, or
2869 -- a non-matching identifier, then an error message is given and
2870 -- Pragma_Exit is raised.
2872 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
2873 -- Checks that the given argument has an identifier, and if so, requires
2874 -- it to match one of the given identifier names. If there is no
2875 -- identifier, or a non-matching identifier, then an error message is
2876 -- given and Pragma_Exit is raised.
2878 procedure Check_In_Main_Program;
2879 -- Common checks for pragmas that appear within a main program
2880 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
2882 procedure Check_Interrupt_Or_Attach_Handler;
2883 -- Common processing for first argument of pragma Interrupt_Handler or
2884 -- pragma Attach_Handler.
2886 procedure Check_Loop_Pragma_Placement;
2887 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
2888 -- appear immediately within a construct restricted to loops, and that
2889 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
2891 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
2892 -- Check that pragma appears in a declarative part, or in a package
2893 -- specification, i.e. that it does not occur in a statement sequence
2894 -- in a body.
2896 procedure Check_No_Identifier (Arg : Node_Id);
2897 -- Checks that the given argument does not have an identifier. If
2898 -- an identifier is present, then an error message is issued, and
2899 -- Pragma_Exit is raised.
2901 procedure Check_No_Identifiers;
2902 -- Checks that none of the arguments to the pragma has an identifier.
2903 -- If any argument has an identifier, then an error message is issued,
2904 -- and Pragma_Exit is raised.
2906 procedure Check_No_Link_Name;
2907 -- Checks that no link name is specified
2909 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
2910 -- Checks if the given argument has an identifier, and if so, requires
2911 -- it to match the given identifier name. If there is a non-matching
2912 -- identifier, then an error message is given and Pragma_Exit is raised.
2914 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
2915 -- Checks if the given argument has an identifier, and if so, requires
2916 -- it to match the given identifier name. If there is a non-matching
2917 -- identifier, then an error message is given and Pragma_Exit is raised.
2918 -- In this version of the procedure, the identifier name is given as
2919 -- a string with lower case letters.
2921 procedure Check_Static_Constraint (Constr : Node_Id);
2922 -- Constr is a constraint from an N_Subtype_Indication node from a
2923 -- component constraint in an Unchecked_Union type. This routine checks
2924 -- that the constraint is static as required by the restrictions for
2925 -- Unchecked_Union.
2927 procedure Check_Valid_Configuration_Pragma;
2928 -- Legality checks for placement of a configuration pragma
2930 procedure Check_Valid_Library_Unit_Pragma;
2931 -- Legality checks for library unit pragmas. A special case arises for
2932 -- pragmas in generic instances that come from copies of the original
2933 -- library unit pragmas in the generic templates. In the case of other
2934 -- than library level instantiations these can appear in contexts which
2935 -- would normally be invalid (they only apply to the original template
2936 -- and to library level instantiations), and they are simply ignored,
2937 -- which is implemented by rewriting them as null statements.
2939 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
2940 -- Check an Unchecked_Union variant for lack of nested variants and
2941 -- presence of at least one component. UU_Typ is the related Unchecked_
2942 -- Union type.
2944 procedure Ensure_Aggregate_Form (Arg : Node_Id);
2945 -- Subsidiary routine to the processing of pragmas Abstract_State,
2946 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
2947 -- Refined_Global and Refined_State. Transform argument Arg into
2948 -- an aggregate if not one already. N_Null is never transformed.
2949 -- Arg may denote an aspect specification or a pragma argument
2950 -- association.
2952 procedure Error_Pragma (Msg : String);
2953 pragma No_Return (Error_Pragma);
2954 -- Outputs error message for current pragma. The message contains a %
2955 -- that will be replaced with the pragma name, and the flag is placed
2956 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
2957 -- calls Fix_Error (see spec of that procedure for details).
2959 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
2960 pragma No_Return (Error_Pragma_Arg);
2961 -- Outputs error message for current pragma. The message may contain
2962 -- a % that will be replaced with the pragma name. The parameter Arg
2963 -- may either be a pragma argument association, in which case the flag
2964 -- is placed on the expression of this association, or an expression,
2965 -- in which case the flag is placed directly on the expression. The
2966 -- message is placed using Error_Msg_N, so the message may also contain
2967 -- an & insertion character which will reference the given Arg value.
2968 -- After placing the message, Pragma_Exit is raised. Note: this routine
2969 -- calls Fix_Error (see spec of that procedure for details).
2971 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
2972 pragma No_Return (Error_Pragma_Arg);
2973 -- Similar to above form of Error_Pragma_Arg except that two messages
2974 -- are provided, the second is a continuation comment starting with \.
2976 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
2977 pragma No_Return (Error_Pragma_Arg_Ident);
2978 -- Outputs error message for current pragma. The message may contain a %
2979 -- that will be replaced with the pragma name. The parameter Arg must be
2980 -- a pragma argument association with a non-empty identifier (i.e. its
2981 -- Chars field must be set), and the error message is placed on the
2982 -- identifier. The message is placed using Error_Msg_N so the message
2983 -- may also contain an & insertion character which will reference
2984 -- the identifier. After placing the message, Pragma_Exit is raised.
2985 -- Note: this routine calls Fix_Error (see spec of that procedure for
2986 -- details).
2988 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
2989 pragma No_Return (Error_Pragma_Ref);
2990 -- Outputs error message for current pragma. The message may contain
2991 -- a % that will be replaced with the pragma name. The parameter Ref
2992 -- must be an entity whose name can be referenced by & and sloc by #.
2993 -- After placing the message, Pragma_Exit is raised. Note: this routine
2994 -- calls Fix_Error (see spec of that procedure for details).
2996 function Find_Lib_Unit_Name return Entity_Id;
2997 -- Used for a library unit pragma to find the entity to which the
2998 -- library unit pragma applies, returns the entity found.
3000 procedure Find_Program_Unit_Name (Id : Node_Id);
3001 -- If the pragma is a compilation unit pragma, the id must denote the
3002 -- compilation unit in the same compilation, and the pragma must appear
3003 -- in the list of preceding or trailing pragmas. If it is a program
3004 -- unit pragma that is not a compilation unit pragma, then the
3005 -- identifier must be visible.
3007 function Find_Unique_Parameterless_Procedure
3008 (Name : Entity_Id;
3009 Arg : Node_Id) return Entity_Id;
3010 -- Used for a procedure pragma to find the unique parameterless
3011 -- procedure identified by Name, returns it if it exists, otherwise
3012 -- errors out and uses Arg as the pragma argument for the message.
3014 function Fix_Error (Msg : String) return String;
3015 -- This is called prior to issuing an error message. Msg is the normal
3016 -- error message issued in the pragma case. This routine checks for the
3017 -- case of a pragma coming from an aspect in the source, and returns a
3018 -- message suitable for the aspect case as follows:
3020 -- Each substring "pragma" is replaced by "aspect"
3022 -- If "argument of" is at the start of the error message text, it is
3023 -- replaced by "entity for".
3025 -- If "argument" is at the start of the error message text, it is
3026 -- replaced by "entity".
3028 -- So for example, "argument of pragma X must be discrete type"
3029 -- returns "entity for aspect X must be a discrete type".
3031 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
3032 -- be different from the pragma name). If the current pragma results
3033 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
3034 -- original pragma name.
3036 procedure Gather_Associations
3037 (Names : Name_List;
3038 Args : out Args_List);
3039 -- This procedure is used to gather the arguments for a pragma that
3040 -- permits arbitrary ordering of parameters using the normal rules
3041 -- for named and positional parameters. The Names argument is a list
3042 -- of Name_Id values that corresponds to the allowed pragma argument
3043 -- association identifiers in order. The result returned in Args is
3044 -- a list of corresponding expressions that are the pragma arguments.
3045 -- Note that this is a list of expressions, not of pragma argument
3046 -- associations (Gather_Associations has completely checked all the
3047 -- optional identifiers when it returns). An entry in Args is Empty
3048 -- on return if the corresponding argument is not present.
3050 procedure GNAT_Pragma;
3051 -- Called for all GNAT defined pragmas to check the relevant restriction
3052 -- (No_Implementation_Pragmas).
3054 function Is_Before_First_Decl
3055 (Pragma_Node : Node_Id;
3056 Decls : List_Id) return Boolean;
3057 -- Return True if Pragma_Node is before the first declarative item in
3058 -- Decls where Decls is the list of declarative items.
3060 function Is_Configuration_Pragma return Boolean;
3061 -- Determines if the placement of the current pragma is appropriate
3062 -- for a configuration pragma.
3064 function Is_In_Context_Clause return Boolean;
3065 -- Returns True if pragma appears within the context clause of a unit,
3066 -- and False for any other placement (does not generate any messages).
3068 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
3069 -- Analyzes the argument, and determines if it is a static string
3070 -- expression, returns True if so, False if non-static or not String.
3071 -- A special case is that a string literal returns True in Ada 83 mode
3072 -- (which has no such thing as static string expressions). Note that
3073 -- the call analyzes its argument, so this cannot be used for the case
3074 -- where an identifier might not be declared.
3076 procedure Pragma_Misplaced;
3077 pragma No_Return (Pragma_Misplaced);
3078 -- Issue fatal error message for misplaced pragma
3080 procedure Process_Atomic_Independent_Shared_Volatile;
3081 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
3082 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
3083 -- and treated as being identical in effect to pragma Atomic.
3085 procedure Process_Compile_Time_Warning_Or_Error;
3086 -- Common processing for Compile_Time_Error and Compile_Time_Warning
3088 procedure Process_Convention
3089 (C : out Convention_Id;
3090 Ent : out Entity_Id);
3091 -- Common processing for Convention, Interface, Import and Export.
3092 -- Checks first two arguments of pragma, and sets the appropriate
3093 -- convention value in the specified entity or entities. On return
3094 -- C is the convention, Ent is the referenced entity.
3096 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
3097 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
3098 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
3100 procedure Process_Extended_Import_Export_Object_Pragma
3101 (Arg_Internal : Node_Id;
3102 Arg_External : Node_Id;
3103 Arg_Size : Node_Id);
3104 -- Common processing for the pragmas Import/Export_Object. The three
3105 -- arguments correspond to the three named parameters of the pragmas. An
3106 -- argument is empty if the corresponding parameter is not present in
3107 -- the pragma.
3109 procedure Process_Extended_Import_Export_Internal_Arg
3110 (Arg_Internal : Node_Id := Empty);
3111 -- Common processing for all extended Import and Export pragmas. The
3112 -- argument is the pragma parameter for the Internal argument. If
3113 -- Arg_Internal is empty or inappropriate, an error message is posted.
3114 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
3115 -- set to identify the referenced entity.
3117 procedure Process_Extended_Import_Export_Subprogram_Pragma
3118 (Arg_Internal : Node_Id;
3119 Arg_External : Node_Id;
3120 Arg_Parameter_Types : Node_Id;
3121 Arg_Result_Type : Node_Id := Empty;
3122 Arg_Mechanism : Node_Id;
3123 Arg_Result_Mechanism : Node_Id := Empty);
3124 -- Common processing for all extended Import and Export pragmas applying
3125 -- to subprograms. The caller omits any arguments that do not apply to
3126 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
3127 -- only in the Import_Function and Export_Function cases). The argument
3128 -- names correspond to the allowed pragma association identifiers.
3130 procedure Process_Generic_List;
3131 -- Common processing for Share_Generic and Inline_Generic
3133 procedure Process_Import_Or_Interface;
3134 -- Common processing for Import or Interface
3136 procedure Process_Import_Predefined_Type;
3137 -- Processing for completing a type with pragma Import. This is used
3138 -- to declare types that match predefined C types, especially for cases
3139 -- without corresponding Ada predefined type.
3141 type Inline_Status is (Suppressed, Disabled, Enabled);
3142 -- Inline status of a subprogram, indicated as follows:
3143 -- Suppressed: inlining is suppressed for the subprogram
3144 -- Disabled: no inlining is requested for the subprogram
3145 -- Enabled: inlining is requested/required for the subprogram
3147 procedure Process_Inline (Status : Inline_Status);
3148 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
3149 -- indicates the inline status specified by the pragma.
3151 procedure Process_Interface_Name
3152 (Subprogram_Def : Entity_Id;
3153 Ext_Arg : Node_Id;
3154 Link_Arg : Node_Id);
3155 -- Given the last two arguments of pragma Import, pragma Export, or
3156 -- pragma Interface_Name, performs validity checks and sets the
3157 -- Interface_Name field of the given subprogram entity to the
3158 -- appropriate external or link name, depending on the arguments given.
3159 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
3160 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
3161 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
3162 -- nor Link_Arg is present, the interface name is set to the default
3163 -- from the subprogram name.
3165 procedure Process_Interrupt_Or_Attach_Handler;
3166 -- Common processing for Interrupt and Attach_Handler pragmas
3168 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
3169 -- Common processing for Restrictions and Restriction_Warnings pragmas.
3170 -- Warn is True for Restriction_Warnings, or for Restrictions if the
3171 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
3172 -- is not set in the Restrictions case.
3174 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
3175 -- Common processing for Suppress and Unsuppress. The boolean parameter
3176 -- Suppress_Case is True for the Suppress case, and False for the
3177 -- Unsuppress case.
3179 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id);
3180 -- Subsidiary to the analysis of pragmas Independent[_Components].
3181 -- Record such a pragma N applied to entity E for future checks.
3183 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
3184 -- This procedure sets the Is_Exported flag for the given entity,
3185 -- checking that the entity was not previously imported. Arg is
3186 -- the argument that specified the entity. A check is also made
3187 -- for exporting inappropriate entities.
3189 procedure Set_Extended_Import_Export_External_Name
3190 (Internal_Ent : Entity_Id;
3191 Arg_External : Node_Id);
3192 -- Common processing for all extended import export pragmas. The first
3193 -- argument, Internal_Ent, is the internal entity, which has already
3194 -- been checked for validity by the caller. Arg_External is from the
3195 -- Import or Export pragma, and may be null if no External parameter
3196 -- was present. If Arg_External is present and is a non-null string
3197 -- (a null string is treated as the default), then the Interface_Name
3198 -- field of Internal_Ent is set appropriately.
3200 procedure Set_Imported (E : Entity_Id);
3201 -- This procedure sets the Is_Imported flag for the given entity,
3202 -- checking that it is not previously exported or imported.
3204 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
3205 -- Mech is a parameter passing mechanism (see Import_Function syntax
3206 -- for MECHANISM_NAME). This routine checks that the mechanism argument
3207 -- has the right form, and if not issues an error message. If the
3208 -- argument has the right form then the Mechanism field of Ent is
3209 -- set appropriately.
3211 procedure Set_Rational_Profile;
3212 -- Activate the set of configuration pragmas and permissions that make
3213 -- up the Rational profile.
3215 procedure Set_Ravenscar_Profile (N : Node_Id);
3216 -- Activate the set of configuration pragmas and restrictions that make
3217 -- up the Ravenscar Profile. N is the corresponding pragma node, which
3218 -- is used for error messages on any constructs violating the profile.
3220 ----------------------------------
3221 -- Acquire_Warning_Match_String --
3222 ----------------------------------
3224 procedure Acquire_Warning_Match_String (Arg : Node_Id) is
3225 begin
3226 String_To_Name_Buffer
3227 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
3229 -- Add asterisk at start if not already there
3231 if Name_Len > 0 and then Name_Buffer (1) /= '*' then
3232 Name_Buffer (2 .. Name_Len + 1) :=
3233 Name_Buffer (1 .. Name_Len);
3234 Name_Buffer (1) := '*';
3235 Name_Len := Name_Len + 1;
3236 end if;
3238 -- Add asterisk at end if not already there
3240 if Name_Buffer (Name_Len) /= '*' then
3241 Name_Len := Name_Len + 1;
3242 Name_Buffer (Name_Len) := '*';
3243 end if;
3244 end Acquire_Warning_Match_String;
3246 ---------------------
3247 -- Ada_2005_Pragma --
3248 ---------------------
3250 procedure Ada_2005_Pragma is
3251 begin
3252 if Ada_Version <= Ada_95 then
3253 Check_Restriction (No_Implementation_Pragmas, N);
3254 end if;
3255 end Ada_2005_Pragma;
3257 ---------------------
3258 -- Ada_2012_Pragma --
3259 ---------------------
3261 procedure Ada_2012_Pragma is
3262 begin
3263 if Ada_Version <= Ada_2005 then
3264 Check_Restriction (No_Implementation_Pragmas, N);
3265 end if;
3266 end Ada_2012_Pragma;
3268 ----------------------------
3269 -- Analyze_Depends_Global --
3270 ----------------------------
3272 procedure Analyze_Depends_Global is
3273 Spec_Id : Entity_Id;
3274 Subp_Decl : Node_Id;
3276 begin
3277 GNAT_Pragma;
3278 Check_Arg_Count (1);
3280 -- Ensure the proper placement of the pragma. Depends/Global must be
3281 -- associated with a subprogram declaration or a body that acts as a
3282 -- spec.
3284 Subp_Decl := Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
3286 -- Generic subprogram
3288 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
3289 null;
3291 -- Body acts as spec
3293 elsif Nkind (Subp_Decl) = N_Subprogram_Body
3294 and then No (Corresponding_Spec (Subp_Decl))
3295 then
3296 null;
3298 -- Body stub acts as spec
3300 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3301 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
3302 then
3303 null;
3305 -- Subprogram declaration
3307 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
3308 null;
3310 else
3311 Pragma_Misplaced;
3312 return;
3313 end if;
3315 Spec_Id := Corresponding_Spec_Of (Subp_Decl);
3317 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
3319 -- Fully analyze the pragma when it appears inside a subprogram body
3320 -- because it cannot benefit from forward references.
3322 if Nkind (Subp_Decl) = N_Subprogram_Body then
3323 if Pragma_Name (N) = Name_Depends then
3324 Analyze_Depends_In_Decl_Part (N);
3326 else pragma Assert (Pname = Name_Global);
3327 Analyze_Global_In_Decl_Part (N);
3328 end if;
3329 end if;
3331 -- Chain the pragma on the contract for further processing by
3332 -- Analyze_Depends_In_Decl_Part/Analyze_Global_In_Decl_Part.
3334 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
3335 end Analyze_Depends_Global;
3337 ---------------------
3338 -- Analyze_Part_Of --
3339 ---------------------
3341 procedure Analyze_Part_Of
3342 (Item_Id : Entity_Id;
3343 State : Node_Id;
3344 Indic : Node_Id;
3345 Legal : out Boolean)
3347 Pack_Id : Entity_Id;
3348 Placement : State_Space_Kind;
3349 Parent_Unit : Entity_Id;
3350 State_Id : Entity_Id;
3352 begin
3353 -- Assume that the pragma/option is illegal
3355 Legal := False;
3357 if Nkind_In (State, N_Expanded_Name,
3358 N_Identifier,
3359 N_Selected_Component)
3360 then
3361 Analyze (State);
3362 Resolve_State (State);
3364 if Is_Entity_Name (State)
3365 and then Ekind (Entity (State)) = E_Abstract_State
3366 then
3367 State_Id := Entity (State);
3369 else
3370 SPARK_Msg_N
3371 ("indicator Part_Of must denote an abstract state", State);
3372 return;
3373 end if;
3375 -- This is a syntax error, always report
3377 else
3378 Error_Msg_N
3379 ("indicator Part_Of must denote an abstract state", State);
3380 return;
3381 end if;
3383 -- Determine where the state, object or the package instantiation
3384 -- lives with respect to the enclosing packages or package bodies (if
3385 -- any). This placement dictates the legality of the encapsulating
3386 -- state.
3388 Find_Placement_In_State_Space
3389 (Item_Id => Item_Id,
3390 Placement => Placement,
3391 Pack_Id => Pack_Id);
3393 -- The item appears in a non-package construct with a declarative
3394 -- part (subprogram, block, etc). As such, the item is not allowed
3395 -- to be a part of an encapsulating state because the item is not
3396 -- visible.
3398 if Placement = Not_In_Package then
3399 SPARK_Msg_N
3400 ("indicator Part_Of cannot appear in this context "
3401 & "(SPARK RM 7.2.6(5))", Indic);
3402 Error_Msg_Name_1 := Chars (Scope (State_Id));
3403 SPARK_Msg_NE
3404 ("\& is not part of the hidden state of package %",
3405 Indic, Item_Id);
3407 -- The item appears in the visible state space of some package. In
3408 -- general this scenario does not warrant Part_Of except when the
3409 -- package is a private child unit and the encapsulating state is
3410 -- declared in a parent unit or a public descendant of that parent
3411 -- unit.
3413 elsif Placement = Visible_State_Space then
3414 if Is_Child_Unit (Pack_Id)
3415 and then Is_Private_Descendant (Pack_Id)
3416 then
3417 -- A variable or state abstraction which is part of the
3418 -- visible state of a private child unit (or one of its public
3419 -- descendants) must have its Part_Of indicator specified. The
3420 -- Part_Of indicator must denote a state abstraction declared
3421 -- by either the parent unit of the private unit or by a public
3422 -- descendant of that parent unit.
3424 -- Find nearest private ancestor (which can be the current unit
3425 -- itself).
3427 Parent_Unit := Pack_Id;
3428 while Present (Parent_Unit) loop
3429 exit when Private_Present
3430 (Parent (Unit_Declaration_Node (Parent_Unit)));
3431 Parent_Unit := Scope (Parent_Unit);
3432 end loop;
3434 Parent_Unit := Scope (Parent_Unit);
3436 if not Is_Child_Or_Sibling (Pack_Id, Scope (State_Id)) then
3437 SPARK_Msg_NE
3438 ("indicator Part_Of must denote an abstract state of& "
3439 & "or public descendant (SPARK RM 7.2.6(3))",
3440 Indic, Parent_Unit);
3442 elsif Scope (State_Id) = Parent_Unit
3443 or else (Is_Ancestor_Package (Parent_Unit, Scope (State_Id))
3444 and then
3445 not Is_Private_Descendant (Scope (State_Id)))
3446 then
3447 null;
3449 else
3450 SPARK_Msg_NE
3451 ("indicator Part_Of must denote an abstract state of& "
3452 & "or public descendant (SPARK RM 7.2.6(3))",
3453 Indic, Parent_Unit);
3454 end if;
3456 -- Indicator Part_Of is not needed when the related package is not
3457 -- a private child unit or a public descendant thereof.
3459 else
3460 SPARK_Msg_N
3461 ("indicator Part_Of cannot appear in this context "
3462 & "(SPARK RM 7.2.6(5))", Indic);
3463 Error_Msg_Name_1 := Chars (Pack_Id);
3464 SPARK_Msg_NE
3465 ("\& is declared in the visible part of package %",
3466 Indic, Item_Id);
3467 end if;
3469 -- When the item appears in the private state space of a package, the
3470 -- encapsulating state must be declared in the same package.
3472 elsif Placement = Private_State_Space then
3473 if Scope (State_Id) /= Pack_Id then
3474 SPARK_Msg_NE
3475 ("indicator Part_Of must designate an abstract state of "
3476 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3477 Error_Msg_Name_1 := Chars (Pack_Id);
3478 SPARK_Msg_NE
3479 ("\& is declared in the private part of package %",
3480 Indic, Item_Id);
3481 end if;
3483 -- Items declared in the body state space of a package do not need
3484 -- Part_Of indicators as the refinement has already been seen.
3486 else
3487 SPARK_Msg_N
3488 ("indicator Part_Of cannot appear in this context "
3489 & "(SPARK RM 7.2.6(5))", Indic);
3491 if Scope (State_Id) = Pack_Id then
3492 Error_Msg_Name_1 := Chars (Pack_Id);
3493 SPARK_Msg_NE
3494 ("\& is declared in the body of package %", Indic, Item_Id);
3495 end if;
3496 end if;
3498 Legal := True;
3499 end Analyze_Part_Of;
3501 --------------------------------
3502 -- Analyze_Pre_Post_Condition --
3503 --------------------------------
3505 procedure Analyze_Pre_Post_Condition is
3506 Prag_Iden : constant Node_Id := Pragma_Identifier (N);
3507 Subp_Decl : Node_Id;
3509 Duplicates_OK : Boolean := False;
3510 -- Flag set when a pre/postcondition allows multiple pragmas of the
3511 -- same kind.
3513 In_Body_OK : Boolean := False;
3514 -- Flag set when a pre/postcondition is allowed to appear on a body
3515 -- even though the subprogram may have a spec.
3517 Is_Pre_Post : Boolean := False;
3518 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
3519 -- Post_Class.
3521 begin
3522 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
3523 -- offer uniformity among the various kinds of pre/postconditions by
3524 -- rewriting the pragma identifier. This allows the retrieval of the
3525 -- original pragma name by routine Original_Aspect_Pragma_Name.
3527 if Comes_From_Source (N) then
3528 if Nam_In (Pname, Name_Pre, Name_Pre_Class) then
3529 Is_Pre_Post := True;
3530 Set_Class_Present (N, Pname = Name_Pre_Class);
3531 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition));
3533 elsif Nam_In (Pname, Name_Post, Name_Post_Class) then
3534 Is_Pre_Post := True;
3535 Set_Class_Present (N, Pname = Name_Post_Class);
3536 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition));
3537 end if;
3538 end if;
3540 -- Determine the semantics with respect to duplicates and placement
3541 -- in a body. Pragmas Precondition and Postcondition were introduced
3542 -- before aspects and are not subject to the same aspect-like rules.
3544 if Nam_In (Pname, Name_Precondition, Name_Postcondition) then
3545 Duplicates_OK := True;
3546 In_Body_OK := True;
3547 end if;
3549 GNAT_Pragma;
3551 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
3552 -- argument without an identifier.
3554 if Is_Pre_Post then
3555 Check_Arg_Count (1);
3556 Check_No_Identifiers;
3558 -- Pragmas Precondition and Postcondition have complex argument
3559 -- profile.
3561 else
3562 Check_At_Least_N_Arguments (1);
3563 Check_At_Most_N_Arguments (2);
3564 Check_Optional_Identifier (Arg1, Name_Check);
3566 if Present (Arg2) then
3567 Check_Optional_Identifier (Arg2, Name_Message);
3568 Preanalyze_Spec_Expression
3569 (Get_Pragma_Arg (Arg2), Standard_String);
3570 end if;
3571 end if;
3573 -- For a pragma PPC in the extended main source unit, record enabled
3574 -- status in SCO.
3575 -- ??? nothing checks that the pragma is in the main source unit
3577 if Is_Checked (N) and then not Split_PPC (N) then
3578 Set_SCO_Pragma_Enabled (Loc);
3579 end if;
3581 -- Ensure the proper placement of the pragma
3583 Subp_Decl :=
3584 Find_Related_Subprogram_Or_Body (N, Do_Checks => not Duplicates_OK);
3586 -- When a pre/postcondition pragma applies to an abstract subprogram,
3587 -- its original form must be an aspect with 'Class.
3589 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
3590 if not From_Aspect_Specification (N) then
3591 Error_Pragma
3592 ("pragma % cannot be applied to abstract subprogram");
3594 elsif not Class_Present (N) then
3595 Error_Pragma
3596 ("aspect % requires ''Class for abstract subprogram");
3597 end if;
3599 -- Entry declaration
3601 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
3602 null;
3604 -- Generic subprogram declaration
3606 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
3607 null;
3609 -- Subprogram body
3611 elsif Nkind (Subp_Decl) = N_Subprogram_Body
3612 and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK)
3613 then
3614 null;
3616 -- Subprogram body stub
3618 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3619 and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK)
3620 then
3621 null;
3623 -- Subprogram declaration
3625 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
3627 -- AI05-0230: When a pre/postcondition pragma applies to a null
3628 -- procedure, its original form must be an aspect with 'Class.
3630 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
3631 and then Null_Present (Specification (Subp_Decl))
3632 and then From_Aspect_Specification (N)
3633 and then not Class_Present (N)
3634 then
3635 Error_Pragma ("aspect % requires ''Class for null procedure");
3636 end if;
3638 -- Otherwise the placement is illegal
3640 else
3641 Pragma_Misplaced;
3642 return;
3643 end if;
3645 -- Fully analyze the pragma when it appears inside a subprogram
3646 -- body because it cannot benefit from forward references.
3648 if Nkind_In (Subp_Decl, N_Subprogram_Body,
3649 N_Subprogram_Body_Stub)
3650 then
3651 Analyze_Pre_Post_Condition_In_Decl_Part (N);
3652 end if;
3654 -- Chain the pragma on the contract for further processing by
3655 -- Analyze_Pre_Post_Condition_In_Decl_Part.
3657 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
3658 end Analyze_Pre_Post_Condition;
3660 -----------------------------------------
3661 -- Analyze_Refined_Depends_Global_Post --
3662 -----------------------------------------
3664 procedure Analyze_Refined_Depends_Global_Post
3665 (Spec_Id : out Entity_Id;
3666 Body_Id : out Entity_Id;
3667 Legal : out Boolean)
3669 Body_Decl : Node_Id;
3670 Spec_Decl : Node_Id;
3672 begin
3673 -- Assume that the pragma is illegal
3675 Spec_Id := Empty;
3676 Body_Id := Empty;
3677 Legal := False;
3679 GNAT_Pragma;
3680 Check_Arg_Count (1);
3681 Check_No_Identifiers;
3683 -- Verify the placement of the pragma and check for duplicates. The
3684 -- pragma must apply to a subprogram body [stub].
3686 Body_Decl := Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
3688 -- Extract the entities of the spec and body
3690 if Nkind (Body_Decl) = N_Subprogram_Body then
3691 Body_Id := Defining_Entity (Body_Decl);
3692 Spec_Id := Corresponding_Spec (Body_Decl);
3694 elsif Nkind (Body_Decl) = N_Subprogram_Body_Stub then
3695 Body_Id := Defining_Entity (Body_Decl);
3696 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
3698 else
3699 Pragma_Misplaced;
3700 return;
3701 end if;
3703 -- The pragma must apply to the second declaration of a subprogram.
3704 -- In other words, the body [stub] cannot acts as a spec.
3706 if No (Spec_Id) then
3707 Error_Pragma ("pragma % cannot apply to a stand alone body");
3708 return;
3710 -- Catch the case where the subprogram body is a subunit and acts as
3711 -- the third declaration of the subprogram.
3713 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
3714 Error_Pragma ("pragma % cannot apply to a subunit");
3715 return;
3716 end if;
3718 -- The pragma can only apply to the body [stub] of a subprogram
3719 -- declared in the visible part of a package. Retrieve the context of
3720 -- the subprogram declaration.
3722 Spec_Decl := Unit_Declaration_Node (Spec_Id);
3724 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
3725 Error_Pragma
3726 ("pragma % must apply to the body of a subprogram declared in a "
3727 & "package specification");
3728 return;
3729 end if;
3731 -- If we get here, then the pragma is legal
3733 if Nam_In (Pname, Name_Refined_Depends,
3734 Name_Refined_Global,
3735 Name_Refined_State)
3736 then
3737 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
3738 end if;
3740 Legal := True;
3741 end Analyze_Refined_Depends_Global_Post;
3743 --------------------------
3744 -- Check_Ada_83_Warning --
3745 --------------------------
3747 procedure Check_Ada_83_Warning is
3748 begin
3749 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
3750 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
3751 end if;
3752 end Check_Ada_83_Warning;
3754 ---------------------
3755 -- Check_Arg_Count --
3756 ---------------------
3758 procedure Check_Arg_Count (Required : Nat) is
3759 begin
3760 if Arg_Count /= Required then
3761 Error_Pragma ("wrong number of arguments for pragma%");
3762 end if;
3763 end Check_Arg_Count;
3765 --------------------------------
3766 -- Check_Arg_Is_External_Name --
3767 --------------------------------
3769 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
3770 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3772 begin
3773 if Nkind (Argx) = N_Identifier then
3774 return;
3776 else
3777 Analyze_And_Resolve (Argx, Standard_String);
3779 if Is_OK_Static_Expression (Argx) then
3780 return;
3782 elsif Etype (Argx) = Any_Type then
3783 raise Pragma_Exit;
3785 -- An interesting special case, if we have a string literal and
3786 -- we are in Ada 83 mode, then we allow it even though it will
3787 -- not be flagged as static. This allows expected Ada 83 mode
3788 -- use of external names which are string literals, even though
3789 -- technically these are not static in Ada 83.
3791 elsif Ada_Version = Ada_83
3792 and then Nkind (Argx) = N_String_Literal
3793 then
3794 return;
3796 -- Static expression that raises Constraint_Error. This has
3797 -- already been flagged, so just exit from pragma processing.
3799 elsif Is_OK_Static_Expression (Argx) then
3800 raise Pragma_Exit;
3802 -- Here we have a real error (non-static expression)
3804 else
3805 Error_Msg_Name_1 := Pname;
3807 declare
3808 Msg : constant String :=
3809 "argument for pragma% must be a identifier or "
3810 & "static string expression!";
3811 begin
3812 Flag_Non_Static_Expr (Fix_Error (Msg), Argx);
3813 raise Pragma_Exit;
3814 end;
3815 end if;
3816 end if;
3817 end Check_Arg_Is_External_Name;
3819 -----------------------------
3820 -- Check_Arg_Is_Identifier --
3821 -----------------------------
3823 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
3824 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3825 begin
3826 if Nkind (Argx) /= N_Identifier then
3827 Error_Pragma_Arg
3828 ("argument for pragma% must be identifier", Argx);
3829 end if;
3830 end Check_Arg_Is_Identifier;
3832 ----------------------------------
3833 -- Check_Arg_Is_Integer_Literal --
3834 ----------------------------------
3836 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
3837 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3838 begin
3839 if Nkind (Argx) /= N_Integer_Literal then
3840 Error_Pragma_Arg
3841 ("argument for pragma% must be integer literal", Argx);
3842 end if;
3843 end Check_Arg_Is_Integer_Literal;
3845 -------------------------------------------
3846 -- Check_Arg_Is_Library_Level_Local_Name --
3847 -------------------------------------------
3849 -- LOCAL_NAME ::=
3850 -- DIRECT_NAME
3851 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3852 -- | library_unit_NAME
3854 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
3855 begin
3856 Check_Arg_Is_Local_Name (Arg);
3858 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
3859 and then Comes_From_Source (N)
3860 then
3861 Error_Pragma_Arg
3862 ("argument for pragma% must be library level entity", Arg);
3863 end if;
3864 end Check_Arg_Is_Library_Level_Local_Name;
3866 -----------------------------
3867 -- Check_Arg_Is_Local_Name --
3868 -----------------------------
3870 -- LOCAL_NAME ::=
3871 -- DIRECT_NAME
3872 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3873 -- | library_unit_NAME
3875 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
3876 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3878 begin
3879 Analyze (Argx);
3881 if Nkind (Argx) not in N_Direct_Name
3882 and then (Nkind (Argx) /= N_Attribute_Reference
3883 or else Present (Expressions (Argx))
3884 or else Nkind (Prefix (Argx)) /= N_Identifier)
3885 and then (not Is_Entity_Name (Argx)
3886 or else not Is_Compilation_Unit (Entity (Argx)))
3887 then
3888 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
3889 end if;
3891 -- No further check required if not an entity name
3893 if not Is_Entity_Name (Argx) then
3894 null;
3896 else
3897 declare
3898 OK : Boolean;
3899 Ent : constant Entity_Id := Entity (Argx);
3900 Scop : constant Entity_Id := Scope (Ent);
3902 begin
3903 -- Case of a pragma applied to a compilation unit: pragma must
3904 -- occur immediately after the program unit in the compilation.
3906 if Is_Compilation_Unit (Ent) then
3907 declare
3908 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
3910 begin
3911 -- Case of pragma placed immediately after spec
3913 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
3914 OK := True;
3916 -- Case of pragma placed immediately after body
3918 elsif Nkind (Decl) = N_Subprogram_Declaration
3919 and then Present (Corresponding_Body (Decl))
3920 then
3921 OK := Parent (N) =
3922 Aux_Decls_Node
3923 (Parent (Unit_Declaration_Node
3924 (Corresponding_Body (Decl))));
3926 -- All other cases are illegal
3928 else
3929 OK := False;
3930 end if;
3931 end;
3933 -- Special restricted placement rule from 10.2.1(11.8/2)
3935 elsif Is_Generic_Formal (Ent)
3936 and then Prag_Id = Pragma_Preelaborable_Initialization
3937 then
3938 OK := List_Containing (N) =
3939 Generic_Formal_Declarations
3940 (Unit_Declaration_Node (Scop));
3942 -- If this is an aspect applied to a subprogram body, the
3943 -- pragma is inserted in its declarative part.
3945 elsif From_Aspect_Specification (N)
3946 and then Ent = Current_Scope
3947 and then
3948 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
3949 then
3950 OK := True;
3952 -- If the aspect is a predicate (possibly others ???) and the
3953 -- context is a record type, this is a discriminant expression
3954 -- within a type declaration, that freezes the predicated
3955 -- subtype.
3957 elsif From_Aspect_Specification (N)
3958 and then Prag_Id = Pragma_Predicate
3959 and then Ekind (Current_Scope) = E_Record_Type
3960 and then Scop = Scope (Current_Scope)
3961 then
3962 OK := True;
3964 -- Default case, just check that the pragma occurs in the scope
3965 -- of the entity denoted by the name.
3967 else
3968 OK := Current_Scope = Scop;
3969 end if;
3971 if not OK then
3972 Error_Pragma_Arg
3973 ("pragma% argument must be in same declarative part", Arg);
3974 end if;
3975 end;
3976 end if;
3977 end Check_Arg_Is_Local_Name;
3979 ---------------------------------
3980 -- Check_Arg_Is_Locking_Policy --
3981 ---------------------------------
3983 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
3984 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3986 begin
3987 Check_Arg_Is_Identifier (Argx);
3989 if not Is_Locking_Policy_Name (Chars (Argx)) then
3990 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
3991 end if;
3992 end Check_Arg_Is_Locking_Policy;
3994 -----------------------------------------------
3995 -- Check_Arg_Is_Partition_Elaboration_Policy --
3996 -----------------------------------------------
3998 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
3999 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4001 begin
4002 Check_Arg_Is_Identifier (Argx);
4004 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
4005 Error_Pragma_Arg
4006 ("& is not a valid partition elaboration policy name", Argx);
4007 end if;
4008 end Check_Arg_Is_Partition_Elaboration_Policy;
4010 -------------------------
4011 -- Check_Arg_Is_One_Of --
4012 -------------------------
4014 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
4015 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4017 begin
4018 Check_Arg_Is_Identifier (Argx);
4020 if not Nam_In (Chars (Argx), N1, N2) then
4021 Error_Msg_Name_2 := N1;
4022 Error_Msg_Name_3 := N2;
4023 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
4024 end if;
4025 end Check_Arg_Is_One_Of;
4027 procedure Check_Arg_Is_One_Of
4028 (Arg : Node_Id;
4029 N1, N2, N3 : Name_Id)
4031 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4033 begin
4034 Check_Arg_Is_Identifier (Argx);
4036 if not Nam_In (Chars (Argx), N1, N2, N3) then
4037 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
4038 end if;
4039 end Check_Arg_Is_One_Of;
4041 procedure Check_Arg_Is_One_Of
4042 (Arg : Node_Id;
4043 N1, N2, N3, N4 : Name_Id)
4045 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4047 begin
4048 Check_Arg_Is_Identifier (Argx);
4050 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
4051 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
4052 end if;
4053 end Check_Arg_Is_One_Of;
4055 procedure Check_Arg_Is_One_Of
4056 (Arg : Node_Id;
4057 N1, N2, N3, N4, N5 : Name_Id)
4059 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4061 begin
4062 Check_Arg_Is_Identifier (Argx);
4064 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
4065 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
4066 end if;
4067 end Check_Arg_Is_One_Of;
4069 ---------------------------------
4070 -- Check_Arg_Is_Queuing_Policy --
4071 ---------------------------------
4073 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
4074 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4076 begin
4077 Check_Arg_Is_Identifier (Argx);
4079 if not Is_Queuing_Policy_Name (Chars (Argx)) then
4080 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
4081 end if;
4082 end Check_Arg_Is_Queuing_Policy;
4084 ---------------------------------------
4085 -- Check_Arg_Is_OK_Static_Expression --
4086 ---------------------------------------
4088 procedure Check_Arg_Is_OK_Static_Expression
4089 (Arg : Node_Id;
4090 Typ : Entity_Id := Empty)
4092 begin
4093 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
4094 end Check_Arg_Is_OK_Static_Expression;
4096 ------------------------------------------
4097 -- Check_Arg_Is_Task_Dispatching_Policy --
4098 ------------------------------------------
4100 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
4101 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4103 begin
4104 Check_Arg_Is_Identifier (Argx);
4106 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
4107 Error_Pragma_Arg
4108 ("& is not an allowed task dispatching policy name", Argx);
4109 end if;
4110 end Check_Arg_Is_Task_Dispatching_Policy;
4112 ---------------------
4113 -- Check_Arg_Order --
4114 ---------------------
4116 procedure Check_Arg_Order (Names : Name_List) is
4117 Arg : Node_Id;
4119 Highest_So_Far : Natural := 0;
4120 -- Highest index in Names seen do far
4122 begin
4123 Arg := Arg1;
4124 for J in 1 .. Arg_Count loop
4125 if Chars (Arg) /= No_Name then
4126 for K in Names'Range loop
4127 if Chars (Arg) = Names (K) then
4128 if K < Highest_So_Far then
4129 Error_Msg_Name_1 := Pname;
4130 Error_Msg_N
4131 ("parameters out of order for pragma%", Arg);
4132 Error_Msg_Name_1 := Names (K);
4133 Error_Msg_Name_2 := Names (Highest_So_Far);
4134 Error_Msg_N ("\% must appear before %", Arg);
4135 raise Pragma_Exit;
4137 else
4138 Highest_So_Far := K;
4139 end if;
4140 end if;
4141 end loop;
4142 end if;
4144 Arg := Next (Arg);
4145 end loop;
4146 end Check_Arg_Order;
4148 --------------------------------
4149 -- Check_At_Least_N_Arguments --
4150 --------------------------------
4152 procedure Check_At_Least_N_Arguments (N : Nat) is
4153 begin
4154 if Arg_Count < N then
4155 Error_Pragma ("too few arguments for pragma%");
4156 end if;
4157 end Check_At_Least_N_Arguments;
4159 -------------------------------
4160 -- Check_At_Most_N_Arguments --
4161 -------------------------------
4163 procedure Check_At_Most_N_Arguments (N : Nat) is
4164 Arg : Node_Id;
4165 begin
4166 if Arg_Count > N then
4167 Arg := Arg1;
4168 for J in 1 .. N loop
4169 Next (Arg);
4170 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
4171 end loop;
4172 end if;
4173 end Check_At_Most_N_Arguments;
4175 ---------------------
4176 -- Check_Component --
4177 ---------------------
4179 procedure Check_Component
4180 (Comp : Node_Id;
4181 UU_Typ : Entity_Id;
4182 In_Variant_Part : Boolean := False)
4184 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
4185 Sindic : constant Node_Id :=
4186 Subtype_Indication (Component_Definition (Comp));
4187 Typ : constant Entity_Id := Etype (Comp_Id);
4189 begin
4190 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
4191 -- object constraint, then the component type shall be an Unchecked_
4192 -- Union.
4194 if Nkind (Sindic) = N_Subtype_Indication
4195 and then Has_Per_Object_Constraint (Comp_Id)
4196 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
4197 then
4198 Error_Msg_N
4199 ("component subtype subject to per-object constraint "
4200 & "must be an Unchecked_Union", Comp);
4202 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
4203 -- the body of a generic unit, or within the body of any of its
4204 -- descendant library units, no part of the type of a component
4205 -- declared in a variant_part of the unchecked union type shall be of
4206 -- a formal private type or formal private extension declared within
4207 -- the formal part of the generic unit.
4209 elsif Ada_Version >= Ada_2012
4210 and then In_Generic_Body (UU_Typ)
4211 and then In_Variant_Part
4212 and then Is_Private_Type (Typ)
4213 and then Is_Generic_Type (Typ)
4214 then
4215 Error_Msg_N
4216 ("component of unchecked union cannot be of generic type", Comp);
4218 elsif Needs_Finalization (Typ) then
4219 Error_Msg_N
4220 ("component of unchecked union cannot be controlled", Comp);
4222 elsif Has_Task (Typ) then
4223 Error_Msg_N
4224 ("component of unchecked union cannot have tasks", Comp);
4225 end if;
4226 end Check_Component;
4228 -----------------------------
4229 -- Check_Declaration_Order --
4230 -----------------------------
4232 procedure Check_Declaration_Order (First : Node_Id; Second : Node_Id) is
4233 procedure Check_Aspect_Specification_Order;
4234 -- Inspect the aspect specifications of the context to determine the
4235 -- proper order.
4237 --------------------------------------
4238 -- Check_Aspect_Specification_Order --
4239 --------------------------------------
4241 procedure Check_Aspect_Specification_Order is
4242 Asp_First : constant Node_Id := Corresponding_Aspect (First);
4243 Asp_Second : constant Node_Id := Corresponding_Aspect (Second);
4244 Asp : Node_Id;
4246 begin
4247 -- Both aspects must be part of the same aspect specification list
4249 pragma Assert
4250 (List_Containing (Asp_First) = List_Containing (Asp_Second));
4252 -- Try to reach Second starting from First in a left to right
4253 -- traversal of the aspect specifications.
4255 Asp := Next (Asp_First);
4256 while Present (Asp) loop
4258 -- The order is ok, First is followed by Second
4260 if Asp = Asp_Second then
4261 return;
4262 end if;
4264 Next (Asp);
4265 end loop;
4267 -- If we get here, then the aspects are out of order
4269 SPARK_Msg_N ("aspect % cannot come after aspect %", First);
4270 end Check_Aspect_Specification_Order;
4272 -- Local variables
4274 Stmt : Node_Id;
4276 -- Start of processing for Check_Declaration_Order
4278 begin
4279 -- Cannot check the order if one of the pragmas is missing
4281 if No (First) or else No (Second) then
4282 return;
4283 end if;
4285 -- Set up the error names in case the order is incorrect
4287 Error_Msg_Name_1 := Pragma_Name (First);
4288 Error_Msg_Name_2 := Pragma_Name (Second);
4290 if From_Aspect_Specification (First) then
4292 -- Both pragmas are actually aspects, check their declaration
4293 -- order in the associated aspect specification list. Otherwise
4294 -- First is an aspect and Second a source pragma.
4296 if From_Aspect_Specification (Second) then
4297 Check_Aspect_Specification_Order;
4298 end if;
4300 -- Abstract_States is a source pragma
4302 else
4303 if From_Aspect_Specification (Second) then
4304 SPARK_Msg_N ("pragma % cannot come after aspect %", First);
4306 -- Both pragmas are source constructs. Try to reach First from
4307 -- Second by traversing the declarations backwards.
4309 else
4310 Stmt := Prev (Second);
4311 while Present (Stmt) loop
4313 -- The order is ok, First is followed by Second
4315 if Stmt = First then
4316 return;
4317 end if;
4319 Prev (Stmt);
4320 end loop;
4322 -- If we get here, then the pragmas are out of order
4324 SPARK_Msg_N ("pragma % cannot come after pragma %", First);
4325 end if;
4326 end if;
4327 end Check_Declaration_Order;
4329 ----------------------------
4330 -- Check_Duplicate_Pragma --
4331 ----------------------------
4333 procedure Check_Duplicate_Pragma (E : Entity_Id) is
4334 Id : Entity_Id := E;
4335 P : Node_Id;
4337 begin
4338 -- Nothing to do if this pragma comes from an aspect specification,
4339 -- since we could not be duplicating a pragma, and we dealt with the
4340 -- case of duplicated aspects in Analyze_Aspect_Specifications.
4342 if From_Aspect_Specification (N) then
4343 return;
4344 end if;
4346 -- Otherwise current pragma may duplicate previous pragma or a
4347 -- previously given aspect specification or attribute definition
4348 -- clause for the same pragma.
4350 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
4352 if Present (P) then
4354 -- If the entity is a type, then we have to make sure that the
4355 -- ostensible duplicate is not for a parent type from which this
4356 -- type is derived.
4358 if Is_Type (E) then
4359 if Nkind (P) = N_Pragma then
4360 declare
4361 Args : constant List_Id :=
4362 Pragma_Argument_Associations (P);
4363 begin
4364 if Present (Args)
4365 and then Is_Entity_Name (Expression (First (Args)))
4366 and then Is_Type (Entity (Expression (First (Args))))
4367 and then Entity (Expression (First (Args))) /= E
4368 then
4369 return;
4370 end if;
4371 end;
4373 elsif Nkind (P) = N_Aspect_Specification
4374 and then Is_Type (Entity (P))
4375 and then Entity (P) /= E
4376 then
4377 return;
4378 end if;
4379 end if;
4381 -- Here we have a definite duplicate
4383 Error_Msg_Name_1 := Pragma_Name (N);
4384 Error_Msg_Sloc := Sloc (P);
4386 -- For a single protected or a single task object, the error is
4387 -- issued on the original entity.
4389 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
4390 Id := Defining_Identifier (Original_Node (Parent (Id)));
4391 end if;
4393 if Nkind (P) = N_Aspect_Specification
4394 or else From_Aspect_Specification (P)
4395 then
4396 Error_Msg_NE ("aspect% for & previously given#", N, Id);
4397 else
4398 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
4399 end if;
4401 raise Pragma_Exit;
4402 end if;
4403 end Check_Duplicate_Pragma;
4405 ----------------------------------
4406 -- Check_Duplicated_Export_Name --
4407 ----------------------------------
4409 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
4410 String_Val : constant String_Id := Strval (Nam);
4412 begin
4413 -- We are only interested in the export case, and in the case of
4414 -- generics, it is the instance, not the template, that is the
4415 -- problem (the template will generate a warning in any case).
4417 if not Inside_A_Generic
4418 and then (Prag_Id = Pragma_Export
4419 or else
4420 Prag_Id = Pragma_Export_Procedure
4421 or else
4422 Prag_Id = Pragma_Export_Valued_Procedure
4423 or else
4424 Prag_Id = Pragma_Export_Function)
4425 then
4426 for J in Externals.First .. Externals.Last loop
4427 if String_Equal (String_Val, Strval (Externals.Table (J))) then
4428 Error_Msg_Sloc := Sloc (Externals.Table (J));
4429 Error_Msg_N ("external name duplicates name given#", Nam);
4430 exit;
4431 end if;
4432 end loop;
4434 Externals.Append (Nam);
4435 end if;
4436 end Check_Duplicated_Export_Name;
4438 ----------------------------------------
4439 -- Check_Expr_Is_OK_Static_Expression --
4440 ----------------------------------------
4442 procedure Check_Expr_Is_OK_Static_Expression
4443 (Expr : Node_Id;
4444 Typ : Entity_Id := Empty)
4446 begin
4447 if Present (Typ) then
4448 Analyze_And_Resolve (Expr, Typ);
4449 else
4450 Analyze_And_Resolve (Expr);
4451 end if;
4453 if Is_OK_Static_Expression (Expr) then
4454 return;
4456 elsif Etype (Expr) = Any_Type then
4457 raise Pragma_Exit;
4459 -- An interesting special case, if we have a string literal and we
4460 -- are in Ada 83 mode, then we allow it even though it will not be
4461 -- flagged as static. This allows the use of Ada 95 pragmas like
4462 -- Import in Ada 83 mode. They will of course be flagged with
4463 -- warnings as usual, but will not cause errors.
4465 elsif Ada_Version = Ada_83
4466 and then Nkind (Expr) = N_String_Literal
4467 then
4468 return;
4470 -- Static expression that raises Constraint_Error. This has already
4471 -- been flagged, so just exit from pragma processing.
4473 elsif Is_OK_Static_Expression (Expr) then
4474 raise Pragma_Exit;
4476 -- Finally, we have a real error
4478 else
4479 Error_Msg_Name_1 := Pname;
4480 Flag_Non_Static_Expr
4481 (Fix_Error ("argument for pragma% must be a static expression!"),
4482 Expr);
4483 raise Pragma_Exit;
4484 end if;
4485 end Check_Expr_Is_OK_Static_Expression;
4487 -------------------------
4488 -- Check_First_Subtype --
4489 -------------------------
4491 procedure Check_First_Subtype (Arg : Node_Id) is
4492 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4493 Ent : constant Entity_Id := Entity (Argx);
4495 begin
4496 if Is_First_Subtype (Ent) then
4497 null;
4499 elsif Is_Type (Ent) then
4500 Error_Pragma_Arg
4501 ("pragma% cannot apply to subtype", Argx);
4503 elsif Is_Object (Ent) then
4504 Error_Pragma_Arg
4505 ("pragma% cannot apply to object, requires a type", Argx);
4507 else
4508 Error_Pragma_Arg
4509 ("pragma% cannot apply to&, requires a type", Argx);
4510 end if;
4511 end Check_First_Subtype;
4513 ----------------------
4514 -- Check_Identifier --
4515 ----------------------
4517 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
4518 begin
4519 if Present (Arg)
4520 and then Nkind (Arg) = N_Pragma_Argument_Association
4521 then
4522 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
4523 Error_Msg_Name_1 := Pname;
4524 Error_Msg_Name_2 := Id;
4525 Error_Msg_N ("pragma% argument expects identifier%", Arg);
4526 raise Pragma_Exit;
4527 end if;
4528 end if;
4529 end Check_Identifier;
4531 --------------------------------
4532 -- Check_Identifier_Is_One_Of --
4533 --------------------------------
4535 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
4536 begin
4537 if Present (Arg)
4538 and then Nkind (Arg) = N_Pragma_Argument_Association
4539 then
4540 if Chars (Arg) = No_Name then
4541 Error_Msg_Name_1 := Pname;
4542 Error_Msg_N ("pragma% argument expects an identifier", Arg);
4543 raise Pragma_Exit;
4545 elsif Chars (Arg) /= N1
4546 and then Chars (Arg) /= N2
4547 then
4548 Error_Msg_Name_1 := Pname;
4549 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
4550 raise Pragma_Exit;
4551 end if;
4552 end if;
4553 end Check_Identifier_Is_One_Of;
4555 ---------------------------
4556 -- Check_In_Main_Program --
4557 ---------------------------
4559 procedure Check_In_Main_Program is
4560 P : constant Node_Id := Parent (N);
4562 begin
4563 -- Must be at in subprogram body
4565 if Nkind (P) /= N_Subprogram_Body then
4566 Error_Pragma ("% pragma allowed only in subprogram");
4568 -- Otherwise warn if obviously not main program
4570 elsif Present (Parameter_Specifications (Specification (P)))
4571 or else not Is_Compilation_Unit (Defining_Entity (P))
4572 then
4573 Error_Msg_Name_1 := Pname;
4574 Error_Msg_N
4575 ("??pragma% is only effective in main program", N);
4576 end if;
4577 end Check_In_Main_Program;
4579 ---------------------------------------
4580 -- Check_Interrupt_Or_Attach_Handler --
4581 ---------------------------------------
4583 procedure Check_Interrupt_Or_Attach_Handler is
4584 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4585 Handler_Proc, Proc_Scope : Entity_Id;
4587 begin
4588 Analyze (Arg1_X);
4590 if Prag_Id = Pragma_Interrupt_Handler then
4591 Check_Restriction (No_Dynamic_Attachment, N);
4592 end if;
4594 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
4595 Proc_Scope := Scope (Handler_Proc);
4597 -- On AAMP only, a pragma Interrupt_Handler is supported for
4598 -- nonprotected parameterless procedures.
4600 if not AAMP_On_Target
4601 or else Prag_Id = Pragma_Attach_Handler
4602 then
4603 if Ekind (Proc_Scope) /= E_Protected_Type then
4604 Error_Pragma_Arg
4605 ("argument of pragma% must be protected procedure", Arg1);
4606 end if;
4608 -- For pragma case (as opposed to access case), check placement.
4609 -- We don't need to do that for aspects, because we have the
4610 -- check that they aspect applies an appropriate procedure.
4612 if not From_Aspect_Specification (N)
4613 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
4614 then
4615 Error_Pragma ("pragma% must be in protected definition");
4616 end if;
4617 end if;
4619 if not Is_Library_Level_Entity (Proc_Scope)
4620 or else (AAMP_On_Target
4621 and then not Is_Library_Level_Entity (Handler_Proc))
4622 then
4623 Error_Pragma_Arg
4624 ("argument for pragma% must be library level entity", Arg1);
4625 end if;
4627 -- AI05-0033: A pragma cannot appear within a generic body, because
4628 -- instance can be in a nested scope. The check that protected type
4629 -- is itself a library-level declaration is done elsewhere.
4631 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
4632 -- handle code prior to AI-0033. Analysis tools typically are not
4633 -- interested in this pragma in any case, so no need to worry too
4634 -- much about its placement.
4636 if Inside_A_Generic then
4637 if Ekind (Scope (Current_Scope)) = E_Generic_Package
4638 and then In_Package_Body (Scope (Current_Scope))
4639 and then not Relaxed_RM_Semantics
4640 then
4641 Error_Pragma ("pragma% cannot be used inside a generic");
4642 end if;
4643 end if;
4644 end Check_Interrupt_Or_Attach_Handler;
4646 ---------------------------------
4647 -- Check_Loop_Pragma_Placement --
4648 ---------------------------------
4650 procedure Check_Loop_Pragma_Placement is
4651 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
4652 -- Verify whether the current pragma is properly grouped with other
4653 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
4654 -- related loop where the pragma appears.
4656 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
4657 -- Determine whether an arbitrary statement Stmt denotes pragma
4658 -- Loop_Invariant or Loop_Variant.
4660 procedure Placement_Error (Constr : Node_Id);
4661 pragma No_Return (Placement_Error);
4662 -- Node Constr denotes the last loop restricted construct before we
4663 -- encountered an illegal relation between enclosing constructs. Emit
4664 -- an error depending on what Constr was.
4666 --------------------------------
4667 -- Check_Loop_Pragma_Grouping --
4668 --------------------------------
4670 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
4671 Stop_Search : exception;
4672 -- This exception is used to terminate the recursive descent of
4673 -- routine Check_Grouping.
4675 procedure Check_Grouping (L : List_Id);
4676 -- Find the first group of pragmas in list L and if successful,
4677 -- ensure that the current pragma is part of that group. The
4678 -- routine raises Stop_Search once such a check is performed to
4679 -- halt the recursive descent.
4681 procedure Grouping_Error (Prag : Node_Id);
4682 pragma No_Return (Grouping_Error);
4683 -- Emit an error concerning the current pragma indicating that it
4684 -- should be placed after pragma Prag.
4686 --------------------
4687 -- Check_Grouping --
4688 --------------------
4690 procedure Check_Grouping (L : List_Id) is
4691 HSS : Node_Id;
4692 Prag : Node_Id;
4693 Stmt : Node_Id;
4695 begin
4696 -- Inspect the list of declarations or statements looking for
4697 -- the first grouping of pragmas:
4699 -- loop
4700 -- pragma Loop_Invariant ...;
4701 -- pragma Loop_Variant ...;
4702 -- . . . -- (1)
4703 -- pragma Loop_Variant ...; -- current pragma
4705 -- If the current pragma is not in the grouping, then it must
4706 -- either appear in a different declarative or statement list
4707 -- or the construct at (1) is separating the pragma from the
4708 -- grouping.
4710 Stmt := First (L);
4711 while Present (Stmt) loop
4713 -- Pragmas Loop_Invariant and Loop_Variant may only appear
4714 -- inside a loop or a block housed inside a loop. Inspect
4715 -- the declarations and statements of the block as they may
4716 -- contain the first grouping.
4718 if Nkind (Stmt) = N_Block_Statement then
4719 HSS := Handled_Statement_Sequence (Stmt);
4721 Check_Grouping (Declarations (Stmt));
4723 if Present (HSS) then
4724 Check_Grouping (Statements (HSS));
4725 end if;
4727 -- First pragma of the first topmost grouping has been found
4729 elsif Is_Loop_Pragma (Stmt) then
4731 -- The group and the current pragma are not in the same
4732 -- declarative or statement list.
4734 if List_Containing (Stmt) /= List_Containing (N) then
4735 Grouping_Error (Stmt);
4737 -- Try to reach the current pragma from the first pragma
4738 -- of the grouping while skipping other members:
4740 -- pragma Loop_Invariant ...; -- first pragma
4741 -- pragma Loop_Variant ...; -- member
4742 -- . . .
4743 -- pragma Loop_Variant ...; -- current pragma
4745 else
4746 while Present (Stmt) loop
4748 -- The current pragma is either the first pragma
4749 -- of the group or is a member of the group. Stop
4750 -- the search as the placement is legal.
4752 if Stmt = N then
4753 raise Stop_Search;
4755 -- Skip group members, but keep track of the last
4756 -- pragma in the group.
4758 elsif Is_Loop_Pragma (Stmt) then
4759 Prag := Stmt;
4761 -- A non-pragma is separating the group from the
4762 -- current pragma, the placement is illegal.
4764 else
4765 Grouping_Error (Prag);
4766 end if;
4768 Next (Stmt);
4769 end loop;
4771 -- If the traversal did not reach the current pragma,
4772 -- then the list must be malformed.
4774 raise Program_Error;
4775 end if;
4776 end if;
4778 Next (Stmt);
4779 end loop;
4780 end Check_Grouping;
4782 --------------------
4783 -- Grouping_Error --
4784 --------------------
4786 procedure Grouping_Error (Prag : Node_Id) is
4787 begin
4788 Error_Msg_Sloc := Sloc (Prag);
4789 Error_Pragma ("pragma% must appear next to pragma#");
4790 end Grouping_Error;
4792 -- Start of processing for Check_Loop_Pragma_Grouping
4794 begin
4795 -- Inspect the statements of the loop or nested blocks housed
4796 -- within to determine whether the current pragma is part of the
4797 -- first topmost grouping of Loop_Invariant and Loop_Variant.
4799 Check_Grouping (Statements (Loop_Stmt));
4801 exception
4802 when Stop_Search => null;
4803 end Check_Loop_Pragma_Grouping;
4805 --------------------
4806 -- Is_Loop_Pragma --
4807 --------------------
4809 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
4810 begin
4811 -- Inspect the original node as Loop_Invariant and Loop_Variant
4812 -- pragmas are rewritten to null when assertions are disabled.
4814 if Nkind (Original_Node (Stmt)) = N_Pragma then
4815 return
4816 Nam_In (Pragma_Name (Original_Node (Stmt)),
4817 Name_Loop_Invariant,
4818 Name_Loop_Variant);
4819 else
4820 return False;
4821 end if;
4822 end Is_Loop_Pragma;
4824 ---------------------
4825 -- Placement_Error --
4826 ---------------------
4828 procedure Placement_Error (Constr : Node_Id) is
4829 LA : constant String := " with Loop_Entry";
4831 begin
4832 if Prag_Id = Pragma_Assert then
4833 Error_Msg_String (1 .. LA'Length) := LA;
4834 Error_Msg_Strlen := LA'Length;
4835 else
4836 Error_Msg_Strlen := 0;
4837 end if;
4839 if Nkind (Constr) = N_Pragma then
4840 Error_Pragma
4841 ("pragma %~ must appear immediately within the statements "
4842 & "of a loop");
4843 else
4844 Error_Pragma_Arg
4845 ("block containing pragma %~ must appear immediately within "
4846 & "the statements of a loop", Constr);
4847 end if;
4848 end Placement_Error;
4850 -- Local declarations
4852 Prev : Node_Id;
4853 Stmt : Node_Id;
4855 -- Start of processing for Check_Loop_Pragma_Placement
4857 begin
4858 -- Check that pragma appears immediately within a loop statement,
4859 -- ignoring intervening block statements.
4861 Prev := N;
4862 Stmt := Parent (N);
4863 while Present (Stmt) loop
4865 -- The pragma or previous block must appear immediately within the
4866 -- current block's declarative or statement part.
4868 if Nkind (Stmt) = N_Block_Statement then
4869 if (No (Declarations (Stmt))
4870 or else List_Containing (Prev) /= Declarations (Stmt))
4871 and then
4872 List_Containing (Prev) /=
4873 Statements (Handled_Statement_Sequence (Stmt))
4874 then
4875 Placement_Error (Prev);
4876 return;
4878 -- Keep inspecting the parents because we are now within a
4879 -- chain of nested blocks.
4881 else
4882 Prev := Stmt;
4883 Stmt := Parent (Stmt);
4884 end if;
4886 -- The pragma or previous block must appear immediately within the
4887 -- statements of the loop.
4889 elsif Nkind (Stmt) = N_Loop_Statement then
4890 if List_Containing (Prev) /= Statements (Stmt) then
4891 Placement_Error (Prev);
4892 end if;
4894 -- Stop the traversal because we reached the innermost loop
4895 -- regardless of whether we encountered an error or not.
4897 exit;
4899 -- Ignore a handled statement sequence. Note that this node may
4900 -- be related to a subprogram body in which case we will emit an
4901 -- error on the next iteration of the search.
4903 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
4904 Stmt := Parent (Stmt);
4906 -- Any other statement breaks the chain from the pragma to the
4907 -- loop.
4909 else
4910 Placement_Error (Prev);
4911 return;
4912 end if;
4913 end loop;
4915 -- Check that the current pragma Loop_Invariant or Loop_Variant is
4916 -- grouped together with other such pragmas.
4918 if Is_Loop_Pragma (N) then
4920 -- The previous check should have located the related loop
4922 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
4923 Check_Loop_Pragma_Grouping (Stmt);
4924 end if;
4925 end Check_Loop_Pragma_Placement;
4927 -------------------------------------------
4928 -- Check_Is_In_Decl_Part_Or_Package_Spec --
4929 -------------------------------------------
4931 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
4932 P : Node_Id;
4934 begin
4935 P := Parent (N);
4936 loop
4937 if No (P) then
4938 exit;
4940 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
4941 exit;
4943 elsif Nkind_In (P, N_Package_Specification,
4944 N_Block_Statement)
4945 then
4946 return;
4948 -- Note: the following tests seem a little peculiar, because
4949 -- they test for bodies, but if we were in the statement part
4950 -- of the body, we would already have hit the handled statement
4951 -- sequence, so the only way we get here is by being in the
4952 -- declarative part of the body.
4954 elsif Nkind_In (P, N_Subprogram_Body,
4955 N_Package_Body,
4956 N_Task_Body,
4957 N_Entry_Body)
4958 then
4959 return;
4960 end if;
4962 P := Parent (P);
4963 end loop;
4965 Error_Pragma ("pragma% is not in declarative part or package spec");
4966 end Check_Is_In_Decl_Part_Or_Package_Spec;
4968 -------------------------
4969 -- Check_No_Identifier --
4970 -------------------------
4972 procedure Check_No_Identifier (Arg : Node_Id) is
4973 begin
4974 if Nkind (Arg) = N_Pragma_Argument_Association
4975 and then Chars (Arg) /= No_Name
4976 then
4977 Error_Pragma_Arg_Ident
4978 ("pragma% does not permit identifier& here", Arg);
4979 end if;
4980 end Check_No_Identifier;
4982 --------------------------
4983 -- Check_No_Identifiers --
4984 --------------------------
4986 procedure Check_No_Identifiers is
4987 Arg_Node : Node_Id;
4988 begin
4989 Arg_Node := Arg1;
4990 for J in 1 .. Arg_Count loop
4991 Check_No_Identifier (Arg_Node);
4992 Next (Arg_Node);
4993 end loop;
4994 end Check_No_Identifiers;
4996 ------------------------
4997 -- Check_No_Link_Name --
4998 ------------------------
5000 procedure Check_No_Link_Name is
5001 begin
5002 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
5003 Arg4 := Arg3;
5004 end if;
5006 if Present (Arg4) then
5007 Error_Pragma_Arg
5008 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
5009 end if;
5010 end Check_No_Link_Name;
5012 -------------------------------
5013 -- Check_Optional_Identifier --
5014 -------------------------------
5016 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
5017 begin
5018 if Present (Arg)
5019 and then Nkind (Arg) = N_Pragma_Argument_Association
5020 and then Chars (Arg) /= No_Name
5021 then
5022 if Chars (Arg) /= Id then
5023 Error_Msg_Name_1 := Pname;
5024 Error_Msg_Name_2 := Id;
5025 Error_Msg_N ("pragma% argument expects identifier%", Arg);
5026 raise Pragma_Exit;
5027 end if;
5028 end if;
5029 end Check_Optional_Identifier;
5031 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
5032 begin
5033 Name_Buffer (1 .. Id'Length) := Id;
5034 Name_Len := Id'Length;
5035 Check_Optional_Identifier (Arg, Name_Find);
5036 end Check_Optional_Identifier;
5038 -----------------------------
5039 -- Check_Static_Constraint --
5040 -----------------------------
5042 -- Note: for convenience in writing this procedure, in addition to
5043 -- the officially (i.e. by spec) allowed argument which is always a
5044 -- constraint, it also allows ranges and discriminant associations.
5045 -- Above is not clear ???
5047 procedure Check_Static_Constraint (Constr : Node_Id) is
5049 procedure Require_Static (E : Node_Id);
5050 -- Require given expression to be static expression
5052 --------------------
5053 -- Require_Static --
5054 --------------------
5056 procedure Require_Static (E : Node_Id) is
5057 begin
5058 if not Is_OK_Static_Expression (E) then
5059 Flag_Non_Static_Expr
5060 ("non-static constraint not allowed in Unchecked_Union!", E);
5061 raise Pragma_Exit;
5062 end if;
5063 end Require_Static;
5065 -- Start of processing for Check_Static_Constraint
5067 begin
5068 case Nkind (Constr) is
5069 when N_Discriminant_Association =>
5070 Require_Static (Expression (Constr));
5072 when N_Range =>
5073 Require_Static (Low_Bound (Constr));
5074 Require_Static (High_Bound (Constr));
5076 when N_Attribute_Reference =>
5077 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
5078 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
5080 when N_Range_Constraint =>
5081 Check_Static_Constraint (Range_Expression (Constr));
5083 when N_Index_Or_Discriminant_Constraint =>
5084 declare
5085 IDC : Entity_Id;
5086 begin
5087 IDC := First (Constraints (Constr));
5088 while Present (IDC) loop
5089 Check_Static_Constraint (IDC);
5090 Next (IDC);
5091 end loop;
5092 end;
5094 when others =>
5095 null;
5096 end case;
5097 end Check_Static_Constraint;
5099 --------------------------------------
5100 -- Check_Valid_Configuration_Pragma --
5101 --------------------------------------
5103 -- A configuration pragma must appear in the context clause of a
5104 -- compilation unit, and only other pragmas may precede it. Note that
5105 -- the test also allows use in a configuration pragma file.
5107 procedure Check_Valid_Configuration_Pragma is
5108 begin
5109 if not Is_Configuration_Pragma then
5110 Error_Pragma ("incorrect placement for configuration pragma%");
5111 end if;
5112 end Check_Valid_Configuration_Pragma;
5114 -------------------------------------
5115 -- Check_Valid_Library_Unit_Pragma --
5116 -------------------------------------
5118 procedure Check_Valid_Library_Unit_Pragma is
5119 Plist : List_Id;
5120 Parent_Node : Node_Id;
5121 Unit_Name : Entity_Id;
5122 Unit_Kind : Node_Kind;
5123 Unit_Node : Node_Id;
5124 Sindex : Source_File_Index;
5126 begin
5127 if not Is_List_Member (N) then
5128 Pragma_Misplaced;
5130 else
5131 Plist := List_Containing (N);
5132 Parent_Node := Parent (Plist);
5134 if Parent_Node = Empty then
5135 Pragma_Misplaced;
5137 -- Case of pragma appearing after a compilation unit. In this case
5138 -- it must have an argument with the corresponding name and must
5139 -- be part of the following pragmas of its parent.
5141 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
5142 if Plist /= Pragmas_After (Parent_Node) then
5143 Pragma_Misplaced;
5145 elsif Arg_Count = 0 then
5146 Error_Pragma
5147 ("argument required if outside compilation unit");
5149 else
5150 Check_No_Identifiers;
5151 Check_Arg_Count (1);
5152 Unit_Node := Unit (Parent (Parent_Node));
5153 Unit_Kind := Nkind (Unit_Node);
5155 Analyze (Get_Pragma_Arg (Arg1));
5157 if Unit_Kind = N_Generic_Subprogram_Declaration
5158 or else Unit_Kind = N_Subprogram_Declaration
5159 then
5160 Unit_Name := Defining_Entity (Unit_Node);
5162 elsif Unit_Kind in N_Generic_Instantiation then
5163 Unit_Name := Defining_Entity (Unit_Node);
5165 else
5166 Unit_Name := Cunit_Entity (Current_Sem_Unit);
5167 end if;
5169 if Chars (Unit_Name) /=
5170 Chars (Entity (Get_Pragma_Arg (Arg1)))
5171 then
5172 Error_Pragma_Arg
5173 ("pragma% argument is not current unit name", Arg1);
5174 end if;
5176 if Ekind (Unit_Name) = E_Package
5177 and then Present (Renamed_Entity (Unit_Name))
5178 then
5179 Error_Pragma ("pragma% not allowed for renamed package");
5180 end if;
5181 end if;
5183 -- Pragma appears other than after a compilation unit
5185 else
5186 -- Here we check for the generic instantiation case and also
5187 -- for the case of processing a generic formal package. We
5188 -- detect these cases by noting that the Sloc on the node
5189 -- does not belong to the current compilation unit.
5191 Sindex := Source_Index (Current_Sem_Unit);
5193 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
5194 Rewrite (N, Make_Null_Statement (Loc));
5195 return;
5197 -- If before first declaration, the pragma applies to the
5198 -- enclosing unit, and the name if present must be this name.
5200 elsif Is_Before_First_Decl (N, Plist) then
5201 Unit_Node := Unit_Declaration_Node (Current_Scope);
5202 Unit_Kind := Nkind (Unit_Node);
5204 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
5205 Pragma_Misplaced;
5207 elsif Unit_Kind = N_Subprogram_Body
5208 and then not Acts_As_Spec (Unit_Node)
5209 then
5210 Pragma_Misplaced;
5212 elsif Nkind (Parent_Node) = N_Package_Body then
5213 Pragma_Misplaced;
5215 elsif Nkind (Parent_Node) = N_Package_Specification
5216 and then Plist = Private_Declarations (Parent_Node)
5217 then
5218 Pragma_Misplaced;
5220 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
5221 or else Nkind (Parent_Node) =
5222 N_Generic_Subprogram_Declaration)
5223 and then Plist = Generic_Formal_Declarations (Parent_Node)
5224 then
5225 Pragma_Misplaced;
5227 elsif Arg_Count > 0 then
5228 Analyze (Get_Pragma_Arg (Arg1));
5230 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
5231 Error_Pragma_Arg
5232 ("name in pragma% must be enclosing unit", Arg1);
5233 end if;
5235 -- It is legal to have no argument in this context
5237 else
5238 return;
5239 end if;
5241 -- Error if not before first declaration. This is because a
5242 -- library unit pragma argument must be the name of a library
5243 -- unit (RM 10.1.5(7)), but the only names permitted in this
5244 -- context are (RM 10.1.5(6)) names of subprogram declarations,
5245 -- generic subprogram declarations or generic instantiations.
5247 else
5248 Error_Pragma
5249 ("pragma% misplaced, must be before first declaration");
5250 end if;
5251 end if;
5252 end if;
5253 end Check_Valid_Library_Unit_Pragma;
5255 -------------------
5256 -- Check_Variant --
5257 -------------------
5259 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
5260 Clist : constant Node_Id := Component_List (Variant);
5261 Comp : Node_Id;
5263 begin
5264 Comp := First (Component_Items (Clist));
5265 while Present (Comp) loop
5266 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
5267 Next (Comp);
5268 end loop;
5269 end Check_Variant;
5271 ---------------------------
5272 -- Ensure_Aggregate_Form --
5273 ---------------------------
5275 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
5276 CFSD : constant Boolean := Get_Comes_From_Source_Default;
5277 Expr : constant Node_Id := Expression (Arg);
5278 Loc : constant Source_Ptr := Sloc (Expr);
5279 Comps : List_Id := No_List;
5280 Exprs : List_Id := No_List;
5281 Nam : Name_Id := No_Name;
5282 Nam_Loc : Source_Ptr;
5284 begin
5285 -- The pragma argument is in positional form:
5287 -- pragma Depends (Nam => ...)
5288 -- ^
5289 -- Chars field
5291 -- Note that the Sloc of the Chars field is the Sloc of the pragma
5292 -- argument association.
5294 if Nkind (Arg) = N_Pragma_Argument_Association then
5295 Nam := Chars (Arg);
5296 Nam_Loc := Sloc (Arg);
5298 -- Remove the pragma argument name as this will be captured in the
5299 -- aggregate.
5301 Set_Chars (Arg, No_Name);
5302 end if;
5304 -- The argument is already in aggregate form, but the presence of a
5305 -- name causes this to be interpreted as named association which in
5306 -- turn must be converted into an aggregate.
5308 -- pragma Global (In_Out => (A, B, C))
5309 -- ^ ^
5310 -- name aggregate
5312 -- pragma Global ((In_Out => (A, B, C)))
5313 -- ^ ^
5314 -- aggregate aggregate
5316 if Nkind (Expr) = N_Aggregate then
5317 if Nam = No_Name then
5318 return;
5319 end if;
5321 -- Do not transform a null argument into an aggregate as N_Null has
5322 -- special meaning in formal verification pragmas.
5324 elsif Nkind (Expr) = N_Null then
5325 return;
5326 end if;
5328 -- Everything comes from source if the original comes from source
5330 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
5332 -- Positional argument is transformed into an aggregate with an
5333 -- Expressions list.
5335 if Nam = No_Name then
5336 Exprs := New_List (Relocate_Node (Expr));
5338 -- An associative argument is transformed into an aggregate with
5339 -- Component_Associations.
5341 else
5342 Comps := New_List (
5343 Make_Component_Association (Loc,
5344 Choices => New_List (Make_Identifier (Nam_Loc, Nam)),
5345 Expression => Relocate_Node (Expr)));
5346 end if;
5348 Set_Expression (Arg,
5349 Make_Aggregate (Loc,
5350 Component_Associations => Comps,
5351 Expressions => Exprs));
5353 -- Restore Comes_From_Source default
5355 Set_Comes_From_Source_Default (CFSD);
5356 end Ensure_Aggregate_Form;
5358 ------------------
5359 -- Error_Pragma --
5360 ------------------
5362 procedure Error_Pragma (Msg : String) is
5363 begin
5364 Error_Msg_Name_1 := Pname;
5365 Error_Msg_N (Fix_Error (Msg), N);
5366 raise Pragma_Exit;
5367 end Error_Pragma;
5369 ----------------------
5370 -- Error_Pragma_Arg --
5371 ----------------------
5373 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
5374 begin
5375 Error_Msg_Name_1 := Pname;
5376 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
5377 raise Pragma_Exit;
5378 end Error_Pragma_Arg;
5380 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
5381 begin
5382 Error_Msg_Name_1 := Pname;
5383 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
5384 Error_Pragma_Arg (Msg2, Arg);
5385 end Error_Pragma_Arg;
5387 ----------------------------
5388 -- Error_Pragma_Arg_Ident --
5389 ----------------------------
5391 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
5392 begin
5393 Error_Msg_Name_1 := Pname;
5394 Error_Msg_N (Fix_Error (Msg), Arg);
5395 raise Pragma_Exit;
5396 end Error_Pragma_Arg_Ident;
5398 ----------------------
5399 -- Error_Pragma_Ref --
5400 ----------------------
5402 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
5403 begin
5404 Error_Msg_Name_1 := Pname;
5405 Error_Msg_Sloc := Sloc (Ref);
5406 Error_Msg_NE (Fix_Error (Msg), N, Ref);
5407 raise Pragma_Exit;
5408 end Error_Pragma_Ref;
5410 ------------------------
5411 -- Find_Lib_Unit_Name --
5412 ------------------------
5414 function Find_Lib_Unit_Name return Entity_Id is
5415 begin
5416 -- Return inner compilation unit entity, for case of nested
5417 -- categorization pragmas. This happens in generic unit.
5419 if Nkind (Parent (N)) = N_Package_Specification
5420 and then Defining_Entity (Parent (N)) /= Current_Scope
5421 then
5422 return Defining_Entity (Parent (N));
5423 else
5424 return Current_Scope;
5425 end if;
5426 end Find_Lib_Unit_Name;
5428 ----------------------------
5429 -- Find_Program_Unit_Name --
5430 ----------------------------
5432 procedure Find_Program_Unit_Name (Id : Node_Id) is
5433 Unit_Name : Entity_Id;
5434 Unit_Kind : Node_Kind;
5435 P : constant Node_Id := Parent (N);
5437 begin
5438 if Nkind (P) = N_Compilation_Unit then
5439 Unit_Kind := Nkind (Unit (P));
5441 if Nkind_In (Unit_Kind, N_Subprogram_Declaration,
5442 N_Package_Declaration)
5443 or else Unit_Kind in N_Generic_Declaration
5444 then
5445 Unit_Name := Defining_Entity (Unit (P));
5447 if Chars (Id) = Chars (Unit_Name) then
5448 Set_Entity (Id, Unit_Name);
5449 Set_Etype (Id, Etype (Unit_Name));
5450 else
5451 Set_Etype (Id, Any_Type);
5452 Error_Pragma
5453 ("cannot find program unit referenced by pragma%");
5454 end if;
5456 else
5457 Set_Etype (Id, Any_Type);
5458 Error_Pragma ("pragma% inapplicable to this unit");
5459 end if;
5461 else
5462 Analyze (Id);
5463 end if;
5464 end Find_Program_Unit_Name;
5466 -----------------------------------------
5467 -- Find_Unique_Parameterless_Procedure --
5468 -----------------------------------------
5470 function Find_Unique_Parameterless_Procedure
5471 (Name : Entity_Id;
5472 Arg : Node_Id) return Entity_Id
5474 Proc : Entity_Id := Empty;
5476 begin
5477 -- The body of this procedure needs some comments ???
5479 if not Is_Entity_Name (Name) then
5480 Error_Pragma_Arg
5481 ("argument of pragma% must be entity name", Arg);
5483 elsif not Is_Overloaded (Name) then
5484 Proc := Entity (Name);
5486 if Ekind (Proc) /= E_Procedure
5487 or else Present (First_Formal (Proc))
5488 then
5489 Error_Pragma_Arg
5490 ("argument of pragma% must be parameterless procedure", Arg);
5491 end if;
5493 else
5494 declare
5495 Found : Boolean := False;
5496 It : Interp;
5497 Index : Interp_Index;
5499 begin
5500 Get_First_Interp (Name, Index, It);
5501 while Present (It.Nam) loop
5502 Proc := It.Nam;
5504 if Ekind (Proc) = E_Procedure
5505 and then No (First_Formal (Proc))
5506 then
5507 if not Found then
5508 Found := True;
5509 Set_Entity (Name, Proc);
5510 Set_Is_Overloaded (Name, False);
5511 else
5512 Error_Pragma_Arg
5513 ("ambiguous handler name for pragma% ", Arg);
5514 end if;
5515 end if;
5517 Get_Next_Interp (Index, It);
5518 end loop;
5520 if not Found then
5521 Error_Pragma_Arg
5522 ("argument of pragma% must be parameterless procedure",
5523 Arg);
5524 else
5525 Proc := Entity (Name);
5526 end if;
5527 end;
5528 end if;
5530 return Proc;
5531 end Find_Unique_Parameterless_Procedure;
5533 ---------------
5534 -- Fix_Error --
5535 ---------------
5537 function Fix_Error (Msg : String) return String is
5538 Res : String (Msg'Range) := Msg;
5539 Res_Last : Natural := Msg'Last;
5540 J : Natural;
5542 begin
5543 -- If we have a rewriting of another pragma, go to that pragma
5545 if Is_Rewrite_Substitution (N)
5546 and then Nkind (Original_Node (N)) = N_Pragma
5547 then
5548 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
5549 end if;
5551 -- Case where pragma comes from an aspect specification
5553 if From_Aspect_Specification (N) then
5555 -- Change appearence of "pragma" in message to "aspect"
5557 J := Res'First;
5558 while J <= Res_Last - 5 loop
5559 if Res (J .. J + 5) = "pragma" then
5560 Res (J .. J + 5) := "aspect";
5561 J := J + 6;
5563 else
5564 J := J + 1;
5565 end if;
5566 end loop;
5568 -- Change "argument of" at start of message to "entity for"
5570 if Res'Length > 11
5571 and then Res (Res'First .. Res'First + 10) = "argument of"
5572 then
5573 Res (Res'First .. Res'First + 9) := "entity for";
5574 Res (Res'First + 10 .. Res_Last - 1) :=
5575 Res (Res'First + 11 .. Res_Last);
5576 Res_Last := Res_Last - 1;
5577 end if;
5579 -- Change "argument" at start of message to "entity"
5581 if Res'Length > 8
5582 and then Res (Res'First .. Res'First + 7) = "argument"
5583 then
5584 Res (Res'First .. Res'First + 5) := "entity";
5585 Res (Res'First + 6 .. Res_Last - 2) :=
5586 Res (Res'First + 8 .. Res_Last);
5587 Res_Last := Res_Last - 2;
5588 end if;
5590 -- Get name from corresponding aspect
5592 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
5593 end if;
5595 -- Return possibly modified message
5597 return Res (Res'First .. Res_Last);
5598 end Fix_Error;
5600 -------------------------
5601 -- Gather_Associations --
5602 -------------------------
5604 procedure Gather_Associations
5605 (Names : Name_List;
5606 Args : out Args_List)
5608 Arg : Node_Id;
5610 begin
5611 -- Initialize all parameters to Empty
5613 for J in Args'Range loop
5614 Args (J) := Empty;
5615 end loop;
5617 -- That's all we have to do if there are no argument associations
5619 if No (Pragma_Argument_Associations (N)) then
5620 return;
5621 end if;
5623 -- Otherwise first deal with any positional parameters present
5625 Arg := First (Pragma_Argument_Associations (N));
5626 for Index in Args'Range loop
5627 exit when No (Arg) or else Chars (Arg) /= No_Name;
5628 Args (Index) := Get_Pragma_Arg (Arg);
5629 Next (Arg);
5630 end loop;
5632 -- Positional parameters all processed, if any left, then we
5633 -- have too many positional parameters.
5635 if Present (Arg) and then Chars (Arg) = No_Name then
5636 Error_Pragma_Arg
5637 ("too many positional associations for pragma%", Arg);
5638 end if;
5640 -- Process named parameters if any are present
5642 while Present (Arg) loop
5643 if Chars (Arg) = No_Name then
5644 Error_Pragma_Arg
5645 ("positional association cannot follow named association",
5646 Arg);
5648 else
5649 for Index in Names'Range loop
5650 if Names (Index) = Chars (Arg) then
5651 if Present (Args (Index)) then
5652 Error_Pragma_Arg
5653 ("duplicate argument association for pragma%", Arg);
5654 else
5655 Args (Index) := Get_Pragma_Arg (Arg);
5656 exit;
5657 end if;
5658 end if;
5660 if Index = Names'Last then
5661 Error_Msg_Name_1 := Pname;
5662 Error_Msg_N ("pragma% does not allow & argument", Arg);
5664 -- Check for possible misspelling
5666 for Index1 in Names'Range loop
5667 if Is_Bad_Spelling_Of
5668 (Chars (Arg), Names (Index1))
5669 then
5670 Error_Msg_Name_1 := Names (Index1);
5671 Error_Msg_N -- CODEFIX
5672 ("\possible misspelling of%", Arg);
5673 exit;
5674 end if;
5675 end loop;
5677 raise Pragma_Exit;
5678 end if;
5679 end loop;
5680 end if;
5682 Next (Arg);
5683 end loop;
5684 end Gather_Associations;
5686 -----------------
5687 -- GNAT_Pragma --
5688 -----------------
5690 procedure GNAT_Pragma is
5691 begin
5692 -- We need to check the No_Implementation_Pragmas restriction for
5693 -- the case of a pragma from source. Note that the case of aspects
5694 -- generating corresponding pragmas marks these pragmas as not being
5695 -- from source, so this test also catches that case.
5697 if Comes_From_Source (N) then
5698 Check_Restriction (No_Implementation_Pragmas, N);
5699 end if;
5700 end GNAT_Pragma;
5702 --------------------------
5703 -- Is_Before_First_Decl --
5704 --------------------------
5706 function Is_Before_First_Decl
5707 (Pragma_Node : Node_Id;
5708 Decls : List_Id) return Boolean
5710 Item : Node_Id := First (Decls);
5712 begin
5713 -- Only other pragmas can come before this pragma
5715 loop
5716 if No (Item) or else Nkind (Item) /= N_Pragma then
5717 return False;
5719 elsif Item = Pragma_Node then
5720 return True;
5721 end if;
5723 Next (Item);
5724 end loop;
5725 end Is_Before_First_Decl;
5727 -----------------------------
5728 -- Is_Configuration_Pragma --
5729 -----------------------------
5731 -- A configuration pragma must appear in the context clause of a
5732 -- compilation unit, and only other pragmas may precede it. Note that
5733 -- the test below also permits use in a configuration pragma file.
5735 function Is_Configuration_Pragma return Boolean is
5736 Lis : constant List_Id := List_Containing (N);
5737 Par : constant Node_Id := Parent (N);
5738 Prg : Node_Id;
5740 begin
5741 -- If no parent, then we are in the configuration pragma file,
5742 -- so the placement is definitely appropriate.
5744 if No (Par) then
5745 return True;
5747 -- Otherwise we must be in the context clause of a compilation unit
5748 -- and the only thing allowed before us in the context list is more
5749 -- configuration pragmas.
5751 elsif Nkind (Par) = N_Compilation_Unit
5752 and then Context_Items (Par) = Lis
5753 then
5754 Prg := First (Lis);
5756 loop
5757 if Prg = N then
5758 return True;
5759 elsif Nkind (Prg) /= N_Pragma then
5760 return False;
5761 end if;
5763 Next (Prg);
5764 end loop;
5766 else
5767 return False;
5768 end if;
5769 end Is_Configuration_Pragma;
5771 --------------------------
5772 -- Is_In_Context_Clause --
5773 --------------------------
5775 function Is_In_Context_Clause return Boolean is
5776 Plist : List_Id;
5777 Parent_Node : Node_Id;
5779 begin
5780 if not Is_List_Member (N) then
5781 return False;
5783 else
5784 Plist := List_Containing (N);
5785 Parent_Node := Parent (Plist);
5787 if Parent_Node = Empty
5788 or else Nkind (Parent_Node) /= N_Compilation_Unit
5789 or else Context_Items (Parent_Node) /= Plist
5790 then
5791 return False;
5792 end if;
5793 end if;
5795 return True;
5796 end Is_In_Context_Clause;
5798 ---------------------------------
5799 -- Is_Static_String_Expression --
5800 ---------------------------------
5802 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
5803 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5804 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
5806 begin
5807 Analyze_And_Resolve (Argx);
5809 -- Special case Ada 83, where the expression will never be static,
5810 -- but we will return true if we had a string literal to start with.
5812 if Ada_Version = Ada_83 then
5813 return Lit;
5815 -- Normal case, true only if we end up with a string literal that
5816 -- is marked as being the result of evaluating a static expression.
5818 else
5819 return Is_OK_Static_Expression (Argx)
5820 and then Nkind (Argx) = N_String_Literal;
5821 end if;
5823 end Is_Static_String_Expression;
5825 ----------------------
5826 -- Pragma_Misplaced --
5827 ----------------------
5829 procedure Pragma_Misplaced is
5830 begin
5831 Error_Pragma ("incorrect placement of pragma%");
5832 end Pragma_Misplaced;
5834 ------------------------------------------------
5835 -- Process_Atomic_Independent_Shared_Volatile --
5836 ------------------------------------------------
5838 procedure Process_Atomic_Independent_Shared_Volatile is
5839 E_Id : Node_Id;
5840 E : Entity_Id;
5841 D : Node_Id;
5842 K : Node_Kind;
5843 Utyp : Entity_Id;
5845 procedure Set_Atomic_Full (E : Entity_Id);
5846 -- Set given type as Is_Atomic or Has_Volatile_Full_Access. Also, if
5847 -- no explicit alignment was given, set alignment to unknown, since
5848 -- back end knows what the alignment requirements are for atomic and
5849 -- full access arrays. Note: this is necessary for derived types.
5851 ---------------------
5852 -- Set_Atomic_Full --
5853 ---------------------
5855 procedure Set_Atomic_Full (E : Entity_Id) is
5856 begin
5857 if Prag_Id = Pragma_Volatile_Full_Access then
5858 Set_Has_Volatile_Full_Access (E);
5859 else
5860 Set_Is_Atomic (E);
5861 end if;
5863 if not Has_Alignment_Clause (E) then
5864 Set_Alignment (E, Uint_0);
5865 end if;
5866 end Set_Atomic_Full;
5868 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
5870 begin
5871 Check_Ada_83_Warning;
5872 Check_No_Identifiers;
5873 Check_Arg_Count (1);
5874 Check_Arg_Is_Local_Name (Arg1);
5875 E_Id := Get_Pragma_Arg (Arg1);
5877 if Etype (E_Id) = Any_Type then
5878 return;
5879 end if;
5881 E := Entity (E_Id);
5882 D := Declaration_Node (E);
5883 K := Nkind (D);
5885 -- Check duplicate before we chain ourselves
5887 Check_Duplicate_Pragma (E);
5889 -- Check Atomic and VFA used together
5891 if (Is_Atomic (E) and then Prag_Id = Pragma_Volatile_Full_Access)
5892 or else (Has_Volatile_Full_Access (E)
5893 and then (Prag_Id = Pragma_Atomic
5894 or else
5895 Prag_Id = Pragma_Shared))
5896 then
5897 Error_Pragma
5898 ("cannot have Volatile_Full_Access and Atomic for same entity");
5899 end if;
5901 -- Now check appropriateness of the entity
5903 if Is_Type (E) then
5904 if Rep_Item_Too_Early (E, N)
5905 or else
5906 Rep_Item_Too_Late (E, N)
5907 then
5908 return;
5909 else
5910 Check_First_Subtype (Arg1);
5911 end if;
5913 -- Attribute belongs on the base type. If the view of the type is
5914 -- currently private, it also belongs on the underlying type.
5916 if Prag_Id = Pragma_Atomic
5917 or else
5918 Prag_Id = Pragma_Shared
5919 or else
5920 Prag_Id = Pragma_Volatile_Full_Access
5921 then
5922 Set_Atomic_Full (E);
5923 Set_Atomic_Full (Base_Type (E));
5924 Set_Atomic_Full (Underlying_Type (E));
5925 end if;
5927 -- Atomic/Shared/Volatile_Full_Access imply Independent
5929 if Prag_Id /= Pragma_Volatile then
5930 Set_Is_Independent (E);
5931 Set_Is_Independent (Base_Type (E));
5932 Set_Is_Independent (Underlying_Type (E));
5934 if Prag_Id = Pragma_Independent then
5935 Record_Independence_Check (N, Base_Type (E));
5936 end if;
5937 end if;
5939 -- Atomic/Shared/Volatile_Full_Access imply Volatile
5941 if Prag_Id /= Pragma_Independent then
5942 Set_Is_Volatile (E);
5943 Set_Is_Volatile (Base_Type (E));
5944 Set_Is_Volatile (Underlying_Type (E));
5946 Set_Treat_As_Volatile (E);
5947 Set_Treat_As_Volatile (Underlying_Type (E));
5948 end if;
5950 elsif K = N_Object_Declaration
5951 or else (K = N_Component_Declaration
5952 and then Original_Record_Component (E) = E)
5953 then
5954 if Rep_Item_Too_Late (E, N) then
5955 return;
5956 end if;
5958 if Prag_Id = Pragma_Atomic
5959 or else
5960 Prag_Id = Pragma_Shared
5961 or else
5962 Prag_Id = Pragma_Volatile_Full_Access
5963 then
5964 if Prag_Id = Pragma_Volatile_Full_Access then
5965 Set_Has_Volatile_Full_Access (E);
5966 else
5967 Set_Is_Atomic (E);
5968 end if;
5970 -- If the object declaration has an explicit initialization, a
5971 -- temporary may have to be created to hold the expression, to
5972 -- ensure that access to the object remain atomic.
5974 if Nkind (Parent (E)) = N_Object_Declaration
5975 and then Present (Expression (Parent (E)))
5976 then
5977 Set_Has_Delayed_Freeze (E);
5978 end if;
5980 -- An interesting improvement here. If an object of composite
5981 -- type X is declared atomic, and the type X isn't, that's a
5982 -- pity, since it may not have appropriate alignment etc. We
5983 -- can rescue this in the special case where the object and
5984 -- type are in the same unit by just setting the type as
5985 -- atomic, so that the back end will process it as atomic.
5987 -- Note: we used to do this for elementary types as well,
5988 -- but that turns out to be a bad idea and can have unwanted
5989 -- effects, most notably if the type is elementary, the object
5990 -- a simple component within a record, and both are in a spec:
5991 -- every object of this type in the entire program will be
5992 -- treated as atomic, thus incurring a potentially costly
5993 -- synchronization operation for every access.
5995 -- For Volatile_Full_Access we can do this for elementary types
5996 -- too, since there is no issue of atomic synchronization.
5998 -- Of course it would be best if the back end could just adjust
5999 -- the alignment etc for the specific object, but that's not
6000 -- something we are capable of doing at this point.
6002 Utyp := Underlying_Type (Etype (E));
6004 if Present (Utyp)
6005 and then (Is_Composite_Type (Utyp)
6006 or else Prag_Id = Pragma_Volatile_Full_Access)
6007 and then Sloc (E) > No_Location
6008 and then Sloc (Utyp) > No_Location
6009 and then
6010 Get_Source_File_Index (Sloc (E)) =
6011 Get_Source_File_Index (Sloc (Utyp))
6012 then
6013 if Prag_Id = Pragma_Volatile_Full_Access then
6014 Set_Has_Volatile_Full_Access (Utyp);
6015 else
6016 Set_Is_Atomic (Utyp);
6017 end if;
6018 end if;
6019 end if;
6021 -- Atomic/Shared/Volatile_Full_Access imply Independent
6023 if Prag_Id /= Pragma_Volatile then
6024 Set_Is_Independent (E);
6026 if Prag_Id = Pragma_Independent then
6027 Record_Independence_Check (N, E);
6028 end if;
6029 end if;
6031 -- Atomic/Shared/Volatile_Full_Access imply Volatile
6033 if Prag_Id /= Pragma_Independent then
6034 Set_Is_Volatile (E);
6035 Set_Treat_As_Volatile (E);
6036 end if;
6038 else
6039 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6040 end if;
6042 -- The following check is only relevant when SPARK_Mode is on as
6043 -- this is not a standard Ada legality rule. Pragma Volatile can
6044 -- only apply to a full type declaration or an object declaration
6045 -- (SPARK RM C.6(1)).
6047 if SPARK_Mode = On
6048 and then Prag_Id = Pragma_Volatile
6049 and then not Nkind_In (K, N_Full_Type_Declaration,
6050 N_Object_Declaration)
6051 then
6052 Error_Pragma_Arg
6053 ("argument of pragma % must denote a full type or object "
6054 & "declaration", Arg1);
6055 end if;
6056 end Process_Atomic_Independent_Shared_Volatile;
6058 -------------------------------------------
6059 -- Process_Compile_Time_Warning_Or_Error --
6060 -------------------------------------------
6062 procedure Process_Compile_Time_Warning_Or_Error is
6063 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
6065 begin
6066 Check_Arg_Count (2);
6067 Check_No_Identifiers;
6068 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
6069 Analyze_And_Resolve (Arg1x, Standard_Boolean);
6071 if Compile_Time_Known_Value (Arg1x) then
6072 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
6073 declare
6074 Str : constant String_Id :=
6075 Strval (Get_Pragma_Arg (Arg2));
6076 Len : constant Int := String_Length (Str);
6077 Cont : Boolean;
6078 Ptr : Nat;
6079 CC : Char_Code;
6080 C : Character;
6081 Cent : constant Entity_Id :=
6082 Cunit_Entity (Current_Sem_Unit);
6084 Force : constant Boolean :=
6085 Prag_Id = Pragma_Compile_Time_Warning
6086 and then
6087 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
6088 and then (Ekind (Cent) /= E_Package
6089 or else not In_Private_Part (Cent));
6090 -- Set True if this is the warning case, and we are in the
6091 -- visible part of a package spec, or in a subprogram spec,
6092 -- in which case we want to force the client to see the
6093 -- warning, even though it is not in the main unit.
6095 begin
6096 -- Loop through segments of message separated by line feeds.
6097 -- We output these segments as separate messages with
6098 -- continuation marks for all but the first.
6100 Cont := False;
6101 Ptr := 1;
6102 loop
6103 Error_Msg_Strlen := 0;
6105 -- Loop to copy characters from argument to error message
6106 -- string buffer.
6108 loop
6109 exit when Ptr > Len;
6110 CC := Get_String_Char (Str, Ptr);
6111 Ptr := Ptr + 1;
6113 -- Ignore wide chars ??? else store character
6115 if In_Character_Range (CC) then
6116 C := Get_Character (CC);
6117 exit when C = ASCII.LF;
6118 Error_Msg_Strlen := Error_Msg_Strlen + 1;
6119 Error_Msg_String (Error_Msg_Strlen) := C;
6120 end if;
6121 end loop;
6123 -- Here with one line ready to go
6125 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
6127 -- If this is a warning in a spec, then we want clients
6128 -- to see the warning, so mark the message with the
6129 -- special sequence !! to force the warning. In the case
6130 -- of a package spec, we do not force this if we are in
6131 -- the private part of the spec.
6133 if Force then
6134 if Cont = False then
6135 Error_Msg_N ("<<~!!", Arg1);
6136 Cont := True;
6137 else
6138 Error_Msg_N ("\<<~!!", Arg1);
6139 end if;
6141 -- Error, rather than warning, or in a body, so we do not
6142 -- need to force visibility for client (error will be
6143 -- output in any case, and this is the situation in which
6144 -- we do not want a client to get a warning, since the
6145 -- warning is in the body or the spec private part).
6147 else
6148 if Cont = False then
6149 Error_Msg_N ("<<~", Arg1);
6150 Cont := True;
6151 else
6152 Error_Msg_N ("\<<~", Arg1);
6153 end if;
6154 end if;
6156 exit when Ptr > Len;
6157 end loop;
6158 end;
6159 end if;
6160 end if;
6161 end Process_Compile_Time_Warning_Or_Error;
6163 ------------------------
6164 -- Process_Convention --
6165 ------------------------
6167 procedure Process_Convention
6168 (C : out Convention_Id;
6169 Ent : out Entity_Id)
6171 Cname : Name_Id;
6173 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
6174 -- Called if we have more than one Export/Import/Convention pragma.
6175 -- This is generally illegal, but we have a special case of allowing
6176 -- Import and Interface to coexist if they specify the convention in
6177 -- a consistent manner. We are allowed to do this, since Interface is
6178 -- an implementation defined pragma, and we choose to do it since we
6179 -- know Rational allows this combination. S is the entity id of the
6180 -- subprogram in question. This procedure also sets the special flag
6181 -- Import_Interface_Present in both pragmas in the case where we do
6182 -- have matching Import and Interface pragmas.
6184 procedure Set_Convention_From_Pragma (E : Entity_Id);
6185 -- Set convention in entity E, and also flag that the entity has a
6186 -- convention pragma. If entity is for a private or incomplete type,
6187 -- also set convention and flag on underlying type. This procedure
6188 -- also deals with the special case of C_Pass_By_Copy convention,
6189 -- and error checks for inappropriate convention specification.
6191 -------------------------------
6192 -- Diagnose_Multiple_Pragmas --
6193 -------------------------------
6195 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
6196 Pdec : constant Node_Id := Declaration_Node (S);
6197 Decl : Node_Id;
6198 Err : Boolean;
6200 function Same_Convention (Decl : Node_Id) return Boolean;
6201 -- Decl is a pragma node. This function returns True if this
6202 -- pragma has a first argument that is an identifier with a
6203 -- Chars field corresponding to the Convention_Id C.
6205 function Same_Name (Decl : Node_Id) return Boolean;
6206 -- Decl is a pragma node. This function returns True if this
6207 -- pragma has a second argument that is an identifier with a
6208 -- Chars field that matches the Chars of the current subprogram.
6210 ---------------------
6211 -- Same_Convention --
6212 ---------------------
6214 function Same_Convention (Decl : Node_Id) return Boolean is
6215 Arg1 : constant Node_Id :=
6216 First (Pragma_Argument_Associations (Decl));
6218 begin
6219 if Present (Arg1) then
6220 declare
6221 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
6222 begin
6223 if Nkind (Arg) = N_Identifier
6224 and then Is_Convention_Name (Chars (Arg))
6225 and then Get_Convention_Id (Chars (Arg)) = C
6226 then
6227 return True;
6228 end if;
6229 end;
6230 end if;
6232 return False;
6233 end Same_Convention;
6235 ---------------
6236 -- Same_Name --
6237 ---------------
6239 function Same_Name (Decl : Node_Id) return Boolean is
6240 Arg1 : constant Node_Id :=
6241 First (Pragma_Argument_Associations (Decl));
6242 Arg2 : Node_Id;
6244 begin
6245 if No (Arg1) then
6246 return False;
6247 end if;
6249 Arg2 := Next (Arg1);
6251 if No (Arg2) then
6252 return False;
6253 end if;
6255 declare
6256 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
6257 begin
6258 if Nkind (Arg) = N_Identifier
6259 and then Chars (Arg) = Chars (S)
6260 then
6261 return True;
6262 end if;
6263 end;
6265 return False;
6266 end Same_Name;
6268 -- Start of processing for Diagnose_Multiple_Pragmas
6270 begin
6271 Err := True;
6273 -- Definitely give message if we have Convention/Export here
6275 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
6276 null;
6278 -- If we have an Import or Export, scan back from pragma to
6279 -- find any previous pragma applying to the same procedure.
6280 -- The scan will be terminated by the start of the list, or
6281 -- hitting the subprogram declaration. This won't allow one
6282 -- pragma to appear in the public part and one in the private
6283 -- part, but that seems very unlikely in practice.
6285 else
6286 Decl := Prev (N);
6287 while Present (Decl) and then Decl /= Pdec loop
6289 -- Look for pragma with same name as us
6291 if Nkind (Decl) = N_Pragma
6292 and then Same_Name (Decl)
6293 then
6294 -- Give error if same as our pragma or Export/Convention
6296 if Nam_In (Pragma_Name (Decl), Name_Export,
6297 Name_Convention,
6298 Pragma_Name (N))
6299 then
6300 exit;
6302 -- Case of Import/Interface or the other way round
6304 elsif Nam_In (Pragma_Name (Decl), Name_Interface,
6305 Name_Import)
6306 then
6307 -- Here we know that we have Import and Interface. It
6308 -- doesn't matter which way round they are. See if
6309 -- they specify the same convention. If so, all OK,
6310 -- and set special flags to stop other messages
6312 if Same_Convention (Decl) then
6313 Set_Import_Interface_Present (N);
6314 Set_Import_Interface_Present (Decl);
6315 Err := False;
6317 -- If different conventions, special message
6319 else
6320 Error_Msg_Sloc := Sloc (Decl);
6321 Error_Pragma_Arg
6322 ("convention differs from that given#", Arg1);
6323 return;
6324 end if;
6325 end if;
6326 end if;
6328 Next (Decl);
6329 end loop;
6330 end if;
6332 -- Give message if needed if we fall through those tests
6333 -- except on Relaxed_RM_Semantics where we let go: either this
6334 -- is a case accepted/ignored by other Ada compilers (e.g.
6335 -- a mix of Convention and Import), or another error will be
6336 -- generated later (e.g. using both Import and Export).
6338 if Err and not Relaxed_RM_Semantics then
6339 Error_Pragma_Arg
6340 ("at most one Convention/Export/Import pragma is allowed",
6341 Arg2);
6342 end if;
6343 end Diagnose_Multiple_Pragmas;
6345 --------------------------------
6346 -- Set_Convention_From_Pragma --
6347 --------------------------------
6349 procedure Set_Convention_From_Pragma (E : Entity_Id) is
6350 begin
6351 -- Ada 2005 (AI-430): Check invalid attempt to change convention
6352 -- for an overridden dispatching operation. Technically this is
6353 -- an amendment and should only be done in Ada 2005 mode. However,
6354 -- this is clearly a mistake, since the problem that is addressed
6355 -- by this AI is that there is a clear gap in the RM.
6357 if Is_Dispatching_Operation (E)
6358 and then Present (Overridden_Operation (E))
6359 and then C /= Convention (Overridden_Operation (E))
6360 then
6361 Error_Pragma_Arg
6362 ("cannot change convention for overridden dispatching "
6363 & "operation", Arg1);
6364 end if;
6366 -- Special checks for Convention_Stdcall
6368 if C = Convention_Stdcall then
6370 -- A dispatching call is not allowed. A dispatching subprogram
6371 -- cannot be used to interface to the Win32 API, so in fact
6372 -- this check does not impose any effective restriction.
6374 if Is_Dispatching_Operation (E) then
6375 Error_Msg_Sloc := Sloc (E);
6377 -- Note: make this unconditional so that if there is more
6378 -- than one call to which the pragma applies, we get a
6379 -- message for each call. Also don't use Error_Pragma,
6380 -- so that we get multiple messages.
6382 Error_Msg_N
6383 ("dispatching subprogram# cannot use Stdcall convention!",
6384 Arg1);
6386 -- Subprograms are not allowed
6388 elsif not Is_Subprogram_Or_Generic_Subprogram (E)
6390 -- A variable is OK
6392 and then Ekind (E) /= E_Variable
6394 -- An access to subprogram is also allowed
6396 and then not
6397 (Is_Access_Type (E)
6398 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
6400 -- Allow internal call to set convention of subprogram type
6402 and then not (Ekind (E) = E_Subprogram_Type)
6403 then
6404 Error_Pragma_Arg
6405 ("second argument of pragma% must be subprogram (type)",
6406 Arg2);
6407 end if;
6408 end if;
6410 -- Set the convention
6412 Set_Convention (E, C);
6413 Set_Has_Convention_Pragma (E);
6415 -- For the case of a record base type, also set the convention of
6416 -- any anonymous access types declared in the record which do not
6417 -- currently have a specified convention.
6419 if Is_Record_Type (E) and then Is_Base_Type (E) then
6420 declare
6421 Comp : Node_Id;
6423 begin
6424 Comp := First_Component (E);
6425 while Present (Comp) loop
6426 if Present (Etype (Comp))
6427 and then Ekind_In (Etype (Comp),
6428 E_Anonymous_Access_Type,
6429 E_Anonymous_Access_Subprogram_Type)
6430 and then not Has_Convention_Pragma (Comp)
6431 then
6432 Set_Convention (Comp, C);
6433 end if;
6435 Next_Component (Comp);
6436 end loop;
6437 end;
6438 end if;
6440 -- Deal with incomplete/private type case, where underlying type
6441 -- is available, so set convention of that underlying type.
6443 if Is_Incomplete_Or_Private_Type (E)
6444 and then Present (Underlying_Type (E))
6445 then
6446 Set_Convention (Underlying_Type (E), C);
6447 Set_Has_Convention_Pragma (Underlying_Type (E), True);
6448 end if;
6450 -- A class-wide type should inherit the convention of the specific
6451 -- root type (although this isn't specified clearly by the RM).
6453 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
6454 Set_Convention (Class_Wide_Type (E), C);
6455 end if;
6457 -- If the entity is a record type, then check for special case of
6458 -- C_Pass_By_Copy, which is treated the same as C except that the
6459 -- special record flag is set. This convention is only permitted
6460 -- on record types (see AI95-00131).
6462 if Cname = Name_C_Pass_By_Copy then
6463 if Is_Record_Type (E) then
6464 Set_C_Pass_By_Copy (Base_Type (E));
6465 elsif Is_Incomplete_Or_Private_Type (E)
6466 and then Is_Record_Type (Underlying_Type (E))
6467 then
6468 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
6469 else
6470 Error_Pragma_Arg
6471 ("C_Pass_By_Copy convention allowed only for record type",
6472 Arg2);
6473 end if;
6474 end if;
6476 -- If the entity is a derived boolean type, check for the special
6477 -- case of convention C, C++, or Fortran, where we consider any
6478 -- nonzero value to represent true.
6480 if Is_Discrete_Type (E)
6481 and then Root_Type (Etype (E)) = Standard_Boolean
6482 and then
6483 (C = Convention_C
6484 or else
6485 C = Convention_CPP
6486 or else
6487 C = Convention_Fortran)
6488 then
6489 Set_Nonzero_Is_True (Base_Type (E));
6490 end if;
6491 end Set_Convention_From_Pragma;
6493 -- Local variables
6495 Comp_Unit : Unit_Number_Type;
6496 E : Entity_Id;
6497 E1 : Entity_Id;
6498 Id : Node_Id;
6500 -- Start of processing for Process_Convention
6502 begin
6503 Check_At_Least_N_Arguments (2);
6504 Check_Optional_Identifier (Arg1, Name_Convention);
6505 Check_Arg_Is_Identifier (Arg1);
6506 Cname := Chars (Get_Pragma_Arg (Arg1));
6508 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
6509 -- tested again below to set the critical flag).
6511 if Cname = Name_C_Pass_By_Copy then
6512 C := Convention_C;
6514 -- Otherwise we must have something in the standard convention list
6516 elsif Is_Convention_Name (Cname) then
6517 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
6519 -- Otherwise warn on unrecognized convention
6521 else
6522 if Warn_On_Export_Import then
6523 Error_Msg_N
6524 ("??unrecognized convention name, C assumed",
6525 Get_Pragma_Arg (Arg1));
6526 end if;
6528 C := Convention_C;
6529 end if;
6531 Check_Optional_Identifier (Arg2, Name_Entity);
6532 Check_Arg_Is_Local_Name (Arg2);
6534 Id := Get_Pragma_Arg (Arg2);
6535 Analyze (Id);
6537 if not Is_Entity_Name (Id) then
6538 Error_Pragma_Arg ("entity name required", Arg2);
6539 end if;
6541 E := Entity (Id);
6543 -- Set entity to return
6545 Ent := E;
6547 -- Ada_Pass_By_Copy special checking
6549 if C = Convention_Ada_Pass_By_Copy then
6550 if not Is_First_Subtype (E) then
6551 Error_Pragma_Arg
6552 ("convention `Ada_Pass_By_Copy` only allowed for types",
6553 Arg2);
6554 end if;
6556 if Is_By_Reference_Type (E) then
6557 Error_Pragma_Arg
6558 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
6559 & "type", Arg1);
6560 end if;
6562 -- Ada_Pass_By_Reference special checking
6564 elsif C = Convention_Ada_Pass_By_Reference then
6565 if not Is_First_Subtype (E) then
6566 Error_Pragma_Arg
6567 ("convention `Ada_Pass_By_Reference` only allowed for types",
6568 Arg2);
6569 end if;
6571 if Is_By_Copy_Type (E) then
6572 Error_Pragma_Arg
6573 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
6574 & "type", Arg1);
6575 end if;
6576 end if;
6578 -- Go to renamed subprogram if present, since convention applies to
6579 -- the actual renamed entity, not to the renaming entity. If the
6580 -- subprogram is inherited, go to parent subprogram.
6582 if Is_Subprogram (E)
6583 and then Present (Alias (E))
6584 then
6585 if Nkind (Parent (Declaration_Node (E))) =
6586 N_Subprogram_Renaming_Declaration
6587 then
6588 if Scope (E) /= Scope (Alias (E)) then
6589 Error_Pragma_Ref
6590 ("cannot apply pragma% to non-local entity&#", E);
6591 end if;
6593 E := Alias (E);
6595 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
6596 N_Private_Extension_Declaration)
6597 and then Scope (E) = Scope (Alias (E))
6598 then
6599 E := Alias (E);
6601 -- Return the parent subprogram the entity was inherited from
6603 Ent := E;
6604 end if;
6605 end if;
6607 -- Check that we are not applying this to a specless body. Relax this
6608 -- check if Relaxed_RM_Semantics to accomodate other Ada compilers.
6610 if Is_Subprogram (E)
6611 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
6612 and then not Relaxed_RM_Semantics
6613 then
6614 Error_Pragma
6615 ("pragma% requires separate spec and must come before body");
6616 end if;
6618 -- Check that we are not applying this to a named constant
6620 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
6621 Error_Msg_Name_1 := Pname;
6622 Error_Msg_N
6623 ("cannot apply pragma% to named constant!",
6624 Get_Pragma_Arg (Arg2));
6625 Error_Pragma_Arg
6626 ("\supply appropriate type for&!", Arg2);
6627 end if;
6629 if Ekind (E) = E_Enumeration_Literal then
6630 Error_Pragma ("enumeration literal not allowed for pragma%");
6631 end if;
6633 -- Check for rep item appearing too early or too late
6635 if Etype (E) = Any_Type
6636 or else Rep_Item_Too_Early (E, N)
6637 then
6638 raise Pragma_Exit;
6640 elsif Present (Underlying_Type (E)) then
6641 E := Underlying_Type (E);
6642 end if;
6644 if Rep_Item_Too_Late (E, N) then
6645 raise Pragma_Exit;
6646 end if;
6648 if Has_Convention_Pragma (E) then
6649 Diagnose_Multiple_Pragmas (E);
6651 elsif Convention (E) = Convention_Protected
6652 or else Ekind (Scope (E)) = E_Protected_Type
6653 then
6654 Error_Pragma_Arg
6655 ("a protected operation cannot be given a different convention",
6656 Arg2);
6657 end if;
6659 -- For Intrinsic, a subprogram is required
6661 if C = Convention_Intrinsic
6662 and then not Is_Subprogram_Or_Generic_Subprogram (E)
6663 then
6664 Error_Pragma_Arg
6665 ("second argument of pragma% must be a subprogram", Arg2);
6666 end if;
6668 -- Deal with non-subprogram cases
6670 if not Is_Subprogram_Or_Generic_Subprogram (E) then
6671 Set_Convention_From_Pragma (E);
6673 if Is_Type (E) then
6675 -- The pragma must apply to a first subtype, but it can also
6676 -- apply to a generic type in a generic formal part, in which
6677 -- case it will also appear in the corresponding instance.
6679 if Is_Generic_Type (E) or else In_Instance then
6680 null;
6681 else
6682 Check_First_Subtype (Arg2);
6683 end if;
6685 Set_Convention_From_Pragma (Base_Type (E));
6687 -- For access subprograms, we must set the convention on the
6688 -- internally generated directly designated type as well.
6690 if Ekind (E) = E_Access_Subprogram_Type then
6691 Set_Convention_From_Pragma (Directly_Designated_Type (E));
6692 end if;
6693 end if;
6695 -- For the subprogram case, set proper convention for all homonyms
6696 -- in same scope and the same declarative part, i.e. the same
6697 -- compilation unit.
6699 else
6700 Comp_Unit := Get_Source_Unit (E);
6701 Set_Convention_From_Pragma (E);
6703 -- Treat a pragma Import as an implicit body, and pragma import
6704 -- as implicit reference (for navigation in GPS).
6706 if Prag_Id = Pragma_Import then
6707 Generate_Reference (E, Id, 'b');
6709 -- For exported entities we restrict the generation of references
6710 -- to entities exported to foreign languages since entities
6711 -- exported to Ada do not provide further information to GPS and
6712 -- add undesired references to the output of the gnatxref tool.
6714 elsif Prag_Id = Pragma_Export
6715 and then Convention (E) /= Convention_Ada
6716 then
6717 Generate_Reference (E, Id, 'i');
6718 end if;
6720 -- If the pragma comes from from an aspect, it only applies to the
6721 -- given entity, not its homonyms.
6723 if From_Aspect_Specification (N) then
6724 return;
6725 end if;
6727 -- Otherwise Loop through the homonyms of the pragma argument's
6728 -- entity, an apply convention to those in the current scope.
6730 E1 := Ent;
6732 loop
6733 E1 := Homonym (E1);
6734 exit when No (E1) or else Scope (E1) /= Current_Scope;
6736 -- Ignore entry for which convention is already set
6738 if Has_Convention_Pragma (E1) then
6739 goto Continue;
6740 end if;
6742 -- Do not set the pragma on inherited operations or on formal
6743 -- subprograms.
6745 if Comes_From_Source (E1)
6746 and then Comp_Unit = Get_Source_Unit (E1)
6747 and then not Is_Formal_Subprogram (E1)
6748 and then Nkind (Original_Node (Parent (E1))) /=
6749 N_Full_Type_Declaration
6750 then
6751 if Present (Alias (E1))
6752 and then Scope (E1) /= Scope (Alias (E1))
6753 then
6754 Error_Pragma_Ref
6755 ("cannot apply pragma% to non-local entity& declared#",
6756 E1);
6757 end if;
6759 Set_Convention_From_Pragma (E1);
6761 if Prag_Id = Pragma_Import then
6762 Generate_Reference (E1, Id, 'b');
6763 end if;
6764 end if;
6766 <<Continue>>
6767 null;
6768 end loop;
6769 end if;
6770 end Process_Convention;
6772 ----------------------------------------
6773 -- Process_Disable_Enable_Atomic_Sync --
6774 ----------------------------------------
6776 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
6777 begin
6778 Check_No_Identifiers;
6779 Check_At_Most_N_Arguments (1);
6781 -- Modeled internally as
6782 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
6784 Rewrite (N,
6785 Make_Pragma (Loc,
6786 Pragma_Identifier =>
6787 Make_Identifier (Loc, Nam),
6788 Pragma_Argument_Associations => New_List (
6789 Make_Pragma_Argument_Association (Loc,
6790 Expression =>
6791 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
6793 if Present (Arg1) then
6794 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
6795 end if;
6797 Analyze (N);
6798 end Process_Disable_Enable_Atomic_Sync;
6800 -------------------------------------------------
6801 -- Process_Extended_Import_Export_Internal_Arg --
6802 -------------------------------------------------
6804 procedure Process_Extended_Import_Export_Internal_Arg
6805 (Arg_Internal : Node_Id := Empty)
6807 begin
6808 if No (Arg_Internal) then
6809 Error_Pragma ("Internal parameter required for pragma%");
6810 end if;
6812 if Nkind (Arg_Internal) = N_Identifier then
6813 null;
6815 elsif Nkind (Arg_Internal) = N_Operator_Symbol
6816 and then (Prag_Id = Pragma_Import_Function
6817 or else
6818 Prag_Id = Pragma_Export_Function)
6819 then
6820 null;
6822 else
6823 Error_Pragma_Arg
6824 ("wrong form for Internal parameter for pragma%", Arg_Internal);
6825 end if;
6827 Check_Arg_Is_Local_Name (Arg_Internal);
6828 end Process_Extended_Import_Export_Internal_Arg;
6830 --------------------------------------------------
6831 -- Process_Extended_Import_Export_Object_Pragma --
6832 --------------------------------------------------
6834 procedure Process_Extended_Import_Export_Object_Pragma
6835 (Arg_Internal : Node_Id;
6836 Arg_External : Node_Id;
6837 Arg_Size : Node_Id)
6839 Def_Id : Entity_Id;
6841 begin
6842 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
6843 Def_Id := Entity (Arg_Internal);
6845 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
6846 Error_Pragma_Arg
6847 ("pragma% must designate an object", Arg_Internal);
6848 end if;
6850 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
6851 or else
6852 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
6853 then
6854 Error_Pragma_Arg
6855 ("previous Common/Psect_Object applies, pragma % not permitted",
6856 Arg_Internal);
6857 end if;
6859 if Rep_Item_Too_Late (Def_Id, N) then
6860 raise Pragma_Exit;
6861 end if;
6863 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
6865 if Present (Arg_Size) then
6866 Check_Arg_Is_External_Name (Arg_Size);
6867 end if;
6869 -- Export_Object case
6871 if Prag_Id = Pragma_Export_Object then
6872 if not Is_Library_Level_Entity (Def_Id) then
6873 Error_Pragma_Arg
6874 ("argument for pragma% must be library level entity",
6875 Arg_Internal);
6876 end if;
6878 if Ekind (Current_Scope) = E_Generic_Package then
6879 Error_Pragma ("pragma& cannot appear in a generic unit");
6880 end if;
6882 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
6883 Error_Pragma_Arg
6884 ("exported object must have compile time known size",
6885 Arg_Internal);
6886 end if;
6888 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
6889 Error_Msg_N ("??duplicate Export_Object pragma", N);
6890 else
6891 Set_Exported (Def_Id, Arg_Internal);
6892 end if;
6894 -- Import_Object case
6896 else
6897 if Is_Concurrent_Type (Etype (Def_Id)) then
6898 Error_Pragma_Arg
6899 ("cannot use pragma% for task/protected object",
6900 Arg_Internal);
6901 end if;
6903 if Ekind (Def_Id) = E_Constant then
6904 Error_Pragma_Arg
6905 ("cannot import a constant", Arg_Internal);
6906 end if;
6908 if Warn_On_Export_Import
6909 and then Has_Discriminants (Etype (Def_Id))
6910 then
6911 Error_Msg_N
6912 ("imported value must be initialized??", Arg_Internal);
6913 end if;
6915 if Warn_On_Export_Import
6916 and then Is_Access_Type (Etype (Def_Id))
6917 then
6918 Error_Pragma_Arg
6919 ("cannot import object of an access type??", Arg_Internal);
6920 end if;
6922 if Warn_On_Export_Import
6923 and then Is_Imported (Def_Id)
6924 then
6925 Error_Msg_N ("??duplicate Import_Object pragma", N);
6927 -- Check for explicit initialization present. Note that an
6928 -- initialization generated by the code generator, e.g. for an
6929 -- access type, does not count here.
6931 elsif Present (Expression (Parent (Def_Id)))
6932 and then
6933 Comes_From_Source
6934 (Original_Node (Expression (Parent (Def_Id))))
6935 then
6936 Error_Msg_Sloc := Sloc (Def_Id);
6937 Error_Pragma_Arg
6938 ("imported entities cannot be initialized (RM B.1(24))",
6939 "\no initialization allowed for & declared#", Arg1);
6940 else
6941 Set_Imported (Def_Id);
6942 Note_Possible_Modification (Arg_Internal, Sure => False);
6943 end if;
6944 end if;
6945 end Process_Extended_Import_Export_Object_Pragma;
6947 ------------------------------------------------------
6948 -- Process_Extended_Import_Export_Subprogram_Pragma --
6949 ------------------------------------------------------
6951 procedure Process_Extended_Import_Export_Subprogram_Pragma
6952 (Arg_Internal : Node_Id;
6953 Arg_External : Node_Id;
6954 Arg_Parameter_Types : Node_Id;
6955 Arg_Result_Type : Node_Id := Empty;
6956 Arg_Mechanism : Node_Id;
6957 Arg_Result_Mechanism : Node_Id := Empty)
6959 Ent : Entity_Id;
6960 Def_Id : Entity_Id;
6961 Hom_Id : Entity_Id;
6962 Formal : Entity_Id;
6963 Ambiguous : Boolean;
6964 Match : Boolean;
6966 function Same_Base_Type
6967 (Ptype : Node_Id;
6968 Formal : Entity_Id) return Boolean;
6969 -- Determines if Ptype references the type of Formal. Note that only
6970 -- the base types need to match according to the spec. Ptype here is
6971 -- the argument from the pragma, which is either a type name, or an
6972 -- access attribute.
6974 --------------------
6975 -- Same_Base_Type --
6976 --------------------
6978 function Same_Base_Type
6979 (Ptype : Node_Id;
6980 Formal : Entity_Id) return Boolean
6982 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
6983 Pref : Node_Id;
6985 begin
6986 -- Case where pragma argument is typ'Access
6988 if Nkind (Ptype) = N_Attribute_Reference
6989 and then Attribute_Name (Ptype) = Name_Access
6990 then
6991 Pref := Prefix (Ptype);
6992 Find_Type (Pref);
6994 if not Is_Entity_Name (Pref)
6995 or else Entity (Pref) = Any_Type
6996 then
6997 raise Pragma_Exit;
6998 end if;
7000 -- We have a match if the corresponding argument is of an
7001 -- anonymous access type, and its designated type matches the
7002 -- type of the prefix of the access attribute
7004 return Ekind (Ftyp) = E_Anonymous_Access_Type
7005 and then Base_Type (Entity (Pref)) =
7006 Base_Type (Etype (Designated_Type (Ftyp)));
7008 -- Case where pragma argument is a type name
7010 else
7011 Find_Type (Ptype);
7013 if not Is_Entity_Name (Ptype)
7014 or else Entity (Ptype) = Any_Type
7015 then
7016 raise Pragma_Exit;
7017 end if;
7019 -- We have a match if the corresponding argument is of the type
7020 -- given in the pragma (comparing base types)
7022 return Base_Type (Entity (Ptype)) = Ftyp;
7023 end if;
7024 end Same_Base_Type;
7026 -- Start of processing for
7027 -- Process_Extended_Import_Export_Subprogram_Pragma
7029 begin
7030 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7031 Ent := Empty;
7032 Ambiguous := False;
7034 -- Loop through homonyms (overloadings) of the entity
7036 Hom_Id := Entity (Arg_Internal);
7037 while Present (Hom_Id) loop
7038 Def_Id := Get_Base_Subprogram (Hom_Id);
7040 -- We need a subprogram in the current scope
7042 if not Is_Subprogram (Def_Id)
7043 or else Scope (Def_Id) /= Current_Scope
7044 then
7045 null;
7047 else
7048 Match := True;
7050 -- Pragma cannot apply to subprogram body
7052 if Is_Subprogram (Def_Id)
7053 and then Nkind (Parent (Declaration_Node (Def_Id))) =
7054 N_Subprogram_Body
7055 then
7056 Error_Pragma
7057 ("pragma% requires separate spec"
7058 & " and must come before body");
7059 end if;
7061 -- Test result type if given, note that the result type
7062 -- parameter can only be present for the function cases.
7064 if Present (Arg_Result_Type)
7065 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
7066 then
7067 Match := False;
7069 elsif Etype (Def_Id) /= Standard_Void_Type
7070 and then
7071 Nam_In (Pname, Name_Export_Procedure, Name_Import_Procedure)
7072 then
7073 Match := False;
7075 -- Test parameter types if given. Note that this parameter
7076 -- has not been analyzed (and must not be, since it is
7077 -- semantic nonsense), so we get it as the parser left it.
7079 elsif Present (Arg_Parameter_Types) then
7080 Check_Matching_Types : declare
7081 Formal : Entity_Id;
7082 Ptype : Node_Id;
7084 begin
7085 Formal := First_Formal (Def_Id);
7087 if Nkind (Arg_Parameter_Types) = N_Null then
7088 if Present (Formal) then
7089 Match := False;
7090 end if;
7092 -- A list of one type, e.g. (List) is parsed as
7093 -- a parenthesized expression.
7095 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
7096 and then Paren_Count (Arg_Parameter_Types) = 1
7097 then
7098 if No (Formal)
7099 or else Present (Next_Formal (Formal))
7100 then
7101 Match := False;
7102 else
7103 Match :=
7104 Same_Base_Type (Arg_Parameter_Types, Formal);
7105 end if;
7107 -- A list of more than one type is parsed as a aggregate
7109 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
7110 and then Paren_Count (Arg_Parameter_Types) = 0
7111 then
7112 Ptype := First (Expressions (Arg_Parameter_Types));
7113 while Present (Ptype) or else Present (Formal) loop
7114 if No (Ptype)
7115 or else No (Formal)
7116 or else not Same_Base_Type (Ptype, Formal)
7117 then
7118 Match := False;
7119 exit;
7120 else
7121 Next_Formal (Formal);
7122 Next (Ptype);
7123 end if;
7124 end loop;
7126 -- Anything else is of the wrong form
7128 else
7129 Error_Pragma_Arg
7130 ("wrong form for Parameter_Types parameter",
7131 Arg_Parameter_Types);
7132 end if;
7133 end Check_Matching_Types;
7134 end if;
7136 -- Match is now False if the entry we found did not match
7137 -- either a supplied Parameter_Types or Result_Types argument
7139 if Match then
7140 if No (Ent) then
7141 Ent := Def_Id;
7143 -- Ambiguous case, the flag Ambiguous shows if we already
7144 -- detected this and output the initial messages.
7146 else
7147 if not Ambiguous then
7148 Ambiguous := True;
7149 Error_Msg_Name_1 := Pname;
7150 Error_Msg_N
7151 ("pragma% does not uniquely identify subprogram!",
7153 Error_Msg_Sloc := Sloc (Ent);
7154 Error_Msg_N ("matching subprogram #!", N);
7155 Ent := Empty;
7156 end if;
7158 Error_Msg_Sloc := Sloc (Def_Id);
7159 Error_Msg_N ("matching subprogram #!", N);
7160 end if;
7161 end if;
7162 end if;
7164 Hom_Id := Homonym (Hom_Id);
7165 end loop;
7167 -- See if we found an entry
7169 if No (Ent) then
7170 if not Ambiguous then
7171 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
7172 Error_Pragma
7173 ("pragma% cannot be given for generic subprogram");
7174 else
7175 Error_Pragma
7176 ("pragma% does not identify local subprogram");
7177 end if;
7178 end if;
7180 return;
7181 end if;
7183 -- Import pragmas must be for imported entities
7185 if Prag_Id = Pragma_Import_Function
7186 or else
7187 Prag_Id = Pragma_Import_Procedure
7188 or else
7189 Prag_Id = Pragma_Import_Valued_Procedure
7190 then
7191 if not Is_Imported (Ent) then
7192 Error_Pragma
7193 ("pragma Import or Interface must precede pragma%");
7194 end if;
7196 -- Here we have the Export case which can set the entity as exported
7198 -- But does not do so if the specified external name is null, since
7199 -- that is taken as a signal in DEC Ada 83 (with which we want to be
7200 -- compatible) to request no external name.
7202 elsif Nkind (Arg_External) = N_String_Literal
7203 and then String_Length (Strval (Arg_External)) = 0
7204 then
7205 null;
7207 -- In all other cases, set entity as exported
7209 else
7210 Set_Exported (Ent, Arg_Internal);
7211 end if;
7213 -- Special processing for Valued_Procedure cases
7215 if Prag_Id = Pragma_Import_Valued_Procedure
7216 or else
7217 Prag_Id = Pragma_Export_Valued_Procedure
7218 then
7219 Formal := First_Formal (Ent);
7221 if No (Formal) then
7222 Error_Pragma ("at least one parameter required for pragma%");
7224 elsif Ekind (Formal) /= E_Out_Parameter then
7225 Error_Pragma ("first parameter must have mode out for pragma%");
7227 else
7228 Set_Is_Valued_Procedure (Ent);
7229 end if;
7230 end if;
7232 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
7234 -- Process Result_Mechanism argument if present. We have already
7235 -- checked that this is only allowed for the function case.
7237 if Present (Arg_Result_Mechanism) then
7238 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
7239 end if;
7241 -- Process Mechanism parameter if present. Note that this parameter
7242 -- is not analyzed, and must not be analyzed since it is semantic
7243 -- nonsense, so we get it in exactly as the parser left it.
7245 if Present (Arg_Mechanism) then
7246 declare
7247 Formal : Entity_Id;
7248 Massoc : Node_Id;
7249 Mname : Node_Id;
7250 Choice : Node_Id;
7252 begin
7253 -- A single mechanism association without a formal parameter
7254 -- name is parsed as a parenthesized expression. All other
7255 -- cases are parsed as aggregates, so we rewrite the single
7256 -- parameter case as an aggregate for consistency.
7258 if Nkind (Arg_Mechanism) /= N_Aggregate
7259 and then Paren_Count (Arg_Mechanism) = 1
7260 then
7261 Rewrite (Arg_Mechanism,
7262 Make_Aggregate (Sloc (Arg_Mechanism),
7263 Expressions => New_List (
7264 Relocate_Node (Arg_Mechanism))));
7265 end if;
7267 -- Case of only mechanism name given, applies to all formals
7269 if Nkind (Arg_Mechanism) /= N_Aggregate then
7270 Formal := First_Formal (Ent);
7271 while Present (Formal) loop
7272 Set_Mechanism_Value (Formal, Arg_Mechanism);
7273 Next_Formal (Formal);
7274 end loop;
7276 -- Case of list of mechanism associations given
7278 else
7279 if Null_Record_Present (Arg_Mechanism) then
7280 Error_Pragma_Arg
7281 ("inappropriate form for Mechanism parameter",
7282 Arg_Mechanism);
7283 end if;
7285 -- Deal with positional ones first
7287 Formal := First_Formal (Ent);
7289 if Present (Expressions (Arg_Mechanism)) then
7290 Mname := First (Expressions (Arg_Mechanism));
7291 while Present (Mname) loop
7292 if No (Formal) then
7293 Error_Pragma_Arg
7294 ("too many mechanism associations", Mname);
7295 end if;
7297 Set_Mechanism_Value (Formal, Mname);
7298 Next_Formal (Formal);
7299 Next (Mname);
7300 end loop;
7301 end if;
7303 -- Deal with named entries
7305 if Present (Component_Associations (Arg_Mechanism)) then
7306 Massoc := First (Component_Associations (Arg_Mechanism));
7307 while Present (Massoc) loop
7308 Choice := First (Choices (Massoc));
7310 if Nkind (Choice) /= N_Identifier
7311 or else Present (Next (Choice))
7312 then
7313 Error_Pragma_Arg
7314 ("incorrect form for mechanism association",
7315 Massoc);
7316 end if;
7318 Formal := First_Formal (Ent);
7319 loop
7320 if No (Formal) then
7321 Error_Pragma_Arg
7322 ("parameter name & not present", Choice);
7323 end if;
7325 if Chars (Choice) = Chars (Formal) then
7326 Set_Mechanism_Value
7327 (Formal, Expression (Massoc));
7329 -- Set entity on identifier (needed by ASIS)
7331 Set_Entity (Choice, Formal);
7333 exit;
7334 end if;
7336 Next_Formal (Formal);
7337 end loop;
7339 Next (Massoc);
7340 end loop;
7341 end if;
7342 end if;
7343 end;
7344 end if;
7345 end Process_Extended_Import_Export_Subprogram_Pragma;
7347 --------------------------
7348 -- Process_Generic_List --
7349 --------------------------
7351 procedure Process_Generic_List is
7352 Arg : Node_Id;
7353 Exp : Node_Id;
7355 begin
7356 Check_No_Identifiers;
7357 Check_At_Least_N_Arguments (1);
7359 -- Check all arguments are names of generic units or instances
7361 Arg := Arg1;
7362 while Present (Arg) loop
7363 Exp := Get_Pragma_Arg (Arg);
7364 Analyze (Exp);
7366 if not Is_Entity_Name (Exp)
7367 or else
7368 (not Is_Generic_Instance (Entity (Exp))
7369 and then
7370 not Is_Generic_Unit (Entity (Exp)))
7371 then
7372 Error_Pragma_Arg
7373 ("pragma% argument must be name of generic unit/instance",
7374 Arg);
7375 end if;
7377 Next (Arg);
7378 end loop;
7379 end Process_Generic_List;
7381 ------------------------------------
7382 -- Process_Import_Predefined_Type --
7383 ------------------------------------
7385 procedure Process_Import_Predefined_Type is
7386 Loc : constant Source_Ptr := Sloc (N);
7387 Elmt : Elmt_Id;
7388 Ftyp : Node_Id := Empty;
7389 Decl : Node_Id;
7390 Def : Node_Id;
7391 Nam : Name_Id;
7393 begin
7394 String_To_Name_Buffer (Strval (Expression (Arg3)));
7395 Nam := Name_Find;
7397 Elmt := First_Elmt (Predefined_Float_Types);
7398 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
7399 Next_Elmt (Elmt);
7400 end loop;
7402 Ftyp := Node (Elmt);
7404 if Present (Ftyp) then
7406 -- Don't build a derived type declaration, because predefined C
7407 -- types have no declaration anywhere, so cannot really be named.
7408 -- Instead build a full type declaration, starting with an
7409 -- appropriate type definition is built
7411 if Is_Floating_Point_Type (Ftyp) then
7412 Def := Make_Floating_Point_Definition (Loc,
7413 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
7414 Make_Real_Range_Specification (Loc,
7415 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
7416 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
7418 -- Should never have a predefined type we cannot handle
7420 else
7421 raise Program_Error;
7422 end if;
7424 -- Build and insert a Full_Type_Declaration, which will be
7425 -- analyzed as soon as this list entry has been analyzed.
7427 Decl := Make_Full_Type_Declaration (Loc,
7428 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
7429 Type_Definition => Def);
7431 Insert_After (N, Decl);
7432 Mark_Rewrite_Insertion (Decl);
7434 else
7435 Error_Pragma_Arg ("no matching type found for pragma%",
7436 Arg2);
7437 end if;
7438 end Process_Import_Predefined_Type;
7440 ---------------------------------
7441 -- Process_Import_Or_Interface --
7442 ---------------------------------
7444 procedure Process_Import_Or_Interface is
7445 C : Convention_Id;
7446 Def_Id : Entity_Id;
7447 Hom_Id : Entity_Id;
7449 begin
7450 -- In Relaxed_RM_Semantics, support old Ada 83 style:
7451 -- pragma Import (Entity, "external name");
7453 if Relaxed_RM_Semantics
7454 and then Arg_Count = 2
7455 and then Prag_Id = Pragma_Import
7456 and then Nkind (Expression (Arg2)) = N_String_Literal
7457 then
7458 C := Convention_C;
7459 Def_Id := Get_Pragma_Arg (Arg1);
7460 Analyze (Def_Id);
7462 if not Is_Entity_Name (Def_Id) then
7463 Error_Pragma_Arg ("entity name required", Arg1);
7464 end if;
7466 Def_Id := Entity (Def_Id);
7467 Kill_Size_Check_Code (Def_Id);
7468 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
7470 else
7471 Process_Convention (C, Def_Id);
7472 Kill_Size_Check_Code (Def_Id);
7473 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
7474 end if;
7476 -- Various error checks
7478 if Ekind_In (Def_Id, E_Variable, E_Constant) then
7480 -- We do not permit Import to apply to a renaming declaration
7482 if Present (Renamed_Object (Def_Id)) then
7483 Error_Pragma_Arg
7484 ("pragma% not allowed for object renaming", Arg2);
7486 -- User initialization is not allowed for imported object, but
7487 -- the object declaration may contain a default initialization,
7488 -- that will be discarded. Note that an explicit initialization
7489 -- only counts if it comes from source, otherwise it is simply
7490 -- the code generator making an implicit initialization explicit.
7492 elsif Present (Expression (Parent (Def_Id)))
7493 and then Comes_From_Source
7494 (Original_Node (Expression (Parent (Def_Id))))
7495 then
7496 -- Set imported flag to prevent cascaded errors
7498 Set_Is_Imported (Def_Id);
7500 Error_Msg_Sloc := Sloc (Def_Id);
7501 Error_Pragma_Arg
7502 ("no initialization allowed for declaration of& #",
7503 "\imported entities cannot be initialized (RM B.1(24))",
7504 Arg2);
7506 else
7507 -- If the pragma comes from an aspect specification the
7508 -- Is_Imported flag has already been set.
7510 if not From_Aspect_Specification (N) then
7511 Set_Imported (Def_Id);
7512 end if;
7514 Process_Interface_Name (Def_Id, Arg3, Arg4);
7516 -- Note that we do not set Is_Public here. That's because we
7517 -- only want to set it if there is no address clause, and we
7518 -- don't know that yet, so we delay that processing till
7519 -- freeze time.
7521 -- pragma Import completes deferred constants
7523 if Ekind (Def_Id) = E_Constant then
7524 Set_Has_Completion (Def_Id);
7525 end if;
7527 -- It is not possible to import a constant of an unconstrained
7528 -- array type (e.g. string) because there is no simple way to
7529 -- write a meaningful subtype for it.
7531 if Is_Array_Type (Etype (Def_Id))
7532 and then not Is_Constrained (Etype (Def_Id))
7533 then
7534 Error_Msg_NE
7535 ("imported constant& must have a constrained subtype",
7536 N, Def_Id);
7537 end if;
7538 end if;
7540 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
7542 -- If the name is overloaded, pragma applies to all of the denoted
7543 -- entities in the same declarative part, unless the pragma comes
7544 -- from an aspect specification or was generated by the compiler
7545 -- (such as for pragma Provide_Shift_Operators).
7547 Hom_Id := Def_Id;
7548 while Present (Hom_Id) loop
7550 Def_Id := Get_Base_Subprogram (Hom_Id);
7552 -- Ignore inherited subprograms because the pragma will apply
7553 -- to the parent operation, which is the one called.
7555 if Is_Overloadable (Def_Id)
7556 and then Present (Alias (Def_Id))
7557 then
7558 null;
7560 -- If it is not a subprogram, it must be in an outer scope and
7561 -- pragma does not apply.
7563 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
7564 null;
7566 -- The pragma does not apply to primitives of interfaces
7568 elsif Is_Dispatching_Operation (Def_Id)
7569 and then Present (Find_Dispatching_Type (Def_Id))
7570 and then Is_Interface (Find_Dispatching_Type (Def_Id))
7571 then
7572 null;
7574 -- Verify that the homonym is in the same declarative part (not
7575 -- just the same scope). If the pragma comes from an aspect
7576 -- specification we know that it is part of the declaration.
7578 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
7579 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
7580 and then not From_Aspect_Specification (N)
7581 then
7582 exit;
7584 else
7585 -- If the pragma comes from an aspect specification the
7586 -- Is_Imported flag has already been set.
7588 if not From_Aspect_Specification (N) then
7589 Set_Imported (Def_Id);
7590 end if;
7592 -- Reject an Import applied to an abstract subprogram
7594 if Is_Subprogram (Def_Id)
7595 and then Is_Abstract_Subprogram (Def_Id)
7596 then
7597 Error_Msg_Sloc := Sloc (Def_Id);
7598 Error_Msg_NE
7599 ("cannot import abstract subprogram& declared#",
7600 Arg2, Def_Id);
7601 end if;
7603 -- Special processing for Convention_Intrinsic
7605 if C = Convention_Intrinsic then
7607 -- Link_Name argument not allowed for intrinsic
7609 Check_No_Link_Name;
7611 Set_Is_Intrinsic_Subprogram (Def_Id);
7613 -- If no external name is present, then check that this
7614 -- is a valid intrinsic subprogram. If an external name
7615 -- is present, then this is handled by the back end.
7617 if No (Arg3) then
7618 Check_Intrinsic_Subprogram
7619 (Def_Id, Get_Pragma_Arg (Arg2));
7620 end if;
7621 end if;
7623 -- Verify that the subprogram does not have a completion
7624 -- through a renaming declaration. For other completions the
7625 -- pragma appears as a too late representation.
7627 declare
7628 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
7630 begin
7631 if Present (Decl)
7632 and then Nkind (Decl) = N_Subprogram_Declaration
7633 and then Present (Corresponding_Body (Decl))
7634 and then Nkind (Unit_Declaration_Node
7635 (Corresponding_Body (Decl))) =
7636 N_Subprogram_Renaming_Declaration
7637 then
7638 Error_Msg_Sloc := Sloc (Def_Id);
7639 Error_Msg_NE
7640 ("cannot import&, renaming already provided for "
7641 & "declaration #", N, Def_Id);
7642 end if;
7643 end;
7645 -- If the pragma comes from an aspect specification, there
7646 -- must be an Import aspect specified as well. In the rare
7647 -- case where Import is set to False, the suprogram needs to
7648 -- have a local completion.
7650 declare
7651 Imp_Aspect : constant Node_Id :=
7652 Find_Aspect (Def_Id, Aspect_Import);
7653 Expr : Node_Id;
7655 begin
7656 if Present (Imp_Aspect)
7657 and then Present (Expression (Imp_Aspect))
7658 then
7659 Expr := Expression (Imp_Aspect);
7660 Analyze_And_Resolve (Expr, Standard_Boolean);
7662 if Is_Entity_Name (Expr)
7663 and then Entity (Expr) = Standard_True
7664 then
7665 Set_Has_Completion (Def_Id);
7666 end if;
7668 -- If there is no expression, the default is True, as for
7669 -- all boolean aspects. Same for the older pragma.
7671 else
7672 Set_Has_Completion (Def_Id);
7673 end if;
7674 end;
7676 Process_Interface_Name (Def_Id, Arg3, Arg4);
7677 end if;
7679 if Is_Compilation_Unit (Hom_Id) then
7681 -- Its possible homonyms are not affected by the pragma.
7682 -- Such homonyms might be present in the context of other
7683 -- units being compiled.
7685 exit;
7687 elsif From_Aspect_Specification (N) then
7688 exit;
7690 -- If the pragma was created by the compiler, then we don't
7691 -- want it to apply to other homonyms. This kind of case can
7692 -- occur when using pragma Provide_Shift_Operators, which
7693 -- generates implicit shift and rotate operators with Import
7694 -- pragmas that might apply to earlier explicit or implicit
7695 -- declarations marked with Import (for example, coming from
7696 -- an earlier pragma Provide_Shift_Operators for another type),
7697 -- and we don't generally want other homonyms being treated
7698 -- as imported or the pragma flagged as an illegal duplicate.
7700 elsif not Comes_From_Source (N) then
7701 exit;
7703 else
7704 Hom_Id := Homonym (Hom_Id);
7705 end if;
7706 end loop;
7708 -- When the convention is Java or CIL, we also allow Import to
7709 -- be given for packages, generic packages, exceptions, record
7710 -- components, and access to subprograms.
7712 elsif (C = Convention_Java or else C = Convention_CIL)
7713 and then
7714 (Is_Package_Or_Generic_Package (Def_Id)
7715 or else Ekind (Def_Id) = E_Exception
7716 or else Ekind (Def_Id) = E_Access_Subprogram_Type
7717 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
7718 then
7719 Set_Imported (Def_Id);
7720 Set_Is_Public (Def_Id);
7721 Process_Interface_Name (Def_Id, Arg3, Arg4);
7723 -- Import a CPP class
7725 elsif C = Convention_CPP
7726 and then (Is_Record_Type (Def_Id)
7727 or else Ekind (Def_Id) = E_Incomplete_Type)
7728 then
7729 if Ekind (Def_Id) = E_Incomplete_Type then
7730 if Present (Full_View (Def_Id)) then
7731 Def_Id := Full_View (Def_Id);
7733 else
7734 Error_Msg_N
7735 ("cannot import 'C'P'P type before full declaration seen",
7736 Get_Pragma_Arg (Arg2));
7738 -- Although we have reported the error we decorate it as
7739 -- CPP_Class to avoid reporting spurious errors
7741 Set_Is_CPP_Class (Def_Id);
7742 return;
7743 end if;
7744 end if;
7746 -- Types treated as CPP classes must be declared limited (note:
7747 -- this used to be a warning but there is no real benefit to it
7748 -- since we did effectively intend to treat the type as limited
7749 -- anyway).
7751 if not Is_Limited_Type (Def_Id) then
7752 Error_Msg_N
7753 ("imported 'C'P'P type must be limited",
7754 Get_Pragma_Arg (Arg2));
7755 end if;
7757 if Etype (Def_Id) /= Def_Id
7758 and then not Is_CPP_Class (Root_Type (Def_Id))
7759 then
7760 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
7761 end if;
7763 Set_Is_CPP_Class (Def_Id);
7765 -- Imported CPP types must not have discriminants (because C++
7766 -- classes do not have discriminants).
7768 if Has_Discriminants (Def_Id) then
7769 Error_Msg_N
7770 ("imported 'C'P'P type cannot have discriminants",
7771 First (Discriminant_Specifications
7772 (Declaration_Node (Def_Id))));
7773 end if;
7775 -- Check that components of imported CPP types do not have default
7776 -- expressions. For private types this check is performed when the
7777 -- full view is analyzed (see Process_Full_View).
7779 if not Is_Private_Type (Def_Id) then
7780 Check_CPP_Type_Has_No_Defaults (Def_Id);
7781 end if;
7783 -- Import a CPP exception
7785 elsif C = Convention_CPP
7786 and then Ekind (Def_Id) = E_Exception
7787 then
7788 if No (Arg3) then
7789 Error_Pragma_Arg
7790 ("'External_'Name arguments is required for 'Cpp exception",
7791 Arg3);
7792 else
7793 -- As only a string is allowed, Check_Arg_Is_External_Name
7794 -- isn't called.
7796 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
7797 end if;
7799 if Present (Arg4) then
7800 Error_Pragma_Arg
7801 ("Link_Name argument not allowed for imported Cpp exception",
7802 Arg4);
7803 end if;
7805 -- Do not call Set_Interface_Name as the name of the exception
7806 -- shouldn't be modified (and in particular it shouldn't be
7807 -- the External_Name). For exceptions, the External_Name is the
7808 -- name of the RTTI structure.
7810 -- ??? Emit an error if pragma Import/Export_Exception is present
7812 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
7813 Check_No_Link_Name;
7814 Check_Arg_Count (3);
7815 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
7817 Process_Import_Predefined_Type;
7819 else
7820 Error_Pragma_Arg
7821 ("second argument of pragma% must be object, subprogram "
7822 & "or incomplete type",
7823 Arg2);
7824 end if;
7826 -- If this pragma applies to a compilation unit, then the unit, which
7827 -- is a subprogram, does not require (or allow) a body. We also do
7828 -- not need to elaborate imported procedures.
7830 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
7831 declare
7832 Cunit : constant Node_Id := Parent (Parent (N));
7833 begin
7834 Set_Body_Required (Cunit, False);
7835 end;
7836 end if;
7837 end Process_Import_Or_Interface;
7839 --------------------
7840 -- Process_Inline --
7841 --------------------
7843 procedure Process_Inline (Status : Inline_Status) is
7844 Assoc : Node_Id;
7845 Decl : Node_Id;
7846 Subp_Id : Node_Id;
7847 Subp : Entity_Id;
7848 Applies : Boolean;
7850 procedure Make_Inline (Subp : Entity_Id);
7851 -- Subp is the defining unit name of the subprogram declaration. Set
7852 -- the flag, as well as the flag in the corresponding body, if there
7853 -- is one present.
7855 procedure Set_Inline_Flags (Subp : Entity_Id);
7856 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
7857 -- Has_Pragma_Inline_Always for the Inline_Always case.
7859 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
7860 -- Returns True if it can be determined at this stage that inlining
7861 -- is not possible, for example if the body is available and contains
7862 -- exception handlers, we prevent inlining, since otherwise we can
7863 -- get undefined symbols at link time. This function also emits a
7864 -- warning if front-end inlining is enabled and the pragma appears
7865 -- too late.
7867 -- ??? is business with link symbols still valid, or does it relate
7868 -- to front end ZCX which is being phased out ???
7870 ---------------------------
7871 -- Inlining_Not_Possible --
7872 ---------------------------
7874 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
7875 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
7876 Stats : Node_Id;
7878 begin
7879 if Nkind (Decl) = N_Subprogram_Body then
7880 Stats := Handled_Statement_Sequence (Decl);
7881 return Present (Exception_Handlers (Stats))
7882 or else Present (At_End_Proc (Stats));
7884 elsif Nkind (Decl) = N_Subprogram_Declaration
7885 and then Present (Corresponding_Body (Decl))
7886 then
7887 if Front_End_Inlining
7888 and then Analyzed (Corresponding_Body (Decl))
7889 then
7890 Error_Msg_N ("pragma appears too late, ignored??", N);
7891 return True;
7893 -- If the subprogram is a renaming as body, the body is just a
7894 -- call to the renamed subprogram, and inlining is trivially
7895 -- possible.
7897 elsif
7898 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
7899 N_Subprogram_Renaming_Declaration
7900 then
7901 return False;
7903 else
7904 Stats :=
7905 Handled_Statement_Sequence
7906 (Unit_Declaration_Node (Corresponding_Body (Decl)));
7908 return
7909 Present (Exception_Handlers (Stats))
7910 or else Present (At_End_Proc (Stats));
7911 end if;
7913 else
7914 -- If body is not available, assume the best, the check is
7915 -- performed again when compiling enclosing package bodies.
7917 return False;
7918 end if;
7919 end Inlining_Not_Possible;
7921 -----------------
7922 -- Make_Inline --
7923 -----------------
7925 procedure Make_Inline (Subp : Entity_Id) is
7926 Kind : constant Entity_Kind := Ekind (Subp);
7927 Inner_Subp : Entity_Id := Subp;
7929 begin
7930 -- Ignore if bad type, avoid cascaded error
7932 if Etype (Subp) = Any_Type then
7933 Applies := True;
7934 return;
7936 -- If inlining is not possible, for now do not treat as an error
7938 elsif Status /= Suppressed
7939 and then Inlining_Not_Possible (Subp)
7940 then
7941 Applies := True;
7942 return;
7944 -- Here we have a candidate for inlining, but we must exclude
7945 -- derived operations. Otherwise we would end up trying to inline
7946 -- a phantom declaration, and the result would be to drag in a
7947 -- body which has no direct inlining associated with it. That
7948 -- would not only be inefficient but would also result in the
7949 -- backend doing cross-unit inlining in cases where it was
7950 -- definitely inappropriate to do so.
7952 -- However, a simple Comes_From_Source test is insufficient, since
7953 -- we do want to allow inlining of generic instances which also do
7954 -- not come from source. We also need to recognize specs generated
7955 -- by the front-end for bodies that carry the pragma. Finally,
7956 -- predefined operators do not come from source but are not
7957 -- inlineable either.
7959 elsif Is_Generic_Instance (Subp)
7960 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
7961 then
7962 null;
7964 elsif not Comes_From_Source (Subp)
7965 and then Scope (Subp) /= Standard_Standard
7966 then
7967 Applies := True;
7968 return;
7969 end if;
7971 -- The referenced entity must either be the enclosing entity, or
7972 -- an entity declared within the current open scope.
7974 if Present (Scope (Subp))
7975 and then Scope (Subp) /= Current_Scope
7976 and then Subp /= Current_Scope
7977 then
7978 Error_Pragma_Arg
7979 ("argument of% must be entity in current scope", Assoc);
7980 return;
7981 end if;
7983 -- Processing for procedure, operator or function. If subprogram
7984 -- is aliased (as for an instance) indicate that the renamed
7985 -- entity (if declared in the same unit) is inlined.
7987 if Is_Subprogram (Subp) then
7988 Inner_Subp := Ultimate_Alias (Inner_Subp);
7990 if In_Same_Source_Unit (Subp, Inner_Subp) then
7991 Set_Inline_Flags (Inner_Subp);
7993 Decl := Parent (Parent (Inner_Subp));
7995 if Nkind (Decl) = N_Subprogram_Declaration
7996 and then Present (Corresponding_Body (Decl))
7997 then
7998 Set_Inline_Flags (Corresponding_Body (Decl));
8000 elsif Is_Generic_Instance (Subp) then
8002 -- Indicate that the body needs to be created for
8003 -- inlining subsequent calls. The instantiation node
8004 -- follows the declaration of the wrapper package
8005 -- created for it.
8007 if Scope (Subp) /= Standard_Standard
8008 and then
8009 Need_Subprogram_Instance_Body
8010 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
8011 Subp)
8012 then
8013 null;
8014 end if;
8016 -- Inline is a program unit pragma (RM 10.1.5) and cannot
8017 -- appear in a formal part to apply to a formal subprogram.
8018 -- Do not apply check within an instance or a formal package
8019 -- the test will have been applied to the original generic.
8021 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
8022 and then List_Containing (Decl) = List_Containing (N)
8023 and then not In_Instance
8024 then
8025 Error_Msg_N
8026 ("Inline cannot apply to a formal subprogram", N);
8028 -- If Subp is a renaming, it is the renamed entity that
8029 -- will appear in any call, and be inlined. However, for
8030 -- ASIS uses it is convenient to indicate that the renaming
8031 -- itself is an inlined subprogram, so that some gnatcheck
8032 -- rules can be applied in the absence of expansion.
8034 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
8035 Set_Inline_Flags (Subp);
8036 end if;
8037 end if;
8039 Applies := True;
8041 -- For a generic subprogram set flag as well, for use at the point
8042 -- of instantiation, to determine whether the body should be
8043 -- generated.
8045 elsif Is_Generic_Subprogram (Subp) then
8046 Set_Inline_Flags (Subp);
8047 Applies := True;
8049 -- Literals are by definition inlined
8051 elsif Kind = E_Enumeration_Literal then
8052 null;
8054 -- Anything else is an error
8056 else
8057 Error_Pragma_Arg
8058 ("expect subprogram name for pragma%", Assoc);
8059 end if;
8060 end Make_Inline;
8062 ----------------------
8063 -- Set_Inline_Flags --
8064 ----------------------
8066 procedure Set_Inline_Flags (Subp : Entity_Id) is
8067 begin
8068 -- First set the Has_Pragma_XXX flags and issue the appropriate
8069 -- errors and warnings for suspicious combinations.
8071 if Prag_Id = Pragma_No_Inline then
8072 if Has_Pragma_Inline_Always (Subp) then
8073 Error_Msg_N
8074 ("Inline_Always and No_Inline are mutually exclusive", N);
8075 elsif Has_Pragma_Inline (Subp) then
8076 Error_Msg_NE
8077 ("Inline and No_Inline both specified for& ??",
8078 N, Entity (Subp_Id));
8079 end if;
8081 Set_Has_Pragma_No_Inline (Subp);
8082 else
8083 if Prag_Id = Pragma_Inline_Always then
8084 if Has_Pragma_No_Inline (Subp) then
8085 Error_Msg_N
8086 ("Inline_Always and No_Inline are mutually exclusive",
8088 end if;
8090 Set_Has_Pragma_Inline_Always (Subp);
8091 else
8092 if Has_Pragma_No_Inline (Subp) then
8093 Error_Msg_NE
8094 ("Inline and No_Inline both specified for& ??",
8095 N, Entity (Subp_Id));
8096 end if;
8097 end if;
8099 if not Has_Pragma_Inline (Subp) then
8100 Set_Has_Pragma_Inline (Subp);
8101 end if;
8102 end if;
8104 -- Then adjust the Is_Inlined flag. It can never be set if the
8105 -- subprogram is subject to pragma No_Inline.
8107 case Status is
8108 when Suppressed =>
8109 Set_Is_Inlined (Subp, False);
8110 when Disabled =>
8111 null;
8112 when Enabled =>
8113 if not Has_Pragma_No_Inline (Subp) then
8114 Set_Is_Inlined (Subp, True);
8115 end if;
8116 end case;
8117 end Set_Inline_Flags;
8119 -- Start of processing for Process_Inline
8121 begin
8122 Check_No_Identifiers;
8123 Check_At_Least_N_Arguments (1);
8125 if Status = Enabled then
8126 Inline_Processing_Required := True;
8127 end if;
8129 Assoc := Arg1;
8130 while Present (Assoc) loop
8131 Subp_Id := Get_Pragma_Arg (Assoc);
8132 Analyze (Subp_Id);
8133 Applies := False;
8135 if Is_Entity_Name (Subp_Id) then
8136 Subp := Entity (Subp_Id);
8138 if Subp = Any_Id then
8140 -- If previous error, avoid cascaded errors
8142 Check_Error_Detected;
8143 Applies := True;
8145 else
8146 Make_Inline (Subp);
8148 -- For the pragma case, climb homonym chain. This is
8149 -- what implements allowing the pragma in the renaming
8150 -- case, with the result applying to the ancestors, and
8151 -- also allows Inline to apply to all previous homonyms.
8153 if not From_Aspect_Specification (N) then
8154 while Present (Homonym (Subp))
8155 and then Scope (Homonym (Subp)) = Current_Scope
8156 loop
8157 Make_Inline (Homonym (Subp));
8158 Subp := Homonym (Subp);
8159 end loop;
8160 end if;
8161 end if;
8162 end if;
8164 if not Applies then
8165 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
8166 end if;
8168 Next (Assoc);
8169 end loop;
8170 end Process_Inline;
8172 ----------------------------
8173 -- Process_Interface_Name --
8174 ----------------------------
8176 procedure Process_Interface_Name
8177 (Subprogram_Def : Entity_Id;
8178 Ext_Arg : Node_Id;
8179 Link_Arg : Node_Id)
8181 Ext_Nam : Node_Id;
8182 Link_Nam : Node_Id;
8183 String_Val : String_Id;
8185 procedure Check_Form_Of_Interface_Name
8186 (SN : Node_Id;
8187 Ext_Name_Case : Boolean);
8188 -- SN is a string literal node for an interface name. This routine
8189 -- performs some minimal checks that the name is reasonable. In
8190 -- particular that no spaces or other obviously incorrect characters
8191 -- appear. This is only a warning, since any characters are allowed.
8192 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
8194 ----------------------------------
8195 -- Check_Form_Of_Interface_Name --
8196 ----------------------------------
8198 procedure Check_Form_Of_Interface_Name
8199 (SN : Node_Id;
8200 Ext_Name_Case : Boolean)
8202 S : constant String_Id := Strval (Expr_Value_S (SN));
8203 SL : constant Nat := String_Length (S);
8204 C : Char_Code;
8206 begin
8207 if SL = 0 then
8208 Error_Msg_N ("interface name cannot be null string", SN);
8209 end if;
8211 for J in 1 .. SL loop
8212 C := Get_String_Char (S, J);
8214 -- Look for dubious character and issue unconditional warning.
8215 -- Definitely dubious if not in character range.
8217 if not In_Character_Range (C)
8219 -- For all cases except CLI target,
8220 -- commas, spaces and slashes are dubious (in CLI, we use
8221 -- commas and backslashes in external names to specify
8222 -- assembly version and public key, while slashes and spaces
8223 -- can be used in names to mark nested classes and
8224 -- valuetypes).
8226 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
8227 and then (Get_Character (C) = ','
8228 or else
8229 Get_Character (C) = '\'))
8230 or else (VM_Target /= CLI_Target
8231 and then (Get_Character (C) = ' '
8232 or else
8233 Get_Character (C) = '/'))
8234 then
8235 Error_Msg
8236 ("??interface name contains illegal character",
8237 Sloc (SN) + Source_Ptr (J));
8238 end if;
8239 end loop;
8240 end Check_Form_Of_Interface_Name;
8242 -- Start of processing for Process_Interface_Name
8244 begin
8245 if No (Link_Arg) then
8246 if No (Ext_Arg) then
8247 if VM_Target = CLI_Target
8248 and then Ekind (Subprogram_Def) = E_Package
8249 and then Nkind (Parent (Subprogram_Def)) =
8250 N_Package_Specification
8251 and then Present (Generic_Parent (Parent (Subprogram_Def)))
8252 then
8253 Set_Interface_Name
8254 (Subprogram_Def,
8255 Interface_Name
8256 (Generic_Parent (Parent (Subprogram_Def))));
8257 end if;
8259 return;
8261 elsif Chars (Ext_Arg) = Name_Link_Name then
8262 Ext_Nam := Empty;
8263 Link_Nam := Expression (Ext_Arg);
8265 else
8266 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
8267 Ext_Nam := Expression (Ext_Arg);
8268 Link_Nam := Empty;
8269 end if;
8271 else
8272 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
8273 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
8274 Ext_Nam := Expression (Ext_Arg);
8275 Link_Nam := Expression (Link_Arg);
8276 end if;
8278 -- Check expressions for external name and link name are static
8280 if Present (Ext_Nam) then
8281 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
8282 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
8284 -- Verify that external name is not the name of a local entity,
8285 -- which would hide the imported one and could lead to run-time
8286 -- surprises. The problem can only arise for entities declared in
8287 -- a package body (otherwise the external name is fully qualified
8288 -- and will not conflict).
8290 declare
8291 Nam : Name_Id;
8292 E : Entity_Id;
8293 Par : Node_Id;
8295 begin
8296 if Prag_Id = Pragma_Import then
8297 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
8298 Nam := Name_Find;
8299 E := Entity_Id (Get_Name_Table_Int (Nam));
8301 if Nam /= Chars (Subprogram_Def)
8302 and then Present (E)
8303 and then not Is_Overloadable (E)
8304 and then Is_Immediately_Visible (E)
8305 and then not Is_Imported (E)
8306 and then Ekind (Scope (E)) = E_Package
8307 then
8308 Par := Parent (E);
8309 while Present (Par) loop
8310 if Nkind (Par) = N_Package_Body then
8311 Error_Msg_Sloc := Sloc (E);
8312 Error_Msg_NE
8313 ("imported entity is hidden by & declared#",
8314 Ext_Arg, E);
8315 exit;
8316 end if;
8318 Par := Parent (Par);
8319 end loop;
8320 end if;
8321 end if;
8322 end;
8323 end if;
8325 if Present (Link_Nam) then
8326 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
8327 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
8328 end if;
8330 -- If there is no link name, just set the external name
8332 if No (Link_Nam) then
8333 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
8335 -- For the Link_Name case, the given literal is preceded by an
8336 -- asterisk, which indicates to GCC that the given name should be
8337 -- taken literally, and in particular that no prepending of
8338 -- underlines should occur, even in systems where this is the
8339 -- normal default.
8341 else
8342 Start_String;
8344 if VM_Target = No_VM then
8345 Store_String_Char (Get_Char_Code ('*'));
8346 end if;
8348 String_Val := Strval (Expr_Value_S (Link_Nam));
8349 Store_String_Chars (String_Val);
8350 Link_Nam :=
8351 Make_String_Literal (Sloc (Link_Nam),
8352 Strval => End_String);
8353 end if;
8355 -- Set the interface name. If the entity is a generic instance, use
8356 -- its alias, which is the callable entity.
8358 if Is_Generic_Instance (Subprogram_Def) then
8359 Set_Encoded_Interface_Name
8360 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
8361 else
8362 Set_Encoded_Interface_Name
8363 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
8364 end if;
8366 -- We allow duplicated export names in CIL/Java, as they are always
8367 -- enclosed in a namespace that differentiates them, and overloaded
8368 -- entities are supported by the VM.
8370 if Convention (Subprogram_Def) /= Convention_CIL
8371 and then
8372 Convention (Subprogram_Def) /= Convention_Java
8373 then
8374 Check_Duplicated_Export_Name (Link_Nam);
8375 end if;
8376 end Process_Interface_Name;
8378 -----------------------------------------
8379 -- Process_Interrupt_Or_Attach_Handler --
8380 -----------------------------------------
8382 procedure Process_Interrupt_Or_Attach_Handler is
8383 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
8384 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
8385 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
8387 begin
8388 Set_Is_Interrupt_Handler (Handler_Proc);
8390 -- If the pragma is not associated with a handler procedure within a
8391 -- protected type, then it must be for a nonprotected procedure for
8392 -- the AAMP target, in which case we don't associate a representation
8393 -- item with the procedure's scope.
8395 if Ekind (Proc_Scope) = E_Protected_Type then
8396 if Prag_Id = Pragma_Interrupt_Handler
8397 or else
8398 Prag_Id = Pragma_Attach_Handler
8399 then
8400 Record_Rep_Item (Proc_Scope, N);
8401 end if;
8402 end if;
8403 end Process_Interrupt_Or_Attach_Handler;
8405 --------------------------------------------------
8406 -- Process_Restrictions_Or_Restriction_Warnings --
8407 --------------------------------------------------
8409 -- Note: some of the simple identifier cases were handled in par-prag,
8410 -- but it is harmless (and more straightforward) to simply handle all
8411 -- cases here, even if it means we repeat a bit of work in some cases.
8413 procedure Process_Restrictions_Or_Restriction_Warnings
8414 (Warn : Boolean)
8416 Arg : Node_Id;
8417 R_Id : Restriction_Id;
8418 Id : Name_Id;
8419 Expr : Node_Id;
8420 Val : Uint;
8422 begin
8423 -- Ignore all Restrictions pragmas in CodePeer mode
8425 if CodePeer_Mode then
8426 return;
8427 end if;
8429 Check_Ada_83_Warning;
8430 Check_At_Least_N_Arguments (1);
8431 Check_Valid_Configuration_Pragma;
8433 Arg := Arg1;
8434 while Present (Arg) loop
8435 Id := Chars (Arg);
8436 Expr := Get_Pragma_Arg (Arg);
8438 -- Case of no restriction identifier present
8440 if Id = No_Name then
8441 if Nkind (Expr) /= N_Identifier then
8442 Error_Pragma_Arg
8443 ("invalid form for restriction", Arg);
8444 end if;
8446 R_Id :=
8447 Get_Restriction_Id
8448 (Process_Restriction_Synonyms (Expr));
8450 if R_Id not in All_Boolean_Restrictions then
8451 Error_Msg_Name_1 := Pname;
8452 Error_Msg_N
8453 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
8455 -- Check for possible misspelling
8457 for J in Restriction_Id loop
8458 declare
8459 Rnm : constant String := Restriction_Id'Image (J);
8461 begin
8462 Name_Buffer (1 .. Rnm'Length) := Rnm;
8463 Name_Len := Rnm'Length;
8464 Set_Casing (All_Lower_Case);
8466 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
8467 Set_Casing
8468 (Identifier_Casing (Current_Source_File));
8469 Error_Msg_String (1 .. Rnm'Length) :=
8470 Name_Buffer (1 .. Name_Len);
8471 Error_Msg_Strlen := Rnm'Length;
8472 Error_Msg_N -- CODEFIX
8473 ("\possible misspelling of ""~""",
8474 Get_Pragma_Arg (Arg));
8475 exit;
8476 end if;
8477 end;
8478 end loop;
8480 raise Pragma_Exit;
8481 end if;
8483 if Implementation_Restriction (R_Id) then
8484 Check_Restriction (No_Implementation_Restrictions, Arg);
8485 end if;
8487 -- Special processing for No_Elaboration_Code restriction
8489 if R_Id = No_Elaboration_Code then
8491 -- Restriction is only recognized within a configuration
8492 -- pragma file, or within a unit of the main extended
8493 -- program. Note: the test for Main_Unit is needed to
8494 -- properly include the case of configuration pragma files.
8496 if not (Current_Sem_Unit = Main_Unit
8497 or else In_Extended_Main_Source_Unit (N))
8498 then
8499 return;
8501 -- Don't allow in a subunit unless already specified in
8502 -- body or spec.
8504 elsif Nkind (Parent (N)) = N_Compilation_Unit
8505 and then Nkind (Unit (Parent (N))) = N_Subunit
8506 and then not Restriction_Active (No_Elaboration_Code)
8507 then
8508 Error_Msg_N
8509 ("invalid specification of ""No_Elaboration_Code""",
8511 Error_Msg_N
8512 ("\restriction cannot be specified in a subunit", N);
8513 Error_Msg_N
8514 ("\unless also specified in body or spec", N);
8515 return;
8517 -- If we accept a No_Elaboration_Code restriction, then it
8518 -- needs to be added to the configuration restriction set so
8519 -- that we get proper application to other units in the main
8520 -- extended source as required.
8522 else
8523 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
8524 end if;
8525 end if;
8527 -- If this is a warning, then set the warning unless we already
8528 -- have a real restriction active (we never want a warning to
8529 -- override a real restriction).
8531 if Warn then
8532 if not Restriction_Active (R_Id) then
8533 Set_Restriction (R_Id, N);
8534 Restriction_Warnings (R_Id) := True;
8535 end if;
8537 -- If real restriction case, then set it and make sure that the
8538 -- restriction warning flag is off, since a real restriction
8539 -- always overrides a warning.
8541 else
8542 Set_Restriction (R_Id, N);
8543 Restriction_Warnings (R_Id) := False;
8544 end if;
8546 -- Check for obsolescent restrictions in Ada 2005 mode
8548 if not Warn
8549 and then Ada_Version >= Ada_2005
8550 and then (R_Id = No_Asynchronous_Control
8551 or else
8552 R_Id = No_Unchecked_Deallocation
8553 or else
8554 R_Id = No_Unchecked_Conversion)
8555 then
8556 Check_Restriction (No_Obsolescent_Features, N);
8557 end if;
8559 -- A very special case that must be processed here: pragma
8560 -- Restrictions (No_Exceptions) turns off all run-time
8561 -- checking. This is a bit dubious in terms of the formal
8562 -- language definition, but it is what is intended by RM
8563 -- H.4(12). Restriction_Warnings never affects generated code
8564 -- so this is done only in the real restriction case.
8566 -- Atomic_Synchronization is not a real check, so it is not
8567 -- affected by this processing).
8569 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
8570 -- run-time checks in CodePeer and GNATprove modes: we want to
8571 -- generate checks for analysis purposes, as set respectively
8572 -- by -gnatC and -gnatd.F
8574 if not Warn
8575 and then not (CodePeer_Mode or GNATprove_Mode)
8576 and then R_Id = No_Exceptions
8577 then
8578 for J in Scope_Suppress.Suppress'Range loop
8579 if J /= Atomic_Synchronization then
8580 Scope_Suppress.Suppress (J) := True;
8581 end if;
8582 end loop;
8583 end if;
8585 -- Case of No_Dependence => unit-name. Note that the parser
8586 -- already made the necessary entry in the No_Dependence table.
8588 elsif Id = Name_No_Dependence then
8589 if not OK_No_Dependence_Unit_Name (Expr) then
8590 raise Pragma_Exit;
8591 end if;
8593 -- Case of No_Specification_Of_Aspect => aspect-identifier
8595 elsif Id = Name_No_Specification_Of_Aspect then
8596 declare
8597 A_Id : Aspect_Id;
8599 begin
8600 if Nkind (Expr) /= N_Identifier then
8601 A_Id := No_Aspect;
8602 else
8603 A_Id := Get_Aspect_Id (Chars (Expr));
8604 end if;
8606 if A_Id = No_Aspect then
8607 Error_Pragma_Arg ("invalid restriction name", Arg);
8608 else
8609 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
8610 end if;
8611 end;
8613 -- Case of No_Use_Of_Attribute => attribute-identifier
8615 elsif Id = Name_No_Use_Of_Attribute then
8616 if Nkind (Expr) /= N_Identifier
8617 or else not Is_Attribute_Name (Chars (Expr))
8618 then
8619 Error_Msg_N ("unknown attribute name??", Expr);
8621 else
8622 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
8623 end if;
8625 -- Case of No_Use_Of_Entity => fully-qualified-name
8627 elsif Id = Name_No_Use_Of_Entity then
8629 -- Restriction is only recognized within a configuration
8630 -- pragma file, or within a unit of the main extended
8631 -- program. Note: the test for Main_Unit is needed to
8632 -- properly include the case of configuration pragma files.
8634 if Current_Sem_Unit = Main_Unit
8635 or else In_Extended_Main_Source_Unit (N)
8636 then
8637 if not OK_No_Dependence_Unit_Name (Expr) then
8638 Error_Msg_N ("wrong form for entity name", Expr);
8639 else
8640 Set_Restriction_No_Use_Of_Entity
8641 (Expr, Warn, No_Profile);
8642 end if;
8643 end if;
8645 -- Case of No_Use_Of_Pragma => pragma-identifier
8647 elsif Id = Name_No_Use_Of_Pragma then
8648 if Nkind (Expr) /= N_Identifier
8649 or else not Is_Pragma_Name (Chars (Expr))
8650 then
8651 Error_Msg_N ("unknown pragma name??", Expr);
8652 else
8653 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
8654 end if;
8656 -- All other cases of restriction identifier present
8658 else
8659 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
8660 Analyze_And_Resolve (Expr, Any_Integer);
8662 if R_Id not in All_Parameter_Restrictions then
8663 Error_Pragma_Arg
8664 ("invalid restriction parameter identifier", Arg);
8666 elsif not Is_OK_Static_Expression (Expr) then
8667 Flag_Non_Static_Expr
8668 ("value must be static expression!", Expr);
8669 raise Pragma_Exit;
8671 elsif not Is_Integer_Type (Etype (Expr))
8672 or else Expr_Value (Expr) < 0
8673 then
8674 Error_Pragma_Arg
8675 ("value must be non-negative integer", Arg);
8676 end if;
8678 -- Restriction pragma is active
8680 Val := Expr_Value (Expr);
8682 if not UI_Is_In_Int_Range (Val) then
8683 Error_Pragma_Arg
8684 ("pragma ignored, value too large??", Arg);
8685 end if;
8687 -- Warning case. If the real restriction is active, then we
8688 -- ignore the request, since warning never overrides a real
8689 -- restriction. Otherwise we set the proper warning. Note that
8690 -- this circuit sets the warning again if it is already set,
8691 -- which is what we want, since the constant may have changed.
8693 if Warn then
8694 if not Restriction_Active (R_Id) then
8695 Set_Restriction
8696 (R_Id, N, Integer (UI_To_Int (Val)));
8697 Restriction_Warnings (R_Id) := True;
8698 end if;
8700 -- Real restriction case, set restriction and make sure warning
8701 -- flag is off since real restriction always overrides warning.
8703 else
8704 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
8705 Restriction_Warnings (R_Id) := False;
8706 end if;
8707 end if;
8709 Next (Arg);
8710 end loop;
8711 end Process_Restrictions_Or_Restriction_Warnings;
8713 ---------------------------------
8714 -- Process_Suppress_Unsuppress --
8715 ---------------------------------
8717 -- Note: this procedure makes entries in the check suppress data
8718 -- structures managed by Sem. See spec of package Sem for full
8719 -- details on how we handle recording of check suppression.
8721 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
8722 C : Check_Id;
8723 E_Id : Node_Id;
8724 E : Entity_Id;
8726 In_Package_Spec : constant Boolean :=
8727 Is_Package_Or_Generic_Package (Current_Scope)
8728 and then not In_Package_Body (Current_Scope);
8730 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
8731 -- Used to suppress a single check on the given entity
8733 --------------------------------
8734 -- Suppress_Unsuppress_Echeck --
8735 --------------------------------
8737 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
8738 begin
8739 -- Check for error of trying to set atomic synchronization for
8740 -- a non-atomic variable.
8742 if C = Atomic_Synchronization
8743 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
8744 then
8745 Error_Msg_N
8746 ("pragma & requires atomic type or variable",
8747 Pragma_Identifier (Original_Node (N)));
8748 end if;
8750 Set_Checks_May_Be_Suppressed (E);
8752 if In_Package_Spec then
8753 Push_Global_Suppress_Stack_Entry
8754 (Entity => E,
8755 Check => C,
8756 Suppress => Suppress_Case);
8757 else
8758 Push_Local_Suppress_Stack_Entry
8759 (Entity => E,
8760 Check => C,
8761 Suppress => Suppress_Case);
8762 end if;
8764 -- If this is a first subtype, and the base type is distinct,
8765 -- then also set the suppress flags on the base type.
8767 if Is_First_Subtype (E) and then Etype (E) /= E then
8768 Suppress_Unsuppress_Echeck (Etype (E), C);
8769 end if;
8770 end Suppress_Unsuppress_Echeck;
8772 -- Start of processing for Process_Suppress_Unsuppress
8774 begin
8775 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
8776 -- on user code: we want to generate checks for analysis purposes, as
8777 -- set respectively by -gnatC and -gnatd.F
8779 if (CodePeer_Mode or GNATprove_Mode)
8780 and then Comes_From_Source (N)
8781 then
8782 return;
8783 end if;
8785 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
8786 -- declarative part or a package spec (RM 11.5(5)).
8788 if not Is_Configuration_Pragma then
8789 Check_Is_In_Decl_Part_Or_Package_Spec;
8790 end if;
8792 Check_At_Least_N_Arguments (1);
8793 Check_At_Most_N_Arguments (2);
8794 Check_No_Identifier (Arg1);
8795 Check_Arg_Is_Identifier (Arg1);
8797 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
8799 if C = No_Check_Id then
8800 Error_Pragma_Arg
8801 ("argument of pragma% is not valid check name", Arg1);
8802 end if;
8804 -- Warn that suppress of Elaboration_Check has no effect in SPARK
8806 if C = Elaboration_Check and then SPARK_Mode = On then
8807 Error_Pragma_Arg
8808 ("Suppress of Elaboration_Check ignored in SPARK??",
8809 "\elaboration checking rules are statically enforced "
8810 & "(SPARK RM 7.7)", Arg1);
8811 end if;
8813 -- One-argument case
8815 if Arg_Count = 1 then
8817 -- Make an entry in the local scope suppress table. This is the
8818 -- table that directly shows the current value of the scope
8819 -- suppress check for any check id value.
8821 if C = All_Checks then
8823 -- For All_Checks, we set all specific predefined checks with
8824 -- the exception of Elaboration_Check, which is handled
8825 -- specially because of not wanting All_Checks to have the
8826 -- effect of deactivating static elaboration order processing.
8827 -- Atomic_Synchronization is also not affected, since this is
8828 -- not a real check.
8830 for J in Scope_Suppress.Suppress'Range loop
8831 if J /= Elaboration_Check
8832 and then
8833 J /= Atomic_Synchronization
8834 then
8835 Scope_Suppress.Suppress (J) := Suppress_Case;
8836 end if;
8837 end loop;
8839 -- If not All_Checks, and predefined check, then set appropriate
8840 -- scope entry. Note that we will set Elaboration_Check if this
8841 -- is explicitly specified. Atomic_Synchronization is allowed
8842 -- only if internally generated and entity is atomic.
8844 elsif C in Predefined_Check_Id
8845 and then (not Comes_From_Source (N)
8846 or else C /= Atomic_Synchronization)
8847 then
8848 Scope_Suppress.Suppress (C) := Suppress_Case;
8849 end if;
8851 -- Also make an entry in the Local_Entity_Suppress table
8853 Push_Local_Suppress_Stack_Entry
8854 (Entity => Empty,
8855 Check => C,
8856 Suppress => Suppress_Case);
8858 -- Case of two arguments present, where the check is suppressed for
8859 -- a specified entity (given as the second argument of the pragma)
8861 else
8862 -- This is obsolescent in Ada 2005 mode
8864 if Ada_Version >= Ada_2005 then
8865 Check_Restriction (No_Obsolescent_Features, Arg2);
8866 end if;
8868 Check_Optional_Identifier (Arg2, Name_On);
8869 E_Id := Get_Pragma_Arg (Arg2);
8870 Analyze (E_Id);
8872 if not Is_Entity_Name (E_Id) then
8873 Error_Pragma_Arg
8874 ("second argument of pragma% must be entity name", Arg2);
8875 end if;
8877 E := Entity (E_Id);
8879 if E = Any_Id then
8880 return;
8881 end if;
8883 -- Enforce RM 11.5(7) which requires that for a pragma that
8884 -- appears within a package spec, the named entity must be
8885 -- within the package spec. We allow the package name itself
8886 -- to be mentioned since that makes sense, although it is not
8887 -- strictly allowed by 11.5(7).
8889 if In_Package_Spec
8890 and then E /= Current_Scope
8891 and then Scope (E) /= Current_Scope
8892 then
8893 Error_Pragma_Arg
8894 ("entity in pragma% is not in package spec (RM 11.5(7))",
8895 Arg2);
8896 end if;
8898 -- Loop through homonyms. As noted below, in the case of a package
8899 -- spec, only homonyms within the package spec are considered.
8901 loop
8902 Suppress_Unsuppress_Echeck (E, C);
8904 if Is_Generic_Instance (E)
8905 and then Is_Subprogram (E)
8906 and then Present (Alias (E))
8907 then
8908 Suppress_Unsuppress_Echeck (Alias (E), C);
8909 end if;
8911 -- Move to next homonym if not aspect spec case
8913 exit when From_Aspect_Specification (N);
8914 E := Homonym (E);
8915 exit when No (E);
8917 -- If we are within a package specification, the pragma only
8918 -- applies to homonyms in the same scope.
8920 exit when In_Package_Spec
8921 and then Scope (E) /= Current_Scope;
8922 end loop;
8923 end if;
8924 end Process_Suppress_Unsuppress;
8926 -------------------------------
8927 -- Record_Independence_Check --
8928 -------------------------------
8930 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is
8931 begin
8932 -- For GCC back ends the validation is done a priori
8934 if VM_Target = No_VM and then not AAMP_On_Target then
8935 return;
8936 end if;
8938 Independence_Checks.Append ((N, E));
8939 end Record_Independence_Check;
8941 ------------------
8942 -- Set_Exported --
8943 ------------------
8945 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
8946 begin
8947 if Is_Imported (E) then
8948 Error_Pragma_Arg
8949 ("cannot export entity& that was previously imported", Arg);
8951 elsif Present (Address_Clause (E))
8952 and then not Relaxed_RM_Semantics
8953 then
8954 Error_Pragma_Arg
8955 ("cannot export entity& that has an address clause", Arg);
8956 end if;
8958 Set_Is_Exported (E);
8960 -- Generate a reference for entity explicitly, because the
8961 -- identifier may be overloaded and name resolution will not
8962 -- generate one.
8964 Generate_Reference (E, Arg);
8966 -- Deal with exporting non-library level entity
8968 if not Is_Library_Level_Entity (E) then
8970 -- Not allowed at all for subprograms
8972 if Is_Subprogram (E) then
8973 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
8975 -- Otherwise set public and statically allocated
8977 else
8978 Set_Is_Public (E);
8979 Set_Is_Statically_Allocated (E);
8981 -- Warn if the corresponding W flag is set
8983 if Warn_On_Export_Import
8985 -- Only do this for something that was in the source. Not
8986 -- clear if this can be False now (there used for sure to be
8987 -- cases on some systems where it was False), but anyway the
8988 -- test is harmless if not needed, so it is retained.
8990 and then Comes_From_Source (Arg)
8991 then
8992 Error_Msg_NE
8993 ("?x?& has been made static as a result of Export",
8994 Arg, E);
8995 Error_Msg_N
8996 ("\?x?this usage is non-standard and non-portable",
8997 Arg);
8998 end if;
8999 end if;
9000 end if;
9002 if Warn_On_Export_Import and then Is_Type (E) then
9003 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
9004 end if;
9006 if Warn_On_Export_Import and Inside_A_Generic then
9007 Error_Msg_NE
9008 ("all instances of& will have the same external name?x?",
9009 Arg, E);
9010 end if;
9011 end Set_Exported;
9013 ----------------------------------------------
9014 -- Set_Extended_Import_Export_External_Name --
9015 ----------------------------------------------
9017 procedure Set_Extended_Import_Export_External_Name
9018 (Internal_Ent : Entity_Id;
9019 Arg_External : Node_Id)
9021 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
9022 New_Name : Node_Id;
9024 begin
9025 if No (Arg_External) then
9026 return;
9027 end if;
9029 Check_Arg_Is_External_Name (Arg_External);
9031 if Nkind (Arg_External) = N_String_Literal then
9032 if String_Length (Strval (Arg_External)) = 0 then
9033 return;
9034 else
9035 New_Name := Adjust_External_Name_Case (Arg_External);
9036 end if;
9038 elsif Nkind (Arg_External) = N_Identifier then
9039 New_Name := Get_Default_External_Name (Arg_External);
9041 -- Check_Arg_Is_External_Name should let through only identifiers and
9042 -- string literals or static string expressions (which are folded to
9043 -- string literals).
9045 else
9046 raise Program_Error;
9047 end if;
9049 -- If we already have an external name set (by a prior normal Import
9050 -- or Export pragma), then the external names must match
9052 if Present (Interface_Name (Internal_Ent)) then
9054 -- Ignore mismatching names in CodePeer mode, to support some
9055 -- old compilers which would export the same procedure under
9056 -- different names, e.g:
9057 -- procedure P;
9058 -- pragma Export_Procedure (P, "a");
9059 -- pragma Export_Procedure (P, "b");
9061 if CodePeer_Mode then
9062 return;
9063 end if;
9065 Check_Matching_Internal_Names : declare
9066 S1 : constant String_Id := Strval (Old_Name);
9067 S2 : constant String_Id := Strval (New_Name);
9069 procedure Mismatch;
9070 pragma No_Return (Mismatch);
9071 -- Called if names do not match
9073 --------------
9074 -- Mismatch --
9075 --------------
9077 procedure Mismatch is
9078 begin
9079 Error_Msg_Sloc := Sloc (Old_Name);
9080 Error_Pragma_Arg
9081 ("external name does not match that given #",
9082 Arg_External);
9083 end Mismatch;
9085 -- Start of processing for Check_Matching_Internal_Names
9087 begin
9088 if String_Length (S1) /= String_Length (S2) then
9089 Mismatch;
9091 else
9092 for J in 1 .. String_Length (S1) loop
9093 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
9094 Mismatch;
9095 end if;
9096 end loop;
9097 end if;
9098 end Check_Matching_Internal_Names;
9100 -- Otherwise set the given name
9102 else
9103 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
9104 Check_Duplicated_Export_Name (New_Name);
9105 end if;
9106 end Set_Extended_Import_Export_External_Name;
9108 ------------------
9109 -- Set_Imported --
9110 ------------------
9112 procedure Set_Imported (E : Entity_Id) is
9113 begin
9114 -- Error message if already imported or exported
9116 if Is_Exported (E) or else Is_Imported (E) then
9118 -- Error if being set Exported twice
9120 if Is_Exported (E) then
9121 Error_Msg_NE ("entity& was previously exported", N, E);
9123 -- Ignore error in CodePeer mode where we treat all imported
9124 -- subprograms as unknown.
9126 elsif CodePeer_Mode then
9127 goto OK;
9129 -- OK if Import/Interface case
9131 elsif Import_Interface_Present (N) then
9132 goto OK;
9134 -- Error if being set Imported twice
9136 else
9137 Error_Msg_NE ("entity& was previously imported", N, E);
9138 end if;
9140 Error_Msg_Name_1 := Pname;
9141 Error_Msg_N
9142 ("\(pragma% applies to all previous entities)", N);
9144 Error_Msg_Sloc := Sloc (E);
9145 Error_Msg_NE ("\import not allowed for& declared#", N, E);
9147 -- Here if not previously imported or exported, OK to import
9149 else
9150 Set_Is_Imported (E);
9152 -- For subprogram, set Import_Pragma field
9154 if Is_Subprogram (E) then
9155 Set_Import_Pragma (E, N);
9156 end if;
9158 -- If the entity is an object that is not at the library level,
9159 -- then it is statically allocated. We do not worry about objects
9160 -- with address clauses in this context since they are not really
9161 -- imported in the linker sense.
9163 if Is_Object (E)
9164 and then not Is_Library_Level_Entity (E)
9165 and then No (Address_Clause (E))
9166 then
9167 Set_Is_Statically_Allocated (E);
9168 end if;
9169 end if;
9171 <<OK>> null;
9172 end Set_Imported;
9174 -------------------------
9175 -- Set_Mechanism_Value --
9176 -------------------------
9178 -- Note: the mechanism name has not been analyzed (and cannot indeed be
9179 -- analyzed, since it is semantic nonsense), so we get it in the exact
9180 -- form created by the parser.
9182 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
9183 procedure Bad_Mechanism;
9184 pragma No_Return (Bad_Mechanism);
9185 -- Signal bad mechanism name
9187 -------------------------
9188 -- Bad_Mechanism_Value --
9189 -------------------------
9191 procedure Bad_Mechanism is
9192 begin
9193 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
9194 end Bad_Mechanism;
9196 -- Start of processing for Set_Mechanism_Value
9198 begin
9199 if Mechanism (Ent) /= Default_Mechanism then
9200 Error_Msg_NE
9201 ("mechanism for & has already been set", Mech_Name, Ent);
9202 end if;
9204 -- MECHANISM_NAME ::= value | reference
9206 if Nkind (Mech_Name) = N_Identifier then
9207 if Chars (Mech_Name) = Name_Value then
9208 Set_Mechanism (Ent, By_Copy);
9209 return;
9211 elsif Chars (Mech_Name) = Name_Reference then
9212 Set_Mechanism (Ent, By_Reference);
9213 return;
9215 elsif Chars (Mech_Name) = Name_Copy then
9216 Error_Pragma_Arg
9217 ("bad mechanism name, Value assumed", Mech_Name);
9219 else
9220 Bad_Mechanism;
9221 end if;
9223 else
9224 Bad_Mechanism;
9225 end if;
9226 end Set_Mechanism_Value;
9228 --------------------------
9229 -- Set_Rational_Profile --
9230 --------------------------
9232 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
9233 -- and extension to the semantics of renaming declarations.
9235 procedure Set_Rational_Profile is
9236 begin
9237 Implicit_Packing := True;
9238 Overriding_Renamings := True;
9239 Use_VADS_Size := True;
9240 end Set_Rational_Profile;
9242 ---------------------------
9243 -- Set_Ravenscar_Profile --
9244 ---------------------------
9246 -- The tasks to be done here are
9248 -- Set required policies
9250 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9251 -- pragma Locking_Policy (Ceiling_Locking)
9253 -- Set Detect_Blocking mode
9255 -- Set required restrictions (see System.Rident for detailed list)
9257 -- Set the No_Dependence rules
9258 -- No_Dependence => Ada.Asynchronous_Task_Control
9259 -- No_Dependence => Ada.Calendar
9260 -- No_Dependence => Ada.Execution_Time.Group_Budget
9261 -- No_Dependence => Ada.Execution_Time.Timers
9262 -- No_Dependence => Ada.Task_Attributes
9263 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9265 procedure Set_Ravenscar_Profile (N : Node_Id) is
9266 Prefix_Entity : Entity_Id;
9267 Selector_Entity : Entity_Id;
9268 Prefix_Node : Node_Id;
9269 Node : Node_Id;
9271 begin
9272 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9274 if Task_Dispatching_Policy /= ' '
9275 and then Task_Dispatching_Policy /= 'F'
9276 then
9277 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9278 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
9280 -- Set the FIFO_Within_Priorities policy, but always preserve
9281 -- System_Location since we like the error message with the run time
9282 -- name.
9284 else
9285 Task_Dispatching_Policy := 'F';
9287 if Task_Dispatching_Policy_Sloc /= System_Location then
9288 Task_Dispatching_Policy_Sloc := Loc;
9289 end if;
9290 end if;
9292 -- pragma Locking_Policy (Ceiling_Locking)
9294 if Locking_Policy /= ' '
9295 and then Locking_Policy /= 'C'
9296 then
9297 Error_Msg_Sloc := Locking_Policy_Sloc;
9298 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
9300 -- Set the Ceiling_Locking policy, but preserve System_Location since
9301 -- we like the error message with the run time name.
9303 else
9304 Locking_Policy := 'C';
9306 if Locking_Policy_Sloc /= System_Location then
9307 Locking_Policy_Sloc := Loc;
9308 end if;
9309 end if;
9311 -- pragma Detect_Blocking
9313 Detect_Blocking := True;
9315 -- Set the corresponding restrictions
9317 Set_Profile_Restrictions
9318 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
9320 -- Set the No_Dependence restrictions
9322 -- The following No_Dependence restrictions:
9323 -- No_Dependence => Ada.Asynchronous_Task_Control
9324 -- No_Dependence => Ada.Calendar
9325 -- No_Dependence => Ada.Task_Attributes
9326 -- are already set by previous call to Set_Profile_Restrictions.
9328 -- Set the following restrictions which were added to Ada 2005:
9329 -- No_Dependence => Ada.Execution_Time.Group_Budget
9330 -- No_Dependence => Ada.Execution_Time.Timers
9332 if Ada_Version >= Ada_2005 then
9333 Name_Buffer (1 .. 3) := "ada";
9334 Name_Len := 3;
9336 Prefix_Entity := Make_Identifier (Loc, Name_Find);
9338 Name_Buffer (1 .. 14) := "execution_time";
9339 Name_Len := 14;
9341 Selector_Entity := Make_Identifier (Loc, Name_Find);
9343 Prefix_Node :=
9344 Make_Selected_Component
9345 (Sloc => Loc,
9346 Prefix => Prefix_Entity,
9347 Selector_Name => Selector_Entity);
9349 Name_Buffer (1 .. 13) := "group_budgets";
9350 Name_Len := 13;
9352 Selector_Entity := Make_Identifier (Loc, Name_Find);
9354 Node :=
9355 Make_Selected_Component
9356 (Sloc => Loc,
9357 Prefix => Prefix_Node,
9358 Selector_Name => Selector_Entity);
9360 Set_Restriction_No_Dependence
9361 (Unit => Node,
9362 Warn => Treat_Restrictions_As_Warnings,
9363 Profile => Ravenscar);
9365 Name_Buffer (1 .. 6) := "timers";
9366 Name_Len := 6;
9368 Selector_Entity := Make_Identifier (Loc, Name_Find);
9370 Node :=
9371 Make_Selected_Component
9372 (Sloc => Loc,
9373 Prefix => Prefix_Node,
9374 Selector_Name => Selector_Entity);
9376 Set_Restriction_No_Dependence
9377 (Unit => Node,
9378 Warn => Treat_Restrictions_As_Warnings,
9379 Profile => Ravenscar);
9380 end if;
9382 -- Set the following restrictions which was added to Ada 2012 (see
9383 -- AI-0171):
9384 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9386 if Ada_Version >= Ada_2012 then
9387 Name_Buffer (1 .. 6) := "system";
9388 Name_Len := 6;
9390 Prefix_Entity := Make_Identifier (Loc, Name_Find);
9392 Name_Buffer (1 .. 15) := "multiprocessors";
9393 Name_Len := 15;
9395 Selector_Entity := Make_Identifier (Loc, Name_Find);
9397 Prefix_Node :=
9398 Make_Selected_Component
9399 (Sloc => Loc,
9400 Prefix => Prefix_Entity,
9401 Selector_Name => Selector_Entity);
9403 Name_Buffer (1 .. 19) := "dispatching_domains";
9404 Name_Len := 19;
9406 Selector_Entity := Make_Identifier (Loc, Name_Find);
9408 Node :=
9409 Make_Selected_Component
9410 (Sloc => Loc,
9411 Prefix => Prefix_Node,
9412 Selector_Name => Selector_Entity);
9414 Set_Restriction_No_Dependence
9415 (Unit => Node,
9416 Warn => Treat_Restrictions_As_Warnings,
9417 Profile => Ravenscar);
9418 end if;
9419 end Set_Ravenscar_Profile;
9421 -- Start of processing for Analyze_Pragma
9423 begin
9424 -- The following code is a defense against recursion. Not clear that
9425 -- this can happen legitimately, but perhaps some error situations
9426 -- can cause it, and we did see this recursion during testing.
9428 if Analyzed (N) then
9429 return;
9430 else
9431 Set_Analyzed (N, True);
9432 end if;
9434 -- Deal with unrecognized pragma
9436 Pname := Pragma_Name (N);
9438 if not Is_Pragma_Name (Pname) then
9439 if Warn_On_Unrecognized_Pragma then
9440 Error_Msg_Name_1 := Pname;
9441 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
9443 for PN in First_Pragma_Name .. Last_Pragma_Name loop
9444 if Is_Bad_Spelling_Of (Pname, PN) then
9445 Error_Msg_Name_1 := PN;
9446 Error_Msg_N -- CODEFIX
9447 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
9448 exit;
9449 end if;
9450 end loop;
9451 end if;
9453 return;
9454 end if;
9456 -- Ignore pragma if Ignore_Pragma applies
9458 if Get_Name_Table_Boolean3 (Pname) then
9459 return;
9460 end if;
9462 -- Here to start processing for recognized pragma
9464 Prag_Id := Get_Pragma_Id (Pname);
9465 Pname := Original_Aspect_Pragma_Name (N);
9467 -- Capture setting of Opt.Uneval_Old
9469 case Opt.Uneval_Old is
9470 when 'A' =>
9471 Set_Uneval_Old_Accept (N);
9472 when 'E' =>
9473 null;
9474 when 'W' =>
9475 Set_Uneval_Old_Warn (N);
9476 when others =>
9477 raise Program_Error;
9478 end case;
9480 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
9481 -- is already set, indicating that we have already checked the policy
9482 -- at the right point. This happens for example in the case of a pragma
9483 -- that is derived from an Aspect.
9485 if Is_Ignored (N) or else Is_Checked (N) then
9486 null;
9488 -- For a pragma that is a rewriting of another pragma, copy the
9489 -- Is_Checked/Is_Ignored status from the rewritten pragma.
9491 elsif Is_Rewrite_Substitution (N)
9492 and then Nkind (Original_Node (N)) = N_Pragma
9493 and then Original_Node (N) /= N
9494 then
9495 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
9496 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
9498 -- Otherwise query the applicable policy at this point
9500 else
9501 Check_Applicable_Policy (N);
9503 -- If pragma is disabled, rewrite as NULL and skip analysis
9505 if Is_Disabled (N) then
9506 Rewrite (N, Make_Null_Statement (Loc));
9507 Analyze (N);
9508 raise Pragma_Exit;
9509 end if;
9510 end if;
9512 -- Preset arguments
9514 Arg_Count := 0;
9515 Arg1 := Empty;
9516 Arg2 := Empty;
9517 Arg3 := Empty;
9518 Arg4 := Empty;
9520 if Present (Pragma_Argument_Associations (N)) then
9521 Arg_Count := List_Length (Pragma_Argument_Associations (N));
9522 Arg1 := First (Pragma_Argument_Associations (N));
9524 if Present (Arg1) then
9525 Arg2 := Next (Arg1);
9527 if Present (Arg2) then
9528 Arg3 := Next (Arg2);
9530 if Present (Arg3) then
9531 Arg4 := Next (Arg3);
9532 end if;
9533 end if;
9534 end if;
9535 end if;
9537 Check_Restriction_No_Use_Of_Pragma (N);
9539 -- An enumeration type defines the pragmas that are supported by the
9540 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
9541 -- into the corresponding enumeration value for the following case.
9543 case Prag_Id is
9545 -----------------
9546 -- Abort_Defer --
9547 -----------------
9549 -- pragma Abort_Defer;
9551 when Pragma_Abort_Defer =>
9552 GNAT_Pragma;
9553 Check_Arg_Count (0);
9555 -- The only required semantic processing is to check the
9556 -- placement. This pragma must appear at the start of the
9557 -- statement sequence of a handled sequence of statements.
9559 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
9560 or else N /= First (Statements (Parent (N)))
9561 then
9562 Pragma_Misplaced;
9563 end if;
9565 --------------------
9566 -- Abstract_State --
9567 --------------------
9569 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
9571 -- ABSTRACT_STATE_LIST ::=
9572 -- null
9573 -- | STATE_NAME_WITH_OPTIONS
9574 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS} )
9576 -- STATE_NAME_WITH_OPTIONS ::=
9577 -- STATE_NAME
9578 -- | (STATE_NAME with OPTION_LIST)
9580 -- OPTION_LIST ::= OPTION {, OPTION}
9582 -- OPTION ::=
9583 -- SIMPLE_OPTION
9584 -- | NAME_VALUE_OPTION
9586 -- SIMPLE_OPTION ::= Ghost
9588 -- NAME_VALUE_OPTION ::=
9589 -- Part_Of => ABSTRACT_STATE
9590 -- | External [=> EXTERNAL_PROPERTY_LIST]
9592 -- EXTERNAL_PROPERTY_LIST ::=
9593 -- EXTERNAL_PROPERTY
9594 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY} )
9596 -- EXTERNAL_PROPERTY ::=
9597 -- Async_Readers [=> boolean_EXPRESSION]
9598 -- | Async_Writers [=> boolean_EXPRESSION]
9599 -- | Effective_Reads [=> boolean_EXPRESSION]
9600 -- | Effective_Writes [=> boolean_EXPRESSION]
9601 -- others => boolean_EXPRESSION
9603 -- STATE_NAME ::= defining_identifier
9605 -- ABSTRACT_STATE ::= name
9607 -- Characteristics:
9609 -- * Analysis - The annotation is fully analyzed immediately upon
9610 -- elaboration as it cannot forward reference entities.
9612 -- * Expansion - None.
9614 -- * Template - The annotation utilizes the generic template of the
9615 -- related package declaration.
9617 -- * Globals - The annotation cannot reference global entities.
9619 -- * Instance - The annotation is instantiated automatically when
9620 -- the related generic package is instantiated.
9622 when Pragma_Abstract_State => Abstract_State : declare
9623 Missing_Parentheses : Boolean := False;
9624 -- Flag set when a state declaration with options is not properly
9625 -- parenthesized.
9627 -- Flags used to verify the consistency of states
9629 Non_Null_Seen : Boolean := False;
9630 Null_Seen : Boolean := False;
9632 procedure Analyze_Abstract_State
9633 (State : Node_Id;
9634 Pack_Id : Entity_Id);
9635 -- Verify the legality of a single state declaration. Create and
9636 -- decorate a state abstraction entity and introduce it into the
9637 -- visibility chain. Pack_Id denotes the entity or the related
9638 -- package where pragma Abstract_State appears.
9640 procedure Malformed_State_Error (State : Node_Id);
9641 -- Emit an error concerning the illegal declaration of abstract
9642 -- state State. This routine diagnoses syntax errors that lead to
9643 -- a different parse tree. The error is issued regardless of the
9644 -- SPARK mode in effect.
9646 ----------------------------
9647 -- Analyze_Abstract_State --
9648 ----------------------------
9650 procedure Analyze_Abstract_State
9651 (State : Node_Id;
9652 Pack_Id : Entity_Id)
9654 -- Flags used to verify the consistency of options
9656 AR_Seen : Boolean := False;
9657 AW_Seen : Boolean := False;
9658 ER_Seen : Boolean := False;
9659 EW_Seen : Boolean := False;
9660 External_Seen : Boolean := False;
9661 Others_Seen : Boolean := False;
9662 Part_Of_Seen : Boolean := False;
9664 -- Flags used to store the static value of all external states'
9665 -- expressions.
9667 AR_Val : Boolean := False;
9668 AW_Val : Boolean := False;
9669 ER_Val : Boolean := False;
9670 EW_Val : Boolean := False;
9672 State_Id : Entity_Id := Empty;
9673 -- The entity to be generated for the current state declaration
9675 procedure Analyze_External_Option (Opt : Node_Id);
9676 -- Verify the legality of option External
9678 procedure Analyze_External_Property
9679 (Prop : Node_Id;
9680 Expr : Node_Id := Empty);
9681 -- Verify the legailty of a single external property. Prop
9682 -- denotes the external property. Expr is the expression used
9683 -- to set the property.
9685 procedure Analyze_Part_Of_Option (Opt : Node_Id);
9686 -- Verify the legality of option Part_Of
9688 procedure Check_Duplicate_Option
9689 (Opt : Node_Id;
9690 Status : in out Boolean);
9691 -- Flag Status denotes whether a particular option has been
9692 -- seen while processing a state. This routine verifies that
9693 -- Opt is not a duplicate option and sets the flag Status
9694 -- (SPARK RM 7.1.4(1)).
9696 procedure Check_Duplicate_Property
9697 (Prop : Node_Id;
9698 Status : in out Boolean);
9699 -- Flag Status denotes whether a particular property has been
9700 -- seen while processing option External. This routine verifies
9701 -- that Prop is not a duplicate property and sets flag Status.
9702 -- Opt is not a duplicate property and sets the flag Status.
9703 -- (SPARK RM 7.1.4(2))
9705 procedure Create_Abstract_State
9706 (Nam : Name_Id;
9707 Decl : Node_Id;
9708 Loc : Source_Ptr;
9709 Is_Null : Boolean);
9710 -- Generate an abstract state entity with name Nam and enter it
9711 -- into visibility. Decl is the "declaration" of the state as
9712 -- it appears in pragma Abstract_State. Loc is the location of
9713 -- the related state "declaration". Flag Is_Null should be set
9714 -- when the associated Abstract_State pragma defines a null
9715 -- state.
9717 -----------------------------
9718 -- Analyze_External_Option --
9719 -----------------------------
9721 procedure Analyze_External_Option (Opt : Node_Id) is
9722 Errors : constant Nat := Serious_Errors_Detected;
9723 Prop : Node_Id;
9724 Props : Node_Id := Empty;
9726 begin
9727 Check_Duplicate_Option (Opt, External_Seen);
9729 if Nkind (Opt) = N_Component_Association then
9730 Props := Expression (Opt);
9731 end if;
9733 -- External state with properties
9735 if Present (Props) then
9737 -- Multiple properties appear as an aggregate
9739 if Nkind (Props) = N_Aggregate then
9741 -- Simple property form
9743 Prop := First (Expressions (Props));
9744 while Present (Prop) loop
9745 Analyze_External_Property (Prop);
9746 Next (Prop);
9747 end loop;
9749 -- Property with expression form
9751 Prop := First (Component_Associations (Props));
9752 while Present (Prop) loop
9753 Analyze_External_Property
9754 (Prop => First (Choices (Prop)),
9755 Expr => Expression (Prop));
9757 Next (Prop);
9758 end loop;
9760 -- Single property
9762 else
9763 Analyze_External_Property (Props);
9764 end if;
9766 -- An external state defined without any properties defaults
9767 -- all properties to True.
9769 else
9770 AR_Val := True;
9771 AW_Val := True;
9772 ER_Val := True;
9773 EW_Val := True;
9774 end if;
9776 -- Once all external properties have been processed, verify
9777 -- their mutual interaction. Do not perform the check when
9778 -- at least one of the properties is illegal as this will
9779 -- produce a bogus error.
9781 if Errors = Serious_Errors_Detected then
9782 Check_External_Properties
9783 (State, AR_Val, AW_Val, ER_Val, EW_Val);
9784 end if;
9785 end Analyze_External_Option;
9787 -------------------------------
9788 -- Analyze_External_Property --
9789 -------------------------------
9791 procedure Analyze_External_Property
9792 (Prop : Node_Id;
9793 Expr : Node_Id := Empty)
9795 Expr_Val : Boolean;
9797 begin
9798 -- Check the placement of "others" (if available)
9800 if Nkind (Prop) = N_Others_Choice then
9801 if Others_Seen then
9802 SPARK_Msg_N
9803 ("only one others choice allowed in option External",
9804 Prop);
9805 else
9806 Others_Seen := True;
9807 end if;
9809 elsif Others_Seen then
9810 SPARK_Msg_N
9811 ("others must be the last property in option External",
9812 Prop);
9814 -- The only remaining legal options are the four predefined
9815 -- external properties.
9817 elsif Nkind (Prop) = N_Identifier
9818 and then Nam_In (Chars (Prop), Name_Async_Readers,
9819 Name_Async_Writers,
9820 Name_Effective_Reads,
9821 Name_Effective_Writes)
9822 then
9823 null;
9825 -- Otherwise the construct is not a valid property
9827 else
9828 SPARK_Msg_N ("invalid external state property", Prop);
9829 return;
9830 end if;
9832 -- Ensure that the expression of the external state property
9833 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
9835 if Present (Expr) then
9836 Analyze_And_Resolve (Expr, Standard_Boolean);
9838 if Is_OK_Static_Expression (Expr) then
9839 Expr_Val := Is_True (Expr_Value (Expr));
9840 else
9841 SPARK_Msg_N
9842 ("expression of external state property must be "
9843 & "static", Expr);
9844 end if;
9846 -- The lack of expression defaults the property to True
9848 else
9849 Expr_Val := True;
9850 end if;
9852 -- Named properties
9854 if Nkind (Prop) = N_Identifier then
9855 if Chars (Prop) = Name_Async_Readers then
9856 Check_Duplicate_Property (Prop, AR_Seen);
9857 AR_Val := Expr_Val;
9859 elsif Chars (Prop) = Name_Async_Writers then
9860 Check_Duplicate_Property (Prop, AW_Seen);
9861 AW_Val := Expr_Val;
9863 elsif Chars (Prop) = Name_Effective_Reads then
9864 Check_Duplicate_Property (Prop, ER_Seen);
9865 ER_Val := Expr_Val;
9867 else
9868 Check_Duplicate_Property (Prop, EW_Seen);
9869 EW_Val := Expr_Val;
9870 end if;
9872 -- The handling of property "others" must take into account
9873 -- all other named properties that have been encountered so
9874 -- far. Only those that have not been seen are affected by
9875 -- "others".
9877 else
9878 if not AR_Seen then
9879 AR_Val := Expr_Val;
9880 end if;
9882 if not AW_Seen then
9883 AW_Val := Expr_Val;
9884 end if;
9886 if not ER_Seen then
9887 ER_Val := Expr_Val;
9888 end if;
9890 if not EW_Seen then
9891 EW_Val := Expr_Val;
9892 end if;
9893 end if;
9894 end Analyze_External_Property;
9896 ----------------------------
9897 -- Analyze_Part_Of_Option --
9898 ----------------------------
9900 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
9901 Encaps : constant Node_Id := Expression (Opt);
9902 Encaps_Id : Entity_Id;
9903 Legal : Boolean;
9905 begin
9906 Check_Duplicate_Option (Opt, Part_Of_Seen);
9908 Analyze_Part_Of
9909 (Item_Id => State_Id,
9910 State => Encaps,
9911 Indic => First (Choices (Opt)),
9912 Legal => Legal);
9914 -- The Part_Of indicator turns an abstract state into a
9915 -- constituent of the encapsulating state.
9917 if Legal then
9918 Encaps_Id := Entity (Encaps);
9920 Append_Elmt (State_Id, Part_Of_Constituents (Encaps_Id));
9921 Set_Encapsulating_State (State_Id, Encaps_Id);
9922 end if;
9923 end Analyze_Part_Of_Option;
9925 ----------------------------
9926 -- Check_Duplicate_Option --
9927 ----------------------------
9929 procedure Check_Duplicate_Option
9930 (Opt : Node_Id;
9931 Status : in out Boolean)
9933 begin
9934 if Status then
9935 SPARK_Msg_N ("duplicate state option", Opt);
9936 end if;
9938 Status := True;
9939 end Check_Duplicate_Option;
9941 ------------------------------
9942 -- Check_Duplicate_Property --
9943 ------------------------------
9945 procedure Check_Duplicate_Property
9946 (Prop : Node_Id;
9947 Status : in out Boolean)
9949 begin
9950 if Status then
9951 SPARK_Msg_N ("duplicate external property", Prop);
9952 end if;
9954 Status := True;
9955 end Check_Duplicate_Property;
9957 ---------------------------
9958 -- Create_Abstract_State --
9959 ---------------------------
9961 procedure Create_Abstract_State
9962 (Nam : Name_Id;
9963 Decl : Node_Id;
9964 Loc : Source_Ptr;
9965 Is_Null : Boolean)
9967 begin
9968 -- The abstract state may be semi-declared when the related
9969 -- package was withed through a limited with clause. In that
9970 -- case reuse the entity to fully declare the state.
9972 if Present (Decl) and then Present (Entity (Decl)) then
9973 State_Id := Entity (Decl);
9975 -- Otherwise the elaboration of pragma Abstract_State
9976 -- declares the state.
9978 else
9979 State_Id := Make_Defining_Identifier (Loc, Nam);
9981 if Present (Decl) then
9982 Set_Entity (Decl, State_Id);
9983 end if;
9984 end if;
9986 -- Null states never come from source
9988 Set_Comes_From_Source (State_Id, not Is_Null);
9989 Set_Parent (State_Id, State);
9990 Set_Ekind (State_Id, E_Abstract_State);
9991 Set_Etype (State_Id, Standard_Void_Type);
9992 Set_Encapsulating_State (State_Id, Empty);
9993 Set_Refinement_Constituents (State_Id, New_Elmt_List);
9994 Set_Part_Of_Constituents (State_Id, New_Elmt_List);
9996 -- An abstract state declared within a Ghost region becomes
9997 -- Ghost (SPARK RM 6.9(2)).
9999 if Ghost_Mode > None then
10000 Set_Is_Ghost_Entity (State_Id);
10001 end if;
10003 -- Establish a link between the state declaration and the
10004 -- abstract state entity. Note that a null state remains as
10005 -- N_Null and does not carry any linkages.
10007 if not Is_Null then
10008 if Present (Decl) then
10009 Set_Entity (Decl, State_Id);
10010 Set_Etype (Decl, Standard_Void_Type);
10011 end if;
10013 -- Every non-null state must be defined, nameable and
10014 -- resolvable.
10016 Push_Scope (Pack_Id);
10017 Generate_Definition (State_Id);
10018 Enter_Name (State_Id);
10019 Pop_Scope;
10020 end if;
10021 end Create_Abstract_State;
10023 -- Local variables
10025 Opt : Node_Id;
10026 Opt_Nam : Node_Id;
10028 -- Start of processing for Analyze_Abstract_State
10030 begin
10031 -- A package with a null abstract state is not allowed to
10032 -- declare additional states.
10034 if Null_Seen then
10035 SPARK_Msg_NE
10036 ("package & has null abstract state", State, Pack_Id);
10038 -- Null states appear as internally generated entities
10040 elsif Nkind (State) = N_Null then
10041 Create_Abstract_State
10042 (Nam => New_Internal_Name ('S'),
10043 Decl => Empty,
10044 Loc => Sloc (State),
10045 Is_Null => True);
10046 Null_Seen := True;
10048 -- Catch a case where a null state appears in a list of
10049 -- non-null states.
10051 if Non_Null_Seen then
10052 SPARK_Msg_NE
10053 ("package & has non-null abstract state",
10054 State, Pack_Id);
10055 end if;
10057 -- Simple state declaration
10059 elsif Nkind (State) = N_Identifier then
10060 Create_Abstract_State
10061 (Nam => Chars (State),
10062 Decl => State,
10063 Loc => Sloc (State),
10064 Is_Null => False);
10065 Non_Null_Seen := True;
10067 -- State declaration with various options. This construct
10068 -- appears as an extension aggregate in the tree.
10070 elsif Nkind (State) = N_Extension_Aggregate then
10071 if Nkind (Ancestor_Part (State)) = N_Identifier then
10072 Create_Abstract_State
10073 (Nam => Chars (Ancestor_Part (State)),
10074 Decl => Ancestor_Part (State),
10075 Loc => Sloc (Ancestor_Part (State)),
10076 Is_Null => False);
10077 Non_Null_Seen := True;
10078 else
10079 SPARK_Msg_N
10080 ("state name must be an identifier",
10081 Ancestor_Part (State));
10082 end if;
10084 -- Options External and Ghost appear as expressions
10086 Opt := First (Expressions (State));
10087 while Present (Opt) loop
10088 if Nkind (Opt) = N_Identifier then
10089 if Chars (Opt) = Name_External then
10090 Analyze_External_Option (Opt);
10092 elsif Chars (Opt) = Name_Ghost then
10093 if Present (State_Id) then
10094 Set_Is_Ghost_Entity (State_Id);
10095 end if;
10097 -- Option Part_Of without an encapsulating state is
10098 -- illegal. (SPARK RM 7.1.4(9)).
10100 elsif Chars (Opt) = Name_Part_Of then
10101 SPARK_Msg_N
10102 ("indicator Part_Of must denote an abstract "
10103 & "state", Opt);
10105 -- Do not emit an error message when a previous state
10106 -- declaration with options was not parenthesized as
10107 -- the option is actually another state declaration.
10109 -- with Abstract_State
10110 -- (State_1 with ..., -- missing parentheses
10111 -- (State_2 with ...),
10112 -- State_3) -- ok state declaration
10114 elsif Missing_Parentheses then
10115 null;
10117 -- Otherwise the option is not allowed. Note that it
10118 -- is not possible to distinguish between an option
10119 -- and a state declaration when a previous state with
10120 -- options not properly parentheses.
10122 -- with Abstract_State
10123 -- (State_1 with ..., -- missing parentheses
10124 -- State_2); -- could be an option
10126 else
10127 SPARK_Msg_N
10128 ("simple option not allowed in state declaration",
10129 Opt);
10130 end if;
10132 -- Catch a case where missing parentheses around a state
10133 -- declaration with options cause a subsequent state
10134 -- declaration with options to be treated as an option.
10136 -- with Abstract_State
10137 -- (State_1 with ..., -- missing parentheses
10138 -- (State_2 with ...))
10140 elsif Nkind (Opt) = N_Extension_Aggregate then
10141 Missing_Parentheses := True;
10142 SPARK_Msg_N
10143 ("state declaration must be parenthesized",
10144 Ancestor_Part (State));
10146 -- Otherwise the option is malformed
10148 else
10149 SPARK_Msg_N ("malformed option", Opt);
10150 end if;
10152 Next (Opt);
10153 end loop;
10155 -- Options External and Part_Of appear as component
10156 -- associations.
10158 Opt := First (Component_Associations (State));
10159 while Present (Opt) loop
10160 Opt_Nam := First (Choices (Opt));
10162 if Nkind (Opt_Nam) = N_Identifier then
10163 if Chars (Opt_Nam) = Name_External then
10164 Analyze_External_Option (Opt);
10166 elsif Chars (Opt_Nam) = Name_Part_Of then
10167 Analyze_Part_Of_Option (Opt);
10169 else
10170 SPARK_Msg_N ("invalid state option", Opt);
10171 end if;
10172 else
10173 SPARK_Msg_N ("invalid state option", Opt);
10174 end if;
10176 Next (Opt);
10177 end loop;
10179 -- Any other attempt to declare a state is illegal
10181 else
10182 Malformed_State_Error (State);
10183 return;
10184 end if;
10186 -- Guard against a junk state. In such cases no entity is
10187 -- generated and the subsequent checks cannot be applied.
10189 if Present (State_Id) then
10191 -- Verify whether the state does not introduce an illegal
10192 -- hidden state within a package subject to a null abstract
10193 -- state.
10195 Check_No_Hidden_State (State_Id);
10197 -- Check whether the lack of option Part_Of agrees with the
10198 -- placement of the abstract state with respect to the state
10199 -- space.
10201 if not Part_Of_Seen then
10202 Check_Missing_Part_Of (State_Id);
10203 end if;
10205 -- Associate the state with its related package
10207 if No (Abstract_States (Pack_Id)) then
10208 Set_Abstract_States (Pack_Id, New_Elmt_List);
10209 end if;
10211 Append_Elmt (State_Id, Abstract_States (Pack_Id));
10212 end if;
10213 end Analyze_Abstract_State;
10215 ---------------------------
10216 -- Malformed_State_Error --
10217 ---------------------------
10219 procedure Malformed_State_Error (State : Node_Id) is
10220 begin
10221 Error_Msg_N ("malformed abstract state declaration", State);
10223 -- An abstract state with a simple option is being declared
10224 -- with "=>" rather than the legal "with". The state appears
10225 -- as a component association.
10227 if Nkind (State) = N_Component_Association then
10228 Error_Msg_N ("\use WITH to specify simple option", State);
10229 end if;
10230 end Malformed_State_Error;
10232 -- Local variables
10234 Pack_Decl : Node_Id;
10235 Pack_Id : Entity_Id;
10236 State : Node_Id;
10237 States : Node_Id;
10239 -- Start of processing for Abstract_State
10241 begin
10242 GNAT_Pragma;
10243 Check_No_Identifiers;
10244 Check_Arg_Count (1);
10246 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
10248 -- Ensure the proper placement of the pragma. Abstract states must
10249 -- be associated with a package declaration.
10251 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
10252 N_Package_Declaration)
10253 then
10254 null;
10256 -- Otherwise the pragma is associated with an illegal construct
10258 else
10259 Pragma_Misplaced;
10260 return;
10261 end if;
10263 Pack_Id := Defining_Entity (Pack_Decl);
10265 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
10267 -- Mark the associated package as Ghost if it is subject to aspect
10268 -- or pragma Ghost as this affects the declaration of an abstract
10269 -- state.
10271 if Is_Subject_To_Ghost (Unit_Declaration_Node (Pack_Id)) then
10272 Set_Is_Ghost_Entity (Pack_Id);
10273 end if;
10275 States := Expression (Get_Argument (N, Pack_Id));
10277 -- Multiple non-null abstract states appear as an aggregate
10279 if Nkind (States) = N_Aggregate then
10280 State := First (Expressions (States));
10281 while Present (State) loop
10282 Analyze_Abstract_State (State, Pack_Id);
10283 Next (State);
10284 end loop;
10286 -- An abstract state with a simple option is being illegaly
10287 -- declared with "=>" rather than "with". In this case the
10288 -- state declaration appears as a component association.
10290 if Present (Component_Associations (States)) then
10291 State := First (Component_Associations (States));
10292 while Present (State) loop
10293 Malformed_State_Error (State);
10294 Next (State);
10295 end loop;
10296 end if;
10298 -- Various forms of a single abstract state. Note that these may
10299 -- include malformed state declarations.
10301 else
10302 Analyze_Abstract_State (States, Pack_Id);
10303 end if;
10305 -- Verify the declaration order of pragmas Abstract_State and
10306 -- Initializes.
10308 Check_Declaration_Order
10309 (First => N,
10310 Second => Get_Pragma (Pack_Id, Pragma_Initializes));
10312 -- Chain the pragma on the contract for completeness
10314 Add_Contract_Item (N, Pack_Id);
10315 end Abstract_State;
10317 ------------
10318 -- Ada_83 --
10319 ------------
10321 -- pragma Ada_83;
10323 -- Note: this pragma also has some specific processing in Par.Prag
10324 -- because we want to set the Ada version mode during parsing.
10326 when Pragma_Ada_83 =>
10327 GNAT_Pragma;
10328 Check_Arg_Count (0);
10330 -- We really should check unconditionally for proper configuration
10331 -- pragma placement, since we really don't want mixed Ada modes
10332 -- within a single unit, and the GNAT reference manual has always
10333 -- said this was a configuration pragma, but we did not check and
10334 -- are hesitant to add the check now.
10336 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
10337 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
10338 -- or Ada 2012 mode.
10340 if Ada_Version >= Ada_2005 then
10341 Check_Valid_Configuration_Pragma;
10342 end if;
10344 -- Now set Ada 83 mode
10346 Ada_Version := Ada_83;
10347 Ada_Version_Explicit := Ada_83;
10348 Ada_Version_Pragma := N;
10350 ------------
10351 -- Ada_95 --
10352 ------------
10354 -- pragma Ada_95;
10356 -- Note: this pragma also has some specific processing in Par.Prag
10357 -- because we want to set the Ada 83 version mode during parsing.
10359 when Pragma_Ada_95 =>
10360 GNAT_Pragma;
10361 Check_Arg_Count (0);
10363 -- We really should check unconditionally for proper configuration
10364 -- pragma placement, since we really don't want mixed Ada modes
10365 -- within a single unit, and the GNAT reference manual has always
10366 -- said this was a configuration pragma, but we did not check and
10367 -- are hesitant to add the check now.
10369 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
10370 -- or Ada 95, so we must check if we are in Ada 2005 mode.
10372 if Ada_Version >= Ada_2005 then
10373 Check_Valid_Configuration_Pragma;
10374 end if;
10376 -- Now set Ada 95 mode
10378 Ada_Version := Ada_95;
10379 Ada_Version_Explicit := Ada_95;
10380 Ada_Version_Pragma := N;
10382 ---------------------
10383 -- Ada_05/Ada_2005 --
10384 ---------------------
10386 -- pragma Ada_05;
10387 -- pragma Ada_05 (LOCAL_NAME);
10389 -- pragma Ada_2005;
10390 -- pragma Ada_2005 (LOCAL_NAME):
10392 -- Note: these pragmas also have some specific processing in Par.Prag
10393 -- because we want to set the Ada 2005 version mode during parsing.
10395 -- The one argument form is used for managing the transition from
10396 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
10397 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
10398 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
10399 -- mode, a preference rule is established which does not choose
10400 -- such an entity unless it is unambiguously specified. This avoids
10401 -- extra subprograms marked this way from generating ambiguities in
10402 -- otherwise legal pre-Ada_2005 programs. The one argument form is
10403 -- intended for exclusive use in the GNAT run-time library.
10405 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
10406 E_Id : Node_Id;
10408 begin
10409 GNAT_Pragma;
10411 if Arg_Count = 1 then
10412 Check_Arg_Is_Local_Name (Arg1);
10413 E_Id := Get_Pragma_Arg (Arg1);
10415 if Etype (E_Id) = Any_Type then
10416 return;
10417 end if;
10419 Set_Is_Ada_2005_Only (Entity (E_Id));
10420 Record_Rep_Item (Entity (E_Id), N);
10422 else
10423 Check_Arg_Count (0);
10425 -- For Ada_2005 we unconditionally enforce the documented
10426 -- configuration pragma placement, since we do not want to
10427 -- tolerate mixed modes in a unit involving Ada 2005. That
10428 -- would cause real difficulties for those cases where there
10429 -- are incompatibilities between Ada 95 and Ada 2005.
10431 Check_Valid_Configuration_Pragma;
10433 -- Now set appropriate Ada mode
10435 Ada_Version := Ada_2005;
10436 Ada_Version_Explicit := Ada_2005;
10437 Ada_Version_Pragma := N;
10438 end if;
10439 end;
10441 ---------------------
10442 -- Ada_12/Ada_2012 --
10443 ---------------------
10445 -- pragma Ada_12;
10446 -- pragma Ada_12 (LOCAL_NAME);
10448 -- pragma Ada_2012;
10449 -- pragma Ada_2012 (LOCAL_NAME):
10451 -- Note: these pragmas also have some specific processing in Par.Prag
10452 -- because we want to set the Ada 2012 version mode during parsing.
10454 -- The one argument form is used for managing the transition from Ada
10455 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
10456 -- as Ada_201 only, then referencing the entity in any pre-Ada_2012
10457 -- mode will generate a warning. In addition, in any pre-Ada_2012
10458 -- mode, a preference rule is established which does not choose
10459 -- such an entity unless it is unambiguously specified. This avoids
10460 -- extra subprograms marked this way from generating ambiguities in
10461 -- otherwise legal pre-Ada_2012 programs. The one argument form is
10462 -- intended for exclusive use in the GNAT run-time library.
10464 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
10465 E_Id : Node_Id;
10467 begin
10468 GNAT_Pragma;
10470 if Arg_Count = 1 then
10471 Check_Arg_Is_Local_Name (Arg1);
10472 E_Id := Get_Pragma_Arg (Arg1);
10474 if Etype (E_Id) = Any_Type then
10475 return;
10476 end if;
10478 Set_Is_Ada_2012_Only (Entity (E_Id));
10479 Record_Rep_Item (Entity (E_Id), N);
10481 else
10482 Check_Arg_Count (0);
10484 -- For Ada_2012 we unconditionally enforce the documented
10485 -- configuration pragma placement, since we do not want to
10486 -- tolerate mixed modes in a unit involving Ada 2012. That
10487 -- would cause real difficulties for those cases where there
10488 -- are incompatibilities between Ada 95 and Ada 2012. We could
10489 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
10491 Check_Valid_Configuration_Pragma;
10493 -- Now set appropriate Ada mode
10495 Ada_Version := Ada_2012;
10496 Ada_Version_Explicit := Ada_2012;
10497 Ada_Version_Pragma := N;
10498 end if;
10499 end;
10501 ----------------------
10502 -- All_Calls_Remote --
10503 ----------------------
10505 -- pragma All_Calls_Remote [(library_package_NAME)];
10507 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
10508 Lib_Entity : Entity_Id;
10510 begin
10511 Check_Ada_83_Warning;
10512 Check_Valid_Library_Unit_Pragma;
10514 if Nkind (N) = N_Null_Statement then
10515 return;
10516 end if;
10518 Lib_Entity := Find_Lib_Unit_Name;
10520 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
10522 if Present (Lib_Entity)
10523 and then not Debug_Flag_U
10524 then
10525 if not Is_Remote_Call_Interface (Lib_Entity) then
10526 Error_Pragma ("pragma% only apply to rci unit");
10528 -- Set flag for entity of the library unit
10530 else
10531 Set_Has_All_Calls_Remote (Lib_Entity);
10532 end if;
10534 end if;
10535 end All_Calls_Remote;
10537 ---------------------------
10538 -- Allow_Integer_Address --
10539 ---------------------------
10541 -- pragma Allow_Integer_Address;
10543 when Pragma_Allow_Integer_Address =>
10544 GNAT_Pragma;
10545 Check_Valid_Configuration_Pragma;
10546 Check_Arg_Count (0);
10548 -- If Address is a private type, then set the flag to allow
10549 -- integer address values. If Address is not private, then this
10550 -- pragma has no purpose, so it is simply ignored. Not clear if
10551 -- there are any such targets now.
10553 if Opt.Address_Is_Private then
10554 Opt.Allow_Integer_Address := True;
10555 end if;
10557 --------------
10558 -- Annotate --
10559 --------------
10561 -- pragma Annotate
10562 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
10563 -- ARG ::= NAME | EXPRESSION
10565 -- The first two arguments are by convention intended to refer to an
10566 -- external tool and a tool-specific function. These arguments are
10567 -- not analyzed.
10569 when Pragma_Annotate => Annotate : declare
10570 Arg : Node_Id;
10571 Exp : Node_Id;
10573 begin
10574 GNAT_Pragma;
10575 Check_At_Least_N_Arguments (1);
10577 -- See if last argument is Entity => local_Name, and if so process
10578 -- and then remove it for remaining processing.
10580 declare
10581 Last_Arg : constant Node_Id :=
10582 Last (Pragma_Argument_Associations (N));
10584 begin
10585 if Nkind (Last_Arg) = N_Pragma_Argument_Association
10586 and then Chars (Last_Arg) = Name_Entity
10587 then
10588 Check_Arg_Is_Local_Name (Last_Arg);
10589 Arg_Count := Arg_Count - 1;
10591 -- Not allowed in compiler units (bootstrap issues)
10593 Check_Compiler_Unit ("Entity for pragma Annotate", N);
10594 end if;
10595 end;
10597 -- Continue processing with last argument removed for now
10599 Check_Arg_Is_Identifier (Arg1);
10600 Check_No_Identifiers;
10601 Store_Note (N);
10603 -- Second parameter is optional, it is never analyzed
10605 if No (Arg2) then
10606 null;
10608 -- Here if we have a second parameter
10610 else
10611 -- Second parameter must be identifier
10613 Check_Arg_Is_Identifier (Arg2);
10615 -- Process remaining parameters if any
10617 Arg := Next (Arg2);
10618 while Present (Arg) loop
10619 Exp := Get_Pragma_Arg (Arg);
10620 Analyze (Exp);
10622 if Is_Entity_Name (Exp) then
10623 null;
10625 -- For string literals, we assume Standard_String as the
10626 -- type, unless the string contains wide or wide_wide
10627 -- characters.
10629 elsif Nkind (Exp) = N_String_Literal then
10630 if Has_Wide_Wide_Character (Exp) then
10631 Resolve (Exp, Standard_Wide_Wide_String);
10632 elsif Has_Wide_Character (Exp) then
10633 Resolve (Exp, Standard_Wide_String);
10634 else
10635 Resolve (Exp, Standard_String);
10636 end if;
10638 elsif Is_Overloaded (Exp) then
10639 Error_Pragma_Arg
10640 ("ambiguous argument for pragma%", Exp);
10642 else
10643 Resolve (Exp);
10644 end if;
10646 Next (Arg);
10647 end loop;
10648 end if;
10649 end Annotate;
10651 -------------------------------------------------
10652 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
10653 -------------------------------------------------
10655 -- pragma Assert
10656 -- ( [Check => ] Boolean_EXPRESSION
10657 -- [, [Message =>] Static_String_EXPRESSION]);
10659 -- pragma Assert_And_Cut
10660 -- ( [Check => ] Boolean_EXPRESSION
10661 -- [, [Message =>] Static_String_EXPRESSION]);
10663 -- pragma Assume
10664 -- ( [Check => ] Boolean_EXPRESSION
10665 -- [, [Message =>] Static_String_EXPRESSION]);
10667 -- pragma Loop_Invariant
10668 -- ( [Check => ] Boolean_EXPRESSION
10669 -- [, [Message =>] Static_String_EXPRESSION]);
10671 when Pragma_Assert |
10672 Pragma_Assert_And_Cut |
10673 Pragma_Assume |
10674 Pragma_Loop_Invariant =>
10675 Assert : declare
10676 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
10677 -- Determine whether expression Expr contains a Loop_Entry
10678 -- attribute reference.
10680 -------------------------
10681 -- Contains_Loop_Entry --
10682 -------------------------
10684 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
10685 Has_Loop_Entry : Boolean := False;
10687 function Process (N : Node_Id) return Traverse_Result;
10688 -- Process function for traversal to look for Loop_Entry
10690 -------------
10691 -- Process --
10692 -------------
10694 function Process (N : Node_Id) return Traverse_Result is
10695 begin
10696 if Nkind (N) = N_Attribute_Reference
10697 and then Attribute_Name (N) = Name_Loop_Entry
10698 then
10699 Has_Loop_Entry := True;
10700 return Abandon;
10701 else
10702 return OK;
10703 end if;
10704 end Process;
10706 procedure Traverse is new Traverse_Proc (Process);
10708 -- Start of processing for Contains_Loop_Entry
10710 begin
10711 Traverse (Expr);
10712 return Has_Loop_Entry;
10713 end Contains_Loop_Entry;
10715 -- Local variables
10717 Expr : Node_Id;
10718 Newa : List_Id;
10720 -- Start of processing for Assert
10722 begin
10723 -- Assert is an Ada 2005 RM-defined pragma
10725 if Prag_Id = Pragma_Assert then
10726 Ada_2005_Pragma;
10728 -- The remaining ones are GNAT pragmas
10730 else
10731 GNAT_Pragma;
10732 end if;
10734 Check_At_Least_N_Arguments (1);
10735 Check_At_Most_N_Arguments (2);
10736 Check_Arg_Order ((Name_Check, Name_Message));
10737 Check_Optional_Identifier (Arg1, Name_Check);
10738 Expr := Get_Pragma_Arg (Arg1);
10740 -- Special processing for Loop_Invariant, Loop_Variant or for
10741 -- other cases where a Loop_Entry attribute is present. If the
10742 -- assertion pragma contains attribute Loop_Entry, ensure that
10743 -- the related pragma is within a loop.
10745 if Prag_Id = Pragma_Loop_Invariant
10746 or else Prag_Id = Pragma_Loop_Variant
10747 or else Contains_Loop_Entry (Expr)
10748 then
10749 Check_Loop_Pragma_Placement;
10751 -- Perform preanalysis to deal with embedded Loop_Entry
10752 -- attributes.
10754 Preanalyze_Assert_Expression (Expression (Arg1), Any_Boolean);
10755 end if;
10757 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
10758 -- a corresponding Check pragma:
10760 -- pragma Check (name, condition [, msg]);
10762 -- Where name is the identifier matching the pragma name. So
10763 -- rewrite pragma in this manner, transfer the message argument
10764 -- if present, and analyze the result
10766 -- Note: When dealing with a semantically analyzed tree, the
10767 -- information that a Check node N corresponds to a source Assert,
10768 -- Assume, or Assert_And_Cut pragma can be retrieved from the
10769 -- pragma kind of Original_Node(N).
10771 Newa := New_List (
10772 Make_Pragma_Argument_Association (Loc,
10773 Expression => Make_Identifier (Loc, Pname)),
10774 Make_Pragma_Argument_Association (Sloc (Expr),
10775 Expression => Expr));
10777 if Arg_Count > 1 then
10778 Check_Optional_Identifier (Arg2, Name_Message);
10780 -- Provide semantic annnotations for optional argument, for
10781 -- ASIS use, before rewriting.
10783 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
10784 Append_To (Newa, New_Copy_Tree (Arg2));
10785 end if;
10787 -- Rewrite as Check pragma
10789 Rewrite (N,
10790 Make_Pragma (Loc,
10791 Chars => Name_Check,
10792 Pragma_Argument_Associations => Newa));
10793 Analyze (N);
10794 end Assert;
10796 ----------------------
10797 -- Assertion_Policy --
10798 ----------------------
10800 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
10802 -- The following form is Ada 2012 only, but we allow it in all modes
10804 -- Pragma Assertion_Policy (
10805 -- ASSERTION_KIND => POLICY_IDENTIFIER
10806 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
10808 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
10810 -- RM_ASSERTION_KIND ::= Assert |
10811 -- Static_Predicate |
10812 -- Dynamic_Predicate |
10813 -- Pre |
10814 -- Pre'Class |
10815 -- Post |
10816 -- Post'Class |
10817 -- Type_Invariant |
10818 -- Type_Invariant'Class
10820 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
10821 -- Assume |
10822 -- Contract_Cases |
10823 -- Debug |
10824 -- Default_Initial_Condition |
10825 -- Ghost |
10826 -- Initial_Condition |
10827 -- Loop_Invariant |
10828 -- Loop_Variant |
10829 -- Postcondition |
10830 -- Precondition |
10831 -- Predicate |
10832 -- Refined_Post |
10833 -- Statement_Assertions
10835 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
10836 -- ID_ASSERTION_KIND list contains implementation-defined additions
10837 -- recognized by GNAT. The effect is to control the behavior of
10838 -- identically named aspects and pragmas, depending on the specified
10839 -- policy identifier:
10841 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore
10843 -- Note: Check and Ignore are language-defined. Disable is a GNAT
10844 -- implementation defined addition that results in totally ignoring
10845 -- the corresponding assertion. If Disable is specified, then the
10846 -- argument of the assertion is not even analyzed. This is useful
10847 -- when the aspect/pragma argument references entities in a with'ed
10848 -- package that is replaced by a dummy package in the final build.
10850 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
10851 -- and Type_Invariant'Class were recognized by the parser and
10852 -- transformed into references to the special internal identifiers
10853 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
10854 -- processing is required here.
10856 when Pragma_Assertion_Policy => Assertion_Policy : declare
10857 Arg : Node_Id;
10858 Kind : Name_Id;
10859 LocP : Source_Ptr;
10860 Policy : Node_Id;
10862 begin
10863 Ada_2005_Pragma;
10865 -- This can always appear as a configuration pragma
10867 if Is_Configuration_Pragma then
10868 null;
10870 -- It can also appear in a declarative part or package spec in Ada
10871 -- 2012 mode. We allow this in other modes, but in that case we
10872 -- consider that we have an Ada 2012 pragma on our hands.
10874 else
10875 Check_Is_In_Decl_Part_Or_Package_Spec;
10876 Ada_2012_Pragma;
10877 end if;
10879 -- One argument case with no identifier (first form above)
10881 if Arg_Count = 1
10882 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
10883 or else Chars (Arg1) = No_Name)
10884 then
10885 Check_Arg_Is_One_Of
10886 (Arg1, Name_Check, Name_Disable, Name_Ignore);
10888 -- Treat one argument Assertion_Policy as equivalent to:
10890 -- pragma Check_Policy (Assertion, policy)
10892 -- So rewrite pragma in that manner and link on to the chain
10893 -- of Check_Policy pragmas, marking the pragma as analyzed.
10895 Policy := Get_Pragma_Arg (Arg1);
10897 Rewrite (N,
10898 Make_Pragma (Loc,
10899 Chars => Name_Check_Policy,
10900 Pragma_Argument_Associations => New_List (
10901 Make_Pragma_Argument_Association (Loc,
10902 Expression => Make_Identifier (Loc, Name_Assertion)),
10904 Make_Pragma_Argument_Association (Loc,
10905 Expression =>
10906 Make_Identifier (Sloc (Policy), Chars (Policy))))));
10907 Analyze (N);
10909 -- Here if we have two or more arguments
10911 else
10912 Check_At_Least_N_Arguments (1);
10913 Ada_2012_Pragma;
10915 -- Loop through arguments
10917 Arg := Arg1;
10918 while Present (Arg) loop
10919 LocP := Sloc (Arg);
10921 -- Kind must be specified
10923 if Nkind (Arg) /= N_Pragma_Argument_Association
10924 or else Chars (Arg) = No_Name
10925 then
10926 Error_Pragma_Arg
10927 ("missing assertion kind for pragma%", Arg);
10928 end if;
10930 -- Check Kind and Policy have allowed forms
10932 Kind := Chars (Arg);
10934 if not Is_Valid_Assertion_Kind (Kind) then
10935 Error_Pragma_Arg
10936 ("invalid assertion kind for pragma%", Arg);
10937 end if;
10939 Check_Arg_Is_One_Of
10940 (Arg, Name_Check, Name_Disable, Name_Ignore);
10942 -- Rewrite the Assertion_Policy pragma as a series of
10943 -- Check_Policy pragmas of the form:
10945 -- Check_Policy (Kind, Policy);
10947 -- Note: the insertion of the pragmas cannot be done with
10948 -- Insert_Action because in the configuration case, there
10949 -- are no scopes on the scope stack and the mechanism will
10950 -- fail.
10952 Insert_Before_And_Analyze (N,
10953 Make_Pragma (LocP,
10954 Chars => Name_Check_Policy,
10955 Pragma_Argument_Associations => New_List (
10956 Make_Pragma_Argument_Association (LocP,
10957 Expression => Make_Identifier (LocP, Kind)),
10958 Make_Pragma_Argument_Association (LocP,
10959 Expression => Get_Pragma_Arg (Arg)))));
10961 Arg := Next (Arg);
10962 end loop;
10964 -- Rewrite the Assertion_Policy pragma as null since we have
10965 -- now inserted all the equivalent Check pragmas.
10967 Rewrite (N, Make_Null_Statement (Loc));
10968 Analyze (N);
10969 end if;
10970 end Assertion_Policy;
10972 ------------------------------
10973 -- Assume_No_Invalid_Values --
10974 ------------------------------
10976 -- pragma Assume_No_Invalid_Values (On | Off);
10978 when Pragma_Assume_No_Invalid_Values =>
10979 GNAT_Pragma;
10980 Check_Valid_Configuration_Pragma;
10981 Check_Arg_Count (1);
10982 Check_No_Identifiers;
10983 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10985 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
10986 Assume_No_Invalid_Values := True;
10987 else
10988 Assume_No_Invalid_Values := False;
10989 end if;
10991 --------------------------
10992 -- Attribute_Definition --
10993 --------------------------
10995 -- pragma Attribute_Definition
10996 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
10997 -- [Entity =>] LOCAL_NAME,
10998 -- [Expression =>] EXPRESSION | NAME);
11000 when Pragma_Attribute_Definition => Attribute_Definition : declare
11001 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
11002 Aname : Name_Id;
11004 begin
11005 GNAT_Pragma;
11006 Check_Arg_Count (3);
11007 Check_Optional_Identifier (Arg1, "attribute");
11008 Check_Optional_Identifier (Arg2, "entity");
11009 Check_Optional_Identifier (Arg3, "expression");
11011 if Nkind (Attribute_Designator) /= N_Identifier then
11012 Error_Msg_N ("attribute name expected", Attribute_Designator);
11013 return;
11014 end if;
11016 Check_Arg_Is_Local_Name (Arg2);
11018 -- If the attribute is not recognized, then issue a warning (not
11019 -- an error), and ignore the pragma.
11021 Aname := Chars (Attribute_Designator);
11023 if not Is_Attribute_Name (Aname) then
11024 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
11025 return;
11026 end if;
11028 -- Otherwise, rewrite the pragma as an attribute definition clause
11030 Rewrite (N,
11031 Make_Attribute_Definition_Clause (Loc,
11032 Name => Get_Pragma_Arg (Arg2),
11033 Chars => Aname,
11034 Expression => Get_Pragma_Arg (Arg3)));
11035 Analyze (N);
11036 end Attribute_Definition;
11038 ------------------------------------------------------------------
11039 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
11040 ------------------------------------------------------------------
11042 -- pragma Asynch_Readers ( object_LOCAL_NAME [, FLAG] );
11043 -- pragma Asynch_Writers ( object_LOCAL_NAME [, FLAG] );
11044 -- pragma Effective_Reads ( object_LOCAL_NAME [, FLAG] );
11045 -- pragma Effective_Writes ( object_LOCAL_NAME [, FLAG] );
11047 -- FLAG ::= boolean_EXPRESSION
11049 when Pragma_Async_Readers |
11050 Pragma_Async_Writers |
11051 Pragma_Effective_Reads |
11052 Pragma_Effective_Writes =>
11053 Async_Effective : declare
11054 Duplic : Node_Id;
11055 Expr : Node_Id;
11056 Obj : Node_Id;
11057 Obj_Id : Entity_Id;
11059 begin
11060 GNAT_Pragma;
11061 Check_No_Identifiers;
11062 Check_At_Least_N_Arguments (1);
11063 Check_At_Most_N_Arguments (2);
11064 Check_Arg_Is_Local_Name (Arg1);
11065 Error_Msg_Name_1 := Pname;
11067 Obj := Get_Pragma_Arg (Arg1);
11068 Expr := Get_Pragma_Arg (Arg2);
11070 -- Perform minimal verification to ensure that the argument is at
11071 -- least a variable. Subsequent finer grained checks will be done
11072 -- at the end of the declarative region the contains the pragma.
11074 if Is_Entity_Name (Obj)
11075 and then Present (Entity (Obj))
11076 and then Ekind (Entity (Obj)) = E_Variable
11077 then
11078 Obj_Id := Entity (Obj);
11080 -- Detect a duplicate pragma. Note that it is not efficient to
11081 -- examine preceding statements as Boolean aspects may appear
11082 -- anywhere between the related object declaration and its
11083 -- freeze point. As an alternative, inspect the contents of the
11084 -- variable contract.
11086 Duplic := Get_Pragma (Obj_Id, Prag_Id);
11088 if Present (Duplic) then
11089 Error_Msg_Sloc := Sloc (Duplic);
11090 Error_Msg_N ("pragma % duplicates pragma declared #", N);
11092 -- No duplicate detected
11094 else
11095 if Present (Expr) then
11096 Preanalyze_And_Resolve (Expr, Standard_Boolean);
11097 end if;
11099 -- Chain the pragma on the contract for further processing
11100 -- by Analyze_External_Property_In_Decl_Part.
11102 Add_Contract_Item (N, Obj_Id);
11103 end if;
11104 else
11105 Error_Pragma ("pragma % must apply to a volatile object");
11106 end if;
11107 end Async_Effective;
11109 ------------------
11110 -- Asynchronous --
11111 ------------------
11113 -- pragma Asynchronous (LOCAL_NAME);
11115 when Pragma_Asynchronous => Asynchronous : declare
11116 Nm : Entity_Id;
11117 C_Ent : Entity_Id;
11118 L : List_Id;
11119 S : Node_Id;
11120 N : Node_Id;
11121 Formal : Entity_Id;
11123 procedure Process_Async_Pragma;
11124 -- Common processing for procedure and access-to-procedure case
11126 --------------------------
11127 -- Process_Async_Pragma --
11128 --------------------------
11130 procedure Process_Async_Pragma is
11131 begin
11132 if No (L) then
11133 Set_Is_Asynchronous (Nm);
11134 return;
11135 end if;
11137 -- The formals should be of mode IN (RM E.4.1(6))
11139 S := First (L);
11140 while Present (S) loop
11141 Formal := Defining_Identifier (S);
11143 if Nkind (Formal) = N_Defining_Identifier
11144 and then Ekind (Formal) /= E_In_Parameter
11145 then
11146 Error_Pragma_Arg
11147 ("pragma% procedure can only have IN parameter",
11148 Arg1);
11149 end if;
11151 Next (S);
11152 end loop;
11154 Set_Is_Asynchronous (Nm);
11155 end Process_Async_Pragma;
11157 -- Start of processing for pragma Asynchronous
11159 begin
11160 Check_Ada_83_Warning;
11161 Check_No_Identifiers;
11162 Check_Arg_Count (1);
11163 Check_Arg_Is_Local_Name (Arg1);
11165 if Debug_Flag_U then
11166 return;
11167 end if;
11169 C_Ent := Cunit_Entity (Current_Sem_Unit);
11170 Analyze (Get_Pragma_Arg (Arg1));
11171 Nm := Entity (Get_Pragma_Arg (Arg1));
11173 if not Is_Remote_Call_Interface (C_Ent)
11174 and then not Is_Remote_Types (C_Ent)
11175 then
11176 -- This pragma should only appear in an RCI or Remote Types
11177 -- unit (RM E.4.1(4)).
11179 Error_Pragma
11180 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
11181 end if;
11183 if Ekind (Nm) = E_Procedure
11184 and then Nkind (Parent (Nm)) = N_Procedure_Specification
11185 then
11186 if not Is_Remote_Call_Interface (Nm) then
11187 Error_Pragma_Arg
11188 ("pragma% cannot be applied on non-remote procedure",
11189 Arg1);
11190 end if;
11192 L := Parameter_Specifications (Parent (Nm));
11193 Process_Async_Pragma;
11194 return;
11196 elsif Ekind (Nm) = E_Function then
11197 Error_Pragma_Arg
11198 ("pragma% cannot be applied to function", Arg1);
11200 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
11201 if Is_Record_Type (Nm) then
11203 -- A record type that is the Equivalent_Type for a remote
11204 -- access-to-subprogram type.
11206 N := Declaration_Node (Corresponding_Remote_Type (Nm));
11208 else
11209 -- A non-expanded RAS type (distribution is not enabled)
11211 N := Declaration_Node (Nm);
11212 end if;
11214 if Nkind (N) = N_Full_Type_Declaration
11215 and then Nkind (Type_Definition (N)) =
11216 N_Access_Procedure_Definition
11217 then
11218 L := Parameter_Specifications (Type_Definition (N));
11219 Process_Async_Pragma;
11221 if Is_Asynchronous (Nm)
11222 and then Expander_Active
11223 and then Get_PCS_Name /= Name_No_DSA
11224 then
11225 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
11226 end if;
11228 else
11229 Error_Pragma_Arg
11230 ("pragma% cannot reference access-to-function type",
11231 Arg1);
11232 end if;
11234 -- Only other possibility is Access-to-class-wide type
11236 elsif Is_Access_Type (Nm)
11237 and then Is_Class_Wide_Type (Designated_Type (Nm))
11238 then
11239 Check_First_Subtype (Arg1);
11240 Set_Is_Asynchronous (Nm);
11241 if Expander_Active then
11242 RACW_Type_Is_Asynchronous (Nm);
11243 end if;
11245 else
11246 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
11247 end if;
11248 end Asynchronous;
11250 ------------
11251 -- Atomic --
11252 ------------
11254 -- pragma Atomic (LOCAL_NAME);
11256 when Pragma_Atomic =>
11257 Process_Atomic_Independent_Shared_Volatile;
11259 -----------------------
11260 -- Atomic_Components --
11261 -----------------------
11263 -- pragma Atomic_Components (array_LOCAL_NAME);
11265 -- This processing is shared by Volatile_Components
11267 when Pragma_Atomic_Components |
11268 Pragma_Volatile_Components =>
11270 Atomic_Components : declare
11271 E_Id : Node_Id;
11272 E : Entity_Id;
11273 D : Node_Id;
11274 K : Node_Kind;
11276 begin
11277 Check_Ada_83_Warning;
11278 Check_No_Identifiers;
11279 Check_Arg_Count (1);
11280 Check_Arg_Is_Local_Name (Arg1);
11281 E_Id := Get_Pragma_Arg (Arg1);
11283 if Etype (E_Id) = Any_Type then
11284 return;
11285 end if;
11287 E := Entity (E_Id);
11289 Check_Duplicate_Pragma (E);
11291 if Rep_Item_Too_Early (E, N)
11292 or else
11293 Rep_Item_Too_Late (E, N)
11294 then
11295 return;
11296 end if;
11298 D := Declaration_Node (E);
11299 K := Nkind (D);
11301 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
11302 or else
11303 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
11304 and then Nkind (D) = N_Object_Declaration
11305 and then Nkind (Object_Definition (D)) =
11306 N_Constrained_Array_Definition)
11307 then
11308 -- The flag is set on the object, or on the base type
11310 if Nkind (D) /= N_Object_Declaration then
11311 E := Base_Type (E);
11312 end if;
11314 -- Atomic implies both Independent and Volatile
11316 if Prag_Id = Pragma_Atomic_Components then
11317 Set_Has_Atomic_Components (E);
11318 Set_Has_Independent_Components (E);
11319 end if;
11321 Set_Has_Volatile_Components (E);
11323 else
11324 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
11325 end if;
11326 end Atomic_Components;
11328 --------------------
11329 -- Attach_Handler --
11330 --------------------
11332 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
11334 when Pragma_Attach_Handler =>
11335 Check_Ada_83_Warning;
11336 Check_No_Identifiers;
11337 Check_Arg_Count (2);
11339 if No_Run_Time_Mode then
11340 Error_Msg_CRT ("Attach_Handler pragma", N);
11341 else
11342 Check_Interrupt_Or_Attach_Handler;
11344 -- The expression that designates the attribute may depend on a
11345 -- discriminant, and is therefore a per-object expression, to
11346 -- be expanded in the init proc. If expansion is enabled, then
11347 -- perform semantic checks on a copy only.
11349 declare
11350 Temp : Node_Id;
11351 Typ : Node_Id;
11352 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
11354 begin
11355 -- In Relaxed_RM_Semantics mode, we allow any static
11356 -- integer value, for compatibility with other compilers.
11358 if Relaxed_RM_Semantics
11359 and then Nkind (Parg2) = N_Integer_Literal
11360 then
11361 Typ := Standard_Integer;
11362 else
11363 Typ := RTE (RE_Interrupt_ID);
11364 end if;
11366 if Expander_Active then
11367 Temp := New_Copy_Tree (Parg2);
11368 Set_Parent (Temp, N);
11369 Preanalyze_And_Resolve (Temp, Typ);
11370 else
11371 Analyze (Parg2);
11372 Resolve (Parg2, Typ);
11373 end if;
11374 end;
11376 Process_Interrupt_Or_Attach_Handler;
11377 end if;
11379 --------------------
11380 -- C_Pass_By_Copy --
11381 --------------------
11383 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
11385 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
11386 Arg : Node_Id;
11387 Val : Uint;
11389 begin
11390 GNAT_Pragma;
11391 Check_Valid_Configuration_Pragma;
11392 Check_Arg_Count (1);
11393 Check_Optional_Identifier (Arg1, "max_size");
11395 Arg := Get_Pragma_Arg (Arg1);
11396 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
11398 Val := Expr_Value (Arg);
11400 if Val <= 0 then
11401 Error_Pragma_Arg
11402 ("maximum size for pragma% must be positive", Arg1);
11404 elsif UI_Is_In_Int_Range (Val) then
11405 Default_C_Record_Mechanism := UI_To_Int (Val);
11407 -- If a giant value is given, Int'Last will do well enough.
11408 -- If sometime someone complains that a record larger than
11409 -- two gigabytes is not copied, we will worry about it then.
11411 else
11412 Default_C_Record_Mechanism := Mechanism_Type'Last;
11413 end if;
11414 end C_Pass_By_Copy;
11416 -----------
11417 -- Check --
11418 -----------
11420 -- pragma Check ([Name =>] CHECK_KIND,
11421 -- [Check =>] Boolean_EXPRESSION
11422 -- [,[Message =>] String_EXPRESSION]);
11424 -- CHECK_KIND ::= IDENTIFIER |
11425 -- Pre'Class |
11426 -- Post'Class |
11427 -- Invariant'Class |
11428 -- Type_Invariant'Class
11430 -- The identifiers Assertions and Statement_Assertions are not
11431 -- allowed, since they have special meaning for Check_Policy.
11433 when Pragma_Check => Check : declare
11434 Expr : Node_Id;
11435 Eloc : Source_Ptr;
11436 Cname : Name_Id;
11437 Str : Node_Id;
11439 begin
11440 GNAT_Pragma;
11441 Check_At_Least_N_Arguments (2);
11442 Check_At_Most_N_Arguments (3);
11443 Check_Optional_Identifier (Arg1, Name_Name);
11444 Check_Optional_Identifier (Arg2, Name_Check);
11446 if Arg_Count = 3 then
11447 Check_Optional_Identifier (Arg3, Name_Message);
11448 Str := Get_Pragma_Arg (Arg3);
11449 end if;
11451 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
11452 Check_Arg_Is_Identifier (Arg1);
11453 Cname := Chars (Get_Pragma_Arg (Arg1));
11455 -- Check forbidden name Assertions or Statement_Assertions
11457 case Cname is
11458 when Name_Assertions =>
11459 Error_Pragma_Arg
11460 ("""Assertions"" is not allowed as a check kind "
11461 & "for pragma%", Arg1);
11463 when Name_Statement_Assertions =>
11464 Error_Pragma_Arg
11465 ("""Statement_Assertions"" is not allowed as a check kind "
11466 & "for pragma%", Arg1);
11468 when others =>
11469 null;
11470 end case;
11472 -- Check applicable policy. We skip this if Checked/Ignored status
11473 -- is already set (e.g. in the case of a pragma from an aspect).
11475 if Is_Checked (N) or else Is_Ignored (N) then
11476 null;
11478 -- For a non-source pragma that is a rewriting of another pragma,
11479 -- copy the Is_Checked/Ignored status from the rewritten pragma.
11481 elsif Is_Rewrite_Substitution (N)
11482 and then Nkind (Original_Node (N)) = N_Pragma
11483 and then Original_Node (N) /= N
11484 then
11485 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
11486 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
11488 -- Otherwise query the applicable policy at this point
11490 else
11491 case Check_Kind (Cname) is
11492 when Name_Ignore =>
11493 Set_Is_Ignored (N, True);
11494 Set_Is_Checked (N, False);
11496 when Name_Check =>
11497 Set_Is_Ignored (N, False);
11498 Set_Is_Checked (N, True);
11500 -- For disable, rewrite pragma as null statement and skip
11501 -- rest of the analysis of the pragma.
11503 when Name_Disable =>
11504 Rewrite (N, Make_Null_Statement (Loc));
11505 Analyze (N);
11506 raise Pragma_Exit;
11508 -- No other possibilities
11510 when others =>
11511 raise Program_Error;
11512 end case;
11513 end if;
11515 -- If check kind was not Disable, then continue pragma analysis
11517 Expr := Get_Pragma_Arg (Arg2);
11519 -- Deal with SCO generation
11521 case Cname is
11522 when Name_Predicate |
11523 Name_Invariant =>
11525 -- Nothing to do: since checks occur in client units,
11526 -- the SCO for the aspect in the declaration unit is
11527 -- conservatively always enabled.
11529 null;
11531 when others =>
11533 if Is_Checked (N) and then not Split_PPC (N) then
11535 -- Mark aspect/pragma SCO as enabled
11537 Set_SCO_Pragma_Enabled (Loc);
11538 end if;
11539 end case;
11541 -- Deal with analyzing the string argument
11543 if Arg_Count = 3 then
11545 -- If checks are not on we don't want any expansion (since
11546 -- such expansion would not get properly deleted) but
11547 -- we do want to analyze (to get proper references).
11548 -- The Preanalyze_And_Resolve routine does just what we want
11550 if Is_Ignored (N) then
11551 Preanalyze_And_Resolve (Str, Standard_String);
11553 -- Otherwise we need a proper analysis and expansion
11555 else
11556 Analyze_And_Resolve (Str, Standard_String);
11557 end if;
11558 end if;
11560 -- Now you might think we could just do the same with the Boolean
11561 -- expression if checks are off (and expansion is on) and then
11562 -- rewrite the check as a null statement. This would work but we
11563 -- would lose the useful warnings about an assertion being bound
11564 -- to fail even if assertions are turned off.
11566 -- So instead we wrap the boolean expression in an if statement
11567 -- that looks like:
11569 -- if False and then condition then
11570 -- null;
11571 -- end if;
11573 -- The reason we do this rewriting during semantic analysis rather
11574 -- than as part of normal expansion is that we cannot analyze and
11575 -- expand the code for the boolean expression directly, or it may
11576 -- cause insertion of actions that would escape the attempt to
11577 -- suppress the check code.
11579 -- Note that the Sloc for the if statement corresponds to the
11580 -- argument condition, not the pragma itself. The reason for
11581 -- this is that we may generate a warning if the condition is
11582 -- False at compile time, and we do not want to delete this
11583 -- warning when we delete the if statement.
11585 if Expander_Active and Is_Ignored (N) then
11586 Eloc := Sloc (Expr);
11588 Rewrite (N,
11589 Make_If_Statement (Eloc,
11590 Condition =>
11591 Make_And_Then (Eloc,
11592 Left_Opnd => Make_Identifier (Eloc, Name_False),
11593 Right_Opnd => Expr),
11594 Then_Statements => New_List (
11595 Make_Null_Statement (Eloc))));
11597 -- Now go ahead and analyze the if statement
11599 In_Assertion_Expr := In_Assertion_Expr + 1;
11601 -- One rather special treatment. If we are now in Eliminated
11602 -- overflow mode, then suppress overflow checking since we do
11603 -- not want to drag in the bignum stuff if we are in Ignore
11604 -- mode anyway. This is particularly important if we are using
11605 -- a configurable run time that does not support bignum ops.
11607 if Scope_Suppress.Overflow_Mode_Assertions = Eliminated then
11608 declare
11609 Svo : constant Boolean :=
11610 Scope_Suppress.Suppress (Overflow_Check);
11611 begin
11612 Scope_Suppress.Overflow_Mode_Assertions := Strict;
11613 Scope_Suppress.Suppress (Overflow_Check) := True;
11614 Analyze (N);
11615 Scope_Suppress.Suppress (Overflow_Check) := Svo;
11616 Scope_Suppress.Overflow_Mode_Assertions := Eliminated;
11617 end;
11619 -- Not that special case!
11621 else
11622 Analyze (N);
11623 end if;
11625 -- All done with this check
11627 In_Assertion_Expr := In_Assertion_Expr - 1;
11629 -- Check is active or expansion not active. In these cases we can
11630 -- just go ahead and analyze the boolean with no worries.
11632 else
11633 In_Assertion_Expr := In_Assertion_Expr + 1;
11634 Analyze_And_Resolve (Expr, Any_Boolean);
11635 In_Assertion_Expr := In_Assertion_Expr - 1;
11636 end if;
11637 end Check;
11639 --------------------------
11640 -- Check_Float_Overflow --
11641 --------------------------
11643 -- pragma Check_Float_Overflow;
11645 when Pragma_Check_Float_Overflow =>
11646 GNAT_Pragma;
11647 Check_Valid_Configuration_Pragma;
11648 Check_Arg_Count (0);
11649 Check_Float_Overflow := not Machine_Overflows_On_Target;
11651 ----------------
11652 -- Check_Name --
11653 ----------------
11655 -- pragma Check_Name (check_IDENTIFIER);
11657 when Pragma_Check_Name =>
11658 GNAT_Pragma;
11659 Check_No_Identifiers;
11660 Check_Valid_Configuration_Pragma;
11661 Check_Arg_Count (1);
11662 Check_Arg_Is_Identifier (Arg1);
11664 declare
11665 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11667 begin
11668 for J in Check_Names.First .. Check_Names.Last loop
11669 if Check_Names.Table (J) = Nam then
11670 return;
11671 end if;
11672 end loop;
11674 Check_Names.Append (Nam);
11675 end;
11677 ------------------
11678 -- Check_Policy --
11679 ------------------
11681 -- This is the old style syntax, which is still allowed in all modes:
11683 -- pragma Check_Policy ([Name =>] CHECK_KIND
11684 -- [Policy =>] POLICY_IDENTIFIER);
11686 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
11688 -- CHECK_KIND ::= IDENTIFIER |
11689 -- Pre'Class |
11690 -- Post'Class |
11691 -- Type_Invariant'Class |
11692 -- Invariant'Class
11694 -- This is the new style syntax, compatible with Assertion_Policy
11695 -- and also allowed in all modes.
11697 -- Pragma Check_Policy (
11698 -- CHECK_KIND => POLICY_IDENTIFIER
11699 -- {, CHECK_KIND => POLICY_IDENTIFIER});
11701 -- Note: the identifiers Name and Policy are not allowed as
11702 -- Check_Kind values. This avoids ambiguities between the old and
11703 -- new form syntax.
11705 when Pragma_Check_Policy => Check_Policy : declare
11706 Ident : Node_Id;
11707 Kind : Node_Id;
11709 begin
11710 GNAT_Pragma;
11711 Check_At_Least_N_Arguments (1);
11713 -- A Check_Policy pragma can appear either as a configuration
11714 -- pragma, or in a declarative part or a package spec (see RM
11715 -- 11.5(5) for rules for Suppress/Unsuppress which are also
11716 -- followed for Check_Policy).
11718 if not Is_Configuration_Pragma then
11719 Check_Is_In_Decl_Part_Or_Package_Spec;
11720 end if;
11722 -- Figure out if we have the old or new syntax. We have the
11723 -- old syntax if the first argument has no identifier, or the
11724 -- identifier is Name.
11726 if Nkind (Arg1) /= N_Pragma_Argument_Association
11727 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
11728 then
11729 -- Old syntax
11731 Check_Arg_Count (2);
11732 Check_Optional_Identifier (Arg1, Name_Name);
11733 Kind := Get_Pragma_Arg (Arg1);
11734 Rewrite_Assertion_Kind (Kind);
11735 Check_Arg_Is_Identifier (Arg1);
11737 -- Check forbidden check kind
11739 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
11740 Error_Msg_Name_2 := Chars (Kind);
11741 Error_Pragma_Arg
11742 ("pragma% does not allow% as check name", Arg1);
11743 end if;
11745 -- Check policy
11747 Check_Optional_Identifier (Arg2, Name_Policy);
11748 Check_Arg_Is_One_Of
11749 (Arg2,
11750 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
11751 Ident := Get_Pragma_Arg (Arg2);
11753 if Chars (Kind) = Name_Ghost then
11755 -- Pragma Check_Policy specifying a Ghost policy cannot
11756 -- occur within a ghost subprogram or package.
11758 if Ghost_Mode > None then
11759 Error_Pragma
11760 ("pragma % cannot appear within ghost subprogram or "
11761 & "package");
11763 -- The policy identifier of pragma Ghost must be either
11764 -- Check or Ignore (SPARK RM 6.9(7)).
11766 elsif not Nam_In (Chars (Ident), Name_Check,
11767 Name_Ignore)
11768 then
11769 Error_Pragma_Arg
11770 ("argument of pragma % Ghost must be Check or Ignore",
11771 Arg2);
11772 end if;
11773 end if;
11775 -- And chain pragma on the Check_Policy_List for search
11777 Set_Next_Pragma (N, Opt.Check_Policy_List);
11778 Opt.Check_Policy_List := N;
11780 -- For the new syntax, what we do is to convert each argument to
11781 -- an old syntax equivalent. We do that because we want to chain
11782 -- old style Check_Policy pragmas for the search (we don't want
11783 -- to have to deal with multiple arguments in the search).
11785 else
11786 declare
11787 Arg : Node_Id;
11788 Argx : Node_Id;
11789 LocP : Source_Ptr;
11791 begin
11792 Arg := Arg1;
11793 while Present (Arg) loop
11794 LocP := Sloc (Arg);
11795 Argx := Get_Pragma_Arg (Arg);
11797 -- Kind must be specified
11799 if Nkind (Arg) /= N_Pragma_Argument_Association
11800 or else Chars (Arg) = No_Name
11801 then
11802 Error_Pragma_Arg
11803 ("missing assertion kind for pragma%", Arg);
11804 end if;
11806 -- Construct equivalent old form syntax Check_Policy
11807 -- pragma and insert it to get remaining checks.
11809 Insert_Action (N,
11810 Make_Pragma (LocP,
11811 Chars => Name_Check_Policy,
11812 Pragma_Argument_Associations => New_List (
11813 Make_Pragma_Argument_Association (LocP,
11814 Expression =>
11815 Make_Identifier (LocP, Chars (Arg))),
11816 Make_Pragma_Argument_Association (Sloc (Argx),
11817 Expression => Argx))));
11819 Arg := Next (Arg);
11820 end loop;
11822 -- Rewrite original Check_Policy pragma to null, since we
11823 -- have converted it into a series of old syntax pragmas.
11825 Rewrite (N, Make_Null_Statement (Loc));
11826 Analyze (N);
11827 end;
11828 end if;
11829 end Check_Policy;
11831 ---------------------
11832 -- CIL_Constructor --
11833 ---------------------
11835 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
11837 -- Processing for this pragma is shared with Java_Constructor
11839 -------------
11840 -- Comment --
11841 -------------
11843 -- pragma Comment (static_string_EXPRESSION)
11845 -- Processing for pragma Comment shares the circuitry for pragma
11846 -- Ident. The only differences are that Ident enforces a limit of 31
11847 -- characters on its argument, and also enforces limitations on
11848 -- placement for DEC compatibility. Pragma Comment shares neither of
11849 -- these restrictions.
11851 -------------------
11852 -- Common_Object --
11853 -------------------
11855 -- pragma Common_Object (
11856 -- [Internal =>] LOCAL_NAME
11857 -- [, [External =>] EXTERNAL_SYMBOL]
11858 -- [, [Size =>] EXTERNAL_SYMBOL]);
11860 -- Processing for this pragma is shared with Psect_Object
11862 ------------------------
11863 -- Compile_Time_Error --
11864 ------------------------
11866 -- pragma Compile_Time_Error
11867 -- (boolean_EXPRESSION, static_string_EXPRESSION);
11869 when Pragma_Compile_Time_Error =>
11870 GNAT_Pragma;
11871 Process_Compile_Time_Warning_Or_Error;
11873 --------------------------
11874 -- Compile_Time_Warning --
11875 --------------------------
11877 -- pragma Compile_Time_Warning
11878 -- (boolean_EXPRESSION, static_string_EXPRESSION);
11880 when Pragma_Compile_Time_Warning =>
11881 GNAT_Pragma;
11882 Process_Compile_Time_Warning_Or_Error;
11884 ---------------------------
11885 -- Compiler_Unit_Warning --
11886 ---------------------------
11888 -- pragma Compiler_Unit_Warning;
11890 -- Historical note
11892 -- Originally, we had only pragma Compiler_Unit, and it resulted in
11893 -- errors not warnings. This means that we had introduced a big extra
11894 -- inertia to compiler changes, since even if we implemented a new
11895 -- feature, and even if all versions to be used for bootstrapping
11896 -- implemented this new feature, we could not use it, since old
11897 -- compilers would give errors for using this feature in units
11898 -- having Compiler_Unit pragmas.
11900 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
11901 -- problem. We no longer have any units mentioning Compiler_Unit,
11902 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
11903 -- and thus generates a warning which can be ignored. So that deals
11904 -- with the problem of old compilers not implementing the newer form
11905 -- of the pragma.
11907 -- Newer compilers recognize the new pragma, but generate warning
11908 -- messages instead of errors, which again can be ignored in the
11909 -- case of an old compiler which implements a wanted new feature
11910 -- but at the time felt like warning about it for older compilers.
11912 -- We retain Compiler_Unit so that new compilers can be used to build
11913 -- older run-times that use this pragma. That's an unusual case, but
11914 -- it's easy enough to handle, so why not?
11916 when Pragma_Compiler_Unit | Pragma_Compiler_Unit_Warning =>
11917 GNAT_Pragma;
11918 Check_Arg_Count (0);
11920 -- Only recognized in main unit
11922 if Current_Sem_Unit = Main_Unit then
11923 Compiler_Unit := True;
11924 end if;
11926 -----------------------------
11927 -- Complete_Representation --
11928 -----------------------------
11930 -- pragma Complete_Representation;
11932 when Pragma_Complete_Representation =>
11933 GNAT_Pragma;
11934 Check_Arg_Count (0);
11936 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
11937 Error_Pragma
11938 ("pragma & must appear within record representation clause");
11939 end if;
11941 ----------------------------
11942 -- Complex_Representation --
11943 ----------------------------
11945 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
11947 when Pragma_Complex_Representation => Complex_Representation : declare
11948 E_Id : Entity_Id;
11949 E : Entity_Id;
11950 Ent : Entity_Id;
11952 begin
11953 GNAT_Pragma;
11954 Check_Arg_Count (1);
11955 Check_Optional_Identifier (Arg1, Name_Entity);
11956 Check_Arg_Is_Local_Name (Arg1);
11957 E_Id := Get_Pragma_Arg (Arg1);
11959 if Etype (E_Id) = Any_Type then
11960 return;
11961 end if;
11963 E := Entity (E_Id);
11965 if not Is_Record_Type (E) then
11966 Error_Pragma_Arg
11967 ("argument for pragma% must be record type", Arg1);
11968 end if;
11970 Ent := First_Entity (E);
11972 if No (Ent)
11973 or else No (Next_Entity (Ent))
11974 or else Present (Next_Entity (Next_Entity (Ent)))
11975 or else not Is_Floating_Point_Type (Etype (Ent))
11976 or else Etype (Ent) /= Etype (Next_Entity (Ent))
11977 then
11978 Error_Pragma_Arg
11979 ("record for pragma% must have two fields of the same "
11980 & "floating-point type", Arg1);
11982 else
11983 Set_Has_Complex_Representation (Base_Type (E));
11985 -- We need to treat the type has having a non-standard
11986 -- representation, for back-end purposes, even though in
11987 -- general a complex will have the default representation
11988 -- of a record with two real components.
11990 Set_Has_Non_Standard_Rep (Base_Type (E));
11991 end if;
11992 end Complex_Representation;
11994 -------------------------
11995 -- Component_Alignment --
11996 -------------------------
11998 -- pragma Component_Alignment (
11999 -- [Form =>] ALIGNMENT_CHOICE
12000 -- [, [Name =>] type_LOCAL_NAME]);
12002 -- ALIGNMENT_CHOICE ::=
12003 -- Component_Size
12004 -- | Component_Size_4
12005 -- | Storage_Unit
12006 -- | Default
12008 when Pragma_Component_Alignment => Component_AlignmentP : declare
12009 Args : Args_List (1 .. 2);
12010 Names : constant Name_List (1 .. 2) := (
12011 Name_Form,
12012 Name_Name);
12014 Form : Node_Id renames Args (1);
12015 Name : Node_Id renames Args (2);
12017 Atype : Component_Alignment_Kind;
12018 Typ : Entity_Id;
12020 begin
12021 GNAT_Pragma;
12022 Gather_Associations (Names, Args);
12024 if No (Form) then
12025 Error_Pragma ("missing Form argument for pragma%");
12026 end if;
12028 Check_Arg_Is_Identifier (Form);
12030 -- Get proper alignment, note that Default = Component_Size on all
12031 -- machines we have so far, and we want to set this value rather
12032 -- than the default value to indicate that it has been explicitly
12033 -- set (and thus will not get overridden by the default component
12034 -- alignment for the current scope)
12036 if Chars (Form) = Name_Component_Size then
12037 Atype := Calign_Component_Size;
12039 elsif Chars (Form) = Name_Component_Size_4 then
12040 Atype := Calign_Component_Size_4;
12042 elsif Chars (Form) = Name_Default then
12043 Atype := Calign_Component_Size;
12045 elsif Chars (Form) = Name_Storage_Unit then
12046 Atype := Calign_Storage_Unit;
12048 else
12049 Error_Pragma_Arg
12050 ("invalid Form parameter for pragma%", Form);
12051 end if;
12053 -- Case with no name, supplied, affects scope table entry
12055 if No (Name) then
12056 Scope_Stack.Table
12057 (Scope_Stack.Last).Component_Alignment_Default := Atype;
12059 -- Case of name supplied
12061 else
12062 Check_Arg_Is_Local_Name (Name);
12063 Find_Type (Name);
12064 Typ := Entity (Name);
12066 if Typ = Any_Type
12067 or else Rep_Item_Too_Early (Typ, N)
12068 then
12069 return;
12070 else
12071 Typ := Underlying_Type (Typ);
12072 end if;
12074 if not Is_Record_Type (Typ)
12075 and then not Is_Array_Type (Typ)
12076 then
12077 Error_Pragma_Arg
12078 ("Name parameter of pragma% must identify record or "
12079 & "array type", Name);
12080 end if;
12082 -- An explicit Component_Alignment pragma overrides an
12083 -- implicit pragma Pack, but not an explicit one.
12085 if not Has_Pragma_Pack (Base_Type (Typ)) then
12086 Set_Is_Packed (Base_Type (Typ), False);
12087 Set_Component_Alignment (Base_Type (Typ), Atype);
12088 end if;
12089 end if;
12090 end Component_AlignmentP;
12092 --------------------
12093 -- Contract_Cases --
12094 --------------------
12096 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
12098 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
12100 -- CASE_GUARD ::= boolean_EXPRESSION | others
12102 -- CONSEQUENCE ::= boolean_EXPRESSION
12104 -- Characteristics:
12106 -- * Analysis - The annotation undergoes initial checks to verify
12107 -- the legal placement and context. Secondary checks preanalyze the
12108 -- expressions in:
12110 -- Analyze_Contract_Cases_In_Decl_Part
12112 -- * Expansion - The annotation is expanded during the expansion of
12113 -- the related subprogram [body] contract as performed in:
12115 -- Expand_Subprogram_Contract
12117 -- * Template - The annotation utilizes the generic template of the
12118 -- related subprogram [body] when it is:
12120 -- aspect on subprogram declaration
12121 -- aspect on stand alone subprogram body
12122 -- pragma on stand alone subprogram body
12124 -- The annotation must prepare its own template when it is:
12126 -- pragma on subprogram declaration
12128 -- * Globals - Capture of global references must occur after full
12129 -- analysis.
12131 -- * Instance - The annotation is instantiated automatically when
12132 -- the related generic subprogram [body] is instantiated except for
12133 -- the "pragma on subprogram declaration" case. In that scenario
12134 -- the annotation must instantiate itself.
12136 when Pragma_Contract_Cases => Contract_Cases : declare
12137 Spec_Id : Entity_Id;
12138 Subp_Decl : Node_Id;
12140 begin
12141 GNAT_Pragma;
12142 Check_No_Identifiers;
12143 Check_Arg_Count (1);
12145 -- The pragma is analyzed at the end of the declarative part which
12146 -- contains the related subprogram. Reset the analyzed flag.
12148 Set_Analyzed (N, False);
12150 -- Ensure the proper placement of the pragma. Contract_Cases must
12151 -- be associated with a subprogram declaration or a body that acts
12152 -- as a spec.
12154 Subp_Decl :=
12155 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
12157 -- Generic subprogram
12159 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
12160 null;
12162 -- Body acts as spec
12164 elsif Nkind (Subp_Decl) = N_Subprogram_Body
12165 and then No (Corresponding_Spec (Subp_Decl))
12166 then
12167 null;
12169 -- Body stub acts as spec
12171 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
12172 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
12173 then
12174 null;
12176 -- Subprogram
12178 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
12179 null;
12181 else
12182 Pragma_Misplaced;
12183 return;
12184 end if;
12186 Spec_Id := Corresponding_Spec_Of (Subp_Decl);
12188 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
12190 -- Fully analyze the pragma when it appears inside a subprogram
12191 -- body because it cannot benefit from forward references.
12193 if Nkind (Subp_Decl) = N_Subprogram_Body then
12194 Analyze_Contract_Cases_In_Decl_Part (N);
12195 end if;
12197 -- Chain the pragma on the contract for further processing by
12198 -- Analyze_Contract_Cases_In_Decl_Part.
12200 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
12201 end Contract_Cases;
12203 ----------------
12204 -- Controlled --
12205 ----------------
12207 -- pragma Controlled (first_subtype_LOCAL_NAME);
12209 when Pragma_Controlled => Controlled : declare
12210 Arg : Node_Id;
12212 begin
12213 Check_No_Identifiers;
12214 Check_Arg_Count (1);
12215 Check_Arg_Is_Local_Name (Arg1);
12216 Arg := Get_Pragma_Arg (Arg1);
12218 if not Is_Entity_Name (Arg)
12219 or else not Is_Access_Type (Entity (Arg))
12220 then
12221 Error_Pragma_Arg ("pragma% requires access type", Arg1);
12222 else
12223 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
12224 end if;
12225 end Controlled;
12227 ----------------
12228 -- Convention --
12229 ----------------
12231 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
12232 -- [Entity =>] LOCAL_NAME);
12234 when Pragma_Convention => Convention : declare
12235 C : Convention_Id;
12236 E : Entity_Id;
12237 pragma Warnings (Off, C);
12238 pragma Warnings (Off, E);
12239 begin
12240 Check_Arg_Order ((Name_Convention, Name_Entity));
12241 Check_Ada_83_Warning;
12242 Check_Arg_Count (2);
12243 Process_Convention (C, E);
12244 end Convention;
12246 ---------------------------
12247 -- Convention_Identifier --
12248 ---------------------------
12250 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
12251 -- [Convention =>] convention_IDENTIFIER);
12253 when Pragma_Convention_Identifier => Convention_Identifier : declare
12254 Idnam : Name_Id;
12255 Cname : Name_Id;
12257 begin
12258 GNAT_Pragma;
12259 Check_Arg_Order ((Name_Name, Name_Convention));
12260 Check_Arg_Count (2);
12261 Check_Optional_Identifier (Arg1, Name_Name);
12262 Check_Optional_Identifier (Arg2, Name_Convention);
12263 Check_Arg_Is_Identifier (Arg1);
12264 Check_Arg_Is_Identifier (Arg2);
12265 Idnam := Chars (Get_Pragma_Arg (Arg1));
12266 Cname := Chars (Get_Pragma_Arg (Arg2));
12268 if Is_Convention_Name (Cname) then
12269 Record_Convention_Identifier
12270 (Idnam, Get_Convention_Id (Cname));
12271 else
12272 Error_Pragma_Arg
12273 ("second arg for % pragma must be convention", Arg2);
12274 end if;
12275 end Convention_Identifier;
12277 ---------------
12278 -- CPP_Class --
12279 ---------------
12281 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
12283 when Pragma_CPP_Class => CPP_Class : declare
12284 begin
12285 GNAT_Pragma;
12287 if Warn_On_Obsolescent_Feature then
12288 Error_Msg_N
12289 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
12290 & "effect; replace it by pragma import?j?", N);
12291 end if;
12293 Check_Arg_Count (1);
12295 Rewrite (N,
12296 Make_Pragma (Loc,
12297 Chars => Name_Import,
12298 Pragma_Argument_Associations => New_List (
12299 Make_Pragma_Argument_Association (Loc,
12300 Expression => Make_Identifier (Loc, Name_CPP)),
12301 New_Copy (First (Pragma_Argument_Associations (N))))));
12302 Analyze (N);
12303 end CPP_Class;
12305 ---------------------
12306 -- CPP_Constructor --
12307 ---------------------
12309 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
12310 -- [, [External_Name =>] static_string_EXPRESSION ]
12311 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12313 when Pragma_CPP_Constructor => CPP_Constructor : declare
12314 Elmt : Elmt_Id;
12315 Id : Entity_Id;
12316 Def_Id : Entity_Id;
12317 Tag_Typ : Entity_Id;
12319 begin
12320 GNAT_Pragma;
12321 Check_At_Least_N_Arguments (1);
12322 Check_At_Most_N_Arguments (3);
12323 Check_Optional_Identifier (Arg1, Name_Entity);
12324 Check_Arg_Is_Local_Name (Arg1);
12326 Id := Get_Pragma_Arg (Arg1);
12327 Find_Program_Unit_Name (Id);
12329 -- If we did not find the name, we are done
12331 if Etype (Id) = Any_Type then
12332 return;
12333 end if;
12335 Def_Id := Entity (Id);
12337 -- Check if already defined as constructor
12339 if Is_Constructor (Def_Id) then
12340 Error_Msg_N
12341 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
12342 return;
12343 end if;
12345 if Ekind (Def_Id) = E_Function
12346 and then (Is_CPP_Class (Etype (Def_Id))
12347 or else (Is_Class_Wide_Type (Etype (Def_Id))
12348 and then
12349 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
12350 then
12351 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
12352 Error_Msg_N
12353 ("'C'P'P constructor must be defined in the scope of "
12354 & "its returned type", Arg1);
12355 end if;
12357 if Arg_Count >= 2 then
12358 Set_Imported (Def_Id);
12359 Set_Is_Public (Def_Id);
12360 Process_Interface_Name (Def_Id, Arg2, Arg3);
12361 end if;
12363 Set_Has_Completion (Def_Id);
12364 Set_Is_Constructor (Def_Id);
12365 Set_Convention (Def_Id, Convention_CPP);
12367 -- Imported C++ constructors are not dispatching primitives
12368 -- because in C++ they don't have a dispatch table slot.
12369 -- However, in Ada the constructor has the profile of a
12370 -- function that returns a tagged type and therefore it has
12371 -- been treated as a primitive operation during semantic
12372 -- analysis. We now remove it from the list of primitive
12373 -- operations of the type.
12375 if Is_Tagged_Type (Etype (Def_Id))
12376 and then not Is_Class_Wide_Type (Etype (Def_Id))
12377 and then Is_Dispatching_Operation (Def_Id)
12378 then
12379 Tag_Typ := Etype (Def_Id);
12381 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
12382 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
12383 Next_Elmt (Elmt);
12384 end loop;
12386 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
12387 Set_Is_Dispatching_Operation (Def_Id, False);
12388 end if;
12390 -- For backward compatibility, if the constructor returns a
12391 -- class wide type, and we internally change the return type to
12392 -- the corresponding root type.
12394 if Is_Class_Wide_Type (Etype (Def_Id)) then
12395 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
12396 end if;
12397 else
12398 Error_Pragma_Arg
12399 ("pragma% requires function returning a 'C'P'P_Class type",
12400 Arg1);
12401 end if;
12402 end CPP_Constructor;
12404 -----------------
12405 -- CPP_Virtual --
12406 -----------------
12408 when Pragma_CPP_Virtual => CPP_Virtual : declare
12409 begin
12410 GNAT_Pragma;
12412 if Warn_On_Obsolescent_Feature then
12413 Error_Msg_N
12414 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
12415 & "effect?j?", N);
12416 end if;
12417 end CPP_Virtual;
12419 ----------------
12420 -- CPP_Vtable --
12421 ----------------
12423 when Pragma_CPP_Vtable => CPP_Vtable : declare
12424 begin
12425 GNAT_Pragma;
12427 if Warn_On_Obsolescent_Feature then
12428 Error_Msg_N
12429 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
12430 & "effect?j?", N);
12431 end if;
12432 end CPP_Vtable;
12434 ---------
12435 -- CPU --
12436 ---------
12438 -- pragma CPU (EXPRESSION);
12440 when Pragma_CPU => CPU : declare
12441 P : constant Node_Id := Parent (N);
12442 Arg : Node_Id;
12443 Ent : Entity_Id;
12445 begin
12446 Ada_2012_Pragma;
12447 Check_No_Identifiers;
12448 Check_Arg_Count (1);
12450 -- Subprogram case
12452 if Nkind (P) = N_Subprogram_Body then
12453 Check_In_Main_Program;
12455 Arg := Get_Pragma_Arg (Arg1);
12456 Analyze_And_Resolve (Arg, Any_Integer);
12458 Ent := Defining_Unit_Name (Specification (P));
12460 if Nkind (Ent) = N_Defining_Program_Unit_Name then
12461 Ent := Defining_Identifier (Ent);
12462 end if;
12464 -- Must be static
12466 if not Is_OK_Static_Expression (Arg) then
12467 Flag_Non_Static_Expr
12468 ("main subprogram affinity is not static!", Arg);
12469 raise Pragma_Exit;
12471 -- If constraint error, then we already signalled an error
12473 elsif Raises_Constraint_Error (Arg) then
12474 null;
12476 -- Otherwise check in range
12478 else
12479 declare
12480 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
12481 -- This is the entity System.Multiprocessors.CPU_Range;
12483 Val : constant Uint := Expr_Value (Arg);
12485 begin
12486 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
12487 or else
12488 Val > Expr_Value (Type_High_Bound (CPU_Id))
12489 then
12490 Error_Pragma_Arg
12491 ("main subprogram CPU is out of range", Arg1);
12492 end if;
12493 end;
12494 end if;
12496 Set_Main_CPU
12497 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12499 -- Task case
12501 elsif Nkind (P) = N_Task_Definition then
12502 Arg := Get_Pragma_Arg (Arg1);
12503 Ent := Defining_Identifier (Parent (P));
12505 -- The expression must be analyzed in the special manner
12506 -- described in "Handling of Default and Per-Object
12507 -- Expressions" in sem.ads.
12509 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
12511 -- Anything else is incorrect
12513 else
12514 Pragma_Misplaced;
12515 end if;
12517 -- Check duplicate pragma before we chain the pragma in the Rep
12518 -- Item chain of Ent.
12520 Check_Duplicate_Pragma (Ent);
12521 Record_Rep_Item (Ent, N);
12522 end CPU;
12524 -----------
12525 -- Debug --
12526 -----------
12528 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
12530 when Pragma_Debug => Debug : declare
12531 Cond : Node_Id;
12532 Call : Node_Id;
12534 begin
12535 GNAT_Pragma;
12537 -- The condition for executing the call is that the expander
12538 -- is active and that we are not ignoring this debug pragma.
12540 Cond :=
12541 New_Occurrence_Of
12542 (Boolean_Literals
12543 (Expander_Active and then not Is_Ignored (N)),
12544 Loc);
12546 if not Is_Ignored (N) then
12547 Set_SCO_Pragma_Enabled (Loc);
12548 end if;
12550 if Arg_Count = 2 then
12551 Cond :=
12552 Make_And_Then (Loc,
12553 Left_Opnd => Relocate_Node (Cond),
12554 Right_Opnd => Get_Pragma_Arg (Arg1));
12555 Call := Get_Pragma_Arg (Arg2);
12556 else
12557 Call := Get_Pragma_Arg (Arg1);
12558 end if;
12560 if Nkind_In (Call,
12561 N_Indexed_Component,
12562 N_Function_Call,
12563 N_Identifier,
12564 N_Expanded_Name,
12565 N_Selected_Component)
12566 then
12567 -- If this pragma Debug comes from source, its argument was
12568 -- parsed as a name form (which is syntactically identical).
12569 -- In a generic context a parameterless call will be left as
12570 -- an expanded name (if global) or selected_component if local.
12571 -- Change it to a procedure call statement now.
12573 Change_Name_To_Procedure_Call_Statement (Call);
12575 elsif Nkind (Call) = N_Procedure_Call_Statement then
12577 -- Already in the form of a procedure call statement: nothing
12578 -- to do (could happen in case of an internally generated
12579 -- pragma Debug).
12581 null;
12583 else
12584 -- All other cases: diagnose error
12586 Error_Msg
12587 ("argument of pragma ""Debug"" is not procedure call",
12588 Sloc (Call));
12589 return;
12590 end if;
12592 -- Rewrite into a conditional with an appropriate condition. We
12593 -- wrap the procedure call in a block so that overhead from e.g.
12594 -- use of the secondary stack does not generate execution overhead
12595 -- for suppressed conditions.
12597 -- Normally the analysis that follows will freeze the subprogram
12598 -- being called. However, if the call is to a null procedure,
12599 -- we want to freeze it before creating the block, because the
12600 -- analysis that follows may be done with expansion disabled, in
12601 -- which case the body will not be generated, leading to spurious
12602 -- errors.
12604 if Nkind (Call) = N_Procedure_Call_Statement
12605 and then Is_Entity_Name (Name (Call))
12606 then
12607 Analyze (Name (Call));
12608 Freeze_Before (N, Entity (Name (Call)));
12609 end if;
12611 Rewrite (N,
12612 Make_Implicit_If_Statement (N,
12613 Condition => Cond,
12614 Then_Statements => New_List (
12615 Make_Block_Statement (Loc,
12616 Handled_Statement_Sequence =>
12617 Make_Handled_Sequence_Of_Statements (Loc,
12618 Statements => New_List (Relocate_Node (Call)))))));
12619 Analyze (N);
12621 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
12622 -- after analysis of the normally rewritten node, to capture all
12623 -- references to entities, which avoids issuing wrong warnings
12624 -- about unused entities.
12626 if GNATprove_Mode then
12627 Rewrite (N, Make_Null_Statement (Loc));
12628 end if;
12629 end Debug;
12631 ------------------
12632 -- Debug_Policy --
12633 ------------------
12635 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
12637 when Pragma_Debug_Policy =>
12638 GNAT_Pragma;
12639 Check_Arg_Count (1);
12640 Check_No_Identifiers;
12641 Check_Arg_Is_Identifier (Arg1);
12643 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
12644 -- rewrite it that way, and let the rest of the checking come
12645 -- from analyzing the rewritten pragma.
12647 Rewrite (N,
12648 Make_Pragma (Loc,
12649 Chars => Name_Check_Policy,
12650 Pragma_Argument_Associations => New_List (
12651 Make_Pragma_Argument_Association (Loc,
12652 Expression => Make_Identifier (Loc, Name_Debug)),
12654 Make_Pragma_Argument_Association (Loc,
12655 Expression => Get_Pragma_Arg (Arg1)))));
12656 Analyze (N);
12658 -------------------------------
12659 -- Default_Initial_Condition --
12660 -------------------------------
12662 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
12664 when Pragma_Default_Initial_Condition => Default_Init_Cond : declare
12665 Discard : Boolean;
12666 Stmt : Node_Id;
12667 Typ : Entity_Id;
12669 begin
12670 GNAT_Pragma;
12671 Check_No_Identifiers;
12672 Check_At_Most_N_Arguments (1);
12674 Stmt := Prev (N);
12675 while Present (Stmt) loop
12677 -- Skip prior pragmas, but check for duplicates
12679 if Nkind (Stmt) = N_Pragma then
12680 if Pragma_Name (Stmt) = Pname then
12681 Error_Msg_Name_1 := Pname;
12682 Error_Msg_Sloc := Sloc (Stmt);
12683 Error_Msg_N ("pragma % duplicates pragma declared#", N);
12684 end if;
12686 -- Skip internally generated code
12688 elsif not Comes_From_Source (Stmt) then
12689 null;
12691 -- The associated private type [extension] has been found, stop
12692 -- the search.
12694 elsif Nkind_In (Stmt, N_Private_Extension_Declaration,
12695 N_Private_Type_Declaration)
12696 then
12697 Typ := Defining_Entity (Stmt);
12698 exit;
12700 -- The pragma does not apply to a legal construct, issue an
12701 -- error and stop the analysis.
12703 else
12704 Pragma_Misplaced;
12705 return;
12706 end if;
12708 Stmt := Prev (Stmt);
12709 end loop;
12711 Set_Has_Default_Init_Cond (Typ);
12712 Set_Has_Inherited_Default_Init_Cond (Typ, False);
12714 -- Chain the pragma on the rep item chain for further processing
12716 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12717 end Default_Init_Cond;
12719 ----------------------------------
12720 -- Default_Scalar_Storage_Order --
12721 ----------------------------------
12723 -- pragma Default_Scalar_Storage_Order
12724 -- (High_Order_First | Low_Order_First);
12726 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
12727 Default : Character;
12729 begin
12730 GNAT_Pragma;
12731 Check_Arg_Count (1);
12733 -- Default_Scalar_Storage_Order can appear as a configuration
12734 -- pragma, or in a declarative part of a package spec.
12736 if not Is_Configuration_Pragma then
12737 Check_Is_In_Decl_Part_Or_Package_Spec;
12738 end if;
12740 Check_No_Identifiers;
12741 Check_Arg_Is_One_Of
12742 (Arg1, Name_High_Order_First, Name_Low_Order_First);
12743 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12744 Default := Fold_Upper (Name_Buffer (1));
12746 if not Support_Nondefault_SSO_On_Target
12747 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
12748 then
12749 if Warn_On_Unrecognized_Pragma then
12750 Error_Msg_N
12751 ("non-default Scalar_Storage_Order not supported "
12752 & "on target?g?", N);
12753 Error_Msg_N
12754 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
12755 end if;
12757 -- Here set the specified default
12759 else
12760 Opt.Default_SSO := Default;
12761 end if;
12762 end DSSO;
12764 --------------------------
12765 -- Default_Storage_Pool --
12766 --------------------------
12768 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
12770 when Pragma_Default_Storage_Pool =>
12771 Ada_2012_Pragma;
12772 Check_Arg_Count (1);
12774 -- Default_Storage_Pool can appear as a configuration pragma, or
12775 -- in a declarative part of a package spec.
12777 if not Is_Configuration_Pragma then
12778 Check_Is_In_Decl_Part_Or_Package_Spec;
12779 end if;
12781 -- Case of Default_Storage_Pool (null);
12783 if Nkind (Expression (Arg1)) = N_Null then
12784 Analyze (Expression (Arg1));
12786 -- This is an odd case, this is not really an expression, so
12787 -- we don't have a type for it. So just set the type to Empty.
12789 Set_Etype (Expression (Arg1), Empty);
12791 -- Case of Default_Storage_Pool (storage_pool_NAME);
12793 else
12794 -- If it's a configuration pragma, then the only allowed
12795 -- argument is "null".
12797 if Is_Configuration_Pragma then
12798 Error_Pragma_Arg ("NULL expected", Arg1);
12799 end if;
12801 -- The expected type for a non-"null" argument is
12802 -- Root_Storage_Pool'Class, and the pool must be a variable.
12804 Analyze_And_Resolve
12805 (Get_Pragma_Arg (Arg1),
12806 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
12808 if not Is_Variable (Expression (Arg1)) then
12809 Error_Pragma_Arg
12810 ("default storage pool must be a variable", Arg1);
12811 end if;
12812 end if;
12814 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
12815 -- for an access type will use this information to set the
12816 -- appropriate attributes of the access type.
12818 Default_Pool := Expression (Arg1);
12820 -------------
12821 -- Depends --
12822 -------------
12824 -- pragma Depends (DEPENDENCY_RELATION);
12826 -- DEPENDENCY_RELATION ::=
12827 -- null
12828 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
12830 -- DEPENDENCY_CLAUSE ::=
12831 -- OUTPUT_LIST =>[+] INPUT_LIST
12832 -- | NULL_DEPENDENCY_CLAUSE
12834 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
12836 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
12838 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
12840 -- OUTPUT ::= NAME | FUNCTION_RESULT
12841 -- INPUT ::= NAME
12843 -- where FUNCTION_RESULT is a function Result attribute_reference
12845 -- Characteristics:
12847 -- * Analysis - The annotation undergoes initial checks to verify
12848 -- the legal placement and context. Secondary checks fully analyze
12849 -- the dependency clauses in:
12851 -- Analyze_Depends_In_Decl_Part
12853 -- * Expansion - None.
12855 -- * Template - The annotation utilizes the generic template of the
12856 -- related subprogram [body] when it is:
12858 -- aspect on subprogram declaration
12859 -- aspect on stand alone subprogram body
12860 -- pragma on stand alone subprogram body
12862 -- The annotation must prepare its own template when it is:
12864 -- pragma on subprogram declaration
12866 -- * Globals - Capture of global references must occur after full
12867 -- analysis.
12869 -- * Instance - The annotation is instantiated automatically when
12870 -- the related generic subprogram [body] is instantiated except for
12871 -- the "pragma on subprogram declaration" case. In that scenario
12872 -- the annotation must instantiate itself.
12874 when Pragma_Depends =>
12875 Analyze_Depends_Global;
12877 ---------------------
12878 -- Detect_Blocking --
12879 ---------------------
12881 -- pragma Detect_Blocking;
12883 when Pragma_Detect_Blocking =>
12884 Ada_2005_Pragma;
12885 Check_Arg_Count (0);
12886 Check_Valid_Configuration_Pragma;
12887 Detect_Blocking := True;
12889 ------------------------------------
12890 -- Disable_Atomic_Synchronization --
12891 ------------------------------------
12893 -- pragma Disable_Atomic_Synchronization [(Entity)];
12895 when Pragma_Disable_Atomic_Synchronization =>
12896 GNAT_Pragma;
12897 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
12899 -------------------
12900 -- Discard_Names --
12901 -------------------
12903 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
12905 when Pragma_Discard_Names => Discard_Names : declare
12906 E : Entity_Id;
12907 E_Id : Entity_Id;
12909 begin
12910 Check_Ada_83_Warning;
12912 -- Deal with configuration pragma case
12914 if Arg_Count = 0 and then Is_Configuration_Pragma then
12915 Global_Discard_Names := True;
12916 return;
12918 -- Otherwise, check correct appropriate context
12920 else
12921 Check_Is_In_Decl_Part_Or_Package_Spec;
12923 if Arg_Count = 0 then
12925 -- If there is no parameter, then from now on this pragma
12926 -- applies to any enumeration, exception or tagged type
12927 -- defined in the current declarative part, and recursively
12928 -- to any nested scope.
12930 Set_Discard_Names (Current_Scope);
12931 return;
12933 else
12934 Check_Arg_Count (1);
12935 Check_Optional_Identifier (Arg1, Name_On);
12936 Check_Arg_Is_Local_Name (Arg1);
12938 E_Id := Get_Pragma_Arg (Arg1);
12940 if Etype (E_Id) = Any_Type then
12941 return;
12942 else
12943 E := Entity (E_Id);
12944 end if;
12946 if (Is_First_Subtype (E)
12947 and then
12948 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
12949 or else Ekind (E) = E_Exception
12950 then
12951 Set_Discard_Names (E);
12952 Record_Rep_Item (E, N);
12954 else
12955 Error_Pragma_Arg
12956 ("inappropriate entity for pragma%", Arg1);
12957 end if;
12959 end if;
12960 end if;
12961 end Discard_Names;
12963 ------------------------
12964 -- Dispatching_Domain --
12965 ------------------------
12967 -- pragma Dispatching_Domain (EXPRESSION);
12969 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
12970 P : constant Node_Id := Parent (N);
12971 Arg : Node_Id;
12972 Ent : Entity_Id;
12974 begin
12975 Ada_2012_Pragma;
12976 Check_No_Identifiers;
12977 Check_Arg_Count (1);
12979 -- This pragma is born obsolete, but not the aspect
12981 if not From_Aspect_Specification (N) then
12982 Check_Restriction
12983 (No_Obsolescent_Features, Pragma_Identifier (N));
12984 end if;
12986 if Nkind (P) = N_Task_Definition then
12987 Arg := Get_Pragma_Arg (Arg1);
12988 Ent := Defining_Identifier (Parent (P));
12990 -- The expression must be analyzed in the special manner
12991 -- described in "Handling of Default and Per-Object
12992 -- Expressions" in sem.ads.
12994 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
12996 -- Check duplicate pragma before we chain the pragma in the Rep
12997 -- Item chain of Ent.
12999 Check_Duplicate_Pragma (Ent);
13000 Record_Rep_Item (Ent, N);
13002 -- Anything else is incorrect
13004 else
13005 Pragma_Misplaced;
13006 end if;
13007 end Dispatching_Domain;
13009 ---------------
13010 -- Elaborate --
13011 ---------------
13013 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
13015 when Pragma_Elaborate => Elaborate : declare
13016 Arg : Node_Id;
13017 Citem : Node_Id;
13019 begin
13020 -- Pragma must be in context items list of a compilation unit
13022 if not Is_In_Context_Clause then
13023 Pragma_Misplaced;
13024 end if;
13026 -- Must be at least one argument
13028 if Arg_Count = 0 then
13029 Error_Pragma ("pragma% requires at least one argument");
13030 end if;
13032 -- In Ada 83 mode, there can be no items following it in the
13033 -- context list except other pragmas and implicit with clauses
13034 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
13035 -- placement rule does not apply.
13037 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
13038 Citem := Next (N);
13039 while Present (Citem) loop
13040 if Nkind (Citem) = N_Pragma
13041 or else (Nkind (Citem) = N_With_Clause
13042 and then Implicit_With (Citem))
13043 then
13044 null;
13045 else
13046 Error_Pragma
13047 ("(Ada 83) pragma% must be at end of context clause");
13048 end if;
13050 Next (Citem);
13051 end loop;
13052 end if;
13054 -- Finally, the arguments must all be units mentioned in a with
13055 -- clause in the same context clause. Note we already checked (in
13056 -- Par.Prag) that the arguments are all identifiers or selected
13057 -- components.
13059 Arg := Arg1;
13060 Outer : while Present (Arg) loop
13061 Citem := First (List_Containing (N));
13062 Inner : while Citem /= N loop
13063 if Nkind (Citem) = N_With_Clause
13064 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
13065 then
13066 Set_Elaborate_Present (Citem, True);
13067 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
13069 -- With the pragma present, elaboration calls on
13070 -- subprograms from the named unit need no further
13071 -- checks, as long as the pragma appears in the current
13072 -- compilation unit. If the pragma appears in some unit
13073 -- in the context, there might still be a need for an
13074 -- Elaborate_All_Desirable from the current compilation
13075 -- to the named unit, so we keep the check enabled.
13077 if In_Extended_Main_Source_Unit (N) then
13079 -- This does not apply in SPARK mode, where we allow
13080 -- pragma Elaborate, but we don't trust it to be right
13081 -- so we will still insist on the Elaborate_All.
13083 if SPARK_Mode /= On then
13084 Set_Suppress_Elaboration_Warnings
13085 (Entity (Name (Citem)));
13086 end if;
13087 end if;
13089 exit Inner;
13090 end if;
13092 Next (Citem);
13093 end loop Inner;
13095 if Citem = N then
13096 Error_Pragma_Arg
13097 ("argument of pragma% is not withed unit", Arg);
13098 end if;
13100 Next (Arg);
13101 end loop Outer;
13103 -- Give a warning if operating in static mode with one of the
13104 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set.
13106 if Elab_Warnings
13107 and not Dynamic_Elaboration_Checks
13109 -- pragma Elaborate not allowed in SPARK mode anyway. We
13110 -- already complained about it, no point in generating any
13111 -- further complaint.
13113 and SPARK_Mode /= On
13114 then
13115 Error_Msg_N
13116 ("?l?use of pragma Elaborate may not be safe", N);
13117 Error_Msg_N
13118 ("?l?use pragma Elaborate_All instead if possible", N);
13119 end if;
13120 end Elaborate;
13122 -------------------
13123 -- Elaborate_All --
13124 -------------------
13126 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
13128 when Pragma_Elaborate_All => Elaborate_All : declare
13129 Arg : Node_Id;
13130 Citem : Node_Id;
13132 begin
13133 Check_Ada_83_Warning;
13135 -- Pragma must be in context items list of a compilation unit
13137 if not Is_In_Context_Clause then
13138 Pragma_Misplaced;
13139 end if;
13141 -- Must be at least one argument
13143 if Arg_Count = 0 then
13144 Error_Pragma ("pragma% requires at least one argument");
13145 end if;
13147 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
13148 -- have to appear at the end of the context clause, but may
13149 -- appear mixed in with other items, even in Ada 83 mode.
13151 -- Final check: the arguments must all be units mentioned in
13152 -- a with clause in the same context clause. Note that we
13153 -- already checked (in Par.Prag) that all the arguments are
13154 -- either identifiers or selected components.
13156 Arg := Arg1;
13157 Outr : while Present (Arg) loop
13158 Citem := First (List_Containing (N));
13159 Innr : while Citem /= N loop
13160 if Nkind (Citem) = N_With_Clause
13161 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
13162 then
13163 Set_Elaborate_All_Present (Citem, True);
13164 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
13166 -- Suppress warnings and elaboration checks on the named
13167 -- unit if the pragma is in the current compilation, as
13168 -- for pragma Elaborate.
13170 if In_Extended_Main_Source_Unit (N) then
13171 Set_Suppress_Elaboration_Warnings
13172 (Entity (Name (Citem)));
13173 end if;
13174 exit Innr;
13175 end if;
13177 Next (Citem);
13178 end loop Innr;
13180 if Citem = N then
13181 Set_Error_Posted (N);
13182 Error_Pragma_Arg
13183 ("argument of pragma% is not withed unit", Arg);
13184 end if;
13186 Next (Arg);
13187 end loop Outr;
13188 end Elaborate_All;
13190 --------------------
13191 -- Elaborate_Body --
13192 --------------------
13194 -- pragma Elaborate_Body [( library_unit_NAME )];
13196 when Pragma_Elaborate_Body => Elaborate_Body : declare
13197 Cunit_Node : Node_Id;
13198 Cunit_Ent : Entity_Id;
13200 begin
13201 Check_Ada_83_Warning;
13202 Check_Valid_Library_Unit_Pragma;
13204 if Nkind (N) = N_Null_Statement then
13205 return;
13206 end if;
13208 Cunit_Node := Cunit (Current_Sem_Unit);
13209 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13211 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
13212 N_Subprogram_Body)
13213 then
13214 Error_Pragma ("pragma% must refer to a spec, not a body");
13215 else
13216 Set_Body_Required (Cunit_Node, True);
13217 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
13219 -- If we are in dynamic elaboration mode, then we suppress
13220 -- elaboration warnings for the unit, since it is definitely
13221 -- fine NOT to do dynamic checks at the first level (and such
13222 -- checks will be suppressed because no elaboration boolean
13223 -- is created for Elaborate_Body packages).
13225 -- But in the static model of elaboration, Elaborate_Body is
13226 -- definitely NOT good enough to ensure elaboration safety on
13227 -- its own, since the body may WITH other units that are not
13228 -- safe from an elaboration point of view, so a client must
13229 -- still do an Elaborate_All on such units.
13231 -- Debug flag -gnatdD restores the old behavior of 3.13, where
13232 -- Elaborate_Body always suppressed elab warnings.
13234 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
13235 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
13236 end if;
13237 end if;
13238 end Elaborate_Body;
13240 ------------------------
13241 -- Elaboration_Checks --
13242 ------------------------
13244 -- pragma Elaboration_Checks (Static | Dynamic);
13246 when Pragma_Elaboration_Checks =>
13247 GNAT_Pragma;
13248 Check_Arg_Count (1);
13249 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
13251 -- Set flag accordingly (ignore attempt at dynamic elaboration
13252 -- checks in SPARK mode).
13254 Dynamic_Elaboration_Checks :=
13255 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic)
13256 and then SPARK_Mode /= On;
13258 ---------------
13259 -- Eliminate --
13260 ---------------
13262 -- pragma Eliminate (
13263 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
13264 -- [,[Entity =>] IDENTIFIER |
13265 -- SELECTED_COMPONENT |
13266 -- STRING_LITERAL]
13267 -- [, OVERLOADING_RESOLUTION]);
13269 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
13270 -- SOURCE_LOCATION
13272 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
13273 -- FUNCTION_PROFILE
13275 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
13277 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
13278 -- Result_Type => result_SUBTYPE_NAME]
13280 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
13281 -- SUBTYPE_NAME ::= STRING_LITERAL
13283 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
13284 -- SOURCE_TRACE ::= STRING_LITERAL
13286 when Pragma_Eliminate => Eliminate : declare
13287 Args : Args_List (1 .. 5);
13288 Names : constant Name_List (1 .. 5) := (
13289 Name_Unit_Name,
13290 Name_Entity,
13291 Name_Parameter_Types,
13292 Name_Result_Type,
13293 Name_Source_Location);
13295 Unit_Name : Node_Id renames Args (1);
13296 Entity : Node_Id renames Args (2);
13297 Parameter_Types : Node_Id renames Args (3);
13298 Result_Type : Node_Id renames Args (4);
13299 Source_Location : Node_Id renames Args (5);
13301 begin
13302 GNAT_Pragma;
13303 Check_Valid_Configuration_Pragma;
13304 Gather_Associations (Names, Args);
13306 if No (Unit_Name) then
13307 Error_Pragma ("missing Unit_Name argument for pragma%");
13308 end if;
13310 if No (Entity)
13311 and then (Present (Parameter_Types)
13312 or else
13313 Present (Result_Type)
13314 or else
13315 Present (Source_Location))
13316 then
13317 Error_Pragma ("missing Entity argument for pragma%");
13318 end if;
13320 if (Present (Parameter_Types)
13321 or else
13322 Present (Result_Type))
13323 and then
13324 Present (Source_Location)
13325 then
13326 Error_Pragma
13327 ("parameter profile and source location cannot be used "
13328 & "together in pragma%");
13329 end if;
13331 Process_Eliminate_Pragma
13333 Unit_Name,
13334 Entity,
13335 Parameter_Types,
13336 Result_Type,
13337 Source_Location);
13338 end Eliminate;
13340 -----------------------------------
13341 -- Enable_Atomic_Synchronization --
13342 -----------------------------------
13344 -- pragma Enable_Atomic_Synchronization [(Entity)];
13346 when Pragma_Enable_Atomic_Synchronization =>
13347 GNAT_Pragma;
13348 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
13350 ------------
13351 -- Export --
13352 ------------
13354 -- pragma Export (
13355 -- [ Convention =>] convention_IDENTIFIER,
13356 -- [ Entity =>] LOCAL_NAME
13357 -- [, [External_Name =>] static_string_EXPRESSION ]
13358 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13360 when Pragma_Export => Export : declare
13361 C : Convention_Id;
13362 Def_Id : Entity_Id;
13364 pragma Warnings (Off, C);
13366 begin
13367 Check_Ada_83_Warning;
13368 Check_Arg_Order
13369 ((Name_Convention,
13370 Name_Entity,
13371 Name_External_Name,
13372 Name_Link_Name));
13374 Check_At_Least_N_Arguments (2);
13375 Check_At_Most_N_Arguments (4);
13377 -- In Relaxed_RM_Semantics, support old Ada 83 style:
13378 -- pragma Export (Entity, "external name");
13380 if Relaxed_RM_Semantics
13381 and then Arg_Count = 2
13382 and then Nkind (Expression (Arg2)) = N_String_Literal
13383 then
13384 C := Convention_C;
13385 Def_Id := Get_Pragma_Arg (Arg1);
13386 Analyze (Def_Id);
13388 if not Is_Entity_Name (Def_Id) then
13389 Error_Pragma_Arg ("entity name required", Arg1);
13390 end if;
13392 Def_Id := Entity (Def_Id);
13393 Set_Exported (Def_Id, Arg1);
13395 else
13396 Process_Convention (C, Def_Id);
13398 if Ekind (Def_Id) /= E_Constant then
13399 Note_Possible_Modification
13400 (Get_Pragma_Arg (Arg2), Sure => False);
13401 end if;
13403 Process_Interface_Name (Def_Id, Arg3, Arg4);
13404 Set_Exported (Def_Id, Arg2);
13405 end if;
13407 -- If the entity is a deferred constant, propagate the information
13408 -- to the full view, because gigi elaborates the full view only.
13410 if Ekind (Def_Id) = E_Constant
13411 and then Present (Full_View (Def_Id))
13412 then
13413 declare
13414 Id2 : constant Entity_Id := Full_View (Def_Id);
13415 begin
13416 Set_Is_Exported (Id2, Is_Exported (Def_Id));
13417 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
13418 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
13419 end;
13420 end if;
13421 end Export;
13423 ---------------------
13424 -- Export_Function --
13425 ---------------------
13427 -- pragma Export_Function (
13428 -- [Internal =>] LOCAL_NAME
13429 -- [, [External =>] EXTERNAL_SYMBOL]
13430 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13431 -- [, [Result_Type =>] TYPE_DESIGNATOR]
13432 -- [, [Mechanism =>] MECHANISM]
13433 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
13435 -- EXTERNAL_SYMBOL ::=
13436 -- IDENTIFIER
13437 -- | static_string_EXPRESSION
13439 -- PARAMETER_TYPES ::=
13440 -- null
13441 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13443 -- TYPE_DESIGNATOR ::=
13444 -- subtype_NAME
13445 -- | subtype_Name ' Access
13447 -- MECHANISM ::=
13448 -- MECHANISM_NAME
13449 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13451 -- MECHANISM_ASSOCIATION ::=
13452 -- [formal_parameter_NAME =>] MECHANISM_NAME
13454 -- MECHANISM_NAME ::=
13455 -- Value
13456 -- | Reference
13458 when Pragma_Export_Function => Export_Function : declare
13459 Args : Args_List (1 .. 6);
13460 Names : constant Name_List (1 .. 6) := (
13461 Name_Internal,
13462 Name_External,
13463 Name_Parameter_Types,
13464 Name_Result_Type,
13465 Name_Mechanism,
13466 Name_Result_Mechanism);
13468 Internal : Node_Id renames Args (1);
13469 External : Node_Id renames Args (2);
13470 Parameter_Types : Node_Id renames Args (3);
13471 Result_Type : Node_Id renames Args (4);
13472 Mechanism : Node_Id renames Args (5);
13473 Result_Mechanism : Node_Id renames Args (6);
13475 begin
13476 GNAT_Pragma;
13477 Gather_Associations (Names, Args);
13478 Process_Extended_Import_Export_Subprogram_Pragma (
13479 Arg_Internal => Internal,
13480 Arg_External => External,
13481 Arg_Parameter_Types => Parameter_Types,
13482 Arg_Result_Type => Result_Type,
13483 Arg_Mechanism => Mechanism,
13484 Arg_Result_Mechanism => Result_Mechanism);
13485 end Export_Function;
13487 -------------------
13488 -- Export_Object --
13489 -------------------
13491 -- pragma Export_Object (
13492 -- [Internal =>] LOCAL_NAME
13493 -- [, [External =>] EXTERNAL_SYMBOL]
13494 -- [, [Size =>] EXTERNAL_SYMBOL]);
13496 -- EXTERNAL_SYMBOL ::=
13497 -- IDENTIFIER
13498 -- | static_string_EXPRESSION
13500 -- PARAMETER_TYPES ::=
13501 -- null
13502 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13504 -- TYPE_DESIGNATOR ::=
13505 -- subtype_NAME
13506 -- | subtype_Name ' Access
13508 -- MECHANISM ::=
13509 -- MECHANISM_NAME
13510 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13512 -- MECHANISM_ASSOCIATION ::=
13513 -- [formal_parameter_NAME =>] MECHANISM_NAME
13515 -- MECHANISM_NAME ::=
13516 -- Value
13517 -- | Reference
13519 when Pragma_Export_Object => Export_Object : declare
13520 Args : Args_List (1 .. 3);
13521 Names : constant Name_List (1 .. 3) := (
13522 Name_Internal,
13523 Name_External,
13524 Name_Size);
13526 Internal : Node_Id renames Args (1);
13527 External : Node_Id renames Args (2);
13528 Size : Node_Id renames Args (3);
13530 begin
13531 GNAT_Pragma;
13532 Gather_Associations (Names, Args);
13533 Process_Extended_Import_Export_Object_Pragma (
13534 Arg_Internal => Internal,
13535 Arg_External => External,
13536 Arg_Size => Size);
13537 end Export_Object;
13539 ----------------------
13540 -- Export_Procedure --
13541 ----------------------
13543 -- pragma Export_Procedure (
13544 -- [Internal =>] LOCAL_NAME
13545 -- [, [External =>] EXTERNAL_SYMBOL]
13546 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13547 -- [, [Mechanism =>] MECHANISM]);
13549 -- EXTERNAL_SYMBOL ::=
13550 -- IDENTIFIER
13551 -- | static_string_EXPRESSION
13553 -- PARAMETER_TYPES ::=
13554 -- null
13555 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13557 -- TYPE_DESIGNATOR ::=
13558 -- subtype_NAME
13559 -- | subtype_Name ' Access
13561 -- MECHANISM ::=
13562 -- MECHANISM_NAME
13563 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13565 -- MECHANISM_ASSOCIATION ::=
13566 -- [formal_parameter_NAME =>] MECHANISM_NAME
13568 -- MECHANISM_NAME ::=
13569 -- Value
13570 -- | Reference
13572 when Pragma_Export_Procedure => Export_Procedure : declare
13573 Args : Args_List (1 .. 4);
13574 Names : constant Name_List (1 .. 4) := (
13575 Name_Internal,
13576 Name_External,
13577 Name_Parameter_Types,
13578 Name_Mechanism);
13580 Internal : Node_Id renames Args (1);
13581 External : Node_Id renames Args (2);
13582 Parameter_Types : Node_Id renames Args (3);
13583 Mechanism : Node_Id renames Args (4);
13585 begin
13586 GNAT_Pragma;
13587 Gather_Associations (Names, Args);
13588 Process_Extended_Import_Export_Subprogram_Pragma (
13589 Arg_Internal => Internal,
13590 Arg_External => External,
13591 Arg_Parameter_Types => Parameter_Types,
13592 Arg_Mechanism => Mechanism);
13593 end Export_Procedure;
13595 ------------------
13596 -- Export_Value --
13597 ------------------
13599 -- pragma Export_Value (
13600 -- [Value =>] static_integer_EXPRESSION,
13601 -- [Link_Name =>] static_string_EXPRESSION);
13603 when Pragma_Export_Value =>
13604 GNAT_Pragma;
13605 Check_Arg_Order ((Name_Value, Name_Link_Name));
13606 Check_Arg_Count (2);
13608 Check_Optional_Identifier (Arg1, Name_Value);
13609 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
13611 Check_Optional_Identifier (Arg2, Name_Link_Name);
13612 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
13614 -----------------------------
13615 -- Export_Valued_Procedure --
13616 -----------------------------
13618 -- pragma Export_Valued_Procedure (
13619 -- [Internal =>] LOCAL_NAME
13620 -- [, [External =>] EXTERNAL_SYMBOL,]
13621 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13622 -- [, [Mechanism =>] MECHANISM]);
13624 -- EXTERNAL_SYMBOL ::=
13625 -- IDENTIFIER
13626 -- | static_string_EXPRESSION
13628 -- PARAMETER_TYPES ::=
13629 -- null
13630 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13632 -- TYPE_DESIGNATOR ::=
13633 -- subtype_NAME
13634 -- | subtype_Name ' Access
13636 -- MECHANISM ::=
13637 -- MECHANISM_NAME
13638 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13640 -- MECHANISM_ASSOCIATION ::=
13641 -- [formal_parameter_NAME =>] MECHANISM_NAME
13643 -- MECHANISM_NAME ::=
13644 -- Value
13645 -- | Reference
13647 when Pragma_Export_Valued_Procedure =>
13648 Export_Valued_Procedure : declare
13649 Args : Args_List (1 .. 4);
13650 Names : constant Name_List (1 .. 4) := (
13651 Name_Internal,
13652 Name_External,
13653 Name_Parameter_Types,
13654 Name_Mechanism);
13656 Internal : Node_Id renames Args (1);
13657 External : Node_Id renames Args (2);
13658 Parameter_Types : Node_Id renames Args (3);
13659 Mechanism : Node_Id renames Args (4);
13661 begin
13662 GNAT_Pragma;
13663 Gather_Associations (Names, Args);
13664 Process_Extended_Import_Export_Subprogram_Pragma (
13665 Arg_Internal => Internal,
13666 Arg_External => External,
13667 Arg_Parameter_Types => Parameter_Types,
13668 Arg_Mechanism => Mechanism);
13669 end Export_Valued_Procedure;
13671 -------------------
13672 -- Extend_System --
13673 -------------------
13675 -- pragma Extend_System ([Name =>] Identifier);
13677 when Pragma_Extend_System => Extend_System : declare
13678 begin
13679 GNAT_Pragma;
13680 Check_Valid_Configuration_Pragma;
13681 Check_Arg_Count (1);
13682 Check_Optional_Identifier (Arg1, Name_Name);
13683 Check_Arg_Is_Identifier (Arg1);
13685 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13687 if Name_Len > 4
13688 and then Name_Buffer (1 .. 4) = "aux_"
13689 then
13690 if Present (System_Extend_Pragma_Arg) then
13691 if Chars (Get_Pragma_Arg (Arg1)) =
13692 Chars (Expression (System_Extend_Pragma_Arg))
13693 then
13694 null;
13695 else
13696 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
13697 Error_Pragma ("pragma% conflicts with that #");
13698 end if;
13700 else
13701 System_Extend_Pragma_Arg := Arg1;
13703 if not GNAT_Mode then
13704 System_Extend_Unit := Arg1;
13705 end if;
13706 end if;
13707 else
13708 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
13709 end if;
13710 end Extend_System;
13712 ------------------------
13713 -- Extensions_Allowed --
13714 ------------------------
13716 -- pragma Extensions_Allowed (ON | OFF);
13718 when Pragma_Extensions_Allowed =>
13719 GNAT_Pragma;
13720 Check_Arg_Count (1);
13721 Check_No_Identifiers;
13722 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13724 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
13725 Extensions_Allowed := True;
13726 Ada_Version := Ada_Version_Type'Last;
13728 else
13729 Extensions_Allowed := False;
13730 Ada_Version := Ada_Version_Explicit;
13731 Ada_Version_Pragma := Empty;
13732 end if;
13734 ------------------------
13735 -- Extensions_Visible --
13736 ------------------------
13738 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
13740 -- Characteristics:
13742 -- * Analysis - The annotation is fully analyzed immediately upon
13743 -- elaboration as its expression must be static.
13745 -- * Expansion - None.
13747 -- * Template - The annotation utilizes the generic template of the
13748 -- related subprogram [body] when it is:
13750 -- aspect on subprogram declaration
13751 -- aspect on stand alone subprogram body
13752 -- pragma on stand alone subprogram body
13754 -- The annotation must prepare its own template when it is:
13756 -- pragma on subprogram declaration
13758 -- * Globals - Capture of global references must occur after full
13759 -- analysis.
13761 -- * Instance - The annotation is instantiated automatically when
13762 -- the related generic subprogram [body] is instantiated except for
13763 -- the "pragma on subprogram declaration" case. In that scenario
13764 -- the annotation must instantiate itself.
13766 when Pragma_Extensions_Visible => Extensions_Visible : declare
13767 Expr : Node_Id;
13768 Formal : Entity_Id;
13769 Has_OK_Formal : Boolean := False;
13770 Spec_Id : Entity_Id;
13771 Subp_Decl : Node_Id;
13773 begin
13774 GNAT_Pragma;
13775 Check_No_Identifiers;
13776 Check_At_Most_N_Arguments (1);
13778 Subp_Decl :=
13779 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
13781 -- Generic subprogram declaration
13783 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
13784 null;
13786 -- Body acts as spec
13788 elsif Nkind (Subp_Decl) = N_Subprogram_Body
13789 and then No (Corresponding_Spec (Subp_Decl))
13790 then
13791 null;
13793 -- Body stub acts as spec
13795 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
13796 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
13797 then
13798 null;
13800 -- Subprogram declaration
13802 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
13803 null;
13805 -- Otherwise the pragma is associated with an illegal construct
13807 else
13808 Error_Pragma ("pragma % must apply to a subprogram");
13809 return;
13810 end if;
13812 Spec_Id := Corresponding_Spec_Of (Subp_Decl);
13814 -- Examine the formals of the related subprogram
13816 Formal := First_Formal (Spec_Id);
13817 while Present (Formal) loop
13819 -- At least one of the formals is of a specific tagged type,
13820 -- the pragma is legal.
13822 if Is_Specific_Tagged_Type (Etype (Formal)) then
13823 Has_OK_Formal := True;
13824 exit;
13826 -- A generic subprogram with at least one formal of a private
13827 -- type ensures the legality of the pragma because the actual
13828 -- may be specifically tagged. Note that this is verified by
13829 -- the check above at instantiation time.
13831 elsif Is_Private_Type (Etype (Formal))
13832 and then Is_Generic_Type (Etype (Formal))
13833 then
13834 Has_OK_Formal := True;
13835 exit;
13836 end if;
13838 Next_Formal (Formal);
13839 end loop;
13841 if not Has_OK_Formal then
13842 Error_Msg_Name_1 := Pname;
13843 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
13844 Error_Msg_NE
13845 ("\subprogram & lacks parameter of specific tagged or "
13846 & "generic private type", N, Spec_Id);
13847 return;
13848 end if;
13850 -- Analyze the Boolean expression (if any)
13852 if Present (Arg1) then
13853 Expr := Expression (Get_Argument (N, Spec_Id));
13855 Analyze_And_Resolve (Expr, Standard_Boolean);
13857 if not Is_OK_Static_Expression (Expr) then
13858 Error_Pragma_Arg
13859 ("expression of pragma % must be static", Expr);
13860 return;
13861 end if;
13862 end if;
13864 -- Chain the pragma on the contract for completeness
13866 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
13867 end Extensions_Visible;
13869 --------------
13870 -- External --
13871 --------------
13873 -- pragma External (
13874 -- [ Convention =>] convention_IDENTIFIER,
13875 -- [ Entity =>] LOCAL_NAME
13876 -- [, [External_Name =>] static_string_EXPRESSION ]
13877 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13879 when Pragma_External => External : declare
13880 Def_Id : Entity_Id;
13882 C : Convention_Id;
13883 pragma Warnings (Off, C);
13885 begin
13886 GNAT_Pragma;
13887 Check_Arg_Order
13888 ((Name_Convention,
13889 Name_Entity,
13890 Name_External_Name,
13891 Name_Link_Name));
13892 Check_At_Least_N_Arguments (2);
13893 Check_At_Most_N_Arguments (4);
13894 Process_Convention (C, Def_Id);
13895 Note_Possible_Modification
13896 (Get_Pragma_Arg (Arg2), Sure => False);
13897 Process_Interface_Name (Def_Id, Arg3, Arg4);
13898 Set_Exported (Def_Id, Arg2);
13899 end External;
13901 --------------------------
13902 -- External_Name_Casing --
13903 --------------------------
13905 -- pragma External_Name_Casing (
13906 -- UPPERCASE | LOWERCASE
13907 -- [, AS_IS | UPPERCASE | LOWERCASE]);
13909 when Pragma_External_Name_Casing => External_Name_Casing : declare
13910 begin
13911 GNAT_Pragma;
13912 Check_No_Identifiers;
13914 if Arg_Count = 2 then
13915 Check_Arg_Is_One_Of
13916 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
13918 case Chars (Get_Pragma_Arg (Arg2)) is
13919 when Name_As_Is =>
13920 Opt.External_Name_Exp_Casing := As_Is;
13922 when Name_Uppercase =>
13923 Opt.External_Name_Exp_Casing := Uppercase;
13925 when Name_Lowercase =>
13926 Opt.External_Name_Exp_Casing := Lowercase;
13928 when others =>
13929 null;
13930 end case;
13932 else
13933 Check_Arg_Count (1);
13934 end if;
13936 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
13938 case Chars (Get_Pragma_Arg (Arg1)) is
13939 when Name_Uppercase =>
13940 Opt.External_Name_Imp_Casing := Uppercase;
13942 when Name_Lowercase =>
13943 Opt.External_Name_Imp_Casing := Lowercase;
13945 when others =>
13946 null;
13947 end case;
13948 end External_Name_Casing;
13950 ---------------
13951 -- Fast_Math --
13952 ---------------
13954 -- pragma Fast_Math;
13956 when Pragma_Fast_Math =>
13957 GNAT_Pragma;
13958 Check_No_Identifiers;
13959 Check_Valid_Configuration_Pragma;
13960 Fast_Math := True;
13962 --------------------------
13963 -- Favor_Top_Level --
13964 --------------------------
13966 -- pragma Favor_Top_Level (type_NAME);
13968 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
13969 Named_Entity : Entity_Id;
13971 begin
13972 GNAT_Pragma;
13973 Check_No_Identifiers;
13974 Check_Arg_Count (1);
13975 Check_Arg_Is_Local_Name (Arg1);
13976 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
13978 -- If it's an access-to-subprogram type (in particular, not a
13979 -- subtype), set the flag on that type.
13981 if Is_Access_Subprogram_Type (Named_Entity) then
13982 Set_Can_Use_Internal_Rep (Named_Entity, False);
13984 -- Otherwise it's an error (name denotes the wrong sort of entity)
13986 else
13987 Error_Pragma_Arg
13988 ("access-to-subprogram type expected",
13989 Get_Pragma_Arg (Arg1));
13990 end if;
13991 end Favor_Top_Level;
13993 ---------------------------
13994 -- Finalize_Storage_Only --
13995 ---------------------------
13997 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
13999 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
14000 Assoc : constant Node_Id := Arg1;
14001 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
14002 Typ : Entity_Id;
14004 begin
14005 GNAT_Pragma;
14006 Check_No_Identifiers;
14007 Check_Arg_Count (1);
14008 Check_Arg_Is_Local_Name (Arg1);
14010 Find_Type (Type_Id);
14011 Typ := Entity (Type_Id);
14013 if Typ = Any_Type
14014 or else Rep_Item_Too_Early (Typ, N)
14015 then
14016 return;
14017 else
14018 Typ := Underlying_Type (Typ);
14019 end if;
14021 if not Is_Controlled (Typ) then
14022 Error_Pragma ("pragma% must specify controlled type");
14023 end if;
14025 Check_First_Subtype (Arg1);
14027 if Finalize_Storage_Only (Typ) then
14028 Error_Pragma ("duplicate pragma%, only one allowed");
14030 elsif not Rep_Item_Too_Late (Typ, N) then
14031 Set_Finalize_Storage_Only (Base_Type (Typ), True);
14032 end if;
14033 end Finalize_Storage;
14035 -----------
14036 -- Ghost --
14037 -----------
14039 -- pragma Ghost [ (boolean_EXPRESSION) ];
14041 when Pragma_Ghost => Ghost : declare
14042 Context : Node_Id;
14043 Expr : Node_Id;
14044 Id : Entity_Id;
14045 Orig_Stmt : Node_Id;
14046 Prev_Id : Entity_Id;
14047 Stmt : Node_Id;
14049 begin
14050 GNAT_Pragma;
14051 Check_No_Identifiers;
14052 Check_At_Most_N_Arguments (1);
14054 Context := Parent (N);
14056 -- Handle compilation units
14058 if Nkind (Context) = N_Compilation_Unit_Aux then
14059 Context := Unit (Parent (Context));
14060 end if;
14062 Id := Empty;
14063 Stmt := Prev (N);
14064 while Present (Stmt) loop
14066 -- Skip prior pragmas, but check for duplicates
14068 if Nkind (Stmt) = N_Pragma then
14069 if Pragma_Name (Stmt) = Pname then
14070 Error_Msg_Name_1 := Pname;
14071 Error_Msg_Sloc := Sloc (Stmt);
14072 Error_Msg_N ("pragma % duplicates pragma declared#", N);
14073 end if;
14075 -- Protected and task types cannot be subject to pragma Ghost
14077 elsif Nkind (Stmt) = N_Protected_Type_Declaration then
14078 Error_Pragma ("pragma % cannot apply to a protected type");
14079 return;
14081 elsif Nkind (Stmt) = N_Task_Type_Declaration then
14082 Error_Pragma ("pragma % cannot apply to a task type");
14083 return;
14085 -- Skip internally generated code
14087 elsif not Comes_From_Source (Stmt) then
14088 Orig_Stmt := Original_Node (Stmt);
14090 -- When pragma Ghost applies to an untagged derivation, the
14091 -- derivation is transformed into a [sub]type declaration.
14093 if Nkind_In (Stmt, N_Full_Type_Declaration,
14094 N_Subtype_Declaration)
14095 and then Comes_From_Source (Orig_Stmt)
14096 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
14097 and then Nkind (Type_Definition (Orig_Stmt)) =
14098 N_Derived_Type_Definition
14099 then
14100 Id := Defining_Entity (Stmt);
14101 exit;
14103 -- When pragma Ghost applies to an expression function, the
14104 -- expression function is transformed into a subprogram.
14106 elsif Nkind (Stmt) = N_Subprogram_Declaration
14107 and then Comes_From_Source (Orig_Stmt)
14108 and then Nkind (Orig_Stmt) = N_Expression_Function
14109 then
14110 Id := Defining_Entity (Stmt);
14111 exit;
14112 end if;
14114 -- The pragma applies to a legal construct, stop the traversal
14116 elsif Nkind_In (Stmt, N_Abstract_Subprogram_Declaration,
14117 N_Full_Type_Declaration,
14118 N_Generic_Subprogram_Declaration,
14119 N_Object_Declaration,
14120 N_Private_Extension_Declaration,
14121 N_Private_Type_Declaration,
14122 N_Subprogram_Declaration,
14123 N_Subtype_Declaration)
14124 then
14125 Id := Defining_Entity (Stmt);
14126 exit;
14128 -- The pragma does not apply to a legal construct, issue an
14129 -- error and stop the analysis.
14131 else
14132 Error_Pragma
14133 ("pragma % must apply to an object, package, subprogram "
14134 & "or type");
14135 return;
14136 end if;
14138 Stmt := Prev (Stmt);
14139 end loop;
14141 if No (Id) then
14143 -- When pragma Ghost is associated with a [generic] package, it
14144 -- appears in the visible declarations.
14146 if Nkind (Context) = N_Package_Specification
14147 and then Present (Visible_Declarations (Context))
14148 and then List_Containing (N) = Visible_Declarations (Context)
14149 then
14150 Id := Defining_Entity (Context);
14152 -- Pragma Ghost applies to a stand alone subprogram body
14154 elsif Nkind (Context) = N_Subprogram_Body
14155 and then No (Corresponding_Spec (Context))
14156 then
14157 Id := Defining_Entity (Context);
14158 end if;
14159 end if;
14161 if No (Id) then
14162 Error_Pragma
14163 ("pragma % must apply to an object, package, subprogram or "
14164 & "type");
14165 return;
14166 end if;
14168 -- A derived type or type extension cannot be subject to pragma
14169 -- Ghost if either the parent type or one of the progenitor types
14170 -- is not Ghost (SPARK RM 6.9(9)).
14172 if Is_Derived_Type (Id) then
14173 Check_Ghost_Derivation (Id);
14174 end if;
14176 -- Handle completions of types and constants that are subject to
14177 -- pragma Ghost.
14179 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
14180 Prev_Id := Incomplete_Or_Partial_View (Id);
14182 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
14183 Error_Msg_Name_1 := Pname;
14185 -- The full declaration of a deferred constant cannot be
14186 -- subject to pragma Ghost unless the deferred declaration
14187 -- is also Ghost (SPARK RM 6.9(10)).
14189 if Ekind (Prev_Id) = E_Constant then
14190 Error_Msg_Name_1 := Pname;
14191 Error_Msg_NE (Fix_Error
14192 ("pragma % must apply to declaration of deferred "
14193 & "constant &"), N, Id);
14194 return;
14196 -- Pragma Ghost may appear on the full view of an incomplete
14197 -- type because the incomplete declaration lacks aspects and
14198 -- cannot be subject to pragma Ghost.
14200 elsif Ekind (Prev_Id) = E_Incomplete_Type then
14201 null;
14203 -- The full declaration of a type cannot be subject to
14204 -- pragma Ghost unless the partial view is also Ghost
14205 -- (SPARK RM 6.9(10)).
14207 else
14208 Error_Msg_NE (Fix_Error
14209 ("pragma % must apply to partial view of type &"),
14210 N, Id);
14211 return;
14212 end if;
14213 end if;
14214 end if;
14216 -- Analyze the Boolean expression (if any)
14218 if Present (Arg1) then
14219 Expr := Get_Pragma_Arg (Arg1);
14221 Analyze_And_Resolve (Expr, Standard_Boolean);
14223 if Is_OK_Static_Expression (Expr) then
14225 -- "Ghostness" cannot be turned off once enabled within a
14226 -- region (SPARK RM 6.9(7)).
14228 if Is_False (Expr_Value (Expr))
14229 and then Ghost_Mode > None
14230 then
14231 Error_Pragma
14232 ("pragma % with value False cannot appear in enabled "
14233 & "ghost region");
14234 return;
14235 end if;
14237 -- Otherwie the expression is not static
14239 else
14240 Error_Pragma_Arg
14241 ("expression of pragma % must be static", Expr);
14242 return;
14243 end if;
14244 end if;
14246 Set_Is_Ghost_Entity (Id);
14247 end Ghost;
14249 ------------
14250 -- Global --
14251 ------------
14253 -- pragma Global (GLOBAL_SPECIFICATION);
14255 -- GLOBAL_SPECIFICATION ::=
14256 -- null
14257 -- | GLOBAL_LIST
14258 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
14260 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
14262 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
14263 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
14264 -- GLOBAL_ITEM ::= NAME
14266 -- Characteristics:
14268 -- * Analysis - The annotation undergoes initial checks to verify
14269 -- the legal placement and context. Secondary checks fully analyze
14270 -- the dependency clauses in:
14272 -- Analyze_Global_In_Decl_Part
14274 -- * Expansion - None.
14276 -- * Template - The annotation utilizes the generic template of the
14277 -- related subprogram [body] when it is:
14279 -- aspect on subprogram declaration
14280 -- aspect on stand alone subprogram body
14281 -- pragma on stand alone subprogram body
14283 -- The annotation must prepare its own template when it is:
14285 -- pragma on subprogram declaration
14287 -- * Globals - Capture of global references must occur after full
14288 -- analysis.
14290 -- * Instance - The annotation is instantiated automatically when
14291 -- the related generic subprogram [body] is instantiated except for
14292 -- the "pragma on subprogram declaration" case. In that scenario
14293 -- the annotation must instantiate itself.
14295 when Pragma_Global =>
14296 Analyze_Depends_Global;
14298 -----------
14299 -- Ident --
14300 -----------
14302 -- pragma Ident (static_string_EXPRESSION)
14304 -- Note: pragma Comment shares this processing. Pragma Ident is
14305 -- identical in effect to pragma Commment.
14307 when Pragma_Ident | Pragma_Comment => Ident : declare
14308 Str : Node_Id;
14310 begin
14311 GNAT_Pragma;
14312 Check_Arg_Count (1);
14313 Check_No_Identifiers;
14314 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
14315 Store_Note (N);
14317 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
14319 declare
14320 CS : Node_Id;
14321 GP : Node_Id;
14323 begin
14324 GP := Parent (Parent (N));
14326 if Nkind_In (GP, N_Package_Declaration,
14327 N_Generic_Package_Declaration)
14328 then
14329 GP := Parent (GP);
14330 end if;
14332 -- If we have a compilation unit, then record the ident value,
14333 -- checking for improper duplication.
14335 if Nkind (GP) = N_Compilation_Unit then
14336 CS := Ident_String (Current_Sem_Unit);
14338 if Present (CS) then
14340 -- If we have multiple instances, concatenate them, but
14341 -- not in ASIS, where we want the original tree.
14343 if not ASIS_Mode then
14344 Start_String (Strval (CS));
14345 Store_String_Char (' ');
14346 Store_String_Chars (Strval (Str));
14347 Set_Strval (CS, End_String);
14348 end if;
14350 else
14351 Set_Ident_String (Current_Sem_Unit, Str);
14352 end if;
14354 -- For subunits, we just ignore the Ident, since in GNAT these
14355 -- are not separate object files, and hence not separate units
14356 -- in the unit table.
14358 elsif Nkind (GP) = N_Subunit then
14359 null;
14360 end if;
14361 end;
14362 end Ident;
14364 -------------------
14365 -- Ignore_Pragma --
14366 -------------------
14368 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
14370 -- Entirely handled in the parser, nothing to do here
14372 when Pragma_Ignore_Pragma =>
14373 null;
14375 ----------------------------
14376 -- Implementation_Defined --
14377 ----------------------------
14379 -- pragma Implementation_Defined (LOCAL_NAME);
14381 -- Marks previously declared entity as implementation defined. For
14382 -- an overloaded entity, applies to the most recent homonym.
14384 -- pragma Implementation_Defined;
14386 -- The form with no arguments appears anywhere within a scope, most
14387 -- typically a package spec, and indicates that all entities that are
14388 -- defined within the package spec are Implementation_Defined.
14390 when Pragma_Implementation_Defined => Implementation_Defined : declare
14391 Ent : Entity_Id;
14393 begin
14394 GNAT_Pragma;
14395 Check_No_Identifiers;
14397 -- Form with no arguments
14399 if Arg_Count = 0 then
14400 Set_Is_Implementation_Defined (Current_Scope);
14402 -- Form with one argument
14404 else
14405 Check_Arg_Count (1);
14406 Check_Arg_Is_Local_Name (Arg1);
14407 Ent := Entity (Get_Pragma_Arg (Arg1));
14408 Set_Is_Implementation_Defined (Ent);
14409 end if;
14410 end Implementation_Defined;
14412 -----------------
14413 -- Implemented --
14414 -----------------
14416 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
14418 -- IMPLEMENTATION_KIND ::=
14419 -- By_Entry | By_Protected_Procedure | By_Any | Optional
14421 -- "By_Any" and "Optional" are treated as synonyms in order to
14422 -- support Ada 2012 aspect Synchronization.
14424 when Pragma_Implemented => Implemented : declare
14425 Proc_Id : Entity_Id;
14426 Typ : Entity_Id;
14428 begin
14429 Ada_2012_Pragma;
14430 Check_Arg_Count (2);
14431 Check_No_Identifiers;
14432 Check_Arg_Is_Identifier (Arg1);
14433 Check_Arg_Is_Local_Name (Arg1);
14434 Check_Arg_Is_One_Of (Arg2,
14435 Name_By_Any,
14436 Name_By_Entry,
14437 Name_By_Protected_Procedure,
14438 Name_Optional);
14440 -- Extract the name of the local procedure
14442 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
14444 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
14445 -- primitive procedure of a synchronized tagged type.
14447 if Ekind (Proc_Id) = E_Procedure
14448 and then Is_Primitive (Proc_Id)
14449 and then Present (First_Formal (Proc_Id))
14450 then
14451 Typ := Etype (First_Formal (Proc_Id));
14453 if Is_Tagged_Type (Typ)
14454 and then
14456 -- Check for a protected, a synchronized or a task interface
14458 ((Is_Interface (Typ)
14459 and then Is_Synchronized_Interface (Typ))
14461 -- Check for a protected type or a task type that implements
14462 -- an interface.
14464 or else
14465 (Is_Concurrent_Record_Type (Typ)
14466 and then Present (Interfaces (Typ)))
14468 -- In analysis-only mode, examine original protected type
14470 or else
14471 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
14472 and then Present (Interface_List (Parent (Typ))))
14474 -- Check for a private record extension with keyword
14475 -- "synchronized".
14477 or else
14478 (Ekind_In (Typ, E_Record_Type_With_Private,
14479 E_Record_Subtype_With_Private)
14480 and then Synchronized_Present (Parent (Typ))))
14481 then
14482 null;
14483 else
14484 Error_Pragma_Arg
14485 ("controlling formal must be of synchronized tagged type",
14486 Arg1);
14487 return;
14488 end if;
14490 -- Procedures declared inside a protected type must be accepted
14492 elsif Ekind (Proc_Id) = E_Procedure
14493 and then Is_Protected_Type (Scope (Proc_Id))
14494 then
14495 null;
14497 -- The first argument is not a primitive procedure
14499 else
14500 Error_Pragma_Arg
14501 ("pragma % must be applied to a primitive procedure", Arg1);
14502 return;
14503 end if;
14505 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
14506 -- By_Protected_Procedure to the primitive procedure of a task
14507 -- interface.
14509 if Chars (Arg2) = Name_By_Protected_Procedure
14510 and then Is_Interface (Typ)
14511 and then Is_Task_Interface (Typ)
14512 then
14513 Error_Pragma_Arg
14514 ("implementation kind By_Protected_Procedure cannot be "
14515 & "applied to a task interface primitive", Arg2);
14516 return;
14517 end if;
14519 Record_Rep_Item (Proc_Id, N);
14520 end Implemented;
14522 ----------------------
14523 -- Implicit_Packing --
14524 ----------------------
14526 -- pragma Implicit_Packing;
14528 when Pragma_Implicit_Packing =>
14529 GNAT_Pragma;
14530 Check_Arg_Count (0);
14531 Implicit_Packing := True;
14533 ------------
14534 -- Import --
14535 ------------
14537 -- pragma Import (
14538 -- [Convention =>] convention_IDENTIFIER,
14539 -- [Entity =>] LOCAL_NAME
14540 -- [, [External_Name =>] static_string_EXPRESSION ]
14541 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14543 when Pragma_Import =>
14544 Check_Ada_83_Warning;
14545 Check_Arg_Order
14546 ((Name_Convention,
14547 Name_Entity,
14548 Name_External_Name,
14549 Name_Link_Name));
14551 Check_At_Least_N_Arguments (2);
14552 Check_At_Most_N_Arguments (4);
14553 Process_Import_Or_Interface;
14555 ---------------------
14556 -- Import_Function --
14557 ---------------------
14559 -- pragma Import_Function (
14560 -- [Internal =>] LOCAL_NAME,
14561 -- [, [External =>] EXTERNAL_SYMBOL]
14562 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14563 -- [, [Result_Type =>] SUBTYPE_MARK]
14564 -- [, [Mechanism =>] MECHANISM]
14565 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
14567 -- EXTERNAL_SYMBOL ::=
14568 -- IDENTIFIER
14569 -- | static_string_EXPRESSION
14571 -- PARAMETER_TYPES ::=
14572 -- null
14573 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14575 -- TYPE_DESIGNATOR ::=
14576 -- subtype_NAME
14577 -- | subtype_Name ' Access
14579 -- MECHANISM ::=
14580 -- MECHANISM_NAME
14581 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14583 -- MECHANISM_ASSOCIATION ::=
14584 -- [formal_parameter_NAME =>] MECHANISM_NAME
14586 -- MECHANISM_NAME ::=
14587 -- Value
14588 -- | Reference
14590 when Pragma_Import_Function => Import_Function : declare
14591 Args : Args_List (1 .. 6);
14592 Names : constant Name_List (1 .. 6) := (
14593 Name_Internal,
14594 Name_External,
14595 Name_Parameter_Types,
14596 Name_Result_Type,
14597 Name_Mechanism,
14598 Name_Result_Mechanism);
14600 Internal : Node_Id renames Args (1);
14601 External : Node_Id renames Args (2);
14602 Parameter_Types : Node_Id renames Args (3);
14603 Result_Type : Node_Id renames Args (4);
14604 Mechanism : Node_Id renames Args (5);
14605 Result_Mechanism : Node_Id renames Args (6);
14607 begin
14608 GNAT_Pragma;
14609 Gather_Associations (Names, Args);
14610 Process_Extended_Import_Export_Subprogram_Pragma (
14611 Arg_Internal => Internal,
14612 Arg_External => External,
14613 Arg_Parameter_Types => Parameter_Types,
14614 Arg_Result_Type => Result_Type,
14615 Arg_Mechanism => Mechanism,
14616 Arg_Result_Mechanism => Result_Mechanism);
14617 end Import_Function;
14619 -------------------
14620 -- Import_Object --
14621 -------------------
14623 -- pragma Import_Object (
14624 -- [Internal =>] LOCAL_NAME
14625 -- [, [External =>] EXTERNAL_SYMBOL]
14626 -- [, [Size =>] EXTERNAL_SYMBOL]);
14628 -- EXTERNAL_SYMBOL ::=
14629 -- IDENTIFIER
14630 -- | static_string_EXPRESSION
14632 when Pragma_Import_Object => Import_Object : declare
14633 Args : Args_List (1 .. 3);
14634 Names : constant Name_List (1 .. 3) := (
14635 Name_Internal,
14636 Name_External,
14637 Name_Size);
14639 Internal : Node_Id renames Args (1);
14640 External : Node_Id renames Args (2);
14641 Size : Node_Id renames Args (3);
14643 begin
14644 GNAT_Pragma;
14645 Gather_Associations (Names, Args);
14646 Process_Extended_Import_Export_Object_Pragma (
14647 Arg_Internal => Internal,
14648 Arg_External => External,
14649 Arg_Size => Size);
14650 end Import_Object;
14652 ----------------------
14653 -- Import_Procedure --
14654 ----------------------
14656 -- pragma Import_Procedure (
14657 -- [Internal =>] LOCAL_NAME
14658 -- [, [External =>] EXTERNAL_SYMBOL]
14659 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14660 -- [, [Mechanism =>] MECHANISM]);
14662 -- EXTERNAL_SYMBOL ::=
14663 -- IDENTIFIER
14664 -- | static_string_EXPRESSION
14666 -- PARAMETER_TYPES ::=
14667 -- null
14668 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14670 -- TYPE_DESIGNATOR ::=
14671 -- subtype_NAME
14672 -- | subtype_Name ' Access
14674 -- MECHANISM ::=
14675 -- MECHANISM_NAME
14676 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14678 -- MECHANISM_ASSOCIATION ::=
14679 -- [formal_parameter_NAME =>] MECHANISM_NAME
14681 -- MECHANISM_NAME ::=
14682 -- Value
14683 -- | Reference
14685 when Pragma_Import_Procedure => Import_Procedure : declare
14686 Args : Args_List (1 .. 4);
14687 Names : constant Name_List (1 .. 4) := (
14688 Name_Internal,
14689 Name_External,
14690 Name_Parameter_Types,
14691 Name_Mechanism);
14693 Internal : Node_Id renames Args (1);
14694 External : Node_Id renames Args (2);
14695 Parameter_Types : Node_Id renames Args (3);
14696 Mechanism : Node_Id renames Args (4);
14698 begin
14699 GNAT_Pragma;
14700 Gather_Associations (Names, Args);
14701 Process_Extended_Import_Export_Subprogram_Pragma (
14702 Arg_Internal => Internal,
14703 Arg_External => External,
14704 Arg_Parameter_Types => Parameter_Types,
14705 Arg_Mechanism => Mechanism);
14706 end Import_Procedure;
14708 -----------------------------
14709 -- Import_Valued_Procedure --
14710 -----------------------------
14712 -- pragma Import_Valued_Procedure (
14713 -- [Internal =>] LOCAL_NAME
14714 -- [, [External =>] EXTERNAL_SYMBOL]
14715 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14716 -- [, [Mechanism =>] MECHANISM]);
14718 -- EXTERNAL_SYMBOL ::=
14719 -- IDENTIFIER
14720 -- | static_string_EXPRESSION
14722 -- PARAMETER_TYPES ::=
14723 -- null
14724 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14726 -- TYPE_DESIGNATOR ::=
14727 -- subtype_NAME
14728 -- | subtype_Name ' Access
14730 -- MECHANISM ::=
14731 -- MECHANISM_NAME
14732 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14734 -- MECHANISM_ASSOCIATION ::=
14735 -- [formal_parameter_NAME =>] MECHANISM_NAME
14737 -- MECHANISM_NAME ::=
14738 -- Value
14739 -- | Reference
14741 when Pragma_Import_Valued_Procedure =>
14742 Import_Valued_Procedure : declare
14743 Args : Args_List (1 .. 4);
14744 Names : constant Name_List (1 .. 4) := (
14745 Name_Internal,
14746 Name_External,
14747 Name_Parameter_Types,
14748 Name_Mechanism);
14750 Internal : Node_Id renames Args (1);
14751 External : Node_Id renames Args (2);
14752 Parameter_Types : Node_Id renames Args (3);
14753 Mechanism : Node_Id renames Args (4);
14755 begin
14756 GNAT_Pragma;
14757 Gather_Associations (Names, Args);
14758 Process_Extended_Import_Export_Subprogram_Pragma (
14759 Arg_Internal => Internal,
14760 Arg_External => External,
14761 Arg_Parameter_Types => Parameter_Types,
14762 Arg_Mechanism => Mechanism);
14763 end Import_Valued_Procedure;
14765 -----------------
14766 -- Independent --
14767 -----------------
14769 -- pragma Independent (LOCAL_NAME);
14771 when Pragma_Independent =>
14772 Process_Atomic_Independent_Shared_Volatile;
14774 ----------------------------
14775 -- Independent_Components --
14776 ----------------------------
14778 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
14780 when Pragma_Independent_Components => Independent_Components : declare
14781 E_Id : Node_Id;
14782 E : Entity_Id;
14783 D : Node_Id;
14784 K : Node_Kind;
14785 C : Node_Id;
14787 begin
14788 Check_Ada_83_Warning;
14789 Ada_2012_Pragma;
14790 Check_No_Identifiers;
14791 Check_Arg_Count (1);
14792 Check_Arg_Is_Local_Name (Arg1);
14793 E_Id := Get_Pragma_Arg (Arg1);
14795 if Etype (E_Id) = Any_Type then
14796 return;
14797 end if;
14799 E := Entity (E_Id);
14801 -- Check duplicate before we chain ourselves
14803 Check_Duplicate_Pragma (E);
14805 -- Check appropriate entity
14807 if Rep_Item_Too_Early (E, N)
14808 or else
14809 Rep_Item_Too_Late (E, N)
14810 then
14811 return;
14812 end if;
14814 D := Declaration_Node (E);
14815 K := Nkind (D);
14817 -- The flag is set on the base type, or on the object
14819 if K = N_Full_Type_Declaration
14820 and then (Is_Array_Type (E) or else Is_Record_Type (E))
14821 then
14822 Set_Has_Independent_Components (Base_Type (E));
14823 Record_Independence_Check (N, Base_Type (E));
14825 -- For record type, set all components independent
14827 if Is_Record_Type (E) then
14828 C := First_Component (E);
14829 while Present (C) loop
14830 Set_Is_Independent (C);
14831 Next_Component (C);
14832 end loop;
14833 end if;
14835 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
14836 and then Nkind (D) = N_Object_Declaration
14837 and then Nkind (Object_Definition (D)) =
14838 N_Constrained_Array_Definition
14839 then
14840 Set_Has_Independent_Components (E);
14841 Record_Independence_Check (N, E);
14843 else
14844 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
14845 end if;
14846 end Independent_Components;
14848 -----------------------
14849 -- Initial_Condition --
14850 -----------------------
14852 -- pragma Initial_Condition (boolean_EXPRESSION);
14854 -- Characteristics:
14856 -- * Analysis - The annotation undergoes initial checks to verify
14857 -- the legal placement and context. Secondary checks preanalyze the
14858 -- expression in:
14860 -- Analyze_Initial_Condition_In_Decl_Part
14862 -- * Expansion - The annotation is expanded during the expansion of
14863 -- the package body whose declaration is subject to the annotation
14864 -- as done in:
14866 -- Expand_Pragma_Initial_Condition
14868 -- * Template - The annotation utilizes the generic template of the
14869 -- related package declaration.
14871 -- * Globals - Capture of global references must occur after full
14872 -- analysis.
14874 -- * Instance - The annotation is instantiated automatically when
14875 -- the related generic package is instantiated.
14877 when Pragma_Initial_Condition => Initial_Condition : declare
14878 Pack_Decl : Node_Id;
14879 Pack_Id : Entity_Id;
14881 begin
14882 GNAT_Pragma;
14883 Check_No_Identifiers;
14884 Check_Arg_Count (1);
14886 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
14888 -- Ensure the proper placement of the pragma. Initial_Condition
14889 -- must be associated with a package declaration.
14891 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
14892 N_Package_Declaration)
14893 then
14894 null;
14896 -- Otherwise the pragma is associated with an illegal context
14898 else
14899 Pragma_Misplaced;
14900 return;
14901 end if;
14903 -- The pragma must be analyzed at the end of the visible
14904 -- declarations of the related package. Save the pragma for later
14905 -- (see Analyze_Initial_Condition_In_Decl_Part) by adding it to
14906 -- the contract of the package.
14908 Pack_Id := Defining_Entity (Pack_Decl);
14910 -- Verify the declaration order of pragma Initial_Condition with
14911 -- respect to pragmas Abstract_State and Initializes when SPARK
14912 -- checks are enabled.
14914 if SPARK_Mode /= Off then
14915 Check_Declaration_Order
14916 (First => Get_Pragma (Pack_Id, Pragma_Abstract_State),
14917 Second => N);
14919 Check_Declaration_Order
14920 (First => Get_Pragma (Pack_Id, Pragma_Initializes),
14921 Second => N);
14922 end if;
14924 -- Chain the pragma on the contract for further processing by
14925 -- Analyze_Initial_Condition_In_Decl_Part.
14927 Add_Contract_Item (N, Pack_Id);
14928 end Initial_Condition;
14930 ------------------------
14931 -- Initialize_Scalars --
14932 ------------------------
14934 -- pragma Initialize_Scalars;
14936 when Pragma_Initialize_Scalars =>
14937 GNAT_Pragma;
14938 Check_Arg_Count (0);
14939 Check_Valid_Configuration_Pragma;
14940 Check_Restriction (No_Initialize_Scalars, N);
14942 -- Initialize_Scalars creates false positives in CodePeer, and
14943 -- incorrect negative results in GNATprove mode, so ignore this
14944 -- pragma in these modes.
14946 if not Restriction_Active (No_Initialize_Scalars)
14947 and then not (CodePeer_Mode or GNATprove_Mode)
14948 then
14949 Init_Or_Norm_Scalars := True;
14950 Initialize_Scalars := True;
14951 end if;
14953 -----------------
14954 -- Initializes --
14955 -----------------
14957 -- pragma Initializes (INITIALIZATION_SPEC);
14959 -- INITIALIZATION_SPEC ::= null | INITIALIZATION_LIST
14961 -- INITIALIZATION_LIST ::=
14962 -- INITIALIZATION_ITEM
14963 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
14965 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
14967 -- INPUT_LIST ::=
14968 -- null
14969 -- | INPUT
14970 -- | (INPUT {, INPUT})
14972 -- INPUT ::= name
14974 -- Characteristics:
14976 -- * Analysis - The annotation undergoes initial checks to verify
14977 -- the legal placement and context. Secondary checks preanalyze the
14978 -- expression in:
14980 -- Analyze_Initializes_In_Decl_Part
14982 -- * Expansion - None.
14984 -- * Template - The annotation utilizes the generic template of the
14985 -- related package declaration.
14987 -- * Globals - Capture of global references must occur after full
14988 -- analysis.
14990 -- * Instance - The annotation is instantiated automatically when
14991 -- the related generic package is instantiated.
14993 when Pragma_Initializes => Initializes : declare
14994 Pack_Decl : Node_Id;
14995 Pack_Id : Entity_Id;
14997 begin
14998 GNAT_Pragma;
14999 Check_No_Identifiers;
15000 Check_Arg_Count (1);
15002 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
15004 -- Ensure the proper placement of the pragma. Initializes must be
15005 -- associated with a package declaration.
15007 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
15008 N_Package_Declaration)
15009 then
15010 null;
15012 -- Otherwise the pragma is associated with an illegal construc
15014 else
15015 Pragma_Misplaced;
15016 return;
15017 end if;
15019 Pack_Id := Defining_Entity (Pack_Decl);
15021 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
15023 -- Verify the declaration order of pragmas Abstract_State and
15024 -- Initializes when SPARK checks are enabled.
15026 if SPARK_Mode /= Off then
15027 Check_Declaration_Order
15028 (First => Get_Pragma (Pack_Id, Pragma_Abstract_State),
15029 Second => N);
15030 end if;
15032 -- Chain the pragma on the contract for further processing by
15033 -- Analyze_Initializes_In_Decl_Part.
15035 Add_Contract_Item (N, Pack_Id);
15036 end Initializes;
15038 ------------
15039 -- Inline --
15040 ------------
15042 -- pragma Inline ( NAME {, NAME} );
15044 when Pragma_Inline =>
15046 -- Pragma always active unless in GNATprove mode. It is disabled
15047 -- in GNATprove mode because frontend inlining is applied
15048 -- independently of pragmas Inline and Inline_Always for
15049 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
15050 -- in inline.ads.
15052 if not GNATprove_Mode then
15054 -- Inline status is Enabled if inlining option is active
15056 if Inline_Active then
15057 Process_Inline (Enabled);
15058 else
15059 Process_Inline (Disabled);
15060 end if;
15061 end if;
15063 -------------------
15064 -- Inline_Always --
15065 -------------------
15067 -- pragma Inline_Always ( NAME {, NAME} );
15069 when Pragma_Inline_Always =>
15070 GNAT_Pragma;
15072 -- Pragma always active unless in CodePeer mode or GNATprove
15073 -- mode. It is disabled in CodePeer mode because inlining is
15074 -- not helpful, and enabling it caused walk order issues. It
15075 -- is disabled in GNATprove mode because frontend inlining is
15076 -- applied independently of pragmas Inline and Inline_Always for
15077 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
15078 -- inline.ads.
15080 if not CodePeer_Mode and not GNATprove_Mode then
15081 Process_Inline (Enabled);
15082 end if;
15084 --------------------
15085 -- Inline_Generic --
15086 --------------------
15088 -- pragma Inline_Generic (NAME {, NAME});
15090 when Pragma_Inline_Generic =>
15091 GNAT_Pragma;
15092 Process_Generic_List;
15094 ----------------------
15095 -- Inspection_Point --
15096 ----------------------
15098 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
15100 when Pragma_Inspection_Point => Inspection_Point : declare
15101 Arg : Node_Id;
15102 Exp : Node_Id;
15104 begin
15107 if Arg_Count > 0 then
15108 Arg := Arg1;
15109 loop
15110 Exp := Get_Pragma_Arg (Arg);
15111 Analyze (Exp);
15113 if not Is_Entity_Name (Exp)
15114 or else not Is_Object (Entity (Exp))
15115 then
15116 Error_Pragma_Arg ("object name required", Arg);
15117 end if;
15119 Next (Arg);
15120 exit when No (Arg);
15121 end loop;
15122 end if;
15123 end Inspection_Point;
15125 ---------------
15126 -- Interface --
15127 ---------------
15129 -- pragma Interface (
15130 -- [ Convention =>] convention_IDENTIFIER,
15131 -- [ Entity =>] LOCAL_NAME
15132 -- [, [External_Name =>] static_string_EXPRESSION ]
15133 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15135 when Pragma_Interface =>
15136 GNAT_Pragma;
15137 Check_Arg_Order
15138 ((Name_Convention,
15139 Name_Entity,
15140 Name_External_Name,
15141 Name_Link_Name));
15142 Check_At_Least_N_Arguments (2);
15143 Check_At_Most_N_Arguments (4);
15144 Process_Import_Or_Interface;
15146 -- In Ada 2005, the permission to use Interface (a reserved word)
15147 -- as a pragma name is considered an obsolescent feature, and this
15148 -- pragma was already obsolescent in Ada 95.
15150 if Ada_Version >= Ada_95 then
15151 Check_Restriction
15152 (No_Obsolescent_Features, Pragma_Identifier (N));
15154 if Warn_On_Obsolescent_Feature then
15155 Error_Msg_N
15156 ("pragma Interface is an obsolescent feature?j?", N);
15157 Error_Msg_N
15158 ("|use pragma Import instead?j?", N);
15159 end if;
15160 end if;
15162 --------------------
15163 -- Interface_Name --
15164 --------------------
15166 -- pragma Interface_Name (
15167 -- [ Entity =>] LOCAL_NAME
15168 -- [,[External_Name =>] static_string_EXPRESSION ]
15169 -- [,[Link_Name =>] static_string_EXPRESSION ]);
15171 when Pragma_Interface_Name => Interface_Name : declare
15172 Id : Node_Id;
15173 Def_Id : Entity_Id;
15174 Hom_Id : Entity_Id;
15175 Found : Boolean;
15177 begin
15178 GNAT_Pragma;
15179 Check_Arg_Order
15180 ((Name_Entity, Name_External_Name, Name_Link_Name));
15181 Check_At_Least_N_Arguments (2);
15182 Check_At_Most_N_Arguments (3);
15183 Id := Get_Pragma_Arg (Arg1);
15184 Analyze (Id);
15186 -- This is obsolete from Ada 95 on, but it is an implementation
15187 -- defined pragma, so we do not consider that it violates the
15188 -- restriction (No_Obsolescent_Features).
15190 if Ada_Version >= Ada_95 then
15191 if Warn_On_Obsolescent_Feature then
15192 Error_Msg_N
15193 ("pragma Interface_Name is an obsolescent feature?j?", N);
15194 Error_Msg_N
15195 ("|use pragma Import instead?j?", N);
15196 end if;
15197 end if;
15199 if not Is_Entity_Name (Id) then
15200 Error_Pragma_Arg
15201 ("first argument for pragma% must be entity name", Arg1);
15202 elsif Etype (Id) = Any_Type then
15203 return;
15204 else
15205 Def_Id := Entity (Id);
15206 end if;
15208 -- Special DEC-compatible processing for the object case, forces
15209 -- object to be imported.
15211 if Ekind (Def_Id) = E_Variable then
15212 Kill_Size_Check_Code (Def_Id);
15213 Note_Possible_Modification (Id, Sure => False);
15215 -- Initialization is not allowed for imported variable
15217 if Present (Expression (Parent (Def_Id)))
15218 and then Comes_From_Source (Expression (Parent (Def_Id)))
15219 then
15220 Error_Msg_Sloc := Sloc (Def_Id);
15221 Error_Pragma_Arg
15222 ("no initialization allowed for declaration of& #",
15223 Arg2);
15225 else
15226 -- For compatibility, support VADS usage of providing both
15227 -- pragmas Interface and Interface_Name to obtain the effect
15228 -- of a single Import pragma.
15230 if Is_Imported (Def_Id)
15231 and then Present (First_Rep_Item (Def_Id))
15232 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
15233 and then
15234 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
15235 then
15236 null;
15237 else
15238 Set_Imported (Def_Id);
15239 end if;
15241 Set_Is_Public (Def_Id);
15242 Process_Interface_Name (Def_Id, Arg2, Arg3);
15243 end if;
15245 -- Otherwise must be subprogram
15247 elsif not Is_Subprogram (Def_Id) then
15248 Error_Pragma_Arg
15249 ("argument of pragma% is not subprogram", Arg1);
15251 else
15252 Check_At_Most_N_Arguments (3);
15253 Hom_Id := Def_Id;
15254 Found := False;
15256 -- Loop through homonyms
15258 loop
15259 Def_Id := Get_Base_Subprogram (Hom_Id);
15261 if Is_Imported (Def_Id) then
15262 Process_Interface_Name (Def_Id, Arg2, Arg3);
15263 Found := True;
15264 end if;
15266 exit when From_Aspect_Specification (N);
15267 Hom_Id := Homonym (Hom_Id);
15269 exit when No (Hom_Id)
15270 or else Scope (Hom_Id) /= Current_Scope;
15271 end loop;
15273 if not Found then
15274 Error_Pragma_Arg
15275 ("argument of pragma% is not imported subprogram",
15276 Arg1);
15277 end if;
15278 end if;
15279 end Interface_Name;
15281 -----------------------
15282 -- Interrupt_Handler --
15283 -----------------------
15285 -- pragma Interrupt_Handler (handler_NAME);
15287 when Pragma_Interrupt_Handler =>
15288 Check_Ada_83_Warning;
15289 Check_Arg_Count (1);
15290 Check_No_Identifiers;
15292 if No_Run_Time_Mode then
15293 Error_Msg_CRT ("Interrupt_Handler pragma", N);
15294 else
15295 Check_Interrupt_Or_Attach_Handler;
15296 Process_Interrupt_Or_Attach_Handler;
15297 end if;
15299 ------------------------
15300 -- Interrupt_Priority --
15301 ------------------------
15303 -- pragma Interrupt_Priority [(EXPRESSION)];
15305 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
15306 P : constant Node_Id := Parent (N);
15307 Arg : Node_Id;
15308 Ent : Entity_Id;
15310 begin
15311 Check_Ada_83_Warning;
15313 if Arg_Count /= 0 then
15314 Arg := Get_Pragma_Arg (Arg1);
15315 Check_Arg_Count (1);
15316 Check_No_Identifiers;
15318 -- The expression must be analyzed in the special manner
15319 -- described in "Handling of Default and Per-Object
15320 -- Expressions" in sem.ads.
15322 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
15323 end if;
15325 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
15326 Pragma_Misplaced;
15327 return;
15329 else
15330 Ent := Defining_Identifier (Parent (P));
15332 -- Check duplicate pragma before we chain the pragma in the Rep
15333 -- Item chain of Ent.
15335 Check_Duplicate_Pragma (Ent);
15336 Record_Rep_Item (Ent, N);
15337 end if;
15338 end Interrupt_Priority;
15340 ---------------------
15341 -- Interrupt_State --
15342 ---------------------
15344 -- pragma Interrupt_State (
15345 -- [Name =>] INTERRUPT_ID,
15346 -- [State =>] INTERRUPT_STATE);
15348 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
15349 -- INTERRUPT_STATE => System | Runtime | User
15351 -- Note: if the interrupt id is given as an identifier, then it must
15352 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
15353 -- given as a static integer expression which must be in the range of
15354 -- Ada.Interrupts.Interrupt_ID.
15356 when Pragma_Interrupt_State => Interrupt_State : declare
15357 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
15358 -- This is the entity Ada.Interrupts.Interrupt_ID;
15360 State_Type : Character;
15361 -- Set to 's'/'r'/'u' for System/Runtime/User
15363 IST_Num : Pos;
15364 -- Index to entry in Interrupt_States table
15366 Int_Val : Uint;
15367 -- Value of interrupt
15369 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
15370 -- The first argument to the pragma
15372 Int_Ent : Entity_Id;
15373 -- Interrupt entity in Ada.Interrupts.Names
15375 begin
15376 GNAT_Pragma;
15377 Check_Arg_Order ((Name_Name, Name_State));
15378 Check_Arg_Count (2);
15380 Check_Optional_Identifier (Arg1, Name_Name);
15381 Check_Optional_Identifier (Arg2, Name_State);
15382 Check_Arg_Is_Identifier (Arg2);
15384 -- First argument is identifier
15386 if Nkind (Arg1X) = N_Identifier then
15388 -- Search list of names in Ada.Interrupts.Names
15390 Int_Ent := First_Entity (RTE (RE_Names));
15391 loop
15392 if No (Int_Ent) then
15393 Error_Pragma_Arg ("invalid interrupt name", Arg1);
15395 elsif Chars (Int_Ent) = Chars (Arg1X) then
15396 Int_Val := Expr_Value (Constant_Value (Int_Ent));
15397 exit;
15398 end if;
15400 Next_Entity (Int_Ent);
15401 end loop;
15403 -- First argument is not an identifier, so it must be a static
15404 -- expression of type Ada.Interrupts.Interrupt_ID.
15406 else
15407 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
15408 Int_Val := Expr_Value (Arg1X);
15410 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
15411 or else
15412 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
15413 then
15414 Error_Pragma_Arg
15415 ("value not in range of type "
15416 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
15417 end if;
15418 end if;
15420 -- Check OK state
15422 case Chars (Get_Pragma_Arg (Arg2)) is
15423 when Name_Runtime => State_Type := 'r';
15424 when Name_System => State_Type := 's';
15425 when Name_User => State_Type := 'u';
15427 when others =>
15428 Error_Pragma_Arg ("invalid interrupt state", Arg2);
15429 end case;
15431 -- Check if entry is already stored
15433 IST_Num := Interrupt_States.First;
15434 loop
15435 -- If entry not found, add it
15437 if IST_Num > Interrupt_States.Last then
15438 Interrupt_States.Append
15439 ((Interrupt_Number => UI_To_Int (Int_Val),
15440 Interrupt_State => State_Type,
15441 Pragma_Loc => Loc));
15442 exit;
15444 -- Case of entry for the same entry
15446 elsif Int_Val = Interrupt_States.Table (IST_Num).
15447 Interrupt_Number
15448 then
15449 -- If state matches, done, no need to make redundant entry
15451 exit when
15452 State_Type = Interrupt_States.Table (IST_Num).
15453 Interrupt_State;
15455 -- Otherwise if state does not match, error
15457 Error_Msg_Sloc :=
15458 Interrupt_States.Table (IST_Num).Pragma_Loc;
15459 Error_Pragma_Arg
15460 ("state conflicts with that given #", Arg2);
15461 exit;
15462 end if;
15464 IST_Num := IST_Num + 1;
15465 end loop;
15466 end Interrupt_State;
15468 ---------------
15469 -- Invariant --
15470 ---------------
15472 -- pragma Invariant
15473 -- ([Entity =>] type_LOCAL_NAME,
15474 -- [Check =>] EXPRESSION
15475 -- [,[Message =>] String_Expression]);
15477 when Pragma_Invariant => Invariant : declare
15478 Type_Id : Node_Id;
15479 Typ : Entity_Id;
15480 Discard : Boolean;
15482 begin
15483 GNAT_Pragma;
15484 Check_At_Least_N_Arguments (2);
15485 Check_At_Most_N_Arguments (3);
15486 Check_Optional_Identifier (Arg1, Name_Entity);
15487 Check_Optional_Identifier (Arg2, Name_Check);
15489 if Arg_Count = 3 then
15490 Check_Optional_Identifier (Arg3, Name_Message);
15491 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
15492 end if;
15494 Check_Arg_Is_Local_Name (Arg1);
15496 Type_Id := Get_Pragma_Arg (Arg1);
15497 Find_Type (Type_Id);
15498 Typ := Entity (Type_Id);
15500 if Typ = Any_Type then
15501 return;
15503 -- Invariants allowed in interface types (RM 7.3.2(3/3))
15505 elsif Is_Interface (Typ) then
15506 null;
15508 -- An invariant must apply to a private type, or appear in the
15509 -- private part of a package spec and apply to a completion.
15510 -- a class-wide invariant can only appear on a private declaration
15511 -- or private extension, not a completion.
15513 elsif Ekind_In (Typ, E_Private_Type,
15514 E_Record_Type_With_Private,
15515 E_Limited_Private_Type)
15516 then
15517 null;
15519 elsif In_Private_Part (Current_Scope)
15520 and then Has_Private_Declaration (Typ)
15521 and then not Class_Present (N)
15522 then
15523 null;
15525 elsif In_Private_Part (Current_Scope) then
15526 Error_Pragma_Arg
15527 ("pragma% only allowed for private type declared in "
15528 & "visible part", Arg1);
15530 else
15531 Error_Pragma_Arg
15532 ("pragma% only allowed for private type", Arg1);
15533 end if;
15535 -- Not allowed for abstract type in the non-class case (it is
15536 -- allowed to use Invariant'Class for abstract types).
15538 if Is_Abstract_Type (Typ) and then not Class_Present (N) then
15539 Error_Pragma_Arg
15540 ("pragma% not allowed for abstract type", Arg1);
15541 end if;
15543 -- Note that the type has at least one invariant, and also that
15544 -- it has inheritable invariants if we have Invariant'Class
15545 -- or Type_Invariant'Class. Build the corresponding invariant
15546 -- procedure declaration, so that calls to it can be generated
15547 -- before the body is built (e.g. within an expression function).
15549 -- Interface types have no invariant procedure; their invariants
15550 -- are propagated to the build invariant procedure of all the
15551 -- types covering the interface type.
15553 if not Is_Interface (Typ) then
15554 Insert_After_And_Analyze
15555 (N, Build_Invariant_Procedure_Declaration (Typ));
15556 end if;
15558 if Class_Present (N) then
15559 Set_Has_Inheritable_Invariants (Typ);
15560 end if;
15562 -- The remaining processing is simply to link the pragma on to
15563 -- the rep item chain, for processing when the type is frozen.
15564 -- This is accomplished by a call to Rep_Item_Too_Late.
15566 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
15567 end Invariant;
15569 ----------------------
15570 -- Java_Constructor --
15571 ----------------------
15573 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
15575 -- Also handles pragma CIL_Constructor
15577 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
15578 Java_Constructor : declare
15579 Convention : Convention_Id;
15580 Def_Id : Entity_Id;
15581 Hom_Id : Entity_Id;
15582 Id : Entity_Id;
15583 This_Formal : Entity_Id;
15585 begin
15586 GNAT_Pragma;
15587 Check_Arg_Count (1);
15588 Check_Optional_Identifier (Arg1, Name_Entity);
15589 Check_Arg_Is_Local_Name (Arg1);
15591 Id := Get_Pragma_Arg (Arg1);
15592 Find_Program_Unit_Name (Id);
15594 -- If we did not find the name, we are done
15596 if Etype (Id) = Any_Type then
15597 return;
15598 end if;
15600 -- Check wrong use of pragma in wrong VM target
15602 if VM_Target = No_VM then
15603 return;
15605 elsif VM_Target = CLI_Target
15606 and then Prag_Id = Pragma_Java_Constructor
15607 then
15608 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
15610 elsif VM_Target = JVM_Target
15611 and then Prag_Id = Pragma_CIL_Constructor
15612 then
15613 Error_Pragma ("must use pragma 'Java_'Constructor");
15614 end if;
15616 case Prag_Id is
15617 when Pragma_CIL_Constructor => Convention := Convention_CIL;
15618 when Pragma_Java_Constructor => Convention := Convention_Java;
15619 when others => null;
15620 end case;
15622 Hom_Id := Entity (Id);
15624 -- Loop through homonyms
15626 loop
15627 Def_Id := Get_Base_Subprogram (Hom_Id);
15629 -- The constructor is required to be a function
15631 if Ekind (Def_Id) /= E_Function then
15632 if VM_Target = JVM_Target then
15633 Error_Pragma_Arg
15634 ("pragma% requires function returning a 'Java access "
15635 & "type", Def_Id);
15636 else
15637 Error_Pragma_Arg
15638 ("pragma% requires function returning a 'C'I'L access "
15639 & "type", Def_Id);
15640 end if;
15641 end if;
15643 -- Check arguments: For tagged type the first formal must be
15644 -- named "this" and its type must be a named access type
15645 -- designating a class-wide tagged type that has convention
15646 -- CIL/Java. The first formal must also have a null default
15647 -- value. For example:
15649 -- type Typ is tagged ...
15650 -- type Ref is access all Typ;
15651 -- pragma Convention (CIL, Typ);
15653 -- function New_Typ (This : Ref) return Ref;
15654 -- function New_Typ (This : Ref; I : Integer) return Ref;
15655 -- pragma Cil_Constructor (New_Typ);
15657 -- Reason: The first formal must NOT be a primitive of the
15658 -- tagged type.
15660 -- This rule also applies to constructors of delegates used
15661 -- to interface with standard target libraries. For example:
15663 -- type Delegate is access procedure ...
15664 -- pragma Import (CIL, Delegate, ...);
15666 -- function new_Delegate
15667 -- (This : Delegate := null; ... ) return Delegate;
15669 -- For value-types this rule does not apply.
15671 if not Is_Value_Type (Etype (Def_Id)) then
15672 if No (First_Formal (Def_Id)) then
15673 Error_Msg_Name_1 := Pname;
15674 Error_Msg_N ("% function must have parameters", Def_Id);
15675 return;
15676 end if;
15678 -- In the JRE library we have several occurrences in which
15679 -- the "this" parameter is not the first formal.
15681 This_Formal := First_Formal (Def_Id);
15683 -- In the JRE library we have several occurrences in which
15684 -- the "this" parameter is not the first formal. Search for
15685 -- it.
15687 if VM_Target = JVM_Target then
15688 while Present (This_Formal)
15689 and then Get_Name_String (Chars (This_Formal)) /= "this"
15690 loop
15691 Next_Formal (This_Formal);
15692 end loop;
15694 if No (This_Formal) then
15695 This_Formal := First_Formal (Def_Id);
15696 end if;
15697 end if;
15699 -- Warning: The first parameter should be named "this".
15700 -- We temporarily allow it because we have the following
15701 -- case in the Java runtime (file s-osinte.ads) ???
15703 -- function new_Thread
15704 -- (Self_Id : System.Address) return Thread_Id;
15705 -- pragma Java_Constructor (new_Thread);
15707 if VM_Target = JVM_Target
15708 and then Get_Name_String (Chars (First_Formal (Def_Id)))
15709 = "self_id"
15710 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
15711 then
15712 null;
15714 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
15715 Error_Msg_Name_1 := Pname;
15716 Error_Msg_N
15717 ("first formal of % function must be named `this`",
15718 Parent (This_Formal));
15720 elsif not Is_Access_Type (Etype (This_Formal)) then
15721 Error_Msg_Name_1 := Pname;
15722 Error_Msg_N
15723 ("first formal of % function must be an access type",
15724 Parameter_Type (Parent (This_Formal)));
15726 -- For delegates the type of the first formal must be a
15727 -- named access-to-subprogram type (see previous example)
15729 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
15730 and then Ekind (Etype (This_Formal))
15731 /= E_Access_Subprogram_Type
15732 then
15733 Error_Msg_Name_1 := Pname;
15734 Error_Msg_N
15735 ("first formal of % function must be a named access "
15736 & "to subprogram type",
15737 Parameter_Type (Parent (This_Formal)));
15739 -- Warning: We should reject anonymous access types because
15740 -- the constructor must not be handled as a primitive of the
15741 -- tagged type. We temporarily allow it because this profile
15742 -- is currently generated by cil2ada???
15744 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
15745 and then not Ekind_In (Etype (This_Formal),
15746 E_Access_Type,
15747 E_General_Access_Type,
15748 E_Anonymous_Access_Type)
15749 then
15750 Error_Msg_Name_1 := Pname;
15751 Error_Msg_N
15752 ("first formal of % function must be a named access "
15753 & "type", Parameter_Type (Parent (This_Formal)));
15755 elsif Atree.Convention
15756 (Designated_Type (Etype (This_Formal))) /= Convention
15757 then
15758 Error_Msg_Name_1 := Pname;
15760 if Convention = Convention_Java then
15761 Error_Msg_N
15762 ("pragma% requires convention 'Cil in designated "
15763 & "type", Parameter_Type (Parent (This_Formal)));
15764 else
15765 Error_Msg_N
15766 ("pragma% requires convention 'Java in designated "
15767 & "type", Parameter_Type (Parent (This_Formal)));
15768 end if;
15770 elsif No (Expression (Parent (This_Formal)))
15771 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
15772 then
15773 Error_Msg_Name_1 := Pname;
15774 Error_Msg_N
15775 ("pragma% requires first formal with default `null`",
15776 Parameter_Type (Parent (This_Formal)));
15777 end if;
15778 end if;
15780 -- Check result type: the constructor must be a function
15781 -- returning:
15782 -- * a value type (only allowed in the CIL compiler)
15783 -- * an access-to-subprogram type with convention Java/CIL
15784 -- * an access-type designating a type that has convention
15785 -- Java/CIL.
15787 if Is_Value_Type (Etype (Def_Id)) then
15788 null;
15790 -- Access-to-subprogram type with convention Java/CIL
15792 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
15793 if Atree.Convention (Etype (Def_Id)) /= Convention then
15794 if Convention = Convention_Java then
15795 Error_Pragma_Arg
15796 ("pragma% requires function returning a 'Java "
15797 & "access type", Arg1);
15798 else
15799 pragma Assert (Convention = Convention_CIL);
15800 Error_Pragma_Arg
15801 ("pragma% requires function returning a 'C'I'L "
15802 & "access type", Arg1);
15803 end if;
15804 end if;
15806 elsif Is_Access_Type (Etype (Def_Id)) then
15807 if not Ekind_In (Etype (Def_Id), E_Access_Type,
15808 E_General_Access_Type)
15809 or else
15810 Atree.Convention
15811 (Designated_Type (Etype (Def_Id))) /= Convention
15812 then
15813 Error_Msg_Name_1 := Pname;
15815 if Convention = Convention_Java then
15816 Error_Pragma_Arg
15817 ("pragma% requires function returning a named "
15818 & "'Java access type", Arg1);
15819 else
15820 Error_Pragma_Arg
15821 ("pragma% requires function returning a named "
15822 & "'C'I'L access type", Arg1);
15823 end if;
15824 end if;
15825 end if;
15827 Set_Is_Constructor (Def_Id);
15828 Set_Convention (Def_Id, Convention);
15829 Set_Is_Imported (Def_Id);
15831 exit when From_Aspect_Specification (N);
15832 Hom_Id := Homonym (Hom_Id);
15834 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
15835 end loop;
15836 end Java_Constructor;
15838 ----------------------
15839 -- Java_Interface --
15840 ----------------------
15842 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
15844 when Pragma_Java_Interface => Java_Interface : declare
15845 Arg : Node_Id;
15846 Typ : Entity_Id;
15848 begin
15849 GNAT_Pragma;
15850 Check_Arg_Count (1);
15851 Check_Optional_Identifier (Arg1, Name_Entity);
15852 Check_Arg_Is_Local_Name (Arg1);
15854 Arg := Get_Pragma_Arg (Arg1);
15855 Analyze (Arg);
15857 if Etype (Arg) = Any_Type then
15858 return;
15859 end if;
15861 if not Is_Entity_Name (Arg)
15862 or else not Is_Type (Entity (Arg))
15863 then
15864 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
15865 end if;
15867 Typ := Underlying_Type (Entity (Arg));
15869 -- For now simply check some of the semantic constraints on the
15870 -- type. This currently leaves out some restrictions on interface
15871 -- types, namely that the parent type must be java.lang.Object.Typ
15872 -- and that all primitives of the type should be declared
15873 -- abstract. ???
15875 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
15876 Error_Pragma_Arg
15877 ("pragma% requires an abstract tagged type", Arg1);
15879 elsif not Has_Discriminants (Typ)
15880 or else Ekind (Etype (First_Discriminant (Typ)))
15881 /= E_Anonymous_Access_Type
15882 or else
15883 not Is_Class_Wide_Type
15884 (Designated_Type (Etype (First_Discriminant (Typ))))
15885 then
15886 Error_Pragma_Arg
15887 ("type must have a class-wide access discriminant", Arg1);
15888 end if;
15889 end Java_Interface;
15891 ----------------
15892 -- Keep_Names --
15893 ----------------
15895 -- pragma Keep_Names ([On => ] LOCAL_NAME);
15897 when Pragma_Keep_Names => Keep_Names : declare
15898 Arg : Node_Id;
15900 begin
15901 GNAT_Pragma;
15902 Check_Arg_Count (1);
15903 Check_Optional_Identifier (Arg1, Name_On);
15904 Check_Arg_Is_Local_Name (Arg1);
15906 Arg := Get_Pragma_Arg (Arg1);
15907 Analyze (Arg);
15909 if Etype (Arg) = Any_Type then
15910 return;
15911 end if;
15913 if not Is_Entity_Name (Arg)
15914 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
15915 then
15916 Error_Pragma_Arg
15917 ("pragma% requires a local enumeration type", Arg1);
15918 end if;
15920 Set_Discard_Names (Entity (Arg), False);
15921 end Keep_Names;
15923 -------------
15924 -- License --
15925 -------------
15927 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
15929 when Pragma_License =>
15930 GNAT_Pragma;
15932 -- Do not analyze pragma any further in CodePeer mode, to avoid
15933 -- extraneous errors in this implementation-dependent pragma,
15934 -- which has a different profile on other compilers.
15936 if CodePeer_Mode then
15937 return;
15938 end if;
15940 Check_Arg_Count (1);
15941 Check_No_Identifiers;
15942 Check_Valid_Configuration_Pragma;
15943 Check_Arg_Is_Identifier (Arg1);
15945 declare
15946 Sind : constant Source_File_Index :=
15947 Source_Index (Current_Sem_Unit);
15949 begin
15950 case Chars (Get_Pragma_Arg (Arg1)) is
15951 when Name_GPL =>
15952 Set_License (Sind, GPL);
15954 when Name_Modified_GPL =>
15955 Set_License (Sind, Modified_GPL);
15957 when Name_Restricted =>
15958 Set_License (Sind, Restricted);
15960 when Name_Unrestricted =>
15961 Set_License (Sind, Unrestricted);
15963 when others =>
15964 Error_Pragma_Arg ("invalid license name", Arg1);
15965 end case;
15966 end;
15968 ---------------
15969 -- Link_With --
15970 ---------------
15972 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
15974 when Pragma_Link_With => Link_With : declare
15975 Arg : Node_Id;
15977 begin
15978 GNAT_Pragma;
15980 if Operating_Mode = Generate_Code
15981 and then In_Extended_Main_Source_Unit (N)
15982 then
15983 Check_At_Least_N_Arguments (1);
15984 Check_No_Identifiers;
15985 Check_Is_In_Decl_Part_Or_Package_Spec;
15986 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
15987 Start_String;
15989 Arg := Arg1;
15990 while Present (Arg) loop
15991 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
15993 -- Store argument, converting sequences of spaces to a
15994 -- single null character (this is one of the differences
15995 -- in processing between Link_With and Linker_Options).
15997 Arg_Store : declare
15998 C : constant Char_Code := Get_Char_Code (' ');
15999 S : constant String_Id :=
16000 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
16001 L : constant Nat := String_Length (S);
16002 F : Nat := 1;
16004 procedure Skip_Spaces;
16005 -- Advance F past any spaces
16007 -----------------
16008 -- Skip_Spaces --
16009 -----------------
16011 procedure Skip_Spaces is
16012 begin
16013 while F <= L and then Get_String_Char (S, F) = C loop
16014 F := F + 1;
16015 end loop;
16016 end Skip_Spaces;
16018 -- Start of processing for Arg_Store
16020 begin
16021 Skip_Spaces; -- skip leading spaces
16023 -- Loop through characters, changing any embedded
16024 -- sequence of spaces to a single null character (this
16025 -- is how Link_With/Linker_Options differ)
16027 while F <= L loop
16028 if Get_String_Char (S, F) = C then
16029 Skip_Spaces;
16030 exit when F > L;
16031 Store_String_Char (ASCII.NUL);
16033 else
16034 Store_String_Char (Get_String_Char (S, F));
16035 F := F + 1;
16036 end if;
16037 end loop;
16038 end Arg_Store;
16040 Arg := Next (Arg);
16042 if Present (Arg) then
16043 Store_String_Char (ASCII.NUL);
16044 end if;
16045 end loop;
16047 Store_Linker_Option_String (End_String);
16048 end if;
16049 end Link_With;
16051 ------------------
16052 -- Linker_Alias --
16053 ------------------
16055 -- pragma Linker_Alias (
16056 -- [Entity =>] LOCAL_NAME
16057 -- [Target =>] static_string_EXPRESSION);
16059 when Pragma_Linker_Alias =>
16060 GNAT_Pragma;
16061 Check_Arg_Order ((Name_Entity, Name_Target));
16062 Check_Arg_Count (2);
16063 Check_Optional_Identifier (Arg1, Name_Entity);
16064 Check_Optional_Identifier (Arg2, Name_Target);
16065 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16066 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16068 -- The only processing required is to link this item on to the
16069 -- list of rep items for the given entity. This is accomplished
16070 -- by the call to Rep_Item_Too_Late (when no error is detected
16071 -- and False is returned).
16073 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
16074 return;
16075 else
16076 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
16077 end if;
16079 ------------------------
16080 -- Linker_Constructor --
16081 ------------------------
16083 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
16085 -- Code is shared with Linker_Destructor
16087 -----------------------
16088 -- Linker_Destructor --
16089 -----------------------
16091 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
16093 when Pragma_Linker_Constructor |
16094 Pragma_Linker_Destructor =>
16095 Linker_Constructor : declare
16096 Arg1_X : Node_Id;
16097 Proc : Entity_Id;
16099 begin
16100 GNAT_Pragma;
16101 Check_Arg_Count (1);
16102 Check_No_Identifiers;
16103 Check_Arg_Is_Local_Name (Arg1);
16104 Arg1_X := Get_Pragma_Arg (Arg1);
16105 Analyze (Arg1_X);
16106 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
16108 if not Is_Library_Level_Entity (Proc) then
16109 Error_Pragma_Arg
16110 ("argument for pragma% must be library level entity", Arg1);
16111 end if;
16113 -- The only processing required is to link this item on to the
16114 -- list of rep items for the given entity. This is accomplished
16115 -- by the call to Rep_Item_Too_Late (when no error is detected
16116 -- and False is returned).
16118 if Rep_Item_Too_Late (Proc, N) then
16119 return;
16120 else
16121 Set_Has_Gigi_Rep_Item (Proc);
16122 end if;
16123 end Linker_Constructor;
16125 --------------------
16126 -- Linker_Options --
16127 --------------------
16129 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
16131 when Pragma_Linker_Options => Linker_Options : declare
16132 Arg : Node_Id;
16134 begin
16135 Check_Ada_83_Warning;
16136 Check_No_Identifiers;
16137 Check_Arg_Count (1);
16138 Check_Is_In_Decl_Part_Or_Package_Spec;
16139 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
16140 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
16142 Arg := Arg2;
16143 while Present (Arg) loop
16144 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
16145 Store_String_Char (ASCII.NUL);
16146 Store_String_Chars
16147 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
16148 Arg := Next (Arg);
16149 end loop;
16151 if Operating_Mode = Generate_Code
16152 and then In_Extended_Main_Source_Unit (N)
16153 then
16154 Store_Linker_Option_String (End_String);
16155 end if;
16156 end Linker_Options;
16158 --------------------
16159 -- Linker_Section --
16160 --------------------
16162 -- pragma Linker_Section (
16163 -- [Entity =>] LOCAL_NAME
16164 -- [Section =>] static_string_EXPRESSION);
16166 when Pragma_Linker_Section => Linker_Section : declare
16167 Arg : Node_Id;
16168 Ent : Entity_Id;
16169 LPE : Node_Id;
16171 begin
16172 GNAT_Pragma;
16173 Check_Arg_Order ((Name_Entity, Name_Section));
16174 Check_Arg_Count (2);
16175 Check_Optional_Identifier (Arg1, Name_Entity);
16176 Check_Optional_Identifier (Arg2, Name_Section);
16177 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16178 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16180 -- Check kind of entity
16182 Arg := Get_Pragma_Arg (Arg1);
16183 Ent := Entity (Arg);
16185 case Ekind (Ent) is
16187 -- Objects (constants and variables) and types. For these cases
16188 -- all we need to do is to set the Linker_Section_pragma field,
16189 -- checking that we do not have a duplicate.
16191 when E_Constant | E_Variable | Type_Kind =>
16192 LPE := Linker_Section_Pragma (Ent);
16194 if Present (LPE) then
16195 Error_Msg_Sloc := Sloc (LPE);
16196 Error_Msg_NE
16197 ("Linker_Section already specified for &#", Arg1, Ent);
16198 end if;
16200 Set_Linker_Section_Pragma (Ent, N);
16202 -- Subprograms
16204 when Subprogram_Kind =>
16206 -- Aspect case, entity already set
16208 if From_Aspect_Specification (N) then
16209 Set_Linker_Section_Pragma
16210 (Entity (Corresponding_Aspect (N)), N);
16212 -- Pragma case, we must climb the homonym chain, but skip
16213 -- any for which the linker section is already set.
16215 else
16216 loop
16217 if No (Linker_Section_Pragma (Ent)) then
16218 Set_Linker_Section_Pragma (Ent, N);
16219 end if;
16221 Ent := Homonym (Ent);
16222 exit when No (Ent)
16223 or else Scope (Ent) /= Current_Scope;
16224 end loop;
16225 end if;
16227 -- All other cases are illegal
16229 when others =>
16230 Error_Pragma_Arg
16231 ("pragma% applies only to objects, subprograms, and types",
16232 Arg1);
16233 end case;
16234 end Linker_Section;
16236 ----------
16237 -- List --
16238 ----------
16240 -- pragma List (On | Off)
16242 -- There is nothing to do here, since we did all the processing for
16243 -- this pragma in Par.Prag (so that it works properly even in syntax
16244 -- only mode).
16246 when Pragma_List =>
16247 null;
16249 ---------------
16250 -- Lock_Free --
16251 ---------------
16253 -- pragma Lock_Free [(Boolean_EXPRESSION)];
16255 when Pragma_Lock_Free => Lock_Free : declare
16256 P : constant Node_Id := Parent (N);
16257 Arg : Node_Id;
16258 Ent : Entity_Id;
16259 Val : Boolean;
16261 begin
16262 Check_No_Identifiers;
16263 Check_At_Most_N_Arguments (1);
16265 -- Protected definition case
16267 if Nkind (P) = N_Protected_Definition then
16268 Ent := Defining_Identifier (Parent (P));
16270 -- One argument
16272 if Arg_Count = 1 then
16273 Arg := Get_Pragma_Arg (Arg1);
16274 Val := Is_True (Static_Boolean (Arg));
16276 -- No arguments (expression is considered to be True)
16278 else
16279 Val := True;
16280 end if;
16282 -- Check duplicate pragma before we chain the pragma in the Rep
16283 -- Item chain of Ent.
16285 Check_Duplicate_Pragma (Ent);
16286 Record_Rep_Item (Ent, N);
16287 Set_Uses_Lock_Free (Ent, Val);
16289 -- Anything else is incorrect placement
16291 else
16292 Pragma_Misplaced;
16293 end if;
16294 end Lock_Free;
16296 --------------------
16297 -- Locking_Policy --
16298 --------------------
16300 -- pragma Locking_Policy (policy_IDENTIFIER);
16302 when Pragma_Locking_Policy => declare
16303 subtype LP_Range is Name_Id
16304 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
16305 LP_Val : LP_Range;
16306 LP : Character;
16308 begin
16309 Check_Ada_83_Warning;
16310 Check_Arg_Count (1);
16311 Check_No_Identifiers;
16312 Check_Arg_Is_Locking_Policy (Arg1);
16313 Check_Valid_Configuration_Pragma;
16314 LP_Val := Chars (Get_Pragma_Arg (Arg1));
16316 case LP_Val is
16317 when Name_Ceiling_Locking =>
16318 LP := 'C';
16319 when Name_Inheritance_Locking =>
16320 LP := 'I';
16321 when Name_Concurrent_Readers_Locking =>
16322 LP := 'R';
16323 end case;
16325 if Locking_Policy /= ' '
16326 and then Locking_Policy /= LP
16327 then
16328 Error_Msg_Sloc := Locking_Policy_Sloc;
16329 Error_Pragma ("locking policy incompatible with policy#");
16331 -- Set new policy, but always preserve System_Location since we
16332 -- like the error message with the run time name.
16334 else
16335 Locking_Policy := LP;
16337 if Locking_Policy_Sloc /= System_Location then
16338 Locking_Policy_Sloc := Loc;
16339 end if;
16340 end if;
16341 end;
16343 -------------------
16344 -- Loop_Optimize --
16345 -------------------
16347 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
16349 -- OPTIMIZATION_HINT ::=
16350 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
16352 when Pragma_Loop_Optimize => Loop_Optimize : declare
16353 Hint : Node_Id;
16355 begin
16356 GNAT_Pragma;
16357 Check_At_Least_N_Arguments (1);
16358 Check_No_Identifiers;
16360 Hint := First (Pragma_Argument_Associations (N));
16361 while Present (Hint) loop
16362 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
16363 Name_No_Unroll,
16364 Name_Unroll,
16365 Name_No_Vector,
16366 Name_Vector);
16367 Next (Hint);
16368 end loop;
16370 Check_Loop_Pragma_Placement;
16371 end Loop_Optimize;
16373 ------------------
16374 -- Loop_Variant --
16375 ------------------
16377 -- pragma Loop_Variant
16378 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
16380 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
16382 -- CHANGE_DIRECTION ::= Increases | Decreases
16384 when Pragma_Loop_Variant => Loop_Variant : declare
16385 Variant : Node_Id;
16387 begin
16388 GNAT_Pragma;
16389 Check_At_Least_N_Arguments (1);
16390 Check_Loop_Pragma_Placement;
16392 -- Process all increasing / decreasing expressions
16394 Variant := First (Pragma_Argument_Associations (N));
16395 while Present (Variant) loop
16396 if not Nam_In (Chars (Variant), Name_Decreases,
16397 Name_Increases)
16398 then
16399 Error_Pragma_Arg ("wrong change modifier", Variant);
16400 end if;
16402 Preanalyze_Assert_Expression
16403 (Expression (Variant), Any_Discrete);
16405 Next (Variant);
16406 end loop;
16407 end Loop_Variant;
16409 -----------------------
16410 -- Machine_Attribute --
16411 -----------------------
16413 -- pragma Machine_Attribute (
16414 -- [Entity =>] LOCAL_NAME,
16415 -- [Attribute_Name =>] static_string_EXPRESSION
16416 -- [, [Info =>] static_EXPRESSION] );
16418 when Pragma_Machine_Attribute => Machine_Attribute : declare
16419 Def_Id : Entity_Id;
16421 begin
16422 GNAT_Pragma;
16423 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
16425 if Arg_Count = 3 then
16426 Check_Optional_Identifier (Arg3, Name_Info);
16427 Check_Arg_Is_OK_Static_Expression (Arg3);
16428 else
16429 Check_Arg_Count (2);
16430 end if;
16432 Check_Optional_Identifier (Arg1, Name_Entity);
16433 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
16434 Check_Arg_Is_Local_Name (Arg1);
16435 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16436 Def_Id := Entity (Get_Pragma_Arg (Arg1));
16438 if Is_Access_Type (Def_Id) then
16439 Def_Id := Designated_Type (Def_Id);
16440 end if;
16442 if Rep_Item_Too_Early (Def_Id, N) then
16443 return;
16444 end if;
16446 Def_Id := Underlying_Type (Def_Id);
16448 -- The only processing required is to link this item on to the
16449 -- list of rep items for the given entity. This is accomplished
16450 -- by the call to Rep_Item_Too_Late (when no error is detected
16451 -- and False is returned).
16453 if Rep_Item_Too_Late (Def_Id, N) then
16454 return;
16455 else
16456 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
16457 end if;
16458 end Machine_Attribute;
16460 ----------
16461 -- Main --
16462 ----------
16464 -- pragma Main
16465 -- (MAIN_OPTION [, MAIN_OPTION]);
16467 -- MAIN_OPTION ::=
16468 -- [STACK_SIZE =>] static_integer_EXPRESSION
16469 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
16470 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
16472 when Pragma_Main => Main : declare
16473 Args : Args_List (1 .. 3);
16474 Names : constant Name_List (1 .. 3) := (
16475 Name_Stack_Size,
16476 Name_Task_Stack_Size_Default,
16477 Name_Time_Slicing_Enabled);
16479 Nod : Node_Id;
16481 begin
16482 GNAT_Pragma;
16483 Gather_Associations (Names, Args);
16485 for J in 1 .. 2 loop
16486 if Present (Args (J)) then
16487 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
16488 end if;
16489 end loop;
16491 if Present (Args (3)) then
16492 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
16493 end if;
16495 Nod := Next (N);
16496 while Present (Nod) loop
16497 if Nkind (Nod) = N_Pragma
16498 and then Pragma_Name (Nod) = Name_Main
16499 then
16500 Error_Msg_Name_1 := Pname;
16501 Error_Msg_N ("duplicate pragma% not permitted", Nod);
16502 end if;
16504 Next (Nod);
16505 end loop;
16506 end Main;
16508 ------------------
16509 -- Main_Storage --
16510 ------------------
16512 -- pragma Main_Storage
16513 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
16515 -- MAIN_STORAGE_OPTION ::=
16516 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
16517 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
16519 when Pragma_Main_Storage => Main_Storage : declare
16520 Args : Args_List (1 .. 2);
16521 Names : constant Name_List (1 .. 2) := (
16522 Name_Working_Storage,
16523 Name_Top_Guard);
16525 Nod : Node_Id;
16527 begin
16528 GNAT_Pragma;
16529 Gather_Associations (Names, Args);
16531 for J in 1 .. 2 loop
16532 if Present (Args (J)) then
16533 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
16534 end if;
16535 end loop;
16537 Check_In_Main_Program;
16539 Nod := Next (N);
16540 while Present (Nod) loop
16541 if Nkind (Nod) = N_Pragma
16542 and then Pragma_Name (Nod) = Name_Main_Storage
16543 then
16544 Error_Msg_Name_1 := Pname;
16545 Error_Msg_N ("duplicate pragma% not permitted", Nod);
16546 end if;
16548 Next (Nod);
16549 end loop;
16550 end Main_Storage;
16552 -----------------
16553 -- Memory_Size --
16554 -----------------
16556 -- pragma Memory_Size (NUMERIC_LITERAL)
16558 when Pragma_Memory_Size =>
16559 GNAT_Pragma;
16561 -- Memory size is simply ignored
16563 Check_No_Identifiers;
16564 Check_Arg_Count (1);
16565 Check_Arg_Is_Integer_Literal (Arg1);
16567 -------------
16568 -- No_Body --
16569 -------------
16571 -- pragma No_Body;
16573 -- The only correct use of this pragma is on its own in a file, in
16574 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
16575 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
16576 -- check for a file containing nothing but a No_Body pragma). If we
16577 -- attempt to process it during normal semantics processing, it means
16578 -- it was misplaced.
16580 when Pragma_No_Body =>
16581 GNAT_Pragma;
16582 Pragma_Misplaced;
16584 -----------------------------
16585 -- No_Elaboration_Code_All --
16586 -----------------------------
16588 -- pragma No_Elaboration_Code_All;
16590 when Pragma_No_Elaboration_Code_All => NECA : declare
16591 begin
16592 GNAT_Pragma;
16593 Check_Valid_Library_Unit_Pragma;
16595 if Nkind (N) = N_Null_Statement then
16596 return;
16597 end if;
16599 -- Must appear for a spec or generic spec
16601 if not Nkind_In (Unit (Cunit (Current_Sem_Unit)),
16602 N_Generic_Package_Declaration,
16603 N_Generic_Subprogram_Declaration,
16604 N_Package_Declaration,
16605 N_Subprogram_Declaration)
16606 then
16607 Error_Pragma
16608 (Fix_Error
16609 ("pragma% can only occur for package "
16610 & "or subprogram spec"));
16611 end if;
16613 -- Set flag in unit table
16615 Set_No_Elab_Code_All (Current_Sem_Unit);
16617 -- Set restriction No_Elaboration_Code if this is the main unit
16619 if Current_Sem_Unit = Main_Unit then
16620 Set_Restriction (No_Elaboration_Code, N);
16621 end if;
16623 -- If we are in the main unit or in an extended main source unit,
16624 -- then we also add it to the configuration restrictions so that
16625 -- it will apply to all units in the extended main source.
16627 if Current_Sem_Unit = Main_Unit
16628 or else In_Extended_Main_Source_Unit (N)
16629 then
16630 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
16631 end if;
16633 -- If in main extended unit, activate transitive with test
16635 if In_Extended_Main_Source_Unit (N) then
16636 Opt.No_Elab_Code_All_Pragma := N;
16637 end if;
16638 end NECA;
16640 ---------------
16641 -- No_Inline --
16642 ---------------
16644 -- pragma No_Inline ( NAME {, NAME} );
16646 when Pragma_No_Inline =>
16647 GNAT_Pragma;
16648 Process_Inline (Suppressed);
16650 ---------------
16651 -- No_Return --
16652 ---------------
16654 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
16656 when Pragma_No_Return => No_Return : declare
16657 Id : Node_Id;
16658 E : Entity_Id;
16659 Found : Boolean;
16660 Arg : Node_Id;
16662 begin
16663 Ada_2005_Pragma;
16664 Check_At_Least_N_Arguments (1);
16666 -- Loop through arguments of pragma
16668 Arg := Arg1;
16669 while Present (Arg) loop
16670 Check_Arg_Is_Local_Name (Arg);
16671 Id := Get_Pragma_Arg (Arg);
16672 Analyze (Id);
16674 if not Is_Entity_Name (Id) then
16675 Error_Pragma_Arg ("entity name required", Arg);
16676 end if;
16678 if Etype (Id) = Any_Type then
16679 raise Pragma_Exit;
16680 end if;
16682 -- Loop to find matching procedures
16684 E := Entity (Id);
16685 Found := False;
16686 while Present (E)
16687 and then Scope (E) = Current_Scope
16688 loop
16689 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
16690 Set_No_Return (E);
16692 -- Set flag on any alias as well
16694 if Is_Overloadable (E) and then Present (Alias (E)) then
16695 Set_No_Return (Alias (E));
16696 end if;
16698 Found := True;
16699 end if;
16701 exit when From_Aspect_Specification (N);
16702 E := Homonym (E);
16703 end loop;
16705 -- If entity in not in current scope it may be the enclosing
16706 -- suprogram body to which the aspect applies.
16708 if not Found then
16709 if Entity (Id) = Current_Scope
16710 and then From_Aspect_Specification (N)
16711 then
16712 Set_No_Return (Entity (Id));
16713 else
16714 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
16715 end if;
16716 end if;
16718 Next (Arg);
16719 end loop;
16720 end No_Return;
16722 -----------------
16723 -- No_Run_Time --
16724 -----------------
16726 -- pragma No_Run_Time;
16728 -- Note: this pragma is retained for backwards compatibility. See
16729 -- body of Rtsfind for full details on its handling.
16731 when Pragma_No_Run_Time =>
16732 GNAT_Pragma;
16733 Check_Valid_Configuration_Pragma;
16734 Check_Arg_Count (0);
16736 No_Run_Time_Mode := True;
16737 Configurable_Run_Time_Mode := True;
16739 -- Set Duration to 32 bits if word size is 32
16741 if Ttypes.System_Word_Size = 32 then
16742 Duration_32_Bits_On_Target := True;
16743 end if;
16745 -- Set appropriate restrictions
16747 Set_Restriction (No_Finalization, N);
16748 Set_Restriction (No_Exception_Handlers, N);
16749 Set_Restriction (Max_Tasks, N, 0);
16750 Set_Restriction (No_Tasking, N);
16752 -----------------------
16753 -- No_Tagged_Streams --
16754 -----------------------
16756 -- pragma No_Tagged_Streams;
16757 -- pragma No_Tagged_Streams ([Entity => ]tagged_type_local_NAME);
16759 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
16760 E_Id : Node_Id;
16761 E : Entity_Id;
16763 begin
16764 GNAT_Pragma;
16765 Check_At_Most_N_Arguments (1);
16767 -- One argument case
16769 if Arg_Count = 1 then
16770 Check_Optional_Identifier (Arg1, Name_Entity);
16771 Check_Arg_Is_Local_Name (Arg1);
16772 E_Id := Get_Pragma_Arg (Arg1);
16774 if Etype (E_Id) = Any_Type then
16775 return;
16776 end if;
16778 E := Entity (E_Id);
16780 Check_Duplicate_Pragma (E);
16782 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
16783 Error_Pragma_Arg
16784 ("argument for pragma% must be root tagged type", Arg1);
16785 end if;
16787 if Rep_Item_Too_Early (E, N)
16788 or else
16789 Rep_Item_Too_Late (E, N)
16790 then
16791 return;
16792 else
16793 Set_No_Tagged_Streams_Pragma (E, N);
16794 end if;
16796 -- Zero argument case
16798 else
16799 Check_Is_In_Decl_Part_Or_Package_Spec;
16800 No_Tagged_Streams := N;
16801 end if;
16802 end No_Tagged_Strms;
16804 ------------------------
16805 -- No_Strict_Aliasing --
16806 ------------------------
16808 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
16810 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
16811 E_Id : Entity_Id;
16813 begin
16814 GNAT_Pragma;
16815 Check_At_Most_N_Arguments (1);
16817 if Arg_Count = 0 then
16818 Check_Valid_Configuration_Pragma;
16819 Opt.No_Strict_Aliasing := True;
16821 else
16822 Check_Optional_Identifier (Arg2, Name_Entity);
16823 Check_Arg_Is_Local_Name (Arg1);
16824 E_Id := Entity (Get_Pragma_Arg (Arg1));
16826 if E_Id = Any_Type then
16827 return;
16828 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
16829 Error_Pragma_Arg ("pragma% requires access type", Arg1);
16830 end if;
16832 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
16833 end if;
16834 end No_Strict_Aliasing;
16836 -----------------------
16837 -- Normalize_Scalars --
16838 -----------------------
16840 -- pragma Normalize_Scalars;
16842 when Pragma_Normalize_Scalars =>
16843 Check_Ada_83_Warning;
16844 Check_Arg_Count (0);
16845 Check_Valid_Configuration_Pragma;
16847 -- Normalize_Scalars creates false positives in CodePeer, and
16848 -- incorrect negative results in GNATprove mode, so ignore this
16849 -- pragma in these modes.
16851 if not (CodePeer_Mode or GNATprove_Mode) then
16852 Normalize_Scalars := True;
16853 Init_Or_Norm_Scalars := True;
16854 end if;
16856 -----------------
16857 -- Obsolescent --
16858 -----------------
16860 -- pragma Obsolescent;
16862 -- pragma Obsolescent (
16863 -- [Message =>] static_string_EXPRESSION
16864 -- [,[Version =>] Ada_05]]);
16866 -- pragma Obsolescent (
16867 -- [Entity =>] NAME
16868 -- [,[Message =>] static_string_EXPRESSION
16869 -- [,[Version =>] Ada_05]] );
16871 when Pragma_Obsolescent => Obsolescent : declare
16872 Ename : Node_Id;
16873 Decl : Node_Id;
16875 procedure Set_Obsolescent (E : Entity_Id);
16876 -- Given an entity Ent, mark it as obsolescent if appropriate
16878 ---------------------
16879 -- Set_Obsolescent --
16880 ---------------------
16882 procedure Set_Obsolescent (E : Entity_Id) is
16883 Active : Boolean;
16884 Ent : Entity_Id;
16885 S : String_Id;
16887 begin
16888 Active := True;
16889 Ent := E;
16891 -- Entity name was given
16893 if Present (Ename) then
16895 -- If entity name matches, we are fine. Save entity in
16896 -- pragma argument, for ASIS use.
16898 if Chars (Ename) = Chars (Ent) then
16899 Set_Entity (Ename, Ent);
16900 Generate_Reference (Ent, Ename);
16902 -- If entity name does not match, only possibility is an
16903 -- enumeration literal from an enumeration type declaration.
16905 elsif Ekind (Ent) /= E_Enumeration_Type then
16906 Error_Pragma
16907 ("pragma % entity name does not match declaration");
16909 else
16910 Ent := First_Literal (E);
16911 loop
16912 if No (Ent) then
16913 Error_Pragma
16914 ("pragma % entity name does not match any "
16915 & "enumeration literal");
16917 elsif Chars (Ent) = Chars (Ename) then
16918 Set_Entity (Ename, Ent);
16919 Generate_Reference (Ent, Ename);
16920 exit;
16922 else
16923 Ent := Next_Literal (Ent);
16924 end if;
16925 end loop;
16926 end if;
16927 end if;
16929 -- Ent points to entity to be marked
16931 if Arg_Count >= 1 then
16933 -- Deal with static string argument
16935 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
16936 S := Strval (Get_Pragma_Arg (Arg1));
16938 for J in 1 .. String_Length (S) loop
16939 if not In_Character_Range (Get_String_Char (S, J)) then
16940 Error_Pragma_Arg
16941 ("pragma% argument does not allow wide characters",
16942 Arg1);
16943 end if;
16944 end loop;
16946 Obsolescent_Warnings.Append
16947 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
16949 -- Check for Ada_05 parameter
16951 if Arg_Count /= 1 then
16952 Check_Arg_Count (2);
16954 declare
16955 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
16957 begin
16958 Check_Arg_Is_Identifier (Argx);
16960 if Chars (Argx) /= Name_Ada_05 then
16961 Error_Msg_Name_2 := Name_Ada_05;
16962 Error_Pragma_Arg
16963 ("only allowed argument for pragma% is %", Argx);
16964 end if;
16966 if Ada_Version_Explicit < Ada_2005
16967 or else not Warn_On_Ada_2005_Compatibility
16968 then
16969 Active := False;
16970 end if;
16971 end;
16972 end if;
16973 end if;
16975 -- Set flag if pragma active
16977 if Active then
16978 Set_Is_Obsolescent (Ent);
16979 end if;
16981 return;
16982 end Set_Obsolescent;
16984 -- Start of processing for pragma Obsolescent
16986 begin
16987 GNAT_Pragma;
16989 Check_At_Most_N_Arguments (3);
16991 -- See if first argument specifies an entity name
16993 if Arg_Count >= 1
16994 and then
16995 (Chars (Arg1) = Name_Entity
16996 or else
16997 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
16998 N_Identifier,
16999 N_Operator_Symbol))
17000 then
17001 Ename := Get_Pragma_Arg (Arg1);
17003 -- Eliminate first argument, so we can share processing
17005 Arg1 := Arg2;
17006 Arg2 := Arg3;
17007 Arg_Count := Arg_Count - 1;
17009 -- No Entity name argument given
17011 else
17012 Ename := Empty;
17013 end if;
17015 if Arg_Count >= 1 then
17016 Check_Optional_Identifier (Arg1, Name_Message);
17018 if Arg_Count = 2 then
17019 Check_Optional_Identifier (Arg2, Name_Version);
17020 end if;
17021 end if;
17023 -- Get immediately preceding declaration
17025 Decl := Prev (N);
17026 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
17027 Prev (Decl);
17028 end loop;
17030 -- Cases where we do not follow anything other than another pragma
17032 if No (Decl) then
17034 -- First case: library level compilation unit declaration with
17035 -- the pragma immediately following the declaration.
17037 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
17038 Set_Obsolescent
17039 (Defining_Entity (Unit (Parent (Parent (N)))));
17040 return;
17042 -- Case 2: library unit placement for package
17044 else
17045 declare
17046 Ent : constant Entity_Id := Find_Lib_Unit_Name;
17047 begin
17048 if Is_Package_Or_Generic_Package (Ent) then
17049 Set_Obsolescent (Ent);
17050 return;
17051 end if;
17052 end;
17053 end if;
17055 -- Cases where we must follow a declaration, including an
17056 -- abstract subprogram declaration, which is not in the
17057 -- other node subtypes.
17059 else
17060 if Nkind (Decl) not in N_Declaration
17061 and then Nkind (Decl) not in N_Later_Decl_Item
17062 and then Nkind (Decl) not in N_Generic_Declaration
17063 and then Nkind (Decl) not in N_Renaming_Declaration
17064 and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration
17065 then
17066 Error_Pragma
17067 ("pragma% misplaced, "
17068 & "must immediately follow a declaration");
17070 else
17071 Set_Obsolescent (Defining_Entity (Decl));
17072 return;
17073 end if;
17074 end if;
17075 end Obsolescent;
17077 --------------
17078 -- Optimize --
17079 --------------
17081 -- pragma Optimize (Time | Space | Off);
17083 -- The actual check for optimize is done in Gigi. Note that this
17084 -- pragma does not actually change the optimization setting, it
17085 -- simply checks that it is consistent with the pragma.
17087 when Pragma_Optimize =>
17088 Check_No_Identifiers;
17089 Check_Arg_Count (1);
17090 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
17092 ------------------------
17093 -- Optimize_Alignment --
17094 ------------------------
17096 -- pragma Optimize_Alignment (Time | Space | Off);
17098 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
17099 GNAT_Pragma;
17100 Check_No_Identifiers;
17101 Check_Arg_Count (1);
17102 Check_Valid_Configuration_Pragma;
17104 declare
17105 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
17106 begin
17107 case Nam is
17108 when Name_Time =>
17109 Opt.Optimize_Alignment := 'T';
17110 when Name_Space =>
17111 Opt.Optimize_Alignment := 'S';
17112 when Name_Off =>
17113 Opt.Optimize_Alignment := 'O';
17114 when others =>
17115 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
17116 end case;
17117 end;
17119 -- Set indication that mode is set locally. If we are in fact in a
17120 -- configuration pragma file, this setting is harmless since the
17121 -- switch will get reset anyway at the start of each unit.
17123 Optimize_Alignment_Local := True;
17124 end Optimize_Alignment;
17126 -------------
17127 -- Ordered --
17128 -------------
17130 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
17132 when Pragma_Ordered => Ordered : declare
17133 Assoc : constant Node_Id := Arg1;
17134 Type_Id : Node_Id;
17135 Typ : Entity_Id;
17137 begin
17138 GNAT_Pragma;
17139 Check_No_Identifiers;
17140 Check_Arg_Count (1);
17141 Check_Arg_Is_Local_Name (Arg1);
17143 Type_Id := Get_Pragma_Arg (Assoc);
17144 Find_Type (Type_Id);
17145 Typ := Entity (Type_Id);
17147 if Typ = Any_Type then
17148 return;
17149 else
17150 Typ := Underlying_Type (Typ);
17151 end if;
17153 if not Is_Enumeration_Type (Typ) then
17154 Error_Pragma ("pragma% must specify enumeration type");
17155 end if;
17157 Check_First_Subtype (Arg1);
17158 Set_Has_Pragma_Ordered (Base_Type (Typ));
17159 end Ordered;
17161 -------------------
17162 -- Overflow_Mode --
17163 -------------------
17165 -- pragma Overflow_Mode
17166 -- ([General => ] MODE [, [Assertions => ] MODE]);
17168 -- MODE := STRICT | MINIMIZED | ELIMINATED
17170 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
17171 -- since System.Bignums makes this assumption. This is true of nearly
17172 -- all (all?) targets.
17174 when Pragma_Overflow_Mode => Overflow_Mode : declare
17175 function Get_Overflow_Mode
17176 (Name : Name_Id;
17177 Arg : Node_Id) return Overflow_Mode_Type;
17178 -- Function to process one pragma argument, Arg. If an identifier
17179 -- is present, it must be Name. Mode type is returned if a valid
17180 -- argument exists, otherwise an error is signalled.
17182 -----------------------
17183 -- Get_Overflow_Mode --
17184 -----------------------
17186 function Get_Overflow_Mode
17187 (Name : Name_Id;
17188 Arg : Node_Id) return Overflow_Mode_Type
17190 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
17192 begin
17193 Check_Optional_Identifier (Arg, Name);
17194 Check_Arg_Is_Identifier (Argx);
17196 if Chars (Argx) = Name_Strict then
17197 return Strict;
17199 elsif Chars (Argx) = Name_Minimized then
17200 return Minimized;
17202 elsif Chars (Argx) = Name_Eliminated then
17203 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
17204 Error_Pragma_Arg
17205 ("Eliminated not implemented on this target", Argx);
17206 else
17207 return Eliminated;
17208 end if;
17210 else
17211 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
17212 end if;
17213 end Get_Overflow_Mode;
17215 -- Start of processing for Overflow_Mode
17217 begin
17218 GNAT_Pragma;
17219 Check_At_Least_N_Arguments (1);
17220 Check_At_Most_N_Arguments (2);
17222 -- Process first argument
17224 Scope_Suppress.Overflow_Mode_General :=
17225 Get_Overflow_Mode (Name_General, Arg1);
17227 -- Case of only one argument
17229 if Arg_Count = 1 then
17230 Scope_Suppress.Overflow_Mode_Assertions :=
17231 Scope_Suppress.Overflow_Mode_General;
17233 -- Case of two arguments present
17235 else
17236 Scope_Suppress.Overflow_Mode_Assertions :=
17237 Get_Overflow_Mode (Name_Assertions, Arg2);
17238 end if;
17239 end Overflow_Mode;
17241 --------------------------
17242 -- Overriding Renamings --
17243 --------------------------
17245 -- pragma Overriding_Renamings;
17247 when Pragma_Overriding_Renamings =>
17248 GNAT_Pragma;
17249 Check_Arg_Count (0);
17250 Check_Valid_Configuration_Pragma;
17251 Overriding_Renamings := True;
17253 ----------
17254 -- Pack --
17255 ----------
17257 -- pragma Pack (first_subtype_LOCAL_NAME);
17259 when Pragma_Pack => Pack : declare
17260 Assoc : constant Node_Id := Arg1;
17261 Type_Id : Node_Id;
17262 Typ : Entity_Id;
17263 Ctyp : Entity_Id;
17264 Ignore : Boolean := False;
17266 begin
17267 Check_No_Identifiers;
17268 Check_Arg_Count (1);
17269 Check_Arg_Is_Local_Name (Arg1);
17270 Type_Id := Get_Pragma_Arg (Assoc);
17272 if not Is_Entity_Name (Type_Id)
17273 or else not Is_Type (Entity (Type_Id))
17274 then
17275 Error_Pragma_Arg
17276 ("argument for pragma% must be type or subtype", Arg1);
17277 end if;
17279 Find_Type (Type_Id);
17280 Typ := Entity (Type_Id);
17282 if Typ = Any_Type
17283 or else Rep_Item_Too_Early (Typ, N)
17284 then
17285 return;
17286 else
17287 Typ := Underlying_Type (Typ);
17288 end if;
17290 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
17291 Error_Pragma ("pragma% must specify array or record type");
17292 end if;
17294 Check_First_Subtype (Arg1);
17295 Check_Duplicate_Pragma (Typ);
17297 -- Array type
17299 if Is_Array_Type (Typ) then
17300 Ctyp := Component_Type (Typ);
17302 -- Ignore pack that does nothing
17304 if Known_Static_Esize (Ctyp)
17305 and then Known_Static_RM_Size (Ctyp)
17306 and then Esize (Ctyp) = RM_Size (Ctyp)
17307 and then Addressable (Esize (Ctyp))
17308 then
17309 Ignore := True;
17310 end if;
17312 -- Process OK pragma Pack. Note that if there is a separate
17313 -- component clause present, the Pack will be cancelled. This
17314 -- processing is in Freeze.
17316 if not Rep_Item_Too_Late (Typ, N) then
17318 -- In CodePeer mode, we do not need complex front-end
17319 -- expansions related to pragma Pack, so disable handling
17320 -- of pragma Pack.
17322 if CodePeer_Mode then
17323 null;
17325 -- Don't attempt any packing for VM targets. We possibly
17326 -- could deal with some cases of array bit-packing, but we
17327 -- don't bother, since this is not a typical kind of
17328 -- representation in the VM context anyway (and would not
17329 -- for example work nicely with the debugger).
17331 elsif VM_Target /= No_VM then
17332 if not GNAT_Mode then
17333 Error_Pragma
17334 ("??pragma% ignored in this configuration");
17335 end if;
17337 -- Normal case where we do the pack action
17339 else
17340 if not Ignore then
17341 Set_Is_Packed (Base_Type (Typ));
17342 Set_Has_Non_Standard_Rep (Base_Type (Typ));
17343 end if;
17345 Set_Has_Pragma_Pack (Base_Type (Typ));
17346 end if;
17347 end if;
17349 -- For record types, the pack is always effective
17351 else pragma Assert (Is_Record_Type (Typ));
17352 if not Rep_Item_Too_Late (Typ, N) then
17354 -- Ignore pack request with warning in VM mode (skip warning
17355 -- if we are compiling GNAT run time library).
17357 if VM_Target /= No_VM then
17358 if not GNAT_Mode then
17359 Error_Pragma
17360 ("??pragma% ignored in this configuration");
17361 end if;
17363 -- Normal case of pack request active
17365 else
17366 Set_Is_Packed (Base_Type (Typ));
17367 Set_Has_Pragma_Pack (Base_Type (Typ));
17368 Set_Has_Non_Standard_Rep (Base_Type (Typ));
17369 end if;
17370 end if;
17371 end if;
17372 end Pack;
17374 ----------
17375 -- Page --
17376 ----------
17378 -- pragma Page;
17380 -- There is nothing to do here, since we did all the processing for
17381 -- this pragma in Par.Prag (so that it works properly even in syntax
17382 -- only mode).
17384 when Pragma_Page =>
17385 null;
17387 -------------
17388 -- Part_Of --
17389 -------------
17391 -- pragma Part_Of (ABSTRACT_STATE);
17393 -- ABSTRACT_STATE ::= NAME
17395 when Pragma_Part_Of => Part_Of : declare
17396 procedure Propagate_Part_Of
17397 (Pack_Id : Entity_Id;
17398 State_Id : Entity_Id;
17399 Instance : Node_Id);
17400 -- Propagate the Part_Of indicator to all abstract states and
17401 -- objects declared in the visible state space of a package
17402 -- denoted by Pack_Id. State_Id is the encapsulating state.
17403 -- Instance is the package instantiation node.
17405 -----------------------
17406 -- Propagate_Part_Of --
17407 -----------------------
17409 procedure Propagate_Part_Of
17410 (Pack_Id : Entity_Id;
17411 State_Id : Entity_Id;
17412 Instance : Node_Id)
17414 Has_Item : Boolean := False;
17415 -- Flag set when the visible state space contains at least one
17416 -- abstract state or variable.
17418 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
17419 -- Propagate the Part_Of indicator to all abstract states and
17420 -- objects declared in the visible state space of a package
17421 -- denoted by Pack_Id.
17423 -----------------------
17424 -- Propagate_Part_Of --
17425 -----------------------
17427 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
17428 Item_Id : Entity_Id;
17430 begin
17431 -- Traverse the entity chain of the package and set relevant
17432 -- attributes of abstract states and objects declared in the
17433 -- visible state space of the package.
17435 Item_Id := First_Entity (Pack_Id);
17436 while Present (Item_Id)
17437 and then not In_Private_Part (Item_Id)
17438 loop
17439 -- Do not consider internally generated items
17441 if not Comes_From_Source (Item_Id) then
17442 null;
17444 -- The Part_Of indicator turns an abstract state or an
17445 -- object into a constituent of the encapsulating state.
17447 elsif Ekind_In (Item_Id, E_Abstract_State,
17448 E_Constant,
17449 E_Variable)
17450 then
17451 Has_Item := True;
17453 Append_Elmt (Item_Id, Part_Of_Constituents (State_Id));
17454 Set_Encapsulating_State (Item_Id, State_Id);
17456 -- Recursively handle nested packages and instantiations
17458 elsif Ekind (Item_Id) = E_Package then
17459 Propagate_Part_Of (Item_Id);
17460 end if;
17462 Next_Entity (Item_Id);
17463 end loop;
17464 end Propagate_Part_Of;
17466 -- Start of processing for Propagate_Part_Of
17468 begin
17469 Propagate_Part_Of (Pack_Id);
17471 -- Detect a package instantiation that is subject to a Part_Of
17472 -- indicator, but has no visible state.
17474 if not Has_Item then
17475 SPARK_Msg_NE
17476 ("package instantiation & has Part_Of indicator but "
17477 & "lacks visible state", Instance, Pack_Id);
17478 end if;
17479 end Propagate_Part_Of;
17481 -- Local variables
17483 Item_Id : Entity_Id;
17484 Legal : Boolean;
17485 State : Node_Id;
17486 State_Id : Entity_Id;
17487 Stmt : Node_Id;
17489 -- Start of processing for Part_Of
17491 begin
17492 GNAT_Pragma;
17493 Check_No_Identifiers;
17494 Check_Arg_Count (1);
17496 -- Ensure the proper placement of the pragma. Part_Of must appear
17497 -- on an object declaration or a package instantiation.
17499 Stmt := Prev (N);
17500 while Present (Stmt) loop
17502 -- Skip prior pragmas, but check for duplicates
17504 if Nkind (Stmt) = N_Pragma then
17505 if Pragma_Name (Stmt) = Pname then
17506 Error_Msg_Name_1 := Pname;
17507 Error_Msg_Sloc := Sloc (Stmt);
17508 Error_Msg_N ("pragma% duplicates pragma declared#", N);
17509 end if;
17511 -- Skip internally generated code
17513 elsif not Comes_From_Source (Stmt) then
17514 null;
17516 -- The pragma applies to an object declaration (possibly a
17517 -- variable) or a package instantiation. Stop the traversal
17518 -- and continue the analysis.
17520 elsif Nkind_In (Stmt, N_Object_Declaration,
17521 N_Package_Instantiation)
17522 then
17523 exit;
17525 -- The pragma does not apply to a legal construct, issue an
17526 -- error and stop the analysis.
17528 else
17529 Pragma_Misplaced;
17530 return;
17531 end if;
17533 Stmt := Prev (Stmt);
17534 end loop;
17536 -- Extract the entity of the related object declaration or package
17537 -- instantiation. In the case of the instantiation, use the entity
17538 -- of the instance spec.
17540 if Nkind (Stmt) = N_Package_Instantiation then
17541 Stmt := Instance_Spec (Stmt);
17542 end if;
17544 Item_Id := Defining_Entity (Stmt);
17545 State := Get_Pragma_Arg (Arg1);
17547 -- Detect any discrepancies between the placement of the object
17548 -- or package instantiation with respect to state space and the
17549 -- encapsulating state.
17551 Analyze_Part_Of
17552 (Item_Id => Item_Id,
17553 State => State,
17554 Indic => N,
17555 Legal => Legal);
17557 if Legal then
17559 -- Constants without "variable input" are not considered part
17560 -- of the hidden state of a package (SPARK RM 7.1.1(2)). As a
17561 -- result such constants do not require a Part_Of indicator.
17563 if Ekind (Item_Id) = E_Constant
17564 and then not Has_Variable_Input (Item_Id)
17565 then
17566 SPARK_Msg_NE
17567 ("useless Part_Of indicator, constant & does not have "
17568 & "variable input", N, Item_Id);
17569 return;
17570 end if;
17572 State_Id := Entity (State);
17574 -- The Part_Of indicator turns an object into a constituent of
17575 -- the encapsulating state.
17577 if Ekind_In (Item_Id, E_Constant, E_Variable) then
17578 Append_Elmt (Item_Id, Part_Of_Constituents (State_Id));
17579 Set_Encapsulating_State (Item_Id, State_Id);
17581 -- Propagate the Part_Of indicator to the visible state space
17582 -- of the package instantiation.
17584 else
17585 Propagate_Part_Of
17586 (Pack_Id => Item_Id,
17587 State_Id => State_Id,
17588 Instance => Stmt);
17589 end if;
17591 -- Add the pragma to the contract of the item. This aids with
17592 -- the detection of a missing but required Part_Of indicator.
17594 Add_Contract_Item (N, Item_Id);
17595 end if;
17596 end Part_Of;
17598 ----------------------------------
17599 -- Partition_Elaboration_Policy --
17600 ----------------------------------
17602 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
17604 when Pragma_Partition_Elaboration_Policy => declare
17605 subtype PEP_Range is Name_Id
17606 range First_Partition_Elaboration_Policy_Name
17607 .. Last_Partition_Elaboration_Policy_Name;
17608 PEP_Val : PEP_Range;
17609 PEP : Character;
17611 begin
17612 Ada_2005_Pragma;
17613 Check_Arg_Count (1);
17614 Check_No_Identifiers;
17615 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
17616 Check_Valid_Configuration_Pragma;
17617 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
17619 case PEP_Val is
17620 when Name_Concurrent =>
17621 PEP := 'C';
17622 when Name_Sequential =>
17623 PEP := 'S';
17624 end case;
17626 if Partition_Elaboration_Policy /= ' '
17627 and then Partition_Elaboration_Policy /= PEP
17628 then
17629 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
17630 Error_Pragma
17631 ("partition elaboration policy incompatible with policy#");
17633 -- Set new policy, but always preserve System_Location since we
17634 -- like the error message with the run time name.
17636 else
17637 Partition_Elaboration_Policy := PEP;
17639 if Partition_Elaboration_Policy_Sloc /= System_Location then
17640 Partition_Elaboration_Policy_Sloc := Loc;
17641 end if;
17642 end if;
17643 end;
17645 -------------
17646 -- Passive --
17647 -------------
17649 -- pragma Passive [(PASSIVE_FORM)];
17651 -- PASSIVE_FORM ::= Semaphore | No
17653 when Pragma_Passive =>
17654 GNAT_Pragma;
17656 if Nkind (Parent (N)) /= N_Task_Definition then
17657 Error_Pragma ("pragma% must be within task definition");
17658 end if;
17660 if Arg_Count /= 0 then
17661 Check_Arg_Count (1);
17662 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
17663 end if;
17665 ----------------------------------
17666 -- Preelaborable_Initialization --
17667 ----------------------------------
17669 -- pragma Preelaborable_Initialization (DIRECT_NAME);
17671 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
17672 Ent : Entity_Id;
17674 begin
17675 Ada_2005_Pragma;
17676 Check_Arg_Count (1);
17677 Check_No_Identifiers;
17678 Check_Arg_Is_Identifier (Arg1);
17679 Check_Arg_Is_Local_Name (Arg1);
17680 Check_First_Subtype (Arg1);
17681 Ent := Entity (Get_Pragma_Arg (Arg1));
17683 -- The pragma may come from an aspect on a private declaration,
17684 -- even if the freeze point at which this is analyzed in the
17685 -- private part after the full view.
17687 if Has_Private_Declaration (Ent)
17688 and then From_Aspect_Specification (N)
17689 then
17690 null;
17692 -- Check appropriate type argument
17694 elsif Is_Private_Type (Ent)
17695 or else Is_Protected_Type (Ent)
17696 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
17698 -- AI05-0028: The pragma applies to all composite types. Note
17699 -- that we apply this binding interpretation to earlier versions
17700 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
17701 -- choice since there are other compilers that do the same.
17703 or else Is_Composite_Type (Ent)
17704 then
17705 null;
17707 else
17708 Error_Pragma_Arg
17709 ("pragma % can only be applied to private, formal derived, "
17710 & "protected, or composite type", Arg1);
17711 end if;
17713 -- Give an error if the pragma is applied to a protected type that
17714 -- does not qualify (due to having entries, or due to components
17715 -- that do not qualify).
17717 if Is_Protected_Type (Ent)
17718 and then not Has_Preelaborable_Initialization (Ent)
17719 then
17720 Error_Msg_N
17721 ("protected type & does not have preelaborable "
17722 & "initialization", Ent);
17724 -- Otherwise mark the type as definitely having preelaborable
17725 -- initialization.
17727 else
17728 Set_Known_To_Have_Preelab_Init (Ent);
17729 end if;
17731 if Has_Pragma_Preelab_Init (Ent)
17732 and then Warn_On_Redundant_Constructs
17733 then
17734 Error_Pragma ("?r?duplicate pragma%!");
17735 else
17736 Set_Has_Pragma_Preelab_Init (Ent);
17737 end if;
17738 end Preelab_Init;
17740 --------------------
17741 -- Persistent_BSS --
17742 --------------------
17744 -- pragma Persistent_BSS [(object_NAME)];
17746 when Pragma_Persistent_BSS => Persistent_BSS : declare
17747 Decl : Node_Id;
17748 Ent : Entity_Id;
17749 Prag : Node_Id;
17751 begin
17752 GNAT_Pragma;
17753 Check_At_Most_N_Arguments (1);
17755 -- Case of application to specific object (one argument)
17757 if Arg_Count = 1 then
17758 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17760 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
17761 or else not
17762 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
17763 E_Constant)
17764 then
17765 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
17766 end if;
17768 Ent := Entity (Get_Pragma_Arg (Arg1));
17769 Decl := Parent (Ent);
17771 -- Check for duplication before inserting in list of
17772 -- representation items.
17774 Check_Duplicate_Pragma (Ent);
17776 if Rep_Item_Too_Late (Ent, N) then
17777 return;
17778 end if;
17780 if Present (Expression (Decl)) then
17781 Error_Pragma_Arg
17782 ("object for pragma% cannot have initialization", Arg1);
17783 end if;
17785 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
17786 Error_Pragma_Arg
17787 ("object type for pragma% is not potentially persistent",
17788 Arg1);
17789 end if;
17791 Prag :=
17792 Make_Linker_Section_Pragma
17793 (Ent, Sloc (N), ".persistent.bss");
17794 Insert_After (N, Prag);
17795 Analyze (Prag);
17797 -- Case of use as configuration pragma with no arguments
17799 else
17800 Check_Valid_Configuration_Pragma;
17801 Persistent_BSS_Mode := True;
17802 end if;
17803 end Persistent_BSS;
17805 -------------
17806 -- Polling --
17807 -------------
17809 -- pragma Polling (ON | OFF);
17811 when Pragma_Polling =>
17812 GNAT_Pragma;
17813 Check_Arg_Count (1);
17814 Check_No_Identifiers;
17815 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
17816 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
17818 -----------------------------------
17819 -- Post/Post_Class/Postcondition --
17820 -----------------------------------
17822 -- pragma Post (Boolean_EXPRESSION);
17823 -- pragma Post_Class (Boolean_EXPRESSION);
17824 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
17825 -- [,[Message =>] String_EXPRESSION]);
17827 -- Characteristics:
17829 -- * Analysis - The annotation undergoes initial checks to verify
17830 -- the legal placement and context. Secondary checks preanalyze the
17831 -- expression in:
17833 -- Analyze_Pre_Post_Condition_In_Decl_Part
17835 -- * Expansion - The annotation is expanded during the expansion of
17836 -- the related subprogram [body] contract as performed in:
17838 -- Expand_Subprogram_Contract
17840 -- * Template - The annotation utilizes the generic template of the
17841 -- related subprogram [body] when it is:
17843 -- aspect on subprogram declaration
17844 -- aspect on stand alone subprogram body
17845 -- pragma on stand alone subprogram body
17847 -- The annotation must prepare its own template when it is:
17849 -- pragma on subprogram declaration
17851 -- * Globals - Capture of global references must occur after full
17852 -- analysis.
17854 -- * Instance - The annotation is instantiated automatically when
17855 -- the related generic subprogram [body] is instantiated except for
17856 -- the "pragma on subprogram declaration" case. In that scenario
17857 -- the annotation must instantiate itself.
17859 when Pragma_Post |
17860 Pragma_Post_Class |
17861 Pragma_Postcondition =>
17862 Analyze_Pre_Post_Condition;
17864 --------------------------------
17865 -- Pre/Pre_Class/Precondition --
17866 --------------------------------
17868 -- pragma Pre (Boolean_EXPRESSION);
17869 -- pragma Pre_Class (Boolean_EXPRESSION);
17870 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
17871 -- [,[Message =>] String_EXPRESSION]);
17873 -- Characteristics:
17875 -- * Analysis - The annotation undergoes initial checks to verify
17876 -- the legal placement and context. Secondary checks preanalyze the
17877 -- expression in:
17879 -- Analyze_Pre_Post_Condition_In_Decl_Part
17881 -- * Expansion - The annotation is expanded during the expansion of
17882 -- the related subprogram [body] contract as performed in:
17884 -- Expand_Subprogram_Contract
17886 -- * Template - The annotation utilizes the generic template of the
17887 -- related subprogram [body] when it is:
17889 -- aspect on subprogram declaration
17890 -- aspect on stand alone subprogram body
17891 -- pragma on stand alone subprogram body
17893 -- The annotation must prepare its own template when it is:
17895 -- pragma on subprogram declaration
17897 -- * Globals - Capture of global references must occur after full
17898 -- analysis.
17900 -- * Instance - The annotation is instantiated automatically when
17901 -- the related generic subprogram [body] is instantiated except for
17902 -- the "pragma on subprogram declaration" case. In that scenario
17903 -- the annotation must instantiate itself.
17905 when Pragma_Pre |
17906 Pragma_Pre_Class |
17907 Pragma_Precondition =>
17908 Analyze_Pre_Post_Condition;
17910 ---------------
17911 -- Predicate --
17912 ---------------
17914 -- pragma Predicate
17915 -- ([Entity =>] type_LOCAL_NAME,
17916 -- [Check =>] boolean_EXPRESSION);
17918 when Pragma_Predicate => Predicate : declare
17919 Type_Id : Node_Id;
17920 Typ : Entity_Id;
17921 Discard : Boolean;
17923 begin
17924 GNAT_Pragma;
17925 Check_Arg_Count (2);
17926 Check_Optional_Identifier (Arg1, Name_Entity);
17927 Check_Optional_Identifier (Arg2, Name_Check);
17929 Check_Arg_Is_Local_Name (Arg1);
17931 Type_Id := Get_Pragma_Arg (Arg1);
17932 Find_Type (Type_Id);
17933 Typ := Entity (Type_Id);
17935 if Typ = Any_Type then
17936 return;
17937 end if;
17939 -- The remaining processing is simply to link the pragma on to
17940 -- the rep item chain, for processing when the type is frozen.
17941 -- This is accomplished by a call to Rep_Item_Too_Late. We also
17942 -- mark the type as having predicates.
17944 Set_Has_Predicates (Typ);
17945 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
17946 end Predicate;
17948 ------------------
17949 -- Preelaborate --
17950 ------------------
17952 -- pragma Preelaborate [(library_unit_NAME)];
17954 -- Set the flag Is_Preelaborated of program unit name entity
17956 when Pragma_Preelaborate => Preelaborate : declare
17957 Pa : constant Node_Id := Parent (N);
17958 Pk : constant Node_Kind := Nkind (Pa);
17959 Ent : Entity_Id;
17961 begin
17962 Check_Ada_83_Warning;
17963 Check_Valid_Library_Unit_Pragma;
17965 if Nkind (N) = N_Null_Statement then
17966 return;
17967 end if;
17969 Ent := Find_Lib_Unit_Name;
17970 Check_Duplicate_Pragma (Ent);
17972 -- This filters out pragmas inside generic parents that show up
17973 -- inside instantiations. Pragmas that come from aspects in the
17974 -- unit are not ignored.
17976 if Present (Ent) then
17977 if Pk = N_Package_Specification
17978 and then Present (Generic_Parent (Pa))
17979 and then not From_Aspect_Specification (N)
17980 then
17981 null;
17983 else
17984 if not Debug_Flag_U then
17985 Set_Is_Preelaborated (Ent);
17986 Set_Suppress_Elaboration_Warnings (Ent);
17987 end if;
17988 end if;
17989 end if;
17990 end Preelaborate;
17992 -------------------------------
17993 -- Prefix_Exception_Messages --
17994 -------------------------------
17996 -- pragma Prefix_Exception_Messages;
17998 when Pragma_Prefix_Exception_Messages =>
17999 GNAT_Pragma;
18000 Check_Valid_Configuration_Pragma;
18001 Check_Arg_Count (0);
18002 Prefix_Exception_Messages := True;
18004 --------------
18005 -- Priority --
18006 --------------
18008 -- pragma Priority (EXPRESSION);
18010 when Pragma_Priority => Priority : declare
18011 P : constant Node_Id := Parent (N);
18012 Arg : Node_Id;
18013 Ent : Entity_Id;
18015 begin
18016 Check_No_Identifiers;
18017 Check_Arg_Count (1);
18019 -- Subprogram case
18021 if Nkind (P) = N_Subprogram_Body then
18022 Check_In_Main_Program;
18024 Ent := Defining_Unit_Name (Specification (P));
18026 if Nkind (Ent) = N_Defining_Program_Unit_Name then
18027 Ent := Defining_Identifier (Ent);
18028 end if;
18030 Arg := Get_Pragma_Arg (Arg1);
18031 Analyze_And_Resolve (Arg, Standard_Integer);
18033 -- Must be static
18035 if not Is_OK_Static_Expression (Arg) then
18036 Flag_Non_Static_Expr
18037 ("main subprogram priority is not static!", Arg);
18038 raise Pragma_Exit;
18040 -- If constraint error, then we already signalled an error
18042 elsif Raises_Constraint_Error (Arg) then
18043 null;
18045 -- Otherwise check in range except if Relaxed_RM_Semantics
18046 -- where we ignore the value if out of range.
18048 else
18049 declare
18050 Val : constant Uint := Expr_Value (Arg);
18051 begin
18052 if not Relaxed_RM_Semantics
18053 and then
18054 (Val < 0
18055 or else Val > Expr_Value (Expression
18056 (Parent (RTE (RE_Max_Priority)))))
18057 then
18058 Error_Pragma_Arg
18059 ("main subprogram priority is out of range", Arg1);
18060 else
18061 Set_Main_Priority
18062 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
18063 end if;
18064 end;
18065 end if;
18067 -- Load an arbitrary entity from System.Tasking.Stages or
18068 -- System.Tasking.Restricted.Stages (depending on the
18069 -- supported profile) to make sure that one of these packages
18070 -- is implicitly with'ed, since we need to have the tasking
18071 -- run time active for the pragma Priority to have any effect.
18072 -- Previously we with'ed the package System.Tasking, but this
18073 -- package does not trigger the required initialization of the
18074 -- run-time library.
18076 declare
18077 Discard : Entity_Id;
18078 pragma Warnings (Off, Discard);
18079 begin
18080 if Restricted_Profile then
18081 Discard := RTE (RE_Activate_Restricted_Tasks);
18082 else
18083 Discard := RTE (RE_Activate_Tasks);
18084 end if;
18085 end;
18087 -- Task or Protected, must be of type Integer
18089 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
18090 Arg := Get_Pragma_Arg (Arg1);
18091 Ent := Defining_Identifier (Parent (P));
18093 -- The expression must be analyzed in the special manner
18094 -- described in "Handling of Default and Per-Object
18095 -- Expressions" in sem.ads.
18097 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
18099 if not Is_OK_Static_Expression (Arg) then
18100 Check_Restriction (Static_Priorities, Arg);
18101 end if;
18103 -- Anything else is incorrect
18105 else
18106 Pragma_Misplaced;
18107 end if;
18109 -- Check duplicate pragma before we chain the pragma in the Rep
18110 -- Item chain of Ent.
18112 Check_Duplicate_Pragma (Ent);
18113 Record_Rep_Item (Ent, N);
18114 end Priority;
18116 -----------------------------------
18117 -- Priority_Specific_Dispatching --
18118 -----------------------------------
18120 -- pragma Priority_Specific_Dispatching (
18121 -- policy_IDENTIFIER,
18122 -- first_priority_EXPRESSION,
18123 -- last_priority_EXPRESSION);
18125 when Pragma_Priority_Specific_Dispatching =>
18126 Priority_Specific_Dispatching : declare
18127 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
18128 -- This is the entity System.Any_Priority;
18130 DP : Character;
18131 Lower_Bound : Node_Id;
18132 Upper_Bound : Node_Id;
18133 Lower_Val : Uint;
18134 Upper_Val : Uint;
18136 begin
18137 Ada_2005_Pragma;
18138 Check_Arg_Count (3);
18139 Check_No_Identifiers;
18140 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
18141 Check_Valid_Configuration_Pragma;
18142 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
18143 DP := Fold_Upper (Name_Buffer (1));
18145 Lower_Bound := Get_Pragma_Arg (Arg2);
18146 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
18147 Lower_Val := Expr_Value (Lower_Bound);
18149 Upper_Bound := Get_Pragma_Arg (Arg3);
18150 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
18151 Upper_Val := Expr_Value (Upper_Bound);
18153 -- It is not allowed to use Task_Dispatching_Policy and
18154 -- Priority_Specific_Dispatching in the same partition.
18156 if Task_Dispatching_Policy /= ' ' then
18157 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
18158 Error_Pragma
18159 ("pragma% incompatible with Task_Dispatching_Policy#");
18161 -- Check lower bound in range
18163 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
18164 or else
18165 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
18166 then
18167 Error_Pragma_Arg
18168 ("first_priority is out of range", Arg2);
18170 -- Check upper bound in range
18172 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
18173 or else
18174 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
18175 then
18176 Error_Pragma_Arg
18177 ("last_priority is out of range", Arg3);
18179 -- Check that the priority range is valid
18181 elsif Lower_Val > Upper_Val then
18182 Error_Pragma
18183 ("last_priority_expression must be greater than or equal to "
18184 & "first_priority_expression");
18186 -- Store the new policy, but always preserve System_Location since
18187 -- we like the error message with the run-time name.
18189 else
18190 -- Check overlapping in the priority ranges specified in other
18191 -- Priority_Specific_Dispatching pragmas within the same
18192 -- partition. We can only check those we know about.
18194 for J in
18195 Specific_Dispatching.First .. Specific_Dispatching.Last
18196 loop
18197 if Specific_Dispatching.Table (J).First_Priority in
18198 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
18199 or else Specific_Dispatching.Table (J).Last_Priority in
18200 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
18201 then
18202 Error_Msg_Sloc :=
18203 Specific_Dispatching.Table (J).Pragma_Loc;
18204 Error_Pragma
18205 ("priority range overlaps with "
18206 & "Priority_Specific_Dispatching#");
18207 end if;
18208 end loop;
18210 -- The use of Priority_Specific_Dispatching is incompatible
18211 -- with Task_Dispatching_Policy.
18213 if Task_Dispatching_Policy /= ' ' then
18214 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
18215 Error_Pragma
18216 ("Priority_Specific_Dispatching incompatible "
18217 & "with Task_Dispatching_Policy#");
18218 end if;
18220 -- The use of Priority_Specific_Dispatching forces ceiling
18221 -- locking policy.
18223 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
18224 Error_Msg_Sloc := Locking_Policy_Sloc;
18225 Error_Pragma
18226 ("Priority_Specific_Dispatching incompatible "
18227 & "with Locking_Policy#");
18229 -- Set the Ceiling_Locking policy, but preserve System_Location
18230 -- since we like the error message with the run time name.
18232 else
18233 Locking_Policy := 'C';
18235 if Locking_Policy_Sloc /= System_Location then
18236 Locking_Policy_Sloc := Loc;
18237 end if;
18238 end if;
18240 -- Add entry in the table
18242 Specific_Dispatching.Append
18243 ((Dispatching_Policy => DP,
18244 First_Priority => UI_To_Int (Lower_Val),
18245 Last_Priority => UI_To_Int (Upper_Val),
18246 Pragma_Loc => Loc));
18247 end if;
18248 end Priority_Specific_Dispatching;
18250 -------------
18251 -- Profile --
18252 -------------
18254 -- pragma Profile (profile_IDENTIFIER);
18256 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
18258 when Pragma_Profile =>
18259 Ada_2005_Pragma;
18260 Check_Arg_Count (1);
18261 Check_Valid_Configuration_Pragma;
18262 Check_No_Identifiers;
18264 declare
18265 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
18267 begin
18268 if Chars (Argx) = Name_Ravenscar then
18269 Set_Ravenscar_Profile (N);
18271 elsif Chars (Argx) = Name_Restricted then
18272 Set_Profile_Restrictions
18273 (Restricted,
18274 N, Warn => Treat_Restrictions_As_Warnings);
18276 elsif Chars (Argx) = Name_Rational then
18277 Set_Rational_Profile;
18279 elsif Chars (Argx) = Name_No_Implementation_Extensions then
18280 Set_Profile_Restrictions
18281 (No_Implementation_Extensions,
18282 N, Warn => Treat_Restrictions_As_Warnings);
18284 else
18285 Error_Pragma_Arg ("& is not a valid profile", Argx);
18286 end if;
18287 end;
18289 ----------------------
18290 -- Profile_Warnings --
18291 ----------------------
18293 -- pragma Profile_Warnings (profile_IDENTIFIER);
18295 -- profile_IDENTIFIER => Restricted | Ravenscar
18297 when Pragma_Profile_Warnings =>
18298 GNAT_Pragma;
18299 Check_Arg_Count (1);
18300 Check_Valid_Configuration_Pragma;
18301 Check_No_Identifiers;
18303 declare
18304 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
18306 begin
18307 if Chars (Argx) = Name_Ravenscar then
18308 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
18310 elsif Chars (Argx) = Name_Restricted then
18311 Set_Profile_Restrictions (Restricted, N, Warn => True);
18313 elsif Chars (Argx) = Name_No_Implementation_Extensions then
18314 Set_Profile_Restrictions
18315 (No_Implementation_Extensions, N, Warn => True);
18317 else
18318 Error_Pragma_Arg ("& is not a valid profile", Argx);
18319 end if;
18320 end;
18322 --------------------------
18323 -- Propagate_Exceptions --
18324 --------------------------
18326 -- pragma Propagate_Exceptions;
18328 -- Note: this pragma is obsolete and has no effect
18330 when Pragma_Propagate_Exceptions =>
18331 GNAT_Pragma;
18332 Check_Arg_Count (0);
18334 if Warn_On_Obsolescent_Feature then
18335 Error_Msg_N
18336 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
18337 "and has no effect?j?", N);
18338 end if;
18340 -----------------------------
18341 -- Provide_Shift_Operators --
18342 -----------------------------
18344 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
18346 when Pragma_Provide_Shift_Operators =>
18347 Provide_Shift_Operators : declare
18348 Ent : Entity_Id;
18350 procedure Declare_Shift_Operator (Nam : Name_Id);
18351 -- Insert declaration and pragma Instrinsic for named shift op
18353 ----------------------------
18354 -- Declare_Shift_Operator --
18355 ----------------------------
18357 procedure Declare_Shift_Operator (Nam : Name_Id) is
18358 Func : Node_Id;
18359 Import : Node_Id;
18361 begin
18362 Func :=
18363 Make_Subprogram_Declaration (Loc,
18364 Make_Function_Specification (Loc,
18365 Defining_Unit_Name =>
18366 Make_Defining_Identifier (Loc, Chars => Nam),
18368 Result_Definition =>
18369 Make_Identifier (Loc, Chars => Chars (Ent)),
18371 Parameter_Specifications => New_List (
18372 Make_Parameter_Specification (Loc,
18373 Defining_Identifier =>
18374 Make_Defining_Identifier (Loc, Name_Value),
18375 Parameter_Type =>
18376 Make_Identifier (Loc, Chars => Chars (Ent))),
18378 Make_Parameter_Specification (Loc,
18379 Defining_Identifier =>
18380 Make_Defining_Identifier (Loc, Name_Amount),
18381 Parameter_Type =>
18382 New_Occurrence_Of (Standard_Natural, Loc)))));
18384 Import :=
18385 Make_Pragma (Loc,
18386 Pragma_Identifier => Make_Identifier (Loc, Name_Import),
18387 Pragma_Argument_Associations => New_List (
18388 Make_Pragma_Argument_Association (Loc,
18389 Expression => Make_Identifier (Loc, Name_Intrinsic)),
18390 Make_Pragma_Argument_Association (Loc,
18391 Expression => Make_Identifier (Loc, Nam))));
18393 Insert_After (N, Import);
18394 Insert_After (N, Func);
18395 end Declare_Shift_Operator;
18397 -- Start of processing for Provide_Shift_Operators
18399 begin
18400 GNAT_Pragma;
18401 Check_Arg_Count (1);
18402 Check_Arg_Is_Local_Name (Arg1);
18404 Arg1 := Get_Pragma_Arg (Arg1);
18406 -- We must have an entity name
18408 if not Is_Entity_Name (Arg1) then
18409 Error_Pragma_Arg
18410 ("pragma % must apply to integer first subtype", Arg1);
18411 end if;
18413 -- If no Entity, means there was a prior error so ignore
18415 if Present (Entity (Arg1)) then
18416 Ent := Entity (Arg1);
18418 -- Apply error checks
18420 if not Is_First_Subtype (Ent) then
18421 Error_Pragma_Arg
18422 ("cannot apply pragma %",
18423 "\& is not a first subtype",
18424 Arg1);
18426 elsif not Is_Integer_Type (Ent) then
18427 Error_Pragma_Arg
18428 ("cannot apply pragma %",
18429 "\& is not an integer type",
18430 Arg1);
18432 elsif Has_Shift_Operator (Ent) then
18433 Error_Pragma_Arg
18434 ("cannot apply pragma %",
18435 "\& already has declared shift operators",
18436 Arg1);
18438 elsif Is_Frozen (Ent) then
18439 Error_Pragma_Arg
18440 ("pragma % appears too late",
18441 "\& is already frozen",
18442 Arg1);
18443 end if;
18445 -- Now declare the operators. We do this during analysis rather
18446 -- than expansion, since we want the operators available if we
18447 -- are operating in -gnatc or ASIS mode.
18449 Declare_Shift_Operator (Name_Rotate_Left);
18450 Declare_Shift_Operator (Name_Rotate_Right);
18451 Declare_Shift_Operator (Name_Shift_Left);
18452 Declare_Shift_Operator (Name_Shift_Right);
18453 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
18454 end if;
18455 end Provide_Shift_Operators;
18457 ------------------
18458 -- Psect_Object --
18459 ------------------
18461 -- pragma Psect_Object (
18462 -- [Internal =>] LOCAL_NAME,
18463 -- [, [External =>] EXTERNAL_SYMBOL]
18464 -- [, [Size =>] EXTERNAL_SYMBOL]);
18466 when Pragma_Psect_Object | Pragma_Common_Object =>
18467 Psect_Object : declare
18468 Args : Args_List (1 .. 3);
18469 Names : constant Name_List (1 .. 3) := (
18470 Name_Internal,
18471 Name_External,
18472 Name_Size);
18474 Internal : Node_Id renames Args (1);
18475 External : Node_Id renames Args (2);
18476 Size : Node_Id renames Args (3);
18478 Def_Id : Entity_Id;
18480 procedure Check_Arg (Arg : Node_Id);
18481 -- Checks that argument is either a string literal or an
18482 -- identifier, and posts error message if not.
18484 ---------------
18485 -- Check_Arg --
18486 ---------------
18488 procedure Check_Arg (Arg : Node_Id) is
18489 begin
18490 if not Nkind_In (Original_Node (Arg),
18491 N_String_Literal,
18492 N_Identifier)
18493 then
18494 Error_Pragma_Arg
18495 ("inappropriate argument for pragma %", Arg);
18496 end if;
18497 end Check_Arg;
18499 -- Start of processing for Common_Object/Psect_Object
18501 begin
18502 GNAT_Pragma;
18503 Gather_Associations (Names, Args);
18504 Process_Extended_Import_Export_Internal_Arg (Internal);
18506 Def_Id := Entity (Internal);
18508 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
18509 Error_Pragma_Arg
18510 ("pragma% must designate an object", Internal);
18511 end if;
18513 Check_Arg (Internal);
18515 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
18516 Error_Pragma_Arg
18517 ("cannot use pragma% for imported/exported object",
18518 Internal);
18519 end if;
18521 if Is_Concurrent_Type (Etype (Internal)) then
18522 Error_Pragma_Arg
18523 ("cannot specify pragma % for task/protected object",
18524 Internal);
18525 end if;
18527 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
18528 or else
18529 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
18530 then
18531 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
18532 end if;
18534 if Ekind (Def_Id) = E_Constant then
18535 Error_Pragma_Arg
18536 ("cannot specify pragma % for a constant", Internal);
18537 end if;
18539 if Is_Record_Type (Etype (Internal)) then
18540 declare
18541 Ent : Entity_Id;
18542 Decl : Entity_Id;
18544 begin
18545 Ent := First_Entity (Etype (Internal));
18546 while Present (Ent) loop
18547 Decl := Declaration_Node (Ent);
18549 if Ekind (Ent) = E_Component
18550 and then Nkind (Decl) = N_Component_Declaration
18551 and then Present (Expression (Decl))
18552 and then Warn_On_Export_Import
18553 then
18554 Error_Msg_N
18555 ("?x?object for pragma % has defaults", Internal);
18556 exit;
18558 else
18559 Next_Entity (Ent);
18560 end if;
18561 end loop;
18562 end;
18563 end if;
18565 if Present (Size) then
18566 Check_Arg (Size);
18567 end if;
18569 if Present (External) then
18570 Check_Arg_Is_External_Name (External);
18571 end if;
18573 -- If all error tests pass, link pragma on to the rep item chain
18575 Record_Rep_Item (Def_Id, N);
18576 end Psect_Object;
18578 ----------
18579 -- Pure --
18580 ----------
18582 -- pragma Pure [(library_unit_NAME)];
18584 when Pragma_Pure => Pure : declare
18585 Ent : Entity_Id;
18587 begin
18588 Check_Ada_83_Warning;
18589 Check_Valid_Library_Unit_Pragma;
18591 if Nkind (N) = N_Null_Statement then
18592 return;
18593 end if;
18595 Ent := Find_Lib_Unit_Name;
18596 Set_Is_Pure (Ent);
18597 Set_Has_Pragma_Pure (Ent);
18598 Set_Suppress_Elaboration_Warnings (Ent);
18599 end Pure;
18601 -------------------
18602 -- Pure_Function --
18603 -------------------
18605 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
18607 when Pragma_Pure_Function => Pure_Function : declare
18608 E_Id : Node_Id;
18609 E : Entity_Id;
18610 Def_Id : Entity_Id;
18611 Effective : Boolean := False;
18613 begin
18614 GNAT_Pragma;
18615 Check_Arg_Count (1);
18616 Check_Optional_Identifier (Arg1, Name_Entity);
18617 Check_Arg_Is_Local_Name (Arg1);
18618 E_Id := Get_Pragma_Arg (Arg1);
18620 if Error_Posted (E_Id) then
18621 return;
18622 end if;
18624 -- Loop through homonyms (overloadings) of referenced entity
18626 E := Entity (E_Id);
18628 if Present (E) then
18629 loop
18630 Def_Id := Get_Base_Subprogram (E);
18632 if not Ekind_In (Def_Id, E_Function,
18633 E_Generic_Function,
18634 E_Operator)
18635 then
18636 Error_Pragma_Arg
18637 ("pragma% requires a function name", Arg1);
18638 end if;
18640 Set_Is_Pure (Def_Id);
18642 if not Has_Pragma_Pure_Function (Def_Id) then
18643 Set_Has_Pragma_Pure_Function (Def_Id);
18644 Effective := True;
18645 end if;
18647 exit when From_Aspect_Specification (N);
18648 E := Homonym (E);
18649 exit when No (E) or else Scope (E) /= Current_Scope;
18650 end loop;
18652 if not Effective
18653 and then Warn_On_Redundant_Constructs
18654 then
18655 Error_Msg_NE
18656 ("pragma Pure_Function on& is redundant?r?",
18657 N, Entity (E_Id));
18658 end if;
18659 end if;
18660 end Pure_Function;
18662 --------------------
18663 -- Queuing_Policy --
18664 --------------------
18666 -- pragma Queuing_Policy (policy_IDENTIFIER);
18668 when Pragma_Queuing_Policy => declare
18669 QP : Character;
18671 begin
18672 Check_Ada_83_Warning;
18673 Check_Arg_Count (1);
18674 Check_No_Identifiers;
18675 Check_Arg_Is_Queuing_Policy (Arg1);
18676 Check_Valid_Configuration_Pragma;
18677 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
18678 QP := Fold_Upper (Name_Buffer (1));
18680 if Queuing_Policy /= ' '
18681 and then Queuing_Policy /= QP
18682 then
18683 Error_Msg_Sloc := Queuing_Policy_Sloc;
18684 Error_Pragma ("queuing policy incompatible with policy#");
18686 -- Set new policy, but always preserve System_Location since we
18687 -- like the error message with the run time name.
18689 else
18690 Queuing_Policy := QP;
18692 if Queuing_Policy_Sloc /= System_Location then
18693 Queuing_Policy_Sloc := Loc;
18694 end if;
18695 end if;
18696 end;
18698 --------------
18699 -- Rational --
18700 --------------
18702 -- pragma Rational, for compatibility with foreign compiler
18704 when Pragma_Rational =>
18705 Set_Rational_Profile;
18707 ------------------------------------
18708 -- Refined_Depends/Refined_Global --
18709 ------------------------------------
18711 -- pragma Refined_Depends (DEPENDENCY_RELATION);
18713 -- DEPENDENCY_RELATION ::=
18714 -- null
18715 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
18717 -- DEPENDENCY_CLAUSE ::=
18718 -- OUTPUT_LIST =>[+] INPUT_LIST
18719 -- | NULL_DEPENDENCY_CLAUSE
18721 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
18723 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
18725 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
18727 -- OUTPUT ::= NAME | FUNCTION_RESULT
18728 -- INPUT ::= NAME
18730 -- where FUNCTION_RESULT is a function Result attribute_reference
18732 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
18734 -- GLOBAL_SPECIFICATION ::=
18735 -- null
18736 -- | GLOBAL_LIST
18737 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
18739 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
18741 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
18742 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
18743 -- GLOBAL_ITEM ::= NAME
18745 -- Characteristics:
18747 -- * Analysis - The annotation undergoes initial checks to verify
18748 -- the legal placement and context. Secondary checks fully analyze
18749 -- the dependency clauses/global list in:
18751 -- Analyze_Refined_Depends_In_Decl_Part
18752 -- Analyze_Refined_Global_In_Decl_Part
18754 -- * Expansion - None.
18756 -- * Template - The annotation utilizes the generic template of the
18757 -- related subprogram body.
18759 -- * Globals - Capture of global references must occur after full
18760 -- analysis.
18762 -- * Instance - The annotation is instantiated automatically when
18763 -- the related generic subprogram body is instantiated.
18765 when Pragma_Refined_Depends |
18766 Pragma_Refined_Global => Refined_Depends_Global :
18767 declare
18768 Body_Id : Entity_Id;
18769 Legal : Boolean;
18770 Spec_Id : Entity_Id;
18772 begin
18773 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
18775 -- Chain the pragma on the contract for further processing by
18776 -- Analyze_Refined_[Depends|Global]_In_Decl_Part.
18778 if Legal then
18779 Add_Contract_Item (N, Body_Id);
18780 end if;
18781 end Refined_Depends_Global;
18783 ------------------
18784 -- Refined_Post --
18785 ------------------
18787 -- pragma Refined_Post (boolean_EXPRESSION);
18789 -- Characteristics:
18791 -- * Analysis - The annotation is fully analyzed immediately upon
18792 -- elaboration as it cannot forward reference entities.
18794 -- * Expansion - The annotation is expanded during the expansion of
18795 -- the related subprogram body contract as performed in:
18797 -- Expand_Subprogram_Contract
18799 -- * Template - The annotation utilizes the generic template of the
18800 -- related subprogram body.
18802 -- * Globals - Capture of global references must occur after full
18803 -- analysis.
18805 -- * Instance - The annotation is instantiated automatically when
18806 -- the related generic subprogram body is instantiated.
18808 when Pragma_Refined_Post => Refined_Post : declare
18809 Body_Id : Entity_Id;
18810 Legal : Boolean;
18811 Spec_Id : Entity_Id;
18813 begin
18814 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
18816 -- Fully analyze the pragma when it appears inside a subprogram
18817 -- body because it cannot benefit from forward references.
18819 if Legal then
18820 Analyze_Pre_Post_Condition_In_Decl_Part (N);
18822 -- Currently it is not possible to inline pre/postconditions on
18823 -- a subprogram subject to pragma Inline_Always.
18825 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
18827 -- Chain the pragma on the contract for completeness
18829 Add_Contract_Item (N, Body_Id);
18830 end if;
18831 end Refined_Post;
18833 -------------------
18834 -- Refined_State --
18835 -------------------
18837 -- pragma Refined_State (REFINEMENT_LIST);
18839 -- REFINEMENT_LIST ::=
18840 -- REFINEMENT_CLAUSE
18841 -- | (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
18843 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
18845 -- CONSTITUENT_LIST ::=
18846 -- null
18847 -- | CONSTITUENT
18848 -- | (CONSTITUENT {, CONSTITUENT})
18850 -- CONSTITUENT ::= object_NAME | state_NAME
18852 -- Characteristics:
18854 -- * Analysis - The annotation undergoes initial checks to verify
18855 -- the legal placement and context. Secondary checks preanalyze the
18856 -- refinement clauses in:
18858 -- Analyze_Refined_State_In_Decl_Part
18860 -- * Expansion - None.
18862 -- * Template - The annotation utilizes the template of the related
18863 -- package body.
18865 -- * Globals - Capture of global references must occur after full
18866 -- analysis.
18868 -- * Instance - The annotation is instantiated automatically when
18869 -- the related generic package body is instantiated.
18871 when Pragma_Refined_State => Refined_State : declare
18872 Pack_Decl : Node_Id;
18873 Spec_Id : Entity_Id;
18875 begin
18876 GNAT_Pragma;
18877 Check_No_Identifiers;
18878 Check_Arg_Count (1);
18880 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
18882 -- Ensure the proper placement of the pragma. Refined states must
18883 -- be associated with a package body.
18885 if Nkind (Pack_Decl) = N_Package_Body then
18886 null;
18888 -- Otherwise the pragma is associated with an illegal construct
18890 else
18891 Pragma_Misplaced;
18892 return;
18893 end if;
18895 Spec_Id := Corresponding_Spec (Pack_Decl);
18897 -- State refinement is allowed only when the corresponding package
18898 -- declaration has non-null pragma Abstract_State. Refinement not
18899 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
18901 if SPARK_Mode /= Off
18902 and then
18903 (No (Abstract_States (Spec_Id))
18904 or else Has_Null_Abstract_State (Spec_Id))
18905 then
18906 Error_Msg_NE
18907 ("useless refinement, package & does not define abstract "
18908 & "states", N, Spec_Id);
18909 return;
18910 end if;
18912 -- Chain the pragma on the contract for further processing by
18913 -- Analyze_Refined_State_In_Decl_Part.
18915 Add_Contract_Item (N, Defining_Entity (Pack_Decl));
18916 end Refined_State;
18918 -----------------------
18919 -- Relative_Deadline --
18920 -----------------------
18922 -- pragma Relative_Deadline (time_span_EXPRESSION);
18924 when Pragma_Relative_Deadline => Relative_Deadline : declare
18925 P : constant Node_Id := Parent (N);
18926 Arg : Node_Id;
18928 begin
18929 Ada_2005_Pragma;
18930 Check_No_Identifiers;
18931 Check_Arg_Count (1);
18933 Arg := Get_Pragma_Arg (Arg1);
18935 -- The expression must be analyzed in the special manner described
18936 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
18938 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
18940 -- Subprogram case
18942 if Nkind (P) = N_Subprogram_Body then
18943 Check_In_Main_Program;
18945 -- Only Task and subprogram cases allowed
18947 elsif Nkind (P) /= N_Task_Definition then
18948 Pragma_Misplaced;
18949 end if;
18951 -- Check duplicate pragma before we set the corresponding flag
18953 if Has_Relative_Deadline_Pragma (P) then
18954 Error_Pragma ("duplicate pragma% not allowed");
18955 end if;
18957 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
18958 -- Relative_Deadline pragma node cannot be inserted in the Rep
18959 -- Item chain of Ent since it is rewritten by the expander as a
18960 -- procedure call statement that will break the chain.
18962 Set_Has_Relative_Deadline_Pragma (P, True);
18963 end Relative_Deadline;
18965 ------------------------
18966 -- Remote_Access_Type --
18967 ------------------------
18969 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
18971 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
18972 E : Entity_Id;
18974 begin
18975 GNAT_Pragma;
18976 Check_Arg_Count (1);
18977 Check_Optional_Identifier (Arg1, Name_Entity);
18978 Check_Arg_Is_Local_Name (Arg1);
18980 E := Entity (Get_Pragma_Arg (Arg1));
18982 if Nkind (Parent (E)) = N_Formal_Type_Declaration
18983 and then Ekind (E) = E_General_Access_Type
18984 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
18985 and then Scope (Root_Type (Directly_Designated_Type (E)))
18986 = Scope (E)
18987 and then Is_Valid_Remote_Object_Type
18988 (Root_Type (Directly_Designated_Type (E)))
18989 then
18990 Set_Is_Remote_Types (E);
18992 else
18993 Error_Pragma_Arg
18994 ("pragma% applies only to formal access to classwide types",
18995 Arg1);
18996 end if;
18997 end Remote_Access_Type;
18999 ---------------------------
19000 -- Remote_Call_Interface --
19001 ---------------------------
19003 -- pragma Remote_Call_Interface [(library_unit_NAME)];
19005 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
19006 Cunit_Node : Node_Id;
19007 Cunit_Ent : Entity_Id;
19008 K : Node_Kind;
19010 begin
19011 Check_Ada_83_Warning;
19012 Check_Valid_Library_Unit_Pragma;
19014 if Nkind (N) = N_Null_Statement then
19015 return;
19016 end if;
19018 Cunit_Node := Cunit (Current_Sem_Unit);
19019 K := Nkind (Unit (Cunit_Node));
19020 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
19022 if K = N_Package_Declaration
19023 or else K = N_Generic_Package_Declaration
19024 or else K = N_Subprogram_Declaration
19025 or else K = N_Generic_Subprogram_Declaration
19026 or else (K = N_Subprogram_Body
19027 and then Acts_As_Spec (Unit (Cunit_Node)))
19028 then
19029 null;
19030 else
19031 Error_Pragma (
19032 "pragma% must apply to package or subprogram declaration");
19033 end if;
19035 Set_Is_Remote_Call_Interface (Cunit_Ent);
19036 end Remote_Call_Interface;
19038 ------------------
19039 -- Remote_Types --
19040 ------------------
19042 -- pragma Remote_Types [(library_unit_NAME)];
19044 when Pragma_Remote_Types => Remote_Types : declare
19045 Cunit_Node : Node_Id;
19046 Cunit_Ent : Entity_Id;
19048 begin
19049 Check_Ada_83_Warning;
19050 Check_Valid_Library_Unit_Pragma;
19052 if Nkind (N) = N_Null_Statement then
19053 return;
19054 end if;
19056 Cunit_Node := Cunit (Current_Sem_Unit);
19057 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
19059 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
19060 N_Generic_Package_Declaration)
19061 then
19062 Error_Pragma
19063 ("pragma% can only apply to a package declaration");
19064 end if;
19066 Set_Is_Remote_Types (Cunit_Ent);
19067 end Remote_Types;
19069 ---------------
19070 -- Ravenscar --
19071 ---------------
19073 -- pragma Ravenscar;
19075 when Pragma_Ravenscar =>
19076 GNAT_Pragma;
19077 Check_Arg_Count (0);
19078 Check_Valid_Configuration_Pragma;
19079 Set_Ravenscar_Profile (N);
19081 if Warn_On_Obsolescent_Feature then
19082 Error_Msg_N
19083 ("pragma Ravenscar is an obsolescent feature?j?", N);
19084 Error_Msg_N
19085 ("|use pragma Profile (Ravenscar) instead?j?", N);
19086 end if;
19088 -------------------------
19089 -- Restricted_Run_Time --
19090 -------------------------
19092 -- pragma Restricted_Run_Time;
19094 when Pragma_Restricted_Run_Time =>
19095 GNAT_Pragma;
19096 Check_Arg_Count (0);
19097 Check_Valid_Configuration_Pragma;
19098 Set_Profile_Restrictions
19099 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
19101 if Warn_On_Obsolescent_Feature then
19102 Error_Msg_N
19103 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
19105 Error_Msg_N
19106 ("|use pragma Profile (Restricted) instead?j?", N);
19107 end if;
19109 ------------------
19110 -- Restrictions --
19111 ------------------
19113 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
19115 -- RESTRICTION ::=
19116 -- restriction_IDENTIFIER
19117 -- | restriction_parameter_IDENTIFIER => EXPRESSION
19119 when Pragma_Restrictions =>
19120 Process_Restrictions_Or_Restriction_Warnings
19121 (Warn => Treat_Restrictions_As_Warnings);
19123 --------------------------
19124 -- Restriction_Warnings --
19125 --------------------------
19127 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
19129 -- RESTRICTION ::=
19130 -- restriction_IDENTIFIER
19131 -- | restriction_parameter_IDENTIFIER => EXPRESSION
19133 when Pragma_Restriction_Warnings =>
19134 GNAT_Pragma;
19135 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
19137 ----------------
19138 -- Reviewable --
19139 ----------------
19141 -- pragma Reviewable;
19143 when Pragma_Reviewable =>
19144 Check_Ada_83_Warning;
19145 Check_Arg_Count (0);
19147 -- Call dummy debugging function rv. This is done to assist front
19148 -- end debugging. By placing a Reviewable pragma in the source
19149 -- program, a breakpoint on rv catches this place in the source,
19150 -- allowing convenient stepping to the point of interest.
19154 --------------------------
19155 -- Short_Circuit_And_Or --
19156 --------------------------
19158 -- pragma Short_Circuit_And_Or;
19160 when Pragma_Short_Circuit_And_Or =>
19161 GNAT_Pragma;
19162 Check_Arg_Count (0);
19163 Check_Valid_Configuration_Pragma;
19164 Short_Circuit_And_Or := True;
19166 -------------------
19167 -- Share_Generic --
19168 -------------------
19170 -- pragma Share_Generic (GNAME {, GNAME});
19172 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
19174 when Pragma_Share_Generic =>
19175 GNAT_Pragma;
19176 Process_Generic_List;
19178 ------------
19179 -- Shared --
19180 ------------
19182 -- pragma Shared (LOCAL_NAME);
19184 when Pragma_Shared =>
19185 GNAT_Pragma;
19186 Process_Atomic_Independent_Shared_Volatile;
19188 --------------------
19189 -- Shared_Passive --
19190 --------------------
19192 -- pragma Shared_Passive [(library_unit_NAME)];
19194 -- Set the flag Is_Shared_Passive of program unit name entity
19196 when Pragma_Shared_Passive => Shared_Passive : declare
19197 Cunit_Node : Node_Id;
19198 Cunit_Ent : Entity_Id;
19200 begin
19201 Check_Ada_83_Warning;
19202 Check_Valid_Library_Unit_Pragma;
19204 if Nkind (N) = N_Null_Statement then
19205 return;
19206 end if;
19208 Cunit_Node := Cunit (Current_Sem_Unit);
19209 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
19211 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
19212 N_Generic_Package_Declaration)
19213 then
19214 Error_Pragma
19215 ("pragma% can only apply to a package declaration");
19216 end if;
19218 Set_Is_Shared_Passive (Cunit_Ent);
19219 end Shared_Passive;
19221 -----------------------
19222 -- Short_Descriptors --
19223 -----------------------
19225 -- pragma Short_Descriptors;
19227 -- Recognize and validate, but otherwise ignore
19229 when Pragma_Short_Descriptors =>
19230 GNAT_Pragma;
19231 Check_Arg_Count (0);
19232 Check_Valid_Configuration_Pragma;
19234 ------------------------------
19235 -- Simple_Storage_Pool_Type --
19236 ------------------------------
19238 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
19240 when Pragma_Simple_Storage_Pool_Type =>
19241 Simple_Storage_Pool_Type : declare
19242 Type_Id : Node_Id;
19243 Typ : Entity_Id;
19245 begin
19246 GNAT_Pragma;
19247 Check_Arg_Count (1);
19248 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19250 Type_Id := Get_Pragma_Arg (Arg1);
19251 Find_Type (Type_Id);
19252 Typ := Entity (Type_Id);
19254 if Typ = Any_Type then
19255 return;
19256 end if;
19258 -- We require the pragma to apply to a type declared in a package
19259 -- declaration, but not (immediately) within a package body.
19261 if Ekind (Current_Scope) /= E_Package
19262 or else In_Package_Body (Current_Scope)
19263 then
19264 Error_Pragma
19265 ("pragma% can only apply to type declared immediately "
19266 & "within a package declaration");
19267 end if;
19269 -- A simple storage pool type must be an immutably limited record
19270 -- or private type. If the pragma is given for a private type,
19271 -- the full type is similarly restricted (which is checked later
19272 -- in Freeze_Entity).
19274 if Is_Record_Type (Typ)
19275 and then not Is_Limited_View (Typ)
19276 then
19277 Error_Pragma
19278 ("pragma% can only apply to explicitly limited record type");
19280 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
19281 Error_Pragma
19282 ("pragma% can only apply to a private type that is limited");
19284 elsif not Is_Record_Type (Typ)
19285 and then not Is_Private_Type (Typ)
19286 then
19287 Error_Pragma
19288 ("pragma% can only apply to limited record or private type");
19289 end if;
19291 Record_Rep_Item (Typ, N);
19292 end Simple_Storage_Pool_Type;
19294 ----------------------
19295 -- Source_File_Name --
19296 ----------------------
19298 -- There are five forms for this pragma:
19300 -- pragma Source_File_Name (
19301 -- [UNIT_NAME =>] unit_NAME,
19302 -- BODY_FILE_NAME => STRING_LITERAL
19303 -- [, [INDEX =>] INTEGER_LITERAL]);
19305 -- pragma Source_File_Name (
19306 -- [UNIT_NAME =>] unit_NAME,
19307 -- SPEC_FILE_NAME => STRING_LITERAL
19308 -- [, [INDEX =>] INTEGER_LITERAL]);
19310 -- pragma Source_File_Name (
19311 -- BODY_FILE_NAME => STRING_LITERAL
19312 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19313 -- [, CASING => CASING_SPEC]);
19315 -- pragma Source_File_Name (
19316 -- SPEC_FILE_NAME => STRING_LITERAL
19317 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19318 -- [, CASING => CASING_SPEC]);
19320 -- pragma Source_File_Name (
19321 -- SUBUNIT_FILE_NAME => STRING_LITERAL
19322 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19323 -- [, CASING => CASING_SPEC]);
19325 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
19327 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
19328 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
19329 -- only be used when no project file is used, while SFNP can only be
19330 -- used when a project file is used.
19332 -- No processing here. Processing was completed during parsing, since
19333 -- we need to have file names set as early as possible. Units are
19334 -- loaded well before semantic processing starts.
19336 -- The only processing we defer to this point is the check for
19337 -- correct placement.
19339 when Pragma_Source_File_Name =>
19340 GNAT_Pragma;
19341 Check_Valid_Configuration_Pragma;
19343 ------------------------------
19344 -- Source_File_Name_Project --
19345 ------------------------------
19347 -- See Source_File_Name for syntax
19349 -- No processing here. Processing was completed during parsing, since
19350 -- we need to have file names set as early as possible. Units are
19351 -- loaded well before semantic processing starts.
19353 -- The only processing we defer to this point is the check for
19354 -- correct placement.
19356 when Pragma_Source_File_Name_Project =>
19357 GNAT_Pragma;
19358 Check_Valid_Configuration_Pragma;
19360 -- Check that a pragma Source_File_Name_Project is used only in a
19361 -- configuration pragmas file.
19363 -- Pragmas Source_File_Name_Project should only be generated by
19364 -- the Project Manager in configuration pragmas files.
19366 -- This is really an ugly test. It seems to depend on some
19367 -- accidental and undocumented property. At the very least it
19368 -- needs to be documented, but it would be better to have a
19369 -- clean way of testing if we are in a configuration file???
19371 if Present (Parent (N)) then
19372 Error_Pragma
19373 ("pragma% can only appear in a configuration pragmas file");
19374 end if;
19376 ----------------------
19377 -- Source_Reference --
19378 ----------------------
19380 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
19382 -- Nothing to do, all processing completed in Par.Prag, since we need
19383 -- the information for possible parser messages that are output.
19385 when Pragma_Source_Reference =>
19386 GNAT_Pragma;
19388 ----------------
19389 -- SPARK_Mode --
19390 ----------------
19392 -- pragma SPARK_Mode [(On | Off)];
19394 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
19395 Mode_Id : SPARK_Mode_Type;
19397 procedure Check_Pragma_Conformance
19398 (Context_Pragma : Node_Id;
19399 Entity_Pragma : Node_Id;
19400 Entity : Entity_Id);
19401 -- If Context_Pragma is not Empty, verify that the new pragma N
19402 -- is compatible with the pragma Context_Pragma that was inherited
19403 -- from the context:
19404 -- . if Context_Pragma is ON, then the new mode can be anything
19405 -- . if Context_Pragma is OFF, then the only allowed new mode is
19406 -- also OFF.
19408 -- If Entity is not Empty, verify that the new pragma N is
19409 -- compatible with Entity_Pragma, the SPARK_Mode previously set
19410 -- for Entity (which may be Empty):
19411 -- . if Entity_Pragma is ON, then the new mode can be anything
19412 -- . if Entity_Pragma is OFF, then the only allowed new mode is
19413 -- also OFF.
19414 -- . if Entity_Pragma is Empty, we always issue an error, as this
19415 -- corresponds to a case where a previous section of Entity
19416 -- had no SPARK_Mode set.
19418 procedure Check_Library_Level_Entity (E : Entity_Id);
19419 -- Verify that pragma is applied to library-level entity E
19421 procedure Set_SPARK_Flags;
19422 -- Sets SPARK_Mode from Mode_Id and SPARK_Mode_Pragma from N,
19423 -- and ensures that Dynamic_Elaboration_Checks are off if the
19424 -- call sets SPARK_Mode On.
19426 ------------------------------
19427 -- Check_Pragma_Conformance --
19428 ------------------------------
19430 procedure Check_Pragma_Conformance
19431 (Context_Pragma : Node_Id;
19432 Entity_Pragma : Node_Id;
19433 Entity : Entity_Id)
19435 Arg : Node_Id := Arg1;
19437 begin
19438 -- The current pragma may appear without an argument. If this
19439 -- is the case, associate all error messages with the pragma
19440 -- itself.
19442 if No (Arg) then
19443 Arg := N;
19444 end if;
19446 -- The mode of the current pragma is compared against that of
19447 -- an enclosing context.
19449 if Present (Context_Pragma) then
19450 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
19452 -- Issue an error if the new mode is less restrictive than
19453 -- that of the context.
19455 if Get_SPARK_Mode_From_Pragma (Context_Pragma) = Off
19456 and then Get_SPARK_Mode_From_Pragma (N) = On
19457 then
19458 Error_Msg_N
19459 ("cannot change SPARK_Mode from Off to On", Arg);
19460 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
19461 Error_Msg_N ("\SPARK_Mode was set to Off#", Arg);
19462 raise Pragma_Exit;
19463 end if;
19464 end if;
19466 -- The mode of the current pragma is compared against that of
19467 -- an initial package/subprogram declaration.
19469 if Present (Entity) then
19471 -- Both the initial declaration and the completion carry
19472 -- SPARK_Mode pragmas.
19474 if Present (Entity_Pragma) then
19475 pragma Assert (Nkind (Entity_Pragma) = N_Pragma);
19477 -- Issue an error if the new mode is less restrictive
19478 -- than that of the initial declaration.
19480 if Get_SPARK_Mode_From_Pragma (Entity_Pragma) = Off
19481 and then Get_SPARK_Mode_From_Pragma (N) = On
19482 then
19483 Error_Msg_N ("incorrect use of SPARK_Mode", Arg);
19484 Error_Msg_Sloc := Sloc (Entity_Pragma);
19485 Error_Msg_NE
19486 ("\value Off was set for SPARK_Mode on&#",
19487 Arg, Entity);
19488 raise Pragma_Exit;
19489 end if;
19491 -- Otherwise the initial declaration lacks a SPARK_Mode
19492 -- pragma in which case the current pragma is illegal as
19493 -- it cannot "complete".
19495 else
19496 Error_Msg_N ("incorrect use of SPARK_Mode", Arg);
19497 Error_Msg_Sloc := Sloc (Entity);
19498 Error_Msg_NE
19499 ("\no value was set for SPARK_Mode on&#",
19500 Arg, Entity);
19501 raise Pragma_Exit;
19502 end if;
19503 end if;
19504 end Check_Pragma_Conformance;
19506 --------------------------------
19507 -- Check_Library_Level_Entity --
19508 --------------------------------
19510 procedure Check_Library_Level_Entity (E : Entity_Id) is
19511 MsgF : constant String := "incorrect placement of pragma%";
19513 begin
19514 if not Is_Library_Level_Entity (E) then
19515 Error_Msg_Name_1 := Pname;
19516 Error_Msg_N (Fix_Error (MsgF), N);
19518 if Ekind_In (E, E_Generic_Package,
19519 E_Package,
19520 E_Package_Body)
19521 then
19522 Error_Msg_NE
19523 ("\& is not a library-level package", N, E);
19524 else
19525 Error_Msg_NE
19526 ("\& is not a library-level subprogram", N, E);
19527 end if;
19529 raise Pragma_Exit;
19530 end if;
19531 end Check_Library_Level_Entity;
19533 ---------------------
19534 -- Set_SPARK_Flags --
19535 ---------------------
19537 procedure Set_SPARK_Flags is
19538 begin
19539 SPARK_Mode := Mode_Id;
19540 SPARK_Mode_Pragma := N;
19542 if SPARK_Mode = On then
19543 Dynamic_Elaboration_Checks := False;
19544 end if;
19545 end Set_SPARK_Flags;
19547 -- Local variables
19549 Body_Id : Entity_Id;
19550 Context : Node_Id;
19551 Mode : Name_Id;
19552 Spec_Id : Entity_Id;
19553 Stmt : Node_Id;
19555 -- Start of processing for Do_SPARK_Mode
19557 begin
19558 -- When a SPARK_Mode pragma appears inside an instantiation whose
19559 -- enclosing context has SPARK_Mode set to "off", the pragma has
19560 -- no semantic effect.
19562 if Ignore_Pragma_SPARK_Mode then
19563 Rewrite (N, Make_Null_Statement (Loc));
19564 Analyze (N);
19565 return;
19566 end if;
19568 GNAT_Pragma;
19569 Check_No_Identifiers;
19570 Check_At_Most_N_Arguments (1);
19572 -- Check the legality of the mode (no argument = ON)
19574 if Arg_Count = 1 then
19575 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
19576 Mode := Chars (Get_Pragma_Arg (Arg1));
19577 else
19578 Mode := Name_On;
19579 end if;
19581 Mode_Id := Get_SPARK_Mode_Type (Mode);
19582 Context := Parent (N);
19584 -- The pragma appears in a configuration pragmas file
19586 if No (Context) then
19587 Check_Valid_Configuration_Pragma;
19589 if Present (SPARK_Mode_Pragma) then
19590 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
19591 Error_Msg_N ("pragma% duplicates pragma declared#", N);
19592 raise Pragma_Exit;
19593 end if;
19595 Set_SPARK_Flags;
19597 -- The pragma acts as a configuration pragma in a compilation unit
19599 -- pragma SPARK_Mode ...;
19600 -- package Pack is ...;
19602 elsif Nkind (Context) = N_Compilation_Unit
19603 and then List_Containing (N) = Context_Items (Context)
19604 then
19605 Check_Valid_Configuration_Pragma;
19606 Set_SPARK_Flags;
19608 -- Otherwise the placement of the pragma within the tree dictates
19609 -- its associated construct. Inspect the declarative list where
19610 -- the pragma resides to find a potential construct.
19612 else
19613 Stmt := Prev (N);
19614 while Present (Stmt) loop
19616 -- Skip prior pragmas, but check for duplicates
19618 if Nkind (Stmt) = N_Pragma then
19619 if Pragma_Name (Stmt) = Pname then
19620 Error_Msg_Name_1 := Pname;
19621 Error_Msg_Sloc := Sloc (Stmt);
19622 Error_Msg_N ("pragma% duplicates pragma declared#", N);
19623 raise Pragma_Exit;
19624 end if;
19626 -- The pragma applies to a [generic] subprogram declaration.
19627 -- Note that this case covers an internally generated spec
19628 -- for a stand alone body.
19630 -- [generic]
19631 -- procedure Proc ...;
19632 -- pragma SPARK_Mode ..;
19634 elsif Nkind_In (Stmt, N_Generic_Subprogram_Declaration,
19635 N_Subprogram_Declaration)
19636 then
19637 Spec_Id := Defining_Entity (Stmt);
19638 Check_Library_Level_Entity (Spec_Id);
19639 Check_Pragma_Conformance
19640 (Context_Pragma => SPARK_Pragma (Spec_Id),
19641 Entity_Pragma => Empty,
19642 Entity => Empty);
19644 Set_SPARK_Pragma (Spec_Id, N);
19645 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19646 return;
19648 -- Skip internally generated code
19650 elsif not Comes_From_Source (Stmt) then
19651 null;
19653 -- Otherwise the pragma does not apply to a legal construct
19654 -- or it does not appear at the top of a declarative or a
19655 -- statement list. Issue an error and stop the analysis.
19657 else
19658 Pragma_Misplaced;
19659 exit;
19660 end if;
19662 Prev (Stmt);
19663 end loop;
19665 -- The pragma applies to a package or a subprogram that acts as
19666 -- a compilation unit.
19668 -- procedure Proc ...;
19669 -- pragma SPARK_Mode ...;
19671 if Nkind (Context) = N_Compilation_Unit_Aux then
19672 Context := Unit (Parent (Context));
19673 end if;
19675 -- The pragma appears within package declarations
19677 if Nkind (Context) = N_Package_Specification then
19678 Spec_Id := Defining_Entity (Context);
19679 Check_Library_Level_Entity (Spec_Id);
19681 -- The pragma is at the top of the visible declarations
19683 -- package Pack is
19684 -- pragma SPARK_Mode ...;
19686 if List_Containing (N) = Visible_Declarations (Context) then
19687 Check_Pragma_Conformance
19688 (Context_Pragma => SPARK_Pragma (Spec_Id),
19689 Entity_Pragma => Empty,
19690 Entity => Empty);
19691 Set_SPARK_Flags;
19693 Set_SPARK_Pragma (Spec_Id, N);
19694 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19695 Set_SPARK_Aux_Pragma (Spec_Id, N);
19696 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
19698 -- The pragma is at the top of the private declarations
19700 -- package Pack is
19701 -- private
19702 -- pragma SPARK_Mode ...;
19704 else
19705 Check_Pragma_Conformance
19706 (Context_Pragma => Empty,
19707 Entity_Pragma => SPARK_Pragma (Spec_Id),
19708 Entity => Spec_Id);
19709 Set_SPARK_Flags;
19711 Set_SPARK_Aux_Pragma (Spec_Id, N);
19712 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
19713 end if;
19715 -- The pragma appears at the top of package body declarations
19717 -- package body Pack is
19718 -- pragma SPARK_Mode ...;
19720 elsif Nkind (Context) = N_Package_Body then
19721 Spec_Id := Corresponding_Spec (Context);
19722 Body_Id := Defining_Entity (Context);
19723 Check_Library_Level_Entity (Body_Id);
19724 Check_Pragma_Conformance
19725 (Context_Pragma => SPARK_Pragma (Body_Id),
19726 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id),
19727 Entity => Spec_Id);
19728 Set_SPARK_Flags;
19730 Set_SPARK_Pragma (Body_Id, N);
19731 Set_SPARK_Pragma_Inherited (Body_Id, False);
19732 Set_SPARK_Aux_Pragma (Body_Id, N);
19733 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
19735 -- The pragma appears at the top of package body statements
19737 -- package body Pack is
19738 -- begin
19739 -- pragma SPARK_Mode;
19741 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
19742 and then Nkind (Parent (Context)) = N_Package_Body
19743 then
19744 Context := Parent (Context);
19745 Spec_Id := Corresponding_Spec (Context);
19746 Body_Id := Defining_Entity (Context);
19747 Check_Library_Level_Entity (Body_Id);
19748 Check_Pragma_Conformance
19749 (Context_Pragma => Empty,
19750 Entity_Pragma => SPARK_Pragma (Body_Id),
19751 Entity => Body_Id);
19752 Set_SPARK_Flags;
19754 Set_SPARK_Aux_Pragma (Body_Id, N);
19755 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
19757 -- The pragma appeared as an aspect of a [generic] subprogram
19758 -- declaration that acts as a compilation unit.
19760 -- [generic]
19761 -- procedure Proc ...;
19762 -- pragma SPARK_Mode ...;
19764 elsif Nkind_In (Context, N_Generic_Subprogram_Declaration,
19765 N_Subprogram_Declaration)
19766 then
19767 Spec_Id := Defining_Entity (Context);
19768 Check_Library_Level_Entity (Spec_Id);
19769 Check_Pragma_Conformance
19770 (Context_Pragma => SPARK_Pragma (Spec_Id),
19771 Entity_Pragma => Empty,
19772 Entity => Empty);
19774 Set_SPARK_Pragma (Spec_Id, N);
19775 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19777 -- The pragma appears at the top of subprogram body
19778 -- declarations.
19780 -- procedure Proc ... is
19781 -- pragma SPARK_Mode;
19783 elsif Nkind (Context) = N_Subprogram_Body then
19784 Spec_Id := Corresponding_Spec (Context);
19785 Context := Specification (Context);
19786 Body_Id := Defining_Entity (Context);
19788 -- Ignore pragma when applied to the special body created
19789 -- for inlining, recognized by its internal name _Parent.
19791 if Chars (Body_Id) = Name_uParent then
19792 return;
19793 end if;
19795 Check_Library_Level_Entity (Body_Id);
19797 -- The body is a completion of a previous declaration
19799 if Present (Spec_Id) then
19800 Check_Pragma_Conformance
19801 (Context_Pragma => SPARK_Pragma (Body_Id),
19802 Entity_Pragma => SPARK_Pragma (Spec_Id),
19803 Entity => Spec_Id);
19805 -- The body acts as spec
19807 else
19808 Check_Pragma_Conformance
19809 (Context_Pragma => SPARK_Pragma (Body_Id),
19810 Entity_Pragma => Empty,
19811 Entity => Empty);
19812 end if;
19814 Set_SPARK_Flags;
19816 Set_SPARK_Pragma (Body_Id, N);
19817 Set_SPARK_Pragma_Inherited (Body_Id, False);
19819 -- The pragma does not apply to a legal construct, issue error
19821 else
19822 Pragma_Misplaced;
19823 end if;
19824 end if;
19825 end Do_SPARK_Mode;
19827 --------------------------------
19828 -- Static_Elaboration_Desired --
19829 --------------------------------
19831 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
19833 when Pragma_Static_Elaboration_Desired =>
19834 GNAT_Pragma;
19835 Check_At_Most_N_Arguments (1);
19837 if Is_Compilation_Unit (Current_Scope)
19838 and then Ekind (Current_Scope) = E_Package
19839 then
19840 Set_Static_Elaboration_Desired (Current_Scope, True);
19841 else
19842 Error_Pragma ("pragma% must apply to a library-level package");
19843 end if;
19845 ------------------
19846 -- Storage_Size --
19847 ------------------
19849 -- pragma Storage_Size (EXPRESSION);
19851 when Pragma_Storage_Size => Storage_Size : declare
19852 P : constant Node_Id := Parent (N);
19853 Arg : Node_Id;
19855 begin
19856 Check_No_Identifiers;
19857 Check_Arg_Count (1);
19859 -- The expression must be analyzed in the special manner described
19860 -- in "Handling of Default Expressions" in sem.ads.
19862 Arg := Get_Pragma_Arg (Arg1);
19863 Preanalyze_Spec_Expression (Arg, Any_Integer);
19865 if not Is_OK_Static_Expression (Arg) then
19866 Check_Restriction (Static_Storage_Size, Arg);
19867 end if;
19869 if Nkind (P) /= N_Task_Definition then
19870 Pragma_Misplaced;
19871 return;
19873 else
19874 if Has_Storage_Size_Pragma (P) then
19875 Error_Pragma ("duplicate pragma% not allowed");
19876 else
19877 Set_Has_Storage_Size_Pragma (P, True);
19878 end if;
19880 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
19881 end if;
19882 end Storage_Size;
19884 ------------------
19885 -- Storage_Unit --
19886 ------------------
19888 -- pragma Storage_Unit (NUMERIC_LITERAL);
19890 -- Only permitted argument is System'Storage_Unit value
19892 when Pragma_Storage_Unit =>
19893 Check_No_Identifiers;
19894 Check_Arg_Count (1);
19895 Check_Arg_Is_Integer_Literal (Arg1);
19897 if Intval (Get_Pragma_Arg (Arg1)) /=
19898 UI_From_Int (Ttypes.System_Storage_Unit)
19899 then
19900 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
19901 Error_Pragma_Arg
19902 ("the only allowed argument for pragma% is ^", Arg1);
19903 end if;
19905 --------------------
19906 -- Stream_Convert --
19907 --------------------
19909 -- pragma Stream_Convert (
19910 -- [Entity =>] type_LOCAL_NAME,
19911 -- [Read =>] function_NAME,
19912 -- [Write =>] function NAME);
19914 when Pragma_Stream_Convert => Stream_Convert : declare
19916 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
19917 -- Check that the given argument is the name of a local function
19918 -- of one argument that is not overloaded earlier in the current
19919 -- local scope. A check is also made that the argument is a
19920 -- function with one parameter.
19922 --------------------------------------
19923 -- Check_OK_Stream_Convert_Function --
19924 --------------------------------------
19926 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
19927 Ent : Entity_Id;
19929 begin
19930 Check_Arg_Is_Local_Name (Arg);
19931 Ent := Entity (Get_Pragma_Arg (Arg));
19933 if Has_Homonym (Ent) then
19934 Error_Pragma_Arg
19935 ("argument for pragma% may not be overloaded", Arg);
19936 end if;
19938 if Ekind (Ent) /= E_Function
19939 or else No (First_Formal (Ent))
19940 or else Present (Next_Formal (First_Formal (Ent)))
19941 then
19942 Error_Pragma_Arg
19943 ("argument for pragma% must be function of one argument",
19944 Arg);
19945 end if;
19946 end Check_OK_Stream_Convert_Function;
19948 -- Start of processing for Stream_Convert
19950 begin
19951 GNAT_Pragma;
19952 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
19953 Check_Arg_Count (3);
19954 Check_Optional_Identifier (Arg1, Name_Entity);
19955 Check_Optional_Identifier (Arg2, Name_Read);
19956 Check_Optional_Identifier (Arg3, Name_Write);
19957 Check_Arg_Is_Local_Name (Arg1);
19958 Check_OK_Stream_Convert_Function (Arg2);
19959 Check_OK_Stream_Convert_Function (Arg3);
19961 declare
19962 Typ : constant Entity_Id :=
19963 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
19964 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
19965 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
19967 begin
19968 Check_First_Subtype (Arg1);
19970 -- Check for too early or too late. Note that we don't enforce
19971 -- the rule about primitive operations in this case, since, as
19972 -- is the case for explicit stream attributes themselves, these
19973 -- restrictions are not appropriate. Note that the chaining of
19974 -- the pragma by Rep_Item_Too_Late is actually the critical
19975 -- processing done for this pragma.
19977 if Rep_Item_Too_Early (Typ, N)
19978 or else
19979 Rep_Item_Too_Late (Typ, N, FOnly => True)
19980 then
19981 return;
19982 end if;
19984 -- Return if previous error
19986 if Etype (Typ) = Any_Type
19987 or else
19988 Etype (Read) = Any_Type
19989 or else
19990 Etype (Write) = Any_Type
19991 then
19992 return;
19993 end if;
19995 -- Error checks
19997 if Underlying_Type (Etype (Read)) /= Typ then
19998 Error_Pragma_Arg
19999 ("incorrect return type for function&", Arg2);
20000 end if;
20002 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
20003 Error_Pragma_Arg
20004 ("incorrect parameter type for function&", Arg3);
20005 end if;
20007 if Underlying_Type (Etype (First_Formal (Read))) /=
20008 Underlying_Type (Etype (Write))
20009 then
20010 Error_Pragma_Arg
20011 ("result type of & does not match Read parameter type",
20012 Arg3);
20013 end if;
20014 end;
20015 end Stream_Convert;
20017 ------------------
20018 -- Style_Checks --
20019 ------------------
20021 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
20023 -- This is processed by the parser since some of the style checks
20024 -- take place during source scanning and parsing. This means that
20025 -- we don't need to issue error messages here.
20027 when Pragma_Style_Checks => Style_Checks : declare
20028 A : constant Node_Id := Get_Pragma_Arg (Arg1);
20029 S : String_Id;
20030 C : Char_Code;
20032 begin
20033 GNAT_Pragma;
20034 Check_No_Identifiers;
20036 -- Two argument form
20038 if Arg_Count = 2 then
20039 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
20041 declare
20042 E_Id : Node_Id;
20043 E : Entity_Id;
20045 begin
20046 E_Id := Get_Pragma_Arg (Arg2);
20047 Analyze (E_Id);
20049 if not Is_Entity_Name (E_Id) then
20050 Error_Pragma_Arg
20051 ("second argument of pragma% must be entity name",
20052 Arg2);
20053 end if;
20055 E := Entity (E_Id);
20057 if not Ignore_Style_Checks_Pragmas then
20058 if E = Any_Id then
20059 return;
20060 else
20061 loop
20062 Set_Suppress_Style_Checks
20063 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
20064 exit when No (Homonym (E));
20065 E := Homonym (E);
20066 end loop;
20067 end if;
20068 end if;
20069 end;
20071 -- One argument form
20073 else
20074 Check_Arg_Count (1);
20076 if Nkind (A) = N_String_Literal then
20077 S := Strval (A);
20079 declare
20080 Slen : constant Natural := Natural (String_Length (S));
20081 Options : String (1 .. Slen);
20082 J : Natural;
20084 begin
20085 J := 1;
20086 loop
20087 C := Get_String_Char (S, Int (J));
20088 exit when not In_Character_Range (C);
20089 Options (J) := Get_Character (C);
20091 -- If at end of string, set options. As per discussion
20092 -- above, no need to check for errors, since we issued
20093 -- them in the parser.
20095 if J = Slen then
20096 if not Ignore_Style_Checks_Pragmas then
20097 Set_Style_Check_Options (Options);
20098 end if;
20100 exit;
20101 end if;
20103 J := J + 1;
20104 end loop;
20105 end;
20107 elsif Nkind (A) = N_Identifier then
20108 if Chars (A) = Name_All_Checks then
20109 if not Ignore_Style_Checks_Pragmas then
20110 if GNAT_Mode then
20111 Set_GNAT_Style_Check_Options;
20112 else
20113 Set_Default_Style_Check_Options;
20114 end if;
20115 end if;
20117 elsif Chars (A) = Name_On then
20118 if not Ignore_Style_Checks_Pragmas then
20119 Style_Check := True;
20120 end if;
20122 elsif Chars (A) = Name_Off then
20123 if not Ignore_Style_Checks_Pragmas then
20124 Style_Check := False;
20125 end if;
20126 end if;
20127 end if;
20128 end if;
20129 end Style_Checks;
20131 --------------
20132 -- Subtitle --
20133 --------------
20135 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
20137 when Pragma_Subtitle =>
20138 GNAT_Pragma;
20139 Check_Arg_Count (1);
20140 Check_Optional_Identifier (Arg1, Name_Subtitle);
20141 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
20142 Store_Note (N);
20144 --------------
20145 -- Suppress --
20146 --------------
20148 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
20150 when Pragma_Suppress =>
20151 Process_Suppress_Unsuppress (Suppress_Case => True);
20153 ------------------
20154 -- Suppress_All --
20155 ------------------
20157 -- pragma Suppress_All;
20159 -- The only check made here is that the pragma has no arguments.
20160 -- There are no placement rules, and the processing required (setting
20161 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
20162 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
20163 -- then creates and inserts a pragma Suppress (All_Checks).
20165 when Pragma_Suppress_All =>
20166 GNAT_Pragma;
20167 Check_Arg_Count (0);
20169 -------------------------
20170 -- Suppress_Debug_Info --
20171 -------------------------
20173 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
20175 when Pragma_Suppress_Debug_Info =>
20176 GNAT_Pragma;
20177 Check_Arg_Count (1);
20178 Check_Optional_Identifier (Arg1, Name_Entity);
20179 Check_Arg_Is_Local_Name (Arg1);
20180 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
20182 ----------------------------------
20183 -- Suppress_Exception_Locations --
20184 ----------------------------------
20186 -- pragma Suppress_Exception_Locations;
20188 when Pragma_Suppress_Exception_Locations =>
20189 GNAT_Pragma;
20190 Check_Arg_Count (0);
20191 Check_Valid_Configuration_Pragma;
20192 Exception_Locations_Suppressed := True;
20194 -----------------------------
20195 -- Suppress_Initialization --
20196 -----------------------------
20198 -- pragma Suppress_Initialization ([Entity =>] type_Name);
20200 when Pragma_Suppress_Initialization => Suppress_Init : declare
20201 E_Id : Node_Id;
20202 E : Entity_Id;
20204 begin
20205 GNAT_Pragma;
20206 Check_Arg_Count (1);
20207 Check_Optional_Identifier (Arg1, Name_Entity);
20208 Check_Arg_Is_Local_Name (Arg1);
20210 E_Id := Get_Pragma_Arg (Arg1);
20212 if Etype (E_Id) = Any_Type then
20213 return;
20214 end if;
20216 E := Entity (E_Id);
20218 if not Is_Type (E) and then Ekind (E) /= E_Variable then
20219 Error_Pragma_Arg
20220 ("pragma% requires variable, type or subtype", Arg1);
20221 end if;
20223 if Rep_Item_Too_Early (E, N)
20224 or else
20225 Rep_Item_Too_Late (E, N, FOnly => True)
20226 then
20227 return;
20228 end if;
20230 -- For incomplete/private type, set flag on full view
20232 if Is_Incomplete_Or_Private_Type (E) then
20233 if No (Full_View (Base_Type (E))) then
20234 Error_Pragma_Arg
20235 ("argument of pragma% cannot be an incomplete type", Arg1);
20236 else
20237 Set_Suppress_Initialization (Full_View (Base_Type (E)));
20238 end if;
20240 -- For first subtype, set flag on base type
20242 elsif Is_First_Subtype (E) then
20243 Set_Suppress_Initialization (Base_Type (E));
20245 -- For other than first subtype, set flag on subtype or variable
20247 else
20248 Set_Suppress_Initialization (E);
20249 end if;
20250 end Suppress_Init;
20252 -----------------
20253 -- System_Name --
20254 -----------------
20256 -- pragma System_Name (DIRECT_NAME);
20258 -- Syntax check: one argument, which must be the identifier GNAT or
20259 -- the identifier GCC, no other identifiers are acceptable.
20261 when Pragma_System_Name =>
20262 GNAT_Pragma;
20263 Check_No_Identifiers;
20264 Check_Arg_Count (1);
20265 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
20267 -----------------------------
20268 -- Task_Dispatching_Policy --
20269 -----------------------------
20271 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
20273 when Pragma_Task_Dispatching_Policy => declare
20274 DP : Character;
20276 begin
20277 Check_Ada_83_Warning;
20278 Check_Arg_Count (1);
20279 Check_No_Identifiers;
20280 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
20281 Check_Valid_Configuration_Pragma;
20282 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
20283 DP := Fold_Upper (Name_Buffer (1));
20285 if Task_Dispatching_Policy /= ' '
20286 and then Task_Dispatching_Policy /= DP
20287 then
20288 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
20289 Error_Pragma
20290 ("task dispatching policy incompatible with policy#");
20292 -- Set new policy, but always preserve System_Location since we
20293 -- like the error message with the run time name.
20295 else
20296 Task_Dispatching_Policy := DP;
20298 if Task_Dispatching_Policy_Sloc /= System_Location then
20299 Task_Dispatching_Policy_Sloc := Loc;
20300 end if;
20301 end if;
20302 end;
20304 ---------------
20305 -- Task_Info --
20306 ---------------
20308 -- pragma Task_Info (EXPRESSION);
20310 when Pragma_Task_Info => Task_Info : declare
20311 P : constant Node_Id := Parent (N);
20312 Ent : Entity_Id;
20314 begin
20315 GNAT_Pragma;
20317 if Warn_On_Obsolescent_Feature then
20318 Error_Msg_N
20319 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
20320 & "instead?j?", N);
20321 end if;
20323 if Nkind (P) /= N_Task_Definition then
20324 Error_Pragma ("pragma% must appear in task definition");
20325 end if;
20327 Check_No_Identifiers;
20328 Check_Arg_Count (1);
20330 Analyze_And_Resolve
20331 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
20333 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
20334 return;
20335 end if;
20337 Ent := Defining_Identifier (Parent (P));
20339 -- Check duplicate pragma before we chain the pragma in the Rep
20340 -- Item chain of Ent.
20342 if Has_Rep_Pragma
20343 (Ent, Name_Task_Info, Check_Parents => False)
20344 then
20345 Error_Pragma ("duplicate pragma% not allowed");
20346 end if;
20348 Record_Rep_Item (Ent, N);
20349 end Task_Info;
20351 ---------------
20352 -- Task_Name --
20353 ---------------
20355 -- pragma Task_Name (string_EXPRESSION);
20357 when Pragma_Task_Name => Task_Name : declare
20358 P : constant Node_Id := Parent (N);
20359 Arg : Node_Id;
20360 Ent : Entity_Id;
20362 begin
20363 Check_No_Identifiers;
20364 Check_Arg_Count (1);
20366 Arg := Get_Pragma_Arg (Arg1);
20368 -- The expression is used in the call to Create_Task, and must be
20369 -- expanded there, not in the context of the current spec. It must
20370 -- however be analyzed to capture global references, in case it
20371 -- appears in a generic context.
20373 Preanalyze_And_Resolve (Arg, Standard_String);
20375 if Nkind (P) /= N_Task_Definition then
20376 Pragma_Misplaced;
20377 end if;
20379 Ent := Defining_Identifier (Parent (P));
20381 -- Check duplicate pragma before we chain the pragma in the Rep
20382 -- Item chain of Ent.
20384 if Has_Rep_Pragma
20385 (Ent, Name_Task_Name, Check_Parents => False)
20386 then
20387 Error_Pragma ("duplicate pragma% not allowed");
20388 end if;
20390 Record_Rep_Item (Ent, N);
20391 end Task_Name;
20393 ------------------
20394 -- Task_Storage --
20395 ------------------
20397 -- pragma Task_Storage (
20398 -- [Task_Type =>] LOCAL_NAME,
20399 -- [Top_Guard =>] static_integer_EXPRESSION);
20401 when Pragma_Task_Storage => Task_Storage : declare
20402 Args : Args_List (1 .. 2);
20403 Names : constant Name_List (1 .. 2) := (
20404 Name_Task_Type,
20405 Name_Top_Guard);
20407 Task_Type : Node_Id renames Args (1);
20408 Top_Guard : Node_Id renames Args (2);
20410 Ent : Entity_Id;
20412 begin
20413 GNAT_Pragma;
20414 Gather_Associations (Names, Args);
20416 if No (Task_Type) then
20417 Error_Pragma
20418 ("missing task_type argument for pragma%");
20419 end if;
20421 Check_Arg_Is_Local_Name (Task_Type);
20423 Ent := Entity (Task_Type);
20425 if not Is_Task_Type (Ent) then
20426 Error_Pragma_Arg
20427 ("argument for pragma% must be task type", Task_Type);
20428 end if;
20430 if No (Top_Guard) then
20431 Error_Pragma_Arg
20432 ("pragma% takes two arguments", Task_Type);
20433 else
20434 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
20435 end if;
20437 Check_First_Subtype (Task_Type);
20439 if Rep_Item_Too_Late (Ent, N) then
20440 raise Pragma_Exit;
20441 end if;
20442 end Task_Storage;
20444 ---------------
20445 -- Test_Case --
20446 ---------------
20448 -- pragma Test_Case
20449 -- ([Name =>] Static_String_EXPRESSION
20450 -- ,[Mode =>] MODE_TYPE
20451 -- [, Requires => Boolean_EXPRESSION]
20452 -- [, Ensures => Boolean_EXPRESSION]);
20454 -- MODE_TYPE ::= Nominal | Robustness
20456 -- Characteristics:
20458 -- * Analysis - The annotation undergoes initial checks to verify
20459 -- the legal placement and context. Secondary checks preanalyze the
20460 -- expressions in:
20462 -- Analyze_Test_Case_In_Decl_Part
20464 -- * Expansion - None.
20466 -- * Template - The annotation utilizes the generic template of the
20467 -- related subprogram when it is:
20469 -- aspect on subprogram declaration
20471 -- The annotation must prepare its own template when it is:
20473 -- pragma on subprogram declaration
20475 -- * Globals - Capture of global references must occur after full
20476 -- analysis.
20478 -- * Instance - The annotation is instantiated automatically when
20479 -- the related generic subprogram is instantiated except for the
20480 -- "pragma on subprogram declaration" case. In that scenario the
20481 -- annotation must instantiate itself.
20483 when Pragma_Test_Case => Test_Case : declare
20484 procedure Check_Distinct_Name (Subp_Id : Entity_Id);
20485 -- Ensure that the contract of subprogram Subp_Id does not contain
20486 -- another Test_Case pragma with the same Name as the current one.
20488 -------------------------
20489 -- Check_Distinct_Name --
20490 -------------------------
20492 procedure Check_Distinct_Name (Subp_Id : Entity_Id) is
20493 Items : constant Node_Id := Contract (Subp_Id);
20494 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
20495 Prag : Node_Id;
20497 begin
20498 -- Inspect all Test_Case pragma of the related subprogram
20499 -- looking for one with a duplicate "Name" argument.
20501 if Present (Items) then
20502 Prag := Contract_Test_Cases (Items);
20503 while Present (Prag) loop
20504 if Pragma_Name (Prag) = Name_Test_Case
20505 and then String_Equal
20506 (Name, Get_Name_From_CTC_Pragma (Prag))
20507 then
20508 Error_Msg_Sloc := Sloc (Prag);
20509 Error_Pragma ("name for pragma % is already used #");
20510 end if;
20512 Prag := Next_Pragma (Prag);
20513 end loop;
20514 end if;
20515 end Check_Distinct_Name;
20517 -- Local variables
20519 Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit));
20520 Asp_Arg : Node_Id;
20521 Context : Node_Id;
20522 Subp_Decl : Node_Id;
20523 Subp_Id : Entity_Id;
20525 -- Start of processing for Test_Case
20527 begin
20528 GNAT_Pragma;
20529 Check_At_Least_N_Arguments (2);
20530 Check_At_Most_N_Arguments (4);
20531 Check_Arg_Order
20532 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
20534 -- Argument "Name"
20536 Check_Optional_Identifier (Arg1, Name_Name);
20537 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
20539 -- Argument "Mode"
20541 Check_Optional_Identifier (Arg2, Name_Mode);
20542 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
20544 -- Arguments "Requires" and "Ensures"
20546 if Present (Arg3) then
20547 if Present (Arg4) then
20548 Check_Identifier (Arg3, Name_Requires);
20549 Check_Identifier (Arg4, Name_Ensures);
20550 else
20551 Check_Identifier_Is_One_Of
20552 (Arg3, Name_Requires, Name_Ensures);
20553 end if;
20554 end if;
20556 -- Pragma Test_Case must be associated with a subprogram declared
20557 -- in a library-level package. First determine whether the current
20558 -- compilation unit is a legal context.
20560 if Nkind_In (Pack_Decl, N_Package_Declaration,
20561 N_Generic_Package_Declaration)
20562 then
20563 null;
20565 -- Otherwise the placement is illegal
20567 else
20568 Pragma_Misplaced;
20569 return;
20570 end if;
20572 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
20574 -- Find the enclosing context
20576 Context := Parent (Subp_Decl);
20578 if Present (Context) then
20579 Context := Parent (Context);
20580 end if;
20582 -- Verify the placement of the pragma
20584 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
20585 Error_Pragma
20586 ("pragma % cannot be applied to abstract subprogram");
20587 return;
20589 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
20590 Error_Pragma ("pragma % cannot be applied to entry");
20591 return;
20593 -- The context is a [generic] subprogram declared at the top level
20594 -- of the [generic] package unit.
20596 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
20597 N_Subprogram_Declaration)
20598 and then Present (Context)
20599 and then Nkind_In (Context, N_Generic_Package_Declaration,
20600 N_Package_Declaration)
20601 then
20602 Subp_Id := Defining_Entity (Subp_Decl);
20604 -- Otherwise the placement is illegal
20606 else
20607 Pragma_Misplaced;
20608 return;
20609 end if;
20611 -- Preanalyze the original aspect argument "Name" for ASIS or for
20612 -- a generic subprogram to properly capture global references.
20614 if ASIS_Mode or else Is_Generic_Subprogram (Subp_Id) then
20615 Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True);
20617 if Present (Asp_Arg) then
20619 -- The argument appears with an identifier in association
20620 -- form.
20622 if Nkind (Asp_Arg) = N_Component_Association then
20623 Asp_Arg := Expression (Asp_Arg);
20624 end if;
20626 Check_Expr_Is_OK_Static_Expression
20627 (Asp_Arg, Standard_String);
20628 end if;
20629 end if;
20631 -- Ensure that the all Test_Case pragmas of the related subprogram
20632 -- have distinct names.
20634 Check_Distinct_Name (Subp_Id);
20636 -- Fully analyze the pragma when it appears inside a subprogram
20637 -- body because it cannot benefit from forward references.
20639 if Nkind_In (Subp_Decl, N_Subprogram_Body,
20640 N_Subprogram_Body_Stub)
20641 then
20642 Analyze_Test_Case_In_Decl_Part (N);
20643 end if;
20645 -- Chain the pragma on the contract for further processing by
20646 -- Analyze_Test_Case_In_Decl_Part.
20648 Add_Contract_Item (N, Subp_Id);
20649 end Test_Case;
20651 --------------------------
20652 -- Thread_Local_Storage --
20653 --------------------------
20655 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
20657 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
20658 Id : Node_Id;
20659 E : Entity_Id;
20661 begin
20662 GNAT_Pragma;
20663 Check_Arg_Count (1);
20664 Check_Optional_Identifier (Arg1, Name_Entity);
20665 Check_Arg_Is_Library_Level_Local_Name (Arg1);
20667 Id := Get_Pragma_Arg (Arg1);
20668 Analyze (Id);
20670 if not Is_Entity_Name (Id)
20671 or else Ekind (Entity (Id)) /= E_Variable
20672 then
20673 Error_Pragma_Arg ("local variable name required", Arg1);
20674 end if;
20676 E := Entity (Id);
20678 if Rep_Item_Too_Early (E, N)
20679 or else Rep_Item_Too_Late (E, N)
20680 then
20681 raise Pragma_Exit;
20682 end if;
20684 Set_Has_Pragma_Thread_Local_Storage (E);
20685 Set_Has_Gigi_Rep_Item (E);
20686 end Thread_Local_Storage;
20688 ----------------
20689 -- Time_Slice --
20690 ----------------
20692 -- pragma Time_Slice (static_duration_EXPRESSION);
20694 when Pragma_Time_Slice => Time_Slice : declare
20695 Val : Ureal;
20696 Nod : Node_Id;
20698 begin
20699 GNAT_Pragma;
20700 Check_Arg_Count (1);
20701 Check_No_Identifiers;
20702 Check_In_Main_Program;
20703 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
20705 if not Error_Posted (Arg1) then
20706 Nod := Next (N);
20707 while Present (Nod) loop
20708 if Nkind (Nod) = N_Pragma
20709 and then Pragma_Name (Nod) = Name_Time_Slice
20710 then
20711 Error_Msg_Name_1 := Pname;
20712 Error_Msg_N ("duplicate pragma% not permitted", Nod);
20713 end if;
20715 Next (Nod);
20716 end loop;
20717 end if;
20719 -- Process only if in main unit
20721 if Get_Source_Unit (Loc) = Main_Unit then
20722 Opt.Time_Slice_Set := True;
20723 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
20725 if Val <= Ureal_0 then
20726 Opt.Time_Slice_Value := 0;
20728 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
20729 Opt.Time_Slice_Value := 1_000_000_000;
20731 else
20732 Opt.Time_Slice_Value :=
20733 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
20734 end if;
20735 end if;
20736 end Time_Slice;
20738 -----------
20739 -- Title --
20740 -----------
20742 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
20744 -- TITLING_OPTION ::=
20745 -- [Title =>] STRING_LITERAL
20746 -- | [Subtitle =>] STRING_LITERAL
20748 when Pragma_Title => Title : declare
20749 Args : Args_List (1 .. 2);
20750 Names : constant Name_List (1 .. 2) := (
20751 Name_Title,
20752 Name_Subtitle);
20754 begin
20755 GNAT_Pragma;
20756 Gather_Associations (Names, Args);
20757 Store_Note (N);
20759 for J in 1 .. 2 loop
20760 if Present (Args (J)) then
20761 Check_Arg_Is_OK_Static_Expression
20762 (Args (J), Standard_String);
20763 end if;
20764 end loop;
20765 end Title;
20767 ----------------------------
20768 -- Type_Invariant[_Class] --
20769 ----------------------------
20771 -- pragma Type_Invariant[_Class]
20772 -- ([Entity =>] type_LOCAL_NAME,
20773 -- [Check =>] EXPRESSION);
20775 when Pragma_Type_Invariant |
20776 Pragma_Type_Invariant_Class =>
20777 Type_Invariant : declare
20778 I_Pragma : Node_Id;
20780 begin
20781 Check_Arg_Count (2);
20783 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
20784 -- setting Class_Present for the Type_Invariant_Class case.
20786 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
20787 I_Pragma := New_Copy (N);
20788 Set_Pragma_Identifier
20789 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
20790 Rewrite (N, I_Pragma);
20791 Set_Analyzed (N, False);
20792 Analyze (N);
20793 end Type_Invariant;
20795 ---------------------
20796 -- Unchecked_Union --
20797 ---------------------
20799 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
20801 when Pragma_Unchecked_Union => Unchecked_Union : declare
20802 Assoc : constant Node_Id := Arg1;
20803 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
20804 Typ : Entity_Id;
20805 Tdef : Node_Id;
20806 Clist : Node_Id;
20807 Vpart : Node_Id;
20808 Comp : Node_Id;
20809 Variant : Node_Id;
20811 begin
20812 Ada_2005_Pragma;
20813 Check_No_Identifiers;
20814 Check_Arg_Count (1);
20815 Check_Arg_Is_Local_Name (Arg1);
20817 Find_Type (Type_Id);
20819 Typ := Entity (Type_Id);
20821 if Typ = Any_Type
20822 or else Rep_Item_Too_Early (Typ, N)
20823 then
20824 return;
20825 else
20826 Typ := Underlying_Type (Typ);
20827 end if;
20829 if Rep_Item_Too_Late (Typ, N) then
20830 return;
20831 end if;
20833 Check_First_Subtype (Arg1);
20835 -- Note remaining cases are references to a type in the current
20836 -- declarative part. If we find an error, we post the error on
20837 -- the relevant type declaration at an appropriate point.
20839 if not Is_Record_Type (Typ) then
20840 Error_Msg_N ("unchecked union must be record type", Typ);
20841 return;
20843 elsif Is_Tagged_Type (Typ) then
20844 Error_Msg_N ("unchecked union must not be tagged", Typ);
20845 return;
20847 elsif not Has_Discriminants (Typ) then
20848 Error_Msg_N
20849 ("unchecked union must have one discriminant", Typ);
20850 return;
20852 -- Note: in previous versions of GNAT we used to check for limited
20853 -- types and give an error, but in fact the standard does allow
20854 -- Unchecked_Union on limited types, so this check was removed.
20856 -- Similarly, GNAT used to require that all discriminants have
20857 -- default values, but this is not mandated by the RM.
20859 -- Proceed with basic error checks completed
20861 else
20862 Tdef := Type_Definition (Declaration_Node (Typ));
20863 Clist := Component_List (Tdef);
20865 -- Check presence of component list and variant part
20867 if No (Clist) or else No (Variant_Part (Clist)) then
20868 Error_Msg_N
20869 ("unchecked union must have variant part", Tdef);
20870 return;
20871 end if;
20873 -- Check components
20875 Comp := First (Component_Items (Clist));
20876 while Present (Comp) loop
20877 Check_Component (Comp, Typ);
20878 Next (Comp);
20879 end loop;
20881 -- Check variant part
20883 Vpart := Variant_Part (Clist);
20885 Variant := First (Variants (Vpart));
20886 while Present (Variant) loop
20887 Check_Variant (Variant, Typ);
20888 Next (Variant);
20889 end loop;
20890 end if;
20892 Set_Is_Unchecked_Union (Typ);
20893 Set_Convention (Typ, Convention_C);
20894 Set_Has_Unchecked_Union (Base_Type (Typ));
20895 Set_Is_Unchecked_Union (Base_Type (Typ));
20896 end Unchecked_Union;
20898 ------------------------
20899 -- Unimplemented_Unit --
20900 ------------------------
20902 -- pragma Unimplemented_Unit;
20904 -- Note: this only gives an error if we are generating code, or if
20905 -- we are in a generic library unit (where the pragma appears in the
20906 -- body, not in the spec).
20908 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
20909 Cunitent : constant Entity_Id :=
20910 Cunit_Entity (Get_Source_Unit (Loc));
20911 Ent_Kind : constant Entity_Kind :=
20912 Ekind (Cunitent);
20914 begin
20915 GNAT_Pragma;
20916 Check_Arg_Count (0);
20918 if Operating_Mode = Generate_Code
20919 or else Ent_Kind = E_Generic_Function
20920 or else Ent_Kind = E_Generic_Procedure
20921 or else Ent_Kind = E_Generic_Package
20922 then
20923 Get_Name_String (Chars (Cunitent));
20924 Set_Casing (Mixed_Case);
20925 Write_Str (Name_Buffer (1 .. Name_Len));
20926 Write_Str (" is not supported in this configuration");
20927 Write_Eol;
20928 raise Unrecoverable_Error;
20929 end if;
20930 end Unimplemented_Unit;
20932 ------------------------
20933 -- Universal_Aliasing --
20934 ------------------------
20936 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
20938 when Pragma_Universal_Aliasing => Universal_Alias : declare
20939 E_Id : Entity_Id;
20941 begin
20942 GNAT_Pragma;
20943 Check_Arg_Count (1);
20944 Check_Optional_Identifier (Arg2, Name_Entity);
20945 Check_Arg_Is_Local_Name (Arg1);
20946 E_Id := Entity (Get_Pragma_Arg (Arg1));
20948 if E_Id = Any_Type then
20949 return;
20950 elsif No (E_Id) or else not Is_Type (E_Id) then
20951 Error_Pragma_Arg ("pragma% requires type", Arg1);
20952 end if;
20954 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
20955 Record_Rep_Item (E_Id, N);
20956 end Universal_Alias;
20958 --------------------
20959 -- Universal_Data --
20960 --------------------
20962 -- pragma Universal_Data [(library_unit_NAME)];
20964 when Pragma_Universal_Data =>
20965 GNAT_Pragma;
20967 -- If this is a configuration pragma, then set the universal
20968 -- addressing option, otherwise confirm that the pragma satisfies
20969 -- the requirements of library unit pragma placement and leave it
20970 -- to the GNAAMP back end to detect the pragma (avoids transitive
20971 -- setting of the option due to withed units).
20973 if Is_Configuration_Pragma then
20974 Universal_Addressing_On_AAMP := True;
20975 else
20976 Check_Valid_Library_Unit_Pragma;
20977 end if;
20979 if not AAMP_On_Target then
20980 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
20981 end if;
20983 ----------------
20984 -- Unmodified --
20985 ----------------
20987 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
20989 when Pragma_Unmodified => Unmodified : declare
20990 Arg_Node : Node_Id;
20991 Arg_Expr : Node_Id;
20992 Arg_Ent : Entity_Id;
20994 begin
20995 GNAT_Pragma;
20996 Check_At_Least_N_Arguments (1);
20998 -- Loop through arguments
21000 Arg_Node := Arg1;
21001 while Present (Arg_Node) loop
21002 Check_No_Identifier (Arg_Node);
21004 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
21005 -- in fact generate reference, so that the entity will have a
21006 -- reference, which will inhibit any warnings about it not
21007 -- being referenced, and also properly show up in the ali file
21008 -- as a reference. But this reference is recorded before the
21009 -- Has_Pragma_Unreferenced flag is set, so that no warning is
21010 -- generated for this reference.
21012 Check_Arg_Is_Local_Name (Arg_Node);
21013 Arg_Expr := Get_Pragma_Arg (Arg_Node);
21015 if Is_Entity_Name (Arg_Expr) then
21016 Arg_Ent := Entity (Arg_Expr);
21018 if not Is_Assignable (Arg_Ent) then
21019 Error_Pragma_Arg
21020 ("pragma% can only be applied to a variable",
21021 Arg_Expr);
21022 else
21023 Set_Has_Pragma_Unmodified (Arg_Ent);
21024 end if;
21025 end if;
21027 Next (Arg_Node);
21028 end loop;
21029 end Unmodified;
21031 ------------------
21032 -- Unreferenced --
21033 ------------------
21035 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
21037 -- or when used in a context clause:
21039 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
21041 when Pragma_Unreferenced => Unreferenced : declare
21042 Arg_Node : Node_Id;
21043 Arg_Expr : Node_Id;
21044 Arg_Ent : Entity_Id;
21045 Citem : Node_Id;
21047 begin
21048 GNAT_Pragma;
21049 Check_At_Least_N_Arguments (1);
21051 -- Check case of appearing within context clause
21053 if Is_In_Context_Clause then
21055 -- The arguments must all be units mentioned in a with clause
21056 -- in the same context clause. Note we already checked (in
21057 -- Par.Prag) that the arguments are either identifiers or
21058 -- selected components.
21060 Arg_Node := Arg1;
21061 while Present (Arg_Node) loop
21062 Citem := First (List_Containing (N));
21063 while Citem /= N loop
21064 if Nkind (Citem) = N_With_Clause
21065 and then
21066 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
21067 then
21068 Set_Has_Pragma_Unreferenced
21069 (Cunit_Entity
21070 (Get_Source_Unit
21071 (Library_Unit (Citem))));
21072 Set_Elab_Unit_Name
21073 (Get_Pragma_Arg (Arg_Node), Name (Citem));
21074 exit;
21075 end if;
21077 Next (Citem);
21078 end loop;
21080 if Citem = N then
21081 Error_Pragma_Arg
21082 ("argument of pragma% is not withed unit", Arg_Node);
21083 end if;
21085 Next (Arg_Node);
21086 end loop;
21088 -- Case of not in list of context items
21090 else
21091 Arg_Node := Arg1;
21092 while Present (Arg_Node) loop
21093 Check_No_Identifier (Arg_Node);
21095 -- Note: the analyze call done by Check_Arg_Is_Local_Name
21096 -- will in fact generate reference, so that the entity will
21097 -- have a reference, which will inhibit any warnings about
21098 -- it not being referenced, and also properly show up in the
21099 -- ali file as a reference. But this reference is recorded
21100 -- before the Has_Pragma_Unreferenced flag is set, so that
21101 -- no warning is generated for this reference.
21103 Check_Arg_Is_Local_Name (Arg_Node);
21104 Arg_Expr := Get_Pragma_Arg (Arg_Node);
21106 if Is_Entity_Name (Arg_Expr) then
21107 Arg_Ent := Entity (Arg_Expr);
21109 -- If the entity is overloaded, the pragma applies to the
21110 -- most recent overloading, as documented. In this case,
21111 -- name resolution does not generate a reference, so it
21112 -- must be done here explicitly.
21114 if Is_Overloaded (Arg_Expr) then
21115 Generate_Reference (Arg_Ent, N);
21116 end if;
21118 Set_Has_Pragma_Unreferenced (Arg_Ent);
21119 end if;
21121 Next (Arg_Node);
21122 end loop;
21123 end if;
21124 end Unreferenced;
21126 --------------------------
21127 -- Unreferenced_Objects --
21128 --------------------------
21130 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
21132 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
21133 Arg_Node : Node_Id;
21134 Arg_Expr : Node_Id;
21136 begin
21137 GNAT_Pragma;
21138 Check_At_Least_N_Arguments (1);
21140 Arg_Node := Arg1;
21141 while Present (Arg_Node) loop
21142 Check_No_Identifier (Arg_Node);
21143 Check_Arg_Is_Local_Name (Arg_Node);
21144 Arg_Expr := Get_Pragma_Arg (Arg_Node);
21146 if not Is_Entity_Name (Arg_Expr)
21147 or else not Is_Type (Entity (Arg_Expr))
21148 then
21149 Error_Pragma_Arg
21150 ("argument for pragma% must be type or subtype", Arg_Node);
21151 end if;
21153 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
21154 Next (Arg_Node);
21155 end loop;
21156 end Unreferenced_Objects;
21158 ------------------------------
21159 -- Unreserve_All_Interrupts --
21160 ------------------------------
21162 -- pragma Unreserve_All_Interrupts;
21164 when Pragma_Unreserve_All_Interrupts =>
21165 GNAT_Pragma;
21166 Check_Arg_Count (0);
21168 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
21169 Unreserve_All_Interrupts := True;
21170 end if;
21172 ----------------
21173 -- Unsuppress --
21174 ----------------
21176 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
21178 when Pragma_Unsuppress =>
21179 Ada_2005_Pragma;
21180 Process_Suppress_Unsuppress (Suppress_Case => False);
21182 ----------------------------
21183 -- Unevaluated_Use_Of_Old --
21184 ----------------------------
21186 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
21188 when Pragma_Unevaluated_Use_Of_Old =>
21189 GNAT_Pragma;
21190 Check_Arg_Count (1);
21191 Check_No_Identifiers;
21192 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
21194 -- Suppress/Unsuppress can appear as a configuration pragma, or in
21195 -- a declarative part or a package spec.
21197 if not Is_Configuration_Pragma then
21198 Check_Is_In_Decl_Part_Or_Package_Spec;
21199 end if;
21201 -- Store proper setting of Uneval_Old
21203 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21204 Uneval_Old := Fold_Upper (Name_Buffer (1));
21206 -------------------
21207 -- Use_VADS_Size --
21208 -------------------
21210 -- pragma Use_VADS_Size;
21212 when Pragma_Use_VADS_Size =>
21213 GNAT_Pragma;
21214 Check_Arg_Count (0);
21215 Check_Valid_Configuration_Pragma;
21216 Use_VADS_Size := True;
21218 ---------------------
21219 -- Validity_Checks --
21220 ---------------------
21222 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
21224 when Pragma_Validity_Checks => Validity_Checks : declare
21225 A : constant Node_Id := Get_Pragma_Arg (Arg1);
21226 S : String_Id;
21227 C : Char_Code;
21229 begin
21230 GNAT_Pragma;
21231 Check_Arg_Count (1);
21232 Check_No_Identifiers;
21234 -- Pragma always active unless in CodePeer or GNATprove modes,
21235 -- which use a fixed configuration of validity checks.
21237 if not (CodePeer_Mode or GNATprove_Mode) then
21238 if Nkind (A) = N_String_Literal then
21239 S := Strval (A);
21241 declare
21242 Slen : constant Natural := Natural (String_Length (S));
21243 Options : String (1 .. Slen);
21244 J : Natural;
21246 begin
21247 -- Couldn't we use a for loop here over Options'Range???
21249 J := 1;
21250 loop
21251 C := Get_String_Char (S, Int (J));
21253 -- This is a weird test, it skips setting validity
21254 -- checks entirely if any element of S is out of
21255 -- range of Character, what is that about ???
21257 exit when not In_Character_Range (C);
21258 Options (J) := Get_Character (C);
21260 if J = Slen then
21261 Set_Validity_Check_Options (Options);
21262 exit;
21263 else
21264 J := J + 1;
21265 end if;
21266 end loop;
21267 end;
21269 elsif Nkind (A) = N_Identifier then
21270 if Chars (A) = Name_All_Checks then
21271 Set_Validity_Check_Options ("a");
21272 elsif Chars (A) = Name_On then
21273 Validity_Checks_On := True;
21274 elsif Chars (A) = Name_Off then
21275 Validity_Checks_On := False;
21276 end if;
21277 end if;
21278 end if;
21279 end Validity_Checks;
21281 --------------
21282 -- Volatile --
21283 --------------
21285 -- pragma Volatile (LOCAL_NAME);
21287 when Pragma_Volatile =>
21288 Process_Atomic_Independent_Shared_Volatile;
21290 --------------------------
21291 -- Volatile_Full_Access --
21292 --------------------------
21294 -- pragma Volatile_Full_Access (LOCAL_NAME);
21296 when Pragma_Volatile_Full_Access =>
21297 GNAT_Pragma;
21298 Process_Atomic_Independent_Shared_Volatile;
21300 -------------------------
21301 -- Volatile_Components --
21302 -------------------------
21304 -- pragma Volatile_Components (array_LOCAL_NAME);
21306 -- Volatile is handled by the same circuit as Atomic_Components
21308 ----------------------
21309 -- Warning_As_Error --
21310 ----------------------
21312 -- pragma Warning_As_Error (static_string_EXPRESSION);
21314 when Pragma_Warning_As_Error =>
21315 GNAT_Pragma;
21316 Check_Arg_Count (1);
21317 Check_No_Identifiers;
21318 Check_Valid_Configuration_Pragma;
21320 if not Is_Static_String_Expression (Arg1) then
21321 Error_Pragma_Arg
21322 ("argument of pragma% must be static string expression",
21323 Arg1);
21325 -- OK static string expression
21327 else
21328 Acquire_Warning_Match_String (Arg1);
21329 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
21330 Warnings_As_Errors (Warnings_As_Errors_Count) :=
21331 new String'(Name_Buffer (1 .. Name_Len));
21332 end if;
21334 --------------
21335 -- Warnings --
21336 --------------
21338 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
21340 -- DETAILS ::= On | Off
21341 -- DETAILS ::= On | Off, local_NAME
21342 -- DETAILS ::= static_string_EXPRESSION
21343 -- DETAILS ::= On | Off, static_string_EXPRESSION
21345 -- TOOL_NAME ::= GNAT | GNATProve
21347 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
21349 -- Note: If the first argument matches an allowed tool name, it is
21350 -- always considered to be a tool name, even if there is a string
21351 -- variable of that name.
21353 -- Note if the second argument of DETAILS is a local_NAME then the
21354 -- second form is always understood. If the intention is to use
21355 -- the fourth form, then you can write NAME & "" to force the
21356 -- intepretation as a static_string_EXPRESSION.
21358 when Pragma_Warnings => Warnings : declare
21359 Reason : String_Id;
21361 begin
21362 GNAT_Pragma;
21363 Check_At_Least_N_Arguments (1);
21365 -- See if last argument is labeled Reason. If so, make sure we
21366 -- have a string literal or a concatenation of string literals,
21367 -- and acquire the REASON string. Then remove the REASON argument
21368 -- by decreasing Num_Args by one; Remaining processing looks only
21369 -- at first Num_Args arguments).
21371 declare
21372 Last_Arg : constant Node_Id :=
21373 Last (Pragma_Argument_Associations (N));
21375 begin
21376 if Nkind (Last_Arg) = N_Pragma_Argument_Association
21377 and then Chars (Last_Arg) = Name_Reason
21378 then
21379 Start_String;
21380 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
21381 Reason := End_String;
21382 Arg_Count := Arg_Count - 1;
21384 -- Not allowed in compiler units (bootstrap issues)
21386 Check_Compiler_Unit ("Reason for pragma Warnings", N);
21388 -- No REASON string, set null string as reason
21390 else
21391 Reason := Null_String_Id;
21392 end if;
21393 end;
21395 -- Now proceed with REASON taken care of and eliminated
21397 Check_No_Identifiers;
21399 -- If debug flag -gnatd.i is set, pragma is ignored
21401 if Debug_Flag_Dot_I then
21402 return;
21403 end if;
21405 -- Process various forms of the pragma
21407 declare
21408 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21409 Shifted_Args : List_Id;
21411 begin
21412 -- See if first argument is a tool name, currently either
21413 -- GNAT or GNATprove. If so, either ignore the pragma if the
21414 -- tool used does not match, or continue as if no tool name
21415 -- was given otherwise, by shifting the arguments.
21417 if Nkind (Argx) = N_Identifier
21418 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
21419 then
21420 if Chars (Argx) = Name_Gnat then
21421 if CodePeer_Mode or GNATprove_Mode or ASIS_Mode then
21422 Rewrite (N, Make_Null_Statement (Loc));
21423 Analyze (N);
21424 raise Pragma_Exit;
21425 end if;
21427 elsif Chars (Argx) = Name_Gnatprove then
21428 if not GNATprove_Mode then
21429 Rewrite (N, Make_Null_Statement (Loc));
21430 Analyze (N);
21431 raise Pragma_Exit;
21432 end if;
21434 else
21435 raise Program_Error;
21436 end if;
21438 -- At this point, the pragma Warnings applies to the tool,
21439 -- so continue with shifted arguments.
21441 Arg_Count := Arg_Count - 1;
21443 if Arg_Count = 1 then
21444 Shifted_Args := New_List (New_Copy (Arg2));
21445 elsif Arg_Count = 2 then
21446 Shifted_Args := New_List (New_Copy (Arg2),
21447 New_Copy (Arg3));
21448 elsif Arg_Count = 3 then
21449 Shifted_Args := New_List (New_Copy (Arg2),
21450 New_Copy (Arg3),
21451 New_Copy (Arg4));
21452 else
21453 raise Program_Error;
21454 end if;
21456 Rewrite (N,
21457 Make_Pragma (Loc,
21458 Chars => Name_Warnings,
21459 Pragma_Argument_Associations => Shifted_Args));
21460 Analyze (N);
21461 raise Pragma_Exit;
21462 end if;
21464 -- One argument case
21466 if Arg_Count = 1 then
21468 -- On/Off one argument case was processed by parser
21470 if Nkind (Argx) = N_Identifier
21471 and then Nam_In (Chars (Argx), Name_On, Name_Off)
21472 then
21473 null;
21475 -- One argument case must be ON/OFF or static string expr
21477 elsif not Is_Static_String_Expression (Arg1) then
21478 Error_Pragma_Arg
21479 ("argument of pragma% must be On/Off or static string "
21480 & "expression", Arg1);
21482 -- One argument string expression case
21484 else
21485 declare
21486 Lit : constant Node_Id := Expr_Value_S (Argx);
21487 Str : constant String_Id := Strval (Lit);
21488 Len : constant Nat := String_Length (Str);
21489 C : Char_Code;
21490 J : Nat;
21491 OK : Boolean;
21492 Chr : Character;
21494 begin
21495 J := 1;
21496 while J <= Len loop
21497 C := Get_String_Char (Str, J);
21498 OK := In_Character_Range (C);
21500 if OK then
21501 Chr := Get_Character (C);
21503 -- Dash case: only -Wxxx is accepted
21505 if J = 1
21506 and then J < Len
21507 and then Chr = '-'
21508 then
21509 J := J + 1;
21510 C := Get_String_Char (Str, J);
21511 Chr := Get_Character (C);
21512 exit when Chr = 'W';
21513 OK := False;
21515 -- Dot case
21517 elsif J < Len and then Chr = '.' then
21518 J := J + 1;
21519 C := Get_String_Char (Str, J);
21520 Chr := Get_Character (C);
21522 if not Set_Dot_Warning_Switch (Chr) then
21523 Error_Pragma_Arg
21524 ("invalid warning switch character "
21525 & '.' & Chr, Arg1);
21526 end if;
21528 -- Non-Dot case
21530 else
21531 OK := Set_Warning_Switch (Chr);
21532 end if;
21533 end if;
21535 if not OK then
21536 Error_Pragma_Arg
21537 ("invalid warning switch character " & Chr,
21538 Arg1);
21539 end if;
21541 J := J + 1;
21542 end loop;
21543 end;
21544 end if;
21546 -- Two or more arguments (must be two)
21548 else
21549 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
21550 Check_Arg_Count (2);
21552 declare
21553 E_Id : Node_Id;
21554 E : Entity_Id;
21555 Err : Boolean;
21557 begin
21558 E_Id := Get_Pragma_Arg (Arg2);
21559 Analyze (E_Id);
21561 -- In the expansion of an inlined body, a reference to
21562 -- the formal may be wrapped in a conversion if the
21563 -- actual is a conversion. Retrieve the real entity name.
21565 if (In_Instance_Body or In_Inlined_Body)
21566 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
21567 then
21568 E_Id := Expression (E_Id);
21569 end if;
21571 -- Entity name case
21573 if Is_Entity_Name (E_Id) then
21574 E := Entity (E_Id);
21576 if E = Any_Id then
21577 return;
21578 else
21579 loop
21580 Set_Warnings_Off
21581 (E, (Chars (Get_Pragma_Arg (Arg1)) =
21582 Name_Off));
21584 -- For OFF case, make entry in warnings off
21585 -- pragma table for later processing. But we do
21586 -- not do that within an instance, since these
21587 -- warnings are about what is needed in the
21588 -- template, not an instance of it.
21590 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
21591 and then Warn_On_Warnings_Off
21592 and then not In_Instance
21593 then
21594 Warnings_Off_Pragmas.Append ((N, E, Reason));
21595 end if;
21597 if Is_Enumeration_Type (E) then
21598 declare
21599 Lit : Entity_Id;
21600 begin
21601 Lit := First_Literal (E);
21602 while Present (Lit) loop
21603 Set_Warnings_Off (Lit);
21604 Next_Literal (Lit);
21605 end loop;
21606 end;
21607 end if;
21609 exit when No (Homonym (E));
21610 E := Homonym (E);
21611 end loop;
21612 end if;
21614 -- Error if not entity or static string expression case
21616 elsif not Is_Static_String_Expression (Arg2) then
21617 Error_Pragma_Arg
21618 ("second argument of pragma% must be entity name "
21619 & "or static string expression", Arg2);
21621 -- Static string expression case
21623 else
21624 Acquire_Warning_Match_String (Arg2);
21626 -- Note on configuration pragma case: If this is a
21627 -- configuration pragma, then for an OFF pragma, we
21628 -- just set Config True in the call, which is all
21629 -- that needs to be done. For the case of ON, this
21630 -- is normally an error, unless it is canceling the
21631 -- effect of a previous OFF pragma in the same file.
21632 -- In any other case, an error will be signalled (ON
21633 -- with no matching OFF).
21635 -- Note: We set Used if we are inside a generic to
21636 -- disable the test that the non-config case actually
21637 -- cancels a warning. That's because we can't be sure
21638 -- there isn't an instantiation in some other unit
21639 -- where a warning is suppressed.
21641 -- We could do a little better here by checking if the
21642 -- generic unit we are inside is public, but for now
21643 -- we don't bother with that refinement.
21645 if Chars (Argx) = Name_Off then
21646 Set_Specific_Warning_Off
21647 (Loc, Name_Buffer (1 .. Name_Len), Reason,
21648 Config => Is_Configuration_Pragma,
21649 Used => Inside_A_Generic or else In_Instance);
21651 elsif Chars (Argx) = Name_On then
21652 Set_Specific_Warning_On
21653 (Loc, Name_Buffer (1 .. Name_Len), Err);
21655 if Err then
21656 Error_Msg
21657 ("??pragma Warnings On with no matching "
21658 & "Warnings Off", Loc);
21659 end if;
21660 end if;
21661 end if;
21662 end;
21663 end if;
21664 end;
21665 end Warnings;
21667 -------------------
21668 -- Weak_External --
21669 -------------------
21671 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
21673 when Pragma_Weak_External => Weak_External : declare
21674 Ent : Entity_Id;
21676 begin
21677 GNAT_Pragma;
21678 Check_Arg_Count (1);
21679 Check_Optional_Identifier (Arg1, Name_Entity);
21680 Check_Arg_Is_Library_Level_Local_Name (Arg1);
21681 Ent := Entity (Get_Pragma_Arg (Arg1));
21683 if Rep_Item_Too_Early (Ent, N) then
21684 return;
21685 else
21686 Ent := Underlying_Type (Ent);
21687 end if;
21689 -- The only processing required is to link this item on to the
21690 -- list of rep items for the given entity. This is accomplished
21691 -- by the call to Rep_Item_Too_Late (when no error is detected
21692 -- and False is returned).
21694 if Rep_Item_Too_Late (Ent, N) then
21695 return;
21696 else
21697 Set_Has_Gigi_Rep_Item (Ent);
21698 end if;
21699 end Weak_External;
21701 -----------------------------
21702 -- Wide_Character_Encoding --
21703 -----------------------------
21705 -- pragma Wide_Character_Encoding (IDENTIFIER);
21707 when Pragma_Wide_Character_Encoding =>
21708 GNAT_Pragma;
21710 -- Nothing to do, handled in parser. Note that we do not enforce
21711 -- configuration pragma placement, this pragma can appear at any
21712 -- place in the source, allowing mixed encodings within a single
21713 -- source program.
21715 null;
21717 --------------------
21718 -- Unknown_Pragma --
21719 --------------------
21721 -- Should be impossible, since the case of an unknown pragma is
21722 -- separately processed before the case statement is entered.
21724 when Unknown_Pragma =>
21725 raise Program_Error;
21726 end case;
21728 -- AI05-0144: detect dangerous order dependence. Disabled for now,
21729 -- until AI is formally approved.
21731 -- Check_Order_Dependence;
21733 exception
21734 when Pragma_Exit => null;
21735 end Analyze_Pragma;
21737 ---------------------------------------------
21738 -- Analyze_Pre_Post_Condition_In_Decl_Part --
21739 ---------------------------------------------
21741 procedure Analyze_Pre_Post_Condition_In_Decl_Part (N : Node_Id) is
21742 procedure Process_Class_Wide_Condition
21743 (Expr : Node_Id;
21744 Spec_Id : Entity_Id;
21745 Subp_Decl : Node_Id);
21746 -- Replace the type of all references to the controlling formal of
21747 -- subprogram Spec_Id found in expression Expr with the corresponding
21748 -- class-wide type. Subp_Decl is the subprogram [body] declaration
21749 -- where the pragma resides.
21751 ----------------------------------
21752 -- Process_Class_Wide_Condition --
21753 ----------------------------------
21755 procedure Process_Class_Wide_Condition
21756 (Expr : Node_Id;
21757 Spec_Id : Entity_Id;
21758 Subp_Decl : Node_Id)
21760 Disp_Typ : constant Entity_Id := Find_Dispatching_Type (Spec_Id);
21762 ACW : Entity_Id := Empty;
21763 -- Access to Disp_Typ'Class, created if there is a controlling formal
21764 -- that is an access parameter.
21766 function Access_Class_Wide_Type return Entity_Id;
21767 -- If expression Expr contains a reference to a controlling access
21768 -- parameter, create an access to Disp_Typ'Class for the necessary
21769 -- conversions if one does not exist.
21771 function Replace_Type (N : Node_Id) return Traverse_Result;
21772 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
21773 -- aspect for a primitive subprogram of a tagged type Disp_Typ, a
21774 -- name that denotes a formal parameter of type Disp_Typ is treated
21775 -- as having type Disp_Typ'Class. Similarly, a name that denotes a
21776 -- formal access parameter of type access-to-Disp_Typ is interpreted
21777 -- as with type access-to-Disp_Typ'Class. This ensures the expression
21778 -- is well defined for a primitive subprogram of a type descended
21779 -- from Disp_Typ.
21781 ----------------------------
21782 -- Access_Class_Wide_Type --
21783 ----------------------------
21785 function Access_Class_Wide_Type return Entity_Id is
21786 Loc : constant Source_Ptr := Sloc (N);
21788 begin
21789 if No (ACW) then
21790 ACW := Make_Temporary (Loc, 'T');
21792 Insert_Before_And_Analyze (Subp_Decl,
21793 Make_Full_Type_Declaration (Loc,
21794 Defining_Identifier => ACW,
21795 Type_Definition =>
21796 Make_Access_To_Object_Definition (Loc,
21797 Subtype_Indication =>
21798 New_Occurrence_Of (Class_Wide_Type (Disp_Typ), Loc),
21799 All_Present => True)));
21801 Freeze_Before (Subp_Decl, ACW);
21802 end if;
21804 return ACW;
21805 end Access_Class_Wide_Type;
21807 ------------------
21808 -- Replace_Type --
21809 ------------------
21811 function Replace_Type (N : Node_Id) return Traverse_Result is
21812 Context : constant Node_Id := Parent (N);
21813 Loc : constant Source_Ptr := Sloc (N);
21814 CW_Typ : Entity_Id := Empty;
21815 Ent : Entity_Id;
21816 Typ : Entity_Id;
21818 begin
21819 if Is_Entity_Name (N)
21820 and then Present (Entity (N))
21821 and then Is_Formal (Entity (N))
21822 then
21823 Ent := Entity (N);
21824 Typ := Etype (Ent);
21826 -- Do not perform the type replacement for selector names in
21827 -- parameter associations. These carry an entity for reference
21828 -- purposes, but semantically they are just identifiers.
21830 if Nkind (Context) = N_Type_Conversion then
21831 null;
21833 elsif Nkind (Context) = N_Parameter_Association
21834 and then Selector_Name (Context) = N
21835 then
21836 null;
21838 elsif Typ = Disp_Typ then
21839 CW_Typ := Class_Wide_Type (Typ);
21841 elsif Is_Access_Type (Typ)
21842 and then Designated_Type (Typ) = Disp_Typ
21843 then
21844 CW_Typ := Access_Class_Wide_Type;
21845 end if;
21847 if Present (CW_Typ) then
21848 Rewrite (N,
21849 Make_Type_Conversion (Loc,
21850 Subtype_Mark => New_Occurrence_Of (CW_Typ, Loc),
21851 Expression => New_Occurrence_Of (Ent, Loc)));
21852 Set_Etype (N, CW_Typ);
21853 end if;
21854 end if;
21856 return OK;
21857 end Replace_Type;
21859 procedure Replace_Types is new Traverse_Proc (Replace_Type);
21861 -- Start of processing for Process_Class_Wide_Condition
21863 begin
21864 -- The subprogram subject to Pre'Class/Post'Class does not have a
21865 -- dispatching type, therefore the aspect/pragma is illegal.
21867 if No (Disp_Typ) then
21868 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
21870 if From_Aspect_Specification (N) then
21871 Error_Msg_N
21872 ("aspect % can only be specified for a primitive operation "
21873 & "of a tagged type", Corresponding_Aspect (N));
21875 -- The pragma is a source construct
21877 else
21878 Error_Msg_N
21879 ("pragma % can only be specified for a primitive operation "
21880 & "of a tagged type", N);
21881 end if;
21882 end if;
21884 Replace_Types (Expr);
21885 end Process_Class_Wide_Condition;
21887 -- Local variables
21889 Subp_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
21890 Spec_Id : constant Entity_Id := Corresponding_Spec_Of (Subp_Decl);
21891 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
21893 Restore_Scope : Boolean := False;
21895 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
21897 begin
21898 -- Ensure that the subprogram and its formals are visible when analyzing
21899 -- the expression of the pragma.
21901 if not In_Open_Scopes (Spec_Id) then
21902 Restore_Scope := True;
21903 Push_Scope (Spec_Id);
21905 if Is_Generic_Subprogram (Spec_Id) then
21906 Install_Generic_Formals (Spec_Id);
21907 else
21908 Install_Formals (Spec_Id);
21909 end if;
21910 end if;
21912 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
21914 -- For a class-wide condition, a reference to a controlling formal must
21915 -- be interpreted as having the class-wide type (or an access to such)
21916 -- so that the inherited condition can be properly applied to any
21917 -- overriding operation (see ARM12 6.6.1 (7)).
21919 if Class_Present (N) then
21920 Process_Class_Wide_Condition (Expr, Spec_Id, Subp_Decl);
21921 end if;
21923 if Restore_Scope then
21924 End_Scope;
21925 end if;
21927 -- Currently it is not possible to inline pre/postconditions on a
21928 -- subprogram subject to pragma Inline_Always.
21930 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
21931 end Analyze_Pre_Post_Condition_In_Decl_Part;
21933 ------------------------------------------
21934 -- Analyze_Refined_Depends_In_Decl_Part --
21935 ------------------------------------------
21937 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
21938 Body_Inputs : Elist_Id := No_Elist;
21939 Body_Outputs : Elist_Id := No_Elist;
21940 -- The inputs and outputs of the subprogram body synthesized from pragma
21941 -- Refined_Depends.
21943 Dependencies : List_Id := No_List;
21944 Depends : Node_Id;
21945 -- The corresponding Depends pragma along with its clauses
21947 Matched_Items : Elist_Id := No_Elist;
21948 -- A list containing the entities of all successfully matched items
21949 -- found in pragma Depends.
21951 Refinements : List_Id := No_List;
21952 -- The clauses of pragma Refined_Depends
21954 Spec_Id : Entity_Id;
21955 -- The entity of the subprogram subject to pragma Refined_Depends
21957 Spec_Inputs : Elist_Id := No_Elist;
21958 Spec_Outputs : Elist_Id := No_Elist;
21959 -- The inputs and outputs of the subprogram spec synthesized from pragma
21960 -- Depends.
21962 procedure Check_Dependency_Clause (Dep_Clause : Node_Id);
21963 -- Try to match a single dependency clause Dep_Clause against one or
21964 -- more refinement clauses found in list Refinements. Each successful
21965 -- match eliminates at least one refinement clause from Refinements.
21967 procedure Check_Output_States;
21968 -- Determine whether pragma Depends contains an output state with a
21969 -- visible refinement and if so, ensure that pragma Refined_Depends
21970 -- mentions all its constituents as outputs.
21972 procedure Normalize_Clauses (Clauses : List_Id);
21973 -- Given a list of dependence or refinement clauses Clauses, normalize
21974 -- each clause by creating multiple dependencies with exactly one input
21975 -- and one output.
21977 procedure Report_Extra_Clauses;
21978 -- Emit an error for each extra clause found in list Refinements
21980 -----------------------------
21981 -- Check_Dependency_Clause --
21982 -----------------------------
21984 procedure Check_Dependency_Clause (Dep_Clause : Node_Id) is
21985 Dep_Input : constant Node_Id := Expression (Dep_Clause);
21986 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
21988 function Is_In_Out_State_Clause return Boolean;
21989 -- Determine whether dependence clause Dep_Clause denotes an abstract
21990 -- state that depends on itself (State => State).
21992 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
21993 -- Determine whether item Item denotes an abstract state with visible
21994 -- null refinement.
21996 procedure Match_Items
21997 (Dep_Item : Node_Id;
21998 Ref_Item : Node_Id;
21999 Matched : out Boolean);
22000 -- Try to match dependence item Dep_Item against refinement item
22001 -- Ref_Item. To match against a possible null refinement (see 2, 7),
22002 -- set Ref_Item to Empty. Flag Matched is set to True when one of
22003 -- the following conformance scenarios is in effect:
22004 -- 1) Both items denote null
22005 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
22006 -- 3) Both items denote attribute 'Result
22007 -- 4) Both items denote the same formal parameter
22008 -- 5) Both items denote the same object
22009 -- 6) Dep_Item is an abstract state with visible null refinement
22010 -- and Ref_Item denotes null.
22011 -- 7) Dep_Item is an abstract state with visible null refinement
22012 -- and Ref_Item is Empty (special case).
22013 -- 8) Dep_Item is an abstract state with visible non-null
22014 -- refinement and Ref_Item denotes one of its constituents.
22015 -- 9) Dep_Item is an abstract state without a visible refinement
22016 -- and Ref_Item denotes the same state.
22017 -- When scenario 8 is in effect, the entity of the abstract state
22018 -- denoted by Dep_Item is added to list Refined_States.
22020 procedure Record_Item (Item_Id : Entity_Id);
22021 -- Store the entity of an item denoted by Item_Id in Matched_Items
22023 ----------------------------
22024 -- Is_In_Out_State_Clause --
22025 ----------------------------
22027 function Is_In_Out_State_Clause return Boolean is
22028 Dep_Input_Id : Entity_Id;
22029 Dep_Output_Id : Entity_Id;
22031 begin
22032 -- Detect the following clause:
22033 -- State => State
22035 if Is_Entity_Name (Dep_Input)
22036 and then Is_Entity_Name (Dep_Output)
22037 then
22038 -- Handle abstract views generated for limited with clauses
22040 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
22041 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
22043 return
22044 Ekind (Dep_Input_Id) = E_Abstract_State
22045 and then Dep_Input_Id = Dep_Output_Id;
22046 else
22047 return False;
22048 end if;
22049 end Is_In_Out_State_Clause;
22051 ---------------------------
22052 -- Is_Null_Refined_State --
22053 ---------------------------
22055 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
22056 Item_Id : Entity_Id;
22058 begin
22059 if Is_Entity_Name (Item) then
22061 -- Handle abstract views generated for limited with clauses
22063 Item_Id := Available_View (Entity_Of (Item));
22065 return Ekind (Item_Id) = E_Abstract_State
22066 and then Has_Null_Refinement (Item_Id);
22068 else
22069 return False;
22070 end if;
22071 end Is_Null_Refined_State;
22073 -----------------
22074 -- Match_Items --
22075 -----------------
22077 procedure Match_Items
22078 (Dep_Item : Node_Id;
22079 Ref_Item : Node_Id;
22080 Matched : out Boolean)
22082 Dep_Item_Id : Entity_Id;
22083 Ref_Item_Id : Entity_Id;
22085 begin
22086 -- Assume that the two items do not match
22088 Matched := False;
22090 -- A null matches null or Empty (special case)
22092 if Nkind (Dep_Item) = N_Null
22093 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
22094 then
22095 Matched := True;
22097 -- Attribute 'Result matches attribute 'Result
22099 elsif Is_Attribute_Result (Dep_Item)
22100 and then Is_Attribute_Result (Dep_Item)
22101 then
22102 Matched := True;
22104 -- Abstract states, formal parameters and objects
22106 elsif Is_Entity_Name (Dep_Item) then
22108 -- Handle abstract views generated for limited with clauses
22110 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
22112 if Ekind (Dep_Item_Id) = E_Abstract_State then
22114 -- An abstract state with visible null refinement matches
22115 -- null or Empty (special case).
22117 if Has_Null_Refinement (Dep_Item_Id)
22118 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
22119 then
22120 Record_Item (Dep_Item_Id);
22121 Matched := True;
22123 -- An abstract state with visible non-null refinement
22124 -- matches one of its constituents.
22126 elsif Has_Non_Null_Refinement (Dep_Item_Id) then
22127 if Is_Entity_Name (Ref_Item) then
22128 Ref_Item_Id := Entity_Of (Ref_Item);
22130 if Ekind_In (Ref_Item_Id, E_Abstract_State,
22131 E_Constant,
22132 E_Variable)
22133 and then Present (Encapsulating_State (Ref_Item_Id))
22134 and then Encapsulating_State (Ref_Item_Id) =
22135 Dep_Item_Id
22136 then
22137 Record_Item (Dep_Item_Id);
22138 Matched := True;
22139 end if;
22140 end if;
22142 -- An abstract state without a visible refinement matches
22143 -- itself.
22145 elsif Is_Entity_Name (Ref_Item)
22146 and then Entity_Of (Ref_Item) = Dep_Item_Id
22147 then
22148 Record_Item (Dep_Item_Id);
22149 Matched := True;
22150 end if;
22152 -- A formal parameter or an object matches itself
22154 elsif Is_Entity_Name (Ref_Item)
22155 and then Entity_Of (Ref_Item) = Dep_Item_Id
22156 then
22157 Record_Item (Dep_Item_Id);
22158 Matched := True;
22159 end if;
22160 end if;
22161 end Match_Items;
22163 -----------------
22164 -- Record_Item --
22165 -----------------
22167 procedure Record_Item (Item_Id : Entity_Id) is
22168 begin
22169 if not Contains (Matched_Items, Item_Id) then
22170 Add_Item (Item_Id, Matched_Items);
22171 end if;
22172 end Record_Item;
22174 -- Local variables
22176 Clause_Matched : Boolean := False;
22177 Dummy : Boolean := False;
22178 Inputs_Match : Boolean;
22179 Next_Ref_Clause : Node_Id;
22180 Outputs_Match : Boolean;
22181 Ref_Clause : Node_Id;
22182 Ref_Input : Node_Id;
22183 Ref_Output : Node_Id;
22185 -- Start of processing for Check_Dependency_Clause
22187 begin
22188 -- Do not perform this check in an instance because it was already
22189 -- performed successfully in the generic template.
22191 if Is_Generic_Instance (Spec_Id) then
22192 return;
22193 end if;
22195 -- Examine all refinement clauses and compare them against the
22196 -- dependence clause.
22198 Ref_Clause := First (Refinements);
22199 while Present (Ref_Clause) loop
22200 Next_Ref_Clause := Next (Ref_Clause);
22202 -- Obtain the attributes of the current refinement clause
22204 Ref_Input := Expression (Ref_Clause);
22205 Ref_Output := First (Choices (Ref_Clause));
22207 -- The current refinement clause matches the dependence clause
22208 -- when both outputs match and both inputs match. See routine
22209 -- Match_Items for all possible conformance scenarios.
22211 -- Depends Dep_Output => Dep_Input
22212 -- ^ ^
22213 -- match ? match ?
22214 -- v v
22215 -- Refined_Depends Ref_Output => Ref_Input
22217 Match_Items
22218 (Dep_Item => Dep_Input,
22219 Ref_Item => Ref_Input,
22220 Matched => Inputs_Match);
22222 Match_Items
22223 (Dep_Item => Dep_Output,
22224 Ref_Item => Ref_Output,
22225 Matched => Outputs_Match);
22227 -- An In_Out state clause may be matched against a refinement with
22228 -- a null input or null output as long as the non-null side of the
22229 -- relation contains a valid constituent of the In_Out_State.
22231 if Is_In_Out_State_Clause then
22233 -- Depends => (State => State)
22234 -- Refined_Depends => (null => Constit) -- OK
22236 if Inputs_Match
22237 and then not Outputs_Match
22238 and then Nkind (Ref_Output) = N_Null
22239 then
22240 Outputs_Match := True;
22241 end if;
22243 -- Depends => (State => State)
22244 -- Refined_Depends => (Constit => null) -- OK
22246 if not Inputs_Match
22247 and then Outputs_Match
22248 and then Nkind (Ref_Input) = N_Null
22249 then
22250 Inputs_Match := True;
22251 end if;
22252 end if;
22254 -- The current refinement clause is legally constructed following
22255 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
22256 -- the pool of candidates. The seach continues because a single
22257 -- dependence clause may have multiple matching refinements.
22259 if Inputs_Match and then Outputs_Match then
22260 Clause_Matched := True;
22261 Remove (Ref_Clause);
22262 end if;
22264 Ref_Clause := Next_Ref_Clause;
22265 end loop;
22267 -- Depending on the order or composition of refinement clauses, an
22268 -- In_Out state clause may not be directly refinable.
22270 -- Depends => ((Output, State) => (Input, State))
22271 -- Refined_State => (State => (Constit_1, Constit_2))
22272 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
22274 -- Matching normalized clause (State => State) fails because there is
22275 -- no direct refinement capable of satisfying this relation. Another
22276 -- similar case arises when clauses (Constit_1 => Input) and (Output
22277 -- => Constit_2) are matched first, leaving no candidates for clause
22278 -- (State => State). Both scenarios are legal as long as one of the
22279 -- previous clauses mentioned a valid constituent of State.
22281 if not Clause_Matched
22282 and then Is_In_Out_State_Clause
22283 and then
22284 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
22285 then
22286 Clause_Matched := True;
22287 end if;
22289 -- A clause where the input is an abstract state with visible null
22290 -- refinement is implicitly matched when the output has already been
22291 -- matched in a previous clause.
22293 -- Depends => (Output => State) -- implicitly OK
22294 -- Refined_State => (State => null)
22295 -- Refined_Depends => (Output => ...)
22297 if not Clause_Matched
22298 and then Is_Null_Refined_State (Dep_Input)
22299 and then Is_Entity_Name (Dep_Output)
22300 and then
22301 Contains (Matched_Items, Available_View (Entity_Of (Dep_Output)))
22302 then
22303 Clause_Matched := True;
22304 end if;
22306 -- A clause where the output is an abstract state with visible null
22307 -- refinement is implicitly matched when the input has already been
22308 -- matched in a previous clause.
22310 -- Depends => (State => Input) -- implicitly OK
22311 -- Refined_State => (State => null)
22312 -- Refined_Depends => (... => Input)
22314 if not Clause_Matched
22315 and then Is_Null_Refined_State (Dep_Output)
22316 and then Is_Entity_Name (Dep_Input)
22317 and then
22318 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
22319 then
22320 Clause_Matched := True;
22321 end if;
22323 -- At this point either all refinement clauses have been examined or
22324 -- pragma Refined_Depends contains a solitary null. Only an abstract
22325 -- state with null refinement can possibly match these cases.
22327 -- Depends => (State => null)
22328 -- Refined_State => (State => null)
22329 -- Refined_Depends => null -- OK
22331 if not Clause_Matched then
22332 Match_Items
22333 (Dep_Item => Dep_Input,
22334 Ref_Item => Empty,
22335 Matched => Inputs_Match);
22337 Match_Items
22338 (Dep_Item => Dep_Output,
22339 Ref_Item => Empty,
22340 Matched => Outputs_Match);
22342 Clause_Matched := Inputs_Match and Outputs_Match;
22343 end if;
22345 -- If the contents of Refined_Depends are legal, then the current
22346 -- dependence clause should be satisfied either by an explicit match
22347 -- or by one of the special cases.
22349 if not Clause_Matched then
22350 SPARK_Msg_NE
22351 ("dependence clause of subprogram & has no matching refinement "
22352 & "in body", Dep_Clause, Spec_Id);
22353 end if;
22354 end Check_Dependency_Clause;
22356 -------------------------
22357 -- Check_Output_States --
22358 -------------------------
22360 procedure Check_Output_States is
22361 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22362 -- Determine whether all constituents of state State_Id with visible
22363 -- refinement are used as outputs in pragma Refined_Depends. Emit an
22364 -- error if this is not the case.
22366 -----------------------------
22367 -- Check_Constituent_Usage --
22368 -----------------------------
22370 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22371 Constit_Elmt : Elmt_Id;
22372 Constit_Id : Entity_Id;
22373 Posted : Boolean := False;
22375 begin
22376 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22377 while Present (Constit_Elmt) loop
22378 Constit_Id := Node (Constit_Elmt);
22380 -- The constituent acts as an input (SPARK RM 7.2.5(3))
22382 if Present (Body_Inputs)
22383 and then Appears_In (Body_Inputs, Constit_Id)
22384 then
22385 Error_Msg_Name_1 := Chars (State_Id);
22386 SPARK_Msg_NE
22387 ("constituent & of state % must act as output in "
22388 & "dependence refinement", N, Constit_Id);
22390 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
22392 elsif No (Body_Outputs)
22393 or else not Appears_In (Body_Outputs, Constit_Id)
22394 then
22395 if not Posted then
22396 Posted := True;
22397 SPARK_Msg_NE
22398 ("output state & must be replaced by all its "
22399 & "constituents in dependence refinement",
22400 N, State_Id);
22401 end if;
22403 SPARK_Msg_NE
22404 ("\constituent & is missing in output list",
22405 N, Constit_Id);
22406 end if;
22408 Next_Elmt (Constit_Elmt);
22409 end loop;
22410 end Check_Constituent_Usage;
22412 -- Local variables
22414 Item : Node_Id;
22415 Item_Elmt : Elmt_Id;
22416 Item_Id : Entity_Id;
22418 -- Start of processing for Check_Output_States
22420 begin
22421 -- Do not perform this check in an instance because it was already
22422 -- performed successfully in the generic template.
22424 if Is_Generic_Instance (Spec_Id) then
22425 null;
22427 -- Inspect the outputs of pragma Depends looking for a state with a
22428 -- visible refinement.
22430 elsif Present (Spec_Outputs) then
22431 Item_Elmt := First_Elmt (Spec_Outputs);
22432 while Present (Item_Elmt) loop
22433 Item := Node (Item_Elmt);
22435 -- Deal with the mixed nature of the input and output lists
22437 if Nkind (Item) = N_Defining_Identifier then
22438 Item_Id := Item;
22439 else
22440 Item_Id := Available_View (Entity_Of (Item));
22441 end if;
22443 if Ekind (Item_Id) = E_Abstract_State then
22445 -- The state acts as an input-output, skip it
22447 if Present (Spec_Inputs)
22448 and then Appears_In (Spec_Inputs, Item_Id)
22449 then
22450 null;
22452 -- Ensure that all of the constituents are utilized as
22453 -- outputs in pragma Refined_Depends.
22455 elsif Has_Non_Null_Refinement (Item_Id) then
22456 Check_Constituent_Usage (Item_Id);
22457 end if;
22458 end if;
22460 Next_Elmt (Item_Elmt);
22461 end loop;
22462 end if;
22463 end Check_Output_States;
22465 -----------------------
22466 -- Normalize_Clauses --
22467 -----------------------
22469 procedure Normalize_Clauses (Clauses : List_Id) is
22470 procedure Normalize_Inputs (Clause : Node_Id);
22471 -- Normalize clause Clause by creating multiple clauses for each
22472 -- input item of Clause. It is assumed that Clause has exactly one
22473 -- output. The transformation is as follows:
22475 -- Output => (Input_1, Input_2) -- original
22477 -- Output => Input_1 -- normalizations
22478 -- Output => Input_2
22480 procedure Normalize_Outputs (Clause : Node_Id);
22481 -- Normalize clause Clause by creating multiple clause for each
22482 -- output item of Clause. The transformation is as follows:
22484 -- (Output_1, Output_2) => Input -- original
22486 -- Output_1 => Input -- normalization
22487 -- Output_2 => Input
22489 ----------------------
22490 -- Normalize_Inputs --
22491 ----------------------
22493 procedure Normalize_Inputs (Clause : Node_Id) is
22494 Inputs : constant Node_Id := Expression (Clause);
22495 Loc : constant Source_Ptr := Sloc (Clause);
22496 Output : constant List_Id := Choices (Clause);
22497 Last_Input : Node_Id;
22498 Input : Node_Id;
22499 New_Clause : Node_Id;
22500 Next_Input : Node_Id;
22502 begin
22503 -- Normalization is performed only when the original clause has
22504 -- more than one input. Multiple inputs appear as an aggregate.
22506 if Nkind (Inputs) = N_Aggregate then
22507 Last_Input := Last (Expressions (Inputs));
22509 -- Create a new clause for each input
22511 Input := First (Expressions (Inputs));
22512 while Present (Input) loop
22513 Next_Input := Next (Input);
22515 -- Unhook the current input from the original input list
22516 -- because it will be relocated to a new clause.
22518 Remove (Input);
22520 -- Special processing for the last input. At this point the
22521 -- original aggregate has been stripped down to one element.
22522 -- Replace the aggregate by the element itself.
22524 if Input = Last_Input then
22525 Rewrite (Inputs, Input);
22527 -- Generate a clause of the form:
22528 -- Output => Input
22530 else
22531 New_Clause :=
22532 Make_Component_Association (Loc,
22533 Choices => New_Copy_List_Tree (Output),
22534 Expression => Input);
22536 -- The new clause contains replicated content that has
22537 -- already been analyzed, mark the clause as analyzed.
22539 Set_Analyzed (New_Clause);
22540 Insert_After (Clause, New_Clause);
22541 end if;
22543 Input := Next_Input;
22544 end loop;
22545 end if;
22546 end Normalize_Inputs;
22548 -----------------------
22549 -- Normalize_Outputs --
22550 -----------------------
22552 procedure Normalize_Outputs (Clause : Node_Id) is
22553 Inputs : constant Node_Id := Expression (Clause);
22554 Loc : constant Source_Ptr := Sloc (Clause);
22555 Outputs : constant Node_Id := First (Choices (Clause));
22556 Last_Output : Node_Id;
22557 New_Clause : Node_Id;
22558 Next_Output : Node_Id;
22559 Output : Node_Id;
22561 begin
22562 -- Multiple outputs appear as an aggregate. Nothing to do when
22563 -- the clause has exactly one output.
22565 if Nkind (Outputs) = N_Aggregate then
22566 Last_Output := Last (Expressions (Outputs));
22568 -- Create a clause for each output. Note that each time a new
22569 -- clause is created, the original output list slowly shrinks
22570 -- until there is one item left.
22572 Output := First (Expressions (Outputs));
22573 while Present (Output) loop
22574 Next_Output := Next (Output);
22576 -- Unhook the output from the original output list as it
22577 -- will be relocated to a new clause.
22579 Remove (Output);
22581 -- Special processing for the last output. At this point
22582 -- the original aggregate has been stripped down to one
22583 -- element. Replace the aggregate by the element itself.
22585 if Output = Last_Output then
22586 Rewrite (Outputs, Output);
22588 else
22589 -- Generate a clause of the form:
22590 -- (Output => Inputs)
22592 New_Clause :=
22593 Make_Component_Association (Loc,
22594 Choices => New_List (Output),
22595 Expression => New_Copy_Tree (Inputs));
22597 -- The new clause contains replicated content that has
22598 -- already been analyzed. There is not need to reanalyze
22599 -- them.
22601 Set_Analyzed (New_Clause);
22602 Insert_After (Clause, New_Clause);
22603 end if;
22605 Output := Next_Output;
22606 end loop;
22607 end if;
22608 end Normalize_Outputs;
22610 -- Local variables
22612 Clause : Node_Id;
22614 -- Start of processing for Normalize_Clauses
22616 begin
22617 Clause := First (Clauses);
22618 while Present (Clause) loop
22619 Normalize_Outputs (Clause);
22620 Next (Clause);
22621 end loop;
22623 Clause := First (Clauses);
22624 while Present (Clause) loop
22625 Normalize_Inputs (Clause);
22626 Next (Clause);
22627 end loop;
22628 end Normalize_Clauses;
22630 --------------------------
22631 -- Report_Extra_Clauses --
22632 --------------------------
22634 procedure Report_Extra_Clauses is
22635 Clause : Node_Id;
22637 begin
22638 -- Do not perform this check in an instance because it was already
22639 -- performed successfully in the generic template.
22641 if Is_Generic_Instance (Spec_Id) then
22642 null;
22644 elsif Present (Refinements) then
22645 Clause := First (Refinements);
22646 while Present (Clause) loop
22648 -- Do not complain about a null input refinement, since a null
22649 -- input legitimately matches anything.
22651 if Nkind (Clause) = N_Component_Association
22652 and then Nkind (Expression (Clause)) = N_Null
22653 then
22654 null;
22656 else
22657 SPARK_Msg_N
22658 ("unmatched or extra clause in dependence refinement",
22659 Clause);
22660 end if;
22662 Next (Clause);
22663 end loop;
22664 end if;
22665 end Report_Extra_Clauses;
22667 -- Local variables
22669 Body_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
22670 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
22671 Errors : constant Nat := Serious_Errors_Detected;
22672 Clause : Node_Id;
22673 Deps : Node_Id;
22674 Dummy : Boolean;
22675 Refs : Node_Id;
22677 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
22679 begin
22680 if Nkind (Body_Decl) = N_Subprogram_Body_Stub then
22681 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
22682 else
22683 Spec_Id := Corresponding_Spec (Body_Decl);
22684 end if;
22686 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
22688 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
22689 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
22691 if No (Depends) then
22692 SPARK_Msg_NE
22693 ("useless refinement, declaration of subprogram & lacks aspect or "
22694 & "pragma Depends", N, Spec_Id);
22695 return;
22696 end if;
22698 Deps := Expression (Get_Argument (Depends, Spec_Id));
22700 -- A null dependency relation renders the refinement useless because it
22701 -- cannot possibly mention abstract states with visible refinement. Note
22702 -- that the inverse is not true as states may be refined to null
22703 -- (SPARK RM 7.2.5(2)).
22705 if Nkind (Deps) = N_Null then
22706 SPARK_Msg_NE
22707 ("useless refinement, subprogram & does not depend on abstract "
22708 & "state with visible refinement", N, Spec_Id);
22709 return;
22710 end if;
22712 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
22713 -- This ensures that the categorization of all refined dependency items
22714 -- is consistent with their role.
22716 Analyze_Depends_In_Decl_Part (N);
22718 -- Do not match dependencies against refinements if Refined_Depends is
22719 -- illegal to avoid emitting misleading error.
22721 if Serious_Errors_Detected = Errors then
22723 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
22724 -- the inputs and outputs of the subprogram spec and body to verify
22725 -- the use of states with visible refinement and their constituents.
22727 if No (Get_Pragma (Spec_Id, Pragma_Global))
22728 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
22729 then
22730 Collect_Subprogram_Inputs_Outputs
22731 (Subp_Id => Spec_Id,
22732 Synthesize => True,
22733 Subp_Inputs => Spec_Inputs,
22734 Subp_Outputs => Spec_Outputs,
22735 Global_Seen => Dummy);
22737 Collect_Subprogram_Inputs_Outputs
22738 (Subp_Id => Body_Id,
22739 Synthesize => True,
22740 Subp_Inputs => Body_Inputs,
22741 Subp_Outputs => Body_Outputs,
22742 Global_Seen => Dummy);
22744 -- For an output state with a visible refinement, ensure that all
22745 -- constituents appear as outputs in the dependency refinement.
22747 Check_Output_States;
22748 end if;
22750 -- Matching is disabled in ASIS because clauses are not normalized as
22751 -- this is a tree altering activity similar to expansion.
22753 if ASIS_Mode then
22754 return;
22755 end if;
22757 -- Multiple dependency clauses appear as component associations of an
22758 -- aggregate. Note that the clauses are copied because the algorithm
22759 -- modifies them and this should not be visible in Depends.
22761 pragma Assert (Nkind (Deps) = N_Aggregate);
22762 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
22763 Normalize_Clauses (Dependencies);
22765 Refs := Expression (Get_Argument (N, Spec_Id));
22767 if Nkind (Refs) = N_Null then
22768 Refinements := No_List;
22770 -- Multiple dependency clauses appear as component associations of an
22771 -- aggregate. Note that the clauses are copied because the algorithm
22772 -- modifies them and this should not be visible in Refined_Depends.
22774 else pragma Assert (Nkind (Refs) = N_Aggregate);
22775 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
22776 Normalize_Clauses (Refinements);
22777 end if;
22779 -- At this point the clauses of pragmas Depends and Refined_Depends
22780 -- have been normalized into simple dependencies between one output
22781 -- and one input. Examine all clauses of pragma Depends looking for
22782 -- matching clauses in pragma Refined_Depends.
22784 Clause := First (Dependencies);
22785 while Present (Clause) loop
22786 Check_Dependency_Clause (Clause);
22787 Next (Clause);
22788 end loop;
22790 if Serious_Errors_Detected = Errors then
22791 Report_Extra_Clauses;
22792 end if;
22793 end if;
22794 end Analyze_Refined_Depends_In_Decl_Part;
22796 -----------------------------------------
22797 -- Analyze_Refined_Global_In_Decl_Part --
22798 -----------------------------------------
22800 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
22801 Global : Node_Id;
22802 -- The corresponding Global pragma
22804 Has_In_State : Boolean := False;
22805 Has_In_Out_State : Boolean := False;
22806 Has_Out_State : Boolean := False;
22807 Has_Proof_In_State : Boolean := False;
22808 -- These flags are set when the corresponding Global pragma has a state
22809 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
22810 -- refinement.
22812 Has_Null_State : Boolean := False;
22813 -- This flag is set when the corresponding Global pragma has at least
22814 -- one state with a null refinement.
22816 In_Constits : Elist_Id := No_Elist;
22817 In_Out_Constits : Elist_Id := No_Elist;
22818 Out_Constits : Elist_Id := No_Elist;
22819 Proof_In_Constits : Elist_Id := No_Elist;
22820 -- These lists contain the entities of all Input, In_Out, Output and
22821 -- Proof_In constituents that appear in Refined_Global and participate
22822 -- in state refinement.
22824 In_Items : Elist_Id := No_Elist;
22825 In_Out_Items : Elist_Id := No_Elist;
22826 Out_Items : Elist_Id := No_Elist;
22827 Proof_In_Items : Elist_Id := No_Elist;
22828 -- These list contain the entities of all Input, In_Out, Output and
22829 -- Proof_In items defined in the corresponding Global pragma.
22831 Spec_Id : Entity_Id;
22832 -- The entity of the subprogram subject to pragma Refined_Global
22834 procedure Check_In_Out_States;
22835 -- Determine whether the corresponding Global pragma mentions In_Out
22836 -- states with visible refinement and if so, ensure that one of the
22837 -- following completions apply to the constituents of the state:
22838 -- 1) there is at least one constituent of mode In_Out
22839 -- 2) there is at least one Input and one Output constituent
22840 -- 3) not all constituents are present and one of them is of mode
22841 -- Output.
22842 -- This routine may remove elements from In_Constits, In_Out_Constits,
22843 -- Out_Constits and Proof_In_Constits.
22845 procedure Check_Input_States;
22846 -- Determine whether the corresponding Global pragma mentions Input
22847 -- states with visible refinement and if so, ensure that at least one of
22848 -- its constituents appears as an Input item in Refined_Global.
22849 -- This routine may remove elements from In_Constits, In_Out_Constits,
22850 -- Out_Constits and Proof_In_Constits.
22852 procedure Check_Output_States;
22853 -- Determine whether the corresponding Global pragma mentions Output
22854 -- states with visible refinement and if so, ensure that all of its
22855 -- constituents appear as Output items in Refined_Global.
22856 -- This routine may remove elements from In_Constits, In_Out_Constits,
22857 -- Out_Constits and Proof_In_Constits.
22859 procedure Check_Proof_In_States;
22860 -- Determine whether the corresponding Global pragma mentions Proof_In
22861 -- states with visible refinement and if so, ensure that at least one of
22862 -- its constituents appears as a Proof_In item in Refined_Global.
22863 -- This routine may remove elements from In_Constits, In_Out_Constits,
22864 -- Out_Constits and Proof_In_Constits.
22866 procedure Check_Refined_Global_List
22867 (List : Node_Id;
22868 Global_Mode : Name_Id := Name_Input);
22869 -- Verify the legality of a single global list declaration. Global_Mode
22870 -- denotes the current mode in effect.
22872 procedure Collect_Global_Items
22873 (List : Node_Id;
22874 Mode : Name_Id := Name_Input);
22875 -- Gather all input, in out, output and Proof_In items from node List
22876 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
22877 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
22878 -- and Has_Proof_In_State are set when there is at least one abstract
22879 -- state with visible refinement available in the corresponding mode.
22880 -- Flag Has_Null_State is set when at least state has a null refinement.
22881 -- Mode enotes the current global mode in effect.
22883 function Present_Then_Remove
22884 (List : Elist_Id;
22885 Item : Entity_Id) return Boolean;
22886 -- Search List for a particular entity Item. If Item has been found,
22887 -- remove it from List. This routine is used to strip lists In_Constits,
22888 -- In_Out_Constits and Out_Constits of valid constituents.
22890 procedure Report_Extra_Constituents;
22891 -- Emit an error for each constituent found in lists In_Constits,
22892 -- In_Out_Constits and Out_Constits.
22894 -------------------------
22895 -- Check_In_Out_States --
22896 -------------------------
22898 procedure Check_In_Out_States is
22899 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22900 -- Determine whether one of the following coverage scenarios is in
22901 -- effect:
22902 -- 1) there is at least one constituent of mode In_Out
22903 -- 2) there is at least one Input and one Output constituent
22904 -- 3) not all constituents are present and one of them is of mode
22905 -- Output.
22906 -- If this is not the case, emit an error.
22908 -----------------------------
22909 -- Check_Constituent_Usage --
22910 -----------------------------
22912 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22913 Constit_Elmt : Elmt_Id;
22914 Constit_Id : Entity_Id;
22915 Has_Missing : Boolean := False;
22916 In_Out_Seen : Boolean := False;
22917 In_Seen : Boolean := False;
22918 Out_Seen : Boolean := False;
22920 begin
22921 -- Process all the constituents of the state and note their modes
22922 -- within the global refinement.
22924 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22925 while Present (Constit_Elmt) loop
22926 Constit_Id := Node (Constit_Elmt);
22928 if Present_Then_Remove (In_Constits, Constit_Id) then
22929 In_Seen := True;
22931 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
22932 In_Out_Seen := True;
22934 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
22935 Out_Seen := True;
22937 -- A Proof_In constituent cannot participate in the completion
22938 -- of an Output state (SPARK RM 7.2.4(5)).
22940 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id) then
22941 Error_Msg_Name_1 := Chars (State_Id);
22942 SPARK_Msg_NE
22943 ("constituent & of state % must have mode Input, In_Out "
22944 & "or Output in global refinement", N, Constit_Id);
22946 else
22947 Has_Missing := True;
22948 end if;
22950 Next_Elmt (Constit_Elmt);
22951 end loop;
22953 -- A single In_Out constituent is a valid completion
22955 if In_Out_Seen then
22956 null;
22958 -- A pair of one Input and one Output constituent is a valid
22959 -- completion.
22961 elsif In_Seen and then Out_Seen then
22962 null;
22964 -- A single Output constituent is a valid completion only when
22965 -- some of the other constituents are missing (SPARK RM 7.2.4(5)).
22967 elsif Has_Missing and then Out_Seen then
22968 null;
22970 else
22971 SPARK_Msg_NE
22972 ("global refinement of state & redefines the mode of its "
22973 & "constituents", N, State_Id);
22974 end if;
22975 end Check_Constituent_Usage;
22977 -- Local variables
22979 Item_Elmt : Elmt_Id;
22980 Item_Id : Entity_Id;
22982 -- Start of processing for Check_In_Out_States
22984 begin
22985 -- Do not perform this check in an instance because it was already
22986 -- performed successfully in the generic template.
22988 if Is_Generic_Instance (Spec_Id) then
22989 null;
22991 -- Inspect the In_Out items of the corresponding Global pragma
22992 -- looking for a state with a visible refinement.
22994 elsif Has_In_Out_State and then Present (In_Out_Items) then
22995 Item_Elmt := First_Elmt (In_Out_Items);
22996 while Present (Item_Elmt) loop
22997 Item_Id := Node (Item_Elmt);
22999 -- Ensure that one of the three coverage variants is satisfied
23001 if Ekind (Item_Id) = E_Abstract_State
23002 and then Has_Non_Null_Refinement (Item_Id)
23003 then
23004 Check_Constituent_Usage (Item_Id);
23005 end if;
23007 Next_Elmt (Item_Elmt);
23008 end loop;
23009 end if;
23010 end Check_In_Out_States;
23012 ------------------------
23013 -- Check_Input_States --
23014 ------------------------
23016 procedure Check_Input_States is
23017 procedure Check_Constituent_Usage (State_Id : Entity_Id);
23018 -- Determine whether at least one constituent of state State_Id with
23019 -- visible refinement is used and has mode Input. Ensure that the
23020 -- remaining constituents do not have In_Out, Output or Proof_In
23021 -- modes.
23023 -----------------------------
23024 -- Check_Constituent_Usage --
23025 -----------------------------
23027 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
23028 Constit_Elmt : Elmt_Id;
23029 Constit_Id : Entity_Id;
23030 In_Seen : Boolean := False;
23032 begin
23033 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
23034 while Present (Constit_Elmt) loop
23035 Constit_Id := Node (Constit_Elmt);
23037 -- At least one of the constituents appears as an Input
23039 if Present_Then_Remove (In_Constits, Constit_Id) then
23040 In_Seen := True;
23042 -- The constituent appears in the global refinement, but has
23043 -- mode In_Out, Output or Proof_In (SPARK RM 7.2.4(5)).
23045 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
23046 or else Present_Then_Remove (Out_Constits, Constit_Id)
23047 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
23048 then
23049 Error_Msg_Name_1 := Chars (State_Id);
23050 SPARK_Msg_NE
23051 ("constituent & of state % must have mode Input in global "
23052 & "refinement", N, Constit_Id);
23053 end if;
23055 Next_Elmt (Constit_Elmt);
23056 end loop;
23058 -- Not one of the constituents appeared as Input
23060 if not In_Seen then
23061 SPARK_Msg_NE
23062 ("global refinement of state & must include at least one "
23063 & "constituent of mode Input", N, State_Id);
23064 end if;
23065 end Check_Constituent_Usage;
23067 -- Local variables
23069 Item_Elmt : Elmt_Id;
23070 Item_Id : Entity_Id;
23072 -- Start of processing for Check_Input_States
23074 begin
23075 -- Do not perform this check in an instance because it was already
23076 -- performed successfully in the generic template.
23078 if Is_Generic_Instance (Spec_Id) then
23079 null;
23081 -- Inspect the Input items of the corresponding Global pragma looking
23082 -- for a state with a visible refinement.
23084 elsif Has_In_State and then Present (In_Items) then
23085 Item_Elmt := First_Elmt (In_Items);
23086 while Present (Item_Elmt) loop
23087 Item_Id := Node (Item_Elmt);
23089 -- Ensure that at least one of the constituents is utilized and
23090 -- is of mode Input.
23092 if Ekind (Item_Id) = E_Abstract_State
23093 and then Has_Non_Null_Refinement (Item_Id)
23094 then
23095 Check_Constituent_Usage (Item_Id);
23096 end if;
23098 Next_Elmt (Item_Elmt);
23099 end loop;
23100 end if;
23101 end Check_Input_States;
23103 -------------------------
23104 -- Check_Output_States --
23105 -------------------------
23107 procedure Check_Output_States is
23108 procedure Check_Constituent_Usage (State_Id : Entity_Id);
23109 -- Determine whether all constituents of state State_Id with visible
23110 -- refinement are used and have mode Output. Emit an error if this is
23111 -- not the case.
23113 -----------------------------
23114 -- Check_Constituent_Usage --
23115 -----------------------------
23117 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
23118 Constit_Elmt : Elmt_Id;
23119 Constit_Id : Entity_Id;
23120 Posted : Boolean := False;
23122 begin
23123 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
23124 while Present (Constit_Elmt) loop
23125 Constit_Id := Node (Constit_Elmt);
23127 if Present_Then_Remove (Out_Constits, Constit_Id) then
23128 null;
23130 -- The constituent appears in the global refinement, but has
23131 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
23133 elsif Present_Then_Remove (In_Constits, Constit_Id)
23134 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
23135 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
23136 then
23137 Error_Msg_Name_1 := Chars (State_Id);
23138 SPARK_Msg_NE
23139 ("constituent & of state % must have mode Output in "
23140 & "global refinement", N, Constit_Id);
23142 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
23144 else
23145 if not Posted then
23146 Posted := True;
23147 SPARK_Msg_NE
23148 ("output state & must be replaced by all its "
23149 & "constituents in global refinement", N, State_Id);
23150 end if;
23152 SPARK_Msg_NE
23153 ("\constituent & is missing in output list",
23154 N, Constit_Id);
23155 end if;
23157 Next_Elmt (Constit_Elmt);
23158 end loop;
23159 end Check_Constituent_Usage;
23161 -- Local variables
23163 Item_Elmt : Elmt_Id;
23164 Item_Id : Entity_Id;
23166 -- Start of processing for Check_Output_States
23168 begin
23169 -- Do not perform this check in an instance because it was already
23170 -- performed successfully in the generic template.
23172 if Is_Generic_Instance (Spec_Id) then
23173 null;
23175 -- Inspect the Output items of the corresponding Global pragma
23176 -- looking for a state with a visible refinement.
23178 elsif Has_Out_State and then Present (Out_Items) then
23179 Item_Elmt := First_Elmt (Out_Items);
23180 while Present (Item_Elmt) loop
23181 Item_Id := Node (Item_Elmt);
23183 -- Ensure that all of the constituents are utilized and they
23184 -- have mode Output.
23186 if Ekind (Item_Id) = E_Abstract_State
23187 and then Has_Non_Null_Refinement (Item_Id)
23188 then
23189 Check_Constituent_Usage (Item_Id);
23190 end if;
23192 Next_Elmt (Item_Elmt);
23193 end loop;
23194 end if;
23195 end Check_Output_States;
23197 ---------------------------
23198 -- Check_Proof_In_States --
23199 ---------------------------
23201 procedure Check_Proof_In_States is
23202 procedure Check_Constituent_Usage (State_Id : Entity_Id);
23203 -- Determine whether at least one constituent of state State_Id with
23204 -- visible refinement is used and has mode Proof_In. Ensure that the
23205 -- remaining constituents do not have Input, In_Out or Output modes.
23207 -----------------------------
23208 -- Check_Constituent_Usage --
23209 -----------------------------
23211 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
23212 Constit_Elmt : Elmt_Id;
23213 Constit_Id : Entity_Id;
23214 Proof_In_Seen : Boolean := False;
23216 begin
23217 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
23218 while Present (Constit_Elmt) loop
23219 Constit_Id := Node (Constit_Elmt);
23221 -- At least one of the constituents appears as Proof_In
23223 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
23224 Proof_In_Seen := True;
23226 -- The constituent appears in the global refinement, but has
23227 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
23229 elsif Present_Then_Remove (In_Constits, Constit_Id)
23230 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
23231 or else Present_Then_Remove (Out_Constits, Constit_Id)
23232 then
23233 Error_Msg_Name_1 := Chars (State_Id);
23234 SPARK_Msg_NE
23235 ("constituent & of state % must have mode Proof_In in "
23236 & "global refinement", N, Constit_Id);
23237 end if;
23239 Next_Elmt (Constit_Elmt);
23240 end loop;
23242 -- Not one of the constituents appeared as Proof_In
23244 if not Proof_In_Seen then
23245 SPARK_Msg_NE
23246 ("global refinement of state & must include at least one "
23247 & "constituent of mode Proof_In", N, State_Id);
23248 end if;
23249 end Check_Constituent_Usage;
23251 -- Local variables
23253 Item_Elmt : Elmt_Id;
23254 Item_Id : Entity_Id;
23256 -- Start of processing for Check_Proof_In_States
23258 begin
23259 -- Do not perform this check in an instance because it was already
23260 -- performed successfully in the generic template.
23262 if Is_Generic_Instance (Spec_Id) then
23263 null;
23265 -- Inspect the Proof_In items of the corresponding Global pragma
23266 -- looking for a state with a visible refinement.
23268 elsif Has_Proof_In_State and then Present (Proof_In_Items) then
23269 Item_Elmt := First_Elmt (Proof_In_Items);
23270 while Present (Item_Elmt) loop
23271 Item_Id := Node (Item_Elmt);
23273 -- Ensure that at least one of the constituents is utilized and
23274 -- is of mode Proof_In
23276 if Ekind (Item_Id) = E_Abstract_State
23277 and then Has_Non_Null_Refinement (Item_Id)
23278 then
23279 Check_Constituent_Usage (Item_Id);
23280 end if;
23282 Next_Elmt (Item_Elmt);
23283 end loop;
23284 end if;
23285 end Check_Proof_In_States;
23287 -------------------------------
23288 -- Check_Refined_Global_List --
23289 -------------------------------
23291 procedure Check_Refined_Global_List
23292 (List : Node_Id;
23293 Global_Mode : Name_Id := Name_Input)
23295 procedure Check_Refined_Global_Item
23296 (Item : Node_Id;
23297 Global_Mode : Name_Id);
23298 -- Verify the legality of a single global item declaration. Parameter
23299 -- Global_Mode denotes the current mode in effect.
23301 -------------------------------
23302 -- Check_Refined_Global_Item --
23303 -------------------------------
23305 procedure Check_Refined_Global_Item
23306 (Item : Node_Id;
23307 Global_Mode : Name_Id)
23309 Item_Id : constant Entity_Id := Entity_Of (Item);
23311 procedure Inconsistent_Mode_Error (Expect : Name_Id);
23312 -- Issue a common error message for all mode mismatches. Expect
23313 -- denotes the expected mode.
23315 -----------------------------
23316 -- Inconsistent_Mode_Error --
23317 -----------------------------
23319 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
23320 begin
23321 SPARK_Msg_NE
23322 ("global item & has inconsistent modes", Item, Item_Id);
23324 Error_Msg_Name_1 := Global_Mode;
23325 Error_Msg_Name_2 := Expect;
23326 SPARK_Msg_N ("\expected mode %, found mode %", Item);
23327 end Inconsistent_Mode_Error;
23329 -- Start of processing for Check_Refined_Global_Item
23331 begin
23332 -- When the state or object acts as a constituent of another
23333 -- state with a visible refinement, collect it for the state
23334 -- completeness checks performed later on.
23336 if Ekind_In (Item_Id, E_Abstract_State, E_Constant, E_Variable)
23337 and then Present (Encapsulating_State (Item_Id))
23338 and then Has_Visible_Refinement (Encapsulating_State (Item_Id))
23339 then
23340 if Global_Mode = Name_Input then
23341 Add_Item (Item_Id, In_Constits);
23343 elsif Global_Mode = Name_In_Out then
23344 Add_Item (Item_Id, In_Out_Constits);
23346 elsif Global_Mode = Name_Output then
23347 Add_Item (Item_Id, Out_Constits);
23349 elsif Global_Mode = Name_Proof_In then
23350 Add_Item (Item_Id, Proof_In_Constits);
23351 end if;
23353 -- When not a constituent, ensure that both occurrences of the
23354 -- item in pragmas Global and Refined_Global match.
23356 elsif Contains (In_Items, Item_Id) then
23357 if Global_Mode /= Name_Input then
23358 Inconsistent_Mode_Error (Name_Input);
23359 end if;
23361 elsif Contains (In_Out_Items, Item_Id) then
23362 if Global_Mode /= Name_In_Out then
23363 Inconsistent_Mode_Error (Name_In_Out);
23364 end if;
23366 elsif Contains (Out_Items, Item_Id) then
23367 if Global_Mode /= Name_Output then
23368 Inconsistent_Mode_Error (Name_Output);
23369 end if;
23371 elsif Contains (Proof_In_Items, Item_Id) then
23372 null;
23374 -- The item does not appear in the corresponding Global pragma,
23375 -- it must be an extra (SPARK RM 7.2.4(3)).
23377 else
23378 SPARK_Msg_NE ("extra global item &", Item, Item_Id);
23379 end if;
23380 end Check_Refined_Global_Item;
23382 -- Local variables
23384 Item : Node_Id;
23386 -- Start of processing for Check_Refined_Global_List
23388 begin
23389 -- Do not perform this check in an instance because it was already
23390 -- performed successfully in the generic template.
23392 if Is_Generic_Instance (Spec_Id) then
23393 null;
23395 elsif Nkind (List) = N_Null then
23396 null;
23398 -- Single global item declaration
23400 elsif Nkind_In (List, N_Expanded_Name,
23401 N_Identifier,
23402 N_Selected_Component)
23403 then
23404 Check_Refined_Global_Item (List, Global_Mode);
23406 -- Simple global list or moded global list declaration
23408 elsif Nkind (List) = N_Aggregate then
23410 -- The declaration of a simple global list appear as a collection
23411 -- of expressions.
23413 if Present (Expressions (List)) then
23414 Item := First (Expressions (List));
23415 while Present (Item) loop
23416 Check_Refined_Global_Item (Item, Global_Mode);
23417 Next (Item);
23418 end loop;
23420 -- The declaration of a moded global list appears as a collection
23421 -- of component associations where individual choices denote
23422 -- modes.
23424 elsif Present (Component_Associations (List)) then
23425 Item := First (Component_Associations (List));
23426 while Present (Item) loop
23427 Check_Refined_Global_List
23428 (List => Expression (Item),
23429 Global_Mode => Chars (First (Choices (Item))));
23431 Next (Item);
23432 end loop;
23434 -- Invalid tree
23436 else
23437 raise Program_Error;
23438 end if;
23440 -- Invalid list
23442 else
23443 raise Program_Error;
23444 end if;
23445 end Check_Refined_Global_List;
23447 --------------------------
23448 -- Collect_Global_Items --
23449 --------------------------
23451 procedure Collect_Global_Items
23452 (List : Node_Id;
23453 Mode : Name_Id := Name_Input)
23455 procedure Collect_Global_Item
23456 (Item : Node_Id;
23457 Item_Mode : Name_Id);
23458 -- Add a single item to the appropriate list. Item_Mode denotes the
23459 -- current mode in effect.
23461 -------------------------
23462 -- Collect_Global_Item --
23463 -------------------------
23465 procedure Collect_Global_Item
23466 (Item : Node_Id;
23467 Item_Mode : Name_Id)
23469 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
23470 -- The above handles abstract views of variables and states built
23471 -- for limited with clauses.
23473 begin
23474 -- Signal that the global list contains at least one abstract
23475 -- state with a visible refinement. Note that the refinement may
23476 -- be null in which case there are no constituents.
23478 if Ekind (Item_Id) = E_Abstract_State then
23479 if Has_Null_Refinement (Item_Id) then
23480 Has_Null_State := True;
23482 elsif Has_Non_Null_Refinement (Item_Id) then
23483 if Item_Mode = Name_Input then
23484 Has_In_State := True;
23485 elsif Item_Mode = Name_In_Out then
23486 Has_In_Out_State := True;
23487 elsif Item_Mode = Name_Output then
23488 Has_Out_State := True;
23489 elsif Item_Mode = Name_Proof_In then
23490 Has_Proof_In_State := True;
23491 end if;
23492 end if;
23493 end if;
23495 -- Add the item to the proper list
23497 if Item_Mode = Name_Input then
23498 Add_Item (Item_Id, In_Items);
23499 elsif Item_Mode = Name_In_Out then
23500 Add_Item (Item_Id, In_Out_Items);
23501 elsif Item_Mode = Name_Output then
23502 Add_Item (Item_Id, Out_Items);
23503 elsif Item_Mode = Name_Proof_In then
23504 Add_Item (Item_Id, Proof_In_Items);
23505 end if;
23506 end Collect_Global_Item;
23508 -- Local variables
23510 Item : Node_Id;
23512 -- Start of processing for Collect_Global_Items
23514 begin
23515 if Nkind (List) = N_Null then
23516 null;
23518 -- Single global item declaration
23520 elsif Nkind_In (List, N_Expanded_Name,
23521 N_Identifier,
23522 N_Selected_Component)
23523 then
23524 Collect_Global_Item (List, Mode);
23526 -- Single global list or moded global list declaration
23528 elsif Nkind (List) = N_Aggregate then
23530 -- The declaration of a simple global list appear as a collection
23531 -- of expressions.
23533 if Present (Expressions (List)) then
23534 Item := First (Expressions (List));
23535 while Present (Item) loop
23536 Collect_Global_Item (Item, Mode);
23537 Next (Item);
23538 end loop;
23540 -- The declaration of a moded global list appears as a collection
23541 -- of component associations where individual choices denote mode.
23543 elsif Present (Component_Associations (List)) then
23544 Item := First (Component_Associations (List));
23545 while Present (Item) loop
23546 Collect_Global_Items
23547 (List => Expression (Item),
23548 Mode => Chars (First (Choices (Item))));
23550 Next (Item);
23551 end loop;
23553 -- Invalid tree
23555 else
23556 raise Program_Error;
23557 end if;
23559 -- To accomodate partial decoration of disabled SPARK features, this
23560 -- routine may be called with illegal input. If this is the case, do
23561 -- not raise Program_Error.
23563 else
23564 null;
23565 end if;
23566 end Collect_Global_Items;
23568 -------------------------
23569 -- Present_Then_Remove --
23570 -------------------------
23572 function Present_Then_Remove
23573 (List : Elist_Id;
23574 Item : Entity_Id) return Boolean
23576 Elmt : Elmt_Id;
23578 begin
23579 if Present (List) then
23580 Elmt := First_Elmt (List);
23581 while Present (Elmt) loop
23582 if Node (Elmt) = Item then
23583 Remove_Elmt (List, Elmt);
23584 return True;
23585 end if;
23587 Next_Elmt (Elmt);
23588 end loop;
23589 end if;
23591 return False;
23592 end Present_Then_Remove;
23594 -------------------------------
23595 -- Report_Extra_Constituents --
23596 -------------------------------
23598 procedure Report_Extra_Constituents is
23599 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
23600 -- Emit an error for every element of List
23602 ---------------------------------------
23603 -- Report_Extra_Constituents_In_List --
23604 ---------------------------------------
23606 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
23607 Constit_Elmt : Elmt_Id;
23609 begin
23610 if Present (List) then
23611 Constit_Elmt := First_Elmt (List);
23612 while Present (Constit_Elmt) loop
23613 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
23614 Next_Elmt (Constit_Elmt);
23615 end loop;
23616 end if;
23617 end Report_Extra_Constituents_In_List;
23619 -- Start of processing for Report_Extra_Constituents
23621 begin
23622 -- Do not perform this check in an instance because it was already
23623 -- performed successfully in the generic template.
23625 if Is_Generic_Instance (Spec_Id) then
23626 null;
23628 else
23629 Report_Extra_Constituents_In_List (In_Constits);
23630 Report_Extra_Constituents_In_List (In_Out_Constits);
23631 Report_Extra_Constituents_In_List (Out_Constits);
23632 Report_Extra_Constituents_In_List (Proof_In_Constits);
23633 end if;
23634 end Report_Extra_Constituents;
23636 -- Local variables
23638 Body_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
23639 Errors : constant Nat := Serious_Errors_Detected;
23640 Items : Node_Id;
23642 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
23644 begin
23645 if Nkind (Body_Decl) = N_Subprogram_Body_Stub then
23646 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
23647 else
23648 Spec_Id := Corresponding_Spec (Body_Decl);
23649 end if;
23651 Global := Get_Pragma (Spec_Id, Pragma_Global);
23652 Items := Expression (Get_Argument (N, Spec_Id));
23654 -- The subprogram declaration lacks pragma Global. This renders
23655 -- Refined_Global useless as there is nothing to refine.
23657 if No (Global) then
23658 SPARK_Msg_NE
23659 ("useless refinement, declaration of subprogram & lacks aspect or "
23660 & "pragma Global", N, Spec_Id);
23661 return;
23662 end if;
23664 -- Extract all relevant items from the corresponding Global pragma
23666 Collect_Global_Items (Expression (Get_Argument (Global, Spec_Id)));
23668 -- Package and subprogram bodies are instantiated individually in
23669 -- a separate compiler pass. Due to this mode of instantiation, the
23670 -- refinement of a state may no longer be visible when a subprogram
23671 -- body contract is instantiated. Since the generic template is legal,
23672 -- do not perform this check in the instance to circumvent this oddity.
23674 if Is_Generic_Instance (Spec_Id) then
23675 null;
23677 -- Non-instance case
23679 else
23680 -- The corresponding Global pragma must mention at least one state
23681 -- witha visible refinement at the point Refined_Global is processed.
23682 -- States with null refinements need Refined_Global pragma
23683 -- (SPARK RM 7.2.4(2)).
23685 if not Has_In_State
23686 and then not Has_In_Out_State
23687 and then not Has_Out_State
23688 and then not Has_Proof_In_State
23689 and then not Has_Null_State
23690 then
23691 SPARK_Msg_NE
23692 ("useless refinement, subprogram & does not depend on abstract "
23693 & "state with visible refinement", N, Spec_Id);
23694 return;
23696 -- The global refinement of inputs and outputs cannot be null when
23697 -- the corresponding Global pragma contains at least one item except
23698 -- in the case where we have states with null refinements.
23700 elsif Nkind (Items) = N_Null
23701 and then
23702 (Present (In_Items)
23703 or else Present (In_Out_Items)
23704 or else Present (Out_Items)
23705 or else Present (Proof_In_Items))
23706 and then not Has_Null_State
23707 then
23708 SPARK_Msg_NE
23709 ("refinement cannot be null, subprogram & has global items",
23710 N, Spec_Id);
23711 return;
23712 end if;
23713 end if;
23715 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
23716 -- This ensures that the categorization of all refined global items is
23717 -- consistent with their role.
23719 Analyze_Global_In_Decl_Part (N);
23721 -- Perform all refinement checks with respect to completeness and mode
23722 -- matching.
23724 if Serious_Errors_Detected = Errors then
23725 Check_Refined_Global_List (Items);
23726 end if;
23728 -- For Input states with visible refinement, at least one constituent
23729 -- must be used as an Input in the global refinement.
23731 if Serious_Errors_Detected = Errors then
23732 Check_Input_States;
23733 end if;
23735 -- Verify all possible completion variants for In_Out states with
23736 -- visible refinement.
23738 if Serious_Errors_Detected = Errors then
23739 Check_In_Out_States;
23740 end if;
23742 -- For Output states with visible refinement, all constituents must be
23743 -- used as Outputs in the global refinement.
23745 if Serious_Errors_Detected = Errors then
23746 Check_Output_States;
23747 end if;
23749 -- For Proof_In states with visible refinement, at least one constituent
23750 -- must be used as Proof_In in the global refinement.
23752 if Serious_Errors_Detected = Errors then
23753 Check_Proof_In_States;
23754 end if;
23756 -- Emit errors for all constituents that belong to other states with
23757 -- visible refinement that do not appear in Global.
23759 if Serious_Errors_Detected = Errors then
23760 Report_Extra_Constituents;
23761 end if;
23762 end Analyze_Refined_Global_In_Decl_Part;
23764 ----------------------------------------
23765 -- Analyze_Refined_State_In_Decl_Part --
23766 ----------------------------------------
23768 procedure Analyze_Refined_State_In_Decl_Part (N : Node_Id) is
23769 Body_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
23770 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
23771 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
23773 Available_States : Elist_Id := No_Elist;
23774 -- A list of all abstract states defined in the package declaration that
23775 -- are available for refinement. The list is used to report unrefined
23776 -- states.
23778 Body_States : Elist_Id := No_Elist;
23779 -- A list of all hidden states that appear in the body of the related
23780 -- package. The list is used to report unused hidden states.
23782 Constituents_Seen : Elist_Id := No_Elist;
23783 -- A list that contains all constituents processed so far. The list is
23784 -- used to detect multiple uses of the same constituent.
23786 Refined_States_Seen : Elist_Id := No_Elist;
23787 -- A list that contains all refined states processed so far. The list is
23788 -- used to detect duplicate refinements.
23790 procedure Analyze_Refinement_Clause (Clause : Node_Id);
23791 -- Perform full analysis of a single refinement clause
23793 function Collect_Body_States (Pack_Id : Entity_Id) return Elist_Id;
23794 -- Gather the entities of all abstract states and objects declared in
23795 -- the body state space of package Pack_Id.
23797 procedure Report_Unrefined_States (States : Elist_Id);
23798 -- Emit errors for all unrefined abstract states found in list States
23800 procedure Report_Unused_States (States : Elist_Id);
23801 -- Emit errors for all unused states found in list States
23803 -------------------------------
23804 -- Analyze_Refinement_Clause --
23805 -------------------------------
23807 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
23808 AR_Constit : Entity_Id := Empty;
23809 AW_Constit : Entity_Id := Empty;
23810 ER_Constit : Entity_Id := Empty;
23811 EW_Constit : Entity_Id := Empty;
23812 -- The entities of external constituents that contain one of the
23813 -- following enabled properties: Async_Readers, Async_Writers,
23814 -- Effective_Reads and Effective_Writes.
23816 External_Constit_Seen : Boolean := False;
23817 -- Flag used to mark when at least one external constituent is part
23818 -- of the state refinement.
23820 Non_Null_Seen : Boolean := False;
23821 Null_Seen : Boolean := False;
23822 -- Flags used to detect multiple uses of null in a single clause or a
23823 -- mixture of null and non-null constituents.
23825 Part_Of_Constits : Elist_Id := No_Elist;
23826 -- A list of all candidate constituents subject to indicator Part_Of
23827 -- where the encapsulating state is the current state.
23829 State : Node_Id;
23830 State_Id : Entity_Id;
23831 -- The current state being refined
23833 procedure Analyze_Constituent (Constit : Node_Id);
23834 -- Perform full analysis of a single constituent
23836 procedure Check_External_Property
23837 (Prop_Nam : Name_Id;
23838 Enabled : Boolean;
23839 Constit : Entity_Id);
23840 -- Determine whether a property denoted by name Prop_Nam is present
23841 -- in both the refined state and constituent Constit. Flag Enabled
23842 -- should be set when the property applies to the refined state. If
23843 -- this is not the case, emit an error message.
23845 procedure Check_Matching_State;
23846 -- Determine whether the state being refined appears in list
23847 -- Available_States. Emit an error when attempting to re-refine the
23848 -- state or when the state is not defined in the package declaration,
23849 -- otherwise remove the state from Available_States.
23851 procedure Report_Unused_Constituents (Constits : Elist_Id);
23852 -- Emit errors for all unused Part_Of constituents in list Constits
23854 -------------------------
23855 -- Analyze_Constituent --
23856 -------------------------
23858 procedure Analyze_Constituent (Constit : Node_Id) is
23859 procedure Check_Ghost_Constituent (Constit_Id : Entity_Id);
23860 -- Verify that the constituent Constit_Id is a Ghost entity if the
23861 -- abstract state being refined is also Ghost. If this is the case
23862 -- verify that the Ghost policy in effect at the point of state
23863 -- and constituent declaration is the same.
23865 procedure Check_Matching_Constituent (Constit_Id : Entity_Id);
23866 -- Determine whether constituent Constit denoted by its entity
23867 -- Constit_Id appears in Hidden_States. Emit an error when the
23868 -- constituent is not a valid hidden state of the related package
23869 -- or when it is used more than once. Otherwise remove the
23870 -- constituent from Hidden_States.
23872 --------------------------------
23873 -- Check_Matching_Constituent --
23874 --------------------------------
23876 procedure Check_Matching_Constituent (Constit_Id : Entity_Id) is
23877 procedure Collect_Constituent;
23878 -- Add constituent Constit_Id to the refinements of State_Id
23880 -------------------------
23881 -- Collect_Constituent --
23882 -------------------------
23884 procedure Collect_Constituent is
23885 begin
23886 -- Add the constituent to the list of processed items to aid
23887 -- with the detection of duplicates.
23889 Add_Item (Constit_Id, Constituents_Seen);
23891 -- Collect the constituent in the list of refinement items
23892 -- and establish a relation between the refined state and
23893 -- the item.
23895 Append_Elmt (Constit_Id, Refinement_Constituents (State_Id));
23896 Set_Encapsulating_State (Constit_Id, State_Id);
23898 -- The state has at least one legal constituent, mark the
23899 -- start of the refinement region. The region ends when the
23900 -- body declarations end (see routine Analyze_Declarations).
23902 Set_Has_Visible_Refinement (State_Id);
23904 -- When the constituent is external, save its relevant
23905 -- property for further checks.
23907 if Async_Readers_Enabled (Constit_Id) then
23908 AR_Constit := Constit_Id;
23909 External_Constit_Seen := True;
23910 end if;
23912 if Async_Writers_Enabled (Constit_Id) then
23913 AW_Constit := Constit_Id;
23914 External_Constit_Seen := True;
23915 end if;
23917 if Effective_Reads_Enabled (Constit_Id) then
23918 ER_Constit := Constit_Id;
23919 External_Constit_Seen := True;
23920 end if;
23922 if Effective_Writes_Enabled (Constit_Id) then
23923 EW_Constit := Constit_Id;
23924 External_Constit_Seen := True;
23925 end if;
23926 end Collect_Constituent;
23928 -- Local variables
23930 State_Elmt : Elmt_Id;
23932 -- Start of processing for Check_Matching_Constituent
23934 begin
23935 -- Detect a duplicate use of a constituent
23937 if Contains (Constituents_Seen, Constit_Id) then
23938 SPARK_Msg_NE
23939 ("duplicate use of constituent &", Constit, Constit_Id);
23940 return;
23941 end if;
23943 -- The constituent is subject to a Part_Of indicator
23945 if Present (Encapsulating_State (Constit_Id)) then
23946 if Encapsulating_State (Constit_Id) = State_Id then
23947 Check_Ghost_Constituent (Constit_Id);
23948 Remove (Part_Of_Constits, Constit_Id);
23949 Collect_Constituent;
23951 -- The constituent is part of another state and is used
23952 -- incorrectly in the refinement of the current state.
23954 else
23955 Error_Msg_Name_1 := Chars (State_Id);
23956 SPARK_Msg_NE
23957 ("& cannot act as constituent of state %",
23958 Constit, Constit_Id);
23959 SPARK_Msg_NE
23960 ("\Part_Of indicator specifies & as encapsulating "
23961 & "state", Constit, Encapsulating_State (Constit_Id));
23962 end if;
23964 -- The only other source of legal constituents is the body
23965 -- state space of the related package.
23967 else
23968 if Present (Body_States) then
23969 State_Elmt := First_Elmt (Body_States);
23970 while Present (State_Elmt) loop
23972 -- Consume a valid constituent to signal that it has
23973 -- been encountered.
23975 if Node (State_Elmt) = Constit_Id then
23976 Check_Ghost_Constituent (Constit_Id);
23977 Remove_Elmt (Body_States, State_Elmt);
23978 Collect_Constituent;
23979 return;
23980 end if;
23982 Next_Elmt (State_Elmt);
23983 end loop;
23984 end if;
23986 -- If we get here, then the constituent is not a hidden
23987 -- state of the related package and may not be used in a
23988 -- refinement (SPARK RM 7.2.2(9)).
23990 Error_Msg_Name_1 := Chars (Spec_Id);
23991 SPARK_Msg_NE
23992 ("cannot use & in refinement, constituent is not a hidden "
23993 & "state of package %", Constit, Constit_Id);
23994 end if;
23995 end Check_Matching_Constituent;
23997 -----------------------------
23998 -- Check_Ghost_Constituent --
23999 -----------------------------
24001 procedure Check_Ghost_Constituent (Constit_Id : Entity_Id) is
24002 begin
24003 if Is_Ghost_Entity (State_Id) then
24004 if Is_Ghost_Entity (Constit_Id) then
24006 -- The Ghost policy in effect at the point of abstract
24007 -- state declaration and constituent must match
24008 -- (SPARK RM 6.9(16)).
24010 if Is_Checked_Ghost_Entity (State_Id)
24011 and then Is_Ignored_Ghost_Entity (Constit_Id)
24012 then
24013 Error_Msg_Sloc := Sloc (Constit);
24015 SPARK_Msg_N
24016 ("incompatible ghost policies in effect", State);
24017 SPARK_Msg_NE
24018 ("\abstract state & declared with ghost policy "
24019 & "Check", State, State_Id);
24020 SPARK_Msg_NE
24021 ("\constituent & declared # with ghost policy "
24022 & "Ignore", State, Constit_Id);
24024 elsif Is_Ignored_Ghost_Entity (State_Id)
24025 and then Is_Checked_Ghost_Entity (Constit_Id)
24026 then
24027 Error_Msg_Sloc := Sloc (Constit);
24029 SPARK_Msg_N
24030 ("incompatible ghost policies in effect", State);
24031 SPARK_Msg_NE
24032 ("\abstract state & declared with ghost policy "
24033 & "Ignore", State, State_Id);
24034 SPARK_Msg_NE
24035 ("\constituent & declared # with ghost policy "
24036 & "Check", State, Constit_Id);
24037 end if;
24039 -- A constituent of a Ghost abstract state must be a Ghost
24040 -- entity (SPARK RM 7.2.2(12)).
24042 else
24043 SPARK_Msg_NE
24044 ("constituent of ghost state & must be ghost",
24045 Constit, State_Id);
24046 end if;
24047 end if;
24048 end Check_Ghost_Constituent;
24050 -- Local variables
24052 Constit_Id : Entity_Id;
24054 -- Start of processing for Analyze_Constituent
24056 begin
24057 -- Detect multiple uses of null in a single refinement clause or a
24058 -- mixture of null and non-null constituents.
24060 if Nkind (Constit) = N_Null then
24061 if Null_Seen then
24062 SPARK_Msg_N
24063 ("multiple null constituents not allowed", Constit);
24065 elsif Non_Null_Seen then
24066 SPARK_Msg_N
24067 ("cannot mix null and non-null constituents", Constit);
24069 else
24070 Null_Seen := True;
24072 -- Collect the constituent in the list of refinement items
24074 Append_Elmt (Constit, Refinement_Constituents (State_Id));
24076 -- The state has at least one legal constituent, mark the
24077 -- start of the refinement region. The region ends when the
24078 -- body declarations end (see Analyze_Declarations).
24080 Set_Has_Visible_Refinement (State_Id);
24081 end if;
24083 -- Non-null constituents
24085 else
24086 Non_Null_Seen := True;
24088 if Null_Seen then
24089 SPARK_Msg_N
24090 ("cannot mix null and non-null constituents", Constit);
24091 end if;
24093 Analyze (Constit);
24094 Resolve_State (Constit);
24096 -- Ensure that the constituent denotes a valid state or a
24097 -- whole object (SPARK RM 7.2.2(5)).
24099 if Is_Entity_Name (Constit) then
24100 Constit_Id := Entity_Of (Constit);
24102 if Ekind_In (Constit_Id, E_Abstract_State,
24103 E_Constant,
24104 E_Variable)
24105 then
24106 Check_Matching_Constituent (Constit_Id);
24108 else
24109 SPARK_Msg_NE
24110 ("constituent & must denote object or state",
24111 Constit, Constit_Id);
24112 end if;
24114 -- The constituent is illegal
24116 else
24117 SPARK_Msg_N ("malformed constituent", Constit);
24118 end if;
24119 end if;
24120 end Analyze_Constituent;
24122 -----------------------------
24123 -- Check_External_Property --
24124 -----------------------------
24126 procedure Check_External_Property
24127 (Prop_Nam : Name_Id;
24128 Enabled : Boolean;
24129 Constit : Entity_Id)
24131 begin
24132 Error_Msg_Name_1 := Prop_Nam;
24134 -- The property is enabled in the related Abstract_State pragma
24135 -- that defines the state (SPARK RM 7.2.8(3)).
24137 if Enabled then
24138 if No (Constit) then
24139 SPARK_Msg_NE
24140 ("external state & requires at least one constituent with "
24141 & "property %", State, State_Id);
24142 end if;
24144 -- The property is missing in the declaration of the state, but
24145 -- a constituent is introducing it in the state refinement
24146 -- (SPARK RM 7.2.8(3)).
24148 elsif Present (Constit) then
24149 Error_Msg_Name_2 := Chars (Constit);
24150 SPARK_Msg_NE
24151 ("external state & lacks property % set by constituent %",
24152 State, State_Id);
24153 end if;
24154 end Check_External_Property;
24156 --------------------------
24157 -- Check_Matching_State --
24158 --------------------------
24160 procedure Check_Matching_State is
24161 State_Elmt : Elmt_Id;
24163 begin
24164 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
24166 if Contains (Refined_States_Seen, State_Id) then
24167 SPARK_Msg_NE
24168 ("duplicate refinement of state &", State, State_Id);
24169 return;
24170 end if;
24172 -- Inspect the abstract states defined in the package declaration
24173 -- looking for a match.
24175 State_Elmt := First_Elmt (Available_States);
24176 while Present (State_Elmt) loop
24178 -- A valid abstract state is being refined in the body. Add
24179 -- the state to the list of processed refined states to aid
24180 -- with the detection of duplicate refinements. Remove the
24181 -- state from Available_States to signal that it has already
24182 -- been refined.
24184 if Node (State_Elmt) = State_Id then
24185 Add_Item (State_Id, Refined_States_Seen);
24186 Remove_Elmt (Available_States, State_Elmt);
24187 return;
24188 end if;
24190 Next_Elmt (State_Elmt);
24191 end loop;
24193 -- If we get here, we are refining a state that is not defined in
24194 -- the package declaration.
24196 Error_Msg_Name_1 := Chars (Spec_Id);
24197 SPARK_Msg_NE
24198 ("cannot refine state, & is not defined in package %",
24199 State, State_Id);
24200 end Check_Matching_State;
24202 --------------------------------
24203 -- Report_Unused_Constituents --
24204 --------------------------------
24206 procedure Report_Unused_Constituents (Constits : Elist_Id) is
24207 Constit_Elmt : Elmt_Id;
24208 Constit_Id : Entity_Id;
24209 Posted : Boolean := False;
24211 begin
24212 if Present (Constits) then
24213 Constit_Elmt := First_Elmt (Constits);
24214 while Present (Constit_Elmt) loop
24215 Constit_Id := Node (Constit_Elmt);
24217 -- Generate an error message of the form:
24219 -- state ... has unused Part_Of constituents
24220 -- abstract state ... defined at ...
24221 -- constant ... defined at ...
24222 -- variable ... defined at ...
24224 if not Posted then
24225 Posted := True;
24226 SPARK_Msg_NE
24227 ("state & has unused Part_Of constituents",
24228 State, State_Id);
24229 end if;
24231 Error_Msg_Sloc := Sloc (Constit_Id);
24233 if Ekind (Constit_Id) = E_Abstract_State then
24234 SPARK_Msg_NE
24235 ("\abstract state & defined #", State, Constit_Id);
24237 elsif Ekind (Constit_Id) = E_Constant then
24238 SPARK_Msg_NE
24239 ("\constant & defined #", State, Constit_Id);
24241 else
24242 pragma Assert (Ekind (Constit_Id) = E_Variable);
24243 SPARK_Msg_NE ("\variable & defined #", State, Constit_Id);
24244 end if;
24246 Next_Elmt (Constit_Elmt);
24247 end loop;
24248 end if;
24249 end Report_Unused_Constituents;
24251 -- Local declarations
24253 Body_Ref : Node_Id;
24254 Body_Ref_Elmt : Elmt_Id;
24255 Constit : Node_Id;
24256 Extra_State : Node_Id;
24258 -- Start of processing for Analyze_Refinement_Clause
24260 begin
24261 -- A refinement clause appears as a component association where the
24262 -- sole choice is the state and the expressions are the constituents.
24263 -- This is a syntax error, always report.
24265 if Nkind (Clause) /= N_Component_Association then
24266 Error_Msg_N ("malformed state refinement clause", Clause);
24267 return;
24268 end if;
24270 -- Analyze the state name of a refinement clause
24272 State := First (Choices (Clause));
24274 Analyze (State);
24275 Resolve_State (State);
24277 -- Ensure that the state name denotes a valid abstract state that is
24278 -- defined in the spec of the related package.
24280 if Is_Entity_Name (State) then
24281 State_Id := Entity_Of (State);
24283 -- Catch any attempts to re-refine a state or refine a state that
24284 -- is not defined in the package declaration.
24286 if Ekind (State_Id) = E_Abstract_State then
24287 Check_Matching_State;
24288 else
24289 SPARK_Msg_NE
24290 ("& must denote an abstract state", State, State_Id);
24291 return;
24292 end if;
24294 -- References to a state with visible refinement are illegal.
24295 -- When nested packages are involved, detecting such references is
24296 -- tricky because pragma Refined_State is analyzed later than the
24297 -- offending pragma Depends or Global. References that occur in
24298 -- such nested context are stored in a list. Emit errors for all
24299 -- references found in Body_References (SPARK RM 6.1.4(8)).
24301 if Present (Body_References (State_Id)) then
24302 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
24303 while Present (Body_Ref_Elmt) loop
24304 Body_Ref := Node (Body_Ref_Elmt);
24306 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
24307 Error_Msg_Sloc := Sloc (State);
24308 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
24310 Next_Elmt (Body_Ref_Elmt);
24311 end loop;
24312 end if;
24314 -- The state name is illegal. This is a syntax error, always report.
24316 else
24317 Error_Msg_N ("malformed state name in refinement clause", State);
24318 return;
24319 end if;
24321 -- A refinement clause may only refine one state at a time
24323 Extra_State := Next (State);
24325 if Present (Extra_State) then
24326 SPARK_Msg_N
24327 ("refinement clause cannot cover multiple states", Extra_State);
24328 end if;
24330 -- Replicate the Part_Of constituents of the refined state because
24331 -- the algorithm will consume items.
24333 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
24335 -- Analyze all constituents of the refinement. Multiple constituents
24336 -- appear as an aggregate.
24338 Constit := Expression (Clause);
24340 if Nkind (Constit) = N_Aggregate then
24341 if Present (Component_Associations (Constit)) then
24342 SPARK_Msg_N
24343 ("constituents of refinement clause must appear in "
24344 & "positional form", Constit);
24346 else pragma Assert (Present (Expressions (Constit)));
24347 Constit := First (Expressions (Constit));
24348 while Present (Constit) loop
24349 Analyze_Constituent (Constit);
24350 Next (Constit);
24351 end loop;
24352 end if;
24354 -- Various forms of a single constituent. Note that these may include
24355 -- malformed constituents.
24357 else
24358 Analyze_Constituent (Constit);
24359 end if;
24361 -- A refined external state is subject to special rules with respect
24362 -- to its properties and constituents.
24364 if Is_External_State (State_Id) then
24366 -- The set of properties that all external constituents yield must
24367 -- match that of the refined state. There are two cases to detect:
24368 -- the refined state lacks a property or has an extra property.
24370 if External_Constit_Seen then
24371 Check_External_Property
24372 (Prop_Nam => Name_Async_Readers,
24373 Enabled => Async_Readers_Enabled (State_Id),
24374 Constit => AR_Constit);
24376 Check_External_Property
24377 (Prop_Nam => Name_Async_Writers,
24378 Enabled => Async_Writers_Enabled (State_Id),
24379 Constit => AW_Constit);
24381 Check_External_Property
24382 (Prop_Nam => Name_Effective_Reads,
24383 Enabled => Effective_Reads_Enabled (State_Id),
24384 Constit => ER_Constit);
24386 Check_External_Property
24387 (Prop_Nam => Name_Effective_Writes,
24388 Enabled => Effective_Writes_Enabled (State_Id),
24389 Constit => EW_Constit);
24391 -- An external state may be refined to null (SPARK RM 7.2.8(2))
24393 elsif Null_Seen then
24394 null;
24396 -- The external state has constituents, but none of them are
24397 -- external (SPARK RM 7.2.8(2)).
24399 else
24400 SPARK_Msg_NE
24401 ("external state & requires at least one external "
24402 & "constituent or null refinement", State, State_Id);
24403 end if;
24405 -- When a refined state is not external, it should not have external
24406 -- constituents (SPARK RM 7.2.8(1)).
24408 elsif External_Constit_Seen then
24409 SPARK_Msg_NE
24410 ("non-external state & cannot contain external constituents in "
24411 & "refinement", State, State_Id);
24412 end if;
24414 -- Ensure that all Part_Of candidate constituents have been mentioned
24415 -- in the refinement clause.
24417 Report_Unused_Constituents (Part_Of_Constits);
24418 end Analyze_Refinement_Clause;
24420 -------------------------
24421 -- Collect_Body_States --
24422 -------------------------
24424 function Collect_Body_States (Pack_Id : Entity_Id) return Elist_Id is
24425 Result : Elist_Id := No_Elist;
24426 -- A list containing all body states of Pack_Id
24428 procedure Collect_Visible_States (Pack_Id : Entity_Id);
24429 -- Gather the entities of all abstract states and objects declared in
24430 -- the visible state space of package Pack_Id.
24432 ----------------------------
24433 -- Collect_Visible_States --
24434 ----------------------------
24436 procedure Collect_Visible_States (Pack_Id : Entity_Id) is
24437 Decl : Node_Id;
24438 Item_Id : Entity_Id;
24440 begin
24441 -- Traverse the entity chain of the package and inspect all
24442 -- visible items.
24444 Item_Id := First_Entity (Pack_Id);
24445 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
24447 -- Do not consider internally generated items as those cannot
24448 -- be named and participate in refinement.
24450 if not Comes_From_Source (Item_Id) then
24451 null;
24453 elsif Ekind (Item_Id) = E_Abstract_State then
24454 Add_Item (Item_Id, Result);
24456 elsif Ekind_In (Item_Id, E_Constant, E_Variable) then
24457 Decl := Declaration_Node (Item_Id);
24459 -- Do not consider constants or variables that map generic
24460 -- formals to their actuals as the formals cannot be named
24461 -- from the outside and participate in refinement.
24463 if Present (Corresponding_Generic_Association (Decl)) then
24464 null;
24466 -- Constants without "variable input" are not considered a
24467 -- hidden state of a package (SPARK RM 7.1.1(2)).
24469 elsif Ekind (Item_Id) = E_Constant
24470 and then not Has_Variable_Input (Item_Id)
24471 then
24472 null;
24474 else
24475 Add_Item (Item_Id, Result);
24476 end if;
24478 -- Recursively gather the visible states of a nested package
24480 elsif Ekind (Item_Id) = E_Package then
24481 Collect_Visible_States (Item_Id);
24482 end if;
24484 Next_Entity (Item_Id);
24485 end loop;
24486 end Collect_Visible_States;
24488 -- Local variables
24490 Pack_Body : constant Node_Id :=
24491 Declaration_Node (Body_Entity (Pack_Id));
24492 Decl : Node_Id;
24493 Item_Id : Entity_Id;
24495 -- Start of processing for Collect_Body_States
24497 begin
24498 -- Inspect the declarations of the body looking for source objects,
24499 -- packages and package instantiations.
24501 Decl := First (Declarations (Pack_Body));
24502 while Present (Decl) loop
24504 -- Capture source objects as internally generated temporaries
24505 -- cannot be named and participate in refinement.
24507 if Nkind (Decl) = N_Object_Declaration then
24508 Item_Id := Defining_Entity (Decl);
24510 if Comes_From_Source (Item_Id) then
24511 Add_Item (Item_Id, Result);
24512 end if;
24514 -- Capture the visible abstract states and objects of a source
24515 -- package [instantiation].
24517 elsif Nkind (Decl) = N_Package_Declaration then
24518 Item_Id := Defining_Entity (Decl);
24520 if Comes_From_Source (Item_Id) then
24521 Collect_Visible_States (Item_Id);
24522 end if;
24523 end if;
24525 Next (Decl);
24526 end loop;
24528 return Result;
24529 end Collect_Body_States;
24531 -----------------------------
24532 -- Report_Unrefined_States --
24533 -----------------------------
24535 procedure Report_Unrefined_States (States : Elist_Id) is
24536 State_Elmt : Elmt_Id;
24538 begin
24539 if Present (States) then
24540 State_Elmt := First_Elmt (States);
24541 while Present (State_Elmt) loop
24542 SPARK_Msg_N
24543 ("abstract state & must be refined", Node (State_Elmt));
24545 Next_Elmt (State_Elmt);
24546 end loop;
24547 end if;
24548 end Report_Unrefined_States;
24550 --------------------------
24551 -- Report_Unused_States --
24552 --------------------------
24554 procedure Report_Unused_States (States : Elist_Id) is
24555 Posted : Boolean := False;
24556 State_Elmt : Elmt_Id;
24557 State_Id : Entity_Id;
24559 begin
24560 if Present (States) then
24561 State_Elmt := First_Elmt (States);
24562 while Present (State_Elmt) loop
24563 State_Id := Node (State_Elmt);
24565 -- Generate an error message of the form:
24567 -- body of package ... has unused hidden states
24568 -- abstract state ... defined at ...
24569 -- constant ... defined at ...
24570 -- variable ... defined at ...
24572 if not Posted then
24573 Posted := True;
24574 SPARK_Msg_N
24575 ("body of package & has unused hidden states", Body_Id);
24576 end if;
24578 Error_Msg_Sloc := Sloc (State_Id);
24580 if Ekind (State_Id) = E_Abstract_State then
24581 SPARK_Msg_NE
24582 ("\abstract state & defined #", Body_Id, State_Id);
24584 elsif Ekind (State_Id) = E_Constant then
24585 SPARK_Msg_NE ("\constant & defined #", Body_Id, State_Id);
24587 else
24588 pragma Assert (Ekind (State_Id) = E_Variable);
24589 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
24590 end if;
24592 Next_Elmt (State_Elmt);
24593 end loop;
24594 end if;
24595 end Report_Unused_States;
24597 -- Local declarations
24599 Clauses : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
24600 Clause : Node_Id;
24602 -- Start of processing for Analyze_Refined_State_In_Decl_Part
24604 begin
24605 Set_Analyzed (N);
24607 -- Replicate the abstract states declared by the package because the
24608 -- matching algorithm will consume states.
24610 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
24612 -- Gather all abstract states and objects declared in the visible
24613 -- state space of the package body. These items must be utilized as
24614 -- constituents in a state refinement.
24616 Body_States := Collect_Body_States (Spec_Id);
24618 -- Multiple non-null state refinements appear as an aggregate
24620 if Nkind (Clauses) = N_Aggregate then
24621 if Present (Expressions (Clauses)) then
24622 SPARK_Msg_N
24623 ("state refinements must appear as component associations",
24624 Clauses);
24626 else pragma Assert (Present (Component_Associations (Clauses)));
24627 Clause := First (Component_Associations (Clauses));
24628 while Present (Clause) loop
24629 Analyze_Refinement_Clause (Clause);
24630 Next (Clause);
24631 end loop;
24632 end if;
24634 -- Various forms of a single state refinement. Note that these may
24635 -- include malformed refinements.
24637 else
24638 Analyze_Refinement_Clause (Clauses);
24639 end if;
24641 -- List all abstract states that were left unrefined
24643 Report_Unrefined_States (Available_States);
24645 -- Ensure that all abstract states and objects declared in the body
24646 -- state space of the related package are utilized as constituents.
24648 Report_Unused_States (Body_States);
24649 end Analyze_Refined_State_In_Decl_Part;
24651 ------------------------------------
24652 -- Analyze_Test_Case_In_Decl_Part --
24653 ------------------------------------
24655 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is
24656 Subp_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
24657 Spec_Id : constant Entity_Id := Corresponding_Spec_Of (Subp_Decl);
24659 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id);
24660 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
24661 -- denoted by Arg_Nam.
24663 ------------------------------
24664 -- Preanalyze_Test_Case_Arg --
24665 ------------------------------
24667 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id) is
24668 Arg : Node_Id;
24670 begin
24671 -- Preanalyze the original aspect argument for ASIS or for a generic
24672 -- subprogram to properly capture global references.
24674 if ASIS_Mode or else Is_Generic_Subprogram (Spec_Id) then
24675 Arg :=
24676 Test_Case_Arg
24677 (Prag => N,
24678 Arg_Nam => Arg_Nam,
24679 From_Aspect => True);
24681 if Present (Arg) then
24682 Preanalyze_Assert_Expression
24683 (Expression (Arg), Standard_Boolean);
24684 end if;
24685 end if;
24687 Arg := Test_Case_Arg (N, Arg_Nam);
24689 if Present (Arg) then
24690 Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean);
24691 end if;
24692 end Preanalyze_Test_Case_Arg;
24694 -- Local variables
24696 Restore_Scope : Boolean := False;
24698 -- Start of processing for Analyze_Test_Case_In_Decl_Part
24700 begin
24701 -- Ensure that the formal parameters are visible when analyzing all
24702 -- clauses. This falls out of the general rule of aspects pertaining
24703 -- to subprogram declarations.
24705 if not In_Open_Scopes (Spec_Id) then
24706 Restore_Scope := True;
24707 Push_Scope (Spec_Id);
24709 if Is_Generic_Subprogram (Spec_Id) then
24710 Install_Generic_Formals (Spec_Id);
24711 else
24712 Install_Formals (Spec_Id);
24713 end if;
24714 end if;
24716 Preanalyze_Test_Case_Arg (Name_Requires);
24717 Preanalyze_Test_Case_Arg (Name_Ensures);
24719 if Restore_Scope then
24720 End_Scope;
24721 end if;
24723 -- Currently it is not possible to inline pre/postconditions on a
24724 -- subprogram subject to pragma Inline_Always.
24726 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
24727 end Analyze_Test_Case_In_Decl_Part;
24729 ----------------
24730 -- Appears_In --
24731 ----------------
24733 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
24734 Elmt : Elmt_Id;
24735 Id : Entity_Id;
24737 begin
24738 if Present (List) then
24739 Elmt := First_Elmt (List);
24740 while Present (Elmt) loop
24741 if Nkind (Node (Elmt)) = N_Defining_Identifier then
24742 Id := Node (Elmt);
24743 else
24744 Id := Entity_Of (Node (Elmt));
24745 end if;
24747 if Id = Item_Id then
24748 return True;
24749 end if;
24751 Next_Elmt (Elmt);
24752 end loop;
24753 end if;
24755 return False;
24756 end Appears_In;
24758 -----------------------------
24759 -- Check_Applicable_Policy --
24760 -----------------------------
24762 procedure Check_Applicable_Policy (N : Node_Id) is
24763 PP : Node_Id;
24764 Policy : Name_Id;
24766 Ename : constant Name_Id := Original_Aspect_Pragma_Name (N);
24768 begin
24769 -- No effect if not valid assertion kind name
24771 if not Is_Valid_Assertion_Kind (Ename) then
24772 return;
24773 end if;
24775 -- Loop through entries in check policy list
24777 PP := Opt.Check_Policy_List;
24778 while Present (PP) loop
24779 declare
24780 PPA : constant List_Id := Pragma_Argument_Associations (PP);
24781 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
24783 begin
24784 if Ename = Pnm
24785 or else Pnm = Name_Assertion
24786 or else (Pnm = Name_Statement_Assertions
24787 and then Nam_In (Ename, Name_Assert,
24788 Name_Assert_And_Cut,
24789 Name_Assume,
24790 Name_Loop_Invariant,
24791 Name_Loop_Variant))
24792 then
24793 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
24795 case Policy is
24796 when Name_Off | Name_Ignore =>
24797 Set_Is_Ignored (N, True);
24798 Set_Is_Checked (N, False);
24800 when Name_On | Name_Check =>
24801 Set_Is_Checked (N, True);
24802 Set_Is_Ignored (N, False);
24804 when Name_Disable =>
24805 Set_Is_Ignored (N, True);
24806 Set_Is_Checked (N, False);
24807 Set_Is_Disabled (N, True);
24809 -- That should be exhaustive, the null here is a defence
24810 -- against a malformed tree from previous errors.
24812 when others =>
24813 null;
24814 end case;
24816 return;
24817 end if;
24819 PP := Next_Pragma (PP);
24820 end;
24821 end loop;
24823 -- If there are no specific entries that matched, then we let the
24824 -- setting of assertions govern. Note that this provides the needed
24825 -- compatibility with the RM for the cases of assertion, invariant,
24826 -- precondition, predicate, and postcondition.
24828 if Assertions_Enabled then
24829 Set_Is_Checked (N, True);
24830 Set_Is_Ignored (N, False);
24831 else
24832 Set_Is_Checked (N, False);
24833 Set_Is_Ignored (N, True);
24834 end if;
24835 end Check_Applicable_Policy;
24837 -------------------------------
24838 -- Check_External_Properties --
24839 -------------------------------
24841 procedure Check_External_Properties
24842 (Item : Node_Id;
24843 AR : Boolean;
24844 AW : Boolean;
24845 ER : Boolean;
24846 EW : Boolean)
24848 begin
24849 -- All properties enabled
24851 if AR and AW and ER and EW then
24852 null;
24854 -- Async_Readers + Effective_Writes
24855 -- Async_Readers + Async_Writers + Effective_Writes
24857 elsif AR and EW and not ER then
24858 null;
24860 -- Async_Writers + Effective_Reads
24861 -- Async_Readers + Async_Writers + Effective_Reads
24863 elsif AW and ER and not EW then
24864 null;
24866 -- Async_Readers + Async_Writers
24868 elsif AR and AW and not ER and not EW then
24869 null;
24871 -- Async_Readers
24873 elsif AR and not AW and not ER and not EW then
24874 null;
24876 -- Async_Writers
24878 elsif AW and not AR and not ER and not EW then
24879 null;
24881 else
24882 SPARK_Msg_N
24883 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
24884 Item);
24885 end if;
24886 end Check_External_Properties;
24888 ----------------
24889 -- Check_Kind --
24890 ----------------
24892 function Check_Kind (Nam : Name_Id) return Name_Id is
24893 PP : Node_Id;
24895 begin
24896 -- Loop through entries in check policy list
24898 PP := Opt.Check_Policy_List;
24899 while Present (PP) loop
24900 declare
24901 PPA : constant List_Id := Pragma_Argument_Associations (PP);
24902 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
24904 begin
24905 if Nam = Pnm
24906 or else (Pnm = Name_Assertion
24907 and then Is_Valid_Assertion_Kind (Nam))
24908 or else (Pnm = Name_Statement_Assertions
24909 and then Nam_In (Nam, Name_Assert,
24910 Name_Assert_And_Cut,
24911 Name_Assume,
24912 Name_Loop_Invariant,
24913 Name_Loop_Variant))
24914 then
24915 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
24916 when Name_On | Name_Check =>
24917 return Name_Check;
24918 when Name_Off | Name_Ignore =>
24919 return Name_Ignore;
24920 when Name_Disable =>
24921 return Name_Disable;
24922 when others =>
24923 raise Program_Error;
24924 end case;
24926 else
24927 PP := Next_Pragma (PP);
24928 end if;
24929 end;
24930 end loop;
24932 -- If there are no specific entries that matched, then we let the
24933 -- setting of assertions govern. Note that this provides the needed
24934 -- compatibility with the RM for the cases of assertion, invariant,
24935 -- precondition, predicate, and postcondition.
24937 if Assertions_Enabled then
24938 return Name_Check;
24939 else
24940 return Name_Ignore;
24941 end if;
24942 end Check_Kind;
24944 ---------------------------
24945 -- Check_Missing_Part_Of --
24946 ---------------------------
24948 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
24949 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
24950 -- Determine whether a package denoted by Pack_Id declares at least one
24951 -- visible state.
24953 -----------------------
24954 -- Has_Visible_State --
24955 -----------------------
24957 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
24958 Item_Id : Entity_Id;
24960 begin
24961 -- Traverse the entity chain of the package trying to find at least
24962 -- one visible abstract state, variable or a package [instantiation]
24963 -- that declares a visible state.
24965 Item_Id := First_Entity (Pack_Id);
24966 while Present (Item_Id)
24967 and then not In_Private_Part (Item_Id)
24968 loop
24969 -- Do not consider internally generated items
24971 if not Comes_From_Source (Item_Id) then
24972 null;
24974 -- A visible state has been found
24976 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
24977 return True;
24979 -- Recursively peek into nested packages and instantiations
24981 elsif Ekind (Item_Id) = E_Package
24982 and then Has_Visible_State (Item_Id)
24983 then
24984 return True;
24985 end if;
24987 Next_Entity (Item_Id);
24988 end loop;
24990 return False;
24991 end Has_Visible_State;
24993 -- Local variables
24995 Pack_Id : Entity_Id;
24996 Placement : State_Space_Kind;
24998 -- Start of processing for Check_Missing_Part_Of
25000 begin
25001 -- Do not consider abstract states, variables or package instantiations
25002 -- coming from an instance as those always inherit the Part_Of indicator
25003 -- of the instance itself.
25005 if In_Instance then
25006 return;
25008 -- Do not consider internally generated entities as these can never
25009 -- have a Part_Of indicator.
25011 elsif not Comes_From_Source (Item_Id) then
25012 return;
25014 -- Perform these checks only when SPARK_Mode is enabled as they will
25015 -- interfere with standard Ada rules and produce false positives.
25017 elsif SPARK_Mode /= On then
25018 return;
25020 -- Do not consider constants without variable input because those are
25021 -- not part of the hidden state of a package (SPARK RM 7.1.1(2)).
25023 elsif Ekind (Item_Id) = E_Constant
25024 and then not Has_Variable_Input (Item_Id)
25025 then
25026 return;
25027 end if;
25029 -- Find where the abstract state, variable or package instantiation
25030 -- lives with respect to the state space.
25032 Find_Placement_In_State_Space
25033 (Item_Id => Item_Id,
25034 Placement => Placement,
25035 Pack_Id => Pack_Id);
25037 -- Items that appear in a non-package construct (subprogram, block, etc)
25038 -- do not require a Part_Of indicator because they can never act as a
25039 -- hidden state.
25041 if Placement = Not_In_Package then
25042 null;
25044 -- An item declared in the body state space of a package always act as a
25045 -- constituent and does not need explicit Part_Of indicator.
25047 elsif Placement = Body_State_Space then
25048 null;
25050 -- In general an item declared in the visible state space of a package
25051 -- does not require a Part_Of indicator. The only exception is when the
25052 -- related package is a private child unit in which case Part_Of must
25053 -- denote a state in the parent unit or in one of its descendants.
25055 elsif Placement = Visible_State_Space then
25056 if Is_Child_Unit (Pack_Id)
25057 and then Is_Private_Descendant (Pack_Id)
25058 then
25059 -- A package instantiation does not need a Part_Of indicator when
25060 -- the related generic template has no visible state.
25062 if Ekind (Item_Id) = E_Package
25063 and then Is_Generic_Instance (Item_Id)
25064 and then not Has_Visible_State (Item_Id)
25065 then
25066 null;
25068 -- All other cases require Part_Of
25070 else
25071 Error_Msg_N
25072 ("indicator Part_Of is required in this context "
25073 & "(SPARK RM 7.2.6(3))", Item_Id);
25074 Error_Msg_Name_1 := Chars (Pack_Id);
25075 Error_Msg_N
25076 ("\& is declared in the visible part of private child "
25077 & "unit %", Item_Id);
25078 end if;
25079 end if;
25081 -- When the item appears in the private state space of a packge, it must
25082 -- be a part of some state declared by the said package.
25084 else pragma Assert (Placement = Private_State_Space);
25086 -- The related package does not declare a state, the item cannot act
25087 -- as a Part_Of constituent.
25089 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
25090 null;
25092 -- A package instantiation does not need a Part_Of indicator when the
25093 -- related generic template has no visible state.
25095 elsif Ekind (Pack_Id) = E_Package
25096 and then Is_Generic_Instance (Pack_Id)
25097 and then not Has_Visible_State (Pack_Id)
25098 then
25099 null;
25101 -- All other cases require Part_Of
25103 else
25104 Error_Msg_N
25105 ("indicator Part_Of is required in this context "
25106 & "(SPARK RM 7.2.6(2))", Item_Id);
25107 Error_Msg_Name_1 := Chars (Pack_Id);
25108 Error_Msg_N
25109 ("\& is declared in the private part of package %", Item_Id);
25110 end if;
25111 end if;
25112 end Check_Missing_Part_Of;
25114 ---------------------------------------------------
25115 -- Check_Postcondition_Use_In_Inlined_Subprogram --
25116 ---------------------------------------------------
25118 procedure Check_Postcondition_Use_In_Inlined_Subprogram
25119 (Prag : Node_Id;
25120 Spec_Id : Entity_Id)
25122 begin
25123 if Warn_On_Redundant_Constructs
25124 and then Has_Pragma_Inline_Always (Spec_Id)
25125 then
25126 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
25128 if From_Aspect_Specification (Prag) then
25129 Error_Msg_NE
25130 ("aspect % not enforced on inlined subprogram &?r?",
25131 Corresponding_Aspect (Prag), Spec_Id);
25132 else
25133 Error_Msg_NE
25134 ("pragma % not enforced on inlined subprogram &?r?",
25135 Prag, Spec_Id);
25136 end if;
25137 end if;
25138 end Check_Postcondition_Use_In_Inlined_Subprogram;
25140 -------------------------------------
25141 -- Check_State_And_Constituent_Use --
25142 -------------------------------------
25144 procedure Check_State_And_Constituent_Use
25145 (States : Elist_Id;
25146 Constits : Elist_Id;
25147 Context : Node_Id)
25149 function Find_Encapsulating_State
25150 (Constit_Id : Entity_Id) return Entity_Id;
25151 -- Given the entity of a constituent, try to find a corresponding
25152 -- encapsulating state that appears in the same context. The routine
25153 -- returns Empty is no such state is found.
25155 ------------------------------
25156 -- Find_Encapsulating_State --
25157 ------------------------------
25159 function Find_Encapsulating_State
25160 (Constit_Id : Entity_Id) return Entity_Id
25162 State_Id : Entity_Id;
25164 begin
25165 -- Since a constituent may be part of a larger constituent set, climb
25166 -- the encapsulated state chain looking for a state that appears in
25167 -- the same context.
25169 State_Id := Encapsulating_State (Constit_Id);
25170 while Present (State_Id) loop
25171 if Contains (States, State_Id) then
25172 return State_Id;
25173 end if;
25175 State_Id := Encapsulating_State (State_Id);
25176 end loop;
25178 return Empty;
25179 end Find_Encapsulating_State;
25181 -- Local variables
25183 Constit_Elmt : Elmt_Id;
25184 Constit_Id : Entity_Id;
25185 State_Id : Entity_Id;
25187 -- Start of processing for Check_State_And_Constituent_Use
25189 begin
25190 -- Nothing to do if there are no states or constituents
25192 if No (States) or else No (Constits) then
25193 return;
25194 end if;
25196 -- Inspect the list of constituents and try to determine whether its
25197 -- encapsulating state is in list States.
25199 Constit_Elmt := First_Elmt (Constits);
25200 while Present (Constit_Elmt) loop
25201 Constit_Id := Node (Constit_Elmt);
25203 -- Determine whether the constituent is part of an encapsulating
25204 -- state that appears in the same context and if this is the case,
25205 -- emit an error (SPARK RM 7.2.6(7)).
25207 State_Id := Find_Encapsulating_State (Constit_Id);
25209 if Present (State_Id) then
25210 Error_Msg_Name_1 := Chars (Constit_Id);
25211 SPARK_Msg_NE
25212 ("cannot mention state & and its constituent % in the same "
25213 & "context", Context, State_Id);
25214 exit;
25215 end if;
25217 Next_Elmt (Constit_Elmt);
25218 end loop;
25219 end Check_State_And_Constituent_Use;
25221 ---------------------------------------
25222 -- Collect_Subprogram_Inputs_Outputs --
25223 ---------------------------------------
25225 procedure Collect_Subprogram_Inputs_Outputs
25226 (Subp_Id : Entity_Id;
25227 Synthesize : Boolean := False;
25228 Subp_Inputs : in out Elist_Id;
25229 Subp_Outputs : in out Elist_Id;
25230 Global_Seen : out Boolean)
25232 procedure Collect_Dependency_Clause (Clause : Node_Id);
25233 -- Collect all relevant items from a dependency clause
25235 procedure Collect_Global_List
25236 (List : Node_Id;
25237 Mode : Name_Id := Name_Input);
25238 -- Collect all relevant items from a global list
25240 -------------------------------
25241 -- Collect_Dependency_Clause --
25242 -------------------------------
25244 procedure Collect_Dependency_Clause (Clause : Node_Id) is
25245 procedure Collect_Dependency_Item
25246 (Item : Node_Id;
25247 Is_Input : Boolean);
25248 -- Add an item to the proper subprogram input or output collection
25250 -----------------------------
25251 -- Collect_Dependency_Item --
25252 -----------------------------
25254 procedure Collect_Dependency_Item
25255 (Item : Node_Id;
25256 Is_Input : Boolean)
25258 Extra : Node_Id;
25260 begin
25261 -- Nothing to collect when the item is null
25263 if Nkind (Item) = N_Null then
25264 null;
25266 -- Ditto for attribute 'Result
25268 elsif Is_Attribute_Result (Item) then
25269 null;
25271 -- Multiple items appear as an aggregate
25273 elsif Nkind (Item) = N_Aggregate then
25274 Extra := First (Expressions (Item));
25275 while Present (Extra) loop
25276 Collect_Dependency_Item (Extra, Is_Input);
25277 Next (Extra);
25278 end loop;
25280 -- Otherwise this is a solitary item
25282 else
25283 if Is_Input then
25284 Add_Item (Item, Subp_Inputs);
25285 else
25286 Add_Item (Item, Subp_Outputs);
25287 end if;
25288 end if;
25289 end Collect_Dependency_Item;
25291 -- Start of processing for Collect_Dependency_Clause
25293 begin
25294 if Nkind (Clause) = N_Null then
25295 null;
25297 -- A dependency cause appears as component association
25299 elsif Nkind (Clause) = N_Component_Association then
25300 Collect_Dependency_Item
25301 (Item => Expression (Clause),
25302 Is_Input => True);
25304 Collect_Dependency_Item
25305 (Item => First (Choices (Clause)),
25306 Is_Input => False);
25308 -- To accomodate partial decoration of disabled SPARK features, this
25309 -- routine may be called with illegal input. If this is the case, do
25310 -- not raise Program_Error.
25312 else
25313 null;
25314 end if;
25315 end Collect_Dependency_Clause;
25317 -------------------------
25318 -- Collect_Global_List --
25319 -------------------------
25321 procedure Collect_Global_List
25322 (List : Node_Id;
25323 Mode : Name_Id := Name_Input)
25325 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
25326 -- Add an item to the proper subprogram input or output collection
25328 -------------------------
25329 -- Collect_Global_Item --
25330 -------------------------
25332 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
25333 begin
25334 if Nam_In (Mode, Name_In_Out, Name_Input) then
25335 Add_Item (Item, Subp_Inputs);
25336 end if;
25338 if Nam_In (Mode, Name_In_Out, Name_Output) then
25339 Add_Item (Item, Subp_Outputs);
25340 end if;
25341 end Collect_Global_Item;
25343 -- Local variables
25345 Assoc : Node_Id;
25346 Item : Node_Id;
25348 -- Start of processing for Collect_Global_List
25350 begin
25351 if Nkind (List) = N_Null then
25352 null;
25354 -- Single global item declaration
25356 elsif Nkind_In (List, N_Expanded_Name,
25357 N_Identifier,
25358 N_Selected_Component)
25359 then
25360 Collect_Global_Item (List, Mode);
25362 -- Simple global list or moded global list declaration
25364 elsif Nkind (List) = N_Aggregate then
25365 if Present (Expressions (List)) then
25366 Item := First (Expressions (List));
25367 while Present (Item) loop
25368 Collect_Global_Item (Item, Mode);
25369 Next (Item);
25370 end loop;
25372 else
25373 Assoc := First (Component_Associations (List));
25374 while Present (Assoc) loop
25375 Collect_Global_List
25376 (List => Expression (Assoc),
25377 Mode => Chars (First (Choices (Assoc))));
25378 Next (Assoc);
25379 end loop;
25380 end if;
25382 -- To accomodate partial decoration of disabled SPARK features, this
25383 -- routine may be called with illegal input. If this is the case, do
25384 -- not raise Program_Error.
25386 else
25387 null;
25388 end if;
25389 end Collect_Global_List;
25391 -- Local variables
25393 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
25394 Spec_Id : constant Entity_Id := Corresponding_Spec_Of (Subp_Decl);
25395 Clause : Node_Id;
25396 Clauses : Node_Id;
25397 Depends : Node_Id;
25398 Formal : Entity_Id;
25399 Global : Node_Id;
25400 List : Node_Id;
25402 -- Start of processing for Collect_Subprogram_Inputs_Outputs
25404 begin
25405 Global_Seen := False;
25407 -- Process all [generic] formal parameters
25409 Formal := First_Entity (Spec_Id);
25410 while Present (Formal) loop
25411 if Ekind_In (Formal, E_Generic_In_Parameter,
25412 E_In_Out_Parameter,
25413 E_In_Parameter)
25414 then
25415 Add_Item (Formal, Subp_Inputs);
25416 end if;
25418 if Ekind_In (Formal, E_Generic_In_Out_Parameter,
25419 E_In_Out_Parameter,
25420 E_Out_Parameter)
25421 then
25422 Add_Item (Formal, Subp_Outputs);
25424 -- Out parameters can act as inputs when the related type is
25425 -- tagged, unconstrained array, unconstrained record or record
25426 -- with unconstrained components.
25428 if Ekind (Formal) = E_Out_Parameter
25429 and then Is_Unconstrained_Or_Tagged_Item (Formal)
25430 then
25431 Add_Item (Formal, Subp_Inputs);
25432 end if;
25433 end if;
25435 Next_Entity (Formal);
25436 end loop;
25438 -- When processing a subprogram body, look for pragmas Refined_Depends
25439 -- and Refined_Global as they specify the inputs and outputs.
25441 if Ekind (Subp_Id) = E_Subprogram_Body then
25442 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
25443 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
25445 -- Subprogram declaration or stand alone body case, look for pragmas
25446 -- Depends and Global
25448 else
25449 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
25450 Global := Get_Pragma (Spec_Id, Pragma_Global);
25451 end if;
25453 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
25454 -- because it provides finer granularity of inputs and outputs.
25456 if Present (Global) then
25457 Global_Seen := True;
25458 List := Expression (Get_Argument (Global, Spec_Id));
25460 -- The pragma may not have been analyzed because of the arbitrary
25461 -- declaration order of aspects. Make sure that it is analyzed for
25462 -- the purposes of item extraction.
25464 if not Analyzed (List) then
25465 if Pragma_Name (Global) = Name_Refined_Global then
25466 Analyze_Refined_Global_In_Decl_Part (Global);
25467 else
25468 Analyze_Global_In_Decl_Part (Global);
25469 end if;
25470 end if;
25472 Collect_Global_List (List);
25474 -- When the related subprogram lacks pragma [Refined_]Global, fall back
25475 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
25476 -- the inputs and outputs from [Refined_]Depends.
25478 elsif Synthesize and then Present (Depends) then
25479 Clauses := Expression (Get_Argument (Depends, Spec_Id));
25481 -- Multiple dependency clauses appear as an aggregate
25483 if Nkind (Clauses) = N_Aggregate then
25484 Clause := First (Component_Associations (Clauses));
25485 while Present (Clause) loop
25486 Collect_Dependency_Clause (Clause);
25487 Next (Clause);
25488 end loop;
25490 -- Otherwise this is a single dependency clause
25492 else
25493 Collect_Dependency_Clause (Clauses);
25494 end if;
25495 end if;
25496 end Collect_Subprogram_Inputs_Outputs;
25498 ---------------------------------
25499 -- Delay_Config_Pragma_Analyze --
25500 ---------------------------------
25502 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
25503 begin
25504 return Nam_In (Pragma_Name (N), Name_Interrupt_State,
25505 Name_Priority_Specific_Dispatching);
25506 end Delay_Config_Pragma_Analyze;
25508 -----------------------
25509 -- Duplication_Error --
25510 -----------------------
25512 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is
25513 Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag);
25514 Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev);
25516 begin
25517 Error_Msg_Sloc := Sloc (Prev);
25518 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
25520 -- Emit a precise message to distinguish between source pragmas and
25521 -- pragmas generated from aspects. The ordering of the two pragmas is
25522 -- the following:
25524 -- Prev -- ok
25525 -- Prag -- duplicate
25527 -- No error is emitted when both pragmas come from aspects because this
25528 -- is already detected by the general aspect analysis mechanism.
25530 if Prag_From_Asp and Prev_From_Asp then
25531 null;
25532 elsif Prag_From_Asp then
25533 Error_Msg_N ("aspect % duplicates pragma declared #", Prag);
25534 elsif Prev_From_Asp then
25535 Error_Msg_N ("pragma % duplicates aspect declared #", Prag);
25536 else
25537 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
25538 end if;
25539 end Duplication_Error;
25541 ----------------------------------
25542 -- Find_Related_Package_Or_Body --
25543 ----------------------------------
25545 function Find_Related_Package_Or_Body
25546 (Prag : Node_Id;
25547 Do_Checks : Boolean := False) return Node_Id
25549 Context : constant Node_Id := Parent (Prag);
25550 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
25551 Stmt : Node_Id;
25553 begin
25554 Stmt := Prev (Prag);
25555 while Present (Stmt) loop
25557 -- Skip prior pragmas, but check for duplicates
25559 if Nkind (Stmt) = N_Pragma then
25560 if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then
25561 Duplication_Error
25562 (Prag => Prag,
25563 Prev => Stmt);
25564 end if;
25566 -- Skip internally generated code
25568 elsif not Comes_From_Source (Stmt) then
25569 if Nkind (Stmt) = N_Subprogram_Declaration then
25571 -- The subprogram declaration is an internally generated spec
25572 -- for an expression function.
25574 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
25575 return Stmt;
25577 -- The subprogram is actually an instance housed within an
25578 -- anonymous wrapper package.
25580 elsif Present (Generic_Parent (Specification (Stmt))) then
25581 return Stmt;
25582 end if;
25583 end if;
25585 -- Return the current source construct which is illegal
25587 else
25588 return Stmt;
25589 end if;
25591 Prev (Stmt);
25592 end loop;
25594 -- If we fall through, then the pragma was either the first declaration
25595 -- or it was preceded by other pragmas and no source constructs.
25597 -- The pragma is associated with a package. The immediate context in
25598 -- this case is the specification of the package.
25600 if Nkind (Context) = N_Package_Specification then
25601 return Parent (Context);
25603 -- The pragma appears in the declarations of a package body
25605 elsif Nkind (Context) = N_Package_Body then
25606 return Context;
25608 -- The pragma appears in the statements of a package body
25610 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
25611 and then Nkind (Parent (Context)) = N_Package_Body
25612 then
25613 return Parent (Context);
25615 -- The pragma is a byproduct of aspect expansion, return the related
25616 -- context of the original aspect. This case has a lower priority as
25617 -- the above circuitry pinpoints precisely the related context.
25619 elsif Present (Corresponding_Aspect (Prag)) then
25620 return Parent (Corresponding_Aspect (Prag));
25622 -- No candidate packge [body] found
25624 else
25625 return Empty;
25626 end if;
25627 end Find_Related_Package_Or_Body;
25629 -------------------------------------
25630 -- Find_Related_Subprogram_Or_Body --
25631 -------------------------------------
25633 function Find_Related_Subprogram_Or_Body
25634 (Prag : Node_Id;
25635 Do_Checks : Boolean := False) return Node_Id
25637 Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
25639 procedure Expression_Function_Error;
25640 -- Emit an error concerning pragma Prag that illegaly applies to an
25641 -- expression function.
25643 -------------------------------
25644 -- Expression_Function_Error --
25645 -------------------------------
25647 procedure Expression_Function_Error is
25648 begin
25649 Error_Msg_Name_1 := Prag_Nam;
25651 -- Emit a precise message to distinguish between source pragmas and
25652 -- pragmas generated from aspects.
25654 if From_Aspect_Specification (Prag) then
25655 Error_Msg_N
25656 ("aspect % cannot apply to a stand alone expression function",
25657 Prag);
25658 else
25659 Error_Msg_N
25660 ("pragma % cannot apply to a stand alone expression function",
25661 Prag);
25662 end if;
25663 end Expression_Function_Error;
25665 -- Local variables
25667 Context : constant Node_Id := Parent (Prag);
25668 Stmt : Node_Id;
25670 Look_For_Body : constant Boolean :=
25671 Nam_In (Prag_Nam, Name_Refined_Depends,
25672 Name_Refined_Global,
25673 Name_Refined_Post);
25674 -- Refinement pragmas must be associated with a subprogram body [stub]
25676 -- Start of processing for Find_Related_Subprogram_Or_Body
25678 begin
25679 Stmt := Prev (Prag);
25680 while Present (Stmt) loop
25682 -- Skip prior pragmas, but check for duplicates. Pragmas produced
25683 -- by splitting a complex pre/postcondition are not considered to
25684 -- be duplicates.
25686 if Nkind (Stmt) = N_Pragma then
25687 if Do_Checks
25688 and then not Split_PPC (Stmt)
25689 and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam
25690 then
25691 Duplication_Error
25692 (Prag => Prag,
25693 Prev => Stmt);
25694 end if;
25696 -- Emit an error when a refinement pragma appears on an expression
25697 -- function without a completion.
25699 elsif Do_Checks
25700 and then Look_For_Body
25701 and then Nkind (Stmt) = N_Subprogram_Declaration
25702 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
25703 and then not Has_Completion (Defining_Entity (Stmt))
25704 then
25705 Expression_Function_Error;
25706 return Empty;
25708 -- The refinement pragma applies to a subprogram body stub
25710 elsif Look_For_Body
25711 and then Nkind (Stmt) = N_Subprogram_Body_Stub
25712 then
25713 return Stmt;
25715 -- Skip internally generated code
25717 elsif not Comes_From_Source (Stmt) then
25718 if Nkind (Stmt) = N_Subprogram_Declaration then
25720 -- The subprogram declaration is an internally generated spec
25721 -- for an expression function.
25723 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
25724 return Stmt;
25726 -- The subprogram is actually an instance housed within an
25727 -- anonymous wrapper package.
25729 elsif Present (Generic_Parent (Specification (Stmt))) then
25730 return Stmt;
25731 end if;
25732 end if;
25734 -- Return the current construct which is either a subprogram body,
25735 -- a subprogram declaration or is illegal.
25737 else
25738 return Stmt;
25739 end if;
25741 Prev (Stmt);
25742 end loop;
25744 -- If we fall through, then the pragma was either the first declaration
25745 -- or it was preceded by other pragmas and no source constructs.
25747 -- The pragma is associated with a library-level subprogram
25749 if Nkind (Context) = N_Compilation_Unit_Aux then
25750 return Unit (Parent (Context));
25752 -- The pragma appears inside the statements of a subprogram body. This
25753 -- placement is the result of subprogram contract expansion.
25755 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
25756 return Parent (Context);
25758 -- The pragma appears inside the declarative part of a subprogram body
25760 elsif Nkind (Context) = N_Subprogram_Body then
25761 return Context;
25763 -- The pragma is a byproduct of aspect expansion, return the related
25764 -- context of the original aspect. This case has a lower priority as
25765 -- the above circuitry pinpoints precisely the related context.
25767 elsif Present (Corresponding_Aspect (Prag)) then
25768 return Parent (Corresponding_Aspect (Prag));
25770 -- No candidate subprogram [body] found
25772 else
25773 return Empty;
25774 end if;
25775 end Find_Related_Subprogram_Or_Body;
25777 ------------------
25778 -- Get_Argument --
25779 ------------------
25781 function Get_Argument
25782 (Prag : Node_Id;
25783 Context_Id : Entity_Id := Empty) return Node_Id
25785 Args : constant List_Id := Pragma_Argument_Associations (Prag);
25787 begin
25788 -- Use the expression of the original aspect when compiling for ASIS or
25789 -- when analyzing the template of a generic unit. In both cases the
25790 -- aspect's tree must be decorated to allow for ASIS queries or to save
25791 -- the global references in the generic context.
25793 if From_Aspect_Specification (Prag)
25794 and then (ASIS_Mode or else (Present (Context_Id)
25795 and then Is_Generic_Unit (Context_Id)))
25796 then
25797 return Corresponding_Aspect (Prag);
25799 -- Otherwise use the expression of the pragma
25801 elsif Present (Args) then
25802 return First (Args);
25804 else
25805 return Empty;
25806 end if;
25807 end Get_Argument;
25809 -------------------------
25810 -- Get_Base_Subprogram --
25811 -------------------------
25813 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
25814 Result : Entity_Id;
25816 begin
25817 -- Follow subprogram renaming chain
25819 Result := Def_Id;
25821 if Is_Subprogram (Result)
25822 and then
25823 Nkind (Parent (Declaration_Node (Result))) =
25824 N_Subprogram_Renaming_Declaration
25825 and then Present (Alias (Result))
25826 then
25827 Result := Alias (Result);
25828 end if;
25830 return Result;
25831 end Get_Base_Subprogram;
25833 -----------------------
25834 -- Get_SPARK_Mode_Type --
25835 -----------------------
25837 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
25838 begin
25839 if N = Name_On then
25840 return On;
25841 elsif N = Name_Off then
25842 return Off;
25844 -- Any other argument is illegal
25846 else
25847 raise Program_Error;
25848 end if;
25849 end Get_SPARK_Mode_Type;
25851 --------------------------------
25852 -- Get_SPARK_Mode_From_Pragma --
25853 --------------------------------
25855 function Get_SPARK_Mode_From_Pragma (N : Node_Id) return SPARK_Mode_Type is
25856 Args : List_Id;
25857 Mode : Node_Id;
25859 begin
25860 pragma Assert (Nkind (N) = N_Pragma);
25861 Args := Pragma_Argument_Associations (N);
25863 -- Extract the mode from the argument list
25865 if Present (Args) then
25866 Mode := First (Pragma_Argument_Associations (N));
25867 return Get_SPARK_Mode_Type (Chars (Get_Pragma_Arg (Mode)));
25869 -- If SPARK_Mode pragma has no argument, default is ON
25871 else
25872 return On;
25873 end if;
25874 end Get_SPARK_Mode_From_Pragma;
25876 ---------------------------
25877 -- Has_Extra_Parentheses --
25878 ---------------------------
25880 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
25881 Expr : Node_Id;
25883 begin
25884 -- The aggregate should not have an expression list because a clause
25885 -- is always interpreted as a component association. The only way an
25886 -- expression list can sneak in is by adding extra parentheses around
25887 -- the individual clauses:
25889 -- Depends (Output => Input) -- proper form
25890 -- Depends ((Output => Input)) -- extra parentheses
25892 -- Since the extra parentheses are not allowed by the syntax of the
25893 -- pragma, flag them now to avoid emitting misleading errors down the
25894 -- line.
25896 if Nkind (Clause) = N_Aggregate
25897 and then Present (Expressions (Clause))
25898 then
25899 Expr := First (Expressions (Clause));
25900 while Present (Expr) loop
25902 -- A dependency clause surrounded by extra parentheses appears
25903 -- as an aggregate of component associations with an optional
25904 -- Paren_Count set.
25906 if Nkind (Expr) = N_Aggregate
25907 and then Present (Component_Associations (Expr))
25908 then
25909 SPARK_Msg_N
25910 ("dependency clause contains extra parentheses", Expr);
25912 -- Otherwise the expression is a malformed construct
25914 else
25915 SPARK_Msg_N ("malformed dependency clause", Expr);
25916 end if;
25918 Next (Expr);
25919 end loop;
25921 return True;
25922 end if;
25924 return False;
25925 end Has_Extra_Parentheses;
25927 ----------------
25928 -- Initialize --
25929 ----------------
25931 procedure Initialize is
25932 begin
25933 Externals.Init;
25934 end Initialize;
25936 --------
25937 -- ip --
25938 --------
25940 procedure ip is
25941 begin
25942 Dummy := Dummy + 1;
25943 end ip;
25945 -----------------------------
25946 -- Is_Config_Static_String --
25947 -----------------------------
25949 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
25951 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
25952 -- This is an internal recursive function that is just like the outer
25953 -- function except that it adds the string to the name buffer rather
25954 -- than placing the string in the name buffer.
25956 ------------------------------
25957 -- Add_Config_Static_String --
25958 ------------------------------
25960 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
25961 N : Node_Id;
25962 C : Char_Code;
25964 begin
25965 N := Arg;
25967 if Nkind (N) = N_Op_Concat then
25968 if Add_Config_Static_String (Left_Opnd (N)) then
25969 N := Right_Opnd (N);
25970 else
25971 return False;
25972 end if;
25973 end if;
25975 if Nkind (N) /= N_String_Literal then
25976 Error_Msg_N ("string literal expected for pragma argument", N);
25977 return False;
25979 else
25980 for J in 1 .. String_Length (Strval (N)) loop
25981 C := Get_String_Char (Strval (N), J);
25983 if not In_Character_Range (C) then
25984 Error_Msg
25985 ("string literal contains invalid wide character",
25986 Sloc (N) + 1 + Source_Ptr (J));
25987 return False;
25988 end if;
25990 Add_Char_To_Name_Buffer (Get_Character (C));
25991 end loop;
25992 end if;
25994 return True;
25995 end Add_Config_Static_String;
25997 -- Start of processing for Is_Config_Static_String
25999 begin
26000 Name_Len := 0;
26002 return Add_Config_Static_String (Arg);
26003 end Is_Config_Static_String;
26005 -------------------------------
26006 -- Is_Elaboration_SPARK_Mode --
26007 -------------------------------
26009 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
26010 begin
26011 pragma Assert
26012 (Nkind (N) = N_Pragma
26013 and then Pragma_Name (N) = Name_SPARK_Mode
26014 and then Is_List_Member (N));
26016 -- Pragma SPARK_Mode affects the elaboration of a package body when it
26017 -- appears in the statement part of the body.
26019 return
26020 Present (Parent (N))
26021 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
26022 and then List_Containing (N) = Statements (Parent (N))
26023 and then Present (Parent (Parent (N)))
26024 and then Nkind (Parent (Parent (N))) = N_Package_Body;
26025 end Is_Elaboration_SPARK_Mode;
26027 -----------------------------------------
26028 -- Is_Non_Significant_Pragma_Reference --
26029 -----------------------------------------
26031 -- This function makes use of the following static table which indicates
26032 -- whether appearance of some name in a given pragma is to be considered
26033 -- as a reference for the purposes of warnings about unreferenced objects.
26035 -- -1 indicates that appearence in any argument is significant
26036 -- 0 indicates that appearance in any argument is not significant
26037 -- +n indicates that appearance as argument n is significant, but all
26038 -- other arguments are not significant
26039 -- 9n arguments from n on are significant, before n inisignificant
26041 Sig_Flags : constant array (Pragma_Id) of Int :=
26042 (Pragma_Abort_Defer => -1,
26043 Pragma_Abstract_State => -1,
26044 Pragma_Ada_83 => -1,
26045 Pragma_Ada_95 => -1,
26046 Pragma_Ada_05 => -1,
26047 Pragma_Ada_2005 => -1,
26048 Pragma_Ada_12 => -1,
26049 Pragma_Ada_2012 => -1,
26050 Pragma_All_Calls_Remote => -1,
26051 Pragma_Allow_Integer_Address => -1,
26052 Pragma_Annotate => 93,
26053 Pragma_Assert => -1,
26054 Pragma_Assert_And_Cut => -1,
26055 Pragma_Assertion_Policy => 0,
26056 Pragma_Assume => -1,
26057 Pragma_Assume_No_Invalid_Values => 0,
26058 Pragma_Async_Readers => 0,
26059 Pragma_Async_Writers => 0,
26060 Pragma_Asynchronous => 0,
26061 Pragma_Atomic => 0,
26062 Pragma_Atomic_Components => 0,
26063 Pragma_Attach_Handler => -1,
26064 Pragma_Attribute_Definition => 92,
26065 Pragma_Check => -1,
26066 Pragma_Check_Float_Overflow => 0,
26067 Pragma_Check_Name => 0,
26068 Pragma_Check_Policy => 0,
26069 Pragma_CIL_Constructor => 0,
26070 Pragma_CPP_Class => 0,
26071 Pragma_CPP_Constructor => 0,
26072 Pragma_CPP_Virtual => 0,
26073 Pragma_CPP_Vtable => 0,
26074 Pragma_CPU => -1,
26075 Pragma_C_Pass_By_Copy => 0,
26076 Pragma_Comment => -1,
26077 Pragma_Common_Object => 0,
26078 Pragma_Compile_Time_Error => -1,
26079 Pragma_Compile_Time_Warning => -1,
26080 Pragma_Compiler_Unit => -1,
26081 Pragma_Compiler_Unit_Warning => -1,
26082 Pragma_Complete_Representation => 0,
26083 Pragma_Complex_Representation => 0,
26084 Pragma_Component_Alignment => 0,
26085 Pragma_Contract_Cases => -1,
26086 Pragma_Controlled => 0,
26087 Pragma_Convention => 0,
26088 Pragma_Convention_Identifier => 0,
26089 Pragma_Debug => -1,
26090 Pragma_Debug_Policy => 0,
26091 Pragma_Detect_Blocking => 0,
26092 Pragma_Default_Initial_Condition => -1,
26093 Pragma_Default_Scalar_Storage_Order => 0,
26094 Pragma_Default_Storage_Pool => 0,
26095 Pragma_Depends => -1,
26096 Pragma_Disable_Atomic_Synchronization => 0,
26097 Pragma_Discard_Names => 0,
26098 Pragma_Dispatching_Domain => -1,
26099 Pragma_Effective_Reads => 0,
26100 Pragma_Effective_Writes => 0,
26101 Pragma_Elaborate => 0,
26102 Pragma_Elaborate_All => 0,
26103 Pragma_Elaborate_Body => 0,
26104 Pragma_Elaboration_Checks => 0,
26105 Pragma_Eliminate => 0,
26106 Pragma_Enable_Atomic_Synchronization => 0,
26107 Pragma_Export => -1,
26108 Pragma_Export_Function => -1,
26109 Pragma_Export_Object => -1,
26110 Pragma_Export_Procedure => -1,
26111 Pragma_Export_Value => -1,
26112 Pragma_Export_Valued_Procedure => -1,
26113 Pragma_Extend_System => -1,
26114 Pragma_Extensions_Allowed => 0,
26115 Pragma_Extensions_Visible => 0,
26116 Pragma_External => -1,
26117 Pragma_Favor_Top_Level => 0,
26118 Pragma_External_Name_Casing => 0,
26119 Pragma_Fast_Math => 0,
26120 Pragma_Finalize_Storage_Only => 0,
26121 Pragma_Ghost => 0,
26122 Pragma_Global => -1,
26123 Pragma_Ident => -1,
26124 Pragma_Ignore_Pragma => 0,
26125 Pragma_Implementation_Defined => -1,
26126 Pragma_Implemented => -1,
26127 Pragma_Implicit_Packing => 0,
26128 Pragma_Import => 93,
26129 Pragma_Import_Function => 0,
26130 Pragma_Import_Object => 0,
26131 Pragma_Import_Procedure => 0,
26132 Pragma_Import_Valued_Procedure => 0,
26133 Pragma_Independent => 0,
26134 Pragma_Independent_Components => 0,
26135 Pragma_Initial_Condition => -1,
26136 Pragma_Initialize_Scalars => 0,
26137 Pragma_Initializes => -1,
26138 Pragma_Inline => 0,
26139 Pragma_Inline_Always => 0,
26140 Pragma_Inline_Generic => 0,
26141 Pragma_Inspection_Point => -1,
26142 Pragma_Interface => 92,
26143 Pragma_Interface_Name => 0,
26144 Pragma_Interrupt_Handler => -1,
26145 Pragma_Interrupt_Priority => -1,
26146 Pragma_Interrupt_State => -1,
26147 Pragma_Invariant => -1,
26148 Pragma_Java_Constructor => -1,
26149 Pragma_Java_Interface => -1,
26150 Pragma_Keep_Names => 0,
26151 Pragma_License => 0,
26152 Pragma_Link_With => -1,
26153 Pragma_Linker_Alias => -1,
26154 Pragma_Linker_Constructor => -1,
26155 Pragma_Linker_Destructor => -1,
26156 Pragma_Linker_Options => -1,
26157 Pragma_Linker_Section => 0,
26158 Pragma_List => 0,
26159 Pragma_Lock_Free => 0,
26160 Pragma_Locking_Policy => 0,
26161 Pragma_Loop_Invariant => -1,
26162 Pragma_Loop_Optimize => 0,
26163 Pragma_Loop_Variant => -1,
26164 Pragma_Machine_Attribute => -1,
26165 Pragma_Main => -1,
26166 Pragma_Main_Storage => -1,
26167 Pragma_Memory_Size => 0,
26168 Pragma_No_Return => 0,
26169 Pragma_No_Body => 0,
26170 Pragma_No_Elaboration_Code_All => 0,
26171 Pragma_No_Inline => 0,
26172 Pragma_No_Run_Time => -1,
26173 Pragma_No_Strict_Aliasing => -1,
26174 Pragma_No_Tagged_Streams => 0,
26175 Pragma_Normalize_Scalars => 0,
26176 Pragma_Obsolescent => 0,
26177 Pragma_Optimize => 0,
26178 Pragma_Optimize_Alignment => 0,
26179 Pragma_Overflow_Mode => 0,
26180 Pragma_Overriding_Renamings => 0,
26181 Pragma_Ordered => 0,
26182 Pragma_Pack => 0,
26183 Pragma_Page => 0,
26184 Pragma_Part_Of => 0,
26185 Pragma_Partition_Elaboration_Policy => 0,
26186 Pragma_Passive => 0,
26187 Pragma_Persistent_BSS => 0,
26188 Pragma_Polling => 0,
26189 Pragma_Prefix_Exception_Messages => 0,
26190 Pragma_Post => -1,
26191 Pragma_Postcondition => -1,
26192 Pragma_Post_Class => -1,
26193 Pragma_Pre => -1,
26194 Pragma_Precondition => -1,
26195 Pragma_Predicate => -1,
26196 Pragma_Preelaborable_Initialization => -1,
26197 Pragma_Preelaborate => 0,
26198 Pragma_Pre_Class => -1,
26199 Pragma_Priority => -1,
26200 Pragma_Priority_Specific_Dispatching => 0,
26201 Pragma_Profile => 0,
26202 Pragma_Profile_Warnings => 0,
26203 Pragma_Propagate_Exceptions => 0,
26204 Pragma_Provide_Shift_Operators => 0,
26205 Pragma_Psect_Object => 0,
26206 Pragma_Pure => 0,
26207 Pragma_Pure_Function => 0,
26208 Pragma_Queuing_Policy => 0,
26209 Pragma_Rational => 0,
26210 Pragma_Ravenscar => 0,
26211 Pragma_Refined_Depends => -1,
26212 Pragma_Refined_Global => -1,
26213 Pragma_Refined_Post => -1,
26214 Pragma_Refined_State => -1,
26215 Pragma_Relative_Deadline => 0,
26216 Pragma_Remote_Access_Type => -1,
26217 Pragma_Remote_Call_Interface => -1,
26218 Pragma_Remote_Types => -1,
26219 Pragma_Restricted_Run_Time => 0,
26220 Pragma_Restriction_Warnings => 0,
26221 Pragma_Restrictions => 0,
26222 Pragma_Reviewable => -1,
26223 Pragma_Short_Circuit_And_Or => 0,
26224 Pragma_Share_Generic => 0,
26225 Pragma_Shared => 0,
26226 Pragma_Shared_Passive => 0,
26227 Pragma_Short_Descriptors => 0,
26228 Pragma_Simple_Storage_Pool_Type => 0,
26229 Pragma_Source_File_Name => 0,
26230 Pragma_Source_File_Name_Project => 0,
26231 Pragma_Source_Reference => 0,
26232 Pragma_SPARK_Mode => 0,
26233 Pragma_Storage_Size => -1,
26234 Pragma_Storage_Unit => 0,
26235 Pragma_Static_Elaboration_Desired => 0,
26236 Pragma_Stream_Convert => 0,
26237 Pragma_Style_Checks => 0,
26238 Pragma_Subtitle => 0,
26239 Pragma_Suppress => 0,
26240 Pragma_Suppress_Exception_Locations => 0,
26241 Pragma_Suppress_All => 0,
26242 Pragma_Suppress_Debug_Info => 0,
26243 Pragma_Suppress_Initialization => 0,
26244 Pragma_System_Name => 0,
26245 Pragma_Task_Dispatching_Policy => 0,
26246 Pragma_Task_Info => -1,
26247 Pragma_Task_Name => -1,
26248 Pragma_Task_Storage => -1,
26249 Pragma_Test_Case => -1,
26250 Pragma_Thread_Local_Storage => -1,
26251 Pragma_Time_Slice => -1,
26252 Pragma_Title => 0,
26253 Pragma_Type_Invariant => -1,
26254 Pragma_Type_Invariant_Class => -1,
26255 Pragma_Unchecked_Union => 0,
26256 Pragma_Unimplemented_Unit => 0,
26257 Pragma_Universal_Aliasing => 0,
26258 Pragma_Universal_Data => 0,
26259 Pragma_Unmodified => 0,
26260 Pragma_Unreferenced => 0,
26261 Pragma_Unreferenced_Objects => 0,
26262 Pragma_Unreserve_All_Interrupts => 0,
26263 Pragma_Unsuppress => 0,
26264 Pragma_Unevaluated_Use_Of_Old => 0,
26265 Pragma_Use_VADS_Size => 0,
26266 Pragma_Validity_Checks => 0,
26267 Pragma_Volatile => 0,
26268 Pragma_Volatile_Components => 0,
26269 Pragma_Volatile_Full_Access => 0,
26270 Pragma_Warning_As_Error => 0,
26271 Pragma_Warnings => 0,
26272 Pragma_Weak_External => 0,
26273 Pragma_Wide_Character_Encoding => 0,
26274 Unknown_Pragma => 0);
26276 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
26277 Id : Pragma_Id;
26278 P : Node_Id;
26279 C : Int;
26280 AN : Nat;
26282 function Arg_No return Nat;
26283 -- Returns an integer showing what argument we are in. A value of
26284 -- zero means we are not in any of the arguments.
26286 ------------
26287 -- Arg_No --
26288 ------------
26290 function Arg_No return Nat is
26291 A : Node_Id;
26292 N : Nat;
26294 begin
26295 A := First (Pragma_Argument_Associations (Parent (P)));
26296 N := 1;
26297 loop
26298 if No (A) then
26299 return 0;
26300 elsif A = P then
26301 return N;
26302 end if;
26304 Next (A);
26305 N := N + 1;
26306 end loop;
26307 end Arg_No;
26309 -- Start of processing for Non_Significant_Pragma_Reference
26311 begin
26312 P := Parent (N);
26314 if Nkind (P) /= N_Pragma_Argument_Association then
26315 return False;
26317 else
26318 Id := Get_Pragma_Id (Parent (P));
26319 C := Sig_Flags (Id);
26320 AN := Arg_No;
26322 if AN = 0 then
26323 return False;
26324 end if;
26326 case C is
26327 when -1 =>
26328 return False;
26330 when 0 =>
26331 return True;
26333 when 92 .. 99 =>
26334 return AN < (C - 90);
26336 when others =>
26337 return AN /= C;
26338 end case;
26339 end if;
26340 end Is_Non_Significant_Pragma_Reference;
26342 ------------------------------
26343 -- Is_Pragma_String_Literal --
26344 ------------------------------
26346 -- This function returns true if the corresponding pragma argument is a
26347 -- static string expression. These are the only cases in which string
26348 -- literals can appear as pragma arguments. We also allow a string literal
26349 -- as the first argument to pragma Assert (although it will of course
26350 -- always generate a type error).
26352 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
26353 Pragn : constant Node_Id := Parent (Par);
26354 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
26355 Pname : constant Name_Id := Pragma_Name (Pragn);
26356 Argn : Natural;
26357 N : Node_Id;
26359 begin
26360 Argn := 1;
26361 N := First (Assoc);
26362 loop
26363 exit when N = Par;
26364 Argn := Argn + 1;
26365 Next (N);
26366 end loop;
26368 if Pname = Name_Assert then
26369 return True;
26371 elsif Pname = Name_Export then
26372 return Argn > 2;
26374 elsif Pname = Name_Ident then
26375 return Argn = 1;
26377 elsif Pname = Name_Import then
26378 return Argn > 2;
26380 elsif Pname = Name_Interface_Name then
26381 return Argn > 1;
26383 elsif Pname = Name_Linker_Alias then
26384 return Argn = 2;
26386 elsif Pname = Name_Linker_Section then
26387 return Argn = 2;
26389 elsif Pname = Name_Machine_Attribute then
26390 return Argn = 2;
26392 elsif Pname = Name_Source_File_Name then
26393 return True;
26395 elsif Pname = Name_Source_Reference then
26396 return Argn = 2;
26398 elsif Pname = Name_Title then
26399 return True;
26401 elsif Pname = Name_Subtitle then
26402 return True;
26404 else
26405 return False;
26406 end if;
26407 end Is_Pragma_String_Literal;
26409 ---------------------------
26410 -- Is_Private_SPARK_Mode --
26411 ---------------------------
26413 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
26414 begin
26415 pragma Assert
26416 (Nkind (N) = N_Pragma
26417 and then Pragma_Name (N) = Name_SPARK_Mode
26418 and then Is_List_Member (N));
26420 -- For pragma SPARK_Mode to be private, it has to appear in the private
26421 -- declarations of a package.
26423 return
26424 Present (Parent (N))
26425 and then Nkind (Parent (N)) = N_Package_Specification
26426 and then List_Containing (N) = Private_Declarations (Parent (N));
26427 end Is_Private_SPARK_Mode;
26429 -------------------------------------
26430 -- Is_Unconstrained_Or_Tagged_Item --
26431 -------------------------------------
26433 function Is_Unconstrained_Or_Tagged_Item
26434 (Item : Entity_Id) return Boolean
26436 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
26437 -- Determine whether record type Typ has at least one unconstrained
26438 -- component.
26440 ---------------------------------
26441 -- Has_Unconstrained_Component --
26442 ---------------------------------
26444 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
26445 Comp : Entity_Id;
26447 begin
26448 Comp := First_Component (Typ);
26449 while Present (Comp) loop
26450 if Is_Unconstrained_Or_Tagged_Item (Comp) then
26451 return True;
26452 end if;
26454 Next_Component (Comp);
26455 end loop;
26457 return False;
26458 end Has_Unconstrained_Component;
26460 -- Local variables
26462 Typ : constant Entity_Id := Etype (Item);
26464 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
26466 begin
26467 if Is_Tagged_Type (Typ) then
26468 return True;
26470 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
26471 return True;
26473 elsif Is_Record_Type (Typ) then
26474 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
26475 return True;
26476 else
26477 return Has_Unconstrained_Component (Typ);
26478 end if;
26480 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
26481 return True;
26483 else
26484 return False;
26485 end if;
26486 end Is_Unconstrained_Or_Tagged_Item;
26488 -----------------------------
26489 -- Is_Valid_Assertion_Kind --
26490 -----------------------------
26492 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
26493 begin
26494 case Nam is
26495 when
26496 -- RM defined
26498 Name_Assert |
26499 Name_Static_Predicate |
26500 Name_Dynamic_Predicate |
26501 Name_Pre |
26502 Name_uPre |
26503 Name_Post |
26504 Name_uPost |
26505 Name_Type_Invariant |
26506 Name_uType_Invariant |
26508 -- Impl defined
26510 Name_Assert_And_Cut |
26511 Name_Assume |
26512 Name_Contract_Cases |
26513 Name_Debug |
26514 Name_Default_Initial_Condition |
26515 Name_Ghost |
26516 Name_Initial_Condition |
26517 Name_Invariant |
26518 Name_uInvariant |
26519 Name_Loop_Invariant |
26520 Name_Loop_Variant |
26521 Name_Postcondition |
26522 Name_Precondition |
26523 Name_Predicate |
26524 Name_Refined_Post |
26525 Name_Statement_Assertions => return True;
26527 when others => return False;
26528 end case;
26529 end Is_Valid_Assertion_Kind;
26531 --------------------------------------
26532 -- Process_Compilation_Unit_Pragmas --
26533 --------------------------------------
26535 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
26536 begin
26537 -- A special check for pragma Suppress_All, a very strange DEC pragma,
26538 -- strange because it comes at the end of the unit. Rational has the
26539 -- same name for a pragma, but treats it as a program unit pragma, In
26540 -- GNAT we just decide to allow it anywhere at all. If it appeared then
26541 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
26542 -- node, and we insert a pragma Suppress (All_Checks) at the start of
26543 -- the context clause to ensure the correct processing.
26545 if Has_Pragma_Suppress_All (N) then
26546 Prepend_To (Context_Items (N),
26547 Make_Pragma (Sloc (N),
26548 Chars => Name_Suppress,
26549 Pragma_Argument_Associations => New_List (
26550 Make_Pragma_Argument_Association (Sloc (N),
26551 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
26552 end if;
26554 -- Nothing else to do at the current time
26556 end Process_Compilation_Unit_Pragmas;
26558 ------------------------------------
26559 -- Record_Possible_Body_Reference --
26560 ------------------------------------
26562 procedure Record_Possible_Body_Reference
26563 (State_Id : Entity_Id;
26564 Ref : Node_Id)
26566 Context : Node_Id;
26567 Spec_Id : Entity_Id;
26569 begin
26570 -- Ensure that we are dealing with a reference to a state
26572 pragma Assert (Ekind (State_Id) = E_Abstract_State);
26574 -- Climb the tree starting from the reference looking for a package body
26575 -- whose spec declares the referenced state. This criteria automatically
26576 -- excludes references in package specs which are legal. Note that it is
26577 -- not wise to emit an error now as the package body may lack pragma
26578 -- Refined_State or the referenced state may not be mentioned in the
26579 -- refinement. This approach avoids the generation of misleading errors.
26581 Context := Ref;
26582 while Present (Context) loop
26583 if Nkind (Context) = N_Package_Body then
26584 Spec_Id := Corresponding_Spec (Context);
26586 if Present (Abstract_States (Spec_Id))
26587 and then Contains (Abstract_States (Spec_Id), State_Id)
26588 then
26589 if No (Body_References (State_Id)) then
26590 Set_Body_References (State_Id, New_Elmt_List);
26591 end if;
26593 Append_Elmt (Ref, To => Body_References (State_Id));
26594 exit;
26595 end if;
26596 end if;
26598 Context := Parent (Context);
26599 end loop;
26600 end Record_Possible_Body_Reference;
26602 ------------------------------
26603 -- Relocate_Pragmas_To_Body --
26604 ------------------------------
26606 procedure Relocate_Pragmas_To_Body
26607 (Subp_Body : Node_Id;
26608 Target_Body : Node_Id := Empty)
26610 procedure Relocate_Pragma (Prag : Node_Id);
26611 -- Remove a single pragma from its current list and add it to the
26612 -- declarations of the proper body (either Subp_Body or Target_Body).
26614 ---------------------
26615 -- Relocate_Pragma --
26616 ---------------------
26618 procedure Relocate_Pragma (Prag : Node_Id) is
26619 Decls : List_Id;
26620 Target : Node_Id;
26622 begin
26623 -- When subprogram stubs or expression functions are involves, the
26624 -- destination declaration list belongs to the proper body.
26626 if Present (Target_Body) then
26627 Target := Target_Body;
26628 else
26629 Target := Subp_Body;
26630 end if;
26632 Decls := Declarations (Target);
26634 if No (Decls) then
26635 Decls := New_List;
26636 Set_Declarations (Target, Decls);
26637 end if;
26639 -- Unhook the pragma from its current list
26641 Remove (Prag);
26642 Prepend (Prag, Decls);
26643 end Relocate_Pragma;
26645 -- Local variables
26647 Body_Id : constant Entity_Id :=
26648 Defining_Unit_Name (Specification (Subp_Body));
26649 Next_Stmt : Node_Id;
26650 Stmt : Node_Id;
26652 -- Start of processing for Relocate_Pragmas_To_Body
26654 begin
26655 -- Do not process a body that comes from a separate unit as no construct
26656 -- can possibly follow it.
26658 if not Is_List_Member (Subp_Body) then
26659 return;
26661 -- Do not relocate pragmas that follow a stub if the stub does not have
26662 -- a proper body.
26664 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
26665 and then No (Target_Body)
26666 then
26667 return;
26669 -- Do not process internally generated routine _Postconditions
26671 elsif Ekind (Body_Id) = E_Procedure
26672 and then Chars (Body_Id) = Name_uPostconditions
26673 then
26674 return;
26675 end if;
26677 -- Look at what is following the body. We are interested in certain kind
26678 -- of pragmas (either from source or byproducts of expansion) that can
26679 -- apply to a body [stub].
26681 Stmt := Next (Subp_Body);
26682 while Present (Stmt) loop
26684 -- Preserve the following statement for iteration purposes due to a
26685 -- possible relocation of a pragma.
26687 Next_Stmt := Next (Stmt);
26689 -- Move a candidate pragma following the body to the declarations of
26690 -- the body.
26692 if Nkind (Stmt) = N_Pragma
26693 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
26694 then
26695 Relocate_Pragma (Stmt);
26697 -- Skip internally generated code
26699 elsif not Comes_From_Source (Stmt) then
26700 null;
26702 -- No candidate pragmas are available for relocation
26704 else
26705 exit;
26706 end if;
26708 Stmt := Next_Stmt;
26709 end loop;
26710 end Relocate_Pragmas_To_Body;
26712 -------------------
26713 -- Resolve_State --
26714 -------------------
26716 procedure Resolve_State (N : Node_Id) is
26717 Func : Entity_Id;
26718 State : Entity_Id;
26720 begin
26721 if Is_Entity_Name (N) and then Present (Entity (N)) then
26722 Func := Entity (N);
26724 -- Handle overloading of state names by functions. Traverse the
26725 -- homonym chain looking for an abstract state.
26727 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
26728 State := Homonym (Func);
26729 while Present (State) loop
26731 -- Resolve the overloading by setting the proper entity of the
26732 -- reference to that of the state.
26734 if Ekind (State) = E_Abstract_State then
26735 Set_Etype (N, Standard_Void_Type);
26736 Set_Entity (N, State);
26737 Set_Associated_Node (N, State);
26738 return;
26739 end if;
26741 State := Homonym (State);
26742 end loop;
26744 -- A function can never act as a state. If the homonym chain does
26745 -- not contain a corresponding state, then something went wrong in
26746 -- the overloading mechanism.
26748 raise Program_Error;
26749 end if;
26750 end if;
26751 end Resolve_State;
26753 ----------------------------
26754 -- Rewrite_Assertion_Kind --
26755 ----------------------------
26757 procedure Rewrite_Assertion_Kind (N : Node_Id) is
26758 Nam : Name_Id;
26760 begin
26761 if Nkind (N) = N_Attribute_Reference
26762 and then Attribute_Name (N) = Name_Class
26763 and then Nkind (Prefix (N)) = N_Identifier
26764 then
26765 case Chars (Prefix (N)) is
26766 when Name_Pre =>
26767 Nam := Name_uPre;
26768 when Name_Post =>
26769 Nam := Name_uPost;
26770 when Name_Type_Invariant =>
26771 Nam := Name_uType_Invariant;
26772 when Name_Invariant =>
26773 Nam := Name_uInvariant;
26774 when others =>
26775 return;
26776 end case;
26778 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
26779 end if;
26780 end Rewrite_Assertion_Kind;
26782 --------
26783 -- rv --
26784 --------
26786 procedure rv is
26787 begin
26788 Dummy := Dummy + 1;
26789 end rv;
26791 --------------------------------
26792 -- Set_Encoded_Interface_Name --
26793 --------------------------------
26795 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
26796 Str : constant String_Id := Strval (S);
26797 Len : constant Int := String_Length (Str);
26798 CC : Char_Code;
26799 C : Character;
26800 J : Int;
26802 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
26804 procedure Encode;
26805 -- Stores encoded value of character code CC. The encoding we use an
26806 -- underscore followed by four lower case hex digits.
26808 ------------
26809 -- Encode --
26810 ------------
26812 procedure Encode is
26813 begin
26814 Store_String_Char (Get_Char_Code ('_'));
26815 Store_String_Char
26816 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
26817 Store_String_Char
26818 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
26819 Store_String_Char
26820 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
26821 Store_String_Char
26822 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
26823 end Encode;
26825 -- Start of processing for Set_Encoded_Interface_Name
26827 begin
26828 -- If first character is asterisk, this is a link name, and we leave it
26829 -- completely unmodified. We also ignore null strings (the latter case
26830 -- happens only in error cases) and no encoding should occur for Java or
26831 -- AAMP interface names.
26833 if Len = 0
26834 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
26835 or else VM_Target /= No_VM
26836 or else AAMP_On_Target
26837 then
26838 Set_Interface_Name (E, S);
26840 else
26841 J := 1;
26842 loop
26843 CC := Get_String_Char (Str, J);
26845 exit when not In_Character_Range (CC);
26847 C := Get_Character (CC);
26849 exit when C /= '_' and then C /= '$'
26850 and then C not in '0' .. '9'
26851 and then C not in 'a' .. 'z'
26852 and then C not in 'A' .. 'Z';
26854 if J = Len then
26855 Set_Interface_Name (E, S);
26856 return;
26858 else
26859 J := J + 1;
26860 end if;
26861 end loop;
26863 -- Here we need to encode. The encoding we use as follows:
26864 -- three underscores + four hex digits (lower case)
26866 Start_String;
26868 for J in 1 .. String_Length (Str) loop
26869 CC := Get_String_Char (Str, J);
26871 if not In_Character_Range (CC) then
26872 Encode;
26873 else
26874 C := Get_Character (CC);
26876 if C = '_' or else C = '$'
26877 or else C in '0' .. '9'
26878 or else C in 'a' .. 'z'
26879 or else C in 'A' .. 'Z'
26880 then
26881 Store_String_Char (CC);
26882 else
26883 Encode;
26884 end if;
26885 end if;
26886 end loop;
26888 Set_Interface_Name (E,
26889 Make_String_Literal (Sloc (S),
26890 Strval => End_String));
26891 end if;
26892 end Set_Encoded_Interface_Name;
26894 ------------------------
26895 -- Set_Elab_Unit_Name --
26896 ------------------------
26898 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is
26899 Pref : Node_Id;
26900 Scop : Entity_Id;
26902 begin
26903 if Nkind (N) = N_Identifier
26904 and then Nkind (With_Item) = N_Identifier
26905 then
26906 Set_Entity (N, Entity (With_Item));
26908 elsif Nkind (N) = N_Selected_Component then
26909 Change_Selected_Component_To_Expanded_Name (N);
26910 Set_Entity (N, Entity (With_Item));
26911 Set_Entity (Selector_Name (N), Entity (N));
26913 Pref := Prefix (N);
26914 Scop := Scope (Entity (N));
26915 while Nkind (Pref) = N_Selected_Component loop
26916 Change_Selected_Component_To_Expanded_Name (Pref);
26917 Set_Entity (Selector_Name (Pref), Scop);
26918 Set_Entity (Pref, Scop);
26919 Pref := Prefix (Pref);
26920 Scop := Scope (Scop);
26921 end loop;
26923 Set_Entity (Pref, Scop);
26924 end if;
26926 Generate_Reference (Entity (With_Item), N, Set_Ref => False);
26927 end Set_Elab_Unit_Name;
26929 -------------------
26930 -- Test_Case_Arg --
26931 -------------------
26933 function Test_Case_Arg
26934 (Prag : Node_Id;
26935 Arg_Nam : Name_Id;
26936 From_Aspect : Boolean := False) return Node_Id
26938 Aspect : constant Node_Id := Corresponding_Aspect (Prag);
26939 Arg : Node_Id;
26940 Args : Node_Id;
26942 begin
26943 pragma Assert (Nam_In (Arg_Nam, Name_Ensures,
26944 Name_Mode,
26945 Name_Name,
26946 Name_Requires));
26948 -- The caller requests the aspect argument
26950 if From_Aspect then
26951 if Present (Aspect)
26952 and then Nkind (Expression (Aspect)) = N_Aggregate
26953 then
26954 Args := Expression (Aspect);
26956 -- "Name" and "Mode" may appear without an identifier as a
26957 -- positional association.
26959 if Present (Expressions (Args)) then
26960 Arg := First (Expressions (Args));
26962 if Present (Arg) and then Arg_Nam = Name_Name then
26963 return Arg;
26964 end if;
26966 -- Skip "Name"
26968 Arg := Next (Arg);
26970 if Present (Arg) and then Arg_Nam = Name_Mode then
26971 return Arg;
26972 end if;
26973 end if;
26975 -- Some or all arguments may appear as component associatons
26977 if Present (Component_Associations (Args)) then
26978 Arg := First (Component_Associations (Args));
26979 while Present (Arg) loop
26980 if Chars (First (Choices (Arg))) = Arg_Nam then
26981 return Arg;
26982 end if;
26984 Next (Arg);
26985 end loop;
26986 end if;
26987 end if;
26989 -- Otherwise retrieve the argument directly from the pragma
26991 else
26992 Arg := First (Pragma_Argument_Associations (Prag));
26994 if Present (Arg) and then Arg_Nam = Name_Name then
26995 return Arg;
26996 end if;
26998 -- Skip argument "Name"
27000 Arg := Next (Arg);
27002 if Present (Arg) and then Arg_Nam = Name_Mode then
27003 return Arg;
27004 end if;
27006 -- Skip argument "Mode"
27008 Arg := Next (Arg);
27010 -- Arguments "Requires" and "Ensures" are optional and may not be
27011 -- present at all.
27013 while Present (Arg) loop
27014 if Chars (Arg) = Arg_Nam then
27015 return Arg;
27016 end if;
27018 Next (Arg);
27019 end loop;
27020 end if;
27022 return Empty;
27023 end Test_Case_Arg;
27025 end Sem_Prag;