2015-03-04 Robert Dewar <dewar@adacore.com>
[official-gcc.git] / gcc / ada / sem_prag.adb
blobcae31f3f818536136da7e3e3ae6d5706bcfff3a6
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 Subp_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 Subp_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 Find_Related_Package_Or_Body
227 (Prag : Node_Id;
228 Do_Checks : Boolean := False) return Node_Id;
229 -- Subsidiary to the analysis of pragmas Abstract_State, Initial_Condition,
230 -- Initializes and Refined_State. Find the declaration of the related
231 -- package [body] subject to pragma Prag. The return value is either
232 -- N_Package_Declaration, N_Package_Body or Empty if the placement of
233 -- the pragma is illegal. If flag Do_Checks is set, the routine reports
234 -- duplicate pragmas.
236 function Get_Argument
237 (Prag : Node_Id;
238 Spec_Id : Entity_Id := Empty) return Node_Id;
239 -- Obtain the argument of pragma Prag depending on context and the nature
240 -- of the pragma. The argument is extracted in the following manner:
242 -- When the pragma is generated from an aspect, return the corresponding
243 -- aspect for ASIS or when Spec_Id denotes a generic subprogram.
245 -- Otherwise return the first argument of Prag
247 -- Spec_Id denotes the entity of the subprogram spec where Prag resides
249 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
250 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
251 -- original one, following the renaming chain) is returned. Otherwise the
252 -- entity is returned unchanged. Should be in Einfo???
254 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
255 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
256 -- Get_SPARK_Mode_Type. Convert a name into a corresponding value of type
257 -- SPARK_Mode_Type.
259 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
260 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
261 -- Determine whether dependency clause Clause is surrounded by extra
262 -- parentheses. If this is the case, issue an error message.
264 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
265 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
266 -- pragma Depends. Determine whether the type of dependency item Item is
267 -- tagged, unconstrained array, unconstrained record or a record with at
268 -- least one unconstrained component.
270 procedure Record_Possible_Body_Reference
271 (State_Id : Entity_Id;
272 Ref : Node_Id);
273 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
274 -- Global. Given an abstract state denoted by State_Id and a reference Ref
275 -- to it, determine whether the reference appears in a package body that
276 -- will eventually refine the state. If this is the case, record the
277 -- reference for future checks (see Analyze_Refined_State_In_Decls).
279 procedure Resolve_State (N : Node_Id);
280 -- Handle the overloading of state names by functions. When N denotes a
281 -- function, this routine finds the corresponding state and sets the entity
282 -- of N to that of the state.
284 procedure Rewrite_Assertion_Kind (N : Node_Id);
285 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
286 -- then it is rewritten as an identifier with the corresponding special
287 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
288 -- and Check_Policy.
290 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id);
291 -- Place semantic information on the argument of an Elaborate/Elaborate_All
292 -- pragma. Entity name for unit and its parents is taken from item in
293 -- previous with_clause that mentions the unit.
295 Dummy : Integer := 0;
296 pragma Volatile (Dummy);
297 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
299 procedure ip;
300 pragma No_Inline (ip);
301 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
302 -- is just to help debugging the front end. If a pragma Inspection_Point
303 -- is added to a source program, then breaking on ip will get you to that
304 -- point in the program.
306 procedure rv;
307 pragma No_Inline (rv);
308 -- This is a dummy function called by the processing for pragma Reviewable.
309 -- It is there for assisting front end debugging. By placing a Reviewable
310 -- pragma in the source program, a breakpoint on rv catches this place in
311 -- the source, allowing convenient stepping to the point of interest.
313 --------------
314 -- Add_Item --
315 --------------
317 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id) is
318 begin
319 Append_New_Elmt (Item, To => To_List);
320 end Add_Item;
322 -------------------------------
323 -- Adjust_External_Name_Case --
324 -------------------------------
326 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
327 CC : Char_Code;
329 begin
330 -- Adjust case of literal if required
332 if Opt.External_Name_Exp_Casing = As_Is then
333 return N;
335 else
336 -- Copy existing string
338 Start_String;
340 -- Set proper casing
342 for J in 1 .. String_Length (Strval (N)) loop
343 CC := Get_String_Char (Strval (N), J);
345 if Opt.External_Name_Exp_Casing = Uppercase
346 and then CC >= Get_Char_Code ('a')
347 and then CC <= Get_Char_Code ('z')
348 then
349 Store_String_Char (CC - 32);
351 elsif Opt.External_Name_Exp_Casing = Lowercase
352 and then CC >= Get_Char_Code ('A')
353 and then CC <= Get_Char_Code ('Z')
354 then
355 Store_String_Char (CC + 32);
357 else
358 Store_String_Char (CC);
359 end if;
360 end loop;
362 return
363 Make_String_Literal (Sloc (N),
364 Strval => End_String);
365 end if;
366 end Adjust_External_Name_Case;
368 -----------------------------------------
369 -- Analyze_Contract_Cases_In_Decl_Part --
370 -----------------------------------------
372 procedure Analyze_Contract_Cases_In_Decl_Part (N : Node_Id) is
373 Others_Seen : Boolean := False;
375 procedure Analyze_Contract_Case (CCase : Node_Id);
376 -- Verify the legality of a single contract case
378 ---------------------------
379 -- Analyze_Contract_Case --
380 ---------------------------
382 procedure Analyze_Contract_Case (CCase : Node_Id) is
383 Case_Guard : Node_Id;
384 Conseq : Node_Id;
385 Extra_Guard : Node_Id;
387 begin
388 if Nkind (CCase) = N_Component_Association then
389 Case_Guard := First (Choices (CCase));
390 Conseq := Expression (CCase);
392 -- Each contract case must have exactly one case guard
394 Extra_Guard := Next (Case_Guard);
396 if Present (Extra_Guard) then
397 Error_Msg_N
398 ("contract case must have exactly one case guard",
399 Extra_Guard);
400 end if;
402 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
404 if Nkind (Case_Guard) = N_Others_Choice then
405 if Others_Seen then
406 Error_Msg_N
407 ("only one others choice allowed in contract cases",
408 Case_Guard);
409 else
410 Others_Seen := True;
411 end if;
413 elsif Others_Seen then
414 Error_Msg_N
415 ("others must be the last choice in contract cases", N);
416 end if;
418 -- Preanalyze the case guard and consequence
420 if Nkind (Case_Guard) /= N_Others_Choice then
421 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
422 end if;
424 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
426 -- The contract case is malformed
428 else
429 Error_Msg_N ("wrong syntax in contract case", CCase);
430 end if;
431 end Analyze_Contract_Case;
433 -- Local variables
435 All_Cases : Node_Id;
436 CCase : Node_Id;
437 Spec_Id : Entity_Id;
438 Subp_Decl : Node_Id;
439 Subp_Id : Entity_Id;
441 Restore_Scope : Boolean := False;
442 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
444 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
446 begin
447 Set_Analyzed (N);
449 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
450 Spec_Id := Corresponding_Spec_Of (Subp_Decl);
451 Subp_Id := Defining_Entity (Subp_Decl);
452 All_Cases := Expression (Get_Argument (N, Subp_Id));
454 -- Single and multiple contract cases must appear in aggregate form. If
455 -- this is not the case, then either the parser of the analysis of the
456 -- pragma failed to produce an aggregate.
458 pragma Assert (Nkind (All_Cases) = N_Aggregate);
460 if Present (Component_Associations (All_Cases)) then
462 -- Ensure that the formal parameters are visible when analyzing all
463 -- clauses. This falls out of the general rule of aspects pertaining
464 -- to subprogram declarations. Skip the installation for subprogram
465 -- bodies because the formals are already visible.
467 if not In_Open_Scopes (Spec_Id) then
468 Restore_Scope := True;
469 Push_Scope (Spec_Id);
471 if Is_Generic_Subprogram (Spec_Id) then
472 Install_Generic_Formals (Spec_Id);
473 else
474 Install_Formals (Spec_Id);
475 end if;
476 end if;
478 CCase := First (Component_Associations (All_Cases));
479 while Present (CCase) loop
480 Analyze_Contract_Case (CCase);
481 Next (CCase);
482 end loop;
484 -- Currently it is not possible to inline pre/postconditions on a
485 -- subprogram subject to pragma Inline_Always.
487 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
489 if Restore_Scope then
490 End_Scope;
491 end if;
492 else
493 Error_Msg_N ("wrong syntax for constract cases", N);
494 end if;
495 end Analyze_Contract_Cases_In_Decl_Part;
497 ----------------------------------
498 -- Analyze_Depends_In_Decl_Part --
499 ----------------------------------
501 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
502 Loc : constant Source_Ptr := Sloc (N);
504 All_Inputs_Seen : Elist_Id := No_Elist;
505 -- A list containing the entities of all the inputs processed so far.
506 -- The list is populated with unique entities because the same input
507 -- may appear in multiple input lists.
509 All_Outputs_Seen : Elist_Id := No_Elist;
510 -- A list containing the entities of all the outputs processed so far.
511 -- The list is populated with unique entities because output items are
512 -- unique in a dependence relation.
514 Constits_Seen : Elist_Id := No_Elist;
515 -- A list containing the entities of all constituents processed so far.
516 -- It aids in detecting illegal usage of a state and a corresponding
517 -- constituent in pragma [Refinde_]Depends.
519 Global_Seen : Boolean := False;
520 -- A flag set when pragma Global has been processed
522 Null_Output_Seen : Boolean := False;
523 -- A flag used to track the legality of a null output
525 Result_Seen : Boolean := False;
526 -- A flag set when Subp_Id'Result is processed
528 Spec_Id : Entity_Id;
529 -- The entity of the subprogram subject to pragma [Refined_]Depends
531 States_Seen : Elist_Id := No_Elist;
532 -- A list containing the entities of all states processed so far. It
533 -- helps in detecting illegal usage of a state and a corresponding
534 -- constituent in pragma [Refined_]Depends.
536 Subp_Id : Entity_Id;
537 -- The entity of the subprogram [body or stub] subject to pragma
538 -- [Refined_]Depends.
540 Subp_Inputs : Elist_Id := No_Elist;
541 Subp_Outputs : Elist_Id := No_Elist;
542 -- Two lists containing the full set of inputs and output of the related
543 -- subprograms. Note that these lists contain both nodes and entities.
545 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
546 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
547 -- to the name buffer. The individual kinds are as follows:
548 -- E_Abstract_State - "state"
549 -- E_In_Parameter - "parameter"
550 -- E_In_Out_Parameter - "parameter"
551 -- E_Out_Parameter - "parameter"
552 -- E_Variable - "global"
554 procedure Analyze_Dependency_Clause
555 (Clause : Node_Id;
556 Is_Last : Boolean);
557 -- Verify the legality of a single dependency clause. Flag Is_Last
558 -- denotes whether Clause is the last clause in the relation.
560 procedure Check_Function_Return;
561 -- Verify that Funtion'Result appears as one of the outputs
562 -- (SPARK RM 6.1.5(10)).
564 procedure Check_Role
565 (Item : Node_Id;
566 Item_Id : Entity_Id;
567 Is_Input : Boolean;
568 Self_Ref : Boolean);
569 -- Ensure that an item fulfils its designated input and/or output role
570 -- as specified by pragma Global (if any) or the enclosing context. If
571 -- this is not the case, emit an error. Item and Item_Id denote the
572 -- attributes of an item. Flag Is_Input should be set when item comes
573 -- from an input list. Flag Self_Ref should be set when the item is an
574 -- output and the dependency clause has operator "+".
576 procedure Check_Usage
577 (Subp_Items : Elist_Id;
578 Used_Items : Elist_Id;
579 Is_Input : Boolean);
580 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
581 -- error if this is not the case.
583 procedure Normalize_Clause (Clause : Node_Id);
584 -- Remove a self-dependency "+" from the input list of a clause
586 -----------------------------
587 -- Add_Item_To_Name_Buffer --
588 -----------------------------
590 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
591 begin
592 if Ekind (Item_Id) = E_Abstract_State then
593 Add_Str_To_Name_Buffer ("state");
595 elsif Is_Formal (Item_Id) then
596 Add_Str_To_Name_Buffer ("parameter");
598 elsif Ekind (Item_Id) = E_Variable then
599 Add_Str_To_Name_Buffer ("global");
601 -- The routine should not be called with non-SPARK items
603 else
604 raise Program_Error;
605 end if;
606 end Add_Item_To_Name_Buffer;
608 -------------------------------
609 -- Analyze_Dependency_Clause --
610 -------------------------------
612 procedure Analyze_Dependency_Clause
613 (Clause : Node_Id;
614 Is_Last : Boolean)
616 procedure Analyze_Input_List (Inputs : Node_Id);
617 -- Verify the legality of a single input list
619 procedure Analyze_Input_Output
620 (Item : Node_Id;
621 Is_Input : Boolean;
622 Self_Ref : Boolean;
623 Top_Level : Boolean;
624 Seen : in out Elist_Id;
625 Null_Seen : in out Boolean;
626 Non_Null_Seen : in out Boolean);
627 -- Verify the legality of a single input or output item. Flag
628 -- Is_Input should be set whenever Item is an input, False when it
629 -- denotes an output. Flag Self_Ref should be set when the item is an
630 -- output and the dependency clause has a "+". Flag Top_Level should
631 -- be set whenever Item appears immediately within an input or output
632 -- list. Seen is a collection of all abstract states, variables and
633 -- formals processed so far. Flag Null_Seen denotes whether a null
634 -- input or output has been encountered. Flag Non_Null_Seen denotes
635 -- whether a non-null input or output has been encountered.
637 ------------------------
638 -- Analyze_Input_List --
639 ------------------------
641 procedure Analyze_Input_List (Inputs : Node_Id) is
642 Inputs_Seen : Elist_Id := No_Elist;
643 -- A list containing the entities of all inputs that appear in the
644 -- current input list.
646 Non_Null_Input_Seen : Boolean := False;
647 Null_Input_Seen : Boolean := False;
648 -- Flags used to check the legality of an input list
650 Input : Node_Id;
652 begin
653 -- Multiple inputs appear as an aggregate
655 if Nkind (Inputs) = N_Aggregate then
656 if Present (Component_Associations (Inputs)) then
657 SPARK_Msg_N
658 ("nested dependency relations not allowed", Inputs);
660 elsif Present (Expressions (Inputs)) then
661 Input := First (Expressions (Inputs));
662 while Present (Input) loop
663 Analyze_Input_Output
664 (Item => Input,
665 Is_Input => True,
666 Self_Ref => False,
667 Top_Level => False,
668 Seen => Inputs_Seen,
669 Null_Seen => Null_Input_Seen,
670 Non_Null_Seen => Non_Null_Input_Seen);
672 Next (Input);
673 end loop;
675 -- Syntax error, always report
677 else
678 Error_Msg_N ("malformed input dependency list", Inputs);
679 end if;
681 -- Process a solitary input
683 else
684 Analyze_Input_Output
685 (Item => Inputs,
686 Is_Input => True,
687 Self_Ref => False,
688 Top_Level => False,
689 Seen => Inputs_Seen,
690 Null_Seen => Null_Input_Seen,
691 Non_Null_Seen => Non_Null_Input_Seen);
692 end if;
694 -- Detect an illegal dependency clause of the form
696 -- (null =>[+] null)
698 if Null_Output_Seen and then Null_Input_Seen then
699 SPARK_Msg_N
700 ("null dependency clause cannot have a null input list",
701 Inputs);
702 end if;
703 end Analyze_Input_List;
705 --------------------------
706 -- Analyze_Input_Output --
707 --------------------------
709 procedure Analyze_Input_Output
710 (Item : Node_Id;
711 Is_Input : Boolean;
712 Self_Ref : Boolean;
713 Top_Level : Boolean;
714 Seen : in out Elist_Id;
715 Null_Seen : in out Boolean;
716 Non_Null_Seen : in out Boolean)
718 Is_Output : constant Boolean := not Is_Input;
719 Grouped : Node_Id;
720 Item_Id : Entity_Id;
722 begin
723 -- Multiple input or output items appear as an aggregate
725 if Nkind (Item) = N_Aggregate then
726 if not Top_Level then
727 SPARK_Msg_N ("nested grouping of items not allowed", Item);
729 elsif Present (Component_Associations (Item)) then
730 SPARK_Msg_N
731 ("nested dependency relations not allowed", Item);
733 -- Recursively analyze the grouped items
735 elsif Present (Expressions (Item)) then
736 Grouped := First (Expressions (Item));
737 while Present (Grouped) loop
738 Analyze_Input_Output
739 (Item => Grouped,
740 Is_Input => Is_Input,
741 Self_Ref => Self_Ref,
742 Top_Level => False,
743 Seen => Seen,
744 Null_Seen => Null_Seen,
745 Non_Null_Seen => Non_Null_Seen);
747 Next (Grouped);
748 end loop;
750 -- Syntax error, always report
752 else
753 Error_Msg_N ("malformed dependency list", Item);
754 end if;
756 -- Process Function'Result in the context of a dependency clause
758 elsif Is_Attribute_Result (Item) then
759 Non_Null_Seen := True;
761 -- It is sufficent to analyze the prefix of 'Result in order to
762 -- establish legality of the attribute.
764 Analyze (Prefix (Item));
766 -- The prefix of 'Result must denote the function for which
767 -- pragma Depends applies (SPARK RM 6.1.5(11)).
769 if not Is_Entity_Name (Prefix (Item))
770 or else Ekind (Spec_Id) /= E_Function
771 or else Entity (Prefix (Item)) /= Spec_Id
772 then
773 Error_Msg_Name_1 := Name_Result;
774 SPARK_Msg_N
775 ("prefix of attribute % must denote the enclosing "
776 & "function", Item);
778 -- Function'Result is allowed to appear on the output side of a
779 -- dependency clause (SPARK RM 6.1.5(6)).
781 elsif Is_Input then
782 SPARK_Msg_N ("function result cannot act as input", Item);
784 elsif Null_Seen then
785 SPARK_Msg_N
786 ("cannot mix null and non-null dependency items", Item);
788 else
789 Result_Seen := True;
790 end if;
792 -- Detect multiple uses of null in a single dependency list or
793 -- throughout the whole relation. Verify the placement of a null
794 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
796 elsif Nkind (Item) = N_Null then
797 if Null_Seen then
798 SPARK_Msg_N
799 ("multiple null dependency relations not allowed", Item);
801 elsif Non_Null_Seen then
802 SPARK_Msg_N
803 ("cannot mix null and non-null dependency items", Item);
805 else
806 Null_Seen := True;
808 if Is_Output then
809 if not Is_Last then
810 SPARK_Msg_N
811 ("null output list must be the last clause in a "
812 & "dependency relation", Item);
814 -- Catch a useless dependence of the form:
815 -- null =>+ ...
817 elsif Self_Ref then
818 SPARK_Msg_N
819 ("useless dependence, null depends on itself", Item);
820 end if;
821 end if;
822 end if;
824 -- Default case
826 else
827 Non_Null_Seen := True;
829 if Null_Seen then
830 SPARK_Msg_N ("cannot mix null and non-null items", Item);
831 end if;
833 Analyze (Item);
834 Resolve_State (Item);
836 -- Find the entity of the item. If this is a renaming, climb
837 -- the renaming chain to reach the root object. Renamings of
838 -- non-entire objects do not yield an entity (Empty).
840 Item_Id := Entity_Of (Item);
842 if Present (Item_Id) then
843 if Ekind_In (Item_Id, E_Abstract_State,
844 E_In_Parameter,
845 E_In_Out_Parameter,
846 E_Out_Parameter,
847 E_Variable)
848 then
849 -- Ensure that the item fulfils its role as input and/or
850 -- output as specified by pragma Global or the enclosing
851 -- context.
853 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
855 -- Detect multiple uses of the same state, variable or
856 -- formal parameter. If this is not the case, add the
857 -- item to the list of processed relations.
859 if Contains (Seen, Item_Id) then
860 SPARK_Msg_NE
861 ("duplicate use of item &", Item, Item_Id);
862 else
863 Add_Item (Item_Id, Seen);
864 end if;
866 -- Detect illegal use of an input related to a null
867 -- output. Such input items cannot appear in other
868 -- input lists (SPARK RM 6.1.5(13)).
870 if Is_Input
871 and then Null_Output_Seen
872 and then Contains (All_Inputs_Seen, Item_Id)
873 then
874 SPARK_Msg_N
875 ("input of a null output list cannot appear in "
876 & "multiple input lists", Item);
877 end if;
879 -- Add an input or a self-referential output to the list
880 -- of all processed inputs.
882 if Is_Input or else Self_Ref then
883 Add_Item (Item_Id, All_Inputs_Seen);
884 end if;
886 -- State related checks (SPARK RM 6.1.5(3))
888 if Ekind (Item_Id) = E_Abstract_State then
889 if Has_Visible_Refinement (Item_Id) then
890 SPARK_Msg_NE
891 ("cannot mention state & in global refinement",
892 Item, Item_Id);
893 SPARK_Msg_N ("\use its constituents instead", Item);
894 return;
896 -- If the reference to the abstract state appears in
897 -- an enclosing package body that will eventually
898 -- refine the state, record the reference for future
899 -- checks.
901 else
902 Record_Possible_Body_Reference
903 (State_Id => Item_Id,
904 Ref => Item);
905 end if;
906 end if;
908 -- When the item renames an entire object, replace the
909 -- item with a reference to the object.
911 if Present (Renamed_Object (Entity (Item))) then
912 Rewrite (Item,
913 New_Occurrence_Of (Item_Id, Sloc (Item)));
914 Analyze (Item);
915 end if;
917 -- Add the entity of the current item to the list of
918 -- processed items.
920 if Ekind (Item_Id) = E_Abstract_State then
921 Add_Item (Item_Id, States_Seen);
922 end if;
924 if Ekind_In (Item_Id, E_Abstract_State, E_Variable)
925 and then Present (Encapsulating_State (Item_Id))
926 then
927 Add_Item (Item_Id, Constits_Seen);
928 end if;
930 -- All other input/output items are illegal
931 -- (SPARK RM 6.1.5(1)).
933 else
934 SPARK_Msg_N
935 ("item must denote parameter, variable, or state",
936 Item);
937 end if;
939 -- All other input/output items are illegal
940 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
942 else
943 Error_Msg_N
944 ("item must denote parameter, variable, or state", Item);
945 end if;
946 end if;
947 end Analyze_Input_Output;
949 -- Local variables
951 Inputs : Node_Id;
952 Output : Node_Id;
953 Self_Ref : Boolean;
955 Non_Null_Output_Seen : Boolean := False;
956 -- Flag used to check the legality of an output list
958 -- Start of processing for Analyze_Dependency_Clause
960 begin
961 Inputs := Expression (Clause);
962 Self_Ref := False;
964 -- An input list with a self-dependency appears as operator "+" where
965 -- the actuals inputs are the right operand.
967 if Nkind (Inputs) = N_Op_Plus then
968 Inputs := Right_Opnd (Inputs);
969 Self_Ref := True;
970 end if;
972 -- Process the output_list of a dependency_clause
974 Output := First (Choices (Clause));
975 while Present (Output) loop
976 Analyze_Input_Output
977 (Item => Output,
978 Is_Input => False,
979 Self_Ref => Self_Ref,
980 Top_Level => True,
981 Seen => All_Outputs_Seen,
982 Null_Seen => Null_Output_Seen,
983 Non_Null_Seen => Non_Null_Output_Seen);
985 Next (Output);
986 end loop;
988 -- Process the input_list of a dependency_clause
990 Analyze_Input_List (Inputs);
991 end Analyze_Dependency_Clause;
993 ---------------------------
994 -- Check_Function_Return --
995 ---------------------------
997 procedure Check_Function_Return is
998 begin
999 if Ekind (Spec_Id) = E_Function and then not Result_Seen then
1000 SPARK_Msg_NE
1001 ("result of & must appear in exactly one output list",
1002 N, Spec_Id);
1003 end if;
1004 end Check_Function_Return;
1006 ----------------
1007 -- Check_Role --
1008 ----------------
1010 procedure Check_Role
1011 (Item : Node_Id;
1012 Item_Id : Entity_Id;
1013 Is_Input : Boolean;
1014 Self_Ref : Boolean)
1016 procedure Find_Role
1017 (Item_Is_Input : out Boolean;
1018 Item_Is_Output : out Boolean);
1019 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1020 -- Item_Is_Output are set depending on the role.
1022 procedure Role_Error
1023 (Item_Is_Input : Boolean;
1024 Item_Is_Output : Boolean);
1025 -- Emit an error message concerning the incorrect use of Item in
1026 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1027 -- denote whether the item is an input and/or an output.
1029 ---------------
1030 -- Find_Role --
1031 ---------------
1033 procedure Find_Role
1034 (Item_Is_Input : out Boolean;
1035 Item_Is_Output : out Boolean)
1037 begin
1038 Item_Is_Input := False;
1039 Item_Is_Output := False;
1041 -- Abstract state cases
1043 if Ekind (Item_Id) = E_Abstract_State then
1045 -- When pragma Global is present, the mode of the state may be
1046 -- further constrained by setting a more restrictive mode.
1048 if Global_Seen then
1049 if Appears_In (Subp_Inputs, Item_Id) then
1050 Item_Is_Input := True;
1051 end if;
1053 if Appears_In (Subp_Outputs, Item_Id) then
1054 Item_Is_Output := True;
1055 end if;
1057 -- Otherwise the state has a default IN OUT mode
1059 else
1060 Item_Is_Input := True;
1061 Item_Is_Output := True;
1062 end if;
1064 -- Parameter cases
1066 elsif Ekind (Item_Id) = E_In_Parameter then
1067 Item_Is_Input := True;
1069 elsif Ekind (Item_Id) = E_In_Out_Parameter then
1070 Item_Is_Input := True;
1071 Item_Is_Output := True;
1073 elsif Ekind (Item_Id) = E_Out_Parameter then
1074 if Scope (Item_Id) = Spec_Id then
1076 -- An OUT parameter of the related subprogram has mode IN
1077 -- if its type is unconstrained or tagged because array
1078 -- bounds, discriminants or tags can be read.
1080 if Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1081 Item_Is_Input := True;
1082 end if;
1084 Item_Is_Output := True;
1086 -- An OUT parameter of an enclosing subprogram behaves as a
1087 -- read-write variable in which case the mode is IN OUT.
1089 else
1090 Item_Is_Input := True;
1091 Item_Is_Output := True;
1092 end if;
1094 -- Variable cases
1096 else pragma Assert (Ekind (Item_Id) = E_Variable);
1098 -- When pragma Global is present, the mode of the variable may
1099 -- be further constrained by setting a more restrictive mode.
1101 if Global_Seen then
1103 -- A variable has mode IN when its type is unconstrained or
1104 -- tagged because array bounds, discriminants or tags can be
1105 -- read.
1107 if Appears_In (Subp_Inputs, Item_Id)
1108 or else Is_Unconstrained_Or_Tagged_Item (Item_Id)
1109 then
1110 Item_Is_Input := True;
1111 end if;
1113 if Appears_In (Subp_Outputs, Item_Id) then
1114 Item_Is_Output := True;
1115 end if;
1117 -- Otherwise the variable has a default IN OUT mode
1119 else
1120 Item_Is_Input := True;
1121 Item_Is_Output := True;
1122 end if;
1123 end if;
1124 end Find_Role;
1126 ----------------
1127 -- Role_Error --
1128 ----------------
1130 procedure Role_Error
1131 (Item_Is_Input : Boolean;
1132 Item_Is_Output : Boolean)
1134 Error_Msg : Name_Id;
1136 begin
1137 Name_Len := 0;
1139 -- When the item is not part of the input and the output set of
1140 -- the related subprogram, then it appears as extra in pragma
1141 -- [Refined_]Depends.
1143 if not Item_Is_Input and then not Item_Is_Output then
1144 Add_Item_To_Name_Buffer (Item_Id);
1145 Add_Str_To_Name_Buffer
1146 (" & cannot appear in dependence relation");
1148 Error_Msg := Name_Find;
1149 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1151 Error_Msg_Name_1 := Chars (Subp_Id);
1152 SPARK_Msg_NE
1153 ("\& is not part of the input or output set of subprogram %",
1154 Item, Item_Id);
1156 -- The mode of the item and its role in pragma [Refined_]Depends
1157 -- are in conflict. Construct a detailed message explaining the
1158 -- illegality (SPARK RM 6.1.5(5-6)).
1160 else
1161 if Item_Is_Input then
1162 Add_Str_To_Name_Buffer ("read-only");
1163 else
1164 Add_Str_To_Name_Buffer ("write-only");
1165 end if;
1167 Add_Char_To_Name_Buffer (' ');
1168 Add_Item_To_Name_Buffer (Item_Id);
1169 Add_Str_To_Name_Buffer (" & cannot appear as ");
1171 if Item_Is_Input then
1172 Add_Str_To_Name_Buffer ("output");
1173 else
1174 Add_Str_To_Name_Buffer ("input");
1175 end if;
1177 Add_Str_To_Name_Buffer (" in dependence relation");
1178 Error_Msg := Name_Find;
1179 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1180 end if;
1181 end Role_Error;
1183 -- Local variables
1185 Item_Is_Input : Boolean;
1186 Item_Is_Output : Boolean;
1188 -- Start of processing for Check_Role
1190 begin
1191 Find_Role (Item_Is_Input, Item_Is_Output);
1193 -- Input item
1195 if Is_Input then
1196 if not Item_Is_Input then
1197 Role_Error (Item_Is_Input, Item_Is_Output);
1198 end if;
1200 -- Self-referential item
1202 elsif Self_Ref then
1203 if not Item_Is_Input or else not Item_Is_Output then
1204 Role_Error (Item_Is_Input, Item_Is_Output);
1205 end if;
1207 -- Output item
1209 elsif not Item_Is_Output then
1210 Role_Error (Item_Is_Input, Item_Is_Output);
1211 end if;
1212 end Check_Role;
1214 -----------------
1215 -- Check_Usage --
1216 -----------------
1218 procedure Check_Usage
1219 (Subp_Items : Elist_Id;
1220 Used_Items : Elist_Id;
1221 Is_Input : Boolean)
1223 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id);
1224 -- Emit an error concerning the illegal usage of an item
1226 -----------------
1227 -- Usage_Error --
1228 -----------------
1230 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id) is
1231 Error_Msg : Name_Id;
1233 begin
1234 -- Input case
1236 if Is_Input then
1238 -- Unconstrained and tagged items are not part of the explicit
1239 -- input set of the related subprogram, they do not have to be
1240 -- present in a dependence relation and should not be flagged
1241 -- (SPARK RM 6.1.5(8)).
1243 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1244 Name_Len := 0;
1246 Add_Item_To_Name_Buffer (Item_Id);
1247 Add_Str_To_Name_Buffer
1248 (" & must appear in at least one input dependence list");
1250 Error_Msg := Name_Find;
1251 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1252 end if;
1254 -- Output case (SPARK RM 6.1.5(10))
1256 else
1257 Name_Len := 0;
1259 Add_Item_To_Name_Buffer (Item_Id);
1260 Add_Str_To_Name_Buffer
1261 (" & must appear in exactly one output dependence list");
1263 Error_Msg := Name_Find;
1264 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1265 end if;
1266 end Usage_Error;
1268 -- Local variables
1270 Elmt : Elmt_Id;
1271 Item : Node_Id;
1272 Item_Id : Entity_Id;
1274 -- Start of processing for Check_Usage
1276 begin
1277 if No (Subp_Items) then
1278 return;
1279 end if;
1281 -- Each input or output of the subprogram must appear in a dependency
1282 -- relation.
1284 Elmt := First_Elmt (Subp_Items);
1285 while Present (Elmt) loop
1286 Item := Node (Elmt);
1288 if Nkind (Item) = N_Defining_Identifier then
1289 Item_Id := Item;
1290 else
1291 Item_Id := Entity_Of (Item);
1292 end if;
1294 -- The item does not appear in a dependency
1296 if Present (Item_Id)
1297 and then not Contains (Used_Items, Item_Id)
1298 then
1299 if Is_Formal (Item_Id) then
1300 Usage_Error (Item, Item_Id);
1302 -- States and global variables are not used properly only when
1303 -- the subprogram is subject to pragma Global.
1305 elsif Global_Seen then
1306 Usage_Error (Item, Item_Id);
1307 end if;
1308 end if;
1310 Next_Elmt (Elmt);
1311 end loop;
1312 end Check_Usage;
1314 ----------------------
1315 -- Normalize_Clause --
1316 ----------------------
1318 procedure Normalize_Clause (Clause : Node_Id) is
1319 procedure Create_Or_Modify_Clause
1320 (Output : Node_Id;
1321 Outputs : Node_Id;
1322 Inputs : Node_Id;
1323 After : Node_Id;
1324 In_Place : Boolean;
1325 Multiple : Boolean);
1326 -- Create a brand new clause to represent the self-reference or
1327 -- modify the input and/or output lists of an existing clause. Output
1328 -- denotes a self-referencial output. Outputs is the output list of a
1329 -- clause. Inputs is the input list of a clause. After denotes the
1330 -- clause after which the new clause is to be inserted. Flag In_Place
1331 -- should be set when normalizing the last output of an output list.
1332 -- Flag Multiple should be set when Output comes from a list with
1333 -- multiple items.
1335 -----------------------------
1336 -- Create_Or_Modify_Clause --
1337 -----------------------------
1339 procedure Create_Or_Modify_Clause
1340 (Output : Node_Id;
1341 Outputs : Node_Id;
1342 Inputs : Node_Id;
1343 After : Node_Id;
1344 In_Place : Boolean;
1345 Multiple : Boolean)
1347 procedure Propagate_Output
1348 (Output : Node_Id;
1349 Inputs : Node_Id);
1350 -- Handle the various cases of output propagation to the input
1351 -- list. Output denotes a self-referencial output item. Inputs is
1352 -- the input list of a clause.
1354 ----------------------
1355 -- Propagate_Output --
1356 ----------------------
1358 procedure Propagate_Output
1359 (Output : Node_Id;
1360 Inputs : Node_Id)
1362 function In_Input_List
1363 (Item : Entity_Id;
1364 Inputs : List_Id) return Boolean;
1365 -- Determine whether a particulat item appears in the input
1366 -- list of a clause.
1368 -------------------
1369 -- In_Input_List --
1370 -------------------
1372 function In_Input_List
1373 (Item : Entity_Id;
1374 Inputs : List_Id) return Boolean
1376 Elmt : Node_Id;
1378 begin
1379 Elmt := First (Inputs);
1380 while Present (Elmt) loop
1381 if Entity_Of (Elmt) = Item then
1382 return True;
1383 end if;
1385 Next (Elmt);
1386 end loop;
1388 return False;
1389 end In_Input_List;
1391 -- Local variables
1393 Output_Id : constant Entity_Id := Entity_Of (Output);
1394 Grouped : List_Id;
1396 -- Start of processing for Propagate_Output
1398 begin
1399 -- The clause is of the form:
1401 -- (Output =>+ null)
1403 -- Remove null input and replace it with a copy of the output:
1405 -- (Output => Output)
1407 if Nkind (Inputs) = N_Null then
1408 Rewrite (Inputs, New_Copy_Tree (Output));
1410 -- The clause is of the form:
1412 -- (Output =>+ (Input1, ..., InputN))
1414 -- Determine whether the output is not already mentioned in the
1415 -- input list and if not, add it to the list of inputs:
1417 -- (Output => (Output, Input1, ..., InputN))
1419 elsif Nkind (Inputs) = N_Aggregate then
1420 Grouped := Expressions (Inputs);
1422 if not In_Input_List
1423 (Item => Output_Id,
1424 Inputs => Grouped)
1425 then
1426 Prepend_To (Grouped, New_Copy_Tree (Output));
1427 end if;
1429 -- The clause is of the form:
1431 -- (Output =>+ Input)
1433 -- If the input does not mention the output, group the two
1434 -- together:
1436 -- (Output => (Output, Input))
1438 elsif Entity_Of (Inputs) /= Output_Id then
1439 Rewrite (Inputs,
1440 Make_Aggregate (Loc,
1441 Expressions => New_List (
1442 New_Copy_Tree (Output),
1443 New_Copy_Tree (Inputs))));
1444 end if;
1445 end Propagate_Output;
1447 -- Local variables
1449 Loc : constant Source_Ptr := Sloc (Clause);
1450 New_Clause : Node_Id;
1452 -- Start of processing for Create_Or_Modify_Clause
1454 begin
1455 -- A null output depending on itself does not require any
1456 -- normalization.
1458 if Nkind (Output) = N_Null then
1459 return;
1461 -- A function result cannot depend on itself because it cannot
1462 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1464 elsif Is_Attribute_Result (Output) then
1465 SPARK_Msg_N ("function result cannot depend on itself", Output);
1466 return;
1467 end if;
1469 -- When performing the transformation in place, simply add the
1470 -- output to the list of inputs (if not already there). This case
1471 -- arises when dealing with the last output of an output list -
1472 -- we perform the normalization in place to avoid generating a
1473 -- malformed tree.
1475 if In_Place then
1476 Propagate_Output (Output, Inputs);
1478 -- A list with multiple outputs is slowly trimmed until only
1479 -- one element remains. When this happens, replace aggregate
1480 -- with the element itself.
1482 if Multiple then
1483 Remove (Output);
1484 Rewrite (Outputs, Output);
1485 end if;
1487 -- Default case
1489 else
1490 -- Unchain the output from its output list as it will appear in
1491 -- a new clause. Note that we cannot simply rewrite the output
1492 -- as null because this will violate the semantics of pragma
1493 -- Depends.
1495 Remove (Output);
1497 -- Generate a new clause of the form:
1498 -- (Output => Inputs)
1500 New_Clause :=
1501 Make_Component_Association (Loc,
1502 Choices => New_List (Output),
1503 Expression => New_Copy_Tree (Inputs));
1505 -- The new clause contains replicated content that has already
1506 -- been analyzed. There is not need to reanalyze it or
1507 -- renormalize it again.
1509 Set_Analyzed (New_Clause);
1511 Propagate_Output
1512 (Output => First (Choices (New_Clause)),
1513 Inputs => Expression (New_Clause));
1515 Insert_After (After, New_Clause);
1516 end if;
1517 end Create_Or_Modify_Clause;
1519 -- Local variables
1521 Outputs : constant Node_Id := First (Choices (Clause));
1522 Inputs : Node_Id;
1523 Last_Output : Node_Id;
1524 Next_Output : Node_Id;
1525 Output : Node_Id;
1527 -- Start of processing for Normalize_Clause
1529 begin
1530 -- A self-dependency appears as operator "+". Remove the "+" from the
1531 -- tree by moving the real inputs to their proper place.
1533 if Nkind (Expression (Clause)) = N_Op_Plus then
1534 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1535 Inputs := Expression (Clause);
1537 -- Multiple outputs appear as an aggregate
1539 if Nkind (Outputs) = N_Aggregate then
1540 Last_Output := Last (Expressions (Outputs));
1542 Output := First (Expressions (Outputs));
1543 while Present (Output) loop
1545 -- Normalization may remove an output from its list,
1546 -- preserve the subsequent output now.
1548 Next_Output := Next (Output);
1550 Create_Or_Modify_Clause
1551 (Output => Output,
1552 Outputs => Outputs,
1553 Inputs => Inputs,
1554 After => Clause,
1555 In_Place => Output = Last_Output,
1556 Multiple => True);
1558 Output := Next_Output;
1559 end loop;
1561 -- Solitary output
1563 else
1564 Create_Or_Modify_Clause
1565 (Output => Outputs,
1566 Outputs => Empty,
1567 Inputs => Inputs,
1568 After => Empty,
1569 In_Place => True,
1570 Multiple => False);
1571 end if;
1572 end if;
1573 end Normalize_Clause;
1575 -- Local variables
1577 Clause : Node_Id;
1578 Deps : Node_Id;
1579 Errors : Nat;
1580 Last_Clause : Node_Id;
1581 Subp_Decl : Node_Id;
1583 Restore_Scope : Boolean := False;
1584 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
1586 -- Start of processing for Analyze_Depends_In_Decl_Part
1588 begin
1589 Set_Analyzed (N);
1591 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
1592 Subp_Id := Defining_Entity (Subp_Decl);
1593 Deps := Expression (Get_Argument (N, Subp_Id));
1595 -- The logic in this routine is used to analyze both pragma Depends and
1596 -- pragma Refined_Depends since they have the same syntax and base
1597 -- semantics. Find the entity of the corresponding spec when analyzing
1598 -- Refined_Depends.
1600 Spec_Id := Corresponding_Spec_Of (Subp_Decl);
1602 -- Empty dependency list
1604 if Nkind (Deps) = N_Null then
1606 -- Gather all states, variables and formal parameters that the
1607 -- subprogram may depend on. These items are obtained from the
1608 -- parameter profile or pragma [Refined_]Global (if available).
1610 Collect_Subprogram_Inputs_Outputs
1611 (Subp_Id => Subp_Id,
1612 Subp_Inputs => Subp_Inputs,
1613 Subp_Outputs => Subp_Outputs,
1614 Global_Seen => Global_Seen);
1616 -- Verify that every input or output of the subprogram appear in a
1617 -- dependency.
1619 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1620 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1621 Check_Function_Return;
1623 -- Dependency clauses appear as component associations of an aggregate
1625 elsif Nkind (Deps) = N_Aggregate then
1627 -- Do not attempt to perform analysis of a syntactically illegal
1628 -- clause as this will lead to misleading errors.
1630 if Has_Extra_Parentheses (Deps) then
1631 return;
1632 end if;
1634 if Present (Component_Associations (Deps)) then
1635 Last_Clause := Last (Component_Associations (Deps));
1637 -- Gather all states, variables and formal parameters that the
1638 -- subprogram may depend on. These items are obtained from the
1639 -- parameter profile or pragma [Refined_]Global (if available).
1641 Collect_Subprogram_Inputs_Outputs
1642 (Subp_Id => Subp_Id,
1643 Subp_Inputs => Subp_Inputs,
1644 Subp_Outputs => Subp_Outputs,
1645 Global_Seen => Global_Seen);
1647 -- Ensure that the formal parameters are visible when analyzing
1648 -- all clauses. This falls out of the general rule of aspects
1649 -- pertaining to subprogram declarations. Skip the installation
1650 -- for subprogram bodies because the formals are already visible.
1652 if not In_Open_Scopes (Spec_Id) then
1653 Restore_Scope := True;
1654 Push_Scope (Spec_Id);
1656 if Is_Generic_Subprogram (Spec_Id) then
1657 Install_Generic_Formals (Spec_Id);
1658 else
1659 Install_Formals (Spec_Id);
1660 end if;
1661 end if;
1663 Clause := First (Component_Associations (Deps));
1664 while Present (Clause) loop
1665 Errors := Serious_Errors_Detected;
1667 -- Normalization may create extra clauses that contain
1668 -- replicated input and output names. There is no need to
1669 -- reanalyze them.
1671 if not Analyzed (Clause) then
1672 Set_Analyzed (Clause);
1674 Analyze_Dependency_Clause
1675 (Clause => Clause,
1676 Is_Last => Clause = Last_Clause);
1677 end if;
1679 -- Do not normalize a clause if errors were detected (count
1680 -- of Serious_Errors has increased) because the inputs and/or
1681 -- outputs may denote illegal items. Normalization is disabled
1682 -- in ASIS mode as it alters the tree by introducing new nodes
1683 -- similar to expansion.
1685 if Serious_Errors_Detected = Errors and then not ASIS_Mode then
1686 Normalize_Clause (Clause);
1687 end if;
1689 Next (Clause);
1690 end loop;
1692 if Restore_Scope then
1693 End_Scope;
1694 end if;
1696 -- Verify that every input or output of the subprogram appear in a
1697 -- dependency.
1699 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1700 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1701 Check_Function_Return;
1703 -- The dependency list is malformed. This is a syntax error, always
1704 -- report.
1706 else
1707 Error_Msg_N ("malformed dependency relation", Deps);
1708 return;
1709 end if;
1711 -- The top level dependency relation is malformed. This is a syntax
1712 -- error, always report.
1714 else
1715 Error_Msg_N ("malformed dependency relation", Deps);
1716 return;
1717 end if;
1719 -- Ensure that a state and a corresponding constituent do not appear
1720 -- together in pragma [Refined_]Depends.
1722 Check_State_And_Constituent_Use
1723 (States => States_Seen,
1724 Constits => Constits_Seen,
1725 Context => N);
1726 end Analyze_Depends_In_Decl_Part;
1728 --------------------------------------------
1729 -- Analyze_External_Property_In_Decl_Part --
1730 --------------------------------------------
1732 procedure Analyze_External_Property_In_Decl_Part
1733 (N : Node_Id;
1734 Expr_Val : out Boolean)
1736 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
1737 Obj_Id : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
1738 Expr : constant Node_Id := Get_Pragma_Arg (Next (Arg1));
1740 begin
1741 Error_Msg_Name_1 := Pragma_Name (N);
1743 -- An external property pragma must apply to an effectively volatile
1744 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
1745 -- The check is performed at the end of the declarative region due to a
1746 -- possible out-of-order arrangement of pragmas:
1748 -- Obj : ...;
1749 -- pragma Async_Readers (Obj);
1750 -- pragma Volatile (Obj);
1752 if not Is_Effectively_Volatile (Obj_Id) then
1753 SPARK_Msg_N
1754 ("external property % must apply to a volatile object", N);
1755 end if;
1757 -- Ensure that the Boolean expression (if present) is static. A missing
1758 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
1760 Expr_Val := True;
1762 if Present (Expr) then
1763 Analyze_And_Resolve (Expr, Standard_Boolean);
1765 if Is_OK_Static_Expression (Expr) then
1766 Expr_Val := Is_True (Expr_Value (Expr));
1767 else
1768 SPARK_Msg_N ("expression of % must be static", Expr);
1769 end if;
1770 end if;
1771 end Analyze_External_Property_In_Decl_Part;
1773 ---------------------------------
1774 -- Analyze_Global_In_Decl_Part --
1775 ---------------------------------
1777 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
1778 Constits_Seen : Elist_Id := No_Elist;
1779 -- A list containing the entities of all constituents processed so far.
1780 -- It aids in detecting illegal usage of a state and a corresponding
1781 -- constituent in pragma [Refinde_]Global.
1783 Seen : Elist_Id := No_Elist;
1784 -- A list containing the entities of all the items processed so far. It
1785 -- plays a role in detecting distinct entities.
1787 Spec_Id : Entity_Id;
1788 -- The entity of the subprogram subject to pragma [Refined_]Global
1790 States_Seen : Elist_Id := No_Elist;
1791 -- A list containing the entities of all states processed so far. It
1792 -- helps in detecting illegal usage of a state and a corresponding
1793 -- constituent in pragma [Refined_]Global.
1795 Subp_Id : Entity_Id;
1796 -- The entity of the subprogram [body or stub] subject to pragma
1797 -- [Refined_]Global.
1799 In_Out_Seen : Boolean := False;
1800 Input_Seen : Boolean := False;
1801 Output_Seen : Boolean := False;
1802 Proof_Seen : Boolean := False;
1803 -- Flags used to verify the consistency of modes
1805 procedure Analyze_Global_List
1806 (List : Node_Id;
1807 Global_Mode : Name_Id := Name_Input);
1808 -- Verify the legality of a single global list declaration. Global_Mode
1809 -- denotes the current mode in effect.
1811 -------------------------
1812 -- Analyze_Global_List --
1813 -------------------------
1815 procedure Analyze_Global_List
1816 (List : Node_Id;
1817 Global_Mode : Name_Id := Name_Input)
1819 procedure Analyze_Global_Item
1820 (Item : Node_Id;
1821 Global_Mode : Name_Id);
1822 -- Verify the legality of a single global item declaration.
1823 -- Global_Mode denotes the current mode in effect.
1825 procedure Check_Duplicate_Mode
1826 (Mode : Node_Id;
1827 Status : in out Boolean);
1828 -- Flag Status denotes whether a particular mode has been seen while
1829 -- processing a global list. This routine verifies that Mode is not a
1830 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
1832 procedure Check_Mode_Restriction_In_Enclosing_Context
1833 (Item : Node_Id;
1834 Item_Id : Entity_Id);
1835 -- Verify that an item of mode In_Out or Output does not appear as an
1836 -- input in the Global aspect of an enclosing subprogram. If this is
1837 -- the case, emit an error. Item and Item_Id are respectively the
1838 -- item and its entity.
1840 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
1841 -- Mode denotes either In_Out or Output. Depending on the kind of the
1842 -- related subprogram, emit an error if those two modes apply to a
1843 -- function (SPARK RM 6.1.4(10)).
1845 -------------------------
1846 -- Analyze_Global_Item --
1847 -------------------------
1849 procedure Analyze_Global_Item
1850 (Item : Node_Id;
1851 Global_Mode : Name_Id)
1853 Item_Id : Entity_Id;
1855 begin
1856 -- Detect one of the following cases
1858 -- with Global => (null, Name)
1859 -- with Global => (Name_1, null, Name_2)
1860 -- with Global => (Name, null)
1862 if Nkind (Item) = N_Null then
1863 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
1864 return;
1865 end if;
1867 Analyze (Item);
1868 Resolve_State (Item);
1870 -- Find the entity of the item. If this is a renaming, climb the
1871 -- renaming chain to reach the root object. Renamings of non-
1872 -- entire objects do not yield an entity (Empty).
1874 Item_Id := Entity_Of (Item);
1876 if Present (Item_Id) then
1878 -- A global item may denote a formal parameter of an enclosing
1879 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
1880 -- provide a better error diagnostic.
1882 if Is_Formal (Item_Id) then
1883 if Scope (Item_Id) = Spec_Id then
1884 SPARK_Msg_NE
1885 ("global item cannot reference parameter of subprogram",
1886 Item, Spec_Id);
1887 return;
1888 end if;
1890 -- A constant cannot act as a global item (SPARK RM 6.1.4(7)).
1891 -- Do this check first to provide a better error diagnostic.
1893 elsif Ekind (Item_Id) = E_Constant then
1894 SPARK_Msg_N ("global item cannot denote a constant", Item);
1896 -- A formal object may act as a global item inside a generic
1898 elsif Is_Formal_Object (Item_Id) then
1899 null;
1901 -- The only legal references are those to abstract states and
1902 -- variables (SPARK RM 6.1.4(4)).
1904 elsif not Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
1905 SPARK_Msg_N
1906 ("global item must denote variable or state", Item);
1907 return;
1908 end if;
1910 -- State related checks
1912 if Ekind (Item_Id) = E_Abstract_State then
1914 -- An abstract state with visible refinement cannot appear
1915 -- in pragma [Refined_]Global as its place must be taken by
1916 -- some of its constituents (SPARK RM 6.1.4(8)).
1918 if Has_Visible_Refinement (Item_Id) then
1919 SPARK_Msg_NE
1920 ("cannot mention state & in global refinement",
1921 Item, Item_Id);
1922 SPARK_Msg_N ("\use its constituents instead", Item);
1923 return;
1925 -- If the reference to the abstract state appears in an
1926 -- enclosing package body that will eventually refine the
1927 -- state, record the reference for future checks.
1929 else
1930 Record_Possible_Body_Reference
1931 (State_Id => Item_Id,
1932 Ref => Item);
1933 end if;
1935 -- Variable related checks. These are only relevant when
1936 -- SPARK_Mode is on as they are not standard Ada legality
1937 -- rules.
1939 elsif SPARK_Mode = On
1940 and then Is_Effectively_Volatile (Item_Id)
1941 then
1942 -- An effectively volatile object cannot appear as a global
1943 -- item of a function (SPARK RM 7.1.3(9)).
1945 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
1946 Error_Msg_NE
1947 ("volatile object & cannot act as global item of a "
1948 & "function", Item, Item_Id);
1949 return;
1951 -- An effectively volatile object with external property
1952 -- Effective_Reads set to True must have mode Output or
1953 -- In_Out.
1955 elsif Effective_Reads_Enabled (Item_Id)
1956 and then Global_Mode = Name_Input
1957 then
1958 Error_Msg_NE
1959 ("volatile object & with property Effective_Reads must "
1960 & "have mode In_Out or Output (SPARK RM 7.1.3(11))",
1961 Item, Item_Id);
1962 return;
1963 end if;
1964 end if;
1966 -- When the item renames an entire object, replace the item
1967 -- with a reference to the object.
1969 if Present (Renamed_Object (Entity (Item))) then
1970 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
1971 Analyze (Item);
1972 end if;
1974 -- Some form of illegal construct masquerading as a name
1975 -- (SPARK RM 6.1.4(4)).
1977 else
1978 Error_Msg_N ("global item must denote variable or state", Item);
1979 return;
1980 end if;
1982 -- Verify that an output does not appear as an input in an
1983 -- enclosing subprogram.
1985 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
1986 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
1987 end if;
1989 -- The same entity might be referenced through various way.
1990 -- Check the entity of the item rather than the item itself
1991 -- (SPARK RM 6.1.4(11)).
1993 if Contains (Seen, Item_Id) then
1994 SPARK_Msg_N ("duplicate global item", Item);
1996 -- Add the entity of the current item to the list of processed
1997 -- items.
1999 else
2000 Add_Item (Item_Id, Seen);
2002 if Ekind (Item_Id) = E_Abstract_State then
2003 Add_Item (Item_Id, States_Seen);
2004 end if;
2006 if Ekind_In (Item_Id, E_Abstract_State, E_Variable)
2007 and then Present (Encapsulating_State (Item_Id))
2008 then
2009 Add_Item (Item_Id, Constits_Seen);
2010 end if;
2011 end if;
2012 end Analyze_Global_Item;
2014 --------------------------
2015 -- Check_Duplicate_Mode --
2016 --------------------------
2018 procedure Check_Duplicate_Mode
2019 (Mode : Node_Id;
2020 Status : in out Boolean)
2022 begin
2023 if Status then
2024 SPARK_Msg_N ("duplicate global mode", Mode);
2025 end if;
2027 Status := True;
2028 end Check_Duplicate_Mode;
2030 -------------------------------------------------
2031 -- Check_Mode_Restriction_In_Enclosing_Context --
2032 -------------------------------------------------
2034 procedure Check_Mode_Restriction_In_Enclosing_Context
2035 (Item : Node_Id;
2036 Item_Id : Entity_Id)
2038 Context : Entity_Id;
2039 Dummy : Boolean;
2040 Inputs : Elist_Id := No_Elist;
2041 Outputs : Elist_Id := No_Elist;
2043 begin
2044 -- Traverse the scope stack looking for enclosing subprograms
2045 -- subject to pragma [Refined_]Global.
2047 Context := Scope (Subp_Id);
2048 while Present (Context) and then Context /= Standard_Standard loop
2049 if Is_Subprogram (Context)
2050 and then
2051 (Present (Get_Pragma (Context, Pragma_Global))
2052 or else
2053 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2054 then
2055 Collect_Subprogram_Inputs_Outputs
2056 (Subp_Id => Context,
2057 Subp_Inputs => Inputs,
2058 Subp_Outputs => Outputs,
2059 Global_Seen => Dummy);
2061 -- The item is classified as In_Out or Output but appears as
2062 -- an Input in an enclosing subprogram (SPARK RM 6.1.4(12)).
2064 if Appears_In (Inputs, Item_Id)
2065 and then not Appears_In (Outputs, Item_Id)
2066 then
2067 SPARK_Msg_NE
2068 ("global item & cannot have mode In_Out or Output",
2069 Item, Item_Id);
2070 SPARK_Msg_NE
2071 ("\item already appears as input of subprogram &",
2072 Item, Context);
2074 -- Stop the traversal once an error has been detected
2076 exit;
2077 end if;
2078 end if;
2080 Context := Scope (Context);
2081 end loop;
2082 end Check_Mode_Restriction_In_Enclosing_Context;
2084 ----------------------------------------
2085 -- Check_Mode_Restriction_In_Function --
2086 ----------------------------------------
2088 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2089 begin
2090 if Ekind (Spec_Id) = E_Function then
2091 SPARK_Msg_N
2092 ("global mode & is not applicable to functions", Mode);
2093 end if;
2094 end Check_Mode_Restriction_In_Function;
2096 -- Local variables
2098 Assoc : Node_Id;
2099 Item : Node_Id;
2100 Mode : Node_Id;
2102 -- Start of processing for Analyze_Global_List
2104 begin
2105 if Nkind (List) = N_Null then
2106 Set_Analyzed (List);
2108 -- Single global item declaration
2110 elsif Nkind_In (List, N_Expanded_Name,
2111 N_Identifier,
2112 N_Selected_Component)
2113 then
2114 Analyze_Global_Item (List, Global_Mode);
2116 -- Simple global list or moded global list declaration
2118 elsif Nkind (List) = N_Aggregate then
2119 Set_Analyzed (List);
2121 -- The declaration of a simple global list appear as a collection
2122 -- of expressions.
2124 if Present (Expressions (List)) then
2125 if Present (Component_Associations (List)) then
2126 SPARK_Msg_N
2127 ("cannot mix moded and non-moded global lists", List);
2128 end if;
2130 Item := First (Expressions (List));
2131 while Present (Item) loop
2132 Analyze_Global_Item (Item, Global_Mode);
2134 Next (Item);
2135 end loop;
2137 -- The declaration of a moded global list appears as a collection
2138 -- of component associations where individual choices denote
2139 -- modes.
2141 elsif Present (Component_Associations (List)) then
2142 if Present (Expressions (List)) then
2143 SPARK_Msg_N
2144 ("cannot mix moded and non-moded global lists", List);
2145 end if;
2147 Assoc := First (Component_Associations (List));
2148 while Present (Assoc) loop
2149 Mode := First (Choices (Assoc));
2151 if Nkind (Mode) = N_Identifier then
2152 if Chars (Mode) = Name_In_Out then
2153 Check_Duplicate_Mode (Mode, In_Out_Seen);
2154 Check_Mode_Restriction_In_Function (Mode);
2156 elsif Chars (Mode) = Name_Input then
2157 Check_Duplicate_Mode (Mode, Input_Seen);
2159 elsif Chars (Mode) = Name_Output then
2160 Check_Duplicate_Mode (Mode, Output_Seen);
2161 Check_Mode_Restriction_In_Function (Mode);
2163 elsif Chars (Mode) = Name_Proof_In then
2164 Check_Duplicate_Mode (Mode, Proof_Seen);
2166 else
2167 SPARK_Msg_N ("invalid mode selector", Mode);
2168 end if;
2170 else
2171 SPARK_Msg_N ("invalid mode selector", Mode);
2172 end if;
2174 -- Items in a moded list appear as a collection of
2175 -- expressions. Reuse the existing machinery to analyze
2176 -- them.
2178 Analyze_Global_List
2179 (List => Expression (Assoc),
2180 Global_Mode => Chars (Mode));
2182 Next (Assoc);
2183 end loop;
2185 -- Invalid tree
2187 else
2188 raise Program_Error;
2189 end if;
2191 -- Any other attempt to declare a global item is illegal. This is a
2192 -- syntax error, always report.
2194 else
2195 Error_Msg_N ("malformed global list", List);
2196 end if;
2197 end Analyze_Global_List;
2199 -- Local variables
2201 Items : Node_Id;
2202 Subp_Decl : Node_Id;
2204 Restore_Scope : Boolean := False;
2205 -- Set True if we do a Push_Scope requiring a Pop_Scope on exit
2207 -- Start of processing for Analyze_Global_In_Decl_Part
2209 begin
2210 Set_Analyzed (N);
2212 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
2213 Subp_Id := Defining_Entity (Subp_Decl);
2214 Items := Expression (Get_Argument (N, Subp_Id));
2216 -- The logic in this routine is used to analyze both pragma Global and
2217 -- pragma Refined_Global since they have the same syntax and base
2218 -- semantics. Find the entity of the corresponding spec when analyzing
2219 -- Refined_Global.
2221 Spec_Id := Corresponding_Spec_Of (Subp_Decl);
2223 -- There is nothing to be done for a null global list
2225 if Nkind (Items) = N_Null then
2226 Set_Analyzed (Items);
2228 -- Analyze the various forms of global lists and items. Note that some
2229 -- of these may be malformed in which case the analysis emits error
2230 -- messages.
2232 else
2233 -- Ensure that the formal parameters are visible when processing an
2234 -- item. This falls out of the general rule of aspects pertaining to
2235 -- subprogram declarations.
2237 if not In_Open_Scopes (Spec_Id) then
2238 Restore_Scope := True;
2239 Push_Scope (Spec_Id);
2241 if Is_Generic_Subprogram (Spec_Id) then
2242 Install_Generic_Formals (Spec_Id);
2243 else
2244 Install_Formals (Spec_Id);
2245 end if;
2246 end if;
2248 Analyze_Global_List (Items);
2250 if Restore_Scope then
2251 End_Scope;
2252 end if;
2253 end if;
2255 -- Ensure that a state and a corresponding constituent do not appear
2256 -- together in pragma [Refined_]Global.
2258 Check_State_And_Constituent_Use
2259 (States => States_Seen,
2260 Constits => Constits_Seen,
2261 Context => N);
2262 end Analyze_Global_In_Decl_Part;
2264 --------------------------------------------
2265 -- Analyze_Initial_Condition_In_Decl_Part --
2266 --------------------------------------------
2268 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2269 Expr : constant Node_Id := Expression (Get_Argument (N));
2271 begin
2272 Set_Analyzed (N);
2274 -- The expression is preanalyzed because it has not been moved to its
2275 -- final place yet. A direct analysis may generate side effects and this
2276 -- is not desired at this point.
2278 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2279 end Analyze_Initial_Condition_In_Decl_Part;
2281 --------------------------------------
2282 -- Analyze_Initializes_In_Decl_Part --
2283 --------------------------------------
2285 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2286 Pack_Spec : constant Node_Id := Parent (N);
2287 Pack_Id : constant Entity_Id := Defining_Entity (Parent (Pack_Spec));
2289 Constits_Seen : Elist_Id := No_Elist;
2290 -- A list containing the entities of all constituents processed so far.
2291 -- It aids in detecting illegal usage of a state and a corresponding
2292 -- constituent in pragma Initializes.
2294 Items_Seen : Elist_Id := No_Elist;
2295 -- A list of all initialization items processed so far. This list is
2296 -- used to detect duplicate items.
2298 Non_Null_Seen : Boolean := False;
2299 Null_Seen : Boolean := False;
2300 -- Flags used to check the legality of a null initialization list
2302 States_And_Vars : Elist_Id := No_Elist;
2303 -- A list of all abstract states and variables declared in the visible
2304 -- declarations of the related package. This list is used to detect the
2305 -- legality of initialization items.
2307 States_Seen : Elist_Id := No_Elist;
2308 -- A list containing the entities of all states processed so far. It
2309 -- helps in detecting illegal usage of a state and a corresponding
2310 -- constituent in pragma Initializes.
2312 procedure Analyze_Initialization_Item (Item : Node_Id);
2313 -- Verify the legality of a single initialization item
2315 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2316 -- Verify the legality of a single initialization item followed by a
2317 -- list of input items.
2319 procedure Collect_States_And_Variables;
2320 -- Inspect the visible declarations of the related package and gather
2321 -- the entities of all abstract states and variables in States_And_Vars.
2323 ---------------------------------
2324 -- Analyze_Initialization_Item --
2325 ---------------------------------
2327 procedure Analyze_Initialization_Item (Item : Node_Id) is
2328 Item_Id : Entity_Id;
2330 begin
2331 -- Null initialization list
2333 if Nkind (Item) = N_Null then
2334 if Null_Seen then
2335 SPARK_Msg_N ("multiple null initializations not allowed", Item);
2337 elsif Non_Null_Seen then
2338 SPARK_Msg_N
2339 ("cannot mix null and non-null initialization items", Item);
2340 else
2341 Null_Seen := True;
2342 end if;
2344 -- Initialization item
2346 else
2347 Non_Null_Seen := True;
2349 if Null_Seen then
2350 SPARK_Msg_N
2351 ("cannot mix null and non-null initialization items", Item);
2352 end if;
2354 Analyze (Item);
2355 Resolve_State (Item);
2357 if Is_Entity_Name (Item) then
2358 Item_Id := Entity_Of (Item);
2360 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
2362 -- The state or variable must be declared in the visible
2363 -- declarations of the package (SPARK RM 7.1.5(7)).
2365 if not Contains (States_And_Vars, Item_Id) then
2366 Error_Msg_Name_1 := Chars (Pack_Id);
2367 SPARK_Msg_NE
2368 ("initialization item & must appear in the visible "
2369 & "declarations of package %", Item, Item_Id);
2371 -- Detect a duplicate use of the same initialization item
2372 -- (SPARK RM 7.1.5(5)).
2374 elsif Contains (Items_Seen, Item_Id) then
2375 SPARK_Msg_N ("duplicate initialization item", Item);
2377 -- The item is legal, add it to the list of processed states
2378 -- and variables.
2380 else
2381 Add_Item (Item_Id, Items_Seen);
2383 if Ekind (Item_Id) = E_Abstract_State then
2384 Add_Item (Item_Id, States_Seen);
2385 end if;
2387 if Present (Encapsulating_State (Item_Id)) then
2388 Add_Item (Item_Id, Constits_Seen);
2389 end if;
2390 end if;
2392 -- The item references something that is not a state or a
2393 -- variable (SPARK RM 7.1.5(3)).
2395 else
2396 SPARK_Msg_N
2397 ("initialization item must denote variable or state",
2398 Item);
2399 end if;
2401 -- Some form of illegal construct masquerading as a name
2402 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2404 else
2405 Error_Msg_N
2406 ("initialization item must denote variable or state", Item);
2407 end if;
2408 end if;
2409 end Analyze_Initialization_Item;
2411 ---------------------------------------------
2412 -- Analyze_Initialization_Item_With_Inputs --
2413 ---------------------------------------------
2415 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2416 Inputs_Seen : Elist_Id := No_Elist;
2417 -- A list of all inputs processed so far. This list is used to detect
2418 -- duplicate uses of an input.
2420 Non_Null_Seen : Boolean := False;
2421 Null_Seen : Boolean := False;
2422 -- Flags used to check the legality of an input list
2424 procedure Analyze_Input_Item (Input : Node_Id);
2425 -- Verify the legality of a single input item
2427 ------------------------
2428 -- Analyze_Input_Item --
2429 ------------------------
2431 procedure Analyze_Input_Item (Input : Node_Id) is
2432 Input_Id : Entity_Id;
2434 begin
2435 -- Null input list
2437 if Nkind (Input) = N_Null then
2438 if Null_Seen then
2439 SPARK_Msg_N
2440 ("multiple null initializations not allowed", Item);
2442 elsif Non_Null_Seen then
2443 SPARK_Msg_N
2444 ("cannot mix null and non-null initialization item", Item);
2445 else
2446 Null_Seen := True;
2447 end if;
2449 -- Input item
2451 else
2452 Non_Null_Seen := True;
2454 if Null_Seen then
2455 SPARK_Msg_N
2456 ("cannot mix null and non-null initialization item", Item);
2457 end if;
2459 Analyze (Input);
2460 Resolve_State (Input);
2462 if Is_Entity_Name (Input) then
2463 Input_Id := Entity_Of (Input);
2465 if Ekind_In (Input_Id, E_Abstract_State,
2466 E_In_Parameter,
2467 E_In_Out_Parameter,
2468 E_Out_Parameter,
2469 E_Variable)
2470 then
2471 -- The input cannot denote states or variables declared
2472 -- within the related package.
2474 if Within_Scope (Input_Id, Current_Scope) then
2475 Error_Msg_Name_1 := Chars (Pack_Id);
2476 SPARK_Msg_NE
2477 ("input item & cannot denote a visible variable or "
2478 & "state of package % (SPARK RM 7.1.5(4))",
2479 Input, Input_Id);
2481 -- Detect a duplicate use of the same input item
2482 -- (SPARK RM 7.1.5(5)).
2484 elsif Contains (Inputs_Seen, Input_Id) then
2485 SPARK_Msg_N ("duplicate input item", Input);
2487 -- Input is legal, add it to the list of processed inputs
2489 else
2490 Add_Item (Input_Id, Inputs_Seen);
2492 if Ekind (Input_Id) = E_Abstract_State then
2493 Add_Item (Input_Id, States_Seen);
2494 end if;
2496 if Ekind_In (Input_Id, E_Abstract_State, E_Variable)
2497 and then Present (Encapsulating_State (Input_Id))
2498 then
2499 Add_Item (Input_Id, Constits_Seen);
2500 end if;
2501 end if;
2503 -- The input references something that is not a state or a
2504 -- variable (SPARK RM 7.1.5(3)).
2506 else
2507 SPARK_Msg_N
2508 ("input item must denote variable or state", Input);
2509 end if;
2511 -- Some form of illegal construct masquerading as a name
2512 -- (SPARK RM 7.1.5(3)).
2514 else
2515 SPARK_Msg_N
2516 ("input item must denote variable or state", Input);
2517 end if;
2518 end if;
2519 end Analyze_Input_Item;
2521 -- Local variables
2523 Inputs : constant Node_Id := Expression (Item);
2524 Elmt : Node_Id;
2525 Input : Node_Id;
2527 Name_Seen : Boolean := False;
2528 -- A flag used to detect multiple item names
2530 -- Start of processing for Analyze_Initialization_Item_With_Inputs
2532 begin
2533 -- Inspect the name of an item with inputs
2535 Elmt := First (Choices (Item));
2536 while Present (Elmt) loop
2537 if Name_Seen then
2538 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
2539 else
2540 Name_Seen := True;
2541 Analyze_Initialization_Item (Elmt);
2542 end if;
2544 Next (Elmt);
2545 end loop;
2547 -- Multiple input items appear as an aggregate
2549 if Nkind (Inputs) = N_Aggregate then
2550 if Present (Expressions (Inputs)) then
2551 Input := First (Expressions (Inputs));
2552 while Present (Input) loop
2553 Analyze_Input_Item (Input);
2554 Next (Input);
2555 end loop;
2556 end if;
2558 if Present (Component_Associations (Inputs)) then
2559 SPARK_Msg_N
2560 ("inputs must appear in named association form", Inputs);
2561 end if;
2563 -- Single input item
2565 else
2566 Analyze_Input_Item (Inputs);
2567 end if;
2568 end Analyze_Initialization_Item_With_Inputs;
2570 ----------------------------------
2571 -- Collect_States_And_Variables --
2572 ----------------------------------
2574 procedure Collect_States_And_Variables is
2575 Decl : Node_Id;
2577 begin
2578 -- Collect the abstract states defined in the package (if any)
2580 if Present (Abstract_States (Pack_Id)) then
2581 States_And_Vars := New_Copy_Elist (Abstract_States (Pack_Id));
2582 end if;
2584 -- Collect all variables the appear in the visible declarations of
2585 -- the related package.
2587 if Present (Visible_Declarations (Pack_Spec)) then
2588 Decl := First (Visible_Declarations (Pack_Spec));
2589 while Present (Decl) loop
2590 if Nkind (Decl) = N_Object_Declaration
2591 and then Ekind (Defining_Entity (Decl)) = E_Variable
2592 and then Comes_From_Source (Decl)
2593 then
2594 Add_Item (Defining_Entity (Decl), States_And_Vars);
2595 end if;
2597 Next (Decl);
2598 end loop;
2599 end if;
2600 end Collect_States_And_Variables;
2602 -- Local variables
2604 Inits : constant Node_Id := Expression (Get_Argument (N));
2605 Init : Node_Id;
2607 -- Start of processing for Analyze_Initializes_In_Decl_Part
2609 begin
2610 Set_Analyzed (N);
2612 -- Nothing to do when the initialization list is empty
2614 if Nkind (Inits) = N_Null then
2615 return;
2616 end if;
2618 -- Single and multiple initialization clauses appear as an aggregate. If
2619 -- this is not the case, then either the parser or the analysis of the
2620 -- pragma failed to produce an aggregate.
2622 pragma Assert (Nkind (Inits) = N_Aggregate);
2624 -- Initialize the various lists used during analysis
2626 Collect_States_And_Variables;
2628 if Present (Expressions (Inits)) then
2629 Init := First (Expressions (Inits));
2630 while Present (Init) loop
2631 Analyze_Initialization_Item (Init);
2632 Next (Init);
2633 end loop;
2634 end if;
2636 if Present (Component_Associations (Inits)) then
2637 Init := First (Component_Associations (Inits));
2638 while Present (Init) loop
2639 Analyze_Initialization_Item_With_Inputs (Init);
2640 Next (Init);
2641 end loop;
2642 end if;
2644 -- Ensure that a state and a corresponding constituent do not appear
2645 -- together in pragma Initializes.
2647 Check_State_And_Constituent_Use
2648 (States => States_Seen,
2649 Constits => Constits_Seen,
2650 Context => N);
2651 end Analyze_Initializes_In_Decl_Part;
2653 --------------------
2654 -- Analyze_Pragma --
2655 --------------------
2657 procedure Analyze_Pragma (N : Node_Id) is
2658 Loc : constant Source_Ptr := Sloc (N);
2659 Prag_Id : Pragma_Id;
2661 Pname : Name_Id;
2662 -- Name of the source pragma, or name of the corresponding aspect for
2663 -- pragmas which originate in a source aspect. In the latter case, the
2664 -- name may be different from the pragma name.
2666 Pragma_Exit : exception;
2667 -- This exception is used to exit pragma processing completely. It
2668 -- is used when an error is detected, and no further processing is
2669 -- required. It is also used if an earlier error has left the tree in
2670 -- a state where the pragma should not be processed.
2672 Arg_Count : Nat;
2673 -- Number of pragma argument associations
2675 Arg1 : Node_Id;
2676 Arg2 : Node_Id;
2677 Arg3 : Node_Id;
2678 Arg4 : Node_Id;
2679 -- First four pragma arguments (pragma argument association nodes, or
2680 -- Empty if the corresponding argument does not exist).
2682 type Name_List is array (Natural range <>) of Name_Id;
2683 type Args_List is array (Natural range <>) of Node_Id;
2684 -- Types used for arguments to Check_Arg_Order and Gather_Associations
2686 -----------------------
2687 -- Local Subprograms --
2688 -----------------------
2690 procedure Acquire_Warning_Match_String (Arg : Node_Id);
2691 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
2692 -- get the given string argument, and place it in Name_Buffer, adding
2693 -- leading and trailing asterisks if they are not already present. The
2694 -- caller has already checked that Arg is a static string expression.
2696 procedure Ada_2005_Pragma;
2697 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
2698 -- Ada 95 mode, these are implementation defined pragmas, so should be
2699 -- caught by the No_Implementation_Pragmas restriction.
2701 procedure Ada_2012_Pragma;
2702 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
2703 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
2704 -- should be caught by the No_Implementation_Pragmas restriction.
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, variable 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_Pragma
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 Create_Generic_Template
2945 (Prag : Node_Id;
2946 Subp_Id : Entity_Id);
2947 -- Subsidiary routine to the processing of pragmas Contract_Cases,
2948 -- Depends, Global, Postcondition, Precondition and Test_Case. Create
2949 -- a generic template for pragma Prag when Prag is a source construct
2950 -- and the related context denoted by Subp_Id is a generic subprogram.
2952 procedure Ensure_Aggregate_Form (Arg : Node_Id);
2953 -- Subsidiary routine to the processing of pragmas Abstract_State,
2954 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
2955 -- Refined_Global and Refined_State. Transform argument Arg into
2956 -- an aggregate if not one already. N_Null is never transformed.
2957 -- Arg may denote an aspect specification or a pragma argument
2958 -- association.
2960 procedure Error_Pragma (Msg : String);
2961 pragma No_Return (Error_Pragma);
2962 -- Outputs error message for current pragma. The message contains a %
2963 -- that will be replaced with the pragma name, and the flag is placed
2964 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
2965 -- calls Fix_Error (see spec of that procedure for details).
2967 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
2968 pragma No_Return (Error_Pragma_Arg);
2969 -- Outputs error message for current pragma. The message may contain
2970 -- a % that will be replaced with the pragma name. The parameter Arg
2971 -- may either be a pragma argument association, in which case the flag
2972 -- is placed on the expression of this association, or an expression,
2973 -- in which case the flag is placed directly on the expression. The
2974 -- message is placed using Error_Msg_N, so the message may also contain
2975 -- an & insertion character which will reference the given Arg value.
2976 -- After placing the message, Pragma_Exit is raised. Note: this routine
2977 -- calls Fix_Error (see spec of that procedure for details).
2979 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
2980 pragma No_Return (Error_Pragma_Arg);
2981 -- Similar to above form of Error_Pragma_Arg except that two messages
2982 -- are provided, the second is a continuation comment starting with \.
2984 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
2985 pragma No_Return (Error_Pragma_Arg_Ident);
2986 -- Outputs error message for current pragma. The message may contain a %
2987 -- that will be replaced with the pragma name. The parameter Arg must be
2988 -- a pragma argument association with a non-empty identifier (i.e. its
2989 -- Chars field must be set), and the error message is placed on the
2990 -- identifier. The message is placed using Error_Msg_N so the message
2991 -- may also contain an & insertion character which will reference
2992 -- the identifier. After placing the message, Pragma_Exit is raised.
2993 -- Note: this routine calls Fix_Error (see spec of that procedure for
2994 -- details).
2996 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
2997 pragma No_Return (Error_Pragma_Ref);
2998 -- Outputs error message for current pragma. The message may contain
2999 -- a % that will be replaced with the pragma name. The parameter Ref
3000 -- must be an entity whose name can be referenced by & and sloc by #.
3001 -- After placing the message, Pragma_Exit is raised. Note: this routine
3002 -- calls Fix_Error (see spec of that procedure for details).
3004 function Find_Lib_Unit_Name return Entity_Id;
3005 -- Used for a library unit pragma to find the entity to which the
3006 -- library unit pragma applies, returns the entity found.
3008 procedure Find_Program_Unit_Name (Id : Node_Id);
3009 -- If the pragma is a compilation unit pragma, the id must denote the
3010 -- compilation unit in the same compilation, and the pragma must appear
3011 -- in the list of preceding or trailing pragmas. If it is a program
3012 -- unit pragma that is not a compilation unit pragma, then the
3013 -- identifier must be visible.
3015 function Find_Unique_Parameterless_Procedure
3016 (Name : Entity_Id;
3017 Arg : Node_Id) return Entity_Id;
3018 -- Used for a procedure pragma to find the unique parameterless
3019 -- procedure identified by Name, returns it if it exists, otherwise
3020 -- errors out and uses Arg as the pragma argument for the message.
3022 function Fix_Error (Msg : String) return String;
3023 -- This is called prior to issuing an error message. Msg is the normal
3024 -- error message issued in the pragma case. This routine checks for the
3025 -- case of a pragma coming from an aspect in the source, and returns a
3026 -- message suitable for the aspect case as follows:
3028 -- Each substring "pragma" is replaced by "aspect"
3030 -- If "argument of" is at the start of the error message text, it is
3031 -- replaced by "entity for".
3033 -- If "argument" is at the start of the error message text, it is
3034 -- replaced by "entity".
3036 -- So for example, "argument of pragma X must be discrete type"
3037 -- returns "entity for aspect X must be a discrete type".
3039 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
3040 -- be different from the pragma name). If the current pragma results
3041 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
3042 -- original pragma name.
3044 procedure Gather_Associations
3045 (Names : Name_List;
3046 Args : out Args_List);
3047 -- This procedure is used to gather the arguments for a pragma that
3048 -- permits arbitrary ordering of parameters using the normal rules
3049 -- for named and positional parameters. The Names argument is a list
3050 -- of Name_Id values that corresponds to the allowed pragma argument
3051 -- association identifiers in order. The result returned in Args is
3052 -- a list of corresponding expressions that are the pragma arguments.
3053 -- Note that this is a list of expressions, not of pragma argument
3054 -- associations (Gather_Associations has completely checked all the
3055 -- optional identifiers when it returns). An entry in Args is Empty
3056 -- on return if the corresponding argument is not present.
3058 procedure GNAT_Pragma;
3059 -- Called for all GNAT defined pragmas to check the relevant restriction
3060 -- (No_Implementation_Pragmas).
3062 function Is_Before_First_Decl
3063 (Pragma_Node : Node_Id;
3064 Decls : List_Id) return Boolean;
3065 -- Return True if Pragma_Node is before the first declarative item in
3066 -- Decls where Decls is the list of declarative items.
3068 function Is_Configuration_Pragma return Boolean;
3069 -- Determines if the placement of the current pragma is appropriate
3070 -- for a configuration pragma.
3072 function Is_In_Context_Clause return Boolean;
3073 -- Returns True if pragma appears within the context clause of a unit,
3074 -- and False for any other placement (does not generate any messages).
3076 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
3077 -- Analyzes the argument, and determines if it is a static string
3078 -- expression, returns True if so, False if non-static or not String.
3079 -- A special case is that a string literal returns True in Ada 83 mode
3080 -- (which has no such thing as static string expressions). Note that
3081 -- the call analyzes its argument, so this cannot be used for the case
3082 -- where an identifier might not be declared.
3084 procedure Pragma_Misplaced;
3085 pragma No_Return (Pragma_Misplaced);
3086 -- Issue fatal error message for misplaced pragma
3088 procedure Process_Atomic_Independent_Shared_Volatile;
3089 -- Common processing for pragmas Atomic, Independent, Shared, Volatile.
3090 -- Note that Shared is an obsolete Ada 83 pragma and treated as being
3091 -- identical in effect to pragma Atomic.
3093 procedure Process_Compile_Time_Warning_Or_Error;
3094 -- Common processing for Compile_Time_Error and Compile_Time_Warning
3096 procedure Process_Convention
3097 (C : out Convention_Id;
3098 Ent : out Entity_Id);
3099 -- Common processing for Convention, Interface, Import and Export.
3100 -- Checks first two arguments of pragma, and sets the appropriate
3101 -- convention value in the specified entity or entities. On return
3102 -- C is the convention, Ent is the referenced entity.
3104 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
3105 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
3106 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
3108 procedure Process_Extended_Import_Export_Object_Pragma
3109 (Arg_Internal : Node_Id;
3110 Arg_External : Node_Id;
3111 Arg_Size : Node_Id);
3112 -- Common processing for the pragmas Import/Export_Object. The three
3113 -- arguments correspond to the three named parameters of the pragmas. An
3114 -- argument is empty if the corresponding parameter is not present in
3115 -- the pragma.
3117 procedure Process_Extended_Import_Export_Internal_Arg
3118 (Arg_Internal : Node_Id := Empty);
3119 -- Common processing for all extended Import and Export pragmas. The
3120 -- argument is the pragma parameter for the Internal argument. If
3121 -- Arg_Internal is empty or inappropriate, an error message is posted.
3122 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
3123 -- set to identify the referenced entity.
3125 procedure Process_Extended_Import_Export_Subprogram_Pragma
3126 (Arg_Internal : Node_Id;
3127 Arg_External : Node_Id;
3128 Arg_Parameter_Types : Node_Id;
3129 Arg_Result_Type : Node_Id := Empty;
3130 Arg_Mechanism : Node_Id;
3131 Arg_Result_Mechanism : Node_Id := Empty);
3132 -- Common processing for all extended Import and Export pragmas applying
3133 -- to subprograms. The caller omits any arguments that do not apply to
3134 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
3135 -- only in the Import_Function and Export_Function cases). The argument
3136 -- names correspond to the allowed pragma association identifiers.
3138 procedure Process_Generic_List;
3139 -- Common processing for Share_Generic and Inline_Generic
3141 procedure Process_Import_Or_Interface;
3142 -- Common processing for Import or Interface
3144 procedure Process_Import_Predefined_Type;
3145 -- Processing for completing a type with pragma Import. This is used
3146 -- to declare types that match predefined C types, especially for cases
3147 -- without corresponding Ada predefined type.
3149 type Inline_Status is (Suppressed, Disabled, Enabled);
3150 -- Inline status of a subprogram, indicated as follows:
3151 -- Suppressed: inlining is suppressed for the subprogram
3152 -- Disabled: no inlining is requested for the subprogram
3153 -- Enabled: inlining is requested/required for the subprogram
3155 procedure Process_Inline (Status : Inline_Status);
3156 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
3157 -- indicates the inline status specified by the pragma.
3159 procedure Process_Interface_Name
3160 (Subprogram_Def : Entity_Id;
3161 Ext_Arg : Node_Id;
3162 Link_Arg : Node_Id);
3163 -- Given the last two arguments of pragma Import, pragma Export, or
3164 -- pragma Interface_Name, performs validity checks and sets the
3165 -- Interface_Name field of the given subprogram entity to the
3166 -- appropriate external or link name, depending on the arguments given.
3167 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
3168 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
3169 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
3170 -- nor Link_Arg is present, the interface name is set to the default
3171 -- from the subprogram name.
3173 procedure Process_Interrupt_Or_Attach_Handler;
3174 -- Common processing for Interrupt and Attach_Handler pragmas
3176 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
3177 -- Common processing for Restrictions and Restriction_Warnings pragmas.
3178 -- Warn is True for Restriction_Warnings, or for Restrictions if the
3179 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
3180 -- is not set in the Restrictions case.
3182 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
3183 -- Common processing for Suppress and Unsuppress. The boolean parameter
3184 -- Suppress_Case is True for the Suppress case, and False for the
3185 -- Unsuppress case.
3187 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id);
3188 -- Subsidiary to the analysis of pragmas Independent[_Components].
3189 -- Record such a pragma N applied to entity E for future checks.
3191 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
3192 -- This procedure sets the Is_Exported flag for the given entity,
3193 -- checking that the entity was not previously imported. Arg is
3194 -- the argument that specified the entity. A check is also made
3195 -- for exporting inappropriate entities.
3197 procedure Set_Extended_Import_Export_External_Name
3198 (Internal_Ent : Entity_Id;
3199 Arg_External : Node_Id);
3200 -- Common processing for all extended import export pragmas. The first
3201 -- argument, Internal_Ent, is the internal entity, which has already
3202 -- been checked for validity by the caller. Arg_External is from the
3203 -- Import or Export pragma, and may be null if no External parameter
3204 -- was present. If Arg_External is present and is a non-null string
3205 -- (a null string is treated as the default), then the Interface_Name
3206 -- field of Internal_Ent is set appropriately.
3208 procedure Set_Imported (E : Entity_Id);
3209 -- This procedure sets the Is_Imported flag for the given entity,
3210 -- checking that it is not previously exported or imported.
3212 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
3213 -- Mech is a parameter passing mechanism (see Import_Function syntax
3214 -- for MECHANISM_NAME). This routine checks that the mechanism argument
3215 -- has the right form, and if not issues an error message. If the
3216 -- argument has the right form then the Mechanism field of Ent is
3217 -- set appropriately.
3219 procedure Set_Rational_Profile;
3220 -- Activate the set of configuration pragmas and permissions that make
3221 -- up the Rational profile.
3223 procedure Set_Ravenscar_Profile (N : Node_Id);
3224 -- Activate the set of configuration pragmas and restrictions that make
3225 -- up the Ravenscar Profile. N is the corresponding pragma node, which
3226 -- is used for error messages on any constructs violating the profile.
3228 ----------------------------------
3229 -- Acquire_Warning_Match_String --
3230 ----------------------------------
3232 procedure Acquire_Warning_Match_String (Arg : Node_Id) is
3233 begin
3234 String_To_Name_Buffer
3235 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
3237 -- Add asterisk at start if not already there
3239 if Name_Len > 0 and then Name_Buffer (1) /= '*' then
3240 Name_Buffer (2 .. Name_Len + 1) :=
3241 Name_Buffer (1 .. Name_Len);
3242 Name_Buffer (1) := '*';
3243 Name_Len := Name_Len + 1;
3244 end if;
3246 -- Add asterisk at end if not already there
3248 if Name_Buffer (Name_Len) /= '*' then
3249 Name_Len := Name_Len + 1;
3250 Name_Buffer (Name_Len) := '*';
3251 end if;
3252 end Acquire_Warning_Match_String;
3254 ---------------------
3255 -- Ada_2005_Pragma --
3256 ---------------------
3258 procedure Ada_2005_Pragma is
3259 begin
3260 if Ada_Version <= Ada_95 then
3261 Check_Restriction (No_Implementation_Pragmas, N);
3262 end if;
3263 end Ada_2005_Pragma;
3265 ---------------------
3266 -- Ada_2012_Pragma --
3267 ---------------------
3269 procedure Ada_2012_Pragma is
3270 begin
3271 if Ada_Version <= Ada_2005 then
3272 Check_Restriction (No_Implementation_Pragmas, N);
3273 end if;
3274 end Ada_2012_Pragma;
3276 ---------------------
3277 -- Analyze_Part_Of --
3278 ---------------------
3280 procedure Analyze_Part_Of
3281 (Item_Id : Entity_Id;
3282 State : Node_Id;
3283 Indic : Node_Id;
3284 Legal : out Boolean)
3286 Pack_Id : Entity_Id;
3287 Placement : State_Space_Kind;
3288 Parent_Unit : Entity_Id;
3289 State_Id : Entity_Id;
3291 begin
3292 -- Assume that the pragma/option is illegal
3294 Legal := False;
3296 if Nkind_In (State, N_Expanded_Name,
3297 N_Identifier,
3298 N_Selected_Component)
3299 then
3300 Analyze (State);
3301 Resolve_State (State);
3303 if Is_Entity_Name (State)
3304 and then Ekind (Entity (State)) = E_Abstract_State
3305 then
3306 State_Id := Entity (State);
3308 else
3309 SPARK_Msg_N
3310 ("indicator Part_Of must denote an abstract state", State);
3311 return;
3312 end if;
3314 -- This is a syntax error, always report
3316 else
3317 Error_Msg_N
3318 ("indicator Part_Of must denote an abstract state", State);
3319 return;
3320 end if;
3322 -- Determine where the state, variable or the package instantiation
3323 -- lives with respect to the enclosing packages or package bodies (if
3324 -- any). This placement dictates the legality of the encapsulating
3325 -- state.
3327 Find_Placement_In_State_Space
3328 (Item_Id => Item_Id,
3329 Placement => Placement,
3330 Pack_Id => Pack_Id);
3332 -- The item appears in a non-package construct with a declarative
3333 -- part (subprogram, block, etc). As such, the item is not allowed
3334 -- to be a part of an encapsulating state because the item is not
3335 -- visible.
3337 if Placement = Not_In_Package then
3338 SPARK_Msg_N
3339 ("indicator Part_Of cannot appear in this context "
3340 & "(SPARK RM 7.2.6(5))", Indic);
3341 Error_Msg_Name_1 := Chars (Scope (State_Id));
3342 SPARK_Msg_NE
3343 ("\& is not part of the hidden state of package %",
3344 Indic, Item_Id);
3346 -- The item appears in the visible state space of some package. In
3347 -- general this scenario does not warrant Part_Of except when the
3348 -- package is a private child unit and the encapsulating state is
3349 -- declared in a parent unit or a public descendant of that parent
3350 -- unit.
3352 elsif Placement = Visible_State_Space then
3353 if Is_Child_Unit (Pack_Id)
3354 and then Is_Private_Descendant (Pack_Id)
3355 then
3356 -- A variable or state abstraction which is part of the
3357 -- visible state of a private child unit (or one of its public
3358 -- descendants) must have its Part_Of indicator specified. The
3359 -- Part_Of indicator must denote a state abstraction declared
3360 -- by either the parent unit of the private unit or by a public
3361 -- descendant of that parent unit.
3363 -- Find nearest private ancestor (which can be the current unit
3364 -- itself).
3366 Parent_Unit := Pack_Id;
3367 while Present (Parent_Unit) loop
3368 exit when Private_Present
3369 (Parent (Unit_Declaration_Node (Parent_Unit)));
3370 Parent_Unit := Scope (Parent_Unit);
3371 end loop;
3373 Parent_Unit := Scope (Parent_Unit);
3375 if not Is_Child_Or_Sibling (Pack_Id, Scope (State_Id)) then
3376 SPARK_Msg_NE
3377 ("indicator Part_Of must denote an abstract state of& "
3378 & "or public descendant (SPARK RM 7.2.6(3))",
3379 Indic, Parent_Unit);
3381 elsif Scope (State_Id) = Parent_Unit
3382 or else (Is_Ancestor_Package (Parent_Unit, Scope (State_Id))
3383 and then
3384 not Is_Private_Descendant (Scope (State_Id)))
3385 then
3386 null;
3388 else
3389 SPARK_Msg_NE
3390 ("indicator Part_Of must denote an abstract state of& "
3391 & "or public descendant (SPARK RM 7.2.6(3))",
3392 Indic, Parent_Unit);
3393 end if;
3395 -- Indicator Part_Of is not needed when the related package is not
3396 -- a private child unit or a public descendant thereof.
3398 else
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 (Pack_Id);
3403 SPARK_Msg_NE
3404 ("\& is declared in the visible part of package %",
3405 Indic, Item_Id);
3406 end if;
3408 -- When the item appears in the private state space of a package, the
3409 -- encapsulating state must be declared in the same package.
3411 elsif Placement = Private_State_Space then
3412 if Scope (State_Id) /= Pack_Id then
3413 SPARK_Msg_NE
3414 ("indicator Part_Of must designate an abstract state of "
3415 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3416 Error_Msg_Name_1 := Chars (Pack_Id);
3417 SPARK_Msg_NE
3418 ("\& is declared in the private part of package %",
3419 Indic, Item_Id);
3420 end if;
3422 -- Items declared in the body state space of a package do not need
3423 -- Part_Of indicators as the refinement has already been seen.
3425 else
3426 SPARK_Msg_N
3427 ("indicator Part_Of cannot appear in this context "
3428 & "(SPARK RM 7.2.6(5))", Indic);
3430 if Scope (State_Id) = Pack_Id then
3431 Error_Msg_Name_1 := Chars (Pack_Id);
3432 SPARK_Msg_NE
3433 ("\& is declared in the body of package %", Indic, Item_Id);
3434 end if;
3435 end if;
3437 Legal := True;
3438 end Analyze_Part_Of;
3440 --------------------------------
3441 -- Analyze_Pre_Post_Condition --
3442 --------------------------------
3444 procedure Analyze_Pre_Post_Condition is
3445 Prag_Iden : constant Node_Id := Pragma_Identifier (N);
3446 Subp_Decl : Node_Id;
3447 Subp_Id : Entity_Id;
3449 Duplicates_OK : Boolean := False;
3450 -- Flag set when a pre/postcondition allows multiple pragmas of the
3451 -- same kind.
3453 In_Body_OK : Boolean := False;
3454 -- Flag set when a pre/postcondition is allowed to appear on a body
3455 -- even though the subprogram may have a spec.
3457 Is_Pre_Post : Boolean := False;
3458 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
3459 -- Post_Class.
3461 begin
3462 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
3463 -- offer uniformity among the various kinds of pre/postconditions by
3464 -- rewriting the pragma identifier. This allows the retrieval of the
3465 -- original pragma name by routine Original_Aspect_Pragma_Name.
3467 if Comes_From_Source (N) then
3468 if Nam_In (Pname, Name_Pre, Name_Pre_Class) then
3469 Is_Pre_Post := True;
3470 Set_Class_Present (N, Pname = Name_Pre_Class);
3471 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition));
3473 elsif Nam_In (Pname, Name_Post, Name_Post_Class) then
3474 Is_Pre_Post := True;
3475 Set_Class_Present (N, Pname = Name_Post_Class);
3476 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition));
3477 end if;
3478 end if;
3480 -- Determine the semantics with respect to duplicates and placement
3481 -- in a body. Pragmas Precondition and Postcondition were introduced
3482 -- before aspects and are not subject to the same aspect-like rules.
3484 if Nam_In (Pname, Name_Precondition, Name_Postcondition) then
3485 Duplicates_OK := True;
3486 In_Body_OK := True;
3487 end if;
3489 GNAT_Pragma;
3491 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
3492 -- argument without an identifier.
3494 if Is_Pre_Post then
3495 Check_Arg_Count (1);
3496 Check_No_Identifiers;
3498 -- Pragmas Precondition and Postcondition have complex argument
3499 -- profile.
3501 else
3502 Check_At_Least_N_Arguments (1);
3503 Check_At_Most_N_Arguments (2);
3504 Check_Optional_Identifier (Arg1, Name_Check);
3506 if Present (Arg2) then
3507 Check_Optional_Identifier (Arg2, Name_Message);
3508 Preanalyze_Spec_Expression
3509 (Get_Pragma_Arg (Arg2), Standard_String);
3510 end if;
3511 end if;
3513 -- For a pragma PPC in the extended main source unit, record enabled
3514 -- status in SCO.
3515 -- ??? nothing checks that the pragma is in the main source unit
3517 if Is_Checked (N) and then not Split_PPC (N) then
3518 Set_SCO_Pragma_Enabled (Loc);
3519 end if;
3521 -- Ensure the proper placement of the pragma
3523 Subp_Decl :=
3524 Find_Related_Subprogram_Or_Body (N, Do_Checks => not Duplicates_OK);
3526 -- When a pre/postcondition pragma applies to an abstract subprogram,
3527 -- its original form must be an aspect with 'Class.
3529 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
3530 if not From_Aspect_Specification (N) then
3531 Error_Pragma
3532 ("pragma % cannot be applied to abstract subprogram");
3534 elsif not Class_Present (N) then
3535 Error_Pragma
3536 ("aspect % requires ''Class for abstract subprogram");
3537 end if;
3539 -- Entry declaration
3541 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
3542 null;
3544 -- Generic subprogram declaration
3546 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
3547 null;
3549 -- Subprogram body
3551 elsif Nkind (Subp_Decl) = N_Subprogram_Body
3552 and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK)
3553 then
3554 null;
3556 -- Subprogram body stub
3558 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3559 and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK)
3560 then
3561 null;
3563 -- Subprogram declaration
3565 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
3567 -- AI05-0230: When a pre/postcondition pragma applies to a null
3568 -- procedure, its original form must be an aspect with 'Class.
3570 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
3571 and then Null_Present (Specification (Subp_Decl))
3572 and then From_Aspect_Specification (N)
3573 and then not Class_Present (N)
3574 then
3575 Error_Pragma ("aspect % requires ''Class for null procedure");
3576 end if;
3578 -- Otherwise the placement is illegal
3580 else
3581 Pragma_Misplaced;
3582 return;
3583 end if;
3585 Subp_Id := Defining_Entity (Subp_Decl);
3587 -- Construct a generic template for the pragma when the context is a
3588 -- generic subprogram and the pragma is a source construct.
3590 Create_Generic_Template (N, Subp_Id);
3592 -- Fully analyze the pragma when it appears inside a subprogram
3593 -- body because it cannot benefit from forward references.
3595 if Nkind_In (Subp_Decl, N_Subprogram_Body,
3596 N_Subprogram_Body_Stub)
3597 then
3598 Analyze_Pre_Post_Condition_In_Decl_Part (N);
3599 end if;
3601 -- Chain the pragma on the contract for further processing
3603 Add_Contract_Item (N, Subp_Id);
3604 end Analyze_Pre_Post_Condition;
3606 ----------------------------
3607 -- Analyze_Refined_Pragma --
3608 ----------------------------
3610 procedure Analyze_Refined_Pragma
3611 (Spec_Id : out Entity_Id;
3612 Body_Id : out Entity_Id;
3613 Legal : out Boolean)
3615 Body_Decl : Node_Id;
3616 Spec_Decl : Node_Id;
3618 begin
3619 -- Assume that the pragma is illegal
3621 Spec_Id := Empty;
3622 Body_Id := Empty;
3623 Legal := False;
3625 GNAT_Pragma;
3626 Check_Arg_Count (1);
3627 Check_No_Identifiers;
3629 -- Verify the placement of the pragma and check for duplicates. The
3630 -- pragma must apply to a subprogram body [stub].
3632 Body_Decl := Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
3634 -- Extract the entities of the spec and body
3636 if Nkind (Body_Decl) = N_Subprogram_Body then
3637 Body_Id := Defining_Entity (Body_Decl);
3638 Spec_Id := Corresponding_Spec (Body_Decl);
3640 elsif Nkind (Body_Decl) = N_Subprogram_Body_Stub then
3641 Body_Id := Defining_Entity (Body_Decl);
3642 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
3644 else
3645 Pragma_Misplaced;
3646 return;
3647 end if;
3649 -- The pragma must apply to the second declaration of a subprogram.
3650 -- In other words, the body [stub] cannot acts as a spec.
3652 if No (Spec_Id) then
3653 Error_Pragma ("pragma % cannot apply to a stand alone body");
3654 return;
3656 -- Catch the case where the subprogram body is a subunit and acts as
3657 -- the third declaration of the subprogram.
3659 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
3660 Error_Pragma ("pragma % cannot apply to a subunit");
3661 return;
3662 end if;
3664 -- The pragma can only apply to the body [stub] of a subprogram
3665 -- declared in the visible part of a package. Retrieve the context of
3666 -- the subprogram declaration.
3668 Spec_Decl := Unit_Declaration_Node (Spec_Id);
3670 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
3671 Error_Pragma
3672 ("pragma % must apply to the body of a subprogram declared in a "
3673 & "package specification");
3674 return;
3675 end if;
3677 -- If we get here, then the pragma is legal
3679 if Nam_In (Pname, Name_Refined_Depends,
3680 Name_Refined_Global,
3681 Name_Refined_State)
3682 then
3683 Ensure_Aggregate_Form (Get_Argument (N));
3684 end if;
3686 Legal := True;
3687 end Analyze_Refined_Pragma;
3689 --------------------------
3690 -- Check_Ada_83_Warning --
3691 --------------------------
3693 procedure Check_Ada_83_Warning is
3694 begin
3695 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
3696 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
3697 end if;
3698 end Check_Ada_83_Warning;
3700 ---------------------
3701 -- Check_Arg_Count --
3702 ---------------------
3704 procedure Check_Arg_Count (Required : Nat) is
3705 begin
3706 if Arg_Count /= Required then
3707 Error_Pragma ("wrong number of arguments for pragma%");
3708 end if;
3709 end Check_Arg_Count;
3711 --------------------------------
3712 -- Check_Arg_Is_External_Name --
3713 --------------------------------
3715 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
3716 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3718 begin
3719 if Nkind (Argx) = N_Identifier then
3720 return;
3722 else
3723 Analyze_And_Resolve (Argx, Standard_String);
3725 if Is_OK_Static_Expression (Argx) then
3726 return;
3728 elsif Etype (Argx) = Any_Type then
3729 raise Pragma_Exit;
3731 -- An interesting special case, if we have a string literal and
3732 -- we are in Ada 83 mode, then we allow it even though it will
3733 -- not be flagged as static. This allows expected Ada 83 mode
3734 -- use of external names which are string literals, even though
3735 -- technically these are not static in Ada 83.
3737 elsif Ada_Version = Ada_83
3738 and then Nkind (Argx) = N_String_Literal
3739 then
3740 return;
3742 -- Static expression that raises Constraint_Error. This has
3743 -- already been flagged, so just exit from pragma processing.
3745 elsif Is_OK_Static_Expression (Argx) then
3746 raise Pragma_Exit;
3748 -- Here we have a real error (non-static expression)
3750 else
3751 Error_Msg_Name_1 := Pname;
3753 declare
3754 Msg : constant String :=
3755 "argument for pragma% must be a identifier or "
3756 & "static string expression!";
3757 begin
3758 Flag_Non_Static_Expr (Fix_Error (Msg), Argx);
3759 raise Pragma_Exit;
3760 end;
3761 end if;
3762 end if;
3763 end Check_Arg_Is_External_Name;
3765 -----------------------------
3766 -- Check_Arg_Is_Identifier --
3767 -----------------------------
3769 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
3770 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3771 begin
3772 if Nkind (Argx) /= N_Identifier then
3773 Error_Pragma_Arg
3774 ("argument for pragma% must be identifier", Argx);
3775 end if;
3776 end Check_Arg_Is_Identifier;
3778 ----------------------------------
3779 -- Check_Arg_Is_Integer_Literal --
3780 ----------------------------------
3782 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
3783 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3784 begin
3785 if Nkind (Argx) /= N_Integer_Literal then
3786 Error_Pragma_Arg
3787 ("argument for pragma% must be integer literal", Argx);
3788 end if;
3789 end Check_Arg_Is_Integer_Literal;
3791 -------------------------------------------
3792 -- Check_Arg_Is_Library_Level_Local_Name --
3793 -------------------------------------------
3795 -- LOCAL_NAME ::=
3796 -- DIRECT_NAME
3797 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3798 -- | library_unit_NAME
3800 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
3801 begin
3802 Check_Arg_Is_Local_Name (Arg);
3804 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
3805 and then Comes_From_Source (N)
3806 then
3807 Error_Pragma_Arg
3808 ("argument for pragma% must be library level entity", Arg);
3809 end if;
3810 end Check_Arg_Is_Library_Level_Local_Name;
3812 -----------------------------
3813 -- Check_Arg_Is_Local_Name --
3814 -----------------------------
3816 -- LOCAL_NAME ::=
3817 -- DIRECT_NAME
3818 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3819 -- | library_unit_NAME
3821 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
3822 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3824 begin
3825 Analyze (Argx);
3827 if Nkind (Argx) not in N_Direct_Name
3828 and then (Nkind (Argx) /= N_Attribute_Reference
3829 or else Present (Expressions (Argx))
3830 or else Nkind (Prefix (Argx)) /= N_Identifier)
3831 and then (not Is_Entity_Name (Argx)
3832 or else not Is_Compilation_Unit (Entity (Argx)))
3833 then
3834 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
3835 end if;
3837 -- No further check required if not an entity name
3839 if not Is_Entity_Name (Argx) then
3840 null;
3842 else
3843 declare
3844 OK : Boolean;
3845 Ent : constant Entity_Id := Entity (Argx);
3846 Scop : constant Entity_Id := Scope (Ent);
3848 begin
3849 -- Case of a pragma applied to a compilation unit: pragma must
3850 -- occur immediately after the program unit in the compilation.
3852 if Is_Compilation_Unit (Ent) then
3853 declare
3854 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
3856 begin
3857 -- Case of pragma placed immediately after spec
3859 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
3860 OK := True;
3862 -- Case of pragma placed immediately after body
3864 elsif Nkind (Decl) = N_Subprogram_Declaration
3865 and then Present (Corresponding_Body (Decl))
3866 then
3867 OK := Parent (N) =
3868 Aux_Decls_Node
3869 (Parent (Unit_Declaration_Node
3870 (Corresponding_Body (Decl))));
3872 -- All other cases are illegal
3874 else
3875 OK := False;
3876 end if;
3877 end;
3879 -- Special restricted placement rule from 10.2.1(11.8/2)
3881 elsif Is_Generic_Formal (Ent)
3882 and then Prag_Id = Pragma_Preelaborable_Initialization
3883 then
3884 OK := List_Containing (N) =
3885 Generic_Formal_Declarations
3886 (Unit_Declaration_Node (Scop));
3888 -- If this is an aspect applied to a subprogram body, the
3889 -- pragma is inserted in its declarative part.
3891 elsif From_Aspect_Specification (N)
3892 and then Ent = Current_Scope
3893 and then
3894 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
3895 then
3896 OK := True;
3898 -- If the aspect is a predicate (possibly others ???) and the
3899 -- context is a record type, this is a discriminant expression
3900 -- within a type declaration, that freezes the predicated
3901 -- subtype.
3903 elsif From_Aspect_Specification (N)
3904 and then Prag_Id = Pragma_Predicate
3905 and then Ekind (Current_Scope) = E_Record_Type
3906 and then Scop = Scope (Current_Scope)
3907 then
3908 OK := True;
3910 -- Default case, just check that the pragma occurs in the scope
3911 -- of the entity denoted by the name.
3913 else
3914 OK := Current_Scope = Scop;
3915 end if;
3917 if not OK then
3918 Error_Pragma_Arg
3919 ("pragma% argument must be in same declarative part", Arg);
3920 end if;
3921 end;
3922 end if;
3923 end Check_Arg_Is_Local_Name;
3925 ---------------------------------
3926 -- Check_Arg_Is_Locking_Policy --
3927 ---------------------------------
3929 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
3930 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3932 begin
3933 Check_Arg_Is_Identifier (Argx);
3935 if not Is_Locking_Policy_Name (Chars (Argx)) then
3936 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
3937 end if;
3938 end Check_Arg_Is_Locking_Policy;
3940 -----------------------------------------------
3941 -- Check_Arg_Is_Partition_Elaboration_Policy --
3942 -----------------------------------------------
3944 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
3945 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3947 begin
3948 Check_Arg_Is_Identifier (Argx);
3950 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
3951 Error_Pragma_Arg
3952 ("& is not a valid partition elaboration policy name", Argx);
3953 end if;
3954 end Check_Arg_Is_Partition_Elaboration_Policy;
3956 -------------------------
3957 -- Check_Arg_Is_One_Of --
3958 -------------------------
3960 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
3961 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3963 begin
3964 Check_Arg_Is_Identifier (Argx);
3966 if not Nam_In (Chars (Argx), N1, N2) then
3967 Error_Msg_Name_2 := N1;
3968 Error_Msg_Name_3 := N2;
3969 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
3970 end if;
3971 end Check_Arg_Is_One_Of;
3973 procedure Check_Arg_Is_One_Of
3974 (Arg : Node_Id;
3975 N1, N2, N3 : Name_Id)
3977 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3979 begin
3980 Check_Arg_Is_Identifier (Argx);
3982 if not Nam_In (Chars (Argx), N1, N2, N3) then
3983 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3984 end if;
3985 end Check_Arg_Is_One_Of;
3987 procedure Check_Arg_Is_One_Of
3988 (Arg : Node_Id;
3989 N1, N2, N3, N4 : Name_Id)
3991 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3993 begin
3994 Check_Arg_Is_Identifier (Argx);
3996 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
3997 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3998 end if;
3999 end Check_Arg_Is_One_Of;
4001 procedure Check_Arg_Is_One_Of
4002 (Arg : Node_Id;
4003 N1, N2, N3, N4, N5 : Name_Id)
4005 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4007 begin
4008 Check_Arg_Is_Identifier (Argx);
4010 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
4011 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
4012 end if;
4013 end Check_Arg_Is_One_Of;
4015 ---------------------------------
4016 -- Check_Arg_Is_Queuing_Policy --
4017 ---------------------------------
4019 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
4020 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4022 begin
4023 Check_Arg_Is_Identifier (Argx);
4025 if not Is_Queuing_Policy_Name (Chars (Argx)) then
4026 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
4027 end if;
4028 end Check_Arg_Is_Queuing_Policy;
4030 ---------------------------------------
4031 -- Check_Arg_Is_OK_Static_Expression --
4032 ---------------------------------------
4034 procedure Check_Arg_Is_OK_Static_Expression
4035 (Arg : Node_Id;
4036 Typ : Entity_Id := Empty)
4038 begin
4039 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
4040 end Check_Arg_Is_OK_Static_Expression;
4042 ------------------------------------------
4043 -- Check_Arg_Is_Task_Dispatching_Policy --
4044 ------------------------------------------
4046 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
4047 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4049 begin
4050 Check_Arg_Is_Identifier (Argx);
4052 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
4053 Error_Pragma_Arg
4054 ("& is not an allowed task dispatching policy name", Argx);
4055 end if;
4056 end Check_Arg_Is_Task_Dispatching_Policy;
4058 ---------------------
4059 -- Check_Arg_Order --
4060 ---------------------
4062 procedure Check_Arg_Order (Names : Name_List) is
4063 Arg : Node_Id;
4065 Highest_So_Far : Natural := 0;
4066 -- Highest index in Names seen do far
4068 begin
4069 Arg := Arg1;
4070 for J in 1 .. Arg_Count loop
4071 if Chars (Arg) /= No_Name then
4072 for K in Names'Range loop
4073 if Chars (Arg) = Names (K) then
4074 if K < Highest_So_Far then
4075 Error_Msg_Name_1 := Pname;
4076 Error_Msg_N
4077 ("parameters out of order for pragma%", Arg);
4078 Error_Msg_Name_1 := Names (K);
4079 Error_Msg_Name_2 := Names (Highest_So_Far);
4080 Error_Msg_N ("\% must appear before %", Arg);
4081 raise Pragma_Exit;
4083 else
4084 Highest_So_Far := K;
4085 end if;
4086 end if;
4087 end loop;
4088 end if;
4090 Arg := Next (Arg);
4091 end loop;
4092 end Check_Arg_Order;
4094 --------------------------------
4095 -- Check_At_Least_N_Arguments --
4096 --------------------------------
4098 procedure Check_At_Least_N_Arguments (N : Nat) is
4099 begin
4100 if Arg_Count < N then
4101 Error_Pragma ("too few arguments for pragma%");
4102 end if;
4103 end Check_At_Least_N_Arguments;
4105 -------------------------------
4106 -- Check_At_Most_N_Arguments --
4107 -------------------------------
4109 procedure Check_At_Most_N_Arguments (N : Nat) is
4110 Arg : Node_Id;
4111 begin
4112 if Arg_Count > N then
4113 Arg := Arg1;
4114 for J in 1 .. N loop
4115 Next (Arg);
4116 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
4117 end loop;
4118 end if;
4119 end Check_At_Most_N_Arguments;
4121 ---------------------
4122 -- Check_Component --
4123 ---------------------
4125 procedure Check_Component
4126 (Comp : Node_Id;
4127 UU_Typ : Entity_Id;
4128 In_Variant_Part : Boolean := False)
4130 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
4131 Sindic : constant Node_Id :=
4132 Subtype_Indication (Component_Definition (Comp));
4133 Typ : constant Entity_Id := Etype (Comp_Id);
4135 begin
4136 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
4137 -- object constraint, then the component type shall be an Unchecked_
4138 -- Union.
4140 if Nkind (Sindic) = N_Subtype_Indication
4141 and then Has_Per_Object_Constraint (Comp_Id)
4142 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
4143 then
4144 Error_Msg_N
4145 ("component subtype subject to per-object constraint "
4146 & "must be an Unchecked_Union", Comp);
4148 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
4149 -- the body of a generic unit, or within the body of any of its
4150 -- descendant library units, no part of the type of a component
4151 -- declared in a variant_part of the unchecked union type shall be of
4152 -- a formal private type or formal private extension declared within
4153 -- the formal part of the generic unit.
4155 elsif Ada_Version >= Ada_2012
4156 and then In_Generic_Body (UU_Typ)
4157 and then In_Variant_Part
4158 and then Is_Private_Type (Typ)
4159 and then Is_Generic_Type (Typ)
4160 then
4161 Error_Msg_N
4162 ("component of unchecked union cannot be of generic type", Comp);
4164 elsif Needs_Finalization (Typ) then
4165 Error_Msg_N
4166 ("component of unchecked union cannot be controlled", Comp);
4168 elsif Has_Task (Typ) then
4169 Error_Msg_N
4170 ("component of unchecked union cannot have tasks", Comp);
4171 end if;
4172 end Check_Component;
4174 -----------------------------
4175 -- Check_Declaration_Order --
4176 -----------------------------
4178 procedure Check_Declaration_Order (First : Node_Id; Second : Node_Id) is
4179 procedure Check_Aspect_Specification_Order;
4180 -- Inspect the aspect specifications of the context to determine the
4181 -- proper order.
4183 --------------------------------------
4184 -- Check_Aspect_Specification_Order --
4185 --------------------------------------
4187 procedure Check_Aspect_Specification_Order is
4188 Asp_First : constant Node_Id := Corresponding_Aspect (First);
4189 Asp_Second : constant Node_Id := Corresponding_Aspect (Second);
4190 Asp : Node_Id;
4192 begin
4193 -- Both aspects must be part of the same aspect specification list
4195 pragma Assert
4196 (List_Containing (Asp_First) = List_Containing (Asp_Second));
4198 -- Try to reach Second starting from First in a left to right
4199 -- traversal of the aspect specifications.
4201 Asp := Next (Asp_First);
4202 while Present (Asp) loop
4204 -- The order is ok, First is followed by Second
4206 if Asp = Asp_Second then
4207 return;
4208 end if;
4210 Next (Asp);
4211 end loop;
4213 -- If we get here, then the aspects are out of order
4215 SPARK_Msg_N ("aspect % cannot come after aspect %", First);
4216 end Check_Aspect_Specification_Order;
4218 -- Local variables
4220 Stmt : Node_Id;
4222 -- Start of processing for Check_Declaration_Order
4224 begin
4225 -- Cannot check the order if one of the pragmas is missing
4227 if No (First) or else No (Second) then
4228 return;
4229 end if;
4231 -- Set up the error names in case the order is incorrect
4233 Error_Msg_Name_1 := Pragma_Name (First);
4234 Error_Msg_Name_2 := Pragma_Name (Second);
4236 if From_Aspect_Specification (First) then
4238 -- Both pragmas are actually aspects, check their declaration
4239 -- order in the associated aspect specification list. Otherwise
4240 -- First is an aspect and Second a source pragma.
4242 if From_Aspect_Specification (Second) then
4243 Check_Aspect_Specification_Order;
4244 end if;
4246 -- Abstract_States is a source pragma
4248 else
4249 if From_Aspect_Specification (Second) then
4250 SPARK_Msg_N ("pragma % cannot come after aspect %", First);
4252 -- Both pragmas are source constructs. Try to reach First from
4253 -- Second by traversing the declarations backwards.
4255 else
4256 Stmt := Prev (Second);
4257 while Present (Stmt) loop
4259 -- The order is ok, First is followed by Second
4261 if Stmt = First then
4262 return;
4263 end if;
4265 Prev (Stmt);
4266 end loop;
4268 -- If we get here, then the pragmas are out of order
4270 SPARK_Msg_N ("pragma % cannot come after pragma %", First);
4271 end if;
4272 end if;
4273 end Check_Declaration_Order;
4275 ----------------------------
4276 -- Check_Duplicate_Pragma --
4277 ----------------------------
4279 procedure Check_Duplicate_Pragma (E : Entity_Id) is
4280 Id : Entity_Id := E;
4281 P : Node_Id;
4283 begin
4284 -- Nothing to do if this pragma comes from an aspect specification,
4285 -- since we could not be duplicating a pragma, and we dealt with the
4286 -- case of duplicated aspects in Analyze_Aspect_Specifications.
4288 if From_Aspect_Specification (N) then
4289 return;
4290 end if;
4292 -- Otherwise current pragma may duplicate previous pragma or a
4293 -- previously given aspect specification or attribute definition
4294 -- clause for the same pragma.
4296 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
4298 if Present (P) then
4300 -- If the entity is a type, then we have to make sure that the
4301 -- ostensible duplicate is not for a parent type from which this
4302 -- type is derived.
4304 if Is_Type (E) then
4305 if Nkind (P) = N_Pragma then
4306 declare
4307 Args : constant List_Id :=
4308 Pragma_Argument_Associations (P);
4309 begin
4310 if Present (Args)
4311 and then Is_Entity_Name (Expression (First (Args)))
4312 and then Is_Type (Entity (Expression (First (Args))))
4313 and then Entity (Expression (First (Args))) /= E
4314 then
4315 return;
4316 end if;
4317 end;
4319 elsif Nkind (P) = N_Aspect_Specification
4320 and then Is_Type (Entity (P))
4321 and then Entity (P) /= E
4322 then
4323 return;
4324 end if;
4325 end if;
4327 -- Here we have a definite duplicate
4329 Error_Msg_Name_1 := Pragma_Name (N);
4330 Error_Msg_Sloc := Sloc (P);
4332 -- For a single protected or a single task object, the error is
4333 -- issued on the original entity.
4335 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
4336 Id := Defining_Identifier (Original_Node (Parent (Id)));
4337 end if;
4339 if Nkind (P) = N_Aspect_Specification
4340 or else From_Aspect_Specification (P)
4341 then
4342 Error_Msg_NE ("aspect% for & previously given#", N, Id);
4343 else
4344 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
4345 end if;
4347 raise Pragma_Exit;
4348 end if;
4349 end Check_Duplicate_Pragma;
4351 ----------------------------------
4352 -- Check_Duplicated_Export_Name --
4353 ----------------------------------
4355 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
4356 String_Val : constant String_Id := Strval (Nam);
4358 begin
4359 -- We are only interested in the export case, and in the case of
4360 -- generics, it is the instance, not the template, that is the
4361 -- problem (the template will generate a warning in any case).
4363 if not Inside_A_Generic
4364 and then (Prag_Id = Pragma_Export
4365 or else
4366 Prag_Id = Pragma_Export_Procedure
4367 or else
4368 Prag_Id = Pragma_Export_Valued_Procedure
4369 or else
4370 Prag_Id = Pragma_Export_Function)
4371 then
4372 for J in Externals.First .. Externals.Last loop
4373 if String_Equal (String_Val, Strval (Externals.Table (J))) then
4374 Error_Msg_Sloc := Sloc (Externals.Table (J));
4375 Error_Msg_N ("external name duplicates name given#", Nam);
4376 exit;
4377 end if;
4378 end loop;
4380 Externals.Append (Nam);
4381 end if;
4382 end Check_Duplicated_Export_Name;
4384 ----------------------------------------
4385 -- Check_Expr_Is_OK_Static_Expression --
4386 ----------------------------------------
4388 procedure Check_Expr_Is_OK_Static_Expression
4389 (Expr : Node_Id;
4390 Typ : Entity_Id := Empty)
4392 begin
4393 if Present (Typ) then
4394 Analyze_And_Resolve (Expr, Typ);
4395 else
4396 Analyze_And_Resolve (Expr);
4397 end if;
4399 if Is_OK_Static_Expression (Expr) then
4400 return;
4402 elsif Etype (Expr) = Any_Type then
4403 raise Pragma_Exit;
4405 -- An interesting special case, if we have a string literal and we
4406 -- are in Ada 83 mode, then we allow it even though it will not be
4407 -- flagged as static. This allows the use of Ada 95 pragmas like
4408 -- Import in Ada 83 mode. They will of course be flagged with
4409 -- warnings as usual, but will not cause errors.
4411 elsif Ada_Version = Ada_83
4412 and then Nkind (Expr) = N_String_Literal
4413 then
4414 return;
4416 -- Static expression that raises Constraint_Error. This has already
4417 -- been flagged, so just exit from pragma processing.
4419 elsif Is_OK_Static_Expression (Expr) then
4420 raise Pragma_Exit;
4422 -- Finally, we have a real error
4424 else
4425 Error_Msg_Name_1 := Pname;
4426 Flag_Non_Static_Expr
4427 (Fix_Error ("argument for pragma% must be a static expression!"),
4428 Expr);
4429 raise Pragma_Exit;
4430 end if;
4431 end Check_Expr_Is_OK_Static_Expression;
4433 -------------------------
4434 -- Check_First_Subtype --
4435 -------------------------
4437 procedure Check_First_Subtype (Arg : Node_Id) is
4438 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4439 Ent : constant Entity_Id := Entity (Argx);
4441 begin
4442 if Is_First_Subtype (Ent) then
4443 null;
4445 elsif Is_Type (Ent) then
4446 Error_Pragma_Arg
4447 ("pragma% cannot apply to subtype", Argx);
4449 elsif Is_Object (Ent) then
4450 Error_Pragma_Arg
4451 ("pragma% cannot apply to object, requires a type", Argx);
4453 else
4454 Error_Pragma_Arg
4455 ("pragma% cannot apply to&, requires a type", Argx);
4456 end if;
4457 end Check_First_Subtype;
4459 ----------------------
4460 -- Check_Identifier --
4461 ----------------------
4463 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
4464 begin
4465 if Present (Arg)
4466 and then Nkind (Arg) = N_Pragma_Argument_Association
4467 then
4468 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
4469 Error_Msg_Name_1 := Pname;
4470 Error_Msg_Name_2 := Id;
4471 Error_Msg_N ("pragma% argument expects identifier%", Arg);
4472 raise Pragma_Exit;
4473 end if;
4474 end if;
4475 end Check_Identifier;
4477 --------------------------------
4478 -- Check_Identifier_Is_One_Of --
4479 --------------------------------
4481 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
4482 begin
4483 if Present (Arg)
4484 and then Nkind (Arg) = N_Pragma_Argument_Association
4485 then
4486 if Chars (Arg) = No_Name then
4487 Error_Msg_Name_1 := Pname;
4488 Error_Msg_N ("pragma% argument expects an identifier", Arg);
4489 raise Pragma_Exit;
4491 elsif Chars (Arg) /= N1
4492 and then Chars (Arg) /= N2
4493 then
4494 Error_Msg_Name_1 := Pname;
4495 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
4496 raise Pragma_Exit;
4497 end if;
4498 end if;
4499 end Check_Identifier_Is_One_Of;
4501 ---------------------------
4502 -- Check_In_Main_Program --
4503 ---------------------------
4505 procedure Check_In_Main_Program is
4506 P : constant Node_Id := Parent (N);
4508 begin
4509 -- Must be at in subprogram body
4511 if Nkind (P) /= N_Subprogram_Body then
4512 Error_Pragma ("% pragma allowed only in subprogram");
4514 -- Otherwise warn if obviously not main program
4516 elsif Present (Parameter_Specifications (Specification (P)))
4517 or else not Is_Compilation_Unit (Defining_Entity (P))
4518 then
4519 Error_Msg_Name_1 := Pname;
4520 Error_Msg_N
4521 ("??pragma% is only effective in main program", N);
4522 end if;
4523 end Check_In_Main_Program;
4525 ---------------------------------------
4526 -- Check_Interrupt_Or_Attach_Handler --
4527 ---------------------------------------
4529 procedure Check_Interrupt_Or_Attach_Handler is
4530 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4531 Handler_Proc, Proc_Scope : Entity_Id;
4533 begin
4534 Analyze (Arg1_X);
4536 if Prag_Id = Pragma_Interrupt_Handler then
4537 Check_Restriction (No_Dynamic_Attachment, N);
4538 end if;
4540 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
4541 Proc_Scope := Scope (Handler_Proc);
4543 -- On AAMP only, a pragma Interrupt_Handler is supported for
4544 -- nonprotected parameterless procedures.
4546 if not AAMP_On_Target
4547 or else Prag_Id = Pragma_Attach_Handler
4548 then
4549 if Ekind (Proc_Scope) /= E_Protected_Type then
4550 Error_Pragma_Arg
4551 ("argument of pragma% must be protected procedure", Arg1);
4552 end if;
4554 -- For pragma case (as opposed to access case), check placement.
4555 -- We don't need to do that for aspects, because we have the
4556 -- check that they aspect applies an appropriate procedure.
4558 if not From_Aspect_Specification (N)
4559 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
4560 then
4561 Error_Pragma ("pragma% must be in protected definition");
4562 end if;
4563 end if;
4565 if not Is_Library_Level_Entity (Proc_Scope)
4566 or else (AAMP_On_Target
4567 and then not Is_Library_Level_Entity (Handler_Proc))
4568 then
4569 Error_Pragma_Arg
4570 ("argument for pragma% must be library level entity", Arg1);
4571 end if;
4573 -- AI05-0033: A pragma cannot appear within a generic body, because
4574 -- instance can be in a nested scope. The check that protected type
4575 -- is itself a library-level declaration is done elsewhere.
4577 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
4578 -- handle code prior to AI-0033. Analysis tools typically are not
4579 -- interested in this pragma in any case, so no need to worry too
4580 -- much about its placement.
4582 if Inside_A_Generic then
4583 if Ekind (Scope (Current_Scope)) = E_Generic_Package
4584 and then In_Package_Body (Scope (Current_Scope))
4585 and then not Relaxed_RM_Semantics
4586 then
4587 Error_Pragma ("pragma% cannot be used inside a generic");
4588 end if;
4589 end if;
4590 end Check_Interrupt_Or_Attach_Handler;
4592 ---------------------------------
4593 -- Check_Loop_Pragma_Placement --
4594 ---------------------------------
4596 procedure Check_Loop_Pragma_Placement is
4597 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
4598 -- Verify whether the current pragma is properly grouped with other
4599 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
4600 -- related loop where the pragma appears.
4602 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
4603 -- Determine whether an arbitrary statement Stmt denotes pragma
4604 -- Loop_Invariant or Loop_Variant.
4606 procedure Placement_Error (Constr : Node_Id);
4607 pragma No_Return (Placement_Error);
4608 -- Node Constr denotes the last loop restricted construct before we
4609 -- encountered an illegal relation between enclosing constructs. Emit
4610 -- an error depending on what Constr was.
4612 --------------------------------
4613 -- Check_Loop_Pragma_Grouping --
4614 --------------------------------
4616 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
4617 Stop_Search : exception;
4618 -- This exception is used to terminate the recursive descent of
4619 -- routine Check_Grouping.
4621 procedure Check_Grouping (L : List_Id);
4622 -- Find the first group of pragmas in list L and if successful,
4623 -- ensure that the current pragma is part of that group. The
4624 -- routine raises Stop_Search once such a check is performed to
4625 -- halt the recursive descent.
4627 procedure Grouping_Error (Prag : Node_Id);
4628 pragma No_Return (Grouping_Error);
4629 -- Emit an error concerning the current pragma indicating that it
4630 -- should be placed after pragma Prag.
4632 --------------------
4633 -- Check_Grouping --
4634 --------------------
4636 procedure Check_Grouping (L : List_Id) is
4637 HSS : Node_Id;
4638 Prag : Node_Id;
4639 Stmt : Node_Id;
4641 begin
4642 -- Inspect the list of declarations or statements looking for
4643 -- the first grouping of pragmas:
4645 -- loop
4646 -- pragma Loop_Invariant ...;
4647 -- pragma Loop_Variant ...;
4648 -- . . . -- (1)
4649 -- pragma Loop_Variant ...; -- current pragma
4651 -- If the current pragma is not in the grouping, then it must
4652 -- either appear in a different declarative or statement list
4653 -- or the construct at (1) is separating the pragma from the
4654 -- grouping.
4656 Stmt := First (L);
4657 while Present (Stmt) loop
4659 -- Pragmas Loop_Invariant and Loop_Variant may only appear
4660 -- inside a loop or a block housed inside a loop. Inspect
4661 -- the declarations and statements of the block as they may
4662 -- contain the first grouping.
4664 if Nkind (Stmt) = N_Block_Statement then
4665 HSS := Handled_Statement_Sequence (Stmt);
4667 Check_Grouping (Declarations (Stmt));
4669 if Present (HSS) then
4670 Check_Grouping (Statements (HSS));
4671 end if;
4673 -- First pragma of the first topmost grouping has been found
4675 elsif Is_Loop_Pragma (Stmt) then
4677 -- The group and the current pragma are not in the same
4678 -- declarative or statement list.
4680 if List_Containing (Stmt) /= List_Containing (N) then
4681 Grouping_Error (Stmt);
4683 -- Try to reach the current pragma from the first pragma
4684 -- of the grouping while skipping other members:
4686 -- pragma Loop_Invariant ...; -- first pragma
4687 -- pragma Loop_Variant ...; -- member
4688 -- . . .
4689 -- pragma Loop_Variant ...; -- current pragma
4691 else
4692 while Present (Stmt) loop
4694 -- The current pragma is either the first pragma
4695 -- of the group or is a member of the group. Stop
4696 -- the search as the placement is legal.
4698 if Stmt = N then
4699 raise Stop_Search;
4701 -- Skip group members, but keep track of the last
4702 -- pragma in the group.
4704 elsif Is_Loop_Pragma (Stmt) then
4705 Prag := Stmt;
4707 -- A non-pragma is separating the group from the
4708 -- current pragma, the placement is illegal.
4710 else
4711 Grouping_Error (Prag);
4712 end if;
4714 Next (Stmt);
4715 end loop;
4717 -- If the traversal did not reach the current pragma,
4718 -- then the list must be malformed.
4720 raise Program_Error;
4721 end if;
4722 end if;
4724 Next (Stmt);
4725 end loop;
4726 end Check_Grouping;
4728 --------------------
4729 -- Grouping_Error --
4730 --------------------
4732 procedure Grouping_Error (Prag : Node_Id) is
4733 begin
4734 Error_Msg_Sloc := Sloc (Prag);
4735 Error_Pragma ("pragma% must appear next to pragma#");
4736 end Grouping_Error;
4738 -- Start of processing for Check_Loop_Pragma_Grouping
4740 begin
4741 -- Inspect the statements of the loop or nested blocks housed
4742 -- within to determine whether the current pragma is part of the
4743 -- first topmost grouping of Loop_Invariant and Loop_Variant.
4745 Check_Grouping (Statements (Loop_Stmt));
4747 exception
4748 when Stop_Search => null;
4749 end Check_Loop_Pragma_Grouping;
4751 --------------------
4752 -- Is_Loop_Pragma --
4753 --------------------
4755 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
4756 begin
4757 -- Inspect the original node as Loop_Invariant and Loop_Variant
4758 -- pragmas are rewritten to null when assertions are disabled.
4760 if Nkind (Original_Node (Stmt)) = N_Pragma then
4761 return
4762 Nam_In (Pragma_Name (Original_Node (Stmt)),
4763 Name_Loop_Invariant,
4764 Name_Loop_Variant);
4765 else
4766 return False;
4767 end if;
4768 end Is_Loop_Pragma;
4770 ---------------------
4771 -- Placement_Error --
4772 ---------------------
4774 procedure Placement_Error (Constr : Node_Id) is
4775 LA : constant String := " with Loop_Entry";
4777 begin
4778 if Prag_Id = Pragma_Assert then
4779 Error_Msg_String (1 .. LA'Length) := LA;
4780 Error_Msg_Strlen := LA'Length;
4781 else
4782 Error_Msg_Strlen := 0;
4783 end if;
4785 if Nkind (Constr) = N_Pragma then
4786 Error_Pragma
4787 ("pragma %~ must appear immediately within the statements "
4788 & "of a loop");
4789 else
4790 Error_Pragma_Arg
4791 ("block containing pragma %~ must appear immediately within "
4792 & "the statements of a loop", Constr);
4793 end if;
4794 end Placement_Error;
4796 -- Local declarations
4798 Prev : Node_Id;
4799 Stmt : Node_Id;
4801 -- Start of processing for Check_Loop_Pragma_Placement
4803 begin
4804 -- Check that pragma appears immediately within a loop statement,
4805 -- ignoring intervening block statements.
4807 Prev := N;
4808 Stmt := Parent (N);
4809 while Present (Stmt) loop
4811 -- The pragma or previous block must appear immediately within the
4812 -- current block's declarative or statement part.
4814 if Nkind (Stmt) = N_Block_Statement then
4815 if (No (Declarations (Stmt))
4816 or else List_Containing (Prev) /= Declarations (Stmt))
4817 and then
4818 List_Containing (Prev) /=
4819 Statements (Handled_Statement_Sequence (Stmt))
4820 then
4821 Placement_Error (Prev);
4822 return;
4824 -- Keep inspecting the parents because we are now within a
4825 -- chain of nested blocks.
4827 else
4828 Prev := Stmt;
4829 Stmt := Parent (Stmt);
4830 end if;
4832 -- The pragma or previous block must appear immediately within the
4833 -- statements of the loop.
4835 elsif Nkind (Stmt) = N_Loop_Statement then
4836 if List_Containing (Prev) /= Statements (Stmt) then
4837 Placement_Error (Prev);
4838 end if;
4840 -- Stop the traversal because we reached the innermost loop
4841 -- regardless of whether we encountered an error or not.
4843 exit;
4845 -- Ignore a handled statement sequence. Note that this node may
4846 -- be related to a subprogram body in which case we will emit an
4847 -- error on the next iteration of the search.
4849 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
4850 Stmt := Parent (Stmt);
4852 -- Any other statement breaks the chain from the pragma to the
4853 -- loop.
4855 else
4856 Placement_Error (Prev);
4857 return;
4858 end if;
4859 end loop;
4861 -- Check that the current pragma Loop_Invariant or Loop_Variant is
4862 -- grouped together with other such pragmas.
4864 if Is_Loop_Pragma (N) then
4866 -- The previous check should have located the related loop
4868 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
4869 Check_Loop_Pragma_Grouping (Stmt);
4870 end if;
4871 end Check_Loop_Pragma_Placement;
4873 -------------------------------------------
4874 -- Check_Is_In_Decl_Part_Or_Package_Spec --
4875 -------------------------------------------
4877 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
4878 P : Node_Id;
4880 begin
4881 P := Parent (N);
4882 loop
4883 if No (P) then
4884 exit;
4886 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
4887 exit;
4889 elsif Nkind_In (P, N_Package_Specification,
4890 N_Block_Statement)
4891 then
4892 return;
4894 -- Note: the following tests seem a little peculiar, because
4895 -- they test for bodies, but if we were in the statement part
4896 -- of the body, we would already have hit the handled statement
4897 -- sequence, so the only way we get here is by being in the
4898 -- declarative part of the body.
4900 elsif Nkind_In (P, N_Subprogram_Body,
4901 N_Package_Body,
4902 N_Task_Body,
4903 N_Entry_Body)
4904 then
4905 return;
4906 end if;
4908 P := Parent (P);
4909 end loop;
4911 Error_Pragma ("pragma% is not in declarative part or package spec");
4912 end Check_Is_In_Decl_Part_Or_Package_Spec;
4914 -------------------------
4915 -- Check_No_Identifier --
4916 -------------------------
4918 procedure Check_No_Identifier (Arg : Node_Id) is
4919 begin
4920 if Nkind (Arg) = N_Pragma_Argument_Association
4921 and then Chars (Arg) /= No_Name
4922 then
4923 Error_Pragma_Arg_Ident
4924 ("pragma% does not permit identifier& here", Arg);
4925 end if;
4926 end Check_No_Identifier;
4928 --------------------------
4929 -- Check_No_Identifiers --
4930 --------------------------
4932 procedure Check_No_Identifiers is
4933 Arg_Node : Node_Id;
4934 begin
4935 Arg_Node := Arg1;
4936 for J in 1 .. Arg_Count loop
4937 Check_No_Identifier (Arg_Node);
4938 Next (Arg_Node);
4939 end loop;
4940 end Check_No_Identifiers;
4942 ------------------------
4943 -- Check_No_Link_Name --
4944 ------------------------
4946 procedure Check_No_Link_Name is
4947 begin
4948 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
4949 Arg4 := Arg3;
4950 end if;
4952 if Present (Arg4) then
4953 Error_Pragma_Arg
4954 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
4955 end if;
4956 end Check_No_Link_Name;
4958 -------------------------------
4959 -- Check_Optional_Identifier --
4960 -------------------------------
4962 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
4963 begin
4964 if Present (Arg)
4965 and then Nkind (Arg) = N_Pragma_Argument_Association
4966 and then Chars (Arg) /= No_Name
4967 then
4968 if Chars (Arg) /= Id then
4969 Error_Msg_Name_1 := Pname;
4970 Error_Msg_Name_2 := Id;
4971 Error_Msg_N ("pragma% argument expects identifier%", Arg);
4972 raise Pragma_Exit;
4973 end if;
4974 end if;
4975 end Check_Optional_Identifier;
4977 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
4978 begin
4979 Name_Buffer (1 .. Id'Length) := Id;
4980 Name_Len := Id'Length;
4981 Check_Optional_Identifier (Arg, Name_Find);
4982 end Check_Optional_Identifier;
4984 -----------------------------
4985 -- Check_Static_Constraint --
4986 -----------------------------
4988 -- Note: for convenience in writing this procedure, in addition to
4989 -- the officially (i.e. by spec) allowed argument which is always a
4990 -- constraint, it also allows ranges and discriminant associations.
4991 -- Above is not clear ???
4993 procedure Check_Static_Constraint (Constr : Node_Id) is
4995 procedure Require_Static (E : Node_Id);
4996 -- Require given expression to be static expression
4998 --------------------
4999 -- Require_Static --
5000 --------------------
5002 procedure Require_Static (E : Node_Id) is
5003 begin
5004 if not Is_OK_Static_Expression (E) then
5005 Flag_Non_Static_Expr
5006 ("non-static constraint not allowed in Unchecked_Union!", E);
5007 raise Pragma_Exit;
5008 end if;
5009 end Require_Static;
5011 -- Start of processing for Check_Static_Constraint
5013 begin
5014 case Nkind (Constr) is
5015 when N_Discriminant_Association =>
5016 Require_Static (Expression (Constr));
5018 when N_Range =>
5019 Require_Static (Low_Bound (Constr));
5020 Require_Static (High_Bound (Constr));
5022 when N_Attribute_Reference =>
5023 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
5024 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
5026 when N_Range_Constraint =>
5027 Check_Static_Constraint (Range_Expression (Constr));
5029 when N_Index_Or_Discriminant_Constraint =>
5030 declare
5031 IDC : Entity_Id;
5032 begin
5033 IDC := First (Constraints (Constr));
5034 while Present (IDC) loop
5035 Check_Static_Constraint (IDC);
5036 Next (IDC);
5037 end loop;
5038 end;
5040 when others =>
5041 null;
5042 end case;
5043 end Check_Static_Constraint;
5045 --------------------------------------
5046 -- Check_Valid_Configuration_Pragma --
5047 --------------------------------------
5049 -- A configuration pragma must appear in the context clause of a
5050 -- compilation unit, and only other pragmas may precede it. Note that
5051 -- the test also allows use in a configuration pragma file.
5053 procedure Check_Valid_Configuration_Pragma is
5054 begin
5055 if not Is_Configuration_Pragma then
5056 Error_Pragma ("incorrect placement for configuration pragma%");
5057 end if;
5058 end Check_Valid_Configuration_Pragma;
5060 -------------------------------------
5061 -- Check_Valid_Library_Unit_Pragma --
5062 -------------------------------------
5064 procedure Check_Valid_Library_Unit_Pragma is
5065 Plist : List_Id;
5066 Parent_Node : Node_Id;
5067 Unit_Name : Entity_Id;
5068 Unit_Kind : Node_Kind;
5069 Unit_Node : Node_Id;
5070 Sindex : Source_File_Index;
5072 begin
5073 if not Is_List_Member (N) then
5074 Pragma_Misplaced;
5076 else
5077 Plist := List_Containing (N);
5078 Parent_Node := Parent (Plist);
5080 if Parent_Node = Empty then
5081 Pragma_Misplaced;
5083 -- Case of pragma appearing after a compilation unit. In this case
5084 -- it must have an argument with the corresponding name and must
5085 -- be part of the following pragmas of its parent.
5087 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
5088 if Plist /= Pragmas_After (Parent_Node) then
5089 Pragma_Misplaced;
5091 elsif Arg_Count = 0 then
5092 Error_Pragma
5093 ("argument required if outside compilation unit");
5095 else
5096 Check_No_Identifiers;
5097 Check_Arg_Count (1);
5098 Unit_Node := Unit (Parent (Parent_Node));
5099 Unit_Kind := Nkind (Unit_Node);
5101 Analyze (Get_Pragma_Arg (Arg1));
5103 if Unit_Kind = N_Generic_Subprogram_Declaration
5104 or else Unit_Kind = N_Subprogram_Declaration
5105 then
5106 Unit_Name := Defining_Entity (Unit_Node);
5108 elsif Unit_Kind in N_Generic_Instantiation then
5109 Unit_Name := Defining_Entity (Unit_Node);
5111 else
5112 Unit_Name := Cunit_Entity (Current_Sem_Unit);
5113 end if;
5115 if Chars (Unit_Name) /=
5116 Chars (Entity (Get_Pragma_Arg (Arg1)))
5117 then
5118 Error_Pragma_Arg
5119 ("pragma% argument is not current unit name", Arg1);
5120 end if;
5122 if Ekind (Unit_Name) = E_Package
5123 and then Present (Renamed_Entity (Unit_Name))
5124 then
5125 Error_Pragma ("pragma% not allowed for renamed package");
5126 end if;
5127 end if;
5129 -- Pragma appears other than after a compilation unit
5131 else
5132 -- Here we check for the generic instantiation case and also
5133 -- for the case of processing a generic formal package. We
5134 -- detect these cases by noting that the Sloc on the node
5135 -- does not belong to the current compilation unit.
5137 Sindex := Source_Index (Current_Sem_Unit);
5139 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
5140 Rewrite (N, Make_Null_Statement (Loc));
5141 return;
5143 -- If before first declaration, the pragma applies to the
5144 -- enclosing unit, and the name if present must be this name.
5146 elsif Is_Before_First_Decl (N, Plist) then
5147 Unit_Node := Unit_Declaration_Node (Current_Scope);
5148 Unit_Kind := Nkind (Unit_Node);
5150 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
5151 Pragma_Misplaced;
5153 elsif Unit_Kind = N_Subprogram_Body
5154 and then not Acts_As_Spec (Unit_Node)
5155 then
5156 Pragma_Misplaced;
5158 elsif Nkind (Parent_Node) = N_Package_Body then
5159 Pragma_Misplaced;
5161 elsif Nkind (Parent_Node) = N_Package_Specification
5162 and then Plist = Private_Declarations (Parent_Node)
5163 then
5164 Pragma_Misplaced;
5166 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
5167 or else Nkind (Parent_Node) =
5168 N_Generic_Subprogram_Declaration)
5169 and then Plist = Generic_Formal_Declarations (Parent_Node)
5170 then
5171 Pragma_Misplaced;
5173 elsif Arg_Count > 0 then
5174 Analyze (Get_Pragma_Arg (Arg1));
5176 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
5177 Error_Pragma_Arg
5178 ("name in pragma% must be enclosing unit", Arg1);
5179 end if;
5181 -- It is legal to have no argument in this context
5183 else
5184 return;
5185 end if;
5187 -- Error if not before first declaration. This is because a
5188 -- library unit pragma argument must be the name of a library
5189 -- unit (RM 10.1.5(7)), but the only names permitted in this
5190 -- context are (RM 10.1.5(6)) names of subprogram declarations,
5191 -- generic subprogram declarations or generic instantiations.
5193 else
5194 Error_Pragma
5195 ("pragma% misplaced, must be before first declaration");
5196 end if;
5197 end if;
5198 end if;
5199 end Check_Valid_Library_Unit_Pragma;
5201 -------------------
5202 -- Check_Variant --
5203 -------------------
5205 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
5206 Clist : constant Node_Id := Component_List (Variant);
5207 Comp : Node_Id;
5209 begin
5210 Comp := First (Component_Items (Clist));
5211 while Present (Comp) loop
5212 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
5213 Next (Comp);
5214 end loop;
5215 end Check_Variant;
5217 -----------------------------
5218 -- Create_Generic_Template --
5219 -----------------------------
5221 procedure Create_Generic_Template
5222 (Prag : Node_Id;
5223 Subp_Id : Entity_Id)
5225 begin
5226 if Comes_From_Source (Prag)
5227 and then Is_Generic_Subprogram (Subp_Id)
5228 then
5229 Rewrite
5230 (Prag, Copy_Generic_Node (Prag, Empty, Instantiating => False));
5231 end if;
5232 end Create_Generic_Template;
5234 ---------------------------
5235 -- Ensure_Aggregate_Form --
5236 ---------------------------
5238 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
5239 CFSD : constant Boolean := Get_Comes_From_Source_Default;
5240 Expr : constant Node_Id := Expression (Arg);
5241 Loc : constant Source_Ptr := Sloc (Expr);
5242 Comps : List_Id := No_List;
5243 Exprs : List_Id := No_List;
5244 Nam : Name_Id := No_Name;
5245 Nam_Loc : Source_Ptr;
5247 begin
5248 -- The pragma argument is in positional form:
5250 -- pragma Depends (Nam => ...)
5251 -- ^
5252 -- Chars field
5254 -- Note that the Sloc of the Chars field is the Sloc of the pragma
5255 -- argument association.
5257 if Nkind (Arg) = N_Pragma_Argument_Association then
5258 Nam := Chars (Arg);
5259 Nam_Loc := Sloc (Arg);
5261 -- Remove the pragma argument name as this will be captured in the
5262 -- aggregate.
5264 Set_Chars (Arg, No_Name);
5265 end if;
5267 -- The argument is already in aggregate form, but the presence of a
5268 -- name causes this to be interpreted as named association which in
5269 -- turn must be converted into an aggregate.
5271 -- pragma Global (In_Out => (A, B, C))
5272 -- ^ ^
5273 -- name aggregate
5275 -- pragma Global ((In_Out => (A, B, C)))
5276 -- ^ ^
5277 -- aggregate aggregate
5279 if Nkind (Expr) = N_Aggregate then
5280 if Nam = No_Name then
5281 return;
5282 end if;
5284 -- Do not transform a null argument into an aggregate as N_Null has
5285 -- special meaning in formal verification pragmas.
5287 elsif Nkind (Expr) = N_Null then
5288 return;
5289 end if;
5291 -- Everything comes from source if the original comes from source
5293 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
5295 -- Positional argument is transformed into an aggregate with an
5296 -- Expressions list.
5298 if Nam = No_Name then
5299 Exprs := New_List (Relocate_Node (Expr));
5301 -- An associative argument is transformed into an aggregate with
5302 -- Component_Associations.
5304 else
5305 Comps := New_List (
5306 Make_Component_Association (Loc,
5307 Choices => New_List (Make_Identifier (Nam_Loc, Nam)),
5308 Expression => Relocate_Node (Expr)));
5309 end if;
5311 Set_Expression (Arg,
5312 Make_Aggregate (Loc,
5313 Component_Associations => Comps,
5314 Expressions => Exprs));
5316 -- Restore Comes_From_Source default
5318 Set_Comes_From_Source_Default (CFSD);
5319 end Ensure_Aggregate_Form;
5321 ------------------
5322 -- Error_Pragma --
5323 ------------------
5325 procedure Error_Pragma (Msg : String) is
5326 begin
5327 Error_Msg_Name_1 := Pname;
5328 Error_Msg_N (Fix_Error (Msg), N);
5329 raise Pragma_Exit;
5330 end Error_Pragma;
5332 ----------------------
5333 -- Error_Pragma_Arg --
5334 ----------------------
5336 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
5337 begin
5338 Error_Msg_Name_1 := Pname;
5339 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
5340 raise Pragma_Exit;
5341 end Error_Pragma_Arg;
5343 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
5344 begin
5345 Error_Msg_Name_1 := Pname;
5346 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
5347 Error_Pragma_Arg (Msg2, Arg);
5348 end Error_Pragma_Arg;
5350 ----------------------------
5351 -- Error_Pragma_Arg_Ident --
5352 ----------------------------
5354 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
5355 begin
5356 Error_Msg_Name_1 := Pname;
5357 Error_Msg_N (Fix_Error (Msg), Arg);
5358 raise Pragma_Exit;
5359 end Error_Pragma_Arg_Ident;
5361 ----------------------
5362 -- Error_Pragma_Ref --
5363 ----------------------
5365 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
5366 begin
5367 Error_Msg_Name_1 := Pname;
5368 Error_Msg_Sloc := Sloc (Ref);
5369 Error_Msg_NE (Fix_Error (Msg), N, Ref);
5370 raise Pragma_Exit;
5371 end Error_Pragma_Ref;
5373 ------------------------
5374 -- Find_Lib_Unit_Name --
5375 ------------------------
5377 function Find_Lib_Unit_Name return Entity_Id is
5378 begin
5379 -- Return inner compilation unit entity, for case of nested
5380 -- categorization pragmas. This happens in generic unit.
5382 if Nkind (Parent (N)) = N_Package_Specification
5383 and then Defining_Entity (Parent (N)) /= Current_Scope
5384 then
5385 return Defining_Entity (Parent (N));
5386 else
5387 return Current_Scope;
5388 end if;
5389 end Find_Lib_Unit_Name;
5391 ----------------------------
5392 -- Find_Program_Unit_Name --
5393 ----------------------------
5395 procedure Find_Program_Unit_Name (Id : Node_Id) is
5396 Unit_Name : Entity_Id;
5397 Unit_Kind : Node_Kind;
5398 P : constant Node_Id := Parent (N);
5400 begin
5401 if Nkind (P) = N_Compilation_Unit then
5402 Unit_Kind := Nkind (Unit (P));
5404 if Nkind_In (Unit_Kind, N_Subprogram_Declaration,
5405 N_Package_Declaration)
5406 or else Unit_Kind in N_Generic_Declaration
5407 then
5408 Unit_Name := Defining_Entity (Unit (P));
5410 if Chars (Id) = Chars (Unit_Name) then
5411 Set_Entity (Id, Unit_Name);
5412 Set_Etype (Id, Etype (Unit_Name));
5413 else
5414 Set_Etype (Id, Any_Type);
5415 Error_Pragma
5416 ("cannot find program unit referenced by pragma%");
5417 end if;
5419 else
5420 Set_Etype (Id, Any_Type);
5421 Error_Pragma ("pragma% inapplicable to this unit");
5422 end if;
5424 else
5425 Analyze (Id);
5426 end if;
5427 end Find_Program_Unit_Name;
5429 -----------------------------------------
5430 -- Find_Unique_Parameterless_Procedure --
5431 -----------------------------------------
5433 function Find_Unique_Parameterless_Procedure
5434 (Name : Entity_Id;
5435 Arg : Node_Id) return Entity_Id
5437 Proc : Entity_Id := Empty;
5439 begin
5440 -- The body of this procedure needs some comments ???
5442 if not Is_Entity_Name (Name) then
5443 Error_Pragma_Arg
5444 ("argument of pragma% must be entity name", Arg);
5446 elsif not Is_Overloaded (Name) then
5447 Proc := Entity (Name);
5449 if Ekind (Proc) /= E_Procedure
5450 or else Present (First_Formal (Proc))
5451 then
5452 Error_Pragma_Arg
5453 ("argument of pragma% must be parameterless procedure", Arg);
5454 end if;
5456 else
5457 declare
5458 Found : Boolean := False;
5459 It : Interp;
5460 Index : Interp_Index;
5462 begin
5463 Get_First_Interp (Name, Index, It);
5464 while Present (It.Nam) loop
5465 Proc := It.Nam;
5467 if Ekind (Proc) = E_Procedure
5468 and then No (First_Formal (Proc))
5469 then
5470 if not Found then
5471 Found := True;
5472 Set_Entity (Name, Proc);
5473 Set_Is_Overloaded (Name, False);
5474 else
5475 Error_Pragma_Arg
5476 ("ambiguous handler name for pragma% ", Arg);
5477 end if;
5478 end if;
5480 Get_Next_Interp (Index, It);
5481 end loop;
5483 if not Found then
5484 Error_Pragma_Arg
5485 ("argument of pragma% must be parameterless procedure",
5486 Arg);
5487 else
5488 Proc := Entity (Name);
5489 end if;
5490 end;
5491 end if;
5493 return Proc;
5494 end Find_Unique_Parameterless_Procedure;
5496 ---------------
5497 -- Fix_Error --
5498 ---------------
5500 function Fix_Error (Msg : String) return String is
5501 Res : String (Msg'Range) := Msg;
5502 Res_Last : Natural := Msg'Last;
5503 J : Natural;
5505 begin
5506 -- If we have a rewriting of another pragma, go to that pragma
5508 if Is_Rewrite_Substitution (N)
5509 and then Nkind (Original_Node (N)) = N_Pragma
5510 then
5511 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
5512 end if;
5514 -- Case where pragma comes from an aspect specification
5516 if From_Aspect_Specification (N) then
5518 -- Change appearence of "pragma" in message to "aspect"
5520 J := Res'First;
5521 while J <= Res_Last - 5 loop
5522 if Res (J .. J + 5) = "pragma" then
5523 Res (J .. J + 5) := "aspect";
5524 J := J + 6;
5526 else
5527 J := J + 1;
5528 end if;
5529 end loop;
5531 -- Change "argument of" at start of message to "entity for"
5533 if Res'Length > 11
5534 and then Res (Res'First .. Res'First + 10) = "argument of"
5535 then
5536 Res (Res'First .. Res'First + 9) := "entity for";
5537 Res (Res'First + 10 .. Res_Last - 1) :=
5538 Res (Res'First + 11 .. Res_Last);
5539 Res_Last := Res_Last - 1;
5540 end if;
5542 -- Change "argument" at start of message to "entity"
5544 if Res'Length > 8
5545 and then Res (Res'First .. Res'First + 7) = "argument"
5546 then
5547 Res (Res'First .. Res'First + 5) := "entity";
5548 Res (Res'First + 6 .. Res_Last - 2) :=
5549 Res (Res'First + 8 .. Res_Last);
5550 Res_Last := Res_Last - 2;
5551 end if;
5553 -- Get name from corresponding aspect
5555 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
5556 end if;
5558 -- Return possibly modified message
5560 return Res (Res'First .. Res_Last);
5561 end Fix_Error;
5563 -------------------------
5564 -- Gather_Associations --
5565 -------------------------
5567 procedure Gather_Associations
5568 (Names : Name_List;
5569 Args : out Args_List)
5571 Arg : Node_Id;
5573 begin
5574 -- Initialize all parameters to Empty
5576 for J in Args'Range loop
5577 Args (J) := Empty;
5578 end loop;
5580 -- That's all we have to do if there are no argument associations
5582 if No (Pragma_Argument_Associations (N)) then
5583 return;
5584 end if;
5586 -- Otherwise first deal with any positional parameters present
5588 Arg := First (Pragma_Argument_Associations (N));
5589 for Index in Args'Range loop
5590 exit when No (Arg) or else Chars (Arg) /= No_Name;
5591 Args (Index) := Get_Pragma_Arg (Arg);
5592 Next (Arg);
5593 end loop;
5595 -- Positional parameters all processed, if any left, then we
5596 -- have too many positional parameters.
5598 if Present (Arg) and then Chars (Arg) = No_Name then
5599 Error_Pragma_Arg
5600 ("too many positional associations for pragma%", Arg);
5601 end if;
5603 -- Process named parameters if any are present
5605 while Present (Arg) loop
5606 if Chars (Arg) = No_Name then
5607 Error_Pragma_Arg
5608 ("positional association cannot follow named association",
5609 Arg);
5611 else
5612 for Index in Names'Range loop
5613 if Names (Index) = Chars (Arg) then
5614 if Present (Args (Index)) then
5615 Error_Pragma_Arg
5616 ("duplicate argument association for pragma%", Arg);
5617 else
5618 Args (Index) := Get_Pragma_Arg (Arg);
5619 exit;
5620 end if;
5621 end if;
5623 if Index = Names'Last then
5624 Error_Msg_Name_1 := Pname;
5625 Error_Msg_N ("pragma% does not allow & argument", Arg);
5627 -- Check for possible misspelling
5629 for Index1 in Names'Range loop
5630 if Is_Bad_Spelling_Of
5631 (Chars (Arg), Names (Index1))
5632 then
5633 Error_Msg_Name_1 := Names (Index1);
5634 Error_Msg_N -- CODEFIX
5635 ("\possible misspelling of%", Arg);
5636 exit;
5637 end if;
5638 end loop;
5640 raise Pragma_Exit;
5641 end if;
5642 end loop;
5643 end if;
5645 Next (Arg);
5646 end loop;
5647 end Gather_Associations;
5649 -----------------
5650 -- GNAT_Pragma --
5651 -----------------
5653 procedure GNAT_Pragma is
5654 begin
5655 -- We need to check the No_Implementation_Pragmas restriction for
5656 -- the case of a pragma from source. Note that the case of aspects
5657 -- generating corresponding pragmas marks these pragmas as not being
5658 -- from source, so this test also catches that case.
5660 if Comes_From_Source (N) then
5661 Check_Restriction (No_Implementation_Pragmas, N);
5662 end if;
5663 end GNAT_Pragma;
5665 --------------------------
5666 -- Is_Before_First_Decl --
5667 --------------------------
5669 function Is_Before_First_Decl
5670 (Pragma_Node : Node_Id;
5671 Decls : List_Id) return Boolean
5673 Item : Node_Id := First (Decls);
5675 begin
5676 -- Only other pragmas can come before this pragma
5678 loop
5679 if No (Item) or else Nkind (Item) /= N_Pragma then
5680 return False;
5682 elsif Item = Pragma_Node then
5683 return True;
5684 end if;
5686 Next (Item);
5687 end loop;
5688 end Is_Before_First_Decl;
5690 -----------------------------
5691 -- Is_Configuration_Pragma --
5692 -----------------------------
5694 -- A configuration pragma must appear in the context clause of a
5695 -- compilation unit, and only other pragmas may precede it. Note that
5696 -- the test below also permits use in a configuration pragma file.
5698 function Is_Configuration_Pragma return Boolean is
5699 Lis : constant List_Id := List_Containing (N);
5700 Par : constant Node_Id := Parent (N);
5701 Prg : Node_Id;
5703 begin
5704 -- If no parent, then we are in the configuration pragma file,
5705 -- so the placement is definitely appropriate.
5707 if No (Par) then
5708 return True;
5710 -- Otherwise we must be in the context clause of a compilation unit
5711 -- and the only thing allowed before us in the context list is more
5712 -- configuration pragmas.
5714 elsif Nkind (Par) = N_Compilation_Unit
5715 and then Context_Items (Par) = Lis
5716 then
5717 Prg := First (Lis);
5719 loop
5720 if Prg = N then
5721 return True;
5722 elsif Nkind (Prg) /= N_Pragma then
5723 return False;
5724 end if;
5726 Next (Prg);
5727 end loop;
5729 else
5730 return False;
5731 end if;
5732 end Is_Configuration_Pragma;
5734 --------------------------
5735 -- Is_In_Context_Clause --
5736 --------------------------
5738 function Is_In_Context_Clause return Boolean is
5739 Plist : List_Id;
5740 Parent_Node : Node_Id;
5742 begin
5743 if not Is_List_Member (N) then
5744 return False;
5746 else
5747 Plist := List_Containing (N);
5748 Parent_Node := Parent (Plist);
5750 if Parent_Node = Empty
5751 or else Nkind (Parent_Node) /= N_Compilation_Unit
5752 or else Context_Items (Parent_Node) /= Plist
5753 then
5754 return False;
5755 end if;
5756 end if;
5758 return True;
5759 end Is_In_Context_Clause;
5761 ---------------------------------
5762 -- Is_Static_String_Expression --
5763 ---------------------------------
5765 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
5766 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5767 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
5769 begin
5770 Analyze_And_Resolve (Argx);
5772 -- Special case Ada 83, where the expression will never be static,
5773 -- but we will return true if we had a string literal to start with.
5775 if Ada_Version = Ada_83 then
5776 return Lit;
5778 -- Normal case, true only if we end up with a string literal that
5779 -- is marked as being the result of evaluating a static expression.
5781 else
5782 return Is_OK_Static_Expression (Argx)
5783 and then Nkind (Argx) = N_String_Literal;
5784 end if;
5786 end Is_Static_String_Expression;
5788 ----------------------
5789 -- Pragma_Misplaced --
5790 ----------------------
5792 procedure Pragma_Misplaced is
5793 begin
5794 Error_Pragma ("incorrect placement of pragma%");
5795 end Pragma_Misplaced;
5797 ------------------------------------------------
5798 -- Process_Atomic_Independent_Shared_Volatile --
5799 ------------------------------------------------
5801 procedure Process_Atomic_Independent_Shared_Volatile is
5802 E_Id : Node_Id;
5803 E : Entity_Id;
5804 D : Node_Id;
5805 K : Node_Kind;
5806 Utyp : Entity_Id;
5808 procedure Set_Atomic (E : Entity_Id);
5809 -- Set given type as atomic, and if no explicit alignment was given,
5810 -- set alignment to unknown, since back end knows what the alignment
5811 -- requirements are for atomic arrays. Note: this step is necessary
5812 -- for derived types.
5814 ----------------
5815 -- Set_Atomic --
5816 ----------------
5818 procedure Set_Atomic (E : Entity_Id) is
5819 begin
5820 Set_Is_Atomic (E);
5822 if not Has_Alignment_Clause (E) then
5823 Set_Alignment (E, Uint_0);
5824 end if;
5825 end Set_Atomic;
5827 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
5829 begin
5830 Check_Ada_83_Warning;
5831 Check_No_Identifiers;
5832 Check_Arg_Count (1);
5833 Check_Arg_Is_Local_Name (Arg1);
5834 E_Id := Get_Pragma_Arg (Arg1);
5836 if Etype (E_Id) = Any_Type then
5837 return;
5838 end if;
5840 E := Entity (E_Id);
5841 D := Declaration_Node (E);
5842 K := Nkind (D);
5844 -- Check duplicate before we chain ourselves
5846 Check_Duplicate_Pragma (E);
5848 -- Now check appropriateness of the entity
5850 if Is_Type (E) then
5851 if Rep_Item_Too_Early (E, N)
5852 or else
5853 Rep_Item_Too_Late (E, N)
5854 then
5855 return;
5856 else
5857 Check_First_Subtype (Arg1);
5858 end if;
5860 if Prag_Id = Pragma_Atomic or else Prag_Id = Pragma_Shared then
5861 Set_Atomic (E);
5862 Set_Atomic (Underlying_Type (E));
5863 Set_Atomic (Base_Type (E));
5864 end if;
5866 -- Atomic/Shared imply both Independent and Volatile
5868 if Prag_Id /= Pragma_Volatile then
5869 Set_Is_Independent (E);
5870 Set_Is_Independent (Underlying_Type (E));
5871 Set_Is_Independent (Base_Type (E));
5873 if Prag_Id = Pragma_Independent then
5874 Record_Independence_Check (N, Base_Type (E));
5875 end if;
5876 end if;
5878 -- Attribute belongs on the base type. If the view of the type is
5879 -- currently private, it also belongs on the underlying type.
5881 if Prag_Id /= Pragma_Independent then
5882 Set_Is_Volatile (Base_Type (E));
5883 Set_Is_Volatile (Underlying_Type (E));
5885 Set_Treat_As_Volatile (E);
5886 Set_Treat_As_Volatile (Underlying_Type (E));
5887 end if;
5889 elsif K = N_Object_Declaration
5890 or else (K = N_Component_Declaration
5891 and then Original_Record_Component (E) = E)
5892 then
5893 if Rep_Item_Too_Late (E, N) then
5894 return;
5895 end if;
5897 if Prag_Id = Pragma_Atomic or else Prag_Id = Pragma_Shared then
5898 Set_Is_Atomic (E);
5900 -- If the object declaration has an explicit initialization, a
5901 -- temporary may have to be created to hold the expression, to
5902 -- ensure that access to the object remain atomic.
5904 if Nkind (Parent (E)) = N_Object_Declaration
5905 and then Present (Expression (Parent (E)))
5906 then
5907 Set_Has_Delayed_Freeze (E);
5908 end if;
5910 -- An interesting improvement here. If an object of composite
5911 -- type X is declared atomic, and the type X isn't, that's a
5912 -- pity, since it may not have appropriate alignment etc. We
5913 -- can rescue this in the special case where the object and
5914 -- type are in the same unit by just setting the type as
5915 -- atomic, so that the back end will process it as atomic.
5917 -- Note: we used to do this for elementary types as well,
5918 -- but that turns out to be a bad idea and can have unwanted
5919 -- effects, most notably if the type is elementary, the object
5920 -- a simple component within a record, and both are in a spec:
5921 -- every object of this type in the entire program will be
5922 -- treated as atomic, thus incurring a potentially costly
5923 -- synchronization operation for every access.
5925 -- Of course it would be best if the back end could just adjust
5926 -- the alignment etc for the specific object, but that's not
5927 -- something we are capable of doing at this point.
5929 Utyp := Underlying_Type (Etype (E));
5931 if Present (Utyp)
5932 and then Is_Composite_Type (Utyp)
5933 and then Sloc (E) > No_Location
5934 and then Sloc (Utyp) > No_Location
5935 and then
5936 Get_Source_File_Index (Sloc (E)) =
5937 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
5938 then
5939 Set_Is_Atomic (Underlying_Type (Etype (E)));
5940 end if;
5941 end if;
5943 -- Atomic/Shared imply both Independent and Volatile
5945 if Prag_Id /= Pragma_Volatile then
5946 Set_Is_Independent (E);
5948 if Prag_Id = Pragma_Independent then
5949 Record_Independence_Check (N, E);
5950 end if;
5951 end if;
5953 if Prag_Id /= Pragma_Independent then
5954 Set_Is_Volatile (E);
5955 Set_Treat_As_Volatile (E);
5956 end if;
5958 else
5959 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
5960 end if;
5962 -- The following check is only relevant when SPARK_Mode is on as
5963 -- this is not a standard Ada legality rule. Pragma Volatile can
5964 -- only apply to a full type declaration or an object declaration
5965 -- (SPARK RM C.6(1)).
5967 if SPARK_Mode = On
5968 and then Prag_Id = Pragma_Volatile
5969 and then not Nkind_In (K, N_Full_Type_Declaration,
5970 N_Object_Declaration)
5971 then
5972 Error_Pragma_Arg
5973 ("argument of pragma % must denote a full type or object "
5974 & "declaration", Arg1);
5975 end if;
5976 end Process_Atomic_Independent_Shared_Volatile;
5978 -------------------------------------------
5979 -- Process_Compile_Time_Warning_Or_Error --
5980 -------------------------------------------
5982 procedure Process_Compile_Time_Warning_Or_Error is
5983 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
5985 begin
5986 Check_Arg_Count (2);
5987 Check_No_Identifiers;
5988 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
5989 Analyze_And_Resolve (Arg1x, Standard_Boolean);
5991 if Compile_Time_Known_Value (Arg1x) then
5992 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
5993 declare
5994 Str : constant String_Id :=
5995 Strval (Get_Pragma_Arg (Arg2));
5996 Len : constant Int := String_Length (Str);
5997 Cont : Boolean;
5998 Ptr : Nat;
5999 CC : Char_Code;
6000 C : Character;
6001 Cent : constant Entity_Id :=
6002 Cunit_Entity (Current_Sem_Unit);
6004 Force : constant Boolean :=
6005 Prag_Id = Pragma_Compile_Time_Warning
6006 and then
6007 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
6008 and then (Ekind (Cent) /= E_Package
6009 or else not In_Private_Part (Cent));
6010 -- Set True if this is the warning case, and we are in the
6011 -- visible part of a package spec, or in a subprogram spec,
6012 -- in which case we want to force the client to see the
6013 -- warning, even though it is not in the main unit.
6015 begin
6016 -- Loop through segments of message separated by line feeds.
6017 -- We output these segments as separate messages with
6018 -- continuation marks for all but the first.
6020 Cont := False;
6021 Ptr := 1;
6022 loop
6023 Error_Msg_Strlen := 0;
6025 -- Loop to copy characters from argument to error message
6026 -- string buffer.
6028 loop
6029 exit when Ptr > Len;
6030 CC := Get_String_Char (Str, Ptr);
6031 Ptr := Ptr + 1;
6033 -- Ignore wide chars ??? else store character
6035 if In_Character_Range (CC) then
6036 C := Get_Character (CC);
6037 exit when C = ASCII.LF;
6038 Error_Msg_Strlen := Error_Msg_Strlen + 1;
6039 Error_Msg_String (Error_Msg_Strlen) := C;
6040 end if;
6041 end loop;
6043 -- Here with one line ready to go
6045 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
6047 -- If this is a warning in a spec, then we want clients
6048 -- to see the warning, so mark the message with the
6049 -- special sequence !! to force the warning. In the case
6050 -- of a package spec, we do not force this if we are in
6051 -- the private part of the spec.
6053 if Force then
6054 if Cont = False then
6055 Error_Msg_N ("<<~!!", Arg1);
6056 Cont := True;
6057 else
6058 Error_Msg_N ("\<<~!!", Arg1);
6059 end if;
6061 -- Error, rather than warning, or in a body, so we do not
6062 -- need to force visibility for client (error will be
6063 -- output in any case, and this is the situation in which
6064 -- we do not want a client to get a warning, since the
6065 -- warning is in the body or the spec private part).
6067 else
6068 if Cont = False then
6069 Error_Msg_N ("<<~", Arg1);
6070 Cont := True;
6071 else
6072 Error_Msg_N ("\<<~", Arg1);
6073 end if;
6074 end if;
6076 exit when Ptr > Len;
6077 end loop;
6078 end;
6079 end if;
6080 end if;
6081 end Process_Compile_Time_Warning_Or_Error;
6083 ------------------------
6084 -- Process_Convention --
6085 ------------------------
6087 procedure Process_Convention
6088 (C : out Convention_Id;
6089 Ent : out Entity_Id)
6091 Cname : Name_Id;
6093 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
6094 -- Called if we have more than one Export/Import/Convention pragma.
6095 -- This is generally illegal, but we have a special case of allowing
6096 -- Import and Interface to coexist if they specify the convention in
6097 -- a consistent manner. We are allowed to do this, since Interface is
6098 -- an implementation defined pragma, and we choose to do it since we
6099 -- know Rational allows this combination. S is the entity id of the
6100 -- subprogram in question. This procedure also sets the special flag
6101 -- Import_Interface_Present in both pragmas in the case where we do
6102 -- have matching Import and Interface pragmas.
6104 procedure Set_Convention_From_Pragma (E : Entity_Id);
6105 -- Set convention in entity E, and also flag that the entity has a
6106 -- convention pragma. If entity is for a private or incomplete type,
6107 -- also set convention and flag on underlying type. This procedure
6108 -- also deals with the special case of C_Pass_By_Copy convention,
6109 -- and error checks for inappropriate convention specification.
6111 -------------------------------
6112 -- Diagnose_Multiple_Pragmas --
6113 -------------------------------
6115 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
6116 Pdec : constant Node_Id := Declaration_Node (S);
6117 Decl : Node_Id;
6118 Err : Boolean;
6120 function Same_Convention (Decl : Node_Id) return Boolean;
6121 -- Decl is a pragma node. This function returns True if this
6122 -- pragma has a first argument that is an identifier with a
6123 -- Chars field corresponding to the Convention_Id C.
6125 function Same_Name (Decl : Node_Id) return Boolean;
6126 -- Decl is a pragma node. This function returns True if this
6127 -- pragma has a second argument that is an identifier with a
6128 -- Chars field that matches the Chars of the current subprogram.
6130 ---------------------
6131 -- Same_Convention --
6132 ---------------------
6134 function Same_Convention (Decl : Node_Id) return Boolean is
6135 Arg1 : constant Node_Id :=
6136 First (Pragma_Argument_Associations (Decl));
6138 begin
6139 if Present (Arg1) then
6140 declare
6141 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
6142 begin
6143 if Nkind (Arg) = N_Identifier
6144 and then Is_Convention_Name (Chars (Arg))
6145 and then Get_Convention_Id (Chars (Arg)) = C
6146 then
6147 return True;
6148 end if;
6149 end;
6150 end if;
6152 return False;
6153 end Same_Convention;
6155 ---------------
6156 -- Same_Name --
6157 ---------------
6159 function Same_Name (Decl : Node_Id) return Boolean is
6160 Arg1 : constant Node_Id :=
6161 First (Pragma_Argument_Associations (Decl));
6162 Arg2 : Node_Id;
6164 begin
6165 if No (Arg1) then
6166 return False;
6167 end if;
6169 Arg2 := Next (Arg1);
6171 if No (Arg2) then
6172 return False;
6173 end if;
6175 declare
6176 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
6177 begin
6178 if Nkind (Arg) = N_Identifier
6179 and then Chars (Arg) = Chars (S)
6180 then
6181 return True;
6182 end if;
6183 end;
6185 return False;
6186 end Same_Name;
6188 -- Start of processing for Diagnose_Multiple_Pragmas
6190 begin
6191 Err := True;
6193 -- Definitely give message if we have Convention/Export here
6195 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
6196 null;
6198 -- If we have an Import or Export, scan back from pragma to
6199 -- find any previous pragma applying to the same procedure.
6200 -- The scan will be terminated by the start of the list, or
6201 -- hitting the subprogram declaration. This won't allow one
6202 -- pragma to appear in the public part and one in the private
6203 -- part, but that seems very unlikely in practice.
6205 else
6206 Decl := Prev (N);
6207 while Present (Decl) and then Decl /= Pdec loop
6209 -- Look for pragma with same name as us
6211 if Nkind (Decl) = N_Pragma
6212 and then Same_Name (Decl)
6213 then
6214 -- Give error if same as our pragma or Export/Convention
6216 if Nam_In (Pragma_Name (Decl), Name_Export,
6217 Name_Convention,
6218 Pragma_Name (N))
6219 then
6220 exit;
6222 -- Case of Import/Interface or the other way round
6224 elsif Nam_In (Pragma_Name (Decl), Name_Interface,
6225 Name_Import)
6226 then
6227 -- Here we know that we have Import and Interface. It
6228 -- doesn't matter which way round they are. See if
6229 -- they specify the same convention. If so, all OK,
6230 -- and set special flags to stop other messages
6232 if Same_Convention (Decl) then
6233 Set_Import_Interface_Present (N);
6234 Set_Import_Interface_Present (Decl);
6235 Err := False;
6237 -- If different conventions, special message
6239 else
6240 Error_Msg_Sloc := Sloc (Decl);
6241 Error_Pragma_Arg
6242 ("convention differs from that given#", Arg1);
6243 return;
6244 end if;
6245 end if;
6246 end if;
6248 Next (Decl);
6249 end loop;
6250 end if;
6252 -- Give message if needed if we fall through those tests
6253 -- except on Relaxed_RM_Semantics where we let go: either this
6254 -- is a case accepted/ignored by other Ada compilers (e.g.
6255 -- a mix of Convention and Import), or another error will be
6256 -- generated later (e.g. using both Import and Export).
6258 if Err and not Relaxed_RM_Semantics then
6259 Error_Pragma_Arg
6260 ("at most one Convention/Export/Import pragma is allowed",
6261 Arg2);
6262 end if;
6263 end Diagnose_Multiple_Pragmas;
6265 --------------------------------
6266 -- Set_Convention_From_Pragma --
6267 --------------------------------
6269 procedure Set_Convention_From_Pragma (E : Entity_Id) is
6270 begin
6271 -- Ada 2005 (AI-430): Check invalid attempt to change convention
6272 -- for an overridden dispatching operation. Technically this is
6273 -- an amendment and should only be done in Ada 2005 mode. However,
6274 -- this is clearly a mistake, since the problem that is addressed
6275 -- by this AI is that there is a clear gap in the RM.
6277 if Is_Dispatching_Operation (E)
6278 and then Present (Overridden_Operation (E))
6279 and then C /= Convention (Overridden_Operation (E))
6280 then
6281 Error_Pragma_Arg
6282 ("cannot change convention for overridden dispatching "
6283 & "operation", Arg1);
6284 end if;
6286 -- Special checks for Convention_Stdcall
6288 if C = Convention_Stdcall then
6290 -- A dispatching call is not allowed. A dispatching subprogram
6291 -- cannot be used to interface to the Win32 API, so in fact
6292 -- this check does not impose any effective restriction.
6294 if Is_Dispatching_Operation (E) then
6295 Error_Msg_Sloc := Sloc (E);
6297 -- Note: make this unconditional so that if there is more
6298 -- than one call to which the pragma applies, we get a
6299 -- message for each call. Also don't use Error_Pragma,
6300 -- so that we get multiple messages.
6302 Error_Msg_N
6303 ("dispatching subprogram# cannot use Stdcall convention!",
6304 Arg1);
6306 -- Subprograms are not allowed
6308 elsif not Is_Subprogram_Or_Generic_Subprogram (E)
6310 -- A variable is OK
6312 and then Ekind (E) /= E_Variable
6314 -- An access to subprogram is also allowed
6316 and then not
6317 (Is_Access_Type (E)
6318 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
6320 -- Allow internal call to set convention of subprogram type
6322 and then not (Ekind (E) = E_Subprogram_Type)
6323 then
6324 Error_Pragma_Arg
6325 ("second argument of pragma% must be subprogram (type)",
6326 Arg2);
6327 end if;
6328 end if;
6330 -- Set the convention
6332 Set_Convention (E, C);
6333 Set_Has_Convention_Pragma (E);
6335 -- For the case of a record base type, also set the convention of
6336 -- any anonymous access types declared in the record which do not
6337 -- currently have a specified convention.
6339 if Is_Record_Type (E) and then Is_Base_Type (E) then
6340 declare
6341 Comp : Node_Id;
6343 begin
6344 Comp := First_Component (E);
6345 while Present (Comp) loop
6346 if Present (Etype (Comp))
6347 and then Ekind_In (Etype (Comp),
6348 E_Anonymous_Access_Type,
6349 E_Anonymous_Access_Subprogram_Type)
6350 and then not Has_Convention_Pragma (Comp)
6351 then
6352 Set_Convention (Comp, C);
6353 end if;
6355 Next_Component (Comp);
6356 end loop;
6357 end;
6358 end if;
6360 -- Deal with incomplete/private type case, where underlying type
6361 -- is available, so set convention of that underlying type.
6363 if Is_Incomplete_Or_Private_Type (E)
6364 and then Present (Underlying_Type (E))
6365 then
6366 Set_Convention (Underlying_Type (E), C);
6367 Set_Has_Convention_Pragma (Underlying_Type (E), True);
6368 end if;
6370 -- A class-wide type should inherit the convention of the specific
6371 -- root type (although this isn't specified clearly by the RM).
6373 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
6374 Set_Convention (Class_Wide_Type (E), C);
6375 end if;
6377 -- If the entity is a record type, then check for special case of
6378 -- C_Pass_By_Copy, which is treated the same as C except that the
6379 -- special record flag is set. This convention is only permitted
6380 -- on record types (see AI95-00131).
6382 if Cname = Name_C_Pass_By_Copy then
6383 if Is_Record_Type (E) then
6384 Set_C_Pass_By_Copy (Base_Type (E));
6385 elsif Is_Incomplete_Or_Private_Type (E)
6386 and then Is_Record_Type (Underlying_Type (E))
6387 then
6388 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
6389 else
6390 Error_Pragma_Arg
6391 ("C_Pass_By_Copy convention allowed only for record type",
6392 Arg2);
6393 end if;
6394 end if;
6396 -- If the entity is a derived boolean type, check for the special
6397 -- case of convention C, C++, or Fortran, where we consider any
6398 -- nonzero value to represent true.
6400 if Is_Discrete_Type (E)
6401 and then Root_Type (Etype (E)) = Standard_Boolean
6402 and then
6403 (C = Convention_C
6404 or else
6405 C = Convention_CPP
6406 or else
6407 C = Convention_Fortran)
6408 then
6409 Set_Nonzero_Is_True (Base_Type (E));
6410 end if;
6411 end Set_Convention_From_Pragma;
6413 -- Local variables
6415 Comp_Unit : Unit_Number_Type;
6416 E : Entity_Id;
6417 E1 : Entity_Id;
6418 Id : Node_Id;
6420 -- Start of processing for Process_Convention
6422 begin
6423 Check_At_Least_N_Arguments (2);
6424 Check_Optional_Identifier (Arg1, Name_Convention);
6425 Check_Arg_Is_Identifier (Arg1);
6426 Cname := Chars (Get_Pragma_Arg (Arg1));
6428 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
6429 -- tested again below to set the critical flag).
6431 if Cname = Name_C_Pass_By_Copy then
6432 C := Convention_C;
6434 -- Otherwise we must have something in the standard convention list
6436 elsif Is_Convention_Name (Cname) then
6437 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
6439 -- Otherwise warn on unrecognized convention
6441 else
6442 if Warn_On_Export_Import then
6443 Error_Msg_N
6444 ("??unrecognized convention name, C assumed",
6445 Get_Pragma_Arg (Arg1));
6446 end if;
6448 C := Convention_C;
6449 end if;
6451 Check_Optional_Identifier (Arg2, Name_Entity);
6452 Check_Arg_Is_Local_Name (Arg2);
6454 Id := Get_Pragma_Arg (Arg2);
6455 Analyze (Id);
6457 if not Is_Entity_Name (Id) then
6458 Error_Pragma_Arg ("entity name required", Arg2);
6459 end if;
6461 E := Entity (Id);
6463 -- Set entity to return
6465 Ent := E;
6467 -- Ada_Pass_By_Copy special checking
6469 if C = Convention_Ada_Pass_By_Copy then
6470 if not Is_First_Subtype (E) then
6471 Error_Pragma_Arg
6472 ("convention `Ada_Pass_By_Copy` only allowed for types",
6473 Arg2);
6474 end if;
6476 if Is_By_Reference_Type (E) then
6477 Error_Pragma_Arg
6478 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
6479 & "type", Arg1);
6480 end if;
6482 -- Ada_Pass_By_Reference special checking
6484 elsif C = Convention_Ada_Pass_By_Reference then
6485 if not Is_First_Subtype (E) then
6486 Error_Pragma_Arg
6487 ("convention `Ada_Pass_By_Reference` only allowed for types",
6488 Arg2);
6489 end if;
6491 if Is_By_Copy_Type (E) then
6492 Error_Pragma_Arg
6493 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
6494 & "type", Arg1);
6495 end if;
6496 end if;
6498 -- Go to renamed subprogram if present, since convention applies to
6499 -- the actual renamed entity, not to the renaming entity. If the
6500 -- subprogram is inherited, go to parent subprogram.
6502 if Is_Subprogram (E)
6503 and then Present (Alias (E))
6504 then
6505 if Nkind (Parent (Declaration_Node (E))) =
6506 N_Subprogram_Renaming_Declaration
6507 then
6508 if Scope (E) /= Scope (Alias (E)) then
6509 Error_Pragma_Ref
6510 ("cannot apply pragma% to non-local entity&#", E);
6511 end if;
6513 E := Alias (E);
6515 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
6516 N_Private_Extension_Declaration)
6517 and then Scope (E) = Scope (Alias (E))
6518 then
6519 E := Alias (E);
6521 -- Return the parent subprogram the entity was inherited from
6523 Ent := E;
6524 end if;
6525 end if;
6527 -- Check that we are not applying this to a specless body. Relax this
6528 -- check if Relaxed_RM_Semantics to accomodate other Ada compilers.
6530 if Is_Subprogram (E)
6531 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
6532 and then not Relaxed_RM_Semantics
6533 then
6534 Error_Pragma
6535 ("pragma% requires separate spec and must come before body");
6536 end if;
6538 -- Check that we are not applying this to a named constant
6540 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
6541 Error_Msg_Name_1 := Pname;
6542 Error_Msg_N
6543 ("cannot apply pragma% to named constant!",
6544 Get_Pragma_Arg (Arg2));
6545 Error_Pragma_Arg
6546 ("\supply appropriate type for&!", Arg2);
6547 end if;
6549 if Ekind (E) = E_Enumeration_Literal then
6550 Error_Pragma ("enumeration literal not allowed for pragma%");
6551 end if;
6553 -- Check for rep item appearing too early or too late
6555 if Etype (E) = Any_Type
6556 or else Rep_Item_Too_Early (E, N)
6557 then
6558 raise Pragma_Exit;
6560 elsif Present (Underlying_Type (E)) then
6561 E := Underlying_Type (E);
6562 end if;
6564 if Rep_Item_Too_Late (E, N) then
6565 raise Pragma_Exit;
6566 end if;
6568 if Has_Convention_Pragma (E) then
6569 Diagnose_Multiple_Pragmas (E);
6571 elsif Convention (E) = Convention_Protected
6572 or else Ekind (Scope (E)) = E_Protected_Type
6573 then
6574 Error_Pragma_Arg
6575 ("a protected operation cannot be given a different convention",
6576 Arg2);
6577 end if;
6579 -- For Intrinsic, a subprogram is required
6581 if C = Convention_Intrinsic
6582 and then not Is_Subprogram_Or_Generic_Subprogram (E)
6583 then
6584 Error_Pragma_Arg
6585 ("second argument of pragma% must be a subprogram", Arg2);
6586 end if;
6588 -- Deal with non-subprogram cases
6590 if not Is_Subprogram_Or_Generic_Subprogram (E) then
6591 Set_Convention_From_Pragma (E);
6593 if Is_Type (E) then
6594 Check_First_Subtype (Arg2);
6595 Set_Convention_From_Pragma (Base_Type (E));
6597 -- For access subprograms, we must set the convention on the
6598 -- internally generated directly designated type as well.
6600 if Ekind (E) = E_Access_Subprogram_Type then
6601 Set_Convention_From_Pragma (Directly_Designated_Type (E));
6602 end if;
6603 end if;
6605 -- For the subprogram case, set proper convention for all homonyms
6606 -- in same scope and the same declarative part, i.e. the same
6607 -- compilation unit.
6609 else
6610 Comp_Unit := Get_Source_Unit (E);
6611 Set_Convention_From_Pragma (E);
6613 -- Treat a pragma Import as an implicit body, and pragma import
6614 -- as implicit reference (for navigation in GPS).
6616 if Prag_Id = Pragma_Import then
6617 Generate_Reference (E, Id, 'b');
6619 -- For exported entities we restrict the generation of references
6620 -- to entities exported to foreign languages since entities
6621 -- exported to Ada do not provide further information to GPS and
6622 -- add undesired references to the output of the gnatxref tool.
6624 elsif Prag_Id = Pragma_Export
6625 and then Convention (E) /= Convention_Ada
6626 then
6627 Generate_Reference (E, Id, 'i');
6628 end if;
6630 -- If the pragma comes from from an aspect, it only applies to the
6631 -- given entity, not its homonyms.
6633 if From_Aspect_Specification (N) then
6634 return;
6635 end if;
6637 -- Otherwise Loop through the homonyms of the pragma argument's
6638 -- entity, an apply convention to those in the current scope.
6640 E1 := Ent;
6642 loop
6643 E1 := Homonym (E1);
6644 exit when No (E1) or else Scope (E1) /= Current_Scope;
6646 -- Ignore entry for which convention is already set
6648 if Has_Convention_Pragma (E1) then
6649 goto Continue;
6650 end if;
6652 -- Do not set the pragma on inherited operations or on formal
6653 -- subprograms.
6655 if Comes_From_Source (E1)
6656 and then Comp_Unit = Get_Source_Unit (E1)
6657 and then not Is_Formal_Subprogram (E1)
6658 and then Nkind (Original_Node (Parent (E1))) /=
6659 N_Full_Type_Declaration
6660 then
6661 if Present (Alias (E1))
6662 and then Scope (E1) /= Scope (Alias (E1))
6663 then
6664 Error_Pragma_Ref
6665 ("cannot apply pragma% to non-local entity& declared#",
6666 E1);
6667 end if;
6669 Set_Convention_From_Pragma (E1);
6671 if Prag_Id = Pragma_Import then
6672 Generate_Reference (E1, Id, 'b');
6673 end if;
6674 end if;
6676 <<Continue>>
6677 null;
6678 end loop;
6679 end if;
6680 end Process_Convention;
6682 ----------------------------------------
6683 -- Process_Disable_Enable_Atomic_Sync --
6684 ----------------------------------------
6686 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
6687 begin
6688 Check_No_Identifiers;
6689 Check_At_Most_N_Arguments (1);
6691 -- Modeled internally as
6692 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
6694 Rewrite (N,
6695 Make_Pragma (Loc,
6696 Pragma_Identifier =>
6697 Make_Identifier (Loc, Nam),
6698 Pragma_Argument_Associations => New_List (
6699 Make_Pragma_Argument_Association (Loc,
6700 Expression =>
6701 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
6703 if Present (Arg1) then
6704 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
6705 end if;
6707 Analyze (N);
6708 end Process_Disable_Enable_Atomic_Sync;
6710 -------------------------------------------------
6711 -- Process_Extended_Import_Export_Internal_Arg --
6712 -------------------------------------------------
6714 procedure Process_Extended_Import_Export_Internal_Arg
6715 (Arg_Internal : Node_Id := Empty)
6717 begin
6718 if No (Arg_Internal) then
6719 Error_Pragma ("Internal parameter required for pragma%");
6720 end if;
6722 if Nkind (Arg_Internal) = N_Identifier then
6723 null;
6725 elsif Nkind (Arg_Internal) = N_Operator_Symbol
6726 and then (Prag_Id = Pragma_Import_Function
6727 or else
6728 Prag_Id = Pragma_Export_Function)
6729 then
6730 null;
6732 else
6733 Error_Pragma_Arg
6734 ("wrong form for Internal parameter for pragma%", Arg_Internal);
6735 end if;
6737 Check_Arg_Is_Local_Name (Arg_Internal);
6738 end Process_Extended_Import_Export_Internal_Arg;
6740 --------------------------------------------------
6741 -- Process_Extended_Import_Export_Object_Pragma --
6742 --------------------------------------------------
6744 procedure Process_Extended_Import_Export_Object_Pragma
6745 (Arg_Internal : Node_Id;
6746 Arg_External : Node_Id;
6747 Arg_Size : Node_Id)
6749 Def_Id : Entity_Id;
6751 begin
6752 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
6753 Def_Id := Entity (Arg_Internal);
6755 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
6756 Error_Pragma_Arg
6757 ("pragma% must designate an object", Arg_Internal);
6758 end if;
6760 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
6761 or else
6762 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
6763 then
6764 Error_Pragma_Arg
6765 ("previous Common/Psect_Object applies, pragma % not permitted",
6766 Arg_Internal);
6767 end if;
6769 if Rep_Item_Too_Late (Def_Id, N) then
6770 raise Pragma_Exit;
6771 end if;
6773 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
6775 if Present (Arg_Size) then
6776 Check_Arg_Is_External_Name (Arg_Size);
6777 end if;
6779 -- Export_Object case
6781 if Prag_Id = Pragma_Export_Object then
6782 if not Is_Library_Level_Entity (Def_Id) then
6783 Error_Pragma_Arg
6784 ("argument for pragma% must be library level entity",
6785 Arg_Internal);
6786 end if;
6788 if Ekind (Current_Scope) = E_Generic_Package then
6789 Error_Pragma ("pragma& cannot appear in a generic unit");
6790 end if;
6792 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
6793 Error_Pragma_Arg
6794 ("exported object must have compile time known size",
6795 Arg_Internal);
6796 end if;
6798 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
6799 Error_Msg_N ("??duplicate Export_Object pragma", N);
6800 else
6801 Set_Exported (Def_Id, Arg_Internal);
6802 end if;
6804 -- Import_Object case
6806 else
6807 if Is_Concurrent_Type (Etype (Def_Id)) then
6808 Error_Pragma_Arg
6809 ("cannot use pragma% for task/protected object",
6810 Arg_Internal);
6811 end if;
6813 if Ekind (Def_Id) = E_Constant then
6814 Error_Pragma_Arg
6815 ("cannot import a constant", Arg_Internal);
6816 end if;
6818 if Warn_On_Export_Import
6819 and then Has_Discriminants (Etype (Def_Id))
6820 then
6821 Error_Msg_N
6822 ("imported value must be initialized??", Arg_Internal);
6823 end if;
6825 if Warn_On_Export_Import
6826 and then Is_Access_Type (Etype (Def_Id))
6827 then
6828 Error_Pragma_Arg
6829 ("cannot import object of an access type??", Arg_Internal);
6830 end if;
6832 if Warn_On_Export_Import
6833 and then Is_Imported (Def_Id)
6834 then
6835 Error_Msg_N ("??duplicate Import_Object pragma", N);
6837 -- Check for explicit initialization present. Note that an
6838 -- initialization generated by the code generator, e.g. for an
6839 -- access type, does not count here.
6841 elsif Present (Expression (Parent (Def_Id)))
6842 and then
6843 Comes_From_Source
6844 (Original_Node (Expression (Parent (Def_Id))))
6845 then
6846 Error_Msg_Sloc := Sloc (Def_Id);
6847 Error_Pragma_Arg
6848 ("imported entities cannot be initialized (RM B.1(24))",
6849 "\no initialization allowed for & declared#", Arg1);
6850 else
6851 Set_Imported (Def_Id);
6852 Note_Possible_Modification (Arg_Internal, Sure => False);
6853 end if;
6854 end if;
6855 end Process_Extended_Import_Export_Object_Pragma;
6857 ------------------------------------------------------
6858 -- Process_Extended_Import_Export_Subprogram_Pragma --
6859 ------------------------------------------------------
6861 procedure Process_Extended_Import_Export_Subprogram_Pragma
6862 (Arg_Internal : Node_Id;
6863 Arg_External : Node_Id;
6864 Arg_Parameter_Types : Node_Id;
6865 Arg_Result_Type : Node_Id := Empty;
6866 Arg_Mechanism : Node_Id;
6867 Arg_Result_Mechanism : Node_Id := Empty)
6869 Ent : Entity_Id;
6870 Def_Id : Entity_Id;
6871 Hom_Id : Entity_Id;
6872 Formal : Entity_Id;
6873 Ambiguous : Boolean;
6874 Match : Boolean;
6876 function Same_Base_Type
6877 (Ptype : Node_Id;
6878 Formal : Entity_Id) return Boolean;
6879 -- Determines if Ptype references the type of Formal. Note that only
6880 -- the base types need to match according to the spec. Ptype here is
6881 -- the argument from the pragma, which is either a type name, or an
6882 -- access attribute.
6884 --------------------
6885 -- Same_Base_Type --
6886 --------------------
6888 function Same_Base_Type
6889 (Ptype : Node_Id;
6890 Formal : Entity_Id) return Boolean
6892 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
6893 Pref : Node_Id;
6895 begin
6896 -- Case where pragma argument is typ'Access
6898 if Nkind (Ptype) = N_Attribute_Reference
6899 and then Attribute_Name (Ptype) = Name_Access
6900 then
6901 Pref := Prefix (Ptype);
6902 Find_Type (Pref);
6904 if not Is_Entity_Name (Pref)
6905 or else Entity (Pref) = Any_Type
6906 then
6907 raise Pragma_Exit;
6908 end if;
6910 -- We have a match if the corresponding argument is of an
6911 -- anonymous access type, and its designated type matches the
6912 -- type of the prefix of the access attribute
6914 return Ekind (Ftyp) = E_Anonymous_Access_Type
6915 and then Base_Type (Entity (Pref)) =
6916 Base_Type (Etype (Designated_Type (Ftyp)));
6918 -- Case where pragma argument is a type name
6920 else
6921 Find_Type (Ptype);
6923 if not Is_Entity_Name (Ptype)
6924 or else Entity (Ptype) = Any_Type
6925 then
6926 raise Pragma_Exit;
6927 end if;
6929 -- We have a match if the corresponding argument is of the type
6930 -- given in the pragma (comparing base types)
6932 return Base_Type (Entity (Ptype)) = Ftyp;
6933 end if;
6934 end Same_Base_Type;
6936 -- Start of processing for
6937 -- Process_Extended_Import_Export_Subprogram_Pragma
6939 begin
6940 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
6941 Ent := Empty;
6942 Ambiguous := False;
6944 -- Loop through homonyms (overloadings) of the entity
6946 Hom_Id := Entity (Arg_Internal);
6947 while Present (Hom_Id) loop
6948 Def_Id := Get_Base_Subprogram (Hom_Id);
6950 -- We need a subprogram in the current scope
6952 if not Is_Subprogram (Def_Id)
6953 or else Scope (Def_Id) /= Current_Scope
6954 then
6955 null;
6957 else
6958 Match := True;
6960 -- Pragma cannot apply to subprogram body
6962 if Is_Subprogram (Def_Id)
6963 and then Nkind (Parent (Declaration_Node (Def_Id))) =
6964 N_Subprogram_Body
6965 then
6966 Error_Pragma
6967 ("pragma% requires separate spec"
6968 & " and must come before body");
6969 end if;
6971 -- Test result type if given, note that the result type
6972 -- parameter can only be present for the function cases.
6974 if Present (Arg_Result_Type)
6975 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
6976 then
6977 Match := False;
6979 elsif Etype (Def_Id) /= Standard_Void_Type
6980 and then
6981 Nam_In (Pname, Name_Export_Procedure, Name_Import_Procedure)
6982 then
6983 Match := False;
6985 -- Test parameter types if given. Note that this parameter
6986 -- has not been analyzed (and must not be, since it is
6987 -- semantic nonsense), so we get it as the parser left it.
6989 elsif Present (Arg_Parameter_Types) then
6990 Check_Matching_Types : declare
6991 Formal : Entity_Id;
6992 Ptype : Node_Id;
6994 begin
6995 Formal := First_Formal (Def_Id);
6997 if Nkind (Arg_Parameter_Types) = N_Null then
6998 if Present (Formal) then
6999 Match := False;
7000 end if;
7002 -- A list of one type, e.g. (List) is parsed as
7003 -- a parenthesized expression.
7005 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
7006 and then Paren_Count (Arg_Parameter_Types) = 1
7007 then
7008 if No (Formal)
7009 or else Present (Next_Formal (Formal))
7010 then
7011 Match := False;
7012 else
7013 Match :=
7014 Same_Base_Type (Arg_Parameter_Types, Formal);
7015 end if;
7017 -- A list of more than one type is parsed as a aggregate
7019 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
7020 and then Paren_Count (Arg_Parameter_Types) = 0
7021 then
7022 Ptype := First (Expressions (Arg_Parameter_Types));
7023 while Present (Ptype) or else Present (Formal) loop
7024 if No (Ptype)
7025 or else No (Formal)
7026 or else not Same_Base_Type (Ptype, Formal)
7027 then
7028 Match := False;
7029 exit;
7030 else
7031 Next_Formal (Formal);
7032 Next (Ptype);
7033 end if;
7034 end loop;
7036 -- Anything else is of the wrong form
7038 else
7039 Error_Pragma_Arg
7040 ("wrong form for Parameter_Types parameter",
7041 Arg_Parameter_Types);
7042 end if;
7043 end Check_Matching_Types;
7044 end if;
7046 -- Match is now False if the entry we found did not match
7047 -- either a supplied Parameter_Types or Result_Types argument
7049 if Match then
7050 if No (Ent) then
7051 Ent := Def_Id;
7053 -- Ambiguous case, the flag Ambiguous shows if we already
7054 -- detected this and output the initial messages.
7056 else
7057 if not Ambiguous then
7058 Ambiguous := True;
7059 Error_Msg_Name_1 := Pname;
7060 Error_Msg_N
7061 ("pragma% does not uniquely identify subprogram!",
7063 Error_Msg_Sloc := Sloc (Ent);
7064 Error_Msg_N ("matching subprogram #!", N);
7065 Ent := Empty;
7066 end if;
7068 Error_Msg_Sloc := Sloc (Def_Id);
7069 Error_Msg_N ("matching subprogram #!", N);
7070 end if;
7071 end if;
7072 end if;
7074 Hom_Id := Homonym (Hom_Id);
7075 end loop;
7077 -- See if we found an entry
7079 if No (Ent) then
7080 if not Ambiguous then
7081 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
7082 Error_Pragma
7083 ("pragma% cannot be given for generic subprogram");
7084 else
7085 Error_Pragma
7086 ("pragma% does not identify local subprogram");
7087 end if;
7088 end if;
7090 return;
7091 end if;
7093 -- Import pragmas must be for imported entities
7095 if Prag_Id = Pragma_Import_Function
7096 or else
7097 Prag_Id = Pragma_Import_Procedure
7098 or else
7099 Prag_Id = Pragma_Import_Valued_Procedure
7100 then
7101 if not Is_Imported (Ent) then
7102 Error_Pragma
7103 ("pragma Import or Interface must precede pragma%");
7104 end if;
7106 -- Here we have the Export case which can set the entity as exported
7108 -- But does not do so if the specified external name is null, since
7109 -- that is taken as a signal in DEC Ada 83 (with which we want to be
7110 -- compatible) to request no external name.
7112 elsif Nkind (Arg_External) = N_String_Literal
7113 and then String_Length (Strval (Arg_External)) = 0
7114 then
7115 null;
7117 -- In all other cases, set entity as exported
7119 else
7120 Set_Exported (Ent, Arg_Internal);
7121 end if;
7123 -- Special processing for Valued_Procedure cases
7125 if Prag_Id = Pragma_Import_Valued_Procedure
7126 or else
7127 Prag_Id = Pragma_Export_Valued_Procedure
7128 then
7129 Formal := First_Formal (Ent);
7131 if No (Formal) then
7132 Error_Pragma ("at least one parameter required for pragma%");
7134 elsif Ekind (Formal) /= E_Out_Parameter then
7135 Error_Pragma ("first parameter must have mode out for pragma%");
7137 else
7138 Set_Is_Valued_Procedure (Ent);
7139 end if;
7140 end if;
7142 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
7144 -- Process Result_Mechanism argument if present. We have already
7145 -- checked that this is only allowed for the function case.
7147 if Present (Arg_Result_Mechanism) then
7148 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
7149 end if;
7151 -- Process Mechanism parameter if present. Note that this parameter
7152 -- is not analyzed, and must not be analyzed since it is semantic
7153 -- nonsense, so we get it in exactly as the parser left it.
7155 if Present (Arg_Mechanism) then
7156 declare
7157 Formal : Entity_Id;
7158 Massoc : Node_Id;
7159 Mname : Node_Id;
7160 Choice : Node_Id;
7162 begin
7163 -- A single mechanism association without a formal parameter
7164 -- name is parsed as a parenthesized expression. All other
7165 -- cases are parsed as aggregates, so we rewrite the single
7166 -- parameter case as an aggregate for consistency.
7168 if Nkind (Arg_Mechanism) /= N_Aggregate
7169 and then Paren_Count (Arg_Mechanism) = 1
7170 then
7171 Rewrite (Arg_Mechanism,
7172 Make_Aggregate (Sloc (Arg_Mechanism),
7173 Expressions => New_List (
7174 Relocate_Node (Arg_Mechanism))));
7175 end if;
7177 -- Case of only mechanism name given, applies to all formals
7179 if Nkind (Arg_Mechanism) /= N_Aggregate then
7180 Formal := First_Formal (Ent);
7181 while Present (Formal) loop
7182 Set_Mechanism_Value (Formal, Arg_Mechanism);
7183 Next_Formal (Formal);
7184 end loop;
7186 -- Case of list of mechanism associations given
7188 else
7189 if Null_Record_Present (Arg_Mechanism) then
7190 Error_Pragma_Arg
7191 ("inappropriate form for Mechanism parameter",
7192 Arg_Mechanism);
7193 end if;
7195 -- Deal with positional ones first
7197 Formal := First_Formal (Ent);
7199 if Present (Expressions (Arg_Mechanism)) then
7200 Mname := First (Expressions (Arg_Mechanism));
7201 while Present (Mname) loop
7202 if No (Formal) then
7203 Error_Pragma_Arg
7204 ("too many mechanism associations", Mname);
7205 end if;
7207 Set_Mechanism_Value (Formal, Mname);
7208 Next_Formal (Formal);
7209 Next (Mname);
7210 end loop;
7211 end if;
7213 -- Deal with named entries
7215 if Present (Component_Associations (Arg_Mechanism)) then
7216 Massoc := First (Component_Associations (Arg_Mechanism));
7217 while Present (Massoc) loop
7218 Choice := First (Choices (Massoc));
7220 if Nkind (Choice) /= N_Identifier
7221 or else Present (Next (Choice))
7222 then
7223 Error_Pragma_Arg
7224 ("incorrect form for mechanism association",
7225 Massoc);
7226 end if;
7228 Formal := First_Formal (Ent);
7229 loop
7230 if No (Formal) then
7231 Error_Pragma_Arg
7232 ("parameter name & not present", Choice);
7233 end if;
7235 if Chars (Choice) = Chars (Formal) then
7236 Set_Mechanism_Value
7237 (Formal, Expression (Massoc));
7239 -- Set entity on identifier (needed by ASIS)
7241 Set_Entity (Choice, Formal);
7243 exit;
7244 end if;
7246 Next_Formal (Formal);
7247 end loop;
7249 Next (Massoc);
7250 end loop;
7251 end if;
7252 end if;
7253 end;
7254 end if;
7255 end Process_Extended_Import_Export_Subprogram_Pragma;
7257 --------------------------
7258 -- Process_Generic_List --
7259 --------------------------
7261 procedure Process_Generic_List is
7262 Arg : Node_Id;
7263 Exp : Node_Id;
7265 begin
7266 Check_No_Identifiers;
7267 Check_At_Least_N_Arguments (1);
7269 -- Check all arguments are names of generic units or instances
7271 Arg := Arg1;
7272 while Present (Arg) loop
7273 Exp := Get_Pragma_Arg (Arg);
7274 Analyze (Exp);
7276 if not Is_Entity_Name (Exp)
7277 or else
7278 (not Is_Generic_Instance (Entity (Exp))
7279 and then
7280 not Is_Generic_Unit (Entity (Exp)))
7281 then
7282 Error_Pragma_Arg
7283 ("pragma% argument must be name of generic unit/instance",
7284 Arg);
7285 end if;
7287 Next (Arg);
7288 end loop;
7289 end Process_Generic_List;
7291 ------------------------------------
7292 -- Process_Import_Predefined_Type --
7293 ------------------------------------
7295 procedure Process_Import_Predefined_Type is
7296 Loc : constant Source_Ptr := Sloc (N);
7297 Elmt : Elmt_Id;
7298 Ftyp : Node_Id := Empty;
7299 Decl : Node_Id;
7300 Def : Node_Id;
7301 Nam : Name_Id;
7303 begin
7304 String_To_Name_Buffer (Strval (Expression (Arg3)));
7305 Nam := Name_Find;
7307 Elmt := First_Elmt (Predefined_Float_Types);
7308 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
7309 Next_Elmt (Elmt);
7310 end loop;
7312 Ftyp := Node (Elmt);
7314 if Present (Ftyp) then
7316 -- Don't build a derived type declaration, because predefined C
7317 -- types have no declaration anywhere, so cannot really be named.
7318 -- Instead build a full type declaration, starting with an
7319 -- appropriate type definition is built
7321 if Is_Floating_Point_Type (Ftyp) then
7322 Def := Make_Floating_Point_Definition (Loc,
7323 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
7324 Make_Real_Range_Specification (Loc,
7325 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
7326 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
7328 -- Should never have a predefined type we cannot handle
7330 else
7331 raise Program_Error;
7332 end if;
7334 -- Build and insert a Full_Type_Declaration, which will be
7335 -- analyzed as soon as this list entry has been analyzed.
7337 Decl := Make_Full_Type_Declaration (Loc,
7338 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
7339 Type_Definition => Def);
7341 Insert_After (N, Decl);
7342 Mark_Rewrite_Insertion (Decl);
7344 else
7345 Error_Pragma_Arg ("no matching type found for pragma%",
7346 Arg2);
7347 end if;
7348 end Process_Import_Predefined_Type;
7350 ---------------------------------
7351 -- Process_Import_Or_Interface --
7352 ---------------------------------
7354 procedure Process_Import_Or_Interface is
7355 C : Convention_Id;
7356 Def_Id : Entity_Id;
7357 Hom_Id : Entity_Id;
7359 begin
7360 -- In Relaxed_RM_Semantics, support old Ada 83 style:
7361 -- pragma Import (Entity, "external name");
7363 if Relaxed_RM_Semantics
7364 and then Arg_Count = 2
7365 and then Prag_Id = Pragma_Import
7366 and then Nkind (Expression (Arg2)) = N_String_Literal
7367 then
7368 C := Convention_C;
7369 Def_Id := Get_Pragma_Arg (Arg1);
7370 Analyze (Def_Id);
7372 if not Is_Entity_Name (Def_Id) then
7373 Error_Pragma_Arg ("entity name required", Arg1);
7374 end if;
7376 Def_Id := Entity (Def_Id);
7377 Kill_Size_Check_Code (Def_Id);
7378 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
7380 else
7381 Process_Convention (C, Def_Id);
7382 Kill_Size_Check_Code (Def_Id);
7383 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
7384 end if;
7386 -- Various error checks
7388 if Ekind_In (Def_Id, E_Variable, E_Constant) then
7390 -- We do not permit Import to apply to a renaming declaration
7392 if Present (Renamed_Object (Def_Id)) then
7393 Error_Pragma_Arg
7394 ("pragma% not allowed for object renaming", Arg2);
7396 -- User initialization is not allowed for imported object, but
7397 -- the object declaration may contain a default initialization,
7398 -- that will be discarded. Note that an explicit initialization
7399 -- only counts if it comes from source, otherwise it is simply
7400 -- the code generator making an implicit initialization explicit.
7402 elsif Present (Expression (Parent (Def_Id)))
7403 and then Comes_From_Source
7404 (Original_Node (Expression (Parent (Def_Id))))
7405 then
7406 -- Set imported flag to prevent cascaded errors
7408 Set_Is_Imported (Def_Id);
7410 Error_Msg_Sloc := Sloc (Def_Id);
7411 Error_Pragma_Arg
7412 ("no initialization allowed for declaration of& #",
7413 "\imported entities cannot be initialized (RM B.1(24))",
7414 Arg2);
7416 else
7417 -- If the pragma comes from an aspect specification the
7418 -- Is_Imported flag has already been set.
7420 if not From_Aspect_Specification (N) then
7421 Set_Imported (Def_Id);
7422 end if;
7424 Process_Interface_Name (Def_Id, Arg3, Arg4);
7426 -- Note that we do not set Is_Public here. That's because we
7427 -- only want to set it if there is no address clause, and we
7428 -- don't know that yet, so we delay that processing till
7429 -- freeze time.
7431 -- pragma Import completes deferred constants
7433 if Ekind (Def_Id) = E_Constant then
7434 Set_Has_Completion (Def_Id);
7435 end if;
7437 -- It is not possible to import a constant of an unconstrained
7438 -- array type (e.g. string) because there is no simple way to
7439 -- write a meaningful subtype for it.
7441 if Is_Array_Type (Etype (Def_Id))
7442 and then not Is_Constrained (Etype (Def_Id))
7443 then
7444 Error_Msg_NE
7445 ("imported constant& must have a constrained subtype",
7446 N, Def_Id);
7447 end if;
7448 end if;
7450 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
7452 -- If the name is overloaded, pragma applies to all of the denoted
7453 -- entities in the same declarative part, unless the pragma comes
7454 -- from an aspect specification or was generated by the compiler
7455 -- (such as for pragma Provide_Shift_Operators).
7457 Hom_Id := Def_Id;
7458 while Present (Hom_Id) loop
7460 Def_Id := Get_Base_Subprogram (Hom_Id);
7462 -- Ignore inherited subprograms because the pragma will apply
7463 -- to the parent operation, which is the one called.
7465 if Is_Overloadable (Def_Id)
7466 and then Present (Alias (Def_Id))
7467 then
7468 null;
7470 -- If it is not a subprogram, it must be in an outer scope and
7471 -- pragma does not apply.
7473 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
7474 null;
7476 -- The pragma does not apply to primitives of interfaces
7478 elsif Is_Dispatching_Operation (Def_Id)
7479 and then Present (Find_Dispatching_Type (Def_Id))
7480 and then Is_Interface (Find_Dispatching_Type (Def_Id))
7481 then
7482 null;
7484 -- Verify that the homonym is in the same declarative part (not
7485 -- just the same scope). If the pragma comes from an aspect
7486 -- specification we know that it is part of the declaration.
7488 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
7489 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
7490 and then not From_Aspect_Specification (N)
7491 then
7492 exit;
7494 else
7495 -- If the pragma comes from an aspect specification the
7496 -- Is_Imported flag has already been set.
7498 if not From_Aspect_Specification (N) then
7499 Set_Imported (Def_Id);
7500 end if;
7502 -- Reject an Import applied to an abstract subprogram
7504 if Is_Subprogram (Def_Id)
7505 and then Is_Abstract_Subprogram (Def_Id)
7506 then
7507 Error_Msg_Sloc := Sloc (Def_Id);
7508 Error_Msg_NE
7509 ("cannot import abstract subprogram& declared#",
7510 Arg2, Def_Id);
7511 end if;
7513 -- Special processing for Convention_Intrinsic
7515 if C = Convention_Intrinsic then
7517 -- Link_Name argument not allowed for intrinsic
7519 Check_No_Link_Name;
7521 Set_Is_Intrinsic_Subprogram (Def_Id);
7523 -- If no external name is present, then check that this
7524 -- is a valid intrinsic subprogram. If an external name
7525 -- is present, then this is handled by the back end.
7527 if No (Arg3) then
7528 Check_Intrinsic_Subprogram
7529 (Def_Id, Get_Pragma_Arg (Arg2));
7530 end if;
7531 end if;
7533 -- Verify that the subprogram does not have a completion
7534 -- through a renaming declaration. For other completions the
7535 -- pragma appears as a too late representation.
7537 declare
7538 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
7540 begin
7541 if Present (Decl)
7542 and then Nkind (Decl) = N_Subprogram_Declaration
7543 and then Present (Corresponding_Body (Decl))
7544 and then Nkind (Unit_Declaration_Node
7545 (Corresponding_Body (Decl))) =
7546 N_Subprogram_Renaming_Declaration
7547 then
7548 Error_Msg_Sloc := Sloc (Def_Id);
7549 Error_Msg_NE
7550 ("cannot import&, renaming already provided for "
7551 & "declaration #", N, Def_Id);
7552 end if;
7553 end;
7555 -- If the pragma comes from an aspect specification, there
7556 -- must be an Import aspect specified as well. In the rare
7557 -- case where Import is set to False, the suprogram needs to
7558 -- have a local completion.
7560 declare
7561 Imp_Aspect : constant Node_Id :=
7562 Find_Aspect (Def_Id, Aspect_Import);
7563 Expr : Node_Id;
7565 begin
7566 if Present (Imp_Aspect)
7567 and then Present (Expression (Imp_Aspect))
7568 then
7569 Expr := Expression (Imp_Aspect);
7570 Analyze_And_Resolve (Expr, Standard_Boolean);
7572 if Is_Entity_Name (Expr)
7573 and then Entity (Expr) = Standard_True
7574 then
7575 Set_Has_Completion (Def_Id);
7576 end if;
7578 -- If there is no expression, the default is True, as for
7579 -- all boolean aspects. Same for the older pragma.
7581 else
7582 Set_Has_Completion (Def_Id);
7583 end if;
7584 end;
7586 Process_Interface_Name (Def_Id, Arg3, Arg4);
7587 end if;
7589 if Is_Compilation_Unit (Hom_Id) then
7591 -- Its possible homonyms are not affected by the pragma.
7592 -- Such homonyms might be present in the context of other
7593 -- units being compiled.
7595 exit;
7597 elsif From_Aspect_Specification (N) then
7598 exit;
7600 -- If the pragma was created by the compiler, then we don't
7601 -- want it to apply to other homonyms. This kind of case can
7602 -- occur when using pragma Provide_Shift_Operators, which
7603 -- generates implicit shift and rotate operators with Import
7604 -- pragmas that might apply to earlier explicit or implicit
7605 -- declarations marked with Import (for example, coming from
7606 -- an earlier pragma Provide_Shift_Operators for another type),
7607 -- and we don't generally want other homonyms being treated
7608 -- as imported or the pragma flagged as an illegal duplicate.
7610 elsif not Comes_From_Source (N) then
7611 exit;
7613 else
7614 Hom_Id := Homonym (Hom_Id);
7615 end if;
7616 end loop;
7618 -- When the convention is Java or CIL, we also allow Import to
7619 -- be given for packages, generic packages, exceptions, record
7620 -- components, and access to subprograms.
7622 elsif (C = Convention_Java or else C = Convention_CIL)
7623 and then
7624 (Is_Package_Or_Generic_Package (Def_Id)
7625 or else Ekind (Def_Id) = E_Exception
7626 or else Ekind (Def_Id) = E_Access_Subprogram_Type
7627 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
7628 then
7629 Set_Imported (Def_Id);
7630 Set_Is_Public (Def_Id);
7631 Process_Interface_Name (Def_Id, Arg3, Arg4);
7633 -- Import a CPP class
7635 elsif C = Convention_CPP
7636 and then (Is_Record_Type (Def_Id)
7637 or else Ekind (Def_Id) = E_Incomplete_Type)
7638 then
7639 if Ekind (Def_Id) = E_Incomplete_Type then
7640 if Present (Full_View (Def_Id)) then
7641 Def_Id := Full_View (Def_Id);
7643 else
7644 Error_Msg_N
7645 ("cannot import 'C'P'P type before full declaration seen",
7646 Get_Pragma_Arg (Arg2));
7648 -- Although we have reported the error we decorate it as
7649 -- CPP_Class to avoid reporting spurious errors
7651 Set_Is_CPP_Class (Def_Id);
7652 return;
7653 end if;
7654 end if;
7656 -- Types treated as CPP classes must be declared limited (note:
7657 -- this used to be a warning but there is no real benefit to it
7658 -- since we did effectively intend to treat the type as limited
7659 -- anyway).
7661 if not Is_Limited_Type (Def_Id) then
7662 Error_Msg_N
7663 ("imported 'C'P'P type must be limited",
7664 Get_Pragma_Arg (Arg2));
7665 end if;
7667 if Etype (Def_Id) /= Def_Id
7668 and then not Is_CPP_Class (Root_Type (Def_Id))
7669 then
7670 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
7671 end if;
7673 Set_Is_CPP_Class (Def_Id);
7675 -- Imported CPP types must not have discriminants (because C++
7676 -- classes do not have discriminants).
7678 if Has_Discriminants (Def_Id) then
7679 Error_Msg_N
7680 ("imported 'C'P'P type cannot have discriminants",
7681 First (Discriminant_Specifications
7682 (Declaration_Node (Def_Id))));
7683 end if;
7685 -- Check that components of imported CPP types do not have default
7686 -- expressions. For private types this check is performed when the
7687 -- full view is analyzed (see Process_Full_View).
7689 if not Is_Private_Type (Def_Id) then
7690 Check_CPP_Type_Has_No_Defaults (Def_Id);
7691 end if;
7693 -- Import a CPP exception
7695 elsif C = Convention_CPP
7696 and then Ekind (Def_Id) = E_Exception
7697 then
7698 if No (Arg3) then
7699 Error_Pragma_Arg
7700 ("'External_'Name arguments is required for 'Cpp exception",
7701 Arg3);
7702 else
7703 -- As only a string is allowed, Check_Arg_Is_External_Name
7704 -- isn't called.
7706 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
7707 end if;
7709 if Present (Arg4) then
7710 Error_Pragma_Arg
7711 ("Link_Name argument not allowed for imported Cpp exception",
7712 Arg4);
7713 end if;
7715 -- Do not call Set_Interface_Name as the name of the exception
7716 -- shouldn't be modified (and in particular it shouldn't be
7717 -- the External_Name). For exceptions, the External_Name is the
7718 -- name of the RTTI structure.
7720 -- ??? Emit an error if pragma Import/Export_Exception is present
7722 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
7723 Check_No_Link_Name;
7724 Check_Arg_Count (3);
7725 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
7727 Process_Import_Predefined_Type;
7729 else
7730 Error_Pragma_Arg
7731 ("second argument of pragma% must be object, subprogram "
7732 & "or incomplete type",
7733 Arg2);
7734 end if;
7736 -- If this pragma applies to a compilation unit, then the unit, which
7737 -- is a subprogram, does not require (or allow) a body. We also do
7738 -- not need to elaborate imported procedures.
7740 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
7741 declare
7742 Cunit : constant Node_Id := Parent (Parent (N));
7743 begin
7744 Set_Body_Required (Cunit, False);
7745 end;
7746 end if;
7747 end Process_Import_Or_Interface;
7749 --------------------
7750 -- Process_Inline --
7751 --------------------
7753 procedure Process_Inline (Status : Inline_Status) is
7754 Assoc : Node_Id;
7755 Decl : Node_Id;
7756 Subp_Id : Node_Id;
7757 Subp : Entity_Id;
7758 Applies : Boolean;
7760 procedure Make_Inline (Subp : Entity_Id);
7761 -- Subp is the defining unit name of the subprogram declaration. Set
7762 -- the flag, as well as the flag in the corresponding body, if there
7763 -- is one present.
7765 procedure Set_Inline_Flags (Subp : Entity_Id);
7766 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
7767 -- Has_Pragma_Inline_Always for the Inline_Always case.
7769 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
7770 -- Returns True if it can be determined at this stage that inlining
7771 -- is not possible, for example if the body is available and contains
7772 -- exception handlers, we prevent inlining, since otherwise we can
7773 -- get undefined symbols at link time. This function also emits a
7774 -- warning if front-end inlining is enabled and the pragma appears
7775 -- too late.
7777 -- ??? is business with link symbols still valid, or does it relate
7778 -- to front end ZCX which is being phased out ???
7780 ---------------------------
7781 -- Inlining_Not_Possible --
7782 ---------------------------
7784 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
7785 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
7786 Stats : Node_Id;
7788 begin
7789 if Nkind (Decl) = N_Subprogram_Body then
7790 Stats := Handled_Statement_Sequence (Decl);
7791 return Present (Exception_Handlers (Stats))
7792 or else Present (At_End_Proc (Stats));
7794 elsif Nkind (Decl) = N_Subprogram_Declaration
7795 and then Present (Corresponding_Body (Decl))
7796 then
7797 if Front_End_Inlining
7798 and then Analyzed (Corresponding_Body (Decl))
7799 then
7800 Error_Msg_N ("pragma appears too late, ignored??", N);
7801 return True;
7803 -- If the subprogram is a renaming as body, the body is just a
7804 -- call to the renamed subprogram, and inlining is trivially
7805 -- possible.
7807 elsif
7808 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
7809 N_Subprogram_Renaming_Declaration
7810 then
7811 return False;
7813 else
7814 Stats :=
7815 Handled_Statement_Sequence
7816 (Unit_Declaration_Node (Corresponding_Body (Decl)));
7818 return
7819 Present (Exception_Handlers (Stats))
7820 or else Present (At_End_Proc (Stats));
7821 end if;
7823 else
7824 -- If body is not available, assume the best, the check is
7825 -- performed again when compiling enclosing package bodies.
7827 return False;
7828 end if;
7829 end Inlining_Not_Possible;
7831 -----------------
7832 -- Make_Inline --
7833 -----------------
7835 procedure Make_Inline (Subp : Entity_Id) is
7836 Kind : constant Entity_Kind := Ekind (Subp);
7837 Inner_Subp : Entity_Id := Subp;
7839 begin
7840 -- Ignore if bad type, avoid cascaded error
7842 if Etype (Subp) = Any_Type then
7843 Applies := True;
7844 return;
7846 -- If inlining is not possible, for now do not treat as an error
7848 elsif Status /= Suppressed
7849 and then Inlining_Not_Possible (Subp)
7850 then
7851 Applies := True;
7852 return;
7854 -- Here we have a candidate for inlining, but we must exclude
7855 -- derived operations. Otherwise we would end up trying to inline
7856 -- a phantom declaration, and the result would be to drag in a
7857 -- body which has no direct inlining associated with it. That
7858 -- would not only be inefficient but would also result in the
7859 -- backend doing cross-unit inlining in cases where it was
7860 -- definitely inappropriate to do so.
7862 -- However, a simple Comes_From_Source test is insufficient, since
7863 -- we do want to allow inlining of generic instances which also do
7864 -- not come from source. We also need to recognize specs generated
7865 -- by the front-end for bodies that carry the pragma. Finally,
7866 -- predefined operators do not come from source but are not
7867 -- inlineable either.
7869 elsif Is_Generic_Instance (Subp)
7870 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
7871 then
7872 null;
7874 elsif not Comes_From_Source (Subp)
7875 and then Scope (Subp) /= Standard_Standard
7876 then
7877 Applies := True;
7878 return;
7879 end if;
7881 -- The referenced entity must either be the enclosing entity, or
7882 -- an entity declared within the current open scope.
7884 if Present (Scope (Subp))
7885 and then Scope (Subp) /= Current_Scope
7886 and then Subp /= Current_Scope
7887 then
7888 Error_Pragma_Arg
7889 ("argument of% must be entity in current scope", Assoc);
7890 return;
7891 end if;
7893 -- Processing for procedure, operator or function. If subprogram
7894 -- is aliased (as for an instance) indicate that the renamed
7895 -- entity (if declared in the same unit) is inlined.
7897 if Is_Subprogram (Subp) then
7898 Inner_Subp := Ultimate_Alias (Inner_Subp);
7900 if In_Same_Source_Unit (Subp, Inner_Subp) then
7901 Set_Inline_Flags (Inner_Subp);
7903 Decl := Parent (Parent (Inner_Subp));
7905 if Nkind (Decl) = N_Subprogram_Declaration
7906 and then Present (Corresponding_Body (Decl))
7907 then
7908 Set_Inline_Flags (Corresponding_Body (Decl));
7910 elsif Is_Generic_Instance (Subp) then
7912 -- Indicate that the body needs to be created for
7913 -- inlining subsequent calls. The instantiation node
7914 -- follows the declaration of the wrapper package
7915 -- created for it.
7917 if Scope (Subp) /= Standard_Standard
7918 and then
7919 Need_Subprogram_Instance_Body
7920 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
7921 Subp)
7922 then
7923 null;
7924 end if;
7926 -- Inline is a program unit pragma (RM 10.1.5) and cannot
7927 -- appear in a formal part to apply to a formal subprogram.
7928 -- Do not apply check within an instance or a formal package
7929 -- the test will have been applied to the original generic.
7931 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
7932 and then List_Containing (Decl) = List_Containing (N)
7933 and then not In_Instance
7934 then
7935 Error_Msg_N
7936 ("Inline cannot apply to a formal subprogram", N);
7938 -- If Subp is a renaming, it is the renamed entity that
7939 -- will appear in any call, and be inlined. However, for
7940 -- ASIS uses it is convenient to indicate that the renaming
7941 -- itself is an inlined subprogram, so that some gnatcheck
7942 -- rules can be applied in the absence of expansion.
7944 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
7945 Set_Inline_Flags (Subp);
7946 end if;
7947 end if;
7949 Applies := True;
7951 -- For a generic subprogram set flag as well, for use at the point
7952 -- of instantiation, to determine whether the body should be
7953 -- generated.
7955 elsif Is_Generic_Subprogram (Subp) then
7956 Set_Inline_Flags (Subp);
7957 Applies := True;
7959 -- Literals are by definition inlined
7961 elsif Kind = E_Enumeration_Literal then
7962 null;
7964 -- Anything else is an error
7966 else
7967 Error_Pragma_Arg
7968 ("expect subprogram name for pragma%", Assoc);
7969 end if;
7970 end Make_Inline;
7972 ----------------------
7973 -- Set_Inline_Flags --
7974 ----------------------
7976 procedure Set_Inline_Flags (Subp : Entity_Id) is
7977 begin
7978 -- First set the Has_Pragma_XXX flags and issue the appropriate
7979 -- errors and warnings for suspicious combinations.
7981 if Prag_Id = Pragma_No_Inline then
7982 if Has_Pragma_Inline_Always (Subp) then
7983 Error_Msg_N
7984 ("Inline_Always and No_Inline are mutually exclusive", N);
7985 elsif Has_Pragma_Inline (Subp) then
7986 Error_Msg_NE
7987 ("Inline and No_Inline both specified for& ??",
7988 N, Entity (Subp_Id));
7989 end if;
7991 Set_Has_Pragma_No_Inline (Subp);
7992 else
7993 if Prag_Id = Pragma_Inline_Always then
7994 if Has_Pragma_No_Inline (Subp) then
7995 Error_Msg_N
7996 ("Inline_Always and No_Inline are mutually exclusive",
7998 end if;
8000 Set_Has_Pragma_Inline_Always (Subp);
8001 else
8002 if Has_Pragma_No_Inline (Subp) then
8003 Error_Msg_NE
8004 ("Inline and No_Inline both specified for& ??",
8005 N, Entity (Subp_Id));
8006 end if;
8007 end if;
8009 if not Has_Pragma_Inline (Subp) then
8010 Set_Has_Pragma_Inline (Subp);
8011 end if;
8012 end if;
8014 -- Then adjust the Is_Inlined flag. It can never be set if the
8015 -- subprogram is subject to pragma No_Inline.
8017 case Status is
8018 when Suppressed =>
8019 Set_Is_Inlined (Subp, False);
8020 when Disabled =>
8021 null;
8022 when Enabled =>
8023 if not Has_Pragma_No_Inline (Subp) then
8024 Set_Is_Inlined (Subp, True);
8025 end if;
8026 end case;
8027 end Set_Inline_Flags;
8029 -- Start of processing for Process_Inline
8031 begin
8032 Check_No_Identifiers;
8033 Check_At_Least_N_Arguments (1);
8035 if Status = Enabled then
8036 Inline_Processing_Required := True;
8037 end if;
8039 Assoc := Arg1;
8040 while Present (Assoc) loop
8041 Subp_Id := Get_Pragma_Arg (Assoc);
8042 Analyze (Subp_Id);
8043 Applies := False;
8045 if Is_Entity_Name (Subp_Id) then
8046 Subp := Entity (Subp_Id);
8048 if Subp = Any_Id then
8050 -- If previous error, avoid cascaded errors
8052 Check_Error_Detected;
8053 Applies := True;
8055 else
8056 Make_Inline (Subp);
8058 -- For the pragma case, climb homonym chain. This is
8059 -- what implements allowing the pragma in the renaming
8060 -- case, with the result applying to the ancestors, and
8061 -- also allows Inline to apply to all previous homonyms.
8063 if not From_Aspect_Specification (N) then
8064 while Present (Homonym (Subp))
8065 and then Scope (Homonym (Subp)) = Current_Scope
8066 loop
8067 Make_Inline (Homonym (Subp));
8068 Subp := Homonym (Subp);
8069 end loop;
8070 end if;
8071 end if;
8072 end if;
8074 if not Applies then
8075 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
8076 end if;
8078 Next (Assoc);
8079 end loop;
8080 end Process_Inline;
8082 ----------------------------
8083 -- Process_Interface_Name --
8084 ----------------------------
8086 procedure Process_Interface_Name
8087 (Subprogram_Def : Entity_Id;
8088 Ext_Arg : Node_Id;
8089 Link_Arg : Node_Id)
8091 Ext_Nam : Node_Id;
8092 Link_Nam : Node_Id;
8093 String_Val : String_Id;
8095 procedure Check_Form_Of_Interface_Name
8096 (SN : Node_Id;
8097 Ext_Name_Case : Boolean);
8098 -- SN is a string literal node for an interface name. This routine
8099 -- performs some minimal checks that the name is reasonable. In
8100 -- particular that no spaces or other obviously incorrect characters
8101 -- appear. This is only a warning, since any characters are allowed.
8102 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
8104 ----------------------------------
8105 -- Check_Form_Of_Interface_Name --
8106 ----------------------------------
8108 procedure Check_Form_Of_Interface_Name
8109 (SN : Node_Id;
8110 Ext_Name_Case : Boolean)
8112 S : constant String_Id := Strval (Expr_Value_S (SN));
8113 SL : constant Nat := String_Length (S);
8114 C : Char_Code;
8116 begin
8117 if SL = 0 then
8118 Error_Msg_N ("interface name cannot be null string", SN);
8119 end if;
8121 for J in 1 .. SL loop
8122 C := Get_String_Char (S, J);
8124 -- Look for dubious character and issue unconditional warning.
8125 -- Definitely dubious if not in character range.
8127 if not In_Character_Range (C)
8129 -- For all cases except CLI target,
8130 -- commas, spaces and slashes are dubious (in CLI, we use
8131 -- commas and backslashes in external names to specify
8132 -- assembly version and public key, while slashes and spaces
8133 -- can be used in names to mark nested classes and
8134 -- valuetypes).
8136 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
8137 and then (Get_Character (C) = ','
8138 or else
8139 Get_Character (C) = '\'))
8140 or else (VM_Target /= CLI_Target
8141 and then (Get_Character (C) = ' '
8142 or else
8143 Get_Character (C) = '/'))
8144 then
8145 Error_Msg
8146 ("??interface name contains illegal character",
8147 Sloc (SN) + Source_Ptr (J));
8148 end if;
8149 end loop;
8150 end Check_Form_Of_Interface_Name;
8152 -- Start of processing for Process_Interface_Name
8154 begin
8155 if No (Link_Arg) then
8156 if No (Ext_Arg) then
8157 if VM_Target = CLI_Target
8158 and then Ekind (Subprogram_Def) = E_Package
8159 and then Nkind (Parent (Subprogram_Def)) =
8160 N_Package_Specification
8161 and then Present (Generic_Parent (Parent (Subprogram_Def)))
8162 then
8163 Set_Interface_Name
8164 (Subprogram_Def,
8165 Interface_Name
8166 (Generic_Parent (Parent (Subprogram_Def))));
8167 end if;
8169 return;
8171 elsif Chars (Ext_Arg) = Name_Link_Name then
8172 Ext_Nam := Empty;
8173 Link_Nam := Expression (Ext_Arg);
8175 else
8176 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
8177 Ext_Nam := Expression (Ext_Arg);
8178 Link_Nam := Empty;
8179 end if;
8181 else
8182 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
8183 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
8184 Ext_Nam := Expression (Ext_Arg);
8185 Link_Nam := Expression (Link_Arg);
8186 end if;
8188 -- Check expressions for external name and link name are static
8190 if Present (Ext_Nam) then
8191 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
8192 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
8194 -- Verify that external name is not the name of a local entity,
8195 -- which would hide the imported one and could lead to run-time
8196 -- surprises. The problem can only arise for entities declared in
8197 -- a package body (otherwise the external name is fully qualified
8198 -- and will not conflict).
8200 declare
8201 Nam : Name_Id;
8202 E : Entity_Id;
8203 Par : Node_Id;
8205 begin
8206 if Prag_Id = Pragma_Import then
8207 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
8208 Nam := Name_Find;
8209 E := Entity_Id (Get_Name_Table_Int (Nam));
8211 if Nam /= Chars (Subprogram_Def)
8212 and then Present (E)
8213 and then not Is_Overloadable (E)
8214 and then Is_Immediately_Visible (E)
8215 and then not Is_Imported (E)
8216 and then Ekind (Scope (E)) = E_Package
8217 then
8218 Par := Parent (E);
8219 while Present (Par) loop
8220 if Nkind (Par) = N_Package_Body then
8221 Error_Msg_Sloc := Sloc (E);
8222 Error_Msg_NE
8223 ("imported entity is hidden by & declared#",
8224 Ext_Arg, E);
8225 exit;
8226 end if;
8228 Par := Parent (Par);
8229 end loop;
8230 end if;
8231 end if;
8232 end;
8233 end if;
8235 if Present (Link_Nam) then
8236 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
8237 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
8238 end if;
8240 -- If there is no link name, just set the external name
8242 if No (Link_Nam) then
8243 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
8245 -- For the Link_Name case, the given literal is preceded by an
8246 -- asterisk, which indicates to GCC that the given name should be
8247 -- taken literally, and in particular that no prepending of
8248 -- underlines should occur, even in systems where this is the
8249 -- normal default.
8251 else
8252 Start_String;
8254 if VM_Target = No_VM then
8255 Store_String_Char (Get_Char_Code ('*'));
8256 end if;
8258 String_Val := Strval (Expr_Value_S (Link_Nam));
8259 Store_String_Chars (String_Val);
8260 Link_Nam :=
8261 Make_String_Literal (Sloc (Link_Nam),
8262 Strval => End_String);
8263 end if;
8265 -- Set the interface name. If the entity is a generic instance, use
8266 -- its alias, which is the callable entity.
8268 if Is_Generic_Instance (Subprogram_Def) then
8269 Set_Encoded_Interface_Name
8270 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
8271 else
8272 Set_Encoded_Interface_Name
8273 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
8274 end if;
8276 -- We allow duplicated export names in CIL/Java, as they are always
8277 -- enclosed in a namespace that differentiates them, and overloaded
8278 -- entities are supported by the VM.
8280 if Convention (Subprogram_Def) /= Convention_CIL
8281 and then
8282 Convention (Subprogram_Def) /= Convention_Java
8283 then
8284 Check_Duplicated_Export_Name (Link_Nam);
8285 end if;
8286 end Process_Interface_Name;
8288 -----------------------------------------
8289 -- Process_Interrupt_Or_Attach_Handler --
8290 -----------------------------------------
8292 procedure Process_Interrupt_Or_Attach_Handler is
8293 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
8294 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
8295 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
8297 begin
8298 Set_Is_Interrupt_Handler (Handler_Proc);
8300 -- If the pragma is not associated with a handler procedure within a
8301 -- protected type, then it must be for a nonprotected procedure for
8302 -- the AAMP target, in which case we don't associate a representation
8303 -- item with the procedure's scope.
8305 if Ekind (Proc_Scope) = E_Protected_Type then
8306 if Prag_Id = Pragma_Interrupt_Handler
8307 or else
8308 Prag_Id = Pragma_Attach_Handler
8309 then
8310 Record_Rep_Item (Proc_Scope, N);
8311 end if;
8312 end if;
8313 end Process_Interrupt_Or_Attach_Handler;
8315 --------------------------------------------------
8316 -- Process_Restrictions_Or_Restriction_Warnings --
8317 --------------------------------------------------
8319 -- Note: some of the simple identifier cases were handled in par-prag,
8320 -- but it is harmless (and more straightforward) to simply handle all
8321 -- cases here, even if it means we repeat a bit of work in some cases.
8323 procedure Process_Restrictions_Or_Restriction_Warnings
8324 (Warn : Boolean)
8326 Arg : Node_Id;
8327 R_Id : Restriction_Id;
8328 Id : Name_Id;
8329 Expr : Node_Id;
8330 Val : Uint;
8332 begin
8333 -- Ignore all Restrictions pragmas in CodePeer mode
8335 if CodePeer_Mode then
8336 return;
8337 end if;
8339 Check_Ada_83_Warning;
8340 Check_At_Least_N_Arguments (1);
8341 Check_Valid_Configuration_Pragma;
8343 Arg := Arg1;
8344 while Present (Arg) loop
8345 Id := Chars (Arg);
8346 Expr := Get_Pragma_Arg (Arg);
8348 -- Case of no restriction identifier present
8350 if Id = No_Name then
8351 if Nkind (Expr) /= N_Identifier then
8352 Error_Pragma_Arg
8353 ("invalid form for restriction", Arg);
8354 end if;
8356 R_Id :=
8357 Get_Restriction_Id
8358 (Process_Restriction_Synonyms (Expr));
8360 if R_Id not in All_Boolean_Restrictions then
8361 Error_Msg_Name_1 := Pname;
8362 Error_Msg_N
8363 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
8365 -- Check for possible misspelling
8367 for J in Restriction_Id loop
8368 declare
8369 Rnm : constant String := Restriction_Id'Image (J);
8371 begin
8372 Name_Buffer (1 .. Rnm'Length) := Rnm;
8373 Name_Len := Rnm'Length;
8374 Set_Casing (All_Lower_Case);
8376 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
8377 Set_Casing
8378 (Identifier_Casing (Current_Source_File));
8379 Error_Msg_String (1 .. Rnm'Length) :=
8380 Name_Buffer (1 .. Name_Len);
8381 Error_Msg_Strlen := Rnm'Length;
8382 Error_Msg_N -- CODEFIX
8383 ("\possible misspelling of ""~""",
8384 Get_Pragma_Arg (Arg));
8385 exit;
8386 end if;
8387 end;
8388 end loop;
8390 raise Pragma_Exit;
8391 end if;
8393 if Implementation_Restriction (R_Id) then
8394 Check_Restriction (No_Implementation_Restrictions, Arg);
8395 end if;
8397 -- Special processing for No_Elaboration_Code restriction
8399 if R_Id = No_Elaboration_Code then
8401 -- Restriction is only recognized within a configuration
8402 -- pragma file, or within a unit of the main extended
8403 -- program. Note: the test for Main_Unit is needed to
8404 -- properly include the case of configuration pragma files.
8406 if not (Current_Sem_Unit = Main_Unit
8407 or else In_Extended_Main_Source_Unit (N))
8408 then
8409 return;
8411 -- Don't allow in a subunit unless already specified in
8412 -- body or spec.
8414 elsif Nkind (Parent (N)) = N_Compilation_Unit
8415 and then Nkind (Unit (Parent (N))) = N_Subunit
8416 and then not Restriction_Active (No_Elaboration_Code)
8417 then
8418 Error_Msg_N
8419 ("invalid specification of ""No_Elaboration_Code""",
8421 Error_Msg_N
8422 ("\restriction cannot be specified in a subunit", N);
8423 Error_Msg_N
8424 ("\unless also specified in body or spec", N);
8425 return;
8427 -- If we accept a No_Elaboration_Code restriction, then it
8428 -- needs to be added to the configuration restriction set so
8429 -- that we get proper application to other units in the main
8430 -- extended source as required.
8432 else
8433 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
8434 end if;
8435 end if;
8437 -- If this is a warning, then set the warning unless we already
8438 -- have a real restriction active (we never want a warning to
8439 -- override a real restriction).
8441 if Warn then
8442 if not Restriction_Active (R_Id) then
8443 Set_Restriction (R_Id, N);
8444 Restriction_Warnings (R_Id) := True;
8445 end if;
8447 -- If real restriction case, then set it and make sure that the
8448 -- restriction warning flag is off, since a real restriction
8449 -- always overrides a warning.
8451 else
8452 Set_Restriction (R_Id, N);
8453 Restriction_Warnings (R_Id) := False;
8454 end if;
8456 -- Check for obsolescent restrictions in Ada 2005 mode
8458 if not Warn
8459 and then Ada_Version >= Ada_2005
8460 and then (R_Id = No_Asynchronous_Control
8461 or else
8462 R_Id = No_Unchecked_Deallocation
8463 or else
8464 R_Id = No_Unchecked_Conversion)
8465 then
8466 Check_Restriction (No_Obsolescent_Features, N);
8467 end if;
8469 -- A very special case that must be processed here: pragma
8470 -- Restrictions (No_Exceptions) turns off all run-time
8471 -- checking. This is a bit dubious in terms of the formal
8472 -- language definition, but it is what is intended by RM
8473 -- H.4(12). Restriction_Warnings never affects generated code
8474 -- so this is done only in the real restriction case.
8476 -- Atomic_Synchronization is not a real check, so it is not
8477 -- affected by this processing).
8479 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
8480 -- run-time checks in CodePeer and GNATprove modes: we want to
8481 -- generate checks for analysis purposes, as set respectively
8482 -- by -gnatC and -gnatd.F
8484 if not Warn
8485 and then not (CodePeer_Mode or GNATprove_Mode)
8486 and then R_Id = No_Exceptions
8487 then
8488 for J in Scope_Suppress.Suppress'Range loop
8489 if J /= Atomic_Synchronization then
8490 Scope_Suppress.Suppress (J) := True;
8491 end if;
8492 end loop;
8493 end if;
8495 -- Case of No_Dependence => unit-name. Note that the parser
8496 -- already made the necessary entry in the No_Dependence table.
8498 elsif Id = Name_No_Dependence then
8499 if not OK_No_Dependence_Unit_Name (Expr) then
8500 raise Pragma_Exit;
8501 end if;
8503 -- Case of No_Specification_Of_Aspect => aspect-identifier
8505 elsif Id = Name_No_Specification_Of_Aspect then
8506 declare
8507 A_Id : Aspect_Id;
8509 begin
8510 if Nkind (Expr) /= N_Identifier then
8511 A_Id := No_Aspect;
8512 else
8513 A_Id := Get_Aspect_Id (Chars (Expr));
8514 end if;
8516 if A_Id = No_Aspect then
8517 Error_Pragma_Arg ("invalid restriction name", Arg);
8518 else
8519 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
8520 end if;
8521 end;
8523 -- Case of No_Use_Of_Attribute => attribute-identifier
8525 elsif Id = Name_No_Use_Of_Attribute then
8526 if Nkind (Expr) /= N_Identifier
8527 or else not Is_Attribute_Name (Chars (Expr))
8528 then
8529 Error_Msg_N ("unknown attribute name??", Expr);
8531 else
8532 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
8533 end if;
8535 -- Case of No_Use_Of_Entity => fully-qualified-name
8537 elsif Id = Name_No_Use_Of_Entity then
8539 -- Restriction is only recognized within a configuration
8540 -- pragma file, or within a unit of the main extended
8541 -- program. Note: the test for Main_Unit is needed to
8542 -- properly include the case of configuration pragma files.
8544 if Current_Sem_Unit = Main_Unit
8545 or else In_Extended_Main_Source_Unit (N)
8546 then
8547 if not OK_No_Dependence_Unit_Name (Expr) then
8548 Error_Msg_N ("wrong form for entity name", Expr);
8549 else
8550 Set_Restriction_No_Use_Of_Entity
8551 (Expr, Warn, No_Profile);
8552 end if;
8553 end if;
8555 -- Case of No_Use_Of_Pragma => pragma-identifier
8557 elsif Id = Name_No_Use_Of_Pragma then
8558 if Nkind (Expr) /= N_Identifier
8559 or else not Is_Pragma_Name (Chars (Expr))
8560 then
8561 Error_Msg_N ("unknown pragma name??", Expr);
8562 else
8563 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
8564 end if;
8566 -- All other cases of restriction identifier present
8568 else
8569 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
8570 Analyze_And_Resolve (Expr, Any_Integer);
8572 if R_Id not in All_Parameter_Restrictions then
8573 Error_Pragma_Arg
8574 ("invalid restriction parameter identifier", Arg);
8576 elsif not Is_OK_Static_Expression (Expr) then
8577 Flag_Non_Static_Expr
8578 ("value must be static expression!", Expr);
8579 raise Pragma_Exit;
8581 elsif not Is_Integer_Type (Etype (Expr))
8582 or else Expr_Value (Expr) < 0
8583 then
8584 Error_Pragma_Arg
8585 ("value must be non-negative integer", Arg);
8586 end if;
8588 -- Restriction pragma is active
8590 Val := Expr_Value (Expr);
8592 if not UI_Is_In_Int_Range (Val) then
8593 Error_Pragma_Arg
8594 ("pragma ignored, value too large??", Arg);
8595 end if;
8597 -- Warning case. If the real restriction is active, then we
8598 -- ignore the request, since warning never overrides a real
8599 -- restriction. Otherwise we set the proper warning. Note that
8600 -- this circuit sets the warning again if it is already set,
8601 -- which is what we want, since the constant may have changed.
8603 if Warn then
8604 if not Restriction_Active (R_Id) then
8605 Set_Restriction
8606 (R_Id, N, Integer (UI_To_Int (Val)));
8607 Restriction_Warnings (R_Id) := True;
8608 end if;
8610 -- Real restriction case, set restriction and make sure warning
8611 -- flag is off since real restriction always overrides warning.
8613 else
8614 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
8615 Restriction_Warnings (R_Id) := False;
8616 end if;
8617 end if;
8619 Next (Arg);
8620 end loop;
8621 end Process_Restrictions_Or_Restriction_Warnings;
8623 ---------------------------------
8624 -- Process_Suppress_Unsuppress --
8625 ---------------------------------
8627 -- Note: this procedure makes entries in the check suppress data
8628 -- structures managed by Sem. See spec of package Sem for full
8629 -- details on how we handle recording of check suppression.
8631 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
8632 C : Check_Id;
8633 E_Id : Node_Id;
8634 E : Entity_Id;
8636 In_Package_Spec : constant Boolean :=
8637 Is_Package_Or_Generic_Package (Current_Scope)
8638 and then not In_Package_Body (Current_Scope);
8640 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
8641 -- Used to suppress a single check on the given entity
8643 --------------------------------
8644 -- Suppress_Unsuppress_Echeck --
8645 --------------------------------
8647 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
8648 begin
8649 -- Check for error of trying to set atomic synchronization for
8650 -- a non-atomic variable.
8652 if C = Atomic_Synchronization
8653 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
8654 then
8655 Error_Msg_N
8656 ("pragma & requires atomic type or variable",
8657 Pragma_Identifier (Original_Node (N)));
8658 end if;
8660 Set_Checks_May_Be_Suppressed (E);
8662 if In_Package_Spec then
8663 Push_Global_Suppress_Stack_Entry
8664 (Entity => E,
8665 Check => C,
8666 Suppress => Suppress_Case);
8667 else
8668 Push_Local_Suppress_Stack_Entry
8669 (Entity => E,
8670 Check => C,
8671 Suppress => Suppress_Case);
8672 end if;
8674 -- If this is a first subtype, and the base type is distinct,
8675 -- then also set the suppress flags on the base type.
8677 if Is_First_Subtype (E) and then Etype (E) /= E then
8678 Suppress_Unsuppress_Echeck (Etype (E), C);
8679 end if;
8680 end Suppress_Unsuppress_Echeck;
8682 -- Start of processing for Process_Suppress_Unsuppress
8684 begin
8685 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
8686 -- on user code: we want to generate checks for analysis purposes, as
8687 -- set respectively by -gnatC and -gnatd.F
8689 if (CodePeer_Mode or GNATprove_Mode)
8690 and then Comes_From_Source (N)
8691 then
8692 return;
8693 end if;
8695 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
8696 -- declarative part or a package spec (RM 11.5(5)).
8698 if not Is_Configuration_Pragma then
8699 Check_Is_In_Decl_Part_Or_Package_Spec;
8700 end if;
8702 Check_At_Least_N_Arguments (1);
8703 Check_At_Most_N_Arguments (2);
8704 Check_No_Identifier (Arg1);
8705 Check_Arg_Is_Identifier (Arg1);
8707 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
8709 if C = No_Check_Id then
8710 Error_Pragma_Arg
8711 ("argument of pragma% is not valid check name", Arg1);
8712 end if;
8714 -- Warn that suppress of Elaboration_Check has no effect in SPARK
8716 if C = Elaboration_Check and then SPARK_Mode = On then
8717 Error_Pragma_Arg
8718 ("Suppress of Elaboration_Check ignored in SPARK??",
8719 "\elaboration checking rules are statically enforced "
8720 & "(SPARK RM 7.7)", Arg1);
8721 end if;
8723 -- One-argument case
8725 if Arg_Count = 1 then
8727 -- Make an entry in the local scope suppress table. This is the
8728 -- table that directly shows the current value of the scope
8729 -- suppress check for any check id value.
8731 if C = All_Checks then
8733 -- For All_Checks, we set all specific predefined checks with
8734 -- the exception of Elaboration_Check, which is handled
8735 -- specially because of not wanting All_Checks to have the
8736 -- effect of deactivating static elaboration order processing.
8737 -- Atomic_Synchronization is also not affected, since this is
8738 -- not a real check.
8740 for J in Scope_Suppress.Suppress'Range loop
8741 if J /= Elaboration_Check
8742 and then
8743 J /= Atomic_Synchronization
8744 then
8745 Scope_Suppress.Suppress (J) := Suppress_Case;
8746 end if;
8747 end loop;
8749 -- If not All_Checks, and predefined check, then set appropriate
8750 -- scope entry. Note that we will set Elaboration_Check if this
8751 -- is explicitly specified. Atomic_Synchronization is allowed
8752 -- only if internally generated and entity is atomic.
8754 elsif C in Predefined_Check_Id
8755 and then (not Comes_From_Source (N)
8756 or else C /= Atomic_Synchronization)
8757 then
8758 Scope_Suppress.Suppress (C) := Suppress_Case;
8759 end if;
8761 -- Also make an entry in the Local_Entity_Suppress table
8763 Push_Local_Suppress_Stack_Entry
8764 (Entity => Empty,
8765 Check => C,
8766 Suppress => Suppress_Case);
8768 -- Case of two arguments present, where the check is suppressed for
8769 -- a specified entity (given as the second argument of the pragma)
8771 else
8772 -- This is obsolescent in Ada 2005 mode
8774 if Ada_Version >= Ada_2005 then
8775 Check_Restriction (No_Obsolescent_Features, Arg2);
8776 end if;
8778 Check_Optional_Identifier (Arg2, Name_On);
8779 E_Id := Get_Pragma_Arg (Arg2);
8780 Analyze (E_Id);
8782 if not Is_Entity_Name (E_Id) then
8783 Error_Pragma_Arg
8784 ("second argument of pragma% must be entity name", Arg2);
8785 end if;
8787 E := Entity (E_Id);
8789 if E = Any_Id then
8790 return;
8791 end if;
8793 -- Enforce RM 11.5(7) which requires that for a pragma that
8794 -- appears within a package spec, the named entity must be
8795 -- within the package spec. We allow the package name itself
8796 -- to be mentioned since that makes sense, although it is not
8797 -- strictly allowed by 11.5(7).
8799 if In_Package_Spec
8800 and then E /= Current_Scope
8801 and then Scope (E) /= Current_Scope
8802 then
8803 Error_Pragma_Arg
8804 ("entity in pragma% is not in package spec (RM 11.5(7))",
8805 Arg2);
8806 end if;
8808 -- Loop through homonyms. As noted below, in the case of a package
8809 -- spec, only homonyms within the package spec are considered.
8811 loop
8812 Suppress_Unsuppress_Echeck (E, C);
8814 if Is_Generic_Instance (E)
8815 and then Is_Subprogram (E)
8816 and then Present (Alias (E))
8817 then
8818 Suppress_Unsuppress_Echeck (Alias (E), C);
8819 end if;
8821 -- Move to next homonym if not aspect spec case
8823 exit when From_Aspect_Specification (N);
8824 E := Homonym (E);
8825 exit when No (E);
8827 -- If we are within a package specification, the pragma only
8828 -- applies to homonyms in the same scope.
8830 exit when In_Package_Spec
8831 and then Scope (E) /= Current_Scope;
8832 end loop;
8833 end if;
8834 end Process_Suppress_Unsuppress;
8836 -------------------------------
8837 -- Record_Independence_Check --
8838 -------------------------------
8840 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is
8841 begin
8842 -- For GCC back ends the validation is done a priori
8844 if VM_Target = No_VM and then not AAMP_On_Target then
8845 return;
8846 end if;
8848 Independence_Checks.Append ((N, E));
8849 end Record_Independence_Check;
8851 ------------------
8852 -- Set_Exported --
8853 ------------------
8855 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
8856 begin
8857 if Is_Imported (E) then
8858 Error_Pragma_Arg
8859 ("cannot export entity& that was previously imported", Arg);
8861 elsif Present (Address_Clause (E))
8862 and then not Relaxed_RM_Semantics
8863 then
8864 Error_Pragma_Arg
8865 ("cannot export entity& that has an address clause", Arg);
8866 end if;
8868 Set_Is_Exported (E);
8870 -- Generate a reference for entity explicitly, because the
8871 -- identifier may be overloaded and name resolution will not
8872 -- generate one.
8874 Generate_Reference (E, Arg);
8876 -- Deal with exporting non-library level entity
8878 if not Is_Library_Level_Entity (E) then
8880 -- Not allowed at all for subprograms
8882 if Is_Subprogram (E) then
8883 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
8885 -- Otherwise set public and statically allocated
8887 else
8888 Set_Is_Public (E);
8889 Set_Is_Statically_Allocated (E);
8891 -- Warn if the corresponding W flag is set
8893 if Warn_On_Export_Import
8895 -- Only do this for something that was in the source. Not
8896 -- clear if this can be False now (there used for sure to be
8897 -- cases on some systems where it was False), but anyway the
8898 -- test is harmless if not needed, so it is retained.
8900 and then Comes_From_Source (Arg)
8901 then
8902 Error_Msg_NE
8903 ("?x?& has been made static as a result of Export",
8904 Arg, E);
8905 Error_Msg_N
8906 ("\?x?this usage is non-standard and non-portable",
8907 Arg);
8908 end if;
8909 end if;
8910 end if;
8912 if Warn_On_Export_Import and then Is_Type (E) then
8913 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
8914 end if;
8916 if Warn_On_Export_Import and Inside_A_Generic then
8917 Error_Msg_NE
8918 ("all instances of& will have the same external name?x?",
8919 Arg, E);
8920 end if;
8921 end Set_Exported;
8923 ----------------------------------------------
8924 -- Set_Extended_Import_Export_External_Name --
8925 ----------------------------------------------
8927 procedure Set_Extended_Import_Export_External_Name
8928 (Internal_Ent : Entity_Id;
8929 Arg_External : Node_Id)
8931 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
8932 New_Name : Node_Id;
8934 begin
8935 if No (Arg_External) then
8936 return;
8937 end if;
8939 Check_Arg_Is_External_Name (Arg_External);
8941 if Nkind (Arg_External) = N_String_Literal then
8942 if String_Length (Strval (Arg_External)) = 0 then
8943 return;
8944 else
8945 New_Name := Adjust_External_Name_Case (Arg_External);
8946 end if;
8948 elsif Nkind (Arg_External) = N_Identifier then
8949 New_Name := Get_Default_External_Name (Arg_External);
8951 -- Check_Arg_Is_External_Name should let through only identifiers and
8952 -- string literals or static string expressions (which are folded to
8953 -- string literals).
8955 else
8956 raise Program_Error;
8957 end if;
8959 -- If we already have an external name set (by a prior normal Import
8960 -- or Export pragma), then the external names must match
8962 if Present (Interface_Name (Internal_Ent)) then
8964 -- Ignore mismatching names in CodePeer mode, to support some
8965 -- old compilers which would export the same procedure under
8966 -- different names, e.g:
8967 -- procedure P;
8968 -- pragma Export_Procedure (P, "a");
8969 -- pragma Export_Procedure (P, "b");
8971 if CodePeer_Mode then
8972 return;
8973 end if;
8975 Check_Matching_Internal_Names : declare
8976 S1 : constant String_Id := Strval (Old_Name);
8977 S2 : constant String_Id := Strval (New_Name);
8979 procedure Mismatch;
8980 pragma No_Return (Mismatch);
8981 -- Called if names do not match
8983 --------------
8984 -- Mismatch --
8985 --------------
8987 procedure Mismatch is
8988 begin
8989 Error_Msg_Sloc := Sloc (Old_Name);
8990 Error_Pragma_Arg
8991 ("external name does not match that given #",
8992 Arg_External);
8993 end Mismatch;
8995 -- Start of processing for Check_Matching_Internal_Names
8997 begin
8998 if String_Length (S1) /= String_Length (S2) then
8999 Mismatch;
9001 else
9002 for J in 1 .. String_Length (S1) loop
9003 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
9004 Mismatch;
9005 end if;
9006 end loop;
9007 end if;
9008 end Check_Matching_Internal_Names;
9010 -- Otherwise set the given name
9012 else
9013 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
9014 Check_Duplicated_Export_Name (New_Name);
9015 end if;
9016 end Set_Extended_Import_Export_External_Name;
9018 ------------------
9019 -- Set_Imported --
9020 ------------------
9022 procedure Set_Imported (E : Entity_Id) is
9023 begin
9024 -- Error message if already imported or exported
9026 if Is_Exported (E) or else Is_Imported (E) then
9028 -- Error if being set Exported twice
9030 if Is_Exported (E) then
9031 Error_Msg_NE ("entity& was previously exported", N, E);
9033 -- Ignore error in CodePeer mode where we treat all imported
9034 -- subprograms as unknown.
9036 elsif CodePeer_Mode then
9037 goto OK;
9039 -- OK if Import/Interface case
9041 elsif Import_Interface_Present (N) then
9042 goto OK;
9044 -- Error if being set Imported twice
9046 else
9047 Error_Msg_NE ("entity& was previously imported", N, E);
9048 end if;
9050 Error_Msg_Name_1 := Pname;
9051 Error_Msg_N
9052 ("\(pragma% applies to all previous entities)", N);
9054 Error_Msg_Sloc := Sloc (E);
9055 Error_Msg_NE ("\import not allowed for& declared#", N, E);
9057 -- Here if not previously imported or exported, OK to import
9059 else
9060 Set_Is_Imported (E);
9062 -- For subprogram, set Import_Pragma field
9064 if Is_Subprogram (E) then
9065 Set_Import_Pragma (E, N);
9066 end if;
9068 -- If the entity is an object that is not at the library level,
9069 -- then it is statically allocated. We do not worry about objects
9070 -- with address clauses in this context since they are not really
9071 -- imported in the linker sense.
9073 if Is_Object (E)
9074 and then not Is_Library_Level_Entity (E)
9075 and then No (Address_Clause (E))
9076 then
9077 Set_Is_Statically_Allocated (E);
9078 end if;
9079 end if;
9081 <<OK>> null;
9082 end Set_Imported;
9084 -------------------------
9085 -- Set_Mechanism_Value --
9086 -------------------------
9088 -- Note: the mechanism name has not been analyzed (and cannot indeed be
9089 -- analyzed, since it is semantic nonsense), so we get it in the exact
9090 -- form created by the parser.
9092 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
9093 procedure Bad_Mechanism;
9094 pragma No_Return (Bad_Mechanism);
9095 -- Signal bad mechanism name
9097 -------------------------
9098 -- Bad_Mechanism_Value --
9099 -------------------------
9101 procedure Bad_Mechanism is
9102 begin
9103 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
9104 end Bad_Mechanism;
9106 -- Start of processing for Set_Mechanism_Value
9108 begin
9109 if Mechanism (Ent) /= Default_Mechanism then
9110 Error_Msg_NE
9111 ("mechanism for & has already been set", Mech_Name, Ent);
9112 end if;
9114 -- MECHANISM_NAME ::= value | reference
9116 if Nkind (Mech_Name) = N_Identifier then
9117 if Chars (Mech_Name) = Name_Value then
9118 Set_Mechanism (Ent, By_Copy);
9119 return;
9121 elsif Chars (Mech_Name) = Name_Reference then
9122 Set_Mechanism (Ent, By_Reference);
9123 return;
9125 elsif Chars (Mech_Name) = Name_Copy then
9126 Error_Pragma_Arg
9127 ("bad mechanism name, Value assumed", Mech_Name);
9129 else
9130 Bad_Mechanism;
9131 end if;
9133 else
9134 Bad_Mechanism;
9135 end if;
9136 end Set_Mechanism_Value;
9138 --------------------------
9139 -- Set_Rational_Profile --
9140 --------------------------
9142 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
9143 -- and extension to the semantics of renaming declarations.
9145 procedure Set_Rational_Profile is
9146 begin
9147 Implicit_Packing := True;
9148 Overriding_Renamings := True;
9149 Use_VADS_Size := True;
9150 end Set_Rational_Profile;
9152 ---------------------------
9153 -- Set_Ravenscar_Profile --
9154 ---------------------------
9156 -- The tasks to be done here are
9158 -- Set required policies
9160 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9161 -- pragma Locking_Policy (Ceiling_Locking)
9163 -- Set Detect_Blocking mode
9165 -- Set required restrictions (see System.Rident for detailed list)
9167 -- Set the No_Dependence rules
9168 -- No_Dependence => Ada.Asynchronous_Task_Control
9169 -- No_Dependence => Ada.Calendar
9170 -- No_Dependence => Ada.Execution_Time.Group_Budget
9171 -- No_Dependence => Ada.Execution_Time.Timers
9172 -- No_Dependence => Ada.Task_Attributes
9173 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9175 procedure Set_Ravenscar_Profile (N : Node_Id) is
9176 Prefix_Entity : Entity_Id;
9177 Selector_Entity : Entity_Id;
9178 Prefix_Node : Node_Id;
9179 Node : Node_Id;
9181 begin
9182 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9184 if Task_Dispatching_Policy /= ' '
9185 and then Task_Dispatching_Policy /= 'F'
9186 then
9187 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9188 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
9190 -- Set the FIFO_Within_Priorities policy, but always preserve
9191 -- System_Location since we like the error message with the run time
9192 -- name.
9194 else
9195 Task_Dispatching_Policy := 'F';
9197 if Task_Dispatching_Policy_Sloc /= System_Location then
9198 Task_Dispatching_Policy_Sloc := Loc;
9199 end if;
9200 end if;
9202 -- pragma Locking_Policy (Ceiling_Locking)
9204 if Locking_Policy /= ' '
9205 and then Locking_Policy /= 'C'
9206 then
9207 Error_Msg_Sloc := Locking_Policy_Sloc;
9208 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
9210 -- Set the Ceiling_Locking policy, but preserve System_Location since
9211 -- we like the error message with the run time name.
9213 else
9214 Locking_Policy := 'C';
9216 if Locking_Policy_Sloc /= System_Location then
9217 Locking_Policy_Sloc := Loc;
9218 end if;
9219 end if;
9221 -- pragma Detect_Blocking
9223 Detect_Blocking := True;
9225 -- Set the corresponding restrictions
9227 Set_Profile_Restrictions
9228 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
9230 -- Set the No_Dependence restrictions
9232 -- The following No_Dependence restrictions:
9233 -- No_Dependence => Ada.Asynchronous_Task_Control
9234 -- No_Dependence => Ada.Calendar
9235 -- No_Dependence => Ada.Task_Attributes
9236 -- are already set by previous call to Set_Profile_Restrictions.
9238 -- Set the following restrictions which were added to Ada 2005:
9239 -- No_Dependence => Ada.Execution_Time.Group_Budget
9240 -- No_Dependence => Ada.Execution_Time.Timers
9242 if Ada_Version >= Ada_2005 then
9243 Name_Buffer (1 .. 3) := "ada";
9244 Name_Len := 3;
9246 Prefix_Entity := Make_Identifier (Loc, Name_Find);
9248 Name_Buffer (1 .. 14) := "execution_time";
9249 Name_Len := 14;
9251 Selector_Entity := Make_Identifier (Loc, Name_Find);
9253 Prefix_Node :=
9254 Make_Selected_Component
9255 (Sloc => Loc,
9256 Prefix => Prefix_Entity,
9257 Selector_Name => Selector_Entity);
9259 Name_Buffer (1 .. 13) := "group_budgets";
9260 Name_Len := 13;
9262 Selector_Entity := Make_Identifier (Loc, Name_Find);
9264 Node :=
9265 Make_Selected_Component
9266 (Sloc => Loc,
9267 Prefix => Prefix_Node,
9268 Selector_Name => Selector_Entity);
9270 Set_Restriction_No_Dependence
9271 (Unit => Node,
9272 Warn => Treat_Restrictions_As_Warnings,
9273 Profile => Ravenscar);
9275 Name_Buffer (1 .. 6) := "timers";
9276 Name_Len := 6;
9278 Selector_Entity := Make_Identifier (Loc, Name_Find);
9280 Node :=
9281 Make_Selected_Component
9282 (Sloc => Loc,
9283 Prefix => Prefix_Node,
9284 Selector_Name => Selector_Entity);
9286 Set_Restriction_No_Dependence
9287 (Unit => Node,
9288 Warn => Treat_Restrictions_As_Warnings,
9289 Profile => Ravenscar);
9290 end if;
9292 -- Set the following restrictions which was added to Ada 2012 (see
9293 -- AI-0171):
9294 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9296 if Ada_Version >= Ada_2012 then
9297 Name_Buffer (1 .. 6) := "system";
9298 Name_Len := 6;
9300 Prefix_Entity := Make_Identifier (Loc, Name_Find);
9302 Name_Buffer (1 .. 15) := "multiprocessors";
9303 Name_Len := 15;
9305 Selector_Entity := Make_Identifier (Loc, Name_Find);
9307 Prefix_Node :=
9308 Make_Selected_Component
9309 (Sloc => Loc,
9310 Prefix => Prefix_Entity,
9311 Selector_Name => Selector_Entity);
9313 Name_Buffer (1 .. 19) := "dispatching_domains";
9314 Name_Len := 19;
9316 Selector_Entity := Make_Identifier (Loc, Name_Find);
9318 Node :=
9319 Make_Selected_Component
9320 (Sloc => Loc,
9321 Prefix => Prefix_Node,
9322 Selector_Name => Selector_Entity);
9324 Set_Restriction_No_Dependence
9325 (Unit => Node,
9326 Warn => Treat_Restrictions_As_Warnings,
9327 Profile => Ravenscar);
9328 end if;
9329 end Set_Ravenscar_Profile;
9331 -- Start of processing for Analyze_Pragma
9333 begin
9334 -- The following code is a defense against recursion. Not clear that
9335 -- this can happen legitimately, but perhaps some error situations
9336 -- can cause it, and we did see this recursion during testing.
9338 if Analyzed (N) then
9339 return;
9340 else
9341 Set_Analyzed (N, True);
9342 end if;
9344 -- Deal with unrecognized pragma
9346 Pname := Pragma_Name (N);
9348 if not Is_Pragma_Name (Pname) then
9349 if Warn_On_Unrecognized_Pragma then
9350 Error_Msg_Name_1 := Pname;
9351 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
9353 for PN in First_Pragma_Name .. Last_Pragma_Name loop
9354 if Is_Bad_Spelling_Of (Pname, PN) then
9355 Error_Msg_Name_1 := PN;
9356 Error_Msg_N -- CODEFIX
9357 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
9358 exit;
9359 end if;
9360 end loop;
9361 end if;
9363 return;
9364 end if;
9366 -- Here to start processing for recognized pragma
9368 Prag_Id := Get_Pragma_Id (Pname);
9369 Pname := Original_Aspect_Pragma_Name (N);
9371 -- Capture setting of Opt.Uneval_Old
9373 case Opt.Uneval_Old is
9374 when 'A' =>
9375 Set_Uneval_Old_Accept (N);
9376 when 'E' =>
9377 null;
9378 when 'W' =>
9379 Set_Uneval_Old_Warn (N);
9380 when others =>
9381 raise Program_Error;
9382 end case;
9384 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
9385 -- is already set, indicating that we have already checked the policy
9386 -- at the right point. This happens for example in the case of a pragma
9387 -- that is derived from an Aspect.
9389 if Is_Ignored (N) or else Is_Checked (N) then
9390 null;
9392 -- For a pragma that is a rewriting of another pragma, copy the
9393 -- Is_Checked/Is_Ignored status from the rewritten pragma.
9395 elsif Is_Rewrite_Substitution (N)
9396 and then Nkind (Original_Node (N)) = N_Pragma
9397 and then Original_Node (N) /= N
9398 then
9399 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
9400 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
9402 -- Otherwise query the applicable policy at this point
9404 else
9405 Check_Applicable_Policy (N);
9407 -- If pragma is disabled, rewrite as NULL and skip analysis
9409 if Is_Disabled (N) then
9410 Rewrite (N, Make_Null_Statement (Loc));
9411 Analyze (N);
9412 raise Pragma_Exit;
9413 end if;
9414 end if;
9416 -- Preset arguments
9418 Arg_Count := 0;
9419 Arg1 := Empty;
9420 Arg2 := Empty;
9421 Arg3 := Empty;
9422 Arg4 := Empty;
9424 if Present (Pragma_Argument_Associations (N)) then
9425 Arg_Count := List_Length (Pragma_Argument_Associations (N));
9426 Arg1 := First (Pragma_Argument_Associations (N));
9428 if Present (Arg1) then
9429 Arg2 := Next (Arg1);
9431 if Present (Arg2) then
9432 Arg3 := Next (Arg2);
9434 if Present (Arg3) then
9435 Arg4 := Next (Arg3);
9436 end if;
9437 end if;
9438 end if;
9439 end if;
9441 Check_Restriction_No_Use_Of_Pragma (N);
9443 -- An enumeration type defines the pragmas that are supported by the
9444 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
9445 -- into the corresponding enumeration value for the following case.
9447 case Prag_Id is
9449 -----------------
9450 -- Abort_Defer --
9451 -----------------
9453 -- pragma Abort_Defer;
9455 when Pragma_Abort_Defer =>
9456 GNAT_Pragma;
9457 Check_Arg_Count (0);
9459 -- The only required semantic processing is to check the
9460 -- placement. This pragma must appear at the start of the
9461 -- statement sequence of a handled sequence of statements.
9463 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
9464 or else N /= First (Statements (Parent (N)))
9465 then
9466 Pragma_Misplaced;
9467 end if;
9469 --------------------
9470 -- Abstract_State --
9471 --------------------
9473 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
9475 -- ABSTRACT_STATE_LIST ::=
9476 -- null
9477 -- | STATE_NAME_WITH_OPTIONS
9478 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS} )
9480 -- STATE_NAME_WITH_OPTIONS ::=
9481 -- STATE_NAME
9482 -- | (STATE_NAME with OPTION_LIST)
9484 -- OPTION_LIST ::= OPTION {, OPTION}
9486 -- OPTION ::=
9487 -- SIMPLE_OPTION
9488 -- | NAME_VALUE_OPTION
9490 -- SIMPLE_OPTION ::= Ghost
9492 -- NAME_VALUE_OPTION ::=
9493 -- Part_Of => ABSTRACT_STATE
9494 -- | External [=> EXTERNAL_PROPERTY_LIST]
9496 -- EXTERNAL_PROPERTY_LIST ::=
9497 -- EXTERNAL_PROPERTY
9498 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY} )
9500 -- EXTERNAL_PROPERTY ::=
9501 -- Async_Readers [=> boolean_EXPRESSION]
9502 -- | Async_Writers [=> boolean_EXPRESSION]
9503 -- | Effective_Reads [=> boolean_EXPRESSION]
9504 -- | Effective_Writes [=> boolean_EXPRESSION]
9505 -- others => boolean_EXPRESSION
9507 -- STATE_NAME ::= defining_identifier
9509 -- ABSTRACT_STATE ::= name
9511 when Pragma_Abstract_State => Abstract_State : declare
9512 Missing_Parentheses : Boolean := False;
9513 -- Flag set when a state declaration with options is not properly
9514 -- parenthesized.
9516 -- Flags used to verify the consistency of states
9518 Non_Null_Seen : Boolean := False;
9519 Null_Seen : Boolean := False;
9521 procedure Analyze_Abstract_State
9522 (State : Node_Id;
9523 Pack_Id : Entity_Id);
9524 -- Verify the legality of a single state declaration. Create and
9525 -- decorate a state abstraction entity and introduce it into the
9526 -- visibility chain. Pack_Id denotes the entity or the related
9527 -- package where pragma Abstract_State appears.
9529 procedure Malformed_State_Error (State : Node_Id);
9530 -- Emit an error concerning the illegal declaration of abstract
9531 -- state State. This routine diagnoses syntax errors that lead to
9532 -- a different parse tree. The error is issued regardless of the
9533 -- SPARK mode in effect.
9535 ----------------------------
9536 -- Analyze_Abstract_State --
9537 ----------------------------
9539 procedure Analyze_Abstract_State
9540 (State : Node_Id;
9541 Pack_Id : Entity_Id)
9543 -- Flags used to verify the consistency of options
9545 AR_Seen : Boolean := False;
9546 AW_Seen : Boolean := False;
9547 ER_Seen : Boolean := False;
9548 EW_Seen : Boolean := False;
9549 External_Seen : Boolean := False;
9550 Others_Seen : Boolean := False;
9551 Part_Of_Seen : Boolean := False;
9553 -- Flags used to store the static value of all external states'
9554 -- expressions.
9556 AR_Val : Boolean := False;
9557 AW_Val : Boolean := False;
9558 ER_Val : Boolean := False;
9559 EW_Val : Boolean := False;
9561 State_Id : Entity_Id := Empty;
9562 -- The entity to be generated for the current state declaration
9564 procedure Analyze_External_Option (Opt : Node_Id);
9565 -- Verify the legality of option External
9567 procedure Analyze_External_Property
9568 (Prop : Node_Id;
9569 Expr : Node_Id := Empty);
9570 -- Verify the legailty of a single external property. Prop
9571 -- denotes the external property. Expr is the expression used
9572 -- to set the property.
9574 procedure Analyze_Part_Of_Option (Opt : Node_Id);
9575 -- Verify the legality of option Part_Of
9577 procedure Check_Duplicate_Option
9578 (Opt : Node_Id;
9579 Status : in out Boolean);
9580 -- Flag Status denotes whether a particular option has been
9581 -- seen while processing a state. This routine verifies that
9582 -- Opt is not a duplicate option and sets the flag Status
9583 -- (SPARK RM 7.1.4(1)).
9585 procedure Check_Duplicate_Property
9586 (Prop : Node_Id;
9587 Status : in out Boolean);
9588 -- Flag Status denotes whether a particular property has been
9589 -- seen while processing option External. This routine verifies
9590 -- that Prop is not a duplicate property and sets flag Status.
9591 -- Opt is not a duplicate property and sets the flag Status.
9592 -- (SPARK RM 7.1.4(2))
9594 procedure Create_Abstract_State
9595 (Nam : Name_Id;
9596 Decl : Node_Id;
9597 Loc : Source_Ptr;
9598 Is_Null : Boolean);
9599 -- Generate an abstract state entity with name Nam and enter it
9600 -- into visibility. Decl is the "declaration" of the state as
9601 -- it appears in pragma Abstract_State. Loc is the location of
9602 -- the related state "declaration". Flag Is_Null should be set
9603 -- when the associated Abstract_State pragma defines a null
9604 -- state.
9606 -----------------------------
9607 -- Analyze_External_Option --
9608 -----------------------------
9610 procedure Analyze_External_Option (Opt : Node_Id) is
9611 Errors : constant Nat := Serious_Errors_Detected;
9612 Prop : Node_Id;
9613 Props : Node_Id := Empty;
9615 begin
9616 Check_Duplicate_Option (Opt, External_Seen);
9618 if Nkind (Opt) = N_Component_Association then
9619 Props := Expression (Opt);
9620 end if;
9622 -- External state with properties
9624 if Present (Props) then
9626 -- Multiple properties appear as an aggregate
9628 if Nkind (Props) = N_Aggregate then
9630 -- Simple property form
9632 Prop := First (Expressions (Props));
9633 while Present (Prop) loop
9634 Analyze_External_Property (Prop);
9635 Next (Prop);
9636 end loop;
9638 -- Property with expression form
9640 Prop := First (Component_Associations (Props));
9641 while Present (Prop) loop
9642 Analyze_External_Property
9643 (Prop => First (Choices (Prop)),
9644 Expr => Expression (Prop));
9646 Next (Prop);
9647 end loop;
9649 -- Single property
9651 else
9652 Analyze_External_Property (Props);
9653 end if;
9655 -- An external state defined without any properties defaults
9656 -- all properties to True.
9658 else
9659 AR_Val := True;
9660 AW_Val := True;
9661 ER_Val := True;
9662 EW_Val := True;
9663 end if;
9665 -- Once all external properties have been processed, verify
9666 -- their mutual interaction. Do not perform the check when
9667 -- at least one of the properties is illegal as this will
9668 -- produce a bogus error.
9670 if Errors = Serious_Errors_Detected then
9671 Check_External_Properties
9672 (State, AR_Val, AW_Val, ER_Val, EW_Val);
9673 end if;
9674 end Analyze_External_Option;
9676 -------------------------------
9677 -- Analyze_External_Property --
9678 -------------------------------
9680 procedure Analyze_External_Property
9681 (Prop : Node_Id;
9682 Expr : Node_Id := Empty)
9684 Expr_Val : Boolean;
9686 begin
9687 -- Check the placement of "others" (if available)
9689 if Nkind (Prop) = N_Others_Choice then
9690 if Others_Seen then
9691 SPARK_Msg_N
9692 ("only one others choice allowed in option External",
9693 Prop);
9694 else
9695 Others_Seen := True;
9696 end if;
9698 elsif Others_Seen then
9699 SPARK_Msg_N
9700 ("others must be the last property in option External",
9701 Prop);
9703 -- The only remaining legal options are the four predefined
9704 -- external properties.
9706 elsif Nkind (Prop) = N_Identifier
9707 and then Nam_In (Chars (Prop), Name_Async_Readers,
9708 Name_Async_Writers,
9709 Name_Effective_Reads,
9710 Name_Effective_Writes)
9711 then
9712 null;
9714 -- Otherwise the construct is not a valid property
9716 else
9717 SPARK_Msg_N ("invalid external state property", Prop);
9718 return;
9719 end if;
9721 -- Ensure that the expression of the external state property
9722 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
9724 if Present (Expr) then
9725 Analyze_And_Resolve (Expr, Standard_Boolean);
9727 if Is_OK_Static_Expression (Expr) then
9728 Expr_Val := Is_True (Expr_Value (Expr));
9729 else
9730 SPARK_Msg_N
9731 ("expression of external state property must be "
9732 & "static", Expr);
9733 end if;
9735 -- The lack of expression defaults the property to True
9737 else
9738 Expr_Val := True;
9739 end if;
9741 -- Named properties
9743 if Nkind (Prop) = N_Identifier then
9744 if Chars (Prop) = Name_Async_Readers then
9745 Check_Duplicate_Property (Prop, AR_Seen);
9746 AR_Val := Expr_Val;
9748 elsif Chars (Prop) = Name_Async_Writers then
9749 Check_Duplicate_Property (Prop, AW_Seen);
9750 AW_Val := Expr_Val;
9752 elsif Chars (Prop) = Name_Effective_Reads then
9753 Check_Duplicate_Property (Prop, ER_Seen);
9754 ER_Val := Expr_Val;
9756 else
9757 Check_Duplicate_Property (Prop, EW_Seen);
9758 EW_Val := Expr_Val;
9759 end if;
9761 -- The handling of property "others" must take into account
9762 -- all other named properties that have been encountered so
9763 -- far. Only those that have not been seen are affected by
9764 -- "others".
9766 else
9767 if not AR_Seen then
9768 AR_Val := Expr_Val;
9769 end if;
9771 if not AW_Seen then
9772 AW_Val := Expr_Val;
9773 end if;
9775 if not ER_Seen then
9776 ER_Val := Expr_Val;
9777 end if;
9779 if not EW_Seen then
9780 EW_Val := Expr_Val;
9781 end if;
9782 end if;
9783 end Analyze_External_Property;
9785 ----------------------------
9786 -- Analyze_Part_Of_Option --
9787 ----------------------------
9789 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
9790 Encaps : constant Node_Id := Expression (Opt);
9791 Encaps_Id : Entity_Id;
9792 Legal : Boolean;
9794 begin
9795 Check_Duplicate_Option (Opt, Part_Of_Seen);
9797 Analyze_Part_Of
9798 (Item_Id => State_Id,
9799 State => Encaps,
9800 Indic => First (Choices (Opt)),
9801 Legal => Legal);
9803 -- The Part_Of indicator turns an abstract state into a
9804 -- constituent of the encapsulating state.
9806 if Legal then
9807 Encaps_Id := Entity (Encaps);
9809 Append_Elmt (State_Id, Part_Of_Constituents (Encaps_Id));
9810 Set_Encapsulating_State (State_Id, Encaps_Id);
9811 end if;
9812 end Analyze_Part_Of_Option;
9814 ----------------------------
9815 -- Check_Duplicate_Option --
9816 ----------------------------
9818 procedure Check_Duplicate_Option
9819 (Opt : Node_Id;
9820 Status : in out Boolean)
9822 begin
9823 if Status then
9824 SPARK_Msg_N ("duplicate state option", Opt);
9825 end if;
9827 Status := True;
9828 end Check_Duplicate_Option;
9830 ------------------------------
9831 -- Check_Duplicate_Property --
9832 ------------------------------
9834 procedure Check_Duplicate_Property
9835 (Prop : Node_Id;
9836 Status : in out Boolean)
9838 begin
9839 if Status then
9840 SPARK_Msg_N ("duplicate external property", Prop);
9841 end if;
9843 Status := True;
9844 end Check_Duplicate_Property;
9846 ---------------------------
9847 -- Create_Abstract_State --
9848 ---------------------------
9850 procedure Create_Abstract_State
9851 (Nam : Name_Id;
9852 Decl : Node_Id;
9853 Loc : Source_Ptr;
9854 Is_Null : Boolean)
9856 begin
9857 -- The abstract state may be semi-declared when the related
9858 -- package was withed through a limited with clause. In that
9859 -- case reuse the entity to fully declare the state.
9861 if Present (Decl) and then Present (Entity (Decl)) then
9862 State_Id := Entity (Decl);
9864 -- Otherwise the elaboration of pragma Abstract_State
9865 -- declares the state.
9867 else
9868 State_Id := Make_Defining_Identifier (Loc, Nam);
9870 if Present (Decl) then
9871 Set_Entity (Decl, State_Id);
9872 end if;
9873 end if;
9875 -- Null states never come from source
9877 Set_Comes_From_Source (State_Id, not Is_Null);
9878 Set_Parent (State_Id, State);
9879 Set_Ekind (State_Id, E_Abstract_State);
9880 Set_Etype (State_Id, Standard_Void_Type);
9881 Set_Encapsulating_State (State_Id, Empty);
9882 Set_Refinement_Constituents (State_Id, New_Elmt_List);
9883 Set_Part_Of_Constituents (State_Id, New_Elmt_List);
9885 -- An abstract state declared within a Ghost region becomes
9886 -- Ghost (SPARK RM 6.9(2)).
9888 if Ghost_Mode > None then
9889 Set_Is_Ghost_Entity (State_Id);
9890 end if;
9892 -- Establish a link between the state declaration and the
9893 -- abstract state entity. Note that a null state remains as
9894 -- N_Null and does not carry any linkages.
9896 if not Is_Null then
9897 if Present (Decl) then
9898 Set_Entity (Decl, State_Id);
9899 Set_Etype (Decl, Standard_Void_Type);
9900 end if;
9902 -- Every non-null state must be defined, nameable and
9903 -- resolvable.
9905 Push_Scope (Pack_Id);
9906 Generate_Definition (State_Id);
9907 Enter_Name (State_Id);
9908 Pop_Scope;
9909 end if;
9910 end Create_Abstract_State;
9912 -- Local variables
9914 Opt : Node_Id;
9915 Opt_Nam : Node_Id;
9917 -- Start of processing for Analyze_Abstract_State
9919 begin
9920 -- A package with a null abstract state is not allowed to
9921 -- declare additional states.
9923 if Null_Seen then
9924 SPARK_Msg_NE
9925 ("package & has null abstract state", State, Pack_Id);
9927 -- Null states appear as internally generated entities
9929 elsif Nkind (State) = N_Null then
9930 Create_Abstract_State
9931 (Nam => New_Internal_Name ('S'),
9932 Decl => Empty,
9933 Loc => Sloc (State),
9934 Is_Null => True);
9935 Null_Seen := True;
9937 -- Catch a case where a null state appears in a list of
9938 -- non-null states.
9940 if Non_Null_Seen then
9941 SPARK_Msg_NE
9942 ("package & has non-null abstract state",
9943 State, Pack_Id);
9944 end if;
9946 -- Simple state declaration
9948 elsif Nkind (State) = N_Identifier then
9949 Create_Abstract_State
9950 (Nam => Chars (State),
9951 Decl => State,
9952 Loc => Sloc (State),
9953 Is_Null => False);
9954 Non_Null_Seen := True;
9956 -- State declaration with various options. This construct
9957 -- appears as an extension aggregate in the tree.
9959 elsif Nkind (State) = N_Extension_Aggregate then
9960 if Nkind (Ancestor_Part (State)) = N_Identifier then
9961 Create_Abstract_State
9962 (Nam => Chars (Ancestor_Part (State)),
9963 Decl => Ancestor_Part (State),
9964 Loc => Sloc (Ancestor_Part (State)),
9965 Is_Null => False);
9966 Non_Null_Seen := True;
9967 else
9968 SPARK_Msg_N
9969 ("state name must be an identifier",
9970 Ancestor_Part (State));
9971 end if;
9973 -- Options External and Ghost appear as expressions
9975 Opt := First (Expressions (State));
9976 while Present (Opt) loop
9977 if Nkind (Opt) = N_Identifier then
9978 if Chars (Opt) = Name_External then
9979 Analyze_External_Option (Opt);
9981 elsif Chars (Opt) = Name_Ghost then
9982 if Present (State_Id) then
9983 Set_Is_Ghost_Entity (State_Id);
9984 end if;
9986 -- Option Part_Of without an encapsulating state is
9987 -- illegal. (SPARK RM 7.1.4(9)).
9989 elsif Chars (Opt) = Name_Part_Of then
9990 SPARK_Msg_N
9991 ("indicator Part_Of must denote an abstract "
9992 & "state", Opt);
9994 -- Do not emit an error message when a previous state
9995 -- declaration with options was not parenthesized as
9996 -- the option is actually another state declaration.
9998 -- with Abstract_State
9999 -- (State_1 with ..., -- missing parentheses
10000 -- (State_2 with ...),
10001 -- State_3) -- ok state declaration
10003 elsif Missing_Parentheses then
10004 null;
10006 -- Otherwise the option is not allowed. Note that it
10007 -- is not possible to distinguish between an option
10008 -- and a state declaration when a previous state with
10009 -- options not properly parentheses.
10011 -- with Abstract_State
10012 -- (State_1 with ..., -- missing parentheses
10013 -- State_2); -- could be an option
10015 else
10016 SPARK_Msg_N
10017 ("simple option not allowed in state declaration",
10018 Opt);
10019 end if;
10021 -- Catch a case where missing parentheses around a state
10022 -- declaration with options cause a subsequent state
10023 -- declaration with options to be treated as an option.
10025 -- with Abstract_State
10026 -- (State_1 with ..., -- missing parentheses
10027 -- (State_2 with ...))
10029 elsif Nkind (Opt) = N_Extension_Aggregate then
10030 Missing_Parentheses := True;
10031 SPARK_Msg_N
10032 ("state declaration must be parenthesized",
10033 Ancestor_Part (State));
10035 -- Otherwise the option is malformed
10037 else
10038 SPARK_Msg_N ("malformed option", Opt);
10039 end if;
10041 Next (Opt);
10042 end loop;
10044 -- Options External and Part_Of appear as component
10045 -- associations.
10047 Opt := First (Component_Associations (State));
10048 while Present (Opt) loop
10049 Opt_Nam := First (Choices (Opt));
10051 if Nkind (Opt_Nam) = N_Identifier then
10052 if Chars (Opt_Nam) = Name_External then
10053 Analyze_External_Option (Opt);
10055 elsif Chars (Opt_Nam) = Name_Part_Of then
10056 Analyze_Part_Of_Option (Opt);
10058 else
10059 SPARK_Msg_N ("invalid state option", Opt);
10060 end if;
10061 else
10062 SPARK_Msg_N ("invalid state option", Opt);
10063 end if;
10065 Next (Opt);
10066 end loop;
10068 -- Any other attempt to declare a state is illegal
10070 else
10071 Malformed_State_Error (State);
10072 return;
10073 end if;
10075 -- Guard against a junk state. In such cases no entity is
10076 -- generated and the subsequent checks cannot be applied.
10078 if Present (State_Id) then
10080 -- Verify whether the state does not introduce an illegal
10081 -- hidden state within a package subject to a null abstract
10082 -- state.
10084 Check_No_Hidden_State (State_Id);
10086 -- Check whether the lack of option Part_Of agrees with the
10087 -- placement of the abstract state with respect to the state
10088 -- space.
10090 if not Part_Of_Seen then
10091 Check_Missing_Part_Of (State_Id);
10092 end if;
10094 -- Associate the state with its related package
10096 if No (Abstract_States (Pack_Id)) then
10097 Set_Abstract_States (Pack_Id, New_Elmt_List);
10098 end if;
10100 Append_Elmt (State_Id, Abstract_States (Pack_Id));
10101 end if;
10102 end Analyze_Abstract_State;
10104 ---------------------------
10105 -- Malformed_State_Error --
10106 ---------------------------
10108 procedure Malformed_State_Error (State : Node_Id) is
10109 begin
10110 Error_Msg_N ("malformed abstract state declaration", State);
10112 -- An abstract state with a simple option is being declared
10113 -- with "=>" rather than the legal "with". The state appears
10114 -- as a component association.
10116 if Nkind (State) = N_Component_Association then
10117 Error_Msg_N ("\\use WITH to specify simple option", State);
10118 end if;
10119 end Malformed_State_Error;
10121 -- Local variables
10123 Pack_Decl : Node_Id;
10124 Pack_Id : Entity_Id;
10125 State : Node_Id;
10126 States : Node_Id;
10128 -- Start of processing for Abstract_State
10130 begin
10131 GNAT_Pragma;
10132 Check_No_Identifiers;
10133 Check_Arg_Count (1);
10135 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
10137 -- Ensure the proper placement of the pragma. Abstract states must
10138 -- be associated with a package declaration.
10140 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
10141 N_Package_Declaration)
10142 then
10143 null;
10145 -- Otherwise the pragma is associated with an illegal construct
10147 else
10148 Pragma_Misplaced;
10149 return;
10150 end if;
10152 Ensure_Aggregate_Form (Get_Argument (N));
10153 Pack_Id := Defining_Entity (Pack_Decl);
10155 -- Mark the associated package as Ghost if it is subject to aspect
10156 -- or pragma Ghost as this affects the declaration of an abstract
10157 -- state.
10159 if Is_Subject_To_Ghost (Unit_Declaration_Node (Pack_Id)) then
10160 Set_Is_Ghost_Entity (Pack_Id);
10161 end if;
10163 States := Expression (Get_Argument (N));
10165 -- Multiple non-null abstract states appear as an aggregate
10167 if Nkind (States) = N_Aggregate then
10168 State := First (Expressions (States));
10169 while Present (State) loop
10170 Analyze_Abstract_State (State, Pack_Id);
10171 Next (State);
10172 end loop;
10174 -- An abstract state with a simple option is being illegaly
10175 -- declared with "=>" rather than "with". In this case the
10176 -- state declaration appears as a component association.
10178 if Present (Component_Associations (States)) then
10179 State := First (Component_Associations (States));
10180 while Present (State) loop
10181 Malformed_State_Error (State);
10182 Next (State);
10183 end loop;
10184 end if;
10186 -- Various forms of a single abstract state. Note that these may
10187 -- include malformed state declarations.
10189 else
10190 Analyze_Abstract_State (States, Pack_Id);
10191 end if;
10193 -- Save the pragma for retrieval by other tools
10195 Add_Contract_Item (N, Pack_Id);
10197 -- Verify the declaration order of pragmas Abstract_State and
10198 -- Initializes.
10200 Check_Declaration_Order
10201 (First => N,
10202 Second => Get_Pragma (Pack_Id, Pragma_Initializes));
10203 end Abstract_State;
10205 ------------
10206 -- Ada_83 --
10207 ------------
10209 -- pragma Ada_83;
10211 -- Note: this pragma also has some specific processing in Par.Prag
10212 -- because we want to set the Ada version mode during parsing.
10214 when Pragma_Ada_83 =>
10215 GNAT_Pragma;
10216 Check_Arg_Count (0);
10218 -- We really should check unconditionally for proper configuration
10219 -- pragma placement, since we really don't want mixed Ada modes
10220 -- within a single unit, and the GNAT reference manual has always
10221 -- said this was a configuration pragma, but we did not check and
10222 -- are hesitant to add the check now.
10224 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
10225 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
10226 -- or Ada 2012 mode.
10228 if Ada_Version >= Ada_2005 then
10229 Check_Valid_Configuration_Pragma;
10230 end if;
10232 -- Now set Ada 83 mode
10234 Ada_Version := Ada_83;
10235 Ada_Version_Explicit := Ada_83;
10236 Ada_Version_Pragma := N;
10238 ------------
10239 -- Ada_95 --
10240 ------------
10242 -- pragma Ada_95;
10244 -- Note: this pragma also has some specific processing in Par.Prag
10245 -- because we want to set the Ada 83 version mode during parsing.
10247 when Pragma_Ada_95 =>
10248 GNAT_Pragma;
10249 Check_Arg_Count (0);
10251 -- We really should check unconditionally for proper configuration
10252 -- pragma placement, since we really don't want mixed Ada modes
10253 -- within a single unit, and the GNAT reference manual has always
10254 -- said this was a configuration pragma, but we did not check and
10255 -- are hesitant to add the check now.
10257 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
10258 -- or Ada 95, so we must check if we are in Ada 2005 mode.
10260 if Ada_Version >= Ada_2005 then
10261 Check_Valid_Configuration_Pragma;
10262 end if;
10264 -- Now set Ada 95 mode
10266 Ada_Version := Ada_95;
10267 Ada_Version_Explicit := Ada_95;
10268 Ada_Version_Pragma := N;
10270 ---------------------
10271 -- Ada_05/Ada_2005 --
10272 ---------------------
10274 -- pragma Ada_05;
10275 -- pragma Ada_05 (LOCAL_NAME);
10277 -- pragma Ada_2005;
10278 -- pragma Ada_2005 (LOCAL_NAME):
10280 -- Note: these pragmas also have some specific processing in Par.Prag
10281 -- because we want to set the Ada 2005 version mode during parsing.
10283 -- The one argument form is used for managing the transition from
10284 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
10285 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
10286 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
10287 -- mode, a preference rule is established which does not choose
10288 -- such an entity unless it is unambiguously specified. This avoids
10289 -- extra subprograms marked this way from generating ambiguities in
10290 -- otherwise legal pre-Ada_2005 programs. The one argument form is
10291 -- intended for exclusive use in the GNAT run-time library.
10293 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
10294 E_Id : Node_Id;
10296 begin
10297 GNAT_Pragma;
10299 if Arg_Count = 1 then
10300 Check_Arg_Is_Local_Name (Arg1);
10301 E_Id := Get_Pragma_Arg (Arg1);
10303 if Etype (E_Id) = Any_Type then
10304 return;
10305 end if;
10307 Set_Is_Ada_2005_Only (Entity (E_Id));
10308 Record_Rep_Item (Entity (E_Id), N);
10310 else
10311 Check_Arg_Count (0);
10313 -- For Ada_2005 we unconditionally enforce the documented
10314 -- configuration pragma placement, since we do not want to
10315 -- tolerate mixed modes in a unit involving Ada 2005. That
10316 -- would cause real difficulties for those cases where there
10317 -- are incompatibilities between Ada 95 and Ada 2005.
10319 Check_Valid_Configuration_Pragma;
10321 -- Now set appropriate Ada mode
10323 Ada_Version := Ada_2005;
10324 Ada_Version_Explicit := Ada_2005;
10325 Ada_Version_Pragma := N;
10326 end if;
10327 end;
10329 ---------------------
10330 -- Ada_12/Ada_2012 --
10331 ---------------------
10333 -- pragma Ada_12;
10334 -- pragma Ada_12 (LOCAL_NAME);
10336 -- pragma Ada_2012;
10337 -- pragma Ada_2012 (LOCAL_NAME):
10339 -- Note: these pragmas also have some specific processing in Par.Prag
10340 -- because we want to set the Ada 2012 version mode during parsing.
10342 -- The one argument form is used for managing the transition from Ada
10343 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
10344 -- as Ada_201 only, then referencing the entity in any pre-Ada_2012
10345 -- mode will generate a warning. In addition, in any pre-Ada_2012
10346 -- mode, a preference rule is established which does not choose
10347 -- such an entity unless it is unambiguously specified. This avoids
10348 -- extra subprograms marked this way from generating ambiguities in
10349 -- otherwise legal pre-Ada_2012 programs. The one argument form is
10350 -- intended for exclusive use in the GNAT run-time library.
10352 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
10353 E_Id : Node_Id;
10355 begin
10356 GNAT_Pragma;
10358 if Arg_Count = 1 then
10359 Check_Arg_Is_Local_Name (Arg1);
10360 E_Id := Get_Pragma_Arg (Arg1);
10362 if Etype (E_Id) = Any_Type then
10363 return;
10364 end if;
10366 Set_Is_Ada_2012_Only (Entity (E_Id));
10367 Record_Rep_Item (Entity (E_Id), N);
10369 else
10370 Check_Arg_Count (0);
10372 -- For Ada_2012 we unconditionally enforce the documented
10373 -- configuration pragma placement, since we do not want to
10374 -- tolerate mixed modes in a unit involving Ada 2012. That
10375 -- would cause real difficulties for those cases where there
10376 -- are incompatibilities between Ada 95 and Ada 2012. We could
10377 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
10379 Check_Valid_Configuration_Pragma;
10381 -- Now set appropriate Ada mode
10383 Ada_Version := Ada_2012;
10384 Ada_Version_Explicit := Ada_2012;
10385 Ada_Version_Pragma := N;
10386 end if;
10387 end;
10389 ----------------------
10390 -- All_Calls_Remote --
10391 ----------------------
10393 -- pragma All_Calls_Remote [(library_package_NAME)];
10395 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
10396 Lib_Entity : Entity_Id;
10398 begin
10399 Check_Ada_83_Warning;
10400 Check_Valid_Library_Unit_Pragma;
10402 if Nkind (N) = N_Null_Statement then
10403 return;
10404 end if;
10406 Lib_Entity := Find_Lib_Unit_Name;
10408 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
10410 if Present (Lib_Entity)
10411 and then not Debug_Flag_U
10412 then
10413 if not Is_Remote_Call_Interface (Lib_Entity) then
10414 Error_Pragma ("pragma% only apply to rci unit");
10416 -- Set flag for entity of the library unit
10418 else
10419 Set_Has_All_Calls_Remote (Lib_Entity);
10420 end if;
10422 end if;
10423 end All_Calls_Remote;
10425 ---------------------------
10426 -- Allow_Integer_Address --
10427 ---------------------------
10429 -- pragma Allow_Integer_Address;
10431 when Pragma_Allow_Integer_Address =>
10432 GNAT_Pragma;
10433 Check_Valid_Configuration_Pragma;
10434 Check_Arg_Count (0);
10436 -- If Address is a private type, then set the flag to allow
10437 -- integer address values. If Address is not private, then this
10438 -- pragma has no purpose, so it is simply ignored. Not clear if
10439 -- there are any such targets now.
10441 if Opt.Address_Is_Private then
10442 Opt.Allow_Integer_Address := True;
10443 end if;
10445 --------------
10446 -- Annotate --
10447 --------------
10449 -- pragma Annotate
10450 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
10451 -- ARG ::= NAME | EXPRESSION
10453 -- The first two arguments are by convention intended to refer to an
10454 -- external tool and a tool-specific function. These arguments are
10455 -- not analyzed.
10457 when Pragma_Annotate => Annotate : declare
10458 Arg : Node_Id;
10459 Exp : Node_Id;
10461 begin
10462 GNAT_Pragma;
10463 Check_At_Least_N_Arguments (1);
10465 -- See if last argument is Entity => local_Name, and if so process
10466 -- and then remove it for remaining processing.
10468 declare
10469 Last_Arg : constant Node_Id :=
10470 Last (Pragma_Argument_Associations (N));
10472 begin
10473 if Nkind (Last_Arg) = N_Pragma_Argument_Association
10474 and then Chars (Last_Arg) = Name_Entity
10475 then
10476 Check_Arg_Is_Local_Name (Last_Arg);
10477 Arg_Count := Arg_Count - 1;
10479 -- Not allowed in compiler units (bootstrap issues)
10481 Check_Compiler_Unit ("Entity for pragma Annotate", N);
10482 end if;
10483 end;
10485 -- Continue processing with last argument removed for now
10487 Check_Arg_Is_Identifier (Arg1);
10488 Check_No_Identifiers;
10489 Store_Note (N);
10491 -- Second parameter is optional, it is never analyzed
10493 if No (Arg2) then
10494 null;
10496 -- Here if we have a second parameter
10498 else
10499 -- Second parameter must be identifier
10501 Check_Arg_Is_Identifier (Arg2);
10503 -- Process remaining parameters if any
10505 Arg := Next (Arg2);
10506 while Present (Arg) loop
10507 Exp := Get_Pragma_Arg (Arg);
10508 Analyze (Exp);
10510 if Is_Entity_Name (Exp) then
10511 null;
10513 -- For string literals, we assume Standard_String as the
10514 -- type, unless the string contains wide or wide_wide
10515 -- characters.
10517 elsif Nkind (Exp) = N_String_Literal then
10518 if Has_Wide_Wide_Character (Exp) then
10519 Resolve (Exp, Standard_Wide_Wide_String);
10520 elsif Has_Wide_Character (Exp) then
10521 Resolve (Exp, Standard_Wide_String);
10522 else
10523 Resolve (Exp, Standard_String);
10524 end if;
10526 elsif Is_Overloaded (Exp) then
10527 Error_Pragma_Arg
10528 ("ambiguous argument for pragma%", Exp);
10530 else
10531 Resolve (Exp);
10532 end if;
10534 Next (Arg);
10535 end loop;
10536 end if;
10537 end Annotate;
10539 -------------------------------------------------
10540 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
10541 -------------------------------------------------
10543 -- pragma Assert
10544 -- ( [Check => ] Boolean_EXPRESSION
10545 -- [, [Message =>] Static_String_EXPRESSION]);
10547 -- pragma Assert_And_Cut
10548 -- ( [Check => ] Boolean_EXPRESSION
10549 -- [, [Message =>] Static_String_EXPRESSION]);
10551 -- pragma Assume
10552 -- ( [Check => ] Boolean_EXPRESSION
10553 -- [, [Message =>] Static_String_EXPRESSION]);
10555 -- pragma Loop_Invariant
10556 -- ( [Check => ] Boolean_EXPRESSION
10557 -- [, [Message =>] Static_String_EXPRESSION]);
10559 when Pragma_Assert |
10560 Pragma_Assert_And_Cut |
10561 Pragma_Assume |
10562 Pragma_Loop_Invariant =>
10563 Assert : declare
10564 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
10565 -- Determine whether expression Expr contains a Loop_Entry
10566 -- attribute reference.
10568 -------------------------
10569 -- Contains_Loop_Entry --
10570 -------------------------
10572 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
10573 Has_Loop_Entry : Boolean := False;
10575 function Process (N : Node_Id) return Traverse_Result;
10576 -- Process function for traversal to look for Loop_Entry
10578 -------------
10579 -- Process --
10580 -------------
10582 function Process (N : Node_Id) return Traverse_Result is
10583 begin
10584 if Nkind (N) = N_Attribute_Reference
10585 and then Attribute_Name (N) = Name_Loop_Entry
10586 then
10587 Has_Loop_Entry := True;
10588 return Abandon;
10589 else
10590 return OK;
10591 end if;
10592 end Process;
10594 procedure Traverse is new Traverse_Proc (Process);
10596 -- Start of processing for Contains_Loop_Entry
10598 begin
10599 Traverse (Expr);
10600 return Has_Loop_Entry;
10601 end Contains_Loop_Entry;
10603 -- Local variables
10605 Expr : Node_Id;
10606 Newa : List_Id;
10608 -- Start of processing for Assert
10610 begin
10611 -- Assert is an Ada 2005 RM-defined pragma
10613 if Prag_Id = Pragma_Assert then
10614 Ada_2005_Pragma;
10616 -- The remaining ones are GNAT pragmas
10618 else
10619 GNAT_Pragma;
10620 end if;
10622 Check_At_Least_N_Arguments (1);
10623 Check_At_Most_N_Arguments (2);
10624 Check_Arg_Order ((Name_Check, Name_Message));
10625 Check_Optional_Identifier (Arg1, Name_Check);
10626 Expr := Get_Pragma_Arg (Arg1);
10628 -- Special processing for Loop_Invariant, Loop_Variant or for
10629 -- other cases where a Loop_Entry attribute is present. If the
10630 -- assertion pragma contains attribute Loop_Entry, ensure that
10631 -- the related pragma is within a loop.
10633 if Prag_Id = Pragma_Loop_Invariant
10634 or else Prag_Id = Pragma_Loop_Variant
10635 or else Contains_Loop_Entry (Expr)
10636 then
10637 Check_Loop_Pragma_Placement;
10639 -- Perform preanalysis to deal with embedded Loop_Entry
10640 -- attributes.
10642 Preanalyze_Assert_Expression (Expression (Arg1), Any_Boolean);
10643 end if;
10645 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
10646 -- a corresponding Check pragma:
10648 -- pragma Check (name, condition [, msg]);
10650 -- Where name is the identifier matching the pragma name. So
10651 -- rewrite pragma in this manner, transfer the message argument
10652 -- if present, and analyze the result
10654 -- Note: When dealing with a semantically analyzed tree, the
10655 -- information that a Check node N corresponds to a source Assert,
10656 -- Assume, or Assert_And_Cut pragma can be retrieved from the
10657 -- pragma kind of Original_Node(N).
10659 Newa := New_List (
10660 Make_Pragma_Argument_Association (Loc,
10661 Expression => Make_Identifier (Loc, Pname)),
10662 Make_Pragma_Argument_Association (Sloc (Expr),
10663 Expression => Expr));
10665 if Arg_Count > 1 then
10666 Check_Optional_Identifier (Arg2, Name_Message);
10668 -- Provide semantic annnotations for optional argument, for
10669 -- ASIS use, before rewriting.
10671 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
10672 Append_To (Newa, New_Copy_Tree (Arg2));
10673 end if;
10675 -- Rewrite as Check pragma
10677 Rewrite (N,
10678 Make_Pragma (Loc,
10679 Chars => Name_Check,
10680 Pragma_Argument_Associations => Newa));
10681 Analyze (N);
10682 end Assert;
10684 ----------------------
10685 -- Assertion_Policy --
10686 ----------------------
10688 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
10690 -- The following form is Ada 2012 only, but we allow it in all modes
10692 -- Pragma Assertion_Policy (
10693 -- ASSERTION_KIND => POLICY_IDENTIFIER
10694 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
10696 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
10698 -- RM_ASSERTION_KIND ::= Assert |
10699 -- Static_Predicate |
10700 -- Dynamic_Predicate |
10701 -- Pre |
10702 -- Pre'Class |
10703 -- Post |
10704 -- Post'Class |
10705 -- Type_Invariant |
10706 -- Type_Invariant'Class
10708 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
10709 -- Assume |
10710 -- Contract_Cases |
10711 -- Debug |
10712 -- Default_Initial_Condition |
10713 -- Ghost |
10714 -- Initial_Condition |
10715 -- Loop_Invariant |
10716 -- Loop_Variant |
10717 -- Postcondition |
10718 -- Precondition |
10719 -- Predicate |
10720 -- Refined_Post |
10721 -- Statement_Assertions
10723 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
10724 -- ID_ASSERTION_KIND list contains implementation-defined additions
10725 -- recognized by GNAT. The effect is to control the behavior of
10726 -- identically named aspects and pragmas, depending on the specified
10727 -- policy identifier:
10729 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore
10731 -- Note: Check and Ignore are language-defined. Disable is a GNAT
10732 -- implementation defined addition that results in totally ignoring
10733 -- the corresponding assertion. If Disable is specified, then the
10734 -- argument of the assertion is not even analyzed. This is useful
10735 -- when the aspect/pragma argument references entities in a with'ed
10736 -- package that is replaced by a dummy package in the final build.
10738 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
10739 -- and Type_Invariant'Class were recognized by the parser and
10740 -- transformed into references to the special internal identifiers
10741 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
10742 -- processing is required here.
10744 when Pragma_Assertion_Policy => Assertion_Policy : declare
10745 Arg : Node_Id;
10746 Kind : Name_Id;
10747 LocP : Source_Ptr;
10748 Policy : Node_Id;
10750 begin
10751 Ada_2005_Pragma;
10753 -- This can always appear as a configuration pragma
10755 if Is_Configuration_Pragma then
10756 null;
10758 -- It can also appear in a declarative part or package spec in Ada
10759 -- 2012 mode. We allow this in other modes, but in that case we
10760 -- consider that we have an Ada 2012 pragma on our hands.
10762 else
10763 Check_Is_In_Decl_Part_Or_Package_Spec;
10764 Ada_2012_Pragma;
10765 end if;
10767 -- One argument case with no identifier (first form above)
10769 if Arg_Count = 1
10770 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
10771 or else Chars (Arg1) = No_Name)
10772 then
10773 Check_Arg_Is_One_Of
10774 (Arg1, Name_Check, Name_Disable, Name_Ignore);
10776 -- Treat one argument Assertion_Policy as equivalent to:
10778 -- pragma Check_Policy (Assertion, policy)
10780 -- So rewrite pragma in that manner and link on to the chain
10781 -- of Check_Policy pragmas, marking the pragma as analyzed.
10783 Policy := Get_Pragma_Arg (Arg1);
10785 Rewrite (N,
10786 Make_Pragma (Loc,
10787 Chars => Name_Check_Policy,
10788 Pragma_Argument_Associations => New_List (
10789 Make_Pragma_Argument_Association (Loc,
10790 Expression => Make_Identifier (Loc, Name_Assertion)),
10792 Make_Pragma_Argument_Association (Loc,
10793 Expression =>
10794 Make_Identifier (Sloc (Policy), Chars (Policy))))));
10795 Analyze (N);
10797 -- Here if we have two or more arguments
10799 else
10800 Check_At_Least_N_Arguments (1);
10801 Ada_2012_Pragma;
10803 -- Loop through arguments
10805 Arg := Arg1;
10806 while Present (Arg) loop
10807 LocP := Sloc (Arg);
10809 -- Kind must be specified
10811 if Nkind (Arg) /= N_Pragma_Argument_Association
10812 or else Chars (Arg) = No_Name
10813 then
10814 Error_Pragma_Arg
10815 ("missing assertion kind for pragma%", Arg);
10816 end if;
10818 -- Check Kind and Policy have allowed forms
10820 Kind := Chars (Arg);
10822 if not Is_Valid_Assertion_Kind (Kind) then
10823 Error_Pragma_Arg
10824 ("invalid assertion kind for pragma%", Arg);
10825 end if;
10827 Check_Arg_Is_One_Of
10828 (Arg, Name_Check, Name_Disable, Name_Ignore);
10830 -- Rewrite the Assertion_Policy pragma as a series of
10831 -- Check_Policy pragmas of the form:
10833 -- Check_Policy (Kind, Policy);
10835 -- Note: the insertion of the pragmas cannot be done with
10836 -- Insert_Action because in the configuration case, there
10837 -- are no scopes on the scope stack and the mechanism will
10838 -- fail.
10840 Insert_Before_And_Analyze (N,
10841 Make_Pragma (LocP,
10842 Chars => Name_Check_Policy,
10843 Pragma_Argument_Associations => New_List (
10844 Make_Pragma_Argument_Association (LocP,
10845 Expression => Make_Identifier (LocP, Kind)),
10846 Make_Pragma_Argument_Association (LocP,
10847 Expression => Get_Pragma_Arg (Arg)))));
10849 Arg := Next (Arg);
10850 end loop;
10852 -- Rewrite the Assertion_Policy pragma as null since we have
10853 -- now inserted all the equivalent Check pragmas.
10855 Rewrite (N, Make_Null_Statement (Loc));
10856 Analyze (N);
10857 end if;
10858 end Assertion_Policy;
10860 ------------------------------
10861 -- Assume_No_Invalid_Values --
10862 ------------------------------
10864 -- pragma Assume_No_Invalid_Values (On | Off);
10866 when Pragma_Assume_No_Invalid_Values =>
10867 GNAT_Pragma;
10868 Check_Valid_Configuration_Pragma;
10869 Check_Arg_Count (1);
10870 Check_No_Identifiers;
10871 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10873 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
10874 Assume_No_Invalid_Values := True;
10875 else
10876 Assume_No_Invalid_Values := False;
10877 end if;
10879 --------------------------
10880 -- Attribute_Definition --
10881 --------------------------
10883 -- pragma Attribute_Definition
10884 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
10885 -- [Entity =>] LOCAL_NAME,
10886 -- [Expression =>] EXPRESSION | NAME);
10888 when Pragma_Attribute_Definition => Attribute_Definition : declare
10889 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
10890 Aname : Name_Id;
10892 begin
10893 GNAT_Pragma;
10894 Check_Arg_Count (3);
10895 Check_Optional_Identifier (Arg1, "attribute");
10896 Check_Optional_Identifier (Arg2, "entity");
10897 Check_Optional_Identifier (Arg3, "expression");
10899 if Nkind (Attribute_Designator) /= N_Identifier then
10900 Error_Msg_N ("attribute name expected", Attribute_Designator);
10901 return;
10902 end if;
10904 Check_Arg_Is_Local_Name (Arg2);
10906 -- If the attribute is not recognized, then issue a warning (not
10907 -- an error), and ignore the pragma.
10909 Aname := Chars (Attribute_Designator);
10911 if not Is_Attribute_Name (Aname) then
10912 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
10913 return;
10914 end if;
10916 -- Otherwise, rewrite the pragma as an attribute definition clause
10918 Rewrite (N,
10919 Make_Attribute_Definition_Clause (Loc,
10920 Name => Get_Pragma_Arg (Arg2),
10921 Chars => Aname,
10922 Expression => Get_Pragma_Arg (Arg3)));
10923 Analyze (N);
10924 end Attribute_Definition;
10926 ------------------------------------------------------------------
10927 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
10928 ------------------------------------------------------------------
10930 -- pragma Asynch_Readers ( object_LOCAL_NAME [, FLAG] );
10931 -- pragma Asynch_Writers ( object_LOCAL_NAME [, FLAG] );
10932 -- pragma Effective_Reads ( object_LOCAL_NAME [, FLAG] );
10933 -- pragma Effective_Writes ( object_LOCAL_NAME [, FLAG] );
10935 -- FLAG ::= boolean_EXPRESSION
10937 when Pragma_Async_Readers |
10938 Pragma_Async_Writers |
10939 Pragma_Effective_Reads |
10940 Pragma_Effective_Writes =>
10941 Async_Effective : declare
10942 Duplic : Node_Id;
10943 Expr : Node_Id;
10944 Obj : Node_Id;
10945 Obj_Id : Entity_Id;
10947 begin
10948 GNAT_Pragma;
10949 Check_No_Identifiers;
10950 Check_At_Least_N_Arguments (1);
10951 Check_At_Most_N_Arguments (2);
10952 Check_Arg_Is_Local_Name (Arg1);
10953 Error_Msg_Name_1 := Pname;
10955 Obj := Get_Pragma_Arg (Arg1);
10956 Expr := Get_Pragma_Arg (Arg2);
10958 -- Perform minimal verification to ensure that the argument is at
10959 -- least a variable. Subsequent finer grained checks will be done
10960 -- at the end of the declarative region the contains the pragma.
10962 if Is_Entity_Name (Obj)
10963 and then Present (Entity (Obj))
10964 and then Ekind (Entity (Obj)) = E_Variable
10965 then
10966 Obj_Id := Entity (Obj);
10968 -- Detect a duplicate pragma. Note that it is not efficient to
10969 -- examine preceding statements as Boolean aspects may appear
10970 -- anywhere between the related object declaration and its
10971 -- freeze point. As an alternative, inspect the contents of the
10972 -- variable contract.
10974 Duplic := Get_Pragma (Obj_Id, Prag_Id);
10976 if Present (Duplic) then
10977 Error_Msg_Sloc := Sloc (Duplic);
10978 Error_Msg_N ("pragma % duplicates pragma declared #", N);
10980 -- No duplicate detected
10982 else
10983 if Present (Expr) then
10984 Preanalyze_And_Resolve (Expr, Standard_Boolean);
10985 end if;
10987 -- Chain the pragma on the contract for further processing
10989 Add_Contract_Item (N, Obj_Id);
10990 end if;
10991 else
10992 Error_Pragma ("pragma % must apply to a volatile object");
10993 end if;
10994 end Async_Effective;
10996 ------------------
10997 -- Asynchronous --
10998 ------------------
11000 -- pragma Asynchronous (LOCAL_NAME);
11002 when Pragma_Asynchronous => Asynchronous : declare
11003 Nm : Entity_Id;
11004 C_Ent : Entity_Id;
11005 L : List_Id;
11006 S : Node_Id;
11007 N : Node_Id;
11008 Formal : Entity_Id;
11010 procedure Process_Async_Pragma;
11011 -- Common processing for procedure and access-to-procedure case
11013 --------------------------
11014 -- Process_Async_Pragma --
11015 --------------------------
11017 procedure Process_Async_Pragma is
11018 begin
11019 if No (L) then
11020 Set_Is_Asynchronous (Nm);
11021 return;
11022 end if;
11024 -- The formals should be of mode IN (RM E.4.1(6))
11026 S := First (L);
11027 while Present (S) loop
11028 Formal := Defining_Identifier (S);
11030 if Nkind (Formal) = N_Defining_Identifier
11031 and then Ekind (Formal) /= E_In_Parameter
11032 then
11033 Error_Pragma_Arg
11034 ("pragma% procedure can only have IN parameter",
11035 Arg1);
11036 end if;
11038 Next (S);
11039 end loop;
11041 Set_Is_Asynchronous (Nm);
11042 end Process_Async_Pragma;
11044 -- Start of processing for pragma Asynchronous
11046 begin
11047 Check_Ada_83_Warning;
11048 Check_No_Identifiers;
11049 Check_Arg_Count (1);
11050 Check_Arg_Is_Local_Name (Arg1);
11052 if Debug_Flag_U then
11053 return;
11054 end if;
11056 C_Ent := Cunit_Entity (Current_Sem_Unit);
11057 Analyze (Get_Pragma_Arg (Arg1));
11058 Nm := Entity (Get_Pragma_Arg (Arg1));
11060 if not Is_Remote_Call_Interface (C_Ent)
11061 and then not Is_Remote_Types (C_Ent)
11062 then
11063 -- This pragma should only appear in an RCI or Remote Types
11064 -- unit (RM E.4.1(4)).
11066 Error_Pragma
11067 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
11068 end if;
11070 if Ekind (Nm) = E_Procedure
11071 and then Nkind (Parent (Nm)) = N_Procedure_Specification
11072 then
11073 if not Is_Remote_Call_Interface (Nm) then
11074 Error_Pragma_Arg
11075 ("pragma% cannot be applied on non-remote procedure",
11076 Arg1);
11077 end if;
11079 L := Parameter_Specifications (Parent (Nm));
11080 Process_Async_Pragma;
11081 return;
11083 elsif Ekind (Nm) = E_Function then
11084 Error_Pragma_Arg
11085 ("pragma% cannot be applied to function", Arg1);
11087 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
11088 if Is_Record_Type (Nm) then
11090 -- A record type that is the Equivalent_Type for a remote
11091 -- access-to-subprogram type.
11093 N := Declaration_Node (Corresponding_Remote_Type (Nm));
11095 else
11096 -- A non-expanded RAS type (distribution is not enabled)
11098 N := Declaration_Node (Nm);
11099 end if;
11101 if Nkind (N) = N_Full_Type_Declaration
11102 and then Nkind (Type_Definition (N)) =
11103 N_Access_Procedure_Definition
11104 then
11105 L := Parameter_Specifications (Type_Definition (N));
11106 Process_Async_Pragma;
11108 if Is_Asynchronous (Nm)
11109 and then Expander_Active
11110 and then Get_PCS_Name /= Name_No_DSA
11111 then
11112 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
11113 end if;
11115 else
11116 Error_Pragma_Arg
11117 ("pragma% cannot reference access-to-function type",
11118 Arg1);
11119 end if;
11121 -- Only other possibility is Access-to-class-wide type
11123 elsif Is_Access_Type (Nm)
11124 and then Is_Class_Wide_Type (Designated_Type (Nm))
11125 then
11126 Check_First_Subtype (Arg1);
11127 Set_Is_Asynchronous (Nm);
11128 if Expander_Active then
11129 RACW_Type_Is_Asynchronous (Nm);
11130 end if;
11132 else
11133 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
11134 end if;
11135 end Asynchronous;
11137 ------------
11138 -- Atomic --
11139 ------------
11141 -- pragma Atomic (LOCAL_NAME);
11143 when Pragma_Atomic =>
11144 Process_Atomic_Independent_Shared_Volatile;
11146 -----------------------
11147 -- Atomic_Components --
11148 -----------------------
11150 -- pragma Atomic_Components (array_LOCAL_NAME);
11152 -- This processing is shared by Volatile_Components
11154 when Pragma_Atomic_Components |
11155 Pragma_Volatile_Components =>
11157 Atomic_Components : declare
11158 E_Id : Node_Id;
11159 E : Entity_Id;
11160 D : Node_Id;
11161 K : Node_Kind;
11163 begin
11164 Check_Ada_83_Warning;
11165 Check_No_Identifiers;
11166 Check_Arg_Count (1);
11167 Check_Arg_Is_Local_Name (Arg1);
11168 E_Id := Get_Pragma_Arg (Arg1);
11170 if Etype (E_Id) = Any_Type then
11171 return;
11172 end if;
11174 E := Entity (E_Id);
11176 Check_Duplicate_Pragma (E);
11178 if Rep_Item_Too_Early (E, N)
11179 or else
11180 Rep_Item_Too_Late (E, N)
11181 then
11182 return;
11183 end if;
11185 D := Declaration_Node (E);
11186 K := Nkind (D);
11188 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
11189 or else
11190 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
11191 and then Nkind (D) = N_Object_Declaration
11192 and then Nkind (Object_Definition (D)) =
11193 N_Constrained_Array_Definition)
11194 then
11195 -- The flag is set on the object, or on the base type
11197 if Nkind (D) /= N_Object_Declaration then
11198 E := Base_Type (E);
11199 end if;
11201 -- Atomic implies both Independent and Volatile
11203 if Prag_Id = Pragma_Atomic_Components then
11204 Set_Has_Atomic_Components (E);
11205 Set_Has_Independent_Components (E);
11206 end if;
11208 Set_Has_Volatile_Components (E);
11210 else
11211 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
11212 end if;
11213 end Atomic_Components;
11215 --------------------
11216 -- Attach_Handler --
11217 --------------------
11219 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
11221 when Pragma_Attach_Handler =>
11222 Check_Ada_83_Warning;
11223 Check_No_Identifiers;
11224 Check_Arg_Count (2);
11226 if No_Run_Time_Mode then
11227 Error_Msg_CRT ("Attach_Handler pragma", N);
11228 else
11229 Check_Interrupt_Or_Attach_Handler;
11231 -- The expression that designates the attribute may depend on a
11232 -- discriminant, and is therefore a per-object expression, to
11233 -- be expanded in the init proc. If expansion is enabled, then
11234 -- perform semantic checks on a copy only.
11236 declare
11237 Temp : Node_Id;
11238 Typ : Node_Id;
11239 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
11241 begin
11242 -- In Relaxed_RM_Semantics mode, we allow any static
11243 -- integer value, for compatibility with other compilers.
11245 if Relaxed_RM_Semantics
11246 and then Nkind (Parg2) = N_Integer_Literal
11247 then
11248 Typ := Standard_Integer;
11249 else
11250 Typ := RTE (RE_Interrupt_ID);
11251 end if;
11253 if Expander_Active then
11254 Temp := New_Copy_Tree (Parg2);
11255 Set_Parent (Temp, N);
11256 Preanalyze_And_Resolve (Temp, Typ);
11257 else
11258 Analyze (Parg2);
11259 Resolve (Parg2, Typ);
11260 end if;
11261 end;
11263 Process_Interrupt_Or_Attach_Handler;
11264 end if;
11266 --------------------
11267 -- C_Pass_By_Copy --
11268 --------------------
11270 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
11272 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
11273 Arg : Node_Id;
11274 Val : Uint;
11276 begin
11277 GNAT_Pragma;
11278 Check_Valid_Configuration_Pragma;
11279 Check_Arg_Count (1);
11280 Check_Optional_Identifier (Arg1, "max_size");
11282 Arg := Get_Pragma_Arg (Arg1);
11283 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
11285 Val := Expr_Value (Arg);
11287 if Val <= 0 then
11288 Error_Pragma_Arg
11289 ("maximum size for pragma% must be positive", Arg1);
11291 elsif UI_Is_In_Int_Range (Val) then
11292 Default_C_Record_Mechanism := UI_To_Int (Val);
11294 -- If a giant value is given, Int'Last will do well enough.
11295 -- If sometime someone complains that a record larger than
11296 -- two gigabytes is not copied, we will worry about it then.
11298 else
11299 Default_C_Record_Mechanism := Mechanism_Type'Last;
11300 end if;
11301 end C_Pass_By_Copy;
11303 -----------
11304 -- Check --
11305 -----------
11307 -- pragma Check ([Name =>] CHECK_KIND,
11308 -- [Check =>] Boolean_EXPRESSION
11309 -- [,[Message =>] String_EXPRESSION]);
11311 -- CHECK_KIND ::= IDENTIFIER |
11312 -- Pre'Class |
11313 -- Post'Class |
11314 -- Invariant'Class |
11315 -- Type_Invariant'Class
11317 -- The identifiers Assertions and Statement_Assertions are not
11318 -- allowed, since they have special meaning for Check_Policy.
11320 when Pragma_Check => Check : declare
11321 Expr : Node_Id;
11322 Eloc : Source_Ptr;
11323 Cname : Name_Id;
11324 Str : Node_Id;
11326 begin
11327 GNAT_Pragma;
11328 Check_At_Least_N_Arguments (2);
11329 Check_At_Most_N_Arguments (3);
11330 Check_Optional_Identifier (Arg1, Name_Name);
11331 Check_Optional_Identifier (Arg2, Name_Check);
11333 if Arg_Count = 3 then
11334 Check_Optional_Identifier (Arg3, Name_Message);
11335 Str := Get_Pragma_Arg (Arg3);
11336 end if;
11338 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
11339 Check_Arg_Is_Identifier (Arg1);
11340 Cname := Chars (Get_Pragma_Arg (Arg1));
11342 -- Check forbidden name Assertions or Statement_Assertions
11344 case Cname is
11345 when Name_Assertions =>
11346 Error_Pragma_Arg
11347 ("""Assertions"" is not allowed as a check kind "
11348 & "for pragma%", Arg1);
11350 when Name_Statement_Assertions =>
11351 Error_Pragma_Arg
11352 ("""Statement_Assertions"" is not allowed as a check kind "
11353 & "for pragma%", Arg1);
11355 when others =>
11356 null;
11357 end case;
11359 -- Check applicable policy. We skip this if Checked/Ignored status
11360 -- is already set (e.g. in the casse of a pragma from an aspect).
11362 if Is_Checked (N) or else Is_Ignored (N) then
11363 null;
11365 -- For a non-source pragma that is a rewriting of another pragma,
11366 -- copy the Is_Checked/Ignored status from the rewritten pragma.
11368 elsif Is_Rewrite_Substitution (N)
11369 and then Nkind (Original_Node (N)) = N_Pragma
11370 and then Original_Node (N) /= N
11371 then
11372 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
11373 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
11375 -- Otherwise query the applicable policy at this point
11377 else
11378 case Check_Kind (Cname) is
11379 when Name_Ignore =>
11380 Set_Is_Ignored (N, True);
11381 Set_Is_Checked (N, False);
11383 when Name_Check =>
11384 Set_Is_Ignored (N, False);
11385 Set_Is_Checked (N, True);
11387 -- For disable, rewrite pragma as null statement and skip
11388 -- rest of the analysis of the pragma.
11390 when Name_Disable =>
11391 Rewrite (N, Make_Null_Statement (Loc));
11392 Analyze (N);
11393 raise Pragma_Exit;
11395 -- No other possibilities
11397 when others =>
11398 raise Program_Error;
11399 end case;
11400 end if;
11402 -- If check kind was not Disable, then continue pragma analysis
11404 Expr := Get_Pragma_Arg (Arg2);
11406 -- Deal with SCO generation
11408 case Cname is
11409 when Name_Predicate |
11410 Name_Invariant =>
11412 -- Nothing to do: since checks occur in client units,
11413 -- the SCO for the aspect in the declaration unit is
11414 -- conservatively always enabled.
11416 null;
11418 when others =>
11420 if Is_Checked (N) and then not Split_PPC (N) then
11422 -- Mark aspect/pragma SCO as enabled
11424 Set_SCO_Pragma_Enabled (Loc);
11425 end if;
11426 end case;
11428 -- Deal with analyzing the string argument.
11430 if Arg_Count = 3 then
11432 -- If checks are not on we don't want any expansion (since
11433 -- such expansion would not get properly deleted) but
11434 -- we do want to analyze (to get proper references).
11435 -- The Preanalyze_And_Resolve routine does just what we want
11437 if Is_Ignored (N) then
11438 Preanalyze_And_Resolve (Str, Standard_String);
11440 -- Otherwise we need a proper analysis and expansion
11442 else
11443 Analyze_And_Resolve (Str, Standard_String);
11444 end if;
11445 end if;
11447 -- Now you might think we could just do the same with the Boolean
11448 -- expression if checks are off (and expansion is on) and then
11449 -- rewrite the check as a null statement. This would work but we
11450 -- would lose the useful warnings about an assertion being bound
11451 -- to fail even if assertions are turned off.
11453 -- So instead we wrap the boolean expression in an if statement
11454 -- that looks like:
11456 -- if False and then condition then
11457 -- null;
11458 -- end if;
11460 -- The reason we do this rewriting during semantic analysis rather
11461 -- than as part of normal expansion is that we cannot analyze and
11462 -- expand the code for the boolean expression directly, or it may
11463 -- cause insertion of actions that would escape the attempt to
11464 -- suppress the check code.
11466 -- Note that the Sloc for the if statement corresponds to the
11467 -- argument condition, not the pragma itself. The reason for
11468 -- this is that we may generate a warning if the condition is
11469 -- False at compile time, and we do not want to delete this
11470 -- warning when we delete the if statement.
11472 if Expander_Active and Is_Ignored (N) then
11473 Eloc := Sloc (Expr);
11475 Rewrite (N,
11476 Make_If_Statement (Eloc,
11477 Condition =>
11478 Make_And_Then (Eloc,
11479 Left_Opnd => Make_Identifier (Eloc, Name_False),
11480 Right_Opnd => Expr),
11481 Then_Statements => New_List (
11482 Make_Null_Statement (Eloc))));
11484 In_Assertion_Expr := In_Assertion_Expr + 1;
11485 Analyze (N);
11486 In_Assertion_Expr := In_Assertion_Expr - 1;
11488 -- Check is active or expansion not active. In these cases we can
11489 -- just go ahead and analyze the boolean with no worries.
11491 else
11492 In_Assertion_Expr := In_Assertion_Expr + 1;
11493 Analyze_And_Resolve (Expr, Any_Boolean);
11494 In_Assertion_Expr := In_Assertion_Expr - 1;
11495 end if;
11496 end Check;
11498 --------------------------
11499 -- Check_Float_Overflow --
11500 --------------------------
11502 -- pragma Check_Float_Overflow;
11504 when Pragma_Check_Float_Overflow =>
11505 GNAT_Pragma;
11506 Check_Valid_Configuration_Pragma;
11507 Check_Arg_Count (0);
11508 Check_Float_Overflow := not Machine_Overflows_On_Target;
11510 ----------------
11511 -- Check_Name --
11512 ----------------
11514 -- pragma Check_Name (check_IDENTIFIER);
11516 when Pragma_Check_Name =>
11517 GNAT_Pragma;
11518 Check_No_Identifiers;
11519 Check_Valid_Configuration_Pragma;
11520 Check_Arg_Count (1);
11521 Check_Arg_Is_Identifier (Arg1);
11523 declare
11524 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11526 begin
11527 for J in Check_Names.First .. Check_Names.Last loop
11528 if Check_Names.Table (J) = Nam then
11529 return;
11530 end if;
11531 end loop;
11533 Check_Names.Append (Nam);
11534 end;
11536 ------------------
11537 -- Check_Policy --
11538 ------------------
11540 -- This is the old style syntax, which is still allowed in all modes:
11542 -- pragma Check_Policy ([Name =>] CHECK_KIND
11543 -- [Policy =>] POLICY_IDENTIFIER);
11545 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
11547 -- CHECK_KIND ::= IDENTIFIER |
11548 -- Pre'Class |
11549 -- Post'Class |
11550 -- Type_Invariant'Class |
11551 -- Invariant'Class
11553 -- This is the new style syntax, compatible with Assertion_Policy
11554 -- and also allowed in all modes.
11556 -- Pragma Check_Policy (
11557 -- CHECK_KIND => POLICY_IDENTIFIER
11558 -- {, CHECK_KIND => POLICY_IDENTIFIER});
11560 -- Note: the identifiers Name and Policy are not allowed as
11561 -- Check_Kind values. This avoids ambiguities between the old and
11562 -- new form syntax.
11564 when Pragma_Check_Policy => Check_Policy : declare
11565 Ident : Node_Id;
11566 Kind : Node_Id;
11568 begin
11569 GNAT_Pragma;
11570 Check_At_Least_N_Arguments (1);
11572 -- A Check_Policy pragma can appear either as a configuration
11573 -- pragma, or in a declarative part or a package spec (see RM
11574 -- 11.5(5) for rules for Suppress/Unsuppress which are also
11575 -- followed for Check_Policy).
11577 if not Is_Configuration_Pragma then
11578 Check_Is_In_Decl_Part_Or_Package_Spec;
11579 end if;
11581 -- Figure out if we have the old or new syntax. We have the
11582 -- old syntax if the first argument has no identifier, or the
11583 -- identifier is Name.
11585 if Nkind (Arg1) /= N_Pragma_Argument_Association
11586 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
11587 then
11588 -- Old syntax
11590 Check_Arg_Count (2);
11591 Check_Optional_Identifier (Arg1, Name_Name);
11592 Kind := Get_Pragma_Arg (Arg1);
11593 Rewrite_Assertion_Kind (Kind);
11594 Check_Arg_Is_Identifier (Arg1);
11596 -- Check forbidden check kind
11598 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
11599 Error_Msg_Name_2 := Chars (Kind);
11600 Error_Pragma_Arg
11601 ("pragma% does not allow% as check name", Arg1);
11602 end if;
11604 -- Check policy
11606 Check_Optional_Identifier (Arg2, Name_Policy);
11607 Check_Arg_Is_One_Of
11608 (Arg2,
11609 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
11610 Ident := Get_Pragma_Arg (Arg2);
11612 if Chars (Kind) = Name_Ghost then
11614 -- Pragma Check_Policy specifying a Ghost policy cannot
11615 -- occur within a ghost subprogram or package.
11617 if Ghost_Mode > None then
11618 Error_Pragma
11619 ("pragma % cannot appear within ghost subprogram or "
11620 & "package");
11622 -- The policy identifier of pragma Ghost must be either
11623 -- Check or Ignore (SPARK RM 6.9(7)).
11625 elsif not Nam_In (Chars (Ident), Name_Check,
11626 Name_Ignore)
11627 then
11628 Error_Pragma_Arg
11629 ("argument of pragma % Ghost must be Check or Ignore",
11630 Arg2);
11631 end if;
11632 end if;
11634 -- And chain pragma on the Check_Policy_List for search
11636 Set_Next_Pragma (N, Opt.Check_Policy_List);
11637 Opt.Check_Policy_List := N;
11639 -- For the new syntax, what we do is to convert each argument to
11640 -- an old syntax equivalent. We do that because we want to chain
11641 -- old style Check_Policy pragmas for the search (we don't want
11642 -- to have to deal with multiple arguments in the search).
11644 else
11645 declare
11646 Arg : Node_Id;
11647 Argx : Node_Id;
11648 LocP : Source_Ptr;
11650 begin
11651 Arg := Arg1;
11652 while Present (Arg) loop
11653 LocP := Sloc (Arg);
11654 Argx := Get_Pragma_Arg (Arg);
11656 -- Kind must be specified
11658 if Nkind (Arg) /= N_Pragma_Argument_Association
11659 or else Chars (Arg) = No_Name
11660 then
11661 Error_Pragma_Arg
11662 ("missing assertion kind for pragma%", Arg);
11663 end if;
11665 -- Construct equivalent old form syntax Check_Policy
11666 -- pragma and insert it to get remaining checks.
11668 Insert_Action (N,
11669 Make_Pragma (LocP,
11670 Chars => Name_Check_Policy,
11671 Pragma_Argument_Associations => New_List (
11672 Make_Pragma_Argument_Association (LocP,
11673 Expression =>
11674 Make_Identifier (LocP, Chars (Arg))),
11675 Make_Pragma_Argument_Association (Sloc (Argx),
11676 Expression => Argx))));
11678 Arg := Next (Arg);
11679 end loop;
11681 -- Rewrite original Check_Policy pragma to null, since we
11682 -- have converted it into a series of old syntax pragmas.
11684 Rewrite (N, Make_Null_Statement (Loc));
11685 Analyze (N);
11686 end;
11687 end if;
11688 end Check_Policy;
11690 ---------------------
11691 -- CIL_Constructor --
11692 ---------------------
11694 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
11696 -- Processing for this pragma is shared with Java_Constructor
11698 -------------
11699 -- Comment --
11700 -------------
11702 -- pragma Comment (static_string_EXPRESSION)
11704 -- Processing for pragma Comment shares the circuitry for pragma
11705 -- Ident. The only differences are that Ident enforces a limit of 31
11706 -- characters on its argument, and also enforces limitations on
11707 -- placement for DEC compatibility. Pragma Comment shares neither of
11708 -- these restrictions.
11710 -------------------
11711 -- Common_Object --
11712 -------------------
11714 -- pragma Common_Object (
11715 -- [Internal =>] LOCAL_NAME
11716 -- [, [External =>] EXTERNAL_SYMBOL]
11717 -- [, [Size =>] EXTERNAL_SYMBOL]);
11719 -- Processing for this pragma is shared with Psect_Object
11721 ------------------------
11722 -- Compile_Time_Error --
11723 ------------------------
11725 -- pragma Compile_Time_Error
11726 -- (boolean_EXPRESSION, static_string_EXPRESSION);
11728 when Pragma_Compile_Time_Error =>
11729 GNAT_Pragma;
11730 Process_Compile_Time_Warning_Or_Error;
11732 --------------------------
11733 -- Compile_Time_Warning --
11734 --------------------------
11736 -- pragma Compile_Time_Warning
11737 -- (boolean_EXPRESSION, static_string_EXPRESSION);
11739 when Pragma_Compile_Time_Warning =>
11740 GNAT_Pragma;
11741 Process_Compile_Time_Warning_Or_Error;
11743 ---------------------------
11744 -- Compiler_Unit_Warning --
11745 ---------------------------
11747 -- pragma Compiler_Unit_Warning;
11749 -- Historical note
11751 -- Originally, we had only pragma Compiler_Unit, and it resulted in
11752 -- errors not warnings. This means that we had introduced a big extra
11753 -- inertia to compiler changes, since even if we implemented a new
11754 -- feature, and even if all versions to be used for bootstrapping
11755 -- implemented this new feature, we could not use it, since old
11756 -- compilers would give errors for using this feature in units
11757 -- having Compiler_Unit pragmas.
11759 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
11760 -- problem. We no longer have any units mentioning Compiler_Unit,
11761 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
11762 -- and thus generates a warning which can be ignored. So that deals
11763 -- with the problem of old compilers not implementing the newer form
11764 -- of the pragma.
11766 -- Newer compilers recognize the new pragma, but generate warning
11767 -- messages instead of errors, which again can be ignored in the
11768 -- case of an old compiler which implements a wanted new feature
11769 -- but at the time felt like warning about it for older compilers.
11771 -- We retain Compiler_Unit so that new compilers can be used to build
11772 -- older run-times that use this pragma. That's an unusual case, but
11773 -- it's easy enough to handle, so why not?
11775 when Pragma_Compiler_Unit | Pragma_Compiler_Unit_Warning =>
11776 GNAT_Pragma;
11777 Check_Arg_Count (0);
11779 -- Only recognized in main unit
11781 if Current_Sem_Unit = Main_Unit then
11782 Compiler_Unit := True;
11783 end if;
11785 -----------------------------
11786 -- Complete_Representation --
11787 -----------------------------
11789 -- pragma Complete_Representation;
11791 when Pragma_Complete_Representation =>
11792 GNAT_Pragma;
11793 Check_Arg_Count (0);
11795 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
11796 Error_Pragma
11797 ("pragma & must appear within record representation clause");
11798 end if;
11800 ----------------------------
11801 -- Complex_Representation --
11802 ----------------------------
11804 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
11806 when Pragma_Complex_Representation => Complex_Representation : declare
11807 E_Id : Entity_Id;
11808 E : Entity_Id;
11809 Ent : Entity_Id;
11811 begin
11812 GNAT_Pragma;
11813 Check_Arg_Count (1);
11814 Check_Optional_Identifier (Arg1, Name_Entity);
11815 Check_Arg_Is_Local_Name (Arg1);
11816 E_Id := Get_Pragma_Arg (Arg1);
11818 if Etype (E_Id) = Any_Type then
11819 return;
11820 end if;
11822 E := Entity (E_Id);
11824 if not Is_Record_Type (E) then
11825 Error_Pragma_Arg
11826 ("argument for pragma% must be record type", Arg1);
11827 end if;
11829 Ent := First_Entity (E);
11831 if No (Ent)
11832 or else No (Next_Entity (Ent))
11833 or else Present (Next_Entity (Next_Entity (Ent)))
11834 or else not Is_Floating_Point_Type (Etype (Ent))
11835 or else Etype (Ent) /= Etype (Next_Entity (Ent))
11836 then
11837 Error_Pragma_Arg
11838 ("record for pragma% must have two fields of the same "
11839 & "floating-point type", Arg1);
11841 else
11842 Set_Has_Complex_Representation (Base_Type (E));
11844 -- We need to treat the type has having a non-standard
11845 -- representation, for back-end purposes, even though in
11846 -- general a complex will have the default representation
11847 -- of a record with two real components.
11849 Set_Has_Non_Standard_Rep (Base_Type (E));
11850 end if;
11851 end Complex_Representation;
11853 -------------------------
11854 -- Component_Alignment --
11855 -------------------------
11857 -- pragma Component_Alignment (
11858 -- [Form =>] ALIGNMENT_CHOICE
11859 -- [, [Name =>] type_LOCAL_NAME]);
11861 -- ALIGNMENT_CHOICE ::=
11862 -- Component_Size
11863 -- | Component_Size_4
11864 -- | Storage_Unit
11865 -- | Default
11867 when Pragma_Component_Alignment => Component_AlignmentP : declare
11868 Args : Args_List (1 .. 2);
11869 Names : constant Name_List (1 .. 2) := (
11870 Name_Form,
11871 Name_Name);
11873 Form : Node_Id renames Args (1);
11874 Name : Node_Id renames Args (2);
11876 Atype : Component_Alignment_Kind;
11877 Typ : Entity_Id;
11879 begin
11880 GNAT_Pragma;
11881 Gather_Associations (Names, Args);
11883 if No (Form) then
11884 Error_Pragma ("missing Form argument for pragma%");
11885 end if;
11887 Check_Arg_Is_Identifier (Form);
11889 -- Get proper alignment, note that Default = Component_Size on all
11890 -- machines we have so far, and we want to set this value rather
11891 -- than the default value to indicate that it has been explicitly
11892 -- set (and thus will not get overridden by the default component
11893 -- alignment for the current scope)
11895 if Chars (Form) = Name_Component_Size then
11896 Atype := Calign_Component_Size;
11898 elsif Chars (Form) = Name_Component_Size_4 then
11899 Atype := Calign_Component_Size_4;
11901 elsif Chars (Form) = Name_Default then
11902 Atype := Calign_Component_Size;
11904 elsif Chars (Form) = Name_Storage_Unit then
11905 Atype := Calign_Storage_Unit;
11907 else
11908 Error_Pragma_Arg
11909 ("invalid Form parameter for pragma%", Form);
11910 end if;
11912 -- Case with no name, supplied, affects scope table entry
11914 if No (Name) then
11915 Scope_Stack.Table
11916 (Scope_Stack.Last).Component_Alignment_Default := Atype;
11918 -- Case of name supplied
11920 else
11921 Check_Arg_Is_Local_Name (Name);
11922 Find_Type (Name);
11923 Typ := Entity (Name);
11925 if Typ = Any_Type
11926 or else Rep_Item_Too_Early (Typ, N)
11927 then
11928 return;
11929 else
11930 Typ := Underlying_Type (Typ);
11931 end if;
11933 if not Is_Record_Type (Typ)
11934 and then not Is_Array_Type (Typ)
11935 then
11936 Error_Pragma_Arg
11937 ("Name parameter of pragma% must identify record or "
11938 & "array type", Name);
11939 end if;
11941 -- An explicit Component_Alignment pragma overrides an
11942 -- implicit pragma Pack, but not an explicit one.
11944 if not Has_Pragma_Pack (Base_Type (Typ)) then
11945 Set_Is_Packed (Base_Type (Typ), False);
11946 Set_Component_Alignment (Base_Type (Typ), Atype);
11947 end if;
11948 end if;
11949 end Component_AlignmentP;
11951 --------------------
11952 -- Contract_Cases --
11953 --------------------
11955 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
11957 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
11959 -- CASE_GUARD ::= boolean_EXPRESSION | others
11961 -- CONSEQUENCE ::= boolean_EXPRESSION
11963 when Pragma_Contract_Cases => Contract_Cases : declare
11964 Subp_Decl : Node_Id;
11965 Subp_Id : Entity_Id;
11967 begin
11968 GNAT_Pragma;
11969 Check_No_Identifiers;
11970 Check_Arg_Count (1);
11972 -- The pragma is analyzed at the end of the declarative part which
11973 -- contains the related subprogram. Reset the analyzed flag.
11975 Set_Analyzed (N, False);
11977 -- Ensure the proper placement of the pragma. Contract_Cases must
11978 -- be associated with a subprogram declaration or a body that acts
11979 -- as a spec.
11981 Subp_Decl :=
11982 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
11984 -- Generic subprogram
11986 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
11987 null;
11989 -- Body acts as spec
11991 elsif Nkind (Subp_Decl) = N_Subprogram_Body
11992 and then No (Corresponding_Spec (Subp_Decl))
11993 then
11994 null;
11996 -- Body stub acts as spec
11998 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
11999 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
12000 then
12001 null;
12003 -- Subprogram
12005 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
12006 null;
12008 else
12009 Pragma_Misplaced;
12010 return;
12011 end if;
12013 Subp_Id := Defining_Entity (Subp_Decl);
12015 Ensure_Aggregate_Form (Get_Argument (N, Subp_Id));
12017 -- Construct a generic template for the pragma when the context is
12018 -- a generic subprogram and the pragma is a source construct.
12020 Create_Generic_Template (N, Subp_Id);
12022 -- Fully analyze the pragma when it appears inside a subprogram
12023 -- body because it cannot benefit from forward references.
12025 if Nkind (Subp_Decl) = N_Subprogram_Body then
12026 Analyze_Contract_Cases_In_Decl_Part (N);
12027 end if;
12029 -- Chain the pragma on the contract for further processing
12031 Add_Contract_Item (N, Subp_Id);
12032 end Contract_Cases;
12034 ----------------
12035 -- Controlled --
12036 ----------------
12038 -- pragma Controlled (first_subtype_LOCAL_NAME);
12040 when Pragma_Controlled => Controlled : declare
12041 Arg : Node_Id;
12043 begin
12044 Check_No_Identifiers;
12045 Check_Arg_Count (1);
12046 Check_Arg_Is_Local_Name (Arg1);
12047 Arg := Get_Pragma_Arg (Arg1);
12049 if not Is_Entity_Name (Arg)
12050 or else not Is_Access_Type (Entity (Arg))
12051 then
12052 Error_Pragma_Arg ("pragma% requires access type", Arg1);
12053 else
12054 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
12055 end if;
12056 end Controlled;
12058 ----------------
12059 -- Convention --
12060 ----------------
12062 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
12063 -- [Entity =>] LOCAL_NAME);
12065 when Pragma_Convention => Convention : declare
12066 C : Convention_Id;
12067 E : Entity_Id;
12068 pragma Warnings (Off, C);
12069 pragma Warnings (Off, E);
12070 begin
12071 Check_Arg_Order ((Name_Convention, Name_Entity));
12072 Check_Ada_83_Warning;
12073 Check_Arg_Count (2);
12074 Process_Convention (C, E);
12075 end Convention;
12077 ---------------------------
12078 -- Convention_Identifier --
12079 ---------------------------
12081 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
12082 -- [Convention =>] convention_IDENTIFIER);
12084 when Pragma_Convention_Identifier => Convention_Identifier : declare
12085 Idnam : Name_Id;
12086 Cname : Name_Id;
12088 begin
12089 GNAT_Pragma;
12090 Check_Arg_Order ((Name_Name, Name_Convention));
12091 Check_Arg_Count (2);
12092 Check_Optional_Identifier (Arg1, Name_Name);
12093 Check_Optional_Identifier (Arg2, Name_Convention);
12094 Check_Arg_Is_Identifier (Arg1);
12095 Check_Arg_Is_Identifier (Arg2);
12096 Idnam := Chars (Get_Pragma_Arg (Arg1));
12097 Cname := Chars (Get_Pragma_Arg (Arg2));
12099 if Is_Convention_Name (Cname) then
12100 Record_Convention_Identifier
12101 (Idnam, Get_Convention_Id (Cname));
12102 else
12103 Error_Pragma_Arg
12104 ("second arg for % pragma must be convention", Arg2);
12105 end if;
12106 end Convention_Identifier;
12108 ---------------
12109 -- CPP_Class --
12110 ---------------
12112 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
12114 when Pragma_CPP_Class => CPP_Class : declare
12115 begin
12116 GNAT_Pragma;
12118 if Warn_On_Obsolescent_Feature then
12119 Error_Msg_N
12120 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
12121 & "effect; replace it by pragma import?j?", N);
12122 end if;
12124 Check_Arg_Count (1);
12126 Rewrite (N,
12127 Make_Pragma (Loc,
12128 Chars => Name_Import,
12129 Pragma_Argument_Associations => New_List (
12130 Make_Pragma_Argument_Association (Loc,
12131 Expression => Make_Identifier (Loc, Name_CPP)),
12132 New_Copy (First (Pragma_Argument_Associations (N))))));
12133 Analyze (N);
12134 end CPP_Class;
12136 ---------------------
12137 -- CPP_Constructor --
12138 ---------------------
12140 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
12141 -- [, [External_Name =>] static_string_EXPRESSION ]
12142 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12144 when Pragma_CPP_Constructor => CPP_Constructor : declare
12145 Elmt : Elmt_Id;
12146 Id : Entity_Id;
12147 Def_Id : Entity_Id;
12148 Tag_Typ : Entity_Id;
12150 begin
12151 GNAT_Pragma;
12152 Check_At_Least_N_Arguments (1);
12153 Check_At_Most_N_Arguments (3);
12154 Check_Optional_Identifier (Arg1, Name_Entity);
12155 Check_Arg_Is_Local_Name (Arg1);
12157 Id := Get_Pragma_Arg (Arg1);
12158 Find_Program_Unit_Name (Id);
12160 -- If we did not find the name, we are done
12162 if Etype (Id) = Any_Type then
12163 return;
12164 end if;
12166 Def_Id := Entity (Id);
12168 -- Check if already defined as constructor
12170 if Is_Constructor (Def_Id) then
12171 Error_Msg_N
12172 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
12173 return;
12174 end if;
12176 if Ekind (Def_Id) = E_Function
12177 and then (Is_CPP_Class (Etype (Def_Id))
12178 or else (Is_Class_Wide_Type (Etype (Def_Id))
12179 and then
12180 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
12181 then
12182 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
12183 Error_Msg_N
12184 ("'C'P'P constructor must be defined in the scope of "
12185 & "its returned type", Arg1);
12186 end if;
12188 if Arg_Count >= 2 then
12189 Set_Imported (Def_Id);
12190 Set_Is_Public (Def_Id);
12191 Process_Interface_Name (Def_Id, Arg2, Arg3);
12192 end if;
12194 Set_Has_Completion (Def_Id);
12195 Set_Is_Constructor (Def_Id);
12196 Set_Convention (Def_Id, Convention_CPP);
12198 -- Imported C++ constructors are not dispatching primitives
12199 -- because in C++ they don't have a dispatch table slot.
12200 -- However, in Ada the constructor has the profile of a
12201 -- function that returns a tagged type and therefore it has
12202 -- been treated as a primitive operation during semantic
12203 -- analysis. We now remove it from the list of primitive
12204 -- operations of the type.
12206 if Is_Tagged_Type (Etype (Def_Id))
12207 and then not Is_Class_Wide_Type (Etype (Def_Id))
12208 and then Is_Dispatching_Operation (Def_Id)
12209 then
12210 Tag_Typ := Etype (Def_Id);
12212 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
12213 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
12214 Next_Elmt (Elmt);
12215 end loop;
12217 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
12218 Set_Is_Dispatching_Operation (Def_Id, False);
12219 end if;
12221 -- For backward compatibility, if the constructor returns a
12222 -- class wide type, and we internally change the return type to
12223 -- the corresponding root type.
12225 if Is_Class_Wide_Type (Etype (Def_Id)) then
12226 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
12227 end if;
12228 else
12229 Error_Pragma_Arg
12230 ("pragma% requires function returning a 'C'P'P_Class type",
12231 Arg1);
12232 end if;
12233 end CPP_Constructor;
12235 -----------------
12236 -- CPP_Virtual --
12237 -----------------
12239 when Pragma_CPP_Virtual => CPP_Virtual : declare
12240 begin
12241 GNAT_Pragma;
12243 if Warn_On_Obsolescent_Feature then
12244 Error_Msg_N
12245 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
12246 & "effect?j?", N);
12247 end if;
12248 end CPP_Virtual;
12250 ----------------
12251 -- CPP_Vtable --
12252 ----------------
12254 when Pragma_CPP_Vtable => CPP_Vtable : declare
12255 begin
12256 GNAT_Pragma;
12258 if Warn_On_Obsolescent_Feature then
12259 Error_Msg_N
12260 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
12261 & "effect?j?", N);
12262 end if;
12263 end CPP_Vtable;
12265 ---------
12266 -- CPU --
12267 ---------
12269 -- pragma CPU (EXPRESSION);
12271 when Pragma_CPU => CPU : declare
12272 P : constant Node_Id := Parent (N);
12273 Arg : Node_Id;
12274 Ent : Entity_Id;
12276 begin
12277 Ada_2012_Pragma;
12278 Check_No_Identifiers;
12279 Check_Arg_Count (1);
12281 -- Subprogram case
12283 if Nkind (P) = N_Subprogram_Body then
12284 Check_In_Main_Program;
12286 Arg := Get_Pragma_Arg (Arg1);
12287 Analyze_And_Resolve (Arg, Any_Integer);
12289 Ent := Defining_Unit_Name (Specification (P));
12291 if Nkind (Ent) = N_Defining_Program_Unit_Name then
12292 Ent := Defining_Identifier (Ent);
12293 end if;
12295 -- Must be static
12297 if not Is_OK_Static_Expression (Arg) then
12298 Flag_Non_Static_Expr
12299 ("main subprogram affinity is not static!", Arg);
12300 raise Pragma_Exit;
12302 -- If constraint error, then we already signalled an error
12304 elsif Raises_Constraint_Error (Arg) then
12305 null;
12307 -- Otherwise check in range
12309 else
12310 declare
12311 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
12312 -- This is the entity System.Multiprocessors.CPU_Range;
12314 Val : constant Uint := Expr_Value (Arg);
12316 begin
12317 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
12318 or else
12319 Val > Expr_Value (Type_High_Bound (CPU_Id))
12320 then
12321 Error_Pragma_Arg
12322 ("main subprogram CPU is out of range", Arg1);
12323 end if;
12324 end;
12325 end if;
12327 Set_Main_CPU
12328 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12330 -- Task case
12332 elsif Nkind (P) = N_Task_Definition then
12333 Arg := Get_Pragma_Arg (Arg1);
12334 Ent := Defining_Identifier (Parent (P));
12336 -- The expression must be analyzed in the special manner
12337 -- described in "Handling of Default and Per-Object
12338 -- Expressions" in sem.ads.
12340 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
12342 -- Anything else is incorrect
12344 else
12345 Pragma_Misplaced;
12346 end if;
12348 -- Check duplicate pragma before we chain the pragma in the Rep
12349 -- Item chain of Ent.
12351 Check_Duplicate_Pragma (Ent);
12352 Record_Rep_Item (Ent, N);
12353 end CPU;
12355 -----------
12356 -- Debug --
12357 -----------
12359 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
12361 when Pragma_Debug => Debug : declare
12362 Cond : Node_Id;
12363 Call : Node_Id;
12365 begin
12366 GNAT_Pragma;
12368 -- The condition for executing the call is that the expander
12369 -- is active and that we are not ignoring this debug pragma.
12371 Cond :=
12372 New_Occurrence_Of
12373 (Boolean_Literals
12374 (Expander_Active and then not Is_Ignored (N)),
12375 Loc);
12377 if not Is_Ignored (N) then
12378 Set_SCO_Pragma_Enabled (Loc);
12379 end if;
12381 if Arg_Count = 2 then
12382 Cond :=
12383 Make_And_Then (Loc,
12384 Left_Opnd => Relocate_Node (Cond),
12385 Right_Opnd => Get_Pragma_Arg (Arg1));
12386 Call := Get_Pragma_Arg (Arg2);
12387 else
12388 Call := Get_Pragma_Arg (Arg1);
12389 end if;
12391 if Nkind_In (Call,
12392 N_Indexed_Component,
12393 N_Function_Call,
12394 N_Identifier,
12395 N_Expanded_Name,
12396 N_Selected_Component)
12397 then
12398 -- If this pragma Debug comes from source, its argument was
12399 -- parsed as a name form (which is syntactically identical).
12400 -- In a generic context a parameterless call will be left as
12401 -- an expanded name (if global) or selected_component if local.
12402 -- Change it to a procedure call statement now.
12404 Change_Name_To_Procedure_Call_Statement (Call);
12406 elsif Nkind (Call) = N_Procedure_Call_Statement then
12408 -- Already in the form of a procedure call statement: nothing
12409 -- to do (could happen in case of an internally generated
12410 -- pragma Debug).
12412 null;
12414 else
12415 -- All other cases: diagnose error
12417 Error_Msg
12418 ("argument of pragma ""Debug"" is not procedure call",
12419 Sloc (Call));
12420 return;
12421 end if;
12423 -- Rewrite into a conditional with an appropriate condition. We
12424 -- wrap the procedure call in a block so that overhead from e.g.
12425 -- use of the secondary stack does not generate execution overhead
12426 -- for suppressed conditions.
12428 -- Normally the analysis that follows will freeze the subprogram
12429 -- being called. However, if the call is to a null procedure,
12430 -- we want to freeze it before creating the block, because the
12431 -- analysis that follows may be done with expansion disabled, in
12432 -- which case the body will not be generated, leading to spurious
12433 -- errors.
12435 if Nkind (Call) = N_Procedure_Call_Statement
12436 and then Is_Entity_Name (Name (Call))
12437 then
12438 Analyze (Name (Call));
12439 Freeze_Before (N, Entity (Name (Call)));
12440 end if;
12442 Rewrite (N,
12443 Make_Implicit_If_Statement (N,
12444 Condition => Cond,
12445 Then_Statements => New_List (
12446 Make_Block_Statement (Loc,
12447 Handled_Statement_Sequence =>
12448 Make_Handled_Sequence_Of_Statements (Loc,
12449 Statements => New_List (Relocate_Node (Call)))))));
12450 Analyze (N);
12452 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
12453 -- after analysis of the normally rewritten node, to capture all
12454 -- references to entities, which avoids issuing wrong warnings
12455 -- about unused entities.
12457 if GNATprove_Mode then
12458 Rewrite (N, Make_Null_Statement (Loc));
12459 end if;
12460 end Debug;
12462 ------------------
12463 -- Debug_Policy --
12464 ------------------
12466 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
12468 when Pragma_Debug_Policy =>
12469 GNAT_Pragma;
12470 Check_Arg_Count (1);
12471 Check_No_Identifiers;
12472 Check_Arg_Is_Identifier (Arg1);
12474 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
12475 -- rewrite it that way, and let the rest of the checking come
12476 -- from analyzing the rewritten pragma.
12478 Rewrite (N,
12479 Make_Pragma (Loc,
12480 Chars => Name_Check_Policy,
12481 Pragma_Argument_Associations => New_List (
12482 Make_Pragma_Argument_Association (Loc,
12483 Expression => Make_Identifier (Loc, Name_Debug)),
12485 Make_Pragma_Argument_Association (Loc,
12486 Expression => Get_Pragma_Arg (Arg1)))));
12487 Analyze (N);
12489 -------------------------------
12490 -- Default_Initial_Condition --
12491 -------------------------------
12493 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
12495 when Pragma_Default_Initial_Condition => Default_Init_Cond : declare
12496 Discard : Boolean;
12497 Stmt : Node_Id;
12498 Typ : Entity_Id;
12500 begin
12501 GNAT_Pragma;
12502 Check_No_Identifiers;
12503 Check_At_Most_N_Arguments (1);
12505 Stmt := Prev (N);
12506 while Present (Stmt) loop
12508 -- Skip prior pragmas, but check for duplicates
12510 if Nkind (Stmt) = N_Pragma then
12511 if Pragma_Name (Stmt) = Pname then
12512 Error_Msg_Name_1 := Pname;
12513 Error_Msg_Sloc := Sloc (Stmt);
12514 Error_Msg_N ("pragma % duplicates pragma declared#", N);
12515 end if;
12517 -- Skip internally generated code
12519 elsif not Comes_From_Source (Stmt) then
12520 null;
12522 -- The associated private type [extension] has been found, stop
12523 -- the search.
12525 elsif Nkind_In (Stmt, N_Private_Extension_Declaration,
12526 N_Private_Type_Declaration)
12527 then
12528 Typ := Defining_Entity (Stmt);
12529 exit;
12531 -- The pragma does not apply to a legal construct, issue an
12532 -- error and stop the analysis.
12534 else
12535 Pragma_Misplaced;
12536 return;
12537 end if;
12539 Stmt := Prev (Stmt);
12540 end loop;
12542 Set_Has_Default_Init_Cond (Typ);
12543 Set_Has_Inherited_Default_Init_Cond (Typ, False);
12545 -- Chain the pragma on the rep item chain for further processing
12547 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12548 end Default_Init_Cond;
12550 ----------------------------------
12551 -- Default_Scalar_Storage_Order --
12552 ----------------------------------
12554 -- pragma Default_Scalar_Storage_Order
12555 -- (High_Order_First | Low_Order_First);
12557 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
12558 Default : Character;
12560 begin
12561 GNAT_Pragma;
12562 Check_Arg_Count (1);
12564 -- Default_Scalar_Storage_Order can appear as a configuration
12565 -- pragma, or in a declarative part of a package spec.
12567 if not Is_Configuration_Pragma then
12568 Check_Is_In_Decl_Part_Or_Package_Spec;
12569 end if;
12571 Check_No_Identifiers;
12572 Check_Arg_Is_One_Of
12573 (Arg1, Name_High_Order_First, Name_Low_Order_First);
12574 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12575 Default := Fold_Upper (Name_Buffer (1));
12577 if not Support_Nondefault_SSO_On_Target
12578 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
12579 then
12580 if Warn_On_Unrecognized_Pragma then
12581 Error_Msg_N
12582 ("non-default Scalar_Storage_Order not supported "
12583 & "on target?g?", N);
12584 Error_Msg_N
12585 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
12586 end if;
12588 -- Here set the specified default
12590 else
12591 Opt.Default_SSO := Default;
12592 end if;
12593 end DSSO;
12595 --------------------------
12596 -- Default_Storage_Pool --
12597 --------------------------
12599 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
12601 when Pragma_Default_Storage_Pool =>
12602 Ada_2012_Pragma;
12603 Check_Arg_Count (1);
12605 -- Default_Storage_Pool can appear as a configuration pragma, or
12606 -- in a declarative part of a package spec.
12608 if not Is_Configuration_Pragma then
12609 Check_Is_In_Decl_Part_Or_Package_Spec;
12610 end if;
12612 -- Case of Default_Storage_Pool (null);
12614 if Nkind (Expression (Arg1)) = N_Null then
12615 Analyze (Expression (Arg1));
12617 -- This is an odd case, this is not really an expression, so
12618 -- we don't have a type for it. So just set the type to Empty.
12620 Set_Etype (Expression (Arg1), Empty);
12622 -- Case of Default_Storage_Pool (storage_pool_NAME);
12624 else
12625 -- If it's a configuration pragma, then the only allowed
12626 -- argument is "null".
12628 if Is_Configuration_Pragma then
12629 Error_Pragma_Arg ("NULL expected", Arg1);
12630 end if;
12632 -- The expected type for a non-"null" argument is
12633 -- Root_Storage_Pool'Class, and the pool must be a variable.
12635 Analyze_And_Resolve
12636 (Get_Pragma_Arg (Arg1),
12637 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
12639 if not Is_Variable (Expression (Arg1)) then
12640 Error_Pragma_Arg
12641 ("default storage pool must be a variable", Arg1);
12642 end if;
12643 end if;
12645 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
12646 -- for an access type will use this information to set the
12647 -- appropriate attributes of the access type.
12649 Default_Pool := Expression (Arg1);
12651 -------------
12652 -- Depends --
12653 -------------
12655 -- pragma Depends (DEPENDENCY_RELATION);
12657 -- DEPENDENCY_RELATION ::=
12658 -- null
12659 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
12661 -- DEPENDENCY_CLAUSE ::=
12662 -- OUTPUT_LIST =>[+] INPUT_LIST
12663 -- | NULL_DEPENDENCY_CLAUSE
12665 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
12667 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
12669 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
12671 -- OUTPUT ::= NAME | FUNCTION_RESULT
12672 -- INPUT ::= NAME
12674 -- where FUNCTION_RESULT is a function Result attribute_reference
12676 when Pragma_Depends => Depends : declare
12677 Subp_Decl : Node_Id;
12678 Subp_Id : Entity_Id;
12680 begin
12681 GNAT_Pragma;
12682 Check_Arg_Count (1);
12684 -- Ensure the proper placement of the pragma. Depends must be
12685 -- associated with a subprogram declaration or a body that acts
12686 -- as a spec.
12688 Subp_Decl :=
12689 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
12691 -- Body acts as spec
12693 if Nkind (Subp_Decl) = N_Subprogram_Body
12694 and then No (Corresponding_Spec (Subp_Decl))
12695 then
12696 null;
12698 -- Body stub acts as spec
12700 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
12701 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
12702 then
12703 null;
12705 -- Subprogram declaration
12707 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
12708 null;
12710 else
12711 Pragma_Misplaced;
12712 return;
12713 end if;
12715 Subp_Id := Defining_Entity (Subp_Decl);
12717 Ensure_Aggregate_Form (Get_Argument (N, Subp_Id));
12719 -- Construct a generic template for the pragma when the context is
12720 -- a generic subprogram and the pragma is a source construct.
12722 Create_Generic_Template (N, Subp_Id);
12724 -- When the pragma appears on a subprogram body, perform the full
12725 -- analysis now.
12727 if Nkind (Subp_Decl) = N_Subprogram_Body then
12728 Analyze_Depends_In_Decl_Part (N);
12729 end if;
12731 -- Chain the pragma on the contract for further processing
12733 Add_Contract_Item (N, Subp_Id);
12734 end Depends;
12736 ---------------------
12737 -- Detect_Blocking --
12738 ---------------------
12740 -- pragma Detect_Blocking;
12742 when Pragma_Detect_Blocking =>
12743 Ada_2005_Pragma;
12744 Check_Arg_Count (0);
12745 Check_Valid_Configuration_Pragma;
12746 Detect_Blocking := True;
12748 ------------------------------------
12749 -- Disable_Atomic_Synchronization --
12750 ------------------------------------
12752 -- pragma Disable_Atomic_Synchronization [(Entity)];
12754 when Pragma_Disable_Atomic_Synchronization =>
12755 GNAT_Pragma;
12756 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
12758 -------------------
12759 -- Discard_Names --
12760 -------------------
12762 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
12764 when Pragma_Discard_Names => Discard_Names : declare
12765 E : Entity_Id;
12766 E_Id : Entity_Id;
12768 begin
12769 Check_Ada_83_Warning;
12771 -- Deal with configuration pragma case
12773 if Arg_Count = 0 and then Is_Configuration_Pragma then
12774 Global_Discard_Names := True;
12775 return;
12777 -- Otherwise, check correct appropriate context
12779 else
12780 Check_Is_In_Decl_Part_Or_Package_Spec;
12782 if Arg_Count = 0 then
12784 -- If there is no parameter, then from now on this pragma
12785 -- applies to any enumeration, exception or tagged type
12786 -- defined in the current declarative part, and recursively
12787 -- to any nested scope.
12789 Set_Discard_Names (Current_Scope);
12790 return;
12792 else
12793 Check_Arg_Count (1);
12794 Check_Optional_Identifier (Arg1, Name_On);
12795 Check_Arg_Is_Local_Name (Arg1);
12797 E_Id := Get_Pragma_Arg (Arg1);
12799 if Etype (E_Id) = Any_Type then
12800 return;
12801 else
12802 E := Entity (E_Id);
12803 end if;
12805 if (Is_First_Subtype (E)
12806 and then
12807 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
12808 or else Ekind (E) = E_Exception
12809 then
12810 Set_Discard_Names (E);
12811 Record_Rep_Item (E, N);
12813 else
12814 Error_Pragma_Arg
12815 ("inappropriate entity for pragma%", Arg1);
12816 end if;
12818 end if;
12819 end if;
12820 end Discard_Names;
12822 ------------------------
12823 -- Dispatching_Domain --
12824 ------------------------
12826 -- pragma Dispatching_Domain (EXPRESSION);
12828 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
12829 P : constant Node_Id := Parent (N);
12830 Arg : Node_Id;
12831 Ent : Entity_Id;
12833 begin
12834 Ada_2012_Pragma;
12835 Check_No_Identifiers;
12836 Check_Arg_Count (1);
12838 -- This pragma is born obsolete, but not the aspect
12840 if not From_Aspect_Specification (N) then
12841 Check_Restriction
12842 (No_Obsolescent_Features, Pragma_Identifier (N));
12843 end if;
12845 if Nkind (P) = N_Task_Definition then
12846 Arg := Get_Pragma_Arg (Arg1);
12847 Ent := Defining_Identifier (Parent (P));
12849 -- The expression must be analyzed in the special manner
12850 -- described in "Handling of Default and Per-Object
12851 -- Expressions" in sem.ads.
12853 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
12855 -- Check duplicate pragma before we chain the pragma in the Rep
12856 -- Item chain of Ent.
12858 Check_Duplicate_Pragma (Ent);
12859 Record_Rep_Item (Ent, N);
12861 -- Anything else is incorrect
12863 else
12864 Pragma_Misplaced;
12865 end if;
12866 end Dispatching_Domain;
12868 ---------------
12869 -- Elaborate --
12870 ---------------
12872 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
12874 when Pragma_Elaborate => Elaborate : declare
12875 Arg : Node_Id;
12876 Citem : Node_Id;
12878 begin
12879 -- Pragma must be in context items list of a compilation unit
12881 if not Is_In_Context_Clause then
12882 Pragma_Misplaced;
12883 end if;
12885 -- Must be at least one argument
12887 if Arg_Count = 0 then
12888 Error_Pragma ("pragma% requires at least one argument");
12889 end if;
12891 -- In Ada 83 mode, there can be no items following it in the
12892 -- context list except other pragmas and implicit with clauses
12893 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
12894 -- placement rule does not apply.
12896 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
12897 Citem := Next (N);
12898 while Present (Citem) loop
12899 if Nkind (Citem) = N_Pragma
12900 or else (Nkind (Citem) = N_With_Clause
12901 and then Implicit_With (Citem))
12902 then
12903 null;
12904 else
12905 Error_Pragma
12906 ("(Ada 83) pragma% must be at end of context clause");
12907 end if;
12909 Next (Citem);
12910 end loop;
12911 end if;
12913 -- Finally, the arguments must all be units mentioned in a with
12914 -- clause in the same context clause. Note we already checked (in
12915 -- Par.Prag) that the arguments are all identifiers or selected
12916 -- components.
12918 Arg := Arg1;
12919 Outer : while Present (Arg) loop
12920 Citem := First (List_Containing (N));
12921 Inner : while Citem /= N loop
12922 if Nkind (Citem) = N_With_Clause
12923 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
12924 then
12925 Set_Elaborate_Present (Citem, True);
12926 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
12928 -- With the pragma present, elaboration calls on
12929 -- subprograms from the named unit need no further
12930 -- checks, as long as the pragma appears in the current
12931 -- compilation unit. If the pragma appears in some unit
12932 -- in the context, there might still be a need for an
12933 -- Elaborate_All_Desirable from the current compilation
12934 -- to the named unit, so we keep the check enabled.
12936 if In_Extended_Main_Source_Unit (N) then
12938 -- This does not apply in SPARK mode, where we allow
12939 -- pragma Elaborate, but we don't trust it to be right
12940 -- so we will still insist on the Elaborate_All.
12942 if SPARK_Mode /= On then
12943 Set_Suppress_Elaboration_Warnings
12944 (Entity (Name (Citem)));
12945 end if;
12946 end if;
12948 exit Inner;
12949 end if;
12951 Next (Citem);
12952 end loop Inner;
12954 if Citem = N then
12955 Error_Pragma_Arg
12956 ("argument of pragma% is not withed unit", Arg);
12957 end if;
12959 Next (Arg);
12960 end loop Outer;
12962 -- Give a warning if operating in static mode with one of the
12963 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set.
12965 if Elab_Warnings
12966 and not Dynamic_Elaboration_Checks
12968 -- pragma Elaborate not allowed in SPARK mode anyway. We
12969 -- already complained about it, no point in generating any
12970 -- further complaint.
12972 and SPARK_Mode /= On
12973 then
12974 Error_Msg_N
12975 ("?l?use of pragma Elaborate may not be safe", N);
12976 Error_Msg_N
12977 ("?l?use pragma Elaborate_All instead if possible", N);
12978 end if;
12979 end Elaborate;
12981 -------------------
12982 -- Elaborate_All --
12983 -------------------
12985 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
12987 when Pragma_Elaborate_All => Elaborate_All : declare
12988 Arg : Node_Id;
12989 Citem : Node_Id;
12991 begin
12992 Check_Ada_83_Warning;
12994 -- Pragma must be in context items list of a compilation unit
12996 if not Is_In_Context_Clause then
12997 Pragma_Misplaced;
12998 end if;
13000 -- Must be at least one argument
13002 if Arg_Count = 0 then
13003 Error_Pragma ("pragma% requires at least one argument");
13004 end if;
13006 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
13007 -- have to appear at the end of the context clause, but may
13008 -- appear mixed in with other items, even in Ada 83 mode.
13010 -- Final check: the arguments must all be units mentioned in
13011 -- a with clause in the same context clause. Note that we
13012 -- already checked (in Par.Prag) that all the arguments are
13013 -- either identifiers or selected components.
13015 Arg := Arg1;
13016 Outr : while Present (Arg) loop
13017 Citem := First (List_Containing (N));
13018 Innr : while Citem /= N loop
13019 if Nkind (Citem) = N_With_Clause
13020 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
13021 then
13022 Set_Elaborate_All_Present (Citem, True);
13023 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
13025 -- Suppress warnings and elaboration checks on the named
13026 -- unit if the pragma is in the current compilation, as
13027 -- for pragma Elaborate.
13029 if In_Extended_Main_Source_Unit (N) then
13030 Set_Suppress_Elaboration_Warnings
13031 (Entity (Name (Citem)));
13032 end if;
13033 exit Innr;
13034 end if;
13036 Next (Citem);
13037 end loop Innr;
13039 if Citem = N then
13040 Set_Error_Posted (N);
13041 Error_Pragma_Arg
13042 ("argument of pragma% is not withed unit", Arg);
13043 end if;
13045 Next (Arg);
13046 end loop Outr;
13047 end Elaborate_All;
13049 --------------------
13050 -- Elaborate_Body --
13051 --------------------
13053 -- pragma Elaborate_Body [( library_unit_NAME )];
13055 when Pragma_Elaborate_Body => Elaborate_Body : declare
13056 Cunit_Node : Node_Id;
13057 Cunit_Ent : Entity_Id;
13059 begin
13060 Check_Ada_83_Warning;
13061 Check_Valid_Library_Unit_Pragma;
13063 if Nkind (N) = N_Null_Statement then
13064 return;
13065 end if;
13067 Cunit_Node := Cunit (Current_Sem_Unit);
13068 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13070 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
13071 N_Subprogram_Body)
13072 then
13073 Error_Pragma ("pragma% must refer to a spec, not a body");
13074 else
13075 Set_Body_Required (Cunit_Node, True);
13076 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
13078 -- If we are in dynamic elaboration mode, then we suppress
13079 -- elaboration warnings for the unit, since it is definitely
13080 -- fine NOT to do dynamic checks at the first level (and such
13081 -- checks will be suppressed because no elaboration boolean
13082 -- is created for Elaborate_Body packages).
13084 -- But in the static model of elaboration, Elaborate_Body is
13085 -- definitely NOT good enough to ensure elaboration safety on
13086 -- its own, since the body may WITH other units that are not
13087 -- safe from an elaboration point of view, so a client must
13088 -- still do an Elaborate_All on such units.
13090 -- Debug flag -gnatdD restores the old behavior of 3.13, where
13091 -- Elaborate_Body always suppressed elab warnings.
13093 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
13094 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
13095 end if;
13096 end if;
13097 end Elaborate_Body;
13099 ------------------------
13100 -- Elaboration_Checks --
13101 ------------------------
13103 -- pragma Elaboration_Checks (Static | Dynamic);
13105 when Pragma_Elaboration_Checks =>
13106 GNAT_Pragma;
13107 Check_Arg_Count (1);
13108 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
13110 -- Set flag accordingly (ignore attempt at dynamic elaboration
13111 -- checks in SPARK mode).
13113 Dynamic_Elaboration_Checks :=
13114 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic)
13115 and then SPARK_Mode /= On;
13117 ---------------
13118 -- Eliminate --
13119 ---------------
13121 -- pragma Eliminate (
13122 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
13123 -- [,[Entity =>] IDENTIFIER |
13124 -- SELECTED_COMPONENT |
13125 -- STRING_LITERAL]
13126 -- [, OVERLOADING_RESOLUTION]);
13128 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
13129 -- SOURCE_LOCATION
13131 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
13132 -- FUNCTION_PROFILE
13134 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
13136 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
13137 -- Result_Type => result_SUBTYPE_NAME]
13139 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
13140 -- SUBTYPE_NAME ::= STRING_LITERAL
13142 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
13143 -- SOURCE_TRACE ::= STRING_LITERAL
13145 when Pragma_Eliminate => Eliminate : declare
13146 Args : Args_List (1 .. 5);
13147 Names : constant Name_List (1 .. 5) := (
13148 Name_Unit_Name,
13149 Name_Entity,
13150 Name_Parameter_Types,
13151 Name_Result_Type,
13152 Name_Source_Location);
13154 Unit_Name : Node_Id renames Args (1);
13155 Entity : Node_Id renames Args (2);
13156 Parameter_Types : Node_Id renames Args (3);
13157 Result_Type : Node_Id renames Args (4);
13158 Source_Location : Node_Id renames Args (5);
13160 begin
13161 GNAT_Pragma;
13162 Check_Valid_Configuration_Pragma;
13163 Gather_Associations (Names, Args);
13165 if No (Unit_Name) then
13166 Error_Pragma ("missing Unit_Name argument for pragma%");
13167 end if;
13169 if No (Entity)
13170 and then (Present (Parameter_Types)
13171 or else
13172 Present (Result_Type)
13173 or else
13174 Present (Source_Location))
13175 then
13176 Error_Pragma ("missing Entity argument for pragma%");
13177 end if;
13179 if (Present (Parameter_Types)
13180 or else
13181 Present (Result_Type))
13182 and then
13183 Present (Source_Location)
13184 then
13185 Error_Pragma
13186 ("parameter profile and source location cannot be used "
13187 & "together in pragma%");
13188 end if;
13190 Process_Eliminate_Pragma
13192 Unit_Name,
13193 Entity,
13194 Parameter_Types,
13195 Result_Type,
13196 Source_Location);
13197 end Eliminate;
13199 -----------------------------------
13200 -- Enable_Atomic_Synchronization --
13201 -----------------------------------
13203 -- pragma Enable_Atomic_Synchronization [(Entity)];
13205 when Pragma_Enable_Atomic_Synchronization =>
13206 GNAT_Pragma;
13207 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
13209 ------------
13210 -- Export --
13211 ------------
13213 -- pragma Export (
13214 -- [ Convention =>] convention_IDENTIFIER,
13215 -- [ Entity =>] LOCAL_NAME
13216 -- [, [External_Name =>] static_string_EXPRESSION ]
13217 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13219 when Pragma_Export => Export : declare
13220 C : Convention_Id;
13221 Def_Id : Entity_Id;
13223 pragma Warnings (Off, C);
13225 begin
13226 Check_Ada_83_Warning;
13227 Check_Arg_Order
13228 ((Name_Convention,
13229 Name_Entity,
13230 Name_External_Name,
13231 Name_Link_Name));
13233 Check_At_Least_N_Arguments (2);
13234 Check_At_Most_N_Arguments (4);
13236 -- In Relaxed_RM_Semantics, support old Ada 83 style:
13237 -- pragma Export (Entity, "external name");
13239 if Relaxed_RM_Semantics
13240 and then Arg_Count = 2
13241 and then Nkind (Expression (Arg2)) = N_String_Literal
13242 then
13243 C := Convention_C;
13244 Def_Id := Get_Pragma_Arg (Arg1);
13245 Analyze (Def_Id);
13247 if not Is_Entity_Name (Def_Id) then
13248 Error_Pragma_Arg ("entity name required", Arg1);
13249 end if;
13251 Def_Id := Entity (Def_Id);
13252 Set_Exported (Def_Id, Arg1);
13254 else
13255 Process_Convention (C, Def_Id);
13257 if Ekind (Def_Id) /= E_Constant then
13258 Note_Possible_Modification
13259 (Get_Pragma_Arg (Arg2), Sure => False);
13260 end if;
13262 Process_Interface_Name (Def_Id, Arg3, Arg4);
13263 Set_Exported (Def_Id, Arg2);
13264 end if;
13266 -- If the entity is a deferred constant, propagate the information
13267 -- to the full view, because gigi elaborates the full view only.
13269 if Ekind (Def_Id) = E_Constant
13270 and then Present (Full_View (Def_Id))
13271 then
13272 declare
13273 Id2 : constant Entity_Id := Full_View (Def_Id);
13274 begin
13275 Set_Is_Exported (Id2, Is_Exported (Def_Id));
13276 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
13277 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
13278 end;
13279 end if;
13280 end Export;
13282 ---------------------
13283 -- Export_Function --
13284 ---------------------
13286 -- pragma Export_Function (
13287 -- [Internal =>] LOCAL_NAME
13288 -- [, [External =>] EXTERNAL_SYMBOL]
13289 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13290 -- [, [Result_Type =>] TYPE_DESIGNATOR]
13291 -- [, [Mechanism =>] MECHANISM]
13292 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
13294 -- EXTERNAL_SYMBOL ::=
13295 -- IDENTIFIER
13296 -- | static_string_EXPRESSION
13298 -- PARAMETER_TYPES ::=
13299 -- null
13300 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13302 -- TYPE_DESIGNATOR ::=
13303 -- subtype_NAME
13304 -- | subtype_Name ' Access
13306 -- MECHANISM ::=
13307 -- MECHANISM_NAME
13308 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13310 -- MECHANISM_ASSOCIATION ::=
13311 -- [formal_parameter_NAME =>] MECHANISM_NAME
13313 -- MECHANISM_NAME ::=
13314 -- Value
13315 -- | Reference
13317 when Pragma_Export_Function => Export_Function : declare
13318 Args : Args_List (1 .. 6);
13319 Names : constant Name_List (1 .. 6) := (
13320 Name_Internal,
13321 Name_External,
13322 Name_Parameter_Types,
13323 Name_Result_Type,
13324 Name_Mechanism,
13325 Name_Result_Mechanism);
13327 Internal : Node_Id renames Args (1);
13328 External : Node_Id renames Args (2);
13329 Parameter_Types : Node_Id renames Args (3);
13330 Result_Type : Node_Id renames Args (4);
13331 Mechanism : Node_Id renames Args (5);
13332 Result_Mechanism : Node_Id renames Args (6);
13334 begin
13335 GNAT_Pragma;
13336 Gather_Associations (Names, Args);
13337 Process_Extended_Import_Export_Subprogram_Pragma (
13338 Arg_Internal => Internal,
13339 Arg_External => External,
13340 Arg_Parameter_Types => Parameter_Types,
13341 Arg_Result_Type => Result_Type,
13342 Arg_Mechanism => Mechanism,
13343 Arg_Result_Mechanism => Result_Mechanism);
13344 end Export_Function;
13346 -------------------
13347 -- Export_Object --
13348 -------------------
13350 -- pragma Export_Object (
13351 -- [Internal =>] LOCAL_NAME
13352 -- [, [External =>] EXTERNAL_SYMBOL]
13353 -- [, [Size =>] EXTERNAL_SYMBOL]);
13355 -- EXTERNAL_SYMBOL ::=
13356 -- IDENTIFIER
13357 -- | static_string_EXPRESSION
13359 -- PARAMETER_TYPES ::=
13360 -- null
13361 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13363 -- TYPE_DESIGNATOR ::=
13364 -- subtype_NAME
13365 -- | subtype_Name ' Access
13367 -- MECHANISM ::=
13368 -- MECHANISM_NAME
13369 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13371 -- MECHANISM_ASSOCIATION ::=
13372 -- [formal_parameter_NAME =>] MECHANISM_NAME
13374 -- MECHANISM_NAME ::=
13375 -- Value
13376 -- | Reference
13378 when Pragma_Export_Object => Export_Object : declare
13379 Args : Args_List (1 .. 3);
13380 Names : constant Name_List (1 .. 3) := (
13381 Name_Internal,
13382 Name_External,
13383 Name_Size);
13385 Internal : Node_Id renames Args (1);
13386 External : Node_Id renames Args (2);
13387 Size : Node_Id renames Args (3);
13389 begin
13390 GNAT_Pragma;
13391 Gather_Associations (Names, Args);
13392 Process_Extended_Import_Export_Object_Pragma (
13393 Arg_Internal => Internal,
13394 Arg_External => External,
13395 Arg_Size => Size);
13396 end Export_Object;
13398 ----------------------
13399 -- Export_Procedure --
13400 ----------------------
13402 -- pragma Export_Procedure (
13403 -- [Internal =>] LOCAL_NAME
13404 -- [, [External =>] EXTERNAL_SYMBOL]
13405 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13406 -- [, [Mechanism =>] MECHANISM]);
13408 -- EXTERNAL_SYMBOL ::=
13409 -- IDENTIFIER
13410 -- | static_string_EXPRESSION
13412 -- PARAMETER_TYPES ::=
13413 -- null
13414 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13416 -- TYPE_DESIGNATOR ::=
13417 -- subtype_NAME
13418 -- | subtype_Name ' Access
13420 -- MECHANISM ::=
13421 -- MECHANISM_NAME
13422 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13424 -- MECHANISM_ASSOCIATION ::=
13425 -- [formal_parameter_NAME =>] MECHANISM_NAME
13427 -- MECHANISM_NAME ::=
13428 -- Value
13429 -- | Reference
13431 when Pragma_Export_Procedure => Export_Procedure : declare
13432 Args : Args_List (1 .. 4);
13433 Names : constant Name_List (1 .. 4) := (
13434 Name_Internal,
13435 Name_External,
13436 Name_Parameter_Types,
13437 Name_Mechanism);
13439 Internal : Node_Id renames Args (1);
13440 External : Node_Id renames Args (2);
13441 Parameter_Types : Node_Id renames Args (3);
13442 Mechanism : Node_Id renames Args (4);
13444 begin
13445 GNAT_Pragma;
13446 Gather_Associations (Names, Args);
13447 Process_Extended_Import_Export_Subprogram_Pragma (
13448 Arg_Internal => Internal,
13449 Arg_External => External,
13450 Arg_Parameter_Types => Parameter_Types,
13451 Arg_Mechanism => Mechanism);
13452 end Export_Procedure;
13454 ------------------
13455 -- Export_Value --
13456 ------------------
13458 -- pragma Export_Value (
13459 -- [Value =>] static_integer_EXPRESSION,
13460 -- [Link_Name =>] static_string_EXPRESSION);
13462 when Pragma_Export_Value =>
13463 GNAT_Pragma;
13464 Check_Arg_Order ((Name_Value, Name_Link_Name));
13465 Check_Arg_Count (2);
13467 Check_Optional_Identifier (Arg1, Name_Value);
13468 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
13470 Check_Optional_Identifier (Arg2, Name_Link_Name);
13471 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
13473 -----------------------------
13474 -- Export_Valued_Procedure --
13475 -----------------------------
13477 -- pragma Export_Valued_Procedure (
13478 -- [Internal =>] LOCAL_NAME
13479 -- [, [External =>] EXTERNAL_SYMBOL,]
13480 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13481 -- [, [Mechanism =>] MECHANISM]);
13483 -- EXTERNAL_SYMBOL ::=
13484 -- IDENTIFIER
13485 -- | static_string_EXPRESSION
13487 -- PARAMETER_TYPES ::=
13488 -- null
13489 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13491 -- TYPE_DESIGNATOR ::=
13492 -- subtype_NAME
13493 -- | subtype_Name ' Access
13495 -- MECHANISM ::=
13496 -- MECHANISM_NAME
13497 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13499 -- MECHANISM_ASSOCIATION ::=
13500 -- [formal_parameter_NAME =>] MECHANISM_NAME
13502 -- MECHANISM_NAME ::=
13503 -- Value
13504 -- | Reference
13506 when Pragma_Export_Valued_Procedure =>
13507 Export_Valued_Procedure : declare
13508 Args : Args_List (1 .. 4);
13509 Names : constant Name_List (1 .. 4) := (
13510 Name_Internal,
13511 Name_External,
13512 Name_Parameter_Types,
13513 Name_Mechanism);
13515 Internal : Node_Id renames Args (1);
13516 External : Node_Id renames Args (2);
13517 Parameter_Types : Node_Id renames Args (3);
13518 Mechanism : Node_Id renames Args (4);
13520 begin
13521 GNAT_Pragma;
13522 Gather_Associations (Names, Args);
13523 Process_Extended_Import_Export_Subprogram_Pragma (
13524 Arg_Internal => Internal,
13525 Arg_External => External,
13526 Arg_Parameter_Types => Parameter_Types,
13527 Arg_Mechanism => Mechanism);
13528 end Export_Valued_Procedure;
13530 -------------------
13531 -- Extend_System --
13532 -------------------
13534 -- pragma Extend_System ([Name =>] Identifier);
13536 when Pragma_Extend_System => Extend_System : declare
13537 begin
13538 GNAT_Pragma;
13539 Check_Valid_Configuration_Pragma;
13540 Check_Arg_Count (1);
13541 Check_Optional_Identifier (Arg1, Name_Name);
13542 Check_Arg_Is_Identifier (Arg1);
13544 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13546 if Name_Len > 4
13547 and then Name_Buffer (1 .. 4) = "aux_"
13548 then
13549 if Present (System_Extend_Pragma_Arg) then
13550 if Chars (Get_Pragma_Arg (Arg1)) =
13551 Chars (Expression (System_Extend_Pragma_Arg))
13552 then
13553 null;
13554 else
13555 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
13556 Error_Pragma ("pragma% conflicts with that #");
13557 end if;
13559 else
13560 System_Extend_Pragma_Arg := Arg1;
13562 if not GNAT_Mode then
13563 System_Extend_Unit := Arg1;
13564 end if;
13565 end if;
13566 else
13567 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
13568 end if;
13569 end Extend_System;
13571 ------------------------
13572 -- Extensions_Allowed --
13573 ------------------------
13575 -- pragma Extensions_Allowed (ON | OFF);
13577 when Pragma_Extensions_Allowed =>
13578 GNAT_Pragma;
13579 Check_Arg_Count (1);
13580 Check_No_Identifiers;
13581 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13583 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
13584 Extensions_Allowed := True;
13585 Ada_Version := Ada_Version_Type'Last;
13587 else
13588 Extensions_Allowed := False;
13589 Ada_Version := Ada_Version_Explicit;
13590 Ada_Version_Pragma := Empty;
13591 end if;
13593 ------------------------
13594 -- Extensions_Visible --
13595 ------------------------
13597 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
13599 when Pragma_Extensions_Visible => Extensions_Visible : declare
13600 Expr : Node_Id;
13601 Formal : Entity_Id;
13602 Has_OK_Formal : Boolean := False;
13603 Spec_Id : Entity_Id;
13604 Subp_Decl : Node_Id;
13605 Subp_Id : Entity_Id;
13607 begin
13608 GNAT_Pragma;
13609 Check_No_Identifiers;
13610 Check_At_Most_N_Arguments (1);
13612 Subp_Decl :=
13613 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
13615 -- Generic subprogram declaration
13617 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
13618 null;
13620 -- Body acts as spec
13622 elsif Nkind (Subp_Decl) = N_Subprogram_Body
13623 and then No (Corresponding_Spec (Subp_Decl))
13624 then
13625 null;
13627 -- Body stub acts as spec
13629 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
13630 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
13631 then
13632 null;
13634 -- Subprogram declaration
13636 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
13637 null;
13639 -- Otherwise the pragma is associated with an illegal construct
13641 else
13642 Error_Pragma ("pragma % must apply to a subprogram");
13643 return;
13644 end if;
13646 Spec_Id := Corresponding_Spec_Of (Subp_Decl);
13647 Subp_Id := Defining_Entity (Subp_Decl);
13649 -- Examine the formals of the related subprogram
13651 Formal := First_Formal (Spec_Id);
13652 while Present (Formal) loop
13654 -- At least one of the formals is of a specific tagged type,
13655 -- the pragma is legal.
13657 if Is_Specific_Tagged_Type (Etype (Formal)) then
13658 Has_OK_Formal := True;
13659 exit;
13661 -- A generic subprogram with at least one formal of a private
13662 -- type ensures the legality of the pragma because the actual
13663 -- may be specifically tagged. Note that this is verified by
13664 -- the check above at instantiation time.
13666 elsif Is_Private_Type (Etype (Formal))
13667 and then Is_Generic_Type (Etype (Formal))
13668 then
13669 Has_OK_Formal := True;
13670 exit;
13671 end if;
13673 Next_Formal (Formal);
13674 end loop;
13676 if not Has_OK_Formal then
13677 Error_Msg_Name_1 := Pname;
13678 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
13679 Error_Msg_NE
13680 ("\subprogram & lacks parameter of specific tagged or "
13681 & "generic private type", N, Spec_Id);
13682 return;
13683 end if;
13685 -- Construct a generic template for the pragma when the context is
13686 -- a generic subprogram and the pragma is a source construct.
13688 Create_Generic_Template (N, Subp_Id);
13690 -- Analyze the Boolean expression (if any)
13692 if Present (Arg1) then
13693 Expr := Expression (Get_Argument (N));
13695 Analyze_And_Resolve (Expr, Standard_Boolean);
13697 if not Is_OK_Static_Expression (Expr) then
13698 Error_Pragma_Arg
13699 ("expression of pragma % must be static", Expr);
13700 return;
13701 end if;
13702 end if;
13704 -- Chain the pragma on the contract for further processing
13706 Add_Contract_Item (N, Subp_Id);
13707 end Extensions_Visible;
13709 --------------
13710 -- External --
13711 --------------
13713 -- pragma External (
13714 -- [ Convention =>] convention_IDENTIFIER,
13715 -- [ Entity =>] LOCAL_NAME
13716 -- [, [External_Name =>] static_string_EXPRESSION ]
13717 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13719 when Pragma_External => External : declare
13720 Def_Id : Entity_Id;
13722 C : Convention_Id;
13723 pragma Warnings (Off, C);
13725 begin
13726 GNAT_Pragma;
13727 Check_Arg_Order
13728 ((Name_Convention,
13729 Name_Entity,
13730 Name_External_Name,
13731 Name_Link_Name));
13732 Check_At_Least_N_Arguments (2);
13733 Check_At_Most_N_Arguments (4);
13734 Process_Convention (C, Def_Id);
13735 Note_Possible_Modification
13736 (Get_Pragma_Arg (Arg2), Sure => False);
13737 Process_Interface_Name (Def_Id, Arg3, Arg4);
13738 Set_Exported (Def_Id, Arg2);
13739 end External;
13741 --------------------------
13742 -- External_Name_Casing --
13743 --------------------------
13745 -- pragma External_Name_Casing (
13746 -- UPPERCASE | LOWERCASE
13747 -- [, AS_IS | UPPERCASE | LOWERCASE]);
13749 when Pragma_External_Name_Casing => External_Name_Casing : declare
13750 begin
13751 GNAT_Pragma;
13752 Check_No_Identifiers;
13754 if Arg_Count = 2 then
13755 Check_Arg_Is_One_Of
13756 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
13758 case Chars (Get_Pragma_Arg (Arg2)) is
13759 when Name_As_Is =>
13760 Opt.External_Name_Exp_Casing := As_Is;
13762 when Name_Uppercase =>
13763 Opt.External_Name_Exp_Casing := Uppercase;
13765 when Name_Lowercase =>
13766 Opt.External_Name_Exp_Casing := Lowercase;
13768 when others =>
13769 null;
13770 end case;
13772 else
13773 Check_Arg_Count (1);
13774 end if;
13776 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
13778 case Chars (Get_Pragma_Arg (Arg1)) is
13779 when Name_Uppercase =>
13780 Opt.External_Name_Imp_Casing := Uppercase;
13782 when Name_Lowercase =>
13783 Opt.External_Name_Imp_Casing := Lowercase;
13785 when others =>
13786 null;
13787 end case;
13788 end External_Name_Casing;
13790 ---------------
13791 -- Fast_Math --
13792 ---------------
13794 -- pragma Fast_Math;
13796 when Pragma_Fast_Math =>
13797 GNAT_Pragma;
13798 Check_No_Identifiers;
13799 Check_Valid_Configuration_Pragma;
13800 Fast_Math := True;
13802 --------------------------
13803 -- Favor_Top_Level --
13804 --------------------------
13806 -- pragma Favor_Top_Level (type_NAME);
13808 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
13809 Named_Entity : Entity_Id;
13811 begin
13812 GNAT_Pragma;
13813 Check_No_Identifiers;
13814 Check_Arg_Count (1);
13815 Check_Arg_Is_Local_Name (Arg1);
13816 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
13818 -- If it's an access-to-subprogram type (in particular, not a
13819 -- subtype), set the flag on that type.
13821 if Is_Access_Subprogram_Type (Named_Entity) then
13822 Set_Can_Use_Internal_Rep (Named_Entity, False);
13824 -- Otherwise it's an error (name denotes the wrong sort of entity)
13826 else
13827 Error_Pragma_Arg
13828 ("access-to-subprogram type expected",
13829 Get_Pragma_Arg (Arg1));
13830 end if;
13831 end Favor_Top_Level;
13833 ---------------------------
13834 -- Finalize_Storage_Only --
13835 ---------------------------
13837 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
13839 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
13840 Assoc : constant Node_Id := Arg1;
13841 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13842 Typ : Entity_Id;
13844 begin
13845 GNAT_Pragma;
13846 Check_No_Identifiers;
13847 Check_Arg_Count (1);
13848 Check_Arg_Is_Local_Name (Arg1);
13850 Find_Type (Type_Id);
13851 Typ := Entity (Type_Id);
13853 if Typ = Any_Type
13854 or else Rep_Item_Too_Early (Typ, N)
13855 then
13856 return;
13857 else
13858 Typ := Underlying_Type (Typ);
13859 end if;
13861 if not Is_Controlled (Typ) then
13862 Error_Pragma ("pragma% must specify controlled type");
13863 end if;
13865 Check_First_Subtype (Arg1);
13867 if Finalize_Storage_Only (Typ) then
13868 Error_Pragma ("duplicate pragma%, only one allowed");
13870 elsif not Rep_Item_Too_Late (Typ, N) then
13871 Set_Finalize_Storage_Only (Base_Type (Typ), True);
13872 end if;
13873 end Finalize_Storage;
13875 -----------
13876 -- Ghost --
13877 -----------
13879 -- pragma Ghost [ (boolean_EXPRESSION) ];
13881 when Pragma_Ghost => Ghost : declare
13882 Context : Node_Id;
13883 Expr : Node_Id;
13884 Id : Entity_Id;
13885 Orig_Stmt : Node_Id;
13886 Prev_Id : Entity_Id;
13887 Stmt : Node_Id;
13889 begin
13890 GNAT_Pragma;
13891 Check_No_Identifiers;
13892 Check_At_Most_N_Arguments (1);
13894 Context := Parent (N);
13896 -- Handle compilation units
13898 if Nkind (Context) = N_Compilation_Unit_Aux then
13899 Context := Unit (Parent (Context));
13900 end if;
13902 Id := Empty;
13903 Stmt := Prev (N);
13904 while Present (Stmt) loop
13906 -- Skip prior pragmas, but check for duplicates
13908 if Nkind (Stmt) = N_Pragma then
13909 if Pragma_Name (Stmt) = Pname then
13910 Error_Msg_Name_1 := Pname;
13911 Error_Msg_Sloc := Sloc (Stmt);
13912 Error_Msg_N ("pragma % duplicates pragma declared#", N);
13913 end if;
13915 -- Protected and task types cannot be subject to pragma Ghost
13917 elsif Nkind (Stmt) = N_Protected_Type_Declaration then
13918 Error_Pragma ("pragma % cannot apply to a protected type");
13919 return;
13921 elsif Nkind (Stmt) = N_Task_Type_Declaration then
13922 Error_Pragma ("pragma % cannot apply to a task type");
13923 return;
13925 -- Skip internally generated code
13927 elsif not Comes_From_Source (Stmt) then
13928 Orig_Stmt := Original_Node (Stmt);
13930 -- When pragma Ghost applies to an untagged derivation, the
13931 -- derivation is transformed into a [sub]type declaration.
13933 if Nkind_In (Stmt, N_Full_Type_Declaration,
13934 N_Subtype_Declaration)
13935 and then Comes_From_Source (Orig_Stmt)
13936 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
13937 and then Nkind (Type_Definition (Orig_Stmt)) =
13938 N_Derived_Type_Definition
13939 then
13940 Id := Defining_Entity (Stmt);
13941 exit;
13943 -- When pragma Ghost applies to an expression function, the
13944 -- expression function is transformed into a subprogram.
13946 elsif Nkind (Stmt) = N_Subprogram_Declaration
13947 and then Comes_From_Source (Orig_Stmt)
13948 and then Nkind (Orig_Stmt) = N_Expression_Function
13949 then
13950 Id := Defining_Entity (Stmt);
13951 exit;
13952 end if;
13954 -- The pragma applies to a legal construct, stop the traversal
13956 elsif Nkind_In (Stmt, N_Abstract_Subprogram_Declaration,
13957 N_Full_Type_Declaration,
13958 N_Generic_Subprogram_Declaration,
13959 N_Object_Declaration,
13960 N_Private_Extension_Declaration,
13961 N_Private_Type_Declaration,
13962 N_Subprogram_Declaration,
13963 N_Subtype_Declaration)
13964 then
13965 Id := Defining_Entity (Stmt);
13966 exit;
13968 -- The pragma does not apply to a legal construct, issue an
13969 -- error and stop the analysis.
13971 else
13972 Error_Pragma
13973 ("pragma % must apply to an object, package, subprogram "
13974 & "or type");
13975 return;
13976 end if;
13978 Stmt := Prev (Stmt);
13979 end loop;
13981 if No (Id) then
13983 -- When pragma Ghost is associated with a [generic] package, it
13984 -- appears in the visible declarations.
13986 if Nkind (Context) = N_Package_Specification
13987 and then Present (Visible_Declarations (Context))
13988 and then List_Containing (N) = Visible_Declarations (Context)
13989 then
13990 Id := Defining_Entity (Context);
13992 -- Pragma Ghost applies to a stand alone subprogram body
13994 elsif Nkind (Context) = N_Subprogram_Body
13995 and then No (Corresponding_Spec (Context))
13996 then
13997 Id := Defining_Entity (Context);
13998 end if;
13999 end if;
14001 if No (Id) then
14002 Error_Pragma
14003 ("pragma % must apply to an object, package, subprogram or "
14004 & "type");
14005 return;
14006 end if;
14008 -- A derived type or type extension cannot be subject to pragma
14009 -- Ghost if either the parent type or one of the progenitor types
14010 -- is not Ghost (SPARK RM 6.9(9)).
14012 if Is_Derived_Type (Id) then
14013 Check_Ghost_Derivation (Id);
14014 end if;
14016 -- Handle completions of types and constants that are subject to
14017 -- pragma Ghost.
14019 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
14020 Prev_Id := Incomplete_Or_Partial_View (Id);
14022 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
14023 Error_Msg_Name_1 := Pname;
14025 -- The full declaration of a deferred constant cannot be
14026 -- subject to pragma Ghost unless the deferred declaration
14027 -- is also Ghost (SPARK RM 6.9(10)).
14029 if Ekind (Prev_Id) = E_Constant then
14030 Error_Msg_Name_1 := Pname;
14031 Error_Msg_NE (Fix_Error
14032 ("pragma % must apply to declaration of deferred "
14033 & "constant &"), N, Id);
14034 return;
14036 -- Pragma Ghost may appear on the full view of an incomplete
14037 -- type because the incomplete declaration lacks aspects and
14038 -- cannot be subject to pragma Ghost.
14040 elsif Ekind (Prev_Id) = E_Incomplete_Type then
14041 null;
14043 -- The full declaration of a type cannot be subject to
14044 -- pragma Ghost unless the partial view is also Ghost
14045 -- (SPARK RM 6.9(10)).
14047 else
14048 Error_Msg_NE (Fix_Error
14049 ("pragma % must apply to partial view of type &"),
14050 N, Id);
14051 return;
14052 end if;
14053 end if;
14054 end if;
14056 -- Analyze the Boolean expression (if any)
14058 if Present (Arg1) then
14059 Expr := Get_Pragma_Arg (Arg1);
14061 Analyze_And_Resolve (Expr, Standard_Boolean);
14063 if Is_OK_Static_Expression (Expr) then
14065 -- "Ghostness" cannot be turned off once enabled within a
14066 -- region (SPARK RM 6.9(7)).
14068 if Is_False (Expr_Value (Expr))
14069 and then Ghost_Mode > None
14070 then
14071 Error_Pragma
14072 ("pragma % with value False cannot appear in enabled "
14073 & "ghost region");
14074 return;
14075 end if;
14077 -- Otherwie the expression is not static
14079 else
14080 Error_Pragma_Arg
14081 ("expression of pragma % must be static", Expr);
14082 return;
14083 end if;
14084 end if;
14086 Set_Is_Ghost_Entity (Id);
14087 end Ghost;
14089 ------------
14090 -- Global --
14091 ------------
14093 -- pragma Global (GLOBAL_SPECIFICATION);
14095 -- GLOBAL_SPECIFICATION ::=
14096 -- null
14097 -- | GLOBAL_LIST
14098 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
14100 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
14102 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
14103 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
14104 -- GLOBAL_ITEM ::= NAME
14106 when Pragma_Global => Global : declare
14107 Subp_Decl : Node_Id;
14108 Subp_Id : Entity_Id;
14110 begin
14111 GNAT_Pragma;
14112 Check_Arg_Count (1);
14114 -- Ensure the proper placement of the pragma. Global must be
14115 -- associated with a subprogram declaration or a body that acts
14116 -- as a spec.
14118 Subp_Decl :=
14119 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
14121 -- Body acts as spec
14123 if Nkind (Subp_Decl) = N_Subprogram_Body
14124 and then No (Corresponding_Spec (Subp_Decl))
14125 then
14126 null;
14128 -- Body stub acts as spec
14130 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
14131 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
14132 then
14133 null;
14135 -- Subprogram declaration
14137 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
14138 null;
14140 else
14141 Pragma_Misplaced;
14142 return;
14143 end if;
14145 Subp_Id := Defining_Entity (Subp_Decl);
14147 Ensure_Aggregate_Form (Get_Argument (N, Subp_Id));
14149 -- Construct a generic template for the pragma when the context is
14150 -- a generic subprogram and the pragma is a source construct.
14152 Create_Generic_Template (N, Subp_Id);
14154 -- When the pragma appears on a subprogram body, perform the full
14155 -- analysis now.
14157 if Nkind (Subp_Decl) = N_Subprogram_Body then
14158 Analyze_Global_In_Decl_Part (N);
14159 end if;
14161 -- Chain the pragma on the contract for further processing
14163 Add_Contract_Item (N, Subp_Id);
14164 end Global;
14166 -----------
14167 -- Ident --
14168 -----------
14170 -- pragma Ident (static_string_EXPRESSION)
14172 -- Note: pragma Comment shares this processing. Pragma Ident is
14173 -- identical in effect to pragma Commment.
14175 when Pragma_Ident | Pragma_Comment => Ident : declare
14176 Str : Node_Id;
14178 begin
14179 GNAT_Pragma;
14180 Check_Arg_Count (1);
14181 Check_No_Identifiers;
14182 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
14183 Store_Note (N);
14185 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
14187 declare
14188 CS : Node_Id;
14189 GP : Node_Id;
14191 begin
14192 GP := Parent (Parent (N));
14194 if Nkind_In (GP, N_Package_Declaration,
14195 N_Generic_Package_Declaration)
14196 then
14197 GP := Parent (GP);
14198 end if;
14200 -- If we have a compilation unit, then record the ident value,
14201 -- checking for improper duplication.
14203 if Nkind (GP) = N_Compilation_Unit then
14204 CS := Ident_String (Current_Sem_Unit);
14206 if Present (CS) then
14208 -- If we have multiple instances, concatenate them, but
14209 -- not in ASIS, where we want the original tree.
14211 if not ASIS_Mode then
14212 Start_String (Strval (CS));
14213 Store_String_Char (' ');
14214 Store_String_Chars (Strval (Str));
14215 Set_Strval (CS, End_String);
14216 end if;
14218 else
14219 Set_Ident_String (Current_Sem_Unit, Str);
14220 end if;
14222 -- For subunits, we just ignore the Ident, since in GNAT these
14223 -- are not separate object files, and hence not separate units
14224 -- in the unit table.
14226 elsif Nkind (GP) = N_Subunit then
14227 null;
14228 end if;
14229 end;
14230 end Ident;
14232 ----------------------------
14233 -- Implementation_Defined --
14234 ----------------------------
14236 -- pragma Implementation_Defined (LOCAL_NAME);
14238 -- Marks previously declared entity as implementation defined. For
14239 -- an overloaded entity, applies to the most recent homonym.
14241 -- pragma Implementation_Defined;
14243 -- The form with no arguments appears anywhere within a scope, most
14244 -- typically a package spec, and indicates that all entities that are
14245 -- defined within the package spec are Implementation_Defined.
14247 when Pragma_Implementation_Defined => Implementation_Defined : declare
14248 Ent : Entity_Id;
14250 begin
14251 GNAT_Pragma;
14252 Check_No_Identifiers;
14254 -- Form with no arguments
14256 if Arg_Count = 0 then
14257 Set_Is_Implementation_Defined (Current_Scope);
14259 -- Form with one argument
14261 else
14262 Check_Arg_Count (1);
14263 Check_Arg_Is_Local_Name (Arg1);
14264 Ent := Entity (Get_Pragma_Arg (Arg1));
14265 Set_Is_Implementation_Defined (Ent);
14266 end if;
14267 end Implementation_Defined;
14269 -----------------
14270 -- Implemented --
14271 -----------------
14273 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
14275 -- IMPLEMENTATION_KIND ::=
14276 -- By_Entry | By_Protected_Procedure | By_Any | Optional
14278 -- "By_Any" and "Optional" are treated as synonyms in order to
14279 -- support Ada 2012 aspect Synchronization.
14281 when Pragma_Implemented => Implemented : declare
14282 Proc_Id : Entity_Id;
14283 Typ : Entity_Id;
14285 begin
14286 Ada_2012_Pragma;
14287 Check_Arg_Count (2);
14288 Check_No_Identifiers;
14289 Check_Arg_Is_Identifier (Arg1);
14290 Check_Arg_Is_Local_Name (Arg1);
14291 Check_Arg_Is_One_Of (Arg2,
14292 Name_By_Any,
14293 Name_By_Entry,
14294 Name_By_Protected_Procedure,
14295 Name_Optional);
14297 -- Extract the name of the local procedure
14299 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
14301 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
14302 -- primitive procedure of a synchronized tagged type.
14304 if Ekind (Proc_Id) = E_Procedure
14305 and then Is_Primitive (Proc_Id)
14306 and then Present (First_Formal (Proc_Id))
14307 then
14308 Typ := Etype (First_Formal (Proc_Id));
14310 if Is_Tagged_Type (Typ)
14311 and then
14313 -- Check for a protected, a synchronized or a task interface
14315 ((Is_Interface (Typ)
14316 and then Is_Synchronized_Interface (Typ))
14318 -- Check for a protected type or a task type that implements
14319 -- an interface.
14321 or else
14322 (Is_Concurrent_Record_Type (Typ)
14323 and then Present (Interfaces (Typ)))
14325 -- In analysis-only mode, examine original protected type
14327 or else
14328 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
14329 and then Present (Interface_List (Parent (Typ))))
14331 -- Check for a private record extension with keyword
14332 -- "synchronized".
14334 or else
14335 (Ekind_In (Typ, E_Record_Type_With_Private,
14336 E_Record_Subtype_With_Private)
14337 and then Synchronized_Present (Parent (Typ))))
14338 then
14339 null;
14340 else
14341 Error_Pragma_Arg
14342 ("controlling formal must be of synchronized tagged type",
14343 Arg1);
14344 return;
14345 end if;
14347 -- Procedures declared inside a protected type must be accepted
14349 elsif Ekind (Proc_Id) = E_Procedure
14350 and then Is_Protected_Type (Scope (Proc_Id))
14351 then
14352 null;
14354 -- The first argument is not a primitive procedure
14356 else
14357 Error_Pragma_Arg
14358 ("pragma % must be applied to a primitive procedure", Arg1);
14359 return;
14360 end if;
14362 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
14363 -- By_Protected_Procedure to the primitive procedure of a task
14364 -- interface.
14366 if Chars (Arg2) = Name_By_Protected_Procedure
14367 and then Is_Interface (Typ)
14368 and then Is_Task_Interface (Typ)
14369 then
14370 Error_Pragma_Arg
14371 ("implementation kind By_Protected_Procedure cannot be "
14372 & "applied to a task interface primitive", Arg2);
14373 return;
14374 end if;
14376 Record_Rep_Item (Proc_Id, N);
14377 end Implemented;
14379 ----------------------
14380 -- Implicit_Packing --
14381 ----------------------
14383 -- pragma Implicit_Packing;
14385 when Pragma_Implicit_Packing =>
14386 GNAT_Pragma;
14387 Check_Arg_Count (0);
14388 Implicit_Packing := True;
14390 ------------
14391 -- Import --
14392 ------------
14394 -- pragma Import (
14395 -- [Convention =>] convention_IDENTIFIER,
14396 -- [Entity =>] LOCAL_NAME
14397 -- [, [External_Name =>] static_string_EXPRESSION ]
14398 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14400 when Pragma_Import =>
14401 Check_Ada_83_Warning;
14402 Check_Arg_Order
14403 ((Name_Convention,
14404 Name_Entity,
14405 Name_External_Name,
14406 Name_Link_Name));
14408 Check_At_Least_N_Arguments (2);
14409 Check_At_Most_N_Arguments (4);
14410 Process_Import_Or_Interface;
14412 ---------------------
14413 -- Import_Function --
14414 ---------------------
14416 -- pragma Import_Function (
14417 -- [Internal =>] LOCAL_NAME,
14418 -- [, [External =>] EXTERNAL_SYMBOL]
14419 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14420 -- [, [Result_Type =>] SUBTYPE_MARK]
14421 -- [, [Mechanism =>] MECHANISM]
14422 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
14424 -- EXTERNAL_SYMBOL ::=
14425 -- IDENTIFIER
14426 -- | static_string_EXPRESSION
14428 -- PARAMETER_TYPES ::=
14429 -- null
14430 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14432 -- TYPE_DESIGNATOR ::=
14433 -- subtype_NAME
14434 -- | subtype_Name ' Access
14436 -- MECHANISM ::=
14437 -- MECHANISM_NAME
14438 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14440 -- MECHANISM_ASSOCIATION ::=
14441 -- [formal_parameter_NAME =>] MECHANISM_NAME
14443 -- MECHANISM_NAME ::=
14444 -- Value
14445 -- | Reference
14447 when Pragma_Import_Function => Import_Function : declare
14448 Args : Args_List (1 .. 6);
14449 Names : constant Name_List (1 .. 6) := (
14450 Name_Internal,
14451 Name_External,
14452 Name_Parameter_Types,
14453 Name_Result_Type,
14454 Name_Mechanism,
14455 Name_Result_Mechanism);
14457 Internal : Node_Id renames Args (1);
14458 External : Node_Id renames Args (2);
14459 Parameter_Types : Node_Id renames Args (3);
14460 Result_Type : Node_Id renames Args (4);
14461 Mechanism : Node_Id renames Args (5);
14462 Result_Mechanism : Node_Id renames Args (6);
14464 begin
14465 GNAT_Pragma;
14466 Gather_Associations (Names, Args);
14467 Process_Extended_Import_Export_Subprogram_Pragma (
14468 Arg_Internal => Internal,
14469 Arg_External => External,
14470 Arg_Parameter_Types => Parameter_Types,
14471 Arg_Result_Type => Result_Type,
14472 Arg_Mechanism => Mechanism,
14473 Arg_Result_Mechanism => Result_Mechanism);
14474 end Import_Function;
14476 -------------------
14477 -- Import_Object --
14478 -------------------
14480 -- pragma Import_Object (
14481 -- [Internal =>] LOCAL_NAME
14482 -- [, [External =>] EXTERNAL_SYMBOL]
14483 -- [, [Size =>] EXTERNAL_SYMBOL]);
14485 -- EXTERNAL_SYMBOL ::=
14486 -- IDENTIFIER
14487 -- | static_string_EXPRESSION
14489 when Pragma_Import_Object => Import_Object : declare
14490 Args : Args_List (1 .. 3);
14491 Names : constant Name_List (1 .. 3) := (
14492 Name_Internal,
14493 Name_External,
14494 Name_Size);
14496 Internal : Node_Id renames Args (1);
14497 External : Node_Id renames Args (2);
14498 Size : Node_Id renames Args (3);
14500 begin
14501 GNAT_Pragma;
14502 Gather_Associations (Names, Args);
14503 Process_Extended_Import_Export_Object_Pragma (
14504 Arg_Internal => Internal,
14505 Arg_External => External,
14506 Arg_Size => Size);
14507 end Import_Object;
14509 ----------------------
14510 -- Import_Procedure --
14511 ----------------------
14513 -- pragma Import_Procedure (
14514 -- [Internal =>] LOCAL_NAME
14515 -- [, [External =>] EXTERNAL_SYMBOL]
14516 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14517 -- [, [Mechanism =>] MECHANISM]);
14519 -- EXTERNAL_SYMBOL ::=
14520 -- IDENTIFIER
14521 -- | static_string_EXPRESSION
14523 -- PARAMETER_TYPES ::=
14524 -- null
14525 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14527 -- TYPE_DESIGNATOR ::=
14528 -- subtype_NAME
14529 -- | subtype_Name ' Access
14531 -- MECHANISM ::=
14532 -- MECHANISM_NAME
14533 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14535 -- MECHANISM_ASSOCIATION ::=
14536 -- [formal_parameter_NAME =>] MECHANISM_NAME
14538 -- MECHANISM_NAME ::=
14539 -- Value
14540 -- | Reference
14542 when Pragma_Import_Procedure => Import_Procedure : declare
14543 Args : Args_List (1 .. 4);
14544 Names : constant Name_List (1 .. 4) := (
14545 Name_Internal,
14546 Name_External,
14547 Name_Parameter_Types,
14548 Name_Mechanism);
14550 Internal : Node_Id renames Args (1);
14551 External : Node_Id renames Args (2);
14552 Parameter_Types : Node_Id renames Args (3);
14553 Mechanism : Node_Id renames Args (4);
14555 begin
14556 GNAT_Pragma;
14557 Gather_Associations (Names, Args);
14558 Process_Extended_Import_Export_Subprogram_Pragma (
14559 Arg_Internal => Internal,
14560 Arg_External => External,
14561 Arg_Parameter_Types => Parameter_Types,
14562 Arg_Mechanism => Mechanism);
14563 end Import_Procedure;
14565 -----------------------------
14566 -- Import_Valued_Procedure --
14567 -----------------------------
14569 -- pragma Import_Valued_Procedure (
14570 -- [Internal =>] LOCAL_NAME
14571 -- [, [External =>] EXTERNAL_SYMBOL]
14572 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14573 -- [, [Mechanism =>] MECHANISM]);
14575 -- EXTERNAL_SYMBOL ::=
14576 -- IDENTIFIER
14577 -- | static_string_EXPRESSION
14579 -- PARAMETER_TYPES ::=
14580 -- null
14581 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14583 -- TYPE_DESIGNATOR ::=
14584 -- subtype_NAME
14585 -- | subtype_Name ' Access
14587 -- MECHANISM ::=
14588 -- MECHANISM_NAME
14589 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14591 -- MECHANISM_ASSOCIATION ::=
14592 -- [formal_parameter_NAME =>] MECHANISM_NAME
14594 -- MECHANISM_NAME ::=
14595 -- Value
14596 -- | Reference
14598 when Pragma_Import_Valued_Procedure =>
14599 Import_Valued_Procedure : declare
14600 Args : Args_List (1 .. 4);
14601 Names : constant Name_List (1 .. 4) := (
14602 Name_Internal,
14603 Name_External,
14604 Name_Parameter_Types,
14605 Name_Mechanism);
14607 Internal : Node_Id renames Args (1);
14608 External : Node_Id renames Args (2);
14609 Parameter_Types : Node_Id renames Args (3);
14610 Mechanism : Node_Id renames Args (4);
14612 begin
14613 GNAT_Pragma;
14614 Gather_Associations (Names, Args);
14615 Process_Extended_Import_Export_Subprogram_Pragma (
14616 Arg_Internal => Internal,
14617 Arg_External => External,
14618 Arg_Parameter_Types => Parameter_Types,
14619 Arg_Mechanism => Mechanism);
14620 end Import_Valued_Procedure;
14622 -----------------
14623 -- Independent --
14624 -----------------
14626 -- pragma Independent (LOCAL_NAME);
14628 when Pragma_Independent =>
14629 Process_Atomic_Independent_Shared_Volatile;
14631 ----------------------------
14632 -- Independent_Components --
14633 ----------------------------
14635 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
14637 when Pragma_Independent_Components => Independent_Components : declare
14638 E_Id : Node_Id;
14639 E : Entity_Id;
14640 D : Node_Id;
14641 K : Node_Kind;
14642 C : Node_Id;
14644 begin
14645 Check_Ada_83_Warning;
14646 Ada_2012_Pragma;
14647 Check_No_Identifiers;
14648 Check_Arg_Count (1);
14649 Check_Arg_Is_Local_Name (Arg1);
14650 E_Id := Get_Pragma_Arg (Arg1);
14652 if Etype (E_Id) = Any_Type then
14653 return;
14654 end if;
14656 E := Entity (E_Id);
14658 -- Check duplicate before we chain ourselves
14660 Check_Duplicate_Pragma (E);
14662 -- Check appropriate entity
14664 if Rep_Item_Too_Early (E, N)
14665 or else
14666 Rep_Item_Too_Late (E, N)
14667 then
14668 return;
14669 end if;
14671 D := Declaration_Node (E);
14672 K := Nkind (D);
14674 -- The flag is set on the base type, or on the object
14676 if K = N_Full_Type_Declaration
14677 and then (Is_Array_Type (E) or else Is_Record_Type (E))
14678 then
14679 Set_Has_Independent_Components (Base_Type (E));
14680 Record_Independence_Check (N, Base_Type (E));
14682 -- For record type, set all components independent
14684 if Is_Record_Type (E) then
14685 C := First_Component (E);
14686 while Present (C) loop
14687 Set_Is_Independent (C);
14688 Next_Component (C);
14689 end loop;
14690 end if;
14692 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
14693 and then Nkind (D) = N_Object_Declaration
14694 and then Nkind (Object_Definition (D)) =
14695 N_Constrained_Array_Definition
14696 then
14697 Set_Has_Independent_Components (E);
14698 Record_Independence_Check (N, E);
14700 else
14701 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
14702 end if;
14703 end Independent_Components;
14705 -----------------------
14706 -- Initial_Condition --
14707 -----------------------
14709 -- pragma Initial_Condition (boolean_EXPRESSION);
14711 when Pragma_Initial_Condition => Initial_Condition : declare
14712 Pack_Decl : Node_Id;
14713 Pack_Id : Entity_Id;
14715 begin
14716 GNAT_Pragma;
14717 Check_No_Identifiers;
14718 Check_Arg_Count (1);
14720 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
14722 -- Ensure the proper placement of the pragma. Initial_Condition
14723 -- must be associated with a package declaration.
14725 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
14726 N_Package_Declaration)
14727 then
14728 null;
14730 -- Otherwise the pragma is associated with an illegal context
14732 else
14733 Pragma_Misplaced;
14734 return;
14735 end if;
14737 -- The pragma must be analyzed at the end of the visible
14738 -- declarations of the related package. Save the pragma for later
14739 -- (see Analyze_Initial_Condition_In_Decl_Part) by adding it to
14740 -- the contract of the package.
14742 Pack_Id := Defining_Entity (Pack_Decl);
14743 Add_Contract_Item (N, Pack_Id);
14745 -- Verify the declaration order of pragma Initial_Condition with
14746 -- respect to pragmas Abstract_State and Initializes when SPARK
14747 -- checks are enabled.
14749 if SPARK_Mode /= Off then
14750 Check_Declaration_Order
14751 (First => Get_Pragma (Pack_Id, Pragma_Abstract_State),
14752 Second => N);
14754 Check_Declaration_Order
14755 (First => Get_Pragma (Pack_Id, Pragma_Initializes),
14756 Second => N);
14757 end if;
14758 end Initial_Condition;
14760 ------------------------
14761 -- Initialize_Scalars --
14762 ------------------------
14764 -- pragma Initialize_Scalars;
14766 when Pragma_Initialize_Scalars =>
14767 GNAT_Pragma;
14768 Check_Arg_Count (0);
14769 Check_Valid_Configuration_Pragma;
14770 Check_Restriction (No_Initialize_Scalars, N);
14772 -- Initialize_Scalars creates false positives in CodePeer, and
14773 -- incorrect negative results in GNATprove mode, so ignore this
14774 -- pragma in these modes.
14776 if not Restriction_Active (No_Initialize_Scalars)
14777 and then not (CodePeer_Mode or GNATprove_Mode)
14778 then
14779 Init_Or_Norm_Scalars := True;
14780 Initialize_Scalars := True;
14781 end if;
14783 -----------------
14784 -- Initializes --
14785 -----------------
14787 -- pragma Initializes (INITIALIZATION_SPEC);
14789 -- INITIALIZATION_SPEC ::= null | INITIALIZATION_LIST
14791 -- INITIALIZATION_LIST ::=
14792 -- INITIALIZATION_ITEM
14793 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
14795 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
14797 -- INPUT_LIST ::=
14798 -- null
14799 -- | INPUT
14800 -- | (INPUT {, INPUT})
14802 -- INPUT ::= name
14804 when Pragma_Initializes => Initializes : declare
14805 Pack_Decl : Node_Id;
14806 Pack_Id : Entity_Id;
14808 begin
14809 GNAT_Pragma;
14810 Check_No_Identifiers;
14811 Check_Arg_Count (1);
14813 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
14815 -- Ensure the proper placement of the pragma. Initializes must be
14816 -- associated with a package declaration.
14818 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
14819 N_Package_Declaration)
14820 then
14821 null;
14823 -- Otherwise the pragma is associated with an illegal construc
14825 else
14826 Pragma_Misplaced;
14827 return;
14828 end if;
14830 Ensure_Aggregate_Form (Get_Argument (N));
14832 -- The pragma must be analyzed at the end of the visible
14833 -- declarations of the related package. Save the pragma for later
14834 -- (see Analyze_Initializes_In_Decl_Part) by adding it to the
14835 -- contract of the package.
14837 Pack_Id := Defining_Entity (Pack_Decl);
14838 Add_Contract_Item (N, Pack_Id);
14840 -- Verify the declaration order of pragmas Abstract_State and
14841 -- Initializes when SPARK checks are enabled.
14843 if SPARK_Mode /= Off then
14844 Check_Declaration_Order
14845 (First => Get_Pragma (Pack_Id, Pragma_Abstract_State),
14846 Second => N);
14847 end if;
14848 end Initializes;
14850 ------------
14851 -- Inline --
14852 ------------
14854 -- pragma Inline ( NAME {, NAME} );
14856 when Pragma_Inline =>
14858 -- Pragma always active unless in GNATprove mode. It is disabled
14859 -- in GNATprove mode because frontend inlining is applied
14860 -- independently of pragmas Inline and Inline_Always for
14861 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
14862 -- in inline.ads.
14864 if not GNATprove_Mode then
14866 -- Inline status is Enabled if inlining option is active
14868 if Inline_Active then
14869 Process_Inline (Enabled);
14870 else
14871 Process_Inline (Disabled);
14872 end if;
14873 end if;
14875 -------------------
14876 -- Inline_Always --
14877 -------------------
14879 -- pragma Inline_Always ( NAME {, NAME} );
14881 when Pragma_Inline_Always =>
14882 GNAT_Pragma;
14884 -- Pragma always active unless in CodePeer mode or GNATprove
14885 -- mode. It is disabled in CodePeer mode because inlining is
14886 -- not helpful, and enabling it caused walk order issues. It
14887 -- is disabled in GNATprove mode because frontend inlining is
14888 -- applied independently of pragmas Inline and Inline_Always for
14889 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
14890 -- inline.ads.
14892 if not CodePeer_Mode and not GNATprove_Mode then
14893 Process_Inline (Enabled);
14894 end if;
14896 --------------------
14897 -- Inline_Generic --
14898 --------------------
14900 -- pragma Inline_Generic (NAME {, NAME});
14902 when Pragma_Inline_Generic =>
14903 GNAT_Pragma;
14904 Process_Generic_List;
14906 ----------------------
14907 -- Inspection_Point --
14908 ----------------------
14910 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
14912 when Pragma_Inspection_Point => Inspection_Point : declare
14913 Arg : Node_Id;
14914 Exp : Node_Id;
14916 begin
14919 if Arg_Count > 0 then
14920 Arg := Arg1;
14921 loop
14922 Exp := Get_Pragma_Arg (Arg);
14923 Analyze (Exp);
14925 if not Is_Entity_Name (Exp)
14926 or else not Is_Object (Entity (Exp))
14927 then
14928 Error_Pragma_Arg ("object name required", Arg);
14929 end if;
14931 Next (Arg);
14932 exit when No (Arg);
14933 end loop;
14934 end if;
14935 end Inspection_Point;
14937 ---------------
14938 -- Interface --
14939 ---------------
14941 -- pragma Interface (
14942 -- [ Convention =>] convention_IDENTIFIER,
14943 -- [ Entity =>] LOCAL_NAME
14944 -- [, [External_Name =>] static_string_EXPRESSION ]
14945 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14947 when Pragma_Interface =>
14948 GNAT_Pragma;
14949 Check_Arg_Order
14950 ((Name_Convention,
14951 Name_Entity,
14952 Name_External_Name,
14953 Name_Link_Name));
14954 Check_At_Least_N_Arguments (2);
14955 Check_At_Most_N_Arguments (4);
14956 Process_Import_Or_Interface;
14958 -- In Ada 2005, the permission to use Interface (a reserved word)
14959 -- as a pragma name is considered an obsolescent feature, and this
14960 -- pragma was already obsolescent in Ada 95.
14962 if Ada_Version >= Ada_95 then
14963 Check_Restriction
14964 (No_Obsolescent_Features, Pragma_Identifier (N));
14966 if Warn_On_Obsolescent_Feature then
14967 Error_Msg_N
14968 ("pragma Interface is an obsolescent feature?j?", N);
14969 Error_Msg_N
14970 ("|use pragma Import instead?j?", N);
14971 end if;
14972 end if;
14974 --------------------
14975 -- Interface_Name --
14976 --------------------
14978 -- pragma Interface_Name (
14979 -- [ Entity =>] LOCAL_NAME
14980 -- [,[External_Name =>] static_string_EXPRESSION ]
14981 -- [,[Link_Name =>] static_string_EXPRESSION ]);
14983 when Pragma_Interface_Name => Interface_Name : declare
14984 Id : Node_Id;
14985 Def_Id : Entity_Id;
14986 Hom_Id : Entity_Id;
14987 Found : Boolean;
14989 begin
14990 GNAT_Pragma;
14991 Check_Arg_Order
14992 ((Name_Entity, Name_External_Name, Name_Link_Name));
14993 Check_At_Least_N_Arguments (2);
14994 Check_At_Most_N_Arguments (3);
14995 Id := Get_Pragma_Arg (Arg1);
14996 Analyze (Id);
14998 -- This is obsolete from Ada 95 on, but it is an implementation
14999 -- defined pragma, so we do not consider that it violates the
15000 -- restriction (No_Obsolescent_Features).
15002 if Ada_Version >= Ada_95 then
15003 if Warn_On_Obsolescent_Feature then
15004 Error_Msg_N
15005 ("pragma Interface_Name is an obsolescent feature?j?", N);
15006 Error_Msg_N
15007 ("|use pragma Import instead?j?", N);
15008 end if;
15009 end if;
15011 if not Is_Entity_Name (Id) then
15012 Error_Pragma_Arg
15013 ("first argument for pragma% must be entity name", Arg1);
15014 elsif Etype (Id) = Any_Type then
15015 return;
15016 else
15017 Def_Id := Entity (Id);
15018 end if;
15020 -- Special DEC-compatible processing for the object case, forces
15021 -- object to be imported.
15023 if Ekind (Def_Id) = E_Variable then
15024 Kill_Size_Check_Code (Def_Id);
15025 Note_Possible_Modification (Id, Sure => False);
15027 -- Initialization is not allowed for imported variable
15029 if Present (Expression (Parent (Def_Id)))
15030 and then Comes_From_Source (Expression (Parent (Def_Id)))
15031 then
15032 Error_Msg_Sloc := Sloc (Def_Id);
15033 Error_Pragma_Arg
15034 ("no initialization allowed for declaration of& #",
15035 Arg2);
15037 else
15038 -- For compatibility, support VADS usage of providing both
15039 -- pragmas Interface and Interface_Name to obtain the effect
15040 -- of a single Import pragma.
15042 if Is_Imported (Def_Id)
15043 and then Present (First_Rep_Item (Def_Id))
15044 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
15045 and then
15046 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
15047 then
15048 null;
15049 else
15050 Set_Imported (Def_Id);
15051 end if;
15053 Set_Is_Public (Def_Id);
15054 Process_Interface_Name (Def_Id, Arg2, Arg3);
15055 end if;
15057 -- Otherwise must be subprogram
15059 elsif not Is_Subprogram (Def_Id) then
15060 Error_Pragma_Arg
15061 ("argument of pragma% is not subprogram", Arg1);
15063 else
15064 Check_At_Most_N_Arguments (3);
15065 Hom_Id := Def_Id;
15066 Found := False;
15068 -- Loop through homonyms
15070 loop
15071 Def_Id := Get_Base_Subprogram (Hom_Id);
15073 if Is_Imported (Def_Id) then
15074 Process_Interface_Name (Def_Id, Arg2, Arg3);
15075 Found := True;
15076 end if;
15078 exit when From_Aspect_Specification (N);
15079 Hom_Id := Homonym (Hom_Id);
15081 exit when No (Hom_Id)
15082 or else Scope (Hom_Id) /= Current_Scope;
15083 end loop;
15085 if not Found then
15086 Error_Pragma_Arg
15087 ("argument of pragma% is not imported subprogram",
15088 Arg1);
15089 end if;
15090 end if;
15091 end Interface_Name;
15093 -----------------------
15094 -- Interrupt_Handler --
15095 -----------------------
15097 -- pragma Interrupt_Handler (handler_NAME);
15099 when Pragma_Interrupt_Handler =>
15100 Check_Ada_83_Warning;
15101 Check_Arg_Count (1);
15102 Check_No_Identifiers;
15104 if No_Run_Time_Mode then
15105 Error_Msg_CRT ("Interrupt_Handler pragma", N);
15106 else
15107 Check_Interrupt_Or_Attach_Handler;
15108 Process_Interrupt_Or_Attach_Handler;
15109 end if;
15111 ------------------------
15112 -- Interrupt_Priority --
15113 ------------------------
15115 -- pragma Interrupt_Priority [(EXPRESSION)];
15117 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
15118 P : constant Node_Id := Parent (N);
15119 Arg : Node_Id;
15120 Ent : Entity_Id;
15122 begin
15123 Check_Ada_83_Warning;
15125 if Arg_Count /= 0 then
15126 Arg := Get_Pragma_Arg (Arg1);
15127 Check_Arg_Count (1);
15128 Check_No_Identifiers;
15130 -- The expression must be analyzed in the special manner
15131 -- described in "Handling of Default and Per-Object
15132 -- Expressions" in sem.ads.
15134 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
15135 end if;
15137 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
15138 Pragma_Misplaced;
15139 return;
15141 else
15142 Ent := Defining_Identifier (Parent (P));
15144 -- Check duplicate pragma before we chain the pragma in the Rep
15145 -- Item chain of Ent.
15147 Check_Duplicate_Pragma (Ent);
15148 Record_Rep_Item (Ent, N);
15149 end if;
15150 end Interrupt_Priority;
15152 ---------------------
15153 -- Interrupt_State --
15154 ---------------------
15156 -- pragma Interrupt_State (
15157 -- [Name =>] INTERRUPT_ID,
15158 -- [State =>] INTERRUPT_STATE);
15160 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
15161 -- INTERRUPT_STATE => System | Runtime | User
15163 -- Note: if the interrupt id is given as an identifier, then it must
15164 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
15165 -- given as a static integer expression which must be in the range of
15166 -- Ada.Interrupts.Interrupt_ID.
15168 when Pragma_Interrupt_State => Interrupt_State : declare
15169 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
15170 -- This is the entity Ada.Interrupts.Interrupt_ID;
15172 State_Type : Character;
15173 -- Set to 's'/'r'/'u' for System/Runtime/User
15175 IST_Num : Pos;
15176 -- Index to entry in Interrupt_States table
15178 Int_Val : Uint;
15179 -- Value of interrupt
15181 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
15182 -- The first argument to the pragma
15184 Int_Ent : Entity_Id;
15185 -- Interrupt entity in Ada.Interrupts.Names
15187 begin
15188 GNAT_Pragma;
15189 Check_Arg_Order ((Name_Name, Name_State));
15190 Check_Arg_Count (2);
15192 Check_Optional_Identifier (Arg1, Name_Name);
15193 Check_Optional_Identifier (Arg2, Name_State);
15194 Check_Arg_Is_Identifier (Arg2);
15196 -- First argument is identifier
15198 if Nkind (Arg1X) = N_Identifier then
15200 -- Search list of names in Ada.Interrupts.Names
15202 Int_Ent := First_Entity (RTE (RE_Names));
15203 loop
15204 if No (Int_Ent) then
15205 Error_Pragma_Arg ("invalid interrupt name", Arg1);
15207 elsif Chars (Int_Ent) = Chars (Arg1X) then
15208 Int_Val := Expr_Value (Constant_Value (Int_Ent));
15209 exit;
15210 end if;
15212 Next_Entity (Int_Ent);
15213 end loop;
15215 -- First argument is not an identifier, so it must be a static
15216 -- expression of type Ada.Interrupts.Interrupt_ID.
15218 else
15219 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
15220 Int_Val := Expr_Value (Arg1X);
15222 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
15223 or else
15224 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
15225 then
15226 Error_Pragma_Arg
15227 ("value not in range of type "
15228 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
15229 end if;
15230 end if;
15232 -- Check OK state
15234 case Chars (Get_Pragma_Arg (Arg2)) is
15235 when Name_Runtime => State_Type := 'r';
15236 when Name_System => State_Type := 's';
15237 when Name_User => State_Type := 'u';
15239 when others =>
15240 Error_Pragma_Arg ("invalid interrupt state", Arg2);
15241 end case;
15243 -- Check if entry is already stored
15245 IST_Num := Interrupt_States.First;
15246 loop
15247 -- If entry not found, add it
15249 if IST_Num > Interrupt_States.Last then
15250 Interrupt_States.Append
15251 ((Interrupt_Number => UI_To_Int (Int_Val),
15252 Interrupt_State => State_Type,
15253 Pragma_Loc => Loc));
15254 exit;
15256 -- Case of entry for the same entry
15258 elsif Int_Val = Interrupt_States.Table (IST_Num).
15259 Interrupt_Number
15260 then
15261 -- If state matches, done, no need to make redundant entry
15263 exit when
15264 State_Type = Interrupt_States.Table (IST_Num).
15265 Interrupt_State;
15267 -- Otherwise if state does not match, error
15269 Error_Msg_Sloc :=
15270 Interrupt_States.Table (IST_Num).Pragma_Loc;
15271 Error_Pragma_Arg
15272 ("state conflicts with that given #", Arg2);
15273 exit;
15274 end if;
15276 IST_Num := IST_Num + 1;
15277 end loop;
15278 end Interrupt_State;
15280 ---------------
15281 -- Invariant --
15282 ---------------
15284 -- pragma Invariant
15285 -- ([Entity =>] type_LOCAL_NAME,
15286 -- [Check =>] EXPRESSION
15287 -- [,[Message =>] String_Expression]);
15289 when Pragma_Invariant => Invariant : declare
15290 Type_Id : Node_Id;
15291 Typ : Entity_Id;
15292 Discard : Boolean;
15294 begin
15295 GNAT_Pragma;
15296 Check_At_Least_N_Arguments (2);
15297 Check_At_Most_N_Arguments (3);
15298 Check_Optional_Identifier (Arg1, Name_Entity);
15299 Check_Optional_Identifier (Arg2, Name_Check);
15301 if Arg_Count = 3 then
15302 Check_Optional_Identifier (Arg3, Name_Message);
15303 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
15304 end if;
15306 Check_Arg_Is_Local_Name (Arg1);
15308 Type_Id := Get_Pragma_Arg (Arg1);
15309 Find_Type (Type_Id);
15310 Typ := Entity (Type_Id);
15312 if Typ = Any_Type then
15313 return;
15315 -- Invariants allowed in interface types (RM 7.3.2(3/3))
15317 elsif Is_Interface (Typ) then
15318 null;
15320 -- An invariant must apply to a private type, or appear in the
15321 -- private part of a package spec and apply to a completion.
15322 -- a class-wide invariant can only appear on a private declaration
15323 -- or private extension, not a completion.
15325 elsif Ekind_In (Typ, E_Private_Type,
15326 E_Record_Type_With_Private,
15327 E_Limited_Private_Type)
15328 then
15329 null;
15331 elsif In_Private_Part (Current_Scope)
15332 and then Has_Private_Declaration (Typ)
15333 and then not Class_Present (N)
15334 then
15335 null;
15337 elsif In_Private_Part (Current_Scope) then
15338 Error_Pragma_Arg
15339 ("pragma% only allowed for private type declared in "
15340 & "visible part", Arg1);
15342 else
15343 Error_Pragma_Arg
15344 ("pragma% only allowed for private type", Arg1);
15345 end if;
15347 -- Not allowed for abstract type in the non-class case (it is
15348 -- allowed to use Invariant'Class for abstract types).
15350 if Is_Abstract_Type (Typ) and then not Class_Present (N) then
15351 Error_Pragma_Arg
15352 ("pragma% not allowed for abstract type", Arg1);
15353 end if;
15355 -- Note that the type has at least one invariant, and also that
15356 -- it has inheritable invariants if we have Invariant'Class
15357 -- or Type_Invariant'Class. Build the corresponding invariant
15358 -- procedure declaration, so that calls to it can be generated
15359 -- before the body is built (e.g. within an expression function).
15361 -- Interface types have no invariant procedure; their invariants
15362 -- are propagated to the build invariant procedure of all the
15363 -- types covering the interface type.
15365 if not Is_Interface (Typ) then
15366 Insert_After_And_Analyze
15367 (N, Build_Invariant_Procedure_Declaration (Typ));
15368 end if;
15370 if Class_Present (N) then
15371 Set_Has_Inheritable_Invariants (Typ);
15372 end if;
15374 -- The remaining processing is simply to link the pragma on to
15375 -- the rep item chain, for processing when the type is frozen.
15376 -- This is accomplished by a call to Rep_Item_Too_Late.
15378 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
15379 end Invariant;
15381 ----------------------
15382 -- Java_Constructor --
15383 ----------------------
15385 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
15387 -- Also handles pragma CIL_Constructor
15389 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
15390 Java_Constructor : declare
15391 Convention : Convention_Id;
15392 Def_Id : Entity_Id;
15393 Hom_Id : Entity_Id;
15394 Id : Entity_Id;
15395 This_Formal : Entity_Id;
15397 begin
15398 GNAT_Pragma;
15399 Check_Arg_Count (1);
15400 Check_Optional_Identifier (Arg1, Name_Entity);
15401 Check_Arg_Is_Local_Name (Arg1);
15403 Id := Get_Pragma_Arg (Arg1);
15404 Find_Program_Unit_Name (Id);
15406 -- If we did not find the name, we are done
15408 if Etype (Id) = Any_Type then
15409 return;
15410 end if;
15412 -- Check wrong use of pragma in wrong VM target
15414 if VM_Target = No_VM then
15415 return;
15417 elsif VM_Target = CLI_Target
15418 and then Prag_Id = Pragma_Java_Constructor
15419 then
15420 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
15422 elsif VM_Target = JVM_Target
15423 and then Prag_Id = Pragma_CIL_Constructor
15424 then
15425 Error_Pragma ("must use pragma 'Java_'Constructor");
15426 end if;
15428 case Prag_Id is
15429 when Pragma_CIL_Constructor => Convention := Convention_CIL;
15430 when Pragma_Java_Constructor => Convention := Convention_Java;
15431 when others => null;
15432 end case;
15434 Hom_Id := Entity (Id);
15436 -- Loop through homonyms
15438 loop
15439 Def_Id := Get_Base_Subprogram (Hom_Id);
15441 -- The constructor is required to be a function
15443 if Ekind (Def_Id) /= E_Function then
15444 if VM_Target = JVM_Target then
15445 Error_Pragma_Arg
15446 ("pragma% requires function returning a 'Java access "
15447 & "type", Def_Id);
15448 else
15449 Error_Pragma_Arg
15450 ("pragma% requires function returning a 'C'I'L access "
15451 & "type", Def_Id);
15452 end if;
15453 end if;
15455 -- Check arguments: For tagged type the first formal must be
15456 -- named "this" and its type must be a named access type
15457 -- designating a class-wide tagged type that has convention
15458 -- CIL/Java. The first formal must also have a null default
15459 -- value. For example:
15461 -- type Typ is tagged ...
15462 -- type Ref is access all Typ;
15463 -- pragma Convention (CIL, Typ);
15465 -- function New_Typ (This : Ref) return Ref;
15466 -- function New_Typ (This : Ref; I : Integer) return Ref;
15467 -- pragma Cil_Constructor (New_Typ);
15469 -- Reason: The first formal must NOT be a primitive of the
15470 -- tagged type.
15472 -- This rule also applies to constructors of delegates used
15473 -- to interface with standard target libraries. For example:
15475 -- type Delegate is access procedure ...
15476 -- pragma Import (CIL, Delegate, ...);
15478 -- function new_Delegate
15479 -- (This : Delegate := null; ... ) return Delegate;
15481 -- For value-types this rule does not apply.
15483 if not Is_Value_Type (Etype (Def_Id)) then
15484 if No (First_Formal (Def_Id)) then
15485 Error_Msg_Name_1 := Pname;
15486 Error_Msg_N ("% function must have parameters", Def_Id);
15487 return;
15488 end if;
15490 -- In the JRE library we have several occurrences in which
15491 -- the "this" parameter is not the first formal.
15493 This_Formal := First_Formal (Def_Id);
15495 -- In the JRE library we have several occurrences in which
15496 -- the "this" parameter is not the first formal. Search for
15497 -- it.
15499 if VM_Target = JVM_Target then
15500 while Present (This_Formal)
15501 and then Get_Name_String (Chars (This_Formal)) /= "this"
15502 loop
15503 Next_Formal (This_Formal);
15504 end loop;
15506 if No (This_Formal) then
15507 This_Formal := First_Formal (Def_Id);
15508 end if;
15509 end if;
15511 -- Warning: The first parameter should be named "this".
15512 -- We temporarily allow it because we have the following
15513 -- case in the Java runtime (file s-osinte.ads) ???
15515 -- function new_Thread
15516 -- (Self_Id : System.Address) return Thread_Id;
15517 -- pragma Java_Constructor (new_Thread);
15519 if VM_Target = JVM_Target
15520 and then Get_Name_String (Chars (First_Formal (Def_Id)))
15521 = "self_id"
15522 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
15523 then
15524 null;
15526 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
15527 Error_Msg_Name_1 := Pname;
15528 Error_Msg_N
15529 ("first formal of % function must be named `this`",
15530 Parent (This_Formal));
15532 elsif not Is_Access_Type (Etype (This_Formal)) then
15533 Error_Msg_Name_1 := Pname;
15534 Error_Msg_N
15535 ("first formal of % function must be an access type",
15536 Parameter_Type (Parent (This_Formal)));
15538 -- For delegates the type of the first formal must be a
15539 -- named access-to-subprogram type (see previous example)
15541 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
15542 and then Ekind (Etype (This_Formal))
15543 /= E_Access_Subprogram_Type
15544 then
15545 Error_Msg_Name_1 := Pname;
15546 Error_Msg_N
15547 ("first formal of % function must be a named access "
15548 & "to subprogram type",
15549 Parameter_Type (Parent (This_Formal)));
15551 -- Warning: We should reject anonymous access types because
15552 -- the constructor must not be handled as a primitive of the
15553 -- tagged type. We temporarily allow it because this profile
15554 -- is currently generated by cil2ada???
15556 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
15557 and then not Ekind_In (Etype (This_Formal),
15558 E_Access_Type,
15559 E_General_Access_Type,
15560 E_Anonymous_Access_Type)
15561 then
15562 Error_Msg_Name_1 := Pname;
15563 Error_Msg_N
15564 ("first formal of % function must be a named access "
15565 & "type", Parameter_Type (Parent (This_Formal)));
15567 elsif Atree.Convention
15568 (Designated_Type (Etype (This_Formal))) /= Convention
15569 then
15570 Error_Msg_Name_1 := Pname;
15572 if Convention = Convention_Java then
15573 Error_Msg_N
15574 ("pragma% requires convention 'Cil in designated "
15575 & "type", Parameter_Type (Parent (This_Formal)));
15576 else
15577 Error_Msg_N
15578 ("pragma% requires convention 'Java in designated "
15579 & "type", Parameter_Type (Parent (This_Formal)));
15580 end if;
15582 elsif No (Expression (Parent (This_Formal)))
15583 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
15584 then
15585 Error_Msg_Name_1 := Pname;
15586 Error_Msg_N
15587 ("pragma% requires first formal with default `null`",
15588 Parameter_Type (Parent (This_Formal)));
15589 end if;
15590 end if;
15592 -- Check result type: the constructor must be a function
15593 -- returning:
15594 -- * a value type (only allowed in the CIL compiler)
15595 -- * an access-to-subprogram type with convention Java/CIL
15596 -- * an access-type designating a type that has convention
15597 -- Java/CIL.
15599 if Is_Value_Type (Etype (Def_Id)) then
15600 null;
15602 -- Access-to-subprogram type with convention Java/CIL
15604 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
15605 if Atree.Convention (Etype (Def_Id)) /= Convention then
15606 if Convention = Convention_Java then
15607 Error_Pragma_Arg
15608 ("pragma% requires function returning a 'Java "
15609 & "access type", Arg1);
15610 else
15611 pragma Assert (Convention = Convention_CIL);
15612 Error_Pragma_Arg
15613 ("pragma% requires function returning a 'C'I'L "
15614 & "access type", Arg1);
15615 end if;
15616 end if;
15618 elsif Is_Access_Type (Etype (Def_Id)) then
15619 if not Ekind_In (Etype (Def_Id), E_Access_Type,
15620 E_General_Access_Type)
15621 or else
15622 Atree.Convention
15623 (Designated_Type (Etype (Def_Id))) /= Convention
15624 then
15625 Error_Msg_Name_1 := Pname;
15627 if Convention = Convention_Java then
15628 Error_Pragma_Arg
15629 ("pragma% requires function returning a named "
15630 & "'Java access type", Arg1);
15631 else
15632 Error_Pragma_Arg
15633 ("pragma% requires function returning a named "
15634 & "'C'I'L access type", Arg1);
15635 end if;
15636 end if;
15637 end if;
15639 Set_Is_Constructor (Def_Id);
15640 Set_Convention (Def_Id, Convention);
15641 Set_Is_Imported (Def_Id);
15643 exit when From_Aspect_Specification (N);
15644 Hom_Id := Homonym (Hom_Id);
15646 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
15647 end loop;
15648 end Java_Constructor;
15650 ----------------------
15651 -- Java_Interface --
15652 ----------------------
15654 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
15656 when Pragma_Java_Interface => Java_Interface : declare
15657 Arg : Node_Id;
15658 Typ : Entity_Id;
15660 begin
15661 GNAT_Pragma;
15662 Check_Arg_Count (1);
15663 Check_Optional_Identifier (Arg1, Name_Entity);
15664 Check_Arg_Is_Local_Name (Arg1);
15666 Arg := Get_Pragma_Arg (Arg1);
15667 Analyze (Arg);
15669 if Etype (Arg) = Any_Type then
15670 return;
15671 end if;
15673 if not Is_Entity_Name (Arg)
15674 or else not Is_Type (Entity (Arg))
15675 then
15676 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
15677 end if;
15679 Typ := Underlying_Type (Entity (Arg));
15681 -- For now simply check some of the semantic constraints on the
15682 -- type. This currently leaves out some restrictions on interface
15683 -- types, namely that the parent type must be java.lang.Object.Typ
15684 -- and that all primitives of the type should be declared
15685 -- abstract. ???
15687 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
15688 Error_Pragma_Arg
15689 ("pragma% requires an abstract tagged type", Arg1);
15691 elsif not Has_Discriminants (Typ)
15692 or else Ekind (Etype (First_Discriminant (Typ)))
15693 /= E_Anonymous_Access_Type
15694 or else
15695 not Is_Class_Wide_Type
15696 (Designated_Type (Etype (First_Discriminant (Typ))))
15697 then
15698 Error_Pragma_Arg
15699 ("type must have a class-wide access discriminant", Arg1);
15700 end if;
15701 end Java_Interface;
15703 ----------------
15704 -- Keep_Names --
15705 ----------------
15707 -- pragma Keep_Names ([On => ] LOCAL_NAME);
15709 when Pragma_Keep_Names => Keep_Names : declare
15710 Arg : Node_Id;
15712 begin
15713 GNAT_Pragma;
15714 Check_Arg_Count (1);
15715 Check_Optional_Identifier (Arg1, Name_On);
15716 Check_Arg_Is_Local_Name (Arg1);
15718 Arg := Get_Pragma_Arg (Arg1);
15719 Analyze (Arg);
15721 if Etype (Arg) = Any_Type then
15722 return;
15723 end if;
15725 if not Is_Entity_Name (Arg)
15726 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
15727 then
15728 Error_Pragma_Arg
15729 ("pragma% requires a local enumeration type", Arg1);
15730 end if;
15732 Set_Discard_Names (Entity (Arg), False);
15733 end Keep_Names;
15735 -------------
15736 -- License --
15737 -------------
15739 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
15741 when Pragma_License =>
15742 GNAT_Pragma;
15744 -- Do not analyze pragma any further in CodePeer mode, to avoid
15745 -- extraneous errors in this implementation-dependent pragma,
15746 -- which has a different profile on other compilers.
15748 if CodePeer_Mode then
15749 return;
15750 end if;
15752 Check_Arg_Count (1);
15753 Check_No_Identifiers;
15754 Check_Valid_Configuration_Pragma;
15755 Check_Arg_Is_Identifier (Arg1);
15757 declare
15758 Sind : constant Source_File_Index :=
15759 Source_Index (Current_Sem_Unit);
15761 begin
15762 case Chars (Get_Pragma_Arg (Arg1)) is
15763 when Name_GPL =>
15764 Set_License (Sind, GPL);
15766 when Name_Modified_GPL =>
15767 Set_License (Sind, Modified_GPL);
15769 when Name_Restricted =>
15770 Set_License (Sind, Restricted);
15772 when Name_Unrestricted =>
15773 Set_License (Sind, Unrestricted);
15775 when others =>
15776 Error_Pragma_Arg ("invalid license name", Arg1);
15777 end case;
15778 end;
15780 ---------------
15781 -- Link_With --
15782 ---------------
15784 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
15786 when Pragma_Link_With => Link_With : declare
15787 Arg : Node_Id;
15789 begin
15790 GNAT_Pragma;
15792 if Operating_Mode = Generate_Code
15793 and then In_Extended_Main_Source_Unit (N)
15794 then
15795 Check_At_Least_N_Arguments (1);
15796 Check_No_Identifiers;
15797 Check_Is_In_Decl_Part_Or_Package_Spec;
15798 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
15799 Start_String;
15801 Arg := Arg1;
15802 while Present (Arg) loop
15803 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
15805 -- Store argument, converting sequences of spaces to a
15806 -- single null character (this is one of the differences
15807 -- in processing between Link_With and Linker_Options).
15809 Arg_Store : declare
15810 C : constant Char_Code := Get_Char_Code (' ');
15811 S : constant String_Id :=
15812 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
15813 L : constant Nat := String_Length (S);
15814 F : Nat := 1;
15816 procedure Skip_Spaces;
15817 -- Advance F past any spaces
15819 -----------------
15820 -- Skip_Spaces --
15821 -----------------
15823 procedure Skip_Spaces is
15824 begin
15825 while F <= L and then Get_String_Char (S, F) = C loop
15826 F := F + 1;
15827 end loop;
15828 end Skip_Spaces;
15830 -- Start of processing for Arg_Store
15832 begin
15833 Skip_Spaces; -- skip leading spaces
15835 -- Loop through characters, changing any embedded
15836 -- sequence of spaces to a single null character (this
15837 -- is how Link_With/Linker_Options differ)
15839 while F <= L loop
15840 if Get_String_Char (S, F) = C then
15841 Skip_Spaces;
15842 exit when F > L;
15843 Store_String_Char (ASCII.NUL);
15845 else
15846 Store_String_Char (Get_String_Char (S, F));
15847 F := F + 1;
15848 end if;
15849 end loop;
15850 end Arg_Store;
15852 Arg := Next (Arg);
15854 if Present (Arg) then
15855 Store_String_Char (ASCII.NUL);
15856 end if;
15857 end loop;
15859 Store_Linker_Option_String (End_String);
15860 end if;
15861 end Link_With;
15863 ------------------
15864 -- Linker_Alias --
15865 ------------------
15867 -- pragma Linker_Alias (
15868 -- [Entity =>] LOCAL_NAME
15869 -- [Target =>] static_string_EXPRESSION);
15871 when Pragma_Linker_Alias =>
15872 GNAT_Pragma;
15873 Check_Arg_Order ((Name_Entity, Name_Target));
15874 Check_Arg_Count (2);
15875 Check_Optional_Identifier (Arg1, Name_Entity);
15876 Check_Optional_Identifier (Arg2, Name_Target);
15877 Check_Arg_Is_Library_Level_Local_Name (Arg1);
15878 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
15880 -- The only processing required is to link this item on to the
15881 -- list of rep items for the given entity. This is accomplished
15882 -- by the call to Rep_Item_Too_Late (when no error is detected
15883 -- and False is returned).
15885 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
15886 return;
15887 else
15888 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
15889 end if;
15891 ------------------------
15892 -- Linker_Constructor --
15893 ------------------------
15895 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
15897 -- Code is shared with Linker_Destructor
15899 -----------------------
15900 -- Linker_Destructor --
15901 -----------------------
15903 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
15905 when Pragma_Linker_Constructor |
15906 Pragma_Linker_Destructor =>
15907 Linker_Constructor : declare
15908 Arg1_X : Node_Id;
15909 Proc : Entity_Id;
15911 begin
15912 GNAT_Pragma;
15913 Check_Arg_Count (1);
15914 Check_No_Identifiers;
15915 Check_Arg_Is_Local_Name (Arg1);
15916 Arg1_X := Get_Pragma_Arg (Arg1);
15917 Analyze (Arg1_X);
15918 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
15920 if not Is_Library_Level_Entity (Proc) then
15921 Error_Pragma_Arg
15922 ("argument for pragma% must be library level entity", Arg1);
15923 end if;
15925 -- The only processing required is to link this item on to the
15926 -- list of rep items for the given entity. This is accomplished
15927 -- by the call to Rep_Item_Too_Late (when no error is detected
15928 -- and False is returned).
15930 if Rep_Item_Too_Late (Proc, N) then
15931 return;
15932 else
15933 Set_Has_Gigi_Rep_Item (Proc);
15934 end if;
15935 end Linker_Constructor;
15937 --------------------
15938 -- Linker_Options --
15939 --------------------
15941 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
15943 when Pragma_Linker_Options => Linker_Options : declare
15944 Arg : Node_Id;
15946 begin
15947 Check_Ada_83_Warning;
15948 Check_No_Identifiers;
15949 Check_Arg_Count (1);
15950 Check_Is_In_Decl_Part_Or_Package_Spec;
15951 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
15952 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
15954 Arg := Arg2;
15955 while Present (Arg) loop
15956 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
15957 Store_String_Char (ASCII.NUL);
15958 Store_String_Chars
15959 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
15960 Arg := Next (Arg);
15961 end loop;
15963 if Operating_Mode = Generate_Code
15964 and then In_Extended_Main_Source_Unit (N)
15965 then
15966 Store_Linker_Option_String (End_String);
15967 end if;
15968 end Linker_Options;
15970 --------------------
15971 -- Linker_Section --
15972 --------------------
15974 -- pragma Linker_Section (
15975 -- [Entity =>] LOCAL_NAME
15976 -- [Section =>] static_string_EXPRESSION);
15978 when Pragma_Linker_Section => Linker_Section : declare
15979 Arg : Node_Id;
15980 Ent : Entity_Id;
15981 LPE : Node_Id;
15983 begin
15984 GNAT_Pragma;
15985 Check_Arg_Order ((Name_Entity, Name_Section));
15986 Check_Arg_Count (2);
15987 Check_Optional_Identifier (Arg1, Name_Entity);
15988 Check_Optional_Identifier (Arg2, Name_Section);
15989 Check_Arg_Is_Library_Level_Local_Name (Arg1);
15990 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
15992 -- Check kind of entity
15994 Arg := Get_Pragma_Arg (Arg1);
15995 Ent := Entity (Arg);
15997 case Ekind (Ent) is
15999 -- Objects (constants and variables) and types. For these cases
16000 -- all we need to do is to set the Linker_Section_pragma field,
16001 -- checking that we do not have a duplicate.
16003 when E_Constant | E_Variable | Type_Kind =>
16004 LPE := Linker_Section_Pragma (Ent);
16006 if Present (LPE) then
16007 Error_Msg_Sloc := Sloc (LPE);
16008 Error_Msg_NE
16009 ("Linker_Section already specified for &#", Arg1, Ent);
16010 end if;
16012 Set_Linker_Section_Pragma (Ent, N);
16014 -- Subprograms
16016 when Subprogram_Kind =>
16018 -- Aspect case, entity already set
16020 if From_Aspect_Specification (N) then
16021 Set_Linker_Section_Pragma
16022 (Entity (Corresponding_Aspect (N)), N);
16024 -- Pragma case, we must climb the homonym chain, but skip
16025 -- any for which the linker section is already set.
16027 else
16028 loop
16029 if No (Linker_Section_Pragma (Ent)) then
16030 Set_Linker_Section_Pragma (Ent, N);
16031 end if;
16033 Ent := Homonym (Ent);
16034 exit when No (Ent)
16035 or else Scope (Ent) /= Current_Scope;
16036 end loop;
16037 end if;
16039 -- All other cases are illegal
16041 when others =>
16042 Error_Pragma_Arg
16043 ("pragma% applies only to objects, subprograms, and types",
16044 Arg1);
16045 end case;
16046 end Linker_Section;
16048 ----------
16049 -- List --
16050 ----------
16052 -- pragma List (On | Off)
16054 -- There is nothing to do here, since we did all the processing for
16055 -- this pragma in Par.Prag (so that it works properly even in syntax
16056 -- only mode).
16058 when Pragma_List =>
16059 null;
16061 ---------------
16062 -- Lock_Free --
16063 ---------------
16065 -- pragma Lock_Free [(Boolean_EXPRESSION)];
16067 when Pragma_Lock_Free => Lock_Free : declare
16068 P : constant Node_Id := Parent (N);
16069 Arg : Node_Id;
16070 Ent : Entity_Id;
16071 Val : Boolean;
16073 begin
16074 Check_No_Identifiers;
16075 Check_At_Most_N_Arguments (1);
16077 -- Protected definition case
16079 if Nkind (P) = N_Protected_Definition then
16080 Ent := Defining_Identifier (Parent (P));
16082 -- One argument
16084 if Arg_Count = 1 then
16085 Arg := Get_Pragma_Arg (Arg1);
16086 Val := Is_True (Static_Boolean (Arg));
16088 -- No arguments (expression is considered to be True)
16090 else
16091 Val := True;
16092 end if;
16094 -- Check duplicate pragma before we chain the pragma in the Rep
16095 -- Item chain of Ent.
16097 Check_Duplicate_Pragma (Ent);
16098 Record_Rep_Item (Ent, N);
16099 Set_Uses_Lock_Free (Ent, Val);
16101 -- Anything else is incorrect placement
16103 else
16104 Pragma_Misplaced;
16105 end if;
16106 end Lock_Free;
16108 --------------------
16109 -- Locking_Policy --
16110 --------------------
16112 -- pragma Locking_Policy (policy_IDENTIFIER);
16114 when Pragma_Locking_Policy => declare
16115 subtype LP_Range is Name_Id
16116 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
16117 LP_Val : LP_Range;
16118 LP : Character;
16120 begin
16121 Check_Ada_83_Warning;
16122 Check_Arg_Count (1);
16123 Check_No_Identifiers;
16124 Check_Arg_Is_Locking_Policy (Arg1);
16125 Check_Valid_Configuration_Pragma;
16126 LP_Val := Chars (Get_Pragma_Arg (Arg1));
16128 case LP_Val is
16129 when Name_Ceiling_Locking =>
16130 LP := 'C';
16131 when Name_Inheritance_Locking =>
16132 LP := 'I';
16133 when Name_Concurrent_Readers_Locking =>
16134 LP := 'R';
16135 end case;
16137 if Locking_Policy /= ' '
16138 and then Locking_Policy /= LP
16139 then
16140 Error_Msg_Sloc := Locking_Policy_Sloc;
16141 Error_Pragma ("locking policy incompatible with policy#");
16143 -- Set new policy, but always preserve System_Location since we
16144 -- like the error message with the run time name.
16146 else
16147 Locking_Policy := LP;
16149 if Locking_Policy_Sloc /= System_Location then
16150 Locking_Policy_Sloc := Loc;
16151 end if;
16152 end if;
16153 end;
16155 -------------------
16156 -- Loop_Optimize --
16157 -------------------
16159 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
16161 -- OPTIMIZATION_HINT ::=
16162 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
16164 when Pragma_Loop_Optimize => Loop_Optimize : declare
16165 Hint : Node_Id;
16167 begin
16168 GNAT_Pragma;
16169 Check_At_Least_N_Arguments (1);
16170 Check_No_Identifiers;
16172 Hint := First (Pragma_Argument_Associations (N));
16173 while Present (Hint) loop
16174 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
16175 Name_No_Unroll,
16176 Name_Unroll,
16177 Name_No_Vector,
16178 Name_Vector);
16179 Next (Hint);
16180 end loop;
16182 Check_Loop_Pragma_Placement;
16183 end Loop_Optimize;
16185 ------------------
16186 -- Loop_Variant --
16187 ------------------
16189 -- pragma Loop_Variant
16190 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
16192 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
16194 -- CHANGE_DIRECTION ::= Increases | Decreases
16196 when Pragma_Loop_Variant => Loop_Variant : declare
16197 Variant : Node_Id;
16199 begin
16200 GNAT_Pragma;
16201 Check_At_Least_N_Arguments (1);
16202 Check_Loop_Pragma_Placement;
16204 -- Process all increasing / decreasing expressions
16206 Variant := First (Pragma_Argument_Associations (N));
16207 while Present (Variant) loop
16208 if not Nam_In (Chars (Variant), Name_Decreases,
16209 Name_Increases)
16210 then
16211 Error_Pragma_Arg ("wrong change modifier", Variant);
16212 end if;
16214 Preanalyze_Assert_Expression
16215 (Expression (Variant), Any_Discrete);
16217 Next (Variant);
16218 end loop;
16219 end Loop_Variant;
16221 -----------------------
16222 -- Machine_Attribute --
16223 -----------------------
16225 -- pragma Machine_Attribute (
16226 -- [Entity =>] LOCAL_NAME,
16227 -- [Attribute_Name =>] static_string_EXPRESSION
16228 -- [, [Info =>] static_EXPRESSION] );
16230 when Pragma_Machine_Attribute => Machine_Attribute : declare
16231 Def_Id : Entity_Id;
16233 begin
16234 GNAT_Pragma;
16235 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
16237 if Arg_Count = 3 then
16238 Check_Optional_Identifier (Arg3, Name_Info);
16239 Check_Arg_Is_OK_Static_Expression (Arg3);
16240 else
16241 Check_Arg_Count (2);
16242 end if;
16244 Check_Optional_Identifier (Arg1, Name_Entity);
16245 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
16246 Check_Arg_Is_Local_Name (Arg1);
16247 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16248 Def_Id := Entity (Get_Pragma_Arg (Arg1));
16250 if Is_Access_Type (Def_Id) then
16251 Def_Id := Designated_Type (Def_Id);
16252 end if;
16254 if Rep_Item_Too_Early (Def_Id, N) then
16255 return;
16256 end if;
16258 Def_Id := Underlying_Type (Def_Id);
16260 -- The only processing required is to link this item on to the
16261 -- list of rep items for the given entity. This is accomplished
16262 -- by the call to Rep_Item_Too_Late (when no error is detected
16263 -- and False is returned).
16265 if Rep_Item_Too_Late (Def_Id, N) then
16266 return;
16267 else
16268 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
16269 end if;
16270 end Machine_Attribute;
16272 ----------
16273 -- Main --
16274 ----------
16276 -- pragma Main
16277 -- (MAIN_OPTION [, MAIN_OPTION]);
16279 -- MAIN_OPTION ::=
16280 -- [STACK_SIZE =>] static_integer_EXPRESSION
16281 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
16282 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
16284 when Pragma_Main => Main : declare
16285 Args : Args_List (1 .. 3);
16286 Names : constant Name_List (1 .. 3) := (
16287 Name_Stack_Size,
16288 Name_Task_Stack_Size_Default,
16289 Name_Time_Slicing_Enabled);
16291 Nod : Node_Id;
16293 begin
16294 GNAT_Pragma;
16295 Gather_Associations (Names, Args);
16297 for J in 1 .. 2 loop
16298 if Present (Args (J)) then
16299 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
16300 end if;
16301 end loop;
16303 if Present (Args (3)) then
16304 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
16305 end if;
16307 Nod := Next (N);
16308 while Present (Nod) loop
16309 if Nkind (Nod) = N_Pragma
16310 and then Pragma_Name (Nod) = Name_Main
16311 then
16312 Error_Msg_Name_1 := Pname;
16313 Error_Msg_N ("duplicate pragma% not permitted", Nod);
16314 end if;
16316 Next (Nod);
16317 end loop;
16318 end Main;
16320 ------------------
16321 -- Main_Storage --
16322 ------------------
16324 -- pragma Main_Storage
16325 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
16327 -- MAIN_STORAGE_OPTION ::=
16328 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
16329 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
16331 when Pragma_Main_Storage => Main_Storage : declare
16332 Args : Args_List (1 .. 2);
16333 Names : constant Name_List (1 .. 2) := (
16334 Name_Working_Storage,
16335 Name_Top_Guard);
16337 Nod : Node_Id;
16339 begin
16340 GNAT_Pragma;
16341 Gather_Associations (Names, Args);
16343 for J in 1 .. 2 loop
16344 if Present (Args (J)) then
16345 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
16346 end if;
16347 end loop;
16349 Check_In_Main_Program;
16351 Nod := Next (N);
16352 while Present (Nod) loop
16353 if Nkind (Nod) = N_Pragma
16354 and then Pragma_Name (Nod) = Name_Main_Storage
16355 then
16356 Error_Msg_Name_1 := Pname;
16357 Error_Msg_N ("duplicate pragma% not permitted", Nod);
16358 end if;
16360 Next (Nod);
16361 end loop;
16362 end Main_Storage;
16364 -----------------
16365 -- Memory_Size --
16366 -----------------
16368 -- pragma Memory_Size (NUMERIC_LITERAL)
16370 when Pragma_Memory_Size =>
16371 GNAT_Pragma;
16373 -- Memory size is simply ignored
16375 Check_No_Identifiers;
16376 Check_Arg_Count (1);
16377 Check_Arg_Is_Integer_Literal (Arg1);
16379 -------------
16380 -- No_Body --
16381 -------------
16383 -- pragma No_Body;
16385 -- The only correct use of this pragma is on its own in a file, in
16386 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
16387 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
16388 -- check for a file containing nothing but a No_Body pragma). If we
16389 -- attempt to process it during normal semantics processing, it means
16390 -- it was misplaced.
16392 when Pragma_No_Body =>
16393 GNAT_Pragma;
16394 Pragma_Misplaced;
16396 -----------------------------
16397 -- No_Elaboration_Code_All --
16398 -----------------------------
16400 -- pragma No_Elaboration_Code_All;
16402 when Pragma_No_Elaboration_Code_All => NECA : declare
16403 begin
16404 GNAT_Pragma;
16405 Check_Valid_Library_Unit_Pragma;
16407 if Nkind (N) = N_Null_Statement then
16408 return;
16409 end if;
16411 -- Must appear for a spec or generic spec
16413 if not Nkind_In (Unit (Cunit (Current_Sem_Unit)),
16414 N_Generic_Package_Declaration,
16415 N_Generic_Subprogram_Declaration,
16416 N_Package_Declaration,
16417 N_Subprogram_Declaration)
16418 then
16419 Error_Pragma
16420 (Fix_Error
16421 ("pragma% can only occur for package "
16422 & "or subprogram spec"));
16423 end if;
16425 -- Set flag in unit table
16427 Set_No_Elab_Code_All (Current_Sem_Unit);
16429 -- Set restriction No_Elaboration_Code if this is the main unit
16431 if Current_Sem_Unit = Main_Unit then
16432 Set_Restriction (No_Elaboration_Code, N);
16433 end if;
16435 -- If we are in the main unit or in an extended main source unit,
16436 -- then we also add it to the configuration restrictions so that
16437 -- it will apply to all units in the extended main source.
16439 if Current_Sem_Unit = Main_Unit
16440 or else In_Extended_Main_Source_Unit (N)
16441 then
16442 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
16443 end if;
16445 -- If in main extended unit, activate transitive with test
16447 if In_Extended_Main_Source_Unit (N) then
16448 Opt.No_Elab_Code_All_Pragma := N;
16449 end if;
16450 end NECA;
16452 ---------------
16453 -- No_Inline --
16454 ---------------
16456 -- pragma No_Inline ( NAME {, NAME} );
16458 when Pragma_No_Inline =>
16459 GNAT_Pragma;
16460 Process_Inline (Suppressed);
16462 ---------------
16463 -- No_Return --
16464 ---------------
16466 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
16468 when Pragma_No_Return => No_Return : declare
16469 Id : Node_Id;
16470 E : Entity_Id;
16471 Found : Boolean;
16472 Arg : Node_Id;
16474 begin
16475 Ada_2005_Pragma;
16476 Check_At_Least_N_Arguments (1);
16478 -- Loop through arguments of pragma
16480 Arg := Arg1;
16481 while Present (Arg) loop
16482 Check_Arg_Is_Local_Name (Arg);
16483 Id := Get_Pragma_Arg (Arg);
16484 Analyze (Id);
16486 if not Is_Entity_Name (Id) then
16487 Error_Pragma_Arg ("entity name required", Arg);
16488 end if;
16490 if Etype (Id) = Any_Type then
16491 raise Pragma_Exit;
16492 end if;
16494 -- Loop to find matching procedures
16496 E := Entity (Id);
16497 Found := False;
16498 while Present (E)
16499 and then Scope (E) = Current_Scope
16500 loop
16501 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
16502 Set_No_Return (E);
16504 -- Set flag on any alias as well
16506 if Is_Overloadable (E) and then Present (Alias (E)) then
16507 Set_No_Return (Alias (E));
16508 end if;
16510 Found := True;
16511 end if;
16513 exit when From_Aspect_Specification (N);
16514 E := Homonym (E);
16515 end loop;
16517 -- If entity in not in current scope it may be the enclosing
16518 -- suprogram body to which the aspect applies.
16520 if not Found then
16521 if Entity (Id) = Current_Scope
16522 and then From_Aspect_Specification (N)
16523 then
16524 Set_No_Return (Entity (Id));
16525 else
16526 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
16527 end if;
16528 end if;
16530 Next (Arg);
16531 end loop;
16532 end No_Return;
16534 -----------------
16535 -- No_Run_Time --
16536 -----------------
16538 -- pragma No_Run_Time;
16540 -- Note: this pragma is retained for backwards compatibility. See
16541 -- body of Rtsfind for full details on its handling.
16543 when Pragma_No_Run_Time =>
16544 GNAT_Pragma;
16545 Check_Valid_Configuration_Pragma;
16546 Check_Arg_Count (0);
16548 No_Run_Time_Mode := True;
16549 Configurable_Run_Time_Mode := True;
16551 -- Set Duration to 32 bits if word size is 32
16553 if Ttypes.System_Word_Size = 32 then
16554 Duration_32_Bits_On_Target := True;
16555 end if;
16557 -- Set appropriate restrictions
16559 Set_Restriction (No_Finalization, N);
16560 Set_Restriction (No_Exception_Handlers, N);
16561 Set_Restriction (Max_Tasks, N, 0);
16562 Set_Restriction (No_Tasking, N);
16564 -----------------------
16565 -- No_Tagged_Streams --
16566 -----------------------
16568 -- pragma No_Tagged_Streams;
16569 -- pragma No_Tagged_Streams ([Entity => ]tagged_type_local_NAME);
16571 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
16572 E_Id : Node_Id;
16573 E : Entity_Id;
16575 begin
16576 GNAT_Pragma;
16577 Check_At_Most_N_Arguments (1);
16579 -- One argument case
16581 if Arg_Count = 1 then
16582 Check_Optional_Identifier (Arg1, Name_Entity);
16583 Check_Arg_Is_Local_Name (Arg1);
16584 E_Id := Get_Pragma_Arg (Arg1);
16586 if Etype (E_Id) = Any_Type then
16587 return;
16588 end if;
16590 E := Entity (E_Id);
16592 Check_Duplicate_Pragma (E);
16594 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
16595 Error_Pragma_Arg
16596 ("argument for pragma% must be root tagged type", Arg1);
16597 end if;
16599 if Rep_Item_Too_Early (E, N)
16600 or else
16601 Rep_Item_Too_Late (E, N)
16602 then
16603 return;
16604 else
16605 Set_No_Tagged_Streams_Pragma (E, N);
16606 end if;
16608 -- Zero argument case
16610 else
16611 Check_Is_In_Decl_Part_Or_Package_Spec;
16612 No_Tagged_Streams := N;
16613 end if;
16614 end No_Tagged_Strms;
16616 ------------------------
16617 -- No_Strict_Aliasing --
16618 ------------------------
16620 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
16622 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
16623 E_Id : Entity_Id;
16625 begin
16626 GNAT_Pragma;
16627 Check_At_Most_N_Arguments (1);
16629 if Arg_Count = 0 then
16630 Check_Valid_Configuration_Pragma;
16631 Opt.No_Strict_Aliasing := True;
16633 else
16634 Check_Optional_Identifier (Arg2, Name_Entity);
16635 Check_Arg_Is_Local_Name (Arg1);
16636 E_Id := Entity (Get_Pragma_Arg (Arg1));
16638 if E_Id = Any_Type then
16639 return;
16640 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
16641 Error_Pragma_Arg ("pragma% requires access type", Arg1);
16642 end if;
16644 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
16645 end if;
16646 end No_Strict_Aliasing;
16648 -----------------------
16649 -- Normalize_Scalars --
16650 -----------------------
16652 -- pragma Normalize_Scalars;
16654 when Pragma_Normalize_Scalars =>
16655 Check_Ada_83_Warning;
16656 Check_Arg_Count (0);
16657 Check_Valid_Configuration_Pragma;
16659 -- Normalize_Scalars creates false positives in CodePeer, and
16660 -- incorrect negative results in GNATprove mode, so ignore this
16661 -- pragma in these modes.
16663 if not (CodePeer_Mode or GNATprove_Mode) then
16664 Normalize_Scalars := True;
16665 Init_Or_Norm_Scalars := True;
16666 end if;
16668 -----------------
16669 -- Obsolescent --
16670 -----------------
16672 -- pragma Obsolescent;
16674 -- pragma Obsolescent (
16675 -- [Message =>] static_string_EXPRESSION
16676 -- [,[Version =>] Ada_05]]);
16678 -- pragma Obsolescent (
16679 -- [Entity =>] NAME
16680 -- [,[Message =>] static_string_EXPRESSION
16681 -- [,[Version =>] Ada_05]] );
16683 when Pragma_Obsolescent => Obsolescent : declare
16684 Ename : Node_Id;
16685 Decl : Node_Id;
16687 procedure Set_Obsolescent (E : Entity_Id);
16688 -- Given an entity Ent, mark it as obsolescent if appropriate
16690 ---------------------
16691 -- Set_Obsolescent --
16692 ---------------------
16694 procedure Set_Obsolescent (E : Entity_Id) is
16695 Active : Boolean;
16696 Ent : Entity_Id;
16697 S : String_Id;
16699 begin
16700 Active := True;
16701 Ent := E;
16703 -- Entity name was given
16705 if Present (Ename) then
16707 -- If entity name matches, we are fine. Save entity in
16708 -- pragma argument, for ASIS use.
16710 if Chars (Ename) = Chars (Ent) then
16711 Set_Entity (Ename, Ent);
16712 Generate_Reference (Ent, Ename);
16714 -- If entity name does not match, only possibility is an
16715 -- enumeration literal from an enumeration type declaration.
16717 elsif Ekind (Ent) /= E_Enumeration_Type then
16718 Error_Pragma
16719 ("pragma % entity name does not match declaration");
16721 else
16722 Ent := First_Literal (E);
16723 loop
16724 if No (Ent) then
16725 Error_Pragma
16726 ("pragma % entity name does not match any "
16727 & "enumeration literal");
16729 elsif Chars (Ent) = Chars (Ename) then
16730 Set_Entity (Ename, Ent);
16731 Generate_Reference (Ent, Ename);
16732 exit;
16734 else
16735 Ent := Next_Literal (Ent);
16736 end if;
16737 end loop;
16738 end if;
16739 end if;
16741 -- Ent points to entity to be marked
16743 if Arg_Count >= 1 then
16745 -- Deal with static string argument
16747 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
16748 S := Strval (Get_Pragma_Arg (Arg1));
16750 for J in 1 .. String_Length (S) loop
16751 if not In_Character_Range (Get_String_Char (S, J)) then
16752 Error_Pragma_Arg
16753 ("pragma% argument does not allow wide characters",
16754 Arg1);
16755 end if;
16756 end loop;
16758 Obsolescent_Warnings.Append
16759 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
16761 -- Check for Ada_05 parameter
16763 if Arg_Count /= 1 then
16764 Check_Arg_Count (2);
16766 declare
16767 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
16769 begin
16770 Check_Arg_Is_Identifier (Argx);
16772 if Chars (Argx) /= Name_Ada_05 then
16773 Error_Msg_Name_2 := Name_Ada_05;
16774 Error_Pragma_Arg
16775 ("only allowed argument for pragma% is %", Argx);
16776 end if;
16778 if Ada_Version_Explicit < Ada_2005
16779 or else not Warn_On_Ada_2005_Compatibility
16780 then
16781 Active := False;
16782 end if;
16783 end;
16784 end if;
16785 end if;
16787 -- Set flag if pragma active
16789 if Active then
16790 Set_Is_Obsolescent (Ent);
16791 end if;
16793 return;
16794 end Set_Obsolescent;
16796 -- Start of processing for pragma Obsolescent
16798 begin
16799 GNAT_Pragma;
16801 Check_At_Most_N_Arguments (3);
16803 -- See if first argument specifies an entity name
16805 if Arg_Count >= 1
16806 and then
16807 (Chars (Arg1) = Name_Entity
16808 or else
16809 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
16810 N_Identifier,
16811 N_Operator_Symbol))
16812 then
16813 Ename := Get_Pragma_Arg (Arg1);
16815 -- Eliminate first argument, so we can share processing
16817 Arg1 := Arg2;
16818 Arg2 := Arg3;
16819 Arg_Count := Arg_Count - 1;
16821 -- No Entity name argument given
16823 else
16824 Ename := Empty;
16825 end if;
16827 if Arg_Count >= 1 then
16828 Check_Optional_Identifier (Arg1, Name_Message);
16830 if Arg_Count = 2 then
16831 Check_Optional_Identifier (Arg2, Name_Version);
16832 end if;
16833 end if;
16835 -- Get immediately preceding declaration
16837 Decl := Prev (N);
16838 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
16839 Prev (Decl);
16840 end loop;
16842 -- Cases where we do not follow anything other than another pragma
16844 if No (Decl) then
16846 -- First case: library level compilation unit declaration with
16847 -- the pragma immediately following the declaration.
16849 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
16850 Set_Obsolescent
16851 (Defining_Entity (Unit (Parent (Parent (N)))));
16852 return;
16854 -- Case 2: library unit placement for package
16856 else
16857 declare
16858 Ent : constant Entity_Id := Find_Lib_Unit_Name;
16859 begin
16860 if Is_Package_Or_Generic_Package (Ent) then
16861 Set_Obsolescent (Ent);
16862 return;
16863 end if;
16864 end;
16865 end if;
16867 -- Cases where we must follow a declaration, including an
16868 -- abstract subprogram declaration, which is not in the
16869 -- other node subtypes.
16871 else
16872 if Nkind (Decl) not in N_Declaration
16873 and then Nkind (Decl) not in N_Later_Decl_Item
16874 and then Nkind (Decl) not in N_Generic_Declaration
16875 and then Nkind (Decl) not in N_Renaming_Declaration
16876 and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration
16877 then
16878 Error_Pragma
16879 ("pragma% misplaced, "
16880 & "must immediately follow a declaration");
16882 else
16883 Set_Obsolescent (Defining_Entity (Decl));
16884 return;
16885 end if;
16886 end if;
16887 end Obsolescent;
16889 --------------
16890 -- Optimize --
16891 --------------
16893 -- pragma Optimize (Time | Space | Off);
16895 -- The actual check for optimize is done in Gigi. Note that this
16896 -- pragma does not actually change the optimization setting, it
16897 -- simply checks that it is consistent with the pragma.
16899 when Pragma_Optimize =>
16900 Check_No_Identifiers;
16901 Check_Arg_Count (1);
16902 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
16904 ------------------------
16905 -- Optimize_Alignment --
16906 ------------------------
16908 -- pragma Optimize_Alignment (Time | Space | Off);
16910 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
16911 GNAT_Pragma;
16912 Check_No_Identifiers;
16913 Check_Arg_Count (1);
16914 Check_Valid_Configuration_Pragma;
16916 declare
16917 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
16918 begin
16919 case Nam is
16920 when Name_Time =>
16921 Opt.Optimize_Alignment := 'T';
16922 when Name_Space =>
16923 Opt.Optimize_Alignment := 'S';
16924 when Name_Off =>
16925 Opt.Optimize_Alignment := 'O';
16926 when others =>
16927 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
16928 end case;
16929 end;
16931 -- Set indication that mode is set locally. If we are in fact in a
16932 -- configuration pragma file, this setting is harmless since the
16933 -- switch will get reset anyway at the start of each unit.
16935 Optimize_Alignment_Local := True;
16936 end Optimize_Alignment;
16938 -------------
16939 -- Ordered --
16940 -------------
16942 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
16944 when Pragma_Ordered => Ordered : declare
16945 Assoc : constant Node_Id := Arg1;
16946 Type_Id : Node_Id;
16947 Typ : Entity_Id;
16949 begin
16950 GNAT_Pragma;
16951 Check_No_Identifiers;
16952 Check_Arg_Count (1);
16953 Check_Arg_Is_Local_Name (Arg1);
16955 Type_Id := Get_Pragma_Arg (Assoc);
16956 Find_Type (Type_Id);
16957 Typ := Entity (Type_Id);
16959 if Typ = Any_Type then
16960 return;
16961 else
16962 Typ := Underlying_Type (Typ);
16963 end if;
16965 if not Is_Enumeration_Type (Typ) then
16966 Error_Pragma ("pragma% must specify enumeration type");
16967 end if;
16969 Check_First_Subtype (Arg1);
16970 Set_Has_Pragma_Ordered (Base_Type (Typ));
16971 end Ordered;
16973 -------------------
16974 -- Overflow_Mode --
16975 -------------------
16977 -- pragma Overflow_Mode
16978 -- ([General => ] MODE [, [Assertions => ] MODE]);
16980 -- MODE := STRICT | MINIMIZED | ELIMINATED
16982 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
16983 -- since System.Bignums makes this assumption. This is true of nearly
16984 -- all (all?) targets.
16986 when Pragma_Overflow_Mode => Overflow_Mode : declare
16987 function Get_Overflow_Mode
16988 (Name : Name_Id;
16989 Arg : Node_Id) return Overflow_Mode_Type;
16990 -- Function to process one pragma argument, Arg. If an identifier
16991 -- is present, it must be Name. Mode type is returned if a valid
16992 -- argument exists, otherwise an error is signalled.
16994 -----------------------
16995 -- Get_Overflow_Mode --
16996 -----------------------
16998 function Get_Overflow_Mode
16999 (Name : Name_Id;
17000 Arg : Node_Id) return Overflow_Mode_Type
17002 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
17004 begin
17005 Check_Optional_Identifier (Arg, Name);
17006 Check_Arg_Is_Identifier (Argx);
17008 if Chars (Argx) = Name_Strict then
17009 return Strict;
17011 elsif Chars (Argx) = Name_Minimized then
17012 return Minimized;
17014 elsif Chars (Argx) = Name_Eliminated then
17015 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
17016 Error_Pragma_Arg
17017 ("Eliminated not implemented on this target", Argx);
17018 else
17019 return Eliminated;
17020 end if;
17022 else
17023 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
17024 end if;
17025 end Get_Overflow_Mode;
17027 -- Start of processing for Overflow_Mode
17029 begin
17030 GNAT_Pragma;
17031 Check_At_Least_N_Arguments (1);
17032 Check_At_Most_N_Arguments (2);
17034 -- Process first argument
17036 Scope_Suppress.Overflow_Mode_General :=
17037 Get_Overflow_Mode (Name_General, Arg1);
17039 -- Case of only one argument
17041 if Arg_Count = 1 then
17042 Scope_Suppress.Overflow_Mode_Assertions :=
17043 Scope_Suppress.Overflow_Mode_General;
17045 -- Case of two arguments present
17047 else
17048 Scope_Suppress.Overflow_Mode_Assertions :=
17049 Get_Overflow_Mode (Name_Assertions, Arg2);
17050 end if;
17051 end Overflow_Mode;
17053 --------------------------
17054 -- Overriding Renamings --
17055 --------------------------
17057 -- pragma Overriding_Renamings;
17059 when Pragma_Overriding_Renamings =>
17060 GNAT_Pragma;
17061 Check_Arg_Count (0);
17062 Check_Valid_Configuration_Pragma;
17063 Overriding_Renamings := True;
17065 ----------
17066 -- Pack --
17067 ----------
17069 -- pragma Pack (first_subtype_LOCAL_NAME);
17071 when Pragma_Pack => Pack : declare
17072 Assoc : constant Node_Id := Arg1;
17073 Type_Id : Node_Id;
17074 Typ : Entity_Id;
17075 Ctyp : Entity_Id;
17076 Ignore : Boolean := False;
17078 begin
17079 Check_No_Identifiers;
17080 Check_Arg_Count (1);
17081 Check_Arg_Is_Local_Name (Arg1);
17082 Type_Id := Get_Pragma_Arg (Assoc);
17084 if not Is_Entity_Name (Type_Id)
17085 or else not Is_Type (Entity (Type_Id))
17086 then
17087 Error_Pragma_Arg
17088 ("argument for pragma% must be type or subtype", Arg1);
17089 end if;
17091 Find_Type (Type_Id);
17092 Typ := Entity (Type_Id);
17094 if Typ = Any_Type
17095 or else Rep_Item_Too_Early (Typ, N)
17096 then
17097 return;
17098 else
17099 Typ := Underlying_Type (Typ);
17100 end if;
17102 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
17103 Error_Pragma ("pragma% must specify array or record type");
17104 end if;
17106 Check_First_Subtype (Arg1);
17107 Check_Duplicate_Pragma (Typ);
17109 -- Array type
17111 if Is_Array_Type (Typ) then
17112 Ctyp := Component_Type (Typ);
17114 -- Ignore pack that does nothing
17116 if Known_Static_Esize (Ctyp)
17117 and then Known_Static_RM_Size (Ctyp)
17118 and then Esize (Ctyp) = RM_Size (Ctyp)
17119 and then Addressable (Esize (Ctyp))
17120 then
17121 Ignore := True;
17122 end if;
17124 -- Process OK pragma Pack. Note that if there is a separate
17125 -- component clause present, the Pack will be cancelled. This
17126 -- processing is in Freeze.
17128 if not Rep_Item_Too_Late (Typ, N) then
17130 -- In CodePeer mode, we do not need complex front-end
17131 -- expansions related to pragma Pack, so disable handling
17132 -- of pragma Pack.
17134 if CodePeer_Mode then
17135 null;
17137 -- Don't attempt any packing for VM targets. We possibly
17138 -- could deal with some cases of array bit-packing, but we
17139 -- don't bother, since this is not a typical kind of
17140 -- representation in the VM context anyway (and would not
17141 -- for example work nicely with the debugger).
17143 elsif VM_Target /= No_VM then
17144 if not GNAT_Mode then
17145 Error_Pragma
17146 ("??pragma% ignored in this configuration");
17147 end if;
17149 -- Normal case where we do the pack action
17151 else
17152 if not Ignore then
17153 Set_Is_Packed (Base_Type (Typ));
17154 Set_Has_Non_Standard_Rep (Base_Type (Typ));
17155 end if;
17157 Set_Has_Pragma_Pack (Base_Type (Typ));
17158 end if;
17159 end if;
17161 -- For record types, the pack is always effective
17163 else pragma Assert (Is_Record_Type (Typ));
17164 if not Rep_Item_Too_Late (Typ, N) then
17166 -- Ignore pack request with warning in VM mode (skip warning
17167 -- if we are compiling GNAT run time library).
17169 if VM_Target /= No_VM then
17170 if not GNAT_Mode then
17171 Error_Pragma
17172 ("??pragma% ignored in this configuration");
17173 end if;
17175 -- Normal case of pack request active
17177 else
17178 Set_Is_Packed (Base_Type (Typ));
17179 Set_Has_Pragma_Pack (Base_Type (Typ));
17180 Set_Has_Non_Standard_Rep (Base_Type (Typ));
17181 end if;
17182 end if;
17183 end if;
17184 end Pack;
17186 ----------
17187 -- Page --
17188 ----------
17190 -- pragma Page;
17192 -- There is nothing to do here, since we did all the processing for
17193 -- this pragma in Par.Prag (so that it works properly even in syntax
17194 -- only mode).
17196 when Pragma_Page =>
17197 null;
17199 -------------
17200 -- Part_Of --
17201 -------------
17203 -- pragma Part_Of (ABSTRACT_STATE);
17205 -- ABSTRACT_STATE ::= NAME
17207 when Pragma_Part_Of => Part_Of : declare
17208 procedure Propagate_Part_Of
17209 (Pack_Id : Entity_Id;
17210 State_Id : Entity_Id;
17211 Instance : Node_Id);
17212 -- Propagate the Part_Of indicator to all abstract states and
17213 -- variables declared in the visible state space of a package
17214 -- denoted by Pack_Id. State_Id is the encapsulating state.
17215 -- Instance is the package instantiation node.
17217 -----------------------
17218 -- Propagate_Part_Of --
17219 -----------------------
17221 procedure Propagate_Part_Of
17222 (Pack_Id : Entity_Id;
17223 State_Id : Entity_Id;
17224 Instance : Node_Id)
17226 Has_Item : Boolean := False;
17227 -- Flag set when the visible state space contains at least one
17228 -- abstract state or variable.
17230 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
17231 -- Propagate the Part_Of indicator to all abstract states and
17232 -- variables declared in the visible state space of a package
17233 -- denoted by Pack_Id.
17235 -----------------------
17236 -- Propagate_Part_Of --
17237 -----------------------
17239 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
17240 Item_Id : Entity_Id;
17242 begin
17243 -- Traverse the entity chain of the package and set relevant
17244 -- attributes of abstract states and variables declared in
17245 -- the visible state space of the package.
17247 Item_Id := First_Entity (Pack_Id);
17248 while Present (Item_Id)
17249 and then not In_Private_Part (Item_Id)
17250 loop
17251 -- Do not consider internally generated items
17253 if not Comes_From_Source (Item_Id) then
17254 null;
17256 -- The Part_Of indicator turns an abstract state or
17257 -- variable into a constituent of the encapsulating
17258 -- state.
17260 elsif Ekind_In (Item_Id, E_Abstract_State,
17261 E_Variable)
17262 then
17263 Has_Item := True;
17265 Append_Elmt (Item_Id, Part_Of_Constituents (State_Id));
17266 Set_Encapsulating_State (Item_Id, State_Id);
17268 -- Recursively handle nested packages and instantiations
17270 elsif Ekind (Item_Id) = E_Package then
17271 Propagate_Part_Of (Item_Id);
17272 end if;
17274 Next_Entity (Item_Id);
17275 end loop;
17276 end Propagate_Part_Of;
17278 -- Start of processing for Propagate_Part_Of
17280 begin
17281 Propagate_Part_Of (Pack_Id);
17283 -- Detect a package instantiation that is subject to a Part_Of
17284 -- indicator, but has no visible state.
17286 if not Has_Item then
17287 SPARK_Msg_NE
17288 ("package instantiation & has Part_Of indicator but "
17289 & "lacks visible state", Instance, Pack_Id);
17290 end if;
17291 end Propagate_Part_Of;
17293 -- Local variables
17295 Item_Id : Entity_Id;
17296 Legal : Boolean;
17297 State : Node_Id;
17298 State_Id : Entity_Id;
17299 Stmt : Node_Id;
17301 -- Start of processing for Part_Of
17303 begin
17304 GNAT_Pragma;
17305 Check_No_Identifiers;
17306 Check_Arg_Count (1);
17308 -- Ensure the proper placement of the pragma. Part_Of must appear
17309 -- on a variable declaration or a package instantiation.
17311 Stmt := Prev (N);
17312 while Present (Stmt) loop
17314 -- Skip prior pragmas, but check for duplicates
17316 if Nkind (Stmt) = N_Pragma then
17317 if Pragma_Name (Stmt) = Pname then
17318 Error_Msg_Name_1 := Pname;
17319 Error_Msg_Sloc := Sloc (Stmt);
17320 Error_Msg_N ("pragma% duplicates pragma declared#", N);
17321 end if;
17323 -- Skip internally generated code
17325 elsif not Comes_From_Source (Stmt) then
17326 null;
17328 -- The pragma applies to an object declaration (possibly a
17329 -- variable) or a package instantiation. Stop the traversal
17330 -- and continue the analysis.
17332 elsif Nkind_In (Stmt, N_Object_Declaration,
17333 N_Package_Instantiation)
17334 then
17335 exit;
17337 -- The pragma does not apply to a legal construct, issue an
17338 -- error and stop the analysis.
17340 else
17341 Pragma_Misplaced;
17342 return;
17343 end if;
17345 Stmt := Prev (Stmt);
17346 end loop;
17348 -- When the context is an object declaration, ensure that we are
17349 -- dealing with a variable.
17351 if Nkind (Stmt) = N_Object_Declaration
17352 and then Ekind (Defining_Entity (Stmt)) /= E_Variable
17353 then
17354 SPARK_Msg_N ("indicator Part_Of must apply to a variable", N);
17355 return;
17356 end if;
17358 -- Extract the entity of the related object declaration or package
17359 -- instantiation. In the case of the instantiation, use the entity
17360 -- of the instance spec.
17362 if Nkind (Stmt) = N_Package_Instantiation then
17363 Stmt := Instance_Spec (Stmt);
17364 end if;
17366 Item_Id := Defining_Entity (Stmt);
17367 State := Get_Pragma_Arg (Arg1);
17369 -- Detect any discrepancies between the placement of the object
17370 -- or package instantiation with respect to state space and the
17371 -- encapsulating state.
17373 Analyze_Part_Of
17374 (Item_Id => Item_Id,
17375 State => State,
17376 Indic => N,
17377 Legal => Legal);
17379 if Legal then
17380 State_Id := Entity (State);
17382 -- Add the pragma to the contract of the item. This aids with
17383 -- the detection of a missing but required Part_Of indicator.
17385 Add_Contract_Item (N, Item_Id);
17387 -- The Part_Of indicator turns a variable into a constituent
17388 -- of the encapsulating state.
17390 if Ekind (Item_Id) = E_Variable then
17391 Append_Elmt (Item_Id, Part_Of_Constituents (State_Id));
17392 Set_Encapsulating_State (Item_Id, State_Id);
17394 -- Propagate the Part_Of indicator to the visible state space
17395 -- of the package instantiation.
17397 else
17398 Propagate_Part_Of
17399 (Pack_Id => Item_Id,
17400 State_Id => State_Id,
17401 Instance => Stmt);
17402 end if;
17403 end if;
17404 end Part_Of;
17406 ----------------------------------
17407 -- Partition_Elaboration_Policy --
17408 ----------------------------------
17410 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
17412 when Pragma_Partition_Elaboration_Policy => declare
17413 subtype PEP_Range is Name_Id
17414 range First_Partition_Elaboration_Policy_Name
17415 .. Last_Partition_Elaboration_Policy_Name;
17416 PEP_Val : PEP_Range;
17417 PEP : Character;
17419 begin
17420 Ada_2005_Pragma;
17421 Check_Arg_Count (1);
17422 Check_No_Identifiers;
17423 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
17424 Check_Valid_Configuration_Pragma;
17425 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
17427 case PEP_Val is
17428 when Name_Concurrent =>
17429 PEP := 'C';
17430 when Name_Sequential =>
17431 PEP := 'S';
17432 end case;
17434 if Partition_Elaboration_Policy /= ' '
17435 and then Partition_Elaboration_Policy /= PEP
17436 then
17437 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
17438 Error_Pragma
17439 ("partition elaboration policy incompatible with policy#");
17441 -- Set new policy, but always preserve System_Location since we
17442 -- like the error message with the run time name.
17444 else
17445 Partition_Elaboration_Policy := PEP;
17447 if Partition_Elaboration_Policy_Sloc /= System_Location then
17448 Partition_Elaboration_Policy_Sloc := Loc;
17449 end if;
17450 end if;
17451 end;
17453 -------------
17454 -- Passive --
17455 -------------
17457 -- pragma Passive [(PASSIVE_FORM)];
17459 -- PASSIVE_FORM ::= Semaphore | No
17461 when Pragma_Passive =>
17462 GNAT_Pragma;
17464 if Nkind (Parent (N)) /= N_Task_Definition then
17465 Error_Pragma ("pragma% must be within task definition");
17466 end if;
17468 if Arg_Count /= 0 then
17469 Check_Arg_Count (1);
17470 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
17471 end if;
17473 ----------------------------------
17474 -- Preelaborable_Initialization --
17475 ----------------------------------
17477 -- pragma Preelaborable_Initialization (DIRECT_NAME);
17479 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
17480 Ent : Entity_Id;
17482 begin
17483 Ada_2005_Pragma;
17484 Check_Arg_Count (1);
17485 Check_No_Identifiers;
17486 Check_Arg_Is_Identifier (Arg1);
17487 Check_Arg_Is_Local_Name (Arg1);
17488 Check_First_Subtype (Arg1);
17489 Ent := Entity (Get_Pragma_Arg (Arg1));
17491 -- The pragma may come from an aspect on a private declaration,
17492 -- even if the freeze point at which this is analyzed in the
17493 -- private part after the full view.
17495 if Has_Private_Declaration (Ent)
17496 and then From_Aspect_Specification (N)
17497 then
17498 null;
17500 -- Check appropriate type argument
17502 elsif Is_Private_Type (Ent)
17503 or else Is_Protected_Type (Ent)
17504 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
17506 -- AI05-0028: The pragma applies to all composite types. Note
17507 -- that we apply this binding interpretation to earlier versions
17508 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
17509 -- choice since there are other compilers that do the same.
17511 or else Is_Composite_Type (Ent)
17512 then
17513 null;
17515 else
17516 Error_Pragma_Arg
17517 ("pragma % can only be applied to private, formal derived, "
17518 & "protected, or composite type", Arg1);
17519 end if;
17521 -- Give an error if the pragma is applied to a protected type that
17522 -- does not qualify (due to having entries, or due to components
17523 -- that do not qualify).
17525 if Is_Protected_Type (Ent)
17526 and then not Has_Preelaborable_Initialization (Ent)
17527 then
17528 Error_Msg_N
17529 ("protected type & does not have preelaborable "
17530 & "initialization", Ent);
17532 -- Otherwise mark the type as definitely having preelaborable
17533 -- initialization.
17535 else
17536 Set_Known_To_Have_Preelab_Init (Ent);
17537 end if;
17539 if Has_Pragma_Preelab_Init (Ent)
17540 and then Warn_On_Redundant_Constructs
17541 then
17542 Error_Pragma ("?r?duplicate pragma%!");
17543 else
17544 Set_Has_Pragma_Preelab_Init (Ent);
17545 end if;
17546 end Preelab_Init;
17548 --------------------
17549 -- Persistent_BSS --
17550 --------------------
17552 -- pragma Persistent_BSS [(object_NAME)];
17554 when Pragma_Persistent_BSS => Persistent_BSS : declare
17555 Decl : Node_Id;
17556 Ent : Entity_Id;
17557 Prag : Node_Id;
17559 begin
17560 GNAT_Pragma;
17561 Check_At_Most_N_Arguments (1);
17563 -- Case of application to specific object (one argument)
17565 if Arg_Count = 1 then
17566 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17568 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
17569 or else not
17570 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
17571 E_Constant)
17572 then
17573 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
17574 end if;
17576 Ent := Entity (Get_Pragma_Arg (Arg1));
17577 Decl := Parent (Ent);
17579 -- Check for duplication before inserting in list of
17580 -- representation items.
17582 Check_Duplicate_Pragma (Ent);
17584 if Rep_Item_Too_Late (Ent, N) then
17585 return;
17586 end if;
17588 if Present (Expression (Decl)) then
17589 Error_Pragma_Arg
17590 ("object for pragma% cannot have initialization", Arg1);
17591 end if;
17593 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
17594 Error_Pragma_Arg
17595 ("object type for pragma% is not potentially persistent",
17596 Arg1);
17597 end if;
17599 Prag :=
17600 Make_Linker_Section_Pragma
17601 (Ent, Sloc (N), ".persistent.bss");
17602 Insert_After (N, Prag);
17603 Analyze (Prag);
17605 -- Case of use as configuration pragma with no arguments
17607 else
17608 Check_Valid_Configuration_Pragma;
17609 Persistent_BSS_Mode := True;
17610 end if;
17611 end Persistent_BSS;
17613 -------------
17614 -- Polling --
17615 -------------
17617 -- pragma Polling (ON | OFF);
17619 when Pragma_Polling =>
17620 GNAT_Pragma;
17621 Check_Arg_Count (1);
17622 Check_No_Identifiers;
17623 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
17624 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
17626 -----------------------------------
17627 -- Post/Post_Class/Postcondition --
17628 -----------------------------------
17630 -- pragma Post (Boolean_EXPRESSION);
17631 -- pragma Post_Class (Boolean_EXPRESSION);
17632 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
17633 -- [,[Message =>] String_EXPRESSION]);
17635 when Pragma_Post |
17636 Pragma_Post_Class |
17637 Pragma_Postcondition =>
17638 Analyze_Pre_Post_Condition;
17640 --------------------------------
17641 -- Pre/Pre_Class/Precondition --
17642 --------------------------------
17644 -- pragma Pre (Boolean_EXPRESSION);
17645 -- pragma Pre_Class (Boolean_EXPRESSION);
17646 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
17647 -- [,[Message =>] String_EXPRESSION]);
17649 when Pragma_Pre |
17650 Pragma_Pre_Class |
17651 Pragma_Precondition =>
17652 Analyze_Pre_Post_Condition;
17654 ---------------
17655 -- Predicate --
17656 ---------------
17658 -- pragma Predicate
17659 -- ([Entity =>] type_LOCAL_NAME,
17660 -- [Check =>] boolean_EXPRESSION);
17662 when Pragma_Predicate => Predicate : declare
17663 Type_Id : Node_Id;
17664 Typ : Entity_Id;
17665 Discard : Boolean;
17667 begin
17668 GNAT_Pragma;
17669 Check_Arg_Count (2);
17670 Check_Optional_Identifier (Arg1, Name_Entity);
17671 Check_Optional_Identifier (Arg2, Name_Check);
17673 Check_Arg_Is_Local_Name (Arg1);
17675 Type_Id := Get_Pragma_Arg (Arg1);
17676 Find_Type (Type_Id);
17677 Typ := Entity (Type_Id);
17679 if Typ = Any_Type then
17680 return;
17681 end if;
17683 -- The remaining processing is simply to link the pragma on to
17684 -- the rep item chain, for processing when the type is frozen.
17685 -- This is accomplished by a call to Rep_Item_Too_Late. We also
17686 -- mark the type as having predicates.
17688 Set_Has_Predicates (Typ);
17689 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
17690 end Predicate;
17692 ------------------
17693 -- Preelaborate --
17694 ------------------
17696 -- pragma Preelaborate [(library_unit_NAME)];
17698 -- Set the flag Is_Preelaborated of program unit name entity
17700 when Pragma_Preelaborate => Preelaborate : declare
17701 Pa : constant Node_Id := Parent (N);
17702 Pk : constant Node_Kind := Nkind (Pa);
17703 Ent : Entity_Id;
17705 begin
17706 Check_Ada_83_Warning;
17707 Check_Valid_Library_Unit_Pragma;
17709 if Nkind (N) = N_Null_Statement then
17710 return;
17711 end if;
17713 Ent := Find_Lib_Unit_Name;
17714 Check_Duplicate_Pragma (Ent);
17716 -- This filters out pragmas inside generic parents that show up
17717 -- inside instantiations. Pragmas that come from aspects in the
17718 -- unit are not ignored.
17720 if Present (Ent) then
17721 if Pk = N_Package_Specification
17722 and then Present (Generic_Parent (Pa))
17723 and then not From_Aspect_Specification (N)
17724 then
17725 null;
17727 else
17728 if not Debug_Flag_U then
17729 Set_Is_Preelaborated (Ent);
17730 Set_Suppress_Elaboration_Warnings (Ent);
17731 end if;
17732 end if;
17733 end if;
17734 end Preelaborate;
17736 -------------------------------
17737 -- Prefix_Exception_Messages --
17738 -------------------------------
17740 -- pragma Prefix_Exception_Messages;
17742 when Pragma_Prefix_Exception_Messages =>
17743 GNAT_Pragma;
17744 Check_Valid_Configuration_Pragma;
17745 Check_Arg_Count (0);
17746 Prefix_Exception_Messages := True;
17748 --------------
17749 -- Priority --
17750 --------------
17752 -- pragma Priority (EXPRESSION);
17754 when Pragma_Priority => Priority : declare
17755 P : constant Node_Id := Parent (N);
17756 Arg : Node_Id;
17757 Ent : Entity_Id;
17759 begin
17760 Check_No_Identifiers;
17761 Check_Arg_Count (1);
17763 -- Subprogram case
17765 if Nkind (P) = N_Subprogram_Body then
17766 Check_In_Main_Program;
17768 Ent := Defining_Unit_Name (Specification (P));
17770 if Nkind (Ent) = N_Defining_Program_Unit_Name then
17771 Ent := Defining_Identifier (Ent);
17772 end if;
17774 Arg := Get_Pragma_Arg (Arg1);
17775 Analyze_And_Resolve (Arg, Standard_Integer);
17777 -- Must be static
17779 if not Is_OK_Static_Expression (Arg) then
17780 Flag_Non_Static_Expr
17781 ("main subprogram priority is not static!", Arg);
17782 raise Pragma_Exit;
17784 -- If constraint error, then we already signalled an error
17786 elsif Raises_Constraint_Error (Arg) then
17787 null;
17789 -- Otherwise check in range except if Relaxed_RM_Semantics
17790 -- where we ignore the value if out of range.
17792 else
17793 declare
17794 Val : constant Uint := Expr_Value (Arg);
17795 begin
17796 if not Relaxed_RM_Semantics
17797 and then
17798 (Val < 0
17799 or else Val > Expr_Value (Expression
17800 (Parent (RTE (RE_Max_Priority)))))
17801 then
17802 Error_Pragma_Arg
17803 ("main subprogram priority is out of range", Arg1);
17804 else
17805 Set_Main_Priority
17806 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
17807 end if;
17808 end;
17809 end if;
17811 -- Load an arbitrary entity from System.Tasking.Stages or
17812 -- System.Tasking.Restricted.Stages (depending on the
17813 -- supported profile) to make sure that one of these packages
17814 -- is implicitly with'ed, since we need to have the tasking
17815 -- run time active for the pragma Priority to have any effect.
17816 -- Previously we with'ed the package System.Tasking, but this
17817 -- package does not trigger the required initialization of the
17818 -- run-time library.
17820 declare
17821 Discard : Entity_Id;
17822 pragma Warnings (Off, Discard);
17823 begin
17824 if Restricted_Profile then
17825 Discard := RTE (RE_Activate_Restricted_Tasks);
17826 else
17827 Discard := RTE (RE_Activate_Tasks);
17828 end if;
17829 end;
17831 -- Task or Protected, must be of type Integer
17833 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
17834 Arg := Get_Pragma_Arg (Arg1);
17835 Ent := Defining_Identifier (Parent (P));
17837 -- The expression must be analyzed in the special manner
17838 -- described in "Handling of Default and Per-Object
17839 -- Expressions" in sem.ads.
17841 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
17843 if not Is_OK_Static_Expression (Arg) then
17844 Check_Restriction (Static_Priorities, Arg);
17845 end if;
17847 -- Anything else is incorrect
17849 else
17850 Pragma_Misplaced;
17851 end if;
17853 -- Check duplicate pragma before we chain the pragma in the Rep
17854 -- Item chain of Ent.
17856 Check_Duplicate_Pragma (Ent);
17857 Record_Rep_Item (Ent, N);
17858 end Priority;
17860 -----------------------------------
17861 -- Priority_Specific_Dispatching --
17862 -----------------------------------
17864 -- pragma Priority_Specific_Dispatching (
17865 -- policy_IDENTIFIER,
17866 -- first_priority_EXPRESSION,
17867 -- last_priority_EXPRESSION);
17869 when Pragma_Priority_Specific_Dispatching =>
17870 Priority_Specific_Dispatching : declare
17871 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
17872 -- This is the entity System.Any_Priority;
17874 DP : Character;
17875 Lower_Bound : Node_Id;
17876 Upper_Bound : Node_Id;
17877 Lower_Val : Uint;
17878 Upper_Val : Uint;
17880 begin
17881 Ada_2005_Pragma;
17882 Check_Arg_Count (3);
17883 Check_No_Identifiers;
17884 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
17885 Check_Valid_Configuration_Pragma;
17886 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
17887 DP := Fold_Upper (Name_Buffer (1));
17889 Lower_Bound := Get_Pragma_Arg (Arg2);
17890 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
17891 Lower_Val := Expr_Value (Lower_Bound);
17893 Upper_Bound := Get_Pragma_Arg (Arg3);
17894 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
17895 Upper_Val := Expr_Value (Upper_Bound);
17897 -- It is not allowed to use Task_Dispatching_Policy and
17898 -- Priority_Specific_Dispatching in the same partition.
17900 if Task_Dispatching_Policy /= ' ' then
17901 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
17902 Error_Pragma
17903 ("pragma% incompatible with Task_Dispatching_Policy#");
17905 -- Check lower bound in range
17907 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
17908 or else
17909 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
17910 then
17911 Error_Pragma_Arg
17912 ("first_priority is out of range", Arg2);
17914 -- Check upper bound in range
17916 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
17917 or else
17918 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
17919 then
17920 Error_Pragma_Arg
17921 ("last_priority is out of range", Arg3);
17923 -- Check that the priority range is valid
17925 elsif Lower_Val > Upper_Val then
17926 Error_Pragma
17927 ("last_priority_expression must be greater than or equal to "
17928 & "first_priority_expression");
17930 -- Store the new policy, but always preserve System_Location since
17931 -- we like the error message with the run-time name.
17933 else
17934 -- Check overlapping in the priority ranges specified in other
17935 -- Priority_Specific_Dispatching pragmas within the same
17936 -- partition. We can only check those we know about.
17938 for J in
17939 Specific_Dispatching.First .. Specific_Dispatching.Last
17940 loop
17941 if Specific_Dispatching.Table (J).First_Priority in
17942 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
17943 or else Specific_Dispatching.Table (J).Last_Priority in
17944 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
17945 then
17946 Error_Msg_Sloc :=
17947 Specific_Dispatching.Table (J).Pragma_Loc;
17948 Error_Pragma
17949 ("priority range overlaps with "
17950 & "Priority_Specific_Dispatching#");
17951 end if;
17952 end loop;
17954 -- The use of Priority_Specific_Dispatching is incompatible
17955 -- with Task_Dispatching_Policy.
17957 if Task_Dispatching_Policy /= ' ' then
17958 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
17959 Error_Pragma
17960 ("Priority_Specific_Dispatching incompatible "
17961 & "with Task_Dispatching_Policy#");
17962 end if;
17964 -- The use of Priority_Specific_Dispatching forces ceiling
17965 -- locking policy.
17967 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
17968 Error_Msg_Sloc := Locking_Policy_Sloc;
17969 Error_Pragma
17970 ("Priority_Specific_Dispatching incompatible "
17971 & "with Locking_Policy#");
17973 -- Set the Ceiling_Locking policy, but preserve System_Location
17974 -- since we like the error message with the run time name.
17976 else
17977 Locking_Policy := 'C';
17979 if Locking_Policy_Sloc /= System_Location then
17980 Locking_Policy_Sloc := Loc;
17981 end if;
17982 end if;
17984 -- Add entry in the table
17986 Specific_Dispatching.Append
17987 ((Dispatching_Policy => DP,
17988 First_Priority => UI_To_Int (Lower_Val),
17989 Last_Priority => UI_To_Int (Upper_Val),
17990 Pragma_Loc => Loc));
17991 end if;
17992 end Priority_Specific_Dispatching;
17994 -------------
17995 -- Profile --
17996 -------------
17998 -- pragma Profile (profile_IDENTIFIER);
18000 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
18002 when Pragma_Profile =>
18003 Ada_2005_Pragma;
18004 Check_Arg_Count (1);
18005 Check_Valid_Configuration_Pragma;
18006 Check_No_Identifiers;
18008 declare
18009 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
18011 begin
18012 if Chars (Argx) = Name_Ravenscar then
18013 Set_Ravenscar_Profile (N);
18015 elsif Chars (Argx) = Name_Restricted then
18016 Set_Profile_Restrictions
18017 (Restricted,
18018 N, Warn => Treat_Restrictions_As_Warnings);
18020 elsif Chars (Argx) = Name_Rational then
18021 Set_Rational_Profile;
18023 elsif Chars (Argx) = Name_No_Implementation_Extensions then
18024 Set_Profile_Restrictions
18025 (No_Implementation_Extensions,
18026 N, Warn => Treat_Restrictions_As_Warnings);
18028 else
18029 Error_Pragma_Arg ("& is not a valid profile", Argx);
18030 end if;
18031 end;
18033 ----------------------
18034 -- Profile_Warnings --
18035 ----------------------
18037 -- pragma Profile_Warnings (profile_IDENTIFIER);
18039 -- profile_IDENTIFIER => Restricted | Ravenscar
18041 when Pragma_Profile_Warnings =>
18042 GNAT_Pragma;
18043 Check_Arg_Count (1);
18044 Check_Valid_Configuration_Pragma;
18045 Check_No_Identifiers;
18047 declare
18048 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
18050 begin
18051 if Chars (Argx) = Name_Ravenscar then
18052 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
18054 elsif Chars (Argx) = Name_Restricted then
18055 Set_Profile_Restrictions (Restricted, N, Warn => True);
18057 elsif Chars (Argx) = Name_No_Implementation_Extensions then
18058 Set_Profile_Restrictions
18059 (No_Implementation_Extensions, N, Warn => True);
18061 else
18062 Error_Pragma_Arg ("& is not a valid profile", Argx);
18063 end if;
18064 end;
18066 --------------------------
18067 -- Propagate_Exceptions --
18068 --------------------------
18070 -- pragma Propagate_Exceptions;
18072 -- Note: this pragma is obsolete and has no effect
18074 when Pragma_Propagate_Exceptions =>
18075 GNAT_Pragma;
18076 Check_Arg_Count (0);
18078 if Warn_On_Obsolescent_Feature then
18079 Error_Msg_N
18080 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
18081 "and has no effect?j?", N);
18082 end if;
18084 -----------------------------
18085 -- Provide_Shift_Operators --
18086 -----------------------------
18088 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
18090 when Pragma_Provide_Shift_Operators =>
18091 Provide_Shift_Operators : declare
18092 Ent : Entity_Id;
18094 procedure Declare_Shift_Operator (Nam : Name_Id);
18095 -- Insert declaration and pragma Instrinsic for named shift op
18097 ----------------------------
18098 -- Declare_Shift_Operator --
18099 ----------------------------
18101 procedure Declare_Shift_Operator (Nam : Name_Id) is
18102 Func : Node_Id;
18103 Import : Node_Id;
18105 begin
18106 Func :=
18107 Make_Subprogram_Declaration (Loc,
18108 Make_Function_Specification (Loc,
18109 Defining_Unit_Name =>
18110 Make_Defining_Identifier (Loc, Chars => Nam),
18112 Result_Definition =>
18113 Make_Identifier (Loc, Chars => Chars (Ent)),
18115 Parameter_Specifications => New_List (
18116 Make_Parameter_Specification (Loc,
18117 Defining_Identifier =>
18118 Make_Defining_Identifier (Loc, Name_Value),
18119 Parameter_Type =>
18120 Make_Identifier (Loc, Chars => Chars (Ent))),
18122 Make_Parameter_Specification (Loc,
18123 Defining_Identifier =>
18124 Make_Defining_Identifier (Loc, Name_Amount),
18125 Parameter_Type =>
18126 New_Occurrence_Of (Standard_Natural, Loc)))));
18128 Import :=
18129 Make_Pragma (Loc,
18130 Pragma_Identifier => Make_Identifier (Loc, Name_Import),
18131 Pragma_Argument_Associations => New_List (
18132 Make_Pragma_Argument_Association (Loc,
18133 Expression => Make_Identifier (Loc, Name_Intrinsic)),
18134 Make_Pragma_Argument_Association (Loc,
18135 Expression => Make_Identifier (Loc, Nam))));
18137 Insert_After (N, Import);
18138 Insert_After (N, Func);
18139 end Declare_Shift_Operator;
18141 -- Start of processing for Provide_Shift_Operators
18143 begin
18144 GNAT_Pragma;
18145 Check_Arg_Count (1);
18146 Check_Arg_Is_Local_Name (Arg1);
18148 Arg1 := Get_Pragma_Arg (Arg1);
18150 -- We must have an entity name
18152 if not Is_Entity_Name (Arg1) then
18153 Error_Pragma_Arg
18154 ("pragma % must apply to integer first subtype", Arg1);
18155 end if;
18157 -- If no Entity, means there was a prior error so ignore
18159 if Present (Entity (Arg1)) then
18160 Ent := Entity (Arg1);
18162 -- Apply error checks
18164 if not Is_First_Subtype (Ent) then
18165 Error_Pragma_Arg
18166 ("cannot apply pragma %",
18167 "\& is not a first subtype",
18168 Arg1);
18170 elsif not Is_Integer_Type (Ent) then
18171 Error_Pragma_Arg
18172 ("cannot apply pragma %",
18173 "\& is not an integer type",
18174 Arg1);
18176 elsif Has_Shift_Operator (Ent) then
18177 Error_Pragma_Arg
18178 ("cannot apply pragma %",
18179 "\& already has declared shift operators",
18180 Arg1);
18182 elsif Is_Frozen (Ent) then
18183 Error_Pragma_Arg
18184 ("pragma % appears too late",
18185 "\& is already frozen",
18186 Arg1);
18187 end if;
18189 -- Now declare the operators. We do this during analysis rather
18190 -- than expansion, since we want the operators available if we
18191 -- are operating in -gnatc or ASIS mode.
18193 Declare_Shift_Operator (Name_Rotate_Left);
18194 Declare_Shift_Operator (Name_Rotate_Right);
18195 Declare_Shift_Operator (Name_Shift_Left);
18196 Declare_Shift_Operator (Name_Shift_Right);
18197 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
18198 end if;
18199 end Provide_Shift_Operators;
18201 ------------------
18202 -- Psect_Object --
18203 ------------------
18205 -- pragma Psect_Object (
18206 -- [Internal =>] LOCAL_NAME,
18207 -- [, [External =>] EXTERNAL_SYMBOL]
18208 -- [, [Size =>] EXTERNAL_SYMBOL]);
18210 when Pragma_Psect_Object | Pragma_Common_Object =>
18211 Psect_Object : declare
18212 Args : Args_List (1 .. 3);
18213 Names : constant Name_List (1 .. 3) := (
18214 Name_Internal,
18215 Name_External,
18216 Name_Size);
18218 Internal : Node_Id renames Args (1);
18219 External : Node_Id renames Args (2);
18220 Size : Node_Id renames Args (3);
18222 Def_Id : Entity_Id;
18224 procedure Check_Arg (Arg : Node_Id);
18225 -- Checks that argument is either a string literal or an
18226 -- identifier, and posts error message if not.
18228 ---------------
18229 -- Check_Arg --
18230 ---------------
18232 procedure Check_Arg (Arg : Node_Id) is
18233 begin
18234 if not Nkind_In (Original_Node (Arg),
18235 N_String_Literal,
18236 N_Identifier)
18237 then
18238 Error_Pragma_Arg
18239 ("inappropriate argument for pragma %", Arg);
18240 end if;
18241 end Check_Arg;
18243 -- Start of processing for Common_Object/Psect_Object
18245 begin
18246 GNAT_Pragma;
18247 Gather_Associations (Names, Args);
18248 Process_Extended_Import_Export_Internal_Arg (Internal);
18250 Def_Id := Entity (Internal);
18252 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
18253 Error_Pragma_Arg
18254 ("pragma% must designate an object", Internal);
18255 end if;
18257 Check_Arg (Internal);
18259 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
18260 Error_Pragma_Arg
18261 ("cannot use pragma% for imported/exported object",
18262 Internal);
18263 end if;
18265 if Is_Concurrent_Type (Etype (Internal)) then
18266 Error_Pragma_Arg
18267 ("cannot specify pragma % for task/protected object",
18268 Internal);
18269 end if;
18271 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
18272 or else
18273 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
18274 then
18275 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
18276 end if;
18278 if Ekind (Def_Id) = E_Constant then
18279 Error_Pragma_Arg
18280 ("cannot specify pragma % for a constant", Internal);
18281 end if;
18283 if Is_Record_Type (Etype (Internal)) then
18284 declare
18285 Ent : Entity_Id;
18286 Decl : Entity_Id;
18288 begin
18289 Ent := First_Entity (Etype (Internal));
18290 while Present (Ent) loop
18291 Decl := Declaration_Node (Ent);
18293 if Ekind (Ent) = E_Component
18294 and then Nkind (Decl) = N_Component_Declaration
18295 and then Present (Expression (Decl))
18296 and then Warn_On_Export_Import
18297 then
18298 Error_Msg_N
18299 ("?x?object for pragma % has defaults", Internal);
18300 exit;
18302 else
18303 Next_Entity (Ent);
18304 end if;
18305 end loop;
18306 end;
18307 end if;
18309 if Present (Size) then
18310 Check_Arg (Size);
18311 end if;
18313 if Present (External) then
18314 Check_Arg_Is_External_Name (External);
18315 end if;
18317 -- If all error tests pass, link pragma on to the rep item chain
18319 Record_Rep_Item (Def_Id, N);
18320 end Psect_Object;
18322 ----------
18323 -- Pure --
18324 ----------
18326 -- pragma Pure [(library_unit_NAME)];
18328 when Pragma_Pure => Pure : declare
18329 Ent : Entity_Id;
18331 begin
18332 Check_Ada_83_Warning;
18333 Check_Valid_Library_Unit_Pragma;
18335 if Nkind (N) = N_Null_Statement then
18336 return;
18337 end if;
18339 Ent := Find_Lib_Unit_Name;
18340 Set_Is_Pure (Ent);
18341 Set_Has_Pragma_Pure (Ent);
18342 Set_Suppress_Elaboration_Warnings (Ent);
18343 end Pure;
18345 -------------------
18346 -- Pure_Function --
18347 -------------------
18349 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
18351 when Pragma_Pure_Function => Pure_Function : declare
18352 E_Id : Node_Id;
18353 E : Entity_Id;
18354 Def_Id : Entity_Id;
18355 Effective : Boolean := False;
18357 begin
18358 GNAT_Pragma;
18359 Check_Arg_Count (1);
18360 Check_Optional_Identifier (Arg1, Name_Entity);
18361 Check_Arg_Is_Local_Name (Arg1);
18362 E_Id := Get_Pragma_Arg (Arg1);
18364 if Error_Posted (E_Id) then
18365 return;
18366 end if;
18368 -- Loop through homonyms (overloadings) of referenced entity
18370 E := Entity (E_Id);
18372 if Present (E) then
18373 loop
18374 Def_Id := Get_Base_Subprogram (E);
18376 if not Ekind_In (Def_Id, E_Function,
18377 E_Generic_Function,
18378 E_Operator)
18379 then
18380 Error_Pragma_Arg
18381 ("pragma% requires a function name", Arg1);
18382 end if;
18384 Set_Is_Pure (Def_Id);
18386 if not Has_Pragma_Pure_Function (Def_Id) then
18387 Set_Has_Pragma_Pure_Function (Def_Id);
18388 Effective := True;
18389 end if;
18391 exit when From_Aspect_Specification (N);
18392 E := Homonym (E);
18393 exit when No (E) or else Scope (E) /= Current_Scope;
18394 end loop;
18396 if not Effective
18397 and then Warn_On_Redundant_Constructs
18398 then
18399 Error_Msg_NE
18400 ("pragma Pure_Function on& is redundant?r?",
18401 N, Entity (E_Id));
18402 end if;
18403 end if;
18404 end Pure_Function;
18406 --------------------
18407 -- Queuing_Policy --
18408 --------------------
18410 -- pragma Queuing_Policy (policy_IDENTIFIER);
18412 when Pragma_Queuing_Policy => declare
18413 QP : Character;
18415 begin
18416 Check_Ada_83_Warning;
18417 Check_Arg_Count (1);
18418 Check_No_Identifiers;
18419 Check_Arg_Is_Queuing_Policy (Arg1);
18420 Check_Valid_Configuration_Pragma;
18421 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
18422 QP := Fold_Upper (Name_Buffer (1));
18424 if Queuing_Policy /= ' '
18425 and then Queuing_Policy /= QP
18426 then
18427 Error_Msg_Sloc := Queuing_Policy_Sloc;
18428 Error_Pragma ("queuing policy incompatible with policy#");
18430 -- Set new policy, but always preserve System_Location since we
18431 -- like the error message with the run time name.
18433 else
18434 Queuing_Policy := QP;
18436 if Queuing_Policy_Sloc /= System_Location then
18437 Queuing_Policy_Sloc := Loc;
18438 end if;
18439 end if;
18440 end;
18442 --------------
18443 -- Rational --
18444 --------------
18446 -- pragma Rational, for compatibility with foreign compiler
18448 when Pragma_Rational =>
18449 Set_Rational_Profile;
18451 ------------------------------------
18452 -- Refined_Depends/Refined_Global --
18453 ------------------------------------
18455 -- pragma Refined_Depends (DEPENDENCY_RELATION);
18457 -- DEPENDENCY_RELATION ::=
18458 -- null
18459 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
18461 -- DEPENDENCY_CLAUSE ::=
18462 -- OUTPUT_LIST =>[+] INPUT_LIST
18463 -- | NULL_DEPENDENCY_CLAUSE
18465 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
18467 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
18469 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
18471 -- OUTPUT ::= NAME | FUNCTION_RESULT
18472 -- INPUT ::= NAME
18474 -- where FUNCTION_RESULT is a function Result attribute_reference
18476 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
18478 -- GLOBAL_SPECIFICATION ::=
18479 -- null
18480 -- | GLOBAL_LIST
18481 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
18483 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
18485 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
18486 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
18487 -- GLOBAL_ITEM ::= NAME
18489 when Pragma_Refined_Depends |
18490 Pragma_Refined_Global => Refined_Depends_Global :
18491 declare
18492 Body_Id : Entity_Id;
18493 Legal : Boolean;
18494 Spec_Id : Entity_Id;
18496 begin
18497 Analyze_Refined_Pragma (Spec_Id, Body_Id, Legal);
18499 -- Save the pragma in the contract of the subprogram body. The
18500 -- remaining analysis is performed at the end of the enclosing
18501 -- declarations.
18503 if Legal then
18504 Add_Contract_Item (N, Body_Id);
18505 end if;
18506 end Refined_Depends_Global;
18508 ------------------
18509 -- Refined_Post --
18510 ------------------
18512 -- pragma Refined_Post (boolean_EXPRESSION);
18514 when Pragma_Refined_Post => Refined_Post : declare
18515 Body_Id : Entity_Id;
18516 Legal : Boolean;
18517 Spec_Id : Entity_Id;
18519 begin
18520 Analyze_Refined_Pragma (Spec_Id, Body_Id, Legal);
18522 -- Fully analyze the pragma when it appears inside a subprogram
18523 -- body because it cannot benefit from forward references.
18525 if Legal then
18526 Analyze_Pre_Post_Condition_In_Decl_Part (N);
18528 -- Currently it is not possible to inline pre/postconditions on
18529 -- a subprogram subject to pragma Inline_Always.
18531 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
18533 -- Chain the pragma on the contract for easy retrieval
18535 Add_Contract_Item (N, Body_Id);
18536 end if;
18537 end Refined_Post;
18539 -------------------
18540 -- Refined_State --
18541 -------------------
18543 -- pragma Refined_State (REFINEMENT_LIST);
18545 -- REFINEMENT_LIST ::=
18546 -- REFINEMENT_CLAUSE
18547 -- | (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
18549 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
18551 -- CONSTITUENT_LIST ::=
18552 -- null
18553 -- | CONSTITUENT
18554 -- | (CONSTITUENT {, CONSTITUENT})
18556 -- CONSTITUENT ::= object_NAME | state_NAME
18558 when Pragma_Refined_State => Refined_State : declare
18559 Pack_Decl : Node_Id;
18560 Spec_Id : Entity_Id;
18562 begin
18563 GNAT_Pragma;
18564 Check_No_Identifiers;
18565 Check_Arg_Count (1);
18567 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
18569 -- Ensure the proper placement of the pragma. Refined states must
18570 -- be associated with a package body.
18572 if Nkind (Pack_Decl) = N_Package_Body then
18573 null;
18575 -- Otherwise the pragma is associated with an illegal construct
18577 else
18578 Pragma_Misplaced;
18579 return;
18580 end if;
18582 Spec_Id := Corresponding_Spec (Pack_Decl);
18584 -- State refinement is allowed only when the corresponding package
18585 -- declaration has non-null pragma Abstract_State. Refinement not
18586 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
18588 if SPARK_Mode /= Off
18589 and then
18590 (No (Abstract_States (Spec_Id))
18591 or else Has_Null_Abstract_State (Spec_Id))
18592 then
18593 Error_Msg_NE
18594 ("useless refinement, package & does not define abstract "
18595 & "states", N, Spec_Id);
18596 return;
18597 end if;
18599 -- The pragma must be analyzed at the end of the declarations as
18600 -- it has visibility over the whole declarative region. Save the
18601 -- pragma for later (see Analyze_Refined_State_In_Decl_Part) by
18602 -- adding it to the contract of the package body.
18604 Add_Contract_Item (N, Defining_Entity (Pack_Decl));
18605 end Refined_State;
18607 -----------------------
18608 -- Relative_Deadline --
18609 -----------------------
18611 -- pragma Relative_Deadline (time_span_EXPRESSION);
18613 when Pragma_Relative_Deadline => Relative_Deadline : declare
18614 P : constant Node_Id := Parent (N);
18615 Arg : Node_Id;
18617 begin
18618 Ada_2005_Pragma;
18619 Check_No_Identifiers;
18620 Check_Arg_Count (1);
18622 Arg := Get_Pragma_Arg (Arg1);
18624 -- The expression must be analyzed in the special manner described
18625 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
18627 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
18629 -- Subprogram case
18631 if Nkind (P) = N_Subprogram_Body then
18632 Check_In_Main_Program;
18634 -- Only Task and subprogram cases allowed
18636 elsif Nkind (P) /= N_Task_Definition then
18637 Pragma_Misplaced;
18638 end if;
18640 -- Check duplicate pragma before we set the corresponding flag
18642 if Has_Relative_Deadline_Pragma (P) then
18643 Error_Pragma ("duplicate pragma% not allowed");
18644 end if;
18646 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
18647 -- Relative_Deadline pragma node cannot be inserted in the Rep
18648 -- Item chain of Ent since it is rewritten by the expander as a
18649 -- procedure call statement that will break the chain.
18651 Set_Has_Relative_Deadline_Pragma (P, True);
18652 end Relative_Deadline;
18654 ------------------------
18655 -- Remote_Access_Type --
18656 ------------------------
18658 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
18660 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
18661 E : Entity_Id;
18663 begin
18664 GNAT_Pragma;
18665 Check_Arg_Count (1);
18666 Check_Optional_Identifier (Arg1, Name_Entity);
18667 Check_Arg_Is_Local_Name (Arg1);
18669 E := Entity (Get_Pragma_Arg (Arg1));
18671 if Nkind (Parent (E)) = N_Formal_Type_Declaration
18672 and then Ekind (E) = E_General_Access_Type
18673 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
18674 and then Scope (Root_Type (Directly_Designated_Type (E)))
18675 = Scope (E)
18676 and then Is_Valid_Remote_Object_Type
18677 (Root_Type (Directly_Designated_Type (E)))
18678 then
18679 Set_Is_Remote_Types (E);
18681 else
18682 Error_Pragma_Arg
18683 ("pragma% applies only to formal access to classwide types",
18684 Arg1);
18685 end if;
18686 end Remote_Access_Type;
18688 ---------------------------
18689 -- Remote_Call_Interface --
18690 ---------------------------
18692 -- pragma Remote_Call_Interface [(library_unit_NAME)];
18694 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
18695 Cunit_Node : Node_Id;
18696 Cunit_Ent : Entity_Id;
18697 K : Node_Kind;
18699 begin
18700 Check_Ada_83_Warning;
18701 Check_Valid_Library_Unit_Pragma;
18703 if Nkind (N) = N_Null_Statement then
18704 return;
18705 end if;
18707 Cunit_Node := Cunit (Current_Sem_Unit);
18708 K := Nkind (Unit (Cunit_Node));
18709 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
18711 if K = N_Package_Declaration
18712 or else K = N_Generic_Package_Declaration
18713 or else K = N_Subprogram_Declaration
18714 or else K = N_Generic_Subprogram_Declaration
18715 or else (K = N_Subprogram_Body
18716 and then Acts_As_Spec (Unit (Cunit_Node)))
18717 then
18718 null;
18719 else
18720 Error_Pragma (
18721 "pragma% must apply to package or subprogram declaration");
18722 end if;
18724 Set_Is_Remote_Call_Interface (Cunit_Ent);
18725 end Remote_Call_Interface;
18727 ------------------
18728 -- Remote_Types --
18729 ------------------
18731 -- pragma Remote_Types [(library_unit_NAME)];
18733 when Pragma_Remote_Types => Remote_Types : declare
18734 Cunit_Node : Node_Id;
18735 Cunit_Ent : Entity_Id;
18737 begin
18738 Check_Ada_83_Warning;
18739 Check_Valid_Library_Unit_Pragma;
18741 if Nkind (N) = N_Null_Statement then
18742 return;
18743 end if;
18745 Cunit_Node := Cunit (Current_Sem_Unit);
18746 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
18748 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
18749 N_Generic_Package_Declaration)
18750 then
18751 Error_Pragma
18752 ("pragma% can only apply to a package declaration");
18753 end if;
18755 Set_Is_Remote_Types (Cunit_Ent);
18756 end Remote_Types;
18758 ---------------
18759 -- Ravenscar --
18760 ---------------
18762 -- pragma Ravenscar;
18764 when Pragma_Ravenscar =>
18765 GNAT_Pragma;
18766 Check_Arg_Count (0);
18767 Check_Valid_Configuration_Pragma;
18768 Set_Ravenscar_Profile (N);
18770 if Warn_On_Obsolescent_Feature then
18771 Error_Msg_N
18772 ("pragma Ravenscar is an obsolescent feature?j?", N);
18773 Error_Msg_N
18774 ("|use pragma Profile (Ravenscar) instead?j?", N);
18775 end if;
18777 -------------------------
18778 -- Restricted_Run_Time --
18779 -------------------------
18781 -- pragma Restricted_Run_Time;
18783 when Pragma_Restricted_Run_Time =>
18784 GNAT_Pragma;
18785 Check_Arg_Count (0);
18786 Check_Valid_Configuration_Pragma;
18787 Set_Profile_Restrictions
18788 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
18790 if Warn_On_Obsolescent_Feature then
18791 Error_Msg_N
18792 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
18794 Error_Msg_N
18795 ("|use pragma Profile (Restricted) instead?j?", N);
18796 end if;
18798 ------------------
18799 -- Restrictions --
18800 ------------------
18802 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
18804 -- RESTRICTION ::=
18805 -- restriction_IDENTIFIER
18806 -- | restriction_parameter_IDENTIFIER => EXPRESSION
18808 when Pragma_Restrictions =>
18809 Process_Restrictions_Or_Restriction_Warnings
18810 (Warn => Treat_Restrictions_As_Warnings);
18812 --------------------------
18813 -- Restriction_Warnings --
18814 --------------------------
18816 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
18818 -- RESTRICTION ::=
18819 -- restriction_IDENTIFIER
18820 -- | restriction_parameter_IDENTIFIER => EXPRESSION
18822 when Pragma_Restriction_Warnings =>
18823 GNAT_Pragma;
18824 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
18826 ----------------
18827 -- Reviewable --
18828 ----------------
18830 -- pragma Reviewable;
18832 when Pragma_Reviewable =>
18833 Check_Ada_83_Warning;
18834 Check_Arg_Count (0);
18836 -- Call dummy debugging function rv. This is done to assist front
18837 -- end debugging. By placing a Reviewable pragma in the source
18838 -- program, a breakpoint on rv catches this place in the source,
18839 -- allowing convenient stepping to the point of interest.
18843 --------------------------
18844 -- Short_Circuit_And_Or --
18845 --------------------------
18847 -- pragma Short_Circuit_And_Or;
18849 when Pragma_Short_Circuit_And_Or =>
18850 GNAT_Pragma;
18851 Check_Arg_Count (0);
18852 Check_Valid_Configuration_Pragma;
18853 Short_Circuit_And_Or := True;
18855 -------------------
18856 -- Share_Generic --
18857 -------------------
18859 -- pragma Share_Generic (GNAME {, GNAME});
18861 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
18863 when Pragma_Share_Generic =>
18864 GNAT_Pragma;
18865 Process_Generic_List;
18867 ------------
18868 -- Shared --
18869 ------------
18871 -- pragma Shared (LOCAL_NAME);
18873 when Pragma_Shared =>
18874 GNAT_Pragma;
18875 Process_Atomic_Independent_Shared_Volatile;
18877 --------------------
18878 -- Shared_Passive --
18879 --------------------
18881 -- pragma Shared_Passive [(library_unit_NAME)];
18883 -- Set the flag Is_Shared_Passive of program unit name entity
18885 when Pragma_Shared_Passive => Shared_Passive : declare
18886 Cunit_Node : Node_Id;
18887 Cunit_Ent : Entity_Id;
18889 begin
18890 Check_Ada_83_Warning;
18891 Check_Valid_Library_Unit_Pragma;
18893 if Nkind (N) = N_Null_Statement then
18894 return;
18895 end if;
18897 Cunit_Node := Cunit (Current_Sem_Unit);
18898 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
18900 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
18901 N_Generic_Package_Declaration)
18902 then
18903 Error_Pragma
18904 ("pragma% can only apply to a package declaration");
18905 end if;
18907 Set_Is_Shared_Passive (Cunit_Ent);
18908 end Shared_Passive;
18910 -----------------------
18911 -- Short_Descriptors --
18912 -----------------------
18914 -- pragma Short_Descriptors;
18916 -- Recognize and validate, but otherwise ignore
18918 when Pragma_Short_Descriptors =>
18919 GNAT_Pragma;
18920 Check_Arg_Count (0);
18921 Check_Valid_Configuration_Pragma;
18923 ------------------------------
18924 -- Simple_Storage_Pool_Type --
18925 ------------------------------
18927 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
18929 when Pragma_Simple_Storage_Pool_Type =>
18930 Simple_Storage_Pool_Type : declare
18931 Type_Id : Node_Id;
18932 Typ : Entity_Id;
18934 begin
18935 GNAT_Pragma;
18936 Check_Arg_Count (1);
18937 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18939 Type_Id := Get_Pragma_Arg (Arg1);
18940 Find_Type (Type_Id);
18941 Typ := Entity (Type_Id);
18943 if Typ = Any_Type then
18944 return;
18945 end if;
18947 -- We require the pragma to apply to a type declared in a package
18948 -- declaration, but not (immediately) within a package body.
18950 if Ekind (Current_Scope) /= E_Package
18951 or else In_Package_Body (Current_Scope)
18952 then
18953 Error_Pragma
18954 ("pragma% can only apply to type declared immediately "
18955 & "within a package declaration");
18956 end if;
18958 -- A simple storage pool type must be an immutably limited record
18959 -- or private type. If the pragma is given for a private type,
18960 -- the full type is similarly restricted (which is checked later
18961 -- in Freeze_Entity).
18963 if Is_Record_Type (Typ)
18964 and then not Is_Limited_View (Typ)
18965 then
18966 Error_Pragma
18967 ("pragma% can only apply to explicitly limited record type");
18969 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
18970 Error_Pragma
18971 ("pragma% can only apply to a private type that is limited");
18973 elsif not Is_Record_Type (Typ)
18974 and then not Is_Private_Type (Typ)
18975 then
18976 Error_Pragma
18977 ("pragma% can only apply to limited record or private type");
18978 end if;
18980 Record_Rep_Item (Typ, N);
18981 end Simple_Storage_Pool_Type;
18983 ----------------------
18984 -- Source_File_Name --
18985 ----------------------
18987 -- There are five forms for this pragma:
18989 -- pragma Source_File_Name (
18990 -- [UNIT_NAME =>] unit_NAME,
18991 -- BODY_FILE_NAME => STRING_LITERAL
18992 -- [, [INDEX =>] INTEGER_LITERAL]);
18994 -- pragma Source_File_Name (
18995 -- [UNIT_NAME =>] unit_NAME,
18996 -- SPEC_FILE_NAME => STRING_LITERAL
18997 -- [, [INDEX =>] INTEGER_LITERAL]);
18999 -- pragma Source_File_Name (
19000 -- BODY_FILE_NAME => STRING_LITERAL
19001 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19002 -- [, CASING => CASING_SPEC]);
19004 -- pragma Source_File_Name (
19005 -- SPEC_FILE_NAME => STRING_LITERAL
19006 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19007 -- [, CASING => CASING_SPEC]);
19009 -- pragma Source_File_Name (
19010 -- SUBUNIT_FILE_NAME => STRING_LITERAL
19011 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19012 -- [, CASING => CASING_SPEC]);
19014 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
19016 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
19017 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
19018 -- only be used when no project file is used, while SFNP can only be
19019 -- used when a project file is used.
19021 -- No processing here. Processing was completed during parsing, since
19022 -- we need to have file names set as early as possible. Units are
19023 -- loaded well before semantic processing starts.
19025 -- The only processing we defer to this point is the check for
19026 -- correct placement.
19028 when Pragma_Source_File_Name =>
19029 GNAT_Pragma;
19030 Check_Valid_Configuration_Pragma;
19032 ------------------------------
19033 -- Source_File_Name_Project --
19034 ------------------------------
19036 -- See Source_File_Name for syntax
19038 -- No processing here. Processing was completed during parsing, since
19039 -- we need to have file names set as early as possible. Units are
19040 -- loaded well before semantic processing starts.
19042 -- The only processing we defer to this point is the check for
19043 -- correct placement.
19045 when Pragma_Source_File_Name_Project =>
19046 GNAT_Pragma;
19047 Check_Valid_Configuration_Pragma;
19049 -- Check that a pragma Source_File_Name_Project is used only in a
19050 -- configuration pragmas file.
19052 -- Pragmas Source_File_Name_Project should only be generated by
19053 -- the Project Manager in configuration pragmas files.
19055 -- This is really an ugly test. It seems to depend on some
19056 -- accidental and undocumented property. At the very least it
19057 -- needs to be documented, but it would be better to have a
19058 -- clean way of testing if we are in a configuration file???
19060 if Present (Parent (N)) then
19061 Error_Pragma
19062 ("pragma% can only appear in a configuration pragmas file");
19063 end if;
19065 ----------------------
19066 -- Source_Reference --
19067 ----------------------
19069 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
19071 -- Nothing to do, all processing completed in Par.Prag, since we need
19072 -- the information for possible parser messages that are output.
19074 when Pragma_Source_Reference =>
19075 GNAT_Pragma;
19077 ----------------
19078 -- SPARK_Mode --
19079 ----------------
19081 -- pragma SPARK_Mode [(On | Off)];
19083 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
19084 Mode_Id : SPARK_Mode_Type;
19086 procedure Check_Pragma_Conformance
19087 (Context_Pragma : Node_Id;
19088 Entity_Pragma : Node_Id;
19089 Entity : Entity_Id);
19090 -- If Context_Pragma is not Empty, verify that the new pragma N
19091 -- is compatible with the pragma Context_Pragma that was inherited
19092 -- from the context:
19093 -- . if Context_Pragma is ON, then the new mode can be anything
19094 -- . if Context_Pragma is OFF, then the only allowed new mode is
19095 -- also OFF.
19097 -- If Entity is not Empty, verify that the new pragma N is
19098 -- compatible with Entity_Pragma, the SPARK_Mode previously set
19099 -- for Entity (which may be Empty):
19100 -- . if Entity_Pragma is ON, then the new mode can be anything
19101 -- . if Entity_Pragma is OFF, then the only allowed new mode is
19102 -- also OFF.
19103 -- . if Entity_Pragma is Empty, we always issue an error, as this
19104 -- corresponds to a case where a previous section of Entity
19105 -- had no SPARK_Mode set.
19107 procedure Check_Library_Level_Entity (E : Entity_Id);
19108 -- Verify that pragma is applied to library-level entity E
19110 procedure Set_SPARK_Flags;
19111 -- Sets SPARK_Mode from Mode_Id and SPARK_Mode_Pragma from N,
19112 -- and ensures that Dynamic_Elaboration_Checks are off if the
19113 -- call sets SPARK_Mode On.
19115 ------------------------------
19116 -- Check_Pragma_Conformance --
19117 ------------------------------
19119 procedure Check_Pragma_Conformance
19120 (Context_Pragma : Node_Id;
19121 Entity_Pragma : Node_Id;
19122 Entity : Entity_Id)
19124 Arg : Node_Id := Arg1;
19126 begin
19127 -- The current pragma may appear without an argument. If this
19128 -- is the case, associate all error messages with the pragma
19129 -- itself.
19131 if No (Arg) then
19132 Arg := N;
19133 end if;
19135 -- The mode of the current pragma is compared against that of
19136 -- an enclosing context.
19138 if Present (Context_Pragma) then
19139 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
19141 -- Issue an error if the new mode is less restrictive than
19142 -- that of the context.
19144 if Get_SPARK_Mode_From_Pragma (Context_Pragma) = Off
19145 and then Get_SPARK_Mode_From_Pragma (N) = On
19146 then
19147 Error_Msg_N
19148 ("cannot change SPARK_Mode from Off to On", Arg);
19149 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
19150 Error_Msg_N ("\SPARK_Mode was set to Off#", Arg);
19151 raise Pragma_Exit;
19152 end if;
19153 end if;
19155 -- The mode of the current pragma is compared against that of
19156 -- an initial package/subprogram declaration.
19158 if Present (Entity) then
19160 -- Both the initial declaration and the completion carry
19161 -- SPARK_Mode pragmas.
19163 if Present (Entity_Pragma) then
19164 pragma Assert (Nkind (Entity_Pragma) = N_Pragma);
19166 -- Issue an error if the new mode is less restrictive
19167 -- than that of the initial declaration.
19169 if Get_SPARK_Mode_From_Pragma (Entity_Pragma) = Off
19170 and then Get_SPARK_Mode_From_Pragma (N) = On
19171 then
19172 Error_Msg_N ("incorrect use of SPARK_Mode", Arg);
19173 Error_Msg_Sloc := Sloc (Entity_Pragma);
19174 Error_Msg_NE
19175 ("\value Off was set for SPARK_Mode on&#",
19176 Arg, Entity);
19177 raise Pragma_Exit;
19178 end if;
19180 -- Otherwise the initial declaration lacks a SPARK_Mode
19181 -- pragma in which case the current pragma is illegal as
19182 -- it cannot "complete".
19184 else
19185 Error_Msg_N ("incorrect use of SPARK_Mode", Arg);
19186 Error_Msg_Sloc := Sloc (Entity);
19187 Error_Msg_NE
19188 ("\no value was set for SPARK_Mode on&#",
19189 Arg, Entity);
19190 raise Pragma_Exit;
19191 end if;
19192 end if;
19193 end Check_Pragma_Conformance;
19195 --------------------------------
19196 -- Check_Library_Level_Entity --
19197 --------------------------------
19199 procedure Check_Library_Level_Entity (E : Entity_Id) is
19200 MsgF : constant String := "incorrect placement of pragma%";
19202 begin
19203 if not Is_Library_Level_Entity (E) then
19204 Error_Msg_Name_1 := Pname;
19205 Error_Msg_N (Fix_Error (MsgF), N);
19207 if Ekind_In (E, E_Generic_Package,
19208 E_Package,
19209 E_Package_Body)
19210 then
19211 Error_Msg_NE
19212 ("\& is not a library-level package", N, E);
19213 else
19214 Error_Msg_NE
19215 ("\& is not a library-level subprogram", N, E);
19216 end if;
19218 raise Pragma_Exit;
19219 end if;
19220 end Check_Library_Level_Entity;
19222 ---------------------
19223 -- Set_SPARK_Flags --
19224 ---------------------
19226 procedure Set_SPARK_Flags is
19227 begin
19228 SPARK_Mode := Mode_Id;
19229 SPARK_Mode_Pragma := N;
19231 if SPARK_Mode = On then
19232 Dynamic_Elaboration_Checks := False;
19233 end if;
19234 end Set_SPARK_Flags;
19236 -- Local variables
19238 Body_Id : Entity_Id;
19239 Context : Node_Id;
19240 Mode : Name_Id;
19241 Spec_Id : Entity_Id;
19242 Stmt : Node_Id;
19244 -- Start of processing for Do_SPARK_Mode
19246 begin
19247 -- When a SPARK_Mode pragma appears inside an instantiation whose
19248 -- enclosing context has SPARK_Mode set to "off", the pragma has
19249 -- no semantic effect.
19251 if Ignore_Pragma_SPARK_Mode then
19252 Rewrite (N, Make_Null_Statement (Loc));
19253 Analyze (N);
19254 return;
19255 end if;
19257 GNAT_Pragma;
19258 Check_No_Identifiers;
19259 Check_At_Most_N_Arguments (1);
19261 -- Check the legality of the mode (no argument = ON)
19263 if Arg_Count = 1 then
19264 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
19265 Mode := Chars (Get_Pragma_Arg (Arg1));
19266 else
19267 Mode := Name_On;
19268 end if;
19270 Mode_Id := Get_SPARK_Mode_Type (Mode);
19271 Context := Parent (N);
19273 -- The pragma appears in a configuration pragmas file
19275 if No (Context) then
19276 Check_Valid_Configuration_Pragma;
19278 if Present (SPARK_Mode_Pragma) then
19279 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
19280 Error_Msg_N ("pragma% duplicates pragma declared#", N);
19281 raise Pragma_Exit;
19282 end if;
19284 Set_SPARK_Flags;
19286 -- The pragma acts as a configuration pragma in a compilation unit
19288 -- pragma SPARK_Mode ...;
19289 -- package Pack is ...;
19291 elsif Nkind (Context) = N_Compilation_Unit
19292 and then List_Containing (N) = Context_Items (Context)
19293 then
19294 Check_Valid_Configuration_Pragma;
19295 Set_SPARK_Flags;
19297 -- Otherwise the placement of the pragma within the tree dictates
19298 -- its associated construct. Inspect the declarative list where
19299 -- the pragma resides to find a potential construct.
19301 else
19302 Stmt := Prev (N);
19303 while Present (Stmt) loop
19305 -- Skip prior pragmas, but check for duplicates
19307 if Nkind (Stmt) = N_Pragma then
19308 if Pragma_Name (Stmt) = Pname then
19309 Error_Msg_Name_1 := Pname;
19310 Error_Msg_Sloc := Sloc (Stmt);
19311 Error_Msg_N ("pragma% duplicates pragma declared#", N);
19312 raise Pragma_Exit;
19313 end if;
19315 -- The pragma applies to a [generic] subprogram declaration.
19316 -- Note that this case covers an internally generated spec
19317 -- for a stand alone body.
19319 -- [generic]
19320 -- procedure Proc ...;
19321 -- pragma SPARK_Mode ..;
19323 elsif Nkind_In (Stmt, N_Generic_Subprogram_Declaration,
19324 N_Subprogram_Declaration)
19325 then
19326 Spec_Id := Defining_Entity (Stmt);
19327 Check_Library_Level_Entity (Spec_Id);
19328 Check_Pragma_Conformance
19329 (Context_Pragma => SPARK_Pragma (Spec_Id),
19330 Entity_Pragma => Empty,
19331 Entity => Empty);
19333 Set_SPARK_Pragma (Spec_Id, N);
19334 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19335 return;
19337 -- Skip internally generated code
19339 elsif not Comes_From_Source (Stmt) then
19340 null;
19342 -- Otherwise the pragma does not apply to a legal construct
19343 -- or it does not appear at the top of a declarative or a
19344 -- statement list. Issue an error and stop the analysis.
19346 else
19347 Pragma_Misplaced;
19348 exit;
19349 end if;
19351 Prev (Stmt);
19352 end loop;
19354 -- The pragma applies to a package or a subprogram that acts as
19355 -- a compilation unit.
19357 -- procedure Proc ...;
19358 -- pragma SPARK_Mode ...;
19360 if Nkind (Context) = N_Compilation_Unit_Aux then
19361 Context := Unit (Parent (Context));
19362 end if;
19364 -- The pragma appears within package declarations
19366 if Nkind (Context) = N_Package_Specification then
19367 Spec_Id := Defining_Entity (Context);
19368 Check_Library_Level_Entity (Spec_Id);
19370 -- The pragma is at the top of the visible declarations
19372 -- package Pack is
19373 -- pragma SPARK_Mode ...;
19375 if List_Containing (N) = Visible_Declarations (Context) then
19376 Check_Pragma_Conformance
19377 (Context_Pragma => SPARK_Pragma (Spec_Id),
19378 Entity_Pragma => Empty,
19379 Entity => Empty);
19380 Set_SPARK_Flags;
19382 Set_SPARK_Pragma (Spec_Id, N);
19383 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19384 Set_SPARK_Aux_Pragma (Spec_Id, N);
19385 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
19387 -- The pragma is at the top of the private declarations
19389 -- package Pack is
19390 -- private
19391 -- pragma SPARK_Mode ...;
19393 else
19394 Check_Pragma_Conformance
19395 (Context_Pragma => Empty,
19396 Entity_Pragma => SPARK_Pragma (Spec_Id),
19397 Entity => Spec_Id);
19398 Set_SPARK_Flags;
19400 Set_SPARK_Aux_Pragma (Spec_Id, N);
19401 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
19402 end if;
19404 -- The pragma appears at the top of package body declarations
19406 -- package body Pack is
19407 -- pragma SPARK_Mode ...;
19409 elsif Nkind (Context) = N_Package_Body then
19410 Spec_Id := Corresponding_Spec (Context);
19411 Body_Id := Defining_Entity (Context);
19412 Check_Library_Level_Entity (Body_Id);
19413 Check_Pragma_Conformance
19414 (Context_Pragma => SPARK_Pragma (Body_Id),
19415 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id),
19416 Entity => Spec_Id);
19417 Set_SPARK_Flags;
19419 Set_SPARK_Pragma (Body_Id, N);
19420 Set_SPARK_Pragma_Inherited (Body_Id, False);
19421 Set_SPARK_Aux_Pragma (Body_Id, N);
19422 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
19424 -- The pragma appears at the top of package body statements
19426 -- package body Pack is
19427 -- begin
19428 -- pragma SPARK_Mode;
19430 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
19431 and then Nkind (Parent (Context)) = N_Package_Body
19432 then
19433 Context := Parent (Context);
19434 Spec_Id := Corresponding_Spec (Context);
19435 Body_Id := Defining_Entity (Context);
19436 Check_Library_Level_Entity (Body_Id);
19437 Check_Pragma_Conformance
19438 (Context_Pragma => Empty,
19439 Entity_Pragma => SPARK_Pragma (Body_Id),
19440 Entity => Body_Id);
19441 Set_SPARK_Flags;
19443 Set_SPARK_Aux_Pragma (Body_Id, N);
19444 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
19446 -- The pragma appeared as an aspect of a [generic] subprogram
19447 -- declaration that acts as a compilation unit.
19449 -- [generic]
19450 -- procedure Proc ...;
19451 -- pragma SPARK_Mode ...;
19453 elsif Nkind_In (Context, N_Generic_Subprogram_Declaration,
19454 N_Subprogram_Declaration)
19455 then
19456 Spec_Id := Defining_Entity (Context);
19457 Check_Library_Level_Entity (Spec_Id);
19458 Check_Pragma_Conformance
19459 (Context_Pragma => SPARK_Pragma (Spec_Id),
19460 Entity_Pragma => Empty,
19461 Entity => Empty);
19463 Set_SPARK_Pragma (Spec_Id, N);
19464 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19466 -- The pragma appears at the top of subprogram body
19467 -- declarations.
19469 -- procedure Proc ... is
19470 -- pragma SPARK_Mode;
19472 elsif Nkind (Context) = N_Subprogram_Body then
19473 Spec_Id := Corresponding_Spec (Context);
19474 Context := Specification (Context);
19475 Body_Id := Defining_Entity (Context);
19477 -- Ignore pragma when applied to the special body created
19478 -- for inlining, recognized by its internal name _Parent.
19480 if Chars (Body_Id) = Name_uParent then
19481 return;
19482 end if;
19484 Check_Library_Level_Entity (Body_Id);
19486 -- The body is a completion of a previous declaration
19488 if Present (Spec_Id) then
19489 Check_Pragma_Conformance
19490 (Context_Pragma => SPARK_Pragma (Body_Id),
19491 Entity_Pragma => SPARK_Pragma (Spec_Id),
19492 Entity => Spec_Id);
19494 -- The body acts as spec
19496 else
19497 Check_Pragma_Conformance
19498 (Context_Pragma => SPARK_Pragma (Body_Id),
19499 Entity_Pragma => Empty,
19500 Entity => Empty);
19501 end if;
19503 Set_SPARK_Flags;
19505 Set_SPARK_Pragma (Body_Id, N);
19506 Set_SPARK_Pragma_Inherited (Body_Id, False);
19508 -- The pragma does not apply to a legal construct, issue error
19510 else
19511 Pragma_Misplaced;
19512 end if;
19513 end if;
19514 end Do_SPARK_Mode;
19516 --------------------------------
19517 -- Static_Elaboration_Desired --
19518 --------------------------------
19520 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
19522 when Pragma_Static_Elaboration_Desired =>
19523 GNAT_Pragma;
19524 Check_At_Most_N_Arguments (1);
19526 if Is_Compilation_Unit (Current_Scope)
19527 and then Ekind (Current_Scope) = E_Package
19528 then
19529 Set_Static_Elaboration_Desired (Current_Scope, True);
19530 else
19531 Error_Pragma ("pragma% must apply to a library-level package");
19532 end if;
19534 ------------------
19535 -- Storage_Size --
19536 ------------------
19538 -- pragma Storage_Size (EXPRESSION);
19540 when Pragma_Storage_Size => Storage_Size : declare
19541 P : constant Node_Id := Parent (N);
19542 Arg : Node_Id;
19544 begin
19545 Check_No_Identifiers;
19546 Check_Arg_Count (1);
19548 -- The expression must be analyzed in the special manner described
19549 -- in "Handling of Default Expressions" in sem.ads.
19551 Arg := Get_Pragma_Arg (Arg1);
19552 Preanalyze_Spec_Expression (Arg, Any_Integer);
19554 if not Is_OK_Static_Expression (Arg) then
19555 Check_Restriction (Static_Storage_Size, Arg);
19556 end if;
19558 if Nkind (P) /= N_Task_Definition then
19559 Pragma_Misplaced;
19560 return;
19562 else
19563 if Has_Storage_Size_Pragma (P) then
19564 Error_Pragma ("duplicate pragma% not allowed");
19565 else
19566 Set_Has_Storage_Size_Pragma (P, True);
19567 end if;
19569 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
19570 end if;
19571 end Storage_Size;
19573 ------------------
19574 -- Storage_Unit --
19575 ------------------
19577 -- pragma Storage_Unit (NUMERIC_LITERAL);
19579 -- Only permitted argument is System'Storage_Unit value
19581 when Pragma_Storage_Unit =>
19582 Check_No_Identifiers;
19583 Check_Arg_Count (1);
19584 Check_Arg_Is_Integer_Literal (Arg1);
19586 if Intval (Get_Pragma_Arg (Arg1)) /=
19587 UI_From_Int (Ttypes.System_Storage_Unit)
19588 then
19589 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
19590 Error_Pragma_Arg
19591 ("the only allowed argument for pragma% is ^", Arg1);
19592 end if;
19594 --------------------
19595 -- Stream_Convert --
19596 --------------------
19598 -- pragma Stream_Convert (
19599 -- [Entity =>] type_LOCAL_NAME,
19600 -- [Read =>] function_NAME,
19601 -- [Write =>] function NAME);
19603 when Pragma_Stream_Convert => Stream_Convert : declare
19605 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
19606 -- Check that the given argument is the name of a local function
19607 -- of one argument that is not overloaded earlier in the current
19608 -- local scope. A check is also made that the argument is a
19609 -- function with one parameter.
19611 --------------------------------------
19612 -- Check_OK_Stream_Convert_Function --
19613 --------------------------------------
19615 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
19616 Ent : Entity_Id;
19618 begin
19619 Check_Arg_Is_Local_Name (Arg);
19620 Ent := Entity (Get_Pragma_Arg (Arg));
19622 if Has_Homonym (Ent) then
19623 Error_Pragma_Arg
19624 ("argument for pragma% may not be overloaded", Arg);
19625 end if;
19627 if Ekind (Ent) /= E_Function
19628 or else No (First_Formal (Ent))
19629 or else Present (Next_Formal (First_Formal (Ent)))
19630 then
19631 Error_Pragma_Arg
19632 ("argument for pragma% must be function of one argument",
19633 Arg);
19634 end if;
19635 end Check_OK_Stream_Convert_Function;
19637 -- Start of processing for Stream_Convert
19639 begin
19640 GNAT_Pragma;
19641 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
19642 Check_Arg_Count (3);
19643 Check_Optional_Identifier (Arg1, Name_Entity);
19644 Check_Optional_Identifier (Arg2, Name_Read);
19645 Check_Optional_Identifier (Arg3, Name_Write);
19646 Check_Arg_Is_Local_Name (Arg1);
19647 Check_OK_Stream_Convert_Function (Arg2);
19648 Check_OK_Stream_Convert_Function (Arg3);
19650 declare
19651 Typ : constant Entity_Id :=
19652 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
19653 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
19654 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
19656 begin
19657 Check_First_Subtype (Arg1);
19659 -- Check for too early or too late. Note that we don't enforce
19660 -- the rule about primitive operations in this case, since, as
19661 -- is the case for explicit stream attributes themselves, these
19662 -- restrictions are not appropriate. Note that the chaining of
19663 -- the pragma by Rep_Item_Too_Late is actually the critical
19664 -- processing done for this pragma.
19666 if Rep_Item_Too_Early (Typ, N)
19667 or else
19668 Rep_Item_Too_Late (Typ, N, FOnly => True)
19669 then
19670 return;
19671 end if;
19673 -- Return if previous error
19675 if Etype (Typ) = Any_Type
19676 or else
19677 Etype (Read) = Any_Type
19678 or else
19679 Etype (Write) = Any_Type
19680 then
19681 return;
19682 end if;
19684 -- Error checks
19686 if Underlying_Type (Etype (Read)) /= Typ then
19687 Error_Pragma_Arg
19688 ("incorrect return type for function&", Arg2);
19689 end if;
19691 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
19692 Error_Pragma_Arg
19693 ("incorrect parameter type for function&", Arg3);
19694 end if;
19696 if Underlying_Type (Etype (First_Formal (Read))) /=
19697 Underlying_Type (Etype (Write))
19698 then
19699 Error_Pragma_Arg
19700 ("result type of & does not match Read parameter type",
19701 Arg3);
19702 end if;
19703 end;
19704 end Stream_Convert;
19706 ------------------
19707 -- Style_Checks --
19708 ------------------
19710 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
19712 -- This is processed by the parser since some of the style checks
19713 -- take place during source scanning and parsing. This means that
19714 -- we don't need to issue error messages here.
19716 when Pragma_Style_Checks => Style_Checks : declare
19717 A : constant Node_Id := Get_Pragma_Arg (Arg1);
19718 S : String_Id;
19719 C : Char_Code;
19721 begin
19722 GNAT_Pragma;
19723 Check_No_Identifiers;
19725 -- Two argument form
19727 if Arg_Count = 2 then
19728 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
19730 declare
19731 E_Id : Node_Id;
19732 E : Entity_Id;
19734 begin
19735 E_Id := Get_Pragma_Arg (Arg2);
19736 Analyze (E_Id);
19738 if not Is_Entity_Name (E_Id) then
19739 Error_Pragma_Arg
19740 ("second argument of pragma% must be entity name",
19741 Arg2);
19742 end if;
19744 E := Entity (E_Id);
19746 if not Ignore_Style_Checks_Pragmas then
19747 if E = Any_Id then
19748 return;
19749 else
19750 loop
19751 Set_Suppress_Style_Checks
19752 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
19753 exit when No (Homonym (E));
19754 E := Homonym (E);
19755 end loop;
19756 end if;
19757 end if;
19758 end;
19760 -- One argument form
19762 else
19763 Check_Arg_Count (1);
19765 if Nkind (A) = N_String_Literal then
19766 S := Strval (A);
19768 declare
19769 Slen : constant Natural := Natural (String_Length (S));
19770 Options : String (1 .. Slen);
19771 J : Natural;
19773 begin
19774 J := 1;
19775 loop
19776 C := Get_String_Char (S, Int (J));
19777 exit when not In_Character_Range (C);
19778 Options (J) := Get_Character (C);
19780 -- If at end of string, set options. As per discussion
19781 -- above, no need to check for errors, since we issued
19782 -- them in the parser.
19784 if J = Slen then
19785 if not Ignore_Style_Checks_Pragmas then
19786 Set_Style_Check_Options (Options);
19787 end if;
19789 exit;
19790 end if;
19792 J := J + 1;
19793 end loop;
19794 end;
19796 elsif Nkind (A) = N_Identifier then
19797 if Chars (A) = Name_All_Checks then
19798 if not Ignore_Style_Checks_Pragmas then
19799 if GNAT_Mode then
19800 Set_GNAT_Style_Check_Options;
19801 else
19802 Set_Default_Style_Check_Options;
19803 end if;
19804 end if;
19806 elsif Chars (A) = Name_On then
19807 if not Ignore_Style_Checks_Pragmas then
19808 Style_Check := True;
19809 end if;
19811 elsif Chars (A) = Name_Off then
19812 if not Ignore_Style_Checks_Pragmas then
19813 Style_Check := False;
19814 end if;
19815 end if;
19816 end if;
19817 end if;
19818 end Style_Checks;
19820 --------------
19821 -- Subtitle --
19822 --------------
19824 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
19826 when Pragma_Subtitle =>
19827 GNAT_Pragma;
19828 Check_Arg_Count (1);
19829 Check_Optional_Identifier (Arg1, Name_Subtitle);
19830 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
19831 Store_Note (N);
19833 --------------
19834 -- Suppress --
19835 --------------
19837 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
19839 when Pragma_Suppress =>
19840 Process_Suppress_Unsuppress (Suppress_Case => True);
19842 ------------------
19843 -- Suppress_All --
19844 ------------------
19846 -- pragma Suppress_All;
19848 -- The only check made here is that the pragma has no arguments.
19849 -- There are no placement rules, and the processing required (setting
19850 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
19851 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
19852 -- then creates and inserts a pragma Suppress (All_Checks).
19854 when Pragma_Suppress_All =>
19855 GNAT_Pragma;
19856 Check_Arg_Count (0);
19858 -------------------------
19859 -- Suppress_Debug_Info --
19860 -------------------------
19862 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
19864 when Pragma_Suppress_Debug_Info =>
19865 GNAT_Pragma;
19866 Check_Arg_Count (1);
19867 Check_Optional_Identifier (Arg1, Name_Entity);
19868 Check_Arg_Is_Local_Name (Arg1);
19869 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
19871 ----------------------------------
19872 -- Suppress_Exception_Locations --
19873 ----------------------------------
19875 -- pragma Suppress_Exception_Locations;
19877 when Pragma_Suppress_Exception_Locations =>
19878 GNAT_Pragma;
19879 Check_Arg_Count (0);
19880 Check_Valid_Configuration_Pragma;
19881 Exception_Locations_Suppressed := True;
19883 -----------------------------
19884 -- Suppress_Initialization --
19885 -----------------------------
19887 -- pragma Suppress_Initialization ([Entity =>] type_Name);
19889 when Pragma_Suppress_Initialization => Suppress_Init : declare
19890 E_Id : Node_Id;
19891 E : Entity_Id;
19893 begin
19894 GNAT_Pragma;
19895 Check_Arg_Count (1);
19896 Check_Optional_Identifier (Arg1, Name_Entity);
19897 Check_Arg_Is_Local_Name (Arg1);
19899 E_Id := Get_Pragma_Arg (Arg1);
19901 if Etype (E_Id) = Any_Type then
19902 return;
19903 end if;
19905 E := Entity (E_Id);
19907 if not Is_Type (E) and then Ekind (E) /= E_Variable then
19908 Error_Pragma_Arg
19909 ("pragma% requires variable, type or subtype", Arg1);
19910 end if;
19912 if Rep_Item_Too_Early (E, N)
19913 or else
19914 Rep_Item_Too_Late (E, N, FOnly => True)
19915 then
19916 return;
19917 end if;
19919 -- For incomplete/private type, set flag on full view
19921 if Is_Incomplete_Or_Private_Type (E) then
19922 if No (Full_View (Base_Type (E))) then
19923 Error_Pragma_Arg
19924 ("argument of pragma% cannot be an incomplete type", Arg1);
19925 else
19926 Set_Suppress_Initialization (Full_View (Base_Type (E)));
19927 end if;
19929 -- For first subtype, set flag on base type
19931 elsif Is_First_Subtype (E) then
19932 Set_Suppress_Initialization (Base_Type (E));
19934 -- For other than first subtype, set flag on subtype or variable
19936 else
19937 Set_Suppress_Initialization (E);
19938 end if;
19939 end Suppress_Init;
19941 -----------------
19942 -- System_Name --
19943 -----------------
19945 -- pragma System_Name (DIRECT_NAME);
19947 -- Syntax check: one argument, which must be the identifier GNAT or
19948 -- the identifier GCC, no other identifiers are acceptable.
19950 when Pragma_System_Name =>
19951 GNAT_Pragma;
19952 Check_No_Identifiers;
19953 Check_Arg_Count (1);
19954 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
19956 -----------------------------
19957 -- Task_Dispatching_Policy --
19958 -----------------------------
19960 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
19962 when Pragma_Task_Dispatching_Policy => declare
19963 DP : Character;
19965 begin
19966 Check_Ada_83_Warning;
19967 Check_Arg_Count (1);
19968 Check_No_Identifiers;
19969 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
19970 Check_Valid_Configuration_Pragma;
19971 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
19972 DP := Fold_Upper (Name_Buffer (1));
19974 if Task_Dispatching_Policy /= ' '
19975 and then Task_Dispatching_Policy /= DP
19976 then
19977 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
19978 Error_Pragma
19979 ("task dispatching policy incompatible with policy#");
19981 -- Set new policy, but always preserve System_Location since we
19982 -- like the error message with the run time name.
19984 else
19985 Task_Dispatching_Policy := DP;
19987 if Task_Dispatching_Policy_Sloc /= System_Location then
19988 Task_Dispatching_Policy_Sloc := Loc;
19989 end if;
19990 end if;
19991 end;
19993 ---------------
19994 -- Task_Info --
19995 ---------------
19997 -- pragma Task_Info (EXPRESSION);
19999 when Pragma_Task_Info => Task_Info : declare
20000 P : constant Node_Id := Parent (N);
20001 Ent : Entity_Id;
20003 begin
20004 GNAT_Pragma;
20006 if Warn_On_Obsolescent_Feature then
20007 Error_Msg_N
20008 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
20009 & "instead?j?", N);
20010 end if;
20012 if Nkind (P) /= N_Task_Definition then
20013 Error_Pragma ("pragma% must appear in task definition");
20014 end if;
20016 Check_No_Identifiers;
20017 Check_Arg_Count (1);
20019 Analyze_And_Resolve
20020 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
20022 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
20023 return;
20024 end if;
20026 Ent := Defining_Identifier (Parent (P));
20028 -- Check duplicate pragma before we chain the pragma in the Rep
20029 -- Item chain of Ent.
20031 if Has_Rep_Pragma
20032 (Ent, Name_Task_Info, Check_Parents => False)
20033 then
20034 Error_Pragma ("duplicate pragma% not allowed");
20035 end if;
20037 Record_Rep_Item (Ent, N);
20038 end Task_Info;
20040 ---------------
20041 -- Task_Name --
20042 ---------------
20044 -- pragma Task_Name (string_EXPRESSION);
20046 when Pragma_Task_Name => Task_Name : declare
20047 P : constant Node_Id := Parent (N);
20048 Arg : Node_Id;
20049 Ent : Entity_Id;
20051 begin
20052 Check_No_Identifiers;
20053 Check_Arg_Count (1);
20055 Arg := Get_Pragma_Arg (Arg1);
20057 -- The expression is used in the call to Create_Task, and must be
20058 -- expanded there, not in the context of the current spec. It must
20059 -- however be analyzed to capture global references, in case it
20060 -- appears in a generic context.
20062 Preanalyze_And_Resolve (Arg, Standard_String);
20064 if Nkind (P) /= N_Task_Definition then
20065 Pragma_Misplaced;
20066 end if;
20068 Ent := Defining_Identifier (Parent (P));
20070 -- Check duplicate pragma before we chain the pragma in the Rep
20071 -- Item chain of Ent.
20073 if Has_Rep_Pragma
20074 (Ent, Name_Task_Name, Check_Parents => False)
20075 then
20076 Error_Pragma ("duplicate pragma% not allowed");
20077 end if;
20079 Record_Rep_Item (Ent, N);
20080 end Task_Name;
20082 ------------------
20083 -- Task_Storage --
20084 ------------------
20086 -- pragma Task_Storage (
20087 -- [Task_Type =>] LOCAL_NAME,
20088 -- [Top_Guard =>] static_integer_EXPRESSION);
20090 when Pragma_Task_Storage => Task_Storage : declare
20091 Args : Args_List (1 .. 2);
20092 Names : constant Name_List (1 .. 2) := (
20093 Name_Task_Type,
20094 Name_Top_Guard);
20096 Task_Type : Node_Id renames Args (1);
20097 Top_Guard : Node_Id renames Args (2);
20099 Ent : Entity_Id;
20101 begin
20102 GNAT_Pragma;
20103 Gather_Associations (Names, Args);
20105 if No (Task_Type) then
20106 Error_Pragma
20107 ("missing task_type argument for pragma%");
20108 end if;
20110 Check_Arg_Is_Local_Name (Task_Type);
20112 Ent := Entity (Task_Type);
20114 if not Is_Task_Type (Ent) then
20115 Error_Pragma_Arg
20116 ("argument for pragma% must be task type", Task_Type);
20117 end if;
20119 if No (Top_Guard) then
20120 Error_Pragma_Arg
20121 ("pragma% takes two arguments", Task_Type);
20122 else
20123 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
20124 end if;
20126 Check_First_Subtype (Task_Type);
20128 if Rep_Item_Too_Late (Ent, N) then
20129 raise Pragma_Exit;
20130 end if;
20131 end Task_Storage;
20133 ---------------
20134 -- Test_Case --
20135 ---------------
20137 -- pragma Test_Case
20138 -- ([Name =>] Static_String_EXPRESSION
20139 -- ,[Mode =>] MODE_TYPE
20140 -- [, Requires => Boolean_EXPRESSION]
20141 -- [, Ensures => Boolean_EXPRESSION]);
20143 -- MODE_TYPE ::= Nominal | Robustness
20145 when Pragma_Test_Case => Test_Case : declare
20146 procedure Check_Distinct_Name (Subp_Id : Entity_Id);
20147 -- Ensure that the contract of subprogram Subp_Id does not contain
20148 -- another Test_Case pragma with the same Name as the current one.
20150 -------------------------
20151 -- Check_Distinct_Name --
20152 -------------------------
20154 procedure Check_Distinct_Name (Subp_Id : Entity_Id) is
20155 Items : constant Node_Id := Contract (Subp_Id);
20156 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
20157 Prag : Node_Id;
20159 begin
20160 -- Inspect all Test_Case pragma of the related subprogram
20161 -- looking for one with a duplicate "Name" argument.
20163 if Present (Items) then
20164 Prag := Contract_Test_Cases (Items);
20165 while Present (Prag) loop
20166 if Pragma_Name (Prag) = Name_Test_Case
20167 and then String_Equal
20168 (Name, Get_Name_From_CTC_Pragma (Prag))
20169 then
20170 Error_Msg_Sloc := Sloc (Prag);
20171 Error_Pragma ("name for pragma % is already used #");
20172 end if;
20174 Prag := Next_Pragma (Prag);
20175 end loop;
20176 end if;
20177 end Check_Distinct_Name;
20179 -- Local variables
20181 Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit));
20182 Asp_Arg : Node_Id;
20183 Context : Node_Id;
20184 Subp_Decl : Node_Id;
20185 Subp_Id : Entity_Id;
20187 -- Start of processing for Test_Case
20189 begin
20190 GNAT_Pragma;
20191 Check_At_Least_N_Arguments (2);
20192 Check_At_Most_N_Arguments (4);
20193 Check_Arg_Order
20194 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
20196 -- Argument "Name"
20198 Check_Optional_Identifier (Arg1, Name_Name);
20199 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
20201 -- Argument "Mode"
20203 Check_Optional_Identifier (Arg2, Name_Mode);
20204 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
20206 -- Arguments "Requires" and "Ensures"
20208 if Present (Arg3) then
20209 if Present (Arg4) then
20210 Check_Identifier (Arg3, Name_Requires);
20211 Check_Identifier (Arg4, Name_Ensures);
20212 else
20213 Check_Identifier_Is_One_Of
20214 (Arg3, Name_Requires, Name_Ensures);
20215 end if;
20216 end if;
20218 -- Pragma Test_Case must be associated with a subprogram declared
20219 -- in a library-level package. First determine whether the current
20220 -- compilation unit is a legal context.
20222 if Nkind_In (Pack_Decl, N_Package_Declaration,
20223 N_Generic_Package_Declaration)
20224 then
20225 null;
20227 -- Otherwise the placement is illegal
20229 else
20230 Pragma_Misplaced;
20231 return;
20232 end if;
20234 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
20236 -- Find the enclosing context
20238 Context := Parent (Subp_Decl);
20240 if Present (Context) then
20241 Context := Parent (Context);
20242 end if;
20244 -- Verify the placement of the pragma
20246 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
20247 Error_Pragma
20248 ("pragma % cannot be applied to abstract subprogram");
20249 return;
20251 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
20252 Error_Pragma ("pragma % cannot be applied to entry");
20253 return;
20255 -- The context is a [generic] subprogram declared at the top level
20256 -- of the [generic] package unit.
20258 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
20259 N_Subprogram_Declaration)
20260 and then Present (Context)
20261 and then Nkind_In (Context, N_Generic_Package_Declaration,
20262 N_Package_Declaration)
20263 then
20264 Subp_Id := Defining_Entity (Subp_Decl);
20266 -- Otherwise the placement is illegal
20268 else
20269 Pragma_Misplaced;
20270 return;
20271 end if;
20273 -- Preanalyze the original aspect argument "Name" for ASIS or for
20274 -- a generic subprogram to properly capture global references.
20276 if ASIS_Mode or else Is_Generic_Subprogram (Subp_Id) then
20277 Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True);
20279 if Present (Asp_Arg) then
20281 -- The argument appears with an identifier in association
20282 -- form.
20284 if Nkind (Asp_Arg) = N_Component_Association then
20285 Asp_Arg := Expression (Asp_Arg);
20286 end if;
20288 Check_Expr_Is_OK_Static_Expression
20289 (Asp_Arg, Standard_String);
20290 end if;
20291 end if;
20293 -- Ensure that the all Test_Case pragmas of the related subprogram
20294 -- have distinct names.
20296 Check_Distinct_Name (Subp_Id);
20298 -- Construct a generic template for the pragma when the context is
20299 -- a generic subprogram and the pragma is a source construct.
20301 Create_Generic_Template (N, Subp_Id);
20303 -- Fully analyze the pragma when it appears inside a subprogram
20304 -- body because it cannot benefit from forward references.
20306 if Nkind_In (Subp_Decl, N_Subprogram_Body,
20307 N_Subprogram_Body_Stub)
20308 then
20309 Analyze_Test_Case_In_Decl_Part (N);
20310 end if;
20312 -- Chain the pragma on the contract for further processing
20314 Add_Contract_Item (N, Subp_Id);
20315 end Test_Case;
20317 --------------------------
20318 -- Thread_Local_Storage --
20319 --------------------------
20321 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
20323 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
20324 Id : Node_Id;
20325 E : Entity_Id;
20327 begin
20328 GNAT_Pragma;
20329 Check_Arg_Count (1);
20330 Check_Optional_Identifier (Arg1, Name_Entity);
20331 Check_Arg_Is_Library_Level_Local_Name (Arg1);
20333 Id := Get_Pragma_Arg (Arg1);
20334 Analyze (Id);
20336 if not Is_Entity_Name (Id)
20337 or else Ekind (Entity (Id)) /= E_Variable
20338 then
20339 Error_Pragma_Arg ("local variable name required", Arg1);
20340 end if;
20342 E := Entity (Id);
20344 if Rep_Item_Too_Early (E, N)
20345 or else Rep_Item_Too_Late (E, N)
20346 then
20347 raise Pragma_Exit;
20348 end if;
20350 Set_Has_Pragma_Thread_Local_Storage (E);
20351 Set_Has_Gigi_Rep_Item (E);
20352 end Thread_Local_Storage;
20354 ----------------
20355 -- Time_Slice --
20356 ----------------
20358 -- pragma Time_Slice (static_duration_EXPRESSION);
20360 when Pragma_Time_Slice => Time_Slice : declare
20361 Val : Ureal;
20362 Nod : Node_Id;
20364 begin
20365 GNAT_Pragma;
20366 Check_Arg_Count (1);
20367 Check_No_Identifiers;
20368 Check_In_Main_Program;
20369 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
20371 if not Error_Posted (Arg1) then
20372 Nod := Next (N);
20373 while Present (Nod) loop
20374 if Nkind (Nod) = N_Pragma
20375 and then Pragma_Name (Nod) = Name_Time_Slice
20376 then
20377 Error_Msg_Name_1 := Pname;
20378 Error_Msg_N ("duplicate pragma% not permitted", Nod);
20379 end if;
20381 Next (Nod);
20382 end loop;
20383 end if;
20385 -- Process only if in main unit
20387 if Get_Source_Unit (Loc) = Main_Unit then
20388 Opt.Time_Slice_Set := True;
20389 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
20391 if Val <= Ureal_0 then
20392 Opt.Time_Slice_Value := 0;
20394 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
20395 Opt.Time_Slice_Value := 1_000_000_000;
20397 else
20398 Opt.Time_Slice_Value :=
20399 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
20400 end if;
20401 end if;
20402 end Time_Slice;
20404 -----------
20405 -- Title --
20406 -----------
20408 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
20410 -- TITLING_OPTION ::=
20411 -- [Title =>] STRING_LITERAL
20412 -- | [Subtitle =>] STRING_LITERAL
20414 when Pragma_Title => Title : declare
20415 Args : Args_List (1 .. 2);
20416 Names : constant Name_List (1 .. 2) := (
20417 Name_Title,
20418 Name_Subtitle);
20420 begin
20421 GNAT_Pragma;
20422 Gather_Associations (Names, Args);
20423 Store_Note (N);
20425 for J in 1 .. 2 loop
20426 if Present (Args (J)) then
20427 Check_Arg_Is_OK_Static_Expression
20428 (Args (J), Standard_String);
20429 end if;
20430 end loop;
20431 end Title;
20433 ----------------------------
20434 -- Type_Invariant[_Class] --
20435 ----------------------------
20437 -- pragma Type_Invariant[_Class]
20438 -- ([Entity =>] type_LOCAL_NAME,
20439 -- [Check =>] EXPRESSION);
20441 when Pragma_Type_Invariant |
20442 Pragma_Type_Invariant_Class =>
20443 Type_Invariant : declare
20444 I_Pragma : Node_Id;
20446 begin
20447 Check_Arg_Count (2);
20449 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
20450 -- setting Class_Present for the Type_Invariant_Class case.
20452 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
20453 I_Pragma := New_Copy (N);
20454 Set_Pragma_Identifier
20455 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
20456 Rewrite (N, I_Pragma);
20457 Set_Analyzed (N, False);
20458 Analyze (N);
20459 end Type_Invariant;
20461 ---------------------
20462 -- Unchecked_Union --
20463 ---------------------
20465 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
20467 when Pragma_Unchecked_Union => Unchecked_Union : declare
20468 Assoc : constant Node_Id := Arg1;
20469 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
20470 Typ : Entity_Id;
20471 Tdef : Node_Id;
20472 Clist : Node_Id;
20473 Vpart : Node_Id;
20474 Comp : Node_Id;
20475 Variant : Node_Id;
20477 begin
20478 Ada_2005_Pragma;
20479 Check_No_Identifiers;
20480 Check_Arg_Count (1);
20481 Check_Arg_Is_Local_Name (Arg1);
20483 Find_Type (Type_Id);
20485 Typ := Entity (Type_Id);
20487 if Typ = Any_Type
20488 or else Rep_Item_Too_Early (Typ, N)
20489 then
20490 return;
20491 else
20492 Typ := Underlying_Type (Typ);
20493 end if;
20495 if Rep_Item_Too_Late (Typ, N) then
20496 return;
20497 end if;
20499 Check_First_Subtype (Arg1);
20501 -- Note remaining cases are references to a type in the current
20502 -- declarative part. If we find an error, we post the error on
20503 -- the relevant type declaration at an appropriate point.
20505 if not Is_Record_Type (Typ) then
20506 Error_Msg_N ("unchecked union must be record type", Typ);
20507 return;
20509 elsif Is_Tagged_Type (Typ) then
20510 Error_Msg_N ("unchecked union must not be tagged", Typ);
20511 return;
20513 elsif not Has_Discriminants (Typ) then
20514 Error_Msg_N
20515 ("unchecked union must have one discriminant", Typ);
20516 return;
20518 -- Note: in previous versions of GNAT we used to check for limited
20519 -- types and give an error, but in fact the standard does allow
20520 -- Unchecked_Union on limited types, so this check was removed.
20522 -- Similarly, GNAT used to require that all discriminants have
20523 -- default values, but this is not mandated by the RM.
20525 -- Proceed with basic error checks completed
20527 else
20528 Tdef := Type_Definition (Declaration_Node (Typ));
20529 Clist := Component_List (Tdef);
20531 -- Check presence of component list and variant part
20533 if No (Clist) or else No (Variant_Part (Clist)) then
20534 Error_Msg_N
20535 ("unchecked union must have variant part", Tdef);
20536 return;
20537 end if;
20539 -- Check components
20541 Comp := First (Component_Items (Clist));
20542 while Present (Comp) loop
20543 Check_Component (Comp, Typ);
20544 Next (Comp);
20545 end loop;
20547 -- Check variant part
20549 Vpart := Variant_Part (Clist);
20551 Variant := First (Variants (Vpart));
20552 while Present (Variant) loop
20553 Check_Variant (Variant, Typ);
20554 Next (Variant);
20555 end loop;
20556 end if;
20558 Set_Is_Unchecked_Union (Typ);
20559 Set_Convention (Typ, Convention_C);
20560 Set_Has_Unchecked_Union (Base_Type (Typ));
20561 Set_Is_Unchecked_Union (Base_Type (Typ));
20562 end Unchecked_Union;
20564 ------------------------
20565 -- Unimplemented_Unit --
20566 ------------------------
20568 -- pragma Unimplemented_Unit;
20570 -- Note: this only gives an error if we are generating code, or if
20571 -- we are in a generic library unit (where the pragma appears in the
20572 -- body, not in the spec).
20574 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
20575 Cunitent : constant Entity_Id :=
20576 Cunit_Entity (Get_Source_Unit (Loc));
20577 Ent_Kind : constant Entity_Kind :=
20578 Ekind (Cunitent);
20580 begin
20581 GNAT_Pragma;
20582 Check_Arg_Count (0);
20584 if Operating_Mode = Generate_Code
20585 or else Ent_Kind = E_Generic_Function
20586 or else Ent_Kind = E_Generic_Procedure
20587 or else Ent_Kind = E_Generic_Package
20588 then
20589 Get_Name_String (Chars (Cunitent));
20590 Set_Casing (Mixed_Case);
20591 Write_Str (Name_Buffer (1 .. Name_Len));
20592 Write_Str (" is not supported in this configuration");
20593 Write_Eol;
20594 raise Unrecoverable_Error;
20595 end if;
20596 end Unimplemented_Unit;
20598 ------------------------
20599 -- Universal_Aliasing --
20600 ------------------------
20602 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
20604 when Pragma_Universal_Aliasing => Universal_Alias : declare
20605 E_Id : Entity_Id;
20607 begin
20608 GNAT_Pragma;
20609 Check_Arg_Count (1);
20610 Check_Optional_Identifier (Arg2, Name_Entity);
20611 Check_Arg_Is_Local_Name (Arg1);
20612 E_Id := Entity (Get_Pragma_Arg (Arg1));
20614 if E_Id = Any_Type then
20615 return;
20616 elsif No (E_Id) or else not Is_Type (E_Id) then
20617 Error_Pragma_Arg ("pragma% requires type", Arg1);
20618 end if;
20620 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
20621 Record_Rep_Item (E_Id, N);
20622 end Universal_Alias;
20624 --------------------
20625 -- Universal_Data --
20626 --------------------
20628 -- pragma Universal_Data [(library_unit_NAME)];
20630 when Pragma_Universal_Data =>
20631 GNAT_Pragma;
20633 -- If this is a configuration pragma, then set the universal
20634 -- addressing option, otherwise confirm that the pragma satisfies
20635 -- the requirements of library unit pragma placement and leave it
20636 -- to the GNAAMP back end to detect the pragma (avoids transitive
20637 -- setting of the option due to withed units).
20639 if Is_Configuration_Pragma then
20640 Universal_Addressing_On_AAMP := True;
20641 else
20642 Check_Valid_Library_Unit_Pragma;
20643 end if;
20645 if not AAMP_On_Target then
20646 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
20647 end if;
20649 ----------------
20650 -- Unmodified --
20651 ----------------
20653 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
20655 when Pragma_Unmodified => Unmodified : declare
20656 Arg_Node : Node_Id;
20657 Arg_Expr : Node_Id;
20658 Arg_Ent : Entity_Id;
20660 begin
20661 GNAT_Pragma;
20662 Check_At_Least_N_Arguments (1);
20664 -- Loop through arguments
20666 Arg_Node := Arg1;
20667 while Present (Arg_Node) loop
20668 Check_No_Identifier (Arg_Node);
20670 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
20671 -- in fact generate reference, so that the entity will have a
20672 -- reference, which will inhibit any warnings about it not
20673 -- being referenced, and also properly show up in the ali file
20674 -- as a reference. But this reference is recorded before the
20675 -- Has_Pragma_Unreferenced flag is set, so that no warning is
20676 -- generated for this reference.
20678 Check_Arg_Is_Local_Name (Arg_Node);
20679 Arg_Expr := Get_Pragma_Arg (Arg_Node);
20681 if Is_Entity_Name (Arg_Expr) then
20682 Arg_Ent := Entity (Arg_Expr);
20684 if not Is_Assignable (Arg_Ent) then
20685 Error_Pragma_Arg
20686 ("pragma% can only be applied to a variable",
20687 Arg_Expr);
20688 else
20689 Set_Has_Pragma_Unmodified (Arg_Ent);
20690 end if;
20691 end if;
20693 Next (Arg_Node);
20694 end loop;
20695 end Unmodified;
20697 ------------------
20698 -- Unreferenced --
20699 ------------------
20701 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
20703 -- or when used in a context clause:
20705 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
20707 when Pragma_Unreferenced => Unreferenced : declare
20708 Arg_Node : Node_Id;
20709 Arg_Expr : Node_Id;
20710 Arg_Ent : Entity_Id;
20711 Citem : Node_Id;
20713 begin
20714 GNAT_Pragma;
20715 Check_At_Least_N_Arguments (1);
20717 -- Check case of appearing within context clause
20719 if Is_In_Context_Clause then
20721 -- The arguments must all be units mentioned in a with clause
20722 -- in the same context clause. Note we already checked (in
20723 -- Par.Prag) that the arguments are either identifiers or
20724 -- selected components.
20726 Arg_Node := Arg1;
20727 while Present (Arg_Node) loop
20728 Citem := First (List_Containing (N));
20729 while Citem /= N loop
20730 if Nkind (Citem) = N_With_Clause
20731 and then
20732 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
20733 then
20734 Set_Has_Pragma_Unreferenced
20735 (Cunit_Entity
20736 (Get_Source_Unit
20737 (Library_Unit (Citem))));
20738 Set_Elab_Unit_Name
20739 (Get_Pragma_Arg (Arg_Node), Name (Citem));
20740 exit;
20741 end if;
20743 Next (Citem);
20744 end loop;
20746 if Citem = N then
20747 Error_Pragma_Arg
20748 ("argument of pragma% is not withed unit", Arg_Node);
20749 end if;
20751 Next (Arg_Node);
20752 end loop;
20754 -- Case of not in list of context items
20756 else
20757 Arg_Node := Arg1;
20758 while Present (Arg_Node) loop
20759 Check_No_Identifier (Arg_Node);
20761 -- Note: the analyze call done by Check_Arg_Is_Local_Name
20762 -- will in fact generate reference, so that the entity will
20763 -- have a reference, which will inhibit any warnings about
20764 -- it not being referenced, and also properly show up in the
20765 -- ali file as a reference. But this reference is recorded
20766 -- before the Has_Pragma_Unreferenced flag is set, so that
20767 -- no warning is generated for this reference.
20769 Check_Arg_Is_Local_Name (Arg_Node);
20770 Arg_Expr := Get_Pragma_Arg (Arg_Node);
20772 if Is_Entity_Name (Arg_Expr) then
20773 Arg_Ent := Entity (Arg_Expr);
20775 -- If the entity is overloaded, the pragma applies to the
20776 -- most recent overloading, as documented. In this case,
20777 -- name resolution does not generate a reference, so it
20778 -- must be done here explicitly.
20780 if Is_Overloaded (Arg_Expr) then
20781 Generate_Reference (Arg_Ent, N);
20782 end if;
20784 Set_Has_Pragma_Unreferenced (Arg_Ent);
20785 end if;
20787 Next (Arg_Node);
20788 end loop;
20789 end if;
20790 end Unreferenced;
20792 --------------------------
20793 -- Unreferenced_Objects --
20794 --------------------------
20796 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
20798 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
20799 Arg_Node : Node_Id;
20800 Arg_Expr : Node_Id;
20802 begin
20803 GNAT_Pragma;
20804 Check_At_Least_N_Arguments (1);
20806 Arg_Node := Arg1;
20807 while Present (Arg_Node) loop
20808 Check_No_Identifier (Arg_Node);
20809 Check_Arg_Is_Local_Name (Arg_Node);
20810 Arg_Expr := Get_Pragma_Arg (Arg_Node);
20812 if not Is_Entity_Name (Arg_Expr)
20813 or else not Is_Type (Entity (Arg_Expr))
20814 then
20815 Error_Pragma_Arg
20816 ("argument for pragma% must be type or subtype", Arg_Node);
20817 end if;
20819 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
20820 Next (Arg_Node);
20821 end loop;
20822 end Unreferenced_Objects;
20824 ------------------------------
20825 -- Unreserve_All_Interrupts --
20826 ------------------------------
20828 -- pragma Unreserve_All_Interrupts;
20830 when Pragma_Unreserve_All_Interrupts =>
20831 GNAT_Pragma;
20832 Check_Arg_Count (0);
20834 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
20835 Unreserve_All_Interrupts := True;
20836 end if;
20838 ----------------
20839 -- Unsuppress --
20840 ----------------
20842 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
20844 when Pragma_Unsuppress =>
20845 Ada_2005_Pragma;
20846 Process_Suppress_Unsuppress (Suppress_Case => False);
20848 ----------------------------
20849 -- Unevaluated_Use_Of_Old --
20850 ----------------------------
20852 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
20854 when Pragma_Unevaluated_Use_Of_Old =>
20855 GNAT_Pragma;
20856 Check_Arg_Count (1);
20857 Check_No_Identifiers;
20858 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
20860 -- Suppress/Unsuppress can appear as a configuration pragma, or in
20861 -- a declarative part or a package spec.
20863 if not Is_Configuration_Pragma then
20864 Check_Is_In_Decl_Part_Or_Package_Spec;
20865 end if;
20867 -- Store proper setting of Uneval_Old
20869 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
20870 Uneval_Old := Fold_Upper (Name_Buffer (1));
20872 -------------------
20873 -- Use_VADS_Size --
20874 -------------------
20876 -- pragma Use_VADS_Size;
20878 when Pragma_Use_VADS_Size =>
20879 GNAT_Pragma;
20880 Check_Arg_Count (0);
20881 Check_Valid_Configuration_Pragma;
20882 Use_VADS_Size := True;
20884 ---------------------
20885 -- Validity_Checks --
20886 ---------------------
20888 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
20890 when Pragma_Validity_Checks => Validity_Checks : declare
20891 A : constant Node_Id := Get_Pragma_Arg (Arg1);
20892 S : String_Id;
20893 C : Char_Code;
20895 begin
20896 GNAT_Pragma;
20897 Check_Arg_Count (1);
20898 Check_No_Identifiers;
20900 -- Pragma always active unless in CodePeer or GNATprove modes,
20901 -- which use a fixed configuration of validity checks.
20903 if not (CodePeer_Mode or GNATprove_Mode) then
20904 if Nkind (A) = N_String_Literal then
20905 S := Strval (A);
20907 declare
20908 Slen : constant Natural := Natural (String_Length (S));
20909 Options : String (1 .. Slen);
20910 J : Natural;
20912 begin
20913 -- Couldn't we use a for loop here over Options'Range???
20915 J := 1;
20916 loop
20917 C := Get_String_Char (S, Int (J));
20919 -- This is a weird test, it skips setting validity
20920 -- checks entirely if any element of S is out of
20921 -- range of Character, what is that about ???
20923 exit when not In_Character_Range (C);
20924 Options (J) := Get_Character (C);
20926 if J = Slen then
20927 Set_Validity_Check_Options (Options);
20928 exit;
20929 else
20930 J := J + 1;
20931 end if;
20932 end loop;
20933 end;
20935 elsif Nkind (A) = N_Identifier then
20936 if Chars (A) = Name_All_Checks then
20937 Set_Validity_Check_Options ("a");
20938 elsif Chars (A) = Name_On then
20939 Validity_Checks_On := True;
20940 elsif Chars (A) = Name_Off then
20941 Validity_Checks_On := False;
20942 end if;
20943 end if;
20944 end if;
20945 end Validity_Checks;
20947 --------------
20948 -- Volatile --
20949 --------------
20951 -- pragma Volatile (LOCAL_NAME);
20953 when Pragma_Volatile =>
20954 Process_Atomic_Independent_Shared_Volatile;
20956 -------------------------
20957 -- Volatile_Components --
20958 -------------------------
20960 -- pragma Volatile_Components (array_LOCAL_NAME);
20962 -- Volatile is handled by the same circuit as Atomic_Components
20964 ----------------------
20965 -- Warning_As_Error --
20966 ----------------------
20968 -- pragma Warning_As_Error (static_string_EXPRESSION);
20970 when Pragma_Warning_As_Error =>
20971 GNAT_Pragma;
20972 Check_Arg_Count (1);
20973 Check_No_Identifiers;
20974 Check_Valid_Configuration_Pragma;
20976 if not Is_Static_String_Expression (Arg1) then
20977 Error_Pragma_Arg
20978 ("argument of pragma% must be static string expression",
20979 Arg1);
20981 -- OK static string expression
20983 else
20984 Acquire_Warning_Match_String (Arg1);
20985 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
20986 Warnings_As_Errors (Warnings_As_Errors_Count) :=
20987 new String'(Name_Buffer (1 .. Name_Len));
20988 end if;
20990 --------------
20991 -- Warnings --
20992 --------------
20994 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
20996 -- DETAILS ::= On | Off
20997 -- DETAILS ::= On | Off, local_NAME
20998 -- DETAILS ::= static_string_EXPRESSION
20999 -- DETAILS ::= On | Off, static_string_EXPRESSION
21001 -- TOOL_NAME ::= GNAT | GNATProve
21003 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
21005 -- Note: If the first argument matches an allowed tool name, it is
21006 -- always considered to be a tool name, even if there is a string
21007 -- variable of that name.
21009 -- Note if the second argument of DETAILS is a local_NAME then the
21010 -- second form is always understood. If the intention is to use
21011 -- the fourth form, then you can write NAME & "" to force the
21012 -- intepretation as a static_string_EXPRESSION.
21014 when Pragma_Warnings => Warnings : declare
21015 Reason : String_Id;
21017 begin
21018 GNAT_Pragma;
21019 Check_At_Least_N_Arguments (1);
21021 -- See if last argument is labeled Reason. If so, make sure we
21022 -- have a string literal or a concatenation of string literals,
21023 -- and acquire the REASON string. Then remove the REASON argument
21024 -- by decreasing Num_Args by one; Remaining processing looks only
21025 -- at first Num_Args arguments).
21027 declare
21028 Last_Arg : constant Node_Id :=
21029 Last (Pragma_Argument_Associations (N));
21031 begin
21032 if Nkind (Last_Arg) = N_Pragma_Argument_Association
21033 and then Chars (Last_Arg) = Name_Reason
21034 then
21035 Start_String;
21036 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
21037 Reason := End_String;
21038 Arg_Count := Arg_Count - 1;
21040 -- Not allowed in compiler units (bootstrap issues)
21042 Check_Compiler_Unit ("Reason for pragma Warnings", N);
21044 -- No REASON string, set null string as reason
21046 else
21047 Reason := Null_String_Id;
21048 end if;
21049 end;
21051 -- Now proceed with REASON taken care of and eliminated
21053 Check_No_Identifiers;
21055 -- If debug flag -gnatd.i is set, pragma is ignored
21057 if Debug_Flag_Dot_I then
21058 return;
21059 end if;
21061 -- Process various forms of the pragma
21063 declare
21064 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21065 Shifted_Args : List_Id;
21067 begin
21068 -- See if first argument is a tool name, currently either
21069 -- GNAT or GNATprove. If so, either ignore the pragma if the
21070 -- tool used does not match, or continue as if no tool name
21071 -- was given otherwise, by shifting the arguments.
21073 if Nkind (Argx) = N_Identifier
21074 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
21075 then
21076 if Chars (Argx) = Name_Gnat then
21077 if CodePeer_Mode or GNATprove_Mode or ASIS_Mode then
21078 Rewrite (N, Make_Null_Statement (Loc));
21079 Analyze (N);
21080 raise Pragma_Exit;
21081 end if;
21083 elsif Chars (Argx) = Name_Gnatprove then
21084 if not GNATprove_Mode then
21085 Rewrite (N, Make_Null_Statement (Loc));
21086 Analyze (N);
21087 raise Pragma_Exit;
21088 end if;
21090 else
21091 raise Program_Error;
21092 end if;
21094 -- At this point, the pragma Warnings applies to the tool,
21095 -- so continue with shifted arguments.
21097 Arg_Count := Arg_Count - 1;
21099 if Arg_Count = 1 then
21100 Shifted_Args := New_List (New_Copy (Arg2));
21101 elsif Arg_Count = 2 then
21102 Shifted_Args := New_List (New_Copy (Arg2),
21103 New_Copy (Arg3));
21104 elsif Arg_Count = 3 then
21105 Shifted_Args := New_List (New_Copy (Arg2),
21106 New_Copy (Arg3),
21107 New_Copy (Arg4));
21108 else
21109 raise Program_Error;
21110 end if;
21112 Rewrite (N,
21113 Make_Pragma (Loc,
21114 Chars => Name_Warnings,
21115 Pragma_Argument_Associations => Shifted_Args));
21116 Analyze (N);
21117 raise Pragma_Exit;
21118 end if;
21120 -- One argument case
21122 if Arg_Count = 1 then
21124 -- On/Off one argument case was processed by parser
21126 if Nkind (Argx) = N_Identifier
21127 and then Nam_In (Chars (Argx), Name_On, Name_Off)
21128 then
21129 null;
21131 -- One argument case must be ON/OFF or static string expr
21133 elsif not Is_Static_String_Expression (Arg1) then
21134 Error_Pragma_Arg
21135 ("argument of pragma% must be On/Off or static string "
21136 & "expression", Arg1);
21138 -- One argument string expression case
21140 else
21141 declare
21142 Lit : constant Node_Id := Expr_Value_S (Argx);
21143 Str : constant String_Id := Strval (Lit);
21144 Len : constant Nat := String_Length (Str);
21145 C : Char_Code;
21146 J : Nat;
21147 OK : Boolean;
21148 Chr : Character;
21150 begin
21151 J := 1;
21152 while J <= Len loop
21153 C := Get_String_Char (Str, J);
21154 OK := In_Character_Range (C);
21156 if OK then
21157 Chr := Get_Character (C);
21159 -- Dash case: only -Wxxx is accepted
21161 if J = 1
21162 and then J < Len
21163 and then Chr = '-'
21164 then
21165 J := J + 1;
21166 C := Get_String_Char (Str, J);
21167 Chr := Get_Character (C);
21168 exit when Chr = 'W';
21169 OK := False;
21171 -- Dot case
21173 elsif J < Len and then Chr = '.' then
21174 J := J + 1;
21175 C := Get_String_Char (Str, J);
21176 Chr := Get_Character (C);
21178 if not Set_Dot_Warning_Switch (Chr) then
21179 Error_Pragma_Arg
21180 ("invalid warning switch character "
21181 & '.' & Chr, Arg1);
21182 end if;
21184 -- Non-Dot case
21186 else
21187 OK := Set_Warning_Switch (Chr);
21188 end if;
21189 end if;
21191 if not OK then
21192 Error_Pragma_Arg
21193 ("invalid warning switch character " & Chr,
21194 Arg1);
21195 end if;
21197 J := J + 1;
21198 end loop;
21199 end;
21200 end if;
21202 -- Two or more arguments (must be two)
21204 else
21205 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
21206 Check_Arg_Count (2);
21208 declare
21209 E_Id : Node_Id;
21210 E : Entity_Id;
21211 Err : Boolean;
21213 begin
21214 E_Id := Get_Pragma_Arg (Arg2);
21215 Analyze (E_Id);
21217 -- In the expansion of an inlined body, a reference to
21218 -- the formal may be wrapped in a conversion if the
21219 -- actual is a conversion. Retrieve the real entity name.
21221 if (In_Instance_Body or In_Inlined_Body)
21222 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
21223 then
21224 E_Id := Expression (E_Id);
21225 end if;
21227 -- Entity name case
21229 if Is_Entity_Name (E_Id) then
21230 E := Entity (E_Id);
21232 if E = Any_Id then
21233 return;
21234 else
21235 loop
21236 Set_Warnings_Off
21237 (E, (Chars (Get_Pragma_Arg (Arg1)) =
21238 Name_Off));
21240 -- For OFF case, make entry in warnings off
21241 -- pragma table for later processing. But we do
21242 -- not do that within an instance, since these
21243 -- warnings are about what is needed in the
21244 -- template, not an instance of it.
21246 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
21247 and then Warn_On_Warnings_Off
21248 and then not In_Instance
21249 then
21250 Warnings_Off_Pragmas.Append ((N, E, Reason));
21251 end if;
21253 if Is_Enumeration_Type (E) then
21254 declare
21255 Lit : Entity_Id;
21256 begin
21257 Lit := First_Literal (E);
21258 while Present (Lit) loop
21259 Set_Warnings_Off (Lit);
21260 Next_Literal (Lit);
21261 end loop;
21262 end;
21263 end if;
21265 exit when No (Homonym (E));
21266 E := Homonym (E);
21267 end loop;
21268 end if;
21270 -- Error if not entity or static string expression case
21272 elsif not Is_Static_String_Expression (Arg2) then
21273 Error_Pragma_Arg
21274 ("second argument of pragma% must be entity name "
21275 & "or static string expression", Arg2);
21277 -- Static string expression case
21279 else
21280 Acquire_Warning_Match_String (Arg2);
21282 -- Note on configuration pragma case: If this is a
21283 -- configuration pragma, then for an OFF pragma, we
21284 -- just set Config True in the call, which is all
21285 -- that needs to be done. For the case of ON, this
21286 -- is normally an error, unless it is canceling the
21287 -- effect of a previous OFF pragma in the same file.
21288 -- In any other case, an error will be signalled (ON
21289 -- with no matching OFF).
21291 -- Note: We set Used if we are inside a generic to
21292 -- disable the test that the non-config case actually
21293 -- cancels a warning. That's because we can't be sure
21294 -- there isn't an instantiation in some other unit
21295 -- where a warning is suppressed.
21297 -- We could do a little better here by checking if the
21298 -- generic unit we are inside is public, but for now
21299 -- we don't bother with that refinement.
21301 if Chars (Argx) = Name_Off then
21302 Set_Specific_Warning_Off
21303 (Loc, Name_Buffer (1 .. Name_Len), Reason,
21304 Config => Is_Configuration_Pragma,
21305 Used => Inside_A_Generic or else In_Instance);
21307 elsif Chars (Argx) = Name_On then
21308 Set_Specific_Warning_On
21309 (Loc, Name_Buffer (1 .. Name_Len), Err);
21311 if Err then
21312 Error_Msg
21313 ("??pragma Warnings On with no matching "
21314 & "Warnings Off", Loc);
21315 end if;
21316 end if;
21317 end if;
21318 end;
21319 end if;
21320 end;
21321 end Warnings;
21323 -------------------
21324 -- Weak_External --
21325 -------------------
21327 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
21329 when Pragma_Weak_External => Weak_External : declare
21330 Ent : Entity_Id;
21332 begin
21333 GNAT_Pragma;
21334 Check_Arg_Count (1);
21335 Check_Optional_Identifier (Arg1, Name_Entity);
21336 Check_Arg_Is_Library_Level_Local_Name (Arg1);
21337 Ent := Entity (Get_Pragma_Arg (Arg1));
21339 if Rep_Item_Too_Early (Ent, N) then
21340 return;
21341 else
21342 Ent := Underlying_Type (Ent);
21343 end if;
21345 -- The only processing required is to link this item on to the
21346 -- list of rep items for the given entity. This is accomplished
21347 -- by the call to Rep_Item_Too_Late (when no error is detected
21348 -- and False is returned).
21350 if Rep_Item_Too_Late (Ent, N) then
21351 return;
21352 else
21353 Set_Has_Gigi_Rep_Item (Ent);
21354 end if;
21355 end Weak_External;
21357 -----------------------------
21358 -- Wide_Character_Encoding --
21359 -----------------------------
21361 -- pragma Wide_Character_Encoding (IDENTIFIER);
21363 when Pragma_Wide_Character_Encoding =>
21364 GNAT_Pragma;
21366 -- Nothing to do, handled in parser. Note that we do not enforce
21367 -- configuration pragma placement, this pragma can appear at any
21368 -- place in the source, allowing mixed encodings within a single
21369 -- source program.
21371 null;
21373 --------------------
21374 -- Unknown_Pragma --
21375 --------------------
21377 -- Should be impossible, since the case of an unknown pragma is
21378 -- separately processed before the case statement is entered.
21380 when Unknown_Pragma =>
21381 raise Program_Error;
21382 end case;
21384 -- AI05-0144: detect dangerous order dependence. Disabled for now,
21385 -- until AI is formally approved.
21387 -- Check_Order_Dependence;
21389 exception
21390 when Pragma_Exit => null;
21391 end Analyze_Pragma;
21393 ---------------------------------------------
21394 -- Analyze_Pre_Post_Condition_In_Decl_Part --
21395 ---------------------------------------------
21397 procedure Analyze_Pre_Post_Condition_In_Decl_Part (N : Node_Id) is
21398 procedure Process_Class_Wide_Condition
21399 (Expr : Node_Id;
21400 Spec_Id : Entity_Id;
21401 Subp_Decl : Node_Id);
21402 -- Replace the type of all references to the controlling formal of
21403 -- subprogram Spec_Id found in expression Expr with the corresponding
21404 -- class-wide type. Subp_Decl is the subprogram [body] declaration
21405 -- where the pragma resides.
21407 ----------------------------------
21408 -- Process_Class_Wide_Condition --
21409 ----------------------------------
21411 procedure Process_Class_Wide_Condition
21412 (Expr : Node_Id;
21413 Spec_Id : Entity_Id;
21414 Subp_Decl : Node_Id)
21416 Disp_Typ : constant Entity_Id := Find_Dispatching_Type (Spec_Id);
21418 ACW : Entity_Id := Empty;
21419 -- Access to Disp_Typ'Class, created if there is a controlling formal
21420 -- that is an access parameter.
21422 function Access_Class_Wide_Type return Entity_Id;
21423 -- If expression Expr contains a reference to a controlling access
21424 -- parameter, create an access to Disp_Typ'Class for the necessary
21425 -- conversions if one does not exist.
21427 function Replace_Type (N : Node_Id) return Traverse_Result;
21428 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
21429 -- aspect for a primitive subprogram of a tagged type Disp_Typ, a
21430 -- name that denotes a formal parameter of type Disp_Typ is treated
21431 -- as having type Disp_Typ'Class. Similarly, a name that denotes a
21432 -- formal access parameter of type access-to-Disp_Typ is interpreted
21433 -- as with type access-to-Disp_Typ'Class. This ensures the expression
21434 -- is well defined for a primitive subprogram of a type descended
21435 -- from Disp_Typ.
21437 ----------------------------
21438 -- Access_Class_Wide_Type --
21439 ----------------------------
21441 function Access_Class_Wide_Type return Entity_Id is
21442 Loc : constant Source_Ptr := Sloc (N);
21444 begin
21445 if No (ACW) then
21446 ACW := Make_Temporary (Loc, 'T');
21448 Insert_Before_And_Analyze (Subp_Decl,
21449 Make_Full_Type_Declaration (Loc,
21450 Defining_Identifier => ACW,
21451 Type_Definition =>
21452 Make_Access_To_Object_Definition (Loc,
21453 Subtype_Indication =>
21454 New_Occurrence_Of (Class_Wide_Type (Disp_Typ), Loc),
21455 All_Present => True)));
21457 Freeze_Before (Subp_Decl, ACW);
21458 end if;
21460 return ACW;
21461 end Access_Class_Wide_Type;
21463 ------------------
21464 -- Replace_Type --
21465 ------------------
21467 function Replace_Type (N : Node_Id) return Traverse_Result is
21468 Context : constant Node_Id := Parent (N);
21469 Loc : constant Source_Ptr := Sloc (N);
21470 CW_Typ : Entity_Id := Empty;
21471 Ent : Entity_Id;
21472 Typ : Entity_Id;
21474 begin
21475 if Is_Entity_Name (N)
21476 and then Present (Entity (N))
21477 and then Is_Formal (Entity (N))
21478 then
21479 Ent := Entity (N);
21480 Typ := Etype (Ent);
21482 -- Do not perform the type replacement for selector names in
21483 -- parameter associations. These carry an entity for reference
21484 -- purposes, but semantically they are just identifiers.
21486 if Nkind (Context) = N_Type_Conversion then
21487 null;
21489 elsif Nkind (Context) = N_Parameter_Association
21490 and then Selector_Name (Context) = N
21491 then
21492 null;
21494 elsif Typ = Disp_Typ then
21495 CW_Typ := Class_Wide_Type (Typ);
21497 elsif Is_Access_Type (Typ)
21498 and then Designated_Type (Typ) = Disp_Typ
21499 then
21500 CW_Typ := Access_Class_Wide_Type;
21501 end if;
21503 if Present (CW_Typ) then
21504 Rewrite (N,
21505 Make_Type_Conversion (Loc,
21506 Subtype_Mark => New_Occurrence_Of (CW_Typ, Loc),
21507 Expression => New_Occurrence_Of (Ent, Loc)));
21508 Set_Etype (N, CW_Typ);
21509 end if;
21510 end if;
21512 return OK;
21513 end Replace_Type;
21515 procedure Replace_Types is new Traverse_Proc (Replace_Type);
21517 -- Start of processing for Process_Class_Wide_Condition
21519 begin
21520 -- The subprogram subject to Pre'Class/Post'Class does not have a
21521 -- dispatching type, therefore the aspect/pragma is illegal.
21523 if No (Disp_Typ) then
21524 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
21526 if From_Aspect_Specification (N) then
21527 Error_Msg_N
21528 ("aspect % can only be specified for a primitive operation "
21529 & "of a tagged type", Corresponding_Aspect (N));
21531 -- The pragma is a source construct
21533 else
21534 Error_Msg_N
21535 ("pragma % can only be specified for a primitive operation "
21536 & "of a tagged type", N);
21537 end if;
21538 end if;
21540 Replace_Types (Expr);
21541 end Process_Class_Wide_Condition;
21543 -- Local variables
21545 Subp_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
21546 Expr : constant Node_Id :=
21547 Expression (Get_Argument (N, Defining_Entity (Subp_Decl)));
21548 Spec_Id : constant Entity_Id := Corresponding_Spec_Of (Subp_Decl);
21550 Restore_Scope : Boolean := False;
21551 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
21553 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
21555 begin
21556 -- Ensure that the subprogram and its formals are visible when analyzing
21557 -- the expression of the pragma.
21559 if not In_Open_Scopes (Spec_Id) then
21560 Restore_Scope := True;
21561 Push_Scope (Spec_Id);
21563 if Is_Generic_Subprogram (Spec_Id) then
21564 Install_Generic_Formals (Spec_Id);
21565 else
21566 Install_Formals (Spec_Id);
21567 end if;
21568 end if;
21570 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
21572 -- For a class-wide condition, a reference to a controlling formal must
21573 -- be interpreted as having the class-wide type (or an access to such)
21574 -- so that the inherited condition can be properly applied to any
21575 -- overriding operation (see ARM12 6.6.1 (7)).
21577 if Class_Present (N) then
21578 Process_Class_Wide_Condition (Expr, Spec_Id, Subp_Decl);
21579 end if;
21581 -- Currently it is not possible to inline pre/postconditions on a
21582 -- subprogram subject to pragma Inline_Always.
21584 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
21586 -- Remove the subprogram from the scope stack now that the pre-analysis
21587 -- of the precondition/postcondition is done.
21589 if Restore_Scope then
21590 End_Scope;
21591 end if;
21592 end Analyze_Pre_Post_Condition_In_Decl_Part;
21594 ------------------------------------------
21595 -- Analyze_Refined_Depends_In_Decl_Part --
21596 ------------------------------------------
21598 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
21599 Body_Inputs : Elist_Id := No_Elist;
21600 Body_Outputs : Elist_Id := No_Elist;
21601 -- The inputs and outputs of the subprogram body synthesized from pragma
21602 -- Refined_Depends.
21604 Dependencies : List_Id := No_List;
21605 Depends : Node_Id;
21606 -- The corresponding Depends pragma along with its clauses
21608 Matched_Items : Elist_Id := No_Elist;
21609 -- A list containing the entities of all successfully matched items
21610 -- found in pragma Depends.
21612 Refinements : List_Id := No_List;
21613 -- The clauses of pragma Refined_Depends
21615 Spec_Id : Entity_Id;
21616 -- The entity of the subprogram subject to pragma Refined_Depends
21618 Spec_Inputs : Elist_Id := No_Elist;
21619 Spec_Outputs : Elist_Id := No_Elist;
21620 -- The inputs and outputs of the subprogram spec synthesized from pragma
21621 -- Depends.
21623 procedure Check_Dependency_Clause (Dep_Clause : Node_Id);
21624 -- Try to match a single dependency clause Dep_Clause against one or
21625 -- more refinement clauses found in list Refinements. Each successful
21626 -- match eliminates at least one refinement clause from Refinements.
21628 procedure Check_Output_States;
21629 -- Determine whether pragma Depends contains an output state with a
21630 -- visible refinement and if so, ensure that pragma Refined_Depends
21631 -- mentions all its constituents as outputs.
21633 procedure Normalize_Clauses (Clauses : List_Id);
21634 -- Given a list of dependence or refinement clauses Clauses, normalize
21635 -- each clause by creating multiple dependencies with exactly one input
21636 -- and one output.
21638 procedure Report_Extra_Clauses;
21639 -- Emit an error for each extra clause found in list Refinements
21641 -----------------------------
21642 -- Check_Dependency_Clause --
21643 -----------------------------
21645 procedure Check_Dependency_Clause (Dep_Clause : Node_Id) is
21646 Dep_Input : constant Node_Id := Expression (Dep_Clause);
21647 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
21649 function Is_In_Out_State_Clause return Boolean;
21650 -- Determine whether dependence clause Dep_Clause denotes an abstract
21651 -- state that depends on itself (State => State).
21653 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
21654 -- Determine whether item Item denotes an abstract state with visible
21655 -- null refinement.
21657 procedure Match_Items
21658 (Dep_Item : Node_Id;
21659 Ref_Item : Node_Id;
21660 Matched : out Boolean);
21661 -- Try to match dependence item Dep_Item against refinement item
21662 -- Ref_Item. To match against a possible null refinement (see 2, 7),
21663 -- set Ref_Item to Empty. Flag Matched is set to True when one of
21664 -- the following conformance scenarios is in effect:
21665 -- 1) Both items denote null
21666 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
21667 -- 3) Both items denote attribute 'Result
21668 -- 4) Both items denote the same formal parameter
21669 -- 5) Both items denote the same variable
21670 -- 6) Dep_Item is an abstract state with visible null refinement
21671 -- and Ref_Item denotes null.
21672 -- 7) Dep_Item is an abstract state with visible null refinement
21673 -- and Ref_Item is Empty (special case).
21674 -- 8) Dep_Item is an abstract state with visible non-null
21675 -- refinement and Ref_Item denotes one of its constituents.
21676 -- 9) Dep_Item is an abstract state without a visible refinement
21677 -- and Ref_Item denotes the same state.
21678 -- When scenario 8 is in effect, the entity of the abstract state
21679 -- denoted by Dep_Item is added to list Refined_States.
21681 procedure Record_Item (Item_Id : Entity_Id);
21682 -- Store the entity of an item denoted by Item_Id in Matched_Items
21684 ----------------------------
21685 -- Is_In_Out_State_Clause --
21686 ----------------------------
21688 function Is_In_Out_State_Clause return Boolean is
21689 Dep_Input_Id : Entity_Id;
21690 Dep_Output_Id : Entity_Id;
21692 begin
21693 -- Detect the following clause:
21694 -- State => State
21696 if Is_Entity_Name (Dep_Input)
21697 and then Is_Entity_Name (Dep_Output)
21698 then
21699 -- Handle abstract views generated for limited with clauses
21701 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
21702 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
21704 return
21705 Ekind (Dep_Input_Id) = E_Abstract_State
21706 and then Dep_Input_Id = Dep_Output_Id;
21707 else
21708 return False;
21709 end if;
21710 end Is_In_Out_State_Clause;
21712 ---------------------------
21713 -- Is_Null_Refined_State --
21714 ---------------------------
21716 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
21717 Item_Id : Entity_Id;
21719 begin
21720 if Is_Entity_Name (Item) then
21722 -- Handle abstract views generated for limited with clauses
21724 Item_Id := Available_View (Entity_Of (Item));
21726 return Ekind (Item_Id) = E_Abstract_State
21727 and then Has_Null_Refinement (Item_Id);
21729 else
21730 return False;
21731 end if;
21732 end Is_Null_Refined_State;
21734 -----------------
21735 -- Match_Items --
21736 -----------------
21738 procedure Match_Items
21739 (Dep_Item : Node_Id;
21740 Ref_Item : Node_Id;
21741 Matched : out Boolean)
21743 Dep_Item_Id : Entity_Id;
21744 Ref_Item_Id : Entity_Id;
21746 begin
21747 -- Assume that the two items do not match
21749 Matched := False;
21751 -- A null matches null or Empty (special case)
21753 if Nkind (Dep_Item) = N_Null
21754 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
21755 then
21756 Matched := True;
21758 -- Attribute 'Result matches attribute 'Result
21760 elsif Is_Attribute_Result (Dep_Item)
21761 and then Is_Attribute_Result (Dep_Item)
21762 then
21763 Matched := True;
21765 -- Abstract states, formal parameters and variables
21767 elsif Is_Entity_Name (Dep_Item) then
21769 -- Handle abstract views generated for limited with clauses
21771 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
21773 if Ekind (Dep_Item_Id) = E_Abstract_State then
21775 -- An abstract state with visible null refinement matches
21776 -- null or Empty (special case).
21778 if Has_Null_Refinement (Dep_Item_Id)
21779 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
21780 then
21781 Record_Item (Dep_Item_Id);
21782 Matched := True;
21784 -- An abstract state with visible non-null refinement
21785 -- matches one of its constituents.
21787 elsif Has_Non_Null_Refinement (Dep_Item_Id) then
21788 if Is_Entity_Name (Ref_Item) then
21789 Ref_Item_Id := Entity_Of (Ref_Item);
21791 if Ekind_In (Ref_Item_Id, E_Abstract_State, E_Variable)
21792 and then Present (Encapsulating_State (Ref_Item_Id))
21793 and then Encapsulating_State (Ref_Item_Id) =
21794 Dep_Item_Id
21795 then
21796 Record_Item (Dep_Item_Id);
21797 Matched := True;
21798 end if;
21799 end if;
21801 -- An abstract state without a visible refinement matches
21802 -- itself.
21804 elsif Is_Entity_Name (Ref_Item)
21805 and then Entity_Of (Ref_Item) = Dep_Item_Id
21806 then
21807 Record_Item (Dep_Item_Id);
21808 Matched := True;
21809 end if;
21811 -- A formal parameter or a variable matches itself
21813 elsif Is_Entity_Name (Ref_Item)
21814 and then Entity_Of (Ref_Item) = Dep_Item_Id
21815 then
21816 Record_Item (Dep_Item_Id);
21817 Matched := True;
21818 end if;
21819 end if;
21820 end Match_Items;
21822 -----------------
21823 -- Record_Item --
21824 -----------------
21826 procedure Record_Item (Item_Id : Entity_Id) is
21827 begin
21828 if not Contains (Matched_Items, Item_Id) then
21829 Add_Item (Item_Id, Matched_Items);
21830 end if;
21831 end Record_Item;
21833 -- Local variables
21835 Clause_Matched : Boolean := False;
21836 Dummy : Boolean := False;
21837 Inputs_Match : Boolean;
21838 Next_Ref_Clause : Node_Id;
21839 Outputs_Match : Boolean;
21840 Ref_Clause : Node_Id;
21841 Ref_Input : Node_Id;
21842 Ref_Output : Node_Id;
21844 -- Start of processing for Check_Dependency_Clause
21846 begin
21847 -- Examine all refinement clauses and compare them against the
21848 -- dependence clause.
21850 Ref_Clause := First (Refinements);
21851 while Present (Ref_Clause) loop
21852 Next_Ref_Clause := Next (Ref_Clause);
21854 -- Obtain the attributes of the current refinement clause
21856 Ref_Input := Expression (Ref_Clause);
21857 Ref_Output := First (Choices (Ref_Clause));
21859 -- The current refinement clause matches the dependence clause
21860 -- when both outputs match and both inputs match. See routine
21861 -- Match_Items for all possible conformance scenarios.
21863 -- Depends Dep_Output => Dep_Input
21864 -- ^ ^
21865 -- match ? match ?
21866 -- v v
21867 -- Refined_Depends Ref_Output => Ref_Input
21869 Match_Items
21870 (Dep_Item => Dep_Input,
21871 Ref_Item => Ref_Input,
21872 Matched => Inputs_Match);
21874 Match_Items
21875 (Dep_Item => Dep_Output,
21876 Ref_Item => Ref_Output,
21877 Matched => Outputs_Match);
21879 -- An In_Out state clause may be matched against a refinement with
21880 -- a null input or null output as long as the non-null side of the
21881 -- relation contains a valid constituent of the In_Out_State.
21883 if Is_In_Out_State_Clause then
21885 -- Depends => (State => State)
21886 -- Refined_Depends => (null => Constit) -- OK
21888 if Inputs_Match
21889 and then not Outputs_Match
21890 and then Nkind (Ref_Output) = N_Null
21891 then
21892 Outputs_Match := True;
21893 end if;
21895 -- Depends => (State => State)
21896 -- Refined_Depends => (Constit => null) -- OK
21898 if not Inputs_Match
21899 and then Outputs_Match
21900 and then Nkind (Ref_Input) = N_Null
21901 then
21902 Inputs_Match := True;
21903 end if;
21904 end if;
21906 -- The current refinement clause is legally constructed following
21907 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
21908 -- the pool of candidates. The seach continues because a single
21909 -- dependence clause may have multiple matching refinements.
21911 if Inputs_Match and then Outputs_Match then
21912 Clause_Matched := True;
21913 Remove (Ref_Clause);
21914 end if;
21916 Ref_Clause := Next_Ref_Clause;
21917 end loop;
21919 -- Depending on the order or composition of refinement clauses, an
21920 -- In_Out state clause may not be directly refinable.
21922 -- Depends => ((Output, State) => (Input, State))
21923 -- Refined_State => (State => (Constit_1, Constit_2))
21924 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
21926 -- Matching normalized clause (State => State) fails because there is
21927 -- no direct refinement capable of satisfying this relation. Another
21928 -- similar case arises when clauses (Constit_1 => Input) and (Output
21929 -- => Constit_2) are matched first, leaving no candidates for clause
21930 -- (State => State). Both scenarios are legal as long as one of the
21931 -- previous clauses mentioned a valid constituent of State.
21933 if not Clause_Matched
21934 and then Is_In_Out_State_Clause
21935 and then
21936 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
21937 then
21938 Clause_Matched := True;
21939 end if;
21941 -- A clause where the input is an abstract state with visible null
21942 -- refinement is implicitly matched when the output has already been
21943 -- matched in a previous clause.
21945 -- Depends => (Output => State) -- implicitly OK
21946 -- Refined_State => (State => null)
21947 -- Refined_Depends => (Output => ...)
21949 if not Clause_Matched
21950 and then Is_Null_Refined_State (Dep_Input)
21951 and then Is_Entity_Name (Dep_Output)
21952 and then
21953 Contains (Matched_Items, Available_View (Entity_Of (Dep_Output)))
21954 then
21955 Clause_Matched := True;
21956 end if;
21958 -- A clause where the output is an abstract state with visible null
21959 -- refinement is implicitly matched when the input has already been
21960 -- matched in a previous clause.
21962 -- Depends => (State => Input) -- implicitly OK
21963 -- Refined_State => (State => null)
21964 -- Refined_Depends => (... => Input)
21966 if not Clause_Matched
21967 and then Is_Null_Refined_State (Dep_Output)
21968 and then Is_Entity_Name (Dep_Input)
21969 and then
21970 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
21971 then
21972 Clause_Matched := True;
21973 end if;
21975 -- At this point either all refinement clauses have been examined or
21976 -- pragma Refined_Depends contains a solitary null. Only an abstract
21977 -- state with null refinement can possibly match these cases.
21979 -- Depends => (State => null)
21980 -- Refined_State => (State => null)
21981 -- Refined_Depends => null -- OK
21983 if not Clause_Matched then
21984 Match_Items
21985 (Dep_Item => Dep_Input,
21986 Ref_Item => Empty,
21987 Matched => Inputs_Match);
21989 Match_Items
21990 (Dep_Item => Dep_Output,
21991 Ref_Item => Empty,
21992 Matched => Outputs_Match);
21994 Clause_Matched := Inputs_Match and Outputs_Match;
21995 end if;
21997 -- If the contents of Refined_Depends are legal, then the current
21998 -- dependence clause should be satisfied either by an explicit match
21999 -- or by one of the special cases.
22001 if not Clause_Matched then
22002 SPARK_Msg_NE
22003 ("dependence clause of subprogram & has no matching refinement "
22004 & "in body", Dep_Clause, Spec_Id);
22005 end if;
22006 end Check_Dependency_Clause;
22008 -------------------------
22009 -- Check_Output_States --
22010 -------------------------
22012 procedure Check_Output_States is
22013 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22014 -- Determine whether all constituents of state State_Id with visible
22015 -- refinement are used as outputs in pragma Refined_Depends. Emit an
22016 -- error if this is not the case.
22018 -----------------------------
22019 -- Check_Constituent_Usage --
22020 -----------------------------
22022 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22023 Constit_Elmt : Elmt_Id;
22024 Constit_Id : Entity_Id;
22025 Posted : Boolean := False;
22027 begin
22028 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22029 while Present (Constit_Elmt) loop
22030 Constit_Id := Node (Constit_Elmt);
22032 -- The constituent acts as an input (SPARK RM 7.2.5(3))
22034 if Present (Body_Inputs)
22035 and then Appears_In (Body_Inputs, Constit_Id)
22036 then
22037 Error_Msg_Name_1 := Chars (State_Id);
22038 SPARK_Msg_NE
22039 ("constituent & of state % must act as output in "
22040 & "dependence refinement", N, Constit_Id);
22042 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
22044 elsif No (Body_Outputs)
22045 or else not Appears_In (Body_Outputs, Constit_Id)
22046 then
22047 if not Posted then
22048 Posted := True;
22049 SPARK_Msg_NE
22050 ("output state & must be replaced by all its "
22051 & "constituents in dependence refinement",
22052 N, State_Id);
22053 end if;
22055 SPARK_Msg_NE
22056 ("\constituent & is missing in output list",
22057 N, Constit_Id);
22058 end if;
22060 Next_Elmt (Constit_Elmt);
22061 end loop;
22062 end Check_Constituent_Usage;
22064 -- Local variables
22066 Item : Node_Id;
22067 Item_Elmt : Elmt_Id;
22068 Item_Id : Entity_Id;
22070 -- Start of processing for Check_Output_States
22072 begin
22073 -- Inspect the outputs of pragma Depends looking for a state with a
22074 -- visible refinement.
22076 if Present (Spec_Outputs) then
22077 Item_Elmt := First_Elmt (Spec_Outputs);
22078 while Present (Item_Elmt) loop
22079 Item := Node (Item_Elmt);
22081 -- Deal with the mixed nature of the input and output lists
22083 if Nkind (Item) = N_Defining_Identifier then
22084 Item_Id := Item;
22085 else
22086 Item_Id := Available_View (Entity_Of (Item));
22087 end if;
22089 if Ekind (Item_Id) = E_Abstract_State then
22091 -- The state acts as an input-output, skip it
22093 if Present (Spec_Inputs)
22094 and then Appears_In (Spec_Inputs, Item_Id)
22095 then
22096 null;
22098 -- Ensure that all of the constituents are utilized as
22099 -- outputs in pragma Refined_Depends.
22101 elsif Has_Non_Null_Refinement (Item_Id) then
22102 Check_Constituent_Usage (Item_Id);
22103 end if;
22104 end if;
22106 Next_Elmt (Item_Elmt);
22107 end loop;
22108 end if;
22109 end Check_Output_States;
22111 -----------------------
22112 -- Normalize_Clauses --
22113 -----------------------
22115 procedure Normalize_Clauses (Clauses : List_Id) is
22116 procedure Normalize_Inputs (Clause : Node_Id);
22117 -- Normalize clause Clause by creating multiple clauses for each
22118 -- input item of Clause. It is assumed that Clause has exactly one
22119 -- output. The transformation is as follows:
22121 -- Output => (Input_1, Input_2) -- original
22123 -- Output => Input_1 -- normalizations
22124 -- Output => Input_2
22126 procedure Normalize_Outputs (Clause : Node_Id);
22127 -- Normalize clause Clause by creating multiple clause for each
22128 -- output item of Clause. The transformation is as follows:
22130 -- (Output_1, Output_2) => Input -- original
22132 -- Output_1 => Input -- normalization
22133 -- Output_2 => Input
22135 ----------------------
22136 -- Normalize_Inputs --
22137 ----------------------
22139 procedure Normalize_Inputs (Clause : Node_Id) is
22140 Inputs : constant Node_Id := Expression (Clause);
22141 Loc : constant Source_Ptr := Sloc (Clause);
22142 Output : constant List_Id := Choices (Clause);
22143 Last_Input : Node_Id;
22144 Input : Node_Id;
22145 New_Clause : Node_Id;
22146 Next_Input : Node_Id;
22148 begin
22149 -- Normalization is performed only when the original clause has
22150 -- more than one input. Multiple inputs appear as an aggregate.
22152 if Nkind (Inputs) = N_Aggregate then
22153 Last_Input := Last (Expressions (Inputs));
22155 -- Create a new clause for each input
22157 Input := First (Expressions (Inputs));
22158 while Present (Input) loop
22159 Next_Input := Next (Input);
22161 -- Unhook the current input from the original input list
22162 -- because it will be relocated to a new clause.
22164 Remove (Input);
22166 -- Special processing for the last input. At this point the
22167 -- original aggregate has been stripped down to one element.
22168 -- Replace the aggregate by the element itself.
22170 if Input = Last_Input then
22171 Rewrite (Inputs, Input);
22173 -- Generate a clause of the form:
22174 -- Output => Input
22176 else
22177 New_Clause :=
22178 Make_Component_Association (Loc,
22179 Choices => New_Copy_List_Tree (Output),
22180 Expression => Input);
22182 -- The new clause contains replicated content that has
22183 -- already been analyzed, mark the clause as analyzed.
22185 Set_Analyzed (New_Clause);
22186 Insert_After (Clause, New_Clause);
22187 end if;
22189 Input := Next_Input;
22190 end loop;
22191 end if;
22192 end Normalize_Inputs;
22194 -----------------------
22195 -- Normalize_Outputs --
22196 -----------------------
22198 procedure Normalize_Outputs (Clause : Node_Id) is
22199 Inputs : constant Node_Id := Expression (Clause);
22200 Loc : constant Source_Ptr := Sloc (Clause);
22201 Outputs : constant Node_Id := First (Choices (Clause));
22202 Last_Output : Node_Id;
22203 New_Clause : Node_Id;
22204 Next_Output : Node_Id;
22205 Output : Node_Id;
22207 begin
22208 -- Multiple outputs appear as an aggregate. Nothing to do when
22209 -- the clause has exactly one output.
22211 if Nkind (Outputs) = N_Aggregate then
22212 Last_Output := Last (Expressions (Outputs));
22214 -- Create a clause for each output. Note that each time a new
22215 -- clause is created, the original output list slowly shrinks
22216 -- until there is one item left.
22218 Output := First (Expressions (Outputs));
22219 while Present (Output) loop
22220 Next_Output := Next (Output);
22222 -- Unhook the output from the original output list as it
22223 -- will be relocated to a new clause.
22225 Remove (Output);
22227 -- Special processing for the last output. At this point
22228 -- the original aggregate has been stripped down to one
22229 -- element. Replace the aggregate by the element itself.
22231 if Output = Last_Output then
22232 Rewrite (Outputs, Output);
22234 else
22235 -- Generate a clause of the form:
22236 -- (Output => Inputs)
22238 New_Clause :=
22239 Make_Component_Association (Loc,
22240 Choices => New_List (Output),
22241 Expression => New_Copy_Tree (Inputs));
22243 -- The new clause contains replicated content that has
22244 -- already been analyzed. There is not need to reanalyze
22245 -- them.
22247 Set_Analyzed (New_Clause);
22248 Insert_After (Clause, New_Clause);
22249 end if;
22251 Output := Next_Output;
22252 end loop;
22253 end if;
22254 end Normalize_Outputs;
22256 -- Local variables
22258 Clause : Node_Id;
22260 -- Start of processing for Normalize_Clauses
22262 begin
22263 Clause := First (Clauses);
22264 while Present (Clause) loop
22265 Normalize_Outputs (Clause);
22266 Next (Clause);
22267 end loop;
22269 Clause := First (Clauses);
22270 while Present (Clause) loop
22271 Normalize_Inputs (Clause);
22272 Next (Clause);
22273 end loop;
22274 end Normalize_Clauses;
22276 --------------------------
22277 -- Report_Extra_Clauses --
22278 --------------------------
22280 procedure Report_Extra_Clauses is
22281 Clause : Node_Id;
22283 begin
22284 if Present (Refinements) then
22285 Clause := First (Refinements);
22286 while Present (Clause) loop
22288 -- Do not complain about a null input refinement, since a null
22289 -- input legitimately matches anything.
22291 if Nkind (Clause) /= N_Component_Association
22292 or else Nkind (Expression (Clause)) /= N_Null
22293 then
22294 SPARK_Msg_N
22295 ("unmatched or extra clause in dependence refinement",
22296 Clause);
22297 end if;
22299 Next (Clause);
22300 end loop;
22301 end if;
22302 end Report_Extra_Clauses;
22304 -- Local variables
22306 Body_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
22307 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
22308 Errors : constant Nat := Serious_Errors_Detected;
22309 Refs : constant Node_Id := Expression (Get_Argument (N));
22310 Clause : Node_Id;
22311 Deps : Node_Id;
22312 Dummy : Boolean;
22314 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
22316 begin
22317 if Nkind (Body_Decl) = N_Subprogram_Body_Stub then
22318 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
22319 else
22320 Spec_Id := Corresponding_Spec (Body_Decl);
22321 end if;
22323 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
22325 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
22326 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
22328 if No (Depends) then
22329 SPARK_Msg_NE
22330 ("useless refinement, declaration of subprogram & lacks aspect or "
22331 & "pragma Depends", N, Spec_Id);
22332 return;
22333 end if;
22335 Deps := Expression (Get_Argument (Depends));
22337 -- A null dependency relation renders the refinement useless because it
22338 -- cannot possibly mention abstract states with visible refinement. Note
22339 -- that the inverse is not true as states may be refined to null
22340 -- (SPARK RM 7.2.5(2)).
22342 if Nkind (Deps) = N_Null then
22343 SPARK_Msg_NE
22344 ("useless refinement, subprogram & does not depend on abstract "
22345 & "state with visible refinement", N, Spec_Id);
22346 return;
22347 end if;
22349 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
22350 -- This ensures that the categorization of all refined dependency items
22351 -- is consistent with their role.
22353 Analyze_Depends_In_Decl_Part (N);
22355 -- Do not match dependencies against refinements if Refined_Depends is
22356 -- illegal to avoid emitting misleading error.
22358 if Serious_Errors_Detected = Errors then
22360 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
22361 -- the inputs and outputs of the subprogram spec and body to verify
22362 -- the use of states with visible refinement and their constituents.
22364 if No (Get_Pragma (Spec_Id, Pragma_Global))
22365 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
22366 then
22367 Collect_Subprogram_Inputs_Outputs
22368 (Subp_Id => Spec_Id,
22369 Synthesize => True,
22370 Subp_Inputs => Spec_Inputs,
22371 Subp_Outputs => Spec_Outputs,
22372 Global_Seen => Dummy);
22374 Collect_Subprogram_Inputs_Outputs
22375 (Subp_Id => Body_Id,
22376 Synthesize => True,
22377 Subp_Inputs => Body_Inputs,
22378 Subp_Outputs => Body_Outputs,
22379 Global_Seen => Dummy);
22381 -- For an output state with a visible refinement, ensure that all
22382 -- constituents appear as outputs in the dependency refinement.
22384 Check_Output_States;
22385 end if;
22387 -- Matching is disabled in ASIS because clauses are not normalized as
22388 -- this is a tree altering activity similar to expansion.
22390 if ASIS_Mode then
22391 return;
22392 end if;
22394 -- Multiple dependency clauses appear as component associations of an
22395 -- aggregate. Note that the clauses are copied because the algorithm
22396 -- modifies them and this should not be visible in Depends.
22398 pragma Assert (Nkind (Deps) = N_Aggregate);
22399 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
22400 Normalize_Clauses (Dependencies);
22402 if Nkind (Refs) = N_Null then
22403 Refinements := No_List;
22405 -- Multiple dependency clauses appear as component associations of an
22406 -- aggregate. Note that the clauses are copied because the algorithm
22407 -- modifies them and this should not be visible in Refined_Depends.
22409 else pragma Assert (Nkind (Refs) = N_Aggregate);
22410 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
22411 Normalize_Clauses (Refinements);
22412 end if;
22414 -- At this point the clauses of pragmas Depends and Refined_Depends
22415 -- have been normalized into simple dependencies between one output
22416 -- and one input. Examine all clauses of pragma Depends looking for
22417 -- matching clauses in pragma Refined_Depends.
22419 Clause := First (Dependencies);
22420 while Present (Clause) loop
22421 Check_Dependency_Clause (Clause);
22422 Next (Clause);
22423 end loop;
22425 if Serious_Errors_Detected = Errors then
22426 Report_Extra_Clauses;
22427 end if;
22428 end if;
22429 end Analyze_Refined_Depends_In_Decl_Part;
22431 -----------------------------------------
22432 -- Analyze_Refined_Global_In_Decl_Part --
22433 -----------------------------------------
22435 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
22436 Global : Node_Id;
22437 -- The corresponding Global pragma
22439 Has_In_State : Boolean := False;
22440 Has_In_Out_State : Boolean := False;
22441 Has_Out_State : Boolean := False;
22442 Has_Proof_In_State : Boolean := False;
22443 -- These flags are set when the corresponding Global pragma has a state
22444 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
22445 -- refinement.
22447 Has_Null_State : Boolean := False;
22448 -- This flag is set when the corresponding Global pragma has at least
22449 -- one state with a null refinement.
22451 In_Constits : Elist_Id := No_Elist;
22452 In_Out_Constits : Elist_Id := No_Elist;
22453 Out_Constits : Elist_Id := No_Elist;
22454 Proof_In_Constits : Elist_Id := No_Elist;
22455 -- These lists contain the entities of all Input, In_Out, Output and
22456 -- Proof_In constituents that appear in Refined_Global and participate
22457 -- in state refinement.
22459 In_Items : Elist_Id := No_Elist;
22460 In_Out_Items : Elist_Id := No_Elist;
22461 Out_Items : Elist_Id := No_Elist;
22462 Proof_In_Items : Elist_Id := No_Elist;
22463 -- These list contain the entities of all Input, In_Out, Output and
22464 -- Proof_In items defined in the corresponding Global pragma.
22466 procedure Check_In_Out_States;
22467 -- Determine whether the corresponding Global pragma mentions In_Out
22468 -- states with visible refinement and if so, ensure that one of the
22469 -- following completions apply to the constituents of the state:
22470 -- 1) there is at least one constituent of mode In_Out
22471 -- 2) there is at least one Input and one Output constituent
22472 -- 3) not all constituents are present and one of them is of mode
22473 -- Output.
22474 -- This routine may remove elements from In_Constits, In_Out_Constits,
22475 -- Out_Constits and Proof_In_Constits.
22477 procedure Check_Input_States;
22478 -- Determine whether the corresponding Global pragma mentions Input
22479 -- states with visible refinement and if so, ensure that at least one of
22480 -- its constituents appears as an Input item in Refined_Global.
22481 -- This routine may remove elements from In_Constits, In_Out_Constits,
22482 -- Out_Constits and Proof_In_Constits.
22484 procedure Check_Output_States;
22485 -- Determine whether the corresponding Global pragma mentions Output
22486 -- states with visible refinement and if so, ensure that all of its
22487 -- constituents appear as Output items in Refined_Global.
22488 -- This routine may remove elements from In_Constits, In_Out_Constits,
22489 -- Out_Constits and Proof_In_Constits.
22491 procedure Check_Proof_In_States;
22492 -- Determine whether the corresponding Global pragma mentions Proof_In
22493 -- states with visible refinement and if so, ensure that at least one of
22494 -- its constituents appears as a Proof_In item in Refined_Global.
22495 -- This routine may remove elements from In_Constits, In_Out_Constits,
22496 -- Out_Constits and Proof_In_Constits.
22498 procedure Check_Refined_Global_List
22499 (List : Node_Id;
22500 Global_Mode : Name_Id := Name_Input);
22501 -- Verify the legality of a single global list declaration. Global_Mode
22502 -- denotes the current mode in effect.
22504 procedure Collect_Global_Items (Prag : Node_Id);
22505 -- Gather all input, in out, output and Proof_In items of pragma Prag
22506 -- in lists In_Items, In_Out_Items, Out_Items and Proof_In_Items. Flags
22507 -- Has_In_State, Has_In_Out_State, Has_Out_State and Has_Proof_In_State
22508 -- are set when there is at least one abstract state with visible
22509 -- refinement available in the corresponding mode. Flag Has_Null_State
22510 -- is set when at least state has a null refinement.
22512 function Present_Then_Remove
22513 (List : Elist_Id;
22514 Item : Entity_Id) return Boolean;
22515 -- Search List for a particular entity Item. If Item has been found,
22516 -- remove it from List. This routine is used to strip lists In_Constits,
22517 -- In_Out_Constits and Out_Constits of valid constituents.
22519 procedure Report_Extra_Constituents;
22520 -- Emit an error for each constituent found in lists In_Constits,
22521 -- In_Out_Constits and Out_Constits.
22523 -------------------------
22524 -- Check_In_Out_States --
22525 -------------------------
22527 procedure Check_In_Out_States is
22528 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22529 -- Determine whether one of the following coverage scenarios is in
22530 -- effect:
22531 -- 1) there is at least one constituent of mode In_Out
22532 -- 2) there is at least one Input and one Output constituent
22533 -- 3) not all constituents are present and one of them is of mode
22534 -- Output.
22535 -- If this is not the case, emit an error.
22537 -----------------------------
22538 -- Check_Constituent_Usage --
22539 -----------------------------
22541 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22542 Constit_Elmt : Elmt_Id;
22543 Constit_Id : Entity_Id;
22544 Has_Missing : Boolean := False;
22545 In_Out_Seen : Boolean := False;
22546 In_Seen : Boolean := False;
22547 Out_Seen : Boolean := False;
22549 begin
22550 -- Process all the constituents of the state and note their modes
22551 -- within the global refinement.
22553 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22554 while Present (Constit_Elmt) loop
22555 Constit_Id := Node (Constit_Elmt);
22557 if Present_Then_Remove (In_Constits, Constit_Id) then
22558 In_Seen := True;
22560 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
22561 In_Out_Seen := True;
22563 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
22564 Out_Seen := True;
22566 -- A Proof_In constituent cannot participate in the completion
22567 -- of an Output state (SPARK RM 7.2.4(5)).
22569 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id) then
22570 Error_Msg_Name_1 := Chars (State_Id);
22571 SPARK_Msg_NE
22572 ("constituent & of state % must have mode Input, In_Out "
22573 & "or Output in global refinement",
22574 N, Constit_Id);
22576 else
22577 Has_Missing := True;
22578 end if;
22580 Next_Elmt (Constit_Elmt);
22581 end loop;
22583 -- A single In_Out constituent is a valid completion
22585 if In_Out_Seen then
22586 null;
22588 -- A pair of one Input and one Output constituent is a valid
22589 -- completion.
22591 elsif In_Seen and then Out_Seen then
22592 null;
22594 -- A single Output constituent is a valid completion only when
22595 -- some of the other constituents are missing (SPARK RM 7.2.4(5)).
22597 elsif Has_Missing and then Out_Seen then
22598 null;
22600 else
22601 SPARK_Msg_NE
22602 ("global refinement of state & redefines the mode of its "
22603 & "constituents", N, State_Id);
22604 end if;
22605 end Check_Constituent_Usage;
22607 -- Local variables
22609 Item_Elmt : Elmt_Id;
22610 Item_Id : Entity_Id;
22612 -- Start of processing for Check_In_Out_States
22614 begin
22615 -- Inspect the In_Out items of the corresponding Global pragma
22616 -- looking for a state with a visible refinement.
22618 if Has_In_Out_State and then Present (In_Out_Items) then
22619 Item_Elmt := First_Elmt (In_Out_Items);
22620 while Present (Item_Elmt) loop
22621 Item_Id := Node (Item_Elmt);
22623 -- Ensure that one of the three coverage variants is satisfied
22625 if Ekind (Item_Id) = E_Abstract_State
22626 and then Has_Non_Null_Refinement (Item_Id)
22627 then
22628 Check_Constituent_Usage (Item_Id);
22629 end if;
22631 Next_Elmt (Item_Elmt);
22632 end loop;
22633 end if;
22634 end Check_In_Out_States;
22636 ------------------------
22637 -- Check_Input_States --
22638 ------------------------
22640 procedure Check_Input_States is
22641 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22642 -- Determine whether at least one constituent of state State_Id with
22643 -- visible refinement is used and has mode Input. Ensure that the
22644 -- remaining constituents do not have In_Out, Output or Proof_In
22645 -- modes.
22647 -----------------------------
22648 -- Check_Constituent_Usage --
22649 -----------------------------
22651 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22652 Constit_Elmt : Elmt_Id;
22653 Constit_Id : Entity_Id;
22654 In_Seen : Boolean := False;
22656 begin
22657 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22658 while Present (Constit_Elmt) loop
22659 Constit_Id := Node (Constit_Elmt);
22661 -- At least one of the constituents appears as an Input
22663 if Present_Then_Remove (In_Constits, Constit_Id) then
22664 In_Seen := True;
22666 -- The constituent appears in the global refinement, but has
22667 -- mode In_Out, Output or Proof_In (SPARK RM 7.2.4(5)).
22669 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
22670 or else Present_Then_Remove (Out_Constits, Constit_Id)
22671 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
22672 then
22673 Error_Msg_Name_1 := Chars (State_Id);
22674 SPARK_Msg_NE
22675 ("constituent & of state % must have mode Input in global "
22676 & "refinement", N, Constit_Id);
22677 end if;
22679 Next_Elmt (Constit_Elmt);
22680 end loop;
22682 -- Not one of the constituents appeared as Input
22684 if not In_Seen then
22685 SPARK_Msg_NE
22686 ("global refinement of state & must include at least one "
22687 & "constituent of mode Input", N, State_Id);
22688 end if;
22689 end Check_Constituent_Usage;
22691 -- Local variables
22693 Item_Elmt : Elmt_Id;
22694 Item_Id : Entity_Id;
22696 -- Start of processing for Check_Input_States
22698 begin
22699 -- Inspect the Input items of the corresponding Global pragma
22700 -- looking for a state with a visible refinement.
22702 if Has_In_State and then Present (In_Items) then
22703 Item_Elmt := First_Elmt (In_Items);
22704 while Present (Item_Elmt) loop
22705 Item_Id := Node (Item_Elmt);
22707 -- Ensure that at least one of the constituents is utilized and
22708 -- is of mode Input.
22710 if Ekind (Item_Id) = E_Abstract_State
22711 and then Has_Non_Null_Refinement (Item_Id)
22712 then
22713 Check_Constituent_Usage (Item_Id);
22714 end if;
22716 Next_Elmt (Item_Elmt);
22717 end loop;
22718 end if;
22719 end Check_Input_States;
22721 -------------------------
22722 -- Check_Output_States --
22723 -------------------------
22725 procedure Check_Output_States is
22726 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22727 -- Determine whether all constituents of state State_Id with visible
22728 -- refinement are used and have mode Output. Emit an error if this is
22729 -- not the case.
22731 -----------------------------
22732 -- Check_Constituent_Usage --
22733 -----------------------------
22735 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22736 Constit_Elmt : Elmt_Id;
22737 Constit_Id : Entity_Id;
22738 Posted : Boolean := False;
22740 begin
22741 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22742 while Present (Constit_Elmt) loop
22743 Constit_Id := Node (Constit_Elmt);
22745 if Present_Then_Remove (Out_Constits, Constit_Id) then
22746 null;
22748 -- The constituent appears in the global refinement, but has
22749 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
22751 elsif Present_Then_Remove (In_Constits, Constit_Id)
22752 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
22753 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
22754 then
22755 Error_Msg_Name_1 := Chars (State_Id);
22756 SPARK_Msg_NE
22757 ("constituent & of state % must have mode Output in "
22758 & "global refinement", N, Constit_Id);
22760 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
22762 else
22763 if not Posted then
22764 Posted := True;
22765 SPARK_Msg_NE
22766 ("output state & must be replaced by all its "
22767 & "constituents in global refinement", N, State_Id);
22768 end if;
22770 SPARK_Msg_NE
22771 ("\constituent & is missing in output list",
22772 N, Constit_Id);
22773 end if;
22775 Next_Elmt (Constit_Elmt);
22776 end loop;
22777 end Check_Constituent_Usage;
22779 -- Local variables
22781 Item_Elmt : Elmt_Id;
22782 Item_Id : Entity_Id;
22784 -- Start of processing for Check_Output_States
22786 begin
22787 -- Inspect the Output items of the corresponding Global pragma
22788 -- looking for a state with a visible refinement.
22790 if Has_Out_State and then Present (Out_Items) then
22791 Item_Elmt := First_Elmt (Out_Items);
22792 while Present (Item_Elmt) loop
22793 Item_Id := Node (Item_Elmt);
22795 -- Ensure that all of the constituents are utilized and they
22796 -- have mode Output.
22798 if Ekind (Item_Id) = E_Abstract_State
22799 and then Has_Non_Null_Refinement (Item_Id)
22800 then
22801 Check_Constituent_Usage (Item_Id);
22802 end if;
22804 Next_Elmt (Item_Elmt);
22805 end loop;
22806 end if;
22807 end Check_Output_States;
22809 ---------------------------
22810 -- Check_Proof_In_States --
22811 ---------------------------
22813 procedure Check_Proof_In_States is
22814 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22815 -- Determine whether at least one constituent of state State_Id with
22816 -- visible refinement is used and has mode Proof_In. Ensure that the
22817 -- remaining constituents do not have Input, In_Out or Output modes.
22819 -----------------------------
22820 -- Check_Constituent_Usage --
22821 -----------------------------
22823 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22824 Constit_Elmt : Elmt_Id;
22825 Constit_Id : Entity_Id;
22826 Proof_In_Seen : Boolean := False;
22828 begin
22829 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22830 while Present (Constit_Elmt) loop
22831 Constit_Id := Node (Constit_Elmt);
22833 -- At least one of the constituents appears as Proof_In
22835 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
22836 Proof_In_Seen := True;
22838 -- The constituent appears in the global refinement, but has
22839 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
22841 elsif Present_Then_Remove (In_Constits, Constit_Id)
22842 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
22843 or else Present_Then_Remove (Out_Constits, Constit_Id)
22844 then
22845 Error_Msg_Name_1 := Chars (State_Id);
22846 SPARK_Msg_NE
22847 ("constituent & of state % must have mode Proof_In in "
22848 & "global refinement", N, Constit_Id);
22849 end if;
22851 Next_Elmt (Constit_Elmt);
22852 end loop;
22854 -- Not one of the constituents appeared as Proof_In
22856 if not Proof_In_Seen then
22857 SPARK_Msg_NE
22858 ("global refinement of state & must include at least one "
22859 & "constituent of mode Proof_In", N, State_Id);
22860 end if;
22861 end Check_Constituent_Usage;
22863 -- Local variables
22865 Item_Elmt : Elmt_Id;
22866 Item_Id : Entity_Id;
22868 -- Start of processing for Check_Proof_In_States
22870 begin
22871 -- Inspect the Proof_In items of the corresponding Global pragma
22872 -- looking for a state with a visible refinement.
22874 if Has_Proof_In_State and then Present (Proof_In_Items) then
22875 Item_Elmt := First_Elmt (Proof_In_Items);
22876 while Present (Item_Elmt) loop
22877 Item_Id := Node (Item_Elmt);
22879 -- Ensure that at least one of the constituents is utilized and
22880 -- is of mode Proof_In
22882 if Ekind (Item_Id) = E_Abstract_State
22883 and then Has_Non_Null_Refinement (Item_Id)
22884 then
22885 Check_Constituent_Usage (Item_Id);
22886 end if;
22888 Next_Elmt (Item_Elmt);
22889 end loop;
22890 end if;
22891 end Check_Proof_In_States;
22893 -------------------------------
22894 -- Check_Refined_Global_List --
22895 -------------------------------
22897 procedure Check_Refined_Global_List
22898 (List : Node_Id;
22899 Global_Mode : Name_Id := Name_Input)
22901 procedure Check_Refined_Global_Item
22902 (Item : Node_Id;
22903 Global_Mode : Name_Id);
22904 -- Verify the legality of a single global item declaration. Parameter
22905 -- Global_Mode denotes the current mode in effect.
22907 -------------------------------
22908 -- Check_Refined_Global_Item --
22909 -------------------------------
22911 procedure Check_Refined_Global_Item
22912 (Item : Node_Id;
22913 Global_Mode : Name_Id)
22915 Item_Id : constant Entity_Id := Entity_Of (Item);
22917 procedure Inconsistent_Mode_Error (Expect : Name_Id);
22918 -- Issue a common error message for all mode mismatches. Expect
22919 -- denotes the expected mode.
22921 -----------------------------
22922 -- Inconsistent_Mode_Error --
22923 -----------------------------
22925 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
22926 begin
22927 SPARK_Msg_NE
22928 ("global item & has inconsistent modes", Item, Item_Id);
22930 Error_Msg_Name_1 := Global_Mode;
22931 Error_Msg_Name_2 := Expect;
22932 SPARK_Msg_N ("\expected mode %, found mode %", Item);
22933 end Inconsistent_Mode_Error;
22935 -- Start of processing for Check_Refined_Global_Item
22937 begin
22938 -- When the state or variable acts as a constituent of another
22939 -- state with a visible refinement, collect it for the state
22940 -- completeness checks performed later on.
22942 if Present (Encapsulating_State (Item_Id))
22943 and then Has_Visible_Refinement (Encapsulating_State (Item_Id))
22944 then
22945 if Global_Mode = Name_Input then
22946 Add_Item (Item_Id, In_Constits);
22948 elsif Global_Mode = Name_In_Out then
22949 Add_Item (Item_Id, In_Out_Constits);
22951 elsif Global_Mode = Name_Output then
22952 Add_Item (Item_Id, Out_Constits);
22954 elsif Global_Mode = Name_Proof_In then
22955 Add_Item (Item_Id, Proof_In_Constits);
22956 end if;
22958 -- When not a constituent, ensure that both occurrences of the
22959 -- item in pragmas Global and Refined_Global match.
22961 elsif Contains (In_Items, Item_Id) then
22962 if Global_Mode /= Name_Input then
22963 Inconsistent_Mode_Error (Name_Input);
22964 end if;
22966 elsif Contains (In_Out_Items, Item_Id) then
22967 if Global_Mode /= Name_In_Out then
22968 Inconsistent_Mode_Error (Name_In_Out);
22969 end if;
22971 elsif Contains (Out_Items, Item_Id) then
22972 if Global_Mode /= Name_Output then
22973 Inconsistent_Mode_Error (Name_Output);
22974 end if;
22976 elsif Contains (Proof_In_Items, Item_Id) then
22977 null;
22979 -- The item does not appear in the corresponding Global pragma,
22980 -- it must be an extra (SPARK RM 7.2.4(3)).
22982 else
22983 SPARK_Msg_NE ("extra global item &", Item, Item_Id);
22984 end if;
22985 end Check_Refined_Global_Item;
22987 -- Local variables
22989 Item : Node_Id;
22991 -- Start of processing for Check_Refined_Global_List
22993 begin
22994 if Nkind (List) = N_Null then
22995 null;
22997 -- Single global item declaration
22999 elsif Nkind_In (List, N_Expanded_Name,
23000 N_Identifier,
23001 N_Selected_Component)
23002 then
23003 Check_Refined_Global_Item (List, Global_Mode);
23005 -- Simple global list or moded global list declaration
23007 elsif Nkind (List) = N_Aggregate then
23009 -- The declaration of a simple global list appear as a collection
23010 -- of expressions.
23012 if Present (Expressions (List)) then
23013 Item := First (Expressions (List));
23014 while Present (Item) loop
23015 Check_Refined_Global_Item (Item, Global_Mode);
23017 Next (Item);
23018 end loop;
23020 -- The declaration of a moded global list appears as a collection
23021 -- of component associations where individual choices denote
23022 -- modes.
23024 elsif Present (Component_Associations (List)) then
23025 Item := First (Component_Associations (List));
23026 while Present (Item) loop
23027 Check_Refined_Global_List
23028 (List => Expression (Item),
23029 Global_Mode => Chars (First (Choices (Item))));
23031 Next (Item);
23032 end loop;
23034 -- Invalid tree
23036 else
23037 raise Program_Error;
23038 end if;
23040 -- Invalid list
23042 else
23043 raise Program_Error;
23044 end if;
23045 end Check_Refined_Global_List;
23047 --------------------------
23048 -- Collect_Global_Items --
23049 --------------------------
23051 procedure Collect_Global_Items (Prag : Node_Id) is
23052 procedure Process_Global_List
23053 (List : Node_Id;
23054 Mode : Name_Id := Name_Input);
23055 -- Collect all items housed in a global list. Formal Mode denotes the
23056 -- current mode in effect.
23058 -------------------------
23059 -- Process_Global_List --
23060 -------------------------
23062 procedure Process_Global_List
23063 (List : Node_Id;
23064 Mode : Name_Id := Name_Input)
23066 procedure Process_Global_Item (Item : Node_Id; Mode : Name_Id);
23067 -- Add a single item to the appropriate list. Formal Mode denotes
23068 -- the current mode in effect.
23070 -------------------------
23071 -- Process_Global_Item --
23072 -------------------------
23074 procedure Process_Global_Item (Item : Node_Id; Mode : Name_Id) is
23075 Item_Id : constant Entity_Id :=
23076 Available_View (Entity_Of (Item));
23077 -- The above handles abstract views of variables and states
23078 -- built for limited with clauses.
23080 begin
23081 -- Signal that the global list contains at least one abstract
23082 -- state with a visible refinement. Note that the refinement
23083 -- may be null in which case there are no constituents.
23085 if Ekind (Item_Id) = E_Abstract_State then
23086 if Has_Null_Refinement (Item_Id) then
23087 Has_Null_State := True;
23089 elsif Has_Non_Null_Refinement (Item_Id) then
23090 if Mode = Name_Input then
23091 Has_In_State := True;
23092 elsif Mode = Name_In_Out then
23093 Has_In_Out_State := True;
23094 elsif Mode = Name_Output then
23095 Has_Out_State := True;
23096 elsif Mode = Name_Proof_In then
23097 Has_Proof_In_State := True;
23098 end if;
23099 end if;
23100 end if;
23102 -- Add the item to the proper list
23104 if Mode = Name_Input then
23105 Add_Item (Item_Id, In_Items);
23106 elsif Mode = Name_In_Out then
23107 Add_Item (Item_Id, In_Out_Items);
23108 elsif Mode = Name_Output then
23109 Add_Item (Item_Id, Out_Items);
23110 elsif Mode = Name_Proof_In then
23111 Add_Item (Item_Id, Proof_In_Items);
23112 end if;
23113 end Process_Global_Item;
23115 -- Local variables
23117 Item : Node_Id;
23119 -- Start of processing for Process_Global_List
23121 begin
23122 if Nkind (List) = N_Null then
23123 null;
23125 -- Single global item declaration
23127 elsif Nkind_In (List, N_Expanded_Name,
23128 N_Identifier,
23129 N_Selected_Component)
23130 then
23131 Process_Global_Item (List, Mode);
23133 -- Single global list or moded global list declaration
23135 elsif Nkind (List) = N_Aggregate then
23137 -- The declaration of a simple global list appear as a
23138 -- collection of expressions.
23140 if Present (Expressions (List)) then
23141 Item := First (Expressions (List));
23142 while Present (Item) loop
23143 Process_Global_Item (Item, Mode);
23144 Next (Item);
23145 end loop;
23147 -- The declaration of a moded global list appears as a
23148 -- collection of component associations where individual
23149 -- choices denote mode.
23151 elsif Present (Component_Associations (List)) then
23152 Item := First (Component_Associations (List));
23153 while Present (Item) loop
23154 Process_Global_List
23155 (List => Expression (Item),
23156 Mode => Chars (First (Choices (Item))));
23158 Next (Item);
23159 end loop;
23161 -- Invalid tree
23163 else
23164 raise Program_Error;
23165 end if;
23167 -- To accomodate partial decoration of disabled SPARK features,
23168 -- this routine may be called with illegal input. If this is the
23169 -- case, do not raise Program_Error.
23171 else
23172 null;
23173 end if;
23174 end Process_Global_List;
23176 -- Start of processing for Collect_Global_Items
23178 begin
23179 Process_Global_List (Expression (Get_Argument (Prag)));
23180 end Collect_Global_Items;
23182 -------------------------
23183 -- Present_Then_Remove --
23184 -------------------------
23186 function Present_Then_Remove
23187 (List : Elist_Id;
23188 Item : Entity_Id) return Boolean
23190 Elmt : Elmt_Id;
23192 begin
23193 if Present (List) then
23194 Elmt := First_Elmt (List);
23195 while Present (Elmt) loop
23196 if Node (Elmt) = Item then
23197 Remove_Elmt (List, Elmt);
23198 return True;
23199 end if;
23201 Next_Elmt (Elmt);
23202 end loop;
23203 end if;
23205 return False;
23206 end Present_Then_Remove;
23208 -------------------------------
23209 -- Report_Extra_Constituents --
23210 -------------------------------
23212 procedure Report_Extra_Constituents is
23213 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
23214 -- Emit an error for every element of List
23216 ---------------------------------------
23217 -- Report_Extra_Constituents_In_List --
23218 ---------------------------------------
23220 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
23221 Constit_Elmt : Elmt_Id;
23223 begin
23224 if Present (List) then
23225 Constit_Elmt := First_Elmt (List);
23226 while Present (Constit_Elmt) loop
23227 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
23228 Next_Elmt (Constit_Elmt);
23229 end loop;
23230 end if;
23231 end Report_Extra_Constituents_In_List;
23233 -- Start of processing for Report_Extra_Constituents
23235 begin
23236 Report_Extra_Constituents_In_List (In_Constits);
23237 Report_Extra_Constituents_In_List (In_Out_Constits);
23238 Report_Extra_Constituents_In_List (Out_Constits);
23239 Report_Extra_Constituents_In_List (Proof_In_Constits);
23240 end Report_Extra_Constituents;
23242 -- Local variables
23244 Body_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
23245 Errors : constant Nat := Serious_Errors_Detected;
23246 Items : constant Node_Id := Expression (Get_Argument (N));
23247 Spec_Id : Entity_Id;
23249 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
23251 begin
23252 if Nkind (Body_Decl) = N_Subprogram_Body_Stub then
23253 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
23254 else
23255 Spec_Id := Corresponding_Spec (Body_Decl);
23256 end if;
23258 Global := Get_Pragma (Spec_Id, Pragma_Global);
23260 -- The subprogram declaration lacks pragma Global. This renders
23261 -- Refined_Global useless as there is nothing to refine.
23263 if No (Global) then
23264 SPARK_Msg_NE
23265 ("useless refinement, declaration of subprogram & lacks aspect or "
23266 & "pragma Global", N, Spec_Id);
23267 return;
23268 end if;
23270 -- Extract all relevant items from the corresponding Global pragma
23272 Collect_Global_Items (Global);
23274 -- Corresponding Global pragma must mention at least one state witha
23275 -- visible refinement at the point Refined_Global is processed. States
23276 -- with null refinements need Refined_Global pragma (SPARK RM 7.2.4(2)).
23278 if not Has_In_State
23279 and then not Has_In_Out_State
23280 and then not Has_Out_State
23281 and then not Has_Proof_In_State
23282 and then not Has_Null_State
23283 then
23284 SPARK_Msg_NE
23285 ("useless refinement, subprogram & does not depend on abstract "
23286 & "state with visible refinement", N, Spec_Id);
23287 return;
23288 end if;
23290 -- The global refinement of inputs and outputs cannot be null when the
23291 -- corresponding Global pragma contains at least one item except in the
23292 -- case where we have states with null refinements.
23294 if Nkind (Items) = N_Null
23295 and then
23296 (Present (In_Items)
23297 or else Present (In_Out_Items)
23298 or else Present (Out_Items)
23299 or else Present (Proof_In_Items))
23300 and then not Has_Null_State
23301 then
23302 SPARK_Msg_NE
23303 ("refinement cannot be null, subprogram & has global items",
23304 N, Spec_Id);
23305 return;
23306 end if;
23308 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
23309 -- This ensures that the categorization of all refined global items is
23310 -- consistent with their role.
23312 Analyze_Global_In_Decl_Part (N);
23314 -- Perform all refinement checks with respect to completeness and mode
23315 -- matching.
23317 if Serious_Errors_Detected = Errors then
23318 Check_Refined_Global_List (Items);
23319 end if;
23321 -- For Input states with visible refinement, at least one constituent
23322 -- must be used as an Input in the global refinement.
23324 if Serious_Errors_Detected = Errors then
23325 Check_Input_States;
23326 end if;
23328 -- Verify all possible completion variants for In_Out states with
23329 -- visible refinement.
23331 if Serious_Errors_Detected = Errors then
23332 Check_In_Out_States;
23333 end if;
23335 -- For Output states with visible refinement, all constituents must be
23336 -- used as Outputs in the global refinement.
23338 if Serious_Errors_Detected = Errors then
23339 Check_Output_States;
23340 end if;
23342 -- For Proof_In states with visible refinement, at least one constituent
23343 -- must be used as Proof_In in the global refinement.
23345 if Serious_Errors_Detected = Errors then
23346 Check_Proof_In_States;
23347 end if;
23349 -- Emit errors for all constituents that belong to other states with
23350 -- visible refinement that do not appear in Global.
23352 if Serious_Errors_Detected = Errors then
23353 Report_Extra_Constituents;
23354 end if;
23355 end Analyze_Refined_Global_In_Decl_Part;
23357 ----------------------------------------
23358 -- Analyze_Refined_State_In_Decl_Part --
23359 ----------------------------------------
23361 procedure Analyze_Refined_State_In_Decl_Part (N : Node_Id) is
23362 Available_States : Elist_Id := No_Elist;
23363 -- A list of all abstract states defined in the package declaration that
23364 -- are available for refinement. The list is used to report unrefined
23365 -- states.
23367 Body_Id : Entity_Id;
23368 -- The body entity of the package subject to pragma Refined_State
23370 Body_States : Elist_Id := No_Elist;
23371 -- A list of all hidden states that appear in the body of the related
23372 -- package. The list is used to report unused hidden states.
23374 Constituents_Seen : Elist_Id := No_Elist;
23375 -- A list that contains all constituents processed so far. The list is
23376 -- used to detect multiple uses of the same constituent.
23378 Refined_States_Seen : Elist_Id := No_Elist;
23379 -- A list that contains all refined states processed so far. The list is
23380 -- used to detect duplicate refinements.
23382 Spec_Id : Entity_Id;
23383 -- The spec entity of the package subject to pragma Refined_State
23385 procedure Analyze_Refinement_Clause (Clause : Node_Id);
23386 -- Perform full analysis of a single refinement clause
23388 function Collect_Body_States (Pack_Id : Entity_Id) return Elist_Id;
23389 -- Gather the entities of all abstract states and variables declared in
23390 -- the body state space of package Pack_Id.
23392 procedure Report_Unrefined_States (States : Elist_Id);
23393 -- Emit errors for all unrefined abstract states found in list States
23395 procedure Report_Unused_States (States : Elist_Id);
23396 -- Emit errors for all unused states found in list States
23398 -------------------------------
23399 -- Analyze_Refinement_Clause --
23400 -------------------------------
23402 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
23403 AR_Constit : Entity_Id := Empty;
23404 AW_Constit : Entity_Id := Empty;
23405 ER_Constit : Entity_Id := Empty;
23406 EW_Constit : Entity_Id := Empty;
23407 -- The entities of external constituents that contain one of the
23408 -- following enabled properties: Async_Readers, Async_Writers,
23409 -- Effective_Reads and Effective_Writes.
23411 External_Constit_Seen : Boolean := False;
23412 -- Flag used to mark when at least one external constituent is part
23413 -- of the state refinement.
23415 Non_Null_Seen : Boolean := False;
23416 Null_Seen : Boolean := False;
23417 -- Flags used to detect multiple uses of null in a single clause or a
23418 -- mixture of null and non-null constituents.
23420 Part_Of_Constits : Elist_Id := No_Elist;
23421 -- A list of all candidate constituents subject to indicator Part_Of
23422 -- where the encapsulating state is the current state.
23424 State : Node_Id;
23425 State_Id : Entity_Id;
23426 -- The current state being refined
23428 procedure Analyze_Constituent (Constit : Node_Id);
23429 -- Perform full analysis of a single constituent
23431 procedure Check_External_Property
23432 (Prop_Nam : Name_Id;
23433 Enabled : Boolean;
23434 Constit : Entity_Id);
23435 -- Determine whether a property denoted by name Prop_Nam is present
23436 -- in both the refined state and constituent Constit. Flag Enabled
23437 -- should be set when the property applies to the refined state. If
23438 -- this is not the case, emit an error message.
23440 procedure Check_Matching_State;
23441 -- Determine whether the state being refined appears in list
23442 -- Available_States. Emit an error when attempting to re-refine the
23443 -- state or when the state is not defined in the package declaration,
23444 -- otherwise remove the state from Available_States.
23446 procedure Report_Unused_Constituents (Constits : Elist_Id);
23447 -- Emit errors for all unused Part_Of constituents in list Constits
23449 -------------------------
23450 -- Analyze_Constituent --
23451 -------------------------
23453 procedure Analyze_Constituent (Constit : Node_Id) is
23454 procedure Check_Ghost_Constituent (Constit_Id : Entity_Id);
23455 -- Verify that the constituent Constit_Id is a Ghost entity if the
23456 -- abstract state being refined is also Ghost. If this is the case
23457 -- verify that the Ghost policy in effect at the point of state
23458 -- and constituent declaration is the same.
23460 procedure Check_Matching_Constituent (Constit_Id : Entity_Id);
23461 -- Determine whether constituent Constit denoted by its entity
23462 -- Constit_Id appears in Hidden_States. Emit an error when the
23463 -- constituent is not a valid hidden state of the related package
23464 -- or when it is used more than once. Otherwise remove the
23465 -- constituent from Hidden_States.
23467 --------------------------------
23468 -- Check_Matching_Constituent --
23469 --------------------------------
23471 procedure Check_Matching_Constituent (Constit_Id : Entity_Id) is
23472 procedure Collect_Constituent;
23473 -- Add constituent Constit_Id to the refinements of State_Id
23475 -------------------------
23476 -- Collect_Constituent --
23477 -------------------------
23479 procedure Collect_Constituent is
23480 begin
23481 -- Add the constituent to the list of processed items to aid
23482 -- with the detection of duplicates.
23484 Add_Item (Constit_Id, Constituents_Seen);
23486 -- Collect the constituent in the list of refinement items
23487 -- and establish a relation between the refined state and
23488 -- the item.
23490 Append_Elmt (Constit_Id, Refinement_Constituents (State_Id));
23491 Set_Encapsulating_State (Constit_Id, State_Id);
23493 -- The state has at least one legal constituent, mark the
23494 -- start of the refinement region. The region ends when the
23495 -- body declarations end (see routine Analyze_Declarations).
23497 Set_Has_Visible_Refinement (State_Id);
23499 -- When the constituent is external, save its relevant
23500 -- property for further checks.
23502 if Async_Readers_Enabled (Constit_Id) then
23503 AR_Constit := Constit_Id;
23504 External_Constit_Seen := True;
23505 end if;
23507 if Async_Writers_Enabled (Constit_Id) then
23508 AW_Constit := Constit_Id;
23509 External_Constit_Seen := True;
23510 end if;
23512 if Effective_Reads_Enabled (Constit_Id) then
23513 ER_Constit := Constit_Id;
23514 External_Constit_Seen := True;
23515 end if;
23517 if Effective_Writes_Enabled (Constit_Id) then
23518 EW_Constit := Constit_Id;
23519 External_Constit_Seen := True;
23520 end if;
23521 end Collect_Constituent;
23523 -- Local variables
23525 State_Elmt : Elmt_Id;
23527 -- Start of processing for Check_Matching_Constituent
23529 begin
23530 -- Detect a duplicate use of a constituent
23532 if Contains (Constituents_Seen, Constit_Id) then
23533 SPARK_Msg_NE
23534 ("duplicate use of constituent &", Constit, Constit_Id);
23535 return;
23536 end if;
23538 -- The constituent is subject to a Part_Of indicator
23540 if Present (Encapsulating_State (Constit_Id)) then
23541 if Encapsulating_State (Constit_Id) = State_Id then
23542 Check_Ghost_Constituent (Constit_Id);
23543 Remove (Part_Of_Constits, Constit_Id);
23544 Collect_Constituent;
23546 -- The constituent is part of another state and is used
23547 -- incorrectly in the refinement of the current state.
23549 else
23550 Error_Msg_Name_1 := Chars (State_Id);
23551 SPARK_Msg_NE
23552 ("& cannot act as constituent of state %",
23553 Constit, Constit_Id);
23554 SPARK_Msg_NE
23555 ("\Part_Of indicator specifies & as encapsulating "
23556 & "state", Constit, Encapsulating_State (Constit_Id));
23557 end if;
23559 -- The only other source of legal constituents is the body
23560 -- state space of the related package.
23562 else
23563 if Present (Body_States) then
23564 State_Elmt := First_Elmt (Body_States);
23565 while Present (State_Elmt) loop
23567 -- Consume a valid constituent to signal that it has
23568 -- been encountered.
23570 if Node (State_Elmt) = Constit_Id then
23571 Check_Ghost_Constituent (Constit_Id);
23573 Remove_Elmt (Body_States, State_Elmt);
23574 Collect_Constituent;
23575 return;
23576 end if;
23578 Next_Elmt (State_Elmt);
23579 end loop;
23580 end if;
23582 -- If we get here, then the constituent is not a hidden
23583 -- state of the related package and may not be used in a
23584 -- refinement (SPARK RM 7.2.2(9)).
23586 Error_Msg_Name_1 := Chars (Spec_Id);
23587 SPARK_Msg_NE
23588 ("cannot use & in refinement, constituent is not a hidden "
23589 & "state of package %", Constit, Constit_Id);
23590 end if;
23591 end Check_Matching_Constituent;
23593 -----------------------------
23594 -- Check_Ghost_Constituent --
23595 -----------------------------
23597 procedure Check_Ghost_Constituent (Constit_Id : Entity_Id) is
23598 begin
23599 if Is_Ghost_Entity (State_Id) then
23600 if Is_Ghost_Entity (Constit_Id) then
23602 -- The Ghost policy in effect at the point of abstract
23603 -- state declaration and constituent must match
23604 -- (SPARK RM 6.9(16)).
23606 if Is_Checked_Ghost_Entity (State_Id)
23607 and then Is_Ignored_Ghost_Entity (Constit_Id)
23608 then
23609 Error_Msg_Sloc := Sloc (Constit);
23611 SPARK_Msg_N
23612 ("incompatible ghost policies in effect", State);
23613 SPARK_Msg_NE
23614 ("\abstract state & declared with ghost policy "
23615 & "Check", State, State_Id);
23616 SPARK_Msg_NE
23617 ("\constituent & declared # with ghost policy "
23618 & "Ignore", State, Constit_Id);
23620 elsif Is_Ignored_Ghost_Entity (State_Id)
23621 and then Is_Checked_Ghost_Entity (Constit_Id)
23622 then
23623 Error_Msg_Sloc := Sloc (Constit);
23625 SPARK_Msg_N
23626 ("incompatible ghost policies in effect", State);
23627 SPARK_Msg_NE
23628 ("\abstract state & declared with ghost policy "
23629 & "Ignore", State, State_Id);
23630 SPARK_Msg_NE
23631 ("\constituent & declared # with ghost policy "
23632 & "Check", State, Constit_Id);
23633 end if;
23635 -- A constituent of a Ghost abstract state must be a Ghost
23636 -- entity (SPARK RM 7.2.2(12)).
23638 else
23639 SPARK_Msg_NE
23640 ("constituent of ghost state & must be ghost",
23641 Constit, State_Id);
23642 end if;
23643 end if;
23644 end Check_Ghost_Constituent;
23646 -- Local variables
23648 Constit_Id : Entity_Id;
23650 -- Start of processing for Analyze_Constituent
23652 begin
23653 -- Detect multiple uses of null in a single refinement clause or a
23654 -- mixture of null and non-null constituents.
23656 if Nkind (Constit) = N_Null then
23657 if Null_Seen then
23658 SPARK_Msg_N
23659 ("multiple null constituents not allowed", Constit);
23661 elsif Non_Null_Seen then
23662 SPARK_Msg_N
23663 ("cannot mix null and non-null constituents", Constit);
23665 else
23666 Null_Seen := True;
23668 -- Collect the constituent in the list of refinement items
23670 Append_Elmt (Constit, Refinement_Constituents (State_Id));
23672 -- The state has at least one legal constituent, mark the
23673 -- start of the refinement region. The region ends when the
23674 -- body declarations end (see Analyze_Declarations).
23676 Set_Has_Visible_Refinement (State_Id);
23677 end if;
23679 -- Non-null constituents
23681 else
23682 Non_Null_Seen := True;
23684 if Null_Seen then
23685 SPARK_Msg_N
23686 ("cannot mix null and non-null constituents", Constit);
23687 end if;
23689 Analyze (Constit);
23690 Resolve_State (Constit);
23692 -- Ensure that the constituent denotes a valid state or a
23693 -- whole variable.
23695 if Is_Entity_Name (Constit) then
23696 Constit_Id := Entity_Of (Constit);
23698 if Ekind_In (Constit_Id, E_Abstract_State, E_Variable) then
23699 Check_Matching_Constituent (Constit_Id);
23701 else
23702 SPARK_Msg_NE
23703 ("constituent & must denote a variable or state (SPARK "
23704 & "RM 7.2.2(5))", Constit, Constit_Id);
23705 end if;
23707 -- The constituent is illegal
23709 else
23710 SPARK_Msg_N ("malformed constituent", Constit);
23711 end if;
23712 end if;
23713 end Analyze_Constituent;
23715 -----------------------------
23716 -- Check_External_Property --
23717 -----------------------------
23719 procedure Check_External_Property
23720 (Prop_Nam : Name_Id;
23721 Enabled : Boolean;
23722 Constit : Entity_Id)
23724 begin
23725 Error_Msg_Name_1 := Prop_Nam;
23727 -- The property is enabled in the related Abstract_State pragma
23728 -- that defines the state (SPARK RM 7.2.8(3)).
23730 if Enabled then
23731 if No (Constit) then
23732 SPARK_Msg_NE
23733 ("external state & requires at least one constituent with "
23734 & "property %", State, State_Id);
23735 end if;
23737 -- The property is missing in the declaration of the state, but
23738 -- a constituent is introducing it in the state refinement
23739 -- (SPARK RM 7.2.8(3)).
23741 elsif Present (Constit) then
23742 Error_Msg_Name_2 := Chars (Constit);
23743 SPARK_Msg_NE
23744 ("external state & lacks property % set by constituent %",
23745 State, State_Id);
23746 end if;
23747 end Check_External_Property;
23749 --------------------------
23750 -- Check_Matching_State --
23751 --------------------------
23753 procedure Check_Matching_State is
23754 State_Elmt : Elmt_Id;
23756 begin
23757 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
23759 if Contains (Refined_States_Seen, State_Id) then
23760 SPARK_Msg_NE
23761 ("duplicate refinement of state &", State, State_Id);
23762 return;
23763 end if;
23765 -- Inspect the abstract states defined in the package declaration
23766 -- looking for a match.
23768 State_Elmt := First_Elmt (Available_States);
23769 while Present (State_Elmt) loop
23771 -- A valid abstract state is being refined in the body. Add
23772 -- the state to the list of processed refined states to aid
23773 -- with the detection of duplicate refinements. Remove the
23774 -- state from Available_States to signal that it has already
23775 -- been refined.
23777 if Node (State_Elmt) = State_Id then
23778 Add_Item (State_Id, Refined_States_Seen);
23779 Remove_Elmt (Available_States, State_Elmt);
23780 return;
23781 end if;
23783 Next_Elmt (State_Elmt);
23784 end loop;
23786 -- If we get here, we are refining a state that is not defined in
23787 -- the package declaration.
23789 Error_Msg_Name_1 := Chars (Spec_Id);
23790 SPARK_Msg_NE
23791 ("cannot refine state, & is not defined in package %",
23792 State, State_Id);
23793 end Check_Matching_State;
23795 --------------------------------
23796 -- Report_Unused_Constituents --
23797 --------------------------------
23799 procedure Report_Unused_Constituents (Constits : Elist_Id) is
23800 Constit_Elmt : Elmt_Id;
23801 Constit_Id : Entity_Id;
23802 Posted : Boolean := False;
23804 begin
23805 if Present (Constits) then
23806 Constit_Elmt := First_Elmt (Constits);
23807 while Present (Constit_Elmt) loop
23808 Constit_Id := Node (Constit_Elmt);
23810 -- Generate an error message of the form:
23812 -- state ... has unused Part_Of constituents
23813 -- abstract state ... defined at ...
23814 -- variable ... defined at ...
23816 if not Posted then
23817 Posted := True;
23818 SPARK_Msg_NE
23819 ("state & has unused Part_Of constituents",
23820 State, State_Id);
23821 end if;
23823 Error_Msg_Sloc := Sloc (Constit_Id);
23825 if Ekind (Constit_Id) = E_Abstract_State then
23826 SPARK_Msg_NE
23827 ("\abstract state & defined #", State, Constit_Id);
23828 else
23829 SPARK_Msg_NE
23830 ("\variable & defined #", State, Constit_Id);
23831 end if;
23833 Next_Elmt (Constit_Elmt);
23834 end loop;
23835 end if;
23836 end Report_Unused_Constituents;
23838 -- Local declarations
23840 Body_Ref : Node_Id;
23841 Body_Ref_Elmt : Elmt_Id;
23842 Constit : Node_Id;
23843 Extra_State : Node_Id;
23845 -- Start of processing for Analyze_Refinement_Clause
23847 begin
23848 -- A refinement clause appears as a component association where the
23849 -- sole choice is the state and the expressions are the constituents.
23850 -- This is a syntax error, always report.
23852 if Nkind (Clause) /= N_Component_Association then
23853 Error_Msg_N ("malformed state refinement clause", Clause);
23854 return;
23855 end if;
23857 -- Analyze the state name of a refinement clause
23859 State := First (Choices (Clause));
23861 Analyze (State);
23862 Resolve_State (State);
23864 -- Ensure that the state name denotes a valid abstract state that is
23865 -- defined in the spec of the related package.
23867 if Is_Entity_Name (State) then
23868 State_Id := Entity_Of (State);
23870 -- Catch any attempts to re-refine a state or refine a state that
23871 -- is not defined in the package declaration.
23873 if Ekind (State_Id) = E_Abstract_State then
23874 Check_Matching_State;
23875 else
23876 SPARK_Msg_NE
23877 ("& must denote an abstract state", State, State_Id);
23878 return;
23879 end if;
23881 -- References to a state with visible refinement are illegal.
23882 -- When nested packages are involved, detecting such references is
23883 -- tricky because pragma Refined_State is analyzed later than the
23884 -- offending pragma Depends or Global. References that occur in
23885 -- such nested context are stored in a list. Emit errors for all
23886 -- references found in Body_References (SPARK RM 6.1.4(8)).
23888 if Present (Body_References (State_Id)) then
23889 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
23890 while Present (Body_Ref_Elmt) loop
23891 Body_Ref := Node (Body_Ref_Elmt);
23893 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
23894 Error_Msg_Sloc := Sloc (State);
23895 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
23897 Next_Elmt (Body_Ref_Elmt);
23898 end loop;
23899 end if;
23901 -- The state name is illegal. This is a syntax error, always report.
23903 else
23904 Error_Msg_N ("malformed state name in refinement clause", State);
23905 return;
23906 end if;
23908 -- A refinement clause may only refine one state at a time
23910 Extra_State := Next (State);
23912 if Present (Extra_State) then
23913 SPARK_Msg_N
23914 ("refinement clause cannot cover multiple states", Extra_State);
23915 end if;
23917 -- Replicate the Part_Of constituents of the refined state because
23918 -- the algorithm will consume items.
23920 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
23922 -- Analyze all constituents of the refinement. Multiple constituents
23923 -- appear as an aggregate.
23925 Constit := Expression (Clause);
23927 if Nkind (Constit) = N_Aggregate then
23928 if Present (Component_Associations (Constit)) then
23929 SPARK_Msg_N
23930 ("constituents of refinement clause must appear in "
23931 & "positional form", Constit);
23933 else pragma Assert (Present (Expressions (Constit)));
23934 Constit := First (Expressions (Constit));
23935 while Present (Constit) loop
23936 Analyze_Constituent (Constit);
23938 Next (Constit);
23939 end loop;
23940 end if;
23942 -- Various forms of a single constituent. Note that these may include
23943 -- malformed constituents.
23945 else
23946 Analyze_Constituent (Constit);
23947 end if;
23949 -- A refined external state is subject to special rules with respect
23950 -- to its properties and constituents.
23952 if Is_External_State (State_Id) then
23954 -- The set of properties that all external constituents yield must
23955 -- match that of the refined state. There are two cases to detect:
23956 -- the refined state lacks a property or has an extra property.
23958 if External_Constit_Seen then
23959 Check_External_Property
23960 (Prop_Nam => Name_Async_Readers,
23961 Enabled => Async_Readers_Enabled (State_Id),
23962 Constit => AR_Constit);
23964 Check_External_Property
23965 (Prop_Nam => Name_Async_Writers,
23966 Enabled => Async_Writers_Enabled (State_Id),
23967 Constit => AW_Constit);
23969 Check_External_Property
23970 (Prop_Nam => Name_Effective_Reads,
23971 Enabled => Effective_Reads_Enabled (State_Id),
23972 Constit => ER_Constit);
23974 Check_External_Property
23975 (Prop_Nam => Name_Effective_Writes,
23976 Enabled => Effective_Writes_Enabled (State_Id),
23977 Constit => EW_Constit);
23979 -- An external state may be refined to null (SPARK RM 7.2.8(2))
23981 elsif Null_Seen then
23982 null;
23984 -- The external state has constituents, but none of them are
23985 -- external (SPARK RM 7.2.8(2)).
23987 else
23988 SPARK_Msg_NE
23989 ("external state & requires at least one external "
23990 & "constituent or null refinement", State, State_Id);
23991 end if;
23993 -- When a refined state is not external, it should not have external
23994 -- constituents (SPARK RM 7.2.8(1)).
23996 elsif External_Constit_Seen then
23997 SPARK_Msg_NE
23998 ("non-external state & cannot contain external constituents in "
23999 & "refinement", State, State_Id);
24000 end if;
24002 -- Ensure that all Part_Of candidate constituents have been mentioned
24003 -- in the refinement clause.
24005 Report_Unused_Constituents (Part_Of_Constits);
24006 end Analyze_Refinement_Clause;
24008 -------------------------
24009 -- Collect_Body_States --
24010 -------------------------
24012 function Collect_Body_States (Pack_Id : Entity_Id) return Elist_Id is
24013 Result : Elist_Id := No_Elist;
24014 -- A list containing all body states of Pack_Id
24016 procedure Collect_Visible_States (Pack_Id : Entity_Id);
24017 -- Gather the entities of all abstract states and variables declared
24018 -- in the visible state space of package Pack_Id.
24020 ----------------------------
24021 -- Collect_Visible_States --
24022 ----------------------------
24024 procedure Collect_Visible_States (Pack_Id : Entity_Id) is
24025 Item_Id : Entity_Id;
24027 begin
24028 -- Traverse the entity chain of the package and inspect all
24029 -- visible items.
24031 Item_Id := First_Entity (Pack_Id);
24032 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
24034 -- Do not consider internally generated items as those cannot
24035 -- be named and participate in refinement.
24037 if not Comes_From_Source (Item_Id) then
24038 null;
24040 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
24041 Add_Item (Item_Id, Result);
24043 -- Recursively gather the visible states of a nested package
24045 elsif Ekind (Item_Id) = E_Package then
24046 Collect_Visible_States (Item_Id);
24047 end if;
24049 Next_Entity (Item_Id);
24050 end loop;
24051 end Collect_Visible_States;
24053 -- Local variables
24055 Pack_Body : constant Node_Id :=
24056 Declaration_Node (Body_Entity (Pack_Id));
24057 Decl : Node_Id;
24058 Item_Id : Entity_Id;
24060 -- Start of processing for Collect_Body_States
24062 begin
24063 -- Inspect the declarations of the body looking for source variables,
24064 -- packages and package instantiations.
24066 Decl := First (Declarations (Pack_Body));
24067 while Present (Decl) loop
24068 if Nkind (Decl) = N_Object_Declaration then
24069 Item_Id := Defining_Entity (Decl);
24071 -- Capture source variables only as internally generated
24072 -- temporaries cannot be named and participate in refinement.
24074 if Ekind (Item_Id) = E_Variable
24075 and then Comes_From_Source (Item_Id)
24076 then
24077 Add_Item (Item_Id, Result);
24078 end if;
24080 elsif Nkind (Decl) = N_Package_Declaration then
24081 Item_Id := Defining_Entity (Decl);
24083 -- Capture the visible abstract states and variables of a
24084 -- source package [instantiation].
24086 if Comes_From_Source (Item_Id) then
24087 Collect_Visible_States (Item_Id);
24088 end if;
24089 end if;
24091 Next (Decl);
24092 end loop;
24094 return Result;
24095 end Collect_Body_States;
24097 -----------------------------
24098 -- Report_Unrefined_States --
24099 -----------------------------
24101 procedure Report_Unrefined_States (States : Elist_Id) is
24102 State_Elmt : Elmt_Id;
24104 begin
24105 if Present (States) then
24106 State_Elmt := First_Elmt (States);
24107 while Present (State_Elmt) loop
24108 SPARK_Msg_N
24109 ("abstract state & must be refined", Node (State_Elmt));
24111 Next_Elmt (State_Elmt);
24112 end loop;
24113 end if;
24114 end Report_Unrefined_States;
24116 --------------------------
24117 -- Report_Unused_States --
24118 --------------------------
24120 procedure Report_Unused_States (States : Elist_Id) is
24121 Posted : Boolean := False;
24122 State_Elmt : Elmt_Id;
24123 State_Id : Entity_Id;
24125 begin
24126 if Present (States) then
24127 State_Elmt := First_Elmt (States);
24128 while Present (State_Elmt) loop
24129 State_Id := Node (State_Elmt);
24131 -- Generate an error message of the form:
24133 -- body of package ... has unused hidden states
24134 -- abstract state ... defined at ...
24135 -- variable ... defined at ...
24137 if not Posted then
24138 Posted := True;
24139 SPARK_Msg_N
24140 ("body of package & has unused hidden states", Body_Id);
24141 end if;
24143 Error_Msg_Sloc := Sloc (State_Id);
24145 if Ekind (State_Id) = E_Abstract_State then
24146 SPARK_Msg_NE
24147 ("\abstract state & defined #", Body_Id, State_Id);
24148 else
24149 SPARK_Msg_NE
24150 ("\variable & defined #", Body_Id, State_Id);
24151 end if;
24153 Next_Elmt (State_Elmt);
24154 end loop;
24155 end if;
24156 end Report_Unused_States;
24158 -- Local declarations
24160 Body_Decl : constant Node_Id := Parent (N);
24161 Clauses : constant Node_Id := Expression (Get_Argument (N));
24162 Clause : Node_Id;
24164 -- Start of processing for Analyze_Refined_State_In_Decl_Part
24166 begin
24167 Set_Analyzed (N);
24169 Body_Id := Defining_Entity (Body_Decl);
24170 Spec_Id := Corresponding_Spec (Body_Decl);
24172 -- Replicate the abstract states declared by the package because the
24173 -- matching algorithm will consume states.
24175 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
24177 -- Gather all abstract states and variables declared in the visible
24178 -- state space of the package body. These items must be utilized as
24179 -- constituents in a state refinement.
24181 Body_States := Collect_Body_States (Spec_Id);
24183 -- Multiple non-null state refinements appear as an aggregate
24185 if Nkind (Clauses) = N_Aggregate then
24186 if Present (Expressions (Clauses)) then
24187 SPARK_Msg_N
24188 ("state refinements must appear as component associations",
24189 Clauses);
24191 else pragma Assert (Present (Component_Associations (Clauses)));
24192 Clause := First (Component_Associations (Clauses));
24193 while Present (Clause) loop
24194 Analyze_Refinement_Clause (Clause);
24196 Next (Clause);
24197 end loop;
24198 end if;
24200 -- Various forms of a single state refinement. Note that these may
24201 -- include malformed refinements.
24203 else
24204 Analyze_Refinement_Clause (Clauses);
24205 end if;
24207 -- List all abstract states that were left unrefined
24209 Report_Unrefined_States (Available_States);
24211 -- Ensure that all abstract states and variables declared in the body
24212 -- state space of the related package are utilized as constituents.
24214 Report_Unused_States (Body_States);
24215 end Analyze_Refined_State_In_Decl_Part;
24217 ------------------------------------
24218 -- Analyze_Test_Case_In_Decl_Part --
24219 ------------------------------------
24221 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is
24222 procedure Preanalyze_Test_Case_Arg
24223 (Arg_Nam : Name_Id;
24224 Spec_Id : Entity_Id);
24225 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
24226 -- denoted by Arg_Nam. Spec_Id is the entity of the subprogram spec
24227 -- subject to pragma Test_Case.
24229 ------------------------------
24230 -- Preanalyze_Test_Case_Arg --
24231 ------------------------------
24233 procedure Preanalyze_Test_Case_Arg
24234 (Arg_Nam : Name_Id;
24235 Spec_Id : Entity_Id)
24237 Arg : Node_Id;
24239 begin
24240 -- Preanalyze the original aspect argument for ASIS or for a generic
24241 -- subprogram to properly capture global references.
24243 if ASIS_Mode or else Is_Generic_Subprogram (Spec_Id) then
24244 Arg :=
24245 Test_Case_Arg
24246 (Prag => N,
24247 Arg_Nam => Arg_Nam,
24248 From_Aspect => True);
24250 if Present (Arg) then
24251 Preanalyze_Assert_Expression
24252 (Expression (Arg), Standard_Boolean);
24253 end if;
24254 end if;
24256 Arg := Test_Case_Arg (N, Arg_Nam);
24258 if Present (Arg) then
24259 Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean);
24260 end if;
24261 end Preanalyze_Test_Case_Arg;
24263 -- Local variables
24265 Spec_Id : Entity_Id;
24266 Subp_Decl : Node_Id;
24268 Restore_Scope : Boolean := False;
24269 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
24271 -- Start of processing for Analyze_Test_Case_In_Decl_Part
24273 begin
24274 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
24275 Spec_Id := Corresponding_Spec_Of (Subp_Decl);
24277 -- Ensure that the formal parameters are visible when analyzing all
24278 -- clauses. This falls out of the general rule of aspects pertaining
24279 -- to subprogram declarations.
24281 if not In_Open_Scopes (Spec_Id) then
24282 Restore_Scope := True;
24283 Push_Scope (Spec_Id);
24285 if Is_Generic_Subprogram (Spec_Id) then
24286 Install_Generic_Formals (Spec_Id);
24287 else
24288 Install_Formals (Spec_Id);
24289 end if;
24290 end if;
24292 Preanalyze_Test_Case_Arg (Name_Requires, Spec_Id);
24293 Preanalyze_Test_Case_Arg (Name_Ensures, Spec_Id);
24295 -- Currently it is not possible to inline pre/postconditions on a
24296 -- subprogram subject to pragma Inline_Always.
24298 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
24300 if Restore_Scope then
24301 End_Scope;
24302 end if;
24303 end Analyze_Test_Case_In_Decl_Part;
24305 ----------------
24306 -- Appears_In --
24307 ----------------
24309 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
24310 Elmt : Elmt_Id;
24311 Id : Entity_Id;
24313 begin
24314 if Present (List) then
24315 Elmt := First_Elmt (List);
24316 while Present (Elmt) loop
24317 if Nkind (Node (Elmt)) = N_Defining_Identifier then
24318 Id := Node (Elmt);
24319 else
24320 Id := Entity_Of (Node (Elmt));
24321 end if;
24323 if Id = Item_Id then
24324 return True;
24325 end if;
24327 Next_Elmt (Elmt);
24328 end loop;
24329 end if;
24331 return False;
24332 end Appears_In;
24334 -----------------------------
24335 -- Check_Applicable_Policy --
24336 -----------------------------
24338 procedure Check_Applicable_Policy (N : Node_Id) is
24339 PP : Node_Id;
24340 Policy : Name_Id;
24342 Ename : constant Name_Id := Original_Aspect_Pragma_Name (N);
24344 begin
24345 -- No effect if not valid assertion kind name
24347 if not Is_Valid_Assertion_Kind (Ename) then
24348 return;
24349 end if;
24351 -- Loop through entries in check policy list
24353 PP := Opt.Check_Policy_List;
24354 while Present (PP) loop
24355 declare
24356 PPA : constant List_Id := Pragma_Argument_Associations (PP);
24357 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
24359 begin
24360 if Ename = Pnm
24361 or else Pnm = Name_Assertion
24362 or else (Pnm = Name_Statement_Assertions
24363 and then Nam_In (Ename, Name_Assert,
24364 Name_Assert_And_Cut,
24365 Name_Assume,
24366 Name_Loop_Invariant,
24367 Name_Loop_Variant))
24368 then
24369 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
24371 case Policy is
24372 when Name_Off | Name_Ignore =>
24373 Set_Is_Ignored (N, True);
24374 Set_Is_Checked (N, False);
24376 when Name_On | Name_Check =>
24377 Set_Is_Checked (N, True);
24378 Set_Is_Ignored (N, False);
24380 when Name_Disable =>
24381 Set_Is_Ignored (N, True);
24382 Set_Is_Checked (N, False);
24383 Set_Is_Disabled (N, True);
24385 -- That should be exhaustive, the null here is a defence
24386 -- against a malformed tree from previous errors.
24388 when others =>
24389 null;
24390 end case;
24392 return;
24393 end if;
24395 PP := Next_Pragma (PP);
24396 end;
24397 end loop;
24399 -- If there are no specific entries that matched, then we let the
24400 -- setting of assertions govern. Note that this provides the needed
24401 -- compatibility with the RM for the cases of assertion, invariant,
24402 -- precondition, predicate, and postcondition.
24404 if Assertions_Enabled then
24405 Set_Is_Checked (N, True);
24406 Set_Is_Ignored (N, False);
24407 else
24408 Set_Is_Checked (N, False);
24409 Set_Is_Ignored (N, True);
24410 end if;
24411 end Check_Applicable_Policy;
24413 -------------------------------
24414 -- Check_External_Properties --
24415 -------------------------------
24417 procedure Check_External_Properties
24418 (Item : Node_Id;
24419 AR : Boolean;
24420 AW : Boolean;
24421 ER : Boolean;
24422 EW : Boolean)
24424 begin
24425 -- All properties enabled
24427 if AR and AW and ER and EW then
24428 null;
24430 -- Async_Readers + Effective_Writes
24431 -- Async_Readers + Async_Writers + Effective_Writes
24433 elsif AR and EW and not ER then
24434 null;
24436 -- Async_Writers + Effective_Reads
24437 -- Async_Readers + Async_Writers + Effective_Reads
24439 elsif AW and ER and not EW then
24440 null;
24442 -- Async_Readers + Async_Writers
24444 elsif AR and AW and not ER and not EW then
24445 null;
24447 -- Async_Readers
24449 elsif AR and not AW and not ER and not EW then
24450 null;
24452 -- Async_Writers
24454 elsif AW and not AR and not ER and not EW then
24455 null;
24457 else
24458 SPARK_Msg_N
24459 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
24460 Item);
24461 end if;
24462 end Check_External_Properties;
24464 ----------------
24465 -- Check_Kind --
24466 ----------------
24468 function Check_Kind (Nam : Name_Id) return Name_Id is
24469 PP : Node_Id;
24471 begin
24472 -- Loop through entries in check policy list
24474 PP := Opt.Check_Policy_List;
24475 while Present (PP) loop
24476 declare
24477 PPA : constant List_Id := Pragma_Argument_Associations (PP);
24478 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
24480 begin
24481 if Nam = Pnm
24482 or else (Pnm = Name_Assertion
24483 and then Is_Valid_Assertion_Kind (Nam))
24484 or else (Pnm = Name_Statement_Assertions
24485 and then Nam_In (Nam, Name_Assert,
24486 Name_Assert_And_Cut,
24487 Name_Assume,
24488 Name_Loop_Invariant,
24489 Name_Loop_Variant))
24490 then
24491 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
24492 when Name_On | Name_Check =>
24493 return Name_Check;
24494 when Name_Off | Name_Ignore =>
24495 return Name_Ignore;
24496 when Name_Disable =>
24497 return Name_Disable;
24498 when others =>
24499 raise Program_Error;
24500 end case;
24502 else
24503 PP := Next_Pragma (PP);
24504 end if;
24505 end;
24506 end loop;
24508 -- If there are no specific entries that matched, then we let the
24509 -- setting of assertions govern. Note that this provides the needed
24510 -- compatibility with the RM for the cases of assertion, invariant,
24511 -- precondition, predicate, and postcondition.
24513 if Assertions_Enabled then
24514 return Name_Check;
24515 else
24516 return Name_Ignore;
24517 end if;
24518 end Check_Kind;
24520 ---------------------------
24521 -- Check_Missing_Part_Of --
24522 ---------------------------
24524 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
24525 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
24526 -- Determine whether a package denoted by Pack_Id declares at least one
24527 -- visible state.
24529 -----------------------
24530 -- Has_Visible_State --
24531 -----------------------
24533 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
24534 Item_Id : Entity_Id;
24536 begin
24537 -- Traverse the entity chain of the package trying to find at least
24538 -- one visible abstract state, variable or a package [instantiation]
24539 -- that declares a visible state.
24541 Item_Id := First_Entity (Pack_Id);
24542 while Present (Item_Id)
24543 and then not In_Private_Part (Item_Id)
24544 loop
24545 -- Do not consider internally generated items
24547 if not Comes_From_Source (Item_Id) then
24548 null;
24550 -- A visible state has been found
24552 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
24553 return True;
24555 -- Recursively peek into nested packages and instantiations
24557 elsif Ekind (Item_Id) = E_Package
24558 and then Has_Visible_State (Item_Id)
24559 then
24560 return True;
24561 end if;
24563 Next_Entity (Item_Id);
24564 end loop;
24566 return False;
24567 end Has_Visible_State;
24569 -- Local variables
24571 Pack_Id : Entity_Id;
24572 Placement : State_Space_Kind;
24574 -- Start of processing for Check_Missing_Part_Of
24576 begin
24577 -- Do not consider abstract states, variables or package instantiations
24578 -- coming from an instance as those always inherit the Part_Of indicator
24579 -- of the instance itself.
24581 if In_Instance then
24582 return;
24584 -- Do not consider internally generated entities as these can never
24585 -- have a Part_Of indicator.
24587 elsif not Comes_From_Source (Item_Id) then
24588 return;
24590 -- Perform these checks only when SPARK_Mode is enabled as they will
24591 -- interfere with standard Ada rules and produce false positives.
24593 elsif SPARK_Mode /= On then
24594 return;
24595 end if;
24597 -- Find where the abstract state, variable or package instantiation
24598 -- lives with respect to the state space.
24600 Find_Placement_In_State_Space
24601 (Item_Id => Item_Id,
24602 Placement => Placement,
24603 Pack_Id => Pack_Id);
24605 -- Items that appear in a non-package construct (subprogram, block, etc)
24606 -- do not require a Part_Of indicator because they can never act as a
24607 -- hidden state.
24609 if Placement = Not_In_Package then
24610 null;
24612 -- An item declared in the body state space of a package always act as a
24613 -- constituent and does not need explicit Part_Of indicator.
24615 elsif Placement = Body_State_Space then
24616 null;
24618 -- In general an item declared in the visible state space of a package
24619 -- does not require a Part_Of indicator. The only exception is when the
24620 -- related package is a private child unit in which case Part_Of must
24621 -- denote a state in the parent unit or in one of its descendants.
24623 elsif Placement = Visible_State_Space then
24624 if Is_Child_Unit (Pack_Id)
24625 and then Is_Private_Descendant (Pack_Id)
24626 then
24627 -- A package instantiation does not need a Part_Of indicator when
24628 -- the related generic template has no visible state.
24630 if Ekind (Item_Id) = E_Package
24631 and then Is_Generic_Instance (Item_Id)
24632 and then not Has_Visible_State (Item_Id)
24633 then
24634 null;
24636 -- All other cases require Part_Of
24638 else
24639 Error_Msg_N
24640 ("indicator Part_Of is required in this context "
24641 & "(SPARK RM 7.2.6(3))", Item_Id);
24642 Error_Msg_Name_1 := Chars (Pack_Id);
24643 Error_Msg_N
24644 ("\& is declared in the visible part of private child "
24645 & "unit %", Item_Id);
24646 end if;
24647 end if;
24649 -- When the item appears in the private state space of a packge, it must
24650 -- be a part of some state declared by the said package.
24652 else pragma Assert (Placement = Private_State_Space);
24654 -- The related package does not declare a state, the item cannot act
24655 -- as a Part_Of constituent.
24657 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
24658 null;
24660 -- A package instantiation does not need a Part_Of indicator when the
24661 -- related generic template has no visible state.
24663 elsif Ekind (Pack_Id) = E_Package
24664 and then Is_Generic_Instance (Pack_Id)
24665 and then not Has_Visible_State (Pack_Id)
24666 then
24667 null;
24669 -- All other cases require Part_Of
24671 else
24672 Error_Msg_N
24673 ("indicator Part_Of is required in this context "
24674 & "(SPARK RM 7.2.6(2))", Item_Id);
24675 Error_Msg_Name_1 := Chars (Pack_Id);
24676 Error_Msg_N
24677 ("\& is declared in the private part of package %", Item_Id);
24678 end if;
24679 end if;
24680 end Check_Missing_Part_Of;
24682 ---------------------------------------------------
24683 -- Check_Postcondition_Use_In_Inlined_Subprogram --
24684 ---------------------------------------------------
24686 procedure Check_Postcondition_Use_In_Inlined_Subprogram
24687 (Prag : Node_Id;
24688 Subp_Id : Entity_Id)
24690 begin
24691 if Warn_On_Redundant_Constructs
24692 and then Has_Pragma_Inline_Always (Subp_Id)
24693 then
24694 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
24696 if From_Aspect_Specification (Prag) then
24697 Error_Msg_NE
24698 ("aspect % not enforced on inlined subprogram &?r?",
24699 Corresponding_Aspect (Prag), Subp_Id);
24700 else
24701 Error_Msg_NE
24702 ("pragma % not enforced on inlined subprogram &?r?",
24703 Prag, Subp_Id);
24704 end if;
24705 end if;
24706 end Check_Postcondition_Use_In_Inlined_Subprogram;
24708 -------------------------------------
24709 -- Check_State_And_Constituent_Use --
24710 -------------------------------------
24712 procedure Check_State_And_Constituent_Use
24713 (States : Elist_Id;
24714 Constits : Elist_Id;
24715 Context : Node_Id)
24717 function Find_Encapsulating_State
24718 (Constit_Id : Entity_Id) return Entity_Id;
24719 -- Given the entity of a constituent, try to find a corresponding
24720 -- encapsulating state that appears in the same context. The routine
24721 -- returns Empty is no such state is found.
24723 ------------------------------
24724 -- Find_Encapsulating_State --
24725 ------------------------------
24727 function Find_Encapsulating_State
24728 (Constit_Id : Entity_Id) return Entity_Id
24730 State_Id : Entity_Id;
24732 begin
24733 -- Since a constituent may be part of a larger constituent set, climb
24734 -- the encapsulated state chain looking for a state that appears in
24735 -- the same context.
24737 State_Id := Encapsulating_State (Constit_Id);
24738 while Present (State_Id) loop
24739 if Contains (States, State_Id) then
24740 return State_Id;
24741 end if;
24743 State_Id := Encapsulating_State (State_Id);
24744 end loop;
24746 return Empty;
24747 end Find_Encapsulating_State;
24749 -- Local variables
24751 Constit_Elmt : Elmt_Id;
24752 Constit_Id : Entity_Id;
24753 State_Id : Entity_Id;
24755 -- Start of processing for Check_State_And_Constituent_Use
24757 begin
24758 -- Nothing to do if there are no states or constituents
24760 if No (States) or else No (Constits) then
24761 return;
24762 end if;
24764 -- Inspect the list of constituents and try to determine whether its
24765 -- encapsulating state is in list States.
24767 Constit_Elmt := First_Elmt (Constits);
24768 while Present (Constit_Elmt) loop
24769 Constit_Id := Node (Constit_Elmt);
24771 -- Determine whether the constituent is part of an encapsulating
24772 -- state that appears in the same context and if this is the case,
24773 -- emit an error (SPARK RM 7.2.6(7)).
24775 State_Id := Find_Encapsulating_State (Constit_Id);
24777 if Present (State_Id) then
24778 Error_Msg_Name_1 := Chars (Constit_Id);
24779 SPARK_Msg_NE
24780 ("cannot mention state & and its constituent % in the same "
24781 & "context", Context, State_Id);
24782 exit;
24783 end if;
24785 Next_Elmt (Constit_Elmt);
24786 end loop;
24787 end Check_State_And_Constituent_Use;
24789 ---------------------------------------
24790 -- Collect_Subprogram_Inputs_Outputs --
24791 ---------------------------------------
24793 procedure Collect_Subprogram_Inputs_Outputs
24794 (Subp_Id : Entity_Id;
24795 Synthesize : Boolean := False;
24796 Subp_Inputs : in out Elist_Id;
24797 Subp_Outputs : in out Elist_Id;
24798 Global_Seen : out Boolean)
24800 procedure Collect_Dependency_Clause (Clause : Node_Id);
24801 -- Collect all relevant items from a dependency clause
24803 procedure Collect_Global_List
24804 (List : Node_Id;
24805 Mode : Name_Id := Name_Input);
24806 -- Collect all relevant items from a global list
24808 -------------------------------
24809 -- Collect_Dependency_Clause --
24810 -------------------------------
24812 procedure Collect_Dependency_Clause (Clause : Node_Id) is
24813 procedure Collect_Dependency_Item
24814 (Item : Node_Id;
24815 Is_Input : Boolean);
24816 -- Add an item to the proper subprogram input or output collection
24818 -----------------------------
24819 -- Collect_Dependency_Item --
24820 -----------------------------
24822 procedure Collect_Dependency_Item
24823 (Item : Node_Id;
24824 Is_Input : Boolean)
24826 Extra : Node_Id;
24828 begin
24829 -- Nothing to collect when the item is null
24831 if Nkind (Item) = N_Null then
24832 null;
24834 -- Ditto for attribute 'Result
24836 elsif Is_Attribute_Result (Item) then
24837 null;
24839 -- Multiple items appear as an aggregate
24841 elsif Nkind (Item) = N_Aggregate then
24842 Extra := First (Expressions (Item));
24843 while Present (Extra) loop
24844 Collect_Dependency_Item (Extra, Is_Input);
24845 Next (Extra);
24846 end loop;
24848 -- Otherwise this is a solitary item
24850 else
24851 if Is_Input then
24852 Add_Item (Item, Subp_Inputs);
24853 else
24854 Add_Item (Item, Subp_Outputs);
24855 end if;
24856 end if;
24857 end Collect_Dependency_Item;
24859 -- Start of processing for Collect_Dependency_Clause
24861 begin
24862 if Nkind (Clause) = N_Null then
24863 null;
24865 -- A dependency cause appears as component association
24867 elsif Nkind (Clause) = N_Component_Association then
24868 Collect_Dependency_Item
24869 (Expression (Clause), Is_Input => True);
24870 Collect_Dependency_Item
24871 (First (Choices (Clause)), Is_Input => False);
24873 -- To accomodate partial decoration of disabled SPARK features, this
24874 -- routine may be called with illegal input. If this is the case, do
24875 -- not raise Program_Error.
24877 else
24878 null;
24879 end if;
24880 end Collect_Dependency_Clause;
24882 -------------------------
24883 -- Collect_Global_List --
24884 -------------------------
24886 procedure Collect_Global_List
24887 (List : Node_Id;
24888 Mode : Name_Id := Name_Input)
24890 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
24891 -- Add an item to the proper subprogram input or output collection
24893 -------------------------
24894 -- Collect_Global_Item --
24895 -------------------------
24897 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
24898 begin
24899 if Nam_In (Mode, Name_In_Out, Name_Input) then
24900 Add_Item (Item, Subp_Inputs);
24901 end if;
24903 if Nam_In (Mode, Name_In_Out, Name_Output) then
24904 Add_Item (Item, Subp_Outputs);
24905 end if;
24906 end Collect_Global_Item;
24908 -- Local variables
24910 Assoc : Node_Id;
24911 Item : Node_Id;
24913 -- Start of processing for Collect_Global_List
24915 begin
24916 if Nkind (List) = N_Null then
24917 null;
24919 -- Single global item declaration
24921 elsif Nkind_In (List, N_Expanded_Name,
24922 N_Identifier,
24923 N_Selected_Component)
24924 then
24925 Collect_Global_Item (List, Mode);
24927 -- Simple global list or moded global list declaration
24929 elsif Nkind (List) = N_Aggregate then
24930 if Present (Expressions (List)) then
24931 Item := First (Expressions (List));
24932 while Present (Item) loop
24933 Collect_Global_Item (Item, Mode);
24934 Next (Item);
24935 end loop;
24937 else
24938 Assoc := First (Component_Associations (List));
24939 while Present (Assoc) loop
24940 Collect_Global_List
24941 (List => Expression (Assoc),
24942 Mode => Chars (First (Choices (Assoc))));
24943 Next (Assoc);
24944 end loop;
24945 end if;
24947 -- To accomodate partial decoration of disabled SPARK features, this
24948 -- routine may be called with illegal input. If this is the case, do
24949 -- not raise Program_Error.
24951 else
24952 null;
24953 end if;
24954 end Collect_Global_List;
24956 -- Local variables
24958 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
24959 Spec_Id : constant Entity_Id := Corresponding_Spec_Of (Subp_Decl);
24960 Clause : Node_Id;
24961 Clauses : Node_Id;
24962 Depends : Node_Id;
24963 Formal : Entity_Id;
24964 Global : Node_Id;
24965 List : Node_Id;
24967 -- Start of processing for Collect_Subprogram_Inputs_Outputs
24969 begin
24970 Global_Seen := False;
24972 -- Process all formal parameters
24974 Formal := First_Formal (Spec_Id);
24975 while Present (Formal) loop
24976 if Ekind_In (Formal, E_In_Out_Parameter, E_In_Parameter) then
24977 Add_Item (Formal, Subp_Inputs);
24978 end if;
24980 if Ekind_In (Formal, E_In_Out_Parameter, E_Out_Parameter) then
24981 Add_Item (Formal, Subp_Outputs);
24983 -- Out parameters can act as inputs when the related type is
24984 -- tagged, unconstrained array, unconstrained record or record
24985 -- with unconstrained components.
24987 if Ekind (Formal) = E_Out_Parameter
24988 and then Is_Unconstrained_Or_Tagged_Item (Formal)
24989 then
24990 Add_Item (Formal, Subp_Inputs);
24991 end if;
24992 end if;
24994 Next_Formal (Formal);
24995 end loop;
24997 -- When processing a subprogram body, look for pragmas Refined_Depends
24998 -- and Refined_Global as they specify the inputs and outputs.
25000 if Ekind (Subp_Id) = E_Subprogram_Body then
25001 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
25002 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
25004 -- Subprogram declaration case, look for pragmas Depends and Global
25006 else
25007 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
25008 Global := Get_Pragma (Spec_Id, Pragma_Global);
25009 end if;
25011 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
25012 -- because it provides finer granularity of inputs and outputs.
25014 if Present (Global) then
25015 Global_Seen := True;
25016 List := Expression (Get_Argument (Global, Spec_Id));
25018 -- The pragma may not have been analyzed because of the arbitrary
25019 -- declaration order of aspects. Make sure that it is analyzed for
25020 -- the purposes of item extraction.
25022 if not Analyzed (List) then
25023 if Pragma_Name (Global) = Name_Refined_Global then
25024 Analyze_Refined_Global_In_Decl_Part (Global);
25025 else
25026 Analyze_Global_In_Decl_Part (Global);
25027 end if;
25028 end if;
25030 Collect_Global_List (List);
25032 -- When the related subprogram lacks pragma [Refined_]Global, fall back
25033 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
25034 -- the inputs and outputs from [Refined_]Depends.
25036 elsif Synthesize and then Present (Depends) then
25037 Clauses := Expression (Get_Argument (Depends, Spec_Id));
25039 -- Multiple dependency clauses appear as an aggregate
25041 if Nkind (Clauses) = N_Aggregate then
25042 Clause := First (Component_Associations (Clauses));
25043 while Present (Clause) loop
25044 Collect_Dependency_Clause (Clause);
25045 Next (Clause);
25046 end loop;
25048 -- Otherwise this is a single dependency clause
25050 else
25051 Collect_Dependency_Clause (Clauses);
25052 end if;
25053 end if;
25054 end Collect_Subprogram_Inputs_Outputs;
25056 ---------------------------------
25057 -- Delay_Config_Pragma_Analyze --
25058 ---------------------------------
25060 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
25061 begin
25062 return Nam_In (Pragma_Name (N), Name_Interrupt_State,
25063 Name_Priority_Specific_Dispatching);
25064 end Delay_Config_Pragma_Analyze;
25066 -----------------------
25067 -- Duplication_Error --
25068 -----------------------
25070 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is
25071 Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag);
25072 Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev);
25074 begin
25075 Error_Msg_Sloc := Sloc (Prev);
25076 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
25078 -- Emit a precise message to distinguish between source pragmas and
25079 -- pragmas generated from aspects. The ordering of the two pragmas is
25080 -- the following:
25082 -- Prev -- ok
25083 -- Prag -- duplicate
25085 -- No error is emitted when both pragmas come from aspects because this
25086 -- is already detected by the general aspect analysis mechanism.
25088 if Prag_From_Asp and Prev_From_Asp then
25089 null;
25090 elsif Prag_From_Asp then
25091 Error_Msg_N ("aspect % duplicates pragma declared #", Prag);
25092 elsif Prev_From_Asp then
25093 Error_Msg_N ("pragma % duplicates aspect declared #", Prag);
25094 else
25095 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
25096 end if;
25097 end Duplication_Error;
25099 ----------------------------------
25100 -- Find_Related_Package_Or_Body --
25101 ----------------------------------
25103 function Find_Related_Package_Or_Body
25104 (Prag : Node_Id;
25105 Do_Checks : Boolean := False) return Node_Id
25107 Context : constant Node_Id := Parent (Prag);
25108 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
25109 Stmt : Node_Id;
25111 begin
25112 Stmt := Prev (Prag);
25113 while Present (Stmt) loop
25115 -- Skip prior pragmas, but check for duplicates
25117 if Nkind (Stmt) = N_Pragma then
25118 if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then
25119 Duplication_Error
25120 (Prag => Prag,
25121 Prev => Stmt);
25122 end if;
25124 -- Skip internally generated code
25126 elsif not Comes_From_Source (Stmt) then
25127 if Nkind (Stmt) = N_Subprogram_Declaration then
25129 -- The subprogram declaration is an internally generated spec
25130 -- for an expression function.
25132 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
25133 return Stmt;
25135 -- The subprogram is actually an instance housed within an
25136 -- anonymous wrapper package.
25138 elsif Present (Generic_Parent (Specification (Stmt))) then
25139 return Stmt;
25140 end if;
25141 end if;
25143 -- Return the current source construct which is illegal
25145 else
25146 return Stmt;
25147 end if;
25149 Prev (Stmt);
25150 end loop;
25152 -- If we fall through, then the pragma was either the first declaration
25153 -- or it was preceded by other pragmas and no source constructs.
25155 -- The pragma is associated with a package. The immediate context in
25156 -- this case is the specification of the package.
25158 if Nkind (Context) = N_Package_Specification then
25159 return Parent (Context);
25161 -- The pragma appears in the declarations of a package body
25163 elsif Nkind (Context) = N_Package_Body then
25164 return Context;
25166 -- The pragma appears in the statements of a package body
25168 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
25169 and then Nkind (Parent (Context)) = N_Package_Body
25170 then
25171 return Parent (Context);
25173 -- The pragma is a byproduct of aspect expansion, return the related
25174 -- context of the original aspect. This case has a lower priority as
25175 -- the above circuitry pinpoints precisely the related context.
25177 elsif Present (Corresponding_Aspect (Prag)) then
25178 return Parent (Corresponding_Aspect (Prag));
25180 -- No candidate packge [body] found
25182 else
25183 return Empty;
25184 end if;
25185 end Find_Related_Package_Or_Body;
25187 -------------------------------------
25188 -- Find_Related_Subprogram_Or_Body --
25189 -------------------------------------
25191 function Find_Related_Subprogram_Or_Body
25192 (Prag : Node_Id;
25193 Do_Checks : Boolean := False) return Node_Id
25195 Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
25197 procedure Expression_Function_Error;
25198 -- Emit an error concerning pragma Prag that illegaly applies to an
25199 -- expression function.
25201 -------------------------------
25202 -- Expression_Function_Error --
25203 -------------------------------
25205 procedure Expression_Function_Error is
25206 begin
25207 Error_Msg_Name_1 := Prag_Nam;
25209 -- Emit a precise message to distinguish between source pragmas and
25210 -- pragmas generated from aspects.
25212 if From_Aspect_Specification (Prag) then
25213 Error_Msg_N
25214 ("aspect % cannot apply to a stand alone expression function",
25215 Prag);
25216 else
25217 Error_Msg_N
25218 ("pragma % cannot apply to a stand alone expression function",
25219 Prag);
25220 end if;
25221 end Expression_Function_Error;
25223 -- Local variables
25225 Context : constant Node_Id := Parent (Prag);
25226 Stmt : Node_Id;
25228 Look_For_Body : constant Boolean :=
25229 Nam_In (Prag_Nam, Name_Refined_Depends,
25230 Name_Refined_Global,
25231 Name_Refined_Post);
25232 -- Refinement pragmas must be associated with a subprogram body [stub]
25234 -- Start of processing for Find_Related_Subprogram_Or_Body
25236 begin
25237 Stmt := Prev (Prag);
25238 while Present (Stmt) loop
25240 -- Skip prior pragmas, but check for duplicates. Pragmas produced
25241 -- by splitting a complex pre/postcondition are not considered to
25242 -- be duplicates.
25244 if Nkind (Stmt) = N_Pragma then
25245 if Do_Checks
25246 and then not Split_PPC (Stmt)
25247 and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam
25248 then
25249 Duplication_Error
25250 (Prag => Prag,
25251 Prev => Stmt);
25252 end if;
25254 -- Emit an error when a refinement pragma appears on an expression
25255 -- function without a completion.
25257 elsif Do_Checks
25258 and then Look_For_Body
25259 and then Nkind (Stmt) = N_Subprogram_Declaration
25260 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
25261 and then not Has_Completion (Defining_Entity (Stmt))
25262 then
25263 Expression_Function_Error;
25264 return Empty;
25266 -- The refinement pragma applies to a subprogram body stub
25268 elsif Look_For_Body
25269 and then Nkind (Stmt) = N_Subprogram_Body_Stub
25270 then
25271 return Stmt;
25273 -- Skip internally generated code
25275 elsif not Comes_From_Source (Stmt) then
25276 if Nkind (Stmt) = N_Subprogram_Declaration then
25278 -- The subprogram declaration is an internally generated spec
25279 -- for an expression function.
25281 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
25282 return Stmt;
25284 -- The subprogram is actually an instance housed within an
25285 -- anonymous wrapper package.
25287 elsif Present (Generic_Parent (Specification (Stmt))) then
25288 return Stmt;
25289 end if;
25290 end if;
25292 -- Return the current construct which is either a subprogram body,
25293 -- a subprogram declaration or is illegal.
25295 else
25296 return Stmt;
25297 end if;
25299 Prev (Stmt);
25300 end loop;
25302 -- If we fall through, then the pragma was either the first declaration
25303 -- or it was preceded by other pragmas and no source constructs.
25305 -- The pragma is associated with a library-level subprogram
25307 if Nkind (Context) = N_Compilation_Unit_Aux then
25308 return Unit (Parent (Context));
25310 -- The pragma appears inside the statements of a subprogram body. This
25311 -- placement is the result of subprogram contract expansion.
25313 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
25314 return Parent (Context);
25316 -- The pragma appears inside the declarative part of a subprogram body
25318 elsif Nkind (Context) = N_Subprogram_Body then
25319 return Context;
25321 -- The pragma is a byproduct of aspect expansion, return the related
25322 -- context of the original aspect. This case has a lower priority as
25323 -- the above circuitry pinpoints precisely the related context.
25325 elsif Present (Corresponding_Aspect (Prag)) then
25326 return Parent (Corresponding_Aspect (Prag));
25328 -- No candidate subprogram [body] found
25330 else
25331 return Empty;
25332 end if;
25333 end Find_Related_Subprogram_Or_Body;
25335 ------------------
25336 -- Get_Argument --
25337 ------------------
25339 function Get_Argument
25340 (Prag : Node_Id;
25341 Spec_Id : Entity_Id := Empty) return Node_Id
25343 Args : constant List_Id := Pragma_Argument_Associations (Prag);
25345 begin
25346 -- Use the expression of the original aspect if possible when compiling
25347 -- for ASIS or when analyzing the template of a generic subprogram. In
25348 -- both cases the aspect's tree must be decorated to allow for ASIS
25349 -- queries or to save all global references in the generic context.
25351 if From_Aspect_Specification (Prag)
25352 and then
25353 (ASIS_Mode or else (Present (Spec_Id)
25354 and then Is_Generic_Subprogram (Spec_Id)))
25355 then
25356 return Corresponding_Aspect (Prag);
25358 -- Otherwise use the expression of the pragma
25360 elsif Present (Args) then
25361 return First (Args);
25363 else
25364 return Empty;
25365 end if;
25366 end Get_Argument;
25368 -------------------------
25369 -- Get_Base_Subprogram --
25370 -------------------------
25372 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
25373 Result : Entity_Id;
25375 begin
25376 -- Follow subprogram renaming chain
25378 Result := Def_Id;
25380 if Is_Subprogram (Result)
25381 and then
25382 Nkind (Parent (Declaration_Node (Result))) =
25383 N_Subprogram_Renaming_Declaration
25384 and then Present (Alias (Result))
25385 then
25386 Result := Alias (Result);
25387 end if;
25389 return Result;
25390 end Get_Base_Subprogram;
25392 -----------------------
25393 -- Get_SPARK_Mode_Type --
25394 -----------------------
25396 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
25397 begin
25398 if N = Name_On then
25399 return On;
25400 elsif N = Name_Off then
25401 return Off;
25403 -- Any other argument is illegal
25405 else
25406 raise Program_Error;
25407 end if;
25408 end Get_SPARK_Mode_Type;
25410 --------------------------------
25411 -- Get_SPARK_Mode_From_Pragma --
25412 --------------------------------
25414 function Get_SPARK_Mode_From_Pragma (N : Node_Id) return SPARK_Mode_Type is
25415 Args : List_Id;
25416 Mode : Node_Id;
25418 begin
25419 pragma Assert (Nkind (N) = N_Pragma);
25420 Args := Pragma_Argument_Associations (N);
25422 -- Extract the mode from the argument list
25424 if Present (Args) then
25425 Mode := First (Pragma_Argument_Associations (N));
25426 return Get_SPARK_Mode_Type (Chars (Get_Pragma_Arg (Mode)));
25428 -- If SPARK_Mode pragma has no argument, default is ON
25430 else
25431 return On;
25432 end if;
25433 end Get_SPARK_Mode_From_Pragma;
25435 ---------------------------
25436 -- Has_Extra_Parentheses --
25437 ---------------------------
25439 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
25440 Expr : Node_Id;
25442 begin
25443 -- The aggregate should not have an expression list because a clause
25444 -- is always interpreted as a component association. The only way an
25445 -- expression list can sneak in is by adding extra parentheses around
25446 -- the individual clauses:
25448 -- Depends (Output => Input) -- proper form
25449 -- Depends ((Output => Input)) -- extra parentheses
25451 -- Since the extra parentheses are not allowed by the syntax of the
25452 -- pragma, flag them now to avoid emitting misleading errors down the
25453 -- line.
25455 if Nkind (Clause) = N_Aggregate
25456 and then Present (Expressions (Clause))
25457 then
25458 Expr := First (Expressions (Clause));
25459 while Present (Expr) loop
25461 -- A dependency clause surrounded by extra parentheses appears
25462 -- as an aggregate of component associations with an optional
25463 -- Paren_Count set.
25465 if Nkind (Expr) = N_Aggregate
25466 and then Present (Component_Associations (Expr))
25467 then
25468 SPARK_Msg_N
25469 ("dependency clause contains extra parentheses", Expr);
25471 -- Otherwise the expression is a malformed construct
25473 else
25474 SPARK_Msg_N ("malformed dependency clause", Expr);
25475 end if;
25477 Next (Expr);
25478 end loop;
25480 return True;
25481 end if;
25483 return False;
25484 end Has_Extra_Parentheses;
25486 ----------------
25487 -- Initialize --
25488 ----------------
25490 procedure Initialize is
25491 begin
25492 Externals.Init;
25493 end Initialize;
25495 --------
25496 -- ip --
25497 --------
25499 procedure ip is
25500 begin
25501 Dummy := Dummy + 1;
25502 end ip;
25504 -----------------------------
25505 -- Is_Config_Static_String --
25506 -----------------------------
25508 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
25510 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
25511 -- This is an internal recursive function that is just like the outer
25512 -- function except that it adds the string to the name buffer rather
25513 -- than placing the string in the name buffer.
25515 ------------------------------
25516 -- Add_Config_Static_String --
25517 ------------------------------
25519 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
25520 N : Node_Id;
25521 C : Char_Code;
25523 begin
25524 N := Arg;
25526 if Nkind (N) = N_Op_Concat then
25527 if Add_Config_Static_String (Left_Opnd (N)) then
25528 N := Right_Opnd (N);
25529 else
25530 return False;
25531 end if;
25532 end if;
25534 if Nkind (N) /= N_String_Literal then
25535 Error_Msg_N ("string literal expected for pragma argument", N);
25536 return False;
25538 else
25539 for J in 1 .. String_Length (Strval (N)) loop
25540 C := Get_String_Char (Strval (N), J);
25542 if not In_Character_Range (C) then
25543 Error_Msg
25544 ("string literal contains invalid wide character",
25545 Sloc (N) + 1 + Source_Ptr (J));
25546 return False;
25547 end if;
25549 Add_Char_To_Name_Buffer (Get_Character (C));
25550 end loop;
25551 end if;
25553 return True;
25554 end Add_Config_Static_String;
25556 -- Start of processing for Is_Config_Static_String
25558 begin
25559 Name_Len := 0;
25561 return Add_Config_Static_String (Arg);
25562 end Is_Config_Static_String;
25564 -------------------------------
25565 -- Is_Elaboration_SPARK_Mode --
25566 -------------------------------
25568 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
25569 begin
25570 pragma Assert
25571 (Nkind (N) = N_Pragma
25572 and then Pragma_Name (N) = Name_SPARK_Mode
25573 and then Is_List_Member (N));
25575 -- Pragma SPARK_Mode affects the elaboration of a package body when it
25576 -- appears in the statement part of the body.
25578 return
25579 Present (Parent (N))
25580 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
25581 and then List_Containing (N) = Statements (Parent (N))
25582 and then Present (Parent (Parent (N)))
25583 and then Nkind (Parent (Parent (N))) = N_Package_Body;
25584 end Is_Elaboration_SPARK_Mode;
25586 -----------------------------------------
25587 -- Is_Non_Significant_Pragma_Reference --
25588 -----------------------------------------
25590 -- This function makes use of the following static table which indicates
25591 -- whether appearance of some name in a given pragma is to be considered
25592 -- as a reference for the purposes of warnings about unreferenced objects.
25594 -- -1 indicates that appearence in any argument is significant
25595 -- 0 indicates that appearance in any argument is not significant
25596 -- +n indicates that appearance as argument n is significant, but all
25597 -- other arguments are not significant
25598 -- 9n arguments from n on are significant, before n inisignificant
25600 Sig_Flags : constant array (Pragma_Id) of Int :=
25601 (Pragma_Abort_Defer => -1,
25602 Pragma_Abstract_State => -1,
25603 Pragma_Ada_83 => -1,
25604 Pragma_Ada_95 => -1,
25605 Pragma_Ada_05 => -1,
25606 Pragma_Ada_2005 => -1,
25607 Pragma_Ada_12 => -1,
25608 Pragma_Ada_2012 => -1,
25609 Pragma_All_Calls_Remote => -1,
25610 Pragma_Allow_Integer_Address => -1,
25611 Pragma_Annotate => 93,
25612 Pragma_Assert => -1,
25613 Pragma_Assert_And_Cut => -1,
25614 Pragma_Assertion_Policy => 0,
25615 Pragma_Assume => -1,
25616 Pragma_Assume_No_Invalid_Values => 0,
25617 Pragma_Async_Readers => 0,
25618 Pragma_Async_Writers => 0,
25619 Pragma_Asynchronous => 0,
25620 Pragma_Atomic => 0,
25621 Pragma_Atomic_Components => 0,
25622 Pragma_Attach_Handler => -1,
25623 Pragma_Attribute_Definition => 92,
25624 Pragma_Check => -1,
25625 Pragma_Check_Float_Overflow => 0,
25626 Pragma_Check_Name => 0,
25627 Pragma_Check_Policy => 0,
25628 Pragma_CIL_Constructor => 0,
25629 Pragma_CPP_Class => 0,
25630 Pragma_CPP_Constructor => 0,
25631 Pragma_CPP_Virtual => 0,
25632 Pragma_CPP_Vtable => 0,
25633 Pragma_CPU => -1,
25634 Pragma_C_Pass_By_Copy => 0,
25635 Pragma_Comment => -1,
25636 Pragma_Common_Object => 0,
25637 Pragma_Compile_Time_Error => -1,
25638 Pragma_Compile_Time_Warning => -1,
25639 Pragma_Compiler_Unit => -1,
25640 Pragma_Compiler_Unit_Warning => -1,
25641 Pragma_Complete_Representation => 0,
25642 Pragma_Complex_Representation => 0,
25643 Pragma_Component_Alignment => 0,
25644 Pragma_Contract_Cases => -1,
25645 Pragma_Controlled => 0,
25646 Pragma_Convention => 0,
25647 Pragma_Convention_Identifier => 0,
25648 Pragma_Debug => -1,
25649 Pragma_Debug_Policy => 0,
25650 Pragma_Detect_Blocking => 0,
25651 Pragma_Default_Initial_Condition => -1,
25652 Pragma_Default_Scalar_Storage_Order => 0,
25653 Pragma_Default_Storage_Pool => 0,
25654 Pragma_Depends => -1,
25655 Pragma_Disable_Atomic_Synchronization => 0,
25656 Pragma_Discard_Names => 0,
25657 Pragma_Dispatching_Domain => -1,
25658 Pragma_Effective_Reads => 0,
25659 Pragma_Effective_Writes => 0,
25660 Pragma_Elaborate => 0,
25661 Pragma_Elaborate_All => 0,
25662 Pragma_Elaborate_Body => 0,
25663 Pragma_Elaboration_Checks => 0,
25664 Pragma_Eliminate => 0,
25665 Pragma_Enable_Atomic_Synchronization => 0,
25666 Pragma_Export => -1,
25667 Pragma_Export_Function => -1,
25668 Pragma_Export_Object => -1,
25669 Pragma_Export_Procedure => -1,
25670 Pragma_Export_Value => -1,
25671 Pragma_Export_Valued_Procedure => -1,
25672 Pragma_Extend_System => -1,
25673 Pragma_Extensions_Allowed => 0,
25674 Pragma_Extensions_Visible => 0,
25675 Pragma_External => -1,
25676 Pragma_Favor_Top_Level => 0,
25677 Pragma_External_Name_Casing => 0,
25678 Pragma_Fast_Math => 0,
25679 Pragma_Finalize_Storage_Only => 0,
25680 Pragma_Ghost => 0,
25681 Pragma_Global => -1,
25682 Pragma_Ident => -1,
25683 Pragma_Implementation_Defined => -1,
25684 Pragma_Implemented => -1,
25685 Pragma_Implicit_Packing => 0,
25686 Pragma_Import => 93,
25687 Pragma_Import_Function => 0,
25688 Pragma_Import_Object => 0,
25689 Pragma_Import_Procedure => 0,
25690 Pragma_Import_Valued_Procedure => 0,
25691 Pragma_Independent => 0,
25692 Pragma_Independent_Components => 0,
25693 Pragma_Initial_Condition => -1,
25694 Pragma_Initialize_Scalars => 0,
25695 Pragma_Initializes => -1,
25696 Pragma_Inline => 0,
25697 Pragma_Inline_Always => 0,
25698 Pragma_Inline_Generic => 0,
25699 Pragma_Inspection_Point => -1,
25700 Pragma_Interface => 92,
25701 Pragma_Interface_Name => 0,
25702 Pragma_Interrupt_Handler => -1,
25703 Pragma_Interrupt_Priority => -1,
25704 Pragma_Interrupt_State => -1,
25705 Pragma_Invariant => -1,
25706 Pragma_Java_Constructor => -1,
25707 Pragma_Java_Interface => -1,
25708 Pragma_Keep_Names => 0,
25709 Pragma_License => 0,
25710 Pragma_Link_With => -1,
25711 Pragma_Linker_Alias => -1,
25712 Pragma_Linker_Constructor => -1,
25713 Pragma_Linker_Destructor => -1,
25714 Pragma_Linker_Options => -1,
25715 Pragma_Linker_Section => 0,
25716 Pragma_List => 0,
25717 Pragma_Lock_Free => 0,
25718 Pragma_Locking_Policy => 0,
25719 Pragma_Loop_Invariant => -1,
25720 Pragma_Loop_Optimize => 0,
25721 Pragma_Loop_Variant => -1,
25722 Pragma_Machine_Attribute => -1,
25723 Pragma_Main => -1,
25724 Pragma_Main_Storage => -1,
25725 Pragma_Memory_Size => 0,
25726 Pragma_No_Return => 0,
25727 Pragma_No_Body => 0,
25728 Pragma_No_Elaboration_Code_All => 0,
25729 Pragma_No_Inline => 0,
25730 Pragma_No_Run_Time => -1,
25731 Pragma_No_Strict_Aliasing => -1,
25732 Pragma_No_Tagged_Streams => 0,
25733 Pragma_Normalize_Scalars => 0,
25734 Pragma_Obsolescent => 0,
25735 Pragma_Optimize => 0,
25736 Pragma_Optimize_Alignment => 0,
25737 Pragma_Overflow_Mode => 0,
25738 Pragma_Overriding_Renamings => 0,
25739 Pragma_Ordered => 0,
25740 Pragma_Pack => 0,
25741 Pragma_Page => 0,
25742 Pragma_Part_Of => 0,
25743 Pragma_Partition_Elaboration_Policy => 0,
25744 Pragma_Passive => 0,
25745 Pragma_Persistent_BSS => 0,
25746 Pragma_Polling => 0,
25747 Pragma_Prefix_Exception_Messages => 0,
25748 Pragma_Post => -1,
25749 Pragma_Postcondition => -1,
25750 Pragma_Post_Class => -1,
25751 Pragma_Pre => -1,
25752 Pragma_Precondition => -1,
25753 Pragma_Predicate => -1,
25754 Pragma_Preelaborable_Initialization => -1,
25755 Pragma_Preelaborate => 0,
25756 Pragma_Pre_Class => -1,
25757 Pragma_Priority => -1,
25758 Pragma_Priority_Specific_Dispatching => 0,
25759 Pragma_Profile => 0,
25760 Pragma_Profile_Warnings => 0,
25761 Pragma_Propagate_Exceptions => 0,
25762 Pragma_Provide_Shift_Operators => 0,
25763 Pragma_Psect_Object => 0,
25764 Pragma_Pure => 0,
25765 Pragma_Pure_Function => 0,
25766 Pragma_Queuing_Policy => 0,
25767 Pragma_Rational => 0,
25768 Pragma_Ravenscar => 0,
25769 Pragma_Refined_Depends => -1,
25770 Pragma_Refined_Global => -1,
25771 Pragma_Refined_Post => -1,
25772 Pragma_Refined_State => -1,
25773 Pragma_Relative_Deadline => 0,
25774 Pragma_Remote_Access_Type => -1,
25775 Pragma_Remote_Call_Interface => -1,
25776 Pragma_Remote_Types => -1,
25777 Pragma_Restricted_Run_Time => 0,
25778 Pragma_Restriction_Warnings => 0,
25779 Pragma_Restrictions => 0,
25780 Pragma_Reviewable => -1,
25781 Pragma_Short_Circuit_And_Or => 0,
25782 Pragma_Share_Generic => 0,
25783 Pragma_Shared => 0,
25784 Pragma_Shared_Passive => 0,
25785 Pragma_Short_Descriptors => 0,
25786 Pragma_Simple_Storage_Pool_Type => 0,
25787 Pragma_Source_File_Name => 0,
25788 Pragma_Source_File_Name_Project => 0,
25789 Pragma_Source_Reference => 0,
25790 Pragma_SPARK_Mode => 0,
25791 Pragma_Storage_Size => -1,
25792 Pragma_Storage_Unit => 0,
25793 Pragma_Static_Elaboration_Desired => 0,
25794 Pragma_Stream_Convert => 0,
25795 Pragma_Style_Checks => 0,
25796 Pragma_Subtitle => 0,
25797 Pragma_Suppress => 0,
25798 Pragma_Suppress_Exception_Locations => 0,
25799 Pragma_Suppress_All => 0,
25800 Pragma_Suppress_Debug_Info => 0,
25801 Pragma_Suppress_Initialization => 0,
25802 Pragma_System_Name => 0,
25803 Pragma_Task_Dispatching_Policy => 0,
25804 Pragma_Task_Info => -1,
25805 Pragma_Task_Name => -1,
25806 Pragma_Task_Storage => -1,
25807 Pragma_Test_Case => -1,
25808 Pragma_Thread_Local_Storage => -1,
25809 Pragma_Time_Slice => -1,
25810 Pragma_Title => 0,
25811 Pragma_Type_Invariant => -1,
25812 Pragma_Type_Invariant_Class => -1,
25813 Pragma_Unchecked_Union => 0,
25814 Pragma_Unimplemented_Unit => 0,
25815 Pragma_Universal_Aliasing => 0,
25816 Pragma_Universal_Data => 0,
25817 Pragma_Unmodified => 0,
25818 Pragma_Unreferenced => 0,
25819 Pragma_Unreferenced_Objects => 0,
25820 Pragma_Unreserve_All_Interrupts => 0,
25821 Pragma_Unsuppress => 0,
25822 Pragma_Unevaluated_Use_Of_Old => 0,
25823 Pragma_Use_VADS_Size => 0,
25824 Pragma_Validity_Checks => 0,
25825 Pragma_Volatile => 0,
25826 Pragma_Volatile_Components => 0,
25827 Pragma_Warning_As_Error => 0,
25828 Pragma_Warnings => 0,
25829 Pragma_Weak_External => 0,
25830 Pragma_Wide_Character_Encoding => 0,
25831 Unknown_Pragma => 0);
25833 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
25834 Id : Pragma_Id;
25835 P : Node_Id;
25836 C : Int;
25837 AN : Nat;
25839 function Arg_No return Nat;
25840 -- Returns an integer showing what argument we are in. A value of
25841 -- zero means we are not in any of the arguments.
25843 ------------
25844 -- Arg_No --
25845 ------------
25847 function Arg_No return Nat is
25848 A : Node_Id;
25849 N : Nat;
25851 begin
25852 A := First (Pragma_Argument_Associations (Parent (P)));
25853 N := 1;
25854 loop
25855 if No (A) then
25856 return 0;
25857 elsif A = P then
25858 return N;
25859 end if;
25861 Next (A);
25862 N := N + 1;
25863 end loop;
25864 end Arg_No;
25866 -- Start of processing for Non_Significant_Pragma_Reference
25868 begin
25869 P := Parent (N);
25871 if Nkind (P) /= N_Pragma_Argument_Association then
25872 return False;
25874 else
25875 Id := Get_Pragma_Id (Parent (P));
25876 C := Sig_Flags (Id);
25877 AN := Arg_No;
25879 if AN = 0 then
25880 return False;
25881 end if;
25883 case C is
25884 when -1 =>
25885 return False;
25887 when 0 =>
25888 return True;
25890 when 92 .. 99 =>
25891 return AN < (C - 90);
25893 when others =>
25894 return AN /= C;
25895 end case;
25896 end if;
25897 end Is_Non_Significant_Pragma_Reference;
25899 ------------------------------
25900 -- Is_Pragma_String_Literal --
25901 ------------------------------
25903 -- This function returns true if the corresponding pragma argument is a
25904 -- static string expression. These are the only cases in which string
25905 -- literals can appear as pragma arguments. We also allow a string literal
25906 -- as the first argument to pragma Assert (although it will of course
25907 -- always generate a type error).
25909 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
25910 Pragn : constant Node_Id := Parent (Par);
25911 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
25912 Pname : constant Name_Id := Pragma_Name (Pragn);
25913 Argn : Natural;
25914 N : Node_Id;
25916 begin
25917 Argn := 1;
25918 N := First (Assoc);
25919 loop
25920 exit when N = Par;
25921 Argn := Argn + 1;
25922 Next (N);
25923 end loop;
25925 if Pname = Name_Assert then
25926 return True;
25928 elsif Pname = Name_Export then
25929 return Argn > 2;
25931 elsif Pname = Name_Ident then
25932 return Argn = 1;
25934 elsif Pname = Name_Import then
25935 return Argn > 2;
25937 elsif Pname = Name_Interface_Name then
25938 return Argn > 1;
25940 elsif Pname = Name_Linker_Alias then
25941 return Argn = 2;
25943 elsif Pname = Name_Linker_Section then
25944 return Argn = 2;
25946 elsif Pname = Name_Machine_Attribute then
25947 return Argn = 2;
25949 elsif Pname = Name_Source_File_Name then
25950 return True;
25952 elsif Pname = Name_Source_Reference then
25953 return Argn = 2;
25955 elsif Pname = Name_Title then
25956 return True;
25958 elsif Pname = Name_Subtitle then
25959 return True;
25961 else
25962 return False;
25963 end if;
25964 end Is_Pragma_String_Literal;
25966 ---------------------------
25967 -- Is_Private_SPARK_Mode --
25968 ---------------------------
25970 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
25971 begin
25972 pragma Assert
25973 (Nkind (N) = N_Pragma
25974 and then Pragma_Name (N) = Name_SPARK_Mode
25975 and then Is_List_Member (N));
25977 -- For pragma SPARK_Mode to be private, it has to appear in the private
25978 -- declarations of a package.
25980 return
25981 Present (Parent (N))
25982 and then Nkind (Parent (N)) = N_Package_Specification
25983 and then List_Containing (N) = Private_Declarations (Parent (N));
25984 end Is_Private_SPARK_Mode;
25986 -------------------------------------
25987 -- Is_Unconstrained_Or_Tagged_Item --
25988 -------------------------------------
25990 function Is_Unconstrained_Or_Tagged_Item
25991 (Item : Entity_Id) return Boolean
25993 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
25994 -- Determine whether record type Typ has at least one unconstrained
25995 -- component.
25997 ---------------------------------
25998 -- Has_Unconstrained_Component --
25999 ---------------------------------
26001 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
26002 Comp : Entity_Id;
26004 begin
26005 Comp := First_Component (Typ);
26006 while Present (Comp) loop
26007 if Is_Unconstrained_Or_Tagged_Item (Comp) then
26008 return True;
26009 end if;
26011 Next_Component (Comp);
26012 end loop;
26014 return False;
26015 end Has_Unconstrained_Component;
26017 -- Local variables
26019 Typ : constant Entity_Id := Etype (Item);
26021 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
26023 begin
26024 if Is_Tagged_Type (Typ) then
26025 return True;
26027 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
26028 return True;
26030 elsif Is_Record_Type (Typ) then
26031 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
26032 return True;
26033 else
26034 return Has_Unconstrained_Component (Typ);
26035 end if;
26037 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
26038 return True;
26040 else
26041 return False;
26042 end if;
26043 end Is_Unconstrained_Or_Tagged_Item;
26045 -----------------------------
26046 -- Is_Valid_Assertion_Kind --
26047 -----------------------------
26049 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
26050 begin
26051 case Nam is
26052 when
26053 -- RM defined
26055 Name_Assert |
26056 Name_Static_Predicate |
26057 Name_Dynamic_Predicate |
26058 Name_Pre |
26059 Name_uPre |
26060 Name_Post |
26061 Name_uPost |
26062 Name_Type_Invariant |
26063 Name_uType_Invariant |
26065 -- Impl defined
26067 Name_Assert_And_Cut |
26068 Name_Assume |
26069 Name_Contract_Cases |
26070 Name_Debug |
26071 Name_Default_Initial_Condition |
26072 Name_Ghost |
26073 Name_Initial_Condition |
26074 Name_Invariant |
26075 Name_uInvariant |
26076 Name_Loop_Invariant |
26077 Name_Loop_Variant |
26078 Name_Postcondition |
26079 Name_Precondition |
26080 Name_Predicate |
26081 Name_Refined_Post |
26082 Name_Statement_Assertions => return True;
26084 when others => return False;
26085 end case;
26086 end Is_Valid_Assertion_Kind;
26088 --------------------------------------
26089 -- Process_Compilation_Unit_Pragmas --
26090 --------------------------------------
26092 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
26093 begin
26094 -- A special check for pragma Suppress_All, a very strange DEC pragma,
26095 -- strange because it comes at the end of the unit. Rational has the
26096 -- same name for a pragma, but treats it as a program unit pragma, In
26097 -- GNAT we just decide to allow it anywhere at all. If it appeared then
26098 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
26099 -- node, and we insert a pragma Suppress (All_Checks) at the start of
26100 -- the context clause to ensure the correct processing.
26102 if Has_Pragma_Suppress_All (N) then
26103 Prepend_To (Context_Items (N),
26104 Make_Pragma (Sloc (N),
26105 Chars => Name_Suppress,
26106 Pragma_Argument_Associations => New_List (
26107 Make_Pragma_Argument_Association (Sloc (N),
26108 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
26109 end if;
26111 -- Nothing else to do at the current time
26113 end Process_Compilation_Unit_Pragmas;
26115 ------------------------------------
26116 -- Record_Possible_Body_Reference --
26117 ------------------------------------
26119 procedure Record_Possible_Body_Reference
26120 (State_Id : Entity_Id;
26121 Ref : Node_Id)
26123 Context : Node_Id;
26124 Spec_Id : Entity_Id;
26126 begin
26127 -- Ensure that we are dealing with a reference to a state
26129 pragma Assert (Ekind (State_Id) = E_Abstract_State);
26131 -- Climb the tree starting from the reference looking for a package body
26132 -- whose spec declares the referenced state. This criteria automatically
26133 -- excludes references in package specs which are legal. Note that it is
26134 -- not wise to emit an error now as the package body may lack pragma
26135 -- Refined_State or the referenced state may not be mentioned in the
26136 -- refinement. This approach avoids the generation of misleading errors.
26138 Context := Ref;
26139 while Present (Context) loop
26140 if Nkind (Context) = N_Package_Body then
26141 Spec_Id := Corresponding_Spec (Context);
26143 if Present (Abstract_States (Spec_Id))
26144 and then Contains (Abstract_States (Spec_Id), State_Id)
26145 then
26146 if No (Body_References (State_Id)) then
26147 Set_Body_References (State_Id, New_Elmt_List);
26148 end if;
26150 Append_Elmt (Ref, To => Body_References (State_Id));
26151 exit;
26152 end if;
26153 end if;
26155 Context := Parent (Context);
26156 end loop;
26157 end Record_Possible_Body_Reference;
26159 ------------------------------
26160 -- Relocate_Pragmas_To_Body --
26161 ------------------------------
26163 procedure Relocate_Pragmas_To_Body
26164 (Subp_Body : Node_Id;
26165 Target_Body : Node_Id := Empty)
26167 procedure Relocate_Pragma (Prag : Node_Id);
26168 -- Remove a single pragma from its current list and add it to the
26169 -- declarations of the proper body (either Subp_Body or Target_Body).
26171 ---------------------
26172 -- Relocate_Pragma --
26173 ---------------------
26175 procedure Relocate_Pragma (Prag : Node_Id) is
26176 Decls : List_Id;
26177 Target : Node_Id;
26179 begin
26180 -- When subprogram stubs or expression functions are involves, the
26181 -- destination declaration list belongs to the proper body.
26183 if Present (Target_Body) then
26184 Target := Target_Body;
26185 else
26186 Target := Subp_Body;
26187 end if;
26189 Decls := Declarations (Target);
26191 if No (Decls) then
26192 Decls := New_List;
26193 Set_Declarations (Target, Decls);
26194 end if;
26196 -- Unhook the pragma from its current list
26198 Remove (Prag);
26199 Prepend (Prag, Decls);
26200 end Relocate_Pragma;
26202 -- Local variables
26204 Body_Id : constant Entity_Id :=
26205 Defining_Unit_Name (Specification (Subp_Body));
26206 Next_Stmt : Node_Id;
26207 Stmt : Node_Id;
26209 -- Start of processing for Relocate_Pragmas_To_Body
26211 begin
26212 -- Do not process a body that comes from a separate unit as no construct
26213 -- can possibly follow it.
26215 if not Is_List_Member (Subp_Body) then
26216 return;
26218 -- Do not relocate pragmas that follow a stub if the stub does not have
26219 -- a proper body.
26221 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
26222 and then No (Target_Body)
26223 then
26224 return;
26226 -- Do not process internally generated routine _Postconditions
26228 elsif Ekind (Body_Id) = E_Procedure
26229 and then Chars (Body_Id) = Name_uPostconditions
26230 then
26231 return;
26232 end if;
26234 -- Look at what is following the body. We are interested in certain kind
26235 -- of pragmas (either from source or byproducts of expansion) that can
26236 -- apply to a body [stub].
26238 Stmt := Next (Subp_Body);
26239 while Present (Stmt) loop
26241 -- Preserve the following statement for iteration purposes due to a
26242 -- possible relocation of a pragma.
26244 Next_Stmt := Next (Stmt);
26246 -- Move a candidate pragma following the body to the declarations of
26247 -- the body.
26249 if Nkind (Stmt) = N_Pragma
26250 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
26251 then
26252 Relocate_Pragma (Stmt);
26254 -- Skip internally generated code
26256 elsif not Comes_From_Source (Stmt) then
26257 null;
26259 -- No candidate pragmas are available for relocation
26261 else
26262 exit;
26263 end if;
26265 Stmt := Next_Stmt;
26266 end loop;
26267 end Relocate_Pragmas_To_Body;
26269 -------------------
26270 -- Resolve_State --
26271 -------------------
26273 procedure Resolve_State (N : Node_Id) is
26274 Func : Entity_Id;
26275 State : Entity_Id;
26277 begin
26278 if Is_Entity_Name (N) and then Present (Entity (N)) then
26279 Func := Entity (N);
26281 -- Handle overloading of state names by functions. Traverse the
26282 -- homonym chain looking for an abstract state.
26284 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
26285 State := Homonym (Func);
26286 while Present (State) loop
26288 -- Resolve the overloading by setting the proper entity of the
26289 -- reference to that of the state.
26291 if Ekind (State) = E_Abstract_State then
26292 Set_Etype (N, Standard_Void_Type);
26293 Set_Entity (N, State);
26294 Set_Associated_Node (N, State);
26295 return;
26296 end if;
26298 State := Homonym (State);
26299 end loop;
26301 -- A function can never act as a state. If the homonym chain does
26302 -- not contain a corresponding state, then something went wrong in
26303 -- the overloading mechanism.
26305 raise Program_Error;
26306 end if;
26307 end if;
26308 end Resolve_State;
26310 ----------------------------
26311 -- Rewrite_Assertion_Kind --
26312 ----------------------------
26314 procedure Rewrite_Assertion_Kind (N : Node_Id) is
26315 Nam : Name_Id;
26317 begin
26318 if Nkind (N) = N_Attribute_Reference
26319 and then Attribute_Name (N) = Name_Class
26320 and then Nkind (Prefix (N)) = N_Identifier
26321 then
26322 case Chars (Prefix (N)) is
26323 when Name_Pre =>
26324 Nam := Name_uPre;
26325 when Name_Post =>
26326 Nam := Name_uPost;
26327 when Name_Type_Invariant =>
26328 Nam := Name_uType_Invariant;
26329 when Name_Invariant =>
26330 Nam := Name_uInvariant;
26331 when others =>
26332 return;
26333 end case;
26335 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
26336 end if;
26337 end Rewrite_Assertion_Kind;
26339 --------
26340 -- rv --
26341 --------
26343 procedure rv is
26344 begin
26345 Dummy := Dummy + 1;
26346 end rv;
26348 --------------------------------
26349 -- Set_Encoded_Interface_Name --
26350 --------------------------------
26352 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
26353 Str : constant String_Id := Strval (S);
26354 Len : constant Int := String_Length (Str);
26355 CC : Char_Code;
26356 C : Character;
26357 J : Int;
26359 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
26361 procedure Encode;
26362 -- Stores encoded value of character code CC. The encoding we use an
26363 -- underscore followed by four lower case hex digits.
26365 ------------
26366 -- Encode --
26367 ------------
26369 procedure Encode is
26370 begin
26371 Store_String_Char (Get_Char_Code ('_'));
26372 Store_String_Char
26373 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
26374 Store_String_Char
26375 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
26376 Store_String_Char
26377 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
26378 Store_String_Char
26379 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
26380 end Encode;
26382 -- Start of processing for Set_Encoded_Interface_Name
26384 begin
26385 -- If first character is asterisk, this is a link name, and we leave it
26386 -- completely unmodified. We also ignore null strings (the latter case
26387 -- happens only in error cases) and no encoding should occur for Java or
26388 -- AAMP interface names.
26390 if Len = 0
26391 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
26392 or else VM_Target /= No_VM
26393 or else AAMP_On_Target
26394 then
26395 Set_Interface_Name (E, S);
26397 else
26398 J := 1;
26399 loop
26400 CC := Get_String_Char (Str, J);
26402 exit when not In_Character_Range (CC);
26404 C := Get_Character (CC);
26406 exit when C /= '_' and then C /= '$'
26407 and then C not in '0' .. '9'
26408 and then C not in 'a' .. 'z'
26409 and then C not in 'A' .. 'Z';
26411 if J = Len then
26412 Set_Interface_Name (E, S);
26413 return;
26415 else
26416 J := J + 1;
26417 end if;
26418 end loop;
26420 -- Here we need to encode. The encoding we use as follows:
26421 -- three underscores + four hex digits (lower case)
26423 Start_String;
26425 for J in 1 .. String_Length (Str) loop
26426 CC := Get_String_Char (Str, J);
26428 if not In_Character_Range (CC) then
26429 Encode;
26430 else
26431 C := Get_Character (CC);
26433 if C = '_' or else C = '$'
26434 or else C in '0' .. '9'
26435 or else C in 'a' .. 'z'
26436 or else C in 'A' .. 'Z'
26437 then
26438 Store_String_Char (CC);
26439 else
26440 Encode;
26441 end if;
26442 end if;
26443 end loop;
26445 Set_Interface_Name (E,
26446 Make_String_Literal (Sloc (S),
26447 Strval => End_String));
26448 end if;
26449 end Set_Encoded_Interface_Name;
26451 ------------------------
26452 -- Set_Elab_Unit_Name --
26453 ------------------------
26455 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is
26456 Pref : Node_Id;
26457 Scop : Entity_Id;
26459 begin
26460 if Nkind (N) = N_Identifier
26461 and then Nkind (With_Item) = N_Identifier
26462 then
26463 Set_Entity (N, Entity (With_Item));
26465 elsif Nkind (N) = N_Selected_Component then
26466 Change_Selected_Component_To_Expanded_Name (N);
26467 Set_Entity (N, Entity (With_Item));
26468 Set_Entity (Selector_Name (N), Entity (N));
26470 Pref := Prefix (N);
26471 Scop := Scope (Entity (N));
26472 while Nkind (Pref) = N_Selected_Component loop
26473 Change_Selected_Component_To_Expanded_Name (Pref);
26474 Set_Entity (Selector_Name (Pref), Scop);
26475 Set_Entity (Pref, Scop);
26476 Pref := Prefix (Pref);
26477 Scop := Scope (Scop);
26478 end loop;
26480 Set_Entity (Pref, Scop);
26481 end if;
26483 Generate_Reference (Entity (With_Item), N, Set_Ref => False);
26484 end Set_Elab_Unit_Name;
26486 -------------------
26487 -- Test_Case_Arg --
26488 -------------------
26490 function Test_Case_Arg
26491 (Prag : Node_Id;
26492 Arg_Nam : Name_Id;
26493 From_Aspect : Boolean := False) return Node_Id
26495 Aspect : constant Node_Id := Corresponding_Aspect (Prag);
26496 Arg : Node_Id;
26497 Args : Node_Id;
26499 begin
26500 pragma Assert (Nam_In (Arg_Nam, Name_Ensures,
26501 Name_Mode,
26502 Name_Name,
26503 Name_Requires));
26505 -- The caller requests the aspect argument
26507 if From_Aspect then
26508 if Present (Aspect)
26509 and then Nkind (Expression (Aspect)) = N_Aggregate
26510 then
26511 Args := Expression (Aspect);
26513 -- "Name" and "Mode" may appear without an identifier as a
26514 -- positional association.
26516 if Present (Expressions (Args)) then
26517 Arg := First (Expressions (Args));
26519 if Present (Arg) and then Arg_Nam = Name_Name then
26520 return Arg;
26521 end if;
26523 -- Skip "Name"
26525 Arg := Next (Arg);
26527 if Present (Arg) and then Arg_Nam = Name_Mode then
26528 return Arg;
26529 end if;
26530 end if;
26532 -- Some or all arguments may appear as component associatons
26534 if Present (Component_Associations (Args)) then
26535 Arg := First (Component_Associations (Args));
26536 while Present (Arg) loop
26537 if Chars (First (Choices (Arg))) = Arg_Nam then
26538 return Arg;
26539 end if;
26541 Next (Arg);
26542 end loop;
26543 end if;
26544 end if;
26546 -- Otherwise retrieve the argument directly from the pragma
26548 else
26549 Arg := First (Pragma_Argument_Associations (Prag));
26551 if Present (Arg) and then Arg_Nam = Name_Name then
26552 return Arg;
26553 end if;
26555 -- Skip argument "Name"
26557 Arg := Next (Arg);
26559 if Present (Arg) and then Arg_Nam = Name_Mode then
26560 return Arg;
26561 end if;
26563 -- Skip argument "Mode"
26565 Arg := Next (Arg);
26567 -- Arguments "Requires" and "Ensures" are optional and may not be
26568 -- present at all.
26570 while Present (Arg) loop
26571 if Chars (Arg) = Arg_Nam then
26572 return Arg;
26573 end if;
26575 Next (Arg);
26576 end loop;
26577 end if;
26579 return Empty;
26580 end Test_Case_Arg;
26582 end Sem_Prag;