2014-10-31 Hristian Kirtchev <kirtchev@adacore.com>
[official-gcc.git] / gcc / ada / sem_prag.adb
blobe5c3d855c750194ba1dd9d4e4c26c518e2417bde
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-2014, 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 Lib; use Lib;
45 with Lib.Writ; use Lib.Writ;
46 with Lib.Xref; use Lib.Xref;
47 with Namet.Sp; use Namet.Sp;
48 with Nlists; use Nlists;
49 with Nmake; use Nmake;
50 with Output; use Output;
51 with Par_SCO; use Par_SCO;
52 with Restrict; use Restrict;
53 with Rident; use Rident;
54 with Rtsfind; use Rtsfind;
55 with Sem; use Sem;
56 with Sem_Aux; use Sem_Aux;
57 with Sem_Ch3; use Sem_Ch3;
58 with Sem_Ch6; use Sem_Ch6;
59 with Sem_Ch8; use Sem_Ch8;
60 with Sem_Ch12; use Sem_Ch12;
61 with Sem_Ch13; use Sem_Ch13;
62 with Sem_Disp; use Sem_Disp;
63 with Sem_Dist; use Sem_Dist;
64 with Sem_Elim; use Sem_Elim;
65 with Sem_Eval; use Sem_Eval;
66 with Sem_Intr; use Sem_Intr;
67 with Sem_Mech; use Sem_Mech;
68 with Sem_Res; use Sem_Res;
69 with Sem_Type; use Sem_Type;
70 with Sem_Util; use Sem_Util;
71 with Sem_Warn; use Sem_Warn;
72 with Stand; use Stand;
73 with Sinfo; use Sinfo;
74 with Sinfo.CN; use Sinfo.CN;
75 with Sinput; use Sinput;
76 with Stringt; use Stringt;
77 with Stylesw; use Stylesw;
78 with Table;
79 with Targparm; use Targparm;
80 with Tbuild; use Tbuild;
81 with Ttypes;
82 with Uintp; use Uintp;
83 with Uname; use Uname;
84 with Urealp; use Urealp;
85 with Validsw; use Validsw;
86 with Warnsw; use Warnsw;
88 package body Sem_Prag is
90 ----------------------------------------------
91 -- Common Handling of Import-Export Pragmas --
92 ----------------------------------------------
94 -- In the following section, a number of Import_xxx and Export_xxx pragmas
95 -- are defined by GNAT. These are compatible with the DEC pragmas of the
96 -- same name, and all have the following common form and processing:
98 -- pragma Export_xxx
99 -- [Internal =>] LOCAL_NAME
100 -- [, [External =>] EXTERNAL_SYMBOL]
101 -- [, other optional parameters ]);
103 -- pragma Import_xxx
104 -- [Internal =>] LOCAL_NAME
105 -- [, [External =>] EXTERNAL_SYMBOL]
106 -- [, other optional parameters ]);
108 -- EXTERNAL_SYMBOL ::=
109 -- IDENTIFIER
110 -- | static_string_EXPRESSION
112 -- The internal LOCAL_NAME designates the entity that is imported or
113 -- exported, and must refer to an entity in the current declarative
114 -- part (as required by the rules for LOCAL_NAME).
116 -- The external linker name is designated by the External parameter if
117 -- given, or the Internal parameter if not (if there is no External
118 -- parameter, the External parameter is a copy of the Internal name).
120 -- If the External parameter is given as a string, then this string is
121 -- treated as an external name (exactly as though it had been given as an
122 -- External_Name parameter for a normal Import pragma).
124 -- If the External parameter is given as an identifier (or there is no
125 -- External parameter, so that the Internal identifier is used), then
126 -- the external name is the characters of the identifier, translated
127 -- to all lower case letters.
129 -- Note: the external name specified or implied by any of these special
130 -- Import_xxx or Export_xxx pragmas override an external or link name
131 -- specified in a previous Import or Export pragma.
133 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
134 -- named notation, following the standard rules for subprogram calls, i.e.
135 -- parameters can be given in any order if named notation is used, and
136 -- positional and named notation can be mixed, subject to the rule that all
137 -- positional parameters must appear first.
139 -- Note: All these pragmas are implemented exactly following the DEC design
140 -- and implementation and are intended to be fully compatible with the use
141 -- of these pragmas in the DEC Ada compiler.
143 --------------------------------------------
144 -- Checking for Duplicated External Names --
145 --------------------------------------------
147 -- It is suspicious if two separate Export pragmas use the same external
148 -- name. The following table is used to diagnose this situation so that
149 -- an appropriate warning can be issued.
151 -- The Node_Id stored is for the N_String_Literal node created to hold
152 -- the value of the external name. The Sloc of this node is used to
153 -- cross-reference the location of the duplication.
155 package Externals is new Table.Table (
156 Table_Component_Type => Node_Id,
157 Table_Index_Type => Int,
158 Table_Low_Bound => 0,
159 Table_Initial => 100,
160 Table_Increment => 100,
161 Table_Name => "Name_Externals");
163 -------------------------------------
164 -- Local Subprograms and Variables --
165 -------------------------------------
167 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id);
168 -- Subsidiary routine to the analysis of pragmas Depends, Global and
169 -- Refined_State. Append an entity to a list. If the list is empty, create
170 -- a new list.
172 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
173 -- This routine is used for possible casing adjustment of an explicit
174 -- external name supplied as a string literal (the node N), according to
175 -- the casing requirement of Opt.External_Name_Casing. If this is set to
176 -- As_Is, then the string literal is returned unchanged, but if it is set
177 -- to Uppercase or Lowercase, then a new string literal with appropriate
178 -- casing is constructed.
180 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
181 -- Subsidiary to the analysis of pragma Global and pragma Depends. Query
182 -- whether a particular item appears in a mixed list of nodes and entities.
183 -- It is assumed that all nodes in the list have entities.
185 function Check_Kind (Nam : Name_Id) return Name_Id;
186 -- This function is used in connection with pragmas Assert, Check,
187 -- and assertion aspects and pragmas, to determine if Check pragmas
188 -- (or corresponding assertion aspects or pragmas) are currently active
189 -- as determined by the presence of -gnata on the command line (which
190 -- sets the default), and the appearance of pragmas Check_Policy and
191 -- Assertion_Policy as configuration pragmas either in a configuration
192 -- pragma file, or at the start of the current unit, or locally given
193 -- Check_Policy and Assertion_Policy pragmas that are currently active.
195 -- The value returned is one of the names Check, Ignore, Disable (On
196 -- returns Check, and Off returns Ignore).
198 -- Note: for assertion kinds Pre'Class, Post'Class, Invariant'Class,
199 -- and Type_Invariant'Class, the name passed is Name_uPre, Name_uPost,
200 -- Name_uInvariant, or Name_uType_Invariant, which corresponds to _Pre,
201 -- _Post, _Invariant, or _Type_Invariant, which are special names used
202 -- in identifiers to represent these attribute references.
204 procedure Check_SPARK_Aspect_For_ASIS (N : Node_Id);
205 -- In ASIS mode we need to analyze the original expression in the aspect
206 -- specification. For Initializes, Global, and related SPARK aspects, the
207 -- expression has a sui-generis syntax which may be a list, an expression,
208 -- or an aggregate.
210 procedure Check_State_And_Constituent_Use
211 (States : Elist_Id;
212 Constits : Elist_Id;
213 Context : Node_Id);
214 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
215 -- Global and Initializes. Determine whether a state from list States and a
216 -- corresponding constituent from list Constits (if any) appear in the same
217 -- context denoted by Context. If this is the case, emit an error.
219 procedure Collect_Global_Items
220 (Prag : Node_Id;
221 In_Items : in out Elist_Id;
222 In_Out_Items : in out Elist_Id;
223 Out_Items : in out Elist_Id;
224 Proof_In_Items : in out Elist_Id;
225 Has_In_State : out Boolean;
226 Has_In_Out_State : out Boolean;
227 Has_Out_State : out Boolean;
228 Has_Proof_In_State : out Boolean;
229 Has_Null_State : out Boolean);
230 -- Subsidiary to the analysis of pragma Refined_Depends/Refined_Global.
231 -- Prag denotes pragma [Refined_]Global. Gather all input, in out, output
232 -- and Proof_In items of Prag in lists In_Items, In_Out_Items, Out_Items
233 -- and Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
234 -- and Has_Proof_In_State are set when there is at least one abstract state
235 -- with visible refinement available in the corresponding mode. Flag
236 -- Has_Null_State is set when at least state has a null refinement.
238 function Find_Related_Subprogram_Or_Body
239 (Prag : Node_Id;
240 Do_Checks : Boolean := False) return Node_Id;
241 -- Subsidiary to the analysis of pragmas Contract_Cases, Depends, Global,
242 -- Refined_Depends, Refined_Global and Refined_Post. Find the declaration
243 -- of the related subprogram [body or stub] subject to pragma Prag. If flag
244 -- Do_Checks is set, the routine reports duplicate pragmas and detects
245 -- improper use of refinement pragmas in stand alone expression functions.
246 -- The returned value depends on the related pragma as follows:
247 -- 1) Pragmas Contract_Cases, Depends and Global yield the corresponding
248 -- N_Subprogram_Declaration node or if the pragma applies to a stand
249 -- alone body, the N_Subprogram_Body node or Empty if illegal.
250 -- 2) Pragmas Refined_Depends, Refined_Global and Refined_Post yield
251 -- N_Subprogram_Body or N_Subprogram_Body_Stub nodes or Empty if
252 -- illegal.
254 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
255 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
256 -- original one, following the renaming chain) is returned. Otherwise the
257 -- entity is returned unchanged. Should be in Einfo???
259 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
260 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
261 -- Get_SPARK_Mode_Type. Convert a name into a corresponding value of type
262 -- SPARK_Mode_Type.
264 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
265 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
266 -- Determine whether dependency clause Clause is surrounded by extra
267 -- parentheses. If this is the case, issue an error message.
269 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
270 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
271 -- pragma Depends. Determine whether the type of dependency item Item is
272 -- tagged, unconstrained array, unconstrained record or a record with at
273 -- least one unconstrained component.
275 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id);
276 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
277 -- of a Test_Case pragma if present (possibly Empty). We treat these as
278 -- spec expressions (i.e. similar to a default expression).
280 procedure Record_Possible_Body_Reference
281 (State_Id : Entity_Id;
282 Ref : Node_Id);
283 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
284 -- Global. Given an abstract state denoted by State_Id and a reference Ref
285 -- to it, determine whether the reference appears in a package body that
286 -- will eventually refine the state. If this is the case, record the
287 -- reference for future checks (see Analyze_Refined_State_In_Decls).
289 procedure Resolve_State (N : Node_Id);
290 -- Handle the overloading of state names by functions. When N denotes a
291 -- function, this routine finds the corresponding state and sets the entity
292 -- of N to that of the state.
294 procedure Rewrite_Assertion_Kind (N : Node_Id);
295 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
296 -- then it is rewritten as an identifier with the corresponding special
297 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas
298 -- Check, Check_Policy.
300 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
301 -- Place semantic information on the argument of an Elaborate/Elaborate_All
302 -- pragma. Entity name for unit and its parents is taken from item in
303 -- previous with_clause that mentions the unit.
305 Dummy : Integer := 0;
306 pragma Volatile (Dummy);
307 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
309 procedure ip;
310 pragma No_Inline (ip);
311 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
312 -- is just to help debugging the front end. If a pragma Inspection_Point
313 -- is added to a source program, then breaking on ip will get you to that
314 -- point in the program.
316 procedure rv;
317 pragma No_Inline (rv);
318 -- This is a dummy function called by the processing for pragma Reviewable.
319 -- It is there for assisting front end debugging. By placing a Reviewable
320 -- pragma in the source program, a breakpoint on rv catches this place in
321 -- the source, allowing convenient stepping to the point of interest.
323 --------------
324 -- Add_Item --
325 --------------
327 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id) is
328 begin
329 Append_New_Elmt (Item, To => To_List);
330 end Add_Item;
332 -------------------------------
333 -- Adjust_External_Name_Case --
334 -------------------------------
336 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
337 CC : Char_Code;
339 begin
340 -- Adjust case of literal if required
342 if Opt.External_Name_Exp_Casing = As_Is then
343 return N;
345 else
346 -- Copy existing string
348 Start_String;
350 -- Set proper casing
352 for J in 1 .. String_Length (Strval (N)) loop
353 CC := Get_String_Char (Strval (N), J);
355 if Opt.External_Name_Exp_Casing = Uppercase
356 and then CC >= Get_Char_Code ('a')
357 and then CC <= Get_Char_Code ('z')
358 then
359 Store_String_Char (CC - 32);
361 elsif Opt.External_Name_Exp_Casing = Lowercase
362 and then CC >= Get_Char_Code ('A')
363 and then CC <= Get_Char_Code ('Z')
364 then
365 Store_String_Char (CC + 32);
367 else
368 Store_String_Char (CC);
369 end if;
370 end loop;
372 return
373 Make_String_Literal (Sloc (N),
374 Strval => End_String);
375 end if;
376 end Adjust_External_Name_Case;
378 -----------------------------------------
379 -- Analyze_Contract_Cases_In_Decl_Part --
380 -----------------------------------------
382 procedure Analyze_Contract_Cases_In_Decl_Part (N : Node_Id) is
383 Others_Seen : Boolean := False;
385 procedure Analyze_Contract_Case (CCase : Node_Id);
386 -- Verify the legality of a single contract case
388 ---------------------------
389 -- Analyze_Contract_Case --
390 ---------------------------
392 procedure Analyze_Contract_Case (CCase : Node_Id) is
393 Case_Guard : Node_Id;
394 Conseq : Node_Id;
395 Extra_Guard : Node_Id;
397 begin
398 if Nkind (CCase) = N_Component_Association then
399 Case_Guard := First (Choices (CCase));
400 Conseq := Expression (CCase);
402 -- Each contract case must have exactly one case guard
404 Extra_Guard := Next (Case_Guard);
406 if Present (Extra_Guard) then
407 Error_Msg_N
408 ("contract case must have exactly one case guard",
409 Extra_Guard);
410 end if;
412 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
414 if Nkind (Case_Guard) = N_Others_Choice then
415 if Others_Seen then
416 Error_Msg_N
417 ("only one others choice allowed in contract cases",
418 Case_Guard);
419 else
420 Others_Seen := True;
421 end if;
423 elsif Others_Seen then
424 Error_Msg_N
425 ("others must be the last choice in contract cases", N);
426 end if;
428 -- Preanalyze the case guard and consequence
430 if Nkind (Case_Guard) /= N_Others_Choice then
431 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
432 end if;
434 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
436 -- The contract case is malformed
438 else
439 Error_Msg_N ("wrong syntax in contract case", CCase);
440 end if;
441 end Analyze_Contract_Case;
443 -- Local variables
445 All_Cases : Node_Id;
446 CCase : Node_Id;
447 Subp_Decl : Node_Id;
448 Subp_Id : Entity_Id;
450 Restore_Scope : Boolean := False;
451 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
453 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
455 begin
456 Set_Analyzed (N);
458 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
459 Subp_Id := Defining_Entity (Subp_Decl);
460 All_Cases := Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
462 -- Single and multiple contract cases must appear in aggregate form. If
463 -- this is not the case, then either the parser of the analysis of the
464 -- pragma failed to produce an aggregate.
466 pragma Assert (Nkind (All_Cases) = N_Aggregate);
468 if No (Component_Associations (All_Cases)) then
469 Error_Msg_N ("wrong syntax for constract cases", N);
471 -- Individual contract cases appear as component associations
473 else
474 -- Ensure that the formal parameters are visible when analyzing all
475 -- clauses. This falls out of the general rule of aspects pertaining
476 -- to subprogram declarations. Skip the installation for subprogram
477 -- bodies because the formals are already visible.
479 if not In_Open_Scopes (Subp_Id) then
480 Restore_Scope := True;
481 Push_Scope (Subp_Id);
482 Install_Formals (Subp_Id);
483 end if;
485 CCase := First (Component_Associations (All_Cases));
486 while Present (CCase) loop
487 Analyze_Contract_Case (CCase);
488 Next (CCase);
489 end loop;
491 if Restore_Scope then
492 End_Scope;
493 end if;
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. Split
585 -- a clause with multiple outputs into multiple clauses with a single
586 -- output.
588 -----------------------------
589 -- Add_Item_To_Name_Buffer --
590 -----------------------------
592 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
593 begin
594 if Ekind (Item_Id) = E_Abstract_State then
595 Add_Str_To_Name_Buffer ("state");
597 elsif Is_Formal (Item_Id) then
598 Add_Str_To_Name_Buffer ("parameter");
600 elsif Ekind (Item_Id) = E_Variable then
601 Add_Str_To_Name_Buffer ("global");
603 -- The routine should not be called with non-SPARK items
605 else
606 raise Program_Error;
607 end if;
608 end Add_Item_To_Name_Buffer;
610 -------------------------------
611 -- Analyze_Dependency_Clause --
612 -------------------------------
614 procedure Analyze_Dependency_Clause
615 (Clause : Node_Id;
616 Is_Last : Boolean)
618 procedure Analyze_Input_List (Inputs : Node_Id);
619 -- Verify the legality of a single input list
621 procedure Analyze_Input_Output
622 (Item : Node_Id;
623 Is_Input : Boolean;
624 Self_Ref : Boolean;
625 Top_Level : Boolean;
626 Seen : in out Elist_Id;
627 Null_Seen : in out Boolean;
628 Non_Null_Seen : in out Boolean);
629 -- Verify the legality of a single input or output item. Flag
630 -- Is_Input should be set whenever Item is an input, False when it
631 -- denotes an output. Flag Self_Ref should be set when the item is an
632 -- output and the dependency clause has a "+". Flag Top_Level should
633 -- be set whenever Item appears immediately within an input or output
634 -- list. Seen is a collection of all abstract states, variables and
635 -- formals processed so far. Flag Null_Seen denotes whether a null
636 -- input or output has been encountered. Flag Non_Null_Seen denotes
637 -- whether a non-null input or output has been encountered.
639 ------------------------
640 -- Analyze_Input_List --
641 ------------------------
643 procedure Analyze_Input_List (Inputs : Node_Id) is
644 Inputs_Seen : Elist_Id := No_Elist;
645 -- A list containing the entities of all inputs that appear in the
646 -- current input list.
648 Non_Null_Input_Seen : Boolean := False;
649 Null_Input_Seen : Boolean := False;
650 -- Flags used to check the legality of an input list
652 Input : Node_Id;
654 begin
655 -- Multiple inputs appear as an aggregate
657 if Nkind (Inputs) = N_Aggregate then
658 if Present (Component_Associations (Inputs)) then
659 SPARK_Msg_N
660 ("nested dependency relations not allowed", Inputs);
662 elsif Present (Expressions (Inputs)) then
663 Input := First (Expressions (Inputs));
664 while Present (Input) loop
665 Analyze_Input_Output
666 (Item => Input,
667 Is_Input => True,
668 Self_Ref => False,
669 Top_Level => False,
670 Seen => Inputs_Seen,
671 Null_Seen => Null_Input_Seen,
672 Non_Null_Seen => Non_Null_Input_Seen);
674 Next (Input);
675 end loop;
677 -- Syntax error, always report
679 else
680 Error_Msg_N ("malformed input dependency list", Inputs);
681 end if;
683 -- Process a solitary input
685 else
686 Analyze_Input_Output
687 (Item => Inputs,
688 Is_Input => True,
689 Self_Ref => False,
690 Top_Level => False,
691 Seen => Inputs_Seen,
692 Null_Seen => Null_Input_Seen,
693 Non_Null_Seen => Non_Null_Input_Seen);
694 end if;
696 -- Detect an illegal dependency clause of the form
698 -- (null =>[+] null)
700 if Null_Output_Seen and then Null_Input_Seen then
701 SPARK_Msg_N
702 ("null dependency clause cannot have a null input list",
703 Inputs);
704 end if;
705 end Analyze_Input_List;
707 --------------------------
708 -- Analyze_Input_Output --
709 --------------------------
711 procedure Analyze_Input_Output
712 (Item : Node_Id;
713 Is_Input : Boolean;
714 Self_Ref : Boolean;
715 Top_Level : Boolean;
716 Seen : in out Elist_Id;
717 Null_Seen : in out Boolean;
718 Non_Null_Seen : in out Boolean)
720 Is_Output : constant Boolean := not Is_Input;
721 Grouped : Node_Id;
722 Item_Id : Entity_Id;
724 begin
725 -- Multiple input or output items appear as an aggregate
727 if Nkind (Item) = N_Aggregate then
728 if not Top_Level then
729 SPARK_Msg_N ("nested grouping of items not allowed", Item);
731 elsif Present (Component_Associations (Item)) then
732 SPARK_Msg_N
733 ("nested dependency relations not allowed", Item);
735 -- Recursively analyze the grouped items
737 elsif Present (Expressions (Item)) then
738 Grouped := First (Expressions (Item));
739 while Present (Grouped) loop
740 Analyze_Input_Output
741 (Item => Grouped,
742 Is_Input => Is_Input,
743 Self_Ref => Self_Ref,
744 Top_Level => False,
745 Seen => Seen,
746 Null_Seen => Null_Seen,
747 Non_Null_Seen => Non_Null_Seen);
749 Next (Grouped);
750 end loop;
752 -- Syntax error, always report
754 else
755 Error_Msg_N ("malformed dependency list", Item);
756 end if;
758 -- Process Function'Result in the context of a dependency clause
760 elsif Is_Attribute_Result (Item) then
761 Non_Null_Seen := True;
763 -- It is sufficent to analyze the prefix of 'Result in order to
764 -- establish legality of the attribute.
766 Analyze (Prefix (Item));
768 -- The prefix of 'Result must denote the function for which
769 -- pragma Depends applies (SPARK RM 6.1.5(11)).
771 if not Is_Entity_Name (Prefix (Item))
772 or else Ekind (Spec_Id) /= E_Function
773 or else Entity (Prefix (Item)) /= Spec_Id
774 then
775 Error_Msg_Name_1 := Name_Result;
776 SPARK_Msg_N
777 ("prefix of attribute % must denote the enclosing "
778 & "function", Item);
780 -- Function'Result is allowed to appear on the output side of a
781 -- dependency clause (SPARK RM 6.1.5(6)).
783 elsif Is_Input then
784 SPARK_Msg_N ("function result cannot act as input", Item);
786 elsif Null_Seen then
787 SPARK_Msg_N
788 ("cannot mix null and non-null dependency items", Item);
790 else
791 Result_Seen := True;
792 end if;
794 -- Detect multiple uses of null in a single dependency list or
795 -- throughout the whole relation. Verify the placement of a null
796 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
798 elsif Nkind (Item) = N_Null then
799 if Null_Seen then
800 SPARK_Msg_N
801 ("multiple null dependency relations not allowed", Item);
803 elsif Non_Null_Seen then
804 SPARK_Msg_N
805 ("cannot mix null and non-null dependency items", Item);
807 else
808 Null_Seen := True;
810 if Is_Output then
811 if not Is_Last then
812 SPARK_Msg_N
813 ("null output list must be the last clause in a "
814 & "dependency relation", Item);
816 -- Catch a useless dependence of the form:
817 -- null =>+ ...
819 elsif Self_Ref then
820 SPARK_Msg_N
821 ("useless dependence, null depends on itself", Item);
822 end if;
823 end if;
824 end if;
826 -- Default case
828 else
829 Non_Null_Seen := True;
831 if Null_Seen then
832 SPARK_Msg_N ("cannot mix null and non-null items", Item);
833 end if;
835 Analyze (Item);
836 Resolve_State (Item);
838 -- Find the entity of the item. If this is a renaming, climb
839 -- the renaming chain to reach the root object. Renamings of
840 -- non-entire objects do not yield an entity (Empty).
842 Item_Id := Entity_Of (Item);
844 if Present (Item_Id) then
845 if Ekind_In (Item_Id, E_Abstract_State,
846 E_In_Parameter,
847 E_In_Out_Parameter,
848 E_Out_Parameter,
849 E_Variable)
850 then
851 -- Ensure that the item fulfils its role as input and/or
852 -- output as specified by pragma Global or the enclosing
853 -- context.
855 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
857 -- Detect multiple uses of the same state, variable or
858 -- formal parameter. If this is not the case, add the
859 -- item to the list of processed relations.
861 if Contains (Seen, Item_Id) then
862 SPARK_Msg_NE
863 ("duplicate use of item &", Item, Item_Id);
864 else
865 Add_Item (Item_Id, Seen);
866 end if;
868 -- Detect illegal use of an input related to a null
869 -- output. Such input items cannot appear in other
870 -- input lists (SPARK RM 6.1.5(13)).
872 if Is_Input
873 and then Null_Output_Seen
874 and then Contains (All_Inputs_Seen, Item_Id)
875 then
876 SPARK_Msg_N
877 ("input of a null output list cannot appear in "
878 & "multiple input lists", Item);
879 end if;
881 -- Add an input or a self-referential output to the list
882 -- of all processed inputs.
884 if Is_Input or else Self_Ref then
885 Add_Item (Item_Id, All_Inputs_Seen);
886 end if;
888 -- State related checks (SPARK RM 6.1.5(3))
890 if Ekind (Item_Id) = E_Abstract_State then
891 if Has_Visible_Refinement (Item_Id) then
892 SPARK_Msg_NE
893 ("cannot mention state & in global refinement",
894 Item, Item_Id);
895 SPARK_Msg_N
896 ("\use its constituents instead", Item);
897 return;
899 -- If the reference to the abstract state appears in
900 -- an enclosing package body that will eventually
901 -- refine the state, record the reference for future
902 -- checks.
904 else
905 Record_Possible_Body_Reference
906 (State_Id => Item_Id,
907 Ref => Item);
908 end if;
909 end if;
911 -- When the item renames an entire object, replace the
912 -- item with a reference to the object.
914 if Present (Renamed_Object (Entity (Item))) then
915 Rewrite (Item,
916 New_Occurrence_Of (Item_Id, Sloc (Item)));
917 Analyze (Item);
918 end if;
920 -- Add the entity of the current item to the list of
921 -- processed items.
923 if Ekind (Item_Id) = E_Abstract_State then
924 Add_Item (Item_Id, States_Seen);
925 end if;
927 if Ekind_In (Item_Id, E_Abstract_State, E_Variable)
928 and then Present (Encapsulating_State (Item_Id))
929 then
930 Add_Item (Item_Id, Constits_Seen);
931 end if;
933 -- All other input/output items are illegal
934 -- (SPARK RM 6.1.5(1)).
936 else
937 SPARK_Msg_N
938 ("item must denote parameter, variable, or state",
939 Item);
940 end if;
942 -- All other input/output items are illegal
943 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
945 else
946 Error_Msg_N
947 ("item must denote parameter, variable, or state", Item);
948 end if;
949 end if;
950 end Analyze_Input_Output;
952 -- Local variables
954 Inputs : Node_Id;
955 Output : Node_Id;
956 Self_Ref : Boolean;
958 Non_Null_Output_Seen : Boolean := False;
959 -- Flag used to check the legality of an output list
961 -- Start of processing for Analyze_Dependency_Clause
963 begin
964 Inputs := Expression (Clause);
965 Self_Ref := False;
967 -- An input list with a self-dependency appears as operator "+" where
968 -- the actuals inputs are the right operand.
970 if Nkind (Inputs) = N_Op_Plus then
971 Inputs := Right_Opnd (Inputs);
972 Self_Ref := True;
973 end if;
975 -- Process the output_list of a dependency_clause
977 Output := First (Choices (Clause));
978 while Present (Output) loop
979 Analyze_Input_Output
980 (Item => Output,
981 Is_Input => False,
982 Self_Ref => Self_Ref,
983 Top_Level => True,
984 Seen => All_Outputs_Seen,
985 Null_Seen => Null_Output_Seen,
986 Non_Null_Seen => Non_Null_Output_Seen);
988 Next (Output);
989 end loop;
991 -- Process the input_list of a dependency_clause
993 Analyze_Input_List (Inputs);
994 end Analyze_Dependency_Clause;
996 ---------------------------
997 -- Check_Function_Return --
998 ---------------------------
1000 procedure Check_Function_Return is
1001 begin
1002 if Ekind (Spec_Id) = E_Function and then not Result_Seen then
1003 SPARK_Msg_NE
1004 ("result of & must appear in exactly one output list",
1005 N, Spec_Id);
1006 end if;
1007 end Check_Function_Return;
1009 ----------------
1010 -- Check_Role --
1011 ----------------
1013 procedure Check_Role
1014 (Item : Node_Id;
1015 Item_Id : Entity_Id;
1016 Is_Input : Boolean;
1017 Self_Ref : Boolean)
1019 procedure Find_Role
1020 (Item_Is_Input : out Boolean;
1021 Item_Is_Output : out Boolean);
1022 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1023 -- Item_Is_Output are set depending on the role.
1025 procedure Role_Error
1026 (Item_Is_Input : Boolean;
1027 Item_Is_Output : Boolean);
1028 -- Emit an error message concerning the incorrect use of Item in
1029 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1030 -- denote whether the item is an input and/or an output.
1032 ---------------
1033 -- Find_Role --
1034 ---------------
1036 procedure Find_Role
1037 (Item_Is_Input : out Boolean;
1038 Item_Is_Output : out Boolean)
1040 begin
1041 Item_Is_Input := False;
1042 Item_Is_Output := False;
1044 -- Abstract state cases
1046 if Ekind (Item_Id) = E_Abstract_State then
1048 -- When pragma Global is present, the mode of the state may be
1049 -- further constrained by setting a more restrictive mode.
1051 if Global_Seen then
1052 if Appears_In (Subp_Inputs, Item_Id) then
1053 Item_Is_Input := True;
1054 end if;
1056 if Appears_In (Subp_Outputs, Item_Id) then
1057 Item_Is_Output := True;
1058 end if;
1060 -- Otherwise the state has a default IN OUT mode
1062 else
1063 Item_Is_Input := True;
1064 Item_Is_Output := True;
1065 end if;
1067 -- Parameter cases
1069 elsif Ekind (Item_Id) = E_In_Parameter then
1070 Item_Is_Input := True;
1072 elsif Ekind (Item_Id) = E_In_Out_Parameter then
1073 Item_Is_Input := True;
1074 Item_Is_Output := True;
1076 elsif Ekind (Item_Id) = E_Out_Parameter then
1077 if Scope (Item_Id) = Spec_Id then
1079 -- An OUT parameter of the related subprogram has mode IN
1080 -- if its type is unconstrained or tagged because array
1081 -- bounds, discriminants or tags can be read.
1083 if Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1084 Item_Is_Input := True;
1085 end if;
1087 Item_Is_Output := True;
1089 -- An OUT parameter of an enclosing subprogram behaves as a
1090 -- read-write variable in which case the mode is IN OUT.
1092 else
1093 Item_Is_Input := True;
1094 Item_Is_Output := True;
1095 end if;
1097 -- Variable cases
1099 else pragma Assert (Ekind (Item_Id) = E_Variable);
1101 -- When pragma Global is present, the mode of the variable may
1102 -- be further constrained by setting a more restrictive mode.
1104 if Global_Seen then
1106 -- A variable has mode IN when its type is unconstrained or
1107 -- tagged because array bounds, discriminants or tags can be
1108 -- read.
1110 if Appears_In (Subp_Inputs, Item_Id)
1111 or else Is_Unconstrained_Or_Tagged_Item (Item_Id)
1112 then
1113 Item_Is_Input := True;
1114 end if;
1116 if Appears_In (Subp_Outputs, Item_Id) then
1117 Item_Is_Output := True;
1118 end if;
1120 -- Otherwise the variable has a default IN OUT mode
1122 else
1123 Item_Is_Input := True;
1124 Item_Is_Output := True;
1125 end if;
1126 end if;
1127 end Find_Role;
1129 ----------------
1130 -- Role_Error --
1131 ----------------
1133 procedure Role_Error
1134 (Item_Is_Input : Boolean;
1135 Item_Is_Output : Boolean)
1137 Error_Msg : Name_Id;
1139 begin
1140 Name_Len := 0;
1142 -- When the item is not part of the input and the output set of
1143 -- the related subprogram, then it appears as extra in pragma
1144 -- [Refined_]Depends.
1146 if not Item_Is_Input and then not Item_Is_Output then
1147 Add_Item_To_Name_Buffer (Item_Id);
1148 Add_Str_To_Name_Buffer
1149 (" & cannot appear in dependence relation");
1151 Error_Msg := Name_Find;
1152 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1154 Error_Msg_Name_1 := Chars (Subp_Id);
1155 SPARK_Msg_NE
1156 ("\& is not part of the input or output set of subprogram %",
1157 Item, Item_Id);
1159 -- The mode of the item and its role in pragma [Refined_]Depends
1160 -- are in conflict. Construct a detailed message explaining the
1161 -- illegality (SPARK RM 6.1.5(5-6)).
1163 else
1164 if Item_Is_Input then
1165 Add_Str_To_Name_Buffer ("read-only");
1166 else
1167 Add_Str_To_Name_Buffer ("write-only");
1168 end if;
1170 Add_Char_To_Name_Buffer (' ');
1171 Add_Item_To_Name_Buffer (Item_Id);
1172 Add_Str_To_Name_Buffer (" & cannot appear as ");
1174 if Item_Is_Input then
1175 Add_Str_To_Name_Buffer ("output");
1176 else
1177 Add_Str_To_Name_Buffer ("input");
1178 end if;
1180 Add_Str_To_Name_Buffer (" in dependence relation");
1181 Error_Msg := Name_Find;
1182 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1183 end if;
1184 end Role_Error;
1186 -- Local variables
1188 Item_Is_Input : Boolean;
1189 Item_Is_Output : Boolean;
1191 -- Start of processing for Check_Role
1193 begin
1194 Find_Role (Item_Is_Input, Item_Is_Output);
1196 -- Input item
1198 if Is_Input then
1199 if not Item_Is_Input then
1200 Role_Error (Item_Is_Input, Item_Is_Output);
1201 end if;
1203 -- Self-referential item
1205 elsif Self_Ref then
1206 if not Item_Is_Input or else not Item_Is_Output then
1207 Role_Error (Item_Is_Input, Item_Is_Output);
1208 end if;
1210 -- Output item
1212 elsif not Item_Is_Output then
1213 Role_Error (Item_Is_Input, Item_Is_Output);
1214 end if;
1215 end Check_Role;
1217 -----------------
1218 -- Check_Usage --
1219 -----------------
1221 procedure Check_Usage
1222 (Subp_Items : Elist_Id;
1223 Used_Items : Elist_Id;
1224 Is_Input : Boolean)
1226 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id);
1227 -- Emit an error concerning the illegal usage of an item
1229 -----------------
1230 -- Usage_Error --
1231 -----------------
1233 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id) is
1234 Error_Msg : Name_Id;
1236 begin
1237 -- Input case
1239 if Is_Input then
1241 -- Unconstrained and tagged items are not part of the explicit
1242 -- input set of the related subprogram, they do not have to be
1243 -- present in a dependence relation and should not be flagged
1244 -- (SPARK RM 6.1.5(8)).
1246 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1247 Name_Len := 0;
1249 Add_Item_To_Name_Buffer (Item_Id);
1250 Add_Str_To_Name_Buffer
1251 (" & must appear in at least one input dependence list");
1253 Error_Msg := Name_Find;
1254 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1255 end if;
1257 -- Output case (SPARK RM 6.1.5(10))
1259 else
1260 Name_Len := 0;
1262 Add_Item_To_Name_Buffer (Item_Id);
1263 Add_Str_To_Name_Buffer
1264 (" & must appear in exactly one output dependence list");
1266 Error_Msg := Name_Find;
1267 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1268 end if;
1269 end Usage_Error;
1271 -- Local variables
1273 Elmt : Elmt_Id;
1274 Item : Node_Id;
1275 Item_Id : Entity_Id;
1277 -- Start of processing for Check_Usage
1279 begin
1280 if No (Subp_Items) then
1281 return;
1282 end if;
1284 -- Each input or output of the subprogram must appear in a dependency
1285 -- relation.
1287 Elmt := First_Elmt (Subp_Items);
1288 while Present (Elmt) loop
1289 Item := Node (Elmt);
1291 if Nkind (Item) = N_Defining_Identifier then
1292 Item_Id := Item;
1293 else
1294 Item_Id := Entity_Of (Item);
1295 end if;
1297 -- The item does not appear in a dependency
1299 if Present (Item_Id)
1300 and then not Contains (Used_Items, Item_Id)
1301 then
1302 if Is_Formal (Item_Id) then
1303 Usage_Error (Item, Item_Id);
1305 -- States and global variables are not used properly only when
1306 -- the subprogram is subject to pragma Global.
1308 elsif Global_Seen then
1309 Usage_Error (Item, Item_Id);
1310 end if;
1311 end if;
1313 Next_Elmt (Elmt);
1314 end loop;
1315 end Check_Usage;
1317 ----------------------
1318 -- Normalize_Clause --
1319 ----------------------
1321 procedure Normalize_Clause (Clause : Node_Id) is
1322 procedure Create_Or_Modify_Clause
1323 (Output : Node_Id;
1324 Outputs : Node_Id;
1325 Inputs : Node_Id;
1326 After : Node_Id;
1327 In_Place : Boolean;
1328 Multiple : Boolean);
1329 -- Create a brand new clause to represent the self-reference or
1330 -- modify the input and/or output lists of an existing clause. Output
1331 -- denotes a self-referencial output. Outputs is the output list of a
1332 -- clause. Inputs is the input list of a clause. After denotes the
1333 -- clause after which the new clause is to be inserted. Flag In_Place
1334 -- should be set when normalizing the last output of an output list.
1335 -- Flag Multiple should be set when Output comes from a list with
1336 -- multiple items.
1338 procedure Normalize_Outputs;
1339 -- If Clause contains more than one output, split the clause into
1340 -- multiple clauses with a single output. All new clauses are added
1341 -- after Clause.
1343 -----------------------------
1344 -- Create_Or_Modify_Clause --
1345 -----------------------------
1347 procedure Create_Or_Modify_Clause
1348 (Output : Node_Id;
1349 Outputs : Node_Id;
1350 Inputs : Node_Id;
1351 After : Node_Id;
1352 In_Place : Boolean;
1353 Multiple : Boolean)
1355 procedure Propagate_Output
1356 (Output : Node_Id;
1357 Inputs : Node_Id);
1358 -- Handle the various cases of output propagation to the input
1359 -- list. Output denotes a self-referencial output item. Inputs is
1360 -- the input list of a clause.
1362 ----------------------
1363 -- Propagate_Output --
1364 ----------------------
1366 procedure Propagate_Output
1367 (Output : Node_Id;
1368 Inputs : Node_Id)
1370 function In_Input_List
1371 (Item : Entity_Id;
1372 Inputs : List_Id) return Boolean;
1373 -- Determine whether a particulat item appears in the input
1374 -- list of a clause.
1376 -------------------
1377 -- In_Input_List --
1378 -------------------
1380 function In_Input_List
1381 (Item : Entity_Id;
1382 Inputs : List_Id) return Boolean
1384 Elmt : Node_Id;
1386 begin
1387 Elmt := First (Inputs);
1388 while Present (Elmt) loop
1389 if Entity_Of (Elmt) = Item then
1390 return True;
1391 end if;
1393 Next (Elmt);
1394 end loop;
1396 return False;
1397 end In_Input_List;
1399 -- Local variables
1401 Output_Id : constant Entity_Id := Entity_Of (Output);
1402 Grouped : List_Id;
1404 -- Start of processing for Propagate_Output
1406 begin
1407 -- The clause is of the form:
1409 -- (Output =>+ null)
1411 -- Remove the null input and replace it with a copy of the
1412 -- output:
1414 -- (Output => Output)
1416 if Nkind (Inputs) = N_Null then
1417 Rewrite (Inputs, New_Copy_Tree (Output));
1419 -- The clause is of the form:
1421 -- (Output =>+ (Input1, ..., InputN))
1423 -- Determine whether the output is not already mentioned in the
1424 -- input list and if not, add it to the list of inputs:
1426 -- (Output => (Output, Input1, ..., InputN))
1428 elsif Nkind (Inputs) = N_Aggregate then
1429 Grouped := Expressions (Inputs);
1431 if not In_Input_List
1432 (Item => Output_Id,
1433 Inputs => Grouped)
1434 then
1435 Prepend_To (Grouped, New_Copy_Tree (Output));
1436 end if;
1438 -- The clause is of the form:
1440 -- (Output =>+ Input)
1442 -- If the input does not mention the output, group the two
1443 -- together:
1445 -- (Output => (Output, Input))
1447 elsif Entity_Of (Inputs) /= Output_Id then
1448 Rewrite (Inputs,
1449 Make_Aggregate (Loc,
1450 Expressions => New_List (
1451 New_Copy_Tree (Output),
1452 New_Copy_Tree (Inputs))));
1453 end if;
1454 end Propagate_Output;
1456 -- Local variables
1458 Loc : constant Source_Ptr := Sloc (Clause);
1459 New_Clause : Node_Id;
1461 -- Start of processing for Create_Or_Modify_Clause
1463 begin
1464 -- A null output depending on itself does not require any
1465 -- normalization.
1467 if Nkind (Output) = N_Null then
1468 return;
1470 -- A function result cannot depend on itself because it cannot
1471 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1473 elsif Is_Attribute_Result (Output) then
1474 SPARK_Msg_N ("function result cannot depend on itself", Output);
1475 return;
1476 end if;
1478 -- When performing the transformation in place, simply add the
1479 -- output to the list of inputs (if not already there). This case
1480 -- arises when dealing with the last output of an output list -
1481 -- we perform the normalization in place to avoid generating a
1482 -- malformed tree.
1484 if In_Place then
1485 Propagate_Output (Output, Inputs);
1487 -- A list with multiple outputs is slowly trimmed until only
1488 -- one element remains. When this happens, replace the
1489 -- aggregate with the element itself.
1491 if Multiple then
1492 Remove (Output);
1493 Rewrite (Outputs, Output);
1494 end if;
1496 -- Default case
1498 else
1499 -- Unchain the output from its output list as it will appear in
1500 -- a new clause. Note that we cannot simply rewrite the output
1501 -- as null because this will violate the semantics of pragma
1502 -- Depends.
1504 Remove (Output);
1506 -- Generate a new clause of the form:
1507 -- (Output => Inputs)
1509 New_Clause :=
1510 Make_Component_Association (Loc,
1511 Choices => New_List (Output),
1512 Expression => New_Copy_Tree (Inputs));
1514 -- The new clause contains replicated content that has already
1515 -- been analyzed. There is not need to reanalyze it or
1516 -- renormalize it again.
1518 Set_Analyzed (New_Clause);
1520 Propagate_Output
1521 (Output => First (Choices (New_Clause)),
1522 Inputs => Expression (New_Clause));
1524 Insert_After (After, New_Clause);
1525 end if;
1526 end Create_Or_Modify_Clause;
1528 -----------------------
1529 -- Normalize_Outputs --
1530 -----------------------
1532 procedure Normalize_Outputs is
1533 Inputs : constant Node_Id := Expression (Clause);
1534 Loc : constant Source_Ptr := Sloc (Clause);
1535 Outputs : constant Node_Id := First (Choices (Clause));
1536 Last_Output : Node_Id;
1537 New_Clause : Node_Id;
1538 Next_Output : Node_Id;
1539 Output : Node_Id;
1541 begin
1542 -- Multiple outputs appear as an aggregate. Nothing to do when
1543 -- the clause has exactly one output.
1545 if Nkind (Outputs) = N_Aggregate then
1546 Last_Output := Last (Expressions (Outputs));
1548 -- Create a clause for each output. Note that each time a new
1549 -- clause is created, the original output list slowly shrinks
1550 -- until there is one item left.
1552 Output := First (Expressions (Outputs));
1553 while Present (Output) loop
1554 Next_Output := Next (Output);
1556 -- Unhook the output from the original output list as it
1557 -- will be relocated to a new clause.
1559 Remove (Output);
1561 -- Special processing for the last output. At this point
1562 -- the original aggregate has been stripped down to one
1563 -- element. Replace the aggregate by the element itself.
1565 if Output = Last_Output then
1566 Rewrite (Outputs, Output);
1568 else
1569 -- Generate a clause of the form:
1570 -- (Output => Inputs)
1572 New_Clause :=
1573 Make_Component_Association (Loc,
1574 Choices => New_List (Output),
1575 Expression => New_Copy_Tree (Inputs));
1577 -- The new clause contains replicated content that has
1578 -- already been analyzed. There is not need to reanalyze
1579 -- them.
1581 Set_Analyzed (New_Clause);
1582 Insert_After (Clause, New_Clause);
1583 end if;
1585 Output := Next_Output;
1586 end loop;
1587 end if;
1588 end Normalize_Outputs;
1590 -- Local variables
1592 Outputs : constant Node_Id := First (Choices (Clause));
1593 Inputs : Node_Id;
1594 Last_Output : Node_Id;
1595 Next_Output : Node_Id;
1596 Output : Node_Id;
1598 -- Start of processing for Normalize_Clause
1600 begin
1601 -- A self-dependency appears as operator "+". Remove the "+" from the
1602 -- tree by moving the real inputs to their proper place.
1604 if Nkind (Expression (Clause)) = N_Op_Plus then
1605 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1606 Inputs := Expression (Clause);
1608 -- Multiple outputs appear as an aggregate
1610 if Nkind (Outputs) = N_Aggregate then
1611 Last_Output := Last (Expressions (Outputs));
1613 Output := First (Expressions (Outputs));
1614 while Present (Output) loop
1616 -- Normalization may remove an output from its list,
1617 -- preserve the subsequent output now.
1619 Next_Output := Next (Output);
1621 Create_Or_Modify_Clause
1622 (Output => Output,
1623 Outputs => Outputs,
1624 Inputs => Inputs,
1625 After => Clause,
1626 In_Place => Output = Last_Output,
1627 Multiple => True);
1629 Output := Next_Output;
1630 end loop;
1632 -- Solitary output
1634 else
1635 Create_Or_Modify_Clause
1636 (Output => Outputs,
1637 Outputs => Empty,
1638 Inputs => Inputs,
1639 After => Empty,
1640 In_Place => True,
1641 Multiple => False);
1642 end if;
1643 end if;
1645 -- Split a clause with multiple outputs into multiple clauses with a
1646 -- single output.
1648 Normalize_Outputs;
1649 end Normalize_Clause;
1651 -- Local variables
1653 Deps : constant Node_Id :=
1654 Get_Pragma_Arg
1655 (First (Pragma_Argument_Associations (N)));
1656 Clause : Node_Id;
1657 Errors : Nat;
1658 Last_Clause : Node_Id;
1659 Subp_Decl : Node_Id;
1661 Restore_Scope : Boolean := False;
1662 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
1664 -- Start of processing for Analyze_Depends_In_Decl_Part
1666 begin
1667 Set_Analyzed (N);
1669 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
1670 Subp_Id := Defining_Entity (Subp_Decl);
1672 -- The logic in this routine is used to analyze both pragma Depends and
1673 -- pragma Refined_Depends since they have the same syntax and base
1674 -- semantics. Find the entity of the corresponding spec when analyzing
1675 -- Refined_Depends.
1677 if Nkind (Subp_Decl) = N_Subprogram_Body
1678 and then Present (Corresponding_Spec (Subp_Decl))
1679 then
1680 Spec_Id := Corresponding_Spec (Subp_Decl);
1682 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
1683 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
1684 then
1685 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
1687 else
1688 Spec_Id := Subp_Id;
1689 end if;
1691 -- Empty dependency list
1693 if Nkind (Deps) = N_Null then
1695 -- Gather all states, variables and formal parameters that the
1696 -- subprogram may depend on. These items are obtained from the
1697 -- parameter profile or pragma [Refined_]Global (if available).
1699 Collect_Subprogram_Inputs_Outputs
1700 (Subp_Id => Subp_Id,
1701 Subp_Inputs => Subp_Inputs,
1702 Subp_Outputs => Subp_Outputs,
1703 Global_Seen => Global_Seen);
1705 -- Verify that every input or output of the subprogram appear in a
1706 -- dependency.
1708 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1709 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1710 Check_Function_Return;
1712 -- Dependency clauses appear as component associations of an aggregate
1714 elsif Nkind (Deps) = N_Aggregate then
1716 -- Do not attempt to perform analysis of a syntactically illegal
1717 -- clause as this will lead to misleading errors.
1719 if Has_Extra_Parentheses (Deps) then
1720 return;
1721 end if;
1723 if Present (Component_Associations (Deps)) then
1724 Last_Clause := Last (Component_Associations (Deps));
1726 -- Gather all states, variables and formal parameters that the
1727 -- subprogram may depend on. These items are obtained from the
1728 -- parameter profile or pragma [Refined_]Global (if available).
1730 Collect_Subprogram_Inputs_Outputs
1731 (Subp_Id => Subp_Id,
1732 Subp_Inputs => Subp_Inputs,
1733 Subp_Outputs => Subp_Outputs,
1734 Global_Seen => Global_Seen);
1736 -- Ensure that the formal parameters are visible when analyzing
1737 -- all clauses. This falls out of the general rule of aspects
1738 -- pertaining to subprogram declarations. Skip the installation
1739 -- for subprogram bodies because the formals are already visible.
1741 if not In_Open_Scopes (Spec_Id) then
1742 Restore_Scope := True;
1743 Push_Scope (Spec_Id);
1744 Install_Formals (Spec_Id);
1745 end if;
1747 Clause := First (Component_Associations (Deps));
1748 while Present (Clause) loop
1749 Errors := Serious_Errors_Detected;
1751 -- Normalization may create extra clauses that contain
1752 -- replicated input and output names. There is no need to
1753 -- reanalyze them.
1755 if not Analyzed (Clause) then
1756 Set_Analyzed (Clause);
1758 Analyze_Dependency_Clause
1759 (Clause => Clause,
1760 Is_Last => Clause = Last_Clause);
1761 end if;
1763 -- Do not normalize a clause if errors were detected (count
1764 -- of Serious_Errors has increased) because the inputs and/or
1765 -- outputs may denote illegal items. Normalization is disabled
1766 -- in ASIS mode as it alters the tree by introducing new nodes
1767 -- similar to expansion.
1769 if Serious_Errors_Detected = Errors and then not ASIS_Mode then
1770 Normalize_Clause (Clause);
1771 end if;
1773 Next (Clause);
1774 end loop;
1776 if Restore_Scope then
1777 End_Scope;
1778 end if;
1780 -- Verify that every input or output of the subprogram appear in a
1781 -- dependency.
1783 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1784 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1785 Check_Function_Return;
1787 -- The dependency list is malformed. This is a syntax error, always
1788 -- report.
1790 else
1791 Error_Msg_N ("malformed dependency relation", Deps);
1792 return;
1793 end if;
1795 -- The top level dependency relation is malformed. This is a syntax
1796 -- error, always report.
1798 else
1799 Error_Msg_N ("malformed dependency relation", Deps);
1800 return;
1801 end if;
1803 -- Ensure that a state and a corresponding constituent do not appear
1804 -- together in pragma [Refined_]Depends.
1806 Check_State_And_Constituent_Use
1807 (States => States_Seen,
1808 Constits => Constits_Seen,
1809 Context => N);
1810 end Analyze_Depends_In_Decl_Part;
1812 --------------------------------------------
1813 -- Analyze_External_Property_In_Decl_Part --
1814 --------------------------------------------
1816 procedure Analyze_External_Property_In_Decl_Part
1817 (N : Node_Id;
1818 Expr_Val : out Boolean)
1820 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
1821 Obj_Id : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
1822 Expr : constant Node_Id := Get_Pragma_Arg (Next (Arg1));
1824 begin
1825 Error_Msg_Name_1 := Pragma_Name (N);
1827 -- An external property pragma must apply to an effectively volatile
1828 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
1829 -- The check is performed at the end of the declarative region due to a
1830 -- possible out-of-order arrangement of pragmas:
1832 -- Obj : ...;
1833 -- pragma Async_Readers (Obj);
1834 -- pragma Volatile (Obj);
1836 if not Is_Effectively_Volatile (Obj_Id) then
1837 SPARK_Msg_N
1838 ("external property % must apply to a volatile object", N);
1839 end if;
1841 -- Ensure that the Boolean expression (if present) is static. A missing
1842 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
1844 Expr_Val := True;
1846 if Present (Expr) then
1847 Analyze_And_Resolve (Expr, Standard_Boolean);
1849 if Is_OK_Static_Expression (Expr) then
1850 Expr_Val := Is_True (Expr_Value (Expr));
1851 else
1852 SPARK_Msg_N ("expression of % must be static", Expr);
1853 end if;
1854 end if;
1855 end Analyze_External_Property_In_Decl_Part;
1857 ---------------------------------
1858 -- Analyze_Global_In_Decl_Part --
1859 ---------------------------------
1861 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
1862 Constits_Seen : Elist_Id := No_Elist;
1863 -- A list containing the entities of all constituents processed so far.
1864 -- It aids in detecting illegal usage of a state and a corresponding
1865 -- constituent in pragma [Refinde_]Global.
1867 Seen : Elist_Id := No_Elist;
1868 -- A list containing the entities of all the items processed so far. It
1869 -- plays a role in detecting distinct entities.
1871 Spec_Id : Entity_Id;
1872 -- The entity of the subprogram subject to pragma [Refined_]Global
1874 States_Seen : Elist_Id := No_Elist;
1875 -- A list containing the entities of all states processed so far. It
1876 -- helps in detecting illegal usage of a state and a corresponding
1877 -- constituent in pragma [Refined_]Global.
1879 Subp_Id : Entity_Id;
1880 -- The entity of the subprogram [body or stub] subject to pragma
1881 -- [Refined_]Global.
1883 In_Out_Seen : Boolean := False;
1884 Input_Seen : Boolean := False;
1885 Output_Seen : Boolean := False;
1886 Proof_Seen : Boolean := False;
1887 -- Flags used to verify the consistency of modes
1889 procedure Analyze_Global_List
1890 (List : Node_Id;
1891 Global_Mode : Name_Id := Name_Input);
1892 -- Verify the legality of a single global list declaration. Global_Mode
1893 -- denotes the current mode in effect.
1895 -------------------------
1896 -- Analyze_Global_List --
1897 -------------------------
1899 procedure Analyze_Global_List
1900 (List : Node_Id;
1901 Global_Mode : Name_Id := Name_Input)
1903 procedure Analyze_Global_Item
1904 (Item : Node_Id;
1905 Global_Mode : Name_Id);
1906 -- Verify the legality of a single global item declaration.
1907 -- Global_Mode denotes the current mode in effect.
1909 procedure Check_Duplicate_Mode
1910 (Mode : Node_Id;
1911 Status : in out Boolean);
1912 -- Flag Status denotes whether a particular mode has been seen while
1913 -- processing a global list. This routine verifies that Mode is not a
1914 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
1916 procedure Check_Mode_Restriction_In_Enclosing_Context
1917 (Item : Node_Id;
1918 Item_Id : Entity_Id);
1919 -- Verify that an item of mode In_Out or Output does not appear as an
1920 -- input in the Global aspect of an enclosing subprogram. If this is
1921 -- the case, emit an error. Item and Item_Id are respectively the
1922 -- item and its entity.
1924 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
1925 -- Mode denotes either In_Out or Output. Depending on the kind of the
1926 -- related subprogram, emit an error if those two modes apply to a
1927 -- function (SPARK RM 6.1.4(10)).
1929 -------------------------
1930 -- Analyze_Global_Item --
1931 -------------------------
1933 procedure Analyze_Global_Item
1934 (Item : Node_Id;
1935 Global_Mode : Name_Id)
1937 Item_Id : Entity_Id;
1939 begin
1940 -- Detect one of the following cases
1942 -- with Global => (null, Name)
1943 -- with Global => (Name_1, null, Name_2)
1944 -- with Global => (Name, null)
1946 if Nkind (Item) = N_Null then
1947 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
1948 return;
1949 end if;
1951 Analyze (Item);
1952 Resolve_State (Item);
1954 -- Find the entity of the item. If this is a renaming, climb the
1955 -- renaming chain to reach the root object. Renamings of non-
1956 -- entire objects do not yield an entity (Empty).
1958 Item_Id := Entity_Of (Item);
1960 if Present (Item_Id) then
1962 -- A global item may denote a formal parameter of an enclosing
1963 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
1964 -- provide a better error diagnostic.
1966 if Is_Formal (Item_Id) then
1967 if Scope (Item_Id) = Spec_Id then
1968 SPARK_Msg_NE
1969 ("global item cannot reference parameter of subprogram",
1970 Item, Spec_Id);
1971 return;
1972 end if;
1974 -- A constant cannot act as a global item (SPARK RM 6.1.4(7)).
1975 -- Do this check first to provide a better error diagnostic.
1977 elsif Ekind (Item_Id) = E_Constant then
1978 SPARK_Msg_N ("global item cannot denote a constant", Item);
1980 -- A formal object may act as a global item inside a generic
1982 elsif Is_Formal_Object (Item_Id) then
1983 null;
1985 -- The only legal references are those to abstract states and
1986 -- variables (SPARK RM 6.1.4(4)).
1988 elsif not Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
1989 SPARK_Msg_N
1990 ("global item must denote variable or state", Item);
1991 return;
1992 end if;
1994 -- State related checks
1996 if Ekind (Item_Id) = E_Abstract_State then
1998 -- An abstract state with visible refinement cannot appear
1999 -- in pragma [Refined_]Global as its place must be taken by
2000 -- some of its constituents (SPARK RM 6.1.4(8)).
2002 if Has_Visible_Refinement (Item_Id) then
2003 SPARK_Msg_NE
2004 ("cannot mention state & in global refinement",
2005 Item, Item_Id);
2006 SPARK_Msg_N ("\use its constituents instead", Item);
2007 return;
2009 -- If the reference to the abstract state appears in an
2010 -- enclosing package body that will eventually refine the
2011 -- state, record the reference for future checks.
2013 else
2014 Record_Possible_Body_Reference
2015 (State_Id => Item_Id,
2016 Ref => Item);
2017 end if;
2019 -- Variable related checks. These are only relevant when
2020 -- SPARK_Mode is on as they are not standard Ada legality
2021 -- rules.
2023 elsif SPARK_Mode = On
2024 and then Is_Effectively_Volatile (Item_Id)
2025 then
2026 -- An effectively volatile object cannot appear as a global
2027 -- item of a function (SPARK RM 7.1.3(9)).
2029 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
2030 Error_Msg_NE
2031 ("volatile object & cannot act as global item of a "
2032 & "function", Item, Item_Id);
2033 return;
2035 -- An effectively volatile object with external property
2036 -- Effective_Reads set to True must have mode Output or
2037 -- In_Out.
2039 elsif Effective_Reads_Enabled (Item_Id)
2040 and then Global_Mode = Name_Input
2041 then
2042 Error_Msg_NE
2043 ("volatile object & with property Effective_Reads must "
2044 & "have mode In_Out or Output (SPARK RM 7.1.3(11))",
2045 Item, Item_Id);
2046 return;
2047 end if;
2048 end if;
2050 -- When the item renames an entire object, replace the item
2051 -- with a reference to the object.
2053 if Present (Renamed_Object (Entity (Item))) then
2054 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2055 Analyze (Item);
2056 end if;
2058 -- Some form of illegal construct masquerading as a name
2059 -- (SPARK RM 6.1.4(4)).
2061 else
2062 Error_Msg_N ("global item must denote variable or state", Item);
2063 return;
2064 end if;
2066 -- Verify that an output does not appear as an input in an
2067 -- enclosing subprogram.
2069 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2070 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
2071 end if;
2073 -- The same entity might be referenced through various way.
2074 -- Check the entity of the item rather than the item itself
2075 -- (SPARK RM 6.1.4(11)).
2077 if Contains (Seen, Item_Id) then
2078 SPARK_Msg_N ("duplicate global item", Item);
2080 -- Add the entity of the current item to the list of processed
2081 -- items.
2083 else
2084 Add_Item (Item_Id, Seen);
2086 if Ekind (Item_Id) = E_Abstract_State then
2087 Add_Item (Item_Id, States_Seen);
2088 end if;
2090 if Ekind_In (Item_Id, E_Abstract_State, E_Variable)
2091 and then Present (Encapsulating_State (Item_Id))
2092 then
2093 Add_Item (Item_Id, Constits_Seen);
2094 end if;
2095 end if;
2096 end Analyze_Global_Item;
2098 --------------------------
2099 -- Check_Duplicate_Mode --
2100 --------------------------
2102 procedure Check_Duplicate_Mode
2103 (Mode : Node_Id;
2104 Status : in out Boolean)
2106 begin
2107 if Status then
2108 SPARK_Msg_N ("duplicate global mode", Mode);
2109 end if;
2111 Status := True;
2112 end Check_Duplicate_Mode;
2114 -------------------------------------------------
2115 -- Check_Mode_Restriction_In_Enclosing_Context --
2116 -------------------------------------------------
2118 procedure Check_Mode_Restriction_In_Enclosing_Context
2119 (Item : Node_Id;
2120 Item_Id : Entity_Id)
2122 Context : Entity_Id;
2123 Dummy : Boolean;
2124 Inputs : Elist_Id := No_Elist;
2125 Outputs : Elist_Id := No_Elist;
2127 begin
2128 -- Traverse the scope stack looking for enclosing subprograms
2129 -- subject to pragma [Refined_]Global.
2131 Context := Scope (Subp_Id);
2132 while Present (Context) and then Context /= Standard_Standard loop
2133 if Is_Subprogram (Context)
2134 and then
2135 (Present (Get_Pragma (Context, Pragma_Global))
2136 or else
2137 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2138 then
2139 Collect_Subprogram_Inputs_Outputs
2140 (Subp_Id => Context,
2141 Subp_Inputs => Inputs,
2142 Subp_Outputs => Outputs,
2143 Global_Seen => Dummy);
2145 -- The item is classified as In_Out or Output but appears as
2146 -- an Input in an enclosing subprogram (SPARK RM 6.1.4(12)).
2148 if Appears_In (Inputs, Item_Id)
2149 and then not Appears_In (Outputs, Item_Id)
2150 then
2151 SPARK_Msg_NE
2152 ("global item & cannot have mode In_Out or Output",
2153 Item, Item_Id);
2154 SPARK_Msg_NE
2155 ("\item already appears as input of subprogram &",
2156 Item, Context);
2158 -- Stop the traversal once an error has been detected
2160 exit;
2161 end if;
2162 end if;
2164 Context := Scope (Context);
2165 end loop;
2166 end Check_Mode_Restriction_In_Enclosing_Context;
2168 ----------------------------------------
2169 -- Check_Mode_Restriction_In_Function --
2170 ----------------------------------------
2172 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2173 begin
2174 if Ekind (Spec_Id) = E_Function then
2175 SPARK_Msg_N
2176 ("global mode & is not applicable to functions", Mode);
2177 end if;
2178 end Check_Mode_Restriction_In_Function;
2180 -- Local variables
2182 Assoc : Node_Id;
2183 Item : Node_Id;
2184 Mode : Node_Id;
2186 -- Start of processing for Analyze_Global_List
2188 begin
2189 if Nkind (List) = N_Null then
2190 Set_Analyzed (List);
2192 -- Single global item declaration
2194 elsif Nkind_In (List, N_Expanded_Name,
2195 N_Identifier,
2196 N_Selected_Component)
2197 then
2198 Analyze_Global_Item (List, Global_Mode);
2200 -- Simple global list or moded global list declaration
2202 elsif Nkind (List) = N_Aggregate then
2203 Set_Analyzed (List);
2205 -- The declaration of a simple global list appear as a collection
2206 -- of expressions.
2208 if Present (Expressions (List)) then
2209 if Present (Component_Associations (List)) then
2210 SPARK_Msg_N
2211 ("cannot mix moded and non-moded global lists", List);
2212 end if;
2214 Item := First (Expressions (List));
2215 while Present (Item) loop
2216 Analyze_Global_Item (Item, Global_Mode);
2218 Next (Item);
2219 end loop;
2221 -- The declaration of a moded global list appears as a collection
2222 -- of component associations where individual choices denote
2223 -- modes.
2225 elsif Present (Component_Associations (List)) then
2226 if Present (Expressions (List)) then
2227 SPARK_Msg_N
2228 ("cannot mix moded and non-moded global lists", List);
2229 end if;
2231 Assoc := First (Component_Associations (List));
2232 while Present (Assoc) loop
2233 Mode := First (Choices (Assoc));
2235 if Nkind (Mode) = N_Identifier then
2236 if Chars (Mode) = Name_In_Out then
2237 Check_Duplicate_Mode (Mode, In_Out_Seen);
2238 Check_Mode_Restriction_In_Function (Mode);
2240 elsif Chars (Mode) = Name_Input then
2241 Check_Duplicate_Mode (Mode, Input_Seen);
2243 elsif Chars (Mode) = Name_Output then
2244 Check_Duplicate_Mode (Mode, Output_Seen);
2245 Check_Mode_Restriction_In_Function (Mode);
2247 elsif Chars (Mode) = Name_Proof_In then
2248 Check_Duplicate_Mode (Mode, Proof_Seen);
2250 else
2251 SPARK_Msg_N ("invalid mode selector", Mode);
2252 end if;
2254 else
2255 SPARK_Msg_N ("invalid mode selector", Mode);
2256 end if;
2258 -- Items in a moded list appear as a collection of
2259 -- expressions. Reuse the existing machinery to analyze
2260 -- them.
2262 Analyze_Global_List
2263 (List => Expression (Assoc),
2264 Global_Mode => Chars (Mode));
2266 Next (Assoc);
2267 end loop;
2269 -- Invalid tree
2271 else
2272 raise Program_Error;
2273 end if;
2275 -- Any other attempt to declare a global item is illegal. This is a
2276 -- syntax error, always report.
2278 else
2279 Error_Msg_N ("malformed global list", List);
2280 end if;
2281 end Analyze_Global_List;
2283 -- Local variables
2285 Items : constant Node_Id :=
2286 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
2287 Subp_Decl : Node_Id;
2289 Restore_Scope : Boolean := False;
2290 -- Set True if we do a Push_Scope requiring a Pop_Scope on exit
2292 -- Start of processing for Analyze_Global_In_Decl_List
2294 begin
2295 Set_Analyzed (N);
2296 Check_SPARK_Aspect_For_ASIS (N);
2298 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
2299 Subp_Id := Defining_Entity (Subp_Decl);
2301 -- The logic in this routine is used to analyze both pragma Global and
2302 -- pragma Refined_Global since they have the same syntax and base
2303 -- semantics. Find the entity of the corresponding spec when analyzing
2304 -- Refined_Global.
2306 if Nkind (Subp_Decl) = N_Subprogram_Body
2307 and then Present (Corresponding_Spec (Subp_Decl))
2308 then
2309 Spec_Id := Corresponding_Spec (Subp_Decl);
2311 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
2312 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
2313 then
2314 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
2316 else
2317 Spec_Id := Subp_Id;
2318 end if;
2320 -- There is nothing to be done for a null global list
2322 if Nkind (Items) = N_Null then
2323 Set_Analyzed (Items);
2325 -- Analyze the various forms of global lists and items. Note that some
2326 -- of these may be malformed in which case the analysis emits error
2327 -- messages.
2329 else
2330 -- Ensure that the formal parameters are visible when processing an
2331 -- item. This falls out of the general rule of aspects pertaining to
2332 -- subprogram declarations.
2334 if not In_Open_Scopes (Spec_Id) then
2335 Restore_Scope := True;
2336 Push_Scope (Spec_Id);
2337 Install_Formals (Spec_Id);
2338 end if;
2340 Analyze_Global_List (Items);
2342 if Restore_Scope then
2343 End_Scope;
2344 end if;
2345 end if;
2347 -- Ensure that a state and a corresponding constituent do not appear
2348 -- together in pragma [Refined_]Global.
2350 Check_State_And_Constituent_Use
2351 (States => States_Seen,
2352 Constits => Constits_Seen,
2353 Context => N);
2354 end Analyze_Global_In_Decl_Part;
2356 --------------------------------------------
2357 -- Analyze_Initial_Condition_In_Decl_Part --
2358 --------------------------------------------
2360 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2361 Expr : constant Node_Id :=
2362 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
2364 begin
2365 Set_Analyzed (N);
2367 -- The expression is preanalyzed because it has not been moved to its
2368 -- final place yet. A direct analysis may generate side effects and this
2369 -- is not desired at this point.
2371 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2372 end Analyze_Initial_Condition_In_Decl_Part;
2374 --------------------------------------
2375 -- Analyze_Initializes_In_Decl_Part --
2376 --------------------------------------
2378 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2379 Pack_Spec : constant Node_Id := Parent (N);
2380 Pack_Id : constant Entity_Id := Defining_Entity (Parent (Pack_Spec));
2382 Constits_Seen : Elist_Id := No_Elist;
2383 -- A list containing the entities of all constituents processed so far.
2384 -- It aids in detecting illegal usage of a state and a corresponding
2385 -- constituent in pragma Initializes.
2387 Items_Seen : Elist_Id := No_Elist;
2388 -- A list of all initialization items processed so far. This list is
2389 -- used to detect duplicate items.
2391 Non_Null_Seen : Boolean := False;
2392 Null_Seen : Boolean := False;
2393 -- Flags used to check the legality of a null initialization list
2395 States_And_Vars : Elist_Id := No_Elist;
2396 -- A list of all abstract states and variables declared in the visible
2397 -- declarations of the related package. This list is used to detect the
2398 -- legality of initialization items.
2400 States_Seen : Elist_Id := No_Elist;
2401 -- A list containing the entities of all states processed so far. It
2402 -- helps in detecting illegal usage of a state and a corresponding
2403 -- constituent in pragma Initializes.
2405 procedure Analyze_Initialization_Item (Item : Node_Id);
2406 -- Verify the legality of a single initialization item
2408 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2409 -- Verify the legality of a single initialization item followed by a
2410 -- list of input items.
2412 procedure Collect_States_And_Variables;
2413 -- Inspect the visible declarations of the related package and gather
2414 -- the entities of all abstract states and variables in States_And_Vars.
2416 ---------------------------------
2417 -- Analyze_Initialization_Item --
2418 ---------------------------------
2420 procedure Analyze_Initialization_Item (Item : Node_Id) is
2421 Item_Id : Entity_Id;
2423 begin
2424 -- Null initialization list
2426 if Nkind (Item) = N_Null then
2427 if Null_Seen then
2428 SPARK_Msg_N ("multiple null initializations not allowed", Item);
2430 elsif Non_Null_Seen then
2431 SPARK_Msg_N
2432 ("cannot mix null and non-null initialization items", Item);
2433 else
2434 Null_Seen := True;
2435 end if;
2437 -- Initialization item
2439 else
2440 Non_Null_Seen := True;
2442 if Null_Seen then
2443 SPARK_Msg_N
2444 ("cannot mix null and non-null initialization items", Item);
2445 end if;
2447 Analyze (Item);
2448 Resolve_State (Item);
2450 if Is_Entity_Name (Item) then
2451 Item_Id := Entity_Of (Item);
2453 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
2455 -- The state or variable must be declared in the visible
2456 -- declarations of the package (SPARK RM 7.1.5(7)).
2458 if not Contains (States_And_Vars, Item_Id) then
2459 Error_Msg_Name_1 := Chars (Pack_Id);
2460 SPARK_Msg_NE
2461 ("initialization item & must appear in the visible "
2462 & "declarations of package %", Item, Item_Id);
2464 -- Detect a duplicate use of the same initialization item
2465 -- (SPARK RM 7.1.5(5)).
2467 elsif Contains (Items_Seen, Item_Id) then
2468 SPARK_Msg_N ("duplicate initialization item", Item);
2470 -- The item is legal, add it to the list of processed states
2471 -- and variables.
2473 else
2474 Add_Item (Item_Id, Items_Seen);
2476 if Ekind (Item_Id) = E_Abstract_State then
2477 Add_Item (Item_Id, States_Seen);
2478 end if;
2480 if Present (Encapsulating_State (Item_Id)) then
2481 Add_Item (Item_Id, Constits_Seen);
2482 end if;
2483 end if;
2485 -- The item references something that is not a state or a
2486 -- variable (SPARK RM 7.1.5(3)).
2488 else
2489 SPARK_Msg_N
2490 ("initialization item must denote variable or state",
2491 Item);
2492 end if;
2494 -- Some form of illegal construct masquerading as a name
2495 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2497 else
2498 Error_Msg_N
2499 ("initialization item must denote variable or state", Item);
2500 end if;
2501 end if;
2502 end Analyze_Initialization_Item;
2504 ---------------------------------------------
2505 -- Analyze_Initialization_Item_With_Inputs --
2506 ---------------------------------------------
2508 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2509 Inputs_Seen : Elist_Id := No_Elist;
2510 -- A list of all inputs processed so far. This list is used to detect
2511 -- duplicate uses of an input.
2513 Non_Null_Seen : Boolean := False;
2514 Null_Seen : Boolean := False;
2515 -- Flags used to check the legality of an input list
2517 procedure Analyze_Input_Item (Input : Node_Id);
2518 -- Verify the legality of a single input item
2520 ------------------------
2521 -- Analyze_Input_Item --
2522 ------------------------
2524 procedure Analyze_Input_Item (Input : Node_Id) is
2525 Input_Id : Entity_Id;
2527 begin
2528 -- Null input list
2530 if Nkind (Input) = N_Null then
2531 if Null_Seen then
2532 SPARK_Msg_N
2533 ("multiple null initializations not allowed", Item);
2535 elsif Non_Null_Seen then
2536 SPARK_Msg_N
2537 ("cannot mix null and non-null initialization item", Item);
2538 else
2539 Null_Seen := True;
2540 end if;
2542 -- Input item
2544 else
2545 Non_Null_Seen := True;
2547 if Null_Seen then
2548 SPARK_Msg_N
2549 ("cannot mix null and non-null initialization item", Item);
2550 end if;
2552 Analyze (Input);
2553 Resolve_State (Input);
2555 if Is_Entity_Name (Input) then
2556 Input_Id := Entity_Of (Input);
2558 if Ekind_In (Input_Id, E_Abstract_State,
2559 E_In_Parameter,
2560 E_In_Out_Parameter,
2561 E_Out_Parameter,
2562 E_Variable)
2563 then
2564 -- The input cannot denote states or variables declared
2565 -- within the related package.
2567 if Within_Scope (Input_Id, Current_Scope) then
2568 Error_Msg_Name_1 := Chars (Pack_Id);
2569 SPARK_Msg_NE
2570 ("input item & cannot denote a visible variable or "
2571 & "state of package % (SPARK RM 7.1.5(4))",
2572 Input, Input_Id);
2574 -- Detect a duplicate use of the same input item
2575 -- (SPARK RM 7.1.5(5)).
2577 elsif Contains (Inputs_Seen, Input_Id) then
2578 SPARK_Msg_N ("duplicate input item", Input);
2580 -- Input is legal, add it to the list of processed inputs
2582 else
2583 Add_Item (Input_Id, Inputs_Seen);
2585 if Ekind (Input_Id) = E_Abstract_State then
2586 Add_Item (Input_Id, States_Seen);
2587 end if;
2589 if Ekind_In (Input_Id, E_Abstract_State, E_Variable)
2590 and then Present (Encapsulating_State (Input_Id))
2591 then
2592 Add_Item (Input_Id, Constits_Seen);
2593 end if;
2594 end if;
2596 -- The input references something that is not a state or a
2597 -- variable (SPARK RM 7.1.5(3)).
2599 else
2600 SPARK_Msg_N
2601 ("input item must denote variable or state", Input);
2602 end if;
2604 -- Some form of illegal construct masquerading as a name
2605 -- (SPARK RM 7.1.5(3)).
2607 else
2608 SPARK_Msg_N
2609 ("input item must denote variable or state", Input);
2610 end if;
2611 end if;
2612 end Analyze_Input_Item;
2614 -- Local variables
2616 Inputs : constant Node_Id := Expression (Item);
2617 Elmt : Node_Id;
2618 Input : Node_Id;
2620 Name_Seen : Boolean := False;
2621 -- A flag used to detect multiple item names
2623 -- Start of processing for Analyze_Initialization_Item_With_Inputs
2625 begin
2626 -- Inspect the name of an item with inputs
2628 Elmt := First (Choices (Item));
2629 while Present (Elmt) loop
2630 if Name_Seen then
2631 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
2632 else
2633 Name_Seen := True;
2634 Analyze_Initialization_Item (Elmt);
2635 end if;
2637 Next (Elmt);
2638 end loop;
2640 -- Multiple input items appear as an aggregate
2642 if Nkind (Inputs) = N_Aggregate then
2643 if Present (Expressions (Inputs)) then
2644 Input := First (Expressions (Inputs));
2645 while Present (Input) loop
2646 Analyze_Input_Item (Input);
2647 Next (Input);
2648 end loop;
2649 end if;
2651 if Present (Component_Associations (Inputs)) then
2652 SPARK_Msg_N
2653 ("inputs must appear in named association form", Inputs);
2654 end if;
2656 -- Single input item
2658 else
2659 Analyze_Input_Item (Inputs);
2660 end if;
2661 end Analyze_Initialization_Item_With_Inputs;
2663 ----------------------------------
2664 -- Collect_States_And_Variables --
2665 ----------------------------------
2667 procedure Collect_States_And_Variables is
2668 Decl : Node_Id;
2670 begin
2671 -- Collect the abstract states defined in the package (if any)
2673 if Present (Abstract_States (Pack_Id)) then
2674 States_And_Vars := New_Copy_Elist (Abstract_States (Pack_Id));
2675 end if;
2677 -- Collect all variables the appear in the visible declarations of
2678 -- the related package.
2680 if Present (Visible_Declarations (Pack_Spec)) then
2681 Decl := First (Visible_Declarations (Pack_Spec));
2682 while Present (Decl) loop
2683 if Nkind (Decl) = N_Object_Declaration
2684 and then Ekind (Defining_Entity (Decl)) = E_Variable
2685 and then Comes_From_Source (Decl)
2686 then
2687 Add_Item (Defining_Entity (Decl), States_And_Vars);
2688 end if;
2690 Next (Decl);
2691 end loop;
2692 end if;
2693 end Collect_States_And_Variables;
2695 -- Local variables
2697 Inits : constant Node_Id :=
2698 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
2699 Init : Node_Id;
2701 -- Start of processing for Analyze_Initializes_In_Decl_Part
2703 begin
2704 Set_Analyzed (N);
2706 Check_SPARK_Aspect_For_ASIS (N);
2708 -- Nothing to do when the initialization list is empty
2710 if Nkind (Inits) = N_Null then
2711 return;
2712 end if;
2714 -- Single and multiple initialization clauses appear as an aggregate. If
2715 -- this is not the case, then either the parser or the analysis of the
2716 -- pragma failed to produce an aggregate.
2718 pragma Assert (Nkind (Inits) = N_Aggregate);
2720 -- Initialize the various lists used during analysis
2722 Collect_States_And_Variables;
2724 if Present (Expressions (Inits)) then
2725 Init := First (Expressions (Inits));
2726 while Present (Init) loop
2727 Analyze_Initialization_Item (Init);
2728 Next (Init);
2729 end loop;
2730 end if;
2732 if Present (Component_Associations (Inits)) then
2733 Init := First (Component_Associations (Inits));
2734 while Present (Init) loop
2735 Analyze_Initialization_Item_With_Inputs (Init);
2736 Next (Init);
2737 end loop;
2738 end if;
2740 -- Ensure that a state and a corresponding constituent do not appear
2741 -- together in pragma Initializes.
2743 Check_State_And_Constituent_Use
2744 (States => States_Seen,
2745 Constits => Constits_Seen,
2746 Context => N);
2747 end Analyze_Initializes_In_Decl_Part;
2749 --------------------
2750 -- Analyze_Pragma --
2751 --------------------
2753 procedure Analyze_Pragma (N : Node_Id) is
2754 Loc : constant Source_Ptr := Sloc (N);
2755 Prag_Id : Pragma_Id;
2757 Pname : Name_Id;
2758 -- Name of the source pragma, or name of the corresponding aspect for
2759 -- pragmas which originate in a source aspect. In the latter case, the
2760 -- name may be different from the pragma name.
2762 Pragma_Exit : exception;
2763 -- This exception is used to exit pragma processing completely. It
2764 -- is used when an error is detected, and no further processing is
2765 -- required. It is also used if an earlier error has left the tree in
2766 -- a state where the pragma should not be processed.
2768 Arg_Count : Nat;
2769 -- Number of pragma argument associations
2771 Arg1 : Node_Id;
2772 Arg2 : Node_Id;
2773 Arg3 : Node_Id;
2774 Arg4 : Node_Id;
2775 -- First four pragma arguments (pragma argument association nodes, or
2776 -- Empty if the corresponding argument does not exist).
2778 type Name_List is array (Natural range <>) of Name_Id;
2779 type Args_List is array (Natural range <>) of Node_Id;
2780 -- Types used for arguments to Check_Arg_Order and Gather_Associations
2782 -----------------------
2783 -- Local Subprograms --
2784 -----------------------
2786 procedure Acquire_Warning_Match_String (Arg : Node_Id);
2787 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
2788 -- get the given string argument, and place it in Name_Buffer, adding
2789 -- leading and trailing asterisks if they are not already present. The
2790 -- caller has already checked that Arg is a static string expression.
2792 procedure Ada_2005_Pragma;
2793 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
2794 -- Ada 95 mode, these are implementation defined pragmas, so should be
2795 -- caught by the No_Implementation_Pragmas restriction.
2797 procedure Ada_2012_Pragma;
2798 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
2799 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
2800 -- should be caught by the No_Implementation_Pragmas restriction.
2802 procedure Analyze_Part_Of
2803 (Item_Id : Entity_Id;
2804 State : Node_Id;
2805 Indic : Node_Id;
2806 Legal : out Boolean);
2807 -- Subsidiary to the analysis of pragmas Abstract_State and Part_Of.
2808 -- Perform full analysis of indicator Part_Of. Item_Id is the entity of
2809 -- an abstract state, variable or package instantiation. State is the
2810 -- encapsulating state. Indic is the Part_Of indicator. Flag Legal is
2811 -- set when the indicator is legal.
2813 procedure Analyze_Refined_Pragma
2814 (Spec_Id : out Entity_Id;
2815 Body_Id : out Entity_Id;
2816 Legal : out Boolean);
2817 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
2818 -- Refined_Global and Refined_Post. Check the placement and related
2819 -- context of the pragma. Spec_Id is the entity of the related
2820 -- subprogram. Body_Id is the entity of the subprogram body. Flag
2821 -- Legal is set when the pragma is properly placed.
2823 procedure Check_Ada_83_Warning;
2824 -- Issues a warning message for the current pragma if operating in Ada
2825 -- 83 mode (used for language pragmas that are not a standard part of
2826 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
2827 -- of 95 pragma.
2829 procedure Check_Arg_Count (Required : Nat);
2830 -- Check argument count for pragma is equal to given parameter. If not,
2831 -- then issue an error message and raise Pragma_Exit.
2833 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
2834 -- Arg which can either be a pragma argument association, in which case
2835 -- the check is applied to the expression of the association or an
2836 -- expression directly.
2838 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
2839 -- Check that an argument has the right form for an EXTERNAL_NAME
2840 -- parameter of an extended import/export pragma. The rule is that the
2841 -- name must be an identifier or string literal (in Ada 83 mode) or a
2842 -- static string expression (in Ada 95 mode).
2844 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
2845 -- Check the specified argument Arg to make sure that it is an
2846 -- identifier. If not give error and raise Pragma_Exit.
2848 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
2849 -- Check the specified argument Arg to make sure that it is an integer
2850 -- literal. If not give error and raise Pragma_Exit.
2852 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
2853 -- Check the specified argument Arg to make sure that it has the proper
2854 -- syntactic form for a local name and meets the semantic requirements
2855 -- for a local name. The local name is analyzed as part of the
2856 -- processing for this call. In addition, the local name is required
2857 -- to represent an entity at the library level.
2859 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
2860 -- Check the specified argument Arg to make sure that it has the proper
2861 -- syntactic form for a local name and meets the semantic requirements
2862 -- for a local name. The local name is analyzed as part of the
2863 -- processing for this call.
2865 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
2866 -- Check the specified argument Arg to make sure that it is a valid
2867 -- locking policy name. If not give error and raise Pragma_Exit.
2869 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
2870 -- Check the specified argument Arg to make sure that it is a valid
2871 -- elaboration policy name. If not give error and raise Pragma_Exit.
2873 procedure Check_Arg_Is_One_Of
2874 (Arg : Node_Id;
2875 N1, N2 : Name_Id);
2876 procedure Check_Arg_Is_One_Of
2877 (Arg : Node_Id;
2878 N1, N2, N3 : Name_Id);
2879 procedure Check_Arg_Is_One_Of
2880 (Arg : Node_Id;
2881 N1, N2, N3, N4 : Name_Id);
2882 procedure Check_Arg_Is_One_Of
2883 (Arg : Node_Id;
2884 N1, N2, N3, N4, N5 : Name_Id);
2885 -- Check the specified argument Arg to make sure that it is an
2886 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
2887 -- present). If not then give error and raise Pragma_Exit.
2889 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
2890 -- Check the specified argument Arg to make sure that it is a valid
2891 -- queuing policy name. If not give error and raise Pragma_Exit.
2893 procedure Check_Arg_Is_OK_Static_Expression
2894 (Arg : Node_Id;
2895 Typ : Entity_Id := Empty);
2896 -- Check the specified argument Arg to make sure that it is a static
2897 -- expression of the given type (i.e. it will be analyzed and resolved
2898 -- using this type, which can be any valid argument to Resolve, e.g.
2899 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2900 -- Typ is left Empty, then any static expression is allowed. Includes
2901 -- checking that the argument does not raise Constraint_Error.
2903 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
2904 -- Check the specified argument Arg to make sure that it is a valid task
2905 -- dispatching policy name. If not give error and raise Pragma_Exit.
2907 procedure Check_Arg_Order (Names : Name_List);
2908 -- Checks for an instance of two arguments with identifiers for the
2909 -- current pragma which are not in the sequence indicated by Names,
2910 -- and if so, generates a fatal message about bad order of arguments.
2912 procedure Check_At_Least_N_Arguments (N : Nat);
2913 -- Check there are at least N arguments present
2915 procedure Check_At_Most_N_Arguments (N : Nat);
2916 -- Check there are no more than N arguments present
2918 procedure Check_Component
2919 (Comp : Node_Id;
2920 UU_Typ : Entity_Id;
2921 In_Variant_Part : Boolean := False);
2922 -- Examine an Unchecked_Union component for correct use of per-object
2923 -- constrained subtypes, and for restrictions on finalizable components.
2924 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
2925 -- should be set when Comp comes from a record variant.
2927 procedure Check_Declaration_Order (First : Node_Id; Second : Node_Id);
2928 -- Subsidiary routine to the analysis of pragmas Abstract_State,
2929 -- Initial_Condition and Initializes. Determine whether pragma First
2930 -- appears before pragma Second. If this is not the case, emit an error.
2932 procedure Check_Duplicate_Pragma (E : Entity_Id);
2933 -- Check if a rep item of the same name as the current pragma is already
2934 -- chained as a rep pragma to the given entity. If so give a message
2935 -- about the duplicate, and then raise Pragma_Exit so does not return.
2936 -- Note that if E is a type, then this routine avoids flagging a pragma
2937 -- which applies to a parent type from which E is derived.
2939 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
2940 -- Nam is an N_String_Literal node containing the external name set by
2941 -- an Import or Export pragma (or extended Import or Export pragma).
2942 -- This procedure checks for possible duplications if this is the export
2943 -- case, and if found, issues an appropriate error message.
2945 procedure Check_Expr_Is_OK_Static_Expression
2946 (Expr : Node_Id;
2947 Typ : Entity_Id := Empty);
2948 -- Check the specified expression Expr to make sure that it is a static
2949 -- expression of the given type (i.e. it will be analyzed and resolved
2950 -- using this type, which can be any valid argument to Resolve, e.g.
2951 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2952 -- Typ is left Empty, then any static expression is allowed. Includes
2953 -- checking that the expression does not raise Constraint_Error.
2955 procedure Check_First_Subtype (Arg : Node_Id);
2956 -- Checks that Arg, whose expression is an entity name, references a
2957 -- first subtype.
2959 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
2960 -- Checks that the given argument has an identifier, and if so, requires
2961 -- it to match the given identifier name. If there is no identifier, or
2962 -- a non-matching identifier, then an error message is given and
2963 -- Pragma_Exit is raised.
2965 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
2966 -- Checks that the given argument has an identifier, and if so, requires
2967 -- it to match one of the given identifier names. If there is no
2968 -- identifier, or a non-matching identifier, then an error message is
2969 -- given and Pragma_Exit is raised.
2971 procedure Check_In_Main_Program;
2972 -- Common checks for pragmas that appear within a main program
2973 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
2975 procedure Check_Interrupt_Or_Attach_Handler;
2976 -- Common processing for first argument of pragma Interrupt_Handler or
2977 -- pragma Attach_Handler.
2979 procedure Check_Loop_Pragma_Placement;
2980 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
2981 -- appear immediately within a construct restricted to loops, and that
2982 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
2984 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
2985 -- Check that pragma appears in a declarative part, or in a package
2986 -- specification, i.e. that it does not occur in a statement sequence
2987 -- in a body.
2989 procedure Check_No_Identifier (Arg : Node_Id);
2990 -- Checks that the given argument does not have an identifier. If
2991 -- an identifier is present, then an error message is issued, and
2992 -- Pragma_Exit is raised.
2994 procedure Check_No_Identifiers;
2995 -- Checks that none of the arguments to the pragma has an identifier.
2996 -- If any argument has an identifier, then an error message is issued,
2997 -- and Pragma_Exit is raised.
2999 procedure Check_No_Link_Name;
3000 -- Checks that no link name is specified
3002 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
3003 -- Checks if the given argument has an identifier, and if so, requires
3004 -- it to match the given identifier name. If there is a non-matching
3005 -- identifier, then an error message is given and Pragma_Exit is raised.
3007 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
3008 -- Checks if the given argument has an identifier, and if so, requires
3009 -- it to match the given identifier name. If there is a non-matching
3010 -- identifier, then an error message is given and Pragma_Exit is raised.
3011 -- In this version of the procedure, the identifier name is given as
3012 -- a string with lower case letters.
3014 procedure Check_Pre_Post;
3015 -- Called to perform checks for Pre, Pre_Class, Post, Post_Class
3016 -- pragmas. These are processed by transformation to equivalent
3017 -- Precondition and Postcondition pragmas, but Pre and Post need an
3018 -- additional check that they are not used in a subprogram body when
3019 -- there is a separate spec present.
3021 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
3022 -- Called to process a precondition or postcondition pragma. There are
3023 -- three cases:
3025 -- The pragma appears after a subprogram spec
3027 -- If the corresponding check is not enabled, the pragma is analyzed
3028 -- but otherwise ignored and control returns with In_Body set False.
3030 -- If the check is enabled, then the first step is to analyze the
3031 -- pragma, but this is skipped if the subprogram spec appears within
3032 -- a package specification (because this is the case where we delay
3033 -- analysis till the end of the spec). Then (whether or not it was
3034 -- analyzed), the pragma is chained to the subprogram in question
3035 -- (using Pre_Post_Conditions and Next_Pragma) and control returns
3036 -- to the caller with In_Body set False.
3038 -- The pragma appears at the start of subprogram body declarations
3040 -- In this case an immediate return to the caller is made with
3041 -- In_Body set True, and the pragma is NOT analyzed.
3043 -- In all other cases, an error message for bad placement is given
3045 procedure Check_Static_Constraint (Constr : Node_Id);
3046 -- Constr is a constraint from an N_Subtype_Indication node from a
3047 -- component constraint in an Unchecked_Union type. This routine checks
3048 -- that the constraint is static as required by the restrictions for
3049 -- Unchecked_Union.
3051 procedure Check_Test_Case;
3052 -- Called to process a test-case pragma. It starts with checking pragma
3053 -- arguments, and the rest of the treatment is similar to the one for
3054 -- pre- and postcondition in Check_Precondition_Postcondition, except
3055 -- the placement rules for the test-case pragma are stricter. These
3056 -- pragmas may only occur after a subprogram spec declared directly
3057 -- in a package spec unit. In this case, the pragma is chained to the
3058 -- subprogram in question (using Contract_Test_Cases and Next_Pragma)
3059 -- and analysis of the pragma is delayed till the end of the spec. In
3060 -- all other cases, an error message for bad placement is given.
3062 procedure Check_Valid_Configuration_Pragma;
3063 -- Legality checks for placement of a configuration pragma
3065 procedure Check_Valid_Library_Unit_Pragma;
3066 -- Legality checks for library unit pragmas. A special case arises for
3067 -- pragmas in generic instances that come from copies of the original
3068 -- library unit pragmas in the generic templates. In the case of other
3069 -- than library level instantiations these can appear in contexts which
3070 -- would normally be invalid (they only apply to the original template
3071 -- and to library level instantiations), and they are simply ignored,
3072 -- which is implemented by rewriting them as null statements.
3074 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
3075 -- Check an Unchecked_Union variant for lack of nested variants and
3076 -- presence of at least one component. UU_Typ is the related Unchecked_
3077 -- Union type.
3079 procedure Ensure_Aggregate_Form (Arg : Node_Id);
3080 -- Subsidiary routine to the processing of pragmas Abstract_State,
3081 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
3082 -- Refined_Global and Refined_State. Transform argument Arg into an
3083 -- aggregate if not one already. N_Null is never transformed.
3085 procedure Error_Pragma (Msg : String);
3086 pragma No_Return (Error_Pragma);
3087 -- Outputs error message for current pragma. The message contains a %
3088 -- that will be replaced with the pragma name, and the flag is placed
3089 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
3090 -- calls Fix_Error (see spec of that procedure for details).
3092 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
3093 pragma No_Return (Error_Pragma_Arg);
3094 -- Outputs error message for current pragma. The message may contain
3095 -- a % that will be replaced with the pragma name. The parameter Arg
3096 -- may either be a pragma argument association, in which case the flag
3097 -- is placed on the expression of this association, or an expression,
3098 -- in which case the flag is placed directly on the expression. The
3099 -- message is placed using Error_Msg_N, so the message may also contain
3100 -- an & insertion character which will reference the given Arg value.
3101 -- After placing the message, Pragma_Exit is raised. Note: this routine
3102 -- calls Fix_Error (see spec of that procedure for details).
3104 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
3105 pragma No_Return (Error_Pragma_Arg);
3106 -- Similar to above form of Error_Pragma_Arg except that two messages
3107 -- are provided, the second is a continuation comment starting with \.
3109 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
3110 pragma No_Return (Error_Pragma_Arg_Ident);
3111 -- Outputs error message for current pragma. The message may contain a %
3112 -- that will be replaced with the pragma name. The parameter Arg must be
3113 -- a pragma argument association with a non-empty identifier (i.e. its
3114 -- Chars field must be set), and the error message is placed on the
3115 -- identifier. The message is placed using Error_Msg_N so the message
3116 -- may also contain an & insertion character which will reference
3117 -- the identifier. After placing the message, Pragma_Exit is raised.
3118 -- Note: this routine calls Fix_Error (see spec of that procedure for
3119 -- details).
3121 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
3122 pragma No_Return (Error_Pragma_Ref);
3123 -- Outputs error message for current pragma. The message may contain
3124 -- a % that will be replaced with the pragma name. The parameter Ref
3125 -- must be an entity whose name can be referenced by & and sloc by #.
3126 -- After placing the message, Pragma_Exit is raised. Note: this routine
3127 -- calls Fix_Error (see spec of that procedure for details).
3129 function Find_Lib_Unit_Name return Entity_Id;
3130 -- Used for a library unit pragma to find the entity to which the
3131 -- library unit pragma applies, returns the entity found.
3133 procedure Find_Program_Unit_Name (Id : Node_Id);
3134 -- If the pragma is a compilation unit pragma, the id must denote the
3135 -- compilation unit in the same compilation, and the pragma must appear
3136 -- in the list of preceding or trailing pragmas. If it is a program
3137 -- unit pragma that is not a compilation unit pragma, then the
3138 -- identifier must be visible.
3140 function Find_Unique_Parameterless_Procedure
3141 (Name : Entity_Id;
3142 Arg : Node_Id) return Entity_Id;
3143 -- Used for a procedure pragma to find the unique parameterless
3144 -- procedure identified by Name, returns it if it exists, otherwise
3145 -- errors out and uses Arg as the pragma argument for the message.
3147 function Fix_Error (Msg : String) return String;
3148 -- This is called prior to issuing an error message. Msg is the normal
3149 -- error message issued in the pragma case. This routine checks for the
3150 -- case of a pragma coming from an aspect in the source, and returns a
3151 -- message suitable for the aspect case as follows:
3153 -- Each substring "pragma" is replaced by "aspect"
3155 -- If "argument of" is at the start of the error message text, it is
3156 -- replaced by "entity for".
3158 -- If "argument" is at the start of the error message text, it is
3159 -- replaced by "entity".
3161 -- So for example, "argument of pragma X must be discrete type"
3162 -- returns "entity for aspect X must be a discrete type".
3164 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
3165 -- be different from the pragma name). If the current pragma results
3166 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
3167 -- original pragma name.
3169 procedure Gather_Associations
3170 (Names : Name_List;
3171 Args : out Args_List);
3172 -- This procedure is used to gather the arguments for a pragma that
3173 -- permits arbitrary ordering of parameters using the normal rules
3174 -- for named and positional parameters. The Names argument is a list
3175 -- of Name_Id values that corresponds to the allowed pragma argument
3176 -- association identifiers in order. The result returned in Args is
3177 -- a list of corresponding expressions that are the pragma arguments.
3178 -- Note that this is a list of expressions, not of pragma argument
3179 -- associations (Gather_Associations has completely checked all the
3180 -- optional identifiers when it returns). An entry in Args is Empty
3181 -- on return if the corresponding argument is not present.
3183 procedure GNAT_Pragma;
3184 -- Called for all GNAT defined pragmas to check the relevant restriction
3185 -- (No_Implementation_Pragmas).
3187 function Is_Before_First_Decl
3188 (Pragma_Node : Node_Id;
3189 Decls : List_Id) return Boolean;
3190 -- Return True if Pragma_Node is before the first declarative item in
3191 -- Decls where Decls is the list of declarative items.
3193 function Is_Configuration_Pragma return Boolean;
3194 -- Determines if the placement of the current pragma is appropriate
3195 -- for a configuration pragma.
3197 function Is_In_Context_Clause return Boolean;
3198 -- Returns True if pragma appears within the context clause of a unit,
3199 -- and False for any other placement (does not generate any messages).
3201 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
3202 -- Analyzes the argument, and determines if it is a static string
3203 -- expression, returns True if so, False if non-static or not String.
3204 -- A special case is that a string literal returns True in Ada 83 mode
3205 -- (which has no such thing as static string expressions).
3207 procedure Pragma_Misplaced;
3208 pragma No_Return (Pragma_Misplaced);
3209 -- Issue fatal error message for misplaced pragma
3211 procedure Process_Atomic_Shared_Volatile;
3212 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
3213 -- Shared is an obsolete Ada 83 pragma, treated as being identical
3214 -- in effect to pragma Atomic.
3216 procedure Process_Compile_Time_Warning_Or_Error;
3217 -- Common processing for Compile_Time_Error and Compile_Time_Warning
3219 procedure Process_Convention
3220 (C : out Convention_Id;
3221 Ent : out Entity_Id);
3222 -- Common processing for Convention, Interface, Import and Export.
3223 -- Checks first two arguments of pragma, and sets the appropriate
3224 -- convention value in the specified entity or entities. On return
3225 -- C is the convention, Ent is the referenced entity.
3227 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
3228 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
3229 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
3231 procedure Process_Extended_Import_Export_Object_Pragma
3232 (Arg_Internal : Node_Id;
3233 Arg_External : Node_Id;
3234 Arg_Size : Node_Id);
3235 -- Common processing for the pragmas Import/Export_Object. The three
3236 -- arguments correspond to the three named parameters of the pragmas. An
3237 -- argument is empty if the corresponding parameter is not present in
3238 -- the pragma.
3240 procedure Process_Extended_Import_Export_Internal_Arg
3241 (Arg_Internal : Node_Id := Empty);
3242 -- Common processing for all extended Import and Export pragmas. The
3243 -- argument is the pragma parameter for the Internal argument. If
3244 -- Arg_Internal is empty or inappropriate, an error message is posted.
3245 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
3246 -- set to identify the referenced entity.
3248 procedure Process_Extended_Import_Export_Subprogram_Pragma
3249 (Arg_Internal : Node_Id;
3250 Arg_External : Node_Id;
3251 Arg_Parameter_Types : Node_Id;
3252 Arg_Result_Type : Node_Id := Empty;
3253 Arg_Mechanism : Node_Id;
3254 Arg_Result_Mechanism : Node_Id := Empty);
3255 -- Common processing for all extended Import and Export pragmas applying
3256 -- to subprograms. The caller omits any arguments that do not apply to
3257 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
3258 -- only in the Import_Function and Export_Function cases). The argument
3259 -- names correspond to the allowed pragma association identifiers.
3261 procedure Process_Generic_List;
3262 -- Common processing for Share_Generic and Inline_Generic
3264 procedure Process_Import_Or_Interface;
3265 -- Common processing for Import of Interface
3267 procedure Process_Import_Predefined_Type;
3268 -- Processing for completing a type with pragma Import. This is used
3269 -- to declare types that match predefined C types, especially for cases
3270 -- without corresponding Ada predefined type.
3272 type Inline_Status is (Suppressed, Disabled, Enabled);
3273 -- Inline status of a subprogram, indicated as follows:
3274 -- Suppressed: inlining is suppressed for the subprogram
3275 -- Disabled: no inlining is requested for the subprogram
3276 -- Enabled: inlining is requested/required for the subprogram
3278 procedure Process_Inline (Status : Inline_Status);
3279 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
3280 -- indicates the inline status specified by the pragma.
3282 procedure Process_Interface_Name
3283 (Subprogram_Def : Entity_Id;
3284 Ext_Arg : Node_Id;
3285 Link_Arg : Node_Id);
3286 -- Given the last two arguments of pragma Import, pragma Export, or
3287 -- pragma Interface_Name, performs validity checks and sets the
3288 -- Interface_Name field of the given subprogram entity to the
3289 -- appropriate external or link name, depending on the arguments given.
3290 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
3291 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
3292 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
3293 -- nor Link_Arg is present, the interface name is set to the default
3294 -- from the subprogram name.
3296 procedure Process_Interrupt_Or_Attach_Handler;
3297 -- Common processing for Interrupt and Attach_Handler pragmas
3299 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
3300 -- Common processing for Restrictions and Restriction_Warnings pragmas.
3301 -- Warn is True for Restriction_Warnings, or for Restrictions if the
3302 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
3303 -- is not set in the Restrictions case.
3305 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
3306 -- Common processing for Suppress and Unsuppress. The boolean parameter
3307 -- Suppress_Case is True for the Suppress case, and False for the
3308 -- Unsuppress case.
3310 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
3311 -- This procedure sets the Is_Exported flag for the given entity,
3312 -- checking that the entity was not previously imported. Arg is
3313 -- the argument that specified the entity. A check is also made
3314 -- for exporting inappropriate entities.
3316 procedure Set_Extended_Import_Export_External_Name
3317 (Internal_Ent : Entity_Id;
3318 Arg_External : Node_Id);
3319 -- Common processing for all extended import export pragmas. The first
3320 -- argument, Internal_Ent, is the internal entity, which has already
3321 -- been checked for validity by the caller. Arg_External is from the
3322 -- Import or Export pragma, and may be null if no External parameter
3323 -- was present. If Arg_External is present and is a non-null string
3324 -- (a null string is treated as the default), then the Interface_Name
3325 -- field of Internal_Ent is set appropriately.
3327 procedure Set_Imported (E : Entity_Id);
3328 -- This procedure sets the Is_Imported flag for the given entity,
3329 -- checking that it is not previously exported or imported.
3331 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
3332 -- Mech is a parameter passing mechanism (see Import_Function syntax
3333 -- for MECHANISM_NAME). This routine checks that the mechanism argument
3334 -- has the right form, and if not issues an error message. If the
3335 -- argument has the right form then the Mechanism field of Ent is
3336 -- set appropriately.
3338 procedure Set_Rational_Profile;
3339 -- Activate the set of configuration pragmas and permissions that make
3340 -- up the Rational profile.
3342 procedure Set_Ravenscar_Profile (N : Node_Id);
3343 -- Activate the set of configuration pragmas and restrictions that make
3344 -- up the Ravenscar Profile. N is the corresponding pragma node, which
3345 -- is used for error messages on any constructs violating the profile.
3347 ----------------------------------
3348 -- Acquire_Warning_Match_String --
3349 ----------------------------------
3351 procedure Acquire_Warning_Match_String (Arg : Node_Id) is
3352 begin
3353 String_To_Name_Buffer
3354 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
3356 -- Add asterisk at start if not already there
3358 if Name_Len > 0 and then Name_Buffer (1) /= '*' then
3359 Name_Buffer (2 .. Name_Len + 1) :=
3360 Name_Buffer (1 .. Name_Len);
3361 Name_Buffer (1) := '*';
3362 Name_Len := Name_Len + 1;
3363 end if;
3365 -- Add asterisk at end if not already there
3367 if Name_Buffer (Name_Len) /= '*' then
3368 Name_Len := Name_Len + 1;
3369 Name_Buffer (Name_Len) := '*';
3370 end if;
3371 end Acquire_Warning_Match_String;
3373 ---------------------
3374 -- Ada_2005_Pragma --
3375 ---------------------
3377 procedure Ada_2005_Pragma is
3378 begin
3379 if Ada_Version <= Ada_95 then
3380 Check_Restriction (No_Implementation_Pragmas, N);
3381 end if;
3382 end Ada_2005_Pragma;
3384 ---------------------
3385 -- Ada_2012_Pragma --
3386 ---------------------
3388 procedure Ada_2012_Pragma is
3389 begin
3390 if Ada_Version <= Ada_2005 then
3391 Check_Restriction (No_Implementation_Pragmas, N);
3392 end if;
3393 end Ada_2012_Pragma;
3395 ---------------------
3396 -- Analyze_Part_Of --
3397 ---------------------
3399 procedure Analyze_Part_Of
3400 (Item_Id : Entity_Id;
3401 State : Node_Id;
3402 Indic : Node_Id;
3403 Legal : out Boolean)
3405 Pack_Id : Entity_Id;
3406 Placement : State_Space_Kind;
3407 Parent_Unit : Entity_Id;
3408 State_Id : Entity_Id;
3410 begin
3411 -- Assume that the pragma/option is illegal
3413 Legal := False;
3415 if Nkind_In (State, N_Expanded_Name,
3416 N_Identifier,
3417 N_Selected_Component)
3418 then
3419 Analyze (State);
3420 Resolve_State (State);
3422 if Is_Entity_Name (State)
3423 and then Ekind (Entity (State)) = E_Abstract_State
3424 then
3425 State_Id := Entity (State);
3427 else
3428 SPARK_Msg_N
3429 ("indicator Part_Of must denote an abstract state", State);
3430 return;
3431 end if;
3433 -- This is a syntax error, always report
3435 else
3436 Error_Msg_N
3437 ("indicator Part_Of must denote an abstract state", State);
3438 return;
3439 end if;
3441 -- Determine where the state, variable or the package instantiation
3442 -- lives with respect to the enclosing packages or package bodies (if
3443 -- any). This placement dictates the legality of the encapsulating
3444 -- state.
3446 Find_Placement_In_State_Space
3447 (Item_Id => Item_Id,
3448 Placement => Placement,
3449 Pack_Id => Pack_Id);
3451 -- The item appears in a non-package construct with a declarative
3452 -- part (subprogram, block, etc). As such, the item is not allowed
3453 -- to be a part of an encapsulating state because the item is not
3454 -- visible.
3456 if Placement = Not_In_Package then
3457 SPARK_Msg_N
3458 ("indicator Part_Of cannot appear in this context "
3459 & "(SPARK RM 7.2.6(5))", Indic);
3460 Error_Msg_Name_1 := Chars (Scope (State_Id));
3461 SPARK_Msg_NE
3462 ("\& is not part of the hidden state of package %",
3463 Indic, Item_Id);
3465 -- The item appears in the visible state space of some package. In
3466 -- general this scenario does not warrant Part_Of except when the
3467 -- package is a private child unit and the encapsulating state is
3468 -- declared in a parent unit or a public descendant of that parent
3469 -- unit.
3471 elsif Placement = Visible_State_Space then
3472 if Is_Child_Unit (Pack_Id)
3473 and then Is_Private_Descendant (Pack_Id)
3474 then
3475 -- A variable or state abstraction which is part of the
3476 -- visible state of a private child unit (or one of its public
3477 -- descendants) must have its Part_Of indicator specified. The
3478 -- Part_Of indicator must denote a state abstraction declared
3479 -- by either the parent unit of the private unit or by a public
3480 -- descendant of that parent unit.
3482 -- Find nearest private ancestor (which can be the current unit
3483 -- itself).
3485 Parent_Unit := Pack_Id;
3486 while Present (Parent_Unit) loop
3487 exit when Private_Present
3488 (Parent (Unit_Declaration_Node (Parent_Unit)));
3489 Parent_Unit := Scope (Parent_Unit);
3490 end loop;
3492 Parent_Unit := Scope (Parent_Unit);
3494 if not Is_Child_Or_Sibling (Pack_Id, Scope (State_Id)) then
3495 SPARK_Msg_NE
3496 ("indicator Part_Of must denote an abstract state of& "
3497 & "or public descendant (SPARK RM 7.2.6(3))",
3498 Indic, Parent_Unit);
3500 elsif Scope (State_Id) = Parent_Unit
3501 or else (Is_Ancestor_Package (Parent_Unit, Scope (State_Id))
3502 and then
3503 not Is_Private_Descendant (Scope (State_Id)))
3504 then
3505 null;
3507 else
3508 SPARK_Msg_NE
3509 ("indicator Part_Of must denote an abstract state of& "
3510 & "or public descendant (SPARK RM 7.2.6(3))",
3511 Indic, Parent_Unit);
3512 end if;
3514 -- Indicator Part_Of is not needed when the related package is not
3515 -- a private child unit or a public descendant thereof.
3517 else
3518 SPARK_Msg_N
3519 ("indicator Part_Of cannot appear in this context "
3520 & "(SPARK RM 7.2.6(5))", Indic);
3521 Error_Msg_Name_1 := Chars (Pack_Id);
3522 SPARK_Msg_NE
3523 ("\& is declared in the visible part of package %",
3524 Indic, Item_Id);
3525 end if;
3527 -- When the item appears in the private state space of a package, the
3528 -- encapsulating state must be declared in the same package.
3530 elsif Placement = Private_State_Space then
3531 if Scope (State_Id) /= Pack_Id then
3532 SPARK_Msg_NE
3533 ("indicator Part_Of must designate an abstract state of "
3534 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3535 Error_Msg_Name_1 := Chars (Pack_Id);
3536 SPARK_Msg_NE
3537 ("\& is declared in the private part of package %",
3538 Indic, Item_Id);
3539 end if;
3541 -- Items declared in the body state space of a package do not need
3542 -- Part_Of indicators as the refinement has already been seen.
3544 else
3545 SPARK_Msg_N
3546 ("indicator Part_Of cannot appear in this context "
3547 & "(SPARK RM 7.2.6(5))", Indic);
3549 if Scope (State_Id) = Pack_Id then
3550 Error_Msg_Name_1 := Chars (Pack_Id);
3551 SPARK_Msg_NE
3552 ("\& is declared in the body of package %", Indic, Item_Id);
3553 end if;
3554 end if;
3556 Legal := True;
3557 end Analyze_Part_Of;
3559 ----------------------------
3560 -- Analyze_Refined_Pragma --
3561 ----------------------------
3563 procedure Analyze_Refined_Pragma
3564 (Spec_Id : out Entity_Id;
3565 Body_Id : out Entity_Id;
3566 Legal : out Boolean)
3568 Body_Decl : Node_Id;
3569 Spec_Decl : Node_Id;
3571 begin
3572 -- Assume that the pragma is illegal
3574 Spec_Id := Empty;
3575 Body_Id := Empty;
3576 Legal := False;
3578 GNAT_Pragma;
3579 Check_Arg_Count (1);
3580 Check_No_Identifiers;
3582 if Nam_In (Pname, Name_Refined_Depends,
3583 Name_Refined_Global,
3584 Name_Refined_State)
3585 then
3586 Ensure_Aggregate_Form (Arg1);
3587 end if;
3589 -- Verify the placement of the pragma and check for duplicates. The
3590 -- pragma must apply to a subprogram body [stub].
3592 Body_Decl := Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
3594 -- Extract the entities of the spec and body
3596 if Nkind (Body_Decl) = N_Subprogram_Body then
3597 Body_Id := Defining_Entity (Body_Decl);
3598 Spec_Id := Corresponding_Spec (Body_Decl);
3600 elsif Nkind (Body_Decl) = N_Subprogram_Body_Stub then
3601 Body_Id := Defining_Entity (Body_Decl);
3602 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
3604 else
3605 Pragma_Misplaced;
3606 return;
3607 end if;
3609 -- The pragma must apply to the second declaration of a subprogram.
3610 -- In other words, the body [stub] cannot acts as a spec.
3612 if No (Spec_Id) then
3613 Error_Pragma ("pragma % cannot apply to a stand alone body");
3614 return;
3616 -- Catch the case where the subprogram body is a subunit and acts as
3617 -- the third declaration of the subprogram.
3619 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
3620 Error_Pragma ("pragma % cannot apply to a subunit");
3621 return;
3622 end if;
3624 -- The pragma can only apply to the body [stub] of a subprogram
3625 -- declared in the visible part of a package. Retrieve the context of
3626 -- the subprogram declaration.
3628 Spec_Decl := Parent (Parent (Spec_Id));
3630 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
3631 Error_Pragma
3632 ("pragma % must apply to the body of a subprogram declared in a "
3633 & "package specification");
3634 return;
3635 end if;
3637 -- If we get here, then the pragma is legal
3639 Legal := True;
3640 end Analyze_Refined_Pragma;
3642 --------------------------
3643 -- Check_Ada_83_Warning --
3644 --------------------------
3646 procedure Check_Ada_83_Warning is
3647 begin
3648 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
3649 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
3650 end if;
3651 end Check_Ada_83_Warning;
3653 ---------------------
3654 -- Check_Arg_Count --
3655 ---------------------
3657 procedure Check_Arg_Count (Required : Nat) is
3658 begin
3659 if Arg_Count /= Required then
3660 Error_Pragma ("wrong number of arguments for pragma%");
3661 end if;
3662 end Check_Arg_Count;
3664 --------------------------------
3665 -- Check_Arg_Is_External_Name --
3666 --------------------------------
3668 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
3669 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3671 begin
3672 if Nkind (Argx) = N_Identifier then
3673 return;
3675 else
3676 Analyze_And_Resolve (Argx, Standard_String);
3678 if Is_OK_Static_Expression (Argx) then
3679 return;
3681 elsif Etype (Argx) = Any_Type then
3682 raise Pragma_Exit;
3684 -- An interesting special case, if we have a string literal and
3685 -- we are in Ada 83 mode, then we allow it even though it will
3686 -- not be flagged as static. This allows expected Ada 83 mode
3687 -- use of external names which are string literals, even though
3688 -- technically these are not static in Ada 83.
3690 elsif Ada_Version = Ada_83
3691 and then Nkind (Argx) = N_String_Literal
3692 then
3693 return;
3695 -- Static expression that raises Constraint_Error. This has
3696 -- already been flagged, so just exit from pragma processing.
3698 elsif Is_OK_Static_Expression (Argx) then
3699 raise Pragma_Exit;
3701 -- Here we have a real error (non-static expression)
3703 else
3704 Error_Msg_Name_1 := Pname;
3706 declare
3707 Msg : constant String :=
3708 "argument for pragma% must be a identifier or "
3709 & "static string expression!";
3710 begin
3711 Flag_Non_Static_Expr (Fix_Error (Msg), Argx);
3712 raise Pragma_Exit;
3713 end;
3714 end if;
3715 end if;
3716 end Check_Arg_Is_External_Name;
3718 -----------------------------
3719 -- Check_Arg_Is_Identifier --
3720 -----------------------------
3722 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
3723 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3724 begin
3725 if Nkind (Argx) /= N_Identifier then
3726 Error_Pragma_Arg
3727 ("argument for pragma% must be identifier", Argx);
3728 end if;
3729 end Check_Arg_Is_Identifier;
3731 ----------------------------------
3732 -- Check_Arg_Is_Integer_Literal --
3733 ----------------------------------
3735 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
3736 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3737 begin
3738 if Nkind (Argx) /= N_Integer_Literal then
3739 Error_Pragma_Arg
3740 ("argument for pragma% must be integer literal", Argx);
3741 end if;
3742 end Check_Arg_Is_Integer_Literal;
3744 -------------------------------------------
3745 -- Check_Arg_Is_Library_Level_Local_Name --
3746 -------------------------------------------
3748 -- LOCAL_NAME ::=
3749 -- DIRECT_NAME
3750 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3751 -- | library_unit_NAME
3753 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
3754 begin
3755 Check_Arg_Is_Local_Name (Arg);
3757 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
3758 and then Comes_From_Source (N)
3759 then
3760 Error_Pragma_Arg
3761 ("argument for pragma% must be library level entity", Arg);
3762 end if;
3763 end Check_Arg_Is_Library_Level_Local_Name;
3765 -----------------------------
3766 -- Check_Arg_Is_Local_Name --
3767 -----------------------------
3769 -- LOCAL_NAME ::=
3770 -- DIRECT_NAME
3771 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3772 -- | library_unit_NAME
3774 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
3775 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3777 begin
3778 Analyze (Argx);
3780 if Nkind (Argx) not in N_Direct_Name
3781 and then (Nkind (Argx) /= N_Attribute_Reference
3782 or else Present (Expressions (Argx))
3783 or else Nkind (Prefix (Argx)) /= N_Identifier)
3784 and then (not Is_Entity_Name (Argx)
3785 or else not Is_Compilation_Unit (Entity (Argx)))
3786 then
3787 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
3788 end if;
3790 -- No further check required if not an entity name
3792 if not Is_Entity_Name (Argx) then
3793 null;
3795 else
3796 declare
3797 OK : Boolean;
3798 Ent : constant Entity_Id := Entity (Argx);
3799 Scop : constant Entity_Id := Scope (Ent);
3801 begin
3802 -- Case of a pragma applied to a compilation unit: pragma must
3803 -- occur immediately after the program unit in the compilation.
3805 if Is_Compilation_Unit (Ent) then
3806 declare
3807 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
3809 begin
3810 -- Case of pragma placed immediately after spec
3812 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
3813 OK := True;
3815 -- Case of pragma placed immediately after body
3817 elsif Nkind (Decl) = N_Subprogram_Declaration
3818 and then Present (Corresponding_Body (Decl))
3819 then
3820 OK := Parent (N) =
3821 Aux_Decls_Node
3822 (Parent (Unit_Declaration_Node
3823 (Corresponding_Body (Decl))));
3825 -- All other cases are illegal
3827 else
3828 OK := False;
3829 end if;
3830 end;
3832 -- Special restricted placement rule from 10.2.1(11.8/2)
3834 elsif Is_Generic_Formal (Ent)
3835 and then Prag_Id = Pragma_Preelaborable_Initialization
3836 then
3837 OK := List_Containing (N) =
3838 Generic_Formal_Declarations
3839 (Unit_Declaration_Node (Scop));
3841 -- If this is an aspect applied to a subprogram body, the
3842 -- pragma is inserted in its declarative part.
3844 elsif From_Aspect_Specification (N)
3845 and then Ent = Current_Scope
3846 and then
3847 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
3848 then
3849 OK := True;
3851 -- If the aspect is a predicate (possibly others ???) and the
3852 -- context is a record type, this is a discriminant expression
3853 -- within a type declaration, that freezes the predicated
3854 -- subtype.
3856 elsif From_Aspect_Specification (N)
3857 and then Prag_Id = Pragma_Predicate
3858 and then Ekind (Current_Scope) = E_Record_Type
3859 and then Scop = Scope (Current_Scope)
3860 then
3861 OK := True;
3863 -- Default case, just check that the pragma occurs in the scope
3864 -- of the entity denoted by the name.
3866 else
3867 OK := Current_Scope = Scop;
3868 end if;
3870 if not OK then
3871 Error_Pragma_Arg
3872 ("pragma% argument must be in same declarative part", Arg);
3873 end if;
3874 end;
3875 end if;
3876 end Check_Arg_Is_Local_Name;
3878 ---------------------------------
3879 -- Check_Arg_Is_Locking_Policy --
3880 ---------------------------------
3882 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
3883 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3885 begin
3886 Check_Arg_Is_Identifier (Argx);
3888 if not Is_Locking_Policy_Name (Chars (Argx)) then
3889 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
3890 end if;
3891 end Check_Arg_Is_Locking_Policy;
3893 -----------------------------------------------
3894 -- Check_Arg_Is_Partition_Elaboration_Policy --
3895 -----------------------------------------------
3897 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
3898 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3900 begin
3901 Check_Arg_Is_Identifier (Argx);
3903 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
3904 Error_Pragma_Arg
3905 ("& is not a valid partition elaboration policy name", Argx);
3906 end if;
3907 end Check_Arg_Is_Partition_Elaboration_Policy;
3909 -------------------------
3910 -- Check_Arg_Is_One_Of --
3911 -------------------------
3913 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
3914 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3916 begin
3917 Check_Arg_Is_Identifier (Argx);
3919 if not Nam_In (Chars (Argx), N1, N2) then
3920 Error_Msg_Name_2 := N1;
3921 Error_Msg_Name_3 := N2;
3922 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
3923 end if;
3924 end Check_Arg_Is_One_Of;
3926 procedure Check_Arg_Is_One_Of
3927 (Arg : Node_Id;
3928 N1, N2, N3 : Name_Id)
3930 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3932 begin
3933 Check_Arg_Is_Identifier (Argx);
3935 if not Nam_In (Chars (Argx), N1, N2, N3) then
3936 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3937 end if;
3938 end Check_Arg_Is_One_Of;
3940 procedure Check_Arg_Is_One_Of
3941 (Arg : Node_Id;
3942 N1, N2, N3, N4 : Name_Id)
3944 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3946 begin
3947 Check_Arg_Is_Identifier (Argx);
3949 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
3950 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3951 end if;
3952 end Check_Arg_Is_One_Of;
3954 procedure Check_Arg_Is_One_Of
3955 (Arg : Node_Id;
3956 N1, N2, N3, N4, N5 : Name_Id)
3958 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3960 begin
3961 Check_Arg_Is_Identifier (Argx);
3963 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
3964 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3965 end if;
3966 end Check_Arg_Is_One_Of;
3968 ---------------------------------
3969 -- Check_Arg_Is_Queuing_Policy --
3970 ---------------------------------
3972 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
3973 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3975 begin
3976 Check_Arg_Is_Identifier (Argx);
3978 if not Is_Queuing_Policy_Name (Chars (Argx)) then
3979 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
3980 end if;
3981 end Check_Arg_Is_Queuing_Policy;
3983 ---------------------------------------
3984 -- Check_Arg_Is_OK_Static_Expression --
3985 ---------------------------------------
3987 procedure Check_Arg_Is_OK_Static_Expression
3988 (Arg : Node_Id;
3989 Typ : Entity_Id := Empty)
3991 begin
3992 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
3993 end Check_Arg_Is_OK_Static_Expression;
3995 ------------------------------------------
3996 -- Check_Arg_Is_Task_Dispatching_Policy --
3997 ------------------------------------------
3999 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
4000 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4002 begin
4003 Check_Arg_Is_Identifier (Argx);
4005 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
4006 Error_Pragma_Arg
4007 ("& is not an allowed task dispatching policy name", Argx);
4008 end if;
4009 end Check_Arg_Is_Task_Dispatching_Policy;
4011 ---------------------
4012 -- Check_Arg_Order --
4013 ---------------------
4015 procedure Check_Arg_Order (Names : Name_List) is
4016 Arg : Node_Id;
4018 Highest_So_Far : Natural := 0;
4019 -- Highest index in Names seen do far
4021 begin
4022 Arg := Arg1;
4023 for J in 1 .. Arg_Count loop
4024 if Chars (Arg) /= No_Name then
4025 for K in Names'Range loop
4026 if Chars (Arg) = Names (K) then
4027 if K < Highest_So_Far then
4028 Error_Msg_Name_1 := Pname;
4029 Error_Msg_N
4030 ("parameters out of order for pragma%", Arg);
4031 Error_Msg_Name_1 := Names (K);
4032 Error_Msg_Name_2 := Names (Highest_So_Far);
4033 Error_Msg_N ("\% must appear before %", Arg);
4034 raise Pragma_Exit;
4036 else
4037 Highest_So_Far := K;
4038 end if;
4039 end if;
4040 end loop;
4041 end if;
4043 Arg := Next (Arg);
4044 end loop;
4045 end Check_Arg_Order;
4047 --------------------------------
4048 -- Check_At_Least_N_Arguments --
4049 --------------------------------
4051 procedure Check_At_Least_N_Arguments (N : Nat) is
4052 begin
4053 if Arg_Count < N then
4054 Error_Pragma ("too few arguments for pragma%");
4055 end if;
4056 end Check_At_Least_N_Arguments;
4058 -------------------------------
4059 -- Check_At_Most_N_Arguments --
4060 -------------------------------
4062 procedure Check_At_Most_N_Arguments (N : Nat) is
4063 Arg : Node_Id;
4064 begin
4065 if Arg_Count > N then
4066 Arg := Arg1;
4067 for J in 1 .. N loop
4068 Next (Arg);
4069 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
4070 end loop;
4071 end if;
4072 end Check_At_Most_N_Arguments;
4074 ---------------------
4075 -- Check_Component --
4076 ---------------------
4078 procedure Check_Component
4079 (Comp : Node_Id;
4080 UU_Typ : Entity_Id;
4081 In_Variant_Part : Boolean := False)
4083 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
4084 Sindic : constant Node_Id :=
4085 Subtype_Indication (Component_Definition (Comp));
4086 Typ : constant Entity_Id := Etype (Comp_Id);
4088 begin
4089 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
4090 -- object constraint, then the component type shall be an Unchecked_
4091 -- Union.
4093 if Nkind (Sindic) = N_Subtype_Indication
4094 and then Has_Per_Object_Constraint (Comp_Id)
4095 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
4096 then
4097 Error_Msg_N
4098 ("component subtype subject to per-object constraint "
4099 & "must be an Unchecked_Union", Comp);
4101 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
4102 -- the body of a generic unit, or within the body of any of its
4103 -- descendant library units, no part of the type of a component
4104 -- declared in a variant_part of the unchecked union type shall be of
4105 -- a formal private type or formal private extension declared within
4106 -- the formal part of the generic unit.
4108 elsif Ada_Version >= Ada_2012
4109 and then In_Generic_Body (UU_Typ)
4110 and then In_Variant_Part
4111 and then Is_Private_Type (Typ)
4112 and then Is_Generic_Type (Typ)
4113 then
4114 Error_Msg_N
4115 ("component of unchecked union cannot be of generic type", Comp);
4117 elsif Needs_Finalization (Typ) then
4118 Error_Msg_N
4119 ("component of unchecked union cannot be controlled", Comp);
4121 elsif Has_Task (Typ) then
4122 Error_Msg_N
4123 ("component of unchecked union cannot have tasks", Comp);
4124 end if;
4125 end Check_Component;
4127 -----------------------------
4128 -- Check_Declaration_Order --
4129 -----------------------------
4131 procedure Check_Declaration_Order (First : Node_Id; Second : Node_Id) is
4132 procedure Check_Aspect_Specification_Order;
4133 -- Inspect the aspect specifications of the context to determine the
4134 -- proper order.
4136 --------------------------------------
4137 -- Check_Aspect_Specification_Order --
4138 --------------------------------------
4140 procedure Check_Aspect_Specification_Order is
4141 Asp_First : constant Node_Id := Corresponding_Aspect (First);
4142 Asp_Second : constant Node_Id := Corresponding_Aspect (Second);
4143 Asp : Node_Id;
4145 begin
4146 -- Both aspects must be part of the same aspect specification list
4148 pragma Assert
4149 (List_Containing (Asp_First) = List_Containing (Asp_Second));
4151 -- Try to reach Second starting from First in a left to right
4152 -- traversal of the aspect specifications.
4154 Asp := Next (Asp_First);
4155 while Present (Asp) loop
4157 -- The order is ok, First is followed by Second
4159 if Asp = Asp_Second then
4160 return;
4161 end if;
4163 Next (Asp);
4164 end loop;
4166 -- If we get here, then the aspects are out of order
4168 SPARK_Msg_N ("aspect % cannot come after aspect %", First);
4169 end Check_Aspect_Specification_Order;
4171 -- Local variables
4173 Stmt : Node_Id;
4175 -- Start of processing for Check_Declaration_Order
4177 begin
4178 -- Cannot check the order if one of the pragmas is missing
4180 if No (First) or else No (Second) then
4181 return;
4182 end if;
4184 -- Set up the error names in case the order is incorrect
4186 Error_Msg_Name_1 := Pragma_Name (First);
4187 Error_Msg_Name_2 := Pragma_Name (Second);
4189 if From_Aspect_Specification (First) then
4191 -- Both pragmas are actually aspects, check their declaration
4192 -- order in the associated aspect specification list. Otherwise
4193 -- First is an aspect and Second a source pragma.
4195 if From_Aspect_Specification (Second) then
4196 Check_Aspect_Specification_Order;
4197 end if;
4199 -- Abstract_States is a source pragma
4201 else
4202 if From_Aspect_Specification (Second) then
4203 SPARK_Msg_N ("pragma % cannot come after aspect %", First);
4205 -- Both pragmas are source constructs. Try to reach First from
4206 -- Second by traversing the declarations backwards.
4208 else
4209 Stmt := Prev (Second);
4210 while Present (Stmt) loop
4212 -- The order is ok, First is followed by Second
4214 if Stmt = First then
4215 return;
4216 end if;
4218 Prev (Stmt);
4219 end loop;
4221 -- If we get here, then the pragmas are out of order
4223 SPARK_Msg_N ("pragma % cannot come after pragma %", First);
4224 end if;
4225 end if;
4226 end Check_Declaration_Order;
4228 ----------------------------
4229 -- Check_Duplicate_Pragma --
4230 ----------------------------
4232 procedure Check_Duplicate_Pragma (E : Entity_Id) is
4233 Id : Entity_Id := E;
4234 P : Node_Id;
4236 begin
4237 -- Nothing to do if this pragma comes from an aspect specification,
4238 -- since we could not be duplicating a pragma, and we dealt with the
4239 -- case of duplicated aspects in Analyze_Aspect_Specifications.
4241 if From_Aspect_Specification (N) then
4242 return;
4243 end if;
4245 -- Otherwise current pragma may duplicate previous pragma or a
4246 -- previously given aspect specification or attribute definition
4247 -- clause for the same pragma.
4249 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
4251 if Present (P) then
4253 -- If the entity is a type, then we have to make sure that the
4254 -- ostensible duplicate is not for a parent type from which this
4255 -- type is derived.
4257 if Is_Type (E) then
4258 if Nkind (P) = N_Pragma then
4259 declare
4260 Args : constant List_Id :=
4261 Pragma_Argument_Associations (P);
4262 begin
4263 if Present (Args)
4264 and then Is_Entity_Name (Expression (First (Args)))
4265 and then Is_Type (Entity (Expression (First (Args))))
4266 and then Entity (Expression (First (Args))) /= E
4267 then
4268 return;
4269 end if;
4270 end;
4272 elsif Nkind (P) = N_Aspect_Specification
4273 and then Is_Type (Entity (P))
4274 and then Entity (P) /= E
4275 then
4276 return;
4277 end if;
4278 end if;
4280 -- Here we have a definite duplicate
4282 Error_Msg_Name_1 := Pragma_Name (N);
4283 Error_Msg_Sloc := Sloc (P);
4285 -- For a single protected or a single task object, the error is
4286 -- issued on the original entity.
4288 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
4289 Id := Defining_Identifier (Original_Node (Parent (Id)));
4290 end if;
4292 if Nkind (P) = N_Aspect_Specification
4293 or else From_Aspect_Specification (P)
4294 then
4295 Error_Msg_NE ("aspect% for & previously given#", N, Id);
4296 else
4297 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
4298 end if;
4300 raise Pragma_Exit;
4301 end if;
4302 end Check_Duplicate_Pragma;
4304 ----------------------------------
4305 -- Check_Duplicated_Export_Name --
4306 ----------------------------------
4308 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
4309 String_Val : constant String_Id := Strval (Nam);
4311 begin
4312 -- We are only interested in the export case, and in the case of
4313 -- generics, it is the instance, not the template, that is the
4314 -- problem (the template will generate a warning in any case).
4316 if not Inside_A_Generic
4317 and then (Prag_Id = Pragma_Export
4318 or else
4319 Prag_Id = Pragma_Export_Procedure
4320 or else
4321 Prag_Id = Pragma_Export_Valued_Procedure
4322 or else
4323 Prag_Id = Pragma_Export_Function)
4324 then
4325 for J in Externals.First .. Externals.Last loop
4326 if String_Equal (String_Val, Strval (Externals.Table (J))) then
4327 Error_Msg_Sloc := Sloc (Externals.Table (J));
4328 Error_Msg_N ("external name duplicates name given#", Nam);
4329 exit;
4330 end if;
4331 end loop;
4333 Externals.Append (Nam);
4334 end if;
4335 end Check_Duplicated_Export_Name;
4337 ----------------------------------------
4338 -- Check_Expr_Is_OK_Static_Expression --
4339 ----------------------------------------
4341 procedure Check_Expr_Is_OK_Static_Expression
4342 (Expr : Node_Id;
4343 Typ : Entity_Id := Empty)
4345 begin
4346 if Present (Typ) then
4347 Analyze_And_Resolve (Expr, Typ);
4348 else
4349 Analyze_And_Resolve (Expr);
4350 end if;
4352 if Is_OK_Static_Expression (Expr) then
4353 return;
4355 elsif Etype (Expr) = Any_Type then
4356 raise Pragma_Exit;
4358 -- An interesting special case, if we have a string literal and we
4359 -- are in Ada 83 mode, then we allow it even though it will not be
4360 -- flagged as static. This allows the use of Ada 95 pragmas like
4361 -- Import in Ada 83 mode. They will of course be flagged with
4362 -- warnings as usual, but will not cause errors.
4364 elsif Ada_Version = Ada_83
4365 and then Nkind (Expr) = N_String_Literal
4366 then
4367 return;
4369 -- Static expression that raises Constraint_Error. This has already
4370 -- been flagged, so just exit from pragma processing.
4372 elsif Is_OK_Static_Expression (Expr) then
4373 raise Pragma_Exit;
4375 -- Finally, we have a real error
4377 else
4378 Error_Msg_Name_1 := Pname;
4379 Flag_Non_Static_Expr
4380 (Fix_Error ("argument for pragma% must be a static expression!"),
4381 Expr);
4382 raise Pragma_Exit;
4383 end if;
4384 end Check_Expr_Is_OK_Static_Expression;
4386 -------------------------
4387 -- Check_First_Subtype --
4388 -------------------------
4390 procedure Check_First_Subtype (Arg : Node_Id) is
4391 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4392 Ent : constant Entity_Id := Entity (Argx);
4394 begin
4395 if Is_First_Subtype (Ent) then
4396 null;
4398 elsif Is_Type (Ent) then
4399 Error_Pragma_Arg
4400 ("pragma% cannot apply to subtype", Argx);
4402 elsif Is_Object (Ent) then
4403 Error_Pragma_Arg
4404 ("pragma% cannot apply to object, requires a type", Argx);
4406 else
4407 Error_Pragma_Arg
4408 ("pragma% cannot apply to&, requires a type", Argx);
4409 end if;
4410 end Check_First_Subtype;
4412 ----------------------
4413 -- Check_Identifier --
4414 ----------------------
4416 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
4417 begin
4418 if Present (Arg)
4419 and then Nkind (Arg) = N_Pragma_Argument_Association
4420 then
4421 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
4422 Error_Msg_Name_1 := Pname;
4423 Error_Msg_Name_2 := Id;
4424 Error_Msg_N ("pragma% argument expects identifier%", Arg);
4425 raise Pragma_Exit;
4426 end if;
4427 end if;
4428 end Check_Identifier;
4430 --------------------------------
4431 -- Check_Identifier_Is_One_Of --
4432 --------------------------------
4434 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
4435 begin
4436 if Present (Arg)
4437 and then Nkind (Arg) = N_Pragma_Argument_Association
4438 then
4439 if Chars (Arg) = No_Name then
4440 Error_Msg_Name_1 := Pname;
4441 Error_Msg_N ("pragma% argument expects an identifier", Arg);
4442 raise Pragma_Exit;
4444 elsif Chars (Arg) /= N1
4445 and then Chars (Arg) /= N2
4446 then
4447 Error_Msg_Name_1 := Pname;
4448 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
4449 raise Pragma_Exit;
4450 end if;
4451 end if;
4452 end Check_Identifier_Is_One_Of;
4454 ---------------------------
4455 -- Check_In_Main_Program --
4456 ---------------------------
4458 procedure Check_In_Main_Program is
4459 P : constant Node_Id := Parent (N);
4461 begin
4462 -- Must be at in subprogram body
4464 if Nkind (P) /= N_Subprogram_Body then
4465 Error_Pragma ("% pragma allowed only in subprogram");
4467 -- Otherwise warn if obviously not main program
4469 elsif Present (Parameter_Specifications (Specification (P)))
4470 or else not Is_Compilation_Unit (Defining_Entity (P))
4471 then
4472 Error_Msg_Name_1 := Pname;
4473 Error_Msg_N
4474 ("??pragma% is only effective in main program", N);
4475 end if;
4476 end Check_In_Main_Program;
4478 ---------------------------------------
4479 -- Check_Interrupt_Or_Attach_Handler --
4480 ---------------------------------------
4482 procedure Check_Interrupt_Or_Attach_Handler is
4483 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4484 Handler_Proc, Proc_Scope : Entity_Id;
4486 begin
4487 Analyze (Arg1_X);
4489 if Prag_Id = Pragma_Interrupt_Handler then
4490 Check_Restriction (No_Dynamic_Attachment, N);
4491 end if;
4493 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
4494 Proc_Scope := Scope (Handler_Proc);
4496 -- On AAMP only, a pragma Interrupt_Handler is supported for
4497 -- nonprotected parameterless procedures.
4499 if not AAMP_On_Target
4500 or else Prag_Id = Pragma_Attach_Handler
4501 then
4502 if Ekind (Proc_Scope) /= E_Protected_Type then
4503 Error_Pragma_Arg
4504 ("argument of pragma% must be protected procedure", Arg1);
4505 end if;
4507 -- For pragma case (as opposed to access case), check placement.
4508 -- We don't need to do that for aspects, because we have the
4509 -- check that they aspect applies an appropriate procedure.
4511 if not From_Aspect_Specification (N)
4512 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
4513 then
4514 Error_Pragma ("pragma% must be in protected definition");
4515 end if;
4516 end if;
4518 if not Is_Library_Level_Entity (Proc_Scope)
4519 or else (AAMP_On_Target
4520 and then not Is_Library_Level_Entity (Handler_Proc))
4521 then
4522 Error_Pragma_Arg
4523 ("argument for pragma% must be library level entity", Arg1);
4524 end if;
4526 -- AI05-0033: A pragma cannot appear within a generic body, because
4527 -- instance can be in a nested scope. The check that protected type
4528 -- is itself a library-level declaration is done elsewhere.
4530 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
4531 -- handle code prior to AI-0033. Analysis tools typically are not
4532 -- interested in this pragma in any case, so no need to worry too
4533 -- much about its placement.
4535 if Inside_A_Generic then
4536 if Ekind (Scope (Current_Scope)) = E_Generic_Package
4537 and then In_Package_Body (Scope (Current_Scope))
4538 and then not Relaxed_RM_Semantics
4539 then
4540 Error_Pragma ("pragma% cannot be used inside a generic");
4541 end if;
4542 end if;
4543 end Check_Interrupt_Or_Attach_Handler;
4545 ---------------------------------
4546 -- Check_Loop_Pragma_Placement --
4547 ---------------------------------
4549 procedure Check_Loop_Pragma_Placement is
4550 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
4551 -- Verify whether the current pragma is properly grouped with other
4552 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
4553 -- related loop where the pragma appears.
4555 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
4556 -- Determine whether an arbitrary statement Stmt denotes pragma
4557 -- Loop_Invariant or Loop_Variant.
4559 procedure Placement_Error (Constr : Node_Id);
4560 pragma No_Return (Placement_Error);
4561 -- Node Constr denotes the last loop restricted construct before we
4562 -- encountered an illegal relation between enclosing constructs. Emit
4563 -- an error depending on what Constr was.
4565 --------------------------------
4566 -- Check_Loop_Pragma_Grouping --
4567 --------------------------------
4569 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
4570 Stop_Search : exception;
4571 -- This exception is used to terminate the recursive descent of
4572 -- routine Check_Grouping.
4574 procedure Check_Grouping (L : List_Id);
4575 -- Find the first group of pragmas in list L and if successful,
4576 -- ensure that the current pragma is part of that group. The
4577 -- routine raises Stop_Search once such a check is performed to
4578 -- halt the recursive descent.
4580 procedure Grouping_Error (Prag : Node_Id);
4581 pragma No_Return (Grouping_Error);
4582 -- Emit an error concerning the current pragma indicating that it
4583 -- should be placed after pragma Prag.
4585 --------------------
4586 -- Check_Grouping --
4587 --------------------
4589 procedure Check_Grouping (L : List_Id) is
4590 HSS : Node_Id;
4591 Prag : Node_Id;
4592 Stmt : Node_Id;
4594 begin
4595 -- Inspect the list of declarations or statements looking for
4596 -- the first grouping of pragmas:
4598 -- loop
4599 -- pragma Loop_Invariant ...;
4600 -- pragma Loop_Variant ...;
4601 -- . . . -- (1)
4602 -- pragma Loop_Variant ...; -- current pragma
4604 -- If the current pragma is not in the grouping, then it must
4605 -- either appear in a different declarative or statement list
4606 -- or the construct at (1) is separating the pragma from the
4607 -- grouping.
4609 Stmt := First (L);
4610 while Present (Stmt) loop
4612 -- Pragmas Loop_Invariant and Loop_Variant may only appear
4613 -- inside a loop or a block housed inside a loop. Inspect
4614 -- the declarations and statements of the block as they may
4615 -- contain the first grouping.
4617 if Nkind (Stmt) = N_Block_Statement then
4618 HSS := Handled_Statement_Sequence (Stmt);
4620 Check_Grouping (Declarations (Stmt));
4622 if Present (HSS) then
4623 Check_Grouping (Statements (HSS));
4624 end if;
4626 -- First pragma of the first topmost grouping has been found
4628 elsif Is_Loop_Pragma (Stmt) then
4630 -- The group and the current pragma are not in the same
4631 -- declarative or statement list.
4633 if List_Containing (Stmt) /= List_Containing (N) then
4634 Grouping_Error (Stmt);
4636 -- Try to reach the current pragma from the first pragma
4637 -- of the grouping while skipping other members:
4639 -- pragma Loop_Invariant ...; -- first pragma
4640 -- pragma Loop_Variant ...; -- member
4641 -- . . .
4642 -- pragma Loop_Variant ...; -- current pragma
4644 else
4645 while Present (Stmt) loop
4647 -- The current pragma is either the first pragma
4648 -- of the group or is a member of the group. Stop
4649 -- the search as the placement is legal.
4651 if Stmt = N then
4652 raise Stop_Search;
4654 -- Skip group members, but keep track of the last
4655 -- pragma in the group.
4657 elsif Is_Loop_Pragma (Stmt) then
4658 Prag := Stmt;
4660 -- A non-pragma is separating the group from the
4661 -- current pragma, the placement is illegal.
4663 else
4664 Grouping_Error (Prag);
4665 end if;
4667 Next (Stmt);
4668 end loop;
4670 -- If the traversal did not reach the current pragma,
4671 -- then the list must be malformed.
4673 raise Program_Error;
4674 end if;
4675 end if;
4677 Next (Stmt);
4678 end loop;
4679 end Check_Grouping;
4681 --------------------
4682 -- Grouping_Error --
4683 --------------------
4685 procedure Grouping_Error (Prag : Node_Id) is
4686 begin
4687 Error_Msg_Sloc := Sloc (Prag);
4688 Error_Pragma ("pragma% must appear next to pragma#");
4689 end Grouping_Error;
4691 -- Start of processing for Check_Loop_Pragma_Grouping
4693 begin
4694 -- Inspect the statements of the loop or nested blocks housed
4695 -- within to determine whether the current pragma is part of the
4696 -- first topmost grouping of Loop_Invariant and Loop_Variant.
4698 Check_Grouping (Statements (Loop_Stmt));
4700 exception
4701 when Stop_Search => null;
4702 end Check_Loop_Pragma_Grouping;
4704 --------------------
4705 -- Is_Loop_Pragma --
4706 --------------------
4708 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
4709 begin
4710 -- Inspect the original node as Loop_Invariant and Loop_Variant
4711 -- pragmas are rewritten to null when assertions are disabled.
4713 if Nkind (Original_Node (Stmt)) = N_Pragma then
4714 return
4715 Nam_In (Pragma_Name (Original_Node (Stmt)),
4716 Name_Loop_Invariant,
4717 Name_Loop_Variant);
4718 else
4719 return False;
4720 end if;
4721 end Is_Loop_Pragma;
4723 ---------------------
4724 -- Placement_Error --
4725 ---------------------
4727 procedure Placement_Error (Constr : Node_Id) is
4728 LA : constant String := " with Loop_Entry";
4730 begin
4731 if Prag_Id = Pragma_Assert then
4732 Error_Msg_String (1 .. LA'Length) := LA;
4733 Error_Msg_Strlen := LA'Length;
4734 else
4735 Error_Msg_Strlen := 0;
4736 end if;
4738 if Nkind (Constr) = N_Pragma then
4739 Error_Pragma
4740 ("pragma %~ must appear immediately within the statements "
4741 & "of a loop");
4742 else
4743 Error_Pragma_Arg
4744 ("block containing pragma %~ must appear immediately within "
4745 & "the statements of a loop", Constr);
4746 end if;
4747 end Placement_Error;
4749 -- Local declarations
4751 Prev : Node_Id;
4752 Stmt : Node_Id;
4754 -- Start of processing for Check_Loop_Pragma_Placement
4756 begin
4757 -- Check that pragma appears immediately within a loop statement,
4758 -- ignoring intervening block statements.
4760 Prev := N;
4761 Stmt := Parent (N);
4762 while Present (Stmt) loop
4764 -- The pragma or previous block must appear immediately within the
4765 -- current block's declarative or statement part.
4767 if Nkind (Stmt) = N_Block_Statement then
4768 if (No (Declarations (Stmt))
4769 or else List_Containing (Prev) /= Declarations (Stmt))
4770 and then
4771 List_Containing (Prev) /=
4772 Statements (Handled_Statement_Sequence (Stmt))
4773 then
4774 Placement_Error (Prev);
4775 return;
4777 -- Keep inspecting the parents because we are now within a
4778 -- chain of nested blocks.
4780 else
4781 Prev := Stmt;
4782 Stmt := Parent (Stmt);
4783 end if;
4785 -- The pragma or previous block must appear immediately within the
4786 -- statements of the loop.
4788 elsif Nkind (Stmt) = N_Loop_Statement then
4789 if List_Containing (Prev) /= Statements (Stmt) then
4790 Placement_Error (Prev);
4791 end if;
4793 -- Stop the traversal because we reached the innermost loop
4794 -- regardless of whether we encountered an error or not.
4796 exit;
4798 -- Ignore a handled statement sequence. Note that this node may
4799 -- be related to a subprogram body in which case we will emit an
4800 -- error on the next iteration of the search.
4802 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
4803 Stmt := Parent (Stmt);
4805 -- Any other statement breaks the chain from the pragma to the
4806 -- loop.
4808 else
4809 Placement_Error (Prev);
4810 return;
4811 end if;
4812 end loop;
4814 -- Check that the current pragma Loop_Invariant or Loop_Variant is
4815 -- grouped together with other such pragmas.
4817 if Is_Loop_Pragma (N) then
4819 -- The previous check should have located the related loop
4821 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
4822 Check_Loop_Pragma_Grouping (Stmt);
4823 end if;
4824 end Check_Loop_Pragma_Placement;
4826 -------------------------------------------
4827 -- Check_Is_In_Decl_Part_Or_Package_Spec --
4828 -------------------------------------------
4830 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
4831 P : Node_Id;
4833 begin
4834 P := Parent (N);
4835 loop
4836 if No (P) then
4837 exit;
4839 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
4840 exit;
4842 elsif Nkind_In (P, N_Package_Specification,
4843 N_Block_Statement)
4844 then
4845 return;
4847 -- Note: the following tests seem a little peculiar, because
4848 -- they test for bodies, but if we were in the statement part
4849 -- of the body, we would already have hit the handled statement
4850 -- sequence, so the only way we get here is by being in the
4851 -- declarative part of the body.
4853 elsif Nkind_In (P, N_Subprogram_Body,
4854 N_Package_Body,
4855 N_Task_Body,
4856 N_Entry_Body)
4857 then
4858 return;
4859 end if;
4861 P := Parent (P);
4862 end loop;
4864 Error_Pragma ("pragma% is not in declarative part or package spec");
4865 end Check_Is_In_Decl_Part_Or_Package_Spec;
4867 -------------------------
4868 -- Check_No_Identifier --
4869 -------------------------
4871 procedure Check_No_Identifier (Arg : Node_Id) is
4872 begin
4873 if Nkind (Arg) = N_Pragma_Argument_Association
4874 and then Chars (Arg) /= No_Name
4875 then
4876 Error_Pragma_Arg_Ident
4877 ("pragma% does not permit identifier& here", Arg);
4878 end if;
4879 end Check_No_Identifier;
4881 --------------------------
4882 -- Check_No_Identifiers --
4883 --------------------------
4885 procedure Check_No_Identifiers is
4886 Arg_Node : Node_Id;
4887 begin
4888 Arg_Node := Arg1;
4889 for J in 1 .. Arg_Count loop
4890 Check_No_Identifier (Arg_Node);
4891 Next (Arg_Node);
4892 end loop;
4893 end Check_No_Identifiers;
4895 ------------------------
4896 -- Check_No_Link_Name --
4897 ------------------------
4899 procedure Check_No_Link_Name is
4900 begin
4901 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
4902 Arg4 := Arg3;
4903 end if;
4905 if Present (Arg4) then
4906 Error_Pragma_Arg
4907 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
4908 end if;
4909 end Check_No_Link_Name;
4911 -------------------------------
4912 -- Check_Optional_Identifier --
4913 -------------------------------
4915 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
4916 begin
4917 if Present (Arg)
4918 and then Nkind (Arg) = N_Pragma_Argument_Association
4919 and then Chars (Arg) /= No_Name
4920 then
4921 if Chars (Arg) /= Id then
4922 Error_Msg_Name_1 := Pname;
4923 Error_Msg_Name_2 := Id;
4924 Error_Msg_N ("pragma% argument expects identifier%", Arg);
4925 raise Pragma_Exit;
4926 end if;
4927 end if;
4928 end Check_Optional_Identifier;
4930 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
4931 begin
4932 Name_Buffer (1 .. Id'Length) := Id;
4933 Name_Len := Id'Length;
4934 Check_Optional_Identifier (Arg, Name_Find);
4935 end Check_Optional_Identifier;
4937 --------------------
4938 -- Check_Pre_Post --
4939 --------------------
4941 procedure Check_Pre_Post is
4942 P : Node_Id;
4943 PO : Node_Id;
4945 begin
4946 if not Is_List_Member (N) then
4947 Pragma_Misplaced;
4948 end if;
4950 -- If we are within an inlined body, the legality of the pragma
4951 -- has been checked already.
4953 if In_Inlined_Body then
4954 return;
4955 end if;
4957 -- Search prior declarations
4959 P := N;
4960 while Present (Prev (P)) loop
4961 P := Prev (P);
4963 -- If the previous node is a generic subprogram, do not go to to
4964 -- the original node, which is the unanalyzed tree: we need to
4965 -- attach the pre/postconditions to the analyzed version at this
4966 -- point. They get propagated to the original tree when analyzing
4967 -- the corresponding body.
4969 if Nkind (P) not in N_Generic_Declaration then
4970 PO := Original_Node (P);
4971 else
4972 PO := P;
4973 end if;
4975 -- Skip past prior pragma
4977 if Nkind (PO) = N_Pragma then
4978 null;
4980 -- Skip stuff not coming from source
4982 elsif not Comes_From_Source (PO) then
4984 -- The condition may apply to a subprogram instantiation
4986 if Nkind (PO) = N_Subprogram_Declaration
4987 and then Present (Generic_Parent (Specification (PO)))
4988 then
4989 return;
4991 elsif Nkind (PO) = N_Subprogram_Declaration
4992 and then In_Instance
4993 then
4994 return;
4996 -- For all other cases of non source code, do nothing
4998 else
4999 null;
5000 end if;
5002 -- Only remaining possibility is subprogram declaration
5004 else
5005 return;
5006 end if;
5007 end loop;
5009 -- If we fall through loop, pragma is at start of list, so see if it
5010 -- is at the start of declarations of a subprogram body.
5012 PO := Parent (N);
5014 if Nkind (PO) = N_Subprogram_Body
5015 and then List_Containing (N) = Declarations (PO)
5016 then
5017 -- This is only allowed if there is no separate specification
5019 if Present (Corresponding_Spec (PO)) then
5020 Error_Pragma
5021 ("pragma% must apply to subprogram specification");
5022 end if;
5024 return;
5025 end if;
5026 end Check_Pre_Post;
5028 --------------------------------------
5029 -- Check_Precondition_Postcondition --
5030 --------------------------------------
5032 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
5033 P : Node_Id;
5034 PO : Node_Id;
5036 procedure Chain_PPC (PO : Node_Id);
5037 -- If PO is an entry or a [generic] subprogram declaration node, then
5038 -- the precondition/postcondition applies to this subprogram and the
5039 -- processing for the pragma is completed. Otherwise the pragma is
5040 -- misplaced.
5042 ---------------
5043 -- Chain_PPC --
5044 ---------------
5046 procedure Chain_PPC (PO : Node_Id) is
5047 S : Entity_Id;
5049 begin
5050 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
5051 if not From_Aspect_Specification (N) then
5052 Error_Pragma
5053 ("pragma% cannot be applied to abstract subprogram");
5055 elsif Class_Present (N) then
5056 null;
5058 else
5059 Error_Pragma
5060 ("aspect % requires ''Class for abstract subprogram");
5061 end if;
5063 -- AI05-0230: The same restriction applies to null procedures. For
5064 -- compatibility with earlier uses of the Ada pragma, apply this
5065 -- rule only to aspect specifications.
5067 -- The above discrepency needs documentation. Robert is dubious
5068 -- about whether it is a good idea ???
5070 elsif Nkind (PO) = N_Subprogram_Declaration
5071 and then Nkind (Specification (PO)) = N_Procedure_Specification
5072 and then Null_Present (Specification (PO))
5073 and then From_Aspect_Specification (N)
5074 and then not Class_Present (N)
5075 then
5076 Error_Pragma
5077 ("aspect % requires ''Class for null procedure");
5079 -- Pre/postconditions are legal on a subprogram body if it is not
5080 -- a completion of a declaration. They are also legal on a stub
5081 -- with no previous declarations (this is checked when processing
5082 -- the corresponding aspects).
5084 elsif Nkind (PO) = N_Subprogram_Body
5085 and then Acts_As_Spec (PO)
5086 then
5087 null;
5089 elsif Nkind (PO) = N_Subprogram_Body_Stub then
5090 null;
5092 elsif not Nkind_In (PO, N_Subprogram_Declaration,
5093 N_Expression_Function,
5094 N_Generic_Subprogram_Declaration,
5095 N_Entry_Declaration)
5096 then
5097 Pragma_Misplaced;
5098 end if;
5100 -- Here if we have [generic] subprogram or entry declaration
5102 if Nkind (PO) = N_Entry_Declaration then
5103 S := Defining_Entity (PO);
5104 else
5105 S := Defining_Unit_Name (Specification (PO));
5107 if Nkind (S) = N_Defining_Program_Unit_Name then
5108 S := Defining_Identifier (S);
5109 end if;
5110 end if;
5112 -- Note: we do not analyze the pragma at this point. Instead we
5113 -- delay this analysis until the end of the declarative part in
5114 -- which the pragma appears. This implements the required delay
5115 -- in this analysis, allowing forward references. The analysis
5116 -- happens at the end of Analyze_Declarations.
5118 -- Chain spec PPC pragma to list for subprogram
5120 Add_Contract_Item (N, S);
5122 -- Return indicating spec case
5124 In_Body := False;
5125 return;
5126 end Chain_PPC;
5128 -- Start of processing for Check_Precondition_Postcondition
5130 begin
5131 if not Is_List_Member (N) then
5132 Pragma_Misplaced;
5133 end if;
5135 -- Preanalyze message argument if present. Visibility in this
5136 -- argument is established at the point of pragma occurrence.
5138 if Arg_Count = 2 then
5139 Check_Optional_Identifier (Arg2, Name_Message);
5140 Preanalyze_Spec_Expression
5141 (Get_Pragma_Arg (Arg2), Standard_String);
5142 end if;
5144 -- For a pragma PPC in the extended main source unit, record enabled
5145 -- status in SCO.
5147 if Is_Checked (N) and then not Split_PPC (N) then
5148 Set_SCO_Pragma_Enabled (Loc);
5149 end if;
5151 -- If we are within an inlined body, the legality of the pragma
5152 -- has been checked already.
5154 if In_Inlined_Body then
5155 In_Body := True;
5156 return;
5157 end if;
5159 -- Search prior declarations
5161 P := N;
5162 while Present (Prev (P)) loop
5163 P := Prev (P);
5165 -- If the previous node is a generic subprogram, do not go to to
5166 -- the original node, which is the unanalyzed tree: we need to
5167 -- attach the pre/postconditions to the analyzed version at this
5168 -- point. They get propagated to the original tree when analyzing
5169 -- the corresponding body.
5171 if Nkind (P) not in N_Generic_Declaration then
5172 PO := Original_Node (P);
5173 else
5174 PO := P;
5175 end if;
5177 -- Skip past prior pragma
5179 if Nkind (PO) = N_Pragma then
5180 null;
5182 -- Skip stuff not coming from source
5184 elsif not Comes_From_Source (PO) then
5186 -- The condition may apply to a subprogram instantiation
5188 if Nkind (PO) = N_Subprogram_Declaration
5189 and then Present (Generic_Parent (Specification (PO)))
5190 then
5191 Chain_PPC (PO);
5192 return;
5194 elsif Nkind (PO) = N_Subprogram_Declaration
5195 and then In_Instance
5196 then
5197 Chain_PPC (PO);
5198 return;
5200 -- For all other cases of non source code, do nothing
5202 else
5203 null;
5204 end if;
5206 -- Only remaining possibility is subprogram declaration
5208 else
5209 Chain_PPC (PO);
5210 return;
5211 end if;
5212 end loop;
5214 -- If we fall through loop, pragma is at start of list, so see if it
5215 -- is at the start of declarations of a subprogram body.
5217 PO := Parent (N);
5219 if Nkind (PO) = N_Subprogram_Body
5220 and then List_Containing (N) = Declarations (PO)
5221 then
5222 if Operating_Mode /= Generate_Code or else Inside_A_Generic then
5224 -- Analyze pragma expression for correctness and for ASIS use
5226 Preanalyze_Assert_Expression
5227 (Get_Pragma_Arg (Arg1), Standard_Boolean);
5229 -- In ASIS mode, for a pragma generated from a source aspect,
5230 -- also analyze the original aspect expression.
5232 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
5233 Preanalyze_Assert_Expression
5234 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
5235 end if;
5236 end if;
5238 -- Retain copy of the pre/postcondition pragma in GNATprove mode.
5239 -- The copy is needed because the pragma is expanded into other
5240 -- constructs which are not acceptable in the N_Contract node.
5242 if Acts_As_Spec (PO) and then GNATprove_Mode then
5243 declare
5244 Prag : constant Node_Id := New_Copy_Tree (N);
5246 begin
5247 -- Preanalyze the pragma
5249 Preanalyze_Assert_Expression
5250 (Get_Pragma_Arg
5251 (First (Pragma_Argument_Associations (Prag))),
5252 Standard_Boolean);
5254 -- Preanalyze the corresponding aspect (if any)
5256 if Present (Corresponding_Aspect (Prag)) then
5257 Preanalyze_Assert_Expression
5258 (Expression (Corresponding_Aspect (Prag)),
5259 Standard_Boolean);
5260 end if;
5262 -- Chain the copy on the contract of the body
5264 Add_Contract_Item
5265 (Prag, Defining_Unit_Name (Specification (PO)));
5266 end;
5267 end if;
5269 In_Body := True;
5270 return;
5272 -- See if it is in the pragmas after a library level subprogram
5274 elsif Nkind (PO) = N_Compilation_Unit_Aux then
5276 -- In GNATprove mode, analyze pragma expression for correctness,
5277 -- as it is not expanded later. Ditto in ASIS_Mode where there is
5278 -- no later point at which the aspect will be analyzed.
5280 if GNATprove_Mode or ASIS_Mode then
5281 Analyze_Pre_Post_Condition_In_Decl_Part
5282 (N, Defining_Entity (Unit (Parent (PO))));
5283 end if;
5285 Chain_PPC (Unit (Parent (PO)));
5286 return;
5287 end if;
5289 -- If we fall through, pragma was misplaced
5291 Pragma_Misplaced;
5292 end Check_Precondition_Postcondition;
5294 -----------------------------
5295 -- Check_Static_Constraint --
5296 -----------------------------
5298 -- Note: for convenience in writing this procedure, in addition to
5299 -- the officially (i.e. by spec) allowed argument which is always a
5300 -- constraint, it also allows ranges and discriminant associations.
5301 -- Above is not clear ???
5303 procedure Check_Static_Constraint (Constr : Node_Id) is
5305 procedure Require_Static (E : Node_Id);
5306 -- Require given expression to be static expression
5308 --------------------
5309 -- Require_Static --
5310 --------------------
5312 procedure Require_Static (E : Node_Id) is
5313 begin
5314 if not Is_OK_Static_Expression (E) then
5315 Flag_Non_Static_Expr
5316 ("non-static constraint not allowed in Unchecked_Union!", E);
5317 raise Pragma_Exit;
5318 end if;
5319 end Require_Static;
5321 -- Start of processing for Check_Static_Constraint
5323 begin
5324 case Nkind (Constr) is
5325 when N_Discriminant_Association =>
5326 Require_Static (Expression (Constr));
5328 when N_Range =>
5329 Require_Static (Low_Bound (Constr));
5330 Require_Static (High_Bound (Constr));
5332 when N_Attribute_Reference =>
5333 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
5334 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
5336 when N_Range_Constraint =>
5337 Check_Static_Constraint (Range_Expression (Constr));
5339 when N_Index_Or_Discriminant_Constraint =>
5340 declare
5341 IDC : Entity_Id;
5342 begin
5343 IDC := First (Constraints (Constr));
5344 while Present (IDC) loop
5345 Check_Static_Constraint (IDC);
5346 Next (IDC);
5347 end loop;
5348 end;
5350 when others =>
5351 null;
5352 end case;
5353 end Check_Static_Constraint;
5355 ---------------------
5356 -- Check_Test_Case --
5357 ---------------------
5359 procedure Check_Test_Case is
5360 P : Node_Id;
5361 PO : Node_Id;
5363 procedure Chain_CTC (PO : Node_Id);
5364 -- If PO is a [generic] subprogram declaration node, then the
5365 -- test-case applies to this subprogram and the processing for
5366 -- the pragma is completed. Otherwise the pragma is misplaced.
5368 ---------------
5369 -- Chain_CTC --
5370 ---------------
5372 procedure Chain_CTC (PO : Node_Id) is
5373 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
5374 CTC : Node_Id;
5375 S : Entity_Id;
5377 begin
5378 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
5379 Error_Pragma
5380 ("pragma% cannot be applied to abstract subprogram");
5382 elsif Nkind (PO) = N_Entry_Declaration then
5383 Error_Pragma ("pragma% cannot be applied to entry");
5385 elsif not Nkind_In (PO, N_Subprogram_Declaration,
5386 N_Generic_Subprogram_Declaration)
5387 then
5388 Pragma_Misplaced;
5389 end if;
5391 -- Here if we have [generic] subprogram declaration
5393 S := Defining_Unit_Name (Specification (PO));
5395 -- Note: we do not analyze the pragma at this point. Instead we
5396 -- delay this analysis until the end of the declarative part in
5397 -- which the pragma appears. This implements the required delay
5398 -- in this analysis, allowing forward references. The analysis
5399 -- happens at the end of Analyze_Declarations.
5401 -- There should not be another test-case with the same name
5402 -- associated to this subprogram.
5404 CTC := Contract_Test_Cases (Contract (S));
5405 while Present (CTC) loop
5407 -- Omit pragma Contract_Cases because it does not introduce
5408 -- a unique case name and it does not follow the syntax of
5409 -- Test_Case.
5411 if Pragma_Name (CTC) = Name_Contract_Cases then
5412 null;
5414 elsif String_Equal (Name, Get_Name_From_CTC_Pragma (CTC)) then
5415 Error_Msg_Sloc := Sloc (CTC);
5416 Error_Pragma ("name for pragma% is already used#");
5417 end if;
5419 CTC := Next_Pragma (CTC);
5420 end loop;
5422 -- Chain spec CTC pragma to list for subprogram
5424 Add_Contract_Item (N, S);
5425 end Chain_CTC;
5427 -- Start of processing for Check_Test_Case
5429 begin
5430 -- First check pragma arguments
5432 Check_At_Least_N_Arguments (2);
5433 Check_At_Most_N_Arguments (4);
5434 Check_Arg_Order
5435 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
5437 Check_Optional_Identifier (Arg1, Name_Name);
5438 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
5440 -- In ASIS mode, for a pragma generated from a source aspect, also
5441 -- analyze the original aspect expression.
5443 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
5444 Check_Expr_Is_OK_Static_Expression
5445 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
5446 end if;
5448 Check_Optional_Identifier (Arg2, Name_Mode);
5449 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
5451 if Arg_Count = 4 then
5452 Check_Identifier (Arg3, Name_Requires);
5453 Check_Identifier (Arg4, Name_Ensures);
5455 elsif Arg_Count = 3 then
5456 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
5457 end if;
5459 -- Check pragma placement
5461 if not Is_List_Member (N) then
5462 Pragma_Misplaced;
5463 end if;
5465 -- Test-case should only appear in package spec unit
5467 if Get_Source_Unit (N) = No_Unit
5468 or else not Nkind_In (Sinfo.Unit (Cunit (Current_Sem_Unit)),
5469 N_Package_Declaration,
5470 N_Generic_Package_Declaration)
5471 then
5472 Pragma_Misplaced;
5473 end if;
5475 -- Search prior declarations
5477 P := N;
5478 while Present (Prev (P)) loop
5479 P := Prev (P);
5481 -- If the previous node is a generic subprogram, do not go to to
5482 -- the original node, which is the unanalyzed tree: we need to
5483 -- attach the test-case to the analyzed version at this point.
5484 -- They get propagated to the original tree when analyzing the
5485 -- corresponding body.
5487 if Nkind (P) not in N_Generic_Declaration then
5488 PO := Original_Node (P);
5489 else
5490 PO := P;
5491 end if;
5493 -- Skip past prior pragma
5495 if Nkind (PO) = N_Pragma then
5496 null;
5498 -- Skip stuff not coming from source
5500 elsif not Comes_From_Source (PO) then
5501 null;
5503 -- Only remaining possibility is subprogram declaration. First
5504 -- check that it is declared directly in a package declaration.
5505 -- This may be either the package declaration for the current unit
5506 -- being defined or a local package declaration.
5508 elsif not Present (Parent (Parent (PO)))
5509 or else not Present (Parent (Parent (Parent (PO))))
5510 or else not Nkind_In (Parent (Parent (PO)),
5511 N_Package_Declaration,
5512 N_Generic_Package_Declaration)
5513 then
5514 Pragma_Misplaced;
5516 else
5517 Chain_CTC (PO);
5518 return;
5519 end if;
5520 end loop;
5522 -- If we fall through, pragma was misplaced
5524 Pragma_Misplaced;
5525 end Check_Test_Case;
5527 --------------------------------------
5528 -- Check_Valid_Configuration_Pragma --
5529 --------------------------------------
5531 -- A configuration pragma must appear in the context clause of a
5532 -- compilation unit, and only other pragmas may precede it. Note that
5533 -- the test also allows use in a configuration pragma file.
5535 procedure Check_Valid_Configuration_Pragma is
5536 begin
5537 if not Is_Configuration_Pragma then
5538 Error_Pragma ("incorrect placement for configuration pragma%");
5539 end if;
5540 end Check_Valid_Configuration_Pragma;
5542 -------------------------------------
5543 -- Check_Valid_Library_Unit_Pragma --
5544 -------------------------------------
5546 procedure Check_Valid_Library_Unit_Pragma is
5547 Plist : List_Id;
5548 Parent_Node : Node_Id;
5549 Unit_Name : Entity_Id;
5550 Unit_Kind : Node_Kind;
5551 Unit_Node : Node_Id;
5552 Sindex : Source_File_Index;
5554 begin
5555 if not Is_List_Member (N) then
5556 Pragma_Misplaced;
5558 else
5559 Plist := List_Containing (N);
5560 Parent_Node := Parent (Plist);
5562 if Parent_Node = Empty then
5563 Pragma_Misplaced;
5565 -- Case of pragma appearing after a compilation unit. In this case
5566 -- it must have an argument with the corresponding name and must
5567 -- be part of the following pragmas of its parent.
5569 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
5570 if Plist /= Pragmas_After (Parent_Node) then
5571 Pragma_Misplaced;
5573 elsif Arg_Count = 0 then
5574 Error_Pragma
5575 ("argument required if outside compilation unit");
5577 else
5578 Check_No_Identifiers;
5579 Check_Arg_Count (1);
5580 Unit_Node := Unit (Parent (Parent_Node));
5581 Unit_Kind := Nkind (Unit_Node);
5583 Analyze (Get_Pragma_Arg (Arg1));
5585 if Unit_Kind = N_Generic_Subprogram_Declaration
5586 or else Unit_Kind = N_Subprogram_Declaration
5587 then
5588 Unit_Name := Defining_Entity (Unit_Node);
5590 elsif Unit_Kind in N_Generic_Instantiation then
5591 Unit_Name := Defining_Entity (Unit_Node);
5593 else
5594 Unit_Name := Cunit_Entity (Current_Sem_Unit);
5595 end if;
5597 if Chars (Unit_Name) /=
5598 Chars (Entity (Get_Pragma_Arg (Arg1)))
5599 then
5600 Error_Pragma_Arg
5601 ("pragma% argument is not current unit name", Arg1);
5602 end if;
5604 if Ekind (Unit_Name) = E_Package
5605 and then Present (Renamed_Entity (Unit_Name))
5606 then
5607 Error_Pragma ("pragma% not allowed for renamed package");
5608 end if;
5609 end if;
5611 -- Pragma appears other than after a compilation unit
5613 else
5614 -- Here we check for the generic instantiation case and also
5615 -- for the case of processing a generic formal package. We
5616 -- detect these cases by noting that the Sloc on the node
5617 -- does not belong to the current compilation unit.
5619 Sindex := Source_Index (Current_Sem_Unit);
5621 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
5622 Rewrite (N, Make_Null_Statement (Loc));
5623 return;
5625 -- If before first declaration, the pragma applies to the
5626 -- enclosing unit, and the name if present must be this name.
5628 elsif Is_Before_First_Decl (N, Plist) then
5629 Unit_Node := Unit_Declaration_Node (Current_Scope);
5630 Unit_Kind := Nkind (Unit_Node);
5632 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
5633 Pragma_Misplaced;
5635 elsif Unit_Kind = N_Subprogram_Body
5636 and then not Acts_As_Spec (Unit_Node)
5637 then
5638 Pragma_Misplaced;
5640 elsif Nkind (Parent_Node) = N_Package_Body then
5641 Pragma_Misplaced;
5643 elsif Nkind (Parent_Node) = N_Package_Specification
5644 and then Plist = Private_Declarations (Parent_Node)
5645 then
5646 Pragma_Misplaced;
5648 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
5649 or else Nkind (Parent_Node) =
5650 N_Generic_Subprogram_Declaration)
5651 and then Plist = Generic_Formal_Declarations (Parent_Node)
5652 then
5653 Pragma_Misplaced;
5655 elsif Arg_Count > 0 then
5656 Analyze (Get_Pragma_Arg (Arg1));
5658 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
5659 Error_Pragma_Arg
5660 ("name in pragma% must be enclosing unit", Arg1);
5661 end if;
5663 -- It is legal to have no argument in this context
5665 else
5666 return;
5667 end if;
5669 -- Error if not before first declaration. This is because a
5670 -- library unit pragma argument must be the name of a library
5671 -- unit (RM 10.1.5(7)), but the only names permitted in this
5672 -- context are (RM 10.1.5(6)) names of subprogram declarations,
5673 -- generic subprogram declarations or generic instantiations.
5675 else
5676 Error_Pragma
5677 ("pragma% misplaced, must be before first declaration");
5678 end if;
5679 end if;
5680 end if;
5681 end Check_Valid_Library_Unit_Pragma;
5683 -------------------
5684 -- Check_Variant --
5685 -------------------
5687 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
5688 Clist : constant Node_Id := Component_List (Variant);
5689 Comp : Node_Id;
5691 begin
5692 Comp := First (Component_Items (Clist));
5693 while Present (Comp) loop
5694 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
5695 Next (Comp);
5696 end loop;
5697 end Check_Variant;
5699 ---------------------------
5700 -- Ensure_Aggregate_Form --
5701 ---------------------------
5703 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
5704 Expr : constant Node_Id := Get_Pragma_Arg (Arg);
5705 Loc : constant Source_Ptr := Sloc (Arg);
5706 Nam : constant Name_Id := Chars (Arg);
5707 Comps : List_Id := No_List;
5708 Exprs : List_Id := No_List;
5710 CFSD : constant Boolean := Get_Comes_From_Source_Default;
5711 -- Used to restore Comes_From_Source_Default
5713 begin
5714 -- The argument is already in aggregate form, but the presence of a
5715 -- name causes this to be interpreted as a named association which in
5716 -- turn must be converted into an aggregate.
5718 -- pragma Global (In_Out => (A, B, C))
5719 -- ^ ^
5720 -- name aggregate
5722 -- pragma Global ((In_Out => (A, B, C)))
5723 -- ^ ^
5724 -- aggregate aggregate
5726 if Nkind (Expr) = N_Aggregate then
5727 if Nam = No_Name then
5728 return;
5729 end if;
5731 -- Do not transform a null argument into an aggregate as N_Null has
5732 -- special meaning in formal verification pragmas.
5734 elsif Nkind (Expr) = N_Null then
5735 return;
5736 end if;
5738 -- Everything comes from source if the original comes from source
5740 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
5742 -- Positional argument is transformed into an aggregate with an
5743 -- Expressions list.
5745 if Nam = No_Name then
5746 Exprs := New_List (Relocate_Node (Expr));
5748 -- An associative argument is transformed into an aggregate with
5749 -- Component_Associations.
5751 else
5752 Comps := New_List (
5753 Make_Component_Association (Loc,
5754 Choices => New_List (Make_Identifier (Loc, Chars (Arg))),
5755 Expression => Relocate_Node (Expr)));
5756 end if;
5758 -- Remove the pragma argument name as this information has been
5759 -- captured in the aggregate.
5761 Set_Chars (Arg, No_Name);
5763 Set_Expression (Arg,
5764 Make_Aggregate (Loc,
5765 Component_Associations => Comps,
5766 Expressions => Exprs));
5768 -- Restore Comes_From_Source default
5770 Set_Comes_From_Source_Default (CFSD);
5771 end Ensure_Aggregate_Form;
5773 ------------------
5774 -- Error_Pragma --
5775 ------------------
5777 procedure Error_Pragma (Msg : String) is
5778 begin
5779 Error_Msg_Name_1 := Pname;
5780 Error_Msg_N (Fix_Error (Msg), N);
5781 raise Pragma_Exit;
5782 end Error_Pragma;
5784 ----------------------
5785 -- Error_Pragma_Arg --
5786 ----------------------
5788 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
5789 begin
5790 Error_Msg_Name_1 := Pname;
5791 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
5792 raise Pragma_Exit;
5793 end Error_Pragma_Arg;
5795 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
5796 begin
5797 Error_Msg_Name_1 := Pname;
5798 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
5799 Error_Pragma_Arg (Msg2, Arg);
5800 end Error_Pragma_Arg;
5802 ----------------------------
5803 -- Error_Pragma_Arg_Ident --
5804 ----------------------------
5806 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
5807 begin
5808 Error_Msg_Name_1 := Pname;
5809 Error_Msg_N (Fix_Error (Msg), Arg);
5810 raise Pragma_Exit;
5811 end Error_Pragma_Arg_Ident;
5813 ----------------------
5814 -- Error_Pragma_Ref --
5815 ----------------------
5817 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
5818 begin
5819 Error_Msg_Name_1 := Pname;
5820 Error_Msg_Sloc := Sloc (Ref);
5821 Error_Msg_NE (Fix_Error (Msg), N, Ref);
5822 raise Pragma_Exit;
5823 end Error_Pragma_Ref;
5825 ------------------------
5826 -- Find_Lib_Unit_Name --
5827 ------------------------
5829 function Find_Lib_Unit_Name return Entity_Id is
5830 begin
5831 -- Return inner compilation unit entity, for case of nested
5832 -- categorization pragmas. This happens in generic unit.
5834 if Nkind (Parent (N)) = N_Package_Specification
5835 and then Defining_Entity (Parent (N)) /= Current_Scope
5836 then
5837 return Defining_Entity (Parent (N));
5838 else
5839 return Current_Scope;
5840 end if;
5841 end Find_Lib_Unit_Name;
5843 ----------------------------
5844 -- Find_Program_Unit_Name --
5845 ----------------------------
5847 procedure Find_Program_Unit_Name (Id : Node_Id) is
5848 Unit_Name : Entity_Id;
5849 Unit_Kind : Node_Kind;
5850 P : constant Node_Id := Parent (N);
5852 begin
5853 if Nkind (P) = N_Compilation_Unit then
5854 Unit_Kind := Nkind (Unit (P));
5856 if Nkind_In (Unit_Kind, N_Subprogram_Declaration,
5857 N_Package_Declaration)
5858 or else Unit_Kind in N_Generic_Declaration
5859 then
5860 Unit_Name := Defining_Entity (Unit (P));
5862 if Chars (Id) = Chars (Unit_Name) then
5863 Set_Entity (Id, Unit_Name);
5864 Set_Etype (Id, Etype (Unit_Name));
5865 else
5866 Set_Etype (Id, Any_Type);
5867 Error_Pragma
5868 ("cannot find program unit referenced by pragma%");
5869 end if;
5871 else
5872 Set_Etype (Id, Any_Type);
5873 Error_Pragma ("pragma% inapplicable to this unit");
5874 end if;
5876 else
5877 Analyze (Id);
5878 end if;
5879 end Find_Program_Unit_Name;
5881 -----------------------------------------
5882 -- Find_Unique_Parameterless_Procedure --
5883 -----------------------------------------
5885 function Find_Unique_Parameterless_Procedure
5886 (Name : Entity_Id;
5887 Arg : Node_Id) return Entity_Id
5889 Proc : Entity_Id := Empty;
5891 begin
5892 -- The body of this procedure needs some comments ???
5894 if not Is_Entity_Name (Name) then
5895 Error_Pragma_Arg
5896 ("argument of pragma% must be entity name", Arg);
5898 elsif not Is_Overloaded (Name) then
5899 Proc := Entity (Name);
5901 if Ekind (Proc) /= E_Procedure
5902 or else Present (First_Formal (Proc))
5903 then
5904 Error_Pragma_Arg
5905 ("argument of pragma% must be parameterless procedure", Arg);
5906 end if;
5908 else
5909 declare
5910 Found : Boolean := False;
5911 It : Interp;
5912 Index : Interp_Index;
5914 begin
5915 Get_First_Interp (Name, Index, It);
5916 while Present (It.Nam) loop
5917 Proc := It.Nam;
5919 if Ekind (Proc) = E_Procedure
5920 and then No (First_Formal (Proc))
5921 then
5922 if not Found then
5923 Found := True;
5924 Set_Entity (Name, Proc);
5925 Set_Is_Overloaded (Name, False);
5926 else
5927 Error_Pragma_Arg
5928 ("ambiguous handler name for pragma% ", Arg);
5929 end if;
5930 end if;
5932 Get_Next_Interp (Index, It);
5933 end loop;
5935 if not Found then
5936 Error_Pragma_Arg
5937 ("argument of pragma% must be parameterless procedure",
5938 Arg);
5939 else
5940 Proc := Entity (Name);
5941 end if;
5942 end;
5943 end if;
5945 return Proc;
5946 end Find_Unique_Parameterless_Procedure;
5948 ---------------
5949 -- Fix_Error --
5950 ---------------
5952 function Fix_Error (Msg : String) return String is
5953 Res : String (Msg'Range) := Msg;
5954 Res_Last : Natural := Msg'Last;
5955 J : Natural;
5957 begin
5958 -- If we have a rewriting of another pragma, go to that pragma
5960 if Is_Rewrite_Substitution (N)
5961 and then Nkind (Original_Node (N)) = N_Pragma
5962 then
5963 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
5964 end if;
5966 -- Case where pragma comes from an aspect specification
5968 if From_Aspect_Specification (N) then
5970 -- Change appearence of "pragma" in message to "aspect"
5972 J := Res'First;
5973 while J <= Res_Last - 5 loop
5974 if Res (J .. J + 5) = "pragma" then
5975 Res (J .. J + 5) := "aspect";
5976 J := J + 6;
5978 else
5979 J := J + 1;
5980 end if;
5981 end loop;
5983 -- Change "argument of" at start of message to "entity for"
5985 if Res'Length > 11
5986 and then Res (Res'First .. Res'First + 10) = "argument of"
5987 then
5988 Res (Res'First .. Res'First + 9) := "entity for";
5989 Res (Res'First + 10 .. Res_Last - 1) :=
5990 Res (Res'First + 11 .. Res_Last);
5991 Res_Last := Res_Last - 1;
5992 end if;
5994 -- Change "argument" at start of message to "entity"
5996 if Res'Length > 8
5997 and then Res (Res'First .. Res'First + 7) = "argument"
5998 then
5999 Res (Res'First .. Res'First + 5) := "entity";
6000 Res (Res'First + 6 .. Res_Last - 2) :=
6001 Res (Res'First + 8 .. Res_Last);
6002 Res_Last := Res_Last - 2;
6003 end if;
6005 -- Get name from corresponding aspect
6007 Error_Msg_Name_1 := Original_Aspect_Name (N);
6008 end if;
6010 -- Return possibly modified message
6012 return Res (Res'First .. Res_Last);
6013 end Fix_Error;
6015 -------------------------
6016 -- Gather_Associations --
6017 -------------------------
6019 procedure Gather_Associations
6020 (Names : Name_List;
6021 Args : out Args_List)
6023 Arg : Node_Id;
6025 begin
6026 -- Initialize all parameters to Empty
6028 for J in Args'Range loop
6029 Args (J) := Empty;
6030 end loop;
6032 -- That's all we have to do if there are no argument associations
6034 if No (Pragma_Argument_Associations (N)) then
6035 return;
6036 end if;
6038 -- Otherwise first deal with any positional parameters present
6040 Arg := First (Pragma_Argument_Associations (N));
6041 for Index in Args'Range loop
6042 exit when No (Arg) or else Chars (Arg) /= No_Name;
6043 Args (Index) := Get_Pragma_Arg (Arg);
6044 Next (Arg);
6045 end loop;
6047 -- Positional parameters all processed, if any left, then we
6048 -- have too many positional parameters.
6050 if Present (Arg) and then Chars (Arg) = No_Name then
6051 Error_Pragma_Arg
6052 ("too many positional associations for pragma%", Arg);
6053 end if;
6055 -- Process named parameters if any are present
6057 while Present (Arg) loop
6058 if Chars (Arg) = No_Name then
6059 Error_Pragma_Arg
6060 ("positional association cannot follow named association",
6061 Arg);
6063 else
6064 for Index in Names'Range loop
6065 if Names (Index) = Chars (Arg) then
6066 if Present (Args (Index)) then
6067 Error_Pragma_Arg
6068 ("duplicate argument association for pragma%", Arg);
6069 else
6070 Args (Index) := Get_Pragma_Arg (Arg);
6071 exit;
6072 end if;
6073 end if;
6075 if Index = Names'Last then
6076 Error_Msg_Name_1 := Pname;
6077 Error_Msg_N ("pragma% does not allow & argument", Arg);
6079 -- Check for possible misspelling
6081 for Index1 in Names'Range loop
6082 if Is_Bad_Spelling_Of
6083 (Chars (Arg), Names (Index1))
6084 then
6085 Error_Msg_Name_1 := Names (Index1);
6086 Error_Msg_N -- CODEFIX
6087 ("\possible misspelling of%", Arg);
6088 exit;
6089 end if;
6090 end loop;
6092 raise Pragma_Exit;
6093 end if;
6094 end loop;
6095 end if;
6097 Next (Arg);
6098 end loop;
6099 end Gather_Associations;
6101 -----------------
6102 -- GNAT_Pragma --
6103 -----------------
6105 procedure GNAT_Pragma is
6106 begin
6107 -- We need to check the No_Implementation_Pragmas restriction for
6108 -- the case of a pragma from source. Note that the case of aspects
6109 -- generating corresponding pragmas marks these pragmas as not being
6110 -- from source, so this test also catches that case.
6112 if Comes_From_Source (N) then
6113 Check_Restriction (No_Implementation_Pragmas, N);
6114 end if;
6115 end GNAT_Pragma;
6117 --------------------------
6118 -- Is_Before_First_Decl --
6119 --------------------------
6121 function Is_Before_First_Decl
6122 (Pragma_Node : Node_Id;
6123 Decls : List_Id) return Boolean
6125 Item : Node_Id := First (Decls);
6127 begin
6128 -- Only other pragmas can come before this pragma
6130 loop
6131 if No (Item) or else Nkind (Item) /= N_Pragma then
6132 return False;
6134 elsif Item = Pragma_Node then
6135 return True;
6136 end if;
6138 Next (Item);
6139 end loop;
6140 end Is_Before_First_Decl;
6142 -----------------------------
6143 -- Is_Configuration_Pragma --
6144 -----------------------------
6146 -- A configuration pragma must appear in the context clause of a
6147 -- compilation unit, and only other pragmas may precede it. Note that
6148 -- the test below also permits use in a configuration pragma file.
6150 function Is_Configuration_Pragma return Boolean is
6151 Lis : constant List_Id := List_Containing (N);
6152 Par : constant Node_Id := Parent (N);
6153 Prg : Node_Id;
6155 begin
6156 -- If no parent, then we are in the configuration pragma file,
6157 -- so the placement is definitely appropriate.
6159 if No (Par) then
6160 return True;
6162 -- Otherwise we must be in the context clause of a compilation unit
6163 -- and the only thing allowed before us in the context list is more
6164 -- configuration pragmas.
6166 elsif Nkind (Par) = N_Compilation_Unit
6167 and then Context_Items (Par) = Lis
6168 then
6169 Prg := First (Lis);
6171 loop
6172 if Prg = N then
6173 return True;
6174 elsif Nkind (Prg) /= N_Pragma then
6175 return False;
6176 end if;
6178 Next (Prg);
6179 end loop;
6181 else
6182 return False;
6183 end if;
6184 end Is_Configuration_Pragma;
6186 --------------------------
6187 -- Is_In_Context_Clause --
6188 --------------------------
6190 function Is_In_Context_Clause return Boolean is
6191 Plist : List_Id;
6192 Parent_Node : Node_Id;
6194 begin
6195 if not Is_List_Member (N) then
6196 return False;
6198 else
6199 Plist := List_Containing (N);
6200 Parent_Node := Parent (Plist);
6202 if Parent_Node = Empty
6203 or else Nkind (Parent_Node) /= N_Compilation_Unit
6204 or else Context_Items (Parent_Node) /= Plist
6205 then
6206 return False;
6207 end if;
6208 end if;
6210 return True;
6211 end Is_In_Context_Clause;
6213 ---------------------------------
6214 -- Is_Static_String_Expression --
6215 ---------------------------------
6217 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
6218 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6219 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
6221 begin
6222 Analyze_And_Resolve (Argx);
6224 -- Special case Ada 83, where the expression will never be static,
6225 -- but we will return true if we had a string literal to start with.
6227 if Ada_Version = Ada_83 then
6228 return Lit;
6230 -- Normal case, true only if we end up with a string literal that
6231 -- is marked as being the result of evaluating a static expression.
6233 else
6234 return Is_OK_Static_Expression (Argx)
6235 and then Nkind (Argx) = N_String_Literal;
6236 end if;
6238 end Is_Static_String_Expression;
6240 ----------------------
6241 -- Pragma_Misplaced --
6242 ----------------------
6244 procedure Pragma_Misplaced is
6245 begin
6246 Error_Pragma ("incorrect placement of pragma%");
6247 end Pragma_Misplaced;
6249 ------------------------------------
6250 -- Process_Atomic_Shared_Volatile --
6251 ------------------------------------
6253 procedure Process_Atomic_Shared_Volatile is
6254 E_Id : Node_Id;
6255 E : Entity_Id;
6256 D : Node_Id;
6257 K : Node_Kind;
6258 Utyp : Entity_Id;
6260 procedure Set_Atomic (E : Entity_Id);
6261 -- Set given type as atomic, and if no explicit alignment was given,
6262 -- set alignment to unknown, since back end knows what the alignment
6263 -- requirements are for atomic arrays. Note: this step is necessary
6264 -- for derived types.
6266 ----------------
6267 -- Set_Atomic --
6268 ----------------
6270 procedure Set_Atomic (E : Entity_Id) is
6271 begin
6272 Set_Is_Atomic (E);
6274 if not Has_Alignment_Clause (E) then
6275 Set_Alignment (E, Uint_0);
6276 end if;
6277 end Set_Atomic;
6279 -- Start of processing for Process_Atomic_Shared_Volatile
6281 begin
6282 Check_Ada_83_Warning;
6283 Check_No_Identifiers;
6284 Check_Arg_Count (1);
6285 Check_Arg_Is_Local_Name (Arg1);
6286 E_Id := Get_Pragma_Arg (Arg1);
6288 if Etype (E_Id) = Any_Type then
6289 return;
6290 end if;
6292 E := Entity (E_Id);
6293 D := Declaration_Node (E);
6294 K := Nkind (D);
6296 -- Check duplicate before we chain ourselves
6298 Check_Duplicate_Pragma (E);
6300 -- Now check appropriateness of the entity
6302 if Is_Type (E) then
6303 if Rep_Item_Too_Early (E, N)
6304 or else
6305 Rep_Item_Too_Late (E, N)
6306 then
6307 return;
6308 else
6309 Check_First_Subtype (Arg1);
6310 end if;
6312 if Prag_Id /= Pragma_Volatile then
6313 Set_Atomic (E);
6314 Set_Atomic (Underlying_Type (E));
6315 Set_Atomic (Base_Type (E));
6316 end if;
6318 -- Attribute belongs on the base type. If the view of the type is
6319 -- currently private, it also belongs on the underlying type.
6321 Set_Is_Volatile (Base_Type (E));
6322 Set_Is_Volatile (Underlying_Type (E));
6324 Set_Treat_As_Volatile (E);
6325 Set_Treat_As_Volatile (Underlying_Type (E));
6327 elsif K = N_Object_Declaration
6328 or else (K = N_Component_Declaration
6329 and then Original_Record_Component (E) = E)
6330 then
6331 if Rep_Item_Too_Late (E, N) then
6332 return;
6333 end if;
6335 if Prag_Id /= Pragma_Volatile then
6336 Set_Is_Atomic (E);
6338 -- If the object declaration has an explicit initialization, a
6339 -- temporary may have to be created to hold the expression, to
6340 -- ensure that access to the object remain atomic.
6342 if Nkind (Parent (E)) = N_Object_Declaration
6343 and then Present (Expression (Parent (E)))
6344 then
6345 Set_Has_Delayed_Freeze (E);
6346 end if;
6348 -- An interesting improvement here. If an object of composite
6349 -- type X is declared atomic, and the type X isn't, that's a
6350 -- pity, since it may not have appropriate alignment etc. We
6351 -- can rescue this in the special case where the object and
6352 -- type are in the same unit by just setting the type as
6353 -- atomic, so that the back end will process it as atomic.
6355 -- Note: we used to do this for elementary types as well,
6356 -- but that turns out to be a bad idea and can have unwanted
6357 -- effects, most notably if the type is elementary, the object
6358 -- a simple component within a record, and both are in a spec:
6359 -- every object of this type in the entire program will be
6360 -- treated as atomic, thus incurring a potentially costly
6361 -- synchronization operation for every access.
6363 -- Of course it would be best if the back end could just adjust
6364 -- the alignment etc for the specific object, but that's not
6365 -- something we are capable of doing at this point.
6367 Utyp := Underlying_Type (Etype (E));
6369 if Present (Utyp)
6370 and then Is_Composite_Type (Utyp)
6371 and then Sloc (E) > No_Location
6372 and then Sloc (Utyp) > No_Location
6373 and then
6374 Get_Source_File_Index (Sloc (E)) =
6375 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
6376 then
6377 Set_Is_Atomic (Underlying_Type (Etype (E)));
6378 end if;
6379 end if;
6381 Set_Is_Volatile (E);
6382 Set_Treat_As_Volatile (E);
6384 else
6385 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6386 end if;
6388 -- The following check is only relevant when SPARK_Mode is on as
6389 -- this is not a standard Ada legality rule. Pragma Volatile can
6390 -- only apply to a full type declaration or an object declaration
6391 -- (SPARK RM C.6(1)).
6393 if SPARK_Mode = On
6394 and then Prag_Id = Pragma_Volatile
6395 and then not Nkind_In (K, N_Full_Type_Declaration,
6396 N_Object_Declaration)
6397 then
6398 Error_Pragma_Arg
6399 ("argument of pragma % must denote a full type or object "
6400 & "declaration", Arg1);
6401 end if;
6402 end Process_Atomic_Shared_Volatile;
6404 -------------------------------------------
6405 -- Process_Compile_Time_Warning_Or_Error --
6406 -------------------------------------------
6408 procedure Process_Compile_Time_Warning_Or_Error is
6409 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
6411 begin
6412 Check_Arg_Count (2);
6413 Check_No_Identifiers;
6414 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
6415 Analyze_And_Resolve (Arg1x, Standard_Boolean);
6417 if Compile_Time_Known_Value (Arg1x) then
6418 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
6419 declare
6420 Str : constant String_Id :=
6421 Strval (Get_Pragma_Arg (Arg2));
6422 Len : constant Int := String_Length (Str);
6423 Cont : Boolean;
6424 Ptr : Nat;
6425 CC : Char_Code;
6426 C : Character;
6427 Cent : constant Entity_Id :=
6428 Cunit_Entity (Current_Sem_Unit);
6430 Force : constant Boolean :=
6431 Prag_Id = Pragma_Compile_Time_Warning
6432 and then
6433 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
6434 and then (Ekind (Cent) /= E_Package
6435 or else not In_Private_Part (Cent));
6436 -- Set True if this is the warning case, and we are in the
6437 -- visible part of a package spec, or in a subprogram spec,
6438 -- in which case we want to force the client to see the
6439 -- warning, even though it is not in the main unit.
6441 begin
6442 -- Loop through segments of message separated by line feeds.
6443 -- We output these segments as separate messages with
6444 -- continuation marks for all but the first.
6446 Cont := False;
6447 Ptr := 1;
6448 loop
6449 Error_Msg_Strlen := 0;
6451 -- Loop to copy characters from argument to error message
6452 -- string buffer.
6454 loop
6455 exit when Ptr > Len;
6456 CC := Get_String_Char (Str, Ptr);
6457 Ptr := Ptr + 1;
6459 -- Ignore wide chars ??? else store character
6461 if In_Character_Range (CC) then
6462 C := Get_Character (CC);
6463 exit when C = ASCII.LF;
6464 Error_Msg_Strlen := Error_Msg_Strlen + 1;
6465 Error_Msg_String (Error_Msg_Strlen) := C;
6466 end if;
6467 end loop;
6469 -- Here with one line ready to go
6471 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
6473 -- If this is a warning in a spec, then we want clients
6474 -- to see the warning, so mark the message with the
6475 -- special sequence !! to force the warning. In the case
6476 -- of a package spec, we do not force this if we are in
6477 -- the private part of the spec.
6479 if Force then
6480 if Cont = False then
6481 Error_Msg_N ("<<~!!", Arg1);
6482 Cont := True;
6483 else
6484 Error_Msg_N ("\<<~!!", Arg1);
6485 end if;
6487 -- Error, rather than warning, or in a body, so we do not
6488 -- need to force visibility for client (error will be
6489 -- output in any case, and this is the situation in which
6490 -- we do not want a client to get a warning, since the
6491 -- warning is in the body or the spec private part).
6493 else
6494 if Cont = False then
6495 Error_Msg_N ("<<~", Arg1);
6496 Cont := True;
6497 else
6498 Error_Msg_N ("\<<~", Arg1);
6499 end if;
6500 end if;
6502 exit when Ptr > Len;
6503 end loop;
6504 end;
6505 end if;
6506 end if;
6507 end Process_Compile_Time_Warning_Or_Error;
6509 ------------------------
6510 -- Process_Convention --
6511 ------------------------
6513 procedure Process_Convention
6514 (C : out Convention_Id;
6515 Ent : out Entity_Id)
6517 Cname : Name_Id;
6519 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
6520 -- Called if we have more than one Export/Import/Convention pragma.
6521 -- This is generally illegal, but we have a special case of allowing
6522 -- Import and Interface to coexist if they specify the convention in
6523 -- a consistent manner. We are allowed to do this, since Interface is
6524 -- an implementation defined pragma, and we choose to do it since we
6525 -- know Rational allows this combination. S is the entity id of the
6526 -- subprogram in question. This procedure also sets the special flag
6527 -- Import_Interface_Present in both pragmas in the case where we do
6528 -- have matching Import and Interface pragmas.
6530 procedure Set_Convention_From_Pragma (E : Entity_Id);
6531 -- Set convention in entity E, and also flag that the entity has a
6532 -- convention pragma. If entity is for a private or incomplete type,
6533 -- also set convention and flag on underlying type. This procedure
6534 -- also deals with the special case of C_Pass_By_Copy convention,
6535 -- and error checks for inappropriate convention specification.
6537 -------------------------------
6538 -- Diagnose_Multiple_Pragmas --
6539 -------------------------------
6541 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
6542 Pdec : constant Node_Id := Declaration_Node (S);
6543 Decl : Node_Id;
6544 Err : Boolean;
6546 function Same_Convention (Decl : Node_Id) return Boolean;
6547 -- Decl is a pragma node. This function returns True if this
6548 -- pragma has a first argument that is an identifier with a
6549 -- Chars field corresponding to the Convention_Id C.
6551 function Same_Name (Decl : Node_Id) return Boolean;
6552 -- Decl is a pragma node. This function returns True if this
6553 -- pragma has a second argument that is an identifier with a
6554 -- Chars field that matches the Chars of the current subprogram.
6556 ---------------------
6557 -- Same_Convention --
6558 ---------------------
6560 function Same_Convention (Decl : Node_Id) return Boolean is
6561 Arg1 : constant Node_Id :=
6562 First (Pragma_Argument_Associations (Decl));
6564 begin
6565 if Present (Arg1) then
6566 declare
6567 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
6568 begin
6569 if Nkind (Arg) = N_Identifier
6570 and then Is_Convention_Name (Chars (Arg))
6571 and then Get_Convention_Id (Chars (Arg)) = C
6572 then
6573 return True;
6574 end if;
6575 end;
6576 end if;
6578 return False;
6579 end Same_Convention;
6581 ---------------
6582 -- Same_Name --
6583 ---------------
6585 function Same_Name (Decl : Node_Id) return Boolean is
6586 Arg1 : constant Node_Id :=
6587 First (Pragma_Argument_Associations (Decl));
6588 Arg2 : Node_Id;
6590 begin
6591 if No (Arg1) then
6592 return False;
6593 end if;
6595 Arg2 := Next (Arg1);
6597 if No (Arg2) then
6598 return False;
6599 end if;
6601 declare
6602 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
6603 begin
6604 if Nkind (Arg) = N_Identifier
6605 and then Chars (Arg) = Chars (S)
6606 then
6607 return True;
6608 end if;
6609 end;
6611 return False;
6612 end Same_Name;
6614 -- Start of processing for Diagnose_Multiple_Pragmas
6616 begin
6617 Err := True;
6619 -- Definitely give message if we have Convention/Export here
6621 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
6622 null;
6624 -- If we have an Import or Export, scan back from pragma to
6625 -- find any previous pragma applying to the same procedure.
6626 -- The scan will be terminated by the start of the list, or
6627 -- hitting the subprogram declaration. This won't allow one
6628 -- pragma to appear in the public part and one in the private
6629 -- part, but that seems very unlikely in practice.
6631 else
6632 Decl := Prev (N);
6633 while Present (Decl) and then Decl /= Pdec loop
6635 -- Look for pragma with same name as us
6637 if Nkind (Decl) = N_Pragma
6638 and then Same_Name (Decl)
6639 then
6640 -- Give error if same as our pragma or Export/Convention
6642 if Nam_In (Pragma_Name (Decl), Name_Export,
6643 Name_Convention,
6644 Pragma_Name (N))
6645 then
6646 exit;
6648 -- Case of Import/Interface or the other way round
6650 elsif Nam_In (Pragma_Name (Decl), Name_Interface,
6651 Name_Import)
6652 then
6653 -- Here we know that we have Import and Interface. It
6654 -- doesn't matter which way round they are. See if
6655 -- they specify the same convention. If so, all OK,
6656 -- and set special flags to stop other messages
6658 if Same_Convention (Decl) then
6659 Set_Import_Interface_Present (N);
6660 Set_Import_Interface_Present (Decl);
6661 Err := False;
6663 -- If different conventions, special message
6665 else
6666 Error_Msg_Sloc := Sloc (Decl);
6667 Error_Pragma_Arg
6668 ("convention differs from that given#", Arg1);
6669 return;
6670 end if;
6671 end if;
6672 end if;
6674 Next (Decl);
6675 end loop;
6676 end if;
6678 -- Give message if needed if we fall through those tests
6679 -- except on Relaxed_RM_Semantics where we let go: either this
6680 -- is a case accepted/ignored by other Ada compilers (e.g.
6681 -- a mix of Convention and Import), or another error will be
6682 -- generated later (e.g. using both Import and Export).
6684 if Err and not Relaxed_RM_Semantics then
6685 Error_Pragma_Arg
6686 ("at most one Convention/Export/Import pragma is allowed",
6687 Arg2);
6688 end if;
6689 end Diagnose_Multiple_Pragmas;
6691 --------------------------------
6692 -- Set_Convention_From_Pragma --
6693 --------------------------------
6695 procedure Set_Convention_From_Pragma (E : Entity_Id) is
6696 begin
6697 -- Ada 2005 (AI-430): Check invalid attempt to change convention
6698 -- for an overridden dispatching operation. Technically this is
6699 -- an amendment and should only be done in Ada 2005 mode. However,
6700 -- this is clearly a mistake, since the problem that is addressed
6701 -- by this AI is that there is a clear gap in the RM.
6703 if Is_Dispatching_Operation (E)
6704 and then Present (Overridden_Operation (E))
6705 and then C /= Convention (Overridden_Operation (E))
6706 then
6707 Error_Pragma_Arg
6708 ("cannot change convention for overridden dispatching "
6709 & "operation", Arg1);
6710 end if;
6712 -- Special checks for Convention_Stdcall
6714 if C = Convention_Stdcall then
6716 -- A dispatching call is not allowed. A dispatching subprogram
6717 -- cannot be used to interface to the Win32 API, so in fact
6718 -- this check does not impose any effective restriction.
6720 if Is_Dispatching_Operation (E) then
6721 Error_Msg_Sloc := Sloc (E);
6723 -- Note: make this unconditional so that if there is more
6724 -- than one call to which the pragma applies, we get a
6725 -- message for each call. Also don't use Error_Pragma,
6726 -- so that we get multiple messages.
6728 Error_Msg_N
6729 ("dispatching subprogram# cannot use Stdcall convention!",
6730 Arg1);
6732 -- Subprograms are not allowed
6734 elsif not Is_Subprogram_Or_Generic_Subprogram (E)
6736 -- A variable is OK
6738 and then Ekind (E) /= E_Variable
6740 -- An access to subprogram is also allowed
6742 and then not
6743 (Is_Access_Type (E)
6744 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
6746 -- Allow internal call to set convention of subprogram type
6748 and then not (Ekind (E) = E_Subprogram_Type)
6749 then
6750 Error_Pragma_Arg
6751 ("second argument of pragma% must be subprogram (type)",
6752 Arg2);
6753 end if;
6754 end if;
6756 -- Set the convention
6758 Set_Convention (E, C);
6759 Set_Has_Convention_Pragma (E);
6761 -- For the case of a record base type, also set the convention of
6762 -- any anonymous access types declared in the record which do not
6763 -- currently have a specified convention.
6765 if Is_Record_Type (E) and then Is_Base_Type (E) then
6766 declare
6767 Comp : Node_Id;
6769 begin
6770 Comp := First_Component (E);
6771 while Present (Comp) loop
6772 if Present (Etype (Comp))
6773 and then Ekind_In (Etype (Comp),
6774 E_Anonymous_Access_Type,
6775 E_Anonymous_Access_Subprogram_Type)
6776 and then not Has_Convention_Pragma (Comp)
6777 then
6778 Set_Convention (Comp, C);
6779 end if;
6781 Next_Component (Comp);
6782 end loop;
6783 end;
6784 end if;
6786 -- Deal with incomplete/private type case, where underlying type
6787 -- is available, so set convention of that underlying type.
6789 if Is_Incomplete_Or_Private_Type (E)
6790 and then Present (Underlying_Type (E))
6791 then
6792 Set_Convention (Underlying_Type (E), C);
6793 Set_Has_Convention_Pragma (Underlying_Type (E), True);
6794 end if;
6796 -- A class-wide type should inherit the convention of the specific
6797 -- root type (although this isn't specified clearly by the RM).
6799 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
6800 Set_Convention (Class_Wide_Type (E), C);
6801 end if;
6803 -- If the entity is a record type, then check for special case of
6804 -- C_Pass_By_Copy, which is treated the same as C except that the
6805 -- special record flag is set. This convention is only permitted
6806 -- on record types (see AI95-00131).
6808 if Cname = Name_C_Pass_By_Copy then
6809 if Is_Record_Type (E) then
6810 Set_C_Pass_By_Copy (Base_Type (E));
6811 elsif Is_Incomplete_Or_Private_Type (E)
6812 and then Is_Record_Type (Underlying_Type (E))
6813 then
6814 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
6815 else
6816 Error_Pragma_Arg
6817 ("C_Pass_By_Copy convention allowed only for record type",
6818 Arg2);
6819 end if;
6820 end if;
6822 -- If the entity is a derived boolean type, check for the special
6823 -- case of convention C, C++, or Fortran, where we consider any
6824 -- nonzero value to represent true.
6826 if Is_Discrete_Type (E)
6827 and then Root_Type (Etype (E)) = Standard_Boolean
6828 and then
6829 (C = Convention_C
6830 or else
6831 C = Convention_CPP
6832 or else
6833 C = Convention_Fortran)
6834 then
6835 Set_Nonzero_Is_True (Base_Type (E));
6836 end if;
6837 end Set_Convention_From_Pragma;
6839 -- Local variables
6841 Comp_Unit : Unit_Number_Type;
6842 E : Entity_Id;
6843 E1 : Entity_Id;
6844 Id : Node_Id;
6846 -- Start of processing for Process_Convention
6848 begin
6849 Check_At_Least_N_Arguments (2);
6850 Check_Optional_Identifier (Arg1, Name_Convention);
6851 Check_Arg_Is_Identifier (Arg1);
6852 Cname := Chars (Get_Pragma_Arg (Arg1));
6854 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
6855 -- tested again below to set the critical flag).
6857 if Cname = Name_C_Pass_By_Copy then
6858 C := Convention_C;
6860 -- Otherwise we must have something in the standard convention list
6862 elsif Is_Convention_Name (Cname) then
6863 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
6865 -- Otherwise warn on unrecognized convention
6867 else
6868 if Warn_On_Export_Import then
6869 Error_Msg_N
6870 ("??unrecognized convention name, C assumed",
6871 Get_Pragma_Arg (Arg1));
6872 end if;
6874 C := Convention_C;
6875 end if;
6877 Check_Optional_Identifier (Arg2, Name_Entity);
6878 Check_Arg_Is_Local_Name (Arg2);
6880 Id := Get_Pragma_Arg (Arg2);
6881 Analyze (Id);
6883 if not Is_Entity_Name (Id) then
6884 Error_Pragma_Arg ("entity name required", Arg2);
6885 end if;
6887 E := Entity (Id);
6889 -- Set entity to return
6891 Ent := E;
6893 -- Ada_Pass_By_Copy special checking
6895 if C = Convention_Ada_Pass_By_Copy then
6896 if not Is_First_Subtype (E) then
6897 Error_Pragma_Arg
6898 ("convention `Ada_Pass_By_Copy` only allowed for types",
6899 Arg2);
6900 end if;
6902 if Is_By_Reference_Type (E) then
6903 Error_Pragma_Arg
6904 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
6905 & "type", Arg1);
6906 end if;
6908 -- Ada_Pass_By_Reference special checking
6910 elsif C = Convention_Ada_Pass_By_Reference then
6911 if not Is_First_Subtype (E) then
6912 Error_Pragma_Arg
6913 ("convention `Ada_Pass_By_Reference` only allowed for types",
6914 Arg2);
6915 end if;
6917 if Is_By_Copy_Type (E) then
6918 Error_Pragma_Arg
6919 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
6920 & "type", Arg1);
6921 end if;
6922 end if;
6924 -- Go to renamed subprogram if present, since convention applies to
6925 -- the actual renamed entity, not to the renaming entity. If the
6926 -- subprogram is inherited, go to parent subprogram.
6928 if Is_Subprogram (E)
6929 and then Present (Alias (E))
6930 then
6931 if Nkind (Parent (Declaration_Node (E))) =
6932 N_Subprogram_Renaming_Declaration
6933 then
6934 if Scope (E) /= Scope (Alias (E)) then
6935 Error_Pragma_Ref
6936 ("cannot apply pragma% to non-local entity&#", E);
6937 end if;
6939 E := Alias (E);
6941 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
6942 N_Private_Extension_Declaration)
6943 and then Scope (E) = Scope (Alias (E))
6944 then
6945 E := Alias (E);
6947 -- Return the parent subprogram the entity was inherited from
6949 Ent := E;
6950 end if;
6951 end if;
6953 -- Check that we are not applying this to a specless body. Relax this
6954 -- check if Relaxed_RM_Semantics to accomodate other Ada compilers.
6956 if Is_Subprogram (E)
6957 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
6958 and then not Relaxed_RM_Semantics
6959 then
6960 Error_Pragma
6961 ("pragma% requires separate spec and must come before body");
6962 end if;
6964 -- Check that we are not applying this to a named constant
6966 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
6967 Error_Msg_Name_1 := Pname;
6968 Error_Msg_N
6969 ("cannot apply pragma% to named constant!",
6970 Get_Pragma_Arg (Arg2));
6971 Error_Pragma_Arg
6972 ("\supply appropriate type for&!", Arg2);
6973 end if;
6975 if Ekind (E) = E_Enumeration_Literal then
6976 Error_Pragma ("enumeration literal not allowed for pragma%");
6977 end if;
6979 -- Check for rep item appearing too early or too late
6981 if Etype (E) = Any_Type
6982 or else Rep_Item_Too_Early (E, N)
6983 then
6984 raise Pragma_Exit;
6986 elsif Present (Underlying_Type (E)) then
6987 E := Underlying_Type (E);
6988 end if;
6990 if Rep_Item_Too_Late (E, N) then
6991 raise Pragma_Exit;
6992 end if;
6994 if Has_Convention_Pragma (E) then
6995 Diagnose_Multiple_Pragmas (E);
6997 elsif Convention (E) = Convention_Protected
6998 or else Ekind (Scope (E)) = E_Protected_Type
6999 then
7000 Error_Pragma_Arg
7001 ("a protected operation cannot be given a different convention",
7002 Arg2);
7003 end if;
7005 -- For Intrinsic, a subprogram is required
7007 if C = Convention_Intrinsic
7008 and then not Is_Subprogram_Or_Generic_Subprogram (E)
7009 then
7010 Error_Pragma_Arg
7011 ("second argument of pragma% must be a subprogram", Arg2);
7012 end if;
7014 -- Deal with non-subprogram cases
7016 if not Is_Subprogram_Or_Generic_Subprogram (E) then
7017 Set_Convention_From_Pragma (E);
7019 if Is_Type (E) then
7020 Check_First_Subtype (Arg2);
7021 Set_Convention_From_Pragma (Base_Type (E));
7023 -- For access subprograms, we must set the convention on the
7024 -- internally generated directly designated type as well.
7026 if Ekind (E) = E_Access_Subprogram_Type then
7027 Set_Convention_From_Pragma (Directly_Designated_Type (E));
7028 end if;
7029 end if;
7031 -- For the subprogram case, set proper convention for all homonyms
7032 -- in same scope and the same declarative part, i.e. the same
7033 -- compilation unit.
7035 else
7036 Comp_Unit := Get_Source_Unit (E);
7037 Set_Convention_From_Pragma (E);
7039 -- Treat a pragma Import as an implicit body, and pragma import
7040 -- as implicit reference (for navigation in GPS).
7042 if Prag_Id = Pragma_Import then
7043 Generate_Reference (E, Id, 'b');
7045 -- For exported entities we restrict the generation of references
7046 -- to entities exported to foreign languages since entities
7047 -- exported to Ada do not provide further information to GPS and
7048 -- add undesired references to the output of the gnatxref tool.
7050 elsif Prag_Id = Pragma_Export
7051 and then Convention (E) /= Convention_Ada
7052 then
7053 Generate_Reference (E, Id, 'i');
7054 end if;
7056 -- If the pragma comes from from an aspect, it only applies to the
7057 -- given entity, not its homonyms.
7059 if From_Aspect_Specification (N) then
7060 return;
7061 end if;
7063 -- Otherwise Loop through the homonyms of the pragma argument's
7064 -- entity, an apply convention to those in the current scope.
7066 E1 := Ent;
7068 loop
7069 E1 := Homonym (E1);
7070 exit when No (E1) or else Scope (E1) /= Current_Scope;
7072 -- Ignore entry for which convention is already set
7074 if Has_Convention_Pragma (E1) then
7075 goto Continue;
7076 end if;
7078 -- Do not set the pragma on inherited operations or on formal
7079 -- subprograms.
7081 if Comes_From_Source (E1)
7082 and then Comp_Unit = Get_Source_Unit (E1)
7083 and then not Is_Formal_Subprogram (E1)
7084 and then Nkind (Original_Node (Parent (E1))) /=
7085 N_Full_Type_Declaration
7086 then
7087 if Present (Alias (E1))
7088 and then Scope (E1) /= Scope (Alias (E1))
7089 then
7090 Error_Pragma_Ref
7091 ("cannot apply pragma% to non-local entity& declared#",
7092 E1);
7093 end if;
7095 Set_Convention_From_Pragma (E1);
7097 if Prag_Id = Pragma_Import then
7098 Generate_Reference (E1, Id, 'b');
7099 end if;
7100 end if;
7102 <<Continue>>
7103 null;
7104 end loop;
7105 end if;
7106 end Process_Convention;
7108 ----------------------------------------
7109 -- Process_Disable_Enable_Atomic_Sync --
7110 ----------------------------------------
7112 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
7113 begin
7114 Check_No_Identifiers;
7115 Check_At_Most_N_Arguments (1);
7117 -- Modeled internally as
7118 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
7120 Rewrite (N,
7121 Make_Pragma (Loc,
7122 Pragma_Identifier =>
7123 Make_Identifier (Loc, Nam),
7124 Pragma_Argument_Associations => New_List (
7125 Make_Pragma_Argument_Association (Loc,
7126 Expression =>
7127 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
7129 if Present (Arg1) then
7130 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
7131 end if;
7133 Analyze (N);
7134 end Process_Disable_Enable_Atomic_Sync;
7136 -------------------------------------------------
7137 -- Process_Extended_Import_Export_Internal_Arg --
7138 -------------------------------------------------
7140 procedure Process_Extended_Import_Export_Internal_Arg
7141 (Arg_Internal : Node_Id := Empty)
7143 begin
7144 if No (Arg_Internal) then
7145 Error_Pragma ("Internal parameter required for pragma%");
7146 end if;
7148 if Nkind (Arg_Internal) = N_Identifier then
7149 null;
7151 elsif Nkind (Arg_Internal) = N_Operator_Symbol
7152 and then (Prag_Id = Pragma_Import_Function
7153 or else
7154 Prag_Id = Pragma_Export_Function)
7155 then
7156 null;
7158 else
7159 Error_Pragma_Arg
7160 ("wrong form for Internal parameter for pragma%", Arg_Internal);
7161 end if;
7163 Check_Arg_Is_Local_Name (Arg_Internal);
7164 end Process_Extended_Import_Export_Internal_Arg;
7166 --------------------------------------------------
7167 -- Process_Extended_Import_Export_Object_Pragma --
7168 --------------------------------------------------
7170 procedure Process_Extended_Import_Export_Object_Pragma
7171 (Arg_Internal : Node_Id;
7172 Arg_External : Node_Id;
7173 Arg_Size : Node_Id)
7175 Def_Id : Entity_Id;
7177 begin
7178 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7179 Def_Id := Entity (Arg_Internal);
7181 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
7182 Error_Pragma_Arg
7183 ("pragma% must designate an object", Arg_Internal);
7184 end if;
7186 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
7187 or else
7188 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
7189 then
7190 Error_Pragma_Arg
7191 ("previous Common/Psect_Object applies, pragma % not permitted",
7192 Arg_Internal);
7193 end if;
7195 if Rep_Item_Too_Late (Def_Id, N) then
7196 raise Pragma_Exit;
7197 end if;
7199 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
7201 if Present (Arg_Size) then
7202 Check_Arg_Is_External_Name (Arg_Size);
7203 end if;
7205 -- Export_Object case
7207 if Prag_Id = Pragma_Export_Object then
7208 if not Is_Library_Level_Entity (Def_Id) then
7209 Error_Pragma_Arg
7210 ("argument for pragma% must be library level entity",
7211 Arg_Internal);
7212 end if;
7214 if Ekind (Current_Scope) = E_Generic_Package then
7215 Error_Pragma ("pragma& cannot appear in a generic unit");
7216 end if;
7218 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
7219 Error_Pragma_Arg
7220 ("exported object must have compile time known size",
7221 Arg_Internal);
7222 end if;
7224 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
7225 Error_Msg_N ("??duplicate Export_Object pragma", N);
7226 else
7227 Set_Exported (Def_Id, Arg_Internal);
7228 end if;
7230 -- Import_Object case
7232 else
7233 if Is_Concurrent_Type (Etype (Def_Id)) then
7234 Error_Pragma_Arg
7235 ("cannot use pragma% for task/protected object",
7236 Arg_Internal);
7237 end if;
7239 if Ekind (Def_Id) = E_Constant then
7240 Error_Pragma_Arg
7241 ("cannot import a constant", Arg_Internal);
7242 end if;
7244 if Warn_On_Export_Import
7245 and then Has_Discriminants (Etype (Def_Id))
7246 then
7247 Error_Msg_N
7248 ("imported value must be initialized??", Arg_Internal);
7249 end if;
7251 if Warn_On_Export_Import
7252 and then Is_Access_Type (Etype (Def_Id))
7253 then
7254 Error_Pragma_Arg
7255 ("cannot import object of an access type??", Arg_Internal);
7256 end if;
7258 if Warn_On_Export_Import
7259 and then Is_Imported (Def_Id)
7260 then
7261 Error_Msg_N ("??duplicate Import_Object pragma", N);
7263 -- Check for explicit initialization present. Note that an
7264 -- initialization generated by the code generator, e.g. for an
7265 -- access type, does not count here.
7267 elsif Present (Expression (Parent (Def_Id)))
7268 and then
7269 Comes_From_Source
7270 (Original_Node (Expression (Parent (Def_Id))))
7271 then
7272 Error_Msg_Sloc := Sloc (Def_Id);
7273 Error_Pragma_Arg
7274 ("imported entities cannot be initialized (RM B.1(24))",
7275 "\no initialization allowed for & declared#", Arg1);
7276 else
7277 Set_Imported (Def_Id);
7278 Note_Possible_Modification (Arg_Internal, Sure => False);
7279 end if;
7280 end if;
7281 end Process_Extended_Import_Export_Object_Pragma;
7283 ------------------------------------------------------
7284 -- Process_Extended_Import_Export_Subprogram_Pragma --
7285 ------------------------------------------------------
7287 procedure Process_Extended_Import_Export_Subprogram_Pragma
7288 (Arg_Internal : Node_Id;
7289 Arg_External : Node_Id;
7290 Arg_Parameter_Types : Node_Id;
7291 Arg_Result_Type : Node_Id := Empty;
7292 Arg_Mechanism : Node_Id;
7293 Arg_Result_Mechanism : Node_Id := Empty)
7295 Ent : Entity_Id;
7296 Def_Id : Entity_Id;
7297 Hom_Id : Entity_Id;
7298 Formal : Entity_Id;
7299 Ambiguous : Boolean;
7300 Match : Boolean;
7302 function Same_Base_Type
7303 (Ptype : Node_Id;
7304 Formal : Entity_Id) return Boolean;
7305 -- Determines if Ptype references the type of Formal. Note that only
7306 -- the base types need to match according to the spec. Ptype here is
7307 -- the argument from the pragma, which is either a type name, or an
7308 -- access attribute.
7310 --------------------
7311 -- Same_Base_Type --
7312 --------------------
7314 function Same_Base_Type
7315 (Ptype : Node_Id;
7316 Formal : Entity_Id) return Boolean
7318 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
7319 Pref : Node_Id;
7321 begin
7322 -- Case where pragma argument is typ'Access
7324 if Nkind (Ptype) = N_Attribute_Reference
7325 and then Attribute_Name (Ptype) = Name_Access
7326 then
7327 Pref := Prefix (Ptype);
7328 Find_Type (Pref);
7330 if not Is_Entity_Name (Pref)
7331 or else Entity (Pref) = Any_Type
7332 then
7333 raise Pragma_Exit;
7334 end if;
7336 -- We have a match if the corresponding argument is of an
7337 -- anonymous access type, and its designated type matches the
7338 -- type of the prefix of the access attribute
7340 return Ekind (Ftyp) = E_Anonymous_Access_Type
7341 and then Base_Type (Entity (Pref)) =
7342 Base_Type (Etype (Designated_Type (Ftyp)));
7344 -- Case where pragma argument is a type name
7346 else
7347 Find_Type (Ptype);
7349 if not Is_Entity_Name (Ptype)
7350 or else Entity (Ptype) = Any_Type
7351 then
7352 raise Pragma_Exit;
7353 end if;
7355 -- We have a match if the corresponding argument is of the type
7356 -- given in the pragma (comparing base types)
7358 return Base_Type (Entity (Ptype)) = Ftyp;
7359 end if;
7360 end Same_Base_Type;
7362 -- Start of processing for
7363 -- Process_Extended_Import_Export_Subprogram_Pragma
7365 begin
7366 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7367 Ent := Empty;
7368 Ambiguous := False;
7370 -- Loop through homonyms (overloadings) of the entity
7372 Hom_Id := Entity (Arg_Internal);
7373 while Present (Hom_Id) loop
7374 Def_Id := Get_Base_Subprogram (Hom_Id);
7376 -- We need a subprogram in the current scope
7378 if not Is_Subprogram (Def_Id)
7379 or else Scope (Def_Id) /= Current_Scope
7380 then
7381 null;
7383 else
7384 Match := True;
7386 -- Pragma cannot apply to subprogram body
7388 if Is_Subprogram (Def_Id)
7389 and then Nkind (Parent (Declaration_Node (Def_Id))) =
7390 N_Subprogram_Body
7391 then
7392 Error_Pragma
7393 ("pragma% requires separate spec"
7394 & " and must come before body");
7395 end if;
7397 -- Test result type if given, note that the result type
7398 -- parameter can only be present for the function cases.
7400 if Present (Arg_Result_Type)
7401 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
7402 then
7403 Match := False;
7405 elsif Etype (Def_Id) /= Standard_Void_Type
7406 and then
7407 Nam_In (Pname, Name_Export_Procedure, Name_Import_Procedure)
7408 then
7409 Match := False;
7411 -- Test parameter types if given. Note that this parameter
7412 -- has not been analyzed (and must not be, since it is
7413 -- semantic nonsense), so we get it as the parser left it.
7415 elsif Present (Arg_Parameter_Types) then
7416 Check_Matching_Types : declare
7417 Formal : Entity_Id;
7418 Ptype : Node_Id;
7420 begin
7421 Formal := First_Formal (Def_Id);
7423 if Nkind (Arg_Parameter_Types) = N_Null then
7424 if Present (Formal) then
7425 Match := False;
7426 end if;
7428 -- A list of one type, e.g. (List) is parsed as
7429 -- a parenthesized expression.
7431 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
7432 and then Paren_Count (Arg_Parameter_Types) = 1
7433 then
7434 if No (Formal)
7435 or else Present (Next_Formal (Formal))
7436 then
7437 Match := False;
7438 else
7439 Match :=
7440 Same_Base_Type (Arg_Parameter_Types, Formal);
7441 end if;
7443 -- A list of more than one type is parsed as a aggregate
7445 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
7446 and then Paren_Count (Arg_Parameter_Types) = 0
7447 then
7448 Ptype := First (Expressions (Arg_Parameter_Types));
7449 while Present (Ptype) or else Present (Formal) loop
7450 if No (Ptype)
7451 or else No (Formal)
7452 or else not Same_Base_Type (Ptype, Formal)
7453 then
7454 Match := False;
7455 exit;
7456 else
7457 Next_Formal (Formal);
7458 Next (Ptype);
7459 end if;
7460 end loop;
7462 -- Anything else is of the wrong form
7464 else
7465 Error_Pragma_Arg
7466 ("wrong form for Parameter_Types parameter",
7467 Arg_Parameter_Types);
7468 end if;
7469 end Check_Matching_Types;
7470 end if;
7472 -- Match is now False if the entry we found did not match
7473 -- either a supplied Parameter_Types or Result_Types argument
7475 if Match then
7476 if No (Ent) then
7477 Ent := Def_Id;
7479 -- Ambiguous case, the flag Ambiguous shows if we already
7480 -- detected this and output the initial messages.
7482 else
7483 if not Ambiguous then
7484 Ambiguous := True;
7485 Error_Msg_Name_1 := Pname;
7486 Error_Msg_N
7487 ("pragma% does not uniquely identify subprogram!",
7489 Error_Msg_Sloc := Sloc (Ent);
7490 Error_Msg_N ("matching subprogram #!", N);
7491 Ent := Empty;
7492 end if;
7494 Error_Msg_Sloc := Sloc (Def_Id);
7495 Error_Msg_N ("matching subprogram #!", N);
7496 end if;
7497 end if;
7498 end if;
7500 Hom_Id := Homonym (Hom_Id);
7501 end loop;
7503 -- See if we found an entry
7505 if No (Ent) then
7506 if not Ambiguous then
7507 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
7508 Error_Pragma
7509 ("pragma% cannot be given for generic subprogram");
7510 else
7511 Error_Pragma
7512 ("pragma% does not identify local subprogram");
7513 end if;
7514 end if;
7516 return;
7517 end if;
7519 -- Import pragmas must be for imported entities
7521 if Prag_Id = Pragma_Import_Function
7522 or else
7523 Prag_Id = Pragma_Import_Procedure
7524 or else
7525 Prag_Id = Pragma_Import_Valued_Procedure
7526 then
7527 if not Is_Imported (Ent) then
7528 Error_Pragma
7529 ("pragma Import or Interface must precede pragma%");
7530 end if;
7532 -- Here we have the Export case which can set the entity as exported
7534 -- But does not do so if the specified external name is null, since
7535 -- that is taken as a signal in DEC Ada 83 (with which we want to be
7536 -- compatible) to request no external name.
7538 elsif Nkind (Arg_External) = N_String_Literal
7539 and then String_Length (Strval (Arg_External)) = 0
7540 then
7541 null;
7543 -- In all other cases, set entity as exported
7545 else
7546 Set_Exported (Ent, Arg_Internal);
7547 end if;
7549 -- Special processing for Valued_Procedure cases
7551 if Prag_Id = Pragma_Import_Valued_Procedure
7552 or else
7553 Prag_Id = Pragma_Export_Valued_Procedure
7554 then
7555 Formal := First_Formal (Ent);
7557 if No (Formal) then
7558 Error_Pragma ("at least one parameter required for pragma%");
7560 elsif Ekind (Formal) /= E_Out_Parameter then
7561 Error_Pragma ("first parameter must have mode out for pragma%");
7563 else
7564 Set_Is_Valued_Procedure (Ent);
7565 end if;
7566 end if;
7568 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
7570 -- Process Result_Mechanism argument if present. We have already
7571 -- checked that this is only allowed for the function case.
7573 if Present (Arg_Result_Mechanism) then
7574 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
7575 end if;
7577 -- Process Mechanism parameter if present. Note that this parameter
7578 -- is not analyzed, and must not be analyzed since it is semantic
7579 -- nonsense, so we get it in exactly as the parser left it.
7581 if Present (Arg_Mechanism) then
7582 declare
7583 Formal : Entity_Id;
7584 Massoc : Node_Id;
7585 Mname : Node_Id;
7586 Choice : Node_Id;
7588 begin
7589 -- A single mechanism association without a formal parameter
7590 -- name is parsed as a parenthesized expression. All other
7591 -- cases are parsed as aggregates, so we rewrite the single
7592 -- parameter case as an aggregate for consistency.
7594 if Nkind (Arg_Mechanism) /= N_Aggregate
7595 and then Paren_Count (Arg_Mechanism) = 1
7596 then
7597 Rewrite (Arg_Mechanism,
7598 Make_Aggregate (Sloc (Arg_Mechanism),
7599 Expressions => New_List (
7600 Relocate_Node (Arg_Mechanism))));
7601 end if;
7603 -- Case of only mechanism name given, applies to all formals
7605 if Nkind (Arg_Mechanism) /= N_Aggregate then
7606 Formal := First_Formal (Ent);
7607 while Present (Formal) loop
7608 Set_Mechanism_Value (Formal, Arg_Mechanism);
7609 Next_Formal (Formal);
7610 end loop;
7612 -- Case of list of mechanism associations given
7614 else
7615 if Null_Record_Present (Arg_Mechanism) then
7616 Error_Pragma_Arg
7617 ("inappropriate form for Mechanism parameter",
7618 Arg_Mechanism);
7619 end if;
7621 -- Deal with positional ones first
7623 Formal := First_Formal (Ent);
7625 if Present (Expressions (Arg_Mechanism)) then
7626 Mname := First (Expressions (Arg_Mechanism));
7627 while Present (Mname) loop
7628 if No (Formal) then
7629 Error_Pragma_Arg
7630 ("too many mechanism associations", Mname);
7631 end if;
7633 Set_Mechanism_Value (Formal, Mname);
7634 Next_Formal (Formal);
7635 Next (Mname);
7636 end loop;
7637 end if;
7639 -- Deal with named entries
7641 if Present (Component_Associations (Arg_Mechanism)) then
7642 Massoc := First (Component_Associations (Arg_Mechanism));
7643 while Present (Massoc) loop
7644 Choice := First (Choices (Massoc));
7646 if Nkind (Choice) /= N_Identifier
7647 or else Present (Next (Choice))
7648 then
7649 Error_Pragma_Arg
7650 ("incorrect form for mechanism association",
7651 Massoc);
7652 end if;
7654 Formal := First_Formal (Ent);
7655 loop
7656 if No (Formal) then
7657 Error_Pragma_Arg
7658 ("parameter name & not present", Choice);
7659 end if;
7661 if Chars (Choice) = Chars (Formal) then
7662 Set_Mechanism_Value
7663 (Formal, Expression (Massoc));
7665 -- Set entity on identifier (needed by ASIS)
7667 Set_Entity (Choice, Formal);
7669 exit;
7670 end if;
7672 Next_Formal (Formal);
7673 end loop;
7675 Next (Massoc);
7676 end loop;
7677 end if;
7678 end if;
7679 end;
7680 end if;
7681 end Process_Extended_Import_Export_Subprogram_Pragma;
7683 --------------------------
7684 -- Process_Generic_List --
7685 --------------------------
7687 procedure Process_Generic_List is
7688 Arg : Node_Id;
7689 Exp : Node_Id;
7691 begin
7692 Check_No_Identifiers;
7693 Check_At_Least_N_Arguments (1);
7695 -- Check all arguments are names of generic units or instances
7697 Arg := Arg1;
7698 while Present (Arg) loop
7699 Exp := Get_Pragma_Arg (Arg);
7700 Analyze (Exp);
7702 if not Is_Entity_Name (Exp)
7703 or else
7704 (not Is_Generic_Instance (Entity (Exp))
7705 and then
7706 not Is_Generic_Unit (Entity (Exp)))
7707 then
7708 Error_Pragma_Arg
7709 ("pragma% argument must be name of generic unit/instance",
7710 Arg);
7711 end if;
7713 Next (Arg);
7714 end loop;
7715 end Process_Generic_List;
7717 ------------------------------------
7718 -- Process_Import_Predefined_Type --
7719 ------------------------------------
7721 procedure Process_Import_Predefined_Type is
7722 Loc : constant Source_Ptr := Sloc (N);
7723 Elmt : Elmt_Id;
7724 Ftyp : Node_Id := Empty;
7725 Decl : Node_Id;
7726 Def : Node_Id;
7727 Nam : Name_Id;
7729 begin
7730 String_To_Name_Buffer (Strval (Expression (Arg3)));
7731 Nam := Name_Find;
7733 Elmt := First_Elmt (Predefined_Float_Types);
7734 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
7735 Next_Elmt (Elmt);
7736 end loop;
7738 Ftyp := Node (Elmt);
7740 if Present (Ftyp) then
7742 -- Don't build a derived type declaration, because predefined C
7743 -- types have no declaration anywhere, so cannot really be named.
7744 -- Instead build a full type declaration, starting with an
7745 -- appropriate type definition is built
7747 if Is_Floating_Point_Type (Ftyp) then
7748 Def := Make_Floating_Point_Definition (Loc,
7749 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
7750 Make_Real_Range_Specification (Loc,
7751 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
7752 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
7754 -- Should never have a predefined type we cannot handle
7756 else
7757 raise Program_Error;
7758 end if;
7760 -- Build and insert a Full_Type_Declaration, which will be
7761 -- analyzed as soon as this list entry has been analyzed.
7763 Decl := Make_Full_Type_Declaration (Loc,
7764 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
7765 Type_Definition => Def);
7767 Insert_After (N, Decl);
7768 Mark_Rewrite_Insertion (Decl);
7770 else
7771 Error_Pragma_Arg ("no matching type found for pragma%",
7772 Arg2);
7773 end if;
7774 end Process_Import_Predefined_Type;
7776 ---------------------------------
7777 -- Process_Import_Or_Interface --
7778 ---------------------------------
7780 procedure Process_Import_Or_Interface is
7781 C : Convention_Id;
7782 Def_Id : Entity_Id;
7783 Hom_Id : Entity_Id;
7785 begin
7786 -- In Relaxed_RM_Semantics, support old Ada 83 style:
7787 -- pragma Import (Entity, "external name");
7789 if Relaxed_RM_Semantics
7790 and then Arg_Count = 2
7791 and then Prag_Id = Pragma_Import
7792 and then Nkind (Expression (Arg2)) = N_String_Literal
7793 then
7794 C := Convention_C;
7795 Def_Id := Get_Pragma_Arg (Arg1);
7796 Analyze (Def_Id);
7798 if not Is_Entity_Name (Def_Id) then
7799 Error_Pragma_Arg ("entity name required", Arg1);
7800 end if;
7802 Def_Id := Entity (Def_Id);
7803 Kill_Size_Check_Code (Def_Id);
7804 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
7806 else
7807 Process_Convention (C, Def_Id);
7808 Kill_Size_Check_Code (Def_Id);
7809 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
7810 end if;
7812 if Ekind_In (Def_Id, E_Variable, E_Constant) then
7814 -- We do not permit Import to apply to a renaming declaration
7816 if Present (Renamed_Object (Def_Id)) then
7817 Error_Pragma_Arg
7818 ("pragma% not allowed for object renaming", Arg2);
7820 -- User initialization is not allowed for imported object, but
7821 -- the object declaration may contain a default initialization,
7822 -- that will be discarded. Note that an explicit initialization
7823 -- only counts if it comes from source, otherwise it is simply
7824 -- the code generator making an implicit initialization explicit.
7826 elsif Present (Expression (Parent (Def_Id)))
7827 and then Comes_From_Source
7828 (Original_Node (Expression (Parent (Def_Id))))
7829 then
7830 -- Set imported flag to prevent cascaded errors
7832 Set_Is_Imported (Def_Id);
7834 Error_Msg_Sloc := Sloc (Def_Id);
7835 Error_Pragma_Arg
7836 ("no initialization allowed for declaration of& #",
7837 "\imported entities cannot be initialized (RM B.1(24))",
7838 Arg2);
7840 else
7841 -- If the pragma comes from an aspect specification the
7842 -- Is_Imported flag has already been set.
7844 if not From_Aspect_Specification (N) then
7845 Set_Imported (Def_Id);
7846 end if;
7848 Process_Interface_Name (Def_Id, Arg3, Arg4);
7850 -- Note that we do not set Is_Public here. That's because we
7851 -- only want to set it if there is no address clause, and we
7852 -- don't know that yet, so we delay that processing till
7853 -- freeze time.
7855 -- pragma Import completes deferred constants
7857 if Ekind (Def_Id) = E_Constant then
7858 Set_Has_Completion (Def_Id);
7859 end if;
7861 -- It is not possible to import a constant of an unconstrained
7862 -- array type (e.g. string) because there is no simple way to
7863 -- write a meaningful subtype for it.
7865 if Is_Array_Type (Etype (Def_Id))
7866 and then not Is_Constrained (Etype (Def_Id))
7867 then
7868 Error_Msg_NE
7869 ("imported constant& must have a constrained subtype",
7870 N, Def_Id);
7871 end if;
7872 end if;
7874 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
7876 -- If the name is overloaded, pragma applies to all of the denoted
7877 -- entities in the same declarative part, unless the pragma comes
7878 -- from an aspect specification or was generated by the compiler
7879 -- (such as for pragma Provide_Shift_Operators).
7881 Hom_Id := Def_Id;
7882 while Present (Hom_Id) loop
7884 Def_Id := Get_Base_Subprogram (Hom_Id);
7886 -- Ignore inherited subprograms because the pragma will apply
7887 -- to the parent operation, which is the one called.
7889 if Is_Overloadable (Def_Id)
7890 and then Present (Alias (Def_Id))
7891 then
7892 null;
7894 -- If it is not a subprogram, it must be in an outer scope and
7895 -- pragma does not apply.
7897 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
7898 null;
7900 -- The pragma does not apply to primitives of interfaces
7902 elsif Is_Dispatching_Operation (Def_Id)
7903 and then Present (Find_Dispatching_Type (Def_Id))
7904 and then Is_Interface (Find_Dispatching_Type (Def_Id))
7905 then
7906 null;
7908 -- Verify that the homonym is in the same declarative part (not
7909 -- just the same scope). If the pragma comes from an aspect
7910 -- specification we know that it is part of the declaration.
7912 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
7913 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
7914 and then not From_Aspect_Specification (N)
7915 then
7916 exit;
7918 else
7919 -- If the pragma comes from an aspect specification the
7920 -- Is_Imported flag has already been set.
7922 if not From_Aspect_Specification (N) then
7923 Set_Imported (Def_Id);
7924 end if;
7926 -- Reject an Import applied to an abstract subprogram
7928 if Is_Subprogram (Def_Id)
7929 and then Is_Abstract_Subprogram (Def_Id)
7930 then
7931 Error_Msg_Sloc := Sloc (Def_Id);
7932 Error_Msg_NE
7933 ("cannot import abstract subprogram& declared#",
7934 Arg2, Def_Id);
7935 end if;
7937 -- Special processing for Convention_Intrinsic
7939 if C = Convention_Intrinsic then
7941 -- Link_Name argument not allowed for intrinsic
7943 Check_No_Link_Name;
7945 Set_Is_Intrinsic_Subprogram (Def_Id);
7947 -- If no external name is present, then check that this
7948 -- is a valid intrinsic subprogram. If an external name
7949 -- is present, then this is handled by the back end.
7951 if No (Arg3) then
7952 Check_Intrinsic_Subprogram
7953 (Def_Id, Get_Pragma_Arg (Arg2));
7954 end if;
7955 end if;
7957 -- Verify that the subprogram does not have a completion
7958 -- through a renaming declaration. For other completions the
7959 -- pragma appears as a too late representation.
7961 declare
7962 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
7964 begin
7965 if Present (Decl)
7966 and then Nkind (Decl) = N_Subprogram_Declaration
7967 and then Present (Corresponding_Body (Decl))
7968 and then Nkind (Unit_Declaration_Node
7969 (Corresponding_Body (Decl))) =
7970 N_Subprogram_Renaming_Declaration
7971 then
7972 Error_Msg_Sloc := Sloc (Def_Id);
7973 Error_Msg_NE
7974 ("cannot import&, renaming already provided for "
7975 & "declaration #", N, Def_Id);
7976 end if;
7977 end;
7979 -- If the pragma comes from an aspect specification, there
7980 -- must be an Import aspect specified as well. In the rare
7981 -- case where Import is set to False, the suprogram needs to
7982 -- have a local completion.
7984 declare
7985 Imp_Aspect : constant Node_Id :=
7986 Find_Aspect (Def_Id, Aspect_Import);
7987 Expr : Node_Id;
7989 begin
7990 if Present (Imp_Aspect)
7991 and then Present (Expression (Imp_Aspect))
7992 then
7993 Expr := Expression (Imp_Aspect);
7994 Analyze_And_Resolve (Expr, Standard_Boolean);
7996 if Is_Entity_Name (Expr)
7997 and then Entity (Expr) = Standard_True
7998 then
7999 Set_Has_Completion (Def_Id);
8000 end if;
8002 -- If there is no expression, the default is True, as for
8003 -- all boolean aspects. Same for the older pragma.
8005 else
8006 Set_Has_Completion (Def_Id);
8007 end if;
8008 end;
8010 Process_Interface_Name (Def_Id, Arg3, Arg4);
8011 end if;
8013 if Is_Compilation_Unit (Hom_Id) then
8015 -- Its possible homonyms are not affected by the pragma.
8016 -- Such homonyms might be present in the context of other
8017 -- units being compiled.
8019 exit;
8021 elsif From_Aspect_Specification (N) then
8022 exit;
8024 -- If the pragma was created by the compiler, then we don't
8025 -- want it to apply to other homonyms. This kind of case can
8026 -- occur when using pragma Provide_Shift_Operators, which
8027 -- generates implicit shift and rotate operators with Import
8028 -- pragmas that might apply to earlier explicit or implicit
8029 -- declarations marked with Import (for example, coming from
8030 -- an earlier pragma Provide_Shift_Operators for another type),
8031 -- and we don't generally want other homonyms being treated
8032 -- as imported or the pragma flagged as an illegal duplicate.
8034 elsif not Comes_From_Source (N) then
8035 exit;
8037 else
8038 Hom_Id := Homonym (Hom_Id);
8039 end if;
8040 end loop;
8042 -- When the convention is Java or CIL, we also allow Import to
8043 -- be given for packages, generic packages, exceptions, record
8044 -- components, and access to subprograms.
8046 elsif (C = Convention_Java or else C = Convention_CIL)
8047 and then
8048 (Is_Package_Or_Generic_Package (Def_Id)
8049 or else Ekind (Def_Id) = E_Exception
8050 or else Ekind (Def_Id) = E_Access_Subprogram_Type
8051 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
8052 then
8053 Set_Imported (Def_Id);
8054 Set_Is_Public (Def_Id);
8055 Process_Interface_Name (Def_Id, Arg3, Arg4);
8057 -- Import a CPP class
8059 elsif C = Convention_CPP
8060 and then (Is_Record_Type (Def_Id)
8061 or else Ekind (Def_Id) = E_Incomplete_Type)
8062 then
8063 if Ekind (Def_Id) = E_Incomplete_Type then
8064 if Present (Full_View (Def_Id)) then
8065 Def_Id := Full_View (Def_Id);
8067 else
8068 Error_Msg_N
8069 ("cannot import 'C'P'P type before full declaration seen",
8070 Get_Pragma_Arg (Arg2));
8072 -- Although we have reported the error we decorate it as
8073 -- CPP_Class to avoid reporting spurious errors
8075 Set_Is_CPP_Class (Def_Id);
8076 return;
8077 end if;
8078 end if;
8080 -- Types treated as CPP classes must be declared limited (note:
8081 -- this used to be a warning but there is no real benefit to it
8082 -- since we did effectively intend to treat the type as limited
8083 -- anyway).
8085 if not Is_Limited_Type (Def_Id) then
8086 Error_Msg_N
8087 ("imported 'C'P'P type must be limited",
8088 Get_Pragma_Arg (Arg2));
8089 end if;
8091 if Etype (Def_Id) /= Def_Id
8092 and then not Is_CPP_Class (Root_Type (Def_Id))
8093 then
8094 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
8095 end if;
8097 Set_Is_CPP_Class (Def_Id);
8099 -- Imported CPP types must not have discriminants (because C++
8100 -- classes do not have discriminants).
8102 if Has_Discriminants (Def_Id) then
8103 Error_Msg_N
8104 ("imported 'C'P'P type cannot have discriminants",
8105 First (Discriminant_Specifications
8106 (Declaration_Node (Def_Id))));
8107 end if;
8109 -- Check that components of imported CPP types do not have default
8110 -- expressions. For private types this check is performed when the
8111 -- full view is analyzed (see Process_Full_View).
8113 if not Is_Private_Type (Def_Id) then
8114 Check_CPP_Type_Has_No_Defaults (Def_Id);
8115 end if;
8117 -- Import a CPP exception
8119 elsif C = Convention_CPP
8120 and then Ekind (Def_Id) = E_Exception
8121 then
8122 if No (Arg3) then
8123 Error_Pragma_Arg
8124 ("'External_'Name arguments is required for 'Cpp exception",
8125 Arg3);
8126 else
8127 -- As only a string is allowed, Check_Arg_Is_External_Name
8128 -- isn't called.
8130 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8131 end if;
8133 if Present (Arg4) then
8134 Error_Pragma_Arg
8135 ("Link_Name argument not allowed for imported Cpp exception",
8136 Arg4);
8137 end if;
8139 -- Do not call Set_Interface_Name as the name of the exception
8140 -- shouldn't be modified (and in particular it shouldn't be
8141 -- the External_Name). For exceptions, the External_Name is the
8142 -- name of the RTTI structure.
8144 -- ??? Emit an error if pragma Import/Export_Exception is present
8146 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
8147 Check_No_Link_Name;
8148 Check_Arg_Count (3);
8149 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8151 Process_Import_Predefined_Type;
8153 else
8154 Error_Pragma_Arg
8155 ("second argument of pragma% must be object, subprogram "
8156 & "or incomplete type",
8157 Arg2);
8158 end if;
8160 -- If this pragma applies to a compilation unit, then the unit, which
8161 -- is a subprogram, does not require (or allow) a body. We also do
8162 -- not need to elaborate imported procedures.
8164 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
8165 declare
8166 Cunit : constant Node_Id := Parent (Parent (N));
8167 begin
8168 Set_Body_Required (Cunit, False);
8169 end;
8170 end if;
8171 end Process_Import_Or_Interface;
8173 --------------------
8174 -- Process_Inline --
8175 --------------------
8177 procedure Process_Inline (Status : Inline_Status) is
8178 Assoc : Node_Id;
8179 Decl : Node_Id;
8180 Subp_Id : Node_Id;
8181 Subp : Entity_Id;
8182 Applies : Boolean;
8184 Effective : Boolean := False;
8185 -- Set True if inline has some effect, i.e. if there is at least one
8186 -- subprogram set as inlined as a result of the use of the pragma.
8188 procedure Make_Inline (Subp : Entity_Id);
8189 -- Subp is the defining unit name of the subprogram declaration. Set
8190 -- the flag, as well as the flag in the corresponding body, if there
8191 -- is one present.
8193 procedure Set_Inline_Flags (Subp : Entity_Id);
8194 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
8195 -- Has_Pragma_Inline_Always for the Inline_Always case.
8197 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
8198 -- Returns True if it can be determined at this stage that inlining
8199 -- is not possible, for example if the body is available and contains
8200 -- exception handlers, we prevent inlining, since otherwise we can
8201 -- get undefined symbols at link time. This function also emits a
8202 -- warning if front-end inlining is enabled and the pragma appears
8203 -- too late.
8205 -- ??? is business with link symbols still valid, or does it relate
8206 -- to front end ZCX which is being phased out ???
8208 ---------------------------
8209 -- Inlining_Not_Possible --
8210 ---------------------------
8212 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
8213 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
8214 Stats : Node_Id;
8216 begin
8217 if Nkind (Decl) = N_Subprogram_Body then
8218 Stats := Handled_Statement_Sequence (Decl);
8219 return Present (Exception_Handlers (Stats))
8220 or else Present (At_End_Proc (Stats));
8222 elsif Nkind (Decl) = N_Subprogram_Declaration
8223 and then Present (Corresponding_Body (Decl))
8224 then
8225 if Front_End_Inlining
8226 and then Analyzed (Corresponding_Body (Decl))
8227 then
8228 Error_Msg_N ("pragma appears too late, ignored??", N);
8229 return True;
8231 -- If the subprogram is a renaming as body, the body is just a
8232 -- call to the renamed subprogram, and inlining is trivially
8233 -- possible.
8235 elsif
8236 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
8237 N_Subprogram_Renaming_Declaration
8238 then
8239 return False;
8241 else
8242 Stats :=
8243 Handled_Statement_Sequence
8244 (Unit_Declaration_Node (Corresponding_Body (Decl)));
8246 return
8247 Present (Exception_Handlers (Stats))
8248 or else Present (At_End_Proc (Stats));
8249 end if;
8251 else
8252 -- If body is not available, assume the best, the check is
8253 -- performed again when compiling enclosing package bodies.
8255 return False;
8256 end if;
8257 end Inlining_Not_Possible;
8259 -----------------
8260 -- Make_Inline --
8261 -----------------
8263 procedure Make_Inline (Subp : Entity_Id) is
8264 Kind : constant Entity_Kind := Ekind (Subp);
8265 Inner_Subp : Entity_Id := Subp;
8267 begin
8268 -- Ignore if bad type, avoid cascaded error
8270 if Etype (Subp) = Any_Type then
8271 Applies := True;
8272 return;
8274 -- Ignore if all inlining is suppressed
8276 elsif Suppress_All_Inlining then
8277 Applies := True;
8278 return;
8280 -- If inlining is not possible, for now do not treat as an error
8282 elsif Status /= Suppressed
8283 and then Inlining_Not_Possible (Subp)
8284 then
8285 Applies := True;
8286 return;
8288 -- Here we have a candidate for inlining, but we must exclude
8289 -- derived operations. Otherwise we would end up trying to inline
8290 -- a phantom declaration, and the result would be to drag in a
8291 -- body which has no direct inlining associated with it. That
8292 -- would not only be inefficient but would also result in the
8293 -- backend doing cross-unit inlining in cases where it was
8294 -- definitely inappropriate to do so.
8296 -- However, a simple Comes_From_Source test is insufficient, since
8297 -- we do want to allow inlining of generic instances which also do
8298 -- not come from source. We also need to recognize specs generated
8299 -- by the front-end for bodies that carry the pragma. Finally,
8300 -- predefined operators do not come from source but are not
8301 -- inlineable either.
8303 elsif Is_Generic_Instance (Subp)
8304 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
8305 then
8306 null;
8308 elsif not Comes_From_Source (Subp)
8309 and then Scope (Subp) /= Standard_Standard
8310 then
8311 Applies := True;
8312 return;
8313 end if;
8315 -- The referenced entity must either be the enclosing entity, or
8316 -- an entity declared within the current open scope.
8318 if Present (Scope (Subp))
8319 and then Scope (Subp) /= Current_Scope
8320 and then Subp /= Current_Scope
8321 then
8322 Error_Pragma_Arg
8323 ("argument of% must be entity in current scope", Assoc);
8324 return;
8325 end if;
8327 -- Processing for procedure, operator or function. If subprogram
8328 -- is aliased (as for an instance) indicate that the renamed
8329 -- entity (if declared in the same unit) is inlined.
8331 if Is_Subprogram (Subp) then
8332 Inner_Subp := Ultimate_Alias (Inner_Subp);
8334 if In_Same_Source_Unit (Subp, Inner_Subp) then
8335 Set_Inline_Flags (Inner_Subp);
8337 Decl := Parent (Parent (Inner_Subp));
8339 if Nkind (Decl) = N_Subprogram_Declaration
8340 and then Present (Corresponding_Body (Decl))
8341 then
8342 Set_Inline_Flags (Corresponding_Body (Decl));
8344 elsif Is_Generic_Instance (Subp) then
8346 -- Indicate that the body needs to be created for
8347 -- inlining subsequent calls. The instantiation node
8348 -- follows the declaration of the wrapper package
8349 -- created for it.
8351 if Scope (Subp) /= Standard_Standard
8352 and then
8353 Need_Subprogram_Instance_Body
8354 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
8355 Subp)
8356 then
8357 null;
8358 end if;
8360 -- Inline is a program unit pragma (RM 10.1.5) and cannot
8361 -- appear in a formal part to apply to a formal subprogram.
8362 -- Do not apply check within an instance or a formal package
8363 -- the test will have been applied to the original generic.
8365 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
8366 and then List_Containing (Decl) = List_Containing (N)
8367 and then not In_Instance
8368 then
8369 Error_Msg_N
8370 ("Inline cannot apply to a formal subprogram", N);
8372 -- If Subp is a renaming, it is the renamed entity that
8373 -- will appear in any call, and be inlined. However, for
8374 -- ASIS uses it is convenient to indicate that the renaming
8375 -- itself is an inlined subprogram, so that some gnatcheck
8376 -- rules can be applied in the absence of expansion.
8378 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
8379 Set_Inline_Flags (Subp);
8380 end if;
8381 end if;
8383 Applies := True;
8385 -- For a generic subprogram set flag as well, for use at the point
8386 -- of instantiation, to determine whether the body should be
8387 -- generated.
8389 elsif Is_Generic_Subprogram (Subp) then
8390 Set_Inline_Flags (Subp);
8391 Applies := True;
8393 -- Literals are by definition inlined
8395 elsif Kind = E_Enumeration_Literal then
8396 null;
8398 -- Anything else is an error
8400 else
8401 Error_Pragma_Arg
8402 ("expect subprogram name for pragma%", Assoc);
8403 end if;
8404 end Make_Inline;
8406 ----------------------
8407 -- Set_Inline_Flags --
8408 ----------------------
8410 procedure Set_Inline_Flags (Subp : Entity_Id) is
8411 begin
8412 -- First set the Has_Pragma_XXX flags and issue the appropriate
8413 -- errors and warnings for suspicious combinations.
8415 if Prag_Id = Pragma_No_Inline then
8416 if Has_Pragma_Inline_Always (Subp) then
8417 Error_Msg_N
8418 ("Inline_Always and No_Inline are mutually exclusive", N);
8419 elsif Has_Pragma_Inline (Subp) then
8420 Error_Msg_NE
8421 ("Inline and No_Inline both specified for& ??",
8422 N, Entity (Subp_Id));
8423 end if;
8425 Set_Has_Pragma_No_Inline (Subp);
8426 else
8427 if Prag_Id = Pragma_Inline_Always then
8428 if Has_Pragma_No_Inline (Subp) then
8429 Error_Msg_N
8430 ("Inline_Always and No_Inline are mutually exclusive",
8432 end if;
8434 Set_Has_Pragma_Inline_Always (Subp);
8435 else
8436 if Has_Pragma_No_Inline (Subp) then
8437 Error_Msg_NE
8438 ("Inline and No_Inline both specified for& ??",
8439 N, Entity (Subp_Id));
8440 end if;
8441 end if;
8443 if not Has_Pragma_Inline (Subp) then
8444 Set_Has_Pragma_Inline (Subp);
8445 Effective := True;
8446 end if;
8447 end if;
8449 -- Then adjust the Is_Inlined flag. It can never be set if the
8450 -- subprogram is subject to pragma No_Inline.
8452 case Status is
8453 when Suppressed =>
8454 Set_Is_Inlined (Subp, False);
8455 when Disabled =>
8456 null;
8457 when Enabled =>
8458 if not Has_Pragma_No_Inline (Subp) then
8459 Set_Is_Inlined (Subp, True);
8460 end if;
8461 end case;
8462 end Set_Inline_Flags;
8464 -- Start of processing for Process_Inline
8466 begin
8467 Check_No_Identifiers;
8468 Check_At_Least_N_Arguments (1);
8470 if Status = Enabled then
8471 Inline_Processing_Required := True;
8472 end if;
8474 Assoc := Arg1;
8475 while Present (Assoc) loop
8476 Subp_Id := Get_Pragma_Arg (Assoc);
8477 Analyze (Subp_Id);
8478 Applies := False;
8480 if Is_Entity_Name (Subp_Id) then
8481 Subp := Entity (Subp_Id);
8483 if Subp = Any_Id then
8485 -- If previous error, avoid cascaded errors
8487 Check_Error_Detected;
8488 Applies := True;
8489 Effective := True;
8491 else
8492 Make_Inline (Subp);
8494 -- For the pragma case, climb homonym chain. This is
8495 -- what implements allowing the pragma in the renaming
8496 -- case, with the result applying to the ancestors, and
8497 -- also allows Inline to apply to all previous homonyms.
8499 if not From_Aspect_Specification (N) then
8500 while Present (Homonym (Subp))
8501 and then Scope (Homonym (Subp)) = Current_Scope
8502 loop
8503 Make_Inline (Homonym (Subp));
8504 Subp := Homonym (Subp);
8505 end loop;
8506 end if;
8507 end if;
8508 end if;
8510 if not Applies then
8511 Error_Pragma_Arg
8512 ("inappropriate argument for pragma%", Assoc);
8514 elsif not Effective
8515 and then Warn_On_Redundant_Constructs
8516 and then not (Status = Suppressed or else Suppress_All_Inlining)
8517 then
8518 if Inlining_Not_Possible (Subp) then
8519 Error_Msg_NE
8520 ("pragma Inline for& is ignored?r?",
8521 N, Entity (Subp_Id));
8522 else
8523 Error_Msg_NE
8524 ("pragma Inline for& is redundant?r?",
8525 N, Entity (Subp_Id));
8526 end if;
8527 end if;
8529 Next (Assoc);
8530 end loop;
8531 end Process_Inline;
8533 ----------------------------
8534 -- Process_Interface_Name --
8535 ----------------------------
8537 procedure Process_Interface_Name
8538 (Subprogram_Def : Entity_Id;
8539 Ext_Arg : Node_Id;
8540 Link_Arg : Node_Id)
8542 Ext_Nam : Node_Id;
8543 Link_Nam : Node_Id;
8544 String_Val : String_Id;
8546 procedure Check_Form_Of_Interface_Name
8547 (SN : Node_Id;
8548 Ext_Name_Case : Boolean);
8549 -- SN is a string literal node for an interface name. This routine
8550 -- performs some minimal checks that the name is reasonable. In
8551 -- particular that no spaces or other obviously incorrect characters
8552 -- appear. This is only a warning, since any characters are allowed.
8553 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
8555 ----------------------------------
8556 -- Check_Form_Of_Interface_Name --
8557 ----------------------------------
8559 procedure Check_Form_Of_Interface_Name
8560 (SN : Node_Id;
8561 Ext_Name_Case : Boolean)
8563 S : constant String_Id := Strval (Expr_Value_S (SN));
8564 SL : constant Nat := String_Length (S);
8565 C : Char_Code;
8567 begin
8568 if SL = 0 then
8569 Error_Msg_N ("interface name cannot be null string", SN);
8570 end if;
8572 for J in 1 .. SL loop
8573 C := Get_String_Char (S, J);
8575 -- Look for dubious character and issue unconditional warning.
8576 -- Definitely dubious if not in character range.
8578 if not In_Character_Range (C)
8580 -- For all cases except CLI target,
8581 -- commas, spaces and slashes are dubious (in CLI, we use
8582 -- commas and backslashes in external names to specify
8583 -- assembly version and public key, while slashes and spaces
8584 -- can be used in names to mark nested classes and
8585 -- valuetypes).
8587 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
8588 and then (Get_Character (C) = ','
8589 or else
8590 Get_Character (C) = '\'))
8591 or else (VM_Target /= CLI_Target
8592 and then (Get_Character (C) = ' '
8593 or else
8594 Get_Character (C) = '/'))
8595 then
8596 Error_Msg
8597 ("??interface name contains illegal character",
8598 Sloc (SN) + Source_Ptr (J));
8599 end if;
8600 end loop;
8601 end Check_Form_Of_Interface_Name;
8603 -- Start of processing for Process_Interface_Name
8605 begin
8606 if No (Link_Arg) then
8607 if No (Ext_Arg) then
8608 if VM_Target = CLI_Target
8609 and then Ekind (Subprogram_Def) = E_Package
8610 and then Nkind (Parent (Subprogram_Def)) =
8611 N_Package_Specification
8612 and then Present (Generic_Parent (Parent (Subprogram_Def)))
8613 then
8614 Set_Interface_Name
8615 (Subprogram_Def,
8616 Interface_Name
8617 (Generic_Parent (Parent (Subprogram_Def))));
8618 end if;
8620 return;
8622 elsif Chars (Ext_Arg) = Name_Link_Name then
8623 Ext_Nam := Empty;
8624 Link_Nam := Expression (Ext_Arg);
8626 else
8627 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
8628 Ext_Nam := Expression (Ext_Arg);
8629 Link_Nam := Empty;
8630 end if;
8632 else
8633 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
8634 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
8635 Ext_Nam := Expression (Ext_Arg);
8636 Link_Nam := Expression (Link_Arg);
8637 end if;
8639 -- Check expressions for external name and link name are static
8641 if Present (Ext_Nam) then
8642 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
8643 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
8645 -- Verify that external name is not the name of a local entity,
8646 -- which would hide the imported one and could lead to run-time
8647 -- surprises. The problem can only arise for entities declared in
8648 -- a package body (otherwise the external name is fully qualified
8649 -- and will not conflict).
8651 declare
8652 Nam : Name_Id;
8653 E : Entity_Id;
8654 Par : Node_Id;
8656 begin
8657 if Prag_Id = Pragma_Import then
8658 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
8659 Nam := Name_Find;
8660 E := Entity_Id (Get_Name_Table_Info (Nam));
8662 if Nam /= Chars (Subprogram_Def)
8663 and then Present (E)
8664 and then not Is_Overloadable (E)
8665 and then Is_Immediately_Visible (E)
8666 and then not Is_Imported (E)
8667 and then Ekind (Scope (E)) = E_Package
8668 then
8669 Par := Parent (E);
8670 while Present (Par) loop
8671 if Nkind (Par) = N_Package_Body then
8672 Error_Msg_Sloc := Sloc (E);
8673 Error_Msg_NE
8674 ("imported entity is hidden by & declared#",
8675 Ext_Arg, E);
8676 exit;
8677 end if;
8679 Par := Parent (Par);
8680 end loop;
8681 end if;
8682 end if;
8683 end;
8684 end if;
8686 if Present (Link_Nam) then
8687 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
8688 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
8689 end if;
8691 -- If there is no link name, just set the external name
8693 if No (Link_Nam) then
8694 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
8696 -- For the Link_Name case, the given literal is preceded by an
8697 -- asterisk, which indicates to GCC that the given name should be
8698 -- taken literally, and in particular that no prepending of
8699 -- underlines should occur, even in systems where this is the
8700 -- normal default.
8702 else
8703 Start_String;
8705 if VM_Target = No_VM then
8706 Store_String_Char (Get_Char_Code ('*'));
8707 end if;
8709 String_Val := Strval (Expr_Value_S (Link_Nam));
8710 Store_String_Chars (String_Val);
8711 Link_Nam :=
8712 Make_String_Literal (Sloc (Link_Nam),
8713 Strval => End_String);
8714 end if;
8716 -- Set the interface name. If the entity is a generic instance, use
8717 -- its alias, which is the callable entity.
8719 if Is_Generic_Instance (Subprogram_Def) then
8720 Set_Encoded_Interface_Name
8721 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
8722 else
8723 Set_Encoded_Interface_Name
8724 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
8725 end if;
8727 -- We allow duplicated export names in CIL/Java, as they are always
8728 -- enclosed in a namespace that differentiates them, and overloaded
8729 -- entities are supported by the VM.
8731 if Convention (Subprogram_Def) /= Convention_CIL
8732 and then
8733 Convention (Subprogram_Def) /= Convention_Java
8734 then
8735 Check_Duplicated_Export_Name (Link_Nam);
8736 end if;
8737 end Process_Interface_Name;
8739 -----------------------------------------
8740 -- Process_Interrupt_Or_Attach_Handler --
8741 -----------------------------------------
8743 procedure Process_Interrupt_Or_Attach_Handler is
8744 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
8745 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
8746 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
8748 begin
8749 Set_Is_Interrupt_Handler (Handler_Proc);
8751 -- If the pragma is not associated with a handler procedure within a
8752 -- protected type, then it must be for a nonprotected procedure for
8753 -- the AAMP target, in which case we don't associate a representation
8754 -- item with the procedure's scope.
8756 if Ekind (Proc_Scope) = E_Protected_Type then
8757 if Prag_Id = Pragma_Interrupt_Handler
8758 or else
8759 Prag_Id = Pragma_Attach_Handler
8760 then
8761 Record_Rep_Item (Proc_Scope, N);
8762 end if;
8763 end if;
8764 end Process_Interrupt_Or_Attach_Handler;
8766 --------------------------------------------------
8767 -- Process_Restrictions_Or_Restriction_Warnings --
8768 --------------------------------------------------
8770 -- Note: some of the simple identifier cases were handled in par-prag,
8771 -- but it is harmless (and more straightforward) to simply handle all
8772 -- cases here, even if it means we repeat a bit of work in some cases.
8774 procedure Process_Restrictions_Or_Restriction_Warnings
8775 (Warn : Boolean)
8777 Arg : Node_Id;
8778 R_Id : Restriction_Id;
8779 Id : Name_Id;
8780 Expr : Node_Id;
8781 Val : Uint;
8783 begin
8784 -- Ignore all Restrictions pragmas in CodePeer mode
8786 if CodePeer_Mode then
8787 return;
8788 end if;
8790 Check_Ada_83_Warning;
8791 Check_At_Least_N_Arguments (1);
8792 Check_Valid_Configuration_Pragma;
8794 Arg := Arg1;
8795 while Present (Arg) loop
8796 Id := Chars (Arg);
8797 Expr := Get_Pragma_Arg (Arg);
8799 -- Case of no restriction identifier present
8801 if Id = No_Name then
8802 if Nkind (Expr) /= N_Identifier then
8803 Error_Pragma_Arg
8804 ("invalid form for restriction", Arg);
8805 end if;
8807 R_Id :=
8808 Get_Restriction_Id
8809 (Process_Restriction_Synonyms (Expr));
8811 if R_Id not in All_Boolean_Restrictions then
8812 Error_Msg_Name_1 := Pname;
8813 Error_Msg_N
8814 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
8816 -- Check for possible misspelling
8818 for J in Restriction_Id loop
8819 declare
8820 Rnm : constant String := Restriction_Id'Image (J);
8822 begin
8823 Name_Buffer (1 .. Rnm'Length) := Rnm;
8824 Name_Len := Rnm'Length;
8825 Set_Casing (All_Lower_Case);
8827 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
8828 Set_Casing
8829 (Identifier_Casing (Current_Source_File));
8830 Error_Msg_String (1 .. Rnm'Length) :=
8831 Name_Buffer (1 .. Name_Len);
8832 Error_Msg_Strlen := Rnm'Length;
8833 Error_Msg_N -- CODEFIX
8834 ("\possible misspelling of ""~""",
8835 Get_Pragma_Arg (Arg));
8836 exit;
8837 end if;
8838 end;
8839 end loop;
8841 raise Pragma_Exit;
8842 end if;
8844 if Implementation_Restriction (R_Id) then
8845 Check_Restriction (No_Implementation_Restrictions, Arg);
8846 end if;
8848 -- Special processing for No_Elaboration_Code restriction
8850 if R_Id = No_Elaboration_Code then
8852 -- Restriction is only recognized within a configuration
8853 -- pragma file, or within a unit of the main extended
8854 -- program. Note: the test for Main_Unit is needed to
8855 -- properly include the case of configuration pragma files.
8857 if not (Current_Sem_Unit = Main_Unit
8858 or else In_Extended_Main_Source_Unit (N))
8859 then
8860 return;
8862 -- Don't allow in a subunit unless already specified in
8863 -- body or spec.
8865 elsif Nkind (Parent (N)) = N_Compilation_Unit
8866 and then Nkind (Unit (Parent (N))) = N_Subunit
8867 and then not Restriction_Active (No_Elaboration_Code)
8868 then
8869 Error_Msg_N
8870 ("invalid specification of ""No_Elaboration_Code""",
8872 Error_Msg_N
8873 ("\restriction cannot be specified in a subunit", N);
8874 Error_Msg_N
8875 ("\unless also specified in body or spec", N);
8876 return;
8878 -- If we accept a No_Elaboration_Code restriction, then it
8879 -- needs to be added to the configuration restriction set so
8880 -- that we get proper application to other units in the main
8881 -- extended source as required.
8883 else
8884 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
8885 end if;
8886 end if;
8888 -- If this is a warning, then set the warning unless we already
8889 -- have a real restriction active (we never want a warning to
8890 -- override a real restriction).
8892 if Warn then
8893 if not Restriction_Active (R_Id) then
8894 Set_Restriction (R_Id, N);
8895 Restriction_Warnings (R_Id) := True;
8896 end if;
8898 -- If real restriction case, then set it and make sure that the
8899 -- restriction warning flag is off, since a real restriction
8900 -- always overrides a warning.
8902 else
8903 Set_Restriction (R_Id, N);
8904 Restriction_Warnings (R_Id) := False;
8905 end if;
8907 -- Check for obsolescent restrictions in Ada 2005 mode
8909 if not Warn
8910 and then Ada_Version >= Ada_2005
8911 and then (R_Id = No_Asynchronous_Control
8912 or else
8913 R_Id = No_Unchecked_Deallocation
8914 or else
8915 R_Id = No_Unchecked_Conversion)
8916 then
8917 Check_Restriction (No_Obsolescent_Features, N);
8918 end if;
8920 -- A very special case that must be processed here: pragma
8921 -- Restrictions (No_Exceptions) turns off all run-time
8922 -- checking. This is a bit dubious in terms of the formal
8923 -- language definition, but it is what is intended by RM
8924 -- H.4(12). Restriction_Warnings never affects generated code
8925 -- so this is done only in the real restriction case.
8927 -- Atomic_Synchronization is not a real check, so it is not
8928 -- affected by this processing).
8930 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
8931 -- run-time checks in CodePeer and GNATprove modes: we want to
8932 -- generate checks for analysis purposes, as set respectively
8933 -- by -gnatC and -gnatd.F
8935 if not Warn
8936 and then not (CodePeer_Mode or GNATprove_Mode)
8937 and then R_Id = No_Exceptions
8938 then
8939 for J in Scope_Suppress.Suppress'Range loop
8940 if J /= Atomic_Synchronization then
8941 Scope_Suppress.Suppress (J) := True;
8942 end if;
8943 end loop;
8944 end if;
8946 -- Case of No_Dependence => unit-name. Note that the parser
8947 -- already made the necessary entry in the No_Dependence table.
8949 elsif Id = Name_No_Dependence then
8950 if not OK_No_Dependence_Unit_Name (Expr) then
8951 raise Pragma_Exit;
8952 end if;
8954 -- Case of No_Specification_Of_Aspect => Identifier.
8956 elsif Id = Name_No_Specification_Of_Aspect then
8957 declare
8958 A_Id : Aspect_Id;
8960 begin
8961 if Nkind (Expr) /= N_Identifier then
8962 A_Id := No_Aspect;
8963 else
8964 A_Id := Get_Aspect_Id (Chars (Expr));
8965 end if;
8967 if A_Id = No_Aspect then
8968 Error_Pragma_Arg ("invalid restriction name", Arg);
8969 else
8970 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
8971 end if;
8972 end;
8974 elsif Id = Name_No_Use_Of_Attribute then
8975 if Nkind (Expr) /= N_Identifier
8976 or else not Is_Attribute_Name (Chars (Expr))
8977 then
8978 Error_Msg_N ("unknown attribute name??", Expr);
8980 else
8981 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
8982 end if;
8984 elsif Id = Name_No_Use_Of_Pragma then
8985 if Nkind (Expr) /= N_Identifier
8986 or else not Is_Pragma_Name (Chars (Expr))
8987 then
8988 Error_Msg_N ("unknown pragma name??", Expr);
8990 else
8991 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
8992 end if;
8994 -- All other cases of restriction identifier present
8996 else
8997 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
8998 Analyze_And_Resolve (Expr, Any_Integer);
9000 if R_Id not in All_Parameter_Restrictions then
9001 Error_Pragma_Arg
9002 ("invalid restriction parameter identifier", Arg);
9004 elsif not Is_OK_Static_Expression (Expr) then
9005 Flag_Non_Static_Expr
9006 ("value must be static expression!", Expr);
9007 raise Pragma_Exit;
9009 elsif not Is_Integer_Type (Etype (Expr))
9010 or else Expr_Value (Expr) < 0
9011 then
9012 Error_Pragma_Arg
9013 ("value must be non-negative integer", Arg);
9014 end if;
9016 -- Restriction pragma is active
9018 Val := Expr_Value (Expr);
9020 if not UI_Is_In_Int_Range (Val) then
9021 Error_Pragma_Arg
9022 ("pragma ignored, value too large??", Arg);
9023 end if;
9025 -- Warning case. If the real restriction is active, then we
9026 -- ignore the request, since warning never overrides a real
9027 -- restriction. Otherwise we set the proper warning. Note that
9028 -- this circuit sets the warning again if it is already set,
9029 -- which is what we want, since the constant may have changed.
9031 if Warn then
9032 if not Restriction_Active (R_Id) then
9033 Set_Restriction
9034 (R_Id, N, Integer (UI_To_Int (Val)));
9035 Restriction_Warnings (R_Id) := True;
9036 end if;
9038 -- Real restriction case, set restriction and make sure warning
9039 -- flag is off since real restriction always overrides warning.
9041 else
9042 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
9043 Restriction_Warnings (R_Id) := False;
9044 end if;
9045 end if;
9047 Next (Arg);
9048 end loop;
9049 end Process_Restrictions_Or_Restriction_Warnings;
9051 ---------------------------------
9052 -- Process_Suppress_Unsuppress --
9053 ---------------------------------
9055 -- Note: this procedure makes entries in the check suppress data
9056 -- structures managed by Sem. See spec of package Sem for full
9057 -- details on how we handle recording of check suppression.
9059 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
9060 C : Check_Id;
9061 E_Id : Node_Id;
9062 E : Entity_Id;
9064 In_Package_Spec : constant Boolean :=
9065 Is_Package_Or_Generic_Package (Current_Scope)
9066 and then not In_Package_Body (Current_Scope);
9068 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
9069 -- Used to suppress a single check on the given entity
9071 --------------------------------
9072 -- Suppress_Unsuppress_Echeck --
9073 --------------------------------
9075 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
9076 begin
9077 -- Check for error of trying to set atomic synchronization for
9078 -- a non-atomic variable.
9080 if C = Atomic_Synchronization
9081 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
9082 then
9083 Error_Msg_N
9084 ("pragma & requires atomic type or variable",
9085 Pragma_Identifier (Original_Node (N)));
9086 end if;
9088 Set_Checks_May_Be_Suppressed (E);
9090 if In_Package_Spec then
9091 Push_Global_Suppress_Stack_Entry
9092 (Entity => E,
9093 Check => C,
9094 Suppress => Suppress_Case);
9095 else
9096 Push_Local_Suppress_Stack_Entry
9097 (Entity => E,
9098 Check => C,
9099 Suppress => Suppress_Case);
9100 end if;
9102 -- If this is a first subtype, and the base type is distinct,
9103 -- then also set the suppress flags on the base type.
9105 if Is_First_Subtype (E) and then Etype (E) /= E then
9106 Suppress_Unsuppress_Echeck (Etype (E), C);
9107 end if;
9108 end Suppress_Unsuppress_Echeck;
9110 -- Start of processing for Process_Suppress_Unsuppress
9112 begin
9113 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
9114 -- on user code: we want to generate checks for analysis purposes, as
9115 -- set respectively by -gnatC and -gnatd.F
9117 if (CodePeer_Mode or GNATprove_Mode)
9118 and then Comes_From_Source (N)
9119 then
9120 return;
9121 end if;
9123 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
9124 -- declarative part or a package spec (RM 11.5(5)).
9126 if not Is_Configuration_Pragma then
9127 Check_Is_In_Decl_Part_Or_Package_Spec;
9128 end if;
9130 Check_At_Least_N_Arguments (1);
9131 Check_At_Most_N_Arguments (2);
9132 Check_No_Identifier (Arg1);
9133 Check_Arg_Is_Identifier (Arg1);
9135 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
9137 if C = No_Check_Id then
9138 Error_Pragma_Arg
9139 ("argument of pragma% is not valid check name", Arg1);
9140 end if;
9142 if Arg_Count = 1 then
9144 -- Make an entry in the local scope suppress table. This is the
9145 -- table that directly shows the current value of the scope
9146 -- suppress check for any check id value.
9148 if C = All_Checks then
9150 -- For All_Checks, we set all specific predefined checks with
9151 -- the exception of Elaboration_Check, which is handled
9152 -- specially because of not wanting All_Checks to have the
9153 -- effect of deactivating static elaboration order processing.
9154 -- Atomic_Synchronization is also not affected, since this is
9155 -- not a real check.
9157 for J in Scope_Suppress.Suppress'Range loop
9158 if J /= Elaboration_Check
9159 and then
9160 J /= Atomic_Synchronization
9161 then
9162 Scope_Suppress.Suppress (J) := Suppress_Case;
9163 end if;
9164 end loop;
9166 -- If not All_Checks, and predefined check, then set appropriate
9167 -- scope entry. Note that we will set Elaboration_Check if this
9168 -- is explicitly specified. Atomic_Synchronization is allowed
9169 -- only if internally generated and entity is atomic.
9171 elsif C in Predefined_Check_Id
9172 and then (not Comes_From_Source (N)
9173 or else C /= Atomic_Synchronization)
9174 then
9175 Scope_Suppress.Suppress (C) := Suppress_Case;
9176 end if;
9178 -- Also make an entry in the Local_Entity_Suppress table
9180 Push_Local_Suppress_Stack_Entry
9181 (Entity => Empty,
9182 Check => C,
9183 Suppress => Suppress_Case);
9185 -- Case of two arguments present, where the check is suppressed for
9186 -- a specified entity (given as the second argument of the pragma)
9188 else
9189 -- This is obsolescent in Ada 2005 mode
9191 if Ada_Version >= Ada_2005 then
9192 Check_Restriction (No_Obsolescent_Features, Arg2);
9193 end if;
9195 Check_Optional_Identifier (Arg2, Name_On);
9196 E_Id := Get_Pragma_Arg (Arg2);
9197 Analyze (E_Id);
9199 if not Is_Entity_Name (E_Id) then
9200 Error_Pragma_Arg
9201 ("second argument of pragma% must be entity name", Arg2);
9202 end if;
9204 E := Entity (E_Id);
9206 if E = Any_Id then
9207 return;
9208 end if;
9210 -- Enforce RM 11.5(7) which requires that for a pragma that
9211 -- appears within a package spec, the named entity must be
9212 -- within the package spec. We allow the package name itself
9213 -- to be mentioned since that makes sense, although it is not
9214 -- strictly allowed by 11.5(7).
9216 if In_Package_Spec
9217 and then E /= Current_Scope
9218 and then Scope (E) /= Current_Scope
9219 then
9220 Error_Pragma_Arg
9221 ("entity in pragma% is not in package spec (RM 11.5(7))",
9222 Arg2);
9223 end if;
9225 -- Loop through homonyms. As noted below, in the case of a package
9226 -- spec, only homonyms within the package spec are considered.
9228 loop
9229 Suppress_Unsuppress_Echeck (E, C);
9231 if Is_Generic_Instance (E)
9232 and then Is_Subprogram (E)
9233 and then Present (Alias (E))
9234 then
9235 Suppress_Unsuppress_Echeck (Alias (E), C);
9236 end if;
9238 -- Move to next homonym if not aspect spec case
9240 exit when From_Aspect_Specification (N);
9241 E := Homonym (E);
9242 exit when No (E);
9244 -- If we are within a package specification, the pragma only
9245 -- applies to homonyms in the same scope.
9247 exit when In_Package_Spec
9248 and then Scope (E) /= Current_Scope;
9249 end loop;
9250 end if;
9251 end Process_Suppress_Unsuppress;
9253 ------------------
9254 -- Set_Exported --
9255 ------------------
9257 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
9258 begin
9259 if Is_Imported (E) then
9260 Error_Pragma_Arg
9261 ("cannot export entity& that was previously imported", Arg);
9263 elsif Present (Address_Clause (E))
9264 and then not Relaxed_RM_Semantics
9265 then
9266 Error_Pragma_Arg
9267 ("cannot export entity& that has an address clause", Arg);
9268 end if;
9270 Set_Is_Exported (E);
9272 -- Generate a reference for entity explicitly, because the
9273 -- identifier may be overloaded and name resolution will not
9274 -- generate one.
9276 Generate_Reference (E, Arg);
9278 -- Deal with exporting non-library level entity
9280 if not Is_Library_Level_Entity (E) then
9282 -- Not allowed at all for subprograms
9284 if Is_Subprogram (E) then
9285 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
9287 -- Otherwise set public and statically allocated
9289 else
9290 Set_Is_Public (E);
9291 Set_Is_Statically_Allocated (E);
9293 -- Warn if the corresponding W flag is set
9295 if Warn_On_Export_Import
9297 -- Only do this for something that was in the source. Not
9298 -- clear if this can be False now (there used for sure to be
9299 -- cases on some systems where it was False), but anyway the
9300 -- test is harmless if not needed, so it is retained.
9302 and then Comes_From_Source (Arg)
9303 then
9304 Error_Msg_NE
9305 ("?x?& has been made static as a result of Export",
9306 Arg, E);
9307 Error_Msg_N
9308 ("\?x?this usage is non-standard and non-portable",
9309 Arg);
9310 end if;
9311 end if;
9312 end if;
9314 if Warn_On_Export_Import and then Is_Type (E) then
9315 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
9316 end if;
9318 if Warn_On_Export_Import and Inside_A_Generic then
9319 Error_Msg_NE
9320 ("all instances of& will have the same external name?x?",
9321 Arg, E);
9322 end if;
9323 end Set_Exported;
9325 ----------------------------------------------
9326 -- Set_Extended_Import_Export_External_Name --
9327 ----------------------------------------------
9329 procedure Set_Extended_Import_Export_External_Name
9330 (Internal_Ent : Entity_Id;
9331 Arg_External : Node_Id)
9333 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
9334 New_Name : Node_Id;
9336 begin
9337 if No (Arg_External) then
9338 return;
9339 end if;
9341 Check_Arg_Is_External_Name (Arg_External);
9343 if Nkind (Arg_External) = N_String_Literal then
9344 if String_Length (Strval (Arg_External)) = 0 then
9345 return;
9346 else
9347 New_Name := Adjust_External_Name_Case (Arg_External);
9348 end if;
9350 elsif Nkind (Arg_External) = N_Identifier then
9351 New_Name := Get_Default_External_Name (Arg_External);
9353 -- Check_Arg_Is_External_Name should let through only identifiers and
9354 -- string literals or static string expressions (which are folded to
9355 -- string literals).
9357 else
9358 raise Program_Error;
9359 end if;
9361 -- If we already have an external name set (by a prior normal Import
9362 -- or Export pragma), then the external names must match
9364 if Present (Interface_Name (Internal_Ent)) then
9366 -- Ignore mismatching names in CodePeer mode, to support some
9367 -- old compilers which would export the same procedure under
9368 -- different names, e.g:
9369 -- procedure P;
9370 -- pragma Export_Procedure (P, "a");
9371 -- pragma Export_Procedure (P, "b");
9373 if CodePeer_Mode then
9374 return;
9375 end if;
9377 Check_Matching_Internal_Names : declare
9378 S1 : constant String_Id := Strval (Old_Name);
9379 S2 : constant String_Id := Strval (New_Name);
9381 procedure Mismatch;
9382 pragma No_Return (Mismatch);
9383 -- Called if names do not match
9385 --------------
9386 -- Mismatch --
9387 --------------
9389 procedure Mismatch is
9390 begin
9391 Error_Msg_Sloc := Sloc (Old_Name);
9392 Error_Pragma_Arg
9393 ("external name does not match that given #",
9394 Arg_External);
9395 end Mismatch;
9397 -- Start of processing for Check_Matching_Internal_Names
9399 begin
9400 if String_Length (S1) /= String_Length (S2) then
9401 Mismatch;
9403 else
9404 for J in 1 .. String_Length (S1) loop
9405 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
9406 Mismatch;
9407 end if;
9408 end loop;
9409 end if;
9410 end Check_Matching_Internal_Names;
9412 -- Otherwise set the given name
9414 else
9415 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
9416 Check_Duplicated_Export_Name (New_Name);
9417 end if;
9418 end Set_Extended_Import_Export_External_Name;
9420 ------------------
9421 -- Set_Imported --
9422 ------------------
9424 procedure Set_Imported (E : Entity_Id) is
9425 begin
9426 -- Error message if already imported or exported
9428 if Is_Exported (E) or else Is_Imported (E) then
9430 -- Error if being set Exported twice
9432 if Is_Exported (E) then
9433 Error_Msg_NE ("entity& was previously exported", N, E);
9435 -- Ignore error in CodePeer mode where we treat all imported
9436 -- subprograms as unknown.
9438 elsif CodePeer_Mode then
9439 goto OK;
9441 -- OK if Import/Interface case
9443 elsif Import_Interface_Present (N) then
9444 goto OK;
9446 -- Error if being set Imported twice
9448 else
9449 Error_Msg_NE ("entity& was previously imported", N, E);
9450 end if;
9452 Error_Msg_Name_1 := Pname;
9453 Error_Msg_N
9454 ("\(pragma% applies to all previous entities)", N);
9456 Error_Msg_Sloc := Sloc (E);
9457 Error_Msg_NE ("\import not allowed for& declared#", N, E);
9459 -- Here if not previously imported or exported, OK to import
9461 else
9462 Set_Is_Imported (E);
9464 -- For subprogram, set Import_Pragma field
9466 if Is_Subprogram (E) then
9467 Set_Import_Pragma (E, N);
9468 end if;
9470 -- If the entity is an object that is not at the library level,
9471 -- then it is statically allocated. We do not worry about objects
9472 -- with address clauses in this context since they are not really
9473 -- imported in the linker sense.
9475 if Is_Object (E)
9476 and then not Is_Library_Level_Entity (E)
9477 and then No (Address_Clause (E))
9478 then
9479 Set_Is_Statically_Allocated (E);
9480 end if;
9481 end if;
9483 <<OK>> null;
9484 end Set_Imported;
9486 -------------------------
9487 -- Set_Mechanism_Value --
9488 -------------------------
9490 -- Note: the mechanism name has not been analyzed (and cannot indeed be
9491 -- analyzed, since it is semantic nonsense), so we get it in the exact
9492 -- form created by the parser.
9494 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
9495 procedure Bad_Mechanism;
9496 pragma No_Return (Bad_Mechanism);
9497 -- Signal bad mechanism name
9499 -------------------------
9500 -- Bad_Mechanism_Value --
9501 -------------------------
9503 procedure Bad_Mechanism is
9504 begin
9505 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
9506 end Bad_Mechanism;
9508 -- Start of processing for Set_Mechanism_Value
9510 begin
9511 if Mechanism (Ent) /= Default_Mechanism then
9512 Error_Msg_NE
9513 ("mechanism for & has already been set", Mech_Name, Ent);
9514 end if;
9516 -- MECHANISM_NAME ::= value | reference
9518 if Nkind (Mech_Name) = N_Identifier then
9519 if Chars (Mech_Name) = Name_Value then
9520 Set_Mechanism (Ent, By_Copy);
9521 return;
9523 elsif Chars (Mech_Name) = Name_Reference then
9524 Set_Mechanism (Ent, By_Reference);
9525 return;
9527 elsif Chars (Mech_Name) = Name_Copy then
9528 Error_Pragma_Arg
9529 ("bad mechanism name, Value assumed", Mech_Name);
9531 else
9532 Bad_Mechanism;
9533 end if;
9535 else
9536 Bad_Mechanism;
9537 end if;
9538 end Set_Mechanism_Value;
9540 --------------------------
9541 -- Set_Rational_Profile --
9542 --------------------------
9544 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
9545 -- and extension to the semantics of renaming declarations.
9547 procedure Set_Rational_Profile is
9548 begin
9549 Implicit_Packing := True;
9550 Overriding_Renamings := True;
9551 Use_VADS_Size := True;
9552 end Set_Rational_Profile;
9554 ---------------------------
9555 -- Set_Ravenscar_Profile --
9556 ---------------------------
9558 -- The tasks to be done here are
9560 -- Set required policies
9562 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9563 -- pragma Locking_Policy (Ceiling_Locking)
9565 -- Set Detect_Blocking mode
9567 -- Set required restrictions (see System.Rident for detailed list)
9569 -- Set the No_Dependence rules
9570 -- No_Dependence => Ada.Asynchronous_Task_Control
9571 -- No_Dependence => Ada.Calendar
9572 -- No_Dependence => Ada.Execution_Time.Group_Budget
9573 -- No_Dependence => Ada.Execution_Time.Timers
9574 -- No_Dependence => Ada.Task_Attributes
9575 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9577 procedure Set_Ravenscar_Profile (N : Node_Id) is
9578 Prefix_Entity : Entity_Id;
9579 Selector_Entity : Entity_Id;
9580 Prefix_Node : Node_Id;
9581 Node : Node_Id;
9583 begin
9584 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9586 if Task_Dispatching_Policy /= ' '
9587 and then Task_Dispatching_Policy /= 'F'
9588 then
9589 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9590 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
9592 -- Set the FIFO_Within_Priorities policy, but always preserve
9593 -- System_Location since we like the error message with the run time
9594 -- name.
9596 else
9597 Task_Dispatching_Policy := 'F';
9599 if Task_Dispatching_Policy_Sloc /= System_Location then
9600 Task_Dispatching_Policy_Sloc := Loc;
9601 end if;
9602 end if;
9604 -- pragma Locking_Policy (Ceiling_Locking)
9606 if Locking_Policy /= ' '
9607 and then Locking_Policy /= 'C'
9608 then
9609 Error_Msg_Sloc := Locking_Policy_Sloc;
9610 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
9612 -- Set the Ceiling_Locking policy, but preserve System_Location since
9613 -- we like the error message with the run time name.
9615 else
9616 Locking_Policy := 'C';
9618 if Locking_Policy_Sloc /= System_Location then
9619 Locking_Policy_Sloc := Loc;
9620 end if;
9621 end if;
9623 -- pragma Detect_Blocking
9625 Detect_Blocking := True;
9627 -- Set the corresponding restrictions
9629 Set_Profile_Restrictions
9630 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
9632 -- Set the No_Dependence restrictions
9634 -- The following No_Dependence restrictions:
9635 -- No_Dependence => Ada.Asynchronous_Task_Control
9636 -- No_Dependence => Ada.Calendar
9637 -- No_Dependence => Ada.Task_Attributes
9638 -- are already set by previous call to Set_Profile_Restrictions.
9640 -- Set the following restrictions which were added to Ada 2005:
9641 -- No_Dependence => Ada.Execution_Time.Group_Budget
9642 -- No_Dependence => Ada.Execution_Time.Timers
9644 if Ada_Version >= Ada_2005 then
9645 Name_Buffer (1 .. 3) := "ada";
9646 Name_Len := 3;
9648 Prefix_Entity := Make_Identifier (Loc, Name_Find);
9650 Name_Buffer (1 .. 14) := "execution_time";
9651 Name_Len := 14;
9653 Selector_Entity := Make_Identifier (Loc, Name_Find);
9655 Prefix_Node :=
9656 Make_Selected_Component
9657 (Sloc => Loc,
9658 Prefix => Prefix_Entity,
9659 Selector_Name => Selector_Entity);
9661 Name_Buffer (1 .. 13) := "group_budgets";
9662 Name_Len := 13;
9664 Selector_Entity := Make_Identifier (Loc, Name_Find);
9666 Node :=
9667 Make_Selected_Component
9668 (Sloc => Loc,
9669 Prefix => Prefix_Node,
9670 Selector_Name => Selector_Entity);
9672 Set_Restriction_No_Dependence
9673 (Unit => Node,
9674 Warn => Treat_Restrictions_As_Warnings,
9675 Profile => Ravenscar);
9677 Name_Buffer (1 .. 6) := "timers";
9678 Name_Len := 6;
9680 Selector_Entity := Make_Identifier (Loc, Name_Find);
9682 Node :=
9683 Make_Selected_Component
9684 (Sloc => Loc,
9685 Prefix => Prefix_Node,
9686 Selector_Name => Selector_Entity);
9688 Set_Restriction_No_Dependence
9689 (Unit => Node,
9690 Warn => Treat_Restrictions_As_Warnings,
9691 Profile => Ravenscar);
9692 end if;
9694 -- Set the following restrictions which was added to Ada 2012 (see
9695 -- AI-0171):
9696 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9698 if Ada_Version >= Ada_2012 then
9699 Name_Buffer (1 .. 6) := "system";
9700 Name_Len := 6;
9702 Prefix_Entity := Make_Identifier (Loc, Name_Find);
9704 Name_Buffer (1 .. 15) := "multiprocessors";
9705 Name_Len := 15;
9707 Selector_Entity := Make_Identifier (Loc, Name_Find);
9709 Prefix_Node :=
9710 Make_Selected_Component
9711 (Sloc => Loc,
9712 Prefix => Prefix_Entity,
9713 Selector_Name => Selector_Entity);
9715 Name_Buffer (1 .. 19) := "dispatching_domains";
9716 Name_Len := 19;
9718 Selector_Entity := Make_Identifier (Loc, Name_Find);
9720 Node :=
9721 Make_Selected_Component
9722 (Sloc => Loc,
9723 Prefix => Prefix_Node,
9724 Selector_Name => Selector_Entity);
9726 Set_Restriction_No_Dependence
9727 (Unit => Node,
9728 Warn => Treat_Restrictions_As_Warnings,
9729 Profile => Ravenscar);
9730 end if;
9731 end Set_Ravenscar_Profile;
9733 -- Start of processing for Analyze_Pragma
9735 begin
9736 -- The following code is a defense against recursion. Not clear that
9737 -- this can happen legitimately, but perhaps some error situations
9738 -- can cause it, and we did see this recursion during testing.
9740 if Analyzed (N) then
9741 return;
9742 else
9743 Set_Analyzed (N, True);
9744 end if;
9746 -- Deal with unrecognized pragma
9748 Pname := Pragma_Name (N);
9750 if not Is_Pragma_Name (Pname) then
9751 if Warn_On_Unrecognized_Pragma then
9752 Error_Msg_Name_1 := Pname;
9753 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
9755 for PN in First_Pragma_Name .. Last_Pragma_Name loop
9756 if Is_Bad_Spelling_Of (Pname, PN) then
9757 Error_Msg_Name_1 := PN;
9758 Error_Msg_N -- CODEFIX
9759 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
9760 exit;
9761 end if;
9762 end loop;
9763 end if;
9765 return;
9766 end if;
9768 -- Here to start processing for recognized pragma
9770 Prag_Id := Get_Pragma_Id (Pname);
9771 Pname := Original_Aspect_Name (N);
9773 -- Capture setting of Opt.Uneval_Old
9775 case Opt.Uneval_Old is
9776 when 'A' =>
9777 Set_Uneval_Old_Accept (N);
9778 when 'E' =>
9779 null;
9780 when 'W' =>
9781 Set_Uneval_Old_Warn (N);
9782 when others =>
9783 raise Program_Error;
9784 end case;
9786 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
9787 -- is already set, indicating that we have already checked the policy
9788 -- at the right point. This happens for example in the case of a pragma
9789 -- that is derived from an Aspect.
9791 if Is_Ignored (N) or else Is_Checked (N) then
9792 null;
9794 -- For a pragma that is a rewriting of another pragma, copy the
9795 -- Is_Checked/Is_Ignored status from the rewritten pragma.
9797 elsif Is_Rewrite_Substitution (N)
9798 and then Nkind (Original_Node (N)) = N_Pragma
9799 and then Original_Node (N) /= N
9800 then
9801 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
9802 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
9804 -- Otherwise query the applicable policy at this point
9806 else
9807 Check_Applicable_Policy (N);
9809 -- If pragma is disabled, rewrite as NULL and skip analysis
9811 if Is_Disabled (N) then
9812 Rewrite (N, Make_Null_Statement (Loc));
9813 Analyze (N);
9814 raise Pragma_Exit;
9815 end if;
9816 end if;
9818 -- Preset arguments
9820 Arg_Count := 0;
9821 Arg1 := Empty;
9822 Arg2 := Empty;
9823 Arg3 := Empty;
9824 Arg4 := Empty;
9826 if Present (Pragma_Argument_Associations (N)) then
9827 Arg_Count := List_Length (Pragma_Argument_Associations (N));
9828 Arg1 := First (Pragma_Argument_Associations (N));
9830 if Present (Arg1) then
9831 Arg2 := Next (Arg1);
9833 if Present (Arg2) then
9834 Arg3 := Next (Arg2);
9836 if Present (Arg3) then
9837 Arg4 := Next (Arg3);
9838 end if;
9839 end if;
9840 end if;
9841 end if;
9843 Check_Restriction_No_Use_Of_Pragma (N);
9845 -- An enumeration type defines the pragmas that are supported by the
9846 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
9847 -- into the corresponding enumeration value for the following case.
9849 case Prag_Id is
9851 -----------------
9852 -- Abort_Defer --
9853 -----------------
9855 -- pragma Abort_Defer;
9857 when Pragma_Abort_Defer =>
9858 GNAT_Pragma;
9859 Check_Arg_Count (0);
9861 -- The only required semantic processing is to check the
9862 -- placement. This pragma must appear at the start of the
9863 -- statement sequence of a handled sequence of statements.
9865 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
9866 or else N /= First (Statements (Parent (N)))
9867 then
9868 Pragma_Misplaced;
9869 end if;
9871 --------------------
9872 -- Abstract_State --
9873 --------------------
9875 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
9877 -- ABSTRACT_STATE_LIST ::=
9878 -- null
9879 -- | STATE_NAME_WITH_OPTIONS
9880 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS} )
9882 -- STATE_NAME_WITH_OPTIONS ::=
9883 -- STATE_NAME
9884 -- | (STATE_NAME with OPTION_LIST)
9886 -- OPTION_LIST ::= OPTION {, OPTION}
9888 -- OPTION ::=
9889 -- SIMPLE_OPTION
9890 -- | NAME_VALUE_OPTION
9892 -- SIMPLE_OPTION ::= Ghost
9894 -- NAME_VALUE_OPTION ::=
9895 -- Part_Of => ABSTRACT_STATE
9896 -- | External [=> EXTERNAL_PROPERTY_LIST]
9898 -- EXTERNAL_PROPERTY_LIST ::=
9899 -- EXTERNAL_PROPERTY
9900 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY} )
9902 -- EXTERNAL_PROPERTY ::=
9903 -- Async_Readers [=> boolean_EXPRESSION]
9904 -- | Async_Writers [=> boolean_EXPRESSION]
9905 -- | Effective_Reads [=> boolean_EXPRESSION]
9906 -- | Effective_Writes [=> boolean_EXPRESSION]
9907 -- others => boolean_EXPRESSION
9909 -- STATE_NAME ::= defining_identifier
9911 -- ABSTRACT_STATE ::= name
9913 when Pragma_Abstract_State => Abstract_State : declare
9914 Missing_Parentheses : Boolean := False;
9915 -- Flag set when a state declaration with options is not properly
9916 -- parenthesized.
9918 -- Flags used to verify the consistency of states
9920 Non_Null_Seen : Boolean := False;
9921 Null_Seen : Boolean := False;
9923 procedure Analyze_Abstract_State
9924 (State : Node_Id;
9925 Pack_Id : Entity_Id);
9926 -- Verify the legality of a single state declaration. Create and
9927 -- decorate a state abstraction entity and introduce it into the
9928 -- visibility chain. Pack_Id denotes the entity or the related
9929 -- package where pragma Abstract_State appears.
9931 ----------------------------
9932 -- Analyze_Abstract_State --
9933 ----------------------------
9935 procedure Analyze_Abstract_State
9936 (State : Node_Id;
9937 Pack_Id : Entity_Id)
9939 -- Flags used to verify the consistency of options
9941 AR_Seen : Boolean := False;
9942 AW_Seen : Boolean := False;
9943 ER_Seen : Boolean := False;
9944 EW_Seen : Boolean := False;
9945 External_Seen : Boolean := False;
9946 Others_Seen : Boolean := False;
9947 Part_Of_Seen : Boolean := False;
9949 -- Flags used to store the static value of all external states'
9950 -- expressions.
9952 AR_Val : Boolean := False;
9953 AW_Val : Boolean := False;
9954 ER_Val : Boolean := False;
9955 EW_Val : Boolean := False;
9957 State_Id : Entity_Id := Empty;
9958 -- The entity to be generated for the current state declaration
9960 procedure Analyze_External_Option (Opt : Node_Id);
9961 -- Verify the legality of option External
9963 procedure Analyze_External_Property
9964 (Prop : Node_Id;
9965 Expr : Node_Id := Empty);
9966 -- Verify the legailty of a single external property. Prop
9967 -- denotes the external property. Expr is the expression used
9968 -- to set the property.
9970 procedure Analyze_Part_Of_Option (Opt : Node_Id);
9971 -- Verify the legality of option Part_Of
9973 procedure Check_Duplicate_Option
9974 (Opt : Node_Id;
9975 Status : in out Boolean);
9976 -- Flag Status denotes whether a particular option has been
9977 -- seen while processing a state. This routine verifies that
9978 -- Opt is not a duplicate option and sets the flag Status
9979 -- (SPARK RM 7.1.4(1)).
9981 procedure Check_Duplicate_Property
9982 (Prop : Node_Id;
9983 Status : in out Boolean);
9984 -- Flag Status denotes whether a particular property has been
9985 -- seen while processing option External. This routine verifies
9986 -- that Prop is not a duplicate property and sets flag Status.
9987 -- Opt is not a duplicate property and sets the flag Status.
9988 -- (SPARK RM 7.1.4(2))
9990 procedure Create_Abstract_State
9991 (Nam : Name_Id;
9992 Decl : Node_Id;
9993 Loc : Source_Ptr;
9994 Is_Null : Boolean);
9995 -- Generate an abstract state entity with name Nam and enter it
9996 -- into visibility. Decl is the "declaration" of the state as
9997 -- it appears in pragma Abstract_State. Loc is the location of
9998 -- the related state "declaration". Flag Is_Null should be set
9999 -- when the associated Abstract_State pragma defines a null
10000 -- state.
10002 -----------------------------
10003 -- Analyze_External_Option --
10004 -----------------------------
10006 procedure Analyze_External_Option (Opt : Node_Id) is
10007 Errors : constant Nat := Serious_Errors_Detected;
10008 Prop : Node_Id;
10009 Props : Node_Id := Empty;
10011 begin
10012 Check_Duplicate_Option (Opt, External_Seen);
10014 if Nkind (Opt) = N_Component_Association then
10015 Props := Expression (Opt);
10016 end if;
10018 -- External state with properties
10020 if Present (Props) then
10022 -- Multiple properties appear as an aggregate
10024 if Nkind (Props) = N_Aggregate then
10026 -- Simple property form
10028 Prop := First (Expressions (Props));
10029 while Present (Prop) loop
10030 Analyze_External_Property (Prop);
10031 Next (Prop);
10032 end loop;
10034 -- Property with expression form
10036 Prop := First (Component_Associations (Props));
10037 while Present (Prop) loop
10038 Analyze_External_Property
10039 (Prop => First (Choices (Prop)),
10040 Expr => Expression (Prop));
10042 Next (Prop);
10043 end loop;
10045 -- Single property
10047 else
10048 Analyze_External_Property (Props);
10049 end if;
10051 -- An external state defined without any properties defaults
10052 -- all properties to True.
10054 else
10055 AR_Val := True;
10056 AW_Val := True;
10057 ER_Val := True;
10058 EW_Val := True;
10059 end if;
10061 -- Once all external properties have been processed, verify
10062 -- their mutual interaction. Do not perform the check when
10063 -- at least one of the properties is illegal as this will
10064 -- produce a bogus error.
10066 if Errors = Serious_Errors_Detected then
10067 Check_External_Properties
10068 (State, AR_Val, AW_Val, ER_Val, EW_Val);
10069 end if;
10070 end Analyze_External_Option;
10072 -------------------------------
10073 -- Analyze_External_Property --
10074 -------------------------------
10076 procedure Analyze_External_Property
10077 (Prop : Node_Id;
10078 Expr : Node_Id := Empty)
10080 Expr_Val : Boolean;
10082 begin
10083 -- Check the placement of "others" (if available)
10085 if Nkind (Prop) = N_Others_Choice then
10086 if Others_Seen then
10087 SPARK_Msg_N
10088 ("only one others choice allowed in option External",
10089 Prop);
10090 else
10091 Others_Seen := True;
10092 end if;
10094 elsif Others_Seen then
10095 SPARK_Msg_N
10096 ("others must be the last property in option External",
10097 Prop);
10099 -- The only remaining legal options are the four predefined
10100 -- external properties.
10102 elsif Nkind (Prop) = N_Identifier
10103 and then Nam_In (Chars (Prop), Name_Async_Readers,
10104 Name_Async_Writers,
10105 Name_Effective_Reads,
10106 Name_Effective_Writes)
10107 then
10108 null;
10110 -- Otherwise the construct is not a valid property
10112 else
10113 SPARK_Msg_N ("invalid external state property", Prop);
10114 return;
10115 end if;
10117 -- Ensure that the expression of the external state property
10118 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
10120 if Present (Expr) then
10121 Analyze_And_Resolve (Expr, Standard_Boolean);
10123 if Is_OK_Static_Expression (Expr) then
10124 Expr_Val := Is_True (Expr_Value (Expr));
10125 else
10126 SPARK_Msg_N
10127 ("expression of external state property must be "
10128 & "static", Expr);
10129 end if;
10131 -- The lack of expression defaults the property to True
10133 else
10134 Expr_Val := True;
10135 end if;
10137 -- Named properties
10139 if Nkind (Prop) = N_Identifier then
10140 if Chars (Prop) = Name_Async_Readers then
10141 Check_Duplicate_Property (Prop, AR_Seen);
10142 AR_Val := Expr_Val;
10144 elsif Chars (Prop) = Name_Async_Writers then
10145 Check_Duplicate_Property (Prop, AW_Seen);
10146 AW_Val := Expr_Val;
10148 elsif Chars (Prop) = Name_Effective_Reads then
10149 Check_Duplicate_Property (Prop, ER_Seen);
10150 ER_Val := Expr_Val;
10152 else
10153 Check_Duplicate_Property (Prop, EW_Seen);
10154 EW_Val := Expr_Val;
10155 end if;
10157 -- The handling of property "others" must take into account
10158 -- all other named properties that have been encountered so
10159 -- far. Only those that have not been seen are affected by
10160 -- "others".
10162 else
10163 if not AR_Seen then
10164 AR_Val := Expr_Val;
10165 end if;
10167 if not AW_Seen then
10168 AW_Val := Expr_Val;
10169 end if;
10171 if not ER_Seen then
10172 ER_Val := Expr_Val;
10173 end if;
10175 if not EW_Seen then
10176 EW_Val := Expr_Val;
10177 end if;
10178 end if;
10179 end Analyze_External_Property;
10181 ----------------------------
10182 -- Analyze_Part_Of_Option --
10183 ----------------------------
10185 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
10186 Encaps : constant Node_Id := Expression (Opt);
10187 Encaps_Id : Entity_Id;
10188 Legal : Boolean;
10190 begin
10191 Check_Duplicate_Option (Opt, Part_Of_Seen);
10193 Analyze_Part_Of
10194 (Item_Id => State_Id,
10195 State => Encaps,
10196 Indic => First (Choices (Opt)),
10197 Legal => Legal);
10199 -- The Part_Of indicator turns an abstract state into a
10200 -- constituent of the encapsulating state.
10202 if Legal then
10203 Encaps_Id := Entity (Encaps);
10205 Append_Elmt (State_Id, Part_Of_Constituents (Encaps_Id));
10206 Set_Encapsulating_State (State_Id, Encaps_Id);
10207 end if;
10208 end Analyze_Part_Of_Option;
10210 ----------------------------
10211 -- Check_Duplicate_Option --
10212 ----------------------------
10214 procedure Check_Duplicate_Option
10215 (Opt : Node_Id;
10216 Status : in out Boolean)
10218 begin
10219 if Status then
10220 SPARK_Msg_N ("duplicate state option", Opt);
10221 end if;
10223 Status := True;
10224 end Check_Duplicate_Option;
10226 ------------------------------
10227 -- Check_Duplicate_Property --
10228 ------------------------------
10230 procedure Check_Duplicate_Property
10231 (Prop : Node_Id;
10232 Status : in out Boolean)
10234 begin
10235 if Status then
10236 SPARK_Msg_N ("duplicate external property", Prop);
10237 end if;
10239 Status := True;
10240 end Check_Duplicate_Property;
10242 ---------------------------
10243 -- Create_Abstract_State --
10244 ---------------------------
10246 procedure Create_Abstract_State
10247 (Nam : Name_Id;
10248 Decl : Node_Id;
10249 Loc : Source_Ptr;
10250 Is_Null : Boolean)
10252 begin
10253 -- The abstract state may be semi-declared when the related
10254 -- package was withed through a limited with clause. In that
10255 -- case reuse the entity to fully declare the state.
10257 if Present (Decl) and then Present (Entity (Decl)) then
10258 State_Id := Entity (Decl);
10260 -- Otherwise the elaboration of pragma Abstract_State
10261 -- declares the state.
10263 else
10264 State_Id := Make_Defining_Identifier (Loc, Nam);
10266 if Present (Decl) then
10267 Set_Entity (Decl, State_Id);
10268 end if;
10269 end if;
10271 -- Null states never come from source
10273 Set_Comes_From_Source (State_Id, not Is_Null);
10274 Set_Parent (State_Id, State);
10275 Set_Ekind (State_Id, E_Abstract_State);
10276 Set_Etype (State_Id, Standard_Void_Type);
10277 Set_Encapsulating_State (State_Id, Empty);
10278 Set_Refinement_Constituents (State_Id, New_Elmt_List);
10279 Set_Part_Of_Constituents (State_Id, New_Elmt_List);
10281 -- An abstract state declared within a Ghost scope becomes
10282 -- Ghost (SPARK RM 6.9(2)).
10284 if Within_Ghost_Scope then
10285 Set_Is_Ghost_Entity (State_Id);
10286 end if;
10288 -- Establish a link between the state declaration and the
10289 -- abstract state entity. Note that a null state remains as
10290 -- N_Null and does not carry any linkages.
10292 if not Is_Null then
10293 if Present (Decl) then
10294 Set_Entity (Decl, State_Id);
10295 Set_Etype (Decl, Standard_Void_Type);
10296 end if;
10298 -- Every non-null state must be defined, nameable and
10299 -- resolvable.
10301 Push_Scope (Pack_Id);
10302 Generate_Definition (State_Id);
10303 Enter_Name (State_Id);
10304 Pop_Scope;
10305 end if;
10306 end Create_Abstract_State;
10308 -- Local variables
10310 Opt : Node_Id;
10311 Opt_Nam : Node_Id;
10313 -- Start of processing for Analyze_Abstract_State
10315 begin
10316 -- A package with a null abstract state is not allowed to
10317 -- declare additional states.
10319 if Null_Seen then
10320 SPARK_Msg_NE
10321 ("package & has null abstract state", State, Pack_Id);
10323 -- Null states appear as internally generated entities
10325 elsif Nkind (State) = N_Null then
10326 Create_Abstract_State
10327 (Nam => New_Internal_Name ('S'),
10328 Decl => Empty,
10329 Loc => Sloc (State),
10330 Is_Null => True);
10331 Null_Seen := True;
10333 -- Catch a case where a null state appears in a list of
10334 -- non-null states.
10336 if Non_Null_Seen then
10337 SPARK_Msg_NE
10338 ("package & has non-null abstract state",
10339 State, Pack_Id);
10340 end if;
10342 -- Simple state declaration
10344 elsif Nkind (State) = N_Identifier then
10345 Create_Abstract_State
10346 (Nam => Chars (State),
10347 Decl => State,
10348 Loc => Sloc (State),
10349 Is_Null => False);
10350 Non_Null_Seen := True;
10352 -- State declaration with various options. This construct
10353 -- appears as an extension aggregate in the tree.
10355 elsif Nkind (State) = N_Extension_Aggregate then
10356 if Nkind (Ancestor_Part (State)) = N_Identifier then
10357 Create_Abstract_State
10358 (Nam => Chars (Ancestor_Part (State)),
10359 Decl => Ancestor_Part (State),
10360 Loc => Sloc (Ancestor_Part (State)),
10361 Is_Null => False);
10362 Non_Null_Seen := True;
10363 else
10364 SPARK_Msg_N
10365 ("state name must be an identifier",
10366 Ancestor_Part (State));
10367 end if;
10369 -- Options External and Ghost appear as expressions
10371 Opt := First (Expressions (State));
10372 while Present (Opt) loop
10373 if Nkind (Opt) = N_Identifier then
10374 if Chars (Opt) = Name_External then
10375 Analyze_External_Option (Opt);
10377 elsif Chars (Opt) = Name_Ghost then
10378 if Present (State_Id) then
10379 Set_Is_Ghost_Entity (State_Id);
10380 end if;
10382 -- Option Part_Of without an encapsulating state is
10383 -- illegal. (SPARK RM 7.1.4(9)).
10385 elsif Chars (Opt) = Name_Part_Of then
10386 SPARK_Msg_N
10387 ("indicator Part_Of must denote an abstract "
10388 & "state", Opt);
10390 -- Do not emit an error message when a previous state
10391 -- declaration with options was not parenthesized as
10392 -- the option is actually another state declaration.
10394 -- with Abstract_State
10395 -- (State_1 with ..., -- missing parentheses
10396 -- (State_2 with ...),
10397 -- State_3) -- ok state declaration
10399 elsif Missing_Parentheses then
10400 null;
10402 -- Otherwise the option is not allowed. Note that it
10403 -- is not possible to distinguish between an option
10404 -- and a state declaration when a previous state with
10405 -- options not properly parentheses.
10407 -- with Abstract_State
10408 -- (State_1 with ..., -- missing parentheses
10409 -- State_2); -- could be an option
10411 else
10412 SPARK_Msg_N
10413 ("simple option not allowed in state declaration",
10414 Opt);
10415 end if;
10417 -- Catch a case where missing parentheses around a state
10418 -- declaration with options cause a subsequent state
10419 -- declaration with options to be treated as an option.
10421 -- with Abstract_State
10422 -- (State_1 with ..., -- missing parentheses
10423 -- (State_2 with ...))
10425 elsif Nkind (Opt) = N_Extension_Aggregate then
10426 Missing_Parentheses := True;
10427 SPARK_Msg_N
10428 ("state declaration must be parenthesized",
10429 Ancestor_Part (State));
10431 -- Otherwise the option is malformed
10433 else
10434 SPARK_Msg_N ("malformed option", Opt);
10435 end if;
10437 Next (Opt);
10438 end loop;
10440 -- Options External and Part_Of appear as component
10441 -- associations.
10443 Opt := First (Component_Associations (State));
10444 while Present (Opt) loop
10445 Opt_Nam := First (Choices (Opt));
10447 if Nkind (Opt_Nam) = N_Identifier then
10448 if Chars (Opt_Nam) = Name_External then
10449 Analyze_External_Option (Opt);
10451 elsif Chars (Opt_Nam) = Name_Part_Of then
10452 Analyze_Part_Of_Option (Opt);
10454 else
10455 SPARK_Msg_N ("invalid state option", Opt);
10456 end if;
10457 else
10458 SPARK_Msg_N ("invalid state option", Opt);
10459 end if;
10461 Next (Opt);
10462 end loop;
10464 -- Any other attempt to declare a state is illegal. This is a
10465 -- syntax error, always report.
10467 else
10468 Error_Msg_N ("malformed abstract state declaration", State);
10469 return;
10470 end if;
10472 -- Guard against a junk state. In such cases no entity is
10473 -- generated and the subsequent checks cannot be applied.
10475 if Present (State_Id) then
10477 -- Verify whether the state does not introduce an illegal
10478 -- hidden state within a package subject to a null abstract
10479 -- state.
10481 Check_No_Hidden_State (State_Id);
10483 -- Check whether the lack of option Part_Of agrees with the
10484 -- placement of the abstract state with respect to the state
10485 -- space.
10487 if not Part_Of_Seen then
10488 Check_Missing_Part_Of (State_Id);
10489 end if;
10491 -- Associate the state with its related package
10493 if No (Abstract_States (Pack_Id)) then
10494 Set_Abstract_States (Pack_Id, New_Elmt_List);
10495 end if;
10497 Append_Elmt (State_Id, Abstract_States (Pack_Id));
10498 end if;
10499 end Analyze_Abstract_State;
10501 -- Local variables
10503 Context : constant Node_Id := Parent (Parent (N));
10504 Pack_Id : Entity_Id;
10505 State : Node_Id;
10507 -- Start of processing for Abstract_State
10509 begin
10510 GNAT_Pragma;
10511 Check_No_Identifiers;
10512 Check_Arg_Count (1);
10513 Ensure_Aggregate_Form (Arg1);
10515 -- Ensure the proper placement of the pragma. Abstract states must
10516 -- be associated with a package declaration.
10518 if not Nkind_In (Context, N_Generic_Package_Declaration,
10519 N_Package_Declaration)
10520 then
10521 Pragma_Misplaced;
10522 return;
10523 end if;
10525 State := Expression (Arg1);
10526 Pack_Id := Defining_Entity (Context);
10528 -- Mark the associated package as Ghost if it is subject to aspect
10529 -- or pragma Ghost as this affects the declaration of an abstract
10530 -- state.
10532 if Is_Subject_To_Ghost (Unit_Declaration_Node (Pack_Id)) then
10533 Set_Is_Ghost_Entity (Pack_Id);
10534 end if;
10536 -- Multiple non-null abstract states appear as an aggregate
10538 if Nkind (State) = N_Aggregate then
10539 State := First (Expressions (State));
10540 while Present (State) loop
10541 Analyze_Abstract_State (State, Pack_Id);
10542 Next (State);
10543 end loop;
10545 -- Various forms of a single abstract state. Note that these may
10546 -- include malformed state declarations.
10548 else
10549 Analyze_Abstract_State (State, Pack_Id);
10550 end if;
10552 -- Save the pragma for retrieval by other tools
10554 Add_Contract_Item (N, Pack_Id);
10556 -- Verify the declaration order of pragmas Abstract_State and
10557 -- Initializes.
10559 Check_Declaration_Order
10560 (First => N,
10561 Second => Get_Pragma (Pack_Id, Pragma_Initializes));
10562 end Abstract_State;
10564 ------------
10565 -- Ada_83 --
10566 ------------
10568 -- pragma Ada_83;
10570 -- Note: this pragma also has some specific processing in Par.Prag
10571 -- because we want to set the Ada version mode during parsing.
10573 when Pragma_Ada_83 =>
10574 GNAT_Pragma;
10575 Check_Arg_Count (0);
10577 -- We really should check unconditionally for proper configuration
10578 -- pragma placement, since we really don't want mixed Ada modes
10579 -- within a single unit, and the GNAT reference manual has always
10580 -- said this was a configuration pragma, but we did not check and
10581 -- are hesitant to add the check now.
10583 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
10584 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
10585 -- or Ada 2012 mode.
10587 if Ada_Version >= Ada_2005 then
10588 Check_Valid_Configuration_Pragma;
10589 end if;
10591 -- Now set Ada 83 mode
10593 Ada_Version := Ada_83;
10594 Ada_Version_Explicit := Ada_83;
10595 Ada_Version_Pragma := N;
10597 ------------
10598 -- Ada_95 --
10599 ------------
10601 -- pragma Ada_95;
10603 -- Note: this pragma also has some specific processing in Par.Prag
10604 -- because we want to set the Ada 83 version mode during parsing.
10606 when Pragma_Ada_95 =>
10607 GNAT_Pragma;
10608 Check_Arg_Count (0);
10610 -- We really should check unconditionally for proper configuration
10611 -- pragma placement, since we really don't want mixed Ada modes
10612 -- within a single unit, and the GNAT reference manual has always
10613 -- said this was a configuration pragma, but we did not check and
10614 -- are hesitant to add the check now.
10616 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
10617 -- or Ada 95, so we must check if we are in Ada 2005 mode.
10619 if Ada_Version >= Ada_2005 then
10620 Check_Valid_Configuration_Pragma;
10621 end if;
10623 -- Now set Ada 95 mode
10625 Ada_Version := Ada_95;
10626 Ada_Version_Explicit := Ada_95;
10627 Ada_Version_Pragma := N;
10629 ---------------------
10630 -- Ada_05/Ada_2005 --
10631 ---------------------
10633 -- pragma Ada_05;
10634 -- pragma Ada_05 (LOCAL_NAME);
10636 -- pragma Ada_2005;
10637 -- pragma Ada_2005 (LOCAL_NAME):
10639 -- Note: these pragmas also have some specific processing in Par.Prag
10640 -- because we want to set the Ada 2005 version mode during parsing.
10642 -- The one argument form is used for managing the transition from
10643 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
10644 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
10645 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
10646 -- mode, a preference rule is established which does not choose
10647 -- such an entity unless it is unambiguously specified. This avoids
10648 -- extra subprograms marked this way from generating ambiguities in
10649 -- otherwise legal pre-Ada_2005 programs. The one argument form is
10650 -- intended for exclusive use in the GNAT run-time library.
10652 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
10653 E_Id : Node_Id;
10655 begin
10656 GNAT_Pragma;
10658 if Arg_Count = 1 then
10659 Check_Arg_Is_Local_Name (Arg1);
10660 E_Id := Get_Pragma_Arg (Arg1);
10662 if Etype (E_Id) = Any_Type then
10663 return;
10664 end if;
10666 Set_Is_Ada_2005_Only (Entity (E_Id));
10667 Record_Rep_Item (Entity (E_Id), N);
10669 else
10670 Check_Arg_Count (0);
10672 -- For Ada_2005 we unconditionally enforce the documented
10673 -- configuration pragma placement, since we do not want to
10674 -- tolerate mixed modes in a unit involving Ada 2005. That
10675 -- would cause real difficulties for those cases where there
10676 -- are incompatibilities between Ada 95 and Ada 2005.
10678 Check_Valid_Configuration_Pragma;
10680 -- Now set appropriate Ada mode
10682 Ada_Version := Ada_2005;
10683 Ada_Version_Explicit := Ada_2005;
10684 Ada_Version_Pragma := N;
10685 end if;
10686 end;
10688 ---------------------
10689 -- Ada_12/Ada_2012 --
10690 ---------------------
10692 -- pragma Ada_12;
10693 -- pragma Ada_12 (LOCAL_NAME);
10695 -- pragma Ada_2012;
10696 -- pragma Ada_2012 (LOCAL_NAME):
10698 -- Note: these pragmas also have some specific processing in Par.Prag
10699 -- because we want to set the Ada 2012 version mode during parsing.
10701 -- The one argument form is used for managing the transition from Ada
10702 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
10703 -- as Ada_201 only, then referencing the entity in any pre-Ada_2012
10704 -- mode will generate a warning. In addition, in any pre-Ada_2012
10705 -- mode, a preference rule is established which does not choose
10706 -- such an entity unless it is unambiguously specified. This avoids
10707 -- extra subprograms marked this way from generating ambiguities in
10708 -- otherwise legal pre-Ada_2012 programs. The one argument form is
10709 -- intended for exclusive use in the GNAT run-time library.
10711 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
10712 E_Id : Node_Id;
10714 begin
10715 GNAT_Pragma;
10717 if Arg_Count = 1 then
10718 Check_Arg_Is_Local_Name (Arg1);
10719 E_Id := Get_Pragma_Arg (Arg1);
10721 if Etype (E_Id) = Any_Type then
10722 return;
10723 end if;
10725 Set_Is_Ada_2012_Only (Entity (E_Id));
10726 Record_Rep_Item (Entity (E_Id), N);
10728 else
10729 Check_Arg_Count (0);
10731 -- For Ada_2012 we unconditionally enforce the documented
10732 -- configuration pragma placement, since we do not want to
10733 -- tolerate mixed modes in a unit involving Ada 2012. That
10734 -- would cause real difficulties for those cases where there
10735 -- are incompatibilities between Ada 95 and Ada 2012. We could
10736 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
10738 Check_Valid_Configuration_Pragma;
10740 -- Now set appropriate Ada mode
10742 Ada_Version := Ada_2012;
10743 Ada_Version_Explicit := Ada_2012;
10744 Ada_Version_Pragma := N;
10745 end if;
10746 end;
10748 ----------------------
10749 -- All_Calls_Remote --
10750 ----------------------
10752 -- pragma All_Calls_Remote [(library_package_NAME)];
10754 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
10755 Lib_Entity : Entity_Id;
10757 begin
10758 Check_Ada_83_Warning;
10759 Check_Valid_Library_Unit_Pragma;
10761 if Nkind (N) = N_Null_Statement then
10762 return;
10763 end if;
10765 Lib_Entity := Find_Lib_Unit_Name;
10767 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
10769 if Present (Lib_Entity)
10770 and then not Debug_Flag_U
10771 then
10772 if not Is_Remote_Call_Interface (Lib_Entity) then
10773 Error_Pragma ("pragma% only apply to rci unit");
10775 -- Set flag for entity of the library unit
10777 else
10778 Set_Has_All_Calls_Remote (Lib_Entity);
10779 end if;
10781 end if;
10782 end All_Calls_Remote;
10784 ---------------------------
10785 -- Allow_Integer_Address --
10786 ---------------------------
10788 -- pragma Allow_Integer_Address;
10790 when Pragma_Allow_Integer_Address =>
10791 GNAT_Pragma;
10792 Check_Valid_Configuration_Pragma;
10793 Check_Arg_Count (0);
10795 -- If Address is a private type, then set the flag to allow
10796 -- integer address values. If Address is not private, then this
10797 -- pragma has no purpose, so it is simply ignored. Not clear if
10798 -- there are any such targets now.
10800 if Opt.Address_Is_Private then
10801 Opt.Allow_Integer_Address := True;
10802 end if;
10804 --------------
10805 -- Annotate --
10806 --------------
10808 -- pragma Annotate
10809 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
10810 -- ARG ::= NAME | EXPRESSION
10812 -- The first two arguments are by convention intended to refer to an
10813 -- external tool and a tool-specific function. These arguments are
10814 -- not analyzed.
10816 when Pragma_Annotate => Annotate : declare
10817 Arg : Node_Id;
10818 Exp : Node_Id;
10820 begin
10821 GNAT_Pragma;
10822 Check_At_Least_N_Arguments (1);
10824 -- See if last argument is Entity => local_Name, and if so process
10825 -- and then remove it for remaining processing.
10827 declare
10828 Last_Arg : constant Node_Id :=
10829 Last (Pragma_Argument_Associations (N));
10831 begin
10832 if Nkind (Last_Arg) = N_Pragma_Argument_Association
10833 and then Chars (Last_Arg) = Name_Entity
10834 then
10835 Check_Arg_Is_Local_Name (Last_Arg);
10836 Arg_Count := Arg_Count - 1;
10838 -- Not allowed in compiler units (bootstrap issues)
10840 Check_Compiler_Unit ("Entity for pragma Annotate", N);
10841 end if;
10842 end;
10844 -- Continue processing with last argument removed for now
10846 Check_Arg_Is_Identifier (Arg1);
10847 Check_No_Identifiers;
10848 Store_Note (N);
10850 -- Second parameter is optional, it is never analyzed
10852 if No (Arg2) then
10853 null;
10855 -- Here if we have a second parameter
10857 else
10858 -- Second parameter must be identifier
10860 Check_Arg_Is_Identifier (Arg2);
10862 -- Process remaining parameters if any
10864 Arg := Next (Arg2);
10865 while Present (Arg) loop
10866 Exp := Get_Pragma_Arg (Arg);
10867 Analyze (Exp);
10869 if Is_Entity_Name (Exp) then
10870 null;
10872 -- For string literals, we assume Standard_String as the
10873 -- type, unless the string contains wide or wide_wide
10874 -- characters.
10876 elsif Nkind (Exp) = N_String_Literal then
10877 if Has_Wide_Wide_Character (Exp) then
10878 Resolve (Exp, Standard_Wide_Wide_String);
10879 elsif Has_Wide_Character (Exp) then
10880 Resolve (Exp, Standard_Wide_String);
10881 else
10882 Resolve (Exp, Standard_String);
10883 end if;
10885 elsif Is_Overloaded (Exp) then
10886 Error_Pragma_Arg
10887 ("ambiguous argument for pragma%", Exp);
10889 else
10890 Resolve (Exp);
10891 end if;
10893 Next (Arg);
10894 end loop;
10895 end if;
10896 end Annotate;
10898 -------------------------------------------------
10899 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
10900 -------------------------------------------------
10902 -- pragma Assert
10903 -- ( [Check => ] Boolean_EXPRESSION
10904 -- [, [Message =>] Static_String_EXPRESSION]);
10906 -- pragma Assert_And_Cut
10907 -- ( [Check => ] Boolean_EXPRESSION
10908 -- [, [Message =>] Static_String_EXPRESSION]);
10910 -- pragma Assume
10911 -- ( [Check => ] Boolean_EXPRESSION
10912 -- [, [Message =>] Static_String_EXPRESSION]);
10914 -- pragma Loop_Invariant
10915 -- ( [Check => ] Boolean_EXPRESSION
10916 -- [, [Message =>] Static_String_EXPRESSION]);
10918 when Pragma_Assert |
10919 Pragma_Assert_And_Cut |
10920 Pragma_Assume |
10921 Pragma_Loop_Invariant =>
10922 Assert : declare
10923 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
10924 -- Determine whether expression Expr contains a Loop_Entry
10925 -- attribute reference.
10927 -------------------------
10928 -- Contains_Loop_Entry --
10929 -------------------------
10931 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
10932 Has_Loop_Entry : Boolean := False;
10934 function Process (N : Node_Id) return Traverse_Result;
10935 -- Process function for traversal to look for Loop_Entry
10937 -------------
10938 -- Process --
10939 -------------
10941 function Process (N : Node_Id) return Traverse_Result is
10942 begin
10943 if Nkind (N) = N_Attribute_Reference
10944 and then Attribute_Name (N) = Name_Loop_Entry
10945 then
10946 Has_Loop_Entry := True;
10947 return Abandon;
10948 else
10949 return OK;
10950 end if;
10951 end Process;
10953 procedure Traverse is new Traverse_Proc (Process);
10955 -- Start of processing for Contains_Loop_Entry
10957 begin
10958 Traverse (Expr);
10959 return Has_Loop_Entry;
10960 end Contains_Loop_Entry;
10962 -- Local variables
10964 Expr : Node_Id;
10965 Newa : List_Id;
10967 -- Start of processing for Assert
10969 begin
10970 -- Assert is an Ada 2005 RM-defined pragma
10972 if Prag_Id = Pragma_Assert then
10973 Ada_2005_Pragma;
10975 -- The remaining ones are GNAT pragmas
10977 else
10978 GNAT_Pragma;
10979 end if;
10981 Check_At_Least_N_Arguments (1);
10982 Check_At_Most_N_Arguments (2);
10983 Check_Arg_Order ((Name_Check, Name_Message));
10984 Check_Optional_Identifier (Arg1, Name_Check);
10985 Expr := Get_Pragma_Arg (Arg1);
10987 -- Special processing for Loop_Invariant, Loop_Variant or for
10988 -- other cases where a Loop_Entry attribute is present. If the
10989 -- assertion pragma contains attribute Loop_Entry, ensure that
10990 -- the related pragma is within a loop.
10992 if Prag_Id = Pragma_Loop_Invariant
10993 or else Prag_Id = Pragma_Loop_Variant
10994 or else Contains_Loop_Entry (Expr)
10995 then
10996 Check_Loop_Pragma_Placement;
10998 -- Perform preanalysis to deal with embedded Loop_Entry
10999 -- attributes.
11001 Preanalyze_Assert_Expression (Expression (Arg1), Any_Boolean);
11002 end if;
11004 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
11005 -- a corresponding Check pragma:
11007 -- pragma Check (name, condition [, msg]);
11009 -- Where name is the identifier matching the pragma name. So
11010 -- rewrite pragma in this manner, transfer the message argument
11011 -- if present, and analyze the result
11013 -- Note: When dealing with a semantically analyzed tree, the
11014 -- information that a Check node N corresponds to a source Assert,
11015 -- Assume, or Assert_And_Cut pragma can be retrieved from the
11016 -- pragma kind of Original_Node(N).
11018 Newa := New_List (
11019 Make_Pragma_Argument_Association (Loc,
11020 Expression => Make_Identifier (Loc, Pname)),
11021 Make_Pragma_Argument_Association (Sloc (Expr),
11022 Expression => Expr));
11024 if Arg_Count > 1 then
11025 Check_Optional_Identifier (Arg2, Name_Message);
11027 -- Provide semantic annnotations for optional argument, for
11028 -- ASIS use, before rewriting.
11030 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
11031 Append_To (Newa, New_Copy_Tree (Arg2));
11032 end if;
11034 -- Rewrite as Check pragma
11036 Rewrite (N,
11037 Make_Pragma (Loc,
11038 Chars => Name_Check,
11039 Pragma_Argument_Associations => Newa));
11040 Analyze (N);
11041 end Assert;
11043 ----------------------
11044 -- Assertion_Policy --
11045 ----------------------
11047 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
11049 -- The following form is Ada 2012 only, but we allow it in all modes
11051 -- Pragma Assertion_Policy (
11052 -- ASSERTION_KIND => POLICY_IDENTIFIER
11053 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
11055 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
11057 -- RM_ASSERTION_KIND ::= Assert |
11058 -- Static_Predicate |
11059 -- Dynamic_Predicate |
11060 -- Pre |
11061 -- Pre'Class |
11062 -- Post |
11063 -- Post'Class |
11064 -- Type_Invariant |
11065 -- Type_Invariant'Class
11067 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
11068 -- Assume |
11069 -- Contract_Cases |
11070 -- Debug |
11071 -- Default_Initial_Condition |
11072 -- Ghost |
11073 -- Initial_Condition |
11074 -- Loop_Invariant |
11075 -- Loop_Variant |
11076 -- Postcondition |
11077 -- Precondition |
11078 -- Predicate |
11079 -- Refined_Post |
11080 -- Statement_Assertions
11082 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
11083 -- ID_ASSERTION_KIND list contains implementation-defined additions
11084 -- recognized by GNAT. The effect is to control the behavior of
11085 -- identically named aspects and pragmas, depending on the specified
11086 -- policy identifier:
11088 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore
11090 -- Note: Check and Ignore are language-defined. Disable is a GNAT
11091 -- implementation defined addition that results in totally ignoring
11092 -- the corresponding assertion. If Disable is specified, then the
11093 -- argument of the assertion is not even analyzed. This is useful
11094 -- when the aspect/pragma argument references entities in a with'ed
11095 -- package that is replaced by a dummy package in the final build.
11097 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
11098 -- and Type_Invariant'Class were recognized by the parser and
11099 -- transformed into references to the special internal identifiers
11100 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
11101 -- processing is required here.
11103 when Pragma_Assertion_Policy => Assertion_Policy : declare
11104 LocP : Source_Ptr;
11105 Policy : Node_Id;
11106 Arg : Node_Id;
11107 Kind : Name_Id;
11109 begin
11110 Ada_2005_Pragma;
11112 -- This can always appear as a configuration pragma
11114 if Is_Configuration_Pragma then
11115 null;
11117 -- It can also appear in a declarative part or package spec in Ada
11118 -- 2012 mode. We allow this in other modes, but in that case we
11119 -- consider that we have an Ada 2012 pragma on our hands.
11121 else
11122 Check_Is_In_Decl_Part_Or_Package_Spec;
11123 Ada_2012_Pragma;
11124 end if;
11126 -- One argument case with no identifier (first form above)
11128 if Arg_Count = 1
11129 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
11130 or else Chars (Arg1) = No_Name)
11131 then
11132 Check_Arg_Is_One_Of
11133 (Arg1, Name_Check, Name_Disable, Name_Ignore);
11135 -- Treat one argument Assertion_Policy as equivalent to:
11137 -- pragma Check_Policy (Assertion, policy)
11139 -- So rewrite pragma in that manner and link on to the chain
11140 -- of Check_Policy pragmas, marking the pragma as analyzed.
11142 Policy := Get_Pragma_Arg (Arg1);
11144 Rewrite (N,
11145 Make_Pragma (Loc,
11146 Chars => Name_Check_Policy,
11147 Pragma_Argument_Associations => New_List (
11148 Make_Pragma_Argument_Association (Loc,
11149 Expression => Make_Identifier (Loc, Name_Assertion)),
11151 Make_Pragma_Argument_Association (Loc,
11152 Expression =>
11153 Make_Identifier (Sloc (Policy), Chars (Policy))))));
11154 Analyze (N);
11156 -- Here if we have two or more arguments
11158 else
11159 Check_At_Least_N_Arguments (1);
11160 Ada_2012_Pragma;
11162 -- Loop through arguments
11164 Arg := Arg1;
11165 while Present (Arg) loop
11166 LocP := Sloc (Arg);
11168 -- Kind must be specified
11170 if Nkind (Arg) /= N_Pragma_Argument_Association
11171 or else Chars (Arg) = No_Name
11172 then
11173 Error_Pragma_Arg
11174 ("missing assertion kind for pragma%", Arg);
11175 end if;
11177 -- Check Kind and Policy have allowed forms
11179 Kind := Chars (Arg);
11181 if not Is_Valid_Assertion_Kind (Kind) then
11182 Error_Pragma_Arg
11183 ("invalid assertion kind for pragma%", Arg);
11184 end if;
11186 Check_Arg_Is_One_Of
11187 (Arg, Name_Check, Name_Disable, Name_Ignore);
11189 -- We rewrite the Assertion_Policy pragma as a series of
11190 -- Check_Policy pragmas:
11192 -- Check_Policy (Kind, Policy);
11194 Insert_Action (N,
11195 Make_Pragma (LocP,
11196 Chars => Name_Check_Policy,
11197 Pragma_Argument_Associations => New_List (
11198 Make_Pragma_Argument_Association (LocP,
11199 Expression => Make_Identifier (LocP, Kind)),
11200 Make_Pragma_Argument_Association (LocP,
11201 Expression => Get_Pragma_Arg (Arg)))));
11203 Arg := Next (Arg);
11204 end loop;
11206 -- Rewrite the Assertion_Policy pragma as null since we have
11207 -- now inserted all the equivalent Check pragmas.
11209 Rewrite (N, Make_Null_Statement (Loc));
11210 Analyze (N);
11211 end if;
11212 end Assertion_Policy;
11214 ------------------------------
11215 -- Assume_No_Invalid_Values --
11216 ------------------------------
11218 -- pragma Assume_No_Invalid_Values (On | Off);
11220 when Pragma_Assume_No_Invalid_Values =>
11221 GNAT_Pragma;
11222 Check_Valid_Configuration_Pragma;
11223 Check_Arg_Count (1);
11224 Check_No_Identifiers;
11225 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11227 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
11228 Assume_No_Invalid_Values := True;
11229 else
11230 Assume_No_Invalid_Values := False;
11231 end if;
11233 --------------------------
11234 -- Attribute_Definition --
11235 --------------------------
11237 -- pragma Attribute_Definition
11238 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
11239 -- [Entity =>] LOCAL_NAME,
11240 -- [Expression =>] EXPRESSION | NAME);
11242 when Pragma_Attribute_Definition => Attribute_Definition : declare
11243 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
11244 Aname : Name_Id;
11246 begin
11247 GNAT_Pragma;
11248 Check_Arg_Count (3);
11249 Check_Optional_Identifier (Arg1, "attribute");
11250 Check_Optional_Identifier (Arg2, "entity");
11251 Check_Optional_Identifier (Arg3, "expression");
11253 if Nkind (Attribute_Designator) /= N_Identifier then
11254 Error_Msg_N ("attribute name expected", Attribute_Designator);
11255 return;
11256 end if;
11258 Check_Arg_Is_Local_Name (Arg2);
11260 -- If the attribute is not recognized, then issue a warning (not
11261 -- an error), and ignore the pragma.
11263 Aname := Chars (Attribute_Designator);
11265 if not Is_Attribute_Name (Aname) then
11266 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
11267 return;
11268 end if;
11270 -- Otherwise, rewrite the pragma as an attribute definition clause
11272 Rewrite (N,
11273 Make_Attribute_Definition_Clause (Loc,
11274 Name => Get_Pragma_Arg (Arg2),
11275 Chars => Aname,
11276 Expression => Get_Pragma_Arg (Arg3)));
11277 Analyze (N);
11278 end Attribute_Definition;
11280 ------------------------------------------------------------------
11281 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
11282 ------------------------------------------------------------------
11284 -- pragma Asynch_Readers ( object_LOCAL_NAME [, FLAG] );
11285 -- pragma Asynch_Writers ( object_LOCAL_NAME [, FLAG] );
11286 -- pragma Effective_Reads ( object_LOCAL_NAME [, FLAG] );
11287 -- pragma Effective_Writes ( object_LOCAL_NAME [, FLAG] );
11289 -- FLAG ::= boolean_EXPRESSION
11291 when Pragma_Async_Readers |
11292 Pragma_Async_Writers |
11293 Pragma_Effective_Reads |
11294 Pragma_Effective_Writes =>
11295 Async_Effective : declare
11296 Duplic : Node_Id;
11297 Expr : Node_Id;
11298 Obj : Node_Id;
11299 Obj_Id : Entity_Id;
11301 begin
11302 GNAT_Pragma;
11303 Check_No_Identifiers;
11304 Check_At_Least_N_Arguments (1);
11305 Check_At_Most_N_Arguments (2);
11306 Check_Arg_Is_Local_Name (Arg1);
11307 Error_Msg_Name_1 := Pname;
11309 Obj := Get_Pragma_Arg (Arg1);
11310 Expr := Get_Pragma_Arg (Arg2);
11312 -- Perform minimal verification to ensure that the argument is at
11313 -- least a variable. Subsequent finer grained checks will be done
11314 -- at the end of the declarative region the contains the pragma.
11316 if Is_Entity_Name (Obj)
11317 and then Present (Entity (Obj))
11318 and then Ekind (Entity (Obj)) = E_Variable
11319 then
11320 Obj_Id := Entity (Obj);
11322 -- Detect a duplicate pragma. Note that it is not efficient to
11323 -- examine preceding statements as Boolean aspects may appear
11324 -- anywhere between the related object declaration and its
11325 -- freeze point. As an alternative, inspect the contents of the
11326 -- variable contract.
11328 Duplic := Get_Pragma (Obj_Id, Prag_Id);
11330 if Present (Duplic) then
11331 Error_Msg_Sloc := Sloc (Duplic);
11332 Error_Msg_N ("pragma % duplicates pragma declared #", N);
11334 -- No duplicate detected
11336 else
11337 if Present (Expr) then
11338 Preanalyze_And_Resolve (Expr, Standard_Boolean);
11339 end if;
11341 -- Chain the pragma on the contract for further processing
11343 Add_Contract_Item (N, Obj_Id);
11344 end if;
11345 else
11346 Error_Pragma ("pragma % must apply to a volatile object");
11347 end if;
11348 end Async_Effective;
11350 ------------------
11351 -- Asynchronous --
11352 ------------------
11354 -- pragma Asynchronous (LOCAL_NAME);
11356 when Pragma_Asynchronous => Asynchronous : declare
11357 Nm : Entity_Id;
11358 C_Ent : Entity_Id;
11359 L : List_Id;
11360 S : Node_Id;
11361 N : Node_Id;
11362 Formal : Entity_Id;
11364 procedure Process_Async_Pragma;
11365 -- Common processing for procedure and access-to-procedure case
11367 --------------------------
11368 -- Process_Async_Pragma --
11369 --------------------------
11371 procedure Process_Async_Pragma is
11372 begin
11373 if No (L) then
11374 Set_Is_Asynchronous (Nm);
11375 return;
11376 end if;
11378 -- The formals should be of mode IN (RM E.4.1(6))
11380 S := First (L);
11381 while Present (S) loop
11382 Formal := Defining_Identifier (S);
11384 if Nkind (Formal) = N_Defining_Identifier
11385 and then Ekind (Formal) /= E_In_Parameter
11386 then
11387 Error_Pragma_Arg
11388 ("pragma% procedure can only have IN parameter",
11389 Arg1);
11390 end if;
11392 Next (S);
11393 end loop;
11395 Set_Is_Asynchronous (Nm);
11396 end Process_Async_Pragma;
11398 -- Start of processing for pragma Asynchronous
11400 begin
11401 Check_Ada_83_Warning;
11402 Check_No_Identifiers;
11403 Check_Arg_Count (1);
11404 Check_Arg_Is_Local_Name (Arg1);
11406 if Debug_Flag_U then
11407 return;
11408 end if;
11410 C_Ent := Cunit_Entity (Current_Sem_Unit);
11411 Analyze (Get_Pragma_Arg (Arg1));
11412 Nm := Entity (Get_Pragma_Arg (Arg1));
11414 if not Is_Remote_Call_Interface (C_Ent)
11415 and then not Is_Remote_Types (C_Ent)
11416 then
11417 -- This pragma should only appear in an RCI or Remote Types
11418 -- unit (RM E.4.1(4)).
11420 Error_Pragma
11421 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
11422 end if;
11424 if Ekind (Nm) = E_Procedure
11425 and then Nkind (Parent (Nm)) = N_Procedure_Specification
11426 then
11427 if not Is_Remote_Call_Interface (Nm) then
11428 Error_Pragma_Arg
11429 ("pragma% cannot be applied on non-remote procedure",
11430 Arg1);
11431 end if;
11433 L := Parameter_Specifications (Parent (Nm));
11434 Process_Async_Pragma;
11435 return;
11437 elsif Ekind (Nm) = E_Function then
11438 Error_Pragma_Arg
11439 ("pragma% cannot be applied to function", Arg1);
11441 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
11442 if Is_Record_Type (Nm) then
11444 -- A record type that is the Equivalent_Type for a remote
11445 -- access-to-subprogram type.
11447 N := Declaration_Node (Corresponding_Remote_Type (Nm));
11449 else
11450 -- A non-expanded RAS type (distribution is not enabled)
11452 N := Declaration_Node (Nm);
11453 end if;
11455 if Nkind (N) = N_Full_Type_Declaration
11456 and then Nkind (Type_Definition (N)) =
11457 N_Access_Procedure_Definition
11458 then
11459 L := Parameter_Specifications (Type_Definition (N));
11460 Process_Async_Pragma;
11462 if Is_Asynchronous (Nm)
11463 and then Expander_Active
11464 and then Get_PCS_Name /= Name_No_DSA
11465 then
11466 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
11467 end if;
11469 else
11470 Error_Pragma_Arg
11471 ("pragma% cannot reference access-to-function type",
11472 Arg1);
11473 end if;
11475 -- Only other possibility is Access-to-class-wide type
11477 elsif Is_Access_Type (Nm)
11478 and then Is_Class_Wide_Type (Designated_Type (Nm))
11479 then
11480 Check_First_Subtype (Arg1);
11481 Set_Is_Asynchronous (Nm);
11482 if Expander_Active then
11483 RACW_Type_Is_Asynchronous (Nm);
11484 end if;
11486 else
11487 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
11488 end if;
11489 end Asynchronous;
11491 ------------
11492 -- Atomic --
11493 ------------
11495 -- pragma Atomic (LOCAL_NAME);
11497 when Pragma_Atomic =>
11498 Process_Atomic_Shared_Volatile;
11500 -----------------------
11501 -- Atomic_Components --
11502 -----------------------
11504 -- pragma Atomic_Components (array_LOCAL_NAME);
11506 -- This processing is shared by Volatile_Components
11508 when Pragma_Atomic_Components |
11509 Pragma_Volatile_Components =>
11511 Atomic_Components : declare
11512 E_Id : Node_Id;
11513 E : Entity_Id;
11514 D : Node_Id;
11515 K : Node_Kind;
11517 begin
11518 Check_Ada_83_Warning;
11519 Check_No_Identifiers;
11520 Check_Arg_Count (1);
11521 Check_Arg_Is_Local_Name (Arg1);
11522 E_Id := Get_Pragma_Arg (Arg1);
11524 if Etype (E_Id) = Any_Type then
11525 return;
11526 end if;
11528 E := Entity (E_Id);
11530 Check_Duplicate_Pragma (E);
11532 if Rep_Item_Too_Early (E, N)
11533 or else
11534 Rep_Item_Too_Late (E, N)
11535 then
11536 return;
11537 end if;
11539 D := Declaration_Node (E);
11540 K := Nkind (D);
11542 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
11543 or else
11544 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
11545 and then Nkind (D) = N_Object_Declaration
11546 and then Nkind (Object_Definition (D)) =
11547 N_Constrained_Array_Definition)
11548 then
11549 -- The flag is set on the object, or on the base type
11551 if Nkind (D) /= N_Object_Declaration then
11552 E := Base_Type (E);
11553 end if;
11555 Set_Has_Volatile_Components (E);
11557 if Prag_Id = Pragma_Atomic_Components then
11558 Set_Has_Atomic_Components (E);
11559 end if;
11561 else
11562 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
11563 end if;
11564 end Atomic_Components;
11566 --------------------
11567 -- Attach_Handler --
11568 --------------------
11570 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
11572 when Pragma_Attach_Handler =>
11573 Check_Ada_83_Warning;
11574 Check_No_Identifiers;
11575 Check_Arg_Count (2);
11577 if No_Run_Time_Mode then
11578 Error_Msg_CRT ("Attach_Handler pragma", N);
11579 else
11580 Check_Interrupt_Or_Attach_Handler;
11582 -- The expression that designates the attribute may depend on a
11583 -- discriminant, and is therefore a per-object expression, to
11584 -- be expanded in the init proc. If expansion is enabled, then
11585 -- perform semantic checks on a copy only.
11587 declare
11588 Temp : Node_Id;
11589 Typ : Node_Id;
11590 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
11592 begin
11593 -- In Relaxed_RM_Semantics mode, we allow any static
11594 -- integer value, for compatibility with other compilers.
11596 if Relaxed_RM_Semantics
11597 and then Nkind (Parg2) = N_Integer_Literal
11598 then
11599 Typ := Standard_Integer;
11600 else
11601 Typ := RTE (RE_Interrupt_ID);
11602 end if;
11604 if Expander_Active then
11605 Temp := New_Copy_Tree (Parg2);
11606 Set_Parent (Temp, N);
11607 Preanalyze_And_Resolve (Temp, Typ);
11608 else
11609 Analyze (Parg2);
11610 Resolve (Parg2, Typ);
11611 end if;
11612 end;
11614 Process_Interrupt_Or_Attach_Handler;
11615 end if;
11617 --------------------
11618 -- C_Pass_By_Copy --
11619 --------------------
11621 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
11623 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
11624 Arg : Node_Id;
11625 Val : Uint;
11627 begin
11628 GNAT_Pragma;
11629 Check_Valid_Configuration_Pragma;
11630 Check_Arg_Count (1);
11631 Check_Optional_Identifier (Arg1, "max_size");
11633 Arg := Get_Pragma_Arg (Arg1);
11634 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
11636 Val := Expr_Value (Arg);
11638 if Val <= 0 then
11639 Error_Pragma_Arg
11640 ("maximum size for pragma% must be positive", Arg1);
11642 elsif UI_Is_In_Int_Range (Val) then
11643 Default_C_Record_Mechanism := UI_To_Int (Val);
11645 -- If a giant value is given, Int'Last will do well enough.
11646 -- If sometime someone complains that a record larger than
11647 -- two gigabytes is not copied, we will worry about it then.
11649 else
11650 Default_C_Record_Mechanism := Mechanism_Type'Last;
11651 end if;
11652 end C_Pass_By_Copy;
11654 -----------
11655 -- Check --
11656 -----------
11658 -- pragma Check ([Name =>] CHECK_KIND,
11659 -- [Check =>] Boolean_EXPRESSION
11660 -- [,[Message =>] String_EXPRESSION]);
11662 -- CHECK_KIND ::= IDENTIFIER |
11663 -- Pre'Class |
11664 -- Post'Class |
11665 -- Invariant'Class |
11666 -- Type_Invariant'Class
11668 -- The identifiers Assertions and Statement_Assertions are not
11669 -- allowed, since they have special meaning for Check_Policy.
11671 when Pragma_Check => Check : declare
11672 Expr : Node_Id;
11673 Eloc : Source_Ptr;
11674 Cname : Name_Id;
11675 Str : Node_Id;
11677 begin
11678 GNAT_Pragma;
11679 Check_At_Least_N_Arguments (2);
11680 Check_At_Most_N_Arguments (3);
11681 Check_Optional_Identifier (Arg1, Name_Name);
11682 Check_Optional_Identifier (Arg2, Name_Check);
11684 if Arg_Count = 3 then
11685 Check_Optional_Identifier (Arg3, Name_Message);
11686 Str := Get_Pragma_Arg (Arg3);
11687 end if;
11689 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
11690 Check_Arg_Is_Identifier (Arg1);
11691 Cname := Chars (Get_Pragma_Arg (Arg1));
11693 -- Check forbidden name Assertions or Statement_Assertions
11695 case Cname is
11696 when Name_Assertions =>
11697 Error_Pragma_Arg
11698 ("""Assertions"" is not allowed as a check kind "
11699 & "for pragma%", Arg1);
11701 when Name_Statement_Assertions =>
11702 Error_Pragma_Arg
11703 ("""Statement_Assertions"" is not allowed as a check kind "
11704 & "for pragma%", Arg1);
11706 when others =>
11707 null;
11708 end case;
11710 -- Check applicable policy. We skip this if Checked/Ignored status
11711 -- is already set (e.g. in the casse of a pragma from an aspect).
11713 if Is_Checked (N) or else Is_Ignored (N) then
11714 null;
11716 -- For a non-source pragma that is a rewriting of another pragma,
11717 -- copy the Is_Checked/Ignored status from the rewritten pragma.
11719 elsif Is_Rewrite_Substitution (N)
11720 and then Nkind (Original_Node (N)) = N_Pragma
11721 and then Original_Node (N) /= N
11722 then
11723 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
11724 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
11726 -- Otherwise query the applicable policy at this point
11728 else
11729 case Check_Kind (Cname) is
11730 when Name_Ignore =>
11731 Set_Is_Ignored (N, True);
11732 Set_Is_Checked (N, False);
11734 when Name_Check =>
11735 Set_Is_Ignored (N, False);
11736 Set_Is_Checked (N, True);
11738 -- For disable, rewrite pragma as null statement and skip
11739 -- rest of the analysis of the pragma.
11741 when Name_Disable =>
11742 Rewrite (N, Make_Null_Statement (Loc));
11743 Analyze (N);
11744 raise Pragma_Exit;
11746 -- No other possibilities
11748 when others =>
11749 raise Program_Error;
11750 end case;
11751 end if;
11753 -- If check kind was not Disable, then continue pragma analysis
11755 Expr := Get_Pragma_Arg (Arg2);
11757 -- Deal with SCO generation
11759 case Cname is
11760 when Name_Predicate |
11761 Name_Invariant =>
11763 -- Nothing to do: since checks occur in client units,
11764 -- the SCO for the aspect in the declaration unit is
11765 -- conservatively always enabled.
11767 null;
11769 when others =>
11771 if Is_Checked (N) and then not Split_PPC (N) then
11773 -- Mark aspect/pragma SCO as enabled
11775 Set_SCO_Pragma_Enabled (Loc);
11776 end if;
11777 end case;
11779 -- Deal with analyzing the string argument.
11781 if Arg_Count = 3 then
11783 -- If checks are not on we don't want any expansion (since
11784 -- such expansion would not get properly deleted) but
11785 -- we do want to analyze (to get proper references).
11786 -- The Preanalyze_And_Resolve routine does just what we want
11788 if Is_Ignored (N) then
11789 Preanalyze_And_Resolve (Str, Standard_String);
11791 -- Otherwise we need a proper analysis and expansion
11793 else
11794 Analyze_And_Resolve (Str, Standard_String);
11795 end if;
11796 end if;
11798 -- Now you might think we could just do the same with the Boolean
11799 -- expression if checks are off (and expansion is on) and then
11800 -- rewrite the check as a null statement. This would work but we
11801 -- would lose the useful warnings about an assertion being bound
11802 -- to fail even if assertions are turned off.
11804 -- So instead we wrap the boolean expression in an if statement
11805 -- that looks like:
11807 -- if False and then condition then
11808 -- null;
11809 -- end if;
11811 -- The reason we do this rewriting during semantic analysis rather
11812 -- than as part of normal expansion is that we cannot analyze and
11813 -- expand the code for the boolean expression directly, or it may
11814 -- cause insertion of actions that would escape the attempt to
11815 -- suppress the check code.
11817 -- Note that the Sloc for the if statement corresponds to the
11818 -- argument condition, not the pragma itself. The reason for
11819 -- this is that we may generate a warning if the condition is
11820 -- False at compile time, and we do not want to delete this
11821 -- warning when we delete the if statement.
11823 if Expander_Active and Is_Ignored (N) then
11824 Eloc := Sloc (Expr);
11826 Rewrite (N,
11827 Make_If_Statement (Eloc,
11828 Condition =>
11829 Make_And_Then (Eloc,
11830 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
11831 Right_Opnd => Expr),
11832 Then_Statements => New_List (
11833 Make_Null_Statement (Eloc))));
11835 In_Assertion_Expr := In_Assertion_Expr + 1;
11836 Analyze (N);
11837 In_Assertion_Expr := In_Assertion_Expr - 1;
11839 -- Check is active or expansion not active. In these cases we can
11840 -- just go ahead and analyze the boolean with no worries.
11842 else
11843 In_Assertion_Expr := In_Assertion_Expr + 1;
11844 Analyze_And_Resolve (Expr, Any_Boolean);
11845 In_Assertion_Expr := In_Assertion_Expr - 1;
11846 end if;
11847 end Check;
11849 --------------------------
11850 -- Check_Float_Overflow --
11851 --------------------------
11853 -- pragma Check_Float_Overflow;
11855 when Pragma_Check_Float_Overflow =>
11856 GNAT_Pragma;
11857 Check_Valid_Configuration_Pragma;
11858 Check_Arg_Count (0);
11859 Check_Float_Overflow := not Machine_Overflows_On_Target;
11861 ----------------
11862 -- Check_Name --
11863 ----------------
11865 -- pragma Check_Name (check_IDENTIFIER);
11867 when Pragma_Check_Name =>
11868 GNAT_Pragma;
11869 Check_No_Identifiers;
11870 Check_Valid_Configuration_Pragma;
11871 Check_Arg_Count (1);
11872 Check_Arg_Is_Identifier (Arg1);
11874 declare
11875 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11877 begin
11878 for J in Check_Names.First .. Check_Names.Last loop
11879 if Check_Names.Table (J) = Nam then
11880 return;
11881 end if;
11882 end loop;
11884 Check_Names.Append (Nam);
11885 end;
11887 ------------------
11888 -- Check_Policy --
11889 ------------------
11891 -- This is the old style syntax, which is still allowed in all modes:
11893 -- pragma Check_Policy ([Name =>] CHECK_KIND
11894 -- [Policy =>] POLICY_IDENTIFIER);
11896 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
11898 -- CHECK_KIND ::= IDENTIFIER |
11899 -- Pre'Class |
11900 -- Post'Class |
11901 -- Type_Invariant'Class |
11902 -- Invariant'Class
11904 -- This is the new style syntax, compatible with Assertion_Policy
11905 -- and also allowed in all modes.
11907 -- Pragma Check_Policy (
11908 -- CHECK_KIND => POLICY_IDENTIFIER
11909 -- {, CHECK_KIND => POLICY_IDENTIFIER});
11911 -- Note: the identifiers Name and Policy are not allowed as
11912 -- Check_Kind values. This avoids ambiguities between the old and
11913 -- new form syntax.
11915 when Pragma_Check_Policy => Check_Policy : declare
11916 Ident : Node_Id;
11917 Kind : Node_Id;
11919 begin
11920 GNAT_Pragma;
11921 Check_At_Least_N_Arguments (1);
11923 -- A Check_Policy pragma can appear either as a configuration
11924 -- pragma, or in a declarative part or a package spec (see RM
11925 -- 11.5(5) for rules for Suppress/Unsuppress which are also
11926 -- followed for Check_Policy).
11928 if not Is_Configuration_Pragma then
11929 Check_Is_In_Decl_Part_Or_Package_Spec;
11930 end if;
11932 -- Figure out if we have the old or new syntax. We have the
11933 -- old syntax if the first argument has no identifier, or the
11934 -- identifier is Name.
11936 if Nkind (Arg1) /= N_Pragma_Argument_Association
11937 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
11938 then
11939 -- Old syntax
11941 Check_Arg_Count (2);
11942 Check_Optional_Identifier (Arg1, Name_Name);
11943 Kind := Get_Pragma_Arg (Arg1);
11944 Rewrite_Assertion_Kind (Kind);
11945 Check_Arg_Is_Identifier (Arg1);
11947 -- Check forbidden check kind
11949 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
11950 Error_Msg_Name_2 := Chars (Kind);
11951 Error_Pragma_Arg
11952 ("pragma% does not allow% as check name", Arg1);
11953 end if;
11955 -- Check policy
11957 Check_Optional_Identifier (Arg2, Name_Policy);
11958 Check_Arg_Is_One_Of
11959 (Arg2,
11960 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
11961 Ident := Get_Pragma_Arg (Arg2);
11963 if Chars (Kind) = Name_Ghost then
11965 -- Pragma Check_Policy specifying a Ghost policy cannot
11966 -- occur within a ghost subprogram or package.
11968 if Within_Ghost_Scope then
11969 Error_Pragma
11970 ("pragma % cannot appear within ghost subprogram or "
11971 & "package");
11973 -- The policy identifier of pragma Ghost must be either
11974 -- Check or Ignore (SPARK RM 6.9(7)).
11976 elsif not Nam_In (Chars (Ident), Name_Check,
11977 Name_Ignore)
11978 then
11979 Error_Pragma_Arg
11980 ("argument of pragma % Ghost must be Check or Ignore",
11981 Arg2);
11982 end if;
11983 end if;
11985 -- And chain pragma on the Check_Policy_List for search
11987 Set_Next_Pragma (N, Opt.Check_Policy_List);
11988 Opt.Check_Policy_List := N;
11990 -- For the new syntax, what we do is to convert each argument to
11991 -- an old syntax equivalent. We do that because we want to chain
11992 -- old style Check_Policy pragmas for the search (we don't want
11993 -- to have to deal with multiple arguments in the search).
11995 else
11996 declare
11997 Arg : Node_Id;
11998 Argx : Node_Id;
11999 LocP : Source_Ptr;
12001 begin
12002 Arg := Arg1;
12003 while Present (Arg) loop
12004 LocP := Sloc (Arg);
12005 Argx := Get_Pragma_Arg (Arg);
12007 -- Kind must be specified
12009 if Nkind (Arg) /= N_Pragma_Argument_Association
12010 or else Chars (Arg) = No_Name
12011 then
12012 Error_Pragma_Arg
12013 ("missing assertion kind for pragma%", Arg);
12014 end if;
12016 -- Construct equivalent old form syntax Check_Policy
12017 -- pragma and insert it to get remaining checks.
12019 Insert_Action (N,
12020 Make_Pragma (LocP,
12021 Chars => Name_Check_Policy,
12022 Pragma_Argument_Associations => New_List (
12023 Make_Pragma_Argument_Association (LocP,
12024 Expression =>
12025 Make_Identifier (LocP, Chars (Arg))),
12026 Make_Pragma_Argument_Association (Sloc (Argx),
12027 Expression => Argx))));
12029 Arg := Next (Arg);
12030 end loop;
12032 -- Rewrite original Check_Policy pragma to null, since we
12033 -- have converted it into a series of old syntax pragmas.
12035 Rewrite (N, Make_Null_Statement (Loc));
12036 Analyze (N);
12037 end;
12038 end if;
12039 end Check_Policy;
12041 ---------------------
12042 -- CIL_Constructor --
12043 ---------------------
12045 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
12047 -- Processing for this pragma is shared with Java_Constructor
12049 -------------
12050 -- Comment --
12051 -------------
12053 -- pragma Comment (static_string_EXPRESSION)
12055 -- Processing for pragma Comment shares the circuitry for pragma
12056 -- Ident. The only differences are that Ident enforces a limit of 31
12057 -- characters on its argument, and also enforces limitations on
12058 -- placement for DEC compatibility. Pragma Comment shares neither of
12059 -- these restrictions.
12061 -------------------
12062 -- Common_Object --
12063 -------------------
12065 -- pragma Common_Object (
12066 -- [Internal =>] LOCAL_NAME
12067 -- [, [External =>] EXTERNAL_SYMBOL]
12068 -- [, [Size =>] EXTERNAL_SYMBOL]);
12070 -- Processing for this pragma is shared with Psect_Object
12072 ------------------------
12073 -- Compile_Time_Error --
12074 ------------------------
12076 -- pragma Compile_Time_Error
12077 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12079 when Pragma_Compile_Time_Error =>
12080 GNAT_Pragma;
12081 Process_Compile_Time_Warning_Or_Error;
12083 --------------------------
12084 -- Compile_Time_Warning --
12085 --------------------------
12087 -- pragma Compile_Time_Warning
12088 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12090 when Pragma_Compile_Time_Warning =>
12091 GNAT_Pragma;
12092 Process_Compile_Time_Warning_Or_Error;
12094 ---------------------------
12095 -- Compiler_Unit_Warning --
12096 ---------------------------
12098 -- pragma Compiler_Unit_Warning;
12100 -- Historical note
12102 -- Originally, we had only pragma Compiler_Unit, and it resulted in
12103 -- errors not warnings. This means that we had introduced a big extra
12104 -- inertia to compiler changes, since even if we implemented a new
12105 -- feature, and even if all versions to be used for bootstrapping
12106 -- implemented this new feature, we could not use it, since old
12107 -- compilers would give errors for using this feature in units
12108 -- having Compiler_Unit pragmas.
12110 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
12111 -- problem. We no longer have any units mentioning Compiler_Unit,
12112 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
12113 -- and thus generates a warning which can be ignored. So that deals
12114 -- with the problem of old compilers not implementing the newer form
12115 -- of the pragma.
12117 -- Newer compilers recognize the new pragma, but generate warning
12118 -- messages instead of errors, which again can be ignored in the
12119 -- case of an old compiler which implements a wanted new feature
12120 -- but at the time felt like warning about it for older compilers.
12122 -- We retain Compiler_Unit so that new compilers can be used to build
12123 -- older run-times that use this pragma. That's an unusual case, but
12124 -- it's easy enough to handle, so why not?
12126 when Pragma_Compiler_Unit | Pragma_Compiler_Unit_Warning =>
12127 GNAT_Pragma;
12128 Check_Arg_Count (0);
12130 -- Only recognized in main unit
12132 if Current_Sem_Unit = Main_Unit then
12133 Compiler_Unit := True;
12134 end if;
12136 -----------------------------
12137 -- Complete_Representation --
12138 -----------------------------
12140 -- pragma Complete_Representation;
12142 when Pragma_Complete_Representation =>
12143 GNAT_Pragma;
12144 Check_Arg_Count (0);
12146 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
12147 Error_Pragma
12148 ("pragma & must appear within record representation clause");
12149 end if;
12151 ----------------------------
12152 -- Complex_Representation --
12153 ----------------------------
12155 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
12157 when Pragma_Complex_Representation => Complex_Representation : declare
12158 E_Id : Entity_Id;
12159 E : Entity_Id;
12160 Ent : Entity_Id;
12162 begin
12163 GNAT_Pragma;
12164 Check_Arg_Count (1);
12165 Check_Optional_Identifier (Arg1, Name_Entity);
12166 Check_Arg_Is_Local_Name (Arg1);
12167 E_Id := Get_Pragma_Arg (Arg1);
12169 if Etype (E_Id) = Any_Type then
12170 return;
12171 end if;
12173 E := Entity (E_Id);
12175 if not Is_Record_Type (E) then
12176 Error_Pragma_Arg
12177 ("argument for pragma% must be record type", Arg1);
12178 end if;
12180 Ent := First_Entity (E);
12182 if No (Ent)
12183 or else No (Next_Entity (Ent))
12184 or else Present (Next_Entity (Next_Entity (Ent)))
12185 or else not Is_Floating_Point_Type (Etype (Ent))
12186 or else Etype (Ent) /= Etype (Next_Entity (Ent))
12187 then
12188 Error_Pragma_Arg
12189 ("record for pragma% must have two fields of the same "
12190 & "floating-point type", Arg1);
12192 else
12193 Set_Has_Complex_Representation (Base_Type (E));
12195 -- We need to treat the type has having a non-standard
12196 -- representation, for back-end purposes, even though in
12197 -- general a complex will have the default representation
12198 -- of a record with two real components.
12200 Set_Has_Non_Standard_Rep (Base_Type (E));
12201 end if;
12202 end Complex_Representation;
12204 -------------------------
12205 -- Component_Alignment --
12206 -------------------------
12208 -- pragma Component_Alignment (
12209 -- [Form =>] ALIGNMENT_CHOICE
12210 -- [, [Name =>] type_LOCAL_NAME]);
12212 -- ALIGNMENT_CHOICE ::=
12213 -- Component_Size
12214 -- | Component_Size_4
12215 -- | Storage_Unit
12216 -- | Default
12218 when Pragma_Component_Alignment => Component_AlignmentP : declare
12219 Args : Args_List (1 .. 2);
12220 Names : constant Name_List (1 .. 2) := (
12221 Name_Form,
12222 Name_Name);
12224 Form : Node_Id renames Args (1);
12225 Name : Node_Id renames Args (2);
12227 Atype : Component_Alignment_Kind;
12228 Typ : Entity_Id;
12230 begin
12231 GNAT_Pragma;
12232 Gather_Associations (Names, Args);
12234 if No (Form) then
12235 Error_Pragma ("missing Form argument for pragma%");
12236 end if;
12238 Check_Arg_Is_Identifier (Form);
12240 -- Get proper alignment, note that Default = Component_Size on all
12241 -- machines we have so far, and we want to set this value rather
12242 -- than the default value to indicate that it has been explicitly
12243 -- set (and thus will not get overridden by the default component
12244 -- alignment for the current scope)
12246 if Chars (Form) = Name_Component_Size then
12247 Atype := Calign_Component_Size;
12249 elsif Chars (Form) = Name_Component_Size_4 then
12250 Atype := Calign_Component_Size_4;
12252 elsif Chars (Form) = Name_Default then
12253 Atype := Calign_Component_Size;
12255 elsif Chars (Form) = Name_Storage_Unit then
12256 Atype := Calign_Storage_Unit;
12258 else
12259 Error_Pragma_Arg
12260 ("invalid Form parameter for pragma%", Form);
12261 end if;
12263 -- Case with no name, supplied, affects scope table entry
12265 if No (Name) then
12266 Scope_Stack.Table
12267 (Scope_Stack.Last).Component_Alignment_Default := Atype;
12269 -- Case of name supplied
12271 else
12272 Check_Arg_Is_Local_Name (Name);
12273 Find_Type (Name);
12274 Typ := Entity (Name);
12276 if Typ = Any_Type
12277 or else Rep_Item_Too_Early (Typ, N)
12278 then
12279 return;
12280 else
12281 Typ := Underlying_Type (Typ);
12282 end if;
12284 if not Is_Record_Type (Typ)
12285 and then not Is_Array_Type (Typ)
12286 then
12287 Error_Pragma_Arg
12288 ("Name parameter of pragma% must identify record or "
12289 & "array type", Name);
12290 end if;
12292 -- An explicit Component_Alignment pragma overrides an
12293 -- implicit pragma Pack, but not an explicit one.
12295 if not Has_Pragma_Pack (Base_Type (Typ)) then
12296 Set_Is_Packed (Base_Type (Typ), False);
12297 Set_Component_Alignment (Base_Type (Typ), Atype);
12298 end if;
12299 end if;
12300 end Component_AlignmentP;
12302 --------------------
12303 -- Contract_Cases --
12304 --------------------
12306 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
12308 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
12310 -- CASE_GUARD ::= boolean_EXPRESSION | others
12312 -- CONSEQUENCE ::= boolean_EXPRESSION
12314 when Pragma_Contract_Cases => Contract_Cases : declare
12315 Subp_Decl : Node_Id;
12317 begin
12318 GNAT_Pragma;
12319 Check_No_Identifiers;
12320 Check_Arg_Count (1);
12321 Ensure_Aggregate_Form (Arg1);
12323 -- The pragma is analyzed at the end of the declarative part which
12324 -- contains the related subprogram. Reset the analyzed flag.
12326 Set_Analyzed (N, False);
12328 -- Ensure the proper placement of the pragma. Contract_Cases must
12329 -- be associated with a subprogram declaration or a body that acts
12330 -- as a spec.
12332 Subp_Decl :=
12333 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
12335 if Nkind (Subp_Decl) = N_Subprogram_Declaration then
12336 null;
12338 -- Body acts as spec
12340 elsif Nkind (Subp_Decl) = N_Subprogram_Body
12341 and then No (Corresponding_Spec (Subp_Decl))
12342 then
12343 null;
12345 -- Body stub acts as spec
12347 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
12348 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
12349 then
12350 null;
12352 else
12353 Pragma_Misplaced;
12354 return;
12355 end if;
12357 -- When the pragma appears on a subprogram body, perform the full
12358 -- analysis now.
12360 if Nkind (Subp_Decl) = N_Subprogram_Body then
12361 Analyze_Contract_Cases_In_Decl_Part (N);
12363 -- When Contract_Cases applies to a subprogram compilation unit,
12364 -- the corresponding pragma is placed after the unit's declaration
12365 -- node and needs to be analyzed immediately.
12367 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
12368 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
12369 then
12370 Analyze_Contract_Cases_In_Decl_Part (N);
12371 end if;
12373 -- Chain the pragma on the contract for further processing
12375 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
12376 end Contract_Cases;
12378 ----------------
12379 -- Controlled --
12380 ----------------
12382 -- pragma Controlled (first_subtype_LOCAL_NAME);
12384 when Pragma_Controlled => Controlled : declare
12385 Arg : Node_Id;
12387 begin
12388 Check_No_Identifiers;
12389 Check_Arg_Count (1);
12390 Check_Arg_Is_Local_Name (Arg1);
12391 Arg := Get_Pragma_Arg (Arg1);
12393 if not Is_Entity_Name (Arg)
12394 or else not Is_Access_Type (Entity (Arg))
12395 then
12396 Error_Pragma_Arg ("pragma% requires access type", Arg1);
12397 else
12398 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
12399 end if;
12400 end Controlled;
12402 ----------------
12403 -- Convention --
12404 ----------------
12406 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
12407 -- [Entity =>] LOCAL_NAME);
12409 when Pragma_Convention => Convention : declare
12410 C : Convention_Id;
12411 E : Entity_Id;
12412 pragma Warnings (Off, C);
12413 pragma Warnings (Off, E);
12414 begin
12415 Check_Arg_Order ((Name_Convention, Name_Entity));
12416 Check_Ada_83_Warning;
12417 Check_Arg_Count (2);
12418 Process_Convention (C, E);
12419 end Convention;
12421 ---------------------------
12422 -- Convention_Identifier --
12423 ---------------------------
12425 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
12426 -- [Convention =>] convention_IDENTIFIER);
12428 when Pragma_Convention_Identifier => Convention_Identifier : declare
12429 Idnam : Name_Id;
12430 Cname : Name_Id;
12432 begin
12433 GNAT_Pragma;
12434 Check_Arg_Order ((Name_Name, Name_Convention));
12435 Check_Arg_Count (2);
12436 Check_Optional_Identifier (Arg1, Name_Name);
12437 Check_Optional_Identifier (Arg2, Name_Convention);
12438 Check_Arg_Is_Identifier (Arg1);
12439 Check_Arg_Is_Identifier (Arg2);
12440 Idnam := Chars (Get_Pragma_Arg (Arg1));
12441 Cname := Chars (Get_Pragma_Arg (Arg2));
12443 if Is_Convention_Name (Cname) then
12444 Record_Convention_Identifier
12445 (Idnam, Get_Convention_Id (Cname));
12446 else
12447 Error_Pragma_Arg
12448 ("second arg for % pragma must be convention", Arg2);
12449 end if;
12450 end Convention_Identifier;
12452 ---------------
12453 -- CPP_Class --
12454 ---------------
12456 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
12458 when Pragma_CPP_Class => CPP_Class : declare
12459 begin
12460 GNAT_Pragma;
12462 if Warn_On_Obsolescent_Feature then
12463 Error_Msg_N
12464 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
12465 & "effect; replace it by pragma import?j?", N);
12466 end if;
12468 Check_Arg_Count (1);
12470 Rewrite (N,
12471 Make_Pragma (Loc,
12472 Chars => Name_Import,
12473 Pragma_Argument_Associations => New_List (
12474 Make_Pragma_Argument_Association (Loc,
12475 Expression => Make_Identifier (Loc, Name_CPP)),
12476 New_Copy (First (Pragma_Argument_Associations (N))))));
12477 Analyze (N);
12478 end CPP_Class;
12480 ---------------------
12481 -- CPP_Constructor --
12482 ---------------------
12484 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
12485 -- [, [External_Name =>] static_string_EXPRESSION ]
12486 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12488 when Pragma_CPP_Constructor => CPP_Constructor : declare
12489 Elmt : Elmt_Id;
12490 Id : Entity_Id;
12491 Def_Id : Entity_Id;
12492 Tag_Typ : Entity_Id;
12494 begin
12495 GNAT_Pragma;
12496 Check_At_Least_N_Arguments (1);
12497 Check_At_Most_N_Arguments (3);
12498 Check_Optional_Identifier (Arg1, Name_Entity);
12499 Check_Arg_Is_Local_Name (Arg1);
12501 Id := Get_Pragma_Arg (Arg1);
12502 Find_Program_Unit_Name (Id);
12504 -- If we did not find the name, we are done
12506 if Etype (Id) = Any_Type then
12507 return;
12508 end if;
12510 Def_Id := Entity (Id);
12512 -- Check if already defined as constructor
12514 if Is_Constructor (Def_Id) then
12515 Error_Msg_N
12516 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
12517 return;
12518 end if;
12520 if Ekind (Def_Id) = E_Function
12521 and then (Is_CPP_Class (Etype (Def_Id))
12522 or else (Is_Class_Wide_Type (Etype (Def_Id))
12523 and then
12524 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
12525 then
12526 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
12527 Error_Msg_N
12528 ("'C'P'P constructor must be defined in the scope of "
12529 & "its returned type", Arg1);
12530 end if;
12532 if Arg_Count >= 2 then
12533 Set_Imported (Def_Id);
12534 Set_Is_Public (Def_Id);
12535 Process_Interface_Name (Def_Id, Arg2, Arg3);
12536 end if;
12538 Set_Has_Completion (Def_Id);
12539 Set_Is_Constructor (Def_Id);
12540 Set_Convention (Def_Id, Convention_CPP);
12542 -- Imported C++ constructors are not dispatching primitives
12543 -- because in C++ they don't have a dispatch table slot.
12544 -- However, in Ada the constructor has the profile of a
12545 -- function that returns a tagged type and therefore it has
12546 -- been treated as a primitive operation during semantic
12547 -- analysis. We now remove it from the list of primitive
12548 -- operations of the type.
12550 if Is_Tagged_Type (Etype (Def_Id))
12551 and then not Is_Class_Wide_Type (Etype (Def_Id))
12552 and then Is_Dispatching_Operation (Def_Id)
12553 then
12554 Tag_Typ := Etype (Def_Id);
12556 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
12557 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
12558 Next_Elmt (Elmt);
12559 end loop;
12561 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
12562 Set_Is_Dispatching_Operation (Def_Id, False);
12563 end if;
12565 -- For backward compatibility, if the constructor returns a
12566 -- class wide type, and we internally change the return type to
12567 -- the corresponding root type.
12569 if Is_Class_Wide_Type (Etype (Def_Id)) then
12570 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
12571 end if;
12572 else
12573 Error_Pragma_Arg
12574 ("pragma% requires function returning a 'C'P'P_Class type",
12575 Arg1);
12576 end if;
12577 end CPP_Constructor;
12579 -----------------
12580 -- CPP_Virtual --
12581 -----------------
12583 when Pragma_CPP_Virtual => CPP_Virtual : declare
12584 begin
12585 GNAT_Pragma;
12587 if Warn_On_Obsolescent_Feature then
12588 Error_Msg_N
12589 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
12590 & "effect?j?", N);
12591 end if;
12592 end CPP_Virtual;
12594 ----------------
12595 -- CPP_Vtable --
12596 ----------------
12598 when Pragma_CPP_Vtable => CPP_Vtable : declare
12599 begin
12600 GNAT_Pragma;
12602 if Warn_On_Obsolescent_Feature then
12603 Error_Msg_N
12604 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
12605 & "effect?j?", N);
12606 end if;
12607 end CPP_Vtable;
12609 ---------
12610 -- CPU --
12611 ---------
12613 -- pragma CPU (EXPRESSION);
12615 when Pragma_CPU => CPU : declare
12616 P : constant Node_Id := Parent (N);
12617 Arg : Node_Id;
12618 Ent : Entity_Id;
12620 begin
12621 Ada_2012_Pragma;
12622 Check_No_Identifiers;
12623 Check_Arg_Count (1);
12625 -- Subprogram case
12627 if Nkind (P) = N_Subprogram_Body then
12628 Check_In_Main_Program;
12630 Arg := Get_Pragma_Arg (Arg1);
12631 Analyze_And_Resolve (Arg, Any_Integer);
12633 Ent := Defining_Unit_Name (Specification (P));
12635 if Nkind (Ent) = N_Defining_Program_Unit_Name then
12636 Ent := Defining_Identifier (Ent);
12637 end if;
12639 -- Must be static
12641 if not Is_OK_Static_Expression (Arg) then
12642 Flag_Non_Static_Expr
12643 ("main subprogram affinity is not static!", Arg);
12644 raise Pragma_Exit;
12646 -- If constraint error, then we already signalled an error
12648 elsif Raises_Constraint_Error (Arg) then
12649 null;
12651 -- Otherwise check in range
12653 else
12654 declare
12655 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
12656 -- This is the entity System.Multiprocessors.CPU_Range;
12658 Val : constant Uint := Expr_Value (Arg);
12660 begin
12661 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
12662 or else
12663 Val > Expr_Value (Type_High_Bound (CPU_Id))
12664 then
12665 Error_Pragma_Arg
12666 ("main subprogram CPU is out of range", Arg1);
12667 end if;
12668 end;
12669 end if;
12671 Set_Main_CPU
12672 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12674 -- Task case
12676 elsif Nkind (P) = N_Task_Definition then
12677 Arg := Get_Pragma_Arg (Arg1);
12678 Ent := Defining_Identifier (Parent (P));
12680 -- The expression must be analyzed in the special manner
12681 -- described in "Handling of Default and Per-Object
12682 -- Expressions" in sem.ads.
12684 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
12686 -- Anything else is incorrect
12688 else
12689 Pragma_Misplaced;
12690 end if;
12692 -- Check duplicate pragma before we chain the pragma in the Rep
12693 -- Item chain of Ent.
12695 Check_Duplicate_Pragma (Ent);
12696 Record_Rep_Item (Ent, N);
12697 end CPU;
12699 -----------
12700 -- Debug --
12701 -----------
12703 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
12705 when Pragma_Debug => Debug : declare
12706 Cond : Node_Id;
12707 Call : Node_Id;
12709 begin
12710 GNAT_Pragma;
12712 -- The condition for executing the call is that the expander
12713 -- is active and that we are not ignoring this debug pragma.
12715 Cond :=
12716 New_Occurrence_Of
12717 (Boolean_Literals
12718 (Expander_Active and then not Is_Ignored (N)),
12719 Loc);
12721 if not Is_Ignored (N) then
12722 Set_SCO_Pragma_Enabled (Loc);
12723 end if;
12725 if Arg_Count = 2 then
12726 Cond :=
12727 Make_And_Then (Loc,
12728 Left_Opnd => Relocate_Node (Cond),
12729 Right_Opnd => Get_Pragma_Arg (Arg1));
12730 Call := Get_Pragma_Arg (Arg2);
12731 else
12732 Call := Get_Pragma_Arg (Arg1);
12733 end if;
12735 if Nkind_In (Call,
12736 N_Indexed_Component,
12737 N_Function_Call,
12738 N_Identifier,
12739 N_Expanded_Name,
12740 N_Selected_Component)
12741 then
12742 -- If this pragma Debug comes from source, its argument was
12743 -- parsed as a name form (which is syntactically identical).
12744 -- In a generic context a parameterless call will be left as
12745 -- an expanded name (if global) or selected_component if local.
12746 -- Change it to a procedure call statement now.
12748 Change_Name_To_Procedure_Call_Statement (Call);
12750 elsif Nkind (Call) = N_Procedure_Call_Statement then
12752 -- Already in the form of a procedure call statement: nothing
12753 -- to do (could happen in case of an internally generated
12754 -- pragma Debug).
12756 null;
12758 else
12759 -- All other cases: diagnose error
12761 Error_Msg
12762 ("argument of pragma ""Debug"" is not procedure call",
12763 Sloc (Call));
12764 return;
12765 end if;
12767 -- Rewrite into a conditional with an appropriate condition. We
12768 -- wrap the procedure call in a block so that overhead from e.g.
12769 -- use of the secondary stack does not generate execution overhead
12770 -- for suppressed conditions.
12772 -- Normally the analysis that follows will freeze the subprogram
12773 -- being called. However, if the call is to a null procedure,
12774 -- we want to freeze it before creating the block, because the
12775 -- analysis that follows may be done with expansion disabled, in
12776 -- which case the body will not be generated, leading to spurious
12777 -- errors.
12779 if Nkind (Call) = N_Procedure_Call_Statement
12780 and then Is_Entity_Name (Name (Call))
12781 then
12782 Analyze (Name (Call));
12783 Freeze_Before (N, Entity (Name (Call)));
12784 end if;
12786 Rewrite (N,
12787 Make_Implicit_If_Statement (N,
12788 Condition => Cond,
12789 Then_Statements => New_List (
12790 Make_Block_Statement (Loc,
12791 Handled_Statement_Sequence =>
12792 Make_Handled_Sequence_Of_Statements (Loc,
12793 Statements => New_List (Relocate_Node (Call)))))));
12794 Analyze (N);
12796 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
12797 -- after analysis of the normally rewritten node, to capture all
12798 -- references to entities, which avoids issuing wrong warnings
12799 -- about unused entities.
12801 if GNATprove_Mode then
12802 Rewrite (N, Make_Null_Statement (Loc));
12803 end if;
12804 end Debug;
12806 ------------------
12807 -- Debug_Policy --
12808 ------------------
12810 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
12812 when Pragma_Debug_Policy =>
12813 GNAT_Pragma;
12814 Check_Arg_Count (1);
12815 Check_No_Identifiers;
12816 Check_Arg_Is_Identifier (Arg1);
12818 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
12819 -- rewrite it that way, and let the rest of the checking come
12820 -- from analyzing the rewritten pragma.
12822 Rewrite (N,
12823 Make_Pragma (Loc,
12824 Chars => Name_Check_Policy,
12825 Pragma_Argument_Associations => New_List (
12826 Make_Pragma_Argument_Association (Loc,
12827 Expression => Make_Identifier (Loc, Name_Debug)),
12829 Make_Pragma_Argument_Association (Loc,
12830 Expression => Get_Pragma_Arg (Arg1)))));
12831 Analyze (N);
12833 -------------------------------
12834 -- Default_Initial_Condition --
12835 -------------------------------
12837 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
12839 when Pragma_Default_Initial_Condition => Default_Init_Cond : declare
12840 Discard : Boolean;
12841 Stmt : Node_Id;
12842 Typ : Entity_Id;
12844 begin
12845 GNAT_Pragma;
12846 Check_No_Identifiers;
12847 Check_At_Most_N_Arguments (1);
12849 Stmt := Prev (N);
12850 while Present (Stmt) loop
12852 -- Skip prior pragmas, but check for duplicates
12854 if Nkind (Stmt) = N_Pragma then
12855 if Pragma_Name (Stmt) = Pname then
12856 Error_Msg_Name_1 := Pname;
12857 Error_Msg_Sloc := Sloc (Stmt);
12858 Error_Msg_N ("pragma % duplicates pragma declared#", N);
12859 end if;
12861 -- Skip internally generated code
12863 elsif not Comes_From_Source (Stmt) then
12864 null;
12866 -- The associated private type [extension] has been found, stop
12867 -- the search.
12869 elsif Nkind_In (Stmt, N_Private_Extension_Declaration,
12870 N_Private_Type_Declaration)
12871 then
12872 Typ := Defining_Entity (Stmt);
12873 exit;
12875 -- The pragma does not apply to a legal construct, issue an
12876 -- error and stop the analysis.
12878 else
12879 Pragma_Misplaced;
12880 return;
12881 end if;
12883 Stmt := Prev (Stmt);
12884 end loop;
12886 Set_Has_Default_Init_Cond (Typ);
12887 Set_Has_Inherited_Default_Init_Cond (Typ, False);
12889 -- Chain the pragma on the rep item chain for further processing
12891 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12892 end Default_Init_Cond;
12894 ----------------------------------
12895 -- Default_Scalar_Storage_Order --
12896 ----------------------------------
12898 -- pragma Default_Scalar_Storage_Order
12899 -- (High_Order_First | Low_Order_First);
12901 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
12902 Default : Character;
12904 begin
12905 GNAT_Pragma;
12906 Check_Arg_Count (1);
12908 -- Default_Scalar_Storage_Order can appear as a configuration
12909 -- pragma, or in a declarative part of a package spec.
12911 if not Is_Configuration_Pragma then
12912 Check_Is_In_Decl_Part_Or_Package_Spec;
12913 end if;
12915 Check_No_Identifiers;
12916 Check_Arg_Is_One_Of
12917 (Arg1, Name_High_Order_First, Name_Low_Order_First);
12918 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12919 Default := Fold_Upper (Name_Buffer (1));
12921 if not Support_Nondefault_SSO_On_Target
12922 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
12923 then
12924 if Warn_On_Unrecognized_Pragma then
12925 Error_Msg_N
12926 ("non-default Scalar_Storage_Order not supported "
12927 & "on target?g?", N);
12928 Error_Msg_N
12929 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
12930 end if;
12932 -- Here set the specified default
12934 else
12935 Opt.Default_SSO := Default;
12936 end if;
12937 end DSSO;
12939 --------------------------
12940 -- Default_Storage_Pool --
12941 --------------------------
12943 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
12945 when Pragma_Default_Storage_Pool =>
12946 Ada_2012_Pragma;
12947 Check_Arg_Count (1);
12949 -- Default_Storage_Pool can appear as a configuration pragma, or
12950 -- in a declarative part of a package spec.
12952 if not Is_Configuration_Pragma then
12953 Check_Is_In_Decl_Part_Or_Package_Spec;
12954 end if;
12956 -- Case of Default_Storage_Pool (null);
12958 if Nkind (Expression (Arg1)) = N_Null then
12959 Analyze (Expression (Arg1));
12961 -- This is an odd case, this is not really an expression, so
12962 -- we don't have a type for it. So just set the type to Empty.
12964 Set_Etype (Expression (Arg1), Empty);
12966 -- Case of Default_Storage_Pool (storage_pool_NAME);
12968 else
12969 -- If it's a configuration pragma, then the only allowed
12970 -- argument is "null".
12972 if Is_Configuration_Pragma then
12973 Error_Pragma_Arg ("NULL expected", Arg1);
12974 end if;
12976 -- The expected type for a non-"null" argument is
12977 -- Root_Storage_Pool'Class, and the pool must be a variable.
12979 Analyze_And_Resolve
12980 (Get_Pragma_Arg (Arg1),
12981 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
12983 if not Is_Variable (Expression (Arg1)) then
12984 Error_Pragma_Arg
12985 ("default storage pool must be a variable", Arg1);
12986 end if;
12987 end if;
12989 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
12990 -- for an access type will use this information to set the
12991 -- appropriate attributes of the access type.
12993 Default_Pool := Expression (Arg1);
12995 -------------
12996 -- Depends --
12997 -------------
12999 -- pragma Depends (DEPENDENCY_RELATION);
13001 -- DEPENDENCY_RELATION ::=
13002 -- null
13003 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
13005 -- DEPENDENCY_CLAUSE ::=
13006 -- OUTPUT_LIST =>[+] INPUT_LIST
13007 -- | NULL_DEPENDENCY_CLAUSE
13009 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
13011 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
13013 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
13015 -- OUTPUT ::= NAME | FUNCTION_RESULT
13016 -- INPUT ::= NAME
13018 -- where FUNCTION_RESULT is a function Result attribute_reference
13020 when Pragma_Depends => Depends : declare
13021 Subp_Decl : Node_Id;
13023 begin
13024 GNAT_Pragma;
13025 Check_Arg_Count (1);
13026 Ensure_Aggregate_Form (Arg1);
13028 -- Ensure the proper placement of the pragma. Depends must be
13029 -- associated with a subprogram declaration or a body that acts
13030 -- as a spec.
13032 Subp_Decl :=
13033 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
13035 if Nkind (Subp_Decl) = N_Subprogram_Declaration then
13036 null;
13038 -- Body acts as spec
13040 elsif Nkind (Subp_Decl) = N_Subprogram_Body
13041 and then No (Corresponding_Spec (Subp_Decl))
13042 then
13043 null;
13045 -- Body stub acts as spec
13047 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
13048 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
13049 then
13050 null;
13052 else
13053 Pragma_Misplaced;
13054 return;
13055 end if;
13057 -- When the pragma appears on a subprogram body, perform the full
13058 -- analysis now.
13060 if Nkind (Subp_Decl) = N_Subprogram_Body then
13061 Analyze_Depends_In_Decl_Part (N);
13063 -- When Depends applies to a subprogram compilation unit, the
13064 -- corresponding pragma is placed after the unit's declaration
13065 -- node and needs to be analyzed immediately.
13067 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
13068 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
13069 then
13070 Analyze_Depends_In_Decl_Part (N);
13071 end if;
13073 -- Chain the pragma on the contract for further processing
13075 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
13076 end Depends;
13078 ---------------------
13079 -- Detect_Blocking --
13080 ---------------------
13082 -- pragma Detect_Blocking;
13084 when Pragma_Detect_Blocking =>
13085 Ada_2005_Pragma;
13086 Check_Arg_Count (0);
13087 Check_Valid_Configuration_Pragma;
13088 Detect_Blocking := True;
13090 ------------------------------------
13091 -- Disable_Atomic_Synchronization --
13092 ------------------------------------
13094 -- pragma Disable_Atomic_Synchronization [(Entity)];
13096 when Pragma_Disable_Atomic_Synchronization =>
13097 GNAT_Pragma;
13098 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
13100 -------------------
13101 -- Discard_Names --
13102 -------------------
13104 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
13106 when Pragma_Discard_Names => Discard_Names : declare
13107 E : Entity_Id;
13108 E_Id : Entity_Id;
13110 begin
13111 Check_Ada_83_Warning;
13113 -- Deal with configuration pragma case
13115 if Arg_Count = 0 and then Is_Configuration_Pragma then
13116 Global_Discard_Names := True;
13117 return;
13119 -- Otherwise, check correct appropriate context
13121 else
13122 Check_Is_In_Decl_Part_Or_Package_Spec;
13124 if Arg_Count = 0 then
13126 -- If there is no parameter, then from now on this pragma
13127 -- applies to any enumeration, exception or tagged type
13128 -- defined in the current declarative part, and recursively
13129 -- to any nested scope.
13131 Set_Discard_Names (Current_Scope);
13132 return;
13134 else
13135 Check_Arg_Count (1);
13136 Check_Optional_Identifier (Arg1, Name_On);
13137 Check_Arg_Is_Local_Name (Arg1);
13139 E_Id := Get_Pragma_Arg (Arg1);
13141 if Etype (E_Id) = Any_Type then
13142 return;
13143 else
13144 E := Entity (E_Id);
13145 end if;
13147 if (Is_First_Subtype (E)
13148 and then
13149 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
13150 or else Ekind (E) = E_Exception
13151 then
13152 Set_Discard_Names (E);
13153 Record_Rep_Item (E, N);
13155 else
13156 Error_Pragma_Arg
13157 ("inappropriate entity for pragma%", Arg1);
13158 end if;
13160 end if;
13161 end if;
13162 end Discard_Names;
13164 ------------------------
13165 -- Dispatching_Domain --
13166 ------------------------
13168 -- pragma Dispatching_Domain (EXPRESSION);
13170 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
13171 P : constant Node_Id := Parent (N);
13172 Arg : Node_Id;
13173 Ent : Entity_Id;
13175 begin
13176 Ada_2012_Pragma;
13177 Check_No_Identifiers;
13178 Check_Arg_Count (1);
13180 -- This pragma is born obsolete, but not the aspect
13182 if not From_Aspect_Specification (N) then
13183 Check_Restriction
13184 (No_Obsolescent_Features, Pragma_Identifier (N));
13185 end if;
13187 if Nkind (P) = N_Task_Definition then
13188 Arg := Get_Pragma_Arg (Arg1);
13189 Ent := Defining_Identifier (Parent (P));
13191 -- The expression must be analyzed in the special manner
13192 -- described in "Handling of Default and Per-Object
13193 -- Expressions" in sem.ads.
13195 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
13197 -- Check duplicate pragma before we chain the pragma in the Rep
13198 -- Item chain of Ent.
13200 Check_Duplicate_Pragma (Ent);
13201 Record_Rep_Item (Ent, N);
13203 -- Anything else is incorrect
13205 else
13206 Pragma_Misplaced;
13207 end if;
13208 end Dispatching_Domain;
13210 ---------------
13211 -- Elaborate --
13212 ---------------
13214 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
13216 when Pragma_Elaborate => Elaborate : declare
13217 Arg : Node_Id;
13218 Citem : Node_Id;
13220 begin
13221 -- Pragma must be in context items list of a compilation unit
13223 if not Is_In_Context_Clause then
13224 Pragma_Misplaced;
13225 end if;
13227 -- Must be at least one argument
13229 if Arg_Count = 0 then
13230 Error_Pragma ("pragma% requires at least one argument");
13231 end if;
13233 -- In Ada 83 mode, there can be no items following it in the
13234 -- context list except other pragmas and implicit with clauses
13235 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
13236 -- placement rule does not apply.
13238 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
13239 Citem := Next (N);
13240 while Present (Citem) loop
13241 if Nkind (Citem) = N_Pragma
13242 or else (Nkind (Citem) = N_With_Clause
13243 and then Implicit_With (Citem))
13244 then
13245 null;
13246 else
13247 Error_Pragma
13248 ("(Ada 83) pragma% must be at end of context clause");
13249 end if;
13251 Next (Citem);
13252 end loop;
13253 end if;
13255 -- Finally, the arguments must all be units mentioned in a with
13256 -- clause in the same context clause. Note we already checked (in
13257 -- Par.Prag) that the arguments are all identifiers or selected
13258 -- components.
13260 Arg := Arg1;
13261 Outer : while Present (Arg) loop
13262 Citem := First (List_Containing (N));
13263 Inner : while Citem /= N loop
13264 if Nkind (Citem) = N_With_Clause
13265 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
13266 then
13267 Set_Elaborate_Present (Citem, True);
13268 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
13269 Generate_Reference (Entity (Name (Citem)), Citem);
13271 -- With the pragma present, elaboration calls on
13272 -- subprograms from the named unit need no further
13273 -- checks, as long as the pragma appears in the current
13274 -- compilation unit. If the pragma appears in some unit
13275 -- in the context, there might still be a need for an
13276 -- Elaborate_All_Desirable from the current compilation
13277 -- to the named unit, so we keep the check enabled.
13279 if In_Extended_Main_Source_Unit (N) then
13280 Set_Suppress_Elaboration_Warnings
13281 (Entity (Name (Citem)));
13282 end if;
13284 exit Inner;
13285 end if;
13287 Next (Citem);
13288 end loop Inner;
13290 if Citem = N then
13291 Error_Pragma_Arg
13292 ("argument of pragma% is not withed unit", Arg);
13293 end if;
13295 Next (Arg);
13296 end loop Outer;
13298 -- Give a warning if operating in static mode with one of the
13299 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set.
13301 if Elab_Warnings and not Dynamic_Elaboration_Checks then
13302 Error_Msg_N
13303 ("?l?use of pragma Elaborate may not be safe", N);
13304 Error_Msg_N
13305 ("?l?use pragma Elaborate_All instead if possible", N);
13306 end if;
13307 end Elaborate;
13309 -------------------
13310 -- Elaborate_All --
13311 -------------------
13313 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
13315 when Pragma_Elaborate_All => Elaborate_All : declare
13316 Arg : Node_Id;
13317 Citem : Node_Id;
13319 begin
13320 Check_Ada_83_Warning;
13322 -- Pragma must be in context items list of a compilation unit
13324 if not Is_In_Context_Clause then
13325 Pragma_Misplaced;
13326 end if;
13328 -- Must be at least one argument
13330 if Arg_Count = 0 then
13331 Error_Pragma ("pragma% requires at least one argument");
13332 end if;
13334 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
13335 -- have to appear at the end of the context clause, but may
13336 -- appear mixed in with other items, even in Ada 83 mode.
13338 -- Final check: the arguments must all be units mentioned in
13339 -- a with clause in the same context clause. Note that we
13340 -- already checked (in Par.Prag) that all the arguments are
13341 -- either identifiers or selected components.
13343 Arg := Arg1;
13344 Outr : while Present (Arg) loop
13345 Citem := First (List_Containing (N));
13346 Innr : while Citem /= N loop
13347 if Nkind (Citem) = N_With_Clause
13348 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
13349 then
13350 Set_Elaborate_All_Present (Citem, True);
13351 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
13353 -- Suppress warnings and elaboration checks on the named
13354 -- unit if the pragma is in the current compilation, as
13355 -- for pragma Elaborate.
13357 if In_Extended_Main_Source_Unit (N) then
13358 Set_Suppress_Elaboration_Warnings
13359 (Entity (Name (Citem)));
13360 end if;
13361 exit Innr;
13362 end if;
13364 Next (Citem);
13365 end loop Innr;
13367 if Citem = N then
13368 Set_Error_Posted (N);
13369 Error_Pragma_Arg
13370 ("argument of pragma% is not withed unit", Arg);
13371 end if;
13373 Next (Arg);
13374 end loop Outr;
13375 end Elaborate_All;
13377 --------------------
13378 -- Elaborate_Body --
13379 --------------------
13381 -- pragma Elaborate_Body [( library_unit_NAME )];
13383 when Pragma_Elaborate_Body => Elaborate_Body : declare
13384 Cunit_Node : Node_Id;
13385 Cunit_Ent : Entity_Id;
13387 begin
13388 Check_Ada_83_Warning;
13389 Check_Valid_Library_Unit_Pragma;
13391 if Nkind (N) = N_Null_Statement then
13392 return;
13393 end if;
13395 Cunit_Node := Cunit (Current_Sem_Unit);
13396 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13398 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
13399 N_Subprogram_Body)
13400 then
13401 Error_Pragma ("pragma% must refer to a spec, not a body");
13402 else
13403 Set_Body_Required (Cunit_Node, True);
13404 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
13406 -- If we are in dynamic elaboration mode, then we suppress
13407 -- elaboration warnings for the unit, since it is definitely
13408 -- fine NOT to do dynamic checks at the first level (and such
13409 -- checks will be suppressed because no elaboration boolean
13410 -- is created for Elaborate_Body packages).
13412 -- But in the static model of elaboration, Elaborate_Body is
13413 -- definitely NOT good enough to ensure elaboration safety on
13414 -- its own, since the body may WITH other units that are not
13415 -- safe from an elaboration point of view, so a client must
13416 -- still do an Elaborate_All on such units.
13418 -- Debug flag -gnatdD restores the old behavior of 3.13, where
13419 -- Elaborate_Body always suppressed elab warnings.
13421 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
13422 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
13423 end if;
13424 end if;
13425 end Elaborate_Body;
13427 ------------------------
13428 -- Elaboration_Checks --
13429 ------------------------
13431 -- pragma Elaboration_Checks (Static | Dynamic);
13433 when Pragma_Elaboration_Checks =>
13434 GNAT_Pragma;
13435 Check_Arg_Count (1);
13436 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
13437 Dynamic_Elaboration_Checks :=
13438 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
13440 ---------------
13441 -- Eliminate --
13442 ---------------
13444 -- pragma Eliminate (
13445 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
13446 -- [,[Entity =>] IDENTIFIER |
13447 -- SELECTED_COMPONENT |
13448 -- STRING_LITERAL]
13449 -- [, OVERLOADING_RESOLUTION]);
13451 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
13452 -- SOURCE_LOCATION
13454 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
13455 -- FUNCTION_PROFILE
13457 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
13459 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
13460 -- Result_Type => result_SUBTYPE_NAME]
13462 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
13463 -- SUBTYPE_NAME ::= STRING_LITERAL
13465 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
13466 -- SOURCE_TRACE ::= STRING_LITERAL
13468 when Pragma_Eliminate => Eliminate : declare
13469 Args : Args_List (1 .. 5);
13470 Names : constant Name_List (1 .. 5) := (
13471 Name_Unit_Name,
13472 Name_Entity,
13473 Name_Parameter_Types,
13474 Name_Result_Type,
13475 Name_Source_Location);
13477 Unit_Name : Node_Id renames Args (1);
13478 Entity : Node_Id renames Args (2);
13479 Parameter_Types : Node_Id renames Args (3);
13480 Result_Type : Node_Id renames Args (4);
13481 Source_Location : Node_Id renames Args (5);
13483 begin
13484 GNAT_Pragma;
13485 Check_Valid_Configuration_Pragma;
13486 Gather_Associations (Names, Args);
13488 if No (Unit_Name) then
13489 Error_Pragma ("missing Unit_Name argument for pragma%");
13490 end if;
13492 if No (Entity)
13493 and then (Present (Parameter_Types)
13494 or else
13495 Present (Result_Type)
13496 or else
13497 Present (Source_Location))
13498 then
13499 Error_Pragma ("missing Entity argument for pragma%");
13500 end if;
13502 if (Present (Parameter_Types)
13503 or else
13504 Present (Result_Type))
13505 and then
13506 Present (Source_Location)
13507 then
13508 Error_Pragma
13509 ("parameter profile and source location cannot be used "
13510 & "together in pragma%");
13511 end if;
13513 Process_Eliminate_Pragma
13515 Unit_Name,
13516 Entity,
13517 Parameter_Types,
13518 Result_Type,
13519 Source_Location);
13520 end Eliminate;
13522 -----------------------------------
13523 -- Enable_Atomic_Synchronization --
13524 -----------------------------------
13526 -- pragma Enable_Atomic_Synchronization [(Entity)];
13528 when Pragma_Enable_Atomic_Synchronization =>
13529 GNAT_Pragma;
13530 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
13532 ------------
13533 -- Export --
13534 ------------
13536 -- pragma Export (
13537 -- [ Convention =>] convention_IDENTIFIER,
13538 -- [ Entity =>] LOCAL_NAME
13539 -- [, [External_Name =>] static_string_EXPRESSION ]
13540 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13542 when Pragma_Export => Export : declare
13543 C : Convention_Id;
13544 Def_Id : Entity_Id;
13546 pragma Warnings (Off, C);
13548 begin
13549 Check_Ada_83_Warning;
13550 Check_Arg_Order
13551 ((Name_Convention,
13552 Name_Entity,
13553 Name_External_Name,
13554 Name_Link_Name));
13556 Check_At_Least_N_Arguments (2);
13557 Check_At_Most_N_Arguments (4);
13559 -- In Relaxed_RM_Semantics, support old Ada 83 style:
13560 -- pragma Export (Entity, "external name");
13562 if Relaxed_RM_Semantics
13563 and then Arg_Count = 2
13564 and then Nkind (Expression (Arg2)) = N_String_Literal
13565 then
13566 C := Convention_C;
13567 Def_Id := Get_Pragma_Arg (Arg1);
13568 Analyze (Def_Id);
13570 if not Is_Entity_Name (Def_Id) then
13571 Error_Pragma_Arg ("entity name required", Arg1);
13572 end if;
13574 Def_Id := Entity (Def_Id);
13575 Set_Exported (Def_Id, Arg1);
13577 else
13578 Process_Convention (C, Def_Id);
13580 if Ekind (Def_Id) /= E_Constant then
13581 Note_Possible_Modification
13582 (Get_Pragma_Arg (Arg2), Sure => False);
13583 end if;
13585 Process_Interface_Name (Def_Id, Arg3, Arg4);
13586 Set_Exported (Def_Id, Arg2);
13587 end if;
13589 -- If the entity is a deferred constant, propagate the information
13590 -- to the full view, because gigi elaborates the full view only.
13592 if Ekind (Def_Id) = E_Constant
13593 and then Present (Full_View (Def_Id))
13594 then
13595 declare
13596 Id2 : constant Entity_Id := Full_View (Def_Id);
13597 begin
13598 Set_Is_Exported (Id2, Is_Exported (Def_Id));
13599 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
13600 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
13601 end;
13602 end if;
13603 end Export;
13605 ---------------------
13606 -- Export_Function --
13607 ---------------------
13609 -- pragma Export_Function (
13610 -- [Internal =>] LOCAL_NAME
13611 -- [, [External =>] EXTERNAL_SYMBOL]
13612 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13613 -- [, [Result_Type =>] TYPE_DESIGNATOR]
13614 -- [, [Mechanism =>] MECHANISM]
13615 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
13617 -- EXTERNAL_SYMBOL ::=
13618 -- IDENTIFIER
13619 -- | static_string_EXPRESSION
13621 -- PARAMETER_TYPES ::=
13622 -- null
13623 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13625 -- TYPE_DESIGNATOR ::=
13626 -- subtype_NAME
13627 -- | subtype_Name ' Access
13629 -- MECHANISM ::=
13630 -- MECHANISM_NAME
13631 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13633 -- MECHANISM_ASSOCIATION ::=
13634 -- [formal_parameter_NAME =>] MECHANISM_NAME
13636 -- MECHANISM_NAME ::=
13637 -- Value
13638 -- | Reference
13640 when Pragma_Export_Function => Export_Function : declare
13641 Args : Args_List (1 .. 6);
13642 Names : constant Name_List (1 .. 6) := (
13643 Name_Internal,
13644 Name_External,
13645 Name_Parameter_Types,
13646 Name_Result_Type,
13647 Name_Mechanism,
13648 Name_Result_Mechanism);
13650 Internal : Node_Id renames Args (1);
13651 External : Node_Id renames Args (2);
13652 Parameter_Types : Node_Id renames Args (3);
13653 Result_Type : Node_Id renames Args (4);
13654 Mechanism : Node_Id renames Args (5);
13655 Result_Mechanism : Node_Id renames Args (6);
13657 begin
13658 GNAT_Pragma;
13659 Gather_Associations (Names, Args);
13660 Process_Extended_Import_Export_Subprogram_Pragma (
13661 Arg_Internal => Internal,
13662 Arg_External => External,
13663 Arg_Parameter_Types => Parameter_Types,
13664 Arg_Result_Type => Result_Type,
13665 Arg_Mechanism => Mechanism,
13666 Arg_Result_Mechanism => Result_Mechanism);
13667 end Export_Function;
13669 -------------------
13670 -- Export_Object --
13671 -------------------
13673 -- pragma Export_Object (
13674 -- [Internal =>] LOCAL_NAME
13675 -- [, [External =>] EXTERNAL_SYMBOL]
13676 -- [, [Size =>] EXTERNAL_SYMBOL]);
13678 -- EXTERNAL_SYMBOL ::=
13679 -- IDENTIFIER
13680 -- | static_string_EXPRESSION
13682 -- PARAMETER_TYPES ::=
13683 -- null
13684 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13686 -- TYPE_DESIGNATOR ::=
13687 -- subtype_NAME
13688 -- | subtype_Name ' Access
13690 -- MECHANISM ::=
13691 -- MECHANISM_NAME
13692 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13694 -- MECHANISM_ASSOCIATION ::=
13695 -- [formal_parameter_NAME =>] MECHANISM_NAME
13697 -- MECHANISM_NAME ::=
13698 -- Value
13699 -- | Reference
13701 when Pragma_Export_Object => Export_Object : declare
13702 Args : Args_List (1 .. 3);
13703 Names : constant Name_List (1 .. 3) := (
13704 Name_Internal,
13705 Name_External,
13706 Name_Size);
13708 Internal : Node_Id renames Args (1);
13709 External : Node_Id renames Args (2);
13710 Size : Node_Id renames Args (3);
13712 begin
13713 GNAT_Pragma;
13714 Gather_Associations (Names, Args);
13715 Process_Extended_Import_Export_Object_Pragma (
13716 Arg_Internal => Internal,
13717 Arg_External => External,
13718 Arg_Size => Size);
13719 end Export_Object;
13721 ----------------------
13722 -- Export_Procedure --
13723 ----------------------
13725 -- pragma Export_Procedure (
13726 -- [Internal =>] LOCAL_NAME
13727 -- [, [External =>] EXTERNAL_SYMBOL]
13728 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13729 -- [, [Mechanism =>] MECHANISM]);
13731 -- EXTERNAL_SYMBOL ::=
13732 -- IDENTIFIER
13733 -- | static_string_EXPRESSION
13735 -- PARAMETER_TYPES ::=
13736 -- null
13737 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13739 -- TYPE_DESIGNATOR ::=
13740 -- subtype_NAME
13741 -- | subtype_Name ' Access
13743 -- MECHANISM ::=
13744 -- MECHANISM_NAME
13745 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13747 -- MECHANISM_ASSOCIATION ::=
13748 -- [formal_parameter_NAME =>] MECHANISM_NAME
13750 -- MECHANISM_NAME ::=
13751 -- Value
13752 -- | Reference
13754 when Pragma_Export_Procedure => Export_Procedure : declare
13755 Args : Args_List (1 .. 4);
13756 Names : constant Name_List (1 .. 4) := (
13757 Name_Internal,
13758 Name_External,
13759 Name_Parameter_Types,
13760 Name_Mechanism);
13762 Internal : Node_Id renames Args (1);
13763 External : Node_Id renames Args (2);
13764 Parameter_Types : Node_Id renames Args (3);
13765 Mechanism : Node_Id renames Args (4);
13767 begin
13768 GNAT_Pragma;
13769 Gather_Associations (Names, Args);
13770 Process_Extended_Import_Export_Subprogram_Pragma (
13771 Arg_Internal => Internal,
13772 Arg_External => External,
13773 Arg_Parameter_Types => Parameter_Types,
13774 Arg_Mechanism => Mechanism);
13775 end Export_Procedure;
13777 ------------------
13778 -- Export_Value --
13779 ------------------
13781 -- pragma Export_Value (
13782 -- [Value =>] static_integer_EXPRESSION,
13783 -- [Link_Name =>] static_string_EXPRESSION);
13785 when Pragma_Export_Value =>
13786 GNAT_Pragma;
13787 Check_Arg_Order ((Name_Value, Name_Link_Name));
13788 Check_Arg_Count (2);
13790 Check_Optional_Identifier (Arg1, Name_Value);
13791 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
13793 Check_Optional_Identifier (Arg2, Name_Link_Name);
13794 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
13796 -----------------------------
13797 -- Export_Valued_Procedure --
13798 -----------------------------
13800 -- pragma Export_Valued_Procedure (
13801 -- [Internal =>] LOCAL_NAME
13802 -- [, [External =>] EXTERNAL_SYMBOL,]
13803 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13804 -- [, [Mechanism =>] MECHANISM]);
13806 -- EXTERNAL_SYMBOL ::=
13807 -- IDENTIFIER
13808 -- | static_string_EXPRESSION
13810 -- PARAMETER_TYPES ::=
13811 -- null
13812 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13814 -- TYPE_DESIGNATOR ::=
13815 -- subtype_NAME
13816 -- | subtype_Name ' Access
13818 -- MECHANISM ::=
13819 -- MECHANISM_NAME
13820 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13822 -- MECHANISM_ASSOCIATION ::=
13823 -- [formal_parameter_NAME =>] MECHANISM_NAME
13825 -- MECHANISM_NAME ::=
13826 -- Value
13827 -- | Reference
13829 when Pragma_Export_Valued_Procedure =>
13830 Export_Valued_Procedure : declare
13831 Args : Args_List (1 .. 4);
13832 Names : constant Name_List (1 .. 4) := (
13833 Name_Internal,
13834 Name_External,
13835 Name_Parameter_Types,
13836 Name_Mechanism);
13838 Internal : Node_Id renames Args (1);
13839 External : Node_Id renames Args (2);
13840 Parameter_Types : Node_Id renames Args (3);
13841 Mechanism : Node_Id renames Args (4);
13843 begin
13844 GNAT_Pragma;
13845 Gather_Associations (Names, Args);
13846 Process_Extended_Import_Export_Subprogram_Pragma (
13847 Arg_Internal => Internal,
13848 Arg_External => External,
13849 Arg_Parameter_Types => Parameter_Types,
13850 Arg_Mechanism => Mechanism);
13851 end Export_Valued_Procedure;
13853 -------------------
13854 -- Extend_System --
13855 -------------------
13857 -- pragma Extend_System ([Name =>] Identifier);
13859 when Pragma_Extend_System => Extend_System : declare
13860 begin
13861 GNAT_Pragma;
13862 Check_Valid_Configuration_Pragma;
13863 Check_Arg_Count (1);
13864 Check_Optional_Identifier (Arg1, Name_Name);
13865 Check_Arg_Is_Identifier (Arg1);
13867 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13869 if Name_Len > 4
13870 and then Name_Buffer (1 .. 4) = "aux_"
13871 then
13872 if Present (System_Extend_Pragma_Arg) then
13873 if Chars (Get_Pragma_Arg (Arg1)) =
13874 Chars (Expression (System_Extend_Pragma_Arg))
13875 then
13876 null;
13877 else
13878 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
13879 Error_Pragma ("pragma% conflicts with that #");
13880 end if;
13882 else
13883 System_Extend_Pragma_Arg := Arg1;
13885 if not GNAT_Mode then
13886 System_Extend_Unit := Arg1;
13887 end if;
13888 end if;
13889 else
13890 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
13891 end if;
13892 end Extend_System;
13894 ------------------------
13895 -- Extensions_Allowed --
13896 ------------------------
13898 -- pragma Extensions_Allowed (ON | OFF);
13900 when Pragma_Extensions_Allowed =>
13901 GNAT_Pragma;
13902 Check_Arg_Count (1);
13903 Check_No_Identifiers;
13904 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13906 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
13907 Extensions_Allowed := True;
13908 Ada_Version := Ada_Version_Type'Last;
13910 else
13911 Extensions_Allowed := False;
13912 Ada_Version := Ada_Version_Explicit;
13913 Ada_Version_Pragma := Empty;
13914 end if;
13916 ------------------------
13917 -- Extensions_Visible --
13918 ------------------------
13920 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
13922 when Pragma_Extensions_Visible => Extensions_Visible : declare
13923 Context : constant Node_Id := Parent (N);
13924 Expr : Node_Id;
13925 Formal : Entity_Id;
13926 Subp : Entity_Id;
13927 Stmt : Node_Id;
13929 Has_OK_Formal : Boolean := False;
13931 begin
13932 GNAT_Pragma;
13933 Check_No_Identifiers;
13934 Check_At_Most_N_Arguments (1);
13936 Subp := Empty;
13937 Stmt := Prev (N);
13938 while Present (Stmt) loop
13940 -- Skip prior pragmas, but check for duplicates
13942 if Nkind (Stmt) = N_Pragma then
13943 if Pragma_Name (Stmt) = Pname then
13944 Error_Msg_Name_1 := Pname;
13945 Error_Msg_Sloc := Sloc (Stmt);
13946 Error_Msg_N ("pragma % duplicates pragma declared#", N);
13947 end if;
13949 -- Skip internally generated code
13951 elsif not Comes_From_Source (Stmt) then
13952 null;
13954 -- The associated [generic] subprogram declaration has been
13955 -- found, stop the search.
13957 elsif Nkind_In (Stmt, N_Generic_Subprogram_Declaration,
13958 N_Subprogram_Declaration)
13959 then
13960 Subp := Defining_Entity (Stmt);
13961 exit;
13963 -- The pragma does not apply to a legal construct, issue an
13964 -- error and stop the analysis.
13966 else
13967 Error_Pragma ("pragma % must apply to a subprogram");
13968 return;
13969 end if;
13971 Stmt := Prev (Stmt);
13972 end loop;
13974 -- When the pragma applies to a stand alone subprogram body, it
13975 -- appears within the declarations of the body. In that case the
13976 -- enclosing construct is the proper context. This check is done
13977 -- after the traversal above to allow for duplicate detection.
13979 if No (Subp)
13980 and then Nkind (Context) = N_Subprogram_Body
13981 and then No (Corresponding_Spec (Context))
13982 then
13983 Subp := Defining_Entity (Context);
13984 end if;
13986 if No (Subp) then
13987 Error_Pragma ("pragma % must apply to a subprogram");
13988 return;
13989 end if;
13991 -- Examine the formals of the related subprogram
13993 Formal := First_Formal (Subp);
13994 while Present (Formal) loop
13996 -- At least one of the formals is of a specific tagged type,
13997 -- the pragma is legal.
13999 if Is_Specific_Tagged_Type (Etype (Formal)) then
14000 Has_OK_Formal := True;
14001 exit;
14003 -- A generic subprogram with at least one formal of a private
14004 -- type ensures the legality of the pragma because the actual
14005 -- may be specifically tagged. Note that this is verified by
14006 -- the check above at instantiation time.
14008 elsif Is_Private_Type (Etype (Formal))
14009 and then Is_Generic_Type (Etype (Formal))
14010 then
14011 Has_OK_Formal := True;
14012 exit;
14013 end if;
14015 Next_Formal (Formal);
14016 end loop;
14018 if not Has_OK_Formal then
14019 Error_Msg_Name_1 := Pname;
14020 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
14021 Error_Msg_NE
14022 ("\subprogram & lacks parameter of specific tagged or "
14023 & "generic private type", N, Subp);
14024 return;
14025 end if;
14027 -- Analyze the Boolean expression (if any)
14029 if Present (Arg1) then
14030 Expr := Get_Pragma_Arg (Arg1);
14032 Analyze_And_Resolve (Expr, Standard_Boolean);
14034 if not Is_OK_Static_Expression (Expr) then
14035 Error_Pragma_Arg
14036 ("expression of pragma % must be static", Expr);
14037 return;
14038 end if;
14039 end if;
14041 -- Chain the pragma on the contract for further processing
14043 Add_Contract_Item (N, Subp);
14044 end Extensions_Visible;
14046 --------------
14047 -- External --
14048 --------------
14050 -- pragma External (
14051 -- [ Convention =>] convention_IDENTIFIER,
14052 -- [ Entity =>] LOCAL_NAME
14053 -- [, [External_Name =>] static_string_EXPRESSION ]
14054 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14056 when Pragma_External => External : declare
14057 Def_Id : Entity_Id;
14059 C : Convention_Id;
14060 pragma Warnings (Off, C);
14062 begin
14063 GNAT_Pragma;
14064 Check_Arg_Order
14065 ((Name_Convention,
14066 Name_Entity,
14067 Name_External_Name,
14068 Name_Link_Name));
14069 Check_At_Least_N_Arguments (2);
14070 Check_At_Most_N_Arguments (4);
14071 Process_Convention (C, Def_Id);
14072 Note_Possible_Modification
14073 (Get_Pragma_Arg (Arg2), Sure => False);
14074 Process_Interface_Name (Def_Id, Arg3, Arg4);
14075 Set_Exported (Def_Id, Arg2);
14076 end External;
14078 --------------------------
14079 -- External_Name_Casing --
14080 --------------------------
14082 -- pragma External_Name_Casing (
14083 -- UPPERCASE | LOWERCASE
14084 -- [, AS_IS | UPPERCASE | LOWERCASE]);
14086 when Pragma_External_Name_Casing => External_Name_Casing : declare
14087 begin
14088 GNAT_Pragma;
14089 Check_No_Identifiers;
14091 if Arg_Count = 2 then
14092 Check_Arg_Is_One_Of
14093 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
14095 case Chars (Get_Pragma_Arg (Arg2)) is
14096 when Name_As_Is =>
14097 Opt.External_Name_Exp_Casing := As_Is;
14099 when Name_Uppercase =>
14100 Opt.External_Name_Exp_Casing := Uppercase;
14102 when Name_Lowercase =>
14103 Opt.External_Name_Exp_Casing := Lowercase;
14105 when others =>
14106 null;
14107 end case;
14109 else
14110 Check_Arg_Count (1);
14111 end if;
14113 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
14115 case Chars (Get_Pragma_Arg (Arg1)) is
14116 when Name_Uppercase =>
14117 Opt.External_Name_Imp_Casing := Uppercase;
14119 when Name_Lowercase =>
14120 Opt.External_Name_Imp_Casing := Lowercase;
14122 when others =>
14123 null;
14124 end case;
14125 end External_Name_Casing;
14127 ---------------
14128 -- Fast_Math --
14129 ---------------
14131 -- pragma Fast_Math;
14133 when Pragma_Fast_Math =>
14134 GNAT_Pragma;
14135 Check_No_Identifiers;
14136 Check_Valid_Configuration_Pragma;
14137 Fast_Math := True;
14139 --------------------------
14140 -- Favor_Top_Level --
14141 --------------------------
14143 -- pragma Favor_Top_Level (type_NAME);
14145 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
14146 Named_Entity : Entity_Id;
14148 begin
14149 GNAT_Pragma;
14150 Check_No_Identifiers;
14151 Check_Arg_Count (1);
14152 Check_Arg_Is_Local_Name (Arg1);
14153 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
14155 -- If it's an access-to-subprogram type (in particular, not a
14156 -- subtype), set the flag on that type.
14158 if Is_Access_Subprogram_Type (Named_Entity) then
14159 Set_Can_Use_Internal_Rep (Named_Entity, False);
14161 -- Otherwise it's an error (name denotes the wrong sort of entity)
14163 else
14164 Error_Pragma_Arg
14165 ("access-to-subprogram type expected",
14166 Get_Pragma_Arg (Arg1));
14167 end if;
14168 end Favor_Top_Level;
14170 ---------------------------
14171 -- Finalize_Storage_Only --
14172 ---------------------------
14174 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
14176 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
14177 Assoc : constant Node_Id := Arg1;
14178 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
14179 Typ : Entity_Id;
14181 begin
14182 GNAT_Pragma;
14183 Check_No_Identifiers;
14184 Check_Arg_Count (1);
14185 Check_Arg_Is_Local_Name (Arg1);
14187 Find_Type (Type_Id);
14188 Typ := Entity (Type_Id);
14190 if Typ = Any_Type
14191 or else Rep_Item_Too_Early (Typ, N)
14192 then
14193 return;
14194 else
14195 Typ := Underlying_Type (Typ);
14196 end if;
14198 if not Is_Controlled (Typ) then
14199 Error_Pragma ("pragma% must specify controlled type");
14200 end if;
14202 Check_First_Subtype (Arg1);
14204 if Finalize_Storage_Only (Typ) then
14205 Error_Pragma ("duplicate pragma%, only one allowed");
14207 elsif not Rep_Item_Too_Late (Typ, N) then
14208 Set_Finalize_Storage_Only (Base_Type (Typ), True);
14209 end if;
14210 end Finalize_Storage;
14212 -----------
14213 -- Ghost --
14214 -----------
14216 -- pragma Ghost [ (boolean_EXPRESSION) ];
14218 when Pragma_Ghost => Ghost : declare
14219 Context : constant Node_Id := Parent (N);
14220 Expr : Node_Id;
14221 Id : Entity_Id;
14222 Orig_Stmt : Node_Id;
14223 Prev_Id : Entity_Id;
14224 Stmt : Node_Id;
14226 begin
14227 GNAT_Pragma;
14228 Check_No_Identifiers;
14229 Check_At_Most_N_Arguments (1);
14231 Id := Empty;
14232 Stmt := Prev (N);
14233 while Present (Stmt) loop
14235 -- Skip prior pragmas, but check for duplicates
14237 if Nkind (Stmt) = N_Pragma then
14238 if Pragma_Name (Stmt) = Pname then
14239 Error_Msg_Name_1 := Pname;
14240 Error_Msg_Sloc := Sloc (Stmt);
14241 Error_Msg_N ("pragma % duplicates pragma declared#", N);
14242 end if;
14244 -- Protected and task types cannot be subject to pragma Ghost
14246 elsif Nkind (Stmt) = N_Protected_Type_Declaration then
14247 Error_Pragma ("pragma % cannot apply to a protected type");
14248 return;
14250 elsif Nkind (Stmt) = N_Task_Type_Declaration then
14251 Error_Pragma ("pragma % cannot apply to a task type");
14252 return;
14254 -- Skip internally generated code
14256 elsif not Comes_From_Source (Stmt) then
14257 Orig_Stmt := Original_Node (Stmt);
14259 -- When pragma Ghost applies to an untagged derivation, the
14260 -- derivation is transformed into a [sub]type declaration.
14262 if Nkind_In (Stmt, N_Full_Type_Declaration,
14263 N_Subtype_Declaration)
14264 and then Comes_From_Source (Orig_Stmt)
14265 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
14266 and then Nkind (Type_Definition (Orig_Stmt)) =
14267 N_Derived_Type_Definition
14268 then
14269 Id := Defining_Entity (Stmt);
14270 exit;
14272 -- When pragma Ghost applies to an expression function, the
14273 -- expression function is transformed into a subprogram.
14275 elsif Nkind (Stmt) = N_Subprogram_Declaration
14276 and then Comes_From_Source (Orig_Stmt)
14277 and then Nkind (Orig_Stmt) = N_Expression_Function
14278 then
14279 Id := Defining_Entity (Stmt);
14280 exit;
14281 end if;
14283 -- The pragma applies to a legal construct, stop the traversal
14285 elsif Nkind_In (Stmt, N_Abstract_Subprogram_Declaration,
14286 N_Full_Type_Declaration,
14287 N_Generic_Subprogram_Declaration,
14288 N_Object_Declaration,
14289 N_Private_Extension_Declaration,
14290 N_Private_Type_Declaration,
14291 N_Subprogram_Declaration,
14292 N_Subtype_Declaration)
14293 then
14294 Id := Defining_Entity (Stmt);
14295 exit;
14297 -- The pragma does not apply to a legal construct, issue an
14298 -- error and stop the analysis.
14300 else
14301 Error_Pragma
14302 ("pragma % must apply to an object, package, subprogram "
14303 & "or type");
14304 return;
14305 end if;
14307 Stmt := Prev (Stmt);
14308 end loop;
14310 if No (Id) then
14312 -- When pragma Ghost is associated with a [generic] package, it
14313 -- appears in the visible declarations.
14315 if Nkind (Context) = N_Package_Specification
14316 and then Present (Visible_Declarations (Context))
14317 and then List_Containing (N) = Visible_Declarations (Context)
14318 then
14319 Id := Defining_Entity (Context);
14321 -- Pragma Ghost applies to a stand alone subprogram body
14323 elsif Nkind (Context) = N_Subprogram_Body
14324 and then No (Corresponding_Spec (Context))
14325 then
14326 Id := Defining_Entity (Context);
14327 end if;
14328 end if;
14330 if No (Id) then
14331 Error_Pragma
14332 ("pragma % must apply to an object, package, subprogram or "
14333 & "type");
14334 return;
14335 end if;
14337 -- A derived type or type extension cannot be subject to pragma
14338 -- Ghost if either the parent type or one of the progenitor types
14339 -- is not Ghost (SPARK RM 6.9(9)).
14341 if Is_Derived_Type (Id) then
14342 Check_Ghost_Derivation (Id);
14343 end if;
14345 -- Handle completions of types and constants that are subject to
14346 -- pragma Ghost.
14348 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
14349 Prev_Id := Incomplete_Or_Partial_View (Id);
14351 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
14352 Error_Msg_Name_1 := Pname;
14354 -- The full declaration of a deferred constant cannot be
14355 -- subject to pragma Ghost unless the deferred declaration
14356 -- is also Ghost (SPARK RM 6.9(10)).
14358 if Ekind (Prev_Id) = E_Constant then
14359 Error_Msg_Name_1 := Pname;
14360 Error_Msg_NE (Fix_Error
14361 ("pragma % must apply to declaration of deferred "
14362 & "constant &"), N, Id);
14363 return;
14365 -- Pragma Ghost may appear on the full view of an incomplete
14366 -- type because the incomplete declaration lacks aspects and
14367 -- cannot be subject to pragma Ghost.
14369 elsif Ekind (Prev_Id) = E_Incomplete_Type then
14370 null;
14372 -- The full declaration of a type cannot be subject to
14373 -- pragma Ghost unless the partial view is also Ghost
14374 -- (SPARK RM 6.9(10)).
14376 else
14377 Error_Msg_NE (Fix_Error
14378 ("pragma % must apply to partial view of type &"),
14379 N, Id);
14380 return;
14381 end if;
14382 end if;
14383 end if;
14385 -- Analyze the Boolean expression (if any)
14387 if Present (Arg1) then
14388 Expr := Get_Pragma_Arg (Arg1);
14390 Analyze_And_Resolve (Expr, Standard_Boolean);
14392 if Is_OK_Static_Expression (Expr) then
14394 -- "Ghostness" cannot be turned off once enabled within a
14395 -- region (SPARK RM 6.9(7)).
14397 if Is_False (Expr_Value (Expr))
14398 and then Within_Ghost_Scope
14399 then
14400 Error_Pragma
14401 ("pragma % with value False cannot appear in enabled "
14402 & "ghost region");
14403 return;
14404 end if;
14406 -- Otherwie the expression is not static
14408 else
14409 Error_Pragma_Arg
14410 ("expression of pragma % must be static", Expr);
14411 return;
14412 end if;
14413 end if;
14415 Set_Is_Ghost_Entity (Id);
14416 end Ghost;
14418 ------------
14419 -- Global --
14420 ------------
14422 -- pragma Global (GLOBAL_SPECIFICATION);
14424 -- GLOBAL_SPECIFICATION ::=
14425 -- null
14426 -- | GLOBAL_LIST
14427 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
14429 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
14431 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
14432 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
14433 -- GLOBAL_ITEM ::= NAME
14435 when Pragma_Global => Global : declare
14436 Subp_Decl : Node_Id;
14438 begin
14439 GNAT_Pragma;
14440 Check_Arg_Count (1);
14441 Ensure_Aggregate_Form (Arg1);
14443 -- Ensure the proper placement of the pragma. Global must be
14444 -- associated with a subprogram declaration or a body that acts
14445 -- as a spec.
14447 Subp_Decl :=
14448 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
14450 if Nkind (Subp_Decl) = N_Subprogram_Declaration then
14451 null;
14453 -- Body acts as spec
14455 elsif Nkind (Subp_Decl) = N_Subprogram_Body
14456 and then No (Corresponding_Spec (Subp_Decl))
14457 then
14458 null;
14460 -- Body stub acts as spec
14462 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
14463 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
14464 then
14465 null;
14467 else
14468 Pragma_Misplaced;
14469 return;
14470 end if;
14472 -- When the pragma appears on a subprogram body, perform the full
14473 -- analysis now.
14475 if Nkind (Subp_Decl) = N_Subprogram_Body then
14476 Analyze_Global_In_Decl_Part (N);
14478 -- When Global applies to a subprogram compilation unit, the
14479 -- corresponding pragma is placed after the unit's declaration
14480 -- node and needs to be analyzed immediately.
14482 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
14483 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
14484 then
14485 Analyze_Global_In_Decl_Part (N);
14486 end if;
14488 -- Chain the pragma on the contract for further processing
14490 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
14491 end Global;
14493 -----------
14494 -- Ident --
14495 -----------
14497 -- pragma Ident (static_string_EXPRESSION)
14499 -- Note: pragma Comment shares this processing. Pragma Ident is
14500 -- identical in effect to pragma Commment.
14502 when Pragma_Ident | Pragma_Comment => Ident : declare
14503 Str : Node_Id;
14505 begin
14506 GNAT_Pragma;
14507 Check_Arg_Count (1);
14508 Check_No_Identifiers;
14509 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
14510 Store_Note (N);
14512 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
14514 declare
14515 CS : Node_Id;
14516 GP : Node_Id;
14518 begin
14519 GP := Parent (Parent (N));
14521 if Nkind_In (GP, N_Package_Declaration,
14522 N_Generic_Package_Declaration)
14523 then
14524 GP := Parent (GP);
14525 end if;
14527 -- If we have a compilation unit, then record the ident value,
14528 -- checking for improper duplication.
14530 if Nkind (GP) = N_Compilation_Unit then
14531 CS := Ident_String (Current_Sem_Unit);
14533 if Present (CS) then
14535 -- If we have multiple instances, concatenate them, but
14536 -- not in ASIS, where we want the original tree.
14538 if not ASIS_Mode then
14539 Start_String (Strval (CS));
14540 Store_String_Char (' ');
14541 Store_String_Chars (Strval (Str));
14542 Set_Strval (CS, End_String);
14543 end if;
14545 else
14546 Set_Ident_String (Current_Sem_Unit, Str);
14547 end if;
14549 -- For subunits, we just ignore the Ident, since in GNAT these
14550 -- are not separate object files, and hence not separate units
14551 -- in the unit table.
14553 elsif Nkind (GP) = N_Subunit then
14554 null;
14555 end if;
14556 end;
14557 end Ident;
14559 ----------------------------
14560 -- Implementation_Defined --
14561 ----------------------------
14563 -- pragma Implementation_Defined (LOCAL_NAME);
14565 -- Marks previously declared entity as implementation defined. For
14566 -- an overloaded entity, applies to the most recent homonym.
14568 -- pragma Implementation_Defined;
14570 -- The form with no arguments appears anywhere within a scope, most
14571 -- typically a package spec, and indicates that all entities that are
14572 -- defined within the package spec are Implementation_Defined.
14574 when Pragma_Implementation_Defined => Implementation_Defined : declare
14575 Ent : Entity_Id;
14577 begin
14578 GNAT_Pragma;
14579 Check_No_Identifiers;
14581 -- Form with no arguments
14583 if Arg_Count = 0 then
14584 Set_Is_Implementation_Defined (Current_Scope);
14586 -- Form with one argument
14588 else
14589 Check_Arg_Count (1);
14590 Check_Arg_Is_Local_Name (Arg1);
14591 Ent := Entity (Get_Pragma_Arg (Arg1));
14592 Set_Is_Implementation_Defined (Ent);
14593 end if;
14594 end Implementation_Defined;
14596 -----------------
14597 -- Implemented --
14598 -----------------
14600 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
14602 -- IMPLEMENTATION_KIND ::=
14603 -- By_Entry | By_Protected_Procedure | By_Any | Optional
14605 -- "By_Any" and "Optional" are treated as synonyms in order to
14606 -- support Ada 2012 aspect Synchronization.
14608 when Pragma_Implemented => Implemented : declare
14609 Proc_Id : Entity_Id;
14610 Typ : Entity_Id;
14612 begin
14613 Ada_2012_Pragma;
14614 Check_Arg_Count (2);
14615 Check_No_Identifiers;
14616 Check_Arg_Is_Identifier (Arg1);
14617 Check_Arg_Is_Local_Name (Arg1);
14618 Check_Arg_Is_One_Of (Arg2,
14619 Name_By_Any,
14620 Name_By_Entry,
14621 Name_By_Protected_Procedure,
14622 Name_Optional);
14624 -- Extract the name of the local procedure
14626 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
14628 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
14629 -- primitive procedure of a synchronized tagged type.
14631 if Ekind (Proc_Id) = E_Procedure
14632 and then Is_Primitive (Proc_Id)
14633 and then Present (First_Formal (Proc_Id))
14634 then
14635 Typ := Etype (First_Formal (Proc_Id));
14637 if Is_Tagged_Type (Typ)
14638 and then
14640 -- Check for a protected, a synchronized or a task interface
14642 ((Is_Interface (Typ)
14643 and then Is_Synchronized_Interface (Typ))
14645 -- Check for a protected type or a task type that implements
14646 -- an interface.
14648 or else
14649 (Is_Concurrent_Record_Type (Typ)
14650 and then Present (Interfaces (Typ)))
14652 -- Check for a private record extension with keyword
14653 -- "synchronized".
14655 or else
14656 (Ekind_In (Typ, E_Record_Type_With_Private,
14657 E_Record_Subtype_With_Private)
14658 and then Synchronized_Present (Parent (Typ))))
14659 then
14660 null;
14661 else
14662 Error_Pragma_Arg
14663 ("controlling formal must be of synchronized tagged type",
14664 Arg1);
14665 return;
14666 end if;
14668 -- Procedures declared inside a protected type must be accepted
14670 elsif Ekind (Proc_Id) = E_Procedure
14671 and then Is_Protected_Type (Scope (Proc_Id))
14672 then
14673 null;
14675 -- The first argument is not a primitive procedure
14677 else
14678 Error_Pragma_Arg
14679 ("pragma % must be applied to a primitive procedure", Arg1);
14680 return;
14681 end if;
14683 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
14684 -- By_Protected_Procedure to the primitive procedure of a task
14685 -- interface.
14687 if Chars (Arg2) = Name_By_Protected_Procedure
14688 and then Is_Interface (Typ)
14689 and then Is_Task_Interface (Typ)
14690 then
14691 Error_Pragma_Arg
14692 ("implementation kind By_Protected_Procedure cannot be "
14693 & "applied to a task interface primitive", Arg2);
14694 return;
14695 end if;
14697 Record_Rep_Item (Proc_Id, N);
14698 end Implemented;
14700 ----------------------
14701 -- Implicit_Packing --
14702 ----------------------
14704 -- pragma Implicit_Packing;
14706 when Pragma_Implicit_Packing =>
14707 GNAT_Pragma;
14708 Check_Arg_Count (0);
14709 Implicit_Packing := True;
14711 ------------
14712 -- Import --
14713 ------------
14715 -- pragma Import (
14716 -- [Convention =>] convention_IDENTIFIER,
14717 -- [Entity =>] LOCAL_NAME
14718 -- [, [External_Name =>] static_string_EXPRESSION ]
14719 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14721 when Pragma_Import =>
14722 Check_Ada_83_Warning;
14723 Check_Arg_Order
14724 ((Name_Convention,
14725 Name_Entity,
14726 Name_External_Name,
14727 Name_Link_Name));
14729 Check_At_Least_N_Arguments (2);
14730 Check_At_Most_N_Arguments (4);
14731 Process_Import_Or_Interface;
14733 ---------------------
14734 -- Import_Function --
14735 ---------------------
14737 -- pragma Import_Function (
14738 -- [Internal =>] LOCAL_NAME,
14739 -- [, [External =>] EXTERNAL_SYMBOL]
14740 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14741 -- [, [Result_Type =>] SUBTYPE_MARK]
14742 -- [, [Mechanism =>] MECHANISM]
14743 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
14745 -- EXTERNAL_SYMBOL ::=
14746 -- IDENTIFIER
14747 -- | static_string_EXPRESSION
14749 -- PARAMETER_TYPES ::=
14750 -- null
14751 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14753 -- TYPE_DESIGNATOR ::=
14754 -- subtype_NAME
14755 -- | subtype_Name ' Access
14757 -- MECHANISM ::=
14758 -- MECHANISM_NAME
14759 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14761 -- MECHANISM_ASSOCIATION ::=
14762 -- [formal_parameter_NAME =>] MECHANISM_NAME
14764 -- MECHANISM_NAME ::=
14765 -- Value
14766 -- | Reference
14768 when Pragma_Import_Function => Import_Function : declare
14769 Args : Args_List (1 .. 6);
14770 Names : constant Name_List (1 .. 6) := (
14771 Name_Internal,
14772 Name_External,
14773 Name_Parameter_Types,
14774 Name_Result_Type,
14775 Name_Mechanism,
14776 Name_Result_Mechanism);
14778 Internal : Node_Id renames Args (1);
14779 External : Node_Id renames Args (2);
14780 Parameter_Types : Node_Id renames Args (3);
14781 Result_Type : Node_Id renames Args (4);
14782 Mechanism : Node_Id renames Args (5);
14783 Result_Mechanism : Node_Id renames Args (6);
14785 begin
14786 GNAT_Pragma;
14787 Gather_Associations (Names, Args);
14788 Process_Extended_Import_Export_Subprogram_Pragma (
14789 Arg_Internal => Internal,
14790 Arg_External => External,
14791 Arg_Parameter_Types => Parameter_Types,
14792 Arg_Result_Type => Result_Type,
14793 Arg_Mechanism => Mechanism,
14794 Arg_Result_Mechanism => Result_Mechanism);
14795 end Import_Function;
14797 -------------------
14798 -- Import_Object --
14799 -------------------
14801 -- pragma Import_Object (
14802 -- [Internal =>] LOCAL_NAME
14803 -- [, [External =>] EXTERNAL_SYMBOL]
14804 -- [, [Size =>] EXTERNAL_SYMBOL]);
14806 -- EXTERNAL_SYMBOL ::=
14807 -- IDENTIFIER
14808 -- | static_string_EXPRESSION
14810 when Pragma_Import_Object => Import_Object : declare
14811 Args : Args_List (1 .. 3);
14812 Names : constant Name_List (1 .. 3) := (
14813 Name_Internal,
14814 Name_External,
14815 Name_Size);
14817 Internal : Node_Id renames Args (1);
14818 External : Node_Id renames Args (2);
14819 Size : Node_Id renames Args (3);
14821 begin
14822 GNAT_Pragma;
14823 Gather_Associations (Names, Args);
14824 Process_Extended_Import_Export_Object_Pragma (
14825 Arg_Internal => Internal,
14826 Arg_External => External,
14827 Arg_Size => Size);
14828 end Import_Object;
14830 ----------------------
14831 -- Import_Procedure --
14832 ----------------------
14834 -- pragma Import_Procedure (
14835 -- [Internal =>] LOCAL_NAME
14836 -- [, [External =>] EXTERNAL_SYMBOL]
14837 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14838 -- [, [Mechanism =>] MECHANISM]);
14840 -- EXTERNAL_SYMBOL ::=
14841 -- IDENTIFIER
14842 -- | static_string_EXPRESSION
14844 -- PARAMETER_TYPES ::=
14845 -- null
14846 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14848 -- TYPE_DESIGNATOR ::=
14849 -- subtype_NAME
14850 -- | subtype_Name ' Access
14852 -- MECHANISM ::=
14853 -- MECHANISM_NAME
14854 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14856 -- MECHANISM_ASSOCIATION ::=
14857 -- [formal_parameter_NAME =>] MECHANISM_NAME
14859 -- MECHANISM_NAME ::=
14860 -- Value
14861 -- | Reference
14863 when Pragma_Import_Procedure => Import_Procedure : declare
14864 Args : Args_List (1 .. 4);
14865 Names : constant Name_List (1 .. 4) := (
14866 Name_Internal,
14867 Name_External,
14868 Name_Parameter_Types,
14869 Name_Mechanism);
14871 Internal : Node_Id renames Args (1);
14872 External : Node_Id renames Args (2);
14873 Parameter_Types : Node_Id renames Args (3);
14874 Mechanism : Node_Id renames Args (4);
14876 begin
14877 GNAT_Pragma;
14878 Gather_Associations (Names, Args);
14879 Process_Extended_Import_Export_Subprogram_Pragma (
14880 Arg_Internal => Internal,
14881 Arg_External => External,
14882 Arg_Parameter_Types => Parameter_Types,
14883 Arg_Mechanism => Mechanism);
14884 end Import_Procedure;
14886 -----------------------------
14887 -- Import_Valued_Procedure --
14888 -----------------------------
14890 -- pragma Import_Valued_Procedure (
14891 -- [Internal =>] LOCAL_NAME
14892 -- [, [External =>] EXTERNAL_SYMBOL]
14893 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14894 -- [, [Mechanism =>] MECHANISM]);
14896 -- EXTERNAL_SYMBOL ::=
14897 -- IDENTIFIER
14898 -- | static_string_EXPRESSION
14900 -- PARAMETER_TYPES ::=
14901 -- null
14902 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14904 -- TYPE_DESIGNATOR ::=
14905 -- subtype_NAME
14906 -- | subtype_Name ' Access
14908 -- MECHANISM ::=
14909 -- MECHANISM_NAME
14910 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14912 -- MECHANISM_ASSOCIATION ::=
14913 -- [formal_parameter_NAME =>] MECHANISM_NAME
14915 -- MECHANISM_NAME ::=
14916 -- Value
14917 -- | Reference
14919 when Pragma_Import_Valued_Procedure =>
14920 Import_Valued_Procedure : declare
14921 Args : Args_List (1 .. 4);
14922 Names : constant Name_List (1 .. 4) := (
14923 Name_Internal,
14924 Name_External,
14925 Name_Parameter_Types,
14926 Name_Mechanism);
14928 Internal : Node_Id renames Args (1);
14929 External : Node_Id renames Args (2);
14930 Parameter_Types : Node_Id renames Args (3);
14931 Mechanism : Node_Id renames Args (4);
14933 begin
14934 GNAT_Pragma;
14935 Gather_Associations (Names, Args);
14936 Process_Extended_Import_Export_Subprogram_Pragma (
14937 Arg_Internal => Internal,
14938 Arg_External => External,
14939 Arg_Parameter_Types => Parameter_Types,
14940 Arg_Mechanism => Mechanism);
14941 end Import_Valued_Procedure;
14943 -----------------
14944 -- Independent --
14945 -----------------
14947 -- pragma Independent (record_component_LOCAL_NAME);
14949 when Pragma_Independent => Independent : declare
14950 E_Id : Node_Id;
14951 E : Entity_Id;
14953 begin
14954 Check_Ada_83_Warning;
14955 Ada_2012_Pragma;
14956 Check_No_Identifiers;
14957 Check_Arg_Count (1);
14958 Check_Arg_Is_Local_Name (Arg1);
14959 E_Id := Get_Pragma_Arg (Arg1);
14961 if Etype (E_Id) = Any_Type then
14962 return;
14963 end if;
14965 E := Entity (E_Id);
14967 -- Check we have a record component. We have not yet setup
14968 -- components fully, so identify by syntactic structure.
14970 if Nkind (Declaration_Node (E)) /= N_Component_Declaration then
14971 Error_Pragma_Arg
14972 ("argument for pragma% must be record component", Arg1);
14973 end if;
14975 -- Check duplicate before we chain ourselves
14977 Check_Duplicate_Pragma (E);
14979 -- Chain pragma
14981 if Rep_Item_Too_Early (E, N)
14982 or else
14983 Rep_Item_Too_Late (E, N)
14984 then
14985 return;
14986 end if;
14988 -- Set flag in component
14990 Set_Is_Independent (E);
14992 Independence_Checks.Append ((N, E));
14993 end Independent;
14995 ----------------------------
14996 -- Independent_Components --
14997 ----------------------------
14999 -- pragma Atomic_Components (array_LOCAL_NAME);
15001 -- This processing is shared by Volatile_Components
15003 when Pragma_Independent_Components => Independent_Components : declare
15004 E_Id : Node_Id;
15005 E : Entity_Id;
15006 D : Node_Id;
15007 K : Node_Kind;
15008 C : Node_Id;
15010 begin
15011 Check_Ada_83_Warning;
15012 Ada_2012_Pragma;
15013 Check_No_Identifiers;
15014 Check_Arg_Count (1);
15015 Check_Arg_Is_Local_Name (Arg1);
15016 E_Id := Get_Pragma_Arg (Arg1);
15018 if Etype (E_Id) = Any_Type then
15019 return;
15020 end if;
15022 E := Entity (E_Id);
15024 -- Check duplicate before we chain ourselves
15026 Check_Duplicate_Pragma (E);
15028 -- Check appropriate entity
15030 if Rep_Item_Too_Early (E, N)
15031 or else
15032 Rep_Item_Too_Late (E, N)
15033 then
15034 return;
15035 end if;
15037 D := Declaration_Node (E);
15038 K := Nkind (D);
15040 if K = N_Full_Type_Declaration
15041 and then (Is_Array_Type (E) or else Is_Record_Type (E))
15042 then
15043 Independence_Checks.Append ((N, Base_Type (E)));
15044 Set_Has_Independent_Components (Base_Type (E));
15046 -- For record type, set all components independent
15048 if Is_Record_Type (E) then
15049 C := First_Component (E);
15050 while Present (C) loop
15051 Set_Is_Independent (C);
15052 Next_Component (C);
15053 end loop;
15054 end if;
15056 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
15057 and then Nkind (D) = N_Object_Declaration
15058 and then Nkind (Object_Definition (D)) =
15059 N_Constrained_Array_Definition
15060 then
15061 Independence_Checks.Append ((N, Base_Type (Etype (E))));
15062 Set_Has_Independent_Components (Base_Type (Etype (E)));
15064 else
15065 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
15066 end if;
15067 end Independent_Components;
15069 -----------------------
15070 -- Initial_Condition --
15071 -----------------------
15073 -- pragma Initial_Condition (boolean_EXPRESSION);
15075 when Pragma_Initial_Condition => Initial_Condition : declare
15076 Context : constant Node_Id := Parent (Parent (N));
15077 Pack_Id : Entity_Id;
15078 Stmt : Node_Id;
15080 begin
15081 GNAT_Pragma;
15082 Check_No_Identifiers;
15083 Check_Arg_Count (1);
15085 -- Ensure the proper placement of the pragma. Initial_Condition
15086 -- must be associated with a package declaration.
15088 if not Nkind_In (Context, N_Generic_Package_Declaration,
15089 N_Package_Declaration)
15090 then
15091 Pragma_Misplaced;
15092 return;
15093 end if;
15095 Stmt := Prev (N);
15096 while Present (Stmt) loop
15098 -- Skip prior pragmas, but check for duplicates
15100 if Nkind (Stmt) = N_Pragma then
15101 if Pragma_Name (Stmt) = Pname then
15102 Error_Msg_Name_1 := Pname;
15103 Error_Msg_Sloc := Sloc (Stmt);
15104 Error_Msg_N ("pragma % duplicates pragma declared #", N);
15105 end if;
15107 -- Skip internally generated code
15109 elsif not Comes_From_Source (Stmt) then
15110 null;
15112 -- The pragma does not apply to a legal construct, issue an
15113 -- error and stop the analysis.
15115 else
15116 Pragma_Misplaced;
15117 return;
15118 end if;
15120 Stmt := Prev (Stmt);
15121 end loop;
15123 -- The pragma must be analyzed at the end of the visible
15124 -- declarations of the related package. Save the pragma for later
15125 -- (see Analyze_Initial_Condition_In_Decl_Part) by adding it to
15126 -- the contract of the package.
15128 Pack_Id := Defining_Entity (Context);
15129 Add_Contract_Item (N, Pack_Id);
15131 -- Verify the declaration order of pragma Initial_Condition with
15132 -- respect to pragmas Abstract_State and Initializes when SPARK
15133 -- checks are enabled.
15135 if SPARK_Mode /= Off then
15136 Check_Declaration_Order
15137 (First => Get_Pragma (Pack_Id, Pragma_Abstract_State),
15138 Second => N);
15140 Check_Declaration_Order
15141 (First => Get_Pragma (Pack_Id, Pragma_Initializes),
15142 Second => N);
15143 end if;
15144 end Initial_Condition;
15146 ------------------------
15147 -- Initialize_Scalars --
15148 ------------------------
15150 -- pragma Initialize_Scalars;
15152 when Pragma_Initialize_Scalars =>
15153 GNAT_Pragma;
15154 Check_Arg_Count (0);
15155 Check_Valid_Configuration_Pragma;
15156 Check_Restriction (No_Initialize_Scalars, N);
15158 -- Initialize_Scalars creates false positives in CodePeer, and
15159 -- incorrect negative results in GNATprove mode, so ignore this
15160 -- pragma in these modes.
15162 if not Restriction_Active (No_Initialize_Scalars)
15163 and then not (CodePeer_Mode or GNATprove_Mode)
15164 then
15165 Init_Or_Norm_Scalars := True;
15166 Initialize_Scalars := True;
15167 end if;
15169 -----------------
15170 -- Initializes --
15171 -----------------
15173 -- pragma Initializes (INITIALIZATION_SPEC);
15175 -- INITIALIZATION_SPEC ::= null | INITIALIZATION_LIST
15177 -- INITIALIZATION_LIST ::=
15178 -- INITIALIZATION_ITEM
15179 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
15181 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
15183 -- INPUT_LIST ::=
15184 -- null
15185 -- | INPUT
15186 -- | (INPUT {, INPUT})
15188 -- INPUT ::= name
15190 when Pragma_Initializes => Initializes : declare
15191 Context : constant Node_Id := Parent (Parent (N));
15192 Pack_Id : Entity_Id;
15193 Stmt : Node_Id;
15195 begin
15196 GNAT_Pragma;
15197 Check_No_Identifiers;
15198 Check_Arg_Count (1);
15199 Ensure_Aggregate_Form (Arg1);
15201 -- Ensure the proper placement of the pragma. Initializes must be
15202 -- associated with a package declaration.
15204 if not Nkind_In (Context, N_Generic_Package_Declaration,
15205 N_Package_Declaration)
15206 then
15207 Pragma_Misplaced;
15208 return;
15209 end if;
15211 Stmt := Prev (N);
15212 while Present (Stmt) loop
15214 -- Skip prior pragmas, but check for duplicates
15216 if Nkind (Stmt) = N_Pragma then
15217 if Pragma_Name (Stmt) = Pname then
15218 Error_Msg_Name_1 := Pname;
15219 Error_Msg_Sloc := Sloc (Stmt);
15220 Error_Msg_N ("pragma % duplicates pragma declared #", N);
15221 end if;
15223 -- Skip internally generated code
15225 elsif not Comes_From_Source (Stmt) then
15226 null;
15228 -- The pragma does not apply to a legal construct, issue an
15229 -- error and stop the analysis.
15231 else
15232 Pragma_Misplaced;
15233 return;
15234 end if;
15236 Stmt := Prev (Stmt);
15237 end loop;
15239 -- The pragma must be analyzed at the end of the visible
15240 -- declarations of the related package. Save the pragma for later
15241 -- (see Analyze_Initializes_In_Decl_Part) by adding it to the
15242 -- contract of the package.
15244 Pack_Id := Defining_Entity (Context);
15245 Add_Contract_Item (N, Pack_Id);
15247 -- Verify the declaration order of pragmas Abstract_State and
15248 -- Initializes when SPARK checks are enabled.
15250 if SPARK_Mode /= Off then
15251 Check_Declaration_Order
15252 (First => Get_Pragma (Pack_Id, Pragma_Abstract_State),
15253 Second => N);
15254 end if;
15255 end Initializes;
15257 ------------
15258 -- Inline --
15259 ------------
15261 -- pragma Inline ( NAME {, NAME} );
15263 when Pragma_Inline =>
15265 -- Pragma always active unless in GNATprove mode. It is disabled
15266 -- in GNATprove mode because frontend inlining is applied
15267 -- independently of pragmas Inline and Inline_Always for
15268 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
15269 -- in inline.ads.
15271 if not GNATprove_Mode then
15273 -- Inline status is Enabled if inlining option is active
15275 if Inline_Active then
15276 Process_Inline (Enabled);
15277 else
15278 Process_Inline (Disabled);
15279 end if;
15280 end if;
15282 -------------------
15283 -- Inline_Always --
15284 -------------------
15286 -- pragma Inline_Always ( NAME {, NAME} );
15288 when Pragma_Inline_Always =>
15289 GNAT_Pragma;
15291 -- Pragma always active unless in CodePeer mode or GNATprove
15292 -- mode. It is disabled in CodePeer mode because inlining is
15293 -- not helpful, and enabling it caused walk order issues. It
15294 -- is disabled in GNATprove mode because frontend inlining is
15295 -- applied independently of pragmas Inline and Inline_Always for
15296 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
15297 -- inline.ads.
15299 if not CodePeer_Mode and not GNATprove_Mode then
15300 Process_Inline (Enabled);
15301 end if;
15303 --------------------
15304 -- Inline_Generic --
15305 --------------------
15307 -- pragma Inline_Generic (NAME {, NAME});
15309 when Pragma_Inline_Generic =>
15310 GNAT_Pragma;
15311 Process_Generic_List;
15313 ----------------------
15314 -- Inspection_Point --
15315 ----------------------
15317 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
15319 when Pragma_Inspection_Point => Inspection_Point : declare
15320 Arg : Node_Id;
15321 Exp : Node_Id;
15323 begin
15326 if Arg_Count > 0 then
15327 Arg := Arg1;
15328 loop
15329 Exp := Get_Pragma_Arg (Arg);
15330 Analyze (Exp);
15332 if not Is_Entity_Name (Exp)
15333 or else not Is_Object (Entity (Exp))
15334 then
15335 Error_Pragma_Arg ("object name required", Arg);
15336 end if;
15338 Next (Arg);
15339 exit when No (Arg);
15340 end loop;
15341 end if;
15342 end Inspection_Point;
15344 ---------------
15345 -- Interface --
15346 ---------------
15348 -- pragma Interface (
15349 -- [ Convention =>] convention_IDENTIFIER,
15350 -- [ Entity =>] LOCAL_NAME
15351 -- [, [External_Name =>] static_string_EXPRESSION ]
15352 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15354 when Pragma_Interface =>
15355 GNAT_Pragma;
15356 Check_Arg_Order
15357 ((Name_Convention,
15358 Name_Entity,
15359 Name_External_Name,
15360 Name_Link_Name));
15361 Check_At_Least_N_Arguments (2);
15362 Check_At_Most_N_Arguments (4);
15363 Process_Import_Or_Interface;
15365 -- In Ada 2005, the permission to use Interface (a reserved word)
15366 -- as a pragma name is considered an obsolescent feature, and this
15367 -- pragma was already obsolescent in Ada 95.
15369 if Ada_Version >= Ada_95 then
15370 Check_Restriction
15371 (No_Obsolescent_Features, Pragma_Identifier (N));
15373 if Warn_On_Obsolescent_Feature then
15374 Error_Msg_N
15375 ("pragma Interface is an obsolescent feature?j?", N);
15376 Error_Msg_N
15377 ("|use pragma Import instead?j?", N);
15378 end if;
15379 end if;
15381 --------------------
15382 -- Interface_Name --
15383 --------------------
15385 -- pragma Interface_Name (
15386 -- [ Entity =>] LOCAL_NAME
15387 -- [,[External_Name =>] static_string_EXPRESSION ]
15388 -- [,[Link_Name =>] static_string_EXPRESSION ]);
15390 when Pragma_Interface_Name => Interface_Name : declare
15391 Id : Node_Id;
15392 Def_Id : Entity_Id;
15393 Hom_Id : Entity_Id;
15394 Found : Boolean;
15396 begin
15397 GNAT_Pragma;
15398 Check_Arg_Order
15399 ((Name_Entity, Name_External_Name, Name_Link_Name));
15400 Check_At_Least_N_Arguments (2);
15401 Check_At_Most_N_Arguments (3);
15402 Id := Get_Pragma_Arg (Arg1);
15403 Analyze (Id);
15405 -- This is obsolete from Ada 95 on, but it is an implementation
15406 -- defined pragma, so we do not consider that it violates the
15407 -- restriction (No_Obsolescent_Features).
15409 if Ada_Version >= Ada_95 then
15410 if Warn_On_Obsolescent_Feature then
15411 Error_Msg_N
15412 ("pragma Interface_Name is an obsolescent feature?j?", N);
15413 Error_Msg_N
15414 ("|use pragma Import instead?j?", N);
15415 end if;
15416 end if;
15418 if not Is_Entity_Name (Id) then
15419 Error_Pragma_Arg
15420 ("first argument for pragma% must be entity name", Arg1);
15421 elsif Etype (Id) = Any_Type then
15422 return;
15423 else
15424 Def_Id := Entity (Id);
15425 end if;
15427 -- Special DEC-compatible processing for the object case, forces
15428 -- object to be imported.
15430 if Ekind (Def_Id) = E_Variable then
15431 Kill_Size_Check_Code (Def_Id);
15432 Note_Possible_Modification (Id, Sure => False);
15434 -- Initialization is not allowed for imported variable
15436 if Present (Expression (Parent (Def_Id)))
15437 and then Comes_From_Source (Expression (Parent (Def_Id)))
15438 then
15439 Error_Msg_Sloc := Sloc (Def_Id);
15440 Error_Pragma_Arg
15441 ("no initialization allowed for declaration of& #",
15442 Arg2);
15444 else
15445 -- For compatibility, support VADS usage of providing both
15446 -- pragmas Interface and Interface_Name to obtain the effect
15447 -- of a single Import pragma.
15449 if Is_Imported (Def_Id)
15450 and then Present (First_Rep_Item (Def_Id))
15451 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
15452 and then
15453 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
15454 then
15455 null;
15456 else
15457 Set_Imported (Def_Id);
15458 end if;
15460 Set_Is_Public (Def_Id);
15461 Process_Interface_Name (Def_Id, Arg2, Arg3);
15462 end if;
15464 -- Otherwise must be subprogram
15466 elsif not Is_Subprogram (Def_Id) then
15467 Error_Pragma_Arg
15468 ("argument of pragma% is not subprogram", Arg1);
15470 else
15471 Check_At_Most_N_Arguments (3);
15472 Hom_Id := Def_Id;
15473 Found := False;
15475 -- Loop through homonyms
15477 loop
15478 Def_Id := Get_Base_Subprogram (Hom_Id);
15480 if Is_Imported (Def_Id) then
15481 Process_Interface_Name (Def_Id, Arg2, Arg3);
15482 Found := True;
15483 end if;
15485 exit when From_Aspect_Specification (N);
15486 Hom_Id := Homonym (Hom_Id);
15488 exit when No (Hom_Id)
15489 or else Scope (Hom_Id) /= Current_Scope;
15490 end loop;
15492 if not Found then
15493 Error_Pragma_Arg
15494 ("argument of pragma% is not imported subprogram",
15495 Arg1);
15496 end if;
15497 end if;
15498 end Interface_Name;
15500 -----------------------
15501 -- Interrupt_Handler --
15502 -----------------------
15504 -- pragma Interrupt_Handler (handler_NAME);
15506 when Pragma_Interrupt_Handler =>
15507 Check_Ada_83_Warning;
15508 Check_Arg_Count (1);
15509 Check_No_Identifiers;
15511 if No_Run_Time_Mode then
15512 Error_Msg_CRT ("Interrupt_Handler pragma", N);
15513 else
15514 Check_Interrupt_Or_Attach_Handler;
15515 Process_Interrupt_Or_Attach_Handler;
15516 end if;
15518 ------------------------
15519 -- Interrupt_Priority --
15520 ------------------------
15522 -- pragma Interrupt_Priority [(EXPRESSION)];
15524 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
15525 P : constant Node_Id := Parent (N);
15526 Arg : Node_Id;
15527 Ent : Entity_Id;
15529 begin
15530 Check_Ada_83_Warning;
15532 if Arg_Count /= 0 then
15533 Arg := Get_Pragma_Arg (Arg1);
15534 Check_Arg_Count (1);
15535 Check_No_Identifiers;
15537 -- The expression must be analyzed in the special manner
15538 -- described in "Handling of Default and Per-Object
15539 -- Expressions" in sem.ads.
15541 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
15542 end if;
15544 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
15545 Pragma_Misplaced;
15546 return;
15548 else
15549 Ent := Defining_Identifier (Parent (P));
15551 -- Check duplicate pragma before we chain the pragma in the Rep
15552 -- Item chain of Ent.
15554 Check_Duplicate_Pragma (Ent);
15555 Record_Rep_Item (Ent, N);
15556 end if;
15557 end Interrupt_Priority;
15559 ---------------------
15560 -- Interrupt_State --
15561 ---------------------
15563 -- pragma Interrupt_State (
15564 -- [Name =>] INTERRUPT_ID,
15565 -- [State =>] INTERRUPT_STATE);
15567 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
15568 -- INTERRUPT_STATE => System | Runtime | User
15570 -- Note: if the interrupt id is given as an identifier, then it must
15571 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
15572 -- given as a static integer expression which must be in the range of
15573 -- Ada.Interrupts.Interrupt_ID.
15575 when Pragma_Interrupt_State => Interrupt_State : declare
15576 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
15577 -- This is the entity Ada.Interrupts.Interrupt_ID;
15579 State_Type : Character;
15580 -- Set to 's'/'r'/'u' for System/Runtime/User
15582 IST_Num : Pos;
15583 -- Index to entry in Interrupt_States table
15585 Int_Val : Uint;
15586 -- Value of interrupt
15588 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
15589 -- The first argument to the pragma
15591 Int_Ent : Entity_Id;
15592 -- Interrupt entity in Ada.Interrupts.Names
15594 begin
15595 GNAT_Pragma;
15596 Check_Arg_Order ((Name_Name, Name_State));
15597 Check_Arg_Count (2);
15599 Check_Optional_Identifier (Arg1, Name_Name);
15600 Check_Optional_Identifier (Arg2, Name_State);
15601 Check_Arg_Is_Identifier (Arg2);
15603 -- First argument is identifier
15605 if Nkind (Arg1X) = N_Identifier then
15607 -- Search list of names in Ada.Interrupts.Names
15609 Int_Ent := First_Entity (RTE (RE_Names));
15610 loop
15611 if No (Int_Ent) then
15612 Error_Pragma_Arg ("invalid interrupt name", Arg1);
15614 elsif Chars (Int_Ent) = Chars (Arg1X) then
15615 Int_Val := Expr_Value (Constant_Value (Int_Ent));
15616 exit;
15617 end if;
15619 Next_Entity (Int_Ent);
15620 end loop;
15622 -- First argument is not an identifier, so it must be a static
15623 -- expression of type Ada.Interrupts.Interrupt_ID.
15625 else
15626 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
15627 Int_Val := Expr_Value (Arg1X);
15629 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
15630 or else
15631 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
15632 then
15633 Error_Pragma_Arg
15634 ("value not in range of type "
15635 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
15636 end if;
15637 end if;
15639 -- Check OK state
15641 case Chars (Get_Pragma_Arg (Arg2)) is
15642 when Name_Runtime => State_Type := 'r';
15643 when Name_System => State_Type := 's';
15644 when Name_User => State_Type := 'u';
15646 when others =>
15647 Error_Pragma_Arg ("invalid interrupt state", Arg2);
15648 end case;
15650 -- Check if entry is already stored
15652 IST_Num := Interrupt_States.First;
15653 loop
15654 -- If entry not found, add it
15656 if IST_Num > Interrupt_States.Last then
15657 Interrupt_States.Append
15658 ((Interrupt_Number => UI_To_Int (Int_Val),
15659 Interrupt_State => State_Type,
15660 Pragma_Loc => Loc));
15661 exit;
15663 -- Case of entry for the same entry
15665 elsif Int_Val = Interrupt_States.Table (IST_Num).
15666 Interrupt_Number
15667 then
15668 -- If state matches, done, no need to make redundant entry
15670 exit when
15671 State_Type = Interrupt_States.Table (IST_Num).
15672 Interrupt_State;
15674 -- Otherwise if state does not match, error
15676 Error_Msg_Sloc :=
15677 Interrupt_States.Table (IST_Num).Pragma_Loc;
15678 Error_Pragma_Arg
15679 ("state conflicts with that given #", Arg2);
15680 exit;
15681 end if;
15683 IST_Num := IST_Num + 1;
15684 end loop;
15685 end Interrupt_State;
15687 ---------------
15688 -- Invariant --
15689 ---------------
15691 -- pragma Invariant
15692 -- ([Entity =>] type_LOCAL_NAME,
15693 -- [Check =>] EXPRESSION
15694 -- [,[Message =>] String_Expression]);
15696 when Pragma_Invariant => Invariant : declare
15697 Type_Id : Node_Id;
15698 Typ : Entity_Id;
15699 Discard : Boolean;
15701 begin
15702 GNAT_Pragma;
15703 Check_At_Least_N_Arguments (2);
15704 Check_At_Most_N_Arguments (3);
15705 Check_Optional_Identifier (Arg1, Name_Entity);
15706 Check_Optional_Identifier (Arg2, Name_Check);
15708 if Arg_Count = 3 then
15709 Check_Optional_Identifier (Arg3, Name_Message);
15710 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
15711 end if;
15713 Check_Arg_Is_Local_Name (Arg1);
15715 Type_Id := Get_Pragma_Arg (Arg1);
15716 Find_Type (Type_Id);
15717 Typ := Entity (Type_Id);
15719 if Typ = Any_Type then
15720 return;
15722 -- An invariant must apply to a private type, or appear in the
15723 -- private part of a package spec and apply to a completion.
15724 -- a class-wide invariant can only appear on a private declaration
15725 -- or private extension, not a completion.
15727 elsif Ekind_In (Typ, E_Private_Type,
15728 E_Record_Type_With_Private,
15729 E_Limited_Private_Type)
15730 then
15731 null;
15733 elsif In_Private_Part (Current_Scope)
15734 and then Has_Private_Declaration (Typ)
15735 and then not Class_Present (N)
15736 then
15737 null;
15739 elsif In_Private_Part (Current_Scope) then
15740 Error_Pragma_Arg
15741 ("pragma% only allowed for private type declared in "
15742 & "visible part", Arg1);
15744 else
15745 Error_Pragma_Arg
15746 ("pragma% only allowed for private type", Arg1);
15747 end if;
15749 -- Note that the type has at least one invariant, and also that
15750 -- it has inheritable invariants if we have Invariant'Class
15751 -- or Type_Invariant'Class. Build the corresponding invariant
15752 -- procedure declaration, so that calls to it can be generated
15753 -- before the body is built (e.g. within an expression function).
15755 Insert_After_And_Analyze
15756 (N, Build_Invariant_Procedure_Declaration (Typ));
15758 if Class_Present (N) then
15759 Set_Has_Inheritable_Invariants (Typ);
15760 end if;
15762 -- The remaining processing is simply to link the pragma on to
15763 -- the rep item chain, for processing when the type is frozen.
15764 -- This is accomplished by a call to Rep_Item_Too_Late.
15766 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
15767 end Invariant;
15769 ----------------------
15770 -- Java_Constructor --
15771 ----------------------
15773 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
15775 -- Also handles pragma CIL_Constructor
15777 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
15778 Java_Constructor : declare
15779 Convention : Convention_Id;
15780 Def_Id : Entity_Id;
15781 Hom_Id : Entity_Id;
15782 Id : Entity_Id;
15783 This_Formal : Entity_Id;
15785 begin
15786 GNAT_Pragma;
15787 Check_Arg_Count (1);
15788 Check_Optional_Identifier (Arg1, Name_Entity);
15789 Check_Arg_Is_Local_Name (Arg1);
15791 Id := Get_Pragma_Arg (Arg1);
15792 Find_Program_Unit_Name (Id);
15794 -- If we did not find the name, we are done
15796 if Etype (Id) = Any_Type then
15797 return;
15798 end if;
15800 -- Check wrong use of pragma in wrong VM target
15802 if VM_Target = No_VM then
15803 return;
15805 elsif VM_Target = CLI_Target
15806 and then Prag_Id = Pragma_Java_Constructor
15807 then
15808 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
15810 elsif VM_Target = JVM_Target
15811 and then Prag_Id = Pragma_CIL_Constructor
15812 then
15813 Error_Pragma ("must use pragma 'Java_'Constructor");
15814 end if;
15816 case Prag_Id is
15817 when Pragma_CIL_Constructor => Convention := Convention_CIL;
15818 when Pragma_Java_Constructor => Convention := Convention_Java;
15819 when others => null;
15820 end case;
15822 Hom_Id := Entity (Id);
15824 -- Loop through homonyms
15826 loop
15827 Def_Id := Get_Base_Subprogram (Hom_Id);
15829 -- The constructor is required to be a function
15831 if Ekind (Def_Id) /= E_Function then
15832 if VM_Target = JVM_Target then
15833 Error_Pragma_Arg
15834 ("pragma% requires function returning a 'Java access "
15835 & "type", Def_Id);
15836 else
15837 Error_Pragma_Arg
15838 ("pragma% requires function returning a 'C'I'L access "
15839 & "type", Def_Id);
15840 end if;
15841 end if;
15843 -- Check arguments: For tagged type the first formal must be
15844 -- named "this" and its type must be a named access type
15845 -- designating a class-wide tagged type that has convention
15846 -- CIL/Java. The first formal must also have a null default
15847 -- value. For example:
15849 -- type Typ is tagged ...
15850 -- type Ref is access all Typ;
15851 -- pragma Convention (CIL, Typ);
15853 -- function New_Typ (This : Ref) return Ref;
15854 -- function New_Typ (This : Ref; I : Integer) return Ref;
15855 -- pragma Cil_Constructor (New_Typ);
15857 -- Reason: The first formal must NOT be a primitive of the
15858 -- tagged type.
15860 -- This rule also applies to constructors of delegates used
15861 -- to interface with standard target libraries. For example:
15863 -- type Delegate is access procedure ...
15864 -- pragma Import (CIL, Delegate, ...);
15866 -- function new_Delegate
15867 -- (This : Delegate := null; ... ) return Delegate;
15869 -- For value-types this rule does not apply.
15871 if not Is_Value_Type (Etype (Def_Id)) then
15872 if No (First_Formal (Def_Id)) then
15873 Error_Msg_Name_1 := Pname;
15874 Error_Msg_N ("% function must have parameters", Def_Id);
15875 return;
15876 end if;
15878 -- In the JRE library we have several occurrences in which
15879 -- the "this" parameter is not the first formal.
15881 This_Formal := First_Formal (Def_Id);
15883 -- In the JRE library we have several occurrences in which
15884 -- the "this" parameter is not the first formal. Search for
15885 -- it.
15887 if VM_Target = JVM_Target then
15888 while Present (This_Formal)
15889 and then Get_Name_String (Chars (This_Formal)) /= "this"
15890 loop
15891 Next_Formal (This_Formal);
15892 end loop;
15894 if No (This_Formal) then
15895 This_Formal := First_Formal (Def_Id);
15896 end if;
15897 end if;
15899 -- Warning: The first parameter should be named "this".
15900 -- We temporarily allow it because we have the following
15901 -- case in the Java runtime (file s-osinte.ads) ???
15903 -- function new_Thread
15904 -- (Self_Id : System.Address) return Thread_Id;
15905 -- pragma Java_Constructor (new_Thread);
15907 if VM_Target = JVM_Target
15908 and then Get_Name_String (Chars (First_Formal (Def_Id)))
15909 = "self_id"
15910 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
15911 then
15912 null;
15914 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
15915 Error_Msg_Name_1 := Pname;
15916 Error_Msg_N
15917 ("first formal of % function must be named `this`",
15918 Parent (This_Formal));
15920 elsif not Is_Access_Type (Etype (This_Formal)) then
15921 Error_Msg_Name_1 := Pname;
15922 Error_Msg_N
15923 ("first formal of % function must be an access type",
15924 Parameter_Type (Parent (This_Formal)));
15926 -- For delegates the type of the first formal must be a
15927 -- named access-to-subprogram type (see previous example)
15929 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
15930 and then Ekind (Etype (This_Formal))
15931 /= E_Access_Subprogram_Type
15932 then
15933 Error_Msg_Name_1 := Pname;
15934 Error_Msg_N
15935 ("first formal of % function must be a named access "
15936 & "to subprogram type",
15937 Parameter_Type (Parent (This_Formal)));
15939 -- Warning: We should reject anonymous access types because
15940 -- the constructor must not be handled as a primitive of the
15941 -- tagged type. We temporarily allow it because this profile
15942 -- is currently generated by cil2ada???
15944 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
15945 and then not Ekind_In (Etype (This_Formal),
15946 E_Access_Type,
15947 E_General_Access_Type,
15948 E_Anonymous_Access_Type)
15949 then
15950 Error_Msg_Name_1 := Pname;
15951 Error_Msg_N
15952 ("first formal of % function must be a named access "
15953 & "type", Parameter_Type (Parent (This_Formal)));
15955 elsif Atree.Convention
15956 (Designated_Type (Etype (This_Formal))) /= Convention
15957 then
15958 Error_Msg_Name_1 := Pname;
15960 if Convention = Convention_Java then
15961 Error_Msg_N
15962 ("pragma% requires convention 'Cil in designated "
15963 & "type", Parameter_Type (Parent (This_Formal)));
15964 else
15965 Error_Msg_N
15966 ("pragma% requires convention 'Java in designated "
15967 & "type", Parameter_Type (Parent (This_Formal)));
15968 end if;
15970 elsif No (Expression (Parent (This_Formal)))
15971 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
15972 then
15973 Error_Msg_Name_1 := Pname;
15974 Error_Msg_N
15975 ("pragma% requires first formal with default `null`",
15976 Parameter_Type (Parent (This_Formal)));
15977 end if;
15978 end if;
15980 -- Check result type: the constructor must be a function
15981 -- returning:
15982 -- * a value type (only allowed in the CIL compiler)
15983 -- * an access-to-subprogram type with convention Java/CIL
15984 -- * an access-type designating a type that has convention
15985 -- Java/CIL.
15987 if Is_Value_Type (Etype (Def_Id)) then
15988 null;
15990 -- Access-to-subprogram type with convention Java/CIL
15992 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
15993 if Atree.Convention (Etype (Def_Id)) /= Convention then
15994 if Convention = Convention_Java then
15995 Error_Pragma_Arg
15996 ("pragma% requires function returning a 'Java "
15997 & "access type", Arg1);
15998 else
15999 pragma Assert (Convention = Convention_CIL);
16000 Error_Pragma_Arg
16001 ("pragma% requires function returning a 'C'I'L "
16002 & "access type", Arg1);
16003 end if;
16004 end if;
16006 elsif Is_Access_Type (Etype (Def_Id)) then
16007 if not Ekind_In (Etype (Def_Id), E_Access_Type,
16008 E_General_Access_Type)
16009 or else
16010 Atree.Convention
16011 (Designated_Type (Etype (Def_Id))) /= Convention
16012 then
16013 Error_Msg_Name_1 := Pname;
16015 if Convention = Convention_Java then
16016 Error_Pragma_Arg
16017 ("pragma% requires function returning a named "
16018 & "'Java access type", Arg1);
16019 else
16020 Error_Pragma_Arg
16021 ("pragma% requires function returning a named "
16022 & "'C'I'L access type", Arg1);
16023 end if;
16024 end if;
16025 end if;
16027 Set_Is_Constructor (Def_Id);
16028 Set_Convention (Def_Id, Convention);
16029 Set_Is_Imported (Def_Id);
16031 exit when From_Aspect_Specification (N);
16032 Hom_Id := Homonym (Hom_Id);
16034 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
16035 end loop;
16036 end Java_Constructor;
16038 ----------------------
16039 -- Java_Interface --
16040 ----------------------
16042 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
16044 when Pragma_Java_Interface => Java_Interface : declare
16045 Arg : Node_Id;
16046 Typ : Entity_Id;
16048 begin
16049 GNAT_Pragma;
16050 Check_Arg_Count (1);
16051 Check_Optional_Identifier (Arg1, Name_Entity);
16052 Check_Arg_Is_Local_Name (Arg1);
16054 Arg := Get_Pragma_Arg (Arg1);
16055 Analyze (Arg);
16057 if Etype (Arg) = Any_Type then
16058 return;
16059 end if;
16061 if not Is_Entity_Name (Arg)
16062 or else not Is_Type (Entity (Arg))
16063 then
16064 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
16065 end if;
16067 Typ := Underlying_Type (Entity (Arg));
16069 -- For now simply check some of the semantic constraints on the
16070 -- type. This currently leaves out some restrictions on interface
16071 -- types, namely that the parent type must be java.lang.Object.Typ
16072 -- and that all primitives of the type should be declared
16073 -- abstract. ???
16075 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
16076 Error_Pragma_Arg
16077 ("pragma% requires an abstract tagged type", Arg1);
16079 elsif not Has_Discriminants (Typ)
16080 or else Ekind (Etype (First_Discriminant (Typ)))
16081 /= E_Anonymous_Access_Type
16082 or else
16083 not Is_Class_Wide_Type
16084 (Designated_Type (Etype (First_Discriminant (Typ))))
16085 then
16086 Error_Pragma_Arg
16087 ("type must have a class-wide access discriminant", Arg1);
16088 end if;
16089 end Java_Interface;
16091 ----------------
16092 -- Keep_Names --
16093 ----------------
16095 -- pragma Keep_Names ([On => ] LOCAL_NAME);
16097 when Pragma_Keep_Names => Keep_Names : declare
16098 Arg : Node_Id;
16100 begin
16101 GNAT_Pragma;
16102 Check_Arg_Count (1);
16103 Check_Optional_Identifier (Arg1, Name_On);
16104 Check_Arg_Is_Local_Name (Arg1);
16106 Arg := Get_Pragma_Arg (Arg1);
16107 Analyze (Arg);
16109 if Etype (Arg) = Any_Type then
16110 return;
16111 end if;
16113 if not Is_Entity_Name (Arg)
16114 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
16115 then
16116 Error_Pragma_Arg
16117 ("pragma% requires a local enumeration type", Arg1);
16118 end if;
16120 Set_Discard_Names (Entity (Arg), False);
16121 end Keep_Names;
16123 -------------
16124 -- License --
16125 -------------
16127 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
16129 when Pragma_License =>
16130 GNAT_Pragma;
16132 -- Do not analyze pragma any further in CodePeer mode, to avoid
16133 -- extraneous errors in this implementation-dependent pragma,
16134 -- which has a different profile on other compilers.
16136 if CodePeer_Mode then
16137 return;
16138 end if;
16140 Check_Arg_Count (1);
16141 Check_No_Identifiers;
16142 Check_Valid_Configuration_Pragma;
16143 Check_Arg_Is_Identifier (Arg1);
16145 declare
16146 Sind : constant Source_File_Index :=
16147 Source_Index (Current_Sem_Unit);
16149 begin
16150 case Chars (Get_Pragma_Arg (Arg1)) is
16151 when Name_GPL =>
16152 Set_License (Sind, GPL);
16154 when Name_Modified_GPL =>
16155 Set_License (Sind, Modified_GPL);
16157 when Name_Restricted =>
16158 Set_License (Sind, Restricted);
16160 when Name_Unrestricted =>
16161 Set_License (Sind, Unrestricted);
16163 when others =>
16164 Error_Pragma_Arg ("invalid license name", Arg1);
16165 end case;
16166 end;
16168 ---------------
16169 -- Link_With --
16170 ---------------
16172 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
16174 when Pragma_Link_With => Link_With : declare
16175 Arg : Node_Id;
16177 begin
16178 GNAT_Pragma;
16180 if Operating_Mode = Generate_Code
16181 and then In_Extended_Main_Source_Unit (N)
16182 then
16183 Check_At_Least_N_Arguments (1);
16184 Check_No_Identifiers;
16185 Check_Is_In_Decl_Part_Or_Package_Spec;
16186 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
16187 Start_String;
16189 Arg := Arg1;
16190 while Present (Arg) loop
16191 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
16193 -- Store argument, converting sequences of spaces to a
16194 -- single null character (this is one of the differences
16195 -- in processing between Link_With and Linker_Options).
16197 Arg_Store : declare
16198 C : constant Char_Code := Get_Char_Code (' ');
16199 S : constant String_Id :=
16200 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
16201 L : constant Nat := String_Length (S);
16202 F : Nat := 1;
16204 procedure Skip_Spaces;
16205 -- Advance F past any spaces
16207 -----------------
16208 -- Skip_Spaces --
16209 -----------------
16211 procedure Skip_Spaces is
16212 begin
16213 while F <= L and then Get_String_Char (S, F) = C loop
16214 F := F + 1;
16215 end loop;
16216 end Skip_Spaces;
16218 -- Start of processing for Arg_Store
16220 begin
16221 Skip_Spaces; -- skip leading spaces
16223 -- Loop through characters, changing any embedded
16224 -- sequence of spaces to a single null character (this
16225 -- is how Link_With/Linker_Options differ)
16227 while F <= L loop
16228 if Get_String_Char (S, F) = C then
16229 Skip_Spaces;
16230 exit when F > L;
16231 Store_String_Char (ASCII.NUL);
16233 else
16234 Store_String_Char (Get_String_Char (S, F));
16235 F := F + 1;
16236 end if;
16237 end loop;
16238 end Arg_Store;
16240 Arg := Next (Arg);
16242 if Present (Arg) then
16243 Store_String_Char (ASCII.NUL);
16244 end if;
16245 end loop;
16247 Store_Linker_Option_String (End_String);
16248 end if;
16249 end Link_With;
16251 ------------------
16252 -- Linker_Alias --
16253 ------------------
16255 -- pragma Linker_Alias (
16256 -- [Entity =>] LOCAL_NAME
16257 -- [Target =>] static_string_EXPRESSION);
16259 when Pragma_Linker_Alias =>
16260 GNAT_Pragma;
16261 Check_Arg_Order ((Name_Entity, Name_Target));
16262 Check_Arg_Count (2);
16263 Check_Optional_Identifier (Arg1, Name_Entity);
16264 Check_Optional_Identifier (Arg2, Name_Target);
16265 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16266 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16268 -- The only processing required is to link this item on to the
16269 -- list of rep items for the given entity. This is accomplished
16270 -- by the call to Rep_Item_Too_Late (when no error is detected
16271 -- and False is returned).
16273 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
16274 return;
16275 else
16276 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
16277 end if;
16279 ------------------------
16280 -- Linker_Constructor --
16281 ------------------------
16283 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
16285 -- Code is shared with Linker_Destructor
16287 -----------------------
16288 -- Linker_Destructor --
16289 -----------------------
16291 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
16293 when Pragma_Linker_Constructor |
16294 Pragma_Linker_Destructor =>
16295 Linker_Constructor : declare
16296 Arg1_X : Node_Id;
16297 Proc : Entity_Id;
16299 begin
16300 GNAT_Pragma;
16301 Check_Arg_Count (1);
16302 Check_No_Identifiers;
16303 Check_Arg_Is_Local_Name (Arg1);
16304 Arg1_X := Get_Pragma_Arg (Arg1);
16305 Analyze (Arg1_X);
16306 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
16308 if not Is_Library_Level_Entity (Proc) then
16309 Error_Pragma_Arg
16310 ("argument for pragma% must be library level entity", Arg1);
16311 end if;
16313 -- The only processing required is to link this item on to the
16314 -- list of rep items for the given entity. This is accomplished
16315 -- by the call to Rep_Item_Too_Late (when no error is detected
16316 -- and False is returned).
16318 if Rep_Item_Too_Late (Proc, N) then
16319 return;
16320 else
16321 Set_Has_Gigi_Rep_Item (Proc);
16322 end if;
16323 end Linker_Constructor;
16325 --------------------
16326 -- Linker_Options --
16327 --------------------
16329 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
16331 when Pragma_Linker_Options => Linker_Options : declare
16332 Arg : Node_Id;
16334 begin
16335 Check_Ada_83_Warning;
16336 Check_No_Identifiers;
16337 Check_Arg_Count (1);
16338 Check_Is_In_Decl_Part_Or_Package_Spec;
16339 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
16340 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
16342 Arg := Arg2;
16343 while Present (Arg) loop
16344 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
16345 Store_String_Char (ASCII.NUL);
16346 Store_String_Chars
16347 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
16348 Arg := Next (Arg);
16349 end loop;
16351 if Operating_Mode = Generate_Code
16352 and then In_Extended_Main_Source_Unit (N)
16353 then
16354 Store_Linker_Option_String (End_String);
16355 end if;
16356 end Linker_Options;
16358 --------------------
16359 -- Linker_Section --
16360 --------------------
16362 -- pragma Linker_Section (
16363 -- [Entity =>] LOCAL_NAME
16364 -- [Section =>] static_string_EXPRESSION);
16366 when Pragma_Linker_Section => Linker_Section : declare
16367 Arg : Node_Id;
16368 Ent : Entity_Id;
16370 begin
16371 GNAT_Pragma;
16372 Check_Arg_Order ((Name_Entity, Name_Section));
16373 Check_Arg_Count (2);
16374 Check_Optional_Identifier (Arg1, Name_Entity);
16375 Check_Optional_Identifier (Arg2, Name_Section);
16376 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16377 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16379 -- Check kind of entity
16381 Arg := Get_Pragma_Arg (Arg1);
16382 Ent := Entity (Arg);
16384 case Ekind (Ent) is
16386 -- Objects (constants and variables) and types. For these cases
16387 -- all we need to do is to set the Linker_Section_pragma field.
16389 when E_Constant | E_Variable | Type_Kind =>
16390 Set_Linker_Section_Pragma (Ent, N);
16392 -- Subprograms
16394 when Subprogram_Kind =>
16396 -- Aspect case, entity already set
16398 if From_Aspect_Specification (N) then
16399 Set_Linker_Section_Pragma
16400 (Entity (Corresponding_Aspect (N)), N);
16402 -- Pragma case, we must climb the homonym chain, but skip
16403 -- any for which the linker section is already set.
16405 else
16406 loop
16407 if No (Linker_Section_Pragma (Ent)) then
16408 Set_Linker_Section_Pragma (Ent, N);
16409 end if;
16411 Ent := Homonym (Ent);
16412 exit when No (Ent)
16413 or else Scope (Ent) /= Current_Scope;
16414 end loop;
16415 end if;
16417 -- All other cases are illegal
16419 when others =>
16420 Error_Pragma_Arg
16421 ("pragma% applies only to objects, subprograms, and types",
16422 Arg1);
16423 end case;
16424 end Linker_Section;
16426 ----------
16427 -- List --
16428 ----------
16430 -- pragma List (On | Off)
16432 -- There is nothing to do here, since we did all the processing for
16433 -- this pragma in Par.Prag (so that it works properly even in syntax
16434 -- only mode).
16436 when Pragma_List =>
16437 null;
16439 ---------------
16440 -- Lock_Free --
16441 ---------------
16443 -- pragma Lock_Free [(Boolean_EXPRESSION)];
16445 when Pragma_Lock_Free => Lock_Free : declare
16446 P : constant Node_Id := Parent (N);
16447 Arg : Node_Id;
16448 Ent : Entity_Id;
16449 Val : Boolean;
16451 begin
16452 Check_No_Identifiers;
16453 Check_At_Most_N_Arguments (1);
16455 -- Protected definition case
16457 if Nkind (P) = N_Protected_Definition then
16458 Ent := Defining_Identifier (Parent (P));
16460 -- One argument
16462 if Arg_Count = 1 then
16463 Arg := Get_Pragma_Arg (Arg1);
16464 Val := Is_True (Static_Boolean (Arg));
16466 -- No arguments (expression is considered to be True)
16468 else
16469 Val := True;
16470 end if;
16472 -- Check duplicate pragma before we chain the pragma in the Rep
16473 -- Item chain of Ent.
16475 Check_Duplicate_Pragma (Ent);
16476 Record_Rep_Item (Ent, N);
16477 Set_Uses_Lock_Free (Ent, Val);
16479 -- Anything else is incorrect placement
16481 else
16482 Pragma_Misplaced;
16483 end if;
16484 end Lock_Free;
16486 --------------------
16487 -- Locking_Policy --
16488 --------------------
16490 -- pragma Locking_Policy (policy_IDENTIFIER);
16492 when Pragma_Locking_Policy => declare
16493 subtype LP_Range is Name_Id
16494 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
16495 LP_Val : LP_Range;
16496 LP : Character;
16498 begin
16499 Check_Ada_83_Warning;
16500 Check_Arg_Count (1);
16501 Check_No_Identifiers;
16502 Check_Arg_Is_Locking_Policy (Arg1);
16503 Check_Valid_Configuration_Pragma;
16504 LP_Val := Chars (Get_Pragma_Arg (Arg1));
16506 case LP_Val is
16507 when Name_Ceiling_Locking =>
16508 LP := 'C';
16509 when Name_Inheritance_Locking =>
16510 LP := 'I';
16511 when Name_Concurrent_Readers_Locking =>
16512 LP := 'R';
16513 end case;
16515 if Locking_Policy /= ' '
16516 and then Locking_Policy /= LP
16517 then
16518 Error_Msg_Sloc := Locking_Policy_Sloc;
16519 Error_Pragma ("locking policy incompatible with policy#");
16521 -- Set new policy, but always preserve System_Location since we
16522 -- like the error message with the run time name.
16524 else
16525 Locking_Policy := LP;
16527 if Locking_Policy_Sloc /= System_Location then
16528 Locking_Policy_Sloc := Loc;
16529 end if;
16530 end if;
16531 end;
16533 -------------------
16534 -- Loop_Optimize --
16535 -------------------
16537 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
16539 -- OPTIMIZATION_HINT ::=
16540 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
16542 when Pragma_Loop_Optimize => Loop_Optimize : declare
16543 Hint : Node_Id;
16545 begin
16546 GNAT_Pragma;
16547 Check_At_Least_N_Arguments (1);
16548 Check_No_Identifiers;
16550 Hint := First (Pragma_Argument_Associations (N));
16551 while Present (Hint) loop
16552 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
16553 Name_No_Unroll,
16554 Name_Unroll,
16555 Name_No_Vector,
16556 Name_Vector);
16557 Next (Hint);
16558 end loop;
16560 Check_Loop_Pragma_Placement;
16561 end Loop_Optimize;
16563 ------------------
16564 -- Loop_Variant --
16565 ------------------
16567 -- pragma Loop_Variant
16568 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
16570 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
16572 -- CHANGE_DIRECTION ::= Increases | Decreases
16574 when Pragma_Loop_Variant => Loop_Variant : declare
16575 Variant : Node_Id;
16577 begin
16578 GNAT_Pragma;
16579 Check_At_Least_N_Arguments (1);
16580 Check_Loop_Pragma_Placement;
16582 -- Process all increasing / decreasing expressions
16584 Variant := First (Pragma_Argument_Associations (N));
16585 while Present (Variant) loop
16586 if not Nam_In (Chars (Variant), Name_Decreases,
16587 Name_Increases)
16588 then
16589 Error_Pragma_Arg ("wrong change modifier", Variant);
16590 end if;
16592 Preanalyze_Assert_Expression
16593 (Expression (Variant), Any_Discrete);
16595 Next (Variant);
16596 end loop;
16597 end Loop_Variant;
16599 -----------------------
16600 -- Machine_Attribute --
16601 -----------------------
16603 -- pragma Machine_Attribute (
16604 -- [Entity =>] LOCAL_NAME,
16605 -- [Attribute_Name =>] static_string_EXPRESSION
16606 -- [, [Info =>] static_EXPRESSION] );
16608 when Pragma_Machine_Attribute => Machine_Attribute : declare
16609 Def_Id : Entity_Id;
16611 begin
16612 GNAT_Pragma;
16613 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
16615 if Arg_Count = 3 then
16616 Check_Optional_Identifier (Arg3, Name_Info);
16617 Check_Arg_Is_OK_Static_Expression (Arg3);
16618 else
16619 Check_Arg_Count (2);
16620 end if;
16622 Check_Optional_Identifier (Arg1, Name_Entity);
16623 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
16624 Check_Arg_Is_Local_Name (Arg1);
16625 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16626 Def_Id := Entity (Get_Pragma_Arg (Arg1));
16628 if Is_Access_Type (Def_Id) then
16629 Def_Id := Designated_Type (Def_Id);
16630 end if;
16632 if Rep_Item_Too_Early (Def_Id, N) then
16633 return;
16634 end if;
16636 Def_Id := Underlying_Type (Def_Id);
16638 -- The only processing required is to link this item on to the
16639 -- list of rep items for the given entity. This is accomplished
16640 -- by the call to Rep_Item_Too_Late (when no error is detected
16641 -- and False is returned).
16643 if Rep_Item_Too_Late (Def_Id, N) then
16644 return;
16645 else
16646 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
16647 end if;
16648 end Machine_Attribute;
16650 ----------
16651 -- Main --
16652 ----------
16654 -- pragma Main
16655 -- (MAIN_OPTION [, MAIN_OPTION]);
16657 -- MAIN_OPTION ::=
16658 -- [STACK_SIZE =>] static_integer_EXPRESSION
16659 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
16660 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
16662 when Pragma_Main => Main : declare
16663 Args : Args_List (1 .. 3);
16664 Names : constant Name_List (1 .. 3) := (
16665 Name_Stack_Size,
16666 Name_Task_Stack_Size_Default,
16667 Name_Time_Slicing_Enabled);
16669 Nod : Node_Id;
16671 begin
16672 GNAT_Pragma;
16673 Gather_Associations (Names, Args);
16675 for J in 1 .. 2 loop
16676 if Present (Args (J)) then
16677 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
16678 end if;
16679 end loop;
16681 if Present (Args (3)) then
16682 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
16683 end if;
16685 Nod := Next (N);
16686 while Present (Nod) loop
16687 if Nkind (Nod) = N_Pragma
16688 and then Pragma_Name (Nod) = Name_Main
16689 then
16690 Error_Msg_Name_1 := Pname;
16691 Error_Msg_N ("duplicate pragma% not permitted", Nod);
16692 end if;
16694 Next (Nod);
16695 end loop;
16696 end Main;
16698 ------------------
16699 -- Main_Storage --
16700 ------------------
16702 -- pragma Main_Storage
16703 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
16705 -- MAIN_STORAGE_OPTION ::=
16706 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
16707 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
16709 when Pragma_Main_Storage => Main_Storage : declare
16710 Args : Args_List (1 .. 2);
16711 Names : constant Name_List (1 .. 2) := (
16712 Name_Working_Storage,
16713 Name_Top_Guard);
16715 Nod : Node_Id;
16717 begin
16718 GNAT_Pragma;
16719 Gather_Associations (Names, Args);
16721 for J in 1 .. 2 loop
16722 if Present (Args (J)) then
16723 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
16724 end if;
16725 end loop;
16727 Check_In_Main_Program;
16729 Nod := Next (N);
16730 while Present (Nod) loop
16731 if Nkind (Nod) = N_Pragma
16732 and then Pragma_Name (Nod) = Name_Main_Storage
16733 then
16734 Error_Msg_Name_1 := Pname;
16735 Error_Msg_N ("duplicate pragma% not permitted", Nod);
16736 end if;
16738 Next (Nod);
16739 end loop;
16740 end Main_Storage;
16742 -----------------
16743 -- Memory_Size --
16744 -----------------
16746 -- pragma Memory_Size (NUMERIC_LITERAL)
16748 when Pragma_Memory_Size =>
16749 GNAT_Pragma;
16751 -- Memory size is simply ignored
16753 Check_No_Identifiers;
16754 Check_Arg_Count (1);
16755 Check_Arg_Is_Integer_Literal (Arg1);
16757 -------------
16758 -- No_Body --
16759 -------------
16761 -- pragma No_Body;
16763 -- The only correct use of this pragma is on its own in a file, in
16764 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
16765 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
16766 -- check for a file containing nothing but a No_Body pragma). If we
16767 -- attempt to process it during normal semantics processing, it means
16768 -- it was misplaced.
16770 when Pragma_No_Body =>
16771 GNAT_Pragma;
16772 Pragma_Misplaced;
16774 -----------------------------
16775 -- No_Elaboration_Code_All --
16776 -----------------------------
16778 -- pragma No_Elaboration_Code_All;
16780 when Pragma_No_Elaboration_Code_All => NECA : declare
16781 begin
16782 GNAT_Pragma;
16783 Check_Valid_Library_Unit_Pragma;
16785 if Nkind (N) = N_Null_Statement then
16786 return;
16787 end if;
16789 -- Must appear for a spec
16791 if not Nkind_In (Unit (Cunit (Current_Sem_Unit)),
16792 N_Package_Declaration,
16793 N_Subprogram_Declaration)
16794 then
16795 Error_Pragma
16796 (Fix_Error
16797 ("pragma% can only occur for package "
16798 & "or subprogram spec"));
16799 end if;
16801 -- Set flag in unit table
16803 Set_No_Elab_Code_All (Current_Sem_Unit);
16805 -- Set restriction No_Elaboration_Code
16807 Set_Restriction (No_Elaboration_Code, N);
16809 -- If we are in the main unit or in an extended main source unit,
16810 -- then we also add it to the configuration restrictions so that
16811 -- it will apply to all units in the extended main source.
16813 if Current_Sem_Unit = Main_Unit
16814 or else In_Extended_Main_Source_Unit (N)
16815 then
16816 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
16817 end if;
16819 -- If in main extended unit, activate transitive with test
16821 if In_Extended_Main_Source_Unit (N) then
16822 Opt.No_Elab_Code_All_Pragma := N;
16823 end if;
16824 end NECA;
16826 ---------------
16827 -- No_Inline --
16828 ---------------
16830 -- pragma No_Inline ( NAME {, NAME} );
16832 when Pragma_No_Inline =>
16833 GNAT_Pragma;
16834 Process_Inline (Suppressed);
16836 ---------------
16837 -- No_Return --
16838 ---------------
16840 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
16842 when Pragma_No_Return => No_Return : declare
16843 Id : Node_Id;
16844 E : Entity_Id;
16845 Found : Boolean;
16846 Arg : Node_Id;
16848 begin
16849 Ada_2005_Pragma;
16850 Check_At_Least_N_Arguments (1);
16852 -- Loop through arguments of pragma
16854 Arg := Arg1;
16855 while Present (Arg) loop
16856 Check_Arg_Is_Local_Name (Arg);
16857 Id := Get_Pragma_Arg (Arg);
16858 Analyze (Id);
16860 if not Is_Entity_Name (Id) then
16861 Error_Pragma_Arg ("entity name required", Arg);
16862 end if;
16864 if Etype (Id) = Any_Type then
16865 raise Pragma_Exit;
16866 end if;
16868 -- Loop to find matching procedures
16870 E := Entity (Id);
16871 Found := False;
16872 while Present (E)
16873 and then Scope (E) = Current_Scope
16874 loop
16875 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
16876 Set_No_Return (E);
16878 -- Set flag on any alias as well
16880 if Is_Overloadable (E) and then Present (Alias (E)) then
16881 Set_No_Return (Alias (E));
16882 end if;
16884 Found := True;
16885 end if;
16887 exit when From_Aspect_Specification (N);
16888 E := Homonym (E);
16889 end loop;
16891 -- If entity in not in current scope it may be the enclosing
16892 -- suprogram body to which the aspect applies.
16894 if not Found then
16895 if Entity (Id) = Current_Scope
16896 and then From_Aspect_Specification (N)
16897 then
16898 Set_No_Return (Entity (Id));
16899 else
16900 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
16901 end if;
16902 end if;
16904 Next (Arg);
16905 end loop;
16906 end No_Return;
16908 -----------------
16909 -- No_Run_Time --
16910 -----------------
16912 -- pragma No_Run_Time;
16914 -- Note: this pragma is retained for backwards compatibility. See
16915 -- body of Rtsfind for full details on its handling.
16917 when Pragma_No_Run_Time =>
16918 GNAT_Pragma;
16919 Check_Valid_Configuration_Pragma;
16920 Check_Arg_Count (0);
16922 No_Run_Time_Mode := True;
16923 Configurable_Run_Time_Mode := True;
16925 -- Set Duration to 32 bits if word size is 32
16927 if Ttypes.System_Word_Size = 32 then
16928 Duration_32_Bits_On_Target := True;
16929 end if;
16931 -- Set appropriate restrictions
16933 Set_Restriction (No_Finalization, N);
16934 Set_Restriction (No_Exception_Handlers, N);
16935 Set_Restriction (Max_Tasks, N, 0);
16936 Set_Restriction (No_Tasking, N);
16938 -----------------------
16939 -- No_Tagged_Streams --
16940 -----------------------
16942 -- pragma No_Tagged_Streams;
16943 -- pragma No_Tagged_Streams ([Entity => ]tagged_type_local_NAME);
16945 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
16946 E_Id : Node_Id;
16947 E : Entity_Id;
16949 begin
16950 GNAT_Pragma;
16951 Check_At_Most_N_Arguments (1);
16953 -- One argument case
16955 if Arg_Count = 1 then
16956 Check_Optional_Identifier (Arg1, Name_Entity);
16957 Check_Arg_Is_Local_Name (Arg1);
16958 E_Id := Get_Pragma_Arg (Arg1);
16960 if Etype (E_Id) = Any_Type then
16961 return;
16962 end if;
16964 E := Entity (E_Id);
16966 Check_Duplicate_Pragma (E);
16968 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
16969 Error_Pragma_Arg
16970 ("argument for pragma% must be root tagged type", Arg1);
16971 end if;
16973 if Rep_Item_Too_Early (E, N)
16974 or else
16975 Rep_Item_Too_Late (E, N)
16976 then
16977 return;
16978 else
16979 Set_No_Tagged_Streams_Pragma (E, N);
16980 end if;
16982 -- Zero argument case
16984 else
16985 Check_Is_In_Decl_Part_Or_Package_Spec;
16986 No_Tagged_Streams := N;
16987 end if;
16988 end No_Tagged_Strms;
16990 ------------------------
16991 -- No_Strict_Aliasing --
16992 ------------------------
16994 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
16996 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
16997 E_Id : Entity_Id;
16999 begin
17000 GNAT_Pragma;
17001 Check_At_Most_N_Arguments (1);
17003 if Arg_Count = 0 then
17004 Check_Valid_Configuration_Pragma;
17005 Opt.No_Strict_Aliasing := True;
17007 else
17008 Check_Optional_Identifier (Arg2, Name_Entity);
17009 Check_Arg_Is_Local_Name (Arg1);
17010 E_Id := Entity (Get_Pragma_Arg (Arg1));
17012 if E_Id = Any_Type then
17013 return;
17014 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
17015 Error_Pragma_Arg ("pragma% requires access type", Arg1);
17016 end if;
17018 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
17019 end if;
17020 end No_Strict_Aliasing;
17022 -----------------------
17023 -- Normalize_Scalars --
17024 -----------------------
17026 -- pragma Normalize_Scalars;
17028 when Pragma_Normalize_Scalars =>
17029 Check_Ada_83_Warning;
17030 Check_Arg_Count (0);
17031 Check_Valid_Configuration_Pragma;
17033 -- Normalize_Scalars creates false positives in CodePeer, and
17034 -- incorrect negative results in GNATprove mode, so ignore this
17035 -- pragma in these modes.
17037 if not (CodePeer_Mode or GNATprove_Mode) then
17038 Normalize_Scalars := True;
17039 Init_Or_Norm_Scalars := True;
17040 end if;
17042 -----------------
17043 -- Obsolescent --
17044 -----------------
17046 -- pragma Obsolescent;
17048 -- pragma Obsolescent (
17049 -- [Message =>] static_string_EXPRESSION
17050 -- [,[Version =>] Ada_05]]);
17052 -- pragma Obsolescent (
17053 -- [Entity =>] NAME
17054 -- [,[Message =>] static_string_EXPRESSION
17055 -- [,[Version =>] Ada_05]] );
17057 when Pragma_Obsolescent => Obsolescent : declare
17058 Ename : Node_Id;
17059 Decl : Node_Id;
17061 procedure Set_Obsolescent (E : Entity_Id);
17062 -- Given an entity Ent, mark it as obsolescent if appropriate
17064 ---------------------
17065 -- Set_Obsolescent --
17066 ---------------------
17068 procedure Set_Obsolescent (E : Entity_Id) is
17069 Active : Boolean;
17070 Ent : Entity_Id;
17071 S : String_Id;
17073 begin
17074 Active := True;
17075 Ent := E;
17077 -- Entity name was given
17079 if Present (Ename) then
17081 -- If entity name matches, we are fine. Save entity in
17082 -- pragma argument, for ASIS use.
17084 if Chars (Ename) = Chars (Ent) then
17085 Set_Entity (Ename, Ent);
17086 Generate_Reference (Ent, Ename);
17088 -- If entity name does not match, only possibility is an
17089 -- enumeration literal from an enumeration type declaration.
17091 elsif Ekind (Ent) /= E_Enumeration_Type then
17092 Error_Pragma
17093 ("pragma % entity name does not match declaration");
17095 else
17096 Ent := First_Literal (E);
17097 loop
17098 if No (Ent) then
17099 Error_Pragma
17100 ("pragma % entity name does not match any "
17101 & "enumeration literal");
17103 elsif Chars (Ent) = Chars (Ename) then
17104 Set_Entity (Ename, Ent);
17105 Generate_Reference (Ent, Ename);
17106 exit;
17108 else
17109 Ent := Next_Literal (Ent);
17110 end if;
17111 end loop;
17112 end if;
17113 end if;
17115 -- Ent points to entity to be marked
17117 if Arg_Count >= 1 then
17119 -- Deal with static string argument
17121 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17122 S := Strval (Get_Pragma_Arg (Arg1));
17124 for J in 1 .. String_Length (S) loop
17125 if not In_Character_Range (Get_String_Char (S, J)) then
17126 Error_Pragma_Arg
17127 ("pragma% argument does not allow wide characters",
17128 Arg1);
17129 end if;
17130 end loop;
17132 Obsolescent_Warnings.Append
17133 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
17135 -- Check for Ada_05 parameter
17137 if Arg_Count /= 1 then
17138 Check_Arg_Count (2);
17140 declare
17141 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
17143 begin
17144 Check_Arg_Is_Identifier (Argx);
17146 if Chars (Argx) /= Name_Ada_05 then
17147 Error_Msg_Name_2 := Name_Ada_05;
17148 Error_Pragma_Arg
17149 ("only allowed argument for pragma% is %", Argx);
17150 end if;
17152 if Ada_Version_Explicit < Ada_2005
17153 or else not Warn_On_Ada_2005_Compatibility
17154 then
17155 Active := False;
17156 end if;
17157 end;
17158 end if;
17159 end if;
17161 -- Set flag if pragma active
17163 if Active then
17164 Set_Is_Obsolescent (Ent);
17165 end if;
17167 return;
17168 end Set_Obsolescent;
17170 -- Start of processing for pragma Obsolescent
17172 begin
17173 GNAT_Pragma;
17175 Check_At_Most_N_Arguments (3);
17177 -- See if first argument specifies an entity name
17179 if Arg_Count >= 1
17180 and then
17181 (Chars (Arg1) = Name_Entity
17182 or else
17183 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
17184 N_Identifier,
17185 N_Operator_Symbol))
17186 then
17187 Ename := Get_Pragma_Arg (Arg1);
17189 -- Eliminate first argument, so we can share processing
17191 Arg1 := Arg2;
17192 Arg2 := Arg3;
17193 Arg_Count := Arg_Count - 1;
17195 -- No Entity name argument given
17197 else
17198 Ename := Empty;
17199 end if;
17201 if Arg_Count >= 1 then
17202 Check_Optional_Identifier (Arg1, Name_Message);
17204 if Arg_Count = 2 then
17205 Check_Optional_Identifier (Arg2, Name_Version);
17206 end if;
17207 end if;
17209 -- Get immediately preceding declaration
17211 Decl := Prev (N);
17212 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
17213 Prev (Decl);
17214 end loop;
17216 -- Cases where we do not follow anything other than another pragma
17218 if No (Decl) then
17220 -- First case: library level compilation unit declaration with
17221 -- the pragma immediately following the declaration.
17223 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
17224 Set_Obsolescent
17225 (Defining_Entity (Unit (Parent (Parent (N)))));
17226 return;
17228 -- Case 2: library unit placement for package
17230 else
17231 declare
17232 Ent : constant Entity_Id := Find_Lib_Unit_Name;
17233 begin
17234 if Is_Package_Or_Generic_Package (Ent) then
17235 Set_Obsolescent (Ent);
17236 return;
17237 end if;
17238 end;
17239 end if;
17241 -- Cases where we must follow a declaration
17243 else
17244 if Nkind (Decl) not in N_Declaration
17245 and then Nkind (Decl) not in N_Later_Decl_Item
17246 and then Nkind (Decl) not in N_Generic_Declaration
17247 and then Nkind (Decl) not in N_Renaming_Declaration
17248 then
17249 Error_Pragma
17250 ("pragma% misplaced, "
17251 & "must immediately follow a declaration");
17253 else
17254 Set_Obsolescent (Defining_Entity (Decl));
17255 return;
17256 end if;
17257 end if;
17258 end Obsolescent;
17260 --------------
17261 -- Optimize --
17262 --------------
17264 -- pragma Optimize (Time | Space | Off);
17266 -- The actual check for optimize is done in Gigi. Note that this
17267 -- pragma does not actually change the optimization setting, it
17268 -- simply checks that it is consistent with the pragma.
17270 when Pragma_Optimize =>
17271 Check_No_Identifiers;
17272 Check_Arg_Count (1);
17273 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
17275 ------------------------
17276 -- Optimize_Alignment --
17277 ------------------------
17279 -- pragma Optimize_Alignment (Time | Space | Off);
17281 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
17282 GNAT_Pragma;
17283 Check_No_Identifiers;
17284 Check_Arg_Count (1);
17285 Check_Valid_Configuration_Pragma;
17287 declare
17288 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
17289 begin
17290 case Nam is
17291 when Name_Time =>
17292 Opt.Optimize_Alignment := 'T';
17293 when Name_Space =>
17294 Opt.Optimize_Alignment := 'S';
17295 when Name_Off =>
17296 Opt.Optimize_Alignment := 'O';
17297 when others =>
17298 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
17299 end case;
17300 end;
17302 -- Set indication that mode is set locally. If we are in fact in a
17303 -- configuration pragma file, this setting is harmless since the
17304 -- switch will get reset anyway at the start of each unit.
17306 Optimize_Alignment_Local := True;
17307 end Optimize_Alignment;
17309 -------------
17310 -- Ordered --
17311 -------------
17313 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
17315 when Pragma_Ordered => Ordered : declare
17316 Assoc : constant Node_Id := Arg1;
17317 Type_Id : Node_Id;
17318 Typ : Entity_Id;
17320 begin
17321 GNAT_Pragma;
17322 Check_No_Identifiers;
17323 Check_Arg_Count (1);
17324 Check_Arg_Is_Local_Name (Arg1);
17326 Type_Id := Get_Pragma_Arg (Assoc);
17327 Find_Type (Type_Id);
17328 Typ := Entity (Type_Id);
17330 if Typ = Any_Type then
17331 return;
17332 else
17333 Typ := Underlying_Type (Typ);
17334 end if;
17336 if not Is_Enumeration_Type (Typ) then
17337 Error_Pragma ("pragma% must specify enumeration type");
17338 end if;
17340 Check_First_Subtype (Arg1);
17341 Set_Has_Pragma_Ordered (Base_Type (Typ));
17342 end Ordered;
17344 -------------------
17345 -- Overflow_Mode --
17346 -------------------
17348 -- pragma Overflow_Mode
17349 -- ([General => ] MODE [, [Assertions => ] MODE]);
17351 -- MODE := STRICT | MINIMIZED | ELIMINATED
17353 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
17354 -- since System.Bignums makes this assumption. This is true of nearly
17355 -- all (all?) targets.
17357 when Pragma_Overflow_Mode => Overflow_Mode : declare
17358 function Get_Overflow_Mode
17359 (Name : Name_Id;
17360 Arg : Node_Id) return Overflow_Mode_Type;
17361 -- Function to process one pragma argument, Arg. If an identifier
17362 -- is present, it must be Name. Mode type is returned if a valid
17363 -- argument exists, otherwise an error is signalled.
17365 -----------------------
17366 -- Get_Overflow_Mode --
17367 -----------------------
17369 function Get_Overflow_Mode
17370 (Name : Name_Id;
17371 Arg : Node_Id) return Overflow_Mode_Type
17373 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
17375 begin
17376 Check_Optional_Identifier (Arg, Name);
17377 Check_Arg_Is_Identifier (Argx);
17379 if Chars (Argx) = Name_Strict then
17380 return Strict;
17382 elsif Chars (Argx) = Name_Minimized then
17383 return Minimized;
17385 elsif Chars (Argx) = Name_Eliminated then
17386 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
17387 Error_Pragma_Arg
17388 ("Eliminated not implemented on this target", Argx);
17389 else
17390 return Eliminated;
17391 end if;
17393 else
17394 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
17395 end if;
17396 end Get_Overflow_Mode;
17398 -- Start of processing for Overflow_Mode
17400 begin
17401 GNAT_Pragma;
17402 Check_At_Least_N_Arguments (1);
17403 Check_At_Most_N_Arguments (2);
17405 -- Process first argument
17407 Scope_Suppress.Overflow_Mode_General :=
17408 Get_Overflow_Mode (Name_General, Arg1);
17410 -- Case of only one argument
17412 if Arg_Count = 1 then
17413 Scope_Suppress.Overflow_Mode_Assertions :=
17414 Scope_Suppress.Overflow_Mode_General;
17416 -- Case of two arguments present
17418 else
17419 Scope_Suppress.Overflow_Mode_Assertions :=
17420 Get_Overflow_Mode (Name_Assertions, Arg2);
17421 end if;
17422 end Overflow_Mode;
17424 --------------------------
17425 -- Overriding Renamings --
17426 --------------------------
17428 -- pragma Overriding_Renamings;
17430 when Pragma_Overriding_Renamings =>
17431 GNAT_Pragma;
17432 Check_Arg_Count (0);
17433 Check_Valid_Configuration_Pragma;
17434 Overriding_Renamings := True;
17436 ----------
17437 -- Pack --
17438 ----------
17440 -- pragma Pack (first_subtype_LOCAL_NAME);
17442 when Pragma_Pack => Pack : declare
17443 Assoc : constant Node_Id := Arg1;
17444 Type_Id : Node_Id;
17445 Typ : Entity_Id;
17446 Ctyp : Entity_Id;
17447 Ignore : Boolean := False;
17449 begin
17450 Check_No_Identifiers;
17451 Check_Arg_Count (1);
17452 Check_Arg_Is_Local_Name (Arg1);
17453 Type_Id := Get_Pragma_Arg (Assoc);
17455 if not Is_Entity_Name (Type_Id)
17456 or else not Is_Type (Entity (Type_Id))
17457 then
17458 Error_Pragma_Arg
17459 ("argument for pragma% must be type or subtype", Arg1);
17460 end if;
17462 Find_Type (Type_Id);
17463 Typ := Entity (Type_Id);
17465 if Typ = Any_Type
17466 or else Rep_Item_Too_Early (Typ, N)
17467 then
17468 return;
17469 else
17470 Typ := Underlying_Type (Typ);
17471 end if;
17473 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
17474 Error_Pragma ("pragma% must specify array or record type");
17475 end if;
17477 Check_First_Subtype (Arg1);
17478 Check_Duplicate_Pragma (Typ);
17480 -- Array type
17482 if Is_Array_Type (Typ) then
17483 Ctyp := Component_Type (Typ);
17485 -- Ignore pack that does nothing
17487 if Known_Static_Esize (Ctyp)
17488 and then Known_Static_RM_Size (Ctyp)
17489 and then Esize (Ctyp) = RM_Size (Ctyp)
17490 and then Addressable (Esize (Ctyp))
17491 then
17492 Ignore := True;
17493 end if;
17495 -- Process OK pragma Pack. Note that if there is a separate
17496 -- component clause present, the Pack will be cancelled. This
17497 -- processing is in Freeze.
17499 if not Rep_Item_Too_Late (Typ, N) then
17501 -- In CodePeer mode, we do not need complex front-end
17502 -- expansions related to pragma Pack, so disable handling
17503 -- of pragma Pack.
17505 if CodePeer_Mode then
17506 null;
17508 -- Don't attempt any packing for VM targets. We possibly
17509 -- could deal with some cases of array bit-packing, but we
17510 -- don't bother, since this is not a typical kind of
17511 -- representation in the VM context anyway (and would not
17512 -- for example work nicely with the debugger).
17514 elsif VM_Target /= No_VM then
17515 if not GNAT_Mode then
17516 Error_Pragma
17517 ("??pragma% ignored in this configuration");
17518 end if;
17520 -- Normal case where we do the pack action
17522 else
17523 if not Ignore then
17524 Set_Is_Packed (Base_Type (Typ));
17525 Set_Has_Non_Standard_Rep (Base_Type (Typ));
17526 end if;
17528 Set_Has_Pragma_Pack (Base_Type (Typ));
17529 end if;
17530 end if;
17532 -- For record types, the pack is always effective
17534 else pragma Assert (Is_Record_Type (Typ));
17535 if not Rep_Item_Too_Late (Typ, N) then
17537 -- Ignore pack request with warning in VM mode (skip warning
17538 -- if we are compiling GNAT run time library).
17540 if VM_Target /= No_VM then
17541 if not GNAT_Mode then
17542 Error_Pragma
17543 ("??pragma% ignored in this configuration");
17544 end if;
17546 -- Normal case of pack request active
17548 else
17549 Set_Is_Packed (Base_Type (Typ));
17550 Set_Has_Pragma_Pack (Base_Type (Typ));
17551 Set_Has_Non_Standard_Rep (Base_Type (Typ));
17552 end if;
17553 end if;
17554 end if;
17555 end Pack;
17557 ----------
17558 -- Page --
17559 ----------
17561 -- pragma Page;
17563 -- There is nothing to do here, since we did all the processing for
17564 -- this pragma in Par.Prag (so that it works properly even in syntax
17565 -- only mode).
17567 when Pragma_Page =>
17568 null;
17570 -------------
17571 -- Part_Of --
17572 -------------
17574 -- pragma Part_Of (ABSTRACT_STATE);
17576 -- ABSTRACT_STATE ::= NAME
17578 when Pragma_Part_Of => Part_Of : declare
17579 procedure Propagate_Part_Of
17580 (Pack_Id : Entity_Id;
17581 State_Id : Entity_Id;
17582 Instance : Node_Id);
17583 -- Propagate the Part_Of indicator to all abstract states and
17584 -- variables declared in the visible state space of a package
17585 -- denoted by Pack_Id. State_Id is the encapsulating state.
17586 -- Instance is the package instantiation node.
17588 -----------------------
17589 -- Propagate_Part_Of --
17590 -----------------------
17592 procedure Propagate_Part_Of
17593 (Pack_Id : Entity_Id;
17594 State_Id : Entity_Id;
17595 Instance : Node_Id)
17597 Has_Item : Boolean := False;
17598 -- Flag set when the visible state space contains at least one
17599 -- abstract state or variable.
17601 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
17602 -- Propagate the Part_Of indicator to all abstract states and
17603 -- variables declared in the visible state space of a package
17604 -- denoted by Pack_Id.
17606 -----------------------
17607 -- Propagate_Part_Of --
17608 -----------------------
17610 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
17611 Item_Id : Entity_Id;
17613 begin
17614 -- Traverse the entity chain of the package and set relevant
17615 -- attributes of abstract states and variables declared in
17616 -- the visible state space of the package.
17618 Item_Id := First_Entity (Pack_Id);
17619 while Present (Item_Id)
17620 and then not In_Private_Part (Item_Id)
17621 loop
17622 -- Do not consider internally generated items
17624 if not Comes_From_Source (Item_Id) then
17625 null;
17627 -- The Part_Of indicator turns an abstract state or
17628 -- variable into a constituent of the encapsulating
17629 -- state.
17631 elsif Ekind_In (Item_Id, E_Abstract_State,
17632 E_Variable)
17633 then
17634 Has_Item := True;
17636 Append_Elmt (Item_Id, Part_Of_Constituents (State_Id));
17637 Set_Encapsulating_State (Item_Id, State_Id);
17639 -- Recursively handle nested packages and instantiations
17641 elsif Ekind (Item_Id) = E_Package then
17642 Propagate_Part_Of (Item_Id);
17643 end if;
17645 Next_Entity (Item_Id);
17646 end loop;
17647 end Propagate_Part_Of;
17649 -- Start of processing for Propagate_Part_Of
17651 begin
17652 Propagate_Part_Of (Pack_Id);
17654 -- Detect a package instantiation that is subject to a Part_Of
17655 -- indicator, but has no visible state.
17657 if not Has_Item then
17658 SPARK_Msg_NE
17659 ("package instantiation & has Part_Of indicator but "
17660 & "lacks visible state", Instance, Pack_Id);
17661 end if;
17662 end Propagate_Part_Of;
17664 -- Local variables
17666 Item_Id : Entity_Id;
17667 Legal : Boolean;
17668 State : Node_Id;
17669 State_Id : Entity_Id;
17670 Stmt : Node_Id;
17672 -- Start of processing for Part_Of
17674 begin
17675 GNAT_Pragma;
17676 Check_No_Identifiers;
17677 Check_Arg_Count (1);
17679 -- Ensure the proper placement of the pragma. Part_Of must appear
17680 -- on a variable declaration or a package instantiation.
17682 Stmt := Prev (N);
17683 while Present (Stmt) loop
17685 -- Skip prior pragmas, but check for duplicates
17687 if Nkind (Stmt) = N_Pragma then
17688 if Pragma_Name (Stmt) = Pname then
17689 Error_Msg_Name_1 := Pname;
17690 Error_Msg_Sloc := Sloc (Stmt);
17691 Error_Msg_N ("pragma% duplicates pragma declared#", N);
17692 end if;
17694 -- Skip internally generated code
17696 elsif not Comes_From_Source (Stmt) then
17697 null;
17699 -- The pragma applies to an object declaration (possibly a
17700 -- variable) or a package instantiation. Stop the traversal
17701 -- and continue the analysis.
17703 elsif Nkind_In (Stmt, N_Object_Declaration,
17704 N_Package_Instantiation)
17705 then
17706 exit;
17708 -- The pragma does not apply to a legal construct, issue an
17709 -- error and stop the analysis.
17711 else
17712 Pragma_Misplaced;
17713 return;
17714 end if;
17716 Stmt := Prev (Stmt);
17717 end loop;
17719 -- When the context is an object declaration, ensure that we are
17720 -- dealing with a variable.
17722 if Nkind (Stmt) = N_Object_Declaration
17723 and then Ekind (Defining_Entity (Stmt)) /= E_Variable
17724 then
17725 SPARK_Msg_N ("indicator Part_Of must apply to a variable", N);
17726 return;
17727 end if;
17729 -- Extract the entity of the related object declaration or package
17730 -- instantiation. In the case of the instantiation, use the entity
17731 -- of the instance spec.
17733 if Nkind (Stmt) = N_Package_Instantiation then
17734 Stmt := Instance_Spec (Stmt);
17735 end if;
17737 Item_Id := Defining_Entity (Stmt);
17738 State := Get_Pragma_Arg (Arg1);
17740 -- Detect any discrepancies between the placement of the object
17741 -- or package instantiation with respect to state space and the
17742 -- encapsulating state.
17744 Analyze_Part_Of
17745 (Item_Id => Item_Id,
17746 State => State,
17747 Indic => N,
17748 Legal => Legal);
17750 if Legal then
17751 State_Id := Entity (State);
17753 -- Add the pragma to the contract of the item. This aids with
17754 -- the detection of a missing but required Part_Of indicator.
17756 Add_Contract_Item (N, Item_Id);
17758 -- The Part_Of indicator turns a variable into a constituent
17759 -- of the encapsulating state.
17761 if Ekind (Item_Id) = E_Variable then
17762 Append_Elmt (Item_Id, Part_Of_Constituents (State_Id));
17763 Set_Encapsulating_State (Item_Id, State_Id);
17765 -- Propagate the Part_Of indicator to the visible state space
17766 -- of the package instantiation.
17768 else
17769 Propagate_Part_Of
17770 (Pack_Id => Item_Id,
17771 State_Id => State_Id,
17772 Instance => Stmt);
17773 end if;
17774 end if;
17775 end Part_Of;
17777 ----------------------------------
17778 -- Partition_Elaboration_Policy --
17779 ----------------------------------
17781 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
17783 when Pragma_Partition_Elaboration_Policy => declare
17784 subtype PEP_Range is Name_Id
17785 range First_Partition_Elaboration_Policy_Name
17786 .. Last_Partition_Elaboration_Policy_Name;
17787 PEP_Val : PEP_Range;
17788 PEP : Character;
17790 begin
17791 Ada_2005_Pragma;
17792 Check_Arg_Count (1);
17793 Check_No_Identifiers;
17794 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
17795 Check_Valid_Configuration_Pragma;
17796 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
17798 case PEP_Val is
17799 when Name_Concurrent =>
17800 PEP := 'C';
17801 when Name_Sequential =>
17802 PEP := 'S';
17803 end case;
17805 if Partition_Elaboration_Policy /= ' '
17806 and then Partition_Elaboration_Policy /= PEP
17807 then
17808 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
17809 Error_Pragma
17810 ("partition elaboration policy incompatible with policy#");
17812 -- Set new policy, but always preserve System_Location since we
17813 -- like the error message with the run time name.
17815 else
17816 Partition_Elaboration_Policy := PEP;
17818 if Partition_Elaboration_Policy_Sloc /= System_Location then
17819 Partition_Elaboration_Policy_Sloc := Loc;
17820 end if;
17821 end if;
17822 end;
17824 -------------
17825 -- Passive --
17826 -------------
17828 -- pragma Passive [(PASSIVE_FORM)];
17830 -- PASSIVE_FORM ::= Semaphore | No
17832 when Pragma_Passive =>
17833 GNAT_Pragma;
17835 if Nkind (Parent (N)) /= N_Task_Definition then
17836 Error_Pragma ("pragma% must be within task definition");
17837 end if;
17839 if Arg_Count /= 0 then
17840 Check_Arg_Count (1);
17841 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
17842 end if;
17844 ----------------------------------
17845 -- Preelaborable_Initialization --
17846 ----------------------------------
17848 -- pragma Preelaborable_Initialization (DIRECT_NAME);
17850 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
17851 Ent : Entity_Id;
17853 begin
17854 Ada_2005_Pragma;
17855 Check_Arg_Count (1);
17856 Check_No_Identifiers;
17857 Check_Arg_Is_Identifier (Arg1);
17858 Check_Arg_Is_Local_Name (Arg1);
17859 Check_First_Subtype (Arg1);
17860 Ent := Entity (Get_Pragma_Arg (Arg1));
17862 -- The pragma may come from an aspect on a private declaration,
17863 -- even if the freeze point at which this is analyzed in the
17864 -- private part after the full view.
17866 if Has_Private_Declaration (Ent)
17867 and then From_Aspect_Specification (N)
17868 then
17869 null;
17871 elsif Is_Private_Type (Ent)
17872 or else Is_Protected_Type (Ent)
17873 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
17874 then
17875 null;
17877 else
17878 Error_Pragma_Arg
17879 ("pragma % can only be applied to private, formal derived or "
17880 & "protected type",
17881 Arg1);
17882 end if;
17884 -- Give an error if the pragma is applied to a protected type that
17885 -- does not qualify (due to having entries, or due to components
17886 -- that do not qualify).
17888 if Is_Protected_Type (Ent)
17889 and then not Has_Preelaborable_Initialization (Ent)
17890 then
17891 Error_Msg_N
17892 ("protected type & does not have preelaborable "
17893 & "initialization", Ent);
17895 -- Otherwise mark the type as definitely having preelaborable
17896 -- initialization.
17898 else
17899 Set_Known_To_Have_Preelab_Init (Ent);
17900 end if;
17902 if Has_Pragma_Preelab_Init (Ent)
17903 and then Warn_On_Redundant_Constructs
17904 then
17905 Error_Pragma ("?r?duplicate pragma%!");
17906 else
17907 Set_Has_Pragma_Preelab_Init (Ent);
17908 end if;
17909 end Preelab_Init;
17911 --------------------
17912 -- Persistent_BSS --
17913 --------------------
17915 -- pragma Persistent_BSS [(object_NAME)];
17917 when Pragma_Persistent_BSS => Persistent_BSS : declare
17918 Decl : Node_Id;
17919 Ent : Entity_Id;
17920 Prag : Node_Id;
17922 begin
17923 GNAT_Pragma;
17924 Check_At_Most_N_Arguments (1);
17926 -- Case of application to specific object (one argument)
17928 if Arg_Count = 1 then
17929 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17931 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
17932 or else not
17933 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
17934 E_Constant)
17935 then
17936 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
17937 end if;
17939 Ent := Entity (Get_Pragma_Arg (Arg1));
17940 Decl := Parent (Ent);
17942 -- Check for duplication before inserting in list of
17943 -- representation items.
17945 Check_Duplicate_Pragma (Ent);
17947 if Rep_Item_Too_Late (Ent, N) then
17948 return;
17949 end if;
17951 if Present (Expression (Decl)) then
17952 Error_Pragma_Arg
17953 ("object for pragma% cannot have initialization", Arg1);
17954 end if;
17956 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
17957 Error_Pragma_Arg
17958 ("object type for pragma% is not potentially persistent",
17959 Arg1);
17960 end if;
17962 Prag :=
17963 Make_Linker_Section_Pragma
17964 (Ent, Sloc (N), ".persistent.bss");
17965 Insert_After (N, Prag);
17966 Analyze (Prag);
17968 -- Case of use as configuration pragma with no arguments
17970 else
17971 Check_Valid_Configuration_Pragma;
17972 Persistent_BSS_Mode := True;
17973 end if;
17974 end Persistent_BSS;
17976 -------------
17977 -- Polling --
17978 -------------
17980 -- pragma Polling (ON | OFF);
17982 when Pragma_Polling =>
17983 GNAT_Pragma;
17984 Check_Arg_Count (1);
17985 Check_No_Identifiers;
17986 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
17987 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
17989 ------------------
17990 -- Post[_Class] --
17991 ------------------
17993 -- pragma Post (Boolean_EXPRESSION);
17994 -- pragma Post_Class (Boolean_EXPRESSION);
17996 when Pragma_Post | Pragma_Post_Class => Post : declare
17997 PC_Pragma : Node_Id;
17999 begin
18000 GNAT_Pragma;
18001 Check_Arg_Count (1);
18002 Check_No_Identifiers;
18003 Check_Pre_Post;
18005 -- Rewrite Post[_Class] pragma as Postcondition pragma setting the
18006 -- flag Class_Present to True for the Post_Class case.
18008 Set_Class_Present (N, Prag_Id = Pragma_Post_Class);
18009 PC_Pragma := New_Copy (N);
18010 Set_Pragma_Identifier
18011 (PC_Pragma, Make_Identifier (Loc, Name_Postcondition));
18012 Rewrite (N, PC_Pragma);
18013 Set_Analyzed (N, False);
18014 Analyze (N);
18015 end Post;
18017 -------------------
18018 -- Postcondition --
18019 -------------------
18021 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
18022 -- [,[Message =>] String_EXPRESSION]);
18024 when Pragma_Postcondition => Postcondition : declare
18025 In_Body : Boolean;
18027 begin
18028 GNAT_Pragma;
18029 Check_At_Least_N_Arguments (1);
18030 Check_At_Most_N_Arguments (2);
18031 Check_Optional_Identifier (Arg1, Name_Check);
18033 -- Verify the proper placement of the pragma. The remainder of the
18034 -- processing is found in Sem_Ch6/Sem_Ch7.
18036 Check_Precondition_Postcondition (In_Body);
18038 -- When the pragma is a source construct appearing inside a body,
18039 -- preanalyze the boolean_expression to detect illegal forward
18040 -- references:
18042 -- procedure P is
18043 -- pragma Postcondition (X'Old ...);
18044 -- X : ...
18046 if Comes_From_Source (N) and then In_Body then
18047 Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean);
18048 end if;
18049 end Postcondition;
18051 -----------------
18052 -- Pre[_Class] --
18053 -----------------
18055 -- pragma Pre (Boolean_EXPRESSION);
18056 -- pragma Pre_Class (Boolean_EXPRESSION);
18058 when Pragma_Pre | Pragma_Pre_Class => Pre : declare
18059 PC_Pragma : Node_Id;
18061 begin
18062 GNAT_Pragma;
18063 Check_Arg_Count (1);
18064 Check_No_Identifiers;
18065 Check_Pre_Post;
18067 -- Rewrite Pre[_Class] pragma as Precondition pragma setting the
18068 -- flag Class_Present to True for the Pre_Class case.
18070 Set_Class_Present (N, Prag_Id = Pragma_Pre_Class);
18071 PC_Pragma := New_Copy (N);
18072 Set_Pragma_Identifier
18073 (PC_Pragma, Make_Identifier (Loc, Name_Precondition));
18074 Rewrite (N, PC_Pragma);
18075 Set_Analyzed (N, False);
18076 Analyze (N);
18077 end Pre;
18079 ------------------
18080 -- Precondition --
18081 ------------------
18083 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
18084 -- [,[Message =>] String_EXPRESSION]);
18086 when Pragma_Precondition => Precondition : declare
18087 In_Body : Boolean;
18089 begin
18090 GNAT_Pragma;
18091 Check_At_Least_N_Arguments (1);
18092 Check_At_Most_N_Arguments (2);
18093 Check_Optional_Identifier (Arg1, Name_Check);
18094 Check_Precondition_Postcondition (In_Body);
18096 -- If in spec, nothing more to do. If in body, then we convert
18097 -- the pragma to an equivalent pragma Check. That works fine since
18098 -- pragma Check will analyze the condition in the proper context.
18100 -- The form of the pragma Check is either:
18102 -- pragma Check (Precondition, cond [, msg])
18103 -- or
18104 -- pragma Check (Pre, cond [, msg])
18106 -- We use the Pre form if this pragma derived from a Pre aspect.
18107 -- This is needed to make sure that the right set of Policy
18108 -- pragmas are checked.
18110 if In_Body then
18112 -- Rewrite as Check pragma
18114 Rewrite (N,
18115 Make_Pragma (Loc,
18116 Chars => Name_Check,
18117 Pragma_Argument_Associations => New_List (
18118 Make_Pragma_Argument_Association (Loc,
18119 Expression => Make_Identifier (Loc, Pname)),
18121 Make_Pragma_Argument_Association (Sloc (Arg1),
18122 Expression =>
18123 Relocate_Node (Get_Pragma_Arg (Arg1))))));
18125 if Arg_Count = 2 then
18126 Append_To (Pragma_Argument_Associations (N),
18127 Make_Pragma_Argument_Association (Sloc (Arg2),
18128 Expression =>
18129 Relocate_Node (Get_Pragma_Arg (Arg2))));
18130 end if;
18132 Analyze (N);
18133 end if;
18134 end Precondition;
18136 ---------------
18137 -- Predicate --
18138 ---------------
18140 -- pragma Predicate
18141 -- ([Entity =>] type_LOCAL_NAME,
18142 -- [Check =>] boolean_EXPRESSION);
18144 when Pragma_Predicate => Predicate : declare
18145 Type_Id : Node_Id;
18146 Typ : Entity_Id;
18147 Discard : Boolean;
18149 begin
18150 GNAT_Pragma;
18151 Check_Arg_Count (2);
18152 Check_Optional_Identifier (Arg1, Name_Entity);
18153 Check_Optional_Identifier (Arg2, Name_Check);
18155 Check_Arg_Is_Local_Name (Arg1);
18157 Type_Id := Get_Pragma_Arg (Arg1);
18158 Find_Type (Type_Id);
18159 Typ := Entity (Type_Id);
18161 if Typ = Any_Type then
18162 return;
18163 end if;
18165 -- The remaining processing is simply to link the pragma on to
18166 -- the rep item chain, for processing when the type is frozen.
18167 -- This is accomplished by a call to Rep_Item_Too_Late. We also
18168 -- mark the type as having predicates.
18170 Set_Has_Predicates (Typ);
18171 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
18172 end Predicate;
18174 ------------------
18175 -- Preelaborate --
18176 ------------------
18178 -- pragma Preelaborate [(library_unit_NAME)];
18180 -- Set the flag Is_Preelaborated of program unit name entity
18182 when Pragma_Preelaborate => Preelaborate : declare
18183 Pa : constant Node_Id := Parent (N);
18184 Pk : constant Node_Kind := Nkind (Pa);
18185 Ent : Entity_Id;
18187 begin
18188 Check_Ada_83_Warning;
18189 Check_Valid_Library_Unit_Pragma;
18191 if Nkind (N) = N_Null_Statement then
18192 return;
18193 end if;
18195 Ent := Find_Lib_Unit_Name;
18196 Check_Duplicate_Pragma (Ent);
18198 -- This filters out pragmas inside generic parents that show up
18199 -- inside instantiations. Pragmas that come from aspects in the
18200 -- unit are not ignored.
18202 if Present (Ent) then
18203 if Pk = N_Package_Specification
18204 and then Present (Generic_Parent (Pa))
18205 and then not From_Aspect_Specification (N)
18206 then
18207 null;
18209 else
18210 if not Debug_Flag_U then
18211 Set_Is_Preelaborated (Ent);
18212 Set_Suppress_Elaboration_Warnings (Ent);
18213 end if;
18214 end if;
18215 end if;
18216 end Preelaborate;
18218 -------------------------------
18219 -- Prefix_Exception_Messages --
18220 -------------------------------
18222 -- pragma Prefix_Exception_Messages;
18224 when Pragma_Prefix_Exception_Messages =>
18225 GNAT_Pragma;
18226 Check_Valid_Configuration_Pragma;
18227 Check_Arg_Count (0);
18228 Prefix_Exception_Messages := True;
18230 --------------
18231 -- Priority --
18232 --------------
18234 -- pragma Priority (EXPRESSION);
18236 when Pragma_Priority => Priority : declare
18237 P : constant Node_Id := Parent (N);
18238 Arg : Node_Id;
18239 Ent : Entity_Id;
18241 begin
18242 Check_No_Identifiers;
18243 Check_Arg_Count (1);
18245 -- Subprogram case
18247 if Nkind (P) = N_Subprogram_Body then
18248 Check_In_Main_Program;
18250 Ent := Defining_Unit_Name (Specification (P));
18252 if Nkind (Ent) = N_Defining_Program_Unit_Name then
18253 Ent := Defining_Identifier (Ent);
18254 end if;
18256 Arg := Get_Pragma_Arg (Arg1);
18257 Analyze_And_Resolve (Arg, Standard_Integer);
18259 -- Must be static
18261 if not Is_OK_Static_Expression (Arg) then
18262 Flag_Non_Static_Expr
18263 ("main subprogram priority is not static!", Arg);
18264 raise Pragma_Exit;
18266 -- If constraint error, then we already signalled an error
18268 elsif Raises_Constraint_Error (Arg) then
18269 null;
18271 -- Otherwise check in range except if Relaxed_RM_Semantics
18272 -- where we ignore the value if out of range.
18274 else
18275 declare
18276 Val : constant Uint := Expr_Value (Arg);
18277 begin
18278 if not Relaxed_RM_Semantics
18279 and then
18280 (Val < 0
18281 or else Val > Expr_Value (Expression
18282 (Parent (RTE (RE_Max_Priority)))))
18283 then
18284 Error_Pragma_Arg
18285 ("main subprogram priority is out of range", Arg1);
18286 else
18287 Set_Main_Priority
18288 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
18289 end if;
18290 end;
18291 end if;
18293 -- Load an arbitrary entity from System.Tasking.Stages or
18294 -- System.Tasking.Restricted.Stages (depending on the
18295 -- supported profile) to make sure that one of these packages
18296 -- is implicitly with'ed, since we need to have the tasking
18297 -- run time active for the pragma Priority to have any effect.
18298 -- Previously we with'ed the package System.Tasking, but this
18299 -- package does not trigger the required initialization of the
18300 -- run-time library.
18302 declare
18303 Discard : Entity_Id;
18304 pragma Warnings (Off, Discard);
18305 begin
18306 if Restricted_Profile then
18307 Discard := RTE (RE_Activate_Restricted_Tasks);
18308 else
18309 Discard := RTE (RE_Activate_Tasks);
18310 end if;
18311 end;
18313 -- Task or Protected, must be of type Integer
18315 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
18316 Arg := Get_Pragma_Arg (Arg1);
18317 Ent := Defining_Identifier (Parent (P));
18319 -- The expression must be analyzed in the special manner
18320 -- described in "Handling of Default and Per-Object
18321 -- Expressions" in sem.ads.
18323 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
18325 if not Is_OK_Static_Expression (Arg) then
18326 Check_Restriction (Static_Priorities, Arg);
18327 end if;
18329 -- Anything else is incorrect
18331 else
18332 Pragma_Misplaced;
18333 end if;
18335 -- Check duplicate pragma before we chain the pragma in the Rep
18336 -- Item chain of Ent.
18338 Check_Duplicate_Pragma (Ent);
18339 Record_Rep_Item (Ent, N);
18340 end Priority;
18342 -----------------------------------
18343 -- Priority_Specific_Dispatching --
18344 -----------------------------------
18346 -- pragma Priority_Specific_Dispatching (
18347 -- policy_IDENTIFIER,
18348 -- first_priority_EXPRESSION,
18349 -- last_priority_EXPRESSION);
18351 when Pragma_Priority_Specific_Dispatching =>
18352 Priority_Specific_Dispatching : declare
18353 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
18354 -- This is the entity System.Any_Priority;
18356 DP : Character;
18357 Lower_Bound : Node_Id;
18358 Upper_Bound : Node_Id;
18359 Lower_Val : Uint;
18360 Upper_Val : Uint;
18362 begin
18363 Ada_2005_Pragma;
18364 Check_Arg_Count (3);
18365 Check_No_Identifiers;
18366 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
18367 Check_Valid_Configuration_Pragma;
18368 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
18369 DP := Fold_Upper (Name_Buffer (1));
18371 Lower_Bound := Get_Pragma_Arg (Arg2);
18372 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
18373 Lower_Val := Expr_Value (Lower_Bound);
18375 Upper_Bound := Get_Pragma_Arg (Arg3);
18376 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
18377 Upper_Val := Expr_Value (Upper_Bound);
18379 -- It is not allowed to use Task_Dispatching_Policy and
18380 -- Priority_Specific_Dispatching in the same partition.
18382 if Task_Dispatching_Policy /= ' ' then
18383 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
18384 Error_Pragma
18385 ("pragma% incompatible with Task_Dispatching_Policy#");
18387 -- Check lower bound in range
18389 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
18390 or else
18391 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
18392 then
18393 Error_Pragma_Arg
18394 ("first_priority is out of range", Arg2);
18396 -- Check upper bound in range
18398 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
18399 or else
18400 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
18401 then
18402 Error_Pragma_Arg
18403 ("last_priority is out of range", Arg3);
18405 -- Check that the priority range is valid
18407 elsif Lower_Val > Upper_Val then
18408 Error_Pragma
18409 ("last_priority_expression must be greater than or equal to "
18410 & "first_priority_expression");
18412 -- Store the new policy, but always preserve System_Location since
18413 -- we like the error message with the run-time name.
18415 else
18416 -- Check overlapping in the priority ranges specified in other
18417 -- Priority_Specific_Dispatching pragmas within the same
18418 -- partition. We can only check those we know about.
18420 for J in
18421 Specific_Dispatching.First .. Specific_Dispatching.Last
18422 loop
18423 if Specific_Dispatching.Table (J).First_Priority in
18424 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
18425 or else Specific_Dispatching.Table (J).Last_Priority in
18426 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
18427 then
18428 Error_Msg_Sloc :=
18429 Specific_Dispatching.Table (J).Pragma_Loc;
18430 Error_Pragma
18431 ("priority range overlaps with "
18432 & "Priority_Specific_Dispatching#");
18433 end if;
18434 end loop;
18436 -- The use of Priority_Specific_Dispatching is incompatible
18437 -- with Task_Dispatching_Policy.
18439 if Task_Dispatching_Policy /= ' ' then
18440 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
18441 Error_Pragma
18442 ("Priority_Specific_Dispatching incompatible "
18443 & "with Task_Dispatching_Policy#");
18444 end if;
18446 -- The use of Priority_Specific_Dispatching forces ceiling
18447 -- locking policy.
18449 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
18450 Error_Msg_Sloc := Locking_Policy_Sloc;
18451 Error_Pragma
18452 ("Priority_Specific_Dispatching incompatible "
18453 & "with Locking_Policy#");
18455 -- Set the Ceiling_Locking policy, but preserve System_Location
18456 -- since we like the error message with the run time name.
18458 else
18459 Locking_Policy := 'C';
18461 if Locking_Policy_Sloc /= System_Location then
18462 Locking_Policy_Sloc := Loc;
18463 end if;
18464 end if;
18466 -- Add entry in the table
18468 Specific_Dispatching.Append
18469 ((Dispatching_Policy => DP,
18470 First_Priority => UI_To_Int (Lower_Val),
18471 Last_Priority => UI_To_Int (Upper_Val),
18472 Pragma_Loc => Loc));
18473 end if;
18474 end Priority_Specific_Dispatching;
18476 -------------
18477 -- Profile --
18478 -------------
18480 -- pragma Profile (profile_IDENTIFIER);
18482 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
18484 when Pragma_Profile =>
18485 Ada_2005_Pragma;
18486 Check_Arg_Count (1);
18487 Check_Valid_Configuration_Pragma;
18488 Check_No_Identifiers;
18490 declare
18491 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
18493 begin
18494 if Chars (Argx) = Name_Ravenscar then
18495 Set_Ravenscar_Profile (N);
18497 elsif Chars (Argx) = Name_Restricted then
18498 Set_Profile_Restrictions
18499 (Restricted,
18500 N, Warn => Treat_Restrictions_As_Warnings);
18502 elsif Chars (Argx) = Name_Rational then
18503 Set_Rational_Profile;
18505 elsif Chars (Argx) = Name_No_Implementation_Extensions then
18506 Set_Profile_Restrictions
18507 (No_Implementation_Extensions,
18508 N, Warn => Treat_Restrictions_As_Warnings);
18510 else
18511 Error_Pragma_Arg ("& is not a valid profile", Argx);
18512 end if;
18513 end;
18515 ----------------------
18516 -- Profile_Warnings --
18517 ----------------------
18519 -- pragma Profile_Warnings (profile_IDENTIFIER);
18521 -- profile_IDENTIFIER => Restricted | Ravenscar
18523 when Pragma_Profile_Warnings =>
18524 GNAT_Pragma;
18525 Check_Arg_Count (1);
18526 Check_Valid_Configuration_Pragma;
18527 Check_No_Identifiers;
18529 declare
18530 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
18532 begin
18533 if Chars (Argx) = Name_Ravenscar then
18534 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
18536 elsif Chars (Argx) = Name_Restricted then
18537 Set_Profile_Restrictions (Restricted, N, Warn => True);
18539 elsif Chars (Argx) = Name_No_Implementation_Extensions then
18540 Set_Profile_Restrictions
18541 (No_Implementation_Extensions, N, Warn => True);
18543 else
18544 Error_Pragma_Arg ("& is not a valid profile", Argx);
18545 end if;
18546 end;
18548 --------------------------
18549 -- Propagate_Exceptions --
18550 --------------------------
18552 -- pragma Propagate_Exceptions;
18554 -- Note: this pragma is obsolete and has no effect
18556 when Pragma_Propagate_Exceptions =>
18557 GNAT_Pragma;
18558 Check_Arg_Count (0);
18560 if Warn_On_Obsolescent_Feature then
18561 Error_Msg_N
18562 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
18563 "and has no effect?j?", N);
18564 end if;
18566 -----------------------------
18567 -- Provide_Shift_Operators --
18568 -----------------------------
18570 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
18572 when Pragma_Provide_Shift_Operators =>
18573 Provide_Shift_Operators : declare
18574 Ent : Entity_Id;
18576 procedure Declare_Shift_Operator (Nam : Name_Id);
18577 -- Insert declaration and pragma Instrinsic for named shift op
18579 ----------------------------
18580 -- Declare_Shift_Operator --
18581 ----------------------------
18583 procedure Declare_Shift_Operator (Nam : Name_Id) is
18584 Func : Node_Id;
18585 Import : Node_Id;
18587 begin
18588 Func :=
18589 Make_Subprogram_Declaration (Loc,
18590 Make_Function_Specification (Loc,
18591 Defining_Unit_Name =>
18592 Make_Defining_Identifier (Loc, Chars => Nam),
18594 Result_Definition =>
18595 Make_Identifier (Loc, Chars => Chars (Ent)),
18597 Parameter_Specifications => New_List (
18598 Make_Parameter_Specification (Loc,
18599 Defining_Identifier =>
18600 Make_Defining_Identifier (Loc, Name_Value),
18601 Parameter_Type =>
18602 Make_Identifier (Loc, Chars => Chars (Ent))),
18604 Make_Parameter_Specification (Loc,
18605 Defining_Identifier =>
18606 Make_Defining_Identifier (Loc, Name_Amount),
18607 Parameter_Type =>
18608 New_Occurrence_Of (Standard_Natural, Loc)))));
18610 Import :=
18611 Make_Pragma (Loc,
18612 Pragma_Identifier => Make_Identifier (Loc, Name_Import),
18613 Pragma_Argument_Associations => New_List (
18614 Make_Pragma_Argument_Association (Loc,
18615 Expression => Make_Identifier (Loc, Name_Intrinsic)),
18616 Make_Pragma_Argument_Association (Loc,
18617 Expression => Make_Identifier (Loc, Nam))));
18619 Insert_After (N, Import);
18620 Insert_After (N, Func);
18621 end Declare_Shift_Operator;
18623 -- Start of processing for Provide_Shift_Operators
18625 begin
18626 GNAT_Pragma;
18627 Check_Arg_Count (1);
18628 Check_Arg_Is_Local_Name (Arg1);
18630 Arg1 := Get_Pragma_Arg (Arg1);
18632 -- We must have an entity name
18634 if not Is_Entity_Name (Arg1) then
18635 Error_Pragma_Arg
18636 ("pragma % must apply to integer first subtype", Arg1);
18637 end if;
18639 -- If no Entity, means there was a prior error so ignore
18641 if Present (Entity (Arg1)) then
18642 Ent := Entity (Arg1);
18644 -- Apply error checks
18646 if not Is_First_Subtype (Ent) then
18647 Error_Pragma_Arg
18648 ("cannot apply pragma %",
18649 "\& is not a first subtype",
18650 Arg1);
18652 elsif not Is_Integer_Type (Ent) then
18653 Error_Pragma_Arg
18654 ("cannot apply pragma %",
18655 "\& is not an integer type",
18656 Arg1);
18658 elsif Has_Shift_Operator (Ent) then
18659 Error_Pragma_Arg
18660 ("cannot apply pragma %",
18661 "\& already has declared shift operators",
18662 Arg1);
18664 elsif Is_Frozen (Ent) then
18665 Error_Pragma_Arg
18666 ("pragma % appears too late",
18667 "\& is already frozen",
18668 Arg1);
18669 end if;
18671 -- Now declare the operators. We do this during analysis rather
18672 -- than expansion, since we want the operators available if we
18673 -- are operating in -gnatc or ASIS mode.
18675 Declare_Shift_Operator (Name_Rotate_Left);
18676 Declare_Shift_Operator (Name_Rotate_Right);
18677 Declare_Shift_Operator (Name_Shift_Left);
18678 Declare_Shift_Operator (Name_Shift_Right);
18679 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
18680 end if;
18681 end Provide_Shift_Operators;
18683 ------------------
18684 -- Psect_Object --
18685 ------------------
18687 -- pragma Psect_Object (
18688 -- [Internal =>] LOCAL_NAME,
18689 -- [, [External =>] EXTERNAL_SYMBOL]
18690 -- [, [Size =>] EXTERNAL_SYMBOL]);
18692 when Pragma_Psect_Object | Pragma_Common_Object =>
18693 Psect_Object : declare
18694 Args : Args_List (1 .. 3);
18695 Names : constant Name_List (1 .. 3) := (
18696 Name_Internal,
18697 Name_External,
18698 Name_Size);
18700 Internal : Node_Id renames Args (1);
18701 External : Node_Id renames Args (2);
18702 Size : Node_Id renames Args (3);
18704 Def_Id : Entity_Id;
18706 procedure Check_Arg (Arg : Node_Id);
18707 -- Checks that argument is either a string literal or an
18708 -- identifier, and posts error message if not.
18710 ---------------
18711 -- Check_Arg --
18712 ---------------
18714 procedure Check_Arg (Arg : Node_Id) is
18715 begin
18716 if not Nkind_In (Original_Node (Arg),
18717 N_String_Literal,
18718 N_Identifier)
18719 then
18720 Error_Pragma_Arg
18721 ("inappropriate argument for pragma %", Arg);
18722 end if;
18723 end Check_Arg;
18725 -- Start of processing for Common_Object/Psect_Object
18727 begin
18728 GNAT_Pragma;
18729 Gather_Associations (Names, Args);
18730 Process_Extended_Import_Export_Internal_Arg (Internal);
18732 Def_Id := Entity (Internal);
18734 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
18735 Error_Pragma_Arg
18736 ("pragma% must designate an object", Internal);
18737 end if;
18739 Check_Arg (Internal);
18741 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
18742 Error_Pragma_Arg
18743 ("cannot use pragma% for imported/exported object",
18744 Internal);
18745 end if;
18747 if Is_Concurrent_Type (Etype (Internal)) then
18748 Error_Pragma_Arg
18749 ("cannot specify pragma % for task/protected object",
18750 Internal);
18751 end if;
18753 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
18754 or else
18755 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
18756 then
18757 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
18758 end if;
18760 if Ekind (Def_Id) = E_Constant then
18761 Error_Pragma_Arg
18762 ("cannot specify pragma % for a constant", Internal);
18763 end if;
18765 if Is_Record_Type (Etype (Internal)) then
18766 declare
18767 Ent : Entity_Id;
18768 Decl : Entity_Id;
18770 begin
18771 Ent := First_Entity (Etype (Internal));
18772 while Present (Ent) loop
18773 Decl := Declaration_Node (Ent);
18775 if Ekind (Ent) = E_Component
18776 and then Nkind (Decl) = N_Component_Declaration
18777 and then Present (Expression (Decl))
18778 and then Warn_On_Export_Import
18779 then
18780 Error_Msg_N
18781 ("?x?object for pragma % has defaults", Internal);
18782 exit;
18784 else
18785 Next_Entity (Ent);
18786 end if;
18787 end loop;
18788 end;
18789 end if;
18791 if Present (Size) then
18792 Check_Arg (Size);
18793 end if;
18795 if Present (External) then
18796 Check_Arg_Is_External_Name (External);
18797 end if;
18799 -- If all error tests pass, link pragma on to the rep item chain
18801 Record_Rep_Item (Def_Id, N);
18802 end Psect_Object;
18804 ----------
18805 -- Pure --
18806 ----------
18808 -- pragma Pure [(library_unit_NAME)];
18810 when Pragma_Pure => Pure : declare
18811 Ent : Entity_Id;
18813 begin
18814 Check_Ada_83_Warning;
18815 Check_Valid_Library_Unit_Pragma;
18817 if Nkind (N) = N_Null_Statement then
18818 return;
18819 end if;
18821 Ent := Find_Lib_Unit_Name;
18822 Set_Is_Pure (Ent);
18823 Set_Has_Pragma_Pure (Ent);
18824 Set_Suppress_Elaboration_Warnings (Ent);
18825 end Pure;
18827 -------------------
18828 -- Pure_Function --
18829 -------------------
18831 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
18833 when Pragma_Pure_Function => Pure_Function : declare
18834 E_Id : Node_Id;
18835 E : Entity_Id;
18836 Def_Id : Entity_Id;
18837 Effective : Boolean := False;
18839 begin
18840 GNAT_Pragma;
18841 Check_Arg_Count (1);
18842 Check_Optional_Identifier (Arg1, Name_Entity);
18843 Check_Arg_Is_Local_Name (Arg1);
18844 E_Id := Get_Pragma_Arg (Arg1);
18846 if Error_Posted (E_Id) then
18847 return;
18848 end if;
18850 -- Loop through homonyms (overloadings) of referenced entity
18852 E := Entity (E_Id);
18854 if Present (E) then
18855 loop
18856 Def_Id := Get_Base_Subprogram (E);
18858 if not Ekind_In (Def_Id, E_Function,
18859 E_Generic_Function,
18860 E_Operator)
18861 then
18862 Error_Pragma_Arg
18863 ("pragma% requires a function name", Arg1);
18864 end if;
18866 Set_Is_Pure (Def_Id);
18868 if not Has_Pragma_Pure_Function (Def_Id) then
18869 Set_Has_Pragma_Pure_Function (Def_Id);
18870 Effective := True;
18871 end if;
18873 exit when From_Aspect_Specification (N);
18874 E := Homonym (E);
18875 exit when No (E) or else Scope (E) /= Current_Scope;
18876 end loop;
18878 if not Effective
18879 and then Warn_On_Redundant_Constructs
18880 then
18881 Error_Msg_NE
18882 ("pragma Pure_Function on& is redundant?r?",
18883 N, Entity (E_Id));
18884 end if;
18885 end if;
18886 end Pure_Function;
18888 --------------------
18889 -- Queuing_Policy --
18890 --------------------
18892 -- pragma Queuing_Policy (policy_IDENTIFIER);
18894 when Pragma_Queuing_Policy => declare
18895 QP : Character;
18897 begin
18898 Check_Ada_83_Warning;
18899 Check_Arg_Count (1);
18900 Check_No_Identifiers;
18901 Check_Arg_Is_Queuing_Policy (Arg1);
18902 Check_Valid_Configuration_Pragma;
18903 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
18904 QP := Fold_Upper (Name_Buffer (1));
18906 if Queuing_Policy /= ' '
18907 and then Queuing_Policy /= QP
18908 then
18909 Error_Msg_Sloc := Queuing_Policy_Sloc;
18910 Error_Pragma ("queuing policy incompatible with policy#");
18912 -- Set new policy, but always preserve System_Location since we
18913 -- like the error message with the run time name.
18915 else
18916 Queuing_Policy := QP;
18918 if Queuing_Policy_Sloc /= System_Location then
18919 Queuing_Policy_Sloc := Loc;
18920 end if;
18921 end if;
18922 end;
18924 --------------
18925 -- Rational --
18926 --------------
18928 -- pragma Rational, for compatibility with foreign compiler
18930 when Pragma_Rational =>
18931 Set_Rational_Profile;
18933 ------------------------------------
18934 -- Refined_Depends/Refined_Global --
18935 ------------------------------------
18937 -- pragma Refined_Depends (DEPENDENCY_RELATION);
18939 -- DEPENDENCY_RELATION ::=
18940 -- null
18941 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
18943 -- DEPENDENCY_CLAUSE ::=
18944 -- OUTPUT_LIST =>[+] INPUT_LIST
18945 -- | NULL_DEPENDENCY_CLAUSE
18947 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
18949 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
18951 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
18953 -- OUTPUT ::= NAME | FUNCTION_RESULT
18954 -- INPUT ::= NAME
18956 -- where FUNCTION_RESULT is a function Result attribute_reference
18958 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
18960 -- GLOBAL_SPECIFICATION ::=
18961 -- null
18962 -- | GLOBAL_LIST
18963 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
18965 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
18967 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
18968 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
18969 -- GLOBAL_ITEM ::= NAME
18971 when Pragma_Refined_Depends |
18972 Pragma_Refined_Global => Refined_Depends_Global :
18973 declare
18974 Body_Id : Entity_Id;
18975 Legal : Boolean;
18976 Spec_Id : Entity_Id;
18978 begin
18979 Analyze_Refined_Pragma (Spec_Id, Body_Id, Legal);
18981 -- Save the pragma in the contract of the subprogram body. The
18982 -- remaining analysis is performed at the end of the enclosing
18983 -- declarations.
18985 if Legal then
18986 Add_Contract_Item (N, Body_Id);
18987 end if;
18988 end Refined_Depends_Global;
18990 ------------------
18991 -- Refined_Post --
18992 ------------------
18994 -- pragma Refined_Post (boolean_EXPRESSION);
18996 when Pragma_Refined_Post => Refined_Post : declare
18997 Body_Id : Entity_Id;
18998 Legal : Boolean;
18999 Result_Seen : Boolean := False;
19000 Spec_Id : Entity_Id;
19002 begin
19003 Analyze_Refined_Pragma (Spec_Id, Body_Id, Legal);
19005 -- Analyze the boolean expression as a "spec expression"
19007 if Legal then
19008 Analyze_Pre_Post_Condition_In_Decl_Part (N, Spec_Id);
19010 -- Verify that the refined postcondition mentions attribute
19011 -- 'Result and its expression introduces a post-state.
19013 if Warn_On_Suspicious_Contract
19014 and then Ekind_In (Spec_Id, E_Function, E_Generic_Function)
19015 then
19016 Check_Result_And_Post_State (N, Result_Seen);
19018 if not Result_Seen then
19019 Error_Pragma
19020 ("pragma % does not mention function result?T?");
19021 end if;
19022 end if;
19024 -- Chain the pragma on the contract for easy retrieval
19026 Add_Contract_Item (N, Body_Id);
19027 end if;
19028 end Refined_Post;
19030 -------------------
19031 -- Refined_State --
19032 -------------------
19034 -- pragma Refined_State (REFINEMENT_LIST);
19036 -- REFINEMENT_LIST ::=
19037 -- REFINEMENT_CLAUSE
19038 -- | (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
19040 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
19042 -- CONSTITUENT_LIST ::=
19043 -- null
19044 -- | CONSTITUENT
19045 -- | (CONSTITUENT {, CONSTITUENT})
19047 -- CONSTITUENT ::= object_NAME | state_NAME
19049 when Pragma_Refined_State => Refined_State : declare
19050 Context : constant Node_Id := Parent (N);
19051 Spec_Id : Entity_Id;
19052 Stmt : Node_Id;
19054 begin
19055 GNAT_Pragma;
19056 Check_No_Identifiers;
19057 Check_Arg_Count (1);
19059 -- Ensure the proper placement of the pragma. Refined states must
19060 -- be associated with a package body.
19062 if Nkind (Context) /= N_Package_Body then
19063 Pragma_Misplaced;
19064 return;
19065 end if;
19067 Stmt := Prev (N);
19068 while Present (Stmt) loop
19070 -- Skip prior pragmas, but check for duplicates
19072 if Nkind (Stmt) = N_Pragma then
19073 if Pragma_Name (Stmt) = Pname then
19074 Error_Msg_Name_1 := Pname;
19075 Error_Msg_Sloc := Sloc (Stmt);
19076 Error_Msg_N ("pragma % duplicates pragma declared #", N);
19077 end if;
19079 -- Skip internally generated code
19081 elsif not Comes_From_Source (Stmt) then
19082 null;
19084 -- The pragma does not apply to a legal construct, issue an
19085 -- error and stop the analysis.
19087 else
19088 Pragma_Misplaced;
19089 return;
19090 end if;
19092 Stmt := Prev (Stmt);
19093 end loop;
19095 Spec_Id := Corresponding_Spec (Context);
19097 -- State refinement is allowed only when the corresponding package
19098 -- declaration has non-null pragma Abstract_State. Refinement not
19099 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
19101 if SPARK_Mode /= Off
19102 and then
19103 (No (Abstract_States (Spec_Id))
19104 or else Has_Null_Abstract_State (Spec_Id))
19105 then
19106 Error_Msg_NE
19107 ("useless refinement, package & does not define abstract "
19108 & "states", N, Spec_Id);
19109 return;
19110 end if;
19112 -- The pragma must be analyzed at the end of the declarations as
19113 -- it has visibility over the whole declarative region. Save the
19114 -- pragma for later (see Analyze_Refined_Depends_In_Decl_Part) by
19115 -- adding it to the contract of the package body.
19117 Add_Contract_Item (N, Defining_Entity (Context));
19118 end Refined_State;
19120 -----------------------
19121 -- Relative_Deadline --
19122 -----------------------
19124 -- pragma Relative_Deadline (time_span_EXPRESSION);
19126 when Pragma_Relative_Deadline => Relative_Deadline : declare
19127 P : constant Node_Id := Parent (N);
19128 Arg : Node_Id;
19130 begin
19131 Ada_2005_Pragma;
19132 Check_No_Identifiers;
19133 Check_Arg_Count (1);
19135 Arg := Get_Pragma_Arg (Arg1);
19137 -- The expression must be analyzed in the special manner described
19138 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
19140 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
19142 -- Subprogram case
19144 if Nkind (P) = N_Subprogram_Body then
19145 Check_In_Main_Program;
19147 -- Only Task and subprogram cases allowed
19149 elsif Nkind (P) /= N_Task_Definition then
19150 Pragma_Misplaced;
19151 end if;
19153 -- Check duplicate pragma before we set the corresponding flag
19155 if Has_Relative_Deadline_Pragma (P) then
19156 Error_Pragma ("duplicate pragma% not allowed");
19157 end if;
19159 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
19160 -- Relative_Deadline pragma node cannot be inserted in the Rep
19161 -- Item chain of Ent since it is rewritten by the expander as a
19162 -- procedure call statement that will break the chain.
19164 Set_Has_Relative_Deadline_Pragma (P, True);
19165 end Relative_Deadline;
19167 ------------------------
19168 -- Remote_Access_Type --
19169 ------------------------
19171 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
19173 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
19174 E : Entity_Id;
19176 begin
19177 GNAT_Pragma;
19178 Check_Arg_Count (1);
19179 Check_Optional_Identifier (Arg1, Name_Entity);
19180 Check_Arg_Is_Local_Name (Arg1);
19182 E := Entity (Get_Pragma_Arg (Arg1));
19184 if Nkind (Parent (E)) = N_Formal_Type_Declaration
19185 and then Ekind (E) = E_General_Access_Type
19186 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
19187 and then Scope (Root_Type (Directly_Designated_Type (E)))
19188 = Scope (E)
19189 and then Is_Valid_Remote_Object_Type
19190 (Root_Type (Directly_Designated_Type (E)))
19191 then
19192 Set_Is_Remote_Types (E);
19194 else
19195 Error_Pragma_Arg
19196 ("pragma% applies only to formal access to classwide types",
19197 Arg1);
19198 end if;
19199 end Remote_Access_Type;
19201 ---------------------------
19202 -- Remote_Call_Interface --
19203 ---------------------------
19205 -- pragma Remote_Call_Interface [(library_unit_NAME)];
19207 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
19208 Cunit_Node : Node_Id;
19209 Cunit_Ent : Entity_Id;
19210 K : Node_Kind;
19212 begin
19213 Check_Ada_83_Warning;
19214 Check_Valid_Library_Unit_Pragma;
19216 if Nkind (N) = N_Null_Statement then
19217 return;
19218 end if;
19220 Cunit_Node := Cunit (Current_Sem_Unit);
19221 K := Nkind (Unit (Cunit_Node));
19222 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
19224 if K = N_Package_Declaration
19225 or else K = N_Generic_Package_Declaration
19226 or else K = N_Subprogram_Declaration
19227 or else K = N_Generic_Subprogram_Declaration
19228 or else (K = N_Subprogram_Body
19229 and then Acts_As_Spec (Unit (Cunit_Node)))
19230 then
19231 null;
19232 else
19233 Error_Pragma (
19234 "pragma% must apply to package or subprogram declaration");
19235 end if;
19237 Set_Is_Remote_Call_Interface (Cunit_Ent);
19238 end Remote_Call_Interface;
19240 ------------------
19241 -- Remote_Types --
19242 ------------------
19244 -- pragma Remote_Types [(library_unit_NAME)];
19246 when Pragma_Remote_Types => Remote_Types : declare
19247 Cunit_Node : Node_Id;
19248 Cunit_Ent : Entity_Id;
19250 begin
19251 Check_Ada_83_Warning;
19252 Check_Valid_Library_Unit_Pragma;
19254 if Nkind (N) = N_Null_Statement then
19255 return;
19256 end if;
19258 Cunit_Node := Cunit (Current_Sem_Unit);
19259 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
19261 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
19262 N_Generic_Package_Declaration)
19263 then
19264 Error_Pragma
19265 ("pragma% can only apply to a package declaration");
19266 end if;
19268 Set_Is_Remote_Types (Cunit_Ent);
19269 end Remote_Types;
19271 ---------------
19272 -- Ravenscar --
19273 ---------------
19275 -- pragma Ravenscar;
19277 when Pragma_Ravenscar =>
19278 GNAT_Pragma;
19279 Check_Arg_Count (0);
19280 Check_Valid_Configuration_Pragma;
19281 Set_Ravenscar_Profile (N);
19283 if Warn_On_Obsolescent_Feature then
19284 Error_Msg_N
19285 ("pragma Ravenscar is an obsolescent feature?j?", N);
19286 Error_Msg_N
19287 ("|use pragma Profile (Ravenscar) instead?j?", N);
19288 end if;
19290 -------------------------
19291 -- Restricted_Run_Time --
19292 -------------------------
19294 -- pragma Restricted_Run_Time;
19296 when Pragma_Restricted_Run_Time =>
19297 GNAT_Pragma;
19298 Check_Arg_Count (0);
19299 Check_Valid_Configuration_Pragma;
19300 Set_Profile_Restrictions
19301 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
19303 if Warn_On_Obsolescent_Feature then
19304 Error_Msg_N
19305 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
19307 Error_Msg_N
19308 ("|use pragma Profile (Restricted) instead?j?", N);
19309 end if;
19311 ------------------
19312 -- Restrictions --
19313 ------------------
19315 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
19317 -- RESTRICTION ::=
19318 -- restriction_IDENTIFIER
19319 -- | restriction_parameter_IDENTIFIER => EXPRESSION
19321 when Pragma_Restrictions =>
19322 Process_Restrictions_Or_Restriction_Warnings
19323 (Warn => Treat_Restrictions_As_Warnings);
19325 --------------------------
19326 -- Restriction_Warnings --
19327 --------------------------
19329 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
19331 -- RESTRICTION ::=
19332 -- restriction_IDENTIFIER
19333 -- | restriction_parameter_IDENTIFIER => EXPRESSION
19335 when Pragma_Restriction_Warnings =>
19336 GNAT_Pragma;
19337 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
19339 ----------------
19340 -- Reviewable --
19341 ----------------
19343 -- pragma Reviewable;
19345 when Pragma_Reviewable =>
19346 Check_Ada_83_Warning;
19347 Check_Arg_Count (0);
19349 -- Call dummy debugging function rv. This is done to assist front
19350 -- end debugging. By placing a Reviewable pragma in the source
19351 -- program, a breakpoint on rv catches this place in the source,
19352 -- allowing convenient stepping to the point of interest.
19356 --------------------------
19357 -- Short_Circuit_And_Or --
19358 --------------------------
19360 -- pragma Short_Circuit_And_Or;
19362 when Pragma_Short_Circuit_And_Or =>
19363 GNAT_Pragma;
19364 Check_Arg_Count (0);
19365 Check_Valid_Configuration_Pragma;
19366 Short_Circuit_And_Or := True;
19368 -------------------
19369 -- Share_Generic --
19370 -------------------
19372 -- pragma Share_Generic (GNAME {, GNAME});
19374 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
19376 when Pragma_Share_Generic =>
19377 GNAT_Pragma;
19378 Process_Generic_List;
19380 ------------
19381 -- Shared --
19382 ------------
19384 -- pragma Shared (LOCAL_NAME);
19386 when Pragma_Shared =>
19387 GNAT_Pragma;
19388 Process_Atomic_Shared_Volatile;
19390 --------------------
19391 -- Shared_Passive --
19392 --------------------
19394 -- pragma Shared_Passive [(library_unit_NAME)];
19396 -- Set the flag Is_Shared_Passive of program unit name entity
19398 when Pragma_Shared_Passive => Shared_Passive : declare
19399 Cunit_Node : Node_Id;
19400 Cunit_Ent : Entity_Id;
19402 begin
19403 Check_Ada_83_Warning;
19404 Check_Valid_Library_Unit_Pragma;
19406 if Nkind (N) = N_Null_Statement then
19407 return;
19408 end if;
19410 Cunit_Node := Cunit (Current_Sem_Unit);
19411 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
19413 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
19414 N_Generic_Package_Declaration)
19415 then
19416 Error_Pragma
19417 ("pragma% can only apply to a package declaration");
19418 end if;
19420 Set_Is_Shared_Passive (Cunit_Ent);
19421 end Shared_Passive;
19423 -----------------------
19424 -- Short_Descriptors --
19425 -----------------------
19427 -- pragma Short_Descriptors;
19429 -- Recognize and validate, but otherwise ignore
19431 when Pragma_Short_Descriptors =>
19432 GNAT_Pragma;
19433 Check_Arg_Count (0);
19434 Check_Valid_Configuration_Pragma;
19436 ------------------------------
19437 -- Simple_Storage_Pool_Type --
19438 ------------------------------
19440 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
19442 when Pragma_Simple_Storage_Pool_Type =>
19443 Simple_Storage_Pool_Type : declare
19444 Type_Id : Node_Id;
19445 Typ : Entity_Id;
19447 begin
19448 GNAT_Pragma;
19449 Check_Arg_Count (1);
19450 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19452 Type_Id := Get_Pragma_Arg (Arg1);
19453 Find_Type (Type_Id);
19454 Typ := Entity (Type_Id);
19456 if Typ = Any_Type then
19457 return;
19458 end if;
19460 -- We require the pragma to apply to a type declared in a package
19461 -- declaration, but not (immediately) within a package body.
19463 if Ekind (Current_Scope) /= E_Package
19464 or else In_Package_Body (Current_Scope)
19465 then
19466 Error_Pragma
19467 ("pragma% can only apply to type declared immediately "
19468 & "within a package declaration");
19469 end if;
19471 -- A simple storage pool type must be an immutably limited record
19472 -- or private type. If the pragma is given for a private type,
19473 -- the full type is similarly restricted (which is checked later
19474 -- in Freeze_Entity).
19476 if Is_Record_Type (Typ)
19477 and then not Is_Limited_View (Typ)
19478 then
19479 Error_Pragma
19480 ("pragma% can only apply to explicitly limited record type");
19482 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
19483 Error_Pragma
19484 ("pragma% can only apply to a private type that is limited");
19486 elsif not Is_Record_Type (Typ)
19487 and then not Is_Private_Type (Typ)
19488 then
19489 Error_Pragma
19490 ("pragma% can only apply to limited record or private type");
19491 end if;
19493 Record_Rep_Item (Typ, N);
19494 end Simple_Storage_Pool_Type;
19496 ----------------------
19497 -- Source_File_Name --
19498 ----------------------
19500 -- There are five forms for this pragma:
19502 -- pragma Source_File_Name (
19503 -- [UNIT_NAME =>] unit_NAME,
19504 -- BODY_FILE_NAME => STRING_LITERAL
19505 -- [, [INDEX =>] INTEGER_LITERAL]);
19507 -- pragma Source_File_Name (
19508 -- [UNIT_NAME =>] unit_NAME,
19509 -- SPEC_FILE_NAME => STRING_LITERAL
19510 -- [, [INDEX =>] INTEGER_LITERAL]);
19512 -- pragma Source_File_Name (
19513 -- BODY_FILE_NAME => STRING_LITERAL
19514 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19515 -- [, CASING => CASING_SPEC]);
19517 -- pragma Source_File_Name (
19518 -- SPEC_FILE_NAME => STRING_LITERAL
19519 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19520 -- [, CASING => CASING_SPEC]);
19522 -- pragma Source_File_Name (
19523 -- SUBUNIT_FILE_NAME => STRING_LITERAL
19524 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19525 -- [, CASING => CASING_SPEC]);
19527 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
19529 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
19530 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
19531 -- only be used when no project file is used, while SFNP can only be
19532 -- used when a project file is used.
19534 -- No processing here. Processing was completed during parsing, since
19535 -- we need to have file names set as early as possible. Units are
19536 -- loaded well before semantic processing starts.
19538 -- The only processing we defer to this point is the check for
19539 -- correct placement.
19541 when Pragma_Source_File_Name =>
19542 GNAT_Pragma;
19543 Check_Valid_Configuration_Pragma;
19545 ------------------------------
19546 -- Source_File_Name_Project --
19547 ------------------------------
19549 -- See Source_File_Name for syntax
19551 -- No processing here. Processing was completed during parsing, since
19552 -- we need to have file names set as early as possible. Units are
19553 -- loaded well before semantic processing starts.
19555 -- The only processing we defer to this point is the check for
19556 -- correct placement.
19558 when Pragma_Source_File_Name_Project =>
19559 GNAT_Pragma;
19560 Check_Valid_Configuration_Pragma;
19562 -- Check that a pragma Source_File_Name_Project is used only in a
19563 -- configuration pragmas file.
19565 -- Pragmas Source_File_Name_Project should only be generated by
19566 -- the Project Manager in configuration pragmas files.
19568 -- This is really an ugly test. It seems to depend on some
19569 -- accidental and undocumented property. At the very least it
19570 -- needs to be documented, but it would be better to have a
19571 -- clean way of testing if we are in a configuration file???
19573 if Present (Parent (N)) then
19574 Error_Pragma
19575 ("pragma% can only appear in a configuration pragmas file");
19576 end if;
19578 ----------------------
19579 -- Source_Reference --
19580 ----------------------
19582 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
19584 -- Nothing to do, all processing completed in Par.Prag, since we need
19585 -- the information for possible parser messages that are output.
19587 when Pragma_Source_Reference =>
19588 GNAT_Pragma;
19590 ----------------
19591 -- SPARK_Mode --
19592 ----------------
19594 -- pragma SPARK_Mode [(On | Off)];
19596 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
19597 procedure Check_Pragma_Conformance
19598 (Context_Pragma : Node_Id;
19599 Entity_Pragma : Node_Id;
19600 Entity : Entity_Id);
19601 -- If Context_Pragma is not Empty, verify that the new pragma N
19602 -- is compatible with the pragma Context_Pragma that was inherited
19603 -- from the context:
19604 -- . if Context_Pragma is ON, then the new mode can be anything
19605 -- . if Context_Pragma is OFF, then the only allowed new mode is
19606 -- also OFF.
19608 -- If Entity is not Empty, verify that the new pragma N is
19609 -- compatible with Entity_Pragma, the SPARK_Mode previously set
19610 -- for Entity (which may be Empty):
19611 -- . if Entity_Pragma is ON, then the new mode can be anything
19612 -- . if Entity_Pragma is OFF, then the only allowed new mode is
19613 -- also OFF.
19614 -- . if Entity_Pragma is Empty, we always issue an error, as this
19615 -- corresponds to a case where a previous section of Entity
19616 -- had no SPARK_Mode set.
19618 procedure Check_Library_Level_Entity (E : Entity_Id);
19619 -- Verify that pragma is applied to library-level entity E
19621 ------------------------------
19622 -- Check_Pragma_Conformance --
19623 ------------------------------
19625 procedure Check_Pragma_Conformance
19626 (Context_Pragma : Node_Id;
19627 Entity_Pragma : Node_Id;
19628 Entity : Entity_Id)
19630 begin
19631 if Present (Context_Pragma) then
19632 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
19634 -- New mode less restrictive than the established mode
19636 if Get_SPARK_Mode_From_Pragma (Context_Pragma) = Off
19637 and then Get_SPARK_Mode_From_Pragma (N) = On
19638 then
19639 Error_Msg_N
19640 ("cannot change SPARK_Mode from Off to On", Arg1);
19641 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
19642 Error_Msg_N ("\SPARK_Mode was set to Off#", Arg1);
19643 raise Pragma_Exit;
19644 end if;
19645 end if;
19647 if Present (Entity) then
19648 if Present (Entity_Pragma) then
19649 if Get_SPARK_Mode_From_Pragma (Entity_Pragma) = Off
19650 and then Get_SPARK_Mode_From_Pragma (N) = On
19651 then
19652 Error_Msg_N ("incorrect use of SPARK_Mode", Arg1);
19653 Error_Msg_Sloc := Sloc (Entity_Pragma);
19654 Error_Msg_NE
19655 ("\value Off was set for SPARK_Mode on&#",
19656 Arg1, Entity);
19657 raise Pragma_Exit;
19658 end if;
19660 else
19661 Error_Msg_N ("incorrect use of SPARK_Mode", Arg1);
19662 Error_Msg_Sloc := Sloc (Entity);
19663 Error_Msg_NE
19664 ("\no value was set for SPARK_Mode on&#",
19665 Arg1, Entity);
19666 raise Pragma_Exit;
19667 end if;
19668 end if;
19669 end Check_Pragma_Conformance;
19671 --------------------------------
19672 -- Check_Library_Level_Entity --
19673 --------------------------------
19675 procedure Check_Library_Level_Entity (E : Entity_Id) is
19676 MsgF : constant String := "incorrect placement of pragma%";
19678 begin
19679 if not Is_Library_Level_Entity (E) then
19680 Error_Msg_Name_1 := Pname;
19681 Error_Msg_N (Fix_Error (MsgF), N);
19683 if Ekind_In (E, E_Generic_Package,
19684 E_Package,
19685 E_Package_Body)
19686 then
19687 Error_Msg_NE
19688 ("\& is not a library-level package", N, E);
19689 else
19690 Error_Msg_NE
19691 ("\& is not a library-level subprogram", N, E);
19692 end if;
19694 raise Pragma_Exit;
19695 end if;
19696 end Check_Library_Level_Entity;
19698 -- Local variables
19700 Body_Id : Entity_Id;
19701 Context : Node_Id;
19702 Mode : Name_Id;
19703 Mode_Id : SPARK_Mode_Type;
19704 Spec_Id : Entity_Id;
19705 Stmt : Node_Id;
19707 -- Start of processing for Do_SPARK_Mode
19709 begin
19710 -- When a SPARK_Mode pragma appears inside an instantiation whose
19711 -- enclosing context has SPARK_Mode set to "off", the pragma has
19712 -- no semantic effect.
19714 if Ignore_Pragma_SPARK_Mode then
19715 Rewrite (N, Make_Null_Statement (Loc));
19716 Analyze (N);
19717 return;
19718 end if;
19720 GNAT_Pragma;
19721 Check_No_Identifiers;
19722 Check_At_Most_N_Arguments (1);
19724 -- Check the legality of the mode (no argument = ON)
19726 if Arg_Count = 1 then
19727 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
19728 Mode := Chars (Get_Pragma_Arg (Arg1));
19729 else
19730 Mode := Name_On;
19731 end if;
19733 Mode_Id := Get_SPARK_Mode_Type (Mode);
19734 Context := Parent (N);
19736 -- The pragma appears in a configuration pragmas file
19738 if No (Context) then
19739 Check_Valid_Configuration_Pragma;
19741 if Present (SPARK_Mode_Pragma) then
19742 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
19743 Error_Msg_N ("pragma% duplicates pragma declared#", N);
19744 raise Pragma_Exit;
19745 end if;
19747 SPARK_Mode_Pragma := N;
19748 SPARK_Mode := Mode_Id;
19750 -- The pragma acts as a configuration pragma in a compilation unit
19752 -- pragma SPARK_Mode ...;
19753 -- package Pack is ...;
19755 elsif Nkind (Context) = N_Compilation_Unit
19756 and then List_Containing (N) = Context_Items (Context)
19757 then
19758 Check_Valid_Configuration_Pragma;
19759 SPARK_Mode_Pragma := N;
19760 SPARK_Mode := Mode_Id;
19762 -- Otherwise the placement of the pragma within the tree dictates
19763 -- its associated construct. Inspect the declarative list where
19764 -- the pragma resides to find a potential construct.
19766 else
19767 Stmt := Prev (N);
19768 while Present (Stmt) loop
19770 -- Skip prior pragmas, but check for duplicates
19772 if Nkind (Stmt) = N_Pragma then
19773 if Pragma_Name (Stmt) = Pname then
19774 Error_Msg_Name_1 := Pname;
19775 Error_Msg_Sloc := Sloc (Stmt);
19776 Error_Msg_N ("pragma% duplicates pragma declared#", N);
19777 raise Pragma_Exit;
19778 end if;
19780 -- The pragma applies to a [generic] subprogram declaration.
19781 -- Note that this case covers an internally generated spec
19782 -- for a stand alone body.
19784 -- [generic]
19785 -- procedure Proc ...;
19786 -- pragma SPARK_Mode ..;
19788 elsif Nkind_In (Stmt, N_Generic_Subprogram_Declaration,
19789 N_Subprogram_Declaration)
19790 then
19791 Spec_Id := Defining_Entity (Stmt);
19792 Check_Library_Level_Entity (Spec_Id);
19793 Check_Pragma_Conformance
19794 (Context_Pragma => SPARK_Pragma (Spec_Id),
19795 Entity_Pragma => Empty,
19796 Entity => Empty);
19798 Set_SPARK_Pragma (Spec_Id, N);
19799 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19800 return;
19802 -- Skip internally generated code
19804 elsif not Comes_From_Source (Stmt) then
19805 null;
19807 -- Otherwise the pragma does not apply to a legal construct
19808 -- or it does not appear at the top of a declarative or a
19809 -- statement list. Issue an error and stop the analysis.
19811 else
19812 Pragma_Misplaced;
19813 exit;
19814 end if;
19816 Prev (Stmt);
19817 end loop;
19819 -- The pragma applies to a package or a subprogram that acts as
19820 -- a compilation unit.
19822 -- procedure Proc ...;
19823 -- pragma SPARK_Mode ...;
19825 if Nkind (Context) = N_Compilation_Unit_Aux then
19826 Context := Unit (Parent (Context));
19827 end if;
19829 -- The pragma appears within package declarations
19831 if Nkind (Context) = N_Package_Specification then
19832 Spec_Id := Defining_Entity (Context);
19833 Check_Library_Level_Entity (Spec_Id);
19835 -- The pragma is at the top of the visible declarations
19837 -- package Pack is
19838 -- pragma SPARK_Mode ...;
19840 if List_Containing (N) = Visible_Declarations (Context) then
19841 Check_Pragma_Conformance
19842 (Context_Pragma => SPARK_Pragma (Spec_Id),
19843 Entity_Pragma => Empty,
19844 Entity => Empty);
19845 SPARK_Mode_Pragma := N;
19846 SPARK_Mode := Mode_Id;
19848 Set_SPARK_Pragma (Spec_Id, N);
19849 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19850 Set_SPARK_Aux_Pragma (Spec_Id, N);
19851 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
19853 -- The pragma is at the top of the private declarations
19855 -- package Pack is
19856 -- private
19857 -- pragma SPARK_Mode ...;
19859 else
19860 Check_Pragma_Conformance
19861 (Context_Pragma => Empty,
19862 Entity_Pragma => SPARK_Pragma (Spec_Id),
19863 Entity => Spec_Id);
19864 SPARK_Mode_Pragma := N;
19865 SPARK_Mode := Mode_Id;
19867 Set_SPARK_Aux_Pragma (Spec_Id, N);
19868 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
19869 end if;
19871 -- The pragma appears at the top of package body declarations
19873 -- package body Pack is
19874 -- pragma SPARK_Mode ...;
19876 elsif Nkind (Context) = N_Package_Body then
19877 Spec_Id := Corresponding_Spec (Context);
19878 Body_Id := Defining_Entity (Context);
19879 Check_Library_Level_Entity (Body_Id);
19880 Check_Pragma_Conformance
19881 (Context_Pragma => SPARK_Pragma (Body_Id),
19882 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id),
19883 Entity => Spec_Id);
19884 SPARK_Mode_Pragma := N;
19885 SPARK_Mode := Mode_Id;
19887 Set_SPARK_Pragma (Body_Id, N);
19888 Set_SPARK_Pragma_Inherited (Body_Id, False);
19889 Set_SPARK_Aux_Pragma (Body_Id, N);
19890 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
19892 -- The pragma appears at the top of package body statements
19894 -- package body Pack is
19895 -- begin
19896 -- pragma SPARK_Mode;
19898 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
19899 and then Nkind (Parent (Context)) = N_Package_Body
19900 then
19901 Context := Parent (Context);
19902 Spec_Id := Corresponding_Spec (Context);
19903 Body_Id := Defining_Entity (Context);
19904 Check_Library_Level_Entity (Body_Id);
19905 Check_Pragma_Conformance
19906 (Context_Pragma => Empty,
19907 Entity_Pragma => SPARK_Pragma (Body_Id),
19908 Entity => Body_Id);
19909 SPARK_Mode_Pragma := N;
19910 SPARK_Mode := Mode_Id;
19912 Set_SPARK_Aux_Pragma (Body_Id, N);
19913 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
19915 -- The pragma appeared as an aspect of a [generic] subprogram
19916 -- declaration that acts as a compilation unit.
19918 -- [generic]
19919 -- procedure Proc ...;
19920 -- pragma SPARK_Mode ...;
19922 elsif Nkind_In (Context, N_Generic_Subprogram_Declaration,
19923 N_Subprogram_Declaration)
19924 then
19925 Spec_Id := Defining_Entity (Context);
19926 Check_Library_Level_Entity (Spec_Id);
19927 Check_Pragma_Conformance
19928 (Context_Pragma => SPARK_Pragma (Spec_Id),
19929 Entity_Pragma => Empty,
19930 Entity => Empty);
19932 Set_SPARK_Pragma (Spec_Id, N);
19933 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19935 -- The pragma appears at the top of subprogram body
19936 -- declarations.
19938 -- procedure Proc ... is
19939 -- pragma SPARK_Mode;
19941 elsif Nkind (Context) = N_Subprogram_Body then
19942 Spec_Id := Corresponding_Spec (Context);
19943 Context := Specification (Context);
19944 Body_Id := Defining_Entity (Context);
19946 -- Ignore pragma when applied to the special body created
19947 -- for inlining, recognized by its internal name _Parent.
19949 if Chars (Body_Id) = Name_uParent then
19950 return;
19951 end if;
19953 Check_Library_Level_Entity (Body_Id);
19955 -- The body is a completion of a previous declaration
19957 if Present (Spec_Id) then
19958 Check_Pragma_Conformance
19959 (Context_Pragma => SPARK_Pragma (Body_Id),
19960 Entity_Pragma => SPARK_Pragma (Spec_Id),
19961 Entity => Spec_Id);
19963 -- The body acts as spec
19965 else
19966 Check_Pragma_Conformance
19967 (Context_Pragma => SPARK_Pragma (Body_Id),
19968 Entity_Pragma => Empty,
19969 Entity => Empty);
19970 end if;
19972 SPARK_Mode_Pragma := N;
19973 SPARK_Mode := Mode_Id;
19975 Set_SPARK_Pragma (Body_Id, N);
19976 Set_SPARK_Pragma_Inherited (Body_Id, False);
19978 -- The pragma does not apply to a legal construct, issue error
19980 else
19981 Pragma_Misplaced;
19982 end if;
19983 end if;
19984 end Do_SPARK_Mode;
19986 --------------------------------
19987 -- Static_Elaboration_Desired --
19988 --------------------------------
19990 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
19992 when Pragma_Static_Elaboration_Desired =>
19993 GNAT_Pragma;
19994 Check_At_Most_N_Arguments (1);
19996 if Is_Compilation_Unit (Current_Scope)
19997 and then Ekind (Current_Scope) = E_Package
19998 then
19999 Set_Static_Elaboration_Desired (Current_Scope, True);
20000 else
20001 Error_Pragma ("pragma% must apply to a library-level package");
20002 end if;
20004 ------------------
20005 -- Storage_Size --
20006 ------------------
20008 -- pragma Storage_Size (EXPRESSION);
20010 when Pragma_Storage_Size => Storage_Size : declare
20011 P : constant Node_Id := Parent (N);
20012 Arg : Node_Id;
20014 begin
20015 Check_No_Identifiers;
20016 Check_Arg_Count (1);
20018 -- The expression must be analyzed in the special manner described
20019 -- in "Handling of Default Expressions" in sem.ads.
20021 Arg := Get_Pragma_Arg (Arg1);
20022 Preanalyze_Spec_Expression (Arg, Any_Integer);
20024 if not Is_OK_Static_Expression (Arg) then
20025 Check_Restriction (Static_Storage_Size, Arg);
20026 end if;
20028 if Nkind (P) /= N_Task_Definition then
20029 Pragma_Misplaced;
20030 return;
20032 else
20033 if Has_Storage_Size_Pragma (P) then
20034 Error_Pragma ("duplicate pragma% not allowed");
20035 else
20036 Set_Has_Storage_Size_Pragma (P, True);
20037 end if;
20039 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
20040 end if;
20041 end Storage_Size;
20043 ------------------
20044 -- Storage_Unit --
20045 ------------------
20047 -- pragma Storage_Unit (NUMERIC_LITERAL);
20049 -- Only permitted argument is System'Storage_Unit value
20051 when Pragma_Storage_Unit =>
20052 Check_No_Identifiers;
20053 Check_Arg_Count (1);
20054 Check_Arg_Is_Integer_Literal (Arg1);
20056 if Intval (Get_Pragma_Arg (Arg1)) /=
20057 UI_From_Int (Ttypes.System_Storage_Unit)
20058 then
20059 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
20060 Error_Pragma_Arg
20061 ("the only allowed argument for pragma% is ^", Arg1);
20062 end if;
20064 --------------------
20065 -- Stream_Convert --
20066 --------------------
20068 -- pragma Stream_Convert (
20069 -- [Entity =>] type_LOCAL_NAME,
20070 -- [Read =>] function_NAME,
20071 -- [Write =>] function NAME);
20073 when Pragma_Stream_Convert => Stream_Convert : declare
20075 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
20076 -- Check that the given argument is the name of a local function
20077 -- of one argument that is not overloaded earlier in the current
20078 -- local scope. A check is also made that the argument is a
20079 -- function with one parameter.
20081 --------------------------------------
20082 -- Check_OK_Stream_Convert_Function --
20083 --------------------------------------
20085 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
20086 Ent : Entity_Id;
20088 begin
20089 Check_Arg_Is_Local_Name (Arg);
20090 Ent := Entity (Get_Pragma_Arg (Arg));
20092 if Has_Homonym (Ent) then
20093 Error_Pragma_Arg
20094 ("argument for pragma% may not be overloaded", Arg);
20095 end if;
20097 if Ekind (Ent) /= E_Function
20098 or else No (First_Formal (Ent))
20099 or else Present (Next_Formal (First_Formal (Ent)))
20100 then
20101 Error_Pragma_Arg
20102 ("argument for pragma% must be function of one argument",
20103 Arg);
20104 end if;
20105 end Check_OK_Stream_Convert_Function;
20107 -- Start of processing for Stream_Convert
20109 begin
20110 GNAT_Pragma;
20111 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
20112 Check_Arg_Count (3);
20113 Check_Optional_Identifier (Arg1, Name_Entity);
20114 Check_Optional_Identifier (Arg2, Name_Read);
20115 Check_Optional_Identifier (Arg3, Name_Write);
20116 Check_Arg_Is_Local_Name (Arg1);
20117 Check_OK_Stream_Convert_Function (Arg2);
20118 Check_OK_Stream_Convert_Function (Arg3);
20120 declare
20121 Typ : constant Entity_Id :=
20122 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
20123 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
20124 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
20126 begin
20127 Check_First_Subtype (Arg1);
20129 -- Check for too early or too late. Note that we don't enforce
20130 -- the rule about primitive operations in this case, since, as
20131 -- is the case for explicit stream attributes themselves, these
20132 -- restrictions are not appropriate. Note that the chaining of
20133 -- the pragma by Rep_Item_Too_Late is actually the critical
20134 -- processing done for this pragma.
20136 if Rep_Item_Too_Early (Typ, N)
20137 or else
20138 Rep_Item_Too_Late (Typ, N, FOnly => True)
20139 then
20140 return;
20141 end if;
20143 -- Return if previous error
20145 if Etype (Typ) = Any_Type
20146 or else
20147 Etype (Read) = Any_Type
20148 or else
20149 Etype (Write) = Any_Type
20150 then
20151 return;
20152 end if;
20154 -- Error checks
20156 if Underlying_Type (Etype (Read)) /= Typ then
20157 Error_Pragma_Arg
20158 ("incorrect return type for function&", Arg2);
20159 end if;
20161 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
20162 Error_Pragma_Arg
20163 ("incorrect parameter type for function&", Arg3);
20164 end if;
20166 if Underlying_Type (Etype (First_Formal (Read))) /=
20167 Underlying_Type (Etype (Write))
20168 then
20169 Error_Pragma_Arg
20170 ("result type of & does not match Read parameter type",
20171 Arg3);
20172 end if;
20173 end;
20174 end Stream_Convert;
20176 ------------------
20177 -- Style_Checks --
20178 ------------------
20180 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
20182 -- This is processed by the parser since some of the style checks
20183 -- take place during source scanning and parsing. This means that
20184 -- we don't need to issue error messages here.
20186 when Pragma_Style_Checks => Style_Checks : declare
20187 A : constant Node_Id := Get_Pragma_Arg (Arg1);
20188 S : String_Id;
20189 C : Char_Code;
20191 begin
20192 GNAT_Pragma;
20193 Check_No_Identifiers;
20195 -- Two argument form
20197 if Arg_Count = 2 then
20198 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
20200 declare
20201 E_Id : Node_Id;
20202 E : Entity_Id;
20204 begin
20205 E_Id := Get_Pragma_Arg (Arg2);
20206 Analyze (E_Id);
20208 if not Is_Entity_Name (E_Id) then
20209 Error_Pragma_Arg
20210 ("second argument of pragma% must be entity name",
20211 Arg2);
20212 end if;
20214 E := Entity (E_Id);
20216 if not Ignore_Style_Checks_Pragmas then
20217 if E = Any_Id then
20218 return;
20219 else
20220 loop
20221 Set_Suppress_Style_Checks
20222 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
20223 exit when No (Homonym (E));
20224 E := Homonym (E);
20225 end loop;
20226 end if;
20227 end if;
20228 end;
20230 -- One argument form
20232 else
20233 Check_Arg_Count (1);
20235 if Nkind (A) = N_String_Literal then
20236 S := Strval (A);
20238 declare
20239 Slen : constant Natural := Natural (String_Length (S));
20240 Options : String (1 .. Slen);
20241 J : Natural;
20243 begin
20244 J := 1;
20245 loop
20246 C := Get_String_Char (S, Int (J));
20247 exit when not In_Character_Range (C);
20248 Options (J) := Get_Character (C);
20250 -- If at end of string, set options. As per discussion
20251 -- above, no need to check for errors, since we issued
20252 -- them in the parser.
20254 if J = Slen then
20255 if not Ignore_Style_Checks_Pragmas then
20256 Set_Style_Check_Options (Options);
20257 end if;
20259 exit;
20260 end if;
20262 J := J + 1;
20263 end loop;
20264 end;
20266 elsif Nkind (A) = N_Identifier then
20267 if Chars (A) = Name_All_Checks then
20268 if not Ignore_Style_Checks_Pragmas then
20269 if GNAT_Mode then
20270 Set_GNAT_Style_Check_Options;
20271 else
20272 Set_Default_Style_Check_Options;
20273 end if;
20274 end if;
20276 elsif Chars (A) = Name_On then
20277 if not Ignore_Style_Checks_Pragmas then
20278 Style_Check := True;
20279 end if;
20281 elsif Chars (A) = Name_Off then
20282 if not Ignore_Style_Checks_Pragmas then
20283 Style_Check := False;
20284 end if;
20285 end if;
20286 end if;
20287 end if;
20288 end Style_Checks;
20290 --------------
20291 -- Subtitle --
20292 --------------
20294 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
20296 when Pragma_Subtitle =>
20297 GNAT_Pragma;
20298 Check_Arg_Count (1);
20299 Check_Optional_Identifier (Arg1, Name_Subtitle);
20300 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
20301 Store_Note (N);
20303 --------------
20304 -- Suppress --
20305 --------------
20307 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
20309 when Pragma_Suppress =>
20310 Process_Suppress_Unsuppress (True);
20312 ------------------
20313 -- Suppress_All --
20314 ------------------
20316 -- pragma Suppress_All;
20318 -- The only check made here is that the pragma has no arguments.
20319 -- There are no placement rules, and the processing required (setting
20320 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
20321 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
20322 -- then creates and inserts a pragma Suppress (All_Checks).
20324 when Pragma_Suppress_All =>
20325 GNAT_Pragma;
20326 Check_Arg_Count (0);
20328 -------------------------
20329 -- Suppress_Debug_Info --
20330 -------------------------
20332 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
20334 when Pragma_Suppress_Debug_Info =>
20335 GNAT_Pragma;
20336 Check_Arg_Count (1);
20337 Check_Optional_Identifier (Arg1, Name_Entity);
20338 Check_Arg_Is_Local_Name (Arg1);
20339 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
20341 ----------------------------------
20342 -- Suppress_Exception_Locations --
20343 ----------------------------------
20345 -- pragma Suppress_Exception_Locations;
20347 when Pragma_Suppress_Exception_Locations =>
20348 GNAT_Pragma;
20349 Check_Arg_Count (0);
20350 Check_Valid_Configuration_Pragma;
20351 Exception_Locations_Suppressed := True;
20353 -----------------------------
20354 -- Suppress_Initialization --
20355 -----------------------------
20357 -- pragma Suppress_Initialization ([Entity =>] type_Name);
20359 when Pragma_Suppress_Initialization => Suppress_Init : declare
20360 E_Id : Node_Id;
20361 E : Entity_Id;
20363 begin
20364 GNAT_Pragma;
20365 Check_Arg_Count (1);
20366 Check_Optional_Identifier (Arg1, Name_Entity);
20367 Check_Arg_Is_Local_Name (Arg1);
20369 E_Id := Get_Pragma_Arg (Arg1);
20371 if Etype (E_Id) = Any_Type then
20372 return;
20373 end if;
20375 E := Entity (E_Id);
20377 if not Is_Type (E) and then Ekind (E) /= E_Variable then
20378 Error_Pragma_Arg
20379 ("pragma% requires variable, type or subtype", Arg1);
20380 end if;
20382 if Rep_Item_Too_Early (E, N)
20383 or else
20384 Rep_Item_Too_Late (E, N, FOnly => True)
20385 then
20386 return;
20387 end if;
20389 -- For incomplete/private type, set flag on full view
20391 if Is_Incomplete_Or_Private_Type (E) then
20392 if No (Full_View (Base_Type (E))) then
20393 Error_Pragma_Arg
20394 ("argument of pragma% cannot be an incomplete type", Arg1);
20395 else
20396 Set_Suppress_Initialization (Full_View (Base_Type (E)));
20397 end if;
20399 -- For first subtype, set flag on base type
20401 elsif Is_First_Subtype (E) then
20402 Set_Suppress_Initialization (Base_Type (E));
20404 -- For other than first subtype, set flag on subtype or variable
20406 else
20407 Set_Suppress_Initialization (E);
20408 end if;
20409 end Suppress_Init;
20411 -----------------
20412 -- System_Name --
20413 -----------------
20415 -- pragma System_Name (DIRECT_NAME);
20417 -- Syntax check: one argument, which must be the identifier GNAT or
20418 -- the identifier GCC, no other identifiers are acceptable.
20420 when Pragma_System_Name =>
20421 GNAT_Pragma;
20422 Check_No_Identifiers;
20423 Check_Arg_Count (1);
20424 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
20426 -----------------------------
20427 -- Task_Dispatching_Policy --
20428 -----------------------------
20430 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
20432 when Pragma_Task_Dispatching_Policy => declare
20433 DP : Character;
20435 begin
20436 Check_Ada_83_Warning;
20437 Check_Arg_Count (1);
20438 Check_No_Identifiers;
20439 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
20440 Check_Valid_Configuration_Pragma;
20441 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
20442 DP := Fold_Upper (Name_Buffer (1));
20444 if Task_Dispatching_Policy /= ' '
20445 and then Task_Dispatching_Policy /= DP
20446 then
20447 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
20448 Error_Pragma
20449 ("task dispatching policy incompatible with policy#");
20451 -- Set new policy, but always preserve System_Location since we
20452 -- like the error message with the run time name.
20454 else
20455 Task_Dispatching_Policy := DP;
20457 if Task_Dispatching_Policy_Sloc /= System_Location then
20458 Task_Dispatching_Policy_Sloc := Loc;
20459 end if;
20460 end if;
20461 end;
20463 ---------------
20464 -- Task_Info --
20465 ---------------
20467 -- pragma Task_Info (EXPRESSION);
20469 when Pragma_Task_Info => Task_Info : declare
20470 P : constant Node_Id := Parent (N);
20471 Ent : Entity_Id;
20473 begin
20474 GNAT_Pragma;
20476 if Warn_On_Obsolescent_Feature then
20477 Error_Msg_N
20478 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
20479 & "instead?j?", N);
20480 end if;
20482 if Nkind (P) /= N_Task_Definition then
20483 Error_Pragma ("pragma% must appear in task definition");
20484 end if;
20486 Check_No_Identifiers;
20487 Check_Arg_Count (1);
20489 Analyze_And_Resolve
20490 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
20492 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
20493 return;
20494 end if;
20496 Ent := Defining_Identifier (Parent (P));
20498 -- Check duplicate pragma before we chain the pragma in the Rep
20499 -- Item chain of Ent.
20501 if Has_Rep_Pragma
20502 (Ent, Name_Task_Info, Check_Parents => False)
20503 then
20504 Error_Pragma ("duplicate pragma% not allowed");
20505 end if;
20507 Record_Rep_Item (Ent, N);
20508 end Task_Info;
20510 ---------------
20511 -- Task_Name --
20512 ---------------
20514 -- pragma Task_Name (string_EXPRESSION);
20516 when Pragma_Task_Name => Task_Name : declare
20517 P : constant Node_Id := Parent (N);
20518 Arg : Node_Id;
20519 Ent : Entity_Id;
20521 begin
20522 Check_No_Identifiers;
20523 Check_Arg_Count (1);
20525 Arg := Get_Pragma_Arg (Arg1);
20527 -- The expression is used in the call to Create_Task, and must be
20528 -- expanded there, not in the context of the current spec. It must
20529 -- however be analyzed to capture global references, in case it
20530 -- appears in a generic context.
20532 Preanalyze_And_Resolve (Arg, Standard_String);
20534 if Nkind (P) /= N_Task_Definition then
20535 Pragma_Misplaced;
20536 end if;
20538 Ent := Defining_Identifier (Parent (P));
20540 -- Check duplicate pragma before we chain the pragma in the Rep
20541 -- Item chain of Ent.
20543 if Has_Rep_Pragma
20544 (Ent, Name_Task_Name, Check_Parents => False)
20545 then
20546 Error_Pragma ("duplicate pragma% not allowed");
20547 end if;
20549 Record_Rep_Item (Ent, N);
20550 end Task_Name;
20552 ------------------
20553 -- Task_Storage --
20554 ------------------
20556 -- pragma Task_Storage (
20557 -- [Task_Type =>] LOCAL_NAME,
20558 -- [Top_Guard =>] static_integer_EXPRESSION);
20560 when Pragma_Task_Storage => Task_Storage : declare
20561 Args : Args_List (1 .. 2);
20562 Names : constant Name_List (1 .. 2) := (
20563 Name_Task_Type,
20564 Name_Top_Guard);
20566 Task_Type : Node_Id renames Args (1);
20567 Top_Guard : Node_Id renames Args (2);
20569 Ent : Entity_Id;
20571 begin
20572 GNAT_Pragma;
20573 Gather_Associations (Names, Args);
20575 if No (Task_Type) then
20576 Error_Pragma
20577 ("missing task_type argument for pragma%");
20578 end if;
20580 Check_Arg_Is_Local_Name (Task_Type);
20582 Ent := Entity (Task_Type);
20584 if not Is_Task_Type (Ent) then
20585 Error_Pragma_Arg
20586 ("argument for pragma% must be task type", Task_Type);
20587 end if;
20589 if No (Top_Guard) then
20590 Error_Pragma_Arg
20591 ("pragma% takes two arguments", Task_Type);
20592 else
20593 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
20594 end if;
20596 Check_First_Subtype (Task_Type);
20598 if Rep_Item_Too_Late (Ent, N) then
20599 raise Pragma_Exit;
20600 end if;
20601 end Task_Storage;
20603 ---------------
20604 -- Test_Case --
20605 ---------------
20607 -- pragma Test_Case
20608 -- ([Name =>] Static_String_EXPRESSION
20609 -- ,[Mode =>] MODE_TYPE
20610 -- [, Requires => Boolean_EXPRESSION]
20611 -- [, Ensures => Boolean_EXPRESSION]);
20613 -- MODE_TYPE ::= Nominal | Robustness
20615 when Pragma_Test_Case =>
20616 GNAT_Pragma;
20617 Check_Test_Case;
20619 --------------------------
20620 -- Thread_Local_Storage --
20621 --------------------------
20623 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
20625 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
20626 Id : Node_Id;
20627 E : Entity_Id;
20629 begin
20630 GNAT_Pragma;
20631 Check_Arg_Count (1);
20632 Check_Optional_Identifier (Arg1, Name_Entity);
20633 Check_Arg_Is_Library_Level_Local_Name (Arg1);
20635 Id := Get_Pragma_Arg (Arg1);
20636 Analyze (Id);
20638 if not Is_Entity_Name (Id)
20639 or else Ekind (Entity (Id)) /= E_Variable
20640 then
20641 Error_Pragma_Arg ("local variable name required", Arg1);
20642 end if;
20644 E := Entity (Id);
20646 if Rep_Item_Too_Early (E, N)
20647 or else Rep_Item_Too_Late (E, N)
20648 then
20649 raise Pragma_Exit;
20650 end if;
20652 Set_Has_Pragma_Thread_Local_Storage (E);
20653 Set_Has_Gigi_Rep_Item (E);
20654 end Thread_Local_Storage;
20656 ----------------
20657 -- Time_Slice --
20658 ----------------
20660 -- pragma Time_Slice (static_duration_EXPRESSION);
20662 when Pragma_Time_Slice => Time_Slice : declare
20663 Val : Ureal;
20664 Nod : Node_Id;
20666 begin
20667 GNAT_Pragma;
20668 Check_Arg_Count (1);
20669 Check_No_Identifiers;
20670 Check_In_Main_Program;
20671 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
20673 if not Error_Posted (Arg1) then
20674 Nod := Next (N);
20675 while Present (Nod) loop
20676 if Nkind (Nod) = N_Pragma
20677 and then Pragma_Name (Nod) = Name_Time_Slice
20678 then
20679 Error_Msg_Name_1 := Pname;
20680 Error_Msg_N ("duplicate pragma% not permitted", Nod);
20681 end if;
20683 Next (Nod);
20684 end loop;
20685 end if;
20687 -- Process only if in main unit
20689 if Get_Source_Unit (Loc) = Main_Unit then
20690 Opt.Time_Slice_Set := True;
20691 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
20693 if Val <= Ureal_0 then
20694 Opt.Time_Slice_Value := 0;
20696 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
20697 Opt.Time_Slice_Value := 1_000_000_000;
20699 else
20700 Opt.Time_Slice_Value :=
20701 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
20702 end if;
20703 end if;
20704 end Time_Slice;
20706 -----------
20707 -- Title --
20708 -----------
20710 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
20712 -- TITLING_OPTION ::=
20713 -- [Title =>] STRING_LITERAL
20714 -- | [Subtitle =>] STRING_LITERAL
20716 when Pragma_Title => Title : declare
20717 Args : Args_List (1 .. 2);
20718 Names : constant Name_List (1 .. 2) := (
20719 Name_Title,
20720 Name_Subtitle);
20722 begin
20723 GNAT_Pragma;
20724 Gather_Associations (Names, Args);
20725 Store_Note (N);
20727 for J in 1 .. 2 loop
20728 if Present (Args (J)) then
20729 Check_Arg_Is_OK_Static_Expression
20730 (Args (J), Standard_String);
20731 end if;
20732 end loop;
20733 end Title;
20735 ----------------------------
20736 -- Type_Invariant[_Class] --
20737 ----------------------------
20739 -- pragma Type_Invariant[_Class]
20740 -- ([Entity =>] type_LOCAL_NAME,
20741 -- [Check =>] EXPRESSION);
20743 when Pragma_Type_Invariant |
20744 Pragma_Type_Invariant_Class =>
20745 Type_Invariant : declare
20746 I_Pragma : Node_Id;
20748 begin
20749 Check_Arg_Count (2);
20751 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
20752 -- setting Class_Present for the Type_Invariant_Class case.
20754 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
20755 I_Pragma := New_Copy (N);
20756 Set_Pragma_Identifier
20757 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
20758 Rewrite (N, I_Pragma);
20759 Set_Analyzed (N, False);
20760 Analyze (N);
20761 end Type_Invariant;
20763 ---------------------
20764 -- Unchecked_Union --
20765 ---------------------
20767 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
20769 when Pragma_Unchecked_Union => Unchecked_Union : declare
20770 Assoc : constant Node_Id := Arg1;
20771 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
20772 Typ : Entity_Id;
20773 Tdef : Node_Id;
20774 Clist : Node_Id;
20775 Vpart : Node_Id;
20776 Comp : Node_Id;
20777 Variant : Node_Id;
20779 begin
20780 Ada_2005_Pragma;
20781 Check_No_Identifiers;
20782 Check_Arg_Count (1);
20783 Check_Arg_Is_Local_Name (Arg1);
20785 Find_Type (Type_Id);
20787 Typ := Entity (Type_Id);
20789 if Typ = Any_Type
20790 or else Rep_Item_Too_Early (Typ, N)
20791 then
20792 return;
20793 else
20794 Typ := Underlying_Type (Typ);
20795 end if;
20797 if Rep_Item_Too_Late (Typ, N) then
20798 return;
20799 end if;
20801 Check_First_Subtype (Arg1);
20803 -- Note remaining cases are references to a type in the current
20804 -- declarative part. If we find an error, we post the error on
20805 -- the relevant type declaration at an appropriate point.
20807 if not Is_Record_Type (Typ) then
20808 Error_Msg_N ("unchecked union must be record type", Typ);
20809 return;
20811 elsif Is_Tagged_Type (Typ) then
20812 Error_Msg_N ("unchecked union must not be tagged", Typ);
20813 return;
20815 elsif not Has_Discriminants (Typ) then
20816 Error_Msg_N
20817 ("unchecked union must have one discriminant", Typ);
20818 return;
20820 -- Note: in previous versions of GNAT we used to check for limited
20821 -- types and give an error, but in fact the standard does allow
20822 -- Unchecked_Union on limited types, so this check was removed.
20824 -- Similarly, GNAT used to require that all discriminants have
20825 -- default values, but this is not mandated by the RM.
20827 -- Proceed with basic error checks completed
20829 else
20830 Tdef := Type_Definition (Declaration_Node (Typ));
20831 Clist := Component_List (Tdef);
20833 -- Check presence of component list and variant part
20835 if No (Clist) or else No (Variant_Part (Clist)) then
20836 Error_Msg_N
20837 ("unchecked union must have variant part", Tdef);
20838 return;
20839 end if;
20841 -- Check components
20843 Comp := First (Component_Items (Clist));
20844 while Present (Comp) loop
20845 Check_Component (Comp, Typ);
20846 Next (Comp);
20847 end loop;
20849 -- Check variant part
20851 Vpart := Variant_Part (Clist);
20853 Variant := First (Variants (Vpart));
20854 while Present (Variant) loop
20855 Check_Variant (Variant, Typ);
20856 Next (Variant);
20857 end loop;
20858 end if;
20860 Set_Is_Unchecked_Union (Typ);
20861 Set_Convention (Typ, Convention_C);
20862 Set_Has_Unchecked_Union (Base_Type (Typ));
20863 Set_Is_Unchecked_Union (Base_Type (Typ));
20864 end Unchecked_Union;
20866 ------------------------
20867 -- Unimplemented_Unit --
20868 ------------------------
20870 -- pragma Unimplemented_Unit;
20872 -- Note: this only gives an error if we are generating code, or if
20873 -- we are in a generic library unit (where the pragma appears in the
20874 -- body, not in the spec).
20876 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
20877 Cunitent : constant Entity_Id :=
20878 Cunit_Entity (Get_Source_Unit (Loc));
20879 Ent_Kind : constant Entity_Kind :=
20880 Ekind (Cunitent);
20882 begin
20883 GNAT_Pragma;
20884 Check_Arg_Count (0);
20886 if Operating_Mode = Generate_Code
20887 or else Ent_Kind = E_Generic_Function
20888 or else Ent_Kind = E_Generic_Procedure
20889 or else Ent_Kind = E_Generic_Package
20890 then
20891 Get_Name_String (Chars (Cunitent));
20892 Set_Casing (Mixed_Case);
20893 Write_Str (Name_Buffer (1 .. Name_Len));
20894 Write_Str (" is not supported in this configuration");
20895 Write_Eol;
20896 raise Unrecoverable_Error;
20897 end if;
20898 end Unimplemented_Unit;
20900 ------------------------
20901 -- Universal_Aliasing --
20902 ------------------------
20904 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
20906 when Pragma_Universal_Aliasing => Universal_Alias : declare
20907 E_Id : Entity_Id;
20909 begin
20910 GNAT_Pragma;
20911 Check_Arg_Count (1);
20912 Check_Optional_Identifier (Arg2, Name_Entity);
20913 Check_Arg_Is_Local_Name (Arg1);
20914 E_Id := Entity (Get_Pragma_Arg (Arg1));
20916 if E_Id = Any_Type then
20917 return;
20918 elsif No (E_Id) or else not Is_Type (E_Id) then
20919 Error_Pragma_Arg ("pragma% requires type", Arg1);
20920 end if;
20922 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
20923 Record_Rep_Item (E_Id, N);
20924 end Universal_Alias;
20926 --------------------
20927 -- Universal_Data --
20928 --------------------
20930 -- pragma Universal_Data [(library_unit_NAME)];
20932 when Pragma_Universal_Data =>
20933 GNAT_Pragma;
20935 -- If this is a configuration pragma, then set the universal
20936 -- addressing option, otherwise confirm that the pragma satisfies
20937 -- the requirements of library unit pragma placement and leave it
20938 -- to the GNAAMP back end to detect the pragma (avoids transitive
20939 -- setting of the option due to withed units).
20941 if Is_Configuration_Pragma then
20942 Universal_Addressing_On_AAMP := True;
20943 else
20944 Check_Valid_Library_Unit_Pragma;
20945 end if;
20947 if not AAMP_On_Target then
20948 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
20949 end if;
20951 ----------------
20952 -- Unmodified --
20953 ----------------
20955 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
20957 when Pragma_Unmodified => Unmodified : declare
20958 Arg_Node : Node_Id;
20959 Arg_Expr : Node_Id;
20960 Arg_Ent : Entity_Id;
20962 begin
20963 GNAT_Pragma;
20964 Check_At_Least_N_Arguments (1);
20966 -- Loop through arguments
20968 Arg_Node := Arg1;
20969 while Present (Arg_Node) loop
20970 Check_No_Identifier (Arg_Node);
20972 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
20973 -- in fact generate reference, so that the entity will have a
20974 -- reference, which will inhibit any warnings about it not
20975 -- being referenced, and also properly show up in the ali file
20976 -- as a reference. But this reference is recorded before the
20977 -- Has_Pragma_Unreferenced flag is set, so that no warning is
20978 -- generated for this reference.
20980 Check_Arg_Is_Local_Name (Arg_Node);
20981 Arg_Expr := Get_Pragma_Arg (Arg_Node);
20983 if Is_Entity_Name (Arg_Expr) then
20984 Arg_Ent := Entity (Arg_Expr);
20986 if not Is_Assignable (Arg_Ent) then
20987 Error_Pragma_Arg
20988 ("pragma% can only be applied to a variable",
20989 Arg_Expr);
20990 else
20991 Set_Has_Pragma_Unmodified (Arg_Ent);
20992 end if;
20993 end if;
20995 Next (Arg_Node);
20996 end loop;
20997 end Unmodified;
20999 ------------------
21000 -- Unreferenced --
21001 ------------------
21003 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
21005 -- or when used in a context clause:
21007 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
21009 when Pragma_Unreferenced => Unreferenced : declare
21010 Arg_Node : Node_Id;
21011 Arg_Expr : Node_Id;
21012 Arg_Ent : Entity_Id;
21013 Citem : Node_Id;
21015 begin
21016 GNAT_Pragma;
21017 Check_At_Least_N_Arguments (1);
21019 -- Check case of appearing within context clause
21021 if Is_In_Context_Clause then
21023 -- The arguments must all be units mentioned in a with clause
21024 -- in the same context clause. Note we already checked (in
21025 -- Par.Prag) that the arguments are either identifiers or
21026 -- selected components.
21028 Arg_Node := Arg1;
21029 while Present (Arg_Node) loop
21030 Citem := First (List_Containing (N));
21031 while Citem /= N loop
21032 if Nkind (Citem) = N_With_Clause
21033 and then
21034 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
21035 then
21036 Set_Has_Pragma_Unreferenced
21037 (Cunit_Entity
21038 (Get_Source_Unit
21039 (Library_Unit (Citem))));
21040 Set_Unit_Name
21041 (Get_Pragma_Arg (Arg_Node), Name (Citem));
21042 exit;
21043 end if;
21045 Next (Citem);
21046 end loop;
21048 if Citem = N then
21049 Error_Pragma_Arg
21050 ("argument of pragma% is not withed unit", Arg_Node);
21051 end if;
21053 Next (Arg_Node);
21054 end loop;
21056 -- Case of not in list of context items
21058 else
21059 Arg_Node := Arg1;
21060 while Present (Arg_Node) loop
21061 Check_No_Identifier (Arg_Node);
21063 -- Note: the analyze call done by Check_Arg_Is_Local_Name
21064 -- will in fact generate reference, so that the entity will
21065 -- have a reference, which will inhibit any warnings about
21066 -- it not being referenced, and also properly show up in the
21067 -- ali file as a reference. But this reference is recorded
21068 -- before the Has_Pragma_Unreferenced flag is set, so that
21069 -- no warning is generated for this reference.
21071 Check_Arg_Is_Local_Name (Arg_Node);
21072 Arg_Expr := Get_Pragma_Arg (Arg_Node);
21074 if Is_Entity_Name (Arg_Expr) then
21075 Arg_Ent := Entity (Arg_Expr);
21077 -- If the entity is overloaded, the pragma applies to the
21078 -- most recent overloading, as documented. In this case,
21079 -- name resolution does not generate a reference, so it
21080 -- must be done here explicitly.
21082 if Is_Overloaded (Arg_Expr) then
21083 Generate_Reference (Arg_Ent, N);
21084 end if;
21086 Set_Has_Pragma_Unreferenced (Arg_Ent);
21087 end if;
21089 Next (Arg_Node);
21090 end loop;
21091 end if;
21092 end Unreferenced;
21094 --------------------------
21095 -- Unreferenced_Objects --
21096 --------------------------
21098 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
21100 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
21101 Arg_Node : Node_Id;
21102 Arg_Expr : Node_Id;
21104 begin
21105 GNAT_Pragma;
21106 Check_At_Least_N_Arguments (1);
21108 Arg_Node := Arg1;
21109 while Present (Arg_Node) loop
21110 Check_No_Identifier (Arg_Node);
21111 Check_Arg_Is_Local_Name (Arg_Node);
21112 Arg_Expr := Get_Pragma_Arg (Arg_Node);
21114 if not Is_Entity_Name (Arg_Expr)
21115 or else not Is_Type (Entity (Arg_Expr))
21116 then
21117 Error_Pragma_Arg
21118 ("argument for pragma% must be type or subtype", Arg_Node);
21119 end if;
21121 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
21122 Next (Arg_Node);
21123 end loop;
21124 end Unreferenced_Objects;
21126 ------------------------------
21127 -- Unreserve_All_Interrupts --
21128 ------------------------------
21130 -- pragma Unreserve_All_Interrupts;
21132 when Pragma_Unreserve_All_Interrupts =>
21133 GNAT_Pragma;
21134 Check_Arg_Count (0);
21136 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
21137 Unreserve_All_Interrupts := True;
21138 end if;
21140 ----------------
21141 -- Unsuppress --
21142 ----------------
21144 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
21146 when Pragma_Unsuppress =>
21147 Ada_2005_Pragma;
21148 Process_Suppress_Unsuppress (False);
21150 ----------------------------
21151 -- Unevaluated_Use_Of_Old --
21152 ----------------------------
21154 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
21156 when Pragma_Unevaluated_Use_Of_Old =>
21157 GNAT_Pragma;
21158 Check_Arg_Count (1);
21159 Check_No_Identifiers;
21160 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
21162 -- Suppress/Unsuppress can appear as a configuration pragma, or in
21163 -- a declarative part or a package spec.
21165 if not Is_Configuration_Pragma then
21166 Check_Is_In_Decl_Part_Or_Package_Spec;
21167 end if;
21169 -- Store proper setting of Uneval_Old
21171 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21172 Uneval_Old := Fold_Upper (Name_Buffer (1));
21174 -------------------
21175 -- Use_VADS_Size --
21176 -------------------
21178 -- pragma Use_VADS_Size;
21180 when Pragma_Use_VADS_Size =>
21181 GNAT_Pragma;
21182 Check_Arg_Count (0);
21183 Check_Valid_Configuration_Pragma;
21184 Use_VADS_Size := True;
21186 ---------------------
21187 -- Validity_Checks --
21188 ---------------------
21190 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
21192 when Pragma_Validity_Checks => Validity_Checks : declare
21193 A : constant Node_Id := Get_Pragma_Arg (Arg1);
21194 S : String_Id;
21195 C : Char_Code;
21197 begin
21198 GNAT_Pragma;
21199 Check_Arg_Count (1);
21200 Check_No_Identifiers;
21202 -- Pragma always active unless in CodePeer or GNATprove modes,
21203 -- which use a fixed configuration of validity checks.
21205 if not (CodePeer_Mode or GNATprove_Mode) then
21206 if Nkind (A) = N_String_Literal then
21207 S := Strval (A);
21209 declare
21210 Slen : constant Natural := Natural (String_Length (S));
21211 Options : String (1 .. Slen);
21212 J : Natural;
21214 begin
21215 -- Couldn't we use a for loop here over Options'Range???
21217 J := 1;
21218 loop
21219 C := Get_String_Char (S, Int (J));
21221 -- This is a weird test, it skips setting validity
21222 -- checks entirely if any element of S is out of
21223 -- range of Character, what is that about ???
21225 exit when not In_Character_Range (C);
21226 Options (J) := Get_Character (C);
21228 if J = Slen then
21229 Set_Validity_Check_Options (Options);
21230 exit;
21231 else
21232 J := J + 1;
21233 end if;
21234 end loop;
21235 end;
21237 elsif Nkind (A) = N_Identifier then
21238 if Chars (A) = Name_All_Checks then
21239 Set_Validity_Check_Options ("a");
21240 elsif Chars (A) = Name_On then
21241 Validity_Checks_On := True;
21242 elsif Chars (A) = Name_Off then
21243 Validity_Checks_On := False;
21244 end if;
21245 end if;
21246 end if;
21247 end Validity_Checks;
21249 --------------
21250 -- Volatile --
21251 --------------
21253 -- pragma Volatile (LOCAL_NAME);
21255 when Pragma_Volatile =>
21256 Process_Atomic_Shared_Volatile;
21258 -------------------------
21259 -- Volatile_Components --
21260 -------------------------
21262 -- pragma Volatile_Components (array_LOCAL_NAME);
21264 -- Volatile is handled by the same circuit as Atomic_Components
21266 ----------------------
21267 -- Warning_As_Error --
21268 ----------------------
21270 -- pragma Warning_As_Error (static_string_EXPRESSION);
21272 when Pragma_Warning_As_Error =>
21273 GNAT_Pragma;
21274 Check_Arg_Count (1);
21275 Check_No_Identifiers;
21276 Check_Valid_Configuration_Pragma;
21278 if not Is_Static_String_Expression (Arg1) then
21279 Error_Pragma_Arg
21280 ("argument of pragma% must be static string expression",
21281 Arg1);
21283 -- OK static string expression
21285 else
21286 Acquire_Warning_Match_String (Arg1);
21287 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
21288 Warnings_As_Errors (Warnings_As_Errors_Count) :=
21289 new String'(Name_Buffer (1 .. Name_Len));
21290 end if;
21292 --------------
21293 -- Warnings --
21294 --------------
21296 -- pragma Warnings (On | Off [,REASON]);
21297 -- pragma Warnings (On | Off, LOCAL_NAME [,REASON]);
21298 -- pragma Warnings (static_string_EXPRESSION [,REASON]);
21299 -- pragma Warnings (On | Off, STRING_LITERAL [,REASON]);
21301 -- REASON ::= Reason => Static_String_Expression
21303 when Pragma_Warnings => Warnings : declare
21304 Reason : String_Id;
21306 begin
21307 GNAT_Pragma;
21308 Check_At_Least_N_Arguments (1);
21310 -- See if last argument is labeled Reason. If so, make sure we
21311 -- have a static string expression, and acquire the REASON string.
21312 -- Then remove the REASON argument by decreasing Num_Args by one;
21313 -- Remaining processing looks only at first Num_Args arguments).
21315 declare
21316 Last_Arg : constant Node_Id :=
21317 Last (Pragma_Argument_Associations (N));
21319 begin
21320 if Nkind (Last_Arg) = N_Pragma_Argument_Association
21321 and then Chars (Last_Arg) = Name_Reason
21322 then
21323 Start_String;
21324 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
21325 Reason := End_String;
21326 Arg_Count := Arg_Count - 1;
21328 -- Not allowed in compiler units (bootstrap issues)
21330 Check_Compiler_Unit ("Reason for pragma Warnings", N);
21332 -- No REASON string, set null string as reason
21334 else
21335 Reason := Null_String_Id;
21336 end if;
21337 end;
21339 -- Now proceed with REASON taken care of and eliminated
21341 Check_No_Identifiers;
21343 -- If debug flag -gnatd.i is set, pragma is ignored
21345 if Debug_Flag_Dot_I then
21346 return;
21347 end if;
21349 -- Process various forms of the pragma
21351 declare
21352 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21354 begin
21355 -- One argument case
21357 if Arg_Count = 1 then
21359 -- On/Off one argument case was processed by parser
21361 if Nkind (Argx) = N_Identifier
21362 and then Nam_In (Chars (Argx), Name_On, Name_Off)
21363 then
21364 null;
21366 -- One argument case must be ON/OFF or static string expr
21368 elsif not Is_Static_String_Expression (Arg1) then
21369 Error_Pragma_Arg
21370 ("argument of pragma% must be On/Off or static string "
21371 & "expression", Arg1);
21373 -- One argument string expression case
21375 else
21376 declare
21377 Lit : constant Node_Id := Expr_Value_S (Argx);
21378 Str : constant String_Id := Strval (Lit);
21379 Len : constant Nat := String_Length (Str);
21380 C : Char_Code;
21381 J : Nat;
21382 OK : Boolean;
21383 Chr : Character;
21385 begin
21386 J := 1;
21387 while J <= Len loop
21388 C := Get_String_Char (Str, J);
21389 OK := In_Character_Range (C);
21391 if OK then
21392 Chr := Get_Character (C);
21394 -- Dash case: only -Wxxx is accepted
21396 if J = 1
21397 and then J < Len
21398 and then Chr = '-'
21399 then
21400 J := J + 1;
21401 C := Get_String_Char (Str, J);
21402 Chr := Get_Character (C);
21403 exit when Chr = 'W';
21404 OK := False;
21406 -- Dot case
21408 elsif J < Len and then Chr = '.' then
21409 J := J + 1;
21410 C := Get_String_Char (Str, J);
21411 Chr := Get_Character (C);
21413 if not Set_Dot_Warning_Switch (Chr) then
21414 Error_Pragma_Arg
21415 ("invalid warning switch character "
21416 & '.' & Chr, Arg1);
21417 end if;
21419 -- Non-Dot case
21421 else
21422 OK := Set_Warning_Switch (Chr);
21423 end if;
21424 end if;
21426 if not OK then
21427 Error_Pragma_Arg
21428 ("invalid warning switch character " & Chr,
21429 Arg1);
21430 end if;
21432 J := J + 1;
21433 end loop;
21434 end;
21435 end if;
21437 -- Two or more arguments (must be two)
21439 else
21440 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
21441 Check_Arg_Count (2);
21443 declare
21444 E_Id : Node_Id;
21445 E : Entity_Id;
21446 Err : Boolean;
21448 begin
21449 E_Id := Get_Pragma_Arg (Arg2);
21450 Analyze (E_Id);
21452 -- In the expansion of an inlined body, a reference to
21453 -- the formal may be wrapped in a conversion if the
21454 -- actual is a conversion. Retrieve the real entity name.
21456 if (In_Instance_Body or In_Inlined_Body)
21457 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
21458 then
21459 E_Id := Expression (E_Id);
21460 end if;
21462 -- Entity name case
21464 if Is_Entity_Name (E_Id) then
21465 E := Entity (E_Id);
21467 if E = Any_Id then
21468 return;
21469 else
21470 loop
21471 Set_Warnings_Off
21472 (E, (Chars (Get_Pragma_Arg (Arg1)) =
21473 Name_Off));
21475 -- For OFF case, make entry in warnings off
21476 -- pragma table for later processing. But we do
21477 -- not do that within an instance, since these
21478 -- warnings are about what is needed in the
21479 -- template, not an instance of it.
21481 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
21482 and then Warn_On_Warnings_Off
21483 and then not In_Instance
21484 then
21485 Warnings_Off_Pragmas.Append ((N, E, Reason));
21486 end if;
21488 if Is_Enumeration_Type (E) then
21489 declare
21490 Lit : Entity_Id;
21491 begin
21492 Lit := First_Literal (E);
21493 while Present (Lit) loop
21494 Set_Warnings_Off (Lit);
21495 Next_Literal (Lit);
21496 end loop;
21497 end;
21498 end if;
21500 exit when No (Homonym (E));
21501 E := Homonym (E);
21502 end loop;
21503 end if;
21505 -- Error if not entity or static string expression case
21507 elsif not Is_Static_String_Expression (Arg2) then
21508 Error_Pragma_Arg
21509 ("second argument of pragma% must be entity name "
21510 & "or static string expression", Arg2);
21512 -- Static string expression case
21514 else
21515 Acquire_Warning_Match_String (Arg2);
21517 -- Note on configuration pragma case: If this is a
21518 -- configuration pragma, then for an OFF pragma, we
21519 -- just set Config True in the call, which is all
21520 -- that needs to be done. For the case of ON, this
21521 -- is normally an error, unless it is canceling the
21522 -- effect of a previous OFF pragma in the same file.
21523 -- In any other case, an error will be signalled (ON
21524 -- with no matching OFF).
21526 -- Note: We set Used if we are inside a generic to
21527 -- disable the test that the non-config case actually
21528 -- cancels a warning. That's because we can't be sure
21529 -- there isn't an instantiation in some other unit
21530 -- where a warning is suppressed.
21532 -- We could do a little better here by checking if the
21533 -- generic unit we are inside is public, but for now
21534 -- we don't bother with that refinement.
21536 if Chars (Argx) = Name_Off then
21537 Set_Specific_Warning_Off
21538 (Loc, Name_Buffer (1 .. Name_Len), Reason,
21539 Config => Is_Configuration_Pragma,
21540 Used => Inside_A_Generic or else In_Instance);
21542 elsif Chars (Argx) = Name_On then
21543 Set_Specific_Warning_On
21544 (Loc, Name_Buffer (1 .. Name_Len), Err);
21546 if Err then
21547 Error_Msg
21548 ("??pragma Warnings On with no matching "
21549 & "Warnings Off", Loc);
21550 end if;
21551 end if;
21552 end if;
21553 end;
21554 end if;
21555 end;
21556 end Warnings;
21558 -------------------
21559 -- Weak_External --
21560 -------------------
21562 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
21564 when Pragma_Weak_External => Weak_External : declare
21565 Ent : Entity_Id;
21567 begin
21568 GNAT_Pragma;
21569 Check_Arg_Count (1);
21570 Check_Optional_Identifier (Arg1, Name_Entity);
21571 Check_Arg_Is_Library_Level_Local_Name (Arg1);
21572 Ent := Entity (Get_Pragma_Arg (Arg1));
21574 if Rep_Item_Too_Early (Ent, N) then
21575 return;
21576 else
21577 Ent := Underlying_Type (Ent);
21578 end if;
21580 -- The only processing required is to link this item on to the
21581 -- list of rep items for the given entity. This is accomplished
21582 -- by the call to Rep_Item_Too_Late (when no error is detected
21583 -- and False is returned).
21585 if Rep_Item_Too_Late (Ent, N) then
21586 return;
21587 else
21588 Set_Has_Gigi_Rep_Item (Ent);
21589 end if;
21590 end Weak_External;
21592 -----------------------------
21593 -- Wide_Character_Encoding --
21594 -----------------------------
21596 -- pragma Wide_Character_Encoding (IDENTIFIER);
21598 when Pragma_Wide_Character_Encoding =>
21599 GNAT_Pragma;
21601 -- Nothing to do, handled in parser. Note that we do not enforce
21602 -- configuration pragma placement, this pragma can appear at any
21603 -- place in the source, allowing mixed encodings within a single
21604 -- source program.
21606 null;
21608 --------------------
21609 -- Unknown_Pragma --
21610 --------------------
21612 -- Should be impossible, since the case of an unknown pragma is
21613 -- separately processed before the case statement is entered.
21615 when Unknown_Pragma =>
21616 raise Program_Error;
21617 end case;
21619 -- AI05-0144: detect dangerous order dependence. Disabled for now,
21620 -- until AI is formally approved.
21622 -- Check_Order_Dependence;
21624 exception
21625 when Pragma_Exit => null;
21626 end Analyze_Pragma;
21628 ---------------------------------------------
21629 -- Analyze_Pre_Post_Condition_In_Decl_Part --
21630 ---------------------------------------------
21632 procedure Analyze_Pre_Post_Condition_In_Decl_Part
21633 (Prag : Node_Id;
21634 Subp_Id : Entity_Id)
21636 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (Prag));
21637 Nam : constant Name_Id := Original_Aspect_Name (Prag);
21638 Expr : Node_Id;
21640 Restore_Scope : Boolean := False;
21641 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
21643 begin
21644 -- Ensure that the subprogram and its formals are visible when analyzing
21645 -- the expression of the pragma.
21647 if not In_Open_Scopes (Subp_Id) then
21648 Restore_Scope := True;
21649 Push_Scope (Subp_Id);
21650 Install_Formals (Subp_Id);
21651 end if;
21653 -- Preanalyze the boolean expression, we treat this as a spec expression
21654 -- (i.e. similar to a default expression).
21656 Expr := Get_Pragma_Arg (Arg1);
21658 -- In ASIS mode, for a pragma generated from a source aspect, analyze
21659 -- the original aspect expression, which is shared with the generated
21660 -- pragma.
21662 if ASIS_Mode and then Present (Corresponding_Aspect (Prag)) then
21663 Expr := Expression (Corresponding_Aspect (Prag));
21664 end if;
21666 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
21668 -- For a class-wide condition, a reference to a controlling formal must
21669 -- be interpreted as having the class-wide type (or an access to such)
21670 -- so that the inherited condition can be properly applied to any
21671 -- overriding operation (see ARM12 6.6.1 (7)).
21673 if Class_Present (Prag) then
21674 Class_Wide_Condition : declare
21675 T : constant Entity_Id := Find_Dispatching_Type (Subp_Id);
21677 ACW : Entity_Id := Empty;
21678 -- Access to T'class, created if there is a controlling formal
21679 -- that is an access parameter.
21681 function Get_ACW return Entity_Id;
21682 -- If the expression has a reference to an controlling access
21683 -- parameter, create an access to T'class for the necessary
21684 -- conversions if one does not exist.
21686 function Process (N : Node_Id) return Traverse_Result;
21687 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
21688 -- aspect for a primitive subprogram of a tagged type T, a name
21689 -- that denotes a formal parameter of type T is interpreted as
21690 -- having type T'Class. Similarly, a name that denotes a formal
21691 -- accessparameter of type access-to-T is interpreted as having
21692 -- type access-to-T'Class. This ensures the expression is well-
21693 -- defined for a primitive subprogram of a type descended from T.
21694 -- Note that this replacement is not done for selector names in
21695 -- parameter associations. These carry an entity for reference
21696 -- purposes, but semantically they are just identifiers.
21698 -------------
21699 -- Get_ACW --
21700 -------------
21702 function Get_ACW return Entity_Id is
21703 Loc : constant Source_Ptr := Sloc (Prag);
21704 Decl : Node_Id;
21706 begin
21707 if No (ACW) then
21708 Decl :=
21709 Make_Full_Type_Declaration (Loc,
21710 Defining_Identifier => Make_Temporary (Loc, 'T'),
21711 Type_Definition =>
21712 Make_Access_To_Object_Definition (Loc,
21713 Subtype_Indication =>
21714 New_Occurrence_Of (Class_Wide_Type (T), Loc),
21715 All_Present => True));
21717 Insert_Before (Unit_Declaration_Node (Subp_Id), Decl);
21718 Analyze (Decl);
21719 ACW := Defining_Identifier (Decl);
21720 Freeze_Before (Unit_Declaration_Node (Subp_Id), ACW);
21721 end if;
21723 return ACW;
21724 end Get_ACW;
21726 -------------
21727 -- Process --
21728 -------------
21730 function Process (N : Node_Id) return Traverse_Result is
21731 Loc : constant Source_Ptr := Sloc (N);
21732 Typ : Entity_Id;
21734 begin
21735 if Is_Entity_Name (N)
21736 and then Present (Entity (N))
21737 and then Is_Formal (Entity (N))
21738 and then Nkind (Parent (N)) /= N_Type_Conversion
21739 and then
21740 (Nkind (Parent (N)) /= N_Parameter_Association
21741 or else N /= Selector_Name (Parent (N)))
21742 then
21743 if Etype (Entity (N)) = T then
21744 Typ := Class_Wide_Type (T);
21746 elsif Is_Access_Type (Etype (Entity (N)))
21747 and then Designated_Type (Etype (Entity (N))) = T
21748 then
21749 Typ := Get_ACW;
21750 else
21751 Typ := Empty;
21752 end if;
21754 if Present (Typ) then
21755 Rewrite (N,
21756 Make_Type_Conversion (Loc,
21757 Subtype_Mark =>
21758 New_Occurrence_Of (Typ, Loc),
21759 Expression => New_Occurrence_Of (Entity (N), Loc)));
21760 Set_Etype (N, Typ);
21761 end if;
21762 end if;
21764 return OK;
21765 end Process;
21767 procedure Replace_Type is new Traverse_Proc (Process);
21769 -- Start of processing for Class_Wide_Condition
21771 begin
21772 if not Present (T) then
21774 -- Pre'Class/Post'Class aspect cases
21776 if From_Aspect_Specification (Prag) then
21777 if Nam = Name_uPre then
21778 Error_Msg_Name_1 := Name_Pre;
21779 else
21780 Error_Msg_Name_1 := Name_Post;
21781 end if;
21783 Error_Msg_Name_2 := Name_Class;
21785 Error_Msg_N
21786 ("aspect `%''%` can only be specified for a primitive "
21787 & "operation of a tagged type",
21788 Corresponding_Aspect (Prag));
21790 -- Pre_Class, Post_Class pragma cases
21792 else
21793 if Nam = Name_uPre then
21794 Error_Msg_Name_1 := Name_Pre_Class;
21795 else
21796 Error_Msg_Name_1 := Name_Post_Class;
21797 end if;
21799 Error_Msg_N
21800 ("pragma% can only be specified for a primitive "
21801 & "operation of a tagged type",
21802 Corresponding_Aspect (Prag));
21803 end if;
21804 end if;
21806 Replace_Type (Get_Pragma_Arg (Arg1));
21807 end Class_Wide_Condition;
21808 end if;
21810 -- Remove the subprogram from the scope stack now that the pre-analysis
21811 -- of the precondition/postcondition is done.
21813 if Restore_Scope then
21814 End_Scope;
21815 end if;
21816 end Analyze_Pre_Post_Condition_In_Decl_Part;
21818 ------------------------------------------
21819 -- Analyze_Refined_Depends_In_Decl_Part --
21820 ------------------------------------------
21822 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
21823 Dependencies : List_Id := No_List;
21824 Depends : Node_Id;
21825 -- The corresponding Depends pragma along with its clauses
21827 Matched_Items : Elist_Id := No_Elist;
21828 -- A list containing the entities of all successfully matched items
21829 -- found in pragma Depends.
21831 Refinements : List_Id := No_List;
21832 -- The clauses of pragma Refined_Depends
21834 Spec_Id : Entity_Id;
21835 -- The entity of the subprogram subject to pragma Refined_Depends
21837 procedure Check_Dependency_Clause (Dep_Clause : Node_Id);
21838 -- Try to match a single dependency clause Dep_Clause against one or
21839 -- more refinement clauses found in list Refinements. Each successful
21840 -- match eliminates at least one refinement clause from Refinements.
21842 procedure Normalize_Clauses (Clauses : List_Id);
21843 -- Given a list of dependence or refinement clauses Clauses, normalize
21844 -- each clause by creating multiple dependencies with exactly one input
21845 -- and one output.
21847 procedure Report_Extra_Clauses;
21848 -- Emit an error for each extra clause found in list Refinements
21850 -----------------------------
21851 -- Check_Dependency_Clause --
21852 -----------------------------
21854 procedure Check_Dependency_Clause (Dep_Clause : Node_Id) is
21855 Dep_Input : constant Node_Id := Expression (Dep_Clause);
21856 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
21858 function Is_In_Out_State_Clause return Boolean;
21859 -- Determine whether dependence clause Dep_Clause denotes an abstract
21860 -- state that depends on itself (State => State).
21862 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
21863 -- Determine whether item Item denotes an abstract state with visible
21864 -- null refinement.
21866 procedure Match_Items
21867 (Dep_Item : Node_Id;
21868 Ref_Item : Node_Id;
21869 Matched : out Boolean);
21870 -- Try to match dependence item Dep_Item against refinement item
21871 -- Ref_Item. To match against a possible null refinement (see 2, 7),
21872 -- set Ref_Item to Empty. Flag Matched is set to True when one of
21873 -- the following conformance scenarios is in effect:
21874 -- 1) Both items denote null
21875 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
21876 -- 3) Both items denote attribute 'Result
21877 -- 4) Both items denote the same formal parameter
21878 -- 5) Both items denote the same variable
21879 -- 6) Dep_Item is an abstract state with visible null refinement
21880 -- and Ref_Item denotes null.
21881 -- 7) Dep_Item is an abstract state with visible null refinement
21882 -- and Ref_Item is Empty (special case).
21883 -- 8) Dep_Item is an abstract state with visible non-null
21884 -- refinement and Ref_Item denotes one of its constituents.
21885 -- 9) Dep_Item is an abstract state without a visible refinement
21886 -- and Ref_Item denotes the same state.
21887 -- When scenario 8 is in effect, the entity of the abstract state
21888 -- denoted by Dep_Item is added to list Refined_States.
21890 procedure Record_Item (Item_Id : Entity_Id);
21891 -- Store the entity of an item denoted by Item_Id in Matched_Items
21893 ----------------------------
21894 -- Is_In_Out_State_Clause --
21895 ----------------------------
21897 function Is_In_Out_State_Clause return Boolean is
21898 Dep_Input_Id : Entity_Id;
21899 Dep_Output_Id : Entity_Id;
21901 begin
21902 -- Detect the following clause:
21903 -- State => State
21905 if Is_Entity_Name (Dep_Input)
21906 and then Is_Entity_Name (Dep_Output)
21907 then
21908 -- Handle abstract views generated for limited with clauses
21910 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
21911 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
21913 return
21914 Ekind (Dep_Input_Id) = E_Abstract_State
21915 and then Dep_Input_Id = Dep_Output_Id;
21916 else
21917 return False;
21918 end if;
21919 end Is_In_Out_State_Clause;
21921 ---------------------------
21922 -- Is_Null_Refined_State --
21923 ---------------------------
21925 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
21926 Item_Id : Entity_Id;
21928 begin
21929 if Is_Entity_Name (Item) then
21931 -- Handle abstract views generated for limited with clauses
21933 Item_Id := Available_View (Entity_Of (Item));
21935 return Ekind (Item_Id) = E_Abstract_State
21936 and then Has_Null_Refinement (Item_Id);
21938 else
21939 return False;
21940 end if;
21941 end Is_Null_Refined_State;
21943 -----------------
21944 -- Match_Items --
21945 -----------------
21947 procedure Match_Items
21948 (Dep_Item : Node_Id;
21949 Ref_Item : Node_Id;
21950 Matched : out Boolean)
21952 Dep_Item_Id : Entity_Id;
21953 Ref_Item_Id : Entity_Id;
21955 begin
21956 -- Assume that the two items do not match
21958 Matched := False;
21960 -- A null matches null or Empty (special case)
21962 if Nkind (Dep_Item) = N_Null
21963 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
21964 then
21965 Matched := True;
21967 -- Attribute 'Result matches attribute 'Result
21969 elsif Is_Attribute_Result (Dep_Item)
21970 and then Is_Attribute_Result (Dep_Item)
21971 then
21972 Matched := True;
21974 -- Abstract states, formal parameters and variables
21976 elsif Is_Entity_Name (Dep_Item) then
21978 -- Handle abstract views generated for limited with clauses
21980 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
21982 if Ekind (Dep_Item_Id) = E_Abstract_State then
21984 -- An abstract state with visible null refinement matches
21985 -- null or Empty (special case).
21987 if Has_Null_Refinement (Dep_Item_Id)
21988 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
21989 then
21990 Record_Item (Dep_Item_Id);
21991 Matched := True;
21993 -- An abstract state with visible non-null refinement
21994 -- matches one of its constituents.
21996 elsif Has_Non_Null_Refinement (Dep_Item_Id) then
21997 if Is_Entity_Name (Ref_Item) then
21998 Ref_Item_Id := Entity_Of (Ref_Item);
22000 if Ekind_In (Ref_Item_Id, E_Abstract_State, E_Variable)
22001 and then Present (Encapsulating_State (Ref_Item_Id))
22002 and then Encapsulating_State (Ref_Item_Id) =
22003 Dep_Item_Id
22004 then
22005 Record_Item (Dep_Item_Id);
22006 Matched := True;
22007 end if;
22008 end if;
22010 -- An abstract state without a visible refinement matches
22011 -- itself.
22013 elsif Is_Entity_Name (Ref_Item)
22014 and then Entity_Of (Ref_Item) = Dep_Item_Id
22015 then
22016 Record_Item (Dep_Item_Id);
22017 Matched := True;
22018 end if;
22020 -- A formal parameter or a variable matches itself
22022 elsif Is_Entity_Name (Ref_Item)
22023 and then Entity_Of (Ref_Item) = Dep_Item_Id
22024 then
22025 Record_Item (Dep_Item_Id);
22026 Matched := True;
22027 end if;
22028 end if;
22029 end Match_Items;
22031 -----------------
22032 -- Record_Item --
22033 -----------------
22035 procedure Record_Item (Item_Id : Entity_Id) is
22036 begin
22037 if not Contains (Matched_Items, Item_Id) then
22038 Add_Item (Item_Id, Matched_Items);
22039 end if;
22040 end Record_Item;
22042 -- Local variables
22044 Clause_Matched : Boolean := False;
22045 Dummy : Boolean := False;
22046 Inputs_Match : Boolean;
22047 Next_Ref_Clause : Node_Id;
22048 Outputs_Match : Boolean;
22049 Ref_Clause : Node_Id;
22050 Ref_Input : Node_Id;
22051 Ref_Output : Node_Id;
22053 -- Start of processing for Check_Dependency_Clause
22055 begin
22056 -- Examine all refinement clauses and compare them against the
22057 -- dependence clause.
22059 Ref_Clause := First (Refinements);
22060 while Present (Ref_Clause) loop
22061 Next_Ref_Clause := Next (Ref_Clause);
22063 -- Obtain the attributes of the current refinement clause
22065 Ref_Input := Expression (Ref_Clause);
22066 Ref_Output := First (Choices (Ref_Clause));
22068 -- The current refinement clause matches the dependence clause
22069 -- when both outputs match and both inputs match. See routine
22070 -- Match_Items for all possible conformance scenarios.
22072 -- Depends Dep_Output => Dep_Input
22073 -- ^ ^
22074 -- match ? match ?
22075 -- v v
22076 -- Refined_Depends Ref_Output => Ref_Input
22078 Match_Items
22079 (Dep_Item => Dep_Input,
22080 Ref_Item => Ref_Input,
22081 Matched => Inputs_Match);
22083 Match_Items
22084 (Dep_Item => Dep_Output,
22085 Ref_Item => Ref_Output,
22086 Matched => Outputs_Match);
22088 -- An In_Out state clause may be matched against a refinement with
22089 -- a null input or null output as long as the non-null side of the
22090 -- relation contains a valid constituent of the In_Out_State.
22092 if Is_In_Out_State_Clause then
22094 -- Depends => (State => State)
22095 -- Refined_Depends => (null => Constit) -- OK
22097 if Inputs_Match
22098 and then not Outputs_Match
22099 and then Nkind (Ref_Output) = N_Null
22100 then
22101 Outputs_Match := True;
22102 end if;
22104 -- Depends => (State => State)
22105 -- Refined_Depends => (Constit => null) -- OK
22107 if not Inputs_Match
22108 and then Outputs_Match
22109 and then Nkind (Ref_Input) = N_Null
22110 then
22111 Inputs_Match := True;
22112 end if;
22113 end if;
22115 -- The current refinement clause is legally constructed following
22116 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
22117 -- the pool of candidates. The seach continues because a single
22118 -- dependence clause may have multiple matching refinements.
22120 if Inputs_Match and then Outputs_Match then
22121 Clause_Matched := True;
22122 Remove (Ref_Clause);
22123 end if;
22125 Ref_Clause := Next_Ref_Clause;
22126 end loop;
22128 -- Depending on the order or composition of refinement clauses, an
22129 -- In_Out state clause may not be directly refinable.
22131 -- Depends => ((Output, State) => (Input, State))
22132 -- Refined_State => (State => (Constit_1, Constit_2))
22133 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
22135 -- Matching normalized clause (State => State) fails because there is
22136 -- no direct refinement capable of satisfying this relation. Another
22137 -- similar case arises when clauses (Constit_1 => Input) and (Output
22138 -- => Constit_2) are matched first, leaving no candidates for clause
22139 -- (State => State). Both scenarios are legal as long as one of the
22140 -- previous clauses mentioned a valid constituent of State.
22142 if not Clause_Matched
22143 and then Is_In_Out_State_Clause
22144 and then
22145 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
22146 then
22147 Clause_Matched := True;
22148 end if;
22150 -- A clause where the input is an abstract state with visible null
22151 -- refinement is implicitly matched when the output has already been
22152 -- matched in a previous clause.
22154 -- Depends => (Output => State) -- implicitly OK
22155 -- Refined_State => (State => null)
22156 -- Refined_Depends => (Output => ...)
22158 if not Clause_Matched
22159 and then Is_Null_Refined_State (Dep_Input)
22160 and then Is_Entity_Name (Dep_Output)
22161 and then
22162 Contains (Matched_Items, Available_View (Entity_Of (Dep_Output)))
22163 then
22164 Clause_Matched := True;
22165 end if;
22167 -- A clause where the output is an abstract state with visible null
22168 -- refinement is implicitly matched when the input has already been
22169 -- matched in a previous clause.
22171 -- Depends => (State => Input) -- implicitly OK
22172 -- Refined_State => (State => null)
22173 -- Refined_Depends => (... => Input)
22175 if not Clause_Matched
22176 and then Is_Null_Refined_State (Dep_Output)
22177 and then Is_Entity_Name (Dep_Input)
22178 and then
22179 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
22180 then
22181 Clause_Matched := True;
22182 end if;
22184 -- At this point either all refinement clauses have been examined or
22185 -- pragma Refined_Depends contains a solitary null. Only an abstract
22186 -- state with null refinement can possibly match these cases.
22188 -- Depends => (State => null)
22189 -- Refined_State => (State => null)
22190 -- Refined_Depends => null -- OK
22192 if not Clause_Matched then
22193 Match_Items
22194 (Dep_Item => Dep_Input,
22195 Ref_Item => Empty,
22196 Matched => Inputs_Match);
22198 Match_Items
22199 (Dep_Item => Dep_Output,
22200 Ref_Item => Empty,
22201 Matched => Outputs_Match);
22203 Clause_Matched := Inputs_Match and Outputs_Match;
22204 end if;
22206 -- If the contents of Refined_Depends are legal, then the current
22207 -- dependence clause should be satisfied either by an explicit match
22208 -- or by one of the special cases.
22210 if not Clause_Matched then
22211 SPARK_Msg_NE
22212 ("dependence clause of subprogram & has no matching refinement "
22213 & "in body", Dep_Clause, Spec_Id);
22214 end if;
22215 end Check_Dependency_Clause;
22217 -----------------------
22218 -- Normalize_Clauses --
22219 -----------------------
22221 procedure Normalize_Clauses (Clauses : List_Id) is
22222 procedure Normalize_Inputs (Clause : Node_Id);
22223 -- Normalize clause Clause by creating multiple clauses for each
22224 -- input item of Clause. It is assumed that Clause has exactly one
22225 -- output. The transformation is as follows:
22227 -- Output => (Input_1, Input_2) -- original
22229 -- Output => Input_1 -- normalizations
22230 -- Output => Input_2
22232 ----------------------
22233 -- Normalize_Inputs --
22234 ----------------------
22236 procedure Normalize_Inputs (Clause : Node_Id) is
22237 Inputs : constant Node_Id := Expression (Clause);
22238 Loc : constant Source_Ptr := Sloc (Clause);
22239 Output : constant List_Id := Choices (Clause);
22240 Last_Input : Node_Id;
22241 Input : Node_Id;
22242 New_Clause : Node_Id;
22243 Next_Input : Node_Id;
22245 begin
22246 -- Normalization is performed only when the original clause has
22247 -- more than one input. Multiple inputs appear as an aggregate.
22249 if Nkind (Inputs) = N_Aggregate then
22250 Last_Input := Last (Expressions (Inputs));
22252 -- Create a new clause for each input
22254 Input := First (Expressions (Inputs));
22255 while Present (Input) loop
22256 Next_Input := Next (Input);
22258 -- Unhook the current input from the original input list
22259 -- because it will be relocated to a new clause.
22261 Remove (Input);
22263 -- Special processing for the last input. At this point the
22264 -- original aggregate has been stripped down to one element.
22265 -- Replace the aggregate by the element itself.
22267 if Input = Last_Input then
22268 Rewrite (Inputs, Input);
22270 -- Generate a clause of the form:
22271 -- Output => Input
22273 else
22274 New_Clause :=
22275 Make_Component_Association (Loc,
22276 Choices => New_Copy_List_Tree (Output),
22277 Expression => Input);
22279 -- The new clause contains replicated content that has
22280 -- already been analyzed, mark the clause as analyzed.
22282 Set_Analyzed (New_Clause);
22283 Insert_After (Clause, New_Clause);
22284 end if;
22286 Input := Next_Input;
22287 end loop;
22288 end if;
22289 end Normalize_Inputs;
22291 -- Local variables
22293 Clause : Node_Id;
22295 -- Start of processing for Normalize_Clauses
22297 begin
22298 Clause := First (Clauses);
22299 while Present (Clause) loop
22300 Normalize_Inputs (Clause);
22301 Next (Clause);
22302 end loop;
22303 end Normalize_Clauses;
22305 --------------------------
22306 -- Report_Extra_Clauses --
22307 --------------------------
22309 procedure Report_Extra_Clauses is
22310 Clause : Node_Id;
22312 begin
22313 if Present (Refinements) then
22314 Clause := First (Refinements);
22315 while Present (Clause) loop
22317 -- Do not complain about a null input refinement, since a null
22318 -- input legitimately matches anything.
22320 if Nkind (Clause) /= N_Component_Association
22321 or else Nkind (Expression (Clause)) /= N_Null
22322 then
22323 SPARK_Msg_N
22324 ("unmatched or extra clause in dependence refinement",
22325 Clause);
22326 end if;
22328 Next (Clause);
22329 end loop;
22330 end if;
22331 end Report_Extra_Clauses;
22333 -- Local variables
22335 Body_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
22336 Errors : constant Nat := Serious_Errors_Detected;
22337 Refs : constant Node_Id :=
22338 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
22339 Clause : Node_Id;
22340 Deps : Node_Id;
22342 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
22344 begin
22345 if Nkind (Body_Decl) = N_Subprogram_Body_Stub then
22346 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
22347 else
22348 Spec_Id := Corresponding_Spec (Body_Decl);
22349 end if;
22351 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
22353 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
22354 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
22356 if No (Depends) then
22357 SPARK_Msg_NE
22358 ("useless refinement, declaration of subprogram & lacks aspect or "
22359 & "pragma Depends", N, Spec_Id);
22360 return;
22361 end if;
22363 Deps := Get_Pragma_Arg (First (Pragma_Argument_Associations (Depends)));
22365 -- A null dependency relation renders the refinement useless because it
22366 -- cannot possibly mention abstract states with visible refinement. Note
22367 -- that the inverse is not true as states may be refined to null
22368 -- (SPARK RM 7.2.5(2)).
22370 if Nkind (Deps) = N_Null then
22371 SPARK_Msg_NE
22372 ("useless refinement, subprogram & does not depend on abstract "
22373 & "state with visible refinement", N, Spec_Id);
22374 return;
22375 end if;
22377 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
22378 -- This ensures that the categorization of all refined dependency items
22379 -- is consistent with their role.
22381 Analyze_Depends_In_Decl_Part (N);
22383 -- Do not match dependencies against refinements if Refined_Depends is
22384 -- illegal to avoid emitting misleading error. Matching is disabled in
22385 -- ASIS because clauses are not normalized as this is a tree altering
22386 -- activity similar to expansion.
22388 if Serious_Errors_Detected = Errors and then not ASIS_Mode then
22390 -- Multiple dependency clauses appear as component associations of an
22391 -- aggregate. Note that the clauses are copied because the algorithm
22392 -- modifies them and this should not be visible in Depends.
22394 pragma Assert (Nkind (Deps) = N_Aggregate);
22395 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
22396 Normalize_Clauses (Dependencies);
22398 if Nkind (Refs) = N_Null then
22399 Refinements := No_List;
22401 -- Multiple dependency clauses appear as component associations of an
22402 -- aggregate. Note that the clauses are copied because the algorithm
22403 -- modifies them and this should not be visible in Refined_Depends.
22405 else pragma Assert (Nkind (Refs) = N_Aggregate);
22406 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
22407 Normalize_Clauses (Refinements);
22408 end if;
22410 -- At this point the clauses of pragmas Depends and Refined_Depends
22411 -- have been normalized into simple dependencies between one output
22412 -- and one input. Examine all clauses of pragma Depends looking for
22413 -- matching clauses in pragma Refined_Depends.
22415 Clause := First (Dependencies);
22416 while Present (Clause) loop
22417 Check_Dependency_Clause (Clause);
22418 Next (Clause);
22419 end loop;
22421 if Serious_Errors_Detected = Errors then
22422 Report_Extra_Clauses;
22423 end if;
22424 end if;
22425 end Analyze_Refined_Depends_In_Decl_Part;
22427 -----------------------------------------
22428 -- Analyze_Refined_Global_In_Decl_Part --
22429 -----------------------------------------
22431 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
22432 Global : Node_Id;
22433 -- The corresponding Global pragma
22435 Has_In_State : Boolean := False;
22436 Has_In_Out_State : Boolean := False;
22437 Has_Out_State : Boolean := False;
22438 Has_Proof_In_State : Boolean := False;
22439 -- These flags are set when the corresponding Global pragma has a state
22440 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
22441 -- refinement.
22443 Has_Null_State : Boolean := False;
22444 -- This flag is set when the corresponding Global pragma has at least
22445 -- one state with a null refinement.
22447 In_Constits : Elist_Id := No_Elist;
22448 In_Out_Constits : Elist_Id := No_Elist;
22449 Out_Constits : Elist_Id := No_Elist;
22450 Proof_In_Constits : Elist_Id := No_Elist;
22451 -- These lists contain the entities of all Input, In_Out, Output and
22452 -- Proof_In constituents that appear in Refined_Global and participate
22453 -- in state refinement.
22455 In_Items : Elist_Id := No_Elist;
22456 In_Out_Items : Elist_Id := No_Elist;
22457 Out_Items : Elist_Id := No_Elist;
22458 Proof_In_Items : Elist_Id := No_Elist;
22459 -- These list contain the entities of all Input, In_Out, Output and
22460 -- Proof_In items defined in the corresponding Global pragma.
22462 procedure Check_In_Out_States;
22463 -- Determine whether the corresponding Global pragma mentions In_Out
22464 -- states with visible refinement and if so, ensure that one of the
22465 -- following completions apply to the constituents of the state:
22466 -- 1) there is at least one constituent of mode In_Out
22467 -- 2) there is at least one Input and one Output constituent
22468 -- 3) not all constituents are present and one of them is of mode
22469 -- Output.
22470 -- This routine may remove elements from In_Constits, In_Out_Constits,
22471 -- Out_Constits and Proof_In_Constits.
22473 procedure Check_Input_States;
22474 -- Determine whether the corresponding Global pragma mentions Input
22475 -- states with visible refinement and if so, ensure that at least one of
22476 -- its constituents appears as an Input item in Refined_Global.
22477 -- This routine may remove elements from In_Constits, In_Out_Constits,
22478 -- Out_Constits and Proof_In_Constits.
22480 procedure Check_Output_States;
22481 -- Determine whether the corresponding Global pragma mentions Output
22482 -- states with visible refinement and if so, ensure that all of its
22483 -- constituents appear as Output items in Refined_Global.
22484 -- This routine may remove elements from In_Constits, In_Out_Constits,
22485 -- Out_Constits and Proof_In_Constits.
22487 procedure Check_Proof_In_States;
22488 -- Determine whether the corresponding Global pragma mentions Proof_In
22489 -- states with visible refinement and if so, ensure that at least one of
22490 -- its constituents appears as a Proof_In item in Refined_Global.
22491 -- This routine may remove elements from In_Constits, In_Out_Constits,
22492 -- Out_Constits and Proof_In_Constits.
22494 procedure Check_Refined_Global_List
22495 (List : Node_Id;
22496 Global_Mode : Name_Id := Name_Input);
22497 -- Verify the legality of a single global list declaration. Global_Mode
22498 -- denotes the current mode in effect.
22500 function Present_Then_Remove
22501 (List : Elist_Id;
22502 Item : Entity_Id) return Boolean;
22503 -- Search List for a particular entity Item. If Item has been found,
22504 -- remove it from List. This routine is used to strip lists In_Constits,
22505 -- In_Out_Constits and Out_Constits of valid constituents.
22507 procedure Report_Extra_Constituents;
22508 -- Emit an error for each constituent found in lists In_Constits,
22509 -- In_Out_Constits and Out_Constits.
22511 -------------------------
22512 -- Check_In_Out_States --
22513 -------------------------
22515 procedure Check_In_Out_States is
22516 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22517 -- Determine whether one of the following coverage scenarios is in
22518 -- effect:
22519 -- 1) there is at least one constituent of mode In_Out
22520 -- 2) there is at least one Input and one Output constituent
22521 -- 3) not all constituents are present and one of them is of mode
22522 -- Output.
22523 -- If this is not the case, emit an error.
22525 -----------------------------
22526 -- Check_Constituent_Usage --
22527 -----------------------------
22529 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22530 Constit_Elmt : Elmt_Id;
22531 Constit_Id : Entity_Id;
22532 Has_Missing : Boolean := False;
22533 In_Out_Seen : Boolean := False;
22534 In_Seen : Boolean := False;
22535 Out_Seen : Boolean := False;
22537 begin
22538 -- Process all the constituents of the state and note their modes
22539 -- within the global refinement.
22541 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22542 while Present (Constit_Elmt) loop
22543 Constit_Id := Node (Constit_Elmt);
22545 if Present_Then_Remove (In_Constits, Constit_Id) then
22546 In_Seen := True;
22548 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
22549 In_Out_Seen := True;
22551 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
22552 Out_Seen := True;
22554 -- A Proof_In constituent cannot participate in the completion
22555 -- of an Output state (SPARK RM 7.2.4(5)).
22557 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id) then
22558 Error_Msg_Name_1 := Chars (State_Id);
22559 SPARK_Msg_NE
22560 ("constituent & of state % must have mode Input, In_Out "
22561 & "or Output in global refinement",
22562 N, Constit_Id);
22564 else
22565 Has_Missing := True;
22566 end if;
22568 Next_Elmt (Constit_Elmt);
22569 end loop;
22571 -- A single In_Out constituent is a valid completion
22573 if In_Out_Seen then
22574 null;
22576 -- A pair of one Input and one Output constituent is a valid
22577 -- completion.
22579 elsif In_Seen and then Out_Seen then
22580 null;
22582 -- A single Output constituent is a valid completion only when
22583 -- some of the other constituents are missing (SPARK RM 7.2.4(5)).
22585 elsif Has_Missing and then Out_Seen then
22586 null;
22588 else
22589 SPARK_Msg_NE
22590 ("global refinement of state & redefines the mode of its "
22591 & "constituents", N, State_Id);
22592 end if;
22593 end Check_Constituent_Usage;
22595 -- Local variables
22597 Item_Elmt : Elmt_Id;
22598 Item_Id : Entity_Id;
22600 -- Start of processing for Check_In_Out_States
22602 begin
22603 -- Inspect the In_Out items of the corresponding Global pragma
22604 -- looking for a state with a visible refinement.
22606 if Has_In_Out_State and then Present (In_Out_Items) then
22607 Item_Elmt := First_Elmt (In_Out_Items);
22608 while Present (Item_Elmt) loop
22609 Item_Id := Node (Item_Elmt);
22611 -- Ensure that one of the three coverage variants is satisfied
22613 if Ekind (Item_Id) = E_Abstract_State
22614 and then Has_Non_Null_Refinement (Item_Id)
22615 then
22616 Check_Constituent_Usage (Item_Id);
22617 end if;
22619 Next_Elmt (Item_Elmt);
22620 end loop;
22621 end if;
22622 end Check_In_Out_States;
22624 ------------------------
22625 -- Check_Input_States --
22626 ------------------------
22628 procedure Check_Input_States is
22629 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22630 -- Determine whether at least one constituent of state State_Id with
22631 -- visible refinement is used and has mode Input. Ensure that the
22632 -- remaining constituents do not have In_Out, Output or Proof_In
22633 -- modes.
22635 -----------------------------
22636 -- Check_Constituent_Usage --
22637 -----------------------------
22639 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22640 Constit_Elmt : Elmt_Id;
22641 Constit_Id : Entity_Id;
22642 In_Seen : Boolean := False;
22644 begin
22645 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22646 while Present (Constit_Elmt) loop
22647 Constit_Id := Node (Constit_Elmt);
22649 -- At least one of the constituents appears as an Input
22651 if Present_Then_Remove (In_Constits, Constit_Id) then
22652 In_Seen := True;
22654 -- The constituent appears in the global refinement, but has
22655 -- mode In_Out, Output or Proof_In (SPARK RM 7.2.4(5)).
22657 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
22658 or else Present_Then_Remove (Out_Constits, Constit_Id)
22659 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
22660 then
22661 Error_Msg_Name_1 := Chars (State_Id);
22662 SPARK_Msg_NE
22663 ("constituent & of state % must have mode Input in global "
22664 & "refinement", N, Constit_Id);
22665 end if;
22667 Next_Elmt (Constit_Elmt);
22668 end loop;
22670 -- Not one of the constituents appeared as Input
22672 if not In_Seen then
22673 SPARK_Msg_NE
22674 ("global refinement of state & must include at least one "
22675 & "constituent of mode Input", N, State_Id);
22676 end if;
22677 end Check_Constituent_Usage;
22679 -- Local variables
22681 Item_Elmt : Elmt_Id;
22682 Item_Id : Entity_Id;
22684 -- Start of processing for Check_Input_States
22686 begin
22687 -- Inspect the Input items of the corresponding Global pragma
22688 -- looking for a state with a visible refinement.
22690 if Has_In_State and then Present (In_Items) then
22691 Item_Elmt := First_Elmt (In_Items);
22692 while Present (Item_Elmt) loop
22693 Item_Id := Node (Item_Elmt);
22695 -- Ensure that at least one of the constituents is utilized and
22696 -- is of mode Input.
22698 if Ekind (Item_Id) = E_Abstract_State
22699 and then Has_Non_Null_Refinement (Item_Id)
22700 then
22701 Check_Constituent_Usage (Item_Id);
22702 end if;
22704 Next_Elmt (Item_Elmt);
22705 end loop;
22706 end if;
22707 end Check_Input_States;
22709 -------------------------
22710 -- Check_Output_States --
22711 -------------------------
22713 procedure Check_Output_States is
22714 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22715 -- Determine whether all constituents of state State_Id with visible
22716 -- refinement are used and have mode Output. Emit an error if this is
22717 -- not the case.
22719 -----------------------------
22720 -- Check_Constituent_Usage --
22721 -----------------------------
22723 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22724 Constit_Elmt : Elmt_Id;
22725 Constit_Id : Entity_Id;
22726 Posted : Boolean := False;
22728 begin
22729 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22730 while Present (Constit_Elmt) loop
22731 Constit_Id := Node (Constit_Elmt);
22733 if Present_Then_Remove (Out_Constits, Constit_Id) then
22734 null;
22736 -- The constituent appears in the global refinement, but has
22737 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
22739 elsif Present_Then_Remove (In_Constits, Constit_Id)
22740 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
22741 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
22742 then
22743 Error_Msg_Name_1 := Chars (State_Id);
22744 SPARK_Msg_NE
22745 ("constituent & of state % must have mode Output in "
22746 & "global refinement", N, Constit_Id);
22748 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
22750 else
22751 if not Posted then
22752 Posted := True;
22753 SPARK_Msg_NE
22754 ("output state & must be replaced by all its "
22755 & "constituents in global refinement", N, State_Id);
22756 end if;
22758 SPARK_Msg_NE
22759 ("\constituent & is missing in output list",
22760 N, Constit_Id);
22761 end if;
22763 Next_Elmt (Constit_Elmt);
22764 end loop;
22765 end Check_Constituent_Usage;
22767 -- Local variables
22769 Item_Elmt : Elmt_Id;
22770 Item_Id : Entity_Id;
22772 -- Start of processing for Check_Output_States
22774 begin
22775 -- Inspect the Output items of the corresponding Global pragma
22776 -- looking for a state with a visible refinement.
22778 if Has_Out_State and then Present (Out_Items) then
22779 Item_Elmt := First_Elmt (Out_Items);
22780 while Present (Item_Elmt) loop
22781 Item_Id := Node (Item_Elmt);
22783 -- Ensure that all of the constituents are utilized and they
22784 -- have mode Output.
22786 if Ekind (Item_Id) = E_Abstract_State
22787 and then Has_Non_Null_Refinement (Item_Id)
22788 then
22789 Check_Constituent_Usage (Item_Id);
22790 end if;
22792 Next_Elmt (Item_Elmt);
22793 end loop;
22794 end if;
22795 end Check_Output_States;
22797 ---------------------------
22798 -- Check_Proof_In_States --
22799 ---------------------------
22801 procedure Check_Proof_In_States is
22802 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22803 -- Determine whether at least one constituent of state State_Id with
22804 -- visible refinement is used and has mode Proof_In. Ensure that the
22805 -- remaining constituents do not have Input, In_Out or Output modes.
22807 -----------------------------
22808 -- Check_Constituent_Usage --
22809 -----------------------------
22811 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22812 Constit_Elmt : Elmt_Id;
22813 Constit_Id : Entity_Id;
22814 Proof_In_Seen : Boolean := False;
22816 begin
22817 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22818 while Present (Constit_Elmt) loop
22819 Constit_Id := Node (Constit_Elmt);
22821 -- At least one of the constituents appears as Proof_In
22823 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
22824 Proof_In_Seen := True;
22826 -- The constituent appears in the global refinement, but has
22827 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
22829 elsif Present_Then_Remove (In_Constits, Constit_Id)
22830 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
22831 or else Present_Then_Remove (Out_Constits, Constit_Id)
22832 then
22833 Error_Msg_Name_1 := Chars (State_Id);
22834 SPARK_Msg_NE
22835 ("constituent & of state % must have mode Proof_In in "
22836 & "global refinement", N, Constit_Id);
22837 end if;
22839 Next_Elmt (Constit_Elmt);
22840 end loop;
22842 -- Not one of the constituents appeared as Proof_In
22844 if not Proof_In_Seen then
22845 SPARK_Msg_NE
22846 ("global refinement of state & must include at least one "
22847 & "constituent of mode Proof_In", N, State_Id);
22848 end if;
22849 end Check_Constituent_Usage;
22851 -- Local variables
22853 Item_Elmt : Elmt_Id;
22854 Item_Id : Entity_Id;
22856 -- Start of processing for Check_Proof_In_States
22858 begin
22859 -- Inspect the Proof_In items of the corresponding Global pragma
22860 -- looking for a state with a visible refinement.
22862 if Has_Proof_In_State and then Present (Proof_In_Items) then
22863 Item_Elmt := First_Elmt (Proof_In_Items);
22864 while Present (Item_Elmt) loop
22865 Item_Id := Node (Item_Elmt);
22867 -- Ensure that at least one of the constituents is utilized and
22868 -- is of mode Proof_In
22870 if Ekind (Item_Id) = E_Abstract_State
22871 and then Has_Non_Null_Refinement (Item_Id)
22872 then
22873 Check_Constituent_Usage (Item_Id);
22874 end if;
22876 Next_Elmt (Item_Elmt);
22877 end loop;
22878 end if;
22879 end Check_Proof_In_States;
22881 -------------------------------
22882 -- Check_Refined_Global_List --
22883 -------------------------------
22885 procedure Check_Refined_Global_List
22886 (List : Node_Id;
22887 Global_Mode : Name_Id := Name_Input)
22889 procedure Check_Refined_Global_Item
22890 (Item : Node_Id;
22891 Global_Mode : Name_Id);
22892 -- Verify the legality of a single global item declaration. Parameter
22893 -- Global_Mode denotes the current mode in effect.
22895 -------------------------------
22896 -- Check_Refined_Global_Item --
22897 -------------------------------
22899 procedure Check_Refined_Global_Item
22900 (Item : Node_Id;
22901 Global_Mode : Name_Id)
22903 Item_Id : constant Entity_Id := Entity_Of (Item);
22905 procedure Inconsistent_Mode_Error (Expect : Name_Id);
22906 -- Issue a common error message for all mode mismatches. Expect
22907 -- denotes the expected mode.
22909 -----------------------------
22910 -- Inconsistent_Mode_Error --
22911 -----------------------------
22913 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
22914 begin
22915 SPARK_Msg_NE
22916 ("global item & has inconsistent modes", Item, Item_Id);
22918 Error_Msg_Name_1 := Global_Mode;
22919 Error_Msg_Name_2 := Expect;
22920 SPARK_Msg_N ("\expected mode %, found mode %", Item);
22921 end Inconsistent_Mode_Error;
22923 -- Start of processing for Check_Refined_Global_Item
22925 begin
22926 -- When the state or variable acts as a constituent of another
22927 -- state with a visible refinement, collect it for the state
22928 -- completeness checks performed later on.
22930 if Present (Encapsulating_State (Item_Id))
22931 and then Has_Visible_Refinement (Encapsulating_State (Item_Id))
22932 then
22933 if Global_Mode = Name_Input then
22934 Add_Item (Item_Id, In_Constits);
22936 elsif Global_Mode = Name_In_Out then
22937 Add_Item (Item_Id, In_Out_Constits);
22939 elsif Global_Mode = Name_Output then
22940 Add_Item (Item_Id, Out_Constits);
22942 elsif Global_Mode = Name_Proof_In then
22943 Add_Item (Item_Id, Proof_In_Constits);
22944 end if;
22946 -- When not a constituent, ensure that both occurrences of the
22947 -- item in pragmas Global and Refined_Global match.
22949 elsif Contains (In_Items, Item_Id) then
22950 if Global_Mode /= Name_Input then
22951 Inconsistent_Mode_Error (Name_Input);
22952 end if;
22954 elsif Contains (In_Out_Items, Item_Id) then
22955 if Global_Mode /= Name_In_Out then
22956 Inconsistent_Mode_Error (Name_In_Out);
22957 end if;
22959 elsif Contains (Out_Items, Item_Id) then
22960 if Global_Mode /= Name_Output then
22961 Inconsistent_Mode_Error (Name_Output);
22962 end if;
22964 elsif Contains (Proof_In_Items, Item_Id) then
22965 null;
22967 -- The item does not appear in the corresponding Global pragma,
22968 -- it must be an extra (SPARK RM 7.2.4(3)).
22970 else
22971 SPARK_Msg_NE ("extra global item &", Item, Item_Id);
22972 end if;
22973 end Check_Refined_Global_Item;
22975 -- Local variables
22977 Item : Node_Id;
22979 -- Start of processing for Check_Refined_Global_List
22981 begin
22982 if Nkind (List) = N_Null then
22983 null;
22985 -- Single global item declaration
22987 elsif Nkind_In (List, N_Expanded_Name,
22988 N_Identifier,
22989 N_Selected_Component)
22990 then
22991 Check_Refined_Global_Item (List, Global_Mode);
22993 -- Simple global list or moded global list declaration
22995 elsif Nkind (List) = N_Aggregate then
22997 -- The declaration of a simple global list appear as a collection
22998 -- of expressions.
23000 if Present (Expressions (List)) then
23001 Item := First (Expressions (List));
23002 while Present (Item) loop
23003 Check_Refined_Global_Item (Item, Global_Mode);
23005 Next (Item);
23006 end loop;
23008 -- The declaration of a moded global list appears as a collection
23009 -- of component associations where individual choices denote
23010 -- modes.
23012 elsif Present (Component_Associations (List)) then
23013 Item := First (Component_Associations (List));
23014 while Present (Item) loop
23015 Check_Refined_Global_List
23016 (List => Expression (Item),
23017 Global_Mode => Chars (First (Choices (Item))));
23019 Next (Item);
23020 end loop;
23022 -- Invalid tree
23024 else
23025 raise Program_Error;
23026 end if;
23028 -- Invalid list
23030 else
23031 raise Program_Error;
23032 end if;
23033 end Check_Refined_Global_List;
23035 -------------------------
23036 -- Present_Then_Remove --
23037 -------------------------
23039 function Present_Then_Remove
23040 (List : Elist_Id;
23041 Item : Entity_Id) return Boolean
23043 Elmt : Elmt_Id;
23045 begin
23046 if Present (List) then
23047 Elmt := First_Elmt (List);
23048 while Present (Elmt) loop
23049 if Node (Elmt) = Item then
23050 Remove_Elmt (List, Elmt);
23051 return True;
23052 end if;
23054 Next_Elmt (Elmt);
23055 end loop;
23056 end if;
23058 return False;
23059 end Present_Then_Remove;
23061 -------------------------------
23062 -- Report_Extra_Constituents --
23063 -------------------------------
23065 procedure Report_Extra_Constituents is
23066 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
23067 -- Emit an error for every element of List
23069 ---------------------------------------
23070 -- Report_Extra_Constituents_In_List --
23071 ---------------------------------------
23073 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
23074 Constit_Elmt : Elmt_Id;
23076 begin
23077 if Present (List) then
23078 Constit_Elmt := First_Elmt (List);
23079 while Present (Constit_Elmt) loop
23080 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
23081 Next_Elmt (Constit_Elmt);
23082 end loop;
23083 end if;
23084 end Report_Extra_Constituents_In_List;
23086 -- Start of processing for Report_Extra_Constituents
23088 begin
23089 Report_Extra_Constituents_In_List (In_Constits);
23090 Report_Extra_Constituents_In_List (In_Out_Constits);
23091 Report_Extra_Constituents_In_List (Out_Constits);
23092 Report_Extra_Constituents_In_List (Proof_In_Constits);
23093 end Report_Extra_Constituents;
23095 -- Local variables
23097 Body_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
23098 Errors : constant Nat := Serious_Errors_Detected;
23099 Items : constant Node_Id :=
23100 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
23101 Spec_Id : Entity_Id;
23103 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
23105 begin
23106 if Nkind (Body_Decl) = N_Subprogram_Body_Stub then
23107 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
23108 else
23109 Spec_Id := Corresponding_Spec (Body_Decl);
23110 end if;
23112 Global := Get_Pragma (Spec_Id, Pragma_Global);
23114 -- The subprogram declaration lacks pragma Global. This renders
23115 -- Refined_Global useless as there is nothing to refine.
23117 if No (Global) then
23118 SPARK_Msg_NE
23119 ("useless refinement, declaration of subprogram & lacks aspect or "
23120 & "pragma Global", N, Spec_Id);
23121 return;
23122 end if;
23124 -- Extract all relevant items from the corresponding Global pragma
23126 Collect_Global_Items
23127 (Prag => Global,
23128 In_Items => In_Items,
23129 In_Out_Items => In_Out_Items,
23130 Out_Items => Out_Items,
23131 Proof_In_Items => Proof_In_Items,
23132 Has_In_State => Has_In_State,
23133 Has_In_Out_State => Has_In_Out_State,
23134 Has_Out_State => Has_Out_State,
23135 Has_Proof_In_State => Has_Proof_In_State,
23136 Has_Null_State => Has_Null_State);
23138 -- Corresponding Global pragma must mention at least one state witha
23139 -- visible refinement at the point Refined_Global is processed. States
23140 -- with null refinements need Refined_Global pragma (SPARK RM 7.2.4(2)).
23142 if not Has_In_State
23143 and then not Has_In_Out_State
23144 and then not Has_Out_State
23145 and then not Has_Proof_In_State
23146 and then not Has_Null_State
23147 then
23148 SPARK_Msg_NE
23149 ("useless refinement, subprogram & does not depend on abstract "
23150 & "state with visible refinement", N, Spec_Id);
23151 return;
23152 end if;
23154 -- The global refinement of inputs and outputs cannot be null when the
23155 -- corresponding Global pragma contains at least one item except in the
23156 -- case where we have states with null refinements.
23158 if Nkind (Items) = N_Null
23159 and then
23160 (Present (In_Items)
23161 or else Present (In_Out_Items)
23162 or else Present (Out_Items)
23163 or else Present (Proof_In_Items))
23164 and then not Has_Null_State
23165 then
23166 SPARK_Msg_NE
23167 ("refinement cannot be null, subprogram & has global items",
23168 N, Spec_Id);
23169 return;
23170 end if;
23172 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
23173 -- This ensures that the categorization of all refined global items is
23174 -- consistent with their role.
23176 Analyze_Global_In_Decl_Part (N);
23178 -- Perform all refinement checks with respect to completeness and mode
23179 -- matching.
23181 if Serious_Errors_Detected = Errors then
23182 Check_Refined_Global_List (Items);
23183 end if;
23185 -- For Input states with visible refinement, at least one constituent
23186 -- must be used as an Input in the global refinement.
23188 if Serious_Errors_Detected = Errors then
23189 Check_Input_States;
23190 end if;
23192 -- Verify all possible completion variants for In_Out states with
23193 -- visible refinement.
23195 if Serious_Errors_Detected = Errors then
23196 Check_In_Out_States;
23197 end if;
23199 -- For Output states with visible refinement, all constituents must be
23200 -- used as Outputs in the global refinement.
23202 if Serious_Errors_Detected = Errors then
23203 Check_Output_States;
23204 end if;
23206 -- For Proof_In states with visible refinement, at least one constituent
23207 -- must be used as Proof_In in the global refinement.
23209 if Serious_Errors_Detected = Errors then
23210 Check_Proof_In_States;
23211 end if;
23213 -- Emit errors for all constituents that belong to other states with
23214 -- visible refinement that do not appear in Global.
23216 if Serious_Errors_Detected = Errors then
23217 Report_Extra_Constituents;
23218 end if;
23219 end Analyze_Refined_Global_In_Decl_Part;
23221 ----------------------------------------
23222 -- Analyze_Refined_State_In_Decl_Part --
23223 ----------------------------------------
23225 procedure Analyze_Refined_State_In_Decl_Part (N : Node_Id) is
23226 Available_States : Elist_Id := No_Elist;
23227 -- A list of all abstract states defined in the package declaration that
23228 -- are available for refinement. The list is used to report unrefined
23229 -- states.
23231 Body_Id : Entity_Id;
23232 -- The body entity of the package subject to pragma Refined_State
23234 Body_States : Elist_Id := No_Elist;
23235 -- A list of all hidden states that appear in the body of the related
23236 -- package. The list is used to report unused hidden states.
23238 Constituents_Seen : Elist_Id := No_Elist;
23239 -- A list that contains all constituents processed so far. The list is
23240 -- used to detect multiple uses of the same constituent.
23242 Refined_States_Seen : Elist_Id := No_Elist;
23243 -- A list that contains all refined states processed so far. The list is
23244 -- used to detect duplicate refinements.
23246 Spec_Id : Entity_Id;
23247 -- The spec entity of the package subject to pragma Refined_State
23249 procedure Analyze_Refinement_Clause (Clause : Node_Id);
23250 -- Perform full analysis of a single refinement clause
23252 function Collect_Body_States (Pack_Id : Entity_Id) return Elist_Id;
23253 -- Gather the entities of all abstract states and variables declared in
23254 -- the body state space of package Pack_Id.
23256 procedure Report_Unrefined_States (States : Elist_Id);
23257 -- Emit errors for all unrefined abstract states found in list States
23259 procedure Report_Unused_States (States : Elist_Id);
23260 -- Emit errors for all unused states found in list States
23262 -------------------------------
23263 -- Analyze_Refinement_Clause --
23264 -------------------------------
23266 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
23267 AR_Constit : Entity_Id := Empty;
23268 AW_Constit : Entity_Id := Empty;
23269 ER_Constit : Entity_Id := Empty;
23270 EW_Constit : Entity_Id := Empty;
23271 -- The entities of external constituents that contain one of the
23272 -- following enabled properties: Async_Readers, Async_Writers,
23273 -- Effective_Reads and Effective_Writes.
23275 External_Constit_Seen : Boolean := False;
23276 -- Flag used to mark when at least one external constituent is part
23277 -- of the state refinement.
23279 Non_Null_Seen : Boolean := False;
23280 Null_Seen : Boolean := False;
23281 -- Flags used to detect multiple uses of null in a single clause or a
23282 -- mixture of null and non-null constituents.
23284 Part_Of_Constits : Elist_Id := No_Elist;
23285 -- A list of all candidate constituents subject to indicator Part_Of
23286 -- where the encapsulating state is the current state.
23288 State : Node_Id;
23289 State_Id : Entity_Id;
23290 -- The current state being refined
23292 procedure Analyze_Constituent (Constit : Node_Id);
23293 -- Perform full analysis of a single constituent
23295 procedure Check_External_Property
23296 (Prop_Nam : Name_Id;
23297 Enabled : Boolean;
23298 Constit : Entity_Id);
23299 -- Determine whether a property denoted by name Prop_Nam is present
23300 -- in both the refined state and constituent Constit. Flag Enabled
23301 -- should be set when the property applies to the refined state. If
23302 -- this is not the case, emit an error message.
23304 procedure Check_Matching_State;
23305 -- Determine whether the state being refined appears in list
23306 -- Available_States. Emit an error when attempting to re-refine the
23307 -- state or when the state is not defined in the package declaration,
23308 -- otherwise remove the state from Available_States.
23310 procedure Report_Unused_Constituents (Constits : Elist_Id);
23311 -- Emit errors for all unused Part_Of constituents in list Constits
23313 -------------------------
23314 -- Analyze_Constituent --
23315 -------------------------
23317 procedure Analyze_Constituent (Constit : Node_Id) is
23318 procedure Check_Ghost_Constituent (Constit_Id : Entity_Id);
23319 -- Verify that the constituent Constit_Id is a Ghost entity if the
23320 -- abstract state being refined is also Ghost. If this is the case
23321 -- verify that the Ghost policy in effect at the point of state
23322 -- and constituent declaration is the same.
23324 procedure Check_Matching_Constituent (Constit_Id : Entity_Id);
23325 -- Determine whether constituent Constit denoted by its entity
23326 -- Constit_Id appears in Hidden_States. Emit an error when the
23327 -- constituent is not a valid hidden state of the related package
23328 -- or when it is used more than once. Otherwise remove the
23329 -- constituent from Hidden_States.
23331 --------------------------------
23332 -- Check_Matching_Constituent --
23333 --------------------------------
23335 procedure Check_Matching_Constituent (Constit_Id : Entity_Id) is
23336 procedure Collect_Constituent;
23337 -- Add constituent Constit_Id to the refinements of State_Id
23339 -------------------------
23340 -- Collect_Constituent --
23341 -------------------------
23343 procedure Collect_Constituent is
23344 begin
23345 -- Add the constituent to the list of processed items to aid
23346 -- with the detection of duplicates.
23348 Add_Item (Constit_Id, Constituents_Seen);
23350 -- Collect the constituent in the list of refinement items
23351 -- and establish a relation between the refined state and
23352 -- the item.
23354 Append_Elmt (Constit_Id, Refinement_Constituents (State_Id));
23355 Set_Encapsulating_State (Constit_Id, State_Id);
23357 -- The state has at least one legal constituent, mark the
23358 -- start of the refinement region. The region ends when the
23359 -- body declarations end (see routine Analyze_Declarations).
23361 Set_Has_Visible_Refinement (State_Id);
23363 -- When the constituent is external, save its relevant
23364 -- property for further checks.
23366 if Async_Readers_Enabled (Constit_Id) then
23367 AR_Constit := Constit_Id;
23368 External_Constit_Seen := True;
23369 end if;
23371 if Async_Writers_Enabled (Constit_Id) then
23372 AW_Constit := Constit_Id;
23373 External_Constit_Seen := True;
23374 end if;
23376 if Effective_Reads_Enabled (Constit_Id) then
23377 ER_Constit := Constit_Id;
23378 External_Constit_Seen := True;
23379 end if;
23381 if Effective_Writes_Enabled (Constit_Id) then
23382 EW_Constit := Constit_Id;
23383 External_Constit_Seen := True;
23384 end if;
23385 end Collect_Constituent;
23387 -- Local variables
23389 State_Elmt : Elmt_Id;
23391 -- Start of processing for Check_Matching_Constituent
23393 begin
23394 -- Detect a duplicate use of a constituent
23396 if Contains (Constituents_Seen, Constit_Id) then
23397 SPARK_Msg_NE
23398 ("duplicate use of constituent &", Constit, Constit_Id);
23399 return;
23400 end if;
23402 -- The constituent is subject to a Part_Of indicator
23404 if Present (Encapsulating_State (Constit_Id)) then
23405 if Encapsulating_State (Constit_Id) = State_Id then
23406 Check_Ghost_Constituent (Constit_Id);
23407 Remove (Part_Of_Constits, Constit_Id);
23408 Collect_Constituent;
23410 -- The constituent is part of another state and is used
23411 -- incorrectly in the refinement of the current state.
23413 else
23414 Error_Msg_Name_1 := Chars (State_Id);
23415 SPARK_Msg_NE
23416 ("& cannot act as constituent of state %",
23417 Constit, Constit_Id);
23418 SPARK_Msg_NE
23419 ("\Part_Of indicator specifies & as encapsulating "
23420 & "state", Constit, Encapsulating_State (Constit_Id));
23421 end if;
23423 -- The only other source of legal constituents is the body
23424 -- state space of the related package.
23426 else
23427 if Present (Body_States) then
23428 State_Elmt := First_Elmt (Body_States);
23429 while Present (State_Elmt) loop
23431 -- Consume a valid constituent to signal that it has
23432 -- been encountered.
23434 if Node (State_Elmt) = Constit_Id then
23435 Check_Ghost_Constituent (Constit_Id);
23437 Remove_Elmt (Body_States, State_Elmt);
23438 Collect_Constituent;
23439 return;
23440 end if;
23442 Next_Elmt (State_Elmt);
23443 end loop;
23444 end if;
23446 -- If we get here, then the constituent is not a hidden
23447 -- state of the related package and may not be used in a
23448 -- refinement (SPARK RM 7.2.2(9)).
23450 Error_Msg_Name_1 := Chars (Spec_Id);
23451 SPARK_Msg_NE
23452 ("cannot use & in refinement, constituent is not a hidden "
23453 & "state of package %", Constit, Constit_Id);
23454 end if;
23455 end Check_Matching_Constituent;
23457 -----------------------------
23458 -- Check_Ghost_Constituent --
23459 -----------------------------
23461 procedure Check_Ghost_Constituent (Constit_Id : Entity_Id) is
23462 begin
23463 if Is_Ghost_Entity (State_Id) then
23464 if Is_Ghost_Entity (Constit_Id) then
23466 -- The Ghost policy in effect at the point of abstract
23467 -- state declaration and constituent must match
23468 -- (SPARK RM 6.9(15)).
23470 if Is_Checked_Ghost_Entity (State_Id)
23471 and then Is_Ignored_Ghost_Entity (Constit_Id)
23472 then
23473 Error_Msg_Sloc := Sloc (Constit);
23475 SPARK_Msg_N
23476 ("incompatible ghost policies in effect", State);
23477 SPARK_Msg_NE
23478 ("\abstract state & declared with ghost policy "
23479 & "Check", State, State_Id);
23480 SPARK_Msg_NE
23481 ("\constituent & declared # with ghost policy "
23482 & "Ignore", State, Constit_Id);
23484 elsif Is_Ignored_Ghost_Entity (State_Id)
23485 and then Is_Checked_Ghost_Entity (Constit_Id)
23486 then
23487 Error_Msg_Sloc := Sloc (Constit);
23489 SPARK_Msg_N
23490 ("incompatible ghost policies in effect", State);
23491 SPARK_Msg_NE
23492 ("\abstract state & declared with ghost policy "
23493 & "Ignore", State, State_Id);
23494 SPARK_Msg_NE
23495 ("\constituent & declared # with ghost policy "
23496 & "Check", State, Constit_Id);
23497 end if;
23499 -- A constituent of a Ghost abstract state must be a Ghost
23500 -- entity (SPARK RM 7.2.2(12)).
23502 else
23503 SPARK_Msg_NE
23504 ("constituent of ghost state & must be ghost",
23505 Constit, State_Id);
23506 end if;
23507 end if;
23508 end Check_Ghost_Constituent;
23510 -- Local variables
23512 Constit_Id : Entity_Id;
23514 -- Start of processing for Analyze_Constituent
23516 begin
23517 -- Detect multiple uses of null in a single refinement clause or a
23518 -- mixture of null and non-null constituents.
23520 if Nkind (Constit) = N_Null then
23521 if Null_Seen then
23522 SPARK_Msg_N
23523 ("multiple null constituents not allowed", Constit);
23525 elsif Non_Null_Seen then
23526 SPARK_Msg_N
23527 ("cannot mix null and non-null constituents", Constit);
23529 else
23530 Null_Seen := True;
23532 -- Collect the constituent in the list of refinement items
23534 Append_Elmt (Constit, Refinement_Constituents (State_Id));
23536 -- The state has at least one legal constituent, mark the
23537 -- start of the refinement region. The region ends when the
23538 -- body declarations end (see Analyze_Declarations).
23540 Set_Has_Visible_Refinement (State_Id);
23541 end if;
23543 -- Non-null constituents
23545 else
23546 Non_Null_Seen := True;
23548 if Null_Seen then
23549 SPARK_Msg_N
23550 ("cannot mix null and non-null constituents", Constit);
23551 end if;
23553 Analyze (Constit);
23554 Resolve_State (Constit);
23556 -- Ensure that the constituent denotes a valid state or a
23557 -- whole variable.
23559 if Is_Entity_Name (Constit) then
23560 Constit_Id := Entity_Of (Constit);
23562 if Ekind_In (Constit_Id, E_Abstract_State, E_Variable) then
23563 Check_Matching_Constituent (Constit_Id);
23565 else
23566 SPARK_Msg_NE
23567 ("constituent & must denote a variable or state (SPARK "
23568 & "RM 7.2.2(5))", Constit, Constit_Id);
23569 end if;
23571 -- The constituent is illegal
23573 else
23574 SPARK_Msg_N ("malformed constituent", Constit);
23575 end if;
23576 end if;
23577 end Analyze_Constituent;
23579 -----------------------------
23580 -- Check_External_Property --
23581 -----------------------------
23583 procedure Check_External_Property
23584 (Prop_Nam : Name_Id;
23585 Enabled : Boolean;
23586 Constit : Entity_Id)
23588 begin
23589 Error_Msg_Name_1 := Prop_Nam;
23591 -- The property is enabled in the related Abstract_State pragma
23592 -- that defines the state (SPARK RM 7.2.8(3)).
23594 if Enabled then
23595 if No (Constit) then
23596 SPARK_Msg_NE
23597 ("external state & requires at least one constituent with "
23598 & "property %", State, State_Id);
23599 end if;
23601 -- The property is missing in the declaration of the state, but
23602 -- a constituent is introducing it in the state refinement
23603 -- (SPARK RM 7.2.8(3)).
23605 elsif Present (Constit) then
23606 Error_Msg_Name_2 := Chars (Constit);
23607 SPARK_Msg_NE
23608 ("external state & lacks property % set by constituent %",
23609 State, State_Id);
23610 end if;
23611 end Check_External_Property;
23613 --------------------------
23614 -- Check_Matching_State --
23615 --------------------------
23617 procedure Check_Matching_State is
23618 State_Elmt : Elmt_Id;
23620 begin
23621 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
23623 if Contains (Refined_States_Seen, State_Id) then
23624 SPARK_Msg_NE
23625 ("duplicate refinement of state &", State, State_Id);
23626 return;
23627 end if;
23629 -- Inspect the abstract states defined in the package declaration
23630 -- looking for a match.
23632 State_Elmt := First_Elmt (Available_States);
23633 while Present (State_Elmt) loop
23635 -- A valid abstract state is being refined in the body. Add
23636 -- the state to the list of processed refined states to aid
23637 -- with the detection of duplicate refinements. Remove the
23638 -- state from Available_States to signal that it has already
23639 -- been refined.
23641 if Node (State_Elmt) = State_Id then
23642 Add_Item (State_Id, Refined_States_Seen);
23643 Remove_Elmt (Available_States, State_Elmt);
23644 return;
23645 end if;
23647 Next_Elmt (State_Elmt);
23648 end loop;
23650 -- If we get here, we are refining a state that is not defined in
23651 -- the package declaration.
23653 Error_Msg_Name_1 := Chars (Spec_Id);
23654 SPARK_Msg_NE
23655 ("cannot refine state, & is not defined in package %",
23656 State, State_Id);
23657 end Check_Matching_State;
23659 --------------------------------
23660 -- Report_Unused_Constituents --
23661 --------------------------------
23663 procedure Report_Unused_Constituents (Constits : Elist_Id) is
23664 Constit_Elmt : Elmt_Id;
23665 Constit_Id : Entity_Id;
23666 Posted : Boolean := False;
23668 begin
23669 if Present (Constits) then
23670 Constit_Elmt := First_Elmt (Constits);
23671 while Present (Constit_Elmt) loop
23672 Constit_Id := Node (Constit_Elmt);
23674 -- Generate an error message of the form:
23676 -- state ... has unused Part_Of constituents
23677 -- abstract state ... defined at ...
23678 -- variable ... defined at ...
23680 if not Posted then
23681 Posted := True;
23682 SPARK_Msg_NE
23683 ("state & has unused Part_Of constituents",
23684 State, State_Id);
23685 end if;
23687 Error_Msg_Sloc := Sloc (Constit_Id);
23689 if Ekind (Constit_Id) = E_Abstract_State then
23690 SPARK_Msg_NE
23691 ("\abstract state & defined #", State, Constit_Id);
23692 else
23693 SPARK_Msg_NE
23694 ("\variable & defined #", State, Constit_Id);
23695 end if;
23697 Next_Elmt (Constit_Elmt);
23698 end loop;
23699 end if;
23700 end Report_Unused_Constituents;
23702 -- Local declarations
23704 Body_Ref : Node_Id;
23705 Body_Ref_Elmt : Elmt_Id;
23706 Constit : Node_Id;
23707 Extra_State : Node_Id;
23709 -- Start of processing for Analyze_Refinement_Clause
23711 begin
23712 -- A refinement clause appears as a component association where the
23713 -- sole choice is the state and the expressions are the constituents.
23714 -- This is a syntax error, always report.
23716 if Nkind (Clause) /= N_Component_Association then
23717 Error_Msg_N ("malformed state refinement clause", Clause);
23718 return;
23719 end if;
23721 -- Analyze the state name of a refinement clause
23723 State := First (Choices (Clause));
23725 Analyze (State);
23726 Resolve_State (State);
23728 -- Ensure that the state name denotes a valid abstract state that is
23729 -- defined in the spec of the related package.
23731 if Is_Entity_Name (State) then
23732 State_Id := Entity_Of (State);
23734 -- Catch any attempts to re-refine a state or refine a state that
23735 -- is not defined in the package declaration.
23737 if Ekind (State_Id) = E_Abstract_State then
23738 Check_Matching_State;
23739 else
23740 SPARK_Msg_NE
23741 ("& must denote an abstract state", State, State_Id);
23742 return;
23743 end if;
23745 -- References to a state with visible refinement are illegal.
23746 -- When nested packages are involved, detecting such references is
23747 -- tricky because pragma Refined_State is analyzed later than the
23748 -- offending pragma Depends or Global. References that occur in
23749 -- such nested context are stored in a list. Emit errors for all
23750 -- references found in Body_References (SPARK RM 6.1.4(8)).
23752 if Present (Body_References (State_Id)) then
23753 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
23754 while Present (Body_Ref_Elmt) loop
23755 Body_Ref := Node (Body_Ref_Elmt);
23757 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
23758 Error_Msg_Sloc := Sloc (State);
23759 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
23761 Next_Elmt (Body_Ref_Elmt);
23762 end loop;
23763 end if;
23765 -- The state name is illegal. This is a syntax error, always report.
23767 else
23768 Error_Msg_N ("malformed state name in refinement clause", State);
23769 return;
23770 end if;
23772 -- A refinement clause may only refine one state at a time
23774 Extra_State := Next (State);
23776 if Present (Extra_State) then
23777 SPARK_Msg_N
23778 ("refinement clause cannot cover multiple states", Extra_State);
23779 end if;
23781 -- Replicate the Part_Of constituents of the refined state because
23782 -- the algorithm will consume items.
23784 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
23786 -- Analyze all constituents of the refinement. Multiple constituents
23787 -- appear as an aggregate.
23789 Constit := Expression (Clause);
23791 if Nkind (Constit) = N_Aggregate then
23792 if Present (Component_Associations (Constit)) then
23793 SPARK_Msg_N
23794 ("constituents of refinement clause must appear in "
23795 & "positional form", Constit);
23797 else pragma Assert (Present (Expressions (Constit)));
23798 Constit := First (Expressions (Constit));
23799 while Present (Constit) loop
23800 Analyze_Constituent (Constit);
23802 Next (Constit);
23803 end loop;
23804 end if;
23806 -- Various forms of a single constituent. Note that these may include
23807 -- malformed constituents.
23809 else
23810 Analyze_Constituent (Constit);
23811 end if;
23813 -- A refined external state is subject to special rules with respect
23814 -- to its properties and constituents.
23816 if Is_External_State (State_Id) then
23818 -- The set of properties that all external constituents yield must
23819 -- match that of the refined state. There are two cases to detect:
23820 -- the refined state lacks a property or has an extra property.
23822 if External_Constit_Seen then
23823 Check_External_Property
23824 (Prop_Nam => Name_Async_Readers,
23825 Enabled => Async_Readers_Enabled (State_Id),
23826 Constit => AR_Constit);
23828 Check_External_Property
23829 (Prop_Nam => Name_Async_Writers,
23830 Enabled => Async_Writers_Enabled (State_Id),
23831 Constit => AW_Constit);
23833 Check_External_Property
23834 (Prop_Nam => Name_Effective_Reads,
23835 Enabled => Effective_Reads_Enabled (State_Id),
23836 Constit => ER_Constit);
23838 Check_External_Property
23839 (Prop_Nam => Name_Effective_Writes,
23840 Enabled => Effective_Writes_Enabled (State_Id),
23841 Constit => EW_Constit);
23843 -- An external state may be refined to null (SPARK RM 7.2.8(2))
23845 elsif Null_Seen then
23846 null;
23848 -- The external state has constituents, but none of them are
23849 -- external (SPARK RM 7.2.8(2)).
23851 else
23852 SPARK_Msg_NE
23853 ("external state & requires at least one external "
23854 & "constituent or null refinement", State, State_Id);
23855 end if;
23857 -- When a refined state is not external, it should not have external
23858 -- constituents (SPARK RM 7.2.8(1)).
23860 elsif External_Constit_Seen then
23861 SPARK_Msg_NE
23862 ("non-external state & cannot contain external constituents in "
23863 & "refinement", State, State_Id);
23864 end if;
23866 -- Ensure that all Part_Of candidate constituents have been mentioned
23867 -- in the refinement clause.
23869 Report_Unused_Constituents (Part_Of_Constits);
23870 end Analyze_Refinement_Clause;
23872 -------------------------
23873 -- Collect_Body_States --
23874 -------------------------
23876 function Collect_Body_States (Pack_Id : Entity_Id) return Elist_Id is
23877 Result : Elist_Id := No_Elist;
23878 -- A list containing all body states of Pack_Id
23880 procedure Collect_Visible_States (Pack_Id : Entity_Id);
23881 -- Gather the entities of all abstract states and variables declared
23882 -- in the visible state space of package Pack_Id.
23884 ----------------------------
23885 -- Collect_Visible_States --
23886 ----------------------------
23888 procedure Collect_Visible_States (Pack_Id : Entity_Id) is
23889 Item_Id : Entity_Id;
23891 begin
23892 -- Traverse the entity chain of the package and inspect all
23893 -- visible items.
23895 Item_Id := First_Entity (Pack_Id);
23896 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
23898 -- Do not consider internally generated items as those cannot
23899 -- be named and participate in refinement.
23901 if not Comes_From_Source (Item_Id) then
23902 null;
23904 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
23905 Add_Item (Item_Id, Result);
23907 -- Recursively gather the visible states of a nested package
23909 elsif Ekind (Item_Id) = E_Package then
23910 Collect_Visible_States (Item_Id);
23911 end if;
23913 Next_Entity (Item_Id);
23914 end loop;
23915 end Collect_Visible_States;
23917 -- Local variables
23919 Pack_Body : constant Node_Id :=
23920 Declaration_Node (Body_Entity (Pack_Id));
23921 Decl : Node_Id;
23922 Item_Id : Entity_Id;
23924 -- Start of processing for Collect_Body_States
23926 begin
23927 -- Inspect the declarations of the body looking for source variables,
23928 -- packages and package instantiations.
23930 Decl := First (Declarations (Pack_Body));
23931 while Present (Decl) loop
23932 if Nkind (Decl) = N_Object_Declaration then
23933 Item_Id := Defining_Entity (Decl);
23935 -- Capture source variables only as internally generated
23936 -- temporaries cannot be named and participate in refinement.
23938 if Ekind (Item_Id) = E_Variable
23939 and then Comes_From_Source (Item_Id)
23940 then
23941 Add_Item (Item_Id, Result);
23942 end if;
23944 elsif Nkind (Decl) = N_Package_Declaration then
23945 Item_Id := Defining_Entity (Decl);
23947 -- Capture the visible abstract states and variables of a
23948 -- source package [instantiation].
23950 if Comes_From_Source (Item_Id) then
23951 Collect_Visible_States (Item_Id);
23952 end if;
23953 end if;
23955 Next (Decl);
23956 end loop;
23958 return Result;
23959 end Collect_Body_States;
23961 -----------------------------
23962 -- Report_Unrefined_States --
23963 -----------------------------
23965 procedure Report_Unrefined_States (States : Elist_Id) is
23966 State_Elmt : Elmt_Id;
23968 begin
23969 if Present (States) then
23970 State_Elmt := First_Elmt (States);
23971 while Present (State_Elmt) loop
23972 SPARK_Msg_N
23973 ("abstract state & must be refined", Node (State_Elmt));
23975 Next_Elmt (State_Elmt);
23976 end loop;
23977 end if;
23978 end Report_Unrefined_States;
23980 --------------------------
23981 -- Report_Unused_States --
23982 --------------------------
23984 procedure Report_Unused_States (States : Elist_Id) is
23985 Posted : Boolean := False;
23986 State_Elmt : Elmt_Id;
23987 State_Id : Entity_Id;
23989 begin
23990 if Present (States) then
23991 State_Elmt := First_Elmt (States);
23992 while Present (State_Elmt) loop
23993 State_Id := Node (State_Elmt);
23995 -- Generate an error message of the form:
23997 -- body of package ... has unused hidden states
23998 -- abstract state ... defined at ...
23999 -- variable ... defined at ...
24001 if not Posted then
24002 Posted := True;
24003 SPARK_Msg_N
24004 ("body of package & has unused hidden states", Body_Id);
24005 end if;
24007 Error_Msg_Sloc := Sloc (State_Id);
24009 if Ekind (State_Id) = E_Abstract_State then
24010 SPARK_Msg_NE
24011 ("\abstract state & defined #", Body_Id, State_Id);
24012 else
24013 SPARK_Msg_NE
24014 ("\variable & defined #", Body_Id, State_Id);
24015 end if;
24017 Next_Elmt (State_Elmt);
24018 end loop;
24019 end if;
24020 end Report_Unused_States;
24022 -- Local declarations
24024 Body_Decl : constant Node_Id := Parent (N);
24025 Clauses : constant Node_Id :=
24026 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
24027 Clause : Node_Id;
24029 -- Start of processing for Analyze_Refined_State_In_Decl_Part
24031 begin
24032 Set_Analyzed (N);
24034 Body_Id := Defining_Entity (Body_Decl);
24035 Spec_Id := Corresponding_Spec (Body_Decl);
24037 -- Replicate the abstract states declared by the package because the
24038 -- matching algorithm will consume states.
24040 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
24042 -- Gather all abstract states and variables declared in the visible
24043 -- state space of the package body. These items must be utilized as
24044 -- constituents in a state refinement.
24046 Body_States := Collect_Body_States (Spec_Id);
24048 -- Multiple non-null state refinements appear as an aggregate
24050 if Nkind (Clauses) = N_Aggregate then
24051 if Present (Expressions (Clauses)) then
24052 SPARK_Msg_N
24053 ("state refinements must appear as component associations",
24054 Clauses);
24056 else pragma Assert (Present (Component_Associations (Clauses)));
24057 Clause := First (Component_Associations (Clauses));
24058 while Present (Clause) loop
24059 Analyze_Refinement_Clause (Clause);
24061 Next (Clause);
24062 end loop;
24063 end if;
24065 -- Various forms of a single state refinement. Note that these may
24066 -- include malformed refinements.
24068 else
24069 Analyze_Refinement_Clause (Clauses);
24070 end if;
24072 -- List all abstract states that were left unrefined
24074 Report_Unrefined_States (Available_States);
24076 -- Ensure that all abstract states and variables declared in the body
24077 -- state space of the related package are utilized as constituents.
24079 Report_Unused_States (Body_States);
24080 end Analyze_Refined_State_In_Decl_Part;
24082 ------------------------------------
24083 -- Analyze_Test_Case_In_Decl_Part --
24084 ------------------------------------
24086 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id; S : Entity_Id) is
24087 begin
24088 -- Install formals and push subprogram spec onto scope stack so that we
24089 -- can see the formals from the pragma.
24091 Push_Scope (S);
24092 Install_Formals (S);
24094 -- Preanalyze the boolean expressions, we treat these as spec
24095 -- expressions (i.e. similar to a default expression).
24097 if Pragma_Name (N) = Name_Test_Case then
24098 Preanalyze_CTC_Args
24100 Get_Requires_From_CTC_Pragma (N),
24101 Get_Ensures_From_CTC_Pragma (N));
24102 end if;
24104 -- Remove the subprogram from the scope stack now that the pre-analysis
24105 -- of the expressions in the contract case or test case is done.
24107 End_Scope;
24108 end Analyze_Test_Case_In_Decl_Part;
24110 ----------------
24111 -- Appears_In --
24112 ----------------
24114 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
24115 Elmt : Elmt_Id;
24116 Id : Entity_Id;
24118 begin
24119 if Present (List) then
24120 Elmt := First_Elmt (List);
24121 while Present (Elmt) loop
24122 if Nkind (Node (Elmt)) = N_Defining_Identifier then
24123 Id := Node (Elmt);
24124 else
24125 Id := Entity_Of (Node (Elmt));
24126 end if;
24128 if Id = Item_Id then
24129 return True;
24130 end if;
24132 Next_Elmt (Elmt);
24133 end loop;
24134 end if;
24136 return False;
24137 end Appears_In;
24139 -----------------------------
24140 -- Check_Applicable_Policy --
24141 -----------------------------
24143 procedure Check_Applicable_Policy (N : Node_Id) is
24144 PP : Node_Id;
24145 Policy : Name_Id;
24147 Ename : constant Name_Id := Original_Aspect_Name (N);
24149 begin
24150 -- No effect if not valid assertion kind name
24152 if not Is_Valid_Assertion_Kind (Ename) then
24153 return;
24154 end if;
24156 -- Loop through entries in check policy list
24158 PP := Opt.Check_Policy_List;
24159 while Present (PP) loop
24160 declare
24161 PPA : constant List_Id := Pragma_Argument_Associations (PP);
24162 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
24164 begin
24165 if Ename = Pnm
24166 or else Pnm = Name_Assertion
24167 or else (Pnm = Name_Statement_Assertions
24168 and then Nam_In (Ename, Name_Assert,
24169 Name_Assert_And_Cut,
24170 Name_Assume,
24171 Name_Loop_Invariant,
24172 Name_Loop_Variant))
24173 then
24174 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
24176 case Policy is
24177 when Name_Off | Name_Ignore =>
24178 Set_Is_Ignored (N, True);
24179 Set_Is_Checked (N, False);
24181 when Name_On | Name_Check =>
24182 Set_Is_Checked (N, True);
24183 Set_Is_Ignored (N, False);
24185 when Name_Disable =>
24186 Set_Is_Ignored (N, True);
24187 Set_Is_Checked (N, False);
24188 Set_Is_Disabled (N, True);
24190 -- That should be exhaustive, the null here is a defence
24191 -- against a malformed tree from previous errors.
24193 when others =>
24194 null;
24195 end case;
24197 return;
24198 end if;
24200 PP := Next_Pragma (PP);
24201 end;
24202 end loop;
24204 -- If there are no specific entries that matched, then we let the
24205 -- setting of assertions govern. Note that this provides the needed
24206 -- compatibility with the RM for the cases of assertion, invariant,
24207 -- precondition, predicate, and postcondition.
24209 if Assertions_Enabled then
24210 Set_Is_Checked (N, True);
24211 Set_Is_Ignored (N, False);
24212 else
24213 Set_Is_Checked (N, False);
24214 Set_Is_Ignored (N, True);
24215 end if;
24216 end Check_Applicable_Policy;
24218 -------------------------------
24219 -- Check_External_Properties --
24220 -------------------------------
24222 procedure Check_External_Properties
24223 (Item : Node_Id;
24224 AR : Boolean;
24225 AW : Boolean;
24226 ER : Boolean;
24227 EW : Boolean)
24229 begin
24230 -- All properties enabled
24232 if AR and AW and ER and EW then
24233 null;
24235 -- Async_Readers + Effective_Writes
24236 -- Async_Readers + Async_Writers + Effective_Writes
24238 elsif AR and EW and not ER then
24239 null;
24241 -- Async_Writers + Effective_Reads
24242 -- Async_Readers + Async_Writers + Effective_Reads
24244 elsif AW and ER and not EW then
24245 null;
24247 -- Async_Readers + Async_Writers
24249 elsif AR and AW and not ER and not EW then
24250 null;
24252 -- Async_Readers
24254 elsif AR and not AW and not ER and not EW then
24255 null;
24257 -- Async_Writers
24259 elsif AW and not AR and not ER and not EW then
24260 null;
24262 else
24263 SPARK_Msg_N
24264 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
24265 Item);
24266 end if;
24267 end Check_External_Properties;
24269 ----------------
24270 -- Check_Kind --
24271 ----------------
24273 function Check_Kind (Nam : Name_Id) return Name_Id is
24274 PP : Node_Id;
24276 begin
24277 -- Loop through entries in check policy list
24279 PP := Opt.Check_Policy_List;
24280 while Present (PP) loop
24281 declare
24282 PPA : constant List_Id := Pragma_Argument_Associations (PP);
24283 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
24285 begin
24286 if Nam = Pnm
24287 or else (Pnm = Name_Assertion
24288 and then Is_Valid_Assertion_Kind (Nam))
24289 or else (Pnm = Name_Statement_Assertions
24290 and then Nam_In (Nam, Name_Assert,
24291 Name_Assert_And_Cut,
24292 Name_Assume,
24293 Name_Loop_Invariant,
24294 Name_Loop_Variant))
24295 then
24296 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
24297 when Name_On | Name_Check =>
24298 return Name_Check;
24299 when Name_Off | Name_Ignore =>
24300 return Name_Ignore;
24301 when Name_Disable =>
24302 return Name_Disable;
24303 when others =>
24304 raise Program_Error;
24305 end case;
24307 else
24308 PP := Next_Pragma (PP);
24309 end if;
24310 end;
24311 end loop;
24313 -- If there are no specific entries that matched, then we let the
24314 -- setting of assertions govern. Note that this provides the needed
24315 -- compatibility with the RM for the cases of assertion, invariant,
24316 -- precondition, predicate, and postcondition.
24318 if Assertions_Enabled then
24319 return Name_Check;
24320 else
24321 return Name_Ignore;
24322 end if;
24323 end Check_Kind;
24325 ---------------------------
24326 -- Check_Missing_Part_Of --
24327 ---------------------------
24329 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
24330 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
24331 -- Determine whether a package denoted by Pack_Id declares at least one
24332 -- visible state.
24334 -----------------------
24335 -- Has_Visible_State --
24336 -----------------------
24338 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
24339 Item_Id : Entity_Id;
24341 begin
24342 -- Traverse the entity chain of the package trying to find at least
24343 -- one visible abstract state, variable or a package [instantiation]
24344 -- that declares a visible state.
24346 Item_Id := First_Entity (Pack_Id);
24347 while Present (Item_Id)
24348 and then not In_Private_Part (Item_Id)
24349 loop
24350 -- Do not consider internally generated items
24352 if not Comes_From_Source (Item_Id) then
24353 null;
24355 -- A visible state has been found
24357 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
24358 return True;
24360 -- Recursively peek into nested packages and instantiations
24362 elsif Ekind (Item_Id) = E_Package
24363 and then Has_Visible_State (Item_Id)
24364 then
24365 return True;
24366 end if;
24368 Next_Entity (Item_Id);
24369 end loop;
24371 return False;
24372 end Has_Visible_State;
24374 -- Local variables
24376 Pack_Id : Entity_Id;
24377 Placement : State_Space_Kind;
24379 -- Start of processing for Check_Missing_Part_Of
24381 begin
24382 -- Do not consider abstract states, variables or package instantiations
24383 -- coming from an instance as those always inherit the Part_Of indicator
24384 -- of the instance itself.
24386 if In_Instance then
24387 return;
24389 -- Do not consider internally generated entities as these can never
24390 -- have a Part_Of indicator.
24392 elsif not Comes_From_Source (Item_Id) then
24393 return;
24395 -- Perform these checks only when SPARK_Mode is enabled as they will
24396 -- interfere with standard Ada rules and produce false positives.
24398 elsif SPARK_Mode /= On then
24399 return;
24400 end if;
24402 -- Find where the abstract state, variable or package instantiation
24403 -- lives with respect to the state space.
24405 Find_Placement_In_State_Space
24406 (Item_Id => Item_Id,
24407 Placement => Placement,
24408 Pack_Id => Pack_Id);
24410 -- Items that appear in a non-package construct (subprogram, block, etc)
24411 -- do not require a Part_Of indicator because they can never act as a
24412 -- hidden state.
24414 if Placement = Not_In_Package then
24415 null;
24417 -- An item declared in the body state space of a package always act as a
24418 -- constituent and does not need explicit Part_Of indicator.
24420 elsif Placement = Body_State_Space then
24421 null;
24423 -- In general an item declared in the visible state space of a package
24424 -- does not require a Part_Of indicator. The only exception is when the
24425 -- related package is a private child unit in which case Part_Of must
24426 -- denote a state in the parent unit or in one of its descendants.
24428 elsif Placement = Visible_State_Space then
24429 if Is_Child_Unit (Pack_Id)
24430 and then Is_Private_Descendant (Pack_Id)
24431 then
24432 -- A package instantiation does not need a Part_Of indicator when
24433 -- the related generic template has no visible state.
24435 if Ekind (Item_Id) = E_Package
24436 and then Is_Generic_Instance (Item_Id)
24437 and then not Has_Visible_State (Item_Id)
24438 then
24439 null;
24441 -- All other cases require Part_Of
24443 else
24444 Error_Msg_N
24445 ("indicator Part_Of is required in this context "
24446 & "(SPARK RM 7.2.6(3))", Item_Id);
24447 Error_Msg_Name_1 := Chars (Pack_Id);
24448 Error_Msg_N
24449 ("\& is declared in the visible part of private child "
24450 & "unit %", Item_Id);
24451 end if;
24452 end if;
24454 -- When the item appears in the private state space of a packge, it must
24455 -- be a part of some state declared by the said package.
24457 else pragma Assert (Placement = Private_State_Space);
24459 -- The related package does not declare a state, the item cannot act
24460 -- as a Part_Of constituent.
24462 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
24463 null;
24465 -- A package instantiation does not need a Part_Of indicator when the
24466 -- related generic template has no visible state.
24468 elsif Ekind (Pack_Id) = E_Package
24469 and then Is_Generic_Instance (Pack_Id)
24470 and then not Has_Visible_State (Pack_Id)
24471 then
24472 null;
24474 -- All other cases require Part_Of
24476 else
24477 Error_Msg_N
24478 ("indicator Part_Of is required in this context "
24479 & "(SPARK RM 7.2.6(2))", Item_Id);
24480 Error_Msg_Name_1 := Chars (Pack_Id);
24481 Error_Msg_N
24482 ("\& is declared in the private part of package %", Item_Id);
24483 end if;
24484 end if;
24485 end Check_Missing_Part_Of;
24487 ---------------------------------
24488 -- Check_SPARK_Aspect_For_ASIS --
24489 ---------------------------------
24491 procedure Check_SPARK_Aspect_For_ASIS (N : Node_Id) is
24492 Expr : Node_Id;
24494 begin
24495 if ASIS_Mode and then From_Aspect_Specification (N) then
24496 Expr := Expression (Corresponding_Aspect (N));
24497 if Nkind (Expr) /= N_Aggregate then
24498 Preanalyze_And_Resolve (Expr);
24500 else
24501 declare
24502 Comps : constant List_Id := Component_Associations (Expr);
24503 Exprs : constant List_Id := Expressions (Expr);
24504 C : Node_Id;
24505 E : Node_Id;
24507 begin
24508 E := First (Exprs);
24509 while Present (E) loop
24510 Analyze (E);
24511 Next (E);
24512 end loop;
24514 C := First (Comps);
24515 while Present (C) loop
24516 Analyze (Expression (C));
24517 Next (C);
24518 end loop;
24519 end;
24520 end if;
24521 end if;
24522 end Check_SPARK_Aspect_For_ASIS;
24524 -------------------------------------
24525 -- Check_State_And_Constituent_Use --
24526 -------------------------------------
24528 procedure Check_State_And_Constituent_Use
24529 (States : Elist_Id;
24530 Constits : Elist_Id;
24531 Context : Node_Id)
24533 function Find_Encapsulating_State
24534 (Constit_Id : Entity_Id) return Entity_Id;
24535 -- Given the entity of a constituent, try to find a corresponding
24536 -- encapsulating state that appears in the same context. The routine
24537 -- returns Empty is no such state is found.
24539 ------------------------------
24540 -- Find_Encapsulating_State --
24541 ------------------------------
24543 function Find_Encapsulating_State
24544 (Constit_Id : Entity_Id) return Entity_Id
24546 State_Id : Entity_Id;
24548 begin
24549 -- Since a constituent may be part of a larger constituent set, climb
24550 -- the encapsulated state chain looking for a state that appears in
24551 -- the same context.
24553 State_Id := Encapsulating_State (Constit_Id);
24554 while Present (State_Id) loop
24555 if Contains (States, State_Id) then
24556 return State_Id;
24557 end if;
24559 State_Id := Encapsulating_State (State_Id);
24560 end loop;
24562 return Empty;
24563 end Find_Encapsulating_State;
24565 -- Local variables
24567 Constit_Elmt : Elmt_Id;
24568 Constit_Id : Entity_Id;
24569 State_Id : Entity_Id;
24571 -- Start of processing for Check_State_And_Constituent_Use
24573 begin
24574 -- Nothing to do if there are no states or constituents
24576 if No (States) or else No (Constits) then
24577 return;
24578 end if;
24580 -- Inspect the list of constituents and try to determine whether its
24581 -- encapsulating state is in list States.
24583 Constit_Elmt := First_Elmt (Constits);
24584 while Present (Constit_Elmt) loop
24585 Constit_Id := Node (Constit_Elmt);
24587 -- Determine whether the constituent is part of an encapsulating
24588 -- state that appears in the same context and if this is the case,
24589 -- emit an error (SPARK RM 7.2.6(7)).
24591 State_Id := Find_Encapsulating_State (Constit_Id);
24593 if Present (State_Id) then
24594 Error_Msg_Name_1 := Chars (Constit_Id);
24595 SPARK_Msg_NE
24596 ("cannot mention state & and its constituent % in the same "
24597 & "context", Context, State_Id);
24598 exit;
24599 end if;
24601 Next_Elmt (Constit_Elmt);
24602 end loop;
24603 end Check_State_And_Constituent_Use;
24605 --------------------------
24606 -- Collect_Global_Items --
24607 --------------------------
24609 procedure Collect_Global_Items
24610 (Prag : Node_Id;
24611 In_Items : in out Elist_Id;
24612 In_Out_Items : in out Elist_Id;
24613 Out_Items : in out Elist_Id;
24614 Proof_In_Items : in out Elist_Id;
24615 Has_In_State : out Boolean;
24616 Has_In_Out_State : out Boolean;
24617 Has_Out_State : out Boolean;
24618 Has_Proof_In_State : out Boolean;
24619 Has_Null_State : out Boolean)
24621 procedure Process_Global_List
24622 (List : Node_Id;
24623 Mode : Name_Id := Name_Input);
24624 -- Collect all items housed in a global list. Formal Mode denotes the
24625 -- current mode in effect.
24627 -------------------------
24628 -- Process_Global_List --
24629 -------------------------
24631 procedure Process_Global_List
24632 (List : Node_Id;
24633 Mode : Name_Id := Name_Input)
24635 procedure Process_Global_Item (Item : Node_Id; Mode : Name_Id);
24636 -- Add a single item to the appropriate list. Formal Mode denotes the
24637 -- current mode in effect.
24639 -------------------------
24640 -- Process_Global_Item --
24641 -------------------------
24643 procedure Process_Global_Item (Item : Node_Id; Mode : Name_Id) is
24644 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
24645 -- The above handles abstract views of variables and states built
24646 -- for limited with clauses.
24648 begin
24649 -- Signal that the global list contains at least one abstract
24650 -- state with a visible refinement. Note that the refinement may
24651 -- be null in which case there are no constituents.
24653 if Ekind (Item_Id) = E_Abstract_State then
24654 if Has_Null_Refinement (Item_Id) then
24655 Has_Null_State := True;
24657 elsif Has_Non_Null_Refinement (Item_Id) then
24658 if Mode = Name_Input then
24659 Has_In_State := True;
24660 elsif Mode = Name_In_Out then
24661 Has_In_Out_State := True;
24662 elsif Mode = Name_Output then
24663 Has_Out_State := True;
24664 elsif Mode = Name_Proof_In then
24665 Has_Proof_In_State := True;
24666 end if;
24667 end if;
24668 end if;
24670 -- Add the item to the proper list
24672 if Mode = Name_Input then
24673 Add_Item (Item_Id, In_Items);
24674 elsif Mode = Name_In_Out then
24675 Add_Item (Item_Id, In_Out_Items);
24676 elsif Mode = Name_Output then
24677 Add_Item (Item_Id, Out_Items);
24678 elsif Mode = Name_Proof_In then
24679 Add_Item (Item_Id, Proof_In_Items);
24680 end if;
24681 end Process_Global_Item;
24683 -- Local variables
24685 Item : Node_Id;
24687 -- Start of processing for Process_Global_List
24689 begin
24690 if Nkind (List) = N_Null then
24691 null;
24693 -- Single global item declaration
24695 elsif Nkind_In (List, N_Expanded_Name,
24696 N_Identifier,
24697 N_Selected_Component)
24698 then
24699 Process_Global_Item (List, Mode);
24701 -- Single global list or moded global list declaration
24703 elsif Nkind (List) = N_Aggregate then
24705 -- The declaration of a simple global list appear as a collection
24706 -- of expressions.
24708 if Present (Expressions (List)) then
24709 Item := First (Expressions (List));
24710 while Present (Item) loop
24711 Process_Global_Item (Item, Mode);
24713 Next (Item);
24714 end loop;
24716 -- The declaration of a moded global list appears as a collection
24717 -- of component associations where individual choices denote mode.
24719 elsif Present (Component_Associations (List)) then
24720 Item := First (Component_Associations (List));
24721 while Present (Item) loop
24722 Process_Global_List
24723 (List => Expression (Item),
24724 Mode => Chars (First (Choices (Item))));
24726 Next (Item);
24727 end loop;
24729 -- Invalid tree
24731 else
24732 raise Program_Error;
24733 end if;
24735 -- To accomodate partial decoration of disabled SPARK features, this
24736 -- routine may be called with illegal input. If this is the case, do
24737 -- not raise Program_Error.
24739 else
24740 null;
24741 end if;
24742 end Process_Global_List;
24744 -- Local variables
24746 Items : constant Node_Id :=
24747 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
24749 -- Start of processing for Collect_Global_Items
24751 begin
24752 -- Assume that no states have been encountered
24754 Has_In_State := False;
24755 Has_In_Out_State := False;
24756 Has_Out_State := False;
24757 Has_Proof_In_State := False;
24758 Has_Null_State := False;
24760 Process_Global_List (Items);
24761 end Collect_Global_Items;
24763 ---------------------------------------
24764 -- Collect_Subprogram_Inputs_Outputs --
24765 ---------------------------------------
24767 procedure Collect_Subprogram_Inputs_Outputs
24768 (Subp_Id : Entity_Id;
24769 Subp_Inputs : in out Elist_Id;
24770 Subp_Outputs : in out Elist_Id;
24771 Global_Seen : out Boolean)
24773 procedure Collect_Global_List
24774 (List : Node_Id;
24775 Mode : Name_Id := Name_Input);
24776 -- Collect all relevant items from a global list
24778 -------------------------
24779 -- Collect_Global_List --
24780 -------------------------
24782 procedure Collect_Global_List
24783 (List : Node_Id;
24784 Mode : Name_Id := Name_Input)
24786 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
24787 -- Add an item to the proper subprogram input or output collection
24789 -------------------------
24790 -- Collect_Global_Item --
24791 -------------------------
24793 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
24794 begin
24795 if Nam_In (Mode, Name_In_Out, Name_Input) then
24796 Add_Item (Item, Subp_Inputs);
24797 end if;
24799 if Nam_In (Mode, Name_In_Out, Name_Output) then
24800 Add_Item (Item, Subp_Outputs);
24801 end if;
24802 end Collect_Global_Item;
24804 -- Local variables
24806 Assoc : Node_Id;
24807 Item : Node_Id;
24809 -- Start of processing for Collect_Global_List
24811 begin
24812 if Nkind (List) = N_Null then
24813 null;
24815 -- Single global item declaration
24817 elsif Nkind_In (List, N_Expanded_Name,
24818 N_Identifier,
24819 N_Selected_Component)
24820 then
24821 Collect_Global_Item (List, Mode);
24823 -- Simple global list or moded global list declaration
24825 elsif Nkind (List) = N_Aggregate then
24826 if Present (Expressions (List)) then
24827 Item := First (Expressions (List));
24828 while Present (Item) loop
24829 Collect_Global_Item (Item, Mode);
24830 Next (Item);
24831 end loop;
24833 else
24834 Assoc := First (Component_Associations (List));
24835 while Present (Assoc) loop
24836 Collect_Global_List
24837 (List => Expression (Assoc),
24838 Mode => Chars (First (Choices (Assoc))));
24839 Next (Assoc);
24840 end loop;
24841 end if;
24843 -- To accomodate partial decoration of disabled SPARK features, this
24844 -- routine may be called with illegal input. If this is the case, do
24845 -- not raise Program_Error.
24847 else
24848 null;
24849 end if;
24850 end Collect_Global_List;
24852 -- Local variables
24854 Subp_Decl : constant Node_Id := Parent (Parent (Subp_Id));
24855 Formal : Entity_Id;
24856 Global : Node_Id;
24857 List : Node_Id;
24858 Spec_Id : Entity_Id;
24860 -- Start of processing for Collect_Subprogram_Inputs_Outputs
24862 begin
24863 Global_Seen := False;
24865 -- Find the entity of the corresponding spec when processing a body
24867 if Nkind (Subp_Decl) = N_Subprogram_Body
24868 and then Present (Corresponding_Spec (Subp_Decl))
24869 then
24870 Spec_Id := Corresponding_Spec (Subp_Decl);
24872 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
24873 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
24874 then
24875 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
24877 else
24878 Spec_Id := Subp_Id;
24879 end if;
24881 -- Process all formal parameters
24883 Formal := First_Formal (Spec_Id);
24884 while Present (Formal) loop
24885 if Ekind_In (Formal, E_In_Out_Parameter, E_In_Parameter) then
24886 Add_Item (Formal, Subp_Inputs);
24887 end if;
24889 if Ekind_In (Formal, E_In_Out_Parameter, E_Out_Parameter) then
24890 Add_Item (Formal, Subp_Outputs);
24892 -- Out parameters can act as inputs when the related type is
24893 -- tagged, unconstrained array, unconstrained record or record
24894 -- with unconstrained components.
24896 if Ekind (Formal) = E_Out_Parameter
24897 and then Is_Unconstrained_Or_Tagged_Item (Formal)
24898 then
24899 Add_Item (Formal, Subp_Inputs);
24900 end if;
24901 end if;
24903 Next_Formal (Formal);
24904 end loop;
24906 -- When processing a subprogram body, look for pragma Refined_Global as
24907 -- it provides finer granularity of inputs and outputs.
24909 if Ekind (Subp_Id) = E_Subprogram_Body then
24910 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
24912 -- Subprogram declaration case, look for pragma Global
24914 else
24915 Global := Get_Pragma (Spec_Id, Pragma_Global);
24916 end if;
24918 if Present (Global) then
24919 Global_Seen := True;
24920 List := Expression (First (Pragma_Argument_Associations (Global)));
24922 -- The pragma may not have been analyzed because of the arbitrary
24923 -- declaration order of aspects. Make sure that it is analyzed for
24924 -- the purposes of item extraction.
24926 if not Analyzed (List) then
24927 if Pragma_Name (Global) = Name_Refined_Global then
24928 Analyze_Refined_Global_In_Decl_Part (Global);
24929 else
24930 Analyze_Global_In_Decl_Part (Global);
24931 end if;
24932 end if;
24934 -- Nothing to be done for a null global list
24936 if Nkind (List) /= N_Null then
24937 Collect_Global_List (List);
24938 end if;
24939 end if;
24940 end Collect_Subprogram_Inputs_Outputs;
24942 ---------------------------------
24943 -- Delay_Config_Pragma_Analyze --
24944 ---------------------------------
24946 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
24947 begin
24948 return Nam_In (Pragma_Name (N), Name_Interrupt_State,
24949 Name_Priority_Specific_Dispatching);
24950 end Delay_Config_Pragma_Analyze;
24952 -------------------------------------
24953 -- Find_Related_Subprogram_Or_Body --
24954 -------------------------------------
24956 function Find_Related_Subprogram_Or_Body
24957 (Prag : Node_Id;
24958 Do_Checks : Boolean := False) return Node_Id
24960 Context : constant Node_Id := Parent (Prag);
24961 Nam : constant Name_Id := Pragma_Name (Prag);
24962 Stmt : Node_Id;
24964 Look_For_Body : constant Boolean :=
24965 Nam_In (Nam, Name_Refined_Depends,
24966 Name_Refined_Global,
24967 Name_Refined_Post);
24968 -- Refinement pragmas must be associated with a subprogram body [stub]
24970 begin
24971 pragma Assert (Nkind (Prag) = N_Pragma);
24973 -- If the pragma is a byproduct of aspect expansion, return the related
24974 -- context of the original aspect.
24976 if Present (Corresponding_Aspect (Prag)) then
24977 return Parent (Corresponding_Aspect (Prag));
24978 end if;
24980 -- Otherwise the pragma is a source construct, most likely part of a
24981 -- declarative list. Skip preceding declarations while looking for a
24982 -- proper subprogram declaration.
24984 pragma Assert (Is_List_Member (Prag));
24986 Stmt := Prev (Prag);
24987 while Present (Stmt) loop
24989 -- Skip prior pragmas, but check for duplicates
24991 if Nkind (Stmt) = N_Pragma then
24992 if Do_Checks and then Pragma_Name (Stmt) = Nam then
24993 Error_Msg_Name_1 := Nam;
24994 Error_Msg_Sloc := Sloc (Stmt);
24995 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
24996 end if;
24998 -- Emit an error when a refinement pragma appears on an expression
24999 -- function without a completion.
25001 elsif Do_Checks
25002 and then Look_For_Body
25003 and then Nkind (Stmt) = N_Subprogram_Declaration
25004 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
25005 and then not Has_Completion (Defining_Entity (Stmt))
25006 then
25007 Error_Msg_Name_1 := Nam;
25008 Error_Msg_N
25009 ("pragma % cannot apply to a stand alone expression function",
25010 Prag);
25012 return Empty;
25014 -- The refinement pragma applies to a subprogram body stub
25016 elsif Look_For_Body
25017 and then Nkind (Stmt) = N_Subprogram_Body_Stub
25018 then
25019 return Stmt;
25021 -- Skip internally generated code
25023 elsif not Comes_From_Source (Stmt) then
25024 null;
25026 -- Return the current construct which is either a subprogram body,
25027 -- a subprogram declaration or is illegal.
25029 else
25030 return Stmt;
25031 end if;
25033 Prev (Stmt);
25034 end loop;
25036 -- If we fall through, then the pragma was either the first declaration
25037 -- or it was preceded by other pragmas and no source constructs.
25039 -- The pragma is associated with a library-level subprogram
25041 if Nkind (Context) = N_Compilation_Unit_Aux then
25042 return Unit (Parent (Context));
25044 -- The pragma appears inside the declarative part of a subprogram body
25046 elsif Nkind (Context) = N_Subprogram_Body then
25047 return Context;
25049 -- No candidate subprogram [body] found
25051 else
25052 return Empty;
25053 end if;
25054 end Find_Related_Subprogram_Or_Body;
25056 -------------------------
25057 -- Get_Base_Subprogram --
25058 -------------------------
25060 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
25061 Result : Entity_Id;
25063 begin
25064 -- Follow subprogram renaming chain
25066 Result := Def_Id;
25068 if Is_Subprogram (Result)
25069 and then
25070 Nkind (Parent (Declaration_Node (Result))) =
25071 N_Subprogram_Renaming_Declaration
25072 and then Present (Alias (Result))
25073 then
25074 Result := Alias (Result);
25075 end if;
25077 return Result;
25078 end Get_Base_Subprogram;
25080 -----------------------
25081 -- Get_SPARK_Mode_Type --
25082 -----------------------
25084 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
25085 begin
25086 if N = Name_On then
25087 return On;
25088 elsif N = Name_Off then
25089 return Off;
25091 -- Any other argument is illegal
25093 else
25094 raise Program_Error;
25095 end if;
25096 end Get_SPARK_Mode_Type;
25098 --------------------------------
25099 -- Get_SPARK_Mode_From_Pragma --
25100 --------------------------------
25102 function Get_SPARK_Mode_From_Pragma (N : Node_Id) return SPARK_Mode_Type is
25103 Args : List_Id;
25104 Mode : Node_Id;
25106 begin
25107 pragma Assert (Nkind (N) = N_Pragma);
25108 Args := Pragma_Argument_Associations (N);
25110 -- Extract the mode from the argument list
25112 if Present (Args) then
25113 Mode := First (Pragma_Argument_Associations (N));
25114 return Get_SPARK_Mode_Type (Chars (Get_Pragma_Arg (Mode)));
25116 -- If SPARK_Mode pragma has no argument, default is ON
25118 else
25119 return On;
25120 end if;
25121 end Get_SPARK_Mode_From_Pragma;
25123 ---------------------------
25124 -- Has_Extra_Parentheses --
25125 ---------------------------
25127 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
25128 Expr : Node_Id;
25130 begin
25131 -- The aggregate should not have an expression list because a clause
25132 -- is always interpreted as a component association. The only way an
25133 -- expression list can sneak in is by adding extra parentheses around
25134 -- the individual clauses:
25136 -- Depends (Output => Input) -- proper form
25137 -- Depends ((Output => Input)) -- extra parentheses
25139 -- Since the extra parentheses are not allowed by the syntax of the
25140 -- pragma, flag them now to avoid emitting misleading errors down the
25141 -- line.
25143 if Nkind (Clause) = N_Aggregate
25144 and then Present (Expressions (Clause))
25145 then
25146 Expr := First (Expressions (Clause));
25147 while Present (Expr) loop
25149 -- A dependency clause surrounded by extra parentheses appears
25150 -- as an aggregate of component associations with an optional
25151 -- Paren_Count set.
25153 if Nkind (Expr) = N_Aggregate
25154 and then Present (Component_Associations (Expr))
25155 then
25156 SPARK_Msg_N
25157 ("dependency clause contains extra parentheses", Expr);
25159 -- Otherwise the expression is a malformed construct
25161 else
25162 SPARK_Msg_N ("malformed dependency clause", Expr);
25163 end if;
25165 Next (Expr);
25166 end loop;
25168 return True;
25169 end if;
25171 return False;
25172 end Has_Extra_Parentheses;
25174 ----------------
25175 -- Initialize --
25176 ----------------
25178 procedure Initialize is
25179 begin
25180 Externals.Init;
25181 end Initialize;
25183 --------
25184 -- ip --
25185 --------
25187 procedure ip is
25188 begin
25189 Dummy := Dummy + 1;
25190 end ip;
25192 -----------------------------
25193 -- Is_Config_Static_String --
25194 -----------------------------
25196 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
25198 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
25199 -- This is an internal recursive function that is just like the outer
25200 -- function except that it adds the string to the name buffer rather
25201 -- than placing the string in the name buffer.
25203 ------------------------------
25204 -- Add_Config_Static_String --
25205 ------------------------------
25207 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
25208 N : Node_Id;
25209 C : Char_Code;
25211 begin
25212 N := Arg;
25214 if Nkind (N) = N_Op_Concat then
25215 if Add_Config_Static_String (Left_Opnd (N)) then
25216 N := Right_Opnd (N);
25217 else
25218 return False;
25219 end if;
25220 end if;
25222 if Nkind (N) /= N_String_Literal then
25223 Error_Msg_N ("string literal expected for pragma argument", N);
25224 return False;
25226 else
25227 for J in 1 .. String_Length (Strval (N)) loop
25228 C := Get_String_Char (Strval (N), J);
25230 if not In_Character_Range (C) then
25231 Error_Msg
25232 ("string literal contains invalid wide character",
25233 Sloc (N) + 1 + Source_Ptr (J));
25234 return False;
25235 end if;
25237 Add_Char_To_Name_Buffer (Get_Character (C));
25238 end loop;
25239 end if;
25241 return True;
25242 end Add_Config_Static_String;
25244 -- Start of processing for Is_Config_Static_String
25246 begin
25247 Name_Len := 0;
25249 return Add_Config_Static_String (Arg);
25250 end Is_Config_Static_String;
25252 -------------------------------
25253 -- Is_Elaboration_SPARK_Mode --
25254 -------------------------------
25256 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
25257 begin
25258 pragma Assert
25259 (Nkind (N) = N_Pragma
25260 and then Pragma_Name (N) = Name_SPARK_Mode
25261 and then Is_List_Member (N));
25263 -- Pragma SPARK_Mode affects the elaboration of a package body when it
25264 -- appears in the statement part of the body.
25266 return
25267 Present (Parent (N))
25268 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
25269 and then List_Containing (N) = Statements (Parent (N))
25270 and then Present (Parent (Parent (N)))
25271 and then Nkind (Parent (Parent (N))) = N_Package_Body;
25272 end Is_Elaboration_SPARK_Mode;
25274 -----------------------------------------
25275 -- Is_Non_Significant_Pragma_Reference --
25276 -----------------------------------------
25278 -- This function makes use of the following static table which indicates
25279 -- whether appearance of some name in a given pragma is to be considered
25280 -- as a reference for the purposes of warnings about unreferenced objects.
25282 -- -1 indicates that appearence in any argument is significant
25283 -- 0 indicates that appearance in any argument is not significant
25284 -- +n indicates that appearance as argument n is significant, but all
25285 -- other arguments are not significant
25286 -- 9n arguments from n on are significant, before n inisignificant
25288 Sig_Flags : constant array (Pragma_Id) of Int :=
25289 (Pragma_Abort_Defer => -1,
25290 Pragma_Abstract_State => -1,
25291 Pragma_Ada_83 => -1,
25292 Pragma_Ada_95 => -1,
25293 Pragma_Ada_05 => -1,
25294 Pragma_Ada_2005 => -1,
25295 Pragma_Ada_12 => -1,
25296 Pragma_Ada_2012 => -1,
25297 Pragma_All_Calls_Remote => -1,
25298 Pragma_Allow_Integer_Address => -1,
25299 Pragma_Annotate => 93,
25300 Pragma_Assert => -1,
25301 Pragma_Assert_And_Cut => -1,
25302 Pragma_Assertion_Policy => 0,
25303 Pragma_Assume => -1,
25304 Pragma_Assume_No_Invalid_Values => 0,
25305 Pragma_Async_Readers => 0,
25306 Pragma_Async_Writers => 0,
25307 Pragma_Asynchronous => 0,
25308 Pragma_Atomic => 0,
25309 Pragma_Atomic_Components => 0,
25310 Pragma_Attach_Handler => -1,
25311 Pragma_Attribute_Definition => 92,
25312 Pragma_Check => -1,
25313 Pragma_Check_Float_Overflow => 0,
25314 Pragma_Check_Name => 0,
25315 Pragma_Check_Policy => 0,
25316 Pragma_CIL_Constructor => 0,
25317 Pragma_CPP_Class => 0,
25318 Pragma_CPP_Constructor => 0,
25319 Pragma_CPP_Virtual => 0,
25320 Pragma_CPP_Vtable => 0,
25321 Pragma_CPU => -1,
25322 Pragma_C_Pass_By_Copy => 0,
25323 Pragma_Comment => -1,
25324 Pragma_Common_Object => 0,
25325 Pragma_Compile_Time_Error => -1,
25326 Pragma_Compile_Time_Warning => -1,
25327 Pragma_Compiler_Unit => -1,
25328 Pragma_Compiler_Unit_Warning => -1,
25329 Pragma_Complete_Representation => 0,
25330 Pragma_Complex_Representation => 0,
25331 Pragma_Component_Alignment => 0,
25332 Pragma_Contract_Cases => -1,
25333 Pragma_Controlled => 0,
25334 Pragma_Convention => 0,
25335 Pragma_Convention_Identifier => 0,
25336 Pragma_Debug => -1,
25337 Pragma_Debug_Policy => 0,
25338 Pragma_Detect_Blocking => 0,
25339 Pragma_Default_Initial_Condition => -1,
25340 Pragma_Default_Scalar_Storage_Order => 0,
25341 Pragma_Default_Storage_Pool => 0,
25342 Pragma_Depends => -1,
25343 Pragma_Disable_Atomic_Synchronization => 0,
25344 Pragma_Discard_Names => 0,
25345 Pragma_Dispatching_Domain => -1,
25346 Pragma_Effective_Reads => 0,
25347 Pragma_Effective_Writes => 0,
25348 Pragma_Elaborate => 0,
25349 Pragma_Elaborate_All => 0,
25350 Pragma_Elaborate_Body => 0,
25351 Pragma_Elaboration_Checks => 0,
25352 Pragma_Eliminate => 0,
25353 Pragma_Enable_Atomic_Synchronization => 0,
25354 Pragma_Export => -1,
25355 Pragma_Export_Function => -1,
25356 Pragma_Export_Object => -1,
25357 Pragma_Export_Procedure => -1,
25358 Pragma_Export_Value => -1,
25359 Pragma_Export_Valued_Procedure => -1,
25360 Pragma_Extend_System => -1,
25361 Pragma_Extensions_Allowed => 0,
25362 Pragma_Extensions_Visible => 0,
25363 Pragma_External => -1,
25364 Pragma_Favor_Top_Level => 0,
25365 Pragma_External_Name_Casing => 0,
25366 Pragma_Fast_Math => 0,
25367 Pragma_Finalize_Storage_Only => 0,
25368 Pragma_Ghost => 0,
25369 Pragma_Global => -1,
25370 Pragma_Ident => -1,
25371 Pragma_Implementation_Defined => -1,
25372 Pragma_Implemented => -1,
25373 Pragma_Implicit_Packing => 0,
25374 Pragma_Import => 93,
25375 Pragma_Import_Function => 0,
25376 Pragma_Import_Object => 0,
25377 Pragma_Import_Procedure => 0,
25378 Pragma_Import_Valued_Procedure => 0,
25379 Pragma_Independent => 0,
25380 Pragma_Independent_Components => 0,
25381 Pragma_Initial_Condition => -1,
25382 Pragma_Initialize_Scalars => 0,
25383 Pragma_Initializes => -1,
25384 Pragma_Inline => 0,
25385 Pragma_Inline_Always => 0,
25386 Pragma_Inline_Generic => 0,
25387 Pragma_Inspection_Point => -1,
25388 Pragma_Interface => 92,
25389 Pragma_Interface_Name => 0,
25390 Pragma_Interrupt_Handler => -1,
25391 Pragma_Interrupt_Priority => -1,
25392 Pragma_Interrupt_State => -1,
25393 Pragma_Invariant => -1,
25394 Pragma_Java_Constructor => -1,
25395 Pragma_Java_Interface => -1,
25396 Pragma_Keep_Names => 0,
25397 Pragma_License => 0,
25398 Pragma_Link_With => -1,
25399 Pragma_Linker_Alias => -1,
25400 Pragma_Linker_Constructor => -1,
25401 Pragma_Linker_Destructor => -1,
25402 Pragma_Linker_Options => -1,
25403 Pragma_Linker_Section => 0,
25404 Pragma_List => 0,
25405 Pragma_Lock_Free => 0,
25406 Pragma_Locking_Policy => 0,
25407 Pragma_Loop_Invariant => -1,
25408 Pragma_Loop_Optimize => 0,
25409 Pragma_Loop_Variant => -1,
25410 Pragma_Machine_Attribute => -1,
25411 Pragma_Main => -1,
25412 Pragma_Main_Storage => -1,
25413 Pragma_Memory_Size => 0,
25414 Pragma_No_Return => 0,
25415 Pragma_No_Body => 0,
25416 Pragma_No_Elaboration_Code_All => 0,
25417 Pragma_No_Inline => 0,
25418 Pragma_No_Run_Time => -1,
25419 Pragma_No_Strict_Aliasing => -1,
25420 Pragma_No_Tagged_Streams => 0,
25421 Pragma_Normalize_Scalars => 0,
25422 Pragma_Obsolescent => 0,
25423 Pragma_Optimize => 0,
25424 Pragma_Optimize_Alignment => 0,
25425 Pragma_Overflow_Mode => 0,
25426 Pragma_Overriding_Renamings => 0,
25427 Pragma_Ordered => 0,
25428 Pragma_Pack => 0,
25429 Pragma_Page => 0,
25430 Pragma_Part_Of => 0,
25431 Pragma_Partition_Elaboration_Policy => 0,
25432 Pragma_Passive => 0,
25433 Pragma_Persistent_BSS => 0,
25434 Pragma_Polling => 0,
25435 Pragma_Prefix_Exception_Messages => 0,
25436 Pragma_Post => -1,
25437 Pragma_Postcondition => -1,
25438 Pragma_Post_Class => -1,
25439 Pragma_Pre => -1,
25440 Pragma_Precondition => -1,
25441 Pragma_Predicate => -1,
25442 Pragma_Preelaborable_Initialization => -1,
25443 Pragma_Preelaborate => 0,
25444 Pragma_Pre_Class => -1,
25445 Pragma_Priority => -1,
25446 Pragma_Priority_Specific_Dispatching => 0,
25447 Pragma_Profile => 0,
25448 Pragma_Profile_Warnings => 0,
25449 Pragma_Propagate_Exceptions => 0,
25450 Pragma_Provide_Shift_Operators => 0,
25451 Pragma_Psect_Object => 0,
25452 Pragma_Pure => 0,
25453 Pragma_Pure_Function => 0,
25454 Pragma_Queuing_Policy => 0,
25455 Pragma_Rational => 0,
25456 Pragma_Ravenscar => 0,
25457 Pragma_Refined_Depends => -1,
25458 Pragma_Refined_Global => -1,
25459 Pragma_Refined_Post => -1,
25460 Pragma_Refined_State => -1,
25461 Pragma_Relative_Deadline => 0,
25462 Pragma_Remote_Access_Type => -1,
25463 Pragma_Remote_Call_Interface => -1,
25464 Pragma_Remote_Types => -1,
25465 Pragma_Restricted_Run_Time => 0,
25466 Pragma_Restriction_Warnings => 0,
25467 Pragma_Restrictions => 0,
25468 Pragma_Reviewable => -1,
25469 Pragma_Short_Circuit_And_Or => 0,
25470 Pragma_Share_Generic => 0,
25471 Pragma_Shared => 0,
25472 Pragma_Shared_Passive => 0,
25473 Pragma_Short_Descriptors => 0,
25474 Pragma_Simple_Storage_Pool_Type => 0,
25475 Pragma_Source_File_Name => 0,
25476 Pragma_Source_File_Name_Project => 0,
25477 Pragma_Source_Reference => 0,
25478 Pragma_SPARK_Mode => 0,
25479 Pragma_Storage_Size => -1,
25480 Pragma_Storage_Unit => 0,
25481 Pragma_Static_Elaboration_Desired => 0,
25482 Pragma_Stream_Convert => 0,
25483 Pragma_Style_Checks => 0,
25484 Pragma_Subtitle => 0,
25485 Pragma_Suppress => 0,
25486 Pragma_Suppress_Exception_Locations => 0,
25487 Pragma_Suppress_All => 0,
25488 Pragma_Suppress_Debug_Info => 0,
25489 Pragma_Suppress_Initialization => 0,
25490 Pragma_System_Name => 0,
25491 Pragma_Task_Dispatching_Policy => 0,
25492 Pragma_Task_Info => -1,
25493 Pragma_Task_Name => -1,
25494 Pragma_Task_Storage => -1,
25495 Pragma_Test_Case => -1,
25496 Pragma_Thread_Local_Storage => -1,
25497 Pragma_Time_Slice => -1,
25498 Pragma_Title => 0,
25499 Pragma_Type_Invariant => -1,
25500 Pragma_Type_Invariant_Class => -1,
25501 Pragma_Unchecked_Union => 0,
25502 Pragma_Unimplemented_Unit => 0,
25503 Pragma_Universal_Aliasing => 0,
25504 Pragma_Universal_Data => 0,
25505 Pragma_Unmodified => 0,
25506 Pragma_Unreferenced => 0,
25507 Pragma_Unreferenced_Objects => 0,
25508 Pragma_Unreserve_All_Interrupts => 0,
25509 Pragma_Unsuppress => 0,
25510 Pragma_Unevaluated_Use_Of_Old => 0,
25511 Pragma_Use_VADS_Size => 0,
25512 Pragma_Validity_Checks => 0,
25513 Pragma_Volatile => 0,
25514 Pragma_Volatile_Components => 0,
25515 Pragma_Warning_As_Error => 0,
25516 Pragma_Warnings => 0,
25517 Pragma_Weak_External => 0,
25518 Pragma_Wide_Character_Encoding => 0,
25519 Unknown_Pragma => 0);
25521 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
25522 Id : Pragma_Id;
25523 P : Node_Id;
25524 C : Int;
25525 AN : Nat;
25527 function Arg_No return Nat;
25528 -- Returns an integer showing what argument we are in. A value of
25529 -- zero means we are not in any of the arguments.
25531 ------------
25532 -- Arg_No --
25533 ------------
25535 function Arg_No return Nat is
25536 A : Node_Id;
25537 N : Nat;
25539 begin
25540 A := First (Pragma_Argument_Associations (Parent (P)));
25541 N := 1;
25542 loop
25543 if No (A) then
25544 return 0;
25545 elsif A = P then
25546 return N;
25547 end if;
25549 Next (A);
25550 N := N + 1;
25551 end loop;
25552 end Arg_No;
25554 -- Start of processing for Non_Significant_Pragma_Reference
25556 begin
25557 P := Parent (N);
25559 if Nkind (P) /= N_Pragma_Argument_Association then
25560 return False;
25562 else
25563 Id := Get_Pragma_Id (Parent (P));
25564 C := Sig_Flags (Id);
25565 AN := Arg_No;
25567 if AN = 0 then
25568 return False;
25569 end if;
25571 case C is
25572 when -1 =>
25573 return False;
25575 when 0 =>
25576 return True;
25578 when 92 .. 99 =>
25579 return AN < (C - 90);
25581 when others =>
25582 return AN /= C;
25583 end case;
25584 end if;
25585 end Is_Non_Significant_Pragma_Reference;
25587 ------------------------------
25588 -- Is_Pragma_String_Literal --
25589 ------------------------------
25591 -- This function returns true if the corresponding pragma argument is a
25592 -- static string expression. These are the only cases in which string
25593 -- literals can appear as pragma arguments. We also allow a string literal
25594 -- as the first argument to pragma Assert (although it will of course
25595 -- always generate a type error).
25597 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
25598 Pragn : constant Node_Id := Parent (Par);
25599 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
25600 Pname : constant Name_Id := Pragma_Name (Pragn);
25601 Argn : Natural;
25602 N : Node_Id;
25604 begin
25605 Argn := 1;
25606 N := First (Assoc);
25607 loop
25608 exit when N = Par;
25609 Argn := Argn + 1;
25610 Next (N);
25611 end loop;
25613 if Pname = Name_Assert then
25614 return True;
25616 elsif Pname = Name_Export then
25617 return Argn > 2;
25619 elsif Pname = Name_Ident then
25620 return Argn = 1;
25622 elsif Pname = Name_Import then
25623 return Argn > 2;
25625 elsif Pname = Name_Interface_Name then
25626 return Argn > 1;
25628 elsif Pname = Name_Linker_Alias then
25629 return Argn = 2;
25631 elsif Pname = Name_Linker_Section then
25632 return Argn = 2;
25634 elsif Pname = Name_Machine_Attribute then
25635 return Argn = 2;
25637 elsif Pname = Name_Source_File_Name then
25638 return True;
25640 elsif Pname = Name_Source_Reference then
25641 return Argn = 2;
25643 elsif Pname = Name_Title then
25644 return True;
25646 elsif Pname = Name_Subtitle then
25647 return True;
25649 else
25650 return False;
25651 end if;
25652 end Is_Pragma_String_Literal;
25654 ---------------------------
25655 -- Is_Private_SPARK_Mode --
25656 ---------------------------
25658 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
25659 begin
25660 pragma Assert
25661 (Nkind (N) = N_Pragma
25662 and then Pragma_Name (N) = Name_SPARK_Mode
25663 and then Is_List_Member (N));
25665 -- For pragma SPARK_Mode to be private, it has to appear in the private
25666 -- declarations of a package.
25668 return
25669 Present (Parent (N))
25670 and then Nkind (Parent (N)) = N_Package_Specification
25671 and then List_Containing (N) = Private_Declarations (Parent (N));
25672 end Is_Private_SPARK_Mode;
25674 -------------------------------------
25675 -- Is_Unconstrained_Or_Tagged_Item --
25676 -------------------------------------
25678 function Is_Unconstrained_Or_Tagged_Item
25679 (Item : Entity_Id) return Boolean
25681 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
25682 -- Determine whether record type Typ has at least one unconstrained
25683 -- component.
25685 ---------------------------------
25686 -- Has_Unconstrained_Component --
25687 ---------------------------------
25689 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
25690 Comp : Entity_Id;
25692 begin
25693 Comp := First_Component (Typ);
25694 while Present (Comp) loop
25695 if Is_Unconstrained_Or_Tagged_Item (Comp) then
25696 return True;
25697 end if;
25699 Next_Component (Comp);
25700 end loop;
25702 return False;
25703 end Has_Unconstrained_Component;
25705 -- Local variables
25707 Typ : constant Entity_Id := Etype (Item);
25709 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
25711 begin
25712 if Is_Tagged_Type (Typ) then
25713 return True;
25715 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
25716 return True;
25718 elsif Is_Record_Type (Typ) then
25719 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
25720 return True;
25721 else
25722 return Has_Unconstrained_Component (Typ);
25723 end if;
25725 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
25726 return True;
25728 else
25729 return False;
25730 end if;
25731 end Is_Unconstrained_Or_Tagged_Item;
25733 -----------------------------
25734 -- Is_Valid_Assertion_Kind --
25735 -----------------------------
25737 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
25738 begin
25739 case Nam is
25740 when
25741 -- RM defined
25743 Name_Assert |
25744 Name_Static_Predicate |
25745 Name_Dynamic_Predicate |
25746 Name_Pre |
25747 Name_uPre |
25748 Name_Post |
25749 Name_uPost |
25750 Name_Type_Invariant |
25751 Name_uType_Invariant |
25753 -- Impl defined
25755 Name_Assert_And_Cut |
25756 Name_Assume |
25757 Name_Contract_Cases |
25758 Name_Debug |
25759 Name_Default_Initial_Condition |
25760 Name_Ghost |
25761 Name_Initial_Condition |
25762 Name_Invariant |
25763 Name_uInvariant |
25764 Name_Loop_Invariant |
25765 Name_Loop_Variant |
25766 Name_Postcondition |
25767 Name_Precondition |
25768 Name_Predicate |
25769 Name_Refined_Post |
25770 Name_Statement_Assertions => return True;
25772 when others => return False;
25773 end case;
25774 end Is_Valid_Assertion_Kind;
25776 -----------------------------------------
25777 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
25778 -----------------------------------------
25780 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
25781 Aspects : constant List_Id := New_List;
25782 Loc : constant Source_Ptr := Sloc (Decl);
25783 Or_Decl : constant Node_Id := Original_Node (Decl);
25785 Original_Aspects : List_Id;
25786 -- To capture global references, a copy of the created aspects must be
25787 -- inserted in the original tree.
25789 Prag : Node_Id;
25790 Prag_Arg_Ass : Node_Id;
25791 Prag_Id : Pragma_Id;
25793 begin
25794 -- Check for any PPC pragmas that appear within Decl
25796 Prag := Next (Decl);
25797 while Nkind (Prag) = N_Pragma loop
25798 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
25800 case Prag_Id is
25801 when Pragma_Postcondition | Pragma_Precondition =>
25802 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
25804 -- Make an aspect from any PPC pragma
25806 Append_To (Aspects,
25807 Make_Aspect_Specification (Loc,
25808 Identifier =>
25809 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
25810 Expression =>
25811 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
25813 -- Generate the analysis information in the pragma expression
25814 -- and then set the pragma node analyzed to avoid any further
25815 -- analysis.
25817 Analyze (Expression (Prag_Arg_Ass));
25818 Set_Analyzed (Prag, True);
25820 when others => null;
25821 end case;
25823 Next (Prag);
25824 end loop;
25826 -- Set all new aspects into the generic declaration node
25828 if Is_Non_Empty_List (Aspects) then
25830 -- Create the list of aspects to be inserted in the original tree
25832 Original_Aspects := Copy_Separate_List (Aspects);
25834 -- Check if Decl already has aspects
25836 -- Attach the new lists of aspects to both the generic copy and the
25837 -- original tree.
25839 if Has_Aspects (Decl) then
25840 Append_List (Aspects, Aspect_Specifications (Decl));
25841 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
25843 else
25844 Set_Parent (Aspects, Decl);
25845 Set_Aspect_Specifications (Decl, Aspects);
25846 Set_Parent (Original_Aspects, Or_Decl);
25847 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
25848 end if;
25849 end if;
25850 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
25852 -------------------------
25853 -- Preanalyze_CTC_Args --
25854 -------------------------
25856 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
25857 begin
25858 -- Preanalyze the boolean expressions, we treat these as spec
25859 -- expressions (i.e. similar to a default expression).
25861 if Present (Arg_Req) then
25862 Preanalyze_Assert_Expression
25863 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
25865 -- In ASIS mode, for a pragma generated from a source aspect, also
25866 -- analyze the original aspect expression.
25868 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
25869 Preanalyze_Assert_Expression
25870 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
25871 end if;
25872 end if;
25874 if Present (Arg_Ens) then
25875 Preanalyze_Assert_Expression
25876 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
25878 -- In ASIS mode, for a pragma generated from a source aspect, also
25879 -- analyze the original aspect expression.
25881 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
25882 Preanalyze_Assert_Expression
25883 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
25884 end if;
25885 end if;
25886 end Preanalyze_CTC_Args;
25888 --------------------------------------
25889 -- Process_Compilation_Unit_Pragmas --
25890 --------------------------------------
25892 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
25893 begin
25894 -- A special check for pragma Suppress_All, a very strange DEC pragma,
25895 -- strange because it comes at the end of the unit. Rational has the
25896 -- same name for a pragma, but treats it as a program unit pragma, In
25897 -- GNAT we just decide to allow it anywhere at all. If it appeared then
25898 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
25899 -- node, and we insert a pragma Suppress (All_Checks) at the start of
25900 -- the context clause to ensure the correct processing.
25902 if Has_Pragma_Suppress_All (N) then
25903 Prepend_To (Context_Items (N),
25904 Make_Pragma (Sloc (N),
25905 Chars => Name_Suppress,
25906 Pragma_Argument_Associations => New_List (
25907 Make_Pragma_Argument_Association (Sloc (N),
25908 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
25909 end if;
25911 -- Nothing else to do at the current time
25913 end Process_Compilation_Unit_Pragmas;
25915 ------------------------------------
25916 -- Record_Possible_Body_Reference --
25917 ------------------------------------
25919 procedure Record_Possible_Body_Reference
25920 (State_Id : Entity_Id;
25921 Ref : Node_Id)
25923 Context : Node_Id;
25924 Spec_Id : Entity_Id;
25926 begin
25927 -- Ensure that we are dealing with a reference to a state
25929 pragma Assert (Ekind (State_Id) = E_Abstract_State);
25931 -- Climb the tree starting from the reference looking for a package body
25932 -- whose spec declares the referenced state. This criteria automatically
25933 -- excludes references in package specs which are legal. Note that it is
25934 -- not wise to emit an error now as the package body may lack pragma
25935 -- Refined_State or the referenced state may not be mentioned in the
25936 -- refinement. This approach avoids the generation of misleading errors.
25938 Context := Ref;
25939 while Present (Context) loop
25940 if Nkind (Context) = N_Package_Body then
25941 Spec_Id := Corresponding_Spec (Context);
25943 if Present (Abstract_States (Spec_Id))
25944 and then Contains (Abstract_States (Spec_Id), State_Id)
25945 then
25946 if No (Body_References (State_Id)) then
25947 Set_Body_References (State_Id, New_Elmt_List);
25948 end if;
25950 Append_Elmt (Ref, To => Body_References (State_Id));
25951 exit;
25952 end if;
25953 end if;
25955 Context := Parent (Context);
25956 end loop;
25957 end Record_Possible_Body_Reference;
25959 ------------------------------
25960 -- Relocate_Pragmas_To_Body --
25961 ------------------------------
25963 procedure Relocate_Pragmas_To_Body
25964 (Subp_Body : Node_Id;
25965 Target_Body : Node_Id := Empty)
25967 procedure Relocate_Pragma (Prag : Node_Id);
25968 -- Remove a single pragma from its current list and add it to the
25969 -- declarations of the proper body (either Subp_Body or Target_Body).
25971 ---------------------
25972 -- Relocate_Pragma --
25973 ---------------------
25975 procedure Relocate_Pragma (Prag : Node_Id) is
25976 Decls : List_Id;
25977 Target : Node_Id;
25979 begin
25980 -- When subprogram stubs or expression functions are involves, the
25981 -- destination declaration list belongs to the proper body.
25983 if Present (Target_Body) then
25984 Target := Target_Body;
25985 else
25986 Target := Subp_Body;
25987 end if;
25989 Decls := Declarations (Target);
25991 if No (Decls) then
25992 Decls := New_List;
25993 Set_Declarations (Target, Decls);
25994 end if;
25996 -- Unhook the pragma from its current list
25998 Remove (Prag);
25999 Prepend (Prag, Decls);
26000 end Relocate_Pragma;
26002 -- Local variables
26004 Body_Id : constant Entity_Id :=
26005 Defining_Unit_Name (Specification (Subp_Body));
26006 Next_Stmt : Node_Id;
26007 Stmt : Node_Id;
26009 -- Start of processing for Relocate_Pragmas_To_Body
26011 begin
26012 -- Do not process a body that comes from a separate unit as no construct
26013 -- can possibly follow it.
26015 if not Is_List_Member (Subp_Body) then
26016 return;
26018 -- Do not relocate pragmas that follow a stub if the stub does not have
26019 -- a proper body.
26021 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
26022 and then No (Target_Body)
26023 then
26024 return;
26026 -- Do not process internally generated routine _Postconditions
26028 elsif Ekind (Body_Id) = E_Procedure
26029 and then Chars (Body_Id) = Name_uPostconditions
26030 then
26031 return;
26032 end if;
26034 -- Look at what is following the body. We are interested in certain kind
26035 -- of pragmas (either from source or byproducts of expansion) that can
26036 -- apply to a body [stub].
26038 Stmt := Next (Subp_Body);
26039 while Present (Stmt) loop
26041 -- Preserve the following statement for iteration purposes due to a
26042 -- possible relocation of a pragma.
26044 Next_Stmt := Next (Stmt);
26046 -- Move a candidate pragma following the body to the declarations of
26047 -- the body.
26049 if Nkind (Stmt) = N_Pragma
26050 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
26051 then
26052 Relocate_Pragma (Stmt);
26054 -- Skip internally generated code
26056 elsif not Comes_From_Source (Stmt) then
26057 null;
26059 -- No candidate pragmas are available for relocation
26061 else
26062 exit;
26063 end if;
26065 Stmt := Next_Stmt;
26066 end loop;
26067 end Relocate_Pragmas_To_Body;
26069 -------------------
26070 -- Resolve_State --
26071 -------------------
26073 procedure Resolve_State (N : Node_Id) is
26074 Func : Entity_Id;
26075 State : Entity_Id;
26077 begin
26078 if Is_Entity_Name (N) and then Present (Entity (N)) then
26079 Func := Entity (N);
26081 -- Handle overloading of state names by functions. Traverse the
26082 -- homonym chain looking for an abstract state.
26084 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
26085 State := Homonym (Func);
26086 while Present (State) loop
26088 -- Resolve the overloading by setting the proper entity of the
26089 -- reference to that of the state.
26091 if Ekind (State) = E_Abstract_State then
26092 Set_Etype (N, Standard_Void_Type);
26093 Set_Entity (N, State);
26094 Set_Associated_Node (N, State);
26095 return;
26096 end if;
26098 State := Homonym (State);
26099 end loop;
26101 -- A function can never act as a state. If the homonym chain does
26102 -- not contain a corresponding state, then something went wrong in
26103 -- the overloading mechanism.
26105 raise Program_Error;
26106 end if;
26107 end if;
26108 end Resolve_State;
26110 ----------------------------
26111 -- Rewrite_Assertion_Kind --
26112 ----------------------------
26114 procedure Rewrite_Assertion_Kind (N : Node_Id) is
26115 Nam : Name_Id;
26117 begin
26118 if Nkind (N) = N_Attribute_Reference
26119 and then Attribute_Name (N) = Name_Class
26120 and then Nkind (Prefix (N)) = N_Identifier
26121 then
26122 case Chars (Prefix (N)) is
26123 when Name_Pre =>
26124 Nam := Name_uPre;
26125 when Name_Post =>
26126 Nam := Name_uPost;
26127 when Name_Type_Invariant =>
26128 Nam := Name_uType_Invariant;
26129 when Name_Invariant =>
26130 Nam := Name_uInvariant;
26131 when others =>
26132 return;
26133 end case;
26135 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
26136 end if;
26137 end Rewrite_Assertion_Kind;
26139 --------
26140 -- rv --
26141 --------
26143 procedure rv is
26144 begin
26145 Dummy := Dummy + 1;
26146 end rv;
26148 --------------------------------
26149 -- Set_Encoded_Interface_Name --
26150 --------------------------------
26152 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
26153 Str : constant String_Id := Strval (S);
26154 Len : constant Int := String_Length (Str);
26155 CC : Char_Code;
26156 C : Character;
26157 J : Int;
26159 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
26161 procedure Encode;
26162 -- Stores encoded value of character code CC. The encoding we use an
26163 -- underscore followed by four lower case hex digits.
26165 ------------
26166 -- Encode --
26167 ------------
26169 procedure Encode is
26170 begin
26171 Store_String_Char (Get_Char_Code ('_'));
26172 Store_String_Char
26173 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
26174 Store_String_Char
26175 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
26176 Store_String_Char
26177 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
26178 Store_String_Char
26179 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
26180 end Encode;
26182 -- Start of processing for Set_Encoded_Interface_Name
26184 begin
26185 -- If first character is asterisk, this is a link name, and we leave it
26186 -- completely unmodified. We also ignore null strings (the latter case
26187 -- happens only in error cases) and no encoding should occur for Java or
26188 -- AAMP interface names.
26190 if Len = 0
26191 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
26192 or else VM_Target /= No_VM
26193 or else AAMP_On_Target
26194 then
26195 Set_Interface_Name (E, S);
26197 else
26198 J := 1;
26199 loop
26200 CC := Get_String_Char (Str, J);
26202 exit when not In_Character_Range (CC);
26204 C := Get_Character (CC);
26206 exit when C /= '_' and then C /= '$'
26207 and then C not in '0' .. '9'
26208 and then C not in 'a' .. 'z'
26209 and then C not in 'A' .. 'Z';
26211 if J = Len then
26212 Set_Interface_Name (E, S);
26213 return;
26215 else
26216 J := J + 1;
26217 end if;
26218 end loop;
26220 -- Here we need to encode. The encoding we use as follows:
26221 -- three underscores + four hex digits (lower case)
26223 Start_String;
26225 for J in 1 .. String_Length (Str) loop
26226 CC := Get_String_Char (Str, J);
26228 if not In_Character_Range (CC) then
26229 Encode;
26230 else
26231 C := Get_Character (CC);
26233 if C = '_' or else C = '$'
26234 or else C in '0' .. '9'
26235 or else C in 'a' .. 'z'
26236 or else C in 'A' .. 'Z'
26237 then
26238 Store_String_Char (CC);
26239 else
26240 Encode;
26241 end if;
26242 end if;
26243 end loop;
26245 Set_Interface_Name (E,
26246 Make_String_Literal (Sloc (S),
26247 Strval => End_String));
26248 end if;
26249 end Set_Encoded_Interface_Name;
26251 -------------------
26252 -- Set_Unit_Name --
26253 -------------------
26255 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
26256 Pref : Node_Id;
26257 Scop : Entity_Id;
26259 begin
26260 if Nkind (N) = N_Identifier
26261 and then Nkind (With_Item) = N_Identifier
26262 then
26263 Set_Entity (N, Entity (With_Item));
26265 elsif Nkind (N) = N_Selected_Component then
26266 Change_Selected_Component_To_Expanded_Name (N);
26267 Set_Entity (N, Entity (With_Item));
26268 Set_Entity (Selector_Name (N), Entity (N));
26270 Pref := Prefix (N);
26271 Scop := Scope (Entity (N));
26272 while Nkind (Pref) = N_Selected_Component loop
26273 Change_Selected_Component_To_Expanded_Name (Pref);
26274 Set_Entity (Selector_Name (Pref), Scop);
26275 Set_Entity (Pref, Scop);
26276 Pref := Prefix (Pref);
26277 Scop := Scope (Scop);
26278 end loop;
26280 Set_Entity (Pref, Scop);
26281 end if;
26282 end Set_Unit_Name;
26284 end Sem_Prag;